Commit Graph

4088 Commits

Author SHA1 Message Date
Mrunal Patel f1eea9051c
Merge pull request #2275 from kolyshkin/scan-nits
bifio.Scan.Err usage nits
2020-03-27 11:41:06 -07:00
Mrunal Patel 53ad1d5100
Merge pull request #2256 from kolyshkin/mountinfo-alt
Use faster mountinfo parser (part 1)
2020-03-27 11:36:51 -07:00
Mrunal Patel 75ff40cd28
Merge pull request #2273 from kolyshkin/v2-untangle
cgroup v2 cleanups
2020-03-27 11:21:36 -07:00
Kir Kolyshkin aab2c8ba52 libcontainer/intelrdt: optimize parseCpuInfoFile
The line we are parsing looks like this

> flags		: fpu vme de pse <...>

so look for "flags" as a prefix, not substring.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-27 00:41:11 -07:00
Kir Kolyshkin 0af5cd2041 Nit: fix use of bufio.Scanner.Err
The Err() method should be called after the Scan() loop, not inside it.

Found by

 git grep -A3 -F '.Scan()' | grep Err

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-27 00:12:17 -07:00
Qiang Huang d4a6a1d998
Merge pull request #2258 from masters-of-cats/eintr-retry
Retry writing to cgroup files on EINTR error
2020-03-27 11:21:41 +08:00
Kir Kolyshkin b45db5d3b2 libcontainer/cgroup: obsolete Get*Cgroup for v2
These functions should not be called from any code handling
the cgroup2 unified hierarchy.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-26 19:20:00 -07:00
Kir Kolyshkin a949e4f22f cgroupv2: UnifiedManager.Apply: simplify
Remove joinCgroupsV2() function, as its name and second parameter
are misleading. Use createCgroupsv2Path() directly, do not call
getv2Path() twice.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-26 19:20:00 -07:00
Kir Kolyshkin 5406833a65 cgroupv2/systemd: add getv2Path
Function getSubsystemPath(), while works for v2 unified case, is
suboptimal, as it does a few unnecessary calls.

Add a simplified version of getSubsystemPath(), called getv2Path(),
and use it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-26 19:17:09 -07:00
Mrunal Patel cebef0ee86
Merge pull request #2272 from kolyshkin/cgroupv2-max
cgroupv2: use "max" for negative values
2020-03-26 15:33:57 -07:00
Kir Kolyshkin ec1f957b23 cgroupv2: don't use getSubsystemPath in Apply
This code is a copy-paste from cgroupv1 systemd code. Its aim
is to check whether a subsystem is available, and skip those
that are not.

In case v2 unified hierarchy is used, getSubsystemPath never
returns "not found" error, so calling it is useless.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-26 13:32:34 -07:00
Kir Kolyshkin 6905b72154 cgroupv2: use "max" for negative values
Cgroup v1 kernel doc [1] says:

> We can write "-1" to reset the ``*.limit_in_bytes(unlimited)``.

and cgroup v2 kernel documentation [2] says:

> - If a controller implements an absolute resource guarantee and/or
>  limit, the interface files should be named "min" and "max"
>  respectively.  If a controller implements best effort resource
>  guarantee and/or limit, the interface files should be named "low"
>  and "high" respectively.
>
>  In the above four control files, the special token "max" should be
>  used to represent upward infinity for both reading and writing.

Allow -1 value to still be used for v2, converting it to "max"
where it makes sense to do so.

This fixes the following issue:

