]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Support vhostuser in attach-interface
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 17 Aug 2021 11:03:04 +0000 (13:03 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 18 Aug 2021 12:21:40 +0000 (14:21 +0200)
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>
docs/manpages/virsh.rst
tools/virsh-completer-domain.c
tools/virsh-completer-domain.h
tools/virsh-domain.c
tools/virsh-domain.h

index 4075929a76ea22c75a99a5d9aa4f59200c503168..3eb310d02e36a6c845095bcad248d9316e03bab8 100644 (file)
@@ -4659,6 +4659,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]
 
 Attach a new network interface to the domain.
 
@@ -4672,7 +4673,9 @@ Attach a new network interface to the domain.
 interfaces or bridges,
 
 *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
 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
 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
 connect the domain to the source.  Names starting with 'vnet' are
 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
 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
 attached is printed instead.
 
index c86d8e81565800765940b8ab7326491c04f4ab14..3ef6c82388cc30500b2eb40683ec2e967d369c02 100644 (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 **
 virshDomainHostnameSourceCompleter(vshControl *ctl G_GNUC_UNUSED,
                                    const vshCmd *cmd G_GNUC_UNUSED,
index 45380906f97e84eac2e3aea1942693dae6377356..39cedf014192dd2a43af5867d3648f485f9ad218 100644 (file)
@@ -59,6 +59,11 @@ virshDomainInterfaceAddrSourceCompleter(vshControl *ctl,
                                         const vshCmd *cmd,
                                         unsigned int flags);
 
+char **
+virshDomainInterfaceSourceModeCompleter(vshControl *ctl,
+                                        const vshCmd *cmd,
+                                        unsigned int flags);
+
 char ** virshDomainHostnameSourceCompleter(vshControl *ctl,
                                            const vshCmd *cmd,
                                            unsigned int flags);
index 62912aaf0100599c4699e21ac44535132cf3a206..e5bd1fdd75cd49c10b78f6d491b8601f23e6fc31 100644 (file)
@@ -831,9 +831,19 @@ static const vshCmdOptDef opts_attach_interface[] = {
      .type = VSH_OT_BOOL,
      .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}
 };
 
+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 = NULL, *target = NULL, *script = NULL,
                *type = NULL, *source = NULL, *model = NULL,
                *inboundStr = NULL, *outboundStr = NULL, *alias = NULL;
+    const char *sourceModeStr = NULL;
+    int sourceMode = -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;
 
     /* check interface type */
@@ -921,6 +934,12 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
+    if (sourceModeStr &&
+        (sourceMode = virshDomainInterfaceSourceModeTypeFromString(sourceModeStr)) < 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;
     }
 
+    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_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:
index a1ac1cf1d456801c596ecf0626f43174d763e79e..cf5ce288250f8c223f6ca4d7c6d1d73104691227 100644 (file)
@@ -38,6 +38,14 @@ typedef enum {
 
 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[];
 
 VIR_ENUM_DECL(virshDomainProcessSignal);