Commit Graph

2483 Commits

Author SHA1 Message Date
Marek Majkowski
02b4f2e1d8 Allow specifying a container by name or pid in --share-net option. 2013-11-11 05:19:29 -08:00
Dwight Engen
293ec75883 add modes argument to lxc-test-concurrent
- This allows testing independently the modes with/without threading

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-08 15:07:34 -06:00
Serge Hallyn
03f064ff74 wait_on_damonized-start: wait only on the pid we want
Otherwise we can reap another thread's forked pid.

Changelog: Per Dwight's suggestion, use pid_t for argument.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: S.Çağlar Onur <caglar@10ur.org>
2013-11-08 13:31:51 -06:00
Serge Hallyn
2d834aa807 api_start: refuse to run undaemonized if multithreaded
lxc-start is not safe (and doesn't actually make sense) if the
task is nto single-threaded.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-08 10:04:21 -06:00
Qiang Huang
94d942c3d2 lxc_user_nic: remove duplicate code
It's a duplicate of util.h.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-07 22:25:26 -06:00
Marek Majkowski
9f30a19089 Enable network namespace sharing in lxc-start
Right now lxc-start always does one of two things: it creates
a new namespace or inherits it from the parent environment.
This patch adds a third option: share a namespace with another
container (actually: a process).

In some situations this is handy. For example by sharing a network
namespace it is possible to migrate services between containers
without (or with little) downtime.

This patch creates an infrastructure for inheriting any type
of namespace, but only the network namespace is supported for now.
2013-11-06 15:16:33 -08:00
Dwight Engen
9beb9ce0ef coverity 1126129: don't try to print c->name when c is NULL
I accidentally introduced this with the change to lxc-info (commit
b9d957c3).

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-06 09:37:21 -06:00
Serge Hallyn
4119204eef lxc-user-nic: rename nic inside container to desired name
To do so we do a quick setns into the container's netns.  This
(unexpectedly) turns out cleaner than trying to rename it from
lxc_setup(), because we don't know the original nic name in
the container until we created it which we do in the parent
after the init has been cloned.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-06 09:04:13 -06:00
Serge Hallyn
57d116ab50 create_run_template: tell the template what caller's uid was mapped to
conf.c/conf.h: have replaced bool hostid_is_mapped() with int mapped_hostid()
   which returns the mapped uid for the caller's uid on the host, or -1 if
   none

create_run_template: pass caller's uid into template.

lxc-ubuntu-cloud:
	1. accept --mapped-uid argument
	2. don't write to devices cgroup - not allowed.
	3. if running in userns, use $HOME/.cache
	4. chown cached files to the uid to which our caller was
	   mapped
	5. ignore /dev when extracting rootfs in a userns

Changelog: nov 5: remove debugging INFO line.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-06 09:04:06 -06:00
Dwight Engen
b9d957c316 add statistics to lxc-info
- allow lxc-info to show more than one container, using regex for the name

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-06 08:15:13 -06:00
Dwight Engen
148a9d276c fix leak in list_active_containers()
Found by running the lxc-test-list test with valgrind. The names were
put into a local array, and never freed in the success case where the
caller didn't want the names returned and in the early out failure case.

Note we don't need to check the return from remove_from_array() because
we just successfully added the name above.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-06 08:11:21 -06:00
Dwight Engen
2c319dbfb5 tests list: refactor and add test for list_all_containers()
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-06 08:11:20 -06:00
Dwight Engen
2871830a40 add list_all_containers(), returns defined and active containers
Changelog: [serge] remove unneeded explicity qsort call

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-06 08:10:54 -06:00
Stéphane Graber
4012c89148
Fix tests on Android
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-05 22:43:38 -05:00
Stéphane Graber
3da0feef09
Only include execinfo.h if MUTEX_DEBUGGING is set
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-05 14:30:30 -05:00
Dwight Engen
c9bb9a85ef fix leak when a veth.pair name is specified
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-05 12:31:59 -05:00
Dwight Engen
8585f20444 lua: add cmd_get_config_item to API
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-05 12:31:48 -05:00
Dwight Engen
6502006a44 allow lxcapi_get_cgroup_item() on lxc-execute containers
Containers started with lxc-execute may not have a conf, but
nothing in the implementation of lxcapi_get_cgroup_item()
actually needs/uses it, and it can be useful to get items out
of the containers' cgroup items.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-05 12:31:40 -05:00
Dwight Engen
2752ecec32 lxc-top: show kernel memory being used if available
- Also removed duplicate stats_clear lua function

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-04 06:37:11 -06:00
Dwight Engen
891f838ba8 lua: fix stats collection using get_cgroup_item
Previously, the lua stats collection was building its own paths to the
cgroup files, which could be wrong depending on what --with-cgroup-pattern
was passed to configure. Fix it to use the get_cgroup_item api so it
always finds the files.

Remove cgroup_path_get since it is not used anymore.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-04 06:37:10 -06:00
Dwight Engen
80ee22284b add [gs]et_cgroup_item to lua api
fix up api test to run and add test for new [gs]et_cgroup_item

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-04 06:37:08 -06:00
S.Çağlar Onur
b12e1cb533 allow setting/getting lxc.loglevel and lxc.logfile via set_config_item/get_config_item API calls
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-04 06:24:16 -06:00
S.Çağlar Onur
497a299568 make sure to check c->lxc_conf is not NULL before dereferencing it.
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-04 06:24:15 -06:00
S.Çağlar Onur
7021548006 ignore tags files that can be created via make ctags target
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-01 16:40:03 -05:00
S.Çağlar Onur
052616ebc6 valgrind drd tool shows conflicting stores happening at lxc_global_config_value@src/lxc/utils.c (v2)
Conflict occurs between following lines

[...]
269         if (values[i])
270                 return values[i];
[...]

and

[...]
309         /* could not find value, use default */
310         values[i] = (*ptr)[1];
[...]

fix it using a specific lock dedicated to that problem as Serge suggested.

Also introduce a new autoconf parameter (--enable-mutex-debugging) to convert mutexes to error reporting type and to provide a stacktrace when locking fails.

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-01 16:40:00 -05:00
Serge Hallyn
4de2791fa7 always remount / rslave before running creation template (if root)
If we're not root, our mounts in private userns won't get pushed
back anyway.  If we are root, we need to make sure that anything
the template does gets cleaned up.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-01 13:21:59 -05:00
Serge Hallyn
0779c6f920 remove a few noisy, unhelpful INFOs in detect_shared_rootfs()
They are a nuisance.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-01 09:11:18 -05:00
Dwight Engen
f25f058d5d remove left over debug getchar()
I goofed and left in a getchar() that I was using to pause the test program
in a case that was failing for me. Remove it.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-30 15:37:11 -05:00
S.Çağlar Onur
83758ed00f daemonize implies close_all_fds so set it in lxcapi_want_daemonize instead of setting in every cli or in every binding explicitly
Reported-by: Fatih Arslan <ftharsln@gmail.com>
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-30 15:33:13 -05:00
Serge Hallyn
0590e82c10 api_create: undo unneeded chunk in previous commit
lxc_conf exists after api_save_config

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-30 12:49:10 -05:00
Serge Hallyn
cf465fe41c api_create and do_bdev_create: a few more fixes
don't use lxcpath variable for rootfs_path, it's confusing.

if rootfs is passed in and tpath is passed in, return error
before we save a new config, and don't delete the container

make sure to check c->lxc_conf is not NULL before dereferencing it.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-30 11:27:04 -05:00
Sheng Yong
cd219ae659 lxc-create: fix conflict of rootfs.path and template default path
1. rootfs.path set, -t not set: rootfs.path is rootfs path
2. rootfs.path set, -t set: change template default path to rootfs path
3. rootfs.path not set, -t set: template default path is rootfs path
4. rootfs.path not set, -t not set: error
5. rootfs.path set but cannot access: error

Signed-off-by: Sheng Yong <shyodx@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-30 10:15:27 -05:00
Sheng Yong
a69aad27ad lxcapi_create: don't delete if container rootfs already exists
If lxc.rootfs is specified, we believe rootfs is ready. lxc-start will
check this later. Return true, because the container is created.

Signed-off-by: Sheng Yong <shyodx@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-30 10:15:26 -05:00
Dwight Engen
86b3688b26 coverity 1097616: don't deref NULL when subsystem doesn't have a '.'
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-10-30 09:52:55 -04:00
Dwight Engen
1f845c396f fix cgpath test
Commit 1ea59ad28 sets memory.use_hierarchy, which means that this test
cannot use memory.swappiness as its dummy cgroup item to set/unset since
writing to it with use_hierarchy set gets -EINVAL. Change test to use
memory.soft_limit_in_bytes instead.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-10-30 09:52:52 -04:00
Dwight Engen
50266dc604 coverity 1097618: check for NULL return from calloc before deref
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-10-29 14:55:08 -04:00
Dwight Engen
4e03ae57ed fix free() of args to startl
Coverity 1076328 marked this as "Use after free", which it isn't really,
its actually just free()ing the wrong 2nd, 3rd, etc... pointers. Test by
passing two or more args to startl, without this change you get segfault
when free()ing the second pointer/arg.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-10-29 14:55:05 -04:00
Serge Hallyn
9588a6cecb rpm spec: fix version numbering when building alpha, beta, rc
We want to ensure smooth upgrades when doing rpm -U throughout the
release cycle so this change implements the scheme documented at:
http://fedoraproject.org/wiki/Packaging%3aNamingGuidelines#NonNumericRelease

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-10-29 14:50:07 -04:00
Dwight Engen
5da6aa8c71 coverity: ifr_name buffer not NULL terminated
The kernel (net/core/dev_ioctl.c:dev_ioctl()) is going to NULL terminate
this name after the copy-in of the ifr, so even though this is a fixed
sized array the last byte isn't usable as part of the name. All the ioctls
we're using go through this code path.

Use the ifr name in the DEBUG message in case it was possibly truncated.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-29 09:38:50 -05:00
S.Çağlar Onur
e853a32df1 free getline allocated line variable to make valgrind happy
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-28 15:08:17 -05:00
S.Çağlar Onur
527dacf6e5 unnamed semaphores should be destroyed not closed
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-28 15:08:02 -05:00
Dwight Engen
7920b1b435 rpm spec: fix "warning: bogus date in %changelog"
Mar 24 2009 was actually a Tuesday, maybe Daniel was still recovering
from Monday ;) Stranger still that RPM actually checks this!?

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-25 16:18:17 -05:00
S.Çağlar Onur
aae93dd3dd Use actual length of socket's name for abstract sockets (v3)
The addrlen parameter should be the actual length of socket's name for abstract sockets. Otherwise socket gets padded with NULLs.

