diff --git a/provider/backup_utils.py b/provider/backup_utils.py index b548365ed9..97b10577b9 100644 --- a/provider/backup_utils.py +++ b/provider/backup_utils.py @@ -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() @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) diff --git a/provider/blockdev_commit_base.py b/provider/blockdev_commit_base.py index aa4c7f49f8..87745aa2e1 100644 --- a/provider/blockdev_commit_base.py +++ b/provider/blockdev_commit_base.py @@ -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) diff --git a/qemu/tests/blockdev_commit_auto_readonly.py b/qemu/tests/blockdev_commit_auto_readonly.py index 6fa454bc19..545d9d346d 100644 --- a/qemu/tests/blockdev_commit_auto_readonly.py +++ b/qemu/tests/blockdev_commit_auto_readonly.py @@ -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) diff --git a/qemu/tests/blockdev_commit_cor.py b/qemu/tests/blockdev_commit_cor.py index 09147aa90b..ce9b626e9c 100644 --- a/qemu/tests/blockdev_commit_cor.py +++ b/qemu/tests/blockdev_commit_cor.py @@ -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) diff --git a/qemu/tests/blockdev_commit_filter_node_name.py b/qemu/tests/blockdev_commit_filter_node_name.py index 8715ef2af5..1df10507a9 100644 --- a/qemu/tests/blockdev_commit_filter_node_name.py +++ b/qemu/tests/blockdev_commit_filter_node_name.py @@ -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() diff --git a/qemu/tests/blockdev_commit_fio.py b/qemu/tests/blockdev_commit_fio.py index 7f52254ae1..3127dd3fcb 100644 --- a/qemu/tests/blockdev_commit_fio.py +++ b/qemu/tests/blockdev_commit_fio.py @@ -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) diff --git a/qemu/tests/blockdev_commit_firewall.py b/qemu/tests/blockdev_commit_firewall.py index f15b193ae8..0dda114659 100644 --- a/qemu/tests/blockdev_commit_firewall.py +++ b/qemu/tests/blockdev_commit_firewall.py @@ -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) diff --git a/qemu/tests/blockdev_commit_forbidden_actions.py b/qemu/tests/blockdev_commit_forbidden_actions.py index 40e9e7c42a..eb475efe17 100644 --- a/qemu/tests/blockdev_commit_forbidden_actions.py +++ b/qemu/tests/blockdev_commit_forbidden_actions.py @@ -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() diff --git a/qemu/tests/blockdev_commit_general_operation.py b/qemu/tests/blockdev_commit_general_operation.py index c0b67bbbd6..9c1f20569e 100644 --- a/qemu/tests/blockdev_commit_general_operation.py +++ b/qemu/tests/blockdev_commit_general_operation.py @@ -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", diff --git a/qemu/tests/blockdev_commit_hotunplug.py b/qemu/tests/blockdev_commit_hotunplug.py index 12dad7f199..1f7b5ae561 100644 --- a/qemu/tests/blockdev_commit_hotunplug.py +++ b/qemu/tests/blockdev_commit_hotunplug.py @@ -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"]}) diff --git a/qemu/tests/blockdev_commit_non_existed_node.py b/qemu/tests/blockdev_commit_non_existed_node.py index 9a0c9c785a..d5824c4495 100644 --- a/qemu/tests/blockdev_commit_non_existed_node.py +++ b/qemu/tests/blockdev_commit_non_existed_node.py @@ -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: diff --git a/qemu/tests/blockdev_commit_powerdown.py b/qemu/tests/blockdev_commit_powerdown.py index 69aceb3907..31003bc8b3 100644 --- a/qemu/tests/blockdev_commit_powerdown.py +++ b/qemu/tests/blockdev_commit_powerdown.py @@ -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]) diff --git a/qemu/tests/blockdev_commit_query_named_block_nodes.py b/qemu/tests/blockdev_commit_query_named_block_nodes.py index 5c02d26bf9..428460f9b5 100644 --- a/qemu/tests/blockdev_commit_query_named_block_nodes.py +++ b/qemu/tests/blockdev_commit_query_named_block_nodes.py @@ -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") diff --git a/qemu/tests/blockdev_commit_reboot.py b/qemu/tests/blockdev_commit_reboot.py index b37d6545a0..6e4701e1b0 100644 --- a/qemu/tests/blockdev_commit_reboot.py +++ b/qemu/tests/blockdev_commit_reboot.py @@ -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") diff --git a/qemu/tests/blockdev_commit_server_down.py b/qemu/tests/blockdev_commit_server_down.py index e2a61286d8..706b05d7a8 100644 --- a/qemu/tests/blockdev_commit_server_down.py +++ b/qemu/tests/blockdev_commit_server_down.py @@ -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'] diff --git a/qemu/tests/blockdev_commit_specify_node.py b/qemu/tests/blockdev_commit_specify_node.py index 8428db6e6a..b49989efcf 100644 --- a/qemu/tests/blockdev_commit_specify_node.py +++ b/qemu/tests/blockdev_commit_specify_node.py @@ -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: diff --git a/qemu/tests/blockdev_commit_speed_limit.py b/qemu/tests/blockdev_commit_speed_limit.py index a097aed9ec..568312bf72 100644 --- a/qemu/tests/blockdev_commit_speed_limit.py +++ b/qemu/tests/blockdev_commit_speed_limit.py @@ -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]) diff --git a/qemu/tests/blockdev_commit_standby.py b/qemu/tests/blockdev_commit_standby.py index 28aa07dc8c..a353beb995 100644 --- a/qemu/tests/blockdev_commit_standby.py +++ b/qemu/tests/blockdev_commit_standby.py @@ -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) diff --git a/qemu/tests/blockdev_commit_stop_cont.py b/qemu/tests/blockdev_commit_stop_cont.py index d6da526b38..85c5a91019 100644 --- a/qemu/tests/blockdev_commit_stop_cont.py +++ b/qemu/tests/blockdev_commit_stop_cont.py @@ -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) diff --git a/qemu/tests/blockdev_commit_with_ignore.py b/qemu/tests/blockdev_commit_with_ignore.py index c278d559da..571b5bf510 100644 --- a/qemu/tests/blockdev_commit_with_ignore.py +++ b/qemu/tests/blockdev_commit_with_ignore.py @@ -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) diff --git a/qemu/tests/blockdev_commit_with_stop.py b/qemu/tests/blockdev_commit_with_stop.py index 9729ba3fb8..99a5093266 100644 --- a/qemu/tests/blockdev_commit_with_stop.py +++ b/qemu/tests/blockdev_commit_with_stop.py @@ -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) diff --git a/qemu/tests/blockdev_stream_base_itself.py b/qemu/tests/blockdev_stream_base_itself.py index b1f1626952..e95220578d 100644 --- a/qemu/tests/blockdev_stream_base_itself.py +++ b/qemu/tests/blockdev_stream_base_itself.py @@ -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: diff --git a/qemu/tests/blockdev_stream_to_invalid_node.py b/qemu/tests/blockdev_stream_to_invalid_node.py index a24200d45a..1fdb9b093e 100644 --- a/qemu/tests/blockdev_stream_to_invalid_node.py +++ b/qemu/tests/blockdev_stream_to_invalid_node.py @@ -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) diff --git a/qemu/tests/qsd_block_commit.py b/qemu/tests/qsd_block_commit.py index 20da696801..f98fa6445e 100644 --- a/qemu/tests/qsd_block_commit.py +++ b/qemu/tests/qsd_block_commit.py @@ -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)