[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH COLO-Frame v16 10/35] COLO: Save PVM state to second
From: |
zhanghailiang |
Subject: |
[Qemu-devel] [PATCH COLO-Frame v16 10/35] COLO: Save PVM state to secondary side when do checkpoint |
Date: |
Fri, 8 Apr 2016 14:26:12 +0800 |
The main process of checkpoint is to synchronize SVM with PVM.
VM's state includes ram and device state. So we will migrate PVM's
state to SVM when do checkpoint, just like migration does.
We will cache PVM's state in slave, we use QEMUSizedBuffer
to store the data, we need to know the size of VM state, so in master,
we use qsb to store VM state temporarily, get the data size by call
qsb_get_length()
and then migrate the data to the qsb in the secondary side.
Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Gonglei <address@hidden>
Signed-off-by: Li Zhijian <address@hidden>
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
Cc: Dr. David Alan Gilbert <address@hidden>
---
v16:
- Rename colo_put_cmd_value() to colo_send_message_value()
v13:
- Refactor colo_put_cmd_value() to use 'Error **errp' to indicate success
or failure.
v12:
- Replace the old colo_ctl_get() with the new helper function
colo_put_cmd_value()
v11:
- Add Reviewed-by tag
---
migration/colo.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
migration/ram.c | 39 ++++++++++++++++++------
2 files changed, 114 insertions(+), 17 deletions(-)
diff --git a/migration/colo.c b/migration/colo.c
index 027961b..19bffea 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -17,6 +17,9 @@
#include "qemu/error-report.h"
#include "qapi/error.h"
+/* colo buffer */
+#define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)
+
bool colo_supported(void)
{
return true;
@@ -55,6 +58,27 @@ static void colo_send_message(QEMUFile *f, COLOMessage msg,
trace_colo_send_message(COLOMessage_lookup[msg]);
}
+static void colo_send_message_value(QEMUFile *f, COLOMessage msg,
+ uint64_t value, Error **errp)
+{
+ Error *local_err = NULL;
+ int ret;
+
+ colo_send_message(f, msg, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ qemu_put_be64(f, value);
+ qemu_fflush(f);
+
+ ret = qemu_file_get_error(f);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Failed to send value for message:%s",
+ COLOMessage_lookup[msg]);
+ }
+}
+
static COLOMessage colo_receive_message(QEMUFile *f, Error **errp)
{
COLOMessage msg;
@@ -91,9 +115,13 @@ static void colo_receive_check_message(QEMUFile *f,
COLOMessage expect_msg,
}
}
-static int colo_do_checkpoint_transaction(MigrationState *s)
+static int colo_do_checkpoint_transaction(MigrationState *s,
+ QEMUSizedBuffer *buffer)
{
+ QEMUFile *trans = NULL;
+ size_t size;
Error *local_err = NULL;
+ int ret = -1;
colo_send_message(s->to_dst_file, COLO_MESSAGE_CHECKPOINT_REQUEST,
&local_err);
@@ -106,15 +134,48 @@ static int colo_do_checkpoint_transaction(MigrationState
*s)
if (local_err) {
goto out;
}
+ /* Reset colo buffer and open it for write */
+ qsb_set_length(buffer, 0);
+ trans = qemu_bufopen("w", buffer);
+ if (!trans) {
+ error_report("Open colo buffer for write failed");
+ goto out;
+ }
- /* TODO: suspend and save vm state to colo buffer */
+ qemu_mutex_lock_iothread();
+ vm_stop_force_state(RUN_STATE_COLO);
+ qemu_mutex_unlock_iothread();
+ trace_colo_vm_state_change("run", "stop");
+
+ /* Disable block migration */
+ s->params.blk = 0;
+ s->params.shared = 0;
+ qemu_savevm_state_header(trans);
+ qemu_savevm_state_begin(trans, &s->params);
+ qemu_mutex_lock_iothread();
+ qemu_savevm_state_complete_precopy(trans, false);
+ qemu_mutex_unlock_iothread();
+
+ qemu_fflush(trans);
colo_send_message(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err);
if (local_err) {
goto out;
}
+ /* we send the total size of the vmstate first */
+ size = qsb_get_length(buffer);
+ colo_send_message_value(s->to_dst_file, COLO_MESSAGE_VMSTATE_SIZE,
+ size, &local_err);
+ if (local_err) {
+ goto out;
+ }
- /* TODO: send vmstate to Secondary */
+ qsb_put_buffer(s->to_dst_file, buffer, size);
+ qemu_fflush(s->to_dst_file);
+ ret = qemu_file_get_error(s->to_dst_file);
+ if (ret < 0) {
+ goto out;
+ }
colo_receive_check_message(s->rp_state.from_dst_file,
COLO_MESSAGE_VMSTATE_RECEIVED, &local_err);
@@ -128,18 +189,26 @@ static int colo_do_checkpoint_transaction(MigrationState
*s)
goto out;
}
- /* TODO: resume Primary */
+ ret = 0;
+ /* Resume primary guest */
+ qemu_mutex_lock_iothread();
+ vm_start();
+ qemu_mutex_unlock_iothread();
+ trace_colo_vm_state_change("stop", "run");
- return 0;
out:
if (local_err) {
error_report_err(local_err);
}
- return -EINVAL;
+ if (trans) {
+ qemu_fclose(trans);
+ }
+ return ret;
}
static void colo_process_checkpoint(MigrationState *s)
{
+ QEMUSizedBuffer *buffer = NULL;
Error *local_err = NULL;
int ret;
@@ -159,6 +228,12 @@ static void colo_process_checkpoint(MigrationState *s)
goto out;
}
+ buffer = qsb_create(NULL, COLO_BUFFER_BASE_SIZE);
+ if (buffer == NULL) {
+ error_report("Failed to allocate colo buffer!");
+ goto out;
+ }
+
qemu_mutex_lock_iothread();
vm_start();
qemu_mutex_unlock_iothread();
@@ -166,7 +241,7 @@ static void colo_process_checkpoint(MigrationState *s)
while (s->state == MIGRATION_STATUS_COLO) {
/* start a colo checkpoint */
- ret = colo_do_checkpoint_transaction(s);
+ ret = colo_do_checkpoint_transaction(s, buffer);
if (ret < 0) {
goto out;
}
@@ -180,6 +255,9 @@ out:
migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
MIGRATION_STATUS_COMPLETED);
+ qsb_free(buffer);
+ buffer = NULL;
+
if (s->rp_state.from_dst_file) {
qemu_fclose(s->rp_state.from_dst_file);
}
diff --git a/migration/ram.c b/migration/ram.c
index 3f05738..cbe8421 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -41,6 +41,7 @@
#include "trace.h"
#include "exec/ram_addr.h"
#include "qemu/rcu_queue.h"
+#include "migration/colo.h"
#ifdef DEBUG_MIGRATION_RAM
#define DPRINTF(fmt, ...) \
@@ -1874,16 +1875,8 @@ err:
return ret;
}
-
-/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has
- * long-running RCU critical section. When rcu-reclaims in the code
- * start to become numerous it will be necessary to reduce the
- * granularity of these critical sections.
- */
-
-static int ram_save_setup(QEMUFile *f, void *opaque)
+static int ram_save_init_globals(void)
{
- RAMBlock *block;
int64_t ram_bitmap_pages; /* Size of bitmap in pages, including gaps */
dirty_rate_high_cnt = 0;
@@ -1949,6 +1942,31 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
migration_bitmap_sync();
qemu_mutex_unlock_ramlist();
qemu_mutex_unlock_iothread();
+ rcu_read_unlock();
+
+ return 0;
+}
+
+/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has
+ * long-running RCU critical section. When rcu-reclaims in the code
+ * start to become numerous it will be necessary to reduce the
+ * granularity of these critical sections.
+ */
+
+static int ram_save_setup(QEMUFile *f, void *opaque)
+{
+ RAMBlock *block;
+
+ /*
+ * migration has already setup the bitmap, reuse it.
+ */
+ if (!migration_in_colo_state()) {
+ if (ram_save_init_globals() < 0) {
+ return -1;
+ }
+ }
+
+ rcu_read_lock();
qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);
@@ -2050,7 +2068,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
while (true) {
int pages;
- pages = ram_find_and_save_block(f, true, &bytes_transferred);
+ pages = ram_find_and_save_block(f, !migration_in_colo_state(),
+ &bytes_transferred);
/* no more blocks to sent */
if (pages == 0) {
break;
--
1.8.3.1
- [Qemu-devel] [PATCH COLO-Frame v16 05/35] migration: Integrate COLO checkpoint process into loadvm, (continued)
- [Qemu-devel] [PATCH COLO-Frame v16 05/35] migration: Integrate COLO checkpoint process into loadvm, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 02/35] migration: Introduce capability 'x-colo' to migration, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 01/35] configure: Add parameter for configure to enable/disable COLO support, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 06/35] COLO/migration: Create a new communication path from destination to source, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 07/35] COLO: Implement colo checkpoint protocol, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 04/35] migration: Integrate COLO checkpoint process into migration, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 09/35] QEMUSizedBuffer: Introduce two help functions for qsb, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 13/35] COLO: Load VMState into qsb before restore it, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 10/35] COLO: Save PVM state to secondary side when do checkpoint,
zhanghailiang <=
- [Qemu-devel] [PATCH COLO-Frame v16 14/35] COLO: Flush PVM's cached RAM into SVM's memory, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 12/35] ram/COLO: Record the dirty pages that SVM received, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 23/35] COLO failover: Don't do failover during loading VM's state, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 20/35] COLO: Implement failover work for Secondary VM, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 16/35] COLO: synchronize PVM's state to SVM periodically, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 26/35] savevm: Introduce two helper functions for save/find loadvm_handlers entry, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 27/35] migration/savevm: Add new helpers to process the different stages of loadvm, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 28/35] migration/savevm: Export two helper functions for savevm process, zhanghailiang, 2016/04/08