@@ -279,7 +279,7 @@ func (c *Connector) Connect() (string, error) {
279
279
// GetISCSIDevices returns all devices if no paths are given
280
280
if len (devicePaths ) < 1 {
281
281
c .Devices = []Device {}
282
- } else if c .Devices , err = GetISCSIDevices (devicePaths ); err != nil {
282
+ } else if c .Devices , err = GetISCSIDevices (devicePaths , true ); err != nil {
283
283
return "" , err
284
284
}
285
285
@@ -457,10 +457,10 @@ func (c *Connector) IsMultipathEnabled() bool {
457
457
458
458
// GetSCSIDevices get SCSI devices from device paths
459
459
// It will returns all SCSI devices if no paths are given
460
- func GetSCSIDevices (devicePaths []string ) ([]Device , error ) {
460
+ func GetSCSIDevices (devicePaths []string , strict bool ) ([]Device , error ) {
461
461
debug .Printf ("Getting info about SCSI devices %s.\n " , devicePaths )
462
462
463
- deviceInfo , err := lsblk (devicePaths )
463
+ deviceInfo , err := lsblk (devicePaths , strict )
464
464
if err != nil {
465
465
debug .Printf ("An error occured while looking info about SCSI devices: %v" , err )
466
466
return nil , err
@@ -471,8 +471,8 @@ func GetSCSIDevices(devicePaths []string) ([]Device, error) {
471
471
472
472
// GetISCSIDevices get iSCSI devices from device paths
473
473
// It will returns all iSCSI devices if no paths are given
474
- func GetISCSIDevices (devicePaths []string ) (devices []Device , err error ) {
475
- scsiDevices , err := GetSCSIDevices (devicePaths )
474
+ func GetISCSIDevices (devicePaths []string , strict bool ) (devices []Device , err error ) {
475
+ scsiDevices , err := GetSCSIDevices (devicePaths , strict )
476
476
if err != nil {
477
477
return
478
478
}
@@ -488,21 +488,26 @@ func GetISCSIDevices(devicePaths []string) (devices []Device, err error) {
488
488
}
489
489
490
490
// lsblk execute the lsblk commands
491
- func lsblk (devicePaths []string ) (* deviceInfo , error ) {
491
+ func lsblk (devicePaths []string , strict bool ) (* deviceInfo , error ) {
492
492
flags := []string {"-J" , "-o" , "NAME,HCTL,TYPE,TRAN,SIZE" }
493
493
command := execCommand ("lsblk" , append (flags , devicePaths ... )... )
494
494
debug .Println (command .String ())
495
495
out , err := command .Output ()
496
496
if err != nil {
497
497
if ee , ok := err .(* exec.ExitError ); ok {
498
- return nil , fmt .Errorf ("%s, (%v)" , strings .Trim (string (ee .Stderr ), "\n " ), ee )
498
+ err = fmt .Errorf ("%s, (%w)" , strings .Trim (string (ee .Stderr ), "\n " ), ee )
499
+ if strict || ee .ExitCode () != 64 { // ignore the error if some devices have been found when not strict
500
+ return nil , err
501
+ }
502
+ debug .Printf ("lsblk could find only some devices: %v" , err )
503
+ } else {
504
+ return nil , err
499
505
}
500
- return nil , err
501
506
}
502
507
503
508
var deviceInfo deviceInfo
504
- if err = json .Unmarshal (out , & deviceInfo ); err != nil {
505
- return nil , err
509
+ if jsonErr : = json .Unmarshal (out , & deviceInfo ); jsonErr != nil {
510
+ return nil , jsonErr
506
511
}
507
512
508
513
return & deviceInfo , nil
@@ -603,13 +608,13 @@ func GetConnectorFromFile(filePath string) (*Connector, error) {
603
608
devicePaths = append (devicePaths , device .GetPath ())
604
609
}
605
610
606
- if devices , err := GetSCSIDevices ([]string {c .MountTargetDevice .GetPath ()}); err != nil {
611
+ if devices , err := GetSCSIDevices ([]string {c .MountTargetDevice .GetPath ()}, false ); err != nil {
607
612
return nil , err
608
613
} else {
609
614
c .MountTargetDevice = & devices [0 ]
610
615
}
611
616
612
- if c .Devices , err = GetSCSIDevices (devicePaths ); err != nil {
617
+ if c .Devices , err = GetSCSIDevices (devicePaths , false ); err != nil {
613
618
return nil , err
614
619
}
615
620
0 commit comments