File bsc#1171372-0005-Refactor-libstonithd-add-function-to-check-supported.patch of Package pacemaker.21298

From 13c73cd447b39f5eb6deef9aa46b08a6f035729a Mon Sep 17 00:00:00 2001
From: "Gao,Yan" <ygao@suse.com>
Date: Wed, 6 May 2020 19:17:28 +0200
Subject: [PATCH 5/6] Refactor: libstonithd: add function to check supported
 parameters according to the metadata of a fence agent

---
 daemons/fenced/pacemaker-fenced.h |  7 ------
 include/crm/fencing/internal.h    | 11 ++++++++
 lib/fencing/st_client.c           | 42 +++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 7 deletions(-)

Index: pacemaker-2.0.1+20190417.13d370ca9/daemons/fenced/pacemaker-fenced.h
===================================================================
--- pacemaker-2.0.1+20190417.13d370ca9.orig/daemons/fenced/pacemaker-fenced.h
+++ pacemaker-2.0.1+20190417.13d370ca9/daemons/fenced/pacemaker-fenced.h
@@ -19,13 +19,6 @@
  */
 gboolean stonith_check_fence_tolerance(int tolerance, const char *target, const char *action);
 
-enum st_device_flags
-{
-    st_device_supports_list   = 0x0001,
-    st_device_supports_status = 0x0002,
-    st_device_supports_reboot = 0x0004,
-};
-
 typedef struct stonith_device_s {
     char *id;
     char *agent;
Index: pacemaker-2.0.1+20190417.13d370ca9/include/crm/fencing/internal.h
===================================================================
--- pacemaker-2.0.1+20190417.13d370ca9.orig/include/crm/fencing/internal.h
+++ pacemaker-2.0.1+20190417.13d370ca9/include/crm/fencing/internal.h
@@ -13,6 +13,15 @@
 #  include <crm/common/ipc.h>
 #  include <crm/common/xml.h>
 
+enum st_device_flags
+{
+    st_device_supports_list   = 0x0001,
+    st_device_supports_status = 0x0002,
+    st_device_supports_reboot = 0x0004,
+    st_device_supports_parameter_plug = 0x0008,
+    st_device_supports_parameter_port = 0x0010,
+};
+
 struct stonith_action_s;
 typedef struct stonith_action_s stonith_action_t;
 
@@ -45,6 +54,8 @@ xmlNode *create_device_registration_xml(
                                         stonith_key_value_t *params,
                                         const char *rsc_provides);
 
+long long stonith__device_parameter_flags(xmlNode *metadata);
+
 #  define ST_LEVEL_MAX 10
 
 #  define F_STONITH_CLIENTID      "st_clientid"
Index: pacemaker-2.0.1+20190417.13d370ca9/lib/fencing/st_client.c
===================================================================
--- pacemaker-2.0.1+20190417.13d370ca9.orig/lib/fencing/st_client.c
+++ pacemaker-2.0.1+20190417.13d370ca9/lib/fencing/st_client.c
@@ -2541,3 +2541,45 @@ stonith_action_str(const char *action)
         return action;
     }
 }
+
+long long
+stonith__device_parameter_flags(xmlNode *metadata)
+{
+    xmlXPathObjectPtr xpath = NULL;
+    int max = 0;
+    int lpc = 0;
+    long long flags = 0;
+
+    CRM_CHECK(metadata, return 0);
+
+    xpath = xpath_search(metadata, "//parameter");
+    max = numXpathResults(xpath);
+
+    if (max <= 0) {
+        freeXpathObject(xpath);
+        return 0;
+    }
+
+    for (lpc = 0; lpc < max; lpc++) {
+        const char *parameter = NULL;
+        xmlNode *match = getXpathResult(xpath, lpc);
+
+        CRM_LOG_ASSERT(match != NULL);
+        if (match == NULL) {
+            continue;
+        }
+
+        parameter = crm_element_value(match, "name");
+
+        if (safe_str_eq(parameter, "plug")) {
+            set_bit(flags, st_device_supports_parameter_plug);
+
+        } else if (safe_str_eq(parameter, "port")) {
+            set_bit(flags, st_device_supports_parameter_port);
+        }
+    }
+
+    freeXpathObject(xpath);
+
+    return flags;
+}
openSUSE Build Service is sponsored by