cat /proc/net/unix | grep lxc
[...]
0000000000000000: 00000003 00000000 00000000 0001 03 226548 @lxc/ad055575fe28ddd5//var/lib/lxc^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
[...]

with this patch;

cat /proc/net/unix | grep lxc
[...]
0000000000000000: 00000002 00000000 00010000 0001 01 109563 @lxc/ad055575fe28ddd5//var/lib/lxc
[...]

Changes since v1:
    * check the length of passed-in string
Changes since v2:
    * remove non-abstract socket code path to simplify functions
    * rename lxc_af_unix_* family to lxc_abstract_unix_*

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-25 16:15:23 -05:00
S.Çağlar Onur
9c88ff1f95 Eliminate duplicate entries from list_active_containers (v2)
list_active_containers parses /proc/net/unix which can contain multiple entries for the same container;

0000000000000000: 00000002 00000000 00010000 0001 01 273672 @/var/lib/lxc/6/command
0000000000000000: 00000002 00000000 00010000 0001 01 274395 @/var/lib/lxc/5/command
0000000000000000: 00000002 00000000 00010000 0001 01 273890 @/var/lib/lxc/4/command
0000000000000000: 00000002 00000000 00010000 0001 01 273141 @/var/lib/lxc/3/command
0000000000000000: 00000002 00000000 00010000 0001 01 273915 @/var/lib/lxc/2/command
0000000000000000: 00000002 00000000 00010000 0001 01 273683 @/var/lib/lxc/1/command
0000000000000000: 00000002 00000000 00010000 0001 01 273074 @/var/lib/lxc/0/command
0000000000000000: 00000002 00000000 00010000 0001 01 273931 @/var/lib/lxc/9/command
0000000000000000: 00000002 00000000 00010000 0001 01 273110 @/var/lib/lxc/8/command
0000000000000000: 00000002 00000000 00010000 0001 01 273390 @/var/lib/lxc/7/command
0000000000000000: 00000003 00000000 00000000 0001 03 275903 @/var/lib/lxc/8/command
0000000000000000: 00000003 00000000 00000000 0001 03 276043 @/var/lib/lxc/1/command
0000000000000000: 00000003 00000000 00000000 0001 03 273301 @/var/lib/lxc/0/command
0000000000000000: 00000003 00000000 00000000 0001 03 275650 @/var/lib/lxc/4/command

