Exemplo n.º 1
0
 def remove(self):
     if self.status != z_fields.PciDeviceStatus.AVAILABLE:
         raise exception.PciDeviceInvalidStatus(
             compute_node_uuid=self.compute_node_uuid,
             address=self.address,
             status=self.status,
             hopestatus=[z_fields.PciDeviceStatus.AVAILABLE])
     self.status = z_fields.PciDeviceStatus.REMOVED
     self.container_uuid = None
     self.request_id = None
Exemplo n.º 2
0
    def allocate(self, container):
        ok_statuses = (z_fields.PciDeviceStatus.AVAILABLE,
                       z_fields.PciDeviceStatus.CLAIMED)
        parent_ok_statuses = (z_fields.PciDeviceStatus.AVAILABLE,
                              z_fields.PciDeviceStatus.UNCLAIMABLE,
                              z_fields.PciDeviceStatus.UNAVAILABLE)
        dependants_ok_statuses = (z_fields.PciDeviceStatus.AVAILABLE,
                                  z_fields.PciDeviceStatus.UNCLAIMABLE)
        if self.status not in ok_statuses:
            raise exception.PciDeviceInvalidStatus(
                compute_node_uuid=self.compute_node_uuid,
                address=self.address,
                status=self.status,
                hopestatus=ok_statuses)
        if (self.status == z_fields.PciDeviceStatus.CLAIMED
                and self.container_uuid != container.uuid):
            raise exception.PciDeviceInvalidOwner(
                compute_node_uuid=self.compute_node_uuid,
                address=self.address,
                owner=self.container_uuid,
                hopeowner=container.uuid)
        if self.dev_type == z_fields.PciDeviceType.SRIOV_PF:
            vfs_list = self.child_devices
            if not all(
                [vf.status in dependants_ok_statuses for vf in vfs_list]):
                raise exception.PciDeviceVFInvalidStatus(
                    compute_node_uuid=self.compute_node_uuid,
                    address=self.address)
            self._bulk_update_status(vfs_list,
                                     z_fields.PciDeviceStatus.UNAVAILABLE)

        elif (self.dev_type == z_fields.PciDeviceType.SRIOV_VF):
            parent = self.parent_device
            if parent:
                if parent.status not in parent_ok_statuses:
                    raise exception.PciDevicePFInvalidStatus(
                        compute_node_uuid=self.compute_node_uuid,
                        address=self.parent_addr,
                        status=self.status,
                        vf_address=self.address,
                        hopestatus=parent_ok_statuses)
                # Set PF status
                parent.status = z_fields.PciDeviceStatus.UNAVAILABLE
            else:
                LOG.debug(
                    'Physical function addr: %(pf_addr)s parent of '
                    'VF addr: %(vf_addr)s was not found', {
                        'pf_addr': self.parent_addr,
                        'vf_addr': self.address
                    })

        self.status = z_fields.PciDeviceStatus.ALLOCATED
        self.container_uuid = container.uuid

        container.pci_devices.append(copy.copy(self))
Exemplo n.º 3
0
    def claim(self, container_uuid):
        if self.status != z_fields.PciDeviceStatus.AVAILABLE:
            raise exception.PciDeviceInvalidStatus(
                compute_node_uuid=self.compute_node_uuid,
                address=self.address,
                status=self.status,
                hopestatus=[z_fields.PciDeviceStatus.AVAILABLE])

        if self.dev_type == z_fields.PciDeviceType.SRIOV_PF:
            # Update PF status to CLAIMED if all of it dependants are free
            # and set their status to UNCLAIMABLE
            vfs_list = self.child_devices
            if not all([vf.is_available() for vf in vfs_list]):
                raise exception.PciDeviceVFInvalidStatus(
                    compute_node_uuid=self.compute_node_uuid,
                    address=self.address)
            self._bulk_update_status(vfs_list,
                                     z_fields.PciDeviceStatus.UNCLAIMABLE)

        elif self.dev_type == z_fields.PciDeviceType.SRIOV_VF:
            # Update VF status to CLAIMED if it's parent has not been
            # previously allocated or claimed
            # When claiming/allocating a VF, it's parent PF becomes
            # unclaimable/unavailable. Therefore, it is expected to find the
            # parent PF in an unclaimable/unavailable state for any following
            # claims to a sibling VF

            parent_ok_statuses = (z_fields.PciDeviceStatus.AVAILABLE,
                                  z_fields.PciDeviceStatus.UNCLAIMABLE,
                                  z_fields.PciDeviceStatus.UNAVAILABLE)
            parent = self.parent_device
            if parent:
                if parent.status not in parent_ok_statuses:
                    raise exception.PciDevicePFInvalidStatus(
                        compute_node_uuid=self.compute_node_uuid,
                        address=self.parent_addr,
                        status=self.status,
                        vf_address=self.address,
                        hopestatus=parent_ok_statuses)
                # Set PF status
                if parent.status == z_fields.PciDeviceStatus.AVAILABLE:
                    parent.status = z_fields.PciDeviceStatus.UNCLAIMABLE
            else:
                LOG.debug(
                    'Physical function addr: %(pf_addr)s parent of '
                    'VF addr: %(vf_addr)s was not found', {
                        'pf_addr': self.parent_addr,
                        'vf_addr': self.address
                    })

        self.status = z_fields.PciDeviceStatus.CLAIMED
        self.container_uuid = container_uuid
Exemplo n.º 4
0
 def free(self, container=None):
     ok_statuses = (z_fields.PciDeviceStatus.ALLOCATED,
                    z_fields.PciDeviceStatus.CLAIMED)
     free_devs = []
     if self.status not in ok_statuses:
         raise exception.PciDeviceInvalidStatus(
             compute_node_uuid=self.compute_node_uuid,
             address=self.address,
             status=self.status,
             hopestatus=ok_statuses)
     if container and self.container_uuid != container['uuid']:
         raise exception.PciDeviceInvalidOwner(
             compute_node_uuid=self.compute_node_uuid,
             address=self.address,
             owner=self.container_uuid,
             hopeowner=container['uuid'])
     if self.dev_type == z_fields.PciDeviceType.SRIOV_PF:
         # Set all PF dependants status to AVAILABLE
         vfs_list = self.child_devices
         self._bulk_update_status(vfs_list,
                                  z_fields.PciDeviceStatus.AVAILABLE)
         free_devs.extend(vfs_list)
     if self.dev_type == z_fields.PciDeviceType.SRIOV_VF:
         # Set PF status to AVAILABLE if all of it's VFs are free
         parent = self.parent_device
         if not parent:
             LOG.debug(
                 'Physical function addr: %(pf_addr)s parent of '
                 'VF addr: %(vf_addr)s was not found', {
                     'pf_addr': self.parent_addr,
                     'vf_addr': self.address
                 })
         else:
             vfs_list = parent.child_devices
             if all(
                 [vf.is_available() for vf in vfs_list
                  if vf.id != self.id]):
                 parent.status = z_fields.PciDeviceStatus.AVAILABLE
                 free_devs.append(parent)
     old_status = self.status
     self.status = z_fields.PciDeviceStatus.AVAILABLE
     free_devs.append(self)
     self.container_uuid = None
     self.request_id = None
     if old_status == z_fields.PciDeviceStatus.ALLOCATED and container:
         existed = next(
             (dev for dev in container.pci_devices if dev.id == self.id))
         container.pci_devices.objects.remove(existed)
     return free_devs