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

[libvirt] [PATCHv2 18/21] qemu: Implement the device parse callback and use it for interfaces



This patch implements the callback that is used to fill the qemu default
network card into the XML if none is specified.

Libvirt assumes that the network card for qemu if none specified is the
"rtl8139". Record this in the XML using the new callback to avoid user
confusion.
---
 src/qemu/qemu_conf.c   |  2 +-
 src/qemu/qemu_domain.c | 25 +++++++++++++++++++++++++
 src/qemu/qemu_domain.h |  1 +
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index ef592cd..b9b7357 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -555,7 +555,7 @@ virDomainXMLConfPtr
 virQEMUDriverCreateXMLConf(void)
 {
     return virDomainXMLConfNew(&virQEMUDriverPrivateDataCallbacks,
-                               NULL,
+                               &virQEMUDriverDomainDefAdjustCallbacks,
                                &virQEMUDriverDomainXMLNamespace);
 }

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2be207f..02ef24e 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -646,6 +646,7 @@ qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
     return 0;
 }

+
 static const char *
 qemuDomainDefNamespaceHref(void)
 {
@@ -661,6 +662,30 @@ virDomainXMLNamespace virQEMUDriverDomainXMLNamespace = {
 };


+static int
+qemuDomainDeviceDefAdjust(virDomainDeviceDefPtr dev,
+                          virDomainDefPtr def ATTRIBUTE_UNUSED,
+                          virCapsPtr caps ATTRIBUTE_UNUSED)
+{
+    if (dev->type == VIR_DOMAIN_DEVICE_NET &&
+        dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+        if (!dev->data.net->model &&
+            !(dev->data.net->model = strdup("rtl8139")))
+                goto no_memory;
+    }
+    return 0;
+
+no_memory:
+    virReportOOMError();
+    return -1;
+}
+
+
+virDomainDefAdjustCallbacks virQEMUDriverDomainDefAdjustCallbacks = {
+    .devices = qemuDomainDeviceDefAdjust,
+};
+
+
 static void
 qemuDomainObjSaveJob(virQEMUDriverPtr driver, virDomainObjPtr obj)
 {
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 3a12b45..05a9daf 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -339,5 +339,6 @@ void qemuDomainCleanupRun(virQEMUDriverPtr driver,

 extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
 extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
+extern virDomainDefAdjustCallbacks virQEMUDriverDomainDefAdjustCallbacks;

 #endif /* __QEMU_DOMAIN_H__ */
-- 
1.8.1.1


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