
# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203681287 -3600 # Node ID d67ec3ae8446a3c9e68b36e511f63ef292689a8c # Parent 46e9fe0ea3e8dca8ad930b77f8171f744928f00c RASD: add function get_rasd_by_ref() for usage in associations Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 46e9fe0ea3e8 -r d67ec3ae8446 src/Virt_RASD.c --- a/src/Virt_RASD.c Fri Feb 22 10:54:01 2008 +0100 +++ b/src/Virt_RASD.c Fri Feb 22 12:54:47 2008 +0100 @@ -357,38 +357,92 @@ static CMPIInstance *rasd_from_vdev(cons return inst; } -CMPIInstance *get_rasd_instance(const CMPIContext *context, - const CMPIObjectPath *ref, - const CMPIBroker *broker, - const char *id, - const uint16_t type) +CMPIStatus get_rasd_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + const uint16_t type, + CMPIInstance **_inst) { CMPIInstance *inst = NULL; - CMPIStatus s; + CMPIStatus s = {CMPI_RC_OK, NULL}; int ret; char *host = NULL; char *devid = NULL; virConnectPtr conn = NULL; struct virt_device *dev; - ret = parse_fq_devid((char *)id, &host, &devid); - if (!ret) - return NULL; - - conn = connect_by_classname(broker, CLASSNAME(ref), &s); - if (conn == NULL) - goto out; + conn = connect_by_classname(broker, CLASSNAME(reference), &s); + if (conn == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance"); + goto out; + } + + ret = parse_fq_devid((char *)name, &host, &devid); + if (ret != 1) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", + name); + goto out; + } dev = find_dev(conn, type, host, devid); - if (dev) - inst = rasd_from_vdev(broker, dev, host, ref); - + if (!dev) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", + name); + goto out; + } + + inst = rasd_from_vdev(broker, dev, host, reference); + if (inst == NULL) + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to set instance properties"); + else + *_inst = inst; + out: virConnectClose(conn); free(host); free(devid); - return inst; + return s; +} + +CMPIStatus get_rasd_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *name = NULL; + uint16_t type; + + if (cu_get_str_path(reference, "InstanceID", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing InstanceID"); + goto out; + } + + if (rasd_type_from_classname(CLASSNAME(reference), &type) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to determine RASD type"); + goto out; + } + + s = get_rasd_by_name(broker, reference, name, type, _inst); + if (s.rc != CMPI_RC_OK) + goto out; + + s = cu_validate_ref(broker, reference, *_inst); + + out: + return s; } CMPIrc rasd_type_from_classname(const char *cn, uint16_t *type) @@ -544,32 +598,14 @@ static CMPIStatus GetInstance(CMPIInstan const char **properties) { CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *inst; - const char *id = NULL; - uint16_t type; - - if (cu_get_str_path(ref, "InstanceID", &id) != CMPI_RC_OK) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Missing InstanceID"); - goto out; - } - - if (rasd_type_from_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unable to determine RASD type"); - goto out; - } - - inst = get_rasd_instance(context, ref, _BROKER, id, type); - - if (inst != NULL) - CMReturnInstance(results, inst); - else - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_NOT_FOUND, - "No such instance (%s)", id); + CMPIInstance *inst = NULL; + + s = get_rasd_by_ref(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + CMReturnInstance(results, inst); + out: return s; } diff -r 46e9fe0ea3e8 -r d67ec3ae8446 src/Virt_RASD.h --- a/src/Virt_RASD.h Fri Feb 22 10:54:01 2008 +0100 +++ b/src/Virt_RASD.h Fri Feb 22 12:54:47 2008 +0100 @@ -42,11 +42,15 @@ CMPIrc rasd_type_from_classname(const ch CMPIrc rasd_type_from_classname(const char *cn, uint16_t *type); CMPIrc rasd_classname_from_type(uint16_t type, const char **cn); -CMPIInstance *get_rasd_instance(const CMPIContext *context, - const CMPIObjectPath *ref, - const CMPIBroker *broker, - const char *id, - const uint16_t type); +CMPIStatus get_rasd_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + const uint16_t type, + CMPIInstance **_inst); + +CMPIStatus get_rasd_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst); #endif