[Libvirt-cim] [PATCH] Remove sdc_rasd_prop structs from SDC

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Thu Oct 2 18:05:25 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1222970713 25200
# Node ID a2759cb96488a8079a24d8c47223ca5c7c7f3524
# Parent  cbe9f59669b6b9342cf14db087139a302a1bff12
Remove sdc_rasd_prop structs from SDC

Instead, a pointer to CMPIInstance can be passed to the <>_template() functions, and the functional can be responsible for setting the properties directly.  Also, the functions will now return a CMPIStatus value instead of a sdc_rasd_prop struct.

This is more useful than structs because some of the property values may differ between the virtualization types.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r cbe9f59669b6 -r a2759cb96488 src/Virt_SettingsDefineCapabilities.c
--- a/src/Virt_SettingsDefineCapabilities.c	Mon Sep 15 14:44:37 2008 -0700
+++ b/src/Virt_SettingsDefineCapabilities.c	Thu Oct 02 11:05:13 2008 -0700
@@ -249,68 +249,13 @@
         return s;
 }
 
-static bool rasd_prop_copy_value(struct sdc_rasd_prop src, 
-                                 struct sdc_rasd_prop *dest)
+static CMPIStatus mem_template(const CMPIObjectPath *ref,
+                               int template_type,
+                               CMPIInstance *inst)
 {
-        bool rc = true;
-
-        CU_DEBUG("Copying '%s'", src.field);
-        if (src.type & CMPI_string) {
-                dest->value = (CMPIValue *)strdup((char *)src.value);
-        } else if (src.type & CMPI_INTEGER) {
-                dest->value = malloc(sizeof(CMPIValue));
-                memcpy(dest->value, src.value, sizeof(CMPIValue));
-        } else {
-                rc = false;
-        }
-
-        return rc;
-}
-
-static bool dup_rasd_prop_list(struct sdc_rasd_prop *src, 
-                               struct sdc_rasd_prop **dest)
-{
-        int count, i;
-        bool ret;
-        *dest = NULL;
-        
-        for (i = 0, count = 1; src[i].field != NULL; i++, count++) {
-                *dest = realloc(*dest, count * sizeof(struct sdc_rasd_prop));
-                (*dest)[i].field = strdup(src[i].field);
-                ret = rasd_prop_copy_value(src[i], &(*dest)[i]);
-                (*dest)[i].type = src[i].type;
-        }
-        
-        /* Make sure to terminate the list. */
-        *dest = realloc(*dest, count * sizeof(struct sdc_rasd_prop));
-        (*dest)[i] = (struct sdc_rasd_prop)PROP_END;
-
-        return true;
-}
-
-static void free_rasd_prop_list(struct sdc_rasd_prop *prop_list)
-{
-        int i;
-        
-        if (!prop_list)
-                return;
-
-        for (i = 0; prop_list[i].field != NULL; i++) {
-                free(prop_list[i].field);
-                free(prop_list[i].value);
-        }
-        
-        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;
+        CMPIStatus s = {CMPI_RC_OK, NULL};
 
         switch (template_type) {
         case SDC_RASD_MIN:
@@ -330,28 +275,20 @@
                 id = "Default";
                 break;
         default:
-                cu_statusf(_BROKER, s,
+                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");
-        }
+        CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars);
+        CMSetProperty(inst, "AllocationUnits", 
+                      (CMPIValue *)"KiloBytes", CMPI_chars);
+        CMSetProperty(inst, "VirtualQuantity", 
+                      (CMPIValue *)&mem_size, CMPI_uint64);
 
  out:
-        return rasd;
+        return s;
 }
 
 static bool get_max_procs(const CMPIObjectPath *ref,
@@ -377,14 +314,14 @@
        return ret;
 }
 
-static struct sdc_rasd_prop *proc_template(const CMPIObjectPath *ref,
-                                           int template_type,
-                                           CMPIStatus *s)
+static CMPIStatus proc_template(const CMPIObjectPath *ref,
+                                int template_type,
+                                CMPIInstance *inst)
 {
         bool ret;
         uint64_t num_procs;
         const char *id;
-        struct sdc_rasd_prop *rasd = NULL;
+        CMPIStatus s = {CMPI_RC_OK, NULL};
 
         switch (template_type) {
         case SDC_RASD_MIN:
@@ -392,7 +329,7 @@
                 id = "Minimum";
                 break;
         case SDC_RASD_MAX:
-                ret = get_max_procs(ref, &num_procs, s);
+                ret = get_max_procs(ref, &num_procs, &s);
                 if (!ret)
                     goto out;
                 id = "Maximum";
@@ -406,29 +343,20 @@
                 id = "Default";
                 break;
         default:
-                cu_statusf(_BROKER, s,
+                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");
-        }
+        CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars);
+        CMSetProperty(inst, "AllocationUnits", 
+                      (CMPIValue *)"Processors", CMPI_chars);
+        CMSetProperty(inst, "VirtualQuantity", 
+                      (CMPIValue *)&num_procs, CMPI_uint64);
 
  out:
-
-        return rasd;
+        return s;
 }
 
 static uint64_t net_max_xen(const CMPIObjectPath *ref,
@@ -508,14 +436,14 @@
         return ret;
 }
 
