From: Serge Hallyn Date: Mon, 16 Dec 2013 13:50:58 +0000 (-0600) Subject: stop: add nolock option X-Git-Tag: lxc-1.0.0.beta1~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8face1de22e8cf3bab2d6cdf33cdcc7476f9217b;p=thirdparty%2Flxc.git stop: add nolock option 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 Acked-by: Stéphane Graber --- diff --git a/doc/lxc-stop.sgml.in b/doc/lxc-stop.sgml.in index d5f851036..d4ec36a17 100644 --- a/doc/lxc-stop.sgml.in +++ b/doc/lxc-stop.sgml.in @@ -120,6 +120,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + + + + + + This option avoids the use of any of the API lxc locking, and should + only be used if lxc-stop is hanging due to a bad + system state. + + + + diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h index 021f552e2..f574fc484 100644 --- a/src/lxc/arguments.h +++ b/src/lxc/arguments.h @@ -73,6 +73,9 @@ struct lxc_arguments { int hardstop; int shutdown; + /* for lxc-stop */ + int nolock; + /* for lxc-destroy */ int force; diff --git a/src/lxc/lxc_stop.c b/src/lxc/lxc_stop.c index 7203d7508..a4ead815b 100644 --- a/src/lxc/lxc_stop.c +++ b/src/lxc/lxc_stop.c @@ -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) { @@ -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; } @@ -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 }; @@ -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, @@ -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");