]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
openvswitch: Check if OVS_VSCTL exists when getting interface name
authorMichal Privoznik <mprivozn@redhat.com>
Sat, 9 Jan 2021 08:16:56 +0000 (09:16 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 11 Jan 2021 15:06:17 +0000 (16:06 +0100)
So far we assumed that any vhostuser interface is plugged into an
OVS bridge and thus 'ovs-vsctl' exists. But this is not always
true. In testing scenarios it is possible to create a vhostuser
interface with this tool dpdk-testpmd (part of dpdk RPM) which
creates/connects to UNIX socket needed for vhostuser. Of course,
since there is no OVS then there is no interface name in which
case virNetDevOpenvswitchGetVhostuserIfname() should return 0.

The rest of APIs that assume OVS are not 'fixed' because we still
want them to fail (e.g. getting statistics, plugging interface
into an OVS bridge, unplugging it from an OVS bridge, ...).

The only API that is fixed is
virNetDevOpenvswitchGetVhostuserIfname() because it is called
explicitly when starting a guest (and callers are okay if no name
was found).

The other way to fix this bug seems to be to simply require
'ovs-vsctl' on spec file level, but that is too heavy gun given
that vhostuser is used by a small set of our users (assumption
made on requirements for vhostuser). Also, this way would drag in
yet another dependency for all users (even those who want minimal
libvirt).

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1913156
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virnetdevopenvswitch.c

index 896c1bd917a298f722c8c5d5c83071e35637c4a5..f9b3369b2a5aff91f08188bfe93d4d31d5d55b27 100644 (file)
@@ -29,6 +29,7 @@
 #include "virstring.h"
 #include "virlog.h"
 #include "virjson.h"
+#include "virfile.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -529,9 +530,19 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
                                        bool server,
                                        char **ifname)
 {
-    g_autoptr(virCommand) cmd = virNetDevOpenvswitchCreateCmd();
+    g_autoptr(virCommand) cmd = NULL;
+    g_autofree char *absoluteOvsVsctlPath = NULL;
     int status;
 
+    if (!(absoluteOvsVsctlPath = virFindFileInPath(OVS_VSCTL))) {
+        /* If there is no 'ovs-vsctl' then the interface is
+         * probably not an OpenVSwitch interface and the @path to
+         * socket was created by some DPDK testing script (e.g.
+         * dpdk-testpmd). */
+        return 0;
+    }
+
+    cmd = virNetDevOpenvswitchCreateCmd();
 
     if (server) {
         virCommandAddArgList(cmd, "--no-headings", "--columns=name", "find",