Commit Graph

46 Commits

Author SHA1 Message Date
Serge Hallyn
50040b5e46 lxc-create: make 'none' bdev type work again
This should address https://github.com/lxc/lxc/issues/199

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-05-01 13:54:16 -04:00
Stéphane Graber
d3de16bb56 lxc-create: Require --template be passed
It's often been reported that the behavior of lxc-create without -t is a
bit confusing. This change makes lxc-create require the --template
option and introduces a new "none" special value which when set will
fallback to the old template-less behavior.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-07 17:18:51 -05:00
Serge Hallyn
7bb878863c add dir support
It used to be supported with the lxc-create.in script, and
the manpage says it's supported...  So let's just support it.

Now

sudo lxc-create -t download --dir /opt/ab -n ab

works, creating the container rootfs under /opt/ab.  This
generally isn't something I'd recommend, however telling users
to use a different lxc-path isn't as friendly as I'd like,
because each lxcpath requires separate lxc-ls and lxc-autostart
runs.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-02-22 18:33:59 -05:00
Stéphane Graber
6ea518f64a log: Set log_define properly
This sets lxc_log_define to what should be appropriate values for all
existing binaries that call lxc_log_init.

The name is lxc_<bin name>_ui for anything that's user visible and
lxc_<bin name> for anything that's not.

The parent is set to "lxc" for anything using the API and to the
matching C file name for anything that isn't.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-02-05 17:16:34 -06:00
Stéphane Graber
6edbfc8650 logging: Add lxc_log_options_no_override function
In current LXC, loglevel and logfile are write-once functions.
That behaviour was appropriate when those two were first introduced
(pre-API) but with current API, one would expect to be able to
set_config_item those multiple times.

So instead, introduce lxc_log_options_no_override which when called
turns those two config keys read-only and have all existing binaries
which use log_init call that function once they're done setting the
value requested by the user.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-02-04 18:01:59 -05:00
Stéphane Graber
19668d8b07 lxc-create: Don't print the help message twice
The forking logic was wrong, causing both the child and the parent to
call the template with -h.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-01-15 23:31:23 -05:00
Stéphane Graber
040f1c4008 Always try to create lxcpath
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-01-15 10:04:04 -05:00
Stéphane Graber
dad87e3bd1 Drop usage of LXC_DEFAULT_CONFIG in our code
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-01-10 11:16:09 -05:00
Stephen Ayotte
d659597e03 Support large bdevs on 32-bit; MB units by default.
Change all instances of "unsigned long" where referring to a bdev size
to uint64_t; this fixes some overflows on 32-bit machines, where
"unsigned long" is uint32_t. Support all unit-sizes supported by LVM
except 's' and 'e' [bkmgt]. Print a warning and use default bdev-size if
invalid unit-size specified.

Signed-off-by: Stephen Ayotte <stephen.ayotte@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-01-08 12:31:50 -05:00
Andrey Mazo
74a3920a97 Mark functions as static and arguments/arrays as const where possible
Mark most of functions that are used within only one file as static.
After 95ee490bbd it's easy to prove they
are not in public API.
Several arrays and structs are also marked static.
This prevents them from being exported from liblxc.so

List of removed previously exported symbols:
bdevs
btrfs_ops
check_autodev
create_partial
dir_ops
dump_stacktrace
get_mapped_rootid
get_next_index
lock_mutex
loop_ops
lvm_ops
lxc_abort
lxcapi_clone
lxc_attach_drop_privs
lxc_attach_get_init_uidgi
lxc_attach_getpwshell
lxc_attach_remount_sys_pr
lxc_attach_set_environmen
lxc_attach_to_ns
lxc_clear_saved_nics
lxc_config_readline
lxc_devs
lxc_free_idmap
lxc_global_config_value
lxc_poll
lxc_proc_get_context_info
lxc_set_state
lxc_spawn
mk_devtmpfs
mount_check_fs
ongoing_create
overlayfs_destroy
overlayfs_ops
prepend_lxc_header
remove_partial
save_phys_nics
setup_pivot_root
signames
static_mutex
thread_mutex
unlock_mutex
unpriv_assign_nic
zfs_ops

Signed-off-by: Andrey Mazo <mazo@telum.ru>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-01-02 09:54:03 -06:00
S.Çağlar Onur
f2363e38d0 adjust include statements (v2)
Use "#include <somefile.h>" style for external or exported headers only.

