55 "encoding/json"
66 "fmt"
77 "slices"
8+ "time"
9+
10+ "github.com/rs/zerolog"
811
912 "github.com/opensvc/om3/v3/core/actionrollback"
1013 "github.com/opensvc/om3/v3/core/datarecv"
@@ -17,7 +20,6 @@ import (
1720 "github.com/opensvc/om3/v3/util/hostname"
1821 "github.com/opensvc/om3/v3/util/sizeconv"
1922 "github.com/opensvc/om3/v3/util/udevadm"
20- "github.com/rs/zerolog"
2123)
2224
2325type (
@@ -79,6 +81,10 @@ type (
7981 }
8082)
8183
84+ const (
85+ DefaultCommandTimeout = 10 * time .Second
86+ )
87+
8288func New () resource.Driver {
8389 t := & T {}
8490 return t
@@ -116,6 +122,7 @@ func (t *T) mapDevice(ctx context.Context) error {
116122 args = append (args , "map" , t .Name )
117123 cmd := command .New (
118124 command .WithContext (ctx ),
125+ command .WithTimeout (DefaultCommandTimeout ),
119126 command .WithName ("rbd" ),
120127 command .WithArgs (args ),
121128 command .WithLogger (t .Log ()),
@@ -144,6 +151,7 @@ func (t *T) unmapDevice(ctx context.Context) error {
144151 args = append (args , "unmap" , t .Name )
145152 cmd := command .New (
146153 command .WithContext (ctx ),
154+ command .WithTimeout (DefaultCommandTimeout ),
147155 command .WithName ("rbd" ),
148156 command .WithArgs (args ),
149157 command .WithLogger (t .Log ()),
@@ -166,6 +174,7 @@ func (t *T) createDevice(ctx context.Context) error {
166174 args = append (args , "create" , "--size" , fmt .Sprintf ("%dB" , bytes ), t .Name )
167175 cmd := command .New (
168176 command .WithContext (ctx ),
177+ command .WithTimeout (DefaultCommandTimeout ),
169178 command .WithName ("rbd" ),
170179 command .WithArgs (args ),
171180 command .WithLogger (t .Log ()),
@@ -188,6 +197,7 @@ func (t *T) removeDevice(ctx context.Context) error {
188197 args = append (args , "remove" , t .Name )
189198 cmd := command .New (
190199 command .WithContext (ctx ),
200+ command .WithTimeout (DefaultCommandTimeout ),
191201 command .WithName ("rbd" ),
192202 command .WithArgs (args ),
193203 command .WithLogger (t .Log ()),
@@ -217,6 +227,7 @@ func (t *T) lockDevice(ctx context.Context) error {
217227 }
218228 cmd := command .New (
219229 command .WithContext (ctx ),
230+ command .WithTimeout (DefaultCommandTimeout ),
220231 command .WithName ("rbd" ),
221232 command .WithArgs (args ),
222233 command .WithLogger (t .Log ()),
@@ -246,6 +257,7 @@ func (t *T) unlockDevice(ctx context.Context) error {
246257 }
247258 cmd := command .New (
248259 command .WithContext (ctx ),
260+ command .WithTimeout (DefaultCommandTimeout ),
249261 command .WithName ("rbd" ),
250262 command .WithArgs (args ),
251263 command .WithLogger (t .Log ()),
@@ -271,6 +283,7 @@ func (t *T) deviceInfo(ctx context.Context) (*RBDInfo, error) {
271283 args = append (args , "info" , t .Name , "--format" , "json" )
272284 cmd := command .New (
273285 command .WithContext (ctx ),
286+ command .WithTimeout (DefaultCommandTimeout ),
274287 command .WithName ("rbd" ),
275288 command .WithArgs (args ),
276289 command .WithLogger (t .Log ()),
@@ -299,6 +312,7 @@ func (t *T) listLocks(ctx context.Context) ([]RBDLock, error) {
299312 args = append (args , "lock" , "list" , t .Name , "--format" , "json" )
300313 cmd := command .New (
301314 command .WithContext (ctx ),
315+ command .WithTimeout (DefaultCommandTimeout ),
302316 command .WithName ("rbd" ),
303317 command .WithArgs (args ),
304318 command .WithLogger (t .Log ()),
@@ -324,6 +338,7 @@ func (t *T) listDevices(ctx context.Context) ([]RBDMap, error) {
324338 args = append (args , "device" , "list" , "--format" , "json" )
325339 cmd := command .New (
326340 command .WithContext (ctx ),
341+ command .WithTimeout (DefaultCommandTimeout ),
327342 command .WithName ("rbd" ),
328343 command .WithArgs (args ),
329344 command .WithLogger (t .Log ()),
0 commit comments