linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Christoph Hellwig <hch@infradead.org>, Jan Kara <jack@suse.cz>,
	linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH] BKL: Remove BKL from isofs
Date: Fri, 17 Sep 2010 21:00:06 +0200	[thread overview]
Message-ID: <201009172100.06598.arnd@arndb.de> (raw)
In-Reply-To: <201009171656.56615.arnd@arndb.de>

As in other file systems, we can replace the big kernel lock
with a private mutex in isofs. This means we can now access
multiple file systems concurrently, but it also means that
we serialize readdir and lookup across sleeping operations
which previously released the big kernel lock. This should
not matter though, as these operations are in practice
serialized through the hardware access.

The isofs_get_blocks functions now does not take any lock
any more, it used to recursively get the BKL. After looking
at the code for hours, I convinced myself that it was never
needed here anyway, because it only reads constant fields
of the inode and writes to a buffer head array that is
at this time only visible to the caller.

The get_sb and fill_super operations do not need the locking
at all because they operate on a file system that is either
about to be created or to be destroyed but in either case
is not visible to other threads.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---

 fs/isofs/dir.c   |    6 +++---
 fs/isofs/inode.c |   17 ++---------------
 fs/isofs/isofs.h |    1 +
 fs/isofs/namei.c |    8 ++++----
 fs/isofs/rock.c  |   10 +++++-----
 5 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/fs/isofs/dir.c b/fs/isofs/dir.c
index e0aca9a..0542b6e 100644
--- a/fs/isofs/dir.c
+++ b/fs/isofs/dir.c
@@ -10,7 +10,6 @@
  *
  *  isofs directory handling functions
  */
-#include <linux/smp_lock.h>
 #include <linux/gfp.h>
 #include "isofs.h"
 
@@ -255,18 +254,19 @@ static int isofs_readdir(struct file *filp,
 	char *tmpname;
 	struct iso_directory_record *tmpde;
 	struct inode *inode = filp->f_path.dentry->d_inode;
+	struct isofs_sb_info *sbi = ISOFS_SB(inode->i_sb);
 
 	tmpname = (char *)__get_free_page(GFP_KERNEL);
 	if (tmpname == NULL)
 		return -ENOMEM;
 
-	lock_kernel();
+	mutex_lock(&sbi->s_mutex);
 	tmpde = (struct iso_directory_record *) (tmpname+1024);
 
 	result = do_isofs_readdir(inode, filp, dirent, filldir, tmpname, tmpde);
 
 	free_page((unsigned long) tmpname);
-	unlock_kernel();
+	mutex_unlock(&sbi->s_mutex);
 	return result;
 }
 
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index 05baf77..09ff41a 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -17,7 +17,6 @@
 #include <linux/slab.h>
 #include <linux/nls.h>
 #include <linux/ctype.h>
-#include <linux/smp_lock.h>
 #include <linux/statfs.h>
 #include <linux/cdrom.h>
 #include <linux/parser.h>
@@ -44,11 +43,7 @@ static void isofs_put_super(struct super_block *sb)
 	struct isofs_sb_info *sbi = ISOFS_SB(sb);
 
 #ifdef CONFIG_JOLIET
-	lock_kernel();
-
 	unload_nls(sbi->s_nls_iocharset);
-
-	unlock_kernel();
 #endif
 
 	kfree(sbi);
@@ -571,15 +566,11 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
 	int table, error = -EINVAL;
 	unsigned int vol_desc_start;
 
-	lock_kernel();
-
 	save_mount_options(s, data);
 
 	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
-	if (!sbi) {
-		unlock_kernel();
+	if (!sbi)
 		return -ENOMEM;
-	}
 	s->s_fs_info = sbi;
 
 	if (!parse_options((char *)data, &opt))
@@ -827,6 +818,7 @@ root_found:
 	sbi->s_utf8 = opt.utf8;
 	sbi->s_nocompress = opt.nocompress;
 	sbi->s_overriderockperm = opt.overriderockperm;
