Check if we're really on a btrfs filesystem before we call btrfs_same_fs().
Otherwise we will report misleading errors although everything went fine.
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
As ls_get() is non-tail recursive we face the inherent danger of blowing up the
stack at some level of nesting. To have at least some security we define
MAX_NESTLVL to be 5. That should be sufficient for most users. The argument lvl
to ls_get() can be used to keep track of the level of nesting we are at. If lvl
is greater than the allowed default level return (without error) and unwind the
stack.
--nesting gains an optional numeric argument. This allows the user to specify
the maximum level of nesting she/he wants to see. Fair warning: If your nesting
level is really deep and/or you have a lot of containers your might run into
trouble.
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
No reason for these to be +x, and it looks weird.
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
When running application containers with lxc-execute, /dev is
populated only with device entries. Since /dev is a tmpfs mount in
the container environment, the /dev/shm folder not being present is not
a sufficient reason for the /dev/shm mount to fail.
Create the /dev/shm directory if not present.
Signed-off-by: Bogdan Purcareata <bogdan.purcareata@nxp.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
In the current implementation, the open_without_symlink function
will default to opening the root mount only if the passed rootfs
prefix is null. It doesn't account for the case where this prefix
is passed as an empty string.
Properly handle this second case as well.
Signed-off-by: Bogdan Purcareata <bogdan.purcareata@nxp.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Should be mentioned separately because it will reset a big group of options.
Signed-off-by: Marko Hauptvogel <marko.hauptvogel@googlemail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
The lock path for lxc is not
RUNTIME_PATH/lock/lxc
but rather
RUNTIME_PATH/lxc/lock
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
More general for all list options.
Seems to currently affect:
lxc.network (clear all NICs)
lxc.network.* (clear current NIC)
lxc.cap.drop
lxc.cap.keep
lxc.cgroup
lxc.mount.entry
lxc.mount.auto
lxc.hook
lxc.id_map
lxc.group
lxc.environment
Signed-off-by: Marko Hauptvogel <marko.hauptvogel@googlemail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
Otherwise every lxc-info by a user who doesn't own all his cgroups
will result in a set of error messages which are really innocuous.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
What we want is to make sure we dont' use controller 'all' if cgmanager
doesn't support, if all our cgroups aren't the same, or if we cannot
controll all our cgroups. We were mixing some of these conditions. Use
cgm_all_controllers_same for all. (Might want to rename it, but we want
to stick with just one).
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Bad late-night commit. We were doing a while loop for a reason. Just
initialize i to 0 before the while loop.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
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>
we were initializing i to 0, then doing a while i <, but then a
separate commit (by myself) used i as a generic variable in between
those two.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
The function
- bdev_get();
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>
The functions
- clone_attach_nbd();
- do_attach_nbd();
- nbd_busy();
- nbd_detach();
- nbd_get_partition();
- wait_for_partition();
move from bdev.c to lxcnbd.c. They remain static
The functions
- attach_nbd();
- detach_nbd_idx();
- nbd_clonepaths();
- nbd_create();
- nbd_destroy();
- nbd_detect();
- nbd_mount();
- nbd_umount();
- requires_nbd();
move from bdev.c to lxcnbd.{c,h}. They all become extern.
The struct
- struct nbd_attach_data
moves from bdev.c to lxcnbd.c.
Adapt Makefile.am to include lxcnbd.{c,h}.
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 lxcnbd.h as the functions
associated with nbd need access to it.
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
The functions
- rbd_clonepaths();
- rbd_create();
- rbd_destroy();
- rbd_detect();
- rbd_mount();
- rbd_umount();
move from bdev.c to lxcrbd.{c,h}. All functions previously declared static
become extern.
Adapt Makefile.am to include lxcrbd.{c,h}.
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 lxcrbd.h as the functions
associated with rbd need access to it.
Put:
- #define __STDC_FORMAT_MACROS
and include:
- #include <inttypes.h>
in lxcrbd.c so that the format specifier PRIu64 is available.
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
The functions
- loop_clonepaths();
- loop_create();
- loop_destroy();
- loop_detect();
- loop_mount();
- loop_umount();
move from bdev.c to lxcloop.{c,h}. All functions previously declared static
become extern.
The functions
- do_loop_create();
- find_free_loopdev_no_control();
- find_free_loopdev();
move from bdev.c to lxcloop.c. They remain static.
Adapt Makefile.am to include lxcloop.{c,h}.
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 lxcloop.h as the functions
associated with loop need access to it.
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
The functions
- dir_clonepaths();
- dir_create();
- dir_destroy();
- dir_detect();
- dir_mount();
- dir_umount();
move from bdev.c to lxcdir.{c,h}. All functions which previously were static
become extern.
Adapt Makefile.am to include lxcdir.{c,h}.
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 lxcdir.h as the functions
associated with dir need access to it.
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
The functions
- aufs_clonepaths();
- aufs_create();
- aufs_destroy();
- aufs_detect();
- aufs_mount();
- aufs_umount();
move from bdev.c to lxcaufs.{c,h}. All functions which previously were static
become extern.
Adapt Makefile.am to include lxcaufs.{c,h}.
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 lxcaufs.h as the functions
associated with aufs need access to it.
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
The functions
- lvm_detect();
- lvm_mount();
- lvm_umount();
- lvm_compare_lv_attr();
- lvm_is_thin_volume();
- lvm_is_thin_pool();
- lvm_snapshot();
- lvm_clonepaths();
- lvm_destroy();
- lvm_create();
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.
The functions:
- blk_getsize();
- detect_fs();
- do_mkfs();
- is_blktype();
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>
The functions:
- zfs_clone();
- zfs_clonepaths();
- zfs_create();
- zfs_destroy();
- zfs_detect();
- zfs_list_entry();
- zfs_mount();
- zfs_umount();
move from bdev.c to lxczfs.{c,h}. All functions previously declared as static
become public.
Adapt Makefile.am to include lxczfs.{c,h}.
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 lxczfs.h as the functions
associated with zfs need access to it.
Minor changes:
- Use exit(EXIT_FAILURE) instead of exit(1).
- Use brackets around else {} if the if {} did:
I.e. instead of:
if {
// do one;
// do two;
} else
// do three;
use:
if {
// do one;
// do two;
} else {
// do three;
}
- Instead of declaring char pointers and arrays on the same line, i.e.:
char arr[len], *p;
do:
char arr[len];
char *p;
which makes intentions a lot clearer.
- Since we require c99 anyway, use finer-grained scoping by declaring
variables where they are needed instead of simply at the top.
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
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.
Closes#732
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
`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`.
Signed-off-by: Peter Simons <simons@cryp.to>
Added missing network utilities to base install for Leap. Included
check to do it for Leap 42.1 only.
Signed-off-by: Terzeus S. Dominguez <zeus@dmgznet.com>
We'll probably want to make this configurable with a
lxc.cgroupns = [1|0], but for now just always do it.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
---
Changelog 20160104: only try to unshare if /proc/self/ns/cgroup exists.