[PATCH 0 of 5] Add get_rasd_... functions to RASD and adopt interface changes to assocs

Added get_rasd_by_ref() and get_rasd_by_name() to RASD provider to clean up / fasten the access to a specific RASD instance. This interface change has been adopted by the appropriate associaton providers, who need this access.

# 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

HE> + s = get_rasd_by_name(broker, reference, name, type, _inst); HE> + if (s.rc != CMPI_RC_OK) HE> + goto out; HE> + HE> + s = cu_validate_ref(broker, reference, *_inst); HE> + HE> + out: HE> + return s; HE> } Potentially the same change is required here, depending on your thoughts on my previous comment :) -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203681290 -3600 # Node ID acb930f1a7c5886d906e30b524d09d4844bbffa3 # Parent d67ec3ae8446a3c9e68b36e511f63ef292689a8c VSMS: adopt interface changes of RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r d67ec3ae8446 -r acb930f1a7c5 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Fri Feb 22 12:54:47 2008 +0100 +++ b/src/Virt_VirtualSystemManagementService.c Fri Feb 22 12:54:50 2008 +0100 @@ -1000,7 +1000,7 @@ static CMPIStatus rasd_refs_to_insts(con CMPIArray *arr, CMPIArray **ret_arr) { - CMPIStatus s; + CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIArray *tmp_arr; int i; int c; @@ -1017,7 +1017,7 @@ static CMPIStatus rasd_refs_to_insts(con for (i = 0; i < c; i++) { CMPIData d; CMPIObjectPath *ref; - CMPIInstance *inst; + CMPIInstance *inst = NULL; const char *id; uint16_t type; @@ -1041,21 +1041,18 @@ static CMPIStatus rasd_refs_to_insts(con continue; } - inst = get_rasd_instance(ctx, reference, _BROKER, id, type); - if (inst != NULL) - CMSetArrayElementAt(tmp_arr, i, - &inst, - CMPI_instance); - else - CU_DEBUG("Failed to get instance for `%s'", - REF2STR(ref)); - } - - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); + s = get_rasd_by_name(_BROKER, reference, id, type, &inst); + if (s.rc != CMPI_RC_OK) + continue; + + CMSetArrayElementAt(tmp_arr, i, + &inst, + CMPI_instance); + + } + *ret_arr = tmp_arr; - + return s; }

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203681291 -3600 # Node ID e12a643f2af88b12b3031de23bb3fd5698badaba # Parent acb930f1a7c5886d906e30b524d09d4844bbffa3 SDS: adopt interface changes of RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r acb930f1a7c5 -r e12a643f2af8 src/Virt_SettingsDefineState.c --- a/src/Virt_SettingsDefineState.c Fri Feb 22 12:54:50 2008 +0100 +++ b/src/Virt_SettingsDefineState.c Fri Feb 22 12:54:51 2008 +0100 @@ -159,6 +159,7 @@ static CMPIStatus rasd_to_dev(const CMPI { CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *dev = NULL; + CMPIInstance *inst = NULL; const char *id = NULL; uint16_t type; @@ -178,6 +179,10 @@ static CMPIStatus rasd_to_dev(const CMPI "Missing ResourceType"); goto out; } + + s = get_rasd_by_name(_BROKER, ref, id, type, &inst); + if (s.rc != CMPI_RC_OK) + goto out; dev = _get_typed_device(id, type, ref, &s); if (dev == NULL) @@ -185,9 +190,6 @@ static CMPIStatus rasd_to_dev(const CMPI inst_list_add(list, dev); - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); out: return s; }

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203681292 -3600 # Node ID d31116669eb24e1ff8691a33b4c1d5a91421fd20 # Parent e12a643f2af88b12b3031de23bb3fd5698badaba RAFP: adopt interface changes to RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r e12a643f2af8 -r d31116669eb2 src/Virt_ResourceAllocationFromPool.c --- a/src/Virt_ResourceAllocationFromPool.c Fri Feb 22 12:54:51 2008 +0100 +++ b/src/Virt_ResourceAllocationFromPool.c Fri Feb 22 12:54:52 2008 +0100 @@ -37,28 +37,6 @@ const static CMPIBroker *_BROKER; -static CMPIStatus validate_rasd_ref(const CMPIContext *context, - const CMPIObjectPath *ref, - uint16_t type, - const char *id) -{ - CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *rasd = NULL; - - rasd = get_rasd_instance(context, - ref, - _BROKER, - id, - type); - - if (CMIsNullObject(rasd)) - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_NOT_FOUND, - "No such instance (%s)", id); - - return s; -} - static CMPIStatus rasd_to_pool(const CMPIObjectPath *ref, struct std_assoc_info *info, struct inst_list *list) @@ -69,6 +47,7 @@ static CMPIStatus rasd_to_pool(const CMP char *poolid = NULL; virConnectPtr conn = NULL; CMPIInstance *pool = NULL; + CMPIInstance *inst = NULL; if (!match_hypervisor_prefix(ref, info)) return s; @@ -87,10 +66,7 @@ static CMPIStatus rasd_to_pool(const CMP goto out; } - s = validate_rasd_ref(info->context, - ref, - type, - id); + s = get_rasd_by_name(_BROKER, ref, id, type, &inst); if (s.rc != CMPI_RC_OK) goto out;

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203681292 -3600 # Node ID 6f70bca8f5caf8f7ff3eeaede8112dca27b3b072 # Parent d31116669eb24e1ff8691a33b4c1d5a91421fd20 ESD: adopt interface changes to RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r d31116669eb2 -r 6f70bca8f5ca src/Virt_ElementSettingData.c --- a/src/Virt_ElementSettingData.c Fri Feb 22 12:54:52 2008 +0100 +++ b/src/Virt_ElementSettingData.c Fri Feb 22 12:54:52 2008 +0100 @@ -63,38 +63,20 @@ static CMPIStatus rasd_to_rasd(const CMP struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *inst; - const char *id = NULL; - uint16_t type; + CMPIInstance *inst = NULL; if (!match_hypervisor_prefix(ref, info)) return s; - if (cu_get_str_path(ref, "InstanceID", &id) != CMPI_RC_OK) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Missing InstanceID"); + /* Special association case: + * RASD instance is pointing to itself + */ + s = get_rasd_by_ref(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) 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(info->context, ref, _BROKER, id, type); - if (inst == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Error getting associated RASD"); - - goto out; - } - + inst_list_add(list, inst); - + out: return s; }

Heidi Eckhart wrote:
Added get_rasd_by_ref() and get_rasd_by_name() to RASD provider to clean up / fasten the access to a specific RASD instance. This interface change has been adopted by the appropriate associaton providers, who need this access.
I really like this set of changes. It condenses a lot of the code, which makes the resulting files easier to read. +1 -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (3)
-
Dan Smith
-
Heidi Eckhart
-
Kaitlin Rupert