Skip to content

Commit c3a41d7

Browse files
authored
Merge pull request #4696 from avagin/criu-vs-exec
criu: Add time namespace to container config after checkpoint/restore
2 parents f88669c + b68cbdf commit c3a41d7

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Diff for: libcontainer/criu_linux.go

+7
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,13 @@ func (c *Container) criuNotifications(resp *criurpc.CriuResp, process *Process,
11511151
}
11521152
// create a timestamp indicating when the restored checkpoint was started
11531153
c.created = time.Now().UTC()
1154+
if !c.config.Namespaces.Contains(configs.NEWTIME) &&
1155+
configs.IsNamespaceSupported(configs.NEWTIME) &&
1156+
c.checkCriuVersion(31400) == nil {
1157+
// CRIU restores processes into a time namespace.
1158+
c.config.Namespaces = append(c.config.Namespaces,
1159+
configs.Namespace{Type: configs.NEWTIME})
1160+
}
11541161
if _, err := c.updateState(r); err != nil {
11551162
return err
11561163
}

Diff for: tests/integration/checkpoint.bats

+35
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,38 @@ function simple_cr() {
441441
pid=$(cat "pid")
442442
grep -q "${REL_CGROUPS_PATH}$" "/proc/$pid/cgroup"
443443
}
444+
445+
@test "checkpoint/restore and exec" {
446+
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
447+
[ "$status" -eq 0 ]
448+
449+
testcontainer test_busybox running
450+
451+
local execed_pid=""
452+
for _ in $(seq 2); do
453+
# checkpoint the running container
454+
runc checkpoint --work-path ./work-dir test_busybox
455+
[ "$status" -eq 0 ]
456+
457+
# after checkpoint busybox is no longer running
458+
testcontainer test_busybox checkpointed
459+
460+
# restore from checkpoint
461+
runc restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox
462+
[ "$status" -eq 0 ]
463+
464+
# busybox should be back up and running
465+
testcontainer test_busybox running
466+
467+
# verify that previously exec'd process is restored.
468+
if [ -n "$execed_pid" ]; then
469+
runc exec test_busybox ls -ld "/proc/$execed_pid"
470+
[ "$status" -eq 0 ]
471+
fi
472+
473+
# exec a new background process.
474+
runc exec test_busybox sh -c 'sleep 1000 < /dev/null &> /dev/null & echo $!'
475+
[ "$status" -eq 0 ]
476+
execed_pid=$output
477+
done
478+
}

0 commit comments

Comments
 (0)