diff mbox series

btrfs: move btrfs_defrag_root() to defrag.{c,h}

Message ID 9474fc4f5eca4a1e7bb38dd1cd2bd01537c4315a.1695335503.git.fdmanana@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: move btrfs_defrag_root() to defrag.{c,h} | expand

Commit Message

Filipe Manana Sept. 22, 2023, 10:37 a.m. UTC
From: Filipe Manana <fdmanana@suse.com>

The btrfs_defrag_root() function does not really belong in the
transaction.{c,h} module and as we have a defrag.{c,h} nowadays,
move it to there instead. This also allows to stop exporting
btrfs_defrag_leaves(), so we can make it static.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/defrag.c      | 44 ++++++++++++++++++++++++++++++++++++++++--
 fs/btrfs/defrag.h      |  2 +-
 fs/btrfs/transaction.c | 39 -------------------------------------
 fs/btrfs/transaction.h |  1 -
 4 files changed, 43 insertions(+), 43 deletions(-)

Comments

David Sterba Sept. 22, 2023, 2:13 p.m. UTC | #1
On Fri, Sep 22, 2023 at 11:37:56AM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> The btrfs_defrag_root() function does not really belong in the
> transaction.{c,h} module and as we have a defrag.{c,h} nowadays,
> move it to there instead. This also allows to stop exporting
> btrfs_defrag_leaves(), so we can make it static.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Added to misc-next, thanks.

