This is a reimplementation of lxc-ls in C. It supports all features previously
supported by lxc-ls.
- All flags and parameters have the same name as before except when the user
specifies a regex to filter container names by. In the previous Python
implementation the regex was passed without paramter flag. The new
C-implementation has the parameter flag -r/--regex for this.
- Since we fork in lxc_attach() we need some form of IPC. Opening shared memory
in the parent (mmap()) seems to be impractical since we don't know the size
of the mapping beforehand. The other option is to open shared memory in the
child and then to attach the parent to it but then we would need to resort to
shm_open() or shmget(). Instead we go for a socketpair() here and wait for
the child.
- Note that we call lxc_attach() and pass ls_get() as exec function to it (To
be even more specific: We do not pass ls_get() directly but rather a wrapper
function for ls_get() which receives a few arguments to enable the
communication between child and parent.). This implementation has the
advantage that we do not depend on any lxc executables being present in the
container. The gist in code:
ls_get()
{
/* Gather all relevant information */
/* get nested containers */
if (args->ls_nested && running) {
/* set up some more stuff */
/*
* execute ls_get() in namespace of the container to
* get nested containers
*/
c->attach(c, ls_get_wrapper, &wrapargs, &aopt, &out)
/* do some cleaning up */
}
}
- When the user requests listing of nested containers without fancy-format
enabled we want him to easily recognize which container is nested in which.
So in this case we do not simply record the name but rather the name
prepended with all the parents of the container:
grand-grand-parent/grand-parent/parent/child
- Pretty-printing nested containers: Any call to list_*_containers() will
return a sorted array of container names. Furthermore, the recursive
implementation of lxc_ls() will automatically put the containers in the
correct order regarding their nesting. That is if we have the following
nesting:
A
A --> S
A --> T --> O
A --> T --> O --> L
A --> T --> O --> M
A --> U
A --> U --> P
A --> U --> Q
B
The array ls_get() will set up looks like this:
A S T O L M U P Q B
Hence, we only need to keep an additional variable nestlvl to indicate the
nesting level a container is at and use that to compute (a) the maximum field
width we need to print out the container names and (b) to correctly indent
each container according to its nesting level when printing it.
- add comments to make the ls_get() function more accessible
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
becomes static. It is called from nowhere else so far and never appeared in any
header.
Minor changes
- Avoid comparisons between int and size_t types. Use size_t where
possible else cast to size_t when it makes sense.
- insert missing spaces between operators
- put declarations for all static functions at the top
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
move from bdev.c to lxclvm.{c,h}. All functions previously declared as static
become public.
Adapt Makefile.am to include lxclvm.{c,h}.
The function:
- mount_unknown_fs();
becomes public.
Rationale: It is already called from different places and will be called by lvm,
and rdb. Also, it is defined twice exactly the same way. Once in conf.c
and once in bdev.c. Let's avoid that.
Defining the same function twice in different places just asks for
trouble.
become public as they will be called for loop, lvm, and or rdb.
Move the definition of:
- DEFAULT_FS_SIZE
- DEFAULT_FSTYPE
from bdev.c to bdev.h to grant other modules access to it.
Remove:
- find_fstype_cb();
from conf.c. It is defined static in bdev.c
Put:
- #define __STDC_FORMAT_MACROS
and include:
- #include <inttypes.h>
in lxclvm.c so that the format specifier PRIu64 is available.
The structs:
- struct bdev; /* defined in bdev.h */
- struct bdev_specs; /* defined in lxccontainer.h */
- struct lxc_conf; /* defined conf.h */
are forward declared/put as incomplete types into lxclvm.h as the functions
associated with lvm need access to it.
Take the chance to restructure bdev.c:
- put bdev structs which have already been split out into separate
modules at the top
- put declarations of all static functions at the top (This includes
all functions associated with modules that have not yet already been
put into a separate module.)
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
Serge Hallyn [Tue, 12 Jan 2016 02:25:19 +0000 (18:25 -0800)]
Set the right variable to NULL when unsetting ipv6_gateway
We were freeing one and setting a different one to NULL, eventually
leading to a crash when closing the netdev (at container shutdown)
and freeing already-freed memory.
Peter Simons [Sat, 2 Jan 2016 16:53:07 +0000 (17:53 +0100)]
bash completion: the 'have' command was deprecated in favor of '_have'
`bash-completion` version 2.1 and later no longer include the `have` command,
and consequently the `lxc` competion file fails on such systems. The command is
now called `_have`.
Wim Coekaerts [Tue, 22 Dec 2015 22:25:00 +0000 (14:25 -0800)]
Add support for Linux for SPARC distribution host and template
Linux for SPARC is a free community Linux distribution for SPARC hosted by Oracle. See : https://oss.oracle.com/projects/linux-sparc
While the distribution is based on Oracle Linux it does have some differences and since it's not actually Oracle Linux I decided to add a separate template rather than having the Oracle Linux template also support Linux for SPARC.
This patch adds the lxc-template for Linux for SPARC and it also adds Linux for SPARC in the configure.ac as a distribution target to build.
Tycho Andersen [Fri, 11 Dec 2015 23:21:53 +0000 (16:21 -0700)]
c/r: use --lsm-profile if provided
Since we can rename a container on a migrate, let's tell CRIU to use the
LSM profile name the user has specified. This change is motivated by LXD,
which sets an LSM profile name based on the container name, so if a user
changes the name of a container during migration, the old profile name
(that criu has saved) won't exist on the new host.
move from bdev.{c,h} to overlay.{c,h}. The only thing that remains in bdev.c
is the static definition of
- static const struct bdev_ops overlayfs_ops
- The functions:
- update_ovl_paths()
- overlay_getlower()
move from lxccontainer.c to overlay.{c,h}. update_ovl_paths() is used to
update absolute paths for overlay lxc.mount.entry entries but it seems to fit
more here than into lxccontainer.c.
The Function overlay_getlower() is used to extract the lower directory for
overlay (and aufs) rootfs. It should at some point become a common helper.
- The functions:
- do_rsync()
- dir_new_path()
remain in bdev.c for now but become extern. We declare them extern in
overlay.c to be able to call them. As the comment to them correctly notices,
they should at some point become common helpers and probably move to
utils.{c,h} or some other more appropriate place.
- The structs:
- struct bdev; /* defined in bdev.h */
- struct bdev_specs; /* defined in lxccontainer.h */
- struct lxc_conf; /* defined conf.h */
are forward declared/put as incomplete types in overlay.h so that the
functions have access to it.
- The header overlay.h is *not* included in bdev.h but only in bdev.c so that
when bdev.h is included the public functions in overlay.h cannot be accessed,
i.e. if an implementation wants to call functions from overlay.h they need to
explicitly include it. (As is e.g. done in the case of lxccontainer.c.)
- The header
- lxc-btrfs.h
also moves to the bdev subfolder.
- Adapt Makefile.am to the new bdev layout.
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
Andre McCurdy [Fri, 11 Dec 2015 20:35:55 +0000 (12:35 -0800)]
lxc-checkconfig: remove zgrep dependency
zgrep is a script provided by the 'gzip' package, which may not be
installed on embedded systems etc which use busybox instead of the
standard full-featured utilities.
Signed-off-by: Andre McCurdy <armccurdy@gmail.com>
Laurent Barbe [Fri, 2 Oct 2015 10:45:14 +0000 (12:45 +0200)]
Add Ceph RBD backingstore
With lxc-create, this will create, map and mount a Rados blockdevice.
A valid ceph.conf and ceph.client.admin.keyring is needed in /etc/ceph/
RBD mapping is not manage on reboot.
Tycho Andersen [Mon, 30 Nov 2015 22:14:22 +0000 (15:14 -0700)]
c/r: add a new ->migrate API call
This patch adds a new ->migrate API call with three commands:
MIGRATE_DUMP: this is basically just ->checkpoint()
MIGRATE_RESTORE: this is just ->restore()
MIGRATE_PRE_DUMP: this can be used to invoke criu's pre-dump command on the
container.
A small addition to the (pre-)dump commands is the ability to specify a
previous partial dump directory, so that one can use a pre-dump of a
container.
Finally, this new API call uses a structure to pass options so that it can
be easily extended in the future (e.g. to CRIU's --leave-frozen option in
the future, for potentially smarter failure handling on restore).
v2: remember to flip the return code for legacy ->checkpoint and ->restore
calls
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Tycho Andersen [Wed, 2 Dec 2015 21:30:52 +0000 (14:30 -0700)]
api wrapper: only reset the current config if this call set it
Instead of *always* resetting the current_config to null, we should only
reset it if this API call set it.
This allows nesting of API calls, e.g. c->checkpoint() can pass stuff into
criu.c, which can call c->init_pid() and not lose the ability to log stuff
afterwards.
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>