+	mutex_init(&sbi->s_mutex);
 	/*
 	 * It would be incredibly stupid to allow people to mark every file
 	 * on the disk as suid, so we merely allow them to set the default
@@ -904,7 +896,6 @@ root_found:
 
 	kfree(opt.iocharset);
 
-	unlock_kernel();
 	return 0;
 
 	/*
@@ -944,7 +935,6 @@ out_freesbi:
 	kfree(opt.iocharset);
 	kfree(sbi);
 	s->s_fs_info = NULL;
-	unlock_kernel();
 	return error;
 }
 
@@ -983,8 +973,6 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
 	int section, rv, error;
 	struct iso_inode_info *ei = ISOFS_I(inode);
 
-	lock_kernel();
-
 	error = -EIO;
 	rv = 0;
 	if (iblock < 0 || iblock != iblock_s) {
@@ -1060,7 +1048,6 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
 
 	error = 0;
 abort:
-	unlock_kernel();
 	return rv != 0 ? rv : error;
 }
 
diff --git a/fs/isofs/isofs.h b/fs/isofs/isofs.h
index 7d33de8..2882dc0 100644
--- a/fs/isofs/isofs.h
+++ b/fs/isofs/isofs.h
@@ -55,6 +55,7 @@ struct isofs_sb_info {
 	gid_t s_gid;
 	uid_t s_uid;
 	struct nls_table *s_nls_iocharset; /* Native language support table */
+	struct mutex s_mutex; /* replaces BKL, please remove if possible */
 };
 
 #define ISOFS_INVALID_MODE ((mode_t) -1)
diff --git a/fs/isofs/namei.c b/fs/isofs/namei.c
index ab438be..0d23abf 100644
--- a/fs/isofs/namei.c
+++ b/fs/isofs/namei.c
@@ -6,7 +6,6 @@
  *  (C) 1991  Linus Torvalds - minix filesystem
  */
 
-#include <linux/smp_lock.h>
 #include <linux/gfp.h>
 #include "isofs.h"
 
