[Libvirt-cim] [PATCH 10 of 10] EAFP: adopt DevicePool interface changes

Heidi Eckhart heidieck at linux.vnet.ibm.com
Thu Mar 6 12:31:51 UTC 2008


# HG changeset patch
# User Heidi Eckhart <heidieck at linux.vnet.ibm.com>
# Date 1204797490 -3600
# Node ID c342fe8a021484ae95e2ab48ca974ae2e7ca5e8e
# Parent  64e4b5f13878ff7b1ba59bea42709d0cac1c7bbc
EAFP: adopt DevicePool interface changes

- adopted changes to DevicePool interface
- updated resource types
- validate client given device ref

Signed-off-by: Heidi Eckhart <heidieck at linux.vnet.ibm.com>

diff -r 64e4b5f13878 -r c342fe8a0214 src/Virt_ElementAllocatedFromPool.c
--- a/src/Virt_ElementAllocatedFromPool.c	Thu Mar 06 10:58:09 2008 +0100
+++ b/src/Virt_ElementAllocatedFromPool.c	Thu Mar 06 10:58:10 2008 +0100
@@ -45,15 +45,15 @@ static uint16_t class_to_type(const CMPI
         uint16_t type;
 
         if (CMClassPathIsA(_BROKER, ref, "CIM_LogicalDisk", NULL))
-                type = CIM_RASD_TYPE_DISK;
+                type = CIM_RES_TYPE_DISK;
         else if (CMClassPathIsA(_BROKER, ref, "CIM_NetworkPort", NULL))
-                type = CIM_RASD_TYPE_NET;
+                type = CIM_RES_TYPE_NET;
         else if (CMClassPathIsA(_BROKER, ref, "CIM_Memory", NULL))
-                type = CIM_RASD_TYPE_MEM;
+                type = CIM_RES_TYPE_MEM;
         else if (CMClassPathIsA(_BROKER, ref, "CIM_Processor", NULL))
-                type = CIM_RASD_TYPE_PROC;
+                type = CIM_RES_TYPE_PROC;
         else
-                type = 0;
+                type = CIM_RES_TYPE_UNKNOWN;
 
         return type;
 }
@@ -66,12 +66,16 @@ static CMPIStatus vdev_to_pool(const CMP
         uint16_t type;
         const char *id = NULL;
         char *poolid = NULL;
-        virConnectPtr conn = NULL;
         CMPIInstance *pool = NULL;
+        CMPIInstance *inst = NULL;
 
         if (!match_hypervisor_prefix(ref, info))
                 return s;
 
+        s = get_device_by_ref(_BROKER, ref, &inst);
+        if (s.rc != CMPI_RC_OK)
+                goto out;
+
         type = class_to_type(ref);
         if (type == 0) {
                 cu_statusf(_BROKER, &s,
@@ -95,25 +99,14 @@ static CMPIStatus vdev_to_pool(const CMP
                 goto out;
         }
 
-        conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
-        if (conn == NULL)
-                goto out;
-
-        pool = get_pool_by_id(_BROKER, conn, poolid, NAMESPACE(ref));
-        if (pool != NULL) {
-                inst_list_add(list, pool);
-                cu_statusf(_BROKER, &s,
-                           CMPI_RC_OK,
-                           "");
-        } else {
-                cu_statusf(_BROKER, &s,
-                           CMPI_RC_ERR_FAILED,
-                           "Unable to find pool `%s'", poolid);
-        }
+        s = get_pool_by_name(_BROKER, ref, poolid, &pool);
+        if (s.rc != CMPI_RC_OK)
+                goto out;
+
+        inst_list_add(list, pool);
 
  out:
         free(poolid);
-        virConnectClose(conn);
 
         return s;
 }
@@ -172,7 +165,6 @@ static int devs_from_pool(uint16_t type,
 
                 name = virDomainGetName(doms[i]);
 
-                /* FIXME: Get VIRT_DEV_ type here */
                 dom_devices(_BROKER, doms[i], ns, type, &tmp);
 
                 filter_by_pool(list, &tmp, type, poolid);
@@ -199,6 +191,10 @@ static CMPIStatus pool_to_vdev(const CMP
         if (!match_hypervisor_prefix(ref, info))
                 return s;
 
+        s = get_pool_by_ref(_BROKER, ref, &inst);
+        if (s.rc != CMPI_RC_OK)
+                goto out;
+
         if (cu_get_str_path(ref, "InstanceID", &poolid) != CMPI_RC_OK) {
                 cu_statusf(_BROKER, &s,
                            CMPI_RC_ERR_FAILED,
@@ -206,25 +202,16 @@ static CMPIStatus pool_to_vdev(const CMP
                 goto out;
         }
 
-        CU_DEBUG("Got %s\n", poolid);
-
-        type = device_type_from_poolid(poolid);
-        if (type == VIRT_DEV_UNKNOWN) {
+        type = res_type_from_pool_id(poolid);
+        if (type == CIM_RES_TYPE_UNKNOWN) {
                 cu_statusf(_BROKER, &s,
                            CMPI_RC_ERR_FAILED,
                            "Invalid InstanceID or unsupported pool type");
                 goto out;
         }
 
-        s = get_pool_inst(_BROKER, ref, &inst);
-        if ((s.rc != CMPI_RC_OK) || (inst == NULL))
-                goto out;
-
         devs_from_pool(type, ref, poolid, list);
 
-        cu_statusf(_BROKER, &s,
-                   CMPI_RC_OK,
-                   "");
  out:
         return s;
 }




More information about the Libvirt-cim mailing list