[PATCH 0 of 2] Move two classes to cu_compare_ref()

The first patch removes the internal reference key checking from VSMS in favor of the libcmpiutil generic one. The second makes ComputerSystem do similar checking. If this looks good to people, we'll want to do this for (probably) all of the instance providers.

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1194042668 25200 # Node ID 6e04d2c0c3a88a4bb991438f9ea02a1ad4596820 # Parent d48584b1c90c499dea3940c1718ef0e97ae5ef9e Make VSMS.GetInstance use the standardized ref checker in libcmpiutil Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r d48584b1c90c -r 6e04d2c0c3a8 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Fri Nov 02 10:28:30 2007 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Fri Nov 02 15:31:08 2007 -0700 @@ -1022,32 +1022,6 @@ static CMPIStatus EnumInstances(CMPIInst return return_vsms(reference, results, 0); } -static int compare_prop(const CMPIObjectPath *ref, - const CMPIInstance *inst, - const char *name, - int mandatory) -{ - char *prop = NULL; - char *key = NULL; - int rc = 0; - - key = cu_get_str_path(ref, name); - if (key == NULL) { - rc = !mandatory; - goto out; - } - - if (cu_get_str_prop(inst, name, &prop) != CMPI_RC_OK) - goto out; - - rc = STREQ(key, prop); - out: - free(prop); - free(key); - - return rc; -} - static CMPIStatus GetInstance(CMPIInstanceMI *self, const CMPIContext *context, const CMPIResult *results, @@ -1056,19 +1030,25 @@ static CMPIStatus GetInstance(CMPIInstan { CMPIInstance *inst; CMPIStatus s; + const struct cu_property *prop; + static struct cu_property props[] = { + {"CreationClassName", 0}, + {"SystemName", 0}, + {"SystemCreationClassName", 0}, + {"Name", 1}, + {NULL, 0} + }; s = _get_vsms(ref, &inst, 0); if (s.rc != CMPI_RC_OK) return s; - if (!compare_prop(ref, inst, "CreationClassName", 0) || - !compare_prop(ref, inst, "SystemName", 0) || - !compare_prop(ref, inst, "Name", 1) || - !compare_prop(ref, inst, "SystemCreationClassName", 0)) + prop = cu_compare_ref(ref, inst, props); + if (prop != NULL) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_NOT_FOUND, - "No such instance"); - else { + "No such instance (%s)", prop->name); + } else { CMSetStatus(&s, CMPI_RC_OK); CMReturnInstance(results, inst); }

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1194042669 25200 # Node ID 8ddace706d4a00e3097553e734dd1842aca0a97a # Parent 6e04d2c0c3a88a4bb991438f9ea02a1ad4596820 Make ComputerSystem.GetInstance() check its reference properly Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 6e04d2c0c3a8 -r 8ddace706d4a src/Virt_ComputerSystem.c --- a/src/Virt_ComputerSystem.c Fri Nov 02 15:31:08 2007 -0700 +++ b/src/Virt_ComputerSystem.c Fri Nov 02 15:31:09 2007 -0700 @@ -377,6 +377,12 @@ static CMPIStatus get_domain(const CMPIO CMPIInstance *inst[2] = {NULL, NULL}; CMPIStatus s; virConnectPtr conn = NULL; + const struct cu_property *prop; + static struct cu_property props[] = { + {"CreationClassName", 0}, + {"Name", 1}, + {NULL, 0} + }; conn = lv_connect(_BROKER, &s); if (conn == NULL) @@ -387,6 +393,14 @@ static CMPIStatus get_domain(const CMPIO cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Unable to find `%s'", name); + goto out; + } + + prop = cu_compare_ref(reference, inst[0], props); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop->name); goto out; }

Dan Smith wrote:
The first patch removes the internal reference key checking from VSMS in favor of the libcmpiutil generic one. The second makes ComputerSystem do similar checking. If this looks good to people, we'll want to do this for (probably) all of the instance providers.
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
Both of these look fine to me (including the error handling =) +1 -- Kaitlin Rupert IBM Linux Technology Center karupert@us.ibm.com
participants (2)
-
Dan Smith
-
Kaitlin Rupert