All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 12/18] btrfs: qgroup: Switch rescan to new mechanism.
Date: Tue, 21 Apr 2015 14:21:28 +0800	[thread overview]
Message-ID: <1429597294-11875-13-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1429597294-11875-1-git-send-email-quwenruo@cn.fujitsu.com>

Switch rescan to use the new new extent oriented mechanism.

As rescan is also based on extent, new mechanism is just a perfect match
for rescan.

With re-designed internal functions, rescan is quite easy, just call
btrfs_find_all_roots() and then btrfs_qgroup_account_one_extent().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 fs/btrfs/qgroup.c | 43 +++++++------------------------------------
 1 file changed, 7 insertions(+), 36 deletions(-)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index be5717f..579f94a 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -2877,15 +2877,13 @@ void assert_qgroups_uptodate(struct btrfs_trans_handle *trans)
  */
 static int
 qgroup_rescan_leaf(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
-		   struct btrfs_trans_handle *trans, struct ulist *qgroups,
-		   struct ulist *tmp, struct extent_buffer *scratch_leaf)
+		   struct btrfs_trans_handle *trans,
+		   struct extent_buffer *scratch_leaf)
 {
 	struct btrfs_key found;
 	struct ulist *roots = NULL;
 	struct seq_list tree_mod_seq_elem = {};
 	u64 num_bytes;
-	u64 seq;
-	int new_roots;
 	int slot;
 	int ret;
 
@@ -2935,33 +2933,15 @@ qgroup_rescan_leaf(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
 		else
 			num_bytes = found.offset;
 
-		ulist_reinit(qgroups);
 		ret = btrfs_find_all_roots(NULL, fs_info, found.objectid, 0,
 					   &roots);
 		if (ret < 0)
 			goto out;
-		spin_lock(&fs_info->qgroup_lock);
-		seq = fs_info->qgroup_seq;
-		fs_info->qgroup_seq += roots->nnodes + 1; /* max refcnt */
-
-		new_roots = 0;
-		ret = qgroup_calc_old_refcnt(fs_info, 0, tmp, roots, qgroups,
-					     seq, &new_roots, 1);
-		if (ret < 0) {
-			spin_unlock(&fs_info->qgroup_lock);
-			ulist_free(roots);
-			goto out;
-		}
-
-		ret = qgroup_adjust_counters(fs_info, 0, num_bytes, qgroups,
-					     seq, 0, new_roots, 1);
-		if (ret < 0) {
-			spin_unlock(&fs_info->qgroup_lock);
-			ulist_free(roots);
+		/* For rescan, just pass old_roots as NULL */
+		ret = btrfs_qgroup_account_extent(trans, fs_info,
+				found.objectid, num_bytes, NULL, roots);
+		if (ret < 0)
 			goto out;
-		}
-		spin_unlock(&fs_info->qgroup_lock);
-		ulist_free(roots);
 	}
 out:
 	btrfs_put_tree_mod_seq(fs_info, &tree_mod_seq_elem);
@@ -2975,19 +2955,12 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
 						     qgroup_rescan_work);
 	struct btrfs_path *path;
 	struct btrfs_trans_handle *trans = NULL;
-	struct ulist *tmp = NULL, *qgroups = NULL;
 	struct extent_buffer *scratch_leaf = NULL;
 	int err = -ENOMEM;
 
 	path = btrfs_alloc_path();
 	if (!path)
 		goto out;
-	qgroups = ulist_alloc(GFP_NOFS);
-	if (!qgroups)
-		goto out;
-	tmp = ulist_alloc(GFP_NOFS);
-	if (!tmp)
-		goto out;
 	scratch_leaf = kmalloc(sizeof(*scratch_leaf), GFP_NOFS);
 	if (!scratch_leaf)
 		goto out;
@@ -3003,7 +2976,7 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
 			err = -EINTR;
 		} else {
 			err = qgroup_rescan_leaf(fs_info, path, trans,
-						 qgroups, tmp, scratch_leaf);
+						 scratch_leaf);
 		}
 		if (err > 0)
 			btrfs_commit_transaction(trans, fs_info->fs_root);
@@ -3013,8 +2986,6 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
 
 out:
 	kfree(scratch_leaf);
-	ulist_free(qgroups);
-	ulist_free(tmp);
 	btrfs_free_path(path);
 
 	mutex_lock(&fs_info->qgroup_rescan_lock);
-- 
2.3.5


  parent reply	other threads:[~2015-04-21  6:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-21  6:21 [PATCH 00/18] New extent-oriented qgroup mechanism with minor cleanup Qu Wenruo
2015-04-21  6:21 ` [PATCH 01/18] btrfs: backref: Don't merge refs which are not for same block Qu Wenruo
2015-04-21  6:21 ` [PATCH 02/18] btrfs: delayed-ref: Use list to replace the ref_root in ref_head Qu Wenruo
2015-04-21  6:21 ` [PATCH 03/18] btrfs: delayed-ref: Cleanup the unneeded functions Qu Wenruo
2015-04-21  6:21 ` [PATCH 04/18] btrfs: qgroup: Cleanup open-coded old/new_refcnt update and read Qu Wenruo
2015-04-21  6:21 ` [PATCH 05/18] btrfs: extent-tree: Use ref_node to replace unneeded parameters in __inc_extent_ref() and __free_extent() Qu Wenruo
2015-04-21  6:21 ` [PATCH 06/18] btrfs: qgroup: Add function qgroup_update_refcnt() Qu Wenruo
2015-04-21  6:21 ` [PATCH 07/18] btrfs: qgroup: Add function qgroup_update_counters() Qu Wenruo
2015-04-21  6:21 ` [PATCH 08/18] btrfs: qgroup: Record possible quota-related extent for qgroup Qu Wenruo
2015-04-21  6:21 ` [PATCH 09/18] btrfs: qgroup: Add new function to record old_roots Qu Wenruo
2015-04-21  6:21 ` [PATCH 10/18] btrfs: backref: Add special time_seq == (u64)-1 case for btrfs_find_all_roots() Qu Wenruo
2015-04-21  6:21 ` [PATCH 11/18] btrfs: qgroup: Add new qgroup calculation function btrfs_qgroup_account_extents() Qu Wenruo
2015-04-21  6:21 ` Qu Wenruo [this message]
2015-04-21  6:21 ` [PATCH 13/18] btrfs: qgroup: Switch to new extent-oriented qgroup mechanism Qu Wenruo
2015-04-21  6:21 ` [PATCH 14/18] btrfs: qgroup: Switch self test to " Qu Wenruo
2015-04-21  6:21 ` [PATCH 15/18] btrfs: qgroup: Cleanup the old ref_node-oriented mechanism Qu Wenruo
2015-04-21  6:21 ` [PATCH 16/18] btrfs: ulist: Add ulist_del() function Qu Wenruo
2015-04-21  6:21 ` [PATCH 17/18] btrfs: qgroup: Add the ability to skip given qgroup for old/new_roots Qu Wenruo
2015-04-21  6:21 ` [PATCH 18/18] btrfs: qgroup: Make snapshot accounting work with new extent-oriented qgroup Qu Wenruo
     [not found] ` <CAP9B-QkT5dY7GkMgiumq6HCszB0aSjcjYidcYFFzSvCFcCEU3A@mail.gmail.com>
2015-04-29  1:55   ` [PATCH 00/18] New extent-oriented qgroup mechanism with minor cleanup 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=1429597294-11875-13-git-send-email-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.