linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v4 6/7] btrfs: qgroup: Use delayed subtree rescan for balance
Date: Tue, 22 Jan 2019 18:05:07 +0100	[thread overview]
Message-ID: <20190122170506.GP2900@twin.jikos.cz> (raw)
In-Reply-To: <20190115081604.785-7-wqu@suse.com>

On Tue, Jan 15, 2019 at 04:16:03PM +0800, Qu Wenruo wrote:
> +int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
> +					 struct btrfs_root *root,
> +					 struct extent_buffer *subv_eb)
> +{
> +	struct btrfs_fs_info *fs_info = root->fs_info;
> +	struct btrfs_qgroup_swapped_blocks *blocks = &root->swapped_blocks;
> +	struct btrfs_qgroup_swapped_block *block;
> +	struct extent_buffer *reloc_eb = NULL;
> +	struct rb_node *n;

Please don't use single letter variable here

> +	bool found = false;
> +	bool swapped = false;
> +	int level = btrfs_header_level(subv_eb);
> +	int ret = 0;
> +	int i;
> +
> +	if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags))
> +		return 0;
> +	if (!is_fstree(root->root_key.objectid) || !root->reloc_root)
> +		return 0;
> +
> +	spin_lock(&blocks->lock);
> +	if (!blocks->swapped) {
> +		spin_unlock(&blocks->lock);
> +		goto out;

I think you can return here directly, as this is a shortcut and there's
no state that would need to be cleaned up (ret is still 0).

> +	}
> +	n = blocks->blocks[level].rb_node;
> +
> +	while (n) {
> +		block = rb_entry(n, struct btrfs_qgroup_swapped_block, node);
> +		if (block->subv_bytenr < subv_eb->start)
> +			n = n->rb_left;
> +		else if (block->subv_bytenr > subv_eb->start)
> +			n = n->rb_right;
> +		else {
> +			found = true;
> +			break;
> +		}
> +	}
> +	if (!found) {
> +		spin_unlock(&blocks->lock);
> +		goto out;
> +	}
> +	/* Found one, remove it from @blocks first and update blocks->swapped */
> +	rb_erase(&block->node, &blocks->blocks[level]);
> +	for (i = 0; i < BTRFS_MAX_LEVEL; i++) {
> +		if (RB_EMPTY_ROOT(&blocks->blocks[i])) {
> +			swapped = true;
> +			break;
> +		}
> +	}
> +	blocks->swapped = swapped;
> +	spin_unlock(&blocks->lock);
> +
> +	/* Read out reloc subtree root */
> +	reloc_eb = read_tree_block(fs_info, block->reloc_bytenr,
> +				   block->reloc_generation, block->level,
> +				   &block->first_key);
> +	if (IS_ERR(reloc_eb)) {
> +		ret = PTR_ERR(subv_eb);
> +		reloc_eb = NULL;
> +		goto free_out;
> +	}
> +	if (!extent_buffer_uptodate(reloc_eb)) {
> +		ret = -EIO;
> +		goto free_out;
> +	}
> +
> +	ret = qgroup_trace_subtree_swap(trans, reloc_eb, subv_eb,
> +			block->last_snapshot, block->trace_leaf);
> +free_out:
> +	kfree(block);
> +	free_extent_buffer(reloc_eb);
> +out:
> +	if (ret < 0) {
> +		btrfs_err_rl(fs_info,
> +			     "failed to account subtree at bytenr %llu: %d",
> +			     subv_eb->start, ret);
> +		fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
> +	}
> +	return ret;
> +}

  reply	other threads:[~2019-01-22 17:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15  8:15 [PATCH v4 0/7] btrfs: qgroup: Delay subtree scan to reduce overhead Qu Wenruo
2019-01-15  8:15 ` [PATCH v4 1/7] btrfs: qgroup: Move reserved data account from btrfs_delayed_ref_head to btrfs_qgroup_extent_record Qu Wenruo
2019-01-15  8:15 ` [PATCH v4 2/7] btrfs: qgroup: Don't trigger backref walk at delayed ref insert time Qu Wenruo
2019-01-15  8:16 ` [PATCH v4 3/7] btrfs: relocation: Delay reloc tree deletion after merge_reloc_roots() Qu Wenruo
2019-01-22 16:32   ` David Sterba
2019-01-23  6:01     ` Qu Wenruo
2019-01-15  8:16 ` [PATCH v4 4/7] btrfs: qgroup: Refactor btrfs_qgroup_trace_subtree_swap() Qu Wenruo
2019-01-22 16:38   ` David Sterba
2019-01-15  8:16 ` [PATCH v4 5/7] btrfs: qgroup: Introduce per-root swapped blocks infrastructure Qu Wenruo
2019-01-22 16:55   ` David Sterba
2019-01-22 23:07     ` Qu Wenruo
2019-01-24 18:44       ` David Sterba
2019-01-15  8:16 ` [PATCH v4 6/7] btrfs: qgroup: Use delayed subtree rescan for balance Qu Wenruo
2019-01-22 17:05   ` David Sterba [this message]
2019-01-15  8:16 ` [PATCH v4 7/7] btrfs: qgroup: Cleanup old subtree swap code Qu Wenruo
2019-01-15 17:26 ` [PATCH v4 0/7] btrfs: qgroup: Delay subtree scan to reduce overhead Josef Bacik
2019-01-16  0:31   ` Qu Wenruo
2019-01-16  1:07     ` Qu Wenruo
2019-01-16  1:15       ` Josef Bacik
2019-01-16  1:29         ` Qu Wenruo
2019-01-16  1:34           ` Josef Bacik
2019-01-16  1:36             ` Qu Wenruo
2019-01-22 16:28 ` David Sterba
2019-01-23  5:43   ` 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=20190122170506.GP2900@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --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).