[Libguestfs] [PATCH 7/8] New API: btrfs_qgroup_create

Hu Tao
Tue, 02 Dec 2014 09:33:37 -0000

btrfs_qgroup_create creates a new qgroup.

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

diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 033d460..dccaf5a 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1120,3 +1120,35 @@ int do_btrfs_qgroup_limit (const char *subvolume, const
char *size)

   return 0;
 }
+
+int do_btrfs_qgroup_create (const char *qgroupid, const char *subvolume)
+{
+  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;
+  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, "create");
+  ADD_ARG (argv, i, qgroupid);
+  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 5d64350..608ddf6 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12082,6 +12082,15 @@ Trash all qgroup numbers and scan the metadata again
with the current config." }
 Limit the size of a subvolume which's path is C<subvolume>.
C<size>
 can have suffix of G, M, or K. " };

+  { defaults with
+    name = "btrfs_qgroup_create";
+    style = RErr, [String "qgroupid"; Pathname
"subvolume"], [];
+    proc_nr = Some 431;
+    optional = Some "btrfs"; camel_name =
"BTRFSQgroupCreate";
+    shortdesc = "create a subvolume quota group";
+    longdesc = "\
+Create a quota group (qgroup) for subvolume at C<subvolume>." };
+
 ]

 (* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index c15fb93..ed4f162 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-430
+431
--
1.9.3