[libvirt] [PATCH] PCI passthrough docs, tests and minor change

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

 



  The following add the documentation for the PCI passthrough,
extends the RNG and add an extra test for the QEmu parsing to
args and serialization back to XML.
  I also noticed that we parse (and save) and extra PCI domain
argument, but it's not actually used when calling qemu, so I
assume it's a missing feature for QEmu and just decided to patch
the code to not save the extra value when not defined (i.e. 0).
  Whether it should just be removed at this point is IMHO a separate
decision, which is why I took the way with minimal changes. Note
that the domain attribute is not documented nor part or the RNG
either at this point.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
Index: docs/formatdomain.html
===================================================================
RCS file: /data/cvs/libxen/docs/formatdomain.html,v
retrieving revision 1.16
diff -u -r1.16 formatdomain.html
--- docs/formatdomain.html	6 Jan 2009 08:48:48 -0000	1.16
+++ docs/formatdomain.html	12 Jan 2009 10:23:02 -0000
@@ -140,7 +140,7 @@
                 <ul><li>
                     <a href="#elementsDisks">Hard drives, floppy disks, CDROMs</a>
                   </li><li>
-                    <a href="#elementsUSB">USB devices</a>
+                    <a href="#elementsUSB">USB and PCI devices</a>
                   </li><li>
                     <a href="#elementsNICS">Network interfaces</a>
                     <ul><li>
@@ -464,11 +464,12 @@
 	attribute provides the sub-type. <span class="since">Since 0.1.8</span>
       </dd></dl>
         <h4>
-          <a name="elementsUSB" id="elementsUSB">USB devices</a>
+          <a name="elementsUSB" id="elementsUSB">USB and PCI devices</a>
         </h4>
         <p>
-      USB devices attached to the host can be passed through to the guest using
-      the <code>hostdev</code> element. <span class="since">since after 0.4.4</span>
+      USB and PCI devices attached to the host can be passed through to the guest using
+      the <code>hostdev</code> element. <span class="since">since after
+      0.4.4 for USB and 0.6.0 for PCI (KVM only)</span>:
     </p>
         <pre>
           ...
@@ -479,20 +480,38 @@
 	    &lt;/source&gt;
 	  &lt;/hostdev&gt;
 	  ...</pre>
+        <p>or:</p>
+        <pre>
+          ...
+	  &lt;hostdev mode='subsystem' type='pci'&gt;
+	    &lt;source&gt;
+	      &lt;address&gt;bus='0x06' slot='0x02' function='0x0'&lt;/address&gt;
+	    &lt;/source&gt;
+	  &lt;/hostdev&gt;
+	  ...</pre>
         <dl><dt><code>hostdev</code></dt><dd>The <code>hostdev</code> element is the main container for describing
       host devices. For usb device passthrough <code>mode</code> is always
-      "subsystem" and <code>type</code> is "usb".
+      "subsystem" and <code>type</code> is "usb" for an USB device and "pci"
+      for a PCI device..
       </dd><dt><code>source</code></dt><dd>The source element describes the device as seen from the host.
       The USB device can either be addressed by vendor / product id using the
       <code>vendor</code> and <code>product</code> elements or by the device's
-      address on the hosts using the <code>address</code> element.</dd><dt><code>vendor</code>, <code>product</code></dt><dd>The <code>vendor</code> and <code>product</code> elements each have an
+      address on the hosts using the <code>address</code> element.
+      PCI devices on the other hand can only be described by their
+      <code>address</code></dd><dt><code>vendor</code>, <code>product</code></dt><dd>The <code>vendor</code> and <code>product</code> elements each have an
       <code>id</code> attribute that specifies the USB vendor and product id.
       The ids can be given in decimal, hexadecimal (starting with 0x) or
-      octal (starting with 0) form.</dd><dt><code>address</code></dt><dd>The <code>address</code> element has a <code>bus</code> and
-      <code>device</code> attribute to specify the USB bus and device number
-      the device appears at on the host. The values of these attributes can
-      be given in decimal, hexadecimal (starting with 0x) or octal (starting
-      with 0) form.</dd></dl>
+      octal (starting with 0) form.</dd><dt><code>address</code></dt><dd>The <code>address</code> element for USB devices has a
+      <code>bus</code> and <code>device</code> attribute to specify the
+      USB bus and device number the device appears at on the host.
+      The values of these attributes can be given in decimal, hexadecimal
+      (starting with 0x) or octal (starting with 0) form.
+      For PCI devices the element carries 3 attributes allowing to designate
+      the device as can be found with the <code>lspci</code> command, the
+      <code>bus</code> attribute allows the hexadecimal values 0 to ff, the
+      <code>slot</code> attribute allows the hexadecimal values 0 to 1f, and
+      the <code>function</code> attribute allows the hexadecimal values 0 to
+      7.</dd></dl>
         <h4>
           <a name="elementsNICS" id="elementsNICS">Network interfaces</a>
         </h4>
