acda74
From 86d2fda1a16bc6d2566acfb6a566e13d704fd25a Mon Sep 17 00:00:00 2001
acda74
Message-Id: <86d2fda1a16bc6d2566acfb6a566e13d704fd25a@dist-git>
acda74
From: Laine Stump <laine@redhat.com>
acda74
Date: Mon, 20 Feb 2023 18:26:51 -0500
acda74
Subject: [PATCH] qemu: add reconnect=5 to passt qemu commandline options when
acda74
 available
acda74
acda74
QEMU's "reconnect" option of "-netdev stream" tells QEMU to
acda74
periodically (period is given in seconds as an argument to the option)
acda74
attempt to reconnect to the same passt socket to which it had
acda74
originally connected to. This is useful in cases where the passt
acda74
process terminates, and libvirtd starts a new passt process in its
acda74
place (which doesn't happen yet, but will happen automatically after
acda74
an upcoming patch in this series).
acda74
acda74
Since there is no real hueristic for determining the "best" value of
acda74
the reconnect interval, rather than clutter up config with a knob that
acda74
nobody knows how to properly twiddle, we just set the reconnect timer
acda74
to 5 seconds.
acda74
acda74
"-netdev stream" first appeared in QEMU 7.2.0, but the reconnect
acda74
option won't be available until QEMU 8.0.0, so we need to check QEMU
acda74
capabilities just in case someone is using QEMU 7.2.0 (and thus can
acda74
support passt backend, but not reconnect)
acda74
acda74
Resolves: https://bugzilla.redhat.com/2172098
acda74
acda74
Signed-off-by: Laine Stump <laine@redhat.com>
acda74
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
acda74
(cherry picked from commit acd8333f763f1e45728fac4e727fef4e33141ebf)
acda74
Signed-off-by: Laine Stump <laine@redhat.com>
acda74
---
acda74
 src/qemu/qemu_passt.c                         | 11 ++++++
acda74
 .../net-user-passt.x86_64-7.2.0.args          | 37 +++++++++++++++++++
acda74
 .../net-user-passt.x86_64-latest.args         |  2 +-
acda74
 tests/qemuxml2argvtest.c                      |  1 +
acda74
 4 files changed, 50 insertions(+), 1 deletion(-)
acda74
 create mode 100644 tests/qemuxml2argvdata/net-user-passt.x86_64-7.2.0.args
acda74
acda74
diff --git a/src/qemu/qemu_passt.c b/src/qemu/qemu_passt.c
acda74
index 88b7df4453..8d28a55455 100644
acda74
--- a/src/qemu/qemu_passt.c
acda74
+++ b/src/qemu/qemu_passt.c
acda74
@@ -83,6 +83,8 @@ qemuPasstAddNetProps(virDomainObj *vm,
acda74
 {
acda74
     g_autofree char *passtSocketName = qemuPasstCreateSocketPath(vm, net);
acda74
     g_autoptr(virJSONValue) addrprops = NULL;
acda74
+    qemuDomainObjPrivate *priv = vm->privateData;
acda74
+    virQEMUCaps *qemuCaps = priv->qemuCaps;
acda74
 
acda74
     if (virJSONValueObjectAdd(&addrprops,
acda74
                               "s:type", "unix",
acda74
@@ -98,6 +100,15 @@ qemuPasstAddNetProps(virDomainObj *vm,
acda74
                               NULL) < 0) {
acda74
         return -1;
acda74
     }
acda74
+
acda74
+    /* a narrow range of QEMU releases support -netdev stream, but
acda74
+     * don't support its "reconnect" option
acda74
+     */
acda74
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV_STREAM_RECONNECT) &&
acda74
+        virJSONValueObjectAdd(netprops, "u:reconnect", 5, NULL) < 0) {
acda74
+        return -1;
acda74
+    }
acda74
+
acda74
     return 0;
acda74
 }
acda74
 
