vfs: plug some holes involving LAST_BIND symlinks and file bind mounts (try #6)
cover vfs: plug some holes involving LAST_BIND symlinks and file bind mounts (try #6)
This patchset is another attempt to add missing dentry revalidations to certain places in the lookup codepath. The main difference from the last patchset is:
* I've dropped the patch that added permissions checks when chasing LAST_BIND symlinks. There's a lot disagreement about whether the current behavior is even a bug. I'd prefer to see more concensus on that point before we do anything here.
* I've rejiggered the error handling in this codepath to ensure that the bind mounts could still be unmounted. Testing showed that returning an error in do_lookup when a bind-mounted dentry went stale made it un-unmountable.
Comments and suggestions appreciated...
Jeff Layton (2):
vfs: force reval of target when following LAST_BIND symlinks
vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT
filesystems
fs/namei.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 55 insertions(+), 1 deletions(-)
PATCH 1/2 vfs: force reval of target when following LAST_BIND symlinks
procfs-style symlinks return a last_type of LAST_BIND without an actual path string. This causes __follow_link to skip calling __vfs_follow_link and so the dentry isn't revalidated.
This is a problem when the link target sits on NFSv4 as it depends on the VFS to revalidate the dentry before using it on an open call. Ensure that this occurs by forcing a revalidation of the target dentry of LAST_BIND symlinks.
--- fs/namei.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-)
fs/namei.c +45 -0
@@ -414,6 +414,46 @@ do_revalidate(struct dentry *dentry, struct nameidata *nd) }/* +* force_reval_path - force revalidation of a dentry +* +* In some situations the path walking code will trust dentries without +* revalidating them. This causes problems for filesystems that depend on +* d_revalidate to handle file opens (e.g. NFSv4). When FS_REVAL_DOT is set +* (which indicates that it's possible for the dentry to go stale), force +* a d_revalidate call before proceeding. +* +* Returns 0 if the revalidation was successful. If the revalidation fails, +* either return the error returned by d_revalidate or -ESTALE if the +* revalidation it just returned 0. If d_revalidate returns 0, we attempt to +* invalidate the dentry. It's up to the caller to handle putting references +* to the path if necessary. +*/ +static int +force_reval_path (struct path *path,struct nameidata *nd) +{ +int status; +struct dentry *dentry = path->dentry; + +/* +* only check on filesystems where it's possible for the dentry to +* become stale. It's assumed that if this flag is set then the +* d_revalidate op will also be defined. +*/ +if (!(dentry->d_sb->s_type->fs_flags &FS_REVAL_DOT )) +return 0 ; + + status = dentry->d_op->d_revalidate (dentry, nd); +if (status >0 ) +return 0 ; + +if (!status) { +d_invalidate (dentry); + status = -ESTALE ; + } +return status; +} + +/* * Internal lookup() using the new generic dcache. * SMP-safe */
@@ -641,6 +681,11 @@ static __always_inline int __do_follow_link(struct path *path, struct nameidata error =0 ;if (s) error =__vfs_follow_link (nd, s); +else if (nd->last_type ==LAST_BIND ) { + error =force_reval_path (&nd->path, nd); +if (error) +path_put (&nd->path); + }if (dentry->d_inode->i_op->put_link) dentry->d_inode->i_op->put_link (dentry, nd, cookie); }
Signature · 1 line
1.5.5.6
Re: [PATCH 1/2] vfs: force reval of target when following LAST_BIND symlinks
Quoted 8 lines · Jeff Layton
procfs-style symlinks return a
last_typeofLAST_BINDwithout an actual path string. This causes__follow_linkto skip calling__vfs_follow_linkand so the dentry isn't revalidated.This is a problem when the link target sits on NFSv4 as it depends on the VFS to revalidate the dentry before using it on an open call. Ensure that this occurs by forcing a revalidation of the target dentry of
LAST_BINDsymlinks.
This seems reasonable to me, and in a quick run through I can't see any problems.
Quoted 71 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/namei.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-)fs/namei.c +45
-0@@ -414,6 +414,46 @@ do_revalidate(struct dentry *dentry, struct nameidata *nd) }/* +* force_reval_path - force revalidation of a dentry +* +* In some situations the path walking code will trust dentries without +* revalidating them. This causes problems for filesystems that depend on +* d_revalidate to handle file opens (e.g. NFSv4). When FS_REVAL_DOT is set +* (which indicates that it's possible for the dentry to go stale), force +* a d_revalidate call before proceeding. +* +* Returns 0 if the revalidation was successful. If the revalidation fails, +* either return the error returned by d_revalidate or -ESTALE if the +* revalidation it just returned 0. If d_revalidate returns 0, we attempt to +* invalidate the dentry. It's up to the caller to handle putting references +* to the path if necessary. +*/ +static int +force_reval_path (struct path *path,struct nameidata *nd) +{ +int status; +struct dentry *dentry = path->dentry; + +/* +* only check on filesystems where it's possible for the dentry to +* become stale. It's assumed that if this flag is set then the +* d_revalidate op will also be defined. +*/ +if (!(dentry->d_sb->s_type->fs_flags &FS_REVAL_DOT )) +return 0 ; + + status = dentry->d_op->d_revalidate (dentry, nd); +if (status >0 ) +return 0 ; + +if (!status) { +d_invalidate (dentry); + status = -ESTALE ; + } +return status; +} + +/* * Internal lookup() using the new generic dcache. * SMP-safe */ @@ -641,6 +681,11 @@ static __always_inline int __do_follow_link(struct path *path, struct nameidata error =0 ;if (s) error =__vfs_follow_link (nd, s); +else if (nd->last_type ==LAST_BIND ) { + error =force_reval_path (&nd->path, nd); +if (error) +path_put (&nd->path); + }if (dentry->d_inode->i_op->put_link) dentry->d_inode->i_op->put_link (dentry, nd, cookie); }Signature · 1 line
1.5.5.6
Re: [PATCH 1/2] vfs: force reval of target when following LAST_BIND symlinks
In reply to Jeff LaytonQuoted 8 lines · Jeff Layton
procfs-style symlinks return a
last_typeofLAST_BINDwithout an actual path string. This causes__follow_linkto skip calling__vfs_follow_linkand so the dentry isn't revalidated.This is a problem when the link target sits on NFSv4 as it depends on the VFS to revalidate the dentry before using it on an open call. Ensure that this occurs by forcing a revalidation of the target dentry of
LAST_BINDsymlinks.
An added advantage is that the symlinks in /proc will show the invalidated path as "(deleted)". Maybe proc_pid_readlink() should also call force_reval_path() to get an up-to-date state of the path?
Quoted 77 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/namei.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-)fs/namei.c +45
-0@@ -414,6 +414,46 @@ do_revalidate(struct dentry *dentry, struct nameidata *nd) }/* +* force_reval_path - force revalidation of a dentry +* +* In some situations the path walking code will trust dentries without +* revalidating them. This causes problems for filesystems that depend on +* d_revalidate to handle file opens (e.g. NFSv4). When FS_REVAL_DOT is set +* (which indicates that it's possible for the dentry to go stale), force +* a d_revalidate call before proceeding. +* +* Returns 0 if the revalidation was successful. If the revalidation fails, +* either return the error returned by d_revalidate or -ESTALE if the +* revalidation it just returned 0. If d_revalidate returns 0, we attempt to +* invalidate the dentry. It's up to the caller to handle putting references +* to the path if necessary. +*/ +static int +force_reval_path (struct path *path,struct nameidata *nd) +{ +int status; +struct dentry *dentry = path->dentry; + +/* +* only check on filesystems where it's possible for the dentry to +* become stale. It's assumed that if this flag is set then the +* d_revalidate op will also be defined. +*/ +if (!(dentry->d_sb->s_type->fs_flags &FS_REVAL_DOT )) +return 0 ; + + status = dentry->d_op->d_revalidate (dentry, nd); +if (status >0 ) +return 0 ; + +if (!status) { +d_invalidate (dentry); + status = -ESTALE ; + } +return status; +} + +/* * Internal lookup() using the new generic dcache. * SMP-safe */ @@ -641,6 +681,11 @@ static __always_inline int __do_follow_link(struct path *path, struct nameidata error =0 ;if (s) error =__vfs_follow_link (nd, s); +else if (nd->last_type ==LAST_BIND ) { + error =force_reval_path (&nd->path, nd); +if (error) +path_put (&nd->path); + }if (dentry->d_inode->i_op->put_link) dentry->d_inode->i_op->put_link (dentry, nd, cookie); }Signature · 6 lines
1.5.5.6 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/2 vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
In reply to Jeff LaytonIn the case of a bind mounted file, the path walking code will assume that the cached dentry that was bind mounted is valid. This is a problem problem for NFSv4 in a way that's similar to LAST_BIND symlinks.
Fix this by revalidating the dentry if FS_FOLLOW_DOT is set and __follow_mount returns true.
Note that in the non-open codepath, we cannot return an error to the lookup if the revalidation fails. Doing so will leave a bind mount in a state such that we can't unmount it. In that case we'll just have to settle for d_invalidating it (which should mostly turn out to be a d_drop in this case) and returning success.
--- fs/namei.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
fs/namei.c +10 -1
@@ -851,7 +851,13 @@ static int do_lookup(struct nameidata *nd, struct qstr *name, done: path->mnt = mnt; path->dentry = dentry; -__follow_mount (path); + +/* +* cannot return the error returned by force_reval_path as that can +* make it impossible to unmount a bind mounted dentry if it's stale. +*/ +if (__follow_mount (path)) +force_reval_path (path, nd);return 0 ; need_lookup:
@@ -1840,6 +1846,9 @@ do_last: error = -ELOOP ;if (flag &O_NOFOLLOW ) goto exit_dput; + error =force_reval_path (&path, &nd); +if (error) + goto exit_dput; } error = -ENOENT ;
Signature · 1 line
1.5.5.6
Re: [PATCH 2/2] vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
Quoted 4 lines · Jeff Layton
In the case of a bind mounted file, the path walking code will assume that the cached dentry that was bind mounted is valid. This is a problem problem for NFSv4 in a way that's similar to
LAST_BINDsymlinks.
Quoted 8 lines
Fix this by revalidating the dentry if
FS_FOLLOW_DOTis set and__follow_mountreturns true.Note that in the non-open codepath, we cannot return an error to the lookup if the revalidation fails. Doing so will leave a bind mount in a state such that we can't unmount it. In that case we'll just have to settle for
d_invalidatingit (which should mostly turn out to be ad_dropin this case) and returning success.
Looks reasonable to me. I wonder a little if we care about follow_mount as well as __follow_mount.
This seems reasonable to me.
Quoted 37 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/namei.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)fs/namei.c +10
-1@@ -851,7 +851,13 @@ static int do_lookup(struct nameidata *nd, struct qstr *name, done: path->mnt = mnt; path->dentry = dentry; -__follow_mount (path); + +/* +* cannot return the error returned by force_reval_path as that can +* make it impossible to unmount a bind mounted dentry if it's stale. +*/ +if (__follow_mount (path)) +force_reval_path (path, nd);return 0 ; need_lookup:@@ -1840,6 +1846,9 @@ do_last: error = -ELOOP ;if (flag &O_NOFOLLOW ) goto exit_dput; + error =force_reval_path (&path, &nd); +if (error) + goto exit_dput; } error = -ENOENT ;Signature · 1 line
1.5.5.6
Re: [PATCH 2/2] vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
Quoted 9 lines · On Wed, 02 Dec 2009 16:01:59 -0800 [email protected] (Eric W. Biederman)…
Quoted 7 lines · Jeff Layton
In the case of a bind mounted file, the path walking code will assume that the cached dentry that was bind mounted is valid. This is a problem problem for NFSv4 in a way that's similar to
LAST_BINDsymlinks.Fix this by revalidating the dentry if
FS_FOLLOW_DOTis set and__follow_mountreturns true.
Quoted 9 lines
Quoted 5 lines
Note that in the non-open codepath, we cannot return an error to the lookup if the revalidation fails. Doing so will leave a bind mount in a state such that we can't unmount it. In that case we'll just have to settle for
d_invalidatingit (which should mostly turn out to be ad_dropin this case) and returning success.Looks reasonable to me. I wonder a little if we care about
follow_mountas well as__follow_mount.
Good question.
It does sort of seem like it. There's also follow_down too...
OTOH, we have a reproducible testcases that the two patches in this series fix. I'm not aware of anything that's technically "broken" by the lack of revalidations in the other codepaths so I'm hesitant to add them in unless and until we do.
Quoted 41 lines
This seems reasonable to me.
Quoted 37 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/namei.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)fs/namei.c +10
-1@@ -851,7 +851,13 @@ static int do_lookup(struct nameidata *nd, struct qstr *name, done: path->mnt = mnt; path->dentry = dentry; -__follow_mount (path); + +/* +* cannot return the error returned by force_reval_path as that can +* make it impossible to unmount a bind mounted dentry if it's stale. +*/ +if (__follow_mount (path)) +force_reval_path (path, nd);return 0 ; need_lookup:@@ -1840,6 +1846,9 @@ do_last: error = -ELOOP ;if (flag &O_NOFOLLOW ) goto exit_dput; + error =force_reval_path (&path, &nd); +if (error) + goto exit_dput; } error = -ENOENT ;Signature · 1 line
1.5.5.6
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 2/2] vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
In reply to Jeff LaytonQuoted 4 lines · Jeff Layton
In the case of a bind mounted file, the path walking code will assume that the cached dentry that was bind mounted is valid. This is a problem problem for NFSv4 in a way that's similar to
LAST_BINDsymlinks.
Quoted 8 lines
Fix this by revalidating the dentry if
FS_FOLLOW_DOTis set and__follow_mountreturns true.Note that in the non-open codepath, we cannot return an error to the lookup if the revalidation fails. Doing so will leave a bind mount in a state such that we can't unmount it. In that case we'll just have to settle for
d_invalidatingit (which should mostly turn out to be ad_dropin this case) and returning success.
The only worry I have is that this adds an extra branch in a very hot codepath (do_lookup). An error can't be returned, as you note, and for bind mounted directories d_invalidate() will not succeed: the directory is busy, it's referenced by the mount. So basically the only thing this does is working around the NFSv4 issue. But Trond has a proper solution to that, and a temporary solution could be added to do_filp_open() rather than burdening do_lookup() with it, no?
Thanks,
Miklos
Quoted 39 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/namei.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)fs/namei.c +10
-1@@ -851,7 +851,13 @@ static int do_lookup(struct nameidata *nd, struct qstr *name, done: path->mnt = mnt; path->dentry = dentry; -__follow_mount (path); + +/* +* cannot return the error returned by force_reval_path as that can +* make it impossible to unmount a bind mounted dentry if it's stale. +*/ +if (__follow_mount (path)) +force_reval_path (path, nd);return 0 ; need_lookup:@@ -1840,6 +1846,9 @@ do_last: error = -ELOOP ;if (flag &O_NOFOLLOW ) goto exit_dput; + error =force_reval_path (&path, &nd); +if (error) + goto exit_dput; } error = -ENOENT ;Signature · 1 line
1.5.5.6
Re: [PATCH 2/2] vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
Quoted 14 lines · Miklos Szeredi
Quoted 4 lines · Jeff Layton
In the case of a bind mounted file, the path walking code will assume that the cached dentry that was bind mounted is valid. This is a problem problem for NFSv4 in a way that's similar to
LAST_BINDsymlinks.Quoted 8 lines
Fix this by revalidating the dentry if
FS_FOLLOW_DOTis set and__follow_mountreturns true.Note that in the non-open codepath, we cannot return an error to the lookup if the revalidation fails. Doing so will leave a bind mount in a state such that we can't unmount it. In that case we'll just have to settle for
d_invalidatingit (which should mostly turn out to be ad_dropin this case) and returning success.
Quoted 4 lines
The only worry I have is that this adds an extra branch in a very hot codepath (
do_lookup). An error can't be returned, as you note, and for bind mounted directoriesd_invalidate()will not succeed: the directory is busy, it's referenced by the mount.
Not true. d_mountpoint is false, so d_invalidate can succeed.
Quoted 2 lines
So basically the
only thing this does is working around the NFSv4 issue.
No, this should catch other cases where we have a dentry goes stale as well, and lets the distributed filesystem handle it.
It is probably worth a benchmark to ease the concerns about the hotpath. I expect the cpu will predict the branch as unlikely and we won't see any difference.
Eric
Re: [PATCH 2/2] vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
Quoted 6 lines · Eric W. Biederman
Quoted 4 lines
The only worry I have is that this adds an extra branch in a very hot codepath (
do_lookup). An error can't be returned, as you note, and for bind mounted directoriesd_invalidate()will not succeed: the directory is busy, it's referenced by the mount.Not true.
d_mountpointis false, sod_invalidatecan succeed.
Have a look at the code. d_invalidate() doesn't check for a mountpoint, it checks the refcount. It needs to keep the directory dentry hashed if it's in any way reachable other than from the cache (file descriptor, cwd, mount, etc).
Thanks,
Miklos
Re: [PATCH 2/2] vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
Quoted 6 lines · Miklos Szeredi
Quoted 5 lines · Eric W. Biederman
Quoted 4 lines
The only worry I have is that this adds an extra branch in a very hot codepath (
do_lookup). An error can't be returned, as you note, and for bind mounted directoriesd_invalidate()will not succeed: the directory is busy, it's referenced by the mount.
Quoted 6 lines
Quoted 1 line
Not true.
d_mountpointis false, sod_invalidatecan succeed.Have a look at the code.
d_invalidate()doesn't check for a mountpoint, it checks the refcount. It needs to keep the directory dentry hashed if it's in any way reachable other than from the cache (file descriptor, cwd, mount, etc).
Ah. I thought you were thinking about the mandatory have_submounts() check in dentry->d_op->d_revalidate().
I expect the generic d_invalidate will simply hit the:
spin_lock(&dcache_lock);
if (d_unhashed(dentry)) {
spin_unlock(&dcache_lock);
return 0;
}After the distributed filesystem has called d_drop in dentry->d_op->d_revalidate (when appropriate.
Eric
Re: [PATCH 2/2] vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
Quoted 4 lines · Eric W. Biederman
Ah. I thought you were thinking about the mandatory
have_submounts()check indentry->d_op->d_revalidate().I expect the generic
d_invalidatewill simply hit the:
Quoted 8 lines
spin_lock(&dcache_lock); if (d_unhashed(dentry)) { spin_unlock(&dcache_lock); return 0; }After the distributed filesystem has called
d_dropindentry->d_op->d_revalidate(when appropriate.
Ah, right, NFS's d_revalidate does do d_drop(). Okay, I have no problem with the patch, as long as path lookup performance doesn't show a regression.
Thanks,
Miklos
Re: [PATCH 2/2] vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
In reply to Miklos SzerediQuoted 14 lines · On Thu, 03 Dec 2009 11:58:43 +0100 Miklos Szeredi <[email protected]> wrote:
Quoted 4 lines · Jeff Layton
In the case of a bind mounted file, the path walking code will assume that the cached dentry that was bind mounted is valid. This is a problem problem for NFSv4 in a way that's similar to
LAST_BINDsymlinks.Quoted 8 lines
Fix this by revalidating the dentry if
FS_FOLLOW_DOTis set and__follow_mountreturns true.Note that in the non-open codepath, we cannot return an error to the lookup if the revalidation fails. Doing so will leave a bind mount in a state such that we can't unmount it. In that case we'll just have to settle for
d_invalidatingit (which should mostly turn out to be ad_dropin this case) and returning success.
Quoted 8 lines
The only worry I have is that this adds an extra branch in a very hot codepath (
do_lookup). An error can't be returned, as you note, and for bind mounted directoriesd_invalidate()will not succeed: the directory is busy, it's referenced by the mount. So basically the only thing this does is working around the NFSv4 issue. But Trond has a proper solution to that, and a temporary solution could be added todo_filp_open()rather than burdeningdo_lookup()with it, no?
(re-adding Trond. I forgot to cc him on this latest set)
Self-NAK on this patch...
That's my main worry too, and sadly it doesn't seem to be unfounded. This patch adds a lot of extra d_revalidate calls here. I think it's going to be too expensive to do this.
Unfortunately, adding the code to do_filp_open alone doesn't really help. The path walking code in there is just for the O_CREAT case. If we're not creating the file, we call into path_lookup_open which eventually calls do_lookup.
What we probably need to do is only make it d_revalidate when it looks like the final dentry is bind mounted. I'm not sure how to tell that though and even if I could, I'm still leery of adding this to such a hot codepath.
The only problem I've identified that this fixes is with file bind mounts and I don't get the impression they're that common. Maybe the best thing is to just fix the LAST_BIND symlink case for now and wait for Trond or Al's overhaul of this code.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 2/2] vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
Quoted 26 lines · Jeff Layton
Quoted 14 lines · On Thu, 03 Dec 2009 11:58:43 +0100 Miklos Szeredi <[email protected]> wrote:
Quoted 4 lines · Jeff Layton
In the case of a bind mounted file, the path walking code will assume that the cached dentry that was bind mounted is valid. This is a problem problem for NFSv4 in a way that's similar to
LAST_BINDsymlinks.Quoted 8 lines
Fix this by revalidating the dentry if
FS_FOLLOW_DOTis set and__follow_mountreturns true.Note that in the non-open codepath, we cannot return an error to the lookup if the revalidation fails. Doing so will leave a bind mount in a state such that we can't unmount it. In that case we'll just have to settle for
d_invalidatingit (which should mostly turn out to be ad_dropin this case) and returning success.Quoted 8 lines
The only worry I have is that this adds an extra branch in a very hot codepath (
do_lookup). An error can't be returned, as you note, and for bind mounted directoriesd_invalidate()will not succeed: the directory is busy, it's referenced by the mount. So basically the only thing this does is working around the NFSv4 issue. But Trond has a proper solution to that, and a temporary solution could be added todo_filp_open()rather than burdeningdo_lookup()with it, no?
Quoted 7 lines
(re-adding Trond. I forgot to cc him on this latest set)
Self-NAK on this patch...
That's my main worry too, and sadly it doesn't seem to be unfounded. This patch adds a lot of extra
d_revalidatecalls here. I think it's going to be too expensive to do this.
How so? We should only see extra calls if we follow a mount point. Currently we call d_revalidate on every path component.
Quoted 4 lines
The only problem I've identified that this fixes is with file bind mounts and I don't get the impression they're that common. Maybe the best thing is to just fix the
LAST_BINDsymlink case for now and wait for Trond or Al's overhaul of this code.
Well right now following mount points breaks the VFS contract that we will revalidate all dentries before we use them. That breaking of the contract breaks NFS.
I don't know what else d_revalidate is good for. On the sysfs side I only use it to unhash the dentry. Something we don't care about from the do_lookup side of things if we have a bind mount.
I'm not clear what kind of changes revalidating a deleted but open file will give you on NFS.
Eric
Re: [PATCH 2/2] vfs: force reval on dentry of bind mounted files on FS_REVAL_DOT filesystems
Quoted 48 lines · On Thu, 03 Dec 2009 10:35:21 -0800 [email protected] (Eric W. Biederman)…
Quoted 26 lines · Jeff Layton
Quoted 14 lines · On Thu, 03 Dec 2009 11:58:43 +0100 Miklos Szeredi <[email protected]> wrote:
Quoted 4 lines · Jeff Layton
In the case of a bind mounted file, the path walking code will assume that the cached dentry that was bind mounted is valid. This is a problem problem for NFSv4 in a way that's similar to
LAST_BINDsymlinks.Quoted 8 lines
Fix this by revalidating the dentry if
FS_FOLLOW_DOTis set and__follow_mountreturns true.Note that in the non-open codepath, we cannot return an error to the lookup if the revalidation fails. Doing so will leave a bind mount in a state such that we can't unmount it. In that case we'll just have to settle for
d_invalidatingit (which should mostly turn out to be ad_dropin this case) and returning success.Quoted 8 lines
The only worry I have is that this adds an extra branch in a very hot codepath (
do_lookup). An error can't be returned, as you note, and for bind mounted directoriesd_invalidate()will not succeed: the directory is busy, it's referenced by the mount. So basically the only thing this does is working around the NFSv4 issue. But Trond has a proper solution to that, and a temporary solution could be added todo_filp_open()rather than burdeningdo_lookup()with it, no?Quoted 7 lines
(re-adding Trond. I forgot to cc him on this latest set)
Self-NAK on this patch...
That's my main worry too, and sadly it doesn't seem to be unfounded. This patch adds a lot of extra
d_revalidatecalls here. I think it's going to be too expensive to do this.How so? We should only see extra calls if we follow a mount point. Currently we call
d_revalidateon every path component.Quoted 4 lines
The only problem I've identified that this fixes is with file bind mounts and I don't get the impression they're that common. Maybe the best thing is to just fix the
LAST_BINDsymlink case for now and wait for Trond or Al's overhaul of this code.Well right now following mount points breaks the VFS contract that we will revalidate all dentries before we use them. That breaking of the contract breaks NFS.
Quoted 7 lines
I don't know what else
d_revalidateis good for. On the sysfs side I only use it to unhash the dentry. Something we don't care about from thedo_lookupside of things if we have a bind mount.I'm not clear what kind of changes revalidating a deleted but open file will give you on NFS.
My concern here is based mainly on a simple experiment I did to fire off a printk and do a dump_stack every time we call d_revalidate from force_reval_path. Even a very small set of operations caused that to get called many, many times, mostly from do_lookup.
You're correct that the current behavior breaks the d_revalidate "contract". What I'm not sure of is whether that truly breaks anything beyond file bind mounts.
If it doesn't then we have to ask ourselves -- is it worth a potential performance hit in a very hot codepath to fix bind mounted files that live on NFSv4? My current thinking is "no".
Much of that decision is based upon an assumption that file bind mounts are rarely ever used. If that's the case, then it's probably more prudent to wait until the VFS has been fixed so that NFSv4 no longer needs to depend on d_revalidate this way.
The LAST_BIND symlink case is a little more straightforward since the fix is more targeted. I think that should be reasonable for 2.6.33.
Cheers,
Signature · 1 line
Jeff Layton <[email protected]>