Skip to content

Commit

Permalink
linux: pass down state_root to the cgroup handler
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Oct 15, 2024
1 parent 3cbded3 commit 4712dff
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/libcrun/cgroup-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct libcrun_cgroup_manager
/* Destroy the cgroup and kill any process if needed. */
int (*destroy_cgroup) (struct libcrun_cgroup_status *cgroup_status, libcrun_error_t *err);
/* Additional resources configuration specific to this manager. */
int (*update_resources) (struct libcrun_cgroup_status *cgroup_status, runtime_spec_schema_config_linux_resources *resources, libcrun_error_t *err);
int (*update_resources) (struct libcrun_cgroup_status *cgroup_status, const char *state_root, runtime_spec_schema_config_linux_resources *resources, libcrun_error_t *err);
};

int move_process_to_cgroup (pid_t pid, const char *subsystem, const char *path, libcrun_error_t *err);
Expand Down
1 change: 1 addition & 0 deletions src/libcrun/cgroup-resources.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ update_cgroup_v2_resources (runtime_spec_schema_config_linux_resources *resource

int
update_cgroup_resources (const char *path,
const char *state_root,
runtime_spec_schema_config_linux_resources *resources,
libcrun_error_t *err)
{
Expand Down
1 change: 1 addition & 0 deletions src/libcrun/cgroup-resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct default_dev_s
struct default_dev_s *get_default_devices ();

int update_cgroup_resources (const char *path,
const char *state_root,
runtime_spec_schema_config_linux_resources *resources,
libcrun_error_t *err);

Expand Down
3 changes: 3 additions & 0 deletions src/libcrun/cgroup-systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,7 @@ libcrun_destroy_cgroup_systemd (struct libcrun_cgroup_status *cgroup_status,

static int
libcrun_update_resources_systemd (struct libcrun_cgroup_status *cgroup_status,
const char *state_root,
runtime_spec_schema_config_linux_resources *resources,
libcrun_error_t *err)
{
Expand Down Expand Up @@ -1710,10 +1711,12 @@ libcrun_destroy_cgroup_systemd (struct libcrun_cgroup_status *cgroup_status,

static int
libcrun_update_resources_systemd (struct libcrun_cgroup_status *cgroup_status,
const char *state_root,
runtime_spec_schema_config_linux_resources *resources,
libcrun_error_t *err)
{
(void) cgroup_status;
(void) state_root;
(void) resources;

return crun_make_error (err, ENOTSUP, "systemd not supported");
Expand Down
7 changes: 4 additions & 3 deletions src/libcrun/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ libcrun_cgroup_destroy (struct libcrun_cgroup_status *cgroup_status, libcrun_err

int
libcrun_update_cgroup_resources (struct libcrun_cgroup_status *cgroup_status,
const char *state_root,
runtime_spec_schema_config_linux_resources *resources,
libcrun_error_t *err)
{
Expand All @@ -218,11 +219,11 @@ libcrun_update_cgroup_resources (struct libcrun_cgroup_status *cgroup_status,

if (cgroup_manager->update_resources)
{
ret = cgroup_manager->update_resources (cgroup_status, resources, err);
ret = cgroup_manager->update_resources (cgroup_status, state_root, resources, err);
if (UNLIKELY (ret < 0))
return ret;
}
return update_cgroup_resources (cgroup_status->path, resources, err);
return update_cgroup_resources (cgroup_status->path, state_root, resources, err);
}

static int
Expand Down Expand Up @@ -375,7 +376,7 @@ libcrun_cgroup_enter (struct libcrun_cgroup_args *args, struct libcrun_cgroup_st

if (args->resources)
{
ret = update_cgroup_resources (status->path, args->resources, err);
ret = update_cgroup_resources (status->path, args->state_root, args->resources, err);
if (UNLIKELY (ret < 0))
return ret;
}
Expand Down
3 changes: 3 additions & 0 deletions src/libcrun/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct libcrun_cgroup_args
gid_t root_gid;
const char *id;
bool joined;

const char *state_root;
};

/* cgroup life-cycle management. */
Expand Down Expand Up @@ -89,6 +91,7 @@ int libcrun_cgroup_has_oom (struct libcrun_cgroup_status *status, libcrun_error_
int libcrun_cgroup_read_pids (struct libcrun_cgroup_status *status, bool recurse, pid_t **pids, libcrun_error_t *err);

int libcrun_update_cgroup_resources (struct libcrun_cgroup_status *status,
const char *state_root,
runtime_spec_schema_config_linux_resources *resources,
libcrun_error_t *err);

Expand Down
4 changes: 3 additions & 1 deletion src/libcrun/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,7 @@ libcrun_container_run_internal (libcrun_container_t *container, libcrun_context_
cg.annotations = def->annotations;
cg.root_uid = root_uid;
cg.root_gid = root_gid;
cg.state_root = context->state_root;

ret = libcrun_cgroup_preenter (&cg, &cgroup_dirfd, err);
if (UNLIKELY (ret < 0))
Expand Down Expand Up @@ -3848,7 +3849,7 @@ libcrun_container_update (libcrun_context_t *context, const char *id, const char
return ret;
}

ret = libcrun_linux_container_update (&status, resources, err);
ret = libcrun_linux_container_update (&status, state_root, resources, err);

cleanup:
if (tree)
Expand Down Expand Up @@ -4270,6 +4271,7 @@ libcrun_container_restore (libcrun_context_t *context, const char *id, libcrun_c
.root_uid = root_uid,
.root_gid = root_gid,
.id = context->id,
.state_root = context->state_root,
};

ret = libcrun_cgroup_enter (&cg, &cgroup_status, err);
Expand Down
4 changes: 2 additions & 2 deletions src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -5442,13 +5442,13 @@ libcrun_join_process (libcrun_context_t *context,
}

int
libcrun_linux_container_update (libcrun_container_status_t *status, runtime_spec_schema_config_linux_resources *resources, libcrun_error_t *err)
libcrun_linux_container_update (libcrun_container_status_t *status, const char *state_root, runtime_spec_schema_config_linux_resources *resources, libcrun_error_t *err)
{
cleanup_cgroup_status struct libcrun_cgroup_status *cgroup_status = NULL;

cgroup_status = libcrun_cgroup_make_status (status);

return libcrun_update_cgroup_resources (cgroup_status, resources, err);
return libcrun_update_cgroup_resources (cgroup_status, state_root, resources, err);
}

static int
Expand Down
4 changes: 3 additions & 1 deletion src/libcrun/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ int libcrun_join_process (libcrun_context_t *context, libcrun_container_t *conta
libcrun_container_status_t *status, const char *cgroup, int detach,
runtime_spec_schema_config_schema_process *process, int *terminal_fd, libcrun_error_t *err);
int libcrun_linux_container_update (libcrun_container_status_t *status,
runtime_spec_schema_config_linux_resources *resources, libcrun_error_t *err);
const char *state_root,
runtime_spec_schema_config_linux_resources *resources,
libcrun_error_t *err);
int libcrun_create_keyring (const char *name, const char *label, libcrun_error_t *err);
int libcrun_container_pause_linux (libcrun_container_status_t *status, libcrun_error_t *err);
int libcrun_container_unpause_linux (libcrun_container_status_t *status, libcrun_error_t *err);
Expand Down

0 comments on commit 4712dff

Please sign in to comment.