예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
 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()
예제 #4
0
파일: devspec.py 프로젝트: youbun/nova
 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)
예제 #5
0
파일: devspec.py 프로젝트: 4everming/nova
 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)
예제 #6
0
 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)
예제 #7
0
파일: devspec.py 프로젝트: arbrandes/nova
 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)
예제 #8
0
 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)
예제 #9
0
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))
예제 #10
0
 def setUp(self):
     super(IsPhysicalFunctionTestCase, self).setUp()
     self.pci_args = utils.get_pci_address_fields('0000:00:00.1')
예제 #11
0
파일: designer.py 프로젝트: 375670450/nova
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))
예제 #12
0
 def setUp(self):
     super(IsPhysicalFunctionTestCase, self).setUp()
     self.pci_args = utils.get_pci_address_fields('0000:00:00.1')
예제 #13
0
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))