Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle case where cgroup v1 freezer is disabled #1616

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/libcrun/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <inttypes.h>
#include <time.h>

#include <linux/magic.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
Expand Down Expand Up @@ -142,7 +143,41 @@ libcrun_cgroup_is_container_paused (struct libcrun_cgroup_status *status, bool *

ret = read_all_file (path, &content, NULL, err);
if (UNLIKELY (ret < 0))
return ret;
{
errno = crun_error_get_errno (err);
/* If the file is missing and we were checking for freezer.state
(so either cgroup v1 or hybrid), it may be the freezer is
simply disabled. In such case the container cannot be paused.
On cgroup v2 freezer is always there.
*/
if (errno != ENOENT || cgroup_mode == CGROUP_MODE_UNIFIED)
return ret;

/* Even with freezer disabled, its directory is still there. But
when it's disabled it has type tmpfs, while on systems with
freezer enabled, its type is cgroupfs. Use that to determine
whether freezer is enabled or not.
*/
struct statfs freezer_stat;
if (statfs (CGROUP_ROOT "/freezer", &freezer_stat))
{
crun_error_release (err);
return crun_make_error (err, errno, "error when using statfs on `%s`", CGROUP_ROOT "/freezer");
}

/* If the freezer is mounted as cgroupfs type, then missing
freezer.state file is an error and should be handled like before.
*/
if (freezer_stat.f_type == CGROUP_SUPER_MAGIC)
return ret;

/* When freezer dir is not mounted as cgroupfs, then it's
disabled, therefore container cannot be in paused state.
*/
crun_error_release (err);
*paused = false;
return 0;
}

*paused = strstr (content, state) != NULL;
return 0;
Expand Down
Loading