def match(self, pci_addr, pci_phys_addr): """Match a device to this PciAddress. Assume this is called given pci_addr and pci_phys_addr reported by libvirt, no attempt is made to verify if pci_addr is a VF of pci_phys_addr. :param pci_addr: PCI address of the device to match. :param pci_phys_addr: PCI address of the parent of the device to match (or None if the device is not a VF). """ # Try to match on the parent PCI address if the PciDeviceSpec is a # PF (sriov is available) and the device to match is a VF. This # makes possible to specify the PCI address of a PF in the # pci_passthrough_whitelist to match any of it's VFs PCI devices. if self.is_physical_function and pci_phys_addr: domain, bus, slot, func = ( utils.get_pci_address_fields(pci_phys_addr)) if (self.domain == domain and self.bus == bus and self.slot == slot and self.func == func): return True # Try to match on the device PCI address only. domain, bus, slot, func = (utils.get_pci_address_fields(pci_addr)) conditions = [ self.domain in (ANY, domain), self.bus in (ANY, bus), self.slot in (ANY, slot), self.func in (ANY, func) ] return all(conditions)
def match(self, pci_addr, pci_phys_addr): """Match a device to this PciAddress. Assume this is called given pci_addr and pci_phys_addr reported by libvirt, no attempt is made to verify if pci_addr is a VF of pci_phys_addr. :param pci_addr: PCI address of the device to match. :param pci_phys_addr: PCI address of the parent of the device to match (or None if the device is not a VF). """ # Try to match on the parent PCI address if the PciDeviceSpec is a # PF (sriov is available) and the device to match is a VF. This # makes possible to specify the PCI address of a PF in the # pci_passthrough_whitelist to match any of it's VFs PCI devices. if self.is_physical_function and pci_phys_addr: domain, bus, slot, func = ( utils.get_pci_address_fields(pci_phys_addr)) if (self.domain == domain and self.bus == bus and self.slot == slot and self.func == func): return True # Try to match on the device PCI address only. domain, bus, slot, func = ( utils.get_pci_address_fields(pci_addr)) conditions = [ self.domain in (ANY, domain), self.bus in (ANY, bus), self.slot in (ANY, slot), self.func in (ANY, func) ] return all(conditions)
def _init_address_fields(self, pci_addr): if self.is_physical_function: (self.domain, self.bus, self.slot, self.func) = utils.get_pci_address_fields(pci_addr) return dbs, sep, func = pci_addr.partition('.') if func: fstr = func.strip() if fstr != ANY: try: f = get_value(fstr) except SyntaxError: raise exception.PciDeviceWrongAddressFormat( address=pci_addr) if f > MAX_FUNC: raise exception.PciDeviceInvalidAddressField( address=pci_addr, field="function") self.func = "%1x" % f if dbs: dbs_fields = dbs.split(':') if len(dbs_fields) > 3: raise exception.PciDeviceWrongAddressFormat(address=pci_addr) # If we got a partial address like ":00.", we need to turn this # into a domain of ANY, a bus of ANY, and a slot of 00. This code # allows the address bus and/or domain to be left off dbs_all = [ANY for x in range(3 - len(dbs_fields))] dbs_all.extend(dbs_fields) dbs_checked = [s.strip() or ANY for s in dbs_all] self.domain, self.bus, self.slot = dbs_checked get_pci_dev_info(self, 'domain', MAX_DOMAIN, '%04x') get_pci_dev_info(self, 'bus', MAX_BUS, '%02x') get_pci_dev_info(self, 'slot', MAX_SLOT, '%02x') self._check_physical_function()
def match(self, pci_addr, pci_phys_addr): # Assume this is called given pci_add and pci_phys_addr from libvirt, # no attempt is made to verify pci_addr is a VF of pci_phys_addr if self.is_physical_function: if not pci_phys_addr: return False domain, bus, slot, func = ( utils.get_pci_address_fields(pci_phys_addr)) return (self.domain == domain and self.bus == bus and self.slot == slot and self.func == func) else: domain, bus, slot, func = (utils.get_pci_address_fields(pci_addr)) conditions = [ self.domain in (ANY, domain), self.bus in (ANY, bus), self.slot in (ANY, slot), self.func in (ANY, func) ] return all(conditions)
def match(self, pci_addr, pci_phys_addr): # Assume this is called given pci_add and pci_phys_addr from libvirt, # no attempt is made to verify pci_addr is a VF of pci_phys_addr if self.is_physical_function: if not pci_phys_addr: return False domain, bus, slot, func = ( utils.get_pci_address_fields(pci_phys_addr)) return (self.domain == domain and self.bus == bus and self.slot == slot and self.func == func) else: domain, bus, slot, func = ( utils.get_pci_address_fields(pci_addr)) conditions = [ self.domain in (ANY, domain), self.bus in (ANY, bus), self.slot in (ANY, slot), self.func in (ANY, func) ] return all(conditions)
def __init__(self, pci_addr): try: if isinstance(pci_addr, dict): self.domain = pci_addr['domain'] self.bus = pci_addr['bus'] self.slot = pci_addr['slot'] self.func = pci_addr['function'] else: self.domain, self.bus, self.slot, self.func = ( utils.get_pci_address_fields(pci_addr)) get_pci_dev_info(self, 'func', MAX_FUNC, '%1x') get_pci_dev_info(self, 'domain', MAX_DOMAIN, '%04x') get_pci_dev_info(self, 'bus', MAX_BUS, '%02x') get_pci_dev_info(self, 'slot', MAX_SLOT, '%02x') except (KeyError, ValueError): raise exception.PciDeviceWrongAddressFormat(address=pci_addr)
def __init__(self, pci_addr): try: if isinstance(pci_addr, dict): self.domain = pci_addr['domain'] self.bus = pci_addr['bus'] self.slot = pci_addr['slot'] self.func = pci_addr['function'] else: self.domain, self.bus, self.slot, self.func = ( utils.get_pci_address_fields(pci_addr)) self._set_pci_dev_info('func', MAX_FUNC, '%1x') self._set_pci_dev_info('domain', MAX_DOMAIN, '%04x') self._set_pci_dev_info('bus', MAX_BUS, '%02x') self._set_pci_dev_info('slot', MAX_SLOT, '%02x') except (KeyError, ValueError): raise exception.PciDeviceWrongAddressFormat(address=pci_addr)
def __init__(self, pci_addr: PCISpecAddressType) -> None: try: # TODO(stephenfin): Is this ever actually a string? if isinstance(pci_addr, dict): self.domain = pci_addr['domain'] self.bus = pci_addr['bus'] self.slot = pci_addr['slot'] self.func = pci_addr['function'] else: self.domain, self.bus, self.slot, self.func = ( utils.get_pci_address_fields(pci_addr)) self._set_pci_dev_info('func', MAX_FUNC, '%1x') self._set_pci_dev_info('domain', MAX_DOMAIN, '%04x') self._set_pci_dev_info('bus', MAX_BUS, '%02x') self._set_pci_dev_info('slot', MAX_SLOT, '%02x') except (KeyError, ValueError): raise exception.PciDeviceWrongAddressFormat(address=pci_addr)
def set_vif_host_backend_hostdev_pci_config(conf, pci_slot): """Populate a LibvirtConfigGuestHostdev instance with pci address data.""" conf.domain, conf.bus, conf.slot, conf.function = ( pci_utils.get_pci_address_fields(pci_slot))
def setUp(self): super(IsPhysicalFunctionTestCase, self).setUp() self.pci_args = utils.get_pci_address_fields('0000:00:00.1')
def set_vif_host_backend_ib_hostdev_config(conf, pci_slot): """Populate a LibvirtConfigGuestInterface instance with hostdev Interface. """ conf.domain, conf.bus, conf.slot, conf.function = ( pci_utils.get_pci_address_fields(pci_slot))