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

« back to all changes in this revision

Viewing changes to patches/autofs4-2.6.22.17-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.22.17/fs/autofs4/root.c
 
2
===================================================================
 
3
--- linux-2.6.22.17.orig/fs/autofs4/root.c
 
4
+++ linux-2.6.22.17/fs/autofs4/root.c
 
5
@@ -25,25 +25,25 @@ static int autofs4_dir_rmdir(struct inod
 
6
 static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
 
7
 static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
 
8
 static int autofs4_dir_open(struct inode *inode, struct file *file);
 
9
-static int autofs4_dir_close(struct inode *inode, struct file *file);
 
10
-static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir);
 
11
-static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
 
12
 static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
 
13
 static void *autofs4_follow_link(struct dentry *, struct nameidata *);
 
14
 
 
15
+#define TRIGGER_FLAGS   (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
 
16
+#define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
 
17
+
 
18
 const struct file_operations autofs4_root_operations = {
 
19
        .open           = dcache_dir_open,
 
20
        .release        = dcache_dir_close,
 
21
        .read           = generic_read_dir,
 
22
-       .readdir        = autofs4_root_readdir,
 
23
+       .readdir        = dcache_readdir,
 
24
        .ioctl          = autofs4_root_ioctl,
 
25
 };
 
26
 
 
27
 const struct file_operations autofs4_dir_operations = {
 
28
        .open           = autofs4_dir_open,
 
29
-       .release        = autofs4_dir_close,
 
30
+       .release        = dcache_dir_close,
 
31
        .read           = generic_read_dir,
 
32
-       .readdir        = autofs4_dir_readdir,
 
33
+       .readdir        = dcache_readdir,
 
34
 };
 
35
 
 
36
 const struct inode_operations autofs4_indirect_root_inode_operations = {
 
37
@@ -70,42 +70,10 @@ const struct inode_operations autofs4_di
 
38
        .rmdir          = autofs4_dir_rmdir,
 
39
 };
 
40
 
 
41
-static int autofs4_root_readdir(struct file *file, void *dirent,
 
42
-                               filldir_t filldir)
 
43
-{
 
44
-       struct autofs_sb_info *sbi = autofs4_sbi(file->f_path.dentry->d_sb);
 
45
-       int oz_mode = autofs4_oz_mode(sbi);
 
46
-
 
47
-       DPRINTK("called, filp->f_pos = %lld", file->f_pos);
 
48
-
 
49
-       /*
 
50
-        * Don't set reghost flag if:
 
51
-        * 1) f_pos is larger than zero -- we've already been here.
 
52
-        * 2) we haven't even enabled reghosting in the 1st place.
 
53
-        * 3) this is the daemon doing a readdir
 
54
-        */
 
55
-       if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
 
56
-               sbi->needs_reghost = 1;
 
57
-
 
58
-       DPRINTK("needs_reghost = %d", sbi->needs_reghost);
 
59
-
 
60
-       return dcache_readdir(file, dirent, filldir);
 
61
-}
 
62
-
 
63
 static int autofs4_dir_open(struct inode *inode, struct file *file)
 
64
 {
 
65
        struct dentry *dentry = file->f_path.dentry;
 
66
-       struct vfsmount *mnt = file->f_path.mnt;
 
67
        struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
68
-       struct dentry *cursor;
 
69
-       int status;
 
70
-
 
71
-       status = dcache_dir_open(inode, file);
 
72
-       if (status)
 
73
-               goto out;
 
74
-
 
75
-       cursor = file->private_data;
 
76
-       cursor->d_fsdata = NULL;
 
77
 
 
78
        DPRINTK("file=%p dentry=%p %.*s",
 
79
                file, dentry, dentry->d_name.len, dentry->d_name.name);
 
80
@@ -113,157 +81,31 @@ static int autofs4_dir_open(struct inode
 
81
        if (autofs4_oz_mode(sbi))
 
82
                goto out;
 
83
 
 
84
-       if (autofs4_ispending(dentry)) {
 
85
-               DPRINTK("dentry busy");
 
86
-               dcache_dir_close(inode, file);
 
87
-               status = -EBUSY;
 
88
-               goto out;
 
89
-       }
 
90
-
 
91
-       status = -ENOENT;
 
92
-       if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) {
 
93
-               struct nameidata nd;
 
94
-               int empty, ret;
 
95
-
 
96
-               /* In case there are stale directory dentrys from a failed mount */
 
97
-               spin_lock(&dcache_lock);
 
98
-               empty = list_empty(&dentry->d_subdirs);
 
99
+       /*
 
100
+        * An empty directory in an autofs file system is always a
 
101
+        * mount point. The daemon must have failed to mount this
 
102
+        * during lookup so it doesn't exist. This can happen, for
 
103
+        * example, if user space returns an incorrect status for a
 
104
+        * mount request. Otherwise we're doing a readdir on the
 
105
+        * autofs file system so just let the libfs routines handle
 
106
+        * it.
 
107
+        */
 
108
+       spin_lock(&dcache_lock);
 
109
+       if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
 
110
                spin_unlock(&dcache_lock);
 
111
-
 
112
-               if (!empty)
 
113
-                       d_invalidate(dentry);
 
114
-
 
115
-               nd.flags = LOOKUP_DIRECTORY;
 
116
-               ret = (dentry->d_op->d_revalidate)(dentry, &nd);
 
117
-
 
118
-               if (ret <= 0) {
 
119
-                       if (ret < 0)
 
120
-                               status = ret;
 
121
-                       dcache_dir_close(inode, file);
 
122
-                       goto out;
 
123
-               }
 
124
-       }
 
125
-
 
126
-       if (d_mountpoint(dentry)) {
 
127
-               struct file *fp = NULL;
 
128
-               struct vfsmount *fp_mnt = mntget(mnt);
 
129
-               struct dentry *fp_dentry = dget(dentry);
 
130
-
 
131
-               if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) {
 
132
-                       dput(fp_dentry);
 
133
-                       mntput(fp_mnt);
 
134
-                       dcache_dir_close(inode, file);
 
135
-                       goto out;
 
136
-               }
 
137
-
 
138
-               fp = dentry_open(fp_dentry, fp_mnt, file->f_flags);
 
139
-               status = PTR_ERR(fp);
 
140
-               if (IS_ERR(fp)) {
 
141
-                       dcache_dir_close(inode, file);
 
142
-                       goto out;
 
143
-               }
 
144
-               cursor->d_fsdata = fp;
 
145
-       }
 
146
-       return 0;
 
147
-out:
 
148
-       return status;
 
149
-}
 
150
-
 
151
-static int autofs4_dir_close(struct inode *inode, struct file *file)
 
152
-{
 
153
-       struct dentry *dentry = file->f_path.dentry;
 
154
-       struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
155
-       struct dentry *cursor = file->private_data;
 
156
-       int status = 0;
 
157
-
 
158
-       DPRINTK("file=%p dentry=%p %.*s",
 
159
-               file, dentry, dentry->d_name.len, dentry->d_name.name);
 
160
-
 
161
-       if (autofs4_oz_mode(sbi))
 
162
-               goto out;
 
163
-
 
164
-       if (autofs4_ispending(dentry)) {
 
165
-               DPRINTK("dentry busy");
 
166
-               status = -EBUSY;
 
167
-               goto out;
 
168
-       }
 
169
-
 
170
-       if (d_mountpoint(dentry)) {
 
171
-               struct file *fp = cursor->d_fsdata;
 
172
-               if (!fp) {
 
173
-                       status = -ENOENT;
 
174
-                       goto out;
 
175
-               }
 
176
-               filp_close(fp, current->files);
 
177
+               return -ENOENT;
 
178
        }
 
179
-out:
 
180
-       dcache_dir_close(inode, file);
 
181
-       return status;
 
182
-}
 
183
-
 
184
-static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
 
185
-{
 
186
-       struct dentry *dentry = file->f_path.dentry;
 
187
-       struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
188
-       struct dentry *cursor = file->private_data;
 
189
-       int status;
 
190
-
 
191
-       DPRINTK("file=%p dentry=%p %.*s",
 
192
-               file, dentry, dentry->d_name.len, dentry->d_name.name);
 
193
-
 
194
-       if (autofs4_oz_mode(sbi))
 
195
-               goto out;
 
196
-
 
197
-       if (autofs4_ispending(dentry)) {
 
198
-               DPRINTK("dentry busy");
 
199
-               return -EBUSY;
 
200
-       }
 
201
-
 
202
-       if (d_mountpoint(dentry)) {
 
203
-               struct file *fp = cursor->d_fsdata;
 
204
-
 
205
-               if (!fp)
 
206
-                       return -ENOENT;
 
207
-
 
208
-               if (!fp->f_op || !fp->f_op->readdir)
 
209
-                       goto out;
 
210
+       spin_unlock(&dcache_lock);
 
211
 
 
212
-               status = vfs_readdir(fp, filldir, dirent);
 
213
-               file->f_pos = fp->f_pos;
 
214
-               if (status)
 
215
-                       autofs4_copy_atime(file, fp);
 
216
-               return status;
 
217
-       }
 
218
 out:
 
219
-       return dcache_readdir(file, dirent, filldir);
 
220
+       return dcache_dir_open(inode, file);
 
221
 }
 
222
 
 
223
 static int try_to_fill_dentry(struct dentry *dentry, int flags)
 
224
 {
 
225
        struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
226
        struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
227
-       int status = 0;
 
228
-
 
229
-       /* Block on any pending expiry here; invalidate the dentry
 
230
-           when expiration is done to trigger mount request with a new
 
231
-           dentry */
 
232
-       if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
 
233
-               DPRINTK("waiting for expire %p name=%.*s",
 
234
-                        dentry, dentry->d_name.len, dentry->d_name.name);
 
235
-
 
236
-               status = autofs4_wait(sbi, dentry, NFY_NONE);
 
237
-
 
238
-               DPRINTK("expire done status=%d", status);
 
239
-
 
240
-               /*
 
241
-                * If the directory still exists the mount request must
 
242
-                * continue otherwise it can't be followed at the right
 
243
-                * time during the walk.
 
244
-                */
 
245
-               status = d_invalidate(dentry);
 
246
-               if (status != -EBUSY)
 
247
-                       return -EAGAIN;
 
248
-       }
 
