This patch is used to add $ndctl destroy-monitor command, by which users
can destroy a monitor. After the monitor is destroyed, the file with
same name under /var/ndctl/monitor will also be deleted.
Example: #ndctl destroy-monitor --monitor m_nmem1
Signed-off-by: QI Fuli <qi.fuli(a)jp.fujitsu.com>
---
builtin.h | 1 +
ndctl/monitor.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
ndctl/ndctl.c | 1 +
3 files changed, 56 insertions(+)
diff --git a/builtin.h b/builtin.h
index b5a006d..2143666 100644
--- a/builtin.h
+++ b/builtin.h
@@ -39,6 +39,7 @@ 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_show_monitor(int argc, const char **argv, void *ctx);
+int cmd_destroy_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 1cff2d8..563a726 100644
--- a/ndctl/monitor.c
+++ b/ndctl/monitor.c
@@ -407,3 +407,57 @@ int cmd_show_monitor(int argc, const char **argv, void *ctx)
out:
return 1;
}
+
+int cmd_destroy_monitor(int argc, const char **argv, void *ctx)
+{
+ const struct option options[] = {
+ OPT_STRING('m', "monitor", ¶m.monitor, "monitor
name",
+ "monitor name")
+ };
+ const char * const u[] = {
+ "ndctl destroy-monitor <monitor>",
+ 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;
+ }
+ if (!param.monitor) {
+ error("monitor name --monitor is required\n");
+ goto out;
+ }
+
+ char *filename;
+ struct json_object *jmonitors, *jpid;
+ int pid;
+ filename = get_full_path_filename(proc_path, param.monitor);
+ jmonitors = json_object_from_file(filename);
+ if (jmonitors == NULL) {
+ error("monitor %s is not exist\n", param.monitor);
+ goto out;
+ }
+
+ if (!json_object_object_get_ex(jmonitors, "pid", &jpid)) {
+ error("cannot find pid in %s\n", filename);
+ goto out;
+ }
+ pid = json_object_get_int(jpid);
+ if (!pid) {
+ error("cannot find pid in %s\n", filename);
+ goto out;
+ }
+ if (kill(pid, SIGUSR1) != 0) {
+ error("failed to kill pid(%d)\n", pid);
+ goto out;
+ }
+ if (destroy_monitor_proc() != 0) {
+ error("failed to delete %s\n", filename);
+ goto out;
+ }
+ printf("destroy monitor %s successed\n", param.monitor);
+
+ return 0;
+out:
+ return 1;
+}
diff --git a/ndctl/ndctl.c b/ndctl/ndctl.c
index 460cf76..ad69222 100644
--- a/ndctl/ndctl.c
+++ b/ndctl/ndctl.c
@@ -87,6 +87,7 @@ static struct cmd_struct commands[] = {
{ "create-monitor", cmd_create_monitor },
{ "list-monitor", cmd_list_monitor },
{ "show-monitor", cmd_show_monitor },
+ { "destroy-monitor", cmd_destroy_monitor },
{ "list", cmd_list },
{ "help", cmd_help },
#ifdef ENABLE_TEST
--
2.9.5