# HG changeset patch # User Qiang Strony Zhang # Date 1447368851 28800 # Node ID e31e1e575df4e70a073f0f9f3a75b65b5cc9c02f # Parent 132450dbe5f66f9ea47343ecaf3548791896a2a7 22031461 volume attachment failed diff -r 132450dbe5f6 -r e31e1e575df4 components/openstack/cinder/files/cinder.conf --- a/components/openstack/cinder/files/cinder.conf Thu Nov 12 10:15:26 2015 -0800 +++ b/components/openstack/cinder/files/cinder.conf Thu Nov 12 14:54:11 2015 -0800 @@ -2090,9 +2090,11 @@ # Options defined in cinder.volume.drivers.solaris.zfs # -# The base dataset for ZFS cinder volumes. +# The base dataset for ZFS cinder volumes. (string value) #zfs_volume_base=rpool/cinder +# iSCSI target group name. (string value) +#zfs_target_group=tgt-grp # # Options defined in cinder.volume.drivers.solidfire diff -r 132450dbe5f6 -r e31e1e575df4 components/openstack/cinder/files/solaris/solarisiscsi.py --- 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): diff -r 132450dbe5f6 -r e31e1e575df4 components/openstack/cinder/files/solaris/zfs.py --- 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