]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
iscsi: Add ability to specify or autodetect block vs fileio
authorJoseph Glanville <joseph@cloudscaling.com>
Wed, 10 Apr 2013 23:02:42 +0000 (16:02 -0700)
committerJoseph Glanville <joseph@cloudscaling.com>
Mon, 22 Apr 2013 06:29:54 +0000 (23:29 -0700)
When using block devices to back iSCSI logical units it is
advantageous to use blockio as it decreases latency and
increases throughput, effect is especially pronounced with
faster backing storage devices.

Change-Id: Ia8cba5ddfe140cb5732c2b9ad882831e812a44bc

cinder/tests/test_iscsi.py
cinder/volume/iscsi.py
cinder/volume/utils.py
etc/cinder/cinder.conf.sample

index b5ea8e49f85168fbbcb12b0318b8210f90cb0a96..c20a99f262b6155110dc75e558a5ba5e1a2c524b 100644 (file)
@@ -21,6 +21,7 @@ import tempfile
 
 from cinder import test
 from cinder.volume import iscsi
+from cinder.volume import utils as volume_utils
 
 
 class TargetAdminTestCase(object):
@@ -127,6 +128,55 @@ class IetAdmTestCase(test.TestCase, TargetAdminTestCase):
             'ietadm --op delete --tid=%(tid)s'])
 
 
+class IetAdmBlockIOTestCase(test.TestCase, TargetAdminTestCase):
+
+    def setUp(self):
+        super(IetAdmBlockIOTestCase, self).setUp()
+        TargetAdminTestCase.setUp(self)
+        self.flags(iscsi_helper='ietadm')
+        self.flags(iscsi_iotype='blockio')
+        self.script_template = "\n".join([
+            'ietadm --op new --tid=%(tid)s --params Name=%(target_name)s',
+            'ietadm --op new --tid=%(tid)s --lun=%(lun)s '
+            '--params Path=%(path)s,Type=blockio',
+            'ietadm --op show --tid=%(tid)s',
+            'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
+            'ietadm --op delete --tid=%(tid)s'])
+
+
+class IetAdmFileIOTestCase(test.TestCase, TargetAdminTestCase):
+
+    def setUp(self):
+        super(IetAdmFileIOTestCase, self).setUp()
+        TargetAdminTestCase.setUp(self)
+        self.flags(iscsi_helper='ietadm')
+        self.flags(iscsi_iotype='fileio')
+        self.script_template = "\n".join([
+            'ietadm --op new --tid=%(tid)s --params Name=%(target_name)s',
+            'ietadm --op new --tid=%(tid)s --lun=%(lun)s '
+            '--params Path=%(path)s,Type=fileio',
+            'ietadm --op show --tid=%(tid)s',
+            'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
+            'ietadm --op delete --tid=%(tid)s'])
+
+
+class IetAdmAutoIOTestCase(test.TestCase, TargetAdminTestCase):
+
+    def setUp(self):
+        super(IetAdmAutoIOTestCase, self).setUp()
+        TargetAdminTestCase.setUp(self)
+        self.stubs.Set(volume_utils, 'is_block', lambda _: True)
+        self.flags(iscsi_helper='ietadm')
+        self.flags(iscsi_iotype='auto')
+        self.script_template = "\n".join([
+            'ietadm --op new --tid=%(tid)s --params Name=%(target_name)s',
+            'ietadm --op new --tid=%(tid)s --lun=%(lun)s '
+            '--params Path=%(path)s,Type=blockio',
+            'ietadm --op show --tid=%(tid)s',
+            'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
+            'ietadm --op delete --tid=%(tid)s'])
+
+
 class LioAdmTestCase(test.TestCase, TargetAdminTestCase):
 
     def setUp(self):
index 6fde9d96347390a06d81f2f9ab635930a31b59d8..8fc0ca9e5529ff53efbe3740b4870627417200dc 100644 (file)
@@ -28,6 +28,7 @@ from cinder import exception
 from cinder import flags
 from cinder.openstack.common import log as logging
 from cinder import utils
+from cinder.volume import utils as volume_utils
 
 LOG = logging.getLogger(__name__)
 
@@ -47,6 +48,13 @@ iscsi_helper_opt = [cfg.StrOpt('iscsi_helper',
                                      'allowed to connect to the '
                                      'iSCSI target. (From Nova compute nodes.)'
                                      )
+                               ),
+                    cfg.StrOpt('iscsi_iotype',
+                               default='fileio',
+                               help=('Sets the behavior of the iSCSI target to'
+                                     'either perform blockio or fileio'
+                                     'optionally, auto can be set and Cinder'
+                                     'will autodetect type of backing device')
                                )
                     ]
 
@@ -220,6 +228,12 @@ class IetAdm(TargetAdmin):
     def __init__(self, execute=utils.execute):
         super(IetAdm, self).__init__('ietadm', execute)
 
+    def _iotype(self, path):
+        if FLAGS.iscsi_iotype == 'auto':
+            return 'blockio' if volume_utils.is_block(path) else 'fileio'
+        else:
+            return FLAGS.iscsi_iotype
+
     def create_iscsi_target(self, name, tid, lun, path,
                             chap_auth=None, **kwargs):
         self._new_target(name, tid, **kwargs)
@@ -234,8 +248,8 @@ class IetAdm(TargetAdmin):
                 volume_conf = """
                         Target %s
                             %s
-                            Lun 0 Path=%s,Type=fileio
-                """ % (name, chap_auth, path)
+                            Lun 0 Path=%s,Type=%s
+                """ % (name, chap_auth, path, self._iotype(path))
 
                 with utils.temporary_chown(conf_file):
                     f = open(conf_file, 'a+')
@@ -297,7 +311,7 @@ class IetAdm(TargetAdmin):
         self._run('--op', 'new',
                   '--tid=%s' % tid,
                   '--lun=%d' % lun,
-                  '--params', 'Path=%s,Type=fileio' % path,
+                  '--params', 'Path=%s,Type=%s' % (path, self._iotype(path)),
                   **kwargs)
 
     def _delete_logicalunit(self, tid, lun, **kwargs):
index 43e9e3dbbd87124484f57b7f874c3003f5628028..9ddd309c18d3daa2efa3e82c89cfca427deb63bb 100644 (file)
@@ -16,6 +16,9 @@
 
 """Volume-related Utilities and helpers."""
 
+import os
+import stat
+
 from cinder import flags
 from cinder.openstack.common import log as logging
 from cinder.openstack.common.notifier import api as notifier_api
@@ -121,3 +124,8 @@ def notify_about_snapshot_usage(context, snapshot, event_suffix,
     notifier_api.notify(context, 'snapshot.%s' % host,
                         'snapshot.%s' % event_suffix,
                         notifier_api.INFO, usage_info)
+
+
+def is_block(path):
+    mode = os.stat(path).st_mode
+    return stat.S_ISBLK(mode)
index 2a3ccf2717ec1326fecfba0efbf350d6b9fa953b..36b8e10d4fc3e6f9e29268ee8162c1bc30d96e7a 100644 (file)
 # the iSCSI target. (From Nova compute nodes.) (string value)
 #lio_initiator_iqns=
 
+# The type of IO the iSCSI target will issue to the backend storage.
+# This option only currently works with IET.
+# Valid settings are 'blockio','fileio' and 'auto' which will autodetect
+# the type of file provided to the target. (string value)
+# iscsi_iotype=fileio
 
 #
 # Options defined in cinder.volume.manager