Make sure to properly avoid treating partitions the same as disk.
Return None if device path is a partition in convert_scsi_path_to_hctl. In convert_scsi_hctl_to_path ensure that device is not a partition in the most correct and efficient way. Get exactly the set of devices that are descendants of the scsi device and are block devices and have type disk. This should be a singleton, or the empty set. Signed-off-by: mulhern <amulhern@redhat.com>
This commit is contained in:
parent
598af739d2
commit
2393c1fd4f
|
@ -224,22 +224,6 @@ def get_blockdev_type(path):
|
|||
|
||||
get_block_type = get_blockdev_type
|
||||
|
||||
def _hctl_from_dev(device):
|
||||
'''
|
||||
@param device: the device
|
||||
@type device: pyudev.Device
|
||||
@returns: H:C:T:L specifier or None if not found
|
||||
@rtype: list of int * 4 or NoneType
|
||||
'''
|
||||
parent = device.find_parent(subsystem='scsi')
|
||||
if parent is None:
|
||||
return None
|
||||
|
||||
try:
|
||||
return [int(data) for data in parent.sys_name.split(':')]
|
||||
except (ValueError, TypeError):
|
||||
return None
|
||||
|
||||
def convert_scsi_path_to_hctl(path):
|
||||
'''
|
||||
This function returns the SCSI ID in H:C:T:L form for the block
|
||||
|
@ -266,10 +250,22 @@ def convert_scsi_path_to_hctl(path):
|
|||
match is found.
|
||||
'''
|
||||
try:
|
||||
device = pyudev.Device.from_device_file(context, os.path.realpath(path))
|
||||
path = os.path.realpath(path)
|
||||
device = pyudev.Device.from_device_file(_CONTEXT, path)
|
||||
except (pyudev.DeviceNotFoundError, EnvironmentError, ValueError):
|
||||
return None
|
||||
return _hctl_from_dev(device)
|
||||
|
||||
if device.device_type != u'disk':
|
||||
return None
|
||||
|
||||
parent = device.find_parent(subsystem='scsi')
|
||||
if parent is None:
|
||||
return None
|
||||
|
||||
try:
|
||||
return [int(data) for data in parent.sys_name.split(':')]
|
||||
except (ValueError, TypeError):
|
||||
return None
|
||||
|
||||
def convert_scsi_hctl_to_path(host, controller, target, lun):
|
||||
'''
|
||||
|
@ -309,10 +305,13 @@ def convert_scsi_hctl_to_path(host, controller, target, lun):
|
|||
except DeviceNotFoundError:
|
||||
return ''
|
||||
|
||||
for device in context.list_devices(subsystem='block'):
|
||||
if device.parent == scsi_device:
|
||||
return device.device_node
|
||||
return ''
|
||||
devices = _CONTEXT.list_devices(
|
||||
subsystem='block',
|
||||
DEVTYPE='disk',
|
||||
parent=scsi_device
|
||||
)
|
||||
|
||||
return next((dev.device_node for dev in devices), '')
|
||||
|
||||
def generate_wwn(wwn_type):
|
||||
'''
|
||||
|
|
Loading…
Reference in New Issue