Commit Graph

4670 Commits

Author SHA1 Message Date
Akihiro Suda c23c05eac0 Merge pull request #2528 from zvier/master
cleancode: adjust and make it more readability
2020-10-05 03:56:56 +09:00
Mrunal Patel f671f6bf3d Merge pull request #2597 from kolyshkin/hugepages
Fix/improve GetHugePageSize
2020-10-02 19:23:23 -07:00
Kir Kolyshkin dc775c138e Merge pull request #2625 from KentaTada/modify-rdt-test-perm
libcontainer/intelrdt: modify the incorrect file mode
2020-10-02 18:59:33 -07:00
Mrunal Patel 0d9b0dfc46 Merge pull request #2626 from kolyshkin/mountinfo-0.3.1
vendor: bump mountinfo v0.3.1
2020-10-02 15:11:45 -07:00
Akihiro Suda 750036e41d Merge pull request #2609 from thaJeztah/byte_trim
libcontainer: prefer bytes.TrimSpace() over strings.TrimSpace()
2020-10-02 14:22:39 +09:00
Aleksa Sarai 4d4d19ce52 merge branch 'pr-2624' into master
Ashok Pon Kumar (1):
  Fix goreport warnings of ineffassign and misspell

LGTMs: @AkihiroSuda @cyphar
Closes #2624
2020-10-02 15:15:06 +10:00
Ashok Pon Kumar fcf210d631 Fix goreport warnings of ineffassign and misspell
Signed-off-by: Ashok Pon Kumar <ashokponkumar@gmail.com>
2020-10-02 09:03:45 +05:30
Kenta Tada 644c107ecb libcontainer/intelrdt: modify the incorrect file mode
Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
2020-10-02 11:08:06 +09:00
Kir Kolyshkin 87412ee435 vendor: bump mountinfo v0.3.1
It contains some breaking changes, so fix the code.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-01 18:51:25 -07:00
Sebastiaan van Stijn 28b452bf65 libcontainer: unconvert
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-10-01 18:36:56 +02:00
Sebastiaan van Stijn b3a8b0742c libcontainer: prefer bytes.TrimSpace() over strings.TrimSpace()
Perform trimming before converting to a string, which should be
somewhat more performant.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-10-01 18:36:53 +02:00
Kir Kolyshkin c82737665a Merge pull request #2621 from KentaTada/refactor-config-test
libcontainer: remove loadConfig which is the unused function
2020-10-01 08:17:21 -07:00
Kir Kolyshkin 2854950e5f Merge pull request #2622 from KentaTada/remove-unused-removepath
libcontainer: remove `removePath` from cgroups
2020-10-01 08:15:20 -07:00
Kir Kolyshkin 5f84b72c79 Merge pull request #2623 from KentaTada/remove-unused-variable-of-spec
libcontainer: remove the unused variable from spec
2020-10-01 08:13:30 -07:00
Kenta Tada 3d5dec2f44 libcontainer: remove the unused variable from spec
Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
2020-10-01 12:29:48 +09:00
Kenta Tada b76652fbeb libcontainer: remove removePath from cgroups
`removePath` is unused as below
https://github.com/opencontainers/runc/commit/11fb94965cab5b2a54da9dca50d0e36d0ee36ef0

Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
2020-10-01 12:22:12 +09:00
Kenta Tada faaecac77d libcontainer: remove loadConfig which is the unused function
Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
2020-10-01 12:07:49 +09:00
Akihiro Suda a220b9c6cc Merge pull request #2608 from thaJeztah/no_join
libcontainer: remove redundant strings.Join()
2020-10-01 10:20:23 +09:00
Kir Kolyshkin 35c3555946 Merge pull request #2618 from kolyshkin/golangci-lint
CI: add golangci-lint via github actions
2020-09-30 18:07:30 -07:00
Kir Kolyshkin 8258fae775 Merge pull request #2619 from thaJeztah/nil_return
setFreezer: explicitly return nil
2020-09-30 18:07:10 -07:00
Kir Kolyshkin a234affccd Merge pull request #2620 from thaJeztah/remove_GetProcessStartTime
libcontainer/system: remove deprecated GetProcessStartTime
2020-09-30 18:02:34 -07:00
Sebastiaan van Stijn c6ac3c4bde libcontainer/system: remove deprecated GetProcessStartTime
GetProcessStartTime was deprecated over three Years ago in
439eaa3584, so we may as well remove
it now.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-10-01 00:06:47 +02:00
Sebastiaan van Stijn 3eb469b029 libcontainer: remove redundant strings.Join()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-10-01 00:00:47 +02:00
Sebastiaan van Stijn bc9a7bda58 setFreezer: explicitly return nil
errors.Wrap(err, "some error") returns nil if err is nil, so it's
slightly clearer to just return early than to set the error to nil
and call errors.Wrap(). This is also somewhat defensive in case
we decide to replace `errors.Wrap()` for golang's native `%w`
wrapping.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-30 23:41:07 +02:00
Mrunal Patel ffc30bb00d Merge pull request #2606 from kolyshkin/intel-rdt
libcontainer/intelrdt: use moby/sys/mountinfo
2020-09-30 13:14:10 -07:00
Mrunal Patel d5098eaae4 Merge pull request #2604 from kolyshkin/fscommon-I
libct/cgroups/fscommon: nits
2020-09-30 13:12:16 -07:00
Kir Kolyshkin 2a644a7d76 CI: add golangci-lint via github actions
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-30 11:17:52 -07:00
Kir Kolyshkin 360981ae1d libct/cgroups: rewrite getHugePageSizeFromFilenames
This is a function to convert huge page sizes (obtained by reading
/sys/kernel/mm/hugepages directory entries) to strings user for hugetlb
cgroup controller resource files. Those strings are when used to get the
hugetlb resource statistics.

