Skip to content

Commit fb2088c

Browse files
spuiukTrond Myklebust
authored and
Trond Myklebust
committed
nfs: Do not allow multiple mounts on same mountpoint when using -o noac
Do not allow multiple mounts on same mountpoint when using -o noac When you normally attempt to mount a share twice on the same mountpoint, a check in do_add_mount causes it to return an error # mount localhost:/nfsv3 /mnt # mount localhost:/nfsv3 /mnt mount.nfs: /mnt is already mounted or busy However when using the option 'noac', the user is able to mount the same share on the same mountpoint multiple times. This happens because a share mounted with the noac option is automatically assigned the 'sync' flag MS_SYNCHRONOUS in nfs_initialise_sb(). This flag is set after the check for already existing superblocks is done in sget(). The check for the mount flags in nfs_compare_mount_options() does not take into account the 'sync' flag applied later on in the code path. This means that when using 'noac', a new superblock structure is assigned for every new mount of the same share and multiple shares on the same mountpoint are allowed. ie. # mount -onoac localhost:/nfsv3 /mnt can be run multiple times. The patch checks for noac and assigns the sync flag before sget() is called to obtain an already existing superblock structure. Signed-off-by: Sachin Prabhu <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent f13c362 commit fb2088c

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

fs/nfs/super.c

+20-3
Original file line numberDiff line numberDiff line change
@@ -2035,9 +2035,6 @@ static inline void nfs_initialise_sb(struct super_block *sb)
20352035
sb->s_blocksize = nfs_block_bits(server->wsize,
20362036
&sb->s_blocksize_bits);
20372037

2038-
if (server->flags & NFS_MOUNT_NOAC)
2039-
sb->s_flags |= MS_SYNCHRONOUS;
2040-
20412038
sb->s_bdi = &server->backing_dev_info;
20422039

20432040
nfs_super_set_maxbytes(sb, server->maxfilesize);
@@ -2249,6 +2246,10 @@ static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
22492246
if (server->flags & NFS_MOUNT_UNSHARED)
22502247
compare_super = NULL;
22512248

2249+
/* -o noac implies -o sync */
2250+
if (server->flags & NFS_MOUNT_NOAC)
2251+
sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2252+
22522253
/* Get a superblock - note that we may end up sharing one that already exists */
22532254
s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
22542255
if (IS_ERR(s)) {
@@ -2361,6 +2362,10 @@ nfs_xdev_mount(struct file_system_type *fs_type, int flags,
23612362
if (server->flags & NFS_MOUNT_UNSHARED)
23622363
compare_super = NULL;
23632364

2365+
/* -o noac implies -o sync */
2366+
if (server->flags & NFS_MOUNT_NOAC)
2367+
sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2368+
23642369
/* Get a superblock - note that we may end up sharing one that already exists */
23652370
s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
23662371
if (IS_ERR(s)) {
@@ -2628,6 +2633,10 @@ nfs4_remote_mount(struct file_system_type *fs_type, int flags,
26282633
if (server->flags & NFS4_MOUNT_UNSHARED)
26292634
compare_super = NULL;
26302635

2636+
/* -o noac implies -o sync */
2637+
if (server->flags & NFS_MOUNT_NOAC)
2638+
sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2639+
26312640
/* Get a superblock - note that we may end up sharing one that already exists */
26322641
s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
26332642
if (IS_ERR(s)) {
@@ -2916,6 +2925,10 @@ nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
29162925
if (server->flags & NFS4_MOUNT_UNSHARED)
29172926
compare_super = NULL;
29182927

2928+
/* -o noac implies -o sync */
2929+
if (server->flags & NFS_MOUNT_NOAC)
2930+
sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2931+
29192932
/* Get a superblock - note that we may end up sharing one that already exists */
29202933
s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
29212934
if (IS_ERR(s)) {
@@ -3003,6 +3016,10 @@ nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
30033016
if (server->flags & NFS4_MOUNT_UNSHARED)
30043017
compare_super = NULL;
30053018

3019+
/* -o noac implies -o sync */
3020+
if (server->flags & NFS_MOUNT_NOAC)
3021+
sb_mntdata.mntflags |= MS_SYNCHRONOUS;
3022+
30063023
/* Get a superblock - note that we may end up sharing one that already exists */
30073024
s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
30083025
if (IS_ERR(s)) {

0 commit comments

Comments
 (0)