[Libvirt-cim] [PATCH 1 of 3] Added support to convert data in the internal format to the format used by the BootDevices property

Richard Maciel rmaciel at linux.vnet.ibm.com
Thu Jun 4 22:27:30 UTC 2009


# HG changeset patch
# User Richard Maciel <rmaciel at linux.vnet.ibm.com>
# Date 1243891178 10800
# Node ID dc7ef55a1fe9870280e369096a4ed267e3eaa4ec
# Parent  849171d2fbc0adbba613516bbdea4b78199178dd
Added support to convert data in the internal format to the format used by the BootDevices property

#2:
 - Code style changes
 - Added cu_statusf() calls to provide specific error messages to the user

#3:
 - cu_statusf() calls now use the local broker instead of the global one

Signed-off-by: Richard Maciel <rmaciel at linux.vnet.ibm.com>

diff -r 849171d2fbc0 -r dc7ef55a1fe9 schema/VSSD.mof
--- a/schema/VSSD.mof	Mon Jun 01 14:01:21 2009 -0700
+++ b/schema/VSSD.mof	Mon Jun 01 18:19:38 2009 -0300
@@ -27,7 +27,7 @@
 
   [Description ("The device to boot from when in fully-virtualized mode."
                 "One of hd,fd,cdrom.")]
-  string BootDevice;
+  string BootDevices[];
 
   [Description ("The emulator the guest should use during runtime.")]
   string Emulator;
@@ -42,8 +42,8 @@
 class KVM_VirtualSystemSettingData : Virt_VirtualSystemSettingData
 {
 
-  [Description ("The device to boot from.  One of hd,fd,cdrom.")]
-  string BootDevice;
+  [Description ("The list of devices to boot from. hd,fd,cdrom.")]
+  string BootDevices[];
 
   [Description ("The emulator the guest should use during runtime.")]
   string Emulator;
diff -r 849171d2fbc0 -r dc7ef55a1fe9 src/Virt_VSSD.c
--- a/src/Virt_VSSD.c	Mon Jun 01 14:01:21 2009 -0700
+++ b/src/Virt_VSSD.c	Mon Jun 01 18:19:38 2009 -0300
@@ -38,20 +38,91 @@
 
 const static CMPIBroker *_BROKER;
 
-static void _set_fv_prop(struct domain *dominfo,
-                         CMPIInstance *inst)
+static CMPIStatus _set_fv_prop(const CMPIBroker *broker,
+                               struct domain *dominfo,
+                               CMPIInstance *inst)
 {
         bool fv = true;
+        CMPIArray *array;
+        CMPICount bl_ct;
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        CMPICount i;
 
         if (dominfo->type == DOMAIN_XENFV)
                 CMSetProperty(inst, "IsFullVirt",
                               (CMPIValue *)&fv, CMPI_boolean);
 
-        if (dominfo->os_info.fv.boot != NULL)
-                CMSetProperty(inst,
-                              "BootDevice",
-                              (CMPIValue *)dominfo->os_info.fv.boot,
-                              CMPI_chars);
+        bl_ct = dominfo->os_info.fv.bootlist_ct;
+        if (bl_ct < 0) 
+                return s;
+
+        CU_DEBUG("bootlist_ct = %d", bl_ct);
+                
+        array = CMNewArray(broker, 
+                           bl_ct,
+                           CMPI_string,
+                           &s);
+
+        if (s.rc != CMPI_RC_OK) {
+                cu_statusf(broker, &s, 
+                           CMPI_RC_ERR_FAILED, 
+                           "Error creating BootDevices list");
+                CU_DEBUG("CMNewArray call failed");
+
+                goto out;
+        }
+
+        for (i = 0; i < bl_ct; i++) {
+                CMPIString *cm_str;
+
+                CU_DEBUG("BootList[%u]=%s",
+                         i,
+                         dominfo->os_info.fv.bootlist[i]);
+
+                cm_str = CMNewString(broker,
+                                     (const char *)dominfo->os_info.
+                                     fv.bootlist[i],
+                                     &s);
+                if (s.rc != CMPI_RC_OK) {
+                        CU_DEBUG("Error creating CMPIString");
+                        cu_statusf(broker, &s, 
+                                   CMPI_RC_ERR_FAILED, 
+                                   "Error creating CMPIString for " 
+                                   "BootDevices item");
+
+                        goto out;
+                }
+
+                s = CMSetArrayElementAt(array,
+                                        i,
+                                        (CMPIValue *)&cm_str,
+                                        CMPI_string);
+                if (s.rc != CMPI_RC_OK) {
+                        CU_DEBUG("Error in CMSetArrayElementAT call");
+                        cu_statusf(broker, &s, 
+                                   CMPI_RC_ERR_FAILED, 
+                                   "Error setting BootDevices array element");
+
+                        goto out;
+                }
+        }
+
+        s = CMSetProperty(inst,
+                          "BootDevices",
+                          (CMPIValue *)&array,
+                          CMPI_stringA);
+
+        if (s.rc != CMPI_RC_OK) {
+                CU_DEBUG("Error in CMSetProperty call");
+                cu_statusf(broker, &s, 
+                           CMPI_RC_ERR_FAILED, 
+                           "Error setting BootDevices property");
+
+                goto out;
+        }
+
+ out:
+        return s;
 }
 
 static void _set_pv_prop(struct domain *dominfo,
@@ -98,12 +169,14 @@
                               CMPI_chars);
 }
 
-static int instance_from_dom(virDomainPtr dom,
+static int instance_from_dom(const CMPIBroker *broker,
+                             virDomainPtr dom,
                              CMPIInstance *inst)
 {
         char *pfx = NULL;
         char *vsid = NULL;
         int ret = 1;
+        CMPIStatus s = {CMPI_RC_OK, NULL};
         CMPIObjectPath *op;
         struct domain *dominfo = NULL;
 
@@ -158,7 +231,12 @@
 
         if ((dominfo->type == DOMAIN_XENFV) ||
             (dominfo->type == DOMAIN_KVM) || (dominfo->type == DOMAIN_QEMU))
-                _set_fv_prop(dominfo, inst);
+                s = _set_fv_prop(broker, dominfo, inst);
+                if (s.rc != CMPI_RC_OK) {
+                        ret = 0;
+                        goto out;
+                }
+
         else if (dominfo->type == DOMAIN_XENPV)
                 _set_pv_prop(dominfo, inst);
         else if (dominfo->type == DOMAIN_LXC)
@@ -203,7 +281,7 @@
                 goto out;
         }
         
-        if (instance_from_dom(dom, inst) != 1) {
+        if (instance_from_dom(broker, dom, inst) != 1) {
                 cu_statusf(broker, s,
                            CMPI_RC_ERR_FAILED,
                            "Unable to get VSSD instance from Domain");




More information about the Libvirt-cim mailing list