Xen 4.0 and DPCI key in sexpr

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

 



This blog post [1] explains how to apply some OpenSuse patches [2]
(especially xen-domctl-ver7.patch) to the libvirt 0.8.1 Debian package
in order to get Xen 4.0 support.

On IRC jonnyt reported problems with PCI passthrough in such a setup.
Debugging and XenD hacking revealed that XenD 4.0 extended the sexpr
format for PCI devices from

   (device (pci (dev (domain 0x0000)(bus 0x02)(slot 0x00)(func 0x0))))

to this, including a new key part

   (device (pci (dev (domain 0x0000)(bus 0x02)(slot 0x00)(func
0x0)(key <whatever-value-xend-expects-here>))))

The Xen upstream commit [3] that added this doesn't explain much about it.

I came up with the attached prove-of-concept patch that just hardcodes
(key 0x0) for XenD 4.0.

On IRC jonnyt confirmed that this patch fixes the immediate error for him:

   error : xend_post:434 : POST operation failed: xend_post: error
from xen daemon: (xend.err "Error creating domain: 'key'")

Matthias

[1] http://spblinux.de/blog/2010/05/xen-4-0-with-libvirt-0-8-1-replace-xm-new-by-virsh/
[2] https://build.opensuse.org/stage/package/files?package=libvirt&project=Virtualization
[3] http://lists.xensource.com/archives/html/xen-changelog/2009-06/msg00298.html
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index e763bad..ccfc401 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -87,7 +87,8 @@ xenDaemonFormatSxprNet(virConnectPtr conn ATTRIBUTE_UNUSED,
 static int
 xenDaemonFormatSxprOnePCI(virDomainHostdevDefPtr def,
                           virBufferPtr buf,
-                          int detach);
+                          int detach,
+                          int xendConfigVersion);
 
 static int
 virDomainXMLDevID(virDomainPtr domain,
@@ -3924,7 +3925,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
         if (dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
             dev->data.hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
             if (xenDaemonFormatSxprOnePCI(dev->data.hostdev,
-                                          &buf, 0) < 0)
+                                          &buf, 0, priv->xendConfigVersion) < 0)
                 goto cleanup;
         } else {
             virXendError(VIR_ERR_NO_SUPPORT, "%s",
@@ -4157,7 +4158,7 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain, const char *xml,
         if (dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
             dev->data.hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
             if (xenDaemonFormatSxprOnePCI(dev->data.hostdev,
-                                          &buf, 1) < 0)
+                                          &buf, 1, priv->xendConfigVersion) < 0)
                 goto cleanup;
         } else {
             virXendError(VIR_ERR_NO_SUPPORT, "%s",
@@ -5485,19 +5486,39 @@ xenDaemonFormatSxprNet(virConnectPtr conn,
 
 static void
 xenDaemonFormatSxprPCI(virDomainHostdevDefPtr def,
-                       virBufferPtr buf)
+                       virBufferPtr buf,
+                       int xendConfigVersion)
 {
-    virBufferVSprintf(buf, "(dev (domain 0x%04x)(bus 0x%02x)(slot 0x%02x)(func 0x%x))",
-                      def->source.subsys.u.pci.domain,
-                      def->source.subsys.u.pci.bus,
-                      def->source.subsys.u.pci.slot,
-                      def->source.subsys.u.pci.function);
+    /* xen 4 added this new key value, not sure what value to assign, so just
+     * hardcoding it to 0 for now.
+     *
+     * http://lists.xensource.com/archives/html/xen-changelog/2009-06/msg00298.html
+     *
+     *   xend: pass-through: Add key to pci device dictionary
+     *
+     *   This will be used to identify the functions belonging to
+     *   a multi-function device.
+     */
+    if (xendConfigVersion == 4) {
+        virBufferVSprintf(buf, "(dev (domain 0x%04x)(bus 0x%02x)(slot 0x%02x)(func 0x%x)(key 0x0))",
+                          def->source.subsys.u.pci.domain,
+                          def->source.subsys.u.pci.bus,
+                          def->source.subsys.u.pci.slot,
+                          def->source.subsys.u.pci.function);
+    } else {
+        virBufferVSprintf(buf, "(dev (domain 0x%04x)(bus 0x%02x)(slot 0x%02x)(func 0x%x))",
+                          def->source.subsys.u.pci.domain,
+                          def->source.subsys.u.pci.bus,
+                          def->source.subsys.u.pci.slot,
+                          def->source.subsys.u.pci.function);
+    }
 }
 
 static int
 xenDaemonFormatSxprOnePCI(virDomainHostdevDefPtr def,
                           virBufferPtr buf,
-                          int detach)
+                          int detach,
+                          int xendConfigVersion)
 {
     if (def->managed) {
         virXendError(VIR_ERR_NO_SUPPORT, "%s",
@@ -5506,7 +5527,7 @@ xenDaemonFormatSxprOnePCI(virDomainHostdevDefPtr def,
     }
 
     virBufferAddLit(buf, "(pci ");
-    xenDaemonFormatSxprPCI(def, buf);
+    xenDaemonFormatSxprPCI(def, buf, xendConfigVersion);
     if (detach)
         virBufferAddLit(buf, "(state 'Closing')");
     else
@@ -5518,7 +5539,8 @@ xenDaemonFormatSxprOnePCI(virDomainHostdevDefPtr def,
 
 static int
 xenDaemonFormatSxprAllPCI(virDomainDefPtr def,
-                          virBufferPtr buf)
+                          virBufferPtr buf,
+                          int xendConfigVersion)
 {
     int hasPCI = 0;
     int i;
@@ -5555,7 +5577,7 @@ xenDaemonFormatSxprAllPCI(virDomainDefPtr def,
                 return -1;
             }
 
-            xenDaemonFormatSxprPCI(def->hostdevs[i], buf);
+            xenDaemonFormatSxprPCI(def->hostdevs[i], buf, xendConfigVersion);
         }
     }
     virBufferAddLit(buf, "))");
@@ -5853,7 +5875,7 @@ xenDaemonFormatSxpr(virConnectPtr conn,
                                    &buf, hvm, xendConfigVersion, 0) < 0)
             goto error;
 
-    if (xenDaemonFormatSxprAllPCI(def, &buf) < 0)
+    if (xenDaemonFormatSxprAllPCI(def, &buf, xendConfigVersion) < 0)
         goto error;
 
     /* New style PV graphics config xen >= 3.0.4,
--
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]