Commit Graph

5399 Commits

Author SHA1 Message Date
Kir Kolyshkin a7cfb23b88 *: stop using pkg/errors
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin b60e2edf75 libct/cg: stop using pkg/errors
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin a6cc36a836 libct/cg/ebpf: stop using pkg/errors
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin f137aaa2c8 libct/cg/devices: stop using pkg/errors
Use Go native errors wrapping.

Introduce wrapErr helper to minimise the patch size.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin ebb0812886 .golangci.yml: enable errorlint
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin 56e478046a *: ignore errorlint warnings about unix.* errors
Errors from unix.* are always bare and thus can be used directly.

Add //nolint:errorlint annotation to ignore errors such as these:

libcontainer/system/xattrs_linux.go:18:7: comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
	case errno == unix.ERANGE:
	     ^
libcontainer/container_linux.go:1259:9: comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
					if e != unix.EINVAL {
					   ^
libcontainer/rootfs_linux.go:919:7: comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
			if err != unix.EINVAL && err != unix.EPERM {
			   ^
libcontainer/rootfs_linux.go:1002:4: switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors (errorlint)
			switch err {
			^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin f6a0899b7f *: use errors.As and errors.Is
Do this for all errors except one from unix.*.

This fixes a bunch of errorlint warnings, like these

libcontainer/generic_error.go:25:15: type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
	if le, ok := err.(Error); ok {
	             ^
libcontainer/factory_linux_test.go:145:14: type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
	lerr, ok := err.(Error)
	            ^
libcontainer/state_linux_test.go:28:11: type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
	_, ok := err.(*stateTransitionError)
	         ^
libcontainer/seccomp/patchbpf/enosys_linux.go:88:4: switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors (errorlint)
			switch err {
			^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin 5d2a11ad2e tty.go: don't use pkg/errors, use errors.Is
Instead of using errors.Wrap, use fmt.Errorf with %w for error wrapping.

Also, use errors.Is instead of direct error comparison.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin c6fed264da libct/keys: stop using pkg/errors
Use fmt.Errorf with %w instead.

Convert the users to the new wrapping.

This fixes an errorlint warning.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin adbac31d88 libct: fix errorlint warning about strconv.NumError
This one is tough as errorlint insists on using errors.Is, and the
latter is known to not work for Go 1.13 which we still support.

So, add a nolint annotation to suppress the warning, and a TODO to
address it later.

For intelrdt, we can do the same, but it is easier to reuse the very
same function from fscommon (note we can't use fscommon for other stuff
as it expects cgroupfs).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin 7be93a66b9 *: fmt.Errorf: use %w when appropriate
This should result in no change when the error is printed, but make the
errors returned unwrappable, meaning errors.As and errors.Is will work.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin d8ba4128b2 libct/rootfs: improve some errors
Errors from os.Open, os.Symlink etc do not need to be wrapped, as they
are already wrapped into os.PathError.

Error from unix are bare errnos and need to be wrapped. Same
os.PathError is a good candidate.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin 36aefad45d libct: wrap unix.Mount/Unmount errors
Errors returned by unix are bare. In some cases it's impossible to find
out what went wrong because there's is not enough context.

Add a mountError type (mostly copy-pasted from github.com/moby/sys/mount),
and mount/unmount helpers. Use these where appropriate, and convert error
checks to use errors.Is.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:37 -07:00
Kir Kolyshkin 825335b2b7 libct/cg/fs2: fix/unify parsing errors
This builds on top of recently introduced fscommon.ParseError.

Errors returned from parsers (mostly ones used by GetStats()) are all
different, and many are incomplete. For example, in many cases errors
from strconv.ParseUint are returned as is, meaning there is no context
telling which file we were reading. Similarly, errors from
fscommon.ParseKeyValue should be wrapped to add more context.
Same is true for scanner.Err().

OTOH, errors from fscommon.GetCgroup* do have enough context and there
is no need to wrap them.

Fix all the above.

While at it, add missing scanner.Err() checks.

[v2: use parseError, not ParseError]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 12:00:54 -07:00
Kir Kolyshkin 5a186d390f libct/cg/fs: fix/unify parsing errors
This builds on top of recently introduced fscommon.ParseError.

Errors returned from parsers (mostly ones used by GetStats()) are all
different, and many are incomplete. For example, in many cases errors
from strconv.ParseUint are returned as is, meaning there is no context
telling which file we were reading. Similarly, errors from
fscommon.ParseKeyValue should be wrapped to add more context.
Same is true for scanner.Err().

One special case that repeats a few times is "malformed line: xxx".
Add and use a helper for that to simplify things.

OTOH, errors from fscommon.GetCgroup* do have enough context and there
is no need to wrap them.

Fix all the above.

While at it, add a missing scanner.Err() check.

[v2: use parseError not ParseError]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:59:54 -07:00
Kir Kolyshkin f813174d5e libct/cg/fscommon: introduce and use ParseError
1. Introduce ParseError type as a way to unify error messages related to
   file parsing. Use it from GetCgroup* functions.

2. Do not discard the error from strconv.Parse{Int,Uint} -- it contains
   the value being parsed, and the details about the error.

2. As the error above already contains the value, drop it from format.

[v2: use path.Join in Error]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:52:26 -07:00
Kir Kolyshkin adcd3b4451 libct/cg/fs[2]: simplify getting pid stats
1. Do not wrap errors returned from fscommon.GetCgroupParamUint -- those
   errors already have enough context.

2. Instead of parsing "max" ourselves, use GetCgroupParamUint which does
   it, and then convert MaxUint64 to 0 (we do it historically since
   commit 087b953dc5, and while using MaxUint64 as is seems fine,
   there may be some existing users who rely on the old behavior).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:44:31 -07:00
Kir Kolyshkin 4e33094277 libct/cg/fs/stats_util_test: fix errors
1. No \n needed in t.Errorf/t.Fatalf.

2. Some cosmetic changes.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:44:12 -07:00
Kir Kolyshkin 563225d55f libct/StartInitialization: fix errors
Errors from strconv.Atoi are already descriptive enough, and contain the
value being converted, so our error messages do not need to contain it.

While at it, use %w to wrap errors.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:43:44 -07:00
Kir Kolyshkin 3fee59f9da libct/cg/fs/*_test: simplify errors
The error from fscommon.GetCgroup* already contains the file name and so
on, so there's no need to wrap it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:43:24 -07:00
Kir Kolyshkin fdf4e90e89 libct/cg/fscommon.ParseKeyValue: no need to wrap err
The error returned from strconv.ParseUint is already pretty descriptive,
something like:

	strconv.ParseUint: parsing "000d": invalid syntax

So, there is no need to add more context to it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:42:59 -07:00
Kir Kolyshkin 627a06ad92 Replace fmt.Errorf w/o %-style to errors.New
Using fmt.Errorf for errors that do not have %-style formatting
directives is an overkill. Switch to errors.New.

Found by

	git grep fmt.Errorf | grep -v ^vendor | grep -v '%'

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:42:07 -07:00
Kir Kolyshkin 242b3283fd libct/cg/fscommon: rm unused var
It is not used since commit 494f900e91

Fixes: 494f900e91
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:42:00 -07:00
Kir Kolyshkin 92e8d9b91a libct/intelrdt: error message nits
An errror from ioutil.WriteFile already contains file name, so there is
no need to duplicate that information.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:41:41 -07:00
Aleksa Sarai 2fc269d7af merge branch 'pr-2971'
Aleksa Sarai (2):
  VERSION: release runc 1.0.0
  VERSION: back to development

LGTMs: cyphar hqhq AkihiroSuda kolyshkin thaJeztah
Closes #2971
2021-06-22 16:01:02 +10:00
Aleksa Sarai 9f93778291 merge branch 'pr-3032'
Kir Kolyshkin (4):
  exec: rm --no-subreaper flag
  runc update: hide --kernel* options
  runc --help: improve log options description
  man/*: revamp

LGTMs: cyphar mrunalp AkihiroSuda
Closes #3032
2021-06-18 17:22:54 +10:00
Aleksa Sarai 041caf107f VERSION: back to development
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-06-17 18:11:39 +10:00
Aleksa Sarai 84113eef6f VERSION: release runc 1.0.0
🎉

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
v1.0.0
2021-06-17 18:11:36 +10:00
Aleksa Sarai 47d37b33cd merge branch 'pr-3022'
Kir Kolyshkin (3):
  libct/cg/fs/blkio: do not set weight == 0
  libct/cg/fs2: set per-device io weight if available
  tests/int/cgroups: add test for bfq per-device weight

LGTMs: AkihiroSuda mrunalp cyphar
Closes #3022
2021-06-17 17:50:36 +10:00
Kir Kolyshkin dfc0f0695a man/*: revamp
Current runc man pages are ugly (no proper man page formatting)
and very short (mostly just a copy-paste from the "runc <command>
--help" output. They are also somewhat obsoleted as not all CLI updates
were propagated to man/*.

This commits makes the first step to solving this.

In short:
 - added some more information about some options;
 - lots of formatting fixes;
 - use references to other man pages and web pages;
 - fix SYNOPSYS (formatting, mostly);
 - removed the repeated description of <container_id> from every page;
 - added SEE ALSO;
 - something else I forgot.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-16 12:42:06 -07:00
Kir Kolyshkin 2916817278 tests/int/cgroups: add test for bfq per-device weight
This works for both cgroup v1 and v2.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-16 04:51:40 -07:00
Kir Kolyshkin 1036f3f995 libct/cg/fs2: set per-device io weight if available
Per-device weight is supported since kernel v5.4 (kernel commit
795fe54c2a8), so let's set those if supplied.

[v2: implement a more relaxed check in bfqDeviceWeightSupported]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-16 04:51:19 -07:00
Kir Kolyshkin e8bd33ae28 runc --help: improve log options description
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-15 17:49:56 -07:00
Kir Kolyshkin cf4ecaed08 runc update: hide --kernel* options
Commit 52390d6804 made this parameters obsoleted, but they are
still shown in e.g. runc update --help output.

Hide them (and maybe in 5 years we can remove them).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-15 17:48:40 -07:00
Kir Kolyshkin 4065c394a3 exec: rm --no-subreaper flag
This was removed from runc exec by commit f61c6e413f about 5 years ago,
so it's time to remove it entirely.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-15 15:40:10 -07:00
Kir Kolyshkin 30d83d4d2f libct/cg/fs/blkio: do not set weight == 0
For per-device weight, you can set weight and/or leaf weight.
The problem is, with the recent fix to use BFQ on cgroup v1,
if per-device weights are set, the code tries to set device
weight to blkio.bfq.weight, and the leaf weight to
blkio.leaf_weight_device. The latter file does not exist on
kernels v5.0, meaning one can not set any per-device weights
at all.

The fix is to only set weights if they are non-zero (i.e. set).

The test case will come in a following commit.

Fixes: 6339d8a0dd
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-14 12:52:30 -07:00
Kir Kolyshkin f093cca13d Merge pull request #3024 from kolyshkin/fscommon-mv
libct/cg: mv fscommon.{Open,Read,Write}File to cgroups
2021-06-14 12:49:18 -07:00
Kir Kolyshkin 8726c701a1 Merge pull request #3017 from wzshiming/fix/setenv
Returns clearer error message for Setenv
2021-06-14 11:13:13 -07:00
Akihiro Suda c4359f8e7d Merge pull request #3005 from adrianreber/2021-06-07-lsm-profile 2021-06-15 01:16:43 +09:00
Kir Kolyshkin d7fc302860 libct/cg/fs*: mark {Open,Read,Write}File as deprecated
... and switch to using the ones from cgroups.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-13 17:17:48 -07:00
Kir Kolyshkin 8f1b4d4a6f libct/cg: mv fscommon.{Open,Read,Write}File to cgroups
This is a better place as cgroups itself is using these.
Should help with moving more stuff common in between fs and fs2 to
fscommon.

Looks big, but this is just moving the code around:

 fscommon/{fscommon,open}.go -> cgroups/file.go
 fscommon/fscommon_test.go   -> cgroups/file_test.go

and fixes for TestMode moved to a different package.

There's no functional change.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-13 12:38:21 -07:00
Shiming Zhang 322c8fd36b Returns clearer error message for setenv
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
2021-06-12 14:32:48 +08:00
Mrunal Patel 93a01cd4d0 Merge pull request #3009 from AkihiroSuda/update-ebpf-wrap
update cilium/ebpf to fix haveBpfProgReplace() check
2021-06-11 15:38:01 -04:00
Mrunal Patel a3813ca249 Merge pull request #3000 from kolyshkin/test-dev-update
libct/int: add device update test
2021-06-11 14:36:49 -04:00
Kir Kolyshkin 0ca4cdad35 Merge pull request #3010 from askervin/5D6_blkio_bfq_weight
libcontainer/cgroups/fs/blkio: support BFQ weight[_device]
2021-06-11 11:30:05 -07:00
Akihiro Suda 46940ed80c update cilium/ebpf to fix haveBpfProgReplace() check
The `errors.Is(err, unix.EINVAL)` check in `haveBpfProgReplace()` was
broken because the `cilium/ebpf` library did not "wrap" errors.
https://github.com/cilium/ebpf/blob/v0.6.0/link/program.go#L72

So the eBPF support of runc was broken for kernel prior to 5.6.

This commit bumps up cilium/ebpf to contain cilium/ebpf PR 320.

Fix opencontainers/runc issue 3008

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-06-12 02:12:25 +09:00
dependabot[bot] 7eb5c527c8 Merge pull request #3023 from opencontainers/dependabot/github_actions/tim-actions/get-pr-commits-1.1.0 2021-06-11 14:43:08 +00:00
Antti Kervinen 6339d8a0dd libcontainer/cgroups/fs/blkio: support BFQ weight[_device]
- Update the blkio cgroup to support the BFQ I/O Scheduler, that has
  replaced CFQ in the Linux kernel.
- BFQ is controlled through blkio.bfq.weight[_device] instead of
  CFQ's blkio.weight[_device] in cgroups v1.
- BFQ does not support blkio.leaf_weight[_device], so that behavior
  remains untouched.
- Do not change behavior on legacy CFQ systems.
- Enable using blkio weights on BFQ systems.

Signed-off-by: Antti Kervinen <antti.kervinen@intel.com>
2021-06-11 11:11:06 +03:00
dependabot[bot] 01f5dcaeb7 build(deps): bump tim-actions/get-pr-commits from 1.0.0 to 1.1.0
Bumps [tim-actions/get-pr-commits](https://github.com/tim-actions/get-pr-commits) from 1.0.0 to 1.1.0.
- [Release notes](https://github.com/tim-actions/get-pr-commits/releases)
- [Commits](https://github.com/tim-actions/get-pr-commits/compare/v1.0.0...v1.1.0)

---
updated-dependencies:
- dependency-name: tim-actions/get-pr-commits
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-11 06:31:30 +00:00
Akihiro Suda b44f48c945 Merge pull request #3018 from oss-qm/submit/tests-fix-spelling
github: workflows: fix tiny typo
2021-06-11 14:19:21 +09:00