aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-06-30 23:07:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-06-30 23:07:45 -0400
commit043cd04950431f206f784d1ed9b3fcc5993045f2 (patch)
tree63c3f3c620c6b8a70030185963f2fea7f74e5e86 /fs/btrfs/disk-io.c
parent43baed34bc6b22fdd433b63ec6738f2d28925b1a (diff)
parent5a5003df98d5a7f6834227885b7c9728f767cc27 (diff)
Merge branch 'for-linus-4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs updates from Chris Mason: "Outside of our usual batch of fixes, this integrates the subvolume quota updates that Qu Wenruo from Fujitsu has been working on for a few releases now. He gets an extra gold star for making btrfs smaller this time, and fixing a number of quota corners in the process. Dave Sterba tested and integrated Anand Jain's sysfs improvements. Outside of exporting a symbol (ack'd by Greg) these are all internal to btrfs and it's mostly cleanups and fixes. Anand also attached some of our sysfs objects to our internal device management structs instead of an object off the super block. It will make device management easier overall and it's a better fit for how the sysfs files are used. None of the existing sysfs files are moved around. Thanks for all the fixes everyone" * 'for-linus-4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (87 commits) btrfs: delayed-ref: double free in btrfs_add_delayed_tree_ref() Btrfs: Check if kobject is initialized before put lib: export symbol kobject_move() Btrfs: sysfs: add support to show replacing target in the sysfs Btrfs: free the stale device Btrfs: use received_uuid of parent during send Btrfs: fix use-after-free in btrfs_replay_log btrfs: wait for delayed iputs on no space btrfs: qgroup: Make snapshot accounting work with new extent-oriented qgroup. btrfs: qgroup: Add the ability to skip given qgroup for old/new_roots. btrfs: ulist: Add ulist_del() function. btrfs: qgroup: Cleanup the old ref_node-oriented mechanism. btrfs: qgroup: Switch self test to extent-oriented qgroup mechanism. btrfs: qgroup: Switch to new extent-oriented qgroup mechanism. btrfs: qgroup: Switch rescan to new mechanism. btrfs: qgroup: Add new qgroup calculation function btrfs_qgroup_account_extents(). btrfs: backref: Add special time_seq == (u64)-1 case for btrfs_find_all_roots(). btrfs: qgroup: Add new function to record old_roots. btrfs: qgroup: Record possible quota-related extent for qgroup. btrfs: qgroup: Add function qgroup_update_counters(). ...
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 0bccf18dc1dc..3f43bfea3684 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1149,12 +1149,12 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
1149 1149
1150 buf = btrfs_find_create_tree_block(root, bytenr); 1150 buf = btrfs_find_create_tree_block(root, bytenr);
1151 if (!buf) 1151 if (!buf)
1152 return NULL; 1152 return ERR_PTR(-ENOMEM);
1153 1153
1154 ret = btree_read_extent_buffer_pages(root, buf, 0, parent_transid); 1154 ret = btree_read_extent_buffer_pages(root, buf, 0, parent_transid);
1155 if (ret) { 1155 if (ret) {
1156 free_extent_buffer(buf); 1156 free_extent_buffer(buf);
1157 return NULL; 1157 return ERR_PTR(ret);
1158 } 1158 }
1159 return buf; 1159 return buf;
1160 1160
@@ -1509,20 +1509,19 @@ static struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
1509 generation = btrfs_root_generation(&root->root_item); 1509 generation = btrfs_root_generation(&root->root_item);
1510 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), 1510 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
1511 generation); 1511 generation);
1512 if (!root->node) { 1512 if (IS_ERR(root->node)) {
1513 ret = -ENOMEM; 1513 ret = PTR_ERR(root->node);
1514 goto find_fail; 1514 goto find_fail;
1515 } else if (!btrfs_buffer_uptodate(root->node, generation, 0)) { 1515 } else if (!btrfs_buffer_uptodate(root->node, generation, 0)) {
1516 ret = -EIO; 1516 ret = -EIO;
1517 goto read_fail; 1517 free_extent_buffer(root->node);
1518 goto find_fail;
1518 } 1519 }
1519 root->commit_root = btrfs_root_node(root); 1520 root->commit_root = btrfs_root_node(root);
1520out: 1521out:
1521 btrfs_free_path(path); 1522 btrfs_free_path(path);
1522 return root; 1523 return root;
1523 1524
1524read_fail:
1525 free_extent_buffer(root->node);
1526find_fail: 1525find_fail:
1527 kfree(root); 1526 kfree(root);
1528alloc_fail: 1527alloc_fail:
@@ -2320,8 +2319,12 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
2320 2319
2321 log_tree_root->node = read_tree_block(tree_root, bytenr, 2320 log_tree_root->node = read_tree_block(tree_root, bytenr,
2322 fs_info->generation + 1); 2321 fs_info->generation + 1);
2323 if (!log_tree_root->node || 2322 if (IS_ERR(log_tree_root->node)) {
2324 !extent_buffer_uptodate(log_tree_root->node)) { 2323 printk(KERN_ERR "BTRFS: failed to read log tree\n");
2324 ret = PTR_ERR(log_tree_root->node);
2325 kfree(log_tree_root);
2326 return ret;
2327 } else if (!extent_buffer_uptodate(log_tree_root->node)) {
2325 printk(KERN_ERR "BTRFS: failed to read log tree\n"); 2328 printk(KERN_ERR "BTRFS: failed to read log tree\n");
2326 free_extent_buffer(log_tree_root->node); 2329 free_extent_buffer(log_tree_root->node);
2327 kfree(log_tree_root); 2330 kfree(log_tree_root);
@@ -2494,7 +2497,6 @@ int open_ctree(struct super_block *sb,
2494 seqlock_init(&fs_info->profiles_lock); 2497 seqlock_init(&fs_info->profiles_lock);
2495 init_rwsem(&fs_info->delayed_iput_sem); 2498 init_rwsem(&fs_info->delayed_iput_sem);
2496 2499
2497 init_completion(&fs_info->kobj_unregister);
2498 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); 2500 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots);
2499 INIT_LIST_HEAD(&fs_info->space_info); 2501 INIT_LIST_HEAD(&fs_info->space_info);
2500 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); 2502 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
@@ -2797,8 +2799,8 @@ int open_ctree(struct super_block *sb,
2797 chunk_root->node = read_tree_block(chunk_root, 2799 chunk_root->node = read_tree_block(chunk_root,
2798 btrfs_super_chunk_root(disk_super), 2800 btrfs_super_chunk_root(disk_super),
2799 generation); 2801 generation);
2800 if (!chunk_root->node || 2802 if (IS_ERR(chunk_root->node) ||
2801 !test_bit(EXTENT_BUFFER_UPTODATE, &chunk_root->node->bflags)) { 2803 !extent_buffer_uptodate(chunk_root->node)) {
2802 printk(KERN_ERR "BTRFS: failed to read chunk root on %s\n", 2804 printk(KERN_ERR "BTRFS: failed to read chunk root on %s\n",
2803 sb->s_id); 2805 sb->s_id);
2804 goto fail_tree_roots; 2806 goto fail_tree_roots;
@@ -2834,8 +2836,8 @@ retry_root_backup:
2834 tree_root->node = read_tree_block(tree_root, 2836 tree_root->node = read_tree_block(tree_root,
2835 btrfs_super_root(disk_super), 2837 btrfs_super_root(disk_super),
2836 generation); 2838 generation);
2837 if (!tree_root->node || 2839 if (IS_ERR(tree_root->node) ||
2838 !test_bit(EXTENT_BUFFER_UPTODATE, &tree_root->node->bflags)) { 2840 !extent_buffer_uptodate(tree_root->node)) {
2839 printk(KERN_WARNING "BTRFS: failed to read tree root on %s\n", 2841 printk(KERN_WARNING "BTRFS: failed to read tree root on %s\n",
2840 sb->s_id); 2842 sb->s_id);
2841 2843
@@ -2874,10 +2876,22 @@ retry_root_backup:
2874 2876
2875 btrfs_close_extra_devices(fs_devices, 1); 2877 btrfs_close_extra_devices(fs_devices, 1);
2876 2878
2879 ret = btrfs_sysfs_add_fsid(fs_devices, NULL);
2880 if (ret) {
2881 pr_err("BTRFS: failed to init sysfs fsid interface: %d\n", ret);
2882 goto fail_block_groups;
2883 }
2884
2885 ret = btrfs_sysfs_add_device(fs_devices);
2886 if (ret) {
2887 pr_err("BTRFS: failed to init sysfs device interface: %d\n", ret);
2888 goto fail_fsdev_sysfs;
2889 }
2890
2877 ret = btrfs_sysfs_add_one(fs_info); 2891 ret = btrfs_sysfs_add_one(fs_info);
2878 if (ret) { 2892 if (ret) {
2879 pr_err("BTRFS: failed to init sysfs interface: %d\n", ret); 2893 pr_err("BTRFS: failed to init sysfs interface: %d\n", ret);
2880 goto fail_block_groups; 2894 goto fail_fsdev_sysfs;
2881 } 2895 }
2882 2896
2883 ret = btrfs_init_space_info(fs_info); 2897 ret = btrfs_init_space_info(fs_info);
@@ -3055,6 +3069,9 @@ fail_cleaner:
3055fail_sysfs: 3069fail_sysfs:
3056 btrfs_sysfs_remove_one(fs_info); 3070 btrfs_sysfs_remove_one(fs_info);
3057 3071
3072fail_fsdev_sysfs:
3073 btrfs_sysfs_remove_fsid(fs_info->fs_devices);
3074
3058fail_block_groups: 3075fail_block_groups:
3059 btrfs_put_block_group_cache(fs_info); 3076 btrfs_put_block_group_cache(fs_info);
3060 btrfs_free_block_groups(fs_info); 3077 btrfs_free_block_groups(fs_info);
@@ -3725,6 +3742,7 @@ void close_ctree(struct btrfs_root *root)
3725 } 3742 }
3726 3743
3727 btrfs_sysfs_remove_one(fs_info); 3744 btrfs_sysfs_remove_one(fs_info);
3745 btrfs_sysfs_remove_fsid(fs_info->fs_devices);
3728 3746
3729 btrfs_free_fs_roots(fs_info); 3747 btrfs_free_fs_roots(fs_info);
3730 3748
@@ -4053,6 +4071,7 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
4053 4071
4054 while ((node = rb_first(&delayed_refs->href_root)) != NULL) { 4072 while ((node = rb_first(&delayed_refs->href_root)) != NULL) {
4055 struct btrfs_delayed_ref_head *head; 4073 struct btrfs_delayed_ref_head *head;
4074 struct btrfs_delayed_ref_node *tmp;
4056 bool pin_bytes = false; 4075 bool pin_bytes = false;
4057 4076
4058 head = rb_entry(node, struct btrfs_delayed_ref_head, 4077 head = rb_entry(node, struct btrfs_delayed_ref_head,
@@ -4068,11 +4087,10 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
4068 continue; 4087 continue;
4069 } 4088 }
4070 spin_lock(&head->lock); 4089 spin_lock(&head->lock);
4071 while ((node = rb_first(&head->ref_root)) != NULL) { 4090 list_for_each_entry_safe_reverse(ref, tmp, &head->ref_list,
4072 ref = rb_entry(node, struct btrfs_delayed_ref_node, 4091 list) {
4073 rb_node);
4074 ref->in_tree = 0; 4092 ref->in_tree = 0;
4075 rb_erase(&ref->rb_node, &head->ref_root); 4093 list_del(&ref->list);
4076 atomic_dec(&delayed_refs->num_entries); 4094 atomic_dec(&delayed_refs->num_entries);
4077 btrfs_put_delayed_ref(ref); 4095 btrfs_put_delayed_ref(ref);
4078 } 4096 }