Commit Graph

5031 Commits

Author SHA1 Message Date
Sebastiaan van Stijn d6e892489f Fix build-tags in libcontainer/devices
Allows importing this package on Windows (for the types)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-03-14 19:11:19 +01:00
Kir Kolyshkin 249bca0a13 Merge pull request #2841 from AdamKorcz/fuzz1
tests: Move fuzzers upstream
2021-03-10 12:00:43 -08:00
Akihiro Suda 097062ae71 Merge pull request #2842 from kolyshkin/cpt-lazy-full-log
tests/checkpoint: show full log lazy pages cpt
2021-03-10 13:30:33 +09:00
AdamKorcz 2ae5665351 Move fuzzers upstream
Signed-off-by: AdamKorcz <adam@adalogics.com>
2021-03-09 10:07:11 +00:00
Kir Kolyshkin 053e15c001 tests/checkpoint: show full log lazy pages cpt
Sometimes the test fails without any clear diagnostics:

> not ok 16 checkpoint --lazy-pages and restore
> (in test file tests/integration/checkpoint.bats, line 191)
>  `[ "$out" = "0000000 000000 0000001" ]' failed
> ...
> criu failed: type NOTIFY errno 3\nlog file: work-dir/dump.log

We look for and print errors via grep, but in the above case
there are nothing that is denoted error in the log.

So, let's show the damn log in its entirely (note it is only shown
if test fails).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-08 15:04:40 -08:00
Kir Kolyshkin 59ad417c14 Merge pull request #2833 from kolyshkin/curl-retry
curl: add --retry 5
2021-03-05 20:00:53 -08:00
Mrunal Patel 497cd0c96e Merge pull request #2829 from KentaTada/refactor-mode-of-factory
libcontainer/factory*: adjust the file mode
2021-03-04 15:42:13 -08:00
Mrunal Patel 50ac158d05 Merge pull request #2809 from kolyshkin/rm-old-hacks
Makefile cleanups
2021-03-04 15:41:19 -08:00
Mrunal Patel 3742bfe891 Merge pull request #2824 from Iceber/fix-integration-tests-readme
fix integration tests README.md
2021-03-04 15:40:24 -08:00
Kir Kolyshkin e618a6d5ee curl: add --retry 5
Sometimes github gives up 5xx errors, for example:

> panic: getImages error exit status 1 (output: curl: (22) The requested URL returned error: 502
> Failed to get https://github.com/docker-library/busybox/raw/dist-i386/stable/glibc/busybox.tar.xz

This is unfortunate but temporary, and adding --retry should handle
at least some cases, improving CI stability.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-04 15:37:59 -08:00
Akihiro Suda d61ca65147 Merge pull request #2831 from cyphar/cyphar-email
MAINTAINERS: update Aleksa's email
2021-03-04 14:05:35 +09:00
Aleksa Sarai 4b98e4a73a MAINTAINERS: update Aleksa's email
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-03-04 10:38:35 +11:00
Kenta Tada 8a3484b736 libcontainer/factory*: adjust the file mode
This commit adjusts the file mode to use the latest golang style
Related to #2625

Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
2021-03-02 16:26:36 +09:00
Kir Kolyshkin 1820c42547 Merge pull request #2768 from kolyshkin/unit-386
ci/gha: add i386 unit test
2021-02-25 18:23:36 -08:00
Akihiro Suda d56a9c67ac Merge pull request #2812 from kolyshkin/memory-tight 2021-02-26 10:52:17 +09:00
Iceber Gu 71ca643213 fix integration tests README.md
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2021-02-26 02:23:44 +08:00
Akihiro Suda 8bddca5118 Merge pull request #2819 from Iceber/fix-comment
libcontainer: fix LinuxFactory comments
2021-02-25 18:08:04 +09:00
Mrunal Patel d11985a586 Merge pull request #2799 from kolyshkin/race1
Fix data races, enable testing with -race
2021-02-24 16:37:34 -08:00
Iceber Gu 916654fffa libcontainer: fix LinuxFactory comments
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2021-02-24 15:51:06 +08:00
Aleksa Sarai c153261830 merge branch 'pr-2786'
Daniel Dao (1):
  Do not convert blkio weight value using blkio->io conversion scheme

LGTMs: @kolyshkin @AkihiroSuda @cyphar
Closes #2786
2021-02-24 18:29:27 +11:00
Kir Kolyshkin 65116710dd Merge pull request #2757 from kolyshkin/test-int-cleanups
tests/int: cleanups
2021-02-23 20:50:17 -08:00
Daniel Dao c3ffd2ef81 Do not convert blkio weight value using blkio->io conversion scheme
bfq weight controller (i.e. io.bfq.weight if present) is still using the
same bfq weight scheme (i.e 1->1000, see [1].) Unfortunately the
documentation for this was wrong, and only fixed recently [2].

Therefore, if we map blkio weight to io.bfq.weight, there's no need to
do any conversion. Otherwise, we will try to write invalid value which
results in error such as:

```
time="2021-02-03T14:55:30Z" level=error msg="container_linux.go:367: starting container process caused: process_linux.go:495: container init caused: process_linux.go:458: setting cgroup config for procHooks process caused: failed to write \"7475\": write /sys/fs/cgroup/runc-cgroups-integration-test/test-cgroup/io.bfq.weight: numerical result out of range"
```

[1] https://github.com/torvalds/linux/blob/master/Documentation/block/bfq-iosched.rst
[2] https://github.com/torvalds/linux/commit/65752aef0a407e1ef17ec78a7fc31ba4e0b360f9

Signed-off-by: Daniel Dao <dqminh89@gmail.com>
2021-02-23 19:46:16 -08:00
Kir Kolyshkin 38b2dd391d runc exec: report possible OOM kill
An exec may fail due to memory shortage (cgroup memory limits being too
tight), and an error message provided in this case is clueless:

> $ sudo ../runc/runc exec xx56 top
> ERRO[0000] exec failed: container_linux.go:367: starting container process caused: read init-p: connection reset by peer

Same as the previous commit for run/start, check the OOM kill counter
and report an OOM kill.

The differences from run are

1. The container is already running and OOM kill counter might not be
   zero.  This is why we have to read the counter before exec and after
   it failed.

2. An unrelated OOM kill event might occur in parallel with our exec
   (and I see no way to find out which process was killed, except to
   parse kernel logs which seems excessive and not very reliable).
   This is why we report _possible_ OOM kill.

With this commit, the error message looks like:

> ERRO[0000] exec failed: container_linux.go:367: starting container process caused: process_linux.go:105: possibly OOM-killed caused: read init-p: connection reset by peer

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:16:33 -08:00
Kir Kolyshkin 5d0ffbf9c8 runc start/run: report OOM
In some cases, container init fails to start because it is killed by
the kernel OOM killer. The errors returned by runc in such cases are
semi-random and rather cryptic. Below are a few examples.

On cgroup v1 + systemd cgroup driver:

> process_linux.go:348: copying bootstrap data to pipe caused: write init-p: broken pipe

> process_linux.go:352: getting the final child's pid from pipe caused: EOF

On cgroup v2:

> process_linux.go:495: container init caused: read init-p: connection reset by peer

> process_linux.go:484: writing syncT 'resume' caused: write init-p: broken pipe

This commits adds the OOM method to cgroup managers, which tells whether
the container was OOM-killed. In case that has happened, the original error
is discarded (unless --debug is set), and the new OOM error is reported
instead:

> ERRO[0000] container_linux.go:367: starting container process caused: container init was OOM-killed (memory limit too low?)

Also, fix the rootless test cases that are failing because they expect
an error in the first line, and we have an additional warning now:

> unable to get oom kill count" error="no directory specified for memory.oom_control

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:15:33 -08:00
Kir Kolyshkin 7e137b9044 libct/cg/fs2/hugetlb: use fscommon.GetValueByKey
This makes the code simpler and more future-proof, in case
any more values will appear in hugetlb.*.events.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 9fa65f6607 libct/cg/fscommon: add GetValueByKey
Generalize the libct/getValueFromCgroup() as fscommon.GetValueByKey(),
and document it.

No changes other than using fscommon.ParseUint to convert the value.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin c54c3f852d libcontainer/notify_linux_v2: use fscommon.ReadFile
This is to benefit from openat2() implementation, on kernels
that support it. Theoretically this also improves security.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 494f900e91 libct/cg/fscommon: rename/facelift GetCgroupParamKeyValue
1. This is the only function in the package with Get prefix
   that does not read a file (but parses a string). Rename
   accordingly, and convert the callers.

	GetCgroupParamKeyValue -> ParseKeyValue

2. Use strings.Split rather than strings.Fields. Split by a space
   is 2x faster, plus we can limit the splitting. The downside is
   we have to strip a newline in one of the callers.

3. Improve the doc and the code flow.

4. Fix a test case with invalid data (spaces at BOL).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 1880d2fc05 libct/cg/fs/memory: handle EBUSY
EBUSY when trying to set memory limit may mean the new limit is too low
(lower than the current usage, and the kernel can't do anything).
Provide a more specific error for such case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 27fd3fc3ce libct/cg/fs: setMemoryAndSwap: refactor
1. Factor out setMemory and setSwap
2. Pass cgroup.Resources (rather than cgroup) to setMemoryAndSwap().
3. Merge the duplicated "set memory, set swap" case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 3cced523a5 libct/cg/fs/memory: optimize Set
Currently, we read and parse 5 different files while we only need 1.

Use GetCgroupParamUint() directly to get current limit.

While at it, remove the workaround previously needed for the unit test,
and make it a bit more verbose.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 65c2d3c2b6 tests/int/update: add test case for PR #592
Add integration test coverage for code initially added by commit
d8b8f76c4f ("Fix problem when update memory and swap memory",
2016-04-05).

This is in addition to existing unit test,
TestMemorySetSwapSmallerThanMemory.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Mrunal Patel f36d64d683 Merge pull request #2814 from kolyshkin/systemd-apply
libct/cgroups/systemd: don't set limits in Apply
2021-02-23 15:16:43 -08:00
Mrunal Patel e00273e09d Merge pull request #2816 from odinuge/cgroup-v2-cache
Fix memory stats for cache in fs2
2021-02-23 14:59:42 -08:00
Akihiro Suda f245b8c207 Merge pull request #2815 from hnts/update_readme 2021-02-23 22:12:42 +09:00
Ryosuke Hanatsuka 53d3b5524a Update README.md for libcontainer
Signed-off-by: Ryosuke Hanatsuka <hanatsuu@gmail.com>
2021-02-23 11:21:34 +09:00
Odin Ugedal 6c5ed0db3a Fix memory stats for cache in fs2
In cgroup v2, the "cache" value from cgroup v1 is called "file" in v2.
There are no values called "cache" in v2.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/memcontrol.c?id=31caf8b2a847214be856f843e251fc2ed2cd1075#n1521
Signed-off-by: Odin Ugedal <odin@uged.al>
2021-02-22 12:27:12 +01:00
Kir Kolyshkin ee06c700dc Merge pull request #2804 from Iceber/filemode
libcontainer: fix the file mode of the device
2021-02-22 00:57:21 -08:00
Kir Kolyshkin af521ed580 libct/cgroups/systemd: don't set limits in Apply
All cgroup managers has Apply() and Set() methods:

 - Apply is used to create a cgroup (and, in case of systemd,
   a systemd unit) and/or put a PID into the cgroup (and unit);

 - Set is used to set various cgroup resources and limits.

The fs/fs2 cgroup manager implements the functionality as described above.

The systemd v1/v2 manager deviate -- it sets *most* of cgroup limits
(those that can be projected to systemd unit properties) in Apply(),
and then again *all* cgroup limits in Set (first indirectly via systemd
properties -- same as in Apply, then via cgroupfs).

This commit removes setting the cgroup limits from Apply,
so now the systemd manager behaves the same way as the fs manager.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-19 18:53:24 -08:00
Iceber Gu fa52df9493 libcontainer: fix the file mode of the device
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2021-02-17 15:08:22 +08:00
Kir Kolyshkin d0cbef576f Makefile: rm go 1.13 workaround
Since go 1.14, mod=vendor is used automatically. Since go 1.16 is now
released, and minimally supported go version is 1.15.

As per commit fbeed5228, remove the go 1.13 workaround.

Fix README to require go 1.14.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 18:58:55 -08:00
Kir Kolyshkin 4019f08d68 make validate: rm go vet
As we already run go vet during CI (via golangci-lint) let's not run it
again.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 18:58:55 -08:00
Kir Kolyshkin f9c2113331 make lint: use golangci-lint
Instead of running just a couple of linters, use the same set as we run
on CI.

NOTE that this is for developers, not scripts, and requires having
golangci-lint installed (see
https://golangci-lint.run/usage/install/#local-installation).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 18:58:55 -08:00
Kir Kolyshkin 671bb97825 Makefile: remove ci target
It is not used since commit e431fe60f8.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 18:58:55 -08:00
Kir Kolyshkin 9594085573 script/validate-gofmt: rm
Add gofmt to golangci-lint configuration, and remove the script
which ran gofmt.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 18:58:55 -08:00
Akihiro Suda f245a1d1ed Merge pull request #2808 from kolyshkin/go116-final 2021-02-17 10:50:03 +09:00
Mrunal Patel 06c1cd8896 Merge pull request #2806 from kolyshkin/readme-gha-badges
README: add gha badges
2021-02-16 14:50:30 -08:00
Kir Kolyshkin 91f0ae1884 ci/gha: bump go 1.16-rc1 -> 1.16.x
As the final go 1.16 is released, rc1 is no longer available.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 12:30:05 -08:00
Kir Kolyshkin 5b14a26164 README: add gha badges
Note that validate currently fails on master -- this is tracked
in https://github.com/opencontainers/runc/issues/2627.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-10 14:39:27 -08:00
Mrunal Patel 824e4ad3b8 Merge pull request #2803 from AkihiroSuda/fix-arch-apparmor
apparmor: try attr/apparmor/exec before attr/exec
2021-02-10 10:29:13 -08:00