From 3284ac046fedc5b21c2bd153aa0f621a19a52e96 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Tue, 24 Jan 2012 19:54:12 -0500 Subject: [PATCH] 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 . 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 | 27 ++++++++++ docs/schemas/domaincommon.rng | 25 +++++---- src/conf/domain_conf.c | 6 ++- src/qemu/qemu_command.c | 54 ++++++++++++------- .../qemuxml2argv-hostdev-pci-rombar.args | 5 -- .../qemuxml2argv-pci-rom.args | 11 ++++ ...ci-rombar.xml => qemuxml2argv-pci-rom.xml} | 17 ++++++ tests/qemuxml2argvtest.c | 3 ++ tests/qemuxml2xmltest.c | 1 + 9 files changed, 114 insertions(+), 35 deletions(-) delete mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-rombar.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pci-rom.args rename tests/qemuxml2argvdata/{qemuxml2argv-hostdev-pci-rombar.xml => qemuxml2argv-pci-rom.xml} (60%) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 464c4a33ca..e90e99f569 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1955,6 +1955,7 @@ <mac address='00:16:3e:5d:c7:9e'/> <script path='vif-bridge'/> <boot order='1'/> + <rom bar='off'/> </interface> </devices> ... @@ -2483,6 +2484,32 @@ qemu-kvm -net nic,model=? /dev/null Since 0.8.8

+
Interface ROM BIOS configuration
+ +
+  ...
+  <devices>
+    <interface type='network'>
+      <source network='default'/>
+      <target dev='vnet1'/>
+      <rom bar='off'/>
+    </interface>
+  </devices>
+  ...
+ +

+ For hypervisors which support this, you can change how a PCI Network + device's ROM is presented to the guest. The bar + 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"). Since + 0.9.10 (QEMU and KVM only) +

+
Quality of service
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 2e53e146ef..7557641438 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1490,6 +1490,9 @@
       
         
       
+      
+        
+      
       
         
       
@@ -2348,15 +2351,7 @@
         
       
       
-        
-          
-            
-              on
-              off
-            
-          
-          
-        
+        
       
     
   
@@ -2821,6 +2816,18 @@
     
   
 
+  
+    
+      
+        
+          on
+          off
+        
+      
+      
+    
+  
+
   
     
       
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c4bf3e4ebb..b7f6913fe6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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, "    \n");
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 543c57ab22..3f60691b58 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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
index 1a8b14e83e..0000000000
--- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-rombar.args
+++ /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
index 0000000000..1a46aa3c0e
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.args
@@ -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
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-rombar.xml b/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml
similarity index 60%
rename from tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-rombar.xml
rename to tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml
index bf17cc49d0..3f6b8deaf2 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-rombar.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml
@@ -17,13 +17,30 @@
     
       
       
+      
+ + + + + + + + + +
+ + +
+ + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 63221aba08..23234f2a52 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -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); diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 09628d874f..346e31093a 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -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");