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
This commit is contained in:
Joseph Glanville 2013-04-10 16:02:42 -07:00
parent b49f37b8ee
commit 7d5787d299
4 changed files with 80 additions and 3 deletions

View 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):

View 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):

View 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)

View File

@ -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