Commit 4b1ae27a96d9860e6c4348673e8fb6a0322511fe
1 parent
60b341b778
Exists in
master
and in
4 other branches
Revert "autofs4: always use lookup for lookup"
This reverts commit 213614d583748d00967a91cacd656f417efb36ce. Alas, ->d_revalidate() can't rely on ->lookup() finishing what it's started; if d_alloc() in do_lookup() fails, we are not going to call ->lookup() at all. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 4 changed files with 158 additions and 330 deletions Side-by-side Diff
fs/autofs4/autofs_i.h
... | ... | @@ -60,11 +60,6 @@ |
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 | - | |
68 | 63 | /* Unified info structure. This is pointed to by both the dentry and |
69 | 64 | inode structures. Each file in the filesystem has an instance of this |
70 | 65 | structure. It holds a reference to the dentry, so dentries are never |
... | ... | @@ -81,7 +76,6 @@ |
81 | 76 | |
82 | 77 | struct list_head active; |
83 | 78 | int active_count; |
84 | - struct list_head rehash_list; | |
85 | 79 | |
86 | 80 | struct list_head expiring; |
87 | 81 | |
... | ... | @@ -104,7 +98,6 @@ |
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 */ |
107 | -#define AUTOFS_INF_REHASH (1<<3) /* dentry in transit to ->lookup() */ | |
108 | 101 | |
109 | 102 | struct autofs_wait_queue { |
110 | 103 | wait_queue_head_t queue; |
fs/autofs4/expire.c
... | ... | @@ -279,7 +279,6 @@ |
279 | 279 | root->d_mounted--; |
280 | 280 | } |
281 | 281 | ino->flags |= AUTOFS_INF_EXPIRING; |
282 | - autofs4_add_expiring(root); | |
283 | 282 | init_completion(&ino->expire_complete); |
284 | 283 | spin_unlock(&sbi->fs_lock); |
285 | 284 | return root; |
... | ... | @@ -407,7 +406,6 @@ |
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; |
410 | - autofs4_add_expiring(expired); | |
411 | 409 | init_completion(&ino->expire_complete); |
412 | 410 | spin_unlock(&sbi->fs_lock); |
413 | 411 | spin_lock(&dcache_lock); |
... | ... | @@ -435,7 +433,7 @@ |
435 | 433 | |
436 | 434 | DPRINTK("expire done status=%d", status); |
437 | 435 | |
438 | - if (d_unhashed(dentry) && IS_DEADDIR(dentry->d_inode)) | |
436 | + if (d_unhashed(dentry)) | |
439 | 437 | return -EAGAIN; |
440 | 438 | |
441 | 439 | return status; |
... | ... | @@ -475,7 +473,6 @@ |
475 | 473 | spin_lock(&sbi->fs_lock); |
476 | 474 | ino = autofs4_dentry_ino(dentry); |
477 | 475 | ino->flags &= ~AUTOFS_INF_EXPIRING; |
478 | - autofs4_del_expiring(dentry); | |
479 | 476 | complete_all(&ino->expire_complete); |
480 | 477 | spin_unlock(&sbi->fs_lock); |
481 | 478 | |
... | ... | @@ -506,7 +503,6 @@ |
506 | 503 | ino->flags &= ~AUTOFS_INF_MOUNTPOINT; |
507 | 504 | } |
508 | 505 | ino->flags &= ~AUTOFS_INF_EXPIRING; |
509 | - autofs4_del_expiring(dentry); | |
510 | 506 | complete_all(&ino->expire_complete); |
511 | 507 | spin_unlock(&sbi->fs_lock); |
512 | 508 | dput(dentry); |
fs/autofs4/inode.c
fs/autofs4/root.c
... | ... | @@ -104,99 +104,6 @@ |
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 | - | |
200 | 107 | static unsigned int autofs4_need_mount(unsigned int flags) |
201 | 108 | { |
202 | 109 | unsigned int res = 0; |
... | ... | @@ -236,7 +143,7 @@ |
236 | 143 | return dcache_dir_open(inode, file); |
237 | 144 | } |
238 | 145 | |
239 | -static int try_to_fill_dentry(struct dentry *dentry) | |
146 | +static int try_to_fill_dentry(struct dentry *dentry, int flags) | |
240 | 147 | { |
241 | 148 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
242 | 149 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
243 | 150 | |
244 | 151 | |
245 | 152 | |
246 | 153 | |
... | ... | @@ -249,17 +156,55 @@ |
249 | 156 | * Wait for a pending mount, triggering one if there |
250 | 157 | * isn't one already |
251 | 158 | */ |
252 | - DPRINTK("waiting for mount name=%.*s", | |
253 | - dentry->d_name.len, dentry->d_name.name); | |
159 | + if (dentry->d_inode == NULL) { | |
160 | + DPRINTK("waiting for mount name=%.*s", | |
161 | + dentry->d_name.len, dentry->d_name.name); | |
254 | 162 | |
255 | - status = autofs4_wait(sbi, dentry, NFY_MOUNT); | |
163 | + status = autofs4_wait(sbi, dentry, NFY_MOUNT); | |
256 | 164 | |
257 | - DPRINTK("mount done status=%d", status); | |
165 | + DPRINTK("mount done status=%d", status); | |
258 | 166 | |
259 | - /* Update expiry counter */ | |
260 | - ino->last_used = jiffies; | |
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); | |
261 | 183 | |
262 | - return status; | |
184 | + spin_lock(&sbi->fs_lock); | |
185 | + ino->flags |= AUTOFS_INF_PENDING; | |
186 | + spin_unlock(&sbi->fs_lock); | |
187 | + status = autofs4_wait(sbi, dentry, NFY_MOUNT); | |
188 | + | |
189 | + DPRINTK("mount done status=%d", 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; | |
263 | 208 | } |
264 | 209 | |
265 | 210 | /* For autofs direct mounts the follow link triggers the mount */ |
266 | 211 | |
... | ... | @@ -313,16 +258,10 @@ |
313 | 258 | */ |
314 | 259 | if (ino->flags & AUTOFS_INF_PENDING || |
315 | 260 | (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs))) { |
316 | - ino->flags |= AUTOFS_INF_PENDING; | |
317 | 261 | spin_unlock(&dcache_lock); |
318 | 262 | spin_unlock(&sbi->fs_lock); |
319 | 263 | |
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 | - | |
264 | + status = try_to_fill_dentry(dentry, 0); | |
326 | 265 | if (status) |
327 | 266 | goto out_error; |
328 | 267 | |
329 | 268 | |
330 | 269 | |
331 | 270 | |
332 | 271 | |
333 | 272 | |
334 | 273 | |
... | ... | @@ -361,48 +300,19 @@ |
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 | - struct autofs_info *ino = autofs4_dentry_ino(dentry); | |
365 | - struct rehash_entry *entry; | |
303 | + int oz_mode = autofs4_oz_mode(sbi); | |
366 | 304 | int flags = nd ? nd->flags : 0; |
367 | - unsigned int mutex_aquired; | |
305 | + int status = 1; | |
368 | 306 | |
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 | 307 | /* Pending dentry */ |
308 | + spin_lock(&sbi->fs_lock); | |
385 | 309 | if (autofs4_ispending(dentry)) { |
386 | - int status; | |
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); | |
310 | + /* The daemon never causes a mount to trigger */ | |
402 | 311 | spin_unlock(&sbi->fs_lock); |
403 | - mutex_unlock(&dir->i_mutex); | |
404 | - kfree(entry); | |
405 | 312 | |
313 | + if (oz_mode) | |
314 | + return 1; | |
315 | + | |
406 | 316 | /* |
407 | 317 | * If the directory has gone away due to an expire |
408 | 318 | * we have been called as ->d_revalidate() and so |
409 | 319 | |
410 | 320 | |
411 | 321 | |
412 | 322 | |
413 | 323 | |
414 | 324 | |
415 | 325 | |
416 | 326 | |
417 | 327 | |
418 | 328 | |
... | ... | @@ -415,82 +325,45 @@ |
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); | |
419 | - | |
420 | - spin_lock(&sbi->fs_lock); | |
421 | - ino->flags &= ~AUTOFS_INF_PENDING; | |
422 | - spin_unlock(&sbi->fs_lock); | |
423 | - | |
328 | + status = try_to_fill_dentry(dentry, flags); | |
424 | 329 | if (status == 0) |
425 | 330 | return 1; |
426 | 331 | |
427 | 332 | return status; |
428 | 333 | } |
334 | + spin_unlock(&sbi->fs_lock); | |
429 | 335 | |
336 | + /* Negative dentry.. invalidate if "old" */ | |
337 | + if (dentry->d_inode == NULL) | |
338 | + return 0; | |
339 | + | |
430 | 340 | /* Check for a non-mountpoint directory with no contents */ |
341 | + spin_lock(&dcache_lock); | |
431 | 342 | if (S_ISDIR(dentry->d_inode->i_mode) && |
432 | 343 | !d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) { |
433 | 344 | DPRINTK("dentry=%p %.*s, emptydir", |
434 | 345 | dentry, dentry->d_name.len, dentry->d_name.name); |
346 | + spin_unlock(&dcache_lock); | |
435 | 347 | |
436 | - if (autofs4_need_mount(flags) || current->link_count) { | |
437 | - int status; | |
348 | + /* The daemon never causes a mount to trigger */ | |
349 | + if (oz_mode) | |
350 | + return 1; | |
438 | 351 | |
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); | |
352 | + /* | |
353 | + * A zero status is success otherwise we have a | |
354 | + * negative error code. | |
355 | + */ | |
356 | + status = try_to_fill_dentry(dentry, flags); | |
357 | + if (status == 0) | |
358 | + return 1; | |
456 | 359 | |
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 | - } | |
360 | + return status; | |
472 | 361 | } |
473 | 362 | spin_unlock(&dcache_lock); |
474 | - spin_unlock(&sbi->fs_lock); | |
475 | 363 | |
476 | - if (mutex_aquired) | |
477 | - mutex_unlock(&dir->i_mutex); | |
478 | - | |
479 | - kfree(entry); | |
480 | - | |
481 | 364 | return 1; |
482 | 365 | } |
483 | 366 | |
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 | - | |
494 | 367 | void autofs4_dentry_release(struct dentry *de) |
495 | 368 | { |
496 | 369 | struct autofs_info *inf; |
... | ... | @@ -509,8 +382,6 @@ |
509 | 382 | list_del(&inf->active); |
510 | 383 | if (!list_empty(&inf->expiring)) |
511 | 384 | list_del(&inf->expiring); |
512 | - if (!list_empty(&inf->rehash_list)) | |
513 | - autofs4_free_rehash_entrys(inf); | |
514 | 385 | spin_unlock(&sbi->lookup_lock); |
515 | 386 | } |
516 | 387 | |
... | ... | @@ -543,7 +414,6 @@ |
543 | 414 | const unsigned char *str = name->name; |
544 | 415 | struct list_head *p, *head; |
545 | 416 | |
546 | -restart: | |
547 | 417 | spin_lock(&dcache_lock); |
548 | 418 | spin_lock(&sbi->lookup_lock); |
549 | 419 | head = &sbi->active_list; |
... | ... | @@ -561,19 +431,6 @@ |
561 | 431 | if (atomic_read(&active->d_count) == 0) |
562 | 432 | goto next; |
563 | 433 | |
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 | 434 | qstr = &active->d_name; |
578 | 435 | |
579 | 436 | if (active->d_name.hash != hash) |
... | ... | @@ -586,11 +443,13 @@ |
586 | 443 | if (memcmp(qstr->name, str, len)) |
587 | 444 | goto next; |
588 | 445 | |
589 | - dget(active); | |
590 | - spin_unlock(&active->d_lock); | |
591 | - spin_unlock(&sbi->lookup_lock); | |
592 | - spin_unlock(&dcache_lock); | |
593 | - return active; | |
446 | + if (d_unhashed(active)) { | |
447 | + dget(active); | |
448 | + spin_unlock(&active->d_lock); | |
449 | + spin_unlock(&sbi->lookup_lock); | |
450 | + spin_unlock(&dcache_lock); | |
451 | + return active; | |
452 | + } | |
594 | 453 | next: |
595 | 454 | spin_unlock(&active->d_lock); |
596 | 455 | } |
... | ... | @@ -639,11 +498,13 @@ |
639 | 498 | if (memcmp(qstr->name, str, len)) |
640 | 499 | goto next; |
641 | 500 | |
642 | - dget(expiring); | |
643 | - spin_unlock(&expiring->d_lock); | |
644 | - spin_unlock(&sbi->lookup_lock); | |
645 | - spin_unlock(&dcache_lock); | |
646 | - return expiring; | |
501 | + if (d_unhashed(expiring)) { | |
502 | + dget(expiring); | |
503 | + spin_unlock(&expiring->d_lock); | |
504 | + spin_unlock(&sbi->lookup_lock); | |
505 | + spin_unlock(&dcache_lock); | |
506 | + return expiring; | |
507 | + } | |
647 | 508 | next: |
648 | 509 | spin_unlock(&expiring->d_lock); |
649 | 510 | } |
... | ... | @@ -653,48 +514,6 @@ |
653 | 514 | return NULL; |
654 | 515 | } |
655 | 516 | |
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 | - | |
698 | 517 | /* Lookups in the root directory */ |
699 | 518 | static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
700 | 519 | { |
... | ... | @@ -702,7 +521,6 @@ |
702 | 521 | struct autofs_info *ino; |
703 | 522 | struct dentry *expiring, *active; |
704 | 523 | int oz_mode; |
705 | - int status = 0; | |
706 | 524 | |
707 | 525 | DPRINTK("name = %.*s", |
708 | 526 | dentry->d_name.len, dentry->d_name.name); |
709 | 527 | |
710 | 528 | |
711 | 529 | |
712 | 530 | |
713 | 531 | |
714 | 532 | |
... | ... | @@ -717,26 +535,44 @@ |
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 | |
720 | - spin_lock(&sbi->fs_lock); | |
721 | 538 | active = autofs4_lookup_active(dentry); |
722 | 539 | if (active) { |
723 | 540 | dentry = active; |
724 | 541 | 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 | 542 | } else { |
729 | - spin_unlock(&sbi->fs_lock); | |
730 | - ino = init_new_dentry(sbi, dentry, oz_mode); | |
731 | - if (IS_ERR(ino)) | |
732 | - return (struct dentry *) ino; | |
733 | - } | |
543 | + /* | |
544 | + * Mark the dentry incomplete but don't hash it. We do this | |
545 | + * to serialize our inode creation operations (symlink and | |
546 | + * mkdir) which prevents deadlock during the callback to | |
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; | |
734 | 555 | |
735 | - autofs4_add_active(dentry); | |
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); | |
736 | 564 | |
565 | + dentry->d_fsdata = ino; | |
566 | + ino->dentry = dentry; | |
567 | + | |
568 | + autofs4_add_active(dentry); | |
569 | + | |
570 | + d_instantiate(dentry, NULL); | |
571 | + } | |
572 | + | |
737 | 573 | if (!oz_mode) { |
738 | - expiring = autofs4_lookup_expiring(dentry); | |
739 | 574 | mutex_unlock(&dir->i_mutex); |
575 | + expiring = autofs4_lookup_expiring(dentry); | |
740 | 576 | if (expiring) { |
741 | 577 | /* |
742 | 578 | * If we are racing with expire the request might not |
743 | 579 | |
744 | 580 | |
745 | 581 | |
746 | 582 | |
747 | 583 | |
748 | 584 | |
... | ... | @@ -744,22 +580,23 @@ |
744 | 580 | * so it must have been successful, so just wait for it. |
745 | 581 | */ |
746 | 582 | autofs4_expire_wait(expiring); |
583 | + autofs4_del_expiring(expiring); | |
747 | 584 | dput(expiring); |
748 | 585 | } |
749 | - status = try_to_fill_dentry(dentry); | |
750 | - mutex_lock(&dir->i_mutex); | |
586 | + | |
751 | 587 | spin_lock(&sbi->fs_lock); |
752 | - ino->flags &= ~AUTOFS_INF_PENDING; | |
588 | + ino->flags |= AUTOFS_INF_PENDING; | |
753 | 589 | 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); | |
754 | 593 | } |
755 | 594 | |
756 | - autofs4_del_active(dentry); | |
757 | - | |
758 | 595 | /* |
759 | - * If we had a mount fail, check if we had to handle | |
596 | + * If we are still pending, check if we had to handle | |
760 | 597 | * a signal. If so we can force a restart.. |
761 | 598 | */ |
762 | - if (status) { | |
599 | + if (ino->flags & AUTOFS_INF_PENDING) { | |
763 | 600 | /* See if we were interrupted */ |
764 | 601 | if (signal_pending(current)) { |
765 | 602 | sigset_t *sigset = ¤t->pending.signal; |
766 | 603 | |
767 | 604 | |
768 | 605 | |
769 | 606 | |
770 | 607 | |
771 | 608 | |
... | ... | @@ -771,46 +608,43 @@ |
771 | 608 | return ERR_PTR(-ERESTARTNOINTR); |
772 | 609 | } |
773 | 610 | } |
774 | - } | |
775 | - | |
776 | - /* | |
777 | - * User space can (and has done in the past) remove and re-create | |
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; | |
611 | + if (!oz_mode) { | |
612 | + spin_lock(&sbi->fs_lock); | |
613 | + ino->flags &= ~AUTOFS_INF_PENDING; | |
614 | + spin_unlock(&sbi->fs_lock); | |
792 | 615 | } |
793 | 616 | } |
794 | 617 | |
795 | 618 | /* |
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. | |
619 | + * If this dentry is unhashed, then we shouldn't honour this | |
620 | + * lookup. Returning ENOENT here doesn't do the right thing | |
621 | + * for all system calls, but it should be OK for the operations | |
622 | + * we permit from an autofs. | |
799 | 623 | */ |
800 | - if (status) { | |
801 | - dentry = ERR_PTR(status); | |
802 | - if (active) | |
803 | - dput(active); | |
804 | - return dentry; | |
805 | - } else { | |
624 | + if (!oz_mode && d_unhashed(dentry)) { | |
806 | 625 | /* |
807 | - * Valid successful mount, return active dentry or NULL | |
808 | - * for a new dentry. | |
626 | + * A user space application can (and has done in the past) | |
627 | + * remove and re-create this directory during the callback. | |
628 | + * This can leave us with an unhashed dentry, but a | |
629 | + * successful mount! So we need to perform another | |
630 | + * cached lookup in case the dentry now exists. | |
809 | 631 | */ |
632 | + struct dentry *parent = dentry->d_parent; | |
633 | + struct dentry *new = d_lookup(parent, &dentry->d_name); | |
634 | + if (new != NULL) | |
635 | + dentry = new; | |
636 | + else | |
637 | + dentry = ERR_PTR(-ENOENT); | |
638 | + | |
810 | 639 | if (active) |
811 | - return active; | |
640 | + dput(active); | |
641 | + | |
642 | + return dentry; | |
812 | 643 | } |
813 | 644 | |
645 | + if (active) | |
646 | + return active; | |
647 | + | |
814 | 648 | return NULL; |
815 | 649 | } |
816 | 650 | |
... | ... | @@ -834,6 +668,8 @@ |
834 | 668 | if (!ino) |
835 | 669 | return -ENOMEM; |
836 | 670 | |
671 | + autofs4_del_active(dentry); | |
672 | + | |
837 | 673 | ino->size = strlen(symname); |
838 | 674 | cp = kmalloc(ino->size + 1, GFP_KERNEL); |
839 | 675 | if (!cp) { |
... | ... | @@ -910,6 +746,7 @@ |
910 | 746 | dir->i_mtime = CURRENT_TIME; |
911 | 747 | |
912 | 748 | spin_lock(&dcache_lock); |
749 | + autofs4_add_expiring(dentry); | |
913 | 750 | spin_lock(&dentry->d_lock); |
914 | 751 | __d_drop(dentry); |
915 | 752 | spin_unlock(&dentry->d_lock); |
... | ... | @@ -935,6 +772,7 @@ |
935 | 772 | spin_unlock(&dcache_lock); |
936 | 773 | return -ENOTEMPTY; |
937 | 774 | } |
775 | + autofs4_add_expiring(dentry); | |
938 | 776 | spin_lock(&dentry->d_lock); |
939 | 777 | __d_drop(dentry); |
940 | 778 | spin_unlock(&dentry->d_lock); |
... | ... | @@ -971,6 +809,8 @@ |
971 | 809 | ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555); |
972 | 810 | if (!ino) |
973 | 811 | return -ENOMEM; |
812 | + | |
813 | + autofs4_del_active(dentry); | |
974 | 814 | |
975 | 815 | inode = autofs4_get_inode(dir->i_sb, ino); |
976 | 816 | if (!inode) { |