Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions images/virtualization-dra/internal/usb/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ package usb

import (
"context"
"fmt"
"log/slog"
"path/filepath"
"strings"

"github.com/deckhouse/virtualization-dra/internal/featuregates"
)
Expand All @@ -44,6 +47,16 @@ func (s *AllocationStore) discoveryPluggedUSBDevices(ctx context.Context) (map[s
if _, ok := busIDSet[device.BusID]; ok {
usbipDeviceSet.Insert(toDevice(&device))
} else {
// usb device can be not exists in attach info because usbip detached it
// while it is still present in sysfs because vhci_hcd has not fully released it yet.
isUSBIPDevice, err := isUSBIPDevice(device.Path)
if err != nil {
return nil, nil, fmt.Errorf("failed to check if usb device is usbip device: %w", err)
}
if isUSBIPDevice {
continue
}

dev := toDevice(&device)
usbDeviceMap[dev.GetName(s.nodeName)] = dev
}
Expand All @@ -56,3 +69,14 @@ func (s *AllocationStore) discoveryPluggedUSBDevices(ctx context.Context) (map[s

return usbDeviceMap, usbipDeviceSet, nil
}

func isUSBIPDevice(devPath string) (bool, error) {
realPath, err := filepath.EvalSymlinks(devPath)
if err != nil {
return false, err
}

realPath = filepath.Clean(realPath)

return strings.Contains(realPath, "vhci_hcd"), nil
}
Loading