@@ -17,14 +17,19 @@ import (
17
17
"github.com/lf-edge/eve/pkg/pillar/types"
18
18
)
19
19
20
+ const qemuExecTimeout = 2 * time .Minute
21
+
22
+ // qemuExecLongTimeout is a long timeout for command executions in separate worker thread that don't interfere with the watchdog
23
+ const qemuExecLongTimeout = 1000 * time .Second
24
+
20
25
func GetImgInfo (log * base.LogObject , diskfile string ) (* types.ImgInfo , error ) {
21
26
var imgInfo types.ImgInfo
22
27
23
28
if _ , err := os .Stat (diskfile ); err != nil {
24
29
return nil , err
25
30
}
26
31
output , err := base .Exec (log , "/usr/bin/qemu-img" , "info" , "-U" , "--output=json" ,
27
- diskfile ).CombinedOutput ()
32
+ diskfile ).WithUnlimitedTimeout ( qemuExecLongTimeout ). CombinedOutput ()
28
33
if err != nil {
29
34
errStr := fmt .Sprintf ("qemu-img failed: %s, %s\n " ,
30
35
err , output )
@@ -65,7 +70,7 @@ func ResizeImg(ctx context.Context, log *base.LogObject, diskfile string, newsiz
65
70
return err
66
71
}
67
72
output , err := base .Exec (log , "/usr/bin/qemu-img" , "resize" , diskfile ,
68
- strconv .FormatUint (newsize , 10 )).WithContext (ctx ).CombinedOutput ()
73
+ strconv .FormatUint (newsize , 10 )).WithContext (ctx ).WithUnlimitedTimeout ( qemuExecLongTimeout ). CombinedOutput ()
69
74
if err != nil {
70
75
errStr := fmt .Sprintf ("qemu-img failed: %s, %s\n " ,
71
76
err , output )
@@ -77,7 +82,7 @@ func ResizeImg(ctx context.Context, log *base.LogObject, diskfile string, newsiz
77
82
// CreateImg creates empty diskfile with defined format and size
78
83
func CreateImg (ctx context.Context , log * base.LogObject , diskfile string , format string , size uint64 ) error {
79
84
output , err := base .Exec (log , "/usr/bin/qemu-img" , "create" , "-f" , format , diskfile ,
80
- strconv .FormatUint (size , 10 )).WithContext (ctx ).CombinedOutput ()
85
+ strconv .FormatUint (size , 10 )).WithContext (ctx ).WithUnlimitedTimeout ( qemuExecLongTimeout ). CombinedOutput ()
81
86
if err != nil {
82
87
errStr := fmt .Sprintf ("qemu-img failed: %s, %s\n " ,
83
88
err , output )
@@ -94,7 +99,7 @@ func RolloutImgToBlock(ctx context.Context, log *base.LogObject, diskfile, outpu
94
99
// writeback cache instead of default unsafe, out of order enabled, skip file creation
95
100
// Timeout 2 hours
96
101
args := []string {"convert" , "--target-is-zero" , "-t" , "writeback" , "-W" , "-n" , "-O" , outputFormat , diskfile , outputFile }
97
- output , err := base .Exec (log , "/usr/bin/qemu-img" , args ... ).WithContext (ctx ).WithUnlimitedTimeout (15 * time . Minute ).CombinedOutput ()
102
+ output , err := base .Exec (log , "/usr/bin/qemu-img" , args ... ).WithContext (ctx ).WithUnlimitedTimeout (qemuExecLongTimeout ).CombinedOutput ()
98
103
if err != nil {
99
104
errStr := fmt .Sprintf ("qemu-img failed: %s, %s\n " ,
100
105
err , output )
@@ -113,7 +118,7 @@ func CreateSnapshot(ctx context.Context, log *base.LogObject, diskfile, snapshot
113
118
cmdBin := "/usr/bin/qemu-img"
114
119
cmdArgs := []string {"snapshot" , "-c" , snapshotName , diskfile }
115
120
log .Noticef ("CreateSnapshot: %s %s" , cmdBin , strings .Join (cmdArgs , " " ))
116
- output , err := base .Exec (log , cmdBin , cmdArgs ... ).WithContext (ctx ).CombinedOutput ()
121
+ output , err := base .Exec (log , cmdBin , cmdArgs ... ).WithContext (ctx ).WithLimitedTimeout ( qemuExecTimeout ). CombinedOutput ()
117
122
if err != nil {
118
123
errStr := fmt .Sprintf ("qemu-img failed: %s, %s\n " , err , output )
119
124
return errors .New (errStr )
@@ -131,7 +136,7 @@ func ApplySnapshot(ctx context.Context, log *base.LogObject, diskfile, snapshotN
131
136
cmdBin := "/usr/bin/qemu-img"
132
137
cmdArgs := []string {"snapshot" , "-a" , snapshotName , diskfile }
133
138
log .Noticef ("ApplySnapshot: %s %s" , cmdBin , strings .Join (cmdArgs , " " ))
134
- output , err := base .Exec (log , cmdBin , cmdArgs ... ).WithContext (ctx ).CombinedOutput ()
139
+ output , err := base .Exec (log , cmdBin , cmdArgs ... ).WithContext (ctx ).WithLimitedTimeout ( qemuExecTimeout ). CombinedOutput ()
135
140
if err != nil {
136
141
errStr := fmt .Sprintf ("qemu-img failed: %s, %s\n " , err , output )
137
142
return errors .New (errStr )
@@ -146,7 +151,7 @@ func DeleteSnapshot(ctx context.Context, log *base.LogObject, diskfile, snapshot
146
151
cmdBin := "/usr/bin/qemu-img"
147
152
cmdArgs := []string {"snapshot" , "-d" , snapshotName , diskfile }
148
153
log .Noticef ("DeleteSnapshot: %s %s" , cmdBin , strings .Join (cmdArgs , " " ))
149
- output , err := base .Exec (log , cmdBin , cmdArgs ... ).WithContext (ctx ).CombinedOutput ()
154
+ output , err := base .Exec (log , cmdBin , cmdArgs ... ).WithContext (ctx ).WithLimitedTimeout ( qemuExecTimeout ). CombinedOutput ()
150
155
if err != nil {
151
156
errStr := fmt .Sprintf ("qemu-img failed: %s, %s\n " , err , output )
152
157
return errors .New (errStr )
0 commit comments