Index: docs/formatdomain.html.in
===================================================================
RCS file: /data/cvs/libxen/docs/formatdomain.html.in,v
retrieving revision 1.11
diff -u -r1.11 formatdomain.html.in
--- docs/formatdomain.html.in	26 Dec 2008 13:37:54 -0000	1.11
+++ docs/formatdomain.html.in	12 Jan 2009 10:23:02 -0000
@@ -375,11 +375,12 @@
       </dd>
     </dl>
 
-    <h4><a name="elementsUSB">USB devices</a></h4>
+    <h4><a name="elementsUSB">USB and PCI devices</a></h4>
 
     <p>
-      USB devices attached to the host can be passed through to the guest using
-      the <code>hostdev</code> element. <span class="since">since after 0.4.4</span>
+      USB and PCI devices attached to the host can be passed through to the guest using
+      the <code>hostdev</code> element. <span class="since">since after
+      0.4.4 for USB and 0.6.0 for PCI (KVM only)</span>:
     </p>
 
     <pre>
@@ -391,28 +392,46 @@
 	    &lt;/source&gt;
 	  &lt;/hostdev&gt;
 	  ...</pre>
+    <p>or:</p>
+    <pre>
+          ...
+	  &lt;hostdev mode='subsystem' type='pci'&gt;
+	    &lt;source&gt;
+	      &lt;address&gt;bus='0x06' slot='0x02' function='0x0'&lt;/address&gt;
+	    &lt;/source&gt;
+	  &lt;/hostdev&gt;
+	  ...</pre>
 
     <dl>
       <dt><code>hostdev</code></dt>
       <dd>The <code>hostdev</code> element is the main container for describing
       host devices. For usb device passthrough <code>mode</code> is always
-      "subsystem" and <code>type</code> is "usb".
+      "subsystem" and <code>type</code> is "usb" for an USB device and "pci"
+      for a PCI device..
       <dt><code>source</code></dt>
       <dd>The source element describes the device as seen from the host.
       The USB device can either be addressed by vendor / product id using the
       <code>vendor</code> and <code>product</code> elements or by the device's
-      address on the hosts using the <code>address</code> element.</dd>
+      address on the hosts using the <code>address</code> element.
+      PCI devices on the other hand can only be described by their
+      <code>address</code></dd>
       <dt><code>vendor</code>, <code>product</code></dt>
       <dd>The <code>vendor</code> and <code>product</code> elements each have an
       <code>id</code> attribute that specifies the USB vendor and product id.
       The ids can be given in decimal, hexadecimal (starting with 0x) or
       octal (starting with 0) form.</dd>
       <dt><code>address</code></dt>
-      <dd>The <code>address</code> element has a <code>bus</code> and
-      <code>device</code> attribute to specify the USB bus and device number
-      the device appears at on the host. The values of these attributes can
-      be given in decimal, hexadecimal (starting with 0x) or octal (starting
-      with 0) form.</dd>
+      <dd>The <code>address</code> element for USB devices has a
+      <code>bus</code> and <code>device</code> attribute to specify the
+      USB bus and device number the device appears at on the host.
+      The values of these attributes can be given in decimal, hexadecimal
+      (starting with 0x) or octal (starting with 0) form.
+      For PCI devices the element carries 3 attributes allowing to designate
+      the device as can be found with the <code>lspci</code> command, the
+      <code>bus</code> attribute allows the hexadecimal values 0 to ff, the
+      <code>slot</code> attribute allows the hexadecimal values 0 to 1f, and
+      the <code>function</code> attribute allows the hexadecimal values 0 to
+      7.</dd>
     </dl>
 
     <h4><a name="elementsNICS">Network interfaces</a></h4>
Index: docs/libvirt.rng
===================================================================
RCS file: /data/cvs/libxen/docs/libvirt.rng,v
retrieving revision 1.16
diff -u -r1.16 libvirt.rng
--- docs/libvirt.rng	11 Dec 2008 11:44:30 -0000	1.16
+++ docs/libvirt.rng	12 Jan 2009 10:23:02 -0000
@@ -890,6 +890,7 @@
             <choice>
               <ref name="usbproduct"/>
               <ref name="usbaddress"/>
+              <ref name="pciaddress"/>
             </choice>
           </element>
       </group>
@@ -920,6 +921,19 @@
     </element>
   </define>
 
