@@ -235,13 +235,27 @@ def _handle_device_dependents(self, pci_dev):
235235 return
236236
237237 @staticmethod
238- def _filter_pools_for_spec (pools , request_specs ):
239- return [pool for pool in pools
240- if utils .pci_device_prop_match (pool , request_specs )]
238+ def _filter_pools_for_spec (pools , request ):
239+ """Filter out pools that don't match the request's device spec.
240+
241+ Exclude pools that do not match the specified ``vendor_id``,
242+ ``product_id`` and/or ``device_type`` field, or any of the other
243+ arbitrary tags such as ``physical_network``, specified in the request.
244+
245+ :param pools: A list of PCI device pool dicts
246+ :param request: An InstancePCIRequest object describing the type,
247+ quantity and required NUMA affinity of device(s) we want.
248+ :returns: A list of pools that can be used to support the request if
249+ this is possible.
250+ """
251+ request_specs = request .spec
252+ return [
253+ pool for pool in pools
254+ if utils .pci_device_prop_match (pool , request_specs )
255+ ]
241256
242257 @classmethod
243- def _filter_pools_for_numa_cells (cls , pools , numa_cells , numa_policy ,
244- requested_count ):
258+ def _filter_pools_for_numa_cells (cls , pools , request , numa_cells ):
245259 """Filter out pools with the wrong NUMA affinity, if required.
246260
247261 Exclude pools that do not have *suitable* PCI NUMA affinity.
@@ -252,18 +266,24 @@ def _filter_pools_for_numa_cells(cls, pools, numa_cells, numa_policy,
252266 we will still attempt to provide it if possible.
253267
254268 :param pools: A list of PCI device pool dicts
269+ :param request: An InstancePCIRequest object describing the type,
270+ quantity and required NUMA affinity of device(s) we want.
255271 :param numa_cells: A list of InstanceNUMACell objects whose ``id``
256272 corresponds to the ``id`` of host NUMACells.
257- :param numa_policy: The PCI NUMA affinity policy to apply.
258- :param requested_count: The number of PCI devices requested.
259273 :returns: A list of pools that can, together, provide at least
260274 ``requested_count`` PCI devices with the level of NUMA affinity
261275 required by ``numa_policy``, else all pools that can satisfy this
262276 policy even if it's not enough.
263277 """
264- # NOTE(stephenfin): We may wish to change the default policy at a later
265- # date
266- requested_policy = numa_policy or fields .PCINUMAAffinityPolicy .LEGACY
278+ if not numa_cells :
279+ return pools
280+
281+ # we default to the 'legacy' policy for...of course...legacy reasons
282+ requested_policy = fields .PCINUMAAffinityPolicy .LEGACY
283+ if 'numa_policy' in request :
284+ requested_policy = request .numa_policy or requested_policy
285+
286+ requested_count = request .count
267287 numa_cell_ids = [cell .id for cell in numa_cells ]
268288
269289 # filter out pools which numa_node is not included in numa_cell_ids
@@ -305,10 +325,18 @@ def _filter_pools_for_numa_cells(cls, pools, numa_cells, numa_policy,
305325 pools , key = lambda pool : pool .get ('numa_node' ) not in numa_cell_ids )
306326
307327 @classmethod
308- def _filter_non_requested_pfs (cls , pools , request ):
309- # Remove SRIOV_PFs from pools, unless it has been explicitly requested
310- # This is especially needed in cases where PFs and VFs have the same
311- # product_id.
328+ def _filter_pools_for_unrequested_pfs (cls , pools , request ):
329+ """Filter out pools with PFs, unless these are required.
330+
331+ This is necessary in cases where PFs and VFs have the same product_id
332+ and generally useful elsewhere.
333+
334+ :param pools: A list of PCI device pool dicts
335+ :param request: An InstancePCIRequest object describing the type,
336+ quantity and required NUMA affinity of device(s) we want.
337+ :returns: A list of pools that can be used to support the request if
338+ this is possible.
339+ """
312340 if all (
313341 spec .get ('dev_type' ) != fields .PciDeviceType .SRIOV_PF
314342 for spec in request .spec
@@ -331,7 +359,7 @@ def _filter_pools(cls, pools, request, numa_cells):
331359
332360 :param pools: A list of PCI device pool dicts
333361 :param request: An InstancePCIRequest object describing the type,
334- quantity and required NUMA affinity of device(s) we want..
362+ quantity and required NUMA affinity of device(s) we want.
335363 :param numa_cells: A list of InstanceNUMACell objects whose ``id``
336364 corresponds to the ``id`` of host NUMACell objects.
337365 :returns: A list of pools that can be used to support the request if
@@ -343,22 +371,16 @@ def _filter_pools(cls, pools, request, numa_cells):
343371
344372 # Firstly, let's exclude all devices that don't match our spec (e.g.
345373 # they've got different PCI IDs or something)
346- pools = cls ._filter_pools_for_spec (pools , request . spec )
374+ pools = cls ._filter_pools_for_spec (pools , request )
347375
348376 # Next, let's exclude all devices that aren't on the correct NUMA node
349377 # *assuming* we have devices and care about that, as determined by
350378 # policy
351- if numa_cells :
352- numa_policy = None
353- if 'numa_policy' in request :
354- numa_policy = request .numa_policy
355-
356- pools = cls ._filter_pools_for_numa_cells (
357- pools , numa_cells , numa_policy , request .count )
379+ pools = cls ._filter_pools_for_numa_cells (pools , request , numa_cells )
358380
359381 # Finally, if we're not requesting PFs then we should not use these.
360382 # Exclude them.
361- pools = cls ._filter_non_requested_pfs (pools , request )
383+ pools = cls ._filter_pools_for_unrequested_pfs (pools , request )
362384
363385 # Do we still have enough devices left?
364386 if sum ([pool ['count' ] for pool in pools ]) < request .count :
0 commit comments