pci: adjust PCIDeviceExtension device identifier syntax
':' is not allowed in device identifier, replace it with '_'. Warning: this breaks existing qubes.xml
This commit is contained in:
parent
fe37e0933e
commit
6bc44b43de
@ -22,7 +22,7 @@
|
||||
</features>
|
||||
|
||||
<devices class="pci">
|
||||
<device backend-domain="dom0" id="01:23.45"/>
|
||||
<device backend-domain="dom0" id="01_23.45"/>
|
||||
</devices>
|
||||
</domain>
|
||||
|
||||
|
@ -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<bus>[0-9a-f]+):(?P<device>[0-9a-f]+)\.(?P<function>[0-9a-f]+)$')
|
||||
r'^(?P<bus>[0-9a-f]+)_(?P<device>[0-9a-f]+)\.(?P<function>[0-9a-f]+)$')
|
||||
libvirt_regex = re.compile(
|
||||
r'^pci_0000_(?P<bus>[0-9a-f]+)_(?P<device>[0-9a-f]+)_'
|
||||
r'(?P<function>[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)
|
||||
|
@ -76,7 +76,7 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase):
|
||||
</features>
|
||||
|
||||
<devices class="pci">
|
||||
<device backend-domain="domain1" id="00:11.22"/>
|
||||
<device backend-domain="domain1" id="00_11.22"/>
|
||||
</devices>
|
||||
|
||||
<devices class="usb" />
|
||||
@ -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')
|
||||
|
||||
|
@ -211,7 +211,7 @@ the parser will complain about missing combine= attribute on the second <start>.
|
||||
dependant).
|
||||
</doc:description>
|
||||
<attribute name="backend-domain">
|
||||
<doc:description>
|
||||
<doc:description>
|
||||
Backend domain name.
|
||||
</doc:description>
|
||||
<data type="string">
|
||||
@ -221,7 +221,7 @@ the parser will complain about missing combine= attribute on the second <start>.
|
||||
<attribute name="id">
|
||||
<!-- TODO: pattern dependent on class! -->
|
||||
<data type="string">
|
||||
<param name="pattern">[0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f]{2}</param>
|
||||
<param name="pattern">[0-9a-f]{2}_[0-9a-f]{2}.[0-9a-f]{2}</param>
|
||||
</data>
|
||||
</attribute>
|
||||
<optional>
|
||||
|
Loading…
Reference in New Issue
Block a user