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