1
diff -Nur linux-2.4.20.orig/fs/namei.c linux-2.4.20/fs/namei.c
2
--- linux-2.4.20.orig/fs/namei.c 2004-04-15 22:13:55.000000000 +0800
3
+++ linux-2.4.20/fs/namei.c 2004-04-24 14:43:56.000000000 +0800
8
- dentry = cached_lookup(nd->dentry, &this, 0);
9
+ dentry = cached_lookup(nd->dentry, &this, nd->flags);
11
- dentry = real_lookup(nd->dentry, &this, 0);
12
+ dentry = real_lookup(nd->dentry, &this, nd->flags);
13
err = PTR_ERR(dentry);
16
diff -Nur linux-2.4.22.orig/Documentation/Configure.help linux-2.4.22/Documentation/Configure.help
17
--- linux-2.4.22.orig/Documentation/Configure.help 2003-08-25 19:44:39.000000000 +0800
18
+++ linux-2.4.22/Documentation/Configure.help 2004-04-24 15:11:14.000000000 +0800
19
@@ -16397,7 +16397,7 @@
20
automounter (amd), which is a pure user space daemon.
22
To use the automounter you need the user-space tools from
23
- <ftp://ftp.kernel.org/pub/linux/daemons/autofs/testing-v4/>; you also
24
+ <ftp://ftp.kernel.org/pub/linux/daemons/autofs/v4/>; you also
25
want to answer Y to "NFS file system support", below.
27
If you want to compile this as a module ( = code which can be
28
--- linux-2.4.22/arch/x86_64/ia32/ia32_ioctl.c.compat-ioctl 2004-12-27 10:45:11.000000000 +0800
29
+++ linux-2.4.22/arch/x86_64/ia32/ia32_ioctl.c 2004-12-27 10:48:04.000000000 +0800
30
@@ -4002,6 +4002,10 @@
31
COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
32
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
33
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
34
+COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
35
+COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
36
+COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
37
+COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
39
COMPATIBLE_IOCTL(DEVFSDIOC_GET_PROTO_REV)
40
COMPATIBLE_IOCTL(DEVFSDIOC_SET_EVENT_MASK)
41
--- linux-2.4.22/arch/ppc64/kernel/ioctl32.c.compat-ioctl 2004-12-27 10:45:11.000000000 +0800
42
+++ linux-2.4.22/arch/ppc64/kernel/ioctl32.c 2004-12-27 10:54:23.000000000 +0800
43
@@ -4305,6 +4305,11 @@
44
COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC),
45
COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER),
46
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE),
47
+COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI),
48
+COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER),
49
+COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST),
50
+COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST),
51
+COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT),
53
COMPATIBLE_IOCTL(DEVFSDIOC_GET_PROTO_REV),
54
COMPATIBLE_IOCTL(DEVFSDIOC_SET_EVENT_MASK),
55
--- linux-2.4.22/arch/sparc64/kernel/ioctl32.c.compat-ioctl 2004-12-27 10:45:11.000000000 +0800
56
+++ linux-2.4.22/arch/sparc64/kernel/ioctl32.c 2004-12-27 10:48:04.000000000 +0800
57
@@ -4914,6 +4914,10 @@
58
COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
59
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
60
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
61
+COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
62
+COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
63
+COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
64
+COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
66
COMPATIBLE_IOCTL(DEVFSDIOC_GET_PROTO_REV)
67
COMPATIBLE_IOCTL(DEVFSDIOC_SET_EVENT_MASK)
68
--- linux-2.4.22/arch/mips64/kernel/ioctl32.c.compat-ioctl 2004-12-27 10:45:11.000000000 +0800
69
+++ linux-2.4.22/arch/mips64/kernel/ioctl32.c 2004-12-27 10:48:04.000000000 +0800
70
@@ -1247,6 +1247,10 @@
71
IOCTL32_HANDLER(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout),
72
IOCTL32_DEFAULT(AUTOFS_IOC_EXPIRE),
73
IOCTL32_DEFAULT(AUTOFS_IOC_EXPIRE_MULTI),
74
+ IOCTL32_DEFAULT(AUTOFS_IOC_PROTSUBVER),
75
+ IOCTL32_DEFAULT(AUTOFS_IOC_ASKREGHOST),
76
+ IOCTL32_DEFAULT(AUTOFS_IOC_TOGGLEREGHOST),
77
+ IOCTL32_DEFAULT(AUTOFS_IOC_ASKUMOUNT),
79
/* Little p (/dev/rtc, /dev/envctrl, etc.) */
80
IOCTL32_DEFAULT(_IOR('p', 20, int[7])), /* RTCGET */
81
--- linux-2.4.22/arch/parisc/kernel/ioctl32.c.compat-ioctl 2004-12-27 10:45:11.000000000 +0800
82
+++ linux-2.4.22/arch/parisc/kernel/ioctl32.c 2004-12-27 10:56:17.000000000 +0800
83
@@ -3375,6 +3375,11 @@
84
COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC)
85
COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
86
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
87
+COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
88
+COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
89
+COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
90
+COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
91
+COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
93
COMPATIBLE_IOCTL(DEVFSDIOC_GET_PROTO_REV)
94
COMPATIBLE_IOCTL(DEVFSDIOC_SET_EVENT_MASK)
95
diff -Nur linux-2.4.22/fs/autofs4/autofs_i.h autofs4-2.4/fs/autofs4/autofs_i.h
96
--- linux-2.4.22/fs/autofs4/autofs_i.h 2002-08-03 08:39:45.000000000 +0800
97
+++ autofs4-2.4/fs/autofs4/autofs_i.h 2005-04-04 22:27:31.000000000 +0800
100
/* This is for status reporting upon return */
107
#define AUTOFS_SBI_MAGIC 0x6d4a556d
113
unsigned long exp_timeout;
114
+ int reghost_enabled;
116
+ struct semaphore wq_sem;
117
+ spinlock_t fs_lock;
118
struct super_block *sb;
119
struct autofs_wait_queue *queues; /* Wait queue pointer */
121
@@ -118,13 +124,27 @@
122
static inline int autofs4_ispending(struct dentry *dentry)
124
struct autofs_info *inf = autofs4_dentry_ino(dentry);
127
- return (dentry->d_flags & DCACHE_AUTOFS_PENDING) ||
128
- (inf != NULL && inf->flags & AUTOFS_INF_EXPIRING);
129
+ if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
133
+ spin_lock(&inf->sbi->fs_lock);
134
+ pending = inf->flags & AUTOFS_INF_EXPIRING;
135
+ spin_unlock(&inf->sbi->fs_lock);
141
+static inline void autofs4_copy_atime(struct file *src, struct file *dst)
143
+ dst->f_dentry->d_inode->i_atime = src->f_dentry->d_inode->i_atime;
147
struct inode *autofs4_get_inode(struct super_block *, struct autofs_info *);
148
-struct autofs_info *autofs4_init_inf(struct autofs_sb_info *, mode_t mode);
149
void autofs4_free_ino(struct autofs_info *);
153
extern struct inode_operations autofs4_symlink_inode_operations;
154
extern struct inode_operations autofs4_dir_inode_operations;
155
extern struct inode_operations autofs4_root_inode_operations;
156
+extern struct file_operations autofs4_dir_operations;
157
extern struct file_operations autofs4_root_operations;
159
/* Initializing function */
164
-int autofs4_wait(struct autofs_sb_info *,struct qstr *, enum autofs_notify);
165
+int autofs4_wait(struct autofs_sb_info *,struct dentry *, enum autofs_notify);
166
int autofs4_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
167
void autofs4_catatonic_mode(struct autofs_sb_info *);
169
+#if !defined(REDHAT_KERNEL) || LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19)
171
+ * list_for_each_entry - iterate over list of given type
172
+ * @pos: the type * to use as a loop counter.
173
+ * @head: the head for your list.
174
+ * @member: the name of the list_struct within the struct.
176
+#define list_for_each_entry(pos, head, member) \
177
+ for (pos = list_entry((head)->next, typeof(*pos), member), \
178
+ prefetch(pos->member.next); \
179
+ &pos->member != (head); \
180
+ pos = list_entry(pos->member.next, typeof(*pos), member), \
181
+ prefetch(pos->member.next))
185
+static inline int simple_positive(struct dentry *dentry)
187
+ return dentry->d_inode && !d_unhashed(dentry);
190
+static inline int simple_empty_nolock(struct dentry *dentry)
192
+ struct dentry *child;
195
+ list_for_each_entry(child, &dentry->d_subdirs, d_child)
196
+ if (simple_positive(child))
203
+static inline int simple_empty(struct dentry *dentry)
205
+ struct dentry *child;
208
+ spin_lock(&dcache_lock);
209
+ list_for_each_entry(child, &dentry->d_subdirs, d_child)
210
+ if (simple_positive(child))
214
+ spin_unlock(&dcache_lock);
218
diff -Nur linux-2.4.22/fs/autofs4/expire.c autofs4-2.4/fs/autofs4/expire.c
219
--- linux-2.4.22/fs/autofs4/expire.c 2001-06-12 10:15:27.000000000 +0800
220
+++ autofs4-2.4/fs/autofs4/expire.c 2005-04-04 22:27:31.000000000 +0800
223
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
224
* Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
225
+ * Copyright 2001-2003 Ian Kent <raven@themaw.net>
227
* This file is part of the Linux kernel and is made available under
228
* the terms of the GNU General Public License, version 2, or at your
229
@@ -13,134 +14,242 @@
231
#include "autofs_i.h"
234
- * Determine if a subtree of the namespace is busy.
236
- * mnt is the mount tree under the autofs mountpoint
238
-static inline int is_vfsmnt_tree_busy(struct vfsmount *mnt)
239
+static unsigned long now;
241
+/* Check if a dentry can be expired return 1 if it can else return 0 */
242
+static inline int autofs4_can_expire(struct dentry *dentry,
243
+ unsigned long timeout, int do_now)
245
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
247
+ /* dentry in the process of being deleted */
251
+ /* No point expiring a pending mount */
252
+ if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
256
+ /* Too young to die */
257
+ if (time_after(ino->last_used + timeout, now))
260
+ /* update last_used here :-
261
+ - obviously makes sense if it is in use now
262
+ - less obviously, prevents rapid-fire expire
263
+ attempts if expire fails the first time */
264
+ ino->last_used = now;
270
+/* Sorry I can't solve the problem without using counts either */
271
+static int autofs4_may_umount(struct vfsmount *mnt)
273
- struct vfsmount *this_parent = mnt;
274
struct list_head *next;
276
+ struct vfsmount *this_parent = mnt;
280
- count = atomic_read(&mnt->mnt_count) - 1;
281
+ actual_refs = atomic_read(&mnt->mnt_count);
284
+ spin_lock(&dcache_lock);
286
next = this_parent->mnt_mounts.next;
287
- DPRINTK(("is_vfsmnt_tree_busy: mnt=%p, this_parent=%p, next=%p\n",
288
- mnt, this_parent, next));
290
- for( ; next != &this_parent->mnt_mounts; next = next->next) {
291
- struct vfsmount *p = list_entry(next, struct vfsmount,
294
- /* -1 for struct vfs_mount's normal count,
295
- -1 to compensate for child's reference to parent */
296
- count += atomic_read(&p->mnt_count) - 1 - 1;
297
+ while (next != &this_parent->mnt_mounts) {
298
+ struct vfsmount *p = list_entry(next, struct vfsmount, mnt_child);
302
- DPRINTK(("is_vfsmnt_tree_busy: p=%p, count now %d\n",
304
+ actual_refs += atomic_read(&p->mnt_count);
307
if (!list_empty(&p->mnt_mounts)) {
311
- /* root is busy if any leaf is busy */
312
- if (atomic_read(&p->mnt_count) > 1)
316
- /* All done at this level ... ascend and resume the search. */
317
if (this_parent != mnt) {
318
- next = this_parent->mnt_child.next;
319
+ next = this_parent->mnt_child.next;
320
this_parent = this_parent->mnt_parent;
323
+ spin_unlock(&dcache_lock);
325
+ DPRINTK(("autofs4_may_umount: done actual = %d, minimum = %d\n",
326
+ actual_refs, minimum_refs));
328
- DPRINTK(("is_vfsmnt_tree_busy: count=%d\n", count));
329
- return count != 0; /* remaining users? */
330
+ return actual_refs > minimum_refs;
333
-/* Traverse a dentry's list of vfsmounts and return the number of
335
-static int check_vfsmnt(struct vfsmount *mnt, struct dentry *dentry)
336
+/* Check a mount point for busyness return 1 if not busy, otherwise */
337
+static int autofs4_check_mount(struct vfsmount *mnt, struct dentry *dentry)
339
- int ret = dentry->d_mounted;
340
- struct vfsmount *vfs = lookup_mnt(mnt, dentry);
343
- if (vfs && is_vfsmnt_tree_busy(vfs))
345
- DPRINTK(("check_vfsmnt: ret=%d\n", ret));
347
+ DPRINTK(("autofs4_check_mount: dentry %p %.*s\n",
348
+ dentry, (int)dentry->d_name.len, dentry->d_name.name));
353
+ if (!follow_down(&mnt, &dentry))
356
+ while (d_mountpoint(dentry) && follow_down(&mnt, &dentry))
359
+ /* This is an autofs submount, we can't expire it */
360
+ if (is_autofs4_dentry(dentry))
363
+ /* The big question */
364
+ if (autofs4_may_umount(mnt) == 0)
367
+ DPRINTK(("autofs4_check_mount: returning = %d\n", status));
373
-/* Check dentry tree for busyness. If a dentry appears to be busy
374
- because it is a mountpoint, check to see if the mounted
375
- filesystem is busy. */
376
-static int is_tree_busy(struct vfsmount *topmnt, struct dentry *top)
377
+/* Check a directory tree of mount points for busyness
378
+ * The tree is not busy iff no mountpoints are busy
379
+ * Return 1 if the tree is busy or 0 otherwise
381
+static int autofs4_check_tree(struct vfsmount *mnt,
382
+ struct dentry *top,
383
+ unsigned long timeout,
386
- struct dentry *this_parent;
387
+ struct dentry *this_parent = top;
388
struct list_head *next;
391
- count = atomic_read(&top->d_count);
393
- DPRINTK(("is_tree_busy: top=%p initial count=%d\n",
397
- if (is_autofs4_dentry(top)) {
399
- DPRINTK(("is_tree_busy: autofs; count=%d\n", count));
401
+ DPRINTK(("autofs4_check_tree: parent %p %.*s\n",
402
+ top, (int)top->d_name.len, top->d_name.name));
404
- if (d_mountpoint(top))
405
- count -= check_vfsmnt(topmnt, top);
406
+ /* Negative dentry - give up */
407
+ if (!simple_positive(top))
410
+ /* Timeout of a tree mount is determined by its top dentry */
411
+ if (!autofs4_can_expire(top, timeout, do_now))
414
+ /* Is someone visiting anywhere in the tree ? */
415
+ if (autofs4_may_umount(mnt))
419
+ spin_lock(&dcache_lock);
421
next = this_parent->d_subdirs.next;
424
while (next != &this_parent->d_subdirs) {
426
- struct dentry *dentry = list_entry(next, struct dentry,
428
+ struct dentry *dentry = list_entry(next, struct dentry, d_child);
430
+ /* Negative dentry - give up */
431
+ if (!simple_positive(dentry)) {
436
+ DPRINTK(("autofs4_check_tree: dentry %p %.*s\n",
437
+ dentry, (int)dentry->d_name.len, dentry->d_name.name));
439
+ if (!list_empty(&dentry->d_subdirs)) {
440
+ this_parent = dentry;
444
+ dentry = dget(dentry);
445
+ spin_unlock(&dcache_lock);
447
+ if (d_mountpoint(dentry)) {
448
+ /* First busy => tree busy */
449
+ if (!autofs4_check_mount(mnt, dentry)) {
456
+ spin_lock(&dcache_lock);
460
+ if (this_parent != top) {
461
+ next = this_parent->d_child.next;
462
+ this_parent = this_parent->d_parent;
465
+ spin_unlock(&dcache_lock);
470
+struct dentry *autofs4_check_leaves(struct vfsmount *mnt,
471
+ struct dentry *parent,
472
+ unsigned long timeout,
475
+ struct dentry *this_parent = parent;
476
+ struct list_head *next;
478
- count += atomic_read(&dentry->d_count) - 1;
479
+ DPRINTK(("autofs4_check_leaves: parent %p %.*s\n",
480
+ parent, (int)parent->d_name.len, parent->d_name.name));
482
- if (d_mountpoint(dentry))
483
- adj += check_vfsmnt(topmnt, dentry);
484
+ spin_lock(&dcache_lock);
486
+ next = this_parent->d_subdirs.next;
488
+ while (next != &this_parent->d_subdirs) {
489
+ struct dentry *dentry = list_entry(next, struct dentry, d_child);
491
- if (is_autofs4_dentry(dentry)) {
493
- DPRINTK(("is_tree_busy: autofs; adj=%d\n",
495
+ /* Negative dentry - give up */
496
+ if (!simple_positive(dentry)) {
502
+ DPRINTK(("autofs4_check_leaves: dentry %p %.*s\n",
503
+ dentry, (int)dentry->d_name.len, dentry->d_name.name));
505
if (!list_empty(&dentry->d_subdirs)) {
506
this_parent = dentry;
510
- if (atomic_read(&dentry->d_count) != adj) {
511
- DPRINTK(("is_tree_busy: busy leaf (d_count=%d adj=%d)\n",
512
- atomic_read(&dentry->d_count), adj));
514
+ dentry = dget(dentry);
515
+ spin_unlock(&dcache_lock);
517
+ if (d_mountpoint(dentry)) {
518
+ /* Can we expire this guy */
519
+ if (!autofs4_can_expire(dentry, timeout, do_now))
522
+ /* Can we umount this guy */
523
+ if (autofs4_check_mount(mnt, dentry))
528
+ spin_lock(&dcache_lock);
532
- /* All done at this level ... ascend and resume the search. */
533
- if (this_parent != top) {
534
- next = this_parent->d_child.next;
535
+ if (this_parent != parent) {
536
+ next = this_parent->d_child.next;
537
this_parent = this_parent->d_parent;
540
+ spin_unlock(&dcache_lock);
542
- DPRINTK(("is_tree_busy: count=%d\n", count));
543
- return count != 0; /* remaining users? */
548
@@ -152,61 +261,94 @@
549
static struct dentry *autofs4_expire(struct super_block *sb,
550
struct vfsmount *mnt,
551
struct autofs_sb_info *sbi,
555
- unsigned long now = jiffies;
556
unsigned long timeout;
557
struct dentry *root = sb->s_root;
558
- struct list_head *tmp;
559
+ struct dentry *expired = NULL;
560
+ struct list_head *next;
561
+ int do_now = how & AUTOFS_EXP_IMMEDIATE;
562
+ int exp_leaves = how & AUTOFS_EXP_LEAVES;
564
if (!sbi->exp_timeout || !root)
568
timeout = sbi->exp_timeout;
570
spin_lock(&dcache_lock);
571
- for(tmp = root->d_subdirs.next;
572
- tmp != &root->d_subdirs;
574
- struct autofs_info *ino;
575
- struct dentry *dentry = list_entry(tmp, struct dentry, d_child);
576
+ next = root->d_subdirs.next;
578
- if (dentry->d_inode == NULL)
579
+ /* On exit from the loop expire is set to a dgot dentry
580
+ * to expire or it's NULL */
581
+ while (next != &root->d_subdirs) {
582
+ struct dentry *dentry = list_entry(next, struct dentry, d_child);
584
+ /* Negative dentry - give up */
585
+ if (!simple_positive(dentry)) {
590
- ino = autofs4_dentry_ino(dentry);
591
+ dentry = dget(dentry);
592
+ spin_unlock(&dcache_lock);
595
- /* dentry in the process of being deleted */
597
+ /* Case 1: indirect mount or top level direct mount */
598
+ if (d_mountpoint(dentry)) {
599
+ DPRINTK(("autofs4_expire: checking mountpoint %p %.*s\n",
600
+ dentry, (int)dentry->d_name.len, dentry->d_name.name));
602
+ /* Can we expire this guy */
603
+ if (!autofs4_can_expire(dentry, timeout, do_now))
606
+ /* Can we umount this guy */
607
+ if (autofs4_check_mount(mnt, dentry)) {
614
- /* No point expiring a pending mount */
615
- if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
617
+ if (simple_empty(dentry))
621
- /* Too young to die */
622
- if (time_after(ino->last_used + timeout, now))
625
- /* update last_used here :-
626
- - obviously makes sense if it is in use now
627
- - less obviously, prevents rapid-fire expire
628
- attempts if expire fails the first time */
629
- ino->last_used = now;
630
+ /* Case 2: tree mount, expire iff entire tree is not busy */
632
+ /* Lock the tree as we must expire as a whole */
633
+ spin_lock(&sbi->fs_lock);
634
+ if (autofs4_check_tree(mnt, dentry, timeout, do_now)) {
635
+ struct autofs_info *inf = autofs4_dentry_ino(dentry);
637
+ /* Set this flag early to catch sys_chdir and the like */
638
+ inf->flags |= AUTOFS_INF_EXPIRING;
639
+ spin_unlock(&sbi->fs_lock);
643
+ spin_unlock(&sbi->fs_lock);
644
+ /* Case 3: direct mount, expire individual leaves */
646
+ expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
652
- if (!is_tree_busy(mnt, dentry)) {
653
- DPRINTK(("autofs_expire: returning %p %.*s\n",
654
- dentry, (int)dentry->d_name.len, dentry->d_name.name));
655
- /* Start from here next time */
656
- list_del(&root->d_subdirs);
657
- list_add(&root->d_subdirs, &dentry->d_child);
659
- spin_unlock(&dcache_lock);
662
+ spin_lock(&dcache_lock);
669
+ DPRINTK(("autofs4_expire: returning %p %.*s\n",
670
+ expired, (int)expired->d_name.len, expired->d_name.name));
671
+ spin_lock(&dcache_lock);
672
+ list_del(&expired->d_parent->d_subdirs);
673
+ list_add(&expired->d_parent->d_subdirs, &expired->d_child);
674
+ spin_unlock(&dcache_lock);
677
spin_unlock(&dcache_lock);
679
@@ -259,11 +401,11 @@
680
/* This is synchronous because it makes the daemon a
682
de_info->flags |= AUTOFS_INF_EXPIRING;
683
- ret = autofs4_wait(sbi, &dentry->d_name, NFY_EXPIRE);
684
+ ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
685
de_info->flags &= ~AUTOFS_INF_EXPIRING;
693
diff -Nur linux-2.4.22/fs/autofs4/inode.c autofs4-2.4/fs/autofs4/inode.c
694
--- linux-2.4.22/fs/autofs4/inode.c 2002-08-03 08:39:45.000000000 +0800
695
+++ autofs4-2.4/fs/autofs4/inode.c 2005-04-04 22:27:31.000000000 +0800
700
- DPRINTK(("autofs: shutting down\n"));
701
+ DPRINTK(("autofs4: shutting down\n"));
704
static int autofs4_statfs(struct super_block *sb, struct statfs *buf);
705
@@ -181,12 +181,13 @@
708
struct autofs_sb_info *sbi;
709
+ struct autofs_info *ino;
710
int minproto, maxproto;
712
sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
715
- DPRINTK(("autofs: starting up, sbi = %p\n",sbi));
716
+ DPRINTK(("autofs4: starting up, sbi = %p\n",sbi));
718
memset(sbi, 0, sizeof(*sbi));
721
sbi->oz_pgrp = current->pgrp;
724
+ sbi->sub_version = 0;
725
+ init_MUTEX(&sbi->wq_sem);
726
+ spin_lock_init(&sbi->fs_lock);
728
+ sbi->reghost_enabled = 0;
729
+ sbi->needs_reghost = 0;
730
s->s_blocksize = 1024;
731
s->s_blocksize_bits = 10;
732
s->s_magic = AUTOFS_SUPER_MAGIC;
735
* Get the root inode and dentry, but defer checking for errors.
737
- root_inode = autofs4_get_inode(s, autofs4_mkroot(sbi));
738
+ ino = autofs4_mkroot(sbi);
739
+ root_inode = autofs4_get_inode(s, ino);
744
root_inode->i_op = &autofs4_root_inode_operations;
745
root_inode->i_fop = &autofs4_root_operations;
746
root = d_alloc_root(root_inode);
747
@@ -220,14 +231,14 @@
748
&root_inode->i_uid, &root_inode->i_gid,
750
&minproto, &maxproto)) {
751
- printk("autofs: called with bogus options\n");
752
+ printk("autofs4: called with bogus options\n");
756
/* Couldn't this be tested earlier? */
757
if (maxproto < AUTOFS_MIN_PROTO_VERSION ||
758
minproto > AUTOFS_MAX_PROTO_VERSION) {
759
- printk("autofs: kernel does not match daemon version "
760
+ printk("autofs4: kernel does not match daemon version "
761
"daemon (%d, %d) kernel (%d, %d)\n",
763
AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
764
@@ -235,12 +246,13 @@
767
sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto;
768
+ sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
770
- DPRINTK(("autofs: pipe fd = %d, pgrp = %u\n", pipefd, sbi->oz_pgrp));
771
+ DPRINTK(("autofs4: pipe fd = %d, pgrp = %u\n", pipefd, sbi->oz_pgrp));
775
- printk("autofs: could not open pipe file descriptor\n");
776
+ printk("autofs4: could not open pipe file descriptor\n");
779
if ( !pipe->f_op || !pipe->f_op->write )
781
* Failure ... clean up.
784
- printk("autofs: pipe file descriptor does not contain proper ops\n");
785
+ printk("autofs4: pipe file descriptor does not contain proper ops\n");
787
* fput() can block, so we clear the super block first.
793
- printk("autofs: get root dentry failed\n");
794
+ printk("autofs4: get root dentry failed\n");
796
* iput() can block, so we clear the super block first.
799
if (S_ISDIR(inf->mode)) {
801
inode->i_op = &autofs4_dir_inode_operations;
802
- inode->i_fop = &dcache_dir_ops;
803
+ inode->i_fop = &autofs4_dir_operations;
804
} else if (S_ISLNK(inf->mode)) {
805
inode->i_size = inf->size;
806
inode->i_op = &autofs4_symlink_inode_operations;
807
diff -Nur linux-2.4.22/fs/autofs4/root.c autofs4-2.4/fs/autofs4/root.c
808
--- linux-2.4.22/fs/autofs4/root.c 2003-08-25 19:44:43.000000000 +0800
809
+++ autofs4-2.4/fs/autofs4/root.c 2005-04-04 22:27:31.000000000 +0800
812
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
813
* Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
814
+ * Copyright 2001-2003 Ian Kent <raven@themaw.net>
816
* This file is part of the Linux kernel and is made available under
817
* the terms of the GNU General Public License, version 2, or at your
819
#include <linux/param.h>
820
#include <linux/sched.h>
821
#include <linux/smp_lock.h>
822
+#include <linux/file.h>
823
+#include <linux/limits.h>
824
+#include <linux/iobuf.h>
825
+#include <linux/module.h>
826
#include "autofs_i.h"
828
-static struct dentry *autofs4_dir_lookup(struct inode *,struct dentry *);
829
static int autofs4_dir_symlink(struct inode *,struct dentry *,const char *);
830
static int autofs4_dir_unlink(struct inode *,struct dentry *);
831
static int autofs4_dir_rmdir(struct inode *,struct dentry *);
832
static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
833
static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
834
-static struct dentry *autofs4_root_lookup(struct inode *,struct dentry *);
835
+static int autofs4_dir_open(struct inode *inode, struct file *file);
836
+static int autofs4_dir_close(struct inode *inode, struct file *file);
837
+static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir);
838
+static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
839
+static struct dentry *autofs4_lookup(struct inode *,struct dentry *);
840
+static int autofs4_dcache_readdir(struct file *, void *, filldir_t);
842
struct file_operations autofs4_root_operations = {
843
- open: dcache_dir_open,
844
- release: dcache_dir_close,
845
- llseek: dcache_dir_lseek,
846
read: generic_read_dir,
847
- readdir: dcache_readdir,
848
- fsync: dcache_dir_fsync,
849
+ readdir: autofs4_root_readdir,
850
ioctl: autofs4_root_ioctl,
853
+struct file_operations autofs4_dir_operations = {
854
+ open: autofs4_dir_open,
855
+ release: autofs4_dir_close,
856
+ read: generic_read_dir,
857
+ readdir: autofs4_dir_readdir,
860
struct inode_operations autofs4_root_inode_operations = {
861
- lookup: autofs4_root_lookup,
862
+ lookup: autofs4_lookup,
863
unlink: autofs4_dir_unlink,
864
symlink: autofs4_dir_symlink,
865
mkdir: autofs4_dir_mkdir,
869
struct inode_operations autofs4_dir_inode_operations = {
870
- lookup: autofs4_dir_lookup,
871
+ lookup: autofs4_lookup,
872
unlink: autofs4_dir_unlink,
873
symlink: autofs4_dir_symlink,
874
mkdir: autofs4_dir_mkdir,
877
/* Update usage from here to top of tree, so that scan of
878
top-level directories will give a useful result */
879
-static void autofs4_update_usage(struct dentry *dentry)
880
+static inline void autofs4_update_usage(struct dentry *dentry)
882
struct dentry *top = dentry->d_sb->s_root;
884
+ spin_lock(&dcache_lock);
885
for(; dentry != top; dentry = dentry->d_parent) {
886
struct autofs_info *ino = autofs4_dentry_ino(dentry);
889
ino->last_used = jiffies;
892
+ spin_unlock(&dcache_lock);
895
+static int autofs4_root_readdir(struct file *file, void *dirent, filldir_t filldir)
897
+ struct autofs_sb_info *sbi = autofs4_sbi(file->f_dentry->d_sb);
898
+ int oz_mode = autofs4_oz_mode(sbi);
900
+ DPRINTK(("autofs4_root_readdir called, filp->f_pos = %lld\n", file->f_pos));
903
+ * Don't set reghost flag if:
904
+ * 1) f_pos is larger than zero -- we've already been here.
905
+ * 2) we haven't even enabled reghosting in the 1st place.
906
+ * 3) this is the daemon doing a readdir
908
+ if ( oz_mode && file->f_pos == 0 && sbi->reghost_enabled )
909
+ sbi->needs_reghost = 1;
911
+ DPRINTK(("autofs4_root_readdir: needs_reghost = %d\n", sbi->needs_reghost));
913
+ return autofs4_dcache_readdir(file, dirent, filldir);
917
+ * From 2.4 kernel readdir.c
919
+static int autofs4_dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
922
+ struct dentry *dentry = filp->f_dentry;
927
+ if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
933
+ if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
939
+ struct list_head *list;
942
+ spin_lock(&dcache_lock);
943
+ list = dentry->d_subdirs.next;
946
+ if (list == &dentry->d_subdirs) {
947
+ spin_unlock(&dcache_lock);
957
+ struct dentry *de = list_entry(list, struct dentry, d_child);
959
+ if (!list_empty(&de->d_hash) && de->d_inode) {
960
+ spin_unlock(&dcache_lock);
961
+ if (filldir(dirent, de->d_name.name, de->d_name.len, filp->f_pos, de->d_inode->i_ino, DT_UNKNOWN) < 0)
963
+ spin_lock(&dcache_lock);
967
+ if (list != &dentry->d_subdirs)
969
+ spin_unlock(&dcache_lock);
977
+static int autofs4_dir_open(struct inode *inode, struct file *file)
979
+ struct dentry *dentry = file->f_dentry;
980
+ struct vfsmount *mnt = file->f_vfsmnt;
981
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
984
+ DPRINTK(("autofs4_dir_open: file=%p dentry=%p %.*s\n",
985
+ file, dentry, dentry->d_name.len, dentry->d_name.name));
987
+ if (autofs4_oz_mode(sbi))
990
+ if (autofs4_ispending(dentry)) {
991
+ DPRINTK(("autofs4_dir_open: dentry busy\n"));
995
+ if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) {
998
+ /* In case there are stale directory dentrys from a failed mount */
999
+ spin_lock(&dcache_lock);
1000
+ empty = list_empty(&dentry->d_subdirs);
1001
+ spin_unlock(&dcache_lock);
1004
+ d_invalidate(dentry);
1006
+ status = (dentry->d_op->d_revalidate)(dentry, LOOKUP_CONTINUE);
1012
+ if ( d_mountpoint(dentry) ) {
1013
+ struct file *fp = NULL;
1014
+ struct vfsmount *fp_mnt = mntget(mnt);
1015
+ struct dentry *fp_dentry = dget(dentry);
1017
+ while (follow_down(&fp_mnt, &fp_dentry) && d_mountpoint(fp_dentry));
1019
+ fp = dentry_open(fp_dentry, fp_mnt, file->f_flags);
1020
+ status = PTR_ERR(fp);
1021
+ if ( IS_ERR(fp) ) {
1022
+ file->private_data = NULL;
1025
+ file->private_data = fp;
1031
+static int autofs4_dir_close(struct inode *inode, struct file *file)
1033
+ struct dentry *dentry = file->f_dentry;
1034
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
1036
+ DPRINTK(("autofs4_dir_close: file=%p dentry=%p %.*s\n",
1037
+ file, dentry, dentry->d_name.len, dentry->d_name.name));
1039
+ if ( autofs4_oz_mode(sbi) )
1042
+ if ( autofs4_ispending(dentry) ) {
1043
+ DPRINTK(("autofs4_dir_close: dentry busy\n"));
1047
+ if ( d_mountpoint(dentry) ) {
1048
+ struct file *fp = file->private_data;
1053
+ filp_close(fp, current->files);
1054
+ file->private_data = NULL;
1060
+static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
1062
+ struct dentry *dentry = file->f_dentry;
1063
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
1066
+ DPRINTK(("autofs4_readdir: file=%p dentry=%p %.*s\n",
1067
+ file, dentry, dentry->d_name.len, dentry->d_name.name));
1069
+ if ( autofs4_oz_mode(sbi) )
1072
+ if ( autofs4_ispending(dentry) ) {
1073
+ DPRINTK(("autofs4_readdir: dentry busy\n"));
1077
+ if ( d_mountpoint(dentry) ) {
1078
+ struct file *fp = file->private_data;
1083
+ if (!fp->f_op || !fp->f_op->readdir)
1086
+ status = vfs_readdir(fp, filldir, dirent);
1087
+ file->f_pos = fp->f_pos;
1089
+ autofs4_copy_atime(file, fp);
1093
+ return autofs4_dcache_readdir(file, dirent, filldir);
1096
static int try_to_fill_dentry(struct dentry *dentry,
1097
struct super_block *sb,
1098
- struct autofs_sb_info *sbi)
1099
+ struct autofs_sb_info *sbi, int flags)
1101
struct autofs_info *de_info = autofs4_dentry_ino(dentry);
1103
@@ -79,12 +294,11 @@
1104
when expiration is done to trigger mount request with a new
1106
if (de_info && (de_info->flags & AUTOFS_INF_EXPIRING)) {
1107
- DPRINTK(("try_to_fill_entry: waiting for expire %p name=%.*s, flags&PENDING=%s de_info=%p de_info->flags=%x\n",
1108
- dentry, dentry->d_name.len, dentry->d_name.name,
1109
- dentry->d_flags & DCACHE_AUTOFS_PENDING?"t":"f",
1110
- de_info, de_info?de_info->flags:0));
1111
- status = autofs4_wait(sbi, &dentry->d_name, NFY_NONE);
1113
+ DPRINTK(("try_to_fill_entry: waiting for expire %p name=%.*s\n",
1114
+ dentry, dentry->d_name.len, dentry->d_name.name));
1116
+ status = autofs4_wait(sbi, dentry, NFY_NONE);
1118
DPRINTK(("try_to_fill_entry: expire done status=%d\n", status));
1121
@@ -94,12 +308,12 @@
1122
dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode));
1124
/* Wait for a pending mount, triggering one if there isn't one already */
1125
- while(dentry->d_inode == NULL) {
1126
- DPRINTK(("try_to_fill_entry: waiting for mount name=%.*s, de_info=%p de_info->flags=%x\n",
1127
- dentry->d_name.len, dentry->d_name.name,
1128
- de_info, de_info?de_info->flags:0));
1129
- status = autofs4_wait(sbi, &dentry->d_name, NFY_MOUNT);
1131
+ if (dentry->d_inode == NULL) {
1132
+ DPRINTK(("try_to_fill_entry: waiting for mount name=%.*s\n",
1133
+ dentry->d_name.len, dentry->d_name.name));
1135
+ status = autofs4_wait(sbi, dentry, NFY_MOUNT);
1137
DPRINTK(("try_to_fill_entry: mount done status=%d\n", status));
1139
if (status && dentry->d_inode)
1140
@@ -108,72 +322,86 @@
1141
/* Turn this into a real negative dentry? */
1142
if (status == -ENOENT) {
1143
dentry->d_time = jiffies + AUTOFS_NEGATIVE_TIMEOUT;
1144
+ spin_lock(&dcache_lock);
1145
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
1146
+ spin_unlock(&dcache_lock);
1148
} else if (status) {
1149
/* Return a negative dentry, but leave it "pending" */
1153
+ /* Trigger mount for path component or follow link */
1154
+ } else if ( flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) ||
1155
+ current->link_count ) {
1156
+ DPRINTK(("try_to_fill_entry: waiting for mount name=%.*s\n",
1157
+ dentry->d_name.len, dentry->d_name.name));
1159
- /* If this is an unused directory that isn't a mount point,
1160
- bitch at the daemon and fix it in user space */
1161
- spin_lock(&dcache_lock);
1162
- if (S_ISDIR(dentry->d_inode->i_mode) &&
1163
- !d_mountpoint(dentry) &&
1164
- list_empty(&dentry->d_subdirs)) {
1165
- DPRINTK(("try_to_fill_entry: mounting existing dir\n"));
1166
+ spin_lock(&dcache_lock);
1167
+ dentry->d_flags |= DCACHE_AUTOFS_PENDING;
1168
spin_unlock(&dcache_lock);
1169
- return autofs4_wait(sbi, &dentry->d_name, NFY_MOUNT) == 0;
1170
+ status = autofs4_wait(sbi, dentry, NFY_MOUNT);
1172
+ DPRINTK(("try_to_fill_entry: mount done status=%d\n", status));
1175
+ spin_lock(&dcache_lock);
1176
+ dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
1177
+ spin_unlock(&dcache_lock);
1181
- spin_unlock(&dcache_lock);
1183
/* We don't update the usages for the autofs daemon itself, this
1184
is necessary for recursive autofs mounts */
1185
if (!autofs4_oz_mode(sbi))
1186
autofs4_update_usage(dentry);
1188
+ spin_unlock(&dcache_lock);
1189
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
1190
+ spin_unlock(&dcache_lock);
1196
* Revalidate is called on every cache lookup. Some of those
1197
* cache lookups may actually happen while the dentry is not
1198
* yet completely filled in, and revalidate has to delay such
1201
-static int autofs4_root_revalidate(struct dentry * dentry, int flags)
1202
+static int autofs4_revalidate(struct dentry * dentry, int flags)
1204
struct inode * dir = dentry->d_parent->d_inode;
1205
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
1206
int oz_mode = autofs4_oz_mode(sbi);
1209
+ DPRINTK(("autofs4_revalidate: dentry=%p %.*s flags=%d\n",
1210
+ dentry, dentry->d_name.len, dentry->d_name.name, flags));
1212
/* Pending dentry */
1213
if (autofs4_ispending(dentry)) {
1214
- if (autofs4_oz_mode(sbi))
1217
- return try_to_fill_dentry(dentry, dir->i_sb, sbi);
1219
+ status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
1223
/* Negative dentry.. invalidate if "old" */
1224
- if (dentry->d_inode == NULL)
1225
- return (dentry->d_time - jiffies <= AUTOFS_NEGATIVE_TIMEOUT);
1226
+ if (dentry->d_inode == NULL) {
1227
+ status = (dentry->d_time - jiffies <= AUTOFS_NEGATIVE_TIMEOUT);
1231
/* Check for a non-mountpoint directory with no contents */
1232
spin_lock(&dcache_lock);
1233
if (S_ISDIR(dentry->d_inode->i_mode) &&
1234
!d_mountpoint(dentry) &&
1235
list_empty(&dentry->d_subdirs)) {
1236
- DPRINTK(("autofs_root_revalidate: dentry=%p %.*s, emptydir\n",
1237
+ DPRINTK(("autofs4_revalidate: dentry=%p %.*s, emptydir\n",
1238
dentry, dentry->d_name.len, dentry->d_name.name));
1239
spin_unlock(&dcache_lock);
1243
- return try_to_fill_dentry(dentry, dir->i_sb, sbi);
1245
+ status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
1248
spin_unlock(&dcache_lock);
1250
@@ -181,25 +409,13 @@
1252
autofs4_update_usage(dentry);
1257
-static int autofs4_revalidate(struct dentry *dentry, int flags)
1259
- struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
1261
- if (!autofs4_oz_mode(sbi))
1262
- autofs4_update_usage(dentry);
1268
static void autofs4_dentry_release(struct dentry *de)
1270
struct autofs_info *inf;
1274
DPRINTK(("autofs4_dentry_release: releasing %p\n", de));
1276
inf = autofs4_dentry_ino(de);
1277
@@ -211,13 +427,11 @@
1279
autofs4_free_ino(inf);
1285
/* For dentries of directories in the root dir */
1286
static struct dentry_operations autofs4_root_dentry_operations = {
1287
- d_revalidate: autofs4_root_revalidate,
1288
+ d_revalidate: autofs4_revalidate,
1289
d_release: autofs4_dentry_release,
1292
@@ -227,28 +441,13 @@
1293
d_release: autofs4_dentry_release,
1296
-/* Lookups in non-root dirs never find anything - if it's there, it's
1297
- already in the dcache */
1298
-static struct dentry *autofs4_dir_lookup(struct inode *dir, struct dentry *dentry)
1301
- DPRINTK(("autofs_dir_lookup: ignoring lookup of %.*s/%.*s\n",
1302
- dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
1303
- dentry->d_name.len, dentry->d_name.name));
1306
- dentry->d_fsdata = NULL;
1307
- d_add(dentry, NULL);
1311
/* Lookups in the root directory */
1312
-static struct dentry *autofs4_root_lookup(struct inode *dir, struct dentry *dentry)
1313
+static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry)
1315
struct autofs_sb_info *sbi;
1318
- DPRINTK(("autofs_root_lookup: name = %.*s\n",
1319
+ DPRINTK(("autofs4_root_lookup: name = %.*s\n",
1320
dentry->d_name.len, dentry->d_name.name));
1322
if (dentry->d_name.len > NAME_MAX)
1324
sbi = autofs4_sbi(dir->i_sb);
1326
oz_mode = autofs4_oz_mode(sbi);
1327
- DPRINTK(("autofs_lookup: pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
1329
+ DPRINTK(("autofs4_root_lookup: pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
1330
current->pid, current->pgrp, sbi->catatonic, oz_mode));
1333
@@ -288,8 +488,15 @@
1334
* a signal. If so we can force a restart..
1336
if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
1337
- if (signal_pending(current))
1338
- return ERR_PTR(-ERESTARTNOINTR);
1339
+ /* See if we were interrupted */
1340
+ if (signal_pending(current)) {
1341
+ sigset_t *sigset = ¤t->pending.signal;
1342
+ if (sigismember (sigset, SIGKILL) ||
1343
+ sigismember (sigset, SIGQUIT) ||
1344
+ sigismember (sigset, SIGINT)) {
1345
+ return ERR_PTR(-ERESTARTNOINTR);
1352
struct inode *inode;
1355
- DPRINTK(("autofs_dir_symlink: %s <- %.*s\n", symname,
1356
+ DPRINTK(("autofs4_dir_symlink: %s <- %.*s\n", symname,
1357
dentry->d_name.len, dentry->d_name.name));
1359
if (!autofs4_oz_mode(sbi))
1361
* If a process is blocked on the dentry waiting for the expire to finish,
1362
* it will invalidate the dentry and try to mount with a new one.
1364
- * Also see autofs_dir_rmdir()..
1365
+ * Also see autofs4_dir_rmdir()..
1367
static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
1375
static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1377
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
1379
if ( !autofs4_oz_mode(sbi) )
1382
- DPRINTK(("autofs_dir_mkdir: dentry %p, creating %.*s\n",
1383
+ DPRINTK(("autofs4_dir_mkdir: dentry %p, creating %.*s\n",
1384
dentry, dentry->d_name.len, dentry->d_name.name));
1386
ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
1387
@@ -448,6 +653,19 @@
1392
+ * Identify autofs_dentries - this is so we can tell if there's
1393
+ * an extra dentry refcount or not. We only hold a refcount on the
1394
+ * dentry if its non-negative (ie, d_inode != NULL)
1396
+int is_autofs4_dentry(struct dentry *dentry)
1398
+ return dentry && dentry->d_inode &&
1399
+ (dentry->d_op == &autofs4_root_dentry_operations ||
1400
+ dentry->d_op == &autofs4_dentry_operations) &&
1401
+ dentry->d_fsdata != NULL;
1404
/* Get/set timeout ioctl() operation */
1405
static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
1407
@@ -473,16 +691,65 @@
1408
return put_user(sbi->version, p);
1411
-/* Identify autofs_dentries - this is so we can tell if there's
1412
- an extra dentry refcount or not. We only hold a refcount on the
1413
- dentry if its non-negative (ie, d_inode != NULL)
1415
-int is_autofs4_dentry(struct dentry *dentry)
1416
+/* Return protocol sub version */
1417
+static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int *p)
1419
- return dentry && dentry->d_inode &&
1420
- (dentry->d_op == &autofs4_root_dentry_operations ||
1421
- dentry->d_op == &autofs4_dentry_operations) &&
1422
- dentry->d_fsdata != NULL;
1423
+ return put_user(sbi->sub_version, p);
1427
+ * Tells the daemon whether we need to reghost or not. Also, clears
1428
+ * the reghost_needed flag.
1430
+static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int *p)
1434
+ DPRINTK(("autofs_ask_reghost: returning %d\n", sbi->needs_reghost));
1436
+ status = put_user(sbi->needs_reghost, p);
1440
+ sbi->needs_reghost = 0;
1445
+ * Enable / Disable reghosting ioctl() operation
1447
+static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int *p)
1452
+ status = get_user(val, p);
1454
+ DPRINTK(("autofs4_toggle_reghost: reghost = %d\n", val));
1459
+ /* turn on/off reghosting, with the val */
1460
+ sbi->reghost_enabled = val;
1465
+ * Tells the daemon whether we can umaont the autofs mount.
1467
+static inline int autofs4_ask_umount(struct vfsmount *mnt, int *p)
1471
+ if (may_umount(mnt) == 0)
1474
+ DPRINTK(("autofs_ask_umount: returning %d\n", status));
1476
+ status = put_user(status, p);
1484
struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
1486
- DPRINTK(("autofs_ioctl: cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",
1487
+ DPRINTK(("autofs4_ioctl: cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",
1488
cmd,arg,sbi,current->pgrp));
1490
if ( _IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
1491
@@ -514,9 +781,19 @@
1493
case AUTOFS_IOC_PROTOVER: /* Get protocol version */
1494
return autofs4_get_protover(sbi, (int *)arg);
1495
+ case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
1496
+ return autofs4_get_protosubver(sbi, (int *) arg);
1497
case AUTOFS_IOC_SETTIMEOUT:
1498
return autofs4_get_set_timeout(sbi,(unsigned long *)arg);
1500
+ case AUTOFS_IOC_TOGGLEREGHOST:
1501
+ return autofs4_toggle_reghost(sbi, (int *) arg);
1502
+ case AUTOFS_IOC_ASKREGHOST:
1503
+ return autofs4_ask_reghost(sbi, (int *) arg);
1505
+ case AUTOFS_IOC_ASKUMOUNT:
1506
+ return autofs4_ask_umount(filp->f_vfsmnt, (int *) arg);
1508
/* return a single thing to expire */
1509
case AUTOFS_IOC_EXPIRE:
1510
return autofs4_expire_run(inode->i_sb,filp->f_vfsmnt,sbi,
1511
diff -Nur linux-2.4.22/fs/autofs4/waitq.c autofs4-2.4/fs/autofs4/waitq.c
1512
--- linux-2.4.22/fs/autofs4/waitq.c 2001-02-10 03:29:44.000000000 +0800
1513
+++ autofs4-2.4/fs/autofs4/waitq.c 2005-04-04 22:27:32.000000000 +0800
1515
* linux/fs/autofs/waitq.c
1517
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
1518
+ * Copyright 2001-2003 Ian Kent <raven@themaw.net>
1520
* This file is part of the Linux kernel and is made available under
1521
* the terms of the GNU General Public License, version 2, or at your
1524
struct autofs_wait_queue *wq, *nwq;
1526
- DPRINTK(("autofs: entering catatonic mode\n"));
1527
+ DPRINTK(("autofs4: entering catatonic mode\n"));
1534
wq->status = -ENOENT; /* Magic is gone - report failure */
1537
- wake_up(&wq->queue);
1542
+ wake_up_interruptible(&wq->queue);
1547
union autofs_packet_union pkt;
1550
- DPRINTK(("autofs_notify: wait id = 0x%08lx, name = %.*s, type=%d\n",
1551
- wq->wait_queue_token, wq->len, wq->name, type));
1552
+ DPRINTK(("autofs4_notify: wait id = 0x%08lx, name = %.*s, type=%d\n",
1553
+ (unsigned long) wq->wait_queue_token, wq->len, wq->name, type));
1555
memset(&pkt,0,sizeof pkt); /* For security reasons */
1558
memcpy(ep->name, wq->name, wq->len);
1559
ep->name[wq->len] = '\0';
1561
- printk("autofs_notify_daemon: bad type %d!\n", type);
1562
+ printk("autofs4_notify_daemon: bad type %d!\n", type);
1566
@@ -124,62 +127,110 @@
1567
autofs4_catatonic_mode(sbi);
1570
-int autofs4_wait(struct autofs_sb_info *sbi, struct qstr *name,
1571
+static int autofs4_getpath(struct autofs_sb_info *sbi,
1572
+ struct dentry *dentry, char **name)
1574
+ struct dentry *root = sbi->sb->s_root;
1575
+ struct dentry *tmp;
1576
+ char *buf = *name;
1580
+ spin_lock(&dcache_lock);
1581
+ for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
1582
+ len += tmp->d_name.len + 1;
1584
+ if (--len > NAME_MAX) {
1585
+ spin_unlock(&dcache_lock);
1589
+ *(buf + len) = '\0';
1590
+ p = buf + len - dentry->d_name.len;
1591
+ strncpy(p, dentry->d_name.name, dentry->d_name.len);
1593
+ for (tmp = dentry->d_parent; tmp != root ; tmp = tmp->d_parent) {
1595
+ p -= tmp->d_name.len;
1596
+ strncpy(p, tmp->d_name.name, tmp->d_name.len);
1598
+ spin_unlock(&dcache_lock);
1603
+int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
1604
enum autofs_notify notify)
1606
struct autofs_wait_queue *wq;
1611
/* In catatonic mode, we don't wait for nobody */
1612
- if ( sbi->catatonic )
1613
+ if (sbi->catatonic)
1616
- /* We shouldn't be able to get here, but just in case */
1617
- if ( name->len > NAME_MAX )
1619
+ name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
1623
+ len = autofs4_getpath(sbi, dentry, &name);
1629
+ if (down_interruptible(&sbi->wq_sem)) {
1634
for ( wq = sbi->queues ; wq ; wq = wq->next ) {
1635
- if ( wq->hash == name->hash &&
1636
- wq->len == name->len &&
1637
- wq->name && !memcmp(wq->name,name->name,name->len) )
1638
+ if ( wq->hash == dentry->d_name.hash &&
1640
+ wq->name && !memcmp(wq->name, name, len) )
1645
/* Create a new wait queue */
1646
- wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
1650
- wq->name = kmalloc(name->len,GFP_KERNEL);
1651
- if ( !wq->name ) {
1653
+ wq = kmalloc(sizeof(struct autofs_wait_queue), GFP_KERNEL);
1660
wq->wait_queue_token = autofs4_next_wait_queue;
1661
if (++autofs4_next_wait_queue == 0)
1662
autofs4_next_wait_queue = 1;
1663
- init_waitqueue_head(&wq->queue);
1664
- wq->hash = name->hash;
1665
- wq->len = name->len;
1666
- wq->status = -EINTR; /* Status return if interrupted */
1667
- memcpy(wq->name, name->name, name->len);
1668
wq->next = sbi->queues;
1670
+ init_waitqueue_head(&wq->queue);
1671
+ wq->hash = dentry->d_name.hash;
1674
+ wq->status = -EINTR; /* Status return if interrupted */
1675
+ atomic_set(&wq->wait_ctr, 2);
1676
+ atomic_set(&wq->notified, 1);
1679
+ atomic_inc(&wq->wait_ctr);
1682
+ DPRINTK(("autofs4_wait: existing wait id = 0x%08lx, name = %.*s, nfy=%d\n",
1683
+ (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify));
1686
+ if (notify != NFY_NONE && atomic_dec_and_test(&wq->notified)) {
1687
+ int type = (notify == NFY_MOUNT ?
1688
+ autofs_ptype_missing : autofs_ptype_expire_multi);
1690
+ DPRINTK(("autofs4_wait: new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
1691
+ (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify));
1693
- DPRINTK(("autofs_wait: new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
1694
- wq->wait_queue_token, wq->len, wq->name, notify));
1695
/* autofs4_notify_daemon() may block */
1697
- if (notify != NFY_NONE) {
1698
- autofs4_notify_daemon(sbi,wq,
1699
- notify == NFY_MOUNT ? autofs_ptype_missing :
1700
- autofs_ptype_expire_multi);
1704
- DPRINTK(("autofs_wait: existing wait id = 0x%08lx, name = %.*s, nfy=%d\n",
1705
- wq->wait_queue_token, wq->len, wq->name, notify));
1706
+ autofs4_notify_daemon(sbi, wq, type);
1709
/* wq->name is NULL if and only if the lock is already released */
1711
recalc_sigpending(current);
1712
spin_unlock_irqrestore(¤t->sigmask_lock, irqflags);
1714
- interruptible_sleep_on(&wq->queue);
1715
+ wait_event_interruptible(wq->queue, wq->name == NULL);
1717
spin_lock_irqsave(¤t->sigmask_lock, irqflags);
1718
current->blocked = oldset;
1721
status = wq->status;
1723
- if (--wq->wait_ctr == 0) /* Are we the last process to need status? */
1724
+ /* Are we the last process to need status? */
1725
+ if (atomic_dec_and_test(&wq->wait_ctr))
1729
@@ -227,23 +279,29 @@
1731
struct autofs_wait_queue *wq, **wql;
1733
+ down(&sbi->wq_sem);
1734
for ( wql = &sbi->queues ; (wq = *wql) ; wql = &wq->next ) {
1735
if ( wq->wait_queue_token == wait_queue_token )
1745
*wql = wq->next; /* Unlink from chain */
1748
wq->name = NULL; /* Do not wait on this queue */
1750
wq->status = status;
1752
- if (--wq->wait_ctr == 0) /* Is anyone still waiting for this guy? */
1753
+ /* Is anyone still waiting for this guy? */
1754
+ if (atomic_dec_and_test(&wq->wait_ctr))
1757
- wake_up(&wq->queue);
1758
+ wake_up_interruptible(&wq->queue);
1762
diff -Nur linux-2.4.22/include/linux/auto_fs.h autofs4-2.4/include/linux/auto_fs.h
1763
--- linux-2.4.22/include/linux/auto_fs.h 2003-06-13 22:51:38.000000000 +0800
1764
+++ autofs4-2.4/include/linux/auto_fs.h 2005-04-04 22:27:31.000000000 +0800
1766
* If so, 32-bit user-space code should be backwards compatible.
1769
-#if !defined(__alpha__) && !defined(__ia64__)
1770
+#if defined(__sparc__) || defined(__mips__) || defined(__s390__) || defined(__powerpc__) || defined(__x86_64__)
1771
typedef unsigned int autofs_wqt_t;
1773
typedef unsigned long autofs_wqt_t;
1774
diff -Nur linux-2.4.22/include/linux/auto_fs4.h autofs4-2.4/include/linux/auto_fs4.h
1775
--- linux-2.4.22/include/linux/auto_fs4.h 2001-11-23 03:46:40.000000000 +0800
1776
+++ autofs4-2.4/include/linux/auto_fs4.h 2005-04-04 22:27:31.000000000 +0800
1778
#define AUTOFS_MIN_PROTO_VERSION 3
1779
#define AUTOFS_MAX_PROTO_VERSION 4
1781
+#define AUTOFS_PROTO_SUBVERSION 6
1783
+/* Mask for expire behaviour */
1784
+#define AUTOFS_EXP_IMMEDIATE 1
1785
+#define AUTOFS_EXP_LEAVES 2
1787
/* New message type */
1788
#define autofs_ptype_expire_multi 2 /* Expire entry (umount request) */
1791
struct autofs_packet_expire_multi expire_multi;
1794
-#define AUTOFS_IOC_EXPIRE_MULTI _IOW(0x93,0x66,int)
1796
+#define AUTOFS_IOC_EXPIRE_MULTI _IOW(0x93,0x66,int)
1797
+#define AUTOFS_IOC_PROTOSUBVER _IOR(0x93,0x67,int)
1798
+#define AUTOFS_IOC_ASKREGHOST _IOR(0x93,0x68,int)
1799
+#define AUTOFS_IOC_TOGGLEREGHOST _IOR(0x93,0x69,int)
1800
+#define AUTOFS_IOC_ASKUMOUNT _IOR(0x93,0x70,int)
1802
#endif /* _LINUX_AUTO_FS4_H */