Skip to content

Commit

Permalink
Merge pull request containers#650 from kolyshkin/v2-cgroupns
Browse files Browse the repository at this point in the history
spec: add cgroup ns if on cgroup v2
  • Loading branch information
giuseppe authored Apr 20, 2021
2 parents fe705a9 + 227e0be commit 8a88d72
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/libcrun/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,7 @@ libcrun_cgroup_pause_unpause (const char *cgroup_path, const bool pause, libcrun
int cgroup_mode;

cgroup_mode = libcrun_get_cgroup_mode (err);
if (cgroup_mode < 0)
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

return libcrun_cgroup_pause_unpause_with_mode (cgroup_path, cgroup_mode, pause, err);
Expand Down Expand Up @@ -1996,7 +1996,7 @@ libcrun_cgroup_read_pids (const char *path, bool recurse, pid_t **pids, libcrun_
return 0;

mode = libcrun_get_cgroup_mode (err);
if (mode < 0)
if (UNLIKELY (mode < 0))
return mode;

switch (mode)
Expand Down Expand Up @@ -2146,7 +2146,7 @@ libcrun_cgroup_destroy (const char *id, const char *path, const char *scope, int
return -1;

mode = libcrun_get_cgroup_mode (err);
if (mode < 0)
if (UNLIKELY (mode < 0))
return mode;

ret = libcrun_cgroup_killall (path, err);
Expand Down
25 changes: 20 additions & 5 deletions src/libcrun/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct sync_socket_message_s

typedef runtime_spec_schema_defs_hook hook;

static char spec_file[] = "\
static const char spec_file[] = "\
{\n\
\"ociVersion\": \"1.0.0\",\n\
\"process\": {\n\
Expand Down Expand Up @@ -255,6 +255,7 @@ static char spec_file[] = "\
{\n\
\"type\": \"uts\"\n\
},\n\
%s\
%s\
{\n\
\"type\": \"mount\"\n\
Expand Down Expand Up @@ -290,6 +291,11 @@ static const char *spec_user = "\
\"type\": \"user\"\n \
},\n";

static const char *spec_cgroupns = "\
{\n\
\"type\": \"cgroup\"\n \
},\n";

#define SYNC_SOCKET_MESSAGE_LEN(x, l) (offsetof (struct sync_socket_message_s, message) + l)

static int
Expand Down Expand Up @@ -2239,7 +2245,7 @@ libcrun_container_run_internal (libcrun_container_t *container, libcrun_context_
}

cgroup_mode = libcrun_get_cgroup_mode (err);
if (cgroup_mode < 0)
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

pid = libcrun_run_linux_container (container, container_init, &container_args, &sync_socket, err);
Expand Down Expand Up @@ -2824,7 +2830,7 @@ libcrun_get_container_state_string (const char *id, libcrun_container_status_t *
int cgroup_mode;

cgroup_mode = libcrun_get_cgroup_mode (err);
if (cgroup_mode < 0)
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

ret = libcrun_cgroup_is_container_paused (status->cgroup_path, cgroup_mode, &paused, err);
Expand Down Expand Up @@ -3362,7 +3368,16 @@ libcrun_container_update_from_file (libcrun_context_t *context, const char *id,
int
libcrun_container_spec (bool root, FILE *out, libcrun_error_t *err arg_unused)
{
return fprintf (out, spec_file, root ? spec_pts_tty_group : "\n", root ? "" : spec_user);
int cgroup_mode;

cgroup_mode = libcrun_get_cgroup_mode (err);
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

return fprintf (out, spec_file,
root ? spec_pts_tty_group : "\n",
root ? "" : spec_user,
cgroup_mode == CGROUP_MODE_UNIFIED ? spec_cgroupns : "");
}

int
Expand Down Expand Up @@ -3487,7 +3502,7 @@ libcrun_container_restore (libcrun_context_t *context, const char *id, libcrun_c
def = container->container_def;

cgroup_mode = libcrun_get_cgroup_mode (err);
if (cgroup_mode < 0)
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

cgroup_manager = CGROUP_MANAGER_CGROUPFS;
Expand Down
4 changes: 2 additions & 2 deletions src/libcrun/criu.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ restore_cgroup_v1_mount (runtime_spec_schema_config_schema *def, libcrun_error_t
uint32_t i;

cgroup_mode = libcrun_get_cgroup_mode (err);
if (cgroup_mode < 0)
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

if (cgroup_mode == CGROUP_MODE_UNIFIED)
Expand Down Expand Up @@ -306,7 +306,7 @@ libcrun_container_checkpoint_linux_criu (libcrun_container_status_t *status, lib
return crun_make_error (err, 0, "error setting CRIU root to %s\n", path);

cgroup_mode = libcrun_get_cgroup_mode (err);
if (cgroup_mode < 0)
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

/* For cgroup v1 we need to tell CRIU to handle all cgroup mounts as external mounts. */
Expand Down
6 changes: 3 additions & 3 deletions src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ do_mount_cgroup_v2 (libcrun_container_t *container, int targetfd, const char *ta
int cgroup_mode;

cgroup_mode = libcrun_get_cgroup_mode (err);
if (cgroup_mode < 0)
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

ret = do_mount (container, "cgroup2", targetfd, target, "cgroup2", mountflags, NULL, LABEL_NONE, err);
Expand Down Expand Up @@ -954,7 +954,7 @@ do_mount_cgroup (libcrun_container_t *container, const char *source, int targetf
int cgroup_mode;

cgroup_mode = libcrun_get_cgroup_mode (err);
if (cgroup_mode < 0)
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

switch (cgroup_mode)
Expand Down Expand Up @@ -3737,7 +3737,7 @@ libcrun_linux_container_update (libcrun_container_status_t *status, const char *
int cgroup_mode;

cgroup_mode = libcrun_get_cgroup_mode (err);
if (cgroup_mode < 0)
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

ret = parse_json_file (&tree, content, &ctx, err);
Expand Down

0 comments on commit 8a88d72

Please sign in to comment.