@@ -16,7 +16,11 @@ import (
1616 "time"
1717)
1818
19- const defaultPort = "3260"
19+ const (
20+ defaultPort = "3260"
21+ maxMultipathAttempts = 10
22+ multipathDelay = 30
23+ )
2024
2125var (
2226 debug * log.Logger
@@ -211,37 +215,42 @@ func getMultipathDisk(path string) (string, error) {
211215 // check to see if any have an entry under /sys/block/dm-*/slaves matching
212216 // the device the symlink was pointing at
213217 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 ++
218+ var dmPaths []string
219+
220+ for attempts < (maxMultipathAttempts + 1 ) {
221+ var err error
226222 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 )
223+ debug .Printf ("[%d] refresh dmPaths [%d] %v" , attempts , len (dmPaths ), dmPaths )
231224 if err != nil {
232225 debug .Printf ("Glob error: %s" , err )
226+ return "" , err
233227 }
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
228+
229+ for _ , dmPath := range dmPaths {
230+ sdevices , err := filepath .Glob (filepath .Join (dmPath , "slaves" , "*" ))
231+ // debug.Printf(".. dmPath=%v, sdevices=[%d]%v", dmPath, len(sdevices), sdevices)
232+ if err != nil {
233+ debug .Printf ("Glob error: %s" , err )
234+ }
235+ for _ , spath := range sdevices {
236+ s := filepath .Base (spath )
237+ // debug.Printf(".. Basepath: %s", s)
238+ if sdevice == s {
239+ // We've found a matching entry, return the path for the
240+ // dm-* device it was found under
241+ p := filepath .Join ("/dev" , filepath .Base (dmPath ))
242+ debug .Printf ("Found matching multipath device (%s) under dm-* device path (%s) p (%v)" , sdevice , dmPath , p )
243+ return p , nil
244+ }
243245 }
244246 }
247+
248+ // Force a reload of all existing multipath maps
249+ output , err := execCommand ("multipath" , "-r" ).CombinedOutput ()
250+ debug .Printf ("## multipath -r: output=%v, err=%v" , output , err )
251+
252+ time .Sleep (multipathDelay * time .Second )
253+ attempts ++
245254 }
246255 debug .Printf ("Couldn't find dm-* path for path: %s, found non dm-* path: %s" , path , devicePath )
247256 return "" , fmt .Errorf ("couldn't find dm-* path for path: %s, found non dm-* path: %s" , path , devicePath )
@@ -350,7 +359,7 @@ func Connect(c *Connector) (string, error) {
350359 }
351360
352361 if lastErr != nil {
353- debug .Printf ("Last error occured during iscsi init: \n %v" , lastErr )
362+ debug .Printf ("Last error occurred during iscsi init: \n %v" , lastErr )
354363 }
355364
356365 for i , path := range devicePaths {
@@ -465,11 +474,14 @@ func PersistConnector(c *Connector, filePath string) error {
465474 //file := path.Join("mnt", c.VolumeName+".json")
466475 f , err := os .Create (filePath )
467476 if err != nil {
477+ debug .Printf ("ERROR: creating iscsi persistence file %s: %s\n " , filePath , err )
468478 return fmt .Errorf ("error creating iscsi persistence file %s: %s" , filePath , err )
469479 }
470480 defer f .Close ()
471481 encoder := json .NewEncoder (f )
482+ debug .Printf ("ConnectorFromFile (write): file=%v, c=%+v\n " , filePath , c )
472483 if err = encoder .Encode (c ); err != nil {
484+ debug .Printf ("ERROR: error encoding connector: %v\n " , err )
473485 return fmt .Errorf ("error encoding connector: %v" , err )
474486 }
475487 return nil
@@ -490,7 +502,7 @@ func GetConnectorFromFile(filePath string) (*Connector, error) {
490502 return & Connector {}, err
491503 }
492504
493- debug .Printf ("data: % +v\n " , data )
505+ debug .Printf ("ConnectorFromFile (read): file=%s, % +v\n " , filePath , data )
494506
495507 return & data , nil
496508
0 commit comments