Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: Currently, we have logic here to look for the disk names with but this fails when we have devices which are starting with e.g: on ppc64le architecture, NPIV based fc disks are discovered as follows: and here is the udev information for one of the disk: Because of the existing logic k8s fails to detect the disk because it does not start with instead starts with , so pod creation fails with the following error: What you expected to happen: FC disk should get attached properly to the pod How to reproduce it (as minimally and precisely as possible): sample pod yaml on a machine with path names starts with Anything else we need to know?: Environment:
/sig storage
/triage accepted

Discussion:
"io/ioutil" "os" "path/filepath" <ins> "regexp" </ins> "strconv" "strings"

// given a wwn and lun, find the device and associated devicemapper parent func findDisk(wwn, lun string, io ioHandler, deviceUtil volumeutil.DeviceUtil) (string, string) { <del> fcPath := "-fc-0x" + wwn + "-lun-" + lun </del> <ins> fcPathExp := "^(pci-.*-fc|fc)-0x" + wwn + "-lun-" + lun r := regexp.MustCompile(fcPathExp) </ins> devPath := byPath if dirs, err := io.ReadDir(devPath); err == nil { for _, f := range dirs { name := f.Name() <del> if strings.Contains(name, fcPath) { </del> <ins> if r.MatchString(name) { </ins> if disk, err1 := io.EvalSymlinks(devPath + name); err1 == nil { dm := deviceUtil.FindMultipathDeviceForDevice(disk) klog.Infof("fc: find disk: %v, dm: %v", disk, dm)

func (handler *fakeIOHandler) ReadDir(dirname string) ([]os.FileInfo, error) { switch dirname { case "/dev/disk/by-path/": <del> f := &fakeFileInfo{ </del> <ins> f1 := &fakeFileInfo{ </ins> name: "pci-0000:41:00.0-fc-0x500a0981891b8dc5-lun-0", } <del> return []os.FileInfo{f}, nil </del> <ins> f2 := &fakeFileInfo{ name: "fc-0x5005076810213b32-lun-2", } f3 := &fakeFileInfo{ name: "abc-0000:41:00.0-fc-0x5005076810213404-lun-0", } return []os.FileInfo{f1, f2, f3}, nil </ins> case "/sys/block/": f := &fakeFileInfo{ name: "dm-1",

} func TestSearchDisk(t *testing.T) { <del> fakeMounter := fcDiskMounter{ fcDisk: &fcDisk{ </del> <ins> tests := []struct { name        string wwns        []string lun         string expectError bool }{ { name: "PCI disk", </ins> wwns: []string{"500a0981891b8dc5"}, lun:  "0", <del> io:   &fakeIOHandler{}, </del> }, <del> deviceUtil: util.NewDeviceHandler(util.NewIOHandler()), </del> <ins> { name: "Non PCI disk", wwns: []string{"5005076810213b32"}, lun:  "2", }, { name:        "Invalid Storage Controller", wwns:        []string{"5005076810213404"}, lun:         "0", expectError: true, }, { name:        "Non existing disk", wwns:        []string{"500507681fffffff"}, lun:         "0", expectError: true, }, </ins> } <del> devicePath, error := searchDisk(fakeMounter) // if no disk matches input wwn and lun, exit if devicePath == "" || error != nil { t.Errorf("no fc disk found") </del> <ins> for _, test := range tests { t.Run(test.name, func(t *testing.T) { fakeMounter := fcDiskMounter{ fcDisk: &fcDisk{ wwns: test.wwns, lun:  test.lun, io:   &fakeIOHandler{}, }, deviceUtil: util.NewDeviceHandler(util.NewIOHandler()), } devicePath, err := searchDisk(fakeMounter) if test.expectError && err == nil { t.Errorf("expected error but got none") } if !test.expectError && err != nil { t.Errorf("got unexpected error: %s", err) } // if no disk matches input wwn and lun, exit if devicePath == "" && !test.expectError { t.Errorf("no fc disk found") } }) </ins> } }