#include "virtime.h"
#include "virtypedparam.h"
#include "virxml.h"
+#include "virsh-nodedev.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
.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}
};
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);
}
/* 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) {
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:
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);
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
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
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.