|
|
a7e38b |
From a18bc12081bcebf2d78883d1c6981c454149bb39 Mon Sep 17 00:00:00 2001
|
|
|
a7e38b |
From: Laszlo Ersek <lersek@redhat.com>
|
|
|
a7e38b |
Date: Thu, 23 Dec 2021 11:37:01 +0100
|
|
|
a7e38b |
Subject: [PATCH] launch-libvirt: add virtio-net via the standard <interface>
|
|
|
a7e38b |
element
|
|
|
a7e38b |
|
|
|
a7e38b |
Starting with version 3.8.0, libvirt allows us to specify the network
|
|
|
a7e38b |
address and network mask (as prefix) for SLIRP directly via the
|
|
|
a7e38b |
<interface> element in the domain XML:
|
|
|
a7e38b |
<https://libvirt.org/formatdomain.html#userspace-slirp-stack>. This means
|
|
|
a7e38b |
we don't need the <qemu:commandline> hack for virtio-net on such versions.
|
|
|
a7e38b |
|
|
|
a7e38b |
Restrict the hack in construct_libvirt_xml_qemu_cmdline() to
|
|
|
a7e38b |
libvirt<3.8.0, and generate the proper <interface> element in
|
|
|
a7e38b |
construct_libvirt_xml_devices() on libvirt>=3.8.0.
|
|
|
a7e38b |
|
|
|
a7e38b |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2034160
|
|
|
a7e38b |
Suggested-by: Richard W.M. Jones <rjones@redhat.com>
|
|
|
a7e38b |
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
a7e38b |
Message-Id: <20211223103701.12702-4-lersek@redhat.com>
|
|
|
a7e38b |
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
|
|
|
a7e38b |
Tested-by: Richard W.M. Jones <rjones@redhat.com>
|
|
|
a7e38b |
(cherry picked from commit 5858c2cf6c24b3776e3867eafd9d86a1f4912d9c)
|
|
|
a7e38b |
---
|
|
|
a7e38b |
lib/guestfs-internal.h | 3 ++-
|
|
|
a7e38b |
lib/launch-libvirt.c | 27 +++++++++++++++++++++++++--
|
|
|
a7e38b |
2 files changed, 27 insertions(+), 3 deletions(-)
|
|
|
a7e38b |
|
|
|
a7e38b |
diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h
|
|
|
a7e38b |
index e24d570f5..4a19e5c6b 100644
|
|
|
a7e38b |
--- a/lib/guestfs-internal.h
|
|
|
a7e38b |
+++ b/lib/guestfs-internal.h
|
|
|
a7e38b |
@@ -173,7 +173,8 @@ cleanup_mutex_unlock (pthread_mutex_t **ptr)
|
|
|
a7e38b |
#endif
|
|
|
a7e38b |
|
|
|
a7e38b |
/* Place the virtio-net controller in slot 0x1e on the root bus, on normal
|
|
|
a7e38b |
- * hardware with PCI. Refer to RHBZ#2034160.
|
|
|
a7e38b |
+ * hardware with PCI. Necessary only before libvirt 3.8.0. Refer to
|
|
|
a7e38b |
+ * RHBZ#2034160.
|
|
|
a7e38b |
*/
|
|
|
a7e38b |
#ifdef HAVE_LIBVIRT_BACKEND
|
|
|
a7e38b |
#if defined(__arm__) || defined(__s390x__)
|
|
|
a7e38b |
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
|
|
|
a7e38b |
index 266d88824..cc714c02e 100644
|
|
|
a7e38b |
--- a/lib/launch-libvirt.c
|
|
|
a7e38b |
+++ b/lib/launch-libvirt.c
|
|
|
a7e38b |
@@ -1413,6 +1413,28 @@ construct_libvirt_xml_devices (guestfs_h *g,
|
|
|
a7e38b |
} end_element ();
|
|
|
a7e38b |
} end_element ();
|
|
|
a7e38b |
|
|
|
a7e38b |
+ /* Virtio-net NIC with SLIRP (= userspace) back-end, if networking is
|
|
|
a7e38b |
+ * enabled. Starting with libvirt 3.8.0, we can specify the network address
|
|
|
a7e38b |
+ * and prefix for SLIRP in the domain XML. Therefore, we can add the NIC
|
|
|
a7e38b |
+ * via the standard <interface> element rather than <qemu:commandline>, and
|
|
|
a7e38b |
+ * so libvirt can manage the PCI address of the virtio-net NIC like the PCI
|
|
|
a7e38b |
+ * addresses of all other devices. Refer to RHBZ#2034160.
|
|
|
a7e38b |
+ */
|
|
|
a7e38b |
+ if (g->enable_network &&
|
|
|
a7e38b |
+ guestfs_int_version_ge (¶ms->data->libvirt_version, 3, 8, 0)) {
|
|
|
a7e38b |
+ start_element ("interface") {
|
|
|
a7e38b |
+ attribute ("type", "user");
|
|
|
a7e38b |
+ start_element ("model") {
|
|
|
a7e38b |
+ attribute ("type", "virtio");
|
|
|
a7e38b |
+ } end_element ();
|
|
|
a7e38b |
+ start_element ("ip") {
|
|
|
a7e38b |
+ attribute ("family", "ipv4");
|
|
|
a7e38b |
+ attribute ("address", NETWORK_ADDRESS);
|
|
|
a7e38b |
+ attribute ("prefix", NETWORK_PREFIX);
|
|
|
a7e38b |
+ } end_element ();
|
|
|
a7e38b |
+ } end_element ();
|
|
|
a7e38b |
+ }
|
|
|
a7e38b |
+
|
|
|
a7e38b |
/* Libvirt adds some devices by default. Indicate to libvirt
|
|
|
a7e38b |
* that we don't want them.
|
|
|
a7e38b |
*/
|
|
|
a7e38b |
@@ -1835,9 +1857,10 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
|
|
|
a7e38b |
} end_element ();
|
|
|
a7e38b |
|
|
|
a7e38b |
/* Workaround because libvirt user networking cannot specify "net="
|
|
|
a7e38b |
- * parameter.
|
|
|
a7e38b |
+ * parameter. Necessary only before libvirt 3.8.0; refer to RHBZ#2034160.
|
|
|
a7e38b |
*/
|
|
|
a7e38b |
- if (g->enable_network) {
|
|
|
a7e38b |
+ if (g->enable_network &&
|
|
|
a7e38b |
+ !guestfs_int_version_ge (¶ms->data->libvirt_version, 3, 8, 0)) {
|
|
|
a7e38b |
start_element ("qemu:arg") {
|
|
|
a7e38b |
attribute ("value", "-netdev");
|
|
|
a7e38b |
} end_element ();
|
|
|
a7e38b |
--
|
|
|
a7e38b |
2.31.1
|
|
|
a7e38b |
|