Skip to contentSkip to conversation

question on fh_to_dentry

DISCUSSION Bryan Henderson 1 participant 1 message Apr 11, 2002 VFS

lore
Share & tools
lore
#0 lore raw
Quoted 6 lines

[when fh_to_dentry finds that there is no existing dentry for the given VFS file handle] I saw in fat/reiserfs use d_alloc_root to create a 'root' dentry and set d_flags to DCACHE_NFSD_DISCONNECTED. How does nfsd then make use of this dentry? Does it use this to get the full dentry path? If so, how and when nfsd call dput on those dentries while traversing the dentry path?

I recently went through this same exercise. Let's see if I can explain it.

In some cases, the fact that this is a made-up and only partly filled in dentry is irrelevant -- the NFS server can just go ahead and use it as if it had been found in the normal dentry tree. In others, it must end up with a conventional dentry. The NFS server first determines which case it is.

If it is for a non-directory and the export has the No Subtree Check attribute (and maybe a few other constraints), the NFSD_DISCONNECTED almost-dentry is sufficient all by itself.

But if it's a directory, someone might want to look up ".." in it, and then you'd be in trouble if it were still NFSD_DISCONNECTED. And if the subtree checking is active (which is default), the NFS server must find out where in the directory structure the file lives in order to know if access is permissible. In these cases, the NFS server generates ancestor dentries all the way up the tree so that the NFSD_DISCONNECTED dentry becomes a normal, fully connected dentry.

This is not easy, and it's not pretty. It works via the "parent" version of the fh_to_dentry call and typically with clues in the VFS filehandle about who a parent might be.

In any case, the dentry returned by fh_to_dentry gets dputted as soon as the NFS server has completed the operation on the file (same as if the dentry were found already existing). The constructed parent dentry gets dputted when the child dentry gets deleted (which may be some time after the child is dputted, if it stays cached), as for any dentry with children.