From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH v2 RESEND 01/11] btrfs: qgroup: Cleanup open-coded old/new_refcnt update and read.
Date: Mon, 23 Mar 2015 16:08:27 +0800 [thread overview]
Message-ID: <1427098117-25152-2-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1427098117-25152-1-git-send-email-quwenruo@cn.fujitsu.com>
Use inline functions to do such things, to improve readability.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Acked-by: David Sterba <dsterba@suse.cz>
---
v2:
Change nameing to btrfs_qgroup_(update|get)_(old|new)_refcnt.
Not use centeral qgroup_(get|update)_refcnt function, direct code into
corresponding functions.
Fix a forgot-to-replace bug.
---
fs/btrfs/qgroup.c | 95 +++++++++++++++++++++++++++++++------------------------
1 file changed, 54 insertions(+), 41 deletions(-)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 97159a8..6e7735d 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -84,11 +84,42 @@ struct btrfs_qgroup {
/*
* temp variables for accounting operations
+ * Refer to qgroup_shared_accouting() for details.
*/
u64 old_refcnt;
u64 new_refcnt;
};
+static void btrfs_qgroup_update_old_refcnt(struct btrfs_qgroup *qg, u64 seq,
+ int mod)
+{
+ if (qg->old_refcnt < seq)
+ qg->old_refcnt = seq;
+ qg->old_refcnt += mod;
+}
+
+static void btrfs_qgroup_update_new_refcnt(struct btrfs_qgroup *qg, u64 seq,
+ int mod)
+{
+ if (qg->new_refcnt < seq)
+ qg->new_refcnt = seq;
+ qg->new_refcnt += mod;
+}
+
+static inline u64 btrfs_qgroup_get_old_refcnt(struct btrfs_qgroup *qg, u64 seq)
+{
+ if (qg->old_refcnt < seq)
+ return 0;
+ return qg->old_refcnt - seq;
+}
+
+static inline u64 btrfs_qgroup_get_new_refcnt(struct btrfs_qgroup *qg, u64 seq)
+{
+ if (qg->new_refcnt < seq)
+ return 0;
+ return qg->new_refcnt - seq;
+}
+
/*
* glue structure to represent the relations between qgroups.
*/
@@ -1497,6 +1528,7 @@ static int qgroup_calc_old_refcnt(struct btrfs_fs_info *fs_info,
ULIST_ITER_INIT(&tmp_uiter);
while ((tmp_unode = ulist_next(tmp, &tmp_uiter))) {
struct btrfs_qgroup_list *glist;
+ int mod;
qg = u64_to_ptr(tmp_unode->aux);
/*
@@ -1508,20 +1540,15 @@ static int qgroup_calc_old_refcnt(struct btrfs_fs_info *fs_info,
* upper level qgroups in order to determine exclusive
* counts.
*
- * For rescan we want to set old_refcnt to seq so our
- * exclusive calculations end up correct.
+ * For rescan none of the extent is recorded before so
+ * we just don't add old_refcnt.
*/
if (rescan)
- qg->old_refcnt = seq;
- else if (qg->old_refcnt < seq)
- qg->old_refcnt = seq + 1;
- else
- qg->old_refcnt++;
-
- if (qg->new_refcnt < seq)
- qg->new_refcnt = seq + 1;
+ mod = 0;
else
- qg->new_refcnt++;
+ mod = 1;
+ btrfs_qgroup_update_old_refcnt(qg, seq, mod);
+ btrfs_qgroup_update_new_refcnt(qg, seq, 1);
list_for_each_entry(glist, &qg->groups, next_group) {
ret = ulist_add(qgroups, glist->group->qgroupid,
ptr_to_u64(glist->group),
@@ -1615,14 +1642,8 @@ next:
struct btrfs_qgroup_list *glist;
qg = u64_to_ptr(unode->aux);
- if (qg->old_refcnt < seq)
- qg->old_refcnt = seq + 1;
- else
- qg->old_refcnt++;
- if (qg->new_refcnt < seq)
- qg->new_refcnt = seq + 1;
- else
- qg->new_refcnt++;
+ btrfs_qgroup_update_old_refcnt(qg, seq, 1);
+ btrfs_qgroup_update_new_refcnt(qg, seq, 1);
list_for_each_entry(glist, &qg->groups, next_group) {
ret = ulist_add(qgroups, glist->group->qgroupid,
ptr_to_u64(glist->group), GFP_ATOMIC);
@@ -1663,17 +1684,10 @@ static int qgroup_calc_new_refcnt(struct btrfs_fs_info *fs_info,
struct btrfs_qgroup_list *glist;
qg = u64_to_ptr(unode->aux);
- if (oper->type == BTRFS_QGROUP_OPER_ADD_SHARED) {
- if (qg->new_refcnt < seq)
- qg->new_refcnt = seq + 1;
- else
- qg->new_refcnt++;
- } else {
- if (qg->old_refcnt < seq)
- qg->old_refcnt = seq + 1;
- else
- qg->old_refcnt++;
- }
+ if (oper->type == BTRFS_QGROUP_OPER_ADD_SHARED)
+ btrfs_qgroup_update_new_refcnt(qg, seq, 1);
+ else
+ btrfs_qgroup_update_old_refcnt(qg, seq, 1);
list_for_each_entry(glist, &qg->groups, next_group) {
ret = ulist_add(tmp, glist->group->qgroupid,
ptr_to_u64(glist->group), GFP_ATOMIC);
@@ -1706,11 +1720,14 @@ static int qgroup_adjust_counters(struct btrfs_fs_info *fs_info,
bool dirty = false;
qg = u64_to_ptr(unode->aux);
+ cur_old_count = btrfs_qgroup_get_old_refcnt(qg, seq);
+ cur_new_count = btrfs_qgroup_get_new_refcnt(qg, seq);
+
/*
* Wasn't referenced before but is now, add to the reference
* counters.
*/
- if (qg->old_refcnt <= seq && qg->new_refcnt > seq) {
+ if (cur_old_count == 0 && cur_new_count > 0) {
qg->rfer += num_bytes;
qg->rfer_cmpr += num_bytes;
dirty = true;
@@ -1720,21 +1737,12 @@ static int qgroup_adjust_counters(struct btrfs_fs_info *fs_info,
* Was referenced before but isn't now, subtract from the
* reference counters.
*/
- if (qg->old_refcnt > seq && qg->new_refcnt <= seq) {
+ if (cur_old_count > 0 && cur_new_count == 0) {
qg->rfer -= num_bytes;
qg->rfer_cmpr -= num_bytes;
dirty = true;
}
- if (qg->old_refcnt < seq)
- cur_old_count = 0;
- else
- cur_old_count = qg->old_refcnt - seq;
- if (qg->new_refcnt < seq)
- cur_new_count = 0;
- else
- cur_new_count = qg->new_refcnt - seq;
-
/*
* If our refcount was the same as the roots previously but our
* new count isn't the same as the number of roots now then we
@@ -1932,6 +1940,11 @@ static int qgroup_shared_accounting(struct btrfs_trans_handle *trans,
new_roots = old_roots;
old_roots++;
}
+
+ /*
+ * Bump qgroup_seq to avoid seq overlap
+ * XXX: This makes qgroup_seq mismatch with oper->seq.
+ */
fs_info->qgroup_seq += old_roots + 1;
--
2.3.3
next prev parent reply other threads:[~2015-03-23 8:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-23 8:08 [RFC PATCH 00/11] Qgroup: new record/write/record infrastructure to record correct old/new_roots Qu Wenruo
2015-03-23 8:08 ` Qu Wenruo [this message]
2015-03-23 8:08 ` [RFC PATCH 02/11] btrfs: extent-tree: Use ref_node to replace unneeded parameters in __inc_extent_ref() and __free_extent() Qu Wenruo
2015-03-23 8:08 ` [RFC PATCH 03/11] btrfs: backref: Add nolock option for btrfs_find_all_roots() Qu Wenruo
2015-03-23 8:08 ` [RFC PATCH 04/11] btrfs: backref: Allow find_parent_nodes() to skip given ref_node Qu Wenruo
2015-03-23 8:08 ` [RFC PATCH 05/11] btrfs: backref: Allow btrfs_find_all_roots() " Qu Wenruo
2015-03-23 8:08 ` [RFC PATCH 06/11] btrfs: qgroup: Add needed parameter and member for qgroup Qu Wenruo
2015-03-23 8:08 ` [RFC PATCH 07/11] btrfs: qgroup: save and pass old_roots ulist to btrfs_qgroup_record_ref() Qu Wenruo
2015-03-23 8:08 ` [RFC PATCH 08/11] btrfs: qgroup: Record current referenced roots at qgroup_record_ref() Qu Wenruo
2015-03-23 8:08 ` [RFC PATCH 09/11] btrfs: qgroup: Use oper->old/new_roots to update refcnt Qu Wenruo
2015-03-23 8:08 ` [RFC PATCH 10/11] btrfs: qgroup-tests: Add old_roots ulist to allow qgroup test pass Qu Wenruo
2015-03-23 8:08 ` [RFC PATCH 11/11] btrfs: qgroup: Cleanup the unneeded codes 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=1427098117-25152-2-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 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).