- fence_scsi: fix registration handling if ISID conflicts

Resolves: RHEL-5397
This commit is contained in:
Oyvind Albrigtsen 2023-10-24 12:17:30 +02:00
parent 1fb091fbe0
commit 381f73b986
3 changed files with 318 additions and 139 deletions

View File

@ -0,0 +1,68 @@
From 9d0d0d013c7edae43a4ebc5f46bf2e7a4f127654 Mon Sep 17 00:00:00 2001
From: "sreejit.mohanan" <sreejit.mohanan@nutanix.com>
Date: Fri, 17 Feb 2023 18:04:03 -0800
Subject: [PATCH] fence_scsi: fix registration handling if ISID conflicts ISID
(Initiator Session ID) belonging to I_T Nexus changes for RHEL based on the
session ID. This means that the connection to the device can be set up with
different ISID on reconnects.
fence_scsi treats same key as a tip to ignore issuing registration
to the device but if the device was registered using a different
ISID, the key would be the same but the I_T Nexus (new ISID) would
not have access to the device.
Fixing this by preempting the old key and replacing with the current
one.
---
agents/scsi/fence_scsi.py | 35 ++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
index f9e6823b2..85e4f29e6 100644
--- a/agents/scsi/fence_scsi.py
+++ b/agents/scsi/fence_scsi.py
@@ -137,12 +137,41 @@ def register_dev(options, dev):
for slave in get_mpath_slaves(dev):
register_dev(options, slave)
return True
- if get_reservation_key(options, dev, False) == options["--key"]:
- return True
+
+ # Check if any registration exists for the key already. We track this in
+ # order to decide whether the existing registration needs to be cleared.
+ # This is needed since the previous registration could be for a
+ # different I_T nexus (different ISID).
+ registration_key_exists = False
+ if options["--key"] in get_registration_keys(options, dev):
+ registration_key_exists = True
+ if not register_helper(options, options["--key"], dev):
+ return False
+
+ if registration_key_exists:
+ # If key matches, make sure it matches with the connection that
+ # exists right now. To do this, we can issue a preempt with same key
+ # which should replace the old invalid entries from the target.
+ if not preempt(options, options["--key"], dev):
+ return False
+
+ # If there was no reservation, we need to issue another registration
+ # since the previous preempt would clear registration made above.
+ if get_reservation_key(options, dev, False) != options["--key"]:
+ return register_helper(options, options["--key"], dev)
+ return True
+
+# cancel registration without aborting tasks
+def preempt(options, host, dev):
+ reset_dev(options,dev)
+ cmd = options["--sg_persist-path"] + " -n -o -P -T 5 -K " + host + " -S " + options["--key"] + " -d " + dev
+ return not bool(run_cmd(options, cmd)["rc"])
+
+# helper function to send the register command
+def register_helper(options, host, dev):
reset_dev(options, dev)
cmd = options["--sg_persist-path"] + " -n -o -I -S " + options["--key"] + " -d " + dev
cmd += " -Z" if "--aptpl" in options else ""
- #cmd return code != 0 but registration can be successful
return not bool(run_cmd(options, cmd)["err"])

View File

