[Libvirt-cim] [PATCH 2 of 2] Expose template DiskPoolRASDs

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Mon Apr 27 23:41:10 UTC 2009


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1240874183 25200
# Node ID 68e42eb53c400352e42e8fc194de7b02073dc1c6
# Parent  1bce4b17fe0bef5d70dc5dd14a02cdfb56d173c8
Expose template DiskPoolRASDs

Signed-off-by: Kaitlin Rupert <karupert at 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)




More information about the Libvirt-cim mailing list