From 22646048cad619f41182c5863aa627602d687981 Mon Sep 17 00:00:00 2001 From: Yihuang Yu Date: Thu, 24 Nov 2022 11:35:54 +0800 Subject: [PATCH] qemu_vm: Fix swtpm path too long for vTPM + ping-pong migration The current workaround is adding "_copied" string into the swtpm path for vTPM migration. When we do ping-pong migration few times, the socket path is longer than system limitation(107), which raises "Path for UnioIO socket is too long". But actually the even times' migration can use the source vTPM socket, so here add an action to roll back the tpm. Signed-off-by: Yihuang Yu --- virttest/qemu_vm.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/virttest/qemu_vm.py b/virttest/qemu_vm.py index 52e583aba5..f62016ec9d 100644 --- a/virttest/qemu_vm.py +++ b/virttest/qemu_vm.py @@ -4463,21 +4463,27 @@ def _set_migrate_capability(vm, capability, value, is_src_vm=True): swtpm_dir = os.path.join(data_dir.get_data_dir(), "swtpm") tpms = clone.params.objects("tpms") tpms_copy = [] - for tpm in tpms: - tpm_name = "%s_%s" % (self.name, tpm) - tpm_path = os.path.join(swtpm_dir, '%s_state' % tpm_name) - tpm_copied_path = os.path.join(swtpm_dir, '%s_copied_state' % - tpm_name) - if os.path.exists(tpm_copied_path): - shutil.rmtree(tpm_copied_path) - shutil.copytree(tpm_path, tpm_copied_path) - tpms_copy.append(tpm + "_copied") - for param in clone.params.copy(): - if param.endswith("_" + tpm): - clone.params[param + "_copied"] = clone.params[param] - del clone.params[param] - clone.params["tpm_overwrite_%s_copied" % tpm] = "no" - clone.params["tpms"] = " ".join(tpms_copy) + _rollback_tpms = clone.params.get("_rollback_tpms") + + if _rollback_tpms: + clone.params["tpms"] = clone.params.pop("_rollback_tpms") + else: + # Backup vTPM resources for ping-pong migration + clone.params["_rollback_tpms"] = clone.params["tpms"] + for tpm in tpms: + tpm_name = "%s_%s" % (self.name, tpm) + tpm_path = os.path.join(swtpm_dir, '%s_state' % tpm_name) + tpm_copied_path = os.path.join(swtpm_dir, '%s_copied_state' % + tpm_name) + if os.path.exists(tpm_copied_path): + shutil.rmtree(tpm_copied_path) + shutil.copytree(tpm_path, tpm_copied_path) + tpms_copy.append(tpm + "_copied") + for param in clone.params.copy(): + if param.endswith("_" + tpm): + clone.params[param + "_copied"] = clone.params[param] + clone.params["tpm_overwrite_%s_copied" % tpm] = "no" + clone.params["tpms"] = " ".join(tpms_copy) try: if (local and not (migration_exec_cmd_src and