[Libvirt-cim] [PATCH 2 of 2] Replace large if-else in EAFP

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Thu Dec 20 18:14:59 UTC 2007


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1198174440 28800
# Node ID 84eb3549e19956d912684a09d58631211724a720
# Parent  ddf699b9cf98f9258b8959676dcd915b24d25a3d
Replace large if-else in EAFP.

This can be handled using device_type_from_poolid() instead.

Also replaced printf() with CU_DEBUG().

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r ddf699b9cf98 -r 84eb3549e199 src/Virt_ElementAllocatedFromPool.c
--- a/src/Virt_ElementAllocatedFromPool.c	Thu Dec 20 10:04:03 2007 -0800
+++ b/src/Virt_ElementAllocatedFromPool.c	Thu Dec 20 10:14:00 2007 -0800
@@ -31,6 +31,7 @@
 #include <libcmpiutil/std_association.h>
 #include "misc_util.h"
 #include "cs_util.h"
+#include "device_parsing.h"
 
 #include "Virt_DevicePool.h"
 #include "Virt_Device.h"
@@ -200,6 +201,7 @@ static CMPIStatus pool_to_vdev(const CMP
 {
         const char *poolid;
         CMPIStatus s = {CMPI_RC_OK, NULL};
+        uint16_t type;
 
         if (!match_hypervisor_prefix(ref, info))
                 return s;
@@ -211,35 +213,18 @@ static CMPIStatus pool_to_vdev(const CMP
                 goto out;
         }
 
-        printf("Got %s\n", poolid);
-
-        /* FIXME, make this shared with the RAFP version */
-        if (STARTS_WITH(poolid, "ProcessorPool"))
-                devs_from_pool(CIM_RASD_TYPE_PROC,
-                               ref,
-                               poolid,
-                               list);
-        else if (STARTS_WITH(poolid, "MemoryPool"))
-                devs_from_pool(CIM_RASD_TYPE_MEM,
-                               ref,
-                               poolid,
-                               list);
-        else if (STARTS_WITH(poolid, "NetworkPool"))
-                devs_from_pool(CIM_RASD_TYPE_NET,
-                               ref,
-                               poolid,
-                               list);
-        else if (STARTS_WITH(poolid, "DiskPool"))
-                devs_from_pool(CIM_RASD_TYPE_DISK,
-                               ref,
-                               poolid,
-                               list);
-        else {
+        CU_DEBUG("Got %s\n", poolid);
+
+        type = device_type_from_poolid(poolid);
+        if (type == VIRT_DEV_UNKNOWN) {
                 cu_statusf(_BROKER, &s,
                            CMPI_RC_ERR_FAILED,
                            "Invalid InstanceID or unsupported pool type");
                 goto out;
         }
+
+
+        devs_from_pool(type, ref, poolid, list);
 
         CMSetStatus(&s, CMPI_RC_OK);
 




More information about the Libvirt-cim mailing list