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