]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virnetdevopenvswitch: Get names for dpdkvhostuserclient too
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 6 Nov 2019 10:59:22 +0000 (11:59 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 12 Nov 2020 07:24:43 +0000 (08:24 +0100)
There are two types of vhostuser ports:

  dpdkvhostuser - OVS creates the socket and QEMU connects to it
  dpdkvhostuserclient - QEMU creates the socket and OVS connects to it

But of course ovs-vsctl syntax for fetching ifname is different.
So far, we've implemented the former. The lack of implementation
for the latter means that we are not detecting the interface name
and thus not reporting it in domain XML, or failing to get
interface statistics.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1767013

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/qemu/qemu_command.c
src/qemu/qemu_hotplug.c
src/util/virnetdevopenvswitch.c
src/util/virnetdevopenvswitch.h
tests/qemuxml2argvmock.c

index 0fecb9f6e7adf5da1def36a1a9e2f9d2c6e99e20..0eec35da1608baa5eb9748620eeeaab46d2b2fc4 100644 (file)
@@ -8004,6 +8004,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
             goto cleanup;
 
         if (virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->data.nix.path,
+                                                   net->data.vhostuser->data.nix.listen,
                                                    &net->ifname) < 0)
             goto cleanup;
 
index c1461ac6217dcdd69ff71f18357401ccf385fbff..81ec44ffcd04d2ffd5f63cd701d21ce84a5874e3 100644 (file)
@@ -1305,6 +1305,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
             goto cleanup;
 
         if (virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->data.nix.path,
+                                                   net->data.vhostuser->data.nix.listen,
                                                    &net->ifname) < 0)
             goto cleanup;
 
index a7b6af594d416d2109062d1749987762207acd90..411207a8ca469e5fb2f8585e3d7d19ca9531f824 100644 (file)
@@ -469,11 +469,22 @@ virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **master)
 
 
 /**
- * virNetDevOpenvswitchVhostuserGetIfname:
+ * virNetDevOpenvswitchGetVhostuserIfname:
  * @path: the path of the unix socket
+ * @server: true if OVS creates the @path
  * @ifname: the retrieved name of the interface
  *
- * Retrieves the ovs ifname from vhostuser unix socket path.
+ * Retrieves the OVS ifname from vhostuser UNIX socket path.
+ * There are two types of vhostuser ports which differ in client/server
+ * role:
+ *
+ * dpdkvhostuser - OVS creates the socket and QEMU connects to it
+ *                 (@server = true)
+ * dpdkvhostuserclient - QEMU creates the socket and OVS connects to it
+ *                       (@server = false)
+ *
+ * Since the way of retrieving ifname is different in these two cases,
+ * caller must set @server according to the interface definition.
  *
  * Returns: 1 if interface is an openvswitch interface,
  *          0 if it is not, but no other error occurred,
@@ -481,33 +492,46 @@ virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **master)
  */
 int
 virNetDevOpenvswitchGetVhostuserIfname(const char *path,
+                                       bool server,
                                        char **ifname)
 {
-    const char *tmpIfname = NULL;
-    int status;
     g_autoptr(virCommand) cmd = NULL;
+    int status;
 
-    /* Openvswitch vhostuser path are hardcoded to
-     * /<runstatedir>/openvswitch/<ifname>
-     * for example: /var/run/openvswitch/dpdkvhostuser0
-     *
-     * so we pick the filename and check it's a openvswitch interface
-     */
-    if (!path ||
-        !(tmpIfname = strrchr(path, '/')))
-        return 0;
-
-    tmpIfname++;
     cmd = virCommandNew(OVS_VSCTL);
     virNetDevOpenvswitchAddTimeout(cmd);
-    virCommandAddArgList(cmd, "get", "Interface", tmpIfname, "name", NULL);
-    if (virCommandRun(cmd, &status) < 0 ||
-        status) {
+
+    if (server) {
+        virCommandAddArgList(cmd, "--no-headings", "--columns=name", "find",
+                             "Interface", NULL);
+        virCommandAddArgPair(cmd, "options:vhost-server-path", "path");
+    } else {
+        const char *tmpIfname = NULL;
+
+        /* Openvswitch vhostuser path is hardcoded to
+         * /<runstatedir>/openvswitch/<ifname>
+         * for example: /var/run/openvswitch/dpdkvhostuser0
+         *
+         * so we pick the filename and check it's an openvswitch interface
+         */
+        if (!path ||
+            !(tmpIfname = strrchr(path, '/'))) {
+            return 0;
+        }
+
+        tmpIfname++;
+        virCommandAddArgList(cmd, "get", "Interface", tmpIfname, "name", NULL);
+    }
+
+    virCommandSetOutputBuffer(cmd, ifname);
+    if (virCommandRun(cmd, &status) < 0)
+        return -1;
+
+    if (status != 0) {
         /* it's not a openvswitch vhostuser interface. */
         return 0;
     }
 
-    *ifname = g_strdup(tmpIfname);
     return 1;
 }
 
index c9ea5920588f96e20357774b92319eb445e955a3..5cd1d22ae3f53008ac6578a4fe82c63b7f7e00f3 100644 (file)
@@ -61,6 +61,7 @@ int virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **master)
     ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
 
 int virNetDevOpenvswitchGetVhostuserIfname(const char *path,
+                                           bool server,
                                            char **ifname)
     ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT G_GNUC_NO_INLINE;
 
index 2cdbe7e3569f465de2c3aa58f8c4f9a08bc7039b..6900232b33ee24e096737f9f52a6f9a9dba242e4 100644 (file)
@@ -217,6 +217,7 @@ virCommandPassFD(virCommandPtr cmd,
 
 int
 virNetDevOpenvswitchGetVhostuserIfname(const char *path G_GNUC_UNUSED,
+                                       bool server G_GNUC_UNUSED,
                                        char **ifname)
 {
     *ifname = g_strdup("vhost-user0");