7a3408
From 37d9c7b752e9bda93e5f15e1ac97dcb614e6b978 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <37d9c7b752e9bda93e5f15e1ac97dcb614e6b978@dist-git>
7a3408
From: Andrea Bolognani <abologna@redhat.com>
7a3408
Date: Fri, 11 Sep 2015 17:00:20 +0200
7a3408
Subject: [PATCH] qemu: Try several network devices when looking for a default
7a3408
7a3408
Up until now, the default has been rtl8139, but no check was in
7a3408
place to make sure that device was actually available.
7a3408
7a3408
Now we try rtl8139, e1000 and virtio-net in turn, checking for
7a3408
availability before using any of them: this means we have a much
7a3408
better chance for the guest to be able to boot.
7a3408
7a3408
(cherry picked from commit 75036c69df7a64f97f3716396f34f78de027f38b)
7a3408
7a3408
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1254044
7a3408
7a3408
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_domain.c | 26 +++++++++++++++++++++++---
7a3408
 1 file changed, 23 insertions(+), 3 deletions(-)
7a3408
7a3408
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
7a3408
index 66d8e3a..e4a9c55 100644
7a3408
--- a/src/qemu/qemu_domain.c
7a3408
+++ b/src/qemu/qemu_domain.c
7a3408
@@ -1174,7 +1174,8 @@ qemuDomainDefPostParse(virDomainDefPtr def,
7a3408
 }
7a3408
 
7a3408
 static const char *
7a3408
-qemuDomainDefaultNetModel(const virDomainDef *def)
7a3408
+qemuDomainDefaultNetModel(const virDomainDef *def,
7a3408
+                          virQEMUCapsPtr qemuCaps)
7a3408
 {
7a3408
     if (ARCH_IS_S390(def->os.arch))
7a3408
         return "virtio";
7a3408
@@ -1192,6 +1193,18 @@ qemuDomainDefaultNetModel(const virDomainDef *def)
7a3408
         return "lan9118";
7a3408
     }
7a3408
 
7a3408
+    /* Try several network devices in turn; each of these devices is
7a3408
+     * less likely be supported out-of-the-box by the guest operating
7a3408
+     * system than the previous one */
7a3408
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_RTL8139))
7a3408
+        return "rtl8139";
7a3408
+    else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_E1000))
7a3408
+        return "e1000";
7a3408
+    else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_NET))
7a3408
+        return "virtio";
7a3408
+
7a3408
+    /* We've had no luck detecting support for any network device,
7a3408
+     * but we have to return something: might as well be rtl8139 */
7a3408
     return "rtl8139";
7a3408
 }
7a3408
 
7a3408
@@ -1201,18 +1214,24 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
7a3408
                              virCapsPtr caps ATTRIBUTE_UNUSED,
7a3408
                              void *opaque)
7a3408
 {
7a3408
-    int ret = -1;
7a3408
     virQEMUDriverPtr driver = opaque;
7a3408
+    virQEMUCapsPtr qemuCaps = NULL;
7a3408
     virQEMUDriverConfigPtr cfg = NULL;
7a3408
+    int ret = -1;
7a3408
 
7a3408
     if (driver)
7a3408
         cfg = virQEMUDriverGetConfig(driver);
7a3408
 
7a3408
+    /* This condition is actually a (temporary) hack for test suite which
7a3408
+     * does not create capabilities cache */
7a3408
+    if (driver && driver->qemuCapsCache)
7a3408
+        qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator);
7a3408
+
7a3408
     if (dev->type == VIR_DOMAIN_DEVICE_NET &&
7a3408
         dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
7a3408
         !dev->data.net->model) {
7a3408
         if (VIR_STRDUP(dev->data.net->model,
7a3408
-                       qemuDomainDefaultNetModel(def)) < 0)
7a3408
+                       qemuDomainDefaultNetModel(def, qemuCaps)) < 0)
7a3408
             goto cleanup;
7a3408
     }
7a3408
 
7a3408
@@ -1338,6 +1357,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
7a3408
     ret = 0;
7a3408
 
7a3408
  cleanup:
7a3408
+    virObjectUnref(qemuCaps);
7a3408
     virObjectUnref(cfg);
7a3408
     return ret;
7a3408
 }
7a3408
-- 
7a3408
2.5.2
7a3408