launch: add support for autodetection of appliance image format

This feature allows you to use different image formats for the fixed
appliance. The raw format is used by default.

Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
This commit is contained in:
Pavel Butsykin
2017-06-27 19:42:20 +03:00
committed by Richard W.M. Jones
parent dd4e95c636
commit 40fcb3e4d2
3 changed files with 25 additions and 7 deletions

View File

@@ -592,7 +592,9 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
append_list ("id=appliance");
append_list ("cache=unsafe");
append_list ("if=none");
#ifndef APPLIANCE_FORMAT_AUTO
append_list ("format=raw");
#endif
} end_list ();
start_list ("-device") {
append_list ("scsi-hd");

View File

@@ -212,9 +212,10 @@ get_source_format_or_autodetect (guestfs_h *g, struct drive *drv)
/**
* Create a qcow2 format overlay, with the given C<backing_drive>
* (file). The C<format> parameter, which must be non-NULL, is the
* backing file format. This is used to create the appliance overlay,
* and also for read-only drives.
* (file). The C<format> parameter is the backing file format.
* The C<format> parameter can be NULL, in this case the backing
* format will be determined automatically. This is used to create
* the appliance overlay, and also for read-only drives.
*/
static char *
make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
@@ -223,8 +224,6 @@ make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
char *overlay;
struct guestfs_disk_create_argv optargs;
assert (format != NULL);
if (guestfs_int_lazy_make_tmpdir (g) == -1)
return NULL;
@@ -232,8 +231,10 @@ make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
optargs.bitmask = GUESTFS_DISK_CREATE_BACKINGFILE_BITMASK;
optargs.backingfile = backing_drive;
optargs.bitmask |= GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK;
optargs.backingformat = format;
if (format) {
optargs.bitmask |= GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK;
optargs.backingformat = format;
}
if (guestfs_disk_create_argv (g, overlay, "qcow2", -1, &optargs) == -1) {
free (overlay);
@@ -461,7 +462,11 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
/* Note that appliance can be NULL if using the old-style appliance. */
if (appliance) {
#ifndef APPLIANCE_FORMAT_AUTO
params.appliance_overlay = make_qcow2_overlay (g, appliance, "raw");
#else
params.appliance_overlay = make_qcow2_overlay (g, appliance, NULL);
#endif
if (!params.appliance_overlay)
goto cleanup;
}

View File

@@ -139,3 +139,14 @@ AC_SUBST([GUESTFS_DEFAULT_PATH])
AC_DEFINE_UNQUOTED([GUESTFS_DEFAULT_PATH], ["$GUESTFS_DEFAULT_PATH"],
[Define guestfs default path.])
AC_ARG_ENABLE([appliance-format-auto],
[AS_HELP_STRING([--enable-appliance-format-auto],
[enable autodetection of appliance image format @<:@default=no@:>@])],
[ENABLE_APPLIANCE_FORMAT_AUTO="$enableval"],
[ENABLE_APPLIANCE_FORMAT_AUTO=no])
if test "x$ENABLE_APPLIANCE_FORMAT_AUTO" = "xyes"; then
AC_DEFINE([APPLIANCE_FORMAT_AUTO], [1],
[Define to 1 if enabled autodetection of appliance image format.])
fi