qemu: (and conf) support rombar for network devices

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).
This commit is contained in:
Laine Stump 2012-01-24 19:54:12 -05:00
parent c01ba1a48f
commit 3284ac046f
9 changed files with 114 additions and 35 deletions

View File

@ -1955,6 +1955,7 @@
&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>

View File

@ -1490,6 +1490,9 @@
<optional>
<ref name="deviceBoot"/>
</optional>
<optional>
<ref name="rom"/>
</optional>
<optional>
<ref name="bandwidth"/>
</optional>
@ -2348,15 +2351,7 @@
<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>
@ -2821,6 +2816,18 @@
</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">

View 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");

View 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();

View File

@ -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

View File

@ -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

View File

@ -17,13 +17,30 @@
<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>

View 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);

View 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");