btrfs-prog commit:
58a39524619f38d193b8adc3d57888ec07b612aa
change the default output to binary prefix,
and introduced a new option '--raw'
to keep the traditional behaviour.
This patch will add a check function to determine
whether to add '--raw' option to 'btrfs show qgroup'.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
daemon/btrfs.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index d4b3207..fabb00b 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1210,12 +1210,45 @@ do_btrfs_qgroup_destroy (const char *qgroupid, const char
*subvolume)
return 0;
}
+/* btrfs qgroup show command change default output to
+ * binary prefix since v3.18.2, such as KiB;
+ * also introduced '--raw' to keep traditional behaviour.
+ * We could check wheter 'btrfs qgroup show' support '--raw'
+ * option by checking the output of
+ * 'btrfs qgroup show' support --help' command.
+ */
+static int
+test_btrfs_qgroup_show_raw_opt (void)
+{
+ static int result = -1;
+ if (result != -1)
+ return result;
+
+ CLEANUP_FREE char *err = NULL;
+ CLEANUP_FREE char *out = NULL;
+
+ int r = commandr (&out, &err, str_btrfs, "qgroup", "show",
"--help", NULL);
+
+ if (r == -1) {
+ reply_with_error ("btrfs qgroup show --help: %s", err);
+ return -1;
+ }
+
+ if (strstr (out, "--raw") == NULL)
+ result = 0;
+ else
+ result = 1;
+
+ return result;
+}
+
guestfs_int_btrfsqgroup_list *
do_btrfs_qgroup_show (const char *path)
{
const size_t MAX_ARGS = 64;
const char *argv[MAX_ARGS];
size_t i = 0;
+ int has_raw_opt = test_btrfs_qgroup_show_raw_opt ();
CLEANUP_FREE char *path_buf = NULL;
CLEANUP_FREE char *err = NULL;
CLEANUP_FREE char *out = NULL;
@@ -1231,6 +1264,8 @@ do_btrfs_qgroup_show (const char *path)
ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "qgroup");
ADD_ARG (argv, i, "show");
+ if (has_raw_opt > 0)
+ ADD_ARG (argv, i, "--raw");
ADD_ARG (argv, i, path_buf);
ADD_ARG (argv, i, NULL);
--
2.1.0
Show replies by date