Currently, the bhyve driver respects domain's on_poweroff and on_reboot
settings for when shutdown and reboot are triggered via libvirt API.
However, they are not respected when the event is triggered within the
guest. Address that by updating monitor to execute the configured
action.

Signed-off-by: Roman Bogorodskiy <[email protected]>
---
 src/bhyve/bhyve_monitor.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/bhyve/bhyve_monitor.c b/src/bhyve/bhyve_monitor.c
index 8cf4b41ca3..3be5ae89ad 100644
--- a/src/bhyve/bhyve_monitor.c
+++ b/src/bhyve/bhyve_monitor.c
@@ -157,12 +157,24 @@ bhyveMonitorIO(int watch, int kq, int events 
G_GNUC_UNUSED, void *opaque)
         } else if (WIFEXITED(status)) {
             if (WEXITSTATUS(status) == 0 || mon->reboot) {
                 /* 0 - reboot */
-                VIR_INFO("Guest %s rebooted; restarting domain.", name);
-                virBhyveProcessRestart(driver, vm);
+                if (vm->def->onReboot == VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY ||
+                    vm->def->onReboot == VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE) 
{
+                    VIR_INFO("Guest %s rebooted; domain on_reboot setting 
overridden, shutting down.", name);
+                    virBhyveProcessStop(driver, vm, 
VIR_DOMAIN_SHUTOFF_SHUTDOWN);
+                } else {
+                    VIR_INFO("Guest %s rebooted; restarting domain.", name);
+                    virBhyveProcessRestart(driver, vm);
+                }
             } else if (WEXITSTATUS(status) < 3) {
                 /* 1 - shutdown, 2 - halt, 3 - triple fault. others - error */
-                VIR_INFO("Guest %s shut itself down; destroying domain.", 
name);
-                virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
+                if (vm->def->onPoweroff == VIR_DOMAIN_LIFECYCLE_ACTION_RESTART 
||
+                    vm->def->onPoweroff == 
VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME) {
+                    VIR_INFO("Guest %s shut itself down; domain on_poweroff 
setting overridden, attempting reboot.", name);
+                    virBhyveProcessRestart(driver, vm);
+                } else {
+                    VIR_INFO("Guest %s shut itself down; destroying domain.", 
name);
+                    virBhyveProcessStop(driver, vm, 
VIR_DOMAIN_SHUTOFF_SHUTDOWN);
+                }
             } else {
                 VIR_INFO("Guest %s had an error and exited with status %d; 
destroying domain.",
                          name, WEXITSTATUS(status));
-- 
2.52.0

Reply via email to