
# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1194283579 28800 # Node ID 0ae96e2255c9d6b095b3cbdcbb247621a8abd91a # Parent fa10054ee62b6f5bb7fc3f832464e4d6caf6f274 Make ResourcePoolConfigurationService return errors when appropriate and fix up some other general error-handling around the needed changes. This includes a use of the (now controversial) cu_compare_ref() function, so I won't commit this until we come to a decision about it, but the act of checking the reference is something we need to do here, no matter how it shakes out. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r fa10054ee62b -r 0ae96e2255c9 src/Virt_ResourcePoolConfigurationService.c --- a/src/Virt_ResourcePoolConfigurationService.c Mon Nov 05 06:59:19 2007 -0800 +++ b/src/Virt_ResourcePoolConfigurationService.c Mon Nov 05 09:26:19 2007 -0800 @@ -89,7 +89,8 @@ DEFAULT_EQ(); DEFAULT_EQ(); DEFAULT_INST_CLEANUP(); -static CMPIInstance *rpcs_instance(const CMPIObjectPath *reference) +static CMPIStatus rpcs_instance(const CMPIObjectPath *reference, + CMPIInstance **_inst) { CMPIInstance *inst; CMPIInstance *host; @@ -98,28 +99,47 @@ static CMPIInstance *rpcs_instance(const s = get_host_cs(_BROKER, reference, &host); if (s.rc != CMPI_RC_OK) - return NULL; + goto out; inst = get_typed_instance(_BROKER, "ResourcePoolConfigurationService", NAMESPACE(reference)); + if (inst == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get " + "ResourcePoolConfigurationService instance"); + goto out; + } CMSetProperty(inst, "Name", (CMPIValue *)"RPCS", CMPI_chars); prop = CMGetProperty(host, "CreationClassName", &s); - if (s.rc != CMPI_RC_OK) - return NULL; + if (s.rc != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get CreationClassName from HostSystem"); + goto out; + } + CMSetProperty(inst, "SystemCreationClassName", (CMPIValue *)&prop.value.string, CMPI_string); prop = CMGetProperty(host, "Name", NULL); - if (s.rc != CMPI_RC_OK) - return NULL; + if (s.rc != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Name from HostSystem"); + goto out; + } + CMSetProperty(inst, "SystemName", (CMPIValue *)&prop.value.string, CMPI_string); - return inst; + *_inst = inst; + out: + return s; } static CMPIStatus GetInstance(CMPIInstanceMI *self, @@ -129,12 +149,30 @@ static CMPIStatus GetInstance(CMPIInstan const char **properties) { CMPIInstance *inst; - - inst = rpcs_instance(reference); - - CMReturnInstance(results, inst); - - return (CMPIStatus){CMPI_RC_OK, NULL}; + CMPIStatus s; + const struct cu_property *prop; + static struct cu_property props[] = { + {"CreationClassName", 0}, + {"SystemCreationClassName", 0}, + {"SystemName", 0}, + {"Name", 1}, + {NULL, 0} + }; + + s = rpcs_instance(reference, &inst); + if (s.rc != CMPI_RC_OK) + return s; + + prop = cu_compare_ref(reference, inst, props); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop->name); + } else { + CMReturnInstance(results, inst); + } + + return s; } static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, @@ -143,12 +181,13 @@ static CMPIStatus EnumInstanceNames(CMPI const CMPIObjectPath *reference) { CMPIInstance *inst; - - inst = rpcs_instance(reference); - - cu_return_instance_name(results, inst); - - return (CMPIStatus){CMPI_RC_OK, NULL}; + CMPIStatus s; + + s = rpcs_instance(reference, &inst); + if (s.rc == CMPI_RC_OK) + cu_return_instance_name(results, inst); + + return s; } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -159,12 +198,13 @@ static CMPIStatus EnumInstances(CMPIInst { CMPIInstance *inst; - - inst = rpcs_instance(reference); - - CMReturnInstance(results, inst); - - return (CMPIStatus){CMPI_RC_OK, NULL}; + CMPIStatus s; + + s = rpcs_instance(reference, &inst); + if (s.rc == CMPI_RC_OK) + CMReturnInstance(results, inst); + + return s; }