Skip to content

Commit 3b7852d

Browse files
committed
fix(usb): use hostDeviceExistsByName for USBIP port check gate
Skip free-port validation when the device already appears in KVVMI host device statuses (attach in progress), matching hostDeviceExistsByName helper added earlier. Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
1 parent 8917459 commit 3b7852d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

images/virtualization-artifact/pkg/controller/vm/internal/usb_device_attach_handler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (h *USBDeviceAttachHandler) Handle(ctx context.Context, s state.VirtualMach
9494
var kvvmiLoaded bool
9595
var kvvmi *virtv1.VirtualMachineInstance
9696
var hostDeviceReadyByName map[string]bool
97+
var hostDeviceExistsByName map[string]bool
9798

9899
var nextStatusRefs []v1alpha2.USBDeviceStatusRef
99100
for _, usbDeviceRef := range vm.Spec.USBDevices {
@@ -163,10 +164,15 @@ func (h *USBDeviceAttachHandler) Handle(ctx context.Context, s state.VirtualMach
163164
continue
164165
}
165166

167+
if hostDeviceExistsByName == nil {
168+
hostDeviceExistsByName = h.hostDeviceExistsByName(kvvmi)
169+
}
170+
166171
// 4) Check free USBIP ports only for NEW attachments from other nodes.
167172
// If device already has a status (existingStatus != nil), the request was already sent.
173+
// If the host device is already listed in KVVMI, attach is in progress — skip port check here.
168174
// Skip re-checking to avoid stuck devices when ports are exhausted mid-flight.
169-
if existingStatus == nil && usbDevice.Status.NodeName != "" && vm.Status.Node != "" && usbDevice.Status.NodeName != vm.Status.Node {
175+
if existingStatus == nil && !hostDeviceExistsByName[deviceName] && usbDevice.Status.NodeName != "" && vm.Status.Node != "" && usbDevice.Status.NodeName != vm.Status.Node {
170176
node := &corev1.Node{}
171177
if err := h.client.Get(ctx, client.ObjectKey{Name: vm.Status.Node}, node); err != nil {
172178
if !apierrors.IsNotFound(err) {

0 commit comments

Comments
 (0)