Skip to content

Commit 7f3ab46

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: qgroup: add more special statuses for qgroups
Currently `btrfs qgroup show` command shows any 0 level qgroup without a root backref as `<stale>`, which is not correct. There are several more cases: - Under deletion The subvolume is not yet full dropped, but unlinked. In that case we would not have a root backref item, but the qgroup is not stale. - Squota space holder This is for squota mode, that a fully dropped subvolume still have extents accounting on the already-gone subvolume. In this case it's not stale either, and future accounting relies on it. This patch would add above special cases, and add an extra `SPECIAL PATHS` section to explain all the cases, including `<stale>`. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 82f7d6c commit 7f3ab46

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

Documentation/btrfs-qgroup.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ show [options] <path>
153153
To retrieve information after updating the state of qgroups,
154154
force sync of the filesystem identified by *path* before getting information.
155155

156+
SPECIAL PATHS
157+
-------------
158+
For `btrfs qgroup show` subcommand, the ``path`` column may has some special
159+
strings:
160+
161+
`<toplevel>`
162+
The toplevel subvolume
163+
164+
`<under deletion>`
165+
The subvolume is unlinked, but not yet fully deleted.
166+
167+
`<squota space holder>`
168+
For simple quota mode only.
169+
By its design, a fully deleted subvolume may still have accounting on
170+
it, so even the subvolume is gone, the numbers are still here for future
171+
accounting.
172+
173+
`<stale>`
174+
The qgroup has no corresponding subvolume anymore, and the qgroup
175+
can be cleaned up under most cases.
176+
The only exception is that, if the qgroup numbers are inconsistent and
177+
the qgroup numbers are not all zeros, some older kernels may refuse to
178+
delete such qgroups until a full rescan.
179+
156180
QUOTA RESCAN
157181
------------
158182

cmds/qgroup.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ struct qgroup_lookup {
7171
};
7272

7373
struct btrfs_qgroup {
74+
struct qgroup_lookup *lookup;
75+
7476
struct rb_node rb_node;
7577
struct rb_node sort_node;
7678
/*
@@ -321,6 +323,26 @@ static void print_qgroup_column_add_blank(enum btrfs_qgroup_column_enum column,
321323
printf(" ");
322324
}
323325

326+
static const char *get_qgroup_path(struct btrfs_qgroup *qgroup)
327+
{
328+
if (qgroup->path)
329+
return qgroup->path;
330+
331+
/* No path but not stale either, the qgroup is being deleted. */
332+
if (!qgroup->stale)
333+
return "<under deletion>";
334+
/*
335+
* Squota mode stale qgroup, but not empty.
336+
* This is fully deleted but still necessary.
337+
*/
338+
if (qgroup->stale &&
339+
(qgroup->lookup->flags & BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE) &&
340+
!is_qgroup_empty(qgroup))
341+
return "<squota space holder>";
342+
343+
return "<stale>";
344+
}
345+
324346
static void print_path_column(struct btrfs_qgroup *qgroup)
325347
{
326348
struct btrfs_qgroup_list *list = NULL;
@@ -338,11 +360,8 @@ static void print_path_column(struct btrfs_qgroup *qgroup)
338360
if (count)
339361
pr_verbose(LOG_DEFAULT, " ");
340362
if (level == 0) {
341-
const char *path = member->path;
342-
343-
if (!path)
344-
path = "<stale>";
345-
pr_verbose(LOG_DEFAULT, "%s", path);
363+
pr_verbose(LOG_DEFAULT, "%s",
364+
get_qgroup_path(qgroup));
346365
} else {
347366
pr_verbose(LOG_DEFAULT, "%llu/%llu", level, sid);
348367
}
@@ -353,7 +372,7 @@ static void print_path_column(struct btrfs_qgroup *qgroup)
353372
} else if (qgroup->path) {
354373
pr_verbose(LOG_DEFAULT, "%s%s", (*qgroup->path ? "" : "<toplevel>"), qgroup->path);
355374
} else {
356-
pr_verbose(LOG_DEFAULT, "<stale>");
375+
pr_verbose(LOG_DEFAULT, "%s", get_qgroup_path(qgroup));
357376
}
358377
}
359378

@@ -805,6 +824,7 @@ static struct btrfs_qgroup *get_or_add_qgroup(int fd,
805824
return ERR_PTR(-ENOMEM);
806825
}
807826

827+
bq->lookup = qgroup_lookup;
808828
bq->qgroupid = qgroupid;
809829
INIT_LIST_HEAD(&bq->qgroups);
810830
INIT_LIST_HEAD(&bq->members);

0 commit comments

Comments
 (0)