Skip to content

Commit 0834dae

Browse files
committed
Enable CRIU configuration files
CRIU 3.11 introduces configuration files: https://criu.org/Configuration_files https://lisas.de/~adrian/posts/2018-Nov-08-criu-configuration-files.html This enables the user to influence CRIU's behaviour without code changes if using new CRIU features or if the user wants to enable certain CRIU behaviour without always specifying certain options. With this it is possible to write 'tcp-established' to the configuration file: $ echo tcp-established > /etc/criu/runc.conf and from now on all checkpoints will preserve the state of established TCP connections. This removes the need to always use $ runc checkpoint --tcp-stablished If the goal is to always checkpoint with '--tcp-established' It also adds the possibility for unexpected CRIU behaviour if the user created a configuration file at some point in time and forgets about it. As a result of the discussion in opencontainers#1933 it is now also possible to define a CRIU configuration file for each container with the annotation 'org.criu.config'. If 'org.criu.config' does not exist, runc will tell CRIU to use '/etc/criu/runc.conf' if it exists. If 'org.criu.config' is set to an empty string (''), runc will tell CRIU to not use any runc specific configuration file at all. If 'org.criu.config' is set to a non-empty string, runc will use that value as an additional configuration file for CRIU. With the annotation the user can decide to use the default configuration file ('/etc/criu/runc.conf'), none or a container specific configuration file. Signed-off-by: Adrian Reber <[email protected]>
1 parent 4d173b3 commit 0834dae

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

libcontainer/container_linux.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,32 @@ func waitForCriuLazyServer(r *os.File, status string) error {
875875
return nil
876876
}
877877

878+
func (c *linuxContainer) handleCriuConfigurationFile(rpcOpts *criurpc.CriuOpts) {
879+
// CRIU will evaluate a configuration starting with release 3.11.
880+
// Settings in the configuration file will overwrite RPC settings.
881+
// Look for annotations. The annotation 'org.criu.config'
882+
// specifies if CRIU should use a different, container specific
883+
// configuration file.
884+
_, annotations := utils.Annotations(c.config.Labels)
885+
configFile, exists := annotations["org.criu.config"]
886+
if exists {
887+
// If the annotation 'org.criu.config' exists and is set
888+
// to a non-empty string, tell CRIU to use that as a
889+
// configuration file. If the file does not exist, CRIU
890+
// will just ignore it.
891+
if configFile != "" {
892+
rpcOpts.ConfigFile = proto.String(configFile)
893+
}
894+
// If 'org.criu.config' exists and is set to an empty
895+
// string, a runc specific CRIU configuration file will
896+
// be not set at all.
897+
} else {
898+
// If the mentioned annotation has not been found, specify
899+
// a default CRIU configuration file.
900+
rpcOpts.ConfigFile = proto.String("/etc/criu/runc.conf")
901+
}
902+
}
903+
878904
func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
879905
c.m.Lock()
880906
defer c.m.Unlock()
@@ -940,6 +966,8 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
940966
LazyPages: proto.Bool(criuOpts.LazyPages),
941967
}
942968

969+
c.handleCriuConfigurationFile(&rpcOpts)
970+
943971
// If the container is running in a network namespace and has
944972
// a path to the network namespace configured, we will dump
945973
// that network namespace as an external namespace and we
@@ -1190,6 +1218,8 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
11901218
},
11911219
}
11921220

1221+
c.handleCriuConfigurationFile(req.Opts)
1222+
11931223
// Same as during checkpointing. If the container has a specific network namespace
11941224
// assigned to it, this now expects that the checkpoint will be restored in a
11951225
// already created network namespace.

0 commit comments

Comments
 (0)