changes since v1:
 - adjusted formatting as Stéphane suggested

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-01-01 14:04:51 -06:00
Stéphane Graber
95ee490bbd
Reduce public API (V2)
This removes all but the following headers from our includes:
 - attach_options.h
 - lxccontainer.h
 - version.h

This also removes the duplicate lxc_version function (lxc_get_version
has been preferred for a while).

lxclock.h is now considered private.

As a result quite a lot of files needed addition of extra includes
previously inherited from lxclock.h.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-12-02 18:17:41 -05:00
pc-wurm
41ace3de7a Update lxc_create.c corrected argument usage example for -t
I think '-t timeout' was mistakenly written, so I corrected it to '-t
template', since the -t argument is used for setting templates, not
timeout as far as I know.

Signed-off-by: pc-wurm <yordanov@pc-wurm.de>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-12 16:03:55 -05:00
Sidnei da Silva
72e99249b0 Pass through all options with -Bbest.
Remove the union in bdev_specs and store all options if -Bbest is passed. Fixes issue #31.

Signed-off-by: Sidnei da Silva <sidnei.da.silva@canonical.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-22 17:10:14 -05:00
Sidnei da Silva
34e135b238 Store fssize and fstype in the right struct.
When using the -Bloop option, fstype and fssize arguments were copied
into the lvm struct of bdev specs instead of the loop struct.

Signed-off-by: Sidnei da Silva <sidnei.da.silva@canonical.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-21 16:37:40 -05:00
Sidnei da Silva
055af165ef Assume a default thin pool named 'lxc'.
Will fallback to no thinpool if not present or if thin pool provided on the command line does not exist.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-21 16:12:19 -05:00
Sidnei da Silva
f99c386b60 Add a --thinpool argument to lxc-create, to use thin pool backed lvm when creating the container. When cloning a container backed by a thin pool, the clone will default to the same thin pool. 2013-10-18 14:43:03 -05:00
Stéphane Graber
f5abd74d1a Improve behaviour for unprivileged users
This mostly changes two things:
 - Only log to the container's logfile on start/stop/restart/execute
 - Call may_control() every time we use the API and return
   "Insufficient privileges" on failure.

NOTE: I didn't test every single one of those but I'm fairly confident
      in my copy/paste abilities and I confirmed they all build fine at least.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-03 09:34:55 -05:00
Stéphane Graber
948955a2d6 Consistently use <lxc/lxccontainer.h> for the API
The API header was included in a variety of ways before, standardize
those to "include <lxc/lxccontainer.h>" as this will always work both in
tree and on a system with the headers installed.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-23 15:30:05 -05:00
Serge Hallyn
e3f46bfbcf lxc-create: add -P to --lxcpath option help text
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-18 16:40:04 -05:00
Serge Hallyn
460bcbd85c lxc-create: support unpriv users
Just make sure we are root if we are asked to deal with something other
than a directory, and make sure we have permission to create the
container in the given lxcpath.

The templates will need much more work.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-07-22 12:14:53 -05:00
Serge Hallyn
dc23c1c817 create: add a quiet flag
If set, then fds 0,1,2 will be redirected while the creation
template is executed.

Note, as Dwight has pointed out, if fd 0 is redirected, then if
templates ask for input there will be a problem.  We could simply
not redirect fd 0, or we could require that templates work without
interaction.  I'm assuming here that we want to do the latter, but
I'm open to changing that.

Reported-by: "S.Çağlar Onur" <caglar@10ur.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-07-12 11:19:54 -05:00
Serge Hallyn
eddaaafd1a implement loopback backing store
Create a loopfile backed container by doing:

	lxc-create -B loop -t template -n name

or

	lxc-clone -B loop -o dir1 -n loop1

The rootfs in the configuration file will be

	loop:/var/lib/lxc/loop1/rootdev

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-06-03 16:38:13 -05:00
Serge Hallyn
f002c8a765 lxc_create: support 'lxc-create -t <template> -h'
With the lxc-create script, 'lxc-create -t template -h' used to call
'template -h' to get template-specific help.  The api based lxc-create
did not yet support that.

Add a 'helpfn' method to the lxc_arguments, which is called at the end
of printhelp, and passed the lxc_arguments.  Use that in lxc_create to
reintroduce the desired behavior.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-06-03 11:22:42 -05:00
Qiang Huang
3155e7f954 lxc-create: fix the typo in help info
Fix typo in help info of lxc-create, and get rid of duplicate
comments in bdev.h

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-06-03 10:53:41 -05:00
Serge Hallyn
0a18b5458b Define LXC_DEFAULT_CONFIG
And use it in place of the various ways we were deducing /etc/lxc/default.conf.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-05-31 11:14:33 -05:00
Serge Hallyn
1897e3bcd3 Move container creation fully into the api
1. implement bdev->create:

