Message ID | f31af8b1283c8dab1f07b0fb7a9617f97f991b7f.1713052088.git.josef@toxicpanda.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: delayed refs cleanups | expand |
On Sun, Apr 14, 2024 at 12:54 AM Josef Bacik <josef@toxicpanda.com> wrote: > > We're extracting all of these values from the btrfs_ref we passed in > already, just pass the btrfs_ref through to init_delayed_ref_common and > get the values directly from the struct. > > Signed-off-by: Josef Bacik <josef@toxicpanda.com> > --- > fs/btrfs/delayed-ref.c | 29 ++++++++--------------------- > fs/btrfs/delayed-ref.h | 19 +++++++++++++++++++ > 2 files changed, 27 insertions(+), 21 deletions(-) > > diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c > index c6a1b6938654..f5e4a64283e4 100644 > --- a/fs/btrfs/delayed-ref.c > +++ b/fs/btrfs/delayed-ref.c > @@ -985,24 +985,24 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, > */ > static void init_delayed_ref_common(struct btrfs_fs_info *fs_info, > struct btrfs_delayed_ref_node *ref, > - u64 bytenr, u64 num_bytes, u64 ref_root, > - int action, u8 ref_type) > + struct btrfs_ref *generic_ref) > { > + int action = generic_ref->action; > u64 seq = 0; > > if (action == BTRFS_ADD_DELAYED_EXTENT) > action = BTRFS_ADD_DELAYED_REF; > > - if (is_fstree(ref_root)) > + if (is_fstree(generic_ref->ref_root)) > seq = atomic64_read(&fs_info->tree_mod_seq); > > refcount_set(&ref->refs, 1); > - ref->bytenr = bytenr; > - ref->num_bytes = num_bytes; > + ref->bytenr = generic_ref->bytenr; > + ref->num_bytes = generic_ref->len; > ref->ref_mod = 1; > ref->action = action; > ref->seq = seq; > - ref->type = ref_type; > + ref->type = btrfs_ref_type(generic_ref); > RB_CLEAR_NODE(&ref->ref_node); > INIT_LIST_HEAD(&ref->add_list); > } > @@ -1064,7 +1064,6 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, > u64 bytenr = generic_ref->bytenr; > u64 num_bytes = generic_ref->len; > u64 parent = generic_ref->parent; > - u8 ref_type; > > is_system = (generic_ref->ref_root == BTRFS_CHUNK_TREE_OBJECTID); > > @@ -1090,13 +1089,7 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, > > ref = btrfs_delayed_node_to_tree_ref(node); > > - if (parent) > - ref_type = BTRFS_SHARED_BLOCK_REF_KEY; > - else > - ref_type = BTRFS_TREE_BLOCK_REF_KEY; > - > - init_delayed_ref_common(fs_info, node, bytenr, num_bytes, > - generic_ref->ref_root, action, ref_type); > + init_delayed_ref_common(fs_info, node, generic_ref); > ref->root = generic_ref->ref_root; > ref->parent = parent; > ref->level = level; > @@ -1159,7 +1152,6 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, > u64 ref_root = generic_ref->ref_root; > u64 owner = generic_ref->data_ref.ino; > u64 offset = generic_ref->data_ref.offset; > - u8 ref_type; > > ASSERT(generic_ref->type == BTRFS_REF_DATA && action); > node = kmem_cache_alloc(btrfs_delayed_ref_node_cachep, GFP_NOFS); > @@ -1168,12 +1160,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, > > ref = btrfs_delayed_node_to_data_ref(node); > > - if (parent) > - ref_type = BTRFS_SHARED_DATA_REF_KEY; > - else > - ref_type = BTRFS_EXTENT_DATA_REF_KEY; > - init_delayed_ref_common(fs_info, node, bytenr, num_bytes, ref_root, > - action, ref_type); > + init_delayed_ref_common(fs_info, node, generic_ref); > ref->root = ref_root; > ref->parent = parent; > ref->objectid = owner; > diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h > index bf2916906bb8..83fcb32715a4 100644 > --- a/fs/btrfs/delayed-ref.h > +++ b/fs/btrfs/delayed-ref.h > @@ -421,4 +421,23 @@ btrfs_delayed_data_ref_to_node(struct btrfs_delayed_data_ref *ref) > return container_of(ref, struct btrfs_delayed_ref_node, data_ref); > } > > +static inline u8 btrfs_ref_type(struct btrfs_ref *ref) > +{ > + ASSERT(ref->type != BTRFS_REF_NOT_SET); Maybe: ASSERT(ref->type == BTRFS_REF_DATA || ref->type == BTRFS_REF_METADATA); To catch any other unexpected value. Other than that: Reviewed-by: Filipe Manana <fdmanana@suse.com> Thanks. > + > + if (ref->type == BTRFS_REF_DATA) { > + if (ref->parent) > + return BTRFS_SHARED_DATA_REF_KEY; > + else > + return BTRFS_EXTENT_DATA_REF_KEY; > + } else { > + if (ref->parent) > + return BTRFS_SHARED_BLOCK_REF_KEY; > + else > + return BTRFS_TREE_BLOCK_REF_KEY; > + } > + > + return 0; > +} > + > #endif > -- > 2.43.0 > >
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index c6a1b6938654..f5e4a64283e4 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -985,24 +985,24 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, */ static void init_delayed_ref_common(struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_node *ref, - u64 bytenr, u64 num_bytes, u64 ref_root, - int action, u8 ref_type) + struct btrfs_ref *generic_ref) { + int action = generic_ref->action; u64 seq = 0; if (action == BTRFS_ADD_DELAYED_EXTENT) action = BTRFS_ADD_DELAYED_REF; - if (is_fstree(ref_root)) + if (is_fstree(generic_ref->ref_root)) seq = atomic64_read(&fs_info->tree_mod_seq); refcount_set(&ref->refs, 1); - ref->bytenr = bytenr; - ref->num_bytes = num_bytes; + ref->bytenr = generic_ref->bytenr; + ref->num_bytes = generic_ref->len; ref->ref_mod = 1; ref->action = action; ref->seq = seq; - ref->type = ref_type; + ref->type = btrfs_ref_type(generic_ref); RB_CLEAR_NODE(&ref->ref_node); INIT_LIST_HEAD(&ref->add_list); } @@ -1064,7 +1064,6 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, u64 bytenr = generic_ref->bytenr; u64 num_bytes = generic_ref->len; u64 parent = generic_ref->parent; - u8 ref_type; is_system = (generic_ref->ref_root == BTRFS_CHUNK_TREE_OBJECTID); @@ -1090,13 +1089,7 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, ref = btrfs_delayed_node_to_tree_ref(node); - if (parent) - ref_type = BTRFS_SHARED_BLOCK_REF_KEY; - else - ref_type = BTRFS_TREE_BLOCK_REF_KEY; - - init_delayed_ref_common(fs_info, node, bytenr, num_bytes, - generic_ref->ref_root, action, ref_type); + init_delayed_ref_common(fs_info, node, generic_ref); ref->root = generic_ref->ref_root; ref->parent = parent; ref->level = level; @@ -1159,7 +1152,6 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, u64 ref_root = generic_ref->ref_root; u64 owner = generic_ref->data_ref.ino; u64 offset = generic_ref->data_ref.offset; - u8 ref_type; ASSERT(generic_ref->type == BTRFS_REF_DATA && action); node = kmem_cache_alloc(btrfs_delayed_ref_node_cachep, GFP_NOFS); @@ -1168,12 +1160,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, ref = btrfs_delayed_node_to_data_ref(node); - if (parent) - ref_type = BTRFS_SHARED_DATA_REF_KEY; - else - ref_type = BTRFS_EXTENT_DATA_REF_KEY; - init_delayed_ref_common(fs_info, node, bytenr, num_bytes, ref_root, - action, ref_type); + init_delayed_ref_common(fs_info, node, generic_ref); ref->root = ref_root; ref->parent = parent; ref->objectid = owner; diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index bf2916906bb8..83fcb32715a4 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -421,4 +421,23 @@ btrfs_delayed_data_ref_to_node(struct btrfs_delayed_data_ref *ref) return container_of(ref, struct btrfs_delayed_ref_node, data_ref); } +static inline u8 btrfs_ref_type(struct btrfs_ref *ref) +{ + ASSERT(ref->type != BTRFS_REF_NOT_SET); + + if (ref->type == BTRFS_REF_DATA) { + if (ref->parent) + return BTRFS_SHARED_DATA_REF_KEY; + else + return BTRFS_EXTENT_DATA_REF_KEY; + } else { + if (ref->parent) + return BTRFS_SHARED_BLOCK_REF_KEY; + else + return BTRFS_TREE_BLOCK_REF_KEY; + } + + return 0; +} + #endif
We're extracting all of these values from the btrfs_ref we passed in already, just pass the btrfs_ref through to init_delayed_ref_common and get the values directly from the struct. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- fs/btrfs/delayed-ref.c | 29 ++++++++--------------------- fs/btrfs/delayed-ref.h | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 21 deletions(-)