Commit Graph

498 Commits

Author SHA1 Message Date
Daniel Lezcano
932b94f5de Remove dead code
Remove dead code.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 15:19:19 +01:00
Michael Holtz
bf601689a9 use pivot_root instead of chroot
lxc currently does a chroot into the target rootfs. chroot is insecure and
can easily be broken, as demonstrated here:

| root@synergy:~# touch /this_is_the_realrootfs_ouch
| # touch /container/webhost/this_is_the_container
| # lxc-start -n webhost /bin/sh
| # ls this*
| this_is_the_container
| # ./breakchroot
| # ls this*
| this_is_the_realrootfs_ouch

code to break chroot taken from
http://www.bpfh.net/simes/computing/chroot-break.html

Now this can be fixed. As our container has his own mount namespace, we can
easily pivot_root into the rootfs and then unmount all old mounts. The patch
attached add a new config keyword which contains the path to a temporary
mount for the old rootfs (inside the container). This stops the chroot break
method shown before. 

Example:

| root@synergy:~# grep pivotdir /var/lib/lxc/webhost/config
| lxc.pivotdir = /oldrootfs
| root@synergy:~# ls -lad /container/webhost/oldrootfs
| drwxr-xr-x 2 root root 4096 2010-01-02 03:59 /container/webhost/oldrootfs
| root@synergy:~# lxc-start -n webhost /bin/sh
| # mount -t proc proc /proc
| # cat /proc/mounts
| rootfs / rootfs rw 0 0
| /dev/root / ext3 rw,relatime,errors=remount-ro,data=writeback 0 0
| devpts /dev/console devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
| proc /proc proc rw,relatime 0 0
| # ls this*   
| this_is_the_container
| # ./breakchroot
| # ls this*
| this_is_the_container

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: Michael Holtz <lxc@my.fqdn.org>
2010-01-08 14:34:13 +01:00
Michel Normand
7b379ab3a5 lxc: avoid memory corruption on ppc and s390 V4
conf object is on stack and is used in forked process.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 14:34:13 +01:00
Michel Normand
4eec6850fc lxc_cgroup_set not reporting error
this is a side effect of previous patch I made
on this same function in commit
a6ddef6149

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 14:34:13 +01:00
Michel Normand
0bb4f8cf3b lxc: update man and help of lxc-create
few added lines to document the new lxc-create -t option

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 14:34:13 +01:00
Paul Fee
23a92fad75 fix manpage typo
Fix and clarify some parts of the lxc.conf man page.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-05 13:11:27 +01:00
Daniel Lezcano
e892973e39 add macvlan vepa and bridge mode
The future kernel 2.6.33 will incorporate the macvlan bridge
mode where all the macvlan will be able to communicate if they are
using the same physical interface. This is an interesting feature
to have containers to communicate together. If we are outside of the
container, we have to setup a macvlan on the same physical interface than
the containers and use it to communicate with them.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-28 22:10:11 +01:00
Daniel Lezcano
eb960fea58 busybox template
This script builds a busybox rootfs and provides the associated
configuration to run the busybox.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-27 22:36:09 +01:00
Daniel Lezcano
418c73ad12 adapt lxc-sshd to be a template
Cleanup the script, simplify it and pass the arguments to this
script to be callable by lxc-create template logic.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-27 22:36:09 +01:00
Daniel Lezcano
1b6d8e7197 add template option for lxc-create
The lxc-create command is now able to call a sub script to install
a mini template.
Right now, debian is supported.

The rootfs is stored automatically in <lxcpath>/<name>/rootfs
So the rootfs is a subdirectory of the container configuration directory.

When lxc-destroy is called, the rootfs is deleted with the container
configuration.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-27 22:36:09 +01:00
Daniel Lezcano
fb7460fe60 cleanup lxc-debian script
The lxc-debian is epurated and consolidated with a better
error handling.

This script is no longer interactive but it installs in a specified
place the debian rootfs.

This script is not supposed to be called directly so it will fall in
libexec path very soon. This script is called by lxc-create
as a template with the right option and the right place.

The debian network configuration is by dhcp.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-27 22:36:09 +01:00
Daniel Lezcano
1d6b1976a0 fix mount entry typo
Added missing carriage-return when adding a new entry.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-18 14:19:59 +01:00
Jamal Hadi Salim
f6cc1de1a9 Introduce per netdev priv structure
Some devices like veth or vlans have a bit of extra details that
are specific to them. Example veth.pair and vlan.vlanid.
Separate them from the common so we can update cleanly in the future.
    
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-15 10:14:27 +01:00
Jamal Hadi Salim
26c390288b Add VLAN support in config
This adds ability to migrate vlan interfaces into namespaces
by specifying them in a config
    
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-15 10:14:27 +01:00
Jamal Hadi Salim
9ddaf3bf1c Add utility u16 get/put
Add utility functions to parse a u16 and put a u16 on a
netlink message
    
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-15 10:14:26 +01:00
Daniel Lezcano
108ed092c3 fix a compilation warning
lxc_get_cgroup_path is used in the file but the header
defining the function is missing.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:25 +01:00
Andrian Nord
f2ae79a045 "Default" configuration may destroy host system
If you're running (by mistake or typo) (via lxc-start) container that does not
exists it will run with lxc.rootfs=/, meaning that /sbin/init will
restart initialization procedure, efficiently messing host's system,
that may lead to unpredictable results or even destroy (make inaccessible) host
system (by reseting network configuration or something like that).

