mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
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:
committed by
Richard W.M. Jones
parent
dd4e95c636
commit
40fcb3e4d2
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user