Commit Graph

4714 Commits

Author SHA1 Message Date
Christian Brauner
b5f845e7e0
utils: add lxc_safe_int()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:05 +01:00
Christian Brauner
57c7adc3c8
tests: add unit tests for lxc_safe_uint()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:03 +01:00
Christian Brauner
6bc2eafe90
utils: add lxc_safe_uint()
This function safely parses an unsigned integer. On success it returns 0 and
stores the unsigned integer in @converted. On error it returns a negative
errno.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:40:59 +01:00
Serge Hallyn
995ea94114 Merge pull request #1309 from brauner/2016-11-21/cgfsng_improve_isolcpus_handling
cgroup: improve isolcpus handling
2016-11-21 17:57:05 -06:00
Christian Brauner
65d29cbc57
cgroups: handle non-existent isolcpus file
If the file "/sys/devices/system/cpu/isolated" doesn't exist, we can't just
simply bail. We still need to check whether we need to copy the parents cpu
settings.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-21 22:31:39 +01:00
Christian Brauner
6f9584d885
cgroup: improve isolcpus handling
- add more logging
- only write to cpuset.cpus if we really have to
- simplify cleanup on error and success

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-21 21:39:47 +01:00
Stéphane Graber
b8ca2bc7c9 Merge pull request #1308 from brauner/2016-11-20/use_ns_info_struct
use ns info struct and always attach to user namespace first
2016-11-20 01:11:24 -05:00
Christian Brauner
29ed9c13ac
namespace: always attach to user namespace first
Move the user namespace at the first position in the array so that we always
attach to it first when iterating over the struct and using setns() to switch
namespaces. This especially affects lxc_attach(): Suppose you cloned a new user
namespace and mount namespace as an unprivileged user on the host and want to
setns() to the mount namespace. This requires you to attach to the user
namespace first otherwise the kernel will fail this check:

    if (!ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN) ||
        !ns_capable(current_user_ns(), CAP_SYS_CHROOT) ||
        !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
    	return -EPERM;

in

    linux/fs/namespace.c:mntns_install().

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-20 06:26:03 +01:00
Christian Brauner
2681861894
attach: use ns_info[LXC_NS_MAX] struct
Using custom structs in attach.c risks getting out of sync with the commonly
used ns_info[LXC_NS_MAX] struct and thus attaching to wrong namespaces. Switch
to using ns_info[LXC_NS_MAX].

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-20 06:17:53 +01:00
Serge Hallyn
88a66d0112 Merge pull request #1255 from brauner/2016-10-27/cleanup_netdevs_lxd#2439_lxc#1253
remove veth device from host
2016-11-19 12:17:11 -06:00
Christian Brauner
a052913dd0
attach, utils: bugfixes
- simply check /proc/self/ns
- improve SYSERROR() report
- use #define to prevent gcc & clang to use a VLA

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:45:01 +01:00
Christian Brauner
9662e444d9
start, namespace: move ns_info to namespace.{c,h}
It's much more appropriate there and makes start.{c,h} cleaner and leaner.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:41 +01:00
Christian Brauner
408da065fb
start, error: improve log + non-functional changes
Improve log and comments in a bunch of places to make it easier for us on bug
reports.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:39 +01:00
Christian Brauner
4d8ac866fc
start, utils: improve preserve_ns()
- Allocating an error message that the caller must free seems pointless. We can
  just print the error message in preserve_ns() itself. This also allows us to
  avoid using the GNU extension asprintf().
- Improve lxc_preserve_ns(): By passing in NULL or "" as the second argument
  the function can now also be used to check whether namespaces are supported
  by the kernel.
- Use lxc_preserve_ns() in preserve_ns().

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:36 +01:00
Christian Brauner
358daf49c0
conf, start: be smarter when deleting networks
- So far we blindly called lxc_delete_network() to make sure that we deleted
  all network interfaces. This resulted in pointless netlink calls, especially
  when a container had multiple networks defined. Let's be smarter and have
  lxc_delete_network() return a boolean that indicates whether *all* configured
  networks have been deleted. If so, don't needlessly try to delete them again
  in start.c. This also decreases confusing error messages a user might see.

- When we receive -ENODEV from one of our lxc_netdev_delete_*() functions,
  let's assume that either the network device already got deleted or that it
  got moved to a different network namespace. Inform the user about this but do
  not report an error in this case.

