export: Fix rootdir corner case in next_mnt()
Subsystems (2)
PATCH 1/1 export: Fix rootdir corner case in next_mnt()
Currently the following setup causes failure:
1. /etc/exports:
/ *(rw,crossmnt,no_subtree_check,fsid=root)
2. /etc/nfs.conf:
[exports]
rootdir=/nfs_srv
3. Mounts:/root/fs1.ext4 on /nfs_srv type ext4 (rw,relatime) /root/fs2.ext4 on /nfs_srv/fs2 type ext4 (rw,relatime)
4. On the client:
$ ls /nfs_client/fs2 ls: cannot open directory '/nfs_client/fs2': Stale file handle
The problem is that next_mnt() misses the corner case that every mount is a sub-mount of "/".
So it fails to see that /nfs_srv/fs2 is a mountpoint when the client asks for fs2 it and as consequence the crossmnt mechanism fails.
--- support/export/cache.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
support/export/cache.c +5 -1
@@ -410,12 +410,16 @@ static char *next_mnt(void **v, char *p) *v = f; }else f = *v; -while ((me =getmntent (f)) !=NULL && l >1 ) { +while ((me =getmntent (f)) !=NULL && l >=1 ) {char *mnt_dir =nfsd_path_strip_root (me->mnt_dir);if (!mnt_dir)continue ; +/* Everything below "/" is a proper sub-mount */ +if (strcmp (p,"/" ) ==0 ) +return mnt_dir; +if (strncmp (mnt_dir, p, l) ==0 && mnt_dir[l] =='/' )return mnt_dir; }
Signature · 1 line
2.26.2
Quoted 17 lines · Richard Weinberger
Currently the following setup causes failure:
1.
/etc/exports:
/ *(rw,crossmnt,no_subtree_check,fsid=root)2.
/etc/nfs.conf:
[exports]
rootdir=/nfs_srv3. Mounts:
/root/fs1.ext4on /nfs_srv type ext4 (rw,relatime)/root/fs2.ext4on /nfs_srv/fs2 type ext4 (rw,relatime)4. On the client:
$ ls /nfs_client/fs2 ls: cannot open directory '/nfs_client/fs2': Stale file handle
Quoted 7 lines
The problem is that
next_mnt()misses the corner case that every mount is a sub-mount of "/".
So it fails to see that /nfs_srv/fs2 is a mountpoint when the client asks for fs2 it and as consequence the crossmnt mechanism fails.Signed-off-by Richard Weinberger <[email protected]>
Committed... (tag: nfs-utils-2-6-3-rc7)
steved.
Quoted 26 lines
--- support/export/cache.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)support/export/cache.c +5
-1@@ -410,12 +410,16 @@ static char *next_mnt(void **v, char *p) *v = f; }else f = *v; -while ((me =getmntent (f)) !=NULL && l >1 ) { +while ((me =getmntent (f)) !=NULL && l >=1 ) {char *mnt_dir =nfsd_path_strip_root (me->mnt_dir);if (!mnt_dir)continue ; +/* Everything below "/" is a proper sub-mount */ +if (strcmp (p,"/" ) ==0 ) +return mnt_dir; +if (strncmp (mnt_dir, p, l) ==0 && mnt_dir[l] =='/' )return mnt_dir; }