Currently, the bhyve driver shutdown implementation
does not take into account domain's on_poweroff action.
Update it so it reboots a domain on shutdown when it is
configured this way.

Signed-off-by: Roman Bogorodskiy <[email protected]>
---
 src/bhyve/bhyve_driver.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 2e7a534396..1f904d8958 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1077,18 +1077,30 @@ bhyveDomainShutdownFlags(virDomainPtr dom, unsigned int 
flags)
 {
     virDomainObj *vm;
     int ret = -1;
+    bhyveDomainObjPrivate *priv;
+    bool isReboot = false;
 
     virCheckFlags(0, -1);
 
     if (!(vm = bhyveDomObjFromDomain(dom)))
         goto cleanup;
 
+    if (vm->def->onPoweroff == VIR_DOMAIN_LIFECYCLE_ACTION_RESTART ||
+        vm->def->onPoweroff == VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME) {
+        isReboot = true;
+        VIR_INFO("Domain on_poweroff setting overridden, attempting reboot");
+    }
+
     if (virDomainShutdownFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
         goto cleanup;
 
     if (virDomainObjCheckActive(vm) < 0)
         goto cleanup;
 
+    if (isReboot) {
+        priv = vm->privateData;
+        bhyveMonitorSetReboot(priv->mon);
+    }
     ret = virBhyveProcessShutdown(vm);
 
  cleanup:
-- 
2.52.0

Reply via email to