Skip to content

Commit f05aea3

Browse files
authored
Merge pull request #5 from mattsmithdatera/master
Fixing bug in Connect where multipath devices were not resolved
2 parents 7c37467 + 52ac436 commit f05aea3

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

iscsi/iscsi.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func waitForPathToExistImpl(devicePath *string, maxRetries, intervalSeconds int,
178178

179179
func getMultipathDisk(path string) (string, error) {
180180
// Follow link to destination directory
181+
debug.Printf("Checking for multipath device for path: %s", path)
181182
devicePath, err := os.Readlink(path)
182183
if err != nil {
183184
debug.Printf("Failed reading link for multipath disk: %s -- error: %s\n", path, err.Error())
@@ -187,16 +188,25 @@ func getMultipathDisk(path string) (string, error) {
187188
// If destination directory is already identified as a multipath device,
188189
// just return its path
189190
if strings.HasPrefix(sdevice, "dm-") {
191+
debug.Printf("Already found multipath device: %s", sdevice)
190192
return path, nil
191193
}
192194
// Fallback to iterating through all the entries under /sys/block/dm-* and
193195
// check to see if any have an entry under /sys/block/dm-*/slaves matching
194196
// the device the symlink was pointing at
195-
dmPaths, _ := filepath.Glob("/sys/block/dm-*")
197+
dmPaths, err := filepath.Glob("/sys/block/dm-*")
198+
if err != nil {
199+
debug.Printf("Glob error: %s", err)
200+
return "", err
201+
}
196202
for _, dmPath := range dmPaths {
197-
sdevices, _ := filepath.Glob(filepath.Join(dmPath, "slaves", "*"))
203+
sdevices, err := filepath.Glob(filepath.Join(dmPath, "slaves", "*"))
204+
if err != nil {
205+
debug.Printf("Glob error: %s", err)
206+
}
198207
for _, spath := range sdevices {
199208
s := filepath.Base(spath)
209+
debug.Printf("Basepath: %s", s)
200210
if sdevice == s {
201211
// We've found a matching entry, return the path for the
202212
// dm-* device it was found under
@@ -206,6 +216,7 @@ func getMultipathDisk(path string) (string, error) {
206216
}
207217
}
208218
}
219+
debug.Printf("Couldn't find dm-* path for path: %s, found non dm-* path: %s", path, devicePath)
209220
return "", fmt.Errorf("Couldn't find dm-* path for path: %s, found non dm-* path: %s", path, devicePath)
210221
}
211222

@@ -283,21 +294,19 @@ func Connect(c Connector) (string, error) {
283294
if len(devicePaths) < 1 {
284295
return "", fmt.Errorf("failed to find device path: %s", devicePath)
285296
}
286-
devicePath = devicePaths[0]
287-
for _, path := range devicePaths {
288-
if path != "" {
289-
if mappedDevicePath, err := getMultipathDisk(path); mappedDevicePath != "" {
290-
devicePath = mappedDevicePath
291-
if err != nil {
292-
return "", err
293-
}
294-
break
297+
298+
}
299+
300+
for i, path := range devicePaths {
301+
if path != "" {
302+
if mappedDevicePath, err := getMultipathDisk(path); mappedDevicePath != "" {
303+
devicePaths[i] = mappedDevicePath
304+
if err != nil {
305+
return "", err
295306
}
296307
}
297308
}
298-
299309
}
300-
301310
debug.Printf("After connect we're returning devicePaths: %s", devicePaths)
302311
if len(devicePaths) > 0 {
303312
return devicePaths[0], err

0 commit comments

Comments
 (0)