Commit Graph

1578 Commits

Author SHA1 Message Date
Dwight Engen
5ca6c34bde coverity: condition already checked for
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-05-07 13:26:59 -04:00
Dwight Engen
42fb4b1585 coverity: open can return 0 as an fd, change error check to < 0
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-05-07 13:26:57 -04:00
Dwight Engen
91c908ee8e coverity: free malloc'ed memory in error case
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-05-07 13:26:54 -04:00
Dwight Engen
ab81cef053 coverity: fix dereference NULL return value
also break once we have found root, no need to search the rest of the mounts

Changelog: May 6: Serge: don't add the break.  (see m-l)

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-06 19:10:09 -05:00
Harald Dunkel
7c7ec7a8ed support alternate container path in lxc-netstat.in
Signed-off-by: Harald Dunkel <harald.dunkel@aixigo.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-06 01:12:54 -05:00
Harald Dunkel
8ee3042a54 lxc-create: add missing -P option for running lxc-destroy
Signed-off-by: Harald Dunkel <harald.dunkel@aixigo.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-06 01:12:35 -05:00
Harald Dunkel
d2c8186b4d support alternate container path in lxc-shutdown
Signed-off-by: Harald Dunkel <harald.dunkel@aixigo.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-06 01:09:55 -05:00
Dwight Engen
a9bafa1085 coverity: fix dereference before NULL check
also fixed some error strings while here

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-03 16:39:14 -05:00
Serge Hallyn
3c73b55472 remove leftover debug cruft (thanks, Dwight)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-03 16:36:08 -05:00
Dwight Engen
a747894428 coverity: ftell returns a signed value
The check for flen < 0 could never have been true since flen was declared
to be size_t (unsigned). Declare flen to be long since that is what ftell
returns.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-03 13:04:19 -05:00
Serge Hallyn
8fb86a37da confile.c:config_network_ipv6_gateway: only define gw in needed scope
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-03 12:28:06 -05:00
Dwight Engen
bec695f3ec coverity: fix leak when ipv6 gw is auto
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-03 12:26:18 -05:00
Dwight Engen
8950ee8ebf coverity: fix leak in error case
Since lxc_execute() is available through the library and is exposed via
the API we cannot be sure the caller will immediately exit, so we should
take care to free the allocated memory.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-03 12:26:17 -05:00
Dwight Engen
a2eea3c197 coverity: ensure string is null terminated, return in
error case

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-03 12:26:15 -05:00
Weng Meiling
2d4bcb9615 lxc_start: free the conf if starting the container fails
When running lxc-start command with valgrind, it reports a memory leak error.
When lxc-start command fails, the conf which is from malloc has not been released.
This patch fix the problem.

Signed-off-by: Weng Meiling <wengmeiling.weng@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-03 12:26:11 -05:00
Weng Meiling
fc7e88640c add free conf->rcfile in lxc_conf_free
when releasing the conf, add free conf->rcfile which is from malloc

Signed-off-by: Weng Meiling <wengmeiling.weng@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-03 12:26:10 -05:00
Serge Hallyn
b85ab7989e ubuntu templates: add comments to show how to enable nesting
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-02 16:28:10 -05:00
Serge Hallyn
375c2258b2 clone: a few fixes
clean up error case in clone, which in particular could cause double
lxc_container_put(c2)

for overlayfs, handle (with error message) all bdev types.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-02 08:31:07 -05:00
Dwight Engen
e0b0b533fe allow lxc-init to log when rootfs not given
On Mon, 29 Apr 2013 14:44:47 -0500
Serge Hallyn <serge.hallyn@ubuntu.com> wrote:

> Quoting Dwight Engen (dwight.engen@oracle.com):
> > So I did this, only to realize that lxc-init is passing "none" for
> > the file anyway, so it currently doesn't intend to log. This makes
> > me think that passing NULL for lxcpath is the right thing to do in
> > this patch. If you want me to make it so lxc-init can log, I can do
> > that but I think it should be in a different change :)
>
> That actually would be very useful, but as you say that's a different
> feature - thanks.

... and here is said change.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-02 08:19:36 -05:00
Serge Hallyn
eee3ba81c8 templates: deny writes to host's clock (v2)
Don't allow write to /dev/rtc0, and remove sys_time.

Thanks, Christoph.

v2: drop sys_time, sys_module, mac_admin and mac_override in
all templates.

