Skip to content

Commit c7b73ea

Browse files
christoph-zededarouming
authored andcommitted
diskmetrics: set exec timeout explicitly
for command executions that run in separate worker thread: set timeout to 1000 seconds (as it was before) for direct command executions: set timeout to 400 seconds in order to not trigger the watchdog and therefore a reboot Signed-off-by: Christoph Ostarek <[email protected]> (cherry picked from commit 4240dd3)
1 parent cd33be0 commit c7b73ea

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

pkg/pillar/diskmetrics/diskmetrics.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ import (
1717
"github.com/lf-edge/eve/pkg/pillar/types"
1818
)
1919

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+
2025
func GetImgInfo(log *base.LogObject, diskfile string) (*types.ImgInfo, error) {
2126
var imgInfo types.ImgInfo
2227

2328
if _, err := os.Stat(diskfile); err != nil {
2429
return nil, err
2530
}
2631
output, err := base.Exec(log, "/usr/bin/qemu-img", "info", "-U", "--output=json",
27-
diskfile).CombinedOutput()
32+
diskfile).WithUnlimitedTimeout(qemuExecLongTimeout).CombinedOutput()
2833
if err != nil {
2934
errStr := fmt.Sprintf("qemu-img failed: %s, %s\n",
3035
err, output)
@@ -65,7 +70,7 @@ func ResizeImg(ctx context.Context, log *base.LogObject, diskfile string, newsiz
6570
return err
6671
}
6772
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()
6974
if err != nil {
7075
errStr := fmt.Sprintf("qemu-img failed: %s, %s\n",
7176
err, output)
@@ -77,7 +82,7 @@ func ResizeImg(ctx context.Context, log *base.LogObject, diskfile string, newsiz
7782
// CreateImg creates empty diskfile with defined format and size
7883
func CreateImg(ctx context.Context, log *base.LogObject, diskfile string, format string, size uint64) error {
7984
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()
8186
if err != nil {
8287
errStr := fmt.Sprintf("qemu-img failed: %s, %s\n",
8388
err, output)
@@ -94,7 +99,7 @@ func RolloutImgToBlock(ctx context.Context, log *base.LogObject, diskfile, outpu
9499
// writeback cache instead of default unsafe, out of order enabled, skip file creation
95100
// Timeout 2 hours
96101
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()
98103
if err != nil {
99104
errStr := fmt.Sprintf("qemu-img failed: %s, %s\n",
100105
err, output)
@@ -113,7 +118,7 @@ func CreateSnapshot(ctx context.Context, log *base.LogObject, diskfile, snapshot
113118
cmdBin := "/usr/bin/qemu-img"
114119
cmdArgs := []string{"snapshot", "-c", snapshotName, diskfile}
115120
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()
117122
if err != nil {
118123
errStr := fmt.Sprintf("qemu-img failed: %s, %s\n", err, output)
119124
return errors.New(errStr)
@@ -131,7 +136,7 @@ func ApplySnapshot(ctx context.Context, log *base.LogObject, diskfile, snapshotN
131136
cmdBin := "/usr/bin/qemu-img"
132137
cmdArgs := []string{"snapshot", "-a", snapshotName, diskfile}
133138
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()
135140
if err != nil {
136141
errStr := fmt.Sprintf("qemu-img failed: %s, %s\n", err, output)
137142
return errors.New(errStr)
@@ -146,7 +151,7 @@ func DeleteSnapshot(ctx context.Context, log *base.LogObject, diskfile, snapshot
146151
cmdBin := "/usr/bin/qemu-img"
147152
cmdArgs := []string{"snapshot", "-d", snapshotName, diskfile}
148153
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()
150155
if err != nil {
151156
errStr := fmt.Sprintf("qemu-img failed: %s, %s\n", err, output)
152157
return errors.New(errStr)

0 commit comments

Comments
 (0)