Skip to content

Commit

Permalink
stop: add nolock option
Browse files Browse the repository at this point in the history
If the system gets into a bad state, it may become impossible to get
the lxc container locks.  We should still be able to stop containers
in that case.  Add a -L/--nolock option to specify this behavior.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
  • Loading branch information
hallyn committed Dec 16, 2013
1 parent fa7fced commit 8face1d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions doc/lxc-stop.sgml.in
Expand Up @@ -120,6 +120,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</listitem>
</varlistentry>

<varlistentry>
<term>
<option>--nolock </option>
</term>
<listitem>
<para>
This option avoids the use of any of the API lxc locking, and should
only be used if <command>lxc-stop</command> is hanging due to a bad
system state.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>
<option>-W,--nowait </option>
Expand Down
3 changes: 3 additions & 0 deletions src/lxc/arguments.h
Expand Up @@ -73,6 +73,9 @@ struct lxc_arguments {
int hardstop;
int shutdown;

/* for lxc-stop */
int nolock;

/* for lxc-destroy */
int force;

Expand Down
10 changes: 10 additions & 0 deletions src/lxc/lxc_stop.c
Expand Up @@ -33,6 +33,8 @@
#include "commands.h"
#include "utils.h"

#define OPT_NO_LOCK OPT_USAGE+1

static int my_parser(struct lxc_arguments* args, int c, char* arg)
{
switch (c) {
Expand All @@ -41,6 +43,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
case 't': args->timeout = atoi(arg); break;
case 'k': args->hardstop = 1; break;
case 's': args->shutdown = 1; break;
case OPT_NO_LOCK: args->nolock = 1; break;
}
return 0;
}
Expand All @@ -51,6 +54,7 @@ static const struct option my_longopts[] = {
{"timeout", required_argument, 0, 't'},
{"kill", no_argument, 0, 'k'},
{"shutdown", no_argument, 0, 's'},
{"no-lock", no_argument, 0, OPT_NO_LOCK},
LXC_COMMON_OPTIONS
};

Expand All @@ -67,6 +71,7 @@ Options :\n\
-W, --nowait don't wait for shutdown or reboot to complete\n\
-t, --timeout=T wait T seconds before hard-stopping\n\
-k, --kill kill container rather than request clean shutdown\n\
--nolock Avoid using API locks\n\
-s, --shutdown Only request clean shutdown, don't later force kill\n",
.options = my_longopts,
.parser = my_parser,
Expand Down Expand Up @@ -139,6 +144,11 @@ int main(int argc, char *argv[])
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
return 1;

/* shortcut - if locking is bogus, we should be able to kill
* containers at least */
if (my_args.nolock)
return lxc_cmd_stop(my_args.name, my_args.lxcpath[0]);

c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {
fprintf(stderr, "Error opening container\n");
Expand Down

0 comments on commit 8face1d

Please sign in to comment.