]> git.proxmox.com Git - mirror_lxc.git/log
mirror_lxc.git
11 years agoarguments: remove trailing slashes for the input lxcpath
Qiang Huang [Tue, 24 Sep 2013 07:27:55 +0000 (15:27 +0800)]
arguments: remove trailing slashes for the input lxcpath

In lxc_cmd(), we use
snprintf(path, len, "%s/%s/command", lxcpath ? lxcpath : inpath, name);
to fill sock name, this assume lxcpath have no trailing slashes, so
if we use
lxc-info -n test -P /usr/local/var/lib/lxc_anon/
to get a running container's state, we will get state: STOPPED which
is wrong, because we combine a wrong sock name.

To fix this, just remove trailing slashes when parsing arguments.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agodoc: Fixed my first name
Stéphane Graber [Sat, 21 Sep 2013 22:43:48 +0000 (17:43 -0500)]
doc: Fixed my first name

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agodoc: Make everything use the @docdtd@ variable
Stéphane Graber [Sat, 21 Sep 2013 22:43:47 +0000 (17:43 -0500)]
doc: Make everything use the @docdtd@ variable

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd some missing comments to configure.ac
Stéphane Graber [Sat, 21 Sep 2013 22:43:46 +0000 (17:43 -0500)]
Add some missing comments to configure.ac

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoConsistently use <lxc/lxccontainer.h> for the API
Stéphane Graber [Sat, 21 Sep 2013 22:43:45 +0000 (17:43 -0500)]
Consistently use <lxc/lxccontainer.h> for the API

The API header was included in a variety of ways before, standardize
those to "include <lxc/lxccontainer.h>" as this will always work both in
tree and on a system with the headers installed.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoWhen callback of one config line fail, we'd better give the exactly
Qiang Huang [Mon, 23 Sep 2013 16:23:27 +0000 (11:23 -0500)]
When callback of one config line fail, we'd better give the exactly
info to help users locate the misconfig.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoreturn the result of the lxcapi_want_close_all_fds call to the caller
S.Çağlar Onur [Sat, 21 Sep 2013 17:00:15 +0000 (13:00 -0400)]
return the result of the lxcapi_want_close_all_fds call to the caller

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoExpose underlying close_all_fds config value via API
S.Çağlar Onur [Fri, 20 Sep 2013 22:45:21 +0000 (18:45 -0400)]
Expose underlying close_all_fds config value via API

