61 lines
2.0 KiB
Diff
61 lines
2.0 KiB
Diff
|
From 431e8bc40288d97d80f07ec195c0a07c5f8c065a Mon Sep 17 00:00:00 2001
|
||
|
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
|
||
|
Date: Tue, 10 Nov 2020 12:46:50 +0100
|
||
|
Subject: [PATCH] fence_scsi: dont write key to device if it's already
|
||
|
registered, and open file correctly to avoid using regex against end-of-file
|
||
|
|
||
|
---
|
||
|
agents/scsi/fence_scsi.py | 12 +++++-------
|
||
|
1 file changed, 5 insertions(+), 7 deletions(-)
|
||
|
|
||
|
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
|
||
|
index 77817f35..9a86689d 100644
|
||
|
--- a/agents/scsi/fence_scsi.py
|
||
|
+++ b/agents/scsi/fence_scsi.py
|
||
|
@@ -135,6 +135,8 @@ 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
|
||
|
reset_dev(options, dev)
|
||
|
cmd = options["--sg_persist-path"] + " -n -o -I -S " + options["--key"] + " -d " + dev
|
||
|
cmd += " -Z" if "--aptpl" in options else ""
|
||
|
@@ -148,14 +150,14 @@ def reserve_dev(options, dev):
|
||
|
return not bool(run_cmd(options, cmd)["err"])
|
||
|
|
||
|
|
||
|
-def get_reservation_key(options, dev):
|
||
|
+def get_reservation_key(options, dev, fail=True):
|
||
|
reset_dev(options,dev)
|
||
|
opts = ""
|
||
|
if "--readonly" in options:
|
||
|
opts = "-y "
|
||
|
cmd = options["--sg_persist-path"] + " -n -i " + opts + "-r -d " + dev
|
||
|
out = run_cmd(options, cmd)
|
||
|
- if out["err"]:
|
||
|
+ if out["err"] and fail:
|
||
|
fail_usage("Cannot get reservation key")
|
||
|
match = re.search(r"\s+key=0x(\S+)\s+", out["out"], re.IGNORECASE)
|
||
|
return match.group(1) if match else None
|
||
|
@@ -257,6 +259,7 @@ def dev_write(dev, options):
|
||
|
f = open(file_path, "a+")
|
||
|
except IOError:
|
||
|
fail_usage("Failed: Cannot open file \""+ file_path + "\"")
|
||
|
+ f.seek(0)
|
||
|
out = f.read()
|
||
|
if not re.search(r"^" + dev + "\s+", out, flags=re.MULTILINE):
|
||
|
f.write(dev + "\n")
|
||
|
@@ -277,11 +280,6 @@ def dev_read(fail=True):
|
||
|
return devs
|
||
|
|
||
|
|
||
|
-def dev_delete(options):
|
||
|
- file_path = options["store_path"] + ".dev"
|
||
|
- os.remove(file_path) if os.path.exists(file_path) else None
|
||
|
-
|
||
|
-
|
||
|
def get_clvm_devices(options):
|
||
|
devs = []
|
||
|
cmd = options["--vgs-path"] + " " +\
|