[libvirt] [PATCH v3 0/4] Try several possible default network devices

Changes in v3: * detect rtl8139 and e1000 availability as well * don't try to use virtio-net based on availability alone: try rtl8139, e1000 and virtio-net in this order instead * patch 4/4 contains an ugly bit we'll be able to get rid of once capabilities can be properly mocked in the test suite Changes in v2[1]: * detect virtio-net availability * try to user it if available Cheers. [1] https://www.redhat.com/archives/libvir-list/2015-September/msg00058.html Andrea Bolognani (4): qemu: Introduce QEMU_CAPS_DEVICE_RTL8139 qemu: Introduce QEMU_CAPS_DEVICE_E1000 qemu: Introduce QEMU_CAPS_DEVICE_VIRTIO_NET qemu: Try several network devices when looking for a default src/qemu/qemu_capabilities.c | 12 +++++++++- src/qemu/qemu_capabilities.h | 3 +++ src/qemu/qemu_domain.c | 32 +++++++++++++++++++++++---- tests/qemucapabilitiesdata/caps_1.2.2-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_1.3.1-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_1.4.2-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_2.1.1-1.caps | 3 +++ tests/qemuhelptest.c | 30 ++++++++++++++++++++----- 11 files changed, 87 insertions(+), 11 deletions(-) -- 2.4.3

