From: Marcos Paulo de Souza <marcos@mpdesouza.com>
To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org
Cc: Marcos Paulo de Souza <mpdesouza@suse.com>
Subject: [PATCH v4 04/11] btrfs-progs: qgroup-verify: Move qgroup classification out of report_qgroups
Date: Wed, 18 Mar 2020 17:21:41 -0300 [thread overview]
Message-ID: <20200318202148.14828-5-marcos@mpdesouza.com> (raw)
In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com>
From: Qu Wenruo <wqu@suse.com>
The original qgroup-verify integrates qgroup classification into
report_qgroups().
This behavior makes silent qgroup repair (or offline rescan) impossible.
To repair qgroup, we must call report_qgroups() to trigger bad qgroup
classification, which will output error message.
This patch moves bad qgroup classification from report_qgroups() to
qgroup_verify_all().
Now report_qgroups() is pretty lightweight, only doing basic qgroup
difference report thus change it type to void.
And since the functionality of qgroup_verify_all() changes, change
callers to handle the new return value correctly.
Signed-off-by: Qu Wenruo <wqu@suse.com>
[ removed some comments ]
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
check/main.c | 18 ++++++------
check/qgroup-verify.c | 67 +++++++++++++++++++++++++++++++------------
check/qgroup-verify.h | 2 +-
3 files changed, 59 insertions(+), 28 deletions(-)
diff --git a/check/main.c b/check/main.c
index 49bdbfec..7632b60a 100644
--- a/check/main.c
+++ b/check/main.c
@@ -9941,7 +9941,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
int clear_space_cache = 0;
int qgroup_report = 0;
int qgroups_repaired = 0;
- int qgroup_report_ret;
+ int qgroup_verify_ret;
unsigned ctree_flags = OPEN_CTREE_EXCLUSIVE;
int force = 0;
@@ -10198,8 +10198,8 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
uuidbuf);
ret = qgroup_verify_all(info);
err |= !!ret;
- if (ret == 0)
- err |= !!report_qgroups(1);
+ if (ret >= 0)
+ report_qgroups(1);
goto close_out;
}
if (subvolid) {
@@ -10433,21 +10433,21 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
ctx.tp = TASK_QGROUPS;
task_start(ctx.info, &ctx.start_time, &ctx.item_count);
}
- ret = qgroup_verify_all(info);
+ qgroup_verify_ret = qgroup_verify_all(info);
task_stop(ctx.info);
- err |= !!ret;
- if (ret) {
+ if (qgroup_verify_ret < 0) {
error("failed to check quota groups");
+ err |= !!qgroup_verify_ret;
goto out;
}
- qgroup_report_ret = report_qgroups(0);
+ report_qgroups(0);
ret = repair_qgroups(info, &qgroups_repaired);
if (ret) {
error("failed to repair quota groups");
goto out;
}
- if (qgroup_report_ret && (!qgroups_repaired || ret))
- err |= qgroup_report_ret;
+ if (qgroup_verify_ret && (!qgroups_repaired || ret))
+ err |= !!qgroup_verify_ret;
ret = 0;
} else {
fprintf(stderr,
diff --git a/check/qgroup-verify.c b/check/qgroup-verify.c
index b7b63095..b1e6b26c 100644
--- a/check/qgroup-verify.c
+++ b/check/qgroup-verify.c
@@ -1311,18 +1311,13 @@ static int report_qgroup_difference(struct qgroup_count *count, int verbose)
/*
* Report qgroups errors
- * Return 0 if nothing wrong.
- * Return <0 if any qgroup is inconsistent.
- *
* @all: if set, all qgroup will be checked and reported even already
* inconsistent or under rescan.
*/
-int report_qgroups(int all)
+void report_qgroups(int all)
{
struct rb_node *node;
struct qgroup_count *c;
- bool found_err = false;
- bool skip_err = false;
if (!repair && counts.rescan_running) {
if (all) {
@@ -1331,34 +1326,26 @@ int report_qgroups(int all)
} else {
printf(
"Qgroup rescan is running, qgroups will not be printed.\n");
- return 0;
+ return;
}
}
/*
* It's possible that rescan hasn't been initialized yet.
*/
if (counts.qgroup_inconsist && !counts.rescan_running &&
- counts.rescan_running == 0) {
+ counts.rescan_running == 0)
printf(
-"Rescan hasn't been initialized, a difference in qgroup accounting is expected\n");
- skip_err = true;
- }
+"Rescan hasn't been initialzied, a difference in qgroup accounting is expected\n");
if (counts.qgroup_inconsist && !counts.rescan_running)
fprintf(stderr, "Qgroup are marked as inconsistent.\n");
node = rb_first(&counts.root);
while (node) {
c = rb_entry(node, struct qgroup_count, rb_node);
- if (report_qgroup_difference(c, all)) {
- list_add_tail(&c->bad_list, &bad_qgroups);
- found_err = true;
- }
+ report_qgroup_difference(c, all);
node = rb_next(node);
}
- if (found_err && !skip_err)
- return -EUCLEAN;
- return 0;
}
void free_qgroup_counts(void)
@@ -1393,9 +1380,29 @@ void free_qgroup_counts(void)
}
}
+static bool is_bad_qgroup(struct qgroup_count *count)
+{
+ struct qgroup_info *info = &count->info;
+ struct qgroup_info *disk = &count->diskinfo;
+ s64 excl_diff = info->exclusive - disk->exclusive;
+ s64 ref_diff = info->referenced - disk->referenced;
+
+ return (excl_diff || ref_diff);
+}
+
+/*
+ * Verify all qgroup numbers.
+ *
+ * Return <0 for fatal errors (e.g. ENOMEM or failed to read quota tree)
+ * Return 0 if all qgroup numbers are correct or no need to check (under rescan)
+ * Return >0 if qgroup numbers are inconsistent.
+ */
int qgroup_verify_all(struct btrfs_fs_info *info)
{
int ret;
+ bool found_err = false;
+ bool skip_err = false;
+ struct rb_node *node;
if (!info->quota_enabled)
return 0;
@@ -1413,6 +1420,12 @@ int qgroup_verify_all(struct btrfs_fs_info *info)
goto out;
}
+ if (counts.rescan_running)
+ skip_err = true;
+ if (counts.qgroup_inconsist && !counts.rescan_running &&
+ counts.rescan_running == 0)
+ skip_err = true;
+
/*
* Put all extent refs into our rbtree
*/
@@ -1430,6 +1443,22 @@ int qgroup_verify_all(struct btrfs_fs_info *info)
ret = account_all_refs(1, 0);
+ /*
+ * Do the correctness check here, so for callers who don't want
+ * verbose report can skip calling report_qgroups()
+ */
+ node = rb_first(&counts.root);
+ while (node) {
+ struct qgroup_count *c;
+
+ c = rb_entry(node, struct qgroup_count, rb_node);
+ if (is_bad_qgroup(c)) {
+ list_add_tail(&c->bad_list, &bad_qgroups);
+ found_err = true;
+ }
+ node = rb_next(node);
+ }
+
out:
/*
* Don't free the qgroup count records as they will be walked
@@ -1437,6 +1466,8 @@ out:
*/
free_tree_blocks();
free_ref_tree(&by_bytenr);
+ if (!ret && !skip_err && found_err)
+ ret = 1;
return ret;
}
diff --git a/check/qgroup-verify.h b/check/qgroup-verify.h
index 20e93708..6495dd18 100644
--- a/check/qgroup-verify.h
+++ b/check/qgroup-verify.h
@@ -23,7 +23,7 @@
#include "ctree.h"
int qgroup_verify_all(struct btrfs_fs_info *info);
-int report_qgroups(int all);
+void report_qgroups(int all);
int repair_qgroups(struct btrfs_fs_info *info, int *repaired);
int print_extent_state(struct btrfs_fs_info *info, u64 subvol);
--
2.25.0
next prev parent reply other threads:[~2020-03-18 20:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-18 20:21 [PATCH v4 00/11] btrfs-progs: mkfs: Quota support through -Q|--quota Marcos Paulo de Souza
2020-03-18 20:21 ` [PATCH v4 01/11] btrfs-progs: qgroup-verify: Avoid NULL pointer dereference for later silent qgroup repair Marcos Paulo de Souza
2020-03-18 20:21 ` [PATCH v4 02/11] btrfs-progs: qgroup-verify: Also repair qgroup status version Marcos Paulo de Souza
2020-03-18 20:21 ` [PATCH v4 03/11] btrfs-progs: qgroup-verify: Use fs_info->readonly to check if we should repair qgroups Marcos Paulo de Souza
2020-03-18 20:21 ` Marcos Paulo de Souza [this message]
2020-03-18 20:21 ` [PATCH v4 05/11] btrfs-progs: qgroup-verify: Allow repair_qgroups function to do silent repair Marcos Paulo de Souza
2020-03-18 20:21 ` [PATCH v4 06/11] btrfs-progs: ctree: Introduce function to create an empty tree Marcos Paulo de Souza
2020-03-18 20:21 ` [PATCH v4 07/11] btrfs-progs: mkfs: Introduce function to insert qgroup info and limit items Marcos Paulo de Souza
2020-03-18 20:21 ` [PATCH v4 08/11] btrfs-progs: mkfs: Introduce function to setup quota root and rescan Marcos Paulo de Souza
2020-03-18 20:21 ` [PATCH v4 09/11] btrfs-progs: mkfs: Introduce mkfs time quota support Marcos Paulo de Souza
2020-03-18 20:21 ` [PATCH v4 10/11] btrfs-progs: test/mkfs: Add test case for -Q|--quota option Marcos Paulo de Souza
2020-03-18 20:21 ` [PATCH v4 11/11] btrfs-progs: test/mkfs: Add test case for --rootdir and --quota Marcos Paulo de Souza
2020-05-25 14:43 ` [PATCH v4 00/11] btrfs-progs: mkfs: Quota support through -Q|--quota 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=20200318202148.14828-5-marcos@mpdesouza.com \
--to=marcos@mpdesouza.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=mpdesouza@suse.com \
--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).