Commit Graph

1744 Commits

Author SHA1 Message Date
Xiaochen Shen f62ad4a0de libcontainer/intelrdt: rename CAT and MBA enabled flags
Rename CAT and MBA enabled flags to be consistent with others.
No functional change.

Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
2020-11-10 15:32:01 +08:00
Akihiro Suda fb59e6f726 Merge pull request #2583 from adrianreber/join-more-namespaces
restore: tell CRIU to use existing namespaces
2020-11-10 00:19:40 +09:00
Mrunal Patel 27227a9358 Merge pull request #2669 from kolyshkin/systemd-unified
Initial v2 resources.unified systemd support
2020-11-06 12:31:31 -08:00
Giuseppe Scrivano 41aa764010 linux: drop MS_REC for readonly remount
it has no effect.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-11-06 11:36:50 +01:00
Giuseppe Scrivano a4e6955e31 linux: fix remount readonly in a user namespace
if we are remounting root read only when in a user namespace, make
sure the existing flags (e.g. MS_NOEXEC, MS_NODEV) are maintained
otherwise the mount fails with EPERM.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-11-06 11:35:40 +01:00
Kir Kolyshkin 2e968a833f libct/cg/sd/v2: "support" (ignore) memory.oom.group
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:05:02 -08:00
Kir Kolyshkin 13afa58d0e libct/cg/sd/v2: support cpuset.* / Allowed*
* cpuset.cpus -> AllowedCPUs
 * cpuset.mems -> AllowedMemoryNodes

No test for cgroup v2 resources.unified override, as this requires a
separate test case, and all the unified resources are handled uniformly
so there's little sense to test all parameters.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:57 -08:00
Kir Kolyshkin 5be8b97aec libct/cg/sd/v2: support cpu.weight / CPUWeight
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:46 -08:00
Kir Kolyshkin ab80eb32d2 libct/cg/sd/v2: support cpu.max unified resource
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:37 -08:00
Kir Kolyshkin fd5226d0eb libct/cg/sd: add defCPUQuotaPeriod
Un-inline defCPUQuotaPeriod constant. To be used by the next commit.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:27 -08:00
Kir Kolyshkin 0cb8bf67a3 Initial v2 resources.unified systemd support
In case systemd is used as cgroups manager, and a user sets some
resources using unified resource map (as per [1]), systemd is not
aware of any parameters, so there will be a discrepancy between
the cgroupfs state and systemd unit state.

Let's try to fix that by converting known unified resources to systemd
properties.

Currently, this is only implemented for pids.max as a POC.

Some other parameters (that might or might not have systemd unit
property equivalents) are:

$ ls -l | grep w-
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.freeze
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.max.depth
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.max.descendants
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.procs
-rw-r--r--. 1 root root 0 Oct 21 09:43 cgroup.subtree_control
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.threads
-rw-r--r--. 1 root root 0 Oct 10 13:57 cgroup.type
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpu.max
-rw-r--r--. 1 root root 0 Oct 10 13:57 cpu.pressure
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpuset.cpus
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpuset.cpus.partition
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpuset.mems
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpu.weight
-rw-r--r--. 1 root root 0 Oct 22 10:30 cpu.weight.nice
-rw-r--r--. 1 root root 0 Oct 22 10:30 hugetlb.1GB.max
-rw-r--r--. 1 root root 0 Oct 22 10:30 hugetlb.1GB.rsvd.max
-rw-r--r--. 1 root root 0 Oct 22 10:30 hugetlb.2MB.max
-rw-r--r--. 1 root root 0 Oct 22 10:30 hugetlb.2MB.rsvd.max
-rw-r--r--. 1 root root 0 Oct 22 10:30 io.bfq.weight
-rw-r--r--. 1 root root 0 Oct 22 10:30 io.latency
-rw-r--r--. 1 root root 0 Oct 22 10:30 io.max
-rw-r--r--. 1 root root 0 Oct 10 13:57 io.pressure
-rw-r--r--. 1 root root 0 Oct 22 10:30 io.weight
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.high
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.low
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.max
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.min
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.oom.group
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.pressure
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.swap.high
-rw-r--r--. 1 root root 0 Oct 10 13:57 memory.swap.max

