Commit Graph

1718 Commits

Author SHA1 Message Date
Serge Hallyn
5acccf95b2 config_ipv6: run inet_pton on the addr value without mask
otherwise a "$addr/$mask" results in failure.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-26 06:26:33 -05:00
Serge Hallyn
79622932f2 api: convert lxc_start
Normal lxc-start usage tends to be "lxc-start -n name [-P lxcpath]".
This causes $lxcpath/$name/config to be the configuration for the
container.  However, lxc-start is more flexible than that.  You can
specify a custom configuration file, in which case $lxcpath/$name/config
is not used.  You can also (in addition or in place of either of these)
specify configuration entries one-by-one using "-s lxc.utsname=xxx".

To support this using the API, if we are not using
$lxcpath/$name/config then we put ourselves into a custom lxcpath
called (configurable using LXCPATH) /var/lib/lxc_anon.  To stop a
container so created, then, you would use

	lxc-stop -P /var/lib/lxc_anon -n name

TODO: we should walk over the list of &defines by hand and set them
using c->set_config_item.  I haven't done that in this patch.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-26 06:23:27 -05:00
Scott Moser
cb0c6c0203 hooks/ubuntu-cloud-prep: add hostname to meta-data
prior to my enabling of the clone hook, the setting of the hostname
was being done by writing to /etc/hostname.  Instead of relying on that
we're now writing 'local-hostname' into the metadata for the instance.

cloud-init then reads this and sets the hostname properly.

We are also writing /etc/hostname with the new hostname explicitly.  This is
useful/necessary because on network bringup of eth0, dhclient will submit its
hosname.  The updating done by cloud-init occurs to late, and thus
the dhcp request goes out with the un-configured hostname and dns doens't
work correctly.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-22 15:29:06 -05:00
Serge Hallyn
92b0b5bac5 api: convert lxc_wait, lxc_freeze, and lxc_unfreeze
These are the last of the simpler conversions.  Start, execute,
kill, info and attach remain to be done.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
2013-08-21 19:21:56 -05:00
Serge Hallyn
9069513c69 lxc_cgroup: convert to using API
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-21 16:38:53 -05:00
Serge Hallyn
dfb31b25e2 Track snapshot dependencies (v2)
(Will push in a bit barring any objections)

lvm, btrfs, and zfs snapshots each do an ok job of handling deletions
for us - a btrfs snapshot does fine after the original is removed,
while zfs and lvm will both refuse to allow the original to be deleted
while the snapshot exists.

Overlayfs doesn't do this for us.  So, for overlayfs snapshots, track
the dependencies.

When c2 is created as an overlayfs snapshot of dir-backed c1, then

1. c2's lxc_rdepends file will contain

	c1_lxcpath
	c1_lxcname

2. c1's lxc_snapshots will contain "1"

c1 cannot be deleted so long as lxc_snapshots exists and contains
a non-zero number.

The contents of lxc_snapshots and lxc_rdepends are protected by
container_disk_lock() and at lxc_clone by the new container not yet
being accessible.

(Originally I was going to keep them in the container config, but the
problem with using $lxcpath/$name/config is that api users could end up
calling c->save_config() with a cached old value of snapshots/rdepends.)

Changelog:
	aug 21: check for fprintf and fclose failures

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
2013-08-21 16:38:51 -05:00
Serge Hallyn
84bdfb2b4c avoid very unlikely race due to EEXIST
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-20 18:15:06 -05:00
Serge Hallyn
659aa0618c coverity: make indent match nest level
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-20 18:01:07 -05:00
Serge Hallyn
5d9598d7d3 coverity: dont dereference before null check
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-20 17:59:19 -05:00
Serge Hallyn
a09295f841 coverity: don't leak partial_fd
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-20 17:54:19 -05:00
Serge Hallyn
ca6973422d coverity: don't leak open DIR
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-20 17:48:54 -05:00
Serge Hallyn
01efd4d3d9 coverity: correctly handle tpath error case.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-20 16:58:24 -05:00
Serge Hallyn
1fd9bd50ab coverity: ftell returns long, not size_t (which is unsigned)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-20 16:50:25 -05:00
Serge Hallyn
b4569e9321 coverity: don't bother getting template path if we're not going to measure it
This should also fix a memory leak, since we were freeing it under ifdef
but always allocating it.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-20 16:30:36 -05:00
Scott Moser
fb760f7054 ubuntu-cloud-prep: improve overlayfs workaround
the previous 'patch_start' can be vastly simplified now that I better
understand what the bug was.  Instead of wrapping 'start', we only
need to ensure that /etc/init exists inside the overlayfs, so that the
directory that upstart watches is guaranteed to be in the overlay, not
the underlay.

