[2/3] btrfs-progs: Refactor btrfs_finish_extent_commit()
diff mbox series

Message ID 20190416071526.3576-3-wqu@suse.com
State New
Headers show
Series
  • btrfs-progs: Handle error properly in btrfs_commit_transaction()
Related show

Commit Message

Qu Wenruo April 16, 2019, 7:15 a.m. UTC
This patch will refactor btrfs_finish_extent_commit() by:
- Make it return void
  There is no failure pattern for btrfs_finish_extent_commit(), thus it
  always return 0. And the caller doesn't care about the return value.
  So no need to return int.

- Remove @root and @unpin parameters
  @root is only used to extract fs_info, which can be extracted from
  transaction handler already.
  @unpin is always fs_info->pinned_extents.
  All these parameters can be extracted from @trans, no need to pass
  them.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 ctree.h       |  4 +---
 extent-tree.c | 14 ++++++--------
 transaction.c |  3 +--
 3 files changed, 8 insertions(+), 13 deletions(-)

Comments

Nikolay Borisov April 16, 2019, 7:39 a.m. UTC | #1
On 16.04.19 г. 10:15 ч., Qu Wenruo wrote:
> This patch will refactor btrfs_finish_extent_commit() by:
> - Make it return void
>   There is no failure pattern for btrfs_finish_extent_commit(), thus it
>   always return 0. And the caller doesn't care about the return value.
>   So no need to return int.
> 
> - Remove @root and @unpin parameters
>   @root is only used to extract fs_info, which can be extracted from
>   transaction handler already.
>   @unpin is always fs_info->pinned_extents.
>   All these parameters can be extracted from @trans, no need to pass
>   them.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

This also makes the function's signature identical to its kernel
counterpart.


Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  ctree.h       |  4 +---
>  extent-tree.c | 14 ++++++--------
>  transaction.c |  3 +--
>  3 files changed, 8 insertions(+), 13 deletions(-)
> 
> diff --git a/ctree.h b/ctree.h
> index 3357290d7045..76f52b1c9b08 100644
> --- a/ctree.h
> +++ b/ctree.h
> @@ -2516,9 +2516,7 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,
>  		      struct btrfs_root *root,
>  		      u64 bytenr, u64 num_bytes, u64 parent,
>  		      u64 root_objectid, u64 owner, u64 offset);
> -int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
> -			       struct btrfs_root *root,
> -			       struct extent_io_tree *unpin);
> +void btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
>  int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
>  				struct btrfs_root *root,
>  				u64 bytenr, u64 num_bytes, u64 parent,
> diff --git a/extent-tree.c b/extent-tree.c
> index b7ece0ccc237..1140ebfc61ff 100644
> --- a/extent-tree.c
> +++ b/extent-tree.c
> @@ -1977,27 +1977,25 @@ next:
>  	return 0;
>  }
>  
> -int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
> -			       struct btrfs_root *root,
> -			       struct extent_io_tree *unpin)
> +void btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
>  {
>  	u64 start;
>  	u64 end;
>  	int ret;
> -	struct extent_io_tree *free_space_cache;
> -	free_space_cache = &root->fs_info->free_space_cache;
> +	struct btrfs_fs_info *fs_info = trans->fs_info;
> +	struct extent_io_tree *free_space_cache = &fs_info->free_space_cache;
> +	struct extent_io_tree *pinned_extents = &fs_info->pinned_extents;
>  
>  	while(1) {
> -		ret = find_first_extent_bit(unpin, 0, &start, &end,
> +		ret = find_first_extent_bit(pinned_extents, 0, &start, &end,
>  					    EXTENT_DIRTY);
>  		if (ret)
>  			break;
>  		update_pinned_extents(trans->fs_info, start, end + 1 - start,
>  				      0);
> -		clear_extent_dirty(unpin, start, end);
> +		clear_extent_dirty(pinned_extents, start, end);
>  		set_extent_dirty(free_space_cache, start, end);
>  	}
> -	return 0;
>  }
>  
>  static int pin_down_bytes(struct btrfs_trans_handle *trans, u64 bytenr,
> diff --git a/transaction.c b/transaction.c
> index 3a63988b0969..8d15eb11c7b5 100644
> --- a/transaction.c
> +++ b/transaction.c
> @@ -198,8 +198,7 @@ commit_tree:
>  	if (ret < 0)
>  		goto out;
>  	ret = write_ctree_super(trans);
> -	btrfs_finish_extent_commit(trans, fs_info->extent_root,
> -			           &fs_info->pinned_extents);
> +	btrfs_finish_extent_commit(trans);
>  	kfree(trans);
>  	free_extent_buffer(root->commit_root);
>  	root->commit_root = NULL;
>

Patch
diff mbox series

diff --git a/ctree.h b/ctree.h
index 3357290d7045..76f52b1c9b08 100644
--- a/ctree.h
+++ b/ctree.h
@@ -2516,9 +2516,7 @@  int btrfs_free_extent(struct btrfs_trans_handle *trans,
 		      struct btrfs_root *root,
 		      u64 bytenr, u64 num_bytes, u64 parent,
 		      u64 root_objectid, u64 owner, u64 offset);
-int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
-			       struct btrfs_root *root,
-			       struct extent_io_tree *unpin);
+void btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
 				struct btrfs_root *root,
 				u64 bytenr, u64 num_bytes, u64 parent,
diff --git a/extent-tree.c b/extent-tree.c
index b7ece0ccc237..1140ebfc61ff 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -1977,27 +1977,25 @@  next:
 	return 0;
 }
 
-int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
-			       struct btrfs_root *root,
-			       struct extent_io_tree *unpin)
+void btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
 {
 	u64 start;
 	u64 end;
 	int ret;
-	struct extent_io_tree *free_space_cache;
-	free_space_cache = &root->fs_info->free_space_cache;
+	struct btrfs_fs_info *fs_info = trans->fs_info;
+	struct extent_io_tree *free_space_cache = &fs_info->free_space_cache;
+	struct extent_io_tree *pinned_extents = &fs_info->pinned_extents;
 
 	while(1) {
-		ret = find_first_extent_bit(unpin, 0, &start, &end,
+		ret = find_first_extent_bit(pinned_extents, 0, &start, &end,
 					    EXTENT_DIRTY);
 		if (ret)
 			break;
 		update_pinned_extents(trans->fs_info, start, end + 1 - start,
 				      0);
-		clear_extent_dirty(unpin, start, end);
+		clear_extent_dirty(pinned_extents, start, end);
 		set_extent_dirty(free_space_cache, start, end);
 	}
-	return 0;
 }
 
 static int pin_down_bytes(struct btrfs_trans_handle *trans, u64 bytenr,
diff --git a/transaction.c b/transaction.c
index 3a63988b0969..8d15eb11c7b5 100644
--- a/transaction.c
+++ b/transaction.c
@@ -198,8 +198,7 @@  commit_tree:
 	if (ret < 0)
 		goto out;
 	ret = write_ctree_super(trans);
-	btrfs_finish_extent_commit(trans, fs_info->extent_root,
-			           &fs_info->pinned_extents);
+	btrfs_finish_extent_commit(trans);
 	kfree(trans);
 	free_extent_buffer(root->commit_root);
 	root->commit_root = NULL;