NOTE: This patch needs to cooperate with kernel patches, which will fix
a kernel bug that never clear INCONSISTENT bit and return 1 if quota
assign makes qgroup data inconsistent.

Some qgroup assign will cause qgroup data inconsistent, like remove a
qgroup with shared extents from a parent qgroup. But some won't, like
assign a empty(OK, nodesize rfer and exel) to a qgroup.

Newer kernel will return 1 if qgroup data inconsistent and in that case
we should schedule a quota rescan.

This patch will do this in btrfs-progs.

Signed-off-by: Qu Wenruo <quwen...@cn.fujitsu.com>
---
 cmds-qgroup.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 2d6d84b..7d5f41f 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -64,13 +64,33 @@ static int qgroup_assign(int assign, int argc, char **argv)
 
        ret = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, &args);
        e = errno;
-       close_file_or_dir(fd, dirstream);
        if (ret < 0) {
                fprintf(stderr, "ERROR: unable to assign quota group: %s\n",
                        strerror(e));
+               close_file_or_dir(fd, dirstream);
                return 1;
        }
-       return 0;
+
+       /*
+        * If ret > 0, it means the assign caused qgroup data inconsistent.
+        * Schedule a quota rescan.
+        *
+        * The return value change only happens in newer kernel. But will not
+        * cause problem since old kernel has a bug that will never clear
+        * INCONSISTENT bit.
+        */
+       if (ret > 0) {
+               struct btrfs_ioctl_quota_rescan_args args;
+
+               printf("Quota data changed, quota rescan scheduled\n");
+               memset(&args, 0, sizeof(args));
+               ret = ioctl(fd, BTRFS_IOC_QUOTA_RESCAN, &args);
+               if (ret < 0)
+                       fprintf(stderr, "ERROR: quota rescan failed: %s\n",
+                               strerror(errno));
+       }
+       close_file_or_dir(fd, dirstream);
+       return ret;
 }
 
 static int qgroup_create(int create, int argc, char **argv)
-- 
2.3.0

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to