]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: (and conf) support rombar for network devices
authorLaine Stump <laine@laine.org>
Wed, 25 Jan 2012 00:54:12 +0000 (19:54 -0500)
committerLaine Stump <laine@laine.org>
Mon, 30 Jan 2012 17:25:32 +0000 (12:25 -0500)
When support for the rombar option was added, it was only added for
PCI passthrough devices, configured with <hostdev>. The same option is
available for any network device that is attached to the guest's PCI
bus. This patch allows setting rombar for any PCI network device type.

After adding cases to test this to qemuxml2argv-hostdev-pci-rombar.*,
I decided to rename those files (to qemuxml2argv-pci-rom.*) to more
accurately reflect the additional tests, and also noticed that up to
now we've only been performing a domainschematest for that case, so I
added the "pci-rom" test to both qemuxml2argv and qemuxml2xml (and in
the process found some bugs whose fixes I squashed into previous
commits of this series).

docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/qemu/qemu_command.c
tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-rombar.args [deleted file]
tests/qemuxml2argvdata/qemuxml2argv-pci-rom.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml [moved from tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-rombar.xml with 60% similarity]
tests/qemuxml2argvtest.c
tests/qemuxml2xmltest.c

index 464c4a33ca25ed5462aafe3fb133063d5f4aeb24..e90e99f569f606fc32fcb9fd74ba89b1b8acb515 100644 (file)
       &lt;mac address='00:16:3e:5d:c7:9e'/&gt;
       &lt;script path='vif-bridge'/&gt;
       &lt;boot order='1'/&gt;
+      &lt;rom bar='off'/&gt;
     &lt;/interface&gt;
   &lt;/devices&gt;
   ...</pre>
@@ -2483,6 +2484,32 @@ qemu-kvm -net nic,model=? /dev/null
       <span class="since">Since 0.8.8</span>
     </p>
 
+    <h5><a name="elementsNICSROM">Interface ROM BIOS configuration</a></h5>
+
+<pre>
+  ...
+  &lt;devices&gt;
+    &lt;interface type='network'&gt;
+      &lt;source network='default'/&gt;
+      &lt;target dev='vnet1'/&gt;
+      <b>&lt;rom bar='off'/&gt;</b>
+    &lt;/interface&gt;
+  &lt;/devices&gt;
+  ...</pre>
+
+    <p>
+      For hypervisors which support this, you can change how a PCI Network
+      device's ROM is presented to the guest. The <code>bar</code>
+      attribute can be set to "on" or "off", and determines whether
+      or not the device's ROM will be visible in the guest's memory
+      map. (In PCI documentation, the "rombar" setting controls the
+      presence of the Base Address Register for the ROM). If no rom
+      bar is specified, the qemu default will be used (older
+      versions of qemu used a default of "off", while newer qemus
+      have a default of "on"). <span class="since">Since
+      0.9.10 (QEMU and KVM only)</span>
+    </p>
+
     <h5><a name="elementQoS">Quality of service</a></h5>
 
 <pre>
index 2e53e146efec000972125002fc64b8a5f5a8d46c..7557641438ddc5d6df8ca7f07d51257b89424781 100644 (file)
       <optional>
         <ref name="deviceBoot"/>
       </optional>
+      <optional>
+        <ref name="rom"/>
+      </optional>
       <optional>
         <ref name="bandwidth"/>
       </optional>
         <ref name="address"/>
       </optional>
       <optional>
-        <element name="rom">
-          <attribute name="bar">
-            <choice>
-              <value>on</value>
-              <value>off</value>
-            </choice>
-          </attribute>
-          <empty/>
-        </element>
+        <ref name="rom"/>
       </optional>
     </element>
   </define>
     </element>
   </define>
 
+  <define name="rom">
+    <element name="rom">
+      <attribute name="bar">
+        <choice>
+          <value>on</value>
+          <value>off</value>
+        </choice>
+      </attribute>
+      <empty/>
+    </element>
+  </define>
+
   <define name="usbmaster">
     <element name="master">
       <attribute name="startport">
index c4bf3e4ebb4f1b16ddb18f3ff35e0b546373267f..b7f6913fe6de5cce775013083969b2efd3770ca9 100644 (file)
@@ -3876,7 +3876,8 @@ virDomainNetDefParseXML(virCapsPtr caps,
         def->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
     } else {
         if (virDomainDeviceInfoParseXML(node, bootMap, &def->info,
-                                        flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0)
+                                        flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT
+                                        | VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0)
             goto error;
     }
 
@@ -10506,7 +10507,8 @@ virDomainNetDefFormat(virBufferPtr buf,
     virBufferAdjustIndent(buf, -6);
 
     if (virDomainDeviceInfoFormat(buf, &def->info,
-                                  flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0)
+                                  flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT
+                                  | VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0)
         return -1;
 
     virBufferAddLit(buf, "    </interface>\n");
index 543c57ab22889f75d79b5fb9499bd22ba020674d..3f60691b58dd1ee63954fd292e29a3a86c0ce79e 100644 (file)
@@ -1514,6 +1514,37 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
     return 0;
 }
 
