From 6bc44b43de714d4eace592a7cbf96eca930ec05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 22 May 2017 14:12:48 +0200 Subject: [PATCH] pci: adjust PCIDeviceExtension device identifier syntax ':' is not allowed in device identifier, replace it with '_'. Warning: this breaks existing qubes.xml --- doc/example.xml | 2 +- qubes/ext/pci.py | 14 ++++++++------ qubes/tests/vm/init.py | 4 ++-- relaxng/qubes.rng | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/doc/example.xml b/doc/example.xml index 6d63723f..130dc154 100644 --- a/doc/example.xml +++ b/doc/example.xml @@ -22,7 +22,7 @@ - + diff --git a/qubes/ext/pci.py b/qubes/ext/pci.py index b5b8602d..2c2edbc8 100644 --- a/qubes/ext/pci.py +++ b/qubes/ext/pci.py @@ -112,7 +112,7 @@ def attached_devices(app): for dev in range(int(devnum)): dbdf = xs.read('', devpath + '/dev-' + str(dev)) bdf = dbdf[len('0000:'):] - devices[bdf] = domain + devices[bdf.replace(':', '_')] = domain return devices @@ -128,7 +128,7 @@ def _device_desc(hostdev_xml): class PCIDevice(qubes.devices.DeviceInfo): # pylint: disable=too-few-public-methods regex = re.compile( - r'^(?P[0-9a-f]+):(?P[0-9a-f]+)\.(?P[0-9a-f]+)$') + r'^(?P[0-9a-f]+)_(?P[0-9a-f]+)\.(?P[0-9a-f]+)$') libvirt_regex = re.compile( r'^pci_0000_(?P[0-9a-f]+)_(?P[0-9a-f]+)_' r'(?P[0-9a-f]+)$') @@ -137,7 +137,7 @@ class PCIDevice(qubes.devices.DeviceInfo): if libvirt_name: dev_match = self.libvirt_regex.match(libvirt_name) assert dev_match - ident = '{bus}:{device}.{function}'.format(**dev_match.groupdict()) + ident = '{bus}_{device}.{function}'.format(**dev_match.groupdict()) super(PCIDevice, self).__init__(backend_domain, ident, None) @@ -210,7 +210,7 @@ class PCIDeviceExtension(qubes.ext.Extension): device = address.get('slot')[2:] function = address.get('function')[2:] - ident = '{bus}:{device}.{function}'.format( + ident = '{bus}_{device}.{function}'.format( bus=bus, device=device, function=function, @@ -221,7 +221,7 @@ class PCIDeviceExtension(qubes.ext.Extension): def on_device_pre_attached_pci(self, vm, event, device, options): # pylint: disable=unused-argument if not os.path.exists('/sys/bus/pci/devices/0000:{}'.format( - device.ident)): + device.ident.replace('_', ':'))): raise qubes.exc.QubesException( 'Invalid PCI device: {}'.format(device.ident)) @@ -253,7 +253,9 @@ class PCIDeviceExtension(qubes.ext.Extension): p = subprocess.Popen(['xl', 'pci-list', str(vm.xid)], stdout=subprocess.PIPE) result = p.communicate()[0].decode() - m = re.search(r'^(\d+.\d+)\s+0000:{}$'.format(device.ident), result, + m = re.search(r'^(\d+.\d+)\s+0000:{}$'.format(device.ident.replace( + '_', ':')), + result, flags=re.MULTILINE) if not m: vm.log.error('Device %s already detached', device.ident) diff --git a/qubes/tests/vm/init.py b/qubes/tests/vm/init.py index 178e5add..425b837d 100644 --- a/qubes/tests/vm/init.py +++ b/qubes/tests/vm/init.py @@ -76,7 +76,7 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase): - + @@ -109,7 +109,7 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase): self.assertCountEqual(vm.devices.keys(), ('pci',)) self.assertCountEqual(list(vm.devices['pci'].persistent()), - [qubes.ext.pci.PCIDevice(vm, '00:11.22')]) + [qubes.ext.pci.PCIDevice(vm, '00_11.22')]) self.assertXMLIsValid(vm.__xml__(), 'domain.rng') diff --git a/relaxng/qubes.rng b/relaxng/qubes.rng index 02c43f22..b8f070c9 100644 --- a/relaxng/qubes.rng +++ b/relaxng/qubes.rng @@ -211,7 +211,7 @@ the parser will complain about missing combine= attribute on the second . dependant). - + Backend domain name. @@ -221,7 +221,7 @@ the parser will complain about missing combine= attribute on the second . - [0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f]{2} + [0-9a-f]{2}_[0-9a-f]{2}.[0-9a-f]{2}