1
Index: linux-2.6.13/fs/autofs4/root.c
2
===================================================================
3
--- linux-2.6.13.orig/fs/autofs4/root.c
4
+++ linux-2.6.13/fs/autofs4/root.c
7
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
8
* Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
9
- * Copyright 2001-2003 Ian Kent <raven@themaw.net>
10
+ * Copyright 2001-2006 Ian Kent <raven@themaw.net>
12
* This file is part of the Linux kernel and is made available under
13
* the terms of the GNU General Public License, version 2, or at your
14
@@ -25,28 +25,28 @@ static int autofs4_dir_rmdir(struct inod
15
static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
16
static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
17
static int autofs4_dir_open(struct inode *inode, struct file *file);
18
-static int autofs4_dir_close(struct inode *inode, struct file *file);
19
-static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir);
20
-static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
21
static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
22
-static int autofs4_dcache_readdir(struct file *, void *, filldir_t);
23
+static void *autofs4_follow_link(struct dentry *, struct nameidata *);
25
+#define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
26
+#define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
28
struct file_operations autofs4_root_operations = {
29
.open = dcache_dir_open,
30
.release = dcache_dir_close,
31
.read = generic_read_dir,
32
- .readdir = autofs4_root_readdir,
33
+ .readdir = dcache_readdir,
34
.ioctl = autofs4_root_ioctl,
37
struct file_operations autofs4_dir_operations = {
38
.open = autofs4_dir_open,
39
- .release = autofs4_dir_close,
40
+ .release = dcache_dir_close,
41
.read = generic_read_dir,
42
- .readdir = autofs4_dir_readdir,
43
+ .readdir = dcache_readdir,
46
-struct inode_operations autofs4_root_inode_operations = {
47
+struct inode_operations autofs4_indirect_root_inode_operations = {
48
.lookup = autofs4_lookup,
49
.unlink = autofs4_dir_unlink,
50
.symlink = autofs4_dir_symlink,
51
@@ -54,6 +54,14 @@ struct inode_operations autofs4_root_ino
52
.rmdir = autofs4_dir_rmdir,
55
+struct inode_operations autofs4_direct_root_inode_operations = {
56
+ .lookup = autofs4_lookup,
57
+ .unlink = autofs4_dir_unlink,
58
+ .mkdir = autofs4_dir_mkdir,
59
+ .rmdir = autofs4_dir_rmdir,
60
+ .follow_link = autofs4_follow_link,
63
struct inode_operations autofs4_dir_inode_operations = {
64
.lookup = autofs4_lookup,
65
.unlink = autofs4_dir_unlink,
66
@@ -62,113 +70,10 @@ struct inode_operations autofs4_dir_inod
67
.rmdir = autofs4_dir_rmdir,
70
-static int autofs4_root_readdir(struct file *file, void *dirent,
73
- struct autofs_sb_info *sbi = autofs4_sbi(file->f_dentry->d_sb);
74
- int oz_mode = autofs4_oz_mode(sbi);
76
- DPRINTK("called, filp->f_pos = %lld", file->f_pos);
79
- * Don't set reghost flag if:
80
- * 1) f_pos is larger than zero -- we've already been here.
81
- * 2) we haven't even enabled reghosting in the 1st place.
82
- * 3) this is the daemon doing a readdir
84
- if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
85
- sbi->needs_reghost = 1;
87
- DPRINTK("needs_reghost = %d", sbi->needs_reghost);
89
- return autofs4_dcache_readdir(file, dirent, filldir);
92
-/* Update usage from here to top of tree, so that scan of
93
- top-level directories will give a useful result */
94
-static void autofs4_update_usage(struct dentry *dentry)
96
- struct dentry *top = dentry->d_sb->s_root;
98
- spin_lock(&dcache_lock);
99
- for(; dentry != top; dentry = dentry->d_parent) {
100
- struct autofs_info *ino = autofs4_dentry_ino(dentry);
103
- update_atime(dentry->d_inode);
104
- ino->last_used = jiffies;
107
- spin_unlock(&dcache_lock);
111
- * From 2.4 kernel readdir.c
113
-static int autofs4_dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
116
- struct dentry *dentry = filp->f_dentry;
121
- if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
127
- if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
133
- struct list_head *list;
136
- spin_lock(&dcache_lock);
137
- list = dentry->d_subdirs.next;
140
- if (list == &dentry->d_subdirs) {
141
- spin_unlock(&dcache_lock);
151
- struct dentry *de = list_entry(list, struct dentry, d_child);
153
- if (!d_unhashed(de) && de->d_inode) {
154
- spin_unlock(&dcache_lock);
155
- if (filldir(dirent, de->d_name.name, de->d_name.len, filp->f_pos, de->d_inode->i_ino, DT_UNKNOWN) < 0)
157
- spin_lock(&dcache_lock);
161
- if (list != &dentry->d_subdirs)
163
- spin_unlock(&dcache_lock);
171
static int autofs4_dir_open(struct inode *inode, struct file *file)
173
struct dentry *dentry = file->f_dentry;
174
- struct vfsmount *mnt = file->f_vfsmnt;
175
struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
178
DPRINTK("file=%p dentry=%p %.*s",
179
file, dentry, dentry->d_name.len, dentry->d_name.name);
180
@@ -176,146 +81,31 @@ static int autofs4_dir_open(struct inode
181
if (autofs4_oz_mode(sbi))
184
- if (autofs4_ispending(dentry)) {
185
- DPRINTK("dentry busy");
189
- if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) {
190
- struct nameidata nd;
193
- /* In case there are stale directory dentrys from a failed mount */
194
- spin_lock(&dcache_lock);
195
- empty = list_empty(&dentry->d_subdirs);
197
+ * An empty directory in an autofs file system is always a
198
+ * mount point. The daemon must have failed to mount this
199
+ * during lookup so it doesn't exist. This can happen, for
200
+ * example, if user space returns an incorrect status for a
201
+ * mount request. Otherwise we're doing a readdir on the
202
+ * autofs file system so just let the libfs routines handle
205
+ if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
206
spin_unlock(&dcache_lock);
209
- d_invalidate(dentry);
211
- nd.flags = LOOKUP_DIRECTORY;
212
- status = (dentry->d_op->d_revalidate)(dentry, &nd);
218
+ spin_unlock(&dcache_lock);
220
- if (d_mountpoint(dentry)) {
221
- struct file *fp = NULL;
222
- struct vfsmount *fp_mnt = mntget(mnt);
223
- struct dentry *fp_dentry = dget(dentry);
225
- if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) {
231
- fp = dentry_open(fp_dentry, fp_mnt, file->f_flags);
232
- status = PTR_ERR(fp);
234
- file->private_data = NULL;
237
- file->private_data = fp;
243
-static int autofs4_dir_close(struct inode *inode, struct file *file)
245
- struct dentry *dentry = file->f_dentry;
246
- struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
248
- DPRINTK("file=%p dentry=%p %.*s",
249
- file, dentry, dentry->d_name.len, dentry->d_name.name);
251
- if (autofs4_oz_mode(sbi))
254
- if (autofs4_ispending(dentry)) {
255
- DPRINTK("dentry busy");
259
- if (d_mountpoint(dentry)) {
260
- struct file *fp = file->private_data;
265
- filp_close(fp, current->files);
266
- file->private_data = NULL;
270
+ return dcache_dir_open(inode, file);
273
-static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
274
+static int try_to_fill_dentry(struct dentry *dentry, int flags)
276
- struct dentry *dentry = file->f_dentry;
277
struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
278
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
281
- DPRINTK("file=%p dentry=%p %.*s",
282
- file, dentry, dentry->d_name.len, dentry->d_name.name);
284
- if (autofs4_oz_mode(sbi))
287
- if (autofs4_ispending(dentry)) {
288
- DPRINTK("dentry busy");
292
- if (d_mountpoint(dentry)) {
293
- struct file *fp = file->private_data;
298
- if (!fp->f_op || !fp->f_op->readdir)
301
- status = vfs_readdir(fp, filldir, dirent);
302
- file->f_pos = fp->f_pos;
304
- autofs4_copy_atime(file, fp);
308
- return autofs4_dcache_readdir(file, dirent, filldir);
311
-static int try_to_fill_dentry(struct dentry *dentry,
312
- struct super_block *sb,
313
- struct autofs_sb_info *sbi, int flags)
315
- struct autofs_info *de_info = autofs4_dentry_ino(dentry);
318
- /* Block on any pending expiry here; invalidate the dentry
319
- when expiration is done to trigger mount request with a new
321
- if (de_info && (de_info->flags & AUTOFS_INF_EXPIRING)) {
322
- DPRINTK("waiting for expire %p name=%.*s",
323
- dentry, dentry->d_name.len, dentry->d_name.name);
325
- status = autofs4_wait(sbi, dentry, NFY_NONE);
327
- DPRINTK("expire done status=%d", status);
330
- * If the directory still exists the mount request must
331
- * continue otherwise it can't be followed at the right
332
- * time during the walk.
334
- status = d_invalidate(dentry);
335
- if (status != -EBUSY)
339
DPRINTK("dentry=%p %.*s ino=%p",
340
dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
342
@@ -328,22 +118,19 @@ static int try_to_fill_dentry(struct den
344
DPRINTK("mount done status=%d", status);
346
- if (status && dentry->d_inode)
347
- return 0; /* Try to get the kernel to invalidate this dentry */
349
/* Turn this into a real negative dentry? */
350
if (status == -ENOENT) {
351
- dentry->d_time = jiffies + AUTOFS_NEGATIVE_TIMEOUT;
352
spin_lock(&dentry->d_lock);
353
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
354
spin_unlock(&dentry->d_lock);
358
/* Return a negative dentry, but leave it "pending" */
362
/* Trigger mount for path component or follow link */
363
- } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) ||
364
+ } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
365
+ flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
366
current->link_count) {
367
DPRINTK("waiting for mount name=%.*s",
368
dentry->d_name.len, dentry->d_name.name);
369
@@ -359,19 +146,96 @@ static int try_to_fill_dentry(struct den
370
spin_lock(&dentry->d_lock);
371
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
372
spin_unlock(&dentry->d_lock);
378
- /* We don't update the usages for the autofs daemon itself, this
379
- is necessary for recursive autofs mounts */
380
- if (!autofs4_oz_mode(sbi))
381
- autofs4_update_usage(dentry);
382
+ /* Initialize expiry counter after successful mount */
384
+ ino->last_used = jiffies;
386
spin_lock(&dentry->d_lock);
387
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
388
spin_unlock(&dentry->d_lock);
394
+/* For autofs direct mounts the follow link triggers the mount */
395
+static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
397
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
398
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
399
+ int oz_mode = autofs4_oz_mode(sbi);
400
+ unsigned int lookup_type;
403
+ DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
404
+ dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
407
+ * For an expire of a covered direct or offset mount we need
408
+ * to beeak out of follow_down() at the autofs mount trigger
409
+ * (d_mounted--), so we can see the expiring flag, and manage
410
+ * the blocking and following here until the expire is completed.
413
+ spin_lock(&sbi->fs_lock);
414
+ if (ino->flags & AUTOFS_INF_EXPIRING) {
415
+ spin_unlock(&sbi->fs_lock);
416
+ /* Follow down to our covering mount. */
417
+ if (!follow_down(&nd->mnt, &nd->dentry))
421
+ spin_unlock(&sbi->fs_lock);
425
+ /* If an expire request is pending everyone must wait. */
426
+ autofs4_expire_wait(dentry);
428
+ /* We trigger a mount for almost all flags */
429
+ lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
430
+ if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
434
+ * If the dentry contains directories then it is an autofs
435
+ * multi-mount with no root mount offset. So don't try to
438
+ spin_lock(&dcache_lock);
439
+ if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
440
+ (!d_mountpoint(dentry) && __simple_empty(dentry))) {
441
+ spin_unlock(&dcache_lock);
443
+ status = try_to_fill_dentry(dentry, 0);
449
+ spin_unlock(&dcache_lock);
452
+ * If there is no root mount it must be an autofs
453
+ * multi-mount with no root offset so we don't need
456
+ if (d_mountpoint(dentry)) {
457
+ if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
468
+ return ERR_PTR(status);
472
@@ -380,47 +244,76 @@ static int try_to_fill_dentry(struct den
473
* yet completely filled in, and revalidate has to delay such
476
-static int autofs4_revalidate(struct dentry * dentry, struct nameidata *nd)
477
+static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
479
- struct inode * dir = dentry->d_parent->d_inode;
480
+ struct inode *dir = dentry->d_parent->d_inode;
481
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
482
int oz_mode = autofs4_oz_mode(sbi);
483
int flags = nd ? nd->flags : 0;
488
+ spin_lock(&sbi->fs_lock);
489
if (autofs4_ispending(dentry)) {
491
- status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
492
+ /* The daemon never causes a mount to trigger */
493
+ spin_unlock(&sbi->fs_lock);
499
+ * If the directory has gone away due to an expire
500
+ * we have been called as ->d_revalidate() and so
501
+ * we need to return false and proceed to ->lookup().
503
+ if (autofs4_expire_wait(dentry) == -EAGAIN)
507
+ * A zero status is success otherwise we have a
508
+ * negative error code.
510
+ status = try_to_fill_dentry(dentry, flags);
516
+ spin_unlock(&sbi->fs_lock);
518
/* Negative dentry.. invalidate if "old" */
519
if (dentry->d_inode == NULL)
520
- return (dentry->d_time - jiffies <= AUTOFS_NEGATIVE_TIMEOUT);
523
/* Check for a non-mountpoint directory with no contents */
524
spin_lock(&dcache_lock);
525
if (S_ISDIR(dentry->d_inode->i_mode) &&
526
!d_mountpoint(dentry) &&
527
- list_empty(&dentry->d_subdirs)) {
528
+ __simple_empty(dentry)) {
529
DPRINTK("dentry=%p %.*s, emptydir",
530
dentry, dentry->d_name.len, dentry->d_name.name);
531
spin_unlock(&dcache_lock);
533
- status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
535
+ /* The daemon never causes a mount to trigger */
540
+ * A zero status is success otherwise we have a
541
+ * negative error code.
543
+ status = try_to_fill_dentry(dentry, flags);
549
spin_unlock(&dcache_lock);
551
- /* Update the usage list */
553
- autofs4_update_usage(dentry);
558
-static void autofs4_dentry_release(struct dentry *de)
559
+void autofs4_dentry_release(struct dentry *de)
561
struct autofs_info *inf;
563
@@ -430,6 +323,17 @@ static void autofs4_dentry_release(struc
567
+ struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
570
+ spin_lock(&sbi->lookup_lock);
571
+ if (!list_empty(&inf->active))
572
+ list_del(&inf->active);
573
+ if (!list_empty(&inf->expiring))
574
+ list_del(&inf->expiring);
575
+ spin_unlock(&sbi->lookup_lock);
581
@@ -449,48 +353,192 @@ static struct dentry_operations autofs4_
582
.d_release = autofs4_dentry_release,
585
+static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
587
+ unsigned int len = name->len;
588
+ unsigned int hash = name->hash;
589
+ const unsigned char *str = name->name;
590
+ struct list_head *p, *head;
592
+ spin_lock(&dcache_lock);
593
+ spin_lock(&sbi->lookup_lock);
594
+ head = &sbi->active_list;
595
+ list_for_each(p, head) {
596
+ struct autofs_info *ino;
597
+ struct dentry *dentry;
600
+ ino = list_entry(p, struct autofs_info, active);
601
+ dentry = ino->dentry;
603
+ spin_lock(&dentry->d_lock);
605
+ /* Already gone? */
606
+ if (atomic_read(&dentry->d_count) == 0)
609
+ qstr = &dentry->d_name;
611
+ if (dentry->d_name.hash != hash)
613
+ if (dentry->d_parent != parent)
616
+ if (qstr->len != len)
618
+ if (memcmp(qstr->name, str, len))
621
+ if (d_unhashed(dentry)) {
623
+ spin_unlock(&dentry->d_lock);
624
+ spin_unlock(&sbi->lookup_lock);
625
+ spin_unlock(&dcache_lock);
629
+ spin_unlock(&dentry->d_lock);
631
+ spin_unlock(&sbi->lookup_lock);
632
+ spin_unlock(&dcache_lock);
637
+static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
639
+ unsigned int len = name->len;
640
+ unsigned int hash = name->hash;
641
+ const unsigned char *str = name->name;
642
+ struct list_head *p, *head;
644
+ spin_lock(&dcache_lock);
645
+ spin_lock(&sbi->lookup_lock);
646
+ head = &sbi->expiring_list;
647
+ list_for_each(p, head) {
648
+ struct autofs_info *ino;
649
+ struct dentry *dentry;
652
+ ino = list_entry(p, struct autofs_info, expiring);
653
+ dentry = ino->dentry;
655
+ spin_lock(&dentry->d_lock);
657
+ /* Bad luck, we've already been dentry_iput */
658
+ if (!dentry->d_inode)
661
+ qstr = &dentry->d_name;
663
+ if (dentry->d_name.hash != hash)
665
+ if (dentry->d_parent != parent)
668
+ if (qstr->len != len)
670
+ if (memcmp(qstr->name, str, len))
673
+ if (d_unhashed(dentry)) {
675
+ spin_unlock(&dentry->d_lock);
676
+ spin_unlock(&sbi->lookup_lock);
677
+ spin_unlock(&dcache_lock);
681
+ spin_unlock(&dentry->d_lock);
683
+ spin_unlock(&sbi->lookup_lock);
684
+ spin_unlock(&dcache_lock);
689
/* Lookups in the root directory */
690
static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
692
struct autofs_sb_info *sbi;
693
+ struct autofs_info *ino;
694
+ struct dentry *expiring, *unhashed;
697
DPRINTK("name = %.*s",
698
dentry->d_name.len, dentry->d_name.name);
700
+ /* File name too long to exist */
701
if (dentry->d_name.len > NAME_MAX)
702
- return ERR_PTR(-ENAMETOOLONG);/* File name too long to exist */
703
+ return ERR_PTR(-ENAMETOOLONG);
705
sbi = autofs4_sbi(dir->i_sb);
707
oz_mode = autofs4_oz_mode(sbi);
709
DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
710
current->pid, process_group(current), sbi->catatonic, oz_mode);
713
- * Mark the dentry incomplete, but add it. This is needed so
714
- * that the VFS layer knows about the dentry, and we can count
715
- * on catching any lookups through the revalidate.
717
- * Let all the hard work be done by the revalidate function that
718
- * needs to be able to do this anyway..
720
- * We need to do this before we release the directory semaphore.
722
- dentry->d_op = &autofs4_root_dentry_operations;
723
+ expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
726
+ * If we are racing with expire the request might not
727
+ * be quite complete but the directory has been removed
728
+ * so it must have been successful, so just wait for it.
730
+ ino = autofs4_dentry_ino(expiring);
731
+ autofs4_expire_wait(expiring);
732
+ spin_lock(&sbi->lookup_lock);
733
+ if (!list_empty(&ino->expiring))
734
+ list_del_init(&ino->expiring);
735
+ spin_unlock(&sbi->lookup_lock);
739
+ unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
744
+ * Mark the dentry incomplete but don't hash it. We do this
745
+ * to serialize our inode creation operations (symlink and
746
+ * mkdir) which prevents deadlock during the callback to
747
+ * the daemon. Subsequent user space lookups for the same
748
+ * dentry are placed on the wait queue while the daemon
749
+ * itself is allowed passage unresticted so the create
750
+ * operation itself can then hash the dentry. Finally,
751
+ * we check for the hashed dentry and return the newly
754
+ dentry->d_op = &autofs4_root_dentry_operations;
757
+ * And we need to ensure that the same dentry is used for
758
+ * all following lookup calls until it is hashed so that
759
+ * the dentry flags are persistent throughout the request.
761
+ ino = autofs4_init_ino(NULL, sbi, 0555);
763
+ return ERR_PTR(-ENOMEM);
765
+ dentry->d_fsdata = ino;
766
+ ino->dentry = dentry;
768
+ spin_lock(&sbi->lookup_lock);
769
+ list_add(&ino->active, &sbi->active_list);
770
+ spin_unlock(&sbi->lookup_lock);
772
+ d_instantiate(dentry, NULL);
776
spin_lock(&dentry->d_lock);
777
dentry->d_flags |= DCACHE_AUTOFS_PENDING;
778
spin_unlock(&dentry->d_lock);
780
- dentry->d_fsdata = NULL;
781
- d_add(dentry, NULL);
783
- if (dentry->d_op && dentry->d_op->d_revalidate) {
785
- (dentry->d_op->d_revalidate)(dentry, nd);
787
+ if (dentry->d_op && dentry->d_op->d_revalidate) {
789
+ (dentry->d_op->d_revalidate)(dentry, nd);
795
@@ -504,19 +552,47 @@ static struct dentry *autofs4_lookup(str
796
if (sigismember (sigset, SIGKILL) ||
797
sigismember (sigset, SIGQUIT) ||
798
sigismember (sigset, SIGINT)) {
801
return ERR_PTR(-ERESTARTNOINTR);
805
+ spin_lock(&dentry->d_lock);
806
+ dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
807
+ spin_unlock(&dentry->d_lock);
812
* If this dentry is unhashed, then we shouldn't honour this
813
- * lookup even if the dentry is positive. Returning ENOENT here
814
- * doesn't do the right thing for all system calls, but it should
815
- * be OK for the operations we permit from an autofs.
816
+ * lookup. Returning ENOENT here doesn't do the right thing
817
+ * for all system calls, but it should be OK for the operations
818
+ * we permit from an autofs.
820
- if ( dentry->d_inode && d_unhashed(dentry) )
821
- return ERR_PTR(-ENOENT);
822
+ if (!oz_mode && d_unhashed(dentry)) {
824
+ * A user space application can (and has done in the past)
825
+ * remove and re-create this directory during the callback.
826
+ * This can leave us with an unhashed dentry, but a
827
+ * successful mount! So we need to perform another
828
+ * cached lookup in case the dentry now exists.
830
+ struct dentry *parent = dentry->d_parent;
831
+ struct dentry *new = d_lookup(parent, &dentry->d_name);
835
+ dentry = ERR_PTR(-ENOENT);
848
@@ -527,6 +603,7 @@ static int autofs4_dir_symlink(struct in
850
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
851
struct autofs_info *ino = autofs4_dentry_ino(dentry);
852
+ struct autofs_info *p_ino;
856
@@ -537,21 +614,32 @@ static int autofs4_dir_symlink(struct in
859
ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
865
- ino->size = strlen(symname);
866
- ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
867
+ spin_lock(&sbi->lookup_lock);
868
+ if (!list_empty(&ino->active))
869
+ list_del_init(&ino->active);
870
+ spin_unlock(&sbi->lookup_lock);
875
+ ino->size = strlen(symname);
876
+ cp = kmalloc(ino->size + 1, GFP_KERNEL);
878
+ if (!dentry->d_fsdata)
885
inode = autofs4_get_inode(dir->i_sb, ino);
886
- d_instantiate(dentry, inode);
889
+ if (!dentry->d_fsdata)
893
+ d_add(dentry, inode);
895
if (dir == dir->i_sb->s_root->d_inode)
896
dentry->d_op = &autofs4_root_dentry_operations;
897
@@ -560,8 +648,13 @@ static int autofs4_dir_symlink(struct in
899
dentry->d_fsdata = ino;
900
ino->dentry = dget(dentry);
901
+ atomic_inc(&ino->count);
902
+ p_ino = autofs4_dentry_ino(dentry->d_parent);
903
+ if (p_ino && dentry->d_parent != dentry)
904
+ atomic_inc(&p_ino->count);
907
+ ino->u.symlink = cp;
908
dir->i_mtime = CURRENT_TIME;
911
@@ -573,9 +666,9 @@ static int autofs4_dir_symlink(struct in
912
* Normal filesystems would do a "d_delete()" to tell the VFS dcache
913
* that the file no longer exists. However, doing that means that the
914
* VFS layer can turn the dentry into a negative dentry. We don't want
915
- * this, because since the unlink is probably the result of an expire.
916
- * We simply d_drop it, which allows the dentry lookup to remount it
918
+ * this, because the unlink is probably the result of an expire.
919
+ * We simply d_drop it and add it to a expiring list in the super block,
920
+ * which allows the dentry lookup to check for an incomplete expire.
922
* If a process is blocked on the dentry waiting for the expire to finish,
923
* it will invalidate the dentry and try to mount with a new one.
924
@@ -586,11 +679,17 @@ static int autofs4_dir_unlink(struct ino
926
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
927
struct autofs_info *ino = autofs4_dentry_ino(dentry);
928
+ struct autofs_info *p_ino;
930
/* This allows root to remove symlinks */
931
if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) )
934
+ if (atomic_dec_and_test(&ino->count)) {
935
+ p_ino = autofs4_dentry_ino(dentry->d_parent);
936
+ if (p_ino && dentry->d_parent != dentry)
937
+ atomic_dec(&p_ino->count);
941
dentry->d_inode->i_size = 0;
942
@@ -598,7 +697,15 @@ static int autofs4_dir_unlink(struct ino
944
dir->i_mtime = CURRENT_TIME;
947
+ spin_lock(&dcache_lock);
948
+ spin_lock(&sbi->lookup_lock);
949
+ if (list_empty(&ino->expiring))
950
+ list_add(&ino->expiring, &sbi->expiring_list);
951
+ spin_unlock(&sbi->lookup_lock);
952
+ spin_lock(&dentry->d_lock);
954
+ spin_unlock(&dentry->d_lock);
955
+ spin_unlock(&dcache_lock);
959
@@ -607,7 +714,11 @@ static int autofs4_dir_rmdir(struct inod
961
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
962
struct autofs_info *ino = autofs4_dentry_ino(dentry);
963
+ struct autofs_info *p_ino;
965
+ DPRINTK("dentry %p, removing %.*s",
966
+ dentry, dentry->d_name.len, dentry->d_name.name);
968
if (!autofs4_oz_mode(sbi))
971
@@ -616,13 +727,21 @@ static int autofs4_dir_rmdir(struct inod
972
spin_unlock(&dcache_lock);
975
+ spin_lock(&sbi->lookup_lock);
976
+ if (list_empty(&ino->expiring))
977
+ list_add(&ino->expiring, &sbi->expiring_list);
978
+ spin_unlock(&sbi->lookup_lock);
979
spin_lock(&dentry->d_lock);
981
spin_unlock(&dentry->d_lock);
982
spin_unlock(&dcache_lock);
984
+ if (atomic_dec_and_test(&ino->count)) {
985
+ p_ino = autofs4_dentry_ino(dentry->d_parent);
986
+ if (p_ino && dentry->d_parent != dentry)
987
+ atomic_dec(&p_ino->count);
991
dentry->d_inode->i_size = 0;
992
dentry->d_inode->i_nlink = 0;
994
@@ -636,6 +755,7 @@ static int autofs4_dir_mkdir(struct inod
996
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
997
struct autofs_info *ino = autofs4_dentry_ino(dentry);
998
+ struct autofs_info *p_ino;
1001
if ( !autofs4_oz_mode(sbi) )
1002
@@ -645,11 +765,21 @@ static int autofs4_dir_mkdir(struct inod
1003
dentry, dentry->d_name.len, dentry->d_name.name);
1005
ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
1011
+ spin_lock(&sbi->lookup_lock);
1012
+ if (!list_empty(&ino->active))
1013
+ list_del_init(&ino->active);
1014
+ spin_unlock(&sbi->lookup_lock);
1016
inode = autofs4_get_inode(dir->i_sb, ino);
1017
- d_instantiate(dentry, inode);
1019
+ if (!dentry->d_fsdata)
1023
+ d_add(dentry, inode);
1025
if (dir == dir->i_sb->s_root->d_inode)
1026
dentry->d_op = &autofs4_root_dentry_operations;
1027
@@ -658,6 +788,10 @@ static int autofs4_dir_mkdir(struct inod
1029
dentry->d_fsdata = ino;
1030
ino->dentry = dget(dentry);
1031
+ atomic_inc(&ino->count);
1032
+ p_ino = autofs4_dentry_ino(dentry->d_parent);
1033
+ if (p_ino && dentry->d_parent != dentry)
1034
+ atomic_inc(&p_ino->count);
1037
dir->i_mtime = CURRENT_TIME;
1038
@@ -697,51 +831,13 @@ static inline int autofs4_get_protosubve
1042
- * Tells the daemon whether we need to reghost or not. Also, clears
1043
- * the reghost_needed flag.
1045
-static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
1049
- DPRINTK("returning %d", sbi->needs_reghost);
1051
- status = put_user(sbi->needs_reghost, p);
1055
- sbi->needs_reghost = 0;
1060
- * Enable / Disable reghosting ioctl() operation
1062
-static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
1067
- status = get_user(val, p);
1069
- DPRINTK("reghost = %d", val);
1074
- /* turn on/off reghosting, with the val */
1075
- sbi->reghost_enabled = val;
1080
* Tells the daemon whether it can umount the autofs mount.
1082
static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
1086
- if (may_umount(mnt) == 0)
1087
+ if (may_umount(mnt))
1090
DPRINTK("returning %d", status);
1091
@@ -798,11 +894,6 @@ static int autofs4_root_ioctl(struct ino
1092
case AUTOFS_IOC_SETTIMEOUT:
1093
return autofs4_get_set_timeout(sbi, p);
1095
- case AUTOFS_IOC_TOGGLEREGHOST:
1096
- return autofs4_toggle_reghost(sbi, p);
1097
- case AUTOFS_IOC_ASKREGHOST:
1098
- return autofs4_ask_reghost(sbi, p);
1100
case AUTOFS_IOC_ASKUMOUNT:
1101
return autofs4_ask_umount(filp->f_vfsmnt, p);
1103
Index: linux-2.6.13/fs/autofs4/autofs_i.h
1104
===================================================================
1105
--- linux-2.6.13.orig/fs/autofs4/autofs_i.h
1106
+++ linux-2.6.13/fs/autofs4/autofs_i.h
1108
* linux/fs/autofs/autofs_i.h
1110
* Copyright 1997-1998 Transmeta Corporation - All Rights Reserved
1111
+ * Copyright 2005-2006 Ian Kent <raven@themaw.net>
1113
* This file is part of the Linux kernel and is made available under
1114
* the terms of the GNU General Public License, version 2, or at your
1116
#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
1117
#define AUTOFS_IOC_COUNT 32
1119
+#define AUTOFS_TYPE_TRIGGER (AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET)
1121
#include <linux/kernel.h>
1122
#include <linux/slab.h>
1123
#include <linux/time.h>
1126
#define AUTOFS_SUPER_MAGIC 0x0187
1129
- * If the daemon returns a negative response (AUTOFS_IOC_FAIL) then the
1130
- * kernel will keep the negative response cached for up to the time given
1131
- * here, although the time can be shorter if the kernel throws the dcache
1132
- * entry away. This probably should be settable from user space.
1134
-#define AUTOFS_NEGATIVE_TIMEOUT (60*HZ) /* 1 minute */
1136
/* Unified info structure. This is pointed to by both the dentry and
1137
inode structures. Each file in the filesystem has an instance of this
1138
structure. It holds a reference to the dentry, so dentries are never
1139
@@ -60,8 +55,14 @@ struct autofs_info {
1143
+ struct completion expire_complete;
1145
+ struct list_head active;
1146
+ struct list_head expiring;
1148
struct autofs_sb_info *sbi;
1149
unsigned long last_used;
1154
@@ -73,38 +74,48 @@ struct autofs_info {
1157
#define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */
1158
+#define AUTOFS_INF_MOUNTPOINT (1<<1) /* mountpoint status for direct expire */
1160
struct autofs_wait_queue {
1161
wait_queue_head_t queue;
1162
struct autofs_wait_queue *next;
1163
autofs_wqt_t wait_queue_token;
1164
/* We use the following to see what we are waiting for */
1175
/* This is for status reporting upon return */
1177
- atomic_t notified;
1178
- atomic_t wait_ctr;
1179
+ unsigned int wait_ctr;
1182
#define AUTOFS_SBI_MAGIC 0x6d4a556d
1184
struct autofs_sb_info {
1186
- struct dentry *root;
1195
unsigned long exp_timeout;
1196
+ unsigned int type;
1197
int reghost_enabled;
1199
struct super_block *sb;
1200
struct semaphore wq_sem;
1202
struct autofs_wait_queue *queues; /* Wait queue pointer */
1203
+ spinlock_t lookup_lock;
1204
+ struct list_head active_list;
1205
+ struct list_head expiring_list;
1208
static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
1209
@@ -129,18 +140,14 @@ static inline int autofs4_oz_mode(struct
1210
static inline int autofs4_ispending(struct dentry *dentry)
1212
struct autofs_info *inf = autofs4_dentry_ino(dentry);
1215
if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
1219
- spin_lock(&inf->sbi->fs_lock);
1220
- pending = inf->flags & AUTOFS_INF_EXPIRING;
1221
- spin_unlock(&inf->sbi->fs_lock);
1223
+ if (inf->flags & AUTOFS_INF_EXPIRING)
1230
static inline void autofs4_copy_atime(struct file *src, struct file *dst)
1231
@@ -154,6 +161,7 @@ void autofs4_free_ino(struct autofs_info
1234
int is_autofs4_dentry(struct dentry *);
1235
+int autofs4_expire_wait(struct dentry *dentry);
1236
int autofs4_expire_run(struct super_block *, struct vfsmount *,
1237
struct autofs_sb_info *,
1238
struct autofs_packet_expire __user *);
1239
@@ -165,6 +173,8 @@ int autofs4_expire_multi(struct super_bl
1240
extern struct inode_operations autofs4_symlink_inode_operations;
1241
extern struct inode_operations autofs4_dir_inode_operations;
1242
extern struct inode_operations autofs4_root_inode_operations;
1243
+extern struct inode_operations autofs4_indirect_root_inode_operations;
1244
+extern struct inode_operations autofs4_direct_root_inode_operations;
1245
extern struct file_operations autofs4_dir_operations;
1246
extern struct file_operations autofs4_root_operations;
1248
@@ -175,13 +185,6 @@ struct autofs_info *autofs4_init_ino(str
1250
/* Queue management functions */
1259
int autofs4_wait(struct autofs_sb_info *,struct dentry *, enum autofs_notify);
1260
int autofs4_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
1261
void autofs4_catatonic_mode(struct autofs_sb_info *);
1262
@@ -199,12 +202,22 @@ static inline int autofs4_follow_mount(s
1266
+static inline u32 autofs4_get_dev(struct autofs_sb_info *sbi)
1268
+ return new_encode_dev(sbi->sb->s_dev);
1271
+static inline u64 autofs4_get_ino(struct autofs_sb_info *sbi)
1273
+ return sbi->sb->s_root->d_inode->i_ino;
1276
static inline int simple_positive(struct dentry *dentry)
1278
return dentry->d_inode && !d_unhashed(dentry);
1281
-static inline int simple_empty_nolock(struct dentry *dentry)
1282
+static inline int __simple_empty(struct dentry *dentry)
1284
struct dentry *child;
1286
@@ -216,3 +229,6 @@ static inline int simple_empty_nolock(st
1291
+void autofs4_dentry_release(struct dentry *);
1292
+extern void autofs4_kill_sb(struct super_block *);
1293
Index: linux-2.6.13/fs/autofs4/expire.c
1294
===================================================================
1295
--- linux-2.6.13.orig/fs/autofs4/expire.c
1296
+++ linux-2.6.13/fs/autofs4/expire.c
1299
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
1300
* Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
1301
- * Copyright 2001-2003 Ian Kent <raven@themaw.net>
1302
+ * Copyright 2001-2006 Ian Kent <raven@themaw.net>
1304
* This file is part of the Linux kernel and is made available under
1305
* the terms of the GNU General Public License, version 2, or at your
1308
static unsigned long now;
1310
-/* Check if a dentry can be expired return 1 if it can else return 0 */
1311
+/* Check if a dentry can be expired */
1312
static inline int autofs4_can_expire(struct dentry *dentry,
1313
unsigned long timeout, int do_now)
1315
@@ -41,14 +41,14 @@ static inline int autofs4_can_expire(str
1316
attempts if expire fails the first time */
1317
ino->last_used = now;
1323
-/* Check a mount point for busyness return 1 if not busy, otherwise */
1324
-static int autofs4_check_mount(struct vfsmount *mnt, struct dentry *dentry)
1325
+/* Check a mount point for busyness */
1326
+static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry)
1329
+ struct dentry *top = dentry;
1332
DPRINTK("dentry %p %.*s",
1333
dentry, (int)dentry->d_name.len, dentry->d_name.name);
1334
@@ -56,95 +56,163 @@ static int autofs4_check_mount(struct vf
1338
- if (!autofs4_follow_mount(&mnt, &dentry))
1339
+ if (!follow_down(&mnt, &dentry))
1342
- /* This is an autofs submount, we can't expire it */
1343
- if (is_autofs4_dentry(dentry))
1344
+ if (is_autofs4_dentry(dentry)) {
1345
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
1347
+ /* This is an autofs submount, we can't expire it */
1348
+ if (sbi->type == AUTOFS_TYPE_INDIRECT)
1352
+ * Otherwise it's an offset mount and we need to check
1353
+ * if we can umount its mount, if there is one.
1355
+ if (!d_mountpoint(dentry))
1359
+ /* Update the expiry counter if fs is busy */
1360
+ if (!may_umount_tree(mnt)) {
1361
+ struct autofs_info *ino = autofs4_dentry_ino(top);
1362
+ ino->last_used = jiffies;
1366
- /* The big question */
1367
- if (may_umount_tree(mnt) == 0)
1371
DPRINTK("returning = %d", status);
1379
+ * Calculate next entry in top down tree traversal.
1380
+ * From next_mnt in namespace.c - elegant.
1382
+static struct dentry *next_dentry(struct dentry *p, struct dentry *root)
1384
+ struct list_head *next = p->d_subdirs.next;
1386
+ if (next == &p->d_subdirs) {
1390
+ next = p->d_child.next;
1391
+ if (next != &p->d_parent->d_subdirs)
1396
+ return list_entry(next, struct dentry, d_child);
1400
+ * Check a direct mount point for busyness.
1401
+ * Direct mounts have similar expiry semantics to tree mounts.
1402
+ * The tree is not busy iff no mountpoints are busy and there are no
1403
+ * autofs submounts.
1405
+static int autofs4_direct_busy(struct vfsmount *mnt,
1406
+ struct dentry *top,
1407
+ unsigned long timeout,
1410
+ DPRINTK("top %p %.*s",
1411
+ top, (int) top->d_name.len, top->d_name.name);
1413
+ /* If it's busy update the expiry counters */
1414
+ if (!may_umount_tree(mnt)) {
1415
+ struct autofs_info *ino = autofs4_dentry_ino(top);
1417
+ ino->last_used = jiffies;
1421
+ /* Timeout of a direct mount is determined by its top dentry */
1422
+ if (!autofs4_can_expire(top, timeout, do_now))
1428
/* Check a directory tree of mount points for busyness
1429
* The tree is not busy iff no mountpoints are busy
1430
- * Return 1 if the tree is busy or 0 otherwise
1432
-static int autofs4_check_tree(struct vfsmount *mnt,
1433
- struct dentry *top,
1434
- unsigned long timeout,
1436
+static int autofs4_tree_busy(struct vfsmount *mnt,
1437
+ struct dentry *top,
1438
+ unsigned long timeout,
1441
- struct dentry *this_parent = top;
1442
- struct list_head *next;
1443
+ struct autofs_info *top_ino = autofs4_dentry_ino(top);
1446
- DPRINTK("parent %p %.*s",
1447
+ DPRINTK("top %p %.*s",
1448
top, (int)top->d_name.len, top->d_name.name);
1450
/* Negative dentry - give up */
1451
if (!simple_positive(top))
1454
- /* Timeout of a tree mount is determined by its top dentry */
1455
- if (!autofs4_can_expire(top, timeout, do_now))
1458
- /* Is someone visiting anywhere in the tree ? */
1459
- if (may_umount_tree(mnt))
1463
spin_lock(&dcache_lock);
1465
- next = this_parent->d_subdirs.next;
1467
- while (next != &this_parent->d_subdirs) {
1468
- struct dentry *dentry = list_entry(next, struct dentry, d_child);
1470
+ for (p = top; p; p = next_dentry(p, top)) {
1471
/* Negative dentry - give up */
1472
- if (!simple_positive(dentry)) {
1473
- next = next->next;
1474
+ if (!simple_positive(p))
1478
DPRINTK("dentry %p %.*s",
1479
- dentry, (int)dentry->d_name.len, dentry->d_name.name);
1480
+ p, (int) p->d_name.len, p->d_name.name);
1482
- if (!simple_empty_nolock(dentry)) {
1483
- this_parent = dentry;
1487
- dentry = dget(dentry);
1489
spin_unlock(&dcache_lock);
1491
- if (d_mountpoint(dentry)) {
1492
- /* First busy => tree busy */
1493
- if (!autofs4_check_mount(mnt, dentry)) {
1497
+ * Is someone visiting anywhere in the subtree ?
1498
+ * If there's no mount we need to check the usage
1499
+ * count for the autofs dentry.
1500
+ * If the fs is busy update the expiry counter.
1502
+ if (d_mountpoint(p)) {
1503
+ if (autofs4_mount_busy(mnt, p)) {
1504
+ top_ino->last_used = jiffies;
1510
+ struct autofs_info *ino = autofs4_dentry_ino(p);
1511
+ unsigned int ino_count = atomic_read(&ino->count);
1515
+ * Clean stale dentries below that have not been
1516
+ * invalidated after a mount fail during lookup
1520
+ /* allow for dget above and top is already dgot */
1526
+ if (atomic_read(&p->d_count) > ino_count) {
1527
+ top_ino->last_used = jiffies;
1533
spin_lock(&dcache_lock);
1534
- next = next->next;
1537
- if (this_parent != top) {
1538
- next = this_parent->d_child.next;
1539
- this_parent = this_parent->d_parent;
1542
spin_unlock(&dcache_lock);
1545
+ /* Timeout of a tree mount is ultimately determined by its top dentry */
1546
+ if (!autofs4_can_expire(top, timeout, do_now))
1552
static struct dentry *autofs4_check_leaves(struct vfsmount *mnt,
1553
@@ -152,58 +220,70 @@ static struct dentry *autofs4_check_leav
1554
unsigned long timeout,
1557
- struct dentry *this_parent = parent;
1558
- struct list_head *next;
1561
DPRINTK("parent %p %.*s",
1562
parent, (int)parent->d_name.len, parent->d_name.name);
1564
spin_lock(&dcache_lock);
1566
- next = this_parent->d_subdirs.next;
1568
- while (next != &this_parent->d_subdirs) {
1569
- struct dentry *dentry = list_entry(next, struct dentry, d_child);
1571
+ for (p = parent; p; p = next_dentry(p, parent)) {
1572
/* Negative dentry - give up */
1573
- if (!simple_positive(dentry)) {
1574
- next = next->next;
1575
+ if (!simple_positive(p))
1579
DPRINTK("dentry %p %.*s",
1580
- dentry, (int)dentry->d_name.len, dentry->d_name.name);
1582
- if (!list_empty(&dentry->d_subdirs)) {
1583
- this_parent = dentry;
1586
+ p, (int) p->d_name.len, p->d_name.name);
1588
- dentry = dget(dentry);
1590
spin_unlock(&dcache_lock);
1592
- if (d_mountpoint(dentry)) {
1593
- /* Can we expire this guy */
1594
- if (!autofs4_can_expire(dentry, timeout, do_now))
1597
+ if (d_mountpoint(p)) {
1598
/* Can we umount this guy */
1599
- if (autofs4_check_mount(mnt, dentry))
1601
+ if (autofs4_mount_busy(mnt, p))
1604
+ /* Can we expire this guy */
1605
+ if (autofs4_can_expire(p, timeout, do_now))
1611
spin_lock(&dcache_lock);
1612
- next = next->next;
1614
+ spin_unlock(&dcache_lock);
1618
+/* Check if we can expire a direct mount (possibly a tree) */
1619
+static struct dentry *autofs4_expire_direct(struct super_block *sb,
1620
+ struct vfsmount *mnt,
1621
+ struct autofs_sb_info *sbi,
1624
+ unsigned long timeout;
1625
+ struct dentry *root = dget(sb->s_root);
1626
+ int do_now = how & AUTOFS_EXP_IMMEDIATE;
1628
+ if (!sbi->exp_timeout || !root)
1632
+ timeout = sbi->exp_timeout;
1634
- if (this_parent != parent) {
1635
- next = this_parent->d_child.next;
1636
- this_parent = this_parent->d_parent;
1638
+ spin_lock(&sbi->fs_lock);
1639
+ if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
1640
+ struct autofs_info *ino = autofs4_dentry_ino(root);
1641
+ if (d_mountpoint(root)) {
1642
+ ino->flags |= AUTOFS_INF_MOUNTPOINT;
1643
+ root->d_mounted--;
1645
+ ino->flags |= AUTOFS_INF_EXPIRING;
1646
+ init_completion(&ino->expire_complete);
1647
+ spin_unlock(&sbi->fs_lock);
1650
- spin_unlock(&dcache_lock);
1651
+ spin_unlock(&sbi->fs_lock);
1656
@@ -214,10 +294,10 @@ cont:
1657
* - it is unused by any user process
1658
* - it has been unused for exp_timeout time
1660
-static struct dentry *autofs4_expire(struct super_block *sb,
1661
- struct vfsmount *mnt,
1662
- struct autofs_sb_info *sbi,
1664
+static struct dentry *autofs4_expire_indirect(struct super_block *sb,
1665
+ struct vfsmount *mnt,
1666
+ struct autofs_sb_info *sbi,
1669
unsigned long timeout;
1670
struct dentry *root = sb->s_root;
1671
@@ -225,6 +305,8 @@ static struct dentry *autofs4_expire(str
1672
struct list_head *next;
1673
int do_now = how & AUTOFS_EXP_IMMEDIATE;
1674
int exp_leaves = how & AUTOFS_EXP_LEAVES;
1675
+ struct autofs_info *ino;
1676
+ unsigned int ino_count;
1678
if ( !sbi->exp_timeout || !root )
1680
@@ -241,7 +323,7 @@ static struct dentry *autofs4_expire(str
1681
struct dentry *dentry = list_entry(next, struct dentry, d_child);
1683
/* Negative dentry - give up */
1684
- if ( !simple_positive(dentry) ) {
1685
+ if (!simple_positive(dentry)) {
1689
@@ -249,66 +331,116 @@ static struct dentry *autofs4_expire(str
1690
dentry = dget(dentry);
1691
spin_unlock(&dcache_lock);
1693
- /* Case 1: indirect mount or top level direct mount */
1694
+ spin_lock(&sbi->fs_lock);
1695
+ ino = autofs4_dentry_ino(dentry);
1698
+ * Case 1: (i) indirect mount or top level pseudo direct mount
1700
+ * (ii) indirect mount with offset mount, check the "/"
1701
+ * offset (autofs-5.0+).
1703
if (d_mountpoint(dentry)) {
1704
DPRINTK("checking mountpoint %p %.*s",
1705
dentry, (int)dentry->d_name.len, dentry->d_name.name);
1707
- /* Can we expire this guy */
1708
- if (!autofs4_can_expire(dentry, timeout, do_now))
1709
+ /* Path walk currently on this dentry? */
1710
+ ino_count = atomic_read(&ino->count) + 2;
1711
+ if (atomic_read(&dentry->d_count) > ino_count)
1714
/* Can we umount this guy */
1715
- if (autofs4_check_mount(mnt, dentry)) {
1716
+ if (autofs4_mount_busy(mnt, dentry))
1719
+ /* Can we expire this guy */
1720
+ if (autofs4_can_expire(dentry, timeout, do_now)) {
1728
- if ( simple_empty(dentry) )
1729
+ if (simple_empty(dentry))
1732
/* Case 2: tree mount, expire iff entire tree is not busy */
1734
- /* Lock the tree as we must expire as a whole */
1735
- spin_lock(&sbi->fs_lock);
1736
- if (autofs4_check_tree(mnt, dentry, timeout, do_now)) {
1737
- struct autofs_info *inf = autofs4_dentry_ino(dentry);
1739
- /* Set this flag early to catch sys_chdir and the like */
1740
- inf->flags |= AUTOFS_INF_EXPIRING;
1741
- spin_unlock(&sbi->fs_lock);
1742
+ /* Path walk currently on this dentry? */
1743
+ ino_count = atomic_read(&ino->count) + 1;
1744
+ if (atomic_read(&dentry->d_count) > ino_count)
1747
+ if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
1752
- spin_unlock(&sbi->fs_lock);
1753
- /* Case 3: direct mount, expire individual leaves */
1755
+ * Case 3: pseudo direct mount, expire individual leaves
1759
+ /* Path walk currently on this dentry? */
1760
+ ino_count = atomic_read(&ino->count) + 1;
1761
+ if (atomic_read(&dentry->d_count) > ino_count)
1764
expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
1772
+ spin_unlock(&sbi->fs_lock);
1774
spin_lock(&dcache_lock);
1777
+ spin_unlock(&dcache_lock);
1781
- DPRINTK("returning %p %.*s",
1782
- expired, (int)expired->d_name.len, expired->d_name.name);
1783
- spin_lock(&dcache_lock);
1784
- list_del(&expired->d_parent->d_subdirs);
1785
- list_add(&expired->d_parent->d_subdirs, &expired->d_child);
1786
- spin_unlock(&dcache_lock);
1790
+ DPRINTK("returning %p %.*s",
1791
+ expired, (int)expired->d_name.len, expired->d_name.name);
1792
+ ino = autofs4_dentry_ino(expired);
1793
+ ino->flags |= AUTOFS_INF_EXPIRING;
1794
+ init_completion(&ino->expire_complete);
1795
+ spin_unlock(&sbi->fs_lock);
1796
+ spin_lock(&dcache_lock);
1797
+ list_del(&expired->d_parent->d_subdirs);
1798
+ list_add(&expired->d_parent->d_subdirs, &expired->d_child);
1799
spin_unlock(&dcache_lock);
1804
+int autofs4_expire_wait(struct dentry *dentry)
1806
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
1807
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
1810
+ /* Block on any pending expire */
1811
+ spin_lock(&sbi->fs_lock);
1812
+ if (ino->flags & AUTOFS_INF_EXPIRING) {
1813
+ spin_unlock(&sbi->fs_lock);
1815
+ DPRINTK("waiting for expire %p name=%.*s",
1816
+ dentry, dentry->d_name.len, dentry->d_name.name);
1818
+ status = autofs4_wait(sbi, dentry, NFY_NONE);
1819
+ wait_for_completion(&ino->expire_complete);
1821
+ DPRINTK("expire done status=%d", status);
1823
+ if (d_unhashed(dentry))
1828
+ spin_unlock(&sbi->fs_lock);
1833
/* Perform an expiry operation */
1834
@@ -318,14 +450,16 @@ int autofs4_expire_run(struct super_bloc
1835
struct autofs_packet_expire __user *pkt_p)
1837
struct autofs_packet_expire pkt;
1838
+ struct autofs_info *ino;
1839
struct dentry *dentry;
1842
memset(&pkt,0,sizeof pkt);
1844
pkt.hdr.proto_version = sbi->version;
1845
pkt.hdr.type = autofs_ptype_expire;
1847
- if ((dentry = autofs4_expire(sb, mnt, sbi, 0)) == NULL)
1848
+ if ((dentry = autofs4_expire_indirect(sb, mnt, sbi, 0)) == NULL)
1851
pkt.len = dentry->d_name.len;
1852
@@ -334,9 +468,15 @@ int autofs4_expire_run(struct super_bloc
1855
if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
1860
+ spin_lock(&sbi->fs_lock);
1861
+ ino = autofs4_dentry_ino(dentry);
1862
+ ino->flags &= ~AUTOFS_INF_EXPIRING;
1863
+ complete_all(&ino->expire_complete);
1864
+ spin_unlock(&sbi->fs_lock);
1869
/* Call repeatedly until it returns -EAGAIN, meaning there's nothing
1870
@@ -351,17 +491,29 @@ int autofs4_expire_multi(struct super_bl
1871
if (arg && get_user(do_now, arg))
1874
- if ((dentry = autofs4_expire(sb, mnt, sbi, do_now)) != NULL) {
1875
- struct autofs_info *de_info = autofs4_dentry_ino(dentry);
1876
+ if (sbi->type & AUTOFS_TYPE_TRIGGER)
1877
+ dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
1879
+ dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
1882
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
1884
/* This is synchronous because it makes the daemon a
1886
- de_info->flags |= AUTOFS_INF_EXPIRING;
1887
ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
1888
- de_info->flags &= ~AUTOFS_INF_EXPIRING;
1890
+ spin_lock(&sbi->fs_lock);
1891
+ if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
1892
+ sb->s_root->d_mounted++;
1893
+ ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
1895
+ ino->flags &= ~AUTOFS_INF_EXPIRING;
1896
+ complete_all(&ino->expire_complete);
1897
+ spin_unlock(&sbi->fs_lock);
1905
Index: linux-2.6.13/fs/autofs4/inode.c
1906
===================================================================
1907
--- linux-2.6.13.orig/fs/autofs4/inode.c
1908
+++ linux-2.6.13/fs/autofs4/inode.c
1910
* linux/fs/autofs/inode.c
1912
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
1913
+ * Copyright 2005-2006 Ian Kent <raven@themaw.net>
1915
* This file is part of the Linux kernel and is made available under
1916
* the terms of the GNU General Public License, version 2, or at your
1918
#include <linux/kernel.h>
1919
#include <linux/slab.h>
1920
#include <linux/file.h>
1921
+#include <linux/seq_file.h>
1922
#include <linux/pagemap.h>
1923
#include <linux/parser.h>
1924
#include <linux/bitops.h>
1925
@@ -41,12 +43,17 @@ struct autofs_info *autofs4_init_ino(str
1931
- ino->inode = NULL;
1932
- ino->dentry = NULL;
1936
+ ino->inode = NULL;
1937
+ ino->dentry = NULL;
1939
+ INIT_LIST_HEAD(&ino->active);
1940
+ INIT_LIST_HEAD(&ino->expiring);
1941
+ atomic_set(&ino->count, 0);
1945
ino->last_used = jiffies;
1948
@@ -66,10 +73,19 @@ struct autofs_info *autofs4_init_ino(str
1950
void autofs4_free_ino(struct autofs_info *ino)
1952
+ struct autofs_info *p_ino;
1955
ino->dentry->d_fsdata = NULL;
1956
- if (ino->dentry->d_inode)
1957
+ if (ino->dentry->d_inode) {
1958
+ struct dentry *parent = ino->dentry->d_parent;
1959
+ if (atomic_dec_and_test(&ino->count)) {
1960
+ p_ino = autofs4_dentry_ino(parent);
1961
+ if (p_ino && parent != ino->dentry)
1962
+ atomic_dec(&p_ino->count);
1969
@@ -85,9 +101,12 @@ void autofs4_free_ino(struct autofs_info
1971
static void autofs4_force_release(struct autofs_sb_info *sbi)
1973
- struct dentry *this_parent = sbi->root;
1974
+ struct dentry *this_parent = sbi->sb->s_root;
1975
struct list_head *next;
1977
+ if (!sbi->sb->s_root)
1980
spin_lock(&dcache_lock);
1982
next = this_parent->d_subdirs.next;
1983
@@ -116,7 +135,7 @@ resume:
1984
spin_lock(&dcache_lock);
1987
- if (this_parent != sbi->root) {
1988
+ if (this_parent != sbi->sb->s_root) {
1989
struct dentry *dentry = this_parent;
1991
next = this_parent->d_child.next;
1992
@@ -129,38 +148,66 @@ resume:
1995
spin_unlock(&dcache_lock);
1999
shrink_dcache_sb(sbi->sb);
2004
-static void autofs4_put_super(struct super_block *sb)
2005
+void autofs4_kill_sb(struct super_block *sb)
2007
struct autofs_sb_info *sbi = autofs4_sbi(sb);
2009
- sb->s_fs_info = NULL;
2011
+ * In the event of a failure in get_sb_nodev the superblock
2012
+ * info is not present so nothing else has been setup, so
2013
+ * just call kill_anon_super when we are called from
2014
+ * deactivate_super.
2019
- if ( !sbi->catatonic )
2020
- autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
2021
+ /* Free wait queues, close pipe */
2022
+ autofs4_catatonic_mode(sbi);
2024
/* Clean up and release dangling references */
2026
- autofs4_force_release(sbi);
2027
+ autofs4_force_release(sbi);
2029
+ sb->s_fs_info = NULL;
2033
DPRINTK("shutting down");
2034
+ kill_anon_super(sb);
2037
+static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt)
2039
+ struct autofs_sb_info *sbi = autofs4_sbi(mnt->mnt_sb);
2044
+ seq_printf(m, ",fd=%d", sbi->pipefd);
2045
+ seq_printf(m, ",pgrp=%d", sbi->oz_pgrp);
2046
+ seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ);
2047
+ seq_printf(m, ",minproto=%d", sbi->min_proto);
2048
+ seq_printf(m, ",maxproto=%d", sbi->max_proto);
2050
+ if (sbi->type & AUTOFS_TYPE_OFFSET)
2051
+ seq_printf(m, ",offset");
2052
+ else if (sbi->type & AUTOFS_TYPE_DIRECT)
2053
+ seq_printf(m, ",direct");
2055
+ seq_printf(m, ",indirect");
2060
static struct super_operations autofs4_sops = {
2061
- .put_super = autofs4_put_super,
2062
.statfs = simple_statfs,
2063
+ .show_options = autofs4_show_options,
2066
-enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto};
2067
+enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto,
2068
+ Opt_indirect, Opt_direct, Opt_offset};
2070
static match_table_t tokens = {
2072
@@ -169,11 +216,15 @@ static match_table_t tokens = {
2073
{Opt_pgrp, "pgrp=%u"},
2074
{Opt_minproto, "minproto=%u"},
2075
{Opt_maxproto, "maxproto=%u"},
2076
+ {Opt_indirect, "indirect"},
2077
+ {Opt_direct, "direct"},
2078
+ {Opt_offset, "offset"},
2082
static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
2083
- pid_t *pgrp, int *minproto, int *maxproto)
2084
+ pid_t *pgrp, unsigned int *type,
2085
+ int *minproto, int *maxproto)
2088
substring_t args[MAX_OPT_ARGS];
2089
@@ -227,6 +278,15 @@ static int parse_options(char *options,
2093
+ case Opt_indirect:
2094
+ *type = AUTOFS_TYPE_INDIRECT;
2097
+ *type = AUTOFS_TYPE_DIRECT;
2100
+ *type = AUTOFS_TYPE_OFFSET;
2105
@@ -245,6 +305,10 @@ static struct autofs_info *autofs4_mkroo
2109
+static struct dentry_operations autofs4_sb_dentry_operations = {
2110
+ .d_release = autofs4_dentry_release,
2113
int autofs4_fill_super(struct super_block *s, void *data, int silent)
2115
struct inode * root_inode;
2116
@@ -253,7 +317,6 @@ int autofs4_fill_super(struct super_bloc
2118
struct autofs_sb_info *sbi;
2119
struct autofs_info *ino;
2120
- int minproto, maxproto;
2122
sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
2124
@@ -264,16 +327,23 @@ int autofs4_fill_super(struct super_bloc
2127
sbi->magic = AUTOFS_SBI_MAGIC;
2129
- sbi->catatonic = 0;
2132
+ sbi->catatonic = 1;
2133
sbi->exp_timeout = 0;
2134
sbi->oz_pgrp = process_group(current);
2137
sbi->sub_version = 0;
2138
+ sbi->type = AUTOFS_TYPE_INDIRECT;
2139
+ sbi->min_proto = 0;
2140
+ sbi->max_proto = 0;
2141
init_MUTEX(&sbi->wq_sem);
2142
spin_lock_init(&sbi->fs_lock);
2144
+ spin_lock_init(&sbi->lookup_lock);
2145
+ INIT_LIST_HEAD(&sbi->active_list);
2146
+ INIT_LIST_HEAD(&sbi->expiring_list);
2147
s->s_blocksize = 1024;
2148
s->s_blocksize_bits = 10;
2149
s->s_magic = AUTOFS_SUPER_MAGIC;
2150
@@ -287,38 +357,46 @@ int autofs4_fill_super(struct super_bloc
2153
root_inode = autofs4_get_inode(s, ino);
2159
- root_inode->i_op = &autofs4_root_inode_operations;
2160
- root_inode->i_fop = &autofs4_root_operations;
2161
root = d_alloc_root(root_inode);
2168
+ root->d_op = &autofs4_sb_dentry_operations;
2169
+ root->d_fsdata = ino;
2171
/* Can this call block? */
2172
if (parse_options(data, &pipefd,
2173
&root_inode->i_uid, &root_inode->i_gid,
2175
- &minproto, &maxproto)) {
2176
+ &sbi->oz_pgrp, &sbi->type,
2177
+ &sbi->min_proto, &sbi->max_proto)) {
2178
printk("autofs: called with bogus options\n");
2182
+ root_inode->i_fop = &autofs4_root_operations;
2183
+ root_inode->i_op = sbi->type & AUTOFS_TYPE_TRIGGER ?
2184
+ &autofs4_direct_root_inode_operations :
2185
+ &autofs4_indirect_root_inode_operations;
2187
/* Couldn't this be tested earlier? */
2188
- if (maxproto < AUTOFS_MIN_PROTO_VERSION ||
2189
- minproto > AUTOFS_MAX_PROTO_VERSION) {
2190
+ if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
2191
+ sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
2192
printk("autofs: kernel does not match daemon version "
2193
"daemon (%d, %d) kernel (%d, %d)\n",
2194
- minproto, maxproto,
2195
+ sbi->min_proto, sbi->max_proto,
2196
AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
2200
- sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto;
2201
+ /* Establish highest kernel protocol version */
2202
+ if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
2203
+ sbi->version = AUTOFS_MAX_PROTO_VERSION;
2205
+ sbi->version = sbi->max_proto;
2206
sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
2208
DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp);
2209
@@ -331,13 +409,8 @@ int autofs4_fill_super(struct super_bloc
2210
if ( !pipe->f_op || !pipe->f_op->write )
2215
- * Take a reference to the root dentry so we get a chance to
2216
- * clean up the dentry tree on umount.
2217
- * See autofs4_force_release.
2219
- sbi->root = dget(root);
2220
+ sbi->pipefd = pipefd;
2221
+ sbi->catatonic = 0;
2224
* Success! Install the root dentry now to indicate completion.
2225
@@ -358,8 +431,11 @@ fail_dput:
2227
printk("autofs: get root dentry failed\n");
2233
+ s->s_fs_info = NULL;
2237
Index: linux-2.6.13/fs/autofs4/waitq.c
2238
===================================================================
2239
--- linux-2.6.13.orig/fs/autofs4/waitq.c
2240
+++ linux-2.6.13/fs/autofs4/waitq.c
2242
* linux/fs/autofs/waitq.c
2244
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
2245
- * Copyright 2001-2003 Ian Kent <raven@themaw.net>
2246
+ * Copyright 2001-2006 Ian Kent <raven@themaw.net>
2248
* This file is part of the Linux kernel and is made available under
2249
* the terms of the GNU General Public License, version 2, or at your
2250
@@ -28,24 +28,31 @@ void autofs4_catatonic_mode(struct autof
2252
struct autofs_wait_queue *wq, *nwq;
2254
+ down(&sbi->wq_sem);
2255
+ if (sbi->catatonic) {
2260
DPRINTK("entering catatonic mode");
2264
sbi->queues = NULL; /* Erase all wait queues */
2268
wq->status = -ENOENT; /* Magic is gone - report failure */
2271
+ if (wq->name.name) {
2272
+ kfree(wq->name.name);
2273
+ wq->name.name = NULL;
2276
wake_up_interruptible(&wq->queue);
2280
- fput(sbi->pipe); /* Close the pipe */
2284
+ fput(sbi->pipe); /* Close the pipe */
2287
shrink_dcache_sb(sbi->sb);
2290
@@ -88,41 +95,90 @@ static void autofs4_notify_daemon(struct
2291
struct autofs_wait_queue *wq,
2294
- union autofs_packet_union pkt;
2296
+ struct autofs_packet_hdr hdr;
2297
+ union autofs_packet_union v4_pkt;
2298
+ union autofs_v5_packet_union v5_pkt;
2300
+ struct file *pipe = NULL;
2303
DPRINTK("wait id = 0x%08lx, name = %.*s, type=%d",
2304
- wq->wait_queue_token, wq->len, wq->name, type);
2305
+ wq->wait_queue_token, wq->name.len, wq->name.name, type);
2307
memset(&pkt,0,sizeof pkt); /* For security reasons */
2309
pkt.hdr.proto_version = sbi->version;
2310
pkt.hdr.type = type;
2311
- if (type == autofs_ptype_missing) {
2312
- struct autofs_packet_missing *mp = &pkt.missing;
2314
+ /* Kernel protocol v4 missing and expire packets */
2315
+ case autofs_ptype_missing:
2317
+ struct autofs_packet_missing *mp = &pkt.v4_pkt.missing;
2319
pktsz = sizeof(*mp);
2321
mp->wait_queue_token = wq->wait_queue_token;
2322
- mp->len = wq->len;
2323
- memcpy(mp->name, wq->name, wq->len);
2324
- mp->name[wq->len] = '\0';
2325
- } else if (type == autofs_ptype_expire_multi) {
2326
- struct autofs_packet_expire_multi *ep = &pkt.expire_multi;
2327
+ mp->len = wq->name.len;
2328
+ memcpy(mp->name, wq->name.name, wq->name.len);
2329
+ mp->name[wq->name.len] = '\0';
2332
+ case autofs_ptype_expire_multi:
2334
+ struct autofs_packet_expire_multi *ep = &pkt.v4_pkt.expire_multi;
2336
pktsz = sizeof(*ep);
2338
ep->wait_queue_token = wq->wait_queue_token;
2339
- ep->len = wq->len;
2340
- memcpy(ep->name, wq->name, wq->len);
2341
- ep->name[wq->len] = '\0';
2343
+ ep->len = wq->name.len;
2344
+ memcpy(ep->name, wq->name.name, wq->name.len);
2345
+ ep->name[wq->name.len] = '\0';
2349
+ * Kernel protocol v5 packet for handling indirect and direct
2350
+ * mount missing and expire requests
2352
+ case autofs_ptype_missing_indirect:
2353
+ case autofs_ptype_expire_indirect:
2354
+ case autofs_ptype_missing_direct:
2355
+ case autofs_ptype_expire_direct:
2357
+ struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
2359
+ pktsz = sizeof(*packet);
2361
+ packet->wait_queue_token = wq->wait_queue_token;
2362
+ packet->len = wq->name.len;
2363
+ memcpy(packet->name, wq->name.name, wq->name.len);
2364
+ packet->name[wq->name.len] = '\0';
2365
+ packet->dev = wq->dev;
2366
+ packet->ino = wq->ino;
2367
+ packet->uid = wq->uid;
2368
+ packet->gid = wq->gid;
2369
+ packet->pid = wq->pid;
2370
+ packet->tgid = wq->tgid;
2374
printk("autofs4_notify_daemon: bad type %d!\n", type);
2378
- if (autofs4_write(sbi->pipe, &pkt, pktsz))
2379
- autofs4_catatonic_mode(sbi);
2380
+ /* Check if we have become catatonic */
2381
+ down(&sbi->wq_sem);
2382
+ if (!sbi->catatonic) {
2389
+ if (autofs4_write(pipe, &pkt, pktsz))
2390
+ autofs4_catatonic_mode(sbi);
2395
static int autofs4_getpath(struct autofs_sb_info *sbi,
2396
@@ -138,7 +194,7 @@ static int autofs4_getpath(struct autofs
2397
for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
2398
len += tmp->d_name.len + 1;
2400
- if (--len > NAME_MAX) {
2401
+ if (!len || --len > NAME_MAX) {
2402
spin_unlock(&dcache_lock);
2405
@@ -157,51 +213,170 @@ static int autofs4_getpath(struct autofs
2409
+static struct autofs_wait_queue *
2410
+autofs4_find_wait(struct autofs_sb_info *sbi, struct qstr *qstr)
2412
+ struct autofs_wait_queue *wq = NULL;
2414
+ for (wq = sbi->queues ; wq ; wq = wq->next) {
2415
+ if (wq->name.hash == qstr->hash &&
2416
+ wq->name.len == qstr->len &&
2417
+ wq->name.name && !memcmp(wq->name, qstr->name, qstr->len))
2424
+ * Check if we have a valid request.
2426
+ * 1 if the request should continue.
2427
+ * In this case we can return an autofs_wait_queue entry if one is
2428
+ * found or NULL to idicate a new wait needs to be created.
2429
+ * 0 or a negative errno if the request shouldn't continue.
2431
+static int validate_request(struct autofs_wait_queue **wait,
2432
+ struct autofs_sb_info *sbi,
2433
+ struct qstr *qstr,
2434
+ struct dentry*dentry, enum autofs_notify notify)
2436
+ struct autofs_wait_queue *wq;
2437
+ struct autofs_info *ino;
2439
+ /* Wait in progress, continue; */
2440
+ wq = autofs4_find_wait(sbi, qstr);
2448
+ /* If we don't yet have any info this is a new request */
2449
+ ino = autofs4_dentry_ino(dentry);
2454
+ * If we've been asked to wait on an existing expire (NFY_NONE)
2455
+ * but there is no wait in the queue ...
2457
+ if (notify == NFY_NONE) {
2459
+ * Either we've betean the pending expire to post it's
2460
+ * wait or it finished while we waited on the semaphore.
2461
+ * So we need to wait till either, the wait appears
2462
+ * or the expire finishes.
2465
+ while (ino->flags & AUTOFS_INF_EXPIRING) {
2467
+ schedule_timeout_interruptible(HZ/10);
2468
+ if (down_interruptible(&sbi->wq_sem))
2471
+ wq = autofs4_find_wait(sbi, qstr);
2479
+ * Not ideal but the status has already gone. Of the two
2480
+ * cases where we wait on NFY_NONE neither depend on the
2481
+ * return status of the wait.
2487
+ * If we've been asked to trigger a mount and the request
2488
+ * completed while we waited on the semaphore ...
2490
+ if (notify == NFY_MOUNT) {
2492
+ * If the dentry isn't hashed just go ahead and try the
2493
+ * mount again with a new wait (not much else we can do).
2495
+ if (!d_unhashed(dentry)) {
2497
+ * But if the dentry is hashed, that means that we
2498
+ * got here through the revalidate path. Thus, we
2499
+ * need to check if the dentry has been mounted
2500
+ * while we waited on the wq_semaphore. If it has,
2501
+ * simply return success.
2503
+ if (d_mountpoint(dentry))
2511
int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
2512
enum autofs_notify notify)
2514
struct autofs_wait_queue *wq;
2518
+ int status, ret, type;
2520
/* In catatonic mode, we don't wait for nobody */
2521
- if ( sbi->catatonic )
2522
+ if (sbi->catatonic)
2526
+ if (!dentry->d_inode) {
2528
+ * A wait for a negative dentry is invalid for certain
2529
+ * cases. A direct or offset mount "always" has its mount
2530
+ * point directory created and so the request dentry must
2531
+ * be positive or the map key doesn't exist. The situation
2532
+ * is very similar for indirect mounts except only dentrys
2533
+ * in the root of the autofs file system may be negative.
2535
+ if (sbi->type & AUTOFS_TYPE_TRIGGER)
2537
+ else if (!IS_ROOT(dentry->d_parent))
2541
name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
2545
- len = autofs4_getpath(sbi, dentry, &name);
2549
+ /* If this is a direct mount request create a dummy name */
2550
+ if (IS_ROOT(dentry) && sbi->type & AUTOFS_TYPE_TRIGGER)
2551
+ qstr.len = sprintf(name, "%p", dentry);
2553
+ qstr.len = autofs4_getpath(sbi, dentry, &name);
2560
+ qstr.hash = full_name_hash(name, qstr.len);
2562
if (down_interruptible(&sbi->wq_sem)) {
2568
- for (wq = sbi->queues ; wq ; wq = wq->next) {
2569
- if (wq->hash == dentry->d_name.hash &&
2571
- wq->name && !memcmp(wq->name, name, len))
2576
- /* Can't wait for an expire if there's no mount */
2577
- if (notify == NFY_NONE && !d_mountpoint(dentry)) {
2579
+ ret = validate_request(&wq, sbi, &qstr, dentry, notify);
2590
/* Create a new wait queue */
2591
wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
2599
@@ -212,44 +387,53 @@ int autofs4_wait(struct autofs_sb_info *
2600
wq->next = sbi->queues;
2602
init_waitqueue_head(&wq->queue);
2603
- wq->hash = dentry->d_name.hash;
2606
+ memcpy(&wq->name, &qstr, sizeof(struct qstr));
2607
+ wq->dev = autofs4_get_dev(sbi);
2608
+ wq->ino = autofs4_get_ino(sbi);
2609
+ wq->uid = current->uid;
2610
+ wq->gid = current->gid;
2611
+ wq->pid = current->pid;
2612
+ wq->tgid = current->tgid;
2613
wq->status = -EINTR; /* Status return if interrupted */
2614
- atomic_set(&wq->wait_ctr, 2);
2615
- atomic_set(&wq->notified, 1);
2619
- atomic_inc(&wq->wait_ctr);
2622
- DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
2623
- (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
2626
- if (notify != NFY_NONE && atomic_dec_and_test(&wq->notified)) {
2627
- int type = (notify == NFY_MOUNT ?
2628
- autofs_ptype_missing : autofs_ptype_expire_multi);
2629
+ if (sbi->version < 5) {
2630
+ if (notify == NFY_MOUNT)
2631
+ type = autofs_ptype_missing;
2633
+ type = autofs_ptype_expire_multi;
2635
+ if (notify == NFY_MOUNT)
2636
+ type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
2637
+ autofs_ptype_missing_direct :
2638
+ autofs_ptype_missing_indirect;
2640
+ type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
2641
+ autofs_ptype_expire_direct :
2642
+ autofs_ptype_expire_indirect;
2645
DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
2646
- (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
2647
+ (unsigned long) wq->wait_queue_token, wq->name.len,
2648
+ wq->name.name, notify);
2650
/* autofs4_notify_daemon() may block */
2651
autofs4_notify_daemon(sbi, wq, type);
2656
+ DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
2657
+ (unsigned long) wq->wait_queue_token, wq->name.len,
2658
+ wq->name.name, notify);
2661
- /* wq->name is NULL if and only if the lock is already released */
2663
- if ( sbi->catatonic ) {
2664
- /* We might have slept, so check again for catatonic mode */
2665
- wq->status = -ENOENT;
2674
+ * wq->name.name is NULL iff the lock is already released
2675
+ * or the mount has been made catatonic.
2677
+ if (wq->name.name) {
2678
/* Block all but "shutdown" signals while waiting */
2680
unsigned long irqflags;
2681
@@ -260,7 +444,7 @@ int autofs4_wait(struct autofs_sb_info *
2682
recalc_sigpending();
2683
spin_unlock_irqrestore(¤t->sighand->siglock, irqflags);
2685
- wait_event_interruptible(wq->queue, wq->name == NULL);
2686
+ wait_event_interruptible(wq->queue, wq->name.name == NULL);
2688
spin_lock_irqsave(¤t->sighand->siglock, irqflags);
2689
current->blocked = oldset;
2690
@@ -273,8 +457,10 @@ int autofs4_wait(struct autofs_sb_info *
2691
status = wq->status;
2693
/* Are we the last process to need status? */
2694
- if (atomic_dec_and_test(&wq->wait_ctr))
2695
+ down(&sbi->wq_sem);
2696
+ if (!--wq->wait_ctr)
2702
@@ -285,27 +471,24 @@ int autofs4_wait_release(struct autofs_s
2703
struct autofs_wait_queue *wq, **wql;
2706
- for ( wql = &sbi->queues ; (wq = *wql) != 0 ; wql = &wq->next ) {
2707
- if ( wq->wait_queue_token == wait_queue_token )
2708
+ for (wql = &sbi->queues ; (wq = *wql) != 0 ; wql = &wq->next) {
2709
+ if (wq->wait_queue_token == wait_queue_token)
2719
*wql = wq->next; /* Unlink from chain */
2722
- wq->name = NULL; /* Do not wait on this queue */
2724
+ kfree(wq->name.name);
2725
+ wq->name.name = NULL; /* Do not wait on this queue */
2726
wq->status = status;
2728
- if (atomic_dec_and_test(&wq->wait_ctr)) /* Is anyone still waiting for this guy? */
2729
+ wake_up_interruptible(&wq->queue);
2730
+ if (!--wq->wait_ctr)
2733
- wake_up_interruptible(&wq->queue);
2738
Index: linux-2.6.13/fs/autofs/dirhash.c
2739
===================================================================
2740
--- linux-2.6.13.orig/fs/autofs/dirhash.c
2741
+++ linux-2.6.13/fs/autofs/dirhash.c
2742
@@ -92,7 +92,7 @@ struct autofs_dir_ent *autofs_expire(str
2746
- if ( may_umount(mnt) == 0 ) {
2747
+ if ( may_umount(mnt) ) {
2749
DPRINTK(("autofs: signaling expire on %s\n", ent->name));
2750
return ent; /* Expirable! */
2751
Index: linux-2.6.13/fs/namespace.c
2752
===================================================================
2753
--- linux-2.6.13.orig/fs/namespace.c
2754
+++ linux-2.6.13/fs/namespace.c
2755
@@ -308,9 +308,9 @@ resume:
2756
spin_unlock(&vfsmount_lock);
2758
if (actual_refs > minimum_refs)
2766
EXPORT_SYMBOL(may_umount_tree);
2767
@@ -330,9 +330,10 @@ EXPORT_SYMBOL(may_umount_tree);
2769
int may_umount(struct vfsmount *mnt)
2772
if (atomic_read(&mnt->mnt_count) > 2)
2779
EXPORT_SYMBOL(may_umount);
2780
Index: linux-2.6.13/include/linux/auto_fs4.h
2781
===================================================================
2782
--- linux-2.6.13.orig/include/linux/auto_fs4.h
2783
+++ linux-2.6.13/include/linux/auto_fs4.h
2785
#undef AUTOFS_MIN_PROTO_VERSION
2786
#undef AUTOFS_MAX_PROTO_VERSION
2788
-#define AUTOFS_PROTO_VERSION 4
2789
+#define AUTOFS_PROTO_VERSION 5
2790
#define AUTOFS_MIN_PROTO_VERSION 3
2791
-#define AUTOFS_MAX_PROTO_VERSION 4
2792
+#define AUTOFS_MAX_PROTO_VERSION 5
2794
-#define AUTOFS_PROTO_SUBVERSION 7
2795
+#define AUTOFS_PROTO_SUBVERSION 0
2797
/* Mask for expire behaviour */
2798
#define AUTOFS_EXP_IMMEDIATE 1
2799
#define AUTOFS_EXP_LEAVES 2
2801
-/* New message type */
2802
-#define autofs_ptype_expire_multi 2 /* Expire entry (umount request) */
2803
+#define AUTOFS_TYPE_ANY 0x0000
2804
+#define AUTOFS_TYPE_INDIRECT 0x0001
2805
+#define AUTOFS_TYPE_DIRECT 0x0002
2806
+#define AUTOFS_TYPE_OFFSET 0x0004
2808
+/* Daemon notification packet types */
2809
+enum autofs_notify {
2815
+/* Kernel protocol version 4 packet types */
2817
+/* Expire entry (umount request) */
2818
+#define autofs_ptype_expire_multi 2
2820
+/* Kernel protocol version 5 packet types */
2822
+/* Indirect mount missing and expire requests. */
2823
+#define autofs_ptype_missing_indirect 3
2824
+#define autofs_ptype_expire_indirect 4
2826
+/* Direct mount missing and expire requests */
2827
+#define autofs_ptype_missing_direct 5
2828
+#define autofs_ptype_expire_direct 6
2830
/* v4 multi expire (via pipe) */
2831
struct autofs_packet_expire_multi {
2832
@@ -47,10 +71,38 @@ union autofs_packet_union {
2833
struct autofs_packet_expire_multi expire_multi;
2836
+/* autofs v5 common packet struct */
2837
+struct autofs_v5_packet {
2838
+ struct autofs_packet_hdr hdr;
2839
+ autofs_wqt_t wait_queue_token;
2847
+ char name[NAME_MAX+1];
2850
+typedef struct autofs_v5_packet autofs_packet_missing_indirect_t;
2851
+typedef struct autofs_v5_packet autofs_packet_expire_indirect_t;
2852
+typedef struct autofs_v5_packet autofs_packet_missing_direct_t;
2853
+typedef struct autofs_v5_packet autofs_packet_expire_direct_t;
2855
+union autofs_v5_packet_union {
2856
+ struct autofs_packet_hdr hdr;
2857
+ struct autofs_v5_packet v5_packet;
2858
+ autofs_packet_missing_indirect_t missing_indirect;
2859
+ autofs_packet_expire_indirect_t expire_indirect;
2860
+ autofs_packet_missing_direct_t missing_direct;
2861
+ autofs_packet_expire_direct_t expire_direct;
2864
#define AUTOFS_IOC_EXPIRE_MULTI _IOW(0x93,0x66,int)
2865
+#define AUTOFS_IOC_EXPIRE_INDIRECT AUTOFS_IOC_EXPIRE_MULTI
2866
+#define AUTOFS_IOC_EXPIRE_DIRECT AUTOFS_IOC_EXPIRE_MULTI
2867
#define AUTOFS_IOC_PROTOSUBVER _IOR(0x93,0x67,int)
2868
-#define AUTOFS_IOC_ASKREGHOST _IOR(0x93,0x68,int)
2869
-#define AUTOFS_IOC_TOGGLEREGHOST _IOR(0x93,0x69,int)
2870
#define AUTOFS_IOC_ASKUMOUNT _IOR(0x93,0x70,int)
2873
Index: linux-2.6.13/fs/namei.c
2874
===================================================================
2875
--- linux-2.6.13.orig/fs/namei.c
2876
+++ linux-2.6.13/fs/namei.c
2877
@@ -317,6 +317,29 @@ void path_release_on_umount(struct namei
2878
mntput_no_expire(nd->mnt);
2881
+static inline struct dentry *do_revalidate(struct dentry *dentry, struct nameidata *nd)
2883
+ int status = dentry->d_op->d_revalidate(dentry, nd);
2884
+ if (unlikely(status <= 0)) {
2886
+ * The dentry failed validation.
2887
+ * If d_revalidate returned 0 attempt to invalidate
2888
+ * the dentry otherwise d_revalidate is asking us
2889
+ * to return a fail status.
2892
+ if (!d_invalidate(dentry)) {
2898
+ dentry = ERR_PTR(status);
2905
* Internal lookup() using the new generic dcache.
2907
@@ -331,12 +354,9 @@ static struct dentry * cached_lookup(str
2909
dentry = d_lookup(parent, name);
2911
- if (dentry && dentry->d_op && dentry->d_op->d_revalidate) {
2912
- if (!dentry->d_op->d_revalidate(dentry, nd) && !d_invalidate(dentry)) {
2917
+ if (dentry && dentry->d_op && dentry->d_op->d_revalidate)
2918
+ dentry = do_revalidate(dentry, nd);
2923
@@ -429,10 +449,9 @@ static struct dentry * real_lookup(struc
2926
if (result->d_op && result->d_op->d_revalidate) {
2927
- if (!result->d_op->d_revalidate(result, nd) && !d_invalidate(result)) {
2929
+ result = do_revalidate(result, nd);
2931
result = ERR_PTR(-ENOENT);
2936
@@ -507,8 +526,15 @@ static inline int __do_follow_link(struc
2937
touch_atime(path->mnt, dentry);
2938
nd_set_link(nd, NULL);
2940
- if (path->mnt == nd->mnt)
2941
- mntget(path->mnt);
2942
+ if (path->mnt != nd->mnt) {
2944
+ if (nd->mnt != path->mnt)
2946
+ nd->mnt = path->mnt;
2947
+ nd->dentry = path->dentry;
2950
+ mntget(path->mnt);
2951
cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
2952
error = PTR_ERR(cookie);
2953
if (!IS_ERR(cookie)) {
2954
@@ -695,12 +721,12 @@ need_lookup:
2958
- if (dentry->d_op->d_revalidate(dentry, nd))
2960
- if (d_invalidate(dentry))
2964
+ dentry = do_revalidate(dentry, nd);
2967
+ if (IS_ERR(dentry))
2972
return PTR_ERR(dentry);
2973
Index: linux-2.6.13/fs/autofs/init.c
2974
===================================================================
2975
--- linux-2.6.13.orig/fs/autofs/init.c
2976
+++ linux-2.6.13/fs/autofs/init.c
2977
@@ -24,7 +24,7 @@ static struct file_system_type autofs_fs
2978
.owner = THIS_MODULE,
2980
.get_sb = autofs_get_sb,
2981
- .kill_sb = kill_anon_super,
2982
+ .kill_sb = autofs_kill_sb,
2985
static int __init init_autofs_fs(void)
2986
Index: linux-2.6.13/fs/autofs/inode.c
2987
===================================================================
2988
--- linux-2.6.13.orig/fs/autofs/inode.c
2989
+++ linux-2.6.13/fs/autofs/inode.c
2991
#include "autofs_i.h"
2992
#include <linux/module.h>
2994
-static void autofs_put_super(struct super_block *sb)
2995
+void autofs4_kill_sb(struct super_block *sb)
2997
struct autofs_sb_info *sbi = autofs_sbi(sb);
3001
+ * In the event of a failure in get_sb_nodev the superblock
3002
+ * info is not present so nothing else has been setup, so
3003
+ * just call kill_anon_super when we are called from
3004
+ * deactivate_super.
3009
if ( !sbi->catatonic )
3010
autofs_catatonic_mode(sbi); /* Free wait queues, close pipe */
3012
@@ -35,14 +44,15 @@ static void autofs_put_super(struct supe
3014
kfree(sb->s_fs_info);
3017
DPRINTK(("autofs: shutting down\n"));
3018
+ kill_anon_super(sb);
3021
static void autofs_read_inode(struct inode *inode);
3023
static struct super_operations autofs_sops = {
3024
.read_inode = autofs_read_inode,
3025
- .put_super = autofs_put_super,
3026
.statfs = simple_statfs,
3029
@@ -136,7 +146,8 @@ int autofs_fill_super(struct super_block
3032
sbi->magic = AUTOFS_SBI_MAGIC;
3033
- sbi->catatonic = 0;
3035
+ sbi->catatonic = 1;
3036
sbi->exp_timeout = 0;
3037
sbi->oz_pgrp = process_group(current);
3038
autofs_initialize_hash(&sbi->dirhash);
3039
@@ -179,6 +190,7 @@ int autofs_fill_super(struct super_block
3040
if ( !pipe->f_op || !pipe->f_op->write )
3043
+ sbi->catatonic = 0;
3046
* Success! Install the root dentry now to indicate completion.
3047
@@ -197,6 +209,7 @@ fail_iput:
3051
+ s->s_fs_info = NULL;
3055
Index: linux-2.6.13/fs/autofs/autofs_i.h
3056
===================================================================
3057
--- linux-2.6.13.orig/fs/autofs/autofs_i.h
3058
+++ linux-2.6.13/fs/autofs/autofs_i.h
3059
@@ -150,6 +150,7 @@ extern struct file_operations autofs_roo
3060
/* Initializing function */
3062
int autofs_fill_super(struct super_block *, void *, int);
3063
+void autofs_kill_sb(struct super_block *);
3065
/* Queue management functions */
3067
Index: linux-2.6.13/fs/autofs4/init.c
3068
===================================================================
3069
--- linux-2.6.13.orig/fs/autofs4/init.c
3070
+++ linux-2.6.13/fs/autofs4/init.c
3071
@@ -24,7 +24,7 @@ static struct file_system_type autofs_fs
3072
.owner = THIS_MODULE,
3074
.get_sb = autofs_get_sb,
3075
- .kill_sb = kill_anon_super,
3076
+ .kill_sb = autofs4_kill_sb,
3079
static int __init init_autofs4_fs(void)
3080
Index: linux-2.6.13/fs/autofs/waitq.c
3081
===================================================================
3082
--- linux-2.6.13.orig/fs/autofs/waitq.c
3083
+++ linux-2.6.13/fs/autofs/waitq.c
3084
@@ -41,6 +41,7 @@ void autofs_catatonic_mode(struct autofs
3087
fput(sbi->pipe); /* Close the pipe */
3089
autofs_hash_dputall(&sbi->dirhash); /* Remove all dentry pointers */
3092
Index: linux-2.6.13/include/linux/compat_ioctl.h
3093
===================================================================
3094
--- linux-2.6.13.orig/include/linux/compat_ioctl.h
3095
+++ linux-2.6.13/include/linux/compat_ioctl.h
3096
@@ -583,8 +583,6 @@ COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
3097
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
3098
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
3099
COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
3100
-COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
3101
-COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
3102
COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
3104
COMPATIBLE_IOCTL(DEVFSDIOC_GET_PROTO_REV)