Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
agent: clean up share path created by the agent
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bergwolf committed Jan 21, 2019
1 parent 36762c7 commit d314e2d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions virtcontainers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 7 additions & 0 deletions virtcontainers/hyperstart_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
8 changes: 8 additions & 0 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
3 changes: 3 additions & 0 deletions virtcontainers/noop_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
2 changes: 2 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit d314e2d

Please sign in to comment.