
This patch refactors iSCSI disconnect code changing the approach to one that just uses `iscsiadm -m session` and sysfs to get all the required information: devices from the connection, multipath system device name, multipath name, the WWN for the block devices... By doing so, not only do we fix a good number of bugs, but we also improve the reliability and speed of the mechanism. A good example of improvements and benefits achieved by this patch are: - Common code for multipath and single path disconnects. - No more querying iSCSI devices for their WWN (page 0x83) removing delays and issue on flaky connections. - All devices are properly cleaned even if they are not part of the multipath. - We wait for device removal and do it in parallel if there are multiple. - Removed usage of `multipath -l` to find devices which is really slow with flaky connections and didn't work when called with a device from a path that is down. - Prevent losing data when detaching, currently if the multipath flush fails for any other reason than "in use" we silently continue with the removal. That is the case when all paths are momentarily down. - Adds a new mechanism for the caller of the disconnect to specify that it's acceptable to lose data and that it's more important to leave a clean system. That is the case if we are creating a volume from an image, since the volume will just be set to error, but we don't want leftovers. Optionally we can tell os-brick to ignore errors and don't raise an exception if the flush fails. - Add a warning when we could be leaving leftovers behind due to disconnect issues. - Action retries (like multipath flush) will now only log the final exception instead of logging all the exceptions. - Flushes of individual paths now use exponential backoff retries instead of random retries between 0.2 and 2 seconds (from oslo library). - We no longer use symlinks from `/dev/disk/by-path`, `/dev/disk/by-id`, or `/dev/mapper` to find devices or multipaths, as they could be leftovers from previous runs. - With high failure rates (above 30%) some CLI calls will enter into a weird state where they wait forever, so we add a timeout mechanism in our `execute` method and add it to those specific calls. Closes-Bug: #1502534 Change-Id: I058ff0a0e5ad517507dc3cda39087c913558561d
132 lines
4.8 KiB
Python
132 lines
4.8 KiB
Python
# Copyright 2016 Cloudbase Solutions Srl
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import collections
|
|
import time
|
|
|
|
from os_win import utilsfactory
|
|
from oslo_log import log as logging
|
|
|
|
from os_brick import exception
|
|
from os_brick.initiator.windows import base as win_conn_base
|
|
from os_brick import utils
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class WindowsFCConnector(win_conn_base.BaseWindowsConnector):
|
|
def __init__(self, *args, **kwargs):
|
|
super(WindowsFCConnector, self).__init__(*args, **kwargs)
|
|
self._fc_utils = utilsfactory.get_fc_utils()
|
|
|
|
@staticmethod
|
|
def get_connector_properties(*args, **kwargs):
|
|
props = {}
|
|
|
|
fc_utils = utilsfactory.get_fc_utils()
|
|
fc_utils.refresh_hba_configuration()
|
|
fc_hba_ports = fc_utils.get_fc_hba_ports()
|
|
|
|
if fc_hba_ports:
|
|
wwnns = []
|
|
wwpns = []
|
|
for port in fc_hba_ports:
|
|
wwnns.append(port['node_name'])
|
|
wwpns.append(port['port_name'])
|
|
props['wwpns'] = wwpns
|
|
props['wwnns'] = list(set(wwnns))
|
|
return props
|
|
|
|
@utils.trace
|
|
def connect_volume(self, connection_properties):
|
|
volume_paths = self.get_volume_paths(connection_properties)
|
|
if not volume_paths:
|
|
raise exception.NoFibreChannelVolumeDeviceFound()
|
|
|
|
device_path = volume_paths[0]
|
|
device_number = self._diskutils.get_device_number_from_device_name(
|
|
device_path)
|
|
scsi_wwn = self._get_scsi_wwn(device_number)
|
|
device_info = {'type': 'block',
|
|
'path': device_path,
|
|
'number': device_number,
|
|
'scsi_wwn': scsi_wwn}
|
|
return device_info
|
|
|
|
@utils.trace
|
|
def get_volume_paths(self, connection_properties):
|
|
# Returns a list containing at most one disk path such as
|
|
# \\.\PhysicalDrive4.
|
|
#
|
|
# If multipath is used and the MPIO service is properly configured
|
|
# to claim the disks, we'll still get a single device path, having
|
|
# the same format, which will be used for all the IO operations.
|
|
disk_paths = set()
|
|
|
|
for attempt in range(self.device_scan_attempts):
|
|
self._diskutils.rescan_disks()
|
|
volume_mappings = self._get_fc_volume_mappings(
|
|
connection_properties)
|
|
LOG.debug("Retrieved volume mappings %(vol_mappings)s "
|
|
"for volume %(conn_props)s",
|
|
dict(vol_mappings=volume_mappings,
|
|
conn_props=connection_properties))
|
|
|
|
# Because of MPIO, we may not be able to get the device name
|
|
# from a specific mapping if the disk was accessed through
|
|
# an other HBA at that moment. In that case, the device name
|
|
# will show up as an empty string.
|
|
for mapping in volume_mappings:
|
|
device_name = mapping['device_name']
|
|
if device_name:
|
|
disk_paths.add(device_name)
|
|
|
|
if disk_paths:
|
|
break
|
|
|
|
time.sleep(self.device_scan_interval)
|
|
|
|
self._check_device_paths(disk_paths)
|
|
return list(disk_paths)
|
|
|
|
def _get_fc_volume_mappings(self, connection_properties):
|
|
# Note(lpetrut): All the WWNs returned by os-win are upper case.
|
|
target_wwpns = [wwpn.upper()
|
|
for wwpn in connection_properties['target_wwn']]
|
|
target_lun = connection_properties['target_lun']
|
|
|
|
volume_mappings = []
|
|
hba_mappings = self._get_fc_hba_mappings()
|
|
for node_name in hba_mappings:
|
|
target_mappings = self._fc_utils.get_fc_target_mappings(node_name)
|
|
for mapping in target_mappings:
|
|
if (mapping['port_name'] in target_wwpns
|
|
and mapping['lun'] == target_lun):
|
|
volume_mappings.append(mapping)
|
|
|
|
return volume_mappings
|
|
|
|
def _get_fc_hba_mappings(self):
|
|
mappings = collections.defaultdict(list)
|
|
fc_hba_ports = self._fc_utils.get_fc_hba_ports()
|
|
for port in fc_hba_ports:
|
|
mappings[port['node_name']].append(port['port_name'])
|
|
return mappings
|
|
|
|
@utils.trace
|
|
def disconnect_volume(self, connection_properties,
|
|
force=False, ignore_errors=False):
|
|
pass
|