]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
stop: add nolock option
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 16 Dec 2013 13:50:58 +0000 (07:50 -0600)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 16 Dec 2013 16:49:05 +0000 (10:49 -0600)
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>
doc/lxc-stop.sgml.in
src/lxc/arguments.h
src/lxc/lxc_stop.c

index d5f851036c04c5c51b1e385e7a2ec9c26259ef12..d4ec36a177719133bcb34b798b02e41535d9da97 100644 (file)
@@ -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>
index 021f552e21667add03258383cd0abce189317b54..f574fc484a5416d5948abfdbb4bd57069ef7d24d 100644 (file)
@@ -73,6 +73,9 @@ struct lxc_arguments {
        int hardstop;
        int shutdown;
 
+       /* for lxc-stop */
+       int nolock;
+
        /* for lxc-destroy */
        int force;
 
index 7203d75085553d0c0f243de771b7c3f05c42ac2d..a4ead815b9dd78fa39a82f02d10ad1f859158751 100644 (file)
@@ -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");