Skip to contentSkip to conversation

btrfs-progs: Fix qgroup false alerts on uninitialized rescan

PATCH Applied Qu Wenruo 2 participants 4 messages Jul 26, 2018 – Aug 3, 2018 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

cover btrfs-progs: Fix qgroup false alerts on uninitialized rescan

This patches can be fetched from github:
https://github.com/adam900710/btrfs-progs/tree/qgroup_report

It's possible that certain timed power loss could lead to initialized quota tree without rescan kicked in.
Can be reproduced in btrfs/166 with low possibility.

In that case, since default flags for QUOTA_STATUS is ON|INCONSISTENT, btrfs check will still check qgroups and report difference as error.

However rescan progress of QUOTA_STATUS is still 0, means qgroup rescan hasn't been kicked in, and all quota numbers are 0, difference is expected.

In this case, make btrfs check don't report such uninitialized rescan as error.

Qu Wenruo (2):
btrfs-progs: qgroup-verify: Don't treat qgroup difference as error if
the fs hasn't initialized a rescan
btrfs-progs: fsck-tests: Add test image to check if btrfs check
reports uninitialized rescan as error

 qgroup-verify.c                                 |  14 +++++++++++++-
 .../no_rescan_kicked_in.img                     | Bin 0 -> 3072 bytes
 .../fsck-tests/035-rescan-not-kicked-in/test.sh |  16 ++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img
 create mode 100755 tests/fsck-tests/035-rescan-not-kicked-in/test.sh
Signature · 1 line
2.18.0
author
#1 lore raw

PATCH 1/2 btrfs-progs: qgroup-verify: Don't treat qgroup difference as error if the fs hasn't initialized a rescan

During test btrfs/166, it's possible to hit a certain case where qgroup is just enabled but rescan hasn't been kicked in.

Since at qgroup enable time, we mark INCONSISTENT flag, and let later rescan to clear that flag, if power loss before we kick in rescan, it's possible we get a qgroup status item with ON|INCONSISTENT but without RESCAN flag.

And in that case, it will definitely cause difference in qgroup numbers (as all numbers in qgroup tree is 0).

Fix this false alert by also checking rescan progress from btrfs_status_item.
And if we find rescan progress is still 0, INCONSISTENT flag set and no RESCAN flag set, we won't treat it as an error.

---
 qgroup-verify.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
qgroup-verify.c +13 -1
index e2332be2975a..21db79d5cf7d 100644
@@ -77,6 +77,7 @@ static struct counts_tree {
 	unsigned int		num_groups;
 	unsigned int		rescan_running:1;
 	unsigned int		qgroup_inconsist:1;
+	u64			scan_progress;
 } counts = { .root = RB_ROOT };
 
 static LIST_HEAD(bad_qgroups);
@@ -914,6 +915,7 @@ static void read_qgroup_status(struct extent_buffer *eb, int slot,
 	counts->qgroup_inconsist = !!(flags &
 			BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT);
 	counts->rescan_running = !!(flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN);
+	counts->scan_progress = btrfs_qgroup_status_rescan(eb, status_item);
 }
 
 static int load_quota_info(struct btrfs_fs_info *info)
@@ -1311,6 +1313,7 @@ int 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) {
@@ -1322,6 +1325,15 @@ int report_qgroups(int all)
 			return 0;
 		}
 	}
+	/*
+	 * It's possible that rescan hasn't been initialized yet.
+	 */
+	if (counts.qgroup_inconsist && !counts.rescan_running &&
+	    counts.rescan_running == 0) {
+		printf(
+"Rescan hasn't been initialzied, a difference in qgroup counts is expected\n");
+		skip_err = true;
+	}
 	if (counts.qgroup_inconsist && !counts.rescan_running)
 		fprintf(stderr, "Qgroup are marked as inconsistent.\n");
 	node = rb_first(&counts.root);
@@ -1335,7 +1347,7 @@ int report_qgroups(int all)
 
 		node = rb_next(node);
 	}
-	if (found_err)
+	if (found_err && !skip_err)
 		return -EUCLEAN;
 	return 0;
 }
Signature · 1 line
2.18.0
author
#2 lore raw

PATCH 2/2 btrfs-progs: fsck-tests: Add test image to check if btrfs check reports uninitialized rescan as error

In reply to Qu Wenruo
---
 .../no_rescan_kicked_in.img                     | Bin 0 -> 3072 bytes
 .../fsck-tests/035-rescan-not-kicked-in/test.sh |  16 ++++++++++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img
 create mode 100755 tests/fsck-tests/035-rescan-not-kicked-in/test.sh
tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..b855a72ff1dd7f629472450a67c27202fb21c628
GIT binary patch
tests/fsck-tests/035-rescan-not-kicked-in/test.sh new file +16 -0
new file mode 100755
index 000000000000..7d632653332f
@@ -0,0 +1,16 @@
+#!/bin/bash
+# Under certain power loss case, btrfs quota tree can be initialized but
+# rescan not kicked in. (can be reproduced in low possibility in btrfs/166).
+#
+# This test case is to ensure for such special case, btrfs check doesn't report
+# such qgroup difference as error, thus no false alert for btrfs/166.
+
+source "$TEST_TOP/common"
+
+check_prereq btrfs
+
+check_image() {
+	run_check "$TOP/btrfs" check "$1"
+}
+
+check_all_images
Signature · 1 line
2.18.0
Applied
#3 lore raw
In reply to Qu Wenruo
Quoted 14 lines · Qu Wenruo

This patches can be fetched from github:
https://github.com/adam900710/btrfs-progs/tree/qgroup_report

It's possible that certain timed power loss could lead to initialized quota tree without rescan kicked in.
Can be reproduced in btrfs/166 with low possibility.

In that case, since default flags for QUOTA_STATUS is ON|INCONSISTENT, btrfs check will still check qgroups and report difference as error.

However rescan progress of QUOTA_STATUS is still 0, means qgroup rescan hasn't been kicked in, and all quota numbers are 0, difference is expected.

Quoted 8 lines

In this case, make btrfs check don't report such uninitialized rescan as error.

Qu Wenruo (2):
btrfs-progs: qgroup-verify: Don't treat qgroup difference as error if
the fs hasn't initialized a rescan
btrfs-progs: fsck-tests: Add test image to check if btrfs check
reports uninitialized rescan as error

Applied, thanks.