diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-10-30 11:27:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-10-30 11:27:13 -0400 |
commit | 85b5d4bcab8b46664f8e1993bd5919cb0f24a3ca (patch) | |
tree | 904b271d66dfbe005f4006fbd5e0bcc97a2fb428 | |
parent | 11743c56785c751c087eecdb98713eef796609e0 (diff) | |
parent | 9084cb6a24bf5838a665af92ded1af8363f9e563 (diff) |
Merge tag 'for-4.20-part2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull more btrfs updates from David Sterba:
"This contains a few minor updates and fixes that were under testing or
arrived shortly after the merge window freeze, mostly stable material"
* tag 'for-4.20-part2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
Btrfs: fix use-after-free when dumping free space
Btrfs: fix use-after-free during inode eviction
btrfs: move the dio_sem higher up the callchain
btrfs: don't run delayed_iputs in commit
btrfs: fix insert_reserved error handling
btrfs: only free reserved extent if we didn't insert it
btrfs: don't use ctl->free_space for max_extent_size
btrfs: set max_extent_size properly
btrfs: reset max_extent_size properly
MAINTAINERS: update my email address for btrfs
btrfs: delayed-ref: extract find_first_ref_head from find_ref_head
Btrfs: fix deadlock when writing out free space caches
Btrfs: fix assertion on fsync of regular file when using no-holes feature
Btrfs: fix null pointer dereference on compressed write path error
-rw-r--r-- | MAINTAINERS | 2 | ||||
-rw-r--r-- | fs/btrfs/ctree.c | 17 | ||||
-rw-r--r-- | fs/btrfs/delayed-ref.c | 50 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 37 | ||||
-rw-r--r-- | fs/btrfs/file.c | 12 | ||||
-rw-r--r-- | fs/btrfs/free-space-cache.c | 32 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 15 | ||||
-rw-r--r-- | fs/btrfs/transaction.c | 9 | ||||
-rw-r--r-- | fs/btrfs/tree-log.c | 5 |
9 files changed, 111 insertions, 68 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index 930241eb6e2d..5d1c3ae9f933 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -3160,7 +3160,7 @@ F: drivers/gpio/gpio-bt8xx.c | |||
3160 | 3160 | ||
3161 | BTRFS FILE SYSTEM | 3161 | BTRFS FILE SYSTEM |
3162 | M: Chris Mason <clm@fb.com> | 3162 | M: Chris Mason <clm@fb.com> |
3163 | M: Josef Bacik <jbacik@fb.com> | 3163 | M: Josef Bacik <josef@toxicpanda.com> |
3164 | M: David Sterba <dsterba@suse.com> | 3164 | M: David Sterba <dsterba@suse.com> |
3165 | L: linux-btrfs@vger.kernel.org | 3165 | L: linux-btrfs@vger.kernel.org |
3166 | W: http://btrfs.wiki.kernel.org/ | 3166 | W: http://btrfs.wiki.kernel.org/ |
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 2ee43b6a4f09..539901fb5165 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -1014,9 +1014,26 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, | |||
1014 | if ((root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) && parent) | 1014 | if ((root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) && parent) |
1015 | parent_start = parent->start; | 1015 | parent_start = parent->start; |
1016 | 1016 | ||
1017 | /* | ||
1018 | * If we are COWing a node/leaf from the extent, chunk or device trees, | ||
1019 | * make sure that we do not finish block group creation of pending block | ||
1020 | * groups. We do this to avoid a deadlock. | ||
1021 | * COWing can result in allocation of a new chunk, and flushing pending | ||
1022 | * block groups (btrfs_create_pending_block_groups()) can be triggered | ||
1023 | * when finishing allocation of a new chunk. Creation of a pending block | ||
1024 | * group modifies the extent, chunk and device trees, therefore we could | ||
1025 | * deadlock with ourselves since we are holding a lock on an extent | ||
1026 | * buffer that btrfs_create_pending_block_groups() may try to COW later. | ||
1027 | */ | ||
1028 | if (root == fs_info->extent_root || | ||
1029 | root == fs_info->chunk_root || | ||
1030 | root == fs_info->dev_root) | ||
1031 | trans->can_flush_pending_bgs = false; | ||
1032 | |||
1017 | cow = btrfs_alloc_tree_block(trans, root, parent_start, | 1033 | cow = btrfs_alloc_tree_block(trans, root, parent_start, |
1018 | root->root_key.objectid, &disk_key, level, | 1034 | root->root_key.objectid, &disk_key, level, |
1019 | search_start, empty_size); | 1035 | search_start, empty_size); |
1036 | trans->can_flush_pending_bgs = true; | ||
1020 | if (IS_ERR(cow)) | 1037 | if (IS_ERR(cow)) |
1021 | return PTR_ERR(cow); | 1038 | return PTR_ERR(cow); |
1022 | 1039 | ||
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 5149165b49a4..9301b3ad9217 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c | |||
@@ -164,14 +164,27 @@ static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root, | |||
164 | return NULL; | 164 | return NULL; |
165 | } | 165 | } |
166 | 166 | ||
167 | static struct btrfs_delayed_ref_head *find_first_ref_head( | ||
168 | struct btrfs_delayed_ref_root *dr) | ||
169 | { | ||
170 | struct rb_node *n; | ||
171 | struct btrfs_delayed_ref_head *entry; | ||
172 | |||
173 | n = rb_first_cached(&dr->href_root); | ||
174 | if (!n) | ||
175 | return NULL; | ||
176 | |||
177 | entry = rb_entry(n, struct btrfs_delayed_ref_head, href_node); | ||
178 | |||
179 | return entry; | ||
180 | } | ||
181 | |||
167 | /* | 182 | /* |
168 | * find an head entry based on bytenr. This returns the delayed ref | 183 | * Find a head entry based on bytenr. This returns the delayed ref head if it |
169 | * head if it was able to find one, or NULL if nothing was in that spot. | 184 | * was able to find one, or NULL if nothing was in that spot. If return_bigger |
170 | * If return_bigger is given, the next bigger entry is returned if no exact | 185 | * is given, the next bigger entry is returned if no exact match is found. |
171 | * match is found. But if no bigger one is found then the first node of the | ||
172 | * ref head tree will be returned. | ||
173 | */ | 186 | */ |
174 | static struct btrfs_delayed_ref_head* find_ref_head( | 187 | static struct btrfs_delayed_ref_head *find_ref_head( |
175 | struct btrfs_delayed_ref_root *dr, u64 bytenr, | 188 | struct btrfs_delayed_ref_root *dr, u64 bytenr, |
176 | bool return_bigger) | 189 | bool return_bigger) |
177 | { | 190 | { |
@@ -195,10 +208,9 @@ static struct btrfs_delayed_ref_head* find_ref_head( | |||
195 | if (bytenr > entry->bytenr) { | 208 | if (bytenr > entry->bytenr) { |
196 | n = rb_next(&entry->href_node); | 209 | n = rb_next(&entry->href_node); |
197 | if (!n) | 210 | if (!n) |
198 | n = rb_first_cached(&dr->href_root); | 211 | return NULL; |
199 | entry = rb_entry(n, struct btrfs_delayed_ref_head, | 212 | entry = rb_entry(n, struct btrfs_delayed_ref_head, |
200 | href_node); | 213 | href_node); |
201 | return entry; | ||
202 | } | 214 | } |
203 | return entry; | 215 | return entry; |
204 | } | 216 | } |
@@ -355,33 +367,25 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( | |||
355 | struct btrfs_delayed_ref_root *delayed_refs) | 367 | struct btrfs_delayed_ref_root *delayed_refs) |
356 | { | 368 | { |
357 | struct btrfs_delayed_ref_head *head; | 369 | struct btrfs_delayed_ref_head *head; |
358 | u64 start; | ||
359 | bool loop = false; | ||
360 | 370 | ||
361 | again: | 371 | again: |
362 | start = delayed_refs->run_delayed_start; | 372 | head = find_ref_head(delayed_refs, delayed_refs->run_delayed_start, |
363 | head = find_ref_head(delayed_refs, start, true); | 373 | true); |
364 | if (!head && !loop) { | 374 | if (!head && delayed_refs->run_delayed_start != 0) { |
365 | delayed_refs->run_delayed_start = 0; | 375 | delayed_refs->run_delayed_start = 0; |
366 | start = 0; | 376 | head = find_first_ref_head(delayed_refs); |
367 | loop = true; | ||
368 | head = find_ref_head(delayed_refs, start, true); | ||
369 | if (!head) | ||
370 | return NULL; | ||
371 | } else if (!head && loop) { | ||
372 | return NULL; | ||
373 | } | 377 | } |
378 | if (!head) | ||
379 | return NULL; | ||
374 | 380 | ||
375 | while (head->processing) { | 381 | while (head->processing) { |
376 | struct rb_node *node; | 382 | struct rb_node *node; |
377 | 383 | ||
378 | node = rb_next(&head->href_node); | 384 | node = rb_next(&head->href_node); |
379 | if (!node) { | 385 | if (!node) { |
380 | if (loop) | 386 | if (delayed_refs->run_delayed_start == 0) |
381 | return NULL; | 387 | return NULL; |
382 | delayed_refs->run_delayed_start = 0; | 388 | delayed_refs->run_delayed_start = 0; |
383 | start = 0; | ||
384 | loop = true; | ||
385 | goto again; | 389 | goto again; |
386 | } | 390 | } |
387 | head = rb_entry(node, struct btrfs_delayed_ref_head, | 391 | head = rb_entry(node, struct btrfs_delayed_ref_head, |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a4cd0221bc8d..a1febf155747 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -2366,6 +2366,9 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans, | |||
2366 | insert_reserved); | 2366 | insert_reserved); |
2367 | else | 2367 | else |
2368 | BUG(); | 2368 | BUG(); |
2369 | if (ret && insert_reserved) | ||
2370 | btrfs_pin_extent(trans->fs_info, node->bytenr, | ||
2371 | node->num_bytes, 1); | ||
2369 | return ret; | 2372 | return ret; |
2370 | } | 2373 | } |
2371 | 2374 | ||
@@ -2954,7 +2957,6 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, | |||
2954 | struct btrfs_delayed_ref_head *head; | 2957 | struct btrfs_delayed_ref_head *head; |
2955 | int ret; | 2958 | int ret; |
2956 | int run_all = count == (unsigned long)-1; | 2959 | int run_all = count == (unsigned long)-1; |
2957 | bool can_flush_pending_bgs = trans->can_flush_pending_bgs; | ||
2958 | 2960 | ||
2959 | /* We'll clean this up in btrfs_cleanup_transaction */ | 2961 | /* We'll clean this up in btrfs_cleanup_transaction */ |
2960 | if (trans->aborted) | 2962 | if (trans->aborted) |
@@ -2971,7 +2973,6 @@ again: | |||
2971 | #ifdef SCRAMBLE_DELAYED_REFS | 2973 | #ifdef SCRAMBLE_DELAYED_REFS |
2972 | delayed_refs->run_delayed_start = find_middle(&delayed_refs->root); | 2974 | delayed_refs->run_delayed_start = find_middle(&delayed_refs->root); |
2973 | #endif | 2975 | #endif |
2974 | trans->can_flush_pending_bgs = false; | ||
2975 | ret = __btrfs_run_delayed_refs(trans, count); | 2976 | ret = __btrfs_run_delayed_refs(trans, count); |
2976 | if (ret < 0) { | 2977 | if (ret < 0) { |
2977 | btrfs_abort_transaction(trans, ret); | 2978 | btrfs_abort_transaction(trans, ret); |
@@ -3002,7 +3003,6 @@ again: | |||
3002 | goto again; | 3003 | goto again; |
3003 | } | 3004 | } |
3004 | out: | 3005 | out: |
3005 | trans->can_flush_pending_bgs = can_flush_pending_bgs; | ||
3006 | return 0; | 3006 | return 0; |
3007 | } | 3007 | } |
3008 | 3008 | ||
@@ -4568,6 +4568,7 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, | |||
4568 | goto out; | 4568 | goto out; |
4569 | } else { | 4569 | } else { |
4570 | ret = 1; | 4570 | ret = 1; |
4571 | space_info->max_extent_size = 0; | ||
4571 | } | 4572 | } |
4572 | 4573 | ||
4573 | space_info->force_alloc = CHUNK_ALLOC_NO_FORCE; | 4574 | space_info->force_alloc = CHUNK_ALLOC_NO_FORCE; |
@@ -4589,11 +4590,9 @@ out: | |||
4589 | * the block groups that were made dirty during the lifetime of the | 4590 | * the block groups that were made dirty during the lifetime of the |
4590 | * transaction. | 4591 | * transaction. |
4591 | */ | 4592 | */ |
4592 | if (trans->can_flush_pending_bgs && | 4593 | if (trans->chunk_bytes_reserved >= (u64)SZ_2M) |
4593 | trans->chunk_bytes_reserved >= (u64)SZ_2M) { | ||
4594 | btrfs_create_pending_block_groups(trans); | 4594 | btrfs_create_pending_block_groups(trans); |
4595 | btrfs_trans_release_chunk_metadata(trans); | 4595 | |
4596 | } | ||
4597 | return ret; | 4596 | return ret; |
4598 | } | 4597 | } |
4599 | 4598 | ||
@@ -6464,6 +6463,7 @@ static void btrfs_free_reserved_bytes(struct btrfs_block_group_cache *cache, | |||
6464 | space_info->bytes_readonly += num_bytes; | 6463 | space_info->bytes_readonly += num_bytes; |
6465 | cache->reserved -= num_bytes; | 6464 | cache->reserved -= num_bytes; |
6466 | space_info->bytes_reserved -= num_bytes; | 6465 | space_info->bytes_reserved -= num_bytes; |
6466 | space_info->max_extent_size = 0; | ||
6467 | 6467 | ||
6468 | if (delalloc) | 6468 | if (delalloc) |
6469 | cache->delalloc_bytes -= num_bytes; | 6469 | cache->delalloc_bytes -= num_bytes; |
@@ -7260,6 +7260,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, | |||
7260 | struct btrfs_block_group_cache *block_group = NULL; | 7260 | struct btrfs_block_group_cache *block_group = NULL; |
7261 | u64 search_start = 0; | 7261 | u64 search_start = 0; |
7262 | u64 max_extent_size = 0; | 7262 | u64 max_extent_size = 0; |
7263 | u64 max_free_space = 0; | ||
7263 | u64 empty_cluster = 0; | 7264 | u64 empty_cluster = 0; |
7264 | struct btrfs_space_info *space_info; | 7265 | struct btrfs_space_info *space_info; |
7265 | int loop = 0; | 7266 | int loop = 0; |
@@ -7555,8 +7556,8 @@ unclustered_alloc: | |||
7555 | spin_lock(&ctl->tree_lock); | 7556 | spin_lock(&ctl->tree_lock); |
7556 | if (ctl->free_space < | 7557 | if (ctl->free_space < |
7557 | num_bytes + empty_cluster + empty_size) { | 7558 | num_bytes + empty_cluster + empty_size) { |
7558 | if (ctl->free_space > max_extent_size) | 7559 | max_free_space = max(max_free_space, |
7559 | max_extent_size = ctl->free_space; | 7560 | ctl->free_space); |
7560 | spin_unlock(&ctl->tree_lock); | 7561 | spin_unlock(&ctl->tree_lock); |
7561 | goto loop; | 7562 | goto loop; |
7562 | } | 7563 | } |
@@ -7723,6 +7724,8 @@ loop: | |||
7723 | } | 7724 | } |
7724 | out: | 7725 | out: |
7725 | if (ret == -ENOSPC) { | 7726 | if (ret == -ENOSPC) { |
7727 | if (!max_extent_size) | ||
7728 | max_extent_size = max_free_space; | ||
7726 | spin_lock(&space_info->lock); | 7729 | spin_lock(&space_info->lock); |
7727 | space_info->max_extent_size = max_extent_size; | 7730 | space_info->max_extent_size = max_extent_size; |
7728 | spin_unlock(&space_info->lock); | 7731 | spin_unlock(&space_info->lock); |
@@ -8004,21 +8007,14 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, | |||
8004 | } | 8007 | } |
8005 | 8008 | ||
8006 | path = btrfs_alloc_path(); | 8009 | path = btrfs_alloc_path(); |
8007 | if (!path) { | 8010 | if (!path) |
8008 | btrfs_free_and_pin_reserved_extent(fs_info, | ||
8009 | extent_key.objectid, | ||
8010 | fs_info->nodesize); | ||
8011 | return -ENOMEM; | 8011 | return -ENOMEM; |
8012 | } | ||
8013 | 8012 | ||
8014 | path->leave_spinning = 1; | 8013 | path->leave_spinning = 1; |
8015 | ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, | 8014 | ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, |
8016 | &extent_key, size); | 8015 | &extent_key, size); |
8017 | if (ret) { | 8016 | if (ret) { |
8018 | btrfs_free_path(path); | 8017 | btrfs_free_path(path); |
8019 | btrfs_free_and_pin_reserved_extent(fs_info, | ||
8020 | extent_key.objectid, | ||
8021 | fs_info->nodesize); | ||
8022 | return ret; | 8018 | return ret; |
8023 | } | 8019 | } |
8024 | 8020 | ||
@@ -10132,9 +10128,10 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans) | |||
10132 | struct btrfs_block_group_item item; | 10128 | struct btrfs_block_group_item item; |
10133 | struct btrfs_key key; | 10129 | struct btrfs_key key; |
10134 | int ret = 0; | 10130 | int ret = 0; |
10135 | bool can_flush_pending_bgs = trans->can_flush_pending_bgs; | ||
10136 | 10131 | ||
10137 | trans->can_flush_pending_bgs = false; | 10132 | if (!trans->can_flush_pending_bgs) |
10133 | return; | ||
10134 | |||
10138 | while (!list_empty(&trans->new_bgs)) { | 10135 | while (!list_empty(&trans->new_bgs)) { |
10139 | block_group = list_first_entry(&trans->new_bgs, | 10136 | block_group = list_first_entry(&trans->new_bgs, |
10140 | struct btrfs_block_group_cache, | 10137 | struct btrfs_block_group_cache, |
@@ -10159,7 +10156,7 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans) | |||
10159 | next: | 10156 | next: |
10160 | list_del_init(&block_group->bg_list); | 10157 | list_del_init(&block_group->bg_list); |
10161 | } | 10158 | } |
10162 | trans->can_flush_pending_bgs = can_flush_pending_bgs; | 10159 | btrfs_trans_release_chunk_metadata(trans); |
10163 | } | 10160 | } |
10164 | 10161 | ||
10165 | int btrfs_make_block_group(struct btrfs_trans_handle *trans, u64 bytes_used, | 10162 | int btrfs_make_block_group(struct btrfs_trans_handle *trans, u64 bytes_used, |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 15b925142793..97c7a086f7bd 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -2078,6 +2078,14 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | |||
2078 | goto out; | 2078 | goto out; |
2079 | 2079 | ||
2080 | inode_lock(inode); | 2080 | inode_lock(inode); |
2081 | |||
2082 | /* | ||
2083 | * We take the dio_sem here because the tree log stuff can race with | ||
2084 | * lockless dio writes and get an extent map logged for an extent we | ||
2085 | * never waited on. We need it this high up for lockdep reasons. | ||
2086 | */ | ||
2087 | down_write(&BTRFS_I(inode)->dio_sem); | ||
2088 | |||
2081 | atomic_inc(&root->log_batch); | 2089 | atomic_inc(&root->log_batch); |
2082 | 2090 | ||
2083 | /* | 2091 | /* |
@@ -2086,6 +2094,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | |||
2086 | */ | 2094 | */ |
2087 | ret = btrfs_wait_ordered_range(inode, start, len); | 2095 | ret = btrfs_wait_ordered_range(inode, start, len); |
2088 | if (ret) { | 2096 | if (ret) { |
2097 | up_write(&BTRFS_I(inode)->dio_sem); | ||
2089 | inode_unlock(inode); | 2098 | inode_unlock(inode); |
2090 | goto out; | 2099 | goto out; |
2091 | } | 2100 | } |
@@ -2109,6 +2118,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | |||
2109 | * checked called fsync. | 2118 | * checked called fsync. |
2110 | */ | 2119 | */ |
2111 | ret = filemap_check_wb_err(inode->i_mapping, file->f_wb_err); | 2120 | ret = filemap_check_wb_err(inode->i_mapping, file->f_wb_err); |
2121 | up_write(&BTRFS_I(inode)->dio_sem); | ||
2112 | inode_unlock(inode); | 2122 | inode_unlock(inode); |
2113 | goto out; | 2123 | goto out; |
2114 | } | 2124 | } |
@@ -2127,6 +2137,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | |||
2127 | trans = btrfs_start_transaction(root, 0); | 2137 | trans = btrfs_start_transaction(root, 0); |
2128 | if (IS_ERR(trans)) { | 2138 | if (IS_ERR(trans)) { |
2129 | ret = PTR_ERR(trans); | 2139 | ret = PTR_ERR(trans); |
2140 | up_write(&BTRFS_I(inode)->dio_sem); | ||
2130 | inode_unlock(inode); | 2141 | inode_unlock(inode); |
2131 | goto out; | 2142 | goto out; |
2132 | } | 2143 | } |
@@ -2148,6 +2159,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | |||
2148 | * file again, but that will end up using the synchronization | 2159 | * file again, but that will end up using the synchronization |
2149 | * inside btrfs_sync_log to keep things safe. | 2160 | * inside btrfs_sync_log to keep things safe. |
2150 | */ | 2161 | */ |
2162 | up_write(&BTRFS_I(inode)->dio_sem); | ||
2151 | inode_unlock(inode); | 2163 | inode_unlock(inode); |
2152 | 2164 | ||
2153 | /* | 2165 | /* |
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 67441219d6c9..4ba0aedc878b 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -1772,6 +1772,13 @@ static int search_bitmap(struct btrfs_free_space_ctl *ctl, | |||
1772 | return -1; | 1772 | return -1; |
1773 | } | 1773 | } |
1774 | 1774 | ||
1775 | static inline u64 get_max_extent_size(struct btrfs_free_space *entry) | ||
1776 | { | ||
1777 | if (entry->bitmap) | ||
1778 | return entry->max_extent_size; | ||
1779 | return entry->bytes; | ||
1780 | } | ||
1781 | |||
1775 | /* Cache the size of the max extent in bytes */ | 1782 | /* Cache the size of the max extent in bytes */ |
1776 | static struct btrfs_free_space * | 1783 | static struct btrfs_free_space * |
1777 | find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, | 1784 | find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, |
@@ -1793,8 +1800,8 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, | |||
1793 | for (node = &entry->offset_index; node; node = rb_next(node)) { | 1800 | for (node = &entry->offset_index; node; node = rb_next(node)) { |
1794 | entry = rb_entry(node, struct btrfs_free_space, offset_index); | 1801 | entry = rb_entry(node, struct btrfs_free_space, offset_index); |
1795 | if (entry->bytes < *bytes) { | 1802 | if (entry->bytes < *bytes) { |
1796 | if (entry->bytes > *max_extent_size) | 1803 | *max_extent_size = max(get_max_extent_size(entry), |
1797 | *max_extent_size = entry->bytes; | 1804 | *max_extent_size); |
1798 | continue; | 1805 | continue; |
1799 | } | 1806 | } |
1800 | 1807 | ||
@@ -1812,8 +1819,8 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, | |||
1812 | } | 1819 | } |
1813 | 1820 | ||
1814 | if (entry->bytes < *bytes + align_off) { | 1821 | if (entry->bytes < *bytes + align_off) { |
1815 | if (entry->bytes > *max_extent_size) | 1822 | *max_extent_size = max(get_max_extent_size(entry), |
1816 | *max_extent_size = entry->bytes; | 1823 | *max_extent_size); |
1817 | continue; | 1824 | continue; |
1818 | } | 1825 | } |
1819 | 1826 | ||
@@ -1825,8 +1832,10 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, | |||
1825 | *offset = tmp; | 1832 | *offset = tmp; |
1826 | *bytes = size; | 1833 | *bytes = size; |
1827 | return entry; | 1834 | return entry; |
1828 | } else if (size > *max_extent_size) { | 1835 | } else { |
1829 | *max_extent_size = size; | 1836 | *max_extent_size = |
1837 | max(get_max_extent_size(entry), | ||
1838 | *max_extent_size); | ||
1830 | } | 1839 | } |
1831 | continue; | 1840 | continue; |
1832 | } | 1841 | } |
@@ -2449,6 +2458,7 @@ void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group, | |||
2449 | struct rb_node *n; | 2458 | struct rb_node *n; |
2450 | int count = 0; | 2459 | int count = 0; |
2451 | 2460 | ||
2461 | spin_lock(&ctl->tree_lock); | ||
2452 | for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) { | 2462 | for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) { |
2453 | info = rb_entry(n, struct btrfs_free_space, offset_index); | 2463 | info = rb_entry(n, struct btrfs_free_space, offset_index); |
2454 | if (info->bytes >= bytes && !block_group->ro) | 2464 | if (info->bytes >= bytes && !block_group->ro) |
@@ -2457,6 +2467,7 @@ void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group, | |||
2457 | info->offset, info->bytes, | 2467 | info->offset, info->bytes, |
2458 | (info->bitmap) ? "yes" : "no"); | 2468 | (info->bitmap) ? "yes" : "no"); |
2459 | } | 2469 | } |
2470 | spin_unlock(&ctl->tree_lock); | ||
2460 | btrfs_info(fs_info, "block group has cluster?: %s", | 2471 | btrfs_info(fs_info, "block group has cluster?: %s", |
2461 | list_empty(&block_group->cluster_list) ? "no" : "yes"); | 2472 | list_empty(&block_group->cluster_list) ? "no" : "yes"); |
2462 | btrfs_info(fs_info, | 2473 | btrfs_info(fs_info, |
@@ -2685,8 +2696,8 @@ static u64 btrfs_alloc_from_bitmap(struct btrfs_block_group_cache *block_group, | |||
2685 | 2696 | ||
2686 | err = search_bitmap(ctl, entry, &search_start, &search_bytes, true); | 2697 | err = search_bitmap(ctl, entry, &search_start, &search_bytes, true); |
2687 | if (err) { | 2698 | if (err) { |
2688 | if (search_bytes > *max_extent_size) | 2699 | *max_extent_size = max(get_max_extent_size(entry), |
2689 | *max_extent_size = search_bytes; | 2700 | *max_extent_size); |
2690 | return 0; | 2701 | return 0; |
2691 | } | 2702 | } |
2692 | 2703 | ||
@@ -2723,8 +2734,9 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group, | |||
2723 | 2734 | ||
2724 | entry = rb_entry(node, struct btrfs_free_space, offset_index); | 2735 | entry = rb_entry(node, struct btrfs_free_space, offset_index); |
2725 | while (1) { | 2736 | while (1) { |
2726 | if (entry->bytes < bytes && entry->bytes > *max_extent_size) | 2737 | if (entry->bytes < bytes) |
2727 | *max_extent_size = entry->bytes; | 2738 | *max_extent_size = max(get_max_extent_size(entry), |
2739 | *max_extent_size); | ||
2728 | 2740 | ||
2729 | if (entry->bytes < bytes || | 2741 | if (entry->bytes < bytes || |
2730 | (!entry->bitmap && entry->offset < min_start)) { | 2742 | (!entry->bitmap && entry->offset < min_start)) { |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 181c58b23110..d3df5b52278c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -502,6 +502,7 @@ again: | |||
502 | pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); | 502 | pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); |
503 | if (!pages) { | 503 | if (!pages) { |
504 | /* just bail out to the uncompressed code */ | 504 | /* just bail out to the uncompressed code */ |
505 | nr_pages = 0; | ||
505 | goto cont; | 506 | goto cont; |
506 | } | 507 | } |
507 | 508 | ||
@@ -2940,6 +2941,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) | |||
2940 | bool truncated = false; | 2941 | bool truncated = false; |
2941 | bool range_locked = false; | 2942 | bool range_locked = false; |
2942 | bool clear_new_delalloc_bytes = false; | 2943 | bool clear_new_delalloc_bytes = false; |
2944 | bool clear_reserved_extent = true; | ||
2943 | 2945 | ||
2944 | if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && | 2946 | if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && |
2945 | !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags) && | 2947 | !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags) && |
@@ -3043,10 +3045,12 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) | |||
3043 | logical_len, logical_len, | 3045 | logical_len, logical_len, |
3044 | compress_type, 0, 0, | 3046 | compress_type, 0, 0, |
3045 | BTRFS_FILE_EXTENT_REG); | 3047 | BTRFS_FILE_EXTENT_REG); |
3046 | if (!ret) | 3048 | if (!ret) { |
3049 | clear_reserved_extent = false; | ||
3047 | btrfs_release_delalloc_bytes(fs_info, | 3050 | btrfs_release_delalloc_bytes(fs_info, |
3048 | ordered_extent->start, | 3051 | ordered_extent->start, |
3049 | ordered_extent->disk_len); | 3052 | ordered_extent->disk_len); |
3053 | } | ||
3050 | } | 3054 | } |
3051 | unpin_extent_cache(&BTRFS_I(inode)->extent_tree, | 3055 | unpin_extent_cache(&BTRFS_I(inode)->extent_tree, |
3052 | ordered_extent->file_offset, ordered_extent->len, | 3056 | ordered_extent->file_offset, ordered_extent->len, |
@@ -3107,8 +3111,13 @@ out: | |||
3107 | * wrong we need to return the space for this ordered extent | 3111 | * wrong we need to return the space for this ordered extent |
3108 | * back to the allocator. We only free the extent in the | 3112 | * back to the allocator. We only free the extent in the |
3109 | * truncated case if we didn't write out the extent at all. | 3113 | * truncated case if we didn't write out the extent at all. |
3114 | * | ||
3115 | * If we made it past insert_reserved_file_extent before we | ||
3116 | * errored out then we don't need to do this as the accounting | ||
3117 | * has already been done. | ||
3110 | */ | 3118 | */ |
3111 | if ((ret || !logical_len) && | 3119 | if ((ret || !logical_len) && |
3120 | clear_reserved_extent && | ||
3112 | !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && | 3121 | !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && |
3113 | !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) | 3122 | !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) |
3114 | btrfs_free_reserved_extent(fs_info, | 3123 | btrfs_free_reserved_extent(fs_info, |
@@ -5259,11 +5268,13 @@ static void evict_inode_truncate_pages(struct inode *inode) | |||
5259 | struct extent_state *cached_state = NULL; | 5268 | struct extent_state *cached_state = NULL; |
5260 | u64 start; | 5269 | u64 start; |
5261 | u64 end; | 5270 | u64 end; |
5271 | unsigned state_flags; | ||
5262 | 5272 | ||
5263 | node = rb_first(&io_tree->state); | 5273 | node = rb_first(&io_tree->state); |
5264 | state = rb_entry(node, struct extent_state, rb_node); | 5274 | state = rb_entry(node, struct extent_state, rb_node); |
5265 | start = state->start; | 5275 | start = state->start; |
5266 | end = state->end; | 5276 | end = state->end; |
5277 | state_flags = state->state; | ||
5267 | spin_unlock(&io_tree->lock); | 5278 | spin_unlock(&io_tree->lock); |
5268 | 5279 | ||
5269 | lock_extent_bits(io_tree, start, end, &cached_state); | 5280 | lock_extent_bits(io_tree, start, end, &cached_state); |
@@ -5276,7 +5287,7 @@ static void evict_inode_truncate_pages(struct inode *inode) | |||
5276 | * | 5287 | * |
5277 | * Note, end is the bytenr of last byte, so we need + 1 here. | 5288 | * Note, end is the bytenr of last byte, so we need + 1 here. |
5278 | */ | 5289 | */ |
5279 | if (state->state & EXTENT_DELALLOC) | 5290 | if (state_flags & EXTENT_DELALLOC) |
5280 | btrfs_qgroup_free_data(inode, NULL, start, end - start + 1); | 5291 | btrfs_qgroup_free_data(inode, NULL, start, end - start + 1); |
5281 | 5292 | ||
5282 | clear_extent_bit(io_tree, start, end, | 5293 | clear_extent_bit(io_tree, start, end, |
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 5686290a50e1..d1eeef9ec5da 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -2283,15 +2283,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) | |||
2283 | 2283 | ||
2284 | kmem_cache_free(btrfs_trans_handle_cachep, trans); | 2284 | kmem_cache_free(btrfs_trans_handle_cachep, trans); |
2285 | 2285 | ||
2286 | /* | ||
2287 | * If fs has been frozen, we can not handle delayed iputs, otherwise | ||
2288 | * it'll result in deadlock about SB_FREEZE_FS. | ||
2289 | */ | ||
2290 | if (current != fs_info->transaction_kthread && | ||
2291 | current != fs_info->cleaner_kthread && | ||
2292 | !test_bit(BTRFS_FS_FROZEN, &fs_info->flags)) | ||
2293 | btrfs_run_delayed_iputs(fs_info); | ||
2294 | |||
2295 | return ret; | 2286 | return ret; |
2296 | 2287 | ||
2297 | scrub_continue: | 2288 | scrub_continue: |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 0dba09334a16..e07f3376b7df 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -4390,7 +4390,6 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans, | |||
4390 | 4390 | ||
4391 | INIT_LIST_HEAD(&extents); | 4391 | INIT_LIST_HEAD(&extents); |
4392 | 4392 | ||
4393 | down_write(&inode->dio_sem); | ||
4394 | write_lock(&tree->lock); | 4393 | write_lock(&tree->lock); |
4395 | test_gen = root->fs_info->last_trans_committed; | 4394 | test_gen = root->fs_info->last_trans_committed; |
4396 | logged_start = start; | 4395 | logged_start = start; |
@@ -4456,7 +4455,6 @@ process: | |||
4456 | } | 4455 | } |
4457 | WARN_ON(!list_empty(&extents)); | 4456 | WARN_ON(!list_empty(&extents)); |
4458 | write_unlock(&tree->lock); | 4457 | write_unlock(&tree->lock); |
4459 | up_write(&inode->dio_sem); | ||
4460 | 4458 | ||
4461 | btrfs_release_path(path); | 4459 | btrfs_release_path(path); |
4462 | if (!ret) | 4460 | if (!ret) |
@@ -4652,7 +4650,8 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans, | |||
4652 | ASSERT(len == i_size || | 4650 | ASSERT(len == i_size || |
4653 | (len == fs_info->sectorsize && | 4651 | (len == fs_info->sectorsize && |
4654 | btrfs_file_extent_compression(leaf, extent) != | 4652 | btrfs_file_extent_compression(leaf, extent) != |
4655 | BTRFS_COMPRESS_NONE)); | 4653 | BTRFS_COMPRESS_NONE) || |
4654 | (len < i_size && i_size < fs_info->sectorsize)); | ||
4656 | return 0; | 4655 | return 0; |
4657 | } | 4656 | } |
4658 | 4657 | ||