@@ -178,6 +178,7 @@ func waitForPathToExistImpl(devicePath *string, maxRetries, intervalSeconds int,
178
178
179
179
func getMultipathDisk (path string ) (string , error ) {
180
180
// Follow link to destination directory
181
+ debug .Printf ("Checking for multipath device for path: %s" , path )
181
182
devicePath , err := os .Readlink (path )
182
183
if err != nil {
183
184
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) {
187
188
// If destination directory is already identified as a multipath device,
188
189
// just return its path
189
190
if strings .HasPrefix (sdevice , "dm-" ) {
191
+ debug .Printf ("Already found multipath device: %s" , sdevice )
190
192
return path , nil
191
193
}
192
194
// Fallback to iterating through all the entries under /sys/block/dm-* and
193
195
// check to see if any have an entry under /sys/block/dm-*/slaves matching
194
196
// 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
+ }
196
202
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
+ }
198
207
for _ , spath := range sdevices {
199
208
s := filepath .Base (spath )
209
+ debug .Printf ("Basepath: %s" , s )
200
210
if sdevice == s {
201
211
// We've found a matching entry, return the path for the
202
212
// dm-* device it was found under
@@ -206,6 +216,7 @@ func getMultipathDisk(path string) (string, error) {
206
216
}
207
217
}
208
218
}
219
+ debug .Printf ("Couldn't find dm-* path for path: %s, found non dm-* path: %s" , path , devicePath )
209
220
return "" , fmt .Errorf ("Couldn't find dm-* path for path: %s, found non dm-* path: %s" , path , devicePath )
210
221
}
211
222
@@ -283,21 +294,19 @@ func Connect(c Connector) (string, error) {
283
294
if len (devicePaths ) < 1 {
284
295
return "" , fmt .Errorf ("failed to find device path: %s" , devicePath )
285
296
}
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
295
306
}
296
307
}
297
308
}
298
-
299
309
}
300
-
301
310
debug .Printf ("After connect we're returning devicePaths: %s" , devicePaths )
302
311
if len (devicePaths ) > 0 {
303
312
return devicePaths [0 ], err
0 commit comments