@@ -162,7 +162,6 @@ func CountNonVirtioBlockDevices() (int64, error) {
162162 // 2. Check if the port has downstream devices
163163 // If the bridge has children, they appear as subdirectories
164164 // matching the PCI address format (e.g., 0000:01:00.0)
165- isNonBlockDevice := false
166165 files , err2 := os .ReadDir (devPath )
167166 if err2 != nil {
168167 klog .Errorf ("failed to read dir %s : %v" , devPath , err2 )
@@ -171,14 +170,13 @@ func CountNonVirtioBlockDevices() (int64, error) {
171170 // Ignore PCI bus directories such as pci001 pci002 and pci010
172171 // Devices must follow <domain:bus:device.function> format
173172 if pciAddressRegex .MatchString (file .Name ()) {
174- isNonBlockDevice = IsNonBlockDevice (devPath , file , isNonBlockDevice )
173+ isNonBlockDevice := IsNonBlockDevice (devPath , file )
174+ if isNonBlockDevice {
175+ pcieSlotsOccupiedByNonBlockDevice ++
176+ }
175177 break
176178 }
177179 }
178-
179- if isNonBlockDevice {
180- pcieSlotsOccupiedByNonBlockDevice ++
181- }
182180 } else {
183181 klog .Infof ("skipping class %s: path: %s" , class , devPath )
184182 }
@@ -187,20 +185,21 @@ func CountNonVirtioBlockDevices() (int64, error) {
187185 return int64 (pcieSlotsOccupiedByNonBlockDevice ), nil
188186}
189187
190- func IsNonBlockDevice (devPath string , file os.DirEntry , isNonBLockDevice bool ) bool {
188+ func IsNonBlockDevice (devPath string , file os.DirEntry ) bool {
189+ var isNonBlockDevice bool
191190 pciDevicePath := filepath .Join (devPath , file .Name ())
192- deviceBuf , err := os .ReadFile (filepath .Join (pciDevicePath , "device" ))
193- if err != nil {
194- klog .Errorf ("failed to read PCI device file %s : %v" , pciDevicePath , err )
195- }
196191 vendorBuf , err := os .ReadFile (filepath .Join (pciDevicePath , "vendor" ))
197192 if err != nil {
198193 klog .Errorf ("failed to read PCI device vendor %s : %v" , pciDevicePath , err )
199194 }
195+ deviceBuf , err := os .ReadFile (filepath .Join (pciDevicePath , "device" ))
196+ if err != nil {
197+ klog .Errorf ("failed to read PCI device file %s : %v" , pciDevicePath , err )
198+ }
200199 if strings .TrimSpace (string (vendorBuf )) == REDHAT_VENDOR && strings .TrimSpace (string (deviceBuf )) != VIRTIO_BLOCK_DEVICE {
201- isNonBLockDevice = true
200+ isNonBlockDevice = true
202201 }
203- return isNonBLockDevice
202+ return isNonBlockDevice
204203}
205204
206205// GetDevicePath returns the path of an attached block storage volume, specified by its id.
0 commit comments