The problem is described under bug 1213925.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 12:36:38 -05:00
Ubuntu
e14f67a7bf cgroup updates: fix several bugs
1. add cgroup_get_subsys_abspath() which returns the absolute
path for a subsystem mount, and use that where needed to actually
set cgroup values

2. cgroup_devices_has_{allow,deny}: don't mix int and boolean
values.  Also, accept 'a *:* rwm" as any whitelist entry for
has_allow().

3. subsys_lists_match(): fix an off-by-one error in calculating
updated oldlen.  (we need to keep the extra char for '\0')

4. return -1, not 0, if lxc_cgroup_attach fails to open
/proc/self/cgroup.

Signed-off-by: Ubuntu <ubuntu@ip-10-181-158-15.ec2.internal>
2013-08-19 12:24:13 -05:00
Christian Seiler
c9ec905567 python/attach: Add function that returns personality for architecture
Adds the arch_to_personality function that looks up an architecture
and returns the corresponding personality. This may be used in
conjunction with the attach/attach_wait keyword argument.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 11:42:08 -05:00
Christian Seiler
01bfae14dd python/attach: export CLONE_NEW* constants to Python
Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 11:42:08 -05:00
Christian Seiler
4f17323e79 cgroup: minor bugfixes so start and attach work again
This fixes some minor bugs in the cgroup logic that made start and
attach fail (at least when all cgroup controllers were mounted
together).

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 11:42:08 -05:00
Christian Seiler
9c6694b707 python/attach: Fix minor memory leaks
Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 11:42:08 -05:00
Christian Seiler
a9cab7e39b attach: Fix minor memory leak in environment variable handling
Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 11:42:08 -05:00
Stéphane Graber
55c76589fd
Remove all trailing whitespaces
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-08-19 14:37:20 +02:00
Stéphane Graber
37fc7b9e2e Fix lxc-user-nic to work on bionic
This adds a couple of missing includes, uses the local version of
getline on bionic and replaces getpwuid_r by getpwuid.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:36 +02:00
Stéphane Graber
e768f9c0f6 Add missing namespace.h include
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:33 +02:00
Stéphane Graber
511a6936c7 Allow building without confstr
We use confstr to grab the default PATH value. If it's not there, just
use a standard one with bin and sbin for /, /usr and /usr/local.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:31 +02:00
Stéphane Graber
1a2e58cf55 Don't define new_personality when building without personalities
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:28 +02:00
Stéphane Graber
5ec279894e Add missing sys/socket.h include
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:26 +02:00
Stéphane Graber
a3da2f3bd7 Define SOCK_CLOEXEC when missing
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:23 +02:00
Stéphane Graber
7f3e12f3e5 Use srand/rand instead of initstate/random
initstate/random doesn't work on bionic, srand/rand works on everything,
so let's use that.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:21 +02:00
Stéphane Graber
2e74d6f374 Include stdio.h in getline.h for FILE
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:18 +02:00
Stéphane Graber
120ce443c4 Import local getline copy on bionic
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:15 +02:00
Stéphane Graber
2b89a9c19d Add missing sys/select.h include for fd_set
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:13 +02:00
Stéphane Graber
ec346ea11f Add missing syscall.h include to utils.h
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:10 +02:00
Stéphane Graber
180edd6702 Add arm defines for __NR_signalfd(4)
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:08 +02:00
Stéphane Graber
590ae88933 Android now uses a sane clone() definition
The current Android NDK provides a clone() defintion that's identical to
eglibc's so we can drop the ifdef from that one.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:05 +02:00
Stéphane Graber
bff13ba210 Define BLKGETSIZE64 and LO_FLAGS_AUTOCLEAR
Those two aren't always around (specifically on bionic), so add some
defines in case they aren't already defined.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:02 +02:00
Stéphane Graber
92adc3e911 Export the local getmntent_r implementation
New code now uses getmntent_r so we need it exported so that it can be
used when building on bionic.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:32:59 +02:00
Stéphane Graber
c32981c3fb Replace all calls to rindex by strrchr
The two functions are identical but strrchr also works on Bionic.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:32:55 +02:00
Stéphane Graber
4ba0d9af63 Add a local implementation of ifaddrs.h
This adds a local ifaddrs implementation to be used on Bionic or other C
libraries that don't come with a getifaddrs implementation.

