Skip to content

Commit a3ba775

Browse files
committed
Option for using qemu internal iscsi driver
Qemu has a user-space implementation of iscsi, which can be used instead of the kernel-level one. By relying only on user-space tooling, we need less privileges and can run more easily in containerised environments.
1 parent 9aab279 commit a3ba775

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

cinder/backup/manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
CONF = cfg.CONF
9595
CONF.register_opts(backup_manager_opts)
9696
CONF.import_opt('use_multipath_for_image_xfer', 'cinder.volume.driver')
97+
CONF.import_opt('use_qemu_for_image_xfer', 'cinder.volume.driver')
9798
CONF.import_opt('num_volume_device_scan_tries', 'cinder.volume.driver')
9899
QUOTAS = quota.QUOTAS
99100
MAPPING = {
@@ -1098,10 +1099,12 @@ def _connect_device(self, conn):
10981099
use_multipath = CONF.use_multipath_for_image_xfer
10991100
device_scan_attempts = CONF.num_volume_device_scan_tries
11001101
protocol = conn['driver_volume_type']
1102+
use_qemu = CONF.use_qemu_for_image_xfer
11011103
connector = volume_utils.brick_get_connector(
11021104
protocol,
11031105
use_multipath=use_multipath,
11041106
device_scan_attempts=device_scan_attempts,
1107+
use_qemu=use_qemu,
11051108
conn=conn,
11061109
expect_raw_disk=True)
11071110
vol_handle = connector.connect_volume(conn['data'])

cinder/image/image_utils.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import os
3131
import re
3232
import tempfile
33+
import time
3334

3435
import cryptography
3536
from cursive import exception as cursive_exception
@@ -344,19 +345,26 @@ def _convert_image(prefix, source, dest, out_format,
344345

345346
# If there is not enough space on the conversion partition, include
346347
# the partitions's name in the error message.
347-
try:
348-
utils.execute(*cmd, run_as_root=run_as_root)
349-
except processutils.ProcessExecutionError as ex:
350-
if "No space left" in ex.stderr and CONF.image_conversion_dir in dest:
351-
conversion_dir = CONF.image_conversion_dir
352-
while not os.path.ismount(conversion_dir):
353-
conversion_dir = os.path.dirname(conversion_dir)
354-
355-
message = _("Insufficient free space on %(location)s for image "
356-
"conversion.") % {'location': conversion_dir}
357-
LOG.error(message)
358-
359-
raise
348+
max_tries = 3
349+
for attempt in range(max_tries):
350+
try:
351+
utils.execute(*cmd, run_as_root=run_as_root)
352+
except processutils.ProcessExecutionError as ex:
353+
if "Could not create image" in ex.stderr and attempt < max_tries:
354+
LOG.info("Retry %d of %d: %s", attempt, max_tries, ex)
355+
time.sleep(3)
356+
continue
357+
358+
if ("No space left" in ex.stderr
359+
and CONF.image_conversion_dir in dest):
360+
conversion_dir = CONF.image_conversion_dir
361+
while not os.path.ismount(conversion_dir):
362+
conversion_dir = os.path.dirname(conversion_dir)
363+
364+
message = _("Insufficient free space on %(location)s for image"
365+
" conversion.") % {'location': conversion_dir}
366+
LOG.error(message)
367+
raise
360368
duration = timeutils.delta_seconds(start_time, timeutils.utcnow())
361369

362370
# NOTE(jdg): use a default of 1, mostly for unit test, but in

cinder/volume/driver.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,13 @@
327327
'This parameter needs to be configured for each backend '
328328
'section or in [backend_defaults] section as a common '
329329
'configuration for all backends.'),
330+
cfg.BoolOpt('use_qemu_for_image_xfer',
331+
default=False,
332+
help='If this is set to True, it will try to use qemu\'s '
333+
'internal block driver.'
334+
'This parameter needs to be configured for each backend '
335+
'section or in [backend_defaults] section as a common '
336+
'configuration for all backends.'),
330337
]
331338
fqdn_opts = [
332339
cfg.BoolOpt('unique_fqdn_network',
@@ -1132,11 +1139,13 @@ def _connect_device(self, conn):
11321139
# Use Brick's code to do attach/detach
11331140
use_multipath = self.configuration.use_multipath_for_image_xfer
11341141
device_scan_attempts = self.configuration.num_volume_device_scan_tries
1142+
use_qemu = self.configuration.use_qemu_for_image_xfer
11351143
protocol = conn['driver_volume_type']
11361144
connector = volume_utils.brick_get_connector(
11371145
protocol,
11381146
use_multipath=use_multipath,
11391147
device_scan_attempts=device_scan_attempts,
1148+
use_qemu=use_qemu,
11401149
conn=conn)
11411150
device = connector.connect_volume(conn['data'])
11421151
host_device = device['path']

cinder/volume/manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,11 +2154,13 @@ def accept_transfer(self, context, volume_id, new_user, new_project,
21542154
def _connect_device(self, conn: dict) -> dict:
21552155
use_multipath = self.configuration.use_multipath_for_image_xfer
21562156
device_scan_attempts = self.configuration.num_volume_device_scan_tries
2157+
use_qemu = self.configuration.use_qemu_for_image_xfer
21572158
protocol = conn['driver_volume_type']
21582159
connector = volume_utils.brick_get_connector(
21592160
protocol,
21602161
use_multipath=use_multipath,
21612162
device_scan_attempts=device_scan_attempts,
2163+
use_qemu=use_qemu,
21622164
conn=conn)
21632165
vol_handle = connector.connect_volume(conn['data'])
21642166

0 commit comments

Comments
 (0)