On Thu, 17 Jun 2021, Wang Yugui wrote: > > Can we go back to the beginning. What, exactly, is the problem you are > > trying to solve? How can you demonstrate the problem? > > > > NeilBrown > > I nfs/exported a btrfs with 2 subvols and 2 snapshot(subvol). > > # btrfs subvolume list /mnt/test > ID 256 gen 53 top level 5 path sub1 > ID 260 gen 56 top level 5 path sub2 > ID 261 gen 57 top level 5 path .snapshot/sub1-s1 > ID 262 gen 57 top level 5 path .snapshot/sub2-s1 > > and then mount.nfs4 it to /nfs/test. > > # /bin/find /nfs/test/ > /nfs/test/ > find: File system loop detected; '/nfs/test/sub1' is part of the same file system loop as '/nfs/test/'. > /nfs/test/.snapshot > find: File system loop detected; '/nfs/test/.snapshot/sub1-s1' is part of the same file system loop as '/nfs/test/'. > find: File system loop detected; '/nfs/test/.snapshot/sub2-s1' is part of the same file system loop as '/nfs/test/'. > /nfs/test/dir1 > /nfs/test/dir1/a.txt > find: File system loop detected; '/nfs/test/sub2' is part of the same file system loop as '/nfs/test/' > > /bin/find report 'File system loop detected'. so I though there is > something wrong. Certainly something is wrong. The error message implies that some directory is reporting the same dev an ino as an ancestor directory. Presumably /nfs/test and /nfs/test/sub1. Can you confirm that please. e.g. run the command stat /nfs/test /nfs/test/sub1 and examine the output. As sub1 is considered a different file system, it should have a different dev number. NFS will assign a different device number only when the server reports a different fsid. The Linux NFS server will report a different fsid if d_mountpoint() is 'true' for the dentry, and follow_down() results in no change the the vfsmnt,dentry in a 'struct path'. You have already said that d_mountpoint doesn't work for btrfs, so that is part of the problem. NFSD doesn't trust d_mountpoint completely as it only reports that the dentry is a mountpoint in some namespace, not necessarily in this namespace. So you really need to fix nfsd_mountpoint. I suggest you try adding your "dirty fix" to nfsd_mountpoint() so that it reports the root of a btrfs subvol as a mountpoint, and see if that fixes the problem. It should change the problem at least. You would need to get nfsd_mountpoint() to return '1' in this case, not '2'. NeilBrown