Skip to content

Commit

Permalink
BKL: Explicitly add BKL around get_sb/fill_super
Browse files Browse the repository at this point in the history
This patch is a preparation necessary to remove the BKL from do_new_mount().
It explicitly adds calls to lock_kernel()/unlock_kernel() around
get_sb/fill_super operations for filesystems that still uses the BKL.

I've read through all the code formerly covered by the BKL inside
do_kern_mount() and have satisfied myself that it doesn't need the BKL
any more.

do_kern_mount() is already called without the BKL when mounting the rootfs
and in nfsctl. do_kern_mount() calls vfs_kern_mount(), which is called
from various places without BKL: simple_pin_fs(), nfs_do_clone_mount()
through nfs_follow_mountpoint(), afs_mntpt_do_automount() through
afs_mntpt_follow_link(). Both later functions are actually the filesystems
follow_link inode operation. vfs_kern_mount() is calling the specified
get_sb function and lets the filesystem do its job by calling the given
fill_super function.

Therefore I think it is safe to push down the BKL from the VFS to the
low-level filesystems get_sb/fill_super operation.

[arnd: do not add the BKL to those file systems that already
       don't use it elsewhere]

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Christoph Hellwig <hch@infradead.org>
  • Loading branch information
jblunck authored and arndb committed Oct 4, 2010
1 parent 899611e commit db71922
Show file tree
Hide file tree
Showing 28 changed files with 187 additions and 25 deletions.
8 changes: 7 additions & 1 deletion fs/adfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,15 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
struct adfs_sb_info *asb;
struct inode *root;

lock_kernel();

sb->s_flags |= MS_NODIRATIME;

asb = kzalloc(sizeof(*asb), GFP_KERNEL);
if (!asb)
if (!asb) {
unlock_kernel();
return -ENOMEM;
}
sb->s_fs_info = asb;

/* set default options */
Expand Down Expand Up @@ -474,13 +478,15 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
goto error;
} else
sb->s_root->d_op = &adfs_dentry_operations;
unlock_kernel();
return 0;

error_free_bh:
brelse(bh);
error:
sb->s_fs_info = NULL;
kfree(asb);
unlock_kernel();
return -EINVAL;
}

Expand Down
9 changes: 8 additions & 1 deletion fs/affs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
u8 sig[4];
int ret = -EINVAL;

lock_kernel();

save_mount_options(sb, data);

pr_debug("AFFS: read_super(%s)\n",data ? (const char *)data : "no options");
Expand All @@ -300,8 +302,10 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
sb->s_flags |= MS_NODIRATIME;

sbi = kzalloc(sizeof(struct affs_sb_info), GFP_KERNEL);
if (!sbi)
if (!sbi) {
unlock_kernel();
return -ENOMEM;
}
sb->s_fs_info = sbi;
mutex_init(&sbi->s_bmlock);
spin_lock_init(&sbi->symlink_lock);
Expand All @@ -312,6 +316,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
printk(KERN_ERR "AFFS: Error parsing options\n");
kfree(sbi->s_prefix);
kfree(sbi);
unlock_kernel();
return -EINVAL;
}
/* N.B. after this point s_prefix must be released */
Expand Down Expand Up @@ -482,6 +487,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
sb->s_root->d_op = &affs_dentry_operations;

pr_debug("AFFS: s_flags=%lX\n",sb->s_flags);
unlock_kernel();
return 0;

/*
Expand All @@ -496,6 +502,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
kfree(sbi->s_prefix);
kfree(sbi);
sb->s_fs_info = NULL;
unlock_kernel();
return ret;
}

Expand Down
5 changes: 5 additions & 0 deletions fs/afs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,15 @@ static int afs_fill_super(struct super_block *sb, void *data)
struct inode *inode = NULL;
int ret;

lock_kernel();

_enter("");

/* allocate a superblock info record */
as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL);
if (!as) {
_leave(" = -ENOMEM");
unlock_kernel();
return -ENOMEM;
}

Expand Down Expand Up @@ -341,6 +344,7 @@ static int afs_fill_super(struct super_block *sb, void *data)
sb->s_root = root;

_leave(" = 0");
unlock_kernel();
return 0;

error_inode:
Expand All @@ -354,6 +358,7 @@ static int afs_fill_super(struct super_block *sb, void *data)
sb->s_fs_info = NULL;

_leave(" = %d", ret);
unlock_kernel();
return ret;
}

Expand Down
8 changes: 7 additions & 1 deletion fs/bfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,13 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
int ret = -EINVAL;
unsigned long i_sblock, i_eblock, i_eoff, s_size;

lock_kernel();

info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info)
if (!info) {
unlock_kernel();
return -ENOMEM;
}
mutex_init(&info->bfs_lock);
s->s_fs_info = info;

Expand Down Expand Up @@ -439,6 +443,7 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
brelse(bh);
brelse(sbh);
dump_imap("read_super", s);
unlock_kernel();
return 0;

out3:
Expand All @@ -452,6 +457,7 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
mutex_destroy(&info->bfs_lock);
kfree(info);
s->s_fs_info = NULL;
unlock_kernel();
return ret;
}

Expand Down
12 changes: 10 additions & 2 deletions fs/cifs/cifsfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,22 +514,30 @@ cifs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
int rc;
struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
struct super_block *sb;

lock_kernel();

sb = sget(fs_type, NULL, set_anon_super, NULL);

cFYI(1, "Devname: %s flags: %d ", dev_name, flags);

if (IS_ERR(sb))
if (IS_ERR(sb)) {
unlock_kernel();
return PTR_ERR(sb);
}

sb->s_flags = flags;

