1 fs/exec.c | 18 +++++++---
2 fs/namei.c | 86 +++++++++++++++++++++++++++++++++++++++++++++----
5 fs/open.c | 62 +++++++++++++++++++++++------------
6 fs/stat.c | 24 ++++++++++---
7 include/linux/dcache.h | 3 +
8 include/linux/fs.h | 8 ++++
9 include/linux/namei.h | 56 ++++++++++++++++++++++++++-----
10 kernel/ksyms.c | 8 ++++
11 10 files changed, 222 insertions(+), 49 deletions(-)
13 Index: linux-2.6.0-test6/fs/exec.c
14 ===================================================================
15 --- linux-2.6.0-test6.orig/fs/exec.c 2003-10-07 15:14:14.000000000 +0800
16 +++ linux-2.6.0-test6/fs/exec.c 2003-10-07 15:33:15.000000000 +0800
21 + intent_init(&nd.intent, IT_OPEN);
23 - nd.intent.open.flags = O_RDONLY;
24 + error = user_path_walk_it(library, &nd);
26 + nd.intent.it_flags = O_RDONLY;
27 error = __user_walk(library, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd);
34 - file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
35 + file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent);
36 error = PTR_ERR(file);
40 struct file *open_exec(const char *name)
43 - int err = path_lookup(name, LOOKUP_FOLLOW, &nd);
44 - struct file *file = ERR_PTR(err);
48 + intent_init(&nd.intent, IT_OPEN);
49 + nd.intent.it_flags = O_RDONLY;
50 + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
51 + file = ERR_PTR(err);
54 struct inode *inode = nd.dentry->d_inode;
59 - file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
60 + file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent);
62 err = deny_write_access(file);
64 Index: linux-2.6.0-test6/fs/namei.c
65 ===================================================================
66 --- linux-2.6.0-test6.orig/fs/namei.c 2003-10-07 15:14:14.000000000 +0800
67 +++ linux-2.6.0-test6/fs/namei.c 2003-10-07 15:33:15.000000000 +0800
72 +void intent_release(struct lookup_intent *it)
76 + if (it->it_magic != INTENT_MAGIC)
78 + if (it->it_op_release)
79 + it->it_op_release(it);
82 void path_release(struct nameidata *nd)
84 + intent_release(&nd->intent);
90 struct dentry * result;
91 struct inode *dir = parent->d_inode;
98 * First re-do the cached lookup just in case it was created
100 if (result->d_op && result->d_op->d_revalidate) {
101 if (!result->d_op->d_revalidate(result, nd) && !d_invalidate(result)) {
103 - result = ERR_PTR(-ENOENT);
105 + result = ERR_PTR(-ESTALE);
106 + if (!IS_ERR(result))
112 return PTR_ERR(dentry);
115 +static int revalidate_special(struct nameidata *nd)
117 + struct dentry *dentry = nd->dentry;
118 + int err, counter = 0;
120 + if (!dentry->d_op || !dentry->d_op->d_revalidate)
123 + if (!dentry->d_op->d_revalidate(dentry, nd)) {
124 + struct dentry *new;
125 + if ((err = permission(dentry->d_parent->d_inode, MAY_EXEC,nd)))
127 + new = real_lookup(dentry->d_parent, &dentry->d_name, nd);
128 + d_invalidate(dentry);
133 + goto revalidate_again;
134 + printk("excessive revalidate_it loops\n");
145 if (inode->i_op->follow_link) {
147 + nd->flags |= LOOKUP_LINK_NOTLAST;
148 err = do_follow_link(next.dentry, nd);
149 + nd->flags &= ~LOOKUP_LINK_NOTLAST;
154 inode = nd->dentry->d_inode;
157 + nd->flags |= LOOKUP_LAST;
158 + err = revalidate_special(nd);
159 + nd->flags &= ~LOOKUP_LAST;
164 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
169 + nd->flags |= LOOKUP_LAST;
170 err = do_lookup(nd, &this, &next);
171 + nd->flags &= ~LOOKUP_LAST;
174 follow_mount(&next.mnt, &next.dentry);
179 -struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
180 +struct dentry * lookup_one_len_it(const char * name, struct dentry * base, int len, struct nameidata *nd)
184 @@ -948,11 +999,16 @@
186 this.hash = end_name_hash(hash);
188 - return lookup_hash(&this, base);
189 + return __lookup_hash(&this, base, nd);
191 return ERR_PTR(-EACCES);
194 +struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
196 + return lookup_one_len_it(name, base, len, NULL);
202 @@ -964,11 +1020,12 @@
203 * that namei follows links, while lnamei does not.
206 -int __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
207 +int __user_walk_it(const char __user *name, unsigned flags, struct nameidata *nd)
209 char *tmp = getname(name);
210 int err = PTR_ERR(tmp);
214 err = path_lookup(tmp, flags, nd);
216 @@ -976,6 +1033,12 @@
220 +int __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
222 + intent_init(&nd->intent, IT_LOOKUP);
223 + return __user_walk_it(name, flags, nd);
227 * It's inline, so penalty for filesystems that don't use sticky bit is
229 @@ -1248,8 +1311,8 @@
230 acc_mode |= MAY_APPEND;
232 /* Fill in the open() intent data */
233 - nd->intent.open.flags = flag;
234 - nd->intent.open.create_mode = mode;
235 + nd->intent.it_flags = flag;
236 + nd->intent.it_create_mode = mode;
239 * The simplest case - just a plain lookup.
240 @@ -1265,6 +1328,7 @@
242 * Create - we need to know the parent.
244 + nd->intent.it_op |= IT_CREAT;
245 error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd);
248 @@ -1281,7 +1345,9 @@
250 nd->flags &= ~LOOKUP_PARENT;
251 down(&dir->d_inode->i_sem);
252 + nd->flags |= LOOKUP_LAST;
253 dentry = __lookup_hash(&nd->last, nd->dentry, nd);
254 + nd->flags &= ~LOOKUP_LAST;
257 error = PTR_ERR(dentry);
258 @@ -1386,7 +1452,9 @@
261 down(&dir->d_inode->i_sem);
262 + nd->flags |= LOOKUP_LAST;
263 dentry = __lookup_hash(&nd->last, nd->dentry, nd);
264 + nd->flags &= ~LOOKUP_LAST;
265 putname(nd->last.name);
268 @@ -2148,7 +2216,9 @@
269 __vfs_follow_link(struct nameidata *nd, const char *link)
272 + struct lookup_intent it = nd->intent;
278 @@ -2158,6 +2228,10 @@
279 /* weird __emul_prefix() stuff did it */
283 + intent_init(&nd->intent, it.it_op);
284 + nd->intent.it_flags = it.it_flags;
285 + nd->intent.it_create_mode = it.it_create_mode;
286 res = link_path_walk(link, nd);
288 if (current->link_count || res || nd->last_type!=LAST_NORM)
289 Index: linux-2.6.0-test6/fs/namespace.c
290 ===================================================================
291 --- linux-2.6.0-test6.orig/fs/namespace.c 2003-09-28 08:50:31.000000000 +0800
292 +++ linux-2.6.0-test6/fs/namespace.c 2003-10-07 15:33:15.000000000 +0800
297 + intent_init(&nd.intent, IT_LOOKUP);
299 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
300 flags &= ~MS_MGC_MSK;
305 +EXPORT_SYMBOL(set_fs_pwd);
307 static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
309 Index: linux-2.6.0-test6/fs/open.c
310 ===================================================================
311 --- linux-2.6.0-test6.orig/fs/open.c 2003-10-07 15:14:14.000000000 +0800
312 +++ linux-2.6.0-test6/fs/open.c 2003-10-07 15:33:15.000000000 +0800
315 struct inode * inode;
318 + intent_init(&nd.intent, IT_GETATTR);
320 if (length < 0) /* sorry, but loff_t says... */
323 int old_fsuid, old_fsgid;
324 kernel_cap_t old_cap;
326 + intent_init(&nd.intent, IT_GETATTR);
328 if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
331 if(!res && (mode & S_IWOTH) && IS_RDONLY(nd.dentry->d_inode)
332 && !special_file(nd.dentry->d_inode->i_mode))
342 + intent_init(&nd.intent, IT_GETATTR);
344 error = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd);
350 + intent_init(&nd.intent, IT_GETATTR);
352 error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd);
356 if (IS_RDONLY(inode))
361 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
364 * for the internal routines (ie open_namei()/follow_link() etc). 00 is
367 -struct file *filp_open(const char * filename, int flags, int mode)
369 - int namei_flags, error;
370 - struct nameidata nd;
372 - namei_flags = flags;
373 - if ((namei_flags+1) & O_ACCMODE)
375 - if (namei_flags & O_TRUNC)
378 - error = open_namei(filename, namei_flags, mode, &nd);
380 - return dentry_open(nd.dentry, nd.mnt, flags);
382 - return ERR_PTR(error);
385 -struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
386 +struct file *dentry_open_it(struct dentry *dentry, struct vfsmount *mnt, int flags,
387 + struct lookup_intent *it)
394 f->f_mode = (flags+1) & O_ACCMODE;
396 inode = dentry->d_inode;
397 if (f->f_mode & FMODE_WRITE) {
398 error = get_write_access(inode);
400 error = f->f_op->open(inode,f);
403 + intent_release(it);
405 f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
407 @@ -810,11 +799,42 @@
411 + intent_release(it);
414 return ERR_PTR(error);
417 +struct file *filp_open(const char * filename, int flags, int mode)
419 + int namei_flags, error;
420 + struct file * temp_filp;
421 + struct nameidata nd;
422 + intent_init(&nd.intent, IT_OPEN);
424 + namei_flags = flags;
425 + if ((namei_flags+1) & O_ACCMODE)
427 + if (namei_flags & O_TRUNC)
430 + error = open_namei(filename, namei_flags, mode, &nd);
432 + temp_filp = dentry_open_it(nd.dentry, nd.mnt, flags, &nd.intent);
435 + return ERR_PTR(error);
439 +struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
441 + struct lookup_intent it;
442 + intent_init(&it, IT_LOOKUP);
444 + return dentry_open_it(dentry, mnt, flags, &it);
448 * Find an empty file descriptor entry, and mark it busy.
450 Index: linux-2.6.0-test6/fs/stat.c
451 ===================================================================
452 --- linux-2.6.0-test6.orig/fs/stat.c 2003-09-28 08:50:10.000000000 +0800
453 +++ linux-2.6.0-test6/fs/stat.c 2003-10-07 15:33:15.000000000 +0800
455 stat->blksize = inode->i_blksize;
458 -int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
459 +int vfs_getattr_it(struct vfsmount *mnt, struct dentry *dentry, struct lookup_intent *it, struct kstat *stat)
461 struct inode *inode = dentry->d_inode;
465 if (inode->i_op->getattr)
466 return inode->i_op->getattr(mnt, dentry, stat);
467 + if (inode->i_op->getattr_it)
468 + return inode->i_op->getattr_it(mnt, dentry, it, stat);
470 generic_fillattr(inode, stat);
471 if (!stat->blksize) {
476 +int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
478 + return vfs_getattr_it(mnt, dentry, NULL, stat);
481 int vfs_stat(char __user *name, struct kstat *stat)
485 + intent_init(&nd.intent, IT_GETATTR);
487 - error = user_path_walk(name, &nd);
488 + error = user_path_walk_it(name, &nd);
490 - error = vfs_getattr(nd.mnt, nd.dentry, stat);
491 + error = vfs_getattr_it(nd.mnt, nd.dentry, &nd.intent, stat);
499 + intent_init(&nd.intent, IT_GETATTR);
501 - error = user_path_walk_link(name, &nd);
502 + error = user_path_walk_link_it(name, &nd);
504 - error = vfs_getattr(nd.mnt, nd.dentry, stat);
505 + error = vfs_getattr_it(nd.mnt, nd.dentry, &nd.intent, stat);
511 struct file *f = fget(fd);
513 + struct nameidata nd;
514 + intent_init(&nd.intent, IT_GETATTR);
517 - error = vfs_getattr(f->f_vfsmnt, f->f_dentry, stat);
518 + error = vfs_getattr_it(f->f_vfsmnt, f->f_dentry, &nd.intent, stat);
519 + intent_release(&nd.intent);
523 Index: linux-2.6.0-test6/include/linux/dcache.h
524 ===================================================================
525 --- linux-2.6.0-test6.orig/include/linux/dcache.h 2003-09-28 08:51:16.000000000 +0800
526 +++ linux-2.6.0-test6/include/linux/dcache.h 2003-10-07 15:33:15.000000000 +0800
530 #include <asm/atomic.h>
531 +#include <linux/string.h>
532 #include <linux/list.h>
533 #include <linux/spinlock.h>
534 #include <linux/cache.h>
539 +#include <linux/namei.h>
541 struct dentry_stat_t {
544 Index: linux-2.6.0-test6/include/linux/fs.h
545 ===================================================================
546 --- linux-2.6.0-test6.orig/include/linux/fs.h 2003-10-07 15:14:15.000000000 +0800
547 +++ linux-2.6.0-test6/include/linux/fs.h 2003-10-07 15:34:10.000000000 +0800
549 #define ATTR_ATTR_FLAG 1024
550 #define ATTR_KILL_SUID 2048
551 #define ATTR_KILL_SGID 4096
552 +#define ATTR_RAW 8192 /* file system, not vfs will massage attrs */
553 +#define ATTR_FROM_OPEN 16384 /* called from open path, ie O_TRUNC */
556 * This is the Inode Attributes structure, used for notify_change(). It
558 struct block_device *i_bdev;
561 + void *i_filterdata;
563 unsigned long i_dnotify_mask; /* Directory notify events */
564 struct dnotify_struct *i_dnotify; /* for directory notifications */
566 struct list_head f_ep_links;
567 spinlock_t f_ep_lock;
568 struct address_space *f_mapping;
569 + struct lookup_intent *f_it;
571 extern spinlock_t files_lock;
572 #define file_list_lock() spin_lock(&files_lock);
574 void (*truncate) (struct inode *);
575 int (*permission) (struct inode *, int, struct nameidata *);
576 int (*setattr) (struct dentry *, struct iattr *);
577 + int (*setattr_raw) (struct inode *, struct iattr *);
578 int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
579 + int (*getattr_it) (struct vfsmount *, struct dentry *, struct lookup_intent *, struct kstat *);
580 int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
581 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
582 ssize_t (*listxattr) (struct dentry *, char *, size_t);
583 @@ -1052,6 +1058,7 @@
584 extern int unregister_filesystem(struct file_system_type *);
585 extern struct vfsmount *kern_mount(struct file_system_type *);
586 extern int may_umount(struct vfsmount *);
587 +struct vfsmount *do_kern_mount(const char *type, int flags, const char *name, void *data);
588 extern long do_mount(char *, char *, char *, unsigned long, void *);
590 extern int vfs_statfs(struct super_block *, struct kstatfs *);
591 @@ -1119,6 +1126,7 @@
593 extern struct file *filp_open(const char *, int, int);
594 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
595 +extern struct file * dentry_open_it(struct dentry *, struct vfsmount *, int, struct lookup_intent *);
596 extern int filp_close(struct file *, fl_owner_t id);
597 extern char * getname(const char __user *);
599 Index: linux-2.6.0-test6/include/linux/namei.h
600 ===================================================================
601 --- linux-2.6.0-test6.orig/include/linux/namei.h 2003-09-28 08:50:15.000000000 +0800
602 +++ linux-2.6.0-test6/include/linux/namei.h 2003-10-07 15:33:15.000000000 +0800
604 #define _LINUX_NAMEI_H
606 #include <linux/linkage.h>
607 +#include <linux/string.h>
612 -struct open_intent {
615 +/* intent opcodes */
617 +#define IT_CREAT (1<<1)
618 +#define IT_READDIR (1<<2)
619 +#define IT_GETATTR (1<<3)
620 +#define IT_LOOKUP (1<<4)
621 +#define IT_UNLINK (1<<5)
622 +#define IT_TRUNC (1<<6)
623 +#define IT_GETXATTR (1<<7)
625 +struct lustre_intent_data {
626 + int it_disposition;
628 + __u64 it_lock_handle;
633 +#define INTENT_MAGIC 0x19620323
634 +struct lookup_intent {
636 + void (*it_op_release)(struct lookup_intent *);
639 + int it_create_mode;
641 + struct lustre_intent_data lustre;
645 +static inline void intent_init(struct lookup_intent *it, int op)
647 + memset(it, 0, sizeof(*it));
648 + it->it_magic = INTENT_MAGIC;
653 struct dentry *dentry;
654 struct vfsmount *mnt;
661 - struct open_intent open;
663 + struct lookup_intent intent;
668 #define LOOKUP_CONTINUE 4
669 #define LOOKUP_PARENT 16
670 #define LOOKUP_NOALT 32
671 +#define LOOKUP_LAST (1<<6)
672 +#define LOOKUP_LINK_NOTLAST (1<<7)
678 #define LOOKUP_ACCESS (0x0400)
680 extern int FASTCALL(__user_walk(const char __user *, unsigned, struct nameidata *));
681 +extern int FASTCALL(__user_walk_it(const char __user *name, unsigned flags, struct nameidata *nd));
682 +#define user_path_walk_it(name,nd) \
683 + __user_walk_it(name, LOOKUP_FOLLOW, nd)
684 +#define user_path_walk_link_it(name,nd) \
685 + __user_walk_it(name, 0, nd)
686 +extern void intent_release(struct lookup_intent *);
687 #define user_path_walk(name,nd) \
688 __user_walk(name, LOOKUP_FOLLOW, nd)
689 #define user_path_walk_link(name,nd) \
692 extern struct dentry * lookup_one_len(const char *, struct dentry *, int);
693 extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
695 extern int follow_down(struct vfsmount **, struct dentry **);
696 extern int follow_up(struct vfsmount **, struct dentry **);
698 Index: linux-2.6.0-test6/kernel/ksyms.c
699 ===================================================================
700 --- linux-2.6.0-test6.orig/kernel/ksyms.c 2003-10-07 15:21:57.000000000 +0800
701 +++ linux-2.6.0-test6/kernel/ksyms.c 2003-10-07 15:33:15.000000000 +0800
702 @@ -220,11 +220,18 @@
703 EXPORT_SYMBOL(unregister_filesystem);
704 EXPORT_SYMBOL(__mntput);
705 EXPORT_SYMBOL(may_umount);
706 +EXPORT_SYMBOL(reparent_to_init);
708 /* interrupt handling */
709 EXPORT_SYMBOL(request_irq);
710 EXPORT_SYMBOL(free_irq);
713 +EXPORT_SYMBOL(do_kern_mount);
714 +EXPORT_SYMBOL(exit_files);
715 +//EXPORT_SYMBOL(kmem_cache_validate);
718 /* waitqueue handling */
719 EXPORT_SYMBOL(add_wait_queue);
720 EXPORT_SYMBOL(add_wait_queue_exclusive);
721 Index: linux-2.6.0-test6/fs/nfs/dir.c
722 ===================================================================
723 --- linux-2.6.0-test6.orig/fs/nfs/dir.c 2003-09-28 08:50:20.000000000 +0800
724 +++ linux-2.6.0-test6/fs/nfs/dir.c 2003-10-07 15:33:15.000000000 +0800
727 if (!nd || (nd->flags & LOOKUP_CONTINUE) || !(nd->flags & LOOKUP_CREATE))
729 - return (nd->intent.open.flags & O_EXCL) != 0;
730 + return (nd->intent.it_flags & O_EXCL) != 0;
733 static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
735 attr.ia_valid = ATTR_MODE;
737 if (nd && (nd->flags & LOOKUP_CREATE))
738 - open_flags = nd->intent.open.flags;
739 + open_flags = nd->intent.it_flags;
742 * The 0 argument passed into the create function should one day
743 Index: linux-2.6.0-test6/fs/inode.c
744 ===================================================================
745 --- linux-2.6.0-test6.orig/fs/inode.c 2003-10-07 15:14:14.000000000 +0800
746 +++ linux-2.6.0-test6/fs/inode.c 2003-10-07 15:38:08.000000000 +0800
748 inodes_stat.nr_unused--;
751 +EXPORT_SYMBOL(__iget);
753 * clear_inode - clear an inode
754 * @inode: inode to clear