diff mbox

[18/18] btrfs-progs: qgroups: don't print dead qgroups

Message ID 20180516213851.10196-19-jeffm@suse.com
State New, archived
Headers show

Commit Message

Jeff Mahoney May 16, 2018, 9:38 p.m. UTC
From: Jeff Mahoney <jeffm@suse.com>

When qgroup items get left behind, we still print them in
'btrfs qgroup show' even though there is nothing to show.  Since we
now look up the pathname and that means we look up the subvolume,
we can filter out first-level qgroups that correspond to roots
that have been removed.  Specifying -v will still show them.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 qgroup.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/qgroup.c b/qgroup.c
index 647bc2f3..08e78887 100644
--- a/qgroup.c
+++ b/qgroup.c
@@ -313,6 +313,13 @@  static void print_qgroup_column(struct btrfs_qgroup *qgroup,
 	}
 }
 
+static bool qgroup_target_exists(const struct btrfs_qgroup *qgroup)
+{
+	if (btrfs_qgroup_level(qgroup->qgroupid) > 0)
+		return true;
+	return qgroup->pathname != NULL;
+}
+
 static void print_single_qgroup_table(struct btrfs_qgroup *qgroup, bool verbose)
 {
 	int i;
@@ -1369,7 +1376,8 @@  static void print_all_qgroups(struct qgroup_lookup *qgroup_lookup, bool verbose)
 	n = rb_first(&qgroup_lookup->root);
 	while (n) {
 		entry = rb_entry(n, struct btrfs_qgroup, sort_node);
-		print_single_qgroup_table(entry, verbose);
+		if (qgroup_target_exists(entry) || verbose)
+			print_single_qgroup_table(entry, verbose);
 		n = rb_next(n);
 	}
 }