[PATCH 0 of 5] #3 - 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 Diff to patch set 2: - RASD: fix stlye issues - RAFP: free tmp_list

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1205150374 -3600 # Node ID e32460a4d31d11a8e77d2038d6c49a388f3f4ca3 # Parent 3d8334f3c78c378b8b592fef23944a647132527a RASD: rename rasds_for_domain to enum_rasds and make it configurable Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 3d8334f3c78c -r e32460a4d31d src/Virt_RASD.c --- a/src/Virt_RASD.c Mon Mar 10 11:27:35 2008 +0100 +++ b/src/Virt_RASD.c Mon Mar 10 12:59:34 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,130 @@ 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 +647,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 +704,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 3d8334f3c78c -r e32460a4d31d src/Virt_RASD.h --- a/src/Virt_RASD.h Mon Mar 10 11:27:35 2008 +0100 +++ b/src/Virt_RASD.h Mon Mar 10 12:59:34 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 1205150455 -3600 # Node ID 77c124f394ea3f03df79edb3e7934d5dbf119833 # Parent e32460a4d31d11a8e77d2038d6c49a388f3f4ca3 VSMS: adopt RASD interface change Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r e32460a4d31d -r 77c124f394ea src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Mon Mar 10 12:59:34 2008 +0100 +++ b/src/Virt_VirtualSystemManagementService.c Mon Mar 10 13:00:55 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 1205150468 -3600 # Node ID fdd9fe95af76f8d209da04848f530e7a10a16eab # Parent 77c124f394ea3f03df79edb3e7934d5dbf119833 VSSDC: adopt RASD interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 77c124f394ea -r fdd9fe95af76 src/Virt_VSSDComponent.c --- a/src/Virt_VSSDComponent.c Mon Mar 10 13:00:55 2008 +0100 +++ b/src/Virt_VSSDComponent.c Mon Mar 10 13:01:08 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 1205150482 -3600 # Node ID 1af3393262f9dfdcd5cd786abe825cc740db3bda # Parent fdd9fe95af76f8d209da04848f530e7a10a16eab SDS: adopt RASD interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r fdd9fe95af76 -r 1af3393262f9 src/Virt_SettingsDefineState.c --- a/src/Virt_SettingsDefineState.c Mon Mar 10 13:01:08 2008 +0100 +++ b/src/Virt_SettingsDefineState.c Mon Mar 10 13:01:22 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 1205150547 -3600 # Node ID 33213e77e6f58b3614ccc1ddb58db19e0112d034 # Parent 1af3393262f9dfdcd5cd786abe825cc740db3bda RAFP: adopt RASD interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 1af3393262f9 -r 33213e77e6f5 src/Virt_ResourceAllocationFromPool.c --- a/src/Virt_ResourceAllocationFromPool.c Mon Mar 10 13:01:22 2008 +0100 +++ b/src/Virt_ResourceAllocationFromPool.c Mon Mar 10 13:02:27 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,18 @@ 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); + + inst_list_free(&tmp_list); out: return s;
participants (1)
-
Heidi Eckhart