diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h index e24d570f5..4a19e5c6b 100644 --- a/lib/guestfs-internal.h +++ b/lib/guestfs-internal.h @@ -173,7 +173,8 @@ cleanup_mutex_unlock (pthread_mutex_t **ptr) #endif /* Place the virtio-net controller in slot 0x1e on the root bus, on normal - * hardware with PCI. Refer to RHBZ#2034160. + * hardware with PCI. Necessary only before libvirt 3.8.0. Refer to + * RHBZ#2034160. */ #ifdef HAVE_LIBVIRT_BACKEND #if defined(__arm__) || defined(__s390x__) diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c index 266d88824..cc714c02e 100644 --- a/lib/launch-libvirt.c +++ b/lib/launch-libvirt.c @@ -1413,6 +1413,28 @@ construct_libvirt_xml_devices (guestfs_h *g, } end_element (); } end_element (); + /* Virtio-net NIC with SLIRP (= userspace) back-end, if networking is + * enabled. Starting with libvirt 3.8.0, we can specify the network address + * and prefix for SLIRP in the domain XML. Therefore, we can add the NIC + * via the standard element rather than , and + * so libvirt can manage the PCI address of the virtio-net NIC like the PCI + * addresses of all other devices. Refer to RHBZ#2034160. + */ + if (g->enable_network && + guestfs_int_version_ge (¶ms->data->libvirt_version, 3, 8, 0)) { + start_element ("interface") { + attribute ("type", "user"); + start_element ("model") { + attribute ("type", "virtio"); + } end_element (); + start_element ("ip") { + attribute ("family", "ipv4"); + attribute ("address", NETWORK_ADDRESS); + attribute ("prefix", NETWORK_PREFIX); + } end_element (); + } end_element (); + } + /* Libvirt adds some devices by default. Indicate to libvirt * that we don't want them. */ @@ -1835,9 +1857,10 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g, } end_element (); /* Workaround because libvirt user networking cannot specify "net=" - * parameter. + * parameter. Necessary only before libvirt 3.8.0; refer to RHBZ#2034160. */ - if (g->enable_network) { + if (g->enable_network && + !guestfs_int_version_ge (¶ms->data->libvirt_version, 3, 8, 0)) { start_element ("qemu:arg") { attribute ("value", "-netdev"); } end_element ();