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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux