[PATCH 0/3] bhyve: Feed hook scripts with domain XML

*** BLURB HERE *** Michal Prívozník (3): docs: Document that libxl hooks are also given full domain XML docs: Document bhyve hook scripts bhyve: Feed hook scripts with domain XML docs/hooks.rst | 56 +++++++++++++++++++++++++++++++++++---- src/bhyve/bhyve_process.c | 35 ++++++++++++++++-------- 2 files changed, 75 insertions(+), 16 deletions(-) -- 2.41.0

Our hooks.rst document existence of libxl hook scripts, but mentions only qemu and lxc as receivers of full domain XML. But since their introduction in v2.2.0-rc1~201 they are also given full domain XML. Fix our wording. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/hooks.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/hooks.rst b/docs/hooks.rst index 9387676a55..b127ec4202 100644 --- a/docs/hooks.rst +++ b/docs/hooks.rst @@ -89,7 +89,7 @@ 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 and lxc, are also given the **full** XML +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 libvirt information the script needs. @@ -126,8 +126,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`` or ``lxc`` hook scripts, because two XMLs may be passed here, while in -the other cases only a single XML is passed. +``qemu``, ``lxc`` or ``libxl`` 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: -- 2.41.0

We have bhyve hook scripts since v6.1.0-rc1~42 but never mention them in hooks.rst. Fill the blanks. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/hooks.rst | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/hooks.rst b/docs/hooks.rst index b127ec4202..4e02ba0f8f 100644 --- a/docs/hooks.rst +++ b/docs/hooks.rst @@ -20,6 +20,7 @@ occur: - A QEMU guest is started or stopped ( :since:`since 0.8.0` ) - An LXC guest is started or stopped ( :since:`since 0.8.0` ) - A libxl-handled Xen guest is started or stopped ( :since:`since 2.1.0` ) +- An bhyve guest is started or stopped ( :since:`since 6.1.0` ) - A network is started or stopped or an interface is plugged/unplugged to/from the network ( :since:`since 1.2.2` ) @@ -53,6 +54,8 @@ At present, there are five hook scripts that can be called: Executed when an LXC guest is started or stopped - ``/etc/libvirt/hooks/libxl`` Executed when a libxl-handled Xen guest is started, stopped, or migrated +- ``/etc/libvirt/hooks/bhyve`` + Executed when an bhyve guest is started or stopped - ``/etc/libvirt/hooks/network`` Executed when a network is started or stopped or an interface is plugged/unplugged to/from the network @@ -393,6 +396,49 @@ operation. There is no specific operation to indicate a "restart" is occurring. /etc/libvirt/hooks/libxl guest_name reconnect begin - +/etc/libvirt/hooks/bhyve +^^^^^^^^^^^^^^^^^^^^^^^^ + +- | Before an bhyve guest is started, the bhyve hook script is called in three + locations; if any location fails, the guest is not started. The first + location, :since:`since 6.1.0` , is before libvirt performs any resource + labeling, and the hook can allocate resources not managed by libvirt. This is + called as: + + :: + + /etc/libvirt/hooks/bhyve guest_name prepare begin - + + | The second location, available :since:`Since 6.1.0` , occurs after libvirt + has finished labeling all resources, but has not yet started the guest, + called as: + + :: + + /etc/libvirt/hooks/bhyve guest_name start begin - + + | The third location, :since:`6.1.0` , occurs after the bhyve process has + successfully started up: + + :: + + /etc/libvirt/hooks/bhyve guest_name started begin - + +- | When an bhyve guest is stopped, the bhyve hook script is called in two + locations, to match the startup. First, :since:`since 6.1.0` , the hook is + called before libvirt restores any labels: + + :: + + /etc/libvirt/hooks/bhyve guest_name stopped end - + + | Then, after libvirt has released all resources, the hook is called again, + :since:`since 6.1.0` , to allow any additional resource cleanup: + + :: + + /etc/libvirt/hooks/bhyve guest_name release end - + /etc/libvirt/hooks/network ^^^^^^^^^^^^^^^^^^^^^^^^^^ -- 2.41.0

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> --- docs/hooks.rst | 10 +++++----- src/bhyve/bhyve_process.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/docs/hooks.rst b/docs/hooks.rst index 4e02ba0f8f..bd197c0d6e 100644 --- a/docs/hooks.rst +++ b/docs/hooks.rst @@ -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: diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 80d5a8804f..d476ff401f 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -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); -- 2.41.0

On a Tuesday in 2023, Michal Privoznik wrote:
*** BLURB HERE ***
Michal Prívozník (3): docs: Document that libxl hooks are also given full domain XML docs: Document bhyve hook scripts bhyve: Feed hook scripts with domain XML
docs/hooks.rst | 56 +++++++++++++++++++++++++++++++++++---- src/bhyve/bhyve_process.c | 35 ++++++++++++++++-------- 2 files changed, 75 insertions(+), 16 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Michal Privoznik