[PATCH 0/2] support 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. In accordance with the discussion (https://www.redhat.com/archives/libguestfs/2017-June/msg00230.html) Pavel Butsykin (2): launch: add support for autodetection of appliance image format build: add ./configure --enable-appliance-fmt-auto option lib/create.c | 5 +++-- lib/guestfs-internal.h | 2 ++ lib/launch-direct.c | 2 ++ lib/launch-libvirt.c | 15 +++++++++------ m4/guestfs_appliance.m4 | 11 +++++++++++ 5 files changed, 27 insertions(+), 8 deletions(-) -- 2.13.0
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/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
On Fri, Jun 23, 2017 at 04:12:35PM +0300, Pavel Butsykin wrote:
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/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;
I think this is patch is against an older version of libguestfs? The current code has: if (optargs->bitmask & GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK) { backingformat = optargs->backingformat; if (!VALID_FORMAT (backingformat)) { error (g, _("invalid value for backingformat parameter ‘%s’"), backingformat); return -1; } } so this hunk can just be omitted.
@@ -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);
backingformat is an optional parameter (controlled by ‘optargs->bitmask & GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK’), so just don't pass it, rather than defining new API. Then ...
@@ -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;
... here, instead of passing "autodetection" (new API), you would conditionally set the GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK flag in the previous line.
+#ifdef APPLIANCE_FMT_AUTO
What would define this? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
On 26.06.2017 00:29, Richard W.M. Jones wrote:
On Fri, Jun 23, 2017 at 04:12:35PM +0300, Pavel Butsykin wrote:
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/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;
I think this is patch is against an older version of libguestfs? The current code has:
if (optargs->bitmask & GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK) { backingformat = optargs->backingformat; if (!VALID_FORMAT (backingformat)) { error (g, _("invalid value for backingformat parameter ‘%s’"), backingformat); return -1; } }
so this hunk can just be omitted.
will fix.
@@ -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);
backingformat is an optional parameter (controlled by ‘optargs->bitmask & GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK’), so just don't pass it, rather than defining new API. Then ...
@@ -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;
... here, instead of passing "autodetection" (new API), you would conditionally set the GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK flag in the previous line.
Thanks, will fix.
+#ifdef APPLIANCE_FMT_AUTO
What would define this?
/* Define to 1 if enabled autodetection of appliance image format. */ #define APPLIANCE_FMT_AUTO 1 and /* #define APPLIANCE_FMT_AUTO 1 */ if the option is disabled. So made the most of the options in config.h
Rich.
Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com> --- m4/guestfs_appliance.m4 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/m4/guestfs_appliance.m4 b/m4/guestfs_appliance.m4 index 81c43879f..7e8d28271 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
On Fri, Jun 23, 2017 at 04:12:36PM +0300, Pavel Butsykin wrote:
Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com> --- m4/guestfs_appliance.m4 | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/m4/guestfs_appliance.m4 b/m4/guestfs_appliance.m4 index 81c43879f..7e8d28271 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
Might as well combine this with the previous patch. No need for two patches as the first one depends on the second. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
participants (2)
-
Pavel Butsykin -
Richard W.M. Jones