[04/10] btrfs: relocation: Rename mark_block_processed() and __mark_block_processed()
diff mbox series

Message ID 20200226055652.24857-5-wqu@suse.com
State New
Headers show
Series
  • btrfs: relocation: Refactor build_backref_tree()
Related show

Commit Message

Qu Wenruo Feb. 26, 2020, 5:56 a.m. UTC
These two functions are weirdly named, mark_block_processed() in fact
just mark a range dirty unconditionally, while __mark_block_processed()
does extra check before doing the marking.

Rename mark_block_processed() to mark_range_processed(), and rename
__mark_block_processed() to mark_block_processed().

Since we're here, also kill the forward declaration.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/relocation.c | 65 +++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 33 deletions(-)

Comments

Nikolay Borisov Feb. 26, 2020, 1:56 p.m. UTC | #1
On 26.02.20 г. 7:56 ч., Qu Wenruo wrote:
> These two functions are weirdly named, mark_block_processed() in fact
> just mark a range dirty unconditionally, while __mark_block_processed()
> does extra check before doing the marking.
> 
> Rename mark_block_processed() to mark_range_processed(), and rename
> __mark_block_processed() to mark_block_processed().
> 
> Since we're here, also kill the forward declaration.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  fs/btrfs/relocation.c | 65 +++++++++++++++++++++----------------------
>  1 file changed, 32 insertions(+), 33 deletions(-)
> 
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 1fe34d8eef6d..d81fa6d63129 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -189,8 +189,34 @@ struct reloc_control {
>  
>  static void remove_backref_node(struct backref_cache *cache,
>  				struct backref_node *node);
> -static void __mark_block_processed(struct reloc_control *rc,
> -				   struct backref_node *node);
> +
> +static int in_block_group(u64 bytenr, struct btrfs_block_group *block_group)
> +{
> +	if (bytenr >= block_group->start &&
> +	    bytenr < block_group->start + block_group->length)
> +		return 1;
> +	return 0;
> +}

This function can be killed altogether and replaced with the in_range
macro defined in fs/btrfs/misc.h . The only difference is you'd have to
call it

in_range(bytenr, block_group->start, block_group->length);

Seeing how in_block_group is called in only 2 places I don't think it
will be a big loss.

> +
> +static void mark_range_processed(struct reloc_control *rc,
> +				 u64 bytenr, u32 blocksize)
> +{
> +	set_extent_bits(&rc->processed_blocks, bytenr, bytenr + blocksize - 1,
> +			EXTENT_DIRTY);
> +}

Having a wrapper just for this seems a bit pointless, remove it and open
code the set_extent_bit call in mark_block_processed.

<snip>

Patch
diff mbox series

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 1fe34d8eef6d..d81fa6d63129 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -189,8 +189,34 @@  struct reloc_control {
 
 static void remove_backref_node(struct backref_cache *cache,
 				struct backref_node *node);
-static void __mark_block_processed(struct reloc_control *rc,
-				   struct backref_node *node);
+
+static int in_block_group(u64 bytenr, struct btrfs_block_group *block_group)
+{
+	if (bytenr >= block_group->start &&
+	    bytenr < block_group->start + block_group->length)
+		return 1;
+	return 0;
+}
+
+static void mark_range_processed(struct reloc_control *rc,
+				 u64 bytenr, u32 blocksize)
+{
+	set_extent_bits(&rc->processed_blocks, bytenr, bytenr + blocksize - 1,
+			EXTENT_DIRTY);
+}
+
+static void mark_block_processed(struct reloc_control *rc,
+				 struct backref_node *node)
+{
+	u32 blocksize;
+	if (node->level == 0 ||
+	    in_block_group(node->bytenr, rc->block_group)) {
+		blocksize = rc->extent_root->fs_info->nodesize;
+		mark_range_processed(rc, node->bytenr, blocksize);
+	}
+	node->processed = 1;
+}
+
 
 static void mapping_tree_init(struct mapping_tree *tree)
 {
@@ -1045,7 +1071,7 @@  struct backref_node *build_backref_tree(struct reloc_control *rc,
 			if (list_empty(&lower->upper))
 				list_add(&lower->list, &useless);
 		}
-		__mark_block_processed(rc, upper);
+		mark_block_processed(rc, upper);
 		if (upper->level > 0) {
 			list_add(&upper->list, &cache->detached);
 			upper->detached = 1;
@@ -1509,14 +1535,6 @@  static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid)
 	return NULL;
 }
 
-static int in_block_group(u64 bytenr, struct btrfs_block_group *block_group)
-{
-	if (bytenr >= block_group->start &&
-	    bytenr < block_group->start + block_group->length)
-		return 1;
-	return 0;
-}
-
 /*
  * get new location of data
  */
@@ -2537,7 +2555,7 @@  struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans,
 			next->root = root;
 			list_add_tail(&next->list,
 				      &rc->backref_cache.changed);
-			__mark_block_processed(rc, next);
+			mark_block_processed(rc, next);
 			break;
 		}
 
@@ -2887,25 +2905,6 @@  static int finish_pending_nodes(struct btrfs_trans_handle *trans,
 	return err;
 }
 
-static void mark_block_processed(struct reloc_control *rc,
-				 u64 bytenr, u32 blocksize)
-{
-	set_extent_bits(&rc->processed_blocks, bytenr, bytenr + blocksize - 1,
-			EXTENT_DIRTY);
-}
-
-static void __mark_block_processed(struct reloc_control *rc,
-				   struct backref_node *node)
-{
-	u32 blocksize;
-	if (node->level == 0 ||
-	    in_block_group(node->bytenr, rc->block_group)) {
-		blocksize = rc->extent_root->fs_info->nodesize;
-		mark_block_processed(rc, node->bytenr, blocksize);
-	}
-	node->processed = 1;
-}
-
 /*
  * mark a block and all blocks directly/indirectly reference the block
  * as processed.
@@ -2924,7 +2923,7 @@  static void update_processed_blocks(struct reloc_control *rc,
 			if (next->processed)
 				break;
 
-			__mark_block_processed(rc, next);
+			mark_block_processed(rc, next);
 
 			if (list_empty(&next->upper))
 				break;
@@ -4663,7 +4662,7 @@  int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
 		}
 
 		if (first_cow)
-			__mark_block_processed(rc, node);
+			mark_block_processed(rc, node);
 
 		if (first_cow && level > 0)
 			rc->nodes_relocated += buf->len;