Skip to content

Commit

Permalink
qcontainer: adds new flag that converts device_add opts to int
Browse files Browse the repository at this point in the history
Devices no longer accept string values in QMP device_add command.
Adds a new flag that casts some of the values to int before
plugging the memory devices.

Signed-off-by: mcasquer <[email protected]>
  • Loading branch information
mcasquer committed Jan 14, 2025
1 parent fc37acd commit 7cad78b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions virttest/qemu_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Flags(object):
TDX_GUEST = _auto_value()
FLOPPY_DEVICE = _auto_value()
BLOCKJOB_BACKING_MASK_PROTOCOL = _auto_value()
DEVICE_OPTS_INT = _auto_value()


class MigrationParams(object):
Expand Down
11 changes: 11 additions & 0 deletions virttest/qemu_devices/qcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class DevContainer(object):
SMP_DRAWERS_VERSION_SCOPE = "[8.2.0, )"
FLOPPY_DEVICE_VERSION_SCOPE = "[5.1.0, )"
BLOCKJOB_BACKING_MASK_PROTOCOL_VERSION_SCOPE = "[9.0.0, )"
DEVICE_OPTS_INT_VERSION_SCOPE = "[9.1.0, )"

MIGRATION_DOWNTIME_LIMTT_VERSION_SCOPE = "[5.1.0, )"
MIGRATION_MAX_BANDWIDTH_VERSION_SCOPE = "[5.1.0, )"
Expand Down Expand Up @@ -451,6 +452,9 @@ def _probe_capabilities(self):
"migrate_set_parameter"
):
self.caps.set_flag(Flags.MIGRATION_PARAMS)
# Some options are no longer accepted as string in device hotplug
if self.__qemu_ver in VersionInterval(self.DEVICE_OPTS_INT_VERSION_SCOPE):
self.caps.set_flag(Flags.DEVICE_OPTS_INT)

def _probe_migration_parameters(self):
"""Probe migration parameters."""
Expand Down Expand Up @@ -3500,6 +3504,8 @@ def dimm_device_define_by_params(self, params, name):
dev = qdevices.Dimm(
params=dimm_params.copy_from_keys(attrs), dimm_type=dimm_type
)
if Flags.DEVICE_OPTS_INT in self.caps and dev.get_param("node"):
dev.set_param("node", int(dev.get_param("node")))
dev.set_param("id", "%s-%s" % ("dimm", name))
for ext_k, ext_v in params.get_dict("dimm_extra_params").items():
dev.set_param(ext_k, ext_v)
Expand Down Expand Up @@ -3564,6 +3570,11 @@ def memory_define_by_params(self, params, name):
parent_bus=virtio_mem_bus,
params=virtio_mem_params,
)
if Flags.DEVICE_OPTS_INT in self.caps:
for option in ["node", "requested-size"]:
value = virtio_mem.get_param(option)
if value:
virtio_mem.set_param(option, int(value))
virtio_mem.set_param("id", "%s-%s" % ("virtio_mem", name))
devices.append(virtio_mem)
else:
Expand Down

0 comments on commit 7cad78b

Please sign in to comment.