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