Skip to content

Commit 5356b8d

Browse files
committed
criu: enable setting of RPC config file
This commit adds support for specifying a CRIU RPC configuration file. This config file allows users to overwrite the default CRIU options used by the container runtime, for example, to specify options such as `--tcp-established` or `--tcp-close` when checkpointing containers with TCP connections in Kubernetes. For compatibility with runc, the default config file path is set to `/etc/criu/runc.conf`. We also introduce support for crun.conf that will be used instead of runc.conf when the file is available. `criu_set_config_file()` was added to libcriu in version 4.2 Signed-off-by: Radostin Stoyanov <[email protected]>
1 parent aca68bb commit 5356b8d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/libcrun/criu.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
# define CRIU_CHECKPOINT_LOG_FILE "dump.log"
4444
# define CRIU_RESTORE_LOG_FILE "restore.log"
4545
# define DESCRIPTORS_FILENAME "descriptors.json"
46+
# define CRIU_RUNC_CONFIG_FILE "/etc/criu/runc.conf"
47+
# define CRIU_CRUN_CONFIG_FILE "/etc/criu/crun.conf"
4648

4749
# define CRIU_EXT_NETNS "extRootNetNS"
4850
# define CRIU_EXT_PIDNS "extRootPidNS"
@@ -99,6 +101,7 @@ struct libcriu_wrapper_s
99101
void (*criu_set_work_dir_fd) (int fd);
100102
int (*criu_set_lsm_profile) (const char *name);
101103
int (*criu_set_lsm_mount_context) (const char *name);
104+
int (*criu_set_config_file) (const char *path);
102105
};
103106

104107
static struct libcriu_wrapper_s *libcriu_wrapper;
@@ -194,6 +197,8 @@ load_wrapper (struct libcriu_wrapper_s **wrapper_out, libcrun_error_t *err)
194197
LOAD_CRIU_FUNCTION (criu_set_work_dir_fd, false);
195198
LOAD_CRIU_FUNCTION (criu_set_lsm_profile, false);
196199
LOAD_CRIU_FUNCTION (criu_set_lsm_mount_context, false);
200+
/* criu_set_config_file was added to libcriu in v4.2 */
201+
LOAD_CRIU_FUNCTION (criu_set_config_file, true);
197202

198203
libcriu_wrapper = *wrapper_out = wrapper;
199204
wrapper = NULL;
@@ -460,6 +465,36 @@ checkpoint_cgroup_v1_mount (runtime_spec_schema_config_schema *def, libcrun_erro
460465
return 0;
461466
}
462467

468+
static int
469+
handle_criu_config_file (libcrun_container_t *container, libcrun_error_t *err)
470+
{
471+
const char *criu_config_annotation;
472+
const char *config_file = CRIU_RUNC_CONFIG_FILE;
473+
474+
criu_config_annotation = find_annotation (container, "org.criu.config");
475+
476+
if (libcriu_wrapper->criu_set_config_file == NULL)
477+
{
478+
if (criu_config_annotation)
479+
return crun_make_error (err, 0, "libcriu RPC config files supported in CRIU >= 4.2");
480+
return 0;
481+
}
482+
483+
if (criu_config_annotation)
484+
{
485+
config_file = CRIU_CRUN_CONFIG_FILE;
486+
}
487+
else if (access (CRIU_CRUN_CONFIG_FILE, F_OK) == 0)
488+
{
489+
config_file = CRIU_CRUN_CONFIG_FILE;
490+
}
491+
492+
libcriu_wrapper->criu_set_config_file (config_file);
493+
494+
return 0;
495+
}
496+
497+
463498
int
464499
libcrun_container_checkpoint_linux_criu (libcrun_container_status_t *status, libcrun_container_t *container,
465500
libcrun_checkpoint_restore_t *cr_options, libcrun_error_t *err)
@@ -522,6 +557,10 @@ libcrun_container_checkpoint_linux_criu (libcrun_container_status_t *status, lib
522557
/* Set up logging. */
523558
libcriu_wrapper->criu_set_log_level (4);
524559
libcriu_wrapper->criu_set_log_file (CRIU_CHECKPOINT_LOG_FILE);
560+
561+
/* Set up CRIU config file */
562+
handle_criu_config_file(container, err);
563+
525564
/* Setting the pid early as we can skip a lot of checkpoint setup if
526565
* we just do a pre-dump. The PID needs to be set always. Do it here.
527566
* The main process of the container is the process CRIU will checkpoint
@@ -1098,6 +1137,9 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
10981137
# endif
10991138
}
11001139

1140+
/* Set up CRIU config file */
1141+
handle_criu_config_file(container, err);
1142+
11011143
/* Tell CRIU if cgroup v1 needs to be handled. */
11021144
ret = restore_cgroup_v1_mount (def, err);
11031145
if (UNLIKELY (ret < 0))

0 commit comments

Comments
 (0)