[Libvirt-cim] [PATCH 1 of 3] AC GetInstance() fails with a "Could not get ResourceType" error

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Tue Dec 18 18:39:55 UTC 2007


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1198002754 28800
# Node ID b85641f03ae2507e894311f9b31d197b5acc5a39
# Parent  d6cf74b64c720d65da17bdac2604f7d0f1d31f7e
AC GetInstance() fails with a "Could not get ResourceType" error.

GetInstance() was calling return_alloc_cap(), which in turn called rasd_type_from_classname().  rasd_type_from_classname() is expecting the classname to be one of the supported RASD type classnames, but this doesn't match the AC classname.

Instead, GetInstance() should only return an instance if the supplied InstanceID matches one of the existing instances.  alloc_cap_instances() should be modified to take a InstanceID argument.

Failing query:
wbemcli gi 'http://localhost/root/virt:Xen_AllocationCapabilities.InstanceID="ProcessorPool/0"'

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

diff -r d6cf74b64c72 -r b85641f03ae2 src/Virt_AllocationCapabilities.c
--- a/src/Virt_AllocationCapabilities.c	Mon Dec 17 10:23:40 2007 -0800
+++ b/src/Virt_AllocationCapabilities.c	Tue Dec 18 10:32:34 2007 -0800
@@ -20,6 +20,7 @@
  */
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
 
 #include <cmpidt.h>
 #include <cmpift.h>
@@ -131,7 +132,8 @@ static CMPIStatus alloc_cap_instances(co
                                       const CMPIObjectPath *ref,
                                       const CMPIResult *results,
                                       bool names_only,
-                                      const char **properties)
+                                      const char **properties,
+                                      const char *id)
 {
         int i;
         virConnectPtr conn = NULL;
@@ -139,6 +141,7 @@ static CMPIStatus alloc_cap_instances(co
         struct inst_list alloc_cap_list;
         struct inst_list device_pool_list;
         CMPIStatus s = {CMPI_RC_OK, NULL};
+        const char *inst_id;
 
         CU_DEBUG("In alloc_cap_instances()");
 
@@ -165,6 +168,18 @@ static CMPIStatus alloc_cap_instances(co
         }
 
         for (i = 0; i < device_pool_list.cur; i++) {
+                if (cu_get_str_prop(device_pool_list.list[i],
+                                    "InstanceID", &inst_id) != CMPI_RC_OK) {
+                        cu_statusf(broker, &s,
+                                   CMPI_RC_ERR_FAILED,
+                                   "Error fetching device pool InstanceID");
+                        goto out;
+                }
+                if (id && (!STREQ(inst_id, id))) {
+                        inst_id = NULL;
+                        continue;
+                }
+
                 s = ac_from_pool(broker, ref, 
                                  device_pool_list.list[i], 
                                  &alloc_cap_inst);
@@ -172,6 +187,16 @@ static CMPIStatus alloc_cap_instances(co
                         goto out;
 
                 inst_list_add(&alloc_cap_list, alloc_cap_inst);
+
+                if (id && (STREQ(inst_id, id)))
+                        break;
+        }
+
+        if (id && !inst_id) {
+            cu_statusf(broker, &s,
+                       CMPI_RC_ERR_NOT_FOUND,
+                       "Requested Object could not be found.");
+            goto out; 
         }
 
         if (names_only)
@@ -192,7 +217,22 @@ static CMPIStatus GetInstance(CMPIInstan
                               const CMPIObjectPath *reference,
                               const char **properties)
 {
-        return return_alloc_cap(reference, results, 0);
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        const char* id;
+
+        if (cu_get_str_path(reference, "InstanceID", &id) != CMPI_RC_OK) {
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "No InstanceID specified");
+                return s;
+        }
+
+        return alloc_cap_instances(_BROKER,
+                                   reference,
+                                   results,
+                                   false,
+                                   properties,
+                                   id);
 }
 
 static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self,
@@ -200,7 +240,7 @@ static CMPIStatus EnumInstanceNames(CMPI
                                     const CMPIResult *results,
                                     const CMPIObjectPath *reference)
 {
-        return alloc_cap_instances(_BROKER, reference, results, true, NULL);
+        return alloc_cap_instances(_BROKER, reference, results, true, NULL, NULL);
 }
 
 static CMPIStatus EnumInstances(CMPIInstanceMI *self,
@@ -209,7 +249,7 @@ static CMPIStatus EnumInstances(CMPIInst
                                 const CMPIObjectPath *reference,
                                 const char **properties)
 {
-        return alloc_cap_instances(_BROKER, reference, results, false, properties);
+        return alloc_cap_instances(_BROKER, reference, results, false, properties, NULL);
 }
 
 DEFAULT_CI();




More information about the Libvirt-cim mailing list