]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: Feed hook scripts with domain XML
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 29 Aug 2023 14:25:38 +0000 (16:25 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 4 Sep 2023 09:03:33 +0000 (11:03 +0200)
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>
docs/hooks.rst
src/bhyve/bhyve_process.c

index 4e02ba0f8f7dc157ba7f658611de2b6b746a4f33..bd197c0d6e3319f356ddaa2534f106307c1c4101 100644 (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:
 
index c8e1a10afe4b846442e02a75b6aa4130ff2908f7..41feabcbe78ae9bb4ed83037c5c1e421a3b24937 100644 (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);