--- a/components/openstack/cinder/files/solaris/solarisiscsi.py Thu Nov 12 10:15:26 2015 -0800
+++ b/components/openstack/cinder/files/solaris/solarisiscsi.py Thu Nov 12 14:54:11 2015 -0800
@@ -33,18 +33,46 @@
self.execute = putils.execute
def _get_device_path(self, connection_properties):
- """Get the device path from the target info."""
+ """Get the device path from the target info.
+
+ The output of cmd below is like this:
+ Target: iqn.2010-10.org.openstack:hostname1-tgt-grp-target
+ Alias: -
+ TPGT: 1
+ ISID: 4000002a0000
+ Connections: 1
+ LUN: 1
+ Vendor: SUN
+ Product: COMSTAR
+ OS Device Name: /dev/rdsk/c0t600144F0FDFAD05D0000563C04030003d0s2
+ LUN: 0
+ Vendor: SUN
+ Product: COMSTAR
+ OS Device Name: /dev/rdsk/c0t600144F0FDFAD05D0000563C02270002d0s2
+
+ """
(out, _err) = self.execute('/usr/sbin/iscsiadm', 'list',
'target', '-S',
connection_properties['target_iqn'])
+ found = False
for line in [l.strip() for l in out.splitlines()]:
- if line.startswith("OS Device Name:"):
- dev_path = line.split()[-1]
- return dev_path
- else:
- LOG.error(_("No device is found for the target %s.") %
- connection_properties['target_iqn'])
+ if line.startswith("LUN:"):
+ lun = line.split()[-1]
+ if int(lun) == int(connection_properties['target_lun']):
+ found = True
+ continue
+ if found:
+ if line.startswith("OS Device Name:"):
+ dev_path = line.split()[-1]
+ return dev_path
+ elif line.startswith("LUN:"):
+ found = False
+
+ if not found:
+ LOG.error(_("No device is found for the target %s LUN %s.") %
+ (connection_properties['target_iqn'],
+ connection_properties['target_lun']))
raise
def get_initiator(self):
--- a/components/openstack/cinder/files/solaris/zfs.py Thu Nov 12 10:15:26 2015 -0800
+++ b/components/openstack/cinder/files/solaris/zfs.py Thu Nov 12 14:54:11 2015 -0800
@@ -45,7 +45,10 @@
solaris_zfs_opts = [
cfg.StrOpt('zfs_volume_base',
default='rpool/cinder',
- help='The base dataset for ZFS volumes.'), ]
+ help='The base dataset for ZFS volumes.'),
+ cfg.StrOpt('zfs_target_group',
+ default='tgt-grp',
+ help='iSCSI target group name.'), ]
FLAGS.register_opts(solaris_zfs_opts)
@@ -543,6 +546,31 @@
def __init__(self, *args, **kwargs):
super(ZFSISCSIDriver, self).__init__(*args, **kwargs)
+ def do_setup(self, context):
+ """Setup the target and target group."""
+ target_group = self.configuration.zfs_target_group
+ target_name = '%s%s-%s-target' % \
+ (self.configuration.iscsi_target_prefix,
+ self.hostname,
+ target_group)
+
+ if not self._check_tg(target_group):
+ self._stmf_execute('/usr/sbin/stmfadm', 'create-tg', target_group)
+ if self._check_target(target_name, 'iSCSI'):
+ return
+
+ # Create and add the target into the target group
+ self._stmf_execute('/usr/sbin/itadm', 'create-target', '-n',
+ target_name)
+ self._stmf_execute('/usr/sbin/stmfadm', 'offline-target',
+ target_name)
+ self._stmf_execute('/usr/sbin/stmfadm', 'add-tg-member', '-g',
+ target_group, target_name)
+ self._stmf_execute('/usr/sbin/stmfadm', 'online-target',
+ target_name)
+
+ assert self._check_target(target_name, 'iSCSI')
+
def create_export(self, context, volume):
"""Export the volume."""
# If the volume is already exported there is nothing to do, as we
@@ -567,23 +595,10 @@
% volume['name'])
raise exception.VolumeBackendAPIException(data=msg)
- # Create a target group and a target belonging to the target group
- target_group = 'tg-%s' % volume['name']
- self._stmf_execute('/usr/sbin/stmfadm', 'create-tg', target_group)
-
- target_name = '%s%s' % (self.configuration.iscsi_target_prefix,
- volume['name'])
- self._stmf_execute('/usr/sbin/stmfadm', 'add-tg-member', '-g',
- target_group, target_name)
-
- self._stmf_execute('/usr/sbin/itadm', 'create-target', '-n',
- target_name)
- assert self._check_target(target_name, 'iSCSI')
-
- # Add a view entry to the logical unit with the specified LUN, 8776
- if luid is not None:
- self._stmf_execute('/usr/sbin/stmfadm', 'add-view', '-n', '8776',
- '-t', target_group, luid)
+ # Add a view entry to the logical unit
+ target_group = self.configuration.zfs_target_group
+ self._stmf_execute('/usr/sbin/stmfadm', 'add-view',
+ '-t', target_group, luid)
def remove_export(self, context, volume):
"""Remove an export for a volume.
@@ -592,9 +607,6 @@
target, target group, view entry and lu, are deleted.
"""
luid = self._get_luid(volume)
- target_group = 'tg-%s' % volume['name']
- target_name = '%s%s' % (self.configuration.iscsi_target_prefix,
- volume['name'])
# Remove the view entry
if luid is not None:
@@ -603,7 +615,12 @@
self._stmf_execute('/usr/sbin/stmfadm', 'remove-view', '-l',
luid, view_lun['view'])
- # Remove the target and its target group
+ # Remove the target and its target group if they were created by
+ # earlier versions of the volume driver
+ target_group = 'tg-%s' % volume['name']
+ target_name = '%s%s' % (self.configuration.iscsi_target_prefix,
+ volume['name'])
+
if self._check_target(target_name, 'iSCSI'):
self._stmf_execute('/usr/sbin/stmfadm', 'offline-target',
target_name)
@@ -642,6 +659,12 @@
target_name = '%s%s' % (self.configuration.iscsi_target_prefix,
volume['name'])
+ if not self._check_target(target_name, 'iSCSI'):
+ target_name = '%s%s-%s-target' % \
+ (self.configuration.iscsi_target_prefix,
+ self.hostname,
+ self.configuration.zfs_target_group)
+
properties = {}
properties['target_discovered'] = True