mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Verify that used OCI runtime supports checkpoint
To be able to use OCI runtimes which do not implement checkpoint/restore this adds a check to the checkpoint code path and the checkpoint/restore tests to see if it knows about the checkpoint subcommand. If the used OCI runtime does not implement checkpoint/restore the tests are skipped and the actual 'podman container checkpoint' returns an error. Signed-off-by: Adrian Reber <areber@redhat.com>
This commit is contained in:

committed by
Adrian Reber

parent
5afae0b25b
commit
43fe2bf064
@ -472,10 +472,19 @@ func (c *Container) addNamespaceContainer(g *generate.Generator, ns LinuxNS, ctr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointOptions) (err error) {
|
func (c *Container) checkpointRestoreSupported() (err error) {
|
||||||
|
|
||||||
if !criu.CheckForCriu() {
|
if !criu.CheckForCriu() {
|
||||||
return errors.Errorf("checkpointing a container requires at least CRIU %d", criu.MinCriuVersion)
|
return errors.Errorf("Checkpoint/Restore requires at least CRIU %d", criu.MinCriuVersion)
|
||||||
|
}
|
||||||
|
if !c.runtime.ociRuntime.featureCheckCheckpointing() {
|
||||||
|
return errors.Errorf("Configured runtime does not support checkpoint/restore")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointOptions) (err error) {
|
||||||
|
if err := c.checkpointRestoreSupported(); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.state.State != ContainerStateRunning {
|
if c.state.State != ContainerStateRunning {
|
||||||
@ -532,8 +541,8 @@ func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointO
|
|||||||
|
|
||||||
func (c *Container) restore(ctx context.Context, options ContainerCheckpointOptions) (err error) {
|
func (c *Container) restore(ctx context.Context, options ContainerCheckpointOptions) (err error) {
|
||||||
|
|
||||||
if !criu.CheckForCriu() {
|
if err := c.checkpointRestoreSupported(); err != nil {
|
||||||
return errors.Errorf("restoring a container requires at least CRIU %d", criu.MinCriuVersion)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.state.State != ContainerStateConfigured) && (c.state.State != ContainerStateExited) {
|
if (c.state.State != ContainerStateConfigured) && (c.state.State != ContainerStateExited) {
|
||||||
|
@ -890,3 +890,16 @@ func (r *OCIRuntime) checkpointContainer(ctr *Container, options ContainerCheckp
|
|||||||
args = append(args, ctr.ID())
|
args = append(args, ctr.ID())
|
||||||
return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, nil, r.path, args...)
|
return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, nil, r.path, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *OCIRuntime) featureCheckCheckpointing() bool {
|
||||||
|
// Check if the runtime implements checkpointing. Currently only
|
||||||
|
// runc's checkpoint/restore implementation is supported.
|
||||||
|
cmd := exec.Command(r.path, "checkpoint", "-h")
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if err := cmd.Wait(); err == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
"github.com/containers/libpod/pkg/criu"
|
"github.com/containers/libpod/pkg/criu"
|
||||||
. "github.com/containers/libpod/test/utils"
|
. "github.com/containers/libpod/test/utils"
|
||||||
@ -27,6 +28,16 @@ var _ = Describe("Podman checkpoint", func() {
|
|||||||
}
|
}
|
||||||
podmanTest = PodmanTestCreate(tempdir)
|
podmanTest = PodmanTestCreate(tempdir)
|
||||||
podmanTest.RestoreAllArtifacts()
|
podmanTest.RestoreAllArtifacts()
|
||||||
|
// Check if the runtime implements checkpointing. Currently only
|
||||||
|
// runc's checkpoint/restore implementation is supported.
|
||||||
|
cmd := exec.Command(podmanTest.OCIRuntime, "checkpoint", "-h")
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
Skip("OCI runtime does not support checkpoint/restore")
|
||||||
|
}
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
Skip("OCI runtime does not support checkpoint/restore")
|
||||||
|
}
|
||||||
|
|
||||||
if !criu.CheckForCriu() {
|
if !criu.CheckForCriu() {
|
||||||
Skip("CRIU is missing or too old.")
|
Skip("CRIU is missing or too old.")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user