]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virsh-domain: update attach-interface to support type=hostdev
authorPavel Hrdina <phrdina@redhat.com>
Wed, 21 Oct 2015 10:59:41 +0000 (12:59 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 11 Nov 2015 14:03:42 +0000 (15:03 +0100)
Adding this feature will allow users to easily attach a hostdev network
interface using PCI passthrough.

The interface can be attached using --type=hostdev and PCI address or
as --source.  This command also allows you to tell, whether the interface
should be managed.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=997561

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
tools/virsh-domain.c
tools/virsh.pod

index 12e85e36890eb03082861a0dbf1f992075fe7145..bd00785622b234f0a0a8373474fb2f15c3e3e742 100644 (file)
@@ -56,6 +56,7 @@
 #include "virtime.h"
 #include "virtypedparam.h"
 #include "virxml.h"
+#include "virsh-nodedev.h"
 
 /* Gnulib doesn't guarantee SA_SIGINFO support.  */
 #ifndef SA_SIGINFO
@@ -866,6 +867,10 @@ static const vshCmdOptDef opts_attach_interface[] = {
      .type = VSH_OT_BOOL,
      .help = N_("print XML document rather than attach the interface")
     },
+    {.name = "managed",
+     .type = VSH_OT_BOOL,
+     .help = N_("libvirt will automatically detach/attach the device from/to host")
+    },
     {.name = NULL}
 };
 
@@ -931,6 +936,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     bool config = vshCommandOptBool(cmd, "config");
     bool live = vshCommandOptBool(cmd, "live");
     bool persistent = vshCommandOptBool(cmd, "persistent");
+    bool managed = vshCommandOptBool(cmd, "managed");
 
     VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
 
@@ -983,7 +989,12 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     }
 
     /* Make XML of interface */
-    virBufferAsprintf(&buf, "<interface type='%s'>\n", type);
+    virBufferAsprintf(&buf, "<interface type='%s'", type);
+
+    if (managed)
+        virBufferAddLit(&buf, " managed='yes'>\n");
+    else
+        virBufferAddLit(&buf, ">\n");
     virBufferAdjustIndent(&buf, 2);
 
     switch (typ) {
@@ -995,6 +1006,26 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     case VIR_DOMAIN_NET_TYPE_DIRECT:
         virBufferAsprintf(&buf, "<source dev='%s'/>\n", source);
         break;
+    case VIR_DOMAIN_NET_TYPE_HOSTDEV:
+    {
+        struct PCIAddress pciAddr = {0, 0, 0, 0};
+
+        if (str2PCIAddress(source, &pciAddr) < 0) {
+            vshError(ctl, _("cannot parse pci address '%s' for network "
+                            "interface"), source);
+            goto cleanup;
+        }
+
+        virBufferAddLit(&buf, "<source>\n");
+        virBufferAdjustIndent(&buf, 2);
+        virBufferAsprintf(&buf, "<address type='pci' domain='0x%.4x'"
+                          " bus='0x%.2x' slot='0x%.2x' function='0x%.1x'/>\n",
+                          pciAddr.domain, pciAddr.bus,
+                          pciAddr.slot, pciAddr.function);
+        virBufferAdjustIndent(&buf, -2);
+        virBufferAddLit(&buf, "</source>\n");
+        break;
+    }
 
     case VIR_DOMAIN_NET_TYPE_USER:
     case VIR_DOMAIN_NET_TYPE_ETHERNET:
@@ -1004,7 +1035,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     case VIR_DOMAIN_NET_TYPE_MCAST:
     case VIR_DOMAIN_NET_TYPE_UDP:
     case VIR_DOMAIN_NET_TYPE_INTERNAL:
-    case VIR_DOMAIN_NET_TYPE_HOSTDEV:
     case VIR_DOMAIN_NET_TYPE_LAST:
         vshError(ctl, _("No support for %s in command 'attach-interface'"),
                  type);
index ee8e6d0a00f8eb2ed5a12b53aa69f2d13f2bf7d4..21ae4a3e5b460c6d1aaf4176581f307a6e35d060 100644 (file)
@@ -2522,6 +2522,9 @@ I<bridge> to indicate connection via a bridge device on the host,
 I<direct> to indicate connection directly to one of the host's network
 interfaces or bridges,
 
+I<hostdev> to indicate connection using a passthrough of PCI device
+on the host.
+
 =back
 
 B<source> indicates the source of the connection.  The source depends
@@ -2535,6 +2538,9 @@ I<bridge> the name of the bridge device,
 
 I<direct> the name of the host's interface or bridge,
 
+I<hostdev> the PCI address of the host's interface formatted
+as domain:bus:slot.function.
+
 =back
 
 B<--target> is used to specify the tap/macvtap device to be used to
@@ -2565,6 +2571,10 @@ kilobytes in a single burst at I<peak> speed as described in the
 Network XML documentation at
 L<http://libvirt.org/formatnetwork.html#elementQoS>.
 
+B<--managed> is usable only for I<hostdev> type and tells libvirt
+that the interface should be managed, which means detached and reattached
+from/to the host by libvirt.
+
 If B<--print-xml> is specified, then the XML of the interface that would be
 attached is printed instead.