- When we have explicitly deleted the host side of a veth pair let's
  immediately free(priv.veth_attr.pair) and NULL it, or
  memset(priv.veth_attr.pair, ...) the corresponding member so we don't
  needlessly try to destroy them again when we have to call
  lxc_delete_network() again in start.c

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:34 +01:00
Christian Brauner
e97946ae96
conf: explicitly remove veth device from host
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:32 +01:00
Christian Brauner
198cbbaa1d
conf, start: improve log output
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:30 +01:00
Christian Brauner
5d04811edf
lxc_user_nic: use lxc_preserve_ns()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:28 +01:00
Christian Brauner
383613cc36
attach: use lxc_preserve_ns()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:25 +01:00
Christian Brauner
64d2fcb5cf
conf: use lxc_preserve_ns()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:23 +01:00
Christian Brauner
738d0deb13
start: add netnsfd to lxc_handler
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:17 +01:00
Christian Brauner
a687256f1d
utils: add lxc_preserve_ns()
This allows to retrieve a file descriptor referring to a namespace.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:12 +01:00
Stéphane Graber
122aaf5094 Merge pull request #1305 from brauner/2016-11-16/cgfsng_debug
cgroups: prevent segfault in cgfsng
2016-11-17 09:48:06 -07:00
Christian Brauner
a7b0cc4c91
cgroups: prevent segfault in cgfsng
When we set LXC_DEBUG_CGFSNG=1 we print out info about detected cgroup
hierarchies. When there's no named cgroup mounted we need to make sure that we
don't try to index an unallocated pointer.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-17 16:32:28 +01:00
Christian Brauner
67c933b6f8 Merge pull request #1303 from adrianreber/master
lxc-checkpoint: automatically detect if --external or --veth-pair
2016-11-16 21:00:19 -05:00
Adrian Reber
46c8ffd5e5 lxc-checkpoint: automatically detect if --external or --veth-pair
With the criu release 2.8 criu deprecated the --veth-pair command-line
option in favor of --external:

f2037e6 veth: Make --external support --veth-pair

git tag --contains f2037e6d3445fc400
v2.8

With this commit lxc-checkpoint will automatically switch between
the new and old command-line option dependent on the detected
criu version.

For criu version older than 2.8 something like this will be used:

  --veth-pair eth0=vethYOK6RW@lxcbr0

and starting with criu version 2.8 it will look like this:

  --external veth[eth0]:vethCRPEYL@lxcbr0

Signed-off-by: Adrian Reber <areber@redhat.com>
2016-11-16 07:31:34 +00:00
Stéphane Graber
471a304df4 Merge pull request #1301 from brauner/2016-11-15/isolcpus
cgroups: use %zu format specifier to print size_t
2016-11-15 09:03:21 -07:00
Stéphane Graber
a8bae5522a Merge pull request #1299 from adrianreber/master
lxc-checkpoint: enable dirty memory tracking in criu
2016-11-15 08:56:55 -07:00
Adrian Reber
9f99a33fa9 lxc-checkpoint: enable dirty memory tracking in criu
CRIU supports dirty memory tracking to take incremental checkpoints.
Incremental checkpoints are one way of reducing downtime during
migration. The first checkpoint dumps all the memory pages and the
second (and third, and fourth, ...) only dumps pages which have changed.

Most of the necessary code has already been implemented. This just adds
the existing functionality to lxc-checkpoint:

  -p, --pre-dump            Only pre-dump the memory of the container.
                            Container keeps on running and following
                            checkpoints will only dump the changes.
  --predump-dir=DIR         path to images from previous dump (relative to -D)

The following is an example from a container running CentOS 7 with psql
and tomcat:

 # lxc-checkpoint -n c7 -D /tmp/cp -p
Container keeps on running
 # du -h /tmp/cp
 229M	/tmp/cp
Sync initial checkpoint to destination
 # rsync -a /tmp/cp host2:/tmp/
Sync file-system
 # rsync -a /var/lib/lxc/c7 host2:/var/lib/lxc/
Final dump; container is stopped
 # lxc-checkpoint -n c7 -D /tmp/cp --predump-dir=../cp -s
 # du -h /tmp/cp2
 90M	/tmp/cp2

After transferring the second (incremental checkpoint) and the changes
to the container's file system the container can be restored on the
second host by pointing lxc-checkpoint to the second checkpoint
directory:

 # lxc-checkpoint -n c7 -D /tmp/cp2 -r

