Blame SOURCES/bz1773890-fence_scsi-add-hash-key-value-support.patch

6147c0
From baf8d524e89d7f6c716e8241a12d8135debadfcc Mon Sep 17 00:00:00 2001
6147c0
From: Ondrej Famera <ondrej@famera.cz>
6147c0
Date: Sun, 20 Oct 2019 20:13:40 +0900
6147c0
Subject: [PATCH 1/4] add new method for autogenerating SCSI key
6147c0
6147c0
this methos generates second part of SCSI key based on hash of cluster
6147c0
node name instead of currently used ID based approach which can brake if
6147c0
the nodes get removed from cluster but whole cluster is not restarted
6147c0
because the IDs changes. With hash approach hashes stays same.
6147c0
Note that there is theoretical risk that hashes could colide.
6147c0
---
6147c0
 agents/scsi/fence_scsi.py          | 32 ++++++++++++++++++++++++++++--
6147c0
 tests/data/metadata/fence_scsi.xml |  5 +++++
6147c0
 2 files changed, 35 insertions(+), 2 deletions(-)
6147c0
6147c0
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
6147c0
index 5580e08b..4cc9b66c 100644
6147c0
--- a/agents/scsi/fence_scsi.py
6147c0
+++ b/agents/scsi/fence_scsi.py
6147c0
@@ -202,9 +202,20 @@ def get_node_id(options):
6147c0
 
6147c0
 	return match.group(1) if match else fail_usage("Failed: unable to parse output of corosync-cmapctl or node does not exist")
6147c0
 
6147c0
+def get_node_hash(options):
6147c0
+	try:
6147c0
+		return hashlib.md5(options["--plug"].encode('ascii')).hexdigest()
6147c0
+	except ValueError:
6147c0
+		# FIPS requires usedforsecurity=False and might not be
6147c0
+		# available on all distros: https://bugs.python.org/issue9216
6147c0
+		return hashlib.md5(options["--plug"].encode('ascii'), usedforsecurity=False).hexdigest()
6147c0
+
6147c0
 
6147c0
 def generate_key(options):
6147c0
-	return "%.4s%.4d" % (get_cluster_id(options), int(get_node_id(options)))
6147c0
+	if options["--key_value"] == "hash":
6147c0
+		return "%.4s%.4s" % (get_cluster_id(options), get_node_hash(options))
6147c0
+	else:
6147c0
+		return "%.4s%.4d" % (get_cluster_id(options), int(get_node_id(options)))
6147c0
 
6147c0
 
6147c0
 # save node key to file
6147c0
@@ -375,6 +386,19 @@ def define_new_opts():
6147c0
 		"default" : "@VGS_PATH@",
6147c0
 		"order": 300
6147c0
 	}
6147c0
+	all_opt["key_value"] = {
6147c0
+		"getopt" : ":",
6147c0
+		"longopt" : "key_value",
6147c0
+		"help" : "--key_value=<id|hash>          SCSI key node generation method",
6147c0
+		"required" : "0",
6147c0
+		"shortdesc" : "Method used to generate the SCSI key. \"id\" (default) \
6147c0
+uses the positional ID from \"corosync-cmactl nodelist\" output which can get inconsistent \
6147c0
+when nodes are removed from cluster without full cluster restart. \"hash\" uses part of hash \
6147c0
+made out of node names which is not affected over time but there is theoretical chance that \
6147c0
+hashes can collide as size of SCSI key is quite limited.",
6147c0
+		"default" : "id",
6147c0
+		"order": 300
6147c0
+	}
6147c0
 
6147c0
 
6147c0
 def scsi_check_get_options(options):
6147c0
@@ -440,7 +464,7 @@ def main():
6147c0
 
6147c0
 	device_opt = ["no_login", "no_password", "devices", "nodename", "port",\
6147c0
 	"no_port", "key", "aptpl", "fabric_fencing", "on_target", "corosync_cmap_path",\
6147c0
-	"sg_persist_path", "sg_turs_path", "logfile", "vgs_path", "force_on"]
6147c0
+	"sg_persist_path", "sg_turs_path", "logfile", "vgs_path", "force_on", "key_value"]
6147c0
 
6147c0
 	define_new_opts()
6147c0
 
6147c0
@@ -517,6 +541,10 @@ def main():
6147c0
 	if options["--key"] == "0" or not options["--key"]:
6147c0
 		fail_usage("Failed: key cannot be 0", stop_after_error)
6147c0
 
