[Libguestfs] [PATCH 1/5] btrfs: add optional parameter `ro' to btrfs_subvolume_snapshot

Hu Tao hutao at cn.fujitsu.com
Wed Nov 26 09:04:04 UTC 2014


Parameter `ro' is for creating readonly btrfs snapshot.

Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---
 daemon/btrfs.c       |  8 +++++++-
 generator/actions.ml | 13 ++++++++-----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 7a4d43d..9b48a5d 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -208,7 +208,7 @@ do_mkfs_btrfs (char *const *devices,
 }
 
 int
-do_btrfs_subvolume_snapshot (const char *source, const char *dest)
+do_btrfs_subvolume_snapshot (const char *source, const char *dest, int ro)
 {
   const size_t MAX_ARGS = 64;
   const char *argv[MAX_ARGS];
@@ -231,6 +231,12 @@ do_btrfs_subvolume_snapshot (const char *source, const char *dest)
   ADD_ARG (argv, i, str_btrfs);
   ADD_ARG (argv, i, "subvolume");
   ADD_ARG (argv, i, "snapshot");
+
+  /* Optional arguments. */
+  if ((optargs_bitmask & GUESTFS_BTRFS_SUBVOLUME_SNAPSHOT_RO_BITMASK) &&
+      ro)
+    ADD_ARG (argv, i, "-r");
+
   ADD_ARG (argv, i, source_buf);
   ADD_ARG (argv, i, dest_buf);
   ADD_ARG (argv, i, NULL);
diff --git a/generator/actions.ml b/generator/actions.ml
index baa7679..47a98e3 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -10217,8 +10217,9 @@ See C<guestfs_get_e2generation>." };
 
   { defaults with
     name = "btrfs_subvolume_snapshot";
-    style = RErr, [Pathname "source"; Pathname "dest"], [];
+    style = RErr, [Pathname "source"; Pathname "dest"], [OBool "ro"];
     proc_nr = Some 322;
+    once_had_no_optargs = true;
     optional = Some "btrfs"; camel_name = "BTRFSSubvolumeSnapshot";
     tests = [
       InitPartition, Always, TestRun (
@@ -10228,13 +10229,15 @@ See C<guestfs_get_e2generation>." };
          ["btrfs_subvolume_create"; "/test1"];
          ["btrfs_subvolume_create"; "/test2"];
          ["btrfs_subvolume_create"; "/dir/test3"];
-         ["btrfs_subvolume_snapshot"; "/dir/test3"; "/dir/test4"]]), []
+         ["btrfs_subvolume_snapshot"; "/dir/test3"; "/dir/test5"; "true"]]), []
     ];
-    shortdesc = "create a writable btrfs snapshot";
+    shortdesc = "create a btrfs snapshot";
     longdesc = "\
-Create a writable snapshot of the btrfs subvolume C<source>.
+Create a snapshot of the btrfs subvolume C<source>.
 The C<dest> argument is the destination directory and the name
-of the snapshot, in the form C</path/to/dest/name>." };
+of the snapshot, in the form C</path/to/dest/name>. By default
+the newly created snapshot is writable, if the value of optional
+parameter C<ro> is true, then a readonly snapshot is created." };
 
   { defaults with
     name = "btrfs_subvolume_delete";
-- 
1.9.3




More information about the Libguestfs mailing list