patch-2.4.10 linux/fs/super.c
Next file: linux/fs/sysv/Makefile
Previous file: linux/fs/stat.c
Back to the patch index
Back to the overall index
- Lines: 770
- Date:
Sat Sep 22 20:35:43 2001
- Orig file:
v2.4.9/linux/fs/super.c
- Orig date:
Sun Aug 12 13:28:00 2001
diff -u --recursive --new-file v2.4.9/linux/fs/super.c linux/fs/super.c
@@ -122,6 +122,7 @@
return -EINVAL;
if (fs->next)
return -EBUSY;
+ INIT_LIST_HEAD(&fs->fs_supers);
write_lock(&file_systems_lock);
p = find_filesystem(fs->name);
if (*p)
@@ -288,8 +289,8 @@
{
unsigned long tmp = ((unsigned long) mnt / L1_CACHE_BYTES);
tmp += ((unsigned long) dentry / L1_CACHE_BYTES);
- tmp = tmp + (tmp >> hash_mask);
- return tmp & hash_bits;
+ tmp = tmp + (tmp >> hash_bits);
+ return tmp & hash_mask;
}
struct vfsmount *alloc_vfsmnt(void)
@@ -387,8 +388,6 @@
spin_lock(&dcache_lock);
list_add(&mnt->mnt_list, vfsmntlist.prev);
spin_unlock(&dcache_lock);
- if (sb->s_type->fs_flags & FS_SINGLE)
- get_filesystem(sb->s_type);
out:
return mnt;
}
@@ -411,6 +410,7 @@
mnt->mnt_root = dget(root);
mnt->mnt_mountpoint = mnt->mnt_root;
mnt->mnt_parent = mnt;
+ mnt->mnt_flags = old->mnt_flags;
atomic_inc(&sb->s_active);
out:
@@ -419,6 +419,9 @@
static int graft_tree(struct vfsmount *mnt, struct nameidata *nd)
{
+ if (mnt->mnt_sb->s_flags & MS_NOUSER)
+ return -EINVAL;
+
if (S_ISDIR(nd->dentry->d_inode->i_mode) !=
S_ISDIR(mnt->mnt_root->d_inode->i_mode))
return -ENOTDIR;
@@ -435,8 +438,6 @@
list_add(&mnt->mnt_list, vfsmntlist.prev);
spin_unlock(&dcache_lock);
up(&nd->dentry->d_inode->i_zombie);
- if (mnt->mnt_sb->s_type->fs_flags & FS_SINGLE)
- get_filesystem(mnt->mnt_sb->s_type);
mntget(mnt);
return 0;
fail:
@@ -520,16 +521,17 @@
int flag;
char *str;
} fs_info[] = {
- { MS_NOEXEC, ",noexec" },
- { MS_NOSUID, ",nosuid" },
- { MS_NODEV, ",nodev" },
{ MS_SYNCHRONOUS, ",sync" },
{ MS_MANDLOCK, ",mand" },
{ MS_NOATIME, ",noatime" },
{ MS_NODIRATIME, ",nodiratime" },
-#ifdef MS_NOSUB /* Can't find this except in mount.c */
- { MS_NOSUB, ",nosub" },
-#endif
+ { 0, NULL }
+};
+
+static struct proc_fs_info mnt_info[] = {
+ { MNT_NOSUID, ",nosuid" },
+ { MNT_NODEV, ",nodev" },
+ { MNT_NOEXEC, ",noexec" },
{ 0, NULL }
};
@@ -580,6 +582,10 @@
if (tmp->mnt_sb->s_flags & fs_infop->flag)
MANGLE(fs_infop->str);
}
+ for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
+ if (tmp->mnt_flags & fs_infop->flag)
+ MANGLE(fs_infop->str);
+ }
if (!strcmp("nfs", tmp->mnt_sb->s_type->name)) {
nfss = &tmp->mnt_sb->u.nfs_sb.s_server;
len += sprintf(buf+len, ",v%d", nfss->rpc_ops->version);
@@ -669,6 +675,7 @@
static void put_super(struct super_block *sb)
{
+ atomic_dec(&sb->s_active);
up_write(&sb->s_umount);
__put_super(sb);
}
@@ -735,10 +742,6 @@
s = find_super(dev);
if (s) {
spin_unlock(&sb_lock);
- /* Yes, it sucks. As soon as we get refcounting... */
- /* Almost there - next two lines will go away RSN */
- lock_super(s);
- unlock_super(s);
down_read(&s->s_umount);
if (s->s_root)
return s;
@@ -792,6 +795,7 @@
INIT_LIST_HEAD(&s->s_dirty);
INIT_LIST_HEAD(&s->s_locked_inodes);
INIT_LIST_HEAD(&s->s_files);
+ INIT_LIST_HEAD(&s->s_instances);
init_rwsem(&s->s_umount);
sema_init(&s->s_lock, 1);
s->s_count = 1;
@@ -819,7 +823,10 @@
s->s_type = type;
spin_lock(&sb_lock);
list_add (&s->s_list, super_blocks.prev);
+ list_add (&s->s_instances, &type->fs_supers);
+ s->s_count += S_BIAS;
spin_unlock(&sb_lock);
+ down_write(&s->s_umount);
lock_super(s);
if (!type->read_super(s, data, silent))
goto out_fail;
@@ -835,11 +842,12 @@
s->s_bdev = 0;
s->s_type = NULL;
unlock_super(s);
- atomic_dec(&s->s_active);
spin_lock(&sb_lock);
list_del(&s->s_list);
+ list_del(&s->s_instances);
+ s->s_count -= S_BIAS;
spin_unlock(&sb_lock);
- __put_super(s);
+ put_super(s);
return NULL;
}
@@ -871,16 +879,38 @@
kdevname(dev));
}
+static int grab_super(struct super_block *sb)
+{
+ sb->s_count++;
+ atomic_inc(&sb->s_active);
+ spin_unlock(&sb_lock);
+ down_write(&sb->s_umount);
+ if (sb->s_root) {
+ spin_lock(&sb_lock);
+ if (sb->s_count > S_BIAS) {
+ sb->s_count--;
+ spin_unlock(&sb_lock);
+ return 1;
+ }
+ spin_unlock(&sb_lock);
+ }
+ put_super(sb);
+ return 0;
+}
+
static struct super_block *get_sb_bdev(struct file_system_type *fs_type,
char *dev_name, int flags, void * data)
{
struct inode *inode;
struct block_device *bdev;
struct block_device_operations *bdops;
- struct super_block * sb;
+ struct super_block * s;
struct nameidata nd;
+ struct list_head *p;
kdev_t dev;
int error = 0;
+ mode_t mode = FMODE_READ; /* we always need it ;-) */
+
/* What device it is? */
if (!dev_name || !*dev_name)
return ERR_PTR(-EINVAL);
@@ -893,61 +923,85 @@
if (!S_ISBLK(inode->i_mode))
goto out;
error = -EACCES;
- if (IS_NODEV(inode))
+ if (nd.mnt->mnt_flags & MNT_NODEV)
goto out;
+ bd_acquire(inode);
bdev = inode->i_bdev;
bdops = devfs_get_ops ( devfs_get_handle_from_inode (inode) );
if (bdops) bdev->bd_op = bdops;
/* Done with lookups, semaphore down */
- down(&mount_sem);
dev = to_kdev_t(bdev->bd_dev);
- sb = get_super(dev);
- if (sb) {
- if (fs_type == sb->s_type &&
- ((flags ^ sb->s_flags) & MS_RDONLY) == 0) {
-/*
- * We are heavily relying on mount_sem here. We _will_ get rid of that
- * ugliness RSN (and then atomicity of ->s_active will play), but first
- * we need to get rid of "reuse" branch of get_empty_super() and that
- * requires reference counters. Chicken and egg problem, but fortunately
- * we can use the fact that right now all accesses to ->s_active are
- * under mount_sem.
- */
- if (atomic_read(&sb->s_active)) {
- spin_lock(&sb_lock);
- sb->s_count--;
- spin_unlock(&sb_lock);
- }
- atomic_inc(&sb->s_active);
- up_read(&sb->s_umount);
- path_release(&nd);
- return sb;
- }
- drop_super(sb);
- } else {
- mode_t mode = FMODE_READ; /* we always need it ;-) */
- if (!(flags & MS_RDONLY))
- mode |= FMODE_WRITE;
- error = blkdev_get(bdev, mode, 0, BDEV_FS);
- if (error)
- goto out;
- check_disk_change(dev);
- error = -EACCES;
- if (!(flags & MS_RDONLY) && is_read_only(dev))
+ if (!(flags & MS_RDONLY))
+ mode |= FMODE_WRITE;
+ error = blkdev_get(bdev, mode, 0, BDEV_FS);
+ if (error)
+ goto out;
+ check_disk_change(dev);
+ error = -EACCES;
+ if (!(flags & MS_RDONLY) && is_read_only(dev))
+ goto out1;
+
+ error = -ENOMEM;
+ s = alloc_super();
+ if (!s)
+ goto out1;
+ down_write(&s->s_umount);
+
+ error = -EBUSY;
+restart:
+ spin_lock(&sb_lock);
+
+ list_for_each(p, &super_blocks) {
+ struct super_block *old = sb_entry(p);
+ if (old->s_dev != dev)
+ continue;
+ if (old->s_type != fs_type ||
+ ((flags ^ old->s_flags) & MS_RDONLY)) {
+ spin_unlock(&sb_lock);
+ put_super(s);
goto out1;
- error = -EINVAL;
- sb = read_super(dev, bdev, fs_type, flags, data, 0);
- if (sb) {
- get_filesystem(fs_type);
- path_release(&nd);
- return sb;
}
-out1:
+ if (!grab_super(old))
+ goto restart;
+ put_super(s);
blkdev_put(bdev, BDEV_FS);
+ path_release(&nd);
+ return old;
}
+ s->s_dev = dev;
+ s->s_bdev = bdev;
+ s->s_flags = flags;
+ s->s_type = fs_type;
+ list_add (&s->s_list, super_blocks.prev);
+ list_add (&s->s_instances, &fs_type->fs_supers);
+ s->s_count += S_BIAS;
+
+ spin_unlock(&sb_lock);
+
+ error = -EINVAL;
+ lock_super(s);
+ if (!fs_type->read_super(s, data, 0))
+ goto out_fail;
+ unlock_super(s);
+ get_filesystem(fs_type);
+ path_release(&nd);
+ return s;
+
+out_fail:
+ s->s_dev = 0;
+ s->s_bdev = 0;
+ s->s_type = NULL;
+ unlock_super(s);
+ spin_lock(&sb_lock);
+ list_del(&s->s_list);
+ list_del(&s->s_instances);
+ s->s_count -= S_BIAS;
+ spin_unlock(&sb_lock);
+ put_super(s);
+out1:
+ blkdev_put(bdev, BDEV_FS);
out:
path_release(&nd);
- up(&mount_sem);
return ERR_PTR(error);
}
@@ -956,7 +1010,6 @@
{
kdev_t dev;
int error = -EMFILE;
- down(&mount_sem);
dev = get_unnamed_dev();
if (dev) {
struct super_block * sb;
@@ -968,25 +1021,65 @@
}
put_unnamed_dev(dev);
}
- up(&mount_sem);
return ERR_PTR(error);
}
static struct super_block *get_sb_single(struct file_system_type *fs_type,
int flags, void *data)
{
- struct super_block * sb;
+ struct super_block * s = alloc_super();
+ if (!s)
+ return ERR_PTR(-ENOMEM);
+ down_write(&s->s_umount);
/*
* Get the superblock of kernel-wide instance, but
* keep the reference to fs_type.
*/
- down(&mount_sem);
- sb = fs_type->kern_mnt->mnt_sb;
- if (!sb)
- BUG();
- atomic_inc(&sb->s_active);
- do_remount_sb(sb, flags, data);
- return sb;
+retry:
+ spin_lock(&sb_lock);
+ if (!list_empty(&fs_type->fs_supers)) {
+ struct super_block *old;
+ old = list_entry(fs_type->fs_supers.next, struct super_block,
+ s_instances);
+ if (!grab_super(old))
+ goto retry;
+ put_super(s);
+ do_remount_sb(old, flags, data);
+ return old;
+ } else {
+ kdev_t dev = get_unnamed_dev();
+ if (!dev) {
+ put_super(s);
+ return ERR_PTR(-EMFILE);
+ }
+ s->s_dev = dev;
+ s->s_flags = flags;
+ s->s_type = fs_type;
+ list_add (&s->s_list, super_blocks.prev);
+ list_add (&s->s_instances, &fs_type->fs_supers);
+ s->s_count += S_BIAS;
+ spin_unlock(&sb_lock);
+ lock_super(s);
+ if (!fs_type->read_super(s, data, 0))
+ goto out_fail;
+ unlock_super(s);
+ get_filesystem(fs_type);
+ return s;
+
+ out_fail:
+ s->s_dev = 0;
+ s->s_bdev = 0;
+ s->s_type = NULL;
+ unlock_super(s);
+ spin_lock(&sb_lock);
+ list_del(&s->s_list);
+ list_del(&s->s_instances);
+ s->s_count -= S_BIAS;
+ spin_unlock(&sb_lock);
+ put_super(s);
+ put_unnamed_dev(dev);
+ return ERR_PTR(-EINVAL);
+ }
}
static void kill_super(struct super_block *sb)
@@ -997,8 +1090,12 @@
struct file_system_type *fs = sb->s_type;
struct super_operations *sop = sb->s_op;
- if (!atomic_dec_and_test(&sb->s_active))
+ if (!atomic_dec_and_lock(&sb->s_active, &sb_lock))
return;
+
+ sb->s_count -= S_BIAS;
+ spin_unlock(&sb_lock);
+
down_write(&sb->s_umount);
lock_kernel();
sb->s_root = NULL;
@@ -1030,14 +1127,15 @@
sb->s_type = NULL;
unlock_super(sb);
unlock_kernel();
- if (bdev) {
+ if (bdev)
blkdev_put(bdev, BDEV_FS);
- bdput(bdev);
- } else
+ else
put_unnamed_dev(dev);
spin_lock(&sb_lock);
list_del(&sb->s_list);
+ list_del(&sb->s_instances);
spin_unlock(&sb_lock);
+ atomic_inc(&sb->s_active);
put_super(sb);
}
@@ -1056,7 +1154,7 @@
if (flags & MS_RDONLY)
acct_auto_close(sb->s_dev);
shrink_dcache_sb(sb);
- fsync_dev(sb->s_dev);
+ fsync_super(sb);
/* If we are remounting RDONLY, make sure there are no rw files open */
if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY))
if (!fs_may_remount_ro(sb))
@@ -1079,34 +1177,6 @@
return 0;
}
-struct vfsmount *kern_mount(struct file_system_type *type)
-{
- struct super_block *sb;
- struct vfsmount *mnt = alloc_vfsmnt();
- kdev_t dev;
-
- if (!mnt)
- return ERR_PTR(-ENOMEM);
-
- dev = get_unnamed_dev();
- if (!dev) {
- kmem_cache_free(mnt_cache, mnt);
- return ERR_PTR(-EMFILE);
- }
- sb = read_super(dev, NULL, type, 0, NULL, 0);
- if (!sb) {
- put_unnamed_dev(dev);
- kmem_cache_free(mnt_cache, mnt);
- return ERR_PTR(-EINVAL);
- }
- mnt->mnt_sb = sb;
- mnt->mnt_root = dget(sb->s_root);
- mnt->mnt_mountpoint = mnt->mnt_root;
- mnt->mnt_parent = mnt;
- type->kern_mnt = mnt;
- return mnt;
-}
-
/*
* Doesn't take quota and stuff into account. IOW, in some cases it will
* give false negatives. The main reason why it's here is that we need
@@ -1140,8 +1210,11 @@
* Special case for "unmounting" root ...
* we just try to remount it readonly.
*/
- if (!(sb->s_flags & MS_RDONLY))
+ if (!(sb->s_flags & MS_RDONLY)) {
+ down_write(&sb->s_umount);
retval = do_remount_sb(sb, MS_RDONLY, 0);
+ up_write(&sb->s_umount);
+ }
return retval;
}
@@ -1152,8 +1225,6 @@
spin_unlock(&dcache_lock);
return -EBUSY;
}
- if (sb->s_type->fs_flags & FS_SINGLE)
- put_filesystem(sb->s_type);
detach_mnt(mnt, &parent_nd);
list_del(&mnt->mnt_list);
spin_unlock(&dcache_lock);
@@ -1315,84 +1386,112 @@
* on it - tough luck.
*/
-static int do_remount(struct nameidata *nd, int flags, char *data)
+static int do_remount(struct nameidata *nd,int flags,int mnt_flags,char *data)
{
+ int err;
+ struct super_block * sb = nd->mnt->mnt_sb;
+
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
if (nd->dentry != nd->mnt->mnt_root)
return -EINVAL;
- return do_remount_sb(nd->mnt->mnt_sb, flags, data);
+ down_write(&sb->s_umount);
+ err = do_remount_sb(sb, flags, data);
+ if (!err)
+ nd->mnt->mnt_flags=mnt_flags;
+ up_write(&sb->s_umount);
+ return err;
}
-static int do_add_mount(struct nameidata *nd, char *type, int flags,
- char *name, void *data)
+struct vfsmount *do_kern_mount(char *type, int flags, char *name, void *data)
{
struct file_system_type * fstype;
struct vfsmount *mnt = NULL;
struct super_block *sb;
- int retval = 0;
if (!type || !memchr(type, 0, PAGE_SIZE))
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
/* we need capabilities... */
if (!capable(CAP_SYS_ADMIN))
- return -EPERM;
+ return ERR_PTR(-EPERM);
/* ... filesystem driver... */
fstype = get_fs_type(type);
if (!fstype)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
/* ... allocated vfsmount... */
- retval = -ENOMEM;
mnt = alloc_vfsmnt();
- if (!mnt)
+ if (!mnt) {
+ mnt = ERR_PTR(-ENOMEM);
goto fs_out;
+ }
if (name) {
mnt->mnt_devname = kmalloc(strlen(name)+1, GFP_KERNEL);
if (mnt->mnt_devname)
strcpy(mnt->mnt_devname, name);
}
- /* get superblock, locks mount_sem on success */
- if (fstype->fs_flags & FS_NOMOUNT)
- sb = ERR_PTR(-EINVAL);
- else if (fstype->fs_flags & FS_REQUIRES_DEV)
+ /* get locked superblock */
+ if (fstype->fs_flags & FS_REQUIRES_DEV)
sb = get_sb_bdev(fstype, name, flags, data);
else if (fstype->fs_flags & FS_SINGLE)
sb = get_sb_single(fstype, flags, data);
else
sb = get_sb_nodev(fstype, flags, data);
- retval = PTR_ERR(sb);
if (IS_ERR(sb)) {
if (mnt->mnt_devname)
kfree(mnt->mnt_devname);
kmem_cache_free(mnt_cache, mnt);
+ mnt = (struct vfsmount *)sb;
goto fs_out;
}
+ if (fstype->fs_flags & FS_NOMOUNT)
+ sb->s_flags |= MS_NOUSER;
mnt->mnt_sb = sb;
mnt->mnt_root = dget(sb->s_root);
mnt->mnt_mountpoint = mnt->mnt_root;
mnt->mnt_parent = mnt;
+ up_write(&sb->s_umount);
+fs_out:
+ put_filesystem(fstype);
+ return mnt;
+}
+struct vfsmount *kern_mount(struct file_system_type *type)
+{
+ return do_kern_mount((char *)type->name, 0, (char *)type->name, NULL);
+}
+
+static int do_add_mount(struct nameidata *nd, char *type, int flags,
+ int mnt_flags, char *name, void *data)
+{
+ struct vfsmount *mnt = do_kern_mount(type, flags, name, data);
+ int retval = PTR_ERR(mnt);
+
+ if (IS_ERR(mnt))
+ goto out;
+
+ mnt->mnt_flags = mnt_flags;
+
+ down(&mount_sem);
/* Something was mounted here while we slept */
while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
;
/* Refuse the same filesystem on the same mount point */
- if (nd->mnt->mnt_sb == sb && nd->mnt->mnt_root == nd->dentry)
+ if (nd->mnt->mnt_sb == mnt->mnt_sb && nd->mnt->mnt_root == nd->dentry)
retval = -EBUSY;
else
retval = graft_tree(mnt, nd);
- mntput(mnt);
up(&mount_sem);
-fs_out:
- put_filesystem(fstype);
+ mntput(mnt);
+out:
return retval;
}
@@ -1448,6 +1547,7 @@
{
struct nameidata nd;
int retval = 0;
+ int mnt_flags = 0;
/* Discard magic */
if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
@@ -1460,6 +1560,15 @@
if (dev_name && !memchr(dev_name, 0, PAGE_SIZE))
return -EINVAL;
+ /* Separate the per-mountpoint flags */
+ if (flags & MS_NOSUID)
+ mnt_flags |= MNT_NOSUID;
+ if (flags & MS_NODEV)
+ mnt_flags |= MNT_NODEV;
+ if (flags & MS_NOEXEC)
+ mnt_flags |= MNT_NOEXEC;
+ flags &= ~(MS_NOSUID|MS_NOEXEC|MS_NODEV);
+
/* ... and get the mountpoint */
if (path_init(dir_name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd))
retval = path_walk(dir_name, &nd);
@@ -1467,12 +1576,12 @@
return retval;
if (flags & MS_REMOUNT)
- retval = do_remount(&nd, flags&~MS_REMOUNT,
+ retval = do_remount(&nd, flags&~MS_REMOUNT, mnt_flags,
(char *)data_page);
else if (flags & MS_BIND)
retval = do_loopback(&nd, dev_name);
else
- retval = do_add_mount(&nd, type_page, flags,
+ retval = do_add_mount(&nd, type_page, flags, mnt_flags,
dev_name, data_page);
path_release(&nd);
return retval;
@@ -1607,6 +1716,7 @@
if (!ROOT_DEV)
panic("I have no root and I want to scream");
+retry:
bdev = bdget(kdev_t_to_nr(ROOT_DEV));
if (!bdev)
panic(__FUNCTION__ ": unable to allocate root device");
@@ -1618,7 +1728,7 @@
retval = blkdev_get(bdev, mode, 0, BDEV_FS);
if (retval == -EROFS) {
root_mountflags |= MS_RDONLY;
- retval = blkdev_get(bdev, FMODE_READ, 0, BDEV_FS);
+ goto retry;
}
if (retval) {
/*
@@ -1639,6 +1749,7 @@
fs_type = sb->s_type;
atomic_inc(&sb->s_active);
up_read(&sb->s_umount);
+ down_write(&sb->s_umount);
goto mount_it;
}
@@ -1659,6 +1770,8 @@
panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV));
mount_it:
+ /* FIXME */
+ up_write(&sb->s_umount);
printk ("VFS: Mounted root (%s filesystem)%s.\n",
fs_type->name,
(sb->s_flags & MS_RDONLY) ? " readonly" : "");
@@ -1863,13 +1976,18 @@
int blivet;
struct block_device *ramdisk = old_rootmnt->mnt_sb->s_bdev;
+ atomic_inc(&ramdisk->bd_count);
blivet = blkdev_get(ramdisk, FMODE_READ, 0, BDEV_FS);
printk(KERN_NOTICE "Trying to unmount old root ... ");
if (!blivet) {
blivet = do_umount(old_rootmnt, 0);
mntput(old_rootmnt);
if (!blivet) {
- ioctl_by_bdev(ramdisk, BLKFLSBUF, 0);
+ int ioctl_err;
+
+ ioctl_err = ioctl_by_bdev(ramdisk, BLKFLSBUF, 0);
+ if (ioctl_err)
+ printk("failed to release ramdisk %d...", ioctl_err);
printk("okay\n");
error = 0;
}
@@ -1906,27 +2024,36 @@
;
do {
- unsigned long tmp;
-
- nr_hash = (1UL << order) * PAGE_SIZE /
- sizeof(struct list_head);
- hash_mask = (nr_hash - 1);
-
- tmp = nr_hash;
- hash_bits = 0;
- while ((tmp >>= 1UL) != 0UL)
- hash_bits++;
-
mount_hashtable = (struct list_head *)
__get_free_pages(GFP_ATOMIC, order);
} while (mount_hashtable == NULL && --order >= 0);
- printk("Mount-cache hash table entries: %d (order: %ld, %ld bytes)\n",
- nr_hash, order, (PAGE_SIZE << order));
-
if (!mount_hashtable)
panic("Failed to allocate mount hash table\n");
+ /*
+ * Find the power-of-two list-heads that can fit into the allocation..
+ * We don't guarantee that "sizeof(struct list_head)" is necessarily
+ * a power-of-two.
+ */
+ nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct list_head);
+ hash_bits = 0;
+ do {
+ hash_bits++;
+ } while ((nr_hash >> hash_bits) != 0);
+ hash_bits--;
+
+ /*
+ * Re-calculate the actual number of entries and the mask
+ * from the number of bits we can fit.
+ */
+ nr_hash = 1UL << hash_bits;
+ hash_mask = nr_hash-1;
+
+ printk("Mount-cache hash table entries: %d (order: %ld, %ld bytes)\n",
+ nr_hash, order, (PAGE_SIZE << order));
+
+ /* And initialize the newly allocated array */
d = mount_hashtable;
i = nr_hash;
do {
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)