-static struct sdc_rasd_prop *net_template(const CMPIObjectPath *ref,
-                                          int template_type,
-                                          CMPIStatus *s)
+static CMPIStatus net_template(const CMPIObjectPath *ref,
+                               int template_type,
+                               CMPIInstance *inst)
 {
         bool ret;
         uint64_t num_nics;
         const char *id;
-        struct sdc_rasd_prop *rasd = NULL;
+        CMPIStatus s = {CMPI_RC_OK, NULL};
 
         switch (template_type) {
         case SDC_RASD_MIN:
@@ -523,7 +451,7 @@
                 id = "Minimum";
                 break;
         case SDC_RASD_MAX:
-                ret = get_max_nics(ref, &num_nics, s);
+                ret = get_max_nics(ref, &num_nics, &s);
                 if (!ret)
                     goto out;
                 id = "Maximum";
@@ -537,27 +465,18 @@
                 id = "Default";
                 break;
         default:
-                cu_statusf(_BROKER, s,
+                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");
-        }
+        CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars);
+        CMSetProperty(inst, "VirtualQuantity", 
+                      (CMPIValue *)&num_nics, CMPI_uint64);
 
  out:
-        return rasd;
+        return s;
 }
  
 static int get_disk_freespace(const CMPIObjectPath *ref,
@@ -606,14 +525,14 @@
         return ret;
 }
 
-static struct sdc_rasd_prop *disk_template(const CMPIObjectPath *ref,
-                                           int template_type,
-                                           CMPIStatus *s)
+static CMPIStatus disk_template(const CMPIObjectPath *ref,
+                                int template_type,
+                                CMPIInstance *inst)
 {
         bool ret;
         uint64_t disk_size;
         const char *id;
-        struct sdc_rasd_prop *rasd = NULL;
+        CMPIStatus s = {CMPI_RC_OK, NULL};
 
         switch(template_type) {
         case SDC_RASD_MIN:
@@ -621,7 +540,7 @@
                 id = "Minimum";
                 break;
         case SDC_RASD_MAX:
-                ret = get_disk_freespace(ref, s, &disk_size);
+                ret = get_disk_freespace(ref, &s, &disk_size);
                 if (!ret)
                     goto out;
                 id = "Maximum";
@@ -635,28 +554,20 @@
                 id = "Default";
                 break;
         default:
-                cu_statusf(_BROKER, s,
+                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");
-        }
+        CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars);
+        CMSetProperty(inst, "AllocationQuantity", 
+                      (CMPIValue *)"MegaBytes", CMPI_chars);
+        CMSetProperty(inst, "VirtualQuantity", 
+                      (CMPIValue *)&disk_size, CMPI_uint64);
 
  out:
-        return rasd;
+        return s;
 }
 
 static CMPIInstance *sdc_rasd_inst(CMPIStatus *s,
@@ -665,26 +576,7 @@
                                    uint16_t resource_type)
 {
         CMPIInstance *inst = NULL;
-        struct sdc_rasd_prop *prop_list = NULL;
-        int i;
         const char *base = NULL;
-
-        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 resource type");
-        }
-
-        if (s->rc != CMPI_RC_OK) 
-                goto out;
 
         if (rasd_classname_from_type(resource_type, &base) != CMPI_RC_OK) {
                 cu_statusf(_BROKER, s, 
@@ -697,17 +589,27 @@
                                   CLASSNAME(ref),
                                   base,
                                   NAMESPACE(ref));
-        
+
+        if (resource_type == CIM_RES_TYPE_MEM)
+                *s = mem_template(ref, type, inst);
+        else if (resource_type == CIM_RES_TYPE_PROC)
+                *s = proc_template(ref, type, inst);
+        else if (resource_type == CIM_RES_TYPE_NET)
+                *s = net_template(ref, type, inst);
+        else if (resource_type == CIM_RES_TYPE_DISK)
+                *s = disk_template(ref, type, inst);
+        else {
+                cu_statusf(_BROKER, s,
+                           CMPI_RC_ERR_FAILED,
+                           "Unsupported resource type");
+        }
+
+        if (s->rc != CMPI_RC_OK) 
+                goto out;
+
         CMSetProperty(inst, "ResourceType", &resource_type, CMPI_uint16);
 
-        for (i = 0; prop_list[i].field != NULL; i++) {
-                CU_DEBUG("Setting property '%s'", prop_list[i].field);
-                CMSetProperty(inst, prop_list[i].field, 
-                              prop_list[i].value, prop_list[i].type);
-        }
-
  out:
-        free_rasd_prop_list(prop_list);
         return inst;
 }
 
@@ -726,7 +628,7 @@
                         goto out;
                 }
                 CU_DEBUG("Got inst");
-                if (inst != NULL) {
+                if ((s.rc == CMPI_RC_OK) && (inst != NULL)) {
                         inst_list_add(list, inst);
                         CU_DEBUG("Added inst");
                 } else {
diff -r cbe9f59669b6 -r a2759cb96488 src/Virt_SettingsDefineCapabilities.h
--- a/src/Virt_SettingsDefineCapabilities.h	Mon Sep 15 14:44:37 2008 -0700
+++ b/src/Virt_SettingsDefineCapabilities.h	Thu Oct 02 11:05:13 2008 -0700
@@ -44,12 +44,6 @@
       SDC_RANGE_INC = 3,
 } range;
 
-struct sdc_rasd_prop {
-        char *field;
-        CMPIValue *value;
-        CMPIType type;
-};
-
 /*
  * Local Variables:
  * mode: C




More information about the Libvirt-cim mailing list