diff options
author | Fabricio Voznika <fvoznika@google.com> | 2021-02-22 15:54:58 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-02-22 15:57:07 -0800 |
commit | 34e2cda9ad6a20861844776abfbb45052d20c3fa (patch) | |
tree | 42e22747194d006da90c6270b37815bbf97c0837 /runsc/cgroup | |
parent | fed1cc6d8c90e53bb9819b515d9d5b8bf4ec166e (diff) |
Return nicer error message when cgroups v1 isn't available
Updates #3481
Closes #5430
PiperOrigin-RevId: 358923208
Diffstat (limited to 'runsc/cgroup')
-rw-r--r-- | runsc/cgroup/BUILD | 1 | ||||
-rw-r--r-- | runsc/cgroup/cgroup.go | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/runsc/cgroup/BUILD b/runsc/cgroup/BUILD index 37f4253ba..f7e892584 100644 --- a/runsc/cgroup/BUILD +++ b/runsc/cgroup/BUILD @@ -11,6 +11,7 @@ go_library( "//pkg/log", "@com_github_cenkalti_backoff//:go_default_library", "@com_github_opencontainers_runtime_spec//specs-go:go_default_library", + "@org_golang_x_sys//unix:go_default_library", ], ) diff --git a/runsc/cgroup/cgroup.go b/runsc/cgroup/cgroup.go index 797c1c2bc..ac9e4e3a8 100644 --- a/runsc/cgroup/cgroup.go +++ b/runsc/cgroup/cgroup.go @@ -32,6 +32,7 @@ import ( "github.com/cenkalti/backoff" specs "github.com/opencontainers/runtime-spec/specs-go" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/cleanup" "gvisor.dev/gvisor/pkg/log" ) @@ -59,6 +60,16 @@ var controllers = map[string]config{ "systemd": {ctrlr: &noop{}}, } +// IsOnlyV2 checks whether cgroups V2 is enabled and V1 is not. +func IsOnlyV2() bool { + var stat unix.Statfs_t + if err := unix.Statfs(cgroupRoot, &stat); err != nil { + // It's not used for anything important, assume not V2 on failure. + return false + } + return stat.Type == unix.CGROUP2_SUPER_MAGIC +} + func setOptionalValueInt(path, name string, val *int64) error { if val == nil || *val == 0 { return nil |