[PATCH 2/2] virsh: allow to specify pci address with attach-interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>

This patch adds 2 options to attach-interface as --address and --multifunction.
I used --address rather than --pci_address becasue attach-disk has --address
for the same purpose, already.
---
 tools/virsh.c   |   38 ++++++++++++++++++++++++++++++++++++--
 tools/virsh.pod |    4 ++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 2cb3a19..2d0bbd8 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -12485,6 +12485,22 @@ static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr)
     return -1;
 }
 
+static int parsePCIAddress(const char *str, struct PCIAddress *address)
+{
+    char *type, *addr;
+
+    if (!address || !str)
+        return -1;
+
+    type = (char *)str;
+    addr = strchr(type, ':');
+    if (!addr)
+        return -1;
+    if (STREQLEN(type, "pci", addr - type))
+        return str2PCIAddress(addr + 1, address);
+    return -1;
+}
+
 static bool
 cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
 {
@@ -12797,6 +12813,9 @@ static const vshCmdOptDef opts_attach_interface[] = {
     {"persistent", VSH_OT_BOOL, 0, N_("persist interface attachment")},
     {"inbound", VSH_OT_DATA, VSH_OFLAG_NONE, N_("control domain's incoming traffics")},
     {"outbound", VSH_OT_DATA, VSH_OFLAG_NONE, N_("control domain's outgoing traffics")},
+    {"address", VSH_OT_DATA, VSH_OFLAG_NONE, N_("pci address of interface")},
+    {"multifunction", VSH_OT_BOOL, VSH_OFLAG_NONE,
+        N_("use multifunction pci under specified address")},
     {NULL, 0, 0, NULL}
 };
 
@@ -12841,7 +12860,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom = NULL;
     const char *mac = NULL, *target = NULL, *script = NULL,
                 *type = NULL, *source = NULL, *model = NULL,
-                *inboundStr = NULL, *outboundStr = NULL;
+                *inboundStr = NULL, *outboundStr = NULL, *pci_address = NULL;
     virNetDevBandwidthRate inbound, outbound;
     int typ;
     int ret;
@@ -12849,6 +12868,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     unsigned int flags;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     char *xml;
+    struct PCIAddress pci;
 
     if (!vshConnectionUsability(ctl, ctl->conn))
         goto cleanup;
@@ -12865,7 +12885,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
         vshCommandOptString(cmd, "script", &script) < 0 ||
         vshCommandOptString(cmd, "model", &model) < 0 ||
         vshCommandOptString(cmd, "inbound", &inboundStr) < 0 ||
-        vshCommandOptString(cmd, "outbound", &outboundStr) < 0) {
+        vshCommandOptString(cmd, "outbound", &outboundStr) < 0 ||
+        vshCommandOptString(cmd, "address", &pci_address) < 0) {
         vshError(ctl, "missing argument");
         goto cleanup;
     }
@@ -12921,6 +12942,19 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     if (model != NULL)
         virBufferAsprintf(&buf, "  <model type='%s'/>\n", model);
 
+    if (pci_address != NULL) {
+        if (parsePCIAddress(pci_address, &pci) < 0) {
+            vshError(ctl, "%s", _("expecting a pci:0000.00.00.00 address."));
+            goto cleanup;
+        }
+        virBufferAsprintf(&buf, "  <address type='pci' domain='0x%04x'"
+                          " bus ='0x%02x' slot='0x%02x' function='0x%0x'",
+                          pci.domain, pci.bus, pci.slot, pci.function);
+        if (vshCommandOptBool(cmd, "multifunction"))
+            virBufferAddLit(&buf, " multifunction='on'");
+        virBufferAddLit(&buf, "/>\n");
+    }
+
     if (inboundStr || outboundStr) {
         virBufferAsprintf(&buf, "  <bandwidth>\n");
         if (inboundStr && inbound.average > 0) {
diff --git a/tools/virsh.pod b/tools/virsh.pod
index c468f13..2682de5 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1300,6 +1300,7 @@ address.
 =item B<attach-interface> I<domain-id> I<type> I<source>
 [I<--target target>] [I<--mac mac>] [I<--script script>] [I<--model model>]
 [I<--persistent>] [I<--inbound average,peak,burst>] [I<--outbound average,peak,burst>]
+[I<--address pci_address>][I<--multifunction>]
 
 Attach a new network interface to the domain.
 I<type> can be either I<network> to indicate a physical network device or I<bridge> to indicate a bridge to a device.
@@ -1313,6 +1314,9 @@ I<persistent> indicates the changes will affect the next boot of the domain.
 I<inbound> and I<outbound> control the bandwidth of the interface. I<peak>
 and I<burst> are optional, so "average,peak", "average,,burst" and
 "average" are also legal.
+I<address> indicates the pci address where the interface is attached in the
+form of pci:domain.bus.slot.function. I<multifunction> indicates specified pci
+address is a multifunction pci device address.
 
 B<Note>: the optional target value is the name of a device to be created
 as the back-end on the node. If not provided a device named "vnetN" or "vifN"
-- 
1.7.4.1


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]