@@ -235,13 +235,27 @@ def _handle_device_dependents(self, pci_dev):
235
235
return
236
236
237
237
@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
+ ]
241
256
242
257
@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 ):
245
259
"""Filter out pools with the wrong NUMA affinity, if required.
246
260
247
261
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,
252
266
we will still attempt to provide it if possible.
253
267
254
268
: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.
255
271
:param numa_cells: A list of InstanceNUMACell objects whose ``id``
256
272
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.
259
273
:returns: A list of pools that can, together, provide at least
260
274
``requested_count`` PCI devices with the level of NUMA affinity
261
275
required by ``numa_policy``, else all pools that can satisfy this
262
276
policy even if it's not enough.
263
277
"""
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
267
287
numa_cell_ids = [cell .id for cell in numa_cells ]
268
288
269
289
# 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,
305
325
pools , key = lambda pool : pool .get ('numa_node' ) not in numa_cell_ids )
306
326
307
327
@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
+ """
312
340
if all (
313
341
spec .get ('dev_type' ) != fields .PciDeviceType .SRIOV_PF
314
342
for spec in request .spec
@@ -331,7 +359,7 @@ def _filter_pools(cls, pools, request, numa_cells):
331
359
332
360
:param pools: A list of PCI device pool dicts
333
361
: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.
335
363
:param numa_cells: A list of InstanceNUMACell objects whose ``id``
336
364
corresponds to the ``id`` of host NUMACell objects.
337
365
: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):
343
371
344
372
# Firstly, let's exclude all devices that don't match our spec (e.g.
345
373
# 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 )
347
375
348
376
# Next, let's exclude all devices that aren't on the correct NUMA node
349
377
# *assuming* we have devices and care about that, as determined by
350
378
# 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 )
358
380
359
381
# Finally, if we're not requesting PFs then we should not use these.
360
382
# Exclude them.
361
- pools = cls ._filter_non_requested_pfs (pools , request )
383
+ pools = cls ._filter_pools_for_unrequested_pfs (pools , request )
362
384
363
385
# Do we still have enough devices left?
364
386
if sum ([pool ['count' ] for pool in pools ]) < request .count :
0 commit comments