[PATCH 0 of 5] #2 - Add configurable enum_rasds interface to RASD and Adopt changes to assoc providers

This patch set implements a configurable enum_rasds() interface to the RASD provider. This slight interface change is adopted to the affected associations. Diff to patch set 1: - moved adoption of new resource types CIM_RES_TYPE_foo into separate patch set - fixed style issues

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204892343 -3600 # Node ID e50362c85943d1b567ad2c9d080d4d0767a85a99 # Parent 50f47a071fb1d4668a5eb1b3e0c649f87ce8f376 RASD: rename rasds_for_domain to enum_rasds and make it configurable Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 50f47a071fb1 -r e50362c85943 src/Virt_RASD.c --- a/src/Virt_RASD.c Fri Mar 07 13:19:02 2008 +0100 +++ b/src/Virt_RASD.c Fri Mar 07 13:19:03 2008 +0100 @@ -439,8 +439,8 @@ CMPIStatus get_rasd_by_ref(const CMPIBro goto out; } - if (rasd_type_from_classname(CLASSNAME(reference), &type) != CMPI_RC_OK) { - cu_statusf(_BROKER, &s, + if (res_type_from_rasd_classname(CLASSNAME(reference), &type) != CMPI_RC_OK) { + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Unable to determine RASD type"); goto out; @@ -460,7 +460,7 @@ CMPIStatus get_rasd_by_ref(const CMPIBro return s; } -CMPIrc rasd_type_from_classname(const char *cn, uint16_t *type) +CMPIrc res_type_from_rasd_classname(const char *cn, uint16_t *type) { char *base = NULL; CMPIrc rc = CMPI_RC_ERR_FAILED; @@ -512,58 +512,114 @@ CMPIrc rasd_classname_from_type(uint16_t return rc; } -static CMPIStatus _enum_rasds(const CMPIObjectPath *ref, +static CMPIStatus _get_rasds(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const virDomainPtr dom, + const uint16_t type, + const char **properties, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + int count; + int i; + struct virt_device *devs = NULL; + + count = get_devices(dom, &devs, type); + if (count <= 0) + goto out; + + for (i = 0; i < count; i++) { + CMPIInstance *dev = NULL; + const char *host = NULL; + + host = virDomainGetName(dom); + if (host == NULL) { + cleanup_virt_device(&devs[i]); + continue; + } + + dev = rasd_from_vdev(broker, + &devs[i], + host, + reference, + properties); + if (dev) + inst_list_add(list, dev); + + cleanup_virt_device(&devs[i]); + } + + out: + free(devs); + return s; +} + +static CMPIStatus _enum_rasds(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const virDomainPtr dom, + const uint16_t type, const char **properties, struct inst_list *list) { + CMPIStatus s; + + if (type == CIM_RES_TYPE_ALL) { + s = _get_rasds(broker, reference, dom, + CIM_RES_TYPE_PROC, + properties, list); + s = _get_rasds(broker, reference, dom, + CIM_RES_TYPE_MEM, + properties, list); + s = _get_rasds(broker, reference, dom, + CIM_RES_TYPE_NET, + properties, list); + s = _get_rasds(broker, reference, dom, + CIM_RES_TYPE_DISK, + properties, list); + } + else + s = _get_rasds(broker, reference, dom, + type, properties, list); + + return s; +} + +CMPIStatus enum_rasds(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const char *domain, + const uint16_t type, + const char **properties, + struct inst_list *list) +{ virConnectPtr conn = NULL; virDomainPtr *domains = NULL; - int count; - int i, j; - uint16_t type; - CMPIStatus s; - uint16_t types[] = {CIM_RES_TYPE_PROC, - CIM_RES_TYPE_DISK, - CIM_RES_TYPE_NET, - CIM_RES_TYPE_MEM, - 0}; + int count = 1; + int i; + CMPIStatus s = {CMPI_RC_OK, NULL}; conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); if (conn == NULL) - return s; - - count = get_domain_list(conn, &domains); - if (count <= 0) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unable to get domain list"); - goto out; - } - - if (rasd_type_from_classname(CLASSNAME(ref), &type) == CMPI_RC_OK) { - types[0] = type; - types[1] = 0; - } + goto out; + + if (domain) { + domains = calloc(1, sizeof(virDomainPtr)); + domains[0] = virDomainLookupByName(conn, domain); + } + else + count = get_domain_list(conn, &domains); for (i = 0; i < count; i++) { - for (j = 0; types[j] != 0; j++) { - CU_DEBUG("Doing RASD type %i for %s", - type, virDomainGetName(domains[i])); - rasds_for_domain(_BROKER, - virDomainGetName(domains[i]), - types[j], - ref, - properties, - list); - } + _enum_rasds(broker, + ref, + domains[i], + type, + properties, + list); virDomainFree(domains[i]); } - s = (CMPIStatus){CMPI_RC_OK, NULL}; - out: virConnectClose(conn); - free(domains); return s; } @@ -575,17 +631,23 @@ static CMPIStatus return_enum_rasds(cons { struct inst_list list; CMPIStatus s; + uint16_t type; inst_list_init(&list); - s = _enum_rasds(ref, properties, &list); - if (s.rc == CMPI_RC_OK) { - if (names_only) - cu_return_instance_names(results, &list); - else - cu_return_instances(results, &list); - } - + res_type_from_rasd_classname(CLASSNAME(ref), &type); + + s = enum_rasds(_BROKER, ref, NULL, + type, properties, &list); + if (s.rc != CMPI_RC_OK) + goto out; + + if (names_only) + cu_return_instance_names(results, &list); + else + cu_return_instances(results, &list); + + out: inst_list_free(&list); return s; @@ -626,41 +688,6 @@ static CMPIStatus GetInstance(CMPIInstan out: return s; -} - -int rasds_for_domain(const CMPIBroker *broker, - const char *name, - const uint16_t type, - const CMPIObjectPath *ref, - const char **properties, - struct inst_list *_list) -{ - struct virt_device *list; - int count; - int i; - virConnectPtr conn; - CMPIStatus s; - - conn = connect_by_classname(broker, CLASSNAME(ref), &s); - if (conn == NULL) - return 0; - - count = list_devs(conn, type, name, &list); - - for (i = 0; i < count; i++) { - CMPIInstance *inst; - - inst = rasd_from_vdev(broker, &list[i], name, ref, properties); - if (inst != NULL) - inst_list_add(_list, inst); - } - - if (count > 0) - cleanup_virt_devices(&list, count); - - virConnectClose(conn); - - return count; } DEFAULT_CI(); diff -r 50f47a071fb1 -r e50362c85943 src/Virt_RASD.h --- a/src/Virt_RASD.h Fri Mar 07 13:19:02 2008 +0100 +++ b/src/Virt_RASD.h Fri Mar 07 13:19:03 2008 +0100 @@ -27,20 +27,20 @@ char *rasd_to_xml(CMPIInstance *rasd); * Get a list of RASDs for a given domain * * @param broker The current broker - * @param name The name of the domain in question + * @param ref Defines the libvirt connection to use + * @param domain The domain id (NULL means for all domains) * @param type The ResourceType of the desired RASDs - * @param ref A reference used for hypervisor connection and namespace - * setting of the resulting instances + * @param properties The properties to filter for * @param _list The list of instances to populate */ -int rasds_for_domain(const CMPIBroker *broker, - const char *name, - const uint16_t type, - const CMPIObjectPath *ref, - const char **properties, - struct inst_list *_list); +CMPIStatus enum_rasds(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const char *domain, + const uint16_t type, + const char **properties, + struct inst_list *_list); -CMPIrc rasd_type_from_classname(const char *cn, uint16_t *type); +CMPIrc res_type_from_rasd_classname(const char *cn, uint16_t *type); CMPIrc rasd_classname_from_type(uint16_t type, const char **cn); CMPIStatus get_rasd_by_name(const CMPIBroker *broker,

