From ed0599391ab4066ec8cfa907efc58a9ce237cef2 Mon Sep 17 00:00:00 2001
From: Marek 'marx' Grac <mgrac@redhat.com>
Date: Wed, 17 Jun 2015 19:48:21 +0200
Subject: [PATCH 06/10] fence_kdump: Add 'monitor' action which tests
possibility of doing kdump on local node
In case of fence_kdump we can not test if remote 'fencing device' is working because
fence_kdump_send is started only after kernel crash. So, monitor action checks if LOCAL
node can enter kdump. The test looks if crashkernel=.. occurs between boot arguments.
Resolves: rhbz#1196068
---
fence/agents/kdump/fence_kdump.c | 35 ++++++++++++++++++++++++++++++++++-
fence/agents/kdump/options.h | 2 ++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/fence/agents/kdump/fence_kdump.c b/fence/agents/kdump/fence_kdump.c
index cae9842..5cea11d 100644
--- a/fence/agents/kdump/fence_kdump.c
+++ b/fence/agents/kdump/fence_kdump.c
@@ -114,6 +114,34 @@ out:
}
static int
+do_action_monitor (void)
+{
+ const char cmdline_path[] = "/proc/cmdline";
+ FILE *procFile;
+ size_t sz;
+ char *lines;
+ int result;
+
+ procFile = fopen(cmdline_path, "r");
+ sz = 0;
+
+ while (!feof (procFile)) {
+ getline (&lines, &sz, procFile);
+ }
+
+ if (strstr(lines, "crashkernel=") == NULL) {
+ result = 1;
+ } else {
+ result = 0;
+ }
+
+ free (lines);
+ fclose (procFile);
+
+ return result;
+}
+
+static int
do_action_off (const fence_kdump_opts_t *opts)
{
int error;
@@ -205,6 +233,7 @@ do_action_metadata (const char *self)
fprintf (stdout, "\t<parameter name=\"action\" unique=\"0\" required=\"0\">\n");
fprintf (stdout, "\t\t<getopt mixed=\"-o, --action\" />\n");
+ fprintf (stdout, "\t\t<content type=\"string\" default=\"monitor\" />\n");
fprintf (stdout, "\t\t<content type=\"string\" default=\"off\" />\n");
fprintf (stdout, "\t\t<shortdesc lang=\"en\">%s</shortdesc>\n",
"Fencing action");
@@ -242,6 +271,7 @@ do_action_metadata (const char *self)
fprintf (stdout, "<actions>\n");
fprintf (stdout, "\t<action name=\"off\" />\n");
+ fprintf (stdout, "\t<action name=\"monitor\" />\n");
fprintf (stdout, "\t<action name=\"metadata\" />\n");
fprintf (stdout, "</actions>\n");
@@ -264,7 +294,7 @@ print_usage (const char *self)
fprintf (stdout, "%s\n",
" -f, --family=FAMILY Network family: ([auto], ipv4, ipv6)");
fprintf (stdout, "%s\n",
- " -o, --action=ACTION Fencing action: ([off], metadata)");
+ " -o, --action=ACTION Fencing action: ([off], monitor, metadata)");
fprintf (stdout, "%s\n",
" -t, --timeout=TIMEOUT Timeout in seconds (default: 60)");
fprintf (stdout, "%s\n",
@@ -501,6 +531,9 @@ main (int argc, char **argv)
case FENCE_KDUMP_ACTION_METADATA:
error = do_action_metadata (argv[0]);
break;
+ case FENCE_KDUMP_ACTION_MONITOR:
+ error = do_action_monitor ();
+ break;
default:
break;
}
diff --git a/fence/agents/kdump/options.h b/fence/agents/kdump/options.h
index 10fa2a2..22731d7 100644
--- a/fence/agents/kdump/options.h
+++ b/fence/agents/kdump/options.h
@@ -189,6 +189,8 @@ set_option_action (fence_kdump_opts_t *opts, const char *arg)
opts->action = FENCE_KDUMP_ACTION_OFF;
} else if (!strcasecmp (arg, "metadata")) {
opts->action = FENCE_KDUMP_ACTION_METADATA;
+ } else if (!strcasecmp (arg, "monitor")) {
+ opts->action = FENCE_KDUMP_ACTION_MONITOR;
} else {
fprintf (stderr, "[error]: unsupported action '%s'\n", arg);
exit (1);
--
1.9.3