PCI extension cache PCIDevice objects
This commit is contained in:
parent
79407a8717
commit
8d60f533c3
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
''' Qubes PCI Extensions '''
|
''' Qubes PCI Extensions '''
|
||||||
|
|
||||||
|
import functools
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -192,7 +193,7 @@ class PCIDeviceExtension(qubes.ext.Extension):
|
|||||||
def on_device_get_pci(self, vm, event, ident):
|
def on_device_get_pci(self, vm, event, ident):
|
||||||
# pylint: disable=unused-argument,no-self-use
|
# pylint: disable=unused-argument,no-self-use
|
||||||
if not vm.app.vmm.offline_mode:
|
if not vm.app.vmm.offline_mode:
|
||||||
yield PCIDevice(vm, ident)
|
yield _cache_get(vm, ident)
|
||||||
|
|
||||||
@qubes.ext.handler('device-list-attached:pci')
|
@qubes.ext.handler('device-list-attached:pci')
|
||||||
def on_device_list_attached(self, vm, event, **kwargs):
|
def on_device_list_attached(self, vm, event, **kwargs):
|
||||||
@ -228,9 +229,7 @@ class PCIDeviceExtension(qubes.ext.Extension):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
device = next(
|
device = _cache_get(vm, device.ident)
|
||||||
self.on_device_get_pci(vm, event, device.ident)
|
|
||||||
)
|
|
||||||
self.bind_pci_to_pciback(vm.app, device)
|
self.bind_pci_to_pciback(vm.app, device)
|
||||||
vm.libvirt_domain.attachDevice(
|
vm.libvirt_domain.attachDevice(
|
||||||
vm.app.env.get_template('libvirt/devices/pci.xml').render(
|
vm.app.env.get_template('libvirt/devices/pci.xml').render(
|
||||||
@ -250,9 +249,7 @@ class PCIDeviceExtension(qubes.ext.Extension):
|
|||||||
# provision in libvirt for extracting device-side BDF; we need it for
|
# provision in libvirt for extracting device-side BDF; we need it for
|
||||||
# qubes.DetachPciDevice, which unbinds driver, not to oops the kernel
|
# qubes.DetachPciDevice, which unbinds driver, not to oops the kernel
|
||||||
|
|
||||||
device = next(
|
device = _cache_get(vm, device.ident)
|
||||||
self.on_device_get_pci(vm, event, device.ident)
|
|
||||||
)
|
|
||||||
p = subprocess.Popen(['xl', 'pci-list', str(vm.xid)],
|
p = subprocess.Popen(['xl', 'pci-list', str(vm.xid)],
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
result = p.communicate()[0].decode()
|
result = p.communicate()[0].decode()
|
||||||
@ -278,8 +275,7 @@ class PCIDeviceExtension(qubes.ext.Extension):
|
|||||||
def on_domain_pre_start(self, vm, _event, **_kwargs):
|
def on_domain_pre_start(self, vm, _event, **_kwargs):
|
||||||
# Bind pci devices to pciback driver
|
# Bind pci devices to pciback driver
|
||||||
for assignment in vm.devices['pci'].persistent():
|
for assignment in vm.devices['pci'].persistent():
|
||||||
device = next(
|
device = _cache_get(vm, assignment.ident)
|
||||||
self.on_device_get_pci(vm, _event, assignment.ident))
|
|
||||||
self.bind_pci_to_pciback(vm.app, device)
|
self.bind_pci_to_pciback(vm.app, device)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -309,3 +305,8 @@ class PCIDeviceExtension(qubes.ext.Extension):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@functools.lru_cache(maxsize=None)
|
||||||
|
def _cache_get(vm, ident):
|
||||||
|
''' Caching wrapper around `PCIDevice(vm, ident)`. '''
|
||||||
|
return PCIDevice(vm, ident)
|
||||||
|
Loading…
Reference in New Issue
Block a user