This function used external library, floating point numbers, and can
(theoretically) produce invalid values, since the kernel only uses KB,
MB, and GB suffixes.

Rewrite it to produce the same strings as used in the kernel (see [1]).
As a result, it's also faster, more future-proof (entries that do not
start with "hugepages-" and/or incorrect suffix are skipped), and does
more input sanity checks. As a side effect, libcontainer no longer
depends on docker/go-units.

While at it, add more test cases.

Before:
	BenchmarkGetHugePageSize-8       	  187452	      6265 ns/op
	BenchmarkGetHugePageSizeImpl-8   	  396769	      2998 ns/op

After:
	BenchmarkGetHugePageSize-8       	  222898	      4554 ns/op
	BenchmarkGetHugePageSizeImpl-8   	 4738924	       241 ns/op

NOTE on removing HugePageSizeUnitList -- this was added by commit
6f77e35da and was used by kubernetes code in [2], which was later
superceded by [3], so there are (hopefully) no external users.
If there are any, they should not be doing that.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/hugetlb_cgroup.c?id=eff48ddeab782e35e58ccc8853f7386bbae9dec4#n574
[2] https://github.com/kubernetes/kubernetes/pull/78495
[3] https://github.com/kubernetes/kubernetes/pull/84154

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-30 10:58:31 -07:00
Akihiro Suda 890cc2aa60 Merge pull request #2612 from thaJeztah/concat
use string-concatenation instead of sprintf for simple cases
2020-10-01 01:56:28 +09:00
Akihiro Suda d4885caaaa Merge pull request #2578 from kolyshkin/fix-destdir
Makefile: fix DESTDIR handling
2020-10-01 01:43:21 +09:00
Kir Kolyshkin 54a8b24c04 Merge pull request #2610 from thaJeztah/hostport_splitting
checkpoint: setPageServer: use net.SplitHostPort instead of strings.Split
2020-09-30 09:33:04 -07:00
Kir Kolyshkin 22f11bafc3 Merge pull request #2611 from thaJeztah/const
libcontainer/cgroups: use const for templates
2020-09-30 09:01:42 -07:00
Kir Kolyshkin 8ee3e560e3 Merge pull request #2616 from thaJeztah/update_logrus
go.mod: update containerd/console v1.0.1, sirupsen/logrus v1.7.0
2020-09-30 09:00:44 -07:00
Mrunal Patel fdd00a693e Merge pull request #2614 from kolyshkin/systemd-race
libct/cgroups/systemd: eliminate runc/systemd race
2020-09-30 08:20:11 -07:00
Mrunal Patel bbf33043af Merge pull request #2615 from kolyshkin/cgroups-ebusy
runc run: fix removing cgroups on error; improve logging on error
2020-09-30 08:18:20 -07:00
Sebastiaan van Stijn 819fd68392 go.mod: sirupsen/logrus v1.7.0
full diff: https://github.com/sirupsen/logrus/compare/v1.6.0...v1.7.0

removes dependency on github.com/konsorten/go-windows-terminal-sequences

Features:
   * a new buffer pool management API has been added
   * a set of `<LogLevel>Fn()` functions have been added

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-30 14:00:16 +02:00
Sebastiaan van Stijn 0eb66c955c go.mod: github.com/containerd/console v1.0.1
full diff: https://github.com/containerd/console/compare/v1.0.0...v1.0.1

Fixes compatibility with current versions of golang.org/x/sys

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-30 13:58:27 +02:00
Sebastiaan van Stijn 8bf216728c use string-concatenation instead of sprintf for simple cases
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-30 10:51:59 +02:00
Kir Kolyshkin ecfad5a118 Merge pull request #2574 from EduardoVega/2249-add-integration-tests-resource-devices
Add integration tests for cgroup devices
2020-09-30 00:19:27 -07:00
Kir Kolyshkin a4d5e8a27b libcontainer/ignoreTerminateError: ignore SIGKILL
When we call terminate(), we kill the process, and wait
returns the error indicating the process was killed.
This is exactly what we expect here, so there is no reason
to treat it as an error.

Before this patch, when a container with invalid cgroup parameters is
started:

> WARN[0000] unable to terminate initProcess               error="signal: killed"
> ERRO[0000] container_linux.go:366: 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 "555": open /sys/fs/cgroup/blkio/user.slice/xx33/blkio.weight: permission denied

