[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH v2] 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>
---
 lib/launch-direct.c     |  2 ++
 lib/launch-libvirt.c    | 19 ++++++++++++-------
 m4/guestfs_appliance.m4 | 11 +++++++++++
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/lib/launch-direct.c b/lib/launch-direct.c
index 0be662e25..b9b54857a 100644
--- a/lib/launch-direct.c
+++ b/lib/launch-direct.c
@@ -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_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 4adb2cfb3..030ea6911 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;
 
@@ -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) {
+#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;
   }
diff --git a/m4/guestfs_appliance.m4 b/m4/guestfs_appliance.m4
index 81c43879f..4e1ec8135 100644
--- a/m4/guestfs_appliance.m4
+++ b/m4/guestfs_appliance.m4
@@ -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-fmt-auto],
+    [AS_HELP_STRING([--enable-appliance-fmt-auto],
+        [enable autodetection of appliance image format @<:@default=no@:>@])],
+        [ENABLE_APPLIANCE_FMT_AUTO="$enableval"],
+        [ENABLE_APPLIANCE_FMT_AUTO=no])
+
+if test "x$ENABLE_APPLIANCE_FMT_AUTO" = "xyes"; then
+    AC_DEFINE([APPLIANCE_FMT_AUTO], [1],
+        [Define to 1 if enabled autodetection of appliance image format.])
+fi
-- 
2.13.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]