@@ -217,15 +217,18 @@ def _handle_device_dependents(self, pci_dev):
217
217
218
218
In case the device is a PF, all of it's dependent VFs should
219
219
be removed from pools count, if these are present.
220
- When the device is a VF, it's parent PF pool count should be
221
- decreased, unless it is no longer in a pool.
220
+ When the device is a VF, or a VDPA device, it's parent PF
221
+ pool count should be decreased, unless it is no longer in a pool.
222
222
"""
223
223
if pci_dev .dev_type == fields .PciDeviceType .SRIOV_PF :
224
224
vfs_list = pci_dev .child_devices
225
225
if vfs_list :
226
226
for vf in vfs_list :
227
227
self .remove_device (vf )
228
- elif pci_dev .dev_type == fields .PciDeviceType .SRIOV_VF :
228
+ elif pci_dev .dev_type in (
229
+ fields .PciDeviceType .SRIOV_VF ,
230
+ fields .PciDeviceType .VDPA ,
231
+ ):
229
232
try :
230
233
parent = pci_dev .parent_device
231
234
# Make sure not to decrease PF pool count if this parent has
@@ -387,6 +390,28 @@ def _filter_pools_for_unrequested_pfs(self, pools, request):
387
390
]
388
391
return pools
389
392
393
+ def _filter_pools_for_unrequested_vdpa_devices (self , pools , request ):
394
+ """Filter out pools with VDPA devices, unless these are required.
395
+
396
+ This is necessary as vdpa devices require special handling and
397
+ should not be allocated to generic pci device requests.
398
+
399
+ :param pools: A list of PCI device pool dicts
400
+ :param request: An InstancePCIRequest object describing the type,
401
+ quantity and required NUMA affinity of device(s) we want.
402
+ :returns: A list of pools that can be used to support the request if
403
+ this is possible.
404
+ """
405
+ if all (
406
+ spec .get ('dev_type' ) != fields .PciDeviceType .VDPA
407
+ for spec in request .spec
408
+ ):
409
+ pools = [
410
+ pool for pool in pools
411
+ if not pool .get ('dev_type' ) == fields .PciDeviceType .VDPA
412
+ ]
413
+ return pools
414
+
390
415
def _filter_pools (self , pools , request , numa_cells ):
391
416
"""Determine if an individual PCI request can be met.
392
417
@@ -421,7 +446,7 @@ def _filter_pools(self, pools, request, numa_cells):
421
446
)
422
447
423
448
if after_count < request .count :
424
- LOG .debug ('Not enough PCI devices left to satify request' )
449
+ LOG .debug ('Not enough PCI devices left to satisfy request' )
425
450
return None
426
451
427
452
# Next, let's exclude all devices that aren't on the correct NUMA node
@@ -438,10 +463,10 @@ def _filter_pools(self, pools, request, numa_cells):
438
463
)
439
464
440
465
if after_count < request .count :
441
- LOG .debug ('Not enough PCI devices left to satify request' )
466
+ LOG .debug ('Not enough PCI devices left to satisfy request' )
442
467
return None
443
468
444
- # Finally, if we're not requesting PFs then we should not use these.
469
+ # If we're not requesting PFs then we should not use these.
445
470
# Exclude them.
446
471
before_count = after_count
447
472
pools = self ._filter_pools_for_unrequested_pfs (pools , request )
@@ -455,7 +480,24 @@ def _filter_pools(self, pools, request, numa_cells):
455
480
)
456
481
457
482
if after_count < request .count :
458
- LOG .debug ('Not enough PCI devices left to satify request' )
483
+ LOG .debug ('Not enough PCI devices left to satisfy request' )
484
+ return None
485
+
486
+ # If we're not requesting VDPA devices then we should not use these
487
+ # either. Exclude them.
488
+ before_count = after_count
489
+ pools = self ._filter_pools_for_unrequested_vdpa_devices (pools , request )
490
+ after_count = sum ([pool ['count' ] for pool in pools ])
491
+
492
+ if after_count < before_count :
493
+ LOG .debug (
494
+ 'Dropped %d devices as they are VDPA devices which we have '
495
+ 'not requested' ,
496
+ before_count - after_count
497
+ )
498
+
499
+ if after_count < request .count :
500
+ LOG .debug ('Not enough PCI devices left to satisfy request' )
459
501
return None
460
502
461
503
return pools
0 commit comments