6147c0
+	if "--key_value" in options\
6147c0
+	and (options["--key_value"] != "id" and options["--key_value"] != "hash"):
6147c0
+		fail_usage("Failed: key_value has to be 'id' or 'hash'", stop_after_error)
6147c0
+
6147c0
 	if options["--action"] == "validate-all":
6147c0
 		sys.exit(0)
6147c0
 
6147c0
diff --git a/tests/data/metadata/fence_scsi.xml b/tests/data/metadata/fence_scsi.xml
6147c0
index b8cdabd1..56c6224d 100644
6147c0
--- a/tests/data/metadata/fence_scsi.xml
6147c0
+++ b/tests/data/metadata/fence_scsi.xml
6147c0
@@ -105,6 +105,11 @@ When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and ve
6147c0
 		<getopt mixed="--corosync-cmap-path=[path]" />
6147c0
 		<shortdesc lang="en">Path to corosync-cmapctl binary</shortdesc>
6147c0
 	</parameter>
6147c0
+	<parameter name="key_value" unique="0" required="0">
6147c0
+		<getopt mixed="--key_value=<id|hash>" />
6147c0
+		<content type="string" default="id"  />
6147c0
+		<shortdesc lang="en">Method used to generate the SCSI key. "id" (default) uses the positional ID from "corosync-cmactl nodelist" output which can get inconsistent when nodes are removed from cluster without full cluster restart. "hash" uses part of hash made out of node names which is not affected over time but there is theoretical chance that hashes can collide as size of SCSI key is quite limited.</shortdesc>
6147c0
+	</parameter>
6147c0
 	<parameter name="sg_persist_path" unique="0" required="0">
6147c0
 		<getopt mixed="--sg_persist-path=[path]" />
6147c0
 		<shortdesc lang="en">Path to sg_persist binary</shortdesc>
6147c0
6147c0
From ee7a5ea238b4b3312384e4cfd9edd392c311d17a Mon Sep 17 00:00:00 2001
6147c0
From: Ondrej Famera <ondrej@famera.cz>
6147c0
Date: Fri, 1 Nov 2019 13:16:58 +0900
6147c0
Subject: [PATCH 2/4] rename 'key_value' to 'key-value' for manual invokation
6147c0
6147c0
---
6147c0
 agents/scsi/fence_scsi.py          | 12 ++++++------
6147c0
 tests/data/metadata/fence_scsi.xml |  2 +-
6147c0
 2 files changed, 7 insertions(+), 7 deletions(-)
6147c0
6147c0
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
6147c0
index 4cc9b66c..7d515e16 100644
6147c0
--- a/agents/scsi/fence_scsi.py
6147c0
+++ b/agents/scsi/fence_scsi.py
6147c0
@@ -212,7 +212,7 @@ def get_node_hash(options):
6147c0
 
6147c0
 
6147c0
 def generate_key(options):
6147c0
-	if options["--key_value"] == "hash":
6147c0
+	if options["--key-value"] == "hash":
6147c0
 		return "%.4s%.4s" % (get_cluster_id(options), get_node_hash(options))
6147c0
 	else:
6147c0
 		return "%.4s%.4d" % (get_cluster_id(options), int(get_node_id(options)))
6147c0
@@ -388,8 +388,8 @@ def define_new_opts():
6147c0
 	}