> ---
>  fs/btrfs/defrag.c      | 44 ++++++++++++++++++++++++++++++++++++++++--
>  fs/btrfs/defrag.h      |  2 +-
>  fs/btrfs/transaction.c | 39 -------------------------------------
>  fs/btrfs/transaction.h |  1 -
>  4 files changed, 43 insertions(+), 43 deletions(-)
> 
> diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
> index f2ff4cbe8656..53544787c348 100644
> --- a/fs/btrfs/defrag.c
> +++ b/fs/btrfs/defrag.c
> @@ -343,8 +343,8 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)
>   * better reflect disk order
>   */
>  
> -int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
> -			struct btrfs_root *root)
> +static int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
> +			       struct btrfs_root *root)
>  {
>  	struct btrfs_path *path = NULL;
>  	struct btrfs_key key;
> @@ -460,6 +460,46 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
>  	return ret;
>  }
>  
> +/*
> + * Defrag a given btree.
> + * Every leaf in the btree is read and defragged.
> + */
> +int btrfs_defrag_root(struct btrfs_root *root)
> +{
> +	struct btrfs_fs_info *info = root->fs_info;

Thi is a good opportunity, I've renamed it to fs_info as this is the
most commonly used name.
Qu Wenruo Sept. 22, 2023, 10:12 p.m. UTC | #2
On 2023/9/22 20:07, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> The btrfs_defrag_root() function does not really belong in the
> transaction.{c,h} module and as we have a defrag.{c,h} nowadays,
> move it to there instead. This also allows to stop exporting
> btrfs_defrag_leaves(), so we can make it static.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/defrag.c      | 44 ++++++++++++++++++++++++++++++++++++++++--
>   fs/btrfs/defrag.h      |  2 +-
>   fs/btrfs/transaction.c | 39 -------------------------------------
>   fs/btrfs/transaction.h |  1 -
>   4 files changed, 43 insertions(+), 43 deletions(-)
>
> diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
> index f2ff4cbe8656..53544787c348 100644
> --- a/fs/btrfs/defrag.c
> +++ b/fs/btrfs/defrag.c
> @@ -343,8 +343,8 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)
>    * better reflect disk order
>    */
>
> -int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
> -			struct btrfs_root *root)
> +static int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
> +			       struct btrfs_root *root)
>   {
>   	struct btrfs_path *path = NULL;
>   	struct btrfs_key key;
> @@ -460,6 +460,46 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
>   	return ret;
>   }
>
> +/*
> + * Defrag a given btree.
> + * Every leaf in the btree is read and defragged.
> + */
> +int btrfs_defrag_root(struct btrfs_root *root)
> +{
> +	struct btrfs_fs_info *info = root->fs_info;
> +	int ret;
> +
> +	if (test_and_set_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state))
> +		return 0;
> +
> +	while (1) {
> +		struct btrfs_trans_handle *trans;
> +
> +		trans = btrfs_start_transaction(root, 0);
> +		if (IS_ERR(trans)) {
> +			ret = PTR_ERR(trans);
> +			break;
> +		}
> +
> +		ret = btrfs_defrag_leaves(trans, root);
> +
> +		btrfs_end_transaction(trans);
> +		btrfs_btree_balance_dirty(info);
> +		cond_resched();
> +
> +		if (btrfs_fs_closing(info) || ret != -EAGAIN)
> +			break;
> +
> +		if (btrfs_defrag_cancelled(info)) {
> +			btrfs_debug(info, "defrag_root cancelled");
> +			ret = -EAGAIN;
> +			break;
> +		}
> +	}
> +	clear_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state);
> +	return ret;
> +}
> +
>   /*
>    * Defrag specific helper to get an extent map.
>    *
> diff --git a/fs/btrfs/defrag.h b/fs/btrfs/defrag.h
> index 5305f2283b5e..5a62763528d1 100644
> --- a/fs/btrfs/defrag.h
> +++ b/fs/btrfs/defrag.h
> @@ -12,7 +12,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
>   			   struct btrfs_inode *inode, u32 extent_thresh);
>   int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info);
>   void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info);
> -int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, struct btrfs_root *root);
> +int btrfs_defrag_root(struct btrfs_root *root);
>
>   static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
>   {
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index 240dad25fa16..c05c2cd84688 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -1564,45 +1564,6 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)
>   	return 0;
>   }
>
> -/*
> - * defrag a given btree.
> - * Every leaf in the btree is read and defragged.
> - */
> -int btrfs_defrag_root(struct btrfs_root *root)
> -{
> -	struct btrfs_fs_info *info = root->fs_info;
> -	struct btrfs_trans_handle *trans;
> -	int ret;
> -
> -	if (test_and_set_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state))
> -		return 0;
> -
> -	while (1) {
> -		trans = btrfs_start_transaction(root, 0);
> -		if (IS_ERR(trans)) {
> -			ret = PTR_ERR(trans);
> -			break;
> -		}
> -
> -		ret = btrfs_defrag_leaves(trans, root);
> -
> -		btrfs_end_transaction(trans);
> -		btrfs_btree_balance_dirty(info);
> -		cond_resched();
> -
> -		if (btrfs_fs_closing(info) || ret != -EAGAIN)
> -			break;
> -
> -		if (btrfs_defrag_cancelled(info)) {
> -			btrfs_debug(info, "defrag_root cancelled");
> -			ret = -EAGAIN;
> -			break;
> -		}
> -	}
> -	clear_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state);
> -	return ret;
> -}
> -
>   /*
>    * Do all special snapshot related qgroup dirty hack.
>    *
> diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
> index efc4fa9e2bd8..de58776de307 100644
> --- a/fs/btrfs/transaction.h
> +++ b/fs/btrfs/transaction.h
> @@ -246,7 +246,6 @@ struct btrfs_trans_handle *btrfs_attach_transaction_barrier(
>   int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid);
>
>   void btrfs_add_dead_root(struct btrfs_root *root);
> -int btrfs_defrag_root(struct btrfs_root *root);
>   void btrfs_maybe_wake_unfinished_drop(struct btrfs_fs_info *fs_info);
>   int btrfs_clean_one_deleted_snapshot(struct btrfs_fs_info *fs_info);
>   int btrfs_commit_transaction(struct btrfs_trans_handle *trans);
diff mbox series

Patch

diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
index f2ff4cbe8656..53544787c348 100644
--- a/fs/btrfs/defrag.c
+++ b/fs/btrfs/defrag.c
@@ -343,8 +343,8 @@  int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)
  * better reflect disk order
  */
 
