Skip to content

Commit

Permalink
Remove old workaround for resolving enclosures (#18)
Browse files Browse the repository at this point in the history
A workaround to resolve same enclosures was added to support old
broken kernels (e.g. 3.10.0-327.36.3.el7). That workaround is not
needed and actually doesn't work with some virtual enclosure.
This patch removes the workaround from sas_devices and udev alias
scripts.

Closes #18
  • Loading branch information
thiell committed Nov 15, 2022
1 parent 390f971 commit 1569b8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 90 deletions.
28 changes: 0 additions & 28 deletions sasutils/cli/sas_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,7 @@ def _print_lu_devlist(self, lu, devlist, maxpaths=None):
print(self.FMT_DEVLIST_VERB.format(**info))

def print_end_devices(self, sysfsnode):

# NOTE: Unfortunately, we cannot always rely on sysfs block device
# 'enclosure_device' symlink to the array device (at least not on
# 3.10.0-327.36.3.el7). We have to do the enclosure lookup ourselves
# as a workaround.

# Preload enclosure dict (sas_address -> EnclosureDevice)
enclosures = {}
for encl in sysfs.node('class').node('enclosure'):
encldev = EnclosureDevice(encl.node('device'))
enclosures[encldev.attrs.sas_address] = encldev

# This code is ugly and should be rewritten...

devmap = {} # LU -> list of (SASEndDevice, SCSIDevice)

for node in sysfsnode:
Expand Down Expand Up @@ -187,13 +174,6 @@ def print_end_devices(self, sysfsnode):
else:
print("Warning: no enclosure symlink set for %s in %s" %
(blk.name, blk.scsi_device.sysfsnode.path))
sasdev = sas_ed.sas_device
try:
encs.add(enclosures[sasdev.attrs.enclosure_identifier])
except (AttributeError, KeyError):
# not an array device?
print("Warning: %s not an array device (%s)" %
(blk.name, sasdev.sysfsnode.path))
if not encs:
orphans.append((lu, dev_list))
continue
Expand Down Expand Up @@ -246,14 +226,6 @@ def enclosure_finder(arg):
# 'enclosure_device' symlink is present
# (preferred method)
_encl = _blk.array_device.enclosure
else:
# 'enclosure_device' symlink is absent: use workaround
try:
_sasdev = _sas_ed.sas_device
_encl = enclosures[_sasdev.attrs.enclosure_identifier]
except (AttributeError, KeyError):
# not an array device
continue
if _encl in encset:
return True
return False
Expand Down
40 changes: 9 additions & 31 deletions sasutils/cli/sas_mpath_snic_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ def sas_mpath_snic_alias(dmdev):
# sanity: check if the bay identifers are the same
# find common snic part and return result

# NOTE: Unfortunately, we cannot always rely on sysfs block device
# 'enclosure_device' symlink to the array device (at least not on
# 3.10.0-327.36.3.el7). We have to do the enclosure lookup ourselves
# as a workaround.

# Preload enclosure dict (sas_address -> EnclosureDevice)
enclosures = {}
for encl in sysfs.node('class').node('enclosure'):
encldev = EnclosureDevice(encl.node('device'))
enclosures[encldev.attrs.sas_address] = encldev

snics = []
bayids = []

Expand All @@ -71,26 +60,15 @@ def sas_mpath_snic_alias(dmdev):
sasdev = blkdev.end_device.sas_device
wwid = '%s_unknown' % dmdev

if blkdev.array_device:
# 'enclosure_device' symlink is present (preferred method)
# Use array_device and enclosure to retrieve the ses sg name
ses_sg = blkdev.array_device.enclosure.scsi_generic.sg_name
try:
# Use the wwid of the enclosure to create enclosure-specifc
# aliases if an enclosure nickname is not set
wwid = blkdev.array_device.enclosure.attrs.wwid
except AttributeError:
pass
else:
# 'enclosure_device' symlink is absent: use workaround (see NOTE)
try:
encl = enclosures[sasdev.attrs.enclosure_identifier]
ses_sg = encl.scsi_generic.sg_name
except KeyError:
# definitively not an array device
logging.warning('%s not an array device (%s)', blkdev.name,
blkdev.sysfsnode.path)
continue
# 'enclosure_device' symlink is present (preferred method)
# Use array_device and enclosure to retrieve the ses sg name
ses_sg = blkdev.array_device.enclosure.scsi_generic.sg_name
try:
# Use the wwid of the enclosure to create enclosure-specifc
# aliases if an enclosure nickname is not set
wwid = blkdev.array_device.enclosure.attrs.wwid
except AttributeError:
pass

# Retrieve bay_identifier from matching sas_device
bayids.append(int(sasdev.attrs.bay_identifier))
Expand Down
40 changes: 9 additions & 31 deletions sasutils/cli/sas_sd_snic_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,43 +40,21 @@
def sas_sd_snic_alias(blkdev):
"""Use sasutils library to get the alias name from the block device."""

# NOTE: Unfortunately, we cannot always rely on sysfs block device
# 'enclosure_device' symlink to the array device (at least not on
# 3.10.0-327.36.3.el7). We have to do the enclosure lookup ourselves
# as a workaround.

# Preload enclosure dict (sas_address -> EnclosureDevice)
enclosures = {}
for encl in sysfs.node('class').node('enclosure'):
encldev = EnclosureDevice(encl.node('device'))
enclosures[encldev.attrs.sas_address] = encldev

# Instantiate SASBlockDevice object from block device sysfs node
# eg. /sys/block/sdx/device
blkdev = SASBlockDevice(sysfs.node('block').node(blkdev).node('device'))
sasdev = blkdev.end_device.sas_device
wwid = '%s_unknown' % blkdev.name

if blkdev.array_device:
# 'enclosure_device' symlink is present (preferred method)
# Use array_device and enclosure to retrieve the ses sg name
ses_sg = blkdev.array_device.enclosure.scsi_generic.sg_name
try:
# Use the wwid of the enclosure to create enclosure-specifc
# aliases if an enclosure nickname is not set
wwid = blkdev.array_device.enclosure.attrs.wwid
except AttributeError:
pass
else:
# 'enclosure_device' symlink is absent: use workaround (see NOTE)
try:
encl = enclosures[sasdev.attrs.enclosure_identifier]
ses_sg = encl.scsi_generic.sg_name
except KeyError:
# not an array device
logging.warning('%s not an array device (%s)', blkdev.name,
blkdev.sysfsnode.path)
raise
# 'enclosure_device' symlink is present (preferred method)
# Use array_device and enclosure to retrieve the ses sg name
ses_sg = blkdev.array_device.enclosure.scsi_generic.sg_name
try:
# Use the wwid of the enclosure to create enclosure-specifc
# aliases if an enclosure nickname is not set
wwid = blkdev.array_device.enclosure.attrs.wwid
except AttributeError:
pass

# Retrieve bay_identifier from matching sas_device
bay = int(sasdev.attrs.bay_identifier)
Expand Down

0 comments on commit 1569b8b

Please sign in to comment.