Skip to content

Commit 1e1efd8

Browse files
Merge pull request #18857 from Luap99/criu-version-error
criu: return error when checking for min version
2 parents 77d2ae9 + ab502fc commit 1e1efd8

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed

libpod/container_internal_common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,8 @@ func (c *Container) exportCheckpoint(options ContainerCheckpointOptions) error {
11351135
}
11361136

11371137
func (c *Container) checkpointRestoreSupported(version int) error {
1138-
if !criu.CheckForCriu(version) {
1139-
return fmt.Errorf("checkpoint/restore requires at least CRIU %d", version)
1138+
if err := criu.CheckForCriu(version); err != nil {
1139+
return err
11401140
}
11411141
if !c.ociRuntime.SupportsCheckpoint() {
11421142
return errors.New("configured runtime does not support checkpoint/restore")

pkg/checkpoint/checkpoint_restore.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ func CRImportCheckpoint(ctx context.Context, runtime *libpod.Runtime, restoreOpt
9393

9494
if restoreOptions.Pod != "" {
9595
// Restoring into a Pod requires much newer versions of CRIU
96-
if !criu.CheckForCriu(criu.PodCriuVersion) {
97-
return nil, fmt.Errorf("restoring containers into pods requires at least CRIU %d", criu.PodCriuVersion)
96+
if err := criu.CheckForCriu(criu.PodCriuVersion); err != nil {
97+
return nil, fmt.Errorf("restoring containers into pod: %w", err)
9898
}
9999
// The runtime also has to support it
100100
if !crutils.CRRuntimeSupportsPodCheckpointRestore(runtime.GetOCIRuntimePath()) {

pkg/criu/criu_linux.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package criu
55

66
import (
7+
"fmt"
8+
79
"github.com/checkpoint-restore/go-criu/v6"
810
"github.com/checkpoint-restore/go-criu/v6/rpc"
911

@@ -12,13 +14,17 @@ import (
1214

1315
// CheckForCriu uses CRIU's go bindings to check if the CRIU
1416
// binary exists and if it at least the version Podman needs.
15-
func CheckForCriu(version int) bool {
17+
func CheckForCriu(version int) error {
1618
c := criu.MakeCriu()
17-
result, err := c.IsCriuAtLeast(version)
19+
criuVersion, err := c.GetCriuVersion()
1820
if err != nil {
19-
return false
21+
return fmt.Errorf("failed to check for criu version: %w", err)
22+
}
23+
24+
if criuVersion >= version {
25+
return nil
2026
}
21-
return result
27+
return fmt.Errorf("checkpoint/restore requires at least CRIU %d, current version is %d", version, criuVersion)
2228
}
2329

2430
func MemTrack() bool {

pkg/criu/criu_unsupported.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
package criu
55

6-
func CheckForCriu(version int) bool {
7-
return false
6+
import "fmt"
7+
8+
func CheckForCriu(version int) error {
9+
return fmt.Errorf("CheckForCriu not supported on this platform")
810
}
911

1012
func MemTrack() bool {

test/e2e/checkpoint_image_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package integration
22

33
import (
4+
"fmt"
45
"os/exec"
56
"strconv"
67
"strings"
@@ -27,8 +28,8 @@ var _ = Describe("Podman checkpoint", func() {
2728
Skip("OCI runtime does not support checkpoint/restore")
2829
}
2930

30-
if !criu.CheckForCriu(criu.MinCriuVersion) {
31-
Skip("CRIU is missing or too old.")
31+
if err := criu.CheckForCriu(criu.MinCriuVersion); err != nil {
32+
Skip(fmt.Sprintf("check CRIU version error: %v", err))
3233
}
3334
})
3435

test/e2e/checkpoint_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ var _ = Describe("Podman checkpoint", func() {
4343
Skip("OCI runtime does not support checkpoint/restore")
4444
}
4545

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

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

0 commit comments

Comments
 (0)