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(a)virtuozzo.com>
---
lib/create.c | 5 +++--
lib/guestfs-internal.h | 2 ++
lib/launch-direct.c | 2 ++
lib/launch-libvirt.c | 15 +++++++++------
4 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/lib/create.c b/lib/create.c
index bd4c32ef7..aedfe8670 100644
--- a/lib/create.c
+++ b/lib/create.c
@@ -272,7 +272,8 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t
size,
*/
if (STRNEQ (backingformat, "raw") &&
STRNEQ (backingformat, "qcow2") &&
- STRNEQ (backingformat, "vmdk")) {
+ STRNEQ (backingformat, "vmdk") &&
+ STRNEQ (backingformat, AUTODETECTION_FORMAT)) {
error (g, _("invalid value for backingformat parameter ā%sā"),
backingformat);
return -1;
@@ -321,7 +322,7 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t
size,
CLEANUP_FREE char *p = guestfs_int_qemu_escape_param (g, backingfile);
guestfs_int_add_sprintf (g, &optionsv, "backing_file=%s", p);
}
- if (backingformat)
+ if (backingformat && STRNEQ (backingformat, AUTODETECTION_FORMAT))
guestfs_int_add_sprintf (g, &optionsv, "backing_fmt=%s",
backingformat);
if (preallocation)
guestfs_int_add_sprintf (g, &optionsv, "preallocation=%s",
preallocation);
diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h
index a04ccff09..ba9f13628 100644
--- a/lib/guestfs-internal.h
+++ b/lib/guestfs-internal.h
@@ -168,6 +168,8 @@
#define MACHINE_TYPE "pseries"
#endif
+#define AUTODETECTION_FORMAT "autodetection"
+
/* Guestfs handle and associated structures. */
/* State. */
diff --git a/lib/launch-direct.c b/lib/launch-direct.c
index 4d5d6b996..c2ddfad6a 100644
--- a/lib/launch-direct.c
+++ b/lib/launch-direct.c
@@ -581,7 +581,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_FMT_AUTO
append_list ("format=raw");
+#endif
} end_list ();
start_list ("-device") {
append_list ("scsi-hd");
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
index f66c8e0ef..7b3e539c9 100644
--- a/lib/launch-libvirt.c
+++ b/lib/launch-libvirt.c
@@ -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;
@@ -233,7 +232,7 @@ 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;
+ optargs.backingformat = format ? format : AUTODETECTION_FORMAT;
if (guestfs_disk_create_argv (g, overlay, "qcow2", -1, &optargs) == -1)
{
free (overlay);
@@ -461,7 +460,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) {
+#ifdef APPLIANCE_FMT_AUTO
+ params.appliance_overlay = make_qcow2_overlay (g, appliance, NULL);
+#else
params.appliance_overlay = make_qcow2_overlay (g, appliance, "raw");
+#endif
if (!params.appliance_overlay)
goto cleanup;
}
--
2.13.0