+static CMPIStatus _enum_rasds(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const virDomainPtr dom, + const uint16_t type, const char **properties, struct inst_list *list) { + CMPIStatus s; + + if (type == CIM_RES_TYPE_ALL) { + s = _get_rasds(broker, reference, dom, + CIM_RES_TYPE_PROC, + properties, list); + s = _get_rasds(broker, reference, dom, + CIM_RES_TYPE_MEM, + properties, list); + s = _get_rasds(broker, reference, dom, + CIM_RES_TYPE_NET, + properties, list); + s = _get_rasds(broker, reference, dom, + CIM_RES_TYPE_DISK, + properties, list); + }
Probably not worth worrying about, but wondering if this could be condensed some.. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
Probably not worth worrying about, but wondering if this could be condensed some.. Will do so in a follow on patch.
-- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor

HE> + if (type == CIM_RES_TYPE_ALL) { HE> + s = _get_rasds(broker, reference, dom, HE> + CIM_RES_TYPE_PROC, HE> + properties, list); HE> + s = _get_rasds(broker, reference, dom, HE> + CIM_RES_TYPE_MEM, HE> + properties, list); HE> + s = _get_rasds(broker, reference, dom, HE> + CIM_RES_TYPE_NET, HE> + properties, list); HE> + s = _get_rasds(broker, reference, dom, HE> + CIM_RES_TYPE_DISK, HE> + properties, list); HE> + } HE> + else HE> + s = _get_rasds(broker, reference, dom, HE> + type, properties, list); These function calls should be one parameter per line. -- 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 1204892343 -3600 # Node ID 5035a40ceb863e53e7b33dcc12e5a7571bbcc1d3 # Parent e50362c85943d1b567ad2c9d080d4d0767a85a99 VSMS: adopt RASD interface change Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r e50362c85943 -r 5035a40ceb86 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Fri Mar 07 13:19:03 2008 +0100 +++ b/src/Virt_VirtualSystemManagementService.c Fri Mar 07 13:19:03 2008 +0100 @@ -220,7 +220,7 @@ static int rasd_to_vdev(CMPIInstance *in if (op == NULL) goto err; - if (rasd_type_from_classname(CLASSNAME(op), &type) != CMPI_RC_OK) + if (res_type_from_rasd_classname(CLASSNAME(op), &type) != CMPI_RC_OK) goto err; dev->type = (int)type; @@ -303,7 +303,7 @@ static int classify_resources(CMPIArray if (op == NULL) return 0; - if (rasd_type_from_classname(CLASSNAME(op), &type) != + if (res_type_from_rasd_classname(CLASSNAME(op), &type) != CMPI_RC_OK) return 0; @@ -882,7 +882,7 @@ static CMPIStatus _update_resources_for( goto out; } - if (rasd_type_from_classname(CLASSNAME(op), &type) != CMPI_RC_OK) { + if (res_type_from_rasd_classname(CLASSNAME(op), &type) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Unable to determine RASD type"); @@ -1036,7 +1036,7 @@ static CMPIStatus rasd_refs_to_insts(con continue; } - if (rasd_type_from_classname(CLASSNAME(ref), &type) != + if (res_type_from_rasd_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { CU_DEBUG("Unable to get type of `%s'", REF2STR(ref));

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204892344 -3600 # Node ID 29a9dd30a48b19e26edeb2a1ed030e4244674f97 # Parent 5035a40ceb863e53e7b33dcc12e5a7571bbcc1d3 VSSDC: adopt RASD interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 5035a40ceb86 -r 29a9dd30a48b src/Virt_VSSDComponent.c --- a/src/Virt_VSSDComponent.c Fri Mar 07 13:19:03 2008 +0100 +++ b/src/Virt_VSSDComponent.c Fri Mar 07 13:19:04 2008 +0100 @@ -43,14 +43,6 @@ static CMPIStatus vssd_to_rasd(const CMP CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *inst = NULL; char *name = NULL; - int i = 0; - int types[] = { - CIM_RES_TYPE_PROC, - CIM_RES_TYPE_NET, - CIM_RES_TYPE_DISK, - CIM_RES_TYPE_MEM, - -1 - }; if (!match_hypervisor_prefix(ref, info)) goto out; @@ -66,14 +58,12 @@ static CMPIStatus vssd_to_rasd(const CMP goto out; } - for (i = 0; types[i] > 0; i++) { - rasds_for_domain(_BROKER, - name, - types[i], - ref, - info->properties, - list); - } + s = enum_rasds(_BROKER, + ref, + name, + CIM_RES_TYPE_ALL, + info->properties, + list); free(name); @@ -86,7 +76,7 @@ static CMPIStatus rasd_to_vssd(const CMP struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *vssd = NULL; + CMPIInstance *inst = NULL; const char *id = NULL; char *host = NULL; char *devid = NULL; @@ -94,6 +84,10 @@ static CMPIStatus rasd_to_vssd(const CMP if (!match_hypervisor_prefix(ref, info)) return s; + + s = get_rasd_by_ref(_BROKER, ref, info->properties, &inst); + if (s.rc != CMPI_RC_OK) + goto out; if (cu_get_str_path(ref, "InstanceID", &id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -110,11 +104,11 @@ static CMPIStatus rasd_to_vssd(const CMP goto out; } - s = get_vssd_by_name(_BROKER, ref, host, &vssd); + s = get_vssd_by_name(_BROKER, ref, host, &inst); if (s.rc != CMPI_RC_OK) goto out; - inst_list_add(list, vssd); + inst_list_add(list, inst); out: free(host);

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204892344 -3600 # Node ID 5c46a8e9bf8962d48535fd3b1c1b486d92a9b5b7 # Parent 29a9dd30a48b19e26edeb2a1ed030e4244674f97 SDS: adopt RASD interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 29a9dd30a48b -r 5c46a8e9bf89 src/Virt_SettingsDefineState.c --- a/src/Virt_SettingsDefineState.c Fri Mar 07 13:19:04 2008 +0100 +++ b/src/Virt_SettingsDefineState.c Fri Mar 07 13:19:04 2008 +0100 @@ -99,7 +99,7 @@ static CMPIStatus rasd_to_dev(const CMPI goto out; } - if (rasd_type_from_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { + if (res_type_from_rasd_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Missing ResourceType");

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204892345 -3600 # Node ID d24e8fe2d358588a2d3a6484111806e1986d90fa # Parent 5c46a8e9bf8962d48535fd3b1c1b486d92a9b5b7 RAFP: adopt RASD interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 5c46a8e9bf89 -r d24e8fe2d358 src/Virt_ResourceAllocationFromPool.c --- a/src/Virt_ResourceAllocationFromPool.c Fri Mar 07 13:19:04 2008 +0100 +++ b/src/Virt_ResourceAllocationFromPool.c Fri Mar 07 13:19:05 2008 +0100 @@ -51,7 +51,7 @@ static CMPIStatus rasd_to_pool(const CMP if (!match_hypervisor_prefix(ref, info)) return s; - if (rasd_type_from_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { + if (res_type_from_rasd_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Unable to determine RASD type"); @@ -109,7 +109,7 @@ static int filter_by_pool(struct inst_li if (op == NULL) continue; - if (rasd_type_from_classname(CLASSNAME(op), &type) != + if (res_type_from_rasd_classname(CLASSNAME(op), &type) != CMPI_RC_OK) continue; @@ -123,52 +123,6 @@ static int filter_by_pool(struct inst_li return dest->cur; } -static int rasds_from_pool(uint16_t type, - const CMPIObjectPath *ref, - const char *poolid, - const char **properties, - struct inst_list *list) -{ - CMPIStatus s; - virConnectPtr conn = NULL; - virDomainPtr *doms = NULL; - int count; - int i; - - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); - if (conn == NULL) - return 0; - - count = get_domain_list(conn, &doms); - - for (i = 0; i < count; i++) { - const char *name; - struct inst_list tmp; - - inst_list_init(&tmp); - - name = virDomainGetName(doms[i]); - - rasds_for_domain(_BROKER, - name, - type, - ref, - properties, - &tmp); - - filter_by_pool(list, &tmp, poolid); - - inst_list_free(&tmp); - - virDomainFree(doms[i]); - } - - free(doms); - virConnectClose(conn); - - return count; -} - static CMPIStatus pool_to_rasd(const CMPIObjectPath *ref, struct std_assoc_info *info, struct inst_list *list) @@ -176,7 +130,8 @@ static CMPIStatus pool_to_rasd(const CMP CMPIStatus s = {CMPI_RC_OK, NULL}; const char *poolid; uint16_t type; - CMPIInstance *inst; + CMPIInstance *inst = NULL; + struct inst_list tmp_list; if (!match_hypervisor_prefix(ref, info)) goto out; @@ -200,11 +155,16 @@ static CMPIStatus pool_to_rasd(const CMP goto out; } - rasds_from_pool(type, - ref, - poolid, - info->properties, - list); + inst_list_init(&tmp_list); + + s = enum_rasds(_BROKER, + ref, + NULL, + type, + info->properties, + &tmp_list); + + filter_by_pool(list, &tmp_list, poolid); out: return s;

static CMPIStatus pool_to_rasd(const CMPIObjectPath *ref, struct std_assoc_info *info, struct inst_list *list) @@ -176,7 +130,8 @@ static CMPIStatus pool_to_rasd(const CMP CMPIStatus s = {CMPI_RC_OK, NULL}; const char *poolid; uint16_t type; - CMPIInstance *inst; + CMPIInstance *inst = NULL; + struct inst_list tmp_list;
if (!match_hypervisor_prefix(ref, info)) goto out; @@ -200,11 +155,16 @@ static CMPIStatus pool_to_rasd(const CMP goto out; }
- rasds_from_pool(type, - ref, - poolid, - info->properties, - list); + inst_list_init(&tmp_list); + + s = enum_rasds(_BROKER, + ref, + NULL, + type, + info->properties, + &tmp_list); + + filter_by_pool(list, &tmp_list, poolid);
out: return s;
tmp_list doesn't get freed here. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (3)
-
Dan Smith
-
Heidi Eckhart
-
Kaitlin Rupert