This capability can be used to detect whether or not the QEMU binary supports the rtl8139 network device. --- src/qemu/qemu_capabilities.c | 5 ++++- src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_1.2.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.3.1-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.4.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.1.1-1.caps | 1 + tests/qemuhelptest.c | 18 ++++++++++++------ 10 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 43d11af..61b0ad5 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -291,7 +291,9 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "gpex-pcihost", "ioh3420", "x3130-upstream", - "xio3130-downstream", + + "xio3130-downstream", /* 195 */ + "rtl8139", ); @@ -1576,6 +1578,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "ioh3420", QEMU_CAPS_DEVICE_IOH3420 }, { "x3130-upstream", QEMU_CAPS_DEVICE_X3130_UPSTREAM }, { "xio3130-downstream", QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM }, + { "rtl8139", QEMU_CAPS_DEVICE_RTL8139 }, }; static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 2d32d6e..168ba39 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -235,6 +235,7 @@ typedef enum { QEMU_CAPS_DEVICE_IOH3420 = 193, /* -device ioh3420 */ QEMU_CAPS_DEVICE_X3130_UPSTREAM = 194, /* -device x3130-upstream */ QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM = 195, /* -device xio3130-downstream */ + QEMU_CAPS_DEVICE_RTL8139 = 196, /* -device rtl8139 */ QEMU_CAPS_LAST, /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_1.2.2-1.caps b/tests/qemucapabilitiesdata/caps_1.2.2-1.caps index ba16635..5b0f6b6 100644 --- a/tests/qemucapabilitiesdata/caps_1.2.2-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.2.2-1.caps @@ -123,4 +123,5 @@ <flag name='ioh3420'/> <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> + <flag name='rtl8139'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.3.1-1.caps b/tests/qemucapabilitiesdata/caps_1.3.1-1.caps index 51cd6d9..c5aad4d 100644 --- a/tests/qemucapabilitiesdata/caps_1.3.1-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.3.1-1.caps @@ -138,4 +138,5 @@ <flag name='ioh3420'/> <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> + <flag name='rtl8139'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.4.2-1.caps b/tests/qemucapabilitiesdata/caps_1.4.2-1.caps index 03d0a3e..f671063 100644 --- a/tests/qemucapabilitiesdata/caps_1.4.2-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.4.2-1.caps @@ -139,4 +139,5 @@ <flag name='ioh3420'/> <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> + <flag name='rtl8139'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.5.3-1.caps b/tests/qemucapabilitiesdata/caps_1.5.3-1.caps index e2f22e4..3f795f5 100644 --- a/tests/qemucapabilitiesdata/caps_1.5.3-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.5.3-1.caps @@ -148,4 +148,5 @@ <flag name='ioh3420'/> <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> + <flag name='rtl8139'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps index 874a050..6d84910 100644 --- a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps @@ -154,4 +154,5 @@ <flag name='ioh3420'/> <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> + <flag name='rtl8139'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps index dd3bcda..8983733 100644 --- a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps @@ -154,4 +154,5 @@ <flag name='ioh3420'/> <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> + <flag name='rtl8139'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps index 3ee2d6f..28f19a0 100644 --- a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps +++ b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps @@ -170,4 +170,5 @@ <flag name='ioh3420'/> <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> + <flag name='rtl8139'/> </qemuCaps> diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c index 8f317d4..9016611 100644 --- a/tests/qemuhelptest.c +++ b/tests/qemuhelptest.c @@ -409,7 +409,8 @@ mymain(void) QEMU_CAPS_DEVICE_USB_SERIAL, QEMU_CAPS_DEVICE_USB_NET, QEMU_CAPS_DEVICE_USB_KBD, - QEMU_CAPS_DEVICE_PCI_BRIDGE); + QEMU_CAPS_DEVICE_PCI_BRIDGE, + QEMU_CAPS_DEVICE_RTL8139); DO_TEST("qemu-kvm-0.12.3", 12003, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -524,7 +525,8 @@ mymain(void) QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_USB_STORAGE, QEMU_CAPS_HOST_PCI_MULTIDOMAIN, - QEMU_CAPS_DEVICE_IVSHMEM); + QEMU_CAPS_DEVICE_IVSHMEM, + QEMU_CAPS_DEVICE_RTL8139); DO_TEST("qemu-kvm-0.12.1.2-rhel61", 12001, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -591,7 +593,8 @@ mymain(void) QEMU_CAPS_DEVICE_USB_SERIAL, QEMU_CAPS_DEVICE_USB_NET, QEMU_CAPS_DEVICE_USB_KBD, - QEMU_CAPS_DEVICE_PCI_BRIDGE); + QEMU_CAPS_DEVICE_PCI_BRIDGE, + QEMU_CAPS_DEVICE_RTL8139); DO_TEST("qemu-kvm-0.12.1.2-rhel62-beta", 12001, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -666,7 +669,8 @@ mymain(void) QEMU_CAPS_DEVICE_CIRRUS_VGA, QEMU_CAPS_DEVICE_PCI_BRIDGE, QEMU_CAPS_DEVICE_USB_KBD, - QEMU_CAPS_DEVICE_USB_STORAGE); + QEMU_CAPS_DEVICE_USB_STORAGE, + QEMU_CAPS_DEVICE_RTL8139); DO_TEST("qemu-1.0", 1000000, 0, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -756,7 +760,8 @@ mymain(void) QEMU_CAPS_DEVICE_IVSHMEM, QEMU_CAPS_DEVICE_IOH3420, QEMU_CAPS_DEVICE_X3130_UPSTREAM, - QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM); + QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM, + QEMU_CAPS_DEVICE_RTL8139); DO_TEST("qemu-1.1.0", 1001000, 0, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -859,7 +864,8 @@ mymain(void) QEMU_CAPS_DEVICE_IVSHMEM, QEMU_CAPS_DEVICE_IOH3420, QEMU_CAPS_DEVICE_X3130_UPSTREAM, - QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM); + QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM, + QEMU_CAPS_DEVICE_RTL8139); DO_TEST_FULL("qemu-1.2.0", 1002000, 0, 0, VIR_ERR_CONFIG_UNSUPPORTED, QEMU_CAPS_LAST); DO_TEST_FULL("qemu-kvm-1.2.0", 1002000, 1, 0, VIR_ERR_CONFIG_UNSUPPORTED, -- 2.4.3

This capability can be used to detect whether or not the QEMU binary supports the e1000 network device. --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_1.2.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.3.1-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.4.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.1.1-1.caps | 1 + tests/qemuhelptest.c | 18 ++++++++++++------ 10 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 61b0ad5..a875727 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -294,6 +294,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "xio3130-downstream", /* 195 */ "rtl8139", + "e1000", ); @@ -1579,6 +1580,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "x3130-upstream", QEMU_CAPS_DEVICE_X3130_UPSTREAM }, { "xio3130-downstream", QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM }, { "rtl8139", QEMU_CAPS_DEVICE_RTL8139 }, + { "e1000", QEMU_CAPS_DEVICE_E1000 }, }; static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 168ba39..76490cb 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -236,6 +236,7 @@ typedef enum { QEMU_CAPS_DEVICE_X3130_UPSTREAM = 194, /* -device x3130-upstream */ QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM = 195, /* -device xio3130-downstream */ QEMU_CAPS_DEVICE_RTL8139 = 196, /* -device rtl8139 */ + QEMU_CAPS_DEVICE_E1000 = 197, /* -device e1000 */ QEMU_CAPS_LAST, /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_1.2.2-1.caps b/tests/qemucapabilitiesdata/caps_1.2.2-1.caps index 5b0f6b6..d083d18 100644 --- a/tests/qemucapabilitiesdata/caps_1.2.2-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.2.2-1.caps @@ -124,4 +124,5 @@ <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> <flag name='rtl8139'/> + <flag name='e1000'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.3.1-1.caps b/tests/qemucapabilitiesdata/caps_1.3.1-1.caps index c5aad4d..3fdfdca 100644 --- a/tests/qemucapabilitiesdata/caps_1.3.1-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.3.1-1.caps @@ -139,4 +139,5 @@ <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> <flag name='rtl8139'/> + <flag name='e1000'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.4.2-1.caps b/tests/qemucapabilitiesdata/caps_1.4.2-1.caps index f671063..b9bb82f 100644 --- a/tests/qemucapabilitiesdata/caps_1.4.2-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.4.2-1.caps @@ -140,4 +140,5 @@ <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> <flag name='rtl8139'/> + <flag name='e1000'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.5.3-1.caps b/tests/qemucapabilitiesdata/caps_1.5.3-1.caps index 3f795f5..7364cd4 100644 --- a/tests/qemucapabilitiesdata/caps_1.5.3-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.5.3-1.caps @@ -149,4 +149,5 @@ <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> <flag name='rtl8139'/> + <flag name='e1000'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps index 6d84910..8753b28 100644 --- a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps @@ -155,4 +155,5 @@ <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> <flag name='rtl8139'/> + <flag name='e1000'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps index 8983733..5234cca 100644 --- a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps @@ -155,4 +155,5 @@ <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> <flag name='rtl8139'/> + <flag name='e1000'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps index 28f19a0..580ad30 100644 --- a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps +++ b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps @@ -171,4 +171,5 @@ <flag name='x3130-upstream'/> <flag name='xio3130-downstream'/> <flag name='rtl8139'/> + <flag name='e1000'/> </qemuCaps> diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c index 9016611..53908cf 100644 --- a/tests/qemuhelptest.c +++ b/tests/qemuhelptest.c @@ -410,7 +410,8 @@ mymain(void) QEMU_CAPS_DEVICE_USB_NET, QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_PCI_BRIDGE, - QEMU_CAPS_DEVICE_RTL8139); + QEMU_CAPS_DEVICE_RTL8139, + QEMU_CAPS_DEVICE_E1000); DO_TEST("qemu-kvm-0.12.3", 12003, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -526,7 +527,8 @@ mymain(void) QEMU_CAPS_DEVICE_USB_STORAGE, QEMU_CAPS_HOST_PCI_MULTIDOMAIN, QEMU_CAPS_DEVICE_IVSHMEM, - QEMU_CAPS_DEVICE_RTL8139); + QEMU_CAPS_DEVICE_RTL8139, + QEMU_CAPS_DEVICE_E1000); DO_TEST("qemu-kvm-0.12.1.2-rhel61", 12001, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -594,7 +596,8 @@ mymain(void) QEMU_CAPS_DEVICE_USB_NET, QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_PCI_BRIDGE, - QEMU_CAPS_DEVICE_RTL8139); + QEMU_CAPS_DEVICE_RTL8139, + QEMU_CAPS_DEVICE_E1000); DO_TEST("qemu-kvm-0.12.1.2-rhel62-beta", 12001, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -670,7 +673,8 @@ mymain(void) QEMU_CAPS_DEVICE_PCI_BRIDGE, QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_USB_STORAGE, - QEMU_CAPS_DEVICE_RTL8139); + QEMU_CAPS_DEVICE_RTL8139, + QEMU_CAPS_DEVICE_E1000); DO_TEST("qemu-1.0", 1000000, 0, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -761,7 +765,8 @@ mymain(void) QEMU_CAPS_DEVICE_IOH3420, QEMU_CAPS_DEVICE_X3130_UPSTREAM, QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM, - QEMU_CAPS_DEVICE_RTL8139); + QEMU_CAPS_DEVICE_RTL8139, + QEMU_CAPS_DEVICE_E1000); DO_TEST("qemu-1.1.0", 1001000, 0, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -865,7 +870,8 @@ mymain(void) QEMU_CAPS_DEVICE_IOH3420, QEMU_CAPS_DEVICE_X3130_UPSTREAM, QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM, - QEMU_CAPS_DEVICE_RTL8139); + QEMU_CAPS_DEVICE_RTL8139, + QEMU_CAPS_DEVICE_E1000); DO_TEST_FULL("qemu-1.2.0", 1002000, 0, 0, VIR_ERR_CONFIG_UNSUPPORTED, QEMU_CAPS_LAST); DO_TEST_FULL("qemu-kvm-1.2.0", 1002000, 1, 0, VIR_ERR_CONFIG_UNSUPPORTED, -- 2.4.3

This capability can be used to detect whether or not the QEMU binary supports the virtio-net-* network device. --- src/qemu/qemu_capabilities.c | 5 +++++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_1.2.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.3.1-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.4.2-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.1.1-1.caps | 1 + tests/qemuhelptest.c | 18 ++++++++++++------ 10 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index a875727..4ad1bdb 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -295,6 +295,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "xio3130-downstream", /* 195 */ "rtl8139", "e1000", + "virtio-net", ); @@ -1581,6 +1582,10 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "xio3130-downstream", QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM }, { "rtl8139", QEMU_CAPS_DEVICE_RTL8139 }, { "e1000", QEMU_CAPS_DEVICE_E1000 }, + { "virtio-net-pci", QEMU_CAPS_DEVICE_VIRTIO_NET }, + { "virtio-net-ccw", QEMU_CAPS_DEVICE_VIRTIO_NET }, + { "virtio-net-s390", QEMU_CAPS_DEVICE_VIRTIO_NET }, + { "virtio-net-device", QEMU_CAPS_DEVICE_VIRTIO_NET }, }; static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 76490cb..2623574 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -237,6 +237,7 @@ typedef enum { QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM = 195, /* -device xio3130-downstream */ QEMU_CAPS_DEVICE_RTL8139 = 196, /* -device rtl8139 */ QEMU_CAPS_DEVICE_E1000 = 197, /* -device e1000 */ + QEMU_CAPS_DEVICE_VIRTIO_NET = 198, /* -device virtio-net-* */ QEMU_CAPS_LAST, /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_1.2.2-1.caps b/tests/qemucapabilitiesdata/caps_1.2.2-1.caps index d083d18..5f179de 100644 --- a/tests/qemucapabilitiesdata/caps_1.2.2-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.2.2-1.caps @@ -125,4 +125,5 @@ <flag name='xio3130-downstream'/> <flag name='rtl8139'/> <flag name='e1000'/> + <flag name='virtio-net'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.3.1-1.caps b/tests/qemucapabilitiesdata/caps_1.3.1-1.caps index 3fdfdca..dad097a 100644 --- a/tests/qemucapabilitiesdata/caps_1.3.1-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.3.1-1.caps @@ -140,4 +140,5 @@ <flag name='xio3130-downstream'/> <flag name='rtl8139'/> <flag name='e1000'/> + <flag name='virtio-net'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.4.2-1.caps b/tests/qemucapabilitiesdata/caps_1.4.2-1.caps index b9bb82f..1f2682e 100644 --- a/tests/qemucapabilitiesdata/caps_1.4.2-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.4.2-1.caps @@ -141,4 +141,5 @@ <flag name='xio3130-downstream'/> <flag name='rtl8139'/> <flag name='e1000'/> + <flag name='virtio-net'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.5.3-1.caps b/tests/qemucapabilitiesdata/caps_1.5.3-1.caps index 7364cd4..95f364f 100644 --- a/tests/qemucapabilitiesdata/caps_1.5.3-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.5.3-1.caps @@ -150,4 +150,5 @@ <flag name='xio3130-downstream'/> <flag name='rtl8139'/> <flag name='e1000'/> + <flag name='virtio-net'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps index 8753b28..6533a6e 100644 --- a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps @@ -156,4 +156,5 @@ <flag name='xio3130-downstream'/> <flag name='rtl8139'/> <flag name='e1000'/> + <flag name='virtio-net'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps index 5234cca..b2e775b 100644 --- a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps +++ b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps @@ -156,4 +156,5 @@ <flag name='xio3130-downstream'/> <flag name='rtl8139'/> <flag name='e1000'/> + <flag name='virtio-net'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps index 580ad30..88fe13a 100644 --- a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps +++ b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps @@ -172,4 +172,5 @@ <flag name='xio3130-downstream'/> <flag name='rtl8139'/> <flag name='e1000'/> + <flag name='virtio-net'/> </qemuCaps> diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c index 53908cf..7b78537 100644 --- a/tests/qemuhelptest.c +++ b/tests/qemuhelptest.c @@ -411,7 +411,8 @@ mymain(void) QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_PCI_BRIDGE, QEMU_CAPS_DEVICE_RTL8139, - QEMU_CAPS_DEVICE_E1000); + QEMU_CAPS_DEVICE_E1000, + QEMU_CAPS_DEVICE_VIRTIO_NET); DO_TEST("qemu-kvm-0.12.3", 12003, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -528,7 +529,8 @@ mymain(void) QEMU_CAPS_HOST_PCI_MULTIDOMAIN, QEMU_CAPS_DEVICE_IVSHMEM, QEMU_CAPS_DEVICE_RTL8139, - QEMU_CAPS_DEVICE_E1000); + QEMU_CAPS_DEVICE_E1000, + QEMU_CAPS_DEVICE_VIRTIO_NET); DO_TEST("qemu-kvm-0.12.1.2-rhel61", 12001, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -597,7 +599,8 @@ mymain(void) QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_PCI_BRIDGE, QEMU_CAPS_DEVICE_RTL8139, - QEMU_CAPS_DEVICE_E1000); + QEMU_CAPS_DEVICE_E1000, + QEMU_CAPS_DEVICE_VIRTIO_NET); DO_TEST("qemu-kvm-0.12.1.2-rhel62-beta", 12001, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -674,7 +677,8 @@ mymain(void) QEMU_CAPS_DEVICE_USB_KBD, QEMU_CAPS_DEVICE_USB_STORAGE, QEMU_CAPS_DEVICE_RTL8139, - QEMU_CAPS_DEVICE_E1000); + QEMU_CAPS_DEVICE_E1000, + QEMU_CAPS_DEVICE_VIRTIO_NET); DO_TEST("qemu-1.0", 1000000, 0, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -766,7 +770,8 @@ mymain(void) QEMU_CAPS_DEVICE_X3130_UPSTREAM, QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM, QEMU_CAPS_DEVICE_RTL8139, - QEMU_CAPS_DEVICE_E1000); + QEMU_CAPS_DEVICE_E1000, + QEMU_CAPS_DEVICE_VIRTIO_NET); DO_TEST("qemu-1.1.0", 1001000, 0, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -871,7 +876,8 @@ mymain(void) QEMU_CAPS_DEVICE_X3130_UPSTREAM, QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM, QEMU_CAPS_DEVICE_RTL8139, - QEMU_CAPS_DEVICE_E1000); + QEMU_CAPS_DEVICE_E1000, + QEMU_CAPS_DEVICE_VIRTIO_NET); DO_TEST_FULL("qemu-1.2.0", 1002000, 0, 0, VIR_ERR_CONFIG_UNSUPPORTED, QEMU_CAPS_LAST); DO_TEST_FULL("qemu-kvm-1.2.0", 1002000, 1, 0, VIR_ERR_CONFIG_UNSUPPORTED, -- 2.4.3

Up until now, the default has been rtl8139, but no check was in place to make sure that device was actually available. Now we try rtl8139, e1000 and virtio-net in turn, checking for availability before using any of them: this means we have a much better chance for the guest to be able to boot. --- src/qemu/qemu_domain.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 91c632c..33cd463 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1193,7 +1193,8 @@ qemuDomainDefPostParse(virDomainDefPtr def, } static const char * -qemuDomainDefaultNetModel(const virDomainDef *def) +qemuDomainDefaultNetModel(const virDomainDef *def, + virQEMUCapsPtr qemuCaps) { if (ARCH_IS_S390(def->os.arch)) return "virtio"; @@ -1211,7 +1212,23 @@ qemuDomainDefaultNetModel(const virDomainDef *def) return "lan9118"; } - return "rtl8139"; + /* Try several network devices in turn; each of these devices is + * less likely be supported out-of-the-box by the guest operating + * system than the previous one. + * + * Note: Using rtl8139 as a last resort, even though by the time + * we get there we already know that it's not available, is an + * ugly hack needed to work around the fact that we don't have + * a way to mock capabilities in the test suite yet. Once we do, + * we should return NULL and raise an error instead */ + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_RTL8139)) + return "rtl8139"; + else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_E1000)) + return "e1000"; + else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_NET)) + return "virtio"; + else + return "rtl8139"; } static int @@ -1220,18 +1237,24 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, virCapsPtr caps ATTRIBUTE_UNUSED, void *opaque) { - int ret = -1; virQEMUDriverPtr driver = opaque; + virQEMUCapsPtr qemuCaps = NULL; virQEMUDriverConfigPtr cfg = NULL; + int ret = -1; if (driver) cfg = virQEMUDriverGetConfig(driver); + /* This condition is actually a (temporary) hack for test suite which + * does not create capabilities cache */ + if (driver && driver->qemuCapsCache) + qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator); + if (dev->type == VIR_DOMAIN_DEVICE_NET && dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && !dev->data.net->model) { if (VIR_STRDUP(dev->data.net->model, - qemuDomainDefaultNetModel(def)) < 0) + qemuDomainDefaultNetModel(def, qemuCaps)) < 0) goto cleanup; } @@ -1357,6 +1380,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, ret = 0; cleanup: + virObjectUnref(qemuCaps); virObjectUnref(cfg); return ret; } -- 2.4.3

