Skip to content

Commit 6ce3c03

Browse files
committed
nfs: clear SB_RDONLY before getting superblock
JIRA: https://issues.redhat.com/browse/RHEL-108616 commit 8cd9b78 Author: Li Lingfeng <lilingfeng3@huawei.com> Date: Tue Mar 4 21:05:32 2025 +0800 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/12d7ea53-1202-4e21-a7ef-431c94758ce5@app.fastmail.com/T/ Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com> Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com> Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
1 parent 1014b8b commit 6ce3c03

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
@@ -1296,8 +1296,17 @@ int nfs_get_tree_common(struct fs_context *fc)
12961296
if (IS_ERR(server))
12971297
return PTR_ERR(server);
12981298

1299+
/*
1300+
* When NFS_MOUNT_UNSHARED is not set, NFS forces the sharing of a
1301+
* superblock among each filesystem that mounts sub-directories
1302+
* belonging to a single exported root path.
1303+
* To prevent interference between different filesystems, the
1304+
* SB_RDONLY flag should be removed from the superblock.
1305+
*/
12991306
if (server->flags & NFS_MOUNT_UNSHARED)
13001307
compare_super = NULL;
1308+
else
1309+
fc->sb_flags &= ~SB_RDONLY;
13011310

13021311
/* -o noac implies -o sync */
13031312
if (server->flags & NFS_MOUNT_NOAC)

0 commit comments

Comments
 (0)