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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull vfs fixes from Al Viro:
"Assorted fixes + unifying __d_move() and __d_materialise_dentry() +
minimal regression fix for d_path() of victims of overwriting rename()
ported on top of that"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
vfs: Don't exchange "short" filenames unconditionally.
fold swapping ->d_name.hash into switch_names()
fold unlocking the children into dentry_unlock_parents_for_move()
kill __d_materialise_dentry()
__d_materialise_dentry(): flip the order of arguments
__d_move(): fold manipulations with ->d_child/->d_subdirs
don't open-code d_rehash() in d_materialise_unique()
pull rehashing and unlocking the target dentry into __d_materialise_dentry()
ufs: deal with nfsd/iget races
fuse: honour max_read and max_write in direct_io mode
shmem: fix nlink for rename overwrite directory

+60 -85
+36 -76
fs/dcache.c
··· 2372 } 2373 EXPORT_SYMBOL(dentry_update_name_case); 2374 2375 - static void switch_names(struct dentry *dentry, struct dentry *target) 2376 { 2377 if (dname_external(target)) { 2378 if (dname_external(dentry)) { ··· 2407 */ 2408 unsigned int i; 2409 BUILD_BUG_ON(!IS_ALIGNED(DNAME_INLINE_LEN, sizeof(long))); 2410 for (i = 0; i < DNAME_INLINE_LEN / sizeof(long); i++) { 2411 swap(((long *) &dentry->d_iname)[i], 2412 ((long *) &target->d_iname)[i]); 2413 } 2414 } 2415 } 2416 - swap(dentry->d_name.len, target->d_name.len); 2417 } 2418 2419 static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target) ··· 2449 } 2450 } 2451 2452 - static void dentry_unlock_parents_for_move(struct dentry *dentry, 2453 - struct dentry *target) 2454 { 2455 if (target->d_parent != dentry->d_parent) 2456 spin_unlock(&dentry->d_parent->d_lock); 2457 if (target->d_parent != target) 2458 spin_unlock(&target->d_parent->d_lock); 2459 } 2460 2461 /* 2462 * When switching names, the actual string doesn't strictly have to 2463 * be preserved in the target - because we're dropping the target 2464 * anyway. As such, we can just do a simple memcpy() to copy over 2465 - * the new name before we switch. 2466 - * 2467 - * Note that we have to be a lot more careful about getting the hash 2468 - * switched - we have to switch the hash value properly even if it 2469 - * then no longer matches the actual (corrupted) string of the target. 2470 - * The hash value has to match the hash queue that the dentry is on.. 2471 */ 2472 /* 2473 * __d_move - move a dentry ··· 2517 d_hash(dentry->d_parent, dentry->d_name.hash)); 2518 } 2519 2520 - list_del(&dentry->d_u.d_child); 2521 - list_del(&target->d_u.d_child); 2522 - 2523 /* Switch the names.. */ 2524 - switch_names(dentry, target); 2525 - swap(dentry->d_name.hash, target->d_name.hash); 2526 2527 - /* ... and switch the parents */ 2528 if (IS_ROOT(dentry)) { 2529 dentry->d_parent = target->d_parent; 2530 target->d_parent = target; 2531 - INIT_LIST_HEAD(&target->d_u.d_child); 2532 } else { 2533 swap(dentry->d_parent, target->d_parent); 2534 - 2535 - /* And add them back to the (new) parent lists */ 2536 - list_add(&target->d_u.d_child, &target->d_parent->d_subdirs); 2537 } 2538 - 2539 - list_add(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); 2540 2541 write_seqcount_end(&target->d_seq); 2542 write_seqcount_end(&dentry->d_seq); 2543 2544 - dentry_unlock_parents_for_move(dentry, target); 2545 - if (exchange) 2546 - fsnotify_d_move(target); 2547 - spin_unlock(&target->d_lock); 2548 - fsnotify_d_move(dentry); 2549 - spin_unlock(&dentry->d_lock); 2550 } 2551 2552 /* ··· 2638 return ret; 2639 } 2640 2641 - /* 2642 - * Prepare an anonymous dentry for life in the superblock's dentry tree as a 2643 - * named dentry in place of the dentry to be replaced. 2644 - * returns with anon->d_lock held! 2645 - */ 2646 - static void __d_materialise_dentry(struct dentry *dentry, struct dentry *anon) 2647 - { 2648 - struct dentry *dparent; 2649 - 2650 - dentry_lock_for_move(anon, dentry); 2651 - 2652 - write_seqcount_begin(&dentry->d_seq); 2653 - write_seqcount_begin_nested(&anon->d_seq, DENTRY_D_LOCK_NESTED); 2654 - 2655 - dparent = dentry->d_parent; 2656 - 2657 - switch_names(dentry, anon); 2658 - swap(dentry->d_name.hash, anon->d_name.hash); 2659 - 2660 - dentry->d_parent = dentry; 2661 - list_del_init(&dentry->d_u.d_child); 2662 - anon->d_parent = dparent; 2663 - if (likely(!d_unhashed(anon))) { 2664 - hlist_bl_lock(&anon->d_sb->s_anon); 2665 - __hlist_bl_del(&anon->d_hash); 2666 - anon->d_hash.pprev = NULL; 2667 - hlist_bl_unlock(&anon->d_sb->s_anon); 2668 - } 2669 - list_move(&anon->d_u.d_child, &dparent->d_subdirs); 2670 - 2671 - write_seqcount_end(&dentry->d_seq); 2672 - write_seqcount_end(&anon->d_seq); 2673 - 2674 - dentry_unlock_parents_for_move(anon, dentry); 2675 - spin_unlock(&dentry->d_lock); 2676 - 2677 - /* anon->d_lock still locked, returns locked */ 2678 - } 2679 - 2680 /** 2681 * d_splice_alias - splice a disconnected dentry into the tree if one exists 2682 * @inode: the inode which may have a disconnected dentry ··· 2683 return ERR_PTR(-EIO); 2684 } 2685 write_seqlock(&rename_lock); 2686 - __d_materialise_dentry(dentry, new); 2687 write_sequnlock(&rename_lock); 2688 - _d_rehash(new); 2689 - spin_unlock(&new->d_lock); 2690 spin_unlock(&inode->i_lock); 2691 security_d_instantiate(new, inode); 2692 iput(inode); ··· 2744 } else if (IS_ROOT(alias)) { 2745 /* Is this an anonymous mountpoint that we 2746 * could splice into our tree? */ 2747 - __d_materialise_dentry(dentry, alias); 2748 write_sequnlock(&rename_lock); 2749 goto found; 2750 } else { ··· 2771 actual = __d_instantiate_unique(dentry, inode); 2772 if (!actual) 2773 actual = dentry; 2774 - else 2775 - BUG_ON(!d_unhashed(actual)); 2776 2777 - spin_lock(&actual->d_lock); 2778 found: 2779 - _d_rehash(actual); 2780 - spin_unlock(&actual->d_lock); 2781 spin_unlock(&inode->i_lock); 2782 out_nolock: 2783 if (actual == dentry) {
··· 2372 } 2373 EXPORT_SYMBOL(dentry_update_name_case); 2374 2375 + static void switch_names(struct dentry *dentry, struct dentry *target, 2376 + bool exchange) 2377 { 2378 if (dname_external(target)) { 2379 if (dname_external(dentry)) { ··· 2406 */ 2407 unsigned int i; 2408 BUILD_BUG_ON(!IS_ALIGNED(DNAME_INLINE_LEN, sizeof(long))); 2409 + if (!exchange) { 2410 + memcpy(dentry->d_iname, target->d_name.name, 2411 + target->d_name.len + 1); 2412 + dentry->d_name.hash_len = target->d_name.hash_len; 2413 + return; 2414 + } 2415 for (i = 0; i < DNAME_INLINE_LEN / sizeof(long); i++) { 2416 swap(((long *) &dentry->d_iname)[i], 2417 ((long *) &target->d_iname)[i]); 2418 } 2419 } 2420 } 2421 + swap(dentry->d_name.hash_len, target->d_name.hash_len); 2422 } 2423 2424 static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target) ··· 2442 } 2443 } 2444 2445 + static void dentry_unlock_for_move(struct dentry *dentry, struct dentry *target) 2446 { 2447 if (target->d_parent != dentry->d_parent) 2448 spin_unlock(&dentry->d_parent->d_lock); 2449 if (target->d_parent != target) 2450 spin_unlock(&target->d_parent->d_lock); 2451 + spin_unlock(&target->d_lock); 2452 + spin_unlock(&dentry->d_lock); 2453 } 2454 2455 /* 2456 * When switching names, the actual string doesn't strictly have to 2457 * be preserved in the target - because we're dropping the target 2458 * anyway. As such, we can just do a simple memcpy() to copy over 2459 + * the new name before we switch, unless we are going to rehash 2460 + * it. Note that if we *do* unhash the target, we are not allowed 2461 + * to rehash it without giving it a new name/hash key - whether 2462 + * we swap or overwrite the names here, resulting name won't match 2463 + * the reality in filesystem; it's only there for d_path() purposes. 2464 + * Note that all of this is happening under rename_lock, so the 2465 + * any hash lookup seeing it in the middle of manipulations will 2466 + * be discarded anyway. So we do not care what happens to the hash 2467 + * key in that case. 2468 */ 2469 /* 2470 * __d_move - move a dentry ··· 2506 d_hash(dentry->d_parent, dentry->d_name.hash)); 2507 } 2508 2509 /* Switch the names.. */ 2510 + switch_names(dentry, target, exchange); 2511 2512 + /* ... and switch them in the tree */ 2513 if (IS_ROOT(dentry)) { 2514 + /* splicing a tree */ 2515 dentry->d_parent = target->d_parent; 2516 target->d_parent = target; 2517 + list_del_init(&target->d_u.d_child); 2518 + list_move(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); 2519 } else { 2520 + /* swapping two dentries */ 2521 swap(dentry->d_parent, target->d_parent); 2522 + list_move(&target->d_u.d_child, &target->d_parent->d_subdirs); 2523 + list_move(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); 2524 + if (exchange) 2525 + fsnotify_d_move(target); 2526 + fsnotify_d_move(dentry); 2527 } 2528 2529 write_seqcount_end(&target->d_seq); 2530 write_seqcount_end(&dentry->d_seq); 2531 2532 + dentry_unlock_for_move(dentry, target); 2533 } 2534 2535 /* ··· 2633 return ret; 2634 } 2635 2636 /** 2637 * d_splice_alias - splice a disconnected dentry into the tree if one exists 2638 * @inode: the inode which may have a disconnected dentry ··· 2717 return ERR_PTR(-EIO); 2718 } 2719 write_seqlock(&rename_lock); 2720 + __d_move(new, dentry, false); 2721 write_sequnlock(&rename_lock); 2722 spin_unlock(&inode->i_lock); 2723 security_d_instantiate(new, inode); 2724 iput(inode); ··· 2780 } else if (IS_ROOT(alias)) { 2781 /* Is this an anonymous mountpoint that we 2782 * could splice into our tree? */ 2783 + __d_move(alias, dentry, false); 2784 write_sequnlock(&rename_lock); 2785 goto found; 2786 } else { ··· 2807 actual = __d_instantiate_unique(dentry, inode); 2808 if (!actual) 2809 actual = dentry; 2810 2811 + d_rehash(actual); 2812 found: 2813 spin_unlock(&inode->i_lock); 2814 out_nolock: 2815 if (actual == dentry) {
+1 -1
fs/direct-io.c
··· 158 { 159 ssize_t ret; 160 161 - ret = iov_iter_get_pages(sdio->iter, dio->pages, DIO_PAGES, 162 &sdio->from); 163 164 if (ret < 0 && sdio->blocks_available && (dio->rw & WRITE)) {
··· 158 { 159 ssize_t ret; 160 161 + ret = iov_iter_get_pages(sdio->iter, dio->pages, LONG_MAX, DIO_PAGES, 162 &sdio->from); 163 164 if (ret < 0 && sdio->blocks_available && (dio->rw & WRITE)) {
+1
fs/fuse/file.c
··· 1305 size_t start; 1306 ssize_t ret = iov_iter_get_pages(ii, 1307 &req->pages[req->num_pages], 1308 req->max_pages - req->num_pages, 1309 &start); 1310 if (ret < 0)
··· 1305 size_t start; 1306 ssize_t ret = iov_iter_get_pages(ii, 1307 &req->pages[req->num_pages], 1308 + *nbytesp - nbytes, 1309 req->max_pages - req->num_pages, 1310 &start); 1311 if (ret < 0)
+5 -1
fs/ufs/ialloc.c
··· 298 ufsi->i_oeftflag = 0; 299 ufsi->i_dir_start_lookup = 0; 300 memset(&ufsi->i_u1, 0, sizeof(ufsi->i_u1)); 301 - insert_inode_hash(inode); 302 mark_inode_dirty(inode); 303 304 if (uspi->fs_magic == UFS2_MAGIC) { ··· 340 fail_remove_inode: 341 unlock_ufs(sb); 342 clear_nlink(inode); 343 iput(inode); 344 UFSD("EXIT (FAILED): err %d\n", err); 345 return ERR_PTR(err);
··· 298 ufsi->i_oeftflag = 0; 299 ufsi->i_dir_start_lookup = 0; 300 memset(&ufsi->i_u1, 0, sizeof(ufsi->i_u1)); 301 + if (insert_inode_locked(inode) < 0) { 302 + err = -EIO; 303 + goto failed; 304 + } 305 mark_inode_dirty(inode); 306 307 if (uspi->fs_magic == UFS2_MAGIC) { ··· 337 fail_remove_inode: 338 unlock_ufs(sb); 339 clear_nlink(inode); 340 + unlock_new_inode(inode); 341 iput(inode); 342 UFSD("EXIT (FAILED): err %d\n", err); 343 return ERR_PTR(err);
+4
fs/ufs/namei.c
··· 38 { 39 int err = ufs_add_link(dentry, inode); 40 if (!err) { 41 d_instantiate(dentry, inode); 42 return 0; 43 } 44 inode_dec_link_count(inode); 45 iput(inode); 46 return err; 47 } ··· 157 158 out_fail: 159 inode_dec_link_count(inode); 160 iput(inode); 161 goto out; 162 } ··· 213 out_fail: 214 inode_dec_link_count(inode); 215 inode_dec_link_count(inode); 216 iput (inode); 217 inode_dec_link_count(dir); 218 unlock_ufs(dir->i_sb);
··· 38 { 39 int err = ufs_add_link(dentry, inode); 40 if (!err) { 41 + unlock_new_inode(inode); 42 d_instantiate(dentry, inode); 43 return 0; 44 } 45 inode_dec_link_count(inode); 46 + unlock_new_inode(inode); 47 iput(inode); 48 return err; 49 } ··· 155 156 out_fail: 157 inode_dec_link_count(inode); 158 + unlock_new_inode(inode); 159 iput(inode); 160 goto out; 161 } ··· 210 out_fail: 211 inode_dec_link_count(inode); 212 inode_dec_link_count(inode); 213 + unlock_new_inode(inode); 214 iput (inode); 215 inode_dec_link_count(dir); 216 unlock_ufs(dir->i_sb);
+1 -1
include/linux/uio.h
··· 84 void iov_iter_init(struct iov_iter *i, int direction, const struct iovec *iov, 85 unsigned long nr_segs, size_t count); 86 ssize_t iov_iter_get_pages(struct iov_iter *i, struct page **pages, 87 - unsigned maxpages, size_t *start); 88 ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, struct page ***pages, 89 size_t maxsize, size_t *start); 90 int iov_iter_npages(const struct iov_iter *i, int maxpages);
··· 84 void iov_iter_init(struct iov_iter *i, int direction, const struct iovec *iov, 85 unsigned long nr_segs, size_t count); 86 ssize_t iov_iter_get_pages(struct iov_iter *i, struct page **pages, 87 + size_t maxsize, unsigned maxpages, size_t *start); 88 ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, struct page ***pages, 89 size_t maxsize, size_t *start); 90 int iov_iter_npages(const struct iov_iter *i, int maxpages);
+9 -5
mm/iov_iter.c
··· 310 EXPORT_SYMBOL(iov_iter_init); 311 312 static ssize_t get_pages_iovec(struct iov_iter *i, 313 - struct page **pages, unsigned maxpages, 314 size_t *start) 315 { 316 size_t offset = i->iov_offset; ··· 323 len = iov->iov_len - offset; 324 if (len > i->count) 325 len = i->count; 326 addr = (unsigned long)iov->iov_base + offset; 327 len += *start = addr & (PAGE_SIZE - 1); 328 if (len > maxpages * PAGE_SIZE) ··· 590 } 591 592 static ssize_t get_pages_bvec(struct iov_iter *i, 593 - struct page **pages, unsigned maxpages, 594 size_t *start) 595 { 596 const struct bio_vec *bvec = i->bvec; 597 size_t len = bvec->bv_len - i->iov_offset; 598 if (len > i->count) 599 len = i->count; 600 /* can't be more than PAGE_SIZE */ 601 *start = bvec->bv_offset + i->iov_offset; 602 ··· 715 EXPORT_SYMBOL(iov_iter_alignment); 716 717 ssize_t iov_iter_get_pages(struct iov_iter *i, 718 - struct page **pages, unsigned maxpages, 719 size_t *start) 720 { 721 if (i->type & ITER_BVEC) 722 - return get_pages_bvec(i, pages, maxpages, start); 723 else 724 - return get_pages_iovec(i, pages, maxpages, start); 725 } 726 EXPORT_SYMBOL(iov_iter_get_pages); 727
··· 310 EXPORT_SYMBOL(iov_iter_init); 311 312 static ssize_t get_pages_iovec(struct iov_iter *i, 313 + struct page **pages, size_t maxsize, unsigned maxpages, 314 size_t *start) 315 { 316 size_t offset = i->iov_offset; ··· 323 len = iov->iov_len - offset; 324 if (len > i->count) 325 len = i->count; 326 + if (len > maxsize) 327 + len = maxsize; 328 addr = (unsigned long)iov->iov_base + offset; 329 len += *start = addr & (PAGE_SIZE - 1); 330 if (len > maxpages * PAGE_SIZE) ··· 588 } 589 590 static ssize_t get_pages_bvec(struct iov_iter *i, 591 + struct page **pages, size_t maxsize, unsigned maxpages, 592 size_t *start) 593 { 594 const struct bio_vec *bvec = i->bvec; 595 size_t len = bvec->bv_len - i->iov_offset; 596 if (len > i->count) 597 len = i->count; 598 + if (len > maxsize) 599 + len = maxsize; 600 /* can't be more than PAGE_SIZE */ 601 *start = bvec->bv_offset + i->iov_offset; 602 ··· 711 EXPORT_SYMBOL(iov_iter_alignment); 712 713 ssize_t iov_iter_get_pages(struct iov_iter *i, 714 + struct page **pages, size_t maxsize, unsigned maxpages, 715 size_t *start) 716 { 717 if (i->type & ITER_BVEC) 718 + return get_pages_bvec(i, pages, maxsize, maxpages, start); 719 else 720 + return get_pages_iovec(i, pages, maxsize, maxpages, start); 721 } 722 EXPORT_SYMBOL(iov_iter_get_pages); 723
+3 -1
mm/shmem.c
··· 2367 2368 if (new_dentry->d_inode) { 2369 (void) shmem_unlink(new_dir, new_dentry); 2370 - if (they_are_dirs) 2371 drop_nlink(old_dir); 2372 } else if (they_are_dirs) { 2373 drop_nlink(old_dir); 2374 inc_nlink(new_dir);
··· 2367 2368 if (new_dentry->d_inode) { 2369 (void) shmem_unlink(new_dir, new_dentry); 2370 + if (they_are_dirs) { 2371 + drop_nlink(new_dentry->d_inode); 2372 drop_nlink(old_dir); 2373 + } 2374 } else if (they_are_dirs) { 2375 drop_nlink(old_dir); 2376 inc_nlink(new_dir);