diff options
author | Mike Christie <mchristi@redhat.com> | 2017-02-06 17:50:44 -0600 |
---|---|---|
committer | Mike Christie <mchristi@redhat.com> | 2017-02-06 17:55:29 -0600 |
commit | 13dfb1aadbba3d1e2fa64133e9e2392071d58a5a (patch) | |
tree | 9dc9f0d7ef17f441f12531f2f43a4ff52ef7f6ae | |
parent | 6bd910bd5530c9dfd0a768411beacef568b2f7d4 (diff) | |
download | rtslib-fb-13dfb1aadbba3d1e2fa64133e9e2392071d58a5a.tar.gz |
Don't raise exception when getting/setting a LUNs ALUA group
Fix crash due to trying to get/set the ALUA group on
passthrough backends. Instead of raising an exception
return None/-1 on failure.
Signed-off-by: Mike Christie <mchristi@redhat.com>
-rw-r--r-- | rtslib/target.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/rtslib/target.py b/rtslib/target.py index 816be74..d3cdab7 100644 --- a/rtslib/target.py +++ b/rtslib/target.py @@ -582,31 +582,43 @@ class LUN(CFSNode): if os.path.realpath("%s/%s" % (mlun.path, mlun.alias)) == self.path: yield mlun + + # pass through backends will not have setup all the default + # ALUA structs in the kernel. If the kernel has been setup, + # a user created group or default_tg_pt_gp will be returned. + # If the kernel was not properly setup an empty string is + # return in alua_tg_pt_gp. Writing to alua_tg_pt_gp will crash + # older kernels and will return a -Exyz code in newer ones. def _get_alua_tg_pt_gp_name(self): self._check_self() + storage_object = self._get_storage_object() + if storage_object.alua_supported is False: + return None + path = "%s/alua_tg_pt_gp" % self.path - info = fread(path) - if info: + try: + info = fread(path) + if not info: + return None group_line = info.splitlines()[0] return group_line.split(':')[1].strip() - return None + except IOError as e: + return None def _set_alua_tg_pt_gp_name(self, group_name): self._check_self() - path = "%s/alua_tg_pt_gp" % self.path - - info = fread(path) - if not info: - # pass through backends will not have setup the default - # ALUA structs in the kernel. - raise RTSLibError("This LUN does not support setting the ALUA Target Port Group") + if not self._get_alua_tg_pt_gp_name(): + return -1 + path = "%s/alua_tg_pt_gp" % self.path try: fwrite(path, group_name) except IOError as e: - raise RTSLibError("Cannot set ALUA Target Port Group: %s" % e) + return -1 + + return 0 # LUN public stuff |