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

« back to all changes in this revision

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