Re: VFS + path walktrough

From: Miklos Szeredi
Date: Mon May 05 2008 - 16:36:21 EST


> On Mon, 2008-05-05 at 20:31 +0200, Miklos Szeredi wrote:
> > > > > > Take a look at 9P walk - it does *not* give
> > > > > > you anything resembling stat, you just get qids of intermediates.
> > > > >
> > > > > Which is exactly what's needed to populate the dentry tree, no?
> > > >
> > > > No - you need inodes as well (i.e. as the absolute least you want
> > > > mode and ownership). Which is to say, you need to issue stat on
> > > > each component in such situation anyway. Not a win...
> >
> > And actually even that *could* be a win, if the network latency is
> > large. Because by doing the lookup first, the stats can be performed
> > in parallel. So a path with an arbitrary number of components could
> > be resolved in just 2 RTTs.
>
> ...and NFSv4 could do it in a single RPC call (assuming no symlinks or
> submounts).

And just to show how utterly trivially this could be done, here's a
patch (totally untested).

Hack? Hell, yes.

Miklos

---
fs/namei.c | 20 ++++++++++++--------
include/linux/fs.h | 1 +
2 files changed, 13 insertions(+), 8 deletions(-)

Index: linux-2.6/fs/namei.c
===================================================================
--- linux-2.6.orig/fs/namei.c 2008-05-05 12:03:24.000000000 +0200
+++ linux-2.6/fs/namei.c 2008-05-05 22:25:52.000000000 +0200
@@ -519,14 +519,18 @@ static struct dentry * real_lookup(struc
*/
result = d_lookup(parent, name);
if (!result) {
- struct dentry * dentry = d_alloc(parent, name);
- result = ERR_PTR(-ENOMEM);
- if (dentry) {
- result = dir->i_op->lookup(dir, dentry, nd);
- if (result)
- dput(dentry);
- else
- result = dentry;
+ if (dir->i_op->lookup_path) {
+ result = dir->i_op->lookup_path(dir, name);
+ } else {
+ struct dentry * dentry = d_alloc(parent, name);
+ result = ERR_PTR(-ENOMEM);
+ if (dentry) {
+ result = dir->i_op->lookup(dir, dentry, nd);
+ if (result)
+ dput(dentry);
+ else
+ result = dentry;
+ }
}
mutex_unlock(&dir->i_mutex);
return result;
Index: linux-2.6/include/linux/fs.h
===================================================================
--- linux-2.6.orig/include/linux/fs.h 2008-05-05 12:03:24.000000000 +0200
+++ linux-2.6/include/linux/fs.h 2008-05-05 22:26:59.000000000 +0200
@@ -1251,6 +1251,7 @@ struct file_operations {
struct inode_operations {
int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
+ struct dentry * (*lookup_path) (struct inode *, struct qstr *);
int (*link) (struct dentry *,struct inode *,struct dentry *);
int (*unlink) (struct inode *,struct dentry *);
int (*symlink) (struct inode *,struct dentry *,const char *);





--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/