(Actually, it _did_ destroy system of everyone who tested this).

Actually, I finally lost any meaning of having such a feature for
full-system containers. You may not use hosts's FS - it's described at
above. You may not use some temporary directory - that's nonsense.

This patch forbinds starting container via lxc-start without rcfile and
custom start program, but probably it fixes only small part of problem.
I really don't see much sense in such a feature without ability of
overriding 'default' setting with command line switches. Anyway, default
behaviour should be as save as possible.

Signed-off-by: Andrian Nord <NightNord@gmail.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:25 +01:00
Daniel Lezcano
fae349da89 pass lxc_conf to the lxc_start function instead of the rcfile
The rcfile is parsed in the lxc_start function. This is not the place
to do that. Let's the caller to do that.

In the meantime, we have the lxc_conf structure filled right before
calling the lxc_start function so we can do some sanity check on the
configuration to not break the system when we launch the container.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:24 +01:00
Jamal Hadi Salim
aedd9d3fb3 Remove unnecessary reset of msg.msg_controlle
Remove unnecessary reset of msg.msg_controllen
    
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:24 +01:00
Sven Wegener
e4e7d59db8 use correct number of ttys during setup
commit 985d15b106 "fix fdleak and errors
in lxc_create_tty()" created a zero-sized malloc(), causing memory
corruption. use config->tty like all the other code does.

Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:23 +01:00
Michael Tokarev
6ab9ab6d08 minor cleanups for instanciate_veth()
the same cleanup as in instanciate_macvlan(). Just makes code
shorter and less "jumpy" (as with goto back)

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:23 +01:00
Michael Tokarev
8634bc197f allow lxc.network.pair to specify host-side name for veth interface
Currently we allocate veth device with random name on host side,
so that things like firewall rules or accounting does not work
at all.  Fix this by recognizing yet anothe keyword to specify
the host-side device name: lxc.network.pair, and use it instead
of random name if specified.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:23 +01:00
Michel Normand
f63147349b lxc-ps to limit its search to containers
The purpose of this patch is to limit the search
of pids to those in containers by looking at first
in the /cgroup/<name>/tasks  when --lxc or --names options
are specified by user.
The idea is to speedup the output when only few
container names are specified while the machine
is running with many processes.

Signed-off-by: Michel Normand <michel.mno@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:22 +01:00
Michel Normand
65cb447f9b lxc-ls to report also active containers
With previous changes that allow to start a container
without the need to create it; the lxc-ls was only reporting
the created containers.
With this patch, the lxc-ls is now reporting created and active
containers.

Signed-off-by: Michel Normand <michel.mno@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:22 +01:00
Michel Normand
83c2e17524 lxc-ps typo in man lxc
Fix bad name parameter in the lxc-ps man page.

Signed-off-by: Michel Normand <michel.mno@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-24 09:47:27 +01:00
Michel Normand
fa08222794 lxc-info to report the FROZEN state
this state is reported when the lxc-freeze command
was issued on the container.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-24 09:47:27 +01:00
Michael Tokarev
985d15b106 fix fdleak and errors in lxc_create_tty()
if, for some reason, openpty() fails, lxc_create_tty() will
leak all previous ptys and leave the config structure in a
inconsistent state (wrt the number of ptys actually opened)
Fix that by explicitly closing all previously opened ptys
in case of failure and by setting number of actually opened
ttys after actual open

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-24 09:47:27 +01:00
Daniel Lezcano
8f0a524dcc version 0.6.4
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-20 15:01:32 +01:00
Daniel Lezcano
3e4bb51f6f fix rpm generation regarding latest modifications
The configuration examples have been moved to doc/lxc/examples.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-20 15:01:31 +01:00
Michael Tokarev
d957ae2d51 check if lxc.netdev.link is set for macvlan
Ensure that lxc.netdev.link is specified for macvlan interfaces,
since it's required.

