linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] btrfs-progs: Fix return value bug of qgroups check
@ 2016-04-18  2:27 Qu Wenruo
  2016-04-18  2:27 ` [PATCH 2/3] btrfs-progs: Fix an extent buffer leak in " Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qu Wenruo @ 2016-04-18  2:27 UTC (permalink / raw)
  To: linux-btrfs, mfasheh

Before this patch, although btrfsck will check qgroups if quota is
enabled, it always return 0 even qgroup numbers are corrupted.

Fix it by allowing return value from report_qgroups function (formally
defined as print_qgroup_difference).

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c    | 8 ++++++--
 qgroup-verify.c | 9 ++++++---
 qgroup-verify.h | 2 +-
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index d59968b..de17be3 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -9698,7 +9698,7 @@ int cmd_check(int argc, char **argv)
 		       uuidbuf);
 		ret = qgroup_verify_all(info);
 		if (ret == 0)
-			print_qgroup_report(1);
+			ret = report_qgroups(1);
 		goto close_out;
 	}
 	if (subvolid) {
@@ -9859,7 +9859,11 @@ int cmd_check(int argc, char **argv)
 		ret = 1;
 	}
 out:
-	print_qgroup_report(0);
+	/* Don't override original ret */
+	if (ret)
+		report_qgroups(0);
+	else
+		ret = report_qgroups(0);
 	if (found_old_backref) { /*
 		 * there was a disk format change when mixed
 		 * backref was in testing tree. The old format
diff --git a/qgroup-verify.c b/qgroup-verify.c
index 10ff8e0..c4e9201 100644
--- a/qgroup-verify.c
+++ b/qgroup-verify.c
@@ -1016,7 +1016,7 @@ static void print_fields_signed(long long bytes,
 	       prefix, type, bytes, type, bytes_compressed);
 }
 
-static void print_qgroup_difference(struct qgroup_count *count, int verbose)
+static int report_qgroup_difference(struct qgroup_count *count, int verbose)
 {
 	int is_different;
 	struct qgroup_info *info = &count->info;
@@ -1046,19 +1046,22 @@ static void print_qgroup_difference(struct qgroup_count *count, int verbose)
 			print_fields_signed(excl_diff, excl_diff,
 					    "diff:", "exclusive");
 	}
+	return (is_different && count->subvol_exists);
 }
 
-void print_qgroup_report(int all)
+int report_qgroups(int all)
 {
 	struct rb_node *node;
 	struct qgroup_count *c;
+	int ret = 0;
 
 	node = rb_first(&counts.root);
 	while (node) {
 		c = rb_entry(node, struct qgroup_count, rb_node);
-		print_qgroup_difference(c, all);
+		ret |= report_qgroup_difference(c, all);
 		node = rb_next(node);
 	}
+	return ret;
 }
 
 int qgroup_verify_all(struct btrfs_fs_info *info)
diff --git a/qgroup-verify.h b/qgroup-verify.h
index 7d91c19..3747465 100644
--- a/qgroup-verify.h
+++ b/qgroup-verify.h
@@ -23,7 +23,7 @@
 #include "ctree.h"
 
 int qgroup_verify_all(struct btrfs_fs_info *info);
-void print_qgroup_report(int all);
+int report_qgroups(int all);
 
 int print_extent_state(struct btrfs_fs_info *info, u64 subvol);
 
-- 
2.8.0




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] btrfs-progs: Fix an extent buffer leak in qgroups check
  2016-04-18  2:27 [PATCH 1/3] btrfs-progs: Fix return value bug of qgroups check Qu Wenruo
@ 2016-04-18  2:27 ` Qu Wenruo
  2016-04-18  2:27 ` [PATCH 3/3] btrfs-progs: Read qgroup status for qgroup verify Qu Wenruo
  2016-04-25 12:09 ` [PATCH 1/3] btrfs-progs: Fix return value bug of qgroups check David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2016-04-18  2:27 UTC (permalink / raw)
  To: linux-btrfs, mfasheh

Qgroup verify codes will read fs root to check if the subvolume exists.
But it forgot to free the extent buffer read out, only freeing the
memory.

Fix it by also freeing the extent buffers.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 qgroup-verify.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qgroup-verify.c b/qgroup-verify.c
index c4e9201..48e4d22 100644
--- a/qgroup-verify.c
+++ b/qgroup-verify.c
@@ -761,7 +761,7 @@ static int load_quota_info(struct btrfs_fs_info *info)
 			tmproot = btrfs_read_fs_root_no_cache(info, &root_key);
 			if (tmproot && !IS_ERR(tmproot)) {
 				count->subvol_exists = 1;
-				free(tmproot);
+				btrfs_free_fs_root(tmproot);
 			}
 		}
 
