Commit Graph

6329 Commits

Author SHA1 Message Date
Christian Brauner
2e3890af0f
Merge pull request #2037 from hallyn/2017-12-14/dir_detect_eperm
dir_detect: warn on eperm
2017-12-14 21:07:22 +01:00
Christian Brauner
1240152866
Merge pull request #2035 from adrianreber/master
criu: add feature check capability
2017-12-14 21:06:17 +01:00
Christian Brauner
f893d89807
commands: fix race when open()/close() cmd socket
When we report STOPPED to a caller and then close the command socket it is
technically possible - and I've seen this happen on the test builders - that a
container start() right after a wait() will receive ECONNREFUSED because it
called open() before we close(). So for all new state clients simply close the
command socket. This will inform all state clients that the container is
STOPPED and also prevents a race between a open()/close() on the command socket
causing a new process to get ECONNREFUSED because we haven't yet closed the
command socket.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-14 20:57:15 +01:00
Adrian Reber
739ef90c82
criu: add a test case for the criu feature check support
This adds a simple test case which verifies that the new migrate() API
command 'MIGRATE_FEATURE_CHECK' works as expected.

If a feature does not exist on the currently running
architecture/kernel/criu combination it does not report an error as this
is a valid scenario.

Signed-off-by: Adrian Reber <areber@redhat.com>
2017-12-14 20:34:51 +01:00
Adrian Reber
b5b12b9e75
criu: add feature check capability
For migration optimization features like pre-copy or post-copy migration
the support cannot be determined by simply looking at the CRIU version.
Features like that depend on the architecture/kernel/criu combination
and CRIU offers a feature checking interface to query if it is
supported.

This adds a LXC interface to query CRIU for those feature via the
migrate() API call. For the recent pre-copy migration support in LXD
this can be used to automatically detect if pre-copy migration should be
used.

In addition to the existing migrate() API commands this adds a new
command: 'MIGRATE_FEATURE_CHECK'.

The migrate_opts{} structure is extended by the member features_to_check
which is a bitmask defining which CRIU features should be queried.

Currently only the querying of the features FEATURE_MEM_TRACK and
FEATURE_LAZY_PAGES is supported.

Signed-off-by: Adrian Reber <areber@redhat.com>
2017-12-14 20:34:51 +01:00
Serge Hallyn
3d8869c369 dir_detect: warn on eperm
if user has lxc.rootfs.path = /some/path/foo, but can't access
some piece of that path, then we'll get an unhelpful "failed to
mount" without any indication of the problem.

At least show that there is a permission problem.

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
2017-12-14 13:32:14 -06:00
Tycho Andersen
c379af4c03 the bike shed should be brilliant purple
Signed-off-by: Tycho Andersen <tycho@tycho.ws>
2017-12-14 17:38:16 +00:00
Serge Hallyn
81b10e37c9
Merge pull request #2026 from brauner/2017-12-12/lxc_hook_version
confile: add lxc.hook.version
2017-12-14 09:27:46 -06:00
Christian Brauner
990b9ac345
network: pass name of peer veth device
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-14 14:41:35 +01:00
Christian Brauner
d08e57088e
conf: simplify run_script_argv()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-14 14:41:35 +01:00
Christian Brauner
14a7b0f98a
network: pass info in env if hook version is 1
Unblocks #2013.
Unblocks #2015.
Closes #1766.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-14 11:54:13 +01:00
Christian Brauner
18b3b9c17f
start: pass namespaces as environment variables
Unblocks #2013.
Unblocks #2015.
Closes #1766.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-14 11:52:09 +01:00
Christian Brauner
3f60c2f749
conf: execute hooks based on lxc.hooks.version
Unblocks #2013.
Unblocks #2015.
Closes #1766.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-14 11:52:07 +01:00
Christian Brauner
a2c09be066
start: set LXC_HOOK_VERSION
This can be used by scripts to detect what version of the hooks are used.