Being able to set close_all_fds via API would be usefull for the
situations like running an application (let's say web server)
that controls the lifecycle of the container using the LXC API.
We don't want forked process to inherit parent's resource (file, socket, ...)

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agofix console deadlocks
Serge Hallyn [Fri, 20 Sep 2013 19:24:36 +0000 (21:24 +0200)]
fix console deadlocks

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolxc-create: add -P to --lxcpath option help text
Serge Hallyn [Wed, 18 Sep 2013 19:00:02 +0000 (14:00 -0500)]
lxc-create: add -P to --lxcpath option help text

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoRemove trailing whitespaces
Stéphane Graber [Wed, 18 Sep 2013 19:40:20 +0000 (14:40 -0500)]
Remove trailing whitespaces

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoAdd get_interfaces to the API
S.Çağlar Onur [Wed, 18 Sep 2013 19:13:22 +0000 (15:13 -0400)]
Add get_interfaces to the API

get_ips accepts an interface name as a parameter but there was no
way to get the interfaces names from the container. This patch
introduces a new get_interfaces call to the API so that users
can obtain the name of the interfaces.

Support for python bindings also introduced as a part of this version.

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agomake heavier use of process_lock (v2)
Serge Hallyn [Mon, 16 Sep 2013 23:28:41 +0000 (18:28 -0500)]
make heavier use of process_lock (v2)

pthread_mutex_lock() will only return an error if it was set to
PTHREAD_MUTEX_ERRORCHECK and we are recursively calling it (and
would otherwise have deadlocked).  If that's the case then log a
message for future debugging and exit.  Trying to "recover" is
nonsense at that point.

process_lock() was held over too long a time in lxcapi_start()
in the daemonize case.  (note the non-daemonized case still needs a
check to enforce that it must NOT be called while threaded).  Add
process_lock() at least across all open/close/socket() calls.

Anything done after a fork() doesn't need the locks as it is no
longer threaded - so some open/close/dups()s are not locked for
that reason.  However, some common functions are called from both
threaded and non-threaded contexts.  So after doing a fork(), do
a possibly-extraneous process_unlock() to make sure that, if we
were forked while pthread mutex was held, we aren't deadlocked by
nobody.

Tested that lp:~serge-hallyn/+junk/lxc-test still works with this
patch.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Tested-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoadd arguments with getopt to concurrent tester
Dwight Engen [Mon, 16 Sep 2013 20:17:54 +0000 (16:17 -0400)]
add arguments with getopt to concurrent tester

- add ability to run for multiple iterations
- can also run non-threaded for comparison to threaded case

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years ago.gitignore generated Japanese manpages
Dwight Engen [Mon, 16 Sep 2013 20:25:38 +0000 (16:25 -0400)]
.gitignore generated Japanese manpages

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoubuntu templates: make pstore fstab entry optional
Serge Hallyn [Mon, 16 Sep 2013 16:48:38 +0000 (11:48 -0500)]
ubuntu templates: make pstore fstab entry optional

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocgroup: add bdev.h to fix the build error
Qiang Huang [Sat, 14 Sep 2013 08:36:27 +0000 (16:36 +0800)]
cgroup: add bdev.h to fix the build error

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoRevert "api_create and api_start: work toward making them thread-safe"
Serge Hallyn [Sat, 14 Sep 2013 18:09:53 +0000 (13:09 -0500)]
Revert "api_create and api_start: work toward making them thread-safe"

This should deadlock with daemonized start due to af_unix changes.

Do this later, but do it more carefully.

This reverts commit 002f3cff4d83c0666cfda40599eded8e0d638c6c.

11 years agoapi_create and api_start: work toward making them thread-safe
Serge Hallyn [Sat, 14 Sep 2013 02:19:42 +0000 (21:19 -0500)]
api_create and api_start: work toward making them thread-safe

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoconcurrent: take lxc template to use as argument
Serge Hallyn [Sat, 14 Sep 2013 17:54:46 +0000 (12:54 -0500)]
concurrent: take lxc template to use as argument

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoadd pstore to container fstab
Serge Hallyn [Fri, 13 Sep 2013 20:43:56 +0000 (15:43 -0500)]
add pstore to container fstab

Otherwise user-namespace containers will hang on mountall.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agouse busybox instead of ubuntu to test as it's much more lightweight, also wait contai...
S.Çağlar Onur [Fri, 13 Sep 2013 18:41:48 +0000 (14:41 -0400)]
use busybox instead of ubuntu to test as it's much more lightweight, also wait containers to enter desired state

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agotests: Introduce lxc-test-concurrent for testing basic actions concurrently
S.Çağlar Onur [Thu, 12 Sep 2013 21:13:15 +0000 (17:13 -0400)]
tests: Introduce lxc-test-concurrent for testing basic actions concurrently

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agosnapshots: add man page and fix up help info a bit.
Serge Hallyn [Thu, 12 Sep 2013 20:07:11 +0000 (15:07 -0500)]
snapshots: add man page and fix up help info a bit.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoChange rootfs pinning mechnism
Christian Seiler [Thu, 12 Sep 2013 20:00:34 +0000 (22:00 +0200)]
Change rootfs pinning mechnism

Chane pinning mechanism: Use $rootfs/lxc.hold instead of $rootfs.hold
(in case $rootfs is a mountpoint itself), but delete the file
immediately after creating it (but keep it open). This will keep the
root filesystem busy but does not leave any unnecessary files lying
around.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoSupport for automatic mounting of filesystems
Christian Seiler [Wed, 11 Sep 2013 23:44:44 +0000 (01:44 +0200)]
Support for automatic mounting of filesystems

This patch adds the lxc.mount.auto configuration option that allows the
user to specify that certain standard filesystems should be
automatically pre-mounted when the container is started.

Currently, four things are implemented:

 - /proc          (mounted read-write)
 - /sys           (mounted read-only)
 - /sys/fs/cgroup (special logic, see mailing list discussions)
 - /proc/sysrq-trigger (see below)

/proc/sysrq-trigger may be used from within a container to trigger a
forced host reboot (echo b > /proc/sysrq-trigger) or do other things
that a container shouldn't be able to do. The logic here is to
bind-mount /dev/null over /proc/sysrq-trigger, so that that cannot
happen. This obviously only protects fully if CAP_SYS_ADMIN is not
available inside the container (otherwise that bind-mount could be
removed).

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocgroup: Add lxc_setup_mount_cgroup to setup /sys/fs/cgroup inside the container
Christian Seiler [Wed, 11 Sep 2013 23:44:43 +0000 (01:44 +0200)]
cgroup: Add lxc_setup_mount_cgroup to setup /sys/fs/cgroup inside the container

Add funbction to mount cgroup filesystem hierarchy into the container,
allowing only access to the parts that the container should have access
to, but none else.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocgroup: Split legacy 'ns' cgroup handling off from main cgroup handling
Christian Seiler [Wed, 11 Sep 2013 23:44:42 +0000 (01:44 +0200)]
cgroup: Split legacy 'ns' cgroup handling off from main cgroup handling

This patch splits off ns legacy cgroup handling from main cgroup
handling. It moves the creation of the cgroups before clone(), so that
the child will easily know which cgroups it will later belong to. Since
this is not possible for the renaming of the 'ns' cgroup, keep that
part after clone.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoutils: Add lxc_append_paths to join two paths.
Christian Seiler [Wed, 11 Sep 2013 23:44:41 +0000 (01:44 +0200)]
utils: Add lxc_append_paths to join two paths.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoUpdate .gitignore
S.Çağlar Onur [Thu, 12 Sep 2013 16:06:28 +0000 (12:06 -0400)]
Update .gitignore

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoignore ability to init /lxc-monitord.log
Serge Hallyn [Thu, 12 Sep 2013 16:17:11 +0000 (11:17 -0500)]
ignore ability to init /lxc-monitord.log

We may long-term want to instead decide on a convention under
/var/log, but for now just ignore it.  This will only happen
if lxcpath is read-only.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agohash lxcname for use in monitor unix socket sun_path[108]
Dwight Engen [Wed, 11 Sep 2013 22:16:15 +0000 (18:16 -0400)]
hash lxcname for use in monitor unix socket sun_path[108]

- Also convert to unix abstract socket
- A simple FNV hash is used instead of SHA-1 since we may not HAVE_GNUTLS

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocgroup: address some style+safety issues
Serge Hallyn [Wed, 11 Sep 2013 21:58:12 +0000 (16:58 -0500)]
cgroup: address some style+safety issues

three issues raised by Christian Seiler: use pid_t, use snprintf,
and use const.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agomove monitor-fifo and monitor-sock to /run
Dwight Engen [Wed, 11 Sep 2013 15:44:19 +0000 (11:44 -0400)]
move monitor-fifo and monitor-sock to /run

Moving these files should allow $lxcpath to be a read-only fs.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocgroup: re-introduce ns cgroup support
Serge Hallyn [Wed, 11 Sep 2013 16:50:54 +0000 (11:50 -0500)]
cgroup: re-introduce ns cgroup support

If a cgroup hierarchy has ns cgroup composed, then we need to treat
that differently:

1. The container init will have already been switched to a new cgroup
called after its pid.
2. We can't move the container init to new deeper cgroup directories.

So, if we detect an ns cgroup, don't bother trying to construct a new
name according to the pattern.  Just rename the current one to the
container name, and save that path for us to later enter and remove.

Note I'm not dealing with the subpaths so nested containers probably
won't work.  However as ns cgroup is very much legacy, that should be
ok.  Eventually we should be able to drop ns cgroup support altogether,
but not just yet.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoapparmor.c: drop newline when reading current profile
Serge Hallyn [Tue, 10 Sep 2013 22:23:22 +0000 (17:23 -0500)]
apparmor.c: drop newline when reading current profile

Otherwise we fail to recognize if we are already unconfined.  Then,
if we want to *start* unconfined, and /proc is readonly, start fails
even though it should be able to proceed.

With this patch, that situation works.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Reported-by: Andre nathan <andre@digirati.com.br>
11 years agoFix some typos
Stéphane Graber [Wed, 11 Sep 2013 14:01:16 +0000 (10:01 -0400)]
Fix some typos

Signed-off-by: KATOH Yasufumi karma@jazz.email.ne.jp
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agopin_rootfs: be quiet and don't fail container start
Serge Hallyn [Wed, 11 Sep 2013 04:17:46 +0000 (23:17 -0500)]
pin_rootfs: be quiet and don't fail container start

It's a legitimate use case to use read-only $lxcpath.  If we can't
create the pin file, then we're not worried about marking the fs
readonly on exit.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc_cgroup_process_info_free_and_remove should recursively call itself
Serge Hallyn [Tue, 10 Sep 2013 19:33:40 +0000 (14:33 -0500)]
lxc_cgroup_process_info_free_and_remove should recursively call itself

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agodon't use cgroup_path_components un-initialized
Serge Hallyn [Tue, 10 Sep 2013 19:33:00 +0000 (14:33 -0500)]
don't use cgroup_path_components un-initialized

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocgroup: Major rewrite of cgroup logic
Christian Seiler [Sun, 8 Sep 2013 18:50:03 +0000 (20:50 +0200)]
cgroup: Major rewrite of cgroup logic

This patch rewrites most of the cgroup logic. It creates a set of data
structures to store the kernel state of the cgroup hierarchies and
their mountpoints.

Mainly, everything is now grouped with respect to the hierarchies of
the system. Multiple controllers may be mounted together or separately
to different hierarchies, the data structures reflect this.

Each hierarchy may have multiple mount points (that were created
previously using the bind mount method) and each of these mount points
may point to a different prefix inside the cgroup tree. The current
code does not make any assumptions regarding the mount points, it just
parses /proc/self/mountinfo to acquire the relevant information.

The only requirement is that the current cgroup of either init (if
cgroup.pattern starts with '/' and the tools are executed as root) or
the current process (otherwise) are accessible. The root cgroup need
not be accessible.

The configuration option cgroup.pattern is introduced. For
root-executed containers, it specifies which format the cgroups should
be in. Example values may include '/lxc/%n', 'lxc/%n', '%n' or
'/machine/%n.lxc'. Any occurrence of '%n' is replaced with the name of
the container (and if clashes occur in any hierarchy, -1, -2, etc. are
appended globally). If the pattern starts with /, new containers'
cgroups will be located relative to init's cgroup; if it doesn't, they
will be located relative to the current process's cgroup.

Some changes to the cgroup.h API have been done to make it more
consistent, both with respect to naming and with respect to the
parameters. This causes some changes in other parts of the code that
are included in the patch.

There has been some testing of this functionality, but there are
probably still quite a few bugs in there, especially for people with
different configurations.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoremove unused lxc_read_line_from_file()
Serge Hallyn [Tue, 10 Sep 2013 19:30:43 +0000 (14:30 -0500)]
remove unused lxc_read_line_from_file()

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoutils: Add utility functions that write/read to entire files
Christian Seiler [Sun, 8 Sep 2013 12:14:48 +0000 (14:14 +0200)]
utils: Add utility functions that write/read to entire files

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoutils: Add string and array utility functions
Christian Seiler [Sun, 8 Sep 2013 11:51:50 +0000 (13:51 +0200)]
utils: Add string and array utility functions

Adds a few useful string and array manipulation functions to utils.[ch]

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofopen_cloexec: simplify open call
Serge Hallyn [Tue, 10 Sep 2013 19:29:10 +0000 (14:29 -0500)]
fopen_cloexec: simplify open call

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd fopen_cloexec function to emulate 'e' mode
Christian Seiler [Sun, 8 Sep 2013 11:43:46 +0000 (13:43 +0200)]
Add fopen_cloexec function to emulate 'e' mode

Newer glibc versions (that we can't require) allow for an additional
letter 'e' in the fopen mode that will cause the file to be opened with
the O_CLOEXEC flag, so that it will be closed if the program exec()s
away. This is important because if liblxc is used in a multithreaded
program, another thread might want to run a program. This options
prevents the leakage of file descriptors from LXC. This patch adds an
emulation for that that uses the open(2) syscall and fdopen(3). At some
later point in time, it may be dropped against fopen(..., "...e").

This commit also converts all fopen() calls in utils.c (where the
function is added) to fopen_cloexec(). Subsequently, other calls to
fopen() and open() should also be adapted.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd cgroup.pattern global configuration option
Christian Seiler [Sun, 8 Sep 2013 11:43:13 +0000 (13:43 +0200)]
Add cgroup.pattern global configuration option

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoglobal config: Unify parsing, add additional checks
Christian Seiler [Sun, 8 Sep 2013 11:38:55 +0000 (13:38 +0200)]
global config: Unify parsing, add additional checks

Instead of duplicating the code for parsing the global config file for
each option, write one main function, lxc_global_config_value, that
does the parsing for an arbitrary option name and just call that
function from the existing ones.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoerror.c: don't return error if container init signaled
Serge Hallyn [Mon, 9 Sep 2013 20:35:52 +0000 (15:35 -0500)]
error.c: don't return error if container init signaled

We log that at INFO level in case it is needed.  However, in a modern
kernel a container which was shut down using 'shutdown' will always
have been signaled with SIGINT.  Making lxc-start return an error to
reflect that seems overkill.

It's *conceivable* that someone is depending on this behavior, so I'm
sending this out for anyone to NACK, but if I hear no complaints I'll
apply.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agointroduce lxc-snapshot
Serge Hallyn [Fri, 6 Sep 2013 23:11:05 +0000 (18:11 -0500)]
introduce lxc-snapshot

Hopefully someone else will come in and spruce it up :)  This
version is as simple as can be

lxc-snapshot -n a1
create a snapshot of a1
echo "second commit" > /tmp/a
lxc-snapshot -n a1 -c /tmp/a
create a snapshot of a1 with /tmp/a as a commit comment
lxc-snapshot -n a1 -L
list a1's snapshots
lxc-snapshot -n a1 -L -C
list a1's snapshots along with commit comments
lxc-snapshot -n a1 -r snap0 a2
restore snapshot 0 of a1 as container a2

Some easy nice-to-haves:

1. sort snapshots in the list
2. allow a comment to be given in-line
3. an option to remove a snapshot?

Removing a snapshot can just as well be done with

lxc-destroy -P /var/lib/lxcsnaps/c1 -n snap2

so I leave it to others to decide whether they really want
it, and provide the patch if so.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoAPI support for container snapshots (v2)
Serge Hallyn [Fri, 6 Sep 2013 23:07:47 +0000 (18:07 -0500)]
API support for container snapshots (v2)

The api allows for creating, listing, and restoring of container
snapshots.  Snapshots are created as snapshot clones of the
original container - i.e. btrfs and lvm will be done as snapshot,
a directory-backed container will have overlayfs snapshots.  A
restore is a copy-clone, using the same backing store as the
original container had.

Changelog:

 . remove lxcapi_snap_open, which wasn't defined anyway.
 . rename get_comment to get_commentpath
 . if no newname is specified at restore, use c->name (as we meant to)
   rather than segving.
 . when choosing a snapshot index, use the correct path to check for.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoFixed opensuse template to make lxc-shutdown work.
Cedric Bosdonnat [Tue, 10 Sep 2013 16:00:41 +0000 (18:00 +0200)]
Fixed opensuse template to make lxc-shutdown work.

The fix is described by:
https://wiki.archlinux.org/index.php/Linux_Containers#Container_cannot_be_shutdown_if_using_systemd

Signed-off-by: Cedric Bosdonnat <cbosdonnat@suse.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoAdd Japanese man pages.
KATOH Yasufumi [Thu, 5 Sep 2013 11:38:32 +0000 (11:38 +0000)]
Add Japanese man pages.

Japanese man pages is installed under $mandir/ja.
At this time, it is based on version 0.9.0.

11 years agochange version to 1.0.0.alpha1 in configure.ac
Daniel Lezcano [Tue, 10 Sep 2013 21:55:26 +0000 (23:55 +0200)]
change version to 1.0.0.alpha1 in configure.ac

Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
11 years agoMerge git://github.com/lxc/lxc
Daniel Lezcano [Mon, 9 Sep 2013 19:07:12 +0000 (21:07 +0200)]
Merge git://github.com/lxc/lxc

Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
11 years agoconfigure: enable Lua if found and continue without if not
Natanael Copa [Fri, 6 Sep 2013 19:09:57 +0000 (21:09 +0200)]
configure: enable Lua if found and continue without if not

Search for Lua if no --enable-lua/--disable-lua specified but continue
without if not found.

If --enable-lua is specified and Lua is not found then return error.

If --disable-lua is specified, then don't search for Lua.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolxc_spawn: don't close pinfd until container is stopped
Serge Hallyn [Fri, 6 Sep 2013 17:25:47 +0000 (12:25 -0500)]
lxc_spawn: don't close pinfd until container is stopped

Otherwise containers may be able to remount -o ro their rootfs
at shutdown.

Reported-by: Harald Dunkel <harri@afaics.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: fix logic to enable lua support in configure
Natanael Copa [Fri, 6 Sep 2013 07:08:45 +0000 (09:08 +0200)]
lua: fix logic to enable lua support in configure

When there is no --enable-lua or --with-lua-pc, Lua should not be
enabled.

This fixes a bug introduced with 12e93188 (configure/makefile:
Allow specify Lua pkg-config file with --with-lua-pc) that caused
configure script to fail if lua headers was missing.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agosanity-check number of detected capabilities
Serge Hallyn [Fri, 6 Sep 2013 01:31:55 +0000 (20:31 -0500)]
sanity-check number of detected capabilities

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoadd AS_VAR_COPY for older autoconf versions
Dwight Engen [Thu, 5 Sep 2013 20:40:49 +0000 (16:40 -0400)]
add AS_VAR_COPY for older autoconf versions

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: fix stats gathering
Dwight Engen [Thu, 5 Sep 2013 19:20:44 +0000 (15:20 -0400)]
lua: fix stats gathering

- remove lxc subdir in cgroup paths (done in commit b98f7d6e)
- remove extraneous debug printfs
- remove extra call to stats_clear

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: implement dirname in C rather than depend on external executable
Natanael Copa [Thu, 5 Sep 2013 13:29:20 +0000 (15:29 +0200)]
lua: implement dirname in C rather than depend on external executable

Instead of popen and run external executable dirname we implement a
dirname in C in the core module.

We also remove the unused basename function.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: implement usleep in C module
Natanael Copa [Thu, 5 Sep 2013 12:33:28 +0000 (14:33 +0200)]
lua: implement usleep in C module

So we avoid running os.execute

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoconfigure/makefile: Allow specify Lua pkg-config file with --with-lua-pc
Natanael Copa [Thu, 5 Sep 2013 15:13:07 +0000 (17:13 +0200)]
configure/makefile: Allow specify Lua pkg-config file with --with-lua-pc

Enable support for both Lua 5.1 and 5.2 by letting user specify the Lua
pkg-config package name. By default it will use 'lua' and try figure
out which version it is.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: prepare for Lua 5.2
Natanael Copa [Thu, 5 Sep 2013 06:45:33 +0000 (08:45 +0200)]
lua: prepare for Lua 5.2

Adjust code for Lua 5.2 and keep compatibility with Lua 5.1.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: fix a bug in the parsing of /proc/mounts
Natanael Copa [Thu, 5 Sep 2013 19:07:51 +0000 (15:07 -0400)]
lua: fix a bug in the parsing of /proc/mounts

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoclone: don't copy rdepends when not doing a snapshot clone
Serge Hallyn [Thu, 5 Sep 2013 23:05:34 +0000 (18:05 -0500)]
clone: don't copy rdepends when not doing a snapshot clone

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofix typo
Serge Hallyn [Thu, 5 Sep 2013 22:59:28 +0000 (17:59 -0500)]
fix typo

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agointroduce lxc.cap.keep
Serge Hallyn [Fri, 14 Jun 2013 03:43:01 +0000 (22:43 -0500)]
introduce lxc.cap.keep

The lxc configuration file currently supports 'lxc.cap.drop', a list of
capabilities to be dropped (using the bounding set) from the container.
The problem with this is that over time new capabilities are added.  So
an older container configuration file may, over time, become insecure.

Walter has in the past suggested replacing lxc.cap.drop with
lxc.cap.preserve, which would have the inverse sense - any capabilities
in that set would be kept, any others would be dropped.

Realistically both have the same problem - the sendmail capabilities
bug proved that running code with unexpectedly dropped privilege can be
dangerous.  This patch gives the admin a choice:  You can use either
lxc.cap.keep or lxc.cap.drop, not both.

Both continue to be ignored if a user namespace is in use.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agobdev: free after bdev_init
Serge Hallyn [Thu, 5 Sep 2013 21:56:54 +0000 (16:56 -0500)]
bdev: free after bdev_init

(Except in cases where we will immediately exit)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agovalgrind: fix memory leak on container new/put
Dwight Engen [Wed, 4 Sep 2013 21:04:51 +0000 (17:04 -0400)]
valgrind: fix memory leak on container new/put

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-alpine: add hwaddr for a single macvlan interface
Natanael Copa [Wed, 4 Sep 2013 15:01:09 +0000 (17:01 +0200)]
lxc-alpine: add hwaddr for a single macvlan interface

We already add harware address for a single veth interface. Do the same
with a single macvlan interface.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agobdev_copy segfaults if bdevtype is NULL
S.Çağlar Onur [Tue, 3 Sep 2013 20:21:15 +0000 (16:21 -0400)]
bdev_copy segfaults if bdevtype is NULL

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agotests: Add lxc-test-usernic to the dist tarball
Stéphane Graber [Tue, 3 Sep 2013 19:11:07 +0000 (15:11 -0400)]
tests: Add lxc-test-usernic to the dist tarball

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolicensing: Add missing headers and FSF address
Stéphane Graber [Tue, 3 Sep 2013 18:29:46 +0000 (14:29 -0400)]
licensing: Add missing headers and FSF address

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoubuntu: iproute is now called iproute2
Stéphane Graber [Tue, 3 Sep 2013 15:36:09 +0000 (11:36 -0400)]
ubuntu: iproute is now called iproute2

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agolua: update license
Serge Hallyn [Tue, 3 Sep 2013 12:56:11 +0000 (07:56 -0500)]
lua: update license

As with other files, update to be LGPL since these are part
of the lxc library.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agopython: Fix api_test to use the new attach() API
Stéphane Graber [Fri, 30 Aug 2013 21:27:14 +0000 (17:27 -0400)]
python: Fix api_test to use the new attach() API

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-commands: add a comment explaining CMD_* rules
Serge Hallyn [Tue, 3 Sep 2013 13:08:39 +0000 (08:08 -0500)]
lxc-commands: add a comment explaining CMD_* rules

We wish to ensure that, henceforth, newer lxc tools are always compatible
with older lxc monitors.  Add a comment to commands.c to explain the
rule we wish to enforce to this end.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoremove old stale comments (lxc-clone is now implemented)
Serge Hallyn [Fri, 30 Aug 2013 20:51:31 +0000 (15:51 -0500)]
remove old stale comments (lxc-clone is now implemented)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd a section about licensing to CONTRIBUTING
Stéphane Graber [Fri, 30 Aug 2013 19:56:21 +0000 (15:56 -0400)]
Add a section about licensing to CONTRIBUTING

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agofix license text in ubuntu and ubuntu-cloud templates
Serge Hallyn [Fri, 30 Aug 2013 19:43:09 +0000 (14:43 -0500)]
fix license text in ubuntu and ubuntu-cloud templates

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofix wrong license text for parts of liblxc library
Serge Hallyn [Fri, 30 Aug 2013 19:42:20 +0000 (14:42 -0500)]
fix wrong license text for parts of liblxc library

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoavoid zgrep -q as it's failing on some distros
Stéphane Graber [Fri, 30 Aug 2013 16:08:26 +0000 (12:08 -0400)]
avoid zgrep -q as it's failing on some distros

Reported-by: Filirom1
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agofedora: Add missing double-quotes.
Stéphane Graber [Fri, 30 Aug 2013 15:47:58 +0000 (11:47 -0400)]
fedora: Add missing double-quotes.

Reported-by: tlc
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoFix some typos
Stéphane Graber [Fri, 30 Aug 2013 15:43:19 +0000 (11:43 -0400)]
Fix some typos

Signed-off-by: Dmitry Shachnev <mitya57@ubuntu.com>
Reported-by: Vincent Ladeuil
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agostart.c: handle potential signal flood
Serge Hallyn [Thu, 29 Aug 2013 15:41:19 +0000 (10:41 -0500)]
start.c: handle potential signal flood

Signalfd does not guarantee that we'll get an event for every signal.
So if 3 tasks exit at the same time, we may get only one sigchld
event.  Therefore, in signal_handler(), always check whether init has
exited.  Do with with WNOWAIT so that we can still wait4 to cleanup
the init after lxc_poll() exists (rather than complicating the code).

Note - there is still a race in the kernel which can cause the
container init to become a defunct child of the host init (!).  This
doesn't solve that, but is a potential (if very unlikely) race which
apw pointed out while we were trying to create a reproducer for the
kernel bug.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolxc-alpine: create /dev/zero
Natanael Copa [Mon, 26 Aug 2013 11:47:58 +0000 (13:47 +0200)]
lxc-alpine: create /dev/zero

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoconfig_ipv6: run inet_pton on the addr value without mask
Serge Hallyn [Fri, 23 Aug 2013 17:45:15 +0000 (12:45 -0500)]
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>
11 years agoapi: convert lxc_start
Serge Hallyn [Thu, 22 Aug 2013 15:27:40 +0000 (10:27 -0500)]
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>
11 years agohooks/ubuntu-cloud-prep: add hostname to meta-data
Scott Moser [Thu, 22 Aug 2013 19:38:48 +0000 (15:38 -0400)]
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>
11 years agoapi: convert lxc_wait, lxc_freeze, and lxc_unfreeze
Serge Hallyn [Wed, 21 Aug 2013 21:53:52 +0000 (16:53 -0500)]
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>
11 years agolxc_cgroup: convert to using API
Serge Hallyn [Wed, 21 Aug 2013 19:35:28 +0000 (14:35 -0500)]
lxc_cgroup: convert to using API

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoTrack snapshot dependencies (v2)
Serge Hallyn [Wed, 21 Aug 2013 19:43:52 +0000 (14:43 -0500)]
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>
11 years agoavoid very unlikely race due to EEXIST
Serge Hallyn [Tue, 20 Aug 2013 23:15:06 +0000 (18:15 -0500)]
avoid very unlikely race due to EEXIST

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: make indent match nest level
Serge Hallyn [Tue, 20 Aug 2013 23:01:07 +0000 (18:01 -0500)]
coverity: make indent match nest level

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: dont dereference before null check
Serge Hallyn [Tue, 20 Aug 2013 22:59:19 +0000 (17:59 -0500)]
coverity: dont dereference before null check

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: don't leak partial_fd
Serge Hallyn [Tue, 20 Aug 2013 22:54:19 +0000 (17:54 -0500)]
coverity: don't leak partial_fd

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: don't leak open DIR
Serge Hallyn [Tue, 20 Aug 2013 22:48:54 +0000 (17:48 -0500)]
coverity: don't leak open DIR

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: correctly handle tpath error case.
Serge Hallyn [Tue, 20 Aug 2013 21:58:24 +0000 (16:58 -0500)]
coverity: correctly handle tpath error case.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>