Skip to content

Commit 80c4de6

Browse files
Li LingfengAnna Schumaker
authored andcommitted
nfs: ignore SB_RDONLY when remounting nfs
In some scenarios, when mounting NFS, more than one superblock may be created. The final superblock used is the last one created, but only the first superblock carries the ro flag passed from user space. If a ro flag is added to the superblock via remount, it will trigger the issue described in Link[1]. Link[2] attempted to address this by marking the superblock as ro during the initial mount. However, this introduced a new problem in scenarios where multiple mount points share the same superblock: [root@a ~]# mount /dev/sdb /mnt/sdb [root@a ~]# echo "/mnt/sdb *(rw,no_root_squash)" > /etc/exports [root@a ~]# echo "/mnt/sdb/test_dir2 *(ro,no_root_squash)" >> /etc/exports [root@a ~]# systemctl restart nfs-server [root@a ~]# mount -t nfs -o rw 127.0.0.1:/mnt/sdb/test_dir1 /mnt/test_mp1 [root@a ~]# mount | grep nfs4 127.0.0.1:/mnt/sdb/test_dir1 on /mnt/test_mp1 type nfs4 (rw,relatime,... [root@a ~]# mount -t nfs -o ro 127.0.0.1:/mnt/sdb/test_dir2 /mnt/test_mp2 [root@a ~]# mount | grep nfs4 127.0.0.1:/mnt/sdb/test_dir1 on /mnt/test_mp1 type nfs4 (ro,relatime,... 127.0.0.1:/mnt/sdb/test_dir2 on /mnt/test_mp2 type nfs4 (ro,relatime,... [root@a ~]# When mounting the second NFS, the shared superblock is marked as ro, causing the previous NFS mount to become read-only. To resolve both issues, the ro flag is no longer applied to the superblock during remount. Instead, the ro flag on the mount is used to control whether the mount point is read-only. Fixes: 281cad4 ("NFS: Create a submount rpc_op") Link[1]: https://lore.kernel.org/all/[email protected]/ Link[2]: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Li Lingfeng <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 8cd9b78 commit 80c4de6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/nfs/super.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,16 @@ int nfs_reconfigure(struct fs_context *fc)
10511051

10521052
sync_filesystem(sb);
10531053

1054+
/*
1055+
* The SB_RDONLY flag has been removed from the superblock during
1056+
* mounts to prevent interference between different filesystems.
1057+
* Similarly, it is also necessary to ignore the SB_RDONLY flag
1058+
* during reconfiguration; otherwise, it may also result in the
1059+
* creation of redundant superblocks when mounting a directory with
1060+
* different rw and ro flags multiple times.
1061+
*/
1062+
fc->sb_flags_mask &= ~SB_RDONLY;
1063+
10541064
/*
10551065
* Userspace mount programs that send binary options generally send
10561066
* them populated with default values. We have no way to know which

0 commit comments

Comments
 (0)