Index: linux-2.6.10/fs/open.c =================================================================== --- linux-2.6.10.orig/fs/open.c 2005-03-31 15:35:27.683586616 +0800 +++ linux-2.6.10/fs/open.c 2005-03-31 17:13:48.440535208 +0800 @@ -217,11 +217,12 @@ struct inode * inode; int error; + intent_init(&nd.intent.open, IT_GETATTR); error = -EINVAL; if (length < 0) /* sorry, but loff_t says... */ goto out; - error = user_path_walk(path, &nd); + error = user_path_walk_it(path, &nd); if (error) goto out; inode = nd.dentry->d_inode; @@ -476,6 +477,7 @@ kernel_cap_t old_cap; int res; + intent_init(&nd.intent.open, IT_GETATTR); if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */ return -EINVAL; @@ -499,7 +501,7 @@ else current->cap_effective = current->cap_permitted; - res = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_ACCESS, &nd); + res = __user_walk_it(filename, LOOKUP_FOLLOW|LOOKUP_ACCESS, &nd); if (!res) { res = permission(nd.dentry->d_inode, mode, &nd); /* SuS v2 requires we report a read only fs too */ @@ -521,7 +523,8 @@ struct nameidata nd; int error; - error = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd); + intent_init(&nd.intent.open, IT_CHDIR); + error = __user_walk_it(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd); if (error) goto out; @@ -574,7 +577,8 @@ struct nameidata nd; int error; - error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd); + intent_init(&nd.intent.open, IT_GETATTR); + error = __user_walk_it(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd); if (error) goto out; @@ -759,6 +763,7 @@ { int namei_flags, error; struct nameidata nd; + intent_init(&nd.intent.open, IT_OPEN); namei_flags = flags; if ((namei_flags+1) & O_ACCMODE) @@ -768,14 +773,14 @@ error = open_namei(filename, namei_flags, mode, &nd); if (!error) - return dentry_open(nd.dentry, nd.mnt, flags); + return dentry_open_it(nd.dentry, nd.mnt, flags, &nd.intent.open); return ERR_PTR(error); } EXPORT_SYMBOL(filp_open); -struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags) +struct file *dentry_open_it(struct dentry *dentry, struct vfsmount *mnt, int flags, struct open_intent *it) { struct file * f; struct inode *inode; @@ -787,6 +792,7 @@ goto cleanup_dentry; f->f_flags = flags; f->f_mode = ((flags+1) & O_ACCMODE) | FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE; + f->f_it = it; inode = dentry->d_inode; if (f->f_mode & FMODE_WRITE) { error = get_write_access(inode); @@ -805,6 +811,7 @@ error = f->f_op->open(inode,f); if (error) goto cleanup_all; + intent_release(it); } f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); @@ -830,11 +837,20 @@ cleanup_file: put_filp(f); cleanup_dentry: + intent_release(it); dput(dentry); mntput(mnt); return ERR_PTR(error); } +struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags) +{ + struct open_intent it; + intent_init(&it, IT_LOOKUP); + + return dentry_open_it(dentry, mnt, flags, &it); +} + EXPORT_SYMBOL(dentry_open); /* Index: linux-2.6.10/fs/xattr.c =================================================================== --- linux-2.6.10.orig/fs/xattr.c 2004-12-25 05:34:32.000000000 +0800 +++ linux-2.6.10/fs/xattr.c 2005-03-31 17:03:37.148465728 +0800 @@ -164,7 +164,8 @@ struct nameidata nd; ssize_t error; - error = user_path_walk(path, &nd); + intent_init(&nd.intent.open, IT_GETXATTR); + error = user_path_walk_it(path, &nd); if (error) return error; error = getxattr(nd.dentry, name, value, size); @@ -179,7 +180,8 @@ struct nameidata nd; ssize_t error; - error = user_path_walk_link(path, &nd); + intent_init(&nd.intent.open, IT_GETXATTR); + error = user_path_walk_link_it(path, &nd); if (error) return error; error = getxattr(nd.dentry, name, value, size); @@ -245,7 +247,8 @@ struct nameidata nd; ssize_t error; - error = user_path_walk(path, &nd); + intent_init(&nd.intent.open, IT_GETXATTR); + error = user_path_walk_it(path, &nd); if (error) return error; error = listxattr(nd.dentry, list, size); @@ -259,7 +262,8 @@ struct nameidata nd; ssize_t error; - error = user_path_walk_link(path, &nd); + intent_init(&nd.intent.open, IT_GETXATTR); + error = user_path_walk_link_it(path, &nd); if (error) return error; error = listxattr(nd.dentry, list, size); Index: linux-2.6.10/fs/namei.c =================================================================== --- linux-2.6.10.orig/fs/namei.c 2005-03-31 15:35:26.294797744 +0800 +++ linux-2.6.10/fs/namei.c 2005-03-31 17:12:26.403006808 +0800 @@ -288,8 +288,19 @@ return 0; } +void intent_release(struct open_intent *it) +{ + if (!it) + return; + if (it->magic != INTENT_MAGIC) + return; + if (it->op_release) + it->op_release(it); +} + void path_release(struct nameidata *nd) { + intent_release(&nd->intent.open); dput(nd->dentry); mntput(nd->mnt); } @@ -448,6 +459,7 @@ static inline int __vfs_follow_link(struct nameidata *nd, const char *link) { int res = 0; + struct open_intent it = nd->intent.open; char *name; if (IS_ERR(link)) goto fail; @@ -458,6 +470,10 @@ /* weird __emul_prefix() stuff did it */ goto out; } + intent_release(&nd->intent.open); + intent_init(&nd->intent.open, it.op); + nd->intent.open.flags = it.flags; + nd->intent.open.create_mode = it.create_mode; res = link_path_walk(link, nd); out: if (nd->depth || res || nd->last_type!=LAST_NORM) @@ -876,8 +892,14 @@ return err; } +int fastcall path_walk_it(const char * name, struct nameidata *nd) +{ + current->total_link_count = 0; + return link_path_walk(name, nd); +} int fastcall path_walk(const char * name, struct nameidata *nd) { + intent_init(&nd->intent.open, IT_LOOKUP); current->total_link_count = 0; return link_path_walk(name, nd); } @@ -886,7 +908,7 @@ /* returns 1 if everything is done */ static int __emul_lookup_dentry(const char *name, struct nameidata *nd) { - if (path_walk(name, nd)) + if (path_walk_it(name, nd)) return 0; /* something went wrong... */ if (!nd->dentry->d_inode || S_ISDIR(nd->dentry->d_inode->i_mode)) { @@ -947,7 +969,18 @@ } } -int fastcall path_lookup(const char *name, unsigned int flags, struct nameidata *nd) +static inline int it_mode_from_lookup_flags(int flags) +{ + int mode = IT_LOOKUP; + + if (flags & LOOKUP_OPEN) + mode = IT_OPEN; + if (flags & LOOKUP_CREATE) + mode |= IT_CREAT; + return mode; +} + +int fastcall path_lookup_it(const char *name, unsigned int flags, struct nameidata *nd) { int retval; @@ -982,6 +1015,12 @@ return retval; } +int fastcall path_lookup(const char *name, unsigned int flags, struct nameidata *nd) +{ + intent_init(&nd->intent.open, it_mode_from_lookup_flags(flags)); + return path_lookup_it(name, flags, nd); +} + /* * Restricted form of lookup. Doesn't follow links, single-component only, * needs parent already locked. Doesn't follow mounts. @@ -1032,7 +1071,7 @@ } /* SMP-safe */ -struct dentry * lookup_one_len(const char * name, struct dentry * base, int len) +struct dentry * lookup_one_len_it(const char * name, struct dentry * base, int len, struct nameidata *nd) { unsigned long hash; struct qstr this; @@ -1052,11 +1091,16 @@ } this.hash = end_name_hash(hash); - return lookup_hash(&this, base); + return __lookup_hash(&this, base, nd); access: return ERR_PTR(-EACCES); } +struct dentry * lookup_one_len(const char * name, struct dentry * base, int len) +{ + return lookup_one_len_it(name, base, len, NULL); +} + /* * namei() * @@ -1068,18 +1112,24 @@ * that namei follows links, while lnamei does not. * SMP-safe */ -int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd) +int fastcall __user_walk_it(const char __user *name, unsigned flags, struct nameidata *nd) { char *tmp = getname(name); int err = PTR_ERR(tmp); if (!IS_ERR(tmp)) { - err = path_lookup(tmp, flags, nd); + err = path_lookup_it(tmp, flags, nd); putname(tmp); } return err; } +int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd) +{ + intent_init(&nd->intent.open, it_mode_from_lookup_flags(flags)); + return __user_walk_it(name, flags, nd); +} + /* * It's inline, so penalty for filesystems that don't use sticky bit is * minimal. @@ -1370,7 +1420,7 @@ * The simplest case - just a plain lookup. */ if (!(flag & O_CREAT)) { - error = path_lookup(pathname, lookup_flags(flag)|LOOKUP_OPEN, nd); + error = path_lookup_it(pathname, lookup_flags(flag), nd); if (error) return error; goto ok; @@ -1379,7 +1429,8 @@ /* * Create - we need to know the parent. */ - error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd); + nd->intent.open.op |= IT_CREAT; + error = path_lookup_it(pathname, LOOKUP_PARENT, nd); if (error) return error; @@ -2344,6 +2395,7 @@ } } + int page_symlink(struct inode *inode, const char *symname, int len) { struct address_space *mapping = inode->i_mapping; @@ -2405,8 +2457,10 @@ EXPORT_SYMBOL(page_symlink); EXPORT_SYMBOL(page_symlink_inode_operations); EXPORT_SYMBOL(path_lookup); +EXPORT_SYMBOL(path_lookup_it); EXPORT_SYMBOL(path_release); EXPORT_SYMBOL(path_walk); +EXPORT_SYMBOL(path_walk_it); EXPORT_SYMBOL(permission); EXPORT_SYMBOL(unlock_rename); EXPORT_SYMBOL(vfs_create); Index: linux-2.6.10/fs/stat.c =================================================================== --- linux-2.6.10.orig/fs/stat.c 2004-12-25 05:34:02.000000000 +0800 +++ linux-2.6.10/fs/stat.c 2005-03-31 17:03:37.144466336 +0800 @@ -60,15 +60,15 @@ } return 0; } - EXPORT_SYMBOL(vfs_getattr); int vfs_stat(char __user *name, struct kstat *stat) { struct nameidata nd; int error; + intent_init(&nd.intent.open, IT_GETATTR); - error = user_path_walk(name, &nd); + error = user_path_walk_it(name, &nd); if (!error) { error = vfs_getattr(nd.mnt, nd.dentry, stat); path_release(&nd); @@ -82,8 +82,9 @@ { struct nameidata nd; int error; + intent_init(&nd.intent.open, IT_GETATTR); - error = user_path_walk_link(name, &nd); + error = user_path_walk_link_it(name, &nd); if (!error) { error = vfs_getattr(nd.mnt, nd.dentry, stat); path_release(&nd); @@ -97,9 +98,12 @@ { struct file *f = fget(fd); int error = -EBADF; + struct nameidata nd; + intent_init(&nd.intent.open, IT_GETATTR); if (f) { error = vfs_getattr(f->f_vfsmnt, f->f_dentry, stat); + intent_release(&nd.intent.open); fput(f); } return error; Index: linux-2.6.10/fs/namespace.c =================================================================== --- linux-2.6.10.orig/fs/namespace.c 2005-03-31 15:35:26.295797592 +0800 +++ linux-2.6.10/fs/namespace.c 2005-03-31 17:03:37.145466184 +0800 @@ -113,6 +113,7 @@ static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd) { + memset(old_nd, 0, sizeof(*old_nd)); old_nd->dentry = mnt->mnt_mountpoint; old_nd->mnt = mnt->mnt_parent; mnt->mnt_parent = mnt; Index: linux-2.6.10/fs/exec.c =================================================================== --- linux-2.6.10.orig/fs/exec.c 2005-03-31 16:20:09.692859232 +0800 +++ linux-2.6.10/fs/exec.c 2005-03-31 17:03:37.147465880 +0800 @@ -125,8 +125,9 @@ struct nameidata nd; int error; + intent_init(&nd.intent.open, IT_OPEN); nd.intent.open.flags = FMODE_READ; - error = __user_walk(library, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd); + error = user_path_walk_it(library, &nd); if (error) goto out; @@ -138,7 +139,7 @@ if (error) goto exit; - file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); + file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent.open); error = PTR_ERR(file); if (IS_ERR(file)) goto out; @@ -485,8 +486,9 @@ int err; struct file *file; + intent_init(&nd.intent.open, IT_OPEN); nd.intent.open.flags = FMODE_READ; - err = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd); + err = path_lookup_it(name, LOOKUP_FOLLOW, &nd); file = ERR_PTR(err); if (!err) { @@ -499,7 +501,7 @@ err = -EACCES; file = ERR_PTR(err); if (!err) { - file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); + file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent.open); if (!IS_ERR(file)) { err = deny_write_access(file); if (err) { Index: linux-2.6.10/include/linux/fs.h =================================================================== --- linux-2.6.10.orig/include/linux/fs.h 2005-03-31 15:35:26.317794248 +0800 +++ linux-2.6.10/include/linux/fs.h 2005-03-31 17:03:37.135467704 +0800 @@ -600,6 +600,7 @@ spinlock_t f_ep_lock; #endif /* #ifdef CONFIG_EPOLL */ struct address_space *f_mapping; + struct open_intent *f_it; }; extern spinlock_t files_lock; #define file_list_lock() spin_lock(&files_lock); @@ -1245,6 +1246,7 @@ extern int do_truncate(struct dentry *, loff_t start); extern struct file *filp_open(const char *, int, int); extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); +extern struct file * dentry_open_it(struct dentry *, struct vfsmount *, int, struct open_intent *); extern int filp_close(struct file *, fl_owner_t id); extern char * getname(const char __user *); Index: linux-2.6.10/include/linux/namei.h =================================================================== --- linux-2.6.10.orig/include/linux/namei.h 2005-03-31 15:35:27.689585704 +0800 +++ linux-2.6.10/include/linux/namei.h 2005-03-31 17:10:14.746021712 +0800 @@ -2,14 +2,41 @@ #define _LINUX_NAMEI_H #include +#include struct vfsmount; +/* intent opcodes */ +#define IT_OPEN (1) +#define IT_CREAT (1<<1) +#define IT_READDIR (1<<2) +#define IT_GETATTR (1<<3) +#define IT_LOOKUP (1<<4) +#define IT_UNLINK (1<<5) +#define IT_TRUNC (1<<6) +#define IT_GETXATTR (1<<7) + +#define INTENT_MAGIC 0x19620323 + + struct open_intent { + int magic; + int op; + void (*op_release)(struct open_intent *); int flags; int create_mode; + union { + void *fs_data; /* FS-specific intent data */ + } d; }; +static inline void intent_init(struct open_intent *it, int op) +{ + memset(it, 0, sizeof(*it)); + it->magic = INTENT_MAGIC; + it->op = op; +} + enum { MAX_NESTED_LINKS = 8 }; struct nameidata { @@ -55,14 +82,22 @@ #define LOOKUP_ACCESS (0x0400) extern int FASTCALL(__user_walk(const char __user *, unsigned, struct nameidata *)); +extern int FASTCALL(__user_walk_it(const char __user *, unsigned, struct nameidata *)); #define user_path_walk(name,nd) \ __user_walk(name, LOOKUP_FOLLOW, nd) +#define user_path_walk_it(name,nd) \ + __user_walk_it(name, LOOKUP_FOLLOW, nd) #define user_path_walk_link(name,nd) \ __user_walk(name, 0, nd) +#define user_path_walk_link_it(name,nd) \ + __user_walk_it(name, 0, nd) extern int FASTCALL(path_lookup(const char *, unsigned, struct nameidata *)); +extern int FASTCALL(path_lookup_it(const char *, unsigned, struct nameidata *)); extern int FASTCALL(path_walk(const char *, struct nameidata *)); +extern int FASTCALL(path_walk_it(const char *, struct nameidata *)); extern int FASTCALL(link_path_walk(const char *, struct nameidata *)); extern void path_release(struct nameidata *); +extern void intent_release(struct open_intent *); extern void path_release_on_umount(struct nameidata *); extern struct dentry * lookup_one_len(const char *, struct dentry *, int); Index: linux-2.6.10/include/linux/mount.h =================================================================== --- linux-2.6.10.orig/include/linux/mount.h 2004-12-25 05:33:51.000000000 +0800 +++ linux-2.6.10/include/linux/mount.h 2005-03-31 17:15:40.613482328 +0800 @@ -36,6 +36,8 @@ struct list_head mnt_list; struct list_head mnt_fslink; /* link in fs-specific expiry list */ struct namespace *mnt_namespace; /* containing namespace */ + struct list_head mnt_lustre_list; /* GNS mount list */ + unsigned long mnt_last_used; /* for GNS auto-umount (jiffies) */ }; static inline struct vfsmount *mntget(struct vfsmount *mnt)