]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
LVM: update iscsi target on volume attach
authorJon Bernard <jobernar@redhat.com>
Thu, 2 Jan 2014 21:28:59 +0000 (16:28 -0500)
committerJon Bernard <jobernar@redhat.com>
Thu, 2 Jan 2014 21:28:59 +0000 (16:28 -0500)
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
cinder/brick/iscsi/iscsi.py
cinder/volume/drivers/lvm.py

index 3d6e014dcddd585dab522c7454b252415f12cde2..b32eb1324b4ae03d93527153ce54a018be70c297 100644 (file)
@@ -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.")
 
index 0aefc2ff80e1a6f2735ce1a96fb6107b131b16f1..aafc532eabf3066f3e0b9814d7369d40a2d27bff 100644 (file)
@@ -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."""
index 668726d216dffcbfc183b88b3bb4007df29e0f5b..7fe2b0e93a9c08beb547152dacffd0ff6e02e8d2 100644 (file)
@@ -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.