[Libvirt-cim] [PATCH 02 of 12] Make DevicePool use connect_by_classname()

Dan Smith danms at us.ibm.com
Mon Nov 19 16:52:53 UTC 2007


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1195491890 28800
# Node ID 59abf0e63644d8c306492645f9291718c35e40d5
# Parent  7a114401c8ede2268fb291d713c0b1e4715b0b8d
Make DevicePool use connect_by_classname()

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

diff -r 7a114401c8ed -r 59abf0e63644 src/Virt_DevicePool.c
--- a/src/Virt_DevicePool.c	Mon Nov 19 08:59:59 2007 -0800
+++ b/src/Virt_DevicePool.c	Mon Nov 19 09:04:50 2007 -0800
@@ -148,7 +148,9 @@ static char *_diskpool_member_of(const c
         return pool;
 }
 
-static char *diskpool_member_of(const CMPIBroker *broker, char *rasd_id)
+static char *diskpool_member_of(const CMPIBroker *broker,
+                                const char *rasd_id,
+                                const char *refcn)
 {
         char *host = NULL;
         char *dev = NULL;
@@ -165,7 +167,7 @@ static char *diskpool_member_of(const CM
         if (!ret)
                 goto out;
 
-        conn = lv_connect(broker, &s);
+        conn = connect_by_classname(broker, refcn, &s);
         if (conn == NULL)
                 goto out;
 
@@ -194,7 +196,9 @@ static char *diskpool_member_of(const CM
         return pool;
 }
 
-static char *netpool_member_of(const CMPIBroker *broker, char *rasd_id)
+static char *netpool_member_of(const CMPIBroker *broker,
+                               const char *rasd_id,
+                               const char *refcn)
 {
         char *host = NULL;
         char *dev = NULL;
@@ -211,7 +215,7 @@ static char *netpool_member_of(const CMP
         if (!ret)
                 goto out;
 
-        conn = lv_connect(broker, &s);
+        conn = connect_by_classname(broker, refcn, &s);
         if (conn == NULL)
                 goto out;
 
@@ -243,7 +247,10 @@ static char *netpool_member_of(const CMP
         return result;
 }
 
-char *pool_member_of(const CMPIBroker *broker, uint16_t type, char *id)
+char *pool_member_of(const CMPIBroker *broker,
+                     const char *refcn,
+                     uint16_t type,
+                     const char *id)
 {
         char *poolid = NULL;
 
@@ -252,9 +259,9 @@ char *pool_member_of(const CMPIBroker *b
         else if (type == CIM_RASD_TYPE_MEM)
                 poolid = strdup("MemoryPool/0");
         else if (type == CIM_RASD_TYPE_NET)
-                poolid = netpool_member_of(broker, id);
+                poolid = netpool_member_of(broker, id, refcn);
         else if (type == CIM_RASD_TYPE_DISK)
-                poolid = diskpool_member_of(broker, id);
+                poolid = diskpool_member_of(broker, id, refcn);
         else
                 return NULL;
 
@@ -630,7 +637,7 @@ static CMPIStatus return_pool(const CMPI
 
         inst_list_init(&list);
 
-        conn = lv_connect(_BROKER, &s);
+        conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
         if (conn == NULL)
                 goto out;
 
@@ -691,7 +698,7 @@ static CMPIStatus GetInstance(CMPIInstan
                 goto out;
         }
 
-        conn = lv_connect(_BROKER, &s);
+        conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s);
         if (conn == NULL)
                 goto out;
 
diff -r 7a114401c8ed -r 59abf0e63644 src/Virt_DevicePool.h
--- a/src/Virt_DevicePool.h	Mon Nov 19 08:59:59 2007 -0800
+++ b/src/Virt_DevicePool.h	Mon Nov 19 09:04:50 2007 -0800
@@ -39,7 +39,21 @@ CMPIInstance *get_pool_by_id(const CMPIB
                              const char *id,
                              const char *ns);
 
-char *pool_member_of(const CMPIBroker *broker, uint16_t type, char *id);
+
+/**
+ * Get the InstanceID of a pool that a given RASD id (for type) is in
+ *
+ * @param broker The current Broker
+ * @param refcn A reference classname to be used for libvirt
+ *              connections.  This can be anything as long as the
+ *              prefix is correct.
+ * @param type The ResourceType of the RASD
+ * @param id The InstanceID of the RASD
+ */
+char *pool_member_of(const CMPIBroker *broker,
+                     const char *refcn,
+                     uint16_t type,
+                     const char *id);
 
 #endif
 
diff -r 7a114401c8ed -r 59abf0e63644 src/Virt_ElementAllocatedFromPool.c
--- a/src/Virt_ElementAllocatedFromPool.c	Mon Nov 19 08:59:59 2007 -0800
+++ b/src/Virt_ElementAllocatedFromPool.c	Mon Nov 19 09:04:50 2007 -0800
@@ -84,7 +84,7 @@ static CMPIStatus vdev_to_pool(const CMP
                 goto out;
         }
 
-        poolid = pool_member_of(_BROKER, type, id);
+        poolid = pool_member_of(_BROKER, CLASSNAME(ref), type, id);
         if (poolid == NULL) {
                 cu_statusf(_BROKER, &s,
                            CMPI_RC_ERR_FAILED,
@@ -120,21 +120,27 @@ static int filter_by_pool(struct inst_li
                           const char *_poolid)
 {
         int i;
-        char *dev_id = NULL;
         char *poolid = NULL;
 
         for (i = 0; i < src->cur; i++) {
                 CMPIInstance *inst = src->list[i];
-
+                char *cn = NULL;
+                char *dev_id = NULL;
+
+                cu_get_str_prop(inst, "CreationClassName", &cn);
                 cu_get_str_prop(inst, "DeviceID", &dev_id);
 
+                if ((dev_id == NULL) || (cn == NULL))
+                        goto end;
+
                 printf("Device %hhi:%s", type, dev_id);
 
-                poolid = pool_member_of(_BROKER, type, dev_id);
+                poolid = pool_member_of(_BROKER, cn, type, dev_id);
                 if (poolid && STREQ(poolid, _poolid))
                         inst_list_add(dest, inst);
-
+        end:
                 free(dev_id);
+                free(cn);
         }
 
         return dest->cur;
diff -r 7a114401c8ed -r 59abf0e63644 src/Virt_ResourceAllocationFromPool.c
--- a/src/Virt_ResourceAllocationFromPool.c	Mon Nov 19 08:59:59 2007 -0800
+++ b/src/Virt_ResourceAllocationFromPool.c	Mon Nov 19 09:04:50 2007 -0800
@@ -66,7 +66,7 @@ static CMPIStatus rasd_to_pool(const CMP
                 goto out;
         }
 
-        poolid = pool_member_of(_BROKER, type, id);
+        poolid = pool_member_of(_BROKER, CLASSNAME(ref), type, id);
         if (poolid == NULL) {
                 cu_statusf(_BROKER, &s,
                            CMPI_RC_ERR_FAILED,
@@ -123,7 +123,7 @@ static int filter_by_pool(struct inst_li
 
                 cu_get_str_prop(inst, "InstanceID", &rasd_id);
 
-                poolid = pool_member_of(_BROKER, type, rasd_id);
+                poolid = pool_member_of(_BROKER, CLASSNAME(op), type, rasd_id);
                 if (STREQ(poolid, _poolid))
                         inst_list_add(dest, inst);
 




More information about the Libvirt-cim mailing list