diff mbox

[V5,11/12] Experimental support for block migrating TPMs state

Message ID 20110520154305.723060931@linux.vnet.ibm.com
State New
Headers show

Commit Message

Stefan Berger May 20, 2011, 3:42 p.m. UTC
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 <stefanb@linux.vnet.ibm.com>

---
 hw/tpm_builtin.c |    5 +++++
 savevm.c         |   22 +++++++++++-----------
 2 files changed, 16 insertions(+), 11 deletions(-)
diff mbox

Patch

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))