From: Joseph Glanville Date: Wed, 10 Apr 2013 23:02:42 +0000 (-0700) Subject: iscsi: Add ability to specify or autodetect block vs fileio X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7d5787d29919bc61425b0fc457ca8235f2597bea;p=openstack-build%2Fcinder-build.git iscsi: Add ability to specify or autodetect block vs fileio 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 --- diff --git a/cinder/tests/test_iscsi.py b/cinder/tests/test_iscsi.py index b5ea8e49f..c20a99f26 100644 --- a/cinder/tests/test_iscsi.py +++ b/cinder/tests/test_iscsi.py @@ -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): diff --git a/cinder/volume/iscsi.py b/cinder/volume/iscsi.py index 6fde9d963..8fc0ca9e5 100644 --- a/cinder/volume/iscsi.py +++ b/cinder/volume/iscsi.py @@ -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): diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index 43e9e3dbb..9ddd309c1 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -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) diff --git a/etc/cinder/cinder.conf.sample b/etc/cinder/cinder.conf.sample index 2a3ccf271..36b8e10d4 100644 --- a/etc/cinder/cinder.conf.sample +++ b/etc/cinder/cinder.conf.sample @@ -1324,6 +1324,11 @@ # 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