+  <define name="pciaddress">
+    <element name="address">
+      <attribute name="bus">
+        <ref name="pciBus"/>
+      </attribute>
+      <attribute name="slot">
+        <ref name="pciSlot"/>
+      </attribute>
+      <attribute name="function">
+        <ref name="pciFunc"/>
+      </attribute>
+    </element>
+  </define>
   <!--
       Devices attached to a domain.
     -->
@@ -1069,4 +1083,19 @@
       <param name="pattern">(0x)?[0-9a-fA-F]{1,3}</param>
     </data>
   </define>
+  <define name='pciBus'>
+    <data type='string'>
+      <param name="pattern">(0x)?[0-9a-fA-F]{1,2}</param>
+    </data>
+  </define>
+  <define name='pciSlot'>
+    <data type='string'>
+      <param name="pattern">(0x)?[0-1]?[0-9a-fA-F]</param>
+    </data>
+  </define>
+  <define name='pciFunc'>
+    <data type='string'>
+      <param name="pattern">(0x)?[0-7]</param>
+    </data>
+  </define>
 </grammar>
Index: src/domain_conf.c
===================================================================
RCS file: /data/cvs/libxen/src/domain_conf.c,v
retrieving revision 1.52
diff -u -r1.52 domain_conf.c
--- src/domain_conf.c	8 Jan 2009 13:54:20 -0000	1.52
+++ src/domain_conf.c	12 Jan 2009 10:23:03 -0000
@@ -3137,11 +3137,20 @@
         }
     }
     if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
-        virBufferVSprintf(buf, "        <address domain='0x%.4x' bus='0x%.2x' slot='0x%.2x' function='0x%.1x'/>\n",
-                          def->source.subsys.u.pci.domain,
-                          def->source.subsys.u.pci.bus,
-                          def->source.subsys.u.pci.slot,
-                          def->source.subsys.u.pci.function);
+        if (def->source.subsys.u.pci.domain != 0) {
+            virBufferVSprintf(buf,
+    "        <address domain='0x%.4x' bus='0x%.2x' slot='0x%.2x' function='0x%.1x'/>\n",
+                              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,
+    "        <address bus='0x%.2x' slot='0x%.2x' function='0x%.1x'/>\n",
+                              def->source.subsys.u.pci.bus,
+                              def->source.subsys.u.pci.slot,
+                              def->source.subsys.u.pci.function);
+        }
     }
 
     virBufferAddLit(buf, "      </source>\n");
Index: tests/qemuxml2argvtest.c
===================================================================
RCS file: /data/cvs/libxen/tests/qemuxml2argvtest.c,v
retrieving revision 1.36
diff -u -r1.36 qemuxml2argvtest.c
--- tests/qemuxml2argvtest.c	18 Dec 2008 15:22:49 -0000	1.36
+++ tests/qemuxml2argvtest.c	12 Jan 2009 10:23:03 -0000
@@ -224,6 +224,8 @@
     DO_TEST("hostdev-usb-product", 0);
     DO_TEST("hostdev-usb-address", 0);
 
+    DO_TEST("hostdev-pci-address", 0);
+
     virCapabilitiesFree(driver.caps);
 
     return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
Index: tests/qemuxml2xmltest.c
===================================================================
RCS file: /data/cvs/libxen/tests/qemuxml2xmltest.c,v
retrieving revision 1.24
diff -u -r1.24 qemuxml2xmltest.c
--- tests/qemuxml2xmltest.c	8 Jan 2009 13:54:20 -0000	1.24
+++ tests/qemuxml2xmltest.c	12 Jan 2009 10:23:03 -0000
@@ -123,6 +123,7 @@
 
     DO_TEST("hostdev-usb-product");
     DO_TEST("hostdev-usb-address");
+    DO_TEST("hostdev-pci-address");
 
     virCapabilitiesFree(driver.caps);
 
<domain type='qemu'>
  <name>QEMUGuest2</name>
  <uuid>c7a5fdbd-edaf-9466-926a-d65c16db1809</uuid>
  <memory>219200</memory>
  <currentMemory>219200</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='i686' machine='pc'>hvm</type>
    <boot dev='hd'/>
  </os>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/qemu</emulator>
    <disk type='block' device='disk'>
      <source dev='/dev/HostVG/QEMUGuest2'/>
      <target dev='hda' bus='ide'/>
    </disk>
    <hostdev mode='subsystem' type='pci'>
      <source>
        <address bus='0x06' slot='0x12' function='0x5'/>
      </source>
    </hostdev>
  </devices>
</domain>
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor pty -pidfile /nowhere/QEMUGuest2.pid -no-acpi -boot c -hda /dev/HostVG/QEMUGuest2 -net none -serial none -parallel none -usb -pcidevice host=06:12.5
--
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]