rc = cifs_read_super(sb, data, dev_name, flags & MS_SILENT ? 1 : 0);
if (rc) {
deactivate_locked_super(sb);
unlock_kernel();
return rc;
}
sb->s_flags |= MS_ACTIVE;
simple_set_mnt(mnt, sb);
unlock_kernel();
return 0;
}

Expand Down
8 changes: 7 additions & 1 deletion fs/coda/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
int error;
int idx;

lock_kernel();

idx = get_device_index((struct coda_mount_data *) data);

/* Ignore errors in data, for backward compatibility */
Expand All @@ -159,11 +161,13 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
vc = &coda_comms[idx];
if (!vc->vc_inuse) {
printk("coda_read_super: No pseudo device\n");
unlock_kernel();
return -EINVAL;
}

if ( vc->vc_sb ) {
printk("coda_read_super: Device already mounted\n");
unlock_kernel();
return -EBUSY;
}

Expand Down Expand Up @@ -202,7 +206,8 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
sb->s_root = d_alloc_root(root);
if (!sb->s_root)
goto error;
return 0;
unlock_kernel();
return 0;

error:
bdi_destroy(&vc->bdi);
Expand All @@ -212,6 +217,7 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
if (vc)
vc->vc_sb = NULL;

unlock_kernel();
return -EINVAL;
}

Expand Down
4 changes: 4 additions & 0 deletions fs/ecryptfs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <linux/parser.h>
#include <linux/fs_stack.h>
#include <linux/slab.h>
#include <linux/smp_lock.h> /* For lock_kernel() */
#include "ecryptfs_kernel.h"

/**
Expand Down Expand Up @@ -550,6 +551,7 @@ static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags,
const char *err = "Getting sb failed";
int rc;

lock_kernel();
sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL);
if (!sbi) {
rc = -ENOMEM;
Expand Down Expand Up @@ -608,6 +610,7 @@ static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags,
goto out;
}
simple_set_mnt(mnt, s);
unlock_kernel();
return 0;

out:
Expand All @@ -616,6 +619,7 @@ static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags,
kmem_cache_free(ecryptfs_sb_info_cache, sbi);
}
printk(KERN_ERR "%s; rc = [%d]\n", err, rc);
unlock_kernel();
return rc;
}

Expand Down
10 changes: 8 additions & 2 deletions fs/ext2/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,15 +747,18 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
__le32 features;
int err;

lock_kernel();

err = -ENOMEM;
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
if (!sbi)
return -ENOMEM;
goto failed_unlock;

sbi->s_blockgroup_lock =
kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
if (!sbi->s_blockgroup_lock) {
kfree(sbi);
return -ENOMEM;
goto failed_unlock;
}
sb->s_fs_info = sbi;
sbi->s_sb_block = sb_block;
Expand Down Expand Up @@ -1083,6 +1086,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
if (ext2_setup_super (sb, es, sb->s_flags & MS_RDONLY))
sb->s_flags |= MS_RDONLY;
ext2_write_super(sb);
unlock_kernel();
return 0;

cantfind_ext2:
Expand All @@ -1107,6 +1111,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
sb->s_fs_info = NULL;
kfree(sbi->s_blockgroup_lock);
kfree(sbi);
failed_unlock:
unlock_kernel();
return ret;
}

Expand Down
9 changes: 8 additions & 1 deletion fs/ext3/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1611,14 +1611,19 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
__le32 features;
int err;

lock_kernel();

sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
if (!sbi)
if (!sbi) {
unlock_kernel();
return -ENOMEM;
}

sbi->s_blockgroup_lock =
kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
if (!sbi->s_blockgroup_lock) {
kfree(sbi);
unlock_kernel();
return -ENOMEM;
}
sb->s_fs_info = sbi;
Expand Down Expand Up @@ -2026,6 +2031,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
"writeback");

lock_kernel();
unlock_kernel();
return 0;

cantfind_ext3:
Expand Down Expand Up @@ -2056,6 +2062,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
kfree(sbi->s_blockgroup_lock);
kfree(sbi);
lock_kernel();
unlock_kernel();
return ret;
}

Expand Down
8 changes: 6 additions & 2 deletions fs/ext4/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
int err;
unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;

lock_kernel();

sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
if (!sbi)
goto out_free_orig;
Expand Down Expand Up @@ -3166,7 +3168,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
if (es->s_error_count)
mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */

lock_kernel();
kfree(orig_data);
return 0;

Expand Down Expand Up @@ -3213,8 +3214,11 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
sb->s_fs_info = NULL;
kfree(sbi->s_blockgroup_lock);
kfree(sbi);
lock_kernel();
kfree(orig_data);
return ret;

out_free_orig:
unlock_kernel();
kfree(orig_data);
return ret;
}
Expand Down
7 changes: 6 additions & 1 deletion fs/fat/namei_msdos.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <linux/module.h>
#include <linux/time.h>
#include <linux/buffer_head.h>
#include <linux/smp_lock.h> /* For lock_kernel() */
#include "fat.h"

/* Characters that are undesirable in an MS-DOS file name */
Expand Down Expand Up @@ -662,12 +663,16 @@ static int msdos_fill_super(struct super_block *sb, void *data, int silent)
{
int res;

lock_kernel();
res = fat_fill_super(sb, data, silent, &msdos_dir_inode_operations, 0);
if (res)
if (res) {
unlock_kernel();
return res;
}

sb->s_flags |= MS_NOATIME;
sb->s_root->d_op = &msdos_dentry_operations;
unlock_kernel();
return 0;
}

Expand Down
Loading

0 comments on commit db71922

Please sign in to comment.