[PATCH 0 of 2] Add support for primordial parent pool

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1240874036 25200 # Node ID 1bce4b17fe0bef5d70dc5dd14a02cdfb56d173c8 # Parent e5000891e231e6b9896786e48442ef98bfe9f9fd Create parent diskpool DSP1041 states that all pool allocations will occur from a parent, primordial pool. This patch adds the parent pool for disk pools. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r e5000891e231 -r 1bce4b17fe0b src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Mon Apr 20 11:02:52 2009 -0700 +++ b/src/Virt_DevicePool.c Mon Apr 27 16:13:56 2009 -0700 @@ -48,6 +48,7 @@ struct disk_pool { char *tag; char *path; + bool primordial; }; /* @@ -60,6 +61,36 @@ # define VIR_USE_LIBVIRT_STORAGE 0 #endif +static bool get_disk_parent(struct disk_pool **_pools, + int *_count) +{ + struct disk_pool *pools = NULL; + int ret = false; + int count; + + count = *_count; + pools = *_pools; + + pools = realloc(pools, (count + 1) * (sizeof(*pools))); + if (pools == NULL) { + CU_DEBUG("Failed to alloc new pool"); + goto out; + } + + pools[count].tag = strdup("Parent"); + pools[count].path = NULL; + pools[count].primordial = true; + count++; + + *_count = count; + *_pools = pools; + ret = true; + + out: + return ret; +} + + #if VIR_USE_LIBVIRT_STORAGE static int get_diskpool_config(virConnectPtr conn, struct disk_pool **_pools) @@ -67,7 +98,7 @@ int count = 0; int i; char ** names = NULL; - struct disk_pool *pools; + struct disk_pool *pools = NULL; count = virConnectNumOfStoragePools(conn); if (count <= 0) @@ -91,11 +122,16 @@ goto out; } - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { pools[i].tag = names[i]; + pools[i].primordial = false; + } + + out: + get_disk_parent(&pools, &count); *_pools = pools; - out: + free(names); return count; @@ -180,6 +216,7 @@ free(pool->tag); free(pool->path); } + pools->primordial = false; return (ret == 2); } @@ -212,6 +249,8 @@ count++; } + + get_disk_parent(&pools, &count); out: free(line); *_pools = pools; @@ -831,6 +870,9 @@ set_params(inst, CIM_RES_TYPE_DISK, poolid, "Megabytes", pool->tag); + CMSetProperty(inst, "Primordial", + (CMPIValue *)&pool->primordial, CMPI_boolean); + if (!diskpool_set_capacity(conn, inst, pool)) CU_DEBUG("Failed to set capacity for disk pool: %s", pool->tag);

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1240874183 25200 # Node ID 68e42eb53c400352e42e8fc194de7b02073dc1c6 # Parent 1bce4b17fe0bef5d70dc5dd14a02cdfb56d173c8 Expose template DiskPoolRASDs Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 1bce4b17fe0b -r 68e42eb53c40 src/Virt_RASD.c --- a/src/Virt_RASD.c Mon Apr 27 16:13:56 2009 -0700 +++ b/src/Virt_RASD.c Mon Apr 27 16:16:23 2009 -0700 @@ -590,6 +590,21 @@ return rc; } +CMPIrc pool_rasd_classname_from_type(uint16_t type, const char **classname) +{ + CMPIrc rc = CMPI_RC_OK; + + switch(type) { + case CIM_RES_TYPE_DISK: + *classname = "DiskPoolResourceAllocationSettingData"; + break; + default: + rc = CMPI_RC_ERR_FAILED; + } + + return rc; +} + static CMPIStatus _get_rasds(const CMPIBroker *broker, const CMPIObjectPath *reference, const virDomainPtr dom, diff -r 1bce4b17fe0b -r 68e42eb53c40 src/Virt_RASD.h --- a/src/Virt_RASD.h Mon Apr 27 16:13:56 2009 -0700 +++ b/src/Virt_RASD.h Mon Apr 27 16:16:23 2009 -0700 @@ -48,6 +48,8 @@ CMPIrc res_type_from_rasd_classname(const char *cn, uint16_t *type); CMPIrc rasd_classname_from_type(uint16_t type, const char **cn); +CMPIrc pool_rasd_classname_from_type(uint16_t type, const char **classname); + CMPIStatus get_rasd_by_name(const CMPIBroker *broker, const CMPIObjectPath *reference, const char *name, diff -r 1bce4b17fe0b -r 68e42eb53c40 src/Virt_SettingsDefineCapabilities.c --- a/src/Virt_SettingsDefineCapabilities.c Mon Apr 27 16:13:56 2009 -0700 +++ b/src/Virt_SettingsDefineCapabilities.c Mon Apr 27 16:16:23 2009 -0700 @@ -40,6 +40,7 @@ #include "misc_util.h" #include <libcmpiutil/std_association.h> #include "device_parsing.h" +#include "pool_parsing.h" #include "svpc_types.h" #include "Virt_SettingsDefineCapabilities.h" @@ -68,6 +69,9 @@ #define SDC_DISK_DEF 5000 #define SDC_DISK_INC 250 +#define DEVICE_RASD 0 +#define POOL_RASD 1 + static bool system_has_vt(virConnectPtr conn) { char *caps = NULL; @@ -265,12 +269,19 @@ static CMPIInstance *sdc_rasd_inst(CMPIStatus *s, const CMPIObjectPath *ref, - uint16_t resource_type) + uint16_t resource_type, + uint16_t rasd_type) { CMPIInstance *inst = NULL; const char *base = NULL; + CMPIrc ret = 1; - if (rasd_classname_from_type(resource_type, &base) != CMPI_RC_OK) { + if (rasd_type == DEVICE_RASD) + ret = rasd_classname_from_type(resource_type, &base); + else if (rasd_type == POOL_RASD) + ret = pool_rasd_classname_from_type(resource_type, &base); + + if (ret != CMPI_RC_OK) { cu_statusf(_BROKER, s, CMPI_RC_ERR_FAILED, "Resource type not known"); @@ -329,7 +340,7 @@ goto out; } - inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_MEM); + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_MEM, DEVICE_RASD); if ((inst == NULL) || (s.rc != CMPI_RC_OK)) goto out; @@ -424,7 +435,7 @@ goto out; } - inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_PROC); + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_PROC, DEVICE_RASD); if ((inst == NULL) || (s.rc != CMPI_RC_OK)) goto out; @@ -534,7 +545,7 @@ CMPIInstance *inst; CMPIStatus s = {CMPI_RC_OK, NULL}; - inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_NET); + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_NET, DEVICE_RASD); if ((inst == NULL) || (s.rc != CMPI_RC_OK)) goto out; @@ -617,7 +628,7 @@ dev = "hda"; } - inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_DISK); + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_DISK, DEVICE_RASD); if ((inst == NULL) || (s.rc != CMPI_RC_OK)) goto out; @@ -1083,6 +1094,107 @@ } #endif +static CMPIStatus disk_pool_template(const CMPIObjectPath *ref, + int template_type, + struct inst_list *list) +{ + const char *id; + CMPIInstance *inst; + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *path = "/dev/null"; + const char *dev_path; + int type[2] = {DISK_POOL_DIR, DISK_POOL_FS}; + int pool_types = 2; + int i; + + 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; + } + + for (i = 0; i < pool_types; i++) { + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_DISK, POOL_RASD); + if ((inst == NULL) || (s.rc != CMPI_RC_OK)) + goto out; + + CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars); + + switch (type[i]) { + case DISK_POOL_FS: + dev_path = "/dev/sda100"; + CMSetProperty(inst, "DevicePath", + (CMPIValue *)dev_path, CMPI_chars); + break; + default: + break; + } + + CMSetProperty(inst, "Type", (CMPIValue *)&type[i], CMPI_uint16); + CMSetProperty(inst, "Path", (CMPIValue *)path, CMPI_chars); + + inst_list_add(list, inst); + } + + out: + return s; +} + +static CMPIStatus disk_dev_or_pool_template(const CMPIObjectPath *ref, + int template_type, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *poolid; + bool val; + + if (cu_get_str_path(ref, "InstanceID", &poolid) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing InstanceID"); + goto out; + } + + s = get_pool_by_name(_BROKER, ref, poolid, &inst); + if (s.rc != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get pool instance from capabilities"); + goto out; + } + + if (cu_get_bool_prop(inst, "Primordial", &val) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to determine pool type"); + goto out; + } + + if (val) + s = disk_pool_template(ref, template_type, list); + else + s = disk_template(ref, template_type, list); + + out: + + return s; +} + static CMPIStatus graphics_template(const CMPIObjectPath *ref, int template_type, struct inst_list *list) @@ -1112,7 +1224,7 @@ goto out; } - inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_GRAPHICS); + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_GRAPHICS, DEVICE_RASD); CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars); @@ -1156,7 +1268,7 @@ } } - inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_INPUT); + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_INPUT, DEVICE_RASD); if ((inst == NULL) || (s.rc != CMPI_RC_OK)) goto out; @@ -1280,7 +1392,7 @@ else if (type == CIM_RES_TYPE_NET) s = net_template(ref, i, list); else if (type == CIM_RES_TYPE_DISK) - s = disk_template(ref, i, list); + s = disk_dev_or_pool_template(ref, i, list); else if (type == CIM_RES_TYPE_GRAPHICS) s = graphics_template(ref, i, list); else if (type == CIM_RES_TYPE_INPUT)

\o/ Kaitlin Rupert wrote:
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel