Commit Graph

1697 Commits

Author SHA1 Message Date
Dwight Engen
40650ea681 quiet gcc 4.4.7 warning about saveptr use before initialization
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-20 09:27:28 -05:00
Serge Hallyn
de09eccbed lxc-create: zfs: consistently use zfsroot, not zfs_root
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-05-17 11:35:51 -05:00
Serge Hallyn
dc92f6c7ee document clone hooks
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-16 08:22:41 -05:00
Serge Hallyn
148e91f567 lxc: add clone hook.
Add a clone hook called from api_clone.  Pass arguments to it from
lxc_clone.c.

The clone update hook is called while the container's bdev is mounted.
Information about the container is passed in through environment
variables LXC_ROOTFS_PATH, LXC_NAME, The LXC_ROOTFS_MOUNT, and
LXC_CONFIG_FILE.

LXC_ROOTFS_MOUNT=/usr/lib/x86_64-linux-gnu/lxc
LXC_CONFIG_FILE=/var/lib/lxc/demo3/config
LXC_ROOTFS_PATH=/var/lib/lxc/demo3/rootfs
LXC_NAME=demo3

So from the hook, updates to the container should be made under
$LXC_ROOTFS_MOUNT/ .

The hook also receives command line arguments as follows:
First argument is container name, second is always 'lxc', third
is the hook name (always clone), then come the arguments which
were passed to lxc-clone.  I.e. when I did:

sudo lxc-clone demo2 demo3 -- hey there dude

the arguments passed in were "demo3 lxc clone hey there dude"

I personally would like to drop the first two arguments.  The
name is available as $LXC_NAME, and the section argument ('lxc')
is meaningless.  However, doing so risks invalidating existing
hooks.

Soon analogous create and destroy hooks will be added as well.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-05-16 08:02:06 -05:00
Serge Hallyn
9a93d99213 cgroup: prevent DOS when a hierachy is mounted multiple times
When starting a container, we walk through all cgroup mounts looking
for a unique directory name we can use for this container.  If the
name we are trying is in use, we try another name.  If it is not in
use in the first mount we check, we need to check other hierarchies
as it may exist there.  But we weren't checking whether we have already
checked a subsystem - so that if freezer was mounted twice, we would
create it in the first mount, see it exists in the second, so start
over trying in the second mount.

To fix this, keep track of which subsystems we have already checked,
and do not re-check.

(See http://pad.lv/1176287 for a bug report)

Note we still need to add, at the next: label, the removal of the
directories we've already created.  I'm keeping that for later as
it's far lower priority than this fix, and I don't want to risk
introducing a regression for that.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-16 07:24:21 -05:00
Dwight Engen
6031a6e5f9 set non device cgroup items before the cgroup is entered
This allows some special cgroup items such as memory.kmem.limit_in_bytes
to be successfully set, since they must be set before any task is put
into the cgroup.

The devices cgroup is setup later giving the container a chance to mount
file systems before the device it might want to mount from becomes
unavailable.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-16 07:18:12 -05:00
Dwight Engen
d9e80daf54 doc/lxc.conf minor clarifications
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-16 07:18:09 -05:00
Michael H. Warfield
627fe3b4c3 lxc-fedora-template: autodev, hostname, ARM archs, Raspberry Pi fixes
This took a lot longer for me to get around to it...  Sorry.

Patch to the lxc-fedora template.

I didn't get any further comments from my earlier proposal, weeks ago,
and did get one addition based on comments about properly setting the
hostname in /etc/hostname, which I've added.  I could have broken them
into separate patches but most are pretty small and minor.

Changes:

* Map armv6l and armv7l architectures to "arm" for yum and repos to
function properly.

* Detect Fedora Remix distros with no "/etc/fedora-release" file
(Raspberry Pi) and find proper release versions when "remix" part of the
file context.

* Change default Fedora container on non-Fedora hosts to Fedora 17.

* Added code for autodev for Fedora systemd containers.

* Added code to set /etc/hostname for Fedora > 14 (systemd).

* Fix a few typos.

Regards,
Mike
--
Michael H. Warfield (AI4NB) | (770) 985-6132 |  mhw@WittsEnd.com
   /\/\|=mhw=|\/\/          | (678) 463-0932 |  http://www.wittsend.com/mhw/
   NIC whois: MHW9          | An optimist believes we live in the best of all
 PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!
--

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-15 12:28:12 -05:00
Bogdan Purcareata
794fb287b3 lxc-busybox: check when bind-mounting host libdirs
The patch removes the behavior of automatically mounting /lib
and /usr/lib, since this is duplicated a few lines below. It will
also remove the risk of failing when one of these entries are not
present on the host - e.g. on a 64bit machine.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-15 12:26:23 -05:00
Serge Hallyn
807732062e lxc-cirros updates
fix userdata consumption

patch for console issue

Signed-off-by: Scott Moser <scott.moser@canonical.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-14 08:24:27 -05:00
Serge Hallyn
58a46e0621 add lxc-cirros
Add a template to create a cirros container.  One great thing about
cirros is that the image you download is 3.5M.

Thanks smoser!

Note by default /etc/inittab doesn't have a /dev/console entry, so you
don't get a login on the lxc-start console.  Adding

console::respawn:/sbin/getty 115200 console

makes that work, but ctrl-c still gets forwarded to init which then
reboots.  So I didn't bother adding console as part of the template
(yet).  Instead I simply lxc-start -d, then lxc-console.

Signed-off-by: Scott Moser <scott.moser@canonical.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-14 08:15:16 -05:00
Dwight Engen
714540763b serialize multiple threads doing lxcapi_start()
The problem is that the fd table is shared between threads and if a thread
forks() while another thread has an open fd to the monitor, the duped fd
in the fork()ed child will not get closed, thus causing monitord to stay
around since it thinks it still has a client. This only happened when
calling lxcapi_start() in the daemonized case since that is the only time
we try to get the status from the monitor.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-13 12:21:51 -05:00
Dwight Engen
304143a823 lxc-shutdown: fix lxc_path variable
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-08 19:58:57 -05:00
Dwight Engen
8d06bd135a lxc-monitor multiple paths
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-08 13:00:08 -05:00
Serge Hallyn
566c0d6dce lxc-ps: handle cgroup collisions
A few months ago cgroup handling in lxc was updated so that if
/sys/fs/cgroup/$cgroup/lxc/$container already exists (most often
due to another container by the same name under a different lxcpath),
then /sys/fs/cgroup/$cgroup/lxc/${container}-N would be used.

lxc-ps was never updated to handle this.  Fix that.

(Note, the ns cgroup is being special cased there, but I don't
really believe ns cgroup works any more.)

It would be preferable to rewrite lxc-ps in python or in C, but
this at least makes the basic lxc-ps work in the case of multiple
containers with the same name.

Changelog:
	fix missing fi.
	replace 'z1' with '$container' as pointed out by Christian

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-08 12:47:42 -05:00
Serge Hallyn
7f4717c293 conf.c: remove a break
commit ab81cef053 meant to remove the
added break, but apparently i had not done 'git add' before commit
--amend.  Remove the added break.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-07 15:33:42 -05:00
Dwight Engen
dd66e5adb3 coverity: fix potential dereference NULL returned from malloc
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-05-07 13:27:09 -04:00
Dwight Engen
f2bbe86da4 coverity: check return from waitpid
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-05-07 13:27:06 -04:00
Dwight Engen
3856bc9ff5 coverity: clonetest: check correct container is cloned
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-05-07 13:27:03 -04:00
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