[PATCH 0 of 2] Refactor SettingsDefineCapabilities AC to RASD

Condensed the 4 functions (one for min, max, inc, and def for each resource type) into 1 function for each resource type. Condensing this removes the need for the sdc_rasd structs and the sdc_rasd_list. The provider behavior should stay the same, the only change here is the layout of the code.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1222810803 25200 # Node ID 5da8358fed0dd5c2bd376ca84af8970fbcbc4694 # Parent 9811decde9f6dbd72abb183ef40a4ac798d9d1a2 Add condensed template functions, update sdc_rasds_for_type() & sdc_rasd_inst() Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 9811decde9f6 -r 5da8358fed0d src/Virt_SettingsDefineCapabilities.c --- a/src/Virt_SettingsDefineCapabilities.c Wed Sep 17 15:53:24 2008 -0700 +++ b/src/Virt_SettingsDefineCapabilities.c Tue Sep 30 14:40:03 2008 -0700 @@ -303,6 +303,57 @@ free (prop_list); } +static struct sdc_rasd_prop *mem_template(const CMPIObjectPath *ref, + int template_type, + CMPIStatus *s) +{ + bool ret; + uint64_t mem_size; + const char *id; + struct sdc_rasd_prop *rasd = NULL; + + switch (template_type) { + case SDC_RASD_MIN: + mem_size = 64 << 10; + id = "Minimum"; + break; + case SDC_RASD_MAX: + mem_size = MAX_MEM; + id = "Maximum"; + break; + case SDC_RASD_INC: + mem_size = 1 << 10; + id = "Increment"; + break; + case SDC_RASD_DEF: + mem_size = 256 << 10; + id = "Default"; + break; + default: + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Unsupported sdc_rasd type"); + goto out; + } + + struct sdc_rasd_prop tmp[] = { + {"InstanceID", (CMPIValue *)id, CMPI_chars}, + {"AllocationUnits", (CMPIValue *)"KiloBytes", CMPI_chars}, + {"VirtualQuantity", (CMPIValue *)&mem_size, CMPI_uint64}, + PROP_END + }; + + ret = dup_rasd_prop_list(tmp, &rasd); + if (!ret) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not copy RASD"); + } + + out: + return rasd; +} + static struct sdc_rasd_prop *mem_max(const CMPIObjectPath *ref, CMPIStatus *s) { @@ -395,6 +446,83 @@ CMPI_RC_ERR_FAILED, "Could not copy RASD"); } + + return rasd; +} + +static bool get_max_procs(const CMPIObjectPath *ref, + uint64_t *num_procs, + CMPIStatus *s) +{ + bool ret = false; + virConnectPtr conn; + + conn = connect_by_classname(_BROKER, CLASSNAME(ref), s); + if (conn == NULL) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not connect to hypervisor"); + goto out; + } + + *num_procs = virConnectGetMaxVcpus(conn, NULL); + CU_DEBUG("libvirt says %d max vcpus", *num_procs); + ret = true; + + out: + return ret; +} + +static struct sdc_rasd_prop *proc_template(const CMPIObjectPath *ref, + int template_type, + CMPIStatus *s) +{ + bool ret; + uint64_t num_procs; + const char *id; + struct sdc_rasd_prop *rasd = NULL; + + switch (template_type) { + case SDC_RASD_MIN: + num_procs = 0; + id = "Minimum"; + break; + case SDC_RASD_MAX: + ret = get_max_procs(ref, &num_procs, s); + if (!ret) + goto out; + id = "Maximum"; + break; + case SDC_RASD_INC: + num_procs = 1; + id = "Increment"; + break; + case SDC_RASD_DEF: + num_procs = 1; + id = "Default"; + break; + default: + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Unsupported sdc_rasd type"); + goto out; + } + + struct sdc_rasd_prop tmp[] = { + {"InstanceID", (CMPIValue *)id, CMPI_chars}, + {"AllocationUnits", (CMPIValue *)"Processors", CMPI_chars}, + {"VirtualQuantity", (CMPIValue *)&num_procs, CMPI_uint64}, + PROP_END + }; + + ret = dup_rasd_prop_list(tmp, &rasd); + if (!ret) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not copy RASD"); + } + + out: return rasd; } @@ -533,12 +661,6 @@ return rasd; } -static uint64_t net_max_kvm(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - /* This appears to not require anything dynamic. */ - return KVM_MAX_NICS; -} static uint64_t net_max_xen(const CMPIObjectPath *ref, CMPIStatus *s) { @@ -572,6 +694,100 @@ out: virConnectClose(conn); return num_nics; +} + +static bool get_max_nics(const CMPIObjectPath *ref, + uint64_t *num_nics, + CMPIStatus *s) +{ + char *prefix; + bool ret = false; + + prefix = class_prefix_name(CLASSNAME(ref)); + if (prefix == NULL) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not get prefix from reference"); + goto out; + } + + if (STREQC(prefix, "Xen")) { + *num_nics = net_max_xen(ref, s); + } else if (STREQC(prefix, "KVM")) { + /* This appears to not require anything dynamic. */ + *num_nics = KVM_MAX_NICS; + } else { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_NOT_SUPPORTED, + "Unsupported hypervisor: '%s'", prefix); + goto out; + } + + if (s->rc != CMPI_RC_OK) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not get max nic count"); + goto out; + } else { + ret = true; + } + + out: + free(prefix); + + return ret; +} + +static struct sdc_rasd_prop *net_template(const CMPIObjectPath *ref, + int template_type, + CMPIStatus *s) +{ + bool ret; + uint64_t num_nics; + const char *id; + struct sdc_rasd_prop *rasd = NULL; + + switch (template_type) { + case SDC_RASD_MIN: + num_nics = 0; + id = "Minimum"; + break; + case SDC_RASD_MAX: + ret = get_max_nics(ref, &num_nics, s); + if (!ret) + goto out; + id = "Maximum"; + break; + case SDC_RASD_INC: + num_nics = 1; + id = "Increment"; + break; + case SDC_RASD_DEF: + num_nics = 1; + id = "Default"; + break; + default: + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Unsupported sdc_rasd type"); + goto out; + } + + struct sdc_rasd_prop tmp[] = { + {"InstanceID", (CMPIValue *)id, CMPI_chars}, + {"VirtualQuantity", (CMPIValue *)&num_nics, CMPI_uint64}, + PROP_END + }; + + ret = dup_rasd_prop_list(tmp, &rasd); + if (!ret) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not copy RASD"); + } + + out: + return rasd; } static struct sdc_rasd_prop *net_max(const CMPIObjectPath *ref, @@ -668,6 +884,105 @@ "Could not copy RASD"); } + return rasd; +} + +static int get_disk_freespace(const CMPIObjectPath *ref, + CMPIStatus *s, + uint64_t *free_space) +{ + bool ret = false; + const char *inst_id; + CMPIrc prop_ret; + virConnectPtr conn; + CMPIInstance *pool_inst; + + if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not get InstanceID"); + goto out; + } + + conn = connect_by_classname(_BROKER, CLASSNAME(ref), s); + if (s->rc != CMPI_RC_OK) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not get connection"); + goto out; + } + + /* Getting the relevant resource pool directly finds the free space + * for us. It is in the Capacity field. */ + *s = get_pool_by_name(_BROKER, ref, inst_id, &pool_inst); + if (s->rc != CMPI_RC_OK) + goto out; + + prop_ret = cu_get_u64_prop(pool_inst, "Capacity", free_space); + if (prop_ret != CMPI_RC_OK) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not get capacity from instance"); + goto out; + } + + CU_DEBUG("Got capacity from pool_inst: %lld", *free_space); + ret = true; + + out: + return ret; +} + +static struct sdc_rasd_prop *disk_template(const CMPIObjectPath *ref, + int template_type, + CMPIStatus *s) +{ + bool ret; + uint64_t disk_size; + const char *id; + struct sdc_rasd_prop *rasd = NULL; + + switch(template_type) { + case SDC_RASD_MIN: + disk_size = SDC_DISK_MIN; + id = "Minimum"; + break; + case SDC_RASD_MAX: + ret = get_disk_freespace(ref, s, &disk_size); + if (!ret) + goto out; + id = "Maximum"; + break; + case SDC_RASD_INC: + disk_size = SDC_DISK_INC; + id = "Increment"; + break; + case SDC_RASD_DEF: + disk_size = SDC_DISK_DEF; + id = "Default"; + break; + default: + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Unsupported sdc_rasd type"); + goto out; + } + + struct sdc_rasd_prop tmp[] = { + {"InstanceID", (CMPIValue *)id, CMPI_chars}, + {"AllocationQuantity", (CMPIValue *)"MegaBytes", CMPI_chars}, + {"VirtualQuantity", (CMPIValue *)&disk_size, CMPI_uint64}, + PROP_END + }; + + ret = dup_rasd_prop_list(tmp, &rasd); + if (!ret) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not copy RASD"); + } + + out: return rasd; } @@ -842,68 +1157,45 @@ NULL }; -static CMPIInstance *sdc_rasd_inst(const CMPIBroker *broker, - CMPIStatus *s, +static CMPIInstance *sdc_rasd_inst(CMPIStatus *s, const CMPIObjectPath *ref, - struct sdc_rasd *rasd, - sdc_rasd_type type) + sdc_rasd_type type, + uint16_t resource_type) { CMPIInstance *inst = NULL; struct sdc_rasd_prop *prop_list = NULL; int i; - const char *inst_id = NULL; const char *base = NULL; - uint16_t resource_type; - switch(type) { - case SDC_RASD_MIN: - if (rasd->min == NULL) - goto out; - prop_list = rasd->min(ref, s); - inst_id = "Minimum"; - break; - case SDC_RASD_MAX: - if (rasd->max == NULL) - goto out; - prop_list = rasd->max(ref, s); - inst_id = "Maximum"; - break; - case SDC_RASD_INC: - if (rasd->inc == NULL) - goto out; - prop_list = rasd->inc(ref, s); - inst_id = "Increment"; - break; - case SDC_RASD_DEF: - if (rasd->def == NULL) - goto out; - prop_list = rasd->def(ref, s); - inst_id = "Default"; - break; - default: - cu_statusf(broker, s, + if (resource_type == CIM_RES_TYPE_MEM) + prop_list = mem_template(ref, type, s); + else if (resource_type == CIM_RES_TYPE_PROC) + prop_list = proc_template(ref, type, s); + else if (resource_type == CIM_RES_TYPE_NET) + prop_list = net_template(ref, type, s); + else if (resource_type == CIM_RES_TYPE_DISK) + prop_list = disk_template(ref, type, s); + else { + cu_statusf(_BROKER, s, CMPI_RC_ERR_FAILED, - "Unsupported sdc_rasd type"); + "Unsupported resource type"); } if (s->rc != CMPI_RC_OK) goto out; - if (rasd_classname_from_type(rasd->resource_type, &base) != CMPI_RC_OK) { - cu_statusf(broker, s, + if (rasd_classname_from_type(resource_type, &base) != CMPI_RC_OK) { + cu_statusf(_BROKER, s, CMPI_RC_ERR_FAILED, "Resource type not known"); goto out; } - inst = get_typed_instance(broker, + inst = get_typed_instance(_BROKER, CLASSNAME(ref), base, NAMESPACE(ref)); - CMSetProperty(inst, "InstanceID", inst_id, CMPI_chars); - - resource_type = rasd->resource_type; CMSetProperty(inst, "ResourceType", &resource_type, CMPI_uint16); for (i = 0; prop_list[i].field != NULL; i++) { @@ -922,40 +1214,24 @@ uint16_t type) { CMPIStatus s = {CMPI_RC_OK, NULL}; - struct sdc_rasd *rasd = NULL; CMPIInstance *inst; int i; - for (i = 0; sdc_rasd_list[i] != NULL; i++) { - if (sdc_rasd_list[i]->resource_type == type) { - rasd = sdc_rasd_list[i]; - break; + for (i = SDC_RASD_MIN; i <= SDC_RASD_INC; i++) { + inst = sdc_rasd_inst(&s, ref, i, type); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("Problem getting inst"); + goto out; + } + CU_DEBUG("Got inst"); + if (inst != NULL) { + inst_list_add(list, inst); + CU_DEBUG("Added inst"); + } else { + CU_DEBUG("Inst is null, not added"); } } - - if (rasd) { - for (i = SDC_RASD_MIN; i <= SDC_RASD_INC; i++) { - inst = sdc_rasd_inst(_BROKER, &s, ref, rasd, i); - if (s.rc != CMPI_RC_OK) { - CU_DEBUG("Problem getting inst"); - goto out; - } - CU_DEBUG("Got inst"); - if (inst != NULL) { - inst_list_add(list, inst); - CU_DEBUG("Added inst"); - } else { - CU_DEBUG("Inst is null, not added"); - } - } - } else { - CU_DEBUG("Unsupported type"); - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unsupported device type"); - } - out: return s; }

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1222810804 25200 # Node ID 3e9ae5caaf705d0eebabadebf9b4bcfb06623aab # Parent 5da8358fed0dd5c2bd376ca84af8970fbcbc4694 Remove old functions and structs Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 5da8358fed0d -r 3e9ae5caaf70 src/Virt_SettingsDefineCapabilities.c --- a/src/Virt_SettingsDefineCapabilities.c Tue Sep 30 14:40:03 2008 -0700 +++ b/src/Virt_SettingsDefineCapabilities.c Tue Sep 30 14:40:04 2008 -0700 @@ -354,102 +354,6 @@ return rasd; } -static struct sdc_rasd_prop *mem_max(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - struct sdc_rasd_prop *rasd = NULL; - uint64_t max_vq = MAX_MEM; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Maximum", CMPI_chars}, - {"AllocationUnits", (CMPIValue *)"KiloBytes", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&max_vq, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - -static struct sdc_rasd_prop *mem_min(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - struct sdc_rasd_prop *rasd = NULL; - uint64_t min_vq = 64 << 10; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Minimum", CMPI_chars}, - {"AllocationUnits", (CMPIValue *)"KiloBytes", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&min_vq, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - -static struct sdc_rasd_prop *mem_def(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - struct sdc_rasd_prop *rasd = NULL; - uint64_t def_vq = 256 << 10; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Default", CMPI_chars}, - {"AllocationUnits", (CMPIValue *)"KiloBytes", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&def_vq, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - -static struct sdc_rasd_prop *mem_inc(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - struct sdc_rasd_prop *rasd = NULL; - uint64_t inc_vq = 1 << 10; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Increment", CMPI_chars}, - {"AllocationUnits", (CMPIValue *)"KiloBytes", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&inc_vq, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - static bool get_max_procs(const CMPIObjectPath *ref, uint64_t *num_procs, CMPIStatus *s) @@ -523,140 +427,6 @@ } out: - - return rasd; -} - -static struct sdc_rasd_prop *proc_min(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - uint64_t num_procs = 1; - struct sdc_rasd_prop *rasd = NULL; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Minimum", CMPI_chars}, - {"AllocationUnits", (CMPIValue *)"Processors", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&num_procs, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - -static struct sdc_rasd_prop *proc_max(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - virConnectPtr conn; - uint64_t num_procs = 0; - struct sdc_rasd_prop *rasd = NULL; - - CU_DEBUG("In proc_max()"); - - conn = connect_by_classname(_BROKER, CLASSNAME(ref), s); - if (conn == NULL) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not connect to hypervisor"); - goto out; - } - - num_procs = virConnectGetMaxVcpus(conn, NULL); - CU_DEBUG("libvirt says %d max vcpus", num_procs); - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Maximum", CMPI_chars}, - {"AllocationUnits", (CMPIValue *)"Processors", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&num_procs, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - out: - return rasd; -} - -static struct sdc_rasd_prop *proc_def(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - uint64_t num_procs = 1; - struct sdc_rasd_prop *rasd = NULL; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Default", CMPI_chars}, - {"AllocationUnits", (CMPIValue *)"Processors", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&num_procs, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - -static struct sdc_rasd_prop *proc_inc(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - uint64_t num_procs = 1; - struct sdc_rasd_prop *rasd = NULL; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Increment", CMPI_chars}, - {"AllocationUnits", (CMPIValue *)"Processors", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&num_procs, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - -static struct sdc_rasd_prop *net_min(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - uint64_t num_nics = 0; - struct sdc_rasd_prop *rasd = NULL; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Minimum", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&num_nics, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } return rasd; } @@ -790,103 +560,6 @@ return rasd; } -static struct sdc_rasd_prop *net_max(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - char *prefix; - uint64_t num_nics; - struct sdc_rasd_prop *rasd = NULL; - - prefix = class_prefix_name(CLASSNAME(ref)); - if (prefix == NULL) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not get prefix from reference"); - goto out; - } - - if (STREQC(prefix, "Xen")) { - num_nics = net_max_xen(ref, s); - } else if (STREQC(prefix, "KVM")) { - num_nics = net_max_kvm(ref, s); - } else { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_NOT_SUPPORTED, - "Unsupported hypervisor: '%s'", prefix); - goto out; - } - - - if (s->rc != CMPI_RC_OK) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not get max nic count"); - goto out; - } - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Maximum", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&num_nics, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - out: - free(prefix); - return rasd; -} - -static struct sdc_rasd_prop *net_def(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - uint64_t num_nics = 1; - struct sdc_rasd_prop *rasd = NULL; - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Default", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&num_nics, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - -static struct sdc_rasd_prop *net_inc(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - uint64_t num_nics = 1; - struct sdc_rasd_prop *rasd = NULL; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Increment", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&num_nics, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - static int get_disk_freespace(const CMPIObjectPath *ref, CMPIStatus *s, uint64_t *free_space) @@ -985,177 +658,6 @@ out: return rasd; } - -static struct sdc_rasd_prop *disk_min(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - uint64_t disk_size = SDC_DISK_MIN; - struct sdc_rasd_prop *rasd = NULL; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Minimum", CMPI_chars}, - {"AllocationQuantity", (CMPIValue *)"MegaBytes", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&disk_size, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - -static struct sdc_rasd_prop *disk_max(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - const char *inst_id; - CMPIrc prop_ret; - uint64_t free_space; - virConnectPtr conn; - CMPIInstance *pool_inst; - struct sdc_rasd_prop *rasd = NULL; - - if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not get InstanceID"); - goto out; - } - - conn = connect_by_classname(_BROKER, CLASSNAME(ref), s); - if (s->rc != CMPI_RC_OK) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not get connection"); - goto out; - } - - /* Getting the relevant resource pool directly finds the free space - for us. It is in the Capacity field. */ - *s = get_pool_by_name(_BROKER, ref, inst_id, &pool_inst); - if (s->rc != CMPI_RC_OK) - goto out; - - prop_ret = cu_get_u64_prop(pool_inst, "Capacity", &free_space); - if (prop_ret != CMPI_RC_OK) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not get capacity from instance"); - goto out; - } - CU_DEBUG("Got capacity from pool_inst: %lld", free_space); - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Maximum", CMPI_chars}, - {"AllocationQuantity", (CMPIValue *)"MegaBytes", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&free_space, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - out: - return rasd; -} - -static struct sdc_rasd_prop *disk_def(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - uint64_t disk_size = SDC_DISK_DEF; - struct sdc_rasd_prop *rasd = NULL; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Default", CMPI_chars}, - {"AllocationQuantity", (CMPIValue *)"MegaBytes", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&disk_size, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - -static struct sdc_rasd_prop *disk_inc(const CMPIObjectPath *ref, - CMPIStatus *s) -{ - bool ret; - uint64_t disk_size = SDC_DISK_INC; - struct sdc_rasd_prop *rasd = NULL; - - struct sdc_rasd_prop tmp[] = { - {"InstanceID", (CMPIValue *)"Increment", CMPI_chars}, - {"AllocationQuantity", (CMPIValue *)"MegaBytes", CMPI_chars}, - {"VirtualQuantity", (CMPIValue *)&disk_size, CMPI_uint64}, - PROP_END - }; - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - - return rasd; -} - -static struct sdc_rasd mem = { - .resource_type = CIM_RES_TYPE_MEM, - .min = mem_min, - .max = mem_max, - .def = mem_def, - .inc = mem_inc -}; - -static struct sdc_rasd processor = { - .resource_type = CIM_RES_TYPE_PROC, - .min = proc_min, - .max = proc_max, - .def = proc_def, - .inc = proc_inc -}; - -static struct sdc_rasd network = { - .resource_type = CIM_RES_TYPE_NET, - .min = net_min, - .max = net_max, - .def = net_def, - .inc = net_inc -}; - -static struct sdc_rasd disk = { - .resource_type = CIM_RES_TYPE_DISK, - .min = disk_min, - .max = disk_max, - .def = disk_def, - .inc = disk_inc -}; - -static struct sdc_rasd *sdc_rasd_list[] = { - &mem, - &processor, - &network, - &disk, - NULL -}; static CMPIInstance *sdc_rasd_inst(CMPIStatus *s, const CMPIObjectPath *ref, diff -r 5da8358fed0d -r 3e9ae5caaf70 src/Virt_SettingsDefineCapabilities.h --- a/src/Virt_SettingsDefineCapabilities.h Tue Sep 30 14:40:03 2008 -0700 +++ b/src/Virt_SettingsDefineCapabilities.h Tue Sep 30 14:40:04 2008 -0700 @@ -50,17 +50,6 @@ CMPIType type; }; -typedef struct sdc_rasd_prop *(*rasd_prop_func_t)(const CMPIObjectPath *ref, - CMPIStatus *s); - -struct sdc_rasd { - uint16_t resource_type; - rasd_prop_func_t min; - rasd_prop_func_t max; - rasd_prop_func_t def; - rasd_prop_func_t inc; -}; - /* * Local Variables: * mode: C

Kaitlin Rupert wrote:
Condensed the 4 functions (one for min, max, inc, and def for each resource type) into 1 function for each resource type. Condensing this removes the need for the sdc_rasd structs and the sdc_rasd_list.
The provider behavior should stay the same, the only change here is the layout of the code.
I'm planning on following this up with some fixes to the template RASDs that are generated. We're not setting the right properties for the template Disk RASDS. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (1)
-
Kaitlin Rupert