Skip to content

Commit aa7dfb8

Browse files
konisAl Viro
authored andcommitted
nilfs2: get rid of bd_mount_sem use from nilfs
This will remove every bd_mount_sem use in nilfs. The intended exclusion control was replaced by the previous patch ("nilfs2: correct exclusion control in nilfs_remount function") for nilfs_remount(), and this patch will replace remains with a new mutex that this inserts in nilfs object. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> Cc: Christoph Hellwig <hch@infradead.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent e59399d commit aa7dfb8

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

fs/nilfs2/cpfile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,11 +864,11 @@ int nilfs_cpfile_change_cpmode(struct inode *cpfile, __u64 cno, int mode)
864864
case NILFS_CHECKPOINT:
865865
/*
866866
* Check for protecting existing snapshot mounts:
867-
* bd_mount_sem is used to make this operation atomic and
867+
* ns_mount_mutex is used to make this operation atomic and
868868
* exclusive with a new mount job. Though it doesn't cover
869869
* umount, it's enough for the purpose.
870870
*/
871-
down(&nilfs->ns_bdev->bd_mount_sem);
871+
mutex_lock(&nilfs->ns_mount_mutex);
872872
if (nilfs_checkpoint_is_mounted(nilfs, cno, 1)) {
873873
/* Current implementation does not have to protect
874874
plain read-only mounts since they are exclusive
@@ -877,7 +877,7 @@ int nilfs_cpfile_change_cpmode(struct inode *cpfile, __u64 cno, int mode)
877877
ret = -EBUSY;
878878
} else
879879
ret = nilfs_cpfile_clear_snapshot(cpfile, cno);
880-
up(&nilfs->ns_bdev->bd_mount_sem);
880+
mutex_unlock(&nilfs->ns_mount_mutex);
881881
return ret;
882882
case NILFS_SNAPSHOT:
883883
return nilfs_cpfile_set_snapshot(cpfile, cno);

fs/nilfs2/super.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ int nilfs_store_magic_and_option(struct super_block *sb,
764764
* @silent: silent mode flag
765765
* @nilfs: the_nilfs struct
766766
*
767-
* This function is called exclusively by bd_mount_mutex.
767+
* This function is called exclusively by nilfs->ns_mount_mutex.
768768
* So, the recovery process is protected from other simultaneous mounts.
769769
*/
770770
static int
@@ -1105,7 +1105,7 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
11051105
goto failed;
11061106
}
11071107

1108-
down(&sd.bdev->bd_mount_sem);
1108+
mutex_lock(&nilfs->ns_mount_mutex);
11091109

11101110
if (!sd.cno) {
11111111
/*
@@ -1164,15 +1164,15 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
11641164
need_to_close = 0;
11651165
}
11661166

1167-
up(&sd.bdev->bd_mount_sem);
1167+
mutex_unlock(&nilfs->ns_mount_mutex);
11681168
put_nilfs(nilfs);
11691169
if (need_to_close)
11701170
close_bdev_exclusive(sd.bdev, flags);
11711171
simple_set_mnt(mnt, s);
11721172
return 0;
11731173

11741174
failed_unlock:
1175-
up(&sd.bdev->bd_mount_sem);
1175+
mutex_unlock(&nilfs->ns_mount_mutex);
11761176
put_nilfs(nilfs);
11771177
failed:
11781178
close_bdev_exclusive(sd.bdev, flags);
@@ -1181,14 +1181,14 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
11811181

11821182
cancel_new:
11831183
/* Abandoning the newly allocated superblock */
1184-
up(&sd.bdev->bd_mount_sem);
1184+
mutex_unlock(&nilfs->ns_mount_mutex);
11851185
put_nilfs(nilfs);
11861186
up_write(&s->s_umount);
11871187
deactivate_super(s);
11881188
/*
11891189
* deactivate_super() invokes close_bdev_exclusive().
11901190
* We must finish all post-cleaning before this call;
1191-
* put_nilfs() and unlocking bd_mount_sem need the block device.
1191+
* put_nilfs() needs the block device.
11921192
*/
11931193
return err;
11941194
}

fs/nilfs2/the_nilfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static struct the_nilfs *alloc_nilfs(struct block_device *bdev)
7373
atomic_set(&nilfs->ns_ndirtyblks, 0);
7474
init_rwsem(&nilfs->ns_sem);
7575
init_rwsem(&nilfs->ns_super_sem);
76+
mutex_init(&nilfs->ns_mount_mutex);
7677
mutex_init(&nilfs->ns_writer_mutex);
7778
INIT_LIST_HEAD(&nilfs->ns_list);
7879
INIT_LIST_HEAD(&nilfs->ns_supers);

fs/nilfs2/the_nilfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ enum {
4949
* @ns_writer: back pointer to writable nilfs_sb_info
5050
* @ns_sem: semaphore for shared states
5151
* @ns_super_sem: semaphore for global operations across super block instances
52+
* @ns_mount_mutex: mutex protecting mount process of nilfs
5253
* @ns_writer_mutex: mutex protecting ns_writer attach/detach
5354
* @ns_writer_refcount: number of referrers on ns_writer
5455
* @ns_current: back pointer to current mount
@@ -98,6 +99,7 @@ struct the_nilfs {
9899
struct nilfs_sb_info *ns_writer;
99100
struct rw_semaphore ns_sem;
100101
struct rw_semaphore ns_super_sem;
102+
struct mutex ns_mount_mutex;
101103
struct mutex ns_writer_mutex;
102104
atomic_t ns_writer_refcount;
103105

0 commit comments

Comments
 (0)