Reported-by: Christoph Mitasch <cmitasch@thomas-krenn.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-01 14:00:41 -05:00
Dwight Engen
ee25a44fd3 log.c: always use dir when lxcpath is not default
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 16:07:52 -05:00
Serge Hallyn
b338c81b9f lxc.functions.in: add missing backquote
Reported by both Dwight and S.Çağlar - thanks.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 14:46:12 -05:00
Serge Hallyn
385e7a431a lxc.functions.in: use the right parameter to lxc-config to get lxcpath
Reported-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 14:25:11 -05:00
Serge Hallyn
b164a17f9b remove lxc-clone-sh
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 14:25:11 -05:00
S.Çağlar Onur
ec471210d9 Update .gitignore
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 14:25:11 -05:00
S.Çağlar Onur
0fc0d057c3 silence "sh: 1: zfs: not found" errors on systems without ZFS
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 14:25:11 -05:00
Serge Hallyn
a8428dfa2c introduce lxc_config
It's a tiny program (exported through the api) wrapping the util.c
helpers for reading /etc/lxc/lxc.conf variables, and replaces
the kludgy shell duplication in lxc.functions.in

Changelog: Apr 30: address feedback from Dwight
	(exit error on failure, and use 'lxcpath' as name, not
	'default_path').

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
2013-04-30 09:15:44 -05:00
Serge Hallyn
1e1bb42a8f add vg and zfsroot options to lxc.functions and use in lxc-create
also make sure to drop spaces between = and variable in lxc.conf

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 09:14:34 -05:00
Serge Hallyn
31a95fecd2 allow site-wide customization of zfsroot and lvm vg
/etc/lxc/lxc.conf can contain

	zfsroot = custom1
	lvm_vg = vg0

(Otherwise the defaults are 'lxc' for lvm_vg, and 'lxc' for zfsroot)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 09:14:30 -05:00
Serge Hallyn
ca52dcb559 Several backing store improvements
allow copy clones from other bdevs

for lvm and zfs, as we don't yet support passing options, only default
VG of 'lxc' and default zfsroot of 'tank' are supported when converting
another backing store type.

refuse deletion of container which has lvm or zfs snapshots.
	Note that since a zfs clone must be made from a zfs snapshot,
	which is made from the original zfs fs, even after we
	lxc-destroy the snapshotted container we still must manually
	remove the snapshot.  This can be handled automatically, by
	looking for snapshots where c1 is the original, c2 is the clone,
	tank/c2 no longer exists, but tank/c1@c2 does.  We can then
	remove tank/c1@c2 and feel free to remove tank/c1.  This patch
	does NOT do that yet.

Make sure not to return when we're a forked child.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 09:14:26 -05:00
Serge Hallyn
3baa76fe36 implement zfs bdev and clone
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 09:14:21 -05:00
Serge Hallyn
9be5377379 implement backend drivers and container clone API (v3)
1. commonize waitpid users to use a single helper.  We frequently want
to run something in a clean namespace, or fork off a script.  This
lets us keep the function doing fork:(1)exec(2)waitpid simpler.

2. start a blockdev backend implementation.  This will be used for
mounting, copying, and snapshotting container filesystems.

3. implement btrfs, lvm, directory, and overlayfs backends.

4. For overlayfs, support a new lxc.rootfs format of
'bdevtype:<extra>'.  This means you can now use overlayfs-based
containers without using lxc-start-ephemeral, by using
lxc.rootfs = overlayfs:/readonly-dir:writeable-dir

5. add a set of simple clone testcases

6. Write a new lxc_clone.c based on api clone.

