Whamcloud - gitweb
smash the HEAD with the contents of b_cmd. HEAD_PRE_CMD_SMASH and
[fs/lustre-release.git] / lustre / kernel_patches / patches / vfs_intent-2.4.20-hp.patch
1  fs/dcache.c               |   19 ++
2  fs/exec.c                 |   17 +-
3  fs/namei.c                |  330 +++++++++++++++++++++++++++++++++++++++-------
4  fs/namespace.c            |   28 ++-
5  fs/open.c                 |  172 +++++++++++++++++------
6  fs/proc/base.c            |    3 
7  fs/stat.c                 |   52 ++++---
8  include/linux/dcache.h    |   60 ++++++++
9  include/linux/fs.h        |   32 ++++
10  include/linux/fs_struct.h |    4 
11  kernel/exit.c             |    3 
12  kernel/fork.c             |    3 
13  kernel/ksyms.c            |    1 
14  13 files changed, 591 insertions(+), 133 deletions(-)
15
16 Index: linux/fs/exec.c
17 ===================================================================
18 --- linux.orig/fs/exec.c        Wed Mar 17 13:00:38 2004
19 +++ linux/fs/exec.c     Wed Mar 17 13:11:25 2004
20 @@ -115,8 +115,10 @@
21         struct file * file;
22         struct nameidata nd;
23         int error;
24 +       struct lookup_intent it = { .it_op = IT_OPEN,
25 +                                   .it_flags = FMODE_READ|FMODE_EXEC };
26  
27 -       error = user_path_walk(library, &nd);
28 +       error = user_path_walk_it(library, &nd, &it);
29         if (error)
30                 goto out;
31  
32 @@ -128,7 +130,8 @@
33         if (error)
34                 goto exit;
35  
36 -       file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
37 +       file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &it);
38 +       intent_release(&it);
39         error = PTR_ERR(file);
40         if (IS_ERR(file))
41                 goto out;
42 @@ -371,8 +374,10 @@
43         struct inode *inode;
44         struct file *file;
45         int err = 0;
46 +       struct lookup_intent it = { .it_op = IT_OPEN,
47 +                                   .it_flags = FMODE_READ|FMODE_EXEC };
48  
49 -       err = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd);
50 +       err = path_lookup_it(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd, &it);
51         file = ERR_PTR(err);
52         if (!err) {
53                 inode = nd.dentry->d_inode;
54 @@ -384,7 +389,8 @@
55                                 err = -EACCES;
56                         file = ERR_PTR(err);
57                         if (!err) {
58 -                               file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
59 +                               file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &it);
60 +                               intent_release(&it);
61                                 if (!IS_ERR(file)) {
62                                         err = deny_write_access(file);
63                                         if (err) {
64 @@ -396,6 +402,7 @@
65                                 return file;
66                         }
67                 }
68 +               intent_release(&it);
69                 path_release(&nd);
70         }
71         goto out;
72 @@ -1120,7 +1127,7 @@
73                 goto close_fail;
74         if (!file->f_op->write)
75                 goto close_fail;
76 -       if (do_truncate(file->f_dentry, 0) != 0)
77 +       if (do_truncate(file->f_dentry, 0, 0) != 0)
78                 goto close_fail;
79  
80         retval = binfmt->core_dump(signr, regs, file);
81 Index: linux/fs/dcache.c
82 ===================================================================
83 --- linux.orig/fs/dcache.c      Thu Nov 28 18:53:15 2002
84 +++ linux/fs/dcache.c   Wed Mar 17 13:11:25 2004
85 @@ -181,6 +181,13 @@
86                 spin_unlock(&dcache_lock);
87                 return 0;
88         }
89 +
90 +       /* network invalidation by Lustre */
91 +       if (dentry->d_flags & DCACHE_LUSTRE_INVALID) {
92 +               spin_unlock(&dcache_lock);
93 +               return 0;
94 +       }
95 +
96         /*
97          * Check whether to do a partial shrink_dcache
98          * to get rid of unused child entries.
99 @@ -830,13 +837,19 @@
100   * Adds a dentry to the hash according to its name.
101   */
102   
103 -void d_rehash(struct dentry * entry)
104 +void __d_rehash(struct dentry * entry, int lock)
105  {
106         struct list_head *list = d_hash(entry->d_parent, entry->d_name.hash);
107         if (!list_empty(&entry->d_hash)) BUG();
108 -       spin_lock(&dcache_lock);
109 +       if (lock) spin_lock(&dcache_lock);
110         list_add(&entry->d_hash, list);
111 -       spin_unlock(&dcache_lock);
112 +       if (lock) spin_unlock(&dcache_lock);
113 +}
114 +EXPORT_SYMBOL(__d_rehash);
115 +
116 +void d_rehash(struct dentry * entry)
117 +{
118 +       __d_rehash(entry, 1);
119  }
120  
121  #define do_switch(x,y) do { \
122 Index: linux/fs/namespace.c
123 ===================================================================
124 --- linux.orig/fs/namespace.c   Thu Nov 28 18:53:15 2002
125 +++ linux/fs/namespace.c        Wed Mar 17 13:11:25 2004
126 @@ -99,6 +99,7 @@
127  {
128         old_nd->dentry = mnt->mnt_mountpoint;
129         old_nd->mnt = mnt->mnt_parent;
130 +       UNPIN(old_nd->dentry, old_nd->mnt, 1);
131         mnt->mnt_parent = mnt;
132         mnt->mnt_mountpoint = mnt->mnt_root;
133         list_del_init(&mnt->mnt_child);
134 @@ -110,6 +111,7 @@
135  {
136         mnt->mnt_parent = mntget(nd->mnt);
137         mnt->mnt_mountpoint = dget(nd->dentry);
138 +       PIN(nd->dentry, nd->mnt, 1);
139         list_add(&mnt->mnt_hash, mount_hashtable+hash(nd->mnt, nd->dentry));
140         list_add(&mnt->mnt_child, &nd->mnt->mnt_mounts);
141         nd->dentry->d_mounted++;
142 @@ -485,14 +487,17 @@
143  {
144         struct nameidata old_nd;
145         struct vfsmount *mnt = NULL;
146 +       struct lookup_intent it = { .it_op = IT_GETATTR };
147         int err = mount_is_safe(nd);
148         if (err)
149                 return err;
150         if (!old_name || !*old_name)
151                 return -EINVAL;
152 -       err = path_lookup(old_name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &old_nd);
153 -       if (err)
154 +       err = path_lookup_it(old_name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &old_nd, &it);
155 +       if (err) {
156 +               intent_release(&it);
157                 return err;
158 +       }
159  
160         down_write(&current->namespace->sem);
161         err = -EINVAL;
162 @@ -515,6 +520,7 @@
163         }
164  
165         up_write(&current->namespace->sem);
166 +       intent_release(&it);
167         path_release(&old_nd);
168         return err;
169  }
170 @@ -698,6 +704,7 @@
171                   unsigned long flags, void *data_page)
172  {
173         struct nameidata nd;
174 +       struct lookup_intent it = { .it_op = IT_GETATTR };
175         int retval = 0;
176         int mnt_flags = 0;
177  
178 @@ -722,10 +729,11 @@
179         flags &= ~(MS_NOSUID|MS_NOEXEC|MS_NODEV);
180  
181         /* ... and get the mountpoint */
182 -       retval = path_lookup(dir_name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd);
183 -       if (retval)
184 +       retval = path_lookup_it(dir_name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd, &it);
185 +       if (retval) {
186 +               intent_release(&it);
187                 return retval;
188 -
189 +       }
190         if (flags & MS_REMOUNT)
191                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
192                                     data_page);
193 @@ -736,6 +744,8 @@
194         else
195                 retval = do_add_mount(&nd, type_page, flags, mnt_flags,
196                                       dev_name, data_page);
197 +
198 +       intent_release(&it);
199         path_release(&nd);
200         return retval;
201  }
202 @@ -901,6 +911,8 @@
203  {
204         struct vfsmount *tmp;
205         struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd;
206 +       struct lookup_intent new_it = { .it_op = IT_GETATTR };
207 +       struct lookup_intent old_it = { .it_op = IT_GETATTR };
208         int error;
209  
210         if (!capable(CAP_SYS_ADMIN))
211 @@ -908,14 +920,14 @@
212  
213         lock_kernel();
214  
215 -       error = __user_walk(new_root, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd);
216 +       error = __user_walk_it(new_root, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd, &new_it);
217         if (error)
218                 goto out0;
219         error = -EINVAL;
220         if (!check_mnt(new_nd.mnt))
221                 goto out1;
222  
223 -       error = __user_walk(put_old, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &old_nd);
224 +       error = __user_walk_it(put_old, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &old_nd, &old_it);
225         if (error)
226                 goto out1;
227  
228 @@ -970,8 +982,10 @@
229         up(&old_nd.dentry->d_inode->i_zombie);
230         up_write(&current->namespace->sem);
231         path_release(&user_nd);
232 +       intent_release(&old_it);
233         path_release(&old_nd);
234  out1:
235 +       intent_release(&new_it);
236         path_release(&new_nd);
237  out0:
238         unlock_kernel();
239 Index: linux/fs/namei.c
240 ===================================================================
241 --- linux.orig/fs/namei.c       Wed Mar 17 13:00:37 2004
242 +++ linux/fs/namei.c    Wed Mar 17 13:12:31 2004
243 @@ -94,6 +94,13 @@
244   * XEmacs seems to be relying on it...
245   */
246  
247 +void intent_release(struct lookup_intent *it)
248 +{
249 +       if (it && it->it_op_release)
250 +               it->it_op_release(it);
251 +
252 +}
253 +
254  /* In order to reduce some races, while at the same time doing additional
255   * checking and hopefully speeding things up, we copy filenames to the
256   * kernel data space before using them..
257 @@ -260,10 +267,19 @@
258   * Internal lookup() using the new generic dcache.
259   * SMP-safe
260   */
261 -static struct dentry * cached_lookup(struct dentry * parent, struct qstr * name, int flags)
262 +static struct dentry *cached_lookup(struct dentry *parent, struct qstr *name,
263 +                                   int flags, struct lookup_intent *it)
264  {
265         struct dentry * dentry = d_lookup(parent, name);
266  
267 +       if (dentry && dentry->d_op && dentry->d_op->d_revalidate_it) {
268 +               if (!dentry->d_op->d_revalidate_it(dentry, flags, it) &&
269 +                   !d_invalidate(dentry)) {
270 +                       dput(dentry);
271 +                       dentry = NULL;
272 +               }
273 +               return dentry;
274 +       } else
275         if (dentry && dentry->d_op && dentry->d_op->d_revalidate) {
276                 if (!dentry->d_op->d_revalidate(dentry, flags) && !d_invalidate(dentry)) {
277                         dput(dentry);
278 @@ -281,11 +297,15 @@
279   * make sure that nobody added the entry to the dcache in the meantime..
280   * SMP-safe
281   */
282 -static struct dentry * real_lookup(struct dentry * parent, struct qstr * name, int flags)
283 +static struct dentry *real_lookup(struct dentry *parent, struct qstr *name,
284 +                                 int flags, struct lookup_intent *it)
285  {
286         struct dentry * result;
287         struct inode *dir = parent->d_inode;
288 +       int counter = 0;
289  
290 +again:
291 +       counter++;
292         down(&dir->i_sem);
293         /*
294          * First re-do the cached lookup just in case it was created
295 @@ -300,6 +320,9 @@
296                 result = ERR_PTR(-ENOMEM);
297                 if (dentry) {
298                         lock_kernel();
299 +                       if (dir->i_op->lookup_it)
300 +                               result = dir->i_op->lookup_it(dir, dentry, it, flags);
301 +                       else
302                         result = dir->i_op->lookup(dir, dentry);
303                         unlock_kernel();
304                         if (result)
305 @@ -321,6 +344,15 @@
306                         dput(result);
307                         result = ERR_PTR(-ENOENT);
308                 }
309 +       } else if (result->d_op && result->d_op->d_revalidate_it) {
310 +               if (!result->d_op->d_revalidate_it(result, flags, it) &&
311 +                   !d_invalidate(result)) {
312 +                       dput(result);
313 +                       if (counter > 10)
314 +                               result = ERR_PTR(-ESTALE);
315 +                       if (!IS_ERR(result))
316 +                               goto again;
317 +               }
318         }
319         return result;
320  }
321 @@ -332,7 +364,8 @@
322   * Without that kind of total limit, nasty chains of consecutive
323   * symlinks can cause almost arbitrarily long lookups. 
324   */
325 -static inline int do_follow_link(struct dentry *dentry, struct nameidata *nd)
326 +static inline int do_follow_link(struct dentry *dentry, struct nameidata *nd,
327 +                                struct lookup_intent *it)
328  {
329         int err;
330         if (current->link_count >= 5)
331 @@ -346,10 +379,18 @@
332         current->link_count++;
333         current->total_link_count++;
334         UPDATE_ATIME(dentry->d_inode);
335 +       nd->intent = it;
336         err = dentry->d_inode->i_op->follow_link(dentry, nd);
337 +       if (!err && it != NULL && !(it->d.lustre.it_int_flags & IT_FL_FOLLOWED)) {
338 +               /* vfs_follow_link was never called */
339 +               intent_release(it);
340 +               path_release(nd);
341 +               err = -ENOLINK;
342 +       }
343         current->link_count--;
344         return err;
345  loop:
346 +       intent_release(it);
347         path_release(nd);
348         return -ELOOP;
349  }
350 @@ -379,15 +420,26 @@
351         return __follow_up(mnt, dentry);
352  }
353  
354 -static inline int __follow_down(struct vfsmount **mnt, struct dentry **dentry)
355 +static inline int __follow_down(struct vfsmount **mnt, struct dentry **dentry,
356 +                               struct lookup_intent *it)
357  {
358         struct vfsmount *mounted;
359  
360         spin_lock(&dcache_lock);
361         mounted = lookup_mnt(*mnt, *dentry);
362         if (mounted) {
363 +               int opc = 0, mode = 0;
364                 *mnt = mntget(mounted);
365                 spin_unlock(&dcache_lock);
366 +               if (it) {
367 +                       opc = it->it_op;
368 +                       mode = it->it_create_mode;
369 +               }
370 +               intent_release(it);
371 +               if (it) {
372 +                       it->it_op = opc;
373 +                       it->it_create_mode = mode;
374 +               }
375                 dput(*dentry);
376                 mntput(mounted->mnt_parent);
377                 *dentry = dget(mounted->mnt_root);
378 @@ -399,7 +451,7 @@
379  
380  int follow_down(struct vfsmount **mnt, struct dentry **dentry)
381  {
382 -       return __follow_down(mnt,dentry);
383 +       return __follow_down(mnt,dentry,NULL);
384  }
385   
386  static inline void follow_dotdot(struct nameidata *nd)
387 @@ -435,7 +487,7 @@
388                 mntput(nd->mnt);
389                 nd->mnt = parent;
390         }
391 -       while (d_mountpoint(nd->dentry) && __follow_down(&nd->mnt, &nd->dentry))
392 +       while (d_mountpoint(nd->dentry) && __follow_down(&nd->mnt, &nd->dentry, NULL))
393                 ;
394  }
395  
396 @@ -447,7 +499,8 @@
397   *
398   * We expect 'base' to be positive and a directory.
399   */
400 -int link_path_walk(const char * name, struct nameidata *nd)
401 +int link_path_walk_it(const char *name, struct nameidata *nd,
402 +                     struct lookup_intent *it)
403  {
404         struct dentry *dentry;
405         struct inode *inode;
406 @@ -520,15 +573,15 @@
407                                 break;
408                 }
409                 /* This does the actual lookups.. */
410 -               dentry = cached_lookup(nd->dentry, &this, LOOKUP_CONTINUE);
411 +               dentry = cached_lookup(nd->dentry, &this, LOOKUP_CONTINUE, NULL);
412                 if (!dentry) {
413 -                       dentry = real_lookup(nd->dentry, &this, LOOKUP_CONTINUE);
414 +                       dentry = real_lookup(nd->dentry, &this, LOOKUP_CONTINUE, NULL);
415                         err = PTR_ERR(dentry);
416                         if (IS_ERR(dentry))
417                                 break;
418                 }
419                 /* Check mountpoints.. */
420 -               while (d_mountpoint(dentry) && __follow_down(&nd->mnt, &dentry))
421 +               while (d_mountpoint(dentry) && __follow_down(&nd->mnt, &dentry, NULL))
422                         ;
423  
424                 err = -ENOENT;
425 @@ -540,7 +593,7 @@
426                         goto out_dput;
427  
428                 if (inode->i_op->follow_link) {
429 -                       err = do_follow_link(dentry, nd);
430 +                       err = do_follow_link(dentry, nd, NULL);
431                         dput(dentry);
432                         if (err)
433                                 goto return_err;
434 @@ -556,7 +609,7 @@
435                         nd->dentry = dentry;
436                 }
437                 err = -ENOTDIR; 
438 -               if (!inode->i_op->lookup)
439 +               if (!inode->i_op->lookup && !inode->i_op->lookup_it)
440                         break;
441                 continue;
442                 /* here ends the main loop */
443 @@ -583,19 +636,19 @@
444                         if (err < 0)
445                                 break;
446                 }
447 -               dentry = cached_lookup(nd->dentry, &this, 0);
448 +               dentry = cached_lookup(nd->dentry, &this, 0, it);
449                 if (!dentry) {
450 -                       dentry = real_lookup(nd->dentry, &this, 0);
451 +                       dentry = real_lookup(nd->dentry, &this, 0, it);
452                         err = PTR_ERR(dentry);
453                         if (IS_ERR(dentry))
454                                 break;
455                 }
456 -               while (d_mountpoint(dentry) && __follow_down(&nd->mnt, &dentry))
457 +               while (d_mountpoint(dentry) && __follow_down(&nd->mnt, &dentry, it))
458                         ;
459                 inode = dentry->d_inode;
460                 if ((lookup_flags & LOOKUP_FOLLOW)
461                     && inode && inode->i_op && inode->i_op->follow_link) {
462 -                       err = do_follow_link(dentry, nd);
463 +                       err = do_follow_link(dentry, nd, it);
464                         dput(dentry);
465                         if (err)
466                                 goto return_err;
467 @@ -609,7 +662,8 @@
468                         goto no_inode;
469                 if (lookup_flags & LOOKUP_DIRECTORY) {
470                         err = -ENOTDIR; 
471 -                       if (!inode->i_op || !inode->i_op->lookup)
472 +                       if (!inode->i_op ||
473 +                           (!inode->i_op->lookup && !inode->i_op->lookup_it))
474                                 break;
475                 }
476                 goto return_base;
477 @@ -633,6 +687,27 @@
478                  * Check the cached dentry for staleness.
479                  */
480                 dentry = nd->dentry;
481 +               if (dentry && dentry->d_op && dentry->d_op->d_revalidate_it) {
482 +                       err = -ESTALE;
483 +                       if (!dentry->d_op->d_revalidate_it(dentry, 0, it)) {
484 +                               struct dentry *new;
485 +                               err = permission(dentry->d_parent->d_inode,
486 +                                                MAY_EXEC);
487 +                               if (err)
488 +                                       break;
489 +                               new = real_lookup(dentry->d_parent,
490 +                                                 &dentry->d_name, 0, NULL);
491 +                               d_invalidate(dentry);
492 +                               dput(dentry);
493 +                               if (IS_ERR(new)) {
494 +                                       err = PTR_ERR(new);
495 +                                       break;
496 +                               }
497 +                               nd->dentry = new;
498 +                       }
499 +                       if (!nd->dentry->d_inode)
500 +                               goto no_inode;
501 +               } else
502                 if (dentry && dentry->d_op && dentry->d_op->d_revalidate) {
503                         err = -ESTALE;
504                         if (!dentry->d_op->d_revalidate(dentry, 0)) {
505 @@ -646,15 +721,28 @@
506                 dput(dentry);
507                 break;
508         }
509 +       if (err)
510 +               intent_release(it);
511         path_release(nd);
512  return_err:
513         return err;
514  }
515  
516 +int link_path_walk(const char * name, struct nameidata *nd)
517 +{
518 +       return link_path_walk_it(name, nd, NULL);
519 +}
520 +
521 +int path_walk_it(const char * name, struct nameidata *nd, struct lookup_intent *it)
522 +{
523 +       current->total_link_count = 0;
524 +       return link_path_walk_it(name, nd, it);
525 +}
526 +
527  int path_walk(const char * name, struct nameidata *nd)
528  {
529         current->total_link_count = 0;
530 -       return link_path_walk(name, nd);
531 +       return link_path_walk_it(name, nd, NULL);
532  }
533  
534  /* SMP-safe */
535 @@ -739,6 +827,17 @@
536  }
537  
538  /* SMP-safe */
539 +int path_lookup_it(const char *path, unsigned flags, struct nameidata *nd,
540 +                  struct lookup_intent *it)
541 +{
542 +       int error = 0;
543 +       if (path_init(path, flags, nd))
544 +               error = path_walk_it(path, nd, it);
545 +       return error;
546 +}
547 +
548 +
549 +/* SMP-safe */
550  int path_lookup(const char *path, unsigned flags, struct nameidata *nd)
551  {
552         int error = 0;
553 @@ -753,6 +852,7 @@
554  {
555         nd->last_type = LAST_ROOT; /* if there are only slashes... */
556         nd->flags = flags;
557 +       nd->intent = NULL;
558         if (*name=='/')
559                 return walk_init_root(name,nd);
560         read_lock(&current->fs->lock);
561 @@ -767,7 +867,8 @@
562   * needs parent already locked. Doesn't follow mounts.
563   * SMP-safe.
564   */
565 -struct dentry * lookup_hash(struct qstr *name, struct dentry * base)
566 +struct dentry * lookup_hash_it(struct qstr *name, struct dentry * base,
567 +                              struct lookup_intent *it)
568  {
569         struct dentry * dentry;
570         struct inode *inode;
571 @@ -790,13 +891,16 @@
572                         goto out;
573         }
574  
575 -       dentry = cached_lookup(base, name, 0);
576 +       dentry = cached_lookup(base, name, 0, it);
577         if (!dentry) {
578                 struct dentry *new = d_alloc(base, name);
579                 dentry = ERR_PTR(-ENOMEM);
580                 if (!new)
581                         goto out;
582                 lock_kernel();
583 +               if (inode->i_op->lookup_it)
584 +                       dentry = inode->i_op->lookup_it(inode, new, it, 0);
585 +               else
586                 dentry = inode->i_op->lookup(inode, new);
587                 unlock_kernel();
588                 if (!dentry)
589 @@ -808,6 +912,12 @@
590         return dentry;
591  }
592  
593 +struct dentry * lookup_hash(struct qstr *name, struct dentry * base)
594 +{
595 +       return lookup_hash_it(name, base, NULL);
596 +}
597 +
598 +
599  /* SMP-safe */
600  struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
601  {
602 @@ -829,7 +939,7 @@
603         }
604         this.hash = end_name_hash(hash);
605  
606 -       return lookup_hash(&this, base);
607 +       return lookup_hash_it(&this, base, NULL);
608  access:
609         return ERR_PTR(-EACCES);
610  }
611 @@ -860,6 +970,23 @@
612         return err;
613  }
614  
615 +int __user_walk_it(const char *name, unsigned flags, struct nameidata *nd,
616 +                  struct lookup_intent *it)
617 +{
618 +       char *tmp;
619 +       int err;
620 +
621 +       tmp = getname(name);
622 +       err = PTR_ERR(tmp);
623 +       if (!IS_ERR(tmp)) {
624 +               err = 0;
625 +               if (path_init(tmp, flags, nd))
626 +                       err = path_walk_it(tmp, nd, it);
627 +               putname(tmp);
628 +       }
629 +       return err;
630 +}
631 +
632  /*
633   * It's inline, so penalty for filesystems that don't use sticky bit is
634   * minimal.
635 @@ -955,7 +1082,8 @@
636         return retval;
637  }
638  
639 -int vfs_create(struct inode *dir, struct dentry *dentry, int mode)
640 +static int vfs_create_it(struct inode *dir, struct dentry *dentry, int mode,
641 +                        struct lookup_intent *it)
642  {
643         int error;
644  
645 @@ -968,12 +1096,15 @@
646                 goto exit_lock;
647  
648         error = -EACCES;        /* shouldn't it be ENOSYS? */
649 -       if (!dir->i_op || !dir->i_op->create)
650 +       if (!dir->i_op || (!dir->i_op->create && !dir->i_op->create_it))
651                 goto exit_lock;
652  
653         DQUOT_INIT(dir);
654         lock_kernel();
655 -       error = dir->i_op->create(dir, dentry, mode);
656 +       if (dir->i_op->create_it)
657 +               error = dir->i_op->create_it(dir, dentry, mode, it);
658 +       else
659 +               error = dir->i_op->create(dir, dentry, mode);
660         unlock_kernel();
661  exit_lock:
662         up(&dir->i_zombie);
663 @@ -982,6 +1113,11 @@
664         return error;
665  }
666  
667 +int vfs_create(struct inode *dir, struct dentry *dentry, int mode)
668 +{
669 +       return vfs_create_it(dir, dentry, mode, NULL);
670 +}
671 +
672  /*
673   *     open_namei()
674   *
675 @@ -996,7 +1132,8 @@
676   * for symlinks (where the permissions are checked later).
677   * SMP-safe
678   */
679 -int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd)
680 +int open_namei_it(const char *pathname, int flag, int mode,
681 +                 struct nameidata *nd, struct lookup_intent *it)
682  {
683         int acc_mode, error = 0;
684         struct inode *inode;
685 @@ -1006,11 +1143,14 @@
686  
687         acc_mode = ACC_MODE(flag);
688  
689 +       if (it)
690 +               it->it_flags = flag;
691 +
692         /*
693          * The simplest case - just a plain lookup.
694          */
695         if (!(flag & O_CREAT)) {
696 -               error = path_lookup(pathname, lookup_flags(flag), nd);
697 +               error = path_lookup_it(pathname, lookup_flags(flag), nd, it);
698                 if (error)
699                         return error;
700                 dentry = nd->dentry;
701 @@ -1020,6 +1160,10 @@
702         /*
703          * Create - we need to know the parent.
704          */
705 +       if (it) {
706 +               it->it_create_mode = mode;
707 +               it->it_op |= IT_CREAT;
708 +       }
709         error = path_lookup(pathname, LOOKUP_PARENT, nd);
710         if (error)
711                 return error;
712 @@ -1035,7 +1179,7 @@
713  
714         dir = nd->dentry;
715         down(&dir->d_inode->i_sem);
716 -       dentry = lookup_hash(&nd->last, nd->dentry);
717 +       dentry = lookup_hash_it(&nd->last, nd->dentry, it);
718  
719  do_last:
720         error = PTR_ERR(dentry);
721 @@ -1044,11 +1188,12 @@
722                 goto exit;
723         }
724  
725 +       it->it_create_mode = mode;
726         /* Negative dentry, just create the file */
727         if (!dentry->d_inode) {
728                 if (!IS_POSIXACL(dir->d_inode))
729                         mode &= ~current->fs->umask;
730 -               error = vfs_create(dir->d_inode, dentry, mode);
731 +               error = vfs_create_it(dir->d_inode, dentry, mode, it);
732                 up(&dir->d_inode->i_sem);
733                 dput(nd->dentry);
734                 nd->dentry = dentry;
735 @@ -1073,7 +1218,7 @@
736                 error = -ELOOP;
737                 if (flag & O_NOFOLLOW)
738                         goto exit_dput;
739 -               while (__follow_down(&nd->mnt,&dentry) && d_mountpoint(dentry));
740 +               while (__follow_down(&nd->mnt,&dentry,it) && d_mountpoint(dentry));
741         }
742         error = -ENOENT;
743         if (!dentry->d_inode)
744 @@ -1152,7 +1297,7 @@
745                 if (!error) {
746                         DQUOT_INIT(inode);
747                         
748 -                       error = do_truncate(dentry, 0);
749 +                       error = do_truncate(dentry, 0, 1);
750                 }
751                 put_write_access(inode);
752                 if (error)
753 @@ -1164,8 +1309,10 @@
754         return 0;
755  
756  exit_dput:
757 +       intent_release(it);
758         dput(dentry);
759  exit:
760 +       intent_release(it);
761         path_release(nd);
762         return error;
763  
764 @@ -1184,7 +1331,16 @@
765          * are done. Procfs-like symlinks just set LAST_BIND.
766          */
767         UPDATE_ATIME(dentry->d_inode);
768 +       nd->intent = it;
769         error = dentry->d_inode->i_op->follow_link(dentry, nd);
770 +       if (error) {
771 +               intent_release(it);
772 +       } else if (it != NULL && !(it->d.lustre.it_int_flags & IT_FL_FOLLOWED)) {
773 +               /* vfs_follow_link was never called */
774 +               intent_release(it);
775 +               path_release(nd);
776 +               error = -ENOLINK;
777 +       }
778         dput(dentry);
779         if (error)
780                 return error;
781 @@ -1206,13 +1362,20 @@
782         }
783         dir = nd->dentry;
784         down(&dir->d_inode->i_sem);
785 -       dentry = lookup_hash(&nd->last, nd->dentry);
786 +       dentry = lookup_hash_it(&nd->last, nd->dentry, it);
787         putname(nd->last.name);
788         goto do_last;
789  }
790  
791 +int open_namei(const char *pathname, int flag, int mode, struct nameidata *nd)
792 +{
793 +       return open_namei_it(pathname, flag, mode, nd, NULL);
794 +}
795 +
796 +
797  /* SMP-safe */
798 -static struct dentry *lookup_create(struct nameidata *nd, int is_dir)
799 +static struct dentry *lookup_create(struct nameidata *nd, int is_dir,
800 +                                   struct lookup_intent *it)
801  {
802         struct dentry *dentry;
803  
804 @@ -1220,7 +1383,7 @@
805         dentry = ERR_PTR(-EEXIST);
806         if (nd->last_type != LAST_NORM)
807                 goto fail;
808 -       dentry = lookup_hash(&nd->last, nd->dentry);
809 +       dentry = lookup_hash_it(&nd->last, nd->dentry, it);
810         if (IS_ERR(dentry))
811                 goto fail;
812         if (!is_dir && nd->last.name[nd->last.len] && !dentry->d_inode)
813 @@ -1276,7 +1439,20 @@
814         error = path_lookup(tmp, LOOKUP_PARENT, &nd);
815         if (error)
816                 goto out;
817 -       dentry = lookup_create(&nd, 0);
818 +
819 +       if (nd.last_type != LAST_NORM) {
820 +               error = -EEXIST;
821 +               goto out2;
822 +       }
823 +       if (nd.dentry->d_inode->i_op->mknod_raw) {
824 +               struct inode_operations *op = nd.dentry->d_inode->i_op;
825 +               error = op->mknod_raw(&nd, mode, dev);
826 +               /* the file system wants to use normal vfs path now */
827 +               if (error != -EOPNOTSUPP)
828 +                       goto out2;
829 +       }
830 +
831 +       dentry = lookup_create(&nd, 0, NULL);
832         error = PTR_ERR(dentry);
833  
834         if (!IS_POSIXACL(nd.dentry->d_inode))
835 @@ -1298,6 +1474,7 @@
836                 dput(dentry);
837         }
838         up(&nd.dentry->d_inode->i_sem);
839 +out2:
840         path_release(&nd);
841  out:
842         putname(tmp);
843 @@ -1345,7 +1522,18 @@
844                 error = path_lookup(tmp, LOOKUP_PARENT, &nd);
845                 if (error)
846                         goto out;
847 -               dentry = lookup_create(&nd, 1);
848 +               if (nd.last_type != LAST_NORM) {
849 +                       error = -EEXIST;
850 +                       goto out2;
851 +               }
852 +               if (nd.dentry->d_inode->i_op->mkdir_raw) {
853 +                       struct inode_operations *op = nd.dentry->d_inode->i_op;
854 +                       error = op->mkdir_raw(&nd, mode);
855 +                       /* the file system wants to use normal vfs path now */
856 +                       if (error != -EOPNOTSUPP)
857 +                               goto out2;
858 +               }
859 +               dentry = lookup_create(&nd, 1, NULL);
860                 error = PTR_ERR(dentry);
861                 if (!IS_ERR(dentry)) {
862                         if (!IS_POSIXACL(nd.dentry->d_inode))
863 @@ -1354,6 +1542,7 @@
864                         dput(dentry);
865                 }
866                 up(&nd.dentry->d_inode->i_sem);
867 +out2:
868                 path_release(&nd);
869  out:
870                 putname(tmp);
871 @@ -1454,8 +1643,16 @@
872                         error = -EBUSY;
873                         goto exit1;
874         }
875 +       if (nd.dentry->d_inode->i_op->rmdir_raw) {
876 +               struct inode_operations *op = nd.dentry->d_inode->i_op;
877 +
878 +               error = op->rmdir_raw(&nd);
879 +               /* the file system wants to use normal vfs path now */
880 +               if (error != -EOPNOTSUPP)
881 +                       goto exit1;
882 +       }
883         down(&nd.dentry->d_inode->i_sem);
884 -       dentry = lookup_hash(&nd.last, nd.dentry);
885 +       dentry = lookup_hash_it(&nd.last, nd.dentry, NULL);
886         error = PTR_ERR(dentry);
887         if (!IS_ERR(dentry)) {
888                 error = vfs_rmdir(nd.dentry->d_inode, dentry);
889 @@ -1513,8 +1710,15 @@
890         error = -EISDIR;
891         if (nd.last_type != LAST_NORM)
892                 goto exit1;
893 +       if (nd.dentry->d_inode->i_op->unlink_raw) {
894 +               struct inode_operations *op = nd.dentry->d_inode->i_op;
895 +               error = op->unlink_raw(&nd);
896 +               /* the file system wants to use normal vfs path now */
897 +               if (error != -EOPNOTSUPP)
898 +                       goto exit1;
899 +       }
900         down(&nd.dentry->d_inode->i_sem);
901 -       dentry = lookup_hash(&nd.last, nd.dentry);
902 +       dentry = lookup_hash_it(&nd.last, nd.dentry, NULL);
903         error = PTR_ERR(dentry);
904         if (!IS_ERR(dentry)) {
905                 /* Why not before? Because we want correct error value */
906 @@ -1581,15 +1785,27 @@
907                 error = path_lookup(to, LOOKUP_PARENT, &nd);
908                 if (error)
909                         goto out;
910 -               dentry = lookup_create(&nd, 0);
911 +               if (nd.last_type != LAST_NORM) {
912 +                       error = -EEXIST;
913 +                       goto out2;
914 +               }
915 +               if (nd.dentry->d_inode->i_op->symlink_raw) {
916 +                       struct inode_operations *op = nd.dentry->d_inode->i_op;
917 +                       error = op->symlink_raw(&nd, from);
918 +                       /* the file system wants to use normal vfs path now */
919 +                       if (error != -EOPNOTSUPP)
920 +                               goto out2;
921 +               }
922 +               dentry = lookup_create(&nd, 0, NULL);
923                 error = PTR_ERR(dentry);
924                 if (!IS_ERR(dentry)) {
925                         error = vfs_symlink(nd.dentry->d_inode, dentry, from);
926                         dput(dentry);
927                 }
928                 up(&nd.dentry->d_inode->i_sem);
929 +       out2:
930                 path_release(&nd);
931 -out:
932 +       out:
933                 putname(to);
934         }
935         putname(from);
936 @@ -1665,7 +1881,18 @@
937                 error = -EXDEV;
938                 if (old_nd.mnt != nd.mnt)
939                         goto out_release;
940 -               new_dentry = lookup_create(&nd, 0);
941 +               if (nd.last_type != LAST_NORM) {
942 +                       error = -EEXIST;
943 +                       goto out_release;
944 +               }
945 +               if (nd.dentry->d_inode->i_op->link_raw) {
946 +                       struct inode_operations *op = nd.dentry->d_inode->i_op;
947 +                       error = op->link_raw(&old_nd, &nd);
948 +                       /* the file system wants to use normal vfs path now */
949 +                       if (error != -EOPNOTSUPP)
950 +                               goto out_release;
951 +               }
952 +               new_dentry = lookup_create(&nd, 0, NULL);
953                 error = PTR_ERR(new_dentry);
954                 if (!IS_ERR(new_dentry)) {
955                         error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
956 @@ -1709,7 +1936,7 @@
957   *        locking].
958   */
959  int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
960 -              struct inode *new_dir, struct dentry *new_dentry)
961 +                  struct inode *new_dir, struct dentry *new_dentry)
962  {
963         int error;
964         struct inode *target;
965 @@ -1788,7 +2015,7 @@
966  }
967  
968  int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
969 -              struct inode *new_dir, struct dentry *new_dentry)
970 +                    struct inode *new_dir, struct dentry *new_dentry)
971  {
972         int error;
973  
974 @@ -1876,9 +2103,18 @@
975         if (newnd.last_type != LAST_NORM)
976                 goto exit2;
977  
978 +       if (old_dir->d_inode->i_op->rename_raw) {
979 +               lock_kernel();
980 +               error = old_dir->d_inode->i_op->rename_raw(&oldnd, &newnd);
981 +               unlock_kernel();
982 +               /* the file system wants to use normal vfs path now */
983 +               if (error != -EOPNOTSUPP)
984 +                       goto exit2;
985 +       }
986 +
987         double_lock(new_dir, old_dir);
988  
989 -       old_dentry = lookup_hash(&oldnd.last, old_dir);
990 +       old_dentry = lookup_hash_it(&oldnd.last, old_dir, NULL);
991         error = PTR_ERR(old_dentry);
992         if (IS_ERR(old_dentry))
993                 goto exit3;
994 @@ -1894,16 +2130,16 @@
995                 if (newnd.last.name[newnd.last.len])
996                         goto exit4;
997         }
998 -       new_dentry = lookup_hash(&newnd.last, new_dir);
999 +       new_dentry = lookup_hash_it(&newnd.last, new_dir, NULL);
1000         error = PTR_ERR(new_dentry);
1001         if (IS_ERR(new_dentry))
1002                 goto exit4;
1003  
1004 +
1005         lock_kernel();
1006         error = vfs_rename(old_dir->d_inode, old_dentry,
1007                                    new_dir->d_inode, new_dentry);
1008         unlock_kernel();
1009 -
1010         dput(new_dentry);
1011  exit4:
1012         dput(old_dentry);
1013 @@ -1954,20 +2190,28 @@
1014  }
1015  
1016  static inline int
1017 -__vfs_follow_link(struct nameidata *nd, const char *link)
1018 +__vfs_follow_link(struct nameidata *nd, const char *link,
1019 +                 struct lookup_intent *it)
1020  {
1021         int res = 0;
1022         char *name;
1023         if (IS_ERR(link))
1024                 goto fail;
1025  
1026 +       if (it == NULL)
1027 +               it = nd->intent;
1028 +       else if (it != nd->intent)
1029 +               printk("it != nd->intent: tell phil@clusterfs.com\n");
1030 +       if (it != NULL)
1031 +               it->d.lustre.it_int_flags |= IT_FL_FOLLOWED;
1032 +
1033         if (*link == '/') {
1034                 path_release(nd);
1035                 if (!walk_init_root(link, nd))
1036                         /* weird __emul_prefix() stuff did it */
1037                         goto out;
1038         }
1039 -       res = link_path_walk(link, nd);
1040 +       res = link_path_walk_it(link, nd, it);
1041  out:
1042         if (current->link_count || res || nd->last_type!=LAST_NORM)
1043                 return res;
1044 @@ -1989,7 +2233,13 @@
1045  
1046  int vfs_follow_link(struct nameidata *nd, const char *link)
1047  {
1048 -       return __vfs_follow_link(nd, link);
1049 +       return __vfs_follow_link(nd, link, NULL);
1050 +}
1051 +
1052 +int vfs_follow_link_it(struct nameidata *nd, const char *link,
1053 +                      struct lookup_intent *it)
1054 +{
1055 +       return __vfs_follow_link(nd, link, it);
1056  }
1057  
1058  /* get the link contents into pagecache */
1059 @@ -2031,7 +2281,7 @@
1060  {
1061         struct page *page = NULL;
1062         char *s = page_getlink(dentry, &page);
1063 -       int res = __vfs_follow_link(nd, s);
1064 +       int res = __vfs_follow_link(nd, s, NULL);
1065         if (page) {
1066                 kunmap(page);
1067                 page_cache_release(page);
1068 Index: linux/fs/open.c
1069 ===================================================================
1070 --- linux.orig/fs/open.c        Thu Nov 28 18:53:15 2002
1071 +++ linux/fs/open.c     Wed Mar 17 13:11:25 2004
1072 @@ -19,6 +19,8 @@
1073  #include <asm/uaccess.h>
1074  
1075  #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))
1076 +extern int path_walk_it(const char *name, struct nameidata *nd,
1077 +                       struct lookup_intent *it);
1078  
1079  int vfs_statfs(struct super_block *sb, struct statfs *buf)
1080  {
1081 @@ -95,9 +97,10 @@
1082         write_unlock(&files->file_lock);
1083  }
1084  
1085 -int do_truncate(struct dentry *dentry, loff_t length)
1086 +int do_truncate(struct dentry *dentry, loff_t length, int called_from_open)
1087  {
1088         struct inode *inode = dentry->d_inode;
1089 +       struct inode_operations *op = dentry->d_inode->i_op;
1090         int error;
1091         struct iattr newattrs;
1092  
1093 @@ -108,7 +111,13 @@
1094         down(&inode->i_sem);
1095         newattrs.ia_size = length;
1096         newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
1097 -       error = notify_change(dentry, &newattrs);
1098 +       if (called_from_open)
1099 +               newattrs.ia_valid |= ATTR_FROM_OPEN;
1100 +       if (op->setattr_raw) {
1101 +               newattrs.ia_valid |= ATTR_RAW;
1102 +               error = op->setattr_raw(inode, &newattrs);
1103 +       } else
1104 +               error = notify_change(dentry, &newattrs);
1105         up(&inode->i_sem);
1106         return error;
1107  }
1108 @@ -118,12 +127,13 @@
1109         struct nameidata nd;
1110         struct inode * inode;
1111         int error;
1112 +       struct lookup_intent it = { .it_op = IT_GETATTR };
1113  
1114         error = -EINVAL;
1115         if (length < 0) /* sorry, but loff_t says... */
1116                 goto out;
1117  
1118 -       error = user_path_walk(path, &nd);
1119 +       error = user_path_walk_it(path, &nd, &it);
1120         if (error)
1121                 goto out;
1122         inode = nd.dentry->d_inode;
1123 @@ -163,11 +173,13 @@
1124         error = locks_verify_truncate(inode, NULL, length);
1125         if (!error) {
1126                 DQUOT_INIT(inode);
1127 -               error = do_truncate(nd.dentry, length);
1128 +               intent_release(&it);
1129 +               error = do_truncate(nd.dentry, length, 0);
1130         }
1131         put_write_access(inode);
1132  
1133  dput_and_out:
1134 +       intent_release(&it);
1135         path_release(&nd);
1136  out:
1137         return error;
1138 @@ -215,7 +227,7 @@
1139  
1140         error = locks_verify_truncate(inode, file, length);
1141         if (!error)
1142 -               error = do_truncate(dentry, length);
1143 +               error = do_truncate(dentry, length, 0);
1144  out_putf:
1145         fput(file);
1146  out:
1147 @@ -260,11 +272,13 @@
1148         struct inode * inode;
1149         struct iattr newattrs;
1150  
1151 -       error = user_path_walk(filename, &nd);
1152 +       error = user_path_walk_it(filename, &nd, NULL);
1153         if (error)
1154                 goto out;
1155         inode = nd.dentry->d_inode;
1156  
1157 +       /* this is safe without a Lustre lock because it only depends
1158 +          on the super block */
1159         error = -EROFS;
1160         if (IS_RDONLY(inode))
1161                 goto dput_and_out;
1162 @@ -279,11 +293,25 @@
1163                         goto dput_and_out;
1164  
1165                 newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET;
1166 -       } else {
1167 +       }
1168 +
1169 +       if (inode->i_op->setattr_raw) {
1170 +               struct inode_operations *op = nd.dentry->d_inode->i_op;
1171 +
1172 +               newattrs.ia_valid |= ATTR_RAW;
1173 +               error = op->setattr_raw(inode, &newattrs);
1174 +               /* the file system wants to use normal vfs path now */
1175 +               if (error != -EOPNOTSUPP)
1176 +                       goto dput_and_out;
1177 +       }
1178 +
1179 +       error = -EPERM;
1180 +       if (!times) {
1181                 if (current->fsuid != inode->i_uid &&
1182                     (error = permission(inode,MAY_WRITE)) != 0)
1183                         goto dput_and_out;
1184         }
1185 +
1186         error = notify_change(nd.dentry, &newattrs);
1187  dput_and_out:
1188         path_release(&nd);
1189 @@ -304,12 +332,14 @@
1190         struct inode * inode;
1191         struct iattr newattrs;
1192  
1193 -       error = user_path_walk(filename, &nd);
1194 +       error = user_path_walk_it(filename, &nd, NULL);
1195  
1196         if (error)
1197                 goto out;
1198         inode = nd.dentry->d_inode;
1199  
1200 +       /* this is safe without a Lustre lock because it only depends
1201 +          on the super block */
1202         error = -EROFS;
1203         if (IS_RDONLY(inode))
1204                 goto dput_and_out;
1205 @@ -324,7 +354,20 @@
1206                 newattrs.ia_atime = times[0].tv_sec;
1207                 newattrs.ia_mtime = times[1].tv_sec;
1208                 newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET;
1209 -       } else {
1210 +       }
1211 +
1212 +       if (inode->i_op->setattr_raw) {
1213 +               struct inode_operations *op = nd.dentry->d_inode->i_op;
1214 +
1215 +               newattrs.ia_valid |= ATTR_RAW;
1216 +               error = op->setattr_raw(inode, &newattrs);
1217 +               /* the file system wants to use normal vfs path now */
1218 +               if (error != -EOPNOTSUPP)
1219 +                       goto dput_and_out;
1220 +       }
1221 +
1222 +       error = -EPERM;
1223 +       if (!utimes) {
1224                 if (current->fsuid != inode->i_uid &&
1225                     (error = permission(inode,MAY_WRITE)) != 0)
1226                         goto dput_and_out;
1227 @@ -347,6 +390,7 @@
1228         int old_fsuid, old_fsgid;
1229         kernel_cap_t old_cap;
1230         int res;
1231 +       struct lookup_intent it = { .it_op = IT_GETATTR };
1232  
1233         if (mode & ~S_IRWXO)    /* where's F_OK, X_OK, W_OK, R_OK? */
1234                 return -EINVAL;
1235 @@ -364,13 +408,14 @@
1236         else
1237                 current->cap_effective = current->cap_permitted;
1238  
1239 -       res = user_path_walk(filename, &nd);
1240 +       res = user_path_walk_it(filename, &nd, &it);
1241         if (!res) {
1242                 res = permission(nd.dentry->d_inode, mode);
1243                 /* SuS v2 requires we report a read only fs too */
1244                 if(!res && (mode & S_IWOTH) && IS_RDONLY(nd.dentry->d_inode)
1245                    && !special_file(nd.dentry->d_inode->i_mode))
1246                         res = -EROFS;
1247 +               intent_release(&it);
1248                 path_release(&nd);
1249         }
1250  
1251 @@ -385,8 +430,9 @@
1252  {
1253         int error;
1254         struct nameidata nd;
1255 +       struct lookup_intent it = { .it_op = IT_GETATTR };
1256  
1257 -       error = __user_walk(filename,LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY,&nd);
1258 +       error = __user_walk_it(filename,LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY,&nd, &it);
1259         if (error)
1260                 goto out;
1261  
1262 @@ -397,6 +443,7 @@
1263         set_fs_pwd(current->fs, nd.mnt, nd.dentry);
1264  
1265  dput_and_out:
1266 +       intent_release(&it);
1267         path_release(&nd);
1268  out:
1269         return error;
1270 @@ -436,9 +483,10 @@
1271  {
1272         int error;
1273         struct nameidata nd;
1274 +       struct lookup_intent it = { .it_op = IT_GETATTR };
1275  
1276 -       error = __user_walk(filename, LOOKUP_POSITIVE | LOOKUP_FOLLOW |
1277 -                     LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd);
1278 +       error = __user_walk_it(filename, LOOKUP_POSITIVE | LOOKUP_FOLLOW |
1279 +                     LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd, &it);
1280         if (error)
1281                 goto out;
1282  
1283 @@ -454,39 +502,56 @@
1284         set_fs_altroot();
1285         error = 0;
1286  dput_and_out:
1287 +       intent_release(&it);
1288         path_release(&nd);
1289  out:
1290         return error;
1291  }
1292  
1293 -asmlinkage long sys_fchmod(unsigned int fd, mode_t mode)
1294 +int chmod_common(struct dentry *dentry, mode_t mode)
1295  {
1296 -       struct inode * inode;
1297 -       struct dentry * dentry;
1298 -       struct file * file;
1299 -       int err = -EBADF;
1300 +       struct inode *inode = dentry->d_inode;
1301         struct iattr newattrs;
1302 +       int err = -EROFS;
1303  
1304 -       file = fget(fd);
1305 -       if (!file)
1306 +       if (IS_RDONLY(inode))
1307                 goto out;
1308  
1309 -       dentry = file->f_dentry;
1310 -       inode = dentry->d_inode;
1311 +       if (inode->i_op->setattr_raw) {
1312 +               newattrs.ia_mode = mode;
1313 +               newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
1314 +               newattrs.ia_valid |= ATTR_RAW;
1315 +               err = inode->i_op->setattr_raw(inode, &newattrs);
1316 +               /* the file system wants to use normal vfs path now */
1317 +               if (err != -EOPNOTSUPP)
1318 +                       goto out;
1319 +       }
1320  
1321 -       err = -EROFS;
1322 -       if (IS_RDONLY(inode))
1323 -               goto out_putf;
1324         err = -EPERM;
1325         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1326 -               goto out_putf;
1327 +               goto out;
1328 +
1329         if (mode == (mode_t) -1)
1330                 mode = inode->i_mode;
1331         newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
1332         newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
1333         err = notify_change(dentry, &newattrs);
1334  
1335 -out_putf:
1336 +out:
1337 +       return err;
1338 +}
1339 +
1340 +asmlinkage long sys_fchmod(unsigned int fd, mode_t mode)
1341 +{
1342 +       struct file * file;
1343 +       int err = -EBADF;
1344 +
1345 +       file = fget(fd);
1346 +       if (!file)
1347 +               goto out;
1348 +
1349 +       err = chmod_common(file->f_dentry, mode);
1350 +
1351         fput(file);
1352  out:
1353         return err;
1354 @@ -495,30 +560,14 @@
1355  asmlinkage long sys_chmod(const char * filename, mode_t mode)
1356  {
1357         struct nameidata nd;
1358 -       struct inode * inode;
1359         int error;
1360 -       struct iattr newattrs;
1361  
1362         error = user_path_walk(filename, &nd);
1363         if (error)
1364                 goto out;
1365 -       inode = nd.dentry->d_inode;
1366 -
1367 -       error = -EROFS;
1368 -       if (IS_RDONLY(inode))
1369 -               goto dput_and_out;
1370  
1371 -       error = -EPERM;
1372 -       if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1373 -               goto dput_and_out;
1374 +       error = chmod_common(nd.dentry, mode);
1375  
1376 -       if (mode == (mode_t) -1)
1377 -               mode = inode->i_mode;
1378 -       newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
1379 -       newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
1380 -       error = notify_change(nd.dentry, &newattrs);
1381 -
1382 -dput_and_out:
1383         path_release(&nd);
1384  out:
1385         return error;
1386 @@ -538,6 +587,20 @@
1387         error = -EROFS;
1388         if (IS_RDONLY(inode))
1389                 goto out;
1390 +
1391 +       if (inode->i_op->setattr_raw) {
1392 +               struct inode_operations *op = dentry->d_inode->i_op;
1393 +
1394 +               newattrs.ia_uid = user;
1395 +               newattrs.ia_gid = group;
1396 +               newattrs.ia_valid = ATTR_UID | ATTR_GID | ATTR_CTIME;
1397 +               newattrs.ia_valid |= ATTR_RAW;
1398 +               error = op->setattr_raw(inode, &newattrs);
1399 +               /* the file system wants to use normal vfs path now */
1400 +               if (error != -EOPNOTSUPP)
1401 +                       return error;
1402 +       }
1403 +
1404         error = -EPERM;
1405         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1406                 goto out;
1407 @@ -642,6 +705,7 @@
1408  {
1409         int namei_flags, error;
1410         struct nameidata nd;
1411 +       struct lookup_intent it = { .it_op = IT_OPEN };
1412  
1413         namei_flags = flags;
1414         if ((namei_flags+1) & O_ACCMODE)
1415 @@ -649,14 +713,15 @@
1416         if (namei_flags & O_TRUNC)
1417                 namei_flags |= 2;
1418  
1419 -       error = open_namei(filename, namei_flags, mode, &nd);
1420 -       if (!error)
1421 -               return dentry_open(nd.dentry, nd.mnt, flags);
1422 +       error = open_namei_it(filename, namei_flags, mode, &nd, &it);
1423 +       if (error)
1424 +               return ERR_PTR(error);
1425  
1426 -       return ERR_PTR(error);
1427 +       return dentry_open_it(nd.dentry, nd.mnt, flags, &it);
1428  }
1429  
1430 -struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
1431 +struct file *dentry_open_it(struct dentry *dentry, struct vfsmount *mnt,
1432 +                           int flags, struct lookup_intent *it)
1433  {
1434         struct file * f;
1435         struct inode *inode;
1436 @@ -693,12 +758,15 @@
1437         }
1438  
1439         if (f->f_op && f->f_op->open) {
1440 +               f->f_it = it;
1441                 error = f->f_op->open(inode,f);
1442 +               f->f_it = NULL;
1443                 if (error)
1444                         goto cleanup_all;
1445         }
1446         f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
1447  
1448 +       intent_release(it);
1449         return f;
1450  
1451  cleanup_all:
1452 @@ -713,11 +781,17 @@
1453  cleanup_file:
1454         put_filp(f);
1455  cleanup_dentry:
1456 +       intent_release(it);
1457         dput(dentry);
1458         mntput(mnt);
1459         return ERR_PTR(error);
1460  }
1461  
1462 +struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
1463 +{
1464 +       return dentry_open_it(dentry, mnt, flags, NULL);
1465 +}
1466 +
1467  /*
1468   * Find an empty file descriptor entry, and mark it busy.
1469   */
1470 Index: linux/fs/stat.c
1471 ===================================================================
1472 --- linux.orig/fs/stat.c        Thu Sep 13 19:04:43 2001
1473 +++ linux/fs/stat.c     Wed Mar 17 13:12:31 2004
1474 @@ -17,10 +17,12 @@
1475   * Revalidate the inode. This is required for proper NFS attribute caching.
1476   */
1477  static __inline__ int
1478 -do_revalidate(struct dentry *dentry)
1479 +do_revalidate(struct dentry *dentry, struct lookup_intent *it)
1480  {
1481         struct inode * inode = dentry->d_inode;
1482 -       if (inode->i_op && inode->i_op->revalidate)
1483 +       if (inode->i_op && inode->i_op->revalidate_it)
1484 +               return inode->i_op->revalidate_it(dentry, it);
1485 +       else if (inode->i_op && inode->i_op->revalidate)
1486                 return inode->i_op->revalidate(dentry);
1487         return 0;
1488  }
1489 @@ -135,13 +137,15 @@
1490  asmlinkage long sys_stat(char * filename, struct __old_kernel_stat * statbuf)
1491  {
1492         struct nameidata nd;
1493 +       struct lookup_intent it = { .it_op = IT_GETATTR };
1494         int error;
1495  
1496 -       error = user_path_walk(filename, &nd);
1497 +       error = user_path_walk_it(filename, &nd, &it);
1498         if (!error) {
1499 -               error = do_revalidate(nd.dentry);
1500 +               error = do_revalidate(nd.dentry, &it);
1501                 if (!error)
1502                         error = cp_old_stat(nd.dentry->d_inode, statbuf);
1503 +               intent_release(&it);
1504                 path_release(&nd);
1505         }
1506         return error;
1507 @@ -151,13 +155,15 @@
1508  asmlinkage long sys_newstat(char * filename, struct stat * statbuf)
1509  {
1510         struct nameidata nd;
1511 +       struct lookup_intent it = { .it_op = IT_GETATTR };
1512         int error;
1513  
1514 -       error = user_path_walk(filename, &nd);
1515 +       error = user_path_walk_it(filename, &nd, &it);
1516         if (!error) {
1517 -               error = do_revalidate(nd.dentry);
1518 +               error = do_revalidate(nd.dentry, &it);
1519                 if (!error)
1520                         error = cp_new_stat(nd.dentry->d_inode, statbuf);
1521 +               intent_release(&it);
1522                 path_release(&nd);
1523         }
1524         return error;
1525 @@ -172,13 +178,15 @@
1526  asmlinkage long sys_lstat(char * filename, struct __old_kernel_stat * statbuf)
1527  {
1528         struct nameidata nd;
1529 +       struct lookup_intent it = { .it_op = IT_GETATTR };
1530         int error;
1531  
1532 -       error = user_path_walk_link(filename, &nd);
1533 +       error = user_path_walk_link_it(filename, &nd, &it);
1534         if (!error) {
1535 -               error = do_revalidate(nd.dentry);
1536 +               error = do_revalidate(nd.dentry, &it);
1537                 if (!error)
1538                         error = cp_old_stat(nd.dentry->d_inode, statbuf);
1539 +               intent_release(&it);
1540                 path_release(&nd);
1541         }
1542         return error;
1543 @@ -189,13 +197,15 @@
1544  asmlinkage long sys_newlstat(char * filename, struct stat * statbuf)
1545  {
1546         struct nameidata nd;
1547 +       struct lookup_intent it = { .it_op = IT_GETATTR };
1548         int error;
1549  
1550 -       error = user_path_walk_link(filename, &nd);
1551 +       error = user_path_walk_link_it(filename, &nd, &it);
1552         if (!error) {
1553 -               error = do_revalidate(nd.dentry);
1554 +               error = do_revalidate(nd.dentry, &it);
1555                 if (!error)
1556                         error = cp_new_stat(nd.dentry->d_inode, statbuf);
1557 +               intent_release(&it);
1558                 path_release(&nd);
1559         }
1560         return error;
1561 @@ -216,7 +226,7 @@
1562         if (f) {
1563                 struct dentry * dentry = f->f_dentry;
1564  
1565 -               err = do_revalidate(dentry);
1566 +               err = do_revalidate(dentry, NULL);
1567                 if (!err)
1568                         err = cp_old_stat(dentry->d_inode, statbuf);
1569                 fput(f);
1570 @@ -235,7 +245,7 @@
1571         if (f) {
1572                 struct dentry * dentry = f->f_dentry;
1573  
1574 -               err = do_revalidate(dentry);
1575 +               err = do_revalidate(dentry, NULL);
1576                 if (!err)
1577                         err = cp_new_stat(dentry->d_inode, statbuf);
1578                 fput(f);
1579 @@ -257,7 +267,7 @@
1580  
1581                 error = -EINVAL;
1582                 if (inode->i_op && inode->i_op->readlink &&
1583 -                   !(error = do_revalidate(nd.dentry))) {
1584 +                   !(error = do_revalidate(nd.dentry, NULL))) {
1585                         UPDATE_ATIME(inode);
1586                         error = inode->i_op->readlink(nd.dentry, buf, bufsiz);
1587                 }
1588 @@ -333,12 +343,14 @@
1589  {
1590         struct nameidata nd;
1591         int error;
1592 +       struct lookup_intent it = { .it_op = IT_GETATTR };
1593  
1594 -       error = user_path_walk(filename, &nd);
1595 +       error = user_path_walk_it(filename, &nd, &it);
1596         if (!error) {
1597 -               error = do_revalidate(nd.dentry);
1598 +               error = do_revalidate(nd.dentry, &it);
1599                 if (!error)
1600                         error = cp_new_stat64(nd.dentry->d_inode, statbuf);
1601 +               intent_release(&it);
1602                 path_release(&nd);
1603         }
1604         return error;
1605 @@ -348,12 +360,14 @@
1606  {
1607         struct nameidata nd;
1608         int error;
1609 +       struct lookup_intent it = { .it_op = IT_GETATTR };
1610  
1611 -       error = user_path_walk_link(filename, &nd);
1612 +       error = user_path_walk_link_it(filename, &nd, &it);
1613         if (!error) {
1614 -               error = do_revalidate(nd.dentry);
1615 +               error = do_revalidate(nd.dentry, &it);
1616                 if (!error)
1617                         error = cp_new_stat64(nd.dentry->d_inode, statbuf);
1618 +               intent_release(&it);
1619                 path_release(&nd);
1620         }
1621         return error;
1622 @@ -368,7 +382,7 @@
1623         if (f) {
1624                 struct dentry * dentry = f->f_dentry;
1625  
1626 -               err = do_revalidate(dentry);
1627 +               err = do_revalidate(dentry, NULL);
1628                 if (!err)
1629                         err = cp_new_stat64(dentry->d_inode, statbuf);
1630                 fput(f);
1631 Index: linux/fs/proc/base.c
1632 ===================================================================
1633 --- linux.orig/fs/proc/base.c   Wed Mar 17 13:00:35 2004
1634 +++ linux/fs/proc/base.c        Wed Mar 17 13:11:25 2004
1635 @@ -481,6 +481,9 @@
1636  
1637         error = inode->u.proc_i.op.proc_get_link(inode, &nd->dentry, &nd->mnt);
1638         nd->last_type = LAST_BIND;
1639 +
1640 +       if (nd->intent != NULL)
1641 +               nd->intent->d.lustre.it_int_flags |= IT_FL_FOLLOWED;
1642  out:
1643         return error;
1644  }
1645 Index: linux/include/linux/dcache.h
1646 ===================================================================
1647 --- linux.orig/include/linux/dcache.h   Thu Nov 28 18:53:15 2002
1648 +++ linux/include/linux/dcache.h        Wed Mar 17 13:11:25 2004
1649 @@ -6,6 +6,51 @@
1650  #include <asm/atomic.h>
1651  #include <linux/mount.h>
1652  #include <linux/kernel.h>
1653 +#include <linux/string.h>
1654 +
1655 +#define IT_OPEN     0x0001
1656 +#define IT_CREAT    0x0002
1657 +#define IT_READDIR  0x0004
1658 +#define IT_GETATTR  0x0008
1659 +#define IT_LOOKUP   0x0010
1660 +#define IT_UNLINK   0x0020
1661 +#define IT_GETXATTR 0x0040
1662 +#define IT_EXEC     0x0080
1663 +#define IT_PIN      0x0100
1664 +
1665 +#define IT_FL_LOCKED   0x0001
1666 +#define IT_FL_FOLLOWED 0x0002 /* set by vfs_follow_link */
1667 +
1668 +#define INTENT_MAGIC 0x19620323
1669 +
1670 +
1671 +struct lustre_intent_data {
1672 +       int       it_disposition;
1673 +       int       it_status;
1674 +       __u64     it_lock_handle;
1675 +       void     *it_data;
1676 +       int       it_lock_mode;
1677 +       int it_int_flags;
1678 +};
1679 +struct lookup_intent {
1680 +       int     it_magic;
1681 +       void    (*it_op_release)(struct lookup_intent *);
1682 +       int     it_op;
1683 +       int     it_flags;
1684 +       int     it_create_mode;
1685 +       union {
1686 +               struct lustre_intent_data lustre;
1687 +       } d;
1688 +};
1689 +
1690 +static inline void intent_init(struct lookup_intent *it, int op, int flags)
1691 +{
1692 +       memset(it, 0, sizeof(*it));
1693 +       it->it_magic = INTENT_MAGIC;
1694 +       it->it_op = op;
1695 +       it->it_flags = flags;
1696 +}
1697 +
1698  
1699  /*
1700   * linux/include/linux/dcache.h
1701 @@ -91,8 +136,22 @@
1702         int (*d_delete)(struct dentry *);
1703         void (*d_release)(struct dentry *);
1704         void (*d_iput)(struct dentry *, struct inode *);
1705 +       int (*d_revalidate_it)(struct dentry *, int, struct lookup_intent *);
1706 +       void (*d_pin)(struct dentry *, struct vfsmount * , int);
1707 +       void (*d_unpin)(struct dentry *, struct vfsmount *, int);
1708  };
1709  
1710 +#define PIN(de,mnt,flag)  if (de && de->d_op && de->d_op->d_pin) \
1711 +                               de->d_op->d_pin(de, mnt, flag);
1712 +#define UNPIN(de,mnt,flag)  if (de && de->d_op && de->d_op->d_unpin) \
1713 +                               de->d_op->d_unpin(de, mnt, flag);
1714 +
1715 +
1716 +/* defined in fs/namei.c */
1717 +extern void intent_release(struct lookup_intent *it);
1718 +/* defined in fs/dcache.c */
1719 +extern void __d_rehash(struct dentry * entry, int lock);
1720 +
1721  /* the dentry parameter passed to d_hash and d_compare is the parent
1722   * directory of the entries to be compared. It is used in case these
1723   * functions need any directory specific information for determining
1724 @@ -124,6 +183,7 @@
1725                                          * s_nfsd_free_path semaphore will be down
1726                                          */
1727  #define DCACHE_REFERENCED      0x0008  /* Recently used, don't discard. */
1728 +#define DCACHE_LUSTRE_INVALID  0x0010  /* Lustre invalidated */
1729  
1730  extern spinlock_t dcache_lock;
1731  
1732 Index: linux/include/linux/fs.h
1733 ===================================================================
1734 --- linux.orig/include/linux/fs.h       Wed Mar 17 13:11:23 2004
1735 +++ linux/include/linux/fs.h    Wed Mar 17 13:11:31 2004
1736 @@ -73,6 +73,7 @@
1737  
1738  #define FMODE_READ 1
1739  #define FMODE_WRITE 2
1740 +#define FMODE_EXEC 4
1741  
1742  #define READ 0
1743  #define WRITE 1
1744 @@ -340,6 +341,9 @@
1745  #define ATTR_MTIME_SET 256
1746  #define ATTR_FORCE     512     /* Not a change, but a change it */
1747  #define ATTR_ATTR_FLAG 1024
1748 +#define ATTR_RAW       0x0800  /* file system, not vfs will massage attrs */
1749 +#define ATTR_FROM_OPEN 0x1000  /* called from open path, ie O_TRUNC */
1750 +#define ATTR_CTIME_SET 0x2000
1751  
1752  /*
1753   * This is the Inode Attributes structure, used for notify_change().  It
1754 @@ -474,6 +478,7 @@
1755         struct pipe_inode_info  *i_pipe;
1756         struct block_device     *i_bdev;
1757         struct char_device      *i_cdev;
1758 +       void                    *i_filterdata;
1759  
1760         unsigned long           i_dnotify_mask; /* Directory notify events */
1761         struct dnotify_struct   *i_dnotify; /* for directory notifications */
1762 @@ -576,6 +581,7 @@
1763  
1764         /* needed for tty driver, and maybe others */
1765         void                    *private_data;
1766 +       struct lookup_intent    *f_it;
1767  
1768         /* preallocated helper kiobuf to speedup O_DIRECT */
1769         struct kiobuf           *f_iobuf;
1770 @@ -697,6 +703,7 @@
1771         struct qstr last;
1772         unsigned int flags;
1773         int last_type;
1774 +       struct lookup_intent *intent;
1775  };
1776  
1777  /*
1778 @@ -817,7 +824,8 @@
1779  extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
1780  extern int vfs_rmdir(struct inode *, struct dentry *);
1781  extern int vfs_unlink(struct inode *, struct dentry *);
1782 -extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
1783 +int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1784 +              struct inode *new_dir, struct dentry *new_dentry);
1785  
1786  /*
1787   * File types
1788 @@ -877,21 +885,32 @@
1789  
1790  struct inode_operations {
1791         int (*create) (struct inode *,struct dentry *,int);
1792 +       int (*create_it) (struct inode *,struct dentry *,int, struct lookup_intent *);
1793         struct dentry * (*lookup) (struct inode *,struct dentry *);
1794 +       struct dentry * (*lookup_it) (struct inode *,struct dentry *, struct lookup_intent *, int flags);
1795         int (*link) (struct dentry *,struct inode *,struct dentry *);
1796 +       int (*link_raw) (struct nameidata *,struct nameidata *);
1797         int (*unlink) (struct inode *,struct dentry *);
1798 +       int (*unlink_raw) (struct nameidata *);
1799         int (*symlink) (struct inode *,struct dentry *,const char *);
1800 +       int (*symlink_raw) (struct nameidata *,const char *);
1801         int (*mkdir) (struct inode *,struct dentry *,int);
1802 +       int (*mkdir_raw) (struct nameidata *,int);
1803         int (*rmdir) (struct inode *,struct dentry *);
1804 +       int (*rmdir_raw) (struct nameidata *);
1805         int (*mknod) (struct inode *,struct dentry *,int,int);
1806 +       int (*mknod_raw) (struct nameidata *,int,dev_t);
1807         int (*rename) (struct inode *, struct dentry *,
1808                         struct inode *, struct dentry *);
1809 +       int (*rename_raw) (struct nameidata *, struct nameidata *);
1810         int (*readlink) (struct dentry *, char *,int);
1811         int (*follow_link) (struct dentry *, struct nameidata *);
1812         void (*truncate) (struct inode *);
1813         int (*permission) (struct inode *, int);
1814         int (*revalidate) (struct dentry *);
1815 +       int (*revalidate_it) (struct dentry *, struct lookup_intent *);
1816         int (*setattr) (struct dentry *, struct iattr *);
1817 +       int (*setattr_raw) (struct inode *, struct iattr *);
1818         int (*getattr) (struct dentry *, struct iattr *);
1819         int (*setxattr) (struct dentry *, const char *, void *, size_t, int);
1820         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
1821 @@ -1088,10 +1107,14 @@
1822  
1823  asmlinkage long sys_open(const char *, int, int);
1824  asmlinkage long sys_close(unsigned int);       /* yes, it's really unsigned */
1825 -extern int do_truncate(struct dentry *, loff_t start);
1826 +extern int do_truncate(struct dentry *, loff_t start, int called_from_open);
1827  
1828  extern struct file *filp_open(const char *, int, int);
1829  extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
1830 +extern int open_namei_it(const char *filename, int namei_flags, int mode,
1831 +                        struct nameidata *nd, struct lookup_intent *it);
1832 +extern struct file *dentry_open_it(struct dentry *dentry, struct vfsmount *mnt,
1833 +                           int flags, struct lookup_intent *it);
1834  extern int filp_close(struct file *, fl_owner_t id);
1835  extern char * getname(const char *);
1836  
1837 @@ -1354,6 +1377,7 @@
1838  extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
1839  
1840  extern int FASTCALL(__user_walk(const char *, unsigned, struct nameidata *));
1841 +extern int FASTCALL(__user_walk_it(const char *, unsigned, struct nameidata *, struct lookup_intent *it));
1842  extern int FASTCALL(path_init(const char *, unsigned, struct nameidata *));
1843  extern int FASTCALL(path_walk(const char *, struct nameidata *));
1844  extern int FASTCALL(path_lookup(const char *, unsigned, struct nameidata *));
1845 @@ -1365,6 +1389,8 @@
1846  extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
1847  #define user_path_walk(name,nd)         __user_walk(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, nd)
1848  #define user_path_walk_link(name,nd) __user_walk(name, LOOKUP_POSITIVE, nd)
1849 +#define user_path_walk_it(name,nd,it)  __user_walk_it(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, nd, it)
1850 +#define user_path_walk_link_it(name,nd,it) __user_walk_it(name, LOOKUP_POSITIVE, nd, it)
1851  
1852  extern void inode_init_once(struct inode *);
1853  extern void _inode_init_once(struct inode *);
1854 @@ -1503,6 +1529,8 @@
1855  
1856  extern int vfs_readlink(struct dentry *, char *, int, const char *);
1857  extern int vfs_follow_link(struct nameidata *, const char *);
1858 +extern int vfs_follow_link_it(struct nameidata *, const char *,
1859 +                             struct lookup_intent *it);
1860  extern int page_readlink(struct dentry *, char *, int);
1861  extern int page_follow_link(struct dentry *, struct nameidata *);
1862  extern struct inode_operations page_symlink_inode_operations;
1863 Index: linux/include/linux/fs_struct.h
1864 ===================================================================
1865 --- linux.orig/include/linux/fs_struct.h        Fri Jul 13 18:10:44 2001
1866 +++ linux/include/linux/fs_struct.h     Wed Mar 17 13:11:25 2004
1867 @@ -34,10 +34,12 @@
1868         write_lock(&fs->lock);
1869         old_root = fs->root;
1870         old_rootmnt = fs->rootmnt;
1871 +       PIN(dentry, mnt, 1);
1872         fs->rootmnt = mntget(mnt);
1873         fs->root = dget(dentry);
1874         write_unlock(&fs->lock);
1875         if (old_root) {
1876 +               UNPIN(old_root, old_rootmnt, 1);
1877                 dput(old_root);
1878                 mntput(old_rootmnt);
1879         }
1880 @@ -57,10 +59,12 @@
1881         write_lock(&fs->lock);
1882         old_pwd = fs->pwd;
1883         old_pwdmnt = fs->pwdmnt;
1884 +       PIN(dentry, mnt, 0);
1885         fs->pwdmnt = mntget(mnt);
1886         fs->pwd = dget(dentry);
1887         write_unlock(&fs->lock);
1888         if (old_pwd) {
1889 +               UNPIN(old_pwd, old_pwdmnt, 0);
1890                 dput(old_pwd);
1891                 mntput(old_pwdmnt);
1892         }
1893 Index: linux/kernel/ksyms.c
1894 ===================================================================
1895 --- linux.orig/kernel/ksyms.c   Wed Mar 17 13:11:23 2004
1896 +++ linux/kernel/ksyms.c        Wed Mar 17 13:11:25 2004
1897 @@ -315,6 +315,7 @@
1898  EXPORT_SYMBOL(set_page_dirty);
1899  EXPORT_SYMBOL(vfs_readlink);
1900  EXPORT_SYMBOL(vfs_follow_link);
1901 +EXPORT_SYMBOL(vfs_follow_link_it);
1902  EXPORT_SYMBOL(page_readlink);
1903  EXPORT_SYMBOL(page_follow_link);
1904  EXPORT_SYMBOL(page_symlink_inode_operations);
1905 Index: linux/kernel/fork.c
1906 ===================================================================
1907 --- linux.orig/kernel/fork.c    Wed Mar 17 13:00:38 2004
1908 +++ linux/kernel/fork.c Wed Mar 17 13:11:25 2004
1909 @@ -387,10 +387,13 @@
1910                 fs->umask = old->umask;
1911                 read_lock(&old->lock);
1912                 fs->rootmnt = mntget(old->rootmnt);
1913 +               PIN(old->pwd, old->pwdmnt, 0);
1914 +               PIN(old->root, old->rootmnt, 1);
1915                 fs->root = dget(old->root);
1916                 fs->pwdmnt = mntget(old->pwdmnt);
1917                 fs->pwd = dget(old->pwd);
1918                 if (old->altroot) {
1919 +                       PIN(old->altroot, old->altrootmnt, 1);
1920                         fs->altrootmnt = mntget(old->altrootmnt);
1921                         fs->altroot = dget(old->altroot);
1922                 } else {
1923 Index: linux/kernel/exit.c
1924 ===================================================================
1925 --- linux.orig/kernel/exit.c    Wed Mar 17 13:00:38 2004
1926 +++ linux/kernel/exit.c Wed Mar 17 13:11:25 2004
1927 @@ -239,11 +239,14 @@
1928  {
1929         /* No need to hold fs->lock if we are killing it */
1930         if (atomic_dec_and_test(&fs->count)) {
1931 +               UNPIN(fs->pwd, fs->pwdmnt, 0);
1932 +               UNPIN(fs->root, fs->rootmnt, 1);
1933                 dput(fs->root);
1934                 mntput(fs->rootmnt);
1935                 dput(fs->pwd);
1936                 mntput(fs->pwdmnt);
1937                 if (fs->altroot) {
1938 +                       UNPIN(fs->altroot, fs->altrootmnt, 1);
1939                         dput(fs->altroot);
1940                         mntput(fs->altrootmnt);
1941                 }