runc/libcontainer/cgroups
Kir Kolyshkin 714c91e9f7 Simplify cgroup path handing in v2 via unified API
This unties the Gordian Knot of using GetPaths in cgroupv2 code.

The problem is, the current code uses GetPaths for three kinds of things:

1. Get all the paths to cgroup v1 controllers to save its state (see
   (*linuxContainer).currentState(), (*LinuxFactory).loadState()
   methods).

2. Get all the paths to cgroup v1 controllers to have the setns process
    enter the proper cgroups in `(*setnsProcess).start()`.

3. Get the path to a specific controller (for example,
   `m.GetPaths()["devices"]`).

Now, for cgroup v2 instead of a set of per-controller paths, we have only
one single unified path, and a dedicated function `GetUnifiedPath()` to get it.

This discrepancy between v1 and v2 cgroupManager API leads to the
following problems with the code:

 - multiple if/else code blocks that have to treat v1 and v2 separately;

 - backward-compatible GetPaths() methods in v2 controllers;

 -  - repeated writing of the PID into the same cgroup for v2;

Overall, it's hard to write the right code with all this, and the code
that is written is kinda hard to follow.

The solution is to slightly change the API to do the 3 things outlined
above in the same manner for v1 and v2:

1. Use `GetPaths()` for state saving and setns process cgroups entering.

2. Introduce and use Path(subsys string) to obtain a path to a
   subsystem. For v2, the argument is ignored and the unified path is
   returned.

This commit converts all the controllers to the new API, and modifies
all the users to use it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-08 12:04:06 -07:00
..
ebpf test: update devicefilter tests 2020-05-08 07:31:05 +01:00
fs Simplify cgroup path handing in v2 via unified API 2020-05-08 12:04:06 -07:00
fs2 Simplify cgroup path handing in v2 via unified API 2020-05-08 12:04:06 -07:00
fscommon cgroups/fscommon: use errors.Is 2020-04-18 16:16:49 -07:00
systemd Simplify cgroup path handing in v2 via unified API 2020-05-08 12:04:06 -07:00
cgroups.go Simplify cgroup path handing in v2 via unified API 2020-05-08 12:04:06 -07:00
cgroups_test.go .travis.yml: add Fedora 31 vagrant box (for cgroup2) 2019-10-31 16:53:01 +09:00
cgroups_unsupported.go Move libcontainer into subdirectory 2015-06-21 19:29:15 -07:00
stats.go Exposing memory.numa_stats 2020-04-08 17:40:09 +02:00
utils.go let runc disable swap in cgroup v2 2020-05-03 20:57:36 +08:00
utils_test.go cgroupv2: fix setting MemorySwap 2020-04-07 20:45:53 -07:00