File bsc#1148236-0001-Low-fencer-improve-error-checking-and-log-messages-f.patch of Package pacemaker.19404

From 652f582112b62489af9e865c14f11e9183e8cd12 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 21 Feb 2019 15:08:05 -0600
Subject: [PATCH 1/2] Low: fencer: improve error checking and log messages for
 API action requests

---
 fencing/commands.c | 54 +++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 21 deletions(-)

Index: pacemaker-1.1.18+20180430.b12c320f5/fencing/commands.c
===================================================================
--- pacemaker-1.1.18+20180430.b12c320f5.orig/fencing/commands.c
+++ pacemaker-1.1.18+20180430.b12c320f5/fencing/commands.c
@@ -1551,38 +1551,50 @@ stonith_level_remove(xmlNode *msg, char
     return pcmk_ok;
 }
 
+/*!
+ * \internal
+ * \brief Schedule an (asynchronous) action directly on a stonith device
+ *
+ * Handle a STONITH_OP_EXEC API message by scheduling a requested agent action
+ * directly on a specified device. Only list, monitor, and status actions are
+ * expected to use this call, though it should work with any agent command.
+ *
+ * \param[in]  msg     API message XML with desired action
+ * \param[out] output  Unused
+ *
+ * \return -EINPROGRESS on success, -errno otherwise
+ */
 static int
 stonith_device_action(xmlNode * msg, char **output)
 {
-    int rc = pcmk_ok;
     xmlNode *dev = get_xpath_object("//" F_STONITH_DEVICE, msg, LOG_ERR);
+    xmlNode *op = get_xpath_object("//@" F_STONITH_ACTION, msg, LOG_ERR);
     const char *id = crm_element_value(dev, F_STONITH_DEVICE);
-
+    const char *action = crm_element_value(op, F_STONITH_ACTION);
     async_command_t *cmd = NULL;
     stonith_device_t *device = NULL;
 
-    if (id) {
-        crm_trace("Looking for '%s'", id);
-        device = g_hash_table_lookup(device_list, id);
+    if ((id == NULL) || (action == NULL)) {
+        crm_info("Malformed API action request: device %s, action %s",
+                 (id? id : "not specified"),
+                 (action? action : "not specified"));
+        return -EPROTO;
     }
 
-    if (device && device->api_registered == FALSE) {
-        rc = -ENODEV;
-
-    } else if (device) {
-        cmd = create_async_command(msg);
-        if (cmd == NULL) {
-            return -EPROTO;
-        }
-
-        schedule_stonith_command(cmd, device);
-        rc = -EINPROGRESS;
+    device = g_hash_table_lookup(device_list, id);
+    if ((device == NULL) || !device->api_registered) {
+        crm_info("Ignoring API %s action request because device %s not found",
+                 action, id);
+        return -ENODEV;
+    }
 
-    } else {
-        crm_info("Device %s not found", id ? id : "<none>");
-        rc = -ENODEV;
+    cmd = create_async_command(msg);
+    if (cmd == NULL) {
+        return -EPROTO;
     }
-    return rc;
+
+    schedule_stonith_command(cmd, device);
+    return -EINPROGRESS;
 }
 
 static void
@@ -2171,7 +2183,7 @@ st_child_done(GPid pid, int rc, const ch
     /* The device is ready to do something else now */
     device = g_hash_table_lookup(device_list, cmd->device);
     if (device) {
-        if (rc == pcmk_ok &&
+        if (!device->verified && (rc == pcmk_ok) &&
             (safe_str_eq(cmd->action, "list") ||
              safe_str_eq(cmd->action, "monitor") || safe_str_eq(cmd->action, "status"))) {
 
openSUSE Build Service is sponsored by