Skip to content

Commit 1c92be0

Browse files
authored
fix(virtualization-dra): skip usb gateway detach for untracked devices (#2298)
Fix USB device cleanup in virtualization-dra during Unprepare. The allocation store now checks whether a device is tracked in usbipAllocatedDevicesCount before calling USBGateway detach cleanup. Devices that are not tracked by USBGateway are skipped. For tracked devices, USBGateway detach is executed only when the current device has exactly one active tracked consumer. Devices with multiple consumers only have their consumer count decremented, and invalid zero-count tracked state is skipped with a warning --------- Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
1 parent a7ad756 commit 1c92be0

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • images/virtualization-dra/internal/usb

images/virtualization-dra/internal/usb/store.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,17 +447,21 @@ func (s *AllocationStore) Unprepare(_ context.Context, claimUID types.UID) error
447447
for _, device := range allocatedDevices {
448448
if usbGatewayEnabled {
449449
count, hasCount := s.usbipAllocatedDevicesCount[device]
450-
s.log.Info("Device attached by USBGateway", slog.String("device", device), slog.Int("count", count))
450+
s.log.Info("Device attached by USBGateway", slog.String("device", device), slog.Int("count", count), slog.Bool("tracked", hasCount))
451451
switch {
452-
case !hasCount || count <= 1:
452+
case !hasCount:
453+
s.log.Info("Device is not tracked by USBGateway, skipping detach", slog.String("device", device))
454+
case count == 1:
453455
s.log.Info("Device has no tracked consumers, attempting detach cleanup", slog.String("device", device), slog.Int("count", count))
454456
if err := s.usbGateway.Detach(device); err != nil {
455457
return fmt.Errorf("failed to detach device %s: %w", device, err)
456458
}
457459
delete(s.usbipAllocatedDevicesCount, device)
458-
default:
460+
case count > 1:
459461
s.log.Info("Decrementing device consumer count", slog.String("device", device), slog.Int("newCount", count-1))
460462
s.usbipAllocatedDevicesCount[device]--
463+
default:
464+
s.log.Warn("Device has invalid USBGateway consumer count, skipping detach", slog.String("device", device), slog.Int("count", count))
461465
}
462466
}
463467

0 commit comments

Comments
 (0)