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/mason/linux-btrfs

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
btrfs: rename the option to nospace_cache
Btrfs: handle bio_add_page failure gracefully in scrub
Btrfs: fix deadlock caused by the race between relocation
Btrfs: only map pages if we know we need them when reading the space cache
Btrfs: fix orphan backref nodes
Btrfs: Abstract similar code for btrfs_block_rsv_add{, _noflush}
Btrfs: fix unreleased path in btrfs_orphan_cleanup()
Btrfs: fix no reserved space for writing out inode cache
Btrfs: fix nocow when deleting the item
Btrfs: tweak the delayed inode reservations again
Btrfs: rework error handling in btrfs_mount()
Btrfs: close devices on all error paths in open_ctree()
Btrfs: avoid null dereference and leaks when bailing from open_ctree()
Btrfs: fix subvol_name leak on error in btrfs_mount()
Btrfs: fix memory leak in btrfs_parse_early_options()
Btrfs: fix our reservations for updating an inode when completing io
Btrfs: fix oops on NULL trans handle in btrfs_truncate
btrfs: fix double-free 'tree_root' in 'btrfs_mount()'

+263 -146
+1 -3
fs/btrfs/btrfs_inode.h
··· 147 147 * the btrfs file release call will add this inode to the 148 148 * ordered operations list so that we make sure to flush out any 149 149 * new data the application may have written before commit. 150 - * 151 - * yes, its silly to have a single bitflag, but we might grow more 152 - * of these. 153 150 */ 154 151 unsigned ordered_data_close:1; 155 152 unsigned orphan_meta_reserved:1; 156 153 unsigned dummy_inode:1; 157 154 unsigned in_defrag:1; 155 + unsigned delalloc_meta_reserved:1; 158 156 159 157 /* 160 158 * always compress this one file
+57 -1
fs/btrfs/delayed-inode.c
··· 617 617 static int btrfs_delayed_inode_reserve_metadata( 618 618 struct btrfs_trans_handle *trans, 619 619 struct btrfs_root *root, 620 + struct inode *inode, 620 621 struct btrfs_delayed_node *node) 621 622 { 622 623 struct btrfs_block_rsv *src_rsv; 623 624 struct btrfs_block_rsv *dst_rsv; 624 625 u64 num_bytes; 625 626 int ret; 627 + int release = false; 626 628 627 629 src_rsv = trans->block_rsv; 628 630 dst_rsv = &root->fs_info->delayed_block_rsv; ··· 654 652 if (!ret) 655 653 node->bytes_reserved = num_bytes; 656 654 return ret; 655 + } else if (src_rsv == &root->fs_info->delalloc_block_rsv) { 656 + spin_lock(&BTRFS_I(inode)->lock); 657 + if (BTRFS_I(inode)->delalloc_meta_reserved) { 658 + BTRFS_I(inode)->delalloc_meta_reserved = 0; 659 + spin_unlock(&BTRFS_I(inode)->lock); 660 + release = true; 661 + goto migrate; 662 + } 663 + spin_unlock(&BTRFS_I(inode)->lock); 664 + 665 + /* Ok we didn't have space pre-reserved. This shouldn't happen 666 + * too often but it can happen if we do delalloc to an existing 667 + * inode which gets dirtied because of the time update, and then 668 + * isn't touched again until after the transaction commits and 669 + * then we try to write out the data. First try to be nice and 670 + * reserve something strictly for us. If not be a pain and try 671 + * to steal from the delalloc block rsv. 672 + */ 673 + ret = btrfs_block_rsv_add_noflush(root, dst_rsv, num_bytes); 674 + if (!ret) 675 + goto out; 676 + 677 + ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes); 678 + if (!ret) 679 + goto out; 680 + 681 + /* 682 + * Ok this is a problem, let's just steal from the global rsv 683 + * since this really shouldn't happen that often. 684 + */ 685 + WARN_ON(1); 686 + ret = btrfs_block_rsv_migrate(&root->fs_info->global_block_rsv, 687 + dst_rsv, num_bytes); 688 + goto out; 657 689 } 658 690 691 + migrate: 659 692 ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes); 693 + 694 + out: 695 + /* 696 + * Migrate only takes a reservation, it doesn't touch the size of the 697 + * block_rsv. This is to simplify people who don't normally have things 698 + * migrated from their block rsv. If they go to release their 699 + * reservation, that will decrease the size as well, so if migrate 700 + * reduced size we'd end up with a negative size. But for the 701 + * delalloc_meta_reserved stuff we will only know to drop 1 reservation, 702 + * but we could in fact do this reserve/migrate dance several times 703 + * between the time we did the original reservation and we'd clean it 704 + * up. So to take care of this, release the space for the meta 705 + * reservation here. I think it may be time for a documentation page on 706 + * how block rsvs. work. 707 + */ 660 708 if (!ret) 661 709 node->bytes_reserved = num_bytes; 710 + 711 + if (release) 712 + btrfs_block_rsv_release(root, src_rsv, num_bytes); 662 713 663 714 return ret; 664 715 } ··· 1763 1708 goto release_node; 1764 1709 } 1765 1710 1766 - ret = btrfs_delayed_inode_reserve_metadata(trans, root, delayed_node); 1711 + ret = btrfs_delayed_inode_reserve_metadata(trans, root, inode, 1712 + delayed_node); 1767 1713 if (ret) 1768 1714 goto release_node; 1769 1715
+18 -24
fs/btrfs/disk-io.c
··· 1890 1890 u64 features; 1891 1891 struct btrfs_key location; 1892 1892 struct buffer_head *bh; 1893 - struct btrfs_root *extent_root = kzalloc(sizeof(struct btrfs_root), 1894 - GFP_NOFS); 1895 - struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root), 1896 - GFP_NOFS); 1893 + struct btrfs_super_block *disk_super; 1897 1894 struct btrfs_root *tree_root = btrfs_sb(sb); 1898 - struct btrfs_fs_info *fs_info = NULL; 1899 - struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), 1900 - GFP_NOFS); 1901 - struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root), 1902 - GFP_NOFS); 1895 + struct btrfs_fs_info *fs_info = tree_root->fs_info; 1896 + struct btrfs_root *extent_root; 1897 + struct btrfs_root *csum_root; 1898 + struct btrfs_root *chunk_root; 1899 + struct btrfs_root *dev_root; 1903 1900 struct btrfs_root *log_tree_root; 1904 - 1905 1901 int ret; 1906 1902 int err = -EINVAL; 1907 1903 int num_backups_tried = 0; 1908 1904 int backup_index = 0; 1909 1905 1910 - struct btrfs_super_block *disk_super; 1906 + extent_root = fs_info->extent_root = 1907 + kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 1908 + csum_root = fs_info->csum_root = 1909 + kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 1910 + chunk_root = fs_info->chunk_root = 1911 + kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 1912 + dev_root = fs_info->dev_root = 1913 + kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 1911 1914 1912 - if (!extent_root || !tree_root || !tree_root->fs_info || 1913 - !chunk_root || !dev_root || !csum_root) { 1915 + if (!extent_root || !csum_root || !chunk_root || !dev_root) { 1914 1916 err = -ENOMEM; 1915 1917 goto fail; 1916 1918 } 1917 - fs_info = tree_root->fs_info; 1918 1919 1919 1920 ret = init_srcu_struct(&fs_info->subvol_srcu); 1920 1921 if (ret) { ··· 1955 1954 mutex_init(&fs_info->reloc_mutex); 1956 1955 1957 1956 init_completion(&fs_info->kobj_unregister); 1958 - fs_info->tree_root = tree_root; 1959 - fs_info->extent_root = extent_root; 1960 - fs_info->csum_root = csum_root; 1961 - fs_info->chunk_root = chunk_root; 1962 - fs_info->dev_root = dev_root; 1963 - fs_info->fs_devices = fs_devices; 1964 1957 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); 1965 1958 INIT_LIST_HEAD(&fs_info->space_info); 1966 1959 btrfs_mapping_init(&fs_info->mapping_tree); ··· 2460 2465 btrfs_stop_workers(&fs_info->caching_workers); 2461 2466 fail_alloc: 2462 2467 fail_iput: 2468 + btrfs_mapping_tree_free(&fs_info->mapping_tree); 2469 + 2463 2470 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); 2464 2471 iput(fs_info->btree_inode); 2465 - 2466 - btrfs_close_devices(fs_info->fs_devices); 2467 - btrfs_mapping_tree_free(&fs_info->mapping_tree); 2468 2472 fail_bdi: 2469 2473 bdi_destroy(&fs_info->bdi); 2470 2474 fail_srcu: 2471 2475 cleanup_srcu_struct(&fs_info->subvol_srcu); 2472 2476 fail: 2477 + btrfs_close_devices(fs_info->fs_devices); 2473 2478 free_fs_info(fs_info); 2474 2479 return ERR_PTR(err); 2475 2480 2476 2481 recovery_tree_root: 2477 - 2478 2482 if (!btrfs_test_opt(tree_root, RECOVERY)) 2479 2483 goto fail_tree_roots; 2480 2484
+32 -20
fs/btrfs/extent-tree.c
··· 3797 3797 kfree(rsv); 3798 3798 } 3799 3799 3800 - int btrfs_block_rsv_add(struct btrfs_root *root, 3801 - struct btrfs_block_rsv *block_rsv, 3802 - u64 num_bytes) 3800 + static inline int __block_rsv_add(struct btrfs_root *root, 3801 + struct btrfs_block_rsv *block_rsv, 3802 + u64 num_bytes, int flush) 3803 3803 { 3804 3804 int ret; 3805 3805 3806 3806 if (num_bytes == 0) 3807 3807 return 0; 3808 3808 3809 - ret = reserve_metadata_bytes(root, block_rsv, num_bytes, 1); 3809 + ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); 3810 3810 if (!ret) { 3811 3811 block_rsv_add_bytes(block_rsv, num_bytes, 1); 3812 3812 return 0; ··· 3815 3815 return ret; 3816 3816 } 3817 3817 3818 + int btrfs_block_rsv_add(struct btrfs_root *root, 3819 + struct btrfs_block_rsv *block_rsv, 3820 + u64 num_bytes) 3821 + { 3822 + return __block_rsv_add(root, block_rsv, num_bytes, 1); 3823 + } 3824 + 3818 3825 int btrfs_block_rsv_add_noflush(struct btrfs_root *root, 3819 3826 struct btrfs_block_rsv *block_rsv, 3820 3827 u64 num_bytes) 3821 3828 { 3822 - int ret; 3823 - 3824 - if (num_bytes == 0) 3825 - return 0; 3826 - 3827 - ret = reserve_metadata_bytes(root, block_rsv, num_bytes, 0); 3828 - if (!ret) { 3829 - block_rsv_add_bytes(block_rsv, num_bytes, 1); 3830 - return 0; 3831 - } 3832 - 3833 - return ret; 3829 + return __block_rsv_add(root, block_rsv, num_bytes, 0); 3834 3830 } 3835 3831 3836 3832 int btrfs_block_rsv_check(struct btrfs_root *root, ··· 4060 4064 */ 4061 4065 static unsigned drop_outstanding_extent(struct inode *inode) 4062 4066 { 4067 + unsigned drop_inode_space = 0; 4063 4068 unsigned dropped_extents = 0; 4064 4069 4065 4070 BUG_ON(!BTRFS_I(inode)->outstanding_extents); 4066 4071 BTRFS_I(inode)->outstanding_extents--; 4072 + 4073 + if (BTRFS_I(inode)->outstanding_extents == 0 && 4074 + BTRFS_I(inode)->delalloc_meta_reserved) { 4075 + drop_inode_space = 1; 4076 + BTRFS_I(inode)->delalloc_meta_reserved = 0; 4077 + } 4067 4078 4068 4079 /* 4069 4080 * If we have more or the same amount of outsanding extents than we have ··· 4078 4075 */ 4079 4076 if (BTRFS_I(inode)->outstanding_extents >= 4080 4077 BTRFS_I(inode)->reserved_extents) 4081 - return 0; 4078 + return drop_inode_space; 4082 4079 4083 4080 dropped_extents = BTRFS_I(inode)->reserved_extents - 4084 4081 BTRFS_I(inode)->outstanding_extents; 4085 4082 BTRFS_I(inode)->reserved_extents -= dropped_extents; 4086 - return dropped_extents; 4083 + return dropped_extents + drop_inode_space; 4087 4084 } 4088 4085 4089 4086 /** ··· 4169 4166 nr_extents = BTRFS_I(inode)->outstanding_extents - 4170 4167 BTRFS_I(inode)->reserved_extents; 4171 4168 BTRFS_I(inode)->reserved_extents += nr_extents; 4172 - 4173 - to_reserve = btrfs_calc_trans_metadata_size(root, nr_extents); 4174 4169 } 4170 + 4171 + /* 4172 + * Add an item to reserve for updating the inode when we complete the 4173 + * delalloc io. 4174 + */ 4175 + if (!BTRFS_I(inode)->delalloc_meta_reserved) { 4176 + nr_extents++; 4177 + BTRFS_I(inode)->delalloc_meta_reserved = 1; 4178 + } 4179 + 4180 + to_reserve = btrfs_calc_trans_metadata_size(root, nr_extents); 4175 4181 to_reserve += calc_csum_metadata_size(inode, num_bytes, 1); 4176 4182 spin_unlock(&BTRFS_I(inode)->lock); 4177 4183
+10 -7
fs/btrfs/free-space-cache.c
··· 537 537 struct btrfs_free_space *entry, u8 *type) 538 538 { 539 539 struct btrfs_free_space_entry *e; 540 + int ret; 541 + 542 + if (!io_ctl->cur) { 543 + ret = io_ctl_check_crc(io_ctl, io_ctl->index); 544 + if (ret) 545 + return ret; 546 + } 540 547 541 548 e = io_ctl->cur; 542 549 entry->offset = le64_to_cpu(e->offset); ··· 557 550 558 551 io_ctl_unmap_page(io_ctl); 559 552 560 - if (io_ctl->index >= io_ctl->num_pages) 561 - return 0; 562 - 563 - return io_ctl_check_crc(io_ctl, io_ctl->index); 553 + return 0; 564 554 } 565 555 566 556 static int io_ctl_read_bitmap(struct io_ctl *io_ctl, 567 557 struct btrfs_free_space *entry) 568 558 { 569 559 int ret; 570 - 571 - if (io_ctl->cur && io_ctl->cur != io_ctl->orig) 572 - io_ctl_unmap_page(io_ctl); 573 560 574 561 ret = io_ctl_check_crc(io_ctl, io_ctl->index); 575 562 if (ret) ··· 699 698 700 699 num_entries--; 701 700 } 701 + 702 + io_ctl_unmap_page(&io_ctl); 702 703 703 704 /* 704 705 * We add the bitmaps at the end of the entries in order that
+24 -4
fs/btrfs/inode-map.c
··· 398 398 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; 399 399 struct btrfs_path *path; 400 400 struct inode *inode; 401 + struct btrfs_block_rsv *rsv; 402 + u64 num_bytes; 401 403 u64 alloc_hint = 0; 402 404 int ret; 403 405 int prealloc; ··· 423 421 if (!path) 424 422 return -ENOMEM; 425 423 424 + rsv = trans->block_rsv; 425 + trans->block_rsv = &root->fs_info->trans_block_rsv; 426 + 427 + num_bytes = trans->bytes_reserved; 428 + /* 429 + * 1 item for inode item insertion if need 430 + * 3 items for inode item update (in the worst case) 431 + * 1 item for free space object 432 + * 3 items for pre-allocation 433 + */ 434 + trans->bytes_reserved = btrfs_calc_trans_metadata_size(root, 8); 435 + ret = btrfs_block_rsv_add_noflush(root, trans->block_rsv, 436 + trans->bytes_reserved); 437 + if (ret) 438 + goto out; 426 439 again: 427 440 inode = lookup_free_ino_inode(root, path); 428 441 if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) { 429 442 ret = PTR_ERR(inode); 430 - goto out; 443 + goto out_release; 431 444 } 432 445 433 446 if (IS_ERR(inode)) { ··· 451 434 452 435 ret = create_free_ino_inode(root, trans, path); 453 436 if (ret) 454 - goto out; 437 + goto out_release; 455 438 goto again; 456 439 } 457 440 ··· 494 477 } 495 478 btrfs_free_reserved_data_space(inode, prealloc); 496 479 480 + ret = btrfs_write_out_ino_cache(root, trans, path); 497 481 out_put: 498 482 iput(inode); 483 + out_release: 484 + btrfs_block_rsv_release(root, trans->block_rsv, trans->bytes_reserved); 499 485 out: 500 - if (ret == 0) 501 - ret = btrfs_write_out_ino_cache(root, trans, path); 486 + trans->block_rsv = rsv; 487 + trans->bytes_reserved = num_bytes; 502 488 503 489 btrfs_free_path(path); 504 490 return ret;
+57 -27
fs/btrfs/inode.c
··· 93 93 struct page *locked_page, 94 94 u64 start, u64 end, int *page_started, 95 95 unsigned long *nr_written, int unlock); 96 + static noinline int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans, 97 + struct btrfs_root *root, struct inode *inode); 96 98 97 99 static int btrfs_init_inode_security(struct btrfs_trans_handle *trans, 98 100 struct inode *inode, struct inode *dir, ··· 1743 1741 trans = btrfs_join_transaction(root); 1744 1742 BUG_ON(IS_ERR(trans)); 1745 1743 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 1746 - ret = btrfs_update_inode(trans, root, inode); 1744 + ret = btrfs_update_inode_fallback(trans, root, inode); 1747 1745 BUG_ON(ret); 1748 1746 } 1749 1747 goto out; ··· 1793 1791 1794 1792 ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent); 1795 1793 if (!ret || !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) { 1796 - ret = btrfs_update_inode(trans, root, inode); 1794 + ret = btrfs_update_inode_fallback(trans, root, inode); 1797 1795 BUG_ON(ret); 1798 1796 } 1799 1797 ret = 0; ··· 2201 2199 if (ret) 2202 2200 goto out; 2203 2201 } 2202 + /* release the path since we're done with it */ 2203 + btrfs_release_path(path); 2204 + 2204 2205 root->orphan_cleanup_state = ORPHAN_CLEANUP_DONE; 2205 2206 2206 2207 if (root->orphan_block_rsv) ··· 2431 2426 /* 2432 2427 * copy everything in the in-memory inode into the btree. 2433 2428 */ 2434 - noinline int btrfs_update_inode(struct btrfs_trans_handle *trans, 2429 + static noinline int btrfs_update_inode_item(struct btrfs_trans_handle *trans, 2435 2430 struct btrfs_root *root, struct inode *inode) 2436 2431 { 2437 2432 struct btrfs_inode_item *inode_item; 2438 2433 struct btrfs_path *path; 2439 2434 struct extent_buffer *leaf; 2440 2435 int ret; 2441 - 2442 - /* 2443 - * If the inode is a free space inode, we can deadlock during commit 2444 - * if we put it into the delayed code. 2445 - * 2446 - * The data relocation inode should also be directly updated 2447 - * without delay 2448 - */ 2449 - if (!btrfs_is_free_space_inode(root, inode) 2450 - && root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID) { 2451 - ret = btrfs_delayed_update_inode(trans, root, inode); 2452 - if (!ret) 2453 - btrfs_set_inode_last_trans(trans, inode); 2454 - return ret; 2455 - } 2456 2436 2457 2437 path = btrfs_alloc_path(); 2458 2438 if (!path) ··· 2463 2473 ret = 0; 2464 2474 failed: 2465 2475 btrfs_free_path(path); 2476 + return ret; 2477 + } 2478 + 2479 + /* 2480 + * copy everything in the in-memory inode into the btree. 2481 + */ 2482 + noinline int btrfs_update_inode(struct btrfs_trans_handle *trans, 2483 + struct btrfs_root *root, struct inode *inode) 2484 + { 2485 + int ret; 2486 + 2487 + /* 2488 + * If the inode is a free space inode, we can deadlock during commit 2489 + * if we put it into the delayed code. 2490 + * 2491 + * The data relocation inode should also be directly updated 2492 + * without delay 2493 + */ 2494 + if (!btrfs_is_free_space_inode(root, inode) 2495 + && root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID) { 2496 + ret = btrfs_delayed_update_inode(trans, root, inode); 2497 + if (!ret) 2498 + btrfs_set_inode_last_trans(trans, inode); 2499 + return ret; 2500 + } 2501 + 2502 + return btrfs_update_inode_item(trans, root, inode); 2503 + } 2504 + 2505 + static noinline int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans, 2506 + struct btrfs_root *root, struct inode *inode) 2507 + { 2508 + int ret; 2509 + 2510 + ret = btrfs_update_inode(trans, root, inode); 2511 + if (ret == -ENOSPC) 2512 + return btrfs_update_inode_item(trans, root, inode); 2466 2513 return ret; 2467 2514 } 2468 2515 ··· 5659 5632 if (test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) { 5660 5633 ret = btrfs_ordered_update_i_size(inode, 0, ordered); 5661 5634 if (!ret) 5662 - err = btrfs_update_inode(trans, root, inode); 5635 + err = btrfs_update_inode_fallback(trans, root, inode); 5663 5636 goto out; 5664 5637 } 5665 5638 ··· 5697 5670 add_pending_csums(trans, inode, ordered->file_offset, &ordered->list); 5698 5671 ret = btrfs_ordered_update_i_size(inode, 0, ordered); 5699 5672 if (!ret || !test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags)) 5700 - btrfs_update_inode(trans, root, inode); 5673 + btrfs_update_inode_fallback(trans, root, inode); 5701 5674 ret = 0; 5702 5675 out_unlock: 5703 5676 unlock_extent_cached(&BTRFS_I(inode)->io_tree, ordered->file_offset, ··· 6556 6529 ret = btrfs_orphan_del(NULL, inode); 6557 6530 } 6558 6531 6559 - trans->block_rsv = &root->fs_info->trans_block_rsv; 6560 - ret = btrfs_update_inode(trans, root, inode); 6561 - if (ret && !err) 6562 - err = ret; 6532 + if (trans) { 6533 + trans->block_rsv = &root->fs_info->trans_block_rsv; 6534 + ret = btrfs_update_inode(trans, root, inode); 6535 + if (ret && !err) 6536 + err = ret; 6563 6537 6564 - nr = trans->blocks_used; 6565 - ret = btrfs_end_transaction_throttle(trans, root); 6566 - btrfs_btree_balance_dirty(root, nr); 6538 + nr = trans->blocks_used; 6539 + ret = btrfs_end_transaction_throttle(trans, root); 6540 + btrfs_btree_balance_dirty(root, nr); 6541 + } 6567 6542 6568 6543 out: 6569 6544 btrfs_free_block_rsv(root, rsv); ··· 6634 6605 ei->orphan_meta_reserved = 0; 6635 6606 ei->dummy_inode = 0; 6636 6607 ei->in_defrag = 0; 6608 + ei->delalloc_meta_reserved = 0; 6637 6609 ei->force_compress = BTRFS_COMPRESS_NONE; 6638 6610 6639 6611 ei->delayed_node = NULL;
+2
fs/btrfs/relocation.c
··· 1174 1174 list_add_tail(&new_edge->list[UPPER], 1175 1175 &new_node->lower); 1176 1176 } 1177 + } else { 1178 + list_add_tail(&new_node->lower, &cache->leaves); 1177 1179 } 1178 1180 1179 1181 rb_node = tree_insert(&cache->rb_root, new_node->bytenr,
+29 -35
fs/btrfs/scrub.c
··· 944 944 static int scrub_submit(struct scrub_dev *sdev) 945 945 { 946 946 struct scrub_bio *sbio; 947 - struct bio *bio; 948 - int i; 949 947 950 948 if (sdev->curr == -1) 951 949 return 0; 952 950 953 951 sbio = sdev->bios[sdev->curr]; 954 - 955 - bio = bio_alloc(GFP_NOFS, sbio->count); 956 - if (!bio) 957 - goto nomem; 958 - 959 - bio->bi_private = sbio; 960 - bio->bi_end_io = scrub_bio_end_io; 961 - bio->bi_bdev = sdev->dev->bdev; 962 - bio->bi_sector = sbio->physical >> 9; 963 - 964 - for (i = 0; i < sbio->count; ++i) { 965 - struct page *page; 966 - int ret; 967 - 968 - page = alloc_page(GFP_NOFS); 969 - if (!page) 970 - goto nomem; 971 - 972 - ret = bio_add_page(bio, page, PAGE_SIZE, 0); 973 - if (!ret) { 974 - __free_page(page); 975 - goto nomem; 976 - } 977 - } 978 - 979 952 sbio->err = 0; 980 953 sdev->curr = -1; 981 954 atomic_inc(&sdev->in_flight); 982 955 983 - submit_bio(READ, bio); 956 + submit_bio(READ, sbio->bio); 984 957 985 958 return 0; 986 - 987 - nomem: 988 - scrub_free_bio(bio); 989 - 990 - return -ENOMEM; 991 959 } 992 960 993 961 static int scrub_page(struct scrub_dev *sdev, u64 logical, u64 len, ··· 963 995 u8 *csum, int force) 964 996 { 965 997 struct scrub_bio *sbio; 998 + struct page *page; 999 + int ret; 966 1000 967 1001 again: 968 1002 /* ··· 985 1015 } 986 1016 sbio = sdev->bios[sdev->curr]; 987 1017 if (sbio->count == 0) { 1018 + struct bio *bio; 1019 + 988 1020 sbio->physical = physical; 989 1021 sbio->logical = logical; 1022 + bio = bio_alloc(GFP_NOFS, SCRUB_PAGES_PER_BIO); 1023 + if (!bio) 1024 + return -ENOMEM; 1025 + 1026 + bio->bi_private = sbio; 1027 + bio->bi_end_io = scrub_bio_end_io; 1028 + bio->bi_bdev = sdev->dev->bdev; 1029 + bio->bi_sector = sbio->physical >> 9; 1030 + sbio->err = 0; 1031 + sbio->bio = bio; 990 1032 } else if (sbio->physical + sbio->count * PAGE_SIZE != physical || 991 1033 sbio->logical + sbio->count * PAGE_SIZE != logical) { 992 - int ret; 993 - 994 1034 ret = scrub_submit(sdev); 995 1035 if (ret) 996 1036 return ret; ··· 1010 1030 sbio->spag[sbio->count].generation = gen; 1011 1031 sbio->spag[sbio->count].have_csum = 0; 1012 1032 sbio->spag[sbio->count].mirror_num = mirror_num; 1033 + 1034 + page = alloc_page(GFP_NOFS); 1035 + if (!page) 1036 + return -ENOMEM; 1037 + 1038 + ret = bio_add_page(sbio->bio, page, PAGE_SIZE, 0); 1039 + if (!ret) { 1040 + __free_page(page); 1041 + ret = scrub_submit(sdev); 1042 + if (ret) 1043 + return ret; 1044 + goto again; 1045 + } 1046 + 1013 1047 if (csum) { 1014 1048 sbio->spag[sbio->count].have_csum = 1; 1015 1049 memcpy(sbio->spag[sbio->count].csum, csum, sdev->csum_size);
+27 -22
fs/btrfs/super.c
··· 197 197 {Opt_subvolrootid, "subvolrootid=%d"}, 198 198 {Opt_defrag, "autodefrag"}, 199 199 {Opt_inode_cache, "inode_cache"}, 200 - {Opt_no_space_cache, "no_space_cache"}, 200 + {Opt_no_space_cache, "nospace_cache"}, 201 201 {Opt_recovery, "recovery"}, 202 202 {Opt_err, NULL}, 203 203 }; ··· 448 448 token = match_token(p, tokens, args); 449 449 switch (token) { 450 450 case Opt_subvol: 451 + kfree(*subvol_name); 451 452 *subvol_name = match_strdup(&args[0]); 452 453 break; 453 454 case Opt_subvolid: ··· 711 710 if (btrfs_test_opt(root, SPACE_CACHE)) 712 711 seq_puts(seq, ",space_cache"); 713 712 else 714 - seq_puts(seq, ",no_space_cache"); 713 + seq_puts(seq, ",nospace_cache"); 715 714 if (btrfs_test_opt(root, CLEAR_CACHE)) 716 715 seq_puts(seq, ",clear_cache"); 717 716 if (btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED)) ··· 891 890 struct super_block *s; 892 891 struct dentry *root; 893 892 struct btrfs_fs_devices *fs_devices = NULL; 894 - struct btrfs_root *tree_root = NULL; 895 893 struct btrfs_fs_info *fs_info = NULL; 896 894 fmode_t mode = FMODE_READ; 897 895 char *subvol_name = NULL; ··· 904 904 error = btrfs_parse_early_options(data, mode, fs_type, 905 905 &subvol_name, &subvol_objectid, 906 906 &subvol_rootid, &fs_devices); 907 - if (error) 907 + if (error) { 908 + kfree(subvol_name); 908 909 return ERR_PTR(error); 910 + } 909 911 910 912 if (subvol_name) { 911 913 root = mount_subvol(subvol_name, flags, device_name, data); ··· 919 917 if (error) 920 918 return ERR_PTR(error); 921 919 922 - error = btrfs_open_devices(fs_devices, mode, fs_type); 923 - if (error) 924 - return ERR_PTR(error); 925 - 926 - if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) { 927 - error = -EACCES; 928 - goto error_close_devices; 929 - } 930 - 931 920 /* 932 921 * Setup a dummy root and fs_info for test/set super. This is because 933 922 * we don't actually fill this stuff out until open_ctree, but we need ··· 926 933 * then open_ctree will properly initialize everything later. 927 934 */ 928 935 fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS); 929 - tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 930 - if (!fs_info || !tree_root) { 936 + if (!fs_info) 937 + return ERR_PTR(-ENOMEM); 938 + 939 + fs_info->tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 940 + if (!fs_info->tree_root) { 931 941 error = -ENOMEM; 932 - goto error_close_devices; 942 + goto error_fs_info; 933 943 } 934 - fs_info->tree_root = tree_root; 944 + fs_info->tree_root->fs_info = fs_info; 935 945 fs_info->fs_devices = fs_devices; 936 - tree_root->fs_info = fs_info; 937 946 938 947 fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS); 939 948 fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS); 940 949 if (!fs_info->super_copy || !fs_info->super_for_commit) { 941 950 error = -ENOMEM; 951 + goto error_fs_info; 952 + } 953 + 954 + error = btrfs_open_devices(fs_devices, mode, fs_type); 955 + if (error) 956 + goto error_fs_info; 957 + 958 + if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) { 959 + error = -EACCES; 942 960 goto error_close_devices; 943 961 } 944 962 945 963 bdev = fs_devices->latest_bdev; 946 - s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root); 964 + s = sget(fs_type, btrfs_test_super, btrfs_set_super, 965 + fs_info->tree_root); 947 966 if (IS_ERR(s)) { 948 967 error = PTR_ERR(s); 949 968 goto error_close_devices; ··· 964 959 if (s->s_root) { 965 960 if ((flags ^ s->s_flags) & MS_RDONLY) { 966 961 deactivate_locked_super(s); 967 - return ERR_PTR(-EBUSY); 962 + error = -EBUSY; 963 + goto error_close_devices; 968 964 } 969 965 970 966 btrfs_close_devices(fs_devices); 971 967 free_fs_info(fs_info); 972 - kfree(tree_root); 973 968 } else { 974 969 char b[BDEVNAME_SIZE]; 975 970 ··· 996 991 997 992 error_close_devices: 998 993 btrfs_close_devices(fs_devices); 994 + error_fs_info: 999 995 free_fs_info(fs_info); 1000 - kfree(tree_root); 1001 996 return ERR_PTR(error); 1002 997 } 1003 998
+2 -2
fs/btrfs/transaction.c
··· 882 882 btrfs_reloc_pre_snapshot(trans, pending, &to_reserve); 883 883 884 884 if (to_reserve > 0) { 885 - ret = btrfs_block_rsv_add(root, &pending->block_rsv, 886 - to_reserve); 885 + ret = btrfs_block_rsv_add_noflush(root, &pending->block_rsv, 886 + to_reserve); 887 887 if (ret) { 888 888 pending->error = ret; 889 889 goto fail;
+4 -1
fs/btrfs/volumes.c
··· 999 999 key.objectid = device->devid; 1000 1000 key.offset = start; 1001 1001 key.type = BTRFS_DEV_EXTENT_KEY; 1002 - 1002 + again: 1003 1003 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 1004 1004 if (ret > 0) { 1005 1005 ret = btrfs_previous_item(root, path, key.objectid, ··· 1012 1012 struct btrfs_dev_extent); 1013 1013 BUG_ON(found_key.offset > start || found_key.offset + 1014 1014 btrfs_dev_extent_length(leaf, extent) < start); 1015 + key = found_key; 1016 + btrfs_release_path(path); 1017 + goto again; 1015 1018 } else if (ret == 0) { 1016 1019 leaf = path->nodes[0]; 1017 1020 extent = btrfs_item_ptr(leaf, path->slots[0],