|
|
bda387 |
From 5f7dbb212b4d6da4f8f2609ae1415e8630d031cd Mon Sep 17 00:00:00 2001
|
|
|
bda387 |
From: Vojtech Trefny <vtrefny@redhat.com>
|
|
|
bda387 |
Date: Mon, 13 May 2019 12:49:52 +0200
|
|
|
bda387 |
Subject: [PATCH] Correctly handle non-unicode iSCSI initiator names
|
|
|
bda387 |
|
|
|
bda387 |
---
|
|
|
bda387 |
blivet/iscsi.py | 4 +++-
|
|
|
bda387 |
blivet/udev.py | 20 +++++++++++---------
|
|
|
bda387 |
2 files changed, 14 insertions(+), 10 deletions(-)
|
|
|
bda387 |
|
|
|
bda387 |
diff --git a/blivet/iscsi.py b/blivet/iscsi.py
|
|
|
bda387 |
index 74432505..f612cf15 100644
|
|
|
bda387 |
--- a/blivet/iscsi.py
|
|
|
bda387 |
+++ b/blivet/iscsi.py
|
|
|
bda387 |
@@ -206,7 +206,9 @@ def initiator(self):
|
|
|
bda387 |
if self._initiator != "":
|
|
|
bda387 |
return self._initiator
|
|
|
bda387 |
|
|
|
bda387 |
- return self._call_initiator_method("GetInitiatorName")[0]
|
|
|
bda387 |
+ # udisks returns initiatorname as a NULL terminated bytearray
|
|
|
bda387 |
+ raw_initiator = bytes(self._call_initiator_method("GetInitiatorNameRaw")[0][:-1])
|
|
|
bda387 |
+ return raw_initiator.decode("utf-8", errors="replace")
|
|
|
bda387 |
|
|
|
bda387 |
@initiator.setter
|
|
|
bda387 |
@storaged_iscsi_required(critical=True, eval_mode=util.EvalMode.onetime)
|
|
|
bda387 |
diff --git a/blivet/udev.py b/blivet/udev.py
|
|
|
bda387 |
index 51b69b76..a70e3e08 100644
|
|
|
bda387 |
--- a/blivet/udev.py
|
|
|
bda387 |
+++ b/blivet/udev.py
|
|
|
bda387 |
@@ -836,24 +836,26 @@ def device_get_iscsi_nic(info):
|
|
|
bda387 |
|
|
|
bda387 |
|
|
|
bda387 |
def device_get_iscsi_initiator(info):
|
|
|
bda387 |
- initiator = None
|
|
|
bda387 |
+ initiator_name = None
|
|
|
bda387 |
if device_is_partoff_iscsi(info):
|
|
|
bda387 |
host = re.match(r'.*/(host\d+)', device_get_sysfs_path(info)).groups()[0]
|
|
|
bda387 |
if host:
|
|
|
bda387 |
initiator_file = "/sys/class/iscsi_host/%s/initiatorname" % host
|
|
|
bda387 |
if os.access(initiator_file, os.R_OK):
|
|
|
bda387 |
- initiator = open(initiator_file).read().strip()
|
|
|
bda387 |
+ initiator = open(initiator_file, "rb").read().strip()
|
|
|
bda387 |
+ initiator_name = initiator.decode("utf-8", errors="replace")
|
|
|
bda387 |
log.debug("found offload iscsi initiatorname %s in file %s",
|
|
|
bda387 |
- initiator, initiator_file)
|
|
|
bda387 |
- if initiator.lstrip("(").rstrip(")").lower() == "null":
|
|
|
bda387 |
- initiator = None
|
|
|
bda387 |
- if initiator is None:
|
|
|
bda387 |
+ initiator_name, initiator_file)
|
|
|
bda387 |
+ if initiator_name.lstrip("(").rstrip(")").lower() == "null":
|
|
|
bda387 |
+ initiator_name = None
|
|
|
bda387 |
+ if initiator_name is None:
|
|
|
bda387 |
session = device_get_iscsi_session(info)
|
|
|
bda387 |
if session:
|
|
|
bda387 |
initiator = open("/sys/class/iscsi_session/%s/initiatorname" %
|
|
|
bda387 |
- session).read().strip()
|
|
|
bda387 |
- log.debug("found iscsi initiatorname %s", initiator)
|
|
|
bda387 |
- return initiator
|
|
|
bda387 |
+ session, "rb").read().strip()
|
|
|
bda387 |
+ initiator_name = initiator.decode("utf-8", errors="replace")
|
|
|
bda387 |
+ log.debug("found iscsi initiatorname %s", initiator_name)
|
|
|
bda387 |
+ return initiator_name
|
|
|
bda387 |
|
|
|
bda387 |
|
|
|
bda387 |
# fcoe disks have ID_PATH in the form of:
|