Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-46038: UPSTREAM: 129180: prevent unnecessary resolving of iscsi/fc devices to dm #2171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion pkg/volume/util/device_util_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ import (
"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 {
if strings.HasPrefix(device, "/dev/dm-") {
return device
}

io := handler.getIo
disk, err := findDeviceForPath(device, io)
if err != nil {
Expand Down
42 changes: 35 additions & 7 deletions pkg/volume/util/device_util_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,42 @@ func (fi *fakeFileInfo) Sys() interface{} {
}

func TestFindMultipathDeviceForDevice(t *testing.T) {
mockDeviceUtil := NewDeviceHandler(&mockOsIOHandler{})
dev := mockDeviceUtil.FindMultipathDeviceForDevice("/dev/disk/by-path/127.0.0.1:3260-eui.02004567A425678D-lun-0")
if dev != "/dev/dm-1" {
t.Fatalf("mpio device not found dm-1 expected got [%s]", dev)
tests := []struct {
name string
device string
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 != "" {
t.Fatalf("mpio device not found '' expected got [%s]", dev)

mockDeviceUtil := NewDeviceHandler(&mockOsIOHandler{})

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)
}
})
}
}

Expand Down