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

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