@@ -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
@@ -32,22 +34,26 @@ type iscsiSession struct {
32
34
Name string
33
35
}
34
36
37
+ type TargetInfo struct {
38
+ Iqn string `json:"iqn"`
39
+ Portal string `json:"portal"`
40
+ Port string `json:"port"`
41
+ }
42
+
35
43
//Connector provides a struct to hold all of the needed parameters to make our iscsi connection
36
44
type Connector struct {
37
- VolumeName string `json:"volume_name"`
38
- TargetIqn string `json:"target_iqn"`
39
- TargetPortals []string `json:"target_portals"`
40
- Port string `json:"port"`
41
- Lun int32 `json:"lun"`
42
- AuthType string `json:"auth_type"`
43
- DiscoverySecrets Secrets `json:"discovery_secrets"`
44
- SessionSecrets Secrets `json:"session_secrets"`
45
- Interface string `json:"interface"`
46
- Multipath bool `json:"multipath"`
47
- RetryCount int32 `json:"retry_count"`
48
- CheckInterval int32 `json:"check_interval"`
49
- DoDiscovery bool `json:"do_discovery"`
50
- DoCHAPDiscovery bool `json:"do_chap_discovery"`
45
+ VolumeName string `json:"volume_name"`
46
+ Targets []TargetInfo `json:"targets"`
47
+ Lun int32 `json:"lun"`
48
+ AuthType string `json:"auth_type"`
49
+ DiscoverySecrets Secrets `json:"discovery_secrets"`
50
+ SessionSecrets Secrets `json:"session_secrets"`
51
+ Interface string `json:"interface"`
52
+ Multipath bool `json:"multipath"`
53
+ RetryCount int32 `json:"retry_count"`
54
+ CheckInterval int32 `json:"check_interval"`
55
+ DoDiscovery bool `json:"do_discovery"`
56
+ DoCHAPDiscovery bool `json:"do_chap_discovery"`
51
57
}
52
58
53
59
func init () {
@@ -248,25 +254,28 @@ func Connect(c Connector) (string, error) {
248
254
}
249
255
iscsiTransport := extractTransportName (out )
250
256
251
- for _ , p := range c .TargetPortals {
252
- debug .Printf ("process portal: %s\n " , p )
253
- baseArgs := []string {"-m" , "node" , "-T" , c . TargetIqn , "-p" , p }
257
+ for _ , target := range c .Targets {
258
+ debug .Printf ("process targetIqn: %s, portal: %s\n " , target . Iqn , target . Portal )
259
+ baseArgs := []string {"-m" , "node" , "-T" , target . Iqn , "-p" , target . Portal }
254
260
// Rescan sessions to discover newly mapped LUNs. Do not specify the interface when rescanning
255
261
// to avoid establishing additional sessions to the same target.
256
262
if _ , err := iscsiCmd (append (baseArgs , []string {"-R" }... )... ); err != nil {
257
263
debug .Printf ("failed to rescan session, err: %v" , err )
258
264
}
259
265
260
266
// create our devicePath that we'll be looking for based on the transport being used
261
- if c .Port != "" {
262
- p = strings .Join ([]string {p , c .Port }, ":" )
267
+ port := defaultPort
268
+ if target .Port != "" {
269
+ port = target .Port
263
270
}
264
- devicePath := strings .Join ([]string {"/dev/disk/by-path/ip" , p , "iscsi" , c .TargetIqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
271
+ // portal with port
272
+ p := strings .Join ([]string {target .Portal , port }, ":" )
273
+ devicePath := strings .Join ([]string {"/dev/disk/by-path/ip" , p , "iscsi" , target .Iqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
265
274
if iscsiTransport != "tcp" {
266
- devicePath = strings .Join ([]string {"/dev/disk/by-path/pci" , "*" , "ip" , p , "iscsi" , c . TargetIqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
275
+ devicePath = strings .Join ([]string {"/dev/disk/by-path/pci" , "*" , "ip" , p , "iscsi" , target . Iqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
267
276
}
268
277
269
- exists , _ := sessionExists (p , c . TargetIqn )
278
+ exists , _ := sessionExists (p , target . Iqn )
270
279
if exists {
271
280
if exists , err := waitForPathToExist (& devicePath , 1 , 1 , iscsiTransport ); exists {
272
281
debug .Printf ("Appending device path: %s" , devicePath )
@@ -287,14 +296,14 @@ func Connect(c Connector) (string, error) {
287
296
}
288
297
289
298
// Make sure we don't log the secrets
290
- err := CreateDBEntry (c . TargetIqn , p , iFace , c .DiscoverySecrets , c .SessionSecrets , c .DoCHAPDiscovery )
299
+ err := CreateDBEntry (target . Iqn , p , iFace , c .DiscoverySecrets , c .SessionSecrets , c .DoCHAPDiscovery )
291
300
if err != nil {
292
301
debug .Printf ("Error creating db entry: %s\n " , err .Error ())
293
302
continue
294
303
}
295
304
296
305
// perform the login
297
- err = Login (c . TargetIqn , p )
306
+ err = Login (target . Iqn , p )
298
307
if err != nil {
299
308
debug .Printf ("failed to login, err: %v" , err )
300
309
lastErr = err
0 commit comments