btrfs-progs: check: Make btrfs check return error for qgroup mismatch

Current btrfs-check will check qgroup consistency, but even when it
finds something wrong, the return value is still 0.

Fix it by allowing report_qgroups() to return int to indicate qgroup
mismatch, and also add extra logic to return no error if qgroup repair
is successful.

Without this patch, fstests can't detect qgroup corruption by its fsck
alone.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
master
Qu Wenruo 2018-04-30 14:16:59 +08:00 committed by David Sterba
parent 9f8316f1c8
commit 4bd7bbb6f6
3 changed files with 24 additions and 8 deletions

View File

@ -9410,6 +9410,7 @@ int cmd_check(int argc, char **argv)
int clear_space_cache = 0;
int qgroup_report = 0;
int qgroups_repaired = 0;
int qgroup_report_ret;
unsigned ctree_flags = OPEN_CTREE_EXCLUSIVE;
int force = 0;
@ -9652,7 +9653,7 @@ int cmd_check(int argc, char **argv)
ret = qgroup_verify_all(info);
err |= !!ret;
if (ret == 0)
report_qgroups(1);
err |= !!report_qgroups(1);
goto close_out;
}
if (subvolid) {
@ -9844,13 +9845,14 @@ int cmd_check(int argc, char **argv)
error("failed to check quota groups");
goto out;
}
report_qgroups(0);
qgroup_report_ret = report_qgroups(0);
ret = repair_qgroups(info, &qgroups_repaired);
err |= !!ret;
if (err) {
if (ret) {
error("failed to repair quota groups");
goto out;
}
if (qgroup_report_ret && (!qgroups_repaired || ret))
err |= qgroup_report_ret;
ret = 0;
}

View File

@ -1298,10 +1298,19 @@ static int report_qgroup_difference(struct qgroup_count *count, int verbose)
return is_different;
}
void report_qgroups(int all)
/*
* 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)
{
struct rb_node *node;
struct qgroup_count *c;
bool found_err = false;
if (!repair && counts.rescan_running) {
if (all) {
@ -1310,7 +1319,7 @@ void report_qgroups(int all)
} else {
printf(
"Qgroup rescan is running, qgroups will not be printed.\n");
return;
return 0;
}
}
if (counts.qgroup_inconsist && !counts.rescan_running)
@ -1319,11 +1328,16 @@ void report_qgroups(int all)
while (node) {
c = rb_entry(node, struct qgroup_count, rb_node);
if (report_qgroup_difference(c, all))
if (report_qgroup_difference(c, all)) {
list_add_tail(&c->bad_list, &bad_qgroups);
found_err = true;
}
node = rb_next(node);
}
if (found_err)
return -EUCLEAN;
return 0;
}
void free_qgroup_counts(void)

View File

@ -23,7 +23,7 @@
#include "ctree.h"
int qgroup_verify_all(struct btrfs_fs_info *info);
void report_qgroups(int all);
int 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);