Peter Pentchev | 9c24be9 | 2022-09-26 22:35:24 +0300 | [diff] [blame^] | 1 | From 6b37214585808aa06af0b1f303966bb22f47dc43 Mon Sep 17 00:00:00 2001 |
| 2 | From: Peter Penchev <openstack-dev@storpool.com> |
| 3 | Date: Mon, 12 Mar 2018 12:00:10 +0200 |
| 4 | Subject: [PATCH] Add iSCSI export support to the StorPool driver |
| 5 | |
| 6 | Add four new driver options: |
| 7 | - iscsi_cinder_volume: use StorPool iSCSI attachments whenever |
| 8 | the cinder-volume service needs to attach a volume to the controller, |
| 9 | e.g. for copying an image to a volume or vice versa |
| 10 | - iscsi_export_to: |
| 11 | - an empty string to use the StorPool native protocol for exporting volumes |
| 12 | protocol for exporting volumes) |
| 13 | - the string "*" to always use iSCSI for exporting volumes |
| 14 | - an experimental, not fully supported list of IQN patterns to export |
| 15 | volumes to using iSCSI; this results in a Cinder driver that exports |
| 16 | different volumes using different storage protocols |
| 17 | - iscsi_portal_group: the name of the iSCSI portal group defined in |
| 18 | the StorPool configuration to use for these export |
| 19 | - iscsi_learn_initiator_iqns: automatically create StorPool configuration |
| 20 | records for an initiator when a volume is first exported to it |
| 21 | |
| 22 | When exporting volumes via iSCSI, report the storage protocol as "iSCSI" and |
| 23 | disable multiattach (the StorPool CI failures with iSCSI multiattach may need |
| 24 | further investigation). |
| 25 | |
| 26 | Change-Id: I9de64306e0e6976268df782053b0651dd1cca96f |
| 27 | --- |
| 28 | .../unit/volume/drivers/test_storpool.py | 64 +++- |
| 29 | cinder/volume/drivers/storpool.py | 360 +++++++++++++++++- |
| 30 | .../drivers/storpool-volume-driver.rst | 49 ++- |
| 31 | 3 files changed, 464 insertions(+), 9 deletions(-) |
| 32 | |
| 33 | diff --git a/cinder/tests/unit/volume/drivers/test_storpool.py b/cinder/tests/unit/volume/drivers/test_storpool.py |
| 34 | index 65d4ed304..350f8c9bd 100644 |
| 35 | --- a/cinder/tests/unit/volume/drivers/test_storpool.py |
| 36 | +++ b/cinder/tests/unit/volume/drivers/test_storpool.py |
| 37 | @@ -32,6 +32,7 @@ fakeStorPool.sptypes = mock.Mock() |
| 38 | sys.modules['storpool'] = fakeStorPool |
| 39 | |
| 40 | |
| 41 | +from cinder.common import constants |
| 42 | from cinder import exception |
| 43 | from cinder.tests.unit import test |
| 44 | from cinder.volume import configuration as conf |
| 45 | @@ -219,7 +220,14 @@ class StorPoolTestCase(test.TestCase): |
| 46 | self.cfg.volume_backend_name = 'storpool_test' |
| 47 | self.cfg.storpool_template = None |
| 48 | self.cfg.storpool_replication = 3 |
| 49 | + self.cfg.iscsi_cinder_volume = False |
| 50 | + self.cfg.iscsi_export_to = '' |
| 51 | + self.cfg.iscsi_portal_group = 'test-group' |
| 52 | |
| 53 | + self._setup_test_driver() |
| 54 | + |
| 55 | + def _setup_test_driver(self): |
| 56 | + """Initialize a StorPool driver as per the current configuration.""" |
| 57 | mock_exec = mock.Mock() |
| 58 | mock_exec.return_value = ('', '') |
| 59 | |
| 60 | @@ -228,7 +236,7 @@ class StorPoolTestCase(test.TestCase): |
| 61 | self.driver.check_for_setup_error() |
| 62 | |
| 63 | @ddt.data( |
| 64 | - (5, TypeError), |
| 65 | + (5, (TypeError, AttributeError)), |
| 66 | ({'no-host': None}, KeyError), |
| 67 | ({'host': 'sbad'}, driver.StorPoolConfigurationInvalid), |
| 68 | ({'host': 's01'}, None), |
| 69 | @@ -244,7 +252,7 @@ class StorPoolTestCase(test.TestCase): |
| 70 | conn) |
| 71 | |
| 72 | @ddt.data( |
| 73 | - (5, TypeError), |
| 74 | + (5, (TypeError, AttributeError)), |
| 75 | ({'no-host': None}, KeyError), |
| 76 | ({'host': 'sbad'}, driver.StorPoolConfigurationInvalid), |
| 77 | ) |
| 78 | @@ -635,3 +643,55 @@ class StorPoolTestCase(test.TestCase): |
| 79 | self.driver.get_pool({ |
| 80 | 'volume_type': volume_type |
| 81 | })) |
| 82 | + |
| 83 | + @ddt.data( |
| 84 | + # The default values |
| 85 | + ('', False, constants.STORPOOL, 'beleriand', False), |
| 86 | + |
| 87 | + # Export to all |
| 88 | + ('*', True, constants.ISCSI, 'beleriand', True), |
| 89 | + ('*', True, constants.ISCSI, 'beleriand', True), |
| 90 | + |
| 91 | + # Only export to the controller |
| 92 | + ('', False, constants.STORPOOL, 'beleriand', False), |
| 93 | + |
| 94 | + # Some of the not-fully-supported pattern lists |
| 95 | + ('roh*', False, constants.STORPOOL, 'beleriand', False), |
| 96 | + ('roh*', False, constants.STORPOOL, 'rohan', True), |
| 97 | + ('*riand roh*', False, constants.STORPOOL, 'beleriand', True), |
| 98 | + ('*riand roh*', False, constants.STORPOOL, 'rohan', True), |
| 99 | + ) |
| 100 | + @ddt.unpack |
| 101 | + def test_wants_iscsi(self, iscsi_export_to, use_iscsi, storage_protocol, |
| 102 | + hostname, expected): |
| 103 | + """Check the "should this export use iSCSI?" detection.""" |
| 104 | + self.cfg.iscsi_export_to = iscsi_export_to |
| 105 | + self._setup_test_driver() |
| 106 | + self.assertEqual(self.driver._use_iscsi, use_iscsi) |
| 107 | + |
| 108 | + # Make sure the driver reports the correct protocol in the stats |
| 109 | + self.driver._update_volume_stats() |
| 110 | + self.assertEqual(self.driver._stats["vendor_name"], "StorPool") |
| 111 | + self.assertEqual(self.driver._stats["storage_protocol"], |
| 112 | + storage_protocol) |
| 113 | + |
| 114 | + def check(conn, forced, expected): |
| 115 | + """Pass partially or completely valid connector info.""" |
| 116 | + for initiator in (None, hostname): |
| 117 | + for host in (None, 'gondor'): |
| 118 | + self.assertEqual( |
| 119 | + self.driver._connector_wants_iscsi({ |
| 120 | + "host": host, |
| 121 | + "initiator": initiator, |
| 122 | + **conn, |
| 123 | + }), |
| 124 | + expected if initiator is not None and host is not None |
| 125 | + else forced) |
| 126 | + |
| 127 | + # If iscsi_cinder_volume is set and this is the controller, then yes. |
| 128 | + check({"storpool_wants_iscsi": True}, True, True) |
| 129 | + |
| 130 | + # If iscsi_cinder_volume is not set or this is not the controller, then |
| 131 | + # look at the specified expected value. |
| 132 | + check({"storpool_wants_iscsi": False}, use_iscsi, expected) |
| 133 | + check({}, use_iscsi, expected) |
| 134 | diff --git a/cinder/volume/drivers/storpool.py b/cinder/volume/drivers/storpool.py |
| 135 | index 418e5750f..abb23865d 100644 |
| 136 | --- a/cinder/volume/drivers/storpool.py |
| 137 | +++ b/cinder/volume/drivers/storpool.py |
| 138 | @@ -15,6 +15,7 @@ |
| 139 | |
| 140 | """StorPool block device driver""" |
| 141 | |
| 142 | +import fnmatch |
| 143 | import platform |
| 144 | |
| 145 | from oslo_config import cfg |
| 146 | @@ -44,6 +45,31 @@ if storpool: |
| 147 | |
| 148 | |
| 149 | storpool_opts = [ |
| 150 | + cfg.BoolOpt('iscsi_cinder_volume', |
| 151 | + default=False, |
| 152 | + help='Let the cinder-volume service use iSCSI instead of ' |
| 153 | + 'the StorPool block device driver for accessing ' |
| 154 | + 'StorPool volumes, e.g. when creating a volume from ' |
| 155 | + 'an image or vice versa.'), |
| 156 | + cfg.StrOpt('iscsi_export_to', |
| 157 | + default='', |
| 158 | + help='Whether to export volumes using iSCSI. ' |
| 159 | + 'An empty string (the default) makes the driver export ' |
| 160 | + 'all volumes using the StorPool native network protocol. ' |
| 161 | + 'The value "*" makes the driver export all volumes using ' |
| 162 | + 'iSCSI. ' |
| 163 | + 'Any other value leads to an experimental not fully ' |
| 164 | + 'supported configuration and is interpreted as ' |
| 165 | + 'a whitespace-separated list of patterns for IQNs for ' |
| 166 | + 'hosts that need volumes to be exported via iSCSI, e.g. ' |
| 167 | + '"iqn.1991-05.com.microsoft:\\*" for Windows hosts.'), |
| 168 | + cfg.BoolOpt('iscsi_learn_initiator_iqns', |
| 169 | + default=True, |
| 170 | + help='Create a StorPool record for a new initiator as soon as ' |
| 171 | + 'Cinder asks for a volume to be exported to it.'), |
| 172 | + cfg.StrOpt('iscsi_portal_group', |
| 173 | + default=None, |
| 174 | + help='The portal group to export volumes via iSCSI in.'), |
| 175 | cfg.StrOpt('storpool_template', |
| 176 | default=None, |
| 177 | help='The StorPool template for volumes with no type.'), |
| 178 | @@ -105,6 +131,7 @@ class StorPoolDriver(driver.VolumeDriver): |
| 179 | self._ourId = None |
| 180 | self._ourIdInt = None |
| 181 | self._attach = None |
| 182 | + self._use_iscsi = None |
| 183 | |
| 184 | @staticmethod |
| 185 | def get_driver_options(): |
| 186 | @@ -162,10 +189,312 @@ class StorPoolDriver(driver.VolumeDriver): |
| 187 | raise StorPoolConfigurationInvalid( |
| 188 | section=hostname, param='SP_OURID', error=e) |
| 189 | |
| 190 | + def _connector_wants_iscsi(self, connector): |
| 191 | + """Should we do this export via iSCSI? |
| 192 | + |
| 193 | + Check the configuration to determine whether this connector is |
| 194 | + expected to provide iSCSI exports as opposed to native StorPool |
| 195 | + protocol ones. Match the initiator's IQN against the list of |
| 196 | + patterns supplied in the "iscsi_export_to" configuration setting. |
| 197 | + """ |
| 198 | + if connector is None: |
| 199 | + return False |
| 200 | + if self._use_iscsi: |
| 201 | + LOG.debug(' - forcing iSCSI for all exported volumes') |
| 202 | + return True |
| 203 | + if connector.get('storpool_wants_iscsi'): |
| 204 | + LOG.debug(' - forcing iSCSI for the controller') |
| 205 | + return True |
| 206 | + |
| 207 | + try: |
| 208 | + iqn = connector.get('initiator') |
| 209 | + except Exception: |
| 210 | + iqn = None |
| 211 | + try: |
| 212 | + host = connector.get('host') |
| 213 | + except Exception: |
| 214 | + host = None |
| 215 | + if iqn is None or host is None: |
| 216 | + LOG.debug(' - this connector certainly does not want iSCSI') |
| 217 | + return False |
| 218 | + |
| 219 | + LOG.debug(' - check whether %(host)s (%(iqn)s) wants iSCSI', |
| 220 | + { |
| 221 | + 'host': host, |
| 222 | + 'iqn': iqn, |
| 223 | + }) |
| 224 | + |
| 225 | + export_to = self.configuration.iscsi_export_to |
| 226 | + if export_to is None: |
| 227 | + return False |
| 228 | + |
| 229 | + for pat in export_to.split(): |
| 230 | + LOG.debug(' - matching against %(pat)s', {'pat': pat}) |
| 231 | + if fnmatch.fnmatch(iqn, pat): |
| 232 | + LOG.debug(' - got it!') |
| 233 | + return True |
| 234 | + LOG.debug(' - nope') |
| 235 | + return False |
| 236 | + |
| 237 | def validate_connector(self, connector): |
| 238 | + if self._connector_wants_iscsi(connector): |
| 239 | + return True |
| 240 | return self._storpool_client_id(connector) >= 0 |
| 241 | |
| 242 | + def _get_iscsi_config(self, iqn, volume_id): |
| 243 | + """Get the StorPool iSCSI config items pertaining to this volume. |
| 244 | + |
| 245 | + Find the elements of the StorPool iSCSI configuration tree that |
| 246 | + will be needed to create, ensure, or remove the iSCSI export of |
| 247 | + the specified volume to the specified initiator. |
| 248 | + """ |
| 249 | + cfg = self._attach.api().iSCSIConfig() |
| 250 | + |
| 251 | + pg_name = self.configuration.iscsi_portal_group |
| 252 | + pg_found = [ |
| 253 | + pg for pg in cfg.iscsi.portalGroups.values() if pg.name == pg_name |
| 254 | + ] |
| 255 | + if not pg_found: |
| 256 | + raise Exception('StorPool Cinder iSCSI configuration error: ' |
| 257 | + 'no portal group "{pg}"'.format(pg=pg_name)) |
| 258 | + pg = pg_found[0] |
| 259 | + |
| 260 | + # Do we know about this initiator? |
| 261 | + i_found = [ |
| 262 | + init for init in cfg.iscsi.initiators.values() if init.name == iqn |
| 263 | + ] |
| 264 | + if i_found: |
| 265 | + initiator = i_found[0] |
| 266 | + else: |
| 267 | + initiator = None |
| 268 | + |
| 269 | + # Is this volume already being exported? |
| 270 | + volname = self._attach.volumeName(volume_id) |
| 271 | + t_found = [ |
| 272 | + tgt for tgt in cfg.iscsi.targets.values() if tgt.volume == volname |
| 273 | + ] |
| 274 | + if t_found: |
| 275 | + target = t_found[0] |
| 276 | + else: |
| 277 | + target = None |
| 278 | + |
| 279 | + # OK, so is this volume being exported to this initiator? |
| 280 | + export = None |
| 281 | + if initiator is not None and target is not None: |
| 282 | + e_found = [ |
| 283 | + exp for exp in initiator.exports |
| 284 | + if exp.portalGroup == pg.name and exp.target == target.name |
| 285 | + ] |
| 286 | + if e_found: |
| 287 | + export = e_found[0] |
| 288 | + |
| 289 | + return { |
| 290 | + 'cfg': cfg, |
| 291 | + 'pg': pg, |
| 292 | + 'initiator': initiator, |
| 293 | + 'target': target, |
| 294 | + 'export': export, |
| 295 | + 'volume_name': volname, |
| 296 | + 'volume_id': volume_id, |
| 297 | + } |
| 298 | + |
| 299 | + def _create_iscsi_export(self, volume, connector): |
| 300 | + """Create (if needed) an iSCSI export for the StorPool volume.""" |
| 301 | + LOG.debug( |
| 302 | + '_create_iscsi_export() invoked for volume ' |
| 303 | + '"%(vol_name)s" (%(vol_id)s) connector %(connector)s', |
| 304 | + { |
| 305 | + 'vol_name': volume['display_name'], |
| 306 | + 'vol_id': volume['id'], |
| 307 | + 'connector': connector, |
| 308 | + } |
| 309 | + ) |
| 310 | + iqn = connector['initiator'] |
| 311 | + try: |
| 312 | + cfg = self._get_iscsi_config(iqn, volume['id']) |
| 313 | + except Exception as exc: |
| 314 | + LOG.error( |
| 315 | + 'Could not fetch the iSCSI config: %(exc)s', {'exc': exc} |
| 316 | + ) |
| 317 | + raise |
| 318 | + |
| 319 | + if cfg['initiator'] is None: |
| 320 | + if not (self.configuration.iscsi_learn_initiator_iqns or |
| 321 | + self.configuration.iscsi_cinder_volume and |
| 322 | + connector.get('storpool_wants_iscsi')): |
| 323 | + raise Exception('The "{iqn}" initiator IQN for the "{host}" ' |
| 324 | + 'host is not defined in the StorPool ' |
| 325 | + 'configuration.' |
| 326 | + .format(iqn=iqn, host=connector['host'])) |
| 327 | + else: |
| 328 | + LOG.info('Creating a StorPool iSCSI initiator ' |
| 329 | + 'for "{host}s" ({iqn}s)', |
| 330 | + {'host': connector['host'], 'iqn': iqn}) |
| 331 | + self._attach.api().iSCSIConfigChange({ |
| 332 | + 'commands': [ |
| 333 | + { |
| 334 | + 'createInitiator': { |
| 335 | + 'name': iqn, |
| 336 | + 'username': '', |
| 337 | + 'secret': '', |
| 338 | + }, |
| 339 | + }, |
| 340 | + { |
| 341 | + 'initiatorAddNetwork': { |
| 342 | + 'initiator': iqn, |
| 343 | + 'net': '0.0.0.0/0', |
| 344 | + }, |
| 345 | + }, |
| 346 | + ] |
| 347 | + }) |
| 348 | + |
| 349 | + if cfg['target'] is None: |
| 350 | + LOG.info( |
| 351 | + 'Creating a StorPool iSCSI target ' |
| 352 | + 'for the "%(vol_name)s" volume (%(vol_id)s)', |
| 353 | + { |
| 354 | + 'vol_name': volume['display_name'], |
| 355 | + 'vol_id': volume['id'], |
| 356 | + } |
| 357 | + ) |
| 358 | + self._attach.api().iSCSIConfigChange({ |
| 359 | + 'commands': [ |
| 360 | + { |
| 361 | + 'createTarget': { |
| 362 | + 'volumeName': cfg['volume_name'], |
| 363 | + }, |
| 364 | + }, |
| 365 | + ] |
| 366 | + }) |
| 367 | + cfg = self._get_iscsi_config(iqn, volume['id']) |
| 368 | + |
| 369 | + if cfg['export'] is None: |
| 370 | + LOG.info('Creating a StorPool iSCSI export ' |
| 371 | + 'for the "{vol_name}s" volume ({vol_id}s) ' |
| 372 | + 'to the "{host}s" initiator ({iqn}s) ' |
| 373 | + 'in the "{pg}s" portal group', |
| 374 | + { |
| 375 | + 'vol_name': volume['display_name'], |
| 376 | + 'vol_id': volume['id'], |
| 377 | + 'host': connector['host'], |
| 378 | + 'iqn': iqn, |
| 379 | + 'pg': cfg['pg'].name |
| 380 | + }) |
| 381 | + self._attach.api().iSCSIConfigChange({ |
| 382 | + 'commands': [ |
| 383 | + { |
| 384 | + 'export': { |
| 385 | + 'initiator': iqn, |
| 386 | + 'portalGroup': cfg['pg'].name, |
| 387 | + 'volumeName': cfg['volume_name'], |
| 388 | + }, |
| 389 | + }, |
| 390 | + ] |
| 391 | + }) |
| 392 | + |
| 393 | + res = { |
| 394 | + 'driver_volume_type': 'iscsi', |
| 395 | + 'data': { |
| 396 | + 'target_discovered': False, |
| 397 | + 'target_iqn': cfg['target'].name, |
| 398 | + 'target_portal': '{}:3260'.format( |
| 399 | + cfg['pg'].networks[0].address |
| 400 | + ), |
| 401 | + 'target_lun': 0, |
| 402 | + 'volume_id': volume['id'], |
| 403 | + 'discard': True, |
| 404 | + }, |
| 405 | + } |
| 406 | + LOG.debug('returning %(res)s', {'res': res}) |
| 407 | + return res |
| 408 | + |
| 409 | + def _remove_iscsi_export(self, volume, connector): |
| 410 | + """Remove an iSCSI export for the specified StorPool volume.""" |
| 411 | + LOG.debug( |
| 412 | + '_remove_iscsi_export() invoked for volume ' |
| 413 | + '"%(vol_name)s" (%(vol_id)s) connector %(conn)s', |
| 414 | + { |
| 415 | + 'vol_name': volume['display_name'], |
| 416 | + 'vol_id': volume['id'], |
| 417 | + 'conn': connector, |
| 418 | + } |
| 419 | + ) |
| 420 | + try: |
| 421 | + cfg = self._get_iscsi_config(connector['initiator'], volume['id']) |
| 422 | + except Exception as exc: |
| 423 | + LOG.error( |
| 424 | + 'Could not fetch the iSCSI config: %(exc)s', {'exc': exc} |
| 425 | + ) |
| 426 | + raise |
| 427 | + |
| 428 | + if cfg['export'] is not None: |
| 429 | + LOG.info('Removing the StorPool iSCSI export ' |
| 430 | + 'for the "%(vol_name)s" volume (%(vol_id)s) ' |
| 431 | + 'to the "%(host)s" initiator (%(iqn)s) ' |
| 432 | + 'in the "%(pg)s" portal group', |
| 433 | + { |
| 434 | + 'vol_name': volume['display_name'], |
| 435 | + 'vol_id': volume['id'], |
| 436 | + 'host': connector['host'], |
| 437 | + 'iqn': connector['initiator'], |
| 438 | + 'pg': cfg['pg'].name, |
| 439 | + }) |
| 440 | + try: |
| 441 | + self._attach.api().iSCSIConfigChange({ |
| 442 | + 'commands': [ |
| 443 | + { |
| 444 | + 'exportDelete': { |
| 445 | + 'initiator': cfg['initiator'].name, |
| 446 | + 'portalGroup': cfg['pg'].name, |
| 447 | + 'volumeName': cfg['volume_name'], |
| 448 | + }, |
| 449 | + }, |
| 450 | + ] |
| 451 | + }) |
| 452 | + except spapi.ApiError as e: |
| 453 | + if e.name not in ('objectExists', 'objectDoesNotExist'): |
| 454 | + raise |
| 455 | + LOG.info('Looks like somebody beat us to it') |
| 456 | + |
| 457 | + if cfg['target'] is not None: |
| 458 | + last = True |
| 459 | + for initiator in cfg['cfg'].iscsi.initiators.values(): |
| 460 | + if initiator.name == cfg['initiator'].name: |
| 461 | + continue |
| 462 | + for exp in initiator.exports: |
| 463 | + if exp.target == cfg['target'].name: |
| 464 | + last = False |
| 465 | + break |
| 466 | + if not last: |
| 467 | + break |
| 468 | + |
| 469 | + if last: |
| 470 | + LOG.info( |
| 471 | + 'Removing the StorPool iSCSI target ' |
| 472 | + 'for the "{vol_name}s" volume ({vol_id}s)', |
| 473 | + { |
| 474 | + 'vol_name': volume['display_name'], |
| 475 | + 'vol_id': volume['id'], |
| 476 | + } |
| 477 | + ) |
| 478 | + try: |
| 479 | + self._attach.api().iSCSIConfigChange({ |
| 480 | + 'commands': [ |
| 481 | + { |
| 482 | + 'deleteTarget': { |
| 483 | + 'volumeName': cfg['volume_name'], |
| 484 | + }, |
| 485 | + }, |
| 486 | + ] |
| 487 | + }) |
| 488 | + except spapi.ApiError as e: |
| 489 | + if e.name not in ('objectDoesNotExist', 'invalidParam'): |
| 490 | + raise |
| 491 | + LOG.info('Looks like somebody beat us to it') |
| 492 | + |
| 493 | def initialize_connection(self, volume, connector): |
| 494 | + if self._connector_wants_iscsi(connector): |
| 495 | + return self._create_iscsi_export(volume, connector) |
| 496 | return {'driver_volume_type': 'storpool', |
| 497 | 'data': { |
| 498 | 'client_id': self._storpool_client_id(connector), |
| 499 | @@ -174,6 +503,9 @@ class StorPoolDriver(driver.VolumeDriver): |
| 500 | }} |
| 501 | |
| 502 | def terminate_connection(self, volume, connector, **kwargs): |
| 503 | + if self._connector_wants_iscsi(connector): |
| 504 | + LOG.debug('- removing an iSCSI export') |
| 505 | + self._remove_iscsi_export(volume, connector) |
| 506 | pass |
| 507 | |
| 508 | def create_snapshot(self, snapshot): |
| 509 | @@ -275,11 +607,20 @@ class StorPoolDriver(driver.VolumeDriver): |
| 510 | ) |
| 511 | |
| 512 | def create_export(self, context, volume, connector): |
| 513 | - pass |
| 514 | + if self._connector_wants_iscsi(connector): |
| 515 | + LOG.debug('- creating an iSCSI export') |
| 516 | + self._create_iscsi_export(volume, connector) |
| 517 | |
| 518 | def remove_export(self, context, volume): |
| 519 | pass |
| 520 | |
| 521 | + def _attach_volume(self, context, volume, properties, remote=False): |
| 522 | + if self.configuration.iscsi_cinder_volume and not remote: |
| 523 | + LOG.debug('- adding the "storpool_wants_iscsi" flag') |
| 524 | + properties['storpool_wants_iscsi'] = True |
| 525 | + |
| 526 | + return super()._attach_volume(context, volume, properties, remote) |
| 527 | + |
| 528 | def delete_volume(self, volume): |
| 529 | name = self._attach.volumeName(volume['id']) |
| 530 | try: |
| 531 | @@ -316,6 +657,17 @@ class StorPoolDriver(driver.VolumeDriver): |
| 532 | LOG.error("StorPoolDriver API initialization failed: %s", e) |
| 533 | raise |
| 534 | |
| 535 | + export_to = self.configuration.iscsi_export_to |
| 536 | + export_to_set = export_to is not None and export_to.split() |
| 537 | + vol_iscsi = self.configuration.iscsi_cinder_volume |
| 538 | + pg_name = self.configuration.iscsi_portal_group |
| 539 | + if (export_to_set or vol_iscsi) and pg_name is None: |
| 540 | + msg = _('The "iscsi_portal_group" option is required if ' |
| 541 | + 'any patterns are listed in "iscsi_export_to"') |
| 542 | + raise exception.VolumeDriverException(message=msg) |
| 543 | + |
| 544 | + self._use_iscsi = export_to == "*" |
| 545 | + |
| 546 | def _update_volume_stats(self): |
| 547 | try: |
| 548 | dl = self._attach.api().disksList() |
| 549 | @@ -341,7 +693,7 @@ class StorPoolDriver(driver.VolumeDriver): |
| 550 | 'total_capacity_gb': total / units.Gi, |
| 551 | 'free_capacity_gb': free / units.Gi, |
| 552 | 'reserved_percentage': 0, |
| 553 | - 'multiattach': True, |
| 554 | + 'multiattach': not self._use_iscsi, |
| 555 | 'QoS_support': False, |
| 556 | 'thick_provisioning_support': False, |
| 557 | 'thin_provisioning_support': True, |
| 558 | @@ -359,7 +711,9 @@ class StorPoolDriver(driver.VolumeDriver): |
| 559 | 'volume_backend_name') or 'storpool', |
| 560 | 'vendor_name': 'StorPool', |
| 561 | 'driver_version': self.VERSION, |
| 562 | - 'storage_protocol': constants.STORPOOL, |
| 563 | + 'storage_protocol': ( |
| 564 | + constants.ISCSI if self._use_iscsi else constants.STORPOOL |
| 565 | + ), |
| 566 | |
| 567 | 'clone_across_pools': True, |
| 568 | 'sparse_copy_volume': True, |
| 569 | diff --git a/doc/source/configuration/block-storage/drivers/storpool-volume-driver.rst b/doc/source/configuration/block-storage/drivers/storpool-volume-driver.rst |
| 570 | index d2c5895a9..c891675bc 100644 |
| 571 | --- a/doc/source/configuration/block-storage/drivers/storpool-volume-driver.rst |
| 572 | +++ b/doc/source/configuration/block-storage/drivers/storpool-volume-driver.rst |
| 573 | @@ -19,12 +19,15 @@ Prerequisites |
| 574 | * The controller and all the compute nodes must have access to the StorPool |
| 575 | API service. |
| 576 | |
| 577 | -* All nodes where StorPool-backed volumes will be attached must have access to |
| 578 | +* If iSCSI is not being used as a transport (see below), all nodes where |
| 579 | + StorPool-backed volumes will be attached must have access to |
| 580 | the StorPool data network and run the ``storpool_block`` service. |
| 581 | |
| 582 | -* If StorPool-backed Cinder volumes need to be created directly from Glance |
| 583 | - images, then the node running the ``cinder-volume`` service must also have |
| 584 | - access to the StorPool data network and run the ``storpool_block`` service. |
| 585 | +* If Glance uses Cinder as its image store, or if StorPool-backed Cinder |
| 586 | + volumes need to be created directly from Glance images, and iSCSI is not |
| 587 | + being used as a transport, then the node running the ``cinder-volume`` |
| 588 | + service must also have access to the StorPool data network and run |
| 589 | + the ``storpool_block`` service. |
| 590 | |
| 591 | * All nodes that need to access the StorPool API (the compute nodes and |
| 592 | the node running the ``cinder-volume`` service) must have the following |
| 593 | @@ -34,6 +37,29 @@ Prerequisites |
| 594 | * the storpool Python bindings package |
| 595 | * the storpool.spopenstack Python helper package |
| 596 | |
| 597 | +Using iSCSI as the transport protocol |
| 598 | +------------------------------------- |
| 599 | + |
| 600 | +The StorPool distributed storage system uses its own, highly optimized and |
| 601 | +tailored for its specifics, network protocol for communication between |
| 602 | +the storage servers and the clients (the OpenStack cluster nodes where |
| 603 | +StorPool-backed volumes will be attached). There are cases when granting |
| 604 | +various nodes access to the StorPool data network or installing and |
| 605 | +running the ``storpool_block`` client service on them may pose difficulties. |
| 606 | +The StorPool servers may also expose the user-created volumes and snapshots |
| 607 | +using the standard iSCSI protocol that only requires TCP routing and |
| 608 | +connectivity between the storage servers and the StorPool clients. |
| 609 | +The StorPool Cinder driver may be configured to export volumes and |
| 610 | +snapshots via iSCSI using the ``iscsi_export_to`` and ``iscsi_portal_group`` |
| 611 | +configuration options. |
| 612 | + |
| 613 | +Additionally, even if e.g. the hypervisor nodes running Nova will use |
| 614 | +the StorPool network protocol and run the ``storpool_block`` service |
| 615 | +(so the ``iscsi_export_to`` option has its default empty string value), |
| 616 | +the ``iscsi_cinder_volume`` option configures the StorPool Cinder driver |
| 617 | +so that only the ``cinder-volume`` service will use the iSCSI protocol when |
| 618 | +attaching volumes and snapshots to transfer data to and from Glance images. |
| 619 | + |
| 620 | Configuring the StorPool volume driver |
| 621 | -------------------------------------- |
| 622 | |
| 623 | @@ -55,6 +81,21 @@ volume backend definition) and per volume type: |
| 624 | with the default placement constraints for the StorPool cluster. |
| 625 | The default value for the chain replication is 3. |
| 626 | |
| 627 | +- ``iscsi_export_to``: if set to the value ``*``, the StorPool Cinder driver |
| 628 | + will export volumes and snapshots using the iSCSI protocol instead of |
| 629 | + the StorPool network protocol. The ``iscsi_portal_group`` option must also |
| 630 | + be specified. |
| 631 | + |
| 632 | +- ``iscsi_portal_group``: if the ``iscsi_export_to`` option is set to |
| 633 | + the value ``*`` or the ``iscsi_cinder_volume`` option is turned on, |
| 634 | + this option specifies the name of the iSCSI portal group that Cinder |
| 635 | + volumes will be exported to. |
| 636 | + |
| 637 | +- ``iscsi_cinder_volume``: if enabled, even if the ``iscsi_export_to`` option |
| 638 | + has its default empty value, the ``cinder-volume`` service will use iSCSI |
| 639 | + to attach the volumes and snapshots for transferring data to and from |
| 640 | + Glance images. |
| 641 | + |
| 642 | Using the StorPool volume driver |
| 643 | -------------------------------- |
| 644 | |
| 645 | -- |
| 646 | 2.35.1 |
| 647 | |