From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/8] btrfs: delayed-ref: Use btrfs_ref to refactor btrfs_add_delayed_tree_ref()
Date: Mon, 10 Dec 2018 11:21:10 +0200 [thread overview]
Message-ID: <167bf109-41cf-f10b-4364-9af5701f5ee0@suse.com> (raw)
In-Reply-To: <20181206065903.11343-4-wqu@suse.com>
On 6.12.18 г. 8:58 ч., Qu Wenruo wrote:
> btrfs_add_delayed_tree_ref() has a longer and longer parameter list, and
> some caller like btrfs_inc_extent_ref() are using @owner as level for
> delayed tree ref.
>
> Instead of making the parameter list longer and longer, use btrfs_ref to
> refactor it, so each parameter assignment should be self-explaining
> without dirty level/owner trick, and provides the basis for later refactor.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> fs/btrfs/delayed-ref.c | 24 ++++++++++++++-------
> fs/btrfs/delayed-ref.h | 4 +---
> fs/btrfs/extent-tree.c | 48 ++++++++++++++++++++++++------------------
> 3 files changed, 44 insertions(+), 32 deletions(-)
>
> diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
> index 11dd46be4017..c42b8ade7b07 100644
> --- a/fs/btrfs/delayed-ref.c
> +++ b/fs/btrfs/delayed-ref.c
> @@ -710,9 +710,7 @@ static void init_delayed_ref_common(struct btrfs_fs_info *fs_info,
> * transaction commits.
> */
> int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
> - u64 bytenr, u64 num_bytes, u64 parent,
> - u64 ref_root, int level, bool for_reloc,
> - int action,
> + struct btrfs_ref *generic_ref,
> struct btrfs_delayed_extent_op *extent_op,
> int *old_ref_mod, int *new_ref_mod)
> {
> @@ -722,10 +720,17 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
> struct btrfs_delayed_ref_root *delayed_refs;
> struct btrfs_qgroup_extent_record *record = NULL;
> int qrecord_inserted;
> - bool is_system = (ref_root == BTRFS_CHUNK_TREE_OBJECTID);
> + bool is_system = (generic_ref->real_root == BTRFS_CHUNK_TREE_OBJECTID);
> + int action = generic_ref->action;
> + int level = generic_ref->tree_ref.level;
> int ret;
> + u64 bytenr = generic_ref->bytenr;
> + u64 num_bytes = generic_ref->len;
> + u64 parent = generic_ref->parent;
> u8 ref_type;
>
> + ASSERT(generic_ref && generic_ref->type == BTRFS_REF_METADATA &&
> + generic_ref->action);
You have already dereferenced generic_ref by the time you ASSERT and
would have crashed. I guess the first condition in the assert can be
removed.
> BUG_ON(extent_op && extent_op->is_data);
> ref = kmem_cache_alloc(btrfs_delayed_tree_ref_cachep, GFP_NOFS);
> if (!ref)
<snip>
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -2031,6 +2031,7 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
> bool for_reloc)
> {
> struct btrfs_fs_info *fs_info = root->fs_info;
> + struct btrfs_ref generic_ref = { 0 };
> int old_ref_mod, new_ref_mod;
> int ret;
>
> @@ -2040,13 +2041,13 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
> btrfs_ref_tree_mod(root, bytenr, num_bytes, parent, root_objectid,
> owner, offset, BTRFS_ADD_DELAYED_REF);
>
> + btrfs_init_generic_ref(&generic_ref, BTRFS_ADD_DELAYED_REF, bytenr,
> + num_bytes, root->root_key.objectid, parent);
> + generic_ref.skip_qgroup = for_reloc;
> if (owner < BTRFS_FIRST_FREE_OBJECTID) {
> - ret = btrfs_add_delayed_tree_ref(trans, bytenr,
> - num_bytes, parent,
> - root_objectid, (int)owner,
> - for_reloc,
> - BTRFS_ADD_DELAYED_REF, NULL,
> - &old_ref_mod, &new_ref_mod);
> + btrfs_init_tree_ref(&generic_ref, (int)owner, root_objectid);
The cast is now redundant since the parameter definition of
btrfs_init_tree_ref is an int.
> + ret = btrfs_add_delayed_tree_ref(trans, &generic_ref,
> + NULL, &old_ref_mod, &new_ref_mod);
> } else {
> ret = btrfs_add_delayed_data_ref(trans, root, bytenr,
> num_bytes, parent,
<snip>
> @@ -7102,11 +7110,8 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,
> old_ref_mod = new_ref_mod = 0;
> ret = 0;
> } else if (owner < BTRFS_FIRST_FREE_OBJECTID) {
> - ret = btrfs_add_delayed_tree_ref(trans, bytenr,
> - num_bytes, parent,
> - root_objectid, (int)owner,
> - for_reloc,
> - BTRFS_DROP_DELAYED_REF, NULL,
> + btrfs_init_tree_ref(&generic_ref, (int)owner, root_objectid);
ditto about the cast
> + ret = btrfs_add_delayed_tree_ref(trans, &generic_ref, NULL,
> &old_ref_mod, &new_ref_mod);
> } else {
> ret = btrfs_add_delayed_data_ref(trans, root, bytenr,
<sniop>
next prev parent reply other threads:[~2018-12-10 9:21 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-06 6:58 [PATCH 0/8] btrfs: Refactor delayed ref parameter list Qu Wenruo
2018-12-06 6:58 ` [PATCH 1/8] btrfs: delayed-ref: Introduce better documented delayed ref structures Qu Wenruo
2018-12-10 9:48 ` Nikolay Borisov
2018-12-10 11:20 ` Qu Wenruo
2018-12-10 11:32 ` Nikolay Borisov
2018-12-10 11:37 ` Qu Wenruo
2018-12-10 17:03 ` David Sterba
2018-12-12 5:09 ` About enum convert (Old "Re: [PATCH 1/8] btrfs: delayed-ref: Introduce better documented delayed ref structures") Qu Wenruo
2018-12-06 6:58 ` [PATCH 2/8] btrfs: extent-tree: Open-code process_func in __btrfs_mod_ref Qu Wenruo
2018-12-07 17:39 ` Nikolay Borisov
2018-12-06 6:58 ` [PATCH 3/8] btrfs: delayed-ref: Use btrfs_ref to refactor btrfs_add_delayed_tree_ref() Qu Wenruo
2018-12-10 9:21 ` Nikolay Borisov [this message]
2018-12-12 5:50 ` Qu Wenruo
2018-12-06 6:58 ` [PATCH 4/8] btrfs: delayed-ref: Use btrfs_ref to refactor btrfs_add_delayed_data_ref() Qu Wenruo
2018-12-10 9:23 ` Nikolay Borisov
2018-12-06 6:59 ` [PATCH 5/8] btrfs: ref-verify: Use btrfs_ref to refactor btrfs_ref_tree_mod() Qu Wenruo
2018-12-06 6:59 ` [PATCH 6/8] btrfs: extent-tree: Use btrfs_ref to refactor add_pinned_bytes() Qu Wenruo
2018-12-10 9:45 ` Nikolay Borisov
2018-12-06 6:59 ` [PATCH 7/8] btrfs: extent-tree: Use btrfs_ref to refactor btrfs_inc_extent_ref() Qu Wenruo
2018-12-10 9:52 ` Nikolay Borisov
2018-12-10 17:28 ` David Sterba
2018-12-11 2:02 ` Qu Wenruo
2018-12-06 6:59 ` [PATCH 8/8] btrfs: extent-tree: Use btrfs_ref to refactor btrfs_free_extent() Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=167bf109-41cf-f10b-4364-9af5701f5ee0@suse.com \
--to=nborisov@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).