[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH COLO-Frame v9 14/32] COLO: Load VMState into qsb bef
From: |
zhanghailiang |
Subject: |
[Qemu-devel] [PATCH COLO-Frame v9 14/32] COLO: Load VMState into qsb before restore it |
Date: |
Wed, 2 Sep 2015 16:23:01 +0800 |
We should not destroy the state of secondary until we receive the whole
state from the primary, in case the primary fails in the middle of sending
the state, so, here we cache the device state in Secondary before restore it.
Besides, we should call qemu_system_reset() before load VM state,
which can ensure the data is intact.
Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Yang Hongyang <address@hidden>
Signed-off-by: Gonglei <address@hidden>
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
---
migration/colo.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 47 insertions(+), 2 deletions(-)
diff --git a/migration/colo.c b/migration/colo.c
index 452a77b..cb6a59d 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -313,6 +313,9 @@ static int colo_wait_handle_cmd(QEMUFile *f, int
*checkpoint_request)
void *colo_process_incoming_thread(void *opaque)
{
MigrationIncomingState *mis = opaque;
+ QEMUFile *fb = NULL;
+ QEMUSizedBuffer *buffer = NULL; /* Cache incoming device state */
+ int total_size;
int fd, ret = 0;
migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
@@ -336,6 +339,12 @@ void *colo_process_incoming_thread(void *opaque)
goto out;
}
+ buffer = qsb_create(NULL, COLO_BUFFER_BASE_SIZE);
+ if (buffer == NULL) {
+ error_report("Failed to allocate colo buffer!");
+ goto out;
+ }
+
ret = colo_ctl_put(mis->to_src_file, COLO_CMD_CHECKPOINT_READY, 0);
if (ret < 0) {
goto out;
@@ -363,20 +372,50 @@ void *colo_process_incoming_thread(void *opaque)
goto out;
}
- /*TODO Load VM state */
+ /* read the VM state total size first */
+ total_size = colo_ctl_get(mis->from_src_file, COLO_CMD_VMSTATE_SIZE);
+ if (total_size <= 0) {
+ goto out;
+ }
+
+ /* read vm device state into colo buffer */
+ ret = qsb_fill_buffer(buffer, mis->from_src_file, total_size);
+ if (ret != total_size) {
+ error_report("can't get all migration data");
+ goto out;
+ }
ret = colo_ctl_put(mis->to_src_file, COLO_CMD_VMSTATE_RECEIVED, 0);
if (ret < 0) {
goto out;
}
+ /* open colo buffer for read */
+ fb = qemu_bufopen("r", buffer);
+ if (!fb) {
+ error_report("can't open colo buffer for read");
+ goto out;
+ }
+
+ qemu_mutex_lock_iothread();
+ qemu_system_reset(VMRESET_SILENT);
+ if (qemu_loadvm_state(fb) < 0) {
+ error_report("COLO: loadvm failed");
+ qemu_mutex_unlock_iothread();
+ goto out;
+ }
+ qemu_mutex_unlock_iothread();
+
/* TODO: flush vm state */
ret = colo_ctl_put(mis->to_src_file, COLO_CMD_VMSTATE_LOADED, 0);
if (ret < 0) {
goto out;
}
-}
+
+ qemu_fclose(fb);
+ fb = NULL;
+ }
out:
if (ret < 0) {
@@ -384,6 +423,11 @@ out:
strerror(-ret));
}
+ if (fb) {
+ qemu_fclose(fb);
+ }
+ qsb_free(buffer);
+
qemu_mutex_lock_iothread();
colo_release_ram_cache();
qemu_mutex_unlock_iothread();
@@ -391,6 +435,7 @@ out:
if (mis->to_src_file) {
qemu_fclose(mis->to_src_file);
}
+
migration_incoming_exit_colo();
return NULL;
--
1.8.3.1
- [Qemu-devel] [PATCH COLO-Frame v9 01/32] configure: Add parameter for configure to enable/disable COLO support, (continued)
- [Qemu-devel] [PATCH COLO-Frame v9 01/32] configure: Add parameter for configure to enable/disable COLO support, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 05/32] migration: Integrate COLO checkpoint process into migration, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 04/32] migration: Add state records for migration incoming, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 09/32] COLO: Implement colo checkpoint protocol, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 11/32] QEMUSizedBuffer: Introduce two help functions for qsb, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 12/32] COLO: Save PVM state to secondary side when do checkpoint, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 08/32] COLO/migration: establish a new communication path from destination to source, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 02/32] migration: Introduce capability 'colo' to migration, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 06/32] migration: Integrate COLO checkpoint process into loadvm, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 16/32] COLO: synchronize PVM's state to SVM periodically, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 14/32] COLO: Load VMState into qsb before restore it,
zhanghailiang <=
- [Qemu-devel] [PATCH COLO-Frame v9 15/32] COLO: Flush PVM's cached RAM into SVM's memory, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 07/32] migration: Rename the'file' member of MigrationState and MigrationIncomingState, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 13/32] COLO: Load PVM's dirty pages into SVM's RAM cache temporarily, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 19/32] COLO: Implement failover work for Primary VM, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 20/32] COLO: Implement failover work for Secondary VM, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 17/32] COLO failover: Introduce a new command to trigger a failover, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 21/32] COLO: implement default failover treatment, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 10/32] COLO: Add a new RunState RUN_STATE_COLO, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 23/32] COLO failover: Shutdown related socket fd when do failover, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 18/32] COLO failover: Introduce state to record failover process, zhanghailiang, 2015/09/02