diff options
author | Chris Mason <clm@fb.com> | 2016-07-26 16:07:05 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2016-07-26 16:07:05 -0400 |
commit | 023a824f04754a4ed5efc16ee8e41bb932878b0b (patch) | |
tree | 8ae0bc5a61945bdec42d6c7a929967c548031d5d | |
parent | 8b8b08cbfb9021af4b54b4175fc4c51d655aac8c (diff) | |
parent | 66642832f06a4351e23cea6cf254967c227f8224 (diff) |
Merge branch 'kdave-v4.8' into for-linus-4.8
45 files changed, 1074 insertions, 826 deletions
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 67a607709d4f..53bb7af4e5f0 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c | |||
@@ -55,8 +55,7 @@ struct posix_acl *btrfs_get_acl(struct inode *inode, int type) | |||
55 | } | 55 | } |
56 | if (size > 0) { | 56 | if (size > 0) { |
57 | acl = posix_acl_from_xattr(&init_user_ns, value, size); | 57 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
58 | } else if (size == -ENOENT || size == -ENODATA || size == 0) { | 58 | } else if (size == -ERANGE || size == -ENODATA || size == 0) { |
59 | /* FIXME, who returns -ENOENT? I think nobody */ | ||
60 | acl = NULL; | 59 | acl = NULL; |
61 | } else { | 60 | } else { |
62 | acl = ERR_PTR(-EIO); | 61 | acl = ERR_PTR(-EIO); |
diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c index 5fb60ea7eee2..e0f071f6b5a7 100644 --- a/fs/btrfs/async-thread.c +++ b/fs/btrfs/async-thread.c | |||
@@ -34,6 +34,10 @@ | |||
34 | 34 | ||
35 | struct __btrfs_workqueue { | 35 | struct __btrfs_workqueue { |
36 | struct workqueue_struct *normal_wq; | 36 | struct workqueue_struct *normal_wq; |
37 | |||
38 | /* File system this workqueue services */ | ||
39 | struct btrfs_fs_info *fs_info; | ||
40 | |||
37 | /* List head pointing to ordered work list */ | 41 | /* List head pointing to ordered work list */ |
38 | struct list_head ordered_list; | 42 | struct list_head ordered_list; |
39 | 43 | ||
@@ -70,6 +74,18 @@ void btrfs_##name(struct work_struct *arg) \ | |||
70 | normal_work_helper(work); \ | 74 | normal_work_helper(work); \ |
71 | } | 75 | } |
72 | 76 | ||
77 | struct btrfs_fs_info * | ||
78 | btrfs_workqueue_owner(struct __btrfs_workqueue *wq) | ||
79 | { | ||
80 | return wq->fs_info; | ||
81 | } | ||
82 | |||
83 | struct btrfs_fs_info * | ||
84 | btrfs_work_owner(struct btrfs_work *work) | ||
85 | { | ||
86 | return work->wq->fs_info; | ||
87 | } | ||
88 | |||
73 | BTRFS_WORK_HELPER(worker_helper); | 89 | BTRFS_WORK_HELPER(worker_helper); |
74 | BTRFS_WORK_HELPER(delalloc_helper); | 90 | BTRFS_WORK_HELPER(delalloc_helper); |
75 | BTRFS_WORK_HELPER(flush_delalloc_helper); | 91 | BTRFS_WORK_HELPER(flush_delalloc_helper); |
@@ -94,14 +110,15 @@ BTRFS_WORK_HELPER(scrubnc_helper); | |||
94 | BTRFS_WORK_HELPER(scrubparity_helper); | 110 | BTRFS_WORK_HELPER(scrubparity_helper); |
95 | 111 | ||
96 | static struct __btrfs_workqueue * | 112 | static struct __btrfs_workqueue * |
97 | __btrfs_alloc_workqueue(const char *name, unsigned int flags, int limit_active, | 113 | __btrfs_alloc_workqueue(struct btrfs_fs_info *fs_info, const char *name, |
98 | int thresh) | 114 | unsigned int flags, int limit_active, int thresh) |
99 | { | 115 | { |
100 | struct __btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_KERNEL); | 116 | struct __btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_KERNEL); |
101 | 117 | ||
102 | if (!ret) | 118 | if (!ret) |
103 | return NULL; | 119 | return NULL; |
104 | 120 | ||
121 | ret->fs_info = fs_info; | ||
105 | ret->limit_active = limit_active; | 122 | ret->limit_active = limit_active; |
106 | atomic_set(&ret->pending, 0); | 123 | atomic_set(&ret->pending, 0); |
107 | if (thresh == 0) | 124 | if (thresh == 0) |
@@ -143,7 +160,8 @@ __btrfs_alloc_workqueue(const char *name, unsigned int flags, int limit_active, | |||
143 | static inline void | 160 | static inline void |
144 | __btrfs_destroy_workqueue(struct __btrfs_workqueue *wq); | 161 | __btrfs_destroy_workqueue(struct __btrfs_workqueue *wq); |
145 | 162 | ||
146 | struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name, | 163 | struct btrfs_workqueue *btrfs_alloc_workqueue(struct btrfs_fs_info *fs_info, |
164 | const char *name, | ||
147 | unsigned int flags, | 165 | unsigned int flags, |
148 | int limit_active, | 166 | int limit_active, |
149 | int thresh) | 167 | int thresh) |
@@ -153,7 +171,8 @@ struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name, | |||
153 | if (!ret) | 171 | if (!ret) |
154 | return NULL; | 172 | return NULL; |
155 | 173 | ||
156 | ret->normal = __btrfs_alloc_workqueue(name, flags & ~WQ_HIGHPRI, | 174 | ret->normal = __btrfs_alloc_workqueue(fs_info, name, |
175 | flags & ~WQ_HIGHPRI, | ||
157 | limit_active, thresh); | 176 | limit_active, thresh); |
158 | if (!ret->normal) { | 177 | if (!ret->normal) { |
159 | kfree(ret); | 178 | kfree(ret); |
@@ -161,8 +180,8 @@ struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name, | |||
161 | } | 180 | } |
162 | 181 | ||
163 | if (flags & WQ_HIGHPRI) { | 182 | if (flags & WQ_HIGHPRI) { |
164 | ret->high = __btrfs_alloc_workqueue(name, flags, limit_active, | 183 | ret->high = __btrfs_alloc_workqueue(fs_info, name, flags, |
165 | thresh); | 184 | limit_active, thresh); |
166 | if (!ret->high) { | 185 | if (!ret->high) { |
167 | __btrfs_destroy_workqueue(ret->normal); | 186 | __btrfs_destroy_workqueue(ret->normal); |
168 | kfree(ret); | 187 | kfree(ret); |
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h index ad4d0647d1a6..8e52484cd461 100644 --- a/fs/btrfs/async-thread.h +++ b/fs/btrfs/async-thread.h | |||
@@ -21,6 +21,7 @@ | |||
21 | #define __BTRFS_ASYNC_THREAD_ | 21 | #define __BTRFS_ASYNC_THREAD_ |
22 | #include <linux/workqueue.h> | 22 | #include <linux/workqueue.h> |
23 | 23 | ||
24 | struct btrfs_fs_info; | ||
24 | struct btrfs_workqueue; | 25 | struct btrfs_workqueue; |
25 | /* Internal use only */ | 26 | /* Internal use only */ |
26 | struct __btrfs_workqueue; | 27 | struct __btrfs_workqueue; |
@@ -67,7 +68,8 @@ BTRFS_WORK_HELPER_PROTO(scrubnc_helper); | |||
67 | BTRFS_WORK_HELPER_PROTO(scrubparity_helper); | 68 | BTRFS_WORK_HELPER_PROTO(scrubparity_helper); |
68 | 69 | ||
69 | 70 | ||
70 | struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name, | 71 | struct btrfs_workqueue *btrfs_alloc_workqueue(struct btrfs_fs_info *fs_info, |
72 | const char *name, | ||
71 | unsigned int flags, | 73 | unsigned int flags, |
72 | int limit_active, | 74 | int limit_active, |
73 | int thresh); | 75 | int thresh); |
@@ -80,4 +82,6 @@ void btrfs_queue_work(struct btrfs_workqueue *wq, | |||
80 | void btrfs_destroy_workqueue(struct btrfs_workqueue *wq); | 82 | void btrfs_destroy_workqueue(struct btrfs_workqueue *wq); |
81 | void btrfs_workqueue_set_max(struct btrfs_workqueue *wq, int max); | 83 | void btrfs_workqueue_set_max(struct btrfs_workqueue *wq, int max); |
82 | void btrfs_set_work_high_priority(struct btrfs_work *work); | 84 | void btrfs_set_work_high_priority(struct btrfs_work *work); |
85 | struct btrfs_fs_info *btrfs_work_owner(struct btrfs_work *work); | ||
86 | struct btrfs_fs_info *btrfs_workqueue_owner(struct __btrfs_workqueue *wq); | ||
83 | #endif | 87 | #endif |
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 8bb3509099e8..2b88439c2ee8 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c | |||
@@ -139,7 +139,7 @@ int __init btrfs_prelim_ref_init(void) | |||
139 | btrfs_prelim_ref_cache = kmem_cache_create("btrfs_prelim_ref", | 139 | btrfs_prelim_ref_cache = kmem_cache_create("btrfs_prelim_ref", |
140 | sizeof(struct __prelim_ref), | 140 | sizeof(struct __prelim_ref), |
141 | 0, | 141 | 0, |
142 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, | 142 | SLAB_MEM_SPREAD, |
143 | NULL); | 143 | NULL); |
144 | if (!btrfs_prelim_ref_cache) | 144 | if (!btrfs_prelim_ref_cache) |
145 | return -ENOMEM; | 145 | return -ENOMEM; |
@@ -361,7 +361,7 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info, | |||
361 | goto out; | 361 | goto out; |
362 | } | 362 | } |
363 | 363 | ||
364 | if (btrfs_test_is_dummy_root(root)) { | 364 | if (btrfs_is_testing(fs_info)) { |
365 | srcu_read_unlock(&fs_info->subvol_srcu, index); | 365 | srcu_read_unlock(&fs_info->subvol_srcu, index); |
366 | ret = -ENOENT; | 366 | ret = -ENOENT; |
367 | goto out; | 367 | goto out; |
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 658c39b70fba..7a4d9c81aa2a 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c | |||
@@ -402,7 +402,10 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, | |||
402 | } | 402 | } |
403 | 403 | ||
404 | ret = btrfs_map_bio(root, WRITE, bio, 0, 1); | 404 | ret = btrfs_map_bio(root, WRITE, bio, 0, 1); |
405 | BUG_ON(ret); /* -ENOMEM */ | 405 | if (ret) { |
406 | bio->bi_error = ret; | ||
407 | bio_endio(bio); | ||
408 | } | ||
406 | 409 | ||
407 | bio_put(bio); | 410 | bio_put(bio); |
408 | 411 | ||
@@ -432,7 +435,10 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, | |||
432 | } | 435 | } |
433 | 436 | ||
434 | ret = btrfs_map_bio(root, WRITE, bio, 0, 1); | 437 | ret = btrfs_map_bio(root, WRITE, bio, 0, 1); |
435 | BUG_ON(ret); /* -ENOMEM */ | 438 | if (ret) { |
439 | bio->bi_error = ret; | ||
440 | bio_endio(bio); | ||
441 | } | ||
436 | 442 | ||
437 | bio_put(bio); | 443 | bio_put(bio); |
438 | return 0; | 444 | return 0; |
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index a85cf7d23309..d1c56c94dd5a 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -1153,14 +1153,14 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, | |||
1153 | 1153 | ||
1154 | ret = update_ref_for_cow(trans, root, buf, cow, &last_ref); | 1154 | ret = update_ref_for_cow(trans, root, buf, cow, &last_ref); |
1155 | if (ret) { | 1155 | if (ret) { |
1156 | btrfs_abort_transaction(trans, root, ret); | 1156 | btrfs_abort_transaction(trans, ret); |
1157 | return ret; | 1157 | return ret; |
1158 | } | 1158 | } |
1159 | 1159 | ||
1160 | if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) { | 1160 | if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) { |
1161 | ret = btrfs_reloc_cow_block(trans, root, buf, cow); | 1161 | ret = btrfs_reloc_cow_block(trans, root, buf, cow); |
1162 | if (ret) { | 1162 | if (ret) { |
1163 | btrfs_abort_transaction(trans, root, ret); | 1163 | btrfs_abort_transaction(trans, ret); |
1164 | return ret; | 1164 | return ret; |
1165 | } | 1165 | } |
1166 | } | 1166 | } |
@@ -1198,7 +1198,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, | |||
1198 | if (last_ref) { | 1198 | if (last_ref) { |
1199 | ret = tree_mod_log_free_eb(root->fs_info, buf); | 1199 | ret = tree_mod_log_free_eb(root->fs_info, buf); |
1200 | if (ret) { | 1200 | if (ret) { |
1201 | btrfs_abort_transaction(trans, root, ret); | 1201 | btrfs_abort_transaction(trans, ret); |
1202 | return ret; | 1202 | return ret; |
1203 | } | 1203 | } |
1204 | } | 1204 | } |
@@ -1505,7 +1505,7 @@ static inline int should_cow_block(struct btrfs_trans_handle *trans, | |||
1505 | struct btrfs_root *root, | 1505 | struct btrfs_root *root, |
1506 | struct extent_buffer *buf) | 1506 | struct extent_buffer *buf) |
1507 | { | 1507 | { |
1508 | if (btrfs_test_is_dummy_root(root)) | 1508 | if (btrfs_is_testing(root->fs_info)) |
1509 | return 0; | 1509 | return 0; |
1510 | 1510 | ||
1511 | /* ensure we can see the force_cow */ | 1511 | /* ensure we can see the force_cow */ |
@@ -1771,6 +1771,14 @@ static noinline int generic_bin_search(struct extent_buffer *eb, | |||
1771 | unsigned long map_len = 0; | 1771 | unsigned long map_len = 0; |
1772 | int err; | 1772 | int err; |
1773 | 1773 | ||
1774 | if (low > high) { | ||
1775 | btrfs_err(eb->fs_info, | ||
1776 | "%s: low (%d) > high (%d) eb %llu owner %llu level %d", | ||
1777 | __func__, low, high, eb->start, | ||
1778 | btrfs_header_owner(eb), btrfs_header_level(eb)); | ||
1779 | return -EINVAL; | ||
1780 | } | ||
1781 | |||
1774 | while (low < high) { | 1782 | while (low < high) { |
1775 | mid = (low + high) / 2; | 1783 | mid = (low + high) / 2; |
1776 | offset = p + mid * item_size; | 1784 | offset = p + mid * item_size; |
@@ -1858,7 +1866,6 @@ static void root_sub_used(struct btrfs_root *root, u32 size) | |||
1858 | 1866 | ||
1859 | /* given a node and slot number, this reads the blocks it points to. The | 1867 | /* given a node and slot number, this reads the blocks it points to. The |
1860 | * extent buffer is returned with a reference taken (but unlocked). | 1868 | * extent buffer is returned with a reference taken (but unlocked). |
1861 | * NULL is returned on error. | ||
1862 | */ | 1869 | */ |
1863 | static noinline struct extent_buffer *read_node_slot(struct btrfs_root *root, | 1870 | static noinline struct extent_buffer *read_node_slot(struct btrfs_root *root, |
1864 | struct extent_buffer *parent, int slot) | 1871 | struct extent_buffer *parent, int slot) |
@@ -1866,19 +1873,16 @@ static noinline struct extent_buffer *read_node_slot(struct btrfs_root *root, | |||
1866 | int level = btrfs_header_level(parent); | 1873 | int level = btrfs_header_level(parent); |
1867 | struct extent_buffer *eb; | 1874 | struct extent_buffer *eb; |
1868 | 1875 | ||
1869 | if (slot < 0) | 1876 | if (slot < 0 || slot >= btrfs_header_nritems(parent)) |
1870 | return NULL; | 1877 | return ERR_PTR(-ENOENT); |
1871 | if (slot >= btrfs_header_nritems(parent)) | ||
1872 | return NULL; | ||
1873 | 1878 | ||
1874 | BUG_ON(level == 0); | 1879 | BUG_ON(level == 0); |
1875 | 1880 | ||
1876 | eb = read_tree_block(root, btrfs_node_blockptr(parent, slot), | 1881 | eb = read_tree_block(root, btrfs_node_blockptr(parent, slot), |
1877 | btrfs_node_ptr_generation(parent, slot)); | 1882 | btrfs_node_ptr_generation(parent, slot)); |
1878 | if (IS_ERR(eb) || !extent_buffer_uptodate(eb)) { | 1883 | if (!IS_ERR(eb) && !extent_buffer_uptodate(eb)) { |
1879 | if (!IS_ERR(eb)) | 1884 | free_extent_buffer(eb); |
1880 | free_extent_buffer(eb); | 1885 | eb = ERR_PTR(-EIO); |
1881 | eb = NULL; | ||
1882 | } | 1886 | } |
1883 | 1887 | ||
1884 | return eb; | 1888 | return eb; |
@@ -1931,8 +1935,8 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, | |||
1931 | 1935 | ||
1932 | /* promote the child to a root */ | 1936 | /* promote the child to a root */ |
1933 | child = read_node_slot(root, mid, 0); | 1937 | child = read_node_slot(root, mid, 0); |
1934 | if (!child) { | 1938 | if (IS_ERR(child)) { |
1935 | ret = -EROFS; | 1939 | ret = PTR_ERR(child); |
1936 | btrfs_handle_fs_error(root->fs_info, ret, NULL); | 1940 | btrfs_handle_fs_error(root->fs_info, ret, NULL); |
1937 | goto enospc; | 1941 | goto enospc; |
1938 | } | 1942 | } |
@@ -1970,6 +1974,9 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, | |||
1970 | return 0; | 1974 | return 0; |
1971 | 1975 | ||
1972 | left = read_node_slot(root, parent, pslot - 1); | 1976 | left = read_node_slot(root, parent, pslot - 1); |
1977 | if (IS_ERR(left)) | ||
1978 | left = NULL; | ||
1979 | |||
1973 | if (left) { | 1980 | if (left) { |
1974 | btrfs_tree_lock(left); | 1981 | btrfs_tree_lock(left); |
1975 | btrfs_set_lock_blocking(left); | 1982 | btrfs_set_lock_blocking(left); |
@@ -1980,7 +1987,11 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, | |||
1980 | goto enospc; | 1987 | goto enospc; |
1981 | } | 1988 | } |
1982 | } | 1989 | } |
1990 | |||
1983 | right = read_node_slot(root, parent, pslot + 1); | 1991 | right = read_node_slot(root, parent, pslot + 1); |
1992 | if (IS_ERR(right)) | ||
1993 | right = NULL; | ||
1994 | |||
1984 | if (right) { | 1995 | if (right) { |
1985 | btrfs_tree_lock(right); | 1996 | btrfs_tree_lock(right); |
1986 | btrfs_set_lock_blocking(right); | 1997 | btrfs_set_lock_blocking(right); |
@@ -2135,6 +2146,8 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans, | |||
2135 | return 1; | 2146 | return 1; |
2136 | 2147 | ||
2137 | left = read_node_slot(root, parent, pslot - 1); | 2148 | left = read_node_slot(root, parent, pslot - 1); |
2149 | if (IS_ERR(left)) | ||
2150 | left = NULL; | ||
2138 | 2151 | ||
2139 | /* first, try to make some room in the middle buffer */ | 2152 | /* first, try to make some room in the middle buffer */ |
2140 | if (left) { | 2153 | if (left) { |
@@ -2185,6 +2198,8 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans, | |||
2185 | free_extent_buffer(left); | 2198 | free_extent_buffer(left); |
2186 | } | 2199 | } |
2187 | right = read_node_slot(root, parent, pslot + 1); | 2200 | right = read_node_slot(root, parent, pslot + 1); |
2201 | if (IS_ERR(right)) | ||
2202 | right = NULL; | ||
2188 | 2203 | ||
2189 | /* | 2204 | /* |
2190 | * then try to empty the right most buffer into the middle | 2205 | * then try to empty the right most buffer into the middle |
@@ -3240,7 +3255,7 @@ static int push_node_left(struct btrfs_trans_handle *trans, | |||
3240 | ret = tree_mod_log_eb_copy(root->fs_info, dst, src, dst_nritems, 0, | 3255 | ret = tree_mod_log_eb_copy(root->fs_info, dst, src, dst_nritems, 0, |
3241 | push_items); | 3256 | push_items); |
3242 | if (ret) { | 3257 | if (ret) { |
3243 | btrfs_abort_transaction(trans, root, ret); | 3258 | btrfs_abort_transaction(trans, ret); |
3244 | return ret; | 3259 | return ret; |
3245 | } | 3260 | } |
3246 | copy_extent_buffer(dst, src, | 3261 | copy_extent_buffer(dst, src, |
@@ -3315,7 +3330,7 @@ static int balance_node_right(struct btrfs_trans_handle *trans, | |||
3315 | ret = tree_mod_log_eb_copy(root->fs_info, dst, src, 0, | 3330 | ret = tree_mod_log_eb_copy(root->fs_info, dst, src, 0, |
3316 | src_nritems - push_items, push_items); | 3331 | src_nritems - push_items, push_items); |
3317 | if (ret) { | 3332 | if (ret) { |
3318 | btrfs_abort_transaction(trans, root, ret); | 3333 | btrfs_abort_transaction(trans, ret); |
3319 | return ret; | 3334 | return ret; |
3320 | } | 3335 | } |
3321 | copy_extent_buffer(dst, src, | 3336 | copy_extent_buffer(dst, src, |
@@ -3519,7 +3534,7 @@ static noinline int split_node(struct btrfs_trans_handle *trans, | |||
3519 | ret = tree_mod_log_eb_copy(root->fs_info, split, c, 0, | 3534 | ret = tree_mod_log_eb_copy(root->fs_info, split, c, 0, |
3520 | mid, c_nritems - mid); | 3535 | mid, c_nritems - mid); |
3521 | if (ret) { | 3536 | if (ret) { |
3522 | btrfs_abort_transaction(trans, root, ret); | 3537 | btrfs_abort_transaction(trans, ret); |
3523 | return ret; | 3538 | return ret; |
3524 | } | 3539 | } |
3525 | copy_extent_buffer(split, c, | 3540 | copy_extent_buffer(split, c, |
@@ -3773,7 +3788,11 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root | |||
3773 | btrfs_assert_tree_locked(path->nodes[1]); | 3788 | btrfs_assert_tree_locked(path->nodes[1]); |
3774 | 3789 | ||
3775 | right = read_node_slot(root, upper, slot + 1); | 3790 | right = read_node_slot(root, upper, slot + 1); |
3776 | if (right == NULL) | 3791 | /* |
3792 | * slot + 1 is not valid or we fail to read the right node, | ||
3793 | * no big deal, just return. | ||
3794 | */ | ||
3795 | if (IS_ERR(right)) | ||
3777 | return 1; | 3796 | return 1; |
3778 | 3797 | ||
3779 | btrfs_tree_lock(right); | 3798 | btrfs_tree_lock(right); |
@@ -4003,7 +4022,11 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root | |||
4003 | btrfs_assert_tree_locked(path->nodes[1]); | 4022 | btrfs_assert_tree_locked(path->nodes[1]); |
4004 | 4023 | ||
4005 | left = read_node_slot(root, path->nodes[1], slot - 1); | 4024 | left = read_node_slot(root, path->nodes[1], slot - 1); |
4006 | if (left == NULL) | 4025 | /* |
4026 | * slot - 1 is not valid or we fail to read the left node, | ||
4027 | * no big deal, just return. | ||
4028 | */ | ||
4029 | if (IS_ERR(left)) | ||
4007 | return 1; | 4030 | return 1; |
4008 | 4031 | ||
4009 | btrfs_tree_lock(left); | 4032 | btrfs_tree_lock(left); |
@@ -5210,7 +5233,10 @@ find_next_key: | |||
5210 | } | 5233 | } |
5211 | btrfs_set_path_blocking(path); | 5234 | btrfs_set_path_blocking(path); |
5212 | cur = read_node_slot(root, cur, slot); | 5235 | cur = read_node_slot(root, cur, slot); |
5213 | BUG_ON(!cur); /* -ENOMEM */ | 5236 | if (IS_ERR(cur)) { |
5237 | ret = PTR_ERR(cur); | ||
5238 | goto out; | ||
5239 | } | ||
5214 | 5240 | ||
5215 | btrfs_tree_read_lock(cur); | 5241 | btrfs_tree_read_lock(cur); |
5216 | 5242 | ||
@@ -5229,15 +5255,21 @@ out: | |||
5229 | return ret; | 5255 | return ret; |
5230 | } | 5256 | } |
5231 | 5257 | ||
5232 | static void tree_move_down(struct btrfs_root *root, | 5258 | static int tree_move_down(struct btrfs_root *root, |
5233 | struct btrfs_path *path, | 5259 | struct btrfs_path *path, |
5234 | int *level, int root_level) | 5260 | int *level, int root_level) |
5235 | { | 5261 | { |
5262 | struct extent_buffer *eb; | ||
5263 | |||
5236 | BUG_ON(*level == 0); | 5264 | BUG_ON(*level == 0); |
5237 | path->nodes[*level - 1] = read_node_slot(root, path->nodes[*level], | 5265 | eb = read_node_slot(root, path->nodes[*level], path->slots[*level]); |
5238 | path->slots[*level]); | 5266 | if (IS_ERR(eb)) |
5267 | return PTR_ERR(eb); | ||
5268 | |||
5269 | path->nodes[*level - 1] = eb; | ||
5239 | path->slots[*level - 1] = 0; | 5270 | path->slots[*level - 1] = 0; |
5240 | (*level)--; | 5271 | (*level)--; |
5272 | return 0; | ||
5241 | } | 5273 | } |
5242 | 5274 | ||
5243 | static int tree_move_next_or_upnext(struct btrfs_root *root, | 5275 | static int tree_move_next_or_upnext(struct btrfs_root *root, |
@@ -5282,8 +5314,7 @@ static int tree_advance(struct btrfs_root *root, | |||
5282 | if (*level == 0 || !allow_down) { | 5314 | if (*level == 0 || !allow_down) { |
5283 | ret = tree_move_next_or_upnext(root, path, level, root_level); | 5315 | ret = tree_move_next_or_upnext(root, path, level, root_level); |
5284 | } else { | 5316 | } else { |
5285 | tree_move_down(root, path, level, root_level); | 5317 | ret = tree_move_down(root, path, level, root_level); |
5286 | ret = 0; | ||
5287 | } | 5318 | } |
5288 | if (ret >= 0) { | 5319 | if (ret >= 0) { |
5289 | if (*level == 0) | 5320 | if (*level == 0) |
@@ -5457,8 +5488,10 @@ int btrfs_compare_trees(struct btrfs_root *left_root, | |||
5457 | left_root_level, | 5488 | left_root_level, |
5458 | advance_left != ADVANCE_ONLY_NEXT, | 5489 | advance_left != ADVANCE_ONLY_NEXT, |
5459 | &left_key); | 5490 | &left_key); |
5460 | if (ret < 0) | 5491 | if (ret == -1) |
5461 | left_end_reached = ADVANCE; | 5492 | left_end_reached = ADVANCE; |
5493 | else if (ret < 0) | ||
5494 | goto out; | ||
5462 | advance_left = 0; | 5495 | advance_left = 0; |
5463 | } | 5496 | } |
5464 | if (advance_right && !right_end_reached) { | 5497 | if (advance_right && !right_end_reached) { |
@@ -5466,8 +5499,10 @@ int btrfs_compare_trees(struct btrfs_root *left_root, | |||
5466 | right_root_level, | 5499 | right_root_level, |
5467 | advance_right != ADVANCE_ONLY_NEXT, | 5500 | advance_right != ADVANCE_ONLY_NEXT, |
5468 | &right_key); | 5501 | &right_key); |
5469 | if (ret < 0) | 5502 | if (ret == -1) |
5470 | right_end_reached = ADVANCE; | 5503 | right_end_reached = ADVANCE; |
5504 | else if (ret < 0) | ||
5505 | goto out; | ||
5471 | advance_right = 0; | 5506 | advance_right = 0; |
5472 | } | 5507 | } |
5473 | 5508 | ||
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 83a6a931af09..f66a0ba9a2a9 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -117,6 +117,7 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes) | |||
117 | #define BTRFS_FS_STATE_REMOUNTING 1 | 117 | #define BTRFS_FS_STATE_REMOUNTING 1 |
118 | #define BTRFS_FS_STATE_TRANS_ABORTED 2 | 118 | #define BTRFS_FS_STATE_TRANS_ABORTED 2 |
119 | #define BTRFS_FS_STATE_DEV_REPLACING 3 | 119 | #define BTRFS_FS_STATE_DEV_REPLACING 3 |
120 | #define BTRFS_FS_STATE_DUMMY_FS_INFO 4 | ||
120 | 121 | ||
121 | #define BTRFS_BACKREF_REV_MAX 256 | 122 | #define BTRFS_BACKREF_REV_MAX 256 |
122 | #define BTRFS_BACKREF_REV_SHIFT 56 | 123 | #define BTRFS_BACKREF_REV_SHIFT 56 |
@@ -144,21 +145,6 @@ struct btrfs_header { | |||
144 | u8 level; | 145 | u8 level; |
145 | } __attribute__ ((__packed__)); | 146 | } __attribute__ ((__packed__)); |
146 | 147 | ||
147 | #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \ | ||
148 | sizeof(struct btrfs_header)) / \ | ||
149 | sizeof(struct btrfs_key_ptr)) | ||
150 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) | ||
151 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->nodesize)) | ||
152 | #define BTRFS_FILE_EXTENT_INLINE_DATA_START \ | ||
153 | (offsetof(struct btrfs_file_extent_item, disk_bytenr)) | ||
154 | #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ | ||
155 | sizeof(struct btrfs_item) - \ | ||
156 | BTRFS_FILE_EXTENT_INLINE_DATA_START) | ||
157 | #define BTRFS_MAX_XATTR_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ | ||
158 | sizeof(struct btrfs_item) -\ | ||
159 | sizeof(struct btrfs_dir_item)) | ||
160 | |||
161 | |||
162 | /* | 148 | /* |
163 | * this is a very generous portion of the super block, giving us | 149 | * this is a very generous portion of the super block, giving us |
164 | * room to translate 14 chunks with 3 stripes each. | 150 | * room to translate 14 chunks with 3 stripes each. |
@@ -1114,12 +1100,11 @@ struct btrfs_subvolume_writers { | |||
1114 | #define BTRFS_ROOT_REF_COWS 1 | 1100 | #define BTRFS_ROOT_REF_COWS 1 |
1115 | #define BTRFS_ROOT_TRACK_DIRTY 2 | 1101 | #define BTRFS_ROOT_TRACK_DIRTY 2 |
1116 | #define BTRFS_ROOT_IN_RADIX 3 | 1102 | #define BTRFS_ROOT_IN_RADIX 3 |
1117 | #define BTRFS_ROOT_DUMMY_ROOT 4 | 1103 | #define BTRFS_ROOT_ORPHAN_ITEM_INSERTED 4 |
1118 | #define BTRFS_ROOT_ORPHAN_ITEM_INSERTED 5 | 1104 | #define BTRFS_ROOT_DEFRAG_RUNNING 5 |
1119 | #define BTRFS_ROOT_DEFRAG_RUNNING 6 | 1105 | #define BTRFS_ROOT_FORCE_COW 6 |
1120 | #define BTRFS_ROOT_FORCE_COW 7 | 1106 | #define BTRFS_ROOT_MULTI_LOG_TASKS 7 |
1121 | #define BTRFS_ROOT_MULTI_LOG_TASKS 8 | 1107 | #define BTRFS_ROOT_DIRTY 8 |
1122 | #define BTRFS_ROOT_DIRTY 9 | ||
1123 | 1108 | ||
1124 | /* | 1109 | /* |
1125 | * in ram representation of the tree. extent_root is used for all allocations | 1110 | * in ram representation of the tree. extent_root is used for all allocations |
@@ -1181,8 +1166,10 @@ struct btrfs_root { | |||
1181 | 1166 | ||
1182 | u64 highest_objectid; | 1167 | u64 highest_objectid; |
1183 | 1168 | ||
1169 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS | ||
1184 | /* only used with CONFIG_BTRFS_FS_RUN_SANITY_TESTS is enabled */ | 1170 | /* only used with CONFIG_BTRFS_FS_RUN_SANITY_TESTS is enabled */ |
1185 | u64 alloc_bytenr; | 1171 | u64 alloc_bytenr; |
1172 | #endif | ||
1186 | 1173 | ||
1187 | u64 defrag_trans_start; | 1174 | u64 defrag_trans_start; |
1188 | struct btrfs_key defrag_progress; | 1175 | struct btrfs_key defrag_progress; |
@@ -1259,6 +1246,39 @@ struct btrfs_root { | |||
1259 | atomic_t qgroup_meta_rsv; | 1246 | atomic_t qgroup_meta_rsv; |
1260 | }; | 1247 | }; |
1261 | 1248 | ||
1249 | static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 blocksize) | ||
1250 | { | ||
1251 | return blocksize - sizeof(struct btrfs_header); | ||
1252 | } | ||
1253 | |||
1254 | static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_root *root) | ||
1255 | { | ||
1256 | return __BTRFS_LEAF_DATA_SIZE(root->nodesize); | ||
1257 | } | ||
1258 | |||
1259 | static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_root *root) | ||
1260 | { | ||
1261 | return BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item); | ||
1262 | } | ||
1263 | |||
1264 | static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_root *root) | ||
1265 | { | ||
1266 | return BTRFS_LEAF_DATA_SIZE(root) / sizeof(struct btrfs_key_ptr); | ||
1267 | } | ||
1268 | |||
1269 | #define BTRFS_FILE_EXTENT_INLINE_DATA_START \ | ||
1270 | (offsetof(struct btrfs_file_extent_item, disk_bytenr)) | ||
1271 | static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_root *root) | ||
1272 | { | ||
1273 | return BTRFS_MAX_ITEM_SIZE(root) - | ||
1274 | BTRFS_FILE_EXTENT_INLINE_DATA_START; | ||
1275 | } | ||
1276 | |||
1277 | static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_root *root) | ||
1278 | { | ||
1279 | return BTRFS_MAX_ITEM_SIZE(root) - sizeof(struct btrfs_dir_item); | ||
1280 | } | ||
1281 | |||
1262 | /* | 1282 | /* |
1263 | * Flags for mount options. | 1283 | * Flags for mount options. |
1264 | * | 1284 | * |
@@ -1299,21 +1319,21 @@ struct btrfs_root { | |||
1299 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) | 1319 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) |
1300 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) | 1320 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) |
1301 | #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt) | 1321 | #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt) |
1302 | #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \ | 1322 | #define btrfs_test_opt(fs_info, opt) ((fs_info)->mount_opt & \ |
1303 | BTRFS_MOUNT_##opt) | 1323 | BTRFS_MOUNT_##opt) |
1304 | 1324 | ||
1305 | #define btrfs_set_and_info(root, opt, fmt, args...) \ | 1325 | #define btrfs_set_and_info(fs_info, opt, fmt, args...) \ |
1306 | { \ | 1326 | { \ |
1307 | if (!btrfs_test_opt(root, opt)) \ | 1327 | if (!btrfs_test_opt(fs_info, opt)) \ |
1308 | btrfs_info(root->fs_info, fmt, ##args); \ | 1328 | btrfs_info(fs_info, fmt, ##args); \ |
1309 | btrfs_set_opt(root->fs_info->mount_opt, opt); \ | 1329 | btrfs_set_opt(fs_info->mount_opt, opt); \ |
1310 | } | 1330 | } |
1311 | 1331 | ||
1312 | #define btrfs_clear_and_info(root, opt, fmt, args...) \ | 1332 | #define btrfs_clear_and_info(fs_info, opt, fmt, args...) \ |
1313 | { \ | 1333 | { \ |
1314 | if (btrfs_test_opt(root, opt)) \ | 1334 | if (btrfs_test_opt(fs_info, opt)) \ |
1315 | btrfs_info(root->fs_info, fmt, ##args); \ | 1335 | btrfs_info(fs_info, fmt, ##args); \ |
1316 | btrfs_clear_opt(root->fs_info->mount_opt, opt); \ | 1336 | btrfs_clear_opt(fs_info->mount_opt, opt); \ |
1317 | } | 1337 | } |
1318 | 1338 | ||
1319 | #ifdef CONFIG_BTRFS_DEBUG | 1339 | #ifdef CONFIG_BTRFS_DEBUG |
@@ -1321,9 +1341,9 @@ static inline int | |||
1321 | btrfs_should_fragment_free_space(struct btrfs_root *root, | 1341 | btrfs_should_fragment_free_space(struct btrfs_root *root, |
1322 | struct btrfs_block_group_cache *block_group) | 1342 | struct btrfs_block_group_cache *block_group) |
1323 | { | 1343 | { |
1324 | return (btrfs_test_opt(root, FRAGMENT_METADATA) && | 1344 | return (btrfs_test_opt(root->fs_info, FRAGMENT_METADATA) && |
1325 | block_group->flags & BTRFS_BLOCK_GROUP_METADATA) || | 1345 | block_group->flags & BTRFS_BLOCK_GROUP_METADATA) || |
1326 | (btrfs_test_opt(root, FRAGMENT_DATA) && | 1346 | (btrfs_test_opt(root->fs_info, FRAGMENT_DATA) && |
1327 | block_group->flags & BTRFS_BLOCK_GROUP_DATA); | 1347 | block_group->flags & BTRFS_BLOCK_GROUP_DATA); |
1328 | } | 1348 | } |
1329 | #endif | 1349 | #endif |
@@ -2886,9 +2906,6 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info, | |||
2886 | int btrfs_old_root_level(struct btrfs_root *root, u64 time_seq); | 2906 | int btrfs_old_root_level(struct btrfs_root *root, u64 time_seq); |
2887 | 2907 | ||
2888 | /* root-item.c */ | 2908 | /* root-item.c */ |
2889 | int btrfs_find_root_ref(struct btrfs_root *tree_root, | ||
2890 | struct btrfs_path *path, | ||
2891 | u64 root_id, u64 ref_id); | ||
2892 | int btrfs_add_root_ref(struct btrfs_trans_handle *trans, | 2909 | int btrfs_add_root_ref(struct btrfs_trans_handle *trans, |
2893 | struct btrfs_root *tree_root, | 2910 | struct btrfs_root *tree_root, |
2894 | u64 root_id, u64 ref_id, u64 dirid, u64 sequence, | 2911 | u64 root_id, u64 ref_id, u64 dirid, u64 sequence, |
@@ -3362,23 +3379,23 @@ const char *btrfs_decode_error(int errno); | |||
3362 | 3379 | ||
3363 | __cold | 3380 | __cold |
3364 | void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, | 3381 | void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, |
3365 | struct btrfs_root *root, const char *function, | 3382 | const char *function, |
3366 | unsigned int line, int errno); | 3383 | unsigned int line, int errno); |
3367 | 3384 | ||
3368 | /* | 3385 | /* |
3369 | * Call btrfs_abort_transaction as early as possible when an error condition is | 3386 | * Call btrfs_abort_transaction as early as possible when an error condition is |
3370 | * detected, that way the exact line number is reported. | 3387 | * detected, that way the exact line number is reported. |
3371 | */ | 3388 | */ |
3372 | #define btrfs_abort_transaction(trans, root, errno) \ | 3389 | #define btrfs_abort_transaction(trans, errno) \ |
3373 | do { \ | 3390 | do { \ |
3374 | /* Report first abort since mount */ \ | 3391 | /* Report first abort since mount */ \ |
3375 | if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \ | 3392 | if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \ |
3376 | &((root)->fs_info->fs_state))) { \ | 3393 | &((trans)->fs_info->fs_state))) { \ |
3377 | WARN(1, KERN_DEBUG \ | 3394 | WARN(1, KERN_DEBUG \ |
3378 | "BTRFS: Transaction aborted (error %d)\n", \ | 3395 | "BTRFS: Transaction aborted (error %d)\n", \ |
3379 | (errno)); \ | 3396 | (errno)); \ |
3380 | } \ | 3397 | } \ |
3381 | __btrfs_abort_transaction((trans), (root), __func__, \ | 3398 | __btrfs_abort_transaction((trans), __func__, \ |
3382 | __LINE__, (errno)); \ | 3399 | __LINE__, (errno)); \ |
3383 | } while (0) | 3400 | } while (0) |
3384 | 3401 | ||
@@ -3610,13 +3627,13 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info) | |||
3610 | void btrfs_test_destroy_inode(struct inode *inode); | 3627 | void btrfs_test_destroy_inode(struct inode *inode); |
3611 | #endif | 3628 | #endif |
3612 | 3629 | ||
3613 | static inline int btrfs_test_is_dummy_root(struct btrfs_root *root) | 3630 | static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info) |
3614 | { | 3631 | { |
3615 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS | 3632 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
3616 | if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state))) | 3633 | if (unlikely(test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, |
3634 | &fs_info->fs_state))) | ||
3617 | return 1; | 3635 | return 1; |
3618 | #endif | 3636 | #endif |
3619 | return 0; | 3637 | return 0; |
3620 | } | 3638 | } |
3621 | |||
3622 | #endif | 3639 | #endif |
diff --git a/fs/btrfs/dedupe.h b/fs/btrfs/dedupe.h new file mode 100644 index 000000000000..83ebfe28da9e --- /dev/null +++ b/fs/btrfs/dedupe.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Fujitsu. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public | ||
6 | * License v2 as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | * General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public | ||
14 | * License along with this program; if not, write to the | ||
15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
16 | * Boston, MA 021110-1307, USA. | ||
17 | */ | ||
18 | |||
19 | #ifndef __BTRFS_DEDUPE__ | ||
20 | #define __BTRFS_DEDUPE__ | ||
21 | |||
22 | /* later in-band dedupe will expand this struct */ | ||
23 | struct btrfs_dedupe_hash; | ||
24 | #endif | ||
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index dd3c040139a2..3eeb9cd8cfa5 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c | |||
@@ -34,7 +34,7 @@ int __init btrfs_delayed_inode_init(void) | |||
34 | delayed_node_cache = kmem_cache_create("btrfs_delayed_node", | 34 | delayed_node_cache = kmem_cache_create("btrfs_delayed_node", |
35 | sizeof(struct btrfs_delayed_node), | 35 | sizeof(struct btrfs_delayed_node), |
36 | 0, | 36 | 0, |
37 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, | 37 | SLAB_MEM_SPREAD, |
38 | NULL); | 38 | NULL); |
39 | if (!delayed_node_cache) | 39 | if (!delayed_node_cache) |
40 | return -ENOMEM; | 40 | return -ENOMEM; |
@@ -1170,7 +1170,7 @@ static int __btrfs_run_delayed_items(struct btrfs_trans_handle *trans, | |||
1170 | if (ret) { | 1170 | if (ret) { |
1171 | btrfs_release_delayed_node(curr_node); | 1171 | btrfs_release_delayed_node(curr_node); |
1172 | curr_node = NULL; | 1172 | curr_node = NULL; |
1173 | btrfs_abort_transaction(trans, root, ret); | 1173 | btrfs_abort_transaction(trans, ret); |
1174 | break; | 1174 | break; |
1175 | } | 1175 | } |
1176 | 1176 | ||
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 430b3689b112..b6d210e7a993 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c | |||
@@ -606,7 +606,8 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info, | |||
606 | qrecord->num_bytes = num_bytes; | 606 | qrecord->num_bytes = num_bytes; |
607 | qrecord->old_roots = NULL; | 607 | qrecord->old_roots = NULL; |
608 | 608 | ||
609 | qexisting = btrfs_qgroup_insert_dirty_extent(delayed_refs, | 609 | qexisting = btrfs_qgroup_insert_dirty_extent(fs_info, |
610 | delayed_refs, | ||
610 | qrecord); | 611 | qrecord); |
611 | if (qexisting) | 612 | if (qexisting) |
612 | kfree(qrecord); | 613 | kfree(qrecord); |
@@ -615,7 +616,7 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info, | |||
615 | spin_lock_init(&head_ref->lock); | 616 | spin_lock_init(&head_ref->lock); |
616 | mutex_init(&head_ref->mutex); | 617 | mutex_init(&head_ref->mutex); |
617 | 618 | ||
618 | trace_add_delayed_ref_head(ref, head_ref, action); | 619 | trace_add_delayed_ref_head(fs_info, ref, head_ref, action); |
619 | 620 | ||
620 | existing = htree_insert(&delayed_refs->href_root, | 621 | existing = htree_insert(&delayed_refs->href_root, |
621 | &head_ref->href_node); | 622 | &head_ref->href_node); |
@@ -682,7 +683,7 @@ add_delayed_tree_ref(struct btrfs_fs_info *fs_info, | |||
682 | ref->type = BTRFS_TREE_BLOCK_REF_KEY; | 683 | ref->type = BTRFS_TREE_BLOCK_REF_KEY; |
683 | full_ref->level = level; | 684 | full_ref->level = level; |
684 | 685 | ||
685 | trace_add_delayed_tree_ref(ref, full_ref, action); | 686 | trace_add_delayed_tree_ref(fs_info, ref, full_ref, action); |
686 | 687 | ||
687 | ret = add_delayed_ref_tail_merge(trans, delayed_refs, head_ref, ref); | 688 | ret = add_delayed_ref_tail_merge(trans, delayed_refs, head_ref, ref); |
688 | 689 | ||
@@ -739,7 +740,7 @@ add_delayed_data_ref(struct btrfs_fs_info *fs_info, | |||
739 | full_ref->objectid = owner; | 740 | full_ref->objectid = owner; |
740 | full_ref->offset = offset; | 741 | full_ref->offset = offset; |
741 | 742 | ||
742 | trace_add_delayed_data_ref(ref, full_ref, action); | 743 | trace_add_delayed_data_ref(fs_info, ref, full_ref, action); |
743 | 744 | ||
744 | ret = add_delayed_ref_tail_merge(trans, delayed_refs, head_ref, ref); | 745 | ret = add_delayed_ref_tail_merge(trans, delayed_refs, head_ref, ref); |
745 | 746 | ||
@@ -940,28 +941,28 @@ int btrfs_delayed_ref_init(void) | |||
940 | btrfs_delayed_ref_head_cachep = kmem_cache_create( | 941 | btrfs_delayed_ref_head_cachep = kmem_cache_create( |
941 | "btrfs_delayed_ref_head", | 942 | "btrfs_delayed_ref_head", |
942 | sizeof(struct btrfs_delayed_ref_head), 0, | 943 | sizeof(struct btrfs_delayed_ref_head), 0, |
943 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 944 | SLAB_MEM_SPREAD, NULL); |
944 | if (!btrfs_delayed_ref_head_cachep) | 945 | if (!btrfs_delayed_ref_head_cachep) |
945 | goto fail; | 946 | goto fail; |
946 | 947 | ||
947 | btrfs_delayed_tree_ref_cachep = kmem_cache_create( | 948 | btrfs_delayed_tree_ref_cachep = kmem_cache_create( |
948 | "btrfs_delayed_tree_ref", | 949 | "btrfs_delayed_tree_ref", |
949 | sizeof(struct btrfs_delayed_tree_ref), 0, | 950 | sizeof(struct btrfs_delayed_tree_ref), 0, |
950 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 951 | SLAB_MEM_SPREAD, NULL); |
951 | if (!btrfs_delayed_tree_ref_cachep) | 952 | if (!btrfs_delayed_tree_ref_cachep) |
952 | goto fail; | 953 | goto fail; |
953 | 954 | ||
954 | btrfs_delayed_data_ref_cachep = kmem_cache_create( | 955 | btrfs_delayed_data_ref_cachep = kmem_cache_create( |
955 | "btrfs_delayed_data_ref", | 956 | "btrfs_delayed_data_ref", |
956 | sizeof(struct btrfs_delayed_data_ref), 0, | 957 | sizeof(struct btrfs_delayed_data_ref), 0, |
957 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 958 | SLAB_MEM_SPREAD, NULL); |
958 | if (!btrfs_delayed_data_ref_cachep) | 959 | if (!btrfs_delayed_data_ref_cachep) |
959 | goto fail; | 960 | goto fail; |
960 | 961 | ||
961 | btrfs_delayed_extent_op_cachep = kmem_cache_create( | 962 | btrfs_delayed_extent_op_cachep = kmem_cache_create( |
962 | "btrfs_delayed_extent_op", | 963 | "btrfs_delayed_extent_op", |
963 | sizeof(struct btrfs_delayed_extent_op), 0, | 964 | sizeof(struct btrfs_delayed_extent_op), 0, |
964 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 965 | SLAB_MEM_SPREAD, NULL); |
965 | if (!btrfs_delayed_extent_op_cachep) | 966 | if (!btrfs_delayed_extent_op_cachep) |
966 | goto fail; | 967 | goto fail; |
967 | 968 | ||
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 63ef9cdf0144..e9bbff3c0029 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c | |||
@@ -142,7 +142,7 @@ no_valid_dev_replace_entry_found: | |||
142 | * missing | 142 | * missing |
143 | */ | 143 | */ |
144 | if (!dev_replace->srcdev && | 144 | if (!dev_replace->srcdev && |
145 | !btrfs_test_opt(dev_root, DEGRADED)) { | 145 | !btrfs_test_opt(dev_root->fs_info, DEGRADED)) { |
146 | ret = -EIO; | 146 | ret = -EIO; |
147 | btrfs_warn(fs_info, | 147 | btrfs_warn(fs_info, |
148 | "cannot mount because device replace operation is ongoing and"); | 148 | "cannot mount because device replace operation is ongoing and"); |
@@ -151,7 +151,7 @@ no_valid_dev_replace_entry_found: | |||
151 | src_devid); | 151 | src_devid); |
152 | } | 152 | } |
153 | if (!dev_replace->tgtdev && | 153 | if (!dev_replace->tgtdev && |
154 | !btrfs_test_opt(dev_root, DEGRADED)) { | 154 | !btrfs_test_opt(dev_root->fs_info, DEGRADED)) { |
155 | ret = -EIO; | 155 | ret = -EIO; |
156 | btrfs_warn(fs_info, | 156 | btrfs_warn(fs_info, |
157 | "cannot mount because device replace operation is ongoing and"); | 157 | "cannot mount because device replace operation is ongoing and"); |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 60ce1190307b..ff2362dca91a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -101,7 +101,7 @@ int __init btrfs_end_io_wq_init(void) | |||
101 | btrfs_end_io_wq_cache = kmem_cache_create("btrfs_end_io_wq", | 101 | btrfs_end_io_wq_cache = kmem_cache_create("btrfs_end_io_wq", |
102 | sizeof(struct btrfs_end_io_wq), | 102 | sizeof(struct btrfs_end_io_wq), |
103 | 0, | 103 | 0, |
104 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, | 104 | SLAB_MEM_SPREAD, |
105 | NULL); | 105 | NULL); |
106 | if (!btrfs_end_io_wq_cache) | 106 | if (!btrfs_end_io_wq_cache) |
107 | return -ENOMEM; | 107 | return -ENOMEM; |
@@ -1146,7 +1146,7 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info, | |||
1146 | struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, | 1146 | struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, |
1147 | u64 bytenr) | 1147 | u64 bytenr) |
1148 | { | 1148 | { |
1149 | if (btrfs_test_is_dummy_root(root)) | 1149 | if (btrfs_is_testing(root->fs_info)) |
1150 | return alloc_test_extent_buffer(root->fs_info, bytenr, | 1150 | return alloc_test_extent_buffer(root->fs_info, bytenr, |
1151 | root->nodesize); | 1151 | root->nodesize); |
1152 | return alloc_extent_buffer(root->fs_info, bytenr); | 1152 | return alloc_extent_buffer(root->fs_info, bytenr); |
@@ -1233,6 +1233,7 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize, | |||
1233 | struct btrfs_root *root, struct btrfs_fs_info *fs_info, | 1233 | struct btrfs_root *root, struct btrfs_fs_info *fs_info, |
1234 | u64 objectid) | 1234 | u64 objectid) |
1235 | { | 1235 | { |
1236 | bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); | ||
1236 | root->node = NULL; | 1237 | root->node = NULL; |
1237 | root->commit_root = NULL; | 1238 | root->commit_root = NULL; |
1238 | root->sectorsize = sectorsize; | 1239 | root->sectorsize = sectorsize; |
@@ -1287,14 +1288,14 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize, | |||
1287 | root->log_transid = 0; | 1288 | root->log_transid = 0; |
1288 | root->log_transid_committed = -1; | 1289 | root->log_transid_committed = -1; |
1289 | root->last_log_commit = 0; | 1290 | root->last_log_commit = 0; |
1290 | if (fs_info) | 1291 | if (!dummy) |
1291 | extent_io_tree_init(&root->dirty_log_pages, | 1292 | extent_io_tree_init(&root->dirty_log_pages, |
1292 | fs_info->btree_inode->i_mapping); | 1293 | fs_info->btree_inode->i_mapping); |
1293 | 1294 | ||
1294 | memset(&root->root_key, 0, sizeof(root->root_key)); | 1295 | memset(&root->root_key, 0, sizeof(root->root_key)); |
1295 | memset(&root->root_item, 0, sizeof(root->root_item)); | 1296 | memset(&root->root_item, 0, sizeof(root->root_item)); |
1296 | memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); | 1297 | memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); |
1297 | if (fs_info) | 1298 | if (!dummy) |
1298 | root->defrag_trans_start = fs_info->generation; | 1299 | root->defrag_trans_start = fs_info->generation; |
1299 | else | 1300 | else |
1300 | root->defrag_trans_start = 0; | 1301 | root->defrag_trans_start = 0; |
@@ -1315,17 +1316,20 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info, | |||
1315 | 1316 | ||
1316 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS | 1317 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
1317 | /* Should only be used by the testing infrastructure */ | 1318 | /* Should only be used by the testing infrastructure */ |
1318 | struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize) | 1319 | struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info, |
1320 | u32 sectorsize, u32 nodesize) | ||
1319 | { | 1321 | { |
1320 | struct btrfs_root *root; | 1322 | struct btrfs_root *root; |
1321 | 1323 | ||
1322 | root = btrfs_alloc_root(NULL, GFP_KERNEL); | 1324 | if (!fs_info) |
1325 | return ERR_PTR(-EINVAL); | ||
1326 | |||
1327 | root = btrfs_alloc_root(fs_info, GFP_KERNEL); | ||
1323 | if (!root) | 1328 | if (!root) |
1324 | return ERR_PTR(-ENOMEM); | 1329 | return ERR_PTR(-ENOMEM); |
1325 | /* We don't use the stripesize in selftest, set it as sectorsize */ | 1330 | /* We don't use the stripesize in selftest, set it as sectorsize */ |
1326 | __setup_root(nodesize, sectorsize, sectorsize, root, NULL, | 1331 | __setup_root(nodesize, sectorsize, sectorsize, root, fs_info, |
1327 | BTRFS_ROOT_TREE_OBJECTID); | 1332 | BTRFS_ROOT_TREE_OBJECTID); |
1328 | set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state); | ||
1329 | root->alloc_bytenr = 0; | 1333 | root->alloc_bytenr = 0; |
1330 | 1334 | ||
1331 | return root; | 1335 | return root; |
@@ -1600,14 +1604,14 @@ int btrfs_init_fs_root(struct btrfs_root *root) | |||
1600 | 1604 | ||
1601 | ret = get_anon_bdev(&root->anon_dev); | 1605 | ret = get_anon_bdev(&root->anon_dev); |
1602 | if (ret) | 1606 | if (ret) |
1603 | goto free_writers; | 1607 | goto fail; |
1604 | 1608 | ||
1605 | mutex_lock(&root->objectid_mutex); | 1609 | mutex_lock(&root->objectid_mutex); |
1606 | ret = btrfs_find_highest_objectid(root, | 1610 | ret = btrfs_find_highest_objectid(root, |
1607 | &root->highest_objectid); | 1611 | &root->highest_objectid); |
1608 | if (ret) { | 1612 | if (ret) { |
1609 | mutex_unlock(&root->objectid_mutex); | 1613 | mutex_unlock(&root->objectid_mutex); |
1610 | goto free_root_dev; | 1614 | goto fail; |
1611 | } | 1615 | } |
1612 | 1616 | ||
1613 | ASSERT(root->highest_objectid <= BTRFS_LAST_FREE_OBJECTID); | 1617 | ASSERT(root->highest_objectid <= BTRFS_LAST_FREE_OBJECTID); |
@@ -1615,14 +1619,8 @@ int btrfs_init_fs_root(struct btrfs_root *root) | |||
1615 | mutex_unlock(&root->objectid_mutex); | 1619 | mutex_unlock(&root->objectid_mutex); |
1616 | 1620 | ||
1617 | return 0; | 1621 | return 0; |
1618 | |||
1619 | free_root_dev: | ||
1620 | free_anon_bdev(root->anon_dev); | ||
1621 | free_writers: | ||
1622 | btrfs_free_subvolume_writers(root->subv_writers); | ||
1623 | fail: | 1622 | fail: |
1624 | kfree(root->free_ino_ctl); | 1623 | /* the caller is responsible to call free_fs_root */ |
1625 | kfree(root->free_ino_pinned); | ||
1626 | return ret; | 1624 | return ret; |
1627 | } | 1625 | } |
1628 | 1626 | ||
@@ -2316,17 +2314,19 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, | |||
2316 | unsigned int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND; | 2314 | unsigned int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND; |
2317 | 2315 | ||
2318 | fs_info->workers = | 2316 | fs_info->workers = |
2319 | btrfs_alloc_workqueue("worker", flags | WQ_HIGHPRI, | 2317 | btrfs_alloc_workqueue(fs_info, "worker", |
2320 | max_active, 16); | 2318 | flags | WQ_HIGHPRI, max_active, 16); |
2321 | 2319 | ||
2322 | fs_info->delalloc_workers = | 2320 | fs_info->delalloc_workers = |
2323 | btrfs_alloc_workqueue("delalloc", flags, max_active, 2); | 2321 | btrfs_alloc_workqueue(fs_info, "delalloc", |
2322 | flags, max_active, 2); | ||
2324 | 2323 | ||
2325 | fs_info->flush_workers = | 2324 | fs_info->flush_workers = |
2326 | btrfs_alloc_workqueue("flush_delalloc", flags, max_active, 0); | 2325 | btrfs_alloc_workqueue(fs_info, "flush_delalloc", |
2326 | flags, max_active, 0); | ||
2327 | 2327 | ||
2328 | fs_info->caching_workers = | 2328 | fs_info->caching_workers = |
2329 | btrfs_alloc_workqueue("cache", flags, max_active, 0); | 2329 | btrfs_alloc_workqueue(fs_info, "cache", flags, max_active, 0); |
2330 | 2330 | ||
2331 | /* | 2331 | /* |
2332 | * a higher idle thresh on the submit workers makes it much more | 2332 | * a higher idle thresh on the submit workers makes it much more |
@@ -2334,41 +2334,48 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, | |||
2334 | * devices | 2334 | * devices |
2335 | */ | 2335 | */ |
2336 | fs_info->submit_workers = | 2336 | fs_info->submit_workers = |
2337 | btrfs_alloc_workqueue("submit", flags, | 2337 | btrfs_alloc_workqueue(fs_info, "submit", flags, |
2338 | min_t(u64, fs_devices->num_devices, | 2338 | min_t(u64, fs_devices->num_devices, |
2339 | max_active), 64); | 2339 | max_active), 64); |
2340 | 2340 | ||
2341 | fs_info->fixup_workers = | 2341 | fs_info->fixup_workers = |
2342 | btrfs_alloc_workqueue("fixup", flags, 1, 0); | 2342 | btrfs_alloc_workqueue(fs_info, "fixup", flags, 1, 0); |
2343 | 2343 | ||
2344 | /* | 2344 | /* |
2345 | * endios are largely parallel and should have a very | 2345 | * endios are largely parallel and should have a very |
2346 | * low idle thresh | 2346 | * low idle thresh |
2347 | */ | 2347 | */ |
2348 | fs_info->endio_workers = | 2348 | fs_info->endio_workers = |
2349 | btrfs_alloc_workqueue("endio", flags, max_active, 4); | 2349 | btrfs_alloc_workqueue(fs_info, "endio", flags, max_active, 4); |
2350 | fs_info->endio_meta_workers = | 2350 | fs_info->endio_meta_workers = |
2351 | btrfs_alloc_workqueue("endio-meta", flags, max_active, 4); | 2351 | btrfs_alloc_workqueue(fs_info, "endio-meta", flags, |
2352 | max_active, 4); | ||
2352 | fs_info->endio_meta_write_workers = | 2353 | fs_info->endio_meta_write_workers = |
2353 | btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2); | 2354 | btrfs_alloc_workqueue(fs_info, "endio-meta-write", flags, |
2355 | max_active, 2); | ||
2354 | fs_info->endio_raid56_workers = | 2356 | fs_info->endio_raid56_workers = |
2355 | btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4); | 2357 | btrfs_alloc_workqueue(fs_info, "endio-raid56", flags, |
2358 | max_active, 4); | ||
2356 | fs_info->endio_repair_workers = | 2359 | fs_info->endio_repair_workers = |
2357 | btrfs_alloc_workqueue("endio-repair", flags, 1, 0); | 2360 | btrfs_alloc_workqueue(fs_info, "endio-repair", flags, 1, 0); |
2358 | fs_info->rmw_workers = | 2361 | fs_info->rmw_workers = |
2359 | btrfs_alloc_workqueue("rmw", flags, max_active, 2); | 2362 | btrfs_alloc_workqueue(fs_info, "rmw", flags, max_active, 2); |
2360 | fs_info->endio_write_workers = | 2363 | fs_info->endio_write_workers = |
2361 | btrfs_alloc_workqueue("endio-write", flags, max_active, 2); | 2364 | btrfs_alloc_workqueue(fs_info, "endio-write", flags, |
2365 | max_active, 2); | ||
2362 | fs_info->endio_freespace_worker = | 2366 | fs_info->endio_freespace_worker = |
2363 | btrfs_alloc_workqueue("freespace-write", flags, max_active, 0); | 2367 | btrfs_alloc_workqueue(fs_info, "freespace-write", flags, |
2368 | max_active, 0); | ||
2364 | fs_info->delayed_workers = | 2369 | fs_info->delayed_workers = |
2365 | btrfs_alloc_workqueue("delayed-meta", flags, max_active, 0); | 2370 | btrfs_alloc_workqueue(fs_info, "delayed-meta", flags, |
2371 | max_active, 0); | ||
2366 | fs_info->readahead_workers = | 2372 | fs_info->readahead_workers = |
2367 | btrfs_alloc_workqueue("readahead", flags, max_active, 2); | 2373 | btrfs_alloc_workqueue(fs_info, "readahead", flags, |
2374 | max_active, 2); | ||
2368 | fs_info->qgroup_rescan_workers = | 2375 | fs_info->qgroup_rescan_workers = |
2369 | btrfs_alloc_workqueue("qgroup-rescan", flags, 1, 0); | 2376 | btrfs_alloc_workqueue(fs_info, "qgroup-rescan", flags, 1, 0); |
2370 | fs_info->extent_workers = | 2377 | fs_info->extent_workers = |
2371 | btrfs_alloc_workqueue("extent-refs", flags, | 2378 | btrfs_alloc_workqueue(fs_info, "extent-refs", flags, |
2372 | min_t(u64, fs_devices->num_devices, | 2379 | min_t(u64, fs_devices->num_devices, |
2373 | max_active), 8); | 2380 | max_active), 8); |
2374 | 2381 | ||
@@ -3016,8 +3023,8 @@ retry_root_backup: | |||
3016 | if (IS_ERR(fs_info->transaction_kthread)) | 3023 | if (IS_ERR(fs_info->transaction_kthread)) |
3017 | goto fail_cleaner; | 3024 | goto fail_cleaner; |
3018 | 3025 | ||
3019 | if (!btrfs_test_opt(tree_root, SSD) && | 3026 | if (!btrfs_test_opt(tree_root->fs_info, SSD) && |
3020 | !btrfs_test_opt(tree_root, NOSSD) && | 3027 | !btrfs_test_opt(tree_root->fs_info, NOSSD) && |
3021 | !fs_info->fs_devices->rotating) { | 3028 | !fs_info->fs_devices->rotating) { |
3022 | btrfs_info(fs_info, "detected SSD devices, enabling SSD mode"); | 3029 | btrfs_info(fs_info, "detected SSD devices, enabling SSD mode"); |
3023 | btrfs_set_opt(fs_info->mount_opt, SSD); | 3030 | btrfs_set_opt(fs_info->mount_opt, SSD); |
@@ -3030,9 +3037,9 @@ retry_root_backup: | |||
3030 | btrfs_apply_pending_changes(fs_info); | 3037 | btrfs_apply_pending_changes(fs_info); |
3031 | 3038 | ||
3032 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY | 3039 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
3033 | if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) { | 3040 | if (btrfs_test_opt(tree_root->fs_info, CHECK_INTEGRITY)) { |
3034 | ret = btrfsic_mount(tree_root, fs_devices, | 3041 | ret = btrfsic_mount(tree_root, fs_devices, |
3035 | btrfs_test_opt(tree_root, | 3042 | btrfs_test_opt(tree_root->fs_info, |
3036 | CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ? | 3043 | CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ? |
3037 | 1 : 0, | 3044 | 1 : 0, |
3038 | fs_info->check_integrity_print_mask); | 3045 | fs_info->check_integrity_print_mask); |
@@ -3048,7 +3055,7 @@ retry_root_backup: | |||
3048 | 3055 | ||
3049 | /* do not make disk changes in broken FS or nologreplay is given */ | 3056 | /* do not make disk changes in broken FS or nologreplay is given */ |
3050 | if (btrfs_super_log_root(disk_super) != 0 && | 3057 | if (btrfs_super_log_root(disk_super) != 0 && |
3051 | !btrfs_test_opt(tree_root, NOLOGREPLAY)) { | 3058 | !btrfs_test_opt(tree_root->fs_info, NOLOGREPLAY)) { |
3052 | ret = btrfs_replay_log(fs_info, fs_devices); | 3059 | ret = btrfs_replay_log(fs_info, fs_devices); |
3053 | if (ret) { | 3060 | if (ret) { |
3054 | err = ret; | 3061 | err = ret; |
@@ -3089,7 +3096,7 @@ retry_root_backup: | |||
3089 | if (sb->s_flags & MS_RDONLY) | 3096 | if (sb->s_flags & MS_RDONLY) |
3090 | return 0; | 3097 | return 0; |
3091 | 3098 | ||
3092 | if (btrfs_test_opt(tree_root, FREE_SPACE_TREE) && | 3099 | if (btrfs_test_opt(tree_root->fs_info, FREE_SPACE_TREE) && |
3093 | !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { | 3100 | !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { |
3094 | btrfs_info(fs_info, "creating free space tree"); | 3101 | btrfs_info(fs_info, "creating free space tree"); |
3095 | ret = btrfs_create_free_space_tree(fs_info); | 3102 | ret = btrfs_create_free_space_tree(fs_info); |
@@ -3126,7 +3133,7 @@ retry_root_backup: | |||
3126 | 3133 | ||
3127 | btrfs_qgroup_rescan_resume(fs_info); | 3134 | btrfs_qgroup_rescan_resume(fs_info); |
3128 | 3135 | ||
3129 | if (btrfs_test_opt(tree_root, CLEAR_CACHE) && | 3136 | if (btrfs_test_opt(tree_root->fs_info, CLEAR_CACHE) && |
3130 | btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { | 3137 | btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { |
3131 | btrfs_info(fs_info, "clearing free space tree"); | 3138 | btrfs_info(fs_info, "clearing free space tree"); |
3132 | ret = btrfs_clear_free_space_tree(fs_info); | 3139 | ret = btrfs_clear_free_space_tree(fs_info); |
@@ -3147,7 +3154,7 @@ retry_root_backup: | |||
3147 | close_ctree(tree_root); | 3154 | close_ctree(tree_root); |
3148 | return ret; | 3155 | return ret; |
3149 | } | 3156 | } |
3150 | } else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) || | 3157 | } else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) || |
3151 | fs_info->generation != | 3158 | fs_info->generation != |
3152 | btrfs_super_uuid_tree_generation(disk_super)) { | 3159 | btrfs_super_uuid_tree_generation(disk_super)) { |
3153 | btrfs_info(fs_info, "checking UUID tree"); | 3160 | btrfs_info(fs_info, "checking UUID tree"); |
@@ -3224,7 +3231,7 @@ fail: | |||
3224 | return err; | 3231 | return err; |
3225 | 3232 | ||
3226 | recovery_tree_root: | 3233 | recovery_tree_root: |
3227 | if (!btrfs_test_opt(tree_root, USEBACKUPROOT)) | 3234 | if (!btrfs_test_opt(tree_root->fs_info, USEBACKUPROOT)) |
3228 | goto fail_tree_roots; | 3235 | goto fail_tree_roots; |
3229 | 3236 | ||
3230 | free_root_pointers(fs_info, 0); | 3237 | free_root_pointers(fs_info, 0); |
@@ -3639,7 +3646,7 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors) | |||
3639 | int total_errors = 0; | 3646 | int total_errors = 0; |
3640 | u64 flags; | 3647 | u64 flags; |
3641 | 3648 | ||
3642 | do_barriers = !btrfs_test_opt(root, NOBARRIER); | 3649 | do_barriers = !btrfs_test_opt(root->fs_info, NOBARRIER); |
3643 | backup_super_roots(root->fs_info); | 3650 | backup_super_roots(root->fs_info); |
3644 | 3651 | ||
3645 | sb = root->fs_info->super_for_commit; | 3652 | sb = root->fs_info->super_for_commit; |
@@ -3923,7 +3930,7 @@ void close_ctree(struct btrfs_root *root) | |||
3923 | iput(fs_info->btree_inode); | 3930 | iput(fs_info->btree_inode); |
3924 | 3931 | ||
3925 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY | 3932 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
3926 | if (btrfs_test_opt(root, CHECK_INTEGRITY)) | 3933 | if (btrfs_test_opt(root->fs_info, CHECK_INTEGRITY)) |
3927 | btrfsic_unmount(root, fs_info->fs_devices); | 3934 | btrfsic_unmount(root, fs_info->fs_devices); |
3928 | #endif | 3935 | #endif |
3929 | 3936 | ||
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index acba821499a9..c9d42c92da2b 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h | |||
@@ -90,7 +90,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, | |||
90 | void btrfs_free_fs_root(struct btrfs_root *root); | 90 | void btrfs_free_fs_root(struct btrfs_root *root); |
91 | 91 | ||
92 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS | 92 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
93 | struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize); | 93 | struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info, |
94 | u32 sectorsize, u32 nodesize); | ||
94 | #endif | 95 | #endif |
95 | 96 | ||
96 | /* | 97 | /* |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 9fcb8c97083b..c2b81b0d3fe0 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -2180,7 +2180,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, | |||
2180 | path, bytenr, parent, root_objectid, | 2180 | path, bytenr, parent, root_objectid, |
2181 | owner, offset, refs_to_add); | 2181 | owner, offset, refs_to_add); |
2182 | if (ret) | 2182 | if (ret) |
2183 | btrfs_abort_transaction(trans, root, ret); | 2183 | btrfs_abort_transaction(trans, ret); |
2184 | out: | 2184 | out: |
2185 | btrfs_free_path(path); | 2185 | btrfs_free_path(path); |
2186 | return ret; | 2186 | return ret; |
@@ -2204,7 +2204,7 @@ static int run_delayed_data_ref(struct btrfs_trans_handle *trans, | |||
2204 | ins.type = BTRFS_EXTENT_ITEM_KEY; | 2204 | ins.type = BTRFS_EXTENT_ITEM_KEY; |
2205 | 2205 | ||
2206 | ref = btrfs_delayed_node_to_data_ref(node); | 2206 | ref = btrfs_delayed_node_to_data_ref(node); |
2207 | trace_run_delayed_data_ref(node, ref, node->action); | 2207 | trace_run_delayed_data_ref(root->fs_info, node, ref, node->action); |
2208 | 2208 | ||
2209 | if (node->type == BTRFS_SHARED_DATA_REF_KEY) | 2209 | if (node->type == BTRFS_SHARED_DATA_REF_KEY) |
2210 | parent = ref->parent; | 2210 | parent = ref->parent; |
@@ -2359,7 +2359,7 @@ static int run_delayed_tree_ref(struct btrfs_trans_handle *trans, | |||
2359 | SKINNY_METADATA); | 2359 | SKINNY_METADATA); |
2360 | 2360 | ||
2361 | ref = btrfs_delayed_node_to_tree_ref(node); | 2361 | ref = btrfs_delayed_node_to_tree_ref(node); |
2362 | trace_run_delayed_tree_ref(node, ref, node->action); | 2362 | trace_run_delayed_tree_ref(root->fs_info, node, ref, node->action); |
2363 | 2363 | ||
2364 | if (node->type == BTRFS_SHARED_BLOCK_REF_KEY) | 2364 | if (node->type == BTRFS_SHARED_BLOCK_REF_KEY) |
2365 | parent = ref->parent; | 2365 | parent = ref->parent; |
@@ -2423,7 +2423,8 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans, | |||
2423 | */ | 2423 | */ |
2424 | BUG_ON(extent_op); | 2424 | BUG_ON(extent_op); |
2425 | head = btrfs_delayed_node_to_head(node); | 2425 | head = btrfs_delayed_node_to_head(node); |
2426 | trace_run_delayed_ref_head(node, head, node->action); | 2426 | trace_run_delayed_ref_head(root->fs_info, node, head, |
2427 | node->action); | ||
2427 | 2428 | ||
2428 | if (insert_reserved) { | 2429 | if (insert_reserved) { |
2429 | btrfs_pin_extent(root, node->bytenr, | 2430 | btrfs_pin_extent(root, node->bytenr, |
@@ -2778,7 +2779,7 @@ u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes) | |||
2778 | u64 num_csums_per_leaf; | 2779 | u64 num_csums_per_leaf; |
2779 | u64 num_csums; | 2780 | u64 num_csums; |
2780 | 2781 | ||
2781 | csum_size = BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item); | 2782 | csum_size = BTRFS_MAX_ITEM_SIZE(root); |
2782 | num_csums_per_leaf = div64_u64(csum_size, | 2783 | num_csums_per_leaf = div64_u64(csum_size, |
2783 | (u64)btrfs_super_csum_size(root->fs_info->super_copy)); | 2784 | (u64)btrfs_super_csum_size(root->fs_info->super_copy)); |
2784 | num_csums = div64_u64(csum_bytes, root->sectorsize); | 2785 | num_csums = div64_u64(csum_bytes, root->sectorsize); |
@@ -2970,7 +2971,7 @@ again: | |||
2970 | trans->can_flush_pending_bgs = false; | 2971 | trans->can_flush_pending_bgs = false; |
2971 | ret = __btrfs_run_delayed_refs(trans, root, count); | 2972 | ret = __btrfs_run_delayed_refs(trans, root, count); |
2972 | if (ret < 0) { | 2973 | if (ret < 0) { |
2973 | btrfs_abort_transaction(trans, root, ret); | 2974 | btrfs_abort_transaction(trans, ret); |
2974 | return ret; | 2975 | return ret; |
2975 | } | 2976 | } |
2976 | 2977 | ||
@@ -3234,7 +3235,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, | |||
3234 | u64, u64, u64, u64, u64, u64); | 3235 | u64, u64, u64, u64, u64, u64); |
3235 | 3236 | ||
3236 | 3237 | ||
3237 | if (btrfs_test_is_dummy_root(root)) | 3238 | if (btrfs_is_testing(root->fs_info)) |
3238 | return 0; | 3239 | return 0; |
3239 | 3240 | ||
3240 | ref_root = btrfs_header_owner(buf); | 3241 | ref_root = btrfs_header_owner(buf); |
@@ -3429,7 +3430,7 @@ again: | |||
3429 | * transaction, this only happens in really bad situations | 3430 | * transaction, this only happens in really bad situations |
3430 | * anyway. | 3431 | * anyway. |
3431 | */ | 3432 | */ |
3432 | btrfs_abort_transaction(trans, root, ret); | 3433 | btrfs_abort_transaction(trans, ret); |
3433 | goto out_put; | 3434 | goto out_put; |
3434 | } | 3435 | } |
3435 | WARN_ON(ret); | 3436 | WARN_ON(ret); |
@@ -3447,7 +3448,7 @@ again: | |||
3447 | 3448 | ||
3448 | spin_lock(&block_group->lock); | 3449 | spin_lock(&block_group->lock); |
3449 | if (block_group->cached != BTRFS_CACHE_FINISHED || | 3450 | if (block_group->cached != BTRFS_CACHE_FINISHED || |
3450 | !btrfs_test_opt(root, SPACE_CACHE)) { | 3451 | !btrfs_test_opt(root->fs_info, SPACE_CACHE)) { |
3451 | /* | 3452 | /* |
3452 | * don't bother trying to write stuff out _if_ | 3453 | * don't bother trying to write stuff out _if_ |
3453 | * a) we're not cached, | 3454 | * a) we're not cached, |
@@ -3524,7 +3525,7 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans, | |||
3524 | struct btrfs_path *path; | 3525 | struct btrfs_path *path; |
3525 | 3526 | ||
3526 | if (list_empty(&cur_trans->dirty_bgs) || | 3527 | if (list_empty(&cur_trans->dirty_bgs) || |
3527 | !btrfs_test_opt(root, SPACE_CACHE)) | 3528 | !btrfs_test_opt(root->fs_info, SPACE_CACHE)) |
3528 | return 0; | 3529 | return 0; |
3529 | 3530 | ||
3530 | path = btrfs_alloc_path(); | 3531 | path = btrfs_alloc_path(); |
@@ -3669,7 +3670,7 @@ again: | |||
3669 | } | 3670 | } |
3670 | spin_unlock(&cur_trans->dirty_bgs_lock); | 3671 | spin_unlock(&cur_trans->dirty_bgs_lock); |
3671 | } else if (ret) { | 3672 | } else if (ret) { |
3672 | btrfs_abort_transaction(trans, root, ret); | 3673 | btrfs_abort_transaction(trans, ret); |
3673 | } | 3674 | } |
3674 | } | 3675 | } |
3675 | 3676 | ||
@@ -3815,7 +3816,7 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, | |||
3815 | cache); | 3816 | cache); |
3816 | } | 3817 | } |
3817 | if (ret) | 3818 | if (ret) |
3818 | btrfs_abort_transaction(trans, root, ret); | 3819 | btrfs_abort_transaction(trans, ret); |
3819 | } | 3820 | } |
3820 | 3821 | ||
3821 | /* if its not on the io list, we need to put the block group */ | 3822 | /* if its not on the io list, we need to put the block group */ |
@@ -4443,7 +4444,7 @@ void check_system_chunk(struct btrfs_trans_handle *trans, | |||
4443 | thresh = btrfs_calc_trunc_metadata_size(root, num_devs) + | 4444 | thresh = btrfs_calc_trunc_metadata_size(root, num_devs) + |
4444 | btrfs_calc_trans_metadata_size(root, 1); | 4445 | btrfs_calc_trans_metadata_size(root, 1); |
4445 | 4446 | ||
4446 | if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) { | 4447 | if (left < thresh && btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) { |
4447 | btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu", | 4448 | btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu", |
4448 | left, thresh, type); | 4449 | left, thresh, type); |
4449 | dump_space_info(info, 0, 0); | 4450 | dump_space_info(info, 0, 0); |
@@ -4588,7 +4589,7 @@ out: | |||
4588 | */ | 4589 | */ |
4589 | if (trans->can_flush_pending_bgs && | 4590 | if (trans->can_flush_pending_bgs && |
4590 | trans->chunk_bytes_reserved >= (u64)SZ_2M) { | 4591 | trans->chunk_bytes_reserved >= (u64)SZ_2M) { |
4591 | btrfs_create_pending_block_groups(trans, trans->root); | 4592 | btrfs_create_pending_block_groups(trans, extent_root); |
4592 | btrfs_trans_release_chunk_metadata(trans); | 4593 | btrfs_trans_release_chunk_metadata(trans); |
4593 | } | 4594 | } |
4594 | return ret; | 4595 | return ret; |
@@ -5729,7 +5730,7 @@ void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans, | |||
5729 | */ | 5730 | */ |
5730 | void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) | 5731 | void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) |
5731 | { | 5732 | { |
5732 | struct btrfs_fs_info *fs_info = trans->root->fs_info; | 5733 | struct btrfs_fs_info *fs_info = trans->fs_info; |
5733 | 5734 | ||
5734 | if (!trans->chunk_bytes_reserved) | 5735 | if (!trans->chunk_bytes_reserved) |
5735 | return; | 5736 | return; |
@@ -6100,7 +6101,7 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes) | |||
6100 | if (dropped > 0) | 6101 | if (dropped > 0) |
6101 | to_free += btrfs_calc_trans_metadata_size(root, dropped); | 6102 | to_free += btrfs_calc_trans_metadata_size(root, dropped); |
6102 | 6103 | ||
6103 | if (btrfs_test_is_dummy_root(root)) | 6104 | if (btrfs_is_testing(root->fs_info)) |
6104 | return; | 6105 | return; |
6105 | 6106 | ||
6106 | trace_btrfs_space_reservation(root->fs_info, "delalloc", | 6107 | trace_btrfs_space_reservation(root->fs_info, "delalloc", |
@@ -6215,7 +6216,7 @@ static int update_block_group(struct btrfs_trans_handle *trans, | |||
6215 | spin_lock(&cache->space_info->lock); | 6216 | spin_lock(&cache->space_info->lock); |
6216 | spin_lock(&cache->lock); | 6217 | spin_lock(&cache->lock); |
6217 | 6218 | ||
6218 | if (btrfs_test_opt(root, SPACE_CACHE) && | 6219 | if (btrfs_test_opt(root->fs_info, SPACE_CACHE) && |
6219 | cache->disk_cache_state < BTRFS_DC_CLEAR) | 6220 | cache->disk_cache_state < BTRFS_DC_CLEAR) |
6220 | cache->disk_cache_state = BTRFS_DC_CLEAR; | 6221 | cache->disk_cache_state = BTRFS_DC_CLEAR; |
6221 | 6222 | ||
@@ -6597,7 +6598,7 @@ fetch_cluster_info(struct btrfs_root *root, struct btrfs_space_info *space_info, | |||
6597 | u64 *empty_cluster) | 6598 | u64 *empty_cluster) |
6598 | { | 6599 | { |
6599 | struct btrfs_free_cluster *ret = NULL; | 6600 | struct btrfs_free_cluster *ret = NULL; |
6600 | bool ssd = btrfs_test_opt(root, SSD); | 6601 | bool ssd = btrfs_test_opt(root->fs_info, SSD); |
6601 | 6602 | ||
6602 | *empty_cluster = 0; | 6603 | *empty_cluster = 0; |
6603 | if (btrfs_mixed_space_info(space_info)) | 6604 | if (btrfs_mixed_space_info(space_info)) |
@@ -6742,7 +6743,7 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, | |||
6742 | break; | 6743 | break; |
6743 | } | 6744 | } |
6744 | 6745 | ||
6745 | if (btrfs_test_opt(root, DISCARD)) | 6746 | if (btrfs_test_opt(root->fs_info, DISCARD)) |
6746 | ret = btrfs_discard_extent(root, start, | 6747 | ret = btrfs_discard_extent(root, start, |
6747 | end + 1 - start, NULL); | 6748 | end + 1 - start, NULL); |
6748 | 6749 | ||
@@ -6880,7 +6881,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
6880 | NULL, refs_to_drop, | 6881 | NULL, refs_to_drop, |
6881 | is_data, &last_ref); | 6882 | is_data, &last_ref); |
6882 | if (ret) { | 6883 | if (ret) { |
6883 | btrfs_abort_transaction(trans, extent_root, ret); | 6884 | btrfs_abort_transaction(trans, ret); |
6884 | goto out; | 6885 | goto out; |
6885 | } | 6886 | } |
6886 | btrfs_release_path(path); | 6887 | btrfs_release_path(path); |
@@ -6929,7 +6930,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
6929 | path->nodes[0]); | 6930 | path->nodes[0]); |
6930 | } | 6931 | } |
6931 | if (ret < 0) { | 6932 | if (ret < 0) { |
6932 | btrfs_abort_transaction(trans, extent_root, ret); | 6933 | btrfs_abort_transaction(trans, ret); |
6933 | goto out; | 6934 | goto out; |
6934 | } | 6935 | } |
6935 | extent_slot = path->slots[0]; | 6936 | extent_slot = path->slots[0]; |
@@ -6940,10 +6941,10 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
6940 | "unable to find ref byte nr %llu parent %llu root %llu owner %llu offset %llu", | 6941 | "unable to find ref byte nr %llu parent %llu root %llu owner %llu offset %llu", |
6941 | bytenr, parent, root_objectid, owner_objectid, | 6942 | bytenr, parent, root_objectid, owner_objectid, |
6942 | owner_offset); | 6943 | owner_offset); |
6943 | btrfs_abort_transaction(trans, extent_root, ret); | 6944 | btrfs_abort_transaction(trans, ret); |
6944 | goto out; | 6945 | goto out; |
6945 | } else { | 6946 | } else { |
6946 | btrfs_abort_transaction(trans, extent_root, ret); | 6947 | btrfs_abort_transaction(trans, ret); |
6947 | goto out; | 6948 | goto out; |
6948 | } | 6949 | } |
6949 | 6950 | ||
@@ -6955,7 +6956,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
6955 | ret = convert_extent_item_v0(trans, extent_root, path, | 6956 | ret = convert_extent_item_v0(trans, extent_root, path, |
6956 | owner_objectid, 0); | 6957 | owner_objectid, 0); |
6957 | if (ret < 0) { | 6958 | if (ret < 0) { |
6958 | btrfs_abort_transaction(trans, extent_root, ret); | 6959 | btrfs_abort_transaction(trans, ret); |
6959 | goto out; | 6960 | goto out; |
6960 | } | 6961 | } |
6961 | 6962 | ||
@@ -6974,7 +6975,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
6974 | btrfs_print_leaf(extent_root, path->nodes[0]); | 6975 | btrfs_print_leaf(extent_root, path->nodes[0]); |
6975 | } | 6976 | } |
6976 | if (ret < 0) { | 6977 | if (ret < 0) { |
6977 | btrfs_abort_transaction(trans, extent_root, ret); | 6978 | btrfs_abort_transaction(trans, ret); |
6978 | goto out; | 6979 | goto out; |
6979 | } | 6980 | } |
6980 | 6981 | ||
@@ -6999,7 +7000,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
6999 | btrfs_err(info, "trying to drop %d refs but we only have %Lu " | 7000 | btrfs_err(info, "trying to drop %d refs but we only have %Lu " |
7000 | "for bytenr %Lu", refs_to_drop, refs, bytenr); | 7001 | "for bytenr %Lu", refs_to_drop, refs, bytenr); |
7001 | ret = -EINVAL; | 7002 | ret = -EINVAL; |
7002 | btrfs_abort_transaction(trans, extent_root, ret); | 7003 | btrfs_abort_transaction(trans, ret); |
7003 | goto out; | 7004 | goto out; |
7004 | } | 7005 | } |
7005 | refs -= refs_to_drop; | 7006 | refs -= refs_to_drop; |
@@ -7022,7 +7023,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
7022 | iref, refs_to_drop, | 7023 | iref, refs_to_drop, |
7023 | is_data, &last_ref); | 7024 | is_data, &last_ref); |
7024 | if (ret) { | 7025 | if (ret) { |
7025 | btrfs_abort_transaction(trans, extent_root, ret); | 7026 | btrfs_abort_transaction(trans, ret); |
7026 | goto out; | 7027 | goto out; |
7027 | } | 7028 | } |
7028 | } | 7029 | } |
@@ -7045,7 +7046,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
7045 | ret = btrfs_del_items(trans, extent_root, path, path->slots[0], | 7046 | ret = btrfs_del_items(trans, extent_root, path, path->slots[0], |
7046 | num_to_del); | 7047 | num_to_del); |
7047 | if (ret) { | 7048 | if (ret) { |
7048 | btrfs_abort_transaction(trans, extent_root, ret); | 7049 | btrfs_abort_transaction(trans, ret); |
7049 | goto out; | 7050 | goto out; |
7050 | } | 7051 | } |
7051 | btrfs_release_path(path); | 7052 | btrfs_release_path(path); |
@@ -7053,7 +7054,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
7053 | if (is_data) { | 7054 | if (is_data) { |
7054 | ret = btrfs_del_csums(trans, root, bytenr, num_bytes); | 7055 | ret = btrfs_del_csums(trans, root, bytenr, num_bytes); |
7055 | if (ret) { | 7056 | if (ret) { |
7056 | btrfs_abort_transaction(trans, extent_root, ret); | 7057 | btrfs_abort_transaction(trans, ret); |
7057 | goto out; | 7058 | goto out; |
7058 | } | 7059 | } |
7059 | } | 7060 | } |
@@ -7061,13 +7062,13 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
7061 | ret = add_to_free_space_tree(trans, root->fs_info, bytenr, | 7062 | ret = add_to_free_space_tree(trans, root->fs_info, bytenr, |
7062 | num_bytes); | 7063 | num_bytes); |
7063 | if (ret) { | 7064 | if (ret) { |
7064 | btrfs_abort_transaction(trans, extent_root, ret); | 7065 | btrfs_abort_transaction(trans, ret); |
7065 | goto out; | 7066 | goto out; |
7066 | } | 7067 | } |
7067 | 7068 | ||
7068 | ret = update_block_group(trans, root, bytenr, num_bytes, 0); | 7069 | ret = update_block_group(trans, root, bytenr, num_bytes, 0); |
7069 | if (ret) { | 7070 | if (ret) { |
7070 | btrfs_abort_transaction(trans, extent_root, ret); | 7071 | btrfs_abort_transaction(trans, ret); |
7071 | goto out; | 7072 | goto out; |
7072 | } | 7073 | } |
7073 | } | 7074 | } |
@@ -7216,7 +7217,7 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
7216 | int ret; | 7217 | int ret; |
7217 | struct btrfs_fs_info *fs_info = root->fs_info; | 7218 | struct btrfs_fs_info *fs_info = root->fs_info; |
7218 | 7219 | ||
7219 | if (btrfs_test_is_dummy_root(root)) | 7220 | if (btrfs_is_testing(fs_info)) |
7220 | return 0; | 7221 | return 0; |
7221 | 7222 | ||
7222 | add_pinned_bytes(root->fs_info, num_bytes, owner, root_objectid); | 7223 | add_pinned_bytes(root->fs_info, num_bytes, owner, root_objectid); |
@@ -7851,8 +7852,7 @@ loop: | |||
7851 | * can do more things. | 7852 | * can do more things. |
7852 | */ | 7853 | */ |
7853 | if (ret < 0 && ret != -ENOSPC) | 7854 | if (ret < 0 && ret != -ENOSPC) |
7854 | btrfs_abort_transaction(trans, | 7855 | btrfs_abort_transaction(trans, ret); |
7855 | root, ret); | ||
7856 | else | 7856 | else |
7857 | ret = 0; | 7857 | ret = 0; |
7858 | if (!exist) | 7858 | if (!exist) |
@@ -7906,8 +7906,8 @@ static void dump_space_info(struct btrfs_space_info *info, u64 bytes, | |||
7906 | printk(KERN_INFO "BTRFS: space_info %llu has %llu free, is %sfull\n", | 7906 | printk(KERN_INFO "BTRFS: space_info %llu has %llu free, is %sfull\n", |
7907 | info->flags, | 7907 | info->flags, |
7908 | info->total_bytes - info->bytes_used - info->bytes_pinned - | 7908 | info->total_bytes - info->bytes_used - info->bytes_pinned - |
7909 | info->bytes_reserved - info->bytes_readonly, | 7909 | info->bytes_reserved - info->bytes_readonly - |
7910 | (info->full) ? "" : "not "); | 7910 | info->bytes_may_use, (info->full) ? "" : "not "); |
7911 | printk(KERN_INFO "BTRFS: space_info total=%llu, used=%llu, pinned=%llu, " | 7911 | printk(KERN_INFO "BTRFS: space_info total=%llu, used=%llu, pinned=%llu, " |
7912 | "reserved=%llu, may_use=%llu, readonly=%llu\n", | 7912 | "reserved=%llu, may_use=%llu, readonly=%llu\n", |
7913 | info->total_bytes, info->bytes_used, info->bytes_pinned, | 7913 | info->total_bytes, info->bytes_used, info->bytes_pinned, |
@@ -7961,7 +7961,7 @@ again: | |||
7961 | if (num_bytes == min_alloc_size) | 7961 | if (num_bytes == min_alloc_size) |
7962 | final_tried = true; | 7962 | final_tried = true; |
7963 | goto again; | 7963 | goto again; |
7964 | } else if (btrfs_test_opt(root, ENOSPC_DEBUG)) { | 7964 | } else if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) { |
7965 | struct btrfs_space_info *sinfo; | 7965 | struct btrfs_space_info *sinfo; |
7966 | 7966 | ||
7967 | sinfo = __find_space_info(root->fs_info, flags); | 7967 | sinfo = __find_space_info(root->fs_info, flags); |
@@ -7992,7 +7992,7 @@ static int __btrfs_free_reserved_extent(struct btrfs_root *root, | |||
7992 | if (pin) | 7992 | if (pin) |
7993 | pin_down_extent(root, cache, start, len, 1); | 7993 | pin_down_extent(root, cache, start, len, 1); |
7994 | else { | 7994 | else { |
7995 | if (btrfs_test_opt(root, DISCARD)) | 7995 | if (btrfs_test_opt(root->fs_info, DISCARD)) |
7996 | ret = btrfs_discard_extent(root, start, len, NULL); | 7996 | ret = btrfs_discard_extent(root, start, len, NULL); |
7997 | btrfs_add_free_space(cache, start, len); | 7997 | btrfs_add_free_space(cache, start, len); |
7998 | btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc); | 7998 | btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc); |
@@ -8300,7 +8300,7 @@ again: | |||
8300 | goto again; | 8300 | goto again; |
8301 | } | 8301 | } |
8302 | 8302 | ||
8303 | if (btrfs_test_opt(root, ENOSPC_DEBUG)) { | 8303 | if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) { |
8304 | static DEFINE_RATELIMIT_STATE(_rs, | 8304 | static DEFINE_RATELIMIT_STATE(_rs, |
8305 | DEFAULT_RATELIMIT_INTERVAL * 10, | 8305 | DEFAULT_RATELIMIT_INTERVAL * 10, |
8306 | /*DEFAULT_RATELIMIT_BURST*/ 1); | 8306 | /*DEFAULT_RATELIMIT_BURST*/ 1); |
@@ -8354,13 +8354,15 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, | |||
8354 | bool skinny_metadata = btrfs_fs_incompat(root->fs_info, | 8354 | bool skinny_metadata = btrfs_fs_incompat(root->fs_info, |
8355 | SKINNY_METADATA); | 8355 | SKINNY_METADATA); |
8356 | 8356 | ||
8357 | if (btrfs_test_is_dummy_root(root)) { | 8357 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
8358 | if (btrfs_is_testing(root->fs_info)) { | ||
8358 | buf = btrfs_init_new_buffer(trans, root, root->alloc_bytenr, | 8359 | buf = btrfs_init_new_buffer(trans, root, root->alloc_bytenr, |
8359 | level); | 8360 | level); |
8360 | if (!IS_ERR(buf)) | 8361 | if (!IS_ERR(buf)) |
8361 | root->alloc_bytenr += blocksize; | 8362 | root->alloc_bytenr += blocksize; |
8362 | return buf; | 8363 | return buf; |
8363 | } | 8364 | } |
8365 | #endif | ||
8364 | 8366 | ||
8365 | block_rsv = use_block_rsv(trans, root, blocksize); | 8367 | block_rsv = use_block_rsv(trans, root, blocksize); |
8366 | if (IS_ERR(block_rsv)) | 8368 | if (IS_ERR(block_rsv)) |
@@ -8540,7 +8542,8 @@ static int record_one_subtree_extent(struct btrfs_trans_handle *trans, | |||
8540 | 8542 | ||
8541 | delayed_refs = &trans->transaction->delayed_refs; | 8543 | delayed_refs = &trans->transaction->delayed_refs; |
8542 | spin_lock(&delayed_refs->lock); | 8544 | spin_lock(&delayed_refs->lock); |
8543 | if (btrfs_qgroup_insert_dirty_extent(delayed_refs, qrecord)) | 8545 | if (btrfs_qgroup_insert_dirty_extent(trans->fs_info, |
8546 | delayed_refs, qrecord)) | ||
8544 | kfree(qrecord); | 8547 | kfree(qrecord); |
8545 | spin_unlock(&delayed_refs->lock); | 8548 | spin_unlock(&delayed_refs->lock); |
8546 | 8549 | ||
@@ -9325,7 +9328,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, | |||
9325 | &root->root_key, | 9328 | &root->root_key, |
9326 | root_item); | 9329 | root_item); |
9327 | if (ret) { | 9330 | if (ret) { |
9328 | btrfs_abort_transaction(trans, tree_root, ret); | 9331 | btrfs_abort_transaction(trans, ret); |
9329 | err = ret; | 9332 | err = ret; |
9330 | goto out_end_trans; | 9333 | goto out_end_trans; |
9331 | } | 9334 | } |
@@ -9352,7 +9355,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, | |||
9352 | 9355 | ||
9353 | ret = btrfs_del_root(trans, tree_root, &root->root_key); | 9356 | ret = btrfs_del_root(trans, tree_root, &root->root_key); |
9354 | if (ret) { | 9357 | if (ret) { |
9355 | btrfs_abort_transaction(trans, tree_root, ret); | 9358 | btrfs_abort_transaction(trans, ret); |
9356 | goto out_end_trans; | 9359 | goto out_end_trans; |
9357 | } | 9360 | } |
9358 | 9361 | ||
@@ -9360,7 +9363,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, | |||
9360 | ret = btrfs_find_root(tree_root, &root->root_key, path, | 9363 | ret = btrfs_find_root(tree_root, &root->root_key, path, |
9361 | NULL, NULL); | 9364 | NULL, NULL); |
9362 | if (ret < 0) { | 9365 | if (ret < 0) { |
9363 | btrfs_abort_transaction(trans, tree_root, ret); | 9366 | btrfs_abort_transaction(trans, ret); |
9364 | err = ret; | 9367 | err = ret; |
9365 | goto out_end_trans; | 9368 | goto out_end_trans; |
9366 | } else if (ret > 0) { | 9369 | } else if (ret > 0) { |
@@ -9731,7 +9734,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr) | |||
9731 | int full = 0; | 9734 | int full = 0; |
9732 | int ret = 0; | 9735 | int ret = 0; |
9733 | 9736 | ||
9734 | debug = btrfs_test_opt(root, ENOSPC_DEBUG); | 9737 | debug = btrfs_test_opt(root->fs_info, ENOSPC_DEBUG); |
9735 | 9738 | ||
9736 | block_group = btrfs_lookup_block_group(root->fs_info, bytenr); | 9739 | block_group = btrfs_lookup_block_group(root->fs_info, bytenr); |
9737 | 9740 | ||
@@ -9887,7 +9890,22 @@ static int find_first_block_group(struct btrfs_root *root, | |||
9887 | 9890 | ||
9888 | if (found_key.objectid >= key->objectid && | 9891 | if (found_key.objectid >= key->objectid && |
9889 | found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) { | 9892 | found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) { |
9890 | ret = 0; | 9893 | struct extent_map_tree *em_tree; |
9894 | struct extent_map *em; | ||
9895 | |||
9896 | em_tree = &root->fs_info->mapping_tree.map_tree; | ||
9897 | read_lock(&em_tree->lock); | ||
9898 | em = lookup_extent_mapping(em_tree, found_key.objectid, | ||
9899 | found_key.offset); | ||
9900 | read_unlock(&em_tree->lock); | ||
9901 | if (!em) { | ||
9902 | btrfs_err(root->fs_info, | ||
9903 | "logical %llu len %llu found bg but no related chunk", | ||
9904 | found_key.objectid, found_key.offset); | ||
9905 | ret = -ENOENT; | ||
9906 | } else { | ||
9907 | ret = 0; | ||
9908 | } | ||
9891 | goto out; | 9909 | goto out; |
9892 | } | 9910 | } |
9893 | path->slots[0]++; | 9911 | path->slots[0]++; |
@@ -10129,10 +10147,10 @@ int btrfs_read_block_groups(struct btrfs_root *root) | |||
10129 | path->reada = READA_FORWARD; | 10147 | path->reada = READA_FORWARD; |
10130 | 10148 | ||
10131 | cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy); | 10149 | cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy); |
10132 | if (btrfs_test_opt(root, SPACE_CACHE) && | 10150 | if (btrfs_test_opt(root->fs_info, SPACE_CACHE) && |
10133 | btrfs_super_generation(root->fs_info->super_copy) != cache_gen) | 10151 | btrfs_super_generation(root->fs_info->super_copy) != cache_gen) |
10134 | need_clear = 1; | 10152 | need_clear = 1; |
10135 | if (btrfs_test_opt(root, CLEAR_CACHE)) | 10153 | if (btrfs_test_opt(root->fs_info, CLEAR_CACHE)) |
10136 | need_clear = 1; | 10154 | need_clear = 1; |
10137 | 10155 | ||
10138 | while (1) { | 10156 | while (1) { |
@@ -10163,7 +10181,7 @@ int btrfs_read_block_groups(struct btrfs_root *root) | |||
10163 | * b) Setting 'dirty flag' makes sure that we flush | 10181 | * b) Setting 'dirty flag' makes sure that we flush |
10164 | * the new space cache info onto disk. | 10182 | * the new space cache info onto disk. |
10165 | */ | 10183 | */ |
10166 | if (btrfs_test_opt(root, SPACE_CACHE)) | 10184 | if (btrfs_test_opt(root->fs_info, SPACE_CACHE)) |
10167 | cache->disk_cache_state = BTRFS_DC_CLEAR; | 10185 | cache->disk_cache_state = BTRFS_DC_CLEAR; |
10168 | } | 10186 | } |
10169 | 10187 | ||
@@ -10305,11 +10323,11 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans, | |||
10305 | ret = btrfs_insert_item(trans, extent_root, &key, &item, | 10323 | ret = btrfs_insert_item(trans, extent_root, &key, &item, |
10306 | sizeof(item)); | 10324 | sizeof(item)); |
10307 | if (ret) | 10325 | if (ret) |
10308 | btrfs_abort_transaction(trans, extent_root, ret); | 10326 | btrfs_abort_transaction(trans, ret); |
10309 | ret = btrfs_finish_chunk_alloc(trans, extent_root, | 10327 | ret = btrfs_finish_chunk_alloc(trans, extent_root, |
10310 | key.objectid, key.offset); | 10328 | key.objectid, key.offset); |
10311 | if (ret) | 10329 | if (ret) |
10312 | btrfs_abort_transaction(trans, extent_root, ret); | 10330 | btrfs_abort_transaction(trans, ret); |
10313 | add_block_group_free_space(trans, root->fs_info, block_group); | 10331 | add_block_group_free_space(trans, root->fs_info, block_group); |
10314 | /* already aborted the transaction if it failed. */ | 10332 | /* already aborted the transaction if it failed. */ |
10315 | next: | 10333 | next: |
@@ -10622,7 +10640,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, | |||
10622 | spin_lock(&block_group->space_info->lock); | 10640 | spin_lock(&block_group->space_info->lock); |
10623 | list_del_init(&block_group->ro_list); | 10641 | list_del_init(&block_group->ro_list); |
10624 | 10642 | ||
10625 | if (btrfs_test_opt(root, ENOSPC_DEBUG)) { | 10643 | if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) { |
10626 | WARN_ON(block_group->space_info->total_bytes | 10644 | WARN_ON(block_group->space_info->total_bytes |
10627 | < block_group->key.offset); | 10645 | < block_group->key.offset); |
10628 | WARN_ON(block_group->space_info->bytes_readonly | 10646 | WARN_ON(block_group->space_info->bytes_readonly |
@@ -10890,7 +10908,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) | |||
10890 | spin_unlock(&space_info->lock); | 10908 | spin_unlock(&space_info->lock); |
10891 | 10909 | ||
10892 | /* DISCARD can flip during remount */ | 10910 | /* DISCARD can flip during remount */ |
10893 | trimming = btrfs_test_opt(root, DISCARD); | 10911 | trimming = btrfs_test_opt(root->fs_info, DISCARD); |
10894 | 10912 | ||
10895 | /* Implicit trim during transaction commit. */ | 10913 | /* Implicit trim during transaction commit. */ |
10896 | if (trimming) | 10914 | if (trimming) |
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 75533adef998..dae2f8470e04 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -163,13 +163,13 @@ int __init extent_io_init(void) | |||
163 | { | 163 | { |
164 | extent_state_cache = kmem_cache_create("btrfs_extent_state", | 164 | extent_state_cache = kmem_cache_create("btrfs_extent_state", |
165 | sizeof(struct extent_state), 0, | 165 | sizeof(struct extent_state), 0, |
166 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 166 | SLAB_MEM_SPREAD, NULL); |
167 | if (!extent_state_cache) | 167 | if (!extent_state_cache) |
168 | return -ENOMEM; | 168 | return -ENOMEM; |
169 | 169 | ||
170 | extent_buffer_cache = kmem_cache_create("btrfs_extent_buffer", | 170 | extent_buffer_cache = kmem_cache_create("btrfs_extent_buffer", |
171 | sizeof(struct extent_buffer), 0, | 171 | sizeof(struct extent_buffer), 0, |
172 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 172 | SLAB_MEM_SPREAD, NULL); |
173 | if (!extent_buffer_cache) | 173 | if (!extent_buffer_cache) |
174 | goto free_state_cache; | 174 | goto free_state_cache; |
175 | 175 | ||
@@ -2756,7 +2756,6 @@ static int merge_bio(int rw, struct extent_io_tree *tree, struct page *page, | |||
2756 | if (tree->ops && tree->ops->merge_bio_hook) | 2756 | if (tree->ops && tree->ops->merge_bio_hook) |
2757 | ret = tree->ops->merge_bio_hook(rw, page, offset, size, bio, | 2757 | ret = tree->ops->merge_bio_hook(rw, page, offset, size, bio, |
2758 | bio_flags); | 2758 | bio_flags); |
2759 | BUG_ON(ret < 0); | ||
2760 | return ret; | 2759 | return ret; |
2761 | 2760 | ||
2762 | } | 2761 | } |
@@ -2879,6 +2878,7 @@ __get_extent_map(struct inode *inode, struct page *page, size_t pg_offset, | |||
2879 | * into the tree that are removed when the IO is done (by the end_io | 2878 | * into the tree that are removed when the IO is done (by the end_io |
2880 | * handlers) | 2879 | * handlers) |
2881 | * XXX JDM: This needs looking at to ensure proper page locking | 2880 | * XXX JDM: This needs looking at to ensure proper page locking |
2881 | * return 0 on success, otherwise return error | ||
2882 | */ | 2882 | */ |
2883 | static int __do_readpage(struct extent_io_tree *tree, | 2883 | static int __do_readpage(struct extent_io_tree *tree, |
2884 | struct page *page, | 2884 | struct page *page, |
@@ -2900,7 +2900,7 @@ static int __do_readpage(struct extent_io_tree *tree, | |||
2900 | sector_t sector; | 2900 | sector_t sector; |
2901 | struct extent_map *em; | 2901 | struct extent_map *em; |
2902 | struct block_device *bdev; | 2902 | struct block_device *bdev; |
2903 | int ret; | 2903 | int ret = 0; |
2904 | int nr = 0; | 2904 | int nr = 0; |
2905 | size_t pg_offset = 0; | 2905 | size_t pg_offset = 0; |
2906 | size_t iosize; | 2906 | size_t iosize; |
@@ -3081,6 +3081,7 @@ static int __do_readpage(struct extent_io_tree *tree, | |||
3081 | } else { | 3081 | } else { |
3082 | SetPageError(page); | 3082 | SetPageError(page); |
3083 | unlock_extent(tree, cur, cur + iosize - 1); | 3083 | unlock_extent(tree, cur, cur + iosize - 1); |
3084 | goto out; | ||
3084 | } | 3085 | } |
3085 | cur = cur + iosize; | 3086 | cur = cur + iosize; |
3086 | pg_offset += iosize; | 3087 | pg_offset += iosize; |
@@ -3091,7 +3092,7 @@ out: | |||
3091 | SetPageUptodate(page); | 3092 | SetPageUptodate(page); |
3092 | unlock_page(page); | 3093 | unlock_page(page); |
3093 | } | 3094 | } |
3094 | return 0; | 3095 | return ret; |
3095 | } | 3096 | } |
3096 | 3097 | ||
3097 | static inline void __do_contiguous_readpages(struct extent_io_tree *tree, | 3098 | static inline void __do_contiguous_readpages(struct extent_io_tree *tree, |
@@ -5231,14 +5232,31 @@ int read_extent_buffer_pages(struct extent_io_tree *tree, | |||
5231 | atomic_set(&eb->io_pages, num_reads); | 5232 | atomic_set(&eb->io_pages, num_reads); |
5232 | for (i = start_i; i < num_pages; i++) { | 5233 | for (i = start_i; i < num_pages; i++) { |
5233 | page = eb->pages[i]; | 5234 | page = eb->pages[i]; |
5235 | |||
5234 | if (!PageUptodate(page)) { | 5236 | if (!PageUptodate(page)) { |
5237 | if (ret) { | ||
5238 | atomic_dec(&eb->io_pages); | ||
5239 | unlock_page(page); | ||
5240 | continue; | ||
5241 | } | ||
5242 | |||
5235 | ClearPageError(page); | 5243 | ClearPageError(page); |
5236 | err = __extent_read_full_page(tree, page, | 5244 | err = __extent_read_full_page(tree, page, |
5237 | get_extent, &bio, | 5245 | get_extent, &bio, |
5238 | mirror_num, &bio_flags, | 5246 | mirror_num, &bio_flags, |
5239 | READ | REQ_META); | 5247 | READ | REQ_META); |
5240 | if (err) | 5248 | if (err) { |
5241 | ret = err; | 5249 | ret = err; |
5250 | /* | ||
5251 | * We use &bio in above __extent_read_full_page, | ||
5252 | * so we ensure that if it returns error, the | ||
5253 | * current page fails to add itself to bio and | ||
5254 | * it's been unlocked. | ||
5255 | * | ||
5256 | * We must dec io_pages by ourselves. | ||
5257 | */ | ||
5258 | atomic_dec(&eb->io_pages); | ||
5259 | } | ||
5242 | } else { | 5260 | } else { |
5243 | unlock_page(page); | 5261 | unlock_page(page); |
5244 | } | 5262 | } |
diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index e0715fcfb11e..26f9ac719d20 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c | |||
@@ -13,7 +13,7 @@ int __init extent_map_init(void) | |||
13 | { | 13 | { |
14 | extent_map_cache = kmem_cache_create("btrfs_extent_map", | 14 | extent_map_cache = kmem_cache_create("btrfs_extent_map", |
15 | sizeof(struct extent_map), 0, | 15 | sizeof(struct extent_map), 0, |
16 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 16 | SLAB_MEM_SPREAD, NULL); |
17 | if (!extent_map_cache) | 17 | if (!extent_map_cache) |
18 | return -ENOMEM; | 18 | return -ENOMEM; |
19 | return 0; | 19 | return 0; |
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 62a81ee13a5f..2fc803da4680 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -27,9 +27,8 @@ | |||
27 | #include "print-tree.h" | 27 | #include "print-tree.h" |
28 | #include "compression.h" | 28 | #include "compression.h" |
29 | 29 | ||
30 | #define __MAX_CSUM_ITEMS(r, size) ((unsigned long)(((BTRFS_LEAF_DATA_SIZE(r) - \ | 30 | #define __MAX_CSUM_ITEMS(r, size) \ |
31 | sizeof(struct btrfs_item) * 2) / \ | 31 | ((unsigned long)(((BTRFS_MAX_ITEM_SIZE(r) * 2) / size) - 1)) |
32 | size) - 1)) | ||
33 | 32 | ||
34 | #define MAX_CSUM_ITEMS(r, size) (min_t(u32, __MAX_CSUM_ITEMS(r, size), \ | 33 | #define MAX_CSUM_ITEMS(r, size) (min_t(u32, __MAX_CSUM_ITEMS(r, size), \ |
35 | PAGE_SIZE)) | 34 | PAGE_SIZE)) |
@@ -250,7 +249,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, | |||
250 | offset + root->sectorsize - 1, | 249 | offset + root->sectorsize - 1, |
251 | EXTENT_NODATASUM); | 250 | EXTENT_NODATASUM); |
252 | } else { | 251 | } else { |
253 | btrfs_info(BTRFS_I(inode)->root->fs_info, | 252 | btrfs_info_rl(BTRFS_I(inode)->root->fs_info, |
254 | "no csum found for inode %llu start %llu", | 253 | "no csum found for inode %llu start %llu", |
255 | btrfs_ino(inode), offset); | 254 | btrfs_ino(inode), offset); |
256 | } | 255 | } |
@@ -699,7 +698,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, | |||
699 | */ | 698 | */ |
700 | ret = btrfs_split_item(trans, root, path, &key, offset); | 699 | ret = btrfs_split_item(trans, root, path, &key, offset); |
701 | if (ret && ret != -EAGAIN) { | 700 | if (ret && ret != -EAGAIN) { |
702 | btrfs_abort_transaction(trans, root, ret); | 701 | btrfs_abort_transaction(trans, ret); |
703 | goto out; | 702 | goto out; |
704 | } | 703 | } |
705 | 704 | ||
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index bcfb4a27ddd4..9404121fd5f7 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -132,7 +132,7 @@ static int __btrfs_add_inode_defrag(struct inode *inode, | |||
132 | 132 | ||
133 | static inline int __need_auto_defrag(struct btrfs_root *root) | 133 | static inline int __need_auto_defrag(struct btrfs_root *root) |
134 | { | 134 | { |
135 | if (!btrfs_test_opt(root, AUTO_DEFRAG)) | 135 | if (!btrfs_test_opt(root->fs_info, AUTO_DEFRAG)) |
136 | return 0; | 136 | return 0; |
137 | 137 | ||
138 | if (btrfs_fs_closing(root->fs_info)) | 138 | if (btrfs_fs_closing(root->fs_info)) |
@@ -950,7 +950,7 @@ delete_extent_item: | |||
950 | ret = btrfs_del_items(trans, root, path, del_slot, | 950 | ret = btrfs_del_items(trans, root, path, del_slot, |
951 | del_nr); | 951 | del_nr); |
952 | if (ret) { | 952 | if (ret) { |
953 | btrfs_abort_transaction(trans, root, ret); | 953 | btrfs_abort_transaction(trans, ret); |
954 | break; | 954 | break; |
955 | } | 955 | } |
956 | 956 | ||
@@ -974,7 +974,7 @@ delete_extent_item: | |||
974 | path->slots[0] = del_slot; | 974 | path->slots[0] = del_slot; |
975 | ret = btrfs_del_items(trans, root, path, del_slot, del_nr); | 975 | ret = btrfs_del_items(trans, root, path, del_slot, del_nr); |
976 | if (ret) | 976 | if (ret) |
977 | btrfs_abort_transaction(trans, root, ret); | 977 | btrfs_abort_transaction(trans, ret); |
978 | } | 978 | } |
979 | 979 | ||
980 | leaf = path->nodes[0]; | 980 | leaf = path->nodes[0]; |
@@ -1190,7 +1190,7 @@ again: | |||
1190 | goto again; | 1190 | goto again; |
1191 | } | 1191 | } |
1192 | if (ret < 0) { | 1192 | if (ret < 0) { |
1193 | btrfs_abort_transaction(trans, root, ret); | 1193 | btrfs_abort_transaction(trans, ret); |
1194 | goto out; | 1194 | goto out; |
1195 | } | 1195 | } |
1196 | 1196 | ||
@@ -1278,7 +1278,7 @@ again: | |||
1278 | 1278 | ||
1279 | ret = btrfs_del_items(trans, root, path, del_slot, del_nr); | 1279 | ret = btrfs_del_items(trans, root, path, del_slot, del_nr); |
1280 | if (ret < 0) { | 1280 | if (ret < 0) { |
1281 | btrfs_abort_transaction(trans, root, ret); | 1281 | btrfs_abort_transaction(trans, ret); |
1282 | goto out; | 1282 | goto out; |
1283 | } | 1283 | } |
1284 | } | 1284 | } |
@@ -2975,7 +2975,7 @@ int btrfs_auto_defrag_init(void) | |||
2975 | { | 2975 | { |
2976 | btrfs_inode_defrag_cachep = kmem_cache_create("btrfs_inode_defrag", | 2976 | btrfs_inode_defrag_cachep = kmem_cache_create("btrfs_inode_defrag", |
2977 | sizeof(struct inode_defrag), 0, | 2977 | sizeof(struct inode_defrag), 0, |
2978 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, | 2978 | SLAB_MEM_SPREAD, |
2979 | NULL); | 2979 | NULL); |
2980 | if (!btrfs_inode_defrag_cachep) | 2980 | if (!btrfs_inode_defrag_cachep) |
2981 | return -ENOMEM; | 2981 | return -ENOMEM; |
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 69d270f6602c..d571bd2b697b 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -280,7 +280,7 @@ fail: | |||
280 | if (locked) | 280 | if (locked) |
281 | mutex_unlock(&trans->transaction->cache_write_mutex); | 281 | mutex_unlock(&trans->transaction->cache_write_mutex); |
282 | if (ret) | 282 | if (ret) |
283 | btrfs_abort_transaction(trans, root, ret); | 283 | btrfs_abort_transaction(trans, ret); |
284 | 284 | ||
285 | return ret; | 285 | return ret; |
286 | } | 286 | } |
@@ -3026,7 +3026,7 @@ int btrfs_find_space_cluster(struct btrfs_root *root, | |||
3026 | * For metadata, allow allocates with smaller extents. For | 3026 | * For metadata, allow allocates with smaller extents. For |
3027 | * data, keep it dense. | 3027 | * data, keep it dense. |
3028 | */ | 3028 | */ |
3029 | if (btrfs_test_opt(root, SSD_SPREAD)) { | 3029 | if (btrfs_test_opt(root->fs_info, SSD_SPREAD)) { |
3030 | cont1_bytes = min_bytes = bytes + empty_size; | 3030 | cont1_bytes = min_bytes = bytes + empty_size; |
3031 | } else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) { | 3031 | } else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) { |
3032 | cont1_bytes = bytes; | 3032 | cont1_bytes = bytes; |
@@ -3470,7 +3470,7 @@ int load_free_ino_cache(struct btrfs_fs_info *fs_info, struct btrfs_root *root) | |||
3470 | int ret = 0; | 3470 | int ret = 0; |
3471 | u64 root_gen = btrfs_root_generation(&root->root_item); | 3471 | u64 root_gen = btrfs_root_generation(&root->root_item); |
3472 | 3472 | ||
3473 | if (!btrfs_test_opt(root, INODE_MAP_CACHE)) | 3473 | if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) |
3474 | return 0; | 3474 | return 0; |
3475 | 3475 | ||
3476 | /* | 3476 | /* |
@@ -3514,7 +3514,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root, | |||
3514 | struct btrfs_io_ctl io_ctl; | 3514 | struct btrfs_io_ctl io_ctl; |
3515 | bool release_metadata = true; | 3515 | bool release_metadata = true; |
3516 | 3516 | ||
3517 | if (!btrfs_test_opt(root, INODE_MAP_CACHE)) | 3517 | if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) |
3518 | return 0; | 3518 | return 0; |
3519 | 3519 | ||
3520 | memset(&io_ctl, 0, sizeof(io_ctl)); | 3520 | memset(&io_ctl, 0, sizeof(io_ctl)); |
diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c index 53dbeaf6ce94..87e7e3d3e676 100644 --- a/fs/btrfs/free-space-tree.c +++ b/fs/btrfs/free-space-tree.c | |||
@@ -305,7 +305,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, | |||
305 | out: | 305 | out: |
306 | kvfree(bitmap); | 306 | kvfree(bitmap); |
307 | if (ret) | 307 | if (ret) |
308 | btrfs_abort_transaction(trans, root, ret); | 308 | btrfs_abort_transaction(trans, ret); |
309 | return ret; | 309 | return ret; |
310 | } | 310 | } |
311 | 311 | ||
@@ -454,7 +454,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans, | |||
454 | out: | 454 | out: |
455 | kvfree(bitmap); | 455 | kvfree(bitmap); |
456 | if (ret) | 456 | if (ret) |
457 | btrfs_abort_transaction(trans, root, ret); | 457 | btrfs_abort_transaction(trans, ret); |
458 | return ret; | 458 | return ret; |
459 | } | 459 | } |
460 | 460 | ||
@@ -851,7 +851,7 @@ int remove_from_free_space_tree(struct btrfs_trans_handle *trans, | |||
851 | out: | 851 | out: |
852 | btrfs_free_path(path); | 852 | btrfs_free_path(path); |
853 | if (ret) | 853 | if (ret) |
854 | btrfs_abort_transaction(trans, fs_info->free_space_root, ret); | 854 | btrfs_abort_transaction(trans, ret); |
855 | return ret; | 855 | return ret; |
856 | } | 856 | } |
857 | 857 | ||
@@ -1047,7 +1047,7 @@ int add_to_free_space_tree(struct btrfs_trans_handle *trans, | |||
1047 | out: | 1047 | out: |
1048 | btrfs_free_path(path); | 1048 | btrfs_free_path(path); |
1049 | if (ret) | 1049 | if (ret) |
1050 | btrfs_abort_transaction(trans, fs_info->free_space_root, ret); | 1050 | btrfs_abort_transaction(trans, ret); |
1051 | return ret; | 1051 | return ret; |
1052 | } | 1052 | } |
1053 | 1053 | ||
@@ -1193,7 +1193,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info) | |||
1193 | 1193 | ||
1194 | abort: | 1194 | abort: |
1195 | fs_info->creating_free_space_tree = 0; | 1195 | fs_info->creating_free_space_tree = 0; |
1196 | btrfs_abort_transaction(trans, tree_root, ret); | 1196 | btrfs_abort_transaction(trans, ret); |
1197 | btrfs_end_transaction(trans, tree_root); | 1197 | btrfs_end_transaction(trans, tree_root); |
1198 | return ret; | 1198 | return ret; |
1199 | } | 1199 | } |
@@ -1280,7 +1280,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info) | |||
1280 | return 0; | 1280 | return 0; |
1281 | 1281 | ||
1282 | abort: | 1282 | abort: |
1283 | btrfs_abort_transaction(trans, tree_root, ret); | 1283 | btrfs_abort_transaction(trans, ret); |
1284 | btrfs_end_transaction(trans, tree_root); | 1284 | btrfs_end_transaction(trans, tree_root); |
1285 | return ret; | 1285 | return ret; |
1286 | } | 1286 | } |
@@ -1333,7 +1333,7 @@ out: | |||
1333 | btrfs_free_path(path); | 1333 | btrfs_free_path(path); |
1334 | mutex_unlock(&block_group->free_space_lock); | 1334 | mutex_unlock(&block_group->free_space_lock); |
1335 | if (ret) | 1335 | if (ret) |
1336 | btrfs_abort_transaction(trans, fs_info->free_space_root, ret); | 1336 | btrfs_abort_transaction(trans, ret); |
1337 | return ret; | 1337 | return ret; |
1338 | } | 1338 | } |
1339 | 1339 | ||
@@ -1410,7 +1410,7 @@ int remove_block_group_free_space(struct btrfs_trans_handle *trans, | |||
1410 | out: | 1410 | out: |
1411 | btrfs_free_path(path); | 1411 | btrfs_free_path(path); |
1412 | if (ret) | 1412 | if (ret) |
1413 | btrfs_abort_transaction(trans, root, ret); | 1413 | btrfs_abort_transaction(trans, ret); |
1414 | return ret; | 1414 | return ret; |
1415 | } | 1415 | } |
1416 | 1416 | ||
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c index 70107f7c9307..aa6fabaee72e 100644 --- a/fs/btrfs/inode-map.c +++ b/fs/btrfs/inode-map.c | |||
@@ -38,7 +38,7 @@ static int caching_kthread(void *data) | |||
38 | int slot; | 38 | int slot; |
39 | int ret; | 39 | int ret; |
40 | 40 | ||
41 | if (!btrfs_test_opt(root, INODE_MAP_CACHE)) | 41 | if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) |
42 | return 0; | 42 | return 0; |
43 | 43 | ||
44 | path = btrfs_alloc_path(); | 44 | path = btrfs_alloc_path(); |
@@ -141,7 +141,7 @@ static void start_caching(struct btrfs_root *root) | |||
141 | int ret; | 141 | int ret; |
142 | u64 objectid; | 142 | u64 objectid; |
143 | 143 | ||
144 | if (!btrfs_test_opt(root, INODE_MAP_CACHE)) | 144 | if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) |
145 | return; | 145 | return; |
146 | 146 | ||
147 | spin_lock(&root->ino_cache_lock); | 147 | spin_lock(&root->ino_cache_lock); |
@@ -185,7 +185,7 @@ static void start_caching(struct btrfs_root *root) | |||
185 | 185 | ||
186 | int btrfs_find_free_ino(struct btrfs_root *root, u64 *objectid) | 186 | int btrfs_find_free_ino(struct btrfs_root *root, u64 *objectid) |
187 | { | 187 | { |
188 | if (!btrfs_test_opt(root, INODE_MAP_CACHE)) | 188 | if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) |
189 | return btrfs_find_free_objectid(root, objectid); | 189 | return btrfs_find_free_objectid(root, objectid); |
190 | 190 | ||
191 | again: | 191 | again: |
@@ -211,7 +211,7 @@ void btrfs_return_ino(struct btrfs_root *root, u64 objectid) | |||
211 | { | 211 | { |
212 | struct btrfs_free_space_ctl *pinned = root->free_ino_pinned; | 212 | struct btrfs_free_space_ctl *pinned = root->free_ino_pinned; |
213 | 213 | ||
214 | if (!btrfs_test_opt(root, INODE_MAP_CACHE)) | 214 | if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) |
215 | return; | 215 | return; |
216 | again: | 216 | again: |
217 | if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { | 217 | if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { |
@@ -251,7 +251,7 @@ void btrfs_unpin_free_ino(struct btrfs_root *root) | |||
251 | struct rb_node *n; | 251 | struct rb_node *n; |
252 | u64 count; | 252 | u64 count; |
253 | 253 | ||
254 | if (!btrfs_test_opt(root, INODE_MAP_CACHE)) | 254 | if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) |
255 | return; | 255 | return; |
256 | 256 | ||
257 | while (1) { | 257 | while (1) { |
@@ -412,7 +412,7 @@ int btrfs_save_ino_cache(struct btrfs_root *root, | |||
412 | if (btrfs_root_refs(&root->root_item) == 0) | 412 | if (btrfs_root_refs(&root->root_item) == 0) |
413 | return 0; | 413 | return 0; |
414 | 414 | ||
415 | if (!btrfs_test_opt(root, INODE_MAP_CACHE)) | 415 | if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) |
416 | return 0; | 416 | return 0; |
417 | 417 | ||
418 | path = btrfs_alloc_path(); | 418 | path = btrfs_alloc_path(); |
@@ -458,7 +458,7 @@ again: | |||
458 | BTRFS_I(inode)->generation = 0; | 458 | BTRFS_I(inode)->generation = 0; |
459 | ret = btrfs_update_inode(trans, root, inode); | 459 | ret = btrfs_update_inode(trans, root, inode); |
460 | if (ret) { | 460 | if (ret) { |
461 | btrfs_abort_transaction(trans, root, ret); | 461 | btrfs_abort_transaction(trans, ret); |
462 | goto out_put; | 462 | goto out_put; |
463 | } | 463 | } |
464 | 464 | ||
@@ -466,7 +466,7 @@ again: | |||
466 | ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode); | 466 | ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode); |
467 | if (ret) { | 467 | if (ret) { |
468 | if (ret != -ENOSPC) | 468 | if (ret != -ENOSPC) |
469 | btrfs_abort_transaction(trans, root, ret); | 469 | btrfs_abort_transaction(trans, ret); |
470 | goto out_put; | 470 | goto out_put; |
471 | } | 471 | } |
472 | } | 472 | } |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3e61bd1f3f65..72cfd15b1fa8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -60,6 +60,7 @@ | |||
60 | #include "hash.h" | 60 | #include "hash.h" |
61 | #include "props.h" | 61 | #include "props.h" |
62 | #include "qgroup.h" | 62 | #include "qgroup.h" |
63 | #include "dedupe.h" | ||
63 | 64 | ||
64 | struct btrfs_iget_args { | 65 | struct btrfs_iget_args { |
65 | struct btrfs_key *location; | 66 | struct btrfs_key *location; |
@@ -105,8 +106,9 @@ static int btrfs_truncate(struct inode *inode); | |||
105 | static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent); | 106 | static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent); |
106 | static noinline int cow_file_range(struct inode *inode, | 107 | static noinline int cow_file_range(struct inode *inode, |
107 | struct page *locked_page, | 108 | struct page *locked_page, |
108 | u64 start, u64 end, int *page_started, | 109 | u64 start, u64 end, u64 delalloc_end, |
109 | unsigned long *nr_written, int unlock); | 110 | int *page_started, unsigned long *nr_written, |
111 | int unlock, struct btrfs_dedupe_hash *hash); | ||
110 | static struct extent_map *create_pinned_em(struct inode *inode, u64 start, | 112 | static struct extent_map *create_pinned_em(struct inode *inode, u64 start, |
111 | u64 len, u64 orig_start, | 113 | u64 len, u64 orig_start, |
112 | u64 block_start, u64 block_len, | 114 | u64 block_start, u64 block_len, |
@@ -294,7 +296,7 @@ static noinline int cow_file_range_inline(struct btrfs_root *root, | |||
294 | start, aligned_end, NULL, | 296 | start, aligned_end, NULL, |
295 | 1, 1, extent_item_size, &extent_inserted); | 297 | 1, 1, extent_item_size, &extent_inserted); |
296 | if (ret) { | 298 | if (ret) { |
297 | btrfs_abort_transaction(trans, root, ret); | 299 | btrfs_abort_transaction(trans, ret); |
298 | goto out; | 300 | goto out; |
299 | } | 301 | } |
300 | 302 | ||
@@ -305,7 +307,7 @@ static noinline int cow_file_range_inline(struct btrfs_root *root, | |||
305 | inline_len, compressed_size, | 307 | inline_len, compressed_size, |
306 | compress_type, compressed_pages); | 308 | compress_type, compressed_pages); |
307 | if (ret && ret != -ENOSPC) { | 309 | if (ret && ret != -ENOSPC) { |
308 | btrfs_abort_transaction(trans, root, ret); | 310 | btrfs_abort_transaction(trans, ret); |
309 | goto out; | 311 | goto out; |
310 | } else if (ret == -ENOSPC) { | 312 | } else if (ret == -ENOSPC) { |
311 | ret = 1; | 313 | ret = 1; |
@@ -374,12 +376,12 @@ static inline int inode_need_compress(struct inode *inode) | |||
374 | struct btrfs_root *root = BTRFS_I(inode)->root; | 376 | struct btrfs_root *root = BTRFS_I(inode)->root; |
375 | 377 | ||
376 | /* force compress */ | 378 | /* force compress */ |
377 | if (btrfs_test_opt(root, FORCE_COMPRESS)) | 379 | if (btrfs_test_opt(root->fs_info, FORCE_COMPRESS)) |
378 | return 1; | 380 | return 1; |
379 | /* bad compression ratios */ | 381 | /* bad compression ratios */ |
380 | if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) | 382 | if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) |
381 | return 0; | 383 | return 0; |
382 | if (btrfs_test_opt(root, COMPRESS) || | 384 | if (btrfs_test_opt(root->fs_info, COMPRESS) || |
383 | BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS || | 385 | BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS || |
384 | BTRFS_I(inode)->force_compress) | 386 | BTRFS_I(inode)->force_compress) |
385 | return 1; | 387 | return 1; |
@@ -585,9 +587,27 @@ cont: | |||
585 | will_compress = 0; | 587 | will_compress = 0; |
586 | } else { | 588 | } else { |
587 | num_bytes = total_in; | 589 | num_bytes = total_in; |
590 | *num_added += 1; | ||
591 | |||
592 | /* | ||
593 | * The async work queues will take care of doing actual | ||
594 | * allocation on disk for these compressed pages, and | ||
595 | * will submit them to the elevator. | ||
596 | */ | ||
597 | add_async_extent(async_cow, start, num_bytes, | ||
598 | total_compressed, pages, nr_pages_ret, | ||
599 | compress_type); | ||
600 | |||
601 | if (start + num_bytes < end) { | ||
602 | start += num_bytes; | ||
603 | pages = NULL; | ||
604 | cond_resched(); | ||
605 | goto again; | ||
606 | } | ||
607 | return; | ||
588 | } | 608 | } |
589 | } | 609 | } |
590 | if (!will_compress && pages) { | 610 | if (pages) { |
591 | /* | 611 | /* |
592 | * the compression code ran but failed to make things smaller, | 612 | * the compression code ran but failed to make things smaller, |
593 | * free any pages it allocated and our page pointer array | 613 | * free any pages it allocated and our page pointer array |
@@ -602,48 +622,28 @@ cont: | |||
602 | nr_pages_ret = 0; | 622 | nr_pages_ret = 0; |
603 | 623 | ||
604 | /* flag the file so we don't compress in the future */ | 624 | /* flag the file so we don't compress in the future */ |
605 | if (!btrfs_test_opt(root, FORCE_COMPRESS) && | 625 | if (!btrfs_test_opt(root->fs_info, FORCE_COMPRESS) && |
606 | !(BTRFS_I(inode)->force_compress)) { | 626 | !(BTRFS_I(inode)->force_compress)) { |
607 | BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS; | 627 | BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS; |
608 | } | 628 | } |
609 | } | 629 | } |
610 | if (will_compress) { | ||
611 | *num_added += 1; | ||
612 | |||
613 | /* the async work queues will take care of doing actual | ||
614 | * allocation on disk for these compressed pages, | ||
615 | * and will submit them to the elevator. | ||
616 | */ | ||
617 | add_async_extent(async_cow, start, num_bytes, | ||
618 | total_compressed, pages, nr_pages_ret, | ||
619 | compress_type); | ||
620 | |||
621 | if (start + num_bytes < end) { | ||
622 | start += num_bytes; | ||
623 | pages = NULL; | ||
624 | cond_resched(); | ||
625 | goto again; | ||
626 | } | ||
627 | } else { | ||
628 | cleanup_and_bail_uncompressed: | 630 | cleanup_and_bail_uncompressed: |
629 | /* | 631 | /* |
630 | * No compression, but we still need to write the pages in | 632 | * No compression, but we still need to write the pages in the file |
631 | * the file we've been given so far. redirty the locked | 633 | * we've been given so far. redirty the locked page if it corresponds |
632 | * page if it corresponds to our extent and set things up | 634 | * to our extent and set things up for the async work queue to run |
633 | * for the async work queue to run cow_file_range to do | 635 | * cow_file_range to do the normal delalloc dance. |
634 | * the normal delalloc dance | 636 | */ |
635 | */ | 637 | if (page_offset(locked_page) >= start && |
636 | if (page_offset(locked_page) >= start && | 638 | page_offset(locked_page) <= end) |
637 | page_offset(locked_page) <= end) { | 639 | __set_page_dirty_nobuffers(locked_page); |
638 | __set_page_dirty_nobuffers(locked_page); | 640 | /* unlocked later on in the async handlers */ |
639 | /* unlocked later on in the async handlers */ | 641 | |
640 | } | 642 | if (redirty) |
641 | if (redirty) | 643 | extent_range_redirty_for_io(inode, start, end); |
642 | extent_range_redirty_for_io(inode, start, end); | 644 | add_async_extent(async_cow, start, end - start + 1, 0, NULL, 0, |
643 | add_async_extent(async_cow, start, end - start + 1, | 645 | BTRFS_COMPRESS_NONE); |
644 | 0, NULL, 0, BTRFS_COMPRESS_NONE); | 646 | *num_added += 1; |
645 | *num_added += 1; | ||
646 | } | ||
647 | 647 | ||
648 | return; | 648 | return; |
649 | 649 | ||
@@ -712,7 +712,10 @@ retry: | |||
712 | async_extent->start, | 712 | async_extent->start, |
713 | async_extent->start + | 713 | async_extent->start + |
714 | async_extent->ram_size - 1, | 714 | async_extent->ram_size - 1, |
715 | &page_started, &nr_written, 0); | 715 | async_extent->start + |
716 | async_extent->ram_size - 1, | ||
717 | &page_started, &nr_written, 0, | ||
718 | NULL); | ||
716 | 719 | ||
717 | /* JDM XXX */ | 720 | /* JDM XXX */ |
718 | 721 | ||
@@ -925,9 +928,9 @@ static u64 get_extent_allocation_hint(struct inode *inode, u64 start, | |||
925 | */ | 928 | */ |
926 | static noinline int cow_file_range(struct inode *inode, | 929 | static noinline int cow_file_range(struct inode *inode, |
927 | struct page *locked_page, | 930 | struct page *locked_page, |
928 | u64 start, u64 end, int *page_started, | 931 | u64 start, u64 end, u64 delalloc_end, |
929 | unsigned long *nr_written, | 932 | int *page_started, unsigned long *nr_written, |
930 | int unlock) | 933 | int unlock, struct btrfs_dedupe_hash *hash) |
931 | { | 934 | { |
932 | struct btrfs_root *root = BTRFS_I(inode)->root; | 935 | struct btrfs_root *root = BTRFS_I(inode)->root; |
933 | u64 alloc_hint = 0; | 936 | u64 alloc_hint = 0; |
@@ -1156,7 +1159,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page, | |||
1156 | async_cow->start = start; | 1159 | async_cow->start = start; |
1157 | 1160 | ||
1158 | if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS && | 1161 | if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS && |
1159 | !btrfs_test_opt(root, FORCE_COMPRESS)) | 1162 | !btrfs_test_opt(root->fs_info, FORCE_COMPRESS)) |
1160 | cur_end = end; | 1163 | cur_end = end; |
1161 | else | 1164 | else |
1162 | cur_end = min(end, start + SZ_512K - 1); | 1165 | cur_end = min(end, start + SZ_512K - 1); |
@@ -1418,7 +1421,8 @@ out_check: | |||
1418 | if (cow_start != (u64)-1) { | 1421 | if (cow_start != (u64)-1) { |
1419 | ret = cow_file_range(inode, locked_page, | 1422 | ret = cow_file_range(inode, locked_page, |
1420 | cow_start, found_key.offset - 1, | 1423 | cow_start, found_key.offset - 1, |
1421 | page_started, nr_written, 1); | 1424 | end, page_started, nr_written, 1, |
1425 | NULL); | ||
1422 | if (ret) { | 1426 | if (ret) { |
1423 | if (!nolock && nocow) | 1427 | if (!nolock && nocow) |
1424 | btrfs_end_write_no_snapshoting(root); | 1428 | btrfs_end_write_no_snapshoting(root); |
@@ -1501,8 +1505,8 @@ out_check: | |||
1501 | } | 1505 | } |
1502 | 1506 | ||
1503 | if (cow_start != (u64)-1) { | 1507 | if (cow_start != (u64)-1) { |
1504 | ret = cow_file_range(inode, locked_page, cow_start, end, | 1508 | ret = cow_file_range(inode, locked_page, cow_start, end, end, |
1505 | page_started, nr_written, 1); | 1509 | page_started, nr_written, 1, NULL); |
1506 | if (ret) | 1510 | if (ret) |
1507 | goto error; | 1511 | goto error; |
1508 | } | 1512 | } |
@@ -1561,8 +1565,8 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page, | |||
1561 | ret = run_delalloc_nocow(inode, locked_page, start, end, | 1565 | ret = run_delalloc_nocow(inode, locked_page, start, end, |
1562 | page_started, 0, nr_written); | 1566 | page_started, 0, nr_written); |
1563 | } else if (!inode_need_compress(inode)) { | 1567 | } else if (!inode_need_compress(inode)) { |
1564 | ret = cow_file_range(inode, locked_page, start, end, | 1568 | ret = cow_file_range(inode, locked_page, start, end, end, |
1565 | page_started, nr_written, 1); | 1569 | page_started, nr_written, 1, NULL); |
1566 | } else { | 1570 | } else { |
1567 | set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, | 1571 | set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, |
1568 | &BTRFS_I(inode)->runtime_flags); | 1572 | &BTRFS_I(inode)->runtime_flags); |
@@ -1740,7 +1744,7 @@ static void btrfs_set_bit_hook(struct inode *inode, | |||
1740 | } | 1744 | } |
1741 | 1745 | ||
1742 | /* For sanity tests */ | 1746 | /* For sanity tests */ |
1743 | if (btrfs_test_is_dummy_root(root)) | 1747 | if (btrfs_is_testing(root->fs_info)) |
1744 | return; | 1748 | return; |
1745 | 1749 | ||
1746 | __percpu_counter_add(&root->fs_info->delalloc_bytes, len, | 1750 | __percpu_counter_add(&root->fs_info->delalloc_bytes, len, |
@@ -1799,7 +1803,7 @@ static void btrfs_clear_bit_hook(struct inode *inode, | |||
1799 | btrfs_delalloc_release_metadata(inode, len); | 1803 | btrfs_delalloc_release_metadata(inode, len); |
1800 | 1804 | ||
1801 | /* For sanity tests. */ | 1805 | /* For sanity tests. */ |
1802 | if (btrfs_test_is_dummy_root(root)) | 1806 | if (btrfs_is_testing(root->fs_info)) |
1803 | return; | 1807 | return; |
1804 | 1808 | ||
1805 | if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID | 1809 | if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID |
@@ -1822,6 +1826,10 @@ static void btrfs_clear_bit_hook(struct inode *inode, | |||
1822 | /* | 1826 | /* |
1823 | * extent_io.c merge_bio_hook, this must check the chunk tree to make sure | 1827 | * extent_io.c merge_bio_hook, this must check the chunk tree to make sure |
1824 | * we don't create bios that span stripes or chunks | 1828 | * we don't create bios that span stripes or chunks |
1829 | * | ||
1830 | * return 1 if page cannot be merged to bio | ||
1831 | * return 0 if page can be merged to bio | ||
1832 | * return error otherwise | ||
1825 | */ | 1833 | */ |
1826 | int btrfs_merge_bio_hook(int rw, struct page *page, unsigned long offset, | 1834 | int btrfs_merge_bio_hook(int rw, struct page *page, unsigned long offset, |
1827 | size_t size, struct bio *bio, | 1835 | size_t size, struct bio *bio, |
@@ -1840,8 +1848,8 @@ int btrfs_merge_bio_hook(int rw, struct page *page, unsigned long offset, | |||
1840 | map_length = length; | 1848 | map_length = length; |
1841 | ret = btrfs_map_block(root->fs_info, rw, logical, | 1849 | ret = btrfs_map_block(root->fs_info, rw, logical, |
1842 | &map_length, NULL, 0); | 1850 | &map_length, NULL, 0); |
1843 | /* Will always return 0 with map_multi == NULL */ | 1851 | if (ret < 0) |
1844 | BUG_ON(ret < 0); | 1852 | return ret; |
1845 | if (map_length < length + size) | 1853 | if (map_length < length + size) |
1846 | return 1; | 1854 | return 1; |
1847 | return 0; | 1855 | return 0; |
@@ -2595,7 +2603,7 @@ again: | |||
2595 | ret = btrfs_insert_empty_item(trans, root, path, &key, | 2603 | ret = btrfs_insert_empty_item(trans, root, path, &key, |
2596 | sizeof(*extent)); | 2604 | sizeof(*extent)); |
2597 | if (ret) { | 2605 | if (ret) { |
2598 | btrfs_abort_transaction(trans, root, ret); | 2606 | btrfs_abort_transaction(trans, ret); |
2599 | goto out_free_path; | 2607 | goto out_free_path; |
2600 | } | 2608 | } |
2601 | 2609 | ||
@@ -2622,7 +2630,7 @@ again: | |||
2622 | backref->root_id, backref->inum, | 2630 | backref->root_id, backref->inum, |
2623 | new->file_pos); /* start - extent_offset */ | 2631 | new->file_pos); /* start - extent_offset */ |
2624 | if (ret) { | 2632 | if (ret) { |
2625 | btrfs_abort_transaction(trans, root, ret); | 2633 | btrfs_abort_transaction(trans, ret); |
2626 | goto out_free_path; | 2634 | goto out_free_path; |
2627 | } | 2635 | } |
2628 | 2636 | ||
@@ -2891,7 +2899,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) | |||
2891 | trans->block_rsv = &root->fs_info->delalloc_block_rsv; | 2899 | trans->block_rsv = &root->fs_info->delalloc_block_rsv; |
2892 | ret = btrfs_update_inode_fallback(trans, root, inode); | 2900 | ret = btrfs_update_inode_fallback(trans, root, inode); |
2893 | if (ret) /* -ENOMEM or corruption */ | 2901 | if (ret) /* -ENOMEM or corruption */ |
2894 | btrfs_abort_transaction(trans, root, ret); | 2902 | btrfs_abort_transaction(trans, ret); |
2895 | goto out; | 2903 | goto out; |
2896 | } | 2904 | } |
2897 | 2905 | ||
@@ -2951,7 +2959,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) | |||
2951 | ordered_extent->file_offset, ordered_extent->len, | 2959 | ordered_extent->file_offset, ordered_extent->len, |
2952 | trans->transid); | 2960 | trans->transid); |
2953 | if (ret < 0) { | 2961 | if (ret < 0) { |
2954 | btrfs_abort_transaction(trans, root, ret); | 2962 | btrfs_abort_transaction(trans, ret); |
2955 | goto out_unlock; | 2963 | goto out_unlock; |
2956 | } | 2964 | } |
2957 | 2965 | ||
@@ -2961,7 +2969,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) | |||
2961 | btrfs_ordered_update_i_size(inode, 0, ordered_extent); | 2969 | btrfs_ordered_update_i_size(inode, 0, ordered_extent); |
2962 | ret = btrfs_update_inode_fallback(trans, root, inode); | 2970 | ret = btrfs_update_inode_fallback(trans, root, inode); |
2963 | if (ret) { /* -ENOMEM or corruption */ | 2971 | if (ret) { /* -ENOMEM or corruption */ |
2964 | btrfs_abort_transaction(trans, root, ret); | 2972 | btrfs_abort_transaction(trans, ret); |
2965 | goto out_unlock; | 2973 | goto out_unlock; |
2966 | } | 2974 | } |
2967 | ret = 0; | 2975 | ret = 0; |
@@ -3205,7 +3213,7 @@ void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans, | |||
3205 | ret = btrfs_del_orphan_item(trans, root->fs_info->tree_root, | 3213 | ret = btrfs_del_orphan_item(trans, root->fs_info->tree_root, |
3206 | root->root_key.objectid); | 3214 | root->root_key.objectid); |
3207 | if (ret) | 3215 | if (ret) |
3208 | btrfs_abort_transaction(trans, root, ret); | 3216 | btrfs_abort_transaction(trans, ret); |
3209 | else | 3217 | else |
3210 | clear_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, | 3218 | clear_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, |
3211 | &root->state); | 3219 | &root->state); |
@@ -3296,7 +3304,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode) | |||
3296 | if (ret != -EEXIST) { | 3304 | if (ret != -EEXIST) { |
3297 | clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, | 3305 | clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, |
3298 | &BTRFS_I(inode)->runtime_flags); | 3306 | &BTRFS_I(inode)->runtime_flags); |
3299 | btrfs_abort_transaction(trans, root, ret); | 3307 | btrfs_abort_transaction(trans, ret); |
3300 | return ret; | 3308 | return ret; |
3301 | } | 3309 | } |
3302 | } | 3310 | } |
@@ -3308,7 +3316,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode) | |||
3308 | ret = btrfs_insert_orphan_item(trans, root->fs_info->tree_root, | 3316 | ret = btrfs_insert_orphan_item(trans, root->fs_info->tree_root, |
3309 | root->root_key.objectid); | 3317 | root->root_key.objectid); |
3310 | if (ret && ret != -EEXIST) { | 3318 | if (ret && ret != -EEXIST) { |
3311 | btrfs_abort_transaction(trans, root, ret); | 3319 | btrfs_abort_transaction(trans, ret); |
3312 | return ret; | 3320 | return ret; |
3313 | } | 3321 | } |
3314 | } | 3322 | } |
@@ -4007,20 +4015,20 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans, | |||
4007 | btrfs_info(root->fs_info, | 4015 | btrfs_info(root->fs_info, |
4008 | "failed to delete reference to %.*s, inode %llu parent %llu", | 4016 | "failed to delete reference to %.*s, inode %llu parent %llu", |
4009 | name_len, name, ino, dir_ino); | 4017 | name_len, name, ino, dir_ino); |
4010 | btrfs_abort_transaction(trans, root, ret); | 4018 | btrfs_abort_transaction(trans, ret); |
4011 | goto err; | 4019 | goto err; |
4012 | } | 4020 | } |
4013 | skip_backref: | 4021 | skip_backref: |
4014 | ret = btrfs_delete_delayed_dir_index(trans, root, dir, index); | 4022 | ret = btrfs_delete_delayed_dir_index(trans, root, dir, index); |
4015 | if (ret) { | 4023 | if (ret) { |
4016 | btrfs_abort_transaction(trans, root, ret); | 4024 | btrfs_abort_transaction(trans, ret); |
4017 | goto err; | 4025 | goto err; |
4018 | } | 4026 | } |
4019 | 4027 | ||
4020 | ret = btrfs_del_inode_ref_in_log(trans, root, name, name_len, | 4028 | ret = btrfs_del_inode_ref_in_log(trans, root, name, name_len, |
4021 | inode, dir_ino); | 4029 | inode, dir_ino); |
4022 | if (ret != 0 && ret != -ENOENT) { | 4030 | if (ret != 0 && ret != -ENOENT) { |
4023 | btrfs_abort_transaction(trans, root, ret); | 4031 | btrfs_abort_transaction(trans, ret); |
4024 | goto err; | 4032 | goto err; |
4025 | } | 4033 | } |
4026 | 4034 | ||
@@ -4029,7 +4037,7 @@ skip_backref: | |||
4029 | if (ret == -ENOENT) | 4037 | if (ret == -ENOENT) |
4030 | ret = 0; | 4038 | ret = 0; |
4031 | else if (ret) | 4039 | else if (ret) |
4032 | btrfs_abort_transaction(trans, root, ret); | 4040 | btrfs_abort_transaction(trans, ret); |
4033 | err: | 4041 | err: |
4034 | btrfs_free_path(path); | 4042 | btrfs_free_path(path); |
4035 | if (ret) | 4043 | if (ret) |
@@ -4143,7 +4151,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, | |||
4143 | WARN_ON(key.type != BTRFS_ROOT_ITEM_KEY || key.objectid != objectid); | 4151 | WARN_ON(key.type != BTRFS_ROOT_ITEM_KEY || key.objectid != objectid); |
4144 | ret = btrfs_delete_one_dir_name(trans, root, path, di); | 4152 | ret = btrfs_delete_one_dir_name(trans, root, path, di); |
4145 | if (ret) { | 4153 | if (ret) { |
4146 | btrfs_abort_transaction(trans, root, ret); | 4154 | btrfs_abort_transaction(trans, ret); |
4147 | goto out; | 4155 | goto out; |
4148 | } | 4156 | } |
4149 | btrfs_release_path(path); | 4157 | btrfs_release_path(path); |
@@ -4153,7 +4161,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, | |||
4153 | dir_ino, &index, name, name_len); | 4161 | dir_ino, &index, name, name_len); |
4154 | if (ret < 0) { | 4162 | if (ret < 0) { |
4155 | if (ret != -ENOENT) { | 4163 | if (ret != -ENOENT) { |
4156 | btrfs_abort_transaction(trans, root, ret); | 4164 | btrfs_abort_transaction(trans, ret); |
4157 | goto out; | 4165 | goto out; |
4158 | } | 4166 | } |
4159 | di = btrfs_search_dir_index_item(root, path, dir_ino, | 4167 | di = btrfs_search_dir_index_item(root, path, dir_ino, |
@@ -4163,7 +4171,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, | |||
4163 | ret = -ENOENT; | 4171 | ret = -ENOENT; |
4164 | else | 4172 | else |
4165 | ret = PTR_ERR(di); | 4173 | ret = PTR_ERR(di); |
4166 | btrfs_abort_transaction(trans, root, ret); | 4174 | btrfs_abort_transaction(trans, ret); |
4167 | goto out; | 4175 | goto out; |
4168 | } | 4176 | } |
4169 | 4177 | ||
@@ -4176,7 +4184,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, | |||
4176 | 4184 | ||
4177 | ret = btrfs_delete_delayed_dir_index(trans, root, dir, index); | 4185 | ret = btrfs_delete_delayed_dir_index(trans, root, dir, index); |
4178 | if (ret) { | 4186 | if (ret) { |
4179 | btrfs_abort_transaction(trans, root, ret); | 4187 | btrfs_abort_transaction(trans, ret); |
4180 | goto out; | 4188 | goto out; |
4181 | } | 4189 | } |
4182 | 4190 | ||
@@ -4185,7 +4193,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, | |||
4185 | dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb); | 4193 | dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb); |
4186 | ret = btrfs_update_inode_fallback(trans, root, dir); | 4194 | ret = btrfs_update_inode_fallback(trans, root, dir); |
4187 | if (ret) | 4195 | if (ret) |
4188 | btrfs_abort_transaction(trans, root, ret); | 4196 | btrfs_abort_transaction(trans, ret); |
4189 | out: | 4197 | out: |
4190 | btrfs_free_path(path); | 4198 | btrfs_free_path(path); |
4191 | return ret; | 4199 | return ret; |
@@ -4506,7 +4514,6 @@ search_again: | |||
4506 | pending_del_nr); | 4514 | pending_del_nr); |
4507 | if (err) { | 4515 | if (err) { |
4508 | btrfs_abort_transaction(trans, | 4516 | btrfs_abort_transaction(trans, |
4509 | root, | ||
4510 | err); | 4517 | err); |
4511 | goto error; | 4518 | goto error; |
4512 | } | 4519 | } |
@@ -4518,8 +4525,7 @@ search_again: | |||
4518 | item_end, | 4525 | item_end, |
4519 | new_size); | 4526 | new_size); |
4520 | if (err) { | 4527 | if (err) { |
4521 | btrfs_abort_transaction(trans, | 4528 | btrfs_abort_transaction(trans, err); |
4522 | root, err); | ||
4523 | goto error; | 4529 | goto error; |
4524 | } | 4530 | } |
4525 | } else if (test_bit(BTRFS_ROOT_REF_COWS, | 4531 | } else if (test_bit(BTRFS_ROOT_REF_COWS, |
@@ -4583,8 +4589,7 @@ delete: | |||
4583 | pending_del_slot, | 4589 | pending_del_slot, |
4584 | pending_del_nr); | 4590 | pending_del_nr); |
4585 | if (ret) { | 4591 | if (ret) { |
4586 | btrfs_abort_transaction(trans, | 4592 | btrfs_abort_transaction(trans, ret); |
4587 | root, ret); | ||
4588 | goto error; | 4593 | goto error; |
4589 | } | 4594 | } |
4590 | pending_del_nr = 0; | 4595 | pending_del_nr = 0; |
@@ -4617,7 +4622,7 @@ out: | |||
4617 | ret = btrfs_del_items(trans, root, path, pending_del_slot, | 4622 | ret = btrfs_del_items(trans, root, path, pending_del_slot, |
4618 | pending_del_nr); | 4623 | pending_del_nr); |
4619 | if (ret) | 4624 | if (ret) |
4620 | btrfs_abort_transaction(trans, root, ret); | 4625 | btrfs_abort_transaction(trans, ret); |
4621 | } | 4626 | } |
4622 | error: | 4627 | error: |
4623 | if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) | 4628 | if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) |
@@ -4786,7 +4791,7 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, | |||
4786 | 4791 | ||
4787 | ret = btrfs_drop_extents(trans, root, inode, offset, offset + len, 1); | 4792 | ret = btrfs_drop_extents(trans, root, inode, offset, offset + len, 1); |
4788 | if (ret) { | 4793 | if (ret) { |
4789 | btrfs_abort_transaction(trans, root, ret); | 4794 | btrfs_abort_transaction(trans, ret); |
4790 | btrfs_end_transaction(trans, root); | 4795 | btrfs_end_transaction(trans, root); |
4791 | return ret; | 4796 | return ret; |
4792 | } | 4797 | } |
@@ -4794,7 +4799,7 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, | |||
4794 | ret = btrfs_insert_file_extent(trans, root, btrfs_ino(inode), offset, | 4799 | ret = btrfs_insert_file_extent(trans, root, btrfs_ino(inode), offset, |
4795 | 0, 0, len, 0, len, 0, 0, 0); | 4800 | 0, 0, len, 0, len, 0, 0, 0); |
4796 | if (ret) | 4801 | if (ret) |
4797 | btrfs_abort_transaction(trans, root, ret); | 4802 | btrfs_abort_transaction(trans, ret); |
4798 | else | 4803 | else |
4799 | btrfs_update_inode(trans, root, inode); | 4804 | btrfs_update_inode(trans, root, inode); |
4800 | btrfs_end_transaction(trans, root); | 4805 | btrfs_end_transaction(trans, root); |
@@ -5021,7 +5026,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) | |||
5021 | i_size_write(inode, BTRFS_I(inode)->disk_i_size); | 5026 | i_size_write(inode, BTRFS_I(inode)->disk_i_size); |
5022 | err = btrfs_orphan_del(trans, inode); | 5027 | err = btrfs_orphan_del(trans, inode); |
5023 | if (err) | 5028 | if (err) |
5024 | btrfs_abort_transaction(trans, root, err); | 5029 | btrfs_abort_transaction(trans, err); |
5025 | btrfs_end_transaction(trans, root); | 5030 | btrfs_end_transaction(trans, root); |
5026 | } | 5031 | } |
5027 | } | 5032 | } |
@@ -5159,11 +5164,18 @@ void btrfs_evict_inode(struct inode *inode) | |||
5159 | struct btrfs_root *root = BTRFS_I(inode)->root; | 5164 | struct btrfs_root *root = BTRFS_I(inode)->root; |
5160 | struct btrfs_block_rsv *rsv, *global_rsv; | 5165 | struct btrfs_block_rsv *rsv, *global_rsv; |
5161 | int steal_from_global = 0; | 5166 | int steal_from_global = 0; |
5162 | u64 min_size = btrfs_calc_trunc_metadata_size(root, 1); | 5167 | u64 min_size; |
5163 | int ret; | 5168 | int ret; |
5164 | 5169 | ||
5165 | trace_btrfs_inode_evict(inode); | 5170 | trace_btrfs_inode_evict(inode); |
5166 | 5171 | ||
5172 | if (!root) { | ||
5173 | kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); | ||
5174 | return; | ||
5175 | } | ||
5176 | |||
5177 | min_size = btrfs_calc_trunc_metadata_size(root, 1); | ||
5178 | |||
5167 | evict_inode_truncate_pages(inode); | 5179 | evict_inode_truncate_pages(inode); |
5168 | 5180 | ||
5169 | if (inode->i_nlink && | 5181 | if (inode->i_nlink && |
@@ -6240,9 +6252,9 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
6240 | btrfs_inherit_iflags(inode, dir); | 6252 | btrfs_inherit_iflags(inode, dir); |
6241 | 6253 | ||
6242 | if (S_ISREG(mode)) { | 6254 | if (S_ISREG(mode)) { |
6243 | if (btrfs_test_opt(root, NODATASUM)) | 6255 | if (btrfs_test_opt(root->fs_info, NODATASUM)) |
6244 | BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM; | 6256 | BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM; |
6245 | if (btrfs_test_opt(root, NODATACOW)) | 6257 | if (btrfs_test_opt(root->fs_info, NODATACOW)) |
6246 | BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW | | 6258 | BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW | |
6247 | BTRFS_INODE_NODATASUM; | 6259 | BTRFS_INODE_NODATASUM; |
6248 | } | 6260 | } |
@@ -6320,7 +6332,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans, | |||
6320 | if (ret == -EEXIST || ret == -EOVERFLOW) | 6332 | if (ret == -EEXIST || ret == -EOVERFLOW) |
6321 | goto fail_dir_item; | 6333 | goto fail_dir_item; |
6322 | else if (ret) { | 6334 | else if (ret) { |
6323 | btrfs_abort_transaction(trans, root, ret); | 6335 | btrfs_abort_transaction(trans, ret); |
6324 | return ret; | 6336 | return ret; |
6325 | } | 6337 | } |
6326 | 6338 | ||
@@ -6331,7 +6343,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans, | |||
6331 | current_fs_time(parent_inode->i_sb); | 6343 | current_fs_time(parent_inode->i_sb); |
6332 | ret = btrfs_update_inode(trans, root, parent_inode); | 6344 | ret = btrfs_update_inode(trans, root, parent_inode); |
6333 | if (ret) | 6345 | if (ret) |
6334 | btrfs_abort_transaction(trans, root, ret); | 6346 | btrfs_abort_transaction(trans, ret); |
6335 | return ret; | 6347 | return ret; |
6336 | 6348 | ||
6337 | fail_dir_item: | 6349 | fail_dir_item: |
@@ -9385,25 +9397,25 @@ int btrfs_init_cachep(void) | |||
9385 | 9397 | ||
9386 | btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle", | 9398 | btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle", |
9387 | sizeof(struct btrfs_trans_handle), 0, | 9399 | sizeof(struct btrfs_trans_handle), 0, |
9388 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 9400 | SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL); |
9389 | if (!btrfs_trans_handle_cachep) | 9401 | if (!btrfs_trans_handle_cachep) |
9390 | goto fail; | 9402 | goto fail; |
9391 | 9403 | ||
9392 | btrfs_transaction_cachep = kmem_cache_create("btrfs_transaction", | 9404 | btrfs_transaction_cachep = kmem_cache_create("btrfs_transaction", |
9393 | sizeof(struct btrfs_transaction), 0, | 9405 | sizeof(struct btrfs_transaction), 0, |
9394 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 9406 | SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL); |
9395 | if (!btrfs_transaction_cachep) | 9407 | if (!btrfs_transaction_cachep) |
9396 | goto fail; | 9408 | goto fail; |
9397 | 9409 | ||
9398 | btrfs_path_cachep = kmem_cache_create("btrfs_path", | 9410 | btrfs_path_cachep = kmem_cache_create("btrfs_path", |
9399 | sizeof(struct btrfs_path), 0, | 9411 | sizeof(struct btrfs_path), 0, |
9400 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 9412 | SLAB_MEM_SPREAD, NULL); |
9401 | if (!btrfs_path_cachep) | 9413 | if (!btrfs_path_cachep) |
9402 | goto fail; | 9414 | goto fail; |
9403 | 9415 | ||
9404 | btrfs_free_space_cachep = kmem_cache_create("btrfs_free_space", | 9416 | btrfs_free_space_cachep = kmem_cache_create("btrfs_free_space", |
9405 | sizeof(struct btrfs_free_space), 0, | 9417 | sizeof(struct btrfs_free_space), 0, |
9406 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | 9418 | SLAB_MEM_SPREAD, NULL); |
9407 | if (!btrfs_free_space_cachep) | 9419 | if (!btrfs_free_space_cachep) |
9408 | goto fail; | 9420 | goto fail; |
9409 | 9421 | ||
@@ -9553,7 +9565,7 @@ static int btrfs_rename_exchange(struct inode *old_dir, | |||
9553 | ret = btrfs_update_inode(trans, root, old_inode); | 9565 | ret = btrfs_update_inode(trans, root, old_inode); |
9554 | } | 9566 | } |
9555 | if (ret) { | 9567 | if (ret) { |
9556 | btrfs_abort_transaction(trans, root, ret); | 9568 | btrfs_abort_transaction(trans, ret); |
9557 | goto out_fail; | 9569 | goto out_fail; |
9558 | } | 9570 | } |
9559 | 9571 | ||
@@ -9573,7 +9585,7 @@ static int btrfs_rename_exchange(struct inode *old_dir, | |||
9573 | ret = btrfs_update_inode(trans, dest, new_inode); | 9585 | ret = btrfs_update_inode(trans, dest, new_inode); |
9574 | } | 9586 | } |
9575 | if (ret) { | 9587 | if (ret) { |
9576 | btrfs_abort_transaction(trans, root, ret); | 9588 | btrfs_abort_transaction(trans, ret); |
9577 | goto out_fail; | 9589 | goto out_fail; |
9578 | } | 9590 | } |
9579 | 9591 | ||
@@ -9581,7 +9593,7 @@ static int btrfs_rename_exchange(struct inode *old_dir, | |||
9581 | new_dentry->d_name.name, | 9593 | new_dentry->d_name.name, |
9582 | new_dentry->d_name.len, 0, old_idx); | 9594 | new_dentry->d_name.len, 0, old_idx); |
9583 | if (ret) { | 9595 | if (ret) { |
9584 | btrfs_abort_transaction(trans, root, ret); | 9596 | btrfs_abort_transaction(trans, ret); |
9585 | goto out_fail; | 9597 | goto out_fail; |
9586 | } | 9598 | } |
9587 | 9599 | ||
@@ -9589,7 +9601,7 @@ static int btrfs_rename_exchange(struct inode *old_dir, | |||
9589 | old_dentry->d_name.name, | 9601 | old_dentry->d_name.name, |
9590 | old_dentry->d_name.len, 0, new_idx); | 9602 | old_dentry->d_name.len, 0, new_idx); |
9591 | if (ret) { | 9603 | if (ret) { |
9592 | btrfs_abort_transaction(trans, root, ret); | 9604 | btrfs_abort_transaction(trans, ret); |
9593 | goto out_fail; | 9605 | goto out_fail; |
9594 | } | 9606 | } |
9595 | 9607 | ||
@@ -9828,7 +9840,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
9828 | ret = btrfs_update_inode(trans, root, old_inode); | 9840 | ret = btrfs_update_inode(trans, root, old_inode); |
9829 | } | 9841 | } |
9830 | if (ret) { | 9842 | if (ret) { |
9831 | btrfs_abort_transaction(trans, root, ret); | 9843 | btrfs_abort_transaction(trans, ret); |
9832 | goto out_fail; | 9844 | goto out_fail; |
9833 | } | 9845 | } |
9834 | 9846 | ||
@@ -9852,7 +9864,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
9852 | if (!ret && new_inode->i_nlink == 0) | 9864 | if (!ret && new_inode->i_nlink == 0) |
9853 | ret = btrfs_orphan_add(trans, d_inode(new_dentry)); | 9865 | ret = btrfs_orphan_add(trans, d_inode(new_dentry)); |
9854 | if (ret) { | 9866 | if (ret) { |
9855 | btrfs_abort_transaction(trans, root, ret); | 9867 | btrfs_abort_transaction(trans, ret); |
9856 | goto out_fail; | 9868 | goto out_fail; |
9857 | } | 9869 | } |
9858 | } | 9870 | } |
@@ -9861,7 +9873,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
9861 | new_dentry->d_name.name, | 9873 | new_dentry->d_name.name, |
9862 | new_dentry->d_name.len, 0, index); | 9874 | new_dentry->d_name.len, 0, index); |
9863 | if (ret) { | 9875 | if (ret) { |
9864 | btrfs_abort_transaction(trans, root, ret); | 9876 | btrfs_abort_transaction(trans, ret); |
9865 | goto out_fail; | 9877 | goto out_fail; |
9866 | } | 9878 | } |
9867 | 9879 | ||
@@ -9881,7 +9893,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
9881 | old_dentry); | 9893 | old_dentry); |
9882 | 9894 | ||
9883 | if (ret) { | 9895 | if (ret) { |
9884 | btrfs_abort_transaction(trans, root, ret); | 9896 | btrfs_abort_transaction(trans, ret); |
9885 | goto out_fail; | 9897 | goto out_fail; |
9886 | } | 9898 | } |
9887 | } | 9899 | } |
@@ -10307,7 +10319,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode, | |||
10307 | if (ret) { | 10319 | if (ret) { |
10308 | btrfs_free_reserved_extent(root, ins.objectid, | 10320 | btrfs_free_reserved_extent(root, ins.objectid, |
10309 | ins.offset, 0); | 10321 | ins.offset, 0); |
10310 | btrfs_abort_transaction(trans, root, ret); | 10322 | btrfs_abort_transaction(trans, ret); |
10311 | if (own_trans) | 10323 | if (own_trans) |
10312 | btrfs_end_transaction(trans, root); | 10324 | btrfs_end_transaction(trans, root); |
10313 | break; | 10325 | break; |
@@ -10367,7 +10379,7 @@ next: | |||
10367 | ret = btrfs_update_inode(trans, root, inode); | 10379 | ret = btrfs_update_inode(trans, root, inode); |
10368 | 10380 | ||
10369 | if (ret) { | 10381 | if (ret) { |
10370 | btrfs_abort_transaction(trans, root, ret); | 10382 | btrfs_abort_transaction(trans, ret); |
10371 | if (own_trans) | 10383 | if (own_trans) |
10372 | btrfs_end_transaction(trans, root); | 10384 | btrfs_end_transaction(trans, root); |
10373 | break; | 10385 | break; |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 05173563e4a6..14ed1e9e6bc8 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -561,7 +561,7 @@ static noinline int create_subvol(struct inode *dir, | |||
561 | new_root = btrfs_read_fs_root_no_name(root->fs_info, &key); | 561 | new_root = btrfs_read_fs_root_no_name(root->fs_info, &key); |
562 | if (IS_ERR(new_root)) { | 562 | if (IS_ERR(new_root)) { |
563 | ret = PTR_ERR(new_root); | 563 | ret = PTR_ERR(new_root); |
564 | btrfs_abort_transaction(trans, root, ret); | 564 | btrfs_abort_transaction(trans, ret); |
565 | goto fail; | 565 | goto fail; |
566 | } | 566 | } |
567 | 567 | ||
@@ -570,7 +570,7 @@ static noinline int create_subvol(struct inode *dir, | |||
570 | ret = btrfs_create_subvol_root(trans, new_root, root, new_dirid); | 570 | ret = btrfs_create_subvol_root(trans, new_root, root, new_dirid); |
571 | if (ret) { | 571 | if (ret) { |
572 | /* We potentially lose an unused inode item here */ | 572 | /* We potentially lose an unused inode item here */ |
573 | btrfs_abort_transaction(trans, root, ret); | 573 | btrfs_abort_transaction(trans, ret); |
574 | goto fail; | 574 | goto fail; |
575 | } | 575 | } |
576 | 576 | ||
@@ -583,7 +583,7 @@ static noinline int create_subvol(struct inode *dir, | |||
583 | */ | 583 | */ |
584 | ret = btrfs_set_inode_index(dir, &index); | 584 | ret = btrfs_set_inode_index(dir, &index); |
585 | if (ret) { | 585 | if (ret) { |
586 | btrfs_abort_transaction(trans, root, ret); | 586 | btrfs_abort_transaction(trans, ret); |
587 | goto fail; | 587 | goto fail; |
588 | } | 588 | } |
589 | 589 | ||
@@ -591,7 +591,7 @@ static noinline int create_subvol(struct inode *dir, | |||
591 | name, namelen, dir, &key, | 591 | name, namelen, dir, &key, |
592 | BTRFS_FT_DIR, index); | 592 | BTRFS_FT_DIR, index); |
593 | if (ret) { | 593 | if (ret) { |
594 | btrfs_abort_transaction(trans, root, ret); | 594 | btrfs_abort_transaction(trans, ret); |
595 | goto fail; | 595 | goto fail; |
596 | } | 596 | } |
597 | 597 | ||
@@ -608,7 +608,7 @@ static noinline int create_subvol(struct inode *dir, | |||
608 | root_item->uuid, BTRFS_UUID_KEY_SUBVOL, | 608 | root_item->uuid, BTRFS_UUID_KEY_SUBVOL, |
609 | objectid); | 609 | objectid); |
610 | if (ret) | 610 | if (ret) |
611 | btrfs_abort_transaction(trans, root, ret); | 611 | btrfs_abort_transaction(trans, ret); |
612 | 612 | ||
613 | fail: | 613 | fail: |
614 | kfree(root_item); | 614 | kfree(root_item); |
@@ -1948,8 +1948,7 @@ static noinline int key_in_sk(struct btrfs_key *key, | |||
1948 | return 1; | 1948 | return 1; |
1949 | } | 1949 | } |
1950 | 1950 | ||
1951 | static noinline int copy_to_sk(struct btrfs_root *root, | 1951 | static noinline int copy_to_sk(struct btrfs_path *path, |
1952 | struct btrfs_path *path, | ||
1953 | struct btrfs_key *key, | 1952 | struct btrfs_key *key, |
1954 | struct btrfs_ioctl_search_key *sk, | 1953 | struct btrfs_ioctl_search_key *sk, |
1955 | size_t *buf_size, | 1954 | size_t *buf_size, |
@@ -2120,7 +2119,7 @@ static noinline int search_ioctl(struct inode *inode, | |||
2120 | ret = 0; | 2119 | ret = 0; |
2121 | goto err; | 2120 | goto err; |
2122 | } | 2121 | } |
2123 | ret = copy_to_sk(root, path, &key, sk, buf_size, ubuf, | 2122 | ret = copy_to_sk(path, &key, sk, buf_size, ubuf, |
2124 | &sk_offset, &num_found); | 2123 | &sk_offset, &num_found); |
2125 | btrfs_release_path(path); | 2124 | btrfs_release_path(path); |
2126 | if (ret) | 2125 | if (ret) |
@@ -2406,7 +2405,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, | |||
2406 | * rmdir(2). | 2405 | * rmdir(2). |
2407 | */ | 2406 | */ |
2408 | err = -EPERM; | 2407 | err = -EPERM; |
2409 | if (!btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED)) | 2408 | if (!btrfs_test_opt(root->fs_info, USER_SUBVOL_RM_ALLOWED)) |
2410 | goto out_dput; | 2409 | goto out_dput; |
2411 | 2410 | ||
2412 | /* | 2411 | /* |
@@ -2489,7 +2488,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, | |||
2489 | dentry->d_name.len); | 2488 | dentry->d_name.len); |
2490 | if (ret) { | 2489 | if (ret) { |
2491 | err = ret; | 2490 | err = ret; |
2492 | btrfs_abort_transaction(trans, root, ret); | 2491 | btrfs_abort_transaction(trans, ret); |
2493 | goto out_end_trans; | 2492 | goto out_end_trans; |
2494 | } | 2493 | } |
2495 | 2494 | ||
@@ -2505,7 +2504,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, | |||
2505 | root->fs_info->tree_root, | 2504 | root->fs_info->tree_root, |
2506 | dest->root_key.objectid); | 2505 | dest->root_key.objectid); |
2507 | if (ret) { | 2506 | if (ret) { |
2508 | btrfs_abort_transaction(trans, root, ret); | 2507 | btrfs_abort_transaction(trans, ret); |
2509 | err = ret; | 2508 | err = ret; |
2510 | goto out_end_trans; | 2509 | goto out_end_trans; |
2511 | } | 2510 | } |
@@ -2515,7 +2514,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, | |||
2515 | dest->root_item.uuid, BTRFS_UUID_KEY_SUBVOL, | 2514 | dest->root_item.uuid, BTRFS_UUID_KEY_SUBVOL, |
2516 | dest->root_key.objectid); | 2515 | dest->root_key.objectid); |
2517 | if (ret && ret != -ENOENT) { | 2516 | if (ret && ret != -ENOENT) { |
2518 | btrfs_abort_transaction(trans, root, ret); | 2517 | btrfs_abort_transaction(trans, ret); |
2519 | err = ret; | 2518 | err = ret; |
2520 | goto out_end_trans; | 2519 | goto out_end_trans; |
2521 | } | 2520 | } |
@@ -2525,7 +2524,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, | |||
2525 | BTRFS_UUID_KEY_RECEIVED_SUBVOL, | 2524 | BTRFS_UUID_KEY_RECEIVED_SUBVOL, |
2526 | dest->root_key.objectid); | 2525 | dest->root_key.objectid); |
2527 | if (ret && ret != -ENOENT) { | 2526 | if (ret && ret != -ENOENT) { |
2528 | btrfs_abort_transaction(trans, root, ret); | 2527 | btrfs_abort_transaction(trans, ret); |
2529 | err = ret; | 2528 | err = ret; |
2530 | goto out_end_trans; | 2529 | goto out_end_trans; |
2531 | } | 2530 | } |
@@ -3292,7 +3291,7 @@ static int clone_finish_inode_update(struct btrfs_trans_handle *trans, | |||
3292 | 3291 | ||
3293 | ret = btrfs_update_inode(trans, root, inode); | 3292 | ret = btrfs_update_inode(trans, root, inode); |
3294 | if (ret) { | 3293 | if (ret) { |
3295 | btrfs_abort_transaction(trans, root, ret); | 3294 | btrfs_abort_transaction(trans, ret); |
3296 | btrfs_end_transaction(trans, root); | 3295 | btrfs_end_transaction(trans, root); |
3297 | goto out; | 3296 | goto out; |
3298 | } | 3297 | } |
@@ -3694,7 +3693,7 @@ process_slot: | |||
3694 | if (ret) { | 3693 | if (ret) { |
3695 | if (ret != -EOPNOTSUPP) | 3694 | if (ret != -EOPNOTSUPP) |
3696 | btrfs_abort_transaction(trans, | 3695 | btrfs_abort_transaction(trans, |
3697 | root, ret); | 3696 | ret); |
3698 | btrfs_end_transaction(trans, root); | 3697 | btrfs_end_transaction(trans, root); |
3699 | goto out; | 3698 | goto out; |
3700 | } | 3699 | } |
@@ -3702,8 +3701,7 @@ process_slot: | |||
3702 | ret = btrfs_insert_empty_item(trans, root, path, | 3701 | ret = btrfs_insert_empty_item(trans, root, path, |
3703 | &new_key, size); | 3702 | &new_key, size); |
3704 | if (ret) { | 3703 | if (ret) { |
3705 | btrfs_abort_transaction(trans, root, | 3704 | btrfs_abort_transaction(trans, ret); |
3706 | ret); | ||
3707 | btrfs_end_transaction(trans, root); | 3705 | btrfs_end_transaction(trans, root); |
3708 | goto out; | 3706 | goto out; |
3709 | } | 3707 | } |
@@ -3735,7 +3733,6 @@ process_slot: | |||
3735 | new_key.offset - datao); | 3733 | new_key.offset - datao); |
3736 | if (ret) { | 3734 | if (ret) { |
3737 | btrfs_abort_transaction(trans, | 3735 | btrfs_abort_transaction(trans, |
3738 | root, | ||
3739 | ret); | 3736 | ret); |
3740 | btrfs_end_transaction(trans, | 3737 | btrfs_end_transaction(trans, |
3741 | root); | 3738 | root); |
@@ -3772,7 +3769,6 @@ process_slot: | |||
3772 | if (ret) { | 3769 | if (ret) { |
3773 | if (ret != -EOPNOTSUPP) | 3770 | if (ret != -EOPNOTSUPP) |
3774 | btrfs_abort_transaction(trans, | 3771 | btrfs_abort_transaction(trans, |
3775 | root, | ||
3776 | ret); | 3772 | ret); |
3777 | btrfs_end_transaction(trans, root); | 3773 | btrfs_end_transaction(trans, root); |
3778 | goto out; | 3774 | goto out; |
@@ -3828,7 +3824,7 @@ process_slot: | |||
3828 | last_dest_end, destoff + len, 1); | 3824 | last_dest_end, destoff + len, 1); |
3829 | if (ret) { | 3825 | if (ret) { |
3830 | if (ret != -EOPNOTSUPP) | 3826 | if (ret != -EOPNOTSUPP) |
3831 | btrfs_abort_transaction(trans, root, ret); | 3827 | btrfs_abort_transaction(trans, ret); |
3832 | btrfs_end_transaction(trans, root); | 3828 | btrfs_end_transaction(trans, root); |
3833 | goto out; | 3829 | goto out; |
3834 | } | 3830 | } |
@@ -5164,13 +5160,13 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file, | |||
5164 | BTRFS_UUID_KEY_RECEIVED_SUBVOL, | 5160 | BTRFS_UUID_KEY_RECEIVED_SUBVOL, |
5165 | root->root_key.objectid); | 5161 | root->root_key.objectid); |
5166 | if (ret < 0 && ret != -EEXIST) { | 5162 | if (ret < 0 && ret != -EEXIST) { |
5167 | btrfs_abort_transaction(trans, root, ret); | 5163 | btrfs_abort_transaction(trans, ret); |
5168 | goto out; | 5164 | goto out; |
5169 | } | 5165 | } |
5170 | } | 5166 | } |
5171 | ret = btrfs_commit_transaction(trans, root); | 5167 | ret = btrfs_commit_transaction(trans, root); |
5172 | if (ret < 0) { | 5168 | if (ret < 0) { |
5173 | btrfs_abort_transaction(trans, root, ret); | 5169 | btrfs_abort_transaction(trans, ret); |
5174 | goto out; | 5170 | goto out; |
5175 | } | 5171 | } |
5176 | 5172 | ||
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index aca8264f4a49..3b78d38173b3 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c | |||
@@ -1122,7 +1122,7 @@ int __init ordered_data_init(void) | |||
1122 | { | 1122 | { |
1123 | btrfs_ordered_extent_cache = kmem_cache_create("btrfs_ordered_extent", | 1123 | btrfs_ordered_extent_cache = kmem_cache_create("btrfs_ordered_extent", |
1124 | sizeof(struct btrfs_ordered_extent), 0, | 1124 | sizeof(struct btrfs_ordered_extent), 0, |
1125 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, | 1125 | SLAB_MEM_SPREAD, |
1126 | NULL); | 1126 | NULL); |
1127 | if (!btrfs_ordered_extent_cache) | 1127 | if (!btrfs_ordered_extent_cache) |
1128 | return -ENOMEM; | 1128 | return -ENOMEM; |
diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c index 36992128c746..cf0b444ac4f3 100644 --- a/fs/btrfs/props.c +++ b/fs/btrfs/props.c | |||
@@ -350,6 +350,7 @@ int btrfs_subvol_inherit_props(struct btrfs_trans_handle *trans, | |||
350 | struct btrfs_root *root, | 350 | struct btrfs_root *root, |
351 | struct btrfs_root *parent_root) | 351 | struct btrfs_root *parent_root) |
352 | { | 352 | { |
353 | struct super_block *sb = root->fs_info->sb; | ||
353 | struct btrfs_key key; | 354 | struct btrfs_key key; |
354 | struct inode *parent_inode, *child_inode; | 355 | struct inode *parent_inode, *child_inode; |
355 | int ret; | 356 | int ret; |
@@ -358,12 +359,11 @@ int btrfs_subvol_inherit_props(struct btrfs_trans_handle *trans, | |||
358 | key.type = BTRFS_INODE_ITEM_KEY; | 359 | key.type = BTRFS_INODE_ITEM_KEY; |
359 | key.offset = 0; | 360 | key.offset = 0; |
360 | 361 | ||
361 | parent_inode = btrfs_iget(parent_root->fs_info->sb, &key, | 362 | parent_inode = btrfs_iget(sb, &key, parent_root, NULL); |
362 | parent_root, NULL); | ||
363 | if (IS_ERR(parent_inode)) | 363 | if (IS_ERR(parent_inode)) |
364 | return PTR_ERR(parent_inode); | 364 | return PTR_ERR(parent_inode); |
365 | 365 | ||
366 | child_inode = btrfs_iget(root->fs_info->sb, &key, root, NULL); | 366 | child_inode = btrfs_iget(sb, &key, root, NULL); |
367 | if (IS_ERR(child_inode)) { | 367 | if (IS_ERR(child_inode)) { |
368 | iput(parent_inode); | 368 | iput(parent_inode); |
369 | return PTR_ERR(child_inode); | 369 | return PTR_ERR(child_inode); |
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 9d4c05b14f6e..93ee1c18ef9d 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c | |||
@@ -571,7 +571,7 @@ static int add_qgroup_item(struct btrfs_trans_handle *trans, | |||
571 | struct extent_buffer *leaf; | 571 | struct extent_buffer *leaf; |
572 | struct btrfs_key key; | 572 | struct btrfs_key key; |
573 | 573 | ||
574 | if (btrfs_test_is_dummy_root(quota_root)) | 574 | if (btrfs_is_testing(quota_root->fs_info)) |
575 | return 0; | 575 | return 0; |
576 | 576 | ||
577 | path = btrfs_alloc_path(); | 577 | path = btrfs_alloc_path(); |
@@ -728,7 +728,7 @@ static int update_qgroup_info_item(struct btrfs_trans_handle *trans, | |||
728 | int ret; | 728 | int ret; |
729 | int slot; | 729 | int slot; |
730 | 730 | ||
731 | if (btrfs_test_is_dummy_root(root)) | 731 | if (btrfs_is_testing(root->fs_info)) |
732 | return 0; | 732 | return 0; |
733 | 733 | ||
734 | key.objectid = 0; | 734 | key.objectid = 0; |
@@ -1453,9 +1453,10 @@ int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, | |||
1453 | return ret; | 1453 | return ret; |
1454 | } | 1454 | } |
1455 | 1455 | ||
1456 | struct btrfs_qgroup_extent_record | 1456 | struct btrfs_qgroup_extent_record * |
1457 | *btrfs_qgroup_insert_dirty_extent(struct btrfs_delayed_ref_root *delayed_refs, | 1457 | btrfs_qgroup_insert_dirty_extent(struct btrfs_fs_info *fs_info, |
1458 | struct btrfs_qgroup_extent_record *record) | 1458 | struct btrfs_delayed_ref_root *delayed_refs, |
1459 | struct btrfs_qgroup_extent_record *record) | ||
1459 | { | 1460 | { |
1460 | struct rb_node **p = &delayed_refs->dirty_extent_root.rb_node; | 1461 | struct rb_node **p = &delayed_refs->dirty_extent_root.rb_node; |
1461 | struct rb_node *parent_node = NULL; | 1462 | struct rb_node *parent_node = NULL; |
@@ -1463,7 +1464,7 @@ struct btrfs_qgroup_extent_record | |||
1463 | u64 bytenr = record->bytenr; | 1464 | u64 bytenr = record->bytenr; |
1464 | 1465 | ||
1465 | assert_spin_locked(&delayed_refs->lock); | 1466 | assert_spin_locked(&delayed_refs->lock); |
1466 | trace_btrfs_qgroup_insert_dirty_extent(record); | 1467 | trace_btrfs_qgroup_insert_dirty_extent(fs_info, record); |
1467 | 1468 | ||
1468 | while (*p) { | 1469 | while (*p) { |
1469 | parent_node = *p; | 1470 | parent_node = *p; |
@@ -1595,8 +1596,8 @@ static int qgroup_update_counters(struct btrfs_fs_info *fs_info, | |||
1595 | cur_old_count = btrfs_qgroup_get_old_refcnt(qg, seq); | 1596 | cur_old_count = btrfs_qgroup_get_old_refcnt(qg, seq); |
1596 | cur_new_count = btrfs_qgroup_get_new_refcnt(qg, seq); | 1597 | cur_new_count = btrfs_qgroup_get_new_refcnt(qg, seq); |
1597 | 1598 | ||
1598 | trace_qgroup_update_counters(qg->qgroupid, cur_old_count, | 1599 | trace_qgroup_update_counters(fs_info, qg->qgroupid, |
1599 | cur_new_count); | 1600 | cur_old_count, cur_new_count); |
1600 | 1601 | ||
1601 | /* Rfer update part */ | 1602 | /* Rfer update part */ |
1602 | if (cur_old_count == 0 && cur_new_count > 0) { | 1603 | if (cur_old_count == 0 && cur_new_count > 0) { |
@@ -1687,8 +1688,8 @@ btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, | |||
1687 | goto out_free; | 1688 | goto out_free; |
1688 | BUG_ON(!fs_info->quota_root); | 1689 | BUG_ON(!fs_info->quota_root); |
1689 | 1690 | ||
1690 | trace_btrfs_qgroup_account_extent(bytenr, num_bytes, nr_old_roots, | 1691 | trace_btrfs_qgroup_account_extent(fs_info, bytenr, num_bytes, |
1691 | nr_new_roots); | 1692 | nr_old_roots, nr_new_roots); |
1692 | 1693 | ||
1693 | qgroups = ulist_alloc(GFP_NOFS); | 1694 | qgroups = ulist_alloc(GFP_NOFS); |
1694 | if (!qgroups) { | 1695 | if (!qgroups) { |
@@ -1759,7 +1760,7 @@ int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans, | |||
1759 | record = rb_entry(node, struct btrfs_qgroup_extent_record, | 1760 | record = rb_entry(node, struct btrfs_qgroup_extent_record, |
1760 | node); | 1761 | node); |
1761 | 1762 | ||
1762 | trace_btrfs_qgroup_account_extents(record); | 1763 | trace_btrfs_qgroup_account_extents(fs_info, record); |
1763 | 1764 | ||
1764 | if (!ret) { | 1765 | if (!ret) { |
1765 | /* | 1766 | /* |
@@ -2195,7 +2196,7 @@ void assert_qgroups_uptodate(struct btrfs_trans_handle *trans) | |||
2195 | { | 2196 | { |
2196 | if (list_empty(&trans->qgroup_ref_list) && !trans->delayed_ref_elem.seq) | 2197 | if (list_empty(&trans->qgroup_ref_list) && !trans->delayed_ref_elem.seq) |
2197 | return; | 2198 | return; |
2198 | btrfs_err(trans->root->fs_info, | 2199 | btrfs_err(trans->fs_info, |
2199 | "qgroups not uptodate in trans handle %p: list is%s empty, " | 2200 | "qgroups not uptodate in trans handle %p: list is%s empty, " |
2200 | "seq is %#x.%x", | 2201 | "seq is %#x.%x", |
2201 | trans, list_empty(&trans->qgroup_ref_list) ? "" : " not", | 2202 | trans, list_empty(&trans->qgroup_ref_list) ? "" : " not", |
diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h index ecb2c143ef75..710887c06aaf 100644 --- a/fs/btrfs/qgroup.h +++ b/fs/btrfs/qgroup.h | |||
@@ -63,9 +63,10 @@ void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info); | |||
63 | struct btrfs_delayed_extent_op; | 63 | struct btrfs_delayed_extent_op; |
64 | int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, | 64 | int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, |
65 | struct btrfs_fs_info *fs_info); | 65 | struct btrfs_fs_info *fs_info); |
66 | struct btrfs_qgroup_extent_record | 66 | struct btrfs_qgroup_extent_record * |
67 | *btrfs_qgroup_insert_dirty_extent(struct btrfs_delayed_ref_root *delayed_refs, | 67 | btrfs_qgroup_insert_dirty_extent(struct btrfs_fs_info *fs_info, |
68 | struct btrfs_qgroup_extent_record *record); | 68 | struct btrfs_delayed_ref_root *delayed_refs, |
69 | struct btrfs_qgroup_extent_record *record); | ||
69 | int | 70 | int |
70 | btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, | 71 | btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, |
71 | struct btrfs_fs_info *fs_info, | 72 | struct btrfs_fs_info *fs_info, |
@@ -88,7 +89,7 @@ static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info, | |||
88 | u64 ref_root, u64 num_bytes) | 89 | u64 ref_root, u64 num_bytes) |
89 | { | 90 | { |
90 | btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes); | 91 | btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes); |
91 | trace_btrfs_qgroup_free_delayed_ref(ref_root, num_bytes); | 92 | trace_btrfs_qgroup_free_delayed_ref(fs_info, ref_root, num_bytes); |
92 | } | 93 | } |
93 | void assert_qgroups_uptodate(struct btrfs_trans_handle *trans); | 94 | void assert_qgroups_uptodate(struct btrfs_trans_handle *trans); |
94 | 95 | ||
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index fc067b07e31f..b26a5aea41b4 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c | |||
@@ -235,12 +235,12 @@ static void backref_cache_cleanup(struct backref_cache *cache) | |||
235 | cache->last_trans = 0; | 235 | cache->last_trans = 0; |
236 | 236 | ||
237 | for (i = 0; i < BTRFS_MAX_LEVEL; i++) | 237 | for (i = 0; i < BTRFS_MAX_LEVEL; i++) |
238 | BUG_ON(!list_empty(&cache->pending[i])); | 238 | ASSERT(list_empty(&cache->pending[i])); |
239 | BUG_ON(!list_empty(&cache->changed)); | 239 | ASSERT(list_empty(&cache->changed)); |
240 | BUG_ON(!list_empty(&cache->detached)); | 240 | ASSERT(list_empty(&cache->detached)); |
241 | BUG_ON(!RB_EMPTY_ROOT(&cache->rb_root)); | 241 | ASSERT(RB_EMPTY_ROOT(&cache->rb_root)); |
242 | BUG_ON(cache->nr_nodes); | 242 | ASSERT(!cache->nr_nodes); |
243 | BUG_ON(cache->nr_edges); | 243 | ASSERT(!cache->nr_edges); |
244 | } | 244 | } |
245 | 245 | ||
246 | static struct backref_node *alloc_backref_node(struct backref_cache *cache) | 246 | static struct backref_node *alloc_backref_node(struct backref_cache *cache) |
@@ -1171,8 +1171,12 @@ out: | |||
1171 | lower = list_entry(useless.next, | 1171 | lower = list_entry(useless.next, |
1172 | struct backref_node, list); | 1172 | struct backref_node, list); |
1173 | list_del_init(&lower->list); | 1173 | list_del_init(&lower->list); |
1174 | if (lower == node) | ||
1175 | node = NULL; | ||
1174 | free_backref_node(cache, lower); | 1176 | free_backref_node(cache, lower); |
1175 | } | 1177 | } |
1178 | |||
1179 | free_backref_node(cache, node); | ||
1176 | return ERR_PTR(err); | 1180 | return ERR_PTR(err); |
1177 | } | 1181 | } |
1178 | ASSERT(!node || !node->detached); | 1182 | ASSERT(!node || !node->detached); |
@@ -1719,7 +1723,7 @@ int replace_file_extents(struct btrfs_trans_handle *trans, | |||
1719 | btrfs_header_owner(leaf), | 1723 | btrfs_header_owner(leaf), |
1720 | key.objectid, key.offset); | 1724 | key.objectid, key.offset); |
1721 | if (ret) { | 1725 | if (ret) { |
1722 | btrfs_abort_transaction(trans, root, ret); | 1726 | btrfs_abort_transaction(trans, ret); |
1723 | break; | 1727 | break; |
1724 | } | 1728 | } |
1725 | 1729 | ||
@@ -1727,7 +1731,7 @@ int replace_file_extents(struct btrfs_trans_handle *trans, | |||
1727 | parent, btrfs_header_owner(leaf), | 1731 | parent, btrfs_header_owner(leaf), |
1728 | key.objectid, key.offset); | 1732 | key.objectid, key.offset); |
1729 | if (ret) { | 1733 | if (ret) { |
1730 | btrfs_abort_transaction(trans, root, ret); | 1734 | btrfs_abort_transaction(trans, ret); |
1731 | break; | 1735 | break; |
1732 | } | 1736 | } |
1733 | } | 1737 | } |
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c index f1c30861d062..7fd7e1830cfe 100644 --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c | |||
@@ -150,7 +150,7 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root | |||
150 | 150 | ||
151 | ret = btrfs_search_slot(trans, root, key, path, 0, 1); | 151 | ret = btrfs_search_slot(trans, root, key, path, 0, 1); |
152 | if (ret < 0) { | 152 | if (ret < 0) { |
153 | btrfs_abort_transaction(trans, root, ret); | 153 | btrfs_abort_transaction(trans, ret); |
154 | goto out; | 154 | goto out; |
155 | } | 155 | } |
156 | 156 | ||
@@ -176,20 +176,20 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root | |||
176 | ret = btrfs_search_slot(trans, root, key, path, | 176 | ret = btrfs_search_slot(trans, root, key, path, |
177 | -1, 1); | 177 | -1, 1); |
178 | if (ret < 0) { | 178 | if (ret < 0) { |
179 | btrfs_abort_transaction(trans, root, ret); | 179 | btrfs_abort_transaction(trans, ret); |
180 | goto out; | 180 | goto out; |
181 | } | 181 | } |
182 | 182 | ||
183 | ret = btrfs_del_item(trans, root, path); | 183 | ret = btrfs_del_item(trans, root, path); |
184 | if (ret < 0) { | 184 | if (ret < 0) { |
185 | btrfs_abort_transaction(trans, root, ret); | 185 | btrfs_abort_transaction(trans, ret); |
186 | goto out; | 186 | goto out; |
187 | } | 187 | } |
188 | btrfs_release_path(path); | 188 | btrfs_release_path(path); |
189 | ret = btrfs_insert_empty_item(trans, root, path, | 189 | ret = btrfs_insert_empty_item(trans, root, path, |
190 | key, sizeof(*item)); | 190 | key, sizeof(*item)); |
191 | if (ret < 0) { | 191 | if (ret < 0) { |
192 | btrfs_abort_transaction(trans, root, ret); | 192 | btrfs_abort_transaction(trans, ret); |
193 | goto out; | 193 | goto out; |
194 | } | 194 | } |
195 | l = path->nodes[0]; | 195 | l = path->nodes[0]; |
@@ -448,7 +448,7 @@ again: | |||
448 | ret = btrfs_insert_empty_item(trans, tree_root, path, &key, | 448 | ret = btrfs_insert_empty_item(trans, tree_root, path, &key, |
449 | sizeof(*ref) + name_len); | 449 | sizeof(*ref) + name_len); |
450 | if (ret) { | 450 | if (ret) { |
451 | btrfs_abort_transaction(trans, tree_root, ret); | 451 | btrfs_abort_transaction(trans, ret); |
452 | btrfs_free_path(path); | 452 | btrfs_free_path(path); |
453 | return ret; | 453 | return ret; |
454 | } | 454 | } |
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 70427ef66b04..68c8a09ae7e5 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
@@ -3781,27 +3781,27 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info, | |||
3781 | if (fs_info->scrub_workers_refcnt == 0) { | 3781 | if (fs_info->scrub_workers_refcnt == 0) { |
3782 | if (is_dev_replace) | 3782 | if (is_dev_replace) |
3783 | fs_info->scrub_workers = | 3783 | fs_info->scrub_workers = |
3784 | btrfs_alloc_workqueue("scrub", flags, | 3784 | btrfs_alloc_workqueue(fs_info, "scrub", flags, |
3785 | 1, 4); | 3785 | 1, 4); |
3786 | else | 3786 | else |
3787 | fs_info->scrub_workers = | 3787 | fs_info->scrub_workers = |
3788 | btrfs_alloc_workqueue("scrub", flags, | 3788 | btrfs_alloc_workqueue(fs_info, "scrub", flags, |
3789 | max_active, 4); | 3789 | max_active, 4); |
3790 | if (!fs_info->scrub_workers) | 3790 | if (!fs_info->scrub_workers) |
3791 | goto fail_scrub_workers; | 3791 | goto fail_scrub_workers; |
3792 | 3792 | ||
3793 | fs_info->scrub_wr_completion_workers = | 3793 | fs_info->scrub_wr_completion_workers = |
3794 | btrfs_alloc_workqueue("scrubwrc", flags, | 3794 | btrfs_alloc_workqueue(fs_info, "scrubwrc", flags, |
3795 | max_active, 2); | 3795 | max_active, 2); |
3796 | if (!fs_info->scrub_wr_completion_workers) | 3796 | if (!fs_info->scrub_wr_completion_workers) |
3797 | goto fail_scrub_wr_completion_workers; | 3797 | goto fail_scrub_wr_completion_workers; |
3798 | 3798 | ||
3799 | fs_info->scrub_nocow_workers = | 3799 | fs_info->scrub_nocow_workers = |
3800 | btrfs_alloc_workqueue("scrubnc", flags, 1, 0); | 3800 | btrfs_alloc_workqueue(fs_info, "scrubnc", flags, 1, 0); |
3801 | if (!fs_info->scrub_nocow_workers) | 3801 | if (!fs_info->scrub_nocow_workers) |
3802 | goto fail_scrub_nocow_workers; | 3802 | goto fail_scrub_nocow_workers; |
3803 | fs_info->scrub_parity_workers = | 3803 | fs_info->scrub_parity_workers = |
3804 | btrfs_alloc_workqueue("scrubparity", flags, | 3804 | btrfs_alloc_workqueue(fs_info, "scrubparity", flags, |
3805 | max_active, 2); | 3805 | max_active, 2); |
3806 | if (!fs_info->scrub_parity_workers) | 3806 | if (!fs_info->scrub_parity_workers) |
3807 | goto fail_scrub_parity_workers; | 3807 | goto fail_scrub_parity_workers; |
@@ -3856,7 +3856,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, | |||
3856 | 3856 | ||
3857 | if (fs_info->chunk_root->sectorsize != PAGE_SIZE) { | 3857 | if (fs_info->chunk_root->sectorsize != PAGE_SIZE) { |
3858 | /* not supported for data w/o checksums */ | 3858 | /* not supported for data w/o checksums */ |
3859 | btrfs_err(fs_info, | 3859 | btrfs_err_rl(fs_info, |
3860 | "scrub: size assumption sectorsize != PAGE_SIZE " | 3860 | "scrub: size assumption sectorsize != PAGE_SIZE " |
3861 | "(%d != %lu) fails", | 3861 | "(%d != %lu) fails", |
3862 | fs_info->chunk_root->sectorsize, PAGE_SIZE); | 3862 | fs_info->chunk_root->sectorsize, PAGE_SIZE); |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 60e7179ed4b7..864ce334f696 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -184,6 +184,22 @@ static const char * const logtypes[] = { | |||
184 | "debug", | 184 | "debug", |
185 | }; | 185 | }; |
186 | 186 | ||
187 | |||
188 | /* | ||
189 | * Use one ratelimit state per log level so that a flood of less important | ||
190 | * messages doesn't cause more important ones to be dropped. | ||
191 | */ | ||
192 | static struct ratelimit_state printk_limits[] = { | ||
193 | RATELIMIT_STATE_INIT(printk_limits[0], DEFAULT_RATELIMIT_INTERVAL, 100), | ||
194 | RATELIMIT_STATE_INIT(printk_limits[1], DEFAULT_RATELIMIT_INTERVAL, 100), | ||
195 | RATELIMIT_STATE_INIT(printk_limits[2], DEFAULT_RATELIMIT_INTERVAL, 100), | ||
196 | RATELIMIT_STATE_INIT(printk_limits[3], DEFAULT_RATELIMIT_INTERVAL, 100), | ||
197 | RATELIMIT_STATE_INIT(printk_limits[4], DEFAULT_RATELIMIT_INTERVAL, 100), | ||
198 | RATELIMIT_STATE_INIT(printk_limits[5], DEFAULT_RATELIMIT_INTERVAL, 100), | ||
199 | RATELIMIT_STATE_INIT(printk_limits[6], DEFAULT_RATELIMIT_INTERVAL, 100), | ||
200 | RATELIMIT_STATE_INIT(printk_limits[7], DEFAULT_RATELIMIT_INTERVAL, 100), | ||
201 | }; | ||
202 | |||
187 | void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) | 203 | void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) |
188 | { | 204 | { |
189 | struct super_block *sb = fs_info->sb; | 205 | struct super_block *sb = fs_info->sb; |
@@ -192,6 +208,7 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) | |||
192 | va_list args; | 208 | va_list args; |
193 | const char *type = logtypes[4]; | 209 | const char *type = logtypes[4]; |
194 | int kern_level; | 210 | int kern_level; |
211 | struct ratelimit_state *ratelimit; | ||
195 | 212 | ||
196 | va_start(args, fmt); | 213 | va_start(args, fmt); |
197 | 214 | ||
@@ -202,13 +219,18 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) | |||
202 | lvl[size] = '\0'; | 219 | lvl[size] = '\0'; |
203 | fmt += size; | 220 | fmt += size; |
204 | type = logtypes[kern_level - '0']; | 221 | type = logtypes[kern_level - '0']; |
205 | } else | 222 | ratelimit = &printk_limits[kern_level - '0']; |
223 | } else { | ||
206 | *lvl = '\0'; | 224 | *lvl = '\0'; |
225 | /* Default to debug output */ | ||
226 | ratelimit = &printk_limits[7]; | ||
227 | } | ||
207 | 228 | ||
208 | vaf.fmt = fmt; | 229 | vaf.fmt = fmt; |
209 | vaf.va = &args; | 230 | vaf.va = &args; |
210 | 231 | ||
211 | printk("%sBTRFS %s (device %s): %pV\n", lvl, type, sb->s_id, &vaf); | 232 | if (__ratelimit(ratelimit)) |
233 | printk("%sBTRFS %s (device %s): %pV\n", lvl, type, sb->s_id, &vaf); | ||
212 | 234 | ||
213 | va_end(args); | 235 | va_end(args); |
214 | } | 236 | } |
@@ -229,9 +251,11 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) | |||
229 | */ | 251 | */ |
230 | __cold | 252 | __cold |
231 | void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, | 253 | void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, |
232 | struct btrfs_root *root, const char *function, | 254 | const char *function, |
233 | unsigned int line, int errno) | 255 | unsigned int line, int errno) |
234 | { | 256 | { |
257 | struct btrfs_fs_info *fs_info = trans->fs_info; | ||
258 | |||
235 | trans->aborted = errno; | 259 | trans->aborted = errno; |
236 | /* Nothing used. The other threads that have joined this | 260 | /* Nothing used. The other threads that have joined this |
237 | * transaction may be able to continue. */ | 261 | * transaction may be able to continue. */ |
@@ -239,16 +263,16 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, | |||
239 | const char *errstr; | 263 | const char *errstr; |
240 | 264 | ||
241 | errstr = btrfs_decode_error(errno); | 265 | errstr = btrfs_decode_error(errno); |
242 | btrfs_warn(root->fs_info, | 266 | btrfs_warn(fs_info, |
243 | "%s:%d: Aborting unused transaction(%s).", | 267 | "%s:%d: Aborting unused transaction(%s).", |
244 | function, line, errstr); | 268 | function, line, errstr); |
245 | return; | 269 | return; |
246 | } | 270 | } |
247 | ACCESS_ONCE(trans->transaction->aborted) = errno; | 271 | ACCESS_ONCE(trans->transaction->aborted) = errno; |
248 | /* Wake up anybody who may be waiting on this transaction */ | 272 | /* Wake up anybody who may be waiting on this transaction */ |
249 | wake_up(&root->fs_info->transaction_wait); | 273 | wake_up(&fs_info->transaction_wait); |
250 | wake_up(&root->fs_info->transaction_blocked_wait); | 274 | wake_up(&fs_info->transaction_blocked_wait); |
251 | __btrfs_handle_fs_error(root->fs_info, function, line, errno, NULL); | 275 | __btrfs_handle_fs_error(fs_info, function, line, errno, NULL); |
252 | } | 276 | } |
253 | /* | 277 | /* |
254 | * __btrfs_panic decodes unexpected, fatal errors from the caller, | 278 | * __btrfs_panic decodes unexpected, fatal errors from the caller, |
@@ -432,12 +456,12 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
432 | */ | 456 | */ |
433 | break; | 457 | break; |
434 | case Opt_nodatasum: | 458 | case Opt_nodatasum: |
435 | btrfs_set_and_info(root, NODATASUM, | 459 | btrfs_set_and_info(info, NODATASUM, |
436 | "setting nodatasum"); | 460 | "setting nodatasum"); |
437 | break; | 461 | break; |
438 | case Opt_datasum: | 462 | case Opt_datasum: |
439 | if (btrfs_test_opt(root, NODATASUM)) { | 463 | if (btrfs_test_opt(info, NODATASUM)) { |
440 | if (btrfs_test_opt(root, NODATACOW)) | 464 | if (btrfs_test_opt(info, NODATACOW)) |
441 | btrfs_info(root->fs_info, "setting datasum, datacow enabled"); | 465 | btrfs_info(root->fs_info, "setting datasum, datacow enabled"); |
442 | else | 466 | else |
443 | btrfs_info(root->fs_info, "setting datasum"); | 467 | btrfs_info(root->fs_info, "setting datasum"); |
@@ -446,9 +470,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
446 | btrfs_clear_opt(info->mount_opt, NODATASUM); | 470 | btrfs_clear_opt(info->mount_opt, NODATASUM); |
447 | break; | 471 | break; |
448 | case Opt_nodatacow: | 472 | case Opt_nodatacow: |
449 | if (!btrfs_test_opt(root, NODATACOW)) { | 473 | if (!btrfs_test_opt(info, NODATACOW)) { |
450 | if (!btrfs_test_opt(root, COMPRESS) || | 474 | if (!btrfs_test_opt(info, COMPRESS) || |
451 | !btrfs_test_opt(root, FORCE_COMPRESS)) { | 475 | !btrfs_test_opt(info, FORCE_COMPRESS)) { |
452 | btrfs_info(root->fs_info, | 476 | btrfs_info(root->fs_info, |
453 | "setting nodatacow, compression disabled"); | 477 | "setting nodatacow, compression disabled"); |
454 | } else { | 478 | } else { |
@@ -461,7 +485,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
461 | btrfs_set_opt(info->mount_opt, NODATASUM); | 485 | btrfs_set_opt(info->mount_opt, NODATASUM); |
462 | break; | 486 | break; |
463 | case Opt_datacow: | 487 | case Opt_datacow: |
464 | btrfs_clear_and_info(root, NODATACOW, | 488 | btrfs_clear_and_info(info, NODATACOW, |
465 | "setting datacow"); | 489 | "setting datacow"); |
466 | break; | 490 | break; |
467 | case Opt_compress_force: | 491 | case Opt_compress_force: |
@@ -470,10 +494,11 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
470 | /* Fallthrough */ | 494 | /* Fallthrough */ |
471 | case Opt_compress: | 495 | case Opt_compress: |
472 | case Opt_compress_type: | 496 | case Opt_compress_type: |
473 | saved_compress_type = btrfs_test_opt(root, COMPRESS) ? | 497 | saved_compress_type = btrfs_test_opt(info, |
498 | COMPRESS) ? | ||
474 | info->compress_type : BTRFS_COMPRESS_NONE; | 499 | info->compress_type : BTRFS_COMPRESS_NONE; |
475 | saved_compress_force = | 500 | saved_compress_force = |
476 | btrfs_test_opt(root, FORCE_COMPRESS); | 501 | btrfs_test_opt(info, FORCE_COMPRESS); |
477 | if (token == Opt_compress || | 502 | if (token == Opt_compress || |
478 | token == Opt_compress_force || | 503 | token == Opt_compress_force || |
479 | strcmp(args[0].from, "zlib") == 0) { | 504 | strcmp(args[0].from, "zlib") == 0) { |
@@ -513,10 +538,10 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
513 | */ | 538 | */ |
514 | btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); | 539 | btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); |
515 | } | 540 | } |
516 | if ((btrfs_test_opt(root, COMPRESS) && | 541 | if ((btrfs_test_opt(info, COMPRESS) && |
517 | (info->compress_type != saved_compress_type || | 542 | (info->compress_type != saved_compress_type || |
518 | compress_force != saved_compress_force)) || | 543 | compress_force != saved_compress_force)) || |
519 | (!btrfs_test_opt(root, COMPRESS) && | 544 | (!btrfs_test_opt(info, COMPRESS) && |
520 | no_compress == 1)) { | 545 | no_compress == 1)) { |
521 | btrfs_info(root->fs_info, | 546 | btrfs_info(root->fs_info, |
522 | "%s %s compression", | 547 | "%s %s compression", |
@@ -526,25 +551,25 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
526 | compress_force = false; | 551 | compress_force = false; |
527 | break; | 552 | break; |
528 | case Opt_ssd: | 553 | case Opt_ssd: |
529 | btrfs_set_and_info(root, SSD, | 554 | btrfs_set_and_info(info, SSD, |
530 | "use ssd allocation scheme"); | 555 | "use ssd allocation scheme"); |
531 | break; | 556 | break; |
532 | case Opt_ssd_spread: | 557 | case Opt_ssd_spread: |
533 | btrfs_set_and_info(root, SSD_SPREAD, | 558 | btrfs_set_and_info(info, SSD_SPREAD, |
534 | "use spread ssd allocation scheme"); | 559 | "use spread ssd allocation scheme"); |
535 | btrfs_set_opt(info->mount_opt, SSD); | 560 | btrfs_set_opt(info->mount_opt, SSD); |
536 | break; | 561 | break; |
537 | case Opt_nossd: | 562 | case Opt_nossd: |
538 | btrfs_set_and_info(root, NOSSD, | 563 | btrfs_set_and_info(info, NOSSD, |
539 | "not using ssd allocation scheme"); | 564 | "not using ssd allocation scheme"); |
540 | btrfs_clear_opt(info->mount_opt, SSD); | 565 | btrfs_clear_opt(info->mount_opt, SSD); |
541 | break; | 566 | break; |
542 | case Opt_barrier: | 567 | case Opt_barrier: |
543 | btrfs_clear_and_info(root, NOBARRIER, | 568 | btrfs_clear_and_info(info, NOBARRIER, |
544 | "turning on barriers"); | 569 | "turning on barriers"); |
545 | break; | 570 | break; |
546 | case Opt_nobarrier: | 571 | case Opt_nobarrier: |
547 | btrfs_set_and_info(root, NOBARRIER, | 572 | btrfs_set_and_info(info, NOBARRIER, |
548 | "turning off barriers"); | 573 | "turning off barriers"); |
549 | break; | 574 | break; |
550 | case Opt_thread_pool: | 575 | case Opt_thread_pool: |
@@ -604,24 +629,24 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
604 | root->fs_info->sb->s_flags &= ~MS_POSIXACL; | 629 | root->fs_info->sb->s_flags &= ~MS_POSIXACL; |
605 | break; | 630 | break; |
606 | case Opt_notreelog: | 631 | case Opt_notreelog: |
607 | btrfs_set_and_info(root, NOTREELOG, | 632 | btrfs_set_and_info(info, NOTREELOG, |
608 | "disabling tree log"); | 633 | "disabling tree log"); |
609 | break; | 634 | break; |
610 | case Opt_treelog: | 635 | case Opt_treelog: |
611 | btrfs_clear_and_info(root, NOTREELOG, | 636 | btrfs_clear_and_info(info, NOTREELOG, |
612 | "enabling tree log"); | 637 | "enabling tree log"); |
613 | break; | 638 | break; |
614 | case Opt_norecovery: | 639 | case Opt_norecovery: |
615 | case Opt_nologreplay: | 640 | case Opt_nologreplay: |
616 | btrfs_set_and_info(root, NOLOGREPLAY, | 641 | btrfs_set_and_info(info, NOLOGREPLAY, |
617 | "disabling log replay at mount time"); | 642 | "disabling log replay at mount time"); |
618 | break; | 643 | break; |
619 | case Opt_flushoncommit: | 644 | case Opt_flushoncommit: |
620 | btrfs_set_and_info(root, FLUSHONCOMMIT, | 645 | btrfs_set_and_info(info, FLUSHONCOMMIT, |
621 | "turning on flush-on-commit"); | 646 | "turning on flush-on-commit"); |
622 | break; | 647 | break; |
623 | case Opt_noflushoncommit: | 648 | case Opt_noflushoncommit: |
624 | btrfs_clear_and_info(root, FLUSHONCOMMIT, | 649 | btrfs_clear_and_info(info, FLUSHONCOMMIT, |
625 | "turning off flush-on-commit"); | 650 | "turning off flush-on-commit"); |
626 | break; | 651 | break; |
627 | case Opt_ratio: | 652 | case Opt_ratio: |
@@ -638,11 +663,11 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
638 | } | 663 | } |
639 | break; | 664 | break; |
640 | case Opt_discard: | 665 | case Opt_discard: |
641 | btrfs_set_and_info(root, DISCARD, | 666 | btrfs_set_and_info(info, DISCARD, |
642 | "turning on discard"); | 667 | "turning on discard"); |
643 | break; | 668 | break; |
644 | case Opt_nodiscard: | 669 | case Opt_nodiscard: |
645 | btrfs_clear_and_info(root, DISCARD, | 670 | btrfs_clear_and_info(info, DISCARD, |
646 | "turning off discard"); | 671 | "turning off discard"); |
647 | break; | 672 | break; |
648 | case Opt_space_cache: | 673 | case Opt_space_cache: |
@@ -651,12 +676,13 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
651 | strcmp(args[0].from, "v1") == 0) { | 676 | strcmp(args[0].from, "v1") == 0) { |
652 | btrfs_clear_opt(root->fs_info->mount_opt, | 677 | btrfs_clear_opt(root->fs_info->mount_opt, |
653 | FREE_SPACE_TREE); | 678 | FREE_SPACE_TREE); |
654 | btrfs_set_and_info(root, SPACE_CACHE, | 679 | btrfs_set_and_info(info, SPACE_CACHE, |
655 | "enabling disk space caching"); | 680 | "enabling disk space caching"); |
656 | } else if (strcmp(args[0].from, "v2") == 0) { | 681 | } else if (strcmp(args[0].from, "v2") == 0) { |
657 | btrfs_clear_opt(root->fs_info->mount_opt, | 682 | btrfs_clear_opt(root->fs_info->mount_opt, |
658 | SPACE_CACHE); | 683 | SPACE_CACHE); |
659 | btrfs_set_and_info(root, FREE_SPACE_TREE, | 684 | btrfs_set_and_info(info, |
685 | FREE_SPACE_TREE, | ||
660 | "enabling free space tree"); | 686 | "enabling free space tree"); |
661 | } else { | 687 | } else { |
662 | ret = -EINVAL; | 688 | ret = -EINVAL; |
@@ -667,12 +693,14 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
667 | btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE); | 693 | btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE); |
668 | break; | 694 | break; |
669 | case Opt_no_space_cache: | 695 | case Opt_no_space_cache: |
670 | if (btrfs_test_opt(root, SPACE_CACHE)) { | 696 | if (btrfs_test_opt(info, SPACE_CACHE)) { |
671 | btrfs_clear_and_info(root, SPACE_CACHE, | 697 | btrfs_clear_and_info(info, |
698 | SPACE_CACHE, | ||
672 | "disabling disk space caching"); | 699 | "disabling disk space caching"); |
673 | } | 700 | } |
674 | if (btrfs_test_opt(root, FREE_SPACE_TREE)) { | 701 | if (btrfs_test_opt(info, FREE_SPACE_TREE)) { |
675 | btrfs_clear_and_info(root, FREE_SPACE_TREE, | 702 | btrfs_clear_and_info(info, |
703 | FREE_SPACE_TREE, | ||
676 | "disabling free space tree"); | 704 | "disabling free space tree"); |
677 | } | 705 | } |
678 | break; | 706 | break; |
@@ -685,7 +713,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
685 | "disabling inode map caching"); | 713 | "disabling inode map caching"); |
686 | break; | 714 | break; |
687 | case Opt_clear_cache: | 715 | case Opt_clear_cache: |
688 | btrfs_set_and_info(root, CLEAR_CACHE, | 716 | btrfs_set_and_info(info, CLEAR_CACHE, |
689 | "force clearing of disk cache"); | 717 | "force clearing of disk cache"); |
690 | break; | 718 | break; |
691 | case Opt_user_subvol_rm_allowed: | 719 | case Opt_user_subvol_rm_allowed: |
@@ -698,11 +726,11 @@ int btrfs_parse_options(struct btrfs_root *root, char *options, | |||
698 | btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG); | 726 | btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG); |
699 | break; | 727 | break; |
700 | case Opt_defrag: | 728 | case Opt_defrag: |
701 | btrfs_set_and_info(root, AUTO_DEFRAG, | 729 | btrfs_set_and_info(info, AUTO_DEFRAG, |
702 | "enabling auto defrag"); | 730 | "enabling auto defrag"); |
703 | break; | 731 | break; |
704 | case Opt_nodefrag: | 732 | case Opt_nodefrag: |
705 | btrfs_clear_and_info(root, AUTO_DEFRAG, | 733 | btrfs_clear_and_info(info, AUTO_DEFRAG, |
706 | "disabling auto defrag"); | 734 | "disabling auto defrag"); |
707 | break; | 735 | break; |
708 | case Opt_recovery: | 736 | case Opt_recovery: |
@@ -810,22 +838,22 @@ check: | |||
810 | /* | 838 | /* |
811 | * Extra check for current option against current flag | 839 | * Extra check for current option against current flag |
812 | */ | 840 | */ |
813 | if (btrfs_test_opt(root, NOLOGREPLAY) && !(new_flags & MS_RDONLY)) { | 841 | if (btrfs_test_opt(info, NOLOGREPLAY) && !(new_flags & MS_RDONLY)) { |
814 | btrfs_err(root->fs_info, | 842 | btrfs_err(root->fs_info, |
815 | "nologreplay must be used with ro mount option"); | 843 | "nologreplay must be used with ro mount option"); |
816 | ret = -EINVAL; | 844 | ret = -EINVAL; |
817 | } | 845 | } |
818 | out: | 846 | out: |
819 | if (btrfs_fs_compat_ro(root->fs_info, FREE_SPACE_TREE) && | 847 | if (btrfs_fs_compat_ro(root->fs_info, FREE_SPACE_TREE) && |
820 | !btrfs_test_opt(root, FREE_SPACE_TREE) && | 848 | !btrfs_test_opt(info, FREE_SPACE_TREE) && |
821 | !btrfs_test_opt(root, CLEAR_CACHE)) { | 849 | !btrfs_test_opt(info, CLEAR_CACHE)) { |
822 | btrfs_err(root->fs_info, "cannot disable free space tree"); | 850 | btrfs_err(root->fs_info, "cannot disable free space tree"); |
823 | ret = -EINVAL; | 851 | ret = -EINVAL; |
824 | 852 | ||
825 | } | 853 | } |
826 | if (!ret && btrfs_test_opt(root, SPACE_CACHE)) | 854 | if (!ret && btrfs_test_opt(info, SPACE_CACHE)) |
827 | btrfs_info(root->fs_info, "disk space caching is enabled"); | 855 | btrfs_info(root->fs_info, "disk space caching is enabled"); |
828 | if (!ret && btrfs_test_opt(root, FREE_SPACE_TREE)) | 856 | if (!ret && btrfs_test_opt(info, FREE_SPACE_TREE)) |
829 | btrfs_info(root->fs_info, "using free space tree"); | 857 | btrfs_info(root->fs_info, "using free space tree"); |
830 | kfree(orig); | 858 | kfree(orig); |
831 | return ret; | 859 | return ret; |
@@ -1149,7 +1177,7 @@ int btrfs_sync_fs(struct super_block *sb, int wait) | |||
1149 | struct btrfs_fs_info *fs_info = btrfs_sb(sb); | 1177 | struct btrfs_fs_info *fs_info = btrfs_sb(sb); |
1150 | struct btrfs_root *root = fs_info->tree_root; | 1178 | struct btrfs_root *root = fs_info->tree_root; |
1151 | 1179 | ||
1152 | trace_btrfs_sync_fs(wait); | 1180 | trace_btrfs_sync_fs(fs_info, wait); |
1153 | 1181 | ||
1154 | if (!wait) { | 1182 | if (!wait) { |
1155 | filemap_flush(fs_info->btree_inode->i_mapping); | 1183 | filemap_flush(fs_info->btree_inode->i_mapping); |
@@ -1192,13 +1220,13 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) | |||
1192 | struct btrfs_root *root = info->tree_root; | 1220 | struct btrfs_root *root = info->tree_root; |
1193 | char *compress_type; | 1221 | char *compress_type; |
1194 | 1222 | ||
1195 | if (btrfs_test_opt(root, DEGRADED)) | 1223 | if (btrfs_test_opt(info, DEGRADED)) |
1196 | seq_puts(seq, ",degraded"); | 1224 | seq_puts(seq, ",degraded"); |
1197 | if (btrfs_test_opt(root, NODATASUM)) | 1225 | if (btrfs_test_opt(info, NODATASUM)) |
1198 | seq_puts(seq, ",nodatasum"); | 1226 | seq_puts(seq, ",nodatasum"); |
1199 | if (btrfs_test_opt(root, NODATACOW)) | 1227 | if (btrfs_test_opt(info, NODATACOW)) |
1200 | seq_puts(seq, ",nodatacow"); | 1228 | seq_puts(seq, ",nodatacow"); |
1201 | if (btrfs_test_opt(root, NOBARRIER)) | 1229 | if (btrfs_test_opt(info, NOBARRIER)) |
1202 | seq_puts(seq, ",nobarrier"); | 1230 | seq_puts(seq, ",nobarrier"); |
1203 | if (info->max_inline != BTRFS_DEFAULT_MAX_INLINE) | 1231 | if (info->max_inline != BTRFS_DEFAULT_MAX_INLINE) |
1204 | seq_printf(seq, ",max_inline=%llu", info->max_inline); | 1232 | seq_printf(seq, ",max_inline=%llu", info->max_inline); |
@@ -1207,56 +1235,56 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) | |||
1207 | if (info->thread_pool_size != min_t(unsigned long, | 1235 | if (info->thread_pool_size != min_t(unsigned long, |
1208 | num_online_cpus() + 2, 8)) | 1236 | num_online_cpus() + 2, 8)) |
1209 | seq_printf(seq, ",thread_pool=%d", info->thread_pool_size); | 1237 | seq_printf(seq, ",thread_pool=%d", info->thread_pool_size); |
1210 | if (btrfs_test_opt(root, COMPRESS)) { | 1238 | if (btrfs_test_opt(info, COMPRESS)) { |
1211 | if (info->compress_type == BTRFS_COMPRESS_ZLIB) | 1239 | if (info->compress_type == BTRFS_COMPRESS_ZLIB) |
1212 | compress_type = "zlib"; | 1240 | compress_type = "zlib"; |
1213 | else | 1241 | else |
1214 | compress_type = "lzo"; | 1242 | compress_type = "lzo"; |
1215 | if (btrfs_test_opt(root, FORCE_COMPRESS)) | 1243 | if (btrfs_test_opt(info, FORCE_COMPRESS)) |
1216 | seq_printf(seq, ",compress-force=%s", compress_type); | 1244 | seq_printf(seq, ",compress-force=%s", compress_type); |
1217 | else | 1245 | else |
1218 | seq_printf(seq, ",compress=%s", compress_type); | 1246 | seq_printf(seq, ",compress=%s", compress_type); |
1219 | } | 1247 | } |
1220 | if (btrfs_test_opt(root, NOSSD)) | 1248 | if (btrfs_test_opt(info, NOSSD)) |
1221 | seq_puts(seq, ",nossd"); | 1249 | seq_puts(seq, ",nossd"); |
1222 | if (btrfs_test_opt(root, SSD_SPREAD)) | 1250 | if (btrfs_test_opt(info, SSD_SPREAD)) |
1223 | seq_puts(seq, ",ssd_spread"); | 1251 | seq_puts(seq, ",ssd_spread"); |
1224 | else if (btrfs_test_opt(root, SSD)) | 1252 | else if (btrfs_test_opt(info, SSD)) |
1225 | seq_puts(seq, ",ssd"); | 1253 | seq_puts(seq, ",ssd"); |
1226 | if (btrfs_test_opt(root, NOTREELOG)) | 1254 | if (btrfs_test_opt(info, NOTREELOG)) |
1227 | seq_puts(seq, ",notreelog"); | 1255 | seq_puts(seq, ",notreelog"); |
1228 | if (btrfs_test_opt(root, NOLOGREPLAY)) | 1256 | if (btrfs_test_opt(info, NOLOGREPLAY)) |
1229 | seq_puts(seq, ",nologreplay"); | 1257 | seq_puts(seq, ",nologreplay"); |
1230 | if (btrfs_test_opt(root, FLUSHONCOMMIT)) | 1258 | if (btrfs_test_opt(info, FLUSHONCOMMIT)) |
1231 | seq_puts(seq, ",flushoncommit"); | 1259 | seq_puts(seq, ",flushoncommit"); |
1232 | if (btrfs_test_opt(root, DISCARD)) | 1260 | if (btrfs_test_opt(info, DISCARD)) |
1233 | seq_puts(seq, ",discard"); | 1261 | seq_puts(seq, ",discard"); |
1234 | if (!(root->fs_info->sb->s_flags & MS_POSIXACL)) | 1262 | if (!(root->fs_info->sb->s_flags & MS_POSIXACL)) |
1235 | seq_puts(seq, ",noacl"); | 1263 | seq_puts(seq, ",noacl"); |
1236 | if (btrfs_test_opt(root, SPACE_CACHE)) | 1264 | if (btrfs_test_opt(info, SPACE_CACHE)) |
1237 | seq_puts(seq, ",space_cache"); | 1265 | seq_puts(seq, ",space_cache"); |
1238 | else if (btrfs_test_opt(root, FREE_SPACE_TREE)) | 1266 | else if (btrfs_test_opt(info, FREE_SPACE_TREE)) |
1239 | seq_puts(seq, ",space_cache=v2"); | 1267 | seq_puts(seq, ",space_cache=v2"); |
1240 | else | 1268 | else |
1241 | seq_puts(seq, ",nospace_cache"); | 1269 | seq_puts(seq, ",nospace_cache"); |
1242 | if (btrfs_test_opt(root, RESCAN_UUID_TREE)) | 1270 | if (btrfs_test_opt(info, RESCAN_UUID_TREE)) |
1243 | seq_puts(seq, ",rescan_uuid_tree"); | 1271 | seq_puts(seq, ",rescan_uuid_tree"); |
1244 | if (btrfs_test_opt(root, CLEAR_CACHE)) | 1272 | if (btrfs_test_opt(info, CLEAR_CACHE)) |
1245 | seq_puts(seq, ",clear_cache"); | 1273 | seq_puts(seq, ",clear_cache"); |
1246 | if (btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED)) | 1274 | if (btrfs_test_opt(info, USER_SUBVOL_RM_ALLOWED)) |
1247 | seq_puts(seq, ",user_subvol_rm_allowed"); | 1275 | seq_puts(seq, ",user_subvol_rm_allowed"); |
1248 | if (btrfs_test_opt(root, ENOSPC_DEBUG)) | 1276 | if (btrfs_test_opt(info, ENOSPC_DEBUG)) |
1249 | seq_puts(seq, ",enospc_debug"); | 1277 | seq_puts(seq, ",enospc_debug"); |
1250 | if (btrfs_test_opt(root, AUTO_DEFRAG)) | 1278 | if (btrfs_test_opt(info, AUTO_DEFRAG)) |
1251 | seq_puts(seq, ",autodefrag"); | 1279 | seq_puts(seq, ",autodefrag"); |
1252 | if (btrfs_test_opt(root, INODE_MAP_CACHE)) | 1280 | if (btrfs_test_opt(info, INODE_MAP_CACHE)) |
1253 | seq_puts(seq, ",inode_cache"); | 1281 | seq_puts(seq, ",inode_cache"); |
1254 | if (btrfs_test_opt(root, SKIP_BALANCE)) | 1282 | if (btrfs_test_opt(info, SKIP_BALANCE)) |
1255 | seq_puts(seq, ",skip_balance"); | 1283 | seq_puts(seq, ",skip_balance"); |
1256 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY | 1284 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
1257 | if (btrfs_test_opt(root, CHECK_INTEGRITY_INCLUDING_EXTENT_DATA)) | 1285 | if (btrfs_test_opt(info, CHECK_INTEGRITY_INCLUDING_EXTENT_DATA)) |
1258 | seq_puts(seq, ",check_int_data"); | 1286 | seq_puts(seq, ",check_int_data"); |
1259 | else if (btrfs_test_opt(root, CHECK_INTEGRITY)) | 1287 | else if (btrfs_test_opt(info, CHECK_INTEGRITY)) |
1260 | seq_puts(seq, ",check_int"); | 1288 | seq_puts(seq, ",check_int"); |
1261 | if (info->check_integrity_print_mask) | 1289 | if (info->check_integrity_print_mask) |
1262 | seq_printf(seq, ",check_int_print_mask=%d", | 1290 | seq_printf(seq, ",check_int_print_mask=%d", |
@@ -1265,14 +1293,14 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) | |||
1265 | if (info->metadata_ratio) | 1293 | if (info->metadata_ratio) |
1266 | seq_printf(seq, ",metadata_ratio=%d", | 1294 | seq_printf(seq, ",metadata_ratio=%d", |
1267 | info->metadata_ratio); | 1295 | info->metadata_ratio); |
1268 | if (btrfs_test_opt(root, PANIC_ON_FATAL_ERROR)) | 1296 | if (btrfs_test_opt(info, PANIC_ON_FATAL_ERROR)) |
1269 | seq_puts(seq, ",fatal_errors=panic"); | 1297 | seq_puts(seq, ",fatal_errors=panic"); |
1270 | if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL) | 1298 | if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL) |
1271 | seq_printf(seq, ",commit=%d", info->commit_interval); | 1299 | seq_printf(seq, ",commit=%d", info->commit_interval); |
1272 | #ifdef CONFIG_BTRFS_DEBUG | 1300 | #ifdef CONFIG_BTRFS_DEBUG |
1273 | if (btrfs_test_opt(root, FRAGMENT_DATA)) | 1301 | if (btrfs_test_opt(info, FRAGMENT_DATA)) |
1274 | seq_puts(seq, ",fragment=data"); | 1302 | seq_puts(seq, ",fragment=data"); |
1275 | if (btrfs_test_opt(root, FRAGMENT_METADATA)) | 1303 | if (btrfs_test_opt(info, FRAGMENT_METADATA)) |
1276 | seq_puts(seq, ",fragment=metadata"); | 1304 | seq_puts(seq, ",fragment=metadata"); |
1277 | #endif | 1305 | #endif |
1278 | seq_printf(seq, ",subvolid=%llu", | 1306 | seq_printf(seq, ",subvolid=%llu", |
@@ -2030,9 +2058,6 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes) | |||
2030 | * chunk). | 2058 | * chunk). |
2031 | * | 2059 | * |
2032 | * If metadata is exhausted, f_bavail will be 0. | 2060 | * If metadata is exhausted, f_bavail will be 0. |
2033 | * | ||
2034 | * FIXME: not accurate for mixed block groups, total and free/used are ok, | ||
2035 | * available appears slightly larger. | ||
2036 | */ | 2061 | */ |
2037 | static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) | 2062 | static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
2038 | { | 2063 | { |
@@ -2319,49 +2344,6 @@ static void btrfs_print_mod_info(void) | |||
2319 | btrfs_crc32c_impl()); | 2344 | btrfs_crc32c_impl()); |
2320 | } | 2345 | } |
2321 | 2346 | ||
2322 | static int btrfs_run_sanity_tests(void) | ||
2323 | { | ||
2324 | int ret, i; | ||
2325 | u32 sectorsize, nodesize; | ||
2326 | u32 test_sectorsize[] = { | ||
2327 | PAGE_SIZE, | ||
2328 | }; | ||
2329 | ret = btrfs_init_test_fs(); | ||
2330 | if (ret) | ||
2331 | return ret; | ||
2332 | for (i = 0; i < ARRAY_SIZE(test_sectorsize); i++) { | ||
2333 | sectorsize = test_sectorsize[i]; | ||
2334 | for (nodesize = sectorsize; | ||
2335 | nodesize <= BTRFS_MAX_METADATA_BLOCKSIZE; | ||
2336 | nodesize <<= 1) { | ||
2337 | pr_info("BTRFS: selftest: sectorsize: %u nodesize: %u\n", | ||
2338 | sectorsize, nodesize); | ||
2339 | ret = btrfs_test_free_space_cache(sectorsize, nodesize); | ||
2340 | if (ret) | ||
2341 | goto out; | ||
2342 | ret = btrfs_test_extent_buffer_operations(sectorsize, | ||
2343 | nodesize); | ||
2344 | if (ret) | ||
2345 | goto out; | ||
2346 | ret = btrfs_test_extent_io(sectorsize, nodesize); | ||
2347 | if (ret) | ||
2348 | goto out; | ||
2349 | ret = btrfs_test_inodes(sectorsize, nodesize); | ||
2350 | if (ret) | ||
2351 | goto out; | ||
2352 | ret = btrfs_test_qgroups(sectorsize, nodesize); | ||
2353 | if (ret) | ||
2354 | goto out; | ||
2355 | ret = btrfs_test_free_space_tree(sectorsize, nodesize); | ||
2356 | if (ret) | ||
2357 | goto out; | ||
2358 | } | ||
2359 | } | ||
2360 | out: | ||
2361 | btrfs_destroy_test_fs(); | ||
2362 | return ret; | ||
2363 | } | ||
2364 | |||
2365 | static int __init init_btrfs_fs(void) | 2347 | static int __init init_btrfs_fs(void) |
2366 | { | 2348 | { |
2367 | int err; | 2349 | int err; |
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 4879656bda3c..c6569905d3d1 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c | |||
@@ -326,6 +326,7 @@ SPACE_INFO_ATTR(bytes_used); | |||
326 | SPACE_INFO_ATTR(bytes_pinned); | 326 | SPACE_INFO_ATTR(bytes_pinned); |
327 | SPACE_INFO_ATTR(bytes_reserved); | 327 | SPACE_INFO_ATTR(bytes_reserved); |
328 | SPACE_INFO_ATTR(bytes_may_use); | 328 | SPACE_INFO_ATTR(bytes_may_use); |
329 | SPACE_INFO_ATTR(bytes_readonly); | ||
329 | SPACE_INFO_ATTR(disk_used); | 330 | SPACE_INFO_ATTR(disk_used); |
330 | SPACE_INFO_ATTR(disk_total); | 331 | SPACE_INFO_ATTR(disk_total); |
331 | BTRFS_ATTR(total_bytes_pinned, btrfs_space_info_show_total_bytes_pinned); | 332 | BTRFS_ATTR(total_bytes_pinned, btrfs_space_info_show_total_bytes_pinned); |
@@ -337,6 +338,7 @@ static struct attribute *space_info_attrs[] = { | |||
337 | BTRFS_ATTR_PTR(bytes_pinned), | 338 | BTRFS_ATTR_PTR(bytes_pinned), |
338 | BTRFS_ATTR_PTR(bytes_reserved), | 339 | BTRFS_ATTR_PTR(bytes_reserved), |
339 | BTRFS_ATTR_PTR(bytes_may_use), | 340 | BTRFS_ATTR_PTR(bytes_may_use), |
341 | BTRFS_ATTR_PTR(bytes_readonly), | ||
340 | BTRFS_ATTR_PTR(disk_used), | 342 | BTRFS_ATTR_PTR(disk_used), |
341 | BTRFS_ATTR_PTR(disk_total), | 343 | BTRFS_ATTR_PTR(disk_total), |
342 | BTRFS_ATTR_PTR(total_bytes_pinned), | 344 | BTRFS_ATTR_PTR(total_bytes_pinned), |
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c index 02223f3f78f4..bf62ad919a95 100644 --- a/fs/btrfs/tests/btrfs-tests.c +++ b/fs/btrfs/tests/btrfs-tests.c | |||
@@ -54,7 +54,7 @@ struct inode *btrfs_new_test_inode(void) | |||
54 | return new_inode(test_mnt->mnt_sb); | 54 | return new_inode(test_mnt->mnt_sb); |
55 | } | 55 | } |
56 | 56 | ||
57 | int btrfs_init_test_fs(void) | 57 | static int btrfs_init_test_fs(void) |
58 | { | 58 | { |
59 | int ret; | 59 | int ret; |
60 | 60 | ||
@@ -73,7 +73,7 @@ int btrfs_init_test_fs(void) | |||
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
75 | 75 | ||
76 | void btrfs_destroy_test_fs(void) | 76 | static void btrfs_destroy_test_fs(void) |
77 | { | 77 | { |
78 | kern_unmount(test_mnt); | 78 | kern_unmount(test_mnt); |
79 | unregister_filesystem(&test_type); | 79 | unregister_filesystem(&test_type); |
@@ -128,14 +128,27 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void) | |||
128 | extent_io_tree_init(&fs_info->freed_extents[0], NULL); | 128 | extent_io_tree_init(&fs_info->freed_extents[0], NULL); |
129 | extent_io_tree_init(&fs_info->freed_extents[1], NULL); | 129 | extent_io_tree_init(&fs_info->freed_extents[1], NULL); |
130 | fs_info->pinned_extents = &fs_info->freed_extents[0]; | 130 | fs_info->pinned_extents = &fs_info->freed_extents[0]; |
131 | set_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); | ||
132 | |||
133 | test_mnt->mnt_sb->s_fs_info = fs_info; | ||
134 | |||
131 | return fs_info; | 135 | return fs_info; |
132 | } | 136 | } |
133 | 137 | ||
134 | static void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info) | 138 | void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info) |
135 | { | 139 | { |
136 | struct radix_tree_iter iter; | 140 | struct radix_tree_iter iter; |
137 | void **slot; | 141 | void **slot; |
138 | 142 | ||
143 | if (!fs_info) | ||
144 | return; | ||
145 | |||
146 | if (WARN_ON(!test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, | ||
147 | &fs_info->fs_state))) | ||
148 | return; | ||
149 | |||
150 | test_mnt->mnt_sb->s_fs_info = NULL; | ||
151 | |||
139 | spin_lock(&fs_info->buffer_lock); | 152 | spin_lock(&fs_info->buffer_lock); |
140 | radix_tree_for_each_slot(slot, &fs_info->buffer_radix, &iter, 0) { | 153 | radix_tree_for_each_slot(slot, &fs_info->buffer_radix, &iter, 0) { |
141 | struct extent_buffer *eb; | 154 | struct extent_buffer *eb; |
@@ -167,10 +180,11 @@ void btrfs_free_dummy_root(struct btrfs_root *root) | |||
167 | { | 180 | { |
168 | if (!root) | 181 | if (!root) |
169 | return; | 182 | return; |
183 | /* Will be freed by btrfs_free_fs_roots */ | ||
184 | if (WARN_ON(test_bit(BTRFS_ROOT_IN_RADIX, &root->state))) | ||
185 | return; | ||
170 | if (root->node) | 186 | if (root->node) |
171 | free_extent_buffer(root->node); | 187 | free_extent_buffer(root->node); |
172 | if (root->fs_info) | ||
173 | btrfs_free_dummy_fs_info(root->fs_info); | ||
174 | kfree(root); | 188 | kfree(root); |
175 | } | 189 | } |
176 | 190 | ||
@@ -220,3 +234,46 @@ void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans) | |||
220 | INIT_LIST_HEAD(&trans->qgroup_ref_list); | 234 | INIT_LIST_HEAD(&trans->qgroup_ref_list); |
221 | trans->type = __TRANS_DUMMY; | 235 | trans->type = __TRANS_DUMMY; |
222 | } | 236 | } |
237 | |||
238 | int btrfs_run_sanity_tests(void) | ||
239 | { | ||
240 | int ret, i; | ||
241 | u32 sectorsize, nodesize; | ||
242 | u32 test_sectorsize[] = { | ||
243 | PAGE_SIZE, | ||
244 | }; | ||
245 | ret = btrfs_init_test_fs(); | ||
246 | if (ret) | ||
247 | return ret; | ||
248 | for (i = 0; i < ARRAY_SIZE(test_sectorsize); i++) { | ||
249 | sectorsize = test_sectorsize[i]; | ||
250 | for (nodesize = sectorsize; | ||
251 | nodesize <= BTRFS_MAX_METADATA_BLOCKSIZE; | ||
252 | nodesize <<= 1) { | ||
253 | pr_info("BTRFS: selftest: sectorsize: %u nodesize: %u\n", | ||
254 | sectorsize, nodesize); | ||
255 | ret = btrfs_test_free_space_cache(sectorsize, nodesize); | ||
256 | if (ret) | ||
257 | goto out; | ||
258 | ret = btrfs_test_extent_buffer_operations(sectorsize, | ||
259 | nodesize); | ||
260 | if (ret) | ||
261 | goto out; | ||
262 | ret = btrfs_test_extent_io(sectorsize, nodesize); | ||
263 | if (ret) | ||
264 | goto out; | ||
265 | ret = btrfs_test_inodes(sectorsize, nodesize); | ||
266 | if (ret) | ||
267 | goto out; | ||
268 | ret = btrfs_test_qgroups(sectorsize, nodesize); | ||
269 | if (ret) | ||
270 | goto out; | ||
271 | ret = btrfs_test_free_space_tree(sectorsize, nodesize); | ||
272 | if (ret) | ||
273 | goto out; | ||
274 | } | ||
275 | } | ||
276 | out: | ||
277 | btrfs_destroy_test_fs(); | ||
278 | return ret; | ||
279 | } | ||
diff --git a/fs/btrfs/tests/btrfs-tests.h b/fs/btrfs/tests/btrfs-tests.h index 66fb6b701eb7..b17ffbe8f9f3 100644 --- a/fs/btrfs/tests/btrfs-tests.h +++ b/fs/btrfs/tests/btrfs-tests.h | |||
@@ -20,57 +20,29 @@ | |||
20 | #define __BTRFS_TESTS | 20 | #define __BTRFS_TESTS |
21 | 21 | ||
22 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS | 22 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
23 | int btrfs_run_sanity_tests(void); | ||
23 | 24 | ||
24 | #define test_msg(fmt, ...) pr_info("BTRFS: selftest: " fmt, ##__VA_ARGS__) | 25 | #define test_msg(fmt, ...) pr_info("BTRFS: selftest: " fmt, ##__VA_ARGS__) |
25 | 26 | ||
26 | struct btrfs_root; | 27 | struct btrfs_root; |
27 | struct btrfs_trans_handle; | 28 | struct btrfs_trans_handle; |
28 | 29 | ||
29 | int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize); | ||
30 | int btrfs_test_extent_buffer_operations(u32 sectorsize, u32 nodesize); | 30 | int btrfs_test_extent_buffer_operations(u32 sectorsize, u32 nodesize); |
31 | int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize); | ||
31 | int btrfs_test_extent_io(u32 sectorsize, u32 nodesize); | 32 | int btrfs_test_extent_io(u32 sectorsize, u32 nodesize); |
32 | int btrfs_test_inodes(u32 sectorsize, u32 nodesize); | 33 | int btrfs_test_inodes(u32 sectorsize, u32 nodesize); |
33 | int btrfs_test_qgroups(u32 sectorsize, u32 nodesize); | 34 | int btrfs_test_qgroups(u32 sectorsize, u32 nodesize); |
34 | int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize); | 35 | int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize); |
35 | int btrfs_init_test_fs(void); | ||
36 | void btrfs_destroy_test_fs(void); | ||
37 | struct inode *btrfs_new_test_inode(void); | 36 | struct inode *btrfs_new_test_inode(void); |
38 | struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void); | 37 | struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void); |
38 | void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info); | ||
39 | void btrfs_free_dummy_root(struct btrfs_root *root); | 39 | void btrfs_free_dummy_root(struct btrfs_root *root); |
40 | struct btrfs_block_group_cache * | 40 | struct btrfs_block_group_cache * |
41 | btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize); | 41 | btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize); |
42 | void btrfs_free_dummy_block_group(struct btrfs_block_group_cache *cache); | 42 | void btrfs_free_dummy_block_group(struct btrfs_block_group_cache *cache); |
43 | void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans); | 43 | void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans); |
44 | #else | 44 | #else |
45 | static inline int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize) | 45 | static inline int btrfs_run_sanity_tests(void) |
46 | { | ||
47 | return 0; | ||
48 | } | ||
49 | static inline int btrfs_test_extent_buffer_operations(u32 sectorsize, | ||
50 | u32 nodesize) | ||
51 | { | ||
52 | return 0; | ||
53 | } | ||
54 | static inline int btrfs_init_test_fs(void) | ||
55 | { | ||
56 | return 0; | ||
57 | } | ||
58 | static inline void btrfs_destroy_test_fs(void) | ||
59 | { | ||
60 | } | ||
61 | static inline int btrfs_test_extent_io(u32 sectorsize, u32 nodesize) | ||
62 | { | ||
63 | return 0; | ||
64 | } | ||
65 | static inline int btrfs_test_inodes(u32 sectorsize, u32 nodesize) | ||
66 | { | ||
67 | return 0; | ||
68 | } | ||
69 | static inline int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) | ||
70 | { | ||
71 | return 0; | ||
72 | } | ||
73 | static inline int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize) | ||
74 | { | 46 | { |
75 | return 0; | 47 | return 0; |
76 | } | 48 | } |
diff --git a/fs/btrfs/tests/extent-buffer-tests.c b/fs/btrfs/tests/extent-buffer-tests.c index 4f8cbd1ec5ee..199569174637 100644 --- a/fs/btrfs/tests/extent-buffer-tests.c +++ b/fs/btrfs/tests/extent-buffer-tests.c | |||
@@ -24,8 +24,9 @@ | |||
24 | 24 | ||
25 | static int test_btrfs_split_item(u32 sectorsize, u32 nodesize) | 25 | static int test_btrfs_split_item(u32 sectorsize, u32 nodesize) |
26 | { | 26 | { |
27 | struct btrfs_path *path; | 27 | struct btrfs_fs_info *fs_info; |
28 | struct btrfs_root *root; | 28 | struct btrfs_path *path = NULL; |
29 | struct btrfs_root *root = NULL; | ||
29 | struct extent_buffer *eb; | 30 | struct extent_buffer *eb; |
30 | struct btrfs_item *item; | 31 | struct btrfs_item *item; |
31 | char *value = "mary had a little lamb"; | 32 | char *value = "mary had a little lamb"; |
@@ -40,17 +41,24 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize) | |||
40 | 41 | ||
41 | test_msg("Running btrfs_split_item tests\n"); | 42 | test_msg("Running btrfs_split_item tests\n"); |
42 | 43 | ||
43 | root = btrfs_alloc_dummy_root(sectorsize, nodesize); | 44 | fs_info = btrfs_alloc_dummy_fs_info(); |
45 | if (!fs_info) { | ||
46 | test_msg("Could not allocate fs_info\n"); | ||
47 | return -ENOMEM; | ||
48 | } | ||
49 | |||
50 | root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); | ||
44 | if (IS_ERR(root)) { | 51 | if (IS_ERR(root)) { |
45 | test_msg("Could not allocate root\n"); | 52 | test_msg("Could not allocate root\n"); |
46 | return PTR_ERR(root); | 53 | ret = PTR_ERR(root); |
54 | goto out; | ||
47 | } | 55 | } |
48 | 56 | ||
49 | path = btrfs_alloc_path(); | 57 | path = btrfs_alloc_path(); |
50 | if (!path) { | 58 | if (!path) { |
51 | test_msg("Could not allocate path\n"); | 59 | test_msg("Could not allocate path\n"); |
52 | kfree(root); | 60 | ret = -ENOMEM; |
53 | return -ENOMEM; | 61 | goto out; |
54 | } | 62 | } |
55 | 63 | ||
56 | path->nodes[0] = eb = alloc_dummy_extent_buffer(NULL, nodesize, | 64 | path->nodes[0] = eb = alloc_dummy_extent_buffer(NULL, nodesize, |
@@ -219,7 +227,8 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize) | |||
219 | } | 227 | } |
220 | out: | 228 | out: |
221 | btrfs_free_path(path); | 229 | btrfs_free_path(path); |
222 | kfree(root); | 230 | btrfs_free_dummy_root(root); |
231 | btrfs_free_dummy_fs_info(fs_info); | ||
223 | return ret; | 232 | return ret; |
224 | } | 233 | } |
225 | 234 | ||
diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c index 3956bb2ff84c..3221c8dee272 100644 --- a/fs/btrfs/tests/free-space-tests.c +++ b/fs/btrfs/tests/free-space-tests.c | |||
@@ -837,6 +837,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache, | |||
837 | 837 | ||
838 | int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize) | 838 | int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize) |
839 | { | 839 | { |
840 | struct btrfs_fs_info *fs_info; | ||
840 | struct btrfs_block_group_cache *cache; | 841 | struct btrfs_block_group_cache *cache; |
841 | struct btrfs_root *root = NULL; | 842 | struct btrfs_root *root = NULL; |
842 | int ret = -ENOMEM; | 843 | int ret = -ENOMEM; |
@@ -855,15 +856,17 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize) | |||
855 | return 0; | 856 | return 0; |
856 | } | 857 | } |
857 | 858 | ||
858 | root = btrfs_alloc_dummy_root(sectorsize, nodesize); | 859 | fs_info = btrfs_alloc_dummy_fs_info(); |
859 | if (IS_ERR(root)) { | 860 | if (!fs_info) { |
860 | ret = PTR_ERR(root); | 861 | ret = -ENOMEM; |
861 | goto out; | 862 | goto out; |
862 | } | 863 | } |
863 | 864 | ||
864 | root->fs_info = btrfs_alloc_dummy_fs_info(); | 865 | root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); |
865 | if (!root->fs_info) | 866 | if (IS_ERR(root)) { |
867 | ret = PTR_ERR(root); | ||
866 | goto out; | 868 | goto out; |
869 | } | ||
867 | 870 | ||
868 | root->fs_info->extent_root = root; | 871 | root->fs_info->extent_root = root; |
869 | cache->fs_info = root->fs_info; | 872 | cache->fs_info = root->fs_info; |
@@ -882,6 +885,7 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize) | |||
882 | out: | 885 | out: |
883 | btrfs_free_dummy_block_group(cache); | 886 | btrfs_free_dummy_block_group(cache); |
884 | btrfs_free_dummy_root(root); | 887 | btrfs_free_dummy_root(root); |
888 | btrfs_free_dummy_fs_info(fs_info); | ||
885 | test_msg("Free space cache tests finished\n"); | 889 | test_msg("Free space cache tests finished\n"); |
886 | return ret; | 890 | return ret; |
887 | } | 891 | } |
diff --git a/fs/btrfs/tests/free-space-tree-tests.c b/fs/btrfs/tests/free-space-tree-tests.c index aac507085ab0..7508d3b42780 100644 --- a/fs/btrfs/tests/free-space-tree-tests.c +++ b/fs/btrfs/tests/free-space-tree-tests.c | |||
@@ -443,23 +443,24 @@ typedef int (*test_func_t)(struct btrfs_trans_handle *, | |||
443 | static int run_test(test_func_t test_func, int bitmaps, | 443 | static int run_test(test_func_t test_func, int bitmaps, |
444 | u32 sectorsize, u32 nodesize) | 444 | u32 sectorsize, u32 nodesize) |
445 | { | 445 | { |
446 | struct btrfs_fs_info *fs_info; | ||
446 | struct btrfs_root *root = NULL; | 447 | struct btrfs_root *root = NULL; |
447 | struct btrfs_block_group_cache *cache = NULL; | 448 | struct btrfs_block_group_cache *cache = NULL; |
448 | struct btrfs_trans_handle trans; | 449 | struct btrfs_trans_handle trans; |
449 | struct btrfs_path *path = NULL; | 450 | struct btrfs_path *path = NULL; |
450 | int ret; | 451 | int ret; |
451 | 452 | ||
452 | root = btrfs_alloc_dummy_root(sectorsize, nodesize); | 453 | fs_info = btrfs_alloc_dummy_fs_info(); |
453 | if (IS_ERR(root)) { | 454 | if (!fs_info) { |
454 | test_msg("Couldn't allocate dummy root\n"); | 455 | test_msg("Couldn't allocate dummy fs info\n"); |
455 | ret = PTR_ERR(root); | 456 | ret = -ENOMEM; |
456 | goto out; | 457 | goto out; |
457 | } | 458 | } |
458 | 459 | ||
459 | root->fs_info = btrfs_alloc_dummy_fs_info(); | 460 | root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); |
460 | if (!root->fs_info) { | 461 | if (IS_ERR(root)) { |
461 | test_msg("Couldn't allocate dummy fs info\n"); | 462 | test_msg("Couldn't allocate dummy root\n"); |
462 | ret = -ENOMEM; | 463 | ret = PTR_ERR(root); |
463 | goto out; | 464 | goto out; |
464 | } | 465 | } |
465 | 466 | ||
@@ -534,6 +535,7 @@ out: | |||
534 | btrfs_free_path(path); | 535 | btrfs_free_path(path); |
535 | btrfs_free_dummy_block_group(cache); | 536 | btrfs_free_dummy_block_group(cache); |
536 | btrfs_free_dummy_root(root); | 537 | btrfs_free_dummy_root(root); |
538 | btrfs_free_dummy_fs_info(fs_info); | ||
537 | return ret; | 539 | return ret; |
538 | } | 540 | } |
539 | 541 | ||
diff --git a/fs/btrfs/tests/inode-tests.c b/fs/btrfs/tests/inode-tests.c index 29648c0a39f1..9f72aeda9220 100644 --- a/fs/btrfs/tests/inode-tests.c +++ b/fs/btrfs/tests/inode-tests.c | |||
@@ -230,6 +230,7 @@ static unsigned long vacancy_only = 0; | |||
230 | 230 | ||
231 | static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize) | 231 | static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize) |
232 | { | 232 | { |
233 | struct btrfs_fs_info *fs_info = NULL; | ||
233 | struct inode *inode = NULL; | 234 | struct inode *inode = NULL; |
234 | struct btrfs_root *root = NULL; | 235 | struct btrfs_root *root = NULL; |
235 | struct extent_map *em = NULL; | 236 | struct extent_map *em = NULL; |
@@ -248,19 +249,15 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize) | |||
248 | BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID; | 249 | BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID; |
249 | BTRFS_I(inode)->location.offset = 0; | 250 | BTRFS_I(inode)->location.offset = 0; |
250 | 251 | ||
251 | root = btrfs_alloc_dummy_root(sectorsize, nodesize); | 252 | fs_info = btrfs_alloc_dummy_fs_info(); |
252 | if (IS_ERR(root)) { | 253 | if (!fs_info) { |
253 | test_msg("Couldn't allocate root\n"); | 254 | test_msg("Couldn't allocate dummy fs info\n"); |
254 | goto out; | 255 | goto out; |
255 | } | 256 | } |
256 | 257 | ||
257 | /* | 258 | root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); |
258 | * We do this since btrfs_get_extent wants to assign em->bdev to | 259 | if (IS_ERR(root)) { |
259 | * root->fs_info->fs_devices->latest_bdev. | 260 | test_msg("Couldn't allocate root\n"); |
260 | */ | ||
261 | root->fs_info = btrfs_alloc_dummy_fs_info(); | ||
262 | if (!root->fs_info) { | ||
263 | test_msg("Couldn't allocate dummy fs info\n"); | ||
264 | goto out; | 261 | goto out; |
265 | } | 262 | } |
266 | 263 | ||
@@ -835,11 +832,13 @@ out: | |||
835 | free_extent_map(em); | 832 | free_extent_map(em); |
836 | iput(inode); | 833 | iput(inode); |
837 | btrfs_free_dummy_root(root); | 834 | btrfs_free_dummy_root(root); |
835 | btrfs_free_dummy_fs_info(fs_info); | ||
838 | return ret; | 836 | return ret; |
839 | } | 837 | } |
840 | 838 | ||
841 | static int test_hole_first(u32 sectorsize, u32 nodesize) | 839 | static int test_hole_first(u32 sectorsize, u32 nodesize) |
842 | { | 840 | { |
841 | struct btrfs_fs_info *fs_info = NULL; | ||
843 | struct inode *inode = NULL; | 842 | struct inode *inode = NULL; |
844 | struct btrfs_root *root = NULL; | 843 | struct btrfs_root *root = NULL; |
845 | struct extent_map *em = NULL; | 844 | struct extent_map *em = NULL; |
@@ -855,15 +854,15 @@ static int test_hole_first(u32 sectorsize, u32 nodesize) | |||
855 | BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID; | 854 | BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID; |
856 | BTRFS_I(inode)->location.offset = 0; | 855 | BTRFS_I(inode)->location.offset = 0; |
857 | 856 | ||
858 | root = btrfs_alloc_dummy_root(sectorsize, nodesize); | 857 | fs_info = btrfs_alloc_dummy_fs_info(); |
859 | if (IS_ERR(root)) { | 858 | if (!fs_info) { |
860 | test_msg("Couldn't allocate root\n"); | 859 | test_msg("Couldn't allocate dummy fs info\n"); |
861 | goto out; | 860 | goto out; |
862 | } | 861 | } |
863 | 862 | ||
864 | root->fs_info = btrfs_alloc_dummy_fs_info(); | 863 | root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); |
865 | if (!root->fs_info) { | 864 | if (IS_ERR(root)) { |
866 | test_msg("Couldn't allocate dummy fs info\n"); | 865 | test_msg("Couldn't allocate root\n"); |
867 | goto out; | 866 | goto out; |
868 | } | 867 | } |
869 | 868 | ||
@@ -934,11 +933,13 @@ out: | |||
934 | free_extent_map(em); | 933 | free_extent_map(em); |
935 | iput(inode); | 934 | iput(inode); |
936 | btrfs_free_dummy_root(root); | 935 | btrfs_free_dummy_root(root); |
936 | btrfs_free_dummy_fs_info(fs_info); | ||
937 | return ret; | 937 | return ret; |
938 | } | 938 | } |
939 | 939 | ||
940 | static int test_extent_accounting(u32 sectorsize, u32 nodesize) | 940 | static int test_extent_accounting(u32 sectorsize, u32 nodesize) |
941 | { | 941 | { |
942 | struct btrfs_fs_info *fs_info = NULL; | ||
942 | struct inode *inode = NULL; | 943 | struct inode *inode = NULL; |
943 | struct btrfs_root *root = NULL; | 944 | struct btrfs_root *root = NULL; |
944 | int ret = -ENOMEM; | 945 | int ret = -ENOMEM; |
@@ -949,15 +950,15 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) | |||
949 | return ret; | 950 | return ret; |
950 | } | 951 | } |
951 | 952 | ||
952 | root = btrfs_alloc_dummy_root(sectorsize, nodesize); | 953 | fs_info = btrfs_alloc_dummy_fs_info(); |
953 | if (IS_ERR(root)) { | 954 | if (!fs_info) { |
954 | test_msg("Couldn't allocate root\n"); | 955 | test_msg("Couldn't allocate dummy fs info\n"); |
955 | goto out; | 956 | goto out; |
956 | } | 957 | } |
957 | 958 | ||
958 | root->fs_info = btrfs_alloc_dummy_fs_info(); | 959 | root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); |
959 | if (!root->fs_info) { | 960 | if (IS_ERR(root)) { |
960 | test_msg("Couldn't allocate dummy fs info\n"); | 961 | test_msg("Couldn't allocate root\n"); |
961 | goto out; | 962 | goto out; |
962 | } | 963 | } |
963 | 964 | ||
@@ -1132,6 +1133,7 @@ out: | |||
1132 | NULL, GFP_KERNEL); | 1133 | NULL, GFP_KERNEL); |
1133 | iput(inode); | 1134 | iput(inode); |
1134 | btrfs_free_dummy_root(root); | 1135 | btrfs_free_dummy_root(root); |
1136 | btrfs_free_dummy_fs_info(fs_info); | ||
1135 | return ret; | 1137 | return ret; |
1136 | } | 1138 | } |
1137 | 1139 | ||
diff --git a/fs/btrfs/tests/qgroup-tests.c b/fs/btrfs/tests/qgroup-tests.c index 57a12c0d680b..4407fef7c16c 100644 --- a/fs/btrfs/tests/qgroup-tests.c +++ b/fs/btrfs/tests/qgroup-tests.c | |||
@@ -453,22 +453,24 @@ static int test_multiple_refs(struct btrfs_root *root, | |||
453 | 453 | ||
454 | int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) | 454 | int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) |
455 | { | 455 | { |
456 | struct btrfs_fs_info *fs_info = NULL; | ||
456 | struct btrfs_root *root; | 457 | struct btrfs_root *root; |
457 | struct btrfs_root *tmp_root; | 458 | struct btrfs_root *tmp_root; |
458 | int ret = 0; | 459 | int ret = 0; |
459 | 460 | ||
460 | root = btrfs_alloc_dummy_root(sectorsize, nodesize); | 461 | fs_info = btrfs_alloc_dummy_fs_info(); |
461 | if (IS_ERR(root)) { | 462 | if (!fs_info) { |
462 | test_msg("Couldn't allocate root\n"); | 463 | test_msg("Couldn't allocate dummy fs info\n"); |
463 | return PTR_ERR(root); | 464 | return -ENOMEM; |
464 | } | 465 | } |
465 | 466 | ||
466 | root->fs_info = btrfs_alloc_dummy_fs_info(); | 467 | root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); |
467 | if (!root->fs_info) { | 468 | if (IS_ERR(root)) { |
468 | test_msg("Couldn't allocate dummy fs info\n"); | 469 | test_msg("Couldn't allocate root\n"); |
469 | ret = -ENOMEM; | 470 | ret = PTR_ERR(root); |
470 | goto out; | 471 | goto out; |
471 | } | 472 | } |
473 | |||
472 | /* We are using this root as our extent root */ | 474 | /* We are using this root as our extent root */ |
473 | root->fs_info->extent_root = root; | 475 | root->fs_info->extent_root = root; |
474 | 476 | ||
@@ -495,7 +497,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) | |||
495 | btrfs_set_header_nritems(root->node, 0); | 497 | btrfs_set_header_nritems(root->node, 0); |
496 | root->alloc_bytenr += 2 * nodesize; | 498 | root->alloc_bytenr += 2 * nodesize; |
497 | 499 | ||
498 | tmp_root = btrfs_alloc_dummy_root(sectorsize, nodesize); | 500 | tmp_root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); |
499 | if (IS_ERR(tmp_root)) { | 501 | if (IS_ERR(tmp_root)) { |
500 | test_msg("Couldn't allocate a fs root\n"); | 502 | test_msg("Couldn't allocate a fs root\n"); |
501 | ret = PTR_ERR(tmp_root); | 503 | ret = PTR_ERR(tmp_root); |
@@ -510,7 +512,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) | |||
510 | goto out; | 512 | goto out; |
511 | } | 513 | } |
512 | 514 | ||
513 | tmp_root = btrfs_alloc_dummy_root(sectorsize, nodesize); | 515 | tmp_root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize); |
514 | if (IS_ERR(tmp_root)) { | 516 | if (IS_ERR(tmp_root)) { |
515 | test_msg("Couldn't allocate a fs root\n"); | 517 | test_msg("Couldn't allocate a fs root\n"); |
516 | ret = PTR_ERR(tmp_root); | 518 | ret = PTR_ERR(tmp_root); |
@@ -531,5 +533,6 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) | |||
531 | ret = test_multiple_refs(root, sectorsize, nodesize); | 533 | ret = test_multiple_refs(root, sectorsize, nodesize); |
532 | out: | 534 | out: |
533 | btrfs_free_dummy_root(root); | 535 | btrfs_free_dummy_root(root); |
536 | btrfs_free_dummy_fs_info(fs_info); | ||
534 | return ret; | 537 | return ret; |
535 | } | 538 | } |
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 948aa186b353..9cca0a721961 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -561,6 +561,7 @@ again: | |||
561 | h->transaction = cur_trans; | 561 | h->transaction = cur_trans; |
562 | h->root = root; | 562 | h->root = root; |
563 | h->use_count = 1; | 563 | h->use_count = 1; |
564 | h->fs_info = root->fs_info; | ||
564 | 565 | ||
565 | h->type = type; | 566 | h->type = type; |
566 | h->can_flush_pending_bgs = true; | 567 | h->can_flush_pending_bgs = true; |
@@ -1491,7 +1492,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1491 | goto dir_item_existed; | 1492 | goto dir_item_existed; |
1492 | } else if (IS_ERR(dir_item)) { | 1493 | } else if (IS_ERR(dir_item)) { |
1493 | ret = PTR_ERR(dir_item); | 1494 | ret = PTR_ERR(dir_item); |
1494 | btrfs_abort_transaction(trans, root, ret); | 1495 | btrfs_abort_transaction(trans, ret); |
1495 | goto fail; | 1496 | goto fail; |
1496 | } | 1497 | } |
1497 | btrfs_release_path(path); | 1498 | btrfs_release_path(path); |
@@ -1504,7 +1505,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1504 | */ | 1505 | */ |
1505 | ret = btrfs_run_delayed_items(trans, root); | 1506 | ret = btrfs_run_delayed_items(trans, root); |
1506 | if (ret) { /* Transaction aborted */ | 1507 | if (ret) { /* Transaction aborted */ |
1507 | btrfs_abort_transaction(trans, root, ret); | 1508 | btrfs_abort_transaction(trans, ret); |
1508 | goto fail; | 1509 | goto fail; |
1509 | } | 1510 | } |
1510 | 1511 | ||
@@ -1543,7 +1544,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1543 | if (ret) { | 1544 | if (ret) { |
1544 | btrfs_tree_unlock(old); | 1545 | btrfs_tree_unlock(old); |
1545 | free_extent_buffer(old); | 1546 | free_extent_buffer(old); |
1546 | btrfs_abort_transaction(trans, root, ret); | 1547 | btrfs_abort_transaction(trans, ret); |
1547 | goto fail; | 1548 | goto fail; |
1548 | } | 1549 | } |
1549 | 1550 | ||
@@ -1554,7 +1555,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1554 | btrfs_tree_unlock(old); | 1555 | btrfs_tree_unlock(old); |
1555 | free_extent_buffer(old); | 1556 | free_extent_buffer(old); |
1556 | if (ret) { | 1557 | if (ret) { |
1557 | btrfs_abort_transaction(trans, root, ret); | 1558 | btrfs_abort_transaction(trans, ret); |
1558 | goto fail; | 1559 | goto fail; |
1559 | } | 1560 | } |
1560 | /* see comments in should_cow_block() */ | 1561 | /* see comments in should_cow_block() */ |
@@ -1568,7 +1569,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1568 | btrfs_tree_unlock(tmp); | 1569 | btrfs_tree_unlock(tmp); |
1569 | free_extent_buffer(tmp); | 1570 | free_extent_buffer(tmp); |
1570 | if (ret) { | 1571 | if (ret) { |
1571 | btrfs_abort_transaction(trans, root, ret); | 1572 | btrfs_abort_transaction(trans, ret); |
1572 | goto fail; | 1573 | goto fail; |
1573 | } | 1574 | } |
1574 | 1575 | ||
@@ -1580,7 +1581,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1580 | btrfs_ino(parent_inode), index, | 1581 | btrfs_ino(parent_inode), index, |
1581 | dentry->d_name.name, dentry->d_name.len); | 1582 | dentry->d_name.name, dentry->d_name.len); |
1582 | if (ret) { | 1583 | if (ret) { |
1583 | btrfs_abort_transaction(trans, root, ret); | 1584 | btrfs_abort_transaction(trans, ret); |
1584 | goto fail; | 1585 | goto fail; |
1585 | } | 1586 | } |
1586 | 1587 | ||
@@ -1588,19 +1589,19 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1588 | pending->snap = btrfs_read_fs_root_no_name(root->fs_info, &key); | 1589 | pending->snap = btrfs_read_fs_root_no_name(root->fs_info, &key); |
1589 | if (IS_ERR(pending->snap)) { | 1590 | if (IS_ERR(pending->snap)) { |
1590 | ret = PTR_ERR(pending->snap); | 1591 | ret = PTR_ERR(pending->snap); |
1591 | btrfs_abort_transaction(trans, root, ret); | 1592 | btrfs_abort_transaction(trans, ret); |
1592 | goto fail; | 1593 | goto fail; |
1593 | } | 1594 | } |
1594 | 1595 | ||
1595 | ret = btrfs_reloc_post_snapshot(trans, pending); | 1596 | ret = btrfs_reloc_post_snapshot(trans, pending); |
1596 | if (ret) { | 1597 | if (ret) { |
1597 | btrfs_abort_transaction(trans, root, ret); | 1598 | btrfs_abort_transaction(trans, ret); |
1598 | goto fail; | 1599 | goto fail; |
1599 | } | 1600 | } |
1600 | 1601 | ||
1601 | ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); | 1602 | ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); |
1602 | if (ret) { | 1603 | if (ret) { |
1603 | btrfs_abort_transaction(trans, root, ret); | 1604 | btrfs_abort_transaction(trans, ret); |
1604 | goto fail; | 1605 | goto fail; |
1605 | } | 1606 | } |
1606 | 1607 | ||
@@ -1622,7 +1623,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1622 | /* We have check then name at the beginning, so it is impossible. */ | 1623 | /* We have check then name at the beginning, so it is impossible. */ |
1623 | BUG_ON(ret == -EEXIST || ret == -EOVERFLOW); | 1624 | BUG_ON(ret == -EEXIST || ret == -EOVERFLOW); |
1624 | if (ret) { | 1625 | if (ret) { |
1625 | btrfs_abort_transaction(trans, root, ret); | 1626 | btrfs_abort_transaction(trans, ret); |
1626 | goto fail; | 1627 | goto fail; |
1627 | } | 1628 | } |
1628 | 1629 | ||
@@ -1632,13 +1633,13 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1632 | current_fs_time(parent_inode->i_sb); | 1633 | current_fs_time(parent_inode->i_sb); |
1633 | ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode); | 1634 | ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode); |
1634 | if (ret) { | 1635 | if (ret) { |
1635 | btrfs_abort_transaction(trans, root, ret); | 1636 | btrfs_abort_transaction(trans, ret); |
1636 | goto fail; | 1637 | goto fail; |
1637 | } | 1638 | } |
1638 | ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root, new_uuid.b, | 1639 | ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root, new_uuid.b, |
1639 | BTRFS_UUID_KEY_SUBVOL, objectid); | 1640 | BTRFS_UUID_KEY_SUBVOL, objectid); |
1640 | if (ret) { | 1641 | if (ret) { |
1641 | btrfs_abort_transaction(trans, root, ret); | 1642 | btrfs_abort_transaction(trans, ret); |
1642 | goto fail; | 1643 | goto fail; |
1643 | } | 1644 | } |
1644 | if (!btrfs_is_empty_uuid(new_root_item->received_uuid)) { | 1645 | if (!btrfs_is_empty_uuid(new_root_item->received_uuid)) { |
@@ -1647,14 +1648,14 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1647 | BTRFS_UUID_KEY_RECEIVED_SUBVOL, | 1648 | BTRFS_UUID_KEY_RECEIVED_SUBVOL, |
1648 | objectid); | 1649 | objectid); |
1649 | if (ret && ret != -EEXIST) { | 1650 | if (ret && ret != -EEXIST) { |
1650 | btrfs_abort_transaction(trans, root, ret); | 1651 | btrfs_abort_transaction(trans, ret); |
1651 | goto fail; | 1652 | goto fail; |
1652 | } | 1653 | } |
1653 | } | 1654 | } |
1654 | 1655 | ||
1655 | ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); | 1656 | ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); |
1656 | if (ret) { | 1657 | if (ret) { |
1657 | btrfs_abort_transaction(trans, root, ret); | 1658 | btrfs_abort_transaction(trans, ret); |
1658 | goto fail; | 1659 | goto fail; |
1659 | } | 1660 | } |
1660 | 1661 | ||
@@ -1709,7 +1710,7 @@ static void update_super_roots(struct btrfs_root *root) | |||
1709 | super->root = root_item->bytenr; | 1710 | super->root = root_item->bytenr; |
1710 | super->generation = root_item->generation; | 1711 | super->generation = root_item->generation; |
1711 | super->root_level = root_item->level; | 1712 | super->root_level = root_item->level; |
1712 | if (btrfs_test_opt(root, SPACE_CACHE)) | 1713 | if (btrfs_test_opt(root->fs_info, SPACE_CACHE)) |
1713 | super->cache_generation = root_item->generation; | 1714 | super->cache_generation = root_item->generation; |
1714 | if (root->fs_info->update_uuid_tree_gen) | 1715 | if (root->fs_info->update_uuid_tree_gen) |
1715 | super->uuid_tree_generation = root_item->generation; | 1716 | super->uuid_tree_generation = root_item->generation; |
@@ -1850,7 +1851,7 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans, | |||
1850 | 1851 | ||
1851 | WARN_ON(trans->use_count > 1); | 1852 | WARN_ON(trans->use_count > 1); |
1852 | 1853 | ||
1853 | btrfs_abort_transaction(trans, root, err); | 1854 | btrfs_abort_transaction(trans, err); |
1854 | 1855 | ||
1855 | spin_lock(&root->fs_info->trans_lock); | 1856 | spin_lock(&root->fs_info->trans_lock); |
1856 | 1857 | ||
@@ -1895,14 +1896,14 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans, | |||
1895 | 1896 | ||
1896 | static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info) | 1897 | static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info) |
1897 | { | 1898 | { |
1898 | if (btrfs_test_opt(fs_info->tree_root, FLUSHONCOMMIT)) | 1899 | if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) |
1899 | return btrfs_start_delalloc_roots(fs_info, 1, -1); | 1900 | return btrfs_start_delalloc_roots(fs_info, 1, -1); |
1900 | return 0; | 1901 | return 0; |
1901 | } | 1902 | } |
1902 | 1903 | ||
1903 | static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info) | 1904 | static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info) |
1904 | { | 1905 | { |
1905 | if (btrfs_test_opt(fs_info->tree_root, FLUSHONCOMMIT)) | 1906 | if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) |
1906 | btrfs_wait_ordered_roots(fs_info, -1, 0, (u64)-1); | 1907 | btrfs_wait_ordered_roots(fs_info, -1, 0, (u64)-1); |
1907 | } | 1908 | } |
1908 | 1909 | ||
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index c5abee4f01ad..efb122643380 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h | |||
@@ -128,6 +128,7 @@ struct btrfs_trans_handle { | |||
128 | * Subvolume quota depends on this | 128 | * Subvolume quota depends on this |
129 | */ | 129 | */ |
130 | struct btrfs_root *root; | 130 | struct btrfs_root *root; |
131 | struct btrfs_fs_info *fs_info; | ||
131 | struct seq_list delayed_ref_elem; | 132 | struct seq_list delayed_ref_elem; |
132 | struct list_head qgroup_ref_list; | 133 | struct list_head qgroup_ref_list; |
133 | struct list_head new_bgs; | 134 | struct list_head new_bgs; |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index c05f69a8ec42..d31a0c4f56be 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -2757,7 +2757,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2757 | while (1) { | 2757 | while (1) { |
2758 | int batch = atomic_read(&root->log_batch); | 2758 | int batch = atomic_read(&root->log_batch); |
2759 | /* when we're on an ssd, just kick the log commit out */ | 2759 | /* when we're on an ssd, just kick the log commit out */ |
2760 | if (!btrfs_test_opt(root, SSD) && | 2760 | if (!btrfs_test_opt(root->fs_info, SSD) && |
2761 | test_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state)) { | 2761 | test_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state)) { |
2762 | mutex_unlock(&root->log_mutex); | 2762 | mutex_unlock(&root->log_mutex); |
2763 | schedule_timeout_uninterruptible(1); | 2763 | schedule_timeout_uninterruptible(1); |
@@ -2788,7 +2788,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2788 | ret = btrfs_write_marked_extents(log, &log->dirty_log_pages, mark); | 2788 | ret = btrfs_write_marked_extents(log, &log->dirty_log_pages, mark); |
2789 | if (ret) { | 2789 | if (ret) { |
2790 | blk_finish_plug(&plug); | 2790 | blk_finish_plug(&plug); |
2791 | btrfs_abort_transaction(trans, root, ret); | 2791 | btrfs_abort_transaction(trans, ret); |
2792 | btrfs_free_logged_extents(log, log_transid); | 2792 | btrfs_free_logged_extents(log, log_transid); |
2793 | btrfs_set_log_full_commit(root->fs_info, trans); | 2793 | btrfs_set_log_full_commit(root->fs_info, trans); |
2794 | mutex_unlock(&root->log_mutex); | 2794 | mutex_unlock(&root->log_mutex); |
@@ -2838,7 +2838,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2838 | btrfs_set_log_full_commit(root->fs_info, trans); | 2838 | btrfs_set_log_full_commit(root->fs_info, trans); |
2839 | 2839 | ||
2840 | if (ret != -ENOSPC) { | 2840 | if (ret != -ENOSPC) { |
2841 | btrfs_abort_transaction(trans, root, ret); | 2841 | btrfs_abort_transaction(trans, ret); |
2842 | mutex_unlock(&log_root_tree->log_mutex); | 2842 | mutex_unlock(&log_root_tree->log_mutex); |
2843 | goto out; | 2843 | goto out; |
2844 | } | 2844 | } |
@@ -2898,7 +2898,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2898 | blk_finish_plug(&plug); | 2898 | blk_finish_plug(&plug); |
2899 | if (ret) { | 2899 | if (ret) { |
2900 | btrfs_set_log_full_commit(root->fs_info, trans); | 2900 | btrfs_set_log_full_commit(root->fs_info, trans); |
2901 | btrfs_abort_transaction(trans, root, ret); | 2901 | btrfs_abort_transaction(trans, ret); |
2902 | btrfs_free_logged_extents(log, log_transid); | 2902 | btrfs_free_logged_extents(log, log_transid); |
2903 | mutex_unlock(&log_root_tree->log_mutex); | 2903 | mutex_unlock(&log_root_tree->log_mutex); |
2904 | goto out_wake_log_root; | 2904 | goto out_wake_log_root; |
@@ -2934,7 +2934,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2934 | ret = write_ctree_super(trans, root->fs_info->tree_root, 1); | 2934 | ret = write_ctree_super(trans, root->fs_info->tree_root, 1); |
2935 | if (ret) { | 2935 | if (ret) { |
2936 | btrfs_set_log_full_commit(root->fs_info, trans); | 2936 | btrfs_set_log_full_commit(root->fs_info, trans); |
2937 | btrfs_abort_transaction(trans, root, ret); | 2937 | btrfs_abort_transaction(trans, ret); |
2938 | goto out_wake_log_root; | 2938 | goto out_wake_log_root; |
2939 | } | 2939 | } |
2940 | 2940 | ||
@@ -2991,7 +2991,7 @@ static void free_log_tree(struct btrfs_trans_handle *trans, | |||
2991 | ret = walk_log_tree(trans, log, &wc); | 2991 | ret = walk_log_tree(trans, log, &wc); |
2992 | /* I don't think this can happen but just in case */ | 2992 | /* I don't think this can happen but just in case */ |
2993 | if (ret) | 2993 | if (ret) |
2994 | btrfs_abort_transaction(trans, log, ret); | 2994 | btrfs_abort_transaction(trans, ret); |
2995 | 2995 | ||
2996 | while (1) { | 2996 | while (1) { |
2997 | ret = find_first_extent_bit(&log->dirty_log_pages, | 2997 | ret = find_first_extent_bit(&log->dirty_log_pages, |
@@ -3160,7 +3160,7 @@ out_unlock: | |||
3160 | btrfs_set_log_full_commit(root->fs_info, trans); | 3160 | btrfs_set_log_full_commit(root->fs_info, trans); |
3161 | ret = 0; | 3161 | ret = 0; |
3162 | } else if (ret < 0) | 3162 | } else if (ret < 0) |
3163 | btrfs_abort_transaction(trans, root, ret); | 3163 | btrfs_abort_transaction(trans, ret); |
3164 | 3164 | ||
3165 | btrfs_end_log_trans(root); | 3165 | btrfs_end_log_trans(root); |
3166 | 3166 | ||
@@ -3193,7 +3193,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, | |||
3193 | btrfs_set_log_full_commit(root->fs_info, trans); | 3193 | btrfs_set_log_full_commit(root->fs_info, trans); |
3194 | ret = 0; | 3194 | ret = 0; |
3195 | } else if (ret < 0 && ret != -ENOENT) | 3195 | } else if (ret < 0 && ret != -ENOENT) |
3196 | btrfs_abort_transaction(trans, root, ret); | 3196 | btrfs_abort_transaction(trans, ret); |
3197 | btrfs_end_log_trans(root); | 3197 | btrfs_end_log_trans(root); |
3198 | 3198 | ||
3199 | return ret; | 3199 | return ret; |
@@ -4703,6 +4703,10 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, | |||
4703 | ins_nr = 0; | 4703 | ins_nr = 0; |
4704 | ret = btrfs_search_forward(root, &min_key, | 4704 | ret = btrfs_search_forward(root, &min_key, |
4705 | path, trans->transid); | 4705 | path, trans->transid); |
4706 | if (ret < 0) { | ||
4707 | err = ret; | ||
4708 | goto out_unlock; | ||
4709 | } | ||
4706 | if (ret != 0) | 4710 | if (ret != 0) |
4707 | break; | 4711 | break; |
4708 | again: | 4712 | again: |
@@ -5301,7 +5305,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | |||
5301 | 5305 | ||
5302 | sb = inode->i_sb; | 5306 | sb = inode->i_sb; |
5303 | 5307 | ||
5304 | if (btrfs_test_opt(root, NOTREELOG)) { | 5308 | if (btrfs_test_opt(root->fs_info, NOTREELOG)) { |
5305 | ret = 1; | 5309 | ret = 1; |
5306 | goto end_no_trans; | 5310 | goto end_no_trans; |
5307 | } | 5311 | } |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 589f128173b1..e217035d63df 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -140,7 +140,6 @@ static int btrfs_relocate_sys_chunks(struct btrfs_root *root); | |||
140 | static void __btrfs_reset_dev_stats(struct btrfs_device *dev); | 140 | static void __btrfs_reset_dev_stats(struct btrfs_device *dev); |
141 | static void btrfs_dev_stat_print_on_error(struct btrfs_device *dev); | 141 | static void btrfs_dev_stat_print_on_error(struct btrfs_device *dev); |
142 | static void btrfs_dev_stat_print_on_load(struct btrfs_device *device); | 142 | static void btrfs_dev_stat_print_on_load(struct btrfs_device *device); |
143 | static void btrfs_close_one_device(struct btrfs_device *device); | ||
144 | 143 | ||
145 | DEFINE_MUTEX(uuid_mutex); | 144 | DEFINE_MUTEX(uuid_mutex); |
146 | static LIST_HEAD(fs_uuids); | 145 | static LIST_HEAD(fs_uuids); |
@@ -853,6 +852,46 @@ static void free_device(struct rcu_head *head) | |||
853 | schedule_work(&device->rcu_work); | 852 | schedule_work(&device->rcu_work); |
854 | } | 853 | } |
855 | 854 | ||
855 | static void btrfs_close_one_device(struct btrfs_device *device) | ||
856 | { | ||
857 | struct btrfs_fs_devices *fs_devices = device->fs_devices; | ||
858 | struct btrfs_device *new_device; | ||
859 | struct rcu_string *name; | ||
860 | |||
861 | if (device->bdev) | ||
862 | fs_devices->open_devices--; | ||
863 | |||
864 | if (device->writeable && | ||
865 | device->devid != BTRFS_DEV_REPLACE_DEVID) { | ||
866 | list_del_init(&device->dev_alloc_list); | ||
867 | fs_devices->rw_devices--; | ||
868 | } | ||
869 | |||
870 | if (device->missing) | ||
871 | fs_devices->missing_devices--; | ||
872 | |||
873 | if (device->bdev && device->writeable) { | ||
874 | sync_blockdev(device->bdev); | ||
875 | invalidate_bdev(device->bdev); | ||
876 | } | ||
877 | |||
878 | new_device = btrfs_alloc_device(NULL, &device->devid, | ||
879 | device->uuid); | ||
880 | BUG_ON(IS_ERR(new_device)); /* -ENOMEM */ | ||
881 | |||
882 | /* Safe because we are under uuid_mutex */ | ||
883 | if (device->name) { | ||
884 | name = rcu_string_strdup(device->name->str, GFP_NOFS); | ||
885 | BUG_ON(!name); /* -ENOMEM */ | ||
886 | rcu_assign_pointer(new_device->name, name); | ||
887 | } | ||
888 | |||
889 | list_replace_rcu(&device->dev_list, &new_device->dev_list); | ||
890 | new_device->fs_devices = device->fs_devices; | ||
891 | |||
892 | call_rcu(&device->rcu, free_device); | ||
893 | } | ||
894 | |||
856 | static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) | 895 | static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) |
857 | { | 896 | { |
858 | struct btrfs_device *device, *tmp; | 897 | struct btrfs_device *device, *tmp; |
@@ -2399,14 +2438,14 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) | |||
2399 | ret = init_first_rw_device(trans, root, device); | 2438 | ret = init_first_rw_device(trans, root, device); |
2400 | unlock_chunks(root); | 2439 | unlock_chunks(root); |
2401 | if (ret) { | 2440 | if (ret) { |
2402 | btrfs_abort_transaction(trans, root, ret); | 2441 | btrfs_abort_transaction(trans, ret); |
2403 | goto error_trans; | 2442 | goto error_trans; |
2404 | } | 2443 | } |
2405 | } | 2444 | } |
2406 | 2445 | ||
2407 | ret = btrfs_add_device(trans, root, device); | 2446 | ret = btrfs_add_device(trans, root, device); |
2408 | if (ret) { | 2447 | if (ret) { |
2409 | btrfs_abort_transaction(trans, root, ret); | 2448 | btrfs_abort_transaction(trans, ret); |
2410 | goto error_trans; | 2449 | goto error_trans; |
2411 | } | 2450 | } |
2412 | 2451 | ||
@@ -2415,7 +2454,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) | |||
2415 | 2454 | ||
2416 | ret = btrfs_finish_sprout(trans, root); | 2455 | ret = btrfs_finish_sprout(trans, root); |
2417 | if (ret) { | 2456 | if (ret) { |
2418 | btrfs_abort_transaction(trans, root, ret); | 2457 | btrfs_abort_transaction(trans, ret); |
2419 | goto error_trans; | 2458 | goto error_trans; |
2420 | } | 2459 | } |
2421 | 2460 | ||
@@ -2801,7 +2840,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, | |||
2801 | &dev_extent_len); | 2840 | &dev_extent_len); |
2802 | if (ret) { | 2841 | if (ret) { |
2803 | mutex_unlock(&fs_devices->device_list_mutex); | 2842 | mutex_unlock(&fs_devices->device_list_mutex); |
2804 | btrfs_abort_transaction(trans, root, ret); | 2843 | btrfs_abort_transaction(trans, ret); |
2805 | goto out; | 2844 | goto out; |
2806 | } | 2845 | } |
2807 | 2846 | ||
@@ -2820,7 +2859,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, | |||
2820 | ret = btrfs_update_device(trans, map->stripes[i].dev); | 2859 | ret = btrfs_update_device(trans, map->stripes[i].dev); |
2821 | if (ret) { | 2860 | if (ret) { |
2822 | mutex_unlock(&fs_devices->device_list_mutex); | 2861 | mutex_unlock(&fs_devices->device_list_mutex); |
2823 | btrfs_abort_transaction(trans, root, ret); | 2862 | btrfs_abort_transaction(trans, ret); |
2824 | goto out; | 2863 | goto out; |
2825 | } | 2864 | } |
2826 | } | 2865 | } |
@@ -2829,7 +2868,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, | |||
2829 | 2868 | ||
2830 | ret = btrfs_free_chunk(trans, root, chunk_objectid, chunk_offset); | 2869 | ret = btrfs_free_chunk(trans, root, chunk_objectid, chunk_offset); |
2831 | if (ret) { | 2870 | if (ret) { |
2832 | btrfs_abort_transaction(trans, root, ret); | 2871 | btrfs_abort_transaction(trans, ret); |
2833 | goto out; | 2872 | goto out; |
2834 | } | 2873 | } |
2835 | 2874 | ||
@@ -2838,14 +2877,14 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, | |||
2838 | if (map->type & BTRFS_BLOCK_GROUP_SYSTEM) { | 2877 | if (map->type & BTRFS_BLOCK_GROUP_SYSTEM) { |
2839 | ret = btrfs_del_sys_chunk(root, chunk_objectid, chunk_offset); | 2878 | ret = btrfs_del_sys_chunk(root, chunk_objectid, chunk_offset); |
2840 | if (ret) { | 2879 | if (ret) { |
2841 | btrfs_abort_transaction(trans, root, ret); | 2880 | btrfs_abort_transaction(trans, ret); |
2842 | goto out; | 2881 | goto out; |
2843 | } | 2882 | } |
2844 | } | 2883 | } |
2845 | 2884 | ||
2846 | ret = btrfs_remove_block_group(trans, extent_root, chunk_offset, em); | 2885 | ret = btrfs_remove_block_group(trans, extent_root, chunk_offset, em); |
2847 | if (ret) { | 2886 | if (ret) { |
2848 | btrfs_abort_transaction(trans, extent_root, ret); | 2887 | btrfs_abort_transaction(trans, ret); |
2849 | goto out; | 2888 | goto out; |
2850 | } | 2889 | } |
2851 | 2890 | ||
@@ -2902,7 +2941,7 @@ static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset) | |||
2902 | * chunk tree entries | 2941 | * chunk tree entries |
2903 | */ | 2942 | */ |
2904 | ret = btrfs_remove_chunk(trans, root, chunk_offset); | 2943 | ret = btrfs_remove_chunk(trans, root, chunk_offset); |
2905 | btrfs_end_transaction(trans, root); | 2944 | btrfs_end_transaction(trans, extent_root); |
2906 | return ret; | 2945 | return ret; |
2907 | } | 2946 | } |
2908 | 2947 | ||
@@ -3421,7 +3460,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) | |||
3421 | u64 size_to_free; | 3460 | u64 size_to_free; |
3422 | u64 chunk_type; | 3461 | u64 chunk_type; |
3423 | struct btrfs_chunk *chunk; | 3462 | struct btrfs_chunk *chunk; |
3424 | struct btrfs_path *path; | 3463 | struct btrfs_path *path = NULL; |
3425 | struct btrfs_key key; | 3464 | struct btrfs_key key; |
3426 | struct btrfs_key found_key; | 3465 | struct btrfs_key found_key; |
3427 | struct btrfs_trans_handle *trans; | 3466 | struct btrfs_trans_handle *trans; |
@@ -3455,13 +3494,33 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) | |||
3455 | ret = btrfs_shrink_device(device, old_size - size_to_free); | 3494 | ret = btrfs_shrink_device(device, old_size - size_to_free); |
3456 | if (ret == -ENOSPC) | 3495 | if (ret == -ENOSPC) |
3457 | break; | 3496 | break; |
3458 | BUG_ON(ret); | 3497 | if (ret) { |
3498 | /* btrfs_shrink_device never returns ret > 0 */ | ||
3499 | WARN_ON(ret > 0); | ||
3500 | goto error; | ||
3501 | } | ||
3459 | 3502 | ||
3460 | trans = btrfs_start_transaction(dev_root, 0); | 3503 | trans = btrfs_start_transaction(dev_root, 0); |
3461 | BUG_ON(IS_ERR(trans)); | 3504 | if (IS_ERR(trans)) { |
3505 | ret = PTR_ERR(trans); | ||
3506 | btrfs_info_in_rcu(fs_info, | ||
3507 | "resize: unable to start transaction after shrinking device %s (error %d), old size %llu, new size %llu", | ||
3508 | rcu_str_deref(device->name), ret, | ||
3509 | old_size, old_size - size_to_free); | ||
3510 | goto error; | ||
3511 | } | ||
3462 | 3512 | ||
3463 | ret = btrfs_grow_device(trans, device, old_size); | 3513 | ret = btrfs_grow_device(trans, device, old_size); |
3464 | BUG_ON(ret); | 3514 | if (ret) { |
3515 | btrfs_end_transaction(trans, dev_root); | ||
3516 | /* btrfs_grow_device never returns ret > 0 */ | ||
3517 | WARN_ON(ret > 0); | ||
3518 | btrfs_info_in_rcu(fs_info, | ||
3519 | "resize: unable to grow device after shrinking device %s (error %d), old size %llu, new size %llu", | ||
3520 | rcu_str_deref(device->name), ret, | ||
3521 | old_size, old_size - size_to_free); | ||
3522 | goto error; | ||
3523 | } | ||
3465 | 3524 | ||
3466 | btrfs_end_transaction(trans, dev_root); | 3525 | btrfs_end_transaction(trans, dev_root); |
3467 | } | 3526 | } |
@@ -3885,7 +3944,7 @@ int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info) | |||
3885 | } | 3944 | } |
3886 | spin_unlock(&fs_info->balance_lock); | 3945 | spin_unlock(&fs_info->balance_lock); |
3887 | 3946 | ||
3888 | if (btrfs_test_opt(fs_info->tree_root, SKIP_BALANCE)) { | 3947 | if (btrfs_test_opt(fs_info, SKIP_BALANCE)) { |
3889 | btrfs_info(fs_info, "force skipping balance"); | 3948 | btrfs_info(fs_info, "force skipping balance"); |
3890 | return 0; | 3949 | return 0; |
3891 | } | 3950 | } |
@@ -4240,7 +4299,7 @@ int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info) | |||
4240 | BTRFS_UUID_TREE_OBJECTID); | 4299 | BTRFS_UUID_TREE_OBJECTID); |
4241 | if (IS_ERR(uuid_root)) { | 4300 | if (IS_ERR(uuid_root)) { |
4242 | ret = PTR_ERR(uuid_root); | 4301 | ret = PTR_ERR(uuid_root); |
4243 | btrfs_abort_transaction(trans, tree_root, ret); | 4302 | btrfs_abort_transaction(trans, ret); |
4244 | btrfs_end_transaction(trans, tree_root); | 4303 | btrfs_end_transaction(trans, tree_root); |
4245 | return ret; | 4304 | return ret; |
4246 | } | 4305 | } |
@@ -4514,8 +4573,7 @@ static void check_raid56_incompat_flag(struct btrfs_fs_info *info, u64 type) | |||
4514 | btrfs_set_fs_incompat(info, RAID56); | 4573 | btrfs_set_fs_incompat(info, RAID56); |
4515 | } | 4574 | } |
4516 | 4575 | ||
4517 | #define BTRFS_MAX_DEVS(r) ((BTRFS_LEAF_DATA_SIZE(r) \ | 4576 | #define BTRFS_MAX_DEVS(r) ((BTRFS_MAX_ITEM_SIZE(r) \ |
4518 | - sizeof(struct btrfs_item) \ | ||
4519 | - sizeof(struct btrfs_chunk)) \ | 4577 | - sizeof(struct btrfs_chunk)) \ |
4520 | / sizeof(struct btrfs_stripe) + 1) | 4578 | / sizeof(struct btrfs_stripe) + 1) |
4521 | 4579 | ||
@@ -6396,7 +6454,8 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, | |||
6396 | BTRFS_UUID_SIZE); | 6454 | BTRFS_UUID_SIZE); |
6397 | map->stripes[i].dev = btrfs_find_device(root->fs_info, devid, | 6455 | map->stripes[i].dev = btrfs_find_device(root->fs_info, devid, |
6398 | uuid, NULL); | 6456 | uuid, NULL); |
6399 | if (!map->stripes[i].dev && !btrfs_test_opt(root, DEGRADED)) { | 6457 | if (!map->stripes[i].dev && |
6458 | !btrfs_test_opt(root->fs_info, DEGRADED)) { | ||
6400 | free_extent_map(em); | 6459 | free_extent_map(em); |
6401 | return -EIO; | 6460 | return -EIO; |
6402 | } | 6461 | } |
@@ -6464,7 +6523,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_root *root, | |||
6464 | 6523 | ||
6465 | fs_devices = find_fsid(fsid); | 6524 | fs_devices = find_fsid(fsid); |
6466 | if (!fs_devices) { | 6525 | if (!fs_devices) { |
6467 | if (!btrfs_test_opt(root, DEGRADED)) | 6526 | if (!btrfs_test_opt(root->fs_info, DEGRADED)) |
6468 | return ERR_PTR(-ENOENT); | 6527 | return ERR_PTR(-ENOENT); |
6469 | 6528 | ||
6470 | fs_devices = alloc_fs_devices(fsid); | 6529 | fs_devices = alloc_fs_devices(fsid); |
@@ -6526,7 +6585,7 @@ static int read_one_dev(struct btrfs_root *root, | |||
6526 | 6585 | ||
6527 | device = btrfs_find_device(root->fs_info, devid, dev_uuid, fs_uuid); | 6586 | device = btrfs_find_device(root->fs_info, devid, dev_uuid, fs_uuid); |
6528 | if (!device) { | 6587 | if (!device) { |
6529 | if (!btrfs_test_opt(root, DEGRADED)) | 6588 | if (!btrfs_test_opt(root->fs_info, DEGRADED)) |
6530 | return -EIO; | 6589 | return -EIO; |
6531 | 6590 | ||
6532 | device = add_missing_dev(root, fs_devices, devid, dev_uuid); | 6591 | device = add_missing_dev(root, fs_devices, devid, dev_uuid); |
@@ -6535,7 +6594,7 @@ static int read_one_dev(struct btrfs_root *root, | |||
6535 | btrfs_warn(root->fs_info, "devid %llu uuid %pU missing", | 6594 | btrfs_warn(root->fs_info, "devid %llu uuid %pU missing", |
6536 | devid, dev_uuid); | 6595 | devid, dev_uuid); |
6537 | } else { | 6596 | } else { |
6538 | if (!device->bdev && !btrfs_test_opt(root, DEGRADED)) | 6597 | if (!device->bdev && !btrfs_test_opt(root->fs_info, DEGRADED)) |
6539 | return -EIO; | 6598 | return -EIO; |
6540 | 6599 | ||
6541 | if(!device->bdev && !device->missing) { | 6600 | if(!device->bdev && !device->missing) { |
@@ -7138,38 +7197,3 @@ void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info) | |||
7138 | fs_devices = fs_devices->seed; | 7197 | fs_devices = fs_devices->seed; |
7139 | } | 7198 | } |
7140 | } | 7199 | } |
7141 | |||
7142 | static void btrfs_close_one_device(struct btrfs_device *device) | ||
7143 | { | ||
7144 | struct btrfs_fs_devices *fs_devices = device->fs_devices; | ||
7145 | struct btrfs_device *new_device; | ||
7146 | struct rcu_string *name; | ||
7147 | |||
7148 | if (device->bdev) | ||
7149 | fs_devices->open_devices--; | ||
7150 | |||
7151 | if (device->writeable && | ||
7152 | device->devid != BTRFS_DEV_REPLACE_DEVID) { | ||
7153 | list_del_init(&device->dev_alloc_list); | ||
7154 | fs_devices->rw_devices--; | ||
7155 | } | ||
7156 | |||
7157 | if (device->missing) | ||
7158 | fs_devices->missing_devices--; | ||
7159 | |||
7160 | new_device = btrfs_alloc_device(NULL, &device->devid, | ||
7161 | device->uuid); | ||
7162 | BUG_ON(IS_ERR(new_device)); /* -ENOMEM */ | ||
7163 | |||
7164 | /* Safe because we are under uuid_mutex */ | ||
7165 | if (device->name) { | ||
7166 | name = rcu_string_strdup(device->name->str, GFP_NOFS); | ||
7167 | BUG_ON(!name); /* -ENOMEM */ | ||
7168 | rcu_assign_pointer(new_device->name, name); | ||
7169 | } | ||
7170 | |||
7171 | list_replace_rcu(&device->dev_list, &new_device->dev_list); | ||
7172 | new_device->fs_devices = device->fs_devices; | ||
7173 | |||
7174 | call_rcu(&device->rcu, free_device); | ||
7175 | } | ||
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index 5b81ef304388..e030d6f6c19a 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h | |||
@@ -66,6 +66,21 @@ struct btrfs_qgroup_extent_record; | |||
66 | { BTRFS_BLOCK_GROUP_RAID6, "RAID6"} | 66 | { BTRFS_BLOCK_GROUP_RAID6, "RAID6"} |
67 | 67 | ||
68 | #define BTRFS_UUID_SIZE 16 | 68 | #define BTRFS_UUID_SIZE 16 |
69 | #define TP_STRUCT__entry_fsid __array(u8, fsid, BTRFS_UUID_SIZE) | ||
70 | |||
71 | #define TP_fast_assign_fsid(fs_info) \ | ||
72 | memcpy(__entry->fsid, fs_info->fsid, BTRFS_UUID_SIZE) | ||
73 | |||
74 | #define TP_STRUCT__entry_btrfs(args...) \ | ||
75 | TP_STRUCT__entry( \ | ||
76 | TP_STRUCT__entry_fsid \ | ||
77 | args) | ||
78 | #define TP_fast_assign_btrfs(fs_info, args...) \ | ||
79 | TP_fast_assign( \ | ||
80 | TP_fast_assign_fsid(fs_info); \ | ||
81 | args) | ||
82 | #define TP_printk_btrfs(fmt, args...) \ | ||
83 | TP_printk("%pU: " fmt, __entry->fsid, args) | ||
69 | 84 | ||
70 | TRACE_EVENT(btrfs_transaction_commit, | 85 | TRACE_EVENT(btrfs_transaction_commit, |
71 | 86 | ||
@@ -73,17 +88,17 @@ TRACE_EVENT(btrfs_transaction_commit, | |||
73 | 88 | ||
74 | TP_ARGS(root), | 89 | TP_ARGS(root), |
75 | 90 | ||
76 | TP_STRUCT__entry( | 91 | TP_STRUCT__entry_btrfs( |
77 | __field( u64, generation ) | 92 | __field( u64, generation ) |
78 | __field( u64, root_objectid ) | 93 | __field( u64, root_objectid ) |
79 | ), | 94 | ), |
80 | 95 | ||
81 | TP_fast_assign( | 96 | TP_fast_assign_btrfs(root->fs_info, |
82 | __entry->generation = root->fs_info->generation; | 97 | __entry->generation = root->fs_info->generation; |
83 | __entry->root_objectid = root->root_key.objectid; | 98 | __entry->root_objectid = root->root_key.objectid; |
84 | ), | 99 | ), |
85 | 100 | ||
86 | TP_printk("root = %llu(%s), gen = %llu", | 101 | TP_printk_btrfs("root = %llu(%s), gen = %llu", |
87 | show_root_type(__entry->root_objectid), | 102 | show_root_type(__entry->root_objectid), |
88 | (unsigned long long)__entry->generation) | 103 | (unsigned long long)__entry->generation) |
89 | ); | 104 | ); |
@@ -94,7 +109,7 @@ DECLARE_EVENT_CLASS(btrfs__inode, | |||
94 | 109 | ||
95 | TP_ARGS(inode), | 110 | TP_ARGS(inode), |
96 | 111 | ||
97 | TP_STRUCT__entry( | 112 | TP_STRUCT__entry_btrfs( |
98 | __field( ino_t, ino ) | 113 | __field( ino_t, ino ) |
99 | __field( blkcnt_t, blocks ) | 114 | __field( blkcnt_t, blocks ) |
100 | __field( u64, disk_i_size ) | 115 | __field( u64, disk_i_size ) |
@@ -104,7 +119,7 @@ DECLARE_EVENT_CLASS(btrfs__inode, | |||
104 | __field( u64, root_objectid ) | 119 | __field( u64, root_objectid ) |
105 | ), | 120 | ), |
106 | 121 | ||
107 | TP_fast_assign( | 122 | TP_fast_assign_btrfs(btrfs_sb(inode->i_sb), |
108 | __entry->ino = inode->i_ino; | 123 | __entry->ino = inode->i_ino; |
109 | __entry->blocks = inode->i_blocks; | 124 | __entry->blocks = inode->i_blocks; |
110 | __entry->disk_i_size = BTRFS_I(inode)->disk_i_size; | 125 | __entry->disk_i_size = BTRFS_I(inode)->disk_i_size; |
@@ -115,7 +130,7 @@ DECLARE_EVENT_CLASS(btrfs__inode, | |||
115 | BTRFS_I(inode)->root->root_key.objectid; | 130 | BTRFS_I(inode)->root->root_key.objectid; |
116 | ), | 131 | ), |
117 | 132 | ||
118 | TP_printk("root = %llu(%s), gen = %llu, ino = %lu, blocks = %llu, " | 133 | TP_printk_btrfs("root = %llu(%s), gen = %llu, ino = %lu, blocks = %llu, " |
119 | "disk_i_size = %llu, last_trans = %llu, logged_trans = %llu", | 134 | "disk_i_size = %llu, last_trans = %llu, logged_trans = %llu", |
120 | show_root_type(__entry->root_objectid), | 135 | show_root_type(__entry->root_objectid), |
121 | (unsigned long long)__entry->generation, | 136 | (unsigned long long)__entry->generation, |
@@ -175,7 +190,7 @@ TRACE_EVENT_CONDITION(btrfs_get_extent, | |||
175 | 190 | ||
176 | TP_CONDITION(map), | 191 | TP_CONDITION(map), |
177 | 192 | ||
178 | TP_STRUCT__entry( | 193 | TP_STRUCT__entry_btrfs( |
179 | __field( u64, root_objectid ) | 194 | __field( u64, root_objectid ) |
180 | __field( u64, start ) | 195 | __field( u64, start ) |
181 | __field( u64, len ) | 196 | __field( u64, len ) |
@@ -187,7 +202,7 @@ TRACE_EVENT_CONDITION(btrfs_get_extent, | |||
187 | __field( unsigned int, compress_type ) | 202 | __field( unsigned int, compress_type ) |
188 | ), | 203 | ), |
189 | 204 | ||
190 | TP_fast_assign( | 205 | TP_fast_assign_btrfs(root->fs_info, |
191 | __entry->root_objectid = root->root_key.objectid; | 206 | __entry->root_objectid = root->root_key.objectid; |
192 | __entry->start = map->start; | 207 | __entry->start = map->start; |
193 | __entry->len = map->len; | 208 | __entry->len = map->len; |
@@ -199,7 +214,7 @@ TRACE_EVENT_CONDITION(btrfs_get_extent, | |||
199 | __entry->compress_type = map->compress_type; | 214 | __entry->compress_type = map->compress_type; |
200 | ), | 215 | ), |
201 | 216 | ||
202 | TP_printk("root = %llu(%s), start = %llu, len = %llu, " | 217 | TP_printk_btrfs("root = %llu(%s), start = %llu, len = %llu, " |
203 | "orig_start = %llu, block_start = %llu(%s), " | 218 | "orig_start = %llu, block_start = %llu(%s), " |
204 | "block_len = %llu, flags = %s, refs = %u, " | 219 | "block_len = %llu, flags = %s, refs = %u, " |
205 | "compress_type = %u", | 220 | "compress_type = %u", |
@@ -233,7 +248,7 @@ DECLARE_EVENT_CLASS(btrfs__ordered_extent, | |||
233 | 248 | ||
234 | TP_ARGS(inode, ordered), | 249 | TP_ARGS(inode, ordered), |
235 | 250 | ||
236 | TP_STRUCT__entry( | 251 | TP_STRUCT__entry_btrfs( |
237 | __field( ino_t, ino ) | 252 | __field( ino_t, ino ) |
238 | __field( u64, file_offset ) | 253 | __field( u64, file_offset ) |
239 | __field( u64, start ) | 254 | __field( u64, start ) |
@@ -246,7 +261,7 @@ DECLARE_EVENT_CLASS(btrfs__ordered_extent, | |||
246 | __field( u64, root_objectid ) | 261 | __field( u64, root_objectid ) |
247 | ), | 262 | ), |
248 | 263 | ||
249 | TP_fast_assign( | 264 | TP_fast_assign_btrfs(btrfs_sb(inode->i_sb), |
250 | __entry->ino = inode->i_ino; | 265 | __entry->ino = inode->i_ino; |
251 | __entry->file_offset = ordered->file_offset; | 266 | __entry->file_offset = ordered->file_offset; |
252 | __entry->start = ordered->start; | 267 | __entry->start = ordered->start; |
@@ -260,7 +275,7 @@ DECLARE_EVENT_CLASS(btrfs__ordered_extent, | |||
260 | BTRFS_I(inode)->root->root_key.objectid; | 275 | BTRFS_I(inode)->root->root_key.objectid; |
261 | ), | 276 | ), |
262 | 277 | ||
263 | TP_printk("root = %llu(%s), ino = %llu, file_offset = %llu, " | 278 | TP_printk_btrfs("root = %llu(%s), ino = %llu, file_offset = %llu, " |
264 | "start = %llu, len = %llu, disk_len = %llu, " | 279 | "start = %llu, len = %llu, disk_len = %llu, " |
265 | "bytes_left = %llu, flags = %s, compress_type = %d, " | 280 | "bytes_left = %llu, flags = %s, compress_type = %d, " |
266 | "refs = %d", | 281 | "refs = %d", |
@@ -310,7 +325,7 @@ DECLARE_EVENT_CLASS(btrfs__writepage, | |||
310 | 325 | ||
311 | TP_ARGS(page, inode, wbc), | 326 | TP_ARGS(page, inode, wbc), |
312 | 327 | ||
313 | TP_STRUCT__entry( | 328 | TP_STRUCT__entry_btrfs( |
314 | __field( ino_t, ino ) | 329 | __field( ino_t, ino ) |
315 | __field( pgoff_t, index ) | 330 | __field( pgoff_t, index ) |
316 | __field( long, nr_to_write ) | 331 | __field( long, nr_to_write ) |
@@ -324,7 +339,7 @@ DECLARE_EVENT_CLASS(btrfs__writepage, | |||
324 | __field( u64, root_objectid ) | 339 | __field( u64, root_objectid ) |
325 | ), | 340 | ), |
326 | 341 | ||
327 | TP_fast_assign( | 342 | TP_fast_assign_btrfs(btrfs_sb(inode->i_sb), |
328 | __entry->ino = inode->i_ino; | 343 | __entry->ino = inode->i_ino; |
329 | __entry->index = page->index; | 344 | __entry->index = page->index; |
330 | __entry->nr_to_write = wbc->nr_to_write; | 345 | __entry->nr_to_write = wbc->nr_to_write; |
@@ -339,7 +354,7 @@ DECLARE_EVENT_CLASS(btrfs__writepage, | |||
339 | BTRFS_I(inode)->root->root_key.objectid; | 354 | BTRFS_I(inode)->root->root_key.objectid; |
340 | ), | 355 | ), |
341 | 356 | ||
342 | TP_printk("root = %llu(%s), ino = %lu, page_index = %lu, " | 357 | TP_printk_btrfs("root = %llu(%s), ino = %lu, page_index = %lu, " |
343 | "nr_to_write = %ld, pages_skipped = %ld, range_start = %llu, " | 358 | "nr_to_write = %ld, pages_skipped = %ld, range_start = %llu, " |
344 | "range_end = %llu, for_kupdate = %d, " | 359 | "range_end = %llu, for_kupdate = %d, " |
345 | "for_reclaim = %d, range_cyclic = %d, writeback_index = %lu", | 360 | "for_reclaim = %d, range_cyclic = %d, writeback_index = %lu", |
@@ -366,7 +381,7 @@ TRACE_EVENT(btrfs_writepage_end_io_hook, | |||
366 | 381 | ||
367 | TP_ARGS(page, start, end, uptodate), | 382 | TP_ARGS(page, start, end, uptodate), |
368 | 383 | ||
369 | TP_STRUCT__entry( | 384 | TP_STRUCT__entry_btrfs( |
370 | __field( ino_t, ino ) | 385 | __field( ino_t, ino ) |
371 | __field( pgoff_t, index ) | 386 | __field( pgoff_t, index ) |
372 | __field( u64, start ) | 387 | __field( u64, start ) |
@@ -375,7 +390,7 @@ TRACE_EVENT(btrfs_writepage_end_io_hook, | |||
375 | __field( u64, root_objectid ) | 390 | __field( u64, root_objectid ) |
376 | ), | 391 | ), |
377 | 392 | ||
378 | TP_fast_assign( | 393 | TP_fast_assign_btrfs(btrfs_sb(page->mapping->host->i_sb), |
379 | __entry->ino = page->mapping->host->i_ino; | 394 | __entry->ino = page->mapping->host->i_ino; |
380 | __entry->index = page->index; | 395 | __entry->index = page->index; |
381 | __entry->start = start; | 396 | __entry->start = start; |
@@ -385,7 +400,7 @@ TRACE_EVENT(btrfs_writepage_end_io_hook, | |||
385 | BTRFS_I(page->mapping->host)->root->root_key.objectid; | 400 | BTRFS_I(page->mapping->host)->root->root_key.objectid; |
386 | ), | 401 | ), |
387 | 402 | ||
388 | TP_printk("root = %llu(%s), ino = %lu, page_index = %lu, start = %llu, " | 403 | TP_printk_btrfs("root = %llu(%s), ino = %lu, page_index = %lu, start = %llu, " |
389 | "end = %llu, uptodate = %d", | 404 | "end = %llu, uptodate = %d", |
390 | show_root_type(__entry->root_objectid), | 405 | show_root_type(__entry->root_objectid), |
391 | (unsigned long)__entry->ino, (unsigned long)__entry->index, | 406 | (unsigned long)__entry->ino, (unsigned long)__entry->index, |
@@ -399,7 +414,7 @@ TRACE_EVENT(btrfs_sync_file, | |||
399 | 414 | ||
400 | TP_ARGS(file, datasync), | 415 | TP_ARGS(file, datasync), |
401 | 416 | ||
402 | TP_STRUCT__entry( | 417 | TP_STRUCT__entry_btrfs( |
403 | __field( ino_t, ino ) | 418 | __field( ino_t, ino ) |
404 | __field( ino_t, parent ) | 419 | __field( ino_t, parent ) |
405 | __field( int, datasync ) | 420 | __field( int, datasync ) |
@@ -410,6 +425,7 @@ TRACE_EVENT(btrfs_sync_file, | |||
410 | struct dentry *dentry = file->f_path.dentry; | 425 | struct dentry *dentry = file->f_path.dentry; |
411 | struct inode *inode = d_inode(dentry); | 426 | struct inode *inode = d_inode(dentry); |
412 | 427 | ||
428 | TP_fast_assign_fsid(btrfs_sb(file->f_path.dentry->d_sb)); | ||
413 | __entry->ino = inode->i_ino; | 429 | __entry->ino = inode->i_ino; |
414 | __entry->parent = d_inode(dentry->d_parent)->i_ino; | 430 | __entry->parent = d_inode(dentry->d_parent)->i_ino; |
415 | __entry->datasync = datasync; | 431 | __entry->datasync = datasync; |
@@ -417,7 +433,7 @@ TRACE_EVENT(btrfs_sync_file, | |||
417 | BTRFS_I(inode)->root->root_key.objectid; | 433 | BTRFS_I(inode)->root->root_key.objectid; |
418 | ), | 434 | ), |
419 | 435 | ||
420 | TP_printk("root = %llu(%s), ino = %ld, parent = %ld, datasync = %d", | 436 | TP_printk_btrfs("root = %llu(%s), ino = %ld, parent = %ld, datasync = %d", |
421 | show_root_type(__entry->root_objectid), | 437 | show_root_type(__entry->root_objectid), |
422 | (unsigned long)__entry->ino, (unsigned long)__entry->parent, | 438 | (unsigned long)__entry->ino, (unsigned long)__entry->parent, |
423 | __entry->datasync) | 439 | __entry->datasync) |
@@ -425,19 +441,19 @@ TRACE_EVENT(btrfs_sync_file, | |||
425 | 441 | ||
426 | TRACE_EVENT(btrfs_sync_fs, | 442 | TRACE_EVENT(btrfs_sync_fs, |
427 | 443 | ||
428 | TP_PROTO(int wait), | 444 | TP_PROTO(struct btrfs_fs_info *fs_info, int wait), |
429 | 445 | ||
430 | TP_ARGS(wait), | 446 | TP_ARGS(fs_info, wait), |
431 | 447 | ||
432 | TP_STRUCT__entry( | 448 | TP_STRUCT__entry_btrfs( |
433 | __field( int, wait ) | 449 | __field( int, wait ) |
434 | ), | 450 | ), |
435 | 451 | ||
436 | TP_fast_assign( | 452 | TP_fast_assign_btrfs(fs_info, |
437 | __entry->wait = wait; | 453 | __entry->wait = wait; |
438 | ), | 454 | ), |
439 | 455 | ||
440 | TP_printk("wait = %d", __entry->wait) | 456 | TP_printk_btrfs("wait = %d", __entry->wait) |
441 | ); | 457 | ); |
442 | 458 | ||
443 | TRACE_EVENT(btrfs_add_block_group, | 459 | TRACE_EVENT(btrfs_add_block_group, |
@@ -490,13 +506,14 @@ TRACE_EVENT(btrfs_add_block_group, | |||
490 | 506 | ||
491 | DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref, | 507 | DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref, |
492 | 508 | ||
493 | TP_PROTO(struct btrfs_delayed_ref_node *ref, | 509 | TP_PROTO(struct btrfs_fs_info *fs_info, |
510 | struct btrfs_delayed_ref_node *ref, | ||
494 | struct btrfs_delayed_tree_ref *full_ref, | 511 | struct btrfs_delayed_tree_ref *full_ref, |
495 | int action), | 512 | int action), |
496 | 513 | ||
497 | TP_ARGS(ref, full_ref, action), | 514 | TP_ARGS(fs_info, ref, full_ref, action), |
498 | 515 | ||
499 | TP_STRUCT__entry( | 516 | TP_STRUCT__entry_btrfs( |
500 | __field( u64, bytenr ) | 517 | __field( u64, bytenr ) |
501 | __field( u64, num_bytes ) | 518 | __field( u64, num_bytes ) |
502 | __field( int, action ) | 519 | __field( int, action ) |
@@ -507,7 +524,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref, | |||
507 | __field( u64, seq ) | 524 | __field( u64, seq ) |
508 | ), | 525 | ), |
509 | 526 | ||
510 | TP_fast_assign( | 527 | TP_fast_assign_btrfs(fs_info, |
511 | __entry->bytenr = ref->bytenr; | 528 | __entry->bytenr = ref->bytenr; |
512 | __entry->num_bytes = ref->num_bytes; | 529 | __entry->num_bytes = ref->num_bytes; |
513 | __entry->action = action; | 530 | __entry->action = action; |
@@ -518,7 +535,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref, | |||
518 | __entry->seq = ref->seq; | 535 | __entry->seq = ref->seq; |
519 | ), | 536 | ), |
520 | 537 | ||
521 | TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, " | 538 | TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, action = %s, " |
522 | "parent = %llu(%s), ref_root = %llu(%s), level = %d, " | 539 | "parent = %llu(%s), ref_root = %llu(%s), level = %d, " |
523 | "type = %s, seq = %llu", | 540 | "type = %s, seq = %llu", |
524 | (unsigned long long)__entry->bytenr, | 541 | (unsigned long long)__entry->bytenr, |
@@ -532,31 +549,34 @@ DECLARE_EVENT_CLASS(btrfs_delayed_tree_ref, | |||
532 | 549 | ||
533 | DEFINE_EVENT(btrfs_delayed_tree_ref, add_delayed_tree_ref, | 550 | DEFINE_EVENT(btrfs_delayed_tree_ref, add_delayed_tree_ref, |
534 | 551 | ||
535 | TP_PROTO(struct btrfs_delayed_ref_node *ref, | 552 | TP_PROTO(struct btrfs_fs_info *fs_info, |
553 | struct btrfs_delayed_ref_node *ref, | ||
536 | struct btrfs_delayed_tree_ref *full_ref, | 554 | struct btrfs_delayed_tree_ref *full_ref, |
537 | int action), | 555 | int action), |
538 | 556 | ||
539 | TP_ARGS(ref, full_ref, action) | 557 | TP_ARGS(fs_info, ref, full_ref, action) |
540 | ); | 558 | ); |
541 | 559 | ||
542 | DEFINE_EVENT(btrfs_delayed_tree_ref, run_delayed_tree_ref, | 560 | DEFINE_EVENT(btrfs_delayed_tree_ref, run_delayed_tree_ref, |
543 | 561 | ||
544 | TP_PROTO(struct btrfs_delayed_ref_node *ref, | 562 | TP_PROTO(struct btrfs_fs_info *fs_info, |
563 | struct btrfs_delayed_ref_node *ref, | ||
545 | struct btrfs_delayed_tree_ref *full_ref, | 564 | struct btrfs_delayed_tree_ref *full_ref, |
546 | int action), | 565 | int action), |
547 | 566 | ||
548 | TP_ARGS(ref, full_ref, action) | 567 | TP_ARGS(fs_info, ref, full_ref, action) |
549 | ); | 568 | ); |
550 | 569 | ||
551 | DECLARE_EVENT_CLASS(btrfs_delayed_data_ref, | 570 | DECLARE_EVENT_CLASS(btrfs_delayed_data_ref, |
552 | 571 | ||
553 | TP_PROTO(struct btrfs_delayed_ref_node *ref, | 572 | TP_PROTO(struct btrfs_fs_info *fs_info, |
573 | struct btrfs_delayed_ref_node *ref, | ||
554 | struct btrfs_delayed_data_ref *full_ref, | 574 | struct btrfs_delayed_data_ref *full_ref, |
555 | int action), | 575 | int action), |
556 | 576 | ||
557 | TP_ARGS(ref, full_ref, action), | 577 | TP_ARGS(fs_info, ref, full_ref, action), |
558 | 578 | ||
559 | TP_STRUCT__entry( | 579 | TP_STRUCT__entry_btrfs( |
560 | __field( u64, bytenr ) | 580 | __field( u64, bytenr ) |
561 | __field( u64, num_bytes ) | 581 | __field( u64, num_bytes ) |
562 | __field( int, action ) | 582 | __field( int, action ) |
@@ -568,7 +588,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_data_ref, | |||
568 | __field( u64, seq ) | 588 | __field( u64, seq ) |
569 | ), | 589 | ), |
570 | 590 | ||
571 | TP_fast_assign( | 591 | TP_fast_assign_btrfs(fs_info, |
572 | __entry->bytenr = ref->bytenr; | 592 | __entry->bytenr = ref->bytenr; |
573 | __entry->num_bytes = ref->num_bytes; | 593 | __entry->num_bytes = ref->num_bytes; |
574 | __entry->action = action; | 594 | __entry->action = action; |
@@ -580,7 +600,7 @@ DECLARE_EVENT_CLASS(btrfs_delayed_data_ref, | |||
580 | __entry->seq = ref->seq; | 600 | __entry->seq = ref->seq; |
581 | ), | 601 | ), |
582 | 602 | ||
583 | TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, " | 603 | TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, action = %s, " |
584 | "parent = %llu(%s), ref_root = %llu(%s), owner = %llu, " | 604 | "parent = %llu(%s), ref_root = %llu(%s), owner = %llu, " |
585 | "offset = %llu, type = %s, seq = %llu", | 605 | "offset = %llu, type = %s, seq = %llu", |
586 | (unsigned long long)__entry->bytenr, | 606 | (unsigned long long)__entry->bytenr, |
@@ -596,45 +616,48 @@ DECLARE_EVENT_CLASS(btrfs_delayed_data_ref, | |||
596 | 616 | ||
597 | DEFINE_EVENT(btrfs_delayed_data_ref, add_delayed_data_ref, | 617 | DEFINE_EVENT(btrfs_delayed_data_ref, add_delayed_data_ref, |
598 | 618 | ||
599 | TP_PROTO(struct btrfs_delayed_ref_node *ref, | 619 | TP_PROTO(struct btrfs_fs_info *fs_info, |
620 | struct btrfs_delayed_ref_node *ref, | ||
600 | struct btrfs_delayed_data_ref *full_ref, | 621 | struct btrfs_delayed_data_ref *full_ref, |
601 | int action), | 622 | int action), |
602 | 623 | ||
603 | TP_ARGS(ref, full_ref, action) | 624 | TP_ARGS(fs_info, ref, full_ref, action) |
604 | ); | 625 | ); |
605 | 626 | ||
606 | DEFINE_EVENT(btrfs_delayed_data_ref, run_delayed_data_ref, | 627 | DEFINE_EVENT(btrfs_delayed_data_ref, run_delayed_data_ref, |
607 | 628 | ||
608 | TP_PROTO(struct btrfs_delayed_ref_node *ref, | 629 | TP_PROTO(struct btrfs_fs_info *fs_info, |
630 | struct btrfs_delayed_ref_node *ref, | ||
609 | struct btrfs_delayed_data_ref *full_ref, | 631 | struct btrfs_delayed_data_ref *full_ref, |
610 | int action), | 632 | int action), |
611 | 633 | ||
612 | TP_ARGS(ref, full_ref, action) | 634 | TP_ARGS(fs_info, ref, full_ref, action) |
613 | ); | 635 | ); |
614 | 636 | ||
615 | DECLARE_EVENT_CLASS(btrfs_delayed_ref_head, | 637 | DECLARE_EVENT_CLASS(btrfs_delayed_ref_head, |
616 | 638 | ||
617 | TP_PROTO(struct btrfs_delayed_ref_node *ref, | 639 | TP_PROTO(struct btrfs_fs_info *fs_info, |
640 | struct btrfs_delayed_ref_node *ref, | ||
618 | struct btrfs_delayed_ref_head *head_ref, | 641 | struct btrfs_delayed_ref_head *head_ref, |
619 | int action), | 642 | int action), |
620 | 643 | ||
621 | TP_ARGS(ref, head_ref, action), | 644 | TP_ARGS(fs_info, ref, head_ref, action), |
622 | 645 | ||
623 | TP_STRUCT__entry( | 646 | TP_STRUCT__entry_btrfs( |
624 | __field( u64, bytenr ) | 647 | __field( u64, bytenr ) |
625 | __field( u64, num_bytes ) | 648 | __field( u64, num_bytes ) |
626 | __field( int, action ) | 649 | __field( int, action ) |
627 | __field( int, is_data ) | 650 | __field( int, is_data ) |
628 | ), | 651 | ), |
629 | 652 | ||
630 | TP_fast_assign( | 653 | TP_fast_assign_btrfs(fs_info, |
631 | __entry->bytenr = ref->bytenr; | 654 | __entry->bytenr = ref->bytenr; |
632 | __entry->num_bytes = ref->num_bytes; | 655 | __entry->num_bytes = ref->num_bytes; |
633 | __entry->action = action; | 656 | __entry->action = action; |
634 | __entry->is_data = head_ref->is_data; | 657 | __entry->is_data = head_ref->is_data; |
635 | ), | 658 | ), |
636 | 659 | ||
637 | TP_printk("bytenr = %llu, num_bytes = %llu, action = %s, is_data = %d", | 660 | TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, action = %s, is_data = %d", |
638 | (unsigned long long)__entry->bytenr, | 661 | (unsigned long long)__entry->bytenr, |
639 | (unsigned long long)__entry->num_bytes, | 662 | (unsigned long long)__entry->num_bytes, |
640 | show_ref_action(__entry->action), | 663 | show_ref_action(__entry->action), |
@@ -643,20 +666,22 @@ DECLARE_EVENT_CLASS(btrfs_delayed_ref_head, | |||
643 | 666 | ||
644 | DEFINE_EVENT(btrfs_delayed_ref_head, add_delayed_ref_head, | 667 | DEFINE_EVENT(btrfs_delayed_ref_head, add_delayed_ref_head, |
645 | 668 | ||
646 | TP_PROTO(struct btrfs_delayed_ref_node *ref, | 669 | TP_PROTO(struct btrfs_fs_info *fs_info, |
670 | struct btrfs_delayed_ref_node *ref, | ||
647 | struct btrfs_delayed_ref_head *head_ref, | 671 | struct btrfs_delayed_ref_head *head_ref, |
648 | int action), | 672 | int action), |
649 | 673 | ||
650 | TP_ARGS(ref, head_ref, action) | 674 | TP_ARGS(fs_info, ref, head_ref, action) |
651 | ); | 675 | ); |
652 | 676 | ||
653 | DEFINE_EVENT(btrfs_delayed_ref_head, run_delayed_ref_head, | 677 | DEFINE_EVENT(btrfs_delayed_ref_head, run_delayed_ref_head, |
654 | 678 | ||
655 | TP_PROTO(struct btrfs_delayed_ref_node *ref, | 679 | TP_PROTO(struct btrfs_fs_info *fs_info, |
680 | struct btrfs_delayed_ref_node *ref, | ||
656 | struct btrfs_delayed_ref_head *head_ref, | 681 | struct btrfs_delayed_ref_head *head_ref, |
657 | int action), | 682 | int action), |
658 | 683 | ||
659 | TP_ARGS(ref, head_ref, action) | 684 | TP_ARGS(fs_info, ref, head_ref, action) |
660 | ); | 685 | ); |
661 | 686 | ||
662 | #define show_chunk_type(type) \ | 687 | #define show_chunk_type(type) \ |
@@ -678,7 +703,7 @@ DECLARE_EVENT_CLASS(btrfs__chunk, | |||
678 | 703 | ||
679 | TP_ARGS(root, map, offset, size), | 704 | TP_ARGS(root, map, offset, size), |
680 | 705 | ||
681 | TP_STRUCT__entry( | 706 | TP_STRUCT__entry_btrfs( |
682 | __field( int, num_stripes ) | 707 | __field( int, num_stripes ) |
683 | __field( u64, type ) | 708 | __field( u64, type ) |
684 | __field( int, sub_stripes ) | 709 | __field( int, sub_stripes ) |
@@ -687,7 +712,7 @@ DECLARE_EVENT_CLASS(btrfs__chunk, | |||
687 | __field( u64, root_objectid ) | 712 | __field( u64, root_objectid ) |
688 | ), | 713 | ), |
689 | 714 | ||
690 | TP_fast_assign( | 715 | TP_fast_assign_btrfs(root->fs_info, |
691 | __entry->num_stripes = map->num_stripes; | 716 | __entry->num_stripes = map->num_stripes; |
692 | __entry->type = map->type; | 717 | __entry->type = map->type; |
693 | __entry->sub_stripes = map->sub_stripes; | 718 | __entry->sub_stripes = map->sub_stripes; |
@@ -696,7 +721,7 @@ DECLARE_EVENT_CLASS(btrfs__chunk, | |||
696 | __entry->root_objectid = root->root_key.objectid; | 721 | __entry->root_objectid = root->root_key.objectid; |
697 | ), | 722 | ), |
698 | 723 | ||
699 | TP_printk("root = %llu(%s), offset = %llu, size = %llu, " | 724 | TP_printk_btrfs("root = %llu(%s), offset = %llu, size = %llu, " |
700 | "num_stripes = %d, sub_stripes = %d, type = %s", | 725 | "num_stripes = %d, sub_stripes = %d, type = %s", |
701 | show_root_type(__entry->root_objectid), | 726 | show_root_type(__entry->root_objectid), |
702 | (unsigned long long)__entry->offset, | 727 | (unsigned long long)__entry->offset, |
@@ -728,7 +753,7 @@ TRACE_EVENT(btrfs_cow_block, | |||
728 | 753 | ||
729 | TP_ARGS(root, buf, cow), | 754 | TP_ARGS(root, buf, cow), |
730 | 755 | ||
731 | TP_STRUCT__entry( | 756 | TP_STRUCT__entry_btrfs( |
732 | __field( u64, root_objectid ) | 757 | __field( u64, root_objectid ) |
733 | __field( u64, buf_start ) | 758 | __field( u64, buf_start ) |
734 | __field( int, refs ) | 759 | __field( int, refs ) |
@@ -737,7 +762,7 @@ TRACE_EVENT(btrfs_cow_block, | |||
737 | __field( int, cow_level ) | 762 | __field( int, cow_level ) |
738 | ), | 763 | ), |
739 | 764 | ||
740 | TP_fast_assign( | 765 | TP_fast_assign_btrfs(root->fs_info, |
741 | __entry->root_objectid = root->root_key.objectid; | 766 | __entry->root_objectid = root->root_key.objectid; |
742 | __entry->buf_start = buf->start; | 767 | __entry->buf_start = buf->start; |
743 | __entry->refs = atomic_read(&buf->refs); | 768 | __entry->refs = atomic_read(&buf->refs); |
@@ -746,7 +771,7 @@ TRACE_EVENT(btrfs_cow_block, | |||
746 | __entry->cow_level = btrfs_header_level(cow); | 771 | __entry->cow_level = btrfs_header_level(cow); |
747 | ), | 772 | ), |
748 | 773 | ||
749 | TP_printk("root = %llu(%s), refs = %d, orig_buf = %llu " | 774 | TP_printk_btrfs("root = %llu(%s), refs = %d, orig_buf = %llu " |
750 | "(orig_level = %d), cow_buf = %llu (cow_level = %d)", | 775 | "(orig_level = %d), cow_buf = %llu (cow_level = %d)", |
751 | show_root_type(__entry->root_objectid), | 776 | show_root_type(__entry->root_objectid), |
752 | __entry->refs, | 777 | __entry->refs, |
@@ -763,25 +788,23 @@ TRACE_EVENT(btrfs_space_reservation, | |||
763 | 788 | ||
764 | TP_ARGS(fs_info, type, val, bytes, reserve), | 789 | TP_ARGS(fs_info, type, val, bytes, reserve), |
765 | 790 | ||
766 | TP_STRUCT__entry( | 791 | TP_STRUCT__entry_btrfs( |
767 | __array( u8, fsid, BTRFS_UUID_SIZE ) | ||
768 | __string( type, type ) | 792 | __string( type, type ) |
769 | __field( u64, val ) | 793 | __field( u64, val ) |
770 | __field( u64, bytes ) | 794 | __field( u64, bytes ) |
771 | __field( int, reserve ) | 795 | __field( int, reserve ) |
772 | ), | 796 | ), |
773 | 797 | ||
774 | TP_fast_assign( | 798 | TP_fast_assign_btrfs(fs_info, |
775 | memcpy(__entry->fsid, fs_info->fsid, BTRFS_UUID_SIZE); | ||
776 | __assign_str(type, type); | 799 | __assign_str(type, type); |
777 | __entry->val = val; | 800 | __entry->val = val; |
778 | __entry->bytes = bytes; | 801 | __entry->bytes = bytes; |
779 | __entry->reserve = reserve; | 802 | __entry->reserve = reserve; |
780 | ), | 803 | ), |
781 | 804 | ||
782 | TP_printk("%pU: %s: %Lu %s %Lu", __entry->fsid, __get_str(type), | 805 | TP_printk_btrfs("%s: %Lu %s %Lu", __get_str(type), __entry->val, |
783 | __entry->val, __entry->reserve ? "reserve" : "release", | 806 | __entry->reserve ? "reserve" : "release", |
784 | __entry->bytes) | 807 | __entry->bytes) |
785 | ); | 808 | ); |
786 | 809 | ||
787 | #define show_flush_action(action) \ | 810 | #define show_flush_action(action) \ |
@@ -872,22 +895,19 @@ DECLARE_EVENT_CLASS(btrfs__reserved_extent, | |||
872 | 895 | ||
873 | TP_ARGS(root, start, len), | 896 | TP_ARGS(root, start, len), |
874 | 897 | ||
875 | TP_STRUCT__entry( | 898 | TP_STRUCT__entry_btrfs( |
876 | __array( u8, fsid, BTRFS_UUID_SIZE ) | 899 | __field( u64, root_objectid ) |
877 | __field( u64, root_objectid ) | 900 | __field( u64, start ) |
878 | __field( u64, start ) | 901 | __field( u64, len ) |
879 | __field( u64, len ) | ||
880 | ), | 902 | ), |
881 | 903 | ||
882 | TP_fast_assign( | 904 | TP_fast_assign_btrfs(root->fs_info, |
883 | memcpy(__entry->fsid, root->fs_info->fsid, BTRFS_UUID_SIZE); | ||
884 | __entry->root_objectid = root->root_key.objectid; | 905 | __entry->root_objectid = root->root_key.objectid; |
885 | __entry->start = start; | 906 | __entry->start = start; |
886 | __entry->len = len; | 907 | __entry->len = len; |
887 | ), | 908 | ), |
888 | 909 | ||
889 | TP_printk("%pU: root = %llu(%s), start = %llu, len = %llu", | 910 | TP_printk_btrfs("root = %llu(%s), start = %llu, len = %llu", |
890 | __entry->fsid, | ||
891 | show_root_type(__entry->root_objectid), | 911 | show_root_type(__entry->root_objectid), |
892 | (unsigned long long)__entry->start, | 912 | (unsigned long long)__entry->start, |
893 | (unsigned long long)__entry->len) | 913 | (unsigned long long)__entry->len) |
@@ -914,21 +934,21 @@ TRACE_EVENT(find_free_extent, | |||
914 | 934 | ||
915 | TP_ARGS(root, num_bytes, empty_size, data), | 935 | TP_ARGS(root, num_bytes, empty_size, data), |
916 | 936 | ||
917 | TP_STRUCT__entry( | 937 | TP_STRUCT__entry_btrfs( |
918 | __field( u64, root_objectid ) | 938 | __field( u64, root_objectid ) |
919 | __field( u64, num_bytes ) | 939 | __field( u64, num_bytes ) |
920 | __field( u64, empty_size ) | 940 | __field( u64, empty_size ) |
921 | __field( u64, data ) | 941 | __field( u64, data ) |
922 | ), | 942 | ), |
923 | 943 | ||
924 | TP_fast_assign( | 944 | TP_fast_assign_btrfs(root->fs_info, |
925 | __entry->root_objectid = root->root_key.objectid; | 945 | __entry->root_objectid = root->root_key.objectid; |
926 | __entry->num_bytes = num_bytes; | 946 | __entry->num_bytes = num_bytes; |
927 | __entry->empty_size = empty_size; | 947 | __entry->empty_size = empty_size; |
928 | __entry->data = data; | 948 | __entry->data = data; |
929 | ), | 949 | ), |
930 | 950 | ||
931 | TP_printk("root = %Lu(%s), len = %Lu, empty_size = %Lu, " | 951 | TP_printk_btrfs("root = %Lu(%s), len = %Lu, empty_size = %Lu, " |
932 | "flags = %Lu(%s)", show_root_type(__entry->root_objectid), | 952 | "flags = %Lu(%s)", show_root_type(__entry->root_objectid), |
933 | __entry->num_bytes, __entry->empty_size, __entry->data, | 953 | __entry->num_bytes, __entry->empty_size, __entry->data, |
934 | __print_flags((unsigned long)__entry->data, "|", | 954 | __print_flags((unsigned long)__entry->data, "|", |
@@ -943,8 +963,7 @@ DECLARE_EVENT_CLASS(btrfs__reserve_extent, | |||
943 | 963 | ||
944 | TP_ARGS(root, block_group, start, len), | 964 | TP_ARGS(root, block_group, start, len), |
945 | 965 | ||
946 | TP_STRUCT__entry( | 966 | TP_STRUCT__entry_btrfs( |
947 | __array( u8, fsid, BTRFS_UUID_SIZE ) | ||
948 | __field( u64, root_objectid ) | 967 | __field( u64, root_objectid ) |
949 | __field( u64, bg_objectid ) | 968 | __field( u64, bg_objectid ) |
950 | __field( u64, flags ) | 969 | __field( u64, flags ) |
@@ -952,8 +971,7 @@ DECLARE_EVENT_CLASS(btrfs__reserve_extent, | |||
952 | __field( u64, len ) | 971 | __field( u64, len ) |
953 | ), | 972 | ), |
954 | 973 | ||
955 | TP_fast_assign( | 974 | TP_fast_assign_btrfs(root->fs_info, |
956 | memcpy(__entry->fsid, root->fs_info->fsid, BTRFS_UUID_SIZE); | ||
957 | __entry->root_objectid = root->root_key.objectid; | 975 | __entry->root_objectid = root->root_key.objectid; |
958 | __entry->bg_objectid = block_group->key.objectid; | 976 | __entry->bg_objectid = block_group->key.objectid; |
959 | __entry->flags = block_group->flags; | 977 | __entry->flags = block_group->flags; |
@@ -961,8 +979,8 @@ DECLARE_EVENT_CLASS(btrfs__reserve_extent, | |||
961 | __entry->len = len; | 979 | __entry->len = len; |
962 | ), | 980 | ), |
963 | 981 | ||
964 | TP_printk("%pU: root = %Lu(%s), block_group = %Lu, flags = %Lu(%s), " | 982 | TP_printk_btrfs("root = %Lu(%s), block_group = %Lu, flags = %Lu(%s), " |
965 | "start = %Lu, len = %Lu", __entry->fsid, | 983 | "start = %Lu, len = %Lu", |
966 | show_root_type(__entry->root_objectid), __entry->bg_objectid, | 984 | show_root_type(__entry->root_objectid), __entry->bg_objectid, |
967 | __entry->flags, __print_flags((unsigned long)__entry->flags, | 985 | __entry->flags, __print_flags((unsigned long)__entry->flags, |
968 | "|", BTRFS_GROUP_FLAGS), | 986 | "|", BTRFS_GROUP_FLAGS), |
@@ -994,7 +1012,7 @@ TRACE_EVENT(btrfs_find_cluster, | |||
994 | 1012 | ||
995 | TP_ARGS(block_group, start, bytes, empty_size, min_bytes), | 1013 | TP_ARGS(block_group, start, bytes, empty_size, min_bytes), |
996 | 1014 | ||
997 | TP_STRUCT__entry( | 1015 | TP_STRUCT__entry_btrfs( |
998 | __field( u64, bg_objectid ) | 1016 | __field( u64, bg_objectid ) |
999 | __field( u64, flags ) | 1017 | __field( u64, flags ) |
1000 | __field( u64, start ) | 1018 | __field( u64, start ) |
@@ -1003,7 +1021,7 @@ TRACE_EVENT(btrfs_find_cluster, | |||
1003 | __field( u64, min_bytes ) | 1021 | __field( u64, min_bytes ) |
1004 | ), | 1022 | ), |
1005 | 1023 | ||
1006 | TP_fast_assign( | 1024 | TP_fast_assign_btrfs(block_group->fs_info, |
1007 | __entry->bg_objectid = block_group->key.objectid; | 1025 | __entry->bg_objectid = block_group->key.objectid; |
1008 | __entry->flags = block_group->flags; | 1026 | __entry->flags = block_group->flags; |
1009 | __entry->start = start; | 1027 | __entry->start = start; |
@@ -1012,7 +1030,7 @@ TRACE_EVENT(btrfs_find_cluster, | |||
1012 | __entry->min_bytes = min_bytes; | 1030 | __entry->min_bytes = min_bytes; |
1013 | ), | 1031 | ), |
1014 | 1032 | ||
1015 | TP_printk("block_group = %Lu, flags = %Lu(%s), start = %Lu, len = %Lu," | 1033 | TP_printk_btrfs("block_group = %Lu, flags = %Lu(%s), start = %Lu, len = %Lu," |
1016 | " empty_size = %Lu, min_bytes = %Lu", __entry->bg_objectid, | 1034 | " empty_size = %Lu, min_bytes = %Lu", __entry->bg_objectid, |
1017 | __entry->flags, | 1035 | __entry->flags, |
1018 | __print_flags((unsigned long)__entry->flags, "|", | 1036 | __print_flags((unsigned long)__entry->flags, "|", |
@@ -1026,15 +1044,15 @@ TRACE_EVENT(btrfs_failed_cluster_setup, | |||
1026 | 1044 | ||
1027 | TP_ARGS(block_group), | 1045 | TP_ARGS(block_group), |
1028 | 1046 | ||
1029 | TP_STRUCT__entry( | 1047 | TP_STRUCT__entry_btrfs( |
1030 | __field( u64, bg_objectid ) | 1048 | __field( u64, bg_objectid ) |
1031 | ), | 1049 | ), |
1032 | 1050 | ||
1033 | TP_fast_assign( | 1051 | TP_fast_assign_btrfs(block_group->fs_info, |
1034 | __entry->bg_objectid = block_group->key.objectid; | 1052 | __entry->bg_objectid = block_group->key.objectid; |
1035 | ), | 1053 | ), |
1036 | 1054 | ||
1037 | TP_printk("block_group = %Lu", __entry->bg_objectid) | 1055 | TP_printk_btrfs("block_group = %Lu", __entry->bg_objectid) |
1038 | ); | 1056 | ); |
1039 | 1057 | ||
1040 | TRACE_EVENT(btrfs_setup_cluster, | 1058 | TRACE_EVENT(btrfs_setup_cluster, |
@@ -1044,7 +1062,7 @@ TRACE_EVENT(btrfs_setup_cluster, | |||
1044 | 1062 | ||
1045 | TP_ARGS(block_group, cluster, size, bitmap), | 1063 | TP_ARGS(block_group, cluster, size, bitmap), |
1046 | 1064 | ||
1047 | TP_STRUCT__entry( | 1065 | TP_STRUCT__entry_btrfs( |
1048 | __field( u64, bg_objectid ) | 1066 | __field( u64, bg_objectid ) |
1049 | __field( u64, flags ) | 1067 | __field( u64, flags ) |
1050 | __field( u64, start ) | 1068 | __field( u64, start ) |
@@ -1053,7 +1071,7 @@ TRACE_EVENT(btrfs_setup_cluster, | |||
1053 | __field( int, bitmap ) | 1071 | __field( int, bitmap ) |
1054 | ), | 1072 | ), |
1055 | 1073 | ||
1056 | TP_fast_assign( | 1074 | TP_fast_assign_btrfs(block_group->fs_info, |
1057 | __entry->bg_objectid = block_group->key.objectid; | 1075 | __entry->bg_objectid = block_group->key.objectid; |
1058 | __entry->flags = block_group->flags; | 1076 | __entry->flags = block_group->flags; |
1059 | __entry->start = cluster->window_start; | 1077 | __entry->start = cluster->window_start; |
@@ -1062,7 +1080,7 @@ TRACE_EVENT(btrfs_setup_cluster, | |||
1062 | __entry->bitmap = bitmap; | 1080 | __entry->bitmap = bitmap; |
1063 | ), | 1081 | ), |
1064 | 1082 | ||
1065 | TP_printk("block_group = %Lu, flags = %Lu(%s), window_start = %Lu, " | 1083 | TP_printk_btrfs("block_group = %Lu, flags = %Lu(%s), window_start = %Lu, " |
1066 | "size = %Lu, max_size = %Lu, bitmap = %d", | 1084 | "size = %Lu, max_size = %Lu, bitmap = %d", |
1067 | __entry->bg_objectid, | 1085 | __entry->bg_objectid, |
1068 | __entry->flags, | 1086 | __entry->flags, |
@@ -1120,7 +1138,7 @@ DECLARE_EVENT_CLASS(btrfs__work, | |||
1120 | 1138 | ||
1121 | TP_ARGS(work), | 1139 | TP_ARGS(work), |
1122 | 1140 | ||
1123 | TP_STRUCT__entry( | 1141 | TP_STRUCT__entry_btrfs( |
1124 | __field( void *, work ) | 1142 | __field( void *, work ) |
1125 | __field( void *, wq ) | 1143 | __field( void *, wq ) |
1126 | __field( void *, func ) | 1144 | __field( void *, func ) |
@@ -1129,7 +1147,7 @@ DECLARE_EVENT_CLASS(btrfs__work, | |||
1129 | __field( void *, normal_work ) | 1147 | __field( void *, normal_work ) |
1130 | ), | 1148 | ), |
1131 | 1149 | ||
1132 | TP_fast_assign( | 1150 | TP_fast_assign_btrfs(btrfs_work_owner(work), |
1133 | __entry->work = work; | 1151 | __entry->work = work; |
1134 | __entry->wq = work->wq; | 1152 | __entry->wq = work->wq; |
1135 | __entry->func = work->func; | 1153 | __entry->func = work->func; |
@@ -1138,7 +1156,7 @@ DECLARE_EVENT_CLASS(btrfs__work, | |||
1138 | __entry->normal_work = &work->normal_work; | 1156 | __entry->normal_work = &work->normal_work; |
1139 | ), | 1157 | ), |
1140 | 1158 | ||
1141 | TP_printk("work=%p (normal_work=%p), wq=%p, func=%pf, ordered_func=%p," | 1159 | TP_printk_btrfs("work=%p (normal_work=%p), wq=%p, func=%pf, ordered_func=%p," |
1142 | " ordered_free=%p", | 1160 | " ordered_free=%p", |
1143 | __entry->work, __entry->normal_work, __entry->wq, | 1161 | __entry->work, __entry->normal_work, __entry->wq, |
1144 | __entry->func, __entry->ordered_func, __entry->ordered_free) | 1162 | __entry->func, __entry->ordered_func, __entry->ordered_free) |
@@ -1151,15 +1169,15 @@ DECLARE_EVENT_CLASS(btrfs__work__done, | |||
1151 | 1169 | ||
1152 | TP_ARGS(work), | 1170 | TP_ARGS(work), |
1153 | 1171 | ||
1154 | TP_STRUCT__entry( | 1172 | TP_STRUCT__entry_btrfs( |
1155 | __field( void *, work ) | 1173 | __field( void *, work ) |
1156 | ), | 1174 | ), |
1157 | 1175 | ||
1158 | TP_fast_assign( | 1176 | TP_fast_assign_btrfs(btrfs_work_owner(work), |
1159 | __entry->work = work; | 1177 | __entry->work = work; |
1160 | ), | 1178 | ), |
1161 | 1179 | ||
1162 | TP_printk("work->%p", __entry->work) | 1180 | TP_printk_btrfs("work->%p", __entry->work) |
1163 | ); | 1181 | ); |
1164 | 1182 | ||
1165 | DEFINE_EVENT(btrfs__work, btrfs_work_queued, | 1183 | DEFINE_EVENT(btrfs__work, btrfs_work_queued, |
@@ -1196,19 +1214,19 @@ DECLARE_EVENT_CLASS(btrfs__workqueue, | |||
1196 | 1214 | ||
1197 | TP_ARGS(wq, name, high), | 1215 | TP_ARGS(wq, name, high), |
1198 | 1216 | ||
1199 | TP_STRUCT__entry( | 1217 | TP_STRUCT__entry_btrfs( |
1200 | __field( void *, wq ) | 1218 | __field( void *, wq ) |
1201 | __string( name, name ) | 1219 | __string( name, name ) |
1202 | __field( int , high ) | 1220 | __field( int , high ) |
1203 | ), | 1221 | ), |
1204 | 1222 | ||
1205 | TP_fast_assign( | 1223 | TP_fast_assign_btrfs(btrfs_workqueue_owner(wq), |
1206 | __entry->wq = wq; | 1224 | __entry->wq = wq; |
1207 | __assign_str(name, name); | 1225 | __assign_str(name, name); |
1208 | __entry->high = high; | 1226 | __entry->high = high; |
1209 | ), | 1227 | ), |
1210 | 1228 | ||
1211 | TP_printk("name=%s%s, wq=%p", __get_str(name), | 1229 | TP_printk_btrfs("name=%s%s, wq=%p", __get_str(name), |
1212 | __print_flags(__entry->high, "", | 1230 | __print_flags(__entry->high, "", |
1213 | {(WQ_HIGHPRI), "-high"}), | 1231 | {(WQ_HIGHPRI), "-high"}), |
1214 | __entry->wq) | 1232 | __entry->wq) |
@@ -1227,15 +1245,15 @@ DECLARE_EVENT_CLASS(btrfs__workqueue_done, | |||
1227 | 1245 | ||
1228 | TP_ARGS(wq), | 1246 | TP_ARGS(wq), |
1229 | 1247 | ||
1230 | TP_STRUCT__entry( | 1248 | TP_STRUCT__entry_btrfs( |
1231 | __field( void *, wq ) | 1249 | __field( void *, wq ) |
1232 | ), | 1250 | ), |
1233 | 1251 | ||
1234 | TP_fast_assign( | 1252 | TP_fast_assign_btrfs(btrfs_workqueue_owner(wq), |
1235 | __entry->wq = wq; | 1253 | __entry->wq = wq; |
1236 | ), | 1254 | ), |
1237 | 1255 | ||
1238 | TP_printk("wq=%p", __entry->wq) | 1256 | TP_printk_btrfs("wq=%p", __entry->wq) |
1239 | ); | 1257 | ); |
1240 | 1258 | ||
1241 | DEFINE_EVENT(btrfs__workqueue_done, btrfs_workqueue_destroy, | 1259 | DEFINE_EVENT(btrfs__workqueue_done, btrfs_workqueue_destroy, |
@@ -1251,19 +1269,19 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_data_map, | |||
1251 | 1269 | ||
1252 | TP_ARGS(inode, free_reserved), | 1270 | TP_ARGS(inode, free_reserved), |
1253 | 1271 | ||
1254 | TP_STRUCT__entry( | 1272 | TP_STRUCT__entry_btrfs( |
1255 | __field( u64, rootid ) | 1273 | __field( u64, rootid ) |
1256 | __field( unsigned long, ino ) | 1274 | __field( unsigned long, ino ) |
1257 | __field( u64, free_reserved ) | 1275 | __field( u64, free_reserved ) |
1258 | ), | 1276 | ), |
1259 | 1277 | ||
1260 | TP_fast_assign( | 1278 | TP_fast_assign_btrfs(btrfs_sb(inode->i_sb), |
1261 | __entry->rootid = BTRFS_I(inode)->root->objectid; | 1279 | __entry->rootid = BTRFS_I(inode)->root->objectid; |
1262 | __entry->ino = inode->i_ino; | 1280 | __entry->ino = inode->i_ino; |
1263 | __entry->free_reserved = free_reserved; | 1281 | __entry->free_reserved = free_reserved; |
1264 | ), | 1282 | ), |
1265 | 1283 | ||
1266 | TP_printk("rootid=%llu, ino=%lu, free_reserved=%llu", | 1284 | TP_printk_btrfs("rootid=%llu, ino=%lu, free_reserved=%llu", |
1267 | __entry->rootid, __entry->ino, __entry->free_reserved) | 1285 | __entry->rootid, __entry->ino, __entry->free_reserved) |
1268 | ); | 1286 | ); |
1269 | 1287 | ||
@@ -1292,7 +1310,7 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data, | |||
1292 | 1310 | ||
1293 | TP_ARGS(inode, start, len, reserved, op), | 1311 | TP_ARGS(inode, start, len, reserved, op), |
1294 | 1312 | ||
1295 | TP_STRUCT__entry( | 1313 | TP_STRUCT__entry_btrfs( |
1296 | __field( u64, rootid ) | 1314 | __field( u64, rootid ) |
1297 | __field( unsigned long, ino ) | 1315 | __field( unsigned long, ino ) |
1298 | __field( u64, start ) | 1316 | __field( u64, start ) |
@@ -1301,7 +1319,7 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data, | |||
1301 | __field( int, op ) | 1319 | __field( int, op ) |
1302 | ), | 1320 | ), |
1303 | 1321 | ||
1304 | TP_fast_assign( | 1322 | TP_fast_assign_btrfs(btrfs_sb(inode->i_sb), |
1305 | __entry->rootid = BTRFS_I(inode)->root->objectid; | 1323 | __entry->rootid = BTRFS_I(inode)->root->objectid; |
1306 | __entry->ino = inode->i_ino; | 1324 | __entry->ino = inode->i_ino; |
1307 | __entry->start = start; | 1325 | __entry->start = start; |
@@ -1310,7 +1328,7 @@ DECLARE_EVENT_CLASS(btrfs__qgroup_rsv_data, | |||
1310 | __entry->op = op; | 1328 | __entry->op = op; |
1311 | ), | 1329 | ), |
1312 | 1330 | ||
1313 | TP_printk("root=%llu, ino=%lu, start=%llu, len=%llu, reserved=%llu, op=%s", | 1331 | TP_printk_btrfs("root=%llu, ino=%lu, start=%llu, len=%llu, reserved=%llu, op=%s", |
1314 | __entry->rootid, __entry->ino, __entry->start, __entry->len, | 1332 | __entry->rootid, __entry->ino, __entry->start, __entry->len, |
1315 | __entry->reserved, | 1333 | __entry->reserved, |
1316 | __print_flags((unsigned long)__entry->op, "", | 1334 | __print_flags((unsigned long)__entry->op, "", |
@@ -1334,86 +1352,90 @@ DEFINE_EVENT(btrfs__qgroup_rsv_data, btrfs_qgroup_release_data, | |||
1334 | 1352 | ||
1335 | DECLARE_EVENT_CLASS(btrfs__qgroup_delayed_ref, | 1353 | DECLARE_EVENT_CLASS(btrfs__qgroup_delayed_ref, |
1336 | 1354 | ||
1337 | TP_PROTO(u64 ref_root, u64 reserved), | 1355 | TP_PROTO(struct btrfs_fs_info *fs_info, u64 ref_root, u64 reserved), |
1338 | 1356 | ||
1339 | TP_ARGS(ref_root, reserved), | 1357 | TP_ARGS(fs_info, ref_root, reserved), |
1340 | 1358 | ||
1341 | TP_STRUCT__entry( | 1359 | TP_STRUCT__entry_btrfs( |
1342 | __field( u64, ref_root ) | 1360 | __field( u64, ref_root ) |
1343 | __field( u64, reserved ) | 1361 | __field( u64, reserved ) |
1344 | ), | 1362 | ), |
1345 | 1363 | ||
1346 | TP_fast_assign( | 1364 | TP_fast_assign_btrfs(fs_info, |
1347 | __entry->ref_root = ref_root; | 1365 | __entry->ref_root = ref_root; |
1348 | __entry->reserved = reserved; | 1366 | __entry->reserved = reserved; |
1349 | ), | 1367 | ), |
1350 | 1368 | ||
1351 | TP_printk("root=%llu, reserved=%llu, op=free", | 1369 | TP_printk_btrfs("root=%llu, reserved=%llu, op=free", |
1352 | __entry->ref_root, __entry->reserved) | 1370 | __entry->ref_root, __entry->reserved) |
1353 | ); | 1371 | ); |
1354 | 1372 | ||
1355 | DEFINE_EVENT(btrfs__qgroup_delayed_ref, btrfs_qgroup_free_delayed_ref, | 1373 | DEFINE_EVENT(btrfs__qgroup_delayed_ref, btrfs_qgroup_free_delayed_ref, |
1356 | 1374 | ||
1357 | TP_PROTO(u64 ref_root, u64 reserved), | 1375 | TP_PROTO(struct btrfs_fs_info *fs_info, u64 ref_root, u64 reserved), |
1358 | 1376 | ||
1359 | TP_ARGS(ref_root, reserved) | 1377 | TP_ARGS(fs_info, ref_root, reserved) |
1360 | ); | 1378 | ); |
1361 | 1379 | ||
1362 | DECLARE_EVENT_CLASS(btrfs_qgroup_extent, | 1380 | DECLARE_EVENT_CLASS(btrfs_qgroup_extent, |
1363 | TP_PROTO(struct btrfs_qgroup_extent_record *rec), | 1381 | TP_PROTO(struct btrfs_fs_info *fs_info, |
1382 | struct btrfs_qgroup_extent_record *rec), | ||
1364 | 1383 | ||
1365 | TP_ARGS(rec), | 1384 | TP_ARGS(fs_info, rec), |
1366 | 1385 | ||
1367 | TP_STRUCT__entry( | 1386 | TP_STRUCT__entry_btrfs( |
1368 | __field( u64, bytenr ) | 1387 | __field( u64, bytenr ) |
1369 | __field( u64, num_bytes ) | 1388 | __field( u64, num_bytes ) |
1370 | ), | 1389 | ), |
1371 | 1390 | ||
1372 | TP_fast_assign( | 1391 | TP_fast_assign_btrfs(fs_info, |
1373 | __entry->bytenr = rec->bytenr, | 1392 | __entry->bytenr = rec->bytenr, |
1374 | __entry->num_bytes = rec->num_bytes; | 1393 | __entry->num_bytes = rec->num_bytes; |
1375 | ), | 1394 | ), |
1376 | 1395 | ||
1377 | TP_printk("bytenr = %llu, num_bytes = %llu", | 1396 | TP_printk_btrfs("bytenr = %llu, num_bytes = %llu", |
1378 | (unsigned long long)__entry->bytenr, | 1397 | (unsigned long long)__entry->bytenr, |
1379 | (unsigned long long)__entry->num_bytes) | 1398 | (unsigned long long)__entry->num_bytes) |
1380 | ); | 1399 | ); |
1381 | 1400 | ||
1382 | DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents, | 1401 | DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents, |
1383 | 1402 | ||
1384 | TP_PROTO(struct btrfs_qgroup_extent_record *rec), | 1403 | TP_PROTO(struct btrfs_fs_info *fs_info, |
1404 | struct btrfs_qgroup_extent_record *rec), | ||
1385 | 1405 | ||
1386 | TP_ARGS(rec) | 1406 | TP_ARGS(fs_info, rec) |
1387 | ); | 1407 | ); |
1388 | 1408 | ||
1389 | DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_insert_dirty_extent, | 1409 | DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_insert_dirty_extent, |
1390 | 1410 | ||
1391 | TP_PROTO(struct btrfs_qgroup_extent_record *rec), | 1411 | TP_PROTO(struct btrfs_fs_info *fs_info, |
1412 | struct btrfs_qgroup_extent_record *rec), | ||
1392 | 1413 | ||
1393 | TP_ARGS(rec) | 1414 | TP_ARGS(fs_info, rec) |
1394 | ); | 1415 | ); |
1395 | 1416 | ||
1396 | TRACE_EVENT(btrfs_qgroup_account_extent, | 1417 | TRACE_EVENT(btrfs_qgroup_account_extent, |
1397 | 1418 | ||
1398 | TP_PROTO(u64 bytenr, u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots), | 1419 | TP_PROTO(struct btrfs_fs_info *fs_info, u64 bytenr, |
1420 | u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots), | ||
1399 | 1421 | ||
1400 | TP_ARGS(bytenr, num_bytes, nr_old_roots, nr_new_roots), | 1422 | TP_ARGS(fs_info, bytenr, num_bytes, nr_old_roots, nr_new_roots), |
1401 | 1423 | ||
1402 | TP_STRUCT__entry( | 1424 | TP_STRUCT__entry_btrfs( |
1403 | __field( u64, bytenr ) | 1425 | __field( u64, bytenr ) |
1404 | __field( u64, num_bytes ) | 1426 | __field( u64, num_bytes ) |
1405 | __field( u64, nr_old_roots ) | 1427 | __field( u64, nr_old_roots ) |
1406 | __field( u64, nr_new_roots ) | 1428 | __field( u64, nr_new_roots ) |
1407 | ), | 1429 | ), |
1408 | 1430 | ||
1409 | TP_fast_assign( | 1431 | TP_fast_assign_btrfs(fs_info, |
1410 | __entry->bytenr = bytenr; | 1432 | __entry->bytenr = bytenr; |
1411 | __entry->num_bytes = num_bytes; | 1433 | __entry->num_bytes = num_bytes; |
1412 | __entry->nr_old_roots = nr_old_roots; | 1434 | __entry->nr_old_roots = nr_old_roots; |
1413 | __entry->nr_new_roots = nr_new_roots; | 1435 | __entry->nr_new_roots = nr_new_roots; |
1414 | ), | 1436 | ), |
1415 | 1437 | ||
1416 | TP_printk("bytenr = %llu, num_bytes = %llu, nr_old_roots = %llu, " | 1438 | TP_printk_btrfs("bytenr = %llu, num_bytes = %llu, nr_old_roots = %llu, " |
1417 | "nr_new_roots = %llu", | 1439 | "nr_new_roots = %llu", |
1418 | __entry->bytenr, | 1440 | __entry->bytenr, |
1419 | __entry->num_bytes, | 1441 | __entry->num_bytes, |
@@ -1423,23 +1445,24 @@ TRACE_EVENT(btrfs_qgroup_account_extent, | |||
1423 | 1445 | ||
1424 | TRACE_EVENT(qgroup_update_counters, | 1446 | TRACE_EVENT(qgroup_update_counters, |
1425 | 1447 | ||
1426 | TP_PROTO(u64 qgid, u64 cur_old_count, u64 cur_new_count), | 1448 | TP_PROTO(struct btrfs_fs_info *fs_info, u64 qgid, |
1449 | u64 cur_old_count, u64 cur_new_count), | ||
1427 | 1450 | ||
1428 | TP_ARGS(qgid, cur_old_count, cur_new_count), | 1451 | TP_ARGS(fs_info, qgid, cur_old_count, cur_new_count), |
1429 | 1452 | ||
1430 | TP_STRUCT__entry( | 1453 | TP_STRUCT__entry_btrfs( |
1431 | __field( u64, qgid ) | 1454 | __field( u64, qgid ) |
1432 | __field( u64, cur_old_count ) | 1455 | __field( u64, cur_old_count ) |
1433 | __field( u64, cur_new_count ) | 1456 | __field( u64, cur_new_count ) |
1434 | ), | 1457 | ), |
1435 | 1458 | ||
1436 | TP_fast_assign( | 1459 | TP_fast_assign_btrfs(fs_info, |
1437 | __entry->qgid = qgid; | 1460 | __entry->qgid = qgid; |
1438 | __entry->cur_old_count = cur_old_count; | 1461 | __entry->cur_old_count = cur_old_count; |
1439 | __entry->cur_new_count = cur_new_count; | 1462 | __entry->cur_new_count = cur_new_count; |
1440 | ), | 1463 | ), |
1441 | 1464 | ||
1442 | TP_printk("qgid = %llu, cur_old_count = %llu, cur_new_count = %llu", | 1465 | TP_printk_btrfs("qgid = %llu, cur_old_count = %llu, cur_new_count = %llu", |
1443 | __entry->qgid, | 1466 | __entry->qgid, |
1444 | __entry->cur_old_count, | 1467 | __entry->cur_old_count, |
1445 | __entry->cur_new_count) | 1468 | __entry->cur_new_count) |
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index 2bdd1e3e7007..ac5eacd3055b 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h | |||
@@ -798,7 +798,7 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code) | |||
798 | #define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \ | 798 | #define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \ |
799 | struct btrfs_ioctl_ino_path_args) | 799 | struct btrfs_ioctl_ino_path_args) |
800 | #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \ | 800 | #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \ |
801 | struct btrfs_ioctl_ino_path_args) | 801 | struct btrfs_ioctl_logical_ino_args) |
802 | #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \ | 802 | #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \ |
803 | struct btrfs_ioctl_received_subvol_args) | 803 | struct btrfs_ioctl_received_subvol_args) |
804 | #define BTRFS_IOC_SEND _IOW(BTRFS_IOCTL_MAGIC, 38, struct btrfs_ioctl_send_args) | 804 | #define BTRFS_IOC_SEND _IOW(BTRFS_IOCTL_MAGIC, 38, struct btrfs_ioctl_send_args) |