This code was written by Kenneth MacKay and is under a two-clause BSD
license (copyright information in the file headers).

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:32:41 +02:00
Scott Moser
d24d56d7ee ubuntu-cloud-prep: patch /sbin/start for overlayfs
upstart depends on inotify, and overlayfs does not support inotify.

That means that the following results in 'tgt' not running. tgt is simply
used here as an example of a service that installs an upstart job and
starts it on package install.
 lxc-clone -s -B overlayfs -o source-precise-amd64 -n test1
 lxc-start -n test1
 ..
 apt-get install tgt

The change here is to modify /sbin/start inside the container so that when
something explicitly tries 'start', it results in an explicit call to
'initctl reload-configuration' so that upstart is aware of the newly
placed job.

Should overlayfs ever gain inotify support, this should still not cause
any harm.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-16 16:05:40 -05:00
Serge Hallyn
e3fdf5cc9c lxc-clone: default to overlaysf for -s clone of dir
If you go to the trouble to request a -s (snapshot) clone of
a container which is dir backingstore, then you deserve an
overlayfs clone.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-16 15:50:25 -05:00
Serge Hallyn
6fe93aa187 cgroup.c: remove spurious ERROR messages
Because they are in probing functions.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-08-16 13:34:36 -05:00
Stéphane Graber
d74325c436
Replace a few more str(n)dupa by str(n)dup + free
strdup and strndup still don't exist on bionic, so we need to do the
alloc() call ourselves or free the memory by hand.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-16 15:00:41 +02:00
Stéphane Graber
1d374b9725
Add attach_options.h to the list of included files
Without this, make dist doesn't include it and LXC fails to build.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-08-16 12:09:02 +02:00
Serge Hallyn
fbbf51926e document new lxc-create btrfs behavior
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-15 15:37:30 -05:00
Serge Hallyn
d44e88c266 bdev: support -B best and -B lvm,dir
-B dev will check whether btrfs, zfs, or lvm can be used,
in that order, and fall back to dir.

-B lvm,btrfs will try lvm first, then btrfs, then fail.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-15 15:35:47 -05:00
Serge Hallyn
d3060bd055 bdev_create: don't default to btrfs if possible
Ideally it would be great to default to a btrfs subvolume for each new
container created.  However, this is not as we previously thought
without consequence.  'rsync --one-file-system' will not descend into
btrfs subvolumes.  This means that 'lxc-create -B _unset' will cause
different behavior for rsync -vax /var/lib/lxc based on whether that
fs is btrfs or not.

So don't do that.  If -B is not specified, use -B dir.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-15 15:35:18 -05:00
Alexander Vladimirov
d007f8ab3d Add subdir-objects option to AM_INIT_AUTOMAKE
Fix build with automake 1.14 and newer, since it requires explicit
setting now.

Signed-off-by: Alexander Vladimirov <alexander.idkfa.vladimirov@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-15 15:33:35 -05:00
Michael H. Warfield
bf7d3153c9 lxc-fedrora: New patch for systemd detection and init configuration.
Satoshi Matsumoto certainly had the right idea and in spotting a bug in
the lxc-fedora template for systemd detection.  Heart was in the right
spot but patch was not what we needed.

I've looked the patch code over for systemd support and init/upstart
support and modified the logic appropriately.  If /etc/systemd/system
exists, we'll do the right thing by systemd.  If /etc/rc.sysinit exists,
we'll do the right thing by init / upstart.  If both are installed,
we'll trying and accommodate both in case someone is playing games with
the two (I've done this).

Patch was trivial, just took more time to actually test it and create
some containers with it and verify them, than it did to code them.

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-15 13:32:53 -05:00
Christian Seiler
3d5e9f4801 attach: implement remaining options of lxc_attach_set_environment
This patch implements the extra_env and extra_keep options of
lxc_attach_set_environment.

The Python implementation, the C container API and the lxc-attach
utility are able to utilize this feature; lxc-attach has gained two new
command line options for this.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-14 16:51:31 -05:00