acda74
diff --git a/tests/qemuxml2argvdata/net-user-passt.x86_64-7.2.0.args b/tests/qemuxml2argvdata/net-user-passt.x86_64-7.2.0.args
acda74
new file mode 100644
acda74
index 0000000000..037dabb87d
acda74
--- /dev/null
acda74
+++ b/tests/qemuxml2argvdata/net-user-passt.x86_64-7.2.0.args
acda74
@@ -0,0 +1,37 @@
acda74
+LC_ALL=C \
acda74
+PATH=/bin \
acda74
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
acda74
+USER=test \
acda74
+LOGNAME=test \
acda74
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
acda74
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
acda74
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
acda74
+/usr/bin/qemu-system-x86_64 \
acda74
+-name guest=QEMUGuest1,debug-threads=on \
acda74
+-S \
acda74
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \
acda74
+-machine pc-i440fx-7.2,usb=off,dump-guest-core=off,memory-backend=pc.ram \
acda74
+-accel tcg \
acda74
+-cpu qemu64 \
acda74
+-m 214 \
acda74
+-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \
acda74
+-overcommit mem-lock=off \
acda74
+-smp 1,sockets=1,cores=1,threads=1 \
acda74
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
acda74
+-display none \
acda74
+-no-user-config \
acda74
+-nodefaults \
acda74
+-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
acda74
+-mon chardev=charmonitor,id=monitor,mode=control \
acda74
+-rtc base=utc \
acda74
+-no-shutdown \
acda74
+-no-acpi \
acda74
+-boot strict=on \
acda74
+-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
acda74
+-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \
acda74
+-device '{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-1-format","id":"ide0-0-0","bootindex":1}' \
acda74
+-netdev '{"type":"stream","addr":{"type":"unix","path":"/bad-test-used-env-xdg-runtime-dir/libvirt/qemu/run/passt/-1-QEMUGuest1-net0.socket"},"server":false,"id":"hostnet0"}' \
acda74
+-device '{"driver":"rtl8139","netdev":"hostnet0","id":"net0","mac":"00:11:22:33:44:55","bus":"pci.0","addr":"0x2"}' \
acda74
+-audiodev '{"id":"audio1","driver":"none"}' \
acda74
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
acda74
+-msg timestamp=on
acda74
diff --git a/tests/qemuxml2argvdata/net-user-passt.x86_64-latest.args b/tests/qemuxml2argvdata/net-user-passt.x86_64-latest.args
acda74
index 48e3e8ca8b..f84bec2ec1 100644
acda74
--- a/tests/qemuxml2argvdata/net-user-passt.x86_64-latest.args
acda74
+++ b/tests/qemuxml2argvdata/net-user-passt.x86_64-latest.args
acda74
@@ -30,7 +30,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
acda74
 -blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
acda74
 -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \
acda74
 -device '{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-1-format","id":"ide0-0-0","bootindex":1}' \
acda74
--netdev '{"type":"stream","addr":{"type":"unix","path":"/bad-test-used-env-xdg-runtime-dir/libvirt/qemu/run/passt/-1-QEMUGuest1-net0.socket"},"server":false,"id":"hostnet0"}' \
acda74
+-netdev '{"type":"stream","addr":{"type":"unix","path":"/bad-test-used-env-xdg-runtime-dir/libvirt/qemu/run/passt/-1-QEMUGuest1-net0.socket"},"server":false,"reconnect":5,"id":"hostnet0"}' \
acda74
 -device '{"driver":"rtl8139","netdev":"hostnet0","id":"net0","mac":"00:11:22:33:44:55","bus":"pci.0","addr":"0x2"}' \
acda74
 -audiodev '{"id":"audio1","driver":"none"}' \
acda74
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
acda74
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
acda74
index 8c52feb83c..e23b32e96a 100644
acda74
--- a/tests/qemuxml2argvtest.c
acda74
+++ b/tests/qemuxml2argvtest.c
acda74
@@ -1471,6 +1471,7 @@ mymain(void)
acda74
     DO_TEST_CAPS_ARCH_LATEST_FULL("net-user", "x86_64", ARG_FLAGS, FLAG_SLIRP_HELPER);
acda74
     DO_TEST_NOCAPS("net-user-addr");
acda74
     DO_TEST_CAPS_LATEST("net-user-passt");
acda74
+    DO_TEST_CAPS_VER("net-user-passt", "7.2.0");
acda74
     DO_TEST_NOCAPS("net-virtio");
acda74
     DO_TEST_NOCAPS("net-virtio-device");
acda74
     DO_TEST_NOCAPS("net-virtio-disable-offloads");
acda74
-- 
acda74
2.39.2
acda74