From: Jan Blunck <jblunck@suse.de>
To: linux-fsdevel@vger.kernel.org
Subject: [RFC 2/3] BKL: remove from ext2
Date: Wed, 30 Sep 2009 17:30:03 +0200 [thread overview]
Message-ID: <1254324604-20243-3-git-send-email-jblunck@suse.de> (raw)
In-Reply-To: <1254324604-20243-1-git-send-email-jblunck@suse.de>
Remove the big kernel lock from ext2 and replace it with a per superblock
mutex.
Signed-off-by: Jan Blunck <jblunck@suse.de>
---
fs/ext2/inode.c | 5 +--
fs/ext2/super.c | 70 +++++++++++++++++++++++++++++---------------
include/linux/ext2_fs_sb.h | 1 +
3 files changed, 49 insertions(+), 27 deletions(-)
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index ade6340..8b51416 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -22,7 +22,6 @@
* Assorted race fixes, rewrite of ext2_get_block() by Al Viro, 2000
*/
-#include <linux/smp_lock.h>
#include <linux/time.h>
#include <linux/highuid.h>
#include <linux/pagemap.h>
@@ -1400,11 +1399,11 @@ int ext2_write_inode(struct inode *inode, int do_sync)
/* If this is the first large file
* created, add a flag to the superblock.
*/
- lock_kernel();
+ mutex_lock(&EXT2_SB(sb)->s_mutex);
ext2_update_dynamic_rev(sb);
EXT2_SET_RO_COMPAT_FEATURE(sb,
EXT2_FEATURE_RO_COMPAT_LARGE_FILE);
- unlock_kernel();
+ mutex_unlock(&EXT2_SB(sb)->s_mutex);
ext2_write_super(sb);
}
}
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 5af1775..87a19df 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -26,7 +26,6 @@
#include <linux/random.h>
#include <linux/buffer_head.h>
#include <linux/exportfs.h>
-#include <linux/smp_lock.h>
#include <linux/vfs.h>
#include <linux/seq_file.h>
#include <linux/mount.h>
@@ -43,6 +42,7 @@ static void ext2_sync_super(struct super_block *sb,
static int ext2_remount (struct super_block * sb, int * flags, char * data);
static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf);
static int ext2_sync_fs(struct super_block *sb, int wait);
+static int ext2_sync_fs_locked(struct super_block *sb, int wait);
void ext2_error (struct super_block * sb, const char * function,
const char * fmt, ...)
@@ -83,7 +83,9 @@ void ext2_warning (struct super_block * sb, const char * function,
printk("\n");
va_end(args);
}
-
+/*
+ * This is called with sbi->s_mutex held.
+ */
void ext2_update_dynamic_rev(struct super_block *sb)
{
struct ext2_super_block *es = EXT2_SB(sb)->s_es;
@@ -109,16 +111,17 @@ void ext2_update_dynamic_rev(struct super_block *sb)
*/
}
+/*
+ * This is called with sb->s_umount held for writing.
+ */
static void ext2_put_super (struct super_block * sb)
{
int db_count;
int i;
struct ext2_sb_info *sbi = EXT2_SB(sb);
- lock_kernel();
-
- if (sb->s_dirt)
- ext2_write_super(sb);
+ if (sb->s_dirt && !(sb->s_flags & MS_RDONLY))
+ ext2_sync_fs_locked(sb, 1);
ext2_xattr_put_super(sb);
if (!(sb->s_flags & MS_RDONLY)) {
@@ -140,8 +143,6 @@ static void ext2_put_super (struct super_block * sb)
sb->s_fs_info = NULL;
kfree(sbi->s_blockgroup_lock);
kfree(sbi);
-
- unlock_kernel();
}
static struct kmem_cache * ext2_inode_cachep;
@@ -207,6 +208,7 @@ static int ext2_show_options(struct seq_file *seq, struct vfsmount *vfs)
struct ext2_super_block *es = sbi->s_es;
unsigned long def_mount_opts;
+ mutex_lock(&sbi->s_mutex);
def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
if (sbi->s_sb_block != 1)
@@ -279,6 +281,7 @@ static int ext2_show_options(struct seq_file *seq, struct vfsmount *vfs)
if (!test_opt(sb, RESERVATION))
seq_puts(seq, ",noreservation");
+ mutex_unlock(&sbi->s_mutex);
return 0;
}
@@ -727,6 +730,9 @@ static unsigned long descriptor_loc(struct super_block *sb,
return ext2_group_first_block_no(sb, bg) + has_super;
}
+/*
+ * This is called with sb->s_umount held for writing.
+ */
static int ext2_fill_super(struct super_block *sb, void *data, int silent)
{
struct buffer_head * bh;
@@ -745,8 +751,6 @@ 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)
@@ -762,6 +766,12 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
sbi->s_sb_block = sb_block;
/*
+ * mutex for protection of modifications of the superblock while being
+ * write out by ext2_write_super() or ext2_sync_fs().
+ */
+ mutex_init(&sbi->s_mutex);
+
+ /*
* See what the current blocksize for the device is, and
* use that as the blocksize. Otherwise (or if the blocksize
* is smaller than the default) use the default.
@@ -1066,7 +1076,6 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
ext2_warning(sb, __func__,
"mounting ext3 filesystem as ext2");
ext2_setup_super (sb, es, sb->s_flags & MS_RDONLY);
- unlock_kernel();
return 0;
cantfind_ext2:
@@ -1091,7 +1100,6 @@ failed_sbi:
kfree(sbi->s_blockgroup_lock);
kfree(sbi);
failed_unlock:
- unlock_kernel();
return ret;
}
@@ -1124,11 +1132,10 @@ static void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es)
* set s_state to EXT2_VALID_FS after some corrections.
*/
-static int ext2_sync_fs(struct super_block *sb, int wait)
+static int ext2_sync_fs_locked(struct super_block *sb, int wait)
{
struct ext2_super_block *es = EXT2_SB(sb)->s_es;
- lock_kernel();
if (es->s_state & cpu_to_le16(EXT2_VALID_FS)) {
ext2_debug("setting valid to 0\n");
es->s_state &= cpu_to_le16(~EXT2_VALID_FS);
@@ -1138,22 +1145,34 @@ static int ext2_sync_fs(struct super_block *sb, int wait)
cpu_to_le32(ext2_count_free_inodes(sb));
es->s_mtime = cpu_to_le32(get_seconds());
ext2_sync_super(sb, es);
- } else {
+ } else
ext2_commit_super(sb, es);
- }
- sb->s_dirt = 0;
- unlock_kernel();
+ sb->s_dirt = 0;
return 0;
}
+static int ext2_sync_fs(struct super_block *sb, int wait)
+{
+ struct ext2_sb_info * sbi = EXT2_SB(sb);
+ int ret;
+
+ mutex_lock(&sbi->s_mutex);
+ ret = ext2_sync_fs_locked(sb, wait);
+ mutex_unlock(&sbi->s_mutex);
+ return ret;
+}
void ext2_write_super(struct super_block *sb)
{
+ struct ext2_sb_info * sbi = EXT2_SB(sb);
+
+ mutex_lock(&sbi->s_mutex);
if (!(sb->s_flags & MS_RDONLY))
- ext2_sync_fs(sb, 1);
+ ext2_sync_fs_locked(sb, 1);
else
sb->s_dirt = 0;
+ mutex_unlock(&sbi->s_mutex);
}
static int ext2_remount (struct super_block * sb, int * flags, char * data)
@@ -1165,7 +1184,7 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
unsigned long old_sb_flags;
int err;
- lock_kernel();
+ mutex_lock(&sbi->s_mutex);
/* Store the old options */
old_sb_flags = sb->s_flags;
@@ -1203,13 +1222,13 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
sbi->s_mount_opt |= old_mount_opt & EXT2_MOUNT_XIP;
}
if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
- unlock_kernel();
+ mutex_unlock(&sbi->s_mutex);
return 0;
}
if (*flags & MS_RDONLY) {
if (le16_to_cpu(es->s_state) & EXT2_VALID_FS ||
!(sbi->s_mount_state & EXT2_VALID_FS)) {
- unlock_kernel();
+ mutex_unlock(&sbi->s_mutex);
return 0;
}
/*
@@ -1238,14 +1257,14 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
sb->s_flags &= ~MS_RDONLY;
}
ext2_sync_super(sb, es);
- unlock_kernel();
+ mutex_unlock(&sbi->s_mutex);
return 0;
restore_opts:
sbi->s_mount_opt = old_opts.s_mount_opt;
sbi->s_resuid = old_opts.s_resuid;
sbi->s_resgid = old_opts.s_resgid;
sb->s_flags = old_sb_flags;
- unlock_kernel();
+ mutex_unlock(&sbi->s_mutex);
return err;
}
@@ -1256,6 +1275,8 @@ static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)
struct ext2_super_block *es = sbi->s_es;
u64 fsid;
+ mutex_lock(&sbi->s_mutex);
+
if (test_opt (sb, MINIX_DF))
sbi->s_overhead_last = 0;
else if (sbi->s_blocks_last != le32_to_cpu(es->s_blocks_count)) {
@@ -1310,6 +1331,7 @@ static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)
le64_to_cpup((void *)es->s_uuid + sizeof(u64));
buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
+ mutex_unlock(&sbi->s_mutex);
return 0;
}
diff --git a/include/linux/ext2_fs_sb.h b/include/linux/ext2_fs_sb.h
index 1cdb663..964b432 100644
--- a/include/linux/ext2_fs_sb.h
+++ b/include/linux/ext2_fs_sb.h
@@ -106,6 +106,7 @@ struct ext2_sb_info {
spinlock_t s_rsv_window_lock;
struct rb_root s_rsv_window_root;
struct ext2_reserve_window_node s_rsv_window_head;
+ struct mutex s_mutex;
};
static inline spinlock_t *
--
1.6.4.2
next prev parent reply other threads:[~2009-09-30 15:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-30 15:30 [RFC 0/3] Remove BKL from fs/ Jan Blunck
2009-09-30 15:30 ` [RFC 1/3] BKL pushdown from do_new_mount() to the filesystems Jan Blunck
2009-09-30 15:46 ` Matthew Wilcox
2009-10-01 18:05 ` Jan Blunck
2009-10-08 15:49 ` Boaz Harrosh
2009-10-31 12:26 ` Jan Blunck
2009-09-30 15:30 ` Jan Blunck [this message]
2009-10-01 18:01 ` [RFC 2/3] BKL: remove from ext2 Christoph Hellwig
2009-10-31 12:24 ` Jan Blunck
2009-10-07 5:44 ` Andi Kleen
2009-09-30 15:30 ` [RFC 3/3] BKL: Remove default_llseek() Jan Blunck
2009-10-01 18:06 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1254324604-20243-3-git-send-email-jblunck@suse.de \
--to=jblunck@suse.de \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).