Skip to content

Commit

Permalink
Option for using qemu internal iscsi driver
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fwiesel committed Apr 25, 2023
1 parent 9aab279 commit a3ba775
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
3 changes: 3 additions & 0 deletions cinder/backup/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
CONF = cfg.CONF
CONF.register_opts(backup_manager_opts)
CONF.import_opt('use_multipath_for_image_xfer', 'cinder.volume.driver')
CONF.import_opt('use_qemu_for_image_xfer', 'cinder.volume.driver')
CONF.import_opt('num_volume_device_scan_tries', 'cinder.volume.driver')
QUOTAS = quota.QUOTAS
MAPPING = {
Expand Down Expand Up @@ -1098,10 +1099,12 @@ def _connect_device(self, conn):
use_multipath = CONF.use_multipath_for_image_xfer
device_scan_attempts = CONF.num_volume_device_scan_tries
protocol = conn['driver_volume_type']
use_qemu = CONF.use_qemu_for_image_xfer
connector = volume_utils.brick_get_connector(
protocol,
use_multipath=use_multipath,
device_scan_attempts=device_scan_attempts,
use_qemu=use_qemu,
conn=conn,
expect_raw_disk=True)
vol_handle = connector.connect_volume(conn['data'])
Expand Down
34 changes: 21 additions & 13 deletions cinder/image/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import os
import re
import tempfile
import time

import cryptography
from cursive import exception as cursive_exception
Expand Down Expand Up @@ -344,19 +345,26 @@ def _convert_image(prefix, source, dest, out_format,

# If there is not enough space on the conversion partition, include
# the partitions's name in the error message.
try:
utils.execute(*cmd, run_as_root=run_as_root)
except processutils.ProcessExecutionError as ex:
if "No space left" in ex.stderr and CONF.image_conversion_dir in dest:
conversion_dir = CONF.image_conversion_dir
while not os.path.ismount(conversion_dir):
conversion_dir = os.path.dirname(conversion_dir)

message = _("Insufficient free space on %(location)s for image "
"conversion.") % {'location': conversion_dir}
LOG.error(message)

raise
max_tries = 3
for attempt in range(max_tries):
try:
utils.execute(*cmd, run_as_root=run_as_root)
except processutils.ProcessExecutionError as ex:
if "Could not create image" in ex.stderr and attempt < max_tries:
LOG.info("Retry %d of %d: %s", attempt, max_tries, ex)
time.sleep(3)
continue

if ("No space left" in ex.stderr
and CONF.image_conversion_dir in dest):
conversion_dir = CONF.image_conversion_dir
while not os.path.ismount(conversion_dir):
conversion_dir = os.path.dirname(conversion_dir)

message = _("Insufficient free space on %(location)s for image"
" conversion.") % {'location': conversion_dir}
LOG.error(message)
raise
duration = timeutils.delta_seconds(start_time, timeutils.utcnow())

# NOTE(jdg): use a default of 1, mostly for unit test, but in
Expand Down
9 changes: 9 additions & 0 deletions cinder/volume/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@
'This parameter needs to be configured for each backend '
'section or in [backend_defaults] section as a common '
'configuration for all backends.'),
cfg.BoolOpt('use_qemu_for_image_xfer',
default=False,
help='If this is set to True, it will try to use qemu\'s '
'internal block driver.'
'This parameter needs to be configured for each backend '
'section or in [backend_defaults] section as a common '
'configuration for all backends.'),
]
fqdn_opts = [
cfg.BoolOpt('unique_fqdn_network',
Expand Down Expand Up @@ -1132,11 +1139,13 @@ def _connect_device(self, conn):
# Use Brick's code to do attach/detach
use_multipath = self.configuration.use_multipath_for_image_xfer
device_scan_attempts = self.configuration.num_volume_device_scan_tries
use_qemu = self.configuration.use_qemu_for_image_xfer
protocol = conn['driver_volume_type']
connector = volume_utils.brick_get_connector(
protocol,
use_multipath=use_multipath,
device_scan_attempts=device_scan_attempts,
use_qemu=use_qemu,
conn=conn)
device = connector.connect_volume(conn['data'])
host_device = device['path']
Expand Down
2 changes: 2 additions & 0 deletions cinder/volume/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2154,11 +2154,13 @@ def accept_transfer(self, context, volume_id, new_user, new_project,
def _connect_device(self, conn: dict) -> dict:
use_multipath = self.configuration.use_multipath_for_image_xfer
device_scan_attempts = self.configuration.num_volume_device_scan_tries
use_qemu = self.configuration.use_qemu_for_image_xfer
protocol = conn['driver_volume_type']
connector = volume_utils.brick_get_connector(
protocol,
use_multipath=use_multipath,
device_scan_attempts=device_scan_attempts,
use_qemu=use_qemu,
conn=conn)
vol_handle = connector.connect_volume(conn['data'])

Expand Down

0 comments on commit a3ba775

Please sign in to comment.