1
Index: linux-2.6.24/fs/autofs4/waitq.c
2
===================================================================
3
--- linux-2.6.24.orig/fs/autofs4/waitq.c
4
+++ linux-2.6.24/fs/autofs4/waitq.c
5
@@ -28,6 +28,12 @@ void autofs4_catatonic_mode(struct autof
7
struct autofs_wait_queue *wq, *nwq;
9
+ mutex_lock(&sbi->wq_mutex);
10
+ if (sbi->catatonic) {
11
+ mutex_unlock(&sbi->wq_mutex);
15
DPRINTK("entering catatonic mode");
18
@@ -36,13 +42,18 @@ void autofs4_catatonic_mode(struct autof
21
wq->status = -ENOENT; /* Magic is gone - report failure */
24
+ if (wq->name.name) {
25
+ kfree(wq->name.name);
26
+ wq->name.name = NULL;
29
wake_up_interruptible(&wq->queue);
32
fput(sbi->pipe); /* Close the pipe */
35
+ mutex_unlock(&sbi->wq_mutex);
38
static int autofs4_write(struct file *file, const void *addr, int bytes)
39
@@ -89,10 +100,11 @@ static void autofs4_notify_daemon(struct
40
union autofs_packet_union v4_pkt;
41
union autofs_v5_packet_union v5_pkt;
43
+ struct file *pipe = NULL;
46
DPRINTK("wait id = 0x%08lx, name = %.*s, type=%d",
47
- wq->wait_queue_token, wq->len, wq->name, type);
48
+ wq->wait_queue_token, wq->name.len, wq->name.name, type);
50
memset(&pkt,0,sizeof pkt); /* For security reasons */
52
@@ -107,9 +119,9 @@ static void autofs4_notify_daemon(struct
55
mp->wait_queue_token = wq->wait_queue_token;
57
- memcpy(mp->name, wq->name, wq->len);
58
- mp->name[wq->len] = '\0';
59
+ mp->len = wq->name.len;
60
+ memcpy(mp->name, wq->name.name, wq->name.len);
61
+ mp->name[wq->name.len] = '\0';
64
case autofs_ptype_expire_multi:
65
@@ -119,9 +131,9 @@ static void autofs4_notify_daemon(struct
68
ep->wait_queue_token = wq->wait_queue_token;
70
- memcpy(ep->name, wq->name, wq->len);
71
- ep->name[wq->len] = '\0';
72
+ ep->len = wq->name.len;
73
+ memcpy(ep->name, wq->name.name, wq->name.len);
74
+ ep->name[wq->name.len] = '\0';
78
@@ -138,9 +150,9 @@ static void autofs4_notify_daemon(struct
79
pktsz = sizeof(*packet);
81
packet->wait_queue_token = wq->wait_queue_token;
82
- packet->len = wq->len;
83
- memcpy(packet->name, wq->name, wq->len);
84
- packet->name[wq->len] = '\0';
85
+ packet->len = wq->name.len;
86
+ memcpy(packet->name, wq->name.name, wq->name.len);
87
+ packet->name[wq->name.len] = '\0';
88
packet->dev = wq->dev;
89
packet->ino = wq->ino;
90
packet->uid = wq->uid;
91
@@ -154,8 +166,19 @@ static void autofs4_notify_daemon(struct
95
- if (autofs4_write(sbi->pipe, &pkt, pktsz))
96
- autofs4_catatonic_mode(sbi);
97
+ /* Check if we have become catatonic */
98
+ mutex_lock(&sbi->wq_mutex);
99
+ if (!sbi->catatonic) {
103
+ mutex_unlock(&sbi->wq_mutex);
106
+ if (autofs4_write(pipe, &pkt, pktsz))
107
+ autofs4_catatonic_mode(sbi);
112
static int autofs4_getpath(struct autofs_sb_info *sbi,
113
@@ -171,7 +194,7 @@ static int autofs4_getpath(struct autofs
114
for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
115
len += tmp->d_name.len + 1;
117
- if (--len > NAME_MAX) {
118
+ if (!len || --len > NAME_MAX) {
119
spin_unlock(&dcache_lock);
122
@@ -191,58 +214,55 @@ static int autofs4_getpath(struct autofs
125
static struct autofs_wait_queue *
126
-autofs4_find_wait(struct autofs_sb_info *sbi,
127
- char *name, unsigned int hash, unsigned int len)
128
+autofs4_find_wait(struct autofs_sb_info *sbi, struct qstr *qstr)
130
struct autofs_wait_queue *wq;
132
for (wq = sbi->queues; wq; wq = wq->next) {
133
- if (wq->hash == hash &&
135
- wq->name && !memcmp(wq->name, name, len))
136
+ if (wq->name.hash == qstr->hash &&
137
+ wq->name.len == qstr->len &&
139
+ !memcmp(wq->name.name, qstr->name, qstr->len))
145
-int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
146
- enum autofs_notify notify)
148
+ * Check if we have a valid request.
150
+ * 1 if the request should continue.
151
+ * In this case we can return an autofs_wait_queue entry if one is
152
+ * found or NULL to idicate a new wait needs to be created.
153
+ * 0 or a negative errno if the request shouldn't continue.
155
+static int validate_request(struct autofs_wait_queue **wait,
156
+ struct autofs_sb_info *sbi,
158
+ struct dentry*dentry, enum autofs_notify notify)
160
- struct autofs_info *ino;
161
struct autofs_wait_queue *wq;
163
- unsigned int len = 0;
164
- unsigned int hash = 0;
167
- /* In catatonic mode, we don't wait for nobody */
168
- if (sbi->catatonic)
171
- name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
174
+ struct autofs_info *ino;
176
- /* If this is a direct mount request create a dummy name */
177
- if (IS_ROOT(dentry) && (sbi->type & AUTOFS_TYPE_DIRECT))
178
- len = sprintf(name, "%p", dentry);
180
- len = autofs4_getpath(sbi, dentry, &name);
185
+ /* Wait in progress, continue; */
186
+ wq = autofs4_find_wait(sbi, qstr);
191
- hash = full_name_hash(name, len);
193
- if (mutex_lock_interruptible(&sbi->wq_mutex)) {
199
- wq = autofs4_find_wait(sbi, name, hash, len);
200
+ /* If we don't yet have any info this is a new request */
201
ino = autofs4_dentry_ino(dentry);
202
- if (!wq && ino && notify == NFY_NONE) {
207
+ * If we've been asked to wait on an existing expire (NFY_NONE)
208
+ * but there is no wait in the queue ...
210
+ if (notify == NFY_NONE) {
212
* Either we've betean the pending expire to post it's
213
* wait or it finished while we waited on the mutex.
214
@@ -253,13 +273,14 @@ int autofs4_wait(struct autofs_sb_info *
215
while (ino->flags & AUTOFS_INF_EXPIRING) {
216
mutex_unlock(&sbi->wq_mutex);
217
schedule_timeout_interruptible(HZ/10);
218
- if (mutex_lock_interruptible(&sbi->wq_mutex)) {
220
+ if (mutex_lock_interruptible(&sbi->wq_mutex))
223
+ wq = autofs4_find_wait(sbi, qstr);
228
- wq = autofs4_find_wait(sbi, name, hash, len);
234
@@ -267,18 +288,96 @@ int autofs4_wait(struct autofs_sb_info *
235
* cases where we wait on NFY_NONE neither depend on the
236
* return status of the wait.
243
+ * If we've been asked to trigger a mount and the request
244
+ * completed while we waited on the mutex ...
246
+ if (notify == NFY_MOUNT) {
248
+ * If the dentry isn't hashed just go ahead and try the
249
+ * mount again with a new wait (not much else we can do).
251
+ if (!d_unhashed(dentry)) {
253
+ * But if the dentry is hashed, that means that we
254
+ * got here through the revalidate path. Thus, we
255
+ * need to check if the dentry has been mounted
256
+ * while we waited on the wq_mutex. If it has,
257
+ * simply return success.
259
+ if (d_mountpoint(dentry))
267
+int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
268
+ enum autofs_notify notify)
270
+ struct autofs_wait_queue *wq;
273
+ int status, ret, type;
275
+ /* In catatonic mode, we don't wait for nobody */
276
+ if (sbi->catatonic)
279
+ if (!dentry->d_inode) {
281
+ * A wait for a negative dentry is invalid for certain
282
+ * cases. A direct or offset mount "always" has its mount
283
+ * point directory created and so the request dentry must
284
+ * be positive or the map key doesn't exist. The situation
285
+ * is very similar for indirect mounts except only dentrys
286
+ * in the root of the autofs file system may be negative.
288
+ if (sbi->type & AUTOFS_TYPE_TRIGGER)
290
+ else if (!IS_ROOT(dentry->d_parent))
294
+ name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
298
+ /* If this is a direct mount request create a dummy name */
299
+ if (IS_ROOT(dentry) && sbi->type & AUTOFS_TYPE_TRIGGER)
300
+ qstr.len = sprintf(name, "%p", dentry);
302
+ qstr.len = autofs4_getpath(sbi, dentry, &name);
305
- mutex_unlock(&sbi->wq_mutex);
311
+ qstr.hash = full_name_hash(name, qstr.len);
313
+ if (mutex_lock_interruptible(&sbi->wq_mutex)) {
318
+ ret = validate_request(&wq, sbi, &qstr, dentry, notify);
321
+ mutex_unlock(&sbi->wq_mutex);
327
/* Create a new wait queue */
328
wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
332
mutex_unlock(&sbi->wq_mutex);
335
@@ -289,9 +388,7 @@ int autofs4_wait(struct autofs_sb_info *
336
wq->next = sbi->queues;
338
init_waitqueue_head(&wq->queue);
342
+ memcpy(&wq->name, &qstr, sizeof(struct qstr));
343
wq->dev = autofs4_get_dev(sbi);
344
wq->ino = autofs4_get_ino(sbi);
345
wq->uid = current->uid;
346
@@ -299,7 +396,7 @@ int autofs4_wait(struct autofs_sb_info *
347
wq->pid = current->pid;
348
wq->tgid = current->tgid;
349
wq->status = -EINTR; /* Status return if interrupted */
350
- atomic_set(&wq->wait_ctr, 2);
352
mutex_unlock(&sbi->wq_mutex);
354
if (sbi->version < 5) {
355
@@ -309,38 +406,35 @@ int autofs4_wait(struct autofs_sb_info *
356
type = autofs_ptype_expire_multi;
358
if (notify == NFY_MOUNT)
359
- type = (sbi->type & AUTOFS_TYPE_DIRECT) ?
360
+ type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
361
autofs_ptype_missing_direct :
362
autofs_ptype_missing_indirect;
364
- type = (sbi->type & AUTOFS_TYPE_DIRECT) ?
365
+ type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
366
autofs_ptype_expire_direct :
367
autofs_ptype_expire_indirect;
370
DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
371
- (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
372
+ (unsigned long) wq->wait_queue_token, wq->name.len,
373
+ wq->name.name, notify);
375
/* autofs4_notify_daemon() may block */
376
autofs4_notify_daemon(sbi, wq, type);
378
- atomic_inc(&wq->wait_ctr);
380
mutex_unlock(&sbi->wq_mutex);
383
DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
384
- (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
385
+ (unsigned long) wq->wait_queue_token, wq->name.len,
386
+ wq->name.name, notify);
389
- /* wq->name is NULL if and only if the lock is already released */
391
- if (sbi->catatonic) {
392
- /* We might have slept, so check again for catatonic mode */
393
- wq->status = -ENOENT;
400
+ * wq->name.name is NULL iff the lock is already released
401
+ * or the mount has been made catatonic.
403
+ if (wq->name.name) {
404
/* Block all but "shutdown" signals while waiting */
406
unsigned long irqflags;
407
@@ -351,7 +445,7 @@ int autofs4_wait(struct autofs_sb_info *
409
spin_unlock_irqrestore(¤t->sighand->siglock, irqflags);
411
- wait_event_interruptible(wq->queue, wq->name == NULL);
412
+ wait_event_interruptible(wq->queue, wq->name.name == NULL);
414
spin_lock_irqsave(¤t->sighand->siglock, irqflags);
415
current->blocked = oldset;
416
@@ -364,8 +458,10 @@ int autofs4_wait(struct autofs_sb_info *
419
/* Are we the last process to need status? */
420
- if (atomic_dec_and_test(&wq->wait_ctr))
421
+ mutex_lock(&sbi->wq_mutex);
422
+ if (!--wq->wait_ctr)
424
+ mutex_unlock(&sbi->wq_mutex);
428
@@ -387,16 +483,13 @@ int autofs4_wait_release(struct autofs_s
431
*wql = wq->next; /* Unlink from chain */
432
- mutex_unlock(&sbi->wq_mutex);
434
- wq->name = NULL; /* Do not wait on this queue */
436
+ kfree(wq->name.name);
437
+ wq->name.name = NULL; /* Do not wait on this queue */
440
- if (atomic_dec_and_test(&wq->wait_ctr)) /* Is anyone still waiting for this guy? */
441
+ wake_up_interruptible(&wq->queue);
442
+ if (!--wq->wait_ctr)
445
- wake_up_interruptible(&wq->queue);
446
+ mutex_unlock(&sbi->wq_mutex);
450
Index: linux-2.6.24/fs/autofs4/expire.c
451
===================================================================
452
--- linux-2.6.24.orig/fs/autofs4/expire.c
453
+++ linux-2.6.24/fs/autofs4/expire.c
454
@@ -56,12 +56,23 @@ static int autofs4_mount_busy(struct vfs
458
- if (!autofs4_follow_mount(&mnt, &dentry))
459
+ if (!follow_down(&mnt, &dentry))
462
- /* This is an autofs submount, we can't expire it */
463
- if (is_autofs4_dentry(dentry))
465
+ if (is_autofs4_dentry(dentry)) {
466
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
468
+ /* This is an autofs submount, we can't expire it */
469
+ if (sbi->type == AUTOFS_TYPE_INDIRECT)
473
+ * Otherwise it's an offset mount and we need to check
474
+ * if we can umount its mount, if there is one.
476
+ if (!d_mountpoint(dentry))
480
/* Update the expiry counter if fs is busy */
481
if (!may_umount_tree(mnt)) {
482
@@ -73,8 +84,8 @@ static int autofs4_mount_busy(struct vfs
485
DPRINTK("returning = %d", status);
492
@@ -259,13 +270,15 @@ static struct dentry *autofs4_expire_dir
494
timeout = sbi->exp_timeout;
496
- /* Lock the tree as we must expire as a whole */
497
spin_lock(&sbi->fs_lock);
498
if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
499
struct autofs_info *ino = autofs4_dentry_ino(root);
501
- /* Set this flag early to catch sys_chdir and the like */
502
+ if (d_mountpoint(root)) {
503
+ ino->flags |= AUTOFS_INF_MOUNTPOINT;
506
ino->flags |= AUTOFS_INF_EXPIRING;
507
+ init_completion(&ino->expire_complete);
508
spin_unlock(&sbi->fs_lock);
511
@@ -292,6 +305,8 @@ static struct dentry *autofs4_expire_ind
512
struct list_head *next;
513
int do_now = how & AUTOFS_EXP_IMMEDIATE;
514
int exp_leaves = how & AUTOFS_EXP_LEAVES;
515
+ struct autofs_info *ino;
516
+ unsigned int ino_count;
520
@@ -316,6 +331,9 @@ static struct dentry *autofs4_expire_ind
521
dentry = dget(dentry);
522
spin_unlock(&dcache_lock);
524
+ spin_lock(&sbi->fs_lock);
525
+ ino = autofs4_dentry_ino(dentry);
528
* Case 1: (i) indirect mount or top level pseudo direct mount
530
@@ -326,6 +344,11 @@ static struct dentry *autofs4_expire_ind
531
DPRINTK("checking mountpoint %p %.*s",
532
dentry, (int)dentry->d_name.len, dentry->d_name.name);
534
+ /* Path walk currently on this dentry? */
535
+ ino_count = atomic_read(&ino->count) + 2;
536
+ if (atomic_read(&dentry->d_count) > ino_count)
539
/* Can we umount this guy */
540
if (autofs4_mount_busy(mnt, dentry))
542
@@ -333,7 +356,7 @@ static struct dentry *autofs4_expire_ind
543
/* Can we expire this guy */
544
if (autofs4_can_expire(dentry, timeout, do_now)) {
551
@@ -343,46 +366,80 @@ static struct dentry *autofs4_expire_ind
553
/* Case 2: tree mount, expire iff entire tree is not busy */
555
- /* Lock the tree as we must expire as a whole */
556
- spin_lock(&sbi->fs_lock);
557
- if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
558
- struct autofs_info *inf = autofs4_dentry_ino(dentry);
559
+ /* Path walk currently on this dentry? */
560
+ ino_count = atomic_read(&ino->count) + 1;
561
+ if (atomic_read(&dentry->d_count) > ino_count)
564
- /* Set this flag early to catch sys_chdir and the like */
565
- inf->flags |= AUTOFS_INF_EXPIRING;
566
- spin_unlock(&sbi->fs_lock);
567
+ if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
572
- spin_unlock(&sbi->fs_lock);
574
* Case 3: pseudo direct mount, expire individual leaves
578
+ /* Path walk currently on this dentry? */
579
+ ino_count = atomic_read(&ino->count) + 1;
580
+ if (atomic_read(&dentry->d_count) > ino_count)
583
expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
591
+ spin_unlock(&sbi->fs_lock);
593
spin_lock(&dcache_lock);
596
+ spin_unlock(&dcache_lock);
600
- DPRINTK("returning %p %.*s",
601
- expired, (int)expired->d_name.len, expired->d_name.name);
602
- spin_lock(&dcache_lock);
603
- list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
604
- spin_unlock(&dcache_lock);
608
+ DPRINTK("returning %p %.*s",
609
+ expired, (int)expired->d_name.len, expired->d_name.name);
610
+ ino = autofs4_dentry_ino(expired);
611
+ ino->flags |= AUTOFS_INF_EXPIRING;
612
+ init_completion(&ino->expire_complete);
613
+ spin_unlock(&sbi->fs_lock);
614
+ spin_lock(&dcache_lock);
615
+ list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
616
spin_unlock(&dcache_lock);
621
+int autofs4_expire_wait(struct dentry *dentry)
623
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
624
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
627
+ /* Block on any pending expire */
628
+ spin_lock(&sbi->fs_lock);
629
+ if (ino->flags & AUTOFS_INF_EXPIRING) {
630
+ spin_unlock(&sbi->fs_lock);
632
+ DPRINTK("waiting for expire %p name=%.*s",
633
+ dentry, dentry->d_name.len, dentry->d_name.name);
635
+ status = autofs4_wait(sbi, dentry, NFY_NONE);
636
+ wait_for_completion(&ino->expire_complete);
638
+ DPRINTK("expire done status=%d", status);
640
+ if (d_unhashed(dentry))
645
+ spin_unlock(&sbi->fs_lock);
650
/* Perform an expiry operation */
651
@@ -392,7 +449,9 @@ int autofs4_expire_run(struct super_bloc
652
struct autofs_packet_expire __user *pkt_p)
654
struct autofs_packet_expire pkt;
655
+ struct autofs_info *ino;
656
struct dentry *dentry;
659
memset(&pkt,0,sizeof pkt);
661
@@ -408,9 +467,15 @@ int autofs4_expire_run(struct super_bloc
664
if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
669
+ spin_lock(&sbi->fs_lock);
670
+ ino = autofs4_dentry_ino(dentry);
671
+ ino->flags &= ~AUTOFS_INF_EXPIRING;
672
+ complete_all(&ino->expire_complete);
673
+ spin_unlock(&sbi->fs_lock);
678
/* Call repeatedly until it returns -EAGAIN, meaning there's nothing
679
@@ -425,7 +490,7 @@ int autofs4_expire_multi(struct super_bl
680
if (arg && get_user(do_now, arg))
683
- if (sbi->type & AUTOFS_TYPE_DIRECT)
684
+ if (sbi->type & AUTOFS_TYPE_TRIGGER)
685
dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
687
dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
688
@@ -435,9 +500,16 @@ int autofs4_expire_multi(struct super_bl
690
/* This is synchronous because it makes the daemon a
692
- ino->flags |= AUTOFS_INF_EXPIRING;
693
ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
695
+ spin_lock(&sbi->fs_lock);
696
+ if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
697
+ sb->s_root->d_mounted++;
698
+ ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
700
ino->flags &= ~AUTOFS_INF_EXPIRING;
701
+ complete_all(&ino->expire_complete);
702
+ spin_unlock(&sbi->fs_lock);
706
Index: linux-2.6.24/fs/autofs4/root.c
707
===================================================================
708
--- linux-2.6.24.orig/fs/autofs4/root.c
709
+++ linux-2.6.24/fs/autofs4/root.c
710
@@ -25,25 +25,25 @@ static int autofs4_dir_rmdir(struct inod
711
static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
712
static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
713
static int autofs4_dir_open(struct inode *inode, struct file *file);
714
-static int autofs4_dir_close(struct inode *inode, struct file *file);
715
-static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir);
716
-static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
717
static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
718
static void *autofs4_follow_link(struct dentry *, struct nameidata *);
720
+#define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
721
+#define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
723
const struct file_operations autofs4_root_operations = {
724
.open = dcache_dir_open,
725
.release = dcache_dir_close,
726
.read = generic_read_dir,
727
- .readdir = autofs4_root_readdir,
728
+ .readdir = dcache_readdir,
729
.ioctl = autofs4_root_ioctl,
732
const struct file_operations autofs4_dir_operations = {
733
.open = autofs4_dir_open,
734
- .release = autofs4_dir_close,
735
+ .release = dcache_dir_close,
736
.read = generic_read_dir,
737
- .readdir = autofs4_dir_readdir,
738
+ .readdir = dcache_readdir,
741
const struct inode_operations autofs4_indirect_root_inode_operations = {
742
@@ -70,42 +70,10 @@ const struct inode_operations autofs4_di
743
.rmdir = autofs4_dir_rmdir,
746
-static int autofs4_root_readdir(struct file *file, void *dirent,
749
- struct autofs_sb_info *sbi = autofs4_sbi(file->f_path.dentry->d_sb);
750
- int oz_mode = autofs4_oz_mode(sbi);
752
- DPRINTK("called, filp->f_pos = %lld", file->f_pos);
755
- * Don't set reghost flag if:
756
- * 1) f_pos is larger than zero -- we've already been here.
757
- * 2) we haven't even enabled reghosting in the 1st place.
758
- * 3) this is the daemon doing a readdir
760
- if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
761
- sbi->needs_reghost = 1;
763
- DPRINTK("needs_reghost = %d", sbi->needs_reghost);
765
- return dcache_readdir(file, dirent, filldir);
768
static int autofs4_dir_open(struct inode *inode, struct file *file)
770
struct dentry *dentry = file->f_path.dentry;
771
- struct vfsmount *mnt = file->f_path.mnt;
772
struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
773
- struct dentry *cursor;
776
- status = dcache_dir_open(inode, file);
780
- cursor = file->private_data;
781
- cursor->d_fsdata = NULL;
783
DPRINTK("file=%p dentry=%p %.*s",
784
file, dentry, dentry->d_name.len, dentry->d_name.name);
785
@@ -113,157 +81,31 @@ static int autofs4_dir_open(struct inode
786
if (autofs4_oz_mode(sbi))
789
- if (autofs4_ispending(dentry)) {
790
- DPRINTK("dentry busy");
791
- dcache_dir_close(inode, file);
797
- if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) {
798
- struct nameidata nd;
801
- /* In case there are stale directory dentrys from a failed mount */
802
- spin_lock(&dcache_lock);
803
- empty = list_empty(&dentry->d_subdirs);
805
+ * An empty directory in an autofs file system is always a
806
+ * mount point. The daemon must have failed to mount this
807
+ * during lookup so it doesn't exist. This can happen, for
808
+ * example, if user space returns an incorrect status for a
809
+ * mount request. Otherwise we're doing a readdir on the
810
+ * autofs file system so just let the libfs routines handle
813
+ spin_lock(&dcache_lock);
814
+ if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
815
spin_unlock(&dcache_lock);
818
- d_invalidate(dentry);
820
- nd.flags = LOOKUP_DIRECTORY;
821
- ret = (dentry->d_op->d_revalidate)(dentry, &nd);
826
- dcache_dir_close(inode, file);
831
- if (d_mountpoint(dentry)) {
832
- struct file *fp = NULL;
833
- struct vfsmount *fp_mnt = mntget(mnt);
834
- struct dentry *fp_dentry = dget(dentry);
836
- if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) {
839
- dcache_dir_close(inode, file);
843
- fp = dentry_open(fp_dentry, fp_mnt, file->f_flags);
844
- status = PTR_ERR(fp);
846
- dcache_dir_close(inode, file);
849
- cursor->d_fsdata = fp;
856
-static int autofs4_dir_close(struct inode *inode, struct file *file)
858
- struct dentry *dentry = file->f_path.dentry;
859
- struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
860
- struct dentry *cursor = file->private_data;
863
- DPRINTK("file=%p dentry=%p %.*s",
864
- file, dentry, dentry->d_name.len, dentry->d_name.name);
866
- if (autofs4_oz_mode(sbi))
869
- if (autofs4_ispending(dentry)) {
870
- DPRINTK("dentry busy");
875
- if (d_mountpoint(dentry)) {
876
- struct file *fp = cursor->d_fsdata;
881
- filp_close(fp, current->files);
885
- dcache_dir_close(inode, file);
889
-static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
891
- struct dentry *dentry = file->f_path.dentry;
892
- struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
893
- struct dentry *cursor = file->private_data;
896
- DPRINTK("file=%p dentry=%p %.*s",
897
- file, dentry, dentry->d_name.len, dentry->d_name.name);
899
- if (autofs4_oz_mode(sbi))
902
- if (autofs4_ispending(dentry)) {
903
- DPRINTK("dentry busy");
907
- if (d_mountpoint(dentry)) {
908
- struct file *fp = cursor->d_fsdata;
913
- if (!fp->f_op || !fp->f_op->readdir)
915
+ spin_unlock(&dcache_lock);
917
- status = vfs_readdir(fp, filldir, dirent);
918
- file->f_pos = fp->f_pos;
920
- autofs4_copy_atime(file, fp);
924
- return dcache_readdir(file, dirent, filldir);
925
+ return dcache_dir_open(inode, file);
928
static int try_to_fill_dentry(struct dentry *dentry, int flags)
930
struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
931
struct autofs_info *ino = autofs4_dentry_ino(dentry);
934
- /* Block on any pending expiry here; invalidate the dentry
935
- when expiration is done to trigger mount request with a new
937
- if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
938
- DPRINTK("waiting for expire %p name=%.*s",
939
- dentry, dentry->d_name.len, dentry->d_name.name);
941
- status = autofs4_wait(sbi, dentry, NFY_NONE);
943
- DPRINTK("expire done status=%d", status);
946
- * If the directory still exists the mount request must
947
- * continue otherwise it can't be followed at the right
948
- * time during the walk.
950
- status = d_invalidate(dentry);
951
- if (status != -EBUSY)
956
DPRINTK("dentry=%p %.*s ino=%p",
957
dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
958
@@ -291,7 +133,8 @@ static int try_to_fill_dentry(struct den
961
/* Trigger mount for path component or follow link */
962
- } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) ||
963
+ } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
964
+ flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
965
current->link_count) {
966
DPRINTK("waiting for mount name=%.*s",
967
dentry->d_name.len, dentry->d_name.name);
968
@@ -318,7 +161,8 @@ static int try_to_fill_dentry(struct den
969
spin_lock(&dentry->d_lock);
970
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
971
spin_unlock(&dentry->d_lock);
977
/* For autofs direct mounts the follow link triggers the mount */
978
@@ -333,50 +177,62 @@ static void *autofs4_follow_link(struct
979
DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
980
dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
983
- /* If it's our master or we shouldn't trigger a mount we're done */
984
- lookup_type = nd->flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY);
985
- if (oz_mode || !lookup_type)
987
+ * For an expire of a covered direct or offset mount we need
988
+ * to beeak out of follow_down() at the autofs mount trigger
989
+ * (d_mounted--), so we can see the expiring flag, and manage
990
+ * the blocking and following here until the expire is completed.
993
+ spin_lock(&sbi->fs_lock);
994
+ if (ino->flags & AUTOFS_INF_EXPIRING) {
995
+ spin_unlock(&sbi->fs_lock);
996
+ /* Follow down to our covering mount. */
997
+ if (!follow_down(&nd->mnt, &nd->dentry))
1001
+ spin_unlock(&sbi->fs_lock);
1005
- /* If an expire request is pending wait for it. */
1006
- if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
1007
- DPRINTK("waiting for active request %p name=%.*s",
1008
- dentry, dentry->d_name.len, dentry->d_name.name);
1010
- status = autofs4_wait(sbi, dentry, NFY_NONE);
1011
+ /* If an expire request is pending everyone must wait. */
1012
+ autofs4_expire_wait(dentry);
1014
- DPRINTK("request done status=%d", status);
1016
+ /* We trigger a mount for almost all flags */
1017
+ lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
1018
+ if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
1022
- * If the dentry contains directories then it is an
1023
- * autofs multi-mount with no root mount offset. So
1024
- * don't try to mount it again.
1025
+ * If the dentry contains directories then it is an autofs
1026
+ * multi-mount with no root mount offset. So don't try to
1029
spin_lock(&dcache_lock);
1030
- if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
1031
+ if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
1032
+ (!d_mountpoint(dentry) && __simple_empty(dentry))) {
1033
spin_unlock(&dcache_lock);
1035
status = try_to_fill_dentry(dentry, 0);
1040
- * The mount succeeded but if there is no root mount
1041
- * it must be an autofs multi-mount with no root offset
1042
- * so we don't need to follow the mount.
1044
- if (d_mountpoint(dentry)) {
1045
- if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
1054
spin_unlock(&dcache_lock);
1057
+ * If there is no root mount it must be an autofs
1058
+ * multi-mount with no root offset so we don't need
1061
+ if (d_mountpoint(dentry)) {
1062
+ if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
1070
@@ -401,12 +257,23 @@ static int autofs4_revalidate(struct den
1073
/* Pending dentry */
1074
+ spin_lock(&sbi->fs_lock);
1075
if (autofs4_ispending(dentry)) {
1076
/* The daemon never causes a mount to trigger */
1077
+ spin_unlock(&sbi->fs_lock);
1083
+ * If the directory has gone away due to an expire
1084
+ * we have been called as ->d_revalidate() and so
1085
+ * we need to return false and proceed to ->lookup().
1087
+ if (autofs4_expire_wait(dentry) == -EAGAIN)
1091
* A zero status is success otherwise we have a
1092
* negative error code.
1094
@@ -414,17 +281,9 @@ static int autofs4_revalidate(struct den
1099
- * A status of EAGAIN here means that the dentry has gone
1100
- * away while waiting for an expire to complete. If we are
1101
- * racing with expire lookup will wait for it so this must
1102
- * be a revalidate and we need to send it to lookup.
1104
- if (status == -EAGAIN)
1109
+ spin_unlock(&sbi->fs_lock);
1111
/* Negative dentry.. invalidate if "old" */
1112
if (dentry->d_inode == NULL)
1113
@@ -438,6 +297,7 @@ static int autofs4_revalidate(struct den
1114
DPRINTK("dentry=%p %.*s, emptydir",
1115
dentry, dentry->d_name.len, dentry->d_name.name);
1116
spin_unlock(&dcache_lock);
1118
/* The daemon never causes a mount to trigger */
1121
@@ -470,10 +330,12 @@ void autofs4_dentry_release(struct dentr
1122
struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
1125
- spin_lock(&sbi->rehash_lock);
1126
- if (!list_empty(&inf->rehash))
1127
- list_del(&inf->rehash);
1128
- spin_unlock(&sbi->rehash_lock);
1129
+ spin_lock(&sbi->lookup_lock);
1130
+ if (!list_empty(&inf->active))
1131
+ list_del(&inf->active);
1132
+ if (!list_empty(&inf->expiring))
1133
+ list_del(&inf->expiring);
1134
+ spin_unlock(&sbi->lookup_lock);
1138
@@ -495,7 +357,7 @@ static struct dentry_operations autofs4_
1139
.d_release = autofs4_dentry_release,
1142
-static struct dentry *autofs4_lookup_unhashed(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
1143
+static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
1145
unsigned int len = name->len;
1146
unsigned int hash = name->hash;
1147
@@ -503,14 +365,66 @@ static struct dentry *autofs4_lookup_unh
1148
struct list_head *p, *head;
1150
spin_lock(&dcache_lock);
1151
- spin_lock(&sbi->rehash_lock);
1152
- head = &sbi->rehash_list;
1153
+ spin_lock(&sbi->lookup_lock);
1154
+ head = &sbi->active_list;
1155
list_for_each(p, head) {
1156
struct autofs_info *ino;
1157
struct dentry *dentry;
1160
- ino = list_entry(p, struct autofs_info, rehash);
1161
+ ino = list_entry(p, struct autofs_info, active);
1162
+ dentry = ino->dentry;
1164
+ spin_lock(&dentry->d_lock);
1166
+ /* Already gone? */
1167
+ if (atomic_read(&dentry->d_count) == 0)
1170
+ qstr = &dentry->d_name;
1172
+ if (dentry->d_name.hash != hash)
1174
+ if (dentry->d_parent != parent)
1177
+ if (qstr->len != len)
1179
+ if (memcmp(qstr->name, str, len))
1182
+ if (d_unhashed(dentry)) {
1184
+ spin_unlock(&dentry->d_lock);
1185
+ spin_unlock(&sbi->lookup_lock);
1186
+ spin_unlock(&dcache_lock);
1190
+ spin_unlock(&dentry->d_lock);
1192
+ spin_unlock(&sbi->lookup_lock);
1193
+ spin_unlock(&dcache_lock);
1198
+static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
1200
+ unsigned int len = name->len;
1201
+ unsigned int hash = name->hash;
1202
+ const unsigned char *str = name->name;
1203
+ struct list_head *p, *head;
1205
+ spin_lock(&dcache_lock);
1206
+ spin_lock(&sbi->lookup_lock);
1207
+ head = &sbi->expiring_list;
1208
+ list_for_each(p, head) {
1209
+ struct autofs_info *ino;
1210
+ struct dentry *dentry;
1211
+ struct qstr *qstr;
1213
+ ino = list_entry(p, struct autofs_info, expiring);
1214
dentry = ino->dentry;
1216
spin_lock(&dentry->d_lock);
1217
@@ -532,33 +446,16 @@ static struct dentry *autofs4_lookup_unh
1220
if (d_unhashed(dentry)) {
1221
- struct autofs_info *ino = autofs4_dentry_ino(dentry);
1222
- struct inode *inode = dentry->d_inode;
1224
- list_del_init(&ino->rehash);
1227
- * Make the rehashed dentry negative so the VFS
1228
- * behaves as it should.
1231
- dentry->d_inode = NULL;
1232
- list_del_init(&dentry->d_alias);
1233
- spin_unlock(&dentry->d_lock);
1234
- spin_unlock(&sbi->rehash_lock);
1235
- spin_unlock(&dcache_lock);
1239
spin_unlock(&dentry->d_lock);
1240
- spin_unlock(&sbi->rehash_lock);
1241
+ spin_unlock(&sbi->lookup_lock);
1242
spin_unlock(&dcache_lock);
1246
spin_unlock(&dentry->d_lock);
1248
- spin_unlock(&sbi->rehash_lock);
1249
+ spin_unlock(&sbi->lookup_lock);
1250
spin_unlock(&dcache_lock);
1253
@@ -568,7 +465,8 @@ next:
1254
static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
1256
struct autofs_sb_info *sbi;
1257
- struct dentry *unhashed;
1258
+ struct autofs_info *ino;
1259
+ struct dentry *expiring, *unhashed;
1262
DPRINTK("name = %.*s",
1263
@@ -584,8 +482,26 @@ static struct dentry *autofs4_lookup(str
1264
DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
1265
current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
1267
- unhashed = autofs4_lookup_unhashed(sbi, dentry->d_parent, &dentry->d_name);
1269
+ expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
1272
+ * If we are racing with expire the request might not
1273
+ * be quite complete but the directory has been removed
1274
+ * so it must have been successful, so just wait for it.
1276
+ ino = autofs4_dentry_ino(expiring);
1277
+ autofs4_expire_wait(expiring);
1278
+ spin_lock(&sbi->lookup_lock);
1279
+ if (!list_empty(&ino->expiring))
1280
+ list_del_init(&ino->expiring);
1281
+ spin_unlock(&sbi->lookup_lock);
1285
+ unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
1287
+ dentry = unhashed;
1290
* Mark the dentry incomplete but don't hash it. We do this
1291
* to serialize our inode creation operations (symlink and
1292
@@ -599,39 +515,34 @@ static struct dentry *autofs4_lookup(str
1294
dentry->d_op = &autofs4_root_dentry_operations;
1296
- dentry->d_fsdata = NULL;
1297
- d_instantiate(dentry, NULL);
1299
- struct autofs_info *ino = autofs4_dentry_ino(unhashed);
1300
- DPRINTK("rehash %p with %p", dentry, unhashed);
1302
- * If we are racing with expire the request might not
1303
- * be quite complete but the directory has been removed
1304
- * so it must have been successful, so just wait for it.
1305
- * We need to ensure the AUTOFS_INF_EXPIRING flag is clear
1306
- * before continuing as revalidate may fail when calling
1307
- * try_to_fill_dentry (returning EAGAIN) if we don't.
1308
+ * And we need to ensure that the same dentry is used for
1309
+ * all following lookup calls until it is hashed so that
1310
+ * the dentry flags are persistent throughout the request.
1312
- while (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
1313
- DPRINTK("wait for incomplete expire %p name=%.*s",
1314
- unhashed, unhashed->d_name.len,
1315
- unhashed->d_name.name);
1316
- autofs4_wait(sbi, unhashed, NFY_NONE);
1317
- DPRINTK("request completed");
1319
- dentry = unhashed;
1320
+ ino = autofs4_init_ino(NULL, sbi, 0555);
1322
+ return ERR_PTR(-ENOMEM);
1324
+ dentry->d_fsdata = ino;
1325
+ ino->dentry = dentry;
1327
+ spin_lock(&sbi->lookup_lock);
1328
+ list_add(&ino->active, &sbi->active_list);
1329
+ spin_unlock(&sbi->lookup_lock);
1331
+ d_instantiate(dentry, NULL);
1335
spin_lock(&dentry->d_lock);
1336
dentry->d_flags |= DCACHE_AUTOFS_PENDING;
1337
spin_unlock(&dentry->d_lock);
1340
- if (dentry->d_op && dentry->d_op->d_revalidate) {
1341
- mutex_unlock(&dir->i_mutex);
1342
- (dentry->d_op->d_revalidate)(dentry, nd);
1343
- mutex_lock(&dir->i_mutex);
1344
+ if (dentry->d_op && dentry->d_op->d_revalidate) {
1345
+ mutex_unlock(&dir->i_mutex);
1346
+ (dentry->d_op->d_revalidate)(dentry, nd);
1347
+ mutex_lock(&dir->i_mutex);
1352
@@ -650,9 +561,11 @@ static struct dentry *autofs4_lookup(str
1353
return ERR_PTR(-ERESTARTNOINTR);
1356
- spin_lock(&dentry->d_lock);
1357
- dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
1358
- spin_unlock(&dentry->d_lock);
1360
+ spin_lock(&dentry->d_lock);
1361
+ dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
1362
+ spin_unlock(&dentry->d_lock);
1367
@@ -683,7 +596,7 @@ static struct dentry *autofs4_lookup(str
1376
@@ -705,20 +618,31 @@ static int autofs4_dir_symlink(struct in
1379
ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
1385
- ino->size = strlen(symname);
1386
- ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
1387
+ spin_lock(&sbi->lookup_lock);
1388
+ if (!list_empty(&ino->active))
1389
+ list_del_init(&ino->active);
1390
+ spin_unlock(&sbi->lookup_lock);
1395
+ ino->size = strlen(symname);
1396
+ cp = kmalloc(ino->size + 1, GFP_KERNEL);
1398
+ if (!dentry->d_fsdata)
1403
strcpy(cp, symname);
1405
inode = autofs4_get_inode(dir->i_sb, ino);
1408
+ if (!dentry->d_fsdata)
1412
d_add(dentry, inode);
1414
if (dir == dir->i_sb->s_root->d_inode)
1415
@@ -734,6 +658,7 @@ static int autofs4_dir_symlink(struct in
1416
atomic_inc(&p_ino->count);
1419
+ ino->u.symlink = cp;
1420
dir->i_mtime = CURRENT_TIME;
1423
@@ -746,9 +671,8 @@ static int autofs4_dir_symlink(struct in
1424
* that the file no longer exists. However, doing that means that the
1425
* VFS layer can turn the dentry into a negative dentry. We don't want
1426
* this, because the unlink is probably the result of an expire.
1427
- * We simply d_drop it and add it to a rehash candidates list in the
1428
- * super block, which allows the dentry lookup to reuse it retaining
1429
- * the flags, such as expire in progress, in case we're racing with expire.
1430
+ * We simply d_drop it and add it to a expiring list in the super block,
1431
+ * which allows the dentry lookup to check for an incomplete expire.
1433
* If a process is blocked on the dentry waiting for the expire to finish,
1434
* it will invalidate the dentry and try to mount with a new one.
1435
@@ -778,9 +702,10 @@ static int autofs4_dir_unlink(struct ino
1436
dir->i_mtime = CURRENT_TIME;
1438
spin_lock(&dcache_lock);
1439
- spin_lock(&sbi->rehash_lock);
1440
- list_add(&ino->rehash, &sbi->rehash_list);
1441
- spin_unlock(&sbi->rehash_lock);
1442
+ spin_lock(&sbi->lookup_lock);
1443
+ if (list_empty(&ino->expiring))
1444
+ list_add(&ino->expiring, &sbi->expiring_list);
1445
+ spin_unlock(&sbi->lookup_lock);
1446
spin_lock(&dentry->d_lock);
1448
spin_unlock(&dentry->d_lock);
1449
@@ -806,9 +731,10 @@ static int autofs4_dir_rmdir(struct inod
1450
spin_unlock(&dcache_lock);
1453
- spin_lock(&sbi->rehash_lock);
1454
- list_add(&ino->rehash, &sbi->rehash_list);
1455
- spin_unlock(&sbi->rehash_lock);
1456
+ spin_lock(&sbi->lookup_lock);
1457
+ if (list_empty(&ino->expiring))
1458
+ list_add(&ino->expiring, &sbi->expiring_list);
1459
+ spin_unlock(&sbi->lookup_lock);
1460
spin_lock(&dentry->d_lock);
1462
spin_unlock(&dentry->d_lock);
1463
@@ -843,10 +769,20 @@ static int autofs4_dir_mkdir(struct inod
1464
dentry, dentry->d_name.len, dentry->d_name.name);
1466
ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
1472
+ spin_lock(&sbi->lookup_lock);
1473
+ if (!list_empty(&ino->active))
1474
+ list_del_init(&ino->active);
1475
+ spin_unlock(&sbi->lookup_lock);
1477
inode = autofs4_get_inode(dir->i_sb, ino);
1479
+ if (!dentry->d_fsdata)
1483
d_add(dentry, inode);
1485
if (dir == dir->i_sb->s_root->d_inode)
1486
@@ -899,44 +835,6 @@ static inline int autofs4_get_protosubve
1490
- * Tells the daemon whether we need to reghost or not. Also, clears
1491
- * the reghost_needed flag.
1493
-static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
1497
- DPRINTK("returning %d", sbi->needs_reghost);
1499
- status = put_user(sbi->needs_reghost, p);
1503
- sbi->needs_reghost = 0;
1508
- * Enable / Disable reghosting ioctl() operation
1510
-static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
1515
- status = get_user(val, p);
1517
- DPRINTK("reghost = %d", val);
1522
- /* turn on/off reghosting, with the val */
1523
- sbi->reghost_enabled = val;
1528
* Tells the daemon whether it can umount the autofs mount.
1530
static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
1531
@@ -1000,11 +898,6 @@ static int autofs4_root_ioctl(struct ino
1532
case AUTOFS_IOC_SETTIMEOUT:
1533
return autofs4_get_set_timeout(sbi, p);
1535
- case AUTOFS_IOC_TOGGLEREGHOST:
1536
- return autofs4_toggle_reghost(sbi, p);
1537
- case AUTOFS_IOC_ASKREGHOST:
1538
- return autofs4_ask_reghost(sbi, p);
1540
case AUTOFS_IOC_ASKUMOUNT:
1541
return autofs4_ask_umount(filp->f_path.mnt, p);
1543
Index: linux-2.6.24/fs/autofs4/autofs_i.h
1544
===================================================================
1545
--- linux-2.6.24.orig/fs/autofs4/autofs_i.h
1546
+++ linux-2.6.24/fs/autofs4/autofs_i.h
1548
#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
1549
#define AUTOFS_IOC_COUNT 32
1551
+#define AUTOFS_TYPE_TRIGGER (AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET)
1553
#include <linux/kernel.h>
1554
#include <linux/slab.h>
1555
#include <linux/time.h>
1556
@@ -52,7 +54,10 @@ struct autofs_info {
1560
- struct list_head rehash;
1561
+ struct completion expire_complete;
1563
+ struct list_head active;
1564
+ struct list_head expiring;
1566
struct autofs_sb_info *sbi;
1567
unsigned long last_used;
1568
@@ -68,15 +73,14 @@ struct autofs_info {
1571
#define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */
1572
+#define AUTOFS_INF_MOUNTPOINT (1<<1) /* mountpoint status for direct expire */
1574
struct autofs_wait_queue {
1575
wait_queue_head_t queue;
1576
struct autofs_wait_queue *next;
1577
autofs_wqt_t wait_queue_token;
1578
/* We use the following to see what we are waiting for */
1579
- unsigned int hash;
1586
@@ -85,15 +89,11 @@ struct autofs_wait_queue {
1588
/* This is for status reporting upon return */
1590
- atomic_t wait_ctr;
1591
+ unsigned int wait_ctr;
1594
#define AUTOFS_SBI_MAGIC 0x6d4a556d
1596
-#define AUTOFS_TYPE_INDIRECT 0x0001
1597
-#define AUTOFS_TYPE_DIRECT 0x0002
1598
-#define AUTOFS_TYPE_OFFSET 0x0004
1600
struct autofs_sb_info {
1603
@@ -112,8 +112,9 @@ struct autofs_sb_info {
1604
struct mutex wq_mutex;
1606
struct autofs_wait_queue *queues; /* Wait queue pointer */
1607
- spinlock_t rehash_lock;
1608
- struct list_head rehash_list;
1609
+ spinlock_t lookup_lock;
1610
+ struct list_head active_list;
1611
+ struct list_head expiring_list;
1614
static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
1615
@@ -138,18 +139,14 @@ static inline int autofs4_oz_mode(struct
1616
static inline int autofs4_ispending(struct dentry *dentry)
1618
struct autofs_info *inf = autofs4_dentry_ino(dentry);
1621
if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
1625
- spin_lock(&inf->sbi->fs_lock);
1626
- pending = inf->flags & AUTOFS_INF_EXPIRING;
1627
- spin_unlock(&inf->sbi->fs_lock);
1629
+ if (inf->flags & AUTOFS_INF_EXPIRING)
1636
static inline void autofs4_copy_atime(struct file *src, struct file *dst)
1637
@@ -164,6 +161,7 @@ void autofs4_free_ino(struct autofs_info
1640
int is_autofs4_dentry(struct dentry *);
1641
+int autofs4_expire_wait(struct dentry *dentry);
1642
int autofs4_expire_run(struct super_block *, struct vfsmount *,
1643
struct autofs_sb_info *,
1644
struct autofs_packet_expire __user *);
1645
Index: linux-2.6.24/fs/autofs4/inode.c
1646
===================================================================
1647
--- linux-2.6.24.orig/fs/autofs4/inode.c
1648
+++ linux-2.6.24/fs/autofs4/inode.c
1651
static void ino_lnkfree(struct autofs_info *ino)
1653
- kfree(ino->u.symlink);
1654
- ino->u.symlink = NULL;
1655
+ if (ino->u.symlink) {
1656
+ kfree(ino->u.symlink);
1657
+ ino->u.symlink = NULL;
1661
struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
1662
@@ -41,16 +43,18 @@ struct autofs_info *autofs4_init_ino(str
1668
- ino->inode = NULL;
1669
- ino->dentry = NULL;
1672
- INIT_LIST_HEAD(&ino->rehash);
1675
+ ino->inode = NULL;
1676
+ ino->dentry = NULL;
1678
+ INIT_LIST_HEAD(&ino->active);
1679
+ INIT_LIST_HEAD(&ino->expiring);
1680
+ atomic_set(&ino->count, 0);
1684
ino->last_used = jiffies;
1685
- atomic_set(&ino->count, 0);
1689
@@ -159,8 +163,8 @@ void autofs4_kill_sb(struct super_block
1693
- if (!sbi->catatonic)
1694
- autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
1695
+ /* Free wait queues, close pipe */
1696
+ autofs4_catatonic_mode(sbi);
1698
/* Clean up and release dangling references */
1699
autofs4_force_release(sbi);
1700
@@ -279,7 +283,7 @@ static int parse_options(char *options,
1701
*type = AUTOFS_TYPE_DIRECT;
1704
- *type = AUTOFS_TYPE_DIRECT | AUTOFS_TYPE_OFFSET;
1705
+ *type = AUTOFS_TYPE_OFFSET;
1709
@@ -327,14 +331,15 @@ int autofs4_fill_super(struct super_bloc
1712
sbi->sub_version = 0;
1714
+ sbi->type = AUTOFS_TYPE_INDIRECT;
1717
mutex_init(&sbi->wq_mutex);
1718
spin_lock_init(&sbi->fs_lock);
1720
- spin_lock_init(&sbi->rehash_lock);
1721
- INIT_LIST_HEAD(&sbi->rehash_list);
1722
+ spin_lock_init(&sbi->lookup_lock);
1723
+ INIT_LIST_HEAD(&sbi->active_list);
1724
+ INIT_LIST_HEAD(&sbi->expiring_list);
1725
s->s_blocksize = 1024;
1726
s->s_blocksize_bits = 10;
1727
s->s_magic = AUTOFS_SUPER_MAGIC;
1728
@@ -368,7 +373,7 @@ int autofs4_fill_super(struct super_bloc
1731
root_inode->i_fop = &autofs4_root_operations;
1732
- root_inode->i_op = sbi->type & AUTOFS_TYPE_DIRECT ?
1733
+ root_inode->i_op = sbi->type & AUTOFS_TYPE_TRIGGER ?
1734
&autofs4_direct_root_inode_operations :
1735
&autofs4_indirect_root_inode_operations;
1737
Index: linux-2.6.24/fs/compat_ioctl.c
1738
===================================================================
1739
--- linux-2.6.24.orig/fs/compat_ioctl.c
1740
+++ linux-2.6.24/fs/compat_ioctl.c
1741
@@ -2384,8 +2384,6 @@ COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
1742
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
1743
COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
1744
COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
1745
-COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
1746
-COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
1747
COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
1749
COMPATIBLE_IOCTL(RAW_SETBIND)
1750
Index: linux-2.6.24/include/linux/auto_fs4.h
1751
===================================================================
1752
--- linux-2.6.24.orig/include/linux/auto_fs4.h
1753
+++ linux-2.6.24/include/linux/auto_fs4.h
1755
#define AUTOFS_EXP_IMMEDIATE 1
1756
#define AUTOFS_EXP_LEAVES 2
1758
+#define AUTOFS_TYPE_ANY 0x0000
1759
+#define AUTOFS_TYPE_INDIRECT 0x0001
1760
+#define AUTOFS_TYPE_DIRECT 0x0002
1761
+#define AUTOFS_TYPE_OFFSET 0x0004
1763
/* Daemon notification packet types */
1764
enum autofs_notify {
1766
@@ -98,8 +103,6 @@ union autofs_v5_packet_union {
1767
#define AUTOFS_IOC_EXPIRE_INDIRECT AUTOFS_IOC_EXPIRE_MULTI
1768
#define AUTOFS_IOC_EXPIRE_DIRECT AUTOFS_IOC_EXPIRE_MULTI
1769
#define AUTOFS_IOC_PROTOSUBVER _IOR(0x93,0x67,int)
1770
-#define AUTOFS_IOC_ASKREGHOST _IOR(0x93,0x68,int)
1771
-#define AUTOFS_IOC_TOGGLEREGHOST _IOR(0x93,0x69,int)
1772
#define AUTOFS_IOC_ASKUMOUNT _IOR(0x93,0x70,int)