Blame SOURCES/0019-launch-libvirt-add-virtio-net-via-the-standard-inter.patch

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