mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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.
This commit is contained in:
committed by
rwmjones
parent
ce4bfa5d08
commit
fd6263df75
@@ -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);
|
||||
|
||||
16
lib/handle.c
16
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
|
||||
|
||||
Reference in New Issue
Block a user