fix(virtualization-dra): skip usb gateway detach for untracked devices#2298
Merged
Conversation
Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
yaroslavborbat
approved these changes
Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix USB device cleanup in
virtualization-draduringUnprepare.The allocation store now checks whether a device is tracked in
usbipAllocatedDevicesCountbefore 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,
Unprepareiterates over all allocated devices for a claim. Local USB devices are not present inusbipAllocatedDevicesCount, but reading a missing map key returns0, so the previouscount <= 1condition attempted to detach them through USBGateway.Also,
count == 0should not be treated as "last consumer". A valid last USBGateway consumer is represented bycount == 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?
Detachis not called for the local untracked device.Detachis not called whilecount > 1.Detachis called only whencount == 1.Checklist
Changelog entries