~ubuntu-branches/ubuntu/raring/autofs5/raring

« back to all changes in this revision

Viewing changes to patches/autofs4-2.6.11-v5-update-20081027.patch

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2009-03-09 01:16:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090309011648-gjynlid883f0s2c4
Tags: 5.0.4-1
* New upstream version (5.0.4 plus patchset as of 2009/03/09).
  * Closes: #518728.
  * Remove dpatch 14, applied upstream.
* New dpatch 14 to avoid using the relatively young SOCK_CLOEXEC
  feature.
* Only invoke 'make clean' on clean target so ./configure isn't
  purged.
* Fix a typo in the postinst regarding the ucf conffile handling.
* Add 'set -e' to package maintenance scripts.
* Drop unnecessary /var/run/autofs from package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Index: linux-2.6.11/fs/autofs4/autofs_i.h
 
2
===================================================================
 
3
--- linux-2.6.11.orig/fs/autofs4/autofs_i.h
 
4
+++ linux-2.6.11/fs/autofs4/autofs_i.h
 
5
@@ -3,6 +3,7 @@
 
6
  * linux/fs/autofs/autofs_i.h
 
7
  *
 
8
  *   Copyright 1997-1998 Transmeta Corporation - All Rights Reserved
 
9
+ *   Copyright 2005-2006 Ian Kent <raven@themaw.net>
 
10
  *
 
11
  * This file is part of the Linux kernel and is made available under
 
12
  * the terms of the GNU General Public License, version 2, or at your
 
13
@@ -19,6 +20,8 @@
 
14
 #define AUTOFS_IOC_FIRST     AUTOFS_IOC_READY
 
15
 #define AUTOFS_IOC_COUNT     32
 
16
 
 
17
+#define AUTOFS_TYPE_TRIGGER    (AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET)
 
18
+
 
19
 #include <linux/kernel.h>
 
20
 #include <linux/slab.h>
 
21
 #include <linux/time.h>
 
22
@@ -40,14 +43,6 @@
 
23
 
 
24
 #define AUTOFS_SUPER_MAGIC 0x0187
 
25
 
 
26
-/*
 
27
- * If the daemon returns a negative response (AUTOFS_IOC_FAIL) then the
 
28
- * kernel will keep the negative response cached for up to the time given
 
29
- * here, although the time can be shorter if the kernel throws the dcache
 
30
- * entry away.  This probably should be settable from user space.
 
31
- */
 
32
-#define AUTOFS_NEGATIVE_TIMEOUT (60*HZ)        /* 1 minute */
 
33
-
 
34
 /* Unified info structure.  This is pointed to by both the dentry and
 
35
    inode structures.  Each file in the filesystem has an instance of this
 
36
    structure.  It holds a reference to the dentry, so dentries are never
 
37
@@ -60,8 +55,14 @@ struct autofs_info {
 
38
 
 
39
        int             flags;
 
40
 
 
41
+       struct completion expire_complete;
 
42
+
 
43
+       struct list_head active;
 
44
+       struct list_head expiring;
 
45
+
 
46
        struct autofs_sb_info *sbi;
 
47
        unsigned long last_used;
 
48
+       atomic_t count;
 
49
 
 
50
        mode_t  mode;
 
51
        size_t  size;
 
52
@@ -73,35 +74,48 @@ struct autofs_info {
 
53
 };
 
54
 
 
55
 #define AUTOFS_INF_EXPIRING    (1<<0) /* dentry is in the process of expiring */
 
56
+#define AUTOFS_INF_MOUNTPOINT  (1<<1) /* mountpoint status for direct expire */
 
57
 
 
58
 struct autofs_wait_queue {
 
59
        wait_queue_head_t queue;
 
60
        struct autofs_wait_queue *next;
 
61
        autofs_wqt_t wait_queue_token;
 
62
        /* We use the following to see what we are waiting for */
 
63
-       int hash;
 
64
-       int len;
 
65
-       char *name;
 
66
+       struct qstr name;
 
67
+       u32 dev;
 
68
+       u64 ino;
 
69
+       uid_t uid;
 
70
+       gid_t gid;
 
71
+       pid_t pid;
 
72
+       pid_t tgid;
 
73
        /* This is for status reporting upon return */
 
74
        int status;
 
75
-       atomic_t wait_ctr;
 
76
+       unsigned int wait_ctr;
 
77
 };
 
78
 
 
79
 #define AUTOFS_SBI_MAGIC 0x6d4a556d
 
80
 
 
81
 struct autofs_sb_info {
 
82
        u32 magic;
 
83
+       int pipefd;
 
84
        struct file *pipe;
 
85
        pid_t oz_pgrp;
 
86
        int catatonic;
 
87
        int version;
 
88
        int sub_version;
 
89
+       int min_proto;
 
90
+       int max_proto;
 
91
        unsigned long exp_timeout;
 
92
+       unsigned int type;
 
93
        int reghost_enabled;
 
94
        int needs_reghost;
 
95
        struct super_block *sb;
 
96
        struct semaphore wq_sem;
 
97
+       spinlock_t fs_lock;
 
98
        struct autofs_wait_queue *queues; /* Wait queue pointer */
 
99
+       spinlock_t lookup_lock;
 
100
+       struct list_head active_list;
 
101
+       struct list_head expiring_list;
 
102
 };
 
103
 
 
104
 static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
 
