Signed-off-by: Pino <caoj.fnst@cn.fujitsu.com> --- daemon/btrfs.c | 29 +++++++++++++++++++++++++++++ generator/actions.ml | 18 ++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/daemon/btrfs.c b/daemon/btrfs.c index 39392f7..7f10792 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -38,6 +38,7 @@ 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); +GUESTFSD_EXT_CMD(str_btrfsconvert, btrfs-convert); int optgroup_btrfs_available (void) @@ -2083,3 +2084,31 @@ do_btrfs_image (char *const *sources, const char *image, return 0; } + +int +do_btrfs_convert (const char *device, int rollback) +{ + const size_t MAX_ARGS = 64; + const char *argv[MAX_ARGS]; + size_t i = 0; + CLEANUP_FREE char *err = NULL; + CLEANUP_FREE char *out = NULL; + int r; + + ADD_ARG (argv, i, str_btrfsconvert); + ADD_ARG (argv, i, device); + + if ((optargs_bitmask & GUESTFS_BTRFS_CONVERT_ROLLBACK_BITMASK) && rollback) + ADD_ARG (argv, i, "-r"); + + ADD_ARG (argv, i, NULL); + + r = commandv (&out, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + return -1; + } + + return 0; +} + diff --git a/generator/actions.ml b/generator/actions.ml index 1a89869..8c83480 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -12579,6 +12579,24 @@ numbered C<partnum> on device C<device>. It returns C<primary>, C<logical>, or C<extended>." }; + { defaults with + name = "btrfs_convert"; + style = RErr, [Device "device"], [OBool "rollback"]; + proc_nr = Some 455; + optional = Some "btrfs"; camel_name = "BTRFSConvert"; + tests = [ + InitEmpty, Always, TestRun ( + [["mkfs"; "ext2"; "/dev/sda"; ""; "NOARG"; ""; ""; "NOARG"]; + ["btrfs_convert"; "/dev/sda"; ""]; + ["btrfs_convert"; "/dev/sda"; "true"]]), [] + ]; + shortdesc = "convert from ext2/3/4 filesystem to btrfs or rollback"; + longdesc = "\ +This is used to convert existed ext2/3/4 to btrfs filesystem, and the original +filesystem image is accessible as from separate subvolume named ext2_saved as file image. + +If you want to rollback to ext2/3/4, set rollback to true." }; + ] (* Non-API meta-commands available only in guestfish. -- 2.1.0