On Wed, Sep 09, 2015 at 02:50:23PM +0200, Andrea Bolognani wrote:
Up until now, the default has been rtl8139, but no check was in place to make sure that device was actually available.
Now we try rtl8139, e1000 and virtio-net in turn, checking for availability before using any of them: this means we have a much better chance for the guest to be able to boot. --- src/qemu/qemu_domain.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 91c632c..33cd463 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1193,7 +1193,8 @@ qemuDomainDefPostParse(virDomainDefPtr def, }
static const char * -qemuDomainDefaultNetModel(const virDomainDef *def) +qemuDomainDefaultNetModel(const virDomainDef *def, + virQEMUCapsPtr qemuCaps) { if (ARCH_IS_S390(def->os.arch)) return "virtio"; @@ -1211,7 +1212,23 @@ qemuDomainDefaultNetModel(const virDomainDef *def) return "lan9118"; }
- return "rtl8139"; + /* Try several network devices in turn; each of these devices is + * less likely be supported out-of-the-box by the guest operating + * system than the previous one. + * + * Note: Using rtl8139 as a last resort, even though by the time + * we get there we already know that it's not available, is an + * ugly hack needed to work around the fact that we don't have + * a way to mock capabilities in the test suite yet. Once we do, + * we should return NULL and raise an error instead */ + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_RTL8139)) + return "rtl8139"; + else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_E1000)) + return "e1000"; + else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_NET)) + return "virtio"; + else
I would remove the comment, remove this "else" and just comment the 'return "rtl8139"' with something along the lines of "we have nothing else to do here, so we can return an error, but rtl8139 may still be supported if the capability probing was broken in any way, so let's use it as a last resort (the same way we did before). Also having a test for the thing you are trying to fix would be nice. Otherwise this code looks fine.
+ return "rtl8139"; }
static int @@ -1220,18 +1237,24 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, virCapsPtr caps ATTRIBUTE_UNUSED, void *opaque) { - int ret = -1; virQEMUDriverPtr driver = opaque; + virQEMUCapsPtr qemuCaps = NULL; virQEMUDriverConfigPtr cfg = NULL; + int ret = -1;
if (driver) cfg = virQEMUDriverGetConfig(driver);
+ /* This condition is actually a (temporary) hack for test suite which + * does not create capabilities cache */ + if (driver && driver->qemuCapsCache) + qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator); + if (dev->type == VIR_DOMAIN_DEVICE_NET && dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && !dev->data.net->model) { if (VIR_STRDUP(dev->data.net->model, - qemuDomainDefaultNetModel(def)) < 0) + qemuDomainDefaultNetModel(def, qemuCaps)) < 0) goto cleanup; }
@@ -1357,6 +1380,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, ret = 0;
cleanup: + virObjectUnref(qemuCaps); virObjectUnref(cfg); return ret; } -- 2.4.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, Sep 09, 2015 at 03:30:07PM +0200, Martin Kletzander wrote:
On Wed, Sep 09, 2015 at 02:50:23PM +0200, Andrea Bolognani wrote:
Up until now, the default has been rtl8139, but no check was in place to make sure that device was actually available.
Now we try rtl8139, e1000 and virtio-net in turn, checking for availability before using any of them: this means we have a much better chance for the guest to be able to boot. --- src/qemu/qemu_domain.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 91c632c..33cd463 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1193,7 +1193,8 @@ qemuDomainDefPostParse(virDomainDefPtr def, }
static const char * -qemuDomainDefaultNetModel(const virDomainDef *def) +qemuDomainDefaultNetModel(const virDomainDef *def, + virQEMUCapsPtr qemuCaps) { if (ARCH_IS_S390(def->os.arch)) return "virtio"; @@ -1211,7 +1212,23 @@ qemuDomainDefaultNetModel(const virDomainDef *def) return "lan9118"; }
- return "rtl8139"; + /* Try several network devices in turn; each of these devices is + * less likely be supported out-of-the-box by the guest operating + * system than the previous one. + * + * Note: Using rtl8139 as a last resort, even though by the time + * we get there we already know that it's not available, is an + * ugly hack needed to work around the fact that we don't have + * a way to mock capabilities in the test suite yet. Once we do, + * we should return NULL and raise an error instead */ + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_RTL8139)) + return "rtl8139"; + else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_E1000)) + return "e1000"; + else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_NET)) + return "virtio"; + else
I would remove the comment, remove this "else" and just comment the 'return "rtl8139"' with something along the lines of "we have nothing else to do here, so we can return an error, but rtl8139 may still be supported if the capability probing was broken in any way, so let's use it as a last resort (the same way we did before).
Also having a test for the thing you are trying to fix would be nice. Otherwise this code looks fine.
I missed the fact that our test suite is not yet prepared to do that, sorry for that. So I'd say ACK with the previous paragraph being addressed.
+ return "rtl8139"; }
static int @@ -1220,18 +1237,24 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, virCapsPtr caps ATTRIBUTE_UNUSED, void *opaque) { - int ret = -1; virQEMUDriverPtr driver = opaque; + virQEMUCapsPtr qemuCaps = NULL; virQEMUDriverConfigPtr cfg = NULL; + int ret = -1;
if (driver) cfg = virQEMUDriverGetConfig(driver);
+ /* This condition is actually a (temporary) hack for test suite which + * does not create capabilities cache */ + if (driver && driver->qemuCapsCache) + qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator); + if (dev->type == VIR_DOMAIN_DEVICE_NET && dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && !dev->data.net->model) { if (VIR_STRDUP(dev->data.net->model, - qemuDomainDefaultNetModel(def)) < 0) + qemuDomainDefaultNetModel(def, qemuCaps)) < 0) goto cleanup; }
@@ -1357,6 +1380,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, ret = 0;
cleanup: + virObjectUnref(qemuCaps); virObjectUnref(cfg); return ret; } -- 2.4.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, Sep 09, 2015 at 02:50:19PM +0200, Andrea Bolognani wrote:
Changes in v3:
* detect rtl8139 and e1000 availability as well
* don't try to use virtio-net based on availability alone: try rtl8139, e1000 and virtio-net in this order instead
* patch 4/4 contains an ugly bit we'll be able to get rid of once capabilities can be properly mocked in the test suite
Changes in v2[1]:
* detect virtio-net availability
* try to user it if available
Cheers.
[1] https://www.redhat.com/archives/libvir-list/2015-September/msg00058.html
Andrea Bolognani (4): qemu: Introduce QEMU_CAPS_DEVICE_RTL8139 qemu: Introduce QEMU_CAPS_DEVICE_E1000 qemu: Introduce QEMU_CAPS_DEVICE_VIRTIO_NET qemu: Try several network devices when looking for a default
ACK to 1-3, 4/4 has it's own conditional ACK in it's own reply.
src/qemu/qemu_capabilities.c | 12 +++++++++- src/qemu/qemu_capabilities.h | 3 +++ src/qemu/qemu_domain.c | 32 +++++++++++++++++++++++---- tests/qemucapabilitiesdata/caps_1.2.2-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_1.3.1-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_1.4.2-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 3 +++ tests/qemucapabilitiesdata/caps_2.1.1-1.caps | 3 +++ tests/qemuhelptest.c | 30 ++++++++++++++++++++----- 11 files changed, 87 insertions(+), 11 deletions(-)
-- 2.4.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, 2015-09-09 at 21:43 +0200, Martin Kletzander wrote:
Andrea Bolognani (4): qemu: Introduce QEMU_CAPS_DEVICE_RTL8139 qemu: Introduce QEMU_CAPS_DEVICE_E1000 qemu: Introduce QEMU_CAPS_DEVICE_VIRTIO_NET qemu: Try several network devices when looking for a default
ACK to 1-3, 4/4 has it's own conditional ACK in it's own reply.
I have changed the comment as suggested and pushed the series. Thanks. -- Andrea Bolognani Software Engineer - Virtualization Team
participants (2)
-
Andrea Bolognani
-
Martin Kletzander