105
@@ -127,8 +141,13 @@ static inline int autofs4_ispending(stru
 
106
 {
 
107
        struct autofs_info *inf = autofs4_dentry_ino(dentry);
 
108
 
 
109
-       return (dentry->d_flags & DCACHE_AUTOFS_PENDING) ||
 
110
-               (inf != NULL && inf->flags & AUTOFS_INF_EXPIRING);
 
111
+       if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
 
112
+               return 1;
 
113
+
 
114
+       if (inf->flags & AUTOFS_INF_EXPIRING)
 
115
+               return 1;
 
116
+
 
117
+       return 0;
 
118
 }
 
119
 
 
120
 static inline void autofs4_copy_atime(struct file *src, struct file *dst)
 
121
@@ -142,6 +161,7 @@ void autofs4_free_ino(struct autofs_info
 
122
 
 
123
 /* Expiration */
 
124
 int is_autofs4_dentry(struct dentry *);
 
125
+int autofs4_expire_wait(struct dentry *dentry);
 
126
 int autofs4_expire_run(struct super_block *, struct vfsmount *,
 
127
                        struct autofs_sb_info *,
 
128
                        struct autofs_packet_expire __user *);
 
129
@@ -153,6 +173,8 @@ int autofs4_expire_multi(struct super_bl
 
130
 extern struct inode_operations autofs4_symlink_inode_operations;
 
131
 extern struct inode_operations autofs4_dir_inode_operations;
 
132
 extern struct inode_operations autofs4_root_inode_operations;
 
133
+extern struct inode_operations autofs4_indirect_root_inode_operations;
 
134
+extern struct inode_operations autofs4_direct_root_inode_operations;
 
135
 extern struct file_operations autofs4_dir_operations;
 
136
 extern struct file_operations autofs4_root_operations;
 
137
 
 
138
@@ -163,23 +185,39 @@ struct autofs_info *autofs4_init_ino(str
 
139
 
 
140
 /* Queue management functions */
 
141
 
 
142
-enum autofs_notify
 
143
-{
 
144
-       NFY_NONE,
 
145
-       NFY_MOUNT,
 
146
-       NFY_EXPIRE
 
147
-};
 
148
-
 
149
 int autofs4_wait(struct autofs_sb_info *,struct dentry *, enum autofs_notify);
 
150
 int autofs4_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
 
151
 void autofs4_catatonic_mode(struct autofs_sb_info *);
 
152
 
 
153
+static inline int autofs4_follow_mount(struct vfsmount **mnt, struct dentry **dentry)
 
154
+{
 
155
+       int res = 0;
 
156
+
 
157
+       while (d_mountpoint(*dentry)) {
 
158
+               int followed = follow_down(mnt, dentry);
 
159
+               if (!followed)
 
160
+                       break;
 
161
+               res = 1;
 
162
+       }
 
163
+       return res;
 
164
+}
 
165
+
 
166
+static inline u32 autofs4_get_dev(struct autofs_sb_info *sbi)
 
167
+{
 
168
+       return new_encode_dev(sbi->sb->s_dev);
 
169
+}
 
170
+
 
171
+static inline u64 autofs4_get_ino(struct autofs_sb_info *sbi)
 
172
+{
 
173
+       return sbi->sb->s_root->d_inode->i_ino;
 
174
+}
 
175
+
 
176
 static inline int simple_positive(struct dentry *dentry)
 
177
 {
 
178
        return dentry->d_inode && !d_unhashed(dentry);
 
179
 }
 
180
 
 
181
-static inline int simple_empty_nolock(struct dentry *dentry)
 
182
+static inline int __simple_empty(struct dentry *dentry)
 
183
 {
 
184
        struct dentry *child;
 
185
        int ret = 0;
 
186
@@ -191,3 +229,6 @@ static inline int simple_empty_nolock(st
 
187
 out:
 
188
        return ret;
 
189
 }
 
190
+
 
191
+void autofs4_dentry_release(struct dentry *);
 
192
+extern void autofs4_kill_sb(struct super_block *);
 
193
Index: linux-2.6.11/fs/autofs4/expire.c
 
194
===================================================================
 
195
--- linux-2.6.11.orig/fs/autofs4/expire.c
 
196
+++ linux-2.6.11/fs/autofs4/expire.c
 
197
@@ -4,7 +4,7 @@
 
198
  *
 
199
  *  Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
 
200
  *  Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
 
201
- *  Copyright 2001-2003 Ian Kent <raven@themaw.net>
 
202
+ *  Copyright 2001-2006 Ian Kent <raven@themaw.net>
 
203
  *
 
204
  * This file is part of the Linux kernel and is made available under
 
205
  * the terms of the GNU General Public License, version 2, or at your
 
206
@@ -16,7 +16,7 @@
 
207
 
 
208
 static unsigned long now;
 
209
 
 
210
-/* Check if a dentry can be expired return 1 if it can else return 0 */
 
211
+/* Check if a dentry can be expired */
 
212
 static inline int autofs4_can_expire(struct dentry *dentry,
 
213
                                        unsigned long timeout, int do_now)
 
214
 {
 
215
@@ -41,14 +41,14 @@ static inline int autofs4_can_expire(str
 
216
                     attempts if expire fails the first time */
 
217
                ino->last_used = now;
 
218
        }
 
219
-
 
220
        return 1;
 
221
 }
 
222
 
 
223
-/* Check a mount point for busyness return 1 if not busy, otherwise */
 
224
-static int autofs4_check_mount(struct vfsmount *mnt, struct dentry *dentry)
 
225
+/* Check a mount point for busyness */
 
226
+static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry)
 
227
 {
 
228
-       int status = 0;
 
229
+       struct dentry *top = dentry;
 
230
+       int status = 1;
 
231
 
 
232
        DPRINTK("dentry %p %.*s",
 
233
                dentry, (int)dentry->d_name.len, dentry->d_name.name);
 
234
@@ -59,91 +59,160 @@ static int autofs4_check_mount(struct vf
 
235
        if (!follow_down(&mnt, &dentry))
 
236
                goto done;
 
237
 
 
238
-       while (d_mountpoint(dentry) && follow_down(&mnt, &dentry))
 
239
-               ;
 
240
+       if (is_autofs4_dentry(dentry)) {
 
241
+               struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
242
+
 
243
+               /* This is an autofs submount, we can't expire it */
 
244
+               if (sbi->type == AUTOFS_TYPE_INDIRECT)
 
245
+                       goto done;
 
246
+
 
247
+               /*
 
248
+                * Otherwise it's an offset mount and we need to check
 
249
+                * if we can umount its mount, if there is one.
 
250
+                */
 
251
+               if (!d_mountpoint(dentry))
 
252
+                       goto done;
 
253
+       }
 
254
 
 
255
-       /* This is an autofs submount, we can't expire it */
 
256
-       if (is_autofs4_dentry(dentry))
 
257
+       /* Update the expiry counter if fs is busy */
 
258
+       if (!may_umount_tree(mnt)) {
 
259
+               struct autofs_info *ino = autofs4_dentry_ino(top);
 
260
+               ino->last_used = jiffies;
 
261
                goto done;
 
262
+       }
 
263
 
 
264
-       /* The big question */
 
265
-       if (may_umount_tree(mnt) == 0)
 
266
-               status = 1;
 
267
+       status = 0;
 
268
 done:
 
269
        DPRINTK("returning = %d", status);
 
270
-       mntput(mnt);
 
271
        dput(dentry);
 
272
+       mntput(mnt);
 
273
        return status;
 
274
 }
 
275
 
 
276
+/*
 
277
+ * Calculate next entry in top down tree traversal.
 
278
+ * From next_mnt in namespace.c - elegant.
 
279
+ */
 
280
+static struct dentry *next_dentry(struct dentry *p, struct dentry *root)
 
281
+{
 
282
+       struct list_head *next = p->d_subdirs.next;
 
283
+
 
284
+       if (next == &p->d_subdirs) {
 
285
+               while (1) {
 
286
+                       if (p == root)
 
287
+                               return NULL;
 
288
+                       next = p->d_child.next;
 
289
+                       if (next != &p->d_parent->d_subdirs)
 
290
+                               break;
 
291
+                       p = p->d_parent;
 
292
+               }
 
293
+       }
 
294
+       return list_entry(next, struct dentry, d_child);
 
295
+}
 
296
+
 
297
+/*
 
298
+ * Check a direct mount point for busyness.
 
299
+ * Direct mounts have similar expiry semantics to tree mounts.
 
300
+ * The tree is not busy iff no mountpoints are busy and there are no
 
301
+ * autofs submounts.
 
302
+ */
 
303
+static int autofs4_direct_busy(struct vfsmount *mnt,
 
304
+                               struct dentry *top,
 
305
+                               unsigned long timeout,
 
306
+                               int do_now)
 
307
+{
 
308
+       DPRINTK("top %p %.*s",
 
309
+               top, (int) top->d_name.len, top->d_name.name);
 
310
+
 
311
+       /* If it's busy update the expiry counters */
 
312
+       if (!may_umount_tree(mnt)) {
 
313
+               struct autofs_info *ino = autofs4_dentry_ino(top);
 
314
+               if (ino)
 
315
+                       ino->last_used = jiffies;
 
316
+               return 1;
 
317
+       }
 
318
+
 
319
+       /* Timeout of a direct mount is determined by its top dentry */
 
320
+       if (!autofs4_can_expire(top, timeout, do_now))
 
321
+               return 1;
 
322
+
 
323
+       return 0;
 
324
+}
 
325
+
 
326
 /* Check a directory tree of mount points for busyness
 
327
  * The tree is not busy iff no mountpoints are busy
 
328
- * Return 1 if the tree is busy or 0 otherwise
 
329
  */
 
330
-static int autofs4_check_tree(struct vfsmount *mnt,
 
331
-                             struct dentry *top,
 
332
-                             unsigned long timeout,
 
333
-                             int do_now)
 
334
+static int autofs4_tree_busy(struct vfsmount *mnt,
 
335
+                            struct dentry *top,
 
336
+                            unsigned long timeout,
 
337
+                            int do_now)
 
338
 {
 
339
-       struct dentry *this_parent = top;
 
340
-       struct list_head *next;
 
341
+       struct autofs_info *top_ino = autofs4_dentry_ino(top);
 
342
+       struct dentry *p;
 
343
 
 
344
-       DPRINTK("parent %p %.*s",
 
345
+       DPRINTK("top %p %.*s",
 
346
                top, (int)top->d_name.len, top->d_name.name);
 
347
 
 
348
        /* Negative dentry - give up */
 
349
        if (!simple_positive(top))
 
350
-               return 0;
 
351
-
 
352
-       /* Timeout of a tree mount is determined by its top dentry */
 
353
-       if (!autofs4_can_expire(top, timeout, do_now))
 
354
-               return 0;
 
355
+               return 1;
 
356
 
 
357
        spin_lock(&dcache_lock);
 
358
-repeat:
 
359
-       next = this_parent->d_subdirs.next;
 
360
-resume:
 
361
-       while (next != &this_parent->d_subdirs) {
 
362
-               struct dentry *dentry = list_entry(next, struct dentry, d_child);
 
363
-
 
364
+       for (p = top; p; p = next_dentry(p, top)) {
 
365
                /* Negative dentry - give up */
 
366
-               if (!simple_positive(dentry)) {
 
367
-                       next = next->next;
 
368
+               if (!simple_positive(p))
 
369
                        continue;
 
370
-               }
 
371
 
 
372
                DPRINTK("dentry %p %.*s",
 
373
-                       dentry, (int)dentry->d_name.len, dentry->d_name.name);
 
374
-
 
375
-               if (!simple_empty_nolock(dentry)) {
 
376
-                       this_parent = dentry;
 
377
-                       goto repeat;
 
378
-               }
 
379
+                       p, (int) p->d_name.len, p->d_name.name);
 
380
 
 
381
-               dentry = dget(dentry);
 
382
+               p = dget(p);
 
383
                spin_unlock(&dcache_lock);
 
384
 
 
385
-               if (d_mountpoint(dentry)) {
 
386
-                       /* First busy => tree busy */
 
387
-                       if (!autofs4_check_mount(mnt, dentry)) {
 
388
-                               dput(dentry);
 
389
-                               return 0;
 
390
+               /*
 
391
+                * Is someone visiting anywhere in the subtree ?
 
392
+                * If there's no mount we need to check the usage
 
393
+                * count for the autofs dentry.
 
394
+                * If the fs is busy update the expiry counter.
 
395
+                */
 
396
+               if (d_mountpoint(p)) {
 
397
+                       if (autofs4_mount_busy(mnt, p)) {
 
398
+                               top_ino->last_used = jiffies;
 
399
+                               dput(p);
 
400
+                               return 1;
 
401
                        }
 
402
-               }
 
403
+               } else {
 
404
+                       struct autofs_info *ino = autofs4_dentry_ino(p);
 
405
+                       unsigned int ino_count = atomic_read(&ino->count);
 
406
 
 
407
-               dput(dentry);
 
408
+                       /*
 
409
+                        * Clean stale dentries below that have not been
 
410
+                        * invalidated after a mount fail during lookup
 
411
+                        */
 
412
+                       d_invalidate(p);
 
413
+
 
414
+                       /* allow for dget above and top is already dgot */
 
415
+                       if (p == top)
 
416
+                               ino_count += 2;
 
417
+                       else
 
418
+                               ino_count++;
 
419
+
 
420
+                       if (atomic_read(&p->d_count) > ino_count) {
 
421
+                               top_ino->last_used = jiffies;
 
422
+                               dput(p);
 
423
+                               return 1;
 
424
+                       }
 
425
+               }
 
426
+               dput(p);
 
427
                spin_lock(&dcache_lock);
 
428
-               next = next->next;
 
429
-       }
 
430
-
 
431
-       if (this_parent != top) {
 
432
-               next = this_parent->d_child.next;
 
433
-               this_parent = this_parent->d_parent;
 
434
-               goto resume;
 
435
        }
 
436
        spin_unlock(&dcache_lock);
 
437
 
 
438
-       return 1;
 
439
+       /* Timeout of a tree mount is ultimately determined by its top dentry */
 
440
+       if (!autofs4_can_expire(top, timeout, do_now))
 
441
+               return 1;
 
442
+
 
443
+       return 0;
 
444
 }
 
445
 
 
446
 static struct dentry *autofs4_check_leaves(struct vfsmount *mnt,
 
447
@@ -151,58 +220,70 @@ static struct dentry *autofs4_check_leav
 
448
                                           unsigned long timeout,
 
449
                                           int do_now)
 
450
 {
 
451
-       struct dentry *this_parent = parent;
 
452
-       struct list_head *next;
 
453
+       struct dentry *p;
 
454
 
 
455
        DPRINTK("parent %p %.*s",
 
456
                parent, (int)parent->d_name.len, parent->d_name.name);
 
457
 
 
458
        spin_lock(&dcache_lock);
 
459
-repeat:
 
460
-       next = this_parent->d_subdirs.next;
 
461
-resume:
 
462
-       while (next != &this_parent->d_subdirs) {
 
463
-               struct dentry *dentry = list_entry(next, struct dentry, d_child);
 
464
-
 
465
+       for (p = parent; p; p = next_dentry(p, parent)) {
 
466
                /* Negative dentry - give up */
 
467
-               if (!simple_positive(dentry)) {
 
468
-                       next = next->next;
 
469
+               if (!simple_positive(p))
 
470
                        continue;
 
471
-               }
 
472
 
 
473
                DPRINTK("dentry %p %.*s",
 
474
-                       dentry, (int)dentry->d_name.len, dentry->d_name.name);
 
475
+                       p, (int) p->d_name.len, p->d_name.name);
 
476
 
 
477
-               if (!list_empty(&dentry->d_subdirs)) {
 
478
-                       this_parent = dentry;
 
479
-                       goto repeat;
 
480
-               }
 
481
-
 
482
-               dentry = dget(dentry);
 
483
+               p = dget(p);
 
484
                spin_unlock(&dcache_lock);
 
485
 
 
486
-               if (d_mountpoint(dentry)) {
 
487
-                       /* Can we expire this guy */
 
488
-                       if (!autofs4_can_expire(dentry, timeout, do_now))
 
489
-                               goto cont;
 
490
-
 
491
+               if (d_mountpoint(p)) {
 
492
                        /* Can we umount this guy */
 
493
-                       if (autofs4_check_mount(mnt, dentry))
 
494
-                               return dentry;
 
495
+                       if (autofs4_mount_busy(mnt, p))
 
496
+                               goto cont;
 
497
 
 
498
+                       /* Can we expire this guy */
 
499
+                       if (autofs4_can_expire(p, timeout, do_now))
 
500
+                               return p;
 
501
                }
 
502
 cont:
 
503
-               dput(dentry);
 
504
+               dput(p);
 
505
                spin_lock(&dcache_lock);
 
506
-               next = next->next;
 
507
        }
 
508
+       spin_unlock(&dcache_lock);
 
509
+       return NULL;
 
510
+}
 
511
+
 
512
+/* Check if we can expire a direct mount (possibly a tree) */
 
513
+static struct dentry *autofs4_expire_direct(struct super_block *sb,
 
514
+                                           struct vfsmount *mnt,
 
515
+                                           struct autofs_sb_info *sbi,
 
516
+                                           int how)
 
517
+{
 
518
+       unsigned long timeout;
 
519
+       struct dentry *root = dget(sb->s_root);
 
520
+       int do_now = how & AUTOFS_EXP_IMMEDIATE;
 
521
 
 
522
-       if (this_parent != parent) {
 
523
-               next = this_parent->d_child.next;
 
524
-               this_parent = this_parent->d_parent;
 
525
-               goto resume;
 
526
+       if (!sbi->exp_timeout || !root)
 
527
+               return NULL;
 
528
+
 
529
+       now = jiffies;
 
530
+       timeout = sbi->exp_timeout;
 
531
+
 
532
+       spin_lock(&sbi->fs_lock);
 
533
+       if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
 
534
+               struct autofs_info *ino = autofs4_dentry_ino(root);
 
535
+               if (d_mountpoint(root)) {
 
536
+                       ino->flags |= AUTOFS_INF_MOUNTPOINT;
 
537
+                       root->d_mounted--;
 
538
+               }
 
539
+               ino->flags |= AUTOFS_INF_EXPIRING;
 
540
+               init_completion(&ino->expire_complete);
 
541
+               spin_unlock(&sbi->fs_lock);
 
542
+               return root;
 
543
        }
 
544
-       spin_unlock(&dcache_lock);
 
545
+       spin_unlock(&sbi->fs_lock);
 
546
+       dput(root);
 
547
 
 
548
        return NULL;
 
549
 }
 
550
@@ -213,10 +294,10 @@ cont:
 
551
  *  - it is unused by any user process
 
552
  *  - it has been unused for exp_timeout time
 
553
  */
 
554
-static struct dentry *autofs4_expire(struct super_block *sb,
 
555
-                                    struct vfsmount *mnt,
 
556
-                                    struct autofs_sb_info *sbi,
 
557
-                                    int how)
 
558
+static struct dentry *autofs4_expire_indirect(struct super_block *sb,
 
559
+                                             struct vfsmount *mnt,
 
560
+                                             struct autofs_sb_info *sbi,
 
561
+                                             int how)
 
562
 {
 
563
        unsigned long timeout;
 
564
        struct dentry *root = sb->s_root;
 
565
@@ -224,6 +305,8 @@ static struct dentry *autofs4_expire(str
 
566
        struct list_head *next;
 
567
        int do_now = how & AUTOFS_EXP_IMMEDIATE;
 
568
        int exp_leaves = how & AUTOFS_EXP_LEAVES;
 
569
+       struct autofs_info *ino;
 
570
+       unsigned int ino_count;
 
571
 
 
572
        if ( !sbi->exp_timeout || !root )
 
573
                return NULL;
 
574
@@ -240,7 +323,7 @@ static struct dentry *autofs4_expire(str
 
575
                struct dentry *dentry = list_entry(next, struct dentry, d_child);
 
576
 
 
577
                /* Negative dentry - give up */
 
578
-               if ( !simple_positive(dentry) ) {
 
579
+               if (!simple_positive(dentry)) {
 
580
                        next = next->next;
 
581
                        continue;
 
582
                }
 
583
@@ -248,58 +331,116 @@ static struct dentry *autofs4_expire(str
 
584
                dentry = dget(dentry);
 
585
                spin_unlock(&dcache_lock);
 
586
 
 
587
-               /* Case 1: indirect mount or top level direct mount */
 
588
+               spin_lock(&sbi->fs_lock);
 
589
+               ino = autofs4_dentry_ino(dentry);
 
590
+
 
591
+               /*
 
592
+                * Case 1: (i) indirect mount or top level pseudo direct mount
 
593
+                *         (autofs-4.1).
 
594
+                *         (ii) indirect mount with offset mount, check the "/"
 
595
+                *         offset (autofs-5.0+).
 
596
+                */
 
597
                if (d_mountpoint(dentry)) {
 
598
                        DPRINTK("checking mountpoint %p %.*s",
 
599
                                dentry, (int)dentry->d_name.len, dentry->d_name.name);
 
600
 
 
601
-                       /* Can we expire this guy */
 
602
-                       if (!autofs4_can_expire(dentry, timeout, do_now))
 
603
+                       /* Path walk currently on this dentry? */
 
604
+                       ino_count = atomic_read(&ino->count) + 2;
 
605
+                       if (atomic_read(&dentry->d_count) > ino_count)
 
606
                                goto next;
 
607
 
 
608
                        /* Can we umount this guy */
 
609
-                       if (autofs4_check_mount(mnt, dentry)) {
 
610
+                       if (autofs4_mount_busy(mnt, dentry))
 
611
+                               goto next;
 
612
+
 
613
+                       /* Can we expire this guy */
 
614
+                       if (autofs4_can_expire(dentry, timeout, do_now)) {
 
615
                                expired = dentry;
 
616
-                               break;
 
617
+                               goto found;
 
618
                        }
 
619
                        goto next;
 
620
                }
 
621
 
 
622
-               if ( simple_empty(dentry) )
 
623
+               if (simple_empty(dentry))
 
624
                        goto next;
 
625
 
 
626
                /* Case 2: tree mount, expire iff entire tree is not busy */
 
627
                if (!exp_leaves) {
 
628
-                       if (autofs4_check_tree(mnt, dentry, timeout, do_now)) {
 
629
-                       expired = dentry;
 
630
-                       break;
 
631
+                       /* Path walk currently on this dentry? */
 
632
+                       ino_count = atomic_read(&ino->count) + 1;
 
633
+                       if (atomic_read(&dentry->d_count) > ino_count)
 
634
+                               goto next;
 
635
+
 
636
+                       if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
 
637
+                               expired = dentry;
 
638
+                               goto found;
 
639
                        }
 
640
-               /* Case 3: direct mount, expire individual leaves */
 
641
+               /*
 
642
+                * Case 3: pseudo direct mount, expire individual leaves
 
643
+                *         (autofs-4.1).
 
644
+                */
 
645
                } else {
 
646
+                       /* Path walk currently on this dentry? */
 
647
+                       ino_count = atomic_read(&ino->count) + 1;
 
648
+                       if (atomic_read(&dentry->d_count) > ino_count)
 
649
+                               goto next;
 
650
+
 
651
                        expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
 
652
                        if (expired) {
 
653
                                dput(dentry);
 
654
-                               break;
 
655
+                               goto found;
 
656
                        }
 
657
                }
 
658
 next:
 
659
+               spin_unlock(&sbi->fs_lock);
 
660
                dput(dentry);
 
661
                spin_lock(&dcache_lock);
 
662
                next = next->next;
 
663
        }
 
664
+       spin_unlock(&dcache_lock);
 
665
+       return NULL;
 
666
 
 
667
-       if ( expired ) {
 
668
-               DPRINTK("returning %p %.*s",
 
669
-                       expired, (int)expired->d_name.len, expired->d_name.name);
 
670
-               spin_lock(&dcache_lock);
 
671
-               list_del(&expired->d_parent->d_subdirs);
 
672
-               list_add(&expired->d_parent->d_subdirs, &expired->d_child);
 
673
-               spin_unlock(&dcache_lock);
 
674
-               return expired;
 
675
-       }
 
676
+found:
 
677
+       DPRINTK("returning %p %.*s",
 
678
+               expired, (int)expired->d_name.len, expired->d_name.name);
 
679
+       ino = autofs4_dentry_ino(expired);
 
680
+       ino->flags |= AUTOFS_INF_EXPIRING;
 
681
+       init_completion(&ino->expire_complete);
 
682
+       spin_unlock(&sbi->fs_lock);
 
683
+       spin_lock(&dcache_lock);
 
684
+       list_del(&expired->d_parent->d_subdirs);
 
685
+       list_add(&expired->d_parent->d_subdirs, &expired->d_child);
 
686
        spin_unlock(&dcache_lock);
 
687
+       return expired;
 
688
+}
 
689
 
 
690
-       return NULL;
 
691
+int autofs4_expire_wait(struct dentry *dentry)
 
692
+{
 
693
+       struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
694
+       struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
695
+       int status;
 
696
+
 
697
+       /* Block on any pending expire */
 
698
+       spin_lock(&sbi->fs_lock);
 
699
+       if (ino->flags & AUTOFS_INF_EXPIRING) {
 
700
+               spin_unlock(&sbi->fs_lock);
 
701
+
 
702
+               DPRINTK("waiting for expire %p name=%.*s",
 
703
+                        dentry, dentry->d_name.len, dentry->d_name.name);
 
704
+
 
705
+               status = autofs4_wait(sbi, dentry, NFY_NONE);
 
706
+               wait_for_completion(&ino->expire_complete);
 
707
+
 
708
+               DPRINTK("expire done status=%d", status);
 
709
+
 
710
+               if (d_unhashed(dentry))
 
711
+                       return -EAGAIN;
 
712
+
 
713
+               return status;
 
714
+       }
 
715
+       spin_unlock(&sbi->fs_lock);
 
716
+
 
717
+       return 0;
 
718
 }
 
719
 
 
720
 /* Perform an expiry operation */
 
721
@@ -309,14 +450,16 @@ int autofs4_expire_run(struct super_bloc
 
722
                      struct autofs_packet_expire __user *pkt_p)
 
723
 {
 
724
        struct autofs_packet_expire pkt;
 
725
+       struct autofs_info *ino;
 
726
        struct dentry *dentry;
 
727
+       int ret = 0;
 
728
 
 
729
        memset(&pkt,0,sizeof pkt);
 
730
 
 
731
        pkt.hdr.proto_version = sbi->version;
 
732
        pkt.hdr.type = autofs_ptype_expire;
 
733
 
 
734
-       if ((dentry = autofs4_expire(sb, mnt, sbi, 0)) == NULL)
 
735
+       if ((dentry = autofs4_expire_indirect(sb, mnt, sbi, 0)) == NULL)
 
736
                return -EAGAIN;
 
737
 
 
738
        pkt.len = dentry->d_name.len;
 
739
@@ -325,9 +468,15 @@ int autofs4_expire_run(struct super_bloc
 
740
        dput(dentry);
 
741
 
 
742
        if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
 
743
-               return -EFAULT;
 
744
+               ret = -EFAULT;
 
745
 
 
746
-       return 0;
 
747
+       spin_lock(&sbi->fs_lock);
 
748
+       ino = autofs4_dentry_ino(dentry);
 
749
+       ino->flags &= ~AUTOFS_INF_EXPIRING;
 
750
+       complete_all(&ino->expire_complete);
 
751
+       spin_unlock(&sbi->fs_lock);
 
752
+
 
753
+       return ret;
 
754
 }
 
755
 
 
756
 /* Call repeatedly until it returns -EAGAIN, meaning there's nothing
 
757
@@ -342,17 +491,29 @@ int autofs4_expire_multi(struct super_bl
 
758
        if (arg && get_user(do_now, arg))
 
759
                return -EFAULT;
 
760
 
 
761
-       if ((dentry = autofs4_expire(sb, mnt, sbi, do_now)) != NULL) {
 
762
-               struct autofs_info *de_info = autofs4_dentry_ino(dentry);
 
763
+       if (sbi->type & AUTOFS_TYPE_TRIGGER)
 
764
+               dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
 
765
+       else
 
766
+               dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
 
767
+
 
768
+       if (dentry) {
 
769
+               struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
770
 
 
771
                /* This is synchronous because it makes the daemon a
 
772
                    little easier */
 
773
-               de_info->flags |= AUTOFS_INF_EXPIRING;
 
774
                ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
 
775
-               de_info->flags &= ~AUTOFS_INF_EXPIRING;
 
776
+
 
777
+               spin_lock(&sbi->fs_lock);
 
778
+               if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
 
779
+                       sb->s_root->d_mounted++;
 
780
+                       ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
 
781
+               }
 
782
+               ino->flags &= ~AUTOFS_INF_EXPIRING;
 
783
+               complete_all(&ino->expire_complete);
 
784
+               spin_unlock(&sbi->fs_lock);
 
785
                dput(dentry);
 
786
        }
 
787
-               
 
788
+
 
789
        return ret;
 
790
 }
 
791
 
 
792
Index: linux-2.6.11/fs/autofs4/inode.c
 
793
===================================================================
 
794
--- linux-2.6.11.orig/fs/autofs4/inode.c
 
795
+++ linux-2.6.11/fs/autofs4/inode.c
 
796
@@ -3,6 +3,7 @@
 
797
  * linux/fs/autofs/inode.c
 
798
  *
 
799
  *  Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
 
800
+ *  Copyright 2005-2006 Ian Kent <raven@themaw.net>
 
801
  *
 
802
  * This file is part of the Linux kernel and is made available under
 
803
  * the terms of the GNU General Public License, version 2, or at your
 
804
@@ -13,9 +14,11 @@
 
805
 #include <linux/kernel.h>
 
806
 #include <linux/slab.h>
 
807
 #include <linux/file.h>
 
808
+#include <linux/seq_file.h>
 
809
 #include <linux/pagemap.h>
 
810
 #include <linux/parser.h>
 
811
 #include <linux/bitops.h>
 
812
+#include <linux/smp_lock.h>
 
813
 #include "autofs_i.h"
 
814
 #include <linux/module.h>
 
815
 
 
816
@@ -40,12 +43,17 @@ struct autofs_info *autofs4_init_ino(str
 
817
        if (ino == NULL)
 
818
                return NULL;
 
819
 
 
820
-       ino->flags = 0;
 
821
-       ino->mode = mode;
 
822
-       ino->inode = NULL;
 
823
-       ino->dentry = NULL;
 
824
-       ino->size = 0;
 
825
+       if (!reinit) {
 
826
+               ino->flags = 0;
 
827
+               ino->inode = NULL;
 
828
+               ino->dentry = NULL;
 
829
+               ino->size = 0;
 
830
+               INIT_LIST_HEAD(&ino->active);
 
831
+               INIT_LIST_HEAD(&ino->expiring);
 
832
+               atomic_set(&ino->count, 0);
 
833
+       }
 
834
 
 
835
+       ino->mode = mode;
 
836
        ino->last_used = jiffies;
 
837
 
 
838
        ino->sbi = sbi;
 
839
@@ -65,10 +73,19 @@ struct autofs_info *autofs4_init_ino(str
 
840
 
 
841
 void autofs4_free_ino(struct autofs_info *ino)
 
842
 {
 
843
+       struct autofs_info *p_ino;
 
844
+
 
845
        if (ino->dentry) {
 
846
                ino->dentry->d_fsdata = NULL;
 
847
-               if (ino->dentry->d_inode)
 
848
+               if (ino->dentry->d_inode) {
 
849
+                       struct dentry *parent = ino->dentry->d_parent;
 
850
+                       if (atomic_dec_and_test(&ino->count)) {
 
851
+                               p_ino = autofs4_dentry_ino(parent);
 
852
+                               if (p_ino && parent != ino->dentry)
 
853
+                                       atomic_dec(&p_ino->count);
 
854
+                       }
 
855
                        dput(ino->dentry);
 
856
+               }
 
857
                ino->dentry = NULL;
 
858
        }
 
859
        if (ino->free)
 
860
@@ -76,26 +93,121 @@ void autofs4_free_ino(struct autofs_info
 
861
        kfree(ino);
 
862
 }
 
863
 
 
864
-static void autofs4_put_super(struct super_block *sb)
 
865
+/*
 
866
+ * Deal with the infamous "Busy inodes after umount ..." message.
 
867
+ *
 
868
+ * Clean up the dentry tree. This happens with autofs if the user
 
869
+ * space program goes away due to a SIGKILL, SIGSEGV etc.
 
870
+ */
 
871
+static void autofs4_force_release(struct autofs_sb_info *sbi)
 
872
+{
 
873
+       struct dentry *this_parent = sbi->sb->s_root;
 
874
+       struct list_head *next;
 
875
+
 
876
+       if (!sbi->sb->s_root)
 
877
+               return;
 
878
+
 
879
+       spin_lock(&dcache_lock);
 
880
+repeat:
 
881
+       next = this_parent->d_subdirs.next;
 
882
+resume:
 
883
+       while (next != &this_parent->d_subdirs) {
 
884
+               struct dentry *dentry = list_entry(next, struct dentry, d_child);
 
885
+
 
886
+               /* Negative dentry - don`t care */
 
887
+               if (!simple_positive(dentry)) {
 
888
+                       next = next->next;
 
889
+                       continue;
 
890
+               }
 
891
+
 
892
+               if (!list_empty(&dentry->d_subdirs)) {
 
893
+                       this_parent = dentry;
 
894
+                       goto repeat;
 
895
+               }
 
896
+
 
897
+               next = next->next;
 
898
+               spin_unlock(&dcache_lock);
 
899
+
 
900
+               DPRINTK("dentry %p %.*s",
 
901
+                       dentry, (int)dentry->d_name.len, dentry->d_name.name);
 
902
+
 
903
+               dput(dentry);
 
904
+               spin_lock(&dcache_lock);
 
905
+       }
 
906
+
 
907
+       if (this_parent != sbi->sb->s_root) {
 
908
+               struct dentry *dentry = this_parent;
 
909
+
 
910
+               next = this_parent->d_child.next;
 
911
+               this_parent = this_parent->d_parent;
 
912
+               spin_unlock(&dcache_lock);
 
913
+               DPRINTK("parent dentry %p %.*s",
 
914
+                       dentry, (int)dentry->d_name.len, dentry->d_name.name);
 
915
+               dput(dentry);
 
916
+               spin_lock(&dcache_lock);
 
917
+               goto resume;
 
918
+       }
 
919
+       spin_unlock(&dcache_lock);
 
920
+       shrink_dcache_sb(sbi->sb);
 
921
+}
 
922
+
 
923
+void autofs4_kill_sb(struct super_block *sb)
 
924
 {
 
925
        struct autofs_sb_info *sbi = autofs4_sbi(sb);
 
926
 
 
927
-       sb->s_fs_info = NULL;
 
928
+       /*
 
929
+        * In the event of a failure in get_sb_nodev the superblock
 
930
+        * info is not present so nothing else has been setup, so
 
931
+        * just call kill_anon_super when we are called from
 
932
+        * deactivate_super.
 
933
+        */
 
934
+       if (!sbi)
 
935
+               goto out_kill_sb;
 
936
 
 
937
-       if ( !sbi->catatonic )
 
938
-               autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
 
939
+       /* Free wait queues, close pipe */
 
940
+       autofs4_catatonic_mode(sbi);
 
941
 
 
942
+       /* Clean up and release dangling references */
 
943
+       autofs4_force_release(sbi);
 
944
+
 
945
+       sb->s_fs_info = NULL;
 
946
        kfree(sbi);
 
947
 
 
948
+out_kill_sb:
 
949
        DPRINTK("shutting down");
 
950
+       kill_anon_super(sb);
 
951
+}
 
952
+
 
953
+static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt)
 
954
+{
 
955
+       struct autofs_sb_info *sbi = autofs4_sbi(mnt->mnt_sb);
 
956
+
 
957
+       if (!sbi)
 
958
+               return 0;
 
959
+
 
960
+       seq_printf(m, ",fd=%d", sbi->pipefd);
 
961
+       seq_printf(m, ",pgrp=%d", sbi->oz_pgrp);
 
962
+       seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ);
 
963
+       seq_printf(m, ",minproto=%d", sbi->min_proto);
 
964
+       seq_printf(m, ",maxproto=%d", sbi->max_proto);
 
965
+
 
966
+       if (sbi->type & AUTOFS_TYPE_OFFSET)
 
967
+               seq_printf(m, ",offset");
 
968
+       else if (sbi->type & AUTOFS_TYPE_DIRECT)
 
969
+               seq_printf(m, ",direct");
 
970
+       else
 
971
+               seq_printf(m, ",indirect");
 
972
+
 
973
+       return 0;
 
974
 }
 
975
 
 
976
 static struct super_operations autofs4_sops = {
 
977
-       .put_super      = autofs4_put_super,
 
978
        .statfs         = simple_statfs,
 
979
+       .show_options   = autofs4_show_options,
 
980
 };
 
981
 
 
982
-enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto};
 
983
+enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto,
 
984
+       Opt_indirect, Opt_direct, Opt_offset};
 
985
 
 
986
 static match_table_t tokens = {
 
987
        {Opt_fd, "fd=%u"},
 
988
@@ -104,11 +216,15 @@ static match_table_t tokens = {
 
989
        {Opt_pgrp, "pgrp=%u"},
 
990
        {Opt_minproto, "minproto=%u"},
 
991
        {Opt_maxproto, "maxproto=%u"},
 
992
+       {Opt_indirect, "indirect"},
 
993
+       {Opt_direct, "direct"},
 
994
+       {Opt_offset, "offset"},
 
995
        {Opt_err, NULL}
 
996
 };
 
997
 
 
998
 static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
 
999
-                        pid_t *pgrp, int *minproto, int *maxproto)
 
1000
+                        pid_t *pgrp, unsigned int *type,
 
1001
+                        int *minproto, int *maxproto)
 
1002
 {
 
1003
        char *p;
 
1004
        substring_t args[MAX_OPT_ARGS];
 
1005
@@ -162,6 +278,15 @@ static int parse_options(char *options, 
 
1006
                                return 1;
 
1007
                        *maxproto = option;
 
1008
                        break;
 
1009
+               case Opt_indirect:
 
1010
+                       *type = AUTOFS_TYPE_INDIRECT;
 
1011
+                       break;
 
1012
+               case Opt_direct:
 
1013
+                       *type = AUTOFS_TYPE_DIRECT;
 
1014
+                       break;
 
1015
+               case Opt_offset:
 
1016
+                       *type = AUTOFS_TYPE_OFFSET;
 
1017
+                       break;
 
1018
                default:
 
1019
                        return 1;
 
1020
                }
 
1021
@@ -180,6 +305,10 @@ static struct autofs_info *autofs4_mkroo
 
1022
        return ino;
 
1023
 }
 
1024
 
 
1025
+static struct dentry_operations autofs4_sb_dentry_operations = {
 
1026
+       .d_release      = autofs4_dentry_release,
 
1027
+};
 
1028
+
 
1029
 int autofs4_fill_super(struct super_block *s, void *data, int silent)
 
1030
 {
 
1031
        struct inode * root_inode;
 
1032
@@ -188,7 +317,6 @@ int autofs4_fill_super(struct super_bloc
 
1033
        int pipefd;
 
1034
        struct autofs_sb_info *sbi;
 
1035
        struct autofs_info *ino;
 
1036
-       int minproto, maxproto;
 
1037
 
 
1038
        sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
 
1039
        if ( !sbi )
 
1040
@@ -199,14 +327,23 @@ int autofs4_fill_super(struct super_bloc
 
1041
 
 
1042
        s->s_fs_info = sbi;
 
1043
        sbi->magic = AUTOFS_SBI_MAGIC;
 
1044
-       sbi->catatonic = 0;
 
1045
+       sbi->pipefd = -1;
 
1046
+       sbi->pipe = NULL;
 
1047
+       sbi->catatonic = 1;
 
1048
        sbi->exp_timeout = 0;
 
1049
        sbi->oz_pgrp = process_group(current);
 
1050
        sbi->sb = s;
 
1051
        sbi->version = 0;
 
1052
        sbi->sub_version = 0;
 
1053
+       sbi->type = AUTOFS_TYPE_INDIRECT;
 
1054
+       sbi->min_proto = 0;
 
1055
+       sbi->max_proto = 0;
 
1056
        init_MUTEX(&sbi->wq_sem);
 
1057
+       spin_lock_init(&sbi->fs_lock);
 
1058
        sbi->queues = NULL;
 
1059
+       spin_lock_init(&sbi->lookup_lock);
 
1060
+       INIT_LIST_HEAD(&sbi->active_list);
 
1061
+       INIT_LIST_HEAD(&sbi->expiring_list);
 
1062
        s->s_blocksize = 1024;
 
1063
        s->s_blocksize_bits = 10;
 
1064
        s->s_magic = AUTOFS_SUPER_MAGIC;
 
1065
@@ -220,38 +357,46 @@ int autofs4_fill_super(struct super_bloc
 
1066
        if (!ino)
 
1067
                goto fail_free;
 
1068
        root_inode = autofs4_get_inode(s, ino);
 
1069
-       kfree(ino);
 
1070
        if (!root_inode)
 
1071
-               goto fail_free;
 
1072
+               goto fail_ino;
 
1073
 
 
1074
-       root_inode->i_op = &autofs4_root_inode_operations;
 
1075
-       root_inode->i_fop = &autofs4_root_operations;
 
1076
        root = d_alloc_root(root_inode);
 
1077
-       pipe = NULL;
 
1078
-
 
1079
        if (!root)
 
1080
                goto fail_iput;
 
1081
+       pipe = NULL;
 
1082
+
 
1083
+       root->d_op = &autofs4_sb_dentry_operations;
 
1084
+       root->d_fsdata = ino;
 
1085
 
 
1086
        /* Can this call block? */
 
1087
        if (parse_options(data, &pipefd,
 
1088
                          &root_inode->i_uid, &root_inode->i_gid,
 
1089
-                         &sbi->oz_pgrp,
 
1090
-                         &minproto, &maxproto)) {
 
1091
+                         &sbi->oz_pgrp, &sbi->type,
 
1092
+                         &sbi->min_proto, &sbi->max_proto)) {
 
1093
                printk("autofs: called with bogus options\n");
 
1094
                goto fail_dput;
 
1095
        }
 
1096
 
 
1097
+       root_inode->i_fop = &autofs4_root_operations;
 
1098
+       root_inode->i_op = sbi->type & AUTOFS_TYPE_TRIGGER ?
 
1099
+                       &autofs4_direct_root_inode_operations :
 
1100
+                       &autofs4_indirect_root_inode_operations;
 
1101
+
 
1102
        /* Couldn't this be tested earlier? */
 
1103
-       if (maxproto < AUTOFS_MIN_PROTO_VERSION ||
 
1104
-           minproto > AUTOFS_MAX_PROTO_VERSION) {
 
1105
+       if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
 
1106
+           sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
 
1107
                printk("autofs: kernel does not match daemon version "
 
1108
                       "daemon (%d, %d) kernel (%d, %d)\n",
 
1109
-                       minproto, maxproto,
 
1110
+                       sbi->min_proto, sbi->max_proto,
 
1111
                        AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
 
1112
                goto fail_dput;
 
1113
        }
 
1114
 
 
1115
-       sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto;
 
1116
+       /* Establish highest kernel protocol version */
 
1117
+       if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
 
1118
+               sbi->version = AUTOFS_MAX_PROTO_VERSION;
 
1119
+       else
 
1120
+               sbi->version = sbi->max_proto;
 
1121
        sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
 
1122
 
 
1123
        DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp);
 
1124
@@ -264,6 +409,8 @@ int autofs4_fill_super(struct super_bloc
 
1125
        if ( !pipe->f_op || !pipe->f_op->write )
 
1126
                goto fail_fput;
 
1127
        sbi->pipe = pipe;
 
1128
+       sbi->pipefd = pipefd;
 
1129
+       sbi->catatonic = 0;
 
1130
 
 
1131
        /*
 
1132
         * Success! Install the root dentry now to indicate completion.
 
1133
@@ -284,8 +431,11 @@ fail_dput:
 
1134
 fail_iput:
 
1135
        printk("autofs: get root dentry failed\n");
 
1136
        iput(root_inode);
 
1137
+fail_ino:
 
1138
+       kfree(ino);
 
1139
 fail_free:
 
1140
        kfree(sbi);
 
1141
+       s->s_fs_info = NULL;
 
1142
 fail_unlock:
 
1143
        return -EINVAL;
 
1144
 }
 
1145
Index: linux-2.6.11/fs/autofs4/waitq.c
 
1146
===================================================================
 
1147
--- linux-2.6.11.orig/fs/autofs4/waitq.c
 
1148
+++ linux-2.6.11/fs/autofs4/waitq.c
 
1149
@@ -3,7 +3,7 @@
 
1150
  * linux/fs/autofs/waitq.c
 
1151
  *
 
1152
  *  Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
 
1153
- *  Copyright 2001-2003 Ian Kent <raven@themaw.net>
 
1154
+ *  Copyright 2001-2006 Ian Kent <raven@themaw.net>
 
1155
  *
 
1156
  * This file is part of the Linux kernel and is made available under
 
1157
  * the terms of the GNU General Public License, version 2, or at your
 
1158
@@ -28,24 +28,31 @@ void autofs4_catatonic_mode(struct autof
 
1159
 {
 
1160
        struct autofs_wait_queue *wq, *nwq;
 
1161
 
 
1162
+       down(&sbi->wq_sem);
 
1163
+       if (sbi->catatonic) {
 
1164
+               up(&sbi->wq_sem);
 
1165
+               return;
 
1166
+       }
 
1167
+
 
1168
        DPRINTK("entering catatonic mode");
 
1169
 
 
1170
        sbi->catatonic = 1;
 
1171
        wq = sbi->queues;
 
1172
        sbi->queues = NULL;     /* Erase all wait queues */
 
1173
-       while ( wq ) {
 
1174
+       while (wq) {
 
1175
                nwq = wq->next;
 
1176
                wq->status = -ENOENT; /* Magic is gone - report failure */
 
1177
-               kfree(wq->name);
 
1178
-               wq->name = NULL;
 
1179
+               if (wq->name.name) {
 
1180
+                       kfree(wq->name.name);
 
1181
+                       wq->name.name = NULL;
 
1182
+               }
 
1183
+               wq->wait_ctr--;
 
1184
                wake_up_interruptible(&wq->queue);
 
1185
                wq = nwq;
 
1186
        }
 
1187
-       if (sbi->pipe) {
 
1188
-               fput(sbi->pipe);        /* Close the pipe */
 
1189
-               sbi->pipe = NULL;
 
1190
-       }
 
1191
-
 
1192
+       fput(sbi->pipe);        /* Close the pipe */
 
1193
+       sbi->pipe = NULL;
 
1194
+       up(&sbi->wq_sem);
 
1195
        shrink_dcache_sb(sbi->sb);
 
1196
 }
 
1197
 
 
1198
@@ -88,41 +95,90 @@ static void autofs4_notify_daemon(struct
 
1199
                                 struct autofs_wait_queue *wq,
 
1200
                                 int type)
 
1201
 {
 
1202
-       union autofs_packet_union pkt;
 
1203
+       union {
 
1204
+               struct autofs_packet_hdr hdr;
 
1205
+               union autofs_packet_union v4_pkt;
 
1206
+               union autofs_v5_packet_union v5_pkt;
 
1207
+       } pkt;
 
1208
+       struct file *pipe = NULL;
 
1209
        size_t pktsz;
 
1210
 
 
1211
        DPRINTK("wait id = 0x%08lx, name = %.*s, type=%d",
 
1212
-               wq->wait_queue_token, wq->len, wq->name, type);
 
1213
+               wq->wait_queue_token, wq->name.len, wq->name.name, type);
 
1214
 
 
1215
        memset(&pkt,0,sizeof pkt); /* For security reasons */
 
1216
 
 
1217
        pkt.hdr.proto_version = sbi->version;
 
1218
        pkt.hdr.type = type;
 
1219
-       if (type == autofs_ptype_missing) {
 
1220
-               struct autofs_packet_missing *mp = &pkt.missing;
 
1221
+       switch (type) {
 
1222
+       /* Kernel protocol v4 missing and expire packets */
 
1223
+       case autofs_ptype_missing:
 
1224
+       {
 
1225
+               struct autofs_packet_missing *mp = &pkt.v4_pkt.missing;
 
1226
 
 
1227
                pktsz = sizeof(*mp);
 
1228
 
 
1229
                mp->wait_queue_token = wq->wait_queue_token;
 
1230
-               mp->len = wq->len;
 
1231
-               memcpy(mp->name, wq->name, wq->len);
 
1232
-               mp->name[wq->len] = '\0';
 
1233
-       } else if (type == autofs_ptype_expire_multi) {
 
1234
-               struct autofs_packet_expire_multi *ep = &pkt.expire_multi;
 
1235
+               mp->len = wq->name.len;
 
1236
+               memcpy(mp->name, wq->name.name, wq->name.len);
 
1237
+               mp->name[wq->name.len] = '\0';
 
1238
+               break;
 
1239
+       }
 
1240
+       case autofs_ptype_expire_multi:
 
1241
+       {
 
1242
+               struct autofs_packet_expire_multi *ep = &pkt.v4_pkt.expire_multi;
 
1243
 
 
1244
                pktsz = sizeof(*ep);
 
1245
 
 
1246
                ep->wait_queue_token = wq->wait_queue_token;
 
1247
-               ep->len = wq->len;
 
1248
-               memcpy(ep->name, wq->name, wq->len);
 
1249
-               ep->name[wq->len] = '\0';
 
1250
-       } else {
 
1251
+               ep->len = wq->name.len;
 
1252
+               memcpy(ep->name, wq->name.name, wq->name.len);
 
1253
+               ep->name[wq->name.len] = '\0';
 
1254
+               break;
 
1255
+       }
 
1256
+       /*
 
1257
+        * Kernel protocol v5 packet for handling indirect and direct
 
1258
+        * mount missing and expire requests
 
1259
+        */
 
1260
+       case autofs_ptype_missing_indirect:
 
1261
+       case autofs_ptype_expire_indirect:
 
1262
+       case autofs_ptype_missing_direct:
 
1263
+       case autofs_ptype_expire_direct:
 
1264
+       {
 
1265
+               struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
 
1266
+
 
1267
+               pktsz = sizeof(*packet);
 
1268
+
 
1269
+               packet->wait_queue_token = wq->wait_queue_token;
 
1270
+               packet->len = wq->name.len;
 
1271
+               memcpy(packet->name, wq->name.name, wq->name.len);
 
1272
+               packet->name[wq->name.len] = '\0';
 
1273
+               packet->dev = wq->dev;
 
1274
+               packet->ino = wq->ino;
 
1275
+               packet->uid = wq->uid;
 
1276
+               packet->gid = wq->gid;
 
1277
+               packet->pid = wq->pid;
 
1278
+               packet->tgid = wq->tgid;
 
1279
+               break;
 
1280
+       }
 
1281
+       default:
 
1282
                printk("autofs4_notify_daemon: bad type %d!\n", type);
 
1283
                return;
 
1284
        }
 
1285
 
 
1286
-       if (autofs4_write(sbi->pipe, &pkt, pktsz))
 
1287
-               autofs4_catatonic_mode(sbi);
 
1288
+       /* Check if we have become catatonic */
 
1289
+       down(&sbi->wq_sem);
 
1290
+       if (!sbi->catatonic) {
 
1291
+               pipe = sbi->pipe;
 
1292
+               get_file(pipe);
 
1293
+       }
 
1294
+       up(&sbi->wq_sem);
 
1295
+
 
1296
+       if (pipe) {
 
1297
+               if (autofs4_write(pipe, &pkt, pktsz))
 
1298
+                       autofs4_catatonic_mode(sbi);
 
1299
+               fput(pipe);
 
1300
+       }
 
1301
 }
 
1302
 
 
1303
 static int autofs4_getpath(struct autofs_sb_info *sbi,
 
1304
@@ -138,7 +194,7 @@ static int autofs4_getpath(struct autofs
 
1305
        for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
 
1306
                len += tmp->d_name.len + 1;
 
1307
 
 
1308
-       if (--len > NAME_MAX) {
 
1309
+       if (!len || --len > NAME_MAX) {
 
1310
                spin_unlock(&dcache_lock);
 
1311
                return 0;
 
1312
        }
 
1313
@@ -157,44 +213,170 @@ static int autofs4_getpath(struct autofs
 
1314
        return len;
 
1315
 }
 
1316
 
 
1317
+static struct autofs_wait_queue *
 
1318
+autofs4_find_wait(struct autofs_sb_info *sbi, struct qstr *qstr)
 
1319
+{
 
1320
+       struct autofs_wait_queue *wq = NULL;
 
1321
+
 
1322
+       for (wq = sbi->queues ; wq ; wq = wq->next) {
 
1323
+               if (wq->name.hash == qstr->hash &&
 
1324
+                   wq->name.len == qstr->len &&
 
1325
+                   wq->name.name && !memcmp(wq->name, qstr->name, qstr->len))
 
1326
+                       break;
 
1327
+       }
 
1328
+       return wq;
 
1329
+}
 
1330
+
 
1331
+/*
 
1332
+ * Check if we have a valid request.
 
1333
+ * Returns
 
1334
+ * 1 if the request should continue.
 
1335
+ *   In this case we can return an autofs_wait_queue entry if one is
 
1336
+ *   found or NULL to idicate a new wait needs to be created.
 
1337
+ * 0 or a negative errno if the request shouldn't continue.
 
1338
+ */
 
1339
+static int validate_request(struct autofs_wait_queue **wait,
 
1340
+                           struct autofs_sb_info *sbi,
 
1341
+                           struct qstr *qstr,
 
1342
+                           struct dentry*dentry, enum autofs_notify notify)
 
1343
+{
 
1344
+       struct autofs_wait_queue *wq;
 
1345
+       struct autofs_info *ino;
 
1346
+
 
1347
+       /* Wait in progress, continue; */
 
1348
+       wq = autofs4_find_wait(sbi, qstr);
 
1349
+       if (wq) {
 
1350
+               *wait = wq;
 
1351
+               return 1;
 
1352
+       }
 
1353
+
 
1354
+       *wait = NULL;
 
1355
+
 
1356
+       /* If we don't yet have any info this is a new request */
 
1357
+       ino = autofs4_dentry_ino(dentry);
 
1358
+       if (!ino)
 
1359
+               return 1;
 
1360
+
 
1361
+       /*
 
1362
+        * If we've been asked to wait on an existing expire (NFY_NONE)
 
1363
+        * but there is no wait in the queue ...
 
1364
+        */
 
1365
+       if (notify == NFY_NONE) {
 
1366
+               /*
 
1367
+                * Either we've betean the pending expire to post it's
 
1368
+                * wait or it finished while we waited on the semaphore.
 
1369
+                * So we need to wait till either, the wait appears
 
1370
+                * or the expire finishes.
 
1371
+                */
 
1372
+
 
1373
+               while (ino->flags & AUTOFS_INF_EXPIRING) {
 
1374
+                       up(&sbi->wq_sem);
 
1375
+                       schedule_timeout_interruptible(HZ/10);
 
1376
+                       if (down_interruptible(&sbi->wq_sem))
 
1377
+                               return -EINTR;
 
1378
+
 
1379
+                       wq = autofs4_find_wait(sbi, qstr);
 
1380
+                       if (wq) {
 
1381
+                               *wait = wq;
 
1382
+                               return 1;
 
1383
+                       }
 
1384
+               }
 
1385
+
 
1386
+               /*
 
1387
+                * Not ideal but the status has already gone. Of the two
 
1388
+                * cases where we wait on NFY_NONE neither depend on the
 
1389
+                * return status of the wait.
 
1390
+                */
 
1391
+               return 0;
 
1392
+       }
 
1393
+
 
1394
+       /*
 
1395
+        * If we've been asked to trigger a mount and the request
 
1396
+        * completed while we waited on the semaphore ...
 
1397
+        */
 
1398
+       if (notify == NFY_MOUNT) {
 
1399
+               /*
 
1400
+                * If the dentry isn't hashed just go ahead and try the
 
1401
+                * mount again with a new wait (not much else we can do).
 
1402
+               */
 
1403
+               if (!d_unhashed(dentry)) {
 
1404
+                       /*
 
1405
+                        * But if the dentry is hashed, that means that we
 
1406
+                        * got here through the revalidate path.  Thus, we
 
1407
+                        * need to check if the dentry has been mounted
 
1408
+                        * while we waited on the wq_semaphore. If it has,
 
1409
+                        * simply return success.
 
1410
+                        */
 
1411
+                       if (d_mountpoint(dentry))
 
1412
+                               return 0;
 
1413
+               }
 
1414
+       }
 
1415
+
 
1416
+       return 1;
 
1417
+}
 
1418
+
 
1419
 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
 
1420
                enum autofs_notify notify)
 
1421
 {
 
1422
        struct autofs_wait_queue *wq;
 
1423
+       struct qstr qstr;
 
1424
        char *name;
 
1425
-       int len, status;
 
1426
+       int status, ret, type;
 
1427
 
 
1428
        /* In catatonic mode, we don't wait for nobody */
 
1429
-       if ( sbi->catatonic )
 
1430
+       if (sbi->catatonic)
 
1431
                return -ENOENT;
 
1432
-       
 
1433
+
 
1434
+       if (!dentry->d_inode) {
 
1435
+               /*
 
1436
+                * A wait for a negative dentry is invalid for certain
 
1437
+                * cases. A direct or offset mount "always" has its mount
 
1438
+                * point directory created and so the request dentry must
 
1439
+                * be positive or the map key doesn't exist. The situation
 
1440
+                * is very similar for indirect mounts except only dentrys
 
1441
+                * in the root of the autofs file system may be negative.
 
1442
+                */
 
1443
+               if (sbi->type & AUTOFS_TYPE_TRIGGER)
 
1444
+                       return -ENOENT;
 
1445
+               else if (!IS_ROOT(dentry->d_parent))
 
1446
+                       return -ENOENT;
 
1447
+       }
 
1448
+
 
1449
        name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
 
1450
        if (!name)
 
1451
                return -ENOMEM;
 
1452
 
 
1453
-       len = autofs4_getpath(sbi, dentry, &name);
 
1454
-       if (!len) {
 
1455
-               kfree(name);
 
1456
-               return -ENOENT;
 
1457
+       /* If this is a direct mount request create a dummy name */
 
1458
+       if (IS_ROOT(dentry) && sbi->type & AUTOFS_TYPE_TRIGGER)
 
1459
+               qstr.len = sprintf(name, "%p", dentry);
 
1460
+       else {
 
1461
+               qstr.len = autofs4_getpath(sbi, dentry, &name);
 
1462
+               if (!qstr.len) {
 
1463
+                       kfree(name);
 
1464
+                       return -ENOENT;
 
1465
+               }
 
1466
        }
 
1467
+       qstr.name = name;
 
1468
+       qstr.hash = full_name_hash(name, qstr.len);
 
1469
 
 
1470
        if (down_interruptible(&sbi->wq_sem)) {
 
1471
-               kfree(name);
 
1472
+               kfree(qstr.name);
 
1473
                return -EINTR;
 
1474
        }
 
1475
 
 
1476
-       for (wq = sbi->queues ; wq ; wq = wq->next) {
 
1477
-               if (wq->hash == dentry->d_name.hash &&
 
1478
-                   wq->len == len &&
 
1479
-                   wq->name && !memcmp(wq->name, name, len))
 
1480
-                       break;
 
1481
+       ret = validate_request(&wq, sbi, &qstr, dentry, notify);
 
1482
+       if (ret <= 0) {
 
1483
+               if (ret == 0)
 
1484
+                       up(&sbi->wq_sem);
 
1485
+               kfree(qstr.name);
 
1486
+               return ret;
 
1487
        }
 
1488
 
 
1489
-       if ( !wq ) {
 
1490
+       if (!wq) {
 
1491
                /* Create a new wait queue */
 
1492
                wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
 
1493
-               if ( !wq ) {
 
1494
-                       kfree(name);
 
1495
+               if (!wq) {
 
1496
+                       kfree(qstr.name);
 
1497
                        up(&sbi->wq_sem);
 
1498
                        return -ENOMEM;
 
1499
                }
 
1500
@@ -205,41 +387,53 @@ int autofs4_wait(struct autofs_sb_info *
 
1501
                wq->next = sbi->queues;
 
1502
                sbi->queues = wq;
 
1503
                init_waitqueue_head(&wq->queue);
 
1504
-               wq->hash = dentry->d_name.hash;
 
1505
-               wq->name = name;
 
1506
-               wq->len = len;
 
1507
+               memcpy(&wq->name, &qstr, sizeof(struct qstr));
 
1508
+               wq->dev = autofs4_get_dev(sbi);
 
1509
+               wq->ino = autofs4_get_ino(sbi);
 
1510
+               wq->uid = current->uid;
 
1511
+               wq->gid = current->gid;
 
1512
+               wq->pid = current->pid;
 
1513
+               wq->tgid = current->tgid;
 
1514
                wq->status = -EINTR; /* Status return if interrupted */
 
1515
-               atomic_set(&wq->wait_ctr, 2);
 
1516
+               wq->wait_ctr = 2;
 
1517
                up(&sbi->wq_sem);
 
1518
 
 
1519
-               DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d",
 
1520
-                       (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
 
1521
-               /* autofs4_notify_daemon() may block */
 
1522
-               if (notify != NFY_NONE) {
 
1523
-                       autofs4_notify_daemon(sbi,wq, 
 
1524
-                                       notify == NFY_MOUNT ?
 
1525
-                                                 autofs_ptype_missing :
 
1526
-                                                 autofs_ptype_expire_multi);
 
1527
+               if (sbi->version < 5) {
 
1528
+                       if (notify == NFY_MOUNT)
 
1529
+                               type = autofs_ptype_missing;
 
1530
+                       else
 
1531
+                               type = autofs_ptype_expire_multi;
 
1532
+               } else {
 
1533
+                       if (notify == NFY_MOUNT)
 
1534
+                               type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
 
1535
+                                       autofs_ptype_missing_direct :
 
1536
+                                        autofs_ptype_missing_indirect;
 
1537
+                       else
 
1538
+                               type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
 
1539
+                                       autofs_ptype_expire_direct :
 
1540
+                                       autofs_ptype_expire_indirect;
 
1541
                }
 
1542
+
 
1543
+               DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
 
1544
+                       (unsigned long) wq->wait_queue_token, wq->name.len,
 
1545
+                       wq->name.name, notify);
 
1546
+
 
1547
+               /* autofs4_notify_daemon() may block */
 
1548
+               autofs4_notify_daemon(sbi, wq, type);
 
1549
        } else {
 
1550
-               atomic_inc(&wq->wait_ctr);
 
1551
+               wq->wait_ctr++;
 
1552
                up(&sbi->wq_sem);
 
1553
+               kfree(qstr.name);
 
1554
                DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
 
1555
-                       (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
 
1556
-       }
 
1557
-
 
1558
-       /* wq->name is NULL if and only if the lock is already released */
 
1559
-
 
1560
-       if ( sbi->catatonic ) {
 
1561
-               /* We might have slept, so check again for catatonic mode */
 
1562
-               wq->status = -ENOENT;
 
1563
-               if ( wq->name ) {
 
1564
-                       kfree(wq->name);
 
1565
-                       wq->name = NULL;
 
1566
-               }
 
1567
+                       (unsigned long) wq->wait_queue_token, wq->name.len,
 
1568
+                       wq->name.name, notify);
 
1569
        }
 
1570
 
 
1571
-       if ( wq->name ) {
 
1572
+       /*
 
1573
+        * wq->name.name is NULL iff the lock is already released
 
1574
+        * or the mount has been made catatonic.
 
1575
+        */
 
1576
+       if (wq->name.name) {
 
1577
                /* Block all but "shutdown" signals while waiting */
 
1578
                sigset_t oldset;
 
1579
                unsigned long irqflags;
 
1580
@@ -250,7 +444,7 @@ int autofs4_wait(struct autofs_sb_info *
 
1581
                recalc_sigpending();
 
1582
                spin_unlock_irqrestore(&current->sighand->siglock, irqflags);
 
1583
 
 
1584
-               wait_event_interruptible(wq->queue, wq->name == NULL);
 
1585
+               wait_event_interruptible(wq->queue, wq->name.name == NULL);
 
1586
 
 
1587
                spin_lock_irqsave(&current->sighand->siglock, irqflags);
 
1588
                current->blocked = oldset;
 
1589
@@ -263,8 +457,10 @@ int autofs4_wait(struct autofs_sb_info *
 
1590
        status = wq->status;
 
1591
 
 
1592
        /* Are we the last process to need status? */
 
1593
-       if (atomic_dec_and_test(&wq->wait_ctr))
 
1594
+       down(&sbi->wq_sem);
 
1595
+       if (!--wq->wait_ctr)
 
1596
                kfree(wq);
 
1597
+       up(&sbi->wq_sem);
 
1598
 
 
1599
        return status;
 
1600
 }
 
1601
@@ -275,27 +471,24 @@ int autofs4_wait_release(struct autofs_s
 
1602
        struct autofs_wait_queue *wq, **wql;
 
1603
 
 
1604
        down(&sbi->wq_sem);
 
1605
-       for ( wql = &sbi->queues ; (wq = *wql) != 0 ; wql = &wq->next ) {
 
1606
-               if ( wq->wait_queue_token == wait_queue_token )
 
1607
+       for (wql = &sbi->queues ; (wq = *wql) != 0 ; wql = &wq->next) {
 
1608
+               if (wq->wait_queue_token == wait_queue_token)
 
1609
                        break;
 
1610
        }
 
1611
 
 
1612
-       if ( !wq ) {
 
1613
+       if (!wq) {
 
1614
                up(&sbi->wq_sem);
 
1615
                return -EINVAL;
 
1616
        }
 
1617
 
 
1618
        *wql = wq->next;        /* Unlink from chain */
 
1619
-       up(&sbi->wq_sem);
 
1620
-       kfree(wq->name);
 
1621
-       wq->name = NULL;        /* Do not wait on this queue */
 
1622
-
 
1623
+       kfree(wq->name.name);
 
1624
+       wq->name.name = NULL;   /* Do not wait on this queue */
 
1625
        wq->status = status;
 
1626
-
 
1627
-       if (atomic_dec_and_test(&wq->wait_ctr)) /* Is anyone still waiting for this guy? */
 
1628
+       wake_up_interruptible(&wq->queue);
 
1629
+       if (!--wq->wait_ctr)
 
1630
                kfree(wq);
 
1631
-       else
 
1632
-               wake_up_interruptible(&wq->queue);
 
1633
+       up(&sbi->wq_sem);
 
1634
 
 
1635
        return 0;
 
1636
 }
 
1637
Index: linux-2.6.11/include/linux/auto_fs4.h
 
1638
===================================================================
 
1639
--- linux-2.6.11.orig/include/linux/auto_fs4.h
 
1640
+++ linux-2.6.11/include/linux/auto_fs4.h
 
1641
@@ -19,18 +19,42 @@
 
1642
 #undef AUTOFS_MIN_PROTO_VERSION
 
1643
 #undef AUTOFS_MAX_PROTO_VERSION
 
1644
 
 
1645
-#define AUTOFS_PROTO_VERSION           4
 
1646
+#define AUTOFS_PROTO_VERSION           5
 
1647
 #define AUTOFS_MIN_PROTO_VERSION       3
 
1648
-#define AUTOFS_MAX_PROTO_VERSION       4
 
1649
+#define AUTOFS_MAX_PROTO_VERSION       5
 
1650
 
 
1651
-#define AUTOFS_PROTO_SUBVERSION         5
 
1652
+#define AUTOFS_PROTO_SUBVERSION                0
 
1653
 
 
1654
 /* Mask for expire behaviour */
 
1655
 #define AUTOFS_EXP_IMMEDIATE           1
 
1656
 #define AUTOFS_EXP_LEAVES              2
 
1657
 
 
1658
-/* New message type */
 
1659
-#define autofs_ptype_expire_multi      2       /* Expire entry (umount request) */
 
1660
+#define AUTOFS_TYPE_ANY                        0x0000
 
1661
+#define AUTOFS_TYPE_INDIRECT           0x0001
 
1662
+#define AUTOFS_TYPE_DIRECT             0x0002
 
1663
+#define AUTOFS_TYPE_OFFSET             0x0004
 
1664
+
 
1665
+/* Daemon notification packet types */
 
1666
+enum autofs_notify {
 
1667
+       NFY_NONE,
 
1668
+       NFY_MOUNT,
 
1669
+       NFY_EXPIRE
 
1670
+};
 
1671
+
 
1672
+/* Kernel protocol version 4 packet types */
 
1673
+
 
1674
+/* Expire entry (umount request) */
 
1675
+#define autofs_ptype_expire_multi      2
 
1676
+
 
1677
+/* Kernel protocol version 5 packet types */
 
1678
+
 
1679
+/* Indirect mount missing and expire requests. */
 
1680
+#define autofs_ptype_missing_indirect  3
 
1681
+#define autofs_ptype_expire_indirect   4
 
1682
+
 
1683
+/* Direct mount missing and expire requests */
 
1684
+#define autofs_ptype_missing_direct    5
 
1685
+#define autofs_ptype_expire_direct     6
 
1686
 
 
1687
 /* v4 multi expire (via pipe) */
 
1688
 struct autofs_packet_expire_multi {
 
1689
@@ -47,10 +71,38 @@ union autofs_packet_union {
 
1690
        struct autofs_packet_expire_multi expire_multi;
 
1691
 };
 
1692
 
 
1693
+/* autofs v5 common packet struct */
 
1694
+struct autofs_v5_packet {
 
1695
+       struct autofs_packet_hdr hdr;
 
1696
+       autofs_wqt_t wait_queue_token;
 
1697
+       __u32 dev;
 
1698
+       __u64 ino;
 
1699
+       __u32 uid;
 
1700
+       __u32 gid;
 
1701
+       __u32 pid;
 
1702
+       __u32 tgid;
 
1703
+       __u32 len;
 
1704
+       char name[NAME_MAX+1];
 
1705
+};
 
1706
+
 
1707
+typedef struct autofs_v5_packet autofs_packet_missing_indirect_t;
 
1708
+typedef struct autofs_v5_packet autofs_packet_expire_indirect_t;
 
1709
+typedef struct autofs_v5_packet autofs_packet_missing_direct_t;
 
1710
+typedef struct autofs_v5_packet autofs_packet_expire_direct_t;
 
1711
+
 
1712
+union autofs_v5_packet_union {
 
1713
+       struct autofs_packet_hdr hdr;
 
1714
+       struct autofs_v5_packet v5_packet;
 
1715
+       autofs_packet_missing_indirect_t missing_indirect;
 
1716
+       autofs_packet_expire_indirect_t expire_indirect;
 
1717
+       autofs_packet_missing_direct_t missing_direct;
 
1718
+       autofs_packet_expire_direct_t expire_direct;
 
1719
+};
 
1720
+
 
1721
 #define AUTOFS_IOC_EXPIRE_MULTI                _IOW(0x93,0x66,int)
 
1722
+#define AUTOFS_IOC_EXPIRE_INDIRECT     AUTOFS_IOC_EXPIRE_MULTI
 
1723
+#define AUTOFS_IOC_EXPIRE_DIRECT       AUTOFS_IOC_EXPIRE_MULTI
 
1724
 #define AUTOFS_IOC_PROTOSUBVER         _IOR(0x93,0x67,int)
 
1725
-#define AUTOFS_IOC_ASKREGHOST           _IOR(0x93,0x68,int)
 
1726
-#define AUTOFS_IOC_TOGGLEREGHOST        _IOR(0x93,0x69,int)
 
1727
 #define AUTOFS_IOC_ASKUMOUNT           _IOR(0x93,0x70,int)
 
1728
 
 
1729
 
 
1730
Index: linux-2.6.11/fs/autofs4/root.c
 
1731
===================================================================
 
1732
--- linux-2.6.11.orig/fs/autofs4/root.c
 
1733
+++ linux-2.6.11/fs/autofs4/root.c
 
1734
@@ -4,7 +4,7 @@
 
1735
  *
 
1736
  *  Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
 
1737
  *  Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
 
1738
- *  Copyright 2001-2003 Ian Kent <raven@themaw.net>
 
1739
+ *  Copyright 2001-2006 Ian Kent <raven@themaw.net>
 
1740
  *
 
1741
  * This file is part of the Linux kernel and is made available under
 
1742
  * the terms of the GNU General Public License, version 2, or at your
 
1743
@@ -25,28 +25,28 @@ static int autofs4_dir_rmdir(struct inod
 
1744
 static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
 
1745
 static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
 
1746
 static int autofs4_dir_open(struct inode *inode, struct file *file);
 
1747
-static int autofs4_dir_close(struct inode *inode, struct file *file);
 
1748
-static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir);
 
1749
-static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
 
1750
 static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
 
1751
-static int autofs4_dcache_readdir(struct file *, void *, filldir_t);
 
1752
+static int autofs4_follow_link(struct dentry *, struct nameidata *);
 
1753
+
 
1754
+#define TRIGGER_FLAGS   (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
 
1755
+#define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
 
1756
 
 
1757
 struct file_operations autofs4_root_operations = {
 
1758
        .open           = dcache_dir_open,
 
1759
        .release        = dcache_dir_close,
 
1760
        .read           = generic_read_dir,
 
1761
-       .readdir        = autofs4_root_readdir,
 
1762
+       .readdir        = dcache_readdir,
 
1763
        .ioctl          = autofs4_root_ioctl,
 
1764
 };
 
1765
 
 
1766
 struct file_operations autofs4_dir_operations = {
 
1767
        .open           = autofs4_dir_open,
 
1768
-       .release        = autofs4_dir_close,
 
1769
+       .release        = dcache_dir_close,
 
1770
        .read           = generic_read_dir,
 
1771
-       .readdir        = autofs4_dir_readdir,
 
1772
+       .readdir        = dcache_readdir,
 
1773
 };
 
1774
 
 
1775
-struct inode_operations autofs4_root_inode_operations = {
 
1776
+struct inode_operations autofs4_indirect_root_inode_operations = {
 
1777
        .lookup         = autofs4_lookup,
 
1778
        .unlink         = autofs4_dir_unlink,
 
1779
        .symlink        = autofs4_dir_symlink,
 
1780
@@ -54,6 +54,14 @@ struct inode_operations autofs4_root_ino
 
1781
        .rmdir          = autofs4_dir_rmdir,
 
1782
 };
 
1783
 
 
1784
+struct inode_operations autofs4_direct_root_inode_operations = {
 
1785
+       .lookup         = autofs4_lookup,
 
1786
+       .unlink         = autofs4_dir_unlink,
 
1787
+       .mkdir          = autofs4_dir_mkdir,
 
1788
+       .rmdir          = autofs4_dir_rmdir,
 
1789
+       .follow_link    = autofs4_follow_link,
 
1790
+};
 
1791
+
 
1792
 struct inode_operations autofs4_dir_inode_operations = {
 
1793
        .lookup         = autofs4_lookup,
 
1794
        .unlink         = autofs4_dir_unlink,
 
1795
@@ -62,113 +70,10 @@ struct inode_operations autofs4_dir_inod
 
1796
        .rmdir          = autofs4_dir_rmdir,
 
1797
 };
 
1798
 
 
1799
-static int autofs4_root_readdir(struct file *file, void *dirent,
 
1800
-                               filldir_t filldir)
 
1801
-{
 
1802
-       struct autofs_sb_info *sbi = autofs4_sbi(file->f_dentry->d_sb);
 
1803
-       int oz_mode = autofs4_oz_mode(sbi);
 
1804
-
 
1805
-       DPRINTK("called, filp->f_pos = %lld", file->f_pos);
 
1806
-
 
1807
-       /*
 
1808
-        * Don't set reghost flag if:
 
1809
-        * 1) f_pos is larger than zero -- we've already been here.
 
1810
-        * 2) we haven't even enabled reghosting in the 1st place.
 
1811
-        * 3) this is the daemon doing a readdir
 
1812
-        */
 
1813
-       if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
 
1814
-               sbi->needs_reghost = 1;
 
1815
-
 
1816
-       DPRINTK("needs_reghost = %d", sbi->needs_reghost);
 
1817
-
 
1818
-       return autofs4_dcache_readdir(file, dirent, filldir);
 
1819
-}
 
1820
-
 
1821
-/* Update usage from here to top of tree, so that scan of
 
1822
-   top-level directories will give a useful result */
 
1823
-static void autofs4_update_usage(struct dentry *dentry)
 
1824
-{
 
1825
-       struct dentry *top = dentry->d_sb->s_root;
 
1826
-
 
1827
-       spin_lock(&dcache_lock);
 
1828
-       for(; dentry != top; dentry = dentry->d_parent) {
 
1829
-               struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
1830
-
 
1831
-               if (ino) {
 
1832
-                       update_atime(dentry->d_inode);
 
1833
-                       ino->last_used = jiffies;
 
1834
-               }
 
1835
-       }
 
1836
-       spin_unlock(&dcache_lock);
 
1837
-}
 
1838
-
 
1839
-/*
 
1840
- * From 2.4 kernel readdir.c
 
1841
- */
 
1842
-static int autofs4_dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
 
1843
-{
 
1844
-       int i;
 
1845
-       struct dentry *dentry = filp->f_dentry;
 
1846
-
 
1847
-       i = filp->f_pos;
 
1848
-       switch (i) {
 
1849
-               case 0:
 
1850
-                       if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
 
1851
-                               break;
 
1852
-                       i++;
 
1853
-                       filp->f_pos++;
 
1854
-                       /* fallthrough */
 
1855
-               case 1:
 
1856
-                       if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
 
1857
-                               break;
 
1858
-                       i++;
 
1859
-                       filp->f_pos++;
 
1860
-                       /* fallthrough */
 
1861
-               default: {
 
1862
-                       struct list_head *list;
 
1863
-                       int j = i-2;
 
1864
-
 
1865
-                       spin_lock(&dcache_lock);
 
1866
-                       list = dentry->d_subdirs.next;
 
1867
-
 
1868
-                       for (;;) {
 
1869
-                               if (list == &dentry->d_subdirs) {
 
1870
-                                       spin_unlock(&dcache_lock);
 
1871
-                                       return 0;
 
1872
-                               }
 
1873
-                               if (!j)
 
1874
-                                       break;
 
1875
-                               j--;
 
1876
-                               list = list->next;
 
1877
-                       }
 
1878
-
 
1879
-                       while(1) {
 
1880
-                               struct dentry *de = list_entry(list, struct dentry, d_child);
 
1881
-
 
1882
-                               if (!d_unhashed(de) && de->d_inode) {
 
1883
-                                       spin_unlock(&dcache_lock);
 
1884
-                                       if (filldir(dirent, de->d_name.name, de->d_name.len, filp->f_pos, de->d_inode->i_ino, DT_UNKNOWN) < 0)
 
1885
-                                               break;
 
1886
-                                       spin_lock(&dcache_lock);
 
1887
-                               }
 
1888
-                               filp->f_pos++;
 
1889
-                               list = list->next;
 
1890
-                               if (list != &dentry->d_subdirs)
 
1891
-                                       continue;
 
1892
-                               spin_unlock(&dcache_lock);
 
1893
-                               break;
 
1894
-                       }
 
1895
-               }
 
1896
-       }
 
1897
-       return 0;
 
1898
-}
 
1899
-
 
1900
 static int autofs4_dir_open(struct inode *inode, struct file *file)
 
1901
 {
 
1902
        struct dentry *dentry = file->f_dentry;
 
1903
-       struct vfsmount *mnt = file->f_vfsmnt;
 
1904
        struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
1905
-       int status;
 
1906
 
 
1907
        DPRINTK("file=%p dentry=%p %.*s",
 
1908
                file, dentry, dentry->d_name.len, dentry->d_name.name);
 
1909
@@ -176,135 +81,31 @@ static int autofs4_dir_open(struct inode
 
1910
        if (autofs4_oz_mode(sbi))
 
1911
                goto out;
 
1912
 
 
1913
-       if (autofs4_ispending(dentry)) {
 
1914
-               DPRINTK("dentry busy");
 
1915
-               return -EBUSY;
 
1916
-       }
 
1917
-
 
1918
-       if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) {
 
1919
-               struct nameidata nd;
 
1920
-               int empty;
 
1921
-
 
1922
-               /* In case there are stale directory dentrys from a failed mount */
 
1923
-               spin_lock(&dcache_lock);
 
1924
-               empty = list_empty(&dentry->d_subdirs);
 
1925
+       /*
 
1926
+        * An empty directory in an autofs file system is always a
 
1927
+        * mount point. The daemon must have failed to mount this
 
1928
+        * during lookup so it doesn't exist. This can happen, for
 
1929
+        * example, if user space returns an incorrect status for a
 
1930
+        * mount request. Otherwise we're doing a readdir on the
 
1931
+        * autofs file system so just let the libfs routines handle
 
1932
+        * it.
 
1933
+        */
 
1934
+       if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
 
1935
                spin_unlock(&dcache_lock);
 
1936
-
 
1937
-               if (!empty)
 
1938
-                       d_invalidate(dentry);
 
1939
-
 
1940
-               nd.flags = LOOKUP_DIRECTORY;
 
1941
-               status = (dentry->d_op->d_revalidate)(dentry, &nd);
 
1942
-
 
1943
-               if (!status)
 
1944
-                       return -ENOENT;
 
1945
-       }
 
1946
-
 
1947
-       if (d_mountpoint(dentry)) {
 
1948
-               struct file *fp = NULL;
 
1949
-               struct vfsmount *fp_mnt = mntget(mnt);
 
1950
-               struct dentry *fp_dentry = dget(dentry);
 
1951
-
 
1952
-               while (follow_down(&fp_mnt, &fp_dentry) && d_mountpoint(fp_dentry));
 
1953
-
 
1954
-               fp = dentry_open(fp_dentry, fp_mnt, file->f_flags);
 
1955
-               status = PTR_ERR(fp);
 
1956
-               if (IS_ERR(fp)) {
 
1957
-                       file->private_data = NULL;
 
1958
-                       return status;
 
1959
-               }
 
1960
-               file->private_data = fp;
 
1961
+               return -ENOENT;
 
1962
        }
 
1963
-out:
 
1964
-       return 0;
 
1965
-}
 
1966
-
 
1967
-static int autofs4_dir_close(struct inode *inode, struct file *file)
 
1968
-{
 
1969
-       struct dentry *dentry = file->f_dentry;
 
1970
-       struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
1971
-
 
1972
-       DPRINTK("file=%p dentry=%p %.*s",
 
1973
-               file, dentry, dentry->d_name.len, dentry->d_name.name);
 
1974
-
 
1975
-       if (autofs4_oz_mode(sbi))
 
1976
-               goto out;
 
1977
-
 
1978
-       if (autofs4_ispending(dentry)) {
 
1979
-               DPRINTK("dentry busy");
 
1980
-               return -EBUSY;
 
1981
-       }
 
1982
-
 
1983
-       if (d_mountpoint(dentry)) {
 
1984
-               struct file *fp = file->private_data;
 
1985
-
 
1986
-               if (!fp)
 
1987
-                       return -ENOENT;
 
1988
+       spin_unlock(&dcache_lock);
 
1989
 
 
1990
-               filp_close(fp, current->files);
 
1991
-               file->private_data = NULL;
 
1992
-       }
 
1993
 out:
 
1994
-       return 0;
 
1995
+       return dcache_dir_open(inode, file);
 
1996
 }
 
1997
 
 
1998
-static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
 
1999
+static int try_to_fill_dentry(struct dentry *dentry, int flags)
 
2000
 {
 
2001
-       struct dentry *dentry = file->f_dentry;
 
2002
        struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
2003
+       struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
2004
        int status;
 
2005
 
 
2006
-       DPRINTK("file=%p dentry=%p %.*s",
 
2007
-               file, dentry, dentry->d_name.len, dentry->d_name.name);
 
2008
-
 
2009
-       if (autofs4_oz_mode(sbi))
 
2010
-               goto out;
 
2011
-
 
2012
-       if (autofs4_ispending(dentry)) {
 
2013
-               DPRINTK("dentry busy");
 
2014
-               return -EBUSY;
 
2015
-       }
 
2016
-
 
2017
-       if (d_mountpoint(dentry)) {
 
2018
-               struct file *fp = file->private_data;
 
2019
-
 
2020
-               if (!fp)
 
2021
-                       return -ENOENT;
 
2022
-
 
2023
-               if (!fp->f_op || !fp->f_op->readdir)
 
2024
-                       goto out;
 
2025
-
 
2026
-               status = vfs_readdir(fp, filldir, dirent);
 
2027
-               file->f_pos = fp->f_pos;
 
2028
-               if (status)
 
2029
-                       autofs4_copy_atime(file, fp);
 
2030
-               return status;
 
2031
-       }
 
2032
-out:
 
2033
-       return autofs4_dcache_readdir(file, dirent, filldir);
 
2034
-}
 
2035
-
 
2036
-static int try_to_fill_dentry(struct dentry *dentry, 
 
2037
-                             struct super_block *sb,
 
2038
-                             struct autofs_sb_info *sbi, int flags)
 
2039
-{
 
2040
-       struct autofs_info *de_info = autofs4_dentry_ino(dentry);
 
2041
-       int status = 0;
 
2042
-
 
2043
-       /* Block on any pending expiry here; invalidate the dentry
 
2044
-           when expiration is done to trigger mount request with a new
 
2045
-           dentry */
 
2046
-       if (de_info && (de_info->flags & AUTOFS_INF_EXPIRING)) {
 
2047
-               DPRINTK("waiting for expire %p name=%.*s",
 
2048
-                        dentry, dentry->d_name.len, dentry->d_name.name);
 
2049
-
 
2050
-               status = autofs4_wait(sbi, dentry, NFY_NONE);
 
2051
-               
 
2052
-               DPRINTK("expire done status=%d", status);
 
2053
-               
 
2054
-               return 0;
 
2055
-       }
 
2056
-
 
2057
        DPRINTK("dentry=%p %.*s ino=%p",
 
2058
                 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
 
2059
 
 
2060
@@ -317,22 +118,19 @@ static int try_to_fill_dentry(struct den
 
2061
                 
 
2062
                DPRINTK("mount done status=%d", status);
 
2063
 
 
2064
-               if (status && dentry->d_inode)
 
2065
-                       return 0; /* Try to get the kernel to invalidate this dentry */
 
2066
-               
 
2067
                /* Turn this into a real negative dentry? */
 
2068
                if (status == -ENOENT) {
 
2069
-                       dentry->d_time = jiffies + AUTOFS_NEGATIVE_TIMEOUT;
 
2070
                        spin_lock(&dentry->d_lock);
 
2071
                        dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
 
2072
                        spin_unlock(&dentry->d_lock);
 
2073
-                       return 1;
 
2074
+                       return status;
 
2075
                } else if (status) {
 
2076
                        /* Return a negative dentry, but leave it "pending" */
 
2077
-                       return 1;
 
2078
+                       return status;
 
2079
                }
 
2080
        /* Trigger mount for path component or follow link */
 
2081
-       } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) ||
 
2082
+       } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
 
2083
+                       flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
 
2084
                        current->link_count) {
 
2085
                DPRINTK("waiting for mount name=%.*s",
 
2086
                        dentry->d_name.len, dentry->d_name.name);
 
2087
@@ -348,19 +146,96 @@ static int try_to_fill_dentry(struct den
 
2088
                        spin_lock(&dentry->d_lock);
 
2089
                        dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
 
2090
                        spin_unlock(&dentry->d_lock);
 
2091
-                       return 0;
 
2092
+                       return status;
 
2093
                }
 
2094
        }
 
2095
 
 
2096
-       /* We don't update the usages for the autofs daemon itself, this
 
2097
-          is necessary for recursive autofs mounts */
 
2098
-       if (!autofs4_oz_mode(sbi))
 
2099
-               autofs4_update_usage(dentry);
 
2100
+       /* Initialize expiry counter after successful mount */
 
2101
+       if (ino)
 
2102
+               ino->last_used = jiffies;
 
2103
 
 
2104
        spin_lock(&dentry->d_lock);
 
2105
        dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
 
2106
        spin_unlock(&dentry->d_lock);
 
2107
-       return 1;
 
2108
+
 
2109
+       return 0;
 
2110
+}
 
2111
+
 
2112
+/* For autofs direct mounts the follow link triggers the mount */
 
2113
+static int autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
 
2114
+{
 
2115
+       struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
2116
+       struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
2117
+       int oz_mode = autofs4_oz_mode(sbi);
 
2118
+       unsigned int lookup_type;
 
2119
+       int status;
 
2120
+
 
2121
+       DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
 
2122
+               dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
 
2123
+               nd->flags);
 
2124
+       /*
 
2125
+        * For an expire of a covered direct or offset mount we need
 
2126
+        * to beeak out of follow_down() at the autofs mount trigger
 
2127
+        * (d_mounted--), so we can see the expiring flag, and manage
 
2128
+        * the blocking and following here until the expire is completed.
 
2129
+        */
 
2130
+       if (oz_mode) {
 
2131
+               spin_lock(&sbi->fs_lock);
 
2132
+               if (ino->flags & AUTOFS_INF_EXPIRING) {
 
2133
+                       spin_unlock(&sbi->fs_lock);
 
2134
+                       /* Follow down to our covering mount. */
 
2135
+                       if (!follow_down(&nd->mnt, &nd->dentry))
 
2136
+                               goto done;
 
2137
+                       goto follow;
 
2138
+               }
 
2139
+               spin_unlock(&sbi->fs_lock);
 
2140
+               goto done;
 
2141
+       }
 
2142
+
 
2143
+       /* If an expire request is pending everyone must wait. */
 
2144
+       autofs4_expire_wait(dentry);
 
2145
+
 
2146
+       /* We trigger a mount for almost all flags */
 
2147
+       lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
 
2148
+       if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
 
2149
+               goto follow;
 
2150
+
 
2151
+       /*
 
2152
+        * If the dentry contains directories then it is an autofs
 
2153
+        * multi-mount with no root mount offset. So don't try to
 
2154
+        * mount it again.
 
2155
+        */
 
2156
+       spin_lock(&dcache_lock);
 
2157
+       if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
 
2158
+           (!d_mountpoint(dentry) && __simple_empty(dentry))) {
 
2159
+               spin_unlock(&dcache_lock);
 
2160
+
 
2161
+               status = try_to_fill_dentry(dentry, 0);
 
2162
+               if (status)
 
2163
+                       goto out_error;
 
2164
+
 
2165
+               goto follow;
 
2166
+       }
 
2167
+       spin_unlock(&dcache_lock);
 
2168
+follow:
 
2169
+       /*
 
2170
+        * If there is no root mount it must be an autofs
 
2171
+        * multi-mount with no root offset so we don't need
 
2172
+        * to follow it.
 
2173
+        */
 
2174
+       if (d_mountpoint(dentry)) {
 
2175
+               if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
 
2176
+                       status = -ENOENT;
 
2177
+                       goto out_error;
 
2178
+               }
 
2179
+       }
 
2180
+
 
2181
+done:
 
2182
+       return 0;
 
2183
+
 
2184
+out_error:
 
2185
+       path_release(nd);
 
2186
+       return status;
 
2187
 }
 
2188
 
 
2189
 /*
 
2190
@@ -369,47 +244,76 @@ static int try_to_fill_dentry(struct den
 
2191
  * yet completely filled in, and revalidate has to delay such
 
2192
  * lookups..
 
2193
  */
 
2194
-static int autofs4_revalidate(struct dentry * dentry, struct nameidata *nd)
 
2195
+static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
 
2196
 {
 
2197
-       struct inode * dir = dentry->d_parent->d_inode;
 
2198
+       struct inode *dir = dentry->d_parent->d_inode;
 
2199
        struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
 
2200
        int oz_mode = autofs4_oz_mode(sbi);
 
2201
        int flags = nd ? nd->flags : 0;
 
2202
-       int status = 1;
 
2203
+       int status;
 
2204
 
 
2205
        /* Pending dentry */
 
2206
+       spin_lock(&sbi->fs_lock);
 
2207
        if (autofs4_ispending(dentry)) {
 
2208
-               if (!oz_mode)
 
2209
-                       status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
 
2210
+               /* The daemon never causes a mount to trigger */
 
2211
+               spin_unlock(&sbi->fs_lock);
 
2212
+
 
2213
+               if (oz_mode)
 
2214
+                       return 1;
 
2215
+
 
2216
+               /*
 
2217
+                * If the directory has gone away due to an expire
 
2218
+                * we have been called as ->d_revalidate() and so
 
2219
+                * we need to return false and proceed to ->lookup().
 
2220
+                */
 
2221
+               if (autofs4_expire_wait(dentry) == -EAGAIN)
 
2222
+                       return 0;
 
2223
+
 
2224
+               /*
 
2225
+                * A zero status is success otherwise we have a
 
2226
+                * negative error code.
 
2227
+                */
 
2228
+               status = try_to_fill_dentry(dentry, flags);
 
2229
+               if (status == 0)
 
2230
+                       return 1;
 
2231
+
 
2232
                return status;
 
2233
        }
 
2234
+       spin_unlock(&sbi->fs_lock);
 
2235
 
 
2236
        /* Negative dentry.. invalidate if "old" */
 
2237
        if (dentry->d_inode == NULL)
 
2238
-               return (dentry->d_time - jiffies <= AUTOFS_NEGATIVE_TIMEOUT);
 
2239
+               return 0;
 
2240
 
 
2241
        /* Check for a non-mountpoint directory with no contents */
 
2242
        spin_lock(&dcache_lock);
 
2243
        if (S_ISDIR(dentry->d_inode->i_mode) &&
 
2244
            !d_mountpoint(dentry) && 
 
2245
-           list_empty(&dentry->d_subdirs)) {
 
2246
+           __simple_empty(dentry)) {
 
2247
                DPRINTK("dentry=%p %.*s, emptydir",
 
2248
                         dentry, dentry->d_name.len, dentry->d_name.name);
 
2249
                spin_unlock(&dcache_lock);
 
2250
-               if (!oz_mode)
 
2251
-                       status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
 
2252
+
 
2253
+               /* The daemon never causes a mount to trigger */
 
2254
+               if (oz_mode)
 
2255
+                       return 1;
 
2256
+
 
2257
+               /*
 
2258
+                * A zero status is success otherwise we have a
 
2259
+                * negative error code.
 
2260
+                */
 
2261
+               status = try_to_fill_dentry(dentry, flags);
 
2262
+               if (status == 0)
 
2263
+                       return 1;
 
2264
+
 
2265
                return status;
 
2266
        }
 
2267
        spin_unlock(&dcache_lock);
 
2268
 
 
2269
-       /* Update the usage list */
 
2270
-       if (!oz_mode)
 
2271
-               autofs4_update_usage(dentry);
 
2272
-
 
2273
        return 1;
 
2274
 }
 
2275
 
 
2276
-static void autofs4_dentry_release(struct dentry *de)
 
2277
+void autofs4_dentry_release(struct dentry *de)
 
2278
 {
 
2279
        struct autofs_info *inf;
 
2280
 
 
2281
@@ -419,6 +323,17 @@ static void autofs4_dentry_release(struc
 
2282
        de->d_fsdata = NULL;
 
2283
 
 
2284
        if (inf) {
 
2285
+               struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
 
2286
+
 
2287
+               if (sbi) {
 
2288
+                       spin_lock(&sbi->lookup_lock);
 
2289
+                       if (!list_empty(&inf->active))
 
2290
+                               list_del(&inf->active);
 
2291
+                       if (!list_empty(&inf->expiring))
 
2292
+                               list_del(&inf->expiring);
 
2293
+                       spin_unlock(&sbi->lookup_lock);
 
2294
+               }
 
2295
+
 
2296
                inf->dentry = NULL;
 
2297
                inf->inode = NULL;
 
2298
 
 
2299
@@ -438,48 +353,192 @@ static struct dentry_operations autofs4_
 
2300
        .d_release      = autofs4_dentry_release,
 
2301
 };
 
2302
 
 
2303
+static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
 
2304
+{
 
2305
+       unsigned int len = name->len;
 
2306
+       unsigned int hash = name->hash;
 
2307
+       const unsigned char *str = name->name;
 
2308
+       struct list_head *p, *head;
 
2309
+
 
2310
+       spin_lock(&dcache_lock);
 
2311
+       spin_lock(&sbi->lookup_lock);
 
2312
+       head = &sbi->active_list;
 
2313
+       list_for_each(p, head) {
 
2314
+               struct autofs_info *ino;
 
2315
+               struct dentry *dentry;
 
2316
+               struct qstr *qstr;
 
2317
+
 
2318
+               ino = list_entry(p, struct autofs_info, active);
 
2319
+               dentry = ino->dentry;
 
2320
+
 
2321
+               spin_lock(&dentry->d_lock);
 
2322
+
 
2323
+               /* Already gone? */
 
2324
+               if (atomic_read(&dentry->d_count) == 0)
 
2325
+                       goto next;
 
2326
+
 
2327
+               qstr = &dentry->d_name;
 
2328
+
 
2329
+               if (dentry->d_name.hash != hash)
 
2330
+                       goto next;
 
2331
+               if (dentry->d_parent != parent)
 
2332
+                       goto next;
 
2333
+
 
2334
+               if (qstr->len != len)
 
2335
+                       goto next;
 
2336
+               if (memcmp(qstr->name, str, len))
 
2337
+                       goto next;
 
2338
+
 
2339
+               if (d_unhashed(dentry)) {
 
2340
+                       dget(dentry);
 
2341
+                       spin_unlock(&dentry->d_lock);
 
2342
+                       spin_unlock(&sbi->lookup_lock);
 
2343
+                       spin_unlock(&dcache_lock);
 
2344
+                       return dentry;
 
2345
+               }
 
2346
+next:
 
2347
+               spin_unlock(&dentry->d_lock);
 
2348
+       }
 
2349
+       spin_unlock(&sbi->lookup_lock);
 
2350
+       spin_unlock(&dcache_lock);
 
2351
+
 
2352
+       return NULL;
 
2353
+}
 
2354
+
 
2355
+static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
 
2356
+{
 
2357
+       unsigned int len = name->len;
 
2358
+       unsigned int hash = name->hash;
 
2359
+       const unsigned char *str = name->name;
 
2360
+       struct list_head *p, *head;
 
2361
+
 
2362
+       spin_lock(&dcache_lock);
 
2363
+       spin_lock(&sbi->lookup_lock);
 
2364
+       head = &sbi->expiring_list;
 
2365
+       list_for_each(p, head) {
 
2366
+               struct autofs_info *ino;
 
2367
+               struct dentry *dentry;
 
2368
+               struct qstr *qstr;
 
2369
+
 
2370
+               ino = list_entry(p, struct autofs_info, expiring);
 
2371
+               dentry = ino->dentry;
 
2372
+
 
2373
+               spin_lock(&dentry->d_lock);
 
2374
+
 
2375
+               /* Bad luck, we've already been dentry_iput */
 
2376
+               if (!dentry->d_inode)
 
2377
+                       goto next;
 
2378
+
 
2379
+               qstr = &dentry->d_name;
 
2380
+
 
2381
+               if (dentry->d_name.hash != hash)
 
2382
+                       goto next;
 
2383
+               if (dentry->d_parent != parent)
 
2384
+                       goto next;
 
2385
+
 
2386
+               if (qstr->len != len)
 
2387
+                       goto next;
 
2388
+               if (memcmp(qstr->name, str, len))
 
2389
+                       goto next;
 
2390
+
 
2391
+               if (d_unhashed(dentry)) {
 
2392
+                       dget(dentry);
 
2393
+                       spin_unlock(&dentry->d_lock);
 
2394
+                       spin_unlock(&sbi->lookup_lock);
 
2395
+                       spin_unlock(&dcache_lock);
 
2396
+                       return dentry;
 
2397
+               }
 
2398
+next:
 
2399
+               spin_unlock(&dentry->d_lock);
 
2400
+       }
 
2401
+       spin_unlock(&sbi->lookup_lock);
 
2402
+       spin_unlock(&dcache_lock);
 
2403
+
 
2404
+       return NULL;
 
2405
+}
 
2406
+
 
2407
 /* Lookups in the root directory */
 
2408
 static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
 
2409
 {
 
2410
        struct autofs_sb_info *sbi;
 
2411
+       struct autofs_info *ino;
 
2412
+       struct dentry *expiring, *unhashed;
 
2413
        int oz_mode;
 
2414
 
 
2415
        DPRINTK("name = %.*s",
 
2416
                dentry->d_name.len, dentry->d_name.name);
 
2417
 
 
2418
+       /* File name too long to exist */
 
2419
        if (dentry->d_name.len > NAME_MAX)
 
2420
-               return ERR_PTR(-ENAMETOOLONG);/* File name too long to exist */
 
2421
+               return ERR_PTR(-ENAMETOOLONG);
 
2422
 
 
2423
        sbi = autofs4_sbi(dir->i_sb);
 
2424
-
 
2425
        oz_mode = autofs4_oz_mode(sbi);
 
2426
+
 
2427
        DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
 
2428
                 current->pid, process_group(current), sbi->catatonic, oz_mode);
 
2429
 
 
2430
-       /*
 
2431
-        * Mark the dentry incomplete, but add it. This is needed so
 
2432
-        * that the VFS layer knows about the dentry, and we can count
 
2433
-        * on catching any lookups through the revalidate.
 
2434
-        *
 
2435
-        * Let all the hard work be done by the revalidate function that
 
2436
-        * needs to be able to do this anyway..
 
2437
-        *
 
2438
-        * We need to do this before we release the directory semaphore.
 
2439
-        */
 
2440
-       dentry->d_op = &autofs4_root_dentry_operations;
 
2441
+       expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
 
2442
+       if (expiring) {
 
2443
+               /*
 
2444
+                * If we are racing with expire the request might not
 
2445
+                * be quite complete but the directory has been removed
 
2446
+                * so it must have been successful, so just wait for it.
 
2447
+                */
 
2448
+               ino = autofs4_dentry_ino(expiring);
 
2449
+               autofs4_expire_wait(expiring);
 
2450
+               spin_lock(&sbi->lookup_lock);
 
2451
+               if (!list_empty(&ino->expiring))
 
2452
+                       list_del_init(&ino->expiring);
 
2453
+               spin_unlock(&sbi->lookup_lock);
 
2454
+               dput(expiring);
 
2455
+       }
 
2456
+
 
2457
+       unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
 
2458
+       if (unhashed)
 
2459
+               dentry = unhashed;
 
2460
+       else {
 
2461
+               /*
 
2462
+                * Mark the dentry incomplete but don't hash it. We do this
 
2463
+                * to serialize our inode creation operations (symlink and
 
2464
+                * mkdir) which prevents deadlock during the callback to
 
2465
+                * the daemon. Subsequent user space lookups for the same
 
2466
+                * dentry are placed on the wait queue while the daemon
 
2467
+                * itself is allowed passage unresticted so the create
 
2468
+                * operation itself can then hash the dentry. Finally,
 
2469
+                * we check for the hashed dentry and return the newly
 
2470
+                * hashed dentry.
 
2471
+                */
 
2472
+               dentry->d_op = &autofs4_root_dentry_operations;
 
2473
+
 
2474
+               /*
 
2475
+                * And we need to ensure that the same dentry is used for
 
2476
+                * all following lookup calls until it is hashed so that
 
2477
+                * the dentry flags are persistent throughout the request.
 
2478
+                */
 
2479
+               ino = autofs4_init_ino(NULL, sbi, 0555);
 
2480
+               if (!ino)
 
2481
+                       return ERR_PTR(-ENOMEM);
 
2482
+
 
2483
+               dentry->d_fsdata = ino;
 
2484
+               ino->dentry = dentry;
 
2485
+
 
2486
+               spin_lock(&sbi->lookup_lock);
 
2487
+               list_add(&ino->active, &sbi->active_list);
 
2488
+               spin_unlock(&sbi->lookup_lock);
 
2489
+
 
2490
+               d_instantiate(dentry, NULL);
 
2491
+       }
 
2492
 
 
2493
        if (!oz_mode) {
 
2494
                spin_lock(&dentry->d_lock);
 
2495
                dentry->d_flags |= DCACHE_AUTOFS_PENDING;
 
2496
                spin_unlock(&dentry->d_lock);
 
2497
-       }
 
2498
-       dentry->d_fsdata = NULL;
 
2499
-       d_add(dentry, NULL);
 
2500
-
 
2501
-       if (dentry->d_op && dentry->d_op->d_revalidate) {
 
2502
-               up(&dir->i_sem);
 
2503
-               (dentry->d_op->d_revalidate)(dentry, nd);
 
2504
-               down(&dir->i_sem);
 
2505
+               if (dentry->d_op && dentry->d_op->d_revalidate) {
 
2506
+                       up(&dir->i_sem);
 
2507
+                       (dentry->d_op->d_revalidate)(dentry, nd);
 
2508
+                       down(&dir->i_sem);
 
2509
+               }
 
2510
        }
 
2511
 
 
2512
        /*
 
2513
@@ -493,19 +552,47 @@ static struct dentry *autofs4_lookup(str
 
2514
                        if (sigismember (sigset, SIGKILL) ||
 
2515
                            sigismember (sigset, SIGQUIT) ||
 
2516
                            sigismember (sigset, SIGINT)) {
 
2517
+                           if (unhashed)
 
2518
+                               dput(unhashed);
 
2519
                            return ERR_PTR(-ERESTARTNOINTR);
 
2520
                        }
 
2521
                }
 
2522
+               if (!oz_mode) {
 
2523
+                       spin_lock(&dentry->d_lock);
 
2524
+                       dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
 
2525
+                       spin_unlock(&dentry->d_lock);
 
2526
+               }
 
2527
        }
 
2528
 
 
2529
        /*
 
2530
         * If this dentry is unhashed, then we shouldn't honour this
 
2531
-        * lookup even if the dentry is positive.  Returning ENOENT here
 
2532
-        * doesn't do the right thing for all system calls, but it should
 
2533
-        * be OK for the operations we permit from an autofs.
 
2534
+        * lookup.  Returning ENOENT here doesn't do the right thing
 
2535
+        * for all system calls, but it should be OK for the operations
 
2536
+        * we permit from an autofs.
 
2537
         */
 
2538
-       if ( dentry->d_inode && d_unhashed(dentry) )
 
2539
-               return ERR_PTR(-ENOENT);
 
2540
+       if (!oz_mode && d_unhashed(dentry)) {
 
2541
+               /*
 
2542
+                * A user space application can (and has done in the past)
 
2543
+                * remove and re-create this directory during the callback.
 
2544
+                * This can leave us with an unhashed dentry, but a
 
2545
+                * successful mount!  So we need to perform another
 
2546
+                * cached lookup in case the dentry now exists.
 
2547
+                */
 
2548
+               struct dentry *parent = dentry->d_parent;
 
2549
+               struct dentry *new = d_lookup(parent, &dentry->d_name);
 
2550
+               if (new != NULL)
 
2551
+                       dentry = new;
 
2552
+               else
 
2553
+                       dentry = ERR_PTR(-ENOENT);
 
2554
+
 
2555
+               if (unhashed)
 
2556
+                       dput(unhashed);
 
2557
+
 
2558
+               return dentry;
 
2559
+       }
 
2560
+
 
2561
+       if (unhashed)
 
2562
+               return unhashed;
 
2563
 
 
2564
        return NULL;
 
2565
 }
 
2566
@@ -516,6 +603,7 @@ static int autofs4_dir_symlink(struct in
 
2567
 {
 
2568
        struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
 
2569
        struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
2570
+       struct autofs_info *p_ino;
 
2571
        struct inode *inode;
 
2572
        char *cp;
 
2573
 
 
2574
@@ -526,21 +614,32 @@ static int autofs4_dir_symlink(struct in
 
2575
                return -EACCES;
 
2576
 
 
2577
        ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
 
2578
-       if (ino == NULL)
 
2579
-               return -ENOSPC;
 
2580
+       if (!ino)
 
2581
+               return -ENOMEM;
 
2582
 
 
2583
-       ino->size = strlen(symname);
 
2584
-       ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
 
2585
+       spin_lock(&sbi->lookup_lock);
 
2586
+       if (!list_empty(&ino->active))
 
2587
+               list_del_init(&ino->active);
 
2588
+       spin_unlock(&sbi->lookup_lock);
 
2589
 
 
2590
-       if (cp == NULL) {
 
2591
-               kfree(ino);
 
2592
-               return -ENOSPC;
 
2593
+       ino->size = strlen(symname);
 
2594
+       cp = kmalloc(ino->size + 1, GFP_KERNEL);
 
2595
+       if (!cp) {
 
2596
+               if (!dentry->d_fsdata)
 
2597
+                       kfree(ino);
 
2598
+               return -ENOMEM;
 
2599
        }
 
2600
 
 
2601
        strcpy(cp, symname);
 
2602
 
 
2603
        inode = autofs4_get_inode(dir->i_sb, ino);
 
2604
-       d_instantiate(dentry, inode);
 
2605
+       if (!inode) {
 
2606
+               kfree(cp);
 
2607
+               if (!dentry->d_fsdata)
 
2608
+                       kfree(ino);
 
2609
+               return -ENOMEM;
 
2610
+       }
 
2611
+       d_add(dentry, inode);
 
2612
 
 
2613
        if (dir == dir->i_sb->s_root->d_inode)
 
2614
                dentry->d_op = &autofs4_root_dentry_operations;
 
2615
@@ -549,8 +648,13 @@ static int autofs4_dir_symlink(struct in
 
2616
 
 
2617
        dentry->d_fsdata = ino;
 
2618
        ino->dentry = dget(dentry);
 
2619
+       atomic_inc(&ino->count);
 
2620
+       p_ino = autofs4_dentry_ino(dentry->d_parent);
 
2621
+       if (p_ino && dentry->d_parent != dentry)
 
2622
+               atomic_inc(&p_ino->count);
 
2623
        ino->inode = inode;
 
2624
 
 
2625
+       ino->u.symlink = cp;
 
2626
        dir->i_mtime = CURRENT_TIME;
 
2627
 
 
2628
        return 0;
 
2629
@@ -562,9 +666,9 @@ static int autofs4_dir_symlink(struct in
 
2630
  * Normal filesystems would do a "d_delete()" to tell the VFS dcache
 
2631
  * that the file no longer exists. However, doing that means that the
 
2632
  * VFS layer can turn the dentry into a negative dentry.  We don't want
 
2633
- * this, because since the unlink is probably the result of an expire.
 
2634
- * We simply d_drop it, which allows the dentry lookup to remount it
 
2635
- * if necessary.
 
2636
+ * this, because the unlink is probably the result of an expire.
 
2637
+ * We simply d_drop it and add it to a expiring list in the super block,
 
2638
+ * which allows the dentry lookup to check for an incomplete expire.
 
2639
  *
 
2640
  * If a process is blocked on the dentry waiting for the expire to finish,
 
2641
  * it will invalidate the dentry and try to mount with a new one.
 
2642
@@ -575,11 +679,17 @@ static int autofs4_dir_unlink(struct ino
 
2643
 {
 
2644
        struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
 
2645
        struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
2646
+       struct autofs_info *p_ino;
 
2647
        
 
2648
        /* This allows root to remove symlinks */
 
2649
        if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) )
 
2650
                return -EACCES;
 
2651
 
 
2652
+       if (atomic_dec_and_test(&ino->count)) {
 
2653
+               p_ino = autofs4_dentry_ino(dentry->d_parent);
 
2654
+               if (p_ino && dentry->d_parent != dentry)
 
2655
+                       atomic_dec(&p_ino->count);
 
2656
+       }
 
2657
        dput(ino->dentry);
 
2658
 
 
2659
        dentry->d_inode->i_size = 0;
 
2660
@@ -587,7 +697,13 @@ static int autofs4_dir_unlink(struct ino
 
2661
 
 
2662
        dir->i_mtime = CURRENT_TIME;
 
2663
 
 
2664
-       d_drop(dentry);
 
2665
+       spin_lock(&dcache_lock);
 
2666
+       spin_lock(&sbi->lookup_lock);
 
2667
+       if (list_empty(&ino->expiring))
 
2668
+               list_add(&ino->expiring, &sbi->expiring_list);
 
2669
+       spin_unlock(&sbi->lookup_lock);
 
2670
+       __d_drop(dentry);
 
2671
+       spin_unlock(&dcache_lock);
 
2672
 
 
2673
        return 0;
 
2674
 }
 
2675
@@ -596,7 +712,11 @@ static int autofs4_dir_rmdir(struct inod
 
2676
 {
 
2677
        struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
 
2678
        struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
2679
+       struct autofs_info *p_ino;
 
2680
        
 
2681
+       DPRINTK("dentry %p, removing %.*s",
 
2682
+               dentry, dentry->d_name.len, dentry->d_name.name);
 
2683
+
 
2684
        if (!autofs4_oz_mode(sbi))
 
2685
                return -EACCES;
 
2686
 
 
2687
@@ -605,11 +725,19 @@ static int autofs4_dir_rmdir(struct inod
 
2688
                spin_unlock(&dcache_lock);
 
2689
                return -ENOTEMPTY;
 
2690
        }
 
2691
+       spin_lock(&sbi->lookup_lock);
 
2692
+       if (list_empty(&ino->expiring))
 
2693
+               list_add(&ino->expiring, &sbi->expiring_list);
 
2694
+       spin_unlock(&sbi->lookup_lock);
 
2695
        __d_drop(dentry);
 
2696
        spin_unlock(&dcache_lock);
 
2697
 
 
2698
+       if (atomic_dec_and_test(&ino->count)) {
 
2699
+               p_ino = autofs4_dentry_ino(dentry->d_parent);
 
2700
+               if (p_ino && dentry->d_parent != dentry)
 
2701
+                       atomic_dec(&p_ino->count);
 
2702
+       }
 
2703
        dput(ino->dentry);
 
2704
-
 
2705
        dentry->d_inode->i_size = 0;
 
2706
        dentry->d_inode->i_nlink = 0;
 
2707
 
 
2708
@@ -623,6 +751,7 @@ static int autofs4_dir_mkdir(struct inod
 
2709
 {
 
2710
        struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
 
2711
        struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
2712
+       struct autofs_info *p_ino;
 
2713
        struct inode *inode;
 
2714
 
 
2715
        if ( !autofs4_oz_mode(sbi) )
 
2716
@@ -632,11 +761,21 @@ static int autofs4_dir_mkdir(struct inod
 
2717
                dentry, dentry->d_name.len, dentry->d_name.name);
 
2718
 
 
2719
        ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
 
2720
-       if (ino == NULL)
 
2721
-               return -ENOSPC;
 
2722
+       if (!ino)
 
2723
+               return -ENOMEM;
 
2724
+
 
2725
+       spin_lock(&sbi->lookup_lock);
 
2726
+       if (!list_empty(&ino->active))
 
2727
+               list_del_init(&ino->active);
 
2728
+       spin_unlock(&sbi->lookup_lock);
 
2729
 
 
2730
        inode = autofs4_get_inode(dir->i_sb, ino);
 
2731
-       d_instantiate(dentry, inode);
 
2732
+       if (!inode) {
 
2733
+               if (!dentry->d_fsdata)
 
2734
+                       kfree(ino);
 
2735
+               return -ENOMEM;
 
2736
+       }
 
2737
+       d_add(dentry, inode);
 
2738
 
 
2739
        if (dir == dir->i_sb->s_root->d_inode)
 
2740
                dentry->d_op = &autofs4_root_dentry_operations;
 
2741
@@ -645,6 +784,10 @@ static int autofs4_dir_mkdir(struct inod
 
2742
 
 
2743
        dentry->d_fsdata = ino;
 
2744
        ino->dentry = dget(dentry);
 
2745
+       atomic_inc(&ino->count);
 
2746
+       p_ino = autofs4_dentry_ino(dentry->d_parent);
 
2747
+       if (p_ino && dentry->d_parent != dentry)
 
2748
+               atomic_inc(&p_ino->count);
 
2749
        ino->inode = inode;
 
2750
        dir->i_nlink++;
 
2751
        dir->i_mtime = CURRENT_TIME;
 
2752
@@ -684,51 +827,13 @@ static inline int autofs4_get_protosubve
 
2753
 }
 
2754
 
 
2755
 /*
 
2756
- * Tells the daemon whether we need to reghost or not. Also, clears
 
2757
- * the reghost_needed flag.
 
2758
- */
 
2759
-static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
 
2760
-{
 
2761
-       int status;
 
2762
-
 
2763
-       DPRINTK("returning %d", sbi->needs_reghost);
 
2764
-
 
2765
-       status = put_user(sbi->needs_reghost, p);
 
2766
-       if ( status )
 
2767
-               return status;
 
2768
-
 
2769
-       sbi->needs_reghost = 0;
 
2770
-       return 0;
 
2771
-}
 
2772
-
 
2773
-/*
 
2774
- * Enable / Disable reghosting ioctl() operation
 
2775
- */
 
2776
-static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
 
2777
-{
 
2778
-       int status;
 
2779
-       int val;
 
2780
-
 
2781
-       status = get_user(val, p);
 
2782
-
 
2783
-       DPRINTK("reghost = %d", val);
 
2784
-
 
2785
-       if (status)
 
2786
-               return status;
 
2787
-
 
2788
-       /* turn on/off reghosting, with the val */
 
2789
-       sbi->reghost_enabled = val;
 
2790
-       return 0;
 
2791
-}
 
2792
-
 
2793
-/*
 
2794
 * Tells the daemon whether it can umount the autofs mount.
 
2795
 */
 
2796
 static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
 
2797
 {
 
2798
        int status = 0;
 
2799
 
 
2800
-       if (may_umount(mnt) == 0)
 
2801
+       if (may_umount(mnt))
 
2802
                status = 1;
 
2803
 
 
2804
        DPRINTK("returning %d", status);
 
2805
@@ -785,11 +890,6 @@ static int autofs4_root_ioctl(struct ino
 
2806
        case AUTOFS_IOC_SETTIMEOUT:
 
2807
                return autofs4_get_set_timeout(sbi, p);
 
2808
 
 
2809
-       case AUTOFS_IOC_TOGGLEREGHOST:
 
2810
-               return autofs4_toggle_reghost(sbi, p);
 
2811
-       case AUTOFS_IOC_ASKREGHOST:
 
2812
-               return autofs4_ask_reghost(sbi, p);
 
2813
-
 
2814
        case AUTOFS_IOC_ASKUMOUNT:
 
2815
                return autofs4_ask_umount(filp->f_vfsmnt, p);
 
2816
 
 
2817
Index: linux-2.6.11/fs/autofs/dirhash.c
 
2818
===================================================================
 
2819
--- linux-2.6.11.orig/fs/autofs/dirhash.c
 
2820
+++ linux-2.6.11/fs/autofs/dirhash.c
 
2821
@@ -92,7 +92,7 @@ struct autofs_dir_ent *autofs_expire(str
 
2822
                        ;
 
2823
                dput(dentry);
 
2824
 
 
2825
-               if ( may_umount(mnt) == 0 ) {
 
2826
+               if ( may_umount(mnt) ) {
 
2827
                        mntput(mnt);
 
2828
                        DPRINTK(("autofs: signaling expire on %s\n", ent->name));
 
2829
                        return ent; /* Expirable! */
 
2830
Index: linux-2.6.11/fs/namespace.c
 
2831
===================================================================
 
2832
--- linux-2.6.11.orig/fs/namespace.c
 
2833
+++ linux-2.6.11/fs/namespace.c
 
2834
@@ -308,9 +308,9 @@ resume:
 
2835
        spin_unlock(&vfsmount_lock);
 
2836
 
 
2837
        if (actual_refs > minimum_refs)
 
2838
-               return -EBUSY;
 
2839
+               return 0;
 
2840
 
 
2841
-       return 0;
 
2842
+       return 1;
 
2843
 }
 
2844
 
 
2845
 EXPORT_SYMBOL(may_umount_tree);
 
2846
@@ -330,9 +330,10 @@ EXPORT_SYMBOL(may_umount_tree);
 
2847
  */
 
2848
 int may_umount(struct vfsmount *mnt)
 
2849
 {
 
2850
+       int ret = 1;
 
2851
        if (atomic_read(&mnt->mnt_count) > 2)
 
2852
-               return -EBUSY;
 
2853
-       return 0;
 
2854
+               ret = 0;
 
2855
+       return ret;
 
2856
 }
 
2857
 
 
2858
 EXPORT_SYMBOL(may_umount);
 
2859
Index: linux-2.6.11/fs/namei.c
 
2860
===================================================================
 
2861
--- linux-2.6.11.orig/fs/namei.c
 
2862
+++ linux-2.6.11/fs/namei.c
 
2863
@@ -306,6 +306,29 @@ void path_release_on_umount(struct namei
 
2864
        _mntput(nd->mnt);
 
2865
 }
 
2866
 
 
2867
+static inline struct dentry *do_revalidate(struct dentry *dentry, struct nameidata *nd)
 
2868
+{
 
2869
+       int status = dentry->d_op->d_revalidate(dentry, nd);
 
2870
+       if (unlikely(status <= 0)) {
 
2871
+               /*
 
2872
+                * The dentry failed validation.
 
2873
+                * If d_revalidate returned 0 attempt to invalidate
 
2874
+                * the dentry otherwise d_revalidate is asking us
 
2875
+                * to return a fail status.
 
2876
+                */
 
2877
+               if (!status) {
 
2878
+                       if (!d_invalidate(dentry)) {
 
2879
+                               dput(dentry);
 
2880
+                               dentry = NULL;
 
2881
+                       }
 
2882
+               } else {
 
2883
+                       dput(dentry);
 
2884
+                       dentry = ERR_PTR(status);
 
2885
+               }
 
2886
+       }
 
2887
+       return dentry;
 
2888
+}
 
2889
+
 
2890
 /*
 
2891
  * Internal lookup() using the new generic dcache.
 
2892
  * SMP-safe
 
2893
@@ -320,12 +343,9 @@ static struct dentry * cached_lookup(str
 
2894
        if (!dentry)
 
2895
                dentry = d_lookup(parent, name);
 
2896
 
 
2897
-       if (dentry && dentry->d_op && dentry->d_op->d_revalidate) {
 
2898
-               if (!dentry->d_op->d_revalidate(dentry, nd) && !d_invalidate(dentry)) {
 
2899
-                       dput(dentry);
 
2900
-                       dentry = NULL;
 
2901
-               }
 
2902
-       }
 
2903
+       if (dentry && dentry->d_op && dentry->d_op->d_revalidate)
 
2904
+               dentry = do_revalidate(dentry, nd);
 
2905
+
 
2906
        return dentry;
 
2907
 }
 
2908
 
 
2909
@@ -418,10 +438,9 @@ static struct dentry * real_lookup(struc
 
2910
         */
 
2911
        up(&dir->i_sem);
 
2912
        if (result->d_op && result->d_op->d_revalidate) {
 
2913
-               if (!result->d_op->d_revalidate(result, nd) && !d_invalidate(result)) {
 
2914
-                       dput(result);
 
2915
+               result = do_revalidate(result, nd);
 
2916
+               if (!result)
 
2917
                        result = ERR_PTR(-ENOENT);
 
2918
-               }
 
2919
        }
 
2920
        return result;
 
2921
 }
 
2922
@@ -662,12 +681,12 @@ need_lookup:
 
2923
        goto done;
 
2924
 
 
2925
 need_revalidate:
 
2926
-       if (dentry->d_op->d_revalidate(dentry, nd))
 
2927
-               goto done;
 
2928
-       if (d_invalidate(dentry))
 
2929
-               goto done;
 
2930
-       dput(dentry);
 
2931
-       goto need_lookup;
 
2932
+       dentry = do_revalidate(dentry, nd);
 
2933
+       if (!dentry)
 
2934
+               goto need_lookup;
 
2935
+       if (IS_ERR(dentry))
 
2936
+               goto fail;
 
2937
+       goto done;
 
2938
 
 
2939
 fail:
 
2940
        return PTR_ERR(dentry);
 
2941
@@ -773,6 +792,11 @@ int fastcall link_path_walk(const char *
 
2942
 
 
2943
                if (inode->i_op->follow_link) {
 
2944
                        mntget(next.mnt);
 
2945
+                       if (next.mnt != nd->mnt) {
 
2946
+                               dput(nd->dentry);
 
2947
+                               nd->mnt = next.mnt;
 
2948
+                               nd->dentry = dget(next.dentry);
 
2949
+                       }
 
2950
                        err = do_follow_link(next.dentry, nd);
 
2951
                        dput(next.dentry);
 
2952
                        mntput(next.mnt);
 
2953
@@ -827,6 +851,11 @@ last_component:
 
2954
                if ((lookup_flags & LOOKUP_FOLLOW)
 
2955
                    && inode && inode->i_op && inode->i_op->follow_link) {
 
2956
                        mntget(next.mnt);
 
2957
+                       if (next.mnt != nd->mnt) {
 
2958
+                               dput(nd->dentry);
 
2959
+                               nd->mnt = next.mnt;
 
2960
+                               nd->dentry = dget(next.dentry);
 
2961
+                       }
 
2962
                        err = do_follow_link(next.dentry, nd);
 
2963
                        dput(next.dentry);
 
2964
                        mntput(next.mnt);
 
2965
Index: linux-2.6.11/fs/autofs/init.c
 
2966
===================================================================
 
2967
--- linux-2.6.11.orig/fs/autofs/init.c
 
2968
+++ linux-2.6.11/fs/autofs/init.c
 
2969
@@ -24,7 +24,7 @@ static struct file_system_type autofs_fs
 
2970
        .owner          = THIS_MODULE,
 
2971
        .name           = "autofs",
 
2972
        .get_sb         = autofs_get_sb,
 
2973
-       .kill_sb        = kill_anon_super,
 
2974
+       .kill_sb        = autofs_kill_sb,
 
2975
 };
 
2976
 
 
2977
 static int __init init_autofs_fs(void)
 
2978
Index: linux-2.6.11/fs/autofs/inode.c
 
2979
===================================================================
 
2980
--- linux-2.6.11.orig/fs/autofs/inode.c
 
2981
+++ linux-2.6.11/fs/autofs/inode.c
 
2982
@@ -19,11 +19,20 @@
 
2983
 #include "autofs_i.h"
 
2984
 #include <linux/module.h>
 
2985
 
 
2986
-static void autofs_put_super(struct super_block *sb)
 
2987
+void autofs4_kill_sb(struct super_block *sb)
 
2988
 {
 
2989
        struct autofs_sb_info *sbi = autofs_sbi(sb);
 
2990
        unsigned int n;
 
2991
 
 
2992
+       /*
 
2993
+        * In the event of a failure in get_sb_nodev the superblock
 
2994
+        * info is not present so nothing else has been setup, so
 
2995
+        * just call kill_anon_super when we are called from
 
2996
+        * deactivate_super.
 
2997
+        */
 
2998
+       if (!sbi)
 
2999
+               goto out_kill_sb;
 
3000
+
 
3001
        if ( !sbi->catatonic )
 
3002
                autofs_catatonic_mode(sbi); /* Free wait queues, close pipe */
 
3003
 
 
3004
@@ -35,14 +44,15 @@ static void autofs_put_super(struct supe
 
3005
 
 
3006
        kfree(sb->s_fs_info);
 
3007
 
 
3008
+out_kill_sb:
 
3009
        DPRINTK(("autofs: shutting down\n"));
 
3010
+       kill_anon_super(sb);
 
3011
 }
 
3012
 
 
3013
 static void autofs_read_inode(struct inode *inode);
 
3014
 
 
3015
 static struct super_operations autofs_sops = {
 
3016
        .read_inode     = autofs_read_inode,
 
3017
-       .put_super      = autofs_put_super,
 
3018
        .statfs         = simple_statfs,
 
3019
 };
 
3020
 
 
3021
@@ -136,7 +146,8 @@ int autofs_fill_super(struct super_block
 
3022
 
 
3023
        s->s_fs_info = sbi;
 
3024
        sbi->magic = AUTOFS_SBI_MAGIC;
 
3025
-       sbi->catatonic = 0;
 
3026
+       sbi->pipe = NULL;
 
3027
+       sbi->catatonic = 1;
 
3028
        sbi->exp_timeout = 0;
 
3029
        sbi->oz_pgrp = process_group(current);
 
3030
        autofs_initialize_hash(&sbi->dirhash);
 
3031
@@ -179,6 +190,7 @@ int autofs_fill_super(struct super_block
 
3032
        if ( !pipe->f_op || !pipe->f_op->write )
 
3033
                goto fail_fput;
 
3034
        sbi->pipe = pipe;
 
3035
+       sbi->catatonic = 0;
 
3036
 
 
3037
        /*
 
3038
         * Success! Install the root dentry now to indicate completion.
 
3039
@@ -197,6 +209,7 @@ fail_iput:
 
3040
        iput(root_inode);
 
3041
 fail_free:
 
3042
        kfree(sbi);
 
3043
+       s->s_fs_info = NULL;
 
3044
 fail_unlock:
 
3045
        return -EINVAL;
 
3046
 }
 
3047
Index: linux-2.6.11/fs/autofs/autofs_i.h
 
3048
===================================================================
 
3049
--- linux-2.6.11.orig/fs/autofs/autofs_i.h
 
3050
+++ linux-2.6.11/fs/autofs/autofs_i.h
 
3051
@@ -150,6 +150,7 @@ extern struct file_operations autofs_roo
 
3052
 /* Initializing function */
 
3053
 
 
3054
 int autofs_fill_super(struct super_block *, void *, int);
 
3055
+void autofs_kill_sb(struct super_block *);
 
3056
 
 
3057
 /* Queue management functions */
 
3058
 
 
3059
Index: linux-2.6.11/fs/autofs4/init.c
 
3060
===================================================================
 
3061
--- linux-2.6.11.orig/fs/autofs4/init.c
 
3062
+++ linux-2.6.11/fs/autofs4/init.c
 
3063
@@ -24,7 +24,7 @@ static struct file_system_type autofs_fs
 
3064
        .owner          = THIS_MODULE,
 
3065
        .name           = "autofs",
 
3066
        .get_sb         = autofs_get_sb,
 
3067
-       .kill_sb        = kill_anon_super,
 
3068
+       .kill_sb        = autofs4_kill_sb,
 
3069
 };
 
3070
 
 
3071
 static int __init init_autofs4_fs(void)
 
3072
Index: linux-2.6.11/fs/autofs/waitq.c
 
3073
===================================================================
 
3074
--- linux-2.6.11.orig/fs/autofs/waitq.c
 
3075
+++ linux-2.6.11/fs/autofs/waitq.c
 
3076
@@ -41,6 +41,7 @@ void autofs_catatonic_mode(struct autofs
 
3077
                wq = nwq;
 
3078
        }
 
3079
        fput(sbi->pipe);        /* Close the pipe */
 
3080
+       sbi->pipe = NULL;
 
3081
        autofs_hash_dputall(&sbi->dirhash); /* Remove all dentry pointers */
 
3082
 }
 
3083
 
 
3084
Index: linux-2.6.11/include/linux/compat_ioctl.h
 
3085
===================================================================
 
3086
--- linux-2.6.11.orig/include/linux/compat_ioctl.h
 
3087
+++ linux-2.6.11/include/linux/compat_ioctl.h
 
3088
@@ -565,8 +565,6 @@ COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
 
3089
 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
 
3090
 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
 
3091
 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
 
3092
-COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
 
3093
-COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
 
3094
 COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
 
3095
 /* DEVFS */
 
3096
 COMPATIBLE_IOCTL(DEVFSDIOC_GET_PROTO_REV)