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 *);
15
+#define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
16
+#define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
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,
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,
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,
41
-static int autofs4_root_readdir(struct file *file, void *dirent,
44
- struct autofs_sb_info *sbi = autofs4_sbi(file->f_path.dentry->d_sb);
45
- int oz_mode = autofs4_oz_mode(sbi);
47
- DPRINTK("called, filp->f_pos = %lld", file->f_pos);
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
55
- if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
56
- sbi->needs_reghost = 1;
58
- DPRINTK("needs_reghost = %d", sbi->needs_reghost);
60
- return dcache_readdir(file, dirent, filldir);
63
static int autofs4_dir_open(struct inode *inode, struct file *file)
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;
71
- status = dcache_dir_open(inode, file);
75
- cursor = file->private_data;
76
- cursor->d_fsdata = NULL;
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))
84
- if (autofs4_ispending(dentry)) {
85
- DPRINTK("dentry busy");
86
- dcache_dir_close(inode, file);
92
- if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) {
93
- struct nameidata nd;
96
- /* In case there are stale directory dentrys from a failed mount */
97
- spin_lock(&dcache_lock);
98
- empty = list_empty(&dentry->d_subdirs);
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
108
+ spin_lock(&dcache_lock);
109
+ if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
110
spin_unlock(&dcache_lock);
113
- d_invalidate(dentry);
115
- nd.flags = LOOKUP_DIRECTORY;
116
- ret = (dentry->d_op->d_revalidate)(dentry, &nd);
121
- dcache_dir_close(inode, file);
126
- if (d_mountpoint(dentry)) {
127
- struct file *fp = NULL;
128
- struct vfsmount *fp_mnt = mntget(mnt);
129
- struct dentry *fp_dentry = dget(dentry);
131
- if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) {
134
- dcache_dir_close(inode, file);
138
- fp = dentry_open(fp_dentry, fp_mnt, file->f_flags);
139
- status = PTR_ERR(fp);
141
- dcache_dir_close(inode, file);
144
- cursor->d_fsdata = fp;
151
-static int autofs4_dir_close(struct inode *inode, struct file *file)
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;
158
- DPRINTK("file=%p dentry=%p %.*s",
159
- file, dentry, dentry->d_name.len, dentry->d_name.name);
161
- if (autofs4_oz_mode(sbi))
164
- if (autofs4_ispending(dentry)) {
165
- DPRINTK("dentry busy");
170
- if (d_mountpoint(dentry)) {
171
- struct file *fp = cursor->d_fsdata;
176
- filp_close(fp, current->files);
180
- dcache_dir_close(inode, file);
184
-static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
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;
191
- DPRINTK("file=%p dentry=%p %.*s",
192
- file, dentry, dentry->d_name.len, dentry->d_name.name);
194
- if (autofs4_oz_mode(sbi))
197
- if (autofs4_ispending(dentry)) {
198
- DPRINTK("dentry busy");
202
- if (d_mountpoint(dentry)) {
203
- struct file *fp = cursor->d_fsdata;
208
- if (!fp->f_op || !fp->f_op->readdir)
210
+ spin_unlock(&dcache_lock);
212
- status = vfs_readdir(fp, filldir, dirent);
213
- file->f_pos = fp->f_pos;
215
- autofs4_copy_atime(file, fp);
219
- return dcache_readdir(file, dirent, filldir);
220
+ return dcache_dir_open(inode, file);
223
static int try_to_fill_dentry(struct dentry *dentry, int flags)
225
struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
226
struct autofs_info *ino = autofs4_dentry_ino(dentry);
229
- /* Block on any pending expiry here; invalidate the dentry
230
- when expiration is done to trigger mount request with a new
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);
236
- status = autofs4_wait(sbi, dentry, NFY_NONE);
238
- DPRINTK("expire done status=%d", status);
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.
245
- status = d_invalidate(dentry);
246
- if (status != -EBUSY)
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
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);
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,
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)
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.
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))
296
+ spin_unlock(&sbi->fs_lock);
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);
305
- status = autofs4_wait(sbi, dentry, NFY_NONE);
306
+ /* If an expire request is pending everyone must wait. */
307
+ autofs4_expire_wait(dentry);
309
- DPRINTK("request done status=%d", status);
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))
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
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);
330
status = try_to_fill_dentry(dentry, 0);
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.
339
- if (d_mountpoint(dentry)) {
340
- if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
349
spin_unlock(&dcache_lock);
352
+ * If there is no root mount it must be an autofs
353
+ * multi-mount with no root offset so we don't need
356
+ if (d_mountpoint(dentry)) {
357
+ if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
365
@@ -401,12 +257,23 @@ static int autofs4_revalidate(struct den
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);
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().
382
+ if (autofs4_expire_wait(dentry) == -EAGAIN)
386
* A zero status is success otherwise we have a
387
* negative error code.
389
@@ -414,17 +281,9 @@ static int autofs4_revalidate(struct den
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.
399
- if (status == -EAGAIN)
404
+ spin_unlock(&sbi->fs_lock);
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);
413
/* The daemon never causes a mount to trigger */
416
@@ -470,10 +330,12 @@ void autofs4_dentry_release(struct dentr
417
struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
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);
433
@@ -495,7 +357,59 @@ static struct dentry_operations autofs4_
434
.d_release = autofs4_dentry_release,
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)
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;
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;
453
+ ino = list_entry(p, struct autofs_info, active);
454
+ dentry = ino->dentry;
456
+ spin_lock(&dentry->d_lock);
458
+ /* Already gone? */
459
+ if (atomic_read(&dentry->d_count) == 0)
462
+ qstr = &dentry->d_name;
464
+ if (dentry->d_name.hash != hash)
466
+ if (dentry->d_parent != parent)
469
+ if (qstr->len != len)
471
+ if (memcmp(qstr->name, str, len))
474
+ if (d_unhashed(dentry)) {
476
+ spin_unlock(&dentry->d_lock);
477
+ spin_unlock(&sbi->lookup_lock);
478
+ spin_unlock(&dcache_lock);
482
+ spin_unlock(&dentry->d_lock);
484
+ spin_unlock(&sbi->lookup_lock);
485
+ spin_unlock(&dcache_lock);
490
+static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
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;
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;
507
- ino = list_entry(p, struct autofs_info, rehash);
508
+ ino = list_entry(p, struct autofs_info, expiring);
509
dentry = ino->dentry;
511
spin_lock(&dentry->d_lock);
512
@@ -532,33 +446,16 @@ static struct dentry *autofs4_lookup_unh
515
if (d_unhashed(dentry)) {
516
- struct autofs_info *ino = autofs4_dentry_ino(dentry);
517
- struct inode *inode = dentry->d_inode;
519
- list_del_init(&ino->rehash);
522
- * Make the rehashed dentry negative so the VFS
523
- * behaves as it should.
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);
534
spin_unlock(&dentry->d_lock);
535
- spin_unlock(&sbi->rehash_lock);
536
+ spin_unlock(&sbi->lookup_lock);
537
spin_unlock(&dcache_lock);
541
spin_unlock(&dentry->d_lock);
543
- spin_unlock(&sbi->rehash_lock);
544
+ spin_unlock(&sbi->lookup_lock);
545
spin_unlock(&dcache_lock);
548
@@ -568,7 +465,8 @@ next:
549
static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
551
struct autofs_sb_info *sbi;
552
- struct dentry *unhashed;
553
+ struct autofs_info *ino;
554
+ struct dentry *expiring, *unhashed;
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);
562
- unhashed = autofs4_lookup_unhashed(sbi, dentry->d_parent, &dentry->d_name);
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.
569
- * Let all the hard work be done by the revalidate function that
570
- * needs to be able to do this anyway..
572
- * We need to do this before we release the directory semaphore.
574
- dentry->d_op = &autofs4_root_dentry_operations;
576
- dentry->d_fsdata = NULL;
577
- d_add(dentry, NULL);
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);
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.
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");
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);
605
+ unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
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
620
+ dentry->d_op = &autofs4_root_dentry_operations;
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.
627
+ ino = autofs4_init_ino(NULL, sbi, 0555);
629
+ return ERR_PTR(-ENOMEM);
631
+ dentry->d_fsdata = ino;
632
+ ino->dentry = dentry;
634
+ spin_lock(&sbi->lookup_lock);
635
+ list_add(&ino->active, &sbi->active_list);
636
+ spin_unlock(&sbi->lookup_lock);
638
+ d_instantiate(dentry, NULL);
642
spin_lock(&dentry->d_lock);
643
dentry->d_flags |= DCACHE_AUTOFS_PENDING;
644
spin_unlock(&dentry->d_lock);
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);
659
@@ -647,9 +561,11 @@ static struct dentry *autofs4_lookup(str
660
return ERR_PTR(-ERESTARTNOINTR);
663
- spin_lock(&dentry->d_lock);
664
- dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
665
- spin_unlock(&dentry->d_lock);
667
+ spin_lock(&dentry->d_lock);
668
+ dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
669
+ spin_unlock(&dentry->d_lock);
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.
678
- if (dentry->d_inode && d_unhashed(dentry)) {
679
+ if (!oz_mode && d_unhashed(dentry)) {
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
692
@@ -702,21 +618,32 @@ static int autofs4_dir_symlink(struct in
695
ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
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);
711
+ ino->size = strlen(symname);
712
+ cp = kmalloc(ino->size + 1, GFP_KERNEL);
714
+ if (!dentry->d_fsdata)
721
inode = autofs4_get_inode(dir->i_sb, ino);
722
- d_instantiate(dentry, inode);
725
+ if (!dentry->d_fsdata)
729
+ d_add(dentry, inode);
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);
737
+ ino->u.symlink = cp;
738
dir->i_mtime = CURRENT_TIME;
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.
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;
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);
766
spin_unlock(&dentry->d_lock);
767
@@ -803,9 +731,10 @@ static int autofs4_dir_rmdir(struct inod
768
spin_unlock(&dcache_lock);
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);
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);
784
ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
790
+ spin_lock(&sbi->lookup_lock);
791
+ if (!list_empty(&ino->active))
792
+ list_del_init(&ino->active);
793
+ spin_unlock(&sbi->lookup_lock);
795
inode = autofs4_get_inode(dir->i_sb, ino);
796
- d_instantiate(dentry, inode);
798
+ if (!dentry->d_fsdata)
802
+ d_add(dentry, inode);
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
810
- * Tells the daemon whether we need to reghost or not. Also, clears
811
- * the reghost_needed flag.
813
-static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
817
- DPRINTK("returning %d", sbi->needs_reghost);
819
- status = put_user(sbi->needs_reghost, p);
823
- sbi->needs_reghost = 0;
828
- * Enable / Disable reghosting ioctl() operation
830
-static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
835
- status = get_user(val, p);
837
- DPRINTK("reghost = %d", val);
842
- /* turn on/off reghosting, with the val */
843
- sbi->reghost_enabled = val;
848
* Tells the daemon whether it can umount the autofs mount.
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);
855
- case AUTOFS_IOC_TOGGLEREGHOST:
856
- return autofs4_toggle_reghost(sbi, p);
857
- case AUTOFS_IOC_ASKREGHOST:
858
- return autofs4_ask_reghost(sbi, p);
860
case AUTOFS_IOC_ASKUMOUNT:
861
return autofs4_ask_umount(filp->f_path.mnt, p);
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
869
struct autofs_wait_queue *wq, *nwq;
871
+ mutex_lock(&sbi->wq_mutex);
872
+ if (sbi->catatonic) {
873
+ mutex_unlock(&sbi->wq_mutex);
877
DPRINTK("entering catatonic mode");
880
@@ -36,13 +42,18 @@ void autofs4_catatonic_mode(struct autof
883
wq->status = -ENOENT; /* Magic is gone - report failure */
886
+ if (wq->name.name) {
887
+ kfree(wq->name.name);
888
+ wq->name.name = NULL;
891
wake_up_interruptible(&wq->queue);
894
fput(sbi->pipe); /* Close the pipe */
897
+ mutex_unlock(&sbi->wq_mutex);
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;
905
+ struct file *pipe = NULL;
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);
912
memset(&pkt,0,sizeof pkt); /* For security reasons */
914
@@ -107,9 +119,9 @@ static void autofs4_notify_daemon(struct
917
mp->wait_queue_token = wq->wait_queue_token;
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';
926
case autofs_ptype_expire_multi:
927
@@ -119,9 +131,9 @@ static void autofs4_notify_daemon(struct
930
ep->wait_queue_token = wq->wait_queue_token;
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';
940
@@ -138,9 +150,9 @@ static void autofs4_notify_daemon(struct
941
pktsz = sizeof(*packet);
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
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) {
965
+ mutex_unlock(&sbi->wq_mutex);
968
+ if (autofs4_write(pipe, &pkt, pktsz))
969
+ autofs4_catatonic_mode(sbi);
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;
979
- if (--len > NAME_MAX) {
980
+ if (!len || --len > NAME_MAX) {
981
spin_unlock(&dcache_lock);
984
@@ -191,58 +214,55 @@ static int autofs4_getpath(struct autofs
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)
992
struct autofs_wait_queue *wq;
994
for (wq = sbi->queues; wq; wq = wq->next) {
995
- if (wq->hash == hash &&
997
- wq->name && !memcmp(wq->name, name, len))
998
+ if (wq->name.hash == qstr->hash &&
999
+ wq->name.len == qstr->len &&
1001
+ !memcmp(wq->name.name, qstr->name, qstr->len))
1007
-int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
1008
- enum autofs_notify notify)
1010
+ * Check if we have a valid request.
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.
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)
1022
- struct autofs_info *ino;
1023
struct autofs_wait_queue *wq;
1025
- unsigned int len = 0;
1026
- unsigned int hash = 0;
1029
- /* In catatonic mode, we don't wait for nobody */
1030
- if (sbi->catatonic)
1033
- name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
1036
+ struct autofs_info *ino;
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);
1042
- len = autofs4_getpath(sbi, dentry, &name);
1047
+ /* Wait in progress, continue; */
1048
+ wq = autofs4_find_wait(sbi, qstr);
1053
- hash = full_name_hash(name, len);
1055
- if (mutex_lock_interruptible(&sbi->wq_mutex)) {
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) {
1069
+ * If we've been asked to wait on an existing expire (NFY_NONE)
1070
+ * but there is no wait in the queue ...
1072
+ if (notify == NFY_NONE) {
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)) {
1082
+ if (mutex_lock_interruptible(&sbi->wq_mutex))
1085
+ wq = autofs4_find_wait(sbi, qstr);
1090
- wq = autofs4_find_wait(sbi, name, hash, len);
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.
1105
+ * If we've been asked to trigger a mount and the request
1106
+ * completed while we waited on the mutex ...
1108
+ if (notify == NFY_MOUNT) {
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).
1113
+ if (!d_unhashed(dentry)) {
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.
1121
+ if (d_mountpoint(dentry))
1129
+int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
1130
+ enum autofs_notify notify)
1132
+ struct autofs_wait_queue *wq;
1135
+ int status, ret, type;
1137
+ /* In catatonic mode, we don't wait for nobody */
1138
+ if (sbi->catatonic)
1141
+ if (!dentry->d_inode) {
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.
1150
+ if (sbi->type & AUTOFS_TYPE_TRIGGER)
1152
+ else if (!IS_ROOT(dentry->d_parent))
1156
+ name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
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);
1164
+ qstr.len = autofs4_getpath(sbi, dentry, &name);
1167
- mutex_unlock(&sbi->wq_mutex);
1173
+ qstr.hash = full_name_hash(name, qstr.len);
1175
+ if (mutex_lock_interruptible(&sbi->wq_mutex)) {
1180
+ ret = validate_request(&wq, sbi, &qstr, dentry, notify);
1183
+ mutex_unlock(&sbi->wq_mutex);
1189
/* Create a new wait queue */
1190
wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
1194
mutex_unlock(&sbi->wq_mutex);
1197
@@ -289,9 +388,7 @@ int autofs4_wait(struct autofs_sb_info *
1198
wq->next = sbi->queues;
1200
init_waitqueue_head(&wq->queue);
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);
1214
mutex_unlock(&sbi->wq_mutex);
1216
if (sbi->version < 5) {
1217
@@ -309,38 +406,35 @@ int autofs4_wait(struct autofs_sb_info *
1218
type = autofs_ptype_expire_multi;
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;
1226
- type = (sbi->type & AUTOFS_TYPE_DIRECT) ?
1227
+ type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
1228
autofs_ptype_expire_direct :
1229
autofs_ptype_expire_indirect;
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);
1237
/* autofs4_notify_daemon() may block */
1238
autofs4_notify_daemon(sbi, wq, type);
1240
- atomic_inc(&wq->wait_ctr);
1242
mutex_unlock(&sbi->wq_mutex);
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);
1251
- /* wq->name is NULL if and only if the lock is already released */
1253
- if (sbi->catatonic) {
1254
- /* We might have slept, so check again for catatonic mode */
1255
- wq->status = -ENOENT;
1262
+ * wq->name.name is NULL iff the lock is already released
1263
+ * or the mount has been made catatonic.
1265
+ if (wq->name.name) {
1266
/* Block all but "shutdown" signals while waiting */
1268
unsigned long irqflags;
1269
@@ -351,7 +445,7 @@ int autofs4_wait(struct autofs_sb_info *
1270
recalc_sigpending();
1271
spin_unlock_irqrestore(¤t->sighand->siglock, irqflags);
1273
- wait_event_interruptible(wq->queue, wq->name == NULL);
1274
+ wait_event_interruptible(wq->queue, wq->name.name == NULL);
1276
spin_lock_irqsave(¤t->sighand->siglock, irqflags);
1277
current->blocked = oldset;
1278
@@ -364,8 +458,10 @@ int autofs4_wait(struct autofs_sb_info *
1279
status = wq->status;
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)
1286
+ mutex_unlock(&sbi->wq_mutex);
1290
@@ -387,16 +483,13 @@ int autofs4_wait_release(struct autofs_s
1293
*wql = wq->next; /* Unlink from chain */
1294
- mutex_unlock(&sbi->wq_mutex);
1296
- wq->name = NULL; /* Do not wait on this queue */
1298
+ kfree(wq->name.name);
1299
+ wq->name.name = NULL; /* Do not wait on this queue */
1300
wq->status = status;
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)
1307
- wake_up_interruptible(&wq->queue);
1308
+ mutex_unlock(&sbi->wq_mutex);
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
1320
- if (!autofs4_follow_mount(&mnt, &dentry))
1321
+ if (!follow_down(&mnt, &dentry))
1324
- /* This is an autofs submount, we can't expire it */
1325
- if (is_autofs4_dentry(dentry))
1327
+ if (is_autofs4_dentry(dentry)) {
1328
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
1330
+ /* This is an autofs submount, we can't expire it */
1331
+ if (sbi->type == AUTOFS_TYPE_INDIRECT)
1335
+ * Otherwise it's an offset mount and we need to check
1336
+ * if we can umount its mount, if there is one.
1338
+ if (!d_mountpoint(dentry))
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
1347
DPRINTK("returning = %d", status);
1354
@@ -259,13 +270,15 @@ static struct dentry *autofs4_expire_dir
1356
timeout = sbi->exp_timeout;
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);
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--;
1368
ino->flags |= AUTOFS_INF_EXPIRING;
1369
+ init_completion(&ino->expire_complete);
1370
spin_unlock(&sbi->fs_lock);
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;
1382
@@ -316,6 +331,9 @@ static struct dentry *autofs4_expire_ind
1383
dentry = dget(dentry);
1384
spin_unlock(&dcache_lock);
1386
+ spin_lock(&sbi->fs_lock);
1387
+ ino = autofs4_dentry_ino(dentry);
1390
* Case 1: (i) indirect mount or top level pseudo direct mount
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);
1396
+ /* Path walk currently on this dentry? */
1397
+ ino_count = atomic_read(&ino->count) + 2;
1398
+ if (atomic_read(&dentry->d_count) > ino_count)
1401
/* Can we umount this guy */
1402
if (autofs4_mount_busy(mnt, dentry))
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)) {
1413
@@ -343,46 +366,80 @@ static struct dentry *autofs4_expire_ind
1415
/* Case 2: tree mount, expire iff entire tree is not busy */
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)
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)) {
1434
- spin_unlock(&sbi->fs_lock);
1436
* Case 3: pseudo direct mount, expire individual leaves
1440
+ /* Path walk currently on this dentry? */
1441
+ ino_count = atomic_read(&ino->count) + 1;
1442
+ if (atomic_read(&dentry->d_count) > ino_count)
1445
expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
1453
+ spin_unlock(&sbi->fs_lock);
1455
spin_lock(&dcache_lock);
1458
+ spin_unlock(&dcache_lock);
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);
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);
1483
+int autofs4_expire_wait(struct dentry *dentry)
1485
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
1486
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
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);
1494
+ DPRINTK("waiting for expire %p name=%.*s",
1495
+ dentry, dentry->d_name.len, dentry->d_name.name);
1497
+ status = autofs4_wait(sbi, dentry, NFY_NONE);
1498
+ wait_for_completion(&ino->expire_complete);
1500
+ DPRINTK("expire done status=%d", status);
1502
+ if (d_unhashed(dentry))
1507
+ spin_unlock(&sbi->fs_lock);
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)
1516
struct autofs_packet_expire pkt;
1517
+ struct autofs_info *ino;
1518
struct dentry *dentry;
1521
memset(&pkt,0,sizeof pkt);
1523
@@ -408,9 +467,15 @@ int autofs4_expire_run(struct super_bloc
1526
if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
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);
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))
1545
- if (sbi->type & AUTOFS_TYPE_DIRECT)
1546
+ if (sbi->type & AUTOFS_TYPE_TRIGGER)
1547
dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
1549
dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
1550
@@ -435,9 +500,16 @@ int autofs4_expire_multi(struct super_bl
1552
/* This is synchronous because it makes the daemon a
1554
- ino->flags |= AUTOFS_INF_EXPIRING;
1555
ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
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;
1562
ino->flags &= ~AUTOFS_INF_EXPIRING;
1563
+ complete_all(&ino->expire_complete);
1564
+ spin_unlock(&sbi->fs_lock);
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
1573
#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
1574
#define AUTOFS_IOC_COUNT 32
1576
+#define AUTOFS_TYPE_TRIGGER (AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET)
1578
#include <linux/kernel.h>
1579
#include <linux/slab.h>
1580
#include <linux/time.h>
1581
@@ -52,7 +54,10 @@ struct autofs_info {
1585
- struct list_head rehash;
1586
+ struct completion expire_complete;
1588
+ struct list_head active;
1589
+ struct list_head expiring;
1591
struct autofs_sb_info *sbi;
1592
unsigned long last_used;
1593
@@ -68,15 +73,14 @@ struct autofs_info {
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 */
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;
1611
@@ -85,15 +89,11 @@ struct autofs_wait_queue {
1613
/* This is for status reporting upon return */
1615
- atomic_t wait_ctr;
1616
+ unsigned int wait_ctr;
1619
#define AUTOFS_SBI_MAGIC 0x6d4a556d
1621
-#define AUTOFS_TYPE_INDIRECT 0x0001
1622
-#define AUTOFS_TYPE_DIRECT 0x0002
1623
-#define AUTOFS_TYPE_OFFSET 0x0004
1625
struct autofs_sb_info {
1628
@@ -112,8 +112,9 @@ struct autofs_sb_info {
1629
struct mutex wq_mutex;
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;
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)
1643
struct autofs_info *inf = autofs4_dentry_ino(dentry);
1646
if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
1650
- spin_lock(&inf->sbi->fs_lock);
1651
- pending = inf->flags & AUTOFS_INF_EXPIRING;
1652
- spin_unlock(&inf->sbi->fs_lock);
1654
+ if (inf->flags & AUTOFS_INF_EXPIRING)
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
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
1676
static void ino_lnkfree(struct autofs_info *ino)
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;
1686
struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
1687
@@ -41,16 +43,18 @@ struct autofs_info *autofs4_init_ino(str
1693
- ino->inode = NULL;
1694
- ino->dentry = NULL;
1697
- INIT_LIST_HEAD(&ino->rehash);
1700
+ ino->inode = NULL;
1701
+ ino->dentry = NULL;
1703
+ INIT_LIST_HEAD(&ino->active);
1704
+ INIT_LIST_HEAD(&ino->expiring);
1705
+ atomic_set(&ino->count, 0);
1709
ino->last_used = jiffies;
1710
- atomic_set(&ino->count, 0);
1714
@@ -159,8 +163,8 @@ void autofs4_kill_sb(struct super_block
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);
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;
1729
- *type = AUTOFS_TYPE_DIRECT | AUTOFS_TYPE_OFFSET;
1730
+ *type = AUTOFS_TYPE_OFFSET;
1734
@@ -329,14 +333,15 @@ int autofs4_fill_super(struct super_bloc
1737
sbi->sub_version = 0;
1739
+ sbi->type = AUTOFS_TYPE_INDIRECT;
1742
mutex_init(&sbi->wq_mutex);
1743
spin_lock_init(&sbi->fs_lock);
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
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;
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)
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
1780
#define AUTOFS_EXP_IMMEDIATE 1
1781
#define AUTOFS_EXP_LEAVES 2
1783
+#define AUTOFS_TYPE_ANY 0x0000
1784
+#define AUTOFS_TYPE_INDIRECT 0x0001
1785
+#define AUTOFS_TYPE_DIRECT 0x0002
1786
+#define AUTOFS_TYPE_OFFSET 0x0004
1788
/* Daemon notification packet types */
1789
enum autofs_notify {
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)