Surely, it is a manual conversion for every such case...

[1] https://github.com/opencontainers/runtime-spec/pull/1040

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-05 16:04:19 -08:00
Aleksa Sarai 8d860c69ad merge branch 'pr-2634'
Cory Bennett (1):
  don't panic when /sys/fs/cgroup is missing for rootless

LGTMs: @AkihiroSuda @cyphar
Closes #2634
2020-10-29 15:59:01 +11:00
Akihiro Suda 9d4c02cf29 Merge pull request #2570 from EduardoVega/2246-fix-chmod-ro-tmpfs-mount
Fix mount error when chmod RO tmpfs
2020-10-26 18:19:16 +09:00
Akihiro Suda 6a28ca3eb4 Merge pull request #2661 from kinvolk/mauricio/fix-unit-test-in-libcontainer-exec
libcontainer/integration: fix unit test
2020-10-26 16:12:59 +09:00
Akihiro Suda 75201f34ed Merge pull request #2653 from xiaochenshen/rdt-IntelRdtManager-refactoring
libcontainer/intelrdt: IntelRdtManager refactoring
2020-10-25 19:00:31 +09:00
Mauricio Vásquez ac5ec5e32f libcontainer/integration: fix unit test
Fix a merge issue between 0aa0fae393 ("Kill all processes in cgroup even if init process Wait fails")
& 73d93eeb01 ("libct/int: make newTemplateConfig argument a struct") that
resulted in passing the wrong datatype to newTemplateConfig in
TestPIDHostInitProcessWait.

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
2020-10-23 07:56:11 -05:00
Mrunal Patel 07e35a7a40 Merge pull request #2600 from kolyshkin/libct-int-wut
libcontainer/integration: fix cgroupv1 + systemd tests
2020-10-22 21:05:15 -07:00
Mrunal Patel 10e5ab7966 Merge pull request #2635 from kolyshkin/fscommon-III
libct/cg: introduce and use fscommon.OpenFile
2020-10-22 20:59:56 -07:00
Kir Kolyshkin 8631de4132 Merge pull request #2652 from SataQiu/fix-20201016
Fix some typos about libcontainer
2020-10-21 10:15:21 -07:00
Mrunal Patel 7ba005bbd3 Merge pull request #2647 from cyphar/procfs-masking-nested
rootfs: handle nested procfs mounts for MS_MOVE
2020-10-19 14:56:34 -07:00
Xiaochen Shen 933c4d31a7 libcontainer/intelrdt: privatize IntelRdtManager and its fields
No functional change.

Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
2020-10-17 16:59:42 +08:00
Xiaochen Shen 2c004a101e libcontainer/intelrdt: introduce NewManager()
Introduce NewManager() to wrap up IntelRdtManager initialization. And
call it when required.

Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
2020-10-17 16:59:20 +08:00
SataQiu abcc1aae05 fix some typos about libcontainer
Signed-off-by: SataQiu <1527062125@qq.com>
2020-10-17 13:14:55 +08:00
Cory Bennett 939ad4e3fc don't panic when /sys/fs/cgroup is missing for rootless
Signed-off-by: Cory Bennett <cbennett@netflix.com>
2020-10-15 15:52:19 +00:00
Aleksa Sarai b8bf572812 rootfs: handle nested procfs mounts for MS_MOVE
In a case where the host /proc mount has already been overmounted, the
MS_MOVE handling would get ENOENT when trying to hide (for instance)
"/proc/bus" because it had already hidden away "/proc". This revealed
two issues in the previous implementation of this hardening feaure:

1. No checks were done to make sure the mount was a "full" mount (it is
   a mount of the root of the filesystem), but the kernel doesn't permit
   a non-full mount to be converted to a full mount (for reference, see
   mnt_already_visible). This just removes extra busy-work during setup.

2. ENOENT was treated as a critical error, even though it actually
   indicates the mount doesn't exist and thus isn't a problem. A more
   theoretically pure solution would be to store the set of mountpoints
   to be hidden and only ignore the error if an ancestor directory of
   the current mountpoint was already hidden, but that would just add
   complexity with little justification.

