From nobody Thu May 2 09:43:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629213160; cv=none; d=zohomail.com; s=zohoarc; b=bBFAvZdkvCrylxEn57JOH5n40E4t/L9I7x/BeBOJtPpcrMaA8NFU6KRQyZO/hlQ3xo9BrwQSZ6fiYY5knxgVE6d3Gd3QIxK5YKzrvwSlglUQsiWH7Nea28LupqvUmvzMGng9hwbqe8juMuEyrcg623ke7lpAOIANwoy/HGYMsWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629213160; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=iu8w5tXHRvPQYGK+owQgzbzFVvWfF2vO5Eqx3s/i/IM=; b=fvdzlBPyBEK3b1aM0IvqcMu/XKWZppwsRBVvQrXTNoM+qeuLH9D6s60+BfKo8rGGO2UD5AlEnY7UyV/8eU1N6FeMzguc8VE51XRIW8XFKyGSa4snhTu9JcoLMnq8/dIuiDAa6Xl8a4YQ3RqqxWjItIMBDAbrBTskDDtg80hNE0I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1629213160298544.9465595783281; Tue, 17 Aug 2021 08:12:40 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-517-OKNSVHL8O6OQSfGuFgb88Q-1; Tue, 17 Aug 2021 11:12:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7FDB8190A7A2; Tue, 17 Aug 2021 15:12:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 81C25179B3; Tue, 17 Aug 2021 15:12:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2DC16181A2A6; Tue, 17 Aug 2021 15:12:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17HF6Uj6009315 for ; Tue, 17 Aug 2021 11:06:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id F3EC3BA6F; Tue, 17 Aug 2021 15:06:29 +0000 (UTC) Received: from bart.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CD3060C17 for ; Tue, 17 Aug 2021 15:06:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629213159; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iu8w5tXHRvPQYGK+owQgzbzFVvWfF2vO5Eqx3s/i/IM=; b=aXTPfMGNKO9n5VOD5no7aGLe1PmbL3mWVzFF+aF1Wi+s3qKU9rfV78rSqAblvs0vpyS0JH 87u3iYbE9/EZuOMxezc7YFryNBv3Uj2fl+hTd22slTlMok1j3U2xWWfCftMLYmRdJVkOiR qmBJQwEGNIhpLL7vSmeSn3l06wzGd38= X-MC-Unique: OKNSVHL8O6OQSfGuFgb88Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virsh: Support vhostuser in attach-interface Date: Tue, 17 Aug 2021 17:06:21 +0200 Message-Id: <827ed33ed57dc5151b6c2b7b838387e1539a9339.1629212781.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629213161931100001 Content-Type: text/plain; charset="utf-8" Recently, I wanted to attach an vhost-user interface but found out that attach-interface command doesn't support it. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- docs/manpages/virsh.rst | 11 ++++++++++- tools/virsh-completer-domain.c | 19 +++++++++++++++++++ tools/virsh-completer-domain.h | 5 +++++ tools/virsh-domain.c | 32 ++++++++++++++++++++++++++++++-- tools/virsh-domain.h | 8 ++++++++ 5 files changed, 72 insertions(+), 3 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 20936994ce..8a875d0d2e 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -4676,6 +4676,7 @@ attach-interface [--target target] [--mac mac] [--script script] [--model model] [--inbound average,peak,burst,floor] [--outbound average,peak,burst] [--alias alias] [--managed] [--print-xml] + [--source-mode mode] =20 Attach a new network interface to the domain. =20 @@ -4689,7 +4690,9 @@ Attach a new network interface to the domain. interfaces or bridges, =20 *hostdev* to indicate connection using a passthrough of PCI device -on the host. +on the host, + +*vhostuser* to indicate connection using a virtio transport protocol. =20 ``source`` indicates the source of the connection. The source depends on the type of the interface: @@ -4703,6 +4706,8 @@ on the type of the interface: *hostdev* the PCI address of the host's interface formatted as domain:bus:slot.function. =20 +*vhostuser* the path to UNIX socket (control plane) + ``--target`` is used to specify the tap/macvtap device to be used to connect the domain to the source. Names starting with 'vnet' are considered as auto-generated and are blanked out/regenerated each @@ -4737,6 +4742,10 @@ Network XML documentation at that the interface should be managed, which means detached and reattached from/to the host by libvirt. =20 +``--source-mode`` is mandatory for *vhostuser* interface and accepts values +*server* and *client* that control whether hypervisor waits for the other +process to connect, or initiates connection, respectively. + If ``--print-xml`` is specified, then the XML of the interface that would = be attached is printed instead. =20 diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index c86d8e8156..3ef6c82388 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -372,6 +372,25 @@ virshDomainInterfaceAddrSourceCompleter(vshControl *ct= l G_GNUC_UNUSED, } =20 =20 +char ** +virshDomainInterfaceSourceModeCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + char **ret =3D NULL; + size_t i; + + virCheckFlags(0, NULL); + + ret =3D g_new0(char *, VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_LAST); + + for (i =3D 0; i < VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_LAST; i++) + ret[i] =3D g_strdup(virshDomainInterfaceSourceModeTypeToString(i)); + + return ret; +} + + char ** virshDomainHostnameSourceCompleter(vshControl *ctl G_GNUC_UNUSED, const vshCmd *cmd G_GNUC_UNUSED, diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 45380906f9..39cedf0141 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -59,6 +59,11 @@ virshDomainInterfaceAddrSourceCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** +virshDomainInterfaceSourceModeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + char ** virshDomainHostnameSourceCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 62912aaf01..e5bd1fdd75 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -831,9 +831,19 @@ static const vshCmdOptDef opts_attach_interface[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("libvirt will automatically detach/attach the device fro= m/to host") }, + {.name =3D "source-mode", + .type =3D VSH_OT_STRING, + .completer =3D virshDomainInterfaceSourceModeCompleter, + .help =3D N_("mode attribute of element") + }, {.name =3D NULL} }; =20 +VIR_ENUM_IMPL(virshDomainInterfaceSourceMode, + VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_LAST, + "server", + "client"); + /* parse inbound and outbound which are in the format of * 'average,peak,burst,floor', in which peak and burst are optional, * thus 'average,,burst' and 'average,peak' are also legal. */ @@ -881,6 +891,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) const char *mac =3D NULL, *target =3D NULL, *script =3D NULL, *type =3D NULL, *source =3D NULL, *model =3D NULL, *inboundStr =3D NULL, *outboundStr =3D NULL, *alias =3D NUL= L; + const char *sourceModeStr =3D NULL; + int sourceMode =3D -1; virNetDevBandwidthRate inbound, outbound; virDomainNetType typ; int ret; @@ -911,7 +923,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "model", &model) < 0 || vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 || vshCommandOptStringReq(ctl, cmd, "inbound", &inboundStr) < 0 || - vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0) + vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0 || + vshCommandOptStringReq(ctl, cmd, "source-mode", &sourceModeStr) < = 0) return false; =20 /* check interface type */ @@ -921,6 +934,12 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) return false; } =20 + if (sourceModeStr && + (sourceMode =3D virshDomainInterfaceSourceModeTypeFromString(sourc= eModeStr)) < 0) { + vshError(ctl, _("Invalid source mode: %s"), sourceModeStr); + return false; + } + if (inboundStr) { memset(&inbound, 0, sizeof(inbound)); if (virshParseRateStr(ctl, inboundStr, &inbound) < 0) @@ -981,9 +1000,18 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) break; } =20 + case VIR_DOMAIN_NET_TYPE_VHOSTUSER: + if (sourceMode < 0) { + vshError(ctl, _("source-mode is mandatory")); + return false; + } + virBufferAsprintf(&buf, "\n", + source, + virshDomainInterfaceSourceModeTypeToString(sourc= eMode)); + break; + case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_ETHERNET: - case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: case VIR_DOMAIN_NET_TYPE_MCAST: diff --git a/tools/virsh-domain.h b/tools/virsh-domain.h index a1ac1cf1d4..cf5ce28825 100644 --- a/tools/virsh-domain.h +++ b/tools/virsh-domain.h @@ -38,6 +38,14 @@ typedef enum { =20 VIR_ENUM_DECL(virshDomainHostnameSource); =20 +typedef enum { + VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_SERVER, + VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_CLIENT, + VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_LAST +} virshDomainInterfaceSourceMode; + +VIR_ENUM_DECL(virshDomainInterfaceSourceMode); + extern const vshCmdDef domManagementCmds[]; =20 VIR_ENUM_DECL(virshDomainProcessSignal); --=20 2.31.1