aboutsummaryrefslogtreecommitdiffstats
path: root/fs/autofs4/root.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/autofs4/root.c')
-rw-r--r--fs/autofs4/root.c475
1 files changed, 158 insertions, 317 deletions
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index 30cc9ddf4b70..109a6c606d92 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -15,6 +15,7 @@
15#include <linux/capability.h> 15#include <linux/capability.h>
16#include <linux/errno.h> 16#include <linux/errno.h>
17#include <linux/stat.h> 17#include <linux/stat.h>
18#include <linux/slab.h>
18#include <linux/param.h> 19#include <linux/param.h>
19#include <linux/time.h> 20#include <linux/time.h>
20#include "autofs_i.h" 21#include "autofs_i.h"
@@ -104,99 +105,6 @@ static void autofs4_del_active(struct dentry *dentry)
104 return; 105 return;
105} 106}
106 107
107static void autofs4_add_rehash_entry(struct autofs_info *ino,
108 struct rehash_entry *entry)
109{
110 entry->task = current;
111 INIT_LIST_HEAD(&entry->list);
112 list_add(&entry->list, &ino->rehash_list);
113 return;
114}
115
116static void autofs4_remove_rehash_entry(struct autofs_info *ino)
117{
118 struct list_head *head = &ino->rehash_list;
119 struct rehash_entry *entry;
120 list_for_each_entry(entry, head, list) {
121 if (entry->task == current) {
122 list_del(&entry->list);
123 kfree(entry);
124 break;
125 }
126 }
127 return;
128}
129
130static void autofs4_remove_rehash_entrys(struct autofs_info *ino)
131{
132 struct autofs_sb_info *sbi = ino->sbi;
133 struct rehash_entry *entry, *next;
134 struct list_head *head;
135
136 spin_lock(&sbi->fs_lock);
137 spin_lock(&sbi->lookup_lock);
138 if (!(ino->flags & AUTOFS_INF_REHASH)) {
139 spin_unlock(&sbi->lookup_lock);
140 spin_unlock(&sbi->fs_lock);
141 return;
142 }
143 ino->flags &= ~AUTOFS_INF_REHASH;
144 head = &ino->rehash_list;
145 list_for_each_entry_safe(entry, next, head, list) {
146 list_del(&entry->list);
147 kfree(entry);
148 }
149 spin_unlock(&sbi->lookup_lock);
150 spin_unlock(&sbi->fs_lock);
151 dput(ino->dentry);
152
153 return;
154}
155
156static void autofs4_revalidate_drop(struct dentry *dentry,
157 struct rehash_entry *entry)
158{
159 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
160 struct autofs_info *ino = autofs4_dentry_ino(dentry);
161 /*
162 * Add to the active list so we can pick this up in
163 * ->lookup(). Also add an entry to a rehash list so
164 * we know when there are no dentrys in flight so we
165 * know when we can rehash the dentry.
166 */
167 spin_lock(&sbi->lookup_lock);
168 if (list_empty(&ino->active))
169 list_add(&ino->active, &sbi->active_list);
170 autofs4_add_rehash_entry(ino, entry);
171 spin_unlock(&sbi->lookup_lock);
172 if (!(ino->flags & AUTOFS_INF_REHASH)) {
173 ino->flags |= AUTOFS_INF_REHASH;
174 dget(dentry);
175 spin_lock(&dentry->d_lock);
176 __d_drop(dentry);
177 spin_unlock(&dentry->d_lock);
178 }
179 return;
180}
181
182static void autofs4_revalidate_rehash(struct dentry *dentry)
183{
184 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
185 struct autofs_info *ino = autofs4_dentry_ino(dentry);
186 if (ino->flags & AUTOFS_INF_REHASH) {
187 spin_lock(&sbi->lookup_lock);
188 autofs4_remove_rehash_entry(ino);
189 if (list_empty(&ino->rehash_list)) {
190 spin_unlock(&sbi->lookup_lock);
191 ino->flags &= ~AUTOFS_INF_REHASH;
192 d_rehash(dentry);
193 dput(ino->dentry);
194 } else
195 spin_unlock(&sbi->lookup_lock);
196 }
197 return;
198}
199
200static unsigned int autofs4_need_mount(unsigned int flags) 108static unsigned int autofs4_need_mount(unsigned int flags)
201{ 109{
202 unsigned int res = 0; 110 unsigned int res = 0;
@@ -236,7 +144,7 @@ out:
236 return dcache_dir_open(inode, file); 144 return dcache_dir_open(inode, file);
237} 145}
238 146
239static int try_to_fill_dentry(struct dentry *dentry) 147static int try_to_fill_dentry(struct dentry *dentry, int flags)
240{ 148{
241 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); 149 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
242 struct autofs_info *ino = autofs4_dentry_ino(dentry); 150 struct autofs_info *ino = autofs4_dentry_ino(dentry);
@@ -249,17 +157,55 @@ static int try_to_fill_dentry(struct dentry *dentry)
249 * Wait for a pending mount, triggering one if there 157 * Wait for a pending mount, triggering one if there
250 * isn't one already 158 * isn't one already
251 */ 159 */
252 DPRINTK("waiting for mount name=%.*s", 160 if (dentry->d_inode == NULL) {
253 dentry->d_name.len, dentry->d_name.name); 161 DPRINTK("waiting for mount name=%.*s",
162 dentry->d_name.len, dentry->d_name.name);
254 163
255 status = autofs4_wait(sbi, dentry, NFY_MOUNT); 164 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
256 165
257 DPRINTK("mount done status=%d", status); 166 DPRINTK("mount done status=%d", status);
258 167
259 /* Update expiry counter */ 168 /* Turn this into a real negative dentry? */
260 ino->last_used = jiffies; 169 if (status == -ENOENT) {
170 spin_lock(&sbi->fs_lock);
171 ino->flags &= ~AUTOFS_INF_PENDING;
172 spin_unlock(&sbi->fs_lock);
173 return status;
174 } else if (status) {
175 /* Return a negative dentry, but leave it "pending" */
176 return status;
177 }
178 /* Trigger mount for path component or follow link */
179 } else if (ino->flags & AUTOFS_INF_PENDING ||
180 autofs4_need_mount(flags) ||
181 current->link_count) {
182 DPRINTK("waiting for mount name=%.*s",
183 dentry->d_name.len, dentry->d_name.name);
261 184
262 return status; 185 spin_lock(&sbi->fs_lock);
186 ino->flags |= AUTOFS_INF_PENDING;
187 spin_unlock(&sbi->fs_lock);
188 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
189
190 DPRINTK("mount done status=%d", status);
191
192 if (status) {
193 spin_lock(&sbi->fs_lock);
194 ino->flags &= ~AUTOFS_INF_PENDING;
195 spin_unlock(&sbi->fs_lock);
196 return status;
197 }
198 }
199
200 /* Initialize expiry counter after successful mount */
201 if (ino)
202 ino->last_used = jiffies;
203
204 spin_lock(&sbi->fs_lock);
205 ino->flags &= ~AUTOFS_INF_PENDING;
206 spin_unlock(&sbi->fs_lock);
207
208 return 0;
263} 209}
264 210
265/* For autofs direct mounts the follow link triggers the mount */ 211/* For autofs direct mounts the follow link triggers the mount */
@@ -313,16 +259,10 @@ static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
313 */ 259 */
314 if (ino->flags & AUTOFS_INF_PENDING || 260 if (ino->flags & AUTOFS_INF_PENDING ||
315 (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs))) { 261 (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs))) {
316 ino->flags |= AUTOFS_INF_PENDING;
317 spin_unlock(&dcache_lock); 262 spin_unlock(&dcache_lock);
318 spin_unlock(&sbi->fs_lock); 263 spin_unlock(&sbi->fs_lock);
319 264
320 status = try_to_fill_dentry(dentry); 265 status = try_to_fill_dentry(dentry, 0);
321
322 spin_lock(&sbi->fs_lock);
323 ino->flags &= ~AUTOFS_INF_PENDING;
324 spin_unlock(&sbi->fs_lock);
325
326 if (status) 266 if (status)
327 goto out_error; 267 goto out_error;
328 268
@@ -361,47 +301,18 @@ static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
361{ 301{
362 struct inode *dir = dentry->d_parent->d_inode; 302 struct inode *dir = dentry->d_parent->d_inode;
363 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); 303 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
364 struct autofs_info *ino = autofs4_dentry_ino(dentry); 304 int oz_mode = autofs4_oz_mode(sbi);
365 struct rehash_entry *entry;
366 int flags = nd ? nd->flags : 0; 305 int flags = nd ? nd->flags : 0;
367 unsigned int mutex_aquired; 306 int status = 1;
368 307
369 DPRINTK("name = %.*s oz_mode = %d",
370 dentry->d_name.len, dentry->d_name.name, oz_mode);
371
372 /* Daemon never causes a mount to trigger */
373 if (autofs4_oz_mode(sbi))
374 return 1;
375
376 entry = kmalloc(sizeof(struct rehash_entry), GFP_KERNEL);
377 if (!entry)
378 return -ENOMEM;
379
380 mutex_aquired = mutex_trylock(&dir->i_mutex);
381
382 spin_lock(&sbi->fs_lock);
383 spin_lock(&dcache_lock);
384 /* Pending dentry */ 308 /* Pending dentry */
309 spin_lock(&sbi->fs_lock);
385 if (autofs4_ispending(dentry)) { 310 if (autofs4_ispending(dentry)) {
386 int status; 311 /* The daemon never causes a mount to trigger */
387
388 /*
389 * We can only unhash and send this to ->lookup() if
390 * the directory mutex is held over d_revalidate() and
391 * ->lookup(). This prevents the VFS from incorrectly
392 * seeing the dentry as non-existent.
393 */
394 ino->flags |= AUTOFS_INF_PENDING;
395 if (!mutex_aquired) {
396 autofs4_revalidate_drop(dentry, entry);
397 spin_unlock(&dcache_lock);
398 spin_unlock(&sbi->fs_lock);
399 return 0;
400 }
401 spin_unlock(&dcache_lock);
402 spin_unlock(&sbi->fs_lock); 312 spin_unlock(&sbi->fs_lock);
403 mutex_unlock(&dir->i_mutex); 313
404 kfree(entry); 314 if (oz_mode)
315 return 1;
405 316
406 /* 317 /*
407 * If the directory has gone away due to an expire 318 * If the directory has gone away due to an expire
@@ -415,82 +326,45 @@ static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
415 * A zero status is success otherwise we have a 326 * A zero status is success otherwise we have a
416 * negative error code. 327 * negative error code.
417 */ 328 */
418 status = try_to_fill_dentry(dentry); 329 status = try_to_fill_dentry(dentry, flags);
419
420 spin_lock(&sbi->fs_lock);
421 ino->flags &= ~AUTOFS_INF_PENDING;
422 spin_unlock(&sbi->fs_lock);
423
424 if (status == 0) 330 if (status == 0)
425 return 1; 331 return 1;
426 332
427 return status; 333 return status;
428 } 334 }
335 spin_unlock(&sbi->fs_lock);
336
337 /* Negative dentry.. invalidate if "old" */
338 if (dentry->d_inode == NULL)
339 return 0;
429 340
430 /* Check for a non-mountpoint directory with no contents */ 341 /* Check for a non-mountpoint directory with no contents */
342 spin_lock(&dcache_lock);
431 if (S_ISDIR(dentry->d_inode->i_mode) && 343 if (S_ISDIR(dentry->d_inode->i_mode) &&
432 !d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) { 344 !d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) {
433 DPRINTK("dentry=%p %.*s, emptydir", 345 DPRINTK("dentry=%p %.*s, emptydir",
434 dentry, dentry->d_name.len, dentry->d_name.name); 346 dentry, dentry->d_name.len, dentry->d_name.name);
347 spin_unlock(&dcache_lock);
435 348
436 if (autofs4_need_mount(flags) || current->link_count) { 349 /* The daemon never causes a mount to trigger */
437 int status; 350 if (oz_mode)
438 351 return 1;
439 /*
440 * We can only unhash and send this to ->lookup() if
441 * the directory mutex is held over d_revalidate() and
442 * ->lookup(). This prevents the VFS from incorrectly
443 * seeing the dentry as non-existent.
444 */
445 ino->flags |= AUTOFS_INF_PENDING;
446 if (!mutex_aquired) {
447 autofs4_revalidate_drop(dentry, entry);
448 spin_unlock(&dcache_lock);
449 spin_unlock(&sbi->fs_lock);
450 return 0;
451 }
452 spin_unlock(&dcache_lock);
453 spin_unlock(&sbi->fs_lock);
454 mutex_unlock(&dir->i_mutex);
455 kfree(entry);
456
457 /*
458 * A zero status is success otherwise we have a
459 * negative error code.
460 */
461 status = try_to_fill_dentry(dentry);
462
463 spin_lock(&sbi->fs_lock);
464 ino->flags &= ~AUTOFS_INF_PENDING;
465 spin_unlock(&sbi->fs_lock);
466 352
467 if (status == 0) 353 /*
468 return 1; 354 * A zero status is success otherwise we have a
355 * negative error code.
356 */
357 status = try_to_fill_dentry(dentry, flags);
358 if (status == 0)
359 return 1;
469 360
470 return status; 361 return status;
471 }
472 } 362 }
473 spin_unlock(&dcache_lock); 363 spin_unlock(&dcache_lock);
474 spin_unlock(&sbi->fs_lock);
475
476 if (mutex_aquired)
477 mutex_unlock(&dir->i_mutex);
478
479 kfree(entry);
480 364
481 return 1; 365 return 1;
482} 366}
483 367
484static void autofs4_free_rehash_entrys(struct autofs_info *inf)
485{
486 struct list_head *head = &inf->rehash_list;
487 struct rehash_entry *entry, *next;
488 list_for_each_entry_safe(entry, next, head, list) {
489 list_del(&entry->list);
490 kfree(entry);
491 }
492}
493
494void autofs4_dentry_release(struct dentry *de) 368void autofs4_dentry_release(struct dentry *de)
495{ 369{
496 struct autofs_info *inf; 370 struct autofs_info *inf;
@@ -509,8 +383,6 @@ void autofs4_dentry_release(struct dentry *de)
509 list_del(&inf->active); 383 list_del(&inf->active);
510 if (!list_empty(&inf->expiring)) 384 if (!list_empty(&inf->expiring))
511 list_del(&inf->expiring); 385 list_del(&inf->expiring);
512 if (!list_empty(&inf->rehash_list))
513 autofs4_free_rehash_entrys(inf);
514 spin_unlock(&sbi->lookup_lock); 386 spin_unlock(&sbi->lookup_lock);
515 } 387 }
516 388
@@ -543,7 +415,6 @@ static struct dentry *autofs4_lookup_active(struct dentry *dentry)
543 const unsigned char *str = name->name; 415 const unsigned char *str = name->name;
544 struct list_head *p, *head; 416 struct list_head *p, *head;
545 417
546restart:
547 spin_lock(&dcache_lock); 418 spin_lock(&dcache_lock);
548 spin_lock(&sbi->lookup_lock); 419 spin_lock(&sbi->lookup_lock);
549 head = &sbi->active_list; 420 head = &sbi->active_list;
@@ -561,19 +432,6 @@ restart:
561 if (atomic_read(&active->d_count) == 0) 432 if (atomic_read(&active->d_count) == 0)
562 goto next; 433 goto next;
563 434
564 if (active->d_inode && IS_DEADDIR(active->d_inode)) {
565 if (!list_empty(&ino->rehash_list)) {
566 dget(active);
567 spin_unlock(&active->d_lock);
568 spin_unlock(&sbi->lookup_lock);
569 spin_unlock(&dcache_lock);
570 autofs4_remove_rehash_entrys(ino);
571 dput(active);
572 goto restart;
573 }
574 goto next;
575 }
576
577 qstr = &active->d_name; 435 qstr = &active->d_name;
578 436
579 if (active->d_name.hash != hash) 437 if (active->d_name.hash != hash)
@@ -586,11 +444,13 @@ restart:
586 if (memcmp(qstr->name, str, len)) 444 if (memcmp(qstr->name, str, len))
587 goto next; 445 goto next;
588 446
589 dget(active); 447 if (d_unhashed(active)) {
590 spin_unlock(&active->d_lock); 448 dget(active);
591 spin_unlock(&sbi->lookup_lock); 449 spin_unlock(&active->d_lock);
592 spin_unlock(&dcache_lock); 450 spin_unlock(&sbi->lookup_lock);
593 return active; 451 spin_unlock(&dcache_lock);
452 return active;
453 }
594next: 454next:
595 spin_unlock(&active->d_lock); 455 spin_unlock(&active->d_lock);
596 } 456 }
@@ -639,11 +499,13 @@ static struct dentry *autofs4_lookup_expiring(struct dentry *dentry)
639 if (memcmp(qstr->name, str, len)) 499 if (memcmp(qstr->name, str, len))
640 goto next; 500 goto next;
641 501
642 dget(expiring); 502 if (d_unhashed(expiring)) {
643 spin_unlock(&expiring->d_lock); 503 dget(expiring);
644 spin_unlock(&sbi->lookup_lock); 504 spin_unlock(&expiring->d_lock);
645 spin_unlock(&dcache_lock); 505 spin_unlock(&sbi->lookup_lock);
646 return expiring; 506 spin_unlock(&dcache_lock);
507 return expiring;
508 }
647next: 509next:
648 spin_unlock(&expiring->d_lock); 510 spin_unlock(&expiring->d_lock);
649 } 511 }
@@ -653,48 +515,6 @@ next:
653 return NULL; 515 return NULL;
654} 516}
655 517
656static struct autofs_info *init_new_dentry(struct autofs_sb_info *sbi,
657 struct dentry *dentry, int oz_mode)
658{
659 struct autofs_info *ino;
660
661 /*
662 * Mark the dentry incomplete but don't hash it. We do this
663 * to serialize our inode creation operations (symlink and
664 * mkdir) which prevents deadlock during the callback to
665 * the daemon. Subsequent user space lookups for the same
666 * dentry are placed on the wait queue while the daemon
667 * itself is allowed passage unresticted so the create
668 * operation itself can then hash the dentry. Finally,
669 * we check for the hashed dentry and return the newly
670 * hashed dentry.
671 */
672 dentry->d_op = &autofs4_root_dentry_operations;
673
674 /*
675 * And we need to ensure that the same dentry is used for
676 * all following lookup calls until it is hashed so that
677 * the dentry flags are persistent throughout the request.
678 */
679 ino = autofs4_init_ino(NULL, sbi, 0555);
680 if (!ino)
681 return ERR_PTR(-ENOMEM);
682
683 dentry->d_fsdata = ino;
684 ino->dentry = dentry;
685
686 /*
687 * Only set the mount pending flag for new dentrys not created
688 * by the daemon.
689 */
690 if (!oz_mode)
691 ino->flags |= AUTOFS_INF_PENDING;
692
693 d_instantiate(dentry, NULL);
694
695 return ino;
696}
697
698/* Lookups in the root directory */ 518/* Lookups in the root directory */
699static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) 519static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
700{ 520{
@@ -702,7 +522,6 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
702 struct autofs_info *ino; 522 struct autofs_info *ino;
703 struct dentry *expiring, *active; 523 struct dentry *expiring, *active;
704 int oz_mode; 524 int oz_mode;
705 int status = 0;
706 525
707 DPRINTK("name = %.*s", 526 DPRINTK("name = %.*s",
708 dentry->d_name.len, dentry->d_name.name); 527 dentry->d_name.len, dentry->d_name.name);
@@ -717,26 +536,44 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
717 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", 536 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
718 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode); 537 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
719 538
720 spin_lock(&sbi->fs_lock);
721 active = autofs4_lookup_active(dentry); 539 active = autofs4_lookup_active(dentry);
722 if (active) { 540 if (active) {
723 dentry = active; 541 dentry = active;
724 ino = autofs4_dentry_ino(dentry); 542 ino = autofs4_dentry_ino(dentry);
725 /* If this came from revalidate, rehash it */
726 autofs4_revalidate_rehash(dentry);
727 spin_unlock(&sbi->fs_lock);
728 } else { 543 } else {
729 spin_unlock(&sbi->fs_lock); 544 /*
730 ino = init_new_dentry(sbi, dentry, oz_mode); 545 * Mark the dentry incomplete but don't hash it. We do this
731 if (IS_ERR(ino)) 546 * to serialize our inode creation operations (symlink and
732 return (struct dentry *) ino; 547 * mkdir) which prevents deadlock during the callback to
733 } 548 * the daemon. Subsequent user space lookups for the same
549 * dentry are placed on the wait queue while the daemon
550 * itself is allowed passage unresticted so the create
551 * operation itself can then hash the dentry. Finally,
552 * we check for the hashed dentry and return the newly
553 * hashed dentry.
554 */
555 dentry->d_op = &autofs4_root_dentry_operations;
556
557 /*
558 * And we need to ensure that the same dentry is used for
559 * all following lookup calls until it is hashed so that
560 * the dentry flags are persistent throughout the request.
561 */
562 ino = autofs4_init_ino(NULL, sbi, 0555);
563 if (!ino)
564 return ERR_PTR(-ENOMEM);
734 565
735 autofs4_add_active(dentry); 566 dentry->d_fsdata = ino;
567 ino->dentry = dentry;
568
569 autofs4_add_active(dentry);
570
571 d_instantiate(dentry, NULL);
572 }
736 573
737 if (!oz_mode) { 574 if (!oz_mode) {
738 expiring = autofs4_lookup_expiring(dentry);
739 mutex_unlock(&dir->i_mutex); 575 mutex_unlock(&dir->i_mutex);
576 expiring = autofs4_lookup_expiring(dentry);
740 if (expiring) { 577 if (expiring) {
741 /* 578 /*
742 * If we are racing with expire the request might not 579 * If we are racing with expire the request might not
@@ -744,22 +581,23 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
744 * so it must have been successful, so just wait for it. 581 * so it must have been successful, so just wait for it.
745 */ 582 */
746 autofs4_expire_wait(expiring); 583 autofs4_expire_wait(expiring);
584 autofs4_del_expiring(expiring);
747 dput(expiring); 585 dput(expiring);
748 } 586 }
749 status = try_to_fill_dentry(dentry); 587
750 mutex_lock(&dir->i_mutex);
751 spin_lock(&sbi->fs_lock); 588 spin_lock(&sbi->fs_lock);
752 ino->flags &= ~AUTOFS_INF_PENDING; 589 ino->flags |= AUTOFS_INF_PENDING;
753 spin_unlock(&sbi->fs_lock); 590 spin_unlock(&sbi->fs_lock);
591 if (dentry->d_op && dentry->d_op->d_revalidate)
592 (dentry->d_op->d_revalidate)(dentry, nd);
593 mutex_lock(&dir->i_mutex);
754 } 594 }
755 595
756 autofs4_del_active(dentry);
757
758 /* 596 /*
759 * If we had a mount fail, check if we had to handle 597 * If we are still pending, check if we had to handle
760 * a signal. If so we can force a restart.. 598 * a signal. If so we can force a restart..
761 */ 599 */
762 if (status) { 600 if (ino->flags & AUTOFS_INF_PENDING) {
763 /* See if we were interrupted */ 601 /* See if we were interrupted */
764 if (signal_pending(current)) { 602 if (signal_pending(current)) {
765 sigset_t *sigset = &current->pending.signal; 603 sigset_t *sigset = &current->pending.signal;
@@ -771,46 +609,43 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
771 return ERR_PTR(-ERESTARTNOINTR); 609 return ERR_PTR(-ERESTARTNOINTR);
772 } 610 }
773 } 611 }
774 } 612 if (!oz_mode) {
775 613 spin_lock(&sbi->fs_lock);
776 /* 614 ino->flags &= ~AUTOFS_INF_PENDING;
777 * User space can (and has done in the past) remove and re-create 615 spin_unlock(&sbi->fs_lock);
778 * this directory during the callback. This can leave us with an
779 * unhashed dentry, but a successful mount! So we need to
780 * perform another cached lookup in case the dentry now exists.
781 */
782 if (!oz_mode && !have_submounts(dentry)) {
783 struct dentry *new;
784 new = d_lookup(dentry->d_parent, &dentry->d_name);
785 if (new) {
786 if (active)
787 dput(active);
788 return new;
789 } else {
790 if (!status)
791 status = -ENOENT;
792 } 616 }
793 } 617 }
794 618
795 /* 619 /*
796 * If we had a mount failure, return status to user space. 620 * If this dentry is unhashed, then we shouldn't honour this
797 * If the mount succeeded and we used a dentry from the active queue 621 * lookup. Returning ENOENT here doesn't do the right thing
798 * return it. 622 * for all system calls, but it should be OK for the operations
623 * we permit from an autofs.
799 */ 624 */
800 if (status) { 625 if (!oz_mode && d_unhashed(dentry)) {
801 dentry = ERR_PTR(status);
802 if (active)
803 dput(active);
804 return dentry;
805 } else {
806 /* 626 /*
807 * Valid successful mount, return active dentry or NULL 627 * A user space application can (and has done in the past)
808 * for a new dentry. 628 * remove and re-create this directory during the callback.
629 * This can leave us with an unhashed dentry, but a
630 * successful mount! So we need to perform another
631 * cached lookup in case the dentry now exists.
809 */ 632 */
633 struct dentry *parent = dentry->d_parent;
634 struct dentry *new = d_lookup(parent, &dentry->d_name);
635 if (new != NULL)
636 dentry = new;
637 else
638 dentry = ERR_PTR(-ENOENT);
639
810 if (active) 640 if (active)
811 return active; 641 dput(active);
642
643 return dentry;
812 } 644 }
813 645
646 if (active)
647 return active;
648
814 return NULL; 649 return NULL;
815} 650}
816 651
@@ -834,6 +669,8 @@ static int autofs4_dir_symlink(struct inode *dir,
834 if (!ino) 669 if (!ino)
835 return -ENOMEM; 670 return -ENOMEM;
836 671
672 autofs4_del_active(dentry);
673
837 ino->size = strlen(symname); 674 ino->size = strlen(symname);
838 cp = kmalloc(ino->size + 1, GFP_KERNEL); 675 cp = kmalloc(ino->size + 1, GFP_KERNEL);
839 if (!cp) { 676 if (!cp) {
@@ -910,6 +747,7 @@ static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
910 dir->i_mtime = CURRENT_TIME; 747 dir->i_mtime = CURRENT_TIME;
911 748
912 spin_lock(&dcache_lock); 749 spin_lock(&dcache_lock);
750 autofs4_add_expiring(dentry);
913 spin_lock(&dentry->d_lock); 751 spin_lock(&dentry->d_lock);
914 __d_drop(dentry); 752 __d_drop(dentry);
915 spin_unlock(&dentry->d_lock); 753 spin_unlock(&dentry->d_lock);
@@ -935,6 +773,7 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
935 spin_unlock(&dcache_lock); 773 spin_unlock(&dcache_lock);
936 return -ENOTEMPTY; 774 return -ENOTEMPTY;
937 } 775 }
776 autofs4_add_expiring(dentry);
938 spin_lock(&dentry->d_lock); 777 spin_lock(&dentry->d_lock);
939 __d_drop(dentry); 778 __d_drop(dentry);
940 spin_unlock(&dentry->d_lock); 779 spin_unlock(&dentry->d_lock);
@@ -972,6 +811,8 @@ static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
972 if (!ino) 811 if (!ino)
973 return -ENOMEM; 812 return -ENOMEM;
974 813
814 autofs4_del_active(dentry);
815
975 inode = autofs4_get_inode(dir->i_sb, ino); 816 inode = autofs4_get_inode(dir->i_sb, ino);
976 if (!inode) { 817 if (!inode) {
977 if (!dentry->d_fsdata) 818 if (!dentry->d_fsdata)