In addition, better document the reasoning behind this logic so that
folks aren't confused when looking at it.

Fixes: 28a697cce3 ("rootfs: umount all procfs and sysfs with --no-pivot")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2020-10-13 20:54:56 +11:00
Xiaochen Shen 5903b0cec3 libcontainer/intelrdt: remove 'omitempty' property from CMT and MBM counters
If the values of CMT and MBM counters are zero, they will be omitted as
empty items when getting Intel RDT stats.

Remove 'omitempty' property from CMT and MBM counters to display zero
values.

Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
2020-10-12 22:04:37 +08:00
Kir Kolyshkin 44f221e2fc Merge pull request #2633 from chaitanyabandi/2632-fix
Kill processes in cgroup even if process Wait fails
2020-10-08 10:51:13 -07:00
Mrunal Patel 10825f70d3 Merge pull request #2631 from knabben/fix-some-lints
Fixing some lint issues
2020-10-07 21:24:40 -07:00
Chaitanya Bandi 0aa0fae393 Kill all processes in cgroup even if init process Wait fails
If the cgroup's init process doesn't complete successfully, Wait returns a
non-nil error. We should still kill all the process in the cgroup if process
namespace is shared. Otherwise, it may result in process leak.

Fixes #2632

Signed-off-by: Chaitanya Bandi <kbandi@cs.stonybrook.edu>
2020-10-08 01:26:34 +00:00
Kir Kolyshkin de77b5b39f Merge pull request #2630 from aos/2582-rootless-systemd-dbus-friendly-error
Rootless systemd dbus friendlier error
2020-10-06 12:43:17 -07:00
Amim Knabben 978fa6e906 Fixing some lint issues
Signed-off-by: Amim Knabben <amim.knabben@gmail.com>
2020-10-06 14:44:14 -04:00
Akihiro Suda bb539a9965 Merge pull request #2628 from thaJeztah/linting_foo
fix some linting issues
2020-10-06 20:10:40 +09:00
Kir Kolyshkin f0fdde79d2 libct/cg/systemd/v1: fix err check in enableKmem
Commit 27d3dd3df3 ("don't fail when subsystem not mounted") added
ignoring "not found" error to enableKmem, and as a result the function
now tries to call Mkdir with an empty path, which results in a weird
error message. For example, this is a failure from a
libcontainer/integration test:

> === RUN   TestRunWithKernelMemorySystemd
>    exec_test.go:704: runContainer failed with kernel memory limit: container_linux.go:370: starting container process caused: process_linux.go:327: applying cgroup configuration for process caused: mkdir : no such file or directory

I am not entirely sure if it is a good idea to silently ignore set
limits, but at least let's fix the error handling.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 20:51:02 -07:00
Kir Kolyshkin c1bba720f7 libct/cg/systemd/v1: do not use c.Path
Commit a1d5398afa ("Respect container's cgroup path") added a
cgroupPath argument to FindCgroupMountpoint to make runc/libcontainer
work in a custom multitenant environment with multiple cgroup mount
points.

It also added passing c.Path as an argument to FindCgroupMountpoint
for systemd (v1) controller. This is wrong, because

1. systemd controller do not use c.Path at all (and c.Path is never set
   by specconv) -- instead, it uses Name and Parent.

2. c.Path, if set, is not absolute -- it is relative to /sys/fs/cgroup
   -- but it is used as an absolute path here.

Since c.Path is never set, the change did not result in any breakage, so
this code sit quietly for some time and the issue might not have been
discovered -- until we started running libcontainer/integration tests
in a CentOS 7 VM, which resulted in a following weird error:

> FAIL: TestPidsSystemd: utils_test.go:55: exec_test.go:630: unexpected error: container_linux.go:353: starting container process caused: process_linux.go:326: applying cgroup configuration for process caused: mountpoint for devices not found

The error was "fixed" in commit f57bb2fe3d by changing the tests'
cgroups Path to be "/sys/fs/cgroup/". This actually resulted in
creation of cgroup directories like /sys/fs/cgroup/memory/sys/fs/cgroup,
/sys/fs/cgroup/devices/sys/fs/cgroup and so on.

