Commit 8face1de by Serge Hallyn

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: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent fa7fced8
...@@ -122,6 +122,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ...@@ -122,6 +122,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
<varlistentry> <varlistentry>
<term> <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> <option>-W,--nowait </option>
</term> </term>
<listitem> <listitem>
......
...@@ -73,6 +73,9 @@ struct lxc_arguments { ...@@ -73,6 +73,9 @@ struct lxc_arguments {
int hardstop; int hardstop;
int shutdown; int shutdown;
/* for lxc-stop */
int nolock;
/* for lxc-destroy */ /* for lxc-destroy */
int force; int force;
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "commands.h" #include "commands.h"
#include "utils.h" #include "utils.h"
#define OPT_NO_LOCK OPT_USAGE+1
static int my_parser(struct lxc_arguments* args, int c, char* arg) static int my_parser(struct lxc_arguments* args, int c, char* arg)
{ {
switch (c) { switch (c) {
...@@ -41,6 +43,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) ...@@ -41,6 +43,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
case 't': args->timeout = atoi(arg); break; case 't': args->timeout = atoi(arg); break;
case 'k': args->hardstop = 1; break; case 'k': args->hardstop = 1; break;
case 's': args->shutdown = 1; break; case 's': args->shutdown = 1; break;
case OPT_NO_LOCK: args->nolock = 1; break;
} }
return 0; return 0;
} }
...@@ -51,6 +54,7 @@ static const struct option my_longopts[] = { ...@@ -51,6 +54,7 @@ static const struct option my_longopts[] = {
{"timeout", required_argument, 0, 't'}, {"timeout", required_argument, 0, 't'},
{"kill", no_argument, 0, 'k'}, {"kill", no_argument, 0, 'k'},
{"shutdown", no_argument, 0, 's'}, {"shutdown", no_argument, 0, 's'},
{"no-lock", no_argument, 0, OPT_NO_LOCK},
LXC_COMMON_OPTIONS LXC_COMMON_OPTIONS
}; };
...@@ -67,6 +71,7 @@ Options :\n\ ...@@ -67,6 +71,7 @@ Options :\n\
-W, --nowait don't wait for shutdown or reboot to complete\n\ -W, --nowait don't wait for shutdown or reboot to complete\n\
-t, --timeout=T wait T seconds before hard-stopping\n\ -t, --timeout=T wait T seconds before hard-stopping\n\
-k, --kill kill container rather than request clean shutdown\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", -s, --shutdown Only request clean shutdown, don't later force kill\n",
.options = my_longopts, .options = my_longopts,
.parser = my_parser, .parser = my_parser,
...@@ -139,6 +144,11 @@ int main(int argc, char *argv[]) ...@@ -139,6 +144,11 @@ int main(int argc, char *argv[])
my_args.progname, my_args.quiet, my_args.lxcpath[0])) my_args.progname, my_args.quiet, my_args.lxcpath[0]))
return 1; 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]); c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) { if (!c) {
fprintf(stderr, "Error opening container\n"); fprintf(stderr, "Error opening container\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment