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

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