aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Mason <clm@fb.com>2015-03-25 13:52:48 -0400
committerChris Mason <clm@fb.com>2015-03-25 13:52:48 -0400
commitfc4c3c872f44bf425963feba57eb9c3f8ac2d7eb (patch)
tree0d49c3e4d8f64a4cc0d3f42f37430fc60007e28b
parent9deed229fa8a83bb5cd713b2d2a8e5c022a4b45b (diff)
parenta4f3d2c4efe2628329249b64fd5799468e025b9d (diff)
Merge branch 'cleanups-post-3.19' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux into for-linus-4.1
Signed-off-by: Chris Mason <clm@fb.com> Conflicts: fs/btrfs/disk-io.c
-rw-r--r--fs/btrfs/async-thread.c4
-rw-r--r--fs/btrfs/async-thread.h2
-rw-r--r--fs/btrfs/check-integrity.c5
-rw-r--r--fs/btrfs/compression.c2
-rw-r--r--fs/btrfs/compression.h4
-rw-r--r--fs/btrfs/ctree.c53
-rw-r--r--fs/btrfs/ctree.h3
-rw-r--r--fs/btrfs/delayed-inode.c9
-rw-r--r--fs/btrfs/disk-io.c554
-rw-r--r--fs/btrfs/disk-io.h4
-rw-r--r--fs/btrfs/extent-tree.c10
-rw-r--r--fs/btrfs/extent_io.h2
-rw-r--r--fs/btrfs/file-item.c2
-rw-r--r--fs/btrfs/file.c8
-rw-r--r--fs/btrfs/lzo.c2
-rw-r--r--fs/btrfs/props.c2
-rw-r--r--fs/btrfs/qgroup.c2
-rw-r--r--fs/btrfs/raid56.c13
-rw-r--r--fs/btrfs/scrub.c2
-rw-r--r--fs/btrfs/sysfs.c2
-rw-r--r--fs/btrfs/transaction.c2
-rw-r--r--fs/btrfs/tree-log.c8
-rw-r--r--fs/btrfs/volumes.c34
-rw-r--r--fs/btrfs/volumes.h3
-rw-r--r--fs/btrfs/zlib.c2
25 files changed, 384 insertions, 350 deletions
diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 4dabeb893b7c..df9932b00d08 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -87,7 +87,7 @@ BTRFS_WORK_HELPER(scrubwrc_helper);
87BTRFS_WORK_HELPER(scrubnc_helper); 87BTRFS_WORK_HELPER(scrubnc_helper);
88 88
89static struct __btrfs_workqueue * 89static struct __btrfs_workqueue *
90__btrfs_alloc_workqueue(const char *name, int flags, int max_active, 90__btrfs_alloc_workqueue(const char *name, unsigned int flags, int max_active,
91 int thresh) 91 int thresh)
92{ 92{
93 struct __btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_NOFS); 93 struct __btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_NOFS);
@@ -132,7 +132,7 @@ static inline void
132__btrfs_destroy_workqueue(struct __btrfs_workqueue *wq); 132__btrfs_destroy_workqueue(struct __btrfs_workqueue *wq);
133 133
134struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name, 134struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
135 int flags, 135 unsigned int flags,
136 int max_active, 136 int max_active,
137 int thresh) 137 int thresh)
138{ 138{
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h
index e386c29ef1f6..ec2ee477f8ba 100644
--- a/fs/btrfs/async-thread.h
+++ b/fs/btrfs/async-thread.h
@@ -66,7 +66,7 @@ BTRFS_WORK_HELPER_PROTO(scrubwrc_helper);
66BTRFS_WORK_HELPER_PROTO(scrubnc_helper); 66BTRFS_WORK_HELPER_PROTO(scrubnc_helper);
67 67
68struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name, 68struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
69 int flags, 69 unsigned int flags,
70 int max_active, 70 int max_active,
71 int thresh); 71 int thresh);
72void btrfs_init_work(struct btrfs_work *work, btrfs_work_func_t helper, 72void btrfs_init_work(struct btrfs_work *work, btrfs_work_func_t helper,
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 089d6fac01a7..ce7dec88f4b8 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -3241,8 +3241,5 @@ void btrfsic_unmount(struct btrfs_root *root,
3241 3241
3242 mutex_unlock(&btrfsic_mutex); 3242 mutex_unlock(&btrfsic_mutex);
3243 3243
3244 if (is_vmalloc_addr(state)) 3244 kvfree(state);
3245 vfree(state);
3246 else
3247 kfree(state);
3248} 3245}
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index ecacb7a2d422..ce62324c78e7 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -750,7 +750,7 @@ static int comp_num_workspace[BTRFS_COMPRESS_TYPES];
750static atomic_t comp_alloc_workspace[BTRFS_COMPRESS_TYPES]; 750static atomic_t comp_alloc_workspace[BTRFS_COMPRESS_TYPES];
751static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES]; 751static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES];
752 752
753static struct btrfs_compress_op *btrfs_compress_op[] = { 753static const struct btrfs_compress_op * const btrfs_compress_op[] = {
754 &btrfs_zlib_compress, 754 &btrfs_zlib_compress,
755 &btrfs_lzo_compress, 755 &btrfs_lzo_compress,
756}; 756};
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
index d181f70caae0..13a4dc0436c9 100644
--- a/fs/btrfs/compression.h
+++ b/fs/btrfs/compression.h
@@ -77,7 +77,7 @@ struct btrfs_compress_op {
77 size_t srclen, size_t destlen); 77 size_t srclen, size_t destlen);
78}; 78};
79 79
80extern struct btrfs_compress_op btrfs_zlib_compress; 80extern const struct btrfs_compress_op btrfs_zlib_compress;
81extern struct btrfs_compress_op btrfs_lzo_compress; 81extern const struct btrfs_compress_op btrfs_lzo_compress;
82 82
83#endif 83#endif
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 1c7e913f1a4b..0f11ebc92f02 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1072,7 +1072,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
1072 ret = btrfs_dec_ref(trans, root, buf, 1); 1072 ret = btrfs_dec_ref(trans, root, buf, 1);
1073 BUG_ON(ret); /* -ENOMEM */ 1073 BUG_ON(ret); /* -ENOMEM */
1074 } 1074 }
1075 clean_tree_block(trans, root, buf); 1075 clean_tree_block(trans, root->fs_info, buf);
1076 *last_ref = 1; 1076 *last_ref = 1;
1077 } 1077 }
1078 return 0; 1078 return 0;
@@ -1677,7 +1677,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1677 continue; 1677 continue;
1678 } 1678 }
1679 1679
1680 cur = btrfs_find_tree_block(root, blocknr); 1680 cur = btrfs_find_tree_block(root->fs_info, blocknr);
1681 if (cur) 1681 if (cur)
1682 uptodate = btrfs_buffer_uptodate(cur, gen, 0); 1682 uptodate = btrfs_buffer_uptodate(cur, gen, 0);
1683 else 1683 else
@@ -1942,7 +1942,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
1942 1942
1943 path->locks[level] = 0; 1943 path->locks[level] = 0;
1944 path->nodes[level] = NULL; 1944 path->nodes[level] = NULL;
1945 clean_tree_block(trans, root, mid); 1945 clean_tree_block(trans, root->fs_info, mid);
1946 btrfs_tree_unlock(mid); 1946 btrfs_tree_unlock(mid);
1947 /* once for the path */ 1947 /* once for the path */
1948 free_extent_buffer(mid); 1948 free_extent_buffer(mid);
@@ -1996,7 +1996,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
1996 if (wret < 0 && wret != -ENOSPC) 1996 if (wret < 0 && wret != -ENOSPC)
1997 ret = wret; 1997 ret = wret;
1998 if (btrfs_header_nritems(right) == 0) { 1998 if (btrfs_header_nritems(right) == 0) {
1999 clean_tree_block(trans, root, right); 1999 clean_tree_block(trans, root->fs_info, right);
2000 btrfs_tree_unlock(right); 2000 btrfs_tree_unlock(right);
2001 del_ptr(root, path, level + 1, pslot + 1); 2001 del_ptr(root, path, level + 1, pslot + 1);
2002 root_sub_used(root, right->len); 2002 root_sub_used(root, right->len);
@@ -2040,7 +2040,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
2040 BUG_ON(wret == 1); 2040 BUG_ON(wret == 1);
2041 } 2041 }
2042 if (btrfs_header_nritems(mid) == 0) { 2042 if (btrfs_header_nritems(mid) == 0) {
2043 clean_tree_block(trans, root, mid); 2043 clean_tree_block(trans, root->fs_info, mid);
2044 btrfs_tree_unlock(mid); 2044 btrfs_tree_unlock(mid);
2045 del_ptr(root, path, level + 1, pslot); 2045 del_ptr(root, path, level + 1, pslot);
2046 root_sub_used(root, mid->len); 2046 root_sub_used(root, mid->len);
@@ -2258,7 +2258,7 @@ static void reada_for_search(struct btrfs_root *root,
2258 2258
2259 search = btrfs_node_blockptr(node, slot); 2259 search = btrfs_node_blockptr(node, slot);
2260 blocksize = root->nodesize; 2260 blocksize = root->nodesize;
2261 eb = btrfs_find_tree_block(root, search); 2261 eb = btrfs_find_tree_block(root->fs_info, search);
2262 if (eb) { 2262 if (eb) {
2263 free_extent_buffer(eb); 2263 free_extent_buffer(eb);
2264 return; 2264 return;
@@ -2318,7 +2318,7 @@ static noinline void reada_for_balance(struct btrfs_root *root,
2318 if (slot > 0) { 2318 if (slot > 0) {
2319 block1 = btrfs_node_blockptr(parent, slot - 1); 2319 block1 = btrfs_node_blockptr(parent, slot - 1);
2320 gen = btrfs_node_ptr_generation(parent, slot - 1); 2320 gen = btrfs_node_ptr_generation(parent, slot - 1);
2321 eb = btrfs_find_tree_block(root, block1); 2321 eb = btrfs_find_tree_block(root->fs_info, block1);
2322 /* 2322 /*
2323 * if we get -eagain from btrfs_buffer_uptodate, we 2323 * if we get -eagain from btrfs_buffer_uptodate, we
2324 * don't want to return eagain here. That will loop 2324 * don't want to return eagain here. That will loop
@@ -2331,7 +2331,7 @@ static noinline void reada_for_balance(struct btrfs_root *root,
2331 if (slot + 1 < nritems) { 2331 if (slot + 1 < nritems) {
2332 block2 = btrfs_node_blockptr(parent, slot + 1); 2332 block2 = btrfs_node_blockptr(parent, slot + 1);
2333 gen = btrfs_node_ptr_generation(parent, slot + 1); 2333 gen = btrfs_node_ptr_generation(parent, slot + 1);
2334 eb = btrfs_find_tree_block(root, block2); 2334 eb = btrfs_find_tree_block(root->fs_info, block2);
2335 if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0) 2335 if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0)
2336 block2 = 0; 2336 block2 = 0;
2337 free_extent_buffer(eb); 2337 free_extent_buffer(eb);
@@ -2449,7 +2449,7 @@ read_block_for_search(struct btrfs_trans_handle *trans,
2449 blocknr = btrfs_node_blockptr(b, slot); 2449 blocknr = btrfs_node_blockptr(b, slot);
2450 gen = btrfs_node_ptr_generation(b, slot); 2450 gen = btrfs_node_ptr_generation(b, slot);
2451 2451
2452 tmp = btrfs_find_tree_block(root, blocknr); 2452 tmp = btrfs_find_tree_block(root->fs_info, blocknr);
2453 if (tmp) { 2453 if (tmp) {
2454 /* first we do an atomic uptodate check */ 2454 /* first we do an atomic uptodate check */
2455 if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) { 2455 if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) {
@@ -3125,7 +3125,8 @@ again:
3125 * higher levels 3125 * higher levels
3126 * 3126 *
3127 */ 3127 */
3128static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path, 3128static void fixup_low_keys(struct btrfs_fs_info *fs_info,
3129 struct btrfs_path *path,
3129 struct btrfs_disk_key *key, int level) 3130 struct btrfs_disk_key *key, int level)
3130{ 3131{
3131 int i; 3132 int i;
@@ -3136,7 +3137,7 @@ static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path,
3136 if (!path->nodes[i]) 3137 if (!path->nodes[i])
3137 break; 3138 break;
3138 t = path->nodes[i]; 3139 t = path->nodes[i];
3139 tree_mod_log_set_node_key(root->fs_info, t, tslot, 1); 3140 tree_mod_log_set_node_key(fs_info, t, tslot, 1);
3140 btrfs_set_node_key(t, key, tslot); 3141 btrfs_set_node_key(t, key, tslot);
3141 btrfs_mark_buffer_dirty(path->nodes[i]); 3142 btrfs_mark_buffer_dirty(path->nodes[i]);
3142 if (tslot != 0) 3143 if (tslot != 0)
@@ -3150,7 +3151,8 @@ static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path,
3150 * This function isn't completely safe. It's the caller's responsibility 3151 * This function isn't completely safe. It's the caller's responsibility
3151 * that the new key won't break the order 3152 * that the new key won't break the order
3152 */ 3153 */
3153void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, 3154void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
3155 struct btrfs_path *path,
3154 struct btrfs_key *new_key) 3156 struct btrfs_key *new_key)
3155{ 3157{
3156 struct btrfs_disk_key disk_key; 3158 struct btrfs_disk_key disk_key;
@@ -3172,7 +3174,7 @@ void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path,
3172 btrfs_set_item_key(eb, &disk_key, slot); 3174 btrfs_set_item_key(eb, &disk_key, slot);
3173 btrfs_mark_buffer_dirty(eb); 3175 btrfs_mark_buffer_dirty(eb);
3174 if (slot == 0) 3176 if (slot == 0)
3175 fixup_low_keys(root, path, &disk_key, 1); 3177 fixup_low_keys(fs_info, path, &disk_key, 1);
3176} 3178}
3177 3179
3178/* 3180/*
@@ -3691,7 +3693,7 @@ static noinline int __push_leaf_right(struct btrfs_trans_handle *trans,
3691 if (left_nritems) 3693 if (left_nritems)
3692 btrfs_mark_buffer_dirty(left); 3694 btrfs_mark_buffer_dirty(left);
3693 else 3695 else
3694 clean_tree_block(trans, root, left); 3696 clean_tree_block(trans, root->fs_info, left);
3695 3697
3696 btrfs_mark_buffer_dirty(right); 3698 btrfs_mark_buffer_dirty(right);
3697 3699
@@ -3703,7 +3705,7 @@ static noinline int __push_leaf_right(struct btrfs_trans_handle *trans,
3703 if (path->slots[0] >= left_nritems) { 3705 if (path->slots[0] >= left_nritems) {
3704 path->slots[0] -= left_nritems; 3706 path->slots[0] -= left_nritems;
3705 if (btrfs_header_nritems(path->nodes[0]) == 0) 3707 if (btrfs_header_nritems(path->nodes[0]) == 0)
3706 clean_tree_block(trans, root, path->nodes[0]); 3708 clean_tree_block(trans, root->fs_info, path->nodes[0]);
3707 btrfs_tree_unlock(path->nodes[0]); 3709 btrfs_tree_unlock(path->nodes[0]);
3708 free_extent_buffer(path->nodes[0]); 3710 free_extent_buffer(path->nodes[0]);
3709 path->nodes[0] = right; 3711 path->nodes[0] = right;
@@ -3927,10 +3929,10 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans,
3927 if (right_nritems) 3929 if (right_nritems)
3928 btrfs_mark_buffer_dirty(right); 3930 btrfs_mark_buffer_dirty(right);
3929 else 3931 else
3930 clean_tree_block(trans, root, right); 3932 clean_tree_block(trans, root->fs_info, right);
3931 3933
3932 btrfs_item_key(right, &disk_key, 0); 3934 btrfs_item_key(right, &disk_key, 0);
3933 fixup_low_keys(root, path, &disk_key, 1); 3935 fixup_low_keys(root->fs_info, path, &disk_key, 1);
3934 3936
3935 /* then fixup the leaf pointer in the path */ 3937 /* then fixup the leaf pointer in the path */
3936 if (path->slots[0] < push_items) { 3938 if (path->slots[0] < push_items) {
@@ -4167,6 +4169,7 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans,
4167 int mid; 4169 int mid;
4168 int slot; 4170 int slot;
4169 struct extent_buffer *right; 4171 struct extent_buffer *right;
4172 struct btrfs_fs_info *fs_info = root->fs_info;
4170 int ret = 0; 4173 int ret = 0;
4171 int wret; 4174 int wret;
4172 int split; 4175 int split;
@@ -4270,10 +4273,10 @@ again:
4270 btrfs_set_header_backref_rev(right, BTRFS_MIXED_BACKREF_REV); 4273 btrfs_set_header_backref_rev(right, BTRFS_MIXED_BACKREF_REV);
4271 btrfs_set_header_owner(right, root->root_key.objectid); 4274 btrfs_set_header_owner(right, root->root_key.objectid);
4272 btrfs_set_header_level(right, 0); 4275 btrfs_set_header_level(right, 0);
4273 write_extent_buffer(right, root->fs_info->fsid, 4276 write_extent_buffer(right, fs_info->fsid,
4274 btrfs_header_fsid(), BTRFS_FSID_SIZE); 4277 btrfs_header_fsid(), BTRFS_FSID_SIZE);
4275 4278
4276 write_extent_buffer(right, root->fs_info->chunk_tree_uuid, 4279 write_extent_buffer(right, fs_info->chunk_tree_uuid,
4277 btrfs_header_chunk_tree_uuid(right), 4280 btrfs_header_chunk_tree_uuid(right),
4278 BTRFS_UUID_SIZE); 4281 BTRFS_UUID_SIZE);
4279 4282
@@ -4296,7 +4299,7 @@ again:
4296 path->nodes[0] = right; 4299 path->nodes[0] = right;
4297 path->slots[0] = 0; 4300 path->slots[0] = 0;
4298 if (path->slots[1] == 0) 4301 if (path->slots[1] == 0)
4299 fixup_low_keys(root, path, &disk_key, 1); 4302 fixup_low_keys(fs_info, path, &disk_key, 1);
4300 } 4303 }
4301 btrfs_mark_buffer_dirty(right); 4304 btrfs_mark_buffer_dirty(right);
4302 return ret; 4305 return ret;
@@ -4614,7 +4617,7 @@ void btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path,
4614 btrfs_set_disk_key_offset(&disk_key, offset + size_diff); 4617 btrfs_set_disk_key_offset(&disk_key, offset + size_diff);
4615 btrfs_set_item_key(leaf, &disk_key, slot); 4618 btrfs_set_item_key(leaf, &disk_key, slot);
4616 if (slot == 0) 4619 if (slot == 0)
4617 fixup_low_keys(root, path, &disk_key, 1); 4620 fixup_low_keys(root->fs_info, path, &disk_key, 1);
4618 } 4621 }
4619 4622
4620 item = btrfs_item_nr(slot); 4623 item = btrfs_item_nr(slot);
@@ -4715,7 +4718,7 @@ void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
4715 4718
4716 if (path->slots[0] == 0) { 4719 if (path->slots[0] == 0) {
4717 btrfs_cpu_key_to_disk(&disk_key, cpu_key); 4720 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
4718 fixup_low_keys(root, path, &disk_key, 1); 4721 fixup_low_keys(root->fs_info, path, &disk_key, 1);
4719 } 4722 }
4720 btrfs_unlock_up_safe(path, 1); 4723 btrfs_unlock_up_safe(path, 1);
4721 4724
@@ -4887,7 +4890,7 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path,
4887 struct btrfs_disk_key disk_key; 4890 struct btrfs_disk_key disk_key;
4888 4891
4889 btrfs_node_key(parent, &disk_key, 0); 4892 btrfs_node_key(parent, &disk_key, 0);
4890 fixup_low_keys(root, path, &disk_key, level + 1); 4893 fixup_low_keys(root->fs_info, path, &disk_key, level + 1);
4891 } 4894 }
4892 btrfs_mark_buffer_dirty(parent); 4895 btrfs_mark_buffer_dirty(parent);
4893} 4896}
@@ -4980,7 +4983,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
4980 btrfs_set_header_level(leaf, 0); 4983 btrfs_set_header_level(leaf, 0);
4981 } else { 4984 } else {
4982 btrfs_set_path_blocking(path); 4985 btrfs_set_path_blocking(path);
4983 clean_tree_block(trans, root, leaf); 4986 clean_tree_block(trans, root->fs_info, leaf);
4984 btrfs_del_leaf(trans, root, path, leaf); 4987 btrfs_del_leaf(trans, root, path, leaf);
4985 } 4988 }
4986 } else { 4989 } else {
@@ -4989,7 +4992,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
4989 struct btrfs_disk_key disk_key; 4992 struct btrfs_disk_key disk_key;
4990 4993
4991 btrfs_item_key(leaf, &disk_key, 0); 4994 btrfs_item_key(leaf, &disk_key, 0);
4992 fixup_low_keys(root, path, &disk_key, 1); 4995 fixup_low_keys(root->fs_info, path, &disk_key, 1);
4993 } 4996 }
4994 4997
4995 /* delete the leaf if it is mostly empty */ 4998 /* delete the leaf if it is mostly empty */
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index f8548d669eb6..95944b81ed5c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3488,7 +3488,8 @@ int btrfs_previous_item(struct btrfs_root *root,
3488 int type); 3488 int type);
3489int btrfs_previous_extent_item(struct btrfs_root *root, 3489int btrfs_previous_extent_item(struct btrfs_root *root,
3490 struct btrfs_path *path, u64 min_objectid); 3490 struct btrfs_path *path, u64 min_objectid);
3491void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, 3491void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
3492 struct btrfs_path *path,
3492 struct btrfs_key *new_key); 3493 struct btrfs_key *new_key);
3493struct extent_buffer *btrfs_root_node(struct btrfs_root *root); 3494struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
3494struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root); 3495struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 82f0c7c95474..cde698a07d21 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1383,7 +1383,7 @@ out:
1383 1383
1384 1384
1385static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root, 1385static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root,
1386 struct btrfs_root *root, int nr) 1386 struct btrfs_fs_info *fs_info, int nr)
1387{ 1387{
1388 struct btrfs_async_delayed_work *async_work; 1388 struct btrfs_async_delayed_work *async_work;
1389 1389
@@ -1399,7 +1399,7 @@ static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root,
1399 btrfs_async_run_delayed_root, NULL, NULL); 1399 btrfs_async_run_delayed_root, NULL, NULL);
1400 async_work->nr = nr; 1400 async_work->nr = nr;
1401 1401
1402 btrfs_queue_work(root->fs_info->delayed_workers, &async_work->work); 1402 btrfs_queue_work(fs_info->delayed_workers, &async_work->work);
1403 return 0; 1403 return 0;
1404} 1404}
1405 1405
@@ -1426,6 +1426,7 @@ static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
1426void btrfs_balance_delayed_items(struct btrfs_root *root) 1426void btrfs_balance_delayed_items(struct btrfs_root *root)
1427{ 1427{
1428 struct btrfs_delayed_root *delayed_root; 1428 struct btrfs_delayed_root *delayed_root;
1429 struct btrfs_fs_info *fs_info = root->fs_info;
1429 1430
1430 delayed_root = btrfs_get_delayed_root(root); 1431 delayed_root = btrfs_get_delayed_root(root);
1431 1432
@@ -1438,7 +1439,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
1438 1439
1439 seq = atomic_read(&delayed_root->items_seq); 1440 seq = atomic_read(&delayed_root->items_seq);
1440 1441
1441 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0); 1442 ret = btrfs_wq_run_delayed_node(delayed_root, fs_info, 0);
1442 if (ret) 1443 if (ret)
1443 return; 1444 return;
1444 1445
@@ -1447,7 +1448,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
1447 return; 1448 return;
1448 } 1449 }
1449 1450
1450 btrfs_wq_run_delayed_node(delayed_root, root, BTRFS_DELAYED_BATCH); 1451 btrfs_wq_run_delayed_node(delayed_root, fs_info, BTRFS_DELAYED_BATCH);
1451} 1452}
1452 1453
1453/* Will return 0 or -ENOMEM */ 1454/* Will return 0 or -ENOMEM */
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 6aaaf987fd31..23c49ab2de4c 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -54,7 +54,7 @@
54#include <asm/cpufeature.h> 54#include <asm/cpufeature.h>
55#endif 55#endif
56 56
57static struct extent_io_ops btree_extent_io_ops; 57static const struct extent_io_ops btree_extent_io_ops;
58static void end_workqueue_fn(struct btrfs_work *work); 58static void end_workqueue_fn(struct btrfs_work *work);
59static void free_fs_root(struct btrfs_root *root); 59static void free_fs_root(struct btrfs_root *root);
60static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, 60static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
@@ -274,10 +274,11 @@ void btrfs_csum_final(u32 crc, char *result)
274 * compute the csum for a btree block, and either verify it or write it 274 * compute the csum for a btree block, and either verify it or write it
275 * into the csum field of the block. 275 * into the csum field of the block.
276 */ 276 */
277static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, 277static int csum_tree_block(struct btrfs_fs_info *fs_info,
278 struct extent_buffer *buf,
278 int verify) 279 int verify)
279{ 280{
280 u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); 281 u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
281 char *result = NULL; 282 char *result = NULL;
282 unsigned long len; 283 unsigned long len;
283 unsigned long cur_len; 284 unsigned long cur_len;
@@ -321,7 +322,7 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
321 printk_ratelimited(KERN_WARNING 322 printk_ratelimited(KERN_WARNING
322 "BTRFS: %s checksum verify failed on %llu wanted %X found %X " 323 "BTRFS: %s checksum verify failed on %llu wanted %X found %X "
323 "level %d\n", 324 "level %d\n",
324 root->fs_info->sb->s_id, buf->start, 325 fs_info->sb->s_id, buf->start,
325 val, found, btrfs_header_level(buf)); 326 val, found, btrfs_header_level(buf));
326 if (result != (char *)&inline_result) 327 if (result != (char *)&inline_result)
327 kfree(result); 328 kfree(result);
@@ -501,7 +502,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,
501 * we only fill in the checksum field in the first page of a multi-page block 502 * we only fill in the checksum field in the first page of a multi-page block
502 */ 503 */
503 504
504static int csum_dirty_buffer(struct btrfs_root *root, struct page *page) 505static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct page *page)
505{ 506{
506 u64 start = page_offset(page); 507 u64 start = page_offset(page);
507 u64 found_start; 508 u64 found_start;
@@ -513,14 +514,14 @@ static int csum_dirty_buffer(struct btrfs_root *root, struct page *page)
513 found_start = btrfs_header_bytenr(eb); 514 found_start = btrfs_header_bytenr(eb);
514 if (WARN_ON(found_start != start || !PageUptodate(page))) 515 if (WARN_ON(found_start != start || !PageUptodate(page)))
515 return 0; 516 return 0;
516 csum_tree_block(root, eb, 0); 517 csum_tree_block(fs_info, eb, 0);
517 return 0; 518 return 0;
518} 519}
519 520
520static int check_tree_block_fsid(struct btrfs_root *root, 521static int check_tree_block_fsid(struct btrfs_fs_info *fs_info,
521 struct extent_buffer *eb) 522 struct extent_buffer *eb)
522{ 523{
523 struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; 524 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
524 u8 fsid[BTRFS_UUID_SIZE]; 525 u8 fsid[BTRFS_UUID_SIZE];
525 int ret = 1; 526 int ret = 1;
526 527
@@ -640,7 +641,7 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
640 ret = -EIO; 641 ret = -EIO;
641 goto err; 642 goto err;
642 } 643 }
643 if (check_tree_block_fsid(root, eb)) { 644 if (check_tree_block_fsid(root->fs_info, eb)) {
644 printk_ratelimited(KERN_ERR "BTRFS (device %s): bad fsid on block %llu\n", 645 printk_ratelimited(KERN_ERR "BTRFS (device %s): bad fsid on block %llu\n",
645 eb->fs_info->sb->s_id, eb->start); 646 eb->fs_info->sb->s_id, eb->start);
646 ret = -EIO; 647 ret = -EIO;
@@ -657,7 +658,7 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
657 btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb), 658 btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb),
658 eb, found_level); 659 eb, found_level);
659 660
660 ret = csum_tree_block(root, eb, 1); 661 ret = csum_tree_block(root->fs_info, eb, 1);
661 if (ret) { 662 if (ret) {
662 ret = -EIO; 663 ret = -EIO;
663 goto err; 664 goto err;
@@ -882,7 +883,7 @@ static int btree_csum_one_bio(struct bio *bio)
882 883
883 bio_for_each_segment_all(bvec, bio, i) { 884 bio_for_each_segment_all(bvec, bio, i) {
884 root = BTRFS_I(bvec->bv_page->mapping->host)->root; 885 root = BTRFS_I(bvec->bv_page->mapping->host)->root;
885 ret = csum_dirty_buffer(root, bvec->bv_page); 886 ret = csum_dirty_buffer(root->fs_info, bvec->bv_page);
886 if (ret) 887 if (ret)
887 break; 888 break;
888 } 889 }
@@ -1119,10 +1120,10 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr,
1119 return 0; 1120 return 0;
1120} 1121}
1121 1122
1122struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, 1123struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
1123 u64 bytenr) 1124 u64 bytenr)
1124{ 1125{
1125 return find_extent_buffer(root->fs_info, bytenr); 1126 return find_extent_buffer(fs_info, bytenr);
1126} 1127}
1127 1128
1128struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, 1129struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
@@ -1165,11 +1166,10 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
1165 1166
1166} 1167}
1167 1168
1168void clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, 1169void clean_tree_block(struct btrfs_trans_handle *trans,
1170 struct btrfs_fs_info *fs_info,
1169 struct extent_buffer *buf) 1171 struct extent_buffer *buf)
1170{ 1172{
1171 struct btrfs_fs_info *fs_info = root->fs_info;
1172
1173 if (btrfs_header_generation(buf) == 1173 if (btrfs_header_generation(buf) ==
1174 fs_info->running_transaction->transid) { 1174 fs_info->running_transaction->transid) {
1175 btrfs_assert_tree_locked(buf); 1175 btrfs_assert_tree_locked(buf);
@@ -2146,6 +2146,267 @@ void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info)
2146 } 2146 }
2147} 2147}
2148 2148
2149static void btrfs_init_scrub(struct btrfs_fs_info *fs_info)
2150{
2151 mutex_init(&fs_info->scrub_lock);
2152 atomic_set(&fs_info->scrubs_running, 0);
2153 atomic_set(&fs_info->scrub_pause_req, 0);
2154 atomic_set(&fs_info->scrubs_paused, 0);
2155 atomic_set(&fs_info->scrub_cancel_req, 0);
2156 init_waitqueue_head(&fs_info->scrub_pause_wait);
2157 fs_info->scrub_workers_refcnt = 0;
2158}
2159
2160static void btrfs_init_balance(struct btrfs_fs_info *fs_info)
2161{
2162 spin_lock_init(&fs_info->balance_lock);
2163 mutex_init(&fs_info->balance_mutex);
2164 atomic_set(&fs_info->balance_running, 0);
2165 atomic_set(&fs_info->balance_pause_req, 0);
2166 atomic_set(&fs_info->balance_cancel_req, 0);
2167 fs_info->balance_ctl = NULL;
2168 init_waitqueue_head(&fs_info->balance_wait_q);
2169}
2170
2171static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info,
2172 struct btrfs_root *tree_root)
2173{
2174 fs_info->btree_inode->i_ino = BTRFS_BTREE_INODE_OBJECTID;
2175 set_nlink(fs_info->btree_inode, 1);
2176 /*
2177 * we set the i_size on the btree inode to the max possible int.
2178 * the real end of the address space is determined by all of
2179 * the devices in the system
2180 */
2181 fs_info->btree_inode->i_size = OFFSET_MAX;
2182 fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
2183
2184 RB_CLEAR_NODE(&BTRFS_I(fs_info->btree_inode)->rb_node);
2185 extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
2186 fs_info->btree_inode->i_mapping);
2187 BTRFS_I(fs_info->btree_inode)->io_tree.track_uptodate = 0;
2188 extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree);
2189
2190 BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
2191
2192 BTRFS_I(fs_info->btree_inode)->root = tree_root;
2193 memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
2194 sizeof(struct btrfs_key));
2195 set_bit(BTRFS_INODE_DUMMY,
2196 &BTRFS_I(fs_info->btree_inode)->runtime_flags);
2197 btrfs_insert_inode_hash(fs_info->btree_inode);
2198}
2199
2200static void btrfs_init_dev_replace_locks(struct btrfs_fs_info *fs_info)
2201{
2202 fs_info->dev_replace.lock_owner = 0;
2203 atomic_set(&fs_info->dev_replace.nesting_level, 0);
2204 mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount);
2205 mutex_init(&fs_info->dev_replace.lock_management_lock);
2206 mutex_init(&fs_info->dev_replace.lock);
2207 init_waitqueue_head(&fs_info->replace_wait);
2208}
2209
2210static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info)
2211{
2212 spin_lock_init(&fs_info->qgroup_lock);
2213 mutex_init(&fs_info->qgroup_ioctl_lock);
2214 fs_info->qgroup_tree = RB_ROOT;
2215 fs_info->qgroup_op_tree = RB_ROOT;
2216 INIT_LIST_HEAD(&fs_info->dirty_qgroups);
2217 fs_info->qgroup_seq = 1;
2218 fs_info->quota_enabled = 0;
2219 fs_info->pending_quota_state = 0;
2220 fs_info->qgroup_ulist = NULL;
2221 mutex_init(&fs_info->qgroup_rescan_lock);
2222}
2223
2224static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
2225 struct btrfs_fs_devices *fs_devices)
2226{
2227 int max_active = fs_info->thread_pool_size;
2228 unsigned int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND;
2229
2230 fs_info->workers =
2231 btrfs_alloc_workqueue("worker", flags | WQ_HIGHPRI,
2232 max_active, 16);
2233
2234 fs_info->delalloc_workers =
2235 btrfs_alloc_workqueue("delalloc", flags, max_active, 2);
2236
2237 fs_info->flush_workers =
2238 btrfs_alloc_workqueue("flush_delalloc", flags, max_active, 0);
2239
2240 fs_info->caching_workers =
2241 btrfs_alloc_workqueue("cache", flags, max_active, 0);
2242
2243 /*
2244 * a higher idle thresh on the submit workers makes it much more
2245 * likely that bios will be send down in a sane order to the
2246 * devices
2247 */
2248 fs_info->submit_workers =
2249 btrfs_alloc_workqueue("submit", flags,
2250 min_t(u64, fs_devices->num_devices,
2251 max_active), 64);
2252
2253 fs_info->fixup_workers =
2254 btrfs_alloc_workqueue("fixup", flags, 1, 0);
2255
2256 /*
2257 * endios are largely parallel and should have a very
2258 * low idle thresh
2259 */
2260 fs_info->endio_workers =
2261 btrfs_alloc_workqueue("endio", flags, max_active, 4);
2262 fs_info->endio_meta_workers =
2263 btrfs_alloc_workqueue("endio-meta", flags, max_active, 4);
2264 fs_info->endio_meta_write_workers =
2265 btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2);
2266 fs_info->endio_raid56_workers =
2267 btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4);
2268 fs_info->endio_repair_workers =
2269 btrfs_alloc_workqueue("endio-repair", flags, 1, 0);
2270 fs_info->rmw_workers =
2271 btrfs_alloc_workqueue("rmw", flags, max_active, 2);
2272 fs_info->endio_write_workers =
2273 btrfs_alloc_workqueue("endio-write", flags, max_active, 2);
2274 fs_info->endio_freespace_worker =
2275 btrfs_alloc_workqueue("freespace-write", flags, max_active, 0);
2276 fs_info->delayed_workers =
2277 btrfs_alloc_workqueue("delayed-meta", flags, max_active, 0);
2278 fs_info->readahead_workers =
2279 btrfs_alloc_workqueue("readahead", flags, max_active, 2);
2280 fs_info->qgroup_rescan_workers =
2281 btrfs_alloc_workqueue("qgroup-rescan", flags, 1, 0);
2282 fs_info->extent_workers =
2283 btrfs_alloc_workqueue("extent-refs", flags,
2284 min_t(u64, fs_devices->num_devices,
2285 max_active), 8);
2286
2287 if (!(fs_info->workers && fs_info->delalloc_workers &&
2288 fs_info->submit_workers && fs_info->flush_workers &&
2289 fs_info->endio_workers && fs_info->endio_meta_workers &&
2290 fs_info->endio_meta_write_workers &&
2291 fs_info->endio_repair_workers &&
2292 fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
2293 fs_info->endio_freespace_worker && fs_info->rmw_workers &&
2294 fs_info->caching_workers && fs_info->readahead_workers &&
2295 fs_info->fixup_workers && fs_info->delayed_workers &&
2296 fs_info->extent_workers &&
2297 fs_info->qgroup_rescan_workers)) {
2298 return -ENOMEM;
2299 }
2300
2301 return 0;
2302}
2303
2304static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
2305 struct btrfs_fs_devices *fs_devices)
2306{
2307 int ret;
2308 struct btrfs_root *tree_root = fs_info->tree_root;
2309 struct btrfs_root *log_tree_root;
2310 struct btrfs_super_block *disk_super = fs_info->super_copy;
2311 u64 bytenr = btrfs_super_log_root(disk_super);
2312
2313 if (fs_devices->rw_devices == 0) {
2314 printk(KERN_WARNING "BTRFS: log replay required "
2315 "on RO media\n");
2316 return -EIO;
2317 }
2318
2319 log_tree_root = btrfs_alloc_root(fs_info);
2320 if (!log_tree_root)
2321 return -ENOMEM;
2322
2323 __setup_root(tree_root->nodesize, tree_root->sectorsize,
2324 tree_root->stripesize, log_tree_root, fs_info,
2325 BTRFS_TREE_LOG_OBJECTID);
2326
2327 log_tree_root->node = read_tree_block(tree_root, bytenr,
2328 fs_info->generation + 1);
2329 if (!log_tree_root->node ||
2330 !extent_buffer_uptodate(log_tree_root->node)) {
2331 printk(KERN_ERR "BTRFS: failed to read log tree\n");
2332 free_extent_buffer(log_tree_root->node);
2333 kfree(log_tree_root);
2334 return -EIO;
2335 }
2336 /* returns with log_tree_root freed on success */
2337 ret = btrfs_recover_log_trees(log_tree_root);
2338 if (ret) {
2339 btrfs_error(tree_root->fs_info, ret,
2340 "Failed to recover log tree");
2341 free_extent_buffer(log_tree_root->node);
2342 kfree(log_tree_root);
2343 return ret;
2344 }
2345
2346 if (fs_info->sb->s_flags & MS_RDONLY) {
2347 ret = btrfs_commit_super(tree_root);
2348 if (ret)
2349 return ret;
2350 }
2351
2352 return 0;
2353}
2354
2355static int btrfs_read_roots(struct btrfs_fs_info *fs_info,
2356 struct btrfs_root *tree_root)
2357{
2358 struct btrfs_root *root;
2359 struct btrfs_key location;
2360 int ret;
2361
2362 location.objectid = BTRFS_EXTENT_TREE_OBJECTID;
2363 location.type = BTRFS_ROOT_ITEM_KEY;
2364 location.offset = 0;
2365
2366 root = btrfs_read_tree_root(tree_root, &location);
2367 if (IS_ERR(root))
2368 return PTR_ERR(root);
2369 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2370 fs_info->extent_root = root;
2371
2372 location.objectid = BTRFS_DEV_TREE_OBJECTID;
2373 root = btrfs_read_tree_root(tree_root, &location);
2374 if (IS_ERR(root))
2375 return PTR_ERR(root);
2376 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2377 fs_info->dev_root = root;
2378 btrfs_init_devices_late(fs_info);
2379
2380 location.objectid = BTRFS_CSUM_TREE_OBJECTID;
2381 root = btrfs_read_tree_root(tree_root, &location);
2382 if (IS_ERR(root))
2383 return PTR_ERR(root);
2384 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2385 fs_info->csum_root = root;
2386
2387 location.objectid = BTRFS_QUOTA_TREE_OBJECTID;
2388 root = btrfs_read_tree_root(tree_root, &location);
2389 if (!IS_ERR(root)) {
2390 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2391 fs_info->quota_enabled = 1;
2392 fs_info->pending_quota_state = 1;
2393 fs_info->quota_root = root;
2394 }
2395
2396 location.objectid = BTRFS_UUID_TREE_OBJECTID;
2397 root = btrfs_read_tree_root(tree_root, &location);
2398 if (IS_ERR(root)) {
2399 ret = PTR_ERR(root);
2400 if (ret != -ENOENT)
2401 return ret;
2402 } else {
2403 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2404 fs_info->uuid_root = root;
2405 }
2406
2407 return 0;
2408}
2409
2149int open_ctree(struct super_block *sb, 2410int open_ctree(struct super_block *sb,
2150 struct btrfs_fs_devices *fs_devices, 2411 struct btrfs_fs_devices *fs_devices,
2151 char *options) 2412 char *options)
@@ -2160,21 +2421,12 @@ int open_ctree(struct super_block *sb,
2160 struct btrfs_super_block *disk_super; 2421 struct btrfs_super_block *disk_super;
2161 struct btrfs_fs_info *fs_info = btrfs_sb(sb); 2422 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
2162 struct btrfs_root *tree_root; 2423 struct btrfs_root *tree_root;
2163 struct btrfs_root *extent_root;
2164 struct btrfs_root *csum_root;
2165 struct btrfs_root *chunk_root; 2424 struct btrfs_root *chunk_root;
2166 struct btrfs_root *dev_root;
2167 struct btrfs_root *quota_root;
2168 struct btrfs_root *uuid_root;
2169 struct btrfs_root *log_tree_root;
2170 int ret; 2425 int ret;
2171 int err = -EINVAL; 2426 int err = -EINVAL;
2172 int num_backups_tried = 0; 2427 int num_backups_tried = 0;
2173 int backup_index = 0; 2428 int backup_index = 0;
2174 int max_active; 2429 int max_active;
2175 int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND;
2176 bool create_uuid_tree;
2177 bool check_uuid_tree;
2178 2430
2179 tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info); 2431 tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info);
2180 chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info); 2432 chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info);
@@ -2294,55 +2546,18 @@ int open_ctree(struct super_block *sb,
2294 } 2546 }
2295 btrfs_init_delayed_root(fs_info->delayed_root); 2547 btrfs_init_delayed_root(fs_info->delayed_root);
2296 2548
2297 mutex_init(&fs_info->scrub_lock); 2549 btrfs_init_scrub(fs_info);
2298 atomic_set(&fs_info->scrubs_running, 0);
2299 atomic_set(&fs_info->scrub_pause_req, 0);
2300 atomic_set(&fs_info->scrubs_paused, 0);
2301 atomic_set(&fs_info->scrub_cancel_req, 0);
2302 init_waitqueue_head(&fs_info->replace_wait);
2303 init_waitqueue_head(&fs_info->scrub_pause_wait);
2304 fs_info->scrub_workers_refcnt = 0;
2305#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY 2550#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
2306 fs_info->check_integrity_print_mask = 0; 2551 fs_info->check_integrity_print_mask = 0;
2307#endif 2552#endif
2308 2553 btrfs_init_balance(fs_info);
2309 spin_lock_init(&fs_info->balance_lock);
2310 mutex_init(&fs_info->balance_mutex);
2311 atomic_set(&fs_info->balance_running, 0);
2312 atomic_set(&fs_info->balance_pause_req, 0);
2313 atomic_set(&fs_info->balance_cancel_req, 0);
2314 fs_info->balance_ctl = NULL;
2315 init_waitqueue_head(&fs_info->balance_wait_q);
2316 btrfs_init_async_reclaim_work(&fs_info->async_reclaim_work); 2554 btrfs_init_async_reclaim_work(&fs_info->async_reclaim_work);
2317 2555
2318 sb->s_blocksize = 4096; 2556 sb->s_blocksize = 4096;
2319 sb->s_blocksize_bits = blksize_bits(4096); 2557 sb->s_blocksize_bits = blksize_bits(4096);
2320 sb->s_bdi = &fs_info->bdi; 2558 sb->s_bdi = &fs_info->bdi;
2321 2559
2322 fs_info->btree_inode->i_ino = BTRFS_BTREE_INODE_OBJECTID; 2560 btrfs_init_btree_inode(fs_info, tree_root);
2323 set_nlink(fs_info->btree_inode, 1);
2324 /*
2325 * we set the i_size on the btree inode to the max possible int.
2326 * the real end of the address space is determined by all of
2327 * the devices in the system
2328 */
2329 fs_info->btree_inode->i_size = OFFSET_MAX;
2330 fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
2331
2332 RB_CLEAR_NODE(&BTRFS_I(fs_info->btree_inode)->rb_node);
2333 extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
2334 fs_info->btree_inode->i_mapping);
2335 BTRFS_I(fs_info->btree_inode)->io_tree.track_uptodate = 0;
2336 extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree);
2337
2338 BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
2339
2340 BTRFS_I(fs_info->btree_inode)->root = tree_root;
2341 memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
2342 sizeof(struct btrfs_key));
2343 set_bit(BTRFS_INODE_DUMMY,
2344 &BTRFS_I(fs_info->btree_inode)->runtime_flags);
2345 btrfs_insert_inode_hash(fs_info->btree_inode);
2346 2561
2347 spin_lock_init(&fs_info->block_group_cache_lock); 2562 spin_lock_init(&fs_info->block_group_cache_lock);
2348 fs_info->block_group_cache_tree = RB_ROOT; 2563 fs_info->block_group_cache_tree = RB_ROOT;
@@ -2367,22 +2582,9 @@ int open_ctree(struct super_block *sb,
2367 init_rwsem(&fs_info->cleanup_work_sem); 2582 init_rwsem(&fs_info->cleanup_work_sem);
2368 init_rwsem(&fs_info->subvol_sem); 2583 init_rwsem(&fs_info->subvol_sem);
2369 sema_init(&fs_info->uuid_tree_rescan_sem, 1); 2584 sema_init(&fs_info->uuid_tree_rescan_sem, 1);
2370 fs_info->dev_replace.lock_owner = 0;
2371 atomic_set(&fs_info->dev_replace.nesting_level, 0);
2372 mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount);
2373 mutex_init(&fs_info->dev_replace.lock_management_lock);
2374 mutex_init(&fs_info->dev_replace.lock);
2375 2585
2376 spin_lock_init(&fs_info->qgroup_lock); 2586 btrfs_init_dev_replace_locks(fs_info);
2377 mutex_init(&fs_info->qgroup_ioctl_lock); 2587 btrfs_init_qgroup(fs_info);
2378 fs_info->qgroup_tree = RB_ROOT;
2379 fs_info->qgroup_op_tree = RB_ROOT;
2380 INIT_LIST_HEAD(&fs_info->dirty_qgroups);
2381 fs_info->qgroup_seq = 1;
2382 fs_info->quota_enabled = 0;
2383 fs_info->pending_quota_state = 0;
2384 fs_info->qgroup_ulist = NULL;
2385 mutex_init(&fs_info->qgroup_rescan_lock);
2386 2588
2387 btrfs_init_free_cluster(&fs_info->meta_alloc_cluster); 2589 btrfs_init_free_cluster(&fs_info->meta_alloc_cluster);
2388 btrfs_init_free_cluster(&fs_info->data_alloc_cluster); 2590 btrfs_init_free_cluster(&fs_info->data_alloc_cluster);
@@ -2554,75 +2756,9 @@ int open_ctree(struct super_block *sb,
2554 2756
2555 max_active = fs_info->thread_pool_size; 2757 max_active = fs_info->thread_pool_size;
2556 2758
2557 fs_info->workers = 2759 ret = btrfs_init_workqueues(fs_info, fs_devices);
2558 btrfs_alloc_workqueue("worker", flags | WQ_HIGHPRI, 2760 if (ret) {
2559 max_active, 16); 2761 err = ret;
2560
2561 fs_info->delalloc_workers =
2562 btrfs_alloc_workqueue("delalloc", flags, max_active, 2);
2563
2564 fs_info->flush_workers =
2565 btrfs_alloc_workqueue("flush_delalloc", flags, max_active, 0);
2566
2567 fs_info->caching_workers =
2568 btrfs_alloc_workqueue("cache", flags, max_active, 0);
2569
2570 /*
2571 * a higher idle thresh on the submit workers makes it much more
2572 * likely that bios will be send down in a sane order to the
2573 * devices
2574 */
2575 fs_info->submit_workers =
2576 btrfs_alloc_workqueue("submit", flags,
2577 min_t(u64, fs_devices->num_devices,
2578 max_active), 64);
2579
2580 fs_info->fixup_workers =
2581 btrfs_alloc_workqueue("fixup", flags, 1, 0);
2582
2583 /*
2584 * endios are largely parallel and should have a very
2585 * low idle thresh
2586 */
2587 fs_info->endio_workers =
2588 btrfs_alloc_workqueue("endio", flags, max_active, 4);
2589 fs_info->endio_meta_workers =
2590 btrfs_alloc_workqueue("endio-meta", flags, max_active, 4);
2591 fs_info->endio_meta_write_workers =
2592 btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2);
2593 fs_info->endio_raid56_workers =
2594 btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4);
2595 fs_info->endio_repair_workers =
2596 btrfs_alloc_workqueue("endio-repair", flags, 1, 0);
2597 fs_info->rmw_workers =
2598 btrfs_alloc_workqueue("rmw", flags, max_active, 2);
2599 fs_info->endio_write_workers =
2600 btrfs_alloc_workqueue("endio-write", flags, max_active, 2);
2601 fs_info->endio_freespace_worker =
2602 btrfs_alloc_workqueue("freespace-write", flags, max_active, 0);
2603 fs_info->delayed_workers =
2604 btrfs_alloc_workqueue("delayed-meta", flags, max_active, 0);
2605 fs_info->readahead_workers =
2606 btrfs_alloc_workqueue("readahead", flags, max_active, 2);
2607 fs_info->qgroup_rescan_workers =
2608 btrfs_alloc_workqueue("qgroup-rescan", flags, 1, 0);
2609 fs_info->extent_workers =
2610 btrfs_alloc_workqueue("extent-refs", flags,
2611 min_t(u64, fs_devices->num_devices,
2612 max_active), 8);
2613
2614 if (!(fs_info->workers && fs_info->delalloc_workers &&
2615 fs_info->submit_workers && fs_info->flush_workers &&
2616 fs_info->endio_workers && fs_info->endio_meta_workers &&
2617 fs_info->endio_meta_write_workers &&
2618 fs_info->endio_repair_workers &&
2619 fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
2620 fs_info->endio_freespace_worker && fs_info->rmw_workers &&
2621 fs_info->caching_workers && fs_info->readahead_workers &&
2622 fs_info->fixup_workers && fs_info->delayed_workers &&
2623 fs_info->extent_workers &&
2624 fs_info->qgroup_rescan_workers)) {
2625 err = -ENOMEM;
2626 goto fail_sb_buffer; 2762 goto fail_sb_buffer;
2627 } 2763 }
2628 2764
@@ -2688,7 +2824,7 @@ int open_ctree(struct super_block *sb,
2688 * keep the device that is marked to be the target device for the 2824 * keep the device that is marked to be the target device for the
2689 * dev_replace procedure 2825 * dev_replace procedure
2690 */ 2826 */
2691 btrfs_close_extra_devices(fs_info, fs_devices, 0); 2827 btrfs_close_extra_devices(fs_devices, 0);
2692 2828
2693 if (!fs_devices->latest_bdev) { 2829 if (!fs_devices->latest_bdev) {
2694 printk(KERN_ERR "BTRFS: failed to read devices on %s\n", 2830 printk(KERN_ERR "BTRFS: failed to read devices on %s\n",
@@ -2714,61 +2850,9 @@ retry_root_backup:
2714 tree_root->commit_root = btrfs_root_node(tree_root); 2850 tree_root->commit_root = btrfs_root_node(tree_root);
2715 btrfs_set_root_refs(&tree_root->root_item, 1); 2851 btrfs_set_root_refs(&tree_root->root_item, 1);
2716 2852
2717 location.objectid = BTRFS_EXTENT_TREE_OBJECTID; 2853 ret = btrfs_read_roots(fs_info, tree_root);
2718 location.type = BTRFS_ROOT_ITEM_KEY; 2854 if (ret)
2719 location.offset = 0;
2720
2721 extent_root = btrfs_read_tree_root(tree_root, &location);
2722 if (IS_ERR(extent_root)) {
2723 ret = PTR_ERR(extent_root);
2724 goto recovery_tree_root;
2725 }
2726 set_bit(BTRFS_ROOT_TRACK_DIRTY, &extent_root->state);
2727 fs_info->extent_root = extent_root;
2728
2729 location.objectid = BTRFS_DEV_TREE_OBJECTID;
2730 dev_root = btrfs_read_tree_root(tree_root, &location);
2731 if (IS_ERR(dev_root)) {
2732 ret = PTR_ERR(dev_root);
2733 goto recovery_tree_root;
2734 }
2735 set_bit(BTRFS_ROOT_TRACK_DIRTY, &dev_root->state);
2736 fs_info->dev_root = dev_root;
2737 btrfs_init_devices_late(fs_info);
2738
2739 location.objectid = BTRFS_CSUM_TREE_OBJECTID;
2740 csum_root = btrfs_read_tree_root(tree_root, &location);
2741 if (IS_ERR(csum_root)) {
2742 ret = PTR_ERR(csum_root);
2743 goto recovery_tree_root; 2855 goto recovery_tree_root;
2744 }
2745 set_bit(BTRFS_ROOT_TRACK_DIRTY, &csum_root->state);
2746 fs_info->csum_root = csum_root;
2747
2748 location.objectid = BTRFS_QUOTA_TREE_OBJECTID;
2749 quota_root = btrfs_read_tree_root(tree_root, &location);
2750 if (!IS_ERR(quota_root)) {
2751 set_bit(BTRFS_ROOT_TRACK_DIRTY, &quota_root->state);
2752 fs_info->quota_enabled = 1;
2753 fs_info->pending_quota_state = 1;
2754 fs_info->quota_root = quota_root;
2755 }
2756
2757 location.objectid = BTRFS_UUID_TREE_OBJECTID;
2758 uuid_root = btrfs_read_tree_root(tree_root, &location);
2759 if (IS_ERR(uuid_root)) {
2760 ret = PTR_ERR(uuid_root);
2761 if (ret != -ENOENT)
2762 goto recovery_tree_root;
2763 create_uuid_tree = true;
2764 check_uuid_tree = false;
2765 } else {
2766 set_bit(BTRFS_ROOT_TRACK_DIRTY, &uuid_root->state);
2767 fs_info->uuid_root = uuid_root;
2768 create_uuid_tree = false;
2769 check_uuid_tree =
2770 generation != btrfs_super_uuid_tree_generation(disk_super);
2771 }
2772 2856
2773 fs_info->generation = generation; 2857 fs_info->generation = generation;
2774 fs_info->last_trans_committed = generation; 2858 fs_info->last_trans_committed = generation;
@@ -2792,7 +2876,7 @@ retry_root_backup:
2792 goto fail_block_groups; 2876 goto fail_block_groups;
2793 } 2877 }
2794 2878
2795 btrfs_close_extra_devices(fs_info, fs_devices, 1); 2879 btrfs_close_extra_devices(fs_devices, 1);
2796 2880
2797 ret = btrfs_sysfs_add_one(fs_info); 2881 ret = btrfs_sysfs_add_one(fs_info);
2798 if (ret) { 2882 if (ret) {
@@ -2806,7 +2890,7 @@ retry_root_backup:
2806 goto fail_sysfs; 2890 goto fail_sysfs;
2807 } 2891 }
2808 2892
2809 ret = btrfs_read_block_groups(extent_root); 2893 ret = btrfs_read_block_groups(fs_info->extent_root);
2810 if (ret) { 2894 if (ret) {
2811 printk(KERN_ERR "BTRFS: Failed to read block groups: %d\n", ret); 2895 printk(KERN_ERR "BTRFS: Failed to read block groups: %d\n", ret);
2812 goto fail_sysfs; 2896 goto fail_sysfs;
@@ -2864,48 +2948,11 @@ retry_root_backup:
2864 2948
2865 /* do not make disk changes in broken FS */ 2949 /* do not make disk changes in broken FS */
2866 if (btrfs_super_log_root(disk_super) != 0) { 2950 if (btrfs_super_log_root(disk_super) != 0) {
2867 u64 bytenr = btrfs_super_log_root(disk_super); 2951 ret = btrfs_replay_log(fs_info, fs_devices);
2868
2869 if (fs_devices->rw_devices == 0) {
2870 printk(KERN_WARNING "BTRFS: log replay required "
2871 "on RO media\n");
2872 err = -EIO;
2873 goto fail_qgroup;
2874 }
2875
2876 log_tree_root = btrfs_alloc_root(fs_info);
2877 if (!log_tree_root) {
2878 err = -ENOMEM;
2879 goto fail_qgroup;
2880 }
2881
2882 __setup_root(nodesize, sectorsize, stripesize,
2883 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID);
2884
2885 log_tree_root->node = read_tree_block(tree_root, bytenr,
2886 generation + 1);
2887 if (!log_tree_root->node ||
2888 !extent_buffer_uptodate(log_tree_root->node)) {
2889 printk(KERN_ERR "BTRFS: failed to read log tree\n");
2890 free_extent_buffer(log_tree_root->node);
2891 kfree(log_tree_root);
2892 goto fail_qgroup;
2893 }
2894 /* returns with log_tree_root freed on success */
2895 ret = btrfs_recover_log_trees(log_tree_root);
2896 if (ret) { 2952 if (ret) {
2897 btrfs_error(tree_root->fs_info, ret, 2953 err = ret;
2898 "Failed to recover log tree");
2899 free_extent_buffer(log_tree_root->node);
2900 kfree(log_tree_root);
2901 goto fail_qgroup; 2954 goto fail_qgroup;
2902 } 2955 }
2903
2904 if (sb->s_flags & MS_RDONLY) {
2905 ret = btrfs_commit_super(tree_root);
2906 if (ret)
2907 goto fail_qgroup;
2908 }
2909 } 2956 }
2910 2957
2911 ret = btrfs_find_orphan_roots(tree_root); 2958 ret = btrfs_find_orphan_roots(tree_root);
@@ -2966,7 +3013,7 @@ retry_root_backup:
2966 3013
2967 btrfs_qgroup_rescan_resume(fs_info); 3014 btrfs_qgroup_rescan_resume(fs_info);
2968 3015
2969 if (create_uuid_tree) { 3016 if (!fs_info->uuid_root) {
2970 pr_info("BTRFS: creating UUID tree\n"); 3017 pr_info("BTRFS: creating UUID tree\n");
2971 ret = btrfs_create_uuid_tree(fs_info); 3018 ret = btrfs_create_uuid_tree(fs_info);
2972 if (ret) { 3019 if (ret) {
@@ -2975,8 +3022,9 @@ retry_root_backup:
2975 close_ctree(tree_root); 3022 close_ctree(tree_root);
2976 return ret; 3023 return ret;
2977 } 3024 }
2978 } else if (check_uuid_tree || 3025 } else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) ||
2979 btrfs_test_opt(tree_root, RESCAN_UUID_TREE)) { 3026 fs_info->generation !=
3027 btrfs_super_uuid_tree_generation(disk_super)) {
2980 pr_info("BTRFS: checking UUID tree\n"); 3028 pr_info("BTRFS: checking UUID tree\n");
2981 ret = btrfs_check_uuid_tree(fs_info); 3029 ret = btrfs_check_uuid_tree(fs_info);
2982 if (ret) { 3030 if (ret) {
@@ -3668,7 +3716,7 @@ void close_ctree(struct btrfs_root *root)
3668 if (!(fs_info->sb->s_flags & MS_RDONLY)) { 3716 if (!(fs_info->sb->s_flags & MS_RDONLY)) {
3669 ret = btrfs_commit_super(root); 3717 ret = btrfs_commit_super(root);
3670 if (ret) 3718 if (ret)
3671 btrfs_err(root->fs_info, "commit super ret %d", ret); 3719 btrfs_err(fs_info, "commit super ret %d", ret);
3672 } 3720 }
3673 3721
3674 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) 3722 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
@@ -3680,10 +3728,10 @@ void close_ctree(struct btrfs_root *root)
3680 fs_info->closing = 2; 3728 fs_info->closing = 2;
3681 smp_mb(); 3729 smp_mb();
3682 3730
3683 btrfs_free_qgroup_config(root->fs_info); 3731 btrfs_free_qgroup_config(fs_info);
3684 3732
3685 if (percpu_counter_sum(&fs_info->delalloc_bytes)) { 3733 if (percpu_counter_sum(&fs_info->delalloc_bytes)) {
3686 btrfs_info(root->fs_info, "at unmount delalloc count %lld", 3734 btrfs_info(fs_info, "at unmount delalloc count %lld",
3687 percpu_counter_sum(&fs_info->delalloc_bytes)); 3735 percpu_counter_sum(&fs_info->delalloc_bytes));
3688 } 3736 }
3689 3737
@@ -4134,7 +4182,7 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root,
4134 4182
4135 clear_extent_bits(dirty_pages, start, end, mark, GFP_NOFS); 4183 clear_extent_bits(dirty_pages, start, end, mark, GFP_NOFS);
4136 while (start <= end) { 4184 while (start <= end) {
4137 eb = btrfs_find_tree_block(root, start); 4185 eb = btrfs_find_tree_block(root->fs_info, start);
4138 start += root->nodesize; 4186 start += root->nodesize;
4139 if (!eb) 4187 if (!eb)
4140 continue; 4188 continue;
@@ -4285,7 +4333,7 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root)
4285 return 0; 4333 return 0;
4286} 4334}
4287 4335
4288static struct extent_io_ops btree_extent_io_ops = { 4336static const struct extent_io_ops btree_extent_io_ops = {
4289 .readpage_end_io_hook = btree_readpage_end_io_hook, 4337 .readpage_end_io_hook = btree_readpage_end_io_hook,
4290 .readpage_io_failed_hook = btree_io_failed_hook, 4338 .readpage_io_failed_hook = btree_io_failed_hook,
4291 .submit_bio_hook = btree_submit_bio_hook, 4339 .submit_bio_hook = btree_submit_bio_hook,
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 27d44c0fd236..d4cbfeeeedd4 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -52,7 +52,7 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr,
52struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, 52struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
53 u64 bytenr); 53 u64 bytenr);
54void clean_tree_block(struct btrfs_trans_handle *trans, 54void clean_tree_block(struct btrfs_trans_handle *trans,
55 struct btrfs_root *root, struct extent_buffer *buf); 55 struct btrfs_fs_info *fs_info, struct extent_buffer *buf);
56int open_ctree(struct super_block *sb, 56int open_ctree(struct super_block *sb,
57 struct btrfs_fs_devices *fs_devices, 57 struct btrfs_fs_devices *fs_devices,
58 char *options); 58 char *options);
@@ -61,7 +61,7 @@ int write_ctree_super(struct btrfs_trans_handle *trans,
61 struct btrfs_root *root, int max_mirrors); 61 struct btrfs_root *root, int max_mirrors);
62struct buffer_head *btrfs_read_dev_super(struct block_device *bdev); 62struct buffer_head *btrfs_read_dev_super(struct block_device *bdev);
63int btrfs_commit_super(struct btrfs_root *root); 63int btrfs_commit_super(struct btrfs_root *root);
64struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, 64struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
65 u64 bytenr); 65 u64 bytenr);
66struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root, 66struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root,
67 struct btrfs_key *location); 67 struct btrfs_key *location);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d2158c4d6b24..d8ce3cfe7ae0 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3640,7 +3640,7 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes)
3640 struct btrfs_root *root = BTRFS_I(inode)->root; 3640 struct btrfs_root *root = BTRFS_I(inode)->root;
3641 struct btrfs_fs_info *fs_info = root->fs_info; 3641 struct btrfs_fs_info *fs_info = root->fs_info;
3642 u64 used; 3642 u64 used;
3643 int ret = 0, committed = 0, alloc_chunk = 1; 3643 int ret = 0, committed = 0;
3644 3644
3645 /* make sure bytes are sectorsize aligned */ 3645 /* make sure bytes are sectorsize aligned */
3646 bytes = ALIGN(bytes, root->sectorsize); 3646 bytes = ALIGN(bytes, root->sectorsize);
@@ -3668,7 +3668,7 @@ again:
3668 * if we don't have enough free bytes in this space then we need 3668 * if we don't have enough free bytes in this space then we need
3669 * to alloc a new chunk. 3669 * to alloc a new chunk.
3670 */ 3670 */
3671 if (!data_sinfo->full && alloc_chunk) { 3671 if (!data_sinfo->full) {
3672 u64 alloc_target; 3672 u64 alloc_target;
3673 3673
3674 data_sinfo->force_alloc = CHUNK_ALLOC_FORCE; 3674 data_sinfo->force_alloc = CHUNK_ALLOC_FORCE;
@@ -7216,7 +7216,7 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,
7216 btrfs_set_header_generation(buf, trans->transid); 7216 btrfs_set_header_generation(buf, trans->transid);
7217 btrfs_set_buffer_lockdep_class(root->root_key.objectid, buf, level); 7217 btrfs_set_buffer_lockdep_class(root->root_key.objectid, buf, level);
7218 btrfs_tree_lock(buf); 7218 btrfs_tree_lock(buf);
7219 clean_tree_block(trans, root, buf); 7219 clean_tree_block(trans, root->fs_info, buf);
7220 clear_bit(EXTENT_BUFFER_STALE, &buf->bflags); 7220 clear_bit(EXTENT_BUFFER_STALE, &buf->bflags);
7221 7221
7222 btrfs_set_lock_blocking(buf); 7222 btrfs_set_lock_blocking(buf);
@@ -7814,7 +7814,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
7814 bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); 7814 bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]);
7815 blocksize = root->nodesize; 7815 blocksize = root->nodesize;
7816 7816
7817 next = btrfs_find_tree_block(root, bytenr); 7817 next = btrfs_find_tree_block(root->fs_info, bytenr);
7818 if (!next) { 7818 if (!next) {
7819 next = btrfs_find_create_tree_block(root, bytenr); 7819 next = btrfs_find_create_tree_block(root, bytenr);
7820 if (!next) 7820 if (!next)
@@ -8015,7 +8015,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans,
8015 btrfs_set_lock_blocking(eb); 8015 btrfs_set_lock_blocking(eb);
8016 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; 8016 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
8017 } 8017 }
8018 clean_tree_block(trans, root, eb); 8018 clean_tree_block(trans, root->fs_info, eb);
8019 } 8019 }
8020 8020
8021 if (eb == root->node) { 8021 if (eb == root->node) {
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 695b0ccfb755..c668f36898d3 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -97,7 +97,7 @@ struct extent_io_tree {
97 u64 dirty_bytes; 97 u64 dirty_bytes;
98 int track_uptodate; 98 int track_uptodate;
99 spinlock_t lock; 99 spinlock_t lock;
100 struct extent_io_ops *ops; 100 const struct extent_io_ops *ops;
101}; 101};
102 102
103struct extent_state { 103struct extent_state {
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 3a4a7924fa38..58ece6558430 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -553,7 +553,7 @@ static noinline void truncate_one_csum(struct btrfs_root *root,
553 btrfs_truncate_item(root, path, new_size, 0); 553 btrfs_truncate_item(root, path, new_size, 0);
554 554
555 key->offset = end_byte; 555 key->offset = end_byte;
556 btrfs_set_item_key_safe(root, path, key); 556 btrfs_set_item_key_safe(root->fs_info, path, key);
557 } else { 557 } else {
558 BUG(); 558 BUG();
559 } 559 }
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index ac26a917df7b..7d4bb3b6fbc2 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -864,7 +864,7 @@ next_slot:
864 864
865 memcpy(&new_key, &key, sizeof(new_key)); 865 memcpy(&new_key, &key, sizeof(new_key));
866 new_key.offset = end; 866 new_key.offset = end;
867 btrfs_set_item_key_safe(root, path, &new_key); 867 btrfs_set_item_key_safe(root->fs_info, path, &new_key);
868 868
869 extent_offset += end - key.offset; 869 extent_offset += end - key.offset;
870 btrfs_set_file_extent_offset(leaf, fi, extent_offset); 870 btrfs_set_file_extent_offset(leaf, fi, extent_offset);
@@ -1122,7 +1122,7 @@ again:
1122 ino, bytenr, orig_offset, 1122 ino, bytenr, orig_offset,
1123 &other_start, &other_end)) { 1123 &other_start, &other_end)) {
1124 new_key.offset = end; 1124 new_key.offset = end;
1125 btrfs_set_item_key_safe(root, path, &new_key); 1125 btrfs_set_item_key_safe(root->fs_info, path, &new_key);
1126 fi = btrfs_item_ptr(leaf, path->slots[0], 1126 fi = btrfs_item_ptr(leaf, path->slots[0],
1127 struct btrfs_file_extent_item); 1127 struct btrfs_file_extent_item);
1128 btrfs_set_file_extent_generation(leaf, fi, 1128 btrfs_set_file_extent_generation(leaf, fi,
@@ -1156,7 +1156,7 @@ again:
1156 trans->transid); 1156 trans->transid);
1157 path->slots[0]++; 1157 path->slots[0]++;
1158 new_key.offset = start; 1158 new_key.offset = start;
1159 btrfs_set_item_key_safe(root, path, &new_key); 1159 btrfs_set_item_key_safe(root->fs_info, path, &new_key);
1160 1160
1161 fi = btrfs_item_ptr(leaf, path->slots[0], 1161 fi = btrfs_item_ptr(leaf, path->slots[0],
1162 struct btrfs_file_extent_item); 1162 struct btrfs_file_extent_item);
@@ -2164,7 +2164,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
2164 u64 num_bytes; 2164 u64 num_bytes;
2165 2165
2166 key.offset = offset; 2166 key.offset = offset;
2167 btrfs_set_item_key_safe(root, path, &key); 2167 btrfs_set_item_key_safe(root->fs_info, path, &key);
2168 fi = btrfs_item_ptr(leaf, path->slots[0], 2168 fi = btrfs_item_ptr(leaf, path->slots[0],
2169 struct btrfs_file_extent_item); 2169 struct btrfs_file_extent_item);
2170 num_bytes = btrfs_file_extent_num_bytes(leaf, fi) + end - 2170 num_bytes = btrfs_file_extent_num_bytes(leaf, fi) + end -
diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index 617553cdb7d3..a2f051347731 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -434,7 +434,7 @@ out:
434 return ret; 434 return ret;
435} 435}
436 436
437struct btrfs_compress_op btrfs_lzo_compress = { 437const struct btrfs_compress_op btrfs_lzo_compress = {
438 .alloc_workspace = lzo_alloc_workspace, 438 .alloc_workspace = lzo_alloc_workspace,
439 .free_workspace = lzo_free_workspace, 439 .free_workspace = lzo_free_workspace,
440 .compress_pages = lzo_compress_pages, 440 .compress_pages = lzo_compress_pages,
diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
index 129b1dd28527..dca137b04095 100644
--- a/fs/btrfs/props.c
+++ b/fs/btrfs/props.c
@@ -425,3 +425,5 @@ static const char *prop_compression_extract(struct inode *inode)
425 425
426 return NULL; 426 return NULL;
427} 427}
428
429
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index e08d26aa017d..33f31375259a 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -982,7 +982,7 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
982 list_del(&quota_root->dirty_list); 982 list_del(&quota_root->dirty_list);
983 983
984 btrfs_tree_lock(quota_root->node); 984 btrfs_tree_lock(quota_root->node);
985 clean_tree_block(trans, tree_root, quota_root->node); 985 clean_tree_block(trans, tree_root->fs_info, quota_root->node);
986 btrfs_tree_unlock(quota_root->node); 986 btrfs_tree_unlock(quota_root->node);
987 btrfs_free_tree_block(trans, quota_root, quota_root->node, 0, 1); 987 btrfs_free_tree_block(trans, quota_root, quota_root->node, 0, 1);
988 988
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index b4634c30981e..fa72068bd256 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -237,12 +237,8 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)
237 } 237 }
238 238
239 x = cmpxchg(&info->stripe_hash_table, NULL, table); 239 x = cmpxchg(&info->stripe_hash_table, NULL, table);
240 if (x) { 240 if (x)
241 if (is_vmalloc_addr(x)) 241 kvfree(x);
242 vfree(x);
243 else
244 kfree(x);
245 }
246 return 0; 242 return 0;
247} 243}
248 244
@@ -453,10 +449,7 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
453 if (!info->stripe_hash_table) 449 if (!info->stripe_hash_table)
454 return; 450 return;
455 btrfs_clear_rbio_cache(info); 451 btrfs_clear_rbio_cache(info);
456 if (is_vmalloc_addr(info->stripe_hash_table)) 452 kvfree(info->stripe_hash_table);
457 vfree(info->stripe_hash_table);
458 else
459 kfree(info->stripe_hash_table);
460 info->stripe_hash_table = NULL; 453 info->stripe_hash_table = NULL;
461} 454}
462 455
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 34e6499ba5a4..ab5811545a98 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3560,7 +3560,7 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
3560 int is_dev_replace) 3560 int is_dev_replace)
3561{ 3561{
3562 int ret = 0; 3562 int ret = 0;
3563 int flags = WQ_FREEZABLE | WQ_UNBOUND; 3563 unsigned int flags = WQ_FREEZABLE | WQ_UNBOUND;
3564 int max_active = fs_info->thread_pool_size; 3564 int max_active = fs_info->thread_pool_size;
3565 3565
3566 if (fs_info->scrub_workers_refcnt == 0) { 3566 if (fs_info->scrub_workers_refcnt == 0) {
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 94edb0a2a026..e8a4c86d274d 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -459,7 +459,7 @@ static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)
459static char btrfs_unknown_feature_names[3][NUM_FEATURE_BITS][13]; 459static char btrfs_unknown_feature_names[3][NUM_FEATURE_BITS][13];
460static struct btrfs_feature_attr btrfs_feature_attrs[3][NUM_FEATURE_BITS]; 460static struct btrfs_feature_attr btrfs_feature_attrs[3][NUM_FEATURE_BITS];
461 461
462static u64 supported_feature_masks[3] = { 462static const u64 supported_feature_masks[3] = {
463 [FEAT_COMPAT] = BTRFS_FEATURE_COMPAT_SUPP, 463 [FEAT_COMPAT] = BTRFS_FEATURE_COMPAT_SUPP,
464 [FEAT_COMPAT_RO] = BTRFS_FEATURE_COMPAT_RO_SUPP, 464 [FEAT_COMPAT_RO] = BTRFS_FEATURE_COMPAT_RO_SUPP,
465 [FEAT_INCOMPAT] = BTRFS_FEATURE_INCOMPAT_SUPP, 465 [FEAT_INCOMPAT] = BTRFS_FEATURE_INCOMPAT_SUPP,
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index fae816b6671d..91c303ac40b6 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -35,7 +35,7 @@
35 35
36#define BTRFS_ROOT_TRANS_TAG 0 36#define BTRFS_ROOT_TRANS_TAG 0
37 37
38static unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = { 38static const unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = {
39 [TRANS_STATE_RUNNING] = 0U, 39 [TRANS_STATE_RUNNING] = 0U,
40 [TRANS_STATE_BLOCKED] = (__TRANS_USERSPACE | 40 [TRANS_STATE_BLOCKED] = (__TRANS_USERSPACE |
41 __TRANS_START), 41 __TRANS_START),
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index c5b8ba37f88e..066e754b1294 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2230,7 +2230,8 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
2230 if (trans) { 2230 if (trans) {
2231 btrfs_tree_lock(next); 2231 btrfs_tree_lock(next);
2232 btrfs_set_lock_blocking(next); 2232 btrfs_set_lock_blocking(next);
2233 clean_tree_block(trans, root, next); 2233 clean_tree_block(trans, root->fs_info,
2234 next);
2234 btrfs_wait_tree_block_writeback(next); 2235 btrfs_wait_tree_block_writeback(next);
2235 btrfs_tree_unlock(next); 2236 btrfs_tree_unlock(next);
2236 } 2237 }
@@ -2308,7 +2309,8 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans,
2308 if (trans) { 2309 if (trans) {
2309 btrfs_tree_lock(next); 2310 btrfs_tree_lock(next);
2310 btrfs_set_lock_blocking(next); 2311 btrfs_set_lock_blocking(next);
2311 clean_tree_block(trans, root, next); 2312 clean_tree_block(trans, root->fs_info,
2313 next);
2312 btrfs_wait_tree_block_writeback(next); 2314 btrfs_wait_tree_block_writeback(next);
2313 btrfs_tree_unlock(next); 2315 btrfs_tree_unlock(next);
2314 } 2316 }
@@ -2384,7 +2386,7 @@ static int walk_log_tree(struct btrfs_trans_handle *trans,
2384 if (trans) { 2386 if (trans) {
2385 btrfs_tree_lock(next); 2387 btrfs_tree_lock(next);
2386 btrfs_set_lock_blocking(next); 2388 btrfs_set_lock_blocking(next);
2387 clean_tree_block(trans, log, next); 2389 clean_tree_block(trans, log->fs_info, next);
2388 btrfs_wait_tree_block_writeback(next); 2390 btrfs_wait_tree_block_writeback(next);
2389 btrfs_tree_unlock(next); 2391 btrfs_tree_unlock(next);
2390 } 2392 }
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 64ec2fd624da..a73acf496e10 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -608,8 +608,7 @@ error:
608 return ERR_PTR(-ENOMEM); 608 return ERR_PTR(-ENOMEM);
609} 609}
610 610
611void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info, 611void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step)
612 struct btrfs_fs_devices *fs_devices, int step)
613{ 612{
614 struct btrfs_device *device, *next; 613 struct btrfs_device *device, *next;
615 struct btrfs_device *latest_dev = NULL; 614 struct btrfs_device *latest_dev = NULL;
@@ -2486,8 +2485,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
2486} 2485}
2487 2486
2488static int btrfs_free_chunk(struct btrfs_trans_handle *trans, 2487static int btrfs_free_chunk(struct btrfs_trans_handle *trans,
2489 struct btrfs_root *root, 2488 struct btrfs_root *root, u64 chunk_objectid,
2490 u64 chunk_tree, u64 chunk_objectid,
2491 u64 chunk_offset) 2489 u64 chunk_offset)
2492{ 2490{
2493 int ret; 2491 int ret;
@@ -2579,7 +2577,6 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
2579 struct map_lookup *map; 2577 struct map_lookup *map;
2580 u64 dev_extent_len = 0; 2578 u64 dev_extent_len = 0;
2581 u64 chunk_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; 2579 u64 chunk_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
2582 u64 chunk_tree = root->fs_info->chunk_root->objectid;
2583 int i, ret = 0; 2580 int i, ret = 0;
2584 2581
2585 /* Just in case */ 2582 /* Just in case */
@@ -2633,8 +2630,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
2633 } 2630 }
2634 } 2631 }
2635 } 2632 }
2636 ret = btrfs_free_chunk(trans, root, chunk_tree, chunk_objectid, 2633 ret = btrfs_free_chunk(trans, root, chunk_objectid, chunk_offset);
2637 chunk_offset);
2638 if (ret) { 2634 if (ret) {
2639 btrfs_abort_transaction(trans, root, ret); 2635 btrfs_abort_transaction(trans, root, ret);
2640 goto out; 2636 goto out;
@@ -2663,8 +2659,8 @@ out:
2663} 2659}
2664 2660
2665static int btrfs_relocate_chunk(struct btrfs_root *root, 2661static int btrfs_relocate_chunk(struct btrfs_root *root,
2666 u64 chunk_tree, u64 chunk_objectid, 2662 u64 chunk_objectid,
2667 u64 chunk_offset) 2663 u64 chunk_offset)
2668{ 2664{
2669 struct btrfs_root *extent_root; 2665 struct btrfs_root *extent_root;
2670 struct btrfs_trans_handle *trans; 2666 struct btrfs_trans_handle *trans;
@@ -2706,7 +2702,6 @@ static int btrfs_relocate_sys_chunks(struct btrfs_root *root)
2706 struct btrfs_chunk *chunk; 2702 struct btrfs_chunk *chunk;
2707 struct btrfs_key key; 2703 struct btrfs_key key;
2708 struct btrfs_key found_key; 2704 struct btrfs_key found_key;
2709 u64 chunk_tree = chunk_root->root_key.objectid;
2710 u64 chunk_type; 2705 u64 chunk_type;
2711 bool retried = false; 2706 bool retried = false;
2712 int failed = 0; 2707 int failed = 0;
@@ -2743,7 +2738,7 @@ again:
2743 btrfs_release_path(path); 2738 btrfs_release_path(path);
2744 2739
2745 if (chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) { 2740 if (chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) {
2746 ret = btrfs_relocate_chunk(chunk_root, chunk_tree, 2741 ret = btrfs_relocate_chunk(chunk_root,
2747 found_key.objectid, 2742 found_key.objectid,
2748 found_key.offset); 2743 found_key.offset);
2749 if (ret == -ENOSPC) 2744 if (ret == -ENOSPC)
@@ -3254,7 +3249,6 @@ again:
3254 } 3249 }
3255 3250
3256 ret = btrfs_relocate_chunk(chunk_root, 3251 ret = btrfs_relocate_chunk(chunk_root,
3257 chunk_root->root_key.objectid,
3258 found_key.objectid, 3252 found_key.objectid,
3259 found_key.offset); 3253 found_key.offset);
3260 if (ret && ret != -ENOSPC) 3254 if (ret && ret != -ENOSPC)
@@ -3956,7 +3950,6 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
3956 struct btrfs_dev_extent *dev_extent = NULL; 3950 struct btrfs_dev_extent *dev_extent = NULL;
3957 struct btrfs_path *path; 3951 struct btrfs_path *path;
3958 u64 length; 3952 u64 length;
3959 u64 chunk_tree;
3960 u64 chunk_objectid; 3953 u64 chunk_objectid;
3961 u64 chunk_offset; 3954 u64 chunk_offset;
3962 int ret; 3955 int ret;
@@ -4026,13 +4019,11 @@ again:
4026 break; 4019 break;
4027 } 4020 }
4028 4021
4029 chunk_tree = btrfs_dev_extent_chunk_tree(l, dev_extent);
4030 chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent); 4022 chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent);
4031 chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent); 4023 chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent);
4032 btrfs_release_path(path); 4024 btrfs_release_path(path);
4033 4025
4034 ret = btrfs_relocate_chunk(root, chunk_tree, chunk_objectid, 4026 ret = btrfs_relocate_chunk(root, chunk_objectid, chunk_offset);
4035 chunk_offset);
4036 if (ret && ret != -ENOSPC) 4027 if (ret && ret != -ENOSPC)
4037 goto done; 4028 goto done;
4038 if (ret == -ENOSPC) 4029 if (ret == -ENOSPC)
@@ -4130,7 +4121,7 @@ static int btrfs_cmp_device_info(const void *a, const void *b)
4130 return 0; 4121 return 0;
4131} 4122}
4132 4123
4133static struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { 4124static const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
4134 [BTRFS_RAID_RAID10] = { 4125 [BTRFS_RAID_RAID10] = {
4135 .sub_stripes = 2, 4126 .sub_stripes = 2,
4136 .dev_stripes = 1, 4127 .dev_stripes = 1,
@@ -5833,8 +5824,8 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
5833 u64 length = 0; 5824 u64 length = 0;
5834 u64 map_length; 5825 u64 map_length;
5835 int ret; 5826 int ret;
5836 int dev_nr = 0; 5827 int dev_nr;
5837 int total_devs = 1; 5828 int total_devs;
5838 struct btrfs_bio *bbio = NULL; 5829 struct btrfs_bio *bbio = NULL;
5839 5830
5840 length = bio->bi_iter.bi_size; 5831 length = bio->bi_iter.bi_size;
@@ -5875,11 +5866,10 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
5875 BUG(); 5866 BUG();
5876 } 5867 }
5877 5868
5878 while (dev_nr < total_devs) { 5869 for (dev_nr = 0; dev_nr < total_devs; dev_nr++) {
5879 dev = bbio->stripes[dev_nr].dev; 5870 dev = bbio->stripes[dev_nr].dev;
5880 if (!dev || !dev->bdev || (rw & WRITE && !dev->writeable)) { 5871 if (!dev || !dev->bdev || (rw & WRITE && !dev->writeable)) {
5881 bbio_error(bbio, first_bio, logical); 5872 bbio_error(bbio, first_bio, logical);
5882 dev_nr++;
5883 continue; 5873 continue;
5884 } 5874 }
5885 5875
@@ -5892,7 +5882,6 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
5892 ret = breakup_stripe_bio(root, bbio, first_bio, dev, 5882 ret = breakup_stripe_bio(root, bbio, first_bio, dev,
5893 dev_nr, rw, async_submit); 5883 dev_nr, rw, async_submit);
5894 BUG_ON(ret); 5884 BUG_ON(ret);
5895 dev_nr++;
5896 continue; 5885 continue;
5897 } 5886 }
5898 5887
@@ -5907,7 +5896,6 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
5907 submit_stripe_bio(root, bbio, bio, 5896 submit_stripe_bio(root, bbio, bio,
5908 bbio->stripes[dev_nr].physical, dev_nr, rw, 5897 bbio->stripes[dev_nr].physical, dev_nr, rw,
5909 async_submit); 5898 async_submit);
5910 dev_nr++;
5911 } 5899 }
5912 btrfs_bio_counter_dec(root->fs_info); 5900 btrfs_bio_counter_dec(root->fs_info);
5913 return 0; 5901 return 0;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 83069dec6898..ebc31331a837 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -421,8 +421,7 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
421int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, 421int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
422 struct btrfs_fs_devices **fs_devices_ret); 422 struct btrfs_fs_devices **fs_devices_ret);
423int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); 423int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
424void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info, 424void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step);
425 struct btrfs_fs_devices *fs_devices, int step);
426int btrfs_find_device_missing_or_by_path(struct btrfs_root *root, 425int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
427 char *device_path, 426 char *device_path,
428 struct btrfs_device **device); 427 struct btrfs_device **device);
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index fb22fd8d8fb8..82990b8f872b 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -403,7 +403,7 @@ next:
403 return ret; 403 return ret;
404} 404}
405 405
406struct btrfs_compress_op btrfs_zlib_compress = { 406const struct btrfs_compress_op btrfs_zlib_compress = {
407 .alloc_workspace = zlib_alloc_workspace, 407 .alloc_workspace = zlib_alloc_workspace,
408 .free_workspace = zlib_free_workspace, 408 .free_workspace = zlib_free_workspace,
409 .compress_pages = zlib_compress_pages, 409 .compress_pages = zlib_compress_pages,