2009-07-26 08:22:00

by Thomas Gleixner

[permalink] [raw]
Subject: [Patch RFC 36/37] fs: Convert bd_mount_sem to mutex

bd_mount_sem is used as mutex so make it a mutex.

Signed-off-by: Thomas Gleixner <[email protected]>
Cc: Al Viro <[email protected]>
---
fs/block_dev.c | 8 ++++----
fs/super.c | 4 ++--
include/linux/fs.h | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)

Index: linux-2.6-tip/fs/block_dev.c
===================================================================
--- linux-2.6-tip.orig/fs/block_dev.c
+++ linux-2.6-tip/fs/block_dev.c
@@ -240,7 +240,7 @@ struct super_block *freeze_bdev(struct b
}
bdev->bd_fsfreeze_count++;

- down(&bdev->bd_mount_sem);
+ mutex_lock(&bdev->bd_mount_sem);
sb = get_super(bdev);
if (sb && !(sb->s_flags & MS_RDONLY)) {
sb->s_frozen = SB_FREEZE_WRITE;
@@ -260,7 +260,7 @@ struct super_block *freeze_bdev(struct b
"VFS:Filesystem freeze failed\n");
sb->s_frozen = SB_UNFROZEN;
drop_super(sb);
- up(&bdev->bd_mount_sem);
+ mutex_unlock(&bdev->bd_mount_sem);
bdev->bd_fsfreeze_count--;
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return ERR_PTR(error);
@@ -321,7 +321,7 @@ int thaw_bdev(struct block_device *bdev,
drop_super(sb);
}

- up(&bdev->bd_mount_sem);
+ mutex_unlock(&bdev->bd_mount_sem);
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return 0;
}
@@ -431,7 +431,7 @@ static void init_once(void *foo)

memset(bdev, 0, sizeof(*bdev));
mutex_init(&bdev->bd_mutex);
- sema_init(&bdev->bd_mount_sem, 1);
+ mutex_init(&bdev->bd_mount_sem);
INIT_LIST_HEAD(&bdev->bd_inodes);
INIT_LIST_HEAD(&bdev->bd_list);
#ifdef CONFIG_SYSFS
Index: linux-2.6-tip/fs/super.c
===================================================================
--- linux-2.6-tip.orig/fs/super.c
+++ linux-2.6-tip/fs/super.c
@@ -740,9 +740,9 @@ int get_sb_bdev(struct file_system_type
* will protect the lockfs code from trying to start a snapshot
* while we are mounting
*/
- down(&bdev->bd_mount_sem);
+ mutex_lock(&bdev->bd_mount_sem);
s = sget(fs_type, test_bdev_super, set_bdev_super, bdev);
- up(&bdev->bd_mount_sem);
+ mutex_unlock(&bdev->bd_mount_sem);
if (IS_ERR(s))
goto error_s;

Index: linux-2.6-tip/include/linux/fs.h
===================================================================
--- linux-2.6-tip.orig/include/linux/fs.h
+++ linux-2.6-tip/include/linux/fs.h
@@ -640,7 +640,7 @@ struct block_device {
struct super_block * bd_super;
int bd_openers;
struct mutex bd_mutex; /* open/close mutex */
- struct semaphore bd_mount_sem;
+ struct mutex bd_mount_sem;
struct list_head bd_inodes;
void * bd_holder;
int bd_holders;


2009-07-27 15:26:37

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [Patch RFC 36/37] fs: Convert bd_mount_sem to mutex

On Sun, Jul 26, 2009 at 08:20:38AM -0000, Thomas Gleixner wrote:
> bd_mount_sem is used as mutex so make it a mutex.

Actually we may return to userspace with it held, so the conversion
is a bad idea. But I have a patch I need to post to completely get
rid of it.

2009-07-27 15:31:09

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [Patch RFC 36/37] fs: Convert bd_mount_sem to mutex


On Mon, 27 Jul 2009, Christoph Hellwig wrote:

> On Sun, Jul 26, 2009 at 08:20:38AM -0000, Thomas Gleixner wrote:
> > bd_mount_sem is used as mutex so make it a mutex.
>
> Actually we may return to userspace with it held, so the conversion
> is a bad idea. But I have a patch I need to post to completely get
> rid of it.

That's why it's RFC :)

2009-07-27 16:42:21

by Daniel Walker

[permalink] [raw]
Subject: Re: [Patch RFC 36/37] fs: Convert bd_mount_sem to mutex

On Mon, 2009-07-27 at 17:30 +0200, Thomas Gleixner wrote:
> On Mon, 27 Jul 2009, Christoph Hellwig wrote:
>
> > On Sun, Jul 26, 2009 at 08:20:38AM -0000, Thomas Gleixner wrote:
> > > bd_mount_sem is used as mutex so make it a mutex.
> >
> > Actually we may return to userspace with it held, so the conversion
> > is a bad idea. But I have a patch I need to post to completely get
> > rid of it.
>
> That's why it's RFC :)

You better inspect these at much greater detail.. Matthias (added to the
CC) , and I did a great number of semaphore to mutex changes and I don't
recall there being too many clear easy ones remaining .. So unless the
semaphore was added in the past 12 months or so , I'd treat it as likely
unsafe for converting to a mutex..

Daniel