agent: clean up share path created by the agent

The agent code creates a directory at
`/run/kata-containers/shared/sandboxes/sbid/` to hold shared data
between host and guest. We need to clean it up when removing a sandbox.

Fixes: #1138

Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
Peng Tao 2019-01-17 17:09:48 +08:00
parent 36762c7cad
commit d314e2d0b7
5 changed files with 23 additions and 0 deletions

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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) {
}

View File

@ -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)
}