python and lua: send NULL for bdevtype and bdevspecs.
They'll want to be updated to pass those in in a way that makes
sense, but I can't think about that right now.

2. templates: pass --rootfs

If the container is backed by a device which must be mounted (i.e.
lvm) then pass the actual rootfs mount destination to the
templates.

Note that the lxc.rootfs can be a mounted block device.  The template
should actually be installing the rootfs under the path where the
lxc.rootfs is *mounted*.

Still, some people like to run templates by hand and assume purely
directory backed containers, so continue to support that use case
(i.e. if no --rootfs is listed).

Make sure the templates don't re-write lxc.rootfs if it is
already in the config.  (Most were already checking for that)

3. Replace lxc-create script with lxc_create.c program.

Changelog:
May 24: when creating a container, create $lxcpath/$name/partial,
and flock it.  When done, close that file and unlink it.  In
lxc_container_new() and lxcapi_start(), check for this file.  If
it is locked, create is ongoing.  If it exists but is not locked,
create() was killed - remove the container.

May 24: dont disk-lock during lxcapi_create.  The partial lock
is sufficient.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-05-25 19:27:07 -05:00
Daniel Lezcano
ab2d32f88c Replace create/destroy by a script
The simplification of the container configuration makes
pointless to have so much complexity in the container creation.
Let's remove that and replace by some scripts.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-13 11:48:29 +01:00
Daniel Lezcano
d685aa8049 clean up and factor out some code
Factor out some code and fix a memory corruption when
dupping the arguments.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-10-12 22:02:06 +02:00
Michel Normand
cfd1dc0932 keep rcfile for lxc-execute as already done for lxc-create
The code previously added in lxc-create with
commit d7efa8fcbf
is also required in lxc-execute.
So make this code common for the two callers.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-10-07 10:05:39 +02:00
Daniel Lezcano
d7efa8fcbf copy the configuration file in the conf repo
When creating the container, copy the configuration file to the
configuration tree.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-28 12:10:50 +02:00
Daniel Lezcano
4fcc0112bd create the container with an empty configuration
Fix the code to not fail when the specified configuration file
is empty.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-28 12:10:50 +02:00
Michel Normand
7f8306138a lxc-create to return 255 in case of error
to have same exit code for all lxc commands

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-18 22:27:35 +02:00
Michel Normand
4237c6ca1f add long options step3
add the long options to remaining lxc_*.c  files
that do not impact the struct lxc_arguments

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-18 22:11:46 +02:00
Michel Normand
441e496395 add quiet option
This added quiet option allow to disable
the reporting via stderr of the lxc error messages.

Note that the usage function is still printing in case of error,
but will be removed by later patches

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-18 22:11:45 +02:00
Michel Normand
51cab6315f add support of a lxc log file to cli
this is adding -o and -l options to all cli of lxc

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-14 15:52:03 +02:00
Michel Normand
3ab87b66af remove fprintf to stderr and replace by ERROR call when needed
do it in all cli, except:
* the usage functions that will be removed by another patch
* the lxc_init that need more work
* the lxc_priority that is not used anymore

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-14 15:52:03 +02:00
Daniel Lezcano
089cd8b878 move lxc_conf_init to conf.c
Changed the struct lxc_conf initialization function to the
right place.

Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
2009-03-30 14:02:19 +02:00
Daniel Lezcano
a871ff6bdf cleanup config.h
Rename lxc_config.h to confile.h

Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
2009-03-30 14:02:19 +02:00
dlezcano
1f3da8f86c Handle the lock error and show message to user
From: Daniel Lezcano <dlezcano@fr.ibm.com>

Handle the lock error and show message to user.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2008-11-17 17:55:49 +00:00
dlezcano
5e30dbead0 Fixed typos 2008-09-19 09:27:37 +00:00
dlezcano
b113348ebd Change header inclusion path 2008-09-04 10:09:53 +00:00
dlezcano
e14459fae5 *** empty log message *** 2008-09-03 12:06:19 +00:00
dlezcano
c2cc9f0a9b Added C++ compatibility, change to libtool, improve monitoring 2008-09-02 09:48:12 +00:00
dlezcano
620eff3ca9 *** empty log message *** 2008-08-24 00:19:37 +00:00
dlezcano
5e97c3fcce Initial revision 2008-08-06 14:32:29 +00:00