[Libvirt-cim] [PATCH 5 of 5] Make VSMS call the appropriate dynamic device functions

Dan Smith danms at us.ibm.com
Wed Nov 7 16:02:30 UTC 2007


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1194454866 28800
# Node ID 92ed39296eb881deddc2d34fa9ee0524aefc1a53
# Parent  e1c63130f720d975822d7c8e3c8ed35c8e18dd15
Make VSMS call the appropriate dynamic device functions

Signed-off-by: Dan Smith <danms at us.ibm.com>

diff -r e1c63130f720 -r 92ed39296eb8 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Wed Nov 07 08:57:10 2007 -0800
+++ b/src/Virt_VirtualSystemManagementService.c	Wed Nov 07 09:01:06 2007 -0800
@@ -563,6 +563,59 @@ static struct virt_device **find_list(st
         return list;
 }
 
+static CMPIStatus _resource_dynamic(struct domain *dominfo,
+                                    struct virt_device *dev,
+                                    bool attach)
+{
+        CMPIStatus s;
+        virConnectPtr conn;
+        virDomainPtr dom;
+        int (*func)(virDomainPtr, struct virt_device *);
+
+        if (attach)
+                func = attach_device;
+        else
+                func = detach_device;
+
+        conn = lv_connect(_BROKER, &s);
+        if (conn == NULL) {
+                CU_DEBUG("Failed to connect");
+                return s;
+        }
+
+        dom = virDomainLookupByName(conn, dominfo->name);
+        if (dom == NULL) {
+                CU_DEBUG("Failed to lookup VS `%s'", dominfo->name);
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_NOT_FOUND,
+                           "Virtual System `%s' not found", dominfo->name);
+                goto out;
+        }
+
+        if (!domain_online(dom)) {
+                CU_DEBUG("VS `%s' not online; skipping dynamic update",
+                         dominfo->name);
+                CMSetStatus(&s, CMPI_RC_OK);
+                goto out;
+        }
+
+        CU_DEBUG("Doing dynamic device update for `%s'", dominfo->name);
+
+        if (func(dom, dev) == 0) {
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Unable to %s device",
+                           attach ? "attach" : "detach");
+        } else {
+                CMSetStatus(&s, CMPI_RC_OK);
+        }
+ out:
+        virDomainFree(dom);
+        virConnectClose(conn);
+
+        return s;
+}
+
 static CMPIStatus resource_del(struct domain *dominfo,
                                CMPIInstance *rasd,
                                uint16_t type,
@@ -593,8 +646,8 @@ static CMPIStatus resource_del(struct do
                 struct virt_device *dev = &list[i];
 
                 if (STREQ(dev->id, devid)) {
+                        s = _resource_dynamic(dominfo, dev, false);
                         dev->type = VIRT_DEV_UNKNOWN;
-                        CMSetStatus(&s, CMPI_RC_OK);
                         break;
                 }
         }
@@ -611,6 +664,7 @@ static CMPIStatus resource_add(struct do
         CMPIStatus s;
         struct virt_device **_list;
         struct virt_device *list;
+        struct virt_device *dev;
         int *count;
 
         _list = find_list(dominfo, type, &count);
@@ -643,12 +697,19 @@ static CMPIStatus resource_add(struct do
         *_list = list;
         memset(&list[*count], 0, sizeof(list[*count]));
 
-        list[*count].type = type;
-        list[*count].id = strdup(devid);
-        rasd_to_vdev(rasd, &list[*count]);
+        dev = &list[*count];
+
+        dev->type = type;
+        dev->id = strdup(devid);
+        rasd_to_vdev(rasd, dev);
+
+        s = _resource_dynamic(dominfo, dev, true);
+        if (s.rc != CMPI_RC_OK)
+                goto out;
+
+        CMSetStatus(&s, CMPI_RC_OK);
         (*count)++;
 
-        CMSetStatus(&s, CMPI_RC_OK);
  out:
         return s;
 }
@@ -728,6 +789,10 @@ static CMPIStatus _update_resources_for(
         }
 
         s = func(dominfo, rasd, type, devid);
+        if (s.rc != CMPI_RC_OK) {
+                CU_DEBUG("Resource transform function failed");
+                goto out;
+        }
 
         xml = system_to_xml(dominfo);
         if (xml != NULL) {




More information about the Libvirt-cim mailing list