Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
daemon/btrfs.c | 38 ++++++++++++++++++++++++++++++++++++++
generator/actions.ml | 22 ++++++++++++++++++++++
src/MAX_PROC_NR | 2 +-
3 files changed, 61 insertions(+), 1 deletion(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index be648bc..e036880 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -2054,3 +2054,41 @@ do_btrfs_image (char *const *sources, const char *image,
return 0;
}
+
+int
+do_btrfs_image_restore (const char *image, char *const *sources)
+{
+ 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;
+ int r;
+
+ if (nr_sources == 0) {
+ reply_with_error ("list of sources must be non-empty");
+ return -1;
+ }
+
+ ADD_ARG (argv, i, str_btrfsimage);
+ ADD_ARG (argv, i, "-r");
+
+ if (nr_sources > 1)
+ ADD_ARG (argv, i, "-m");
+
+ ADD_ARG (argv, i, image);
+
+ for (j = 0; j < nr_sources; ++j)
+ ADD_ARG (argv, i, sources[j]);
+
+ ADD_ARG (argv, i, NULL);
+
+ r = commandv (&out, &err, argv);
+ if (r == -1) {
+ reply_with_error ("%s %s: %s", image, sources[0], err);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index 090f797..c4c882e 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12545,6 +12545,28 @@ This used to create an image of a btrfs filesystem.
All data will be zeroed, but metadata and the like is preserved." };
+ { defaults with
+ name = "btrfs_image_restore";
+ style = RErr, [Pathname "image"; DeviceList "source"], [];
+ proc_nr = Some 454;
+ 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"];
+ ["part_add"; "/dev/sda"; "p"; "409600";
"614399"];
+ ["mkfs_btrfs"; "/dev/sda1"; ""; "";
"NOARG"; ""; "NOARG"; "NOARG"; "";
""];
+ ["mkfs_btrfs"; "/dev/sda2 /dev/sda3"; "";
""; "NOARG"; ""; "NOARG"; "NOARG";
""; ""];
+ ["mount"; "/dev/sda1"; "/"];
+ ["btrfs_image"; "/dev/sda2"; "/1.img";
""; ""];
+ ["btrfs_image_restore"; "/1.img"; "/dev/sda2
/dev/sda3"]]), []
+ ];
+
+ shortdesc = "restore metadump image to btrfs filesystem";
+ longdesc = "\
+This used to restore metadump image to btrfs filesystem."};
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 534b992..515f19a 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-453
+454
--
2.1.0