This patch adds $ndctl list-monitor command, by which users can list all
currently running monitors.
Example: $ndctl list-monitor --all

Signed-off-by: QI Fuli <qi.f...@jp.fujitsu.com>
---
 builtin.h       |  1 +
 ndctl/monitor.c | 32 ++++++++++++++++++++++++++++++++
 ndctl/ndctl.c   |  1 +
 3 files changed, 34 insertions(+)

diff --git a/builtin.h b/builtin.h
index 850f6a8..eda5c7a 100644
--- a/builtin.h
+++ b/builtin.h
@@ -37,6 +37,7 @@ int cmd_init_labels(int argc, const char **argv, void *ctx);
 int cmd_check_labels(int argc, const char **argv, void *ctx);
 int cmd_inject_error(int argc, const char **argv, void *ctx);
 int cmd_create_monitor(int argc, const char **argv, void *ctx);
+int cmd_list_monitor(int argc, const char **argv, void *ctx);
 int cmd_list(int argc, const char **argv, void *ctx);
 #ifdef ENABLE_TEST
 int cmd_test(int argc, const char **argv, void *ctx);
diff --git a/ndctl/monitor.c b/ndctl/monitor.c
index cf1cd6e..53b7c67 100644
--- a/ndctl/monitor.c
+++ b/ndctl/monitor.c
@@ -340,3 +340,35 @@ int cmd_create_monitor(int argc, const char **argv, void 
*ctx)
 out:
        return 1;
 }
+
+int cmd_list_monitor(int argc, const char **argv, void *ctx)
+{
+       const struct option options[] = {
+               OPT_BOOLEAN('a', "all", &param.all, "list all monitors")
+       };
+       const char * const u[] = {
+               "ndctl list-monitor [<options>]",
+               NULL
+       };
+       argc = parse_options(argc, argv, options, u, 0);
+       for (int i = 0; i < argc; i++) {
+               error("unknown parameter \"%s\"\n", argv[i]);
+               goto out;
+       }
+       DIR *dir;
+       struct dirent *ent;
+       dir = opendir("/var/ndctl/monitor/");
+       if (!dir)
+               return -1;
+       while ((ent = readdir(dir)) != NULL)
+       {
+               if (strcmp(ent->d_name, ".") == 0
+                               || strcmp(ent->d_name, "..") == 0)
+                       continue;
+               printf(" %s\n", ent->d_name);
+       }
+       return 0;
+
+out:
+       return 1;
+}
diff --git a/ndctl/ndctl.c b/ndctl/ndctl.c
index 6c63d79..7eae794 100644
--- a/ndctl/ndctl.c
+++ b/ndctl/ndctl.c
@@ -85,6 +85,7 @@ static struct cmd_struct commands[] = {
        { "check-labels", cmd_check_labels },
        { "inject-error", cmd_inject_error },
        { "create-monitor", cmd_create_monitor },
+       { "list-monitor", cmd_list_monitor },
        { "list", cmd_list },
        { "help", cmd_help },
        #ifdef ENABLE_TEST
-- 
2.9.5


_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reply via email to