Merge pull request #129180 from RomanBednar/automated-cherry-pick-of-#128086-upstream-release-1.32

Automated cherry pick of #128086: prevent unnecessary resolving of iscsi/fc devices to dm
This commit is contained in:
Kubernetes Prow Robot 2025-01-08 14:06:31 -08:00 committed by GitHub
commit 88f4a70c32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 8 deletions

View File

@ -31,8 +31,13 @@ import (
"k8s.io/klog/v2" "k8s.io/klog/v2"
) )
// FindMultipathDeviceForDevice given a device name like /dev/sdx, find the devicemapper parent // FindMultipathDeviceForDevice given a device name like /dev/sdx, find the devicemapper parent. If called with a device
// already resolved to devicemapper, do nothing.
func (handler *deviceHandler) FindMultipathDeviceForDevice(device string) string { func (handler *deviceHandler) FindMultipathDeviceForDevice(device string) string {
if strings.HasPrefix(device, "/dev/dm-") {
return device
}
io := handler.getIo io := handler.getIo
disk, err := findDeviceForPath(device, io) disk, err := findDeviceForPath(device, io)
if err != nil { if err != nil {

View File

@ -204,14 +204,42 @@ func (fi *fakeFileInfo) Sys() interface{} {
} }
func TestFindMultipathDeviceForDevice(t *testing.T) { func TestFindMultipathDeviceForDevice(t *testing.T) {
mockDeviceUtil := NewDeviceHandler(&mockOsIOHandler{}) tests := []struct {
dev := mockDeviceUtil.FindMultipathDeviceForDevice("/dev/disk/by-path/127.0.0.1:3260-eui.02004567A425678D-lun-0") name string
if dev != "/dev/dm-1" { device string
t.Fatalf("mpio device not found dm-1 expected got [%s]", dev) expectedResult string
}{
{
name: "Device is already a dm device",
device: "/dev/dm-1",
expectedResult: "/dev/dm-1",
},
{
name: "Device has no multipath",
device: "/dev/sdc",
expectedResult: "",
},
{
name: "Device has multipath",
device: "/dev/disk/by-path/127.0.0.1:3260-eui.02004567A425678D-lun-0",
expectedResult: "/dev/dm-1",
},
{
name: "Invalid device path",
device: "/dev/nonexistent",
expectedResult: "",
},
} }
dev = mockDeviceUtil.FindMultipathDeviceForDevice("/dev/disk/by-path/empty")
if dev != "" { mockDeviceUtil := NewDeviceHandler(&mockOsIOHandler{})
t.Fatalf("mpio device not found '' expected got [%s]", dev)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := mockDeviceUtil.FindMultipathDeviceForDevice(tt.device)
if result != tt.expectedResult {
t.Errorf("FindMultipathDeviceForDevice(%s) = %s, want %s", tt.device, result, tt.expectedResult)
}
})
} }
} }