[Libvirt-cim] [PATCH] Make DestroySystem actually undefine a domain as it should

Dan Smith danms at us.ibm.com
Fri Mar 28 20:35:10 UTC 2008


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1206736474 25200
# Node ID 1e1c2cd2ef0bff684df37d5c94d7b66b6189295c
# Parent  2eaed9da089f7b49d85eadeb75334c11c869ffc8
Make DestroySystem actually undefine a domain as it should

Also clean up the error path and CMPIValue stuff in the method while
we're swizzling

Signed-off-by: Dan Smith <danms at us.ibm.com>

diff -r 2eaed9da089f -r 1e1c2cd2ef0b src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Fri Mar 28 07:20:02 2008 -0700
+++ b/src/Virt_VirtualSystemManagementService.c	Fri Mar 28 13:34:34 2008 -0700
@@ -479,54 +479,56 @@ static CMPIStatus destroy_system(CMPIMet
                                  CMPIArgs *argsout)
 {
         const char *dom_name = NULL;
-        CMPIStatus status = {CMPI_RC_OK, NULL};
-        CMPIValue rc;
+        CMPIStatus status;
+        uint32_t rc = IM_RC_FAILED;
         CMPIObjectPath *sys;
-
-        virConnectPtr conn;
+        virConnectPtr conn = NULL;
+        virDomainPtr dom = NULL;
 
         conn = connect_by_classname(_BROKER,
                                     CLASSNAME(reference),
                                     &status);
-        if (conn == NULL) {
-                rc.uint32 = IM_RC_FAILED;
-                goto error1;
-        }
-
-        if (cu_get_ref_arg(argsin, "AffectedSystem", &sys) != CMPI_RC_OK) {
-                rc.uint32 = IM_RC_FAILED;
-                goto error2;
-        }
+        if (conn == NULL)
+                goto error;
+
+        if (cu_get_ref_arg(argsin, "AffectedSystem", &sys) != CMPI_RC_OK)
+                goto error;
 
         dom_name = get_key_from_ref_arg(argsin, "AffectedSystem", "Name");
-        if (dom_name == NULL) {
-                rc.uint32 = IM_RC_FAILED;
-                goto error2;
-        }
+        if (dom_name == NULL)
+                goto error;
 
         // Make sure system exists and destroy it.
-        if (domain_exists(conn, dom_name)) {
-                virDomainPtr dom = virDomainLookupByName(conn, dom_name);
-                if (!virDomainDestroy(dom)) {
-                        rc.uint32 = IM_RC_OK;
-                } else {
-                        rc.uint32 = IM_RC_FAILED;
-                        cu_statusf(_BROKER, &status,
-                                   CMPI_RC_ERR_FAILED,
-                                   "Domain already exists");
-                }
-                virDomainFree(dom);
+        if (!domain_exists(conn, dom_name))
+                goto error;
+
+        dom = virDomainLookupByName(conn, dom_name);
+        if (dom == NULL) {
+                CU_DEBUG("No such domain `%s', dom_name");
+                rc = IM_RC_SYS_NOT_FOUND;
+                goto error;
+        }
+
+        virDomainDestroy(dom); /* Okay for this to fail */
+        if (virDomainUndefine(dom) == 0) {
+                rc = IM_RC_OK;
                 trigger_indication(context,
                                    "ComputerSystemDeletedIndication",
                                    NAMESPACE(reference));
-        } else {
-                rc.uint32 = IM_RC_SYS_NOT_FOUND;
-        }
-
- error2:
+        }
+
+error:
+        if (rc == IM_RC_SYS_NOT_FOUND)
+                cu_statusf(_BROKER, &status,
+                           CMPI_RC_ERR_FAILED,
+                           "Failed to find domain");
+        else if (rc == IM_RC_OK)
+                status = (CMPIStatus){CMPI_RC_OK, NULL};
+
+        virDomainFree(dom);
         virConnectClose(conn);
- error1:
         CMReturnData(results, &rc, CMPI_uint32);
+
         return status;
 }
 




More information about the Libvirt-cim mailing list