+static int
+qemuBuildRomStr(virBufferPtr buf,
+                virDomainDeviceInfoPtr info,
+                virBitmapPtr qemuCaps)
+{
+    if (info->rombar) {
+        if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+            qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                            "%s", _("rombar is supported only for PCI devices"));
+            return -1;
+        }
+        if (!qemuCapsGet(qemuCaps, QEMU_CAPS_PCI_ROMBAR)) {
+            qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                            "%s", _("rombar not supported in this QEMU binary"));
+            return -1;
+        }
+
+        switch (info->rombar) {
+        case VIR_DOMAIN_PCI_ROMBAR_OFF:
+            virBufferAddLit(buf, ",rombar=0");
+            break;
+        case VIR_DOMAIN_PCI_ROMBAR_ON:
+            virBufferAddLit(buf, ",rombar=1");
+            break;
+        default:
+            break;
+        }
+    }
+    return 0;
+}
+
 static int
 qemuBuildIoEventFdStr(virBufferPtr buf,
                       enum virDomainIoEventFd use,
@@ -2502,6 +2533,8 @@ qemuBuildNicDevStr(virDomainNetDefPtr net,
                       net->mac[4], net->mac[5]);
     if (qemuBuildDeviceAddressStr(&buf, &net->info, qemuCaps) < 0)
         goto error;
+    if (qemuBuildRomStr(&buf, &net->info, qemuCaps) < 0)
+       goto error;
     if (bootindex && qemuCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX))
         virBufferAsprintf(&buf, ",bootindex=%d", bootindex);
 
@@ -2853,25 +2886,8 @@ qemuBuildPCIHostdevDevStr(virDomainHostdevDefPtr dev, const char *configfd,
         virBufferAsprintf(&buf, ",bootindex=%d", dev->info.bootIndex);
     if (qemuBuildDeviceAddressStr(&buf, &dev->info, qemuCaps) < 0)
         goto error;
-
-    if (dev->info.rombar) {
-        if (!qemuCapsGet(qemuCaps, QEMU_CAPS_PCI_ROMBAR)) {
-            qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                            "%s", _("rombar not supported in this QEMU binary"));
-            goto error;
-        }
-
-        switch (dev->info.rombar) {
-        case VIR_DOMAIN_PCI_ROMBAR_OFF:
-            virBufferAddLit(&buf, ",rombar=0");
-            break;
-        case VIR_DOMAIN_PCI_ROMBAR_ON:
-            virBufferAddLit(&buf, ",rombar=1");
-            break;
-        default:
-            break;
-        }
-    }
+    if (qemuBuildRomStr(&buf, &dev->info, qemuCaps) < 0)
+       goto error;
 
     if (virBufferError(&buf)) {
         virReportOOMError();
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-rombar.args b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-rombar.args
deleted file mode 100644 (file)
index 1a8b14e..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
-pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -monitor \
-unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda \
-/dev/HostVG/QEMUGuest2 -usb -device pci-assign,host=06:12.5,id=hostdev0,\
-bus=pci.0,addr=0x3,rombar=0 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.args b/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.args
new file mode 100644 (file)
index 0000000..1a46aa3
--- /dev/null
@@ -0,0 +1,11 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
+pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -monitor \
+unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda \
+/dev/HostVG/QEMUGuest2 \
+-device virtio-net-pci,vlan=0,id=net0,mac=52:54:00:24:a5:9f,bus=pci.0,addr=0x3,rombar=1 \
+-net user,vlan=0,name=hostnet0 \
+-device virtio-net-pci,vlan=1,id=net1,mac=52:54:00:24:a5:9e,bus=pci.0,addr=0x4 \
+-net user,vlan=1,name=hostnet1 \
+-usb -device pci-assign,host=06:12.5,id=hostdev0,bus=pci.0,addr=0x5,rombar=0 \
+-device pci-assign,host=06:12.6,id=hostdev1,bus=pci.0,addr=0x6,rombar=1 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x7
similarity index 60%
rename from tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-rombar.xml
rename to tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml
index bf17cc49d0a96933bce0785292ae4c441e4f3763..3f6b8deaf2155322b9ffeff9f45a440d0ce2f4ab 100644 (file)
     <disk type='block' device='disk'>
       <source dev='/dev/HostVG/QEMUGuest2'/>
       <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' unit='0'/>
     </disk>
+    <controller type='ide' index='0'/>
+    <interface type='user'>
+      <mac address='52:54:00:24:a5:9f'/>
+      <model type='virtio'/>
+      <rom bar='on'/>
+    </interface>
+    <interface type='user'>
+      <mac address='52:54:00:24:a5:9e'/>
+      <model type='virtio'/>
+    </interface>
     <hostdev mode='subsystem' type='pci' managed='yes'>
       <source>
         <address domain='0x0000' bus='0x06' slot='0x12' function='0x5'/>
       </source>
       <rom bar='off'/>
     </hostdev>
+    <hostdev mode='subsystem' type='pci' managed='yes'>
+      <source>
+        <address domain='0x0000' bus='0x06' slot='0x12' function='0x6'/>
+      </source>
+      <rom bar='on'/>
+    </hostdev>
     <memballoon model='virtio'/>
   </devices>
 </domain>
index 63221aba08610d8a93b2674a6a2b720ace04a418..23234f2a521ff0728f32283ddd7ee2bbf85f177a 100644 (file)
@@ -663,6 +663,9 @@ mymain(void)
     DO_TEST("hostdev-pci-address", false, QEMU_CAPS_PCIDEVICE);
     DO_TEST("hostdev-pci-address-device", false,
             QEMU_CAPS_PCIDEVICE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
+    DO_TEST("pci-rom", false,
+            QEMU_CAPS_PCIDEVICE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
+            QEMU_CAPS_PCI_ROMBAR);
 
     DO_TEST_FULL("restore-v1", "stdio", 7, false, false,
             QEMU_CAPS_MIGRATE_KVM_STDIO);
index 09628d874f84c86d42ff02a6114734add8eff4f9..346e31093a90840dca565633a545a85221c141a0 100644 (file)
@@ -184,6 +184,7 @@ mymain(void)
 
     DO_TEST("hostdev-usb-address");
     DO_TEST("hostdev-pci-address");
+    DO_TEST("pci-rom");
 
     DO_TEST("encrypted-disk");
     DO_TEST("memtune");