Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
v3: remove optional paramter numthreads(-t)
v2: add optargs_bitmask check
daemon/btrfs.c | 43 +++++++++++++++++++++++++++++++++++++++++++
generator/actions.ml | 22 ++++++++++++++++++++++
src/MAX_PROC_NR | 2 +-
3 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index fabb00b..39392f7 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -37,6 +37,7 @@ GUESTFSD_EXT_CMD(str_btrfstune, btrfstune);
GUESTFSD_EXT_CMD(str_btrfsck, btrfsck);
GUESTFSD_EXT_CMD(str_mkfs_btrfs, mkfs.btrfs);
GUESTFSD_EXT_CMD(str_umount, umount);
+GUESTFSD_EXT_CMD(str_btrfsimage, btrfs-image);
int
optgroup_btrfs_available (void)
@@ -2040,3 +2041,45 @@ do_btrfstune_enable_skinny_metadata_extent_refs (const char
*device)
return 0;
}
+
+int
+do_btrfs_image (char *const *sources, const char *image,
+ int compresslevel)
+{
+ size_t nr_sources = count_strings (sources);
+ const size_t MAX_ARGS = 64 + nr_sources;
+ const char *argv[MAX_ARGS];
+ size_t i = 0, j;
+ CLEANUP_FREE char *err = NULL;
+ CLEANUP_FREE char *out = NULL;
+ char compresslevel_s[64];
+ int r;
+
+ if (nr_sources == 0) {
+ reply_with_error ("list of sources must be non-empty");
+ return -1;
+ }
+
+ ADD_ARG (argv, i, str_btrfsimage);
+
+ if ((optargs_bitmask & GUESTFS_BTRFS_IMAGE_COMPRESSLEVEL_BITMASK)
+ && compresslevel >= 0) {
+ snprintf (compresslevel_s, sizeof compresslevel_s, "%d", compresslevel);
+ ADD_ARG (argv, i, "-c");
+ ADD_ARG (argv, i, compresslevel_s);
+ }
+
+ for (j = 0; j < nr_sources; ++j)
+ ADD_ARG (argv, i, sources[j]);
+
+ ADD_ARG (argv, i, image);
+ ADD_ARG (argv, i, NULL);
+
+ r = commandv (&out, &err, argv);
+ if (r == -1) {
+ reply_with_error ("%s %s: %s", sources[0], image, err);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index 786b9a2..5e462a8 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12527,6 +12527,28 @@ This will Enable extended inode refs." };
longdesc = "\
This enable skinny metadata extent refs." };
+ { defaults with
+ name = "btrfs_image";
+ style = RErr, [DeviceList "source"; Pathname "image"], [OInt
"compresslevel"];
+ proc_nr = Some 453;
+ optional = Some "btrfs"; camel_name = "BTRFSImage";
+ tests = [
+ InitPartition, Always, TestRun (
+ [["part_init"; "/dev/sda"; "mbr"];
+ ["part_add"; "/dev/sda"; "p"; "64";
"204799"];
+ ["part_add"; "/dev/sda"; "p"; "204800";
"409599"];
+ ["mkfs_btrfs"; "/dev/sda1"; ""; "";
"NOARG"; ""; "NOARG"; "NOARG"; "";
""];
+ ["mkfs_btrfs"; "/dev/sda2"; ""; "";
"NOARG"; ""; "NOARG"; "NOARG"; "";
""];
+ ["mount"; "/dev/sda1"; "/"];
+ ["btrfs_image"; "/dev/sda2"; "/1.img";
""];
+ ["btrfs_image"; "/dev/sda2"; "/2.img";
"2"]]), []
+ ];
+
+ shortdesc = "create an image of a btrfs filesystem";
+ longdesc = "\
+This is used to create an image of a btrfs filesystem.
+All data will be zeroed, but metadata and the like is preserved." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 8670c73..534b992 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-452
+453
--
2.1.0