diff options
author | Chris Mason <clm@fb.com> | 2016-01-11 08:59:32 -0500 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2016-01-11 08:59:32 -0500 |
commit | a3058101c17d2825f34a0ab5c37d93ead0f4d9dc (patch) | |
tree | 193417b02c4fa79b582b435e154761b91a501884 | |
parent | 511711af91f21d80b27f18b569352d6896562828 (diff) | |
parent | ee592d07716139ef7c3ea8049936cbc3aafbc533 (diff) |
Merge branch 'misc-for-4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux into for-linus-4.5
-rw-r--r-- | fs/btrfs/btrfs_inode.h | 4 | ||||
-rw-r--r-- | fs/btrfs/ctree.c | 9 | ||||
-rw-r--r-- | fs/btrfs/ctree.h | 9 | ||||
-rw-r--r-- | fs/btrfs/delayed-ref.c | 4 | ||||
-rw-r--r-- | fs/btrfs/delayed-ref.h | 8 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 1 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 27 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.h | 0 | ||||
-rw-r--r-- | fs/btrfs/file-item.c | 4 | ||||
-rw-r--r-- | fs/btrfs/free-space-cache.c | 2 | ||||
-rw-r--r-- | fs/btrfs/free-space-cache.h | 2 | ||||
-rw-r--r-- | fs/btrfs/inode-map.c | 6 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 101 | ||||
-rw-r--r-- | fs/btrfs/ioctl.c | 35 | ||||
-rw-r--r-- | fs/btrfs/relocation.c | 12 | ||||
-rw-r--r-- | fs/btrfs/scrub.c | 12 | ||||
-rw-r--r-- | fs/btrfs/super.c | 26 | ||||
-rw-r--r-- | fs/btrfs/tests/free-space-tests.c | 14 | ||||
-rw-r--r-- | fs/btrfs/transaction.c | 18 | ||||
-rw-r--r-- | fs/btrfs/transaction.h | 2 | ||||
-rw-r--r-- | fs/btrfs/volumes.c | 32 | ||||
-rw-r--r-- | fs/btrfs/xattr.c | 2 |
22 files changed, 186 insertions, 144 deletions
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 0ef5cc13fae2..61205e3bbefa 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h | |||
@@ -192,6 +192,10 @@ struct btrfs_inode { | |||
192 | /* File creation time. */ | 192 | /* File creation time. */ |
193 | struct timespec i_otime; | 193 | struct timespec i_otime; |
194 | 194 | ||
195 | /* Hook into fs_info->delayed_iputs */ | ||
196 | struct list_head delayed_iput; | ||
197 | long delayed_iput_count; | ||
198 | |||
195 | struct inode vfs_inode; | 199 | struct inode vfs_inode; |
196 | }; | 200 | }; |
197 | 201 | ||
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 5b8e235c4b6d..be1be0422ff4 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -2248,7 +2248,6 @@ static void reada_for_search(struct btrfs_root *root, | |||
2248 | u64 target; | 2248 | u64 target; |
2249 | u64 nread = 0; | 2249 | u64 nread = 0; |
2250 | u64 gen; | 2250 | u64 gen; |
2251 | int direction = path->reada; | ||
2252 | struct extent_buffer *eb; | 2251 | struct extent_buffer *eb; |
2253 | u32 nr; | 2252 | u32 nr; |
2254 | u32 blocksize; | 2253 | u32 blocksize; |
@@ -2276,16 +2275,16 @@ static void reada_for_search(struct btrfs_root *root, | |||
2276 | nr = slot; | 2275 | nr = slot; |
2277 | 2276 | ||
2278 | while (1) { | 2277 | while (1) { |
2279 | if (direction < 0) { | 2278 | if (path->reada == READA_BACK) { |
2280 | if (nr == 0) | 2279 | if (nr == 0) |
2281 | break; | 2280 | break; |
2282 | nr--; | 2281 | nr--; |
2283 | } else if (direction > 0) { | 2282 | } else if (path->reada == READA_FORWARD) { |
2284 | nr++; | 2283 | nr++; |
2285 | if (nr >= nritems) | 2284 | if (nr >= nritems) |
2286 | break; | 2285 | break; |
2287 | } | 2286 | } |
2288 | if (path->reada < 0 && objectid) { | 2287 | if (path->reada == READA_BACK && objectid) { |
2289 | btrfs_node_key(node, &disk_key, nr); | 2288 | btrfs_node_key(node, &disk_key, nr); |
2290 | if (btrfs_disk_key_objectid(&disk_key) != objectid) | 2289 | if (btrfs_disk_key_objectid(&disk_key) != objectid) |
2291 | break; | 2290 | break; |
@@ -2493,7 +2492,7 @@ read_block_for_search(struct btrfs_trans_handle *trans, | |||
2493 | btrfs_set_path_blocking(p); | 2492 | btrfs_set_path_blocking(p); |
2494 | 2493 | ||
2495 | free_extent_buffer(tmp); | 2494 | free_extent_buffer(tmp); |
2496 | if (p->reada) | 2495 | if (p->reada != READA_NONE) |
2497 | reada_for_search(root, p, level, slot, key->objectid); | 2496 | reada_for_search(root, p, level, slot, key->objectid); |
2498 | 2497 | ||
2499 | btrfs_release_path(p); | 2498 | btrfs_release_path(p); |
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 9a88d0c69be4..70c940582482 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -177,7 +177,7 @@ struct btrfs_ordered_sum; | |||
177 | /* csum types */ | 177 | /* csum types */ |
178 | #define BTRFS_CSUM_TYPE_CRC32 0 | 178 | #define BTRFS_CSUM_TYPE_CRC32 0 |
179 | 179 | ||
180 | static int btrfs_csum_sizes[] = { 4 }; | 180 | static const int btrfs_csum_sizes[] = { 4 }; |
181 | 181 | ||
182 | /* four bytes for CRC32 */ | 182 | /* four bytes for CRC32 */ |
183 | #define BTRFS_EMPTY_DIR_SIZE 0 | 183 | #define BTRFS_EMPTY_DIR_SIZE 0 |
@@ -598,14 +598,15 @@ struct btrfs_node { | |||
598 | * The slots array records the index of the item or block pointer | 598 | * The slots array records the index of the item or block pointer |
599 | * used while walking the tree. | 599 | * used while walking the tree. |
600 | */ | 600 | */ |
601 | enum { READA_NONE = 0, READA_BACK, READA_FORWARD }; | ||
601 | struct btrfs_path { | 602 | struct btrfs_path { |
602 | struct extent_buffer *nodes[BTRFS_MAX_LEVEL]; | 603 | struct extent_buffer *nodes[BTRFS_MAX_LEVEL]; |
603 | int slots[BTRFS_MAX_LEVEL]; | 604 | int slots[BTRFS_MAX_LEVEL]; |
604 | /* if there is real range locking, this locks field will change */ | 605 | /* if there is real range locking, this locks field will change */ |
605 | int locks[BTRFS_MAX_LEVEL]; | 606 | u8 locks[BTRFS_MAX_LEVEL]; |
606 | int reada; | 607 | u8 reada; |
607 | /* keep some upper locks as we walk down */ | 608 | /* keep some upper locks as we walk down */ |
608 | int lowest_level; | 609 | u8 lowest_level; |
609 | 610 | ||
610 | /* | 611 | /* |
611 | * set by btrfs_split_item, tells search_slot to keep all locks | 612 | * set by btrfs_split_item, tells search_slot to keep all locks |
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index e06dd75ad13f..914ac13bd92f 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c | |||
@@ -493,12 +493,12 @@ update_existing_head_ref(struct btrfs_delayed_ref_root *delayed_refs, | |||
493 | memcpy(&existing_ref->extent_op->key, | 493 | memcpy(&existing_ref->extent_op->key, |
494 | &ref->extent_op->key, | 494 | &ref->extent_op->key, |
495 | sizeof(ref->extent_op->key)); | 495 | sizeof(ref->extent_op->key)); |
496 | existing_ref->extent_op->update_key = 1; | 496 | existing_ref->extent_op->update_key = true; |
497 | } | 497 | } |
498 | if (ref->extent_op->update_flags) { | 498 | if (ref->extent_op->update_flags) { |
499 | existing_ref->extent_op->flags_to_set |= | 499 | existing_ref->extent_op->flags_to_set |= |
500 | ref->extent_op->flags_to_set; | 500 | ref->extent_op->flags_to_set; |
501 | existing_ref->extent_op->update_flags = 1; | 501 | existing_ref->extent_op->update_flags = true; |
502 | } | 502 | } |
503 | btrfs_free_delayed_extent_op(ref->extent_op); | 503 | btrfs_free_delayed_extent_op(ref->extent_op); |
504 | } | 504 | } |
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 00ed02cbf3e9..c24b653c7343 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h | |||
@@ -75,11 +75,11 @@ struct btrfs_delayed_ref_node { | |||
75 | 75 | ||
76 | struct btrfs_delayed_extent_op { | 76 | struct btrfs_delayed_extent_op { |
77 | struct btrfs_disk_key key; | 77 | struct btrfs_disk_key key; |
78 | u8 level; | ||
79 | bool update_key; | ||
80 | bool update_flags; | ||
81 | bool is_data; | ||
78 | u64 flags_to_set; | 82 | u64 flags_to_set; |
79 | int level; | ||
80 | unsigned int update_key:1; | ||
81 | unsigned int update_flags:1; | ||
82 | unsigned int is_data:1; | ||
83 | }; | 83 | }; |
84 | 84 | ||
85 | /* | 85 | /* |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index dc6b73a95342..c94457fde64d 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -2682,6 +2682,7 @@ int open_ctree(struct super_block *sb, | |||
2682 | if (btrfs_check_super_csum(bh->b_data)) { | 2682 | if (btrfs_check_super_csum(bh->b_data)) { |
2683 | printk(KERN_ERR "BTRFS: superblock checksum mismatch\n"); | 2683 | printk(KERN_ERR "BTRFS: superblock checksum mismatch\n"); |
2684 | err = -EINVAL; | 2684 | err = -EINVAL; |
2685 | brelse(bh); | ||
2685 | goto fail_alloc; | 2686 | goto fail_alloc; |
2686 | } | 2687 | } |
2687 | 2688 | ||
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index add4af641cfa..46a39336e3d6 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -437,7 +437,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) | |||
437 | */ | 437 | */ |
438 | path->skip_locking = 1; | 438 | path->skip_locking = 1; |
439 | path->search_commit_root = 1; | 439 | path->search_commit_root = 1; |
440 | path->reada = 1; | 440 | path->reada = READA_FORWARD; |
441 | 441 | ||
442 | key.objectid = last; | 442 | key.objectid = last; |
443 | key.offset = 0; | 443 | key.offset = 0; |
@@ -2131,7 +2131,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, | |||
2131 | if (!path) | 2131 | if (!path) |
2132 | return -ENOMEM; | 2132 | return -ENOMEM; |
2133 | 2133 | ||
2134 | path->reada = 1; | 2134 | path->reada = READA_FORWARD; |
2135 | path->leave_spinning = 1; | 2135 | path->leave_spinning = 1; |
2136 | /* this will setup the path even if it fails to insert the back ref */ | 2136 | /* this will setup the path even if it fails to insert the back ref */ |
2137 | ret = insert_inline_extent_backref(trans, fs_info->extent_root, path, | 2137 | ret = insert_inline_extent_backref(trans, fs_info->extent_root, path, |
@@ -2157,7 +2157,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, | |||
2157 | btrfs_mark_buffer_dirty(leaf); | 2157 | btrfs_mark_buffer_dirty(leaf); |
2158 | btrfs_release_path(path); | 2158 | btrfs_release_path(path); |
2159 | 2159 | ||
2160 | path->reada = 1; | 2160 | path->reada = READA_FORWARD; |
2161 | path->leave_spinning = 1; | 2161 | path->leave_spinning = 1; |
2162 | /* now insert the actual backref */ | 2162 | /* now insert the actual backref */ |
2163 | ret = insert_extent_backref(trans, root->fs_info->extent_root, | 2163 | ret = insert_extent_backref(trans, root->fs_info->extent_root, |
@@ -2270,7 +2270,7 @@ static int run_delayed_extent_op(struct btrfs_trans_handle *trans, | |||
2270 | } | 2270 | } |
2271 | 2271 | ||
2272 | again: | 2272 | again: |
2273 | path->reada = 1; | 2273 | path->reada = READA_FORWARD; |
2274 | path->leave_spinning = 1; | 2274 | path->leave_spinning = 1; |
2275 | ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, | 2275 | ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, |
2276 | path, 0, 1); | 2276 | path, 0, 1); |
@@ -3007,9 +3007,9 @@ int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, | |||
3007 | return -ENOMEM; | 3007 | return -ENOMEM; |
3008 | 3008 | ||
3009 | extent_op->flags_to_set = flags; | 3009 | extent_op->flags_to_set = flags; |
3010 | extent_op->update_flags = 1; | 3010 | extent_op->update_flags = true; |
3011 | extent_op->update_key = 0; | 3011 | extent_op->update_key = false; |
3012 | extent_op->is_data = is_data ? 1 : 0; | 3012 | extent_op->is_data = is_data ? true : false; |
3013 | extent_op->level = level; | 3013 | extent_op->level = level; |
3014 | 3014 | ||
3015 | ret = btrfs_add_delayed_extent_op(root->fs_info, trans, bytenr, | 3015 | ret = btrfs_add_delayed_extent_op(root->fs_info, trans, bytenr, |
@@ -6472,7 +6472,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
6472 | if (!path) | 6472 | if (!path) |
6473 | return -ENOMEM; | 6473 | return -ENOMEM; |
6474 | 6474 | ||
6475 | path->reada = 1; | 6475 | path->reada = READA_FORWARD; |
6476 | path->leave_spinning = 1; | 6476 | path->leave_spinning = 1; |
6477 | 6477 | ||
6478 | is_data = owner_objectid >= BTRFS_FIRST_FREE_OBJECTID; | 6478 | is_data = owner_objectid >= BTRFS_FIRST_FREE_OBJECTID; |
@@ -8031,12 +8031,9 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, | |||
8031 | else | 8031 | else |
8032 | memset(&extent_op->key, 0, sizeof(extent_op->key)); | 8032 | memset(&extent_op->key, 0, sizeof(extent_op->key)); |
8033 | extent_op->flags_to_set = flags; | 8033 | extent_op->flags_to_set = flags; |
8034 | if (skinny_metadata) | 8034 | extent_op->update_key = skinny_metadata ? false : true; |
8035 | extent_op->update_key = 0; | 8035 | extent_op->update_flags = true; |
8036 | else | 8036 | extent_op->is_data = false; |
8037 | extent_op->update_key = 1; | ||
8038 | extent_op->update_flags = 1; | ||
8039 | extent_op->is_data = 0; | ||
8040 | extent_op->level = level; | 8037 | extent_op->level = level; |
8041 | 8038 | ||
8042 | ret = btrfs_add_delayed_tree_ref(root->fs_info, trans, | 8039 | ret = btrfs_add_delayed_tree_ref(root->fs_info, trans, |
@@ -9745,7 +9742,7 @@ int btrfs_read_block_groups(struct btrfs_root *root) | |||
9745 | path = btrfs_alloc_path(); | 9742 | path = btrfs_alloc_path(); |
9746 | if (!path) | 9743 | if (!path) |
9747 | return -ENOMEM; | 9744 | return -ENOMEM; |
9748 | path->reada = 1; | 9745 | path->reada = READA_FORWARD; |
9749 | 9746 | ||
9750 | cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy); | 9747 | cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy); |
9751 | if (btrfs_test_opt(root, SPACE_CACHE) && | 9748 | if (btrfs_test_opt(root, SPACE_CACHE) && |
diff --git a/fs/btrfs/extent-tree.h b/fs/btrfs/extent-tree.h deleted file mode 100644 index e69de29bb2d1..000000000000 --- a/fs/btrfs/extent-tree.h +++ /dev/null | |||
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 58ece6558430..a67e1c828d0f 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -202,7 +202,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, | |||
202 | } | 202 | } |
203 | 203 | ||
204 | if (bio->bi_iter.bi_size > PAGE_CACHE_SIZE * 8) | 204 | if (bio->bi_iter.bi_size > PAGE_CACHE_SIZE * 8) |
205 | path->reada = 2; | 205 | path->reada = READA_FORWARD; |
206 | 206 | ||
207 | WARN_ON(bio->bi_vcnt <= 0); | 207 | WARN_ON(bio->bi_vcnt <= 0); |
208 | 208 | ||
@@ -328,7 +328,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, | |||
328 | 328 | ||
329 | if (search_commit) { | 329 | if (search_commit) { |
330 | path->skip_locking = 1; | 330 | path->skip_locking = 1; |
331 | path->reada = 2; | 331 | path->reada = READA_FORWARD; |
332 | path->search_commit_root = 1; | 332 | path->search_commit_root = 1; |
333 | } | 333 | } |
334 | 334 | ||
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 7c5992d0fd31..d468bfd3debc 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -2016,7 +2016,7 @@ static bool use_bitmap(struct btrfs_free_space_ctl *ctl, | |||
2016 | return true; | 2016 | return true; |
2017 | } | 2017 | } |
2018 | 2018 | ||
2019 | static struct btrfs_free_space_op free_space_op = { | 2019 | static const struct btrfs_free_space_op free_space_op = { |
2020 | .recalc_thresholds = recalculate_thresholds, | 2020 | .recalc_thresholds = recalculate_thresholds, |
2021 | .use_bitmap = use_bitmap, | 2021 | .use_bitmap = use_bitmap, |
2022 | }; | 2022 | }; |
diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h index f251865eb6f3..33178c490ace 100644 --- a/fs/btrfs/free-space-cache.h +++ b/fs/btrfs/free-space-cache.h | |||
@@ -37,7 +37,7 @@ struct btrfs_free_space_ctl { | |||
37 | int total_bitmaps; | 37 | int total_bitmaps; |
38 | int unit; | 38 | int unit; |
39 | u64 start; | 39 | u64 start; |
40 | struct btrfs_free_space_op *op; | 40 | const struct btrfs_free_space_op *op; |
41 | void *private; | 41 | void *private; |
42 | struct mutex cache_writeout_mutex; | 42 | struct mutex cache_writeout_mutex; |
43 | struct list_head trimming_ranges; | 43 | struct list_head trimming_ranges; |
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c index 767a6056ac45..1951ad69382f 100644 --- a/fs/btrfs/inode-map.c +++ b/fs/btrfs/inode-map.c | |||
@@ -48,7 +48,7 @@ static int caching_kthread(void *data) | |||
48 | /* Since the commit root is read-only, we can safely skip locking. */ | 48 | /* Since the commit root is read-only, we can safely skip locking. */ |
49 | path->skip_locking = 1; | 49 | path->skip_locking = 1; |
50 | path->search_commit_root = 1; | 50 | path->search_commit_root = 1; |
51 | path->reada = 2; | 51 | path->reada = READA_FORWARD; |
52 | 52 | ||
53 | key.objectid = BTRFS_FIRST_FREE_OBJECTID; | 53 | key.objectid = BTRFS_FIRST_FREE_OBJECTID; |
54 | key.offset = 0; | 54 | key.offset = 0; |
@@ -334,7 +334,7 @@ static bool use_bitmap(struct btrfs_free_space_ctl *ctl, | |||
334 | return true; | 334 | return true; |
335 | } | 335 | } |
336 | 336 | ||
337 | static struct btrfs_free_space_op free_ino_op = { | 337 | static const struct btrfs_free_space_op free_ino_op = { |
338 | .recalc_thresholds = recalculate_thresholds, | 338 | .recalc_thresholds = recalculate_thresholds, |
339 | .use_bitmap = use_bitmap, | 339 | .use_bitmap = use_bitmap, |
340 | }; | 340 | }; |
@@ -356,7 +356,7 @@ static bool pinned_use_bitmap(struct btrfs_free_space_ctl *ctl, | |||
356 | return false; | 356 | return false; |
357 | } | 357 | } |
358 | 358 | ||
359 | static struct btrfs_free_space_op pinned_free_ino_op = { | 359 | static const struct btrfs_free_space_op pinned_free_ino_op = { |
360 | .recalc_thresholds = pinned_recalc_thresholds, | 360 | .recalc_thresholds = pinned_recalc_thresholds, |
361 | .use_bitmap = pinned_use_bitmap, | 361 | .use_bitmap = pinned_use_bitmap, |
362 | }; | 362 | }; |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index bdb0008712c8..f09cf27245f9 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -81,17 +81,16 @@ static const struct inode_operations btrfs_file_inode_operations; | |||
81 | static const struct address_space_operations btrfs_aops; | 81 | static const struct address_space_operations btrfs_aops; |
82 | static const struct address_space_operations btrfs_symlink_aops; | 82 | static const struct address_space_operations btrfs_symlink_aops; |
83 | static const struct file_operations btrfs_dir_file_operations; | 83 | static const struct file_operations btrfs_dir_file_operations; |
84 | static struct extent_io_ops btrfs_extent_io_ops; | 84 | static const struct extent_io_ops btrfs_extent_io_ops; |
85 | 85 | ||
86 | static struct kmem_cache *btrfs_inode_cachep; | 86 | static struct kmem_cache *btrfs_inode_cachep; |
87 | static struct kmem_cache *btrfs_delalloc_work_cachep; | ||
88 | struct kmem_cache *btrfs_trans_handle_cachep; | 87 | struct kmem_cache *btrfs_trans_handle_cachep; |
89 | struct kmem_cache *btrfs_transaction_cachep; | 88 | struct kmem_cache *btrfs_transaction_cachep; |
90 | struct kmem_cache *btrfs_path_cachep; | 89 | struct kmem_cache *btrfs_path_cachep; |
91 | struct kmem_cache *btrfs_free_space_cachep; | 90 | struct kmem_cache *btrfs_free_space_cachep; |
92 | 91 | ||
93 | #define S_SHIFT 12 | 92 | #define S_SHIFT 12 |
94 | static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = { | 93 | static const unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = { |
95 | [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE, | 94 | [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE, |
96 | [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR, | 95 | [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR, |
97 | [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV, | 96 | [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV, |
@@ -3113,55 +3112,47 @@ static int btrfs_readpage_end_io_hook(struct btrfs_io_bio *io_bio, | |||
3113 | start, (size_t)(end - start + 1)); | 3112 | start, (size_t)(end - start + 1)); |
3114 | } | 3113 | } |
3115 | 3114 | ||
3116 | struct delayed_iput { | ||
3117 | struct list_head list; | ||
3118 | struct inode *inode; | ||
3119 | }; | ||
3120 | |||
3121 | /* JDM: If this is fs-wide, why can't we add a pointer to | ||
3122 | * btrfs_inode instead and avoid the allocation? */ | ||
3123 | void btrfs_add_delayed_iput(struct inode *inode) | 3115 | void btrfs_add_delayed_iput(struct inode *inode) |
3124 | { | 3116 | { |
3125 | struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; | 3117 | struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; |
3126 | struct delayed_iput *delayed; | 3118 | struct btrfs_inode *binode = BTRFS_I(inode); |
3127 | 3119 | ||
3128 | if (atomic_add_unless(&inode->i_count, -1, 1)) | 3120 | if (atomic_add_unless(&inode->i_count, -1, 1)) |
3129 | return; | 3121 | return; |
3130 | 3122 | ||
3131 | delayed = kmalloc(sizeof(*delayed), GFP_NOFS | __GFP_NOFAIL); | ||
3132 | delayed->inode = inode; | ||
3133 | |||
3134 | spin_lock(&fs_info->delayed_iput_lock); | 3123 | spin_lock(&fs_info->delayed_iput_lock); |
3135 | list_add_tail(&delayed->list, &fs_info->delayed_iputs); | 3124 | if (binode->delayed_iput_count == 0) { |
3125 | ASSERT(list_empty(&binode->delayed_iput)); | ||
3126 | list_add_tail(&binode->delayed_iput, &fs_info->delayed_iputs); | ||
3127 | } else { | ||
3128 | binode->delayed_iput_count++; | ||
3129 | } | ||
3136 | spin_unlock(&fs_info->delayed_iput_lock); | 3130 | spin_unlock(&fs_info->delayed_iput_lock); |
3137 | } | 3131 | } |
3138 | 3132 | ||
3139 | void btrfs_run_delayed_iputs(struct btrfs_root *root) | 3133 | void btrfs_run_delayed_iputs(struct btrfs_root *root) |
3140 | { | 3134 | { |
3141 | LIST_HEAD(list); | ||
3142 | struct btrfs_fs_info *fs_info = root->fs_info; | 3135 | struct btrfs_fs_info *fs_info = root->fs_info; |
3143 | struct delayed_iput *delayed; | ||
3144 | int empty; | ||
3145 | |||
3146 | spin_lock(&fs_info->delayed_iput_lock); | ||
3147 | empty = list_empty(&fs_info->delayed_iputs); | ||
3148 | spin_unlock(&fs_info->delayed_iput_lock); | ||
3149 | if (empty) | ||
3150 | return; | ||
3151 | 3136 | ||
3152 | down_read(&fs_info->delayed_iput_sem); | 3137 | down_read(&fs_info->delayed_iput_sem); |
3153 | |||
3154 | spin_lock(&fs_info->delayed_iput_lock); | 3138 | spin_lock(&fs_info->delayed_iput_lock); |
3155 | list_splice_init(&fs_info->delayed_iputs, &list); | 3139 | while (!list_empty(&fs_info->delayed_iputs)) { |
3156 | spin_unlock(&fs_info->delayed_iput_lock); | 3140 | struct btrfs_inode *inode; |
3157 | 3141 | ||
3158 | while (!list_empty(&list)) { | 3142 | inode = list_first_entry(&fs_info->delayed_iputs, |
3159 | delayed = list_entry(list.next, struct delayed_iput, list); | 3143 | struct btrfs_inode, delayed_iput); |
3160 | list_del(&delayed->list); | 3144 | if (inode->delayed_iput_count) { |
3161 | iput(delayed->inode); | 3145 | inode->delayed_iput_count--; |
3162 | kfree(delayed); | 3146 | list_move_tail(&inode->delayed_iput, |
3147 | &fs_info->delayed_iputs); | ||
3148 | } else { | ||
3149 | list_del_init(&inode->delayed_iput); | ||
3150 | } | ||
3151 | spin_unlock(&fs_info->delayed_iput_lock); | ||
3152 | iput(&inode->vfs_inode); | ||
3153 | spin_lock(&fs_info->delayed_iput_lock); | ||
3163 | } | 3154 | } |
3164 | 3155 | spin_unlock(&fs_info->delayed_iput_lock); | |
3165 | up_read(&root->fs_info->delayed_iput_sem); | 3156 | up_read(&root->fs_info->delayed_iput_sem); |
3166 | } | 3157 | } |
3167 | 3158 | ||
@@ -3358,7 +3349,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) | |||
3358 | ret = -ENOMEM; | 3349 | ret = -ENOMEM; |
3359 | goto out; | 3350 | goto out; |
3360 | } | 3351 | } |
3361 | path->reada = -1; | 3352 | path->reada = READA_BACK; |
3362 | 3353 | ||
3363 | key.objectid = BTRFS_ORPHAN_OBJECTID; | 3354 | key.objectid = BTRFS_ORPHAN_OBJECTID; |
3364 | key.type = BTRFS_ORPHAN_ITEM_KEY; | 3355 | key.type = BTRFS_ORPHAN_ITEM_KEY; |
@@ -4324,7 +4315,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, | |||
4324 | path = btrfs_alloc_path(); | 4315 | path = btrfs_alloc_path(); |
4325 | if (!path) | 4316 | if (!path) |
4326 | return -ENOMEM; | 4317 | return -ENOMEM; |
4327 | path->reada = -1; | 4318 | path->reada = READA_BACK; |
4328 | 4319 | ||
4329 | /* | 4320 | /* |
4330 | * We want to drop from the next block forward in case this new size is | 4321 | * We want to drop from the next block forward in case this new size is |
@@ -5760,7 +5751,7 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) | |||
5760 | if (!path) | 5751 | if (!path) |
5761 | return -ENOMEM; | 5752 | return -ENOMEM; |
5762 | 5753 | ||
5763 | path->reada = 1; | 5754 | path->reada = READA_FORWARD; |
5764 | 5755 | ||
5765 | if (key_type == BTRFS_DIR_INDEX_KEY) { | 5756 | if (key_type == BTRFS_DIR_INDEX_KEY) { |
5766 | INIT_LIST_HEAD(&ins_list); | 5757 | INIT_LIST_HEAD(&ins_list); |
@@ -6791,7 +6782,7 @@ again: | |||
6791 | * Chances are we'll be called again, so go ahead and do | 6782 | * Chances are we'll be called again, so go ahead and do |
6792 | * readahead | 6783 | * readahead |
6793 | */ | 6784 | */ |
6794 | path->reada = 1; | 6785 | path->reada = READA_FORWARD; |
6795 | } | 6786 | } |
6796 | 6787 | ||
6797 | ret = btrfs_lookup_file_extent(trans, root, path, | 6788 | ret = btrfs_lookup_file_extent(trans, root, path, |
@@ -8563,15 +8554,28 @@ int btrfs_readpage(struct file *file, struct page *page) | |||
8563 | static int btrfs_writepage(struct page *page, struct writeback_control *wbc) | 8554 | static int btrfs_writepage(struct page *page, struct writeback_control *wbc) |
8564 | { | 8555 | { |
8565 | struct extent_io_tree *tree; | 8556 | struct extent_io_tree *tree; |
8566 | 8557 | struct inode *inode = page->mapping->host; | |
8558 | int ret; | ||
8567 | 8559 | ||
8568 | if (current->flags & PF_MEMALLOC) { | 8560 | if (current->flags & PF_MEMALLOC) { |
8569 | redirty_page_for_writepage(wbc, page); | 8561 | redirty_page_for_writepage(wbc, page); |
8570 | unlock_page(page); | 8562 | unlock_page(page); |
8571 | return 0; | 8563 | return 0; |
8572 | } | 8564 | } |
8565 | |||
8566 | /* | ||
8567 | * If we are under memory pressure we will call this directly from the | ||
8568 | * VM, we need to make sure we have the inode referenced for the ordered | ||
8569 | * extent. If not just return like we didn't do anything. | ||
8570 | */ | ||
8571 | if (!igrab(inode)) { | ||
8572 | redirty_page_for_writepage(wbc, page); | ||
8573 | return AOP_WRITEPAGE_ACTIVATE; | ||
8574 | } | ||
8573 | tree = &BTRFS_I(page->mapping->host)->io_tree; | 8575 | tree = &BTRFS_I(page->mapping->host)->io_tree; |
8574 | return extent_write_full_page(tree, page, btrfs_get_extent, wbc); | 8576 | ret = extent_write_full_page(tree, page, btrfs_get_extent, wbc); |
8577 | btrfs_add_delayed_iput(inode); | ||
8578 | return ret; | ||
8575 | } | 8579 | } |
8576 | 8580 | ||
8577 | static int btrfs_writepages(struct address_space *mapping, | 8581 | static int btrfs_writepages(struct address_space *mapping, |
@@ -9053,6 +9057,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
9053 | ei->dir_index = 0; | 9057 | ei->dir_index = 0; |
9054 | ei->last_unlink_trans = 0; | 9058 | ei->last_unlink_trans = 0; |
9055 | ei->last_log_commit = 0; | 9059 | ei->last_log_commit = 0; |
9060 | ei->delayed_iput_count = 0; | ||
9056 | 9061 | ||
9057 | spin_lock_init(&ei->lock); | 9062 | spin_lock_init(&ei->lock); |
9058 | ei->outstanding_extents = 0; | 9063 | ei->outstanding_extents = 0; |
@@ -9077,6 +9082,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
9077 | mutex_init(&ei->delalloc_mutex); | 9082 | mutex_init(&ei->delalloc_mutex); |
9078 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); | 9083 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); |
9079 | INIT_LIST_HEAD(&ei->delalloc_inodes); | 9084 | INIT_LIST_HEAD(&ei->delalloc_inodes); |
9085 | INIT_LIST_HEAD(&ei->delayed_iput); | ||
9080 | RB_CLEAR_NODE(&ei->rb_node); | 9086 | RB_CLEAR_NODE(&ei->rb_node); |
9081 | 9087 | ||
9082 | return inode; | 9088 | return inode; |
@@ -9181,8 +9187,6 @@ void btrfs_destroy_cachep(void) | |||
9181 | kmem_cache_destroy(btrfs_path_cachep); | 9187 | kmem_cache_destroy(btrfs_path_cachep); |
9182 | if (btrfs_free_space_cachep) | 9188 | if (btrfs_free_space_cachep) |
9183 | kmem_cache_destroy(btrfs_free_space_cachep); | 9189 | kmem_cache_destroy(btrfs_free_space_cachep); |
9184 | if (btrfs_delalloc_work_cachep) | ||
9185 | kmem_cache_destroy(btrfs_delalloc_work_cachep); | ||
9186 | } | 9190 | } |
9187 | 9191 | ||
9188 | int btrfs_init_cachep(void) | 9192 | int btrfs_init_cachep(void) |
@@ -9217,13 +9221,6 @@ int btrfs_init_cachep(void) | |||
9217 | if (!btrfs_free_space_cachep) | 9221 | if (!btrfs_free_space_cachep) |
9218 | goto fail; | 9222 | goto fail; |
9219 | 9223 | ||
9220 | btrfs_delalloc_work_cachep = kmem_cache_create("btrfs_delalloc_work", | ||
9221 | sizeof(struct btrfs_delalloc_work), 0, | ||
9222 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, | ||
9223 | NULL); | ||
9224 | if (!btrfs_delalloc_work_cachep) | ||
9225 | goto fail; | ||
9226 | |||
9227 | return 0; | 9224 | return 0; |
9228 | fail: | 9225 | fail: |
9229 | btrfs_destroy_cachep(); | 9226 | btrfs_destroy_cachep(); |
@@ -9464,7 +9461,7 @@ struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode, | |||
9464 | { | 9461 | { |
9465 | struct btrfs_delalloc_work *work; | 9462 | struct btrfs_delalloc_work *work; |
9466 | 9463 | ||
9467 | work = kmem_cache_zalloc(btrfs_delalloc_work_cachep, GFP_NOFS); | 9464 | work = kmalloc(sizeof(*work), GFP_NOFS); |
9468 | if (!work) | 9465 | if (!work) |
9469 | return NULL; | 9466 | return NULL; |
9470 | 9467 | ||
@@ -9482,7 +9479,7 @@ struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode, | |||
9482 | void btrfs_wait_and_free_delalloc_work(struct btrfs_delalloc_work *work) | 9479 | void btrfs_wait_and_free_delalloc_work(struct btrfs_delalloc_work *work) |
9483 | { | 9480 | { |
9484 | wait_for_completion(&work->completion); | 9481 | wait_for_completion(&work->completion); |
9485 | kmem_cache_free(btrfs_delalloc_work_cachep, work); | 9482 | kfree(work); |
9486 | } | 9483 | } |
9487 | 9484 | ||
9488 | /* | 9485 | /* |
@@ -10047,7 +10044,7 @@ static const struct file_operations btrfs_dir_file_operations = { | |||
10047 | .fsync = btrfs_sync_file, | 10044 | .fsync = btrfs_sync_file, |
10048 | }; | 10045 | }; |
10049 | 10046 | ||
10050 | static struct extent_io_ops btrfs_extent_io_ops = { | 10047 | static const struct extent_io_ops btrfs_extent_io_ops = { |
10051 | .fill_delalloc = run_delalloc_range, | 10048 | .fill_delalloc = run_delalloc_range, |
10052 | .submit_bio_hook = btrfs_submit_bio_hook, | 10049 | .submit_bio_hook = btrfs_submit_bio_hook, |
10053 | .merge_bio_hook = btrfs_merge_bio_hook, | 10050 | .merge_bio_hook = btrfs_merge_bio_hook, |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 8bbecdaf58a3..f8519b866c0a 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -655,22 +655,28 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, | |||
655 | if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) | 655 | if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) |
656 | return -EINVAL; | 656 | return -EINVAL; |
657 | 657 | ||
658 | pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS); | ||
659 | if (!pending_snapshot) | ||
660 | return -ENOMEM; | ||
661 | |||
662 | pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item), | ||
663 | GFP_NOFS); | ||
664 | pending_snapshot->path = btrfs_alloc_path(); | ||
665 | if (!pending_snapshot->root_item || !pending_snapshot->path) { | ||
666 | ret = -ENOMEM; | ||
667 | goto free_pending; | ||
668 | } | ||
669 | |||
658 | atomic_inc(&root->will_be_snapshoted); | 670 | atomic_inc(&root->will_be_snapshoted); |
659 | smp_mb__after_atomic(); | 671 | smp_mb__after_atomic(); |
660 | btrfs_wait_for_no_snapshoting_writes(root); | 672 | btrfs_wait_for_no_snapshoting_writes(root); |
661 | 673 | ||
662 | ret = btrfs_start_delalloc_inodes(root, 0); | 674 | ret = btrfs_start_delalloc_inodes(root, 0); |
663 | if (ret) | 675 | if (ret) |
664 | goto out; | 676 | goto dec_and_free; |
665 | 677 | ||
666 | btrfs_wait_ordered_extents(root, -1); | 678 | btrfs_wait_ordered_extents(root, -1); |
667 | 679 | ||
668 | pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS); | ||
669 | if (!pending_snapshot) { | ||
670 | ret = -ENOMEM; | ||
671 | goto out; | ||
672 | } | ||
673 | |||
674 | btrfs_init_block_rsv(&pending_snapshot->block_rsv, | 680 | btrfs_init_block_rsv(&pending_snapshot->block_rsv, |
675 | BTRFS_BLOCK_RSV_TEMP); | 681 | BTRFS_BLOCK_RSV_TEMP); |
676 | /* | 682 | /* |
@@ -686,7 +692,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, | |||
686 | &pending_snapshot->qgroup_reserved, | 692 | &pending_snapshot->qgroup_reserved, |
687 | false); | 693 | false); |
688 | if (ret) | 694 | if (ret) |
689 | goto free; | 695 | goto dec_and_free; |
690 | 696 | ||
691 | pending_snapshot->dentry = dentry; | 697 | pending_snapshot->dentry = dentry; |
692 | pending_snapshot->root = root; | 698 | pending_snapshot->root = root; |
@@ -737,11 +743,14 @@ fail: | |||
737 | btrfs_subvolume_release_metadata(BTRFS_I(dir)->root, | 743 | btrfs_subvolume_release_metadata(BTRFS_I(dir)->root, |
738 | &pending_snapshot->block_rsv, | 744 | &pending_snapshot->block_rsv, |
739 | pending_snapshot->qgroup_reserved); | 745 | pending_snapshot->qgroup_reserved); |
740 | free: | 746 | dec_and_free: |
741 | kfree(pending_snapshot); | ||
742 | out: | ||
743 | if (atomic_dec_and_test(&root->will_be_snapshoted)) | 747 | if (atomic_dec_and_test(&root->will_be_snapshoted)) |
744 | wake_up_atomic_t(&root->will_be_snapshoted); | 748 | wake_up_atomic_t(&root->will_be_snapshoted); |
749 | free_pending: | ||
750 | kfree(pending_snapshot->root_item); | ||
751 | btrfs_free_path(pending_snapshot->path); | ||
752 | kfree(pending_snapshot); | ||
753 | |||
745 | return ret; | 754 | return ret; |
746 | } | 755 | } |
747 | 756 | ||
@@ -3478,7 +3487,7 @@ static int btrfs_clone(struct inode *src, struct inode *inode, | |||
3478 | return ret; | 3487 | return ret; |
3479 | } | 3488 | } |
3480 | 3489 | ||
3481 | path->reada = 2; | 3490 | path->reada = READA_FORWARD; |
3482 | /* clone data */ | 3491 | /* clone data */ |
3483 | key.objectid = btrfs_ino(src); | 3492 | key.objectid = btrfs_ino(src); |
3484 | key.type = BTRFS_EXTENT_DATA_KEY; | 3493 | key.type = BTRFS_EXTENT_DATA_KEY; |
@@ -5286,7 +5295,7 @@ out_unlock: | |||
5286 | static int btrfs_ioctl_get_supported_features(struct file *file, | 5295 | static int btrfs_ioctl_get_supported_features(struct file *file, |
5287 | void __user *arg) | 5296 | void __user *arg) |
5288 | { | 5297 | { |
5289 | static struct btrfs_ioctl_feature_flags features[3] = { | 5298 | static const struct btrfs_ioctl_feature_flags features[3] = { |
5290 | INIT_FEATURE_FLAGS(SUPP), | 5299 | INIT_FEATURE_FLAGS(SUPP), |
5291 | INIT_FEATURE_FLAGS(SAFE_SET), | 5300 | INIT_FEATURE_FLAGS(SAFE_SET), |
5292 | INIT_FEATURE_FLAGS(SAFE_CLEAR) | 5301 | INIT_FEATURE_FLAGS(SAFE_CLEAR) |
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index b4ca5454ef1a..ef6d8fc85853 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c | |||
@@ -708,8 +708,8 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, | |||
708 | err = -ENOMEM; | 708 | err = -ENOMEM; |
709 | goto out; | 709 | goto out; |
710 | } | 710 | } |
711 | path1->reada = 1; | 711 | path1->reada = READA_FORWARD; |
712 | path2->reada = 2; | 712 | path2->reada = READA_FORWARD; |
713 | 713 | ||
714 | node = alloc_backref_node(cache); | 714 | node = alloc_backref_node(cache); |
715 | if (!node) { | 715 | if (!node) { |
@@ -2130,7 +2130,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc, | |||
2130 | path = btrfs_alloc_path(); | 2130 | path = btrfs_alloc_path(); |
2131 | if (!path) | 2131 | if (!path) |
2132 | return -ENOMEM; | 2132 | return -ENOMEM; |
2133 | path->reada = 1; | 2133 | path->reada = READA_FORWARD; |
2134 | 2134 | ||
2135 | reloc_root = root->reloc_root; | 2135 | reloc_root = root->reloc_root; |
2136 | root_item = &reloc_root->root_item; | 2136 | root_item = &reloc_root->root_item; |
@@ -3527,7 +3527,7 @@ static int find_data_references(struct reloc_control *rc, | |||
3527 | path = btrfs_alloc_path(); | 3527 | path = btrfs_alloc_path(); |
3528 | if (!path) | 3528 | if (!path) |
3529 | return -ENOMEM; | 3529 | return -ENOMEM; |
3530 | path->reada = 1; | 3530 | path->reada = READA_FORWARD; |
3531 | 3531 | ||
3532 | root = read_fs_root(rc->extent_root->fs_info, ref_root); | 3532 | root = read_fs_root(rc->extent_root->fs_info, ref_root); |
3533 | if (IS_ERR(root)) { | 3533 | if (IS_ERR(root)) { |
@@ -3917,7 +3917,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) | |||
3917 | path = btrfs_alloc_path(); | 3917 | path = btrfs_alloc_path(); |
3918 | if (!path) | 3918 | if (!path) |
3919 | return -ENOMEM; | 3919 | return -ENOMEM; |
3920 | path->reada = 1; | 3920 | path->reada = READA_FORWARD; |
3921 | 3921 | ||
3922 | ret = prepare_to_relocate(rc); | 3922 | ret = prepare_to_relocate(rc); |
3923 | if (ret) { | 3923 | if (ret) { |
@@ -4343,7 +4343,7 @@ int btrfs_recover_relocation(struct btrfs_root *root) | |||
4343 | path = btrfs_alloc_path(); | 4343 | path = btrfs_alloc_path(); |
4344 | if (!path) | 4344 | if (!path) |
4345 | return -ENOMEM; | 4345 | return -ENOMEM; |
4346 | path->reada = -1; | 4346 | path->reada = READA_BACK; |
4347 | 4347 | ||
4348 | key.objectid = BTRFS_TREE_RELOC_OBJECTID; | 4348 | key.objectid = BTRFS_TREE_RELOC_OBJECTID; |
4349 | key.type = BTRFS_ROOT_ITEM_KEY; | 4349 | key.type = BTRFS_ROOT_ITEM_KEY; |
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 69987150ddfa..dbfbfb3b86b5 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
@@ -3507,7 +3507,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, | |||
3507 | if (!path) | 3507 | if (!path) |
3508 | return -ENOMEM; | 3508 | return -ENOMEM; |
3509 | 3509 | ||
3510 | path->reada = 2; | 3510 | path->reada = READA_FORWARD; |
3511 | path->search_commit_root = 1; | 3511 | path->search_commit_root = 1; |
3512 | path->skip_locking = 1; | 3512 | path->skip_locking = 1; |
3513 | 3513 | ||
@@ -3735,27 +3735,27 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info, | |||
3735 | if (fs_info->scrub_workers_refcnt == 0) { | 3735 | if (fs_info->scrub_workers_refcnt == 0) { |
3736 | if (is_dev_replace) | 3736 | if (is_dev_replace) |
3737 | fs_info->scrub_workers = | 3737 | fs_info->scrub_workers = |
3738 | btrfs_alloc_workqueue("btrfs-scrub", flags, | 3738 | btrfs_alloc_workqueue("scrub", flags, |
3739 | 1, 4); | 3739 | 1, 4); |
3740 | else | 3740 | else |
3741 | fs_info->scrub_workers = | 3741 | fs_info->scrub_workers = |
3742 | btrfs_alloc_workqueue("btrfs-scrub", flags, | 3742 | btrfs_alloc_workqueue("scrub", flags, |
3743 | max_active, 4); | 3743 | max_active, 4); |
3744 | if (!fs_info->scrub_workers) | 3744 | if (!fs_info->scrub_workers) |
3745 | goto fail_scrub_workers; | 3745 | goto fail_scrub_workers; |
3746 | 3746 | ||
3747 | fs_info->scrub_wr_completion_workers = | 3747 | fs_info->scrub_wr_completion_workers = |
3748 | btrfs_alloc_workqueue("btrfs-scrubwrc", flags, | 3748 | btrfs_alloc_workqueue("scrubwrc", flags, |
3749 | max_active, 2); | 3749 | max_active, 2); |
3750 | if (!fs_info->scrub_wr_completion_workers) | 3750 | if (!fs_info->scrub_wr_completion_workers) |
3751 | goto fail_scrub_wr_completion_workers; | 3751 | goto fail_scrub_wr_completion_workers; |
3752 | 3752 | ||
3753 | fs_info->scrub_nocow_workers = | 3753 | fs_info->scrub_nocow_workers = |
3754 | btrfs_alloc_workqueue("btrfs-scrubnc", flags, 1, 0); | 3754 | btrfs_alloc_workqueue("scrubnc", flags, 1, 0); |
3755 | if (!fs_info->scrub_nocow_workers) | 3755 | if (!fs_info->scrub_nocow_workers) |
3756 | goto fail_scrub_nocow_workers; | 3756 | goto fail_scrub_nocow_workers; |
3757 | fs_info->scrub_parity_workers = | 3757 | fs_info->scrub_parity_workers = |
3758 | btrfs_alloc_workqueue("btrfs-scrubparity", flags, | 3758 | btrfs_alloc_workqueue("scrubparity", flags, |
3759 | max_active, 2); | 3759 | max_active, 2); |
3760 | if (!fs_info->scrub_parity_workers) | 3760 | if (!fs_info->scrub_parity_workers) |
3761 | goto fail_scrub_parity_workers; | 3761 | goto fail_scrub_parity_workers; |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 9153d54d27c8..ff15087052f5 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -310,7 +310,7 @@ enum { | |||
310 | Opt_err, | 310 | Opt_err, |
311 | }; | 311 | }; |
312 | 312 | ||
313 | static match_table_t tokens = { | 313 | static const match_table_t tokens = { |
314 | {Opt_degraded, "degraded"}, | 314 | {Opt_degraded, "degraded"}, |
315 | {Opt_subvol, "subvol=%s"}, | 315 | {Opt_subvol, "subvol=%s"}, |
316 | {Opt_subvolid, "subvolid=%s"}, | 316 | {Opt_subvolid, "subvolid=%s"}, |
@@ -1991,6 +1991,8 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes) | |||
1991 | * there are other factors that may change the result (like a new metadata | 1991 | * there are other factors that may change the result (like a new metadata |
1992 | * chunk). | 1992 | * chunk). |
1993 | * | 1993 | * |
1994 | * If metadata is exhausted, f_bavail will be 0. | ||
1995 | * | ||
1994 | * FIXME: not accurate for mixed block groups, total and free/used are ok, | 1996 | * FIXME: not accurate for mixed block groups, total and free/used are ok, |
1995 | * available appears slightly larger. | 1997 | * available appears slightly larger. |
1996 | */ | 1998 | */ |
@@ -2002,11 +2004,13 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
2002 | struct btrfs_space_info *found; | 2004 | struct btrfs_space_info *found; |
2003 | u64 total_used = 0; | 2005 | u64 total_used = 0; |
2004 | u64 total_free_data = 0; | 2006 | u64 total_free_data = 0; |
2007 | u64 total_free_meta = 0; | ||
2005 | int bits = dentry->d_sb->s_blocksize_bits; | 2008 | int bits = dentry->d_sb->s_blocksize_bits; |
2006 | __be32 *fsid = (__be32 *)fs_info->fsid; | 2009 | __be32 *fsid = (__be32 *)fs_info->fsid; |
2007 | unsigned factor = 1; | 2010 | unsigned factor = 1; |
2008 | struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv; | 2011 | struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv; |
2009 | int ret; | 2012 | int ret; |
2013 | u64 thresh = 0; | ||
2010 | 2014 | ||
2011 | /* | 2015 | /* |
2012 | * holding chunk_muext to avoid allocating new chunks, holding | 2016 | * holding chunk_muext to avoid allocating new chunks, holding |
@@ -2032,6 +2036,8 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
2032 | } | 2036 | } |
2033 | } | 2037 | } |
2034 | } | 2038 | } |
2039 | if (found->flags & BTRFS_BLOCK_GROUP_METADATA) | ||
2040 | total_free_meta += found->disk_total - found->disk_used; | ||
2035 | 2041 | ||
2036 | total_used += found->disk_used; | 2042 | total_used += found->disk_used; |
2037 | } | 2043 | } |
@@ -2054,6 +2060,24 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
2054 | buf->f_bavail += div_u64(total_free_data, factor); | 2060 | buf->f_bavail += div_u64(total_free_data, factor); |
2055 | buf->f_bavail = buf->f_bavail >> bits; | 2061 | buf->f_bavail = buf->f_bavail >> bits; |
2056 | 2062 | ||
2063 | /* | ||
2064 | * We calculate the remaining metadata space minus global reserve. If | ||
2065 | * this is (supposedly) smaller than zero, there's no space. But this | ||
2066 | * does not hold in practice, the exhausted state happens where's still | ||
2067 | * some positive delta. So we apply some guesswork and compare the | ||
2068 | * delta to a 4M threshold. (Practically observed delta was ~2M.) | ||
2069 | * | ||
2070 | * We probably cannot calculate the exact threshold value because this | ||
2071 | * depends on the internal reservations requested by various | ||
2072 | * operations, so some operations that consume a few metadata will | ||
2073 | * succeed even if the Avail is zero. But this is better than the other | ||
2074 | * way around. | ||
2075 | */ | ||
2076 | thresh = 4 * 1024 * 1024; | ||
2077 | |||
2078 | if (total_free_meta - thresh < block_rsv->size) | ||
2079 | buf->f_bavail = 0; | ||
2080 | |||
2057 | buf->f_type = BTRFS_SUPER_MAGIC; | 2081 | buf->f_type = BTRFS_SUPER_MAGIC; |
2058 | buf->f_bsize = dentry->d_sb->s_blocksize; | 2082 | buf->f_bsize = dentry->d_sb->s_blocksize; |
2059 | buf->f_namelen = BTRFS_NAME_LEN; | 2083 | buf->f_namelen = BTRFS_NAME_LEN; |
diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c index cd3e300b9ba5..e37d55ecdf1f 100644 --- a/fs/btrfs/tests/free-space-tests.c +++ b/fs/btrfs/tests/free-space-tests.c | |||
@@ -410,9 +410,11 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) | |||
410 | int ret; | 410 | int ret; |
411 | u64 offset; | 411 | u64 offset; |
412 | u64 max_extent_size; | 412 | u64 max_extent_size; |
413 | 413 | const struct btrfs_free_space_op test_free_space_ops = { | |
414 | bool (*use_bitmap_op)(struct btrfs_free_space_ctl *, | 414 | .recalc_thresholds = cache->free_space_ctl->op->recalc_thresholds, |
415 | struct btrfs_free_space *); | 415 | .use_bitmap = test_use_bitmap, |
416 | }; | ||
417 | const struct btrfs_free_space_op *orig_free_space_ops; | ||
416 | 418 | ||
417 | test_msg("Running space stealing from bitmap to extent\n"); | 419 | test_msg("Running space stealing from bitmap to extent\n"); |
418 | 420 | ||
@@ -434,8 +436,8 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) | |||
434 | * that forces use of bitmaps as soon as we have at least 1 | 436 | * that forces use of bitmaps as soon as we have at least 1 |
435 | * extent entry. | 437 | * extent entry. |
436 | */ | 438 | */ |
437 | use_bitmap_op = cache->free_space_ctl->op->use_bitmap; | 439 | orig_free_space_ops = cache->free_space_ctl->op; |
438 | cache->free_space_ctl->op->use_bitmap = test_use_bitmap; | 440 | cache->free_space_ctl->op = &test_free_space_ops; |
439 | 441 | ||
440 | /* | 442 | /* |
441 | * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[ | 443 | * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[ |
@@ -842,7 +844,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) | |||
842 | if (ret) | 844 | if (ret) |
843 | return ret; | 845 | return ret; |
844 | 846 | ||
845 | cache->free_space_ctl->op->use_bitmap = use_bitmap_op; | 847 | cache->free_space_ctl->op = orig_free_space_ops; |
846 | __btrfs_remove_free_space_cache(cache->free_space_ctl); | 848 | __btrfs_remove_free_space_cache(cache->free_space_ctl); |
847 | 849 | ||
848 | return 0; | 850 | return 0; |
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index f85ccf634ca1..34961f02e58c 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -1336,17 +1336,11 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
1336 | u64 root_flags; | 1336 | u64 root_flags; |
1337 | uuid_le new_uuid; | 1337 | uuid_le new_uuid; |
1338 | 1338 | ||
1339 | path = btrfs_alloc_path(); | 1339 | ASSERT(pending->path); |
1340 | if (!path) { | 1340 | path = pending->path; |
1341 | pending->error = -ENOMEM; | ||
1342 | return 0; | ||
1343 | } | ||
1344 | 1341 | ||
1345 | new_root_item = kmalloc(sizeof(*new_root_item), GFP_NOFS); | 1342 | ASSERT(pending->root_item); |
1346 | if (!new_root_item) { | 1343 | new_root_item = pending->root_item; |
1347 | pending->error = -ENOMEM; | ||
1348 | goto root_item_alloc_fail; | ||
1349 | } | ||
1350 | 1344 | ||
1351 | pending->error = btrfs_find_free_objectid(tree_root, &objectid); | 1345 | pending->error = btrfs_find_free_objectid(tree_root, &objectid); |
1352 | if (pending->error) | 1346 | if (pending->error) |
@@ -1579,8 +1573,10 @@ clear_skip_qgroup: | |||
1579 | btrfs_clear_skip_qgroup(trans); | 1573 | btrfs_clear_skip_qgroup(trans); |
1580 | no_free_objectid: | 1574 | no_free_objectid: |
1581 | kfree(new_root_item); | 1575 | kfree(new_root_item); |
1582 | root_item_alloc_fail: | 1576 | pending->root_item = NULL; |
1583 | btrfs_free_path(path); | 1577 | btrfs_free_path(path); |
1578 | pending->path = NULL; | ||
1579 | |||
1584 | return ret; | 1580 | return ret; |
1585 | } | 1581 | } |
1586 | 1582 | ||
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index 64c8221b6165..72be51f7ca2f 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h | |||
@@ -137,8 +137,10 @@ struct btrfs_pending_snapshot { | |||
137 | struct dentry *dentry; | 137 | struct dentry *dentry; |
138 | struct inode *dir; | 138 | struct inode *dir; |
139 | struct btrfs_root *root; | 139 | struct btrfs_root *root; |
140 | struct btrfs_root_item *root_item; | ||
140 | struct btrfs_root *snap; | 141 | struct btrfs_root *snap; |
141 | struct btrfs_qgroup_inherit *inherit; | 142 | struct btrfs_qgroup_inherit *inherit; |
143 | struct btrfs_path *path; | ||
142 | /* block reservation for the operation */ | 144 | /* block reservation for the operation */ |
143 | struct btrfs_block_rsv block_rsv; | 145 | struct btrfs_block_rsv block_rsv; |
144 | u64 qgroup_reserved; | 146 | u64 qgroup_reserved; |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index a114b7bb87a0..2fa5ba814120 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -1103,7 +1103,7 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start, | |||
1103 | path = btrfs_alloc_path(); | 1103 | path = btrfs_alloc_path(); |
1104 | if (!path) | 1104 | if (!path) |
1105 | return -ENOMEM; | 1105 | return -ENOMEM; |
1106 | path->reada = 2; | 1106 | path->reada = READA_FORWARD; |
1107 | 1107 | ||
1108 | key.objectid = device->devid; | 1108 | key.objectid = device->devid; |
1109 | key.offset = start; | 1109 | key.offset = start; |
@@ -1272,7 +1272,7 @@ again: | |||
1272 | goto out; | 1272 | goto out; |
1273 | } | 1273 | } |
1274 | 1274 | ||
1275 | path->reada = 2; | 1275 | path->reada = READA_FORWARD; |
1276 | path->search_commit_root = 1; | 1276 | path->search_commit_root = 1; |
1277 | path->skip_locking = 1; | 1277 | path->skip_locking = 1; |
1278 | 1278 | ||
@@ -3724,14 +3724,6 @@ int btrfs_balance(struct btrfs_balance_control *bctl, | |||
3724 | goto out; | 3724 | goto out; |
3725 | } | 3725 | } |
3726 | 3726 | ||
3727 | /* allow dup'ed data chunks only in mixed mode */ | ||
3728 | if (!mixed && (bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) && | ||
3729 | (bctl->data.target & BTRFS_BLOCK_GROUP_DUP)) { | ||
3730 | btrfs_err(fs_info, "dup for data is not allowed"); | ||
3731 | ret = -EINVAL; | ||
3732 | goto out; | ||
3733 | } | ||
3734 | |||
3735 | /* allow to reduce meta or sys integrity only if force set */ | 3727 | /* allow to reduce meta or sys integrity only if force set */ |
3736 | allowed = BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1 | | 3728 | allowed = BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1 | |
3737 | BTRFS_BLOCK_GROUP_RAID10 | | 3729 | BTRFS_BLOCK_GROUP_RAID10 | |
@@ -3757,6 +3749,13 @@ int btrfs_balance(struct btrfs_balance_control *bctl, | |||
3757 | } | 3749 | } |
3758 | } while (read_seqretry(&fs_info->profiles_lock, seq)); | 3750 | } while (read_seqretry(&fs_info->profiles_lock, seq)); |
3759 | 3751 | ||
3752 | if (btrfs_get_num_tolerated_disk_barrier_failures(bctl->meta.target) < | ||
3753 | btrfs_get_num_tolerated_disk_barrier_failures(bctl->data.target)) { | ||
3754 | btrfs_warn(fs_info, | ||
3755 | "metatdata profile 0x%llx has lower redundancy than data profile 0x%llx", | ||
3756 | bctl->meta.target, bctl->data.target); | ||
3757 | } | ||
3758 | |||
3760 | if (bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) { | 3759 | if (bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) { |
3761 | fs_info->num_tolerated_disk_barrier_failures = min( | 3760 | fs_info->num_tolerated_disk_barrier_failures = min( |
3762 | btrfs_calc_num_tolerated_disk_barrier_failures(fs_info), | 3761 | btrfs_calc_num_tolerated_disk_barrier_failures(fs_info), |
@@ -4269,7 +4268,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) | |||
4269 | if (!path) | 4268 | if (!path) |
4270 | return -ENOMEM; | 4269 | return -ENOMEM; |
4271 | 4270 | ||
4272 | path->reada = 2; | 4271 | path->reada = READA_FORWARD; |
4273 | 4272 | ||
4274 | lock_chunks(root); | 4273 | lock_chunks(root); |
4275 | 4274 | ||
@@ -6526,6 +6525,14 @@ int btrfs_read_sys_array(struct btrfs_root *root) | |||
6526 | goto out_short_read; | 6525 | goto out_short_read; |
6527 | 6526 | ||
6528 | num_stripes = btrfs_chunk_num_stripes(sb, chunk); | 6527 | num_stripes = btrfs_chunk_num_stripes(sb, chunk); |
6528 | if (!num_stripes) { | ||
6529 | printk(KERN_ERR | ||
6530 | "BTRFS: invalid number of stripes %u in sys_array at offset %u\n", | ||
6531 | num_stripes, cur_offset); | ||
6532 | ret = -EIO; | ||
6533 | break; | ||
6534 | } | ||
6535 | |||
6529 | len = btrfs_chunk_item_size(num_stripes); | 6536 | len = btrfs_chunk_item_size(num_stripes); |
6530 | if (cur_offset + len > array_size) | 6537 | if (cur_offset + len > array_size) |
6531 | goto out_short_read; | 6538 | goto out_short_read; |
@@ -6534,6 +6541,9 @@ int btrfs_read_sys_array(struct btrfs_root *root) | |||
6534 | if (ret) | 6541 | if (ret) |
6535 | break; | 6542 | break; |
6536 | } else { | 6543 | } else { |
6544 | printk(KERN_ERR | ||
6545 | "BTRFS: unexpected item type %u in sys_array at offset %u\n", | ||
6546 | (u32)key.type, cur_offset); | ||
6537 | ret = -EIO; | 6547 | ret = -EIO; |
6538 | break; | 6548 | break; |
6539 | } | 6549 | } |
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c index 24e8ff722730..608552ed89c0 100644 --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c | |||
@@ -283,7 +283,7 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size) | |||
283 | path = btrfs_alloc_path(); | 283 | path = btrfs_alloc_path(); |
284 | if (!path) | 284 | if (!path) |
285 | return -ENOMEM; | 285 | return -ENOMEM; |
286 | path->reada = 2; | 286 | path->reada = READA_FORWARD; |
287 | 287 | ||
288 | /* search for our xattrs */ | 288 | /* search for our xattrs */ |
289 | ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); | 289 | ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); |