[Libvirt-cim] [PATCH] Change cu_compare_ref() to be a little lighter-weight

Dan Smith danms at us.ibm.com
Wed Nov 7 15:40:56 UTC 2007


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1194453648 28800
# Node ID 926009fc62a0080bcf93aaddf098b074ce71a096
# Parent  404c4803b1b542676c4d283226a7cc3b7f3ab58d
Change cu_compare_ref() to be a little lighter-weight
Now, we just check the keys that were provided by the client (or the CIMOM
if that ever starts to happen).  We will have already checked the required
keys to actually do the lookup in the provider, which serves the "required"
key purpose.  Changes to libvirt-cim to follow shortly...

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

diff -r 404c4803b1b5 -r 926009fc62a0 instance_util.c
--- a/instance_util.c	Fri Nov 02 15:29:38 2007 -0700
+++ b/instance_util.c	Wed Nov 07 08:40:48 2007 -0800
@@ -88,38 +88,48 @@ static bool _compare_data(const CMPIData
         return false;
 }
 
-const struct cu_property *cu_compare_ref(const CMPIObjectPath *ref,
-                                         const CMPIInstance *inst,
-                                         const struct cu_property *props)
+const char *cu_compare_ref(const CMPIObjectPath *ref,
+                           const CMPIInstance *inst)
 {
-        const struct cu_property *p = NULL;
         int i;
         CMPIStatus s;
+        int count;
+        const char *prop = NULL;
 
-        for (i = 0; props[i].name != NULL; i++) {
+        count = CMGetKeyCount(ref, &s);
+        if (s.rc != CMPI_RC_OK) {
+                CU_DEBUG("Unable to get key count");
+                return NULL;
+        }
+
+        for (i = 0; i < count; i++) {
                 CMPIData kd, pd;
+                CMPIString *str;
 
-                p = &props[i];
-
-                kd = CMGetKey(ref, p->name, &s);
+                kd = CMGetKeyAt(ref, i, &str, &s);
                 if (s.rc != CMPI_RC_OK) {
-                        if (p->required)
-                                goto out;
-                        else
-                                continue;
+                        CU_DEBUG("Failed to get key %i", i);
+                        goto out;
                 }
 
-                pd = CMGetProperty(inst, p->name, &s);
-                if (s.rc != CMPI_RC_OK)
+                prop = CMGetCharPtr(str);
+                CU_DEBUG("Comparing key `%s'", prop);
+
+                pd = CMGetProperty(inst, prop, &s);
+                if (s.rc != CMPI_RC_OK) {
+                        CU_DEBUG("Failed to get property `%s'", prop);
                         goto out;
+                }
 
-                if (!_compare_data(&kd, &pd))
+                if (!_compare_data(&kd, &pd)) {
+                        CU_DEBUG("No data match for `%s'", prop);
                         goto out;
+                }
         }
 
-        p = NULL;
+        prop = NULL;
  out:
-        return p;
+        return prop;
 }
 
 /*
diff -r 404c4803b1b5 -r 926009fc62a0 libcmpiutil.h
--- a/libcmpiutil.h	Fri Nov 02 15:29:38 2007 -0700
+++ b/libcmpiutil.h	Wed Nov 07 08:40:48 2007 -0800
@@ -337,26 +337,17 @@ void inst_list_free(struct inst_list *li
  */
 int inst_list_add(struct inst_list *list, CMPIInstance *inst);
 
-struct cu_property {
-        const char *name;
-        bool required;
-};
-
 /**
  * Compare key values in a reference to properties in an instance,
- * making sure they are identical.  If props identifies a particular
- * key as not required, then absence in the object path will not
- * result in failure of this test.
+ * making sure they are identical.
  *
  * @param ref The ObjectPath to examine
  * @param inst The Instance to compare
- * @param props A NULL-terminated list of properties to compare
- * @returns A pointer to the property structure of the first
- *          non-matching property, or NULL if all match
- */
-const struct cu_property *cu_compare_ref(const CMPIObjectPath *ref,
-                                         const CMPIInstance *inst,
-                                         const struct cu_property *props);
+ * @returns A pointer to the name of the first non-matching property,
+ *          or NULL if all match
+ */
+const char *cu_compare_ref(const CMPIObjectPath *ref,
+                           const CMPIInstance *inst);
 
 #define DEFAULT_EIN(pn)                                                 \
         static CMPIStatus pn##EnumInstanceNames(CMPIInstanceMI *self,   \




More information about the Libvirt-cim mailing list