Signed-off-by: Adrian Reber <areber@redhat.com>
2016-11-15 14:10:03 +00:00
Christian Brauner
657f890799
cgroups: use %zu format specifier to print size_t
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-15 06:19:55 +01:00
Serge Hallyn
748c52b52c Merge pull request #1282 from brauner/2016-11-03/isolcpus
cgroups: remove isolated cpus from cpuset.cpus  …
2016-11-14 13:53:56 -06:00
Serge Hallyn
5b40ec9292 Merge pull request #1300 from stgraber/master
debian: Don't depend on libui-dialog-perl
2016-11-14 11:17:52 -06:00
Stéphane Graber
4fd968818c debian: Don't depend on libui-dialog-perl
This package doesn't exist in stretch anymore, and it's unclear why we
were depending on a library to begin with (as opposed to having it
brought by whatever needs it).

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2016-11-14 11:53:07 -05:00
Serge Hallyn
a3524e9147 Merge pull request #1297 from brauner/2016-11-13/fix_tmpfile_errno
conf: do not use %m format specifier
2016-11-14 00:33:40 -06:00
Christian Brauner
9e4e7b0dad
conf: do not use %m format specifier
This is a GNU extension and some libcs might be missing it.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-13 17:10:41 +01:00
Christian Brauner
d3c57812b5 Merge pull request #1293 from evgeni/always-stop-lxc-net
also stop lxc-net in runlevels 0 and 6
2016-11-12 11:13:25 -05:00
Christian Brauner
0379b4ffbd Merge pull request #1294 from evgeni/ignore-lxc.egg-info
add lxc.egg-info to gitignore
2016-11-12 11:13:18 -05:00
Christian Brauner
d06df88abb Merge pull request #1295 from evgeni/bash-completion-pkg-config
install bash completion where pkg-config tells us to
2016-11-12 11:13:10 -05:00
Evgeni Golov
23f4c8a01a install bash completion where pkg-config tells us to
Signed-off-by: Evgeni Golov <evgeni@debian.org>
2016-11-12 14:57:34 +01:00
Evgeni Golov
8467eee707 add lxc.egg-info to gitignore
Signed-off-by: Evgeni Golov <evgeni@debian.org>
2016-11-12 14:47:33 +01:00
Evgeni Golov
79c07e4b11 also stop lxc-net in runlevels 0 and 6
there is no reason to not do this :)

Signed-off-by: Evgeni Golov <evgeni@debian.org>
2016-11-12 12:29:26 +01:00
Serge Hallyn
f3d7477c37 Merge pull request #1290 from brauner/2016-11-09/named_controllers
cgroups: skip v2 hierarchy entry
2016-11-10 20:40:23 -06:00
Christian Brauner
ff8d6ee936
cgroups: skip v2 hierarchy entry
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-11 00:31:04 +01:00
Christian Brauner
bedea59739 Merge pull request #1289 from Cypresslin/ubuntu-cloud-squashfs
templates: add squashfs support to lxc-ubuntu-cloud.in
2016-11-10 09:29:23 -05:00
Po-Hsu Lin
5d58fc90a6 templates: add squashfs support to lxc-ubuntu-cloud.in
Add squashfs format file support for lxc-ubuntu-cloud.in

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
2016-11-10 16:48:29 +08:00
Christian Brauner
7a8082f47b Merge pull request #1288 from Cypresslin/known-release-zesty
Update Ubuntu release name: add zesty
2016-11-10 00:22:05 -05:00
Po-Hsu Lin
0815a59287 Update Ubuntu release name: add zesty and remove wily
Add zesty to KNOWN_RELEASES
Remove EOL wily from KNOWN_RELEASES

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
2016-11-10 11:06:09 +08:00
Christian Brauner
a54694f86d
cgroups: remove isolated cpus from cpuset.cpus
In case the system was booted with

    isolcpus=n_i-n_j,n_k,n_m

we cannot simply copy the cpuset.cpus file from our parent cgroup. For example,
in the root cgroup cpuset.cpus will contain all of the cpus including the
isolated cpus. Copying the values of the root cgroup into a child cgroup will
lead to a wrong view in /proc/self/status: For the root cgroup
/sys/fs/cgroup/cpuset /proc/self/status will correctly show

    Cpus_allowed_list:      0-1,3

even though cpuset.cpus will show

    0-3

However, initializing a subcgroup in the cpuset controller by copying the
cpuset.cpus setting from the root cgroup will cause /proc/self/status to
incorrectly show

    Cpus_allowed_list:      0-3

Hence, we need to make sure to remove the isolated cpus from cpuset.cpus. Seth
has argued that this is not a kernel bug but by design. So let us be the smart
guys and fix this in liblxc.

The solution is straightforward: To avoid having to work with raw cpulist
strings we create cpumasks based on uint32_t bit arrays.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-09 19:28:02 +01:00
Christian Brauner
000dfda7f3
utils: add lxc_append_string()
lxc_append_string() appends strings without separator. This is mostly useful
for reading in whole files line-by-line.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-09 19:27:58 +01:00
Stéphane Graber
5e8b774630 Merge pull request #1286 from mgariepy/patch-1
create symlink for /var/run
2016-11-09 05:18:11 -07:00