[Libguestfs] [PATCH v2 06/11] New API: btrfs_qgroup_limit

Hu Tao
Thu, 11 Dec 2014 06:11:34 -0000

btrfs_qgroup_limit limits the size of a qgroup.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 daemon/btrfs.c       | 35 +++++++++++++++++++++++++++++++++++
 generator/actions.ml | 22 ++++++++++++++++++++++
 src/MAX_PROC_NR      |  2 +-
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 629cb6f..8e9abed 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1082,3 +1082,38 @@ error:
     return -1;
   return r;
 }
+
+int
+do_btrfs_qgroup_limit (const char *subvolume, int64_t size)
+{
+  const size_t MAX_ARGS = 64;
+  const char *argv[MAX_ARGS];
+  size_t i = 0;
+  CLEANUP_FREE char *subvolume_buf = NULL;
+  CLEANUP_FREE char *err = NULL;
+  CLEANUP_FREE char *out = NULL;
+  char size_str[32];
+  int r;
+
+  subvolume_buf = sysroot_path (subvolume);
+  if (subvolume_buf == NULL) {
+    reply_with_perror ("malloc");
+    return -1;
+  }
+
+  ADD_ARG (argv, i, str_btrfs);
+  ADD_ARG (argv, i, "qgroup");
+  ADD_ARG (argv, i, "limit");
+  snprintf (size_str, sizeof size_str, "%" PRIi64, size);
+  ADD_ARG (argv, i, size_str);
+  ADD_ARG (argv, i, subvolume_buf);
+  ADD_ARG (argv, i, NULL);
+
+  r = commandv (&out, &err, argv);
+  if (r == -1) {
+    reply_with_error ("%s: %s", subvolume, err);
+    return -1;
+  }
+
+  return 0;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index e635ef9..2d8f0a6 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12121,6 +12121,28 @@ Enable or disable subvolume quota support for
filesystem which contains C<path>.
     longdesc = "\
 Trash all qgroup numbers and scan the metadata again with the current
config." };

+  { defaults with
+    name = "btrfs_qgroup_limit";
+    style = RErr, [Pathname "subvolume"; Int64 "size"], [];
+    proc_nr = Some 429;
+    optional = Some "btrfs"; camel_name =
"BTRFSQgroupLimit";
+    tests = [
+      InitPartition, Always, TestRun (
+        [["mkfs_btrfs"; "/dev/sda1"; "";
""; "NOARG"; ""; "NOARG";
"NOARG"; ""; ""];
+         ["mount"; "/dev/sda1"; "/"];
+         ["btrfs_quota_enable"; "/"; "true"];
+         ["btrfs_qgroup_limit"; "/";
"10737418240"]]), [];
+      InitPartition, Always, TestLastFail (
+        [["mkfs_btrfs"; "/dev/sda1"; "";
""; "NOARG"; ""; "NOARG";
"NOARG"; ""; ""];
+         ["mount"; "/dev/sda1"; "/"];
+         ["btrfs_quota_enable"; "/"; "false"];
+         ["btrfs_qgroup_limit"; "/";
"10737418240"]]), [];
+    ];
+    shortdesc = "limit the size of a subvolume";
+    longdesc = "\
+Limit the size of a subvolume which's path is C<subvolume>.
C<size>
+can have suffix of G, M, or K. " };
+
 ]

 (* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 43d371a..3560666 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-428
+429
--
1.9.3