1
Index: linux-2.6.11/fs/autofs4/autofs_i.h
2
===================================================================
3
--- linux-2.6.11.orig/fs/autofs4/autofs_i.h
4
+++ linux-2.6.11/fs/autofs4/autofs_i.h
6
* linux/fs/autofs/autofs_i.h
8
* Copyright 1997-1998 Transmeta Corporation - All Rights Reserved
9
+ * Copyright 2005-2006 Ian Kent <raven@themaw.net>
11
* This file is part of the Linux kernel and is made available under
12
* the terms of the GNU General Public License, version 2, or at your
14
#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
15
#define AUTOFS_IOC_COUNT 32
17
+#define AUTOFS_TYPE_TRIGGER (AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET)
19
#include <linux/kernel.h>
20
#include <linux/slab.h>
21
#include <linux/time.h>
24
#define AUTOFS_SUPER_MAGIC 0x0187
27
- * If the daemon returns a negative response (AUTOFS_IOC_FAIL) then the
28
- * kernel will keep the negative response cached for up to the time given
29
- * here, although the time can be shorter if the kernel throws the dcache
30
- * entry away. This probably should be settable from user space.
32
-#define AUTOFS_NEGATIVE_TIMEOUT (60*HZ) /* 1 minute */
34
/* Unified info structure. This is pointed to by both the dentry and
35
inode structures. Each file in the filesystem has an instance of this
36
structure. It holds a reference to the dentry, so dentries are never
37
@@ -60,8 +55,14 @@ struct autofs_info {
41
+ struct completion expire_complete;
43
+ struct list_head active;
44
+ struct list_head expiring;
46
struct autofs_sb_info *sbi;
47
unsigned long last_used;
52
@@ -73,35 +74,48 @@ struct autofs_info {
55
#define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */
56
+#define AUTOFS_INF_MOUNTPOINT (1<<1) /* mountpoint status for direct expire */
58
struct autofs_wait_queue {
59
wait_queue_head_t queue;
60
struct autofs_wait_queue *next;
61
autofs_wqt_t wait_queue_token;
62
/* We use the following to see what we are waiting for */
73
/* This is for status reporting upon return */
76
+ unsigned int wait_ctr;
79
#define AUTOFS_SBI_MAGIC 0x6d4a556d
81
struct autofs_sb_info {
91
unsigned long exp_timeout;
95
struct super_block *sb;
96
struct semaphore wq_sem;
98
struct autofs_wait_queue *queues; /* Wait queue pointer */
99
+ spinlock_t lookup_lock;
100
+ struct list_head active_list;
101
+ struct list_head expiring_list;
104
static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
105
@@ -127,8 +141,13 @@ static inline int autofs4_ispending(stru
107
struct autofs_info *inf = autofs4_dentry_ino(dentry);
109
- return (dentry->d_flags & DCACHE_AUTOFS_PENDING) ||
110
- (inf != NULL && inf->flags & AUTOFS_INF_EXPIRING);
111
+ if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
114
+ if (inf->flags & AUTOFS_INF_EXPIRING)
120
static inline void autofs4_copy_atime(struct file *src, struct file *dst)
121
@@ -142,6 +161,7 @@ void autofs4_free_ino(struct autofs_info
124
int is_autofs4_dentry(struct dentry *);
125
+int autofs4_expire_wait(struct dentry *dentry);
126
int autofs4_expire_run(struct super_block *, struct vfsmount *,
127
struct autofs_sb_info *,
128
struct autofs_packet_expire __user *);
129
@@ -153,6 +173,8 @@ int autofs4_expire_multi(struct super_bl
130
extern struct inode_operations autofs4_symlink_inode_operations;
131
extern struct inode_operations autofs4_dir_inode_operations;
132
extern struct inode_operations autofs4_root_inode_operations;
133
+extern struct inode_operations autofs4_indirect_root_inode_operations;
134
+extern struct inode_operations autofs4_direct_root_inode_operations;
135
extern struct file_operations autofs4_dir_operations;
136
extern struct file_operations autofs4_root_operations;
138
@@ -163,23 +185,39 @@ struct autofs_info *autofs4_init_ino(str
140
/* Queue management functions */
149
int autofs4_wait(struct autofs_sb_info *,struct dentry *, enum autofs_notify);
150
int autofs4_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
151
void autofs4_catatonic_mode(struct autofs_sb_info *);
153
+static inline int autofs4_follow_mount(struct vfsmount **mnt, struct dentry **dentry)
157
+ while (d_mountpoint(*dentry)) {
158
+ int followed = follow_down(mnt, dentry);
166
+static inline u32 autofs4_get_dev(struct autofs_sb_info *sbi)
168
+ return new_encode_dev(sbi->sb->s_dev);
171
+static inline u64 autofs4_get_ino(struct autofs_sb_info *sbi)
173
+ return sbi->sb->s_root->d_inode->i_ino;
176
static inline int simple_positive(struct dentry *dentry)
178
return dentry->d_inode && !d_unhashed(dentry);
181
-static inline int simple_empty_nolock(struct dentry *dentry)
182
+static inline int __simple_empty(struct dentry *dentry)
184
struct dentry *child;
186
@@ -191,3 +229,6 @@ static inline int simple_empty_nolock(st
191
+void autofs4_dentry_release(struct dentry *);
192
+extern void autofs4_kill_sb(struct super_block *);
193
Index: linux-2.6.11/fs/autofs4/expire.c
194
===================================================================
195
--- linux-2.6.11.orig/fs/autofs4/expire.c
196
+++ linux-2.6.11/fs/autofs4/expire.c
199
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
200
* Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
201
- * Copyright 2001-2003 Ian Kent <raven@themaw.net>
202
+ * Copyright 2001-2006 Ian Kent <raven@themaw.net>
204
* This file is part of the Linux kernel and is made available under
205
* the terms of the GNU General Public License, version 2, or at your
208
static unsigned long now;
210
-/* Check if a dentry can be expired return 1 if it can else return 0 */
211
+/* Check if a dentry can be expired */
212
static inline int autofs4_can_expire(struct dentry *dentry,
213
unsigned long timeout, int do_now)
215
@@ -41,14 +41,14 @@ static inline int autofs4_can_expire(str
216
attempts if expire fails the first time */
217
ino->last_used = now;
223
-/* Check a mount point for busyness return 1 if not busy, otherwise */
224
-static int autofs4_check_mount(struct vfsmount *mnt, struct dentry *dentry)
225
+/* Check a mount point for busyness */
226
+static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry)
229
+ struct dentry *top = dentry;
232
DPRINTK("dentry %p %.*s",
233
dentry, (int)dentry->d_name.len, dentry->d_name.name);
234
@@ -59,91 +59,160 @@ static int autofs4_check_mount(struct vf
235
if (!follow_down(&mnt, &dentry))
238
- while (d_mountpoint(dentry) && follow_down(&mnt, &dentry))
240
+ if (is_autofs4_dentry(dentry)) {
241
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
243
+ /* This is an autofs submount, we can't expire it */
244
+ if (sbi->type == AUTOFS_TYPE_INDIRECT)
248
+ * Otherwise it's an offset mount and we need to check
249
+ * if we can umount its mount, if there is one.
251
+ if (!d_mountpoint(dentry))
255
- /* This is an autofs submount, we can't expire it */
256
- if (is_autofs4_dentry(dentry))
257
+ /* Update the expiry counter if fs is busy */
258
+ if (!may_umount_tree(mnt)) {
259
+ struct autofs_info *ino = autofs4_dentry_ino(top);
260
+ ino->last_used = jiffies;
264
- /* The big question */
265
- if (may_umount_tree(mnt) == 0)
269
DPRINTK("returning = %d", status);
277
+ * Calculate next entry in top down tree traversal.
278
+ * From next_mnt in namespace.c - elegant.
280
+static struct dentry *next_dentry(struct dentry *p, struct dentry *root)
282
+ struct list_head *next = p->d_subdirs.next;
284
+ if (next == &p->d_subdirs) {
288
+ next = p->d_child.next;
289
+ if (next != &p->d_parent->d_subdirs)
294
+ return list_entry(next, struct dentry, d_child);
298
+ * Check a direct mount point for busyness.
299
+ * Direct mounts have similar expiry semantics to tree mounts.
300
+ * The tree is not busy iff no mountpoints are busy and there are no
301
+ * autofs submounts.
303
+static int autofs4_direct_busy(struct vfsmount *mnt,
304
+ struct dentry *top,
305
+ unsigned long timeout,
308
+ DPRINTK("top %p %.*s",
309
+ top, (int) top->d_name.len, top->d_name.name);
311
+ /* If it's busy update the expiry counters */
312
+ if (!may_umount_tree(mnt)) {
313
+ struct autofs_info *ino = autofs4_dentry_ino(top);
315
+ ino->last_used = jiffies;
319
+ /* Timeout of a direct mount is determined by its top dentry */
320
+ if (!autofs4_can_expire(top, timeout, do_now))
326
/* Check a directory tree of mount points for busyness
327
* The tree is not busy iff no mountpoints are busy
328
- * Return 1 if the tree is busy or 0 otherwise
330
-static int autofs4_check_tree(struct vfsmount *mnt,
331
- struct dentry *top,
332
- unsigned long timeout,
334
+static int autofs4_tree_busy(struct vfsmount *mnt,
335
+ struct dentry *top,
336
+ unsigned long timeout,
339
- struct dentry *this_parent = top;
340
- struct list_head *next;
341
+ struct autofs_info *top_ino = autofs4_dentry_ino(top);
344
- DPRINTK("parent %p %.*s",
345
+ DPRINTK("top %p %.*s",
346
top, (int)top->d_name.len, top->d_name.name);
348
/* Negative dentry - give up */
349
if (!simple_positive(top))
352
- /* Timeout of a tree mount is determined by its top dentry */
353
- if (!autofs4_can_expire(top, timeout, do_now))
357
spin_lock(&dcache_lock);
359
- next = this_parent->d_subdirs.next;
361
- while (next != &this_parent->d_subdirs) {
362
- struct dentry *dentry = list_entry(next, struct dentry, d_child);
364
+ for (p = top; p; p = next_dentry(p, top)) {
365
/* Negative dentry - give up */
366
- if (!simple_positive(dentry)) {
368
+ if (!simple_positive(p))
372
DPRINTK("dentry %p %.*s",
373
- dentry, (int)dentry->d_name.len, dentry->d_name.name);
375
- if (!simple_empty_nolock(dentry)) {
376
- this_parent = dentry;
379
+ p, (int) p->d_name.len, p->d_name.name);
381
- dentry = dget(dentry);
383
spin_unlock(&dcache_lock);
385
- if (d_mountpoint(dentry)) {
386
- /* First busy => tree busy */
387
- if (!autofs4_check_mount(mnt, dentry)) {
391
+ * Is someone visiting anywhere in the subtree ?
392
+ * If there's no mount we need to check the usage
393
+ * count for the autofs dentry.
394
+ * If the fs is busy update the expiry counter.
396
+ if (d_mountpoint(p)) {
397
+ if (autofs4_mount_busy(mnt, p)) {
398
+ top_ino->last_used = jiffies;
404
+ struct autofs_info *ino = autofs4_dentry_ino(p);
405
+ unsigned int ino_count = atomic_read(&ino->count);
409
+ * Clean stale dentries below that have not been
410
+ * invalidated after a mount fail during lookup
414
+ /* allow for dget above and top is already dgot */
420
+ if (atomic_read(&p->d_count) > ino_count) {
421
+ top_ino->last_used = jiffies;
427
spin_lock(&dcache_lock);
431
- if (this_parent != top) {
432
- next = this_parent->d_child.next;
433
- this_parent = this_parent->d_parent;
436
spin_unlock(&dcache_lock);
439
+ /* Timeout of a tree mount is ultimately determined by its top dentry */
440
+ if (!autofs4_can_expire(top, timeout, do_now))
446
static struct dentry *autofs4_check_leaves(struct vfsmount *mnt,
447
@@ -151,58 +220,70 @@ static struct dentry *autofs4_check_leav
448
unsigned long timeout,
451
- struct dentry *this_parent = parent;
452
- struct list_head *next;
455
DPRINTK("parent %p %.*s",
456
parent, (int)parent->d_name.len, parent->d_name.name);
458
spin_lock(&dcache_lock);
460
- next = this_parent->d_subdirs.next;
462
- while (next != &this_parent->d_subdirs) {
463
- struct dentry *dentry = list_entry(next, struct dentry, d_child);
465
+ for (p = parent; p; p = next_dentry(p, parent)) {
466
/* Negative dentry - give up */
467
- if (!simple_positive(dentry)) {
469
+ if (!simple_positive(p))
473
DPRINTK("dentry %p %.*s",
474
- dentry, (int)dentry->d_name.len, dentry->d_name.name);
475
+ p, (int) p->d_name.len, p->d_name.name);
477
- if (!list_empty(&dentry->d_subdirs)) {
478
- this_parent = dentry;
482
- dentry = dget(dentry);
484
spin_unlock(&dcache_lock);
486
- if (d_mountpoint(dentry)) {
487
- /* Can we expire this guy */
488
- if (!autofs4_can_expire(dentry, timeout, do_now))
491
+ if (d_mountpoint(p)) {
492
/* Can we umount this guy */
493
- if (autofs4_check_mount(mnt, dentry))
495
+ if (autofs4_mount_busy(mnt, p))
498
+ /* Can we expire this guy */
499
+ if (autofs4_can_expire(p, timeout, do_now))
505
spin_lock(&dcache_lock);
508
+ spin_unlock(&dcache_lock);
512
+/* Check if we can expire a direct mount (possibly a tree) */
513
+static struct dentry *autofs4_expire_direct(struct super_block *sb,
514
+ struct vfsmount *mnt,
515
+ struct autofs_sb_info *sbi,
518
+ unsigned long timeout;
519
+ struct dentry *root = dget(sb->s_root);
520
+ int do_now = how & AUTOFS_EXP_IMMEDIATE;
522
- if (this_parent != parent) {
523
- next = this_parent->d_child.next;
524
- this_parent = this_parent->d_parent;
526
+ if (!sbi->exp_timeout || !root)
530
+ timeout = sbi->exp_timeout;
532
+ spin_lock(&sbi->fs_lock);
533
+ if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
534
+ struct autofs_info *ino = autofs4_dentry_ino(root);
535
+ if (d_mountpoint(root)) {
536
+ ino->flags |= AUTOFS_INF_MOUNTPOINT;
539
+ ino->flags |= AUTOFS_INF_EXPIRING;
540
+ init_completion(&ino->expire_complete);
541
+ spin_unlock(&sbi->fs_lock);
544
- spin_unlock(&dcache_lock);
545
+ spin_unlock(&sbi->fs_lock);
550
@@ -213,10 +294,10 @@ cont:
551
* - it is unused by any user process
552
* - it has been unused for exp_timeout time
554
-static struct dentry *autofs4_expire(struct super_block *sb,
555
- struct vfsmount *mnt,
556
- struct autofs_sb_info *sbi,
558
+static struct dentry *autofs4_expire_indirect(struct super_block *sb,
559
+ struct vfsmount *mnt,
560
+ struct autofs_sb_info *sbi,
563
unsigned long timeout;
564
struct dentry *root = sb->s_root;
565
@@ -224,6 +305,8 @@ static struct dentry *autofs4_expire(str
566
struct list_head *next;
567
int do_now = how & AUTOFS_EXP_IMMEDIATE;
568
int exp_leaves = how & AUTOFS_EXP_LEAVES;
569
+ struct autofs_info *ino;
570
+ unsigned int ino_count;
572
if ( !sbi->exp_timeout || !root )
574
@@ -240,7 +323,7 @@ static struct dentry *autofs4_expire(str
575
struct dentry *dentry = list_entry(next, struct dentry, d_child);
577
/* Negative dentry - give up */
578
- if ( !simple_positive(dentry) ) {
579
+ if (!simple_positive(dentry)) {
583
@@ -248,58 +331,116 @@ static struct dentry *autofs4_expire(str
584
dentry = dget(dentry);
585
spin_unlock(&dcache_lock);
587
- /* Case 1: indirect mount or top level direct mount */
588
+ spin_lock(&sbi->fs_lock);
589
+ ino = autofs4_dentry_ino(dentry);
592
+ * Case 1: (i) indirect mount or top level pseudo direct mount
594
+ * (ii) indirect mount with offset mount, check the "/"
595
+ * offset (autofs-5.0+).
597
if (d_mountpoint(dentry)) {
598
DPRINTK("checking mountpoint %p %.*s",
599
dentry, (int)dentry->d_name.len, dentry->d_name.name);
601
- /* Can we expire this guy */
602
- if (!autofs4_can_expire(dentry, timeout, do_now))
603
+ /* Path walk currently on this dentry? */
604
+ ino_count = atomic_read(&ino->count) + 2;
605
+ if (atomic_read(&dentry->d_count) > ino_count)
608
/* Can we umount this guy */
609
- if (autofs4_check_mount(mnt, dentry)) {
610
+ if (autofs4_mount_busy(mnt, dentry))
613
+ /* Can we expire this guy */
614
+ if (autofs4_can_expire(dentry, timeout, do_now)) {
622
- if ( simple_empty(dentry) )
623
+ if (simple_empty(dentry))
626
/* Case 2: tree mount, expire iff entire tree is not busy */
628
- if (autofs4_check_tree(mnt, dentry, timeout, do_now)) {
631
+ /* Path walk currently on this dentry? */
632
+ ino_count = atomic_read(&ino->count) + 1;
633
+ if (atomic_read(&dentry->d_count) > ino_count)
636
+ if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
640
- /* Case 3: direct mount, expire individual leaves */
642
+ * Case 3: pseudo direct mount, expire individual leaves
646
+ /* Path walk currently on this dentry? */
647
+ ino_count = atomic_read(&ino->count) + 1;
648
+ if (atomic_read(&dentry->d_count) > ino_count)
651
expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
659
+ spin_unlock(&sbi->fs_lock);
661
spin_lock(&dcache_lock);
664
+ spin_unlock(&dcache_lock);
668
- DPRINTK("returning %p %.*s",
669
- expired, (int)expired->d_name.len, expired->d_name.name);
670
- spin_lock(&dcache_lock);
671
- list_del(&expired->d_parent->d_subdirs);
672
- list_add(&expired->d_parent->d_subdirs, &expired->d_child);
673
- spin_unlock(&dcache_lock);
677
+ DPRINTK("returning %p %.*s",
678
+ expired, (int)expired->d_name.len, expired->d_name.name);
679
+ ino = autofs4_dentry_ino(expired);
680
+ ino->flags |= AUTOFS_INF_EXPIRING;
681
+ init_completion(&ino->expire_complete);
682
+ spin_unlock(&sbi->fs_lock);
683
+ spin_lock(&dcache_lock);
684
+ list_del(&expired->d_parent->d_subdirs);
685
+ list_add(&expired->d_parent->d_subdirs, &expired->d_child);
686
spin_unlock(&dcache_lock);
691
+int autofs4_expire_wait(struct dentry *dentry)
693
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
694
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
697
+ /* Block on any pending expire */
698
+ spin_lock(&sbi->fs_lock);
699
+ if (ino->flags & AUTOFS_INF_EXPIRING) {
700
+ spin_unlock(&sbi->fs_lock);
702
+ DPRINTK("waiting for expire %p name=%.*s",
703
+ dentry, dentry->d_name.len, dentry->d_name.name);
705
+ status = autofs4_wait(sbi, dentry, NFY_NONE);
706
+ wait_for_completion(&ino->expire_complete);
708
+ DPRINTK("expire done status=%d", status);
710
+ if (d_unhashed(dentry))
715
+ spin_unlock(&sbi->fs_lock);
720
/* Perform an expiry operation */
721
@@ -309,14 +450,16 @@ int autofs4_expire_run(struct super_bloc
722
struct autofs_packet_expire __user *pkt_p)
724
struct autofs_packet_expire pkt;
725
+ struct autofs_info *ino;
726
struct dentry *dentry;
729
memset(&pkt,0,sizeof pkt);
731
pkt.hdr.proto_version = sbi->version;
732
pkt.hdr.type = autofs_ptype_expire;
734
- if ((dentry = autofs4_expire(sb, mnt, sbi, 0)) == NULL)
735
+ if ((dentry = autofs4_expire_indirect(sb, mnt, sbi, 0)) == NULL)
738
pkt.len = dentry->d_name.len;
739
@@ -325,9 +468,15 @@ int autofs4_expire_run(struct super_bloc
742
if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
747
+ spin_lock(&sbi->fs_lock);
748
+ ino = autofs4_dentry_ino(dentry);
749
+ ino->flags &= ~AUTOFS_INF_EXPIRING;
750
+ complete_all(&ino->expire_complete);
751
+ spin_unlock(&sbi->fs_lock);
756
/* Call repeatedly until it returns -EAGAIN, meaning there's nothing
757
@@ -342,17 +491,29 @@ int autofs4_expire_multi(struct super_bl
758
if (arg && get_user(do_now, arg))
761
- if ((dentry = autofs4_expire(sb, mnt, sbi, do_now)) != NULL) {
762
- struct autofs_info *de_info = autofs4_dentry_ino(dentry);
763
+ if (sbi->type & AUTOFS_TYPE_TRIGGER)
764
+ dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
766
+ dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
769
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
771
/* This is synchronous because it makes the daemon a
773
- de_info->flags |= AUTOFS_INF_EXPIRING;
774
ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
775
- de_info->flags &= ~AUTOFS_INF_EXPIRING;
777
+ spin_lock(&sbi->fs_lock);
778
+ if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
779
+ sb->s_root->d_mounted++;
780
+ ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
782
+ ino->flags &= ~AUTOFS_INF_EXPIRING;
783
+ complete_all(&ino->expire_complete);
784
+ spin_unlock(&sbi->fs_lock);
792
Index: linux-2.6.11/fs/autofs4/inode.c
793
===================================================================
794
--- linux-2.6.11.orig/fs/autofs4/inode.c
795
+++ linux-2.6.11/fs/autofs4/inode.c
797
* linux/fs/autofs/inode.c
799
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
800
+ * Copyright 2005-2006 Ian Kent <raven@themaw.net>
802
* This file is part of the Linux kernel and is made available under
803
* the terms of the GNU General Public License, version 2, or at your
805
#include <linux/kernel.h>
806
#include <linux/slab.h>
807
#include <linux/file.h>
808
+#include <linux/seq_file.h>
809
#include <linux/pagemap.h>
810
#include <linux/parser.h>
811
#include <linux/bitops.h>
812
+#include <linux/smp_lock.h>
813
#include "autofs_i.h"
814
#include <linux/module.h>
816
@@ -40,12 +43,17 @@ struct autofs_info *autofs4_init_ino(str
823
- ino->dentry = NULL;
828
+ ino->dentry = NULL;
830
+ INIT_LIST_HEAD(&ino->active);
831
+ INIT_LIST_HEAD(&ino->expiring);
832
+ atomic_set(&ino->count, 0);
836
ino->last_used = jiffies;
839
@@ -65,10 +73,19 @@ struct autofs_info *autofs4_init_ino(str
841
void autofs4_free_ino(struct autofs_info *ino)
843
+ struct autofs_info *p_ino;
846
ino->dentry->d_fsdata = NULL;
847
- if (ino->dentry->d_inode)
848
+ if (ino->dentry->d_inode) {
849
+ struct dentry *parent = ino->dentry->d_parent;
850
+ if (atomic_dec_and_test(&ino->count)) {
851
+ p_ino = autofs4_dentry_ino(parent);
852
+ if (p_ino && parent != ino->dentry)
853
+ atomic_dec(&p_ino->count);
860
@@ -76,26 +93,121 @@ void autofs4_free_ino(struct autofs_info
864
-static void autofs4_put_super(struct super_block *sb)
866
+ * Deal with the infamous "Busy inodes after umount ..." message.
868
+ * Clean up the dentry tree. This happens with autofs if the user
869
+ * space program goes away due to a SIGKILL, SIGSEGV etc.
871
+static void autofs4_force_release(struct autofs_sb_info *sbi)
873
+ struct dentry *this_parent = sbi->sb->s_root;
874
+ struct list_head *next;
876
+ if (!sbi->sb->s_root)
879
+ spin_lock(&dcache_lock);
881
+ next = this_parent->d_subdirs.next;
883
+ while (next != &this_parent->d_subdirs) {
884
+ struct dentry *dentry = list_entry(next, struct dentry, d_child);
886
+ /* Negative dentry - don`t care */
887
+ if (!simple_positive(dentry)) {
892
+ if (!list_empty(&dentry->d_subdirs)) {
893
+ this_parent = dentry;
898
+ spin_unlock(&dcache_lock);
900
+ DPRINTK("dentry %p %.*s",
901
+ dentry, (int)dentry->d_name.len, dentry->d_name.name);
904
+ spin_lock(&dcache_lock);
907
+ if (this_parent != sbi->sb->s_root) {
908
+ struct dentry *dentry = this_parent;
910
+ next = this_parent->d_child.next;
911
+ this_parent = this_parent->d_parent;
912
+ spin_unlock(&dcache_lock);
913
+ DPRINTK("parent dentry %p %.*s",
914
+ dentry, (int)dentry->d_name.len, dentry->d_name.name);
916
+ spin_lock(&dcache_lock);
919
+ spin_unlock(&dcache_lock);
920
+ shrink_dcache_sb(sbi->sb);
923
+void autofs4_kill_sb(struct super_block *sb)
925
struct autofs_sb_info *sbi = autofs4_sbi(sb);
927
- sb->s_fs_info = NULL;
929
+ * In the event of a failure in get_sb_nodev the superblock
930
+ * info is not present so nothing else has been setup, so
931
+ * just call kill_anon_super when we are called from
932
+ * deactivate_super.
937
- if ( !sbi->catatonic )
938
- autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
939
+ /* Free wait queues, close pipe */
940
+ autofs4_catatonic_mode(sbi);
942
+ /* Clean up and release dangling references */
943
+ autofs4_force_release(sbi);
945
+ sb->s_fs_info = NULL;
949
DPRINTK("shutting down");
950
+ kill_anon_super(sb);
953
+static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt)
955
+ struct autofs_sb_info *sbi = autofs4_sbi(mnt->mnt_sb);
960
+ seq_printf(m, ",fd=%d", sbi->pipefd);
961
+ seq_printf(m, ",pgrp=%d", sbi->oz_pgrp);
962
+ seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ);
963
+ seq_printf(m, ",minproto=%d", sbi->min_proto);
964
+ seq_printf(m, ",maxproto=%d", sbi->max_proto);
966
+ if (sbi->type & AUTOFS_TYPE_OFFSET)
967
+ seq_printf(m, ",offset");
968
+ else if (sbi->type & AUTOFS_TYPE_DIRECT)
969
+ seq_printf(m, ",direct");
971
+ seq_printf(m, ",indirect");
976
static struct super_operations autofs4_sops = {
977
- .put_super = autofs4_put_super,
978
.statfs = simple_statfs,
979
+ .show_options = autofs4_show_options,
982
-enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto};
983
+enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto,
984
+ Opt_indirect, Opt_direct, Opt_offset};
986
static match_table_t tokens = {
988
@@ -104,11 +216,15 @@ static match_table_t tokens = {
989
{Opt_pgrp, "pgrp=%u"},
990
{Opt_minproto, "minproto=%u"},
991
{Opt_maxproto, "maxproto=%u"},
992
+ {Opt_indirect, "indirect"},
993
+ {Opt_direct, "direct"},
994
+ {Opt_offset, "offset"},
998
static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
999
- pid_t *pgrp, int *minproto, int *maxproto)
1000
+ pid_t *pgrp, unsigned int *type,
1001
+ int *minproto, int *maxproto)
1004
substring_t args[MAX_OPT_ARGS];
1005
@@ -162,6 +278,15 @@ static int parse_options(char *options,
1009
+ case Opt_indirect:
1010
+ *type = AUTOFS_TYPE_INDIRECT;
1013
+ *type = AUTOFS_TYPE_DIRECT;
1016
+ *type = AUTOFS_TYPE_OFFSET;
1021
@@ -180,6 +305,10 @@ static struct autofs_info *autofs4_mkroo
1025
+static struct dentry_operations autofs4_sb_dentry_operations = {
1026
+ .d_release = autofs4_dentry_release,
1029
int autofs4_fill_super(struct super_block *s, void *data, int silent)
1031
struct inode * root_inode;
1032
@@ -188,7 +317,6 @@ int autofs4_fill_super(struct super_bloc
1034
struct autofs_sb_info *sbi;
1035
struct autofs_info *ino;
1036
- int minproto, maxproto;
1038
sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
1040
@@ -199,14 +327,23 @@ int autofs4_fill_super(struct super_bloc
1043
sbi->magic = AUTOFS_SBI_MAGIC;
1044
- sbi->catatonic = 0;
1047
+ sbi->catatonic = 1;
1048
sbi->exp_timeout = 0;
1049
sbi->oz_pgrp = process_group(current);
1052
sbi->sub_version = 0;
1053
+ sbi->type = AUTOFS_TYPE_INDIRECT;
1054
+ sbi->min_proto = 0;
1055
+ sbi->max_proto = 0;
1056
init_MUTEX(&sbi->wq_sem);
1057
+ spin_lock_init(&sbi->fs_lock);
1059
+ spin_lock_init(&sbi->lookup_lock);
1060
+ INIT_LIST_HEAD(&sbi->active_list);
1061
+ INIT_LIST_HEAD(&sbi->expiring_list);
1062
s->s_blocksize = 1024;
1063
s->s_blocksize_bits = 10;
1064
s->s_magic = AUTOFS_SUPER_MAGIC;
1065
@@ -220,38 +357,46 @@ int autofs4_fill_super(struct super_bloc
1068
root_inode = autofs4_get_inode(s, ino);
1074
- root_inode->i_op = &autofs4_root_inode_operations;
1075
- root_inode->i_fop = &autofs4_root_operations;
1076
root = d_alloc_root(root_inode);
1083
+ root->d_op = &autofs4_sb_dentry_operations;
1084
+ root->d_fsdata = ino;
1086
/* Can this call block? */
1087
if (parse_options(data, &pipefd,
1088
&root_inode->i_uid, &root_inode->i_gid,
1090
- &minproto, &maxproto)) {
1091
+ &sbi->oz_pgrp, &sbi->type,
1092
+ &sbi->min_proto, &sbi->max_proto)) {
1093
printk("autofs: called with bogus options\n");
1097
+ root_inode->i_fop = &autofs4_root_operations;
1098
+ root_inode->i_op = sbi->type & AUTOFS_TYPE_TRIGGER ?
1099
+ &autofs4_direct_root_inode_operations :
1100
+ &autofs4_indirect_root_inode_operations;
1102
/* Couldn't this be tested earlier? */
1103
- if (maxproto < AUTOFS_MIN_PROTO_VERSION ||
1104
- minproto > AUTOFS_MAX_PROTO_VERSION) {
1105
+ if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
1106
+ sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
1107
printk("autofs: kernel does not match daemon version "
1108
"daemon (%d, %d) kernel (%d, %d)\n",
1109
- minproto, maxproto,
1110
+ sbi->min_proto, sbi->max_proto,
1111
AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
1115
- sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto;
1116
+ /* Establish highest kernel protocol version */
1117
+ if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
1118
+ sbi->version = AUTOFS_MAX_PROTO_VERSION;
1120
+ sbi->version = sbi->max_proto;
1121
sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
1123
DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp);
1124
@@ -264,6 +409,8 @@ int autofs4_fill_super(struct super_bloc
1125
if ( !pipe->f_op || !pipe->f_op->write )
1128
+ sbi->pipefd = pipefd;
1129
+ sbi->catatonic = 0;
1132
* Success! Install the root dentry now to indicate completion.
1133
@@ -284,8 +431,11 @@ fail_dput:
1135
printk("autofs: get root dentry failed\n");
1141
+ s->s_fs_info = NULL;
1145
Index: linux-2.6.11/fs/autofs4/waitq.c
1146
===================================================================
1147
--- linux-2.6.11.orig/fs/autofs4/waitq.c
1148
+++ linux-2.6.11/fs/autofs4/waitq.c
1150
* linux/fs/autofs/waitq.c
1152
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
1153
- * Copyright 2001-2003 Ian Kent <raven@themaw.net>
1154
+ * Copyright 2001-2006 Ian Kent <raven@themaw.net>
1156
* This file is part of the Linux kernel and is made available under
1157
* the terms of the GNU General Public License, version 2, or at your
1158
@@ -28,24 +28,31 @@ void autofs4_catatonic_mode(struct autof
1160
struct autofs_wait_queue *wq, *nwq;
1162
+ down(&sbi->wq_sem);
1163
+ if (sbi->catatonic) {
1168
DPRINTK("entering catatonic mode");
1172
sbi->queues = NULL; /* Erase all wait queues */
1176
wq->status = -ENOENT; /* Magic is gone - report failure */
1179
+ if (wq->name.name) {
1180
+ kfree(wq->name.name);
1181
+ wq->name.name = NULL;
1184
wake_up_interruptible(&wq->queue);
1188
- fput(sbi->pipe); /* Close the pipe */
1192
+ fput(sbi->pipe); /* Close the pipe */
1195
shrink_dcache_sb(sbi->sb);
1198
@@ -88,41 +95,90 @@ static void autofs4_notify_daemon(struct
1199
struct autofs_wait_queue *wq,
1202
- union autofs_packet_union pkt;
1204
+ struct autofs_packet_hdr hdr;
1205
+ union autofs_packet_union v4_pkt;
1206
+ union autofs_v5_packet_union v5_pkt;
1208
+ struct file *pipe = NULL;
1211
DPRINTK("wait id = 0x%08lx, name = %.*s, type=%d",
1212
- wq->wait_queue_token, wq->len, wq->name, type);
1213
+ wq->wait_queue_token, wq->name.len, wq->name.name, type);
1215
memset(&pkt,0,sizeof pkt); /* For security reasons */
1217
pkt.hdr.proto_version = sbi->version;
1218
pkt.hdr.type = type;
1219
- if (type == autofs_ptype_missing) {
1220
- struct autofs_packet_missing *mp = &pkt.missing;
1222
+ /* Kernel protocol v4 missing and expire packets */
1223
+ case autofs_ptype_missing:
1225
+ struct autofs_packet_missing *mp = &pkt.v4_pkt.missing;
1227
pktsz = sizeof(*mp);
1229
mp->wait_queue_token = wq->wait_queue_token;
1230
- mp->len = wq->len;
1231
- memcpy(mp->name, wq->name, wq->len);
1232
- mp->name[wq->len] = '\0';
1233
- } else if (type == autofs_ptype_expire_multi) {
1234
- struct autofs_packet_expire_multi *ep = &pkt.expire_multi;
1235
+ mp->len = wq->name.len;
1236
+ memcpy(mp->name, wq->name.name, wq->name.len);
1237
+ mp->name[wq->name.len] = '\0';
1240
+ case autofs_ptype_expire_multi:
1242
+ struct autofs_packet_expire_multi *ep = &pkt.v4_pkt.expire_multi;
1244
pktsz = sizeof(*ep);
1246
ep->wait_queue_token = wq->wait_queue_token;
1247
- ep->len = wq->len;
1248
- memcpy(ep->name, wq->name, wq->len);
1249
- ep->name[wq->len] = '\0';
1251
+ ep->len = wq->name.len;
1252
+ memcpy(ep->name, wq->name.name, wq->name.len);
1253
+ ep->name[wq->name.len] = '\0';
1257
+ * Kernel protocol v5 packet for handling indirect and direct
1258
+ * mount missing and expire requests
1260
+ case autofs_ptype_missing_indirect:
1261
+ case autofs_ptype_expire_indirect:
1262
+ case autofs_ptype_missing_direct:
1263
+ case autofs_ptype_expire_direct:
1265
+ struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
1267
+ pktsz = sizeof(*packet);
1269
+ packet->wait_queue_token = wq->wait_queue_token;
1270
+ packet->len = wq->name.len;
1271
+ memcpy(packet->name, wq->name.name, wq->name.len);
1272
+ packet->name[wq->name.len] = '\0';
1273
+ packet->dev = wq->dev;
1274
+ packet->ino = wq->ino;
1275
+ packet->uid = wq->uid;
1276
+ packet->gid = wq->gid;
1277
+ packet->pid = wq->pid;
1278
+ packet->tgid = wq->tgid;
1282
printk("autofs4_notify_daemon: bad type %d!\n", type);
1286
- if (autofs4_write(sbi->pipe, &pkt, pktsz))
1287
- autofs4_catatonic_mode(sbi);
1288
+ /* Check if we have become catatonic */
1289
+ down(&sbi->wq_sem);
1290
+ if (!sbi->catatonic) {
1297
+ if (autofs4_write(pipe, &pkt, pktsz))
1298
+ autofs4_catatonic_mode(sbi);
1303
static int autofs4_getpath(struct autofs_sb_info *sbi,
1304
@@ -138,7 +194,7 @@ static int autofs4_getpath(struct autofs
1305
for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
1306
len += tmp->d_name.len + 1;
1308
- if (--len > NAME_MAX) {
1309
+ if (!len || --len > NAME_MAX) {
1310
spin_unlock(&dcache_lock);
1313
@@ -157,44 +213,170 @@ static int autofs4_getpath(struct autofs
1317
+static struct autofs_wait_queue *
1318
+autofs4_find_wait(struct autofs_sb_info *sbi, struct qstr *qstr)
1320
+ struct autofs_wait_queue *wq = NULL;
1322
+ for (wq = sbi->queues ; wq ; wq = wq->next) {
1323
+ if (wq->name.hash == qstr->hash &&
1324
+ wq->name.len == qstr->len &&
1325
+ wq->name.name && !memcmp(wq->name, qstr->name, qstr->len))
1332
+ * Check if we have a valid request.
1334
+ * 1 if the request should continue.
1335
+ * In this case we can return an autofs_wait_queue entry if one is
1336
+ * found or NULL to idicate a new wait needs to be created.
1337
+ * 0 or a negative errno if the request shouldn't continue.
1339
+static int validate_request(struct autofs_wait_queue **wait,
1340
+ struct autofs_sb_info *sbi,
1341
+ struct qstr *qstr,
1342
+ struct dentry*dentry, enum autofs_notify notify)
1344
+ struct autofs_wait_queue *wq;
1345
+ struct autofs_info *ino;
1347
+ /* Wait in progress, continue; */
1348
+ wq = autofs4_find_wait(sbi, qstr);
1356
+ /* If we don't yet have any info this is a new request */
1357
+ ino = autofs4_dentry_ino(dentry);
1362
+ * If we've been asked to wait on an existing expire (NFY_NONE)
1363
+ * but there is no wait in the queue ...
1365
+ if (notify == NFY_NONE) {
1367
+ * Either we've betean the pending expire to post it's
1368
+ * wait or it finished while we waited on the semaphore.
1369
+ * So we need to wait till either, the wait appears
1370
+ * or the expire finishes.
1373
+ while (ino->flags & AUTOFS_INF_EXPIRING) {
1375
+ schedule_timeout_interruptible(HZ/10);
1376
+ if (down_interruptible(&sbi->wq_sem))
1379
+ wq = autofs4_find_wait(sbi, qstr);
1387
+ * Not ideal but the status has already gone. Of the two
1388
+ * cases where we wait on NFY_NONE neither depend on the
1389
+ * return status of the wait.
1395
+ * If we've been asked to trigger a mount and the request
1396
+ * completed while we waited on the semaphore ...
1398
+ if (notify == NFY_MOUNT) {
1400
+ * If the dentry isn't hashed just go ahead and try the
1401
+ * mount again with a new wait (not much else we can do).
1403
+ if (!d_unhashed(dentry)) {
1405
+ * But if the dentry is hashed, that means that we
1406
+ * got here through the revalidate path. Thus, we
1407
+ * need to check if the dentry has been mounted
1408
+ * while we waited on the wq_semaphore. If it has,
1409
+ * simply return success.
1411
+ if (d_mountpoint(dentry))
1419
int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
1420
enum autofs_notify notify)
1422
struct autofs_wait_queue *wq;
1426
+ int status, ret, type;
1428
/* In catatonic mode, we don't wait for nobody */
1429
- if ( sbi->catatonic )
1430
+ if (sbi->catatonic)
1434
+ if (!dentry->d_inode) {
1436
+ * A wait for a negative dentry is invalid for certain
1437
+ * cases. A direct or offset mount "always" has its mount
1438
+ * point directory created and so the request dentry must
1439
+ * be positive or the map key doesn't exist. The situation
1440
+ * is very similar for indirect mounts except only dentrys
1441
+ * in the root of the autofs file system may be negative.
1443
+ if (sbi->type & AUTOFS_TYPE_TRIGGER)
1445
+ else if (!IS_ROOT(dentry->d_parent))
1449
name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
1453
- len = autofs4_getpath(sbi, dentry, &name);
1457
+ /* If this is a direct mount request create a dummy name */
1458
+ if (IS_ROOT(dentry) && sbi->type & AUTOFS_TYPE_TRIGGER)
1459
+ qstr.len = sprintf(name, "%p", dentry);
1461
+ qstr.len = autofs4_getpath(sbi, dentry, &name);
1468
+ qstr.hash = full_name_hash(name, qstr.len);
1470
if (down_interruptible(&sbi->wq_sem)) {
1476
- for (wq = sbi->queues ; wq ; wq = wq->next) {
1477
- if (wq->hash == dentry->d_name.hash &&
1479
- wq->name && !memcmp(wq->name, name, len))
1481
+ ret = validate_request(&wq, sbi, &qstr, dentry, notify);
1491
/* Create a new wait queue */
1492
wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
1500
@@ -205,41 +387,53 @@ int autofs4_wait(struct autofs_sb_info *
1501
wq->next = sbi->queues;
1503
init_waitqueue_head(&wq->queue);
1504
- wq->hash = dentry->d_name.hash;
1507
+ memcpy(&wq->name, &qstr, sizeof(struct qstr));
1508
+ wq->dev = autofs4_get_dev(sbi);
1509
+ wq->ino = autofs4_get_ino(sbi);
1510
+ wq->uid = current->uid;
1511
+ wq->gid = current->gid;
1512
+ wq->pid = current->pid;
1513
+ wq->tgid = current->tgid;
1514
wq->status = -EINTR; /* Status return if interrupted */
1515
- atomic_set(&wq->wait_ctr, 2);
1519
- DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d",
1520
- (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
1521
- /* autofs4_notify_daemon() may block */
1522
- if (notify != NFY_NONE) {
1523
- autofs4_notify_daemon(sbi,wq,
1524
- notify == NFY_MOUNT ?
1525
- autofs_ptype_missing :
1526
- autofs_ptype_expire_multi);
1527
+ if (sbi->version < 5) {
1528
+ if (notify == NFY_MOUNT)
1529
+ type = autofs_ptype_missing;
1531
+ type = autofs_ptype_expire_multi;
1533
+ if (notify == NFY_MOUNT)
1534
+ type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
1535
+ autofs_ptype_missing_direct :
1536
+ autofs_ptype_missing_indirect;
1538
+ type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
1539
+ autofs_ptype_expire_direct :
1540
+ autofs_ptype_expire_indirect;
1543
+ DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
1544
+ (unsigned long) wq->wait_queue_token, wq->name.len,
1545
+ wq->name.name, notify);
1547
+ /* autofs4_notify_daemon() may block */
1548
+ autofs4_notify_daemon(sbi, wq, type);
1550
- atomic_inc(&wq->wait_ctr);
1554
DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
1555
- (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
1558
- /* wq->name is NULL if and only if the lock is already released */
1560
- if ( sbi->catatonic ) {
1561
- /* We might have slept, so check again for catatonic mode */
1562
- wq->status = -ENOENT;
1567
+ (unsigned long) wq->wait_queue_token, wq->name.len,
1568
+ wq->name.name, notify);
1573
+ * wq->name.name is NULL iff the lock is already released
1574
+ * or the mount has been made catatonic.
1576
+ if (wq->name.name) {
1577
/* Block all but "shutdown" signals while waiting */
1579
unsigned long irqflags;
1580
@@ -250,7 +444,7 @@ int autofs4_wait(struct autofs_sb_info *
1581
recalc_sigpending();
1582
spin_unlock_irqrestore(¤t->sighand->siglock, irqflags);
1584
- wait_event_interruptible(wq->queue, wq->name == NULL);
1585
+ wait_event_interruptible(wq->queue, wq->name.name == NULL);
1587
spin_lock_irqsave(¤t->sighand->siglock, irqflags);
1588
current->blocked = oldset;
1589
@@ -263,8 +457,10 @@ int autofs4_wait(struct autofs_sb_info *
1590
status = wq->status;
1592
/* Are we the last process to need status? */
1593
- if (atomic_dec_and_test(&wq->wait_ctr))
1594
+ down(&sbi->wq_sem);
1595
+ if (!--wq->wait_ctr)
1601
@@ -275,27 +471,24 @@ int autofs4_wait_release(struct autofs_s
1602
struct autofs_wait_queue *wq, **wql;
1605
- for ( wql = &sbi->queues ; (wq = *wql) != 0 ; wql = &wq->next ) {
1606
- if ( wq->wait_queue_token == wait_queue_token )
1607
+ for (wql = &sbi->queues ; (wq = *wql) != 0 ; wql = &wq->next) {
1608
+ if (wq->wait_queue_token == wait_queue_token)
1618
*wql = wq->next; /* Unlink from chain */
1621
- wq->name = NULL; /* Do not wait on this queue */
1623
+ kfree(wq->name.name);
1624
+ wq->name.name = NULL; /* Do not wait on this queue */
1625
wq->status = status;
1627
- if (atomic_dec_and_test(&wq->wait_ctr)) /* Is anyone still waiting for this guy? */
1628
+ wake_up_interruptible(&wq->queue);
1629
+ if (!--wq->wait_ctr)
1632
- wake_up_interruptible(&wq->queue);
1637
Index: linux-2.6.11/include/linux/auto_fs4.h
1638
===================================================================
1639
--- linux-2.6.11.orig/include/linux/auto_fs4.h
1640
+++ linux-2.6.11/include/linux/auto_fs4.h
1642
#undef AUTOFS_MIN_PROTO_VERSION
1643
#undef AUTOFS_MAX_PROTO_VERSION
1645
-#define AUTOFS_PROTO_VERSION 4
1646
+#define AUTOFS_PROTO_VERSION 5
1647
#define AUTOFS_MIN_PROTO_VERSION 3
1648
-#define AUTOFS_MAX_PROTO_VERSION 4
1649
+#define AUTOFS_MAX_PROTO_VERSION 5
1651
-#define AUTOFS_PROTO_SUBVERSION 5
1652
+#define AUTOFS_PROTO_SUBVERSION 0
1654
/* Mask for expire behaviour */
1655
#define AUTOFS_EXP_IMMEDIATE 1
1656
#define AUTOFS_EXP_LEAVES 2
1658
-/* New message type */
1659
-#define autofs_ptype_expire_multi 2 /* Expire entry (umount request) */
1660
+#define AUTOFS_TYPE_ANY 0x0000
1661
+#define AUTOFS_TYPE_INDIRECT 0x0001
1662
+#define AUTOFS_TYPE_DIRECT 0x0002
1663
+#define AUTOFS_TYPE_OFFSET 0x0004
1665
+/* Daemon notification packet types */
1666
+enum autofs_notify {
1672
+/* Kernel protocol version 4 packet types */
1674
+/* Expire entry (umount request) */
1675
+#define autofs_ptype_expire_multi 2
1677
+/* Kernel protocol version 5 packet types */
1679
+/* Indirect mount missing and expire requests. */
1680
+#define autofs_ptype_missing_indirect 3
1681
+#define autofs_ptype_expire_indirect 4
1683
+/* Direct mount missing and expire requests */
1684
+#define autofs_ptype_missing_direct 5
1685
+#define autofs_ptype_expire_direct 6
1687
/* v4 multi expire (via pipe) */
1688
struct autofs_packet_expire_multi {
1689
@@ -47,10 +71,38 @@ union autofs_packet_union {
1690
struct autofs_packet_expire_multi expire_multi;
1693
+/* autofs v5 common packet struct */
1694
+struct autofs_v5_packet {
1695
+ struct autofs_packet_hdr hdr;
1696
+ autofs_wqt_t wait_queue_token;
1704
+ char name[NAME_MAX+1];
1707
+typedef struct autofs_v5_packet autofs_packet_missing_indirect_t;
1708
+typedef struct autofs_v5_packet autofs_packet_expire_indirect_t;
1709
+typedef struct autofs_v5_packet autofs_packet_missing_direct_t;
1710
+typedef struct autofs_v5_packet autofs_packet_expire_direct_t;
1712
+union autofs_v5_packet_union {
1713
+ struct autofs_packet_hdr hdr;
1714
+ struct autofs_v5_packet v5_packet;
1715
+ autofs_packet_missing_indirect_t missing_indirect;
1716
+ autofs_packet_expire_indirect_t expire_indirect;
1717
+ autofs_packet_missing_direct_t missing_direct;
1718
+ autofs_packet_expire_direct_t expire_direct;
1721
#define AUTOFS_IOC_EXPIRE_MULTI _IOW(0x93,0x66,int)
1722
+#define AUTOFS_IOC_EXPIRE_INDIRECT AUTOFS_IOC_EXPIRE_MULTI
1723
+#define AUTOFS_IOC_EXPIRE_DIRECT AUTOFS_IOC_EXPIRE_MULTI
1724
#define AUTOFS_IOC_PROTOSUBVER _IOR(0x93,0x67,int)
1725
-#define AUTOFS_IOC_ASKREGHOST _IOR(0x93,0x68,int)
1726
-#define AUTOFS_IOC_TOGGLEREGHOST _IOR(0x93,0x69,int)
1727
#define AUTOFS_IOC_ASKUMOUNT _IOR(0x93,0x70,int)
1730
Index: linux-2.6.11/fs/autofs4/root.c
1731
===================================================================
1732
--- linux-2.6.11.orig/fs/autofs4/root.c
1733
+++ linux-2.6.11/fs/autofs4/root.c
1736
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
1737
* Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
1738
- * Copyright 2001-2003 Ian Kent <raven@themaw.net>
1739
+ * Copyright 2001-2006 Ian Kent <raven@themaw.net>
1741
* This file is part of the Linux kernel and is made available under
1742
* the terms of the GNU General Public License, version 2, or at your
1743
@@ -25,28 +25,28 @@ static int autofs4_dir_rmdir(struct inod
1744
static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
1745
static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
1746
static int autofs4_dir_open(struct inode *inode, struct file *file);
1747
-static int autofs4_dir_close(struct inode *inode, struct file *file);
1748
-static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir);
1749
-static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
1750
static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
1751
-static int autofs4_dcache_readdir(struct file *, void *, filldir_t);
1752
+static int autofs4_follow_link(struct dentry *, struct nameidata *);
1754
+#define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
1755
+#define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
1757
struct file_operations autofs4_root_operations = {
1758
.open = dcache_dir_open,
1759
.release = dcache_dir_close,
1760
.read = generic_read_dir,
1761
- .readdir = autofs4_root_readdir,
1762
+ .readdir = dcache_readdir,
1763
.ioctl = autofs4_root_ioctl,
1766
struct file_operations autofs4_dir_operations = {
1767
.open = autofs4_dir_open,
1768
- .release = autofs4_dir_close,
1769
+ .release = dcache_dir_close,
1770
.read = generic_read_dir,
1771
- .readdir = autofs4_dir_readdir,
1772
+ .readdir = dcache_readdir,
1775
-struct inode_operations autofs4_root_inode_operations = {
1776
+struct inode_operations autofs4_indirect_root_inode_operations = {
1777
.lookup = autofs4_lookup,
1778
.unlink = autofs4_dir_unlink,
1779
.symlink = autofs4_dir_symlink,
1780
@@ -54,6 +54,14 @@ struct inode_operations autofs4_root_ino
1781
.rmdir = autofs4_dir_rmdir,
1784
+struct inode_operations autofs4_direct_root_inode_operations = {
1785
+ .lookup = autofs4_lookup,
1786
+ .unlink = autofs4_dir_unlink,
1787
+ .mkdir = autofs4_dir_mkdir,
1788
+ .rmdir = autofs4_dir_rmdir,
1789
+ .follow_link = autofs4_follow_link,
1792
struct inode_operations autofs4_dir_inode_operations = {
1793
.lookup = autofs4_lookup,
1794
.unlink = autofs4_dir_unlink,
1795
@@ -62,113 +70,10 @@ struct inode_operations autofs4_dir_inod
1796
.rmdir = autofs4_dir_rmdir,
1799
-static int autofs4_root_readdir(struct file *file, void *dirent,
1800
- filldir_t filldir)
1802
- struct autofs_sb_info *sbi = autofs4_sbi(file->f_dentry->d_sb);
1803
- int oz_mode = autofs4_oz_mode(sbi);
1805
- DPRINTK("called, filp->f_pos = %lld", file->f_pos);
1808
- * Don't set reghost flag if:
1809
- * 1) f_pos is larger than zero -- we've already been here.
1810
- * 2) we haven't even enabled reghosting in the 1st place.
1811
- * 3) this is the daemon doing a readdir
1813
- if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
1814
- sbi->needs_reghost = 1;
1816
- DPRINTK("needs_reghost = %d", sbi->needs_reghost);
1818
- return autofs4_dcache_readdir(file, dirent, filldir);
1821
-/* Update usage from here to top of tree, so that scan of
1822
- top-level directories will give a useful result */
1823
-static void autofs4_update_usage(struct dentry *dentry)
1825
- struct dentry *top = dentry->d_sb->s_root;
1827
- spin_lock(&dcache_lock);
1828
- for(; dentry != top; dentry = dentry->d_parent) {
1829
- struct autofs_info *ino = autofs4_dentry_ino(dentry);
1832
- update_atime(dentry->d_inode);
1833
- ino->last_used = jiffies;
1836
- spin_unlock(&dcache_lock);
1840
- * From 2.4 kernel readdir.c
1842
-static int autofs4_dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
1845
- struct dentry *dentry = filp->f_dentry;
1850
- if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
1856
- if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
1862
- struct list_head *list;
1865
- spin_lock(&dcache_lock);
1866
- list = dentry->d_subdirs.next;
1869
- if (list == &dentry->d_subdirs) {
1870
- spin_unlock(&dcache_lock);
1876
- list = list->next;
1880
- struct dentry *de = list_entry(list, struct dentry, d_child);
1882
- if (!d_unhashed(de) && de->d_inode) {
1883
- spin_unlock(&dcache_lock);
1884
- if (filldir(dirent, de->d_name.name, de->d_name.len, filp->f_pos, de->d_inode->i_ino, DT_UNKNOWN) < 0)
1886
- spin_lock(&dcache_lock);
1889
- list = list->next;
1890
- if (list != &dentry->d_subdirs)
1892
- spin_unlock(&dcache_lock);
1900
static int autofs4_dir_open(struct inode *inode, struct file *file)
1902
struct dentry *dentry = file->f_dentry;
1903
- struct vfsmount *mnt = file->f_vfsmnt;
1904
struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
1907
DPRINTK("file=%p dentry=%p %.*s",
1908
file, dentry, dentry->d_name.len, dentry->d_name.name);
1909
@@ -176,135 +81,31 @@ static int autofs4_dir_open(struct inode
1910
if (autofs4_oz_mode(sbi))
1913
- if (autofs4_ispending(dentry)) {
1914
- DPRINTK("dentry busy");
1918
- if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) {
1919
- struct nameidata nd;
1922
- /* In case there are stale directory dentrys from a failed mount */
1923
- spin_lock(&dcache_lock);
1924
- empty = list_empty(&dentry->d_subdirs);
1926
+ * An empty directory in an autofs file system is always a
1927
+ * mount point. The daemon must have failed to mount this
1928
+ * during lookup so it doesn't exist. This can happen, for
1929
+ * example, if user space returns an incorrect status for a
1930
+ * mount request. Otherwise we're doing a readdir on the
1931
+ * autofs file system so just let the libfs routines handle
1934
+ if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
1935
spin_unlock(&dcache_lock);
1938
- d_invalidate(dentry);
1940
- nd.flags = LOOKUP_DIRECTORY;
1941
- status = (dentry->d_op->d_revalidate)(dentry, &nd);
1947
- if (d_mountpoint(dentry)) {
1948
- struct file *fp = NULL;
1949
- struct vfsmount *fp_mnt = mntget(mnt);
1950
- struct dentry *fp_dentry = dget(dentry);
1952
- while (follow_down(&fp_mnt, &fp_dentry) && d_mountpoint(fp_dentry));
1954
- fp = dentry_open(fp_dentry, fp_mnt, file->f_flags);
1955
- status = PTR_ERR(fp);
1957
- file->private_data = NULL;
1960
- file->private_data = fp;
1967
-static int autofs4_dir_close(struct inode *inode, struct file *file)
1969
- struct dentry *dentry = file->f_dentry;
1970
- struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
1972
- DPRINTK("file=%p dentry=%p %.*s",
1973
- file, dentry, dentry->d_name.len, dentry->d_name.name);
1975
- if (autofs4_oz_mode(sbi))
1978
- if (autofs4_ispending(dentry)) {
1979
- DPRINTK("dentry busy");
1983
- if (d_mountpoint(dentry)) {
1984
- struct file *fp = file->private_data;
1988
+ spin_unlock(&dcache_lock);
1990
- filp_close(fp, current->files);
1991
- file->private_data = NULL;
1995
+ return dcache_dir_open(inode, file);
1998
-static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
1999
+static int try_to_fill_dentry(struct dentry *dentry, int flags)
2001
- struct dentry *dentry = file->f_dentry;
2002
struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
2003
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
2006
- DPRINTK("file=%p dentry=%p %.*s",
2007
- file, dentry, dentry->d_name.len, dentry->d_name.name);
2009
- if (autofs4_oz_mode(sbi))
2012
- if (autofs4_ispending(dentry)) {
2013
- DPRINTK("dentry busy");
2017
- if (d_mountpoint(dentry)) {
2018
- struct file *fp = file->private_data;
2023
- if (!fp->f_op || !fp->f_op->readdir)
2026
- status = vfs_readdir(fp, filldir, dirent);
2027
- file->f_pos = fp->f_pos;
2029
- autofs4_copy_atime(file, fp);
2033
- return autofs4_dcache_readdir(file, dirent, filldir);
2036
-static int try_to_fill_dentry(struct dentry *dentry,
2037
- struct super_block *sb,
2038
- struct autofs_sb_info *sbi, int flags)
2040
- struct autofs_info *de_info = autofs4_dentry_ino(dentry);
2043
- /* Block on any pending expiry here; invalidate the dentry
2044
- when expiration is done to trigger mount request with a new
2046
- if (de_info && (de_info->flags & AUTOFS_INF_EXPIRING)) {
2047
- DPRINTK("waiting for expire %p name=%.*s",
2048
- dentry, dentry->d_name.len, dentry->d_name.name);
2050
- status = autofs4_wait(sbi, dentry, NFY_NONE);
2052
- DPRINTK("expire done status=%d", status);
2057
DPRINTK("dentry=%p %.*s ino=%p",
2058
dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
2060
@@ -317,22 +118,19 @@ static int try_to_fill_dentry(struct den
2062
DPRINTK("mount done status=%d", status);
2064
- if (status && dentry->d_inode)
2065
- return 0; /* Try to get the kernel to invalidate this dentry */
2067
/* Turn this into a real negative dentry? */
2068
if (status == -ENOENT) {
2069
- dentry->d_time = jiffies + AUTOFS_NEGATIVE_TIMEOUT;
2070
spin_lock(&dentry->d_lock);
2071
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
2072
spin_unlock(&dentry->d_lock);
2075
} else if (status) {
2076
/* Return a negative dentry, but leave it "pending" */
2080
/* Trigger mount for path component or follow link */
2081
- } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) ||
2082
+ } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
2083
+ flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
2084
current->link_count) {
2085
DPRINTK("waiting for mount name=%.*s",
2086
dentry->d_name.len, dentry->d_name.name);
2087
@@ -348,19 +146,96 @@ static int try_to_fill_dentry(struct den
2088
spin_lock(&dentry->d_lock);
2089
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
2090
spin_unlock(&dentry->d_lock);
2096
- /* We don't update the usages for the autofs daemon itself, this
2097
- is necessary for recursive autofs mounts */
2098
- if (!autofs4_oz_mode(sbi))
2099
- autofs4_update_usage(dentry);
2100
+ /* Initialize expiry counter after successful mount */
2102
+ ino->last_used = jiffies;
2104
spin_lock(&dentry->d_lock);
2105
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
2106
spin_unlock(&dentry->d_lock);
2112
+/* For autofs direct mounts the follow link triggers the mount */
2113
+static int autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
2115
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
2116
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
2117
+ int oz_mode = autofs4_oz_mode(sbi);
2118
+ unsigned int lookup_type;
2121
+ DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
2122
+ dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
2125
+ * For an expire of a covered direct or offset mount we need
2126
+ * to beeak out of follow_down() at the autofs mount trigger
2127
+ * (d_mounted--), so we can see the expiring flag, and manage
2128
+ * the blocking and following here until the expire is completed.
2131
+ spin_lock(&sbi->fs_lock);
2132
+ if (ino->flags & AUTOFS_INF_EXPIRING) {
2133
+ spin_unlock(&sbi->fs_lock);
2134
+ /* Follow down to our covering mount. */
2135
+ if (!follow_down(&nd->mnt, &nd->dentry))
2139
+ spin_unlock(&sbi->fs_lock);
2143
+ /* If an expire request is pending everyone must wait. */
2144
+ autofs4_expire_wait(dentry);
2146
+ /* We trigger a mount for almost all flags */
2147
+ lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
2148
+ if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
2152
+ * If the dentry contains directories then it is an autofs
2153
+ * multi-mount with no root mount offset. So don't try to
2156
+ spin_lock(&dcache_lock);
2157
+ if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
2158
+ (!d_mountpoint(dentry) && __simple_empty(dentry))) {
2159
+ spin_unlock(&dcache_lock);
2161
+ status = try_to_fill_dentry(dentry, 0);
2167
+ spin_unlock(&dcache_lock);
2170
+ * If there is no root mount it must be an autofs
2171
+ * multi-mount with no root offset so we don't need
2174
+ if (d_mountpoint(dentry)) {
2175
+ if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
2190
@@ -369,47 +244,76 @@ static int try_to_fill_dentry(struct den
2191
* yet completely filled in, and revalidate has to delay such
2194
-static int autofs4_revalidate(struct dentry * dentry, struct nameidata *nd)
2195
+static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
2197
- struct inode * dir = dentry->d_parent->d_inode;
2198
+ struct inode *dir = dentry->d_parent->d_inode;
2199
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
2200
int oz_mode = autofs4_oz_mode(sbi);
2201
int flags = nd ? nd->flags : 0;
2205
/* Pending dentry */
2206
+ spin_lock(&sbi->fs_lock);
2207
if (autofs4_ispending(dentry)) {
2209
- status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
2210
+ /* The daemon never causes a mount to trigger */
2211
+ spin_unlock(&sbi->fs_lock);
2217
+ * If the directory has gone away due to an expire
2218
+ * we have been called as ->d_revalidate() and so
2219
+ * we need to return false and proceed to ->lookup().
2221
+ if (autofs4_expire_wait(dentry) == -EAGAIN)
2225
+ * A zero status is success otherwise we have a
2226
+ * negative error code.
2228
+ status = try_to_fill_dentry(dentry, flags);
2234
+ spin_unlock(&sbi->fs_lock);
2236
/* Negative dentry.. invalidate if "old" */
2237
if (dentry->d_inode == NULL)
2238
- return (dentry->d_time - jiffies <= AUTOFS_NEGATIVE_TIMEOUT);
2241
/* Check for a non-mountpoint directory with no contents */
2242
spin_lock(&dcache_lock);
2243
if (S_ISDIR(dentry->d_inode->i_mode) &&
2244
!d_mountpoint(dentry) &&
2245
- list_empty(&dentry->d_subdirs)) {
2246
+ __simple_empty(dentry)) {
2247
DPRINTK("dentry=%p %.*s, emptydir",
2248
dentry, dentry->d_name.len, dentry->d_name.name);
2249
spin_unlock(&dcache_lock);
2251
- status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
2253
+ /* The daemon never causes a mount to trigger */
2258
+ * A zero status is success otherwise we have a
2259
+ * negative error code.
2261
+ status = try_to_fill_dentry(dentry, flags);
2267
spin_unlock(&dcache_lock);
2269
- /* Update the usage list */
2271
- autofs4_update_usage(dentry);
2276
-static void autofs4_dentry_release(struct dentry *de)
2277
+void autofs4_dentry_release(struct dentry *de)
2279
struct autofs_info *inf;
2281
@@ -419,6 +323,17 @@ static void autofs4_dentry_release(struc
2282
de->d_fsdata = NULL;
2285
+ struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
2288
+ spin_lock(&sbi->lookup_lock);
2289
+ if (!list_empty(&inf->active))
2290
+ list_del(&inf->active);
2291
+ if (!list_empty(&inf->expiring))
2292
+ list_del(&inf->expiring);
2293
+ spin_unlock(&sbi->lookup_lock);
2299
@@ -438,48 +353,192 @@ static struct dentry_operations autofs4_
2300
.d_release = autofs4_dentry_release,
2303
+static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
2305
+ unsigned int len = name->len;
2306
+ unsigned int hash = name->hash;
2307
+ const unsigned char *str = name->name;
2308
+ struct list_head *p, *head;
2310
+ spin_lock(&dcache_lock);
2311
+ spin_lock(&sbi->lookup_lock);
2312
+ head = &sbi->active_list;
2313
+ list_for_each(p, head) {
2314
+ struct autofs_info *ino;
2315
+ struct dentry *dentry;
2316
+ struct qstr *qstr;
2318
+ ino = list_entry(p, struct autofs_info, active);
2319
+ dentry = ino->dentry;
2321
+ spin_lock(&dentry->d_lock);
2323
+ /* Already gone? */
2324
+ if (atomic_read(&dentry->d_count) == 0)
2327
+ qstr = &dentry->d_name;
2329
+ if (dentry->d_name.hash != hash)
2331
+ if (dentry->d_parent != parent)
2334
+ if (qstr->len != len)
2336
+ if (memcmp(qstr->name, str, len))
2339
+ if (d_unhashed(dentry)) {
2341
+ spin_unlock(&dentry->d_lock);
2342
+ spin_unlock(&sbi->lookup_lock);
2343
+ spin_unlock(&dcache_lock);
2347
+ spin_unlock(&dentry->d_lock);
2349
+ spin_unlock(&sbi->lookup_lock);
2350
+ spin_unlock(&dcache_lock);
2355
+static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
2357
+ unsigned int len = name->len;
2358
+ unsigned int hash = name->hash;
2359
+ const unsigned char *str = name->name;
2360
+ struct list_head *p, *head;
2362
+ spin_lock(&dcache_lock);
2363
+ spin_lock(&sbi->lookup_lock);
2364
+ head = &sbi->expiring_list;
2365
+ list_for_each(p, head) {
2366
+ struct autofs_info *ino;
2367
+ struct dentry *dentry;
2368
+ struct qstr *qstr;
2370
+ ino = list_entry(p, struct autofs_info, expiring);
2371
+ dentry = ino->dentry;
2373
+ spin_lock(&dentry->d_lock);
2375
+ /* Bad luck, we've already been dentry_iput */
2376
+ if (!dentry->d_inode)
2379
+ qstr = &dentry->d_name;
2381
+ if (dentry->d_name.hash != hash)
2383
+ if (dentry->d_parent != parent)
2386
+ if (qstr->len != len)
2388
+ if (memcmp(qstr->name, str, len))
2391
+ if (d_unhashed(dentry)) {
2393
+ spin_unlock(&dentry->d_lock);
2394
+ spin_unlock(&sbi->lookup_lock);
2395
+ spin_unlock(&dcache_lock);
2399
+ spin_unlock(&dentry->d_lock);
2401
+ spin_unlock(&sbi->lookup_lock);
2402
+ spin_unlock(&dcache_lock);
2407
/* Lookups in the root directory */
2408
static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
2410
struct autofs_sb_info *sbi;
2411
+ struct autofs_info *ino;
2412
+ struct dentry *expiring, *unhashed;
2415
DPRINTK("name = %.*s",
2416
dentry->d_name.len, dentry->d_name.name);
2418
+ /* File name too long to exist */
2419
if (dentry->d_name.len > NAME_MAX)
2420
- return ERR_PTR(-ENAMETOOLONG);/* File name too long to exist */
2421
+ return ERR_PTR(-ENAMETOOLONG);
2423
sbi = autofs4_sbi(dir->i_sb);
2425
oz_mode = autofs4_oz_mode(sbi);
2427
DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
2428
current->pid, process_group(current), sbi->catatonic, oz_mode);
2431
- * Mark the dentry incomplete, but add it. This is needed so
2432
- * that the VFS layer knows about the dentry, and we can count
2433
- * on catching any lookups through the revalidate.
2435
- * Let all the hard work be done by the revalidate function that
2436
- * needs to be able to do this anyway..
2438
- * We need to do this before we release the directory semaphore.
2440
- dentry->d_op = &autofs4_root_dentry_operations;
2441
+ expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
2444
+ * If we are racing with expire the request might not
2445
+ * be quite complete but the directory has been removed
2446
+ * so it must have been successful, so just wait for it.
2448
+ ino = autofs4_dentry_ino(expiring);
2449
+ autofs4_expire_wait(expiring);
2450
+ spin_lock(&sbi->lookup_lock);
2451
+ if (!list_empty(&ino->expiring))
2452
+ list_del_init(&ino->expiring);
2453
+ spin_unlock(&sbi->lookup_lock);
2457
+ unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
2459
+ dentry = unhashed;
2462
+ * Mark the dentry incomplete but don't hash it. We do this
2463
+ * to serialize our inode creation operations (symlink and
2464
+ * mkdir) which prevents deadlock during the callback to
2465
+ * the daemon. Subsequent user space lookups for the same
2466
+ * dentry are placed on the wait queue while the daemon
2467
+ * itself is allowed passage unresticted so the create
2468
+ * operation itself can then hash the dentry. Finally,
2469
+ * we check for the hashed dentry and return the newly
2472
+ dentry->d_op = &autofs4_root_dentry_operations;
2475
+ * And we need to ensure that the same dentry is used for
2476
+ * all following lookup calls until it is hashed so that
2477
+ * the dentry flags are persistent throughout the request.
2479
+ ino = autofs4_init_ino(NULL, sbi, 0555);
2481
+ return ERR_PTR(-ENOMEM);
2483
+ dentry->d_fsdata = ino;
2484
+ ino->dentry = dentry;
2486
+ spin_lock(&sbi->lookup_lock);
2487
+ list_add(&ino->active, &sbi->active_list);
2488
+ spin_unlock(&sbi->lookup_lock);
2490
+ d_instantiate(dentry, NULL);
2494
spin_lock(&dentry->d_lock);
2495
dentry->d_flags |= DCACHE_AUTOFS_PENDING;
2496
spin_unlock(&dentry->d_lock);
2498
- dentry->d_fsdata = NULL;
2499
- d_add(dentry, NULL);
2501
- if (dentry->d_op && dentry->d_op->d_revalidate) {
2503
- (dentry->d_op->d_revalidate)(dentry, nd);
2504
- down(&dir->i_sem);
2505
+ if (dentry->d_op && dentry->d_op->d_revalidate) {
2507
+ (dentry->d_op->d_revalidate)(dentry, nd);
2508
+ down(&dir->i_sem);
2513
@@ -493,19 +552,47 @@ static struct dentry *autofs4_lookup(str
2514
if (sigismember (sigset, SIGKILL) ||
2515
sigismember (sigset, SIGQUIT) ||
2516
sigismember (sigset, SIGINT)) {
2519
return ERR_PTR(-ERESTARTNOINTR);
2523
+ spin_lock(&dentry->d_lock);
2524
+ dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
2525
+ spin_unlock(&dentry->d_lock);
2530
* If this dentry is unhashed, then we shouldn't honour this
2531
- * lookup even if the dentry is positive. Returning ENOENT here
2532
- * doesn't do the right thing for all system calls, but it should
2533
- * be OK for the operations we permit from an autofs.
2534
+ * lookup. Returning ENOENT here doesn't do the right thing
2535
+ * for all system calls, but it should be OK for the operations
2536
+ * we permit from an autofs.
2538
- if ( dentry->d_inode && d_unhashed(dentry) )
2539
- return ERR_PTR(-ENOENT);
2540
+ if (!oz_mode && d_unhashed(dentry)) {
2542
+ * A user space application can (and has done in the past)
2543
+ * remove and re-create this directory during the callback.
2544
+ * This can leave us with an unhashed dentry, but a
2545
+ * successful mount! So we need to perform another
2546
+ * cached lookup in case the dentry now exists.
2548
+ struct dentry *parent = dentry->d_parent;
2549
+ struct dentry *new = d_lookup(parent, &dentry->d_name);
2553
+ dentry = ERR_PTR(-ENOENT);
2566
@@ -516,6 +603,7 @@ static int autofs4_dir_symlink(struct in
2568
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
2569
struct autofs_info *ino = autofs4_dentry_ino(dentry);
2570
+ struct autofs_info *p_ino;
2571
struct inode *inode;
2574
@@ -526,21 +614,32 @@ static int autofs4_dir_symlink(struct in
2577
ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
2583
- ino->size = strlen(symname);
2584
- ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
2585
+ spin_lock(&sbi->lookup_lock);
2586
+ if (!list_empty(&ino->active))
2587
+ list_del_init(&ino->active);
2588
+ spin_unlock(&sbi->lookup_lock);
2593
+ ino->size = strlen(symname);
2594
+ cp = kmalloc(ino->size + 1, GFP_KERNEL);
2596
+ if (!dentry->d_fsdata)
2601
strcpy(cp, symname);
2603
inode = autofs4_get_inode(dir->i_sb, ino);
2604
- d_instantiate(dentry, inode);
2607
+ if (!dentry->d_fsdata)
2611
+ d_add(dentry, inode);
2613
if (dir == dir->i_sb->s_root->d_inode)
2614
dentry->d_op = &autofs4_root_dentry_operations;
2615
@@ -549,8 +648,13 @@ static int autofs4_dir_symlink(struct in
2617
dentry->d_fsdata = ino;
2618
ino->dentry = dget(dentry);
2619
+ atomic_inc(&ino->count);
2620
+ p_ino = autofs4_dentry_ino(dentry->d_parent);
2621
+ if (p_ino && dentry->d_parent != dentry)
2622
+ atomic_inc(&p_ino->count);
2625
+ ino->u.symlink = cp;
2626
dir->i_mtime = CURRENT_TIME;
2629
@@ -562,9 +666,9 @@ static int autofs4_dir_symlink(struct in
2630
* Normal filesystems would do a "d_delete()" to tell the VFS dcache
2631
* that the file no longer exists. However, doing that means that the
2632
* VFS layer can turn the dentry into a negative dentry. We don't want
2633
- * this, because since the unlink is probably the result of an expire.
2634
- * We simply d_drop it, which allows the dentry lookup to remount it
2636
+ * this, because the unlink is probably the result of an expire.
2637
+ * We simply d_drop it and add it to a expiring list in the super block,
2638
+ * which allows the dentry lookup to check for an incomplete expire.
2640
* If a process is blocked on the dentry waiting for the expire to finish,
2641
* it will invalidate the dentry and try to mount with a new one.
2642
@@ -575,11 +679,17 @@ static int autofs4_dir_unlink(struct ino
2644
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
2645
struct autofs_info *ino = autofs4_dentry_ino(dentry);
2646
+ struct autofs_info *p_ino;
2648
/* This allows root to remove symlinks */
2649
if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) )
2652
+ if (atomic_dec_and_test(&ino->count)) {
2653
+ p_ino = autofs4_dentry_ino(dentry->d_parent);
2654
+ if (p_ino && dentry->d_parent != dentry)
2655
+ atomic_dec(&p_ino->count);
2659
dentry->d_inode->i_size = 0;
2660
@@ -587,7 +697,13 @@ static int autofs4_dir_unlink(struct ino
2662
dir->i_mtime = CURRENT_TIME;
2665
+ spin_lock(&dcache_lock);
2666
+ spin_lock(&sbi->lookup_lock);
2667
+ if (list_empty(&ino->expiring))
2668
+ list_add(&ino->expiring, &sbi->expiring_list);
2669
+ spin_unlock(&sbi->lookup_lock);
2671
+ spin_unlock(&dcache_lock);
2675
@@ -596,7 +712,11 @@ static int autofs4_dir_rmdir(struct inod
2677
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
2678
struct autofs_info *ino = autofs4_dentry_ino(dentry);
2679
+ struct autofs_info *p_ino;
2681
+ DPRINTK("dentry %p, removing %.*s",
2682
+ dentry, dentry->d_name.len, dentry->d_name.name);
2684
if (!autofs4_oz_mode(sbi))
2687
@@ -605,11 +725,19 @@ static int autofs4_dir_rmdir(struct inod
2688
spin_unlock(&dcache_lock);
2691
+ spin_lock(&sbi->lookup_lock);
2692
+ if (list_empty(&ino->expiring))
2693
+ list_add(&ino->expiring, &sbi->expiring_list);
2694
+ spin_unlock(&sbi->lookup_lock);
2696
spin_unlock(&dcache_lock);
2698
+ if (atomic_dec_and_test(&ino->count)) {
2699
+ p_ino = autofs4_dentry_ino(dentry->d_parent);
2700
+ if (p_ino && dentry->d_parent != dentry)
2701
+ atomic_dec(&p_ino->count);
2705
dentry->d_inode->i_size = 0;
2706
dentry->d_inode->i_nlink = 0;
2708
@@ -623,6 +751,7 @@ static int autofs4_dir_mkdir(struct inod
2710
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
2711
struct autofs_info *ino = autofs4_dentry_ino(dentry);
2712
+ struct autofs_info *p_ino;
2713
struct inode *inode;
2715
if ( !autofs4_oz_mode(sbi) )
2716
@@ -632,11 +761,21 @@ static int autofs4_dir_mkdir(struct inod
2717
dentry, dentry->d_name.len, dentry->d_name.name);
2719
ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
2725
+ spin_lock(&sbi->lookup_lock);
2726
+ if (!list_empty(&ino->active))
2727
+ list_del_init(&ino->active);
2728
+ spin_unlock(&sbi->lookup_lock);
2730
inode = autofs4_get_inode(dir->i_sb, ino);
2731
- d_instantiate(dentry, inode);
2733
+ if (!dentry->d_fsdata)
2737
+ d_add(dentry, inode);
2739
if (dir == dir->i_sb->s_root->d_inode)
2740
dentry->d_op = &autofs4_root_dentry_operations;
2741
@@ -645,6 +784,10 @@ static int autofs4_dir_mkdir(struct inod
2743
dentry->d_fsdata = ino;
2744
ino->dentry = dget(dentry);
2745
+ atomic_inc(&ino->count);
2746
+ p_ino = autofs4_dentry_ino(dentry->d_parent);
2747
+ if (p_ino && dentry->d_parent != dentry)
2748
+ atomic_inc(&p_ino->count);
2751
dir->i_mtime = CURRENT_TIME;
2752
@@ -684,51 +827,13 @@ static inline int autofs4_get_protosubve
2756
- * Tells the daemon whether we need to reghost or not. Also, clears
2757
- * the reghost_needed flag.
2759
-static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
2763
- DPRINTK("returning %d", sbi->needs_reghost);
2765
- status = put_user(sbi->needs_reghost, p);
2769
- sbi->needs_reghost = 0;
2774
- * Enable / Disable reghosting ioctl() operation
2776
-static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
2781
- status = get_user(val, p);
2783
- DPRINTK("reghost = %d", val);
2788
- /* turn on/off reghosting, with the val */
2789
- sbi->reghost_enabled = val;
2794
* Tells the daemon whether it can umount the autofs mount.
2796
static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
2800
- if (may_umount(mnt) == 0)
2801
+ if (may_umount(mnt))
2804
DPRINTK("returning %d", status);
2805
@@ -785,11 +890,6 @@ static int autofs4_root_ioctl(struct ino
2806
case AUTOFS_IOC_SETTIMEOUT:
2807
return autofs4_get_set_timeout(sbi, p);
2809
- case AUTOFS_IOC_TOGGLEREGHOST:
2810
- return autofs4_toggle_reghost(sbi, p);
2811
- case AUTOFS_IOC_ASKREGHOST:
2812
- return autofs4_ask_reghost(sbi, p);
2814
case AUTOFS_IOC_ASKUMOUNT:
2815
return autofs4_ask_umount(filp->f_vfsmnt, p);
2817
Index: linux-2.6.11/fs/autofs/dirhash.c
2818
===================================================================
2819
--- linux-2.6.11.orig/fs/autofs/dirhash.c
2820
+++ linux-2.6.11/fs/autofs/dirhash.c
2821
@@ -92,7 +92,7 @@ struct autofs_dir_ent *autofs_expire(str
2825
- if ( may_umount(mnt) == 0 ) {
2826
+ if ( may_umount(mnt) ) {
2828
DPRINTK(("autofs: signaling expire on %s\n", ent->name));
2829
return ent; /* Expirable! */
2830
Index: linux-2.6.11/fs/namespace.c
2831
===================================================================
2832
--- linux-2.6.11.orig/fs/namespace.c
2833
+++ linux-2.6.11/fs/namespace.c
2834
@@ -308,9 +308,9 @@ resume:
2835
spin_unlock(&vfsmount_lock);
2837
if (actual_refs > minimum_refs)
2845
EXPORT_SYMBOL(may_umount_tree);
2846
@@ -330,9 +330,10 @@ EXPORT_SYMBOL(may_umount_tree);
2848
int may_umount(struct vfsmount *mnt)
2851
if (atomic_read(&mnt->mnt_count) > 2)
2858
EXPORT_SYMBOL(may_umount);
2859
Index: linux-2.6.11/fs/namei.c
2860
===================================================================
2861
--- linux-2.6.11.orig/fs/namei.c
2862
+++ linux-2.6.11/fs/namei.c
2863
@@ -306,6 +306,29 @@ void path_release_on_umount(struct namei
2867
+static inline struct dentry *do_revalidate(struct dentry *dentry, struct nameidata *nd)
2869
+ int status = dentry->d_op->d_revalidate(dentry, nd);
2870
+ if (unlikely(status <= 0)) {
2872
+ * The dentry failed validation.
2873
+ * If d_revalidate returned 0 attempt to invalidate
2874
+ * the dentry otherwise d_revalidate is asking us
2875
+ * to return a fail status.
2878
+ if (!d_invalidate(dentry)) {
2884
+ dentry = ERR_PTR(status);
2891
* Internal lookup() using the new generic dcache.
2893
@@ -320,12 +343,9 @@ static struct dentry * cached_lookup(str
2895
dentry = d_lookup(parent, name);
2897
- if (dentry && dentry->d_op && dentry->d_op->d_revalidate) {
2898
- if (!dentry->d_op->d_revalidate(dentry, nd) && !d_invalidate(dentry)) {
2903
+ if (dentry && dentry->d_op && dentry->d_op->d_revalidate)
2904
+ dentry = do_revalidate(dentry, nd);
2909
@@ -418,10 +438,9 @@ static struct dentry * real_lookup(struc
2912
if (result->d_op && result->d_op->d_revalidate) {
2913
- if (!result->d_op->d_revalidate(result, nd) && !d_invalidate(result)) {
2915
+ result = do_revalidate(result, nd);
2917
result = ERR_PTR(-ENOENT);
2922
@@ -662,12 +681,12 @@ need_lookup:
2926
- if (dentry->d_op->d_revalidate(dentry, nd))
2928
- if (d_invalidate(dentry))
2932
+ dentry = do_revalidate(dentry, nd);
2935
+ if (IS_ERR(dentry))
2940
return PTR_ERR(dentry);
2941
@@ -773,6 +792,11 @@ int fastcall link_path_walk(const char *
2943
if (inode->i_op->follow_link) {
2945
+ if (next.mnt != nd->mnt) {
2947
+ nd->mnt = next.mnt;
2948
+ nd->dentry = dget(next.dentry);
2950
err = do_follow_link(next.dentry, nd);
2953
@@ -827,6 +851,11 @@ last_component:
2954
if ((lookup_flags & LOOKUP_FOLLOW)
2955
&& inode && inode->i_op && inode->i_op->follow_link) {
2957
+ if (next.mnt != nd->mnt) {
2959
+ nd->mnt = next.mnt;
2960
+ nd->dentry = dget(next.dentry);
2962
err = do_follow_link(next.dentry, nd);
2965
Index: linux-2.6.11/fs/autofs/init.c
2966
===================================================================
2967
--- linux-2.6.11.orig/fs/autofs/init.c
2968
+++ linux-2.6.11/fs/autofs/init.c
2969
@@ -24,7 +24,7 @@ static struct file_system_type autofs_fs
2970
.owner = THIS_MODULE,
2972
.get_sb = autofs_get_sb,
2973
- .kill_sb = kill_anon_super,
2974
+ .kill_sb = autofs_kill_sb,
2977
static int __init init_autofs_fs(void)
2978
Index: linux-2.6.11/fs/autofs/inode.c
2979
===================================================================
2980
--- linux-2.6.11.orig/fs/autofs/inode.c
2981
+++ linux-2.6.11/fs/autofs/inode.c
2983
#include "autofs_i.h"
2984
#include <linux/module.h>
2986
-static void autofs_put_super(struct super_block *sb)
2987
+void autofs4_kill_sb(struct super_block *sb)
2989
struct autofs_sb_info *sbi = autofs_sbi(sb);
2993
+ * In the event of a failure in get_sb_nodev the superblock
2994
+ * info is not present so nothing else has been setup, so
2995
+ * just call kill_anon_super when we are called from
2996
+ * deactivate_super.
3001
if ( !sbi->catatonic )
3002
autofs_catatonic_mode(sbi); /* Free wait queues, close pipe */
3004
@@ -35,14 +44,15 @@ static void autofs_put_super(struct supe
3006
kfree(sb->s_fs_info);
3009
DPRINTK(("autofs: shutting down\n"));
3010
+ kill_anon_super(sb);
3013
static void autofs_read_inode(struct inode *inode);
3015
static struct super_operations autofs_sops = {
3016
.read_inode = autofs_read_inode,
3017
- .put_super = autofs_put_super,
3018
.statfs = simple_statfs,
3021
@@ -136,7 +146,8 @@ int autofs_fill_super(struct super_block
3024
sbi->magic = AUTOFS_SBI_MAGIC;
3025
- sbi->catatonic = 0;
3027
+ sbi->catatonic = 1;
3028
sbi->exp_timeout = 0;
3029
sbi->oz_pgrp = process_group(current);
3030
autofs_initialize_hash(&sbi->dirhash);
3031
@@ -179,6 +190,7 @@ int autofs_fill_super(struct super_block
3032
if ( !pipe->f_op || !pipe->f_op->write )
3035
+ sbi->catatonic = 0;
3038
* Success! Install the root dentry now to indicate completion.
3039
@@ -197,6 +209,7 @@ fail_iput:
3043
+ s->s_fs_info = NULL;
3047
Index: linux-2.6.11/fs/autofs/autofs_i.h
3048
===================================================================
3049
--- linux-2.6.11.orig/fs/autofs/autofs_i.h
3050
+++ linux-2.6.11/fs/autofs/autofs_i.h
3051
@@ -150,6 +150,7 @@ extern struct file_operations autofs_roo
3052
/* Initializing function */
3054
int autofs_fill_super(struct super_block *, void *, int);
3055
+void autofs_kill_sb(struct super_block *);
3057
/* Queue management functions */
3059
Index: linux-2.6.11/fs/autofs4/init.c
3060
===================================================================
3061
--- linux-2.6.11.orig/fs/autofs4/init.c
3062
+++ linux-2.6.11/fs/autofs4/init.c
3063
@@ -24,7 +24,7 @@ static struct file_system_type autofs_fs
3064
.owner = THIS_MODULE,
3066
.get_sb = autofs_get_sb,
3067
- .kill_sb = kill_anon_super,
3068
+ .kill_sb = autofs4_kill_sb,
3071
static int __init init_autofs4_fs(void)
3072
Index: linux-2.6.11/fs/autofs/waitq.c
3073
===================================================================
3074
--- linux-2.6.11.orig/fs/autofs/waitq.c
3075
+++ linux-2.6.11/fs/autofs/waitq.c
3076
@@ -41,6 +41,7 @@ void autofs_catatonic_mode(struct autofs
3079
fput(sbi->pipe); /* Close the pipe */
3081
autofs_hash_dputall(&sbi->dirhash); /* Remove all dentry pointers */
3084
Index: linux-2.6.11/include/linux/compat_ioctl.h
3085
===================================================================
3086
--- linux-2.6.11.orig/include/linux/compat_ioctl.h
3087
+++ linux-2.6.11/include/linux/compat_ioctl.h
3088
@@ -565,8 +565,6 @@ COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
3089
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
3090
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
3091
COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
3092
-COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
3093
-COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
3094
COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
3096
COMPATIBLE_IOCTL(DEVFSDIOC_GET_PROTO_REV)