@@ -16,6 +16,8 @@ import (
16
16
"time"
17
17
)
18
18
19
+ const defaultPort = "3260"
20
+
19
21
var (
20
22
debug * log.Logger
21
23
execCommand = exec .Command
@@ -33,14 +35,15 @@ type iscsiSession struct {
33
35
}
34
36
35
37
type TargetInfo struct {
36
- Iqn , Portal string
38
+ Iqn string `json:"iqn"`
39
+ Portal string `json:"portal"`
40
+ Port string `json:"port"`
37
41
}
38
42
39
43
//Connector provides a struct to hold all of the needed parameters to make our iscsi connection
40
44
type Connector struct {
41
45
VolumeName string `json:"volume_name"`
42
46
Targets []TargetInfo `json:"targets"`
43
- Port string `json:"port"`
44
47
Lun int32 `json:"lun"`
45
48
AuthType string `json:"auth_type"`
46
49
DiscoverySecrets Secrets `json:"discovery_secrets"`
@@ -253,23 +256,26 @@ func Connect(c Connector) (string, error) {
253
256
254
257
for _ , target := range c .Targets {
255
258
debug .Printf ("process targetIqn: %s, portal: %s\n " , target .Iqn , target .Portal )
256
- baseArgs := []string {"-m" , "node" , "-T" , target .Iqn , "-target.Portal " , target .Portal }
259
+ baseArgs := []string {"-m" , "node" , "-T" , target .Iqn , "-p " , target .Portal }
257
260
// Rescan sessions to discover newly mapped LUNs. Do not specify the interface when rescanning
258
261
// to avoid establishing additional sessions to the same target.
259
262
if _ , err := iscsiCmd (append (baseArgs , []string {"-R" }... )... ); err != nil {
260
263
debug .Printf ("failed to rescan session, err: %v" , err )
261
264
}
262
265
263
266
// create our devicePath that we'll be looking for based on the transport being used
264
- if c .Port != "" {
265
- target .Portal = strings .Join ([]string {target .Portal , c .Port }, ":" )
267
+ port := defaultPort
268
+ if target .Port != "" {
269
+ port = target .Port
266
270
}
267
- devicePath := strings .Join ([]string {"/dev/disk/by-path/ip" , target .Portal , "iscsi" , target .Iqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
271
+ // portal with port
272
+ portal := strings .Join ([]string {target .Portal , port }, ":" )
273
+ devicePath := strings .Join ([]string {"/dev/disk/by-path/ip" , portal , "iscsi" , target .Iqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
268
274
if iscsiTransport != "tcp" {
269
- devicePath = strings .Join ([]string {"/dev/disk/by-path/pci" , "*" , "ip" , target . Portal , "iscsi" , target .Iqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
275
+ devicePath = strings .Join ([]string {"/dev/disk/by-path/pci" , "*" , "ip" , portal , "iscsi" , target .Iqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
270
276
}
271
277
272
- exists , _ := sessionExists (target . Portal , target .Iqn )
278
+ exists , _ := sessionExists (portal , target .Iqn )
273
279
if exists {
274
280
if exists , err := waitForPathToExist (& devicePath , 1 , 1 , iscsiTransport ); exists {
275
281
debug .Printf ("Appending device path: %s" , devicePath )
@@ -282,22 +288,22 @@ func Connect(c Connector) (string, error) {
282
288
283
289
if c .DoDiscovery {
284
290
// build discoverydb and discover iscsi target
285
- if err := Discovery (target . Portal , iFace , c .DiscoverySecrets , c .DoCHAPDiscovery ); err != nil {
291
+ if err := Discovery (portal , iFace , c .DiscoverySecrets , c .DoCHAPDiscovery ); err != nil {
286
292
debug .Printf ("Error in discovery of the target: %s\n " , err .Error ())
287
293
lastErr = err
288
294
continue
289
295
}
290
296
}
291
297
292
298
// Make sure we don't log the secrets
293
- err := CreateDBEntry (target .Iqn , target . Portal , iFace , c .DiscoverySecrets , c .SessionSecrets , c .DoCHAPDiscovery )
299
+ err := CreateDBEntry (target .Iqn , portal , iFace , c .DiscoverySecrets , c .SessionSecrets , c .DoCHAPDiscovery )
294
300
if err != nil {
295
301
debug .Printf ("Error creating db entry: %s\n " , err .Error ())
296
302
continue
297
303
}
298
304
299
305
// perform the login
300
- err = Login (target .Iqn , target . Portal )
306
+ err = Login (target .Iqn , portal )
301
307
if err != nil {
302
308
debug .Printf ("failed to login, err: %v" , err )
303
309
lastErr = err
0 commit comments