-int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
-			struct btrfs_root *root)
+static int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
+			       struct btrfs_root *root)
 {
 	struct btrfs_path *path = NULL;
 	struct btrfs_key key;
@@ -460,6 +460,46 @@  int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
+/*
+ * Defrag a given btree.
+ * Every leaf in the btree is read and defragged.
+ */
+int btrfs_defrag_root(struct btrfs_root *root)
+{
+	struct btrfs_fs_info *info = root->fs_info;
+	int ret;
+
+	if (test_and_set_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state))
+		return 0;
+
+	while (1) {
+		struct btrfs_trans_handle *trans;
+
+		trans = btrfs_start_transaction(root, 0);
+		if (IS_ERR(trans)) {
+			ret = PTR_ERR(trans);
+			break;
+		}
+
+		ret = btrfs_defrag_leaves(trans, root);
+
+		btrfs_end_transaction(trans);
+		btrfs_btree_balance_dirty(info);
+		cond_resched();
+
+		if (btrfs_fs_closing(info) || ret != -EAGAIN)
+			break;
+
+		if (btrfs_defrag_cancelled(info)) {
+			btrfs_debug(info, "defrag_root cancelled");
+			ret = -EAGAIN;
+			break;
+		}
+	}
+	clear_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state);
+	return ret;
+}
+
 /*
  * Defrag specific helper to get an extent map.
  *
diff --git a/fs/btrfs/defrag.h b/fs/btrfs/defrag.h
index 5305f2283b5e..5a62763528d1 100644
--- a/fs/btrfs/defrag.h
+++ b/fs/btrfs/defrag.h
@@ -12,7 +12,7 @@  int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
 			   struct btrfs_inode *inode, u32 extent_thresh);
 int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info);
 void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info);
-int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, struct btrfs_root *root);
+int btrfs_defrag_root(struct btrfs_root *root);
 
 static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
 {
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 240dad25fa16..c05c2cd84688 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1564,45 +1564,6 @@  static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)
 	return 0;
 }
 
-/*
- * defrag a given btree.
- * Every leaf in the btree is read and defragged.
- */
-int btrfs_defrag_root(struct btrfs_root *root)
-{
-	struct btrfs_fs_info *info = root->fs_info;
-	struct btrfs_trans_handle *trans;
-	int ret;
-
-	if (test_and_set_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state))
-		return 0;
-
-	while (1) {
-		trans = btrfs_start_transaction(root, 0);
-		if (IS_ERR(trans)) {
-			ret = PTR_ERR(trans);
-			break;
-		}
-
-		ret = btrfs_defrag_leaves(trans, root);
-
-		btrfs_end_transaction(trans);
-		btrfs_btree_balance_dirty(info);
-		cond_resched();
-
-		if (btrfs_fs_closing(info) || ret != -EAGAIN)
-			break;
-
-		if (btrfs_defrag_cancelled(info)) {
-			btrfs_debug(info, "defrag_root cancelled");
-			ret = -EAGAIN;
-			break;
-		}
-	}
-	clear_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state);
-	return ret;
-}
-
 /*
  * Do all special snapshot related qgroup dirty hack.
  *
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index efc4fa9e2bd8..de58776de307 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -246,7 +246,6 @@  struct btrfs_trans_handle *btrfs_attach_transaction_barrier(
 int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid);
 
 void btrfs_add_dead_root(struct btrfs_root *root);
-int btrfs_defrag_root(struct btrfs_root *root);
 void btrfs_maybe_wake_unfinished_drop(struct btrfs_fs_info *fs_info);
 int btrfs_clean_one_deleted_snapshot(struct btrfs_fs_info *fs_info);
 int btrfs_commit_transaction(struct btrfs_trans_handle *trans);