mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-07 16:34:28 +01:00
When the container's rootfs is block storage backed such as devmapper, shimv2 will not mount it on the host, instead it insert it into hypervisor as a block device directly. If kata's config set "disable_block_device_use" as true, it will mount the rootfs onto host as before. Fixes:#1158 Signed-off-by: lifupan <lifupan@gmail.com>
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
// Copyright (c) 2018 HyperHQ Inc.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package containerdshim
|
|
|
|
import (
|
|
"context"
|
|
"path"
|
|
|
|
"github.com/containerd/containerd/mount"
|
|
"github.com/kata-containers/runtime/pkg/katautils"
|
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func deleteContainer(ctx context.Context, s *service, c *container) error {
|
|
|
|
status, err := s.sandbox.StatusContainer(c.id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if status.State.State != types.StateStopped {
|
|
_, err = s.sandbox.StopContainer(c.id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
_, err = s.sandbox.DeleteContainer(c.id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Run post-stop OCI hooks.
|
|
if err := katautils.PostStopHooks(ctx, *c.spec, s.sandbox.ID(), c.bundle); err != nil {
|
|
return err
|
|
}
|
|
|
|
if s.mount {
|
|
rootfs := path.Join(c.bundle, "rootfs")
|
|
if err := mount.UnmountAll(rootfs, 0); err != nil {
|
|
logrus.WithError(err).Warn("failed to cleanup rootfs mount")
|
|
}
|
|
}
|
|
|
|
delete(s.containers, c.id)
|
|
|
|
return nil
|
|
}
|