bhyve: Feed hook scripts with domain XML

Domain related hook scripts are all fed with domain XML on their
stdin, except for bhyve. Fix this.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/528
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2023-08-29 16:25:38 +02:00
parent 4e73f50b1e
commit ad8c4d9d6d
2 changed files with 29 additions and 16 deletions

View File

@ -92,9 +92,9 @@ Script arguments
The hook scripts are called with specific command line arguments, depending upon
the script, and the operation being performed.
The guest hook scripts, qemu, lxc and libxl are also given the **full** XML
description for the domain on their stdin. This includes items such the UUID of
the domain and its storage information, and is intended to provide all the
The guest hook scripts, qemu, lxc, libxl and bhyve are also given the **full**
XML description for the domain on their stdin. This includes items such the UUID
of the domain and its storage information, and is intended to provide all the
libvirt information the script needs.
For all cases, stdin of the network hook script is provided with the full XML
@ -129,8 +129,8 @@ followed with the full XML description of the port:
</hookData>
Please note that this approach is different from other cases such as ``daemon``,
``qemu``, ``lxc`` or ``libxl`` hook scripts, because two XMLs may be passed
here, while in the other cases only a single XML is passed.
``qemu``, ``lxc``, ``libxl`` or ``bhyve`` hook scripts, because two XMLs may be
passed here, while in the other cases only a single XML is passed.
The command line arguments take this approach:

View File

@ -94,21 +94,34 @@ virBhyveFormatDevMapFile(const char *vm_name, char **fn_out)
}
static int
bhyveProcessStartHook(virDomainObj *vm, virHookBhyveOpType op)
bhyveProcessStartHook(struct _bhyveConn *driver,
virDomainObj *vm,
virHookBhyveOpType op)
{
g_autofree char *xml = NULL;
if (!virHookPresent(VIR_HOOK_DRIVER_BHYVE))
return 0;
xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
return virHookCall(VIR_HOOK_DRIVER_BHYVE, vm->def->name, op,
VIR_HOOK_SUBOP_BEGIN, NULL, NULL, NULL);
VIR_HOOK_SUBOP_BEGIN, NULL, xml, NULL);
}
static void
bhyveProcessStopHook(virDomainObj *vm, virHookBhyveOpType op)
bhyveProcessStopHook(struct _bhyveConn *driver,
virDomainObj *vm,
virHookBhyveOpType op)
{
if (virHookPresent(VIR_HOOK_DRIVER_BHYVE))
virHookCall(VIR_HOOK_DRIVER_BHYVE, vm->def->name, op,
VIR_HOOK_SUBOP_END, NULL, NULL, NULL);
g_autofree char *xml = NULL;
if (!virHookPresent(VIR_HOOK_DRIVER_BHYVE))
return;
xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
virHookCall(VIR_HOOK_DRIVER_BHYVE, vm->def->name, op,
VIR_HOOK_SUBOP_END, NULL, xml, NULL);
}
static int
@ -194,7 +207,7 @@ virBhyveProcessStartImpl(struct _bhyveConn *driver,
goto cleanup;
}
if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_START) < 0)
if (bhyveProcessStartHook(driver, vm, VIR_HOOK_BHYVE_OP_START) < 0)
goto cleanup;
/* Now we can start the domain */
@ -216,7 +229,7 @@ virBhyveProcessStartImpl(struct _bhyveConn *driver,
BHYVE_STATE_DIR) < 0)
goto cleanup;
if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_STARTED) < 0)
if (bhyveProcessStartHook(driver, vm, VIR_HOOK_BHYVE_OP_STARTED) < 0)
goto cleanup;
ret = 0;
@ -265,7 +278,7 @@ virBhyveProcessStart(virConnectPtr conn,
struct _bhyveConn *driver = conn->privateData;
/* Run an early hook to setup missing devices. */
if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0)
if (bhyveProcessStartHook(driver, vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0)
return -1;
if (flags & VIR_BHYVE_PROCESS_START_AUTODESTROY)
@ -307,7 +320,7 @@ virBhyveProcessStop(struct _bhyveConn *driver,
if ((priv != NULL) && (priv->mon != NULL))
bhyveMonitorClose(priv->mon);
bhyveProcessStopHook(vm, VIR_HOOK_BHYVE_OP_STOPPED);
bhyveProcessStopHook(driver, vm, VIR_HOOK_BHYVE_OP_STOPPED);
/* Cleanup network interfaces */
bhyveNetCleanup(vm);
@ -329,7 +342,7 @@ virBhyveProcessStop(struct _bhyveConn *driver,
vm->pid = 0;
vm->def->id = -1;
bhyveProcessStopHook(vm, VIR_HOOK_BHYVE_OP_RELEASE);
bhyveProcessStopHook(driver, vm, VIR_HOOK_BHYVE_OP_RELEASE);
cleanup:
virPidFileDelete(BHYVE_STATE_DIR, vm->def->name);