@@ -55,11 +55,11 @@ type Connector struct {
5555 // DevicePath is dm-x for a multipath device, and sdx for a normal device.
5656 DevicePath string `json:"device_path"`
5757
58- RetryCount int32 `json:"retry_count"`
59- CheckInterval int32 `json:"check_interval"`
60- DoDiscovery bool `json:"do_discovery"`
61- DoCHAPDiscovery bool `json:"do_chap_discovery"`
62- TargetIqn string `json:"target_iqn"`
58+ RetryCount int32 `json:"retry_count"`
59+ CheckInterval int32 `json:"check_interval"`
60+ DoDiscovery bool `json:"do_discovery"`
61+ DoCHAPDiscovery bool `json:"do_chap_discovery"`
62+ TargetIqn string `json:"target_iqn"`
6363 TargetPortals []string `json:"target_portals"`
6464}
6565
@@ -147,15 +147,16 @@ func waitForPathToExist(devicePath *string, maxRetries, intervalSeconds int, dev
147147}
148148
149149func waitForPathToExistImpl (devicePath * string , maxRetries , intervalSeconds int , deviceTransport string , osStat statFunc , filepathGlob globFunc ) (bool , error ) {
150- if devicePath == nil {
151- return false , fmt .Errorf ("unable to check unspecified devicePath" )
150+ if devicePath == nil || * devicePath == "" {
151+ return false , fmt .Errorf ("unable to check nil or unspecified devicePath" )
152152 }
153153
154154 var err error
155155 for i := 0 ; i < maxRetries ; i ++ {
156156 err = nil
157157 if deviceTransport == "tcp" {
158158 _ , err = osStat (* devicePath )
159+ debug .Printf ("os stat device: exist %v device %v" , ! os .IsNotExist (err ), * devicePath )
159160 if err != nil && ! os .IsNotExist (err ) {
160161 debug .Printf ("Error attempting to stat device: %s" , err .Error ())
161162 return false , err
@@ -164,13 +165,15 @@ func waitForPathToExistImpl(devicePath *string, maxRetries, intervalSeconds int,
164165 }
165166
166167 } else {
168+ debug .Printf ("filepathGlob: %s" , * devicePath )
167169 fpath , _ := filepathGlob (* devicePath )
168170 if fpath == nil {
169171 err = os .ErrNotExist
170172 } else {
171173 // There might be a case that fpath contains multiple device paths if
172174 // multiple PCI devices connect to same iscsi target. We handle this
173175 // case at subsequent logic. Pick up only first path here.
176+ debug .Printf ("set - devicePath %s" , fpath [0 ])
174177 * devicePath = fpath [0 ]
175178 }
176179 }
@@ -210,6 +213,7 @@ func getMultipathDisk(path string) (string, error) {
210213 }
211214 for _ , dmPath := range dmPaths {
212215 sdevices , err := filepath .Glob (filepath .Join (dmPath , "slaves" , "*" ))
216+ debug .Printf ("dmPath=%v, sdevices=%v" , dmPath , sdevices )
213217 if err != nil {
214218 debug .Printf ("Glob error: %s" , err )
215219 }
@@ -230,7 +234,7 @@ func getMultipathDisk(path string) (string, error) {
230234}
231235
232236// Connect attempts to connect a volume to this node using the provided Connector info
233- func Connect (c Connector ) (string , error ) {
237+ func Connect (c * Connector ) (string , error ) {
234238 var lastErr error
235239 if c .RetryCount == 0 {
236240 c .RetryCount = 10
@@ -279,7 +283,10 @@ func Connect(c Connector) (string, error) {
279283
280284 exists , _ := sessionExists (p , target .Iqn )
281285 if exists {
282- if exists , err := waitForPathToExist (& devicePath , 1 , 1 , iscsiTransport ); exists {
286+ debug .Printf ("Session already exists, checking if device path %q exists" , devicePath )
287+ exists , err := waitForPathToExist (& devicePath , int (c .RetryCount ), int (c .CheckInterval ), iscsiTransport )
288+ debug .Printf ("waitForPathToExist: exists=%v err=%v" , exists , err )
289+ if exists {
283290 debug .Printf ("Appending device path: %s" , devicePath )
284291 devicePaths = append (devicePaths , devicePath )
285292 continue
@@ -334,15 +341,19 @@ func Connect(c Connector) (string, error) {
334341 for i , path := range devicePaths {
335342 if path != "" {
336343 if mappedDevicePath , err := getMultipathDisk (path ); mappedDevicePath != "" {
344+ debug .Printf ("update devicePaths[%d] before=%v, after=%v" , i , devicePaths [i ], mappedDevicePath )
337345 devicePaths [i ] = mappedDevicePath
346+ c .Multipath = true
338347 if err != nil {
339348 return "" , err
340349 }
341350 }
342351 }
343352 }
344- debug .Printf ("After connect we're returning devicePaths: %s " , devicePaths )
353+ debug .Printf ("After connect we're returning devicePaths: %v " , devicePaths )
345354 if len (devicePaths ) > 0 {
355+ c .DevicePath = devicePaths [0 ]
356+ debug .Printf ("set -- devicePath %s" , c .DevicePath )
346357 return devicePaths [0 ], err
347358
348359 }
@@ -373,7 +384,7 @@ func DisconnectVolume(c Connector) error {
373384
374385 debug .Printf ("Disconnecting volume in path %s.\n " , c .DevicePath )
375386 if c .Multipath {
376- debug .Printf ("Removing multipath device. \n " )
387+ debug .Printf ("Removing multipath device %s \n " , c . DevicePath )
377388 devices , err := GetSysDevicesFromMultipathDevice (c .DevicePath )
378389 if err != nil {
379390 return err
@@ -453,16 +464,19 @@ func PersistConnector(c *Connector, filePath string) error {
453464// GetConnectorFromFile attempts to create a Connector using the specified json file (ie /var/lib/pfile/myConnector.json)
454465func GetConnectorFromFile (filePath string ) (* Connector , error ) {
455466 f , err := ioutil .ReadFile (filePath )
467+ debug .Printf ("GetConnectorFromFile (%s), err=%v\n " , filePath , err )
456468 if err != nil {
457469 return & Connector {}, err
458-
459470 }
471+
460472 data := Connector {}
461473 err = json .Unmarshal (f , & data )
462474 if err != nil {
463475 return & Connector {}, err
464476 }
465477
478+ debug .Printf ("data: %+v\n " , data )
479+
466480 return & data , nil
467481
468482}
0 commit comments