Skip to content

Commit 8cd9b78

Browse files
Li LingfengAnna Schumaker
authored andcommitted
nfs: clear SB_RDONLY before getting superblock
As described in the link, commit 52cb7f8 ("nfs: ignore SB_RDONLY when mounting nfs") removed the check for the ro flag when determining whether to share the superblock, which caused issues when mounting different subdirectories under the same export directory via NFSv3. However, this change did not affect NFSv4. For NFSv3: 1) A single superblock is created for the initial mount. 2) When mounted read-only, this superblock carries the SB_RDONLY flag. 3) Before commit 52cb7f8 ("nfs: ignore SB_RDONLY when mounting nfs"): Subsequent rw mounts would not share the existing ro superblock due to flag mismatch, creating a new superblock without SB_RDONLY. After the commit: The SB_RDONLY flag is ignored during superblock comparison, and this leads to sharing the existing superblock even for rw mounts. Ultimately results in write operations being rejected at the VFS layer. For NFSv4: 1) Multiple superblocks are created and the last one will be kept. 2) The actually used superblock for ro mounts doesn't carry SB_RDONLY flag. Therefore, commit 52cb7f8 doesn't affect NFSv4 mounts. Clear SB_RDONLY before getting superblock when NFS_MOUNT_UNSHARED is not set to fix it. Fixes: 52cb7f8 ("nfs: ignore SB_RDONLY when mounting nfs") Closes: https://lore.kernel.org/all/[email protected]/T/ Signed-off-by: Li Lingfeng <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 1ff4716 commit 8cd9b78

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fs/nfs/super.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,17 @@ int nfs_get_tree_common(struct fs_context *fc)
13081308
if (IS_ERR(server))
13091309
return PTR_ERR(server);
13101310

1311+
/*
1312+
* When NFS_MOUNT_UNSHARED is not set, NFS forces the sharing of a
1313+
* superblock among each filesystem that mounts sub-directories
1314+
* belonging to a single exported root path.
1315+
* To prevent interference between different filesystems, the
1316+
* SB_RDONLY flag should be removed from the superblock.
1317+
*/
13111318
if (server->flags & NFS_MOUNT_UNSHARED)
13121319
compare_super = NULL;
1320+
else
1321+
fc->sb_flags &= ~SB_RDONLY;
13131322

13141323
/* -o noac implies -o sync */
13151324
if (server->flags & NFS_MOUNT_NOAC)

0 commit comments

Comments
 (0)