[lxc-devel] [lxc/master] lxc-ls: return all containers by default, new filter - list only defi…

grzgrzgrz3 on Github lxc-bot at linuxcontainers.org
Sat May 27 17:49:14 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 514 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170527/ee842350/attachment.bin>
-------------- next part --------------
From c2e1b07ab72f4fc9b759b86634f12fa2f91bd4d1 Mon Sep 17 00:00:00 2001
From: Grzegorz Grzywacz <grzegorz.grzywacz at nazwa.pl>
Date: Thu, 15 Dec 2016 10:24:31 +0100
Subject: [PATCH] lxc-ls: return all containers by default, new filter - list
 only defined containers.

1.x.x lxc-ls list all containers, new lxc-ls (2.x.x) implementation is
ignoring not defined containers.

related with issue: #984

Signed-off-by: Grzegorz Grzywacz <grzgrzgrz3 at gmail.com>
---
 doc/lxc-ls.sgml.in     | 12 ++++++++++++
 src/lxc/arguments.h    |  1 +
 src/lxc/tools/lxc_ls.c |  9 ++++++++-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/doc/lxc-ls.sgml.in b/doc/lxc-ls.sgml.in
index 2b2823779..7f55f4f9e 100644
--- a/doc/lxc-ls.sgml.in
+++ b/doc/lxc-ls.sgml.in
@@ -55,6 +55,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
       <arg choice="opt">--frozen</arg>
       <arg choice="opt">--running</arg>
       <arg choice="opt">--stopped</arg>
+      <arg choice="opt">--defined</arg>
       <arg choice="opt">-f</arg>
       <arg choice="opt">-F <replaceable>format</replaceable></arg>
       <arg choice="opt">-g <replaceable>groups</replaceable></arg>
@@ -131,6 +132,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
       <varlistentry>
         <term>
+          <option>--defined</option>
+        </term>
+        <listitem>
+          <para>
+            List only defined containers.
+          </para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>
           <option>-f,--fancy</option>
         </term>
         <listitem>
diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h
index 8ace559fb..d51db4559 100644
--- a/src/lxc/arguments.h
+++ b/src/lxc/arguments.h
@@ -130,6 +130,7 @@ struct lxc_arguments {
 	bool ls_line;
 	bool ls_running;
 	bool ls_stopped;
+	bool ls_defined;
 
 	/* lxc-copy */
 	bool tmpfs;
diff --git a/src/lxc/tools/lxc_ls.c b/src/lxc/tools/lxc_ls.c
index 63053b110..33ba470ad 100644
--- a/src/lxc/tools/lxc_ls.c
+++ b/src/lxc/tools/lxc_ls.c
@@ -53,6 +53,7 @@ lxc_log_define(lxc_ls, lxc);
 #define LS_RUNNING 4
 #define LS_NESTING 5
 #define LS_FILTER 6
+#define LS_DEFINED 7
 
 #ifndef SOCK_CLOEXEC
 #  define SOCK_CLOEXEC                02000000
@@ -167,6 +168,7 @@ static const struct option my_longopts[] = {
 	{"running", no_argument, 0, LS_RUNNING},
 	{"frozen", no_argument, 0, LS_FROZEN},
 	{"stopped", no_argument, 0, LS_STOPPED},
+	{"defined", no_argument, 0, LS_DEFINED},
 	{"nesting", optional_argument, 0, LS_NESTING},
 	{"groups", required_argument, 0, 'g'},
 	{"filter", required_argument, 0, LS_FILTER},
@@ -192,6 +194,7 @@ Options :\n\
   --running          list only running containers\n\
   --frozen           list only frozen containers\n\
   --stopped          list only stopped containers\n\
+  --defined          list only defined containers\n\
   --nesting=NUM      list nested containers up to NUM (default is 5) levels of nesting\n\
   --filter=REGEX     filter container names by regular expression\n\
   -g --groups        comma separated list of groups a container must have to be displayed\n",
@@ -395,8 +398,9 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
  		else if (!c)
  			continue;
 
-		if (!c->is_defined(c))
+		if (args->ls_defined && !c->is_defined(c)){
 			goto put_and_next;
+		}
 
 		/* This does not allocate memory so no worries about freeing it
 		 * when we goto next or out. */
@@ -928,6 +932,9 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
 	case LS_STOPPED:
 		args->ls_stopped = true;
 		break;
+	case LS_DEFINED:
+		args->ls_defined = true;
+		break;
 	case LS_NESTING:
 		/* In case strtoul() receives a string that represents a
 		 * negative number it will return ULONG_MAX - the number that


More information about the lxc-devel mailing list