Skip to content

fix(virtualization-dra): skip usb gateway detach for untracked devices#2298

Merged
danilrwx merged 2 commits into
mainfrom
fix/usb/detach-local-usb
Apr 29, 2026
Merged

fix(virtualization-dra): skip usb gateway detach for untracked devices#2298
danilrwx merged 2 commits into
mainfrom
fix/usb/detach-local-usb

Conversation

@danilrwx
Copy link
Copy Markdown
Contributor

@danilrwx danilrwx commented Apr 29, 2026

Description

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.

Why do we need it, and what problem does it solve?

When USBGateway is enabled, Unprepare iterates over all allocated devices for a claim. Local USB devices are not present in usbipAllocatedDevicesCount, but reading a missing map key returns 0, so the previous count <= 1 condition attempted to detach them through USBGateway.

Also, count == 0 should not be treated as "last consumer". A valid last USBGateway consumer is represented by count == 1. Zero means either the device is not tracked by USBGateway or the allocation state is inconsistent, so detach must be skipped to avoid detaching/unexporting a device incorrectly.

What is the expected result?

  1. Prepare a claim with a local USB device while USBGateway is enabled.
  2. Unprepare the claim.
  3. Verify that USBGateway Detach is not called for the local untracked device.
  4. Prepare several consumers for the same USBGateway device.
  5. Unprepare one consumer and verify that USBGateway Detach is not called while count > 1.
  6. Unprepare the last tracked consumer and verify that USBGateway Detach is called only when count == 1.

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: module
type: fix
summary: Skip USBGateway detach cleanup for untracked USB devices and detach tracked devices only on the last active consumer.
impact_level: low

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
@danilrwx danilrwx added this to the v1.9.0 milestone Apr 29, 2026
@danilrwx danilrwx marked this pull request as ready for review April 29, 2026 09:55
@danilrwx danilrwx merged commit 1c92be0 into main Apr 29, 2026
29 of 31 checks passed
@danilrwx danilrwx deleted the fix/usb/detach-local-usb branch April 29, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants