Skip to content

Commit 48d389d

Browse files
author
Lou
committed
move Port to TargetInfo
Signed-off-by: Lou <[email protected]>
1 parent 0fd8753 commit 48d389d

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

iscsi/iscsi.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"time"
1717
)
1818

19+
const defaultPort = "3260"
20+
1921
var (
2022
debug *log.Logger
2123
execCommand = exec.Command
@@ -33,14 +35,15 @@ type iscsiSession struct {
3335
}
3436

3537
type TargetInfo struct {
36-
Iqn, Portal string
38+
Iqn string `json:"iqn"`
39+
Portal string `json:"portal"`
40+
Port string `json:"port"`
3741
}
3842

3943
//Connector provides a struct to hold all of the needed parameters to make our iscsi connection
4044
type Connector struct {
4145
VolumeName string `json:"volume_name"`
4246
Targets []TargetInfo `json:"targets"`
43-
Port string `json:"port"`
4447
Lun int32 `json:"lun"`
4548
AuthType string `json:"auth_type"`
4649
DiscoverySecrets Secrets `json:"discovery_secrets"`
@@ -253,23 +256,26 @@ func Connect(c Connector) (string, error) {
253256

254257
for _, target := range c.Targets {
255258
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}
257260
// Rescan sessions to discover newly mapped LUNs. Do not specify the interface when rescanning
258261
// to avoid establishing additional sessions to the same target.
259262
if _, err := iscsiCmd(append(baseArgs, []string{"-R"}...)...); err != nil {
260263
debug.Printf("failed to rescan session, err: %v", err)
261264
}
262265

263266
// 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
266270
}
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)}, "-")
268274
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)}, "-")
270276
}
271277

272-
exists, _ := sessionExists(target.Portal, target.Iqn)
278+
exists, _ := sessionExists(portal, target.Iqn)
273279
if exists {
274280
if exists, err := waitForPathToExist(&devicePath, 1, 1, iscsiTransport); exists {
275281
debug.Printf("Appending device path: %s", devicePath)
@@ -282,22 +288,22 @@ func Connect(c Connector) (string, error) {
282288

283289
if c.DoDiscovery {
284290
// 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 {
286292
debug.Printf("Error in discovery of the target: %s\n", err.Error())
287293
lastErr = err
288294
continue
289295
}
290296
}
291297

292298
// 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)
294300
if err != nil {
295301
debug.Printf("Error creating db entry: %s\n", err.Error())
296302
continue
297303
}
298304

299305
// perform the login
300-
err = Login(target.Iqn, target.Portal)
306+
err = Login(target.Iqn, portal)
301307
if err != nil {
302308
debug.Printf("failed to login, err: %v", err)
303309
lastErr = err

0 commit comments

Comments
 (0)