diff mbox series

[1/4] btrfs-progs: cmds/qgroup: sync the fs before doing qgroup search

Message ID 50d13a90a4dd1146fe6d755ec3a7e69ff9fba325.1715245781.git.wqu@suse.com (mailing list archive)
State New
Headers show
Series btrfs-progs: cmds/qgroup: enhance stale qgroups handling | expand

Commit Message

Qu Wenruo May 9, 2024, 9:12 a.m. UTC
Since qgroup numbers are only updated at transaction commit time, it's
better to do the a sync before reading the quota tree, to reduce the
chance of uncommitted qgroup changes.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 cmds/qgroup.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/cmds/qgroup.c b/cmds/qgroup.c
index 6e88db5803a5..09eac0d2b36e 100644
--- a/cmds/qgroup.c
+++ b/cmds/qgroup.c
@@ -2135,6 +2135,7 @@  static const char * const cmd_qgroup_clear_stale_usage[] = {
 
 static int cmd_qgroup_clear_stale(const struct cmd_struct *cmd, int argc, char **argv)
 {
+	enum btrfs_util_error err;
 	int ret = 0;
 	int fd;
 	char *path = NULL;
@@ -2151,6 +2152,11 @@  static int cmd_qgroup_clear_stale(const struct cmd_struct *cmd, int argc, char *
 	if (fd < 0)
 		return 1;
 
+	/* Sync the fs so that the qgroup numbers are uptodate. */
+	err = btrfs_util_sync_fd(fd);
+	if (err)
+		warning("sync ioctl failed on '%s': %m", path);
+
 	ret = qgroups_search_all(fd, &qgroup_lookup);
 	if (ret == -ENOTTY) {
 		error("can't list qgroups: quotas not enabled");