[PATCH 0 of 5] #2 - 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. diff to patch set 1: - fixed get_rasd_by_name and get_rasd_by_ref to only return a valid instance pointer in case of success

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203934392 -3600 # Node ID 6e25b6b5b541ee6a3547ab2125937a7207bd21fc # Parent 875e54efe5feb2f65572c0b4d786081506e65cc8 RASD: add function get_rasd_by_ref() for usage in associations Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 875e54efe5fe -r 6e25b6b5b541 src/Virt_RASD.c --- a/src/Virt_RASD.c Mon Feb 25 11:09:49 2008 +0100 +++ b/src/Virt_RASD.c Mon Feb 25 11:13:12 2008 +0100 @@ -357,38 +357,97 @@ 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}; + CMPIInstance *inst = 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); + if (s.rc != CMPI_RC_OK) + goto out; + + *_inst = inst; + + out: + return s; } CMPIrc rasd_type_from_classname(const char *cn, uint16_t *type) @@ -544,32 +603,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 875e54efe5fe -r 6e25b6b5b541 src/Virt_RASD.h --- a/src/Virt_RASD.h Mon Feb 25 11:09:49 2008 +0100 +++ b/src/Virt_RASD.h Mon Feb 25 11:13:12 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

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203934430 -3600 # Node ID fdda40f15fcfd38c50a8918ad1075714e19efa7a # Parent 6e25b6b5b541ee6a3547ab2125937a7207bd21fc VSMS: adopt interface changes of RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 6e25b6b5b541 -r fdda40f15fcf src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Mon Feb 25 11:13:12 2008 +0100 +++ b/src/Virt_VirtualSystemManagementService.c Mon Feb 25 11:13: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; }

Heidi Eckhart wrote:
# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203934430 -3600 # Node ID fdda40f15fcfd38c50a8918ad1075714e19efa7a # Parent 6e25b6b5b541ee6a3547ab2125937a7207bd21fc VSMS: adopt interface changes of RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com>
diff -r 6e25b6b5b541 -r fdda40f15fcf src/Virt_VirtualSystemManagementService.c
+ *ret_arr = tmp_arr; - + return s; }
Whitespace here. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203934433 -3600 # Node ID 50360523c174c877639dbc2100fd5723b2193226 # Parent fdda40f15fcfd38c50a8918ad1075714e19efa7a SDS: adopt interface changes of RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r fdda40f15fcf -r 50360523c174 src/Virt_SettingsDefineState.c --- a/src/Virt_SettingsDefineState.c Mon Feb 25 11:13:50 2008 +0100 +++ b/src/Virt_SettingsDefineState.c Mon Feb 25 11:13:53 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 1203934433 -3600 # Node ID a8bd1f2980451ea709a720d2846300c52e089de0 # Parent 50360523c174c877639dbc2100fd5723b2193226 RAFP: adopt interface changes to RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 50360523c174 -r a8bd1f298045 src/Virt_ResourceAllocationFromPool.c --- a/src/Virt_ResourceAllocationFromPool.c Mon Feb 25 11:13:53 2008 +0100 +++ b/src/Virt_ResourceAllocationFromPool.c Mon Feb 25 11:13:53 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 1203934434 -3600 # Node ID 09459d892a7ba1f25fdd396dd41ff0e77fb6c234 # Parent a8bd1f2980451ea709a720d2846300c52e089de0 ESD: adopt interface changes to RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r a8bd1f298045 -r 09459d892a7b src/Virt_ElementSettingData.c --- a/src/Virt_ElementSettingData.c Mon Feb 25 11:13:53 2008 +0100 +++ b/src/Virt_ElementSettingData.c Mon Feb 25 11:13:54 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:
# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203934434 -3600 # Node ID 09459d892a7ba1f25fdd396dd41ff0e77fb6c234 # Parent a8bd1f2980451ea709a720d2846300c52e089de0 ESD: adopt interface changes to RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com>
diff -r a8bd1f298045 -r 09459d892a7b src/Virt_ElementSettingData.c
- + inst_list_add(list, inst); - + out: return s; }
Also whitespace here. Otherwise, this set looks good. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
Heidi Eckhart wrote:
# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203934434 -3600 # Node ID 09459d892a7ba1f25fdd396dd41ff0e77fb6c234 # Parent a8bd1f2980451ea709a720d2846300c52e089de0 ESD: adopt interface changes to RASD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com>
diff -r a8bd1f298045 -r 09459d892a7b src/Virt_ElementSettingData.c
Nevermind on this comment and the comment for src/Virt_VirtualSystemManagementService.c. I think my mail client was displaying things incorrectly. =) -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Heidi Eckhart
-
Kaitlin Rupert