mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #110719 from xakdwch/master
volume/fc: fix FibreChannel volume plugin matching wrong disks
This commit is contained in:
commit
7a9268d83a
@ -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
|
// given a wwn and lun, find the device and associated devicemapper parent
|
||||||
func findDisk(wwn, lun string, io ioHandler, deviceUtil volumeutil.DeviceUtil) (string, string) {
|
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)
|
r := regexp.MustCompile(fcPathExp)
|
||||||
devPath := byPath
|
devPath := byPath
|
||||||
if dirs, err := io.ReadDir(devPath); err == nil {
|
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 r.MatchString(name) {
|
||||||
if disk, err1 := io.EvalSymlinks(devPath + name); err1 == nil {
|
if disk, err1 := io.EvalSymlinks(devPath + name); err1 == nil {
|
||||||
dm := deviceUtil.FindMultipathDeviceForDevice(disk)
|
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
|
return disk, dm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,16 @@ func (handler *fakeIOHandler) ReadDir(dirname string) ([]os.FileInfo, error) {
|
|||||||
f3 := &fakeFileInfo{
|
f3 := &fakeFileInfo{
|
||||||
name: "abc-0000:41:00.0-fc-0x5005076810213404-lun-0",
|
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/":
|
case "/sys/block/":
|
||||||
f := &fakeFileInfo{
|
f := &fakeFileInfo{
|
||||||
name: "dm-1",
|
name: "dm-1",
|
||||||
@ -86,7 +95,21 @@ func (handler *fakeIOHandler) Lstat(name string) (os.FileInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (handler *fakeIOHandler) EvalSymlinks(path string) (string, 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 {
|
func (handler *fakeIOHandler) WriteFile(filename string, data []byte, perm os.FileMode) error {
|
||||||
@ -98,17 +121,26 @@ func TestSearchDisk(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
wwns []string
|
wwns []string
|
||||||
lun string
|
lun string
|
||||||
|
disk string
|
||||||
expectError bool
|
expectError bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "PCI disk",
|
name: "PCI disk 0",
|
||||||
wwns: []string{"500a0981891b8dc5"},
|
wwns: []string{"500a0981891b8dc5"},
|
||||||
lun: "0",
|
lun: "0",
|
||||||
|
disk: "/dev/sda",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "PCI disk 1",
|
||||||
|
wwns: []string{"500a0981891b8dc5"},
|
||||||
|
lun: "1",
|
||||||
|
disk: "/dev/sdb",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Non PCI disk",
|
name: "Non PCI disk",
|
||||||
wwns: []string{"5005076810213b32"},
|
wwns: []string{"5005076810213b32"},
|
||||||
lun: "2",
|
lun: "2",
|
||||||
|
disk: "/dev/sdc",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid Storage Controller",
|
name: "Invalid Storage Controller",
|
||||||
@ -145,6 +177,9 @@ func TestSearchDisk(t *testing.T) {
|
|||||||
if devicePath == "" && !test.expectError {
|
if devicePath == "" && !test.expectError {
|
||||||
t.Errorf("no fc disk found")
|
t.Errorf("no fc disk found")
|
||||||
}
|
}
|
||||||
|
if devicePath != test.disk {
|
||||||
|
t.Errorf("matching wrong disk, expected: %s, actual: %s", test.disk, devicePath)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user