Skip to content

Commit

Permalink
backup_utils: Added backing-mask-protocol support
Browse files Browse the repository at this point in the history
After qemu9.0.0, a new option backing-mask-protocol was added for
the block commit and stream qmp commands. We need to set it true
by default.

Signed-off-by: Zhenchao Liu <[email protected]>
  • Loading branch information
zhencliu committed Aug 7, 2024
1 parent 895daca commit e10a5cd
Show file tree
Hide file tree
Showing 24 changed files with 53 additions and 3 deletions.
33 changes: 30 additions & 3 deletions provider/backup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,35 @@
from virttest import utils_numeric
from virttest import utils_misc
from virttest import utils_disk
from virttest import utils_version

from provider import block_dirty_bitmap as block_bitmap
from provider.virt_storage.storage_admin import sp_admin
from provider import job_utils


BACKING_MASK_PROTOCOL_VERSION_SCOPE = "[9.0.0, )"


def set_default_block_job_options(obj, arguments):
"""
Set the default options only when they are not set by users
"""
options = {
"backing-mask-protocol": (BACKING_MASK_PROTOCOL_VERSION_SCOPE, True),
}

version = None
if hasattr(obj, "devices"):
version = obj.devices.qemu_version
elif hasattr(obj, "qsd_version"):
version = obj.qsd_version

for key, (scope, value) in options.items():
if version in utils_version.VersionInterval(scope):
arguments[key] = arguments.get(key, value)


def generate_log2_value(start, end, step=1, blacklist=None):
if blacklist is None:
blacklist = list()
Expand Down Expand Up @@ -61,7 +84,7 @@ def copy_out_dict_if_exists(params_in, keys):
if key in ["speed", "granularity", "buf-size", "timeout"]:
params_out[key] = int(val)
continue
if key in ["auto-finalize", "auto-dismiss", "unmap", "persistent"]:
if key in ["auto-finalize", "auto-dismiss", "unmap", "persistent", "backing-mask-protocol"]:
if val in ["yes", "true", "on", True]:
params_out[key] = True
continue
Expand Down Expand Up @@ -174,7 +197,9 @@ def block_commit_qmp_cmd(device, **extra_options):
'on-error',
'filter-node-name',
'auto-finalize',
'auto-dismiss']
'auto-dismiss',
'backing-mask-protocol',
]
arguments = copy_out_dict_if_exists(extra_options, options)
arguments["device"] = device
arguments["job-id"] = job_id
Expand All @@ -190,7 +215,7 @@ def blockdev_stream_qmp_cmd(device, **extra_options):
# TODO: we may have to sync the block-stream options with libvirt
options = ["speed", "base", "base-node", "snapshot-file",
"filter-node-name", "on-error", "backing-file",
"auto-dismiss", "auto-finalize"]
"auto-dismiss", "auto-finalize", 'backing-mask-protocol']
args = copy_out_dict_if_exists(extra_options, options)
if args:
arguments.update(args)
Expand Down Expand Up @@ -259,6 +284,7 @@ def blockdev_mirror(vm, source, target, **extra_options):
@fail_on
def block_commit(vm, device, **extra_options):
cmd, arguments = block_commit_qmp_cmd(device, **extra_options)
set_default_block_job_options(vm, arguments)
timeout = int(extra_options.pop("timeout", 600))
vm.monitor.cmd(cmd, arguments)
job_id = arguments.get("job-id", device)
Expand All @@ -269,6 +295,7 @@ def block_commit(vm, device, **extra_options):
def blockdev_stream_nowait(vm, device, **extra_options):
"""Do block-stream and don't wait stream completed, return job id"""
cmd, arguments = blockdev_stream_qmp_cmd(device, **extra_options)
set_default_block_job_options(vm, arguments)
vm.monitor.cmd(cmd, arguments)
return arguments.get("job-id", device)

