1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

virnetdevopenvswitch: Get names for dpdkvhostuserclient too

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>
This commit is contained in:
Michal Privoznik 2019-11-06 11:59:22 +01:00
parent 3c7c7cd4d8
commit e4c29e2904
5 changed files with 47 additions and 19 deletions

View File

@ -8004,6 +8004,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
if (virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->data.nix.path, if (virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->data.nix.path,
net->data.vhostuser->data.nix.listen,
&net->ifname) < 0) &net->ifname) < 0)
goto cleanup; goto cleanup;

View File

@ -1305,6 +1305,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
if (virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->data.nix.path, if (virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->data.nix.path,
net->data.vhostuser->data.nix.listen,
&net->ifname) < 0) &net->ifname) < 0)
goto cleanup; goto cleanup;

View File

@ -469,11 +469,22 @@ virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **master)
/** /**
* virNetDevOpenvswitchVhostuserGetIfname: * virNetDevOpenvswitchGetVhostuserIfname:
* @path: the path of the unix socket * @path: the path of the unix socket
* @server: true if OVS creates the @path
* @ifname: the retrieved name of the interface * @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, * Returns: 1 if interface is an openvswitch interface,
* 0 if it is not, but no other error occurred, * 0 if it is not, but no other error occurred,
@ -481,33 +492,46 @@ virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **master)
*/ */
int int
virNetDevOpenvswitchGetVhostuserIfname(const char *path, virNetDevOpenvswitchGetVhostuserIfname(const char *path,
bool server,
char **ifname) char **ifname)
{ {
const char *tmpIfname = NULL;
int status;
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
int status;
/* Openvswitch vhostuser path are hardcoded to cmd = virCommandNew(OVS_VSCTL);
virNetDevOpenvswitchAddTimeout(cmd);
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> * /<runstatedir>/openvswitch/<ifname>
* for example: /var/run/openvswitch/dpdkvhostuser0 * for example: /var/run/openvswitch/dpdkvhostuser0
* *
* so we pick the filename and check it's a openvswitch interface * so we pick the filename and check it's an openvswitch interface
*/ */
if (!path || if (!path ||
!(tmpIfname = strrchr(path, '/'))) !(tmpIfname = strrchr(path, '/'))) {
return 0; return 0;
}
tmpIfname++; tmpIfname++;
cmd = virCommandNew(OVS_VSCTL);
virNetDevOpenvswitchAddTimeout(cmd);
virCommandAddArgList(cmd, "get", "Interface", tmpIfname, "name", NULL); virCommandAddArgList(cmd, "get", "Interface", tmpIfname, "name", NULL);
if (virCommandRun(cmd, &status) < 0 || }
status) {
virCommandSetOutputBuffer(cmd, ifname);
if (virCommandRun(cmd, &status) < 0)
return -1;
if (status != 0) {
/* it's not a openvswitch vhostuser interface. */ /* it's not a openvswitch vhostuser interface. */
return 0; return 0;
} }
*ifname = g_strdup(tmpIfname);
return 1; return 1;
} }

View File

@ -61,6 +61,7 @@ int virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **master)
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT; ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
int virNetDevOpenvswitchGetVhostuserIfname(const char *path, int virNetDevOpenvswitchGetVhostuserIfname(const char *path,
bool server,
char **ifname) char **ifname)
ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT G_GNUC_NO_INLINE; ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT G_GNUC_NO_INLINE;

View File

@ -217,6 +217,7 @@ virCommandPassFD(virCommandPtr cmd,
int int
virNetDevOpenvswitchGetVhostuserIfname(const char *path G_GNUC_UNUSED, virNetDevOpenvswitchGetVhostuserIfname(const char *path G_GNUC_UNUSED,
bool server G_GNUC_UNUSED,
char **ifname) char **ifname)
{ {
*ifname = g_strdup("vhost-user0"); *ifname = g_strdup("vhost-user0");