diff options
author | Ivana Hutarova Varekova <varekova@redhat.com> | 2009-12-10 13:25:21 +0100 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-12-16 14:03:20 +0530 |
commit | a380f99da2f7e8b818f456584dd8ee6a8a53f166 (patch) | |
tree | e905ae26ac5b790365e2245cd62472251420c07e | |
parent | 5dfd5d40b68febd5376e6823021e4b376de77efc (diff) | |
download | libcg-a380f99da2f7e8b818f456584dd8ee6a8a53f166.tar.gz libcg-a380f99da2f7e8b818f456584dd8ee6a8a53f166.tar.xz libcg-a380f99da2f7e8b818f456584dd8ee6a8a53f166.zip |
lssubsys: new option -a,--all
This patch adds new option to lssubsys command
lssubsys with this option displays moreover controllers which are
not mounted
The patch change the behavior of lssubsys a bit - there is no
error message if controllers are not mounted and lssubsys is called.
Example:
$ ./lssubsys -a
devices
cpuset,cpuacct
ns
cpu
$ ./lssubsys -am
devices /mnt/cgroups/devices
cpuset,cpuacct /mnt/cgroups/cpuset
ns
cpu
$ ./lssubsys
Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
-rw-r--r-- | doc/man/lssubsys.1 | 6 | ||||
-rw-r--r-- | src/tools/lssubsys.c | 53 |
2 files changed, 52 insertions, 7 deletions
diff --git a/doc/man/lssubsys.1 b/doc/man/lssubsys.1 index 9ea97d6..2b62f1d 100644 --- a/doc/man/lssubsys.1 +++ b/doc/man/lssubsys.1 @@ -7,7 +7,7 @@ lssubsys \- list hierarchies containing given subsystem .SH SYNOPSIS -\fBlssubsys\fR [\fB-m|--mount-points\fR] [\fIcontroller\fR] [...] +\fBlssubsys\fR [\fB-m|--mount-points\fR] [\fB-a|--all\fR] [\fIcontroller\fR] [...] .br \fBlssubsys\fR [\fB-h|--help\fR] @@ -27,6 +27,10 @@ list all subsystems which are present. Display mount points. .TP +.B -a, --all +Display not mounted subsystems. + +.TP .B -h, --help Display help and exit. diff --git a/src/tools/lssubsys.c b/src/tools/lssubsys.c index 959b9bf..2299922 100644 --- a/src/tools/lssubsys.c +++ b/src/tools/lssubsys.c @@ -19,8 +19,9 @@ #include <libcgroup.h> enum flag{ - FL_MOUNT = 1, - FL_LIST = 2 + FL_MOUNT = 1, /* show the mount points */ + FL_LIST = 2, + FL_ALL = 4 /* show all subsystems - not mounted too */ }; typedef char cont_name_t[FILENAME_MAX]; @@ -37,6 +38,8 @@ void usage(int status, char *program_name) fprintf(stdout, "list all sybsystems of given controller\n"); fprintf(stdout, " -h, --help Display this help\n"); fprintf(stdout, " -m, --mount-points Display mount points\n"); + fprintf(stdout, " -a, --all "); + fprintf(stdout, "Display all not mounted subsystems\n"); } } @@ -119,10 +122,13 @@ int cgroup_list_controllers(char *tname, /* initialize libcgroup */ ret = cgroup_init(); + if (ret) { - fprintf(stderr, "controllers can't be listed: %s\n", - cgroup_strerror(ret)); - return ret; + if (flags & FL_ALL) { + return 0; + } else { + return ret; + } } if ((flags & FL_LIST) == 0) { @@ -156,6 +162,32 @@ int cgroup_list_controllers(char *tname, return final_ret; } +int cgroup_list_all_controllers(char *tname) +{ + int ret = 0; + void *handle; + struct controller_data info; + + ret = cgroup_get_all_controller_begin(&handle, &info); + + while (ret != ECGEOF) { + if (info.hierarchy == 0) + printf("%s\n", info.name); + ret = cgroup_get_all_controller_next(&handle, &info); + if (ret && ret != ECGEOF) { + fprintf(stderr, + "%s: cgroup_get_controller_next failed (%s)\n", + tname, cgroup_strerror(ret)); + return ret; + } + } + + ret = cgroup_get_all_controller_end(&handle); + + return ret; + +} + int main(int argc, char *argv[]) { @@ -171,6 +203,7 @@ int main(int argc, char *argv[]) static struct option options[] = { {"help", 0, 0, 'h'}, {"mount-points", 0, 0, 'm'}, + {"all", 0, 0, 'a'}, {0, 0, 0, 0} }; @@ -178,7 +211,7 @@ int main(int argc, char *argv[]) cont_name[i][0] = '\0'; /* parse arguments */ - while ((c = getopt_long(argc, argv, "mh", options, NULL)) > 0) { + while ((c = getopt_long(argc, argv, "mha", options, NULL)) > 0) { switch (c) { case 'h': usage(0, argv[0]); @@ -186,6 +219,9 @@ int main(int argc, char *argv[]) case 'm': flags |= FL_MOUNT; break; + case 'a': + flags |= FL_ALL; + break; default: usage(1, argv[0]); return -1; @@ -211,6 +247,11 @@ int main(int argc, char *argv[]) * based on list of input controllers and flags */ ret = cgroup_list_controllers(argv[0], cont_name, flags); + if (ret) + return ret; + + if (flags & FL_ALL) + ret = cgroup_list_all_controllers(argv[0]); return ret; } |