From a9267644ee09591e2d642d6c1204d94a9fdd8c82 Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Thu, 2 Jan 2014 16:28:59 -0500 Subject: [PATCH] LVM: update iscsi target on volume attach This patch updates the existing iSCSI target for a LVM volume during attach. This is necessary in the event that a user extended the volume after creation so that the correct size is visible to the host. This adds support only for tgtadm. Other changes may be needed for ietadm/lioadm to provide the same functionality. Change-Id: I185a90ffc4d50dd9f91381df07289476fa792043 Closes-Bug: #1248415 --- cinder/brick/exception.py | 4 ++++ cinder/brick/iscsi/iscsi.py | 25 ++++++++++++++++++------- cinder/volume/drivers/lvm.py | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/cinder/brick/exception.py b/cinder/brick/exception.py index 3d6e014dc..b32eb1324 100644 --- a/cinder/brick/exception.py +++ b/cinder/brick/exception.py @@ -105,6 +105,10 @@ class ISCSITargetCreateFailed(BrickException): message = _("Failed to create iscsi target for volume %(volume_id)s.") +class ISCSITargetUpdateFailed(BrickException): + message = _("Failed to update iscsi target for volume %(name)s.") + + class ISCSITargetRemoveFailed(BrickException): message = _("Failed to remove iscsi target for volume %(volume_id)s.") diff --git a/cinder/brick/iscsi/iscsi.py b/cinder/brick/iscsi/iscsi.py index 0aefc2ff8..aafc532ea 100644 --- a/cinder/brick/iscsi/iscsi.py +++ b/cinder/brick/iscsi/iscsi.py @@ -184,13 +184,7 @@ class TgtAdm(TargetAdmin): old_persist_file = os.path.join(volumes_dir, old_name) try: - (out, err) = self._execute('tgt-admin', - '--update', - name, - run_as_root=True) - - LOG.debug("StdOut from tgt-admin --update: %s" % out) - LOG.debug("StdErr from tgt-admin --update: %s" % err) + self.update_iscsi_target(name) # Grab targets list for debug # Consider adding a check for lun 0 and 1 for tgtadm @@ -246,6 +240,20 @@ class TgtAdm(TargetAdmin): return tid + def update_iscsi_target(self, name): + + LOG.info(_('Updating iscsi target: %s') % name) + + try: + (out, err) = self._execute('tgt-admin', '--update', name, + run_as_root=True) + except putils.ProcessExecutionError as e: + LOG.error(_("Failed to update iscsi target %(name)s: %(e)s") % + {'name': name, 'e': str(e)}) + LOG.debug("StdOut from tgt-admin --update: %s" % out) + LOG.debug("StdErr from tgt-admin --update: %s" % err) + raise exception.ISCSITargetUpdateFailed(name=name) + def remove_iscsi_target(self, tid, lun, vol_id, vol_name, **kwargs): LOG.info(_('Removing iscsi_target for: %s') % vol_id) vol_uuid_file = vol_name @@ -434,6 +442,9 @@ class FakeIscsiHelper(object): self.tid += 1 return self.tid + def update_iscsi_target(self, name): + return + class LioAdm(TargetAdmin): """iSCSI target administration for LIO using python-rtslib.""" diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 668726d21..7fe2b0e93 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -744,6 +744,24 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): def _iscsi_authentication(self, chap, name, password): return "%s %s %s" % (chap, name, password) + def initialize_connection(self, volume, connector): + """Initializes the connection and returns connection info. + + This function overrides the base class implementation so that the iSCSI + target can be updated. This is necessary in the event that a user + extended the volume before attachement. + """ + + # update the iSCSI target + iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix, + volume['name']) + self.tgtadm.update_iscsi_target(iscsi_name) + + # continue with the base class behaviour + return driver.ISCSIDriver.initialize_connection(self, + volume, + connector) + class LVMISERDriver(LVMISCSIDriver, driver.ISERDriver): """Executes commands relating to ISER volumes. -- 2.45.2