While at it, simplify logic in instanciate_macvlan():
remove unnecessary-complicating goto statements (we only
need to perform a cleanup in one place)

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-20 15:01:31 +01:00
Michael Tokarev
734915aca1 allow link-less veth devices
Before, a veth device pair required a link which was treated as
a bridge device.  Code crashed if there was no lxc.network.link
specified.  Fix that by allowing lxc.network.link to be unset

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-20 15:01:31 +01:00
Daniel Lezcano
7418c9ced1 rollback configuration is a file
The container will be a directory where the user can store everything,
so we create one directory and store a configuration file inside.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-20 15:01:30 +01:00
Daniel Lezcano
158f998257 Do not chdir when daemonize
With the previous modifications, a temporary directory is created
to mount the rootfs in order to have the system container to remount
itself the '/' directory.

But in case of daemonize, we change the directory, so when the rootfs
is specified with a relative path, we can not access it.

Don't chdir, as that will be done automatically later in the chroot
setup.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-20 15:01:30 +01:00
Daniel Lezcano
6a22713f64 update the man pages
Update the man pages regarding the different modifications.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-20 15:01:30 +01:00
Michel Normand
ad3ac5e0ad change C/R api
Change Checkpoint / Restart API

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-19 15:06:02 +01:00
Michel Normand
55237dfa66 remove unused cr_plugin_columbia.c
Remove checkpoint / restart dead code.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-19 15:06:02 +01:00
Michel Normand
8ac1b0bf82 lxc_init better error reporting
Display the 'rcfile' value on error

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-19 15:06:02 +01:00
Daniel Lezcano
16950ecb45 change network_netdev function parameter
A mindless change to encapsulate a little more the function.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-19 15:06:02 +01:00
Michael Tokarev
33c945e023 factor out common config evaluating code
in confile.c we currently have a ton of functions each doing
the same thing.  Clean them up by providing common routines
to do the main work.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-19 15:06:02 +01:00
Michael Tokarev
9d0834025e rename struct lxc_netdev fields to match reality
struct lxc_netdev is used to hold information from cnfig file
about a network device/configuration.  Make the fields of this
structure to be named similarily with the config file keywords,
namely:
 s/ifname/link/ - host-side link for the device (bridge or eth0)
 s/newname/name/ - container-side ifname
It is insane to have completely different names in config file
and in structure/variable names :)

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-19 15:06:02 +01:00
Daniel Lezcano
0f71d073ee update the man pages
Update the man pages regarding the modifications around the 
configuration option, volatile containers and new configuration
file format.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-19 15:06:02 +01:00
Michel Normand
25c2aca55a export set_state function
This function will be needed for the restart function.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 22:57:46 +01:00
Michel Normand
bcc23654af add capabilities for lxc-checkpoint
add capabilities for lxc-checkpoint

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 22:57:46 +01:00
Michel Normand
6e4bb2e01f lxc: move setup_fs to utils.c
This is not required immidiately but may be used by other init.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 22:57:46 +01:00
Daniel Lezcano
96c210bbbe fix container find the previously created configuration
The command specifies a configuration file => use it
The command does not specify a configuration but the container
was created before, use the configuration.
The command does not specify a configuration and the container
was not created before, use default.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 22:57:46 +01:00
Andrian Nord
a7856c5545 lxc-netstat should use @LXCPATH@ for lxcpath=
Typo ;)

Signed-off-by: Andrian Nord <NightNord@gmail.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 10:56:24 +01:00
Michael Tokarev
92db2bb00c batched reads for lxc_console
Instead of doing I/O one-byte-at-a-time in lxc_console,
which is slow, let's do it in batches.  Only for output
(from container to the host system), since input is most
likely one-byte-at-a-time anyway (from a keyboard).

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 10:56:24 +01:00
Michael Tokarev
994f905eed host consoles/ttys in containers
I noticed that container's consoles aren't quite useable
(be it lxc-console or lxc-start with getty bound to /dev/console).
The main problem is a complete lack of window resizing support:
when I resize an xterm window with lxc-start or lxc-console, the
"guest" does not know about that and continues to think that the
terminal is 80x25 still.

Is it just a lack of functionality (missing implementation) or
something problematic?
 
Ok, the attached patch fixes this.
 
It moves the 'master' variable out of main function so it's
accessible from the signal handler, sets up SIGWINCH handler
to call a (newly created) winsz() function that gets the
current tty size using TIOCGWINSZ ioctl and if that works,
sets up the pty size using TIOCSWINSZ.  That same function
is called at the start as well, when setting up the signal
handler.

Signed-off-By: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-By: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 10:56:24 +01:00
Andrian Nord
aef4ebcf22 Choose configuration directory
Maybe it will be more logical to keep configs into /etc/lxc/?

Or, maybe, just use --with-config-path=/some/path switch into configure,
which could be overridden as user wants to? Something like this one (in
assumption, that this is up to user to create corresponding directory):

Signed-off-by: Andrian Nord <NightNord@gmail.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 10:56:23 +01:00
Cedric Le Goater
00b3c2e284 cleanup <lxc/lxc.h>
<lxc/lxc.h>  should only include what is needed. This patch removes
all useless headers from lxc.h and fixed other .c files.

Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 10:56:23 +01:00