[PATCH] Make RASD not dependent on ResourceType key

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1193767892 25200 # Node ID babb2ffdc4c2c3f11a3281af4fb33cc3257127f8 # Parent e385d591fa6f8bbe135434117a16039d5693f5b4 Make RASD not dependent on ResourceType key I have tested DefineSystem() and some of the ResourcePool associations. (replaced the AllocationCapabilities changes) (removed the SettingsDefineCapabilities changes) Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r e385d591fa6f -r babb2ffdc4c2 schema/KVM_ResourceAllocationSettingData.mof --- a/schema/KVM_ResourceAllocationSettingData.mof Tue Oct 30 09:39:29 2007 -0700 +++ b/schema/KVM_ResourceAllocationSettingData.mof Tue Oct 30 11:11:32 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 e385d591fa6f -r babb2ffdc4c2 schema/Xen_ResourceAllocationSettingData.mof --- a/schema/Xen_ResourceAllocationSettingData.mof Tue Oct 30 09:39:29 2007 -0700 +++ b/schema/Xen_ResourceAllocationSettingData.mof Tue Oct 30 11:11:32 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 e385d591fa6f -r babb2ffdc4c2 src/Makefile.am --- a/src/Makefile.am Tue Oct 30 09:39:29 2007 -0700 +++ b/src/Makefile.am Tue Oct 30 11:11:32 2007 -0700 @@ -83,8 +83,10 @@ libVirt_ElementCapabilities_la_LIBADD = -lVirt_HostSystem libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c +libVirt_AllocationCapabilities_la_LIBADD = -lVirt_RASD libVirt_SettingsDefineCapabilities_la_SOURCES = Virt_SettingsDefineCapabilities.c +libVirt_SettingsDefineCapabilities_la_LIBADD = -lVirt_RASD libVirt_RegisteredProfile_la_SOURCES = Virt_RegisteredProfile.c diff -r e385d591fa6f -r babb2ffdc4c2 src/Virt_AllocationCapabilities.c --- a/src/Virt_AllocationCapabilities.c Tue Oct 30 09:39:29 2007 -0700 +++ b/src/Virt_AllocationCapabilities.c Tue Oct 30 11:11:32 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 e385d591fa6f -r babb2ffdc4c2 src/Virt_RASD.c --- a/src/Virt_RASD.c Tue Oct 30 09:39:29 2007 -0700 +++ b/src/Virt_RASD.c Tue Oct 30 11:11:32 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 e385d591fa6f -r babb2ffdc4c2 src/Virt_RASD.h --- a/src/Virt_RASD.h Tue Oct 30 09:39:29 2007 -0700 +++ b/src/Virt_RASD.h Tue Oct 30 11:11:32 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 e385d591fa6f -r babb2ffdc4c2 src/Virt_ResourceAllocationFromPool.c --- a/src/Virt_ResourceAllocationFromPool.c Tue Oct 30 09:39:29 2007 -0700 +++ b/src/Virt_ResourceAllocationFromPool.c Tue Oct 30 11:11:32 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 e385d591fa6f -r babb2ffdc4c2 src/Virt_SettingsDefineState.c --- a/src/Virt_SettingsDefineState.c Tue Oct 30 09:39:29 2007 -0700 +++ b/src/Virt_SettingsDefineState.c Tue Oct 30 11:11:32 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 e385d591fa6f -r babb2ffdc4c2 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Tue Oct 30 09:39:29 2007 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Tue Oct 30 11:11:32 2007 -0700 @@ -161,9 +161,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) @@ -210,7 +216,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; @@ -223,8 +228,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) @@ -692,6 +703,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, @@ -700,10 +712,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; }

DS> (replaced the AllocationCapabilities changes) DS> (removed the SettingsDefineCapabilities changes) Whoops. Reverted the wrong hunk last time (although in my defense, they looked almost identical!). This updated patch should be right. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1193767892 25200 # Node ID babb2ffdc4c2c3f11a3281af4fb33cc3257127f8 # Parent e385d591fa6f8bbe135434117a16039d5693f5b4 Make RASD not dependent on ResourceType key I have tested DefineSystem() and some of the ResourcePool associations.
(replaced the AllocationCapabilities changes) (removed the SettingsDefineCapabilities changes)
Signed-off-by: Dan Smith <danms@us.ibm.com>
Looks good now, +1. -- -Jay
participants (2)
-
Dan Smith
-
Jay Gagnon