Linux-BTRFS Archive on lore.kernel.org
 help / color / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v3 8/9] btrfs: extent-tree: Use btrfs_ref to refactor btrfs_free_extent()
Date: Mon, 11 Feb 2019 15:05:53 +0200
Message-ID: <f8c23577-038f-c1c1-0c61-48f9b4e354af@suse.com> (raw)
In-Reply-To: <20190211051653.3167-9-wqu@suse.com>



On 11.02.19 г. 7:16 ч., Qu Wenruo wrote:
> Similar to btrfs_inc_extent_ref(), just use btrfs_ref to replace the
> long parameter list and the confusing @owner parameter.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

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


> ---
>  fs/btrfs/ctree.h       |  5 +---
>  fs/btrfs/extent-tree.c | 52 +++++++++++++++++++-----------------------
>  fs/btrfs/file.c        | 22 ++++++++++--------
>  fs/btrfs/inode.c       | 13 +++++++----
>  fs/btrfs/relocation.c  | 25 ++++++++++++--------
>  5 files changed, 61 insertions(+), 56 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index cd90f7cbc8f2..84a20abd0811 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -2744,10 +2744,7 @@ int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
>  				struct btrfs_fs_info *fs_info,
>  				u64 bytenr, u64 num_bytes, u64 flags,
>  				int level, int is_data);
> -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_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref);
>  
>  int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
>  			       u64 start, u64 len, int delalloc);
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index d08186ec6410..e2f34a8f5e91 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -3290,9 +3290,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
>  			if (inc)
>  				ret = btrfs_inc_extent_ref(trans, &generic_ref);
>  			else
> -				ret = btrfs_free_extent(trans, root, bytenr,
> -						num_bytes, parent, ref_root,
> -						key.objectid, key.offset);
> +				ret = btrfs_free_extent(trans, &generic_ref);
>  			if (ret)
>  				goto fail;
>  		} else {
> @@ -3306,9 +3304,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
>  			if (inc)
>  				ret = btrfs_inc_extent_ref(trans, &generic_ref);
>  			else
> -				ret = btrfs_free_extent(trans, root, bytenr,
> -						num_bytes, parent, ref_root,
> -						level - 1, 0);
> +				ret = btrfs_free_extent(trans, &generic_ref);
>  			if (ret)
>  				goto fail;
>  		}
> @@ -7340,47 +7336,43 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
>  }
>  
>  /* Can return -ENOMEM */
> -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_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref)
>  {
> -	struct btrfs_fs_info *fs_info = root->fs_info;
> -	struct btrfs_ref generic_ref = { 0 };
> +	struct btrfs_fs_info *fs_info = trans->fs_info;
>  	int old_ref_mod, new_ref_mod;
>  	int ret;
>  
>  	if (btrfs_is_testing(fs_info))
>  		return 0;
>  
> -	btrfs_init_generic_ref(&generic_ref, BTRFS_DROP_DELAYED_REF, bytenr,
> -			       num_bytes, parent);
> -	generic_ref.real_root = root->root_key.objectid;
>  	/*
>  	 * tree log blocks never actually go into the extent allocation
>  	 * tree, just update pinning info and exit early.
>  	 */
> -	if (root_objectid == BTRFS_TREE_LOG_OBJECTID) {
> -		WARN_ON(owner >= BTRFS_FIRST_FREE_OBJECTID);
> +	if ((ref->type == BTRFS_REF_METADATA &&
> +	     ref->tree_ref.root == BTRFS_TREE_LOG_OBJECTID) ||
> +	    (ref->type == BTRFS_REF_DATA &&
> +	     ref->data_ref.ref_root == BTRFS_TREE_LOG_OBJECTID)) {
>  		/* unlocks the pinned mutex */
> -		btrfs_pin_extent(fs_info, bytenr, num_bytes, 1);
> +		btrfs_pin_extent(fs_info, ref->bytenr, ref->len, 1);
>  		old_ref_mod = new_ref_mod = 0;
>  		ret = 0;
> -	} else if (owner < BTRFS_FIRST_FREE_OBJECTID) {
> -		btrfs_init_tree_ref(&generic_ref, (int)owner, root_objectid);
> -		ret = btrfs_add_delayed_tree_ref(trans, &generic_ref, NULL,
> +	} else if (ref->type == BTRFS_REF_METADATA) {
> +		ret = btrfs_add_delayed_tree_ref(trans, ref, NULL,
>  						 &old_ref_mod, &new_ref_mod);
>  	} else {
> -		btrfs_init_data_ref(&generic_ref, root_objectid, owner, offset);
> -		ret = btrfs_add_delayed_data_ref(trans, &generic_ref, 0,
> +		ret = btrfs_add_delayed_data_ref(trans, ref, 0,
>  						 &old_ref_mod, &new_ref_mod);
>  	}
>  
> -	if (root_objectid != BTRFS_TREE_LOG_OBJECTID)
> -		btrfs_ref_tree_mod(fs_info, &generic_ref);
> +	if (!((ref->type == BTRFS_REF_METADATA &&
> +	       ref->tree_ref.root == BTRFS_TREE_LOG_OBJECTID) ||
> +	      (ref->type == BTRFS_REF_DATA &&
> +	       ref->data_ref.ref_root == BTRFS_TREE_LOG_OBJECTID)))
> +		btrfs_ref_tree_mod(fs_info, ref);
>  
>  	if (ret == 0 && old_ref_mod >= 0 && new_ref_mod < 0)
> -		add_pinned_bytes(fs_info, &generic_ref);
> +		add_pinned_bytes(fs_info, ref);
>  
>  	return ret;
>  }
> @@ -8957,6 +8949,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
>  	u64 parent;
>  	struct btrfs_key key;
>  	struct btrfs_key first_key;
> +	struct btrfs_ref ref = { 0 };
>  	struct extent_buffer *next;
>  	int level = wc->level;
>  	int reada = 0;
> @@ -9102,9 +9095,10 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
>  					     ret);
>  			}
>  		}
> -		ret = btrfs_free_extent(trans, root, bytenr, fs_info->nodesize,
> -					parent, root->root_key.objectid,
> -					level - 1, 0);
> +		btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, bytenr,
> +				       fs_info->nodesize, parent);
> +		btrfs_init_tree_ref(&ref, level - 1, root->root_key.objectid);
> +		ret = btrfs_free_extent(trans, &ref);
>  		if (ret)
>  			goto out_unlock;
>  	}
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 2aba5980f522..f032f123be53 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -997,11 +997,14 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
>  				extent_end = ALIGN(extent_end,
>  						   fs_info->sectorsize);
>  			} else if (update_refs && disk_bytenr > 0) {
> -				ret = btrfs_free_extent(trans, root,
> -						disk_bytenr, num_bytes, 0,
> +				btrfs_init_generic_ref(&ref,
> +						BTRFS_DROP_DELAYED_REF,
> +						disk_bytenr, num_bytes, 0);
> +				btrfs_init_data_ref(&ref,
>  						root->root_key.objectid,
> -						key.objectid, key.offset -
> -						extent_offset);
> +						key.objectid,
> +						key.offset - extent_offset);
> +				ret = btrfs_free_extent(trans, &ref);
>  				BUG_ON(ret); /* -ENOMEM */
>  				inode_sub_bytes(inode,
>  						extent_end - key.offset);
> @@ -1318,6 +1321,9 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
>  
>  	other_start = end;
>  	other_end = 0;
> +	btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, bytenr,
> +			       num_bytes, 0);
> +	btrfs_init_data_ref(&ref, root->root_key.objectid, ino, orig_offset);
>  	if (extent_mergeable(leaf, path->slots[0] + 1,
>  			     ino, bytenr, orig_offset,
>  			     &other_start, &other_end)) {
> @@ -1328,9 +1334,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
>  		extent_end = other_end;
>  		del_slot = path->slots[0] + 1;
>  		del_nr++;
> -		ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
> -					0, root->root_key.objectid,
> -					ino, orig_offset);
> +		ret = btrfs_free_extent(trans, &ref);
>  		if (ret) {
>  			btrfs_abort_transaction(trans, ret);
>  			goto out;
> @@ -1348,9 +1352,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
>  		key.offset = other_start;
>  		del_slot = path->slots[0];
>  		del_nr++;
> -		ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
> -					0, root->root_key.objectid,
> -					ino, orig_offset);
> +		ret = btrfs_free_extent(trans, &ref);
>  		if (ret) {
>  			btrfs_abort_transaction(trans, ret);
>  			goto out;
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 95535ba375f8..bc01584791fd 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -4720,12 +4720,17 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
>  		if (found_extent &&
>  		    (test_bit(BTRFS_ROOT_REF_COWS, &root->state) ||
>  		     root == fs_info->tree_root)) {
> +			struct btrfs_ref ref = { 0 };
> +
>  			btrfs_set_path_blocking(path);
>  			bytes_deleted += extent_num_bytes;
> -			ret = btrfs_free_extent(trans, root, extent_start,
> -						extent_num_bytes, 0,
> -						btrfs_header_owner(leaf),
> -						ino, extent_offset);
> +
> +			btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF,
> +					extent_start, extent_num_bytes, 0);
> +			ref.real_root = root->root_key.objectid;
> +			btrfs_init_data_ref(&ref, btrfs_header_owner(leaf),
> +					ino, extent_offset);
> +			ret = btrfs_free_extent(trans, &ref);
>  			if (ret) {
>  				btrfs_abort_transaction(trans, ret);
>  				break;
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index b82d532d8e5e..3b93a4585b70 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -1716,9 +1716,12 @@ int replace_file_extents(struct btrfs_trans_handle *trans,
>  			break;
>  		}
>  
> -		ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
> -					parent, btrfs_header_owner(leaf),
> -					key.objectid, key.offset);
> +		btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, bytenr,
> +				       num_bytes, parent);
> +		ref.real_root = root->root_key.objectid;
> +		btrfs_init_data_ref(&ref, btrfs_header_owner(leaf),
> +				    key.objectid, key.offset);
> +		ret = btrfs_free_extent(trans, &ref);
>  		if (ret) {
>  			btrfs_abort_transaction(trans, ret);
>  			break;
> @@ -1932,14 +1935,18 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
>  		ret = btrfs_inc_extent_ref(trans, &ref);
>  		BUG_ON(ret);
>  
> -		ret = btrfs_free_extent(trans, src, new_bytenr, blocksize,
> -					path->nodes[level]->start,
> -					src->root_key.objectid, level - 1, 0);
> +		btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, new_bytenr,
> +				       blocksize, path->nodes[level]->start);
> +		btrfs_init_tree_ref(&ref, level - 1, src->root_key.objectid);
> +		ref.skip_qgroup = true;
> +		ret = btrfs_free_extent(trans, &ref);
>  		BUG_ON(ret);
>  
> -		ret = btrfs_free_extent(trans, dest, old_bytenr, blocksize,
> -					0, dest->root_key.objectid, level - 1,
> -					0);
> +		btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, old_bytenr,
> +				       blocksize, 0);
> +		btrfs_init_tree_ref(&ref, level - 1, dest->root_key.objectid);
> +		ref.skip_qgroup = true;
> +		ret = btrfs_free_extent(trans, &ref);
>  		BUG_ON(ret);
>  
>  		btrfs_unlock_up_safe(path, 0);
> 

  reply index

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-11  5:16 [PATCH v3 0/9] btrfs: Refactor delayed ref parameter list Qu Wenruo
2019-02-11  5:16 ` [PATCH v3 1/9] btrfs: delayed-ref: Introduce better documented delayed ref structures Qu Wenruo
2019-02-11 12:55   ` Nikolay Borisov
2019-02-11 13:23     ` Qu Wenruo
2019-02-11 14:20       ` Nikolay Borisov
2019-02-11 14:23         ` Qu Wenruo
2019-02-18  5:00           ` Qu Wenruo
2019-02-18  6:59             ` Su Yue
2019-02-11  5:16 ` [PATCH v3 2/9] btrfs: extent-tree: Open-code process_func in __btrfs_mod_ref Qu Wenruo
2019-02-11  5:16 ` [PATCH v3 3/9] btrfs: delayed-ref: Use btrfs_ref to refactor btrfs_add_delayed_tree_ref() Qu Wenruo
2019-02-11 12:58   ` Nikolay Borisov
2019-02-11  5:16 ` [PATCH v3 4/9] btrfs: delayed-ref: Use btrfs_ref to refactor btrfs_add_delayed_data_ref() Qu Wenruo
2019-02-11 12:59   ` Nikolay Borisov
2019-02-11  5:16 ` [PATCH v3 5/9] btrfs: ref-verify: Use btrfs_ref to refactor btrfs_ref_tree_mod() Qu Wenruo
2019-02-11 13:00   ` Nikolay Borisov
2019-02-11  5:16 ` [PATCH v3 6/9] btrfs: extent-tree: Use btrfs_ref to refactor add_pinned_bytes() Qu Wenruo
2019-02-11  5:16 ` [PATCH v3 7/9] btrfs: extent-tree: Use btrfs_ref to refactor btrfs_inc_extent_ref() Qu Wenruo
2019-02-11 13:04   ` Nikolay Borisov
2019-02-11  5:16 ` [PATCH v3 8/9] btrfs: extent-tree: Use btrfs_ref to refactor btrfs_free_extent() Qu Wenruo
2019-02-11 13:05   ` Nikolay Borisov [this message]
2019-02-11  5:16 ` [PATCH v3 9/9] btrfs: qgroup: Don't scan leaf if we're modifying reloc tree Qu Wenruo
2019-04-03 16:29 ` [PATCH v3 0/9] btrfs: Refactor delayed ref parameter list David Sterba
2019-04-04  1:12   ` Qu Wenruo
2019-04-04  6:44   ` Qu Wenruo

Reply instructions:

You may reply publically 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=f8c23577-038f-c1c1-0c61-48f9b4e354af@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

Linux-BTRFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-btrfs/0 linux-btrfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-btrfs linux-btrfs/ https://lore.kernel.org/linux-btrfs \
		linux-btrfs@vger.kernel.org linux-btrfs@archiver.kernel.org
	public-inbox-index linux-btrfs


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-btrfs


AGPL code for this site: git clone https://public-inbox.org/ public-inbox