[libvirt] [PATCH v2 5/9] bhyve: start using virDomainObjCheckActive

Clementine Hayat posted 9 patches 7 years ago
[libvirt] [PATCH v2 5/9] bhyve: start using virDomainObjCheckActive
Posted by Clementine Hayat 7 years ago
Signed-off-by: Clementine Hayat <clem@lse.epita.fr>
---
 src/bhyve/bhyve_driver.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 24c4a9c80..8aff0c65c 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -883,11 +883,8 @@ bhyveDomainCreateWithFlags(virDomainPtr dom,
     if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    if (virDomainObjIsActive(vm)) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       "%s", _("Domain is already running"));
+    if (virDomainObjCheckActive(vm) < 0)
         goto cleanup;
-    }
 
     ret = virBhyveProcessStart(dom->conn, privconn, vm,
                                VIR_DOMAIN_RUNNING_BOOTED,
@@ -996,11 +993,8 @@ bhyveDomainDestroy(virDomainPtr dom)
     if (virDomainDestroyEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    if (!virDomainObjIsActive(vm)) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       "%s", _("Domain is not running"));
+    if (virDomainObjCheckActive(vm) < 0)
         goto cleanup;
-    }
 
     ret = virBhyveProcessStop(privconn, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
     event = virDomainEventLifecycleNewFromObj(vm,
@@ -1031,11 +1025,8 @@ bhyveDomainShutdown(virDomainPtr dom)
     if (virDomainShutdownEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    if (!virDomainObjIsActive(vm)) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       "%s", _("Domain is not running"));
+    if (virDomainObjCheckActive(vm) < 0)
         goto cleanup;
-    }
 
     ret = virBhyveProcessShutdown(vm);
 
@@ -1062,11 +1053,8 @@ bhyveDomainOpenConsole(virDomainPtr dom,
     if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    if (!virDomainObjIsActive(vm)) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       "%s", _("domain is not running"));
+    if (virDomainObjCheckActive(vm) < 0)
         goto cleanup;
-    }
 
     if (!vm->def->nserials) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-- 
2.17.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 5/9] bhyve: start using virDomainObjCheckActive
Posted by Ján Tomko 7 years ago
On Tue, Apr 17, 2018 at 10:13:30PM +0000, Clementine Hayat wrote:
>Signed-off-by: Clementine Hayat <clem@lse.epita.fr>
>---
> src/bhyve/bhyve_driver.c | 20 ++++----------------
> 1 file changed, 4 insertions(+), 16 deletions(-)
>
>diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
>index 24c4a9c80..8aff0c65c 100644
>--- a/src/bhyve/bhyve_driver.c
>+++ b/src/bhyve/bhyve_driver.c
>@@ -883,11 +883,8 @@ bhyveDomainCreateWithFlags(virDomainPtr dom,
>     if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0)
>         goto cleanup;
>
>-    if (virDomainObjIsActive(vm)) {
>-        virReportError(VIR_ERR_OPERATION_INVALID,
>-                       "%s", _("Domain is already running"));
>+    if (virDomainObjCheckActive(vm) < 0)
>         goto cleanup;
>-    }
>
>     ret = virBhyveProcessStart(dom->conn, privconn, vm,
>                                VIR_DOMAIN_RUNNING_BOOTED,

This hunk is incorrect - it would reverse the logic.

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list