Unblocks #2013.
Unblocks #2015.
Closes #1766.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-14 11:47:36 +01:00
Christian Brauner
44ae0fb6ca
confile: add lxc.hook.version
Unblocks #2013.
Unblocks #2015.
Closes #1766.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-14 11:47:34 +01:00
Serge Hallyn
45acc1bd8c
Merge pull request #2030 from brauner/2017-12-13/fix_cgroup_namsepace_recording
start: fix cgroup namespace preservation
2017-12-14 00:45:52 -06:00
Tycho Andersen
eeeb5865f5 SHARE_NS options should be before OPT_USAGE
Signed-off-by: Tycho Andersen <tycho@tycho.ws>
2017-12-14 00:57:48 +00:00
Tycho Andersen
d76e3e1a5b init: don't kill(-1) if we aren't in a pid ns
...otherwise we'll kill everyone on the machine. Instead, let's explicitly
try to kill our children. Let's do a best effort against fork bombs by
disabling forking via the pids cgroup if it exists. This is best effort for
a number of reasons:

* the pids cgroup may not be available
* the container may have bind mounted /dev/null over pids.max, so the write
  doesn't do anything

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
2017-12-14 00:26:02 +00:00
Stéphane Graber
941ee1fe2a
Merge pull request #2017 from brauner/generic/patch_testing
coverity: bugfixes
2017-12-13 13:26:32 -05:00
Stéphane Graber
352e79d458
Merge pull request #2025 from brauner/2017-12-12/fix_network_attach_and_detach
lxccontainer: only attach netns on netdev detach
2017-12-13 13:22:31 -05:00
Stéphane Graber
1370036089
Merge pull request #2024 from brauner/2017-11-12/fix_lxc_execute
tools: block using lxc-execute without config file
2017-12-13 13:03:42 -05:00
Stéphane Graber
d987c5da4d
Merge pull request #2022 from 3XX0/exec-run-script
conf: avoid spawning unnecessary subshells
2017-12-13 13:02:03 -05:00
Stéphane Graber
5875fa24a4
Merge pull request #2029 from brauner/2017-12-12/do_not_unconditionally_dup_stdfds_for_execute
start: do not unconditionally dup std{in,out,err}
2017-12-13 12:58:58 -05:00
Christian Brauner
547dfee335
Merge pull request #2010 from tanyifeng/set_oom_score_adj
confile: add lxc.proc.* to set proc filesystem
2017-12-13 11:24:47 +01:00
Yifeng Tan
61d7a733c7 confile: add lxc.proc.* to set proc filesystem
Signed-off-by: Yifeng Tan <tanyifeng1@huawei.com>
2017-12-13 20:08:56 +08:00
Christian Brauner
5af9369bf3
start: fix cgroup namespace preservation
Prior to this patch we raced with a very short-lived init process. Essentially,
the init process could exit before we had time to record the cgroup namespace
causing the container to abort and report ABORTING to the caller when it
actually started just fine. Let's not do this.

(This uses syscall(SYS_getpid) in the the child to retrieve the pid just in case
we're on an older glibc version and we end up in the namespace sharing branch
of the actual lxc_clone() call.)

Additionally this fixes the shortlived tests. They were faulty so far and
should have actually failed because of the cgroup namespace recording race but
the ret variable used to return from the function was not correctly
initialized. This fixes it.
Furthermore, the shortlived tests used the c->error_num variable to determine
success or failure but this is actually not correct when the container is
started daemonized.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-13 00:28:30 +01:00
Christian Brauner
6c84b5994a
tools: exit success when lxc-execute is daemonized
The error_num value doesn't tell us anything since the container hasn't exited.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 21:05:39 +01:00
Christian Brauner
5d113f650c
start: do not unconditionally dup std{in,out,err}
Starting with commit

    commit c5b93afba1
    Author: Li Feng <lifeng68@huawei.com>
    Date:   Mon Jul 10 17:19:52 2017 +0800

        start: dup std{in,out,err} to pty slave

        In the case the container has a console with a valid slave pty file descriptor
        we duplicate std{in,out,err} to the slave file descriptor so console logging
        works correctly. When the container does not have a valid slave pty file
        descriptor for its console and is started daemonized we should dup to
        /dev/null.

        Closes #1646.

        Signed-off-by: Li Feng <lifeng68@huawei.com>
        Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>

