Skip to content

Commit

Permalink
Merge pull request containers#18857 from Luap99/criu-version-error
Browse files Browse the repository at this point in the history
criu: return error when checking for min version
  • Loading branch information
openshift-merge-robot authored Jun 12, 2023
2 parents 77d2ae9 + ab502fc commit 1e1efd8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions libpod/container_internal_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,8 @@ func (c *Container) exportCheckpoint(options ContainerCheckpointOptions) error {
}

func (c *Container) checkpointRestoreSupported(version int) error {
if !criu.CheckForCriu(version) {
return fmt.Errorf("checkpoint/restore requires at least CRIU %d", version)
if err := criu.CheckForCriu(version); err != nil {
return err
}
if !c.ociRuntime.SupportsCheckpoint() {
return errors.New("configured runtime does not support checkpoint/restore")
Expand Down
4 changes: 2 additions & 2 deletions pkg/checkpoint/checkpoint_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func CRImportCheckpoint(ctx context.Context, runtime *libpod.Runtime, restoreOpt

if restoreOptions.Pod != "" {
// Restoring into a Pod requires much newer versions of CRIU
if !criu.CheckForCriu(criu.PodCriuVersion) {
return nil, fmt.Errorf("restoring containers into pods requires at least CRIU %d", criu.PodCriuVersion)
if err := criu.CheckForCriu(criu.PodCriuVersion); err != nil {
return nil, fmt.Errorf("restoring containers into pod: %w", err)
}
// The runtime also has to support it
if !crutils.CRRuntimeSupportsPodCheckpointRestore(runtime.GetOCIRuntimePath()) {
Expand Down
14 changes: 10 additions & 4 deletions pkg/criu/criu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package criu

import (
"fmt"

"github.com/checkpoint-restore/go-criu/v6"
"github.com/checkpoint-restore/go-criu/v6/rpc"

Expand All @@ -12,13 +14,17 @@ import (

// CheckForCriu uses CRIU's go bindings to check if the CRIU
// binary exists and if it at least the version Podman needs.
func CheckForCriu(version int) bool {
func CheckForCriu(version int) error {
c := criu.MakeCriu()
result, err := c.IsCriuAtLeast(version)
criuVersion, err := c.GetCriuVersion()
if err != nil {
return false
return fmt.Errorf("failed to check for criu version: %w", err)
}

if criuVersion >= version {
return nil
}
return result
return fmt.Errorf("checkpoint/restore requires at least CRIU %d, current version is %d", version, criuVersion)
}

func MemTrack() bool {
Expand Down
6 changes: 4 additions & 2 deletions pkg/criu/criu_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

package criu

func CheckForCriu(version int) bool {
return false
import "fmt"

func CheckForCriu(version int) error {
return fmt.Errorf("CheckForCriu not supported on this platform")
}

func MemTrack() bool {
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/checkpoint_image_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"fmt"
"os/exec"
"strconv"
"strings"
Expand All @@ -27,8 +28,8 @@ var _ = Describe("Podman checkpoint", func() {
Skip("OCI runtime does not support checkpoint/restore")
}

if !criu.CheckForCriu(criu.MinCriuVersion) {
Skip("CRIU is missing or too old.")
if err := criu.CheckForCriu(criu.MinCriuVersion); err != nil {
Skip(fmt.Sprintf("check CRIU version error: %v", err))
}
})

Expand Down
8 changes: 4 additions & 4 deletions test/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ var _ = Describe("Podman checkpoint", func() {
Skip("OCI runtime does not support checkpoint/restore")
}

if !criu.CheckForCriu(criu.MinCriuVersion) {
Skip("CRIU is missing or too old.")
if err := criu.CheckForCriu(criu.MinCriuVersion); err != nil {
Skip(fmt.Sprintf("check CRIU version error: %v", err))
}
// Only Fedora 29 and newer has a new enough selinux-policy and
// container-selinux package to support CRIU in correctly
Expand Down Expand Up @@ -1121,8 +1121,8 @@ var _ = Describe("Podman checkpoint", func() {
share := share // copy into local scope, for use inside function

It(testName, func() {
if !criu.CheckForCriu(criu.PodCriuVersion) {
Skip("CRIU is missing or too old.")
if err := criu.CheckForCriu(criu.PodCriuVersion); err != nil {
Skip(fmt.Sprintf("check CRIU pod version error: %v", err))
}
if !crutils.CRRuntimeSupportsPodCheckpointRestore(podmanTest.OCIRuntime) {
Skip("runtime does not support pod restore: " + podmanTest.OCIRuntime)
Expand Down

0 comments on commit 1e1efd8

Please sign in to comment.