From a9a583d6df74a795f26f4ac4187eede842a7a2b6 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Wed, 21 Oct 2015 12:59:41 +0200 Subject: [PATCH] virsh-domain: update attach-interface to support type=hostdev 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 --- tools/virsh-domain.c | 34 ++++++++++++++++++++++++++++++++-- tools/virsh.pod | 10 ++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 12e85e3689..bd00785622 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -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, "\n", type); + virBufferAsprintf(&buf, "\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, "\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, "\n"); + virBufferAdjustIndent(&buf, 2); + virBufferAsprintf(&buf, "
\n", + pciAddr.domain, pciAddr.bus, + pciAddr.slot, pciAddr.function); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\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); diff --git a/tools/virsh.pod b/tools/virsh.pod index ee8e6d0a00..21ae4a3e5b 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -2522,6 +2522,9 @@ I to indicate connection via a bridge device on the host, I to indicate connection directly to one of the host's network interfaces or bridges, +I to indicate connection using a passthrough of PCI device +on the host. + =back B indicates the source of the connection. The source depends @@ -2535,6 +2538,9 @@ I the name of the bridge device, I the name of the host's interface or bridge, +I 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 speed as described in the Network XML documentation at L. +B<--managed> is usable only for I 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.