Whamcloud - gitweb
b=6866
[fs/lustre-release.git] / lustre / kernel_patches / patches / vfs-intent_api-vanilla-2.6.10-fc3.patch
1 Index: linux-2.6.10/fs/open.c
2 ===================================================================
3 --- linux-2.6.10.orig/fs/open.c 2005-03-31 15:35:27.683586616 +0800
4 +++ linux-2.6.10/fs/open.c      2005-03-31 17:13:48.440535208 +0800
5 @@ -217,11 +217,12 @@
6         struct inode * inode;
7         int error;
8  
9 +       intent_init(&nd.intent.open, IT_GETATTR);
10         error = -EINVAL;
11         if (length < 0) /* sorry, but loff_t says... */
12                 goto out;
13  
14 -       error = user_path_walk(path, &nd);
15 +       error = user_path_walk_it(path, &nd);
16         if (error)
17                 goto out;
18         inode = nd.dentry->d_inode;
19 @@ -476,6 +477,7 @@
20         kernel_cap_t old_cap;
21         int res;
22  
23 +       intent_init(&nd.intent.open, IT_GETATTR);
24         if (mode & ~S_IRWXO)    /* where's F_OK, X_OK, W_OK, R_OK? */
25                 return -EINVAL;
26  
27 @@ -499,7 +501,7 @@
28         else
29                 current->cap_effective = current->cap_permitted;
30  
31 -       res = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_ACCESS, &nd);
32 +       res = __user_walk_it(filename, LOOKUP_FOLLOW|LOOKUP_ACCESS, &nd);
33         if (!res) {
34                 res = permission(nd.dentry->d_inode, mode, &nd);
35                 /* SuS v2 requires we report a read only fs too */
36 @@ -521,7 +523,8 @@
37         struct nameidata nd;
38         int error;
39  
40 -       error = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd);
41 +       intent_init(&nd.intent.open, IT_CHDIR);
42 +       error = __user_walk_it(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd);
43         if (error)
44                 goto out;
45  
46 @@ -574,7 +577,8 @@
47         struct nameidata nd;
48         int error;
49  
50 -       error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd);
51 +       intent_init(&nd.intent.open, IT_GETATTR);
52 +       error = __user_walk_it(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd);
53         if (error)
54                 goto out;
55  
56 @@ -759,6 +763,7 @@
57  {
58         int namei_flags, error;
59         struct nameidata nd;
60 +       intent_init(&nd.intent.open, IT_OPEN);
61  
62         namei_flags = flags;
63         if ((namei_flags+1) & O_ACCMODE)
64 @@ -768,14 +773,14 @@
65  
66         error = open_namei(filename, namei_flags, mode, &nd);
67         if (!error)
68 -               return dentry_open(nd.dentry, nd.mnt, flags);
69 +               return dentry_open_it(nd.dentry, nd.mnt, flags, &nd.intent.open);
70  
71         return ERR_PTR(error);
72  }
73  
74  EXPORT_SYMBOL(filp_open);
75  
76 -struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
77 +struct file *dentry_open_it(struct dentry *dentry, struct vfsmount *mnt, int flags, struct open_intent *it)
78  {
79         struct file * f;
80         struct inode *inode;
81 @@ -787,6 +792,7 @@
82                 goto cleanup_dentry;
83         f->f_flags = flags;
84         f->f_mode = ((flags+1) & O_ACCMODE) | FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE;
85 +       f->f_it = it;
86         inode = dentry->d_inode;
87         if (f->f_mode & FMODE_WRITE) {
88                 error = get_write_access(inode);
89 @@ -805,6 +811,7 @@
90                 error = f->f_op->open(inode,f);
91                 if (error)
92                         goto cleanup_all;
93 +               intent_release(it);
94         }
95         f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
96  
97 @@ -830,11 +837,20 @@
98  cleanup_file:
99         put_filp(f);
100  cleanup_dentry:
101 +       intent_release(it);
102         dput(dentry);
103         mntput(mnt);
104         return ERR_PTR(error);
105  }
106  
107 +struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
108 +{
109 +       struct open_intent it;
110 +       intent_init(&it, IT_LOOKUP);
111 +
112 +       return dentry_open_it(dentry, mnt, flags, &it);
113 +}
114 +
115  EXPORT_SYMBOL(dentry_open);
116  
117  /*
118 Index: linux-2.6.10/fs/xattr.c
119 ===================================================================
120 --- linux-2.6.10.orig/fs/xattr.c        2004-12-25 05:34:32.000000000 +0800
121 +++ linux-2.6.10/fs/xattr.c     2005-03-31 17:03:37.148465728 +0800
122 @@ -164,7 +164,8 @@
123         struct nameidata nd;
124         ssize_t error;
125  
126 -       error = user_path_walk(path, &nd);
127 +       intent_init(&nd.intent.open, IT_GETXATTR);
128 +       error = user_path_walk_it(path, &nd);
129         if (error)
130                 return error;
131         error = getxattr(nd.dentry, name, value, size);
132 @@ -179,7 +180,8 @@
133         struct nameidata nd;
134         ssize_t error;
135  
136 -       error = user_path_walk_link(path, &nd);
137 +       intent_init(&nd.intent.open, IT_GETXATTR);
138 +       error = user_path_walk_link_it(path, &nd);
139         if (error)
140                 return error;
141         error = getxattr(nd.dentry, name, value, size);
142 @@ -245,7 +247,8 @@
143         struct nameidata nd;
144         ssize_t error;
145  
146 -       error = user_path_walk(path, &nd);
147 +       intent_init(&nd.intent.open, IT_GETXATTR);
148 +       error = user_path_walk_it(path, &nd);
149         if (error)
150                 return error;
151         error = listxattr(nd.dentry, list, size);
152 @@ -259,7 +262,8 @@
153         struct nameidata nd;
154         ssize_t error;
155  
156 -       error = user_path_walk_link(path, &nd);
157 +       intent_init(&nd.intent.open, IT_GETXATTR);
158 +       error = user_path_walk_link_it(path, &nd);
159         if (error)
160                 return error;
161         error = listxattr(nd.dentry, list, size);
162 Index: linux-2.6.10/fs/namei.c
163 ===================================================================
164 --- linux-2.6.10.orig/fs/namei.c        2005-03-31 15:35:26.294797744 +0800
165 +++ linux-2.6.10/fs/namei.c     2005-03-31 17:12:26.403006808 +0800
166 @@ -288,8 +288,19 @@
167         return 0;
168  }
169  
170 +void intent_release(struct open_intent *it)
171 +{
172 +       if (!it)
173 +               return;
174 +       if (it->magic != INTENT_MAGIC)
175 +               return;
176 +       if (it->op_release)
177 +               it->op_release(it);
178 +}
179 +
180  void path_release(struct nameidata *nd)
181  {
182 +       intent_release(&nd->intent.open);
183         dput(nd->dentry);
184         mntput(nd->mnt);
185  }
186 @@ -448,6 +459,7 @@
187  static inline int __vfs_follow_link(struct nameidata *nd, const char *link)
188  {
189         int res = 0;
190 +       struct open_intent it = nd->intent.open;
191         char *name;
192         if (IS_ERR(link))
193                 goto fail;
194 @@ -458,6 +470,10 @@
195                         /* weird __emul_prefix() stuff did it */
196                         goto out;
197         }
198 +       intent_release(&nd->intent.open);
199 +       intent_init(&nd->intent.open, it.op);
200 +       nd->intent.open.flags = it.flags;
201 +       nd->intent.open.create_mode = it.create_mode;
202         res = link_path_walk(link, nd);
203  out:
204         if (nd->depth || res || nd->last_type!=LAST_NORM)
205 @@ -876,8 +892,14 @@
206         return err;
207  }
208  
209 +int fastcall path_walk_it(const char * name, struct nameidata *nd)
210 +{
211 +       current->total_link_count = 0;
212 +       return link_path_walk(name, nd);
213 +}
214  int fastcall path_walk(const char * name, struct nameidata *nd)
215  {
216 +       intent_init(&nd->intent.open, IT_LOOKUP);
217         current->total_link_count = 0;
218         return link_path_walk(name, nd);
219  }
220 @@ -886,7 +908,7 @@
221  /* returns 1 if everything is done */
222  static int __emul_lookup_dentry(const char *name, struct nameidata *nd)
223  {
224 -       if (path_walk(name, nd))
225 +       if (path_walk_it(name, nd))
226                 return 0;               /* something went wrong... */
227  
228         if (!nd->dentry->d_inode || S_ISDIR(nd->dentry->d_inode->i_mode)) {
229 @@ -947,7 +969,18 @@
230         }
231  }
232  
233 -int fastcall path_lookup(const char *name, unsigned int flags, struct nameidata *nd)
234 +static inline int it_mode_from_lookup_flags(int flags)
235 +{
236 +       int mode = IT_LOOKUP;
237 +
238 +       if (flags & LOOKUP_OPEN)
239 +               mode = IT_OPEN;
240 +       if (flags & LOOKUP_CREATE)
241 +               mode |= IT_CREAT;
242 +       return mode;
243 +}
244 +
245 +int fastcall path_lookup_it(const char *name, unsigned int flags, struct nameidata *nd)
246  {
247         int retval;
248  
249 @@ -982,6 +1015,12 @@
250         return retval;
251  }
252  
253 +int fastcall path_lookup(const char *name, unsigned int flags, struct nameidata *nd)
254 +{
255 +       intent_init(&nd->intent.open, it_mode_from_lookup_flags(flags));
256 +       return path_lookup_it(name, flags, nd);
257 +}
258 +
259  /*
260   * Restricted form of lookup. Doesn't follow links, single-component only,
261   * needs parent already locked. Doesn't follow mounts.
262 @@ -1032,7 +1071,7 @@
263  }
264  
265  /* SMP-safe */
266 -struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
267 +struct dentry * lookup_one_len_it(const char * name, struct dentry * base, int len, struct nameidata *nd)
268  {
269         unsigned long hash;
270         struct qstr this;
271 @@ -1052,11 +1091,16 @@
272         }
273         this.hash = end_name_hash(hash);
274  
275 -       return lookup_hash(&this, base);
276 +       return __lookup_hash(&this, base, nd);
277  access:
278         return ERR_PTR(-EACCES);
279  }
280  
281 +struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
282 +{
283 +       return lookup_one_len_it(name, base, len, NULL);
284 +}
285 +
286  /*
287   *     namei()
288   *
289 @@ -1068,18 +1112,24 @@
290   * that namei follows links, while lnamei does not.
291   * SMP-safe
292   */
293 -int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
294 +int fastcall __user_walk_it(const char __user *name, unsigned flags, struct nameidata *nd)
295  {
296         char *tmp = getname(name);
297         int err = PTR_ERR(tmp);
298  
299         if (!IS_ERR(tmp)) {
300 -               err = path_lookup(tmp, flags, nd);
301 +               err = path_lookup_it(tmp, flags, nd);
302                 putname(tmp);
303         }
304         return err;
305  }
306  
307 +int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
308 +{
309 +       intent_init(&nd->intent.open, it_mode_from_lookup_flags(flags));
310 +       return __user_walk_it(name, flags, nd);
311 +}
312 +
313  /*
314   * It's inline, so penalty for filesystems that don't use sticky bit is
315   * minimal.
316 @@ -1370,7 +1420,7 @@
317          * The simplest case - just a plain lookup.
318          */
319         if (!(flag & O_CREAT)) {
320 -               error = path_lookup(pathname, lookup_flags(flag)|LOOKUP_OPEN, nd);
321 +               error = path_lookup_it(pathname, lookup_flags(flag), nd);
322                 if (error)
323                         return error;
324                 goto ok;
325 @@ -1379,7 +1429,8 @@
326         /*
327          * Create - we need to know the parent.
328          */
329 -       error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd);
330 +       nd->intent.open.op |= IT_CREAT;
331 +       error = path_lookup_it(pathname, LOOKUP_PARENT, nd);
332         if (error)
333                 return error;
334  
335 @@ -2344,6 +2395,7 @@
336         }
337  }
338  
339 +
340  int page_symlink(struct inode *inode, const char *symname, int len)
341  {
342         struct address_space *mapping = inode->i_mapping;
343 @@ -2405,8 +2457,10 @@
344  EXPORT_SYMBOL(page_symlink);
345  EXPORT_SYMBOL(page_symlink_inode_operations);
346  EXPORT_SYMBOL(path_lookup);
347 +EXPORT_SYMBOL(path_lookup_it);
348  EXPORT_SYMBOL(path_release);
349  EXPORT_SYMBOL(path_walk);
350 +EXPORT_SYMBOL(path_walk_it);
351  EXPORT_SYMBOL(permission);
352  EXPORT_SYMBOL(unlock_rename);
353  EXPORT_SYMBOL(vfs_create);
354 Index: linux-2.6.10/fs/stat.c
355 ===================================================================
356 --- linux-2.6.10.orig/fs/stat.c 2004-12-25 05:34:02.000000000 +0800
357 +++ linux-2.6.10/fs/stat.c      2005-03-31 17:03:37.144466336 +0800
358 @@ -60,15 +60,15 @@
359         }
360         return 0;
361  }
362 -
363  EXPORT_SYMBOL(vfs_getattr);
364  
365  int vfs_stat(char __user *name, struct kstat *stat)
366  {
367         struct nameidata nd;
368         int error;
369 +       intent_init(&nd.intent.open, IT_GETATTR);
370  
371 -       error = user_path_walk(name, &nd);
372 +       error = user_path_walk_it(name, &nd);
373         if (!error) {
374                 error = vfs_getattr(nd.mnt, nd.dentry, stat);
375                 path_release(&nd);
376 @@ -82,8 +82,9 @@
377  {
378         struct nameidata nd;
379         int error;
380 +       intent_init(&nd.intent.open, IT_GETATTR);
381  
382 -       error = user_path_walk_link(name, &nd);
383 +       error = user_path_walk_link_it(name, &nd);
384         if (!error) {
385                 error = vfs_getattr(nd.mnt, nd.dentry, stat);
386                 path_release(&nd);
387 @@ -97,9 +98,12 @@
388  {
389         struct file *f = fget(fd);
390         int error = -EBADF;
391 +       struct nameidata nd;
392 +       intent_init(&nd.intent.open, IT_GETATTR);
393  
394         if (f) {
395                 error = vfs_getattr(f->f_vfsmnt, f->f_dentry, stat);
396 +               intent_release(&nd.intent.open);
397                 fput(f);
398         }
399         return error;
400 Index: linux-2.6.10/fs/namespace.c
401 ===================================================================
402 --- linux-2.6.10.orig/fs/namespace.c    2005-03-31 15:35:26.295797592 +0800
403 +++ linux-2.6.10/fs/namespace.c 2005-03-31 17:03:37.145466184 +0800
404 @@ -113,6 +113,7 @@
405  
406  static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd)
407  {
408 +       memset(old_nd, 0, sizeof(*old_nd));
409         old_nd->dentry = mnt->mnt_mountpoint;
410         old_nd->mnt = mnt->mnt_parent;
411         mnt->mnt_parent = mnt;
412 Index: linux-2.6.10/fs/exec.c
413 ===================================================================
414 --- linux-2.6.10.orig/fs/exec.c 2005-03-31 16:20:09.692859232 +0800
415 +++ linux-2.6.10/fs/exec.c      2005-03-31 17:03:37.147465880 +0800
416 @@ -125,8 +125,9 @@
417         struct nameidata nd;
418         int error;
419  
420 +       intent_init(&nd.intent.open, IT_OPEN);
421         nd.intent.open.flags = FMODE_READ;
422 -       error = __user_walk(library, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd);
423 +       error = user_path_walk_it(library, &nd);
424         if (error)
425                 goto out;
426  
427 @@ -138,7 +139,7 @@
428         if (error)
429                 goto exit;
430  
431 -       file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
432 +       file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent.open);
433         error = PTR_ERR(file);
434         if (IS_ERR(file))
435                 goto out;
436 @@ -485,8 +486,9 @@
437         int err;
438         struct file *file;
439  
440 +       intent_init(&nd.intent.open, IT_OPEN);
441         nd.intent.open.flags = FMODE_READ;
442 -       err = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd);
443 +       err = path_lookup_it(name, LOOKUP_FOLLOW, &nd);
444         file = ERR_PTR(err);
445  
446         if (!err) {
447 @@ -499,7 +501,7 @@
448                                 err = -EACCES;
449                         file = ERR_PTR(err);
450                         if (!err) {
451 -                               file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
452 +                               file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent.open);
453                                 if (!IS_ERR(file)) {
454                                         err = deny_write_access(file);
455                                         if (err) {
456 Index: linux-2.6.10/include/linux/fs.h
457 ===================================================================
458 --- linux-2.6.10.orig/include/linux/fs.h        2005-03-31 15:35:26.317794248 +0800
459 +++ linux-2.6.10/include/linux/fs.h     2005-03-31 17:03:37.135467704 +0800
460 @@ -600,6 +600,7 @@
461         spinlock_t              f_ep_lock;
462  #endif /* #ifdef CONFIG_EPOLL */
463         struct address_space    *f_mapping;
464 +       struct open_intent      *f_it;
465  };
466  extern spinlock_t files_lock;
467  #define file_list_lock() spin_lock(&files_lock);
468 @@ -1245,6 +1246,7 @@
469  extern int do_truncate(struct dentry *, loff_t start);
470  extern struct file *filp_open(const char *, int, int);
471  extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
472 +extern struct file * dentry_open_it(struct dentry *, struct vfsmount *, int, struct open_intent *);
473  extern int filp_close(struct file *, fl_owner_t id);
474  extern char * getname(const char __user *);
475  
476 Index: linux-2.6.10/include/linux/namei.h
477 ===================================================================
478 --- linux-2.6.10.orig/include/linux/namei.h     2005-03-31 15:35:27.689585704 +0800
479 +++ linux-2.6.10/include/linux/namei.h  2005-03-31 17:10:14.746021712 +0800
480 @@ -2,14 +2,41 @@
481  #define _LINUX_NAMEI_H
482  
483  #include <linux/linkage.h>
484 +#include <linux/string.h>
485  
486  struct vfsmount;
487  
488 +/* intent opcodes */
489 +#define IT_OPEN                (1)
490 +#define IT_CREAT       (1<<1)
491 +#define IT_READDIR     (1<<2)
492 +#define IT_GETATTR     (1<<3)
493 +#define IT_LOOKUP      (1<<4)
494 +#define IT_UNLINK      (1<<5)
495 +#define IT_TRUNC       (1<<6)
496 +#define IT_GETXATTR    (1<<7)
497
498 +#define INTENT_MAGIC 0x19620323
499
500 +
501  struct open_intent {
502 +       int     magic;
503 +       int     op;
504 +       void    (*op_release)(struct open_intent *);
505         int     flags;
506         int     create_mode;
507 +       union {
508 +               void *fs_data; /* FS-specific intent data */
509 +       } d;
510  };
511  
512 +static inline void intent_init(struct open_intent *it, int op)
513 +{
514 +       memset(it, 0, sizeof(*it));
515 +       it->magic = INTENT_MAGIC;
516 +       it->op = op;
517 +}
518
519  enum { MAX_NESTED_LINKS = 8 };
520  
521  struct nameidata {
522 @@ -55,14 +82,22 @@
523  #define LOOKUP_ACCESS          (0x0400)
524  
525  extern int FASTCALL(__user_walk(const char __user *, unsigned, struct nameidata *));
526 +extern int FASTCALL(__user_walk_it(const char __user *, unsigned, struct nameidata *));
527  #define user_path_walk(name,nd) \
528         __user_walk(name, LOOKUP_FOLLOW, nd)
529 +#define user_path_walk_it(name,nd) \
530 +       __user_walk_it(name, LOOKUP_FOLLOW, nd)
531  #define user_path_walk_link(name,nd) \
532         __user_walk(name, 0, nd)
533 +#define user_path_walk_link_it(name,nd) \
534 +       __user_walk_it(name, 0, nd)
535  extern int FASTCALL(path_lookup(const char *, unsigned, struct nameidata *));
536 +extern int FASTCALL(path_lookup_it(const char *, unsigned, struct nameidata *));
537  extern int FASTCALL(path_walk(const char *, struct nameidata *));
538 +extern int FASTCALL(path_walk_it(const char *, struct nameidata *));
539  extern int FASTCALL(link_path_walk(const char *, struct nameidata *));
540  extern void path_release(struct nameidata *);
541 +extern void intent_release(struct open_intent *);
542  extern void path_release_on_umount(struct nameidata *);
543  
544  extern struct dentry * lookup_one_len(const char *, struct dentry *, int);
545 Index: linux-2.6.10/include/linux/mount.h
546 ===================================================================
547 --- linux-2.6.10.orig/include/linux/mount.h     2004-12-25 05:33:51.000000000 +0800
548 +++ linux-2.6.10/include/linux/mount.h  2005-03-31 17:15:40.613482328 +0800
549 @@ -36,6 +36,8 @@
550         struct list_head mnt_list;
551         struct list_head mnt_fslink;    /* link in fs-specific expiry list */
552         struct namespace *mnt_namespace; /* containing namespace */
553 +        struct list_head mnt_lustre_list; /* GNS mount list */
554 +        unsigned long mnt_last_used;      /* for GNS auto-umount (jiffies) */
555  };
556  
557  static inline struct vfsmount *mntget(struct vfsmount *mnt)