Blame SOURCES/0007-alua-enable-alua-for-pscsi-tcmu-if-kernel-reports-su.patch

4959d3
From 86fed9fdab8803fd8d321c8242097e7b4f952ada Mon Sep 17 00:00:00 2001
4959d3
From: Maurizio Lombardi <mlombard@redhat.com>
4959d3
Date: Tue, 27 Mar 2018 14:50:09 +0200
4959d3
Subject: [PATCH] alua: enable alua for pscsi/tcmu if kernel reports support
4959d3
4959d3
4.14 (it is currently the 4.13 feature window and I think we will
4959d3
miss it) will add this patch
4959d3
4959d3
https://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git/commit/?h=for-next&id=c17d5d5f51f72f24e0e17a4450ae5010bf6962d9
4959d3
4959d3
commit c17d5d5f51f72f24e0e17a4450ae5010bf6962d9
4959d3
Author: Mike Christie <mchristi@redhat.com>
4959d3
Date:   Mon Jul 10 14:53:31 2017 -0500
4959d3
4959d3
    target: export lio pgr/alua support as device attr
4959d3
4959d3
which has the lio device report if it supports lio based ALUA.
4959d3
We can then check this configfs file and know if we are using
4959d3
a modern kernel with support and not worry about possibly crashing
4959d3
the system.
4959d3
4959d3
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
4959d3
---
4959d3
 rtslib/alua.py |  4 ----
4959d3
 rtslib/tcm.py  | 23 ++++++++++++++++++-----
4959d3
 2 files changed, 18 insertions(+), 9 deletions(-)
4959d3
4959d3
diff --git a/rtslib/alua.py b/rtslib/alua.py
4959d3
index 390e74a..fadc225 100644
4959d3
--- a/rtslib/alua.py
4959d3
+++ b/rtslib/alua.py
4959d3
@@ -46,10 +46,6 @@ class ALUATargetPortGroup(CFSNode):
4959d3
         @param tag: target port group id. If not passed in, try to look
4959d3
                     up existing ALUA TPG with the same name
4959d3
         """
4959d3
-        # kernel partially sets up default_tg_pt_gp and will let you partially
4959d3
-        # setup ALUA groups for pscsi and user, but writing to some of the
4959d3
-        # files will crash the kernel. Just fail to even create groups until
4959d3
-        # the kernel is fixed.
4959d3
         if storage_object.alua_supported is False:
4959d3
             raise RTSLibALUANotSupported("Backend does not support ALUA setup")
4959d3
 
4959d3
diff --git a/rtslib/tcm.py b/rtslib/tcm.py
4959d3
index aa3530a..bf681fe 100644
4959d3
--- a/rtslib/tcm.py
4959d3
+++ b/rtslib/tcm.py
4959d3
@@ -32,6 +32,19 @@ from .utils import convert_scsi_path_to_hctl, convert_scsi_hctl_to_path
4959d3
 from .utils import is_dev_in_use, get_blockdev_type
4959d3
 from .utils import get_size_for_blk_dev, get_size_for_disk_name
4959d3
 
4959d3
+def storage_object_get_alua_support_attr(so):
4959d3
+    '''
4959d3
+    Helper function that can be called by passthrough type of backends.
4959d3
+    '''
4959d3
+    try:
4959d3
+        if int(so.get_attribute("alua_support")) == 1:
4959d3
+            return True
4959d3
+    except RTSLibError:
4959d3
+            pass
4959d3
+    # Default to false because older kernels will crash when
4959d3
+    # reading/writing to some ALUA files when ALUA was not
4959d3
+    # fully supported by pscsi and tcmu.
4959d3
+    return False
4959d3
 
4959d3
 class StorageObject(CFSNode):
4959d3
     '''
4959d3
@@ -227,7 +240,7 @@ class StorageObject(CFSNode):
4959d3
 
4959d3
     def _get_alua_supported(self):
4959d3
         '''
4959d3
-        Children should override and return false if ALUA setup is not supported.
4959d3
+        Children should override if the backend did not always support ALUA
4959d3
         '''
4959d3
         self._check_self()
4959d3
         return True
4959d3
@@ -420,7 +433,7 @@ class PSCSIStorageObject(StorageObject):
4959d3
 
4959d3
     def _get_alua_supported(self):
4959d3
         self._check_self()
4959d3
-        return False
4959d3
+        return storage_object_get_alua_support_attr(self)
4959d3
 
4959d3
     # PSCSIStorageObject public stuff
4959d3
 
4959d3
@@ -442,7 +455,7 @@ class PSCSIStorageObject(StorageObject):
4959d3
     lun = property(_get_lun,
4959d3
             doc="Get the SCSI device LUN")
4959d3
     alua_supported = property(_get_alua_supported,
4959d3
-            doc="ALUA cannot be setup with rtslib, so False is returned.");
4959d3
+            doc="Returns true if ALUA can be setup. False if not supported.")
4959d3
 
4959d3
     def dump(self):
4959d3
         d = super(PSCSIStorageObject, self).dump()
4959d3
@@ -826,14 +839,14 @@ class UserBackedStorageObject(StorageObject):
4959d3
 
4959d3
     def _get_alua_supported(self):
4959d3
         self._check_self()
4959d3
-        return False
4959d3
+        return storage_object_get_alua_support_attr(self)
4959d3
 
4959d3
     size = property(_get_size,
4959d3
             doc="Get the size in bytes.")
4959d3
     config = property(_get_config,
4959d3
             doc="Get the TCMU config.")
4959d3
     alua_supported = property(_get_alua_supported,
4959d3
-            doc="ALUA cannot be setup with rtslib, so False is returned.");
4959d3
+            doc="Returns true if ALUA can be setup. False if not supported.")
4959d3
 
4959d3
     def dump(self):
4959d3
         d = super(UserBackedStorageObject, self).dump()
4959d3
-- 
4959d3
1.8.3.1
4959d3