All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: send: use struct send_ctx *sctx for btrfs_compare_trees and changed_cb
@ 2021-01-25 19:43 Roman Anasal
  2021-01-26 18:05 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Roman Anasal @ 2021-01-25 19:43 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Roman Anasal

btrfs_compare_trees and changed_cb use a void *ctx parameter instead of
struct send_ctx *sctx but when used in changed_cb it is immediately
casted to `struct send_ctx *sctx = ctx;`.

changed_cb is only ever called from btrfs_compare_trees and full_send_tree:
- full_send_tree already passes a struct send_ctx *sctx
- btrfs_compare_trees is only called by send_subvol with a struct send_ctx *sctx
- void *ctx in btrfs_compare_trees is only used to be passed to changed_cb

So casting to/from void *ctx seems unnecessary and directly using
struct send_ctx *sctx instead provides better type-safety.

The original reason for using void *ctx in the first place seems to have
been dropped with
1b51d6f ("btrfs: send: remove indirect callback parameter for changed_cb")

Signed-off-by: Roman Anasal <roman.anasal@bdsu.de>
---
 fs/btrfs/send.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index ae97f4dba..fee15c4d3 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -6592,10 +6592,9 @@ static int changed_cb(struct btrfs_path *left_path,
 		      struct btrfs_path *right_path,
 		      struct btrfs_key *key,
 		      enum btrfs_compare_tree_result result,
-		      void *ctx)
+		      struct send_ctx *sctx)
 {
 	int ret = 0;
-	struct send_ctx *sctx = ctx;
 
 	if (result == BTRFS_COMPARE_TREE_SAME) {
 		if (key->type == BTRFS_INODE_REF_KEY ||
@@ -6800,7 +6799,7 @@ static int tree_compare_item(struct btrfs_path *left_path,
  * If it detects a change, it aborts immediately.
  */
 static int btrfs_compare_trees(struct btrfs_root *left_root,
-			struct btrfs_root *right_root, void *ctx)
+			struct btrfs_root *right_root, struct send_ctx *sctx)
 {
 	struct btrfs_fs_info *fs_info = left_root->fs_info;
 	int ret;
@@ -6952,7 +6951,7 @@ static int btrfs_compare_trees(struct btrfs_root *left_root,
 				ret = changed_cb(left_path, right_path,
 						&right_key,
 						BTRFS_COMPARE_TREE_DELETED,
-						ctx);
+						sctx);
 				if (ret < 0)
 					goto out;
 			}
@@ -6963,7 +6962,7 @@ static int btrfs_compare_trees(struct btrfs_root *left_root,
 				ret = changed_cb(left_path, right_path,
 						&left_key,
 						BTRFS_COMPARE_TREE_NEW,
-						ctx);
+						sctx);
 				if (ret < 0)
 					goto out;
 			}
@@ -6977,7 +6976,7 @@ static int btrfs_compare_trees(struct btrfs_root *left_root,
 				ret = changed_cb(left_path, right_path,
 						&left_key,
 						BTRFS_COMPARE_TREE_NEW,
-						ctx);
+						sctx);
 				if (ret < 0)
 					goto out;
 				advance_left = ADVANCE;
@@ -6985,7 +6984,7 @@ static int btrfs_compare_trees(struct btrfs_root *left_root,
 				ret = changed_cb(left_path, right_path,
 						&right_key,
 						BTRFS_COMPARE_TREE_DELETED,
-						ctx);
+						sctx);
 				if (ret < 0)
 					goto out;
 				advance_right = ADVANCE;
@@ -7000,7 +6999,7 @@ static int btrfs_compare_trees(struct btrfs_root *left_root,
 				else
 					result = BTRFS_COMPARE_TREE_SAME;
 				ret = changed_cb(left_path, right_path,
-						 &left_key, result, ctx);
+						 &left_key, result, sctx);
 				if (ret < 0)
 					goto out;
 				advance_left = ADVANCE;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs: send: use struct send_ctx *sctx for btrfs_compare_trees and changed_cb
  2021-01-25 19:43 [PATCH] btrfs: send: use struct send_ctx *sctx for btrfs_compare_trees and changed_cb Roman Anasal
@ 2021-01-26 18:05 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2021-01-26 18:05 UTC (permalink / raw)
  To: Roman Anasal; +Cc: linux-btrfs

On Mon, Jan 25, 2021 at 08:43:25PM +0100, Roman Anasal wrote:
> btrfs_compare_trees and changed_cb use a void *ctx parameter instead of
> struct send_ctx *sctx but when used in changed_cb it is immediately
> casted to `struct send_ctx *sctx = ctx;`.
> 
> changed_cb is only ever called from btrfs_compare_trees and full_send_tree:
> - full_send_tree already passes a struct send_ctx *sctx
> - btrfs_compare_trees is only called by send_subvol with a struct send_ctx *sctx
> - void *ctx in btrfs_compare_trees is only used to be passed to changed_cb
> 
> So casting to/from void *ctx seems unnecessary and directly using
> struct send_ctx *sctx instead provides better type-safety.
> 
> The original reason for using void *ctx in the first place seems to have
> been dropped with
> 1b51d6f ("btrfs: send: remove indirect callback parameter for changed_cb")
> 
> Signed-off-by: Roman Anasal <roman.anasal@bdsu.de>

Makes sense, added to misc-next, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-27 10:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25 19:43 [PATCH] btrfs: send: use struct send_ctx *sctx for btrfs_compare_trees and changed_cb Roman Anasal
2021-01-26 18:05 ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.