Still to do (there's more, but off top of my head):

1. support zfs, aufs
2. have clone handle other mount entries (right now it only clones
the rootfs)
3. python, lua, and go bindings (not me :)
4. lxc-destroy: if lvm backing store, check for snapshots of it.
   (what about directories which have overlayfs clones?)

Changes since v2:
	Initialize random generator when picking new macaddr (reported
	  by caglar@10ur.org)
	Fix wrong use of bitmask flags
	On copy-clone of btrfs, create a subvolume
	lxc_clone.c: respect the command line usage of the old script
	lxc-clone(1): update documentation
	Refuse to try changing backing stores expect to overlayfs, as
	  it is not implemented (yet) anyway.

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

Conflicts:
	src/lxc/utils.h
2013-04-30 09:12:42 -05:00
Dwight Engen
ab1bf971d2 Create log file in lxcpath for non-system containers
On Fri, 26 Apr 2013 10:18:12 -0500
Serge Hallyn <serge.hallyn@ubuntu.com> wrote:

> Quoting Dwight Engen (dwight.engen@oracle.com):
> > On Fri, 26 Apr 2013 09:37:49 -0500
> > Serge Hallyn <serge.hallyn@ubuntu.com> wrote:
> >
> > > Quoting Dwight Engen (dwight.engen@oracle.com):
> > > > Using lxc configured with --enable-configpath-log, and
> > > > specifying a path to the lxc commands with -P, the log file
> > > > path is generated with a basename of LOGPATH instead of the
> > > > lxcpath. This means for example if you do
> > > >
> > > > lxc-start -P /tmp/containers -n test01 -l INFO
> > > >
> > > > your log file will be
> > > >
> > > > /var/lib/lxc/test01/test01.log
> > > >
> > > > I was expecting the log to be /tmp/containers/test01/test01.log.
> > > > This is particularly confusing if you also have test01 on the
> > > > regular lxcpath. The patch below changes the log file path to be
> > > > based on lxcpath rather than LOGPATH when lxc is configured with
> > > > --enable-configpath-log.
> > > >
> > > > I think that even in the normal non --enable-configpath-log case
> > > > we should consider using lxcpath as the base and not having
> > > > LOGPATH at all, as attempting to create the log files
> > > > in /var/log is not going to work for regular users on their own
> > > > lxcpath. If we want that, I'll update the patch to do that as
> > > > well.
> > >
> > >
> > > Perhaps we should do:
> > >
> > > 	1. If lxcpath == default_lxc_path(), then first choice is
> > > 	   LOGPATH, second is lxcpath/container.log
> > > 	2. when opening, if first choice fails, use second choice
> > > 	   if there is any.
> > >
> > > That way 'system' containers will go to /var/log/lxc, as I think
> > > they should.  Custom-lxcpath containers should never go
> > > to /var/log/lxc, since their names could be dups of containers in
> > > default_lxc_path(). And if the system is a weird one where
> > > default_lxc_path is set up so that an unprivileged user can use
> > > it, then we should log into $lxcpath.
> >
> > That sounds good to me. So these rules would apply in both the
> > regular and --enable-configpath-log cases.

I updated the patch to try to open the log file according to the
choices given above. Along the way I cleaned up log.c a bit, making
some things static, grouping external interfaces together, etc...
Hopefully that doesn't add too much noise.

> > > (Note this patch will trivially conflict with my new lxc_clone.c
> > > causing it to fail to build - unfortunate result of timing)
> >
> > Yeah unfortunately this touches every lxc_log_init() caller. I can
> > work on the above logic and re-submit after your new lxc_clone
> > stuff goes in.
>
> No no, I'll just need to remember to update mine.  Don't hold up on
> mine, this is just the nature of such collaboration  :)
>
> > Did you have any thoughts on the XXX what to pass in for lxcpath in
> > lxc_init? Right now it just falls back to LOGPATH.
>
> No - that's a weird one, since lxc_init runs in the container.  If
> there were only system containers I'd say always use LOGPATH.
> However there are people (apparently :) who use container sharing the
> host's rootfs...
>
> lxc-execute does know the lxcpath.  Perhaps we can simply have
> src/lxc/execute.c:execute_start() look at handler->conf to see if a
> rootfs is set.  If rootfs is NOT set, then pass lxcpath along to
> lxc-init.  Then lxc-init can mostly do the same as the others?  (It
> doesn't use src/lxc/arguments.c, so you'd have to add lxcpath to
> options[] in lxc-init.c)

So I did this, only to realize that lxc-init is passing "none" for the
file anyway, so it currently doesn't intend to log. This makes me
think that passing NULL for lxcpath is the right thing to do in
this patch. If you want me to make it so lxc-init can log, I can do
that but I think it should be in a different change :)

--

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 08:20:17 -05:00
Dwight Engen
7f95145833 fix building docs
Commit 69fe23ff added checking for the older docbook2man back into
configure, but this breaks building the docs on at least Oracle Linux and
Fedora when docbook2X is not installed as docbook2man will be found but the
docs don't actually build with that tool.

This change makes it so the docs can be built with either the older
docbook2man or the newer 2X tools by using configure to set the dtd
string to an appropriate value depending on use of docbook2man or
db2x_docbook2man.

Also fixed a small error in lxc-destroy.sgml.in that was noticed
by the old tools.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-30 08:19:37 -05:00
Serge Hallyn
33c2c3ec93 add zfs support to lxc-create and lxc-destroy
This is based on patch from Papp Tamas (thanks).  It also does some
reorganizing of lxc-create to commonize some of the backingstore handling.

I played with it using:

	sudo lvcreate -L 100G -n zfs vg0
	sudo zpool create lxc /dev/vg0/zfs
	sudo lxc-create -B zfs --zfsroot lxc -t ubuntu -n dir2

or you could

	qemu-img create zfs.img 100G
	sudo qemu-nbd -c /dev/nbd0 zfs.img
	sudo zpool create lxc /dev/nbd0
	sudo lxc-create -B zfs --zfsroot lxc -t ubuntu -n dir2

