@@ -56,10 +56,8 @@ type Device struct {
56
56
Hctl string `json:"hctl"`
57
57
Children []Device `json:"children"`
58
58
Type string `json:"type"`
59
- Vendor string `json:"vendor"`
60
- Model string `json:"model"`
61
- Revision string `json:"rev"`
62
59
Transport string `json:"tran"`
60
+ Size string `json:"size,omitempty"`
63
61
}
64
62
65
63
// Connector provides a struct to hold all of the needed parameters to make our iSCSI connection
@@ -216,17 +214,8 @@ func pathExists(devicePath *string, deviceTransport string) error {
216
214
// getMultipathDevice returns a multipath device for the configured targets if it exists
217
215
func getMultipathDevice (devices []Device ) (* Device , error ) {
218
216
var multipathDevice * Device
219
- var devicePaths []string
220
217
221
218
for _ , device := range devices {
222
- devicePaths = append (devicePaths , device .GetPath ())
223
- }
224
- deviceInfo , err := lsblk ("" , devicePaths )
225
- if err != nil {
226
- return nil , err
227
- }
228
-
229
- for _ , device := range deviceInfo .BlockDevices {
230
219
if len (device .Children ) != 1 {
231
220
return nil , fmt .Errorf ("device is not mapped to exactly one multipath device: %v" , device .Children )
232
221
}
@@ -454,7 +443,7 @@ func (c *Connector) IsMultipathEnabled() bool {
454
443
func GetSCSIDevices (devicePaths []string ) ([]Device , error ) {
455
444
debug .Printf ("Getting info about SCSI devices %s.\n " , devicePaths )
456
445
457
- deviceInfo , err := lsblk ("-S" , devicePaths )
446
+ deviceInfo , err := lsblk (devicePaths )
458
447
if err != nil {
459
448
debug .Printf ("An error occured while looking info about SCSI devices: %v" , err )
460
449
return nil , err
@@ -482,24 +471,19 @@ func GetISCSIDevices(devicePaths []string) (devices []Device, err error) {
482
471
}
483
472
484
473
// lsblk execute the lsblk commands
485
- func lsblkRaw (flags string , devicePaths []string ) ([]byte , error ) {
486
- out , err := execCommand ("lsblk" , append ([]string {flags }, devicePaths ... )... ).CombinedOutput ()
487
- debug .Printf ("lsblk %s %s" , flags , strings .Join (devicePaths , " " ))
488
- if err != nil {
489
- return nil , fmt .Errorf ("lsblk: %s" , string (out ))
490
- }
491
-
492
- return out , nil
493
- }
494
-
495
- func lsblk (flags string , devicePaths []string ) (* deviceInfo , error ) {
496
- var deviceInfo deviceInfo
497
-
498
- out , err := lsblkRaw ("-J " + flags , devicePaths )
474
+ func lsblk (devicePaths []string ) (* deviceInfo , error ) {
475
+ flags := []string {"-J" , "-o" , "NAME,HCTL,TYPE,TRAN,SIZE" }
476
+ command := execCommand ("lsblk" , append (flags , devicePaths ... )... )
477
+ debug .Println (command .String ())
478
+ out , err := command .Output ()
499
479
if err != nil {
480
+ if ee , ok := err .(* exec.ExitError ); ok {
481
+ return nil , fmt .Errorf ("%s, (%v)" , strings .Trim (string (ee .Stderr ), "\n " ), ee )
482
+ }
500
483
return nil , err
501
484
}
502
485
486
+ var deviceInfo deviceInfo
503
487
if err = json .Unmarshal (out , & deviceInfo ); err != nil {
504
488
return nil , err
505
489
}
@@ -589,16 +573,30 @@ func (c *Connector) Persist(filePath string) error {
589
573
func GetConnectorFromFile (filePath string ) (* Connector , error ) {
590
574
f , err := ioutil .ReadFile (filePath )
591
575
if err != nil {
592
- return & Connector {}, err
593
-
576
+ return nil , err
594
577
}
595
- data := Connector {}
596
- err = json .Unmarshal (f , & data )
578
+ c := Connector {}
579
+ err = json .Unmarshal ([] byte ( f ) , & c )
597
580
if err != nil {
598
- return & Connector {}, err
581
+ return nil , err
582
+ }
583
+
584
+ devicePaths := []string {}
585
+ for _ , device := range c .Devices {
586
+ devicePaths = append (devicePaths , device .GetPath ())
587
+ }
588
+
589
+ if devices , err := GetSCSIDevices ([]string {c .MountTargetDevice .GetPath ()}); err != nil {
590
+ return nil , err
591
+ } else {
592
+ c .MountTargetDevice = & devices [0 ]
593
+ }
594
+
595
+ if c .Devices , err = GetSCSIDevices (devicePaths ); err != nil {
596
+ return nil , err
599
597
}
600
598
601
- return & data , nil
599
+ return & c , nil
602
600
}
603
601
604
602
// Exists check if the device exists at its path and returns an error otherwise
0 commit comments