249
+       int status;
 
250
 
 
251
        DPRINTK("dentry=%p %.*s ino=%p",
 
252
                 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
 
253
@@ -291,7 +133,8 @@ static int try_to_fill_dentry(struct den
 
254
                        return status;
 
255
                }
 
256
        /* Trigger mount for path component or follow link */
 
257
-       } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) ||
 
258
+       } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
 
259
+                       flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
 
260
                        current->link_count) {
 
261
                DPRINTK("waiting for mount name=%.*s",
 
262
                        dentry->d_name.len, dentry->d_name.name);
 
263
@@ -318,7 +161,8 @@ static int try_to_fill_dentry(struct den
 
264
        spin_lock(&dentry->d_lock);
 
265
        dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
 
266
        spin_unlock(&dentry->d_lock);
 
267
-       return status;
 
268
+
 
269
+       return 0;
 
270
 }
 
271
 
 
272
 /* For autofs direct mounts the follow link triggers the mount */
 
273
@@ -333,50 +177,62 @@ static void *autofs4_follow_link(struct 
 
274
        DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
 
275
                dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
 
276
                nd->flags);
 
277
-
 
278
-       /* If it's our master or we shouldn't trigger a mount we're done */
 
279
-       lookup_type = nd->flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY);
 
280
-       if (oz_mode || !lookup_type)
 
281
+       /*
 
282
+        * For an expire of a covered direct or offset mount we need
 
283
+        * to beeak out of follow_down() at the autofs mount trigger
 
284
+        * (d_mounted--), so we can see the expiring flag, and manage
 
285
+        * the blocking and following here until the expire is completed.
 
286
+        */
 
287
+       if (oz_mode) {
 
288
+               spin_lock(&sbi->fs_lock);
 
289
+               if (ino->flags & AUTOFS_INF_EXPIRING) {
 
290
+                       spin_unlock(&sbi->fs_lock);
 
291
+                       /* Follow down to our covering mount. */
 
292
+                       if (!follow_down(&nd->mnt, &nd->dentry))
 
293
+                               goto done;
 
294
+                       goto follow;
 
295
+               }
 
296
+               spin_unlock(&sbi->fs_lock);
 
297
                goto done;
 
298
+       }
 
299
 
 
300
-       /* If an expire request is pending wait for it. */
 
301
-       if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
 
302
-               DPRINTK("waiting for active request %p name=%.*s",
 
303
-                       dentry, dentry->d_name.len, dentry->d_name.name);
 
304
-
 
305
-               status = autofs4_wait(sbi, dentry, NFY_NONE);
 
306
+       /* If an expire request is pending everyone must wait. */
 
307
+       autofs4_expire_wait(dentry);
 
308
 
 
309
-               DPRINTK("request done status=%d", status);
 
310
-       }
 
311
+       /* We trigger a mount for almost all flags */
 
312
+       lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
 
313
+       if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
 
314
+               goto follow;
 
315
 
 
316
        /*
 
317
-        * If the dentry contains directories then it is an
 
318
-        * autofs multi-mount with no root mount offset. So
 
319
-        * don't try to mount it again.
 
320
+        * If the dentry contains directories then it is an autofs
 
321
+        * multi-mount with no root mount offset. So don't try to
 
322
+        * mount it again.
 
323
         */
 
324
        spin_lock(&dcache_lock);
 
325
-       if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
 
326
+       if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
 
327
+           (!d_mountpoint(dentry) && __simple_empty(dentry))) {
 
328
                spin_unlock(&dcache_lock);
 
329
 
 
330
                status = try_to_fill_dentry(dentry, 0);
 
331
                if (status)
 
332
                        goto out_error;
 
333
 
 
334
-               /*
 
335
-                * The mount succeeded but if there is no root mount
 
336
-                * it must be an autofs multi-mount with no root offset
 
337
-                * so we don't need to follow the mount.
 
338
-                */
 
339
-               if (d_mountpoint(dentry)) {
 
340
-                       if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
 
341
-                               status = -ENOENT;
 
342
-                               goto out_error;
 
343
-                       }
 
344
-               }
 
345
-
 
346
-               goto done;
 
347
+               goto follow;
 
348
        }
 
349
        spin_unlock(&dcache_lock);
 
350
+follow:
 
351
+       /*
 
352
+        * If there is no root mount it must be an autofs
 
353
+        * multi-mount with no root offset so we don't need
 
354
+        * to follow it.
 
355
+        */
 
356
+       if (d_mountpoint(dentry)) {
 
357
+               if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
 
358
+                       status = -ENOENT;
 
359
+                       goto out_error;
 
360
+               }
 
361
+       }
 
362
 
 
363
 done:
 
364
        return NULL;
 
