Skip to content

Commit 663244e

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: qgroup show: use sysfs to detect inconsistent state early
Currently if "btrfs qgroup show" detects the qgroup is in an inconsistent state, it will print a warning: WARNING: qgroup data inconsistent, rescan recommended But the detection is based on the tree search ioctl, and qgroup tree is only updated at transaction commit time. This means if qgroup is marked inconsistent, and the transaction is not commit, there can be a time window as long as 30s before "btrfs qgroup show" gives a proper warning about inconsistent qgroup numbers. To address this, use the '/sys/fs/btrfs/<fsid>/qgroup/inconsistent' file to do extra check. That file is updated at real time, thus there is no delay, and can give an early warning about inconsistent qgroup numbers. Link: https://bugzilla.suse.com/show_bug.cgi?id=1235765 Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent c7fce0e commit 663244e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

cmds/qgroup.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "kernel-shared/uapi/btrfs.h"
3737
#include "kernel-shared/ctree.h"
3838
#include "common/open-utils.h"
39+
#include "common/sysfs-utils.h"
3940
#include "common/utils.h"
4041
#include "common/help.h"
4142
#include "common/units.h"
@@ -1610,6 +1611,31 @@ static void print_all_qgroups_json(struct qgroup_lookup *qgroup_lookup)
16101611
fmt_end(&fctx);
16111612
}
16121613

1614+
/*
1615+
* Tree search based 'inconsistent' flag is only updated at transaction commit
1616+
* time. Thus even if the qgroup_status flag shows consistent, the qgroup may
1617+
* already be in an inconsistent state.
1618+
*/
1619+
static void check_qgroup_sysfs_inconsistent(int fd, const struct qgroup_lookup *qgroup_lookup)
1620+
{
1621+
u64 value;
1622+
int sysfs_fd;
1623+
int ret;
1624+
1625+
if (qgroup_lookup->flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
1626+
return;
1627+
sysfs_fd = sysfs_open_fsid_file(fd, "qgroups/inconsistent");
1628+
if (fd < 0)
1629+
return;
1630+
ret = sysfs_read_fsid_file_u64(fd, "qgroups/inconsistent", &value);
1631+
if (ret < 0)
1632+
goto out;
1633+
if (value)
1634+
warning("qgroup data inconsistent, rescan recommended");
1635+
out:
1636+
close(sysfs_fd);
1637+
}
1638+
16131639
static int show_qgroups(int fd,
16141640
struct btrfs_qgroup_filter_set *filter_set,
16151641
struct btrfs_qgroup_comparer_set *comp_set)
@@ -1622,6 +1648,8 @@ static int show_qgroups(int fd,
16221648
ret = qgroups_search_all(fd, &qgroup_lookup);
16231649
if (ret)
16241650
return ret;
1651+
1652+
check_qgroup_sysfs_inconsistent(fd, &qgroup_lookup);
16251653
__filter_and_sort_qgroups(&qgroup_lookup, &sort_tree,
16261654
filter_set, comp_set);
16271655
if (bconf.output_format == CMD_FORMAT_JSON)

0 commit comments

Comments
 (0)