1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-10 05:17:59 +03:00

virsh: Support vhostuser in attach-interface

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 <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Michal Privoznik 2021-08-17 13:03:04 +02:00
parent 8efd949c8b
commit 868bacd380
5 changed files with 72 additions and 3 deletions

View File

@ -4659,6 +4659,7 @@ attach-interface
[--target target] [--mac mac] [--script script] [--model model] [--target target] [--mac mac] [--script script] [--model model]
[--inbound average,peak,burst,floor] [--outbound average,peak,burst] [--inbound average,peak,burst,floor] [--outbound average,peak,burst]
[--alias alias] [--managed] [--print-xml] [--alias alias] [--managed] [--print-xml]
[--source-mode mode]
Attach a new network interface to the domain. Attach a new network interface to the domain.
@ -4672,7 +4673,9 @@ Attach a new network interface to the domain.
interfaces or bridges, interfaces or bridges,
*hostdev* to indicate connection using a passthrough of PCI device *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.
``source`` indicates the source of the connection. The source depends ``source`` indicates the source of the connection. The source depends
on the type of the interface: on the type of the interface:
@ -4686,6 +4689,8 @@ on the type of the interface:
*hostdev* the PCI address of the host's interface formatted *hostdev* the PCI address of the host's interface formatted
as domain:bus:slot.function. as domain:bus:slot.function.
*vhostuser* the path to UNIX socket (control plane)
``--target`` is used to specify the tap/macvtap device to be used to ``--target`` is used to specify the tap/macvtap device to be used to
connect the domain to the source. Names starting with 'vnet' are connect the domain to the source. Names starting with 'vnet' are
considered as auto-generated and are blanked out/regenerated each considered as auto-generated and are blanked out/regenerated each
@ -4720,6 +4725,10 @@ Network XML documentation at
that the interface should be managed, which means detached and reattached that the interface should be managed, which means detached and reattached
from/to the host by libvirt. from/to the host by libvirt.
``--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 If ``--print-xml`` is specified, then the XML of the interface that would be
attached is printed instead. attached is printed instead.

View File

@ -372,6 +372,25 @@ virshDomainInterfaceAddrSourceCompleter(vshControl *ctl G_GNUC_UNUSED,
} }
char **
virshDomainInterfaceSourceModeCompleter(vshControl *ctl G_GNUC_UNUSED,
const vshCmd *cmd G_GNUC_UNUSED,
unsigned int flags)
{
char **ret = NULL;
size_t i;
virCheckFlags(0, NULL);
ret = g_new0(char *, VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_LAST);
for (i = 0; i < VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_LAST; i++)
ret[i] = g_strdup(virshDomainInterfaceSourceModeTypeToString(i));
return ret;
}
char ** char **
virshDomainHostnameSourceCompleter(vshControl *ctl G_GNUC_UNUSED, virshDomainHostnameSourceCompleter(vshControl *ctl G_GNUC_UNUSED,
const vshCmd *cmd G_GNUC_UNUSED, const vshCmd *cmd G_GNUC_UNUSED,

View File

@ -59,6 +59,11 @@ virshDomainInterfaceAddrSourceCompleter(vshControl *ctl,
const vshCmd *cmd, const vshCmd *cmd,
unsigned int flags); unsigned int flags);
char **
virshDomainInterfaceSourceModeCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char ** virshDomainHostnameSourceCompleter(vshControl *ctl, char ** virshDomainHostnameSourceCompleter(vshControl *ctl,
const vshCmd *cmd, const vshCmd *cmd,
unsigned int flags); unsigned int flags);

View File

@ -831,9 +831,19 @@ static const vshCmdOptDef opts_attach_interface[] = {
.type = VSH_OT_BOOL, .type = VSH_OT_BOOL,
.help = N_("libvirt will automatically detach/attach the device from/to host") .help = N_("libvirt will automatically detach/attach the device from/to host")
}, },
{.name = "source-mode",
.type = VSH_OT_STRING,
.completer = virshDomainInterfaceSourceModeCompleter,
.help = N_("mode attribute of <source/> element")
},
{.name = NULL} {.name = NULL}
}; };
VIR_ENUM_IMPL(virshDomainInterfaceSourceMode,
VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_LAST,
"server",
"client");
/* parse inbound and outbound which are in the format of /* parse inbound and outbound which are in the format of
* 'average,peak,burst,floor', in which peak and burst are optional, * 'average,peak,burst,floor', in which peak and burst are optional,
* thus 'average,,burst' and 'average,peak' are also legal. */ * thus 'average,,burst' and 'average,peak' are also legal. */
@ -881,6 +891,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
const char *mac = NULL, *target = NULL, *script = NULL, const char *mac = NULL, *target = NULL, *script = NULL,
*type = NULL, *source = NULL, *model = NULL, *type = NULL, *source = NULL, *model = NULL,
*inboundStr = NULL, *outboundStr = NULL, *alias = NULL; *inboundStr = NULL, *outboundStr = NULL, *alias = NULL;
const char *sourceModeStr = NULL;
int sourceMode = -1;
virNetDevBandwidthRate inbound, outbound; virNetDevBandwidthRate inbound, outbound;
virDomainNetType typ; virDomainNetType typ;
int ret; int ret;
@ -911,7 +923,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
vshCommandOptStringReq(ctl, cmd, "model", &model) < 0 || vshCommandOptStringReq(ctl, cmd, "model", &model) < 0 ||
vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 || vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 ||
vshCommandOptStringReq(ctl, cmd, "inbound", &inboundStr) < 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; return false;
/* check interface type */ /* check interface type */
@ -921,6 +934,12 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
return false; return false;
} }
if (sourceModeStr &&
(sourceMode = virshDomainInterfaceSourceModeTypeFromString(sourceModeStr)) < 0) {
vshError(ctl, _("Invalid source mode: %s"), sourceModeStr);
return false;
}
if (inboundStr) { if (inboundStr) {
memset(&inbound, 0, sizeof(inbound)); memset(&inbound, 0, sizeof(inbound));
if (virshParseRateStr(ctl, inboundStr, &inbound) < 0) if (virshParseRateStr(ctl, inboundStr, &inbound) < 0)
@ -981,9 +1000,18 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
break; break;
} }
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
if (sourceMode < 0) {
vshError(ctl, _("source-mode is mandatory"));
return false;
}
virBufferAsprintf(&buf, "<source type='unix' path='%s' mode='%s'/>\n",
source,
virshDomainInterfaceSourceModeTypeToString(sourceMode));
break;
case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_USER:
case VIR_DOMAIN_NET_TYPE_ETHERNET: case VIR_DOMAIN_NET_TYPE_ETHERNET:
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_SERVER:
case VIR_DOMAIN_NET_TYPE_CLIENT: case VIR_DOMAIN_NET_TYPE_CLIENT:
case VIR_DOMAIN_NET_TYPE_MCAST: case VIR_DOMAIN_NET_TYPE_MCAST:

View File

@ -38,6 +38,14 @@ typedef enum {
VIR_ENUM_DECL(virshDomainHostnameSource); VIR_ENUM_DECL(virshDomainHostnameSource);
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[]; extern const vshCmdDef domManagementCmds[];
VIR_ENUM_DECL(virshDomainProcessSignal); VIR_ENUM_DECL(virshDomainProcessSignal);