6147c0
 	all_opt["key_value"] = {
6147c0
 		"getopt" : ":",
6147c0
-		"longopt" : "key_value",
6147c0
-		"help" : "--key_value=<id|hash>          SCSI key node generation method",
6147c0
+		"longopt" : "key-value",
6147c0
+		"help" : "--key-value=<id|hash>          SCSI key node generation method",
6147c0
 		"required" : "0",
6147c0
 		"shortdesc" : "Method used to generate the SCSI key. \"id\" (default) \
6147c0
 uses the positional ID from \"corosync-cmactl nodelist\" output which can get inconsistent \
6147c0
@@ -541,9 +541,9 @@ def main():
6147c0
 	if options["--key"] == "0" or not options["--key"]:
6147c0
 		fail_usage("Failed: key cannot be 0", stop_after_error)
6147c0
 
6147c0
-	if "--key_value" in options\
6147c0
-	and (options["--key_value"] != "id" and options["--key_value"] != "hash"):
6147c0
-		fail_usage("Failed: key_value has to be 'id' or 'hash'", stop_after_error)
6147c0
+	if "--key-value" in options\
6147c0
+	and (options["--key-value"] != "id" and options["--key-value"] != "hash"):
6147c0
+		fail_usage("Failed: key-value has to be 'id' or 'hash'", stop_after_error)
6147c0
 
6147c0
 	if options["--action"] == "validate-all":
6147c0
 		sys.exit(0)
6147c0
diff --git a/tests/data/metadata/fence_scsi.xml b/tests/data/metadata/fence_scsi.xml
6147c0
index 56c6224d..72800688 100644
6147c0
--- a/tests/data/metadata/fence_scsi.xml
6147c0
+++ b/tests/data/metadata/fence_scsi.xml
6147c0
@@ -106,7 +106,7 @@ When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and ve
6147c0
 		<shortdesc lang="en">Path to corosync-cmapctl binary</shortdesc>
6147c0
 	</parameter>
6147c0
 	<parameter name="key_value" unique="0" required="0">
6147c0
-		<getopt mixed="--key_value=<id|hash>" />
6147c0
+		<getopt mixed="--key-value=<id|hash>" />
6147c0
 		<content type="string" default="id"  />
6147c0
 		<shortdesc lang="en">Method used to generate the SCSI key. "id" (default) uses the positional ID from "corosync-cmactl nodelist" output which can get inconsistent when nodes are removed from cluster without full cluster restart. "hash" uses part of hash made out of node names which is not affected over time but there is theoretical chance that hashes can collide as size of SCSI key is quite limited.</shortdesc>
6147c0
 	</parameter>
6147c0
6147c0
From 58105710876bd6a2220f92ea37d621991d68bf4b Mon Sep 17 00:00:00 2001
6147c0
From: Ondrej Famera <ondrej@famera.cz>
6147c0
Date: Fri, 1 Nov 2019 13:20:17 +0900
6147c0
Subject: [PATCH 3/4] expand longdesc of fence_scsi to describe the impact of
6147c0
 key_value option
6147c0
6147c0
---
6147c0
 agents/scsi/fence_scsi.py          | 6 +++++-
6147c0
 tests/data/metadata/fence_scsi.xml | 2 +-
6147c0
 2 files changed, 6 insertions(+), 2 deletions(-)
6147c0
6147c0
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
6147c0
index 7d515e16..4b2bfe20 100644
6147c0
--- a/agents/scsi/fence_scsi.py
6147c0
+++ b/agents/scsi/fence_scsi.py
6147c0
@@ -493,7 +493,11 @@ def main():
6147c0
 devices must support SCSI-3 persistent reservations (SPC-3 or greater) as \
6147c0
 well as the \"preempt-and-abort\" subcommand.\nThe fence_scsi agent works by \
6147c0
 having each node in the cluster register a unique key with the SCSI \
6147c0
-device(s). Once registered, a single node will become the reservation holder \
6147c0
+device(s). Reservation key is generated from \"node id\" (default) or from \
6147c0
+\"node name hash\" (recommended) by adjusting \"key_value\" option. \
6147c0
+Using hash is recommended to prevent issues when removing nodes \
6147c0
+from cluster without full cluster restart. \
6147c0
+Once registered, a single node will become the reservation holder \
6147c0
 by creating a \"write exclusive, registrants only\" reservation on the \
6147c0
 device(s). The result is that only registered nodes may write to the \
6147c0
 device(s). When a node failure occurs, the fence_scsi agent will remove the \
6147c0
diff --git a/tests/data/metadata/fence_scsi.xml b/tests/data/metadata/fence_scsi.xml
6147c0
index 72800688..6f914823 100644
6147c0
--- a/tests/data/metadata/fence_scsi.xml
6147c0
+++ b/tests/data/metadata/fence_scsi.xml
6147c0
@@ -1,7 +1,7 @@
6147c0
 
6147c0
 <resource-agent name="fence_scsi" shortdesc="Fence agent for SCSI persistent reservation" >
6147c0
 <longdesc>fence_scsi is an I/O fencing agent that uses SCSI-3 persistent reservations to control access to shared storage devices. These devices must support SCSI-3 persistent reservations (SPC-3 or greater) as well as the "preempt-and-abort" subcommand.
6147c0
-The fence_scsi agent works by having each node in the cluster register a unique key with the SCSI device(s). Once registered, a single node will become the reservation holder by creating a "write exclusive, registrants only" reservation on the device(s). The result is that only registered nodes may write to the device(s). When a node failure occurs, the fence_scsi agent will remove the key belonging to the failed node from the device(s). The failed node will no longer be able to write to the device(s). A manual reboot is required.
6147c0
+The fence_scsi agent works by having each node in the cluster register a unique key with the SCSI device(s). Reservation key is generated from "node id" (default) or from "node name hash" (recommended) by adjusting "key_value" option. Using hash is recommended to prevent issues when removing nodes from cluster without full cluster restart. Once registered, a single node will become the reservation holder by creating a "write exclusive, registrants only" reservation on the device(s). The result is that only registered nodes may write to the device(s). When a node failure occurs, the fence_scsi agent will remove the key belonging to the failed node from the device(s). The failed node will no longer be able to write to the device(s). A manual reboot is required.
6147c0
 
6147c0
 When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and verbose=yes parameters in /etc/sysconfig/stonith if you have issues with it failing.</longdesc>
6147c0
 <vendor-url></vendor-url>
6147c0
6147c0
From 6a73919ab70d76fcf4ce19b4fd00e182e41f33b5 Mon Sep 17 00:00:00 2001
6147c0
From: Ondrej Famera <ondrej@famera.cz>
6147c0
Date: Sat, 16 Nov 2019 17:03:42 +0900
6147c0
Subject: [PATCH 4/4] emphasize the recommendation to use 'hash' over 'id'
6147c0
6147c0
---
6147c0
 agents/scsi/fence_scsi.py          | 2 +-
6147c0
 tests/data/metadata/fence_scsi.xml | 2 +-
6147c0
 2 files changed, 2 insertions(+), 2 deletions(-)
6147c0
6147c0
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
6147c0
index 4b2bfe20..9b6af556 100644
6147c0
--- a/agents/scsi/fence_scsi.py
6147c0
+++ b/agents/scsi/fence_scsi.py
6147c0
@@ -494,7 +494,7 @@ def main():
6147c0
 well as the \"preempt-and-abort\" subcommand.\nThe fence_scsi agent works by \
6147c0
 having each node in the cluster register a unique key with the SCSI \
6147c0
 device(s). Reservation key is generated from \"node id\" (default) or from \
6147c0
-\"node name hash\" (recommended) by adjusting \"key_value\" option. \
6147c0
+\"node name hash\" (RECOMMENDED) by adjusting \"key_value\" option. \
6147c0
 Using hash is recommended to prevent issues when removing nodes \
6147c0
 from cluster without full cluster restart. \
6147c0
 Once registered, a single node will become the reservation holder \
6147c0
diff --git a/tests/data/metadata/fence_scsi.xml b/tests/data/metadata/fence_scsi.xml
6147c0
index 6f914823..b840f3cf 100644
6147c0
--- a/tests/data/metadata/fence_scsi.xml
6147c0
+++ b/tests/data/metadata/fence_scsi.xml
6147c0
@@ -1,7 +1,7 @@
6147c0
 
6147c0
 <resource-agent name="fence_scsi" shortdesc="Fence agent for SCSI persistent reservation" >
6147c0
 <longdesc>fence_scsi is an I/O fencing agent that uses SCSI-3 persistent reservations to control access to shared storage devices. These devices must support SCSI-3 persistent reservations (SPC-3 or greater) as well as the "preempt-and-abort" subcommand.
6147c0
-The fence_scsi agent works by having each node in the cluster register a unique key with the SCSI device(s). Reservation key is generated from "node id" (default) or from "node name hash" (recommended) by adjusting "key_value" option. Using hash is recommended to prevent issues when removing nodes from cluster without full cluster restart. Once registered, a single node will become the reservation holder by creating a "write exclusive, registrants only" reservation on the device(s). The result is that only registered nodes may write to the device(s). When a node failure occurs, the fence_scsi agent will remove the key belonging to the failed node from the device(s). The failed node will no longer be able to write to the device(s). A manual reboot is required.
6147c0
+The fence_scsi agent works by having each node in the cluster register a unique key with the SCSI device(s). Reservation key is generated from "node id" (default) or from "node name hash" (RECOMMENDED) by adjusting "key_value" option. Using hash is recommended to prevent issues when removing nodes from cluster without full cluster restart. Once registered, a single node will become the reservation holder by creating a "write exclusive, registrants only" reservation on the device(s). The result is that only registered nodes may write to the device(s). When a node failure occurs, the fence_scsi agent will remove the key belonging to the failed node from the device(s). The failed node will no longer be able to write to the device(s). A manual reboot is required.
6147c0
 
6147c0
 When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and verbose=yes parameters in /etc/sysconfig/stonith if you have issues with it failing.</longdesc>
6147c0
 <vendor-url></vendor-url>