365
@@ -401,12 +257,23 @@ static int autofs4_revalidate(struct den
 
366
        int status = 1;
 
367
 
 
368
        /* Pending dentry */
 
369
+       spin_lock(&sbi->fs_lock);
 
370
        if (autofs4_ispending(dentry)) {
 
371
                /* The daemon never causes a mount to trigger */
 
372
+               spin_unlock(&sbi->fs_lock);
 
373
+
 
374
                if (oz_mode)
 
375
                        return 1;
 
376
 
 
377
                /*
 
378
+                * If the directory has gone away due to an expire
 
379
+                * we have been called as ->d_revalidate() and so
 
380
+                * we need to return false and proceed to ->lookup().
 
381
+                */
 
382
+               if (autofs4_expire_wait(dentry) == -EAGAIN)
 
383
+                       return 0;
 
384
+
 
385
+               /*
 
386
                 * A zero status is success otherwise we have a
 
387
                 * negative error code.
 
388
                 */
 
389
@@ -414,17 +281,9 @@ static int autofs4_revalidate(struct den
 
390
                if (status == 0)
 
391
                        return 1;
 
392
 
 
393
-               /*
 
394
-                * A status of EAGAIN here means that the dentry has gone
 
395
-                * away while waiting for an expire to complete. If we are
 
396
-                * racing with expire lookup will wait for it so this must
 
397
-                * be a revalidate and we need to send it to lookup.
 
398
-                */
 
399
-               if (status == -EAGAIN)
 
400
-                       return 0;
 
401
-
 
402
                return status;
 
403
        }
 
404
+       spin_unlock(&sbi->fs_lock);
 
405
 
 
406
        /* Negative dentry.. invalidate if "old" */
 
407
        if (dentry->d_inode == NULL)
 
408
@@ -438,6 +297,7 @@ static int autofs4_revalidate(struct den
 
409
                DPRINTK("dentry=%p %.*s, emptydir",
 
410
                         dentry, dentry->d_name.len, dentry->d_name.name);
 
411
                spin_unlock(&dcache_lock);
 
412
+
 
413
                /* The daemon never causes a mount to trigger */
 
414
                if (oz_mode)
 
415
                        return 1;
 
416
@@ -470,10 +330,12 @@ void autofs4_dentry_release(struct dentr
 
417
                struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
 
418
 
 
419
                if (sbi) {
 
420
-                       spin_lock(&sbi->rehash_lock);
 
421
-                       if (!list_empty(&inf->rehash))
 
422
-                               list_del(&inf->rehash);
 
423
-                       spin_unlock(&sbi->rehash_lock);
 
424
+                       spin_lock(&sbi->lookup_lock);
 
425
+                       if (!list_empty(&inf->active))
 
426
+                               list_del(&inf->active);
 
427
+                       if (!list_empty(&inf->expiring))
 
428
+                               list_del(&inf->expiring);
 
429
+                       spin_unlock(&sbi->lookup_lock);
 
430
                }
 
431
 
 
432
                inf->dentry = NULL;
 
433
@@ -495,7 +357,59 @@ static struct dentry_operations autofs4_
 
434
        .d_release      = autofs4_dentry_release,
 
435
 };
 
436
 
 
437
-static struct dentry *autofs4_lookup_unhashed(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
 
438
+static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
 
439
+{
 
440
+       unsigned int len = name->len;
 
441
+       unsigned int hash = name->hash;
 
442
+       const unsigned char *str = name->name;
 
443
+       struct list_head *p, *head;
 
444
+
 
445
+       spin_lock(&dcache_lock);
 
446
+       spin_lock(&sbi->lookup_lock);
 
447
+       head = &sbi->active_list;
 
448
+       list_for_each(p, head) {
 
449
+               struct autofs_info *ino;
 
450
+               struct dentry *dentry;
 
451
+               struct qstr *qstr;
 
452
+
 
453
+               ino = list_entry(p, struct autofs_info, active);
 
454
+               dentry = ino->dentry;
 
455
+
 
456
+               spin_lock(&dentry->d_lock);
 
457
+
 
458
+               /* Already gone? */
 
459
+               if (atomic_read(&dentry->d_count) == 0)
 
460
+                       goto next;
 
461
+
 
462
+               qstr = &dentry->d_name;
 
463
+
 
464
+               if (dentry->d_name.hash != hash)
 
465
+                       goto next;
 
466
+               if (dentry->d_parent != parent)
 
467
+                       goto next;
 
468
+
 
469
+               if (qstr->len != len)
 
470
+                       goto next;
 
471
+               if (memcmp(qstr->name, str, len))
 
472
+                       goto next;
 
473
+
 
474
+               if (d_unhashed(dentry)) {
 
475
+                       dget(dentry);
 
476
+                       spin_unlock(&dentry->d_lock);
 
477
+                       spin_unlock(&sbi->lookup_lock);
 
478
+                       spin_unlock(&dcache_lock);
 
479
+                       return dentry;
 
480
+               }
 
481
+next:
 
482
+               spin_unlock(&dentry->d_lock);
 
483
+       }
 
484
+       spin_unlock(&sbi->lookup_lock);
 
485
+       spin_unlock(&dcache_lock);
 
486
+
 
487
+       return NULL;
 
488
+}
 
489
+
 
490
+static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
 
491
 {
 
492
        unsigned int len = name->len;
 
493
        unsigned int hash = name->hash;
 
494
@@ -503,14 +417,14 @@ static struct dentry *autofs4_lookup_unh
 
495
        struct list_head *p, *head;
 
496
 
 
497
        spin_lock(&dcache_lock);
 
498
-       spin_lock(&sbi->rehash_lock);
 
499
-       head = &sbi->rehash_list;
 
500
+       spin_lock(&sbi->lookup_lock);
 
501
+       head = &sbi->expiring_list;
 
502
        list_for_each(p, head) {
 
503
                struct autofs_info *ino;
 
504
                struct dentry *dentry;
 
505
                struct qstr *qstr;
 
506
 
 
507
-               ino = list_entry(p, struct autofs_info, rehash);
 
508
+               ino = list_entry(p, struct autofs_info, expiring);
 
509
                dentry = ino->dentry;
 
510
 
 
511
                spin_lock(&dentry->d_lock);
 
512
@@ -532,33 +446,16 @@ static struct dentry *autofs4_lookup_unh
 
513
                        goto next;
 
514
 
 
515
                if (d_unhashed(dentry)) {
 
516
-                       struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
517
-                       struct inode *inode = dentry->d_inode;
 
518
-
 
519
-                       list_del_init(&ino->rehash);
 
520
                        dget(dentry);
 
521
-                       /*
 
522
-                        * Make the rehashed dentry negative so the VFS
 
523
-                        * behaves as it should.
 
524
-                        */
 
525
-                       if (inode) {
 
526
-                               dentry->d_inode = NULL;
 
527
-                               list_del_init(&dentry->d_alias);
 
528
-                               spin_unlock(&dentry->d_lock);
 
529
-                               spin_unlock(&sbi->rehash_lock);
 
530
-                               spin_unlock(&dcache_lock);
 
531
-                               iput(inode);
 
532
-                               return dentry;
 
533
-                       }
 
534
                        spin_unlock(&dentry->d_lock);
 
535
-                       spin_unlock(&sbi->rehash_lock);
 
536
+                       spin_unlock(&sbi->lookup_lock);
 
537
                        spin_unlock(&dcache_lock);
 
538
                        return dentry;
 
539
                }
 
540
 next:
 
541
                spin_unlock(&dentry->d_lock);
 
542
        }
 
543
-       spin_unlock(&sbi->rehash_lock);
 
544
+       spin_unlock(&sbi->lookup_lock);
 
545
        spin_unlock(&dcache_lock);
 
546
 
 
547
        return NULL;
 
548
@@ -568,7 +465,8 @@ next:
 
549
 static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
 
550
 {
 
551
        struct autofs_sb_info *sbi;
 
552
-       struct dentry *unhashed;
 
553
+       struct autofs_info *ino;
 
554
+       struct dentry *expiring, *unhashed;
 
555
        int oz_mode;
 
556
 
 
557
        DPRINTK("name = %.*s",
 
558
@@ -584,51 +482,67 @@ static struct dentry *autofs4_lookup(str
 
559
        DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
 
560
                 current->pid, process_group(current), sbi->catatonic, oz_mode);
 
561
 
 
562
-       unhashed = autofs4_lookup_unhashed(sbi, dentry->d_parent, &dentry->d_name);
 
563
-       if (!unhashed) {
 
564
-               /*
 
565
-                * Mark the dentry incomplete, but add it. This is needed so
 
566
-                * that the VFS layer knows about the dentry, and we can count
 
567
-                * on catching any lookups through the revalidate.
 
568
-                *
 
569
-                * Let all the hard work be done by the revalidate function that
 
570
-                * needs to be able to do this anyway..
 
571
-                *
 
572
-                * We need to do this before we release the directory semaphore.
 
573
-                */
 
574
-               dentry->d_op = &autofs4_root_dentry_operations;
 
575
-
 
576
-               dentry->d_fsdata = NULL;
 
577
-               d_add(dentry, NULL);
 
578
-       } else {
 
579
-               struct autofs_info *ino = autofs4_dentry_ino(unhashed);
 
580
-               DPRINTK("rehash %p with %p", dentry, unhashed);
 
581
+       expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
 
582
+       if (expiring) {
 
583
                /*
 
584
                 * If we are racing with expire the request might not
 
585
                 * be quite complete but the directory has been removed
 
586
                 * so it must have been successful, so just wait for it.
 
587
                 */
 
588
-               if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
 
589
-                       DPRINTK("wait for incomplete expire %p name=%.*s",
 
590
-                               unhashed, unhashed->d_name.len,
 
591
-                               unhashed->d_name.name);
 
592
-                       autofs4_wait(sbi, unhashed, NFY_NONE);
 
593
-                       DPRINTK("request completed");
 
594
-               }
 
595
-               d_rehash(unhashed);
 
596
+               ino = autofs4_dentry_ino(expiring);
 
597
+               autofs4_expire_wait(expiring);
 
598
+               spin_lock(&sbi->lookup_lock);
 
599
+               if (!list_empty(&ino->expiring))
 
600
+                       list_del_init(&ino->expiring);
 
601
+               spin_unlock(&sbi->lookup_lock);
 
602
+               dput(expiring);
 
603
+       }
 
604
+
 
605
+       unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
 
606
+       if (unhashed)
 
607
                dentry = unhashed;
 
608
+       else {
 
609
+               /*
 
610
+                * Mark the dentry incomplete but don't hash it. We do this
 
611
+                * to serialize our inode creation operations (symlink and
 
612
+                * mkdir) which prevents deadlock during the callback to
 
613
+                * the daemon. Subsequent user space lookups for the same
 
614
+                * dentry are placed on the wait queue while the daemon
 
615
+                * itself is allowed passage unresticted so the create
 
616
+                * operation itself can then hash the dentry. Finally,
 
617
+                * we check for the hashed dentry and return the newly
 
618
+                * hashed dentry.
 
619
+                */
 
620
+               dentry->d_op = &autofs4_root_dentry_operations;
 
621
+
 
622
+               /*
 
623
+                * And we need to ensure that the same dentry is used for
 
624
+                * all following lookup calls until it is hashed so that
 
625
+                * the dentry flags are persistent throughout the request.
 
626
+                */
 
627
+               ino = autofs4_init_ino(NULL, sbi, 0555);
 
628
+               if (!ino)
 
629
+                       return ERR_PTR(-ENOMEM);
 
630
+
 
631
+               dentry->d_fsdata = ino;
 
632
+               ino->dentry = dentry;
 
633
+
 
634
+               spin_lock(&sbi->lookup_lock);
 
635
+               list_add(&ino->active, &sbi->active_list);
 
636
+               spin_unlock(&sbi->lookup_lock);
 
637
+
 
638
+               d_instantiate(dentry, NULL);
 
639
        }
 
640
 
 
641
        if (!oz_mode) {
 
642
                spin_lock(&dentry->d_lock);
 
643
                dentry->d_flags |= DCACHE_AUTOFS_PENDING;
 
644
                spin_unlock(&dentry->d_lock);
 
645
-       }
 
646
-
 
647
-       if (dentry->d_op && dentry->d_op->d_revalidate) {
 
648
-               mutex_unlock(&dir->i_mutex);
 
649
-               (dentry->d_op->d_revalidate)(dentry, nd);
 
650
-               mutex_lock(&dir->i_mutex);
 
651
+               if (dentry->d_op && dentry->d_op->d_revalidate) {
 
652
+                       mutex_unlock(&dir->i_mutex);
 
653
+                       (dentry->d_op->d_revalidate)(dentry, nd);
 
654
+                       mutex_lock(&dir->i_mutex);
 
655
+               }
 
656
        }
 
657
 
 
658
        /*
 
659
@@ -647,9 +561,11 @@ static struct dentry *autofs4_lookup(str
 
660
                            return ERR_PTR(-ERESTARTNOINTR);
 
661
                        }
 
662
                }
 
663
-               spin_lock(&dentry->d_lock);
 
664
-               dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
 
665
-               spin_unlock(&dentry->d_lock);
 
666
+               if (!oz_mode) {
 
667
+                       spin_lock(&dentry->d_lock);
 
668
+                       dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
 
669
+                       spin_unlock(&dentry->d_lock);
 
670
+               }
 
671
        }
 
672
 
 
673
        /*
 
674
@@ -658,7 +574,7 @@ static struct dentry *autofs4_lookup(str
 
675
         * for all system calls, but it should be OK for the operations
 
676
         * we permit from an autofs.
 
677
         */
 
678
-       if (dentry->d_inode && d_unhashed(dentry)) {
 
679
+       if (!oz_mode && d_unhashed(dentry)) {
 
680
                /*
 
681
                 * A user space application can (and has done in the past)
 
682
                 * remove and re-create this directory during the callback.
 
683
@@ -680,7 +596,7 @@ static struct dentry *autofs4_lookup(str
 
684
        }
 
685
 
 
686
        if (unhashed)
 
687
-               return dentry;
 
688
+               return unhashed;
 
689
 
 
690
        return NULL;
 
691
 }
 
692
@@ -702,21 +618,32 @@ static int autofs4_dir_symlink(struct in
 
693
                return -EACCES;
 
694
 
 
695
        ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
 
696
-       if (ino == NULL)
 
697
-               return -ENOSPC;
 
698
+       if (!ino)
 
699
+               return -ENOMEM;
 
700
 
 
701
-       ino->size = strlen(symname);
 
702
-       ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
 
703
+       spin_lock(&sbi->lookup_lock);
 
704
+       if (!list_empty(&ino->active))
 
705
+               list_del_init(&ino->active);
 
706
+       spin_unlock(&sbi->lookup_lock);
 
707
 
 
708
-       if (cp == NULL) {
 
709
-               kfree(ino);
 
710
-               return -ENOSPC;
 
711
+       ino->size = strlen(symname);
 
712
+       cp = kmalloc(ino->size + 1, GFP_KERNEL);
 
713
+       if (!cp) {
 
714
+               if (!dentry->d_fsdata)
 
715
+                       kfree(ino);
 
716
+               return -ENOMEM;
 
717
        }
 
718
 
 
719
        strcpy(cp, symname);
 
720
 
 
721
        inode = autofs4_get_inode(dir->i_sb, ino);
 
722
-       d_instantiate(dentry, inode);
 
723
+       if (!inode) {
 
724
+               kfree(cp);
 
725
+               if (!dentry->d_fsdata)
 
726
+                       kfree(ino);
 
727
+               return -ENOMEM;
 
728
+       }
 
729
+       d_add(dentry, inode);
 
730
 
 
731
        if (dir == dir->i_sb->s_root->d_inode)
 
732
                dentry->d_op = &autofs4_root_dentry_operations;
 
733
@@ -731,6 +658,7 @@ static int autofs4_dir_symlink(struct in
 
734
                atomic_inc(&p_ino->count);
 
735
        ino->inode = inode;
 
736
 
 
737
+       ino->u.symlink = cp;
 
738
        dir->i_mtime = CURRENT_TIME;
 
739
 
 
740
        return 0;
 
741
@@ -743,9 +671,8 @@ static int autofs4_dir_symlink(struct in
 
742
  * that the file no longer exists. However, doing that means that the
 
743
  * VFS layer can turn the dentry into a negative dentry.  We don't want
 
744
  * this, because the unlink is probably the result of an expire.
 
745
- * We simply d_drop it and add it to a rehash candidates list in the
 
746
- * super block, which allows the dentry lookup to reuse it retaining
 
747
- * the flags, such as expire in progress, in case we're racing with expire.
 
748
+ * We simply d_drop it and add it to a expiring list in the super block,
 
749
+ * which allows the dentry lookup to check for an incomplete expire.
 
750
  *
 
751
  * If a process is blocked on the dentry waiting for the expire to finish,
 
752
  * it will invalidate the dentry and try to mount with a new one.
 
753
@@ -775,9 +702,10 @@ static int autofs4_dir_unlink(struct ino
 
754
        dir->i_mtime = CURRENT_TIME;
 
755
 
 
756
        spin_lock(&dcache_lock);
 
757
-       spin_lock(&sbi->rehash_lock);
 
758
-       list_add(&ino->rehash, &sbi->rehash_list);
 
759
-       spin_unlock(&sbi->rehash_lock);
 
760
+       spin_lock(&sbi->lookup_lock);
 
761
+       if (list_empty(&ino->expiring))
 
762
+               list_add(&ino->expiring, &sbi->expiring_list);
 
763
+       spin_unlock(&sbi->lookup_lock);
 
764
        spin_lock(&dentry->d_lock);
 
765
        __d_drop(dentry);
 
766
        spin_unlock(&dentry->d_lock);
 
767
@@ -803,9 +731,10 @@ static int autofs4_dir_rmdir(struct inod
 
768
                spin_unlock(&dcache_lock);
 
769
                return -ENOTEMPTY;
 
770
        }
 
771
-       spin_lock(&sbi->rehash_lock);
 
772
-       list_add(&ino->rehash, &sbi->rehash_list);
 
773
-       spin_unlock(&sbi->rehash_lock);
 
774
+       spin_lock(&sbi->lookup_lock);
 
775
+       if (list_empty(&ino->expiring))
 
776
+               list_add(&ino->expiring, &sbi->expiring_list);
 
777
+       spin_unlock(&sbi->lookup_lock);
 
778
        spin_lock(&dentry->d_lock);
 
779
        __d_drop(dentry);
 
780
        spin_unlock(&dentry->d_lock);
 
781
@@ -840,11 +769,21 @@ static int autofs4_dir_mkdir(struct inod
 
782
                dentry, dentry->d_name.len, dentry->d_name.name);
 
783
 
 
784
        ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
 
785
-       if (ino == NULL)
 
786
-               return -ENOSPC;
 
787
+       if (!ino)
 
788
+               return -ENOMEM;
 
789
+
 
790
+       spin_lock(&sbi->lookup_lock);
 
791
+       if (!list_empty(&ino->active))
 
792
+               list_del_init(&ino->active);
 
793
+       spin_unlock(&sbi->lookup_lock);
 
794
 
 
795
        inode = autofs4_get_inode(dir->i_sb, ino);
 
796
-       d_instantiate(dentry, inode);
 
797
+       if (!inode) {
 
798
+               if (!dentry->d_fsdata)
 
799
+                       kfree(ino);
 
800
+               return -ENOMEM;
 
801
+       }
 
802
+       d_add(dentry, inode);
 
803
 
 
804
        if (dir == dir->i_sb->s_root->d_inode)
 
805
                dentry->d_op = &autofs4_root_dentry_operations;
 
806
@@ -896,44 +835,6 @@ static inline int autofs4_get_protosubve
 
807
 }
 
808
 
 
809
 /*
 
810
- * Tells the daemon whether we need to reghost or not. Also, clears
 
811
- * the reghost_needed flag.
 
812
- */
 
813
-static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
 
814
-{
 
815
-       int status;
 
816
-
 
817
-       DPRINTK("returning %d", sbi->needs_reghost);
 
818
-
 
819
-       status = put_user(sbi->needs_reghost, p);
 
820
-       if (status)
 
821
-               return status;
 
822
-
 
823
-       sbi->needs_reghost = 0;
 
824
-       return 0;
 
825
-}
 
826
-
 
827
-/*
 
828
- * Enable / Disable reghosting ioctl() operation
 
829
- */
 
830
-static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
 
831
-{
 
832
-       int status;
 
833
-       int val;
 
834
-
 
835
-       status = get_user(val, p);
 
836
-
 
837
-       DPRINTK("reghost = %d", val);
 
838
-
 
839
-       if (status)
 
840
-               return status;
 
841
-
 
842
-       /* turn on/off reghosting, with the val */
 
843
-       sbi->reghost_enabled = val;
 
844
-       return 0;
 
845
-}
 
846
-
 
847
-/*
 
848
 * Tells the daemon whether it can umount the autofs mount.
 
849
 */
 
850
 static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
 
851
@@ -997,11 +898,6 @@ static int autofs4_root_ioctl(struct ino
 
852
        case AUTOFS_IOC_SETTIMEOUT:
 
853
                return autofs4_get_set_timeout(sbi, p);
 
854
 
 
855
-       case AUTOFS_IOC_TOGGLEREGHOST:
 
856
-               return autofs4_toggle_reghost(sbi, p);
 
857
-       case AUTOFS_IOC_ASKREGHOST:
 
858
-               return autofs4_ask_reghost(sbi, p);
 
859
-
 
860
        case AUTOFS_IOC_ASKUMOUNT:
 
861
                return autofs4_ask_umount(filp->f_path.mnt, p);
 
862
 
 
863
Index: linux-2.6.22.17/fs/autofs4/waitq.c
 
864
===================================================================
 
865
--- linux-2.6.22.17.orig/fs/autofs4/waitq.c
 
866
+++ linux-2.6.22.17/fs/autofs4/waitq.c
 
867
@@ -28,6 +28,12 @@ void autofs4_catatonic_mode(struct autof
 
868
 {
 
869
        struct autofs_wait_queue *wq, *nwq;
 
870
 
 
871
+       mutex_lock(&sbi->wq_mutex);
 
872
+       if (sbi->catatonic) {
 
873
+               mutex_unlock(&sbi->wq_mutex);
 
874
+               return;
 
875
+       }
 
876
+
 
877
        DPRINTK("entering catatonic mode");
 
878
 
 
879
        sbi->catatonic = 1;
 
880
@@ -36,13 +42,18 @@ void autofs4_catatonic_mode(struct autof
 
881
        while (wq) {
 
882
                nwq = wq->next;
 
883
                wq->status = -ENOENT; /* Magic is gone - report failure */
 
884
-               kfree(wq->name);
 
885
-               wq->name = NULL;
 
886
+               if (wq->name.name) {
 
887
+                       kfree(wq->name.name);
 
888
+                       wq->name.name = NULL;
 
889
+               }
 
890
+               wq->wait_ctr--;
 
891
                wake_up_interruptible(&wq->queue);
 
892
                wq = nwq;
 
893
        }
 
894
        fput(sbi->pipe);        /* Close the pipe */
 
895
        sbi->pipe = NULL;
 
896
+       sbi->pipefd = -1;
 
897
+       mutex_unlock(&sbi->wq_mutex);
 
898
 }
 
899
 
 
900
 static int autofs4_write(struct file *file, const void *addr, int bytes)
 
901
@@ -89,10 +100,11 @@ static void autofs4_notify_daemon(struct
 
902
                union autofs_packet_union v4_pkt;
 
903
                union autofs_v5_packet_union v5_pkt;
 
904
        } pkt;
 
905
+       struct file *pipe = NULL;
 
906
        size_t pktsz;
 
907
 
 
908
        DPRINTK("wait id = 0x%08lx, name = %.*s, type=%d",
 
909
-               wq->wait_queue_token, wq->len, wq->name, type);
 
910
+               wq->wait_queue_token, wq->name.len, wq->name.name, type);
 
911
 
 
912
        memset(&pkt,0,sizeof pkt); /* For security reasons */
 
913
 
 
914
@@ -107,9 +119,9 @@ static void autofs4_notify_daemon(struct
 
915
                pktsz = sizeof(*mp);
 
916
 
 
917
                mp->wait_queue_token = wq->wait_queue_token;
 
918
-               mp->len = wq->len;
 
919
-               memcpy(mp->name, wq->name, wq->len);
 
920
-               mp->name[wq->len] = '\0';
 
921
+               mp->len = wq->name.len;
 
922
+               memcpy(mp->name, wq->name.name, wq->name.len);
 
923
+               mp->name[wq->name.len] = '\0';
 
924
                break;
 
925
        }
 
926
        case autofs_ptype_expire_multi:
 
927
@@ -119,9 +131,9 @@ static void autofs4_notify_daemon(struct
 
928
                pktsz = sizeof(*ep);
 
929
 
 
930
                ep->wait_queue_token = wq->wait_queue_token;
 
931
-               ep->len = wq->len;
 
932
-               memcpy(ep->name, wq->name, wq->len);
 
933
-               ep->name[wq->len] = '\0';
 
934
+               ep->len = wq->name.len;
 
935
+               memcpy(ep->name, wq->name.name, wq->name.len);
 
936
+               ep->name[wq->name.len] = '\0';
 
937
                break;
 
938
        }
 
939
        /*
 
940
@@ -138,9 +150,9 @@ static void autofs4_notify_daemon(struct
 
941
                pktsz = sizeof(*packet);
 
942
 
 
943
                packet->wait_queue_token = wq->wait_queue_token;
 
944
-               packet->len = wq->len;
 
945
-               memcpy(packet->name, wq->name, wq->len);
 
946
-               packet->name[wq->len] = '\0';
 
947
+               packet->len = wq->name.len;
 
948
+               memcpy(packet->name, wq->name.name, wq->name.len);
 
949
+               packet->name[wq->name.len] = '\0';
 
950
                packet->dev = wq->dev;
 
951
                packet->ino = wq->ino;
 
952
                packet->uid = wq->uid;
 
953
@@ -154,8 +166,19 @@ static void autofs4_notify_daemon(struct
 
954
                return;
 
955
        }
 
956
 
 
957
-       if (autofs4_write(sbi->pipe, &pkt, pktsz))
 
958
-               autofs4_catatonic_mode(sbi);
 
959
+       /* Check if we have become catatonic */
 
960
+       mutex_lock(&sbi->wq_mutex);
 
961
+       if (!sbi->catatonic) {
 
962
+               pipe = sbi->pipe;
 
963
+               get_file(pipe);
 
964
+       }
 
965
+       mutex_unlock(&sbi->wq_mutex);
 
966
+
 
967
+       if (pipe) {
 
968
+               if (autofs4_write(pipe, &pkt, pktsz))
 
969
+                       autofs4_catatonic_mode(sbi);
 
970
+               fput(pipe);
 
971
+       }
 
972
 }
 
973
 
 
974
 static int autofs4_getpath(struct autofs_sb_info *sbi,
 
975
@@ -171,7 +194,7 @@ static int autofs4_getpath(struct autofs
 
976
        for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
 
977
                len += tmp->d_name.len + 1;
 
978
 
 
979
-       if (--len > NAME_MAX) {
 
980
+       if (!len || --len > NAME_MAX) {
 
981
                spin_unlock(&dcache_lock);
 
982
                return 0;
 
983
        }
 
984
@@ -191,58 +214,55 @@ static int autofs4_getpath(struct autofs
 
985
 }
 
986
 
 
987
 static struct autofs_wait_queue *
 
988
-autofs4_find_wait(struct autofs_sb_info *sbi,
 
989
-                 char *name, unsigned int hash, unsigned int len)
 
990
+autofs4_find_wait(struct autofs_sb_info *sbi, struct qstr *qstr)
 
991
 {
 
992
        struct autofs_wait_queue *wq;
 
993
 
 
994
        for (wq = sbi->queues; wq; wq = wq->next) {
 
995
-               if (wq->hash == hash &&
 
996
-                   wq->len == len &&
 
997
-                   wq->name && !memcmp(wq->name, name, len))
 
998
+               if (wq->name.hash == qstr->hash &&
 
999
+                   wq->name.len == qstr->len &&
 
1000
+                   wq->name.name &&
 
1001
+                        !memcmp(wq->name.name, qstr->name, qstr->len))
 
1002
                        break;
 
1003
        }
 
1004
        return wq;
 
1005
 }
 
1006
 
 
1007
-int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
 
1008
-               enum autofs_notify notify)
 
1009
+/*
 
1010
+ * Check if we have a valid request.
 
1011
+ * Returns
 
1012
+ * 1 if the request should continue.
 
1013
+ *   In this case we can return an autofs_wait_queue entry if one is
 
1014
+ *   found or NULL to idicate a new wait needs to be created.
 
1015
+ * 0 or a negative errno if the request shouldn't continue.
 
1016
+ */
 
1017
+static int validate_request(struct autofs_wait_queue **wait,
 
1018
+                           struct autofs_sb_info *sbi,
 
1019
+                           struct qstr *qstr,
 
1020
+                           struct dentry*dentry, enum autofs_notify notify)
 
1021
 {
 
1022
-       struct autofs_info *ino;
 
1023
        struct autofs_wait_queue *wq;
 
1024
-       char *name;
 
1025
-       unsigned int len = 0;
 
1026
-       unsigned int hash = 0;
 
1027
-       int status, type;
 
1028
-
 
1029
-       /* In catatonic mode, we don't wait for nobody */
 
1030
-       if (sbi->catatonic)
 
1031
-               return -ENOENT;
 
1032
-       
 
1033
-       name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
 
1034
-       if (!name)
 
1035
-               return -ENOMEM;
 
1036
+       struct autofs_info *ino;
 
1037
 
 
1038
-       /* If this is a direct mount request create a dummy name */
 
1039
-       if (IS_ROOT(dentry) && (sbi->type & AUTOFS_TYPE_DIRECT))
 
1040
-               len = sprintf(name, "%p", dentry);
 
1041
-       else {
 
1042
-               len = autofs4_getpath(sbi, dentry, &name);
 
1043
-               if (!len) {
 
1044
-                       kfree(name);
 
1045
-                       return -ENOENT;
 
1046
-               }
 
1047
+       /* Wait in progress, continue; */
 
1048
+       wq = autofs4_find_wait(sbi, qstr);
 
1049
+       if (wq) {
 
1050
+               *wait = wq;
 
1051
+               return 1;
 
1052
        }
 
1053
-       hash = full_name_hash(name, len);
 
1054
 
 
1055
-       if (mutex_lock_interruptible(&sbi->wq_mutex)) {
 
1056
-               kfree(name);
 
1057
-               return -EINTR;
 
1058
-       }
 
1059
+       *wait = NULL;
 
1060
 
 
1061
-       wq = autofs4_find_wait(sbi, name, hash, len);
 
1062
+       /* If we don't yet have any info this is a new request */
 
1063
        ino = autofs4_dentry_ino(dentry);
 
1064
-       if (!wq && ino && notify == NFY_NONE) {
 
1065
+       if (!ino)
 
1066
+               return 1;
 
1067
+
 
1068
+       /*
 
1069
+        * If we've been asked to wait on an existing expire (NFY_NONE)
 
1070
+        * but there is no wait in the queue ...
 
1071
+        */
 
1072
+       if (notify == NFY_NONE) {
 
1073
                /*
 
1074
                 * Either we've betean the pending expire to post it's
 
1075
                 * wait or it finished while we waited on the mutex.
 
1076
@@ -253,13 +273,14 @@ int autofs4_wait(struct autofs_sb_info *
 
1077
                while (ino->flags & AUTOFS_INF_EXPIRING) {
 
1078
                        mutex_unlock(&sbi->wq_mutex);
 
1079
                        schedule_timeout_interruptible(HZ/10);
 
1080
-                       if (mutex_lock_interruptible(&sbi->wq_mutex)) {
 
1081
-                               kfree(name);
 
1082
+                       if (mutex_lock_interruptible(&sbi->wq_mutex))
 
1083
                                return -EINTR;
 
1084
+
 
1085
+                       wq = autofs4_find_wait(sbi, qstr);
 
1086
+                       if (wq) {
 
1087
+                               *wait = wq;
 
1088
+                               return 1;
 
1089
                        }
 
1090
-                       wq = autofs4_find_wait(sbi, name, hash, len);
 
1091
-                       if (wq)
 
1092
-                               break;
 
1093
                }
 
1094
 
 
1095
                /*
 
1096
@@ -267,18 +288,96 @@ int autofs4_wait(struct autofs_sb_info *
 
1097
                 * cases where we wait on NFY_NONE neither depend on the
 
1098
                 * return status of the wait.
 
1099
                 */
 
1100
-               if (!wq) {
 
1101
+               return 0;
 
1102
+       }
 
1103
+
 
1104
+       /*
 
1105
+        * If we've been asked to trigger a mount and the request
 
1106
+        * completed while we waited on the mutex ...
 
1107
+        */
 
1108
+       if (notify == NFY_MOUNT) {
 
1109
+               /*
 
1110
+                * If the dentry isn't hashed just go ahead and try the
 
1111
+                * mount again with a new wait (not much else we can do).
 
1112
+               */
 
1113
+               if (!d_unhashed(dentry)) {
 
1114
+                       /*
 
1115
+                        * But if the dentry is hashed, that means that we
 
1116
+                        * got here through the revalidate path.  Thus, we
 
1117
+                        * need to check if the dentry has been mounted
 
1118
+                        * while we waited on the wq_mutex. If it has,
 
1119
+                        * simply return success.
 
1120
+                        */
 
1121
+                       if (d_mountpoint(dentry))
 
1122
+                               return 0;
 
1123
+               }
 
1124
+       }
 
1125
+
 
1126
+       return 1;
 
1127
+}
 
1128
+
 
1129
+int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
 
1130
+               enum autofs_notify notify)
 
1131
+{
 
1132
+       struct autofs_wait_queue *wq;
 
1133
+       struct qstr qstr;
 
1134
+       char *name;
 
1135
+       int status, ret, type;
 
1136
+
 
1137
+       /* In catatonic mode, we don't wait for nobody */
 
1138
+       if (sbi->catatonic)
 
1139
+               return -ENOENT;
 
1140
+
 
1141
+       if (!dentry->d_inode) {
 
1142
+               /*
 
1143
+                * A wait for a negative dentry is invalid for certain
 
1144
+                * cases. A direct or offset mount "always" has its mount
 
1145
+                * point directory created and so the request dentry must
 
1146
+                * be positive or the map key doesn't exist. The situation
 
1147
+                * is very similar for indirect mounts except only dentrys
 
1148
+                * in the root of the autofs file system may be negative.
 
1149
+                */
 
1150
+               if (sbi->type & AUTOFS_TYPE_TRIGGER)
 
1151
+                       return -ENOENT;
 
1152
+               else if (!IS_ROOT(dentry->d_parent))
 
1153
+                       return -ENOENT;
 
1154
+       }
 
1155
+
 
1156
+       name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
 
1157
+       if (!name)
 
1158
+               return -ENOMEM;
 
1159
+
 
1160
+       /* If this is a direct mount request create a dummy name */
 
1161
+       if (IS_ROOT(dentry) && sbi->type & AUTOFS_TYPE_TRIGGER)
 
1162
+               qstr.len = sprintf(name, "%p", dentry);
 
1163
+       else {
 
1164
+               qstr.len = autofs4_getpath(sbi, dentry, &name);
 
1165
+               if (!qstr.len) {
 
1166
                        kfree(name);
 
1167
-                       mutex_unlock(&sbi->wq_mutex);
 
1168
-                       return 0;
 
1169
+                       return -ENOENT;
 
1170
                }
 
1171
        }
 
1172
+       qstr.name = name;
 
1173
+       qstr.hash = full_name_hash(name, qstr.len);
 
1174
+
 
1175
+       if (mutex_lock_interruptible(&sbi->wq_mutex)) {
 
1176
+               kfree(qstr.name);
 
1177
+               return -EINTR;
 
1178
+       }
 
1179
+
 
1180
+       ret = validate_request(&wq, sbi, &qstr, dentry, notify);
 
1181
+       if (ret <= 0) {
 
1182
+               if (ret == 0)
 
1183
+                       mutex_unlock(&sbi->wq_mutex);
 
1184
+               kfree(qstr.name);
 
1185
+               return ret;
 
1186
+       }
 
1187
 
 
1188
        if (!wq) {
 
1189
                /* Create a new wait queue */
 
1190
                wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
 
1191
                if (!wq) {
 
1192
-                       kfree(name);
 
1193
+                       kfree(qstr.name);
 
1194
                        mutex_unlock(&sbi->wq_mutex);
 
1195
                        return -ENOMEM;
 
1196
                }
 
1197
@@ -289,9 +388,7 @@ int autofs4_wait(struct autofs_sb_info *
 
1198
                wq->next = sbi->queues;
 
1199
                sbi->queues = wq;
 
1200
                init_waitqueue_head(&wq->queue);
 
1201
-               wq->hash = hash;
 
1202
-               wq->name = name;
 
1203
-               wq->len = len;
 
1204
+               memcpy(&wq->name, &qstr, sizeof(struct qstr));
 
1205
                wq->dev = autofs4_get_dev(sbi);
 
1206
                wq->ino = autofs4_get_ino(sbi);
 
1207
                wq->uid = current->uid;
 
1208
@@ -299,7 +396,7 @@ int autofs4_wait(struct autofs_sb_info *
 
1209
                wq->pid = current->pid;
 
1210
                wq->tgid = current->tgid;
 
1211
                wq->status = -EINTR; /* Status return if interrupted */
 
1212
-               atomic_set(&wq->wait_ctr, 2);
 
1213
+               wq->wait_ctr = 2;
 
1214
                mutex_unlock(&sbi->wq_mutex);
 
1215
 
 
1216
                if (sbi->version < 5) {
 
1217
@@ -309,38 +406,35 @@ int autofs4_wait(struct autofs_sb_info *
 
1218
                                type = autofs_ptype_expire_multi;
 
1219
                } else {
 
1220
                        if (notify == NFY_MOUNT)
 
1221
-                               type = (sbi->type & AUTOFS_TYPE_DIRECT) ?
 
1222
+                               type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
 
1223
                                        autofs_ptype_missing_direct :
 
1224
                                         autofs_ptype_missing_indirect;
 
1225
                        else
 
1226
-                               type = (sbi->type & AUTOFS_TYPE_DIRECT) ?
 
1227
+                               type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
 
1228
                                        autofs_ptype_expire_direct :
 
1229
                                        autofs_ptype_expire_indirect;
 
1230
                }
 
1231
 
 
1232
                DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
 
1233
-                       (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
 
1234
+                       (unsigned long) wq->wait_queue_token, wq->name.len,
 
1235
+                       wq->name.name, notify);
 
1236
 
 
1237
                /* autofs4_notify_daemon() may block */
 
1238
                autofs4_notify_daemon(sbi, wq, type);
 
1239
        } else {
 
1240
-               atomic_inc(&wq->wait_ctr);
 
1241
+               wq->wait_ctr++;
 
1242
                mutex_unlock(&sbi->wq_mutex);
 
1243
-               kfree(name);
 
1244
+               kfree(qstr.name);
 
1245
                DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
 
1246
-                       (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
 
1247
+                       (unsigned long) wq->wait_queue_token, wq->name.len,
 
1248
+                       wq->name.name, notify);
 
1249
        }
 
1250
 
 
1251
-       /* wq->name is NULL if and only if the lock is already released */
 
1252
-
 
1253
-       if (sbi->catatonic) {
 
1254
-               /* We might have slept, so check again for catatonic mode */
 
1255
-               wq->status = -ENOENT;
 
1256
-               kfree(wq->name);
 
1257
-               wq->name = NULL;
 
1258
-       }
 
1259
-
 
1260
-       if (wq->name) {
 
1261
+       /*
 
1262
+        * wq->name.name is NULL iff the lock is already released
 
1263
+        * or the mount has been made catatonic.
 
1264
+        */
 
1265
+       if (wq->name.name) {
 
1266
                /* Block all but "shutdown" signals while waiting */
 
1267
                sigset_t oldset;
 
1268
                unsigned long irqflags;
 
1269
@@ -351,7 +445,7 @@ int autofs4_wait(struct autofs_sb_info *
 
1270
                recalc_sigpending();
 
1271
                spin_unlock_irqrestore(&current->sighand->siglock, irqflags);
 
1272
 
 
1273
-               wait_event_interruptible(wq->queue, wq->name == NULL);
 
1274
+               wait_event_interruptible(wq->queue, wq->name.name == NULL);
 
1275
 
 
1276
                spin_lock_irqsave(&current->sighand->siglock, irqflags);
 
1277
                current->blocked = oldset;
 
1278
@@ -364,8 +458,10 @@ int autofs4_wait(struct autofs_sb_info *
 
1279
        status = wq->status;
 
1280
 
 
1281
        /* Are we the last process to need status? */
 
1282
-       if (atomic_dec_and_test(&wq->wait_ctr))
 
1283
+       mutex_lock(&sbi->wq_mutex);
 
1284
+       if (!--wq->wait_ctr)
 
1285
                kfree(wq);
 
1286
+       mutex_unlock(&sbi->wq_mutex);
 
1287
 
 
1288
        return status;
 
1289
 }
 
1290
@@ -387,16 +483,13 @@ int autofs4_wait_release(struct autofs_s
 
1291
        }
 
1292
 
 
1293
        *wql = wq->next;        /* Unlink from chain */
 
1294
-       mutex_unlock(&sbi->wq_mutex);
 
1295
-       kfree(wq->name);
 
1296
-       wq->name = NULL;        /* Do not wait on this queue */
 
1297
-
 
1298
+       kfree(wq->name.name);
 
1299
+       wq->name.name = NULL;   /* Do not wait on this queue */
 
1300
        wq->status = status;
 
1301
-
 
1302
-       if (atomic_dec_and_test(&wq->wait_ctr)) /* Is anyone still waiting for this guy? */
 
1303
+       wake_up_interruptible(&wq->queue);
 
1304
+       if (!--wq->wait_ctr)
 
1305
                kfree(wq);
 
1306
-       else
 
1307
-               wake_up_interruptible(&wq->queue);
 
1308
+       mutex_unlock(&sbi->wq_mutex);
 
1309
 
 
1310
        return 0;
 
1311
 }
 
1312
Index: linux-2.6.22.17/fs/autofs4/expire.c
 
1313
===================================================================
 
1314
--- linux-2.6.22.17.orig/fs/autofs4/expire.c
 
1315
+++ linux-2.6.22.17/fs/autofs4/expire.c
 
1316
@@ -56,12 +56,23 @@ static int autofs4_mount_busy(struct vfs
 
1317
        mntget(mnt);
 
1318
        dget(dentry);
 
1319
 
 
1320
-       if (!autofs4_follow_mount(&mnt, &dentry))
 
1321
+       if (!follow_down(&mnt, &dentry))
 
1322
                goto done;
 
1323
 
 
1324
-       /* This is an autofs submount, we can't expire it */
 
1325
-       if (is_autofs4_dentry(dentry))
 
1326
-               goto done;
 
1327
+       if (is_autofs4_dentry(dentry)) {
 
1328
+               struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
1329
+
 
1330
+               /* This is an autofs submount, we can't expire it */
 
1331
+               if (sbi->type == AUTOFS_TYPE_INDIRECT)
 
1332
+                       goto done;
 
1333
+
 
1334
+               /*
 
1335
+                * Otherwise it's an offset mount and we need to check
 
1336
+                * if we can umount its mount, if there is one.
 
1337
+                */
 
1338
+               if (!d_mountpoint(dentry))
 
1339
+                       goto done;
 
1340
+       }
 
1341
 
 
1342
        /* Update the expiry counter if fs is busy */
 
1343
        if (!may_umount_tree(mnt)) {
 
1344
@@ -73,8 +84,8 @@ static int autofs4_mount_busy(struct vfs
 
1345
        status = 0;
 
1346
 done:
 
1347
        DPRINTK("returning = %d", status);
 
1348
-       mntput(mnt);
 
1349
        dput(dentry);
 
1350
+       mntput(mnt);
 
1351
        return status;
 
1352
 }
 
1353
 
 
1354
@@ -259,13 +270,15 @@ static struct dentry *autofs4_expire_dir
 
1355
        now = jiffies;
 
1356
        timeout = sbi->exp_timeout;
 
1357
 
 
1358
-       /* Lock the tree as we must expire as a whole */
 
1359
        spin_lock(&sbi->fs_lock);
 
1360
        if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
 
1361
                struct autofs_info *ino = autofs4_dentry_ino(root);
 
1362
-
 
1363
-               /* Set this flag early to catch sys_chdir and the like */
 
1364
+               if (d_mountpoint(root)) {
 
1365
+                       ino->flags |= AUTOFS_INF_MOUNTPOINT;
 
1366
+                       root->d_mounted--;
 
1367
+               }
 
1368
                ino->flags |= AUTOFS_INF_EXPIRING;
 
1369
+               init_completion(&ino->expire_complete);
 
1370
                spin_unlock(&sbi->fs_lock);
 
1371
                return root;
 
1372
        }
 
1373
@@ -292,6 +305,8 @@ static struct dentry *autofs4_expire_ind
 
1374
        struct list_head *next;
 
1375
        int do_now = how & AUTOFS_EXP_IMMEDIATE;
 
1376
        int exp_leaves = how & AUTOFS_EXP_LEAVES;
 
1377
+       struct autofs_info *ino;
 
1378
+       unsigned int ino_count;
 
1379
 
 
1380
        if (!root)
 
1381
                return NULL;
 
1382
@@ -316,6 +331,9 @@ static struct dentry *autofs4_expire_ind
 
1383
                dentry = dget(dentry);
 
1384
                spin_unlock(&dcache_lock);
 
1385
 
 
1386
+               spin_lock(&sbi->fs_lock);
 
1387
+               ino = autofs4_dentry_ino(dentry);
 
1388
+
 
1389
                /*
 
1390
                 * Case 1: (i) indirect mount or top level pseudo direct mount
 
1391
                 *         (autofs-4.1).
 
1392
@@ -326,6 +344,11 @@ static struct dentry *autofs4_expire_ind
 
1393
                        DPRINTK("checking mountpoint %p %.*s",
 
1394
                                dentry, (int)dentry->d_name.len, dentry->d_name.name);
 
1395
 
 
1396
+                       /* Path walk currently on this dentry? */
 
1397
+                       ino_count = atomic_read(&ino->count) + 2;
 
1398
+                       if (atomic_read(&dentry->d_count) > ino_count)
 
1399
+                               goto next;
 
1400
+
 
1401
                        /* Can we umount this guy */
 
1402
                        if (autofs4_mount_busy(mnt, dentry))
 
1403
                                goto next;
 
1404
@@ -333,7 +356,7 @@ static struct dentry *autofs4_expire_ind
 
1405
                        /* Can we expire this guy */
 
1406
                        if (autofs4_can_expire(dentry, timeout, do_now)) {
 
1407
                                expired = dentry;
 
1408
-                               break;
 
1409
+                               goto found;
 
1410
                        }
 
1411
                        goto next;
 
1412
                }
 
1413
@@ -343,46 +366,80 @@ static struct dentry *autofs4_expire_ind
 
1414
 
 
1415
                /* Case 2: tree mount, expire iff entire tree is not busy */
 
1416
                if (!exp_leaves) {
 
1417
-                       /* Lock the tree as we must expire as a whole */
 
1418
-                       spin_lock(&sbi->fs_lock);
 
1419
-                       if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
 
1420
-                               struct autofs_info *inf = autofs4_dentry_ino(dentry);
 
1421
+                       /* Path walk currently on this dentry? */
 
1422
+                       ino_count = atomic_read(&ino->count) + 1;
 
1423
+                       if (atomic_read(&dentry->d_count) > ino_count)
 
1424
+                               goto next;
 
1425
 
 
1426
-                               /* Set this flag early to catch sys_chdir and the like */
 
1427
-                               inf->flags |= AUTOFS_INF_EXPIRING;
 
1428
-                               spin_unlock(&sbi->fs_lock);
 
1429
+                       if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
 
1430
                                expired = dentry;
 
1431
-                               break;
 
1432
+                               goto found;
 
1433
                        }
 
1434
-                       spin_unlock(&sbi->fs_lock);
 
1435
                /*
 
1436
                 * Case 3: pseudo direct mount, expire individual leaves
 
1437
                 *         (autofs-4.1).
 
1438
                 */
 
1439
                } else {
 
1440
+                       /* Path walk currently on this dentry? */
 
1441
+                       ino_count = atomic_read(&ino->count) + 1;
 
1442
+                       if (atomic_read(&dentry->d_count) > ino_count)
 
1443
+                               goto next;
 
1444
+
 
1445
                        expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
 
1446
                        if (expired) {
 
1447
                                dput(dentry);
 
1448
-                               break;
 
1449
+                               goto found;
 
1450
                        }
 
1451
                }
 
1452
 next:
 
1453
+               spin_unlock(&sbi->fs_lock);
 
1454
                dput(dentry);
 
1455
                spin_lock(&dcache_lock);
 
1456
                next = next->next;
 
1457
        }
 
1458
+       spin_unlock(&dcache_lock);
 
1459
+       return NULL;
 
1460
 
 
1461
-       if (expired) {
 
1462
-               DPRINTK("returning %p %.*s",
 
1463
-                       expired, (int)expired->d_name.len, expired->d_name.name);
 
1464
-               spin_lock(&dcache_lock);
 
1465
-               list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
 
1466
-               spin_unlock(&dcache_lock);
 
1467
-               return expired;
 
1468
-       }
 
1469
+found:
 
1470
+       DPRINTK("returning %p %.*s",
 
1471
+               expired, (int)expired->d_name.len, expired->d_name.name);
 
1472
+       ino = autofs4_dentry_ino(expired);
 
1473
+       ino->flags |= AUTOFS_INF_EXPIRING;
 
1474
+       init_completion(&ino->expire_complete);
 
1475
+       spin_unlock(&sbi->fs_lock);
 
1476
+       spin_lock(&dcache_lock);
 
1477
+       list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
 
1478
        spin_unlock(&dcache_lock);
 
1479
+       return expired;
 
1480
+}
 
1481
 
 
1482
-       return NULL;
 
1483
+int autofs4_expire_wait(struct dentry *dentry)
 
1484
+{
 
1485
+       struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
1486
+       struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
1487
+       int status;
 
1488
+
 
1489
+       /* Block on any pending expire */
 
1490
+       spin_lock(&sbi->fs_lock);
 
1491
+       if (ino->flags & AUTOFS_INF_EXPIRING) {
 
1492
+               spin_unlock(&sbi->fs_lock);
 
1493
+
 
1494
+               DPRINTK("waiting for expire %p name=%.*s",
 
1495
+                        dentry, dentry->d_name.len, dentry->d_name.name);
 
1496
+
 
1497
+               status = autofs4_wait(sbi, dentry, NFY_NONE);
 
1498
+               wait_for_completion(&ino->expire_complete);
 
1499
+
 
1500
+               DPRINTK("expire done status=%d", status);
 
1501
+
 
1502
+               if (d_unhashed(dentry))
 
1503
+                       return -EAGAIN;
 
1504
+
 
1505
+               return status;
 
1506
+       }
 
1507
+       spin_unlock(&sbi->fs_lock);
 
1508
+
 
1509
+       return 0;
 
1510
 }
 
1511
 
 
1512
 /* Perform an expiry operation */
 
1513
@@ -392,7 +449,9 @@ int autofs4_expire_run(struct super_bloc
 
1514
                      struct autofs_packet_expire __user *pkt_p)
 
1515
 {
 
1516
        struct autofs_packet_expire pkt;
 
1517
+       struct autofs_info *ino;
 
1518
        struct dentry *dentry;
 
1519
+       int ret = 0;
 
1520
 
 
1521
        memset(&pkt,0,sizeof pkt);
 
1522
 
 
1523
@@ -408,9 +467,15 @@ int autofs4_expire_run(struct super_bloc
 
1524
        dput(dentry);
 
1525
 
 
1526
        if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
 
1527
-               return -EFAULT;
 
1528
+               ret = -EFAULT;
 
1529
 
 
1530
-       return 0;
 
1531
+       spin_lock(&sbi->fs_lock);
 
1532
+       ino = autofs4_dentry_ino(dentry);
 
1533
+       ino->flags &= ~AUTOFS_INF_EXPIRING;
 
1534
+       complete_all(&ino->expire_complete);
 
1535
+       spin_unlock(&sbi->fs_lock);
 
1536
+
 
1537
+       return ret;
 
1538
 }
 
1539
 
 
1540
 /* Call repeatedly until it returns -EAGAIN, meaning there's nothing
 
1541
@@ -425,7 +490,7 @@ int autofs4_expire_multi(struct super_bl
 
1542
        if (arg && get_user(do_now, arg))
 
1543
                return -EFAULT;
 
1544
 
 
1545
-       if (sbi->type & AUTOFS_TYPE_DIRECT)
 
1546
+       if (sbi->type & AUTOFS_TYPE_TRIGGER)
 
1547
                dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
 
1548
        else
 
1549
                dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
 
1550
@@ -435,9 +500,16 @@ int autofs4_expire_multi(struct super_bl
 
1551
 
 
1552
                /* This is synchronous because it makes the daemon a
 
1553
                    little easier */
 
1554
-               ino->flags |= AUTOFS_INF_EXPIRING;
 
1555
                ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
 
1556
+
 
1557
+               spin_lock(&sbi->fs_lock);
 
1558
+               if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
 
1559
+                       sb->s_root->d_mounted++;
 
1560
+                       ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
 
1561
+               }
 
1562
                ino->flags &= ~AUTOFS_INF_EXPIRING;
 
1563
+               complete_all(&ino->expire_complete);
 
1564
+               spin_unlock(&sbi->fs_lock);
 
1565
                dput(dentry);
 
1566
        }
 
1567
 
 
1568
Index: linux-2.6.22.17/fs/autofs4/autofs_i.h
 
1569
===================================================================
 
1570
--- linux-2.6.22.17.orig/fs/autofs4/autofs_i.h
 
1571
+++ linux-2.6.22.17/fs/autofs4/autofs_i.h
 
1572
@@ -21,6 +21,8 @@
 
1573
 #define AUTOFS_IOC_FIRST     AUTOFS_IOC_READY
 
1574
 #define AUTOFS_IOC_COUNT     32
 
1575
 
 
1576
+#define AUTOFS_TYPE_TRIGGER    (AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET)
 
1577
+
 
1578
 #include <linux/kernel.h>
 
1579
 #include <linux/slab.h>
 
1580
 #include <linux/time.h>
 
1581
@@ -52,7 +54,10 @@ struct autofs_info {
 
1582
 
 
1583
        int             flags;
 
1584
 
 
1585
-       struct list_head rehash;
 
1586
+       struct completion expire_complete;
 
1587
+
 
1588
+       struct list_head active;
 
1589
+       struct list_head expiring;
 
1590
 
 
1591
        struct autofs_sb_info *sbi;
 
1592
        unsigned long last_used;
 
1593
@@ -68,15 +73,14 @@ struct autofs_info {
 
1594
 };
 
1595
 
 
1596
 #define AUTOFS_INF_EXPIRING    (1<<0) /* dentry is in the process of expiring */
 
1597
+#define AUTOFS_INF_MOUNTPOINT  (1<<1) /* mountpoint status for direct expire */
 
1598
 
 
1599
 struct autofs_wait_queue {
 
1600
        wait_queue_head_t queue;
 
1601
        struct autofs_wait_queue *next;
 
1602
        autofs_wqt_t wait_queue_token;
 
1603
        /* We use the following to see what we are waiting for */
 
1604
-       unsigned int hash;
 
1605
-       unsigned int len;
 
1606
-       char *name;
 
1607
+       struct qstr name;
 
1608
        u32 dev;
 
1609
        u64 ino;
 
1610
        uid_t uid;
 
1611
@@ -85,15 +89,11 @@ struct autofs_wait_queue {
 
1612
        pid_t tgid;
 
1613
        /* This is for status reporting upon return */
 
1614
        int status;
 
1615
-       atomic_t wait_ctr;
 
1616
+       unsigned int wait_ctr;
 
1617
 };
 
1618
 
 
1619
 #define AUTOFS_SBI_MAGIC 0x6d4a556d
 
1620
 
 
1621
-#define AUTOFS_TYPE_INDIRECT     0x0001
 
1622
-#define AUTOFS_TYPE_DIRECT       0x0002
 
1623
-#define AUTOFS_TYPE_OFFSET       0x0004
 
1624
-
 
1625
 struct autofs_sb_info {
 
1626
        u32 magic;
 
1627
        int pipefd;
 
1628
@@ -112,8 +112,9 @@ struct autofs_sb_info {
 
1629
        struct mutex wq_mutex;
 
1630
        spinlock_t fs_lock;
 
1631
        struct autofs_wait_queue *queues; /* Wait queue pointer */
 
1632
-       spinlock_t rehash_lock;
 
1633
-       struct list_head rehash_list;
 
1634
+       spinlock_t lookup_lock;
 
1635
+       struct list_head active_list;
 
1636
+       struct list_head expiring_list;
 
1637
 };
 
1638
 
 
1639
 static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
 
1640
@@ -138,18 +139,14 @@ static inline int autofs4_oz_mode(struct
 
1641
 static inline int autofs4_ispending(struct dentry *dentry)
 
1642
 {
 
1643
        struct autofs_info *inf = autofs4_dentry_ino(dentry);
 
1644
-       int pending = 0;
 
1645
 
 
1646
        if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
 
1647
                return 1;
 
1648
 
 
1649
-       if (inf) {
 
1650
-               spin_lock(&inf->sbi->fs_lock);
 
1651
-               pending = inf->flags & AUTOFS_INF_EXPIRING;
 
1652
-               spin_unlock(&inf->sbi->fs_lock);
 
1653
-       }
 
1654
+       if (inf->flags & AUTOFS_INF_EXPIRING)
 
1655
+               return 1;
 
1656
 
 
1657
-       return pending;
 
1658
+       return 0;
 
1659
 }
 
1660
 
 
1661
 static inline void autofs4_copy_atime(struct file *src, struct file *dst)
 
1662
@@ -164,6 +161,7 @@ void autofs4_free_ino(struct autofs_info
 
1663
 
 
1664
 /* Expiration */
 
1665
 int is_autofs4_dentry(struct dentry *);
 
1666
+int autofs4_expire_wait(struct dentry *dentry);
 
1667
 int autofs4_expire_run(struct super_block *, struct vfsmount *,
 
1668
                        struct autofs_sb_info *,
 
1669
                        struct autofs_packet_expire __user *);
 
1670
Index: linux-2.6.22.17/fs/autofs4/inode.c
 
1671
===================================================================
 
1672
--- linux-2.6.22.17.orig/fs/autofs4/inode.c
 
1673
+++ linux-2.6.22.17/fs/autofs4/inode.c
 
1674
@@ -24,8 +24,10 @@
 
1675
 
 
1676
 static void ino_lnkfree(struct autofs_info *ino)
 
1677
 {
 
1678
-       kfree(ino->u.symlink);
 
1679
-       ino->u.symlink = NULL;
 
1680
+       if (ino->u.symlink) {
 
1681
+               kfree(ino->u.symlink);
 
1682
+               ino->u.symlink = NULL;
 
1683
+       }
 
1684
 }
 
1685
 
 
1686
 struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
 
1687
@@ -41,16 +43,18 @@ struct autofs_info *autofs4_init_ino(str
 
1688
        if (ino == NULL)
 
1689
                return NULL;
 
1690
 
 
1691
-       ino->flags = 0;
 
1692
-       ino->mode = mode;
 
1693
-       ino->inode = NULL;
 
1694
-       ino->dentry = NULL;
 
1695
-       ino->size = 0;
 
1696
-
 
1697
-       INIT_LIST_HEAD(&ino->rehash);
 
1698
+       if (!reinit) {
 
1699
+               ino->flags = 0;
 
1700
+               ino->inode = NULL;
 
1701
+               ino->dentry = NULL;
 
1702
+               ino->size = 0;
 
1703
+               INIT_LIST_HEAD(&ino->active);
 
1704
+               INIT_LIST_HEAD(&ino->expiring);
 
1705
+               atomic_set(&ino->count, 0);
 
1706
+       }
 
1707
 
 
1708
+       ino->mode = mode;
 
1709
        ino->last_used = jiffies;
 
1710
-       atomic_set(&ino->count, 0);
 
1711
 
 
1712
        ino->sbi = sbi;
 
1713
 
 
1714
@@ -159,8 +163,8 @@ void autofs4_kill_sb(struct super_block 
 
1715
        if (!sbi)
 
1716
                goto out_kill_sb;
 
1717
 
 
1718
-       if (!sbi->catatonic)
 
1719
-               autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
 
1720
+       /* Free wait queues, close pipe */
 
1721
+       autofs4_catatonic_mode(sbi);
 
1722
 
 
1723
        /* Clean up and release dangling references */
 
1724
        autofs4_force_release(sbi);
 
1725
@@ -279,7 +283,7 @@ static int parse_options(char *options, 
 
1726
                        *type = AUTOFS_TYPE_DIRECT;
 
1727
                        break;
 
1728
                case Opt_offset:
 
1729
-                       *type = AUTOFS_TYPE_DIRECT | AUTOFS_TYPE_OFFSET;
 
1730
+                       *type = AUTOFS_TYPE_OFFSET;
 
1731
                        break;
 
1732
                default:
 
1733
                        return 1;
 
1734
@@ -329,14 +333,15 @@ int autofs4_fill_super(struct super_bloc
 
1735
        sbi->sb = s;
 
1736
        sbi->version = 0;
 
1737
        sbi->sub_version = 0;
 
1738
-       sbi->type = 0;
 
1739
+       sbi->type = AUTOFS_TYPE_INDIRECT;
 
1740
        sbi->min_proto = 0;
 
1741
        sbi->max_proto = 0;
 
1742
        mutex_init(&sbi->wq_mutex);
 
1743
        spin_lock_init(&sbi->fs_lock);
 
1744
        sbi->queues = NULL;
 
1745
-       spin_lock_init(&sbi->rehash_lock);
 
1746
-       INIT_LIST_HEAD(&sbi->rehash_list);
 
1747
+       spin_lock_init(&sbi->lookup_lock);
 
1748
+       INIT_LIST_HEAD(&sbi->active_list);
 
1749
+       INIT_LIST_HEAD(&sbi->expiring_list);
 
1750
        s->s_blocksize = 1024;
 
1751
        s->s_blocksize_bits = 10;
 
1752
        s->s_magic = AUTOFS_SUPER_MAGIC;
 
1753
@@ -370,7 +375,7 @@ int autofs4_fill_super(struct super_bloc
 
1754
        }
 
1755
 
 
1756
        root_inode->i_fop = &autofs4_root_operations;
 
1757
-       root_inode->i_op = sbi->type & AUTOFS_TYPE_DIRECT ?
 
1758
+       root_inode->i_op = sbi->type & AUTOFS_TYPE_TRIGGER ?
 
1759
                        &autofs4_direct_root_inode_operations :
 
1760
                        &autofs4_indirect_root_inode_operations;
 
1761
 
 
1762
Index: linux-2.6.22.17/fs/compat_ioctl.c
 
1763
===================================================================
 
1764
--- linux-2.6.22.17.orig/fs/compat_ioctl.c
 
1765
+++ linux-2.6.22.17/fs/compat_ioctl.c
 
1766
@@ -2998,8 +2998,6 @@ COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
 
1767
 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
 
1768
 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
 
1769
 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
 
1770
-COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
 
1771
-COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
 
1772
 COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
 
1773
 /* Raw devices */
 
1774
 COMPATIBLE_IOCTL(RAW_SETBIND)
 
1775
Index: linux-2.6.22.17/include/linux/auto_fs4.h
 
1776
===================================================================
 
1777
--- linux-2.6.22.17.orig/include/linux/auto_fs4.h
 
1778
+++ linux-2.6.22.17/include/linux/auto_fs4.h
 
1779
@@ -29,6 +29,11 @@
 
1780
 #define AUTOFS_EXP_IMMEDIATE           1
 
1781
 #define AUTOFS_EXP_LEAVES              2
 
1782
 
 
1783
+#define AUTOFS_TYPE_ANY                        0x0000
 
1784
+#define AUTOFS_TYPE_INDIRECT           0x0001
 
1785
+#define AUTOFS_TYPE_DIRECT             0x0002
 
1786
+#define AUTOFS_TYPE_OFFSET             0x0004
 
1787
+
 
1788
 /* Daemon notification packet types */
 
1789
 enum autofs_notify {
 
1790
        NFY_NONE,
 
1791
@@ -98,8 +103,6 @@ union autofs_v5_packet_union {
 
1792
 #define AUTOFS_IOC_EXPIRE_INDIRECT     AUTOFS_IOC_EXPIRE_MULTI
 
1793
 #define AUTOFS_IOC_EXPIRE_DIRECT       AUTOFS_IOC_EXPIRE_MULTI
 
1794
 #define AUTOFS_IOC_PROTOSUBVER         _IOR(0x93,0x67,int)
 
1795
-#define AUTOFS_IOC_ASKREGHOST           _IOR(0x93,0x68,int)
 
1796
-#define AUTOFS_IOC_TOGGLEREGHOST        _IOR(0x93,0x69,int)
 
1797
 #define AUTOFS_IOC_ASKUMOUNT           _IOR(0x93,0x70,int)
 
1798
 
 
1799