From patchwork Wed Jul 6 16:34:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 103540 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 123F3B6EE8 for ; Thu, 7 Jul 2011 03:06:19 +1000 (EST) Received: from localhost ([::1]:41199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeVYF-0003he-JK for incoming@patchwork.ozlabs.org; Wed, 06 Jul 2011 13:06:15 -0400 Received: from eggs.gnu.org ([140.186.70.92]:41561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeV58-00050m-W3 for qemu-devel@nongnu.org; Wed, 06 Jul 2011 12:36:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QeV54-0000JT-0U for qemu-devel@nongnu.org; Wed, 06 Jul 2011 12:36:10 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:40222) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeV52-0000JN-VG for qemu-devel@nongnu.org; Wed, 06 Jul 2011 12:36:05 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p66GBvcm026994 for ; Wed, 6 Jul 2011 12:11:57 -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 p66Ga3rG100412 for ; Wed, 6 Jul 2011 12:36:03 -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 p66AYuI0006423 for ; Wed, 6 Jul 2011 04:34:56 -0600 Received: from localhost.localdomain (d941e-10.watson.ibm.com [9.59.241.154]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p66AYtFC006051 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 6 Jul 2011 04:34:56 -0600 Received: from localhost.localdomain (d941e-10 [127.0.0.1]) by localhost.localdomain (8.14.4/8.14.3) with ESMTP id p66GZHqe026679; Wed, 6 Jul 2011 12:35:17 -0400 Received: (from root@localhost) by localhost.localdomain (8.14.4/8.14.4/Submit) id p66GZHoH026678; Wed, 6 Jul 2011 12:35:17 -0400 Message-Id: <20110706163517.391554439@linux.vnet.ibm.com> User-Agent: quilt/0.48-1 Date: Wed, 06 Jul 2011 12:34:51 -0400 From: Stefan Berger To: stefanb@linux.vnet.ibm.com, qemu-devel@nongnu.org References: <20110706163440.987096936@linux.vnet.ibm.com> Content-Disposition: inline; filename=qemu_tpm_blkmig.diff X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 32.97.182.146 Cc: anbang.ruan@cs.ox.ac.uk, andreas.niederl@iaik.tugraz.at, serge@hallyn.com Subject: [Qemu-devel] [PATCH V6 11/13] Experimental support for block migrating TPMs state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 @@ -488,6 +488,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 @@ -1546,17 +1546,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) @@ -1577,6 +1566,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))