@@ -16,7 +16,11 @@ import (
16
16
"time"
17
17
)
18
18
19
- const defaultPort = "3260"
19
+ const (
20
+ defaultPort = "3260"
21
+ maxMultipathAttempts = 10
22
+ multipathDelay = 10
23
+ )
20
24
21
25
var (
22
26
debug * log.Logger
@@ -158,7 +162,7 @@ func waitForPathToExistImpl(devicePath *string, maxRetries, intervalSeconds int,
158
162
err = nil
159
163
if deviceTransport == "tcp" {
160
164
_ , err = osStat (* devicePath )
161
- debug .Printf ("os stat device: exist %v device %v" , ! os .IsNotExist (err ), * devicePath )
165
+ debug .Printf ("[%d] os stat device: exist %v device %v" , i , ! os .IsNotExist (err ), * devicePath )
162
166
if err != nil && ! os .IsNotExist (err ) {
163
167
debug .Printf ("Error attempting to stat device: %s" , err .Error ())
164
168
return false , err
@@ -167,7 +171,7 @@ func waitForPathToExistImpl(devicePath *string, maxRetries, intervalSeconds int,
167
171
}
168
172
169
173
} else {
170
- debug .Printf ("filepathGlob: %s" , * devicePath )
174
+ debug .Printf ("[%d] filepathGlob: %s" , i , * devicePath )
171
175
fpath , _ := filepathGlob (* devicePath )
172
176
if fpath == nil {
173
177
err = os .ErrNotExist
@@ -187,6 +191,7 @@ func waitForPathToExistImpl(devicePath *string, maxRetries, intervalSeconds int,
187
191
}
188
192
time .Sleep (time .Second * time .Duration (intervalSeconds ))
189
193
}
194
+ debug .Printf ("device does NOT exist [%d*%ds] (%v)" , maxRetries , intervalSeconds , * devicePath )
190
195
return false , err
191
196
}
192
197
@@ -211,37 +216,42 @@ func getMultipathDisk(path string) (string, error) {
211
216
// check to see if any have an entry under /sys/block/dm-*/slaves matching
212
217
// the device the symlink was pointing at
213
218
attempts := 1
214
- dmPaths , err := filepath .Glob ("/sys/block/dm-*" )
215
- for attempts < 4 {
216
- debug .Printf ("[%d] dmPaths=%v" , attempts , dmPaths )
217
- if err != nil {
218
- debug .Printf ("Glob error: %s" , err )
219
- return "" , err
220
- }
221
- if len (dmPaths ) > 0 {
222
- break
223
- }
224
- time .Sleep (1 * time .Second )
225
- attempts ++
219
+ var dmPaths []string
220
+
221
+ for attempts < (maxMultipathAttempts + 1 ) {
222
+ var err error
226
223
dmPaths , err = filepath .Glob ("/sys/block/dm-*" )
227
- }
228
- for _ , dmPath := range dmPaths {
229
- sdevices , err := filepath .Glob (filepath .Join (dmPath , "slaves" , "*" ))
230
- debug .Printf ("dmPath=%v/slaves/*, sdevices=%v" , dmPath , sdevices )
224
+ debug .Printf ("[%d] refresh dmPaths [%d] %v" , attempts , len (dmPaths ), dmPaths )
231
225
if err != nil {
232
226
debug .Printf ("Glob error: %s" , err )
227
+ return "" , err
233
228
}
234
- for _ , spath := range sdevices {
235
- s := filepath .Base (spath )
236
- debug .Printf ("Basepath: %s" , s )
237
- if sdevice == s {
238
- // We've found a matching entry, return the path for the
239
- // dm-* device it was found under
240
- p := filepath .Join ("/dev" , filepath .Base (dmPath ))
241
- debug .Printf ("Found matching multipath device (%s) under dm-* device path (%s), (%v)" , sdevice , dmPath , p )
242
- return p , nil
229
+
230
+ for _ , dmPath := range dmPaths {
231
+ sdevices , err := filepath .Glob (filepath .Join (dmPath , "slaves" , "*" ))
232
+ // debug.Printf(".. dmPath=%v, sdevices=[%d]%v", dmPath, len(sdevices), sdevices)
233
+ if err != nil {
234
+ debug .Printf ("Glob error: %s" , err )
235
+ }
236
+ for _ , spath := range sdevices {
237
+ s := filepath .Base (spath )
238
+ // debug.Printf(".. Basepath: %s", s)
239
+ if sdevice == s {
240
+ // We've found a matching entry, return the path for the
241
+ // dm-* device it was found under
242
+ p := filepath .Join ("/dev" , filepath .Base (dmPath ))
243
+ debug .Printf ("Found matching multipath device (%s) under dm-* device path (%s) p (%v)" , sdevice , dmPath , p )
244
+ return p , nil
245
+ }
243
246
}
244
247
}
248
+
249
+ // Force a reload of all existing multipath maps
250
+ output , err := execCommand ("multipath" , "-r" ).CombinedOutput ()
251
+ debug .Printf ("## multipath -r: output=%v, err=%v" , output , err )
252
+
253
+ time .Sleep (multipathDelay * time .Second )
254
+ attempts ++
245
255
}
246
256
debug .Printf ("Couldn't find dm-* path for path: %s, found non dm-* path: %s" , path , devicePath )
247
257
return "" , fmt .Errorf ("couldn't find dm-* path for path: %s, found non dm-* path: %s" , path , devicePath )
@@ -350,7 +360,7 @@ func Connect(c *Connector) (string, error) {
350
360
}
351
361
352
362
if lastErr != nil {
353
- debug .Printf ("Last error occured during iscsi init: \n %v" , lastErr )
363
+ debug .Printf ("Last error occurred during iscsi init: \n %v" , lastErr )
354
364
}
355
365
356
366
for i , path := range devicePaths {
@@ -465,11 +475,14 @@ func PersistConnector(c *Connector, filePath string) error {
465
475
//file := path.Join("mnt", c.VolumeName+".json")
466
476
f , err := os .Create (filePath )
467
477
if err != nil {
478
+ debug .Printf ("ERROR: creating iscsi persistence file %s: %s\n " , filePath , err )
468
479
return fmt .Errorf ("error creating iscsi persistence file %s: %s" , filePath , err )
469
480
}
470
481
defer f .Close ()
471
482
encoder := json .NewEncoder (f )
483
+ debug .Printf ("ConnectorFromFile (write): file=%v, c=%+v\n " , filePath , c )
472
484
if err = encoder .Encode (c ); err != nil {
485
+ debug .Printf ("ERROR: error encoding connector: %v\n " , err )
473
486
return fmt .Errorf ("error encoding connector: %v" , err )
474
487
}
475
488
return nil
@@ -490,7 +503,7 @@ func GetConnectorFromFile(filePath string) (*Connector, error) {
490
503
return & Connector {}, err
491
504
}
492
505
493
- debug .Printf ("data: % +v\n " , data )
506
+ debug .Printf ("ConnectorFromFile (read): file=%s, % +v\n " , filePath , data )
494
507
495
508
return & data , nil
496
509
0 commit comments