[Libguestfs] [PATCH v2 04/11] New API: btrfs_quota_enable

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

btrfs_quota_enable enables or disables quota for btrfs filesystems.

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

diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 9e32e11..195b9ba 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1013,3 +1013,39 @@ do_btrfs_subvolume_show (const char *subvolume)

   return ret.argv;
 }
+
+int
+do_btrfs_quota_enable (const mountable_t *fs, int enable)
+{
+  const size_t MAX_ARGS = 64;
+  const char *argv[MAX_ARGS];
+  size_t i = 0;
+  char *fs_buf = NULL;
+  CLEANUP_FREE char *err = NULL;
+  CLEANUP_FREE char *out = NULL;
+  int r = -1;
+
+  fs_buf = mount (fs);
+  if (fs_buf == NULL)
+    goto error;
+
+  ADD_ARG (argv, i, str_btrfs);
+  ADD_ARG (argv, i, "quota");
+  if (enable)
+    ADD_ARG (argv, i, "enable");
+  else
+    ADD_ARG (argv, i, "disable");
+  ADD_ARG (argv, i, fs_buf);
+  ADD_ARG (argv, i, NULL);
+
+  r = commandv (&out, &err, argv);
+  if (r == -1) {
+    reply_with_error ("%s: %s", fs_buf, err);
+    goto error;
+  }
+
+error:
+  if (fs_buf && umount (fs_buf, fs) != 0)
+    return -1;
+  return r;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index 1ea19f7..9de6b14 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12075,6 +12075,31 @@ Get the default subvolume or snapshot of a filesystem
mounted at C<mountpoint>."
     longdesc = "\
 Return detailed information of the subvolume." };

+  { defaults with
+    name = "btrfs_quota_enable";
+    style = RErr, [Mountable_or_Path "fs"; Bool "enable"],
[];
+    proc_nr = Some 427;
+    optional = Some "btrfs"; camel_name =
"BTRFSQuotaEnable";
+    tests = [
+      InitPartition, Always, TestRun (
+        [["mkfs_btrfs"; "/dev/sda1"; "";
""; "NOARG"; ""; "NOARG";
"NOARG"; ""; ""];
+         ["btrfs_quota_enable"; "/dev/sda1";
"true"]]), [];
+      InitPartition, Always, TestRun (
+        [["mkfs_btrfs"; "/dev/sda1"; "";
""; "NOARG"; ""; "NOARG";
"NOARG"; ""; ""];
+         ["mount"; "/dev/sda1"; "/"];
+         ["btrfs_quota_enable"; "/"; "true"]]),
[];
+      InitPartition, Always, TestRun (
+        [["mkfs_btrfs"; "/dev/sda1"; "";
""; "NOARG"; ""; "NOARG";
"NOARG"; ""; ""];
+         ["btrfs_quota_enable"; "/dev/sda1";
"false"]]), [];
+      InitPartition, Always, TestRun (
+        [["mkfs_btrfs"; "/dev/sda1"; "";
""; "NOARG"; ""; "NOARG";
"NOARG"; ""; ""];
+         ["mount"; "/dev/sda1"; "/"];
+         ["btrfs_quota_enable"; "/"; "false"]]),
[];
+    ];
+    shortdesc = "enable or disable subvolume quota support";
+    longdesc = "\
+Enable or disable subvolume quota support for filesystem which contains
C<path>." };
+
 ]

 (* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 9f51d08..d2a1e59 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-426
+427
--
1.9.3