mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-01 17:52:40 +00:00
commit
3b0b0147bd
@ -254,4 +254,7 @@ type agent interface {
|
||||
|
||||
// copyFile copies file from host to container's rootfs
|
||||
copyFile(src, dst string) error
|
||||
|
||||
// cleanup removes all on disk information generated by the agent
|
||||
cleanup(id string)
|
||||
}
|
||||
|
@ -1012,3 +1012,10 @@ func (h *hyper) copyFile(src, dst string) error {
|
||||
// hyperstart-agent does not support copyFile
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *hyper) cleanup(id string) {
|
||||
path := h.getSharePath(id)
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
h.Logger().WithError(err).Errorf("failed to cleanup vm share path %s", path)
|
||||
}
|
||||
}
|
||||
|
@ -1835,3 +1835,11 @@ func (k *kataAgent) copyFile(src, dst string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *kataAgent) cleanup(id string) {
|
||||
path := k.getSharePath(id)
|
||||
k.Logger().WithField("path", path).Infof("cleanup agent")
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
k.Logger().WithError(err).Errorf("failed to cleanup vm share path %s", path)
|
||||
}
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ func bindUnmountContainerRootfs(ctx context.Context, sharedDir, sandboxID, cID s
|
||||
defer span.Finish()
|
||||
|
||||
rootfsDest := filepath.Join(sharedDir, sandboxID, cID, rootfsDir)
|
||||
syscall.Unmount(rootfsDest, 0)
|
||||
syscall.Unmount(rootfsDest, syscall.MNT_DETACH)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -215,3 +215,6 @@ func (n *noopAgent) setGuestDateTime(time.Time) error {
|
||||
func (n *noopAgent) copyFile(src, dst string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *noopAgent) cleanup(id string) {
|
||||
}
|
||||
|
@ -654,9 +654,25 @@ func (q *qemu) stopSandbox() error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.RemoveAll(filepath.Join(RunVMStoragePath, q.id))
|
||||
// cleanup vm path
|
||||
dir := filepath.Join(RunVMStoragePath, q.id)
|
||||
|
||||
// If it's a symlink, remove both dir and the target.
|
||||
// This can happen when vm template links a sandbox to a vm.
|
||||
link, err := filepath.EvalSymlinks(dir)
|
||||
if err != nil {
|
||||
q.Logger().WithError(err).Error("Fail to clean up vm directory")
|
||||
// Well, it's just cleanup failure. Let's ignore it.
|
||||
q.Logger().WithError(err).WithField("dir", dir).Warn("failed to resolve vm path")
|
||||
}
|
||||
q.Logger().WithField("link", link).WithField("dir", dir).Infof("cleanup vm path")
|
||||
|
||||
if err := os.RemoveAll(dir); err != nil {
|
||||
q.Logger().WithError(err).Warnf("failed to remove vm path %s", dir)
|
||||
}
|
||||
if link != dir && link != "" {
|
||||
if err := os.RemoveAll(link); err != nil {
|
||||
q.Logger().WithError(err).WithField("link", link).Warn("failed to remove resolved vm path")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -744,6 +744,8 @@ func (s *Sandbox) Delete() error {
|
||||
s.Logger().WithError(err).Error("failed to cleanup hypervisor")
|
||||
}
|
||||
|
||||
s.agent.cleanup(s.id)
|
||||
|
||||
return s.storage.deleteSandboxResources(s.id, nil)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user