@@ -80,25 +80,27 @@ func (s vendorVFIOSysfs) discoverVFs() ([]VirtualFunction, error) {
8080}
8181
8282func (s vendorVFIOSysfs ) listProfiles (vfs []VirtualFunction ) ([]GPUProfile , error ) {
83- metadata , err := s .profileMetadata (vfs )
84- if err != nil {
85- return nil , err
86- }
87-
88- availability := make (map [string ]int , len (metadata ))
83+ profilesByType := make (map [string ]profileMetadata )
84+ availability := make (map [string ]int )
8985 for _ , vf := range vfs {
90- if vf .Allocated {
91- continue
92- }
93- profiles , err := s .readCreatableProfiles (vf .PCIAddress )
86+ creatable , err := s .readCreatableProfiles (vf .PCIAddress )
9487 if err != nil {
9588 return nil , err
9689 }
97- for _ , profile := range profiles {
98- availability [profile .TypeName ]++
90+ for _ , profile := range creatable {
91+ profilesByType [profile .TypeName ] = profile
92+ if ! vf .Allocated {
93+ availability [profile .TypeName ]++
94+ }
9995 }
10096 }
10197
98+ metadata := make ([]profileMetadata , 0 , len (profilesByType ))
99+ for _ , profile := range profilesByType {
100+ metadata = append (metadata , profile )
101+ }
102+ sort .Slice (metadata , func (i , j int ) bool { return metadata [i ].Name < metadata [j ].Name })
103+
102104 profiles := make ([]GPUProfile , 0 , len (metadata ))
103105 for _ , profile := range metadata {
104106 profiles = append (profiles , GPUProfile {
@@ -263,6 +265,9 @@ func (s vendorVFIOSysfs) reconcile(ctx context.Context, protectedDevicePaths map
263265 return fmt .Errorf ("scan open VFIO handles: %w" , err )
264266 }
265267 }
268+ // destroyWithOpenPaths repeats this probe under the lock; the
269+ // pre-check only keeps live VMs from being logged below as failed
270+ // destroys.
266271 inUse , err := s .vfioDeviceInUse (vf .PCIAddress , openPaths )
267272 if err != nil {
268273 log .WarnContext (ctx , "failed to check vendor VFIO vGPU usage" , "vf" , vf .PCIAddress , "error" , err )
0 commit comments