After:

> ERRO[0000] container_linux.go:366: 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 "555": open /sys/fs/cgroup/blkio/user.slice/xx33/blkio.weight: permission denied

I.e. the useless warning is gone.

NOTE this breaks a couple of integration test cases, since they were
expecting a particular message in the second line, and now due to
"signal: killed" removed it's in the first line. Fix those, too.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 23:55:02 -07:00
Kir Kolyshkin dc42459130 libct/(*initProcess).start: fix removing cgroups on error
In case cgroup configuration is invalid (some parameters can't be set
etc.), p.manager.Set fails, the error is returned, and then we try to
remove cgroups (by calling p.manager.Destroy) in a defer.

The problem is, the container init is not yet killed (as it is killed in
the caller, i.e. (*linuxContainer).start), so cgroup removal fails like
this:

> time="2020-09-26T07:46:25Z" level=warning msg="Failed to remove cgroup (will retry)" error="rmdir /sys/fs/cgroup/net_cls,net_prio/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod28ce6e74_694c_4b77_a953_dc01e182ac76.slice/crio-f6984c5eeb6c6b49ff3f036bdcb9ded317b3d0b2469ebbb35705442a2afd98c2.scope: device or resource busy"
> ...
> time="2020-09-26T07:46:27Z" level=error msg="Failed to remove cgroup" error="rmdir /sys/fs/cgroup/net_cls,net_prio/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod28ce6e74_694c_4b77_a953_dc01e182ac76.slice/crio-f6984c5eeb6c6b49ff3f036bdcb9ded317b3d0b2469ebbb35705442a2afd98c2.scope: device or resource busy"

The above is repeated for every controller, and looks quite scary.

To fix, move the init termination to the abovementioned defer.

Do the same for (*setnsProcess).start() for uniformity.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 18:49:29 -07:00
Kir Kolyshkin 8699596dce libct/(*setnsProcess).Start: use retErr
It is not a good practice to have the name `err` for the error returned
by a function.  Switch to `retErr`.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 18:38:31 -07:00
Kir Kolyshkin 38447895a5 libct/cgroups/systemd: eliminate runc/systemd race
In case it takes more than 1 second for systemd to create a unit,
startUnit() times out with a warning and then runc proceeds
(to create cgroups using fs manager and so on).

Now runc and systemd are racing, and multiple scenarios are possible.

In one such scenario, by the time runc calls systemd manager's Apply()
the unit is not yet created, the dbusConnection.SetUnitProperties()
call fails with "unit xxx.scope not found", and the whole container
start also fails.

To eliminate the race, we need to return an error in case the timeout is
hit.

To reduce the chance to fail, increase the timeout from 1 to 30 seconds,
to not error out too early on a busy/slow system (and times like 3-5
seconds are not unrealistic).

While at it, as the timeout is quite long now, make sure to not leave
a stray timer.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 17:43:15 -07:00
Kir Kolyshkin 6c83d23ffc libcontainer/cgroups/fscommon: improve doc
Document ReadFile and WriteFile. Fix doc for ParseUint to be in
canonical form.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 11:58:14 -07:00
Kir Kolyshkin 31f0f5b7e0 libct/cg/fscommon.GetCgroupParamUint: improve
1. Use GetCgroupParamString as the initial part of both functions are
   the same and we can reuse it. This also gives us whatever security
   measures GetCgroupParamString has (see previous commit).

2. Fix the error wrapping to not add the value, as it is already a part
   of the error returned by ParseUint.

3. Improve docstring.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 11:58:14 -07:00
Kir Kolyshkin e76ac1c054 libct/cg/fscommon.GetCgroupParamString: use ReadFile
1. Use own ReadFile wrapper instead of ioutils.ReadFile.
   This makes it use the security measures of ReadFile.

2. Improve doc.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 11:58:14 -07:00
Kir Kolyshkin aac4d1f5c3 libct/cg/fscommon/GetCgroupParamKeyValue: nits
2. Fix wrapping the error to not have the value as it's already
   part of the error returned from ParseUint.

3. Fix/improve doc.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 11:57:49 -07:00
Kir Kolyshkin d167be2925 libct/cgroups/fs2/statHugeTlb: error message nits
1. Don't wrap the error from fscommon.GetCgroupParamUint as it already
   contains the file name.

2. Don't put file name when wrapping the error from ioutil.ReadFile
   since it already has it.

3. Don't reconstruct file name, use existing one since it's available.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 11:57:18 -07:00
Kir Kolyshkin 2c70d23840 libct/intelrdt: add TestFindIntelRdtMountpointDir
Heavily based on work by Paweł Szulik <pawel.szulik@intel.com>

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 09:21:32 -07:00
Sebastiaan van Stijn ab2b5dfa8a libcontainer/cgroups: use const for templates
The names of these templates overlapped with some local
variables, which made reading the code somewhat confusing.

Changing them to a const, given that these were not updated anywere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-29 13:34:44 +02:00