Merge pull request #110719 from xakdwch/master

volume/fc: fix FibreChannel volume plugin matching wrong disks
This commit is contained in:
Kubernetes Prow Robot 2022-06-24 03:40:57 -07:00 committed by GitHub
commit 7a9268d83a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 5 deletions

View File

@ -62,7 +62,7 @@ func (handler *osIOHandler) WriteFile(filename string, data []byte, perm os.File
// given a wwn and lun, find the device and associated devicemapper parent
func findDisk(wwn, lun string, io ioHandler, deviceUtil volumeutil.DeviceUtil) (string, string) {
fcPathExp := "^(pci-.*-fc|fc)-0x" + wwn + "-lun-" + lun
fcPathExp := "^(pci-.*-fc|fc)-0x" + wwn + "-lun-" + lun + "$"
r := regexp.MustCompile(fcPathExp)
devPath := byPath
if dirs, err := io.ReadDir(devPath); err == nil {
@ -71,7 +71,7 @@ func findDisk(wwn, lun string, io ioHandler, deviceUtil volumeutil.DeviceUtil) (
if r.MatchString(name) {
if disk, err1 := io.EvalSymlinks(devPath + name); err1 == nil {
dm := deviceUtil.FindMultipathDeviceForDevice(disk)
klog.Infof("fc: find disk: %v, dm: %v", disk, dm)
klog.Infof("fc: find disk: %v, dm: %v, fc path: %v", disk, dm, name)
return disk, dm
}
}

View File

@ -66,7 +66,16 @@ func (handler *fakeIOHandler) ReadDir(dirname string) ([]os.FileInfo, error) {
f3 := &fakeFileInfo{
name: "abc-0000:41:00.0-fc-0x5005076810213404-lun-0",
}
return []os.FileInfo{f1, f2, f3}, nil
f4 := &fakeFileInfo{
name: "pci-0000:41:00.0-fc-0x500a0981891b8dc5-lun-12",
}
f5 := &fakeFileInfo{
name: "pci-0000:41:00.0-fc-0x500a0981891b8dc5-lun-1",
}
f6 := &fakeFileInfo{
name: "fc-0x5005076810213b32-lun-25",
}
return []os.FileInfo{f4, f5, f6, f1, f2, f3}, nil
case "/sys/block/":
f := &fakeFileInfo{
name: "dm-1",
@ -86,7 +95,21 @@ func (handler *fakeIOHandler) Lstat(name string) (os.FileInfo, error) {
}
func (handler *fakeIOHandler) EvalSymlinks(path string) (string, error) {
return "/dev/sda", nil
switch path {
case "/dev/disk/by-path/pci-0000:41:00.0-fc-0x500a0981891b8dc5-lun-0":
return "/dev/sda", nil
case "/dev/disk/by-path/pci-0000:41:00.0-fc-0x500a0981891b8dc5-lun-1":
return "/dev/sdb", nil
case "/dev/disk/by-path/fc-0x5005076810213b32-lun-2":
return "/dev/sdc", nil
case "/dev/disk/by-path/pci-0000:41:00.0-fc-0x500a0981891b8dc5-lun-12":
return "/dev/sdl", nil
case "/dev/disk/by-path/fc-0x5005076810213b32-lun-25":
return "/dev/sdx", nil
case "/dev/disk/by-id/scsi-3600508b400105e210000900000490000":
return "/dev/sdd", nil
}
return "", nil
}
func (handler *fakeIOHandler) WriteFile(filename string, data []byte, perm os.FileMode) error {
@ -98,17 +121,26 @@ func TestSearchDisk(t *testing.T) {
name string
wwns []string
lun string
disk string
expectError bool
}{
{
name: "PCI disk",
name: "PCI disk 0",
wwns: []string{"500a0981891b8dc5"},
lun: "0",
disk: "/dev/sda",
},
{
name: "PCI disk 1",
wwns: []string{"500a0981891b8dc5"},
lun: "1",
disk: "/dev/sdb",
},
{
name: "Non PCI disk",
wwns: []string{"5005076810213b32"},
lun: "2",
disk: "/dev/sdc",
},
{
name: "Invalid Storage Controller",
@ -145,6 +177,9 @@ func TestSearchDisk(t *testing.T) {
if devicePath == "" && !test.expectError {
t.Errorf("no fc disk found")
}
if devicePath != test.disk {
t.Errorf("matching wrong disk, expected: %s, actual: %s", test.disk, devicePath)
}
})
}
}