@@ -168,6 +167,7 @@ struct dentry *isofs_lookup(struct inode *dir, struct dentry *dentry, struct nam
 	int found;
 	unsigned long uninitialized_var(block);
 	unsigned long uninitialized_var(offset);
+	struct isofs_sb_info *sbi = ISOFS_SB(dir->i_sb);
 	struct inode *inode;
 	struct page *page;
 
@@ -177,7 +177,7 @@ struct dentry *isofs_lookup(struct inode *dir, struct dentry *dentry, struct nam
 	if (!page)
 		return ERR_PTR(-ENOMEM);
 
-	lock_kernel();
+	mutex_lock(&sbi->s_mutex);
 	found = isofs_find_entry(dir, dentry,
 				&block, &offset,
 				page_address(page),
@@ -188,10 +188,10 @@ struct dentry *isofs_lookup(struct inode *dir, struct dentry *dentry, struct nam
 	if (found) {
 		inode = isofs_iget(dir->i_sb, block, offset);
 		if (IS_ERR(inode)) {
-			unlock_kernel();
+			mutex_unlock(&sbi->s_mutex);
 			return ERR_CAST(inode);
 		}
 	}
-	unlock_kernel();
+	mutex_unlock(&sbi->s_mutex);
 	return d_splice_alias(inode, dentry);
 }
diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
index 96a685c..f9cd04d 100644
--- a/fs/isofs/rock.c
+++ b/fs/isofs/rock.c
@@ -8,7 +8,6 @@
 
 #include <linux/slab.h>
 #include <linux/pagemap.h>
-#include <linux/smp_lock.h>
 
 #include "isofs.h"
 #include "rock.h"
@@ -661,6 +660,7 @@ static int rock_ridge_symlink_readpage(struct file *file, struct page *page)
 {
 	struct inode *inode = page->mapping->host;
 	struct iso_inode_info *ei = ISOFS_I(inode);
+	struct isofs_sb_info *sbi = ISOFS_SB(inode->i_sb);
 	char *link = kmap(page);
 	unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
 	struct buffer_head *bh;
@@ -673,12 +673,12 @@ static int rock_ridge_symlink_readpage(struct file *file, struct page *page)
 	struct rock_state rs;
 	int ret;
 
-	if (!ISOFS_SB(inode->i_sb)->s_rock)
+	if (!sbi->s_rock)
 		goto error;
 
 	init_rock_state(&rs, inode);
 	block = ei->i_iget5_block;
-	lock_kernel();
+	mutex_lock(&sbi->s_mutex);
 	bh = sb_bread(inode->i_sb, block);
 	if (!bh)
 		goto out_noread;
@@ -748,7 +748,7 @@ repeat:
 		goto fail;
 	brelse(bh);
 	*rpnt = '\0';
-	unlock_kernel();
+	mutex_unlock(&sbi->s_mutex);
 	SetPageUptodate(page);
 	kunmap(page);
 	unlock_page(page);
@@ -765,7 +765,7 @@ out_bad_span:
 	printk("symlink spans iso9660 blocks\n");
 fail:
 	brelse(bh);
-	unlock_kernel();
+	mutex_unlock(&sbi->s_mutex);
 error:
 	SetPageError(page);
 	kunmap(page);

  reply	other threads:[~2010-09-17 19:00 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-16 14:32 Remaining BKL users, what to do Arnd Bergmann
2010-09-16 14:49 ` Steven Rostedt
2010-09-16 18:32   ` Jens Axboe
2010-09-17 18:46     ` Arnd Bergmann
2010-09-16 15:04 ` Jan Kara
2010-09-16 21:26   ` Anton Altaparmakov
2010-09-17 10:45     ` Arnd Bergmann
2010-09-17 13:32       ` Christoph Hellwig
2010-09-17 13:50         ` Arnd Bergmann
2010-09-17 14:02           ` Christoph Hellwig
2010-09-17 14:56             ` Arnd Bergmann
2010-09-17 19:00               ` Arnd Bergmann [this message]
2010-09-20 10:58                 ` [PATCH] BKL: Remove BKL from isofs Jan Kara
2010-09-20 11:13                   ` Arnd Bergmann
2010-09-20 15:18                     ` Jan Kara
2010-09-20 15:40                       ` Alexander E. Patrakov
2010-09-20 15:50                         ` Jan Kara
2010-09-16 15:07 ` Remaining BKL users, what to do Alan Cox
2010-09-16 20:08   ` David Miller
2010-09-16 16:09 ` Anders Larsen
2010-09-16 16:57 ` Samuel Ortiz
2010-09-16 20:08   ` David Miller
2010-09-16 19:00 ` Jan Harkes
2010-09-16 19:26   ` Arnd Bergmann
2010-09-20  1:25 ` [autofs] " Ian Kent
2010-10-18 15:42 ` [v2] " Arnd Bergmann
2010-10-18 16:19   ` Christoph Hellwig
2010-10-18 17:38     ` Arnd Bergmann
2010-10-18 18:43   ` [Ksummit-2010-discuss] " Greg KH
2010-10-18 23:00     ` Dave Airlie
2010-10-19  0:40       ` Greg KH
2010-10-19  0:57         ` Dave Airlie
2010-10-19  2:24           ` Greg KH
2010-10-19  2:45             ` Dave Airlie
2010-10-19  3:33               ` Steven Rostedt
2010-10-19  4:03                 ` Dave Airlie
2010-10-19  5:00                 ` Theodore Kilgore
2010-10-19  4:52                   ` Dave Airlie
2010-10-19  7:26                     ` Arnd Bergmann
2010-10-19 12:39                       ` Steven Rostedt
2010-10-19 13:54                         ` Paul Mundt
2010-10-19 13:26                       ` Arnd Bergmann
2010-10-19 20:50                         ` Dave Airlie
2010-10-20 16:14                           ` Ville Syrjälä
2010-10-19 18:24         ` Valdis.Kletnieks
2010-10-19 19:37           ` Greg KH
2010-10-19 19:40             ` Oliver Neukum
2010-10-19 20:29               ` Greg KH
2010-10-19 20:38                 ` Jiri Kosina
2010-10-19 20:41                 ` Alan Cox
2010-10-19 20:48                   ` Arnd Bergmann
2010-10-19 20:44                 ` Arnd Bergmann
2010-10-20  4:43                   ` Dave Young
2010-10-20  6:50                     ` Arnd Bergmann
2010-11-02  1:21                   ` Pavel Machek
2010-11-03  6:58                     ` Pekka Enberg
2010-10-21 12:47 ` Christoph Hellwig
2010-10-21 13:38   ` Arnd Bergmann
2010-10-21 13:50     ` [PATCH 1/2] BKL: remove BKL from qnx4 Arnd Bergmann
2010-10-21 15:22       ` Anders Larsen
2010-10-21 13:51     ` [PATCH 2/2] BKL: remove BKL from freevxfs Arnd Bergmann

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=201009172100.06598.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=hch@infradead.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@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).