[PATCH 3/3] [bhyve] parse passthru argument from XML-config

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

 



Sponsored by: Future Crew, LLC
Signed-off-by: Alexander Shursha <kekek2@xxxxx>
---
 src/bhyve/bhyve_parse_command.c | 59 +++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 29d3a678bf..14916c401d 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -639,6 +639,63 @@ bhyveParsePCIFbuf(virDomainDef *def,
     return -1;
 }
 
+static int
+bhyveParsePassthru(virDomainDef *def G_GNUC_UNUSED,
+                  unsigned pcibus,
+                  unsigned pcislot,
+                  unsigned pcifunction,
+                  char *addr)
+{
+    /* -s slot,bus/slot/function */
+    /* -s slot,pcibus:slot:function */
+    virDomainHostdevDef *hostdev = NULL;
+    g_auto(GStrv) params = NULL;
+    GStrv param;
+    char *p = NULL;
+
+    if (!(hostdev = virDomainHostdevDefNew()))
+        return 0;
+
+    hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
+    hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
+
+    hostdev->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+    hostdev->info->addr.pci.bus = pcibus;
+    hostdev->info->addr.pci.slot = pcislot;
+    hostdev->info->addr.pci.function = pcifunction;
+
+    if (!addr)
+        goto error;
+
+    if (!(params = g_strsplit(addr, ":", -1))) {
+        virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to parse PCI address %1$s"), addr);
+        goto error;
+    }
+    if (g_str_equal(addr, *params))
+        if (!(params = g_strsplit(addr, "/", -1))) {
+            virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to parse PCI address %1$s"), addr);
+            goto error;
+        }
+    if (g_strv_length(params) != 3) {
+        virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to parse PCI address %1$s"), addr);
+        goto error;
+    }
+    param = params;
+    hostdev->source.subsys.u.pci.addr.bus = g_ascii_strtoull(*param++, &p, 10);
+    hostdev->source.subsys.u.pci.addr.slot = g_ascii_strtoull(*param++, &p, 10);
+    hostdev->source.subsys.u.pci.addr.function = g_ascii_strtoull(*param, &p, 10);
+
+    hostdev->source.subsys.u.pci.addr.domain = 0;
+    hostdev->managed = false;
+
+    VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev);
+    return 0;
+
+    error:
+        virDomainHostdevDefFree(hostdev);
+        return -1;
+}
+
 static int
 bhyveParseBhyvePCIArg(virDomainDef *def,
                       virDomainXMLOption *xmlopt,
@@ -703,6 +760,8 @@ bhyveParseBhyvePCIArg(virDomainDef *def,
                          VIR_DOMAIN_NET_MODEL_E1000, conf);
     else if (STREQ(emulation, "fbuf"))
         bhyveParsePCIFbuf(def, xmlopt, caps, bus, slot, function, conf);
+    else if (STREQ(emulation, "passthru"))
+        bhyveParsePassthru(def, bus, slot, function, conf);
 
     VIR_FREE(emulation);
     VIR_FREE(slotdef);
-- 
2.47.1



[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]

  Powered by Linux