@@ -548,22 +548,26 @@ func RemoveSCSIDevices(devices ...Device) error {
548
548
var errs []error
549
549
for _ , device := range devices {
550
550
debug .Printf ("Flush SCSI device %v.\n " , device .Name )
551
- out , err := exec .Command ("blockdev" , "--flushbufs" , device .GetPath ()).CombinedOutput ()
552
- if err != nil {
553
- debug .Printf ("Command 'blockdev --flushbufs %v' did not succeed to flush the device: %v\n " , device .Name , err )
554
- return errors .New (string (out ))
551
+ if err := device .Exists (); err == nil {
552
+ out , err := exec .Command ("blockdev" , "--flushbufs" , device .GetPath ()).CombinedOutput ()
553
+ if err != nil {
554
+ debug .Printf ("Command 'blockdev --flushbufs %s' did not succeed to flush the device: %v\n " , device .GetPath (), err )
555
+ return errors .New (string (out ))
556
+ }
557
+ } else if ! os .IsNotExist (err ) {
558
+ return err
555
559
}
556
560
557
- debug .Printf ("Put SCSI device %v offline.\n " , device .Name )
558
- err = device .Shutdown ()
561
+ debug .Printf ("Put SCSI device %q offline.\n " , device .Name )
562
+ err : = device .Shutdown ()
559
563
if err != nil {
560
564
if ! os .IsNotExist (err ) { // Ignore device already removed
561
565
errs = append (errs , err )
562
566
}
563
567
continue
564
568
}
565
569
566
- debug .Printf ("Delete SCSI device %v .\n " , device .Name )
570
+ debug .Printf ("Delete SCSI device %q .\n " , device .Name )
567
571
err = device .Delete ()
568
572
if err != nil {
569
573
if ! os .IsNotExist (err ) { // Ignore device already removed
@@ -611,6 +615,12 @@ func GetConnectorFromFile(filePath string) (*Connector, error) {
611
615
return & data , nil
612
616
}
613
617
618
+ // Exists check if the device exists at its path and returns an error otherwise
619
+ func (d * Device ) Exists () error {
620
+ _ , err := os .Stat (d .GetPath ())
621
+ return err
622
+ }
623
+
614
624
// GetPath returns the path of a device
615
625
func (d * Device ) GetPath () string {
616
626
if d .Type == "mpath" {
0 commit comments