On this system list_active_containers returns 14 containers while only 10 containers are running.

Following patch;

	* Introduces array_contains function to do a binary search on given array,
	* Starts to sort arrays inside the add_to_clist and add_to_names functions,
	* Consumes array_contains in list_active_containers to eliminate duplicates,
	* Replaces the linear search code in lxcapi_get_interfaces with the new function.

Changes since v1:
	* Do not load containers if a if a container list is not passed in
	* Fix possible memory leaks in lxcapi_get_ips and lxcapi_get_interfaces if realloc fails

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-25 16:15:21 -05:00
Natanael Copa
44f820e30b lxc-alpine: enable 4 consoles by default
We allow 4 consoles in the LXC config file so we can enable 4 in the
inittab as well.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-25 09:52:25 -05:00
Natanael Copa
2899ab0b1a lxc-alpine: run bootmisc and syslog at boot runlevel
The bootmisc script is needed to clean up various temp dirs like /tmp
and migrate /var/run to /run if needed.

The syslog service is started in 'boot' runlevel when running on real
hardware so we do the same for containers.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-25 09:52:23 -05:00
Serge Hallyn
1ea59ad28a cgroup: set memory.use_hierarchy
But don't fail the container start if that fails.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-10-25 09:31:22 -05:00
Stéphane Graber
1563f8eff3 lxc-ls: Rewrite nesting code to use the attach API
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-10-24 16:19:56 -04:00
Serge Hallyn
cbef6c52be start: use lxc-user-nic if we are not root
Note this results in nics named things like 'lxcuser-0p'.  We'll
likely want to pass the requested name to lxc-user-nic, but let's
do that in a separate patch.

If we're not root, we can't create new network itnerfaces to pass
into the container.  Instead wait until the container is started,
and call lxc-user-nic to create and assign the nics.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-10-24 12:13:47 -05:00
Serge Hallyn
9e214906db lxc-busybox: if in userns, don't try to mknod
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-10-24 12:13:40 -05:00