we made std{err,in,out} a duplicate of the slave file descriptor of the console
if it existed. This meant we also duplicated all of them when we executed
application containers in the foreground even if some std{err,in,out} file
descriptor did not refer to a {p,t}ty. This blocked use cases such as:

    echo foo | lxc-execute -n -- cat

which are very valid and common with application containers but less common
with system containers where we don't have to care about this. So my suggestion
is to unconditionally duplicate std{err,in,out} to the console file descriptor
if we are either running daemonized - this ensures that daemonized application
containers with a single bash shell keep on working - or when we are not
running an application container. In other cases we only duplicate those file
descriptors that actually refer to a {p,t}ty. This logic is similar to what we
do for lxc-attach already.

Refers to #1690.
Closes #2028.

Reported-by: Felix Abecassis <fabecassis@nvidia.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 20:50:51 +01:00
Christian Brauner
9e1329562b
conf: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:56 +01:00
Christian Brauner
a61b4e8584
coverity: #1426028
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:56 +01:00
Christian Brauner
a55f31bda2
coverity: #1425857
remove logically dead code

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
0e4adc1a33
coverity: #1425858
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
e8eb39565a
coverity: #1425859
check return value of snprintf()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
d5590c8c70
coverity: #1425860
remove logically dead code

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
f54f8d0b58
coverity: #1425861
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
41784e4ee4
coverity: #1425862
initialize handler

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
6a0019fa97
coverity: #1425863
remove logically dead code

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:54 +01:00
Christian Brauner
62de1db6ef
coverity: #1425866
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:54 +01:00
Christian Brauner
d6d979bc2b
coverity: #1425867
do not pass NULL pointer to chdir()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:54 +01:00
Christian Brauner
3ca108148b
coverity: #1425869
do not unmap prematurely

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:54 +01:00
Christian Brauner
de429548c4
coverity: #1425870
check snprintf() return value

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:54 +01:00
Christian Brauner
c7d76c0947
lxccontainer: cleanup {attach,detach}_interface()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:54:21 +01:00
Christian Brauner
acbfeda88b
lxccontainer: only attach netns on netdev detach
Detaching network namespaces as an unprivileged user is currently not possible
and attaching to the user namespace will mean we are not allowed to move the
network device into an ancestor network namespace.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:54:12 +01:00
Christian Brauner
b69dfc9fcb
coverity: #1425874 + cleanup
- check for memory allocation failure
- free allocated memory
- cleanup function

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:53:58 +01:00
Christian Brauner
bad943c4dc
Merge pull request #2021 from 3XX0/overlay-oob-copy
overlay: fix out-of-bounds copy
2017-12-12 11:40:21 +01:00
Jonathan Calmels
6d1a5f93db conf: avoid spawning unnecessary subshells
Signed-off-by: Jonathan Calmels <jcalmels@nvidia.com>
2017-12-11 16:52:55 -08:00
Christian Brauner
19bfbf6e94
tools: block using lxc-execute without config file
Moving away from internal symbols we can't do hacks like we currently do in
lxc-start and call internal functions like lxc_conf_init(). This is unsafe
anyway. Instead, we should simply error out if the user didn't give us a
configuration file to use. lxc-start refuses to start in that case already.

Relates to discussion in https://github.com/lxc/go-lxc/pull/96#discussion_r155075560 .
Closes #2023.

Reported-by: Felix Abecassis <fabecassis@nvidia.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 01:45:54 +01:00
Jonathan Calmels
fe3485479f overlay: fix out-of-bounds copy
Signed-off-by: Jonathan Calmels <jcalmels@nvidia.com>
2017-12-11 14:49:57 -08:00
Serge Hallyn
f449521ce6
Merge pull request #2020 from brauner/2017-12-11/clone
start: intelligently use clone() on ns sharing
2017-12-11 13:52:05 -06:00
Christian Brauner
7acb5ce30d
tests: add namespace sharing tests
This also ensures that the new more efficient clone() way of sharing namespaces
is tested.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 19:16:26 +01:00