I'll write the bdev.c handler and hook up lxc-clone next.

This also fixses a bug in the sed expression to extract the rootfs from
container config, which prepended an extra '/' to the rootdev.  (That
caused the zfs list entry not to match at destroy)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Cc: Papp Tamas <tompos@martos.bme.hu>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-26 10:00:15 +02:00
Dwight Engen
f485f377a1 lxc_wait should start monitord
If lxc_wait is called before the container has started the socket will not
yet have been created and lxc_wait's connect to it will fail. Starting the
daemon will create the socket for lxc_wait to connect to.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-26 09:54:29 +02:00
Christian Seiler
4f43438c47
lxc_attach: Use clone() instead of second fork()
Because of an assertion in glibc's fork() wrapper that parent pid and
pid of child should never be the same, one should avoid fork() after
attaching to a PID namespace, since the pid inside the namespace may
coincide with the pid of the parent outside the namespace, thus hitting
the aforementioned assertion.

This patch just changes the code in the most simple manner to use
clone() instead of fork(). Since clone() requires a function to be
called instead of returning 0, we move the code of the child into a
function child_main.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-25 18:17:53 +02:00
Stéphane Graber
6320e49454
lxc.conf: Add reference to capabilities manpage
This adds a reference to capabilities(7) to the lxc.conf manpage.

Signed-off-by: Tomáš Pospíšek <tpo_deb@sourcepole.ch>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-25 17:31:34 +02:00
Peter Simons
69fe23ff07
configure: support for the "docbook2man" utility to build the documentation
This adds docbook2man as an alternative name for the docbook compiler.
As that name was used on Debian based systems for an older version of the tool,
this change also adds a check so that docbook2man is never used on Debian based
systems.

Reported-by: Peter Simons <simons@cryp.to>
Reported-by: Christian Bühler christian@cbuehler.de
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-25 15:29:51 +02:00
Serge Hallyn
f05699d19e Revert "monitor.c: sanity check on waitpid return value"
It's reported to errors in parallel starts.

Reported-by: "S.Çağlar Onur" <caglar@10ur.org>

This reverts commit 6b79166952.
2013-04-24 22:47:50 -05:00
Serge Hallyn
6b79166952 monitor.c: sanity check on waitpid return value
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-24 19:59:10 -05:00
Serge Hallyn
e8b9ac8fdf close fd on error path
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-24 19:49:59 -05:00
Serge Hallyn
4fa22bfca1
lxc-create: cleanup whenever exiting with error
Otherwise we leave bad containers sitting around and further confuse
things on retries.

Reported-by: Mukanyiligira Didacienne <siyana223@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-25 01:54:39 +02:00
Dwight Engen
e51d489512
Allow multiple monitor clients
This fixes a long standing issue that there could only be a single
lxc-monitor per container.

With this change, a new lxc-monitord daemon is spawned the first time
lxc-monitor is called against the container and will accept connections
from any subsequent lxc-monitor.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-25 01:38:26 +02:00
Stéphane Graber
dc7f65454e
ubuntu: Don't break when the locale is C.*
Update the code to also match C.* so that C.UTF-8 doesn't make the
container creation fail.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-25 01:31:11 +02:00
S.Çağlar Onur
0a9362f574
Support starting containers concurrently
Trying to start multiple containers concurrently may cause
lxc_monitor_read_timeout to fail as select call could be
interrupted by a signal, handle it.

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-25 01:30:42 +02:00
Stéphane Graber
15451ecf74
python: Make the code compatibly with 3.2
The previous change used some 3.3-specific functions.
We still support 3.2 so revert to 3.2-compatible calls.

Reported-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-24 18:47:42 +02:00
Stéphane Graber
6516ad8b01
python: Fix convert_tuple_to_char_pointer_array
This finally fixes a few issues with the magic
convert_tuple_to_char_pointer_array function.

This now clearly copies the char* from the python object so we don't
end up keeping reference to those.

Also add the few required free calls to free the content of the array.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-24 15:08:32 +02:00
Stéphane Graber
93d564edc5
cgroup: Remove unused mntent variables
Spotted by coverity, we were now assigning mntent but only every using
mntent_r, so drop those variables and assignation.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-24 11:41:45 +02:00
S.Çağlar Onur
fd37327f57
Support stopping containers concurrently
Trying to stop multiple containers concurrently ends up with "cgroup is not mounted" errors as multiple threads corrupts the shared variables.
Fix that stack corruption and start to use getmntent_r to support stopping multiple containers concurrently.

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-24 01:01:08 +02:00