From ab502fc5c496d0fd7fefb984f4052e39cf9fd3f7 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 12 Jun 2023 15:05:40 +0200 Subject: [PATCH] criu: return error when checking for min version There is weird issue #18856 which causes the version check to fail. Return the underlying error in these cases so we can see it and debug it. Signed-off-by: Paul Holzinger --- libpod/container_internal_common.go | 4 ++-- pkg/checkpoint/checkpoint_restore.go | 4 ++-- pkg/criu/criu_linux.go | 14 ++++++++++---- pkg/criu/criu_unsupported.go | 6 ++++-- test/e2e/checkpoint_image_test.go | 5 +++-- test/e2e/checkpoint_test.go | 8 ++++---- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go index fadff0b4e5..d7cb65e43b 100644 --- a/libpod/container_internal_common.go +++ b/libpod/container_internal_common.go @@ -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") diff --git a/pkg/checkpoint/checkpoint_restore.go b/pkg/checkpoint/checkpoint_restore.go index f461363551..aa4d167dec 100644 --- a/pkg/checkpoint/checkpoint_restore.go +++ b/pkg/checkpoint/checkpoint_restore.go @@ -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()) { diff --git a/pkg/criu/criu_linux.go b/pkg/criu/criu_linux.go index ee1de85965..5525e31b09 100644 --- a/pkg/criu/criu_linux.go +++ b/pkg/criu/criu_linux.go @@ -4,6 +4,8 @@ package criu import ( + "fmt" + "github.com/checkpoint-restore/go-criu/v6" "github.com/checkpoint-restore/go-criu/v6/rpc" @@ -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 { diff --git a/pkg/criu/criu_unsupported.go b/pkg/criu/criu_unsupported.go index 437482a0e5..8def2b89cf 100644 --- a/pkg/criu/criu_unsupported.go +++ b/pkg/criu/criu_unsupported.go @@ -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 { diff --git a/test/e2e/checkpoint_image_test.go b/test/e2e/checkpoint_image_test.go index 34c91b3437..ab3dc72908 100644 --- a/test/e2e/checkpoint_image_test.go +++ b/test/e2e/checkpoint_image_test.go @@ -1,6 +1,7 @@ package integration import ( + "fmt" "os/exec" "strconv" "strings" @@ -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)) } }) diff --git a/test/e2e/checkpoint_test.go b/test/e2e/checkpoint_test.go index 4fb33d9f54..e713667721 100644 --- a/test/e2e/checkpoint_test.go +++ b/test/e2e/checkpoint_test.go @@ -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 @@ -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)