[PATCH 20/21] Added implementation for virDomainAttachDevice and virDomainAttachDeviceFlags (required xmlopt in private structure)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: yvinter <yves.vinter@xxxxxxxx>

---
 src/hyperv/hyperv_driver.c  | 81 +++++++++++++++++++++++++++++++++++++++++++++
 src/hyperv/hyperv_private.h |  2 ++
 2 files changed, 83 insertions(+)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 8b8e612..8e0d6b3 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -62,6 +62,9 @@ hypervFreePrivate(hypervPrivate **priv)
     if ((*priv)->caps != NULL)
         virObjectUnref((*priv)->caps);
 
+    if ((*priv)->xmlopt != NULL)
+        virObjectUnref((*priv)->xmlopt);
+
     hypervFreeParsedUri(&(*priv)->parsedUri);
     VIR_FREE(*priv);
 }
@@ -206,6 +209,9 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags
         goto cleanup;
     }
 
+    /* Init xmlopt to parse Domain XML */
+    priv->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL);
+
     conn->privateData = priv;
     priv = NULL;
     result = VIR_DRV_OPEN_SUCCESS;
@@ -3019,6 +3025,79 @@ hypervDomainAttachNetwork(virDomainPtr domain, virDomainNetDefPtr net)
 
 
 
+static int
+hypervDomainAttachDeviceFlags(virDomainPtr domain, const char *xml,
+                              unsigned int flags ATTRIBUTE_UNUSED)
+{
+    int result = -1;
+    hypervPrivate *priv = domain->conn->privateData;
+    virDomainDefPtr def = NULL;
+    virDomainDeviceDefPtr dev = NULL;
+    char *xmlDomain = NULL;
+    
+    /* Get domain definition */
+    if ((xmlDomain = hypervDomainGetXMLDesc(domain, 0)) == NULL) {
+        goto cleanup;
+    }
+    if ((def = virDomainDefParseString(xmlDomain, priv->caps, priv->xmlopt,
+                                       1 << VIR_DOMAIN_VIRT_HYPERV, VIR_DOMAIN_XML_INACTIVE)) == NULL) {
+        goto cleanup;
+    }
+    
+    /* Get domain device definition */
+    if ((dev = virDomainDeviceDefParse(xml, def, priv->caps,
+                                       priv->xmlopt, VIR_DOMAIN_XML_INACTIVE)) == NULL) {
+        goto cleanup;
+    }
+    
+    switch (dev->type) {
+        /* Device = disk */
+        case VIR_DOMAIN_DEVICE_DISK:
+            if (hypervDomainAttachDisk(domain, dev->data.disk) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Could not attach disk"));
+                goto cleanup;
+            }
+            VIR_DEBUG("Disk attached");
+            break;
+        
+        /* Device = network */
+        case VIR_DOMAIN_DEVICE_NET:
+            if (hypervDomainAttachNetwork(domain, dev->data.net) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Could not attach network"));
+                goto cleanup;
+            }
+            VIR_DEBUG("Network attached");
+            break;
+        
+        /* Unsupported device type */
+        default:
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Device attachment of type %d is not implemented"), dev->type);
+            goto cleanup;
+    }
+    
+    result = 0;
+    
+ cleanup:
+    virDomainDefFree(def);
+    virDomainDeviceDefFree(dev);
+    VIR_FREE(xmlDomain);
+
+    return result;
+}
+
+
+
+static int
+hypervDomainAttachDevice(virDomainPtr domain, const char *xml)
+{
+    return hypervDomainAttachDeviceFlags(domain, xml, 0);
+}
+
+
+
 static virDriver hypervDriver = {
     .no = VIR_DRV_HYPERV,
     .name = "Hyper-V",
@@ -3075,6 +3154,8 @@ static virDriver hypervDriver = {
     .domainSetVcpusFlags = hypervDomainSetVcpusFlags, /* 1.2.10 */
     .domainUndefine = hypervDomainUndefine, /* 1.2.10 */
     .domainUndefineFlags = hypervDomainUndefineFlags, /* 1.2.10 */
+    .domainAttachDevice = hypervDomainAttachDevice, /* 1.2.10 */
+    .domainAttachDeviceFlags = hypervDomainAttachDeviceFlags, /* 1.2.10 */
 };
 
 
diff --git a/src/hyperv/hyperv_private.h b/src/hyperv/hyperv_private.h
index d9aa0bd..2dfce6e 100644
--- a/src/hyperv/hyperv_private.h
+++ b/src/hyperv/hyperv_private.h
@@ -27,6 +27,7 @@
 # include "virerror.h"
 # include "hyperv_util.h"
 # include "capabilities.h"
+# include "domain_conf.h"
 # include "openwsman.h"
 
 typedef struct _hypervPrivate hypervPrivate;
@@ -35,6 +36,7 @@ struct _hypervPrivate {
     hypervParsedUri *parsedUri;
     WsManClient *client;
     virCapsPtr caps;
+    virDomainXMLOptionPtr xmlopt;
 };
 
 #endif /* __HYPERV_PRIVATE_H__ */
-- 
1.9.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]