Skip to content

Commit 1552ffa

Browse files
committed
fix(runtime): roll back snapshot view binds on failure
Signed-off-by: sidneychang <2190206983@qq.com>
1 parent 43cd324 commit 1552ffa

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

pkg/unikontainers/block.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,24 @@ func (b blockRootfs) preSetup() error {
260260

261261
bundleDir := filepath.Dir(b.monRootfs)
262262
var viewTargets []string
263+
viewMountsCommitted := false
264+
defer func() {
265+
if viewMountsCommitted || len(viewTargets) == 0 {
266+
return
267+
}
268+
rollbackPerContainerViewTargets(viewTargets)
269+
if err := removePerContainerViewMountsState(bundleDir); err != nil {
270+
uniklog.WithError(err).Warn("failed to remove snapshot view mount state during rollback")
271+
}
272+
}()
273+
263274
fromPerContainerView, err := tryRunOnPerContainerView(bundleDir, func(root string) error {
264275
var bindErr error
265276
viewTargets, bindErr = bindBootArtifactsToMonRootfs(root, b.monRootfs, b.kernelPath, b.initrdPath, b.uruncJSONPath)
266277
return bindErr
267278
})
268279
if err != nil {
269280
if len(viewTargets) > 0 {
270-
rollbackPerContainerViewTargets(viewTargets)
271281
return fmt.Errorf("snapshot view boot artifact bind completed but cleanup failed: %w", err)
272282
}
273283
uniklog.WithError(err).Warn("snapshot view unavailable; falling back to legacy boot file extraction")
@@ -286,6 +296,7 @@ func (b blockRootfs) preSetup() error {
286296
if err := mount.Unmount(b.mountedPath); err != nil {
287297
return fmt.Errorf("failed to unmount rootfs: %w", err)
288298
}
299+
viewMountsCommitted = true
289300
} else {
290301
if err := removePerContainerViewMountsState(bundleDir); err != nil {
291302
return err

0 commit comments

Comments
 (0)