[Libguestfs] [PATCH libguestfs 1/1] launch: libvirt, direct: Add force_tcg backend setting.
Sam Eiderman
sameid at google.com
Sun Mar 14 15:35:51 UTC 2021
Obviously commit title is wrong - meant to be "force_kvm" :-) (copied
from the commits that added force_tcg)
On Sun, Mar 14, 2021 at 5:34 PM Sam Eiderman <sameid at google.com> wrote:
>
> By using:
>
> export LIBGUESTFS_BACKEND_SETTINGS=force_kvm
>
> you can force the backend to use KVM and never fall back to
> TCG (software emulation).
> ---
> lib/launch-direct.c | 22 +++++++++++++++++++---
> lib/launch-libvirt.c | 12 +++++++++++-
> 2 files changed, 30 insertions(+), 4 deletions(-)
>
> diff --git a/lib/launch-direct.c b/lib/launch-direct.c
> index b6ed9766f..79e6ef2fd 100644
> --- a/lib/launch-direct.c
> +++ b/lib/launch-direct.c
> @@ -385,6 +385,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
> struct hv_param *hp;
> bool has_kvm;
> int force_tcg;
> + int force_kvm;
> const char *cpu_model;
> CLEANUP_FREE char *append = NULL;
> CLEANUP_FREE_STRING_LIST char **argv = NULL;
> @@ -434,8 +435,22 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
> if (force_tcg == -1)
> return -1;
>
> - if (!has_kvm && !force_tcg)
> - debian_kvm_warning (g);
> + force_kvm = guestfs_int_get_backend_setting_bool (g, "force_kvm");
> + if (force_kvm == -1)
> + return -1;
> +
> + if (force_kvm && force_tcg) {
> + error (g, "Both force_kvm and force_tcg backend settings supplied.");
> + return -1;
> + }
> + if (!has_kvm) {
> + if (!force_tcg)
> + debian_kvm_warning (g);
> + if (force_kvm) {
> + error (g, "force_kvm supplied but kvm not available.");
> + return -1;
> + }
> + }
>
> /* Using virtio-serial, we need to create a local Unix domain socket
> * for qemu to connect to.
> @@ -530,7 +545,8 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
> if (has_kvm && !force_tcg)
> append_list ("gic-version=host");
> #endif
> - append_list_format ("accel=%s", !force_tcg ? "kvm:tcg" : "tcg");
> + append_list_format ("accel=%s", force_kvm ? "kvm" :
> + (!force_tcg ? "kvm:tcg" : "tcg"));
> } end_list ();
>
> cpu_model = guestfs_int_get_cpu_model (has_kvm && !force_tcg);
> diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
> index 6c0cfe937..a56afbdd4 100644
> --- a/lib/launch-libvirt.c
> +++ b/lib/launch-libvirt.c
> @@ -773,6 +773,7 @@ parse_capabilities (guestfs_h *g, const char *capabilities_xml,
> xmlAttrPtr attr;
> size_t seen_qemu, seen_kvm;
> int force_tcg;
> + int force_kvm;
>
> doc = xmlReadMemory (capabilities_xml, strlen (capabilities_xml),
> NULL, NULL, XML_PARSE_NONET);
> @@ -820,11 +821,15 @@ parse_capabilities (guestfs_h *g, const char *capabilities_xml,
> }
> }
>
> + force_kvm = guestfs_int_get_backend_setting_bool (g, "force_kvm");
> + if (force_kvm == -1)
> + return -1;
> +
> /* This was RHBZ#886915: in that case the default libvirt URI
> * pointed to a Xen hypervisor, and so could not create the
> * appliance VM.
> */
> - if (!seen_qemu && !seen_kvm) {
> + if ((!seen_qemu || force_kvm) && !seen_kvm) {
> CLEANUP_FREE char *backend = guestfs_get_backend (g);
>
> error (g,
> @@ -846,6 +851,11 @@ parse_capabilities (guestfs_h *g, const char *capabilities_xml,
> if (force_tcg == -1)
> return -1;
>
> + if (force_kvm && force_tcg) {
> + error (g, "Both force_kvm and force_tcg backend settings supplied.");
> + return -1;
> + }
> +
> if (!force_tcg)
> data->is_kvm = seen_kvm;
> else
> --
> 2.31.0.rc2.261.g7f71774620-goog
>
More information about the Libguestfs
mailing list