From 57773816b39b50dacc74894fea43d181f20ccb1a Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 12 Nov 2018 14:49:35 -0800 Subject: [PATCH] sandbox: Create and export Pause/ResumeContainer() to the API level In order to support use cases such as containerd-shim-v2 where we would have a long running process holding the sandbox pointer, there would be no reason to call into the stateless functions PauseContainer() and ResumeContainer(), which would recreate a new sandbox pointer and the corresponding ones for containers. Fixes #903 Signed-off-by: Sebastien Boeuf --- virtcontainers/api.go | 10 ++-------- virtcontainers/interfaces.go | 2 ++ virtcontainers/pkg/vcmock/sandbox.go | 10 ++++++++++ virtcontainers/sandbox.go | 24 ++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/virtcontainers/api.go b/virtcontainers/api.go index c564b9461c..55ccf6ddfd 100644 --- a/virtcontainers/api.go +++ b/virtcontainers/api.go @@ -784,17 +784,11 @@ func togglePauseContainer(ctx context.Context, sandboxID, containerID string, pa } defer s.releaseStatelessSandbox() - // Fetch the container. - c, err := s.findContainer(containerID) - if err != nil { - return err - } - if pause { - return c.pause() + return s.PauseContainer(containerID) } - return c.resume() + return s.ResumeContainer(containerID) } // PauseContainer is the virtcontainers container pause entry point. diff --git a/virtcontainers/interfaces.go b/virtcontainers/interfaces.go index 82e753c35c..10d03cdc0f 100644 --- a/virtcontainers/interfaces.go +++ b/virtcontainers/interfaces.go @@ -81,6 +81,8 @@ type VCSandbox interface { KillContainer(containerID string, signal syscall.Signal, all bool) error StatusContainer(containerID string) (ContainerStatus, error) StatsContainer(containerID string) (ContainerStats, error) + PauseContainer(containerID string) error + ResumeContainer(containerID string) error EnterContainer(containerID string, cmd Cmd) (VCContainer, *Process, error) UpdateContainer(containerID string, resources specs.LinuxResources) error ProcessListContainer(containerID string, options ProcessListOptions) (ProcessList, error) diff --git a/virtcontainers/pkg/vcmock/sandbox.go b/virtcontainers/pkg/vcmock/sandbox.go index 2d3dfb14f5..938248b78d 100644 --- a/virtcontainers/pkg/vcmock/sandbox.go +++ b/virtcontainers/pkg/vcmock/sandbox.go @@ -127,6 +127,16 @@ func (s *Sandbox) StatsContainer(contID string) (vc.ContainerStats, error) { return vc.ContainerStats{}, nil } +// PauseContainer implements the VCSandbox function of the same name. +func (s *Sandbox) PauseContainer(contID string) error { + return nil +} + +// ResumeContainer implements the VCSandbox function of the same name. +func (s *Sandbox) ResumeContainer(contID string) error { + return nil +} + // Status implements the VCSandbox function of the same name. func (s *Sandbox) Status() vc.SandboxStatus { return vc.SandboxStatus{} diff --git a/virtcontainers/sandbox.go b/virtcontainers/sandbox.go index d8fa76dfe2..c6cf596992 100644 --- a/virtcontainers/sandbox.go +++ b/virtcontainers/sandbox.go @@ -1463,6 +1463,30 @@ func (s *Sandbox) StatsContainer(containerID string) (ContainerStats, error) { return *stats, nil } +// PauseContainer pauses a running container. +func (s *Sandbox) PauseContainer(containerID string) error { + // Fetch the container. + c, err := s.findContainer(containerID) + if err != nil { + return err + } + + // Pause the container. + return c.pause() +} + +// ResumeContainer resumes a paused container. +func (s *Sandbox) ResumeContainer(containerID string) error { + // Fetch the container. + c, err := s.findContainer(containerID) + if err != nil { + return err + } + + // Resume the container. + return c.resume() +} + // createContainers registers all containers to the proxy, create the // containers in the guest and starts one shim per container. func (s *Sandbox) createContainers() error {