2015-01-22 19:09:30 +00:00
|
|
|
# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
"""Generic linux Fibre Channel utilities."""
|
|
|
|
|
2021-04-15 12:04:21 -04:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-06-24 12:44:13 +02:00
|
|
|
import glob
|
2015-07-17 15:25:48 +02:00
|
|
|
import os
|
2022-08-19 11:32:52 -04:00
|
|
|
from typing import Iterable
|
2015-01-22 19:09:30 +00:00
|
|
|
|
|
|
|
from oslo_concurrency import processutils as putils
|
2015-04-13 18:09:29 -04:00
|
|
|
from oslo_log import log as logging
|
2015-01-22 19:09:30 +00:00
|
|
|
|
2015-02-05 23:58:37 +00:00
|
|
|
from os_brick.initiator import linuxscsi
|
2015-01-22 19:09:30 +00:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class LinuxFibreChannel(linuxscsi.LinuxSCSI):
|
2022-06-24 12:44:13 +02:00
|
|
|
FC_HOST_SYSFS_PATH = '/sys/class/fc_host'
|
|
|
|
# Only load the sysfs attributes we care about
|
|
|
|
HBA_ATTRIBUTES = ('port_name', 'node_name', 'port_state')
|
2016-10-05 03:31:03 -07:00
|
|
|
|
Fix: FC partial target scan
When fetching the target value (T in HCTL) for the storage HBAs,
we use the /sys/class/fc_transport path to find available targets.
However, this path only contains targets that already have a LUN
attached from, to the host.
Scenario:
If we have 2 controllers on the backend side with 4 target HBAs each (total 8).
For the first LUN mapping from controller1, we will do a wildcard
scan and find the 4 targets from controller1 which will get
populated in the /fc_transport path.
If we try mapping a LUN from controller2, we try to find targets in the
fc_transport path but the path only contains targets from controller1 so
we will not be able to discover the LUN from controller2 and fail with
NoFibreChannelVolumeDeviceFound exception.
Solution:
In each rescan attempt, we will first search for targets in the
fc_transport path: "/sys/class/fc_transport/target<host>*".
If the target in not found then we will search in the fc_remote_ports
path: "/sys/class/fc_remote_ports/rport-<host>*"
If a [c,t,l] combination is found from either path, we add it to
the list of ctls we later use it for scanning.
This way, we don't alter the current "working" mechanism of scanning
but also add an additional way of discovering targets and improving
the scan to avoid failure scenarios in each rescan attempt.
Closes-Bug: #2051237
Change-Id: Ia74b0fc24e0cf92453e65d15b4a76e565ed04d16
2024-01-25 20:12:55 +05:30
|
|
|
def _get_target_fc_transport_path(self, path, wwpn, lun):
|
|
|
|
"""Scan target in the fc_transport path
|
|
|
|
|
|
|
|
Scan for target in the following path:
|
|
|
|
* /sys/class/fc_transport/target<host>*
|
|
|
|
|
|
|
|
:returns: List with [c, t, l] if the target path exists else
|
|
|
|
empty list
|
|
|
|
"""
|
2025-01-23 02:39:06 +05:30
|
|
|
try:
|
|
|
|
cmd = 'grep -Gil "%(wwpns)s" %(path)s*/port_name' % {'wwpns': wwpn,
|
|
|
|
'path': path}
|
|
|
|
# We need to run command in shell to expand the * glob
|
|
|
|
out, _err = self._execute(cmd, shell=True) # nosec: B604
|
|
|
|
# The grep command will only return 1 path (if found)
|
|
|
|
# associated with the target wwpn used for the search
|
|
|
|
# in the current HBA host
|
|
|
|
out_path = out.split('\n')[0]
|
|
|
|
if out_path.startswith(path):
|
|
|
|
return out_path.split('/')[4].split(':')[1:] + [lun]
|
|
|
|
except Exception as exc:
|
|
|
|
LOG.debug('Could not get HBA channel and SCSI target ID, path:'
|
|
|
|
' %(path)s*, reason: %(reason)s', {'path': path,
|
|
|
|
'reason': exc})
|
Fix: FC partial target scan
When fetching the target value (T in HCTL) for the storage HBAs,
we use the /sys/class/fc_transport path to find available targets.
However, this path only contains targets that already have a LUN
attached from, to the host.
Scenario:
If we have 2 controllers on the backend side with 4 target HBAs each (total 8).
For the first LUN mapping from controller1, we will do a wildcard
scan and find the 4 targets from controller1 which will get
populated in the /fc_transport path.
If we try mapping a LUN from controller2, we try to find targets in the
fc_transport path but the path only contains targets from controller1 so
we will not be able to discover the LUN from controller2 and fail with
NoFibreChannelVolumeDeviceFound exception.
Solution:
In each rescan attempt, we will first search for targets in the
fc_transport path: "/sys/class/fc_transport/target<host>*".
If the target in not found then we will search in the fc_remote_ports
path: "/sys/class/fc_remote_ports/rport-<host>*"
If a [c,t,l] combination is found from either path, we add it to
the list of ctls we later use it for scanning.
This way, we don't alter the current "working" mechanism of scanning
but also add an additional way of discovering targets and improving
the scan to avoid failure scenarios in each rescan attempt.
Closes-Bug: #2051237
Change-Id: Ia74b0fc24e0cf92453e65d15b4a76e565ed04d16
2024-01-25 20:12:55 +05:30
|
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
def _get_target_fc_remote_ports_path(self, path, wwpn, lun):
|
|
|
|
"""Scan target in the fc_remote_ports path
|
|
|
|
|
|
|
|
Scan for target in the following path:
|
|
|
|
* /sys/class/fc_remote_ports/rport-<host>*
|
|
|
|
|
|
|
|
If the path exist, we fetch the target value from the
|
|
|
|
scsi_target_id file.
|
|
|
|
Example: /sys/class/fc_remote_ports/rport-6:0-1/scsi_target_id
|
|
|
|
|
|
|
|
:returns: List with [c, t, l] if the target path exists else
|
|
|
|
empty list
|
|
|
|
"""
|
2025-01-23 02:39:06 +05:30
|
|
|
try:
|
|
|
|
cmd = 'grep -Gil "%(wwpns)s" %(path)s*/port_name' % {'wwpns': wwpn,
|
|
|
|
'path': path}
|
|
|
|
# We need to run command in shell to expand the * glob
|
|
|
|
out, _err = self._execute(cmd, shell=True) # nosec: B604
|
|
|
|
# The scsi_target_id file contains the target ID.
|
|
|
|
# Example path:
|
|
|
|
# /sys/class/fc_remote_ports/rport-2:0-0/scsi_target_id
|
|
|
|
target_path = os.path.dirname(out) + '/scsi_target_id'
|
|
|
|
# There could be a case where the out variable has empty string
|
|
|
|
# and we end up with a path '/scsi_target_id' so check if it
|
|
|
|
# starts with the correct path
|
|
|
|
if target_path.startswith(path):
|
|
|
|
try:
|
|
|
|
scsi_target = '-1'
|
|
|
|
with open(target_path) as scsi_target_file:
|
|
|
|
lines = scsi_target_file.read()
|
|
|
|
scsi_target = lines.split('\n')[0]
|
|
|
|
except OSError:
|
|
|
|
# We were not able to read from the scsi_target_id
|
|
|
|
# file but we can still discover other targets so
|
|
|
|
# continue
|
|
|
|
pass
|
|
|
|
# If the target value is -1, it is not a real target so
|
|
|
|
# skip it
|
|
|
|
if scsi_target != '-1':
|
|
|
|
channel = target_path.split(':')[1].split('-')[0]
|
|
|
|
return [channel, scsi_target, lun]
|
|
|
|
except Exception as exc:
|
|
|
|
LOG.debug('Could not get HBA channel and SCSI target ID, path:'
|
|
|
|
' %(path)s*, reason: %(reason)s', {'path': path,
|
|
|
|
'reason': exc})
|
Fix: FC partial target scan
When fetching the target value (T in HCTL) for the storage HBAs,
we use the /sys/class/fc_transport path to find available targets.
However, this path only contains targets that already have a LUN
attached from, to the host.
Scenario:
If we have 2 controllers on the backend side with 4 target HBAs each (total 8).
For the first LUN mapping from controller1, we will do a wildcard
scan and find the 4 targets from controller1 which will get
populated in the /fc_transport path.
If we try mapping a LUN from controller2, we try to find targets in the
fc_transport path but the path only contains targets from controller1 so
we will not be able to discover the LUN from controller2 and fail with
NoFibreChannelVolumeDeviceFound exception.
Solution:
In each rescan attempt, we will first search for targets in the
fc_transport path: "/sys/class/fc_transport/target<host>*".
If the target in not found then we will search in the fc_remote_ports
path: "/sys/class/fc_remote_ports/rport-<host>*"
If a [c,t,l] combination is found from either path, we add it to
the list of ctls we later use it for scanning.
This way, we don't alter the current "working" mechanism of scanning
but also add an additional way of discovering targets and improving
the scan to avoid failure scenarios in each rescan attempt.
Closes-Bug: #2051237
Change-Id: Ia74b0fc24e0cf92453e65d15b4a76e565ed04d16
2024-01-25 20:12:55 +05:30
|
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
def _get_hba_channel_scsi_target_lun(self,
|
|
|
|
hba,
|
|
|
|
conn_props):
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
"""Get HBA channels, SCSI targets, LUNs to FC targets for given HBA.
|
2016-07-27 14:06:06 +02:00
|
|
|
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
Given an HBA and the connection properties we look for the HBA channels
|
|
|
|
and SCSI targets for each of the FC targets that this HBA has been
|
|
|
|
granted permission to connect.
|
2016-09-28 16:03:54 -04:00
|
|
|
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
For drivers that don't return an initiator to target map we try to find
|
|
|
|
the info for all the target ports.
|
2018-07-16 10:31:52 -07:00
|
|
|
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
For drivers that return an initiator_target_map we use the
|
|
|
|
initiator_target_lun_map entry that was generated by the FC connector
|
|
|
|
based on the contents of the connection information data to know which
|
|
|
|
target ports to look for.
|
|
|
|
|
Fix: FC partial target scan
When fetching the target value (T in HCTL) for the storage HBAs,
we use the /sys/class/fc_transport path to find available targets.
However, this path only contains targets that already have a LUN
attached from, to the host.
Scenario:
If we have 2 controllers on the backend side with 4 target HBAs each (total 8).
For the first LUN mapping from controller1, we will do a wildcard
scan and find the 4 targets from controller1 which will get
populated in the /fc_transport path.
If we try mapping a LUN from controller2, we try to find targets in the
fc_transport path but the path only contains targets from controller1 so
we will not be able to discover the LUN from controller2 and fail with
NoFibreChannelVolumeDeviceFound exception.
Solution:
In each rescan attempt, we will first search for targets in the
fc_transport path: "/sys/class/fc_transport/target<host>*".
If the target in not found then we will search in the fc_remote_ports
path: "/sys/class/fc_remote_ports/rport-<host>*"
If a [c,t,l] combination is found from either path, we add it to
the list of ctls we later use it for scanning.
This way, we don't alter the current "working" mechanism of scanning
but also add an additional way of discovering targets and improving
the scan to avoid failure scenarios in each rescan attempt.
Closes-Bug: #2051237
Change-Id: Ia74b0fc24e0cf92453e65d15b4a76e565ed04d16
2024-01-25 20:12:55 +05:30
|
|
|
We scan for targets in the following two paths:
|
|
|
|
* /sys/class/fc_transport/target<host>*
|
|
|
|
* /sys/class/fc_remote_ports/rport-<host>*
|
|
|
|
|
|
|
|
We search for targets in the fc_transport path first and if not
|
|
|
|
found, we search in the fc_remote_ports path
|
|
|
|
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
:returns: 2-Tuple with the first entry being a list of [c, t, l]
|
|
|
|
entries where the target port was found, and the second entry of the
|
|
|
|
tuple being a set of luns for ports that were not found.
|
2016-07-27 14:06:06 +02:00
|
|
|
"""
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
# We want the targets' WWPNs, so we use the initiator_target_map if
|
|
|
|
# present for this hba or default to targets if not present.
|
2018-07-16 10:31:52 -07:00
|
|
|
targets = conn_props['targets']
|
2018-01-30 06:08:57 -05:00
|
|
|
if conn_props.get('initiator_target_map') is not None:
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
# This map we try to use was generated by the FC connector
|
2018-07-16 10:31:52 -07:00
|
|
|
targets = conn_props['initiator_target_lun_map'].get(
|
|
|
|
hba['port_name'], targets)
|
2017-11-08 21:03:08 +01:00
|
|
|
|
2016-07-27 14:06:06 +02:00
|
|
|
# Leave only the number from the host_device field (ie: host6)
|
|
|
|
host_device = hba['host_device']
|
|
|
|
if host_device and len(host_device) > 4:
|
|
|
|
host_device = host_device[4:]
|
|
|
|
|
|
|
|
path = '/sys/class/fc_transport/target%s:' % host_device
|
Fix: FC partial target scan
When fetching the target value (T in HCTL) for the storage HBAs,
we use the /sys/class/fc_transport path to find available targets.
However, this path only contains targets that already have a LUN
attached from, to the host.
Scenario:
If we have 2 controllers on the backend side with 4 target HBAs each (total 8).
For the first LUN mapping from controller1, we will do a wildcard
scan and find the 4 targets from controller1 which will get
populated in the /fc_transport path.
If we try mapping a LUN from controller2, we try to find targets in the
fc_transport path but the path only contains targets from controller1 so
we will not be able to discover the LUN from controller2 and fail with
NoFibreChannelVolumeDeviceFound exception.
Solution:
In each rescan attempt, we will first search for targets in the
fc_transport path: "/sys/class/fc_transport/target<host>*".
If the target in not found then we will search in the fc_remote_ports
path: "/sys/class/fc_remote_ports/rport-<host>*"
If a [c,t,l] combination is found from either path, we add it to
the list of ctls we later use it for scanning.
This way, we don't alter the current "working" mechanism of scanning
but also add an additional way of discovering targets and improving
the scan to avoid failure scenarios in each rescan attempt.
Closes-Bug: #2051237
Change-Id: Ia74b0fc24e0cf92453e65d15b4a76e565ed04d16
2024-01-25 20:12:55 +05:30
|
|
|
rpath = '/sys/class/fc_remote_ports/rport-%s:' % host_device
|
|
|
|
|
2018-07-16 10:31:52 -07:00
|
|
|
ctls = []
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
luns_not_found = set()
|
2018-07-16 10:31:52 -07:00
|
|
|
for wwpn, lun in targets:
|
2025-01-23 02:39:06 +05:30
|
|
|
# Search for target in the fc_transport path first and if we
|
|
|
|
# don't find ctl, search for target in the fc_remote_ports path
|
|
|
|
ctl = (self._get_target_fc_transport_path(path, wwpn, lun) or
|
|
|
|
self._get_target_fc_remote_ports_path(rpath, wwpn, lun))
|
|
|
|
|
|
|
|
if ctl:
|
|
|
|
ctls.append(ctl)
|
|
|
|
else:
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
# If we didn't find any paths add it to the not found list
|
|
|
|
luns_not_found.add(lun)
|
Fix: FC partial target scan
When fetching the target value (T in HCTL) for the storage HBAs,
we use the /sys/class/fc_transport path to find available targets.
However, this path only contains targets that already have a LUN
attached from, to the host.
Scenario:
If we have 2 controllers on the backend side with 4 target HBAs each (total 8).
For the first LUN mapping from controller1, we will do a wildcard
scan and find the 4 targets from controller1 which will get
populated in the /fc_transport path.
If we try mapping a LUN from controller2, we try to find targets in the
fc_transport path but the path only contains targets from controller1 so
we will not be able to discover the LUN from controller2 and fail with
NoFibreChannelVolumeDeviceFound exception.
Solution:
In each rescan attempt, we will first search for targets in the
fc_transport path: "/sys/class/fc_transport/target<host>*".
If the target in not found then we will search in the fc_remote_ports
path: "/sys/class/fc_remote_ports/rport-<host>*"
If a [c,t,l] combination is found from either path, we add it to
the list of ctls we later use it for scanning.
This way, we don't alter the current "working" mechanism of scanning
but also add an additional way of discovering targets and improving
the scan to avoid failure scenarios in each rescan attempt.
Closes-Bug: #2051237
Change-Id: Ia74b0fc24e0cf92453e65d15b4a76e565ed04d16
2024-01-25 20:12:55 +05:30
|
|
|
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
return ctls, luns_not_found
|
2016-07-27 14:06:06 +02:00
|
|
|
|
2021-04-15 12:04:21 -04:00
|
|
|
def rescan_hosts(self,
|
|
|
|
hbas: Iterable,
|
|
|
|
connection_properties: dict) -> None:
|
2022-09-24 18:48:14 +00:00
|
|
|
LOG.debug('Rescanning HBAs %(hbas)s with connection properties '
|
2018-04-18 12:34:37 +02:00
|
|
|
'%(conn_props)s', {'hbas': hbas,
|
|
|
|
'conn_props': connection_properties})
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
# Use initiator_target_lun_map (generated from initiator_target_map by
|
|
|
|
# the FC connector) as HBA exclusion map
|
2018-07-16 10:31:52 -07:00
|
|
|
ports = connection_properties.get('initiator_target_lun_map')
|
2018-04-18 12:34:37 +02:00
|
|
|
if ports:
|
|
|
|
hbas = [hba for hba in hbas if hba['port_name'] in ports]
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
LOG.debug('Using initiator target map to exclude HBAs: %s',
|
|
|
|
hbas)
|
|
|
|
|
|
|
|
# Most storage arrays get their target ports automatically detected
|
|
|
|
# by the Linux FC initiator and sysfs gets populated with that
|
|
|
|
# information, but there are some that don't. We'll do a narrow scan
|
|
|
|
# using the channel, target, and LUN for the former and a wider scan
|
|
|
|
# for the latter. If all paths to a former type of array were down on
|
|
|
|
# the system boot the array could look like it's of the latter type
|
|
|
|
# and make us bring us unwanted volumes into the system by doing a
|
|
|
|
# broad scan. To prevent this from happening Cinder drivers can use
|
|
|
|
# the "enable_wildcard_scan" key in the connection_info to let us know
|
|
|
|
# they don't want us to do broad scans even in those cases.
|
|
|
|
broad_scan = connection_properties.get('enable_wildcard_scan', True)
|
|
|
|
if not broad_scan:
|
|
|
|
LOG.debug('Connection info disallows broad SCSI scanning')
|
|
|
|
|
|
|
|
process = []
|
|
|
|
skipped = []
|
|
|
|
get_ctls = self._get_hba_channel_scsi_target_lun
|
2019-05-09 17:25:03 +02:00
|
|
|
for hba in hbas:
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
ctls, luns_wildcards = get_ctls(hba, connection_properties)
|
|
|
|
# If we found the target ports, ignore HBAs that din't find them
|
|
|
|
if ctls:
|
|
|
|
process.append((hba, ctls))
|
|
|
|
|
|
|
|
# If target ports not found and should have, then the HBA is not
|
|
|
|
# connected to our storage
|
|
|
|
elif not broad_scan:
|
|
|
|
LOG.debug('Skipping HBA %s, nothing to scan, target port '
|
|
|
|
'not connected to initiator', hba['node_name'])
|
|
|
|
|
|
|
|
# If we haven't found any target ports we may need to do broad
|
|
|
|
# SCSI scans
|
|
|
|
elif not process:
|
|
|
|
skipped.append((hba,
|
|
|
|
[('-', '-', lun) for lun in luns_wildcards]))
|
|
|
|
|
|
|
|
# If we didn't find any target ports use wildcards if they are enabled
|
|
|
|
process = process or skipped
|
2017-11-08 21:03:08 +01:00
|
|
|
|
2023-02-21 19:31:38 +01:00
|
|
|
addressing_mode = connection_properties.get('addressing_mode')
|
|
|
|
|
2018-07-16 10:31:52 -07:00
|
|
|
for hba, ctls in process:
|
|
|
|
for hba_channel, target_id, target_lun in ctls:
|
2023-02-21 19:31:38 +01:00
|
|
|
target_lun = self.lun_for_addressing(target_lun,
|
|
|
|
addressing_mode)
|
Fix FC scan too broad
After some changes to the FC connector we have introduced a regression
on the way we do the scans, and we end up scanning using wildcards even
though we shouldn't.
The targets in the "initiator_target_map" don't mean that they are all
connected, so we must take that into account.
With the current code, if we have the following connections:
HBA host7 ---- SWITCH ---- port W (channel 0, target 2)
\--- SWITCH ---- port X (channel 0, target 3)
HBA host8 ---- SWITCH ---- port Y (channel 0, target 2)
\--- SWITCH ---- port Z (channel 0, target 3)
We will end up with the following scans 8 scans for LUN L:
- - L > host7
- - L > host7
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
- - L > host8
- - L > host8
Which correspond to the responses from _get_hba_channel_scsi_target like
this:
port Y port Z port W port X
host7 ... ['-','-',L] ['-','-',L] ['0','2',L] ['0','3',L]
host8 ... ['0','2',L] ['0','3',L] ['-','-',L] ['-','-',L]
And we should only be doing 4 scans:
0 2 L > host7
0 3 L > host7
0 2 L > host8
0 3 L > host8
Most storage arrays get their target ports automatically detected by the
Linux FC initiator and sysfs gets populated with that information, but
there are some that don't.
We'll do a narrow scan using the channel, target, and LUN for the former
and a wider scan for the latter.
If all paths to a former type of array were down on the system boot the
array could look like it's of the latter type and make us bring us
unwanted volumes into the system by doing a broad scan.
To prevent this from happening Cinder drivers can use the
"enable_wildcard_scan" key in the connection information to let us know
they don't want us to do broad scans even if no target ports are found
(because they know the cause is there's no connection).
Close-Bug: #1849504
Related-Bug: #1765000
Related-Bug: #1828440
Change-Id: I5dbefaff43fb902b15117b443fc92f7b6a6ad8c9
2019-10-14 16:42:22 +02:00
|
|
|
LOG.debug('Scanning %(host)s (wwnn: %(wwnn)s, c: '
|
2016-07-27 14:06:06 +02:00
|
|
|
'%(channel)s, t: %(target)s, l: %(lun)s)',
|
|
|
|
{'host': hba['host_device'],
|
|
|
|
'wwnn': hba['node_name'], 'channel': hba_channel,
|
|
|
|
'target': target_id, 'lun': target_lun})
|
|
|
|
self.echo_scsi_command(
|
|
|
|
"/sys/class/scsi_host/%s/scan" % hba['host_device'],
|
|
|
|
"%(c)s %(t)s %(l)s" % {'c': hba_channel,
|
|
|
|
't': target_id,
|
|
|
|
'l': target_lun})
|
2015-01-22 19:09:30 +00:00
|
|
|
|
2022-06-24 12:44:13 +02:00
|
|
|
@classmethod
|
2021-04-15 12:04:21 -04:00
|
|
|
def get_fc_hbas(cls) -> list[dict[str, str]]:
|
2022-06-24 12:44:13 +02:00
|
|
|
"""Get the Fibre Channel HBA information from sysfs."""
|
2015-01-22 19:09:30 +00:00
|
|
|
hbas = []
|
2022-06-24 12:44:13 +02:00
|
|
|
for hostpath in glob.glob(f'{cls.FC_HOST_SYSFS_PATH}/*'):
|
|
|
|
try:
|
|
|
|
hba = {'ClassDevice': os.path.basename(hostpath),
|
|
|
|
'ClassDevicepath': os.path.realpath(hostpath)}
|
|
|
|
for attribute in cls.HBA_ATTRIBUTES:
|
|
|
|
with open(os.path.join(hostpath, attribute), 'rt') as f:
|
|
|
|
hba[attribute] = f.read().strip()
|
|
|
|
hbas.append(hba)
|
|
|
|
except Exception as exc:
|
2022-08-09 16:08:40 -04:00
|
|
|
LOG.warning('Could not read attributes for %(hp)s: %(exc)s',
|
|
|
|
{'hp': hostpath, 'exc': exc})
|
2015-01-22 19:09:30 +00:00
|
|
|
return hbas
|
|
|
|
|
2022-08-19 11:32:52 -04:00
|
|
|
def get_fc_hbas_info(self) -> list[dict[str, str]]:
|
2015-01-22 19:09:30 +00:00
|
|
|
"""Get Fibre Channel WWNs and device paths from the system, if any."""
|
|
|
|
hbas = self.get_fc_hbas()
|
|
|
|
|
|
|
|
hbas_info = []
|
|
|
|
for hba in hbas:
|
|
|
|
wwpn = hba['port_name'].replace('0x', '')
|
|
|
|
wwnn = hba['node_name'].replace('0x', '')
|
|
|
|
device_path = hba['ClassDevicepath']
|
|
|
|
device = hba['ClassDevice']
|
|
|
|
hbas_info.append({'port_name': wwpn,
|
|
|
|
'node_name': wwnn,
|
|
|
|
'host_device': device,
|
|
|
|
'device_path': device_path})
|
|
|
|
return hbas_info
|
|
|
|
|
2022-08-19 11:32:52 -04:00
|
|
|
def get_fc_wwpns(self) -> list[str]:
|
2015-01-22 19:09:30 +00:00
|
|
|
"""Get Fibre Channel WWPNs from the system, if any."""
|
|
|
|
hbas = self.get_fc_hbas()
|
|
|
|
|
|
|
|
wwpns = []
|
2016-12-01 13:30:38 +01:00
|
|
|
for hba in hbas:
|
|
|
|
if hba['port_state'] == 'Online':
|
|
|
|
wwpn = hba['port_name'].replace('0x', '')
|
|
|
|
wwpns.append(wwpn)
|
2015-01-22 19:09:30 +00:00
|
|
|
|
|
|
|
return wwpns
|
|
|
|
|
2022-08-19 11:32:52 -04:00
|
|
|
def get_fc_wwnns(self) -> list[str]:
|
2015-01-22 19:09:30 +00:00
|
|
|
"""Get Fibre Channel WWNNs from the system, if any."""
|
|
|
|
hbas = self.get_fc_hbas()
|
|
|
|
|
|
|
|
wwnns = []
|
2016-12-01 13:30:38 +01:00
|
|
|
for hba in hbas:
|
|
|
|
if hba['port_state'] == 'Online':
|
|
|
|
wwnn = hba['node_name'].replace('0x', '')
|
|
|
|
wwnns.append(wwnn)
|
2015-01-22 19:09:30 +00:00
|
|
|
|
|
|
|
return wwnns
|
2015-03-09 17:46:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
class LinuxFibreChannelS390X(LinuxFibreChannel):
|
|
|
|
def get_fc_hbas_info(self):
|
|
|
|
"""Get Fibre Channel WWNs and device paths from the system, if any."""
|
|
|
|
|
|
|
|
hbas = self.get_fc_hbas()
|
|
|
|
|
|
|
|
hbas_info = []
|
|
|
|
for hba in hbas:
|
|
|
|
if hba['port_state'] == 'Online':
|
|
|
|
wwpn = hba['port_name'].replace('0x', '')
|
|
|
|
wwnn = hba['node_name'].replace('0x', '')
|
|
|
|
device_path = hba['ClassDevicepath']
|
|
|
|
device = hba['ClassDevice']
|
|
|
|
hbas_info.append({'port_name': wwpn,
|
|
|
|
'node_name': wwnn,
|
|
|
|
'host_device': device,
|
|
|
|
'device_path': device_path})
|
|
|
|
return hbas_info
|
|
|
|
|
|
|
|
def configure_scsi_device(self, device_number, target_wwn, lun):
|
|
|
|
"""Write the LUN to the port's unit_add attribute.
|
|
|
|
|
2015-07-17 15:25:48 +02:00
|
|
|
If auto-discovery of Fibre-Channel target ports is
|
|
|
|
disabled on s390 platforms, ports need to be added to
|
|
|
|
the configuration.
|
2015-03-09 17:46:45 +01:00
|
|
|
If auto-discovery of LUNs is disabled on s390 platforms
|
|
|
|
luns need to be added to the configuration through the
|
|
|
|
unit_add interface
|
|
|
|
"""
|
2015-03-18 05:46:59 -07:00
|
|
|
LOG.debug("Configure lun for s390: device_number=%(device_num)s "
|
|
|
|
"target_wwn=%(target_wwn)s target_lun=%(target_lun)s",
|
2015-03-09 17:46:45 +01:00
|
|
|
{'device_num': device_number,
|
|
|
|
'target_wwn': target_wwn,
|
|
|
|
'target_lun': lun})
|
2015-07-17 15:25:48 +02:00
|
|
|
filepath = ("/sys/bus/ccw/drivers/zfcp/%s/%s" %
|
|
|
|
(device_number, target_wwn))
|
|
|
|
if not (os.path.exists(filepath)):
|
|
|
|
zfcp_device_command = ("/sys/bus/ccw/drivers/zfcp/%s/port_rescan" %
|
|
|
|
(device_number))
|
|
|
|
LOG.debug("port_rescan call for s390: %s", zfcp_device_command)
|
|
|
|
try:
|
|
|
|
self.echo_scsi_command(zfcp_device_command, "1")
|
|
|
|
except putils.ProcessExecutionError as exc:
|
2017-03-21 12:41:51 +08:00
|
|
|
LOG.warning("port_rescan call for s390 failed exit"
|
|
|
|
" %(code)s, stderr %(stderr)s",
|
2015-07-17 15:25:48 +02:00
|
|
|
{'code': exc.exit_code, 'stderr': exc.stderr})
|
|
|
|
|
2015-03-09 17:46:45 +01:00
|
|
|
zfcp_device_command = ("/sys/bus/ccw/drivers/zfcp/%s/%s/unit_add" %
|
|
|
|
(device_number, target_wwn))
|
|
|
|
LOG.debug("unit_add call for s390 execute: %s", zfcp_device_command)
|
|
|
|
try:
|
|
|
|
self.echo_scsi_command(zfcp_device_command, lun)
|
|
|
|
except putils.ProcessExecutionError as exc:
|
2017-03-21 12:41:51 +08:00
|
|
|
LOG.warning("unit_add call for s390 failed exit %(code)s, "
|
|
|
|
"stderr %(stderr)s",
|
2015-03-18 05:46:59 -07:00
|
|
|
{'code': exc.exit_code, 'stderr': exc.stderr})
|
2015-03-09 17:46:45 +01:00
|
|
|
|
|
|
|
def deconfigure_scsi_device(self, device_number, target_wwn, lun):
|
|
|
|
"""Write the LUN to the port's unit_remove attribute.
|
|
|
|
|
|
|
|
If auto-discovery of LUNs is disabled on s390 platforms
|
|
|
|
luns need to be removed from the configuration through the
|
|
|
|
unit_remove interface
|
|
|
|
"""
|
|
|
|
LOG.debug("Deconfigure lun for s390: "
|
2015-03-18 05:46:59 -07:00
|
|
|
"device_number=%(device_num)s "
|
|
|
|
"target_wwn=%(target_wwn)s target_lun=%(target_lun)s",
|
2015-03-09 17:46:45 +01:00
|
|
|
{'device_num': device_number,
|
|
|
|
'target_wwn': target_wwn,
|
|
|
|
'target_lun': lun})
|
|
|
|
zfcp_device_command = ("/sys/bus/ccw/drivers/zfcp/%s/%s/unit_remove" %
|
|
|
|
(device_number, target_wwn))
|
|
|
|
LOG.debug("unit_remove call for s390 execute: %s", zfcp_device_command)
|
|
|
|
try:
|
|
|
|
self.echo_scsi_command(zfcp_device_command, lun)
|
|
|
|
except putils.ProcessExecutionError as exc:
|
2017-03-21 12:41:51 +08:00
|
|
|
LOG.warning("unit_remove call for s390 failed exit %(code)s, "
|
|
|
|
"stderr %(stderr)s",
|
2015-03-18 05:46:59 -07:00
|
|
|
{'code': exc.exit_code, 'stderr': exc.stderr})
|