From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/6] btrfs: relocation: Commit transaction before dropping btrfs_root::reloc_root
Date: Thu, 18 Oct 2018 19:17:25 +0800	[thread overview]
Message-ID: <20181018111729.11128-3-wqu@suse.com> (raw)
In-Reply-To: <20181018111729.11128-1-wqu@suse.com>
Currently only relocation code cares about btrfs_root::reloc_root, and
they have the method to sync btrfs_root::reloc_root without screwing
things up.
However qgroup code doesn't really have the ability to keep
btrfs_root::reloc_root reliable.
Currently if someone outside of relocation code want to access
btrfs_root::reloc_root, it's highly possible some race could make
@reloc_root unreliable.
Thankfully, we only need to make qgroup code access
btrfs_root::reloc_root, and due to the nature of qgroup, it only needs
it before committing a transaction.
So alter the timming of transaction commit for merge_reloc_root(). For
every successful root merge, commit transaction before dropping
btrfs_root::reloc_root, making qgroup code happy with it.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/relocation.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 44efde9886fc..a8b62323f60b 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2251,6 +2251,17 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
 	btrfs_free_path(path);
 
 	if (err == 0) {
+		/*
+		 * Commit current trans before we reset root->reloc_root
+		 * pointer, since qgroup code still needs root->reloc_root
+		 * to trace post-swap CoWs until we commit transaction.
+		 */
+		err = btrfs_commit_transaction(trans);
+		if (err < 0)
+			return err;
+		trans = btrfs_start_transaction(root, 0);
+		if (IS_ERR(trans))
+			return PTR_ERR(trans);
 		memset(&root_item->drop_progress, 0,
 		       sizeof(root_item->drop_progress));
 		root_item->drop_level = 0;
-- 
2.19.1
next prev parent reply	other threads:[~2018-10-18 11:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-18 11:17 [PATCH 0/6] btrfs: qgroup: Delay subtree scan to reduce overhead Qu Wenruo
2018-10-18 11:17 ` [PATCH 1/6] btrfs: qgroup: Allow btrfs_qgroup_extent_record::old_roots unpopulated at insert time Qu Wenruo
2018-10-18 11:17 ` Qu Wenruo [this message]
2018-10-18 11:17 ` [PATCH 3/6] btrfs: qgroup: Refactor btrfs_qgroup_trace_subtree_swap() Qu Wenruo
2018-10-18 11:17 ` [PATCH 4/6] btrfs: qgroup: Introduce per-root swapped blocks infrastructure Qu Wenruo
2018-10-18 16:20   ` David Sterba
2018-10-18 23:29     ` Qu Wenruo
2018-10-19  9:15       ` David Sterba
2018-10-19  9:46         ` Qu Wenruo
2018-10-19 10:04           ` David Sterba
2018-10-19 13:03             ` Qu Wenruo
2018-10-18 11:17 ` [PATCH 5/6] btrfs: qgroup: Use delayed subtree rescan for balance Qu Wenruo
2018-10-19 13:12   ` David Sterba
2018-10-19 13:19     ` David Sterba
2018-10-18 11:17 ` [PATCH 6/6] btrfs: qgroup: Cleanup old subtree swap code Qu Wenruo
2018-10-19 13:42 ` [PATCH 0/6] btrfs: qgroup: Delay subtree scan to reduce overhead David Sterba
2018-10-19 13:47   ` Qu Wenruo
2018-10-19 14:51   ` Qu Wenruo
2018-10-19 14:54     ` David Sterba
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=20181018111729.11128-3-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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).