The bhyveDomainShutdownFlags() and bhyveDomainReboot()
already exit early if virDomainObjCheckActive(vm) < 0.
With the suspended it's not enough, so make sure that the
domain is actually running.

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 bae1961036..05b20c0cf8 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1137,6 +1137,12 @@ bhyveDomainShutdownFlags(virDomainPtr dom, unsigned int 
flags)
     if (virDomainObjCheckActive(vm) < 0)
         goto cleanup;
 
+    if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("domain is not running"));
+        goto cleanup;
+    }
+
     agentForced = agentRequested && !signalRequested;
     if (useAgent) {
         ret = bhyveDomainShutdownFlagsAgent(vm, isReboot, agentForced);
@@ -1202,6 +1208,12 @@ bhyveDomainReboot(virDomainPtr dom, unsigned int flags)
     if (virDomainObjCheckActive(vm) < 0)
         goto cleanup;
 
+    if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("domain is not running"));
+        goto cleanup;
+    }
+
     agentForced = agentRequested && !signalRequested;
     if (useAgent) {
         ret = bhyveDomainRebootAgent(vm, isReboot, agentForced);
-- 
2.56.0

Reply via email to