Skip to content

Commit 3ed1e8a

Browse files
riconnonrohitChaware
authored andcommitted
Handle multiple /dev/disk/by-path symlinks (#308)
Some systems have udev rules which create additional symlinks under /dev/disk/by-path which don't follow the expected format. In these cases we want to proceed if any symlink matches the expected pattern.
1 parent 2159fae commit 3ed1e8a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

pkg/util/iscsi/iscsi.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,17 @@ func NewFromMountPointPath(logger *zap.SugaredLogger, mountPath string) (Interfa
143143
if err != nil {
144144
return nil, err
145145
}
146-
diskByPath, err := diskByPathForMountPoint(mountPoint)
146+
diskByPaths, err := diskByPathsForMountPoint(mountPoint)
147147
if err != nil {
148148
return nil, err
149149
}
150-
return NewFromDevicePath(logger, diskByPath)
150+
for _, diskByPath := range(diskByPaths) {
151+
iface, err := NewFromDevicePath(logger, diskByPath)
152+
if err == nil {
153+
return iface, nil
154+
}
155+
}
156+
return nil, errors.New("iSCSI information not found for mount point")
151157
}
152158

153159
// getISCSIAdmPath gets the absolute path to the iscsiadm executable on the
@@ -306,22 +312,23 @@ func getMountPointForPath(ml mountLister, path string) (mount.MountPoint, error)
306312

307313
// TODO(apryde): Need to think about how best to test this/make it more
308314
// testable.
309-
func diskByPathForMountPoint(mountPoint mount.MountPoint) (string, error) {
310-
foundErr := errors.New("found")
311-
diskByPath := ""
315+
func diskByPathsForMountPoint(mountPoint mount.MountPoint) ([]string, error) {
316+
diskByPaths := []string{}
312317
err := filepath.Walk("/dev/disk/by-path/", func(path string, info os.FileInfo, err error) error {
313318
target, err := filepath.EvalSymlinks(path)
314319
if err != nil {
315320
return err
316321
}
317322
if target == mountPoint.Device {
318-
diskByPath = path
319-
return foundErr
323+
diskByPaths = append(diskByPaths, path)
320324
}
321325
return nil
322326
})
323-
if err != foundErr {
324-
return "", err
327+
if err != nil {
328+
return nil, err
329+
}
330+
if len(diskByPaths) == 0 {
331+
return nil, errors.New("disk by path link not found")
325332
}
326-
return diskByPath, nil
333+
return diskByPaths, nil
327334
}

0 commit comments

Comments
 (0)