> runc update test_update --memory-swap -1:
> error while setting cgroup v2: [write /sys/fs/cgroup/machine.slice/runc-cgroups-integration-test.scope/memory.swap.max: invalid argument
> failed to write "-1" to "/sys/fs/cgroup/machine.slice/runc-cgroups-integration-test.scope/memory.swap.max"
> github.com/opencontainers/runc/libcontainer/cgroups/fscommon.WriteFile
> 	/home/kir/go/src/github.com/opencontainers/runc/libcontainer/cgroups/fscommon/fscommon.go:21
> github.com/opencontainers/runc/libcontainer/cgroups/fs2.setMemory
> 	/home/kir/go/src/github.com/opencontainers/runc/libcontainer/cgroups/fs2/memory.go:20
> github.com/opencontainers/runc/libcontainer/cgroups/fs2.(*manager).Set
> 	/home/kir/go/src/github.com/opencontainers/runc/libcontainer/cgroups/fs2/fs2.go:175
> github.com/opencontainers/runc/libcontainer/cgroups/systemd.(*UnifiedManager).Set
> 	/home/kir/go/src/github.com/opencontainers/runc/libcontainer/cgroups/systemd/unified_hierarchy.go:290
> github.com/opencontainers/runc/libcontainer.(*linuxContainer).Set
> 	/home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:211

[1] linux/Documentation/admin-guide/cgroup-v1/memory.rst
[2] linux/Documentation/admin-guide/cgroup-v2.rst

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-26 11:14:32 -07:00
Mrunal Patel 96596cbbec
Merge pull request #2270 from kolyshkin/systemd-no-kmem
cgroupv2: don't try to set kmem for systemd case
2020-03-25 21:39:52 -07:00
Kir Kolyshkin a675b5ebea cgroupv2: don't try to set kmem for systemd case
To the best of my knowledge, it has been decided to drop the kernel
memory controller from the cgroupv2 hierarchy, so "kernel memory limits"
do not exist if we're using v2 unified.

So, we need to ignore kernel memory setting. This was already done in
non-systemd case (see commit 88e8350de), let's do the same for systemd.

This fixes the following error:

> container_linux.go:349: starting container process caused "process_linux.go:306: applying cgroup configuration for process caused \"open /sys/fs/cgroup/machine.slice/runc-cgroups-integration-test.scope/tasks: no such file or directory\""

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-25 20:00:23 -07:00
Mrunal Patel be51398a8a
Merge pull request #2193 from milkwine/fix-readSync
fix readSync
2020-03-24 14:29:42 -07:00
Mrunal Patel a7ee31fa18
Merge pull request #2260 from adrianreber/leave-running
checkpoint: remove error message with --leave-running
2020-03-24 14:18:39 -07:00
Mrunal Patel 7de5db3dad
Merge pull request #2263 from kolyshkin/nits
Assorted minor nits in libcontainer
2020-03-24 14:17:22 -07:00
Akihiro Suda cc183ca662
Merge pull request #2242 from AkihiroSuda/vendor-systemd
vendor: update go-systemd and godbus
2020-03-25 02:40:22 +09:00
Michael Crosby 4e6d8a0fb9
Merge pull request #2267 from tedyu/runner-destroy
Avoid duplicate calls to runner#destroy
2020-03-24 12:10:56 -04:00
Mrunal Patel 3087d43bc8
Merge pull request #1826 from jingxiaolu/fix_specconv_process_nil
specconv: fix null spec.Process making runc panic
2020-03-23 21:07:06 -07:00
Michael Crosby 07bd2809ed
Merge pull request #2257 from kolyshkin/no-signal
Use signal map from x/sys/unix
2020-03-23 16:25:27 -04:00
Ted Yu 0a7762c664 Avoid duplicate calls to runner#destroy
Signed-off-by: Ted Yu <yuzhihong@gmail.com>
2020-03-23 09:04:38 -07:00
Michael Crosby 1797622fd4
Merge pull request #2264 from kolyshkin/dockerfile
Dockerfile: add -f to curl
2020-03-23 11:56:02 -04:00
Kir Kolyshkin dd7b34618f libct/msMoveRoot: benefit from GetMounts filter
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-21 10:33:43 -07:00
Kir Kolyshkin fc4357a8b0 libct/msMoveRoot: rm redundant filepath.Abs() calls
1. rootfs is already validated to be kosher by (*ConfigValidator).rootfs()

2. mount points from /proc/self/mountinfo are absolute and clean, too

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-21 10:33:43 -07:00
Kir Kolyshkin dce0de8975 getParentMount: benefit from GetMounts filter
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-21 10:33:43 -07:00
Kir Kolyshkin 81d8452e30 libct/TestFactoryNewTmpfs: benefit from GetMounts
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-21 10:33:43 -07:00
Kir Kolyshkin c7ab2c036b libcontainer: switch to moby/sys/mountinfo package
Delete libcontainer/mount in favor of github.com/moby/sys/mountinfo,
which is fast mountinfo parser.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-21 10:33:43 -07:00
Kir Kolyshkin 3147c3200e Switch to golang 1.13, drop unsupported versions
Run CI with go 1.13 and 1.14 (aka "stable").

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-21 10:33:23 -07:00
Kir Kolyshkin 88a0244783 Dockerfile: add -f to curl
When github is giving HTTP 404 (or other error), it still sends some
document (to be viewed in a browser), but we have tar on the other end
of the pipe, so the end result is like this:

> Step 13/13 : RUN . tests/integration/multi-arch.bash     && curl -o- -sSL `get_busybox` | tar xfJC - ${ROOTFS}
> 4872 ---> Running in ad84646a69f3
> 4873xz: (stdin): File format not recognized
> 4874tar: Child returned status 1
> 4875tar: Error is not recoverable: exiting now
> 4876The command '/bin/sh -c . tests/integration/multi-arch.bash     && curl -o- -sSL `get_busybox` | tar xfJC - ${ROOTFS}' returned a non-zero code: 2

Add -f switch to curl, so it will display an HTTP error and exit:

> curl: (22) The requested URL returned error: 404 Not Found
> xz: (stdin): File format not recognized
> tar: Child returned status 1
> tar: Error is not recoverable: exiting now

While at it, also
 * remove -v from criu untar (too much output)
 * remove -o - from curl (it does the same by default)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-20 17:26:15 -07:00
Kir Kolyshkin a572216f74 libcontainer/intelrdt: rm fmt.Sprintf
It it not needed as it does nothing here.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-20 12:33:24 -07:00
Kir Kolyshkin 5542a2c77d libcontainer/cgroups: GetAllPids: optimize
1. Return earlier if there is an error.

2. Do not use filepath.Split on every entry, use info.Name() instead.

3. Make readProcsFile() accept file name as an argument, to avoid
   unnecessary file name and directory splitting and merging.

4. Skip on info.IsDir() -- this avoids an error when cgroup name is
   set to "cgroup.procs".

This is still not very good since filepath.Walk() performs an unnecessary
stat(2) on every entry, but better than before.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-20 12:27:36 -07:00
Kir Kolyshkin 12dc475dd6 libcontainer: simplify createCgroupsv2Path
fmt.Sprintf is slow and is not needed here, string concatenation would
be sufficient. It is also redundant to convert []byte from string and
back, since `bytes` package now provides the same functions as `strings`.

Use Fields() instead of TrimSpace() and Split(), mainly for readability
(note Fields() is somewhat slower than Split() but here it doesn't
matter much).

Use Join() to prepend the plus signs.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-20 11:51:55 -07:00
Mario Nitchev 648295be98 Skip test for cgroups v2
Signed-off-by: Yulia Nedyalkova <julianedialkova@hotmail.com>
2020-03-19 12:54:54 +02:00
Danail Branekov f34eb2c003 Retry writing to cgroup files on EINTR error
Golang 1.14 introduces asynchronous preemption which results into
applications getting frequent EINTR (syscall interrupted) errors when
invoking slow syscalls, e.g. when writing to cgroup files.

As writing to cgroups is idempotent, it is safe to retry writing to the
file whenever the write syscall is interrupted.

Signed-off-by: Mario Nitchev <marionitchev@gmail.com>
2020-03-18 13:00:05 +02:00
Adrian Reber 87712d288e
checkpoint: remove error message with --leave-running
If checkpointing a container with '--leave-running' runc started to
print the following message:

 ERRO[0000] container is not destroyed

The message is correct, because CRIU did not terminate the process, but
as that was requested by the user the message is wrong.

So now the container is only destroyed if the user did not specify
'--leave-running'.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-03-17 18:43:46 +01:00
SiYu Zhao 34d471769b fix readSync
Signed-off-by: SiYu Zhao <d.chaser.zsy@gmail.com>
2020-03-17 11:26:46 +08:00
Kir Kolyshkin 0e062a78ae Remove signalmap, use unix.SignalNum
Since [1], x/sys/unix has a function to convert signal name
to a number. Let's use it and drop home-grown signal map.

While at it, add a test case.

[1] d455e41777

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-16 19:59:06 -07:00
Michael Crosby 939cd0b734
Merge pull request #1737 from wking/remove-procConsole-comment
libcontainer/sync: Drop procConsole transaction from comments
2020-03-16 14:00:00 -04:00
Michael Crosby 88474967d3
Merge pull request #1974 from openSUSE/unreachable-code
Remove unreachable code paths
2020-03-16 13:56:05 -04:00
Akihiro Suda 525b9f311c
Merge pull request #2248 from AkihiroSuda/fix-cgroupv2-conversion
cgroup2: fix conversion
2020-03-16 14:00:02 +09:00
Akihiro Suda 492d525e55 vendor: update go-systemd and godbus
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-03-16 13:26:03 +09:00
Mrunal Patel 981dbef514
Merge pull request #2226 from avagin/runsc-restore-cmd-wait
restore: fix a race condition in process.Wait()
2020-03-15 18:48:16 -07:00
Aleksa Sarai a15d2c3ca0
merge branch 'pr-2073'
Odin Ugedal (7):
  Run verify-dependencies only on go1.x
  Don't add git utils to go.mod in CI
  Remove refrences to vndr
  Make CI script to verify that vendor is in sync
  Fix file permissions for mounts.bats
  Update spec test to use go.mod
  Add support for GO Modules

LGTMs: @hqhq @AkihiroSuda @cyphar
Closes #2073
2020-03-16 12:38:40 +11:00
Aleksa Sarai 9167393cb8
merge branch 'pr-2254'
Kir Kolyshkin (2):
  Makefile: add selinux and apparmor build tags
  README, travis.yml: rm ambient tag

LGTMs: @AkihiroSuda @cyphar
Closes #2254
2020-03-16 12:26:23 +11:00
Kir Kolyshkin 89c108b1be Makefile: add selinux and apparmor build tags
Both selinux and apparmor subsystem can detect whether it is enabled,
and act accordingly. Compiling it in by default should help avoid
some frustration cased by missing build tags.

This should not change anything in case BUILDTAGS is already set.

README.md is amended to clarify what BUILDTAGS are enabled by
default.

[v2: add apparmor]
[v3: add it unconditionally, fix README]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-15 10:29:35 -07:00
Kir Kolyshkin 69f6f32f6b README, travis.yml: rm ambient tag
This build tag was removed in commit 4f903a21c4 (PR #1370)
quite some time ago.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-15 10:25:33 -07:00
Michael Crosby 8615da6f7b
Merge pull request #1999 from lifubang/rootlesspath
fix rootless container: unrelated error with root flag
2020-03-13 16:06:54 -04:00
Mrunal Patel 167e33ca50
Merge pull request #1807 from giuseppe/notify-no-block
sd-notify: do not hang when NOTIFY_SOCKET is used with create
2020-03-13 10:40:13 -07:00
Giuseppe Scrivano 25fd4a6757
sd-notify: do not hang when NOTIFY_SOCKET is used with create
if NOTIFY_SOCKET is used, do not block the main runc process waiting
for events on the notify socket.  Bind mount the parent directory of
the notify socket, so that "start" can create the socket and it is
still accessible from the container.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-12 21:21:05 +01:00