Richard Maciel wrote:
# HG changeset patch
# User Richard Maciel <rmaciel(a)linux.vnet.ibm.com>
# Date 1236119796 10800
# Node ID 3b757b1d572ed9a6bc84a767140ae48c047027b0
# Parent 9010a4ffa133439c3e66a64552840e2a76ef9ad9
(#3) Changed the output of AllocationCapability association when using DiskPool as input
This patch fix the results of a 'association instances' query when passing a disk
pool AllocationCapabilities reference as input. Before this patch, this query returned
RASD templates for the disk pools, but now it returns the RASD templates for each of the
volumes which composes the disk pool passed as input.
3:
- Kept code for versions which doesn't support disk pools
This approach leaves a lot of redundant code. There aren't alot of
differences in the two versions of set_disk_props(). So any time there
is a change in the way we set a given attribute (or a new attribute,
etc), we'd need to modify both code paths...
It seems like only the disk_template() function needs to differ.. what
about something like:
When disk pool support doesn't exist:
1) Call default_disk_template()
2) if virt_type != LXC:
Call cdrom_template()
When disk pool support exists:
1) if virt_type == LXC:
Call _disk_template()
2) Do the storage volume look up
3) Call volume_template()
4) Call cdrom_template()
Then default_disk_template() would look like what disk_template() looks
like in the current code.
Does this seem reasonable?
+static CMPIStatus cdrom_template(const CMPIObjectPath *ref,
+ int template_type,
+ struct inst_list *list)
+{
+ char *pfx;
+ const char *id;
+ char *vol_path;
This can be a const - otherwise it needs to be freed before exiting the
function.
+ uint64_t vol_size = 0;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ uint16_t emu_type = 1;
+
+ switch(template_type) {
+ case SDC_RASD_MIN:
+ id = "Minimum CDROM";
+ break;
+ case SDC_RASD_MAX:
+ id = "Maximum CDROM";
+ break;
+ case SDC_RASD_INC:
+ id = "Increment CDROM";
+ break;
+ case SDC_RASD_DEF:
+ id = "Default CDROM";
+ break;
+ default:
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unsupported sdc_rasd type");
+ goto out;
+ }
+
+ vol_path = "/dev/null";
+
+ pfx = class_prefix_name(CLASSNAME(ref));
pfx isn't freed.
+
+ if (STREQ(pfx, "Xen")) {
+ int xen_type[2] = {DOMAIN_XENFV, DOMAIN_XENPV};
+ int i = 0;
+ for (; i < 2; i++) {
+ s = set_disk_props(xen_type[i],
+ ref,
+ id,
+ vol_path,
+ vol_size,
+ emu_type,
+ list);
+ }
+ } else if (STREQ(pfx, "KVM")) {
+ s = set_disk_props(DOMAIN_KVM,
+ ref,
+ id,
+ vol_path,
+ vol_size,
+ emu_type,
+ list);
+
+ } else if (!STREQ(pfx, "LXC")){
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unsupported virtualization type");
+ }
+
+ out:
+ return s;
+
+}
+
+
+static CMPIStatus volume_template(const CMPIObjectPath *ref,
+ int template_type,
+ virStorageVolPtr volume_ptr,
+ struct inst_list *list)
+{
+ char *pfx;
+ const char *id;
+ char *vol_path;
+ uint64_t vol_size;
+ virStorageVolInfo vol_info;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ int ret;
+ uint16_t emu_type = 0;
+
+ ret = virStorageVolGetInfo(volume_ptr, &vol_info);
+ if (ret == -1) {
+ virt_set_status(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ virStorageVolGetConnect(volume_ptr),
+ "Unable to get volume information");
+ goto out;
+ }
+
+ switch(template_type) {
+ case SDC_RASD_MIN:
+ if (SDC_DISK_MIN > (uint64_t)vol_info.capacity)
+ vol_size = (uint64_t)vol_info.capacity;
+ else
+ vol_size = SDC_DISK_MIN;
+ id = "Minimum";
+ break;
+ case SDC_RASD_MAX:
+ vol_size = (uint64_t)vol_info.capacity;
+ id = "Maximum";
+ break;
+ case SDC_RASD_INC:
+ vol_size = SDC_DISK_INC;
+ id = "Increment";
+ break;
+ case SDC_RASD_DEF:
+ vol_size = (uint64_t)vol_info.allocation;
+ id = "Default";
+ break;
+ default:
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unsupported sdc_rasd type");
+ goto out;
+ }
+
+ vol_path = virStorageVolGetPath(volume_ptr);
This needs to be freed before exiting.
+ if (vol_path == NULL) {
+ virt_set_status(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ virStorageVolGetConnect(volume_ptr),
+ "Unable to get volume path");
+ goto out;
+ }
+
+ pfx = class_prefix_name(CLASSNAME(ref));
Needs to be freed before exiting.
+static CMPIStatus lxc_template(const CMPIObjectPath *ref,
+ int template_type,
+ struct inst_list *list)
+{
+ uint64_t vol_size = 0;
+ int emu_type = 0;
+ char *vol_path = "/tmp";
Declare this as a const.
+ const char *id;
+
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+
+ switch(template_type) {
+ case SDC_RASD_MIN:
+ id = "Minimum";
+ break;
+ case SDC_RASD_MAX:
+ id = "Maximum";
+ break;
+ case SDC_RASD_INC:
+ id = "Increment";
+ break;
+ case SDC_RASD_DEF:
+ id = "Default";
+ break;
+ default:
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unsupported sdc_rasd type");
+ goto out;
+ }
+
+ s = set_disk_props(DOMAIN_LXC,
+ ref,
+ id,
+ vol_path,
+ vol_size,
+ emu_type,
+ list);
+
+ out:
+ return s;
+
+}
+
+static CMPIStatus disk_template(const CMPIObjectPath *ref,
+ int template_type,
+ struct inst_list *list)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ virConnectPtr conn = NULL;
+ virStoragePoolPtr poolptr = NULL;
+ virStorageVolPtr volptr = NULL;
+ const char *instid = NULL;
+ char *host = NULL;
+ const char *poolname = NULL;
+ char **volnames = NULL;
+ int numvols = 0;
+ int numvolsret = 0;
+ int i;
+ char *pfx = NULL;
+
+ pfx = class_prefix_name(CLASSNAME(ref));
Free this before exiting the function.
+ if (STREQ(pfx, "LXC")) {
+ s = lxc_template(ref, template_type, list);
+ goto out;
+ }
+
+ conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
+
+ if (cu_get_str_path(ref, "InstanceID", &instid) != CMPI_RC_OK) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get InstanceID for disk device");
+ goto out;
+ }
+
+ if (parse_fq_devid(instid, &host, (char **)&poolname) != 1) {
Free host before exiting the function.
--
Kaitlin Rupert
IBM Linux Technology Center
kaitlin(a)linux.vnet.ibm.com