Blame SOURCES/bz1196068-fence_kdump-add_monitor.patch

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