[PATCH 0 of 5] 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.

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204806480 -3600 # Node ID cb86b8615183d98199f02c45df6aa07cfedf5bb2 # Parent 6b9530915893f8531c90cb18eca9bf9a7dd091b7 RASD: rename rasds_for_domain to enum_rasds and make it configurable Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 6b9530915893 -r cb86b8615183 src/Virt_RASD.c --- a/src/Virt_RASD.c Thu Mar 06 11:21:29 2008 +0100 +++ b/src/Virt_RASD.c Thu Mar 06 13:28:00 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,103 @@ 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 +620,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 +677,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 6b9530915893 -r cb86b8615183 src/Virt_RASD.h --- a/src/Virt_RASD.h Thu Mar 06 11:21:29 2008 +0100 +++ b/src/Virt_RASD.h Thu Mar 06 13:28:00 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,

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204806483 -3600 # Node ID 7bb967966c0c44c4ab7b89a4f3bf7c82301a4711 # Parent cb86b8615183d98199f02c45df6aa07cfedf5bb2 VSMS: adopt RASD interface change Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r cb86b8615183 -r 7bb967966c0c src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Thu Mar 06 13:28:00 2008 +0100 +++ b/src/Virt_VirtualSystemManagementService.c Thu Mar 06 13:28: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 1204806483 -3600 # Node ID 81c2aba96aff5c3177c86cb1dc08d88b52c3897f # Parent 7bb967966c0c44c4ab7b89a4f3bf7c82301a4711 VSSDC: adopt RASD interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 7bb967966c0c -r 81c2aba96aff src/Virt_VSSDComponent.c --- a/src/Virt_VSSDComponent.c Thu Mar 06 13:28:03 2008 +0100 +++ b/src/Virt_VSSDComponent.c Thu Mar 06 13:28:03 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,8 @@ 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 +72,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 +80,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 +100,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 1204806484 -3600 # Node ID c52aea6200a31e7f7dcb367124f036980f5beb36 # Parent 81c2aba96aff5c3177c86cb1dc08d88b52c3897f SDS: adopt RASD interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 81c2aba96aff -r c52aea6200a3 src/Virt_SettingsDefineState.c --- a/src/Virt_SettingsDefineState.c Thu Mar 06 13:28:03 2008 +0100 +++ b/src/Virt_SettingsDefineState.c Thu Mar 06 13:28: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 1204806485 -3600 # Node ID 0b7289fc81a8965c8376d69f0b0d43ff37e76de0 # Parent c52aea6200a31e7f7dcb367124f036980f5beb36 RAFP: adopt RASD interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r c52aea6200a3 -r 0b7289fc81a8 src/Virt_ResourceAllocationFromPool.c --- a/src/Virt_ResourceAllocationFromPool.c Thu Mar 06 13:28:04 2008 +0100 +++ b/src/Virt_ResourceAllocationFromPool.c Thu Mar 06 13:28: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"); @@ -77,10 +77,7 @@ static CMPIStatus rasd_to_pool(const CMP goto out; } - s = get_pool_by_name(_BROKER, - ref, - poolid, - &pool); + s = get_pool_by_name(_BROKER, ref, poolid, &pool); if (s.rc != CMPI_RC_OK) goto out; @@ -109,7 +106,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 +120,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 +127,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 +152,12 @@ 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;

HE> - s = get_pool_by_name(_BROKER, HE> - ref, HE> - poolid, HE> - &pool); HE> + s = get_pool_by_name(_BROKER, ref, poolid, &pool); Please don't needlessly reformat lines that are not part of the function changes of a patch. HE> + s = enum_rasds(_BROKER, ref, NULL, type, HE> + info->properties, &tmp_list); Everywhere else, we make multi-line function calls have one parameter per line (with a few pattern exceptions for cu_statusf(), etc). Otherwise I'm happy with this set :) -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com
participants (2)
-
Dan Smith
-
Heidi Eckhart