From fd6263df75ea1e0957e9c94b6a68a508b3835548 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 17 Mar 2026 14:49:10 +0000 Subject: [PATCH] lib: Change guestfs_get_hv to report backend default hypervisor Change the implementation of guestfs_get_hv so that if a custom hypervisor was not set (eg. by an earlier call to guestfs_set_hv) then we will return the default hypervisor reported by the backend. This changes the API slightly because we can now return an error here in the libvirt backend case if the appliance has not been launched yet. --- generator/actions_properties.ml | 8 ++++++-- lib/handle.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/generator/actions_properties.ml b/generator/actions_properties.ml index 61fca197a..c6474763f 100644 --- a/generator/actions_properties.ml +++ b/generator/actions_properties.ml @@ -59,8 +59,12 @@ the qemu binary at the same time as the handle is created.|} }; longdesc = "\ Return the current hypervisor binary. -This is always non-NULL. If it wasn't set already, then this will -return the default qemu binary name." }; +If it wasn't set already, then this will return the default +qemu binary name. + +For some backends this may return an error if called before +launch since it may not be possible to get the default hypervisor +before the appliance is launched." }; { defaults with name = "set_path"; added = (0, 0, 3); diff --git a/lib/handle.c b/lib/handle.c index 12fbf800e..ab0e1289e 100644 --- a/lib/handle.c +++ b/lib/handle.c @@ -575,7 +575,21 @@ guestfs_impl_set_hv (guestfs_h *g, const char *hv) char * guestfs_impl_get_hv (guestfs_h *g) { - return safe_strdup (g, g->hv); + if (g->hv) + return safe_strdup (g, g->hv); + else { + /* Try to return the default hypervisor. */ + const char *default_hv; + + if (g->backend_ops && g->backend_data && + (default_hv = g->backend_ops->get_default_hv (g, g->backend_data)) + != NULL) + return safe_strdup (g, default_hv); + else { + error (g, _("cannot get default hypervisor")); + return NULL; + } + } } int