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