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

« back to all changes in this revision

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