[Libvirt-cim] [PATCH 1 of 5] Add device attach/detach support to device_parsing

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


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1194454604 28800
# Node ID b9eaad2ace9b71f7c6cb9feb3b6ea630050e3e0f
# Parent  2626820d78b2d70564096dcacf6a2f1b2bc726e1
Add device attach/detach support to device_parsing

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

diff -r 2626820d78b2 -r b9eaad2ace9b libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c	Wed Nov 07 08:52:51 2007 -0800
+++ b/libxkutil/device_parsing.c	Wed Nov 07 08:56:44 2007 -0800
@@ -31,6 +31,7 @@
 #include <libcmpiutil.h>
 
 #include "device_parsing.h"
+#include "xmlgen.h"
 #include "../src/svpc_types.h"
 
 #define DISK_XPATH      (xmlChar *)"/domain/devices/disk"
@@ -614,6 +615,60 @@ void cleanup_dominfo(struct domain **dom
         *dominfo = NULL;
 }
 
+static int change_device(virDomainPtr dom,
+                         struct virt_device *dev,
+                         bool attach)
+{
+        char *xml = NULL;
+        int ret = 0;
+        int (*func)(virDomainPtr, char *);
+
+        if (attach)
+                func = virDomainAttachDevice;
+        else
+                func = virDomainDetachDevice;
+
+        xml = device_to_xml(dev);
+        if (xml == NULL) {
+                CU_DEBUG("Failed to get XML for device `%s'", dev->id);
+                goto out;
+        }
+
+        if (func(dom, xml) != 0) {
+                CU_DEBUG("Failed to dynamically change device:");
+                CU_DEBUG("%s", xml);
+                goto out;
+        }
+
+        ret = 1;
+ out:
+        free(xml);
+
+        return ret;
+
+}
+
+int attach_device(virDomainPtr dom, struct virt_device *dev)
+{
+        if ((dev->type == VIRT_DEV_NET) ||
+            (dev->type == VIRT_DEV_DISK))
+                return change_device(dom, dev, true);
+
+        CU_DEBUG("Unhandled device type %i", dev->type);
+
+        return 0;
+}
+
+int detach_device(virDomainPtr dom, struct virt_device *dev)
+{
+        if ((dev->type == VIRT_DEV_NET) ||
+            (dev->type == VIRT_DEV_DISK))
+                return change_device(dom, dev, false);
+
+        CU_DEBUG("Unhandled device type %i", dev->type);
+
+        return 0;
+}
 
 /*
  * Local Variables:
diff -r 2626820d78b2 -r b9eaad2ace9b libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h	Wed Nov 07 08:52:51 2007 -0800
+++ b/libxkutil/device_parsing.h	Wed Nov 07 08:56:44 2007 -0800
@@ -111,6 +111,9 @@ char *get_fq_devid(char *host, char *_de
 char *get_fq_devid(char *host, char *_devid);
 int parse_fq_devid(char *devid, char **host, char **device);
 
+int attach_device(virDomainPtr dom, struct virt_device *dev);
+int detach_device(virDomainPtr dom, struct virt_device *dev);
+
 #endif
 
 /*
diff -r 2626820d78b2 -r b9eaad2ace9b libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c	Wed Nov 07 08:52:51 2007 -0800
+++ b/libxkutil/xmlgen.c	Wed Nov 07 08:56:44 2007 -0800
@@ -192,7 +192,7 @@ static char *mem_to_xml(struct mem_devic
         return xml;
 }
 
-static char *device_to_xml(struct virt_device *dev)
+char *device_to_xml(struct virt_device *dev)
 {
         switch (dev->type) {
         case VIRT_DEV_NET:
diff -r 2626820d78b2 -r b9eaad2ace9b libxkutil/xmlgen.h
--- a/libxkutil/xmlgen.h	Wed Nov 07 08:52:51 2007 -0800
+++ b/libxkutil/xmlgen.h	Wed Nov 07 08:56:44 2007 -0800
@@ -31,5 +31,6 @@ struct kv {
 };
 
 char *system_to_xml(struct domain *dominfo);
+char *device_to_xml(struct virt_device *dev);
 
 #endif




More information about the Libvirt-cim mailing list