From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:59561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNRrt-000451-MN for qemu-devel@nongnu.org; Fri, 20 May 2011 11:44:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QNRrr-0000AG-T5 for qemu-devel@nongnu.org; Fri, 20 May 2011 11:44:01 -0400 Received: from e2.ny.us.ibm.com ([32.97.182.142]:39860) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNRrr-0000A6-O4 for qemu-devel@nongnu.org; Fri, 20 May 2011 11:43:59 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by e2.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p4KFO3ji030217 for ; Fri, 20 May 2011 11:24:03 -0400 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p4KFhwPc099548 for ; Fri, 20 May 2011 11:43:58 -0400 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p4K9ggeN013155 for ; Fri, 20 May 2011 03:42:43 -0600 Message-Id: <20110520154305.723060931@linux.vnet.ibm.com> Date: Fri, 20 May 2011 11:42:51 -0400 From: Stefan Berger References: <20110520154240.279198011@linux.vnet.ibm.com> Content-Disposition: inline; filename=qemu_tpm_blkmig.diff Subject: [Qemu-devel] [PATCH V5 11/12] Experimental support for block migrating TPMs state List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: stefanb@linux.vnet.ibm.com, qemu-devel@nongnu.org Cc: anbang.ruan@cs.ox.ac.uk, andreas.niederl@iaik.tugraz.at, serge@hallyn.com This patch adds (experimental) support for block migration. In the case of block migration an empty QCoW2 image must be found on the destination so that early checks on the content and whether it can be decrytped with the provided key have to be skipped. That empty file needs to be created by higher layers (i.e., libvirt). Also, the completion of the block migration has to be delayed until after the TPM has written the last bytes of its state into the block device so that we get the latest state on the target as well. Before the change to savevm.c it could happen that the latest state of the TPM did not make it to the destination host since the TPM was still processing a command and changing its state (written into block storage) but the block migration already had finished. Re-ordering the saving of the live_state to finish after the 'non live_state' seems to get it right. Signed-off-by: Stefan Berger --- hw/tpm_builtin.c | 5 +++++ savevm.c | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) Index: qemu-git/hw/tpm_builtin.c =================================================================== --- qemu-git.orig/hw/tpm_builtin.c +++ qemu-git/hw/tpm_builtin.c @@ -471,6 +471,11 @@ static int tpm_builtin_startup_bs(BlockD if (!tpm_builtin_is_valid_bsdir(dir) || !tpm_builtin_has_valid_content(dir)) { + if (incoming_expected) { + /* during migration with block migration, we may end + up here due to an empty block file */ + return -ENOKEY; + } /* if it's encrypted and has something else than null-content, we assume to have the wrong key */ if (bdrv_is_encrypted(bs)) { Index: qemu-git/savevm.c =================================================================== --- qemu-git.orig/savevm.c +++ qemu-git/savevm.c @@ -1547,17 +1547,6 @@ int qemu_savevm_state_complete(Monitor * cpu_synchronize_all_states(); QTAILQ_FOREACH(se, &savevm_handlers, entry) { - if (se->save_live_state == NULL) - continue; - - /* Section type */ - qemu_put_byte(f, QEMU_VM_SECTION_END); - qemu_put_be32(f, se->section_id); - - se->save_live_state(mon, f, QEMU_VM_SECTION_END, se->opaque); - } - - QTAILQ_FOREACH(se, &savevm_handlers, entry) { int len; if (se->save_state == NULL && se->vmsd == NULL) @@ -1578,6 +1567,17 @@ int qemu_savevm_state_complete(Monitor * vmstate_save(f, se); } + QTAILQ_FOREACH(se, &savevm_handlers, entry) { + if (se->save_live_state == NULL) + continue; + + /* Section type */ + qemu_put_byte(f, QEMU_VM_SECTION_END); + qemu_put_be32(f, se->section_id); + + se->save_live_state(mon, f, QEMU_VM_SECTION_END, se->opaque); + } + qemu_put_byte(f, QEMU_VM_EOF); if (qemu_file_has_error(f))