Skip to content

Commit

Permalink
avocado-vt: add support for virtio-blk-vhost-user
Browse files Browse the repository at this point in the history
Signed-off-by: Xueqiang Wei <[email protected]>
  • Loading branch information
XueqiangWei committed Oct 28, 2024
1 parent 3a65355 commit cde5414
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 120 deletions.
58 changes: 22 additions & 36 deletions virttest/qemu_devices/qcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ def machine_arm64_mmio(machine_params):
aarch64 (arm64) doesn't support PCI bus, only MMIO transports.
Also it requires pflash for EFI boot.
"""
LOG.warning("Support for aarch64 is highly experimental!")
LOG.warn("Support for aarch64 is highly experimental!")
devices = []
# Add virtio-bus
# TODO: Currently this uses QNoAddrCustomBus and does not
Expand All @@ -1633,7 +1633,7 @@ def machine_arm64_pci(machine_params):
"""
Experimental support for pci-based aarch64
"""
LOG.warning("Support for aarch64 is highly experimental!")
LOG.warn("Support for aarch64 is highly experimental!")
devices = []

bus = (
Expand Down Expand Up @@ -1694,7 +1694,7 @@ def machine_s390_virtio(machine_params):
# set the device's properties. This means that the qemu qtree
# and autotest's representations are completely different and
# can't be used.
LOG.warning("Support for s390x is highly experimental!")
LOG.warn("Support for s390x is highly experimental!")
bus = (
qdevices.QNoAddrCustomBus(
"bus",
Expand All @@ -1716,7 +1716,7 @@ def machine_riscv64_mmio(machine_params):
"""
riscv doesn't support PCI bus, only MMIO transports.
"""
LOG.warning(
LOG.warn(
"Support for riscv64 is highly experimental. See "
"https://avocado-vt.readthedocs.io"
"/en/latest/Experimental.html#riscv64 for "
Expand Down Expand Up @@ -1747,7 +1747,7 @@ def machine_other(machine_params):
isapc or unknown machine type. This type doesn't add any default
buses or devices, only sets the cmdline.
"""
LOG.warning(
LOG.warn(
"Machine type isa/unknown is not supported by "
"avocado-vt. False errors might occur"
)
Expand Down Expand Up @@ -1811,7 +1811,7 @@ def machine_other(machine_params):
elif avocado_machine == "riscv64-mmio":
devices = machine_riscv64_mmio(machine_params)
else:
LOG.warning(
LOG.warn(
"Machine type '%s' is not supported "
"by avocado-vt, errors might occur",
machine_type,
Expand Down Expand Up @@ -2066,7 +2066,6 @@ def images_define_by_variables(
image_discard=None,
image_copy_on_read=None,
image_iothread_vq_mapping=None,
slices_info=None,
):
"""
Creates related devices by variables
Expand Down Expand Up @@ -2114,7 +2113,6 @@ def images_define_by_variables(
:param image_copy_on_read: if support copy-on-read filter
:param image_iothread_vq_mapping: the mapping between iothread
and virt-queues
:param slices_info: Slices information of disk image
"""

def _get_access_tls_creds(image_access):
Expand Down Expand Up @@ -2346,7 +2344,7 @@ def define_hbas(

use_device = self.has_option("device")
if fmt == "scsi": # fmt=scsi force the old version of devices
LOG.warning(
LOG.warn(
"'scsi' drive_format is deprecated, please use the "
"new lsi_scsi type for disk %s",
name,
Expand Down Expand Up @@ -2382,18 +2380,18 @@ def define_hbas(
port = none_or_int(port) # Third level
# Compatibility with old params - scsiid, lun
if scsiid is not None:
LOG.warning(
LOG.warn(
"drive_scsiid param is obsolete, use drive_unit " "instead (disk %s)",
name,
)
unit = none_or_int(scsiid)
if lun is not None:
LOG.warning(
LOG.warn(
"drive_lun param is obsolete, use drive_port instead " "(disk %s)", name
)
port = none_or_int(lun)
if pci_addr is not None and fmt == "virtio":
LOG.warning(
LOG.warn(
"drive_pci_addr is obsolete, use drive_bus instead " "(disk %s)", name
)
bus = none_or_int(pci_addr)
Expand All @@ -2413,7 +2411,7 @@ def define_hbas(
)
):
if not (bus is None and unit is None and port is None):
LOG.warning(
LOG.warn(
"Using scsi interface without -device "
"support; ignoring bus/unit/port. (%s)",
name,
Expand Down Expand Up @@ -2447,7 +2445,7 @@ def define_hbas(
devices.extend(_[0])
elif fmt == "ide":
if bus:
LOG.warning(
LOG.warn(
"ide supports only 1 hba, use drive_unit to set"
"ide.* for disk %s",
name,
Expand Down Expand Up @@ -2492,7 +2490,7 @@ def define_hbas(
devices.extend(_)
elif fmt in ("usb1", "usb2", "usb3"):
if bus:
LOG.warning(
LOG.warn(
"Manual setting of drive_bus is not yet supported"
" for usb disk %s",
name,
Expand Down Expand Up @@ -2547,6 +2545,8 @@ def define_hbas(
protocol_cls = qdevices.QBlockdevProtocolFTP
elif filename.startswith("vdpa:"):
protocol_cls = qdevices.QBlockdevProtocolVirtioBlkVhostVdpa
elif "vhost-user-blk" in filename:
protocol_cls = qdevices.QBlockdevProtocolVirtioBlkVhostUser
elif fmt in ("scsi-generic", "scsi-block"):
protocol_cls = qdevices.QBlockdevProtocolHostDevice
elif blkdebug is not None:
Expand All @@ -2570,7 +2570,6 @@ def define_hbas(

need_format_node = format_cls is not qdevices.QBlockdevFormatRaw
need_format_node |= Flags.BLOCKJOB_BACKING_MASK_PROTOCOL not in self.caps
need_format_node |= slices_info is not None and bool(slices_info.slices)
format_node = None
if need_format_node:
format_node = format_cls(name)
Expand Down Expand Up @@ -2604,7 +2603,7 @@ def define_hbas(
if Flags.BLOCKDEV in self.caps:
for opt, val in zip(("serial", "boot"), (serial, boot)):
if val is not None:
LOG.warning(
LOG.warn(
"The command line option %s is not supported "
"on %s by -blockdev." % (opt, name)
)
Expand All @@ -2616,10 +2615,6 @@ def define_hbas(
protocol_node.set_param("auto-read-only", image_auto_readonly, bool)
protocol_node.set_param("discard", image_discard)

if slices_info is not None and len(slices_info.slices) > 0:
format_node.set_param("offset", slices_info.slices[0].offset)
format_node.set_param("size", slices_info.slices[0].size)

if secret_obj:
if isinstance(format_node, qdevices.QBlockdevFormatQcow2):
format_node.set_param("encrypt.format", image_encryption.format)
Expand Down Expand Up @@ -2656,7 +2651,7 @@ def define_hbas(

if "aio" in self.get_help_text():
if aio == "native" and snapshot == "yes":
LOG.warning("snapshot is on, fallback aio to threads.")
LOG.warn("snapshot is on, fallback aio to threads.")
aio = "threads"
if Flags.BLOCKDEV in self.caps:
if isinstance(
Expand Down Expand Up @@ -2823,7 +2818,7 @@ def define_hbas(
devices[-1].set_param("addr", pci_addr)
devices[-1].parent_bus = (pci_bus,)
if not media == "cdrom":
LOG.warning(
LOG.warn(
"Using -drive fmt=xxx for %s is unsupported "
"method, false errors might occur.",
name,
Expand Down Expand Up @@ -2883,7 +2878,7 @@ def define_hbas(
({"busid": "drive_%s" % name}, {"type": fmt}),
)
else:
LOG.warning("Using default device handling (disk %s)", name)
LOG.warn("Using default device handling (disk %s)", name)
devices[-1].set_param("driver", fmt)
if force_fmt:
LOG.info("Force to use %s for the device" % force_fmt)
Expand Down Expand Up @@ -3043,10 +3038,6 @@ def images_define_by_params(
image_params, data_root, name
)

slices_info = storage.ImageSlicesInfo.slices_info_define_by_params(
name, image_params
)

return self.images_define_by_variables(
name,
image_filename,
Expand Down Expand Up @@ -3093,7 +3084,6 @@ def images_define_by_params(
image_params.get("image_discard"),
image_params.get("image_copy_on_read"),
image_params.get("image_iothread_vq_mapping"),
slices_info,
)

def serials_define_by_variables(
Expand Down Expand Up @@ -3334,7 +3324,7 @@ def cdroms_define_by_params(
scsi_hba = "virtio-scsi-ccw"
if cd_format in (None, "ide"):
if not self.get_buses({"atype": "ide"}):
LOG.warning("cd_format IDE not available, using AHCI instead.")
LOG.warn("cd_format IDE not available, using AHCI instead.")
cd_format = "ahci"
if scsi_hba == "virtio-scsi-pci":
if "mmio" in image_params.get("machine_type"):
Expand Down Expand Up @@ -3613,7 +3603,7 @@ def input_define_by_params(self, params, name, bus=None):
dev.set_param("id", "input_%s" % name)
devices.append(dev)
else:
LOG.warning("'%s' is not supported by your qemu", driver)
LOG.warn("'%s' is not supported by your qemu", driver)

return devices

Expand Down Expand Up @@ -3747,7 +3737,7 @@ def _handle_log(line):
try:
utils_logfile.log_line("%s_swtpm_setup.log" % name, line)
except Exception as e:
LOG.warning("Can't log %s_swtpm_setup output: %s.", name, e)
LOG.warn("Can't log %s_swtpm_setup output: %s.", name, e)

def _emulator_setup(binary, extra_options=None):
setup_cmd = binary
Expand Down Expand Up @@ -3998,10 +3988,6 @@ def _gen_tdx_obj_props(obj_id, params):
raise ValueError("Unsupported tdx-guest object")

backend, tdx_obj_props = "tdx-guest", {"id": obj_id}
tdx_opts = params.get_dict("vm_secure_guest_object_options")
if tdx_opts:
tdx_obj_props.update(tdx_opts)

return backend, tdx_obj_props

obj_props_handlers = {"sev": _gen_sev_obj_props, "tdx": _gen_tdx_obj_props}
Expand Down
49 changes: 14 additions & 35 deletions virttest/qemu_devices/qdevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import re
import shutil
import signal
import subprocess
import time
import traceback
from collections import OrderedDict
Expand Down Expand Up @@ -555,7 +554,7 @@ def set_param(self, option, value, option_type=None):
Ignore addr parameters as they are not supported by old qemus
"""
if option == "addr":
LOG.warning(
LOG.warn(
"Ignoring 'addr=%s' parameter of %s due of old qemu"
", PCI addresses might be messed up.",
value,
Expand Down Expand Up @@ -793,17 +792,13 @@ def _convert_blkdev_args(args):
"""
new_args = dict()
keep_original_type = ("detect-zeroes",)
int_opts = ("offset", "size")
for key, value in six.iteritems(args):
if key not in keep_original_type:
if value in ("on", "yes"):
value = True
elif value in ("off", "no"):
value = False

if key in int_opts:
value = int(value)

parts = key.split(".")
d = new_args
for part in parts[:-1]:
Expand Down Expand Up @@ -982,6 +977,12 @@ class QBlockdevProtocolVirtioBlkVhostVdpa(QBlockdevProtocol):
TYPE = "virtio-blk-vhost-vdpa"


class QBlockdevProtocolVirtioBlkVhostUser(QBlockdevProtocol):
"""New a protocol virtio-blk-vhost-user blockdev node."""

TYPE = "virtio-blk-vhost-user"


class QBlockdevProtocolFile(QBlockdevProtocol):
"""New a protocol file blockdev node."""

Expand Down Expand Up @@ -1259,7 +1260,6 @@ def _cmdline_json(self):
# guest-stats-polling-interval from
# device ("driver": "virtio-balloon-ccw")
# acpi-index from device("driver": "virtio-net-pci")
# aw-bits from device("driver": "intel-iommu")
elif key in (
"physical_block_size",
"logical_block_size",
Expand All @@ -1283,7 +1283,6 @@ def _cmdline_json(self):
"opt_io_size",
"guest-stats-polling-interval",
"acpi-index",
"aw-bits",
):
command_dict[key] = int(val)
# port from usb related driver
Expand Down Expand Up @@ -2141,7 +2140,7 @@ def start_daemon(self):
start_until_timeout = self.get_param("start_until_timeout", 1)

if cmd is None:
LOG.warning("No provided command to start %s daemon.", name)
LOG.warn("No provided command to start %s daemon.", name)
self._daemon_process = None

if self.is_daemon_alive():
Expand Down Expand Up @@ -2258,35 +2257,15 @@ def _handle_log(self, line):
try:
utils_logfile.log_line("%s-%s.log" % (self.get_qid(), name), line)
except Exception as e:
LOG.warning("Can't log %s-%s, output: '%s'.", self.get_qid(), name, e)
LOG.warn("Can't log %s-%s, output: '%s'.", self.get_qid(), name, e)

def start_daemon(self):
"""Start the virtiofs daemon in background."""
virtiofs_binary = self.get_param("binary")
socket_path = self.get_param("sock_path")
source_dir = self.get_param("source")

fsd_cmd = f"{virtiofs_binary} --socket-path={socket_path}"

# Capture the capabilities of virtiofsd
try:
result = subprocess.check_output(
[virtiofs_binary, "--print-capabilities"], universal_newlines=True
)
except subprocess.CalledProcessError as e:
raise DeviceError("virtiofsd failed to report capabilities: %s" % e)

virtiofs_cpblt = json.loads(result)

# Append appropriate parameters based on the virtiofsd capabilities
if (
"features" in virtiofs_cpblt
and "separate-options" in virtiofs_cpblt["features"]
):
fsd_cmd += f" --shared-dir {source_dir}"
else:
fsd_cmd += f" -o source={source_dir}"

fsd_cmd = "%s --socket-path=%s" % (
self.get_param("binary"),
self.get_param("sock_path"),
)
fsd_cmd += " -o source=%s" % self.get_param("source")
if self.get_param("enable_debug_mode") == "on":
fsd_cmd += " -d"
self.set_param("status_active", "Waiting for vhost-user socket connection")
Expand Down
Loading

0 comments on commit cde5414

Please sign in to comment.