@@ -39,13 +39,6 @@ type iscsiSession struct {
39
39
Name string
40
40
}
41
41
42
- // TargetInfo contains connection information to connect to an iSCSI endpoint
43
- type TargetInfo struct {
44
- Iqn string `json:"iqn"`
45
- Portal string `json:"portal"`
46
- Port string `json:"port"`
47
- }
48
-
49
42
type deviceInfo struct {
50
43
BlockDevices []Device
51
44
}
@@ -69,13 +62,14 @@ type HCTL struct {
69
62
70
63
// Connector provides a struct to hold all of the needed parameters to make our iSCSI connection
71
64
type Connector struct {
72
- VolumeName string `json:"volume_name"`
73
- Targets []TargetInfo `json:"targets"`
74
- Lun int32 `json:"lun"`
75
- AuthType string `json:"auth_type"`
76
- DiscoverySecrets Secrets `json:"discovery_secrets"`
77
- SessionSecrets Secrets `json:"session_secrets"`
78
- Interface string `json:"interface"`
65
+ VolumeName string `json:"volume_name"`
66
+ TargetIqn string `json:"target_iqn"`
67
+ TargetPortals []string `json:"target_portal"`
68
+ Lun int32 `json:"lun"`
69
+ AuthType string `json:"auth_type"`
70
+ DiscoverySecrets Secrets `json:"discovery_secrets"`
71
+ SessionSecrets Secrets `json:"session_secrets"`
72
+ Interface string `json:"interface"`
79
73
80
74
MountTargetDevice * Device `json:"mount_target_device"`
81
75
Devices []Device `json:"devices"`
@@ -247,6 +241,11 @@ func getMultipathDevice(devices []Device) (*Device, error) {
247
241
return multipathDevice , nil
248
242
}
249
243
244
+ // Connect is for backward-compatiblity with c.Connect()
245
+ func Connect (c Connector ) (string , error ) {
246
+ return c .Connect ()
247
+ }
248
+
250
249
// Connect attempts to connect a volume to this node using the provided Connector info
251
250
func (c * Connector ) Connect () (string , error ) {
252
251
if c .RetryCount == 0 {
@@ -270,8 +269,8 @@ func (c *Connector) Connect() (string, error) {
270
269
271
270
var lastErr error
272
271
var devicePaths []string
273
- for _ , target := range c .Targets {
274
- devicePath , err := c .connectTarget (& target , iFace , iscsiTransport )
272
+ for _ , target := range c .TargetPortals {
273
+ devicePath , err := c .connectTarget (c . TargetIqn , target , iFace , iscsiTransport )
275
274
if err != nil {
276
275
lastErr = err
277
276
} else {
@@ -311,9 +310,15 @@ func (c *Connector) Connect() (string, error) {
311
310
return c .MountTargetDevice .GetPath (), nil
312
311
}
313
312
314
- func (c * Connector ) connectTarget (target * TargetInfo , iFace string , iscsiTransport string ) (string , error ) {
315
- debug .Printf ("Process targetIqn: %s, portal: %s\n " , target .Iqn , target .Portal )
316
- baseArgs := []string {"-m" , "node" , "-T" , target .Iqn , "-p" , target .Portal }
313
+ func (c * Connector ) connectTarget (targetIqn string , target string , iFace string , iscsiTransport string ) (string , error ) {
314
+ debug .Printf ("Process targetIqn: %s, portal: %s\n " , targetIqn , target )
315
+ targetParts := strings .Split (target , ":" )
316
+ targetPortal := targetParts [0 ]
317
+ targetPort := defaultPort
318
+ if len (targetParts ) > 1 {
319
+ targetPort = targetParts [1 ]
320
+ }
321
+ baseArgs := []string {"-m" , "node" , "-T" , targetIqn , "-p" , targetPortal }
317
322
// Rescan sessions to discover newly mapped LUNs. Do not specify the interface when rescanning
318
323
// to avoid establishing additional sessions to the same target.
319
324
if _ , err := iscsiCmd (append (baseArgs , []string {"-R" }... )... ); err != nil {
@@ -329,18 +334,14 @@ func (c *Connector) connectTarget(target *TargetInfo, iFace string, iscsiTranspo
329
334
}
330
335
331
336
// create our devicePath that we'll be looking for based on the transport being used
332
- port := defaultPort
333
- if target .Port != "" {
334
- port = target .Port
335
- }
336
337
// portal with port
337
- portal := strings .Join ([]string {target . Portal , port }, ":" )
338
- devicePath := strings .Join ([]string {"/dev/disk/by-path/ip" , portal , "iscsi" , target . Iqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
338
+ portal := strings .Join ([]string {targetPortal , targetPort }, ":" )
339
+ devicePath := strings .Join ([]string {"/dev/disk/by-path/ip" , portal , "iscsi" , targetIqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
339
340
if iscsiTransport != "tcp" {
340
- devicePath = strings .Join ([]string {"/dev/disk/by-path/pci" , "*" , "ip" , portal , "iscsi" , target . Iqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
341
+ devicePath = strings .Join ([]string {"/dev/disk/by-path/pci" , "*" , "ip" , portal , "iscsi" , targetIqn , "lun" , fmt .Sprint (c .Lun )}, "-" )
341
342
}
342
343
343
- exists , _ := sessionExists (portal , target . Iqn )
344
+ exists , _ := sessionExists (portal , targetIqn )
344
345
if exists {
345
346
debug .Printf ("Session already exists, checking if device path %q exists" , devicePath )
346
347
if err := waitForPathToExist (& devicePath , c .RetryCount , c .CheckInterval , iscsiTransport ); err != nil {
@@ -349,12 +350,12 @@ func (c *Connector) connectTarget(target *TargetInfo, iFace string, iscsiTranspo
349
350
return devicePath , nil
350
351
}
351
352
352
- if err := c .discoverTarget (target , iFace , portal ); err != nil {
353
+ if err := c .discoverTarget (targetIqn , iFace , portal ); err != nil {
353
354
return "" , err
354
355
}
355
356
356
357
// perform the login
357
- err := Login (target . Iqn , portal )
358
+ err := Login (targetIqn , portal )
358
359
if err != nil {
359
360
debug .Printf ("Failed to login: %v" , err )
360
361
return "" , err
@@ -368,7 +369,7 @@ func (c *Connector) connectTarget(target *TargetInfo, iFace string, iscsiTranspo
368
369
return devicePath , nil
369
370
}
370
371
371
- func (c * Connector ) discoverTarget (target * TargetInfo , iFace string , portal string ) error {
372
+ func (c * Connector ) discoverTarget (targetIqn string , iFace string , portal string ) error {
372
373
if c .DoDiscovery {
373
374
// build discoverydb and discover iscsi target
374
375
if err := Discoverydb (portal , iFace , c .DiscoverySecrets , c .DoCHAPDiscovery ); err != nil {
@@ -379,7 +380,7 @@ func (c *Connector) discoverTarget(target *TargetInfo, iFace string, portal stri
379
380
380
381
if c .DoCHAPDiscovery {
381
382
// Make sure we don't log the secrets
382
- err := CreateDBEntry (target . Iqn , portal , iFace , c .DiscoverySecrets , c .SessionSecrets )
383
+ err := CreateDBEntry (targetIqn , portal , iFace , c .DiscoverySecrets , c .SessionSecrets )
383
384
if err != nil {
384
385
debug .Printf ("Error creating db entry: %s\n " , err .Error ())
385
386
return err
@@ -389,21 +390,25 @@ func (c *Connector) discoverTarget(target *TargetInfo, iFace string, portal stri
389
390
return nil
390
391
}
391
392
392
- // Disconnect performs a disconnect operation from an appliance.
393
- // Be sure to disconnect all deivces properly before doing this as it can result in data loss.
394
- func ( c * Connector ) Disconnect () {
395
- for _ , target := range c . Targets {
396
- Logout (target . Iqn , target . Portal )
393
+ // Disconnect is for backward-compatibility with c.Disconnect()
394
+ func Disconnect ( targetIqn string , targets [] string ) {
395
+ for _ , target := range targets {
396
+ targetPortal := strings . Split ( target , ":" )[ 0 ]
397
+ Logout (targetIqn , targetPortal )
397
398
}
398
399
399
400
deleted := map [string ]bool {}
400
- for _ , target := range c .Targets {
401
- if _ , ok := deleted [target .Iqn ]; ok {
402
- continue
403
- }
404
- deleted [target .Iqn ] = true
405
- DeleteDBEntry (target .Iqn )
401
+ if _ , ok := deleted [targetIqn ]; ok {
402
+ return
406
403
}
404
+ deleted [targetIqn ] = true
405
+ DeleteDBEntry (targetIqn )
406
+ }
407
+
408
+ // Disconnect performs a disconnect operation from an appliance.
409
+ // Be sure to disconnect all deivces properly before doing this as it can result in data loss.
410
+ func (c * Connector ) Disconnect () {
411
+ Disconnect (c .TargetIqn , c .TargetPortals )
407
412
}
408
413
409
414
// DisconnectVolume removes a volume from a Linux host.
@@ -588,6 +593,11 @@ func RemoveSCSIDevices(devices ...Device) error {
588
593
return nil
589
594
}
590
595
596
+ // PersistConnector is for backward-compatibility with c.Persist()
597
+ func PersistConnector (c * Connector , filePath string ) error {
598
+ return c .Persist (filePath )
599
+ }
600
+
591
601
// Persist persists the Connector to the specified file (ie /var/lib/pfile/myConnector.json)
592
602
func (c * Connector ) Persist (filePath string ) error {
593
603
//file := path.Join("mnt", c.VolumeName+".json")
0 commit comments