@ -0,0 +1,103 @@
From 34baef58db442148b8e067509d2cdd37b7a91ef4 Mon Sep 17 00:00:00 2001
From: "sreejit.mohanan" <sreejit.mohanan@nutanix.com>
Date: Thu, 7 Sep 2023 15:57:51 -0700
Subject: [PATCH] fence_scsi: fix registration handling in device 'off'
workflows
ISID (Initiator Session ID) belonging to I_T Nexus changes for
RHEL based on the session ID. This means that the connection to
the device can be set up with different ISID on reconnects.
When a device is powered off, fence_scsi assumes that the client
has a registration to the device and sends a preempt-and-abort
request which ends up failing due to reservation conflict.
Fixing this by registering the host key with the device and preempting
the old registration (if it exists). This should make sure that the
host is able to preempt the other key successfully.
---
agents/scsi/fence_scsi.py | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
index 42530ceb5..519319bf5 100644
--- a/agents/scsi/fence_scsi.py
+++ b/agents/scsi/fence_scsi.py
@@ -41,7 +41,7 @@ def set_status(conn, options):
for dev in options["devices"]:
is_block_device(dev)
- register_dev(options, dev)
+ register_dev(options, dev, options["--key"])
if options["--key"] not in get_registration_keys(options, dev):
count += 1
logging.debug("Failed to register key "\
@@ -62,7 +62,7 @@ def set_status(conn, options):
fail_usage("Failed: keys cannot be same. You can not fence yourself.")
for dev in options["devices"]:
is_block_device(dev)
-
+ register_dev(options, dev, host_key)
if options["--key"] in get_registration_keys(options, dev):
preempt_abort(options, host_key, dev)
@@ -131,11 +131,11 @@ def reset_dev(options, dev):
return run_cmd(options, options["--sg_turs-path"] + " " + dev)["rc"]
-def register_dev(options, dev):
+def register_dev(options, dev, key):
dev = os.path.realpath(dev)
if re.search(r"^dm", dev[5:]):
for slave in get_mpath_slaves(dev):
- register_dev(options, slave)
+ register_dev(options, slave, key)
return True
# Check if any registration exists for the key already. We track this in
@@ -143,34 +143,35 @@ def register_dev(options, dev):
# This is needed since the previous registration could be for a
# different I_T nexus (different ISID).
registration_key_exists = False
- if options["--key"] in get_registration_keys(options, dev):
+ if key in get_registration_keys(options, dev):
+ logging.debug("Registration key exists for device " + dev)
registration_key_exists = True
- if not register_helper(options, options["--key"], dev):
+ if not register_helper(options, dev, key):
return False
if registration_key_exists:
# If key matches, make sure it matches with the connection that
# exists right now. To do this, we can issue a preempt with same key
# which should replace the old invalid entries from the target.
- if not preempt(options, options["--key"], dev):
+ if not preempt(options, key, dev, key):
return False
# If there was no reservation, we need to issue another registration
# since the previous preempt would clear registration made above.
- if get_reservation_key(options, dev, False) != options["--key"]:
- return register_helper(options, options["--key"], dev)
+ if get_reservation_key(options, dev, False) != key:
+ return register_helper(options, dev, key)
return True
-# cancel registration without aborting tasks
-def preempt(options, host, dev):
+# helper function to preempt host with 'key' using 'host_key' without aborting tasks
+def preempt(options, host_key, dev, key):
reset_dev(options,dev)
- cmd = options["--sg_persist-path"] + " -n -o -P -T 5 -K " + host + " -S " + options["--key"] + " -d " + dev
+ cmd = options["--sg_persist-path"] + " -n -o -P -T 5 -K " + host_key + " -S " + key + " -d " + dev
return not bool(run_cmd(options, cmd)["rc"])
# helper function to send the register command
-def register_helper(options, host, dev):
+def register_helper(options, dev, key):
reset_dev(options, dev)
- cmd = options["--sg_persist-path"] + " -n -o -I -S " + options["--key"] + " -d " + dev
+ cmd = options["--sg_persist-path"] + " -n -o -I -S " + key + " -d " + dev
cmd += " -Z" if "--aptpl" in options else ""
return not bool(run_cmd(options, cmd)["rc"])

View File

@ -87,7 +87,7 @@
Name: fence-agents Name: fence-agents
Summary: Set of unified programs capable of host isolation ("fencing") Summary: Set of unified programs capable of host isolation ("fencing")
Version: 4.2.1 Version: 4.2.1
Release: 125%{?alphatag:.%{alphatag}}%{?dist} Release: 126%{?alphatag:.%{alphatag}}%{?dist}
License: GPLv2+ and LGPLv2+ License: GPLv2+ and LGPLv2+
Group: System Environment/Base Group: System Environment/Base
URL: https://github.com/ClusterLabs/fence-agents URL: https://github.com/ClusterLabs/fence-agents
@ -277,6 +277,8 @@ Patch134: bz2155453-fence_ibm_powervs-performance-improvements.patch
Patch135: RHEL-14343-fence_zvmip-document-user-permissions.patch Patch135: RHEL-14343-fence_zvmip-document-user-permissions.patch
Patch136: RHEL-14031-1-all-agents-metadata-update-IO-Power-Network.patch Patch136: RHEL-14031-1-all-agents-metadata-update-IO-Power-Network.patch
Patch137: RHEL-14031-2-fence_cisco_mds-undo-metadata-change.patch Patch137: RHEL-14031-2-fence_cisco_mds-undo-metadata-change.patch
Patch138: RHEL-5397-fence_scsi-1-fix-ISID-reg-handling.patch
Patch139: RHEL-5397-fence_scsi-2-fix-ISID-reg-handling-off.patch
### HA support libs/utils ### ### HA support libs/utils ###
# all archs # all archs
@ -362,144 +364,146 @@ BuildRequires: python3-google-api-client python3-pip python3-wheel python3-jinja
%prep %prep
%setup -q -n %{name}-%{version} %setup -q -n %{name}-%{version}
%patch0 -p1 %patch -p1 -P 0
%patch1 -p1 %patch -p1 -P 1
%patch2 -p1 %patch -p1 -P 2
%patch3 -p1 %patch -p1 -P 3
%patch4 -p1 %patch -p1 -P 4
%patch5 -p1 %patch -p1 -P 5
%patch6 -p1 %patch -p1 -P 6
%patch7 -p1 %patch -p1 -P 7
%patch8 -p1 %patch -p1 -P 8
%patch9 -p1 %patch -p1 -P 9
%patch10 -p1 %patch -p1 -P 10
%patch11 -p1 %patch -p1 -P 11
%patch12 -p1 %patch -p1 -P 12
%patch13 -p1 %patch -p1 -P 13
%patch14 -p1 %patch -p1 -P 14
%patch15 -p1 %patch -p1 -P 15
%patch16 -p1 %patch -p1 -P 16
%patch17 -p1 %patch -p1 -P 17
%patch18 -p1 %patch -p1 -P 18
%patch19 -p1 %patch -p1 -P 19
%patch20 -p1 %patch -p1 -P 20
%patch21 -p1 %patch -p1 -P 21
%patch22 -p1 %patch -p1 -P 22
%patch23 -p1 %patch -p1 -P 23
%patch24 -p1 %patch -p1 -P 24
%patch25 -p1 %patch -p1 -P 25
%patch26 -p1 %patch -p1 -P 26
%patch27 -p1 %patch -p1 -P 27
%patch28 -p1 %patch -p1 -P 28
%patch29 -p1 %patch -p1 -P 29
%patch30 -p1 -F2 %patch -p1 -P 30 -F2
%patch31 -p1 -F2 %patch -p1 -P 31 -F2
%patch32 -p1 %patch -p1 -P 32
%patch33 -p1 %patch -p1 -P 33
%patch34 -p1 %patch -p1 -P 34
%patch35 -p1 %patch -p1 -P 35
%patch36 -p1 -F1 %patch -p1 -P 36 -F1
%patch37 -p1 %patch -p1 -P 37
%patch38 -p1 %patch -p1 -P 38
%patch39 -p1 %patch -p1 -P 39
%patch40 -p1 -F2 %patch -p1 -P 40 -F2
%patch41 -p1 %patch -p1 -P 41
%patch42 -p1 %patch -p1 -P 42
%patch43 -p1 %patch -p1 -P 43
%patch44 -p1 %patch -p1 -P 44
%patch45 -p1 %patch -p1 -P 45
%patch46 -p1 %patch -p1 -P 46
%patch47 -p1 %patch -p1 -P 47
%patch48 -p1 -F1 %patch -p1 -P 48 -F1
%patch49 -p1 %patch -p1 -P 49
%patch50 -p1 %patch -p1 -P 50
%patch51 -p1 %patch -p1 -P 51
%patch52 -p1 %patch -p1 -P 52
%patch53 -p1 %patch -p1 -P 53
%patch54 -p1 %patch -p1 -P 54
%patch55 -p1 %patch -p1 -P 55
%patch56 -p1 %patch -p1 -P 56
%patch57 -p1 %patch -p1 -P 57
%patch58 -p1 %patch -p1 -P 58
%patch59 -p1 %patch -p1 -P 59
%patch60 -p1 -F1 %patch -p1 -P 60 -F1
%patch61 -p1 %patch -p1 -P 61
%patch62 -p1 %patch -p1 -P 62
%patch63 -p1 %patch -p1 -P 63
%patch64 -p1 %patch -p1 -P 64
%patch65 -p1 -F1 %patch -p1 -P 65 -F1
%patch66 -p1 %patch -p1 -P 66
%patch67 -p1 %patch -p1 -P 67
%patch68 -p1 %patch -p1 -P 68
%patch69 -p1 %patch -p1 -P 69
%patch70 -p1 %patch -p1 -P 70
%patch71 -p1 %patch -p1 -P 71
%patch72 -p1 %patch -p1 -P 72
%patch73 -p1 %patch -p1 -P 73
%patch74 -p1 %patch -p1 -P 74
%patch75 -p1 %patch -p1 -P 75
%patch76 -p1 %patch -p1 -P 76
%patch77 -p1 %patch -p1 -P 77
%patch78 -p1 %patch -p1 -P 78
%patch79 -p1 %patch -p1 -P 79
%patch80 -p1 %patch -p1 -P 80
%patch81 -p1 %patch -p1 -P 81
%patch82 -p1 %patch -p1 -P 82
%patch83 -p1 %patch -p1 -P 83
%patch84 -p1 %patch -p1 -P 84
%patch85 -p1 %patch -p1 -P 85
%patch86 -p1 -F1 %patch -p1 -P 86 -F1
%patch87 -p1 %patch -p1 -P 87
%patch88 -p1 %patch -p1 -P 88
%patch89 -p1 %patch -p1 -P 89
%patch90 -p1 %patch -p1 -P 90
%patch91 -p1 %patch -p1 -P 91
%patch92 -p1 %patch -p1 -P 92
%patch93 -p1 %patch -p1 -P 93
%patch94 -p1 %patch -p1 -P 94
%patch95 -p1 %patch -p1 -P 95
%patch96 -p1 -F2 %patch -p1 -P 96 -F2
%patch97 -p1 %patch -p1 -P 97
%patch98 -p1 %patch -p1 -P 98
%patch99 -p1 %patch -p1 -P 99
%patch100 -p1 %patch -p1 -P 100
%patch101 -p1 %patch -p1 -P 101
%patch102 -p1 %patch -p1 -P 102
%patch103 -p1 %patch -p1 -P 103
%patch104 -p1 -F1 %patch -p1 -P 104 -F1
%patch105 -p1 %patch -p1 -P 105
%patch106 -p1 %patch -p1 -P 106
%patch107 -p1 %patch -p1 -P 107
%patch108 -p1 %patch -p1 -P 108
%patch109 -p1 %patch -p1 -P 109
%patch110 -p1 %patch -p1 -P 110
%patch111 -p1 %patch -p1 -P 111
%patch112 -p1 %patch -p1 -P 112
%patch113 -p1 %patch -p1 -P 113
%patch114 -p1 %patch -p1 -P 114
%patch115 -p1 %patch -p1 -P 115
%patch116 -p1 %patch -p1 -P 116
%patch117 -p1 %patch -p1 -P 117
%patch118 -p1 %patch -p1 -P 118
%patch119 -p1 %patch -p1 -P 119
%patch120 -p1 %patch -p1 -P 120
%patch121 -p1 %patch -p1 -P 121
%patch122 -p1 -F2 %patch -p1 -P 122 -F2
%patch123 -p1 %patch -p1 -P 123
%patch124 -p1 %patch -p1 -P 124
%patch125 -p1 %patch -p1 -P 125
%patch126 -p1 %patch -p1 -P 126
%patch127 -p1 %patch -p1 -P 127
%patch128 -p1 -F2 %patch -p1 -P 128 -F2
%patch129 -p1 %patch -p1 -P 129
%patch130 -p1 %patch -p1 -P 130
%patch131 -p1 %patch -p1 -P 131
%patch132 -p1 %patch -p1 -P 132
%patch133 -p1 %patch -p1 -P 133
%patch134 -p1 %patch -p1 -P 134
%patch135 -p1 %patch -p1 -P 135
%patch136 -p1 -F2 %patch -p1 -P 136 -F2
%patch137 -p1 %patch -p1 -P 137
%patch -p1 -P 138
%patch -p1 -P 139 -F2
# prevent compilation of something that won't get used anyway # prevent compilation of something that won't get used anyway
sed -i.orig 's|FENCE_ZVM=1|FENCE_ZVM=0|' configure.ac sed -i.orig 's|FENCE_ZVM=1|FENCE_ZVM=0|' configure.ac
@ -1508,6 +1512,10 @@ Fence agent for IBM z/VM over IP.
%endif %endif
%changelog %changelog
* Tue Oct 24 2023 Oyvind Albrigtsen <oalbrigt@redhat.com> - 4.2.1-126
- fence_scsi: fix registration handling if ISID conflicts
Resolves: RHEL-5397
* Mon Oct 23 2023 Oyvind Albrigtsen <oalbrigt@redhat.com> - 4.2.1-125 * Mon Oct 23 2023 Oyvind Albrigtsen <oalbrigt@redhat.com> - 4.2.1-125
- all agents: update metadata in non-I/O agents to Power or Network - all agents: update metadata in non-I/O agents to Power or Network
fencing fencing