The proper fix to the test case is implemented in the previous commit,
which sets c.Name and c.Parent.

This commit just removes the invalid use of c.Path, and tells the whole
story.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 20:51:02 -07:00
Kir Kolyshkin fa47f95872 libct/int/newTemplateConfig: add systemd support
... and properly set ScopePrefix, Name and Parent for a systemd case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 20:51:02 -07:00
Kir Kolyshkin 9135d99c94 libct/int/newTemplateConfig: add userns param
It seems that a few tests add a cgroup mount in case userns is not set.
Let's do it inside newTemplateConfig() for all tests.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 20:51:02 -07:00
Kir Kolyshkin 73d93eeb01 libct/int: make newTemplateConfig argument a struct
...so we can add more fields later.

This commit is mostly courtesy of

sed -i 's/newTemplateConfig(rootfs)/newTemplateConfig(\&tParam{rootfs: rootfs})/g'

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 20:51:02 -07:00
Eduardo Vega fb4c27c4b7 Fix mount error when chmod RO tmpfs
Signed-off-by: Eduardo Vega <edvegavalerio@gmail.com>
2020-10-05 21:23:30 -06:00
Kir Kolyshkin 002c92f1b2 libct/cg.WriteCgroupProc: use fscommon.OpenFile
...and drop os.O_CREATE|os.O_TRUNC as those are definitely not needed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 17:08:09 -07:00
Kir Kolyshkin c95e69007c libct/cg/fs*: use fscommon.OpenFile
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 17:08:09 -07:00
Kir Kolyshkin d55729f140 libct/cg/fs/blkio: use fscommon.OpenFile
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 17:08:09 -07:00
Kir Kolyshkin 0228226e6d libcontainer/cgroups/fscommon: introduce OpenFile
Move the functionality of opening a cgroup file into a separate
function, OpenFile, which, similar to ReadFile and WriteFile,
use separate dir and file arguments.

Change ReadFile and WriteFile to rely on OpenFile, and use lower-level
read and write instead of ones from ioutil.

It changes the semantics of WriteFile a bit -- it no longer uses
O_CREAT flag. This is good for real cgroup as there is no need to try
creating the files in there, but can potentially break WriteFile users
-- previously, EPERM error was returned for non-existing files, and
now it's ENOENT.

This also breaks the fs/fs2 unit tests since they write to pseudo-cgroup
files inside a test directory (not to a real cgroup fs), and now
fscommon.WriteFile do not create or truncate files, so we have to add a
variable that is set by the unit tests.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 17:08:09 -07:00
Aos Dabbagh b448330514 Add error message
* Updated cgroups-v2 documentation to mention dbus-user-session requirement
* Added friendlier error message

Signed-off-by: Aos Dabbagh <aosdab@gmail.com>
2020-10-05 17:08:07 -04:00
Kir Kolyshkin e25b8cfcd5 libct/cg/utils: use fscommon.ReadFile
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 14:07:57 -07:00
Kir Kolyshkin 6bae53f589 libct/cg/fs2: use fscommon.ReadFile
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 14:07:15 -07:00
Kir Kolyshkin 2588e6f1b8 libct/cg/fs/cpuset: use fscommon.ReadFile
While at it,

 - change some functions to not be methods of CpusetCgroup as
   they don't use any members;
 - simplify isEmpty.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 14:07:15 -07:00
Kir Kolyshkin 1d20cf49f1 libct/cg/fs/cpuacct: use fscommon.ReadFile
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 14:07:15 -07:00
Kir Kolyshkin 9e78b66e88 libct/cg/systemd/v1.enableKmem: use fscommon.ReadFile
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 14:07:15 -07:00
Kir Kolyshkin 316344364c libct/cg/fs2.CreateCgroupPath: use fscommon.*File
fscommon's ReadFile and WriteFile are tailored to cgroupfs,
so let's use them here.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 14:07:15 -07:00
Kir Kolyshkin b7092d84ee libct/cg/fs.setKernelMemory: use fscommon.WriteFile
fscommon.WriteFile is added specifically to work with cgroup files,
and the error it returns does not need to be wrapped.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 14:07:15 -07:00