Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

autofs4: always use lookup for lookup

We need to be able to cope with the directory mutex being held during
->d_revalidate() in some cases, but not all cases, and not necessarily by
us. Because we need to release the mutex when we call back to the daemon
to do perform a mount we must be sure that it is us who holds the mutex so
we must redirect mount requests to ->lookup() if the mutex is held.

Signed-off-by: Ian Kent <raven@themaw.net>
Cc: Sage Weil <sage@newdream.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Andreas Dilger <adilger@sun.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Yehuda Saheh <yehuda@newdream.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ian Kent and committed by
Linus Torvalds
213614d5 cb4b492a

+331 -159
+7
fs/autofs4/autofs_i.h
··· 60 60 current->pid, __func__, ##args); \ 61 61 } while (0) 62 62 63 + struct rehash_entry { 64 + struct task_struct *task; 65 + struct list_head list; 66 + }; 67 + 63 68 /* Unified info structure. This is pointed to by both the dentry and 64 69 inode structures. Each file in the filesystem has an instance of this 65 70 structure. It holds a reference to the dentry, so dentries are never ··· 81 76 82 77 struct list_head active; 83 78 int active_count; 79 + struct list_head rehash_list; 84 80 85 81 struct list_head expiring; 86 82 ··· 104 98 #define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */ 105 99 #define AUTOFS_INF_MOUNTPOINT (1<<1) /* mountpoint status for direct expire */ 106 100 #define AUTOFS_INF_PENDING (1<<2) /* dentry pending mount */ 101 + #define AUTOFS_INF_REHASH (1<<3) /* dentry in transit to ->lookup() */ 107 102 108 103 struct autofs_wait_queue { 109 104 wait_queue_head_t queue;
+5 -1
fs/autofs4/expire.c
··· 279 279 root->d_mounted--; 280 280 } 281 281 ino->flags |= AUTOFS_INF_EXPIRING; 282 + autofs4_add_expiring(root); 282 283 init_completion(&ino->expire_complete); 283 284 spin_unlock(&sbi->fs_lock); 284 285 return root; ··· 407 406 expired, (int)expired->d_name.len, expired->d_name.name); 408 407 ino = autofs4_dentry_ino(expired); 409 408 ino->flags |= AUTOFS_INF_EXPIRING; 409 + autofs4_add_expiring(expired); 410 410 init_completion(&ino->expire_complete); 411 411 spin_unlock(&sbi->fs_lock); 412 412 spin_lock(&dcache_lock); ··· 435 433 436 434 DPRINTK("expire done status=%d", status); 437 435 438 - if (d_unhashed(dentry)) 436 + if (d_unhashed(dentry) && IS_DEADDIR(dentry->d_inode)) 439 437 return -EAGAIN; 440 438 441 439 return status; ··· 475 473 spin_lock(&sbi->fs_lock); 476 474 ino = autofs4_dentry_ino(dentry); 477 475 ino->flags &= ~AUTOFS_INF_EXPIRING; 476 + autofs4_del_expiring(dentry); 478 477 complete_all(&ino->expire_complete); 479 478 spin_unlock(&sbi->fs_lock); 480 479 ··· 506 503 ino->flags &= ~AUTOFS_INF_MOUNTPOINT; 507 504 } 508 505 ino->flags &= ~AUTOFS_INF_EXPIRING; 506 + autofs4_del_expiring(dentry); 509 507 complete_all(&ino->expire_complete); 510 508 spin_unlock(&sbi->fs_lock); 511 509 dput(dentry);
+1
fs/autofs4/inode.c
··· 49 49 ino->dentry = NULL; 50 50 ino->size = 0; 51 51 INIT_LIST_HEAD(&ino->active); 52 + INIT_LIST_HEAD(&ino->rehash_list); 52 53 ino->active_count = 0; 53 54 INIT_LIST_HEAD(&ino->expiring); 54 55 atomic_set(&ino->count, 0);
+318 -158
fs/autofs4/root.c
··· 104 104 return; 105 105 } 106 106 107 + static 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 + 116 + static 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 + 130 + static 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 + 156 + static 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 + 182 + static 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 + 107 200 static unsigned int autofs4_need_mount(unsigned int flags) 108 201 { 109 202 unsigned int res = 0; ··· 236 143 return dcache_dir_open(inode, file); 237 144 } 238 145 239 - static int try_to_fill_dentry(struct dentry *dentry, int flags) 146 + static int try_to_fill_dentry(struct dentry *dentry) 240 147 { 241 148 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); 242 149 struct autofs_info *ino = autofs4_dentry_ino(dentry); ··· 249 156 * Wait for a pending mount, triggering one if there 250 157 * isn't one already 251 158 */ 252 - if (dentry->d_inode == NULL) { 253 - DPRINTK("waiting for mount name=%.*s", 254 - dentry->d_name.len, dentry->d_name.name); 159 + DPRINTK("waiting for mount name=%.*s", 160 + dentry->d_name.len, dentry->d_name.name); 255 161 256 - status = autofs4_wait(sbi, dentry, NFY_MOUNT); 162 + status = autofs4_wait(sbi, dentry, NFY_MOUNT); 257 163 258 - DPRINTK("mount done status=%d", status); 164 + DPRINTK("mount done status=%d", status); 259 165 260 - /* Turn this into a real negative dentry? */ 261 - if (status == -ENOENT) { 262 - spin_lock(&sbi->fs_lock); 263 - ino->flags &= ~AUTOFS_INF_PENDING; 264 - spin_unlock(&sbi->fs_lock); 265 - return status; 266 - } else if (status) { 267 - /* Return a negative dentry, but leave it "pending" */ 268 - return status; 269 - } 270 - /* Trigger mount for path component or follow link */ 271 - } else if (ino->flags & AUTOFS_INF_PENDING || 272 - autofs4_need_mount(flags) || 273 - current->link_count) { 274 - DPRINTK("waiting for mount name=%.*s", 275 - dentry->d_name.len, dentry->d_name.name); 166 + /* Update expiry counter */ 167 + ino->last_used = jiffies; 276 168 277 - spin_lock(&sbi->fs_lock); 278 - ino->flags |= AUTOFS_INF_PENDING; 279 - spin_unlock(&sbi->fs_lock); 280 - status = autofs4_wait(sbi, dentry, NFY_MOUNT); 281 - 282 - DPRINTK("mount done status=%d", status); 283 - 284 - if (status) { 285 - spin_lock(&sbi->fs_lock); 286 - ino->flags &= ~AUTOFS_INF_PENDING; 287 - spin_unlock(&sbi->fs_lock); 288 - return status; 289 - } 290 - } 291 - 292 - /* Initialize expiry counter after successful mount */ 293 - if (ino) 294 - ino->last_used = jiffies; 295 - 296 - spin_lock(&sbi->fs_lock); 297 - ino->flags &= ~AUTOFS_INF_PENDING; 298 - spin_unlock(&sbi->fs_lock); 299 - 300 - return 0; 169 + return status; 301 170 } 302 171 303 172 /* For autofs direct mounts the follow link triggers the mount */ ··· 313 258 */ 314 259 if (ino->flags & AUTOFS_INF_PENDING || 315 260 (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs))) { 261 + ino->flags |= AUTOFS_INF_PENDING; 316 262 spin_unlock(&dcache_lock); 317 263 spin_unlock(&sbi->fs_lock); 318 264 319 - status = try_to_fill_dentry(dentry, 0); 265 + status = try_to_fill_dentry(dentry); 266 + 267 + spin_lock(&sbi->fs_lock); 268 + ino->flags &= ~AUTOFS_INF_PENDING; 269 + spin_unlock(&sbi->fs_lock); 270 + 320 271 if (status) 321 272 goto out_error; 322 273 ··· 361 300 { 362 301 struct inode *dir = dentry->d_parent->d_inode; 363 302 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); 364 - int oz_mode = autofs4_oz_mode(sbi); 303 + struct autofs_info *ino = autofs4_dentry_ino(dentry); 304 + struct rehash_entry *entry; 365 305 int flags = nd ? nd->flags : 0; 366 - int status = 1; 306 + unsigned int mutex_aquired; 367 307 368 - /* Pending dentry */ 308 + DPRINTK("name = %.*s oz_mode = %d", 309 + dentry->d_name.len, dentry->d_name.name, oz_mode); 310 + 311 + /* Daemon never causes a mount to trigger */ 312 + if (autofs4_oz_mode(sbi)) 313 + return 1; 314 + 315 + entry = kmalloc(sizeof(struct rehash_entry), GFP_KERNEL); 316 + if (!entry) 317 + return -ENOMEM; 318 + 319 + mutex_aquired = mutex_trylock(&dir->i_mutex); 320 + 369 321 spin_lock(&sbi->fs_lock); 322 + spin_lock(&dcache_lock); 323 + /* Pending dentry */ 370 324 if (autofs4_ispending(dentry)) { 371 - /* The daemon never causes a mount to trigger */ 372 - spin_unlock(&sbi->fs_lock); 325 + int status; 373 326 374 - if (oz_mode) 375 - return 1; 327 + /* 328 + * We can only unhash and send this to ->lookup() if 329 + * the directory mutex is held over d_revalidate() and 330 + * ->lookup(). This prevents the VFS from incorrectly 331 + * seeing the dentry as non-existent. 332 + */ 333 + ino->flags |= AUTOFS_INF_PENDING; 334 + if (!mutex_aquired) { 335 + autofs4_revalidate_drop(dentry, entry); 336 + spin_unlock(&dcache_lock); 337 + spin_unlock(&sbi->fs_lock); 338 + return 0; 339 + } 340 + spin_unlock(&dcache_lock); 341 + spin_unlock(&sbi->fs_lock); 342 + mutex_unlock(&dir->i_mutex); 343 + kfree(entry); 376 344 377 345 /* 378 346 * If the directory has gone away due to an expire ··· 415 325 * A zero status is success otherwise we have a 416 326 * negative error code. 417 327 */ 418 - status = try_to_fill_dentry(dentry, flags); 328 + status = try_to_fill_dentry(dentry); 329 + 330 + spin_lock(&sbi->fs_lock); 331 + ino->flags &= ~AUTOFS_INF_PENDING; 332 + spin_unlock(&sbi->fs_lock); 333 + 419 334 if (status == 0) 420 335 return 1; 421 336 422 337 return status; 423 338 } 424 - spin_unlock(&sbi->fs_lock); 425 - 426 - /* Negative dentry.. invalidate if "old" */ 427 - if (dentry->d_inode == NULL) 428 - return 0; 429 339 430 340 /* Check for a non-mountpoint directory with no contents */ 431 - spin_lock(&dcache_lock); 432 341 if (S_ISDIR(dentry->d_inode->i_mode) && 433 342 !d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) { 434 343 DPRINTK("dentry=%p %.*s, emptydir", 435 344 dentry, dentry->d_name.len, dentry->d_name.name); 436 - spin_unlock(&dcache_lock); 437 345 438 - /* The daemon never causes a mount to trigger */ 439 - if (oz_mode) 440 - return 1; 346 + if (autofs4_need_mount(flags) || current->link_count) { 347 + int status; 441 348 442 - /* 443 - * A zero status is success otherwise we have a 444 - * negative error code. 445 - */ 446 - status = try_to_fill_dentry(dentry, flags); 447 - if (status == 0) 448 - return 1; 349 + /* 350 + * We can only unhash and send this to ->lookup() if 351 + * the directory mutex is held over d_revalidate() and 352 + * ->lookup(). This prevents the VFS from incorrectly 353 + * seeing the dentry as non-existent. 354 + */ 355 + ino->flags |= AUTOFS_INF_PENDING; 356 + if (!mutex_aquired) { 357 + autofs4_revalidate_drop(dentry, entry); 358 + spin_unlock(&dcache_lock); 359 + spin_unlock(&sbi->fs_lock); 360 + return 0; 361 + } 362 + spin_unlock(&dcache_lock); 363 + spin_unlock(&sbi->fs_lock); 364 + mutex_unlock(&dir->i_mutex); 365 + kfree(entry); 449 366 450 - return status; 367 + /* 368 + * A zero status is success otherwise we have a 369 + * negative error code. 370 + */ 371 + status = try_to_fill_dentry(dentry); 372 + 373 + spin_lock(&sbi->fs_lock); 374 + ino->flags &= ~AUTOFS_INF_PENDING; 375 + spin_unlock(&sbi->fs_lock); 376 + 377 + if (status == 0) 378 + return 1; 379 + 380 + return status; 381 + } 451 382 } 452 383 spin_unlock(&dcache_lock); 384 + spin_unlock(&sbi->fs_lock); 385 + 386 + if (mutex_aquired) 387 + mutex_unlock(&dir->i_mutex); 388 + 389 + kfree(entry); 453 390 454 391 return 1; 392 + } 393 + 394 + static void autofs4_free_rehash_entrys(struct autofs_info *inf) 395 + { 396 + struct list_head *head = &inf->rehash_list; 397 + struct rehash_entry *entry, *next; 398 + list_for_each_entry_safe(entry, next, head, list) { 399 + list_del(&entry->list); 400 + kfree(entry); 401 + } 455 402 } 456 403 457 404 void autofs4_dentry_release(struct dentry *de) ··· 509 382 list_del(&inf->active); 510 383 if (!list_empty(&inf->expiring)) 511 384 list_del(&inf->expiring); 385 + if (!list_empty(&inf->rehash_list)) 386 + autofs4_free_rehash_entrys(inf); 512 387 spin_unlock(&sbi->lookup_lock); 513 388 } 514 389 ··· 543 414 const unsigned char *str = name->name; 544 415 struct list_head *p, *head; 545 416 417 + restart: 546 418 spin_lock(&dcache_lock); 547 419 spin_lock(&sbi->lookup_lock); 548 420 head = &sbi->active_list; ··· 561 431 if (atomic_read(&active->d_count) == 0) 562 432 goto next; 563 433 434 + if (active->d_inode && IS_DEADDIR(active->d_inode)) { 435 + if (!list_empty(&ino->rehash_list)) { 436 + dget(active); 437 + spin_unlock(&active->d_lock); 438 + spin_unlock(&sbi->lookup_lock); 439 + spin_unlock(&dcache_lock); 440 + autofs4_remove_rehash_entrys(ino); 441 + dput(active); 442 + goto restart; 443 + } 444 + goto next; 445 + } 446 + 564 447 qstr = &active->d_name; 565 448 566 449 if (active->d_name.hash != hash) ··· 586 443 if (memcmp(qstr->name, str, len)) 587 444 goto next; 588 445 589 - if (d_unhashed(active)) { 590 - dget(active); 591 - spin_unlock(&active->d_lock); 592 - spin_unlock(&sbi->lookup_lock); 593 - spin_unlock(&dcache_lock); 594 - return active; 595 - } 446 + dget(active); 447 + spin_unlock(&active->d_lock); 448 + spin_unlock(&sbi->lookup_lock); 449 + spin_unlock(&dcache_lock); 450 + return active; 596 451 next: 597 452 spin_unlock(&active->d_lock); 598 453 } ··· 639 498 if (memcmp(qstr->name, str, len)) 640 499 goto next; 641 500 642 - if (d_unhashed(expiring)) { 643 - dget(expiring); 644 - spin_unlock(&expiring->d_lock); 645 - spin_unlock(&sbi->lookup_lock); 646 - spin_unlock(&dcache_lock); 647 - return expiring; 648 - } 501 + dget(expiring); 502 + spin_unlock(&expiring->d_lock); 503 + spin_unlock(&sbi->lookup_lock); 504 + spin_unlock(&dcache_lock); 505 + return expiring; 649 506 next: 650 507 spin_unlock(&expiring->d_lock); 651 508 } ··· 653 514 return NULL; 654 515 } 655 516 517 + static struct autofs_info *init_new_dentry(struct autofs_sb_info *sbi, 518 + struct dentry *dentry, int oz_mode) 519 + { 520 + struct autofs_info *ino; 521 + 522 + /* 523 + * Mark the dentry incomplete but don't hash it. We do this 524 + * to serialize our inode creation operations (symlink and 525 + * mkdir) which prevents deadlock during the callback to 526 + * the daemon. Subsequent user space lookups for the same 527 + * dentry are placed on the wait queue while the daemon 528 + * itself is allowed passage unresticted so the create 529 + * operation itself can then hash the dentry. Finally, 530 + * we check for the hashed dentry and return the newly 531 + * hashed dentry. 532 + */ 533 + dentry->d_op = &autofs4_root_dentry_operations; 534 + 535 + /* 536 + * And we need to ensure that the same dentry is used for 537 + * all following lookup calls until it is hashed so that 538 + * the dentry flags are persistent throughout the request. 539 + */ 540 + ino = autofs4_init_ino(NULL, sbi, 0555); 541 + if (!ino) 542 + return ERR_PTR(-ENOMEM); 543 + 544 + dentry->d_fsdata = ino; 545 + ino->dentry = dentry; 546 + 547 + /* 548 + * Only set the mount pending flag for new dentrys not created 549 + * by the daemon. 550 + */ 551 + if (!oz_mode) 552 + ino->flags |= AUTOFS_INF_PENDING; 553 + 554 + d_instantiate(dentry, NULL); 555 + 556 + return ino; 557 + } 558 + 656 559 /* Lookups in the root directory */ 657 560 static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) 658 561 { ··· 702 521 struct autofs_info *ino; 703 522 struct dentry *expiring, *active; 704 523 int oz_mode; 524 + int status = 0; 705 525 706 526 DPRINTK("name = %.*s", 707 527 dentry->d_name.len, dentry->d_name.name); ··· 717 535 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", 718 536 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode); 719 537 538 + spin_lock(&sbi->fs_lock); 720 539 active = autofs4_lookup_active(dentry); 721 540 if (active) { 722 541 dentry = active; 723 542 ino = autofs4_dentry_ino(dentry); 543 + /* If this came from revalidate, rehash it */ 544 + autofs4_revalidate_rehash(dentry); 545 + spin_unlock(&sbi->fs_lock); 724 546 } else { 725 - /* 726 - * Mark the dentry incomplete but don't hash it. We do this 727 - * to serialize our inode creation operations (symlink and 728 - * mkdir) which prevents deadlock during the callback to 729 - * the daemon. Subsequent user space lookups for the same 730 - * dentry are placed on the wait queue while the daemon 731 - * itself is allowed passage unresticted so the create 732 - * operation itself can then hash the dentry. Finally, 733 - * we check for the hashed dentry and return the newly 734 - * hashed dentry. 735 - */ 736 - dentry->d_op = &autofs4_root_dentry_operations; 737 - 738 - /* 739 - * And we need to ensure that the same dentry is used for 740 - * all following lookup calls until it is hashed so that 741 - * the dentry flags are persistent throughout the request. 742 - */ 743 - ino = autofs4_init_ino(NULL, sbi, 0555); 744 - if (!ino) 745 - return ERR_PTR(-ENOMEM); 746 - 747 - dentry->d_fsdata = ino; 748 - ino->dentry = dentry; 749 - 750 - autofs4_add_active(dentry); 751 - 752 - d_instantiate(dentry, NULL); 547 + spin_unlock(&sbi->fs_lock); 548 + ino = init_new_dentry(sbi, dentry, oz_mode); 549 + if (IS_ERR(ino)) 550 + return (struct dentry *) ino; 753 551 } 754 552 553 + autofs4_add_active(dentry); 554 + 755 555 if (!oz_mode) { 756 - mutex_unlock(&dir->i_mutex); 757 556 expiring = autofs4_lookup_expiring(dentry); 557 + mutex_unlock(&dir->i_mutex); 758 558 if (expiring) { 759 559 /* 760 560 * If we are racing with expire the request might not ··· 744 580 * so it must have been successful, so just wait for it. 745 581 */ 746 582 autofs4_expire_wait(expiring); 747 - autofs4_del_expiring(expiring); 748 583 dput(expiring); 749 584 } 750 - 751 - spin_lock(&sbi->fs_lock); 752 - ino->flags |= AUTOFS_INF_PENDING; 753 - spin_unlock(&sbi->fs_lock); 754 - if (dentry->d_op && dentry->d_op->d_revalidate) 755 - (dentry->d_op->d_revalidate)(dentry, nd); 585 + status = try_to_fill_dentry(dentry); 756 586 mutex_lock(&dir->i_mutex); 587 + spin_lock(&sbi->fs_lock); 588 + ino->flags &= ~AUTOFS_INF_PENDING; 589 + spin_unlock(&sbi->fs_lock); 757 590 } 758 591 592 + autofs4_del_active(dentry); 593 + 759 594 /* 760 - * If we are still pending, check if we had to handle 595 + * If we had a mount fail, check if we had to handle 761 596 * a signal. If so we can force a restart.. 762 597 */ 763 - if (ino->flags & AUTOFS_INF_PENDING) { 598 + if (status) { 764 599 /* See if we were interrupted */ 765 600 if (signal_pending(current)) { 766 601 sigset_t *sigset = &current->pending.signal; ··· 771 608 return ERR_PTR(-ERESTARTNOINTR); 772 609 } 773 610 } 774 - if (!oz_mode) { 775 - spin_lock(&sbi->fs_lock); 776 - ino->flags &= ~AUTOFS_INF_PENDING; 777 - spin_unlock(&sbi->fs_lock); 611 + } 612 + 613 + /* 614 + * User space can (and has done in the past) remove and re-create 615 + * this directory during the callback. This can leave us with an 616 + * unhashed dentry, but a successful mount! So we need to 617 + * perform another cached lookup in case the dentry now exists. 618 + */ 619 + if (!oz_mode && !have_submounts(dentry)) { 620 + struct dentry *new; 621 + new = d_lookup(dentry->d_parent, &dentry->d_name); 622 + if (new) { 623 + if (active) 624 + dput(active); 625 + return new; 626 + } else { 627 + if (!status) 628 + status = -ENOENT; 778 629 } 779 630 } 780 631 781 632 /* 782 - * If this dentry is unhashed, then we shouldn't honour this 783 - * lookup. Returning ENOENT here doesn't do the right thing 784 - * for all system calls, but it should be OK for the operations 785 - * we permit from an autofs. 633 + * If we had a mount failure, return status to user space. 634 + * If the mount succeeded and we used a dentry from the active queue 635 + * return it. 786 636 */ 787 - if (!oz_mode && d_unhashed(dentry)) { 788 - /* 789 - * A user space application can (and has done in the past) 790 - * remove and re-create this directory during the callback. 791 - * This can leave us with an unhashed dentry, but a 792 - * successful mount! So we need to perform another 793 - * cached lookup in case the dentry now exists. 794 - */ 795 - struct dentry *parent = dentry->d_parent; 796 - struct dentry *new = d_lookup(parent, &dentry->d_name); 797 - if (new != NULL) 798 - dentry = new; 799 - else 800 - dentry = ERR_PTR(-ENOENT); 801 - 637 + if (status) { 638 + dentry = ERR_PTR(status); 802 639 if (active) 803 640 dput(active); 804 - 805 641 return dentry; 642 + } else { 643 + /* 644 + * Valid successful mount, return active dentry or NULL 645 + * for a new dentry. 646 + */ 647 + if (active) 648 + return active; 806 649 } 807 - 808 - if (active) 809 - return active; 810 650 811 651 return NULL; 812 652 } ··· 833 667 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555); 834 668 if (!ino) 835 669 return -ENOMEM; 836 - 837 - autofs4_del_active(dentry); 838 670 839 671 ino->size = strlen(symname); 840 672 cp = kmalloc(ino->size + 1, GFP_KERNEL); ··· 910 746 dir->i_mtime = CURRENT_TIME; 911 747 912 748 spin_lock(&dcache_lock); 913 - autofs4_add_expiring(dentry); 914 749 spin_lock(&dentry->d_lock); 915 750 __d_drop(dentry); 916 751 spin_unlock(&dentry->d_lock); ··· 935 772 spin_unlock(&dcache_lock); 936 773 return -ENOTEMPTY; 937 774 } 938 - autofs4_add_expiring(dentry); 939 775 spin_lock(&dentry->d_lock); 940 776 __d_drop(dentry); 941 777 spin_unlock(&dentry->d_lock); ··· 971 809 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555); 972 810 if (!ino) 973 811 return -ENOMEM; 974 - 975 - autofs4_del_active(dentry); 976 812 977 813 inode = autofs4_get_inode(dir->i_sb, ino); 978 814 if (!inode) {