From db025aba75c8d8fd78cc9c213905fd24931f4fc2 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 12 Feb 2021 17:56:53 -0800 Subject: [PATCH] libct: criuSwrk: only iterate over CriuOpts if debug is set In case log level is less than debug, this code does nothing, so let's add a condition and skip it entirely. Add a test case to make sure this code path is hit. Signed-off-by: Kir Kolyshkin --- libcontainer/container_linux.go | 5 +++-- tests/integration/checkpoint.bats | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 65e2eace8..a6221178e 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -1524,8 +1524,9 @@ func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts * // should be empty. For older CRIU versions it still will be // available but empty. criurpc.CriuReqType_VERSION actually // has no req.GetOpts(). - if !(req.GetType() == criurpc.CriuReqType_FEATURE_CHECK || - req.GetType() == criurpc.CriuReqType_VERSION) { + if logrus.GetLevel() >= logrus.DebugLevel && + !(req.GetType() == criurpc.CriuReqType_FEATURE_CHECK || + req.GetType() == criurpc.CriuReqType_VERSION) { val := reflect.ValueOf(req.GetOpts()) v := reflect.Indirect(val) diff --git a/tests/integration/checkpoint.bats b/tests/integration/checkpoint.bats index ccfbe0b7d..b60456412 100644 --- a/tests/integration/checkpoint.bats +++ b/tests/integration/checkpoint.bats @@ -97,7 +97,7 @@ function simple_cr() { for _ in $(seq 2); do # checkpoint the running container - runc --criu "$CRIU" checkpoint --work-path ./work-dir test_busybox + runc --criu "$CRIU" "$@" checkpoint --work-path ./work-dir test_busybox grep -B 5 Error ./work-dir/dump.log || true [ "$status" -eq 0 ] @@ -105,7 +105,7 @@ function simple_cr() { testcontainer test_busybox checkpointed # restore from checkpoint - runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox + runc --criu "$CRIU" "$@" restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox grep -B 5 Error ./work-dir/restore.log || true [ "$status" -eq 0 ] @@ -118,6 +118,10 @@ function simple_cr() { simple_cr } +@test "checkpoint and restore (with --debug)" { + simple_cr --debug +} + @test "checkpoint and restore (cgroupns)" { # cgroupv2 already enables cgroupns so this case was tested above already requires cgroups_v1 cgroupns