Skip to content

Commit faad359

Browse files
committed
[fix.] add retry for enable target loop
Signed-off-by: Yifan Yuan <[email protected]>
1 parent b9ec009 commit faad359

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pkg/snapshot/storage.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"path/filepath"
3131
"strconv"
3232
"strings"
33+
"syscall"
3334
"time"
3435

3536
sn "github.com/containerd/accelerated-container-image/pkg/types"
@@ -285,7 +286,24 @@ func (o *snapshotter) attachAndMountBlockDevice(ctx context.Context, snID string
285286
return fmt.Errorf("failed to write target max_data_area_mb for %s: max_data_area_mb=%d: %w", targetPath, obdMaxDataAreaMB, err)
286287
}
287288

288-
err = os.WriteFile(path.Join(targetPath, "enable"), ([]byte)("1"), 0666)
289+
// enable target may fails with EAGAIN, so we need to retry
290+
for retry := 0; retry < 100; retry++ {
291+
err = os.WriteFile(path.Join(targetPath, "enable"), ([]byte)("1"), 0666)
292+
if err != nil {
293+
perror, ok := err.(*os.PathError)
294+
if ok {
295+
if perror.Err == syscall.EAGAIN {
296+
log.G(ctx).Infof("write %s returned EAGAIN, retry", targetPath)
297+
time.Sleep(50 * time.Millisecond)
298+
continue
299+
}
300+
}
301+
return fmt.Errorf(err, "failed to write enable for %s", targetPath)
302+
} else {
303+
break
304+
}
305+
}
306+
289307
if err != nil {
290308
// read the init-debug.log for readable
291309
debugLogPath := o.overlaybdInitDebuglogPath(snID)

0 commit comments

Comments
 (0)