mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-06 03:56:34 +00:00
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:
parent
36762c7cad
commit
d314e2d0b7
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
}
|
||||
|
@ -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