[virt-tools-list] [virt-manager PATCH 2/3] Automatically add multifunction address parameter when needed
Martin Kletzander
mkletzan at redhat.com
Mon Sep 2 15:21:33 UTC 2013
Also check for use of duplicate addresses before passing such XML to
libvirt. And fix tests (of course).
Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
tests/cli-test-xml/compare/many-devices.xml | 4 ++--
virtinst/guest.py | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/tests/cli-test-xml/compare/many-devices.xml b/tests/cli-test-xml/compare/many-devices.xml
index 390c22e..b525472 100644
--- a/tests/cli-test-xml/compare/many-devices.xml
+++ b/tests/cli-test-xml/compare/many-devices.xml
@@ -46,7 +46,7 @@
</controller>
<controller type="usb" index="0" model="ich9-uhci1">
<master startport="0"/>
- <address type="pci" domain="0" bus="0" slot="4" function="0"/>
+ <address type="pci" domain="0" bus="0" slot="4" function="0" multifunction="on"/>
</controller>
<controller type="usb" index="0" model="ich9-uhci2">
<master startport="2"/>
@@ -134,7 +134,7 @@
</controller>
<controller type="usb" index="0" model="ich9-uhci1">
<master startport="0"/>
- <address type="pci" domain="0" bus="0" slot="4" function="0"/>
+ <address type="pci" domain="0" bus="0" slot="4" function="0" multifunction="on"/>
</controller>
<controller type="usb" index="0" model="ich9-uhci2">
<master startport="2"/>
diff --git a/virtinst/guest.py b/virtinst/guest.py
index db981fe..06b06cc 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -612,6 +612,7 @@ class Guest(XMLBuilder):
for dev in self.get_all_devices():
dev.set_defaults()
self._add_implied_controllers()
+ self._check_address_multi()
self._set_disk_defaults()
self._set_net_defaults()
self._set_input_defaults()
@@ -697,6 +698,28 @@ class Guest(XMLBuilder):
ctrl.address.set_addrstr("spapr-vio")
self.add_device(ctrl)
+ def _check_address_multi(self):
+ addresses = {}
+ for d in self._devices:
+ if d.address.type != d.address.ADDRESS_TYPE_PCI:
+ continue
+
+ addr = d.address
+ addrstr = "%d%d%d" % (d.address.domain,
+ d.address.bus,
+ d.address.slot)
+
+ if addrstr not in addresses:
+ addresses[addrstr] = {}
+ if addr.function in addresses[addrstr]:
+ raise ValueError(_("Duplicate address for devices %s and %s") %
+ (str(d), str(addresses[addrstr][addr.function])))
+ addresses[addrstr][addr.function] = d
+
+ for devs in addresses.values():
+ if len(devs) > 1 and 0 in devs:
+ devs[0].address.multifunction = True
+
def _can_virtio(self, key):
if not self.conn.is_qemu():
return False
--
1.8.3.2
More information about the virt-tools-list
mailing list