Expand Down
1 change: 1 addition & 0 deletions provider/blockdev_commit_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def commit_snapshots(self):
else:
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
job_id = args.get("job-id", device)
job_id_list.append(job_id)
self.main_vm.monitor.cmd(cmd, args)
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_auto_readonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
job_id = args.get("job-id", device)
job_utils.wait_until_block_job_completed(self.main_vm, job_id)
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_cor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def commit_snapshots(self):
device = self.get_node_name(device_tag)
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device)
backup_utils.set_default_block_job_options(self.main_vm, args)
job_id = args.get("job-id", device)
self.main_vm.monitor.cmd(cmd, args)
job_utils.wait_until_block_job_completed(self.main_vm, job_id)
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_filter_node_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
job_id = args.get("job-id", device)
block_info = self.main_vm.monitor.info_block()
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_fio.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device)
backup_utils.set_default_block_job_options(self.main_vm, args)
job_id = args.get("job-id", device)
self.main_vm.monitor.cmd(cmd, args)
job_timeout = self.params.get_numeric("commit_job_timeout", 1800)
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def commit_snapshots(self):
arguments["speed"] = self.params["speed"]
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
self.job_id = args.get("job-id", device)

Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_forbidden_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def commit_snapshots(self):
self.forbidden_node = self.get_node_name(self.params["fnode"])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(self.active_node, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
job_id = args.get("job-id", self.active_node)
self.do_forbidden_actions()
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_general_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
job_id = args.get("job-id", device)
self.main_vm.monitor.cmd("block-job-set-speed",
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_hotunplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
self.main_vm.monitor.cmd('device_del',
{'id': self.params["device_tag"]})
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_non_existed_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def commit_snapshots(self):
arguments["top-node"] = self.params["none_existed_top"]
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
try:
self.main_vm.monitor.cmd(cmd, args)
except QMPCmdError as e:
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_powerdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def commit_snapshot_and_destory_vm(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
job_id = args.get("job-id", device)
job_utils.check_block_jobs_started(self.main_vm, [job_id])
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_query_named_block_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
job_id = args.get("job-id", device)
self.main_vm.monitor.cmd("query-named-block-nodes")
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
job_id = args.get("job-id", device)
self.main_vm.reboot(method="system_reset")
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_server_down.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])

cmd, arguments = backup_utils.block_commit_qmp_cmd(device, **args)
backup_utils.set_default_block_job_options(self.main_vm, arguments)
self.main_vm.monitor.cmd(cmd, arguments)
job = job_utils.query_block_jobs(self.main_vm)[0]
self.commit_job = job['device']
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_specify_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
try:
self.main_vm.monitor.cmd(cmd, args)
except QMPCmdError as e:
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_speed_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
job_id = args.get("job-id", device)
job_utils.check_block_jobs_started(self.main_vm, [job_id])
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_standby.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.monitor.cmd(cmd, args)
job_id = args.get("job-id", device)
job_utils.wait_until_job_status_match(self.main_vm, "ready", job_id, timeout=120)
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_stop_cont.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, args)
self.main_vm.pause()
self.main_vm.monitor.cmd(cmd, args)
job_id = args.get("job-id", device)
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_with_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def commit_snapshots(self):
arguments = {}
arguments.update({"on-error": "ignore"})
cmd, arguments = backup_utils.block_commit_qmp_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, arguments)
timeout = self.params.get("job_timeout", 600)
self.main_vm.monitor.cmd(cmd, arguments)
job_id = arguments.get("job-id", device)
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_commit_with_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def commit_snapshots(self):
device = self.get_node_name(snapshot_tags[-1])
arguments = {"on-error": "stop"}
cmd, arguments = backup_utils.block_commit_qmp_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.main_vm, arguments)
timeout = self.params.get("job_timeout", 600)
self.main_vm.monitor.cmd(cmd, arguments)
job_id = arguments.get("job-id", device)
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_stream_base_itself.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def blockdev_stream(self):
device = self.params["base_node"]
get_stream_cmd = backup_utils.blockdev_stream_qmp_cmd
cmd, arguments = get_stream_cmd(device, **self._stream_options)
backup_utils.set_default_block_job_options(self.clone_vm, arguments)
try:
self.clone_vm.monitor.cmd(cmd, arguments)
except QMPCmdError as e:
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/blockdev_stream_to_invalid_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def stream_to_invalid_node(self):
device_node = self.get_node_name(stream_node_tag)
try:
cmd, arguments = backup_utils.blockdev_stream_qmp_cmd(device_node)
backup_utils.set_default_block_job_options(self.main_vm, arguments)
self.main_vm.monitor.cmd(cmd, arguments)
except QMPCmdError as e:
qemu_binary = utils_misc.get_qemu_binary(self.params)
Expand Down
1 change: 1 addition & 0 deletions qemu/tests/qsd_block_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def commit_snapshots(self):
else:
commit_cmd = backup_utils.block_commit_qmp_cmd
cmd, args = commit_cmd(device, **arguments)
backup_utils.set_default_block_job_options(self.qsd, args)
job_id = args.get("job-id", device)
job_id_list.append(job_id)
self.qsd.monitor.cmd(cmd, args)
Expand Down

0 comments on commit e10a5cd

Please sign in to comment.