From: Hyman Huang <yong.hu...@smartx.com> Introduce the virNetDevVhostUserIface struct to encapsulate the necessary configuration for attaching a vhostuser port to a bridge.
Update the virNetDevOpenvswitchAddPort signature to accept an additional iface argument. Extend the implementation of virNetDevOpenvswitchAddPort to fully support automatic attachment of the vhostuser port. --- src/lxc/lxc_process.c | 3 ++- src/util/virnetdevopenvswitch.c | 36 ++++++++++++++++++++++++++++++++- src/util/virnetdevopenvswitch.h | 10 ++++++++- src/util/virnetdevtap.c | 3 ++- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 1bca9e8dae..ad1554fa56 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -286,7 +286,8 @@ virLXCProcessSetupInterfaceTap(virDomainDef *vm, if (brname) { if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) { if (virNetDevOpenvswitchAddPort(brname, parentVeth, &net->mac, vm->uuid, - vport, virDomainNetGetActualVlan(net)) < 0) + vport, virDomainNetGetActualVlan(net), + NULL) < 0) return NULL; } else { if (virNetDevBridgeAddPort(brname, parentVeth, virDomainNetGetActualVlan(net)) < 0) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 868d6d26ba..6f6b995fe2 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -119,6 +119,36 @@ virNetDevOpenvswitchConstructVlans(virCommand *cmd, const virNetDevVlan *virtVla } } +/** + * virNetDevOpenvswitchConstructIface: + * @cmd: command to construct + * @ifname: the ovs interface name + * @iface: the configuration of ovs vhost user interface + * + * Construct the ovs vhost user interface configuration + * parameters to be passed to ovs-vsctl command. + * + */ +static void +virNetDevOpenvswitchConstructIface(virCommand *cmd, const char *ifname, + const virNetDevVhostUserIface *iface) +{ + g_autofree char *type_info = NULL; + g_autofree char *server_path = NULL; + + if (!ifname || !iface) + return; + + type_info = g_strdup_printf("type=\"%s\"", + iface->client ? "dpdkvhostuserclient" : "dpdkvhostuser"); + server_path = g_strdup_printf("options:vhost-server-path=\"%s\"", iface->path); + + virCommandAddArgList(cmd, + "--", "set", "Interface", ifname, type_info, + "--", "set", "Interface", ifname, server_path, + NULL); +} + /** * virNetDevOpenvswitchAddPort: * @brname: the bridge name @@ -126,6 +156,7 @@ virNetDevOpenvswitchConstructVlans(virCommand *cmd, const virNetDevVlan *virtVla * @macaddr: the mac address of the virtual interface * @vmuuid: the Domain UUID that has this interface * @ovsport: the ovs specific fields + * @ovsiface: the configuration of ovs vhost user interface * * Add an interface to the OVS bridge * @@ -135,7 +166,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, const virMacAddr *macaddr, const unsigned char *vmuuid, const virNetDevVPortProfile *ovsport, - const virNetDevVlan *virtVlan) + const virNetDevVlan *virtVlan, + const virNetDevVhostUserIface *ovsiface) { char macaddrstr[VIR_MAC_STRING_BUFLEN]; char ifuuidstr[VIR_UUID_STRING_BUFLEN]; @@ -170,6 +202,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, virNetDevOpenvswitchConstructVlans(cmd, virtVlan); + virNetDevOpenvswitchConstructIface(cmd, ifname, ovsiface); + if (ovsport->profileID[0] == '\0') { virCommandAddArgList(cmd, "--", "set", "Interface", ifname, attachedmac_ex_id, diff --git a/src/util/virnetdevopenvswitch.h b/src/util/virnetdevopenvswitch.h index 3b4a1e509b..4d5300f7d8 100644 --- a/src/util/virnetdevopenvswitch.h +++ b/src/util/virnetdevopenvswitch.h @@ -27,6 +27,13 @@ #define VIR_NETDEV_OVS_DEFAULT_TIMEOUT 5 +typedef struct _virNetDevVhostUserIface virNetDevVhostUserIface; +typedef virNetDevVhostUserIface *virNetDevVhostUserIfacePtr; +struct _virNetDevVhostUserIface { + bool client; + char *path; /* vhost user path listened by server */ +}; + void virNetDevOpenvswitchSetTimeout(unsigned int timeout); int virNetDevOpenvswitchAddPort(const char *brname, @@ -34,7 +41,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const virMacAddr *macaddr, const unsigned char *vmuuid, const virNetDevVPortProfile *ovsport, - const virNetDevVlan *virtVlan) + const virNetDevVlan *virtVlan, + const virNetDevVhostUserIface *ovsiface) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) G_GNUC_WARN_UNUSED_RESULT; diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index b709d76cc7..f0e0c3c16b 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -479,7 +479,8 @@ virNetDevTapAttachBridge(const char *tapname, return -1; } else if (virtPortProfile->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) { if (virNetDevOpenvswitchAddPort(brname, tapname, macaddr, vmuuid, - virtPortProfile, virtVlan) < 0) + virtPortProfile, virtVlan, + NULL) < 0) return -1; } } else { -- 2.27.0