-- 
2.8.0




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] btrfs-progs: Read qgroup status for qgroup verify
  2016-04-18  2:27 [PATCH 1/3] btrfs-progs: Fix return value bug of qgroups check Qu Wenruo
  2016-04-18  2:27 ` [PATCH 2/3] btrfs-progs: Fix an extent buffer leak in " Qu Wenruo
@ 2016-04-18  2:27 ` Qu Wenruo
  2016-04-25 12:09 ` [PATCH 1/3] btrfs-progs: Fix return value bug of qgroups check David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2016-04-18  2:27 UTC (permalink / raw)
  To: linux-btrfs, mfasheh

Read qgroup status for its flags like QGROUP_STATUS_FLAG_RESCAN and
QGROUP_STATUS_FLAG_INCONSISTENT.

This will help to avoid false alert for case like qgroup rescan is still
running when un-mounted.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 qgroup-verify.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/qgroup-verify.c b/qgroup-verify.c
index 48e4d22..e2b8be3 100644
--- a/qgroup-verify.c
+++ b/qgroup-verify.c
@@ -59,6 +59,8 @@ struct qgroup_count {
 static struct counts_tree {
 	struct rb_root		root;
 	unsigned int		num_groups;
+	unsigned int		rescan_running:1;
+	unsigned int		qgroup_inconsist:1;
 } counts = { .root = RB_ROOT };
 
 static struct rb_root by_bytenr = RB_ROOT;
@@ -700,6 +702,19 @@ static void add_bytes(u64 root_objectid, u64 num_bytes, int exclusive)
 	}
 }
 
+static void read_qgroup_status(struct btrfs_path *path,
+			      struct counts_tree *counts)
+{
+	struct btrfs_qgroup_status_item *status_item;
+	u64 flags;
+
+	status_item = btrfs_item_ptr(path->nodes[0], path->slots[0],
+				     struct btrfs_qgroup_status_item);
+	flags = btrfs_qgroup_status_flags(path->nodes[0], status_item);
+	counts->qgroup_inconsist = flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+	counts->rescan_running = flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN;
+}
+
 static int load_quota_info(struct btrfs_fs_info *info)
 {
 	int ret;
@@ -734,13 +749,17 @@ static int load_quota_info(struct btrfs_fs_info *info)
 			btrfs_item_key(leaf, &disk_key, i);
 			btrfs_disk_key_to_cpu(&key, &disk_key);
 
+			if (key.type == BTRFS_QGROUP_STATUS_KEY) {
+				read_qgroup_status(&path, &counts);
+				continue;
+			}
 			if (key.type == BTRFS_QGROUP_RELATION_KEY)
 				printf("Ignoring qgroup relation key %llu\n",
 				       key.objectid);
 
 			/*
-			 * Ignore: BTRFS_QGROUP_STATUS_KEY,
-			 * BTRFS_QGROUP_LIMIT_KEY, BTRFS_QGROUP_RELATION_KEY
+			 * Ignore: BTRFS_QGROUP_LIMIT_KEY,
+			 * 	   BTRFS_QGROUP_RELATION_KEY
 			 */
 			if (key.type != BTRFS_QGROUP_INFO_KEY)
 				continue;
@@ -1055,6 +1074,16 @@ int report_qgroups(int all)
 	struct qgroup_count *c;
 	int ret = 0;
 
+	if (counts.rescan_running) {
+		if (all)
+			printf("Qgroup rescan is running, qgroup counts difference is expected\n");
+		else {
+			printf("Qgroup rescan is running, ignore qgroup check\n");
+			return ret;
+		}
+	}
+	if (counts.qgroup_inconsist && !counts.rescan_running)
+		fprintf(stderr, "Qgroup is already inconsistent before checking\n");
 	node = rb_first(&counts.root);
 	while (node) {
 		c = rb_entry(node, struct qgroup_count, rb_node);
-- 
2.8.0




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] btrfs-progs: Fix return value bug of qgroups check
  2016-04-18  2:27 [PATCH 1/3] btrfs-progs: Fix return value bug of qgroups check Qu Wenruo
  2016-04-18  2:27 ` [PATCH 2/3] btrfs-progs: Fix an extent buffer leak in " Qu Wenruo
  2016-04-18  2:27 ` [PATCH 3/3] btrfs-progs: Read qgroup status for qgroup verify Qu Wenruo
@ 2016-04-25 12:09 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2016-04-25 12:09 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, mfasheh

On Mon, Apr 18, 2016 at 10:27:07AM +0800, Qu Wenruo wrote:
> Before this patch, although btrfsck will check qgroups if quota is
> enabled, it always return 0 even qgroup numbers are corrupted.
> 
> Fix it by allowing return value from report_qgroups function (formally
> defined as print_qgroup_difference).
> 
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

All three applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-25 12:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-18  2:27 [PATCH 1/3] btrfs-progs: Fix return value bug of qgroups check Qu Wenruo
2016-04-18  2:27 ` [PATCH 2/3] btrfs-progs: Fix an extent buffer leak in " Qu Wenruo
2016-04-18  2:27 ` [PATCH 3/3] btrfs-progs: Read qgroup status for qgroup verify Qu Wenruo
2016-04-25 12:09 ` [PATCH 1/3] btrfs-progs: Fix return value bug of qgroups check David Sterba

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).