* [PATCH v2 1/2] btrfs: relocation: Cleanup while() loop using rbtree_postorder_for_each_entry_safe()
@ 2018-09-21 7:20 Qu Wenruo
2018-09-21 7:20 ` [PATCH v2 2/2] btrfs: relocation: Remove redundant tree level check Qu Wenruo
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Qu Wenruo @ 2018-09-21 7:20 UTC (permalink / raw)
To: linux-btrfs
And add one line comment explaining what we're doing for each loop.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
changelog:
v2:
Use rbtree_postorder_for_each_entry_safe() to replace for() loop.
---
fs/btrfs/relocation.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 8783a1776540..94aa148ccde6 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2987,7 +2987,7 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
struct backref_node *node;
struct btrfs_path *path;
struct tree_block *block;
- struct rb_node *rb_node;
+ struct tree_block *next;
int ret;
int err = 0;
@@ -2997,29 +2997,23 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
goto out_free_blocks;
}
- rb_node = rb_first(blocks);
- while (rb_node) {
- block = rb_entry(rb_node, struct tree_block, rb_node);
+ /* Kick in readahead for tree blocks with missing keys */
+ rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
if (!block->key_ready)
readahead_tree_block(fs_info, block->bytenr);
- rb_node = rb_next(rb_node);
}
- rb_node = rb_first(blocks);
- while (rb_node) {
- block = rb_entry(rb_node, struct tree_block, rb_node);
+ /* Get first keys */
+ rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
if (!block->key_ready) {
err = get_tree_block_key(fs_info, block);
if (err)
goto out_free_path;
}
- rb_node = rb_next(rb_node);
}
- rb_node = rb_first(blocks);
- while (rb_node) {
- block = rb_entry(rb_node, struct tree_block, rb_node);
-
+ /* Do tree relocation */
+ rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
node = build_backref_tree(rc, &block->key,
block->level, block->bytenr);
if (IS_ERR(node)) {
@@ -3030,11 +3024,11 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
ret = relocate_tree_block(trans, rc, node, &block->key,
path);
if (ret < 0) {
- if (ret != -EAGAIN || rb_node == rb_first(blocks))
+ if (ret != -EAGAIN || &block->rb_node ==
+ rb_first(blocks))
err = ret;
goto out;
}
- rb_node = rb_next(rb_node);
}
out:
err = finish_pending_nodes(trans, rc, path, err);
--
2.19.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] btrfs: relocation: Remove redundant tree level check
2018-09-21 7:20 [PATCH v2 1/2] btrfs: relocation: Cleanup while() loop using rbtree_postorder_for_each_entry_safe() Qu Wenruo
@ 2018-09-21 7:20 ` Qu Wenruo
2018-09-21 7:33 ` Nikolay Borisov
2018-09-21 7:34 ` [PATCH v2 1/2] btrfs: relocation: Cleanup while() loop using rbtree_postorder_for_each_entry_safe() Nikolay Borisov
2018-10-12 16:38 ` David Sterba
2 siblings, 1 reply; 6+ messages in thread
From: Qu Wenruo @ 2018-09-21 7:20 UTC (permalink / raw)
To: linux-btrfs
Commit 581c1760415c ("btrfs: Validate child tree block's level and first
key") has made tree block level check mandatory.
So if tree block level doesn't match, we won't get a valid extent
buffer.
The extra WARN_ON() check can be removed completely.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Changelog:
v2:
Added tags.
---
fs/btrfs/relocation.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 94aa148ccde6..a554e7861b6e 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2911,7 +2911,6 @@ static int get_tree_block_key(struct btrfs_fs_info *fs_info,
free_extent_buffer(eb);
return -EIO;
}
- WARN_ON(btrfs_header_level(eb) != block->level);
if (block->level == 0)
btrfs_item_key_to_cpu(eb, &block->key, 0);
else
--
2.19.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] btrfs: relocation: Remove redundant tree level check
2018-09-21 7:20 ` [PATCH v2 2/2] btrfs: relocation: Remove redundant tree level check Qu Wenruo
@ 2018-09-21 7:33 ` Nikolay Borisov
2018-09-21 7:37 ` Qu Wenruo
0 siblings, 1 reply; 6+ messages in thread
From: Nikolay Borisov @ 2018-09-21 7:33 UTC (permalink / raw)
To: Qu Wenruo, linux-btrfs
On 21.09.2018 10:20, Qu Wenruo wrote:
> Commit 581c1760415c ("btrfs: Validate child tree block's level and first
> key") has made tree block level check mandatory.
>
> So if tree block level doesn't match, we won't get a valid extent
> buffer.
> The extra WARN_ON() check can be removed completely.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> Changelog:
> v2:
> Added tags.
Nope you didn't :)
> ---
> fs/btrfs/relocation.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 94aa148ccde6..a554e7861b6e 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -2911,7 +2911,6 @@ static int get_tree_block_key(struct btrfs_fs_info *fs_info,
> free_extent_buffer(eb);
> return -EIO;
> }
> - WARN_ON(btrfs_header_level(eb) != block->level);
> if (block->level == 0)
> btrfs_item_key_to_cpu(eb, &block->key, 0);
> else
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] btrfs: relocation: Cleanup while() loop using rbtree_postorder_for_each_entry_safe()
2018-09-21 7:20 [PATCH v2 1/2] btrfs: relocation: Cleanup while() loop using rbtree_postorder_for_each_entry_safe() Qu Wenruo
2018-09-21 7:20 ` [PATCH v2 2/2] btrfs: relocation: Remove redundant tree level check Qu Wenruo
@ 2018-09-21 7:34 ` Nikolay Borisov
2018-10-12 16:38 ` David Sterba
2 siblings, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2018-09-21 7:34 UTC (permalink / raw)
To: Qu Wenruo, linux-btrfs
On 21.09.2018 10:20, Qu Wenruo wrote:
> And add one line comment explaining what we're doing for each loop.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> changelog:
> v2:
> Use rbtree_postorder_for_each_entry_safe() to replace for() loop.
> ---
> fs/btrfs/relocation.c | 24 +++++++++---------------
> 1 file changed, 9 insertions(+), 15 deletions(-)
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 8783a1776540..94aa148ccde6 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -2987,7 +2987,7 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
> struct backref_node *node;
> struct btrfs_path *path;
> struct tree_block *block;
> - struct rb_node *rb_node;
> + struct tree_block *next;
> int ret;
> int err = 0;
>
> @@ -2997,29 +2997,23 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
> goto out_free_blocks;
> }
>
> - rb_node = rb_first(blocks);
> - while (rb_node) {
> - block = rb_entry(rb_node, struct tree_block, rb_node);
> + /* Kick in readahead for tree blocks with missing keys */
> + rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
> if (!block->key_ready)
> readahead_tree_block(fs_info, block->bytenr);
> - rb_node = rb_next(rb_node);
> }
>
> - rb_node = rb_first(blocks);
> - while (rb_node) {
> - block = rb_entry(rb_node, struct tree_block, rb_node);
> + /* Get first keys */
> + rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
> if (!block->key_ready) {
> err = get_tree_block_key(fs_info, block);
> if (err)
> goto out_free_path;
> }
> - rb_node = rb_next(rb_node);
> }
>
> - rb_node = rb_first(blocks);
> - while (rb_node) {
> - block = rb_entry(rb_node, struct tree_block, rb_node);
> -
> + /* Do tree relocation */
> + rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
> node = build_backref_tree(rc, &block->key,
> block->level, block->bytenr);
> if (IS_ERR(node)) {
> @@ -3030,11 +3024,11 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
> ret = relocate_tree_block(trans, rc, node, &block->key,
> path);
> if (ret < 0) {
> - if (ret != -EAGAIN || rb_node == rb_first(blocks))
> + if (ret != -EAGAIN || &block->rb_node ==
> + rb_first(blocks))
> err = ret;
> goto out;
> }
> - rb_node = rb_next(rb_node);
> }
> out:
> err = finish_pending_nodes(trans, rc, path, err);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] btrfs: relocation: Remove redundant tree level check
2018-09-21 7:33 ` Nikolay Borisov
@ 2018-09-21 7:37 ` Qu Wenruo
0 siblings, 0 replies; 6+ messages in thread
From: Qu Wenruo @ 2018-09-21 7:37 UTC (permalink / raw)
To: Nikolay Borisov, linux-btrfs
On 2018/9/21 下午3:33, Nikolay Borisov wrote:
>
>
> On 21.09.2018 10:20, Qu Wenruo wrote:
>> Commit 581c1760415c ("btrfs: Validate child tree block's level and first
>> key") has made tree block level check mandatory.
>>
>> So if tree block level doesn't match, we won't get a valid extent
>> buffer.
>> The extra WARN_ON() check can be removed completely.
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>> Changelog:
>> v2:
>> Added tags.
>
> Nope you didn't :)
Face palm, only added in formatted patch, and just re-formatted patch again.
Anyway, David could handle it.
Thanks,
Qu
>
>> ---
>> fs/btrfs/relocation.c | 1 -
>> 1 file changed, 1 deletion(-)
>>
>> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
>> index 94aa148ccde6..a554e7861b6e 100644
>> --- a/fs/btrfs/relocation.c
>> +++ b/fs/btrfs/relocation.c
>> @@ -2911,7 +2911,6 @@ static int get_tree_block_key(struct btrfs_fs_info *fs_info,
>> free_extent_buffer(eb);
>> return -EIO;
>> }
>> - WARN_ON(btrfs_header_level(eb) != block->level);
>> if (block->level == 0)
>> btrfs_item_key_to_cpu(eb, &block->key, 0);
>> else
>>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] btrfs: relocation: Cleanup while() loop using rbtree_postorder_for_each_entry_safe()
2018-09-21 7:20 [PATCH v2 1/2] btrfs: relocation: Cleanup while() loop using rbtree_postorder_for_each_entry_safe() Qu Wenruo
2018-09-21 7:20 ` [PATCH v2 2/2] btrfs: relocation: Remove redundant tree level check Qu Wenruo
2018-09-21 7:34 ` [PATCH v2 1/2] btrfs: relocation: Cleanup while() loop using rbtree_postorder_for_each_entry_safe() Nikolay Borisov
@ 2018-10-12 16:38 ` David Sterba
2 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2018-10-12 16:38 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Fri, Sep 21, 2018 at 03:20:29PM +0800, Qu Wenruo wrote:
> And add one line comment explaining what we're doing for each loop.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> changelog:
> v2:
> Use rbtree_postorder_for_each_entry_safe() to replace for() loop.
1-2 reviewed and added to 4.20 queue, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-10-12 16:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-21 7:20 [PATCH v2 1/2] btrfs: relocation: Cleanup while() loop using rbtree_postorder_for_each_entry_safe() Qu Wenruo
2018-09-21 7:20 ` [PATCH v2 2/2] btrfs: relocation: Remove redundant tree level check Qu Wenruo
2018-09-21 7:33 ` Nikolay Borisov
2018-09-21 7:37 ` Qu Wenruo
2018-09-21 7:34 ` [PATCH v2 1/2] btrfs: relocation: Cleanup while() loop using rbtree_postorder_for_each_entry_safe() Nikolay Borisov
2018-10-12 16:38 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).