@@ -3,8 +3,10 @@ package iscsi
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
+ "fmt"
6
7
"os"
7
8
"os/exec"
9
+ "strings"
8
10
"time"
9
11
)
10
12
@@ -50,7 +52,10 @@ func ExecWithTimeout(command string, args []string, timeout time.Duration) ([]by
50
52
}
51
53
52
54
if err != nil {
53
- debug .Printf ("Non-zero exit code: %s\n " , err )
55
+ if ee , ok := err .(* exec.ExitError ); ok {
56
+ debug .Printf ("Non-zero exit code: %s\n " , err )
57
+ err = fmt .Errorf ("%s" , ee .Stderr )
58
+ }
54
59
}
55
60
56
61
debug .Println ("Finished executing command." )
@@ -61,10 +66,10 @@ func getMultipathMap(device string) (*multipathDeviceMap, error) {
61
66
debug .Printf ("Getting multipath map for device %s.\n " , device )
62
67
63
68
cmd := exec .Command ("multipathd" , "show" , "map" , device [1 :], "json" )
64
- out , err := cmd .Output ()
69
+ out , err := cmd .CombinedOutput ()
65
70
// debug.Printf(string(out))
66
71
if err != nil {
67
- debug .Printf ("An error occured while looking for multipath device map: %v \n " , err )
72
+ debug .Printf ("An error occured while looking for multipath device map: %s \n " , out )
68
73
return nil , err
69
74
}
70
75
@@ -100,6 +105,9 @@ func FlushMultipathDevice(device *Device) error {
100
105
if _ , e := os .Stat (devicePath ); os .IsNotExist (e ) {
101
106
debug .Printf ("Multipath device %v has been removed.\n " , devicePath )
102
107
} else {
108
+ if strings .Contains (err .Error (), "map in use" ) {
109
+ err = fmt .Errorf ("device is probably still in use somewhere else: %v" , err )
110
+ }
103
111
debug .Printf ("Command 'multipath -f %v' did not succeed to delete the device: %v\n " , devicePath , err )
104
112
return err
105
113
}
0 commit comments