
# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1193673965 25200 # Node ID 07b9be7502efdeead8b1ab83df2d13bcb5398548 # Parent 82ff2daf1ddb72c0bd8a83588a03bd7a37ea110b Make RASD not dependent on ResourceType key I have tested DefineSystem() and some of the ResourcePool associations. It would be good to get a quick smoke test of the AllocationCapabilities stuff as well, just to make sure I didn't break anything. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 82ff2daf1ddb -r 07b9be7502ef schema/KVM_ResourceAllocationSettingData.mof --- a/schema/KVM_ResourceAllocationSettingData.mof Mon Oct 29 12:20:44 2007 +0100 +++ b/schema/KVM_ResourceAllocationSettingData.mof Mon Oct 29 09:06:05 2007 -0700 @@ -1,9 +1,4 @@ // Copyright IBM Corp. 2007 class KVM_ResourceAllocationSettingData : CIM_ResourceAllocationSettingData { - [Key, - Description ("The type of allocated resource"), - Override ("ResourceType")] - uint16 ResourceType; - }; diff -r 82ff2daf1ddb -r 07b9be7502ef schema/Xen_ResourceAllocationSettingData.mof --- a/schema/Xen_ResourceAllocationSettingData.mof Mon Oct 29 12:20:44 2007 +0100 +++ b/schema/Xen_ResourceAllocationSettingData.mof Mon Oct 29 09:06:05 2007 -0700 @@ -1,9 +1,4 @@ // Copyright IBM Corp. 2007 class Xen_ResourceAllocationSettingData : CIM_ResourceAllocationSettingData { - [Key, - Description ("The type of allocated resource"), - Override ("ResourceType")] - uint16 ResourceType; - }; diff -r 82ff2daf1ddb -r 07b9be7502ef src/Makefile.am --- a/src/Makefile.am Mon Oct 29 12:20:44 2007 +0100 +++ b/src/Makefile.am Mon Oct 29 09:06:05 2007 -0700 @@ -83,8 +83,10 @@ libVirt_ElementCapabilities_la_LIBADD = -lVirt_HostSystem libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c +libVirt_AllocationCapabilities_la_SOURCES = -lVirt_RASD libVirt_SettingsDefineCapabilities_la_SOURCES = Virt_SettingsDefineCapabilities.c +libVirt_SettingsDefineCapabilities_la_SOURCES = -lVirt_RASD libVirt_RegisteredProfile_la_SOURCES = Virt_RegisteredProfile.c diff -r 82ff2daf1ddb -r 07b9be7502ef src/Virt_AllocationCapabilities.c --- a/src/Virt_AllocationCapabilities.c Mon Oct 29 12:20:44 2007 +0100 +++ b/src/Virt_AllocationCapabilities.c Mon Oct 29 09:06:05 2007 -0700 @@ -29,6 +29,7 @@ #include "misc_util.h" #include "Virt_AllocationCapabilities.h" +#include "Virt_RASD.h" const static CMPIBroker *_BROKER; @@ -44,8 +45,7 @@ CMPIStatus get_alloc_cap(const CMPIBroke *inst = get_typed_instance(broker, "AllocationCapabilities", NAMESPACE(ref)); - ret = cu_get_u16_path(ref, "ResourceType", &type); - if (ret != 1) { + if (rasd_type_from_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { CMSetStatusWithChars(broker, &s, CMPI_RC_ERR_FAILED, "Could not get ResourceType."); goto out; diff -r 82ff2daf1ddb -r 07b9be7502ef src/Virt_RASD.c --- a/src/Virt_RASD.c Mon Oct 29 12:20:44 2007 +0100 +++ b/src/Virt_RASD.c Mon Oct 29 09:06:05 2007 -0700 @@ -205,10 +205,38 @@ static CMPIInstance *get_rasd_instance(c return inst; } +CMPIrc rasd_type_from_classname(const char *cn, uint16_t *type) +{ + char *base = NULL; + CMPIrc rc = CMPI_RC_ERR_FAILED; + + base = class_base_name(cn); + if (base == NULL) + goto out; + + if (STREQ(base, "DiskResourceAllocationSettingData")) + *type = CIM_RASD_TYPE_DISK; + else if (STREQ(base, "NetResourceAllocationSettingData")) + *type = CIM_RASD_TYPE_NET; + else if (STREQ(base, "ProcResourceAllocationSettingData")) + *type = CIM_RASD_TYPE_PROC; + else if (STREQ(base, "MemResourceAllocationSettingData")) + *type = CIM_RASD_TYPE_MEM; + else + goto out; + + rc = CMPI_RC_OK; + + out: + free(base); + + return rc; +} + static CMPIStatus GetInstance(CMPIInstanceMI *self, const CMPIContext *context, const CMPIResult *results, - const CMPIObjectPath *reference, + const CMPIObjectPath *ref, const char **properties) { CMPIStatus s = {CMPI_RC_OK, NULL}; @@ -216,7 +244,7 @@ static CMPIStatus GetInstance(CMPIInstan char *id = NULL; uint16_t type; - id = cu_get_str_path(reference, "InstanceID"); + id = cu_get_str_path(ref, "InstanceID"); if (id == NULL) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, @@ -224,14 +252,14 @@ static CMPIStatus GetInstance(CMPIInstan goto out; } - if (!cu_get_u16_path(reference, "ResourceType", &type)) { + if (rasd_type_from_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, - "Missing or invalid ResourceType"); - goto out; - } - - inst = get_rasd_instance(context, reference, id, type); + "Unable to determine RASD type"); + goto out; + } + + inst = get_rasd_instance(context, ref, id, type); if (inst != NULL) CMReturnInstance(results, inst); diff -r 82ff2daf1ddb -r 07b9be7502ef src/Virt_RASD.h --- a/src/Virt_RASD.h Mon Oct 29 12:20:44 2007 +0100 +++ b/src/Virt_RASD.h Mon Oct 29 09:06:05 2007 -0700 @@ -27,6 +27,7 @@ int rasds_for_domain(const CMPIBroker *b const uint16_t type, const char *ns, struct inst_list *_list); +CMPIrc rasd_type_from_classname(const char *cn, uint16_t *type); #endif diff -r 82ff2daf1ddb -r 07b9be7502ef src/Virt_ResourceAllocationFromPool.c --- a/src/Virt_ResourceAllocationFromPool.c Mon Oct 29 12:20:44 2007 +0100 +++ b/src/Virt_ResourceAllocationFromPool.c Mon Oct 29 09:06:05 2007 -0700 @@ -42,7 +42,6 @@ static CMPIStatus rasd_to_pool(const CMP struct inst_list *list) { CMPIStatus s; - int ret; uint16_t type; char *id = NULL; char *poolid = NULL; @@ -52,11 +51,10 @@ static CMPIStatus rasd_to_pool(const CMP inst_list_init(&_list); - ret = cu_get_u16_path(ref, "ResourceType", &type); - if (!ret) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Missing ResourceType"); + 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; } @@ -113,8 +111,16 @@ static int filter_by_pool(struct inst_li for (i = 0; i < src->cur; i++) { CMPIInstance *inst = src->list[i]; - - cu_get_u16_prop(inst, "ResourceType", &type); + CMPIObjectPath *op; + + op = CMGetObjectPath(inst, NULL); + if (op == NULL) + continue; + + if (rasd_type_from_classname(CLASSNAME(op), &type) != + CMPI_RC_OK) + continue; + cu_get_str_prop(inst, "InstanceID", &rasd_id); poolid = pool_member_of(_BROKER, type, rasd_id); diff -r 82ff2daf1ddb -r 07b9be7502ef src/Virt_SettingsDefineCapabilities.c --- a/src/Virt_SettingsDefineCapabilities.c Mon Oct 29 12:20:44 2007 +0100 +++ b/src/Virt_SettingsDefineCapabilities.c Mon Oct 29 09:06:05 2007 -0700 @@ -37,6 +37,7 @@ #include "svpc_types.h" #include "Virt_SettingsDefineCapabilities.h" +#include "Virt_RASD.h" const static CMPIBroker *_BROKER; @@ -315,13 +316,11 @@ static CMPIStatus alloc_cap_to_rasd(cons struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK}; - int ret; uint16_t type; CU_DEBUG("Getting ResourceType.\n"); - ret = cu_get_u16_path(ref, "ResourceType", &type); - if (ret != 1) { + if (rasd_type_from_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { CMSetStatusWithChars(_BROKER, &s, CMPI_RC_ERR_FAILED, "Could not get ResourceType."); goto out; diff -r 82ff2daf1ddb -r 07b9be7502ef src/Virt_SettingsDefineState.c --- a/src/Virt_SettingsDefineState.c Mon Oct 29 12:20:44 2007 +0100 +++ b/src/Virt_SettingsDefineState.c Mon Oct 29 09:06:05 2007 -0700 @@ -162,7 +162,6 @@ static CMPIStatus rasd_to_dev(const CMPI CMPIStatus s; CMPIInstance *dev = NULL; char *id = NULL; - int ret; uint16_t type; ASSOC_MATCH(info->provider_name, CLASSNAME(ref)); @@ -175,8 +174,7 @@ static CMPIStatus rasd_to_dev(const CMPI goto out; } - ret = cu_get_u16_path(ref, "ResourceType", &type); - if (!ret) { + if (rasd_type_from_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Missing ResourceType"); diff -r 82ff2daf1ddb -r 07b9be7502ef src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Mon Oct 29 12:20:44 2007 +0100 +++ b/src/Virt_VirtualSystemManagementService.c Mon Oct 29 09:06:05 2007 -0700 @@ -157,9 +157,15 @@ static int rasd_to_vdev(CMPIInstance *in char *id = NULL; char *name = NULL; char *devid = NULL; - - if (cu_get_u16_prop(inst, "ResourceType", &type) != CMPI_RC_OK) + CMPIObjectPath *op; + + op = CMGetObjectPath(inst, NULL); + if (op == NULL) goto err; + + if (rasd_type_from_classname(CLASSNAME(op), &type) != CMPI_RC_OK) + goto err; + dev->type = (int)type; if (cu_get_str_prop(inst, "InstanceID", &id) != CMPI_RC_OK) @@ -206,7 +212,6 @@ static int classify_resources(struct ins static int classify_resources(struct inst_list *all, struct domain *domain) { - int ret; int i; uint16_t type; @@ -219,8 +224,14 @@ static int classify_resources(struct ins domain->dev_net = calloc(all->cur, sizeof(struct virt_device)); for (i = 0; i < all->cur; i++) { - ret = cu_get_u16_prop(all->list[i], "ResourceType", &type); - if (ret != CMPI_RC_OK) + CMPIObjectPath *op; + + op = CMGetObjectPath(all->list[i], NULL); + if (op == NULL) + return 0; + + if (rasd_type_from_classname(CLASSNAME(op), &type) != + CMPI_RC_OK) return 0; if (type == CIM_RASD_TYPE_PROC) @@ -681,6 +692,7 @@ static CMPIStatus _update_resources_for( struct domain *dominfo = NULL; uint16_t type; char *xml = NULL; + CMPIObjectPath *op; if (!get_dominfo(dom, &dominfo)) { cu_statusf(_BROKER, &s, @@ -689,10 +701,18 @@ static CMPIStatus _update_resources_for( goto out; } - if (cu_get_u16_prop(rasd, "ResourceType", &type) != CMPI_RC_OK) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Missing ResourceType"); + op = CMGetObjectPath(rasd, NULL); + if (op == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get RASD path"); + goto out; + } + + if (rasd_type_from_classname(CLASSNAME(op), &type) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to determine RASD type"); goto out; }