Skip to contentSkip to conversation

COarse-grain LOck-stepping(COLO) Virtual Machines for Non-stop Service (FT)

PATCH Superseded zhanghailiang 3 participants 41 messages Jun 3, 2016 – Jul 29, 2016 Networking

v17 of 23 Superseded Latest is v23 →

lore
Share & tools
lore
#0 lore raw

v17 cover COarse-grain LOck-stepping(COLO) Virtual Machines for Non-stop Service (FT)

This is the 17th version of COLO FT feature.

Here is only COLO frame part, you can get the whole codes from github:
https://github.com/coloft/qemu/commits/colo-v3.0-periodic-mode

Migration now switches to use the new QIOChannel API. It only affects COLO's patch 9 and patch 12, which we used the old qsb buffer before, and we updated them with the new API. It's only involving tiny changes.

Patch status:
Unreviewed: patch 32 ~ 35
Updated: patch 9, 12, 32

Cc Stefan Hajnoczi <[email protected]>
Cc Jeff Cody <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>
Cc Juan Quintela <[email protected]>
Cc Amit Shah <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
Cc Jason Wang <[email protected]>

PS: These series has been in community for a long time, it depends on Changlong's block-replicaton series, but that has been blocked for a long time, we really need help on reviewing that and this series. Thanks.

TODO:
1. Checkpoint based on proxy in qemu
2. The capability of continuous FT
3. Optimize the VM's downtime during checkpoint

v17:
- Rebase master to use the new QIOChannel API, only affect patch 9 and 12
- Reorganize some ugly comments
- Rename colo_sem to colo_exit_sem (patch 21)

v16:
- Fix compile broken due to missing osdep.h
- Add reviewed-by tag for patch 27, 28, 29
- Rename the message send/receive helper function (patch 7, 13)
- Simplify the codes by using some notifier helpers in QEMU (patch 32)
- Remove the useless check in colo_add_buffer_filter() (patch 33)
- Remove the previous patch 36, 37 which export filter_buffer_flush() to release the buffered packets, we simplify it by stopping buffer filter while doing checkpoint, which will flush the buffered packets by default. (patch 34)
v15:
- Go on the shutdown process if encounter error while sending shutdown message to SVM. (patch 24)
- Rename qemu_need_skip_netfilter to qemu_netfilter_can_skip and Remove some useless comment. (patch 31, Jason)
- Call object_new_with_props() directly to add filter in colo_add_buffer_filter. (patch 34, Jason)
- Re-implement colo_set_filter_status() based on COLOBufferFilters list. (patch 35)
- Re-implement colo_flush_filter_packets() based on COLOBufferFilters list. (patch 37)
v14:
- Re-implement the network processing based on netfilter (Jason Wang)
- Rename 'COLOCommand' to 'COLOMessage'. (Markus's suggestion)
- Split two new patches (patch 27/28) from patch 29
- Fix some other comments from Dave and Markus.

v13:
- Refactor colo_*_cmd helper functions to use 'Error **errp' parameter instead of return value to indicate success or failure. (patch 10)
- Remove the optional error message for COLO_EXIT event. (patch 25)
- Use semaphore to notify colo/colo incoming loop that failover work is finished. (patch 26)
- Move COLO shutdown related codes to colo.c file. (patch 28)
- Fix memory leak bug for colo incoming loop. (new patch 31)
- Re-use some existed helper functions to realize the process of saving/loading ram and device. (patch 32)
- Fix some other comments from Dave and Markus.

zhanghailiang (34):
configure: Add parameter for configure to enable/disable COLO support
migration: Introduce capability 'x-colo' to migration
COLO: migrate colo related info to secondary node
migration: Integrate COLO checkpoint process into migration
migration: Integrate COLO checkpoint process into loadvm COLO/migration: Create a new communication path from destination to
source
COLO: Implement COLO checkpoint protocol
COLO: Add a new RunState RUN_STATE_COLO
COLO: Save PVM state to secondary side when do checkpoint
COLO: Load PVM's dirty pages into SVM's RAM cache temporarily ram/COLO: Record the dirty pages that SVM received
COLO: Load VMState into buffer before restore it
COLO: Flush PVM's cached RAM into SVM's memory
COLO: Add checkpoint-delay parameter for migrate-set-parameters
COLO: Synchronize PVM's state to SVM periodically
COLO failover: Introduce a new command to trigger a failover COLO failover: Introduce state to record failover process
COLO: Implement failover work for Primary VM
COLO: Implement failover work for Secondary VM
qmp event: Add COLO_EXIT event to notify users while exited from COLO COLO failover: Shutdown related socket fd when do failover COLO failover: Don't do failover during loading VM's state
COLO: Process shutdown command for VM in COLO state
COLO: Update the global runstate after going into colo state
savevm: Introduce two helper functions for save/find loadvm_handlers
entry
migration/savevm: Add new helpers to process the different stages of
loadvm
migration/savevm: Export two helper functions for savevm process
COLO: Separate the process of saving/loading ram and device state
COLO: Split qemu_savevm_state_begin out of checkpoint process
filter-buffer: Accept zero interval
net: Add notifier/callback for netdev init
COLO/filter: Add each netdev a buffer filter
COLO: Control the status of buffer filters for PVM
COLO: Add block replication into colo process

 configure                     |  11 +
 docs/qmp-events.txt           |  16 +
 hmp-commands.hx               |  15 +
 hmp.c                         |  15 +
 hmp.h                         |   1 +
 include/exec/ram_addr.h       |   1 +
 include/migration/colo.h      |  43 +++
 include/migration/failover.h  |  33 ++
 include/migration/migration.h |  16 +
 include/net/filter.h          |   2 +
 include/net/net.h             |   3 +
 include/sysemu/sysemu.h       |   9 +
 migration/Makefile.objs       |   2 +
 migration/colo-comm.c         |  79 ++++
 migration/colo-failover.c     |  84 +++++
 migration/colo.c              | 844 ++++++++++++++++++++++++++++++++++++++++++
 migration/migration.c         |  84 ++++-
 migration/ram.c               | 175 ++++++++-
 migration/savevm.c            | 114 ++++--
 net/filter-buffer.c           |  12 -
 net/net.c                     |  12 +
 qapi-schema.json              | 102 ++++-
 qapi/event.json               |  15 +
 qmp-commands.hx               |  24 +-
 stubs/Makefile.objs           |   1 +
 stubs/migration-colo.c        |  55 +++
 trace-events                  |   8 +
 vl.c                          |  31 +-
 28 files changed, 1744 insertions(+), 63 deletions(-)
 create mode 100644 include/migration/colo.h
 create mode 100644 include/migration/failover.h
 create mode 100644 migration/colo-comm.c
 create mode 100644 migration/colo-failover.c
 create mode 100644 migration/colo.c
 create mode 100644 stubs/migration-colo.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v17 1/34 configure: Add parameter for configure to enable/disable COLO support

configure --enable-colo/--disable-colo to switch COLO support on/off.
COLO support is On by default.

---
v11:
- Turn COLO on in default (Eric's suggestion)

---
 configure | 11 +++++++++++
 1 file changed, 11 insertions(+)
configure +11 -0
index b5aab72..996548f 100755
@@ -229,6 +229,7 @@ xfs=""
 vhost_net="no"
 vhost_scsi="no"
 kvm="no"
+colo="yes"
 rdma=""
 gprof="no"
 debug_tcg="no"
@@ -917,6 +918,10 @@ for opt do
   ;;
   --enable-kvm) kvm="yes"
   ;;
+  --disable-colo) colo="no"
+  ;;
+  --enable-colo) colo="yes"
+  ;;
   --disable-tcg-interpreter) tcg_interpreter="no"
   ;;
   --enable-tcg-interpreter) tcg_interpreter="yes"
@@ -1340,6 +1345,7 @@ disabled with --disable-FEATURE, default is enabled if available:
   fdt             fdt device tree
   bluez           bluez stack connectivity
   kvm             KVM acceleration support
+  colo            COarse-grain LOck-stepping VM for Non-stop Service
   rdma            RDMA-based migration support
   uuid            uuid support
   vde             support for vde network
@@ -4835,6 +4841,7 @@ echo "Linux AIO support $linux_aio"
 echo "ATTR/XATTR support $attr"
 echo "Install blobs     $blobs"
 echo "KVM support       $kvm"
+echo "COLO support      $colo"
 echo "RDMA support      $rdma"
 echo "TCG interpreter   $tcg_interpreter"
 echo "fdt support       $fdt"
@@ -5457,6 +5464,10 @@ if have_backend "ftrace"; then
 fi
 echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
 
+if test "$colo" = "yes"; then
+  echo "CONFIG_COLO=y" >> $config_host_mak
+fi
+
 if test "$rdma" = "yes" ; then
   echo "CONFIG_RDMA=y" >> $config_host_mak
 fi
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v17 2/34 migration: Introduce capability 'x-colo' to migration

In reply to zhanghailiang

We add helper function colo_supported() to indicate whether colo is supported or not, with which we use to control whether or not showing 'x-colo' string to users, they can use qmp command 'query-migrate-capabilities' or hmp command 'info migrate_capabilities' to learn if colo is supported.

---
v16:
- fix compile broken due to missing osdep.h
v14:
- Fix the date of Copyright to 2016
v10:
- Rename capability 'colo' to experimental 'x-colo' (Eric's suggestion).
- Rename migrate_enable_colo() to migrate_colo_enabled() (Eric's suggestion).

---
 include/migration/colo.h      | 20 ++++++++++++++++++++
 include/migration/migration.h |  1 +
 migration/Makefile.objs       |  1 +
 migration/colo.c              | 19 +++++++++++++++++++
 migration/migration.c         | 18 ++++++++++++++++++
 qapi-schema.json              |  6 +++++-
 qmp-commands.hx               |  2 +-
 stubs/Makefile.objs           |  1 +
 stubs/migration-colo.c        | 19 +++++++++++++++++++
 9 files changed, 85 insertions(+), 2 deletions(-)
 create mode 100644 include/migration/colo.h
 create mode 100644 migration/colo.c
 create mode 100644 stubs/migration-colo.c
include/migration/colo.h new file +20 -0
new file mode 100644
index 0000000..59a632a
@@ -0,0 +1,20 @@
+/*
+ * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
+ * (a.k.a. Fault Tolerance or Continuous Replication)
+ *
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
+ * Copyright (c) 2016 FUJITSU LIMITED
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_COLO_H
+#define QEMU_COLO_H
+
+#include "qemu-common.h"
+
+bool colo_supported(void);
+
+#endif
include/migration/migration.h +1 -0
index 13b12b7..3250bf3 100644
@@ -299,6 +299,7 @@ int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen);
 
 int migrate_use_xbzrle(void);
 int64_t migrate_xbzrle_cache_size(void);
+bool migrate_colo_enabled(void);
 
 int64_t xbzrle_cache_resize(int64_t new_size);
 
migration/Makefile.objs +1 -0
index 30ad945..cff96f0 100644
@@ -1,5 +1,6 @@
 common-obj-y += migration.o socket.o fd.o exec.o
 common-obj-y += tls.o
+common-obj-$(CONFIG_COLO) += colo.o
 common-obj-y += vmstate.o
 common-obj-y += qemu-file.o
 common-obj-y += qemu-file-channel.o
migration/colo.c new file +19 -0
new file mode 100644
index 0000000..5749016
@@ -0,0 +1,19 @@
+/*
+ * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
+ * (a.k.a. Fault Tolerance or Continuous Replication)
+ *
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
+ * Copyright (c) 2016 FUJITSU LIMITED
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "migration/colo.h"
+
+bool colo_supported(void)
+{
+    return true;
+}
migration/migration.c +18 -0
index 7ecbade..b62e415 100644
@@ -36,6 +36,7 @@
 #include "exec/address-spaces.h"
 #include "io/channel-buffer.h"
 #include "io/channel-tls.h"
+#include "migration/colo.h"
 
 #define MAX_THROTTLE  (32 << 20)      /* Migration transfer speed throttling */
 
@@ -537,6 +538,9 @@ MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
 
     caps = NULL; /* silence compiler warning */
     for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
+        if (i == MIGRATION_CAPABILITY_X_COLO && !colo_supported()) {
+            continue;
+        }
         if (head == NULL) {
             head = g_malloc0(sizeof(*caps));
             caps = head;
@@ -739,6 +743,14 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
     }
 
     for (cap = params; cap; cap = cap->next) {
+        if (cap->value->capability == MIGRATION_CAPABILITY_X_COLO) {
+            if (!colo_supported()) {
+                error_setg(errp, "COLO is not currently supported, please"
+                             " configure with --enable-colo option in order to"
+                             " support COLO feature");
+                continue;
+            }
+        }
         s->enabled_capabilities[cap->value->capability] = cap->value->state;
     }
 
@@ -1693,6 +1705,12 @@ fail:
                       MIGRATION_STATUS_FAILED);
 }
 
+bool migrate_colo_enabled(void)
+{
+    MigrationState *s = migrate_get_current();
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_X_COLO];
+}
+
 /*
  * Master migration thread on the source VM.
  * It drives the migration and pumps the data down the outgoing channel.
qapi-schema.json +5 -1
index 8483bdf..2a9a607 100644
@@ -549,11 +549,15 @@
 #          been migrated, pulling the remaining pages along as needed. NOTE: If
 #          the migration fails during postcopy the VM will fail.  (since 2.6)
 #
+# @x-colo: If enabled, migration will never end, and the state of the VM on the
+#        primary side will be migrated continuously to the VM on secondary
+#        side. (since 2.7)
+#
 # Since: 1.2
 ##
 { 'enum': 'MigrationCapability',
   'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks',
-           'compress', 'events', 'postcopy-ram'] }
+           'compress', 'events', 'postcopy-ram', 'x-colo'] }
 
 ##
 # @MigrationCapabilityStatus
qmp-commands.hx +1 -1
index 28801a2..34d82c3 100644
@@ -3713,7 +3713,7 @@ Query current migration capabilities
          - "zero-blocks" : Zero Blocks state (json-bool)
          - "compress": Multiple compression threads state (json-bool)
          - "events": Migration state change event state (json-bool)
-         - "postcopy-ram": postcopy ram state (json-bool)
+         - "x-colo" : COarse-Grain LOck Stepping for Non-stop Service (json-bool)
 
 Arguments:
 
stubs/Makefile.objs +1 -0
index 4b258a6..f4284db 100644
@@ -41,3 +41,4 @@ stub-obj-y += target-monitor-defs.o
 stub-obj-y += target-get-monitor-def.o
 stub-obj-y += vhost.o
 stub-obj-y += iohandler.o
+stub-obj-y += migration-colo.o
stubs/migration-colo.c new file +19 -0
new file mode 100644
index 0000000..d215057
@@ -0,0 +1,19 @@
+/*
+ * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
+ * (a.k.a. Fault Tolerance or Continuous Replication)
+ *
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
+ * Copyright (c) 2016 FUJITSU LIMITED
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "migration/colo.h"
+
+bool colo_supported(void)
+{
+    return false;
+}
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v17 3/34 COLO: migrate colo related info to secondary node

In reply to zhanghailiang

We can know if VM in destination should go into COLO mode by refer to the info that been migrated from PVM.

We skip this section if colo is not enabled (i.e. migrate_set_capability colo off), so that, It not break compatibility with migration however the --enable-colo/disable-colo on the source/destination;

---
v16:
- Fix compile broken due to missing osdep.h
v14:
- Adjust the place of calling colo_info_init()
v11:
- Add Reviewed-by tag
v10:
- Use VMSTATE_BOOL instead of VMSTATE_UNIT32 for 'colo_requested' (Dave's suggestion)

---
 include/migration/colo.h |  2 ++
 migration/Makefile.objs  |  1 +
 migration/colo-comm.c    | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c                     |  4 +++-
 4 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 migration/colo-comm.c
include/migration/colo.h +2 -0
index 59a632a..1c899a0 100644
@@ -14,7 +14,9 @@
 #define QEMU_COLO_H
 
 #include "qemu-common.h"
+#include "migration/migration.h"
 
 bool colo_supported(void);
+void colo_info_init(void);
 
 #endif
migration/Makefile.objs +1 -0
index cff96f0..4bbe9ab 100644
@@ -1,6 +1,7 @@
 common-obj-y += migration.o socket.o fd.o exec.o
 common-obj-y += tls.o
 common-obj-$(CONFIG_COLO) += colo.o
+common-obj-y += colo-comm.o
 common-obj-y += vmstate.o
 common-obj-y += qemu-file.o
 common-obj-y += qemu-file-channel.o
migration/colo-comm.c new file +51 -0

51 lines not on this page · raw message

vl.c +3 -1
index 2f74fe8..1a8869e 100644
@@ -89,6 +89,7 @@ int main(int argc, char **argv)
 #include "audio/audio.h"
 #include "migration/migration.h"
 #include "sysemu/cpus.h"
+#include "migration/colo.h"
 #include "sysemu/kvm.h"
 #include "qapi/qmp/qjson.h"
 #include "qemu/option.h"
@@ -4372,6 +4373,8 @@ int main(int argc, char **argv, char **envp)
 #endif
     }
 
+    colo_info_init();
+
     if (net_init_clients() < 0) {
         exit(1);
     }
@@ -4402,7 +4405,6 @@ int main(int argc, char **argv, char **envp)
 
     blk_mig_init();
     ram_mig_init();
-
     /* If the currently selected machine wishes to override the units-per-bus
      * property of its default HBA interface type, do so now. */
     if (machine_class->units_per_default_bus) {
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v17 4/34 migration: Integrate COLO checkpoint process into migration

In reply to zhanghailiang

Add a migrate state: MIGRATION_STATUS_COLO, enter this migration state after the first live migration successfully finished.

We reuse migration thread, so if colo is enabled by user, migration thread will go into the process of colo.

---
v11:
- Rebase to master
- Add Reviewed-by tag
v10:
- Simplify process by dropping colo thread and reusing migration thread. (Dave's suggestion)

---
 include/migration/colo.h |  3 +++
 migration/colo.c         | 31 +++++++++++++++++++++++++++++++
 migration/migration.c    | 30 ++++++++++++++++++++++++++----
 qapi-schema.json         |  4 +++-
 stubs/migration-colo.c   |  9 +++++++++
 trace-events             |  3 +++
 6 files changed, 75 insertions(+), 5 deletions(-)
include/migration/colo.h +3 -0
index 1c899a0..bf84b99 100644
@@ -19,4 +19,7 @@
 bool colo_supported(void);
 void colo_info_init(void);
 
+void migrate_start_colo_process(MigrationState *s);
+bool migration_in_colo_state(void);
+
 #endif
migration/colo.c +31 -0
index 5749016..d2c2d1f 100644
@@ -11,9 +11,40 @@
  */
 
 #include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
 #include "migration/colo.h"
+#include "trace.h"
 
 bool colo_supported(void)
 {
     return true;
 }
+
+bool migration_in_colo_state(void)
+{
+    MigrationState *s = migrate_get_current();
+
+    return (s->state == MIGRATION_STATUS_COLO);
+}
+
+static void colo_process_checkpoint(MigrationState *s)
+{
+    qemu_mutex_lock_iothread();
+    vm_start();
+    qemu_mutex_unlock_iothread();
+    trace_colo_vm_state_change("stop", "run");
+
+    /*TODO: COLO checkpoint savevm loop*/
+
+    migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
+                      MIGRATION_STATUS_COMPLETED);
+}
+
+void migrate_start_colo_process(MigrationState *s)
+{
+    qemu_mutex_unlock_iothread();
+    migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE,
+                      MIGRATION_STATUS_COLO);
+    colo_process_checkpoint(s);
+    qemu_mutex_lock_iothread();
+}
migration/migration.c +26 -4
index b62e415..64edac5 100644
@@ -692,6 +692,10 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 
         get_xbzrle_cache_stats(info);
         break;
+    case MIGRATION_STATUS_COLO:
+        info->has_status = true;
+        /* TODO: display COLO specific information (checkpoint info etc.) */
+        break;
     case MIGRATION_STATUS_COMPLETED:
         get_xbzrle_cache_stats(info);
 
@@ -1091,7 +1095,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
     params.shared = has_inc && inc;
 
     if (migration_is_setup_or_active(s->state) ||
-        s->state == MIGRATION_STATUS_CANCELLING) {
+        s->state == MIGRATION_STATUS_CANCELLING ||
+        s->state == MIGRATION_STATUS_COLO) {
         error_setg(errp, QERR_MIGRATION_ACTIVE);
         return;
     }
@@ -1683,8 +1688,11 @@ static void migration_completion(MigrationState *s, int current_active_state,
         goto fail_invalidate;
     }
 
-    migrate_set_state(&s->state, current_active_state,
-                      MIGRATION_STATUS_COMPLETED);
+    if (!migrate_colo_enabled()) {
+        migrate_set_state(&s->state, current_active_state,
+                          MIGRATION_STATUS_COMPLETED);
+    }
+
     return;
 
 fail_invalidate:
@@ -1729,6 +1737,7 @@ static void *migration_thread(void *opaque)
     bool entered_postcopy = false;
     /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */
     enum MigrationStatus current_active_state = MIGRATION_STATUS_ACTIVE;
+    bool enable_colo = migrate_colo_enabled();
 
     rcu_register_thread();
 
@@ -1837,7 +1846,11 @@ static void *migration_thread(void *opaque)
     end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
 
     qemu_mutex_lock_iothread();
-    qemu_savevm_state_cleanup();
+    /* The resource has been allocated by migration will be reused in COLO
+      process, so don't release them. */
+    if (!enable_colo) {
+        qemu_savevm_state_cleanup();
+    }
     if (s->state == MIGRATION_STATUS_COMPLETED) {
         uint64_t transferred_bytes = qemu_ftell(s->to_dst_file);
         s->total_time = end_time - s->total_time;
@@ -1850,6 +1863,15 @@ static void *migration_thread(void *opaque)
         }
         runstate_set(RUN_STATE_POSTMIGRATE);
     } else {
+        if (s->state == MIGRATION_STATUS_ACTIVE && enable_colo) {
+            migrate_start_colo_process(s);
+            qemu_savevm_state_cleanup();
+            /*
+            * Fixme: we will run VM in COLO no matter its old running state.
+            * After exited COLO, we will keep running.
+            */
+            old_vm_running = true;
+        }
         if (old_vm_running && !entered_postcopy) {
             vm_start();
         }
qapi-schema.json +3 -1
index 2a9a607..6aa78aa 100644
@@ -434,12 +434,14 @@
 #
 # @failed: some error occurred during migration process.
 #
+# @colo: VM is in the process of fault tolerance. (since 2.7)
+#
 # Since: 2.3
 #
 ##
 { 'enum': 'MigrationStatus',
   'data': [ 'none', 'setup', 'cancelling', 'cancelled',
-            'active', 'postcopy-active', 'completed', 'failed' ] }
+            'active', 'postcopy-active', 'completed', 'failed', 'colo' ] }
 
 ##
 # @MigrationInfo
stubs/migration-colo.c +9 -0
index d215057..0c8eef4 100644
@@ -17,3 +17,12 @@ bool colo_supported(void)
 {
     return false;
 }
+
+bool migration_in_colo_state(void)
+{
+    return false;
+}
+
+void migrate_start_colo_process(MigrationState *s)
+{
+}
trace-events +3 -0
index 68ebac9..bd6b750 100644
@@ -1620,6 +1620,9 @@ migration_tls_incoming_handshake_start(void) ""
 migration_tls_incoming_handshake_error(const char *err) "err=%s"
 migration_tls_incoming_handshake_complete(void) ""
 
+# migration/colo.c
+colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'"
+
 # kvm-all.c
 kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"
 kvm_vm_ioctl(int type, void *arg) "type 0x%x, arg %p"
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v17 5/34 migration: Integrate COLO checkpoint process into loadvm

In reply to zhanghailiang

Switch from normal migration loadvm process into COLO checkpoint process if COLO mode is enabled.
We add three new members to struct MigrationIncomingState, 'have_colo_incoming_thread' and 'colo_incoming_thread' record the colo related threads for secondary VM, 'migration_incoming_co' records the original migration incoming coroutine.

---
v12:
- Add Reviewed-by tag
v11:
- We moved the place of bdrv_invalidate_cache_all(), but done the deleting work in other patch. Fix it.
- Add documentation for colo in 'MigrationStatus' (Eric's review comment) v10:
- fix a bug about fd leak which is found by Dave.

---
 include/migration/colo.h      |  7 +++++++
 include/migration/migration.h |  7 +++++++
 migration/colo-comm.c         | 10 ++++++++++
 migration/colo.c              | 21 +++++++++++++++++++++
 migration/migration.c         | 12 ++++++++++++
 stubs/migration-colo.c        | 10 ++++++++++
 6 files changed, 67 insertions(+)
include/migration/colo.h +7 -0
index bf84b99..b40676c 100644
@@ -15,6 +15,8 @@
 
 #include "qemu-common.h"
 #include "migration/migration.h"
+#include "qemu/coroutine_int.h"
+#include "qemu/thread.h"
 
 bool colo_supported(void);
 void colo_info_init(void);
@@ -22,4 +24,9 @@ void colo_info_init(void);
 void migrate_start_colo_process(MigrationState *s);
 bool migration_in_colo_state(void);
 
+/* loadvm */
+bool migration_incoming_enable_colo(void);
+void migration_incoming_exit_colo(void);
+void *colo_process_incoming_thread(void *opaque);
+bool migration_incoming_in_colo_state(void);
 #endif
include/migration/migration.h +7 -0
index 3250bf3..55a2df6 100644
@@ -21,6 +21,7 @@
 #include "migration/vmstate.h"
 #include "qapi-types.h"
 #include "exec/cpu-common.h"
+#include "qemu/coroutine_int.h"
 
 #define QEMU_VM_FILE_MAGIC           0x5145564d
 #define QEMU_VM_FILE_VERSION_COMPAT  0x00000002
@@ -107,6 +108,12 @@ struct MigrationIncomingState {
     QEMUBH *bh;
 
     int state;
+
+    bool have_colo_incoming_thread;
+    QemuThread colo_incoming_thread;
+    /* The coroutine we should enter (back) after failover */
+    Coroutine *migration_incoming_co;
+
     /* See savevm.c */
     LoadStateEntry_Head loadvm_handlers;
 };
migration/colo-comm.c +10 -0
index 2d06ace..1a36893 100644
@@ -49,3 +49,13 @@ void colo_info_init(void)
 {
     vmstate_register(NULL, 0, &colo_state, &colo_info);
 }
+
+bool migration_incoming_enable_colo(void)
+{
+    return colo_info.colo_requested;
+}
+
+void migration_incoming_exit_colo(void)
+{
+    colo_info.colo_requested = 0;
+}
migration/colo.c +21 -0
index d2c2d1f..68815c0 100644
@@ -27,6 +27,13 @@ bool migration_in_colo_state(void)
     return (s->state == MIGRATION_STATUS_COLO);
 }
 
+bool migration_incoming_in_colo_state(void)
+{
+    MigrationIncomingState *mis = migration_incoming_get_current();
+
+    return mis && (mis->state == MIGRATION_STATUS_COLO);
+}
+
 static void colo_process_checkpoint(MigrationState *s)
 {
     qemu_mutex_lock_iothread();
@@ -48,3 +55,17 @@ void migrate_start_colo_process(MigrationState *s)
     colo_process_checkpoint(s);
     qemu_mutex_lock_iothread();
 }
+
+void *colo_process_incoming_thread(void *opaque)
+{
+    MigrationIncomingState *mis = opaque;
+
+    migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
+                      MIGRATION_STATUS_COLO);
+
+    /* TODO: COLO checkpoint restore loop */
+
+    migration_incoming_exit_colo();
+
+    return NULL;
+}
migration/migration.c +12 -0
index 64edac5..71a81fb 100644
@@ -402,6 +402,18 @@ static void process_incoming_migration_co(void *opaque)
         /* Else if something went wrong then just fall out of the normal exit */
     }
 
+    /* we get colo info, and know if we are in colo mode */
+    if (!ret && migration_incoming_enable_colo()) {
+        mis->migration_incoming_co = qemu_coroutine_self();
+        qemu_thread_create(&mis->colo_incoming_thread, "colo incoming",
+             colo_process_incoming_thread, mis, QEMU_THREAD_JOINABLE);
+        mis->have_colo_incoming_thread = true;
+        qemu_coroutine_yield();
+
+        /* Wait checkpoint incoming thread exit before free resource */
+        qemu_thread_join(&mis->colo_incoming_thread);
+    }
+
     qemu_fclose(f);
     free_xbzrle_decoded_buf();
 
stubs/migration-colo.c +10 -0
index 0c8eef4..7b72395 100644
@@ -23,6 +23,16 @@ bool migration_in_colo_state(void)
     return false;
 }
 
+bool migration_incoming_in_colo_state(void)
+{
+    return false;
+}
+
 void migrate_start_colo_process(MigrationState *s)
 {
 }
+
+void *colo_process_incoming_thread(void *opaque)
+{
+    return NULL;
+}
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v17 6/34 COLO/migration: Create a new communication path from destination to source

In reply to zhanghailiang

This new communication path will be used for returning messages from destination to source.

---
v13:
- Remove useless error report
v12:
- Add Reviewed-by tag
v11:
- Rebase master to use qemu_file_get_return_path() for opening return path v10:
- fix the the error log (Dave's suggestion).

---
 migration/colo.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
migration/colo.c +28 -0
index 68815c0..13204fc 100644
@@ -14,6 +14,7 @@
 #include "sysemu/sysemu.h"
 #include "migration/colo.h"
 #include "trace.h"
+#include "qemu/error-report.h"
 
 bool colo_supported(void)
 {
@@ -36,6 +37,12 @@ bool migration_incoming_in_colo_state(void)
 
 static void colo_process_checkpoint(MigrationState *s)
 {
+    s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file);
+    if (!s->rp_state.from_dst_file) {
+        error_report("Open QEMUFile from_dst_file failed");
+        goto out;
+    }
+
     qemu_mutex_lock_iothread();
     vm_start();
     qemu_mutex_unlock_iothread();
@@ -43,8 +50,13 @@ static void colo_process_checkpoint(MigrationState *s)
 
     /*TODO: COLO checkpoint savevm loop*/
 
+out:
     migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
                       MIGRATION_STATUS_COMPLETED);
+
+    if (s->rp_state.from_dst_file) {
+        qemu_fclose(s->rp_state.from_dst_file);
+    }
 }
 
 void migrate_start_colo_process(MigrationState *s)
@@ -63,8 +75,24 @@ void *colo_process_incoming_thread(void *opaque)
     migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
                       MIGRATION_STATUS_COLO);
 
+    mis->to_src_file = qemu_file_get_return_path(mis->from_src_file);
+    if (!mis->to_src_file) {
+        error_report("colo incoming thread: Open QEMUFile to_src_file failed");
+        goto out;
+    }
+    /*
+     * Note: We set the fd to unblocked in migration incoming coroutine,
+     * But here we are in the colo incoming thread, so it is ok to set the
+     * fd back to blocked.
+     */
+    qemu_file_set_blocking(mis->from_src_file, true);
+
     /* TODO: COLO checkpoint restore loop */
 
+out:
+    if (mis->to_src_file) {
+        qemu_fclose(mis->to_src_file);
+    }
     migration_incoming_exit_colo();
 
     return NULL;
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v17 7/34 COLO: Implement COLO checkpoint protocol

In reply to zhanghailiang

We need communications protocol of user-defined to control the checkpoint process.

The new checkpoint request is started by Primary VM, and the interactive process like below:
Checkpoint synchronizing points:

Primary Secondary
initial work
'checkpoint-ready' <-------------------- @

'checkpoint-request' @ -------------------->
Suspend (Only in hybrid mode)
'checkpoint-reply' <-------------------- @
Suspend&Save state
'vmstate-send' @ -------------------->
Send state Receive state
'vmstate-received' <-------------------- @
Release packets Load state
'vmstate-load' <-------------------- @
Resume Resume (Only in hybrid mode)

Start Comparing (Only in hybrid mode)
NOTE:
1) '@' who sends the message
2) Every sync-point is synchronized by two sides with only one handshake(single direction) for low-latency.
If more strict synchronization is required, a opposite direction sync-point should be added.
3) Since sync-points are single direction, the remote side may go forward a lot when this side just receives the sync-point.
4) For now, we only support 'periodic' checkpoint, for which the Secondary VM is not running, later we will support 'hybrid' mode.

---
v16:
- Rename 'colo_put/get[_check]_cmd()' to 'colo_send/receive[_check]_message()' v14:
- Rename 'COLOCommand' to 'COLOMessage'. (Markus's suggestion)
- Add Reviewd-by tag
v13:
- Refactor colo command related helper functions, use 'Error **errp' parameter instead of return value to indicate success or failure.
- Fix some other comments from Markus.

v12:
- Rename colo_ctl_put() to colo_put_cmd()
- Rename colo_ctl_get() to colo_get_check_cmd() and drop
the third parameter
- Rename colo_ctl_get_cmd() to colo_get_cmd()
- Remove useless 'invalid' member for COLOcommand enum.
v11:
- Add missing 'checkpoint-ready' communication in comment.
- Use parameter to return 'value' for colo_ctl_get() (Dave's suggestion)
- Fix trace for colo_ctl_get() to trace command and value both v10:
- Rename enum COLOCmd to COLOCommand (Eric's suggestion).
- Remove unused 'ram-steal'

---
 migration/colo.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 qapi-schema.json |  25 +++++++
 trace-events     |   2 +
 3 files changed, 225 insertions(+), 2 deletions(-)
migration/colo.c +198 -2
index 13204fc..d6b934c 100644
@@ -15,6 +15,7 @@
 #include "migration/colo.h"
 #include "trace.h"
 #include "qemu/error-report.h"
+#include "qapi/error.h"
 
 bool colo_supported(void)
 {
@@ -35,22 +36,146 @@ bool migration_incoming_in_colo_state(void)
     return mis && (mis->state == MIGRATION_STATUS_COLO);
 }
 
+static void colo_send_message(QEMUFile *f, COLOMessage msg,
+                              Error **errp)
+{
+    int ret;
+
+    if (msg >= COLO_MESSAGE__MAX) {
+        error_setg(errp, "%s: Invalid message", __func__);
+        return;
+    }
+    qemu_put_be32(f, msg);
+    qemu_fflush(f);
+
+    ret = qemu_file_get_error(f);
+    if (ret < 0) {
+        error_setg_errno(errp, -ret, "Can't send COLO message");
+    }
+    trace_colo_send_message(COLOMessage_lookup[msg]);
+}
+
+static COLOMessage colo_receive_message(QEMUFile *f, Error **errp)
+{
+    COLOMessage msg;
+    int ret;
+
+    msg = qemu_get_be32(f);
+    ret = qemu_file_get_error(f);
+    if (ret < 0) {
+        error_setg_errno(errp, -ret, "Can't receive COLO message");
+        return msg;
+    }
+    if (msg >= COLO_MESSAGE__MAX) {
+        error_setg(errp, "%s: Invalid message", __func__);
+        return msg;
+    }
+    trace_colo_receive_message(COLOMessage_lookup[msg]);
+    return msg;
+}
+
+static void colo_receive_check_message(QEMUFile *f, COLOMessage expect_msg,
+                                       Error **errp)
+{
+    COLOMessage msg;
+    Error *local_err = NULL;
+
+    msg = colo_receive_message(f, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+    if (msg != expect_msg) {
+        error_setg(errp, "Unexpected COLO message %d, expected %d",
+                          msg, expect_msg);
+    }
+}
+
+static int colo_do_checkpoint_transaction(MigrationState *s)
+{
+    Error *local_err = NULL;
+
+    colo_send_message(s->to_dst_file, COLO_MESSAGE_CHECKPOINT_REQUEST,
+                      &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    colo_receive_check_message(s->rp_state.from_dst_file,
+                    COLO_MESSAGE_CHECKPOINT_REPLY, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    /* TODO: suspend and save vm state to colo buffer */
+
+    colo_send_message(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    /* TODO: send vmstate to Secondary */
+
+    colo_receive_check_message(s->rp_state.from_dst_file,
+                       COLO_MESSAGE_VMSTATE_RECEIVED, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    colo_receive_check_message(s->rp_state.from_dst_file,
+                       COLO_MESSAGE_VMSTATE_LOADED, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    /* TODO: resume Primary */
+
+    return 0;
+out:
+    if (local_err) {
+        error_report_err(local_err);
+    }
+    return -EINVAL;
+}
+
 static void colo_process_checkpoint(MigrationState *s)
 {
+    Error *local_err = NULL;
+    int ret;
+
     s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file);
     if (!s->rp_state.from_dst_file) {
         error_report("Open QEMUFile from_dst_file failed");
         goto out;
     }
 
+    /*
+     * Wait for Secondary finish loading vm states and enter COLO
+     * restore.
+     */
+    colo_receive_check_message(s->rp_state.from_dst_file,
+                       COLO_MESSAGE_CHECKPOINT_READY, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
     qemu_mutex_lock_iothread();
     vm_start();
     qemu_mutex_unlock_iothread();
     trace_colo_vm_state_change("stop", "run");
 
-    /*TODO: COLO checkpoint savevm loop*/
+    while (s->state == MIGRATION_STATUS_COLO) {
+        ret = colo_do_checkpoint_transaction(s);
+        if (ret < 0) {
+            goto out;
+        }
+    }
 
 out:
+    /* Throw the unreported error message after exited from loop */
+    if (local_err) {
+        error_report_err(local_err);
+    }
     migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
                       MIGRATION_STATUS_COMPLETED);
 
@@ -68,9 +193,33 @@ void migrate_start_colo_process(MigrationState *s)
     qemu_mutex_lock_iothread();
 }
 
+static void colo_wait_handle_message(QEMUFile *f, int *checkpoint_request,
+                                     Error **errp)
+{
+    COLOMessage msg;
+    Error *local_err = NULL;
+
+    msg = colo_receive_message(f, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    switch (msg) {
+    case COLO_MESSAGE_CHECKPOINT_REQUEST:
+        *checkpoint_request = 1;
+        break;
+    default:
+        *checkpoint_request = 0;
+        error_setg(errp, "Got unknown COLO message: %d", msg);
+        break;
+    }
+}
+
 void *colo_process_incoming_thread(void *opaque)
 {
     MigrationIncomingState *mis = opaque;
+    Error *local_err = NULL;
 
     migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
                       MIGRATION_STATUS_COLO);
@@ -87,9 +236,56 @@ void *colo_process_incoming_thread(void *opaque)
      */
     qemu_file_set_blocking(mis->from_src_file, true);
 
-    /* TODO: COLO checkpoint restore loop */
+    colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY,
+                      &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    while (mis->state == MIGRATION_STATUS_COLO) {
+        int request;
+
+        colo_wait_handle_message(mis->from_src_file, &request, &local_err);
+        if (local_err) {
+            goto out;
+        }
+        assert(request);
+        /* FIXME: This is unnecessary for periodic checkpoint mode */
+        colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_REPLY,
+                     &local_err);
+        if (local_err) {
+            goto out;
+        }
+
+        colo_receive_check_message(mis->from_src_file,
+                           COLO_MESSAGE_VMSTATE_SEND, &local_err);
+        if (local_err) {
+            goto out;
+        }
+
+        /* TODO: read migration data into colo buffer */
+
+        colo_send_message(mis->to_src_file, COLO_MESSAGE_VMSTATE_RECEIVED,
+                     &local_err);
+        if (local_err) {
+            goto out;
+        }
+
+        /* TODO: load vm state */
+
+        colo_send_message(mis->to_src_file, COLO_MESSAGE_VMSTATE_LOADED,
+                     &local_err);
+        if (local_err) {
+            goto out;
+        }
+    }
 
 out:
+    /* Throw the unreported error message after exited from loop */
+    if (local_err) {
+        error_report_err(local_err);
+    }
+
     if (mis->to_src_file) {
         qemu_fclose(mis->to_src_file);
     }
qapi-schema.json +25 -0
index 6aa78aa..40c5849 100644
@@ -775,6 +775,31 @@
 { 'command': 'migrate-start-postcopy' }
 
 ##
+# @COLOMessage
+#
+# The message transmission between PVM and SVM
+#
+# @checkpoint-ready: SVM is ready for checkpointing
+#
+# @checkpoint-request: PVM tells SVM to prepare for new checkpointing
+#
+# @checkpoint-reply: SVM gets PVM's checkpoint request
+#
+# @vmstate-send: VM's state will be sent by PVM.
+#
+# @vmstate-size: The total size of VMstate.
+#
+# @vmstate-received: VM's state has been received by SVM.
+#
+# @vmstate-loaded: VM's state has been loaded by SVM.
+#
+# Since: 2.7
+##
+{ 'enum': 'COLOMessage',
+  'data': [ 'checkpoint-ready', 'checkpoint-request', 'checkpoint-reply',
+            'vmstate-send', 'vmstate-size', 'vmstate-received',
+            'vmstate-loaded' ] }
+
 # @MouseInfo:
 #
 # Information about a mouse device.
trace-events +2 -0
index bd6b750..1dd4344 100644
@@ -1622,6 +1622,8 @@ migration_tls_incoming_handshake_complete(void) ""
 
 # migration/colo.c
 colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'"
+colo_send_message(const char *msg) "Send '%s' message"
+colo_receive_message(const char *msg) "Receive '%s' message"
 
 # kvm-all.c
 kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH v17 8/34 COLO: Add a new RunState RUN_STATE_COLO

In reply to zhanghailiang

Guest will enter this state when paused to save/restore VM state under colo checkpoint.

---
 qapi-schema.json | 5 ++++-
 vl.c             | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
qapi-schema.json +4 -1
index 40c5849..724bcf7 100644
@@ -154,12 +154,15 @@
 # @watchdog: the watchdog action is configured to pause and has been triggered
 #
 # @guest-panicked: guest has been panicked as a result of guest OS panic
+#
+# @colo: guest is paused to save/restore VM state under colo checkpoint (since
+# 2.7)
 ##
 { 'enum': 'RunState',
   'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused',
             'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm',
             'running', 'save-vm', 'shutdown', 'suspended', 'watchdog',
-            'guest-panicked' ] }
+            'guest-panicked', 'colo' ] }
 
 ##
 # @StatusInfo:
vl.c +8 -0
index 1a8869e..47ca1c1 100644
@@ -594,6 +594,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_INMIGRATE, RUN_STATE_FINISH_MIGRATE },
     { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH },
     { RUN_STATE_INMIGRATE, RUN_STATE_POSTMIGRATE },
+    { RUN_STATE_INMIGRATE, RUN_STATE_COLO },
 
     { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
     { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
@@ -606,6 +607,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
     { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
     { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH },
+    { RUN_STATE_PAUSED, RUN_STATE_COLO},
 
     { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
     { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
@@ -618,10 +620,13 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
+    { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO},
 
     { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
     { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
 
+    { RUN_STATE_COLO, RUN_STATE_RUNNING },
+
     { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
     { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
     { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
@@ -632,6 +637,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
     { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
     { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
+    { RUN_STATE_RUNNING, RUN_STATE_COLO},
 
     { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
 
@@ -644,10 +650,12 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
     { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
     { RUN_STATE_SUSPENDED, RUN_STATE_PRELAUNCH },
+    { RUN_STATE_SUSPENDED, RUN_STATE_COLO},
 
     { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
     { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
     { RUN_STATE_WATCHDOG, RUN_STATE_PRELAUNCH },
+    { RUN_STATE_WATCHDOG, RUN_STATE_COLO},
 
     { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING },
     { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH v17 9/34 COLO: Save PVM state to secondary side when do checkpoint

In reply to zhanghailiang

The main process of the 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.

---
v17:
- Rebase to master, use the new channel-buffer API
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 | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 migration/ram.c  | 39 +++++++++++++++++++-------
 2 files changed, 104 insertions(+), 18 deletions(-)
migration/colo.c +75 -8
index d6b934c..8ef1a22 100644
@@ -13,10 +13,13 @@
 #include "qemu/osdep.h"
 #include "sysemu/sysemu.h"
 #include "migration/colo.h"
+#include "io/channel-buffer.h"
 #include "trace.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 
+#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,12 @@ 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,
+                                          QIOChannelBuffer *bioc,
+                                          QEMUFile *fb)
 {
     Error *local_err = NULL;
+    int ret = -1;
 
     colo_send_message(s->to_dst_file, COLO_MESSAGE_CHECKPOINT_REQUEST,
                       &local_err);
@@ -106,15 +133,46 @@ static int colo_do_checkpoint_transaction(MigrationState *s)
     if (local_err) {
         goto out;
     }
+    /* Reset channel-buffer directly */
+    qio_channel_io_seek(QIO_CHANNEL(bioc), 0, 0, NULL);
+    bioc->usage = 0;
+
+    qemu_mutex_lock_iothread();
+    vm_stop_force_state(RUN_STATE_COLO);
+    qemu_mutex_unlock_iothread();
+    trace_colo_vm_state_change("run", "stop");
 
-    /* TODO: suspend and save vm state to colo buffer */
+    /* Disable block migration */
+    s->params.blk = 0;
+    s->params.shared = 0;
+    qemu_savevm_state_header(fb);
+    qemu_savevm_state_begin(fb, &s->params);
+    qemu_mutex_lock_iothread();
+    qemu_savevm_state_complete_precopy(fb, false);
+    qemu_mutex_unlock_iothread();
+
+    qemu_fflush(fb);
 
     colo_send_message(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err);
     if (local_err) {
         goto out;
     }
+    /*
+     * We need the size of the VMstate data in Secondary side,
+     * With which we can decide how much data should be read.
+     */
+    colo_send_message_value(s->to_dst_file, COLO_MESSAGE_VMSTATE_SIZE,
+                            bioc->usage, &local_err);
+    if (local_err) {
+        goto out;
+    }
 
-    /* TODO: send vmstate to Secondary */
+    qemu_put_buffer(s->to_dst_file, bioc->data, bioc->usage);
+    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 +186,24 @@ static int colo_do_checkpoint_transaction(MigrationState *s)
         goto out;
     }
 
-    /* TODO: resume Primary */
+    ret = 0;
+
+    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;
+    return ret;
 }
 
 static void colo_process_checkpoint(MigrationState *s)
 {
+    QIOChannelBuffer *bioc;
+    QEMUFile *fb = NULL;
     Error *local_err = NULL;
     int ret;
 
@@ -158,6 +222,9 @@ static void colo_process_checkpoint(MigrationState *s)
     if (local_err) {
         goto out;
     }
+    bioc = qio_channel_buffer_new(COLO_BUFFER_BASE_SIZE);
+    fb = qemu_fopen_channel_output(QIO_CHANNEL(bioc));
+    object_unref(OBJECT(bioc));
 
     qemu_mutex_lock_iothread();
     vm_start();
@@ -165,7 +232,7 @@ static void colo_process_checkpoint(MigrationState *s)
     trace_colo_vm_state_change("stop", "run");
 
     while (s->state == MIGRATION_STATUS_COLO) {
-        ret = colo_do_checkpoint_transaction(s);
+        ret = colo_do_checkpoint_transaction(s, bioc, fb);
         if (ret < 0) {
             goto out;
         }
@@ -178,7 +245,7 @@ out:
     }
     migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
                       MIGRATION_STATUS_COMPLETED);
-
+    qemu_fclose(fb);
     if (s->rp_state.from_dst_file) {
         qemu_fclose(s->rp_state.from_dst_file);
     }
migration/ram.c +29 -10
index 844ea46..ae9a656 100644
@@ -43,6 +43,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;
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH v17 10/34 COLO: Load PVM's dirty pages into SVM's RAM cache temporarily

In reply to zhanghailiang

We should not load PVM's state directly into SVM, because there maybe some errors happen when SVM is receving data, which will break SVM.

We need to ensure receving all data before load the state into SVM. We use an extra memory to cache these data (PVM's ram). The ram cache in secondary side is initially the same as SVM/PVM's memory. And in the process of checkpoint, we cache the dirty pages of PVM into this ram cache firstly, so this ram cache always the same as PVM's memory at every checkpoint, then we flush this cached ram to SVM after we receive all PVM's state.

---
v12:
- Fix minor error in error_report (Dave's comment)
- Add Reviewed-by tag
v11:
- Rename 'host_cache' to 'colo_cache' (Dave's suggestion) v10:
- Split the process of dirty pages recording into a new patch

---
 include/exec/ram_addr.h       |  1 +
 include/migration/migration.h |  4 +++
 migration/colo.c              | 11 +++++++
 migration/ram.c               | 73 ++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 88 insertions(+), 1 deletion(-)
include/exec/ram_addr.h +1 -0
index 2a9465d..b4c04fb 100644
@@ -26,6 +26,7 @@ struct RAMBlock {
     struct rcu_head rcu;
     struct MemoryRegion *mr;
     uint8_t *host;
+    uint8_t *colo_cache; /* For colo, VM's ram cache */
     ram_addr_t offset;
     ram_addr_t used_length;
     ram_addr_t max_length;
include/migration/migration.h +4 -0
index 55a2df6..5cd1ff1 100644
@@ -360,4 +360,8 @@ int ram_save_queue_pages(MigrationState *ms, const char *rbname,
 PostcopyState postcopy_state_get(void);
 /* Set the state and return the old state */
 PostcopyState postcopy_state_set(PostcopyState new_state);
+
+/* ram cache */
+int colo_init_ram_cache(void);
+void colo_release_ram_cache(void);
 #endif
migration/colo.c +11 -0
index 8ef1a22..aa8c7e1 100644
@@ -287,6 +287,7 @@ void *colo_process_incoming_thread(void *opaque)
 {
     MigrationIncomingState *mis = opaque;
     Error *local_err = NULL;
+    int ret;
 
     migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
                       MIGRATION_STATUS_COLO);
@@ -303,6 +304,12 @@ void *colo_process_incoming_thread(void *opaque)
      */
     qemu_file_set_blocking(mis->from_src_file, true);
 
+    ret = colo_init_ram_cache();
+    if (ret < 0) {
+        error_report("Failed to initialize ram cache");
+        goto out;
+    }
+
     colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY,
                       &local_err);
     if (local_err) {
@@ -353,6 +360,10 @@ out:
         error_report_err(local_err);
     }
 
+    qemu_mutex_lock_iothread();
+    colo_release_ram_cache();
+    qemu_mutex_unlock_iothread();
+
     if (mis->to_src_file) {
         qemu_fclose(mis->to_src_file);
     }
migration/ram.c +72 -1

97 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#11 lore raw

PATCH v17 11/34 ram/COLO: Record the dirty pages that SVM received

In reply to zhanghailiang

We record the address of the dirty pages that received, it will help flushing pages that cached into SVM. We record them by re-using migration dirty bitmap.

---
v16:
- Use the new wrapper memory_region_get_ram_addr() modified in commit 7ebb2745 v12:
- Add Reviewed-by tag
v11:
- Split a new helper function from original host_from_stream_offset() (Dave's suggestion)
- Only do recording work in this patch
v10:
- New patch split from v9's patch 13
- Rebase to master to use 'migration_bitmap_rcu'

---
 migration/ram.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
migration/ram.c +30 -0
index 327e872..13e28c7 100644
@@ -2196,6 +2196,9 @@ static inline void *host_from_ram_block_offset(RAMBlock *block,
 static inline void *colo_cache_from_block_offset(RAMBlock *block,
                                                  ram_addr_t offset)
 {
+    unsigned long *bitmap;
+    long k;
+
     if (!offset_in_ramblock(block, offset)) {
         return NULL;
     }
@@ -2204,6 +2207,17 @@ static inline void *colo_cache_from_block_offset(RAMBlock *block,
                      __func__, block->idstr);
         return NULL;
     }
+
+    k = (memory_region_get_ram_addr(block->mr) + offset) >> TARGET_PAGE_BITS;
+    bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
+    /*
+    * During colo checkpoint, we need bitmap of these migrated pages.
+    * It help us to decide which pages in ram cache should be flushed
+    * into VM's RAM later.
+    */
+    if (!test_and_set_bit(k, bitmap)) {
+        migration_dirty_pages++;
+    }
     return block->colo_cache + offset;
 }
 
@@ -2590,6 +2604,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
 int colo_init_ram_cache(void)
 {
     RAMBlock *block;
+    int64_t ram_cache_pages = last_ram_offset() >> TARGET_PAGE_BITS;
 
     rcu_read_lock();
     QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
@@ -2604,6 +2619,15 @@ int colo_init_ram_cache(void)
     }
     rcu_read_unlock();
     ram_cache_enable = true;
+    /*
+    * Record the dirty pages that sent by PVM, we use this dirty bitmap together
+    * with to decide which page in cache should be flushed into SVM's RAM. Here
+    * we use the same name 'migration_bitmap_rcu' as for migration.
+    */
+    migration_bitmap_rcu = g_new0(struct BitmapRcu, 1);
+    migration_bitmap_rcu->bmap = bitmap_new(ram_cache_pages);
+    migration_dirty_pages = 0;
+
     return 0;
 
 out_locked:
@@ -2621,9 +2645,15 @@ out_locked:
 void colo_release_ram_cache(void)
 {
     RAMBlock *block;
+    struct BitmapRcu *bitmap = migration_bitmap_rcu;
 
     ram_cache_enable = false;
 
+    atomic_rcu_set(&migration_bitmap_rcu, NULL);
+    if (bitmap) {
+        call_rcu(bitmap, migration_bitmap_free, rcu);
+    }
+
     rcu_read_lock();
     QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
         if (block->colo_cache) {
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH v17 12/34 COLO: Load VMState into buffer before restore it

In reply to zhanghailiang

We should not destroy the state of SVM (Secondary VM) until we receive the whole state from the PVM (Primary VM), 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.

---
v17:
- Replace the old buffer API with the new channel buffer API. v16:
- Rename colo_get_cmd_value() to colo_receive_mesage_value(); v13:
- Fix the define of colo_get_cmd_value() to use 'Error **errp' instead of return value.
v12:
- Use the new helper colo_get_cmd_value() instead of colo_ctl_get()

---
 migration/colo.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 69 insertions(+), 2 deletions(-)
migration/colo.c +69 -2
index aa8c7e1..28aef3f 100644
@@ -115,6 +115,28 @@ static void colo_receive_check_message(QEMUFile *f, COLOMessage expect_msg,
     }
 }
 
+static uint64_t colo_receive_message_value(QEMUFile *f, uint32_t expect_msg,
+                                           Error **errp)
+{
+    Error *local_err = NULL;
+    uint64_t value;
+    int ret;
+
+    colo_receive_check_message(f, expect_msg, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return 0;
+    }
+
+    value = qemu_get_be64(f);
+    ret = qemu_file_get_error(f);
+    if (ret < 0) {
+        error_setg_errno(errp, -ret, "Failed to get value for COLO message: %s",
+                         COLOMessage_lookup[expect_msg]);
+    }
+    return value;
+}
+
 static int colo_do_checkpoint_transaction(MigrationState *s,
                                           QIOChannelBuffer *bioc,
                                           QEMUFile *fb)
@@ -286,6 +308,10 @@ static void colo_wait_handle_message(QEMUFile *f, int *checkpoint_request,
 void *colo_process_incoming_thread(void *opaque)
 {
     MigrationIncomingState *mis = opaque;
+    QEMUFile *fb = NULL;
+    QIOChannelBuffer *bioc = NULL; /* Cache incoming device state */
+    uint64_t total_size;
+    uint64_t value;
     Error *local_err = NULL;
     int ret;
 
@@ -310,6 +336,10 @@ void *colo_process_incoming_thread(void *opaque)
         goto out;
     }
 
+    bioc = qio_channel_buffer_new(COLO_BUFFER_BASE_SIZE);
+    fb = qemu_fopen_channel_input(QIO_CHANNEL(bioc));
+    object_unref(OBJECT(bioc));
+
     colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY,
                       &local_err);
     if (local_err) {
@@ -337,7 +367,31 @@ void *colo_process_incoming_thread(void *opaque)
             goto out;
         }
 
-        /* TODO: read migration data into colo buffer */
+        /* read the VM state total size first */
+        value = colo_receive_message_value(mis->from_src_file,
+                                 COLO_MESSAGE_VMSTATE_SIZE, &local_err);
+        if (local_err) {
+            goto out;
+        }
+
+        /*
+         * Read VM device state data into channel buffer,
+         * It's better to re-use the memory allocated.
+         * Here we need to handle the channel buffer directly.
+         */
+        if (value > bioc->capacity) {
+            bioc->capacity = value;
+            bioc->data = g_realloc(bioc->data, bioc->capacity);
+        }
+        total_size = qemu_get_buffer(mis->from_src_file, bioc->data, value);
+        if (total_size != value) {
+            error_report("Got %lu VMState data, less than expected %lu",
+                         total_size, value);
+            ret = -EINVAL;
+            goto out;
+        }
+        bioc->usage = total_size;
+        qio_channel_io_seek(QIO_CHANNEL(bioc), 0, 0, NULL);
 
         colo_send_message(mis->to_src_file, COLO_MESSAGE_VMSTATE_RECEIVED,
                      &local_err);
@@ -345,7 +399,16 @@ void *colo_process_incoming_thread(void *opaque)
             goto out;
         }
 
-        /* TODO: load vm state */
+        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 */
 
         colo_send_message(mis->to_src_file, COLO_MESSAGE_VMSTATE_LOADED,
                      &local_err);
@@ -360,6 +423,10 @@ out:
         error_report_err(local_err);
     }
 
+    if (fb) {
+        qemu_fclose(fb);
+    }
+
     qemu_mutex_lock_iothread();
     colo_release_ram_cache();
     qemu_mutex_unlock_iothread();
Signature · 1 line
1.8.3.1
#13 lore raw

PATCH v17 13/34 COLO: Flush PVM's cached RAM into SVM's memory

In reply to zhanghailiang

During the time of VM's running, PVM may dirty some pages, we will transfer PVM's dirty pages to SVM and store them into SVM's RAM cache at next checkpoint time. So, the content of SVM's RAM cache will always be same with PVM's memory after checkpoint.

Instead of flushing all content of PVM's RAM cache into SVM's MEMORY, we do this in a more efficient way:
Only flush any page that dirtied by PVM since last checkpoint. In this way, we can ensure SVM's memory same with PVM's.

Besides, we must ensure flush RAM cache before load device state.

---
v12:
- Add a trace point in the end of colo_flush_ram_cache() (Dave's suggestion)
- Add Reviewed-by tag
v11:
- Move the place of 'need_flush' (Dave's suggestion)
- Remove unused 'DPRINTF("Flush ram_cache\n")'
v10:
- trace the number of dirty pages that be received.

---
 include/migration/migration.h |  1 +
 migration/colo.c              |  2 --
 migration/ram.c               | 38 ++++++++++++++++++++++++++++++++++++++
 trace-events                  |  2 ++
 4 files changed, 41 insertions(+), 2 deletions(-)
include/migration/migration.h +1 -0
index 5cd1ff1..566b2a5 100644
@@ -364,4 +364,5 @@ PostcopyState postcopy_state_set(PostcopyState new_state);
 /* ram cache */
 int colo_init_ram_cache(void);
 void colo_release_ram_cache(void);
+void colo_flush_ram_cache(void);
 #endif
migration/colo.c +0 -2
index 28aef3f..396cdcf 100644
@@ -408,8 +408,6 @@ void *colo_process_incoming_thread(void *opaque)
         }
         qemu_mutex_unlock_iothread();
 
-        /* TODO: flush vm state */
-
         colo_send_message(mis->to_src_file, COLO_MESSAGE_VMSTATE_LOADED,
                      &local_err);
         if (local_err) {
migration/ram.c +38 -0
index 13e28c7..91d1287 100644
@@ -2466,6 +2466,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
      * be atomic
      */
     bool postcopy_running = postcopy_state_get() >= POSTCOPY_INCOMING_LISTENING;
+    bool need_flush = false;
 
     seq_iter++;
 
@@ -2500,6 +2501,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             /* After going into COLO, we should load the Page into colo_cache */
             if (ram_cache_enable) {
                 host = colo_cache_from_block_offset(block, addr);
+                need_flush = true;
             } else {
                 host = host_from_ram_block_offset(block, addr);
             }
@@ -2592,6 +2594,10 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
     }
 
     rcu_read_unlock();
+
+    if (!ret  && ram_cache_enable && need_flush) {
+        colo_flush_ram_cache();
+    }
     DPRINTF("Completed load of VM with exit code %d seq iteration "
             "%" PRIu64 "\n", ret, seq_iter);
     return ret;
@@ -2664,6 +2670,38 @@ void colo_release_ram_cache(void)
     rcu_read_unlock();
 }
 
+/*
+ * Flush content of RAM cache into SVM's memory.
+ * Only flush the pages that be dirtied by PVM or SVM or both.
+ */
+void colo_flush_ram_cache(void)
+{
+    RAMBlock *block = NULL;
+    void *dst_host;
+    void *src_host;
+    ram_addr_t offset = 0;
+
+    trace_colo_flush_ram_cache_begin(migration_dirty_pages);
+    rcu_read_lock();
+    block = QLIST_FIRST_RCU(&ram_list.blocks);
+    while (block) {
+        ram_addr_t ram_addr_abs;
+        offset = migration_bitmap_find_dirty(block, offset, &ram_addr_abs);
+        migration_bitmap_clear_dirty(ram_addr_abs);
+        if (offset >= block->used_length) {
+            offset = 0;
+            block = QLIST_NEXT_RCU(block, next);
+        } else {
+            dst_host = block->host + offset;
+            src_host = block->colo_cache + offset;
+            memcpy(dst_host, src_host, TARGET_PAGE_SIZE);
+        }
+    }
+    rcu_read_unlock();
+    trace_colo_flush_ram_cache_end();
+    assert(migration_dirty_pages == 0);
+}
+
 static SaveVMHandlers savevm_ram_handlers = {
     .save_live_setup = ram_save_setup,
     .save_live_iterate = ram_save_iterate,
trace-events +2 -0
index 1dd4344..b58adc3 100644
@@ -1286,6 +1286,8 @@ migration_throttle(void) ""
 ram_load_postcopy_loop(uint64_t addr, int flags) "@%" PRIx64 " %x"
 ram_postcopy_send_discard_bitmap(void) ""
 ram_save_queue_pages(const char *rbname, size_t start, size_t len) "%s: start: %zx len: %zx"
+colo_flush_ram_cache_begin(uint64_t dirty_pages) "dirty_pages %" PRIu64
+colo_flush_ram_cache_end(void) ""
 
 # hw/display/qxl.c
 disable qxl_interface_set_mm_time(int qid, uint32_t mm_time) "%d %d"
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH v17 14/34 COLO: Add checkpoint-delay parameter for migrate-set-parameters

In reply to zhanghailiang

Add checkpoint-delay parameter for migrate-set-parameters, so that we can control the checkpoint frequency when COLO is in periodic mode.

---
v12:
- Change checkpoint-delay to x-checkpoint-delay (Dave's suggestion)
- Add Reviewed-by tag
v11:
- Move this patch ahead of the patch where uses 'checkpoint_delay' (Dave's suggestion)
v10:
- Fix related qmp command

---
 hmp.c                 |  7 +++++++
 migration/migration.c | 18 ++++++++++++++++++
 qapi-schema.json      | 17 ++++++++++++++---
 qmp-commands.hx       |  3 ++-
 4 files changed, 41 insertions(+), 4 deletions(-)
hmp.c +7 -0
index a4b1d3d..05174b9 100644
@@ -300,6 +300,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, " %s: '%s'",
             MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME],
             params->tls_hostname ? : "");
+        monitor_printf(mon, " %s: %" PRId64,
+            MigrationParameter_lookup[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY],
+            params->x_checkpoint_delay);
         monitor_printf(mon, "\n");
     }
 
@@ -1260,6 +1263,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     bool has_tls_creds = false;
     bool has_tls_hostname = false;
     bool use_int_value = false;
+    bool has_x_checkpoint_delay = false;
     int i;
 
     for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
@@ -1283,6 +1287,8 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
                 break;
             case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
                 has_cpu_throttle_increment = true;
+            case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
+                has_x_checkpoint_delay = true;
                 break;
             case MIGRATION_PARAMETER_TLS_CREDS:
                 has_tls_creds = true;
@@ -1307,6 +1313,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
                                        has_cpu_throttle_increment, valueint,
                                        has_tls_creds, valuestr,
                                        has_tls_hostname, valuestr,
+                                       has_x_checkpoint_delay, valueint,
                                        &err);
             break;
         }
migration/migration.c +18 -0
index 71a81fb..8d735fc 100644
@@ -59,6 +59,11 @@
 /* Migration XBZRLE default cache size */
 #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
 
+/* The delay time (in ms) between two COLO checkpoints
+ * Note: Please change this default value to 10000 when we support hybrid mode.
+ */
+#define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY 200
+
 static NotifierList migration_state_notifiers =
     NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
 
@@ -90,6 +95,7 @@ MigrationState *migrate_get_current(void)
             .decompress_threads = DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT,
             .cpu_throttle_initial = DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL,
             .cpu_throttle_increment = DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT,
+            .x_checkpoint_delay = DEFAULT_MIGRATE_X_CHECKPOINT_DELAY,
         },
     };
 
@@ -582,6 +588,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
     params->tls_creds = g_strdup(s->parameters.tls_creds);
     params->tls_hostname = g_strdup(s->parameters.tls_hostname);
+    params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
 
     return params;
 }
@@ -799,6 +806,8 @@ void qmp_migrate_set_parameters(bool has_compress_level,
                                 const char *tls_creds,
                                 bool has_tls_hostname,
                                 const char *tls_hostname,
+                                bool has_x_checkpoint_delay,
+                                int64_t x_checkpoint_delay,
                                 Error **errp)
 {
     MigrationState *s = migrate_get_current();
@@ -834,6 +843,11 @@ void qmp_migrate_set_parameters(bool has_compress_level,
                    "cpu_throttle_increment",
                    "an integer in the range of 1 to 99");
     }
+    if (has_x_checkpoint_delay && (x_checkpoint_delay < 0)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                    "x_checkpoint_delay",
+                    "is invalid, it should be positive");
+    }
 
     if (has_compress_level) {
         s->parameters.compress_level = compress_level;
@@ -858,6 +872,10 @@ void qmp_migrate_set_parameters(bool has_compress_level,
         g_free(s->parameters.tls_hostname);
         s->parameters.tls_hostname = g_strdup(tls_hostname);
     }
+
+    if (has_x_checkpoint_delay) {
+        s->parameters.x_checkpoint_delay = x_checkpoint_delay;
+    }
 }
 
 
qapi-schema.json +14 -3
index 724bcf7..08e64fe 100644
@@ -642,12 +642,16 @@
 #                hostname must be provided so that the server's x509
 #                certificate identity canbe validated. (Since 2.7)
 #
+# @x-checkpoint-delay: The delay time (in ms) between two COLO checkpoints in
+#          periodic mode. (Since 2.7)
+#
 # Since: 2.4
 ##
 { 'enum': 'MigrationParameter',
   'data': ['compress-level', 'compress-threads', 'decompress-threads',
            'cpu-throttle-initial', 'cpu-throttle-increment',
-           'tls-creds', 'tls-hostname'] }
+           'tls-creds', 'tls-hostname',
+           'x-checkpoint-delay' ] }
 
 #
 # @migrate-set-parameters
@@ -683,6 +687,8 @@
 #                hostname must be provided so that the server's x509
 #                certificate identity canbe validated. (Since 2.7)
 #
+# @x-checkpoint-delay: the delay time between two checkpoints. (Since 2.7)
+#
 # Since: 2.4
 ##
 { 'command': 'migrate-set-parameters',
@@ -692,7 +698,8 @@
             '*cpu-throttle-initial': 'int',
             '*cpu-throttle-increment': 'int',
             '*tls-creds': 'str',
-            '*tls-hostname': 'str'} }
+            '*tls-hostname': 'str',
+            '*x-checkpoint-delay': 'int' } }
 
 #
 # @MigrationParameters
@@ -726,6 +733,8 @@
 #                hostname must be provided so that the server's x509
 #                certificate identity canbe validated. (Since 2.6)
 #
+# @x-checkpoint-delay: the delay time between two COLO checkpoints. (Since 2.7)
+#
 # Since: 2.4
 ##
 { 'struct': 'MigrationParameters',
@@ -735,7 +744,9 @@
             'cpu-throttle-initial': 'int',
             'cpu-throttle-increment': 'int',
             'tls-creds': 'str',
-            'tls-hostname': 'str'} }
+            'tls-hostname': 'str',
+            'x-checkpoint-delay': 'int'} }
+
 ##
 # @query-migrate-parameters
 #
qmp-commands.hx +2 -1
index 34d82c3..e70eae5 100644
@@ -3751,6 +3751,7 @@ Set migration parameters
                           throttled for auto-converge (json-int)
 - "cpu-throttle-increment": set throttle increasing percentage for
                             auto-converge (json-int)
+- "x-checkpoint-delay": set the delay time for periodic checkpoint (json-int)
 
 Arguments:
 
@@ -3764,7 +3765,7 @@ EQMP
     {
         .name       = "migrate-set-parameters",
         .args_type  =
-            "compress-level:i?,compress-threads:i?,decompress-threads:i?,cpu-throttle-initial:i?,cpu-throttle-increment:i?",
+            "compress-level:i?,compress-threads:i?,decompress-threads:i?,cpu-throttle-initial:i?,cpu-throttle-increment:i?,x-checkpoint-delay:i?",
         .mhandler.cmd_new = qmp_marshal_migrate_set_parameters,
     },
 SQMP
Signature · 1 line
1.8.3.1
#15 lore raw

PATCH v17 15/34 COLO: Synchronize PVM's state to SVM periodically

In reply to zhanghailiang

Do checkpoint periodically, the default interval is 200ms.

---
v12:
- Add Reviewed-by tag
v11:
- Fix wrong sleep time for checkpoint period. (Dave's comment)

---
 migration/colo.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
migration/colo.c +12 -0
index 396cdcf..47718e7 100644
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 #include "migration/colo.h"
 #include "io/channel-buffer.h"
@@ -226,6 +227,7 @@ static void colo_process_checkpoint(MigrationState *s)
 {
     QIOChannelBuffer *bioc;
     QEMUFile *fb = NULL;
+    int64_t current_time, checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
     Error *local_err = NULL;
     int ret;
 
@@ -254,10 +256,20 @@ static void colo_process_checkpoint(MigrationState *s)
     trace_colo_vm_state_change("stop", "run");
 
     while (s->state == MIGRATION_STATUS_COLO) {
+        current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
+        if (current_time - checkpoint_time <
+            s->parameters.x_checkpoint_delay) {
+            int64_t delay_ms;
+
+            delay_ms = s->parameters.x_checkpoint_delay -
+                       (current_time - checkpoint_time);
+            g_usleep(delay_ms * 1000);
+        }
         ret = colo_do_checkpoint_transaction(s, bioc, fb);
         if (ret < 0) {
             goto out;
         }
+        checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
     }
 
 out:
Signature · 1 line
1.8.3.1
#16 lore raw

PATCH v17 16/34 COLO failover: Introduce a new command to trigger a failover

In reply to zhanghailiang

We leave users to choose whatever heartbeat solution they want, if the heartbeat is lost, or other errors they detect, they can use experimental command 'x_colo_lost_heartbeat' to tell COLO to do failover, COLO will do operations accordingly.

For example, if the command is sent to the PVM, the Primary side will exit COLO mode and take over operation. If sent to the Secondary, the secondary will run failover work, then take over server operation to become the new Primary.

---
v16:
- Fix compile broken due to missing osdep.h
v13:
- Add Reviewed-by tag
v11:
- Add more comments for x-colo-lost-heartbeat command (Eric's suggestion)
- Return 'enum' instead of 'int' for get_colo_mode() (Eric's suggestion) v10:
- Rename command colo_lost_hearbeat to experimental 'x_colo_lost_heartbeat'

---
 hmp-commands.hx              | 15 +++++++++++++++
 hmp.c                        |  8 ++++++++
 hmp.h                        |  1 +
 include/migration/colo.h     |  3 +++
 include/migration/failover.h | 20 ++++++++++++++++++++
 migration/Makefile.objs      |  2 +-
 migration/colo-comm.c        | 11 +++++++++++
 migration/colo-failover.c    | 42 ++++++++++++++++++++++++++++++++++++++++++
 migration/colo.c             |  1 +
 qapi-schema.json             | 29 +++++++++++++++++++++++++++++
 qmp-commands.hx              | 19 +++++++++++++++++++
 stubs/migration-colo.c       |  8 ++++++++
 12 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 include/migration/failover.h
 create mode 100644 migration/colo-failover.c
hmp-commands.hx +15 -0
index 98b4b1a..4ea22a2 100644
@@ -1039,6 +1039,21 @@ migration (or once already in postcopy).
 ETEXI
 
     {
+        .name       = "x_colo_lost_heartbeat",
+        .args_type  = "",
+        .params     = "",
+        .help       = "Tell COLO that heartbeat is lost,\n\t\t\t"
+                      "a failover or takeover is needed.",
+        .mhandler.cmd = hmp_x_colo_lost_heartbeat,
+    },
+
+STEXI
+@item x_colo_lost_heartbeat
+@findex x_colo_lost_heartbeat
+Tell COLO that heartbeat is lost, a failover or takeover is needed.
+ETEXI
+
+    {
         .name       = "client_migrate_info",
         .args_type  = "protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?",
         .params     = "protocol hostname port tls-port cert-subject",
hmp.c +8 -0
index 05174b9..d03f1a6 100644
@@ -1353,6 +1353,14 @@ void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
     hmp_handle_error(mon, &err);
 }
 
+void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+
+    qmp_x_colo_lost_heartbeat(&err);
+    hmp_handle_error(mon, &err);
+}
+
 void hmp_set_password(Monitor *mon, const QDict *qdict)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
hmp.h +1 -0
index 093d65f..5d979fd 100644
@@ -70,6 +70,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict);
 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict);
 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict);
+void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict);
 void hmp_set_password(Monitor *mon, const QDict *qdict);
 void hmp_expire_password(Monitor *mon, const QDict *qdict);
 void hmp_eject(Monitor *mon, const QDict *qdict);
include/migration/colo.h +3 -0
index b40676c..e9ac2c3 100644
@@ -17,6 +17,7 @@
 #include "migration/migration.h"
 #include "qemu/coroutine_int.h"
 #include "qemu/thread.h"
+#include "qemu/main-loop.h"
 
 bool colo_supported(void);
 void colo_info_init(void);
@@ -29,4 +30,6 @@ bool migration_incoming_enable_colo(void);
 void migration_incoming_exit_colo(void);
 void *colo_process_incoming_thread(void *opaque);
 bool migration_incoming_in_colo_state(void);
+
+COLOMode get_colo_mode(void);
 #endif
include/migration/failover.h new file +20 -0
new file mode 100644
index 0000000..3274735
@@ -0,0 +1,20 @@
+/*
+ *  COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
+ *  (a.k.a. Fault Tolerance or Continuous Replication)
+ *
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD.
+ * Copyright (c) 2016 FUJITSU LIMITED
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_FAILOVER_H
+#define QEMU_FAILOVER_H
+
+#include "qemu-common.h"
+
+void failover_request_active(Error **errp);
+
+#endif
migration/Makefile.objs +1 -1
index 4bbe9ab..3f3e237 100644
@@ -1,7 +1,7 @@
 common-obj-y += migration.o socket.o fd.o exec.o
 common-obj-y += tls.o
-common-obj-$(CONFIG_COLO) += colo.o
 common-obj-y += colo-comm.o
+common-obj-$(CONFIG_COLO) += colo.o colo-failover.o
 common-obj-y += vmstate.o
 common-obj-y += qemu-file.o
 common-obj-y += qemu-file-channel.o
migration/colo-comm.c +11 -0
index 1a36893..716a4f7 100644
@@ -21,6 +21,17 @@ typedef struct {
 
 static COLOInfo colo_info;
 
+COLOMode get_colo_mode(void)
+{
+    if (migration_in_colo_state()) {
+        return COLO_MODE_PRIMARY;
+    } else if (migration_incoming_in_colo_state()) {
+        return COLO_MODE_SECONDARY;
+    } else {
+        return COLO_MODE_UNKNOWN;
+    }
+}
+
 static void colo_info_pre_save(void *opaque)
 {
     COLOInfo *s = opaque;
migration/colo-failover.c new file +42 -0

42 lines not on this page · raw message

migration/colo.c +1 -0
index 47718e7..c087be8 100644
@@ -18,6 +18,7 @@
 #include "trace.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
+#include "migration/failover.h"
 
 #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)
 
qapi-schema.json +29 -0
index 08e64fe..07d3fcb 100644
@@ -814,6 +814,35 @@
             'vmstate-send', 'vmstate-size', 'vmstate-received',
             'vmstate-loaded' ] }
 
+##
+# @COLOMode
+#
+# The colo mode
+#
+# @unknown: unknown mode
+#
+# @primary: master side
+#
+# @secondary: slave side
+#
+# Since: 2.7
+##
+{ 'enum': 'COLOMode',
+  'data': [ 'unknown', 'primary', 'secondary'] }
+
+##
+# @x-colo-lost-heartbeat
+#
+# Tell qemu that heartbeat is lost, request it to do takeover procedures.
+# If this command is sent to the PVM, the Primary side will exit COLO mode.
+# If sent to the Secondary, the Secondary side will run failover work,
+# then takes over server operation to become the service VM.
+#
+# Since: 2.7
+##
+{ 'command': 'x-colo-lost-heartbeat' }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +19 -0
index e70eae5..4f6efdd 100644
@@ -803,6 +803,25 @@ Example:
 EQMP
 
     {
+        .name       = "x-colo-lost-heartbeat",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_x_colo_lost_heartbeat,
+    },
+
+SQMP
+x-colo-lost-heartbeat
+--------------------
+
+Tell COLO that heartbeat is lost, a failover or takeover is needed.
+
+Example:
+
+-> { "execute": "x-colo-lost-heartbeat" }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "client_migrate_info",
         .args_type  = "protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?",
         .params     = "protocol hostname port tls-port cert-subject",
stubs/migration-colo.c +8 -0
index 7b72395..7811764 100644
@@ -12,6 +12,7 @@
 
 #include "qemu/osdep.h"
 #include "migration/colo.h"
+#include "qmp-commands.h"
 
 bool colo_supported(void)
 {
@@ -36,3 +37,10 @@ void *colo_process_incoming_thread(void *opaque)
 {
     return NULL;
 }
+
+void qmp_x_colo_lost_heartbeat(Error **errp)
+{
+    error_setg(errp, "COLO is not supported, please rerun configure"
+                     " with --enable-colo option in order to support"
+                     " COLO feature");
+}
Signature · 1 line
1.8.3.1
#17 lore raw

PATCH v17 17/34 COLO failover: Introduce state to record failover process

In reply to zhanghailiang

When handling failover, we do different things according to the different stage of failover process, here we introduce a global atomic variable to record the status of failover.

We add four failover status to indicate the different stage of failover process. You should use the helpers to get and set the value.

---
v11:
- fix several typos found by Dave
- Add Reviewed-by tag

---
 include/migration/failover.h | 10 ++++++++++
 migration/colo-failover.c    | 37 +++++++++++++++++++++++++++++++++++++
 migration/colo.c             |  4 ++++
 trace-events                 |  1 +
 4 files changed, 52 insertions(+)
include/migration/failover.h +10 -0
index 3274735..fe71bb4 100644
@@ -15,6 +15,16 @@
 
 #include "qemu-common.h"
 
+typedef enum COLOFailoverStatus {
+    FAILOVER_STATUS_NONE = 0,
+    FAILOVER_STATUS_REQUEST = 1, /* Request but not handled */
+    FAILOVER_STATUS_HANDLING = 2, /* In the process of handling failover */
+    FAILOVER_STATUS_COMPLETED = 3, /* Finish the failover process */
+} COLOFailoverStatus;
+
+void failover_init_state(void);
+int failover_set_state(int old_state, int new_state);
+int failover_get_state(void);
 void failover_request_active(Error **errp);
 
 #endif
migration/colo-failover.c +37 -0
index 413675d..69aac55 100644
@@ -15,22 +15,59 @@
 #include "migration/failover.h"
 #include "qmp-commands.h"
 #include "qapi/qmp/qerror.h"
+#include "qemu/error-report.h"
+#include "trace.h"
 
 static QEMUBH *failover_bh;
+static COLOFailoverStatus failover_state;
 
 static void colo_failover_bh(void *opaque)
 {
+    int old_state;
+
     qemu_bh_delete(failover_bh);
     failover_bh = NULL;
+    old_state = failover_set_state(FAILOVER_STATUS_REQUEST,
+                                   FAILOVER_STATUS_HANDLING);
+    if (old_state != FAILOVER_STATUS_REQUEST) {
+        error_report("Unkown error for failover, old_state=%d", old_state);
+        return;
+    }
     /*TODO: Do failover work */
 }
 
 void failover_request_active(Error **errp)
 {
+   if (failover_set_state(FAILOVER_STATUS_NONE, FAILOVER_STATUS_REQUEST)
+         != FAILOVER_STATUS_NONE) {
+        error_setg(errp, "COLO failover is already actived");
+        return;
+    }
     failover_bh = qemu_bh_new(colo_failover_bh, NULL);
     qemu_bh_schedule(failover_bh);
 }
 
+void failover_init_state(void)
+{
+    failover_state = FAILOVER_STATUS_NONE;
+}
+
+int failover_set_state(int old_state, int new_state)
+{
+    int old;
+
+    old = atomic_cmpxchg(&failover_state, old_state, new_state);
+    if (old == old_state) {
+        trace_colo_failover_set_state(new_state);
+    }
+    return old;
+}
+
+int failover_get_state(void)
+{
+    return atomic_read(&failover_state);
+}
+
 void qmp_x_colo_lost_heartbeat(Error **errp)
 {
     if (get_colo_mode() == COLO_MODE_UNKNOWN) {
migration/colo.c +4 -0
index c087be8..f98d7fb 100644
@@ -232,6 +232,8 @@ static void colo_process_checkpoint(MigrationState *s)
     Error *local_err = NULL;
     int ret;
 
+    failover_init_state();
+
     s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file);
     if (!s->rp_state.from_dst_file) {
         error_report("Open QEMUFile from_dst_file failed");
@@ -331,6 +333,8 @@ void *colo_process_incoming_thread(void *opaque)
     migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
                       MIGRATION_STATUS_COLO);
 
+    failover_init_state();
+
     mis->to_src_file = qemu_file_get_return_path(mis->from_src_file);
     if (!mis->to_src_file) {
         error_report("colo incoming thread: Open QEMUFile to_src_file failed");
trace-events +1 -0
index b58adc3..380276c 100644
@@ -1626,6 +1626,7 @@ migration_tls_incoming_handshake_complete(void) ""
 colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'"
 colo_send_message(const char *msg) "Send '%s' message"
 colo_receive_message(const char *msg) "Receive '%s' message"
+colo_failover_set_state(int new_state) "new state %d"
 
 # kvm-all.c
 kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"
Signature · 1 line
1.8.3.1
#18 lore raw

PATCH v17 18/34 COLO: Implement failover work for Primary VM

In reply to zhanghailiang

For PVM, if there is failover request from users.
The COLO thread will exit the loop while the failover BH does the cleanup work and resumes VM.

---
v13:
- Add Reviewed-by tag
v12:
- Fix error report and remove unnecessary check in primary_vm_do_failover() (Dave's suggestion)
v11:
- Don't call migration_end() in primary_vm_do_failover(), The cleanup work will be done in migration_thread().
- Remove vm_start() in primary_vm_do_failover() which also been done in migraiton_thread()
v10:
- Call migration_end() in primary_vm_do_failover()

---
 include/migration/colo.h     |  3 +++
 include/migration/failover.h |  1 +
 migration/colo-failover.c    |  7 +++++-
 migration/colo.c             | 54 ++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 62 insertions(+), 3 deletions(-)
include/migration/colo.h +3 -0
index e9ac2c3..e32eef4 100644
@@ -32,4 +32,7 @@ void *colo_process_incoming_thread(void *opaque);
 bool migration_incoming_in_colo_state(void);
 
 COLOMode get_colo_mode(void);
+
+/* failover */
+void colo_do_failover(MigrationState *s);
 #endif
include/migration/failover.h +1 -0
index fe71bb4..c4bd81e 100644
@@ -26,5 +26,6 @@ void failover_init_state(void);
 int failover_set_state(int old_state, int new_state);
 int failover_get_state(void);
 void failover_request_active(Error **errp);
+bool failover_request_is_active(void);
 
 #endif
migration/colo-failover.c +6 -1
index 69aac55..fa84172 100644
@@ -33,7 +33,7 @@ static void colo_failover_bh(void *opaque)
         error_report("Unkown error for failover, old_state=%d", old_state);
         return;
     }
-    /*TODO: Do failover work */
+    colo_do_failover(NULL);
 }
 
 void failover_request_active(Error **errp)
@@ -68,6 +68,11 @@ int failover_get_state(void)
     return atomic_read(&failover_state);
 }
 
+bool failover_request_is_active(void)
+{
+    return failover_get_state() != FAILOVER_STATUS_NONE;
+}
+
 void qmp_x_colo_lost_heartbeat(Error **errp)
 {
     if (get_colo_mode() == COLO_MODE_UNKNOWN) {
migration/colo.c +52 -2

82 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#19 lore raw

PATCH v17 19/34 COLO: Implement failover work for Secondary VM

In reply to zhanghailiang

If users require SVM to takeover work, colo incoming thread should exit from loop while failover BH helps backing to migration incoming coroutine.

---
v12:
- Improve error message that suggested by Dave
- Add Reviewed-by tag

---
 migration/colo.c | 42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)
migration/colo.c +39 -3
index 52ab82b..8216c5f 100644
@@ -46,6 +46,33 @@ static bool colo_runstate_is_stopped(void)
     return runstate_check(RUN_STATE_COLO) || !runstate_is_running();
 }
 
+static void secondary_vm_do_failover(void)
+{
+    int old_state;
+    MigrationIncomingState *mis = migration_incoming_get_current();
+
+    migrate_set_state(&mis->state, MIGRATION_STATUS_COLO,
+                      MIGRATION_STATUS_COMPLETED);
+
+    if (!autostart) {
+        error_report("\"-S\" qemu option will be ignored in secondary side");
+        /* recover runstate to normal migration finish state */
+        autostart = true;
+    }
+
+    old_state = failover_set_state(FAILOVER_STATUS_HANDLING,
+                                   FAILOVER_STATUS_COMPLETED);
+    if (old_state != FAILOVER_STATUS_HANDLING) {
+        error_report("Incorrect state (%d) while doing failover for "
+                     "secondary VM", old_state);
+        return;
+    }
+    /* For Secondary VM, jump to incoming co */
+    if (mis->migration_incoming_co) {
+        qemu_coroutine_enter(mis->migration_incoming_co, NULL);
+    }
+}
+
 static void primary_vm_do_failover(void)
 {
     MigrationState *s = migrate_get_current();
@@ -72,6 +99,8 @@ void colo_do_failover(MigrationState *s)
 
     if (get_colo_mode() == COLO_MODE_PRIMARY) {
         primary_vm_do_failover();
+    } else {
+        secondary_vm_do_failover();
     }
 }
 
@@ -421,6 +450,11 @@ void *colo_process_incoming_thread(void *opaque)
             goto out;
         }
         assert(request);
+        if (failover_request_is_active()) {
+            error_report("failover request");
+            goto out;
+        }
+
         /* FIXME: This is unnecessary for periodic checkpoint mode */
         colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_REPLY,
                      &local_err);
@@ -491,10 +525,12 @@ out:
     if (fb) {
         qemu_fclose(fb);
     }
-
-    qemu_mutex_lock_iothread();
+    /*
+     * We can ensure BH is hold the global lock, and will join COLO
+     * incoming thread, so here it is not necessary to lock here again,
+     * Or there will be a deadlock error.
+     */
     colo_release_ram_cache();
-    qemu_mutex_unlock_iothread();
 
     if (mis->to_src_file) {
         qemu_fclose(mis->to_src_file);
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH v17 20/34 qmp event: Add COLO_EXIT event to notify users while exited from COLO

In reply to zhanghailiang

If some errors happen during VM's COLO FT stage, it's important to notify the users of this event. Together with 'x_colo_lost_heartbeat', Users can intervene in COLO's failover work immediately.
If users don't want to get involved in COLO's failover verdict, it is still necessary to notify users that we exited COLO mode.

---
v16:
- fix some minor grammars from Eric
- Add Reviewed-by tag
v13:
- Remove optional 'error' string for this event.
(I doubted it was usefull for users, Since users shouldn't
interpret it and can't depend on it to decide what happened exaclty. Besides it is really hard to organize.)
- Remove unused 'unknown' member for enum COLOExitReason. (Eric's suggestion)
- Fix comment for COLO_EXIT
v11:
- Fix several typos found by Eric

---
 docs/qmp-events.txt | 16 ++++++++++++++++
 migration/colo.c    | 19 +++++++++++++++++++
 qapi-schema.json    | 14 ++++++++++++++
 qapi/event.json     | 15 +++++++++++++++
 4 files changed, 64 insertions(+)
docs/qmp-events.txt +16 -0
index fa7574d..77c634e 100644
@@ -184,6 +184,22 @@ Example:
 Note: The "ready to complete" status is always reset by a BLOCK_JOB_ERROR
 event.
 
+COLO_EXIT
+---------
+
+Emitted when VM finishes COLO mode due to some errors happening or
+at the request of users.
+
+Data:
+
+ - "mode": COLO mode, primary or secondary side (json-string)
+ - "reason": the exit reason, internal error or external request. (json-string)
+
+Example:
+
+{"timestamp": {"seconds": 2032141960, "microseconds": 417172},
+ "event": "COLO_EXIT", "data": {"mode": "primary", "reason": "request" } }
+
 DEVICE_DELETED
 --------------
 
migration/colo.c +19 -0
index 8216c5f..db6534a 100644
@@ -19,6 +19,7 @@
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "migration/failover.h"
+#include "qapi-event.h"
 
 #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)
 
@@ -361,6 +362,17 @@ out:
     }
 
     qemu_fclose(fb);
+    /*
+     * There are only two reasons we can go here, some error happened.
+     * Or the user triggered failover.
+     */
+    if (!failover_request_is_active()) {
+        qapi_event_send_colo_exit(COLO_MODE_PRIMARY,
+                                  COLO_EXIT_REASON_ERROR, NULL);
+    } else {
+        qapi_event_send_colo_exit(COLO_MODE_PRIMARY,
+                                  COLO_EXIT_REASON_REQUEST, NULL);
+    }
 
     if (s->rp_state.from_dst_file) {
         qemu_fclose(s->rp_state.from_dst_file);
@@ -521,6 +533,13 @@ out:
     if (local_err) {
         error_report_err(local_err);
     }
+    if (!failover_request_is_active()) {
+        qapi_event_send_colo_exit(COLO_MODE_SECONDARY,
+                                  COLO_EXIT_REASON_ERROR, NULL);
+    } else {
+        qapi_event_send_colo_exit(COLO_MODE_SECONDARY,
+                                  COLO_EXIT_REASON_REQUEST, NULL);
+    }
 
     if (fb) {
         qemu_fclose(fb);
qapi-schema.json +14 -0
index 07d3fcb..9856567 100644
@@ -831,6 +831,20 @@
   'data': [ 'unknown', 'primary', 'secondary'] }
 
 ##
+# @COLOExitReason
+#
+# The reason for a COLO exit
+#
+# @request: COLO exit is due to an external request
+#
+# @error: COLO exit is due to an internal error
+#
+# Since: 2.7
+##
+{ 'enum': 'COLOExitReason',
+  'data': [ 'request', 'error' ] }
+
+##
 # @x-colo-lost-heartbeat
 #
 # Tell qemu that heartbeat is lost, request it to do takeover procedures.
qapi/event.json +15 -0
index 8642052..09542fa 100644
@@ -268,6 +268,21 @@
   'data': { 'pass': 'int' } }
 
 ##
+# @COLO_EXIT
+#
+# Emitted when VM finishes COLO mode due to some errors happening or
+# at the request of users.
+#
+# @mode: which COLO mode the VM was in when it exited.
+#
+# @reason: describes the reason for the COLO exit.
+#
+# Since: 2.7
+##
+{ 'event': 'COLO_EXIT',
+  'data': {'mode': 'COLOMode', 'reason': 'COLOExitReason' } }
+
+##
 # @ACPI_DEVICE_OST
 #
 # Emitted when guest executes ACPI _OST method.
Signature · 1 line
1.8.3.1
#21 lore raw

PATCH v17 21/34 COLO failover: Shutdown related socket fd when do failover

In reply to zhanghailiang

If the net connection between COLO's two sides is broken while COLO or COLO incoming thread is blocked in read()/write() socket fd. It will not detect this error until connection is timeout. That will be a long time.

Here we shutdown all the related socket file descriptors to wake up the blocking operation in failover BH. Besides, we should close the corresponding file descriptors after failvoer BH shutdown them, or there will be an error.

---
v17:
- Rename colo_sem to colo_exit_sem.
v13:
- Add Reviewed-by tag
- Use semaphore to notify colo/colo incoming loop that failover work is finished.
v12:
- Shutdown both QEMUFile's fd though they may use the same fd. (Dave's suggestion)
v11:
- Only shutdown fd for once

---
 include/migration/migration.h |  3 +++
 migration/colo.c              | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
include/migration/migration.h +3 -0
index 566b2a5..74f49ee 100644
@@ -113,6 +113,7 @@ struct MigrationIncomingState {
     QemuThread colo_incoming_thread;
     /* The coroutine we should enter (back) after failover */
     Coroutine *migration_incoming_co;
+    QemuSemaphore colo_incoming_sem;
 
     /* See savevm.c */
     LoadStateEntry_Head loadvm_handlers;
@@ -181,6 +182,8 @@ struct MigrationState
     QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest) src_page_requests;
     /* The RAMBlock used in the last src_page_request */
     RAMBlock *last_req_rb;
+    /* The semaphore is used to notify COLO thread that failover is finished */
+    QemuSemaphore colo_exit_sem;
 
     /* The last error that occurred */
     Error *error;
migration/colo.c +43 -0

91 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#22 lore raw

PATCH v17 22/34 COLO failover: Don't do failover during loading VM's state

In reply to zhanghailiang

We should not do failover work while the main thread is loading VM's state. Otherwise it will destroy the consistent of VM's memory and device state.

Here we add a new failover status 'RELAUNCH' which means we should relaunch the process of failover.

---
v14:
- Move the place of 'vmstate_loading = false;'.
v13:
- Add Reviewed-by tag

---
 include/migration/failover.h |  2 ++
 migration/colo.c             | 25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
include/migration/failover.h +2 -0
index c4bd81e..99b0d58 100644
@@ -20,6 +20,8 @@ typedef enum COLOFailoverStatus {
     FAILOVER_STATUS_REQUEST = 1, /* Request but not handled */
     FAILOVER_STATUS_HANDLING = 2, /* In the process of handling failover */
     FAILOVER_STATUS_COMPLETED = 3, /* Finish the failover process */
+    /* Optional, Relaunch the failover process, again 'NONE' -> 'COMPLETED' */
+    FAILOVER_STATUS_RELAUNCH = 4,
 } COLOFailoverStatus;
 
 void failover_init_state(void);
migration/colo.c +25 -0
index ff7b77b..dab615b 100644
@@ -21,6 +21,8 @@
 #include "migration/failover.h"
 #include "qapi-event.h"
 
+static bool vmstate_loading;
+
 #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)
 
 bool colo_supported(void)
@@ -52,6 +54,19 @@ static void secondary_vm_do_failover(void)
     int old_state;
     MigrationIncomingState *mis = migration_incoming_get_current();
 
+    /* Can not do failover during the process of VM's loading VMstate, Or
+     * it will break the secondary VM.
+     */
+    if (vmstate_loading) {
+        old_state = failover_set_state(FAILOVER_STATUS_HANDLING,
+                                       FAILOVER_STATUS_RELAUNCH);
+        if (old_state != FAILOVER_STATUS_HANDLING) {
+            error_report("Unknown error while do failover for secondary VM,"
+                         "old_state: %d", old_state);
+        }
+        return;
+    }
+
     migrate_set_state(&mis->state, MIGRATION_STATUS_COLO,
                       MIGRATION_STATUS_COMPLETED);
 
@@ -553,13 +568,22 @@ void *colo_process_incoming_thread(void *opaque)
 
         qemu_mutex_lock_iothread();
         qemu_system_reset(VMRESET_SILENT);
+        vmstate_loading = true;
         if (qemu_loadvm_state(fb) < 0) {
             error_report("COLO: loadvm failed");
             qemu_mutex_unlock_iothread();
             goto out;
         }
+
+        vmstate_loading = false;
         qemu_mutex_unlock_iothread();
 
+        if (failover_get_state() == FAILOVER_STATUS_RELAUNCH) {
+            failover_set_state(FAILOVER_STATUS_RELAUNCH, FAILOVER_STATUS_NONE);
+            failover_request_active(NULL);
+            goto out;
+        }
+
         colo_send_message(mis->to_src_file, COLO_MESSAGE_VMSTATE_LOADED,
                      &local_err);
         if (local_err) {
@@ -568,6 +592,7 @@ void *colo_process_incoming_thread(void *opaque)
     }
 
 out:
+    vmstate_loading = false;
     /* Throw the unreported error message after exited from loop */
     if (local_err) {
         error_report_err(local_err);
Signature · 1 line
1.8.3.1
#23 lore raw

PATCH v17 23/34 COLO: Process shutdown command for VM in COLO state

In reply to zhanghailiang

If VM is in COLO FT state, we should do some extra work before normal shutdown process. SVM will ignore the shutdown command if this command is issued directly to it. PVM will send the shutdown command to SVM if it gets this command.

---
v15:
- Go on the shutdown process even some error happened while sent 'SHUTDOWN' message to SVM.
- Add Reviewed-by tag
v14:
- Remove 'colo_shutdown' variable, use colo_shutdown_request directly v13:
- Move COLO shutdown related codes to colo.c file (Dave's suggestion)

---
 include/migration/colo.h |  2 ++
 include/sysemu/sysemu.h  |  3 +++
 migration/colo.c         | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 qapi-schema.json         |  4 +++-
 stubs/migration-colo.c   |  5 +++++
 vl.c                     | 19 ++++++++++++++++---
 6 files changed, 74 insertions(+), 6 deletions(-)
include/migration/colo.h +2 -0
index e32eef4..b16c642 100644
@@ -35,4 +35,6 @@ COLOMode get_colo_mode(void);
 
 /* failover */
 void colo_do_failover(MigrationState *s);
+
+bool colo_handle_shutdown(void);
 #endif
include/sysemu/sysemu.h +3 -0
index 9428141..b80e145 100644
@@ -51,6 +51,8 @@ typedef enum WakeupReason {
     QEMU_WAKEUP_REASON_OTHER,
 } WakeupReason;
 
+extern int colo_shutdown_requested;
+
 void qemu_system_reset_request(void);
 void qemu_system_suspend_request(void);
 void qemu_register_suspend_notifier(Notifier *notifier);
@@ -58,6 +60,7 @@ void qemu_system_wakeup_request(WakeupReason reason);
 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
 void qemu_register_wakeup_notifier(Notifier *notifier);
 void qemu_system_shutdown_request(void);
+void qemu_system_shutdown_request_core(void);
 void qemu_system_powerdown_request(void);
 void qemu_register_powerdown_notifier(Notifier *notifier);
 void qemu_system_debug_request(void);
migration/colo.c +45 -2

68 lines not on this page · raw message

qapi-schema.json +3 -1
index 9856567..a43ebcf 100644
@@ -807,12 +807,14 @@
 #
 # @vmstate-loaded: VM's state has been loaded by SVM.
 #
+# @guest-shutdown: shutdown require from PVM to SVM
+#
 # Since: 2.7
 ##
 { 'enum': 'COLOMessage',
   'data': [ 'checkpoint-ready', 'checkpoint-request', 'checkpoint-reply',
             'vmstate-send', 'vmstate-size', 'vmstate-received',
-            'vmstate-loaded' ] }
+            'vmstate-loaded', 'guest-shutdown' ] }
 
 ##
 # @COLOMode
stubs/migration-colo.c +5 -0
index 7811764..167b191 100644
@@ -44,3 +44,8 @@ void qmp_x_colo_lost_heartbeat(Error **errp)
                      " with --enable-colo option in order to support"
                      " COLO feature");
 }
+
+bool colo_handle_shutdown(void)
+{
+    return false;
+}
vl.c +16 -3
index 47ca1c1..e058e03 100644
@@ -1646,6 +1646,8 @@ static NotifierList wakeup_notifiers =
     NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
 static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE);
 
+int colo_shutdown_requested;
+
 int qemu_shutdown_requested_get(void)
 {
     return shutdown_requested;
@@ -1779,7 +1781,10 @@ void qemu_system_guest_panicked(void)
 void qemu_system_reset_request(void)
 {
     if (no_reboot) {
-        shutdown_requested = 1;
+        qemu_system_shutdown_request();
+        if (!shutdown_requested) {/* colo handle it ? */
+            return;
+        }
     } else {
         reset_requested = 1;
     }
@@ -1852,14 +1857,22 @@ void qemu_system_killed(int signal, pid_t pid)
     qemu_notify_event();
 }
 
-void qemu_system_shutdown_request(void)
+void qemu_system_shutdown_request_core(void)
 {
-    trace_qemu_system_shutdown_request();
     replay_shutdown_request();
     shutdown_requested = 1;
     qemu_notify_event();
 }
 
+void qemu_system_shutdown_request(void)
+{
+    trace_qemu_system_shutdown_request();
+    if (colo_handle_shutdown()) {
+        return;
+    }
+    qemu_system_shutdown_request_core();
+}
+
 static void qemu_system_powerdown(void)
 {
     qapi_event_send_powerdown(&error_abort);
Signature · 1 line
1.8.3.1
#24 lore raw

PATCH v17 24/34 COLO: Update the global runstate after going into colo state

In reply to zhanghailiang

If we start qemu with -S, the runstate will change from 'prelaunch' to 'running' after going into colo state.
So it is necessary to update the global runstate after going into colo state.

---
v13:
- Add Reviewed-by tag

---
 migration/colo.c | 5 +++++
 1 file changed, 5 insertions(+)
migration/colo.c +5 -0
index 55c8d35..16f402f 100644
@@ -391,6 +391,11 @@ static void colo_process_checkpoint(MigrationState *s)
     qemu_mutex_unlock_iothread();
     trace_colo_vm_state_change("stop", "run");
 
+    ret = global_state_store();
+    if (ret < 0) {
+        goto out;
+    }
+
     while (s->state == MIGRATION_STATUS_COLO) {
         if (failover_request_is_active()) {
             error_report("failover request");
Signature · 1 line
1.8.3.1
#25 lore raw

PATCH v17 25/34 savevm: Introduce two helper functions for save/find loadvm_handlers entry

In reply to zhanghailiang

For COLO's checkpoint process, we will do savevm/loadvm repeatedly. So every time we call qemu_loadvm_section_start_full(), we will add all sections information into loadvm_handlers list for one time. There will be many instances in loadvm_handlers for one section, and this will lead to memory leak.

We need to check if we have the section info in loadvm_handlers list before save it. For normal migration, it is harmless.

---
v14:
- Add Reviewed-by tag
-
v13:
- New patch

---
 migration/savevm.c | 56 ++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 40 insertions(+), 16 deletions(-)
migration/savevm.c +40 -16
index 6c21231..fd3032d 100644
@@ -1718,6 +1718,37 @@ void loadvm_free_handlers(MigrationIncomingState *mis)
     }
 }
 
+static LoadStateEntry *loadvm_save_section_entry(MigrationIncomingState *mis,
+                                                 SaveStateEntry *se,
+                                                 uint32_t section_id,
+                                                 uint32_t version_id)
+{
+    LoadStateEntry *le;
+
+    /* Add entry */
+    le = g_malloc0(sizeof(*le));
+
+    le->se = se;
+    le->section_id = section_id;
+    le->version_id = version_id;
+    QLIST_INSERT_HEAD(&mis->loadvm_handlers, le, entry);
+    return le;
+}
+
+static LoadStateEntry *loadvm_find_section_entry(MigrationIncomingState *mis,
+                                                 uint32_t section_id)
+{
+    LoadStateEntry *le;
+
+    QLIST_FOREACH(le, &mis->loadvm_handlers, entry) {
+        if (le->section_id == section_id) {
+            break;
+        }
+    }
+
+    return le;
+}
+
 static int
 qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis)
 {
@@ -1753,16 +1784,12 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis)
                      version_id, idstr, se->version_id);
         return -EINVAL;
     }
-
-    /* Add entry */
-    le = g_malloc0(sizeof(*le));
-
-    le->se = se;
-    le->section_id = section_id;
-    le->version_id = version_id;
-    QLIST_INSERT_HEAD(&mis->loadvm_handlers, le, entry);
-
-    ret = vmstate_load(f, le->se, le->version_id);
+     /* Check if we have saved this section info before, if not, save it */
+    le = loadvm_find_section_entry(mis, section_id);
+    if (!le) {
+        le = loadvm_save_section_entry(mis, se, section_id, version_id);
+    }
+    ret = vmstate_load(f, se, version_id);
     if (ret < 0) {
         error_report("error while loading state for instance 0x%x of"
                      " device '%s'", instance_id, idstr);
@@ -1785,12 +1812,9 @@ qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis)
     section_id = qemu_get_be32(f);
 
     trace_qemu_loadvm_state_section_partend(section_id);
-    QLIST_FOREACH(le, &mis->loadvm_handlers, entry) {
-        if (le->section_id == section_id) {
-            break;
-        }
-    }
-    if (le == NULL) {
+
+    le = loadvm_find_section_entry(mis, section_id);
+    if (!le) {
         error_report("Unknown savevm section %d", section_id);
         return -EINVAL;
     }
Signature · 1 line
1.8.3.1
#26 lore raw

PATCH v17 26/34 migration/savevm: Add new helpers to process the different stages of loadvm

In reply to zhanghailiang

There are several stages during loadvm process. In different stage, migration incoming processes different section.
We want to control these stages more accuracy, to optimize the COLO capability.

Here we add two new helper functions: qemu_loadvm_state_begin() and qemu_load_device_state().
Besides, we make qemu_loadvm_state_main() API public.

---
v16:
- Add Reviewed-by
v14:
- Split from patch 'COLO: Separate the process of saving/loading ram and device state

---
 include/sysemu/sysemu.h |  3 +++
 migration/savevm.c      | 38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 38 insertions(+), 3 deletions(-)
include/sysemu/sysemu.h +3 -0
index b80e145..2b44981 100644
@@ -133,6 +133,9 @@ void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f, const char *name,
                                            uint64_t *length_list);
 
 int qemu_loadvm_state(QEMUFile *f);
+int qemu_loadvm_state_begin(QEMUFile *f);
+int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
+int qemu_load_device_state(QEMUFile *f);
 
 extern int autostart;
 
migration/savevm.c +35 -3
index fd3032d..98abb5c 100644
@@ -1235,8 +1235,6 @@ enum LoadVMExitCodes {
     LOADVM_QUIT     =  1,
 };
 
-static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
-
 /* ------ incoming postcopy messages ------ */
 /* 'advise' arrives before any transfers just to tell us that a postcopy
  * *might* happen - it might be skipped if precopy transferred everything
@@ -1832,7 +1830,7 @@ qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis)
     return 0;
 }
 
-static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis)
+int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis)
 {
     uint8_t section_type;
     int ret;
@@ -1965,6 +1963,40 @@ int qemu_loadvm_state(QEMUFile *f)
     return ret;
 }
 
+int qemu_loadvm_state_begin(QEMUFile *f)
+{
+    MigrationIncomingState *mis = migration_incoming_get_current();
+    Error *local_err = NULL;
+    int ret;
+
+    if (qemu_savevm_state_blocked(&local_err)) {
+        error_report_err(local_err);
+        return -EINVAL;
+    }
+    /* Load QEMU_VM_SECTION_START section */
+    ret = qemu_loadvm_state_main(f, mis);
+    if (ret < 0) {
+        error_report("Failed to loadvm begin work: %d", ret);
+    }
+    return ret;
+}
+
+int qemu_load_device_state(QEMUFile *f)
+{
+    MigrationIncomingState *mis = migration_incoming_get_current();
+    int ret;
+
+    /* Load QEMU_VM_SECTION_FULL section */
+    ret = qemu_loadvm_state_main(f, mis);
+    if (ret < 0) {
+        error_report("Failed to load device state: %d", ret);
+        return ret;
+    }
+
+    cpu_synchronize_all_post_init();
+    return 0;
+}
+
 void hmp_savevm(Monitor *mon, const QDict *qdict)
 {
     BlockDriverState *bs, *bs1;
Signature · 1 line
1.8.3.1
#27 lore raw

PATCH v17 27/34 migration/savevm: Export two helper functions for savevm process

In reply to zhanghailiang

We add a new helper functions qemu_savevm_live_state(), and make qemu_save_device_state() public.

---
v15:
- Add Reviewd-by tag
v14:
- New patch split from previous
'COLO: Separate the process of saving/loading ram and device state

---
 include/sysemu/sysemu.h |  3 +++
 migration/savevm.c      | 16 ++++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)
include/sysemu/sysemu.h +3 -0
index 2b44981..2f2161a 100644
@@ -132,6 +132,9 @@ void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f, const char *name,
                                            uint64_t *start_list,
                                            uint64_t *length_list);
 
+void qemu_savevm_live_state(QEMUFile *f);
+int qemu_save_device_state(QEMUFile *f);
+
 int qemu_loadvm_state(QEMUFile *f);
 int qemu_loadvm_state_begin(QEMUFile *f);
 int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
migration/savevm.c +12 -4
index 98abb5c..55a2eab 100644
@@ -53,6 +53,7 @@
 #include "qemu/cutils.h"
 #include "io/channel-buffer.h"
 #include "io/channel-file.h"
+#include "migration/colo.h"
 
 #ifndef ETH_P_RARP
 #define ETH_P_RARP 0x8035
@@ -1178,13 +1179,20 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
     return ret;
 }
 
-static int qemu_save_device_state(QEMUFile *f)
+void qemu_savevm_live_state(QEMUFile *f)
 {
-    SaveStateEntry *se;
+    /* save QEMU_VM_SECTION_END section */
+    qemu_savevm_state_complete_precopy(f, true);
+    qemu_put_byte(f, QEMU_VM_EOF);
+}
 
-    qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
-    qemu_put_be32(f, QEMU_VM_FILE_VERSION);
+int qemu_save_device_state(QEMUFile *f)
+{
+    SaveStateEntry *se;
 
+    if (!migration_in_colo_state()) {
+        qemu_savevm_state_header(f);
+    }
     cpu_synchronize_all_states();
 
     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
Signature · 1 line
1.8.3.1
#28 lore raw

PATCH v17 28/34 COLO: Separate the process of saving/loading ram and device state

In reply to zhanghailiang

We separate the process of saving/loading ram and device state when do checkpoint. We add new helpers for save/load ram/device. With this change, we can directly transfer RAM from primary side to secondary side without using channel-buffer as assistant, which also reduce the size of extra memory was used during checkpoint.

Besides, we move the colo_flush_ram_cache to the proper position after the above change.

---
v16:
- Add Reviewd-by tag
v14:
- split two new patches from this patch
- Some minor fixes from Dave
v13:
- Re-use some existed helper functions to realize saving/loading ram and device.
v11:
- Remove load configuration section in qemu_loadvm_state_begin()

---
 migration/colo.c   | 48 ++++++++++++++++++++++++++++++++++++++----------
 migration/ram.c    |  5 -----
 migration/savevm.c |  4 ++++
 3 files changed, 42 insertions(+), 15 deletions(-)
migration/colo.c +38 -10
index 16f402f..5641031 100644
@@ -284,21 +284,37 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
         goto out;
     }
 
+    colo_send_message(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
     /* Disable block migration */
     s->params.blk = 0;
     s->params.shared = 0;
-    qemu_savevm_state_header(fb);
-    qemu_savevm_state_begin(fb, &s->params);
+    qemu_savevm_state_begin(s->to_dst_file, &s->params);
+    ret = qemu_file_get_error(s->to_dst_file);
+    if (ret < 0) {
+        error_report("Save vm state begin error");
+        goto out;
+    }
+
     qemu_mutex_lock_iothread();
-    qemu_savevm_state_complete_precopy(fb, false);
+    /*
+     * Only save VM's live state, which not including device state.
+     * TODO: We may need a timeout mechanism to prevent COLO process
+     * to be blocked here.
+     */
+    qemu_savevm_live_state(s->to_dst_file);
+    /* Note: device state is saved into buffer */
+    ret = qemu_save_device_state(fb);
     qemu_mutex_unlock_iothread();
-
-    qemu_fflush(fb);
-
-    colo_send_message(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err);
-    if (local_err) {
+    if (ret < 0) {
+        error_report("Save device state error");
         goto out;
     }
+    qemu_fflush(fb);
+
     /*
      * We need the size of the VMstate data in Secondary side,
      * With which we can decide how much data should be read.
@@ -565,6 +581,16 @@ void *colo_process_incoming_thread(void *opaque)
             goto out;
         }
 
+        ret = qemu_loadvm_state_begin(mis->from_src_file);
+        if (ret < 0) {
+            error_report("Load vm state begin error, ret=%d", ret);
+            goto out;
+        }
+        ret = qemu_loadvm_state_main(mis->from_src_file, mis);
+        if (ret < 0) {
+            error_report("Load VM's live state (ram) error");
+            goto out;
+        }
         /* read the VM state total size first */
         value = colo_receive_message_value(mis->from_src_file,
                                  COLO_MESSAGE_VMSTATE_SIZE, &local_err);
@@ -600,8 +626,10 @@ void *colo_process_incoming_thread(void *opaque)
         qemu_mutex_lock_iothread();
         qemu_system_reset(VMRESET_SILENT);
         vmstate_loading = true;
-        if (qemu_loadvm_state(fb) < 0) {
-            error_report("COLO: loadvm failed");
+        colo_flush_ram_cache();
+        ret = qemu_load_device_state(fb);
+        if (ret < 0) {
+            error_report("COLO: load device state failed");
             qemu_mutex_unlock_iothread();
             goto out;
         }
migration/ram.c +0 -5
index 91d1287..34aa87e 100644
@@ -2466,7 +2466,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
      * be atomic
      */
     bool postcopy_running = postcopy_state_get() >= POSTCOPY_INCOMING_LISTENING;
-    bool need_flush = false;
 
     seq_iter++;
 
@@ -2501,7 +2500,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             /* After going into COLO, we should load the Page into colo_cache */
             if (ram_cache_enable) {
                 host = colo_cache_from_block_offset(block, addr);
-                need_flush = true;
             } else {
                 host = host_from_ram_block_offset(block, addr);
             }
@@ -2595,9 +2593,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
 
     rcu_read_unlock();
 
-    if (!ret  && ram_cache_enable && need_flush) {
-        colo_flush_ram_cache();
-    }
     DPRINTF("Completed load of VM with exit code %d seq iteration "
             "%" PRIu64 "\n", ret, seq_iter);
     return ret;
migration/savevm.c +4 -0
index 55a2eab..41ea2bd 100644
@@ -911,6 +911,10 @@ void qemu_savevm_state_begin(QEMUFile *f,
             break;
         }
     }
+    if (migration_in_colo_state()) {
+        qemu_put_byte(f, QEMU_VM_EOF);
+        qemu_fflush(f);
+    }
 }
 
 /*
Signature · 1 line
1.8.3.1
#29 lore raw

PATCH v17 29/34 COLO: Split qemu_savevm_state_begin out of checkpoint process

In reply to zhanghailiang

It is unnecessary to call qemu_savevm_state_begin() in every checkpoint process. It mainly sets up devices and does the first device state pass. These data will not change during the later checkpoint process. So, we split it out of colo_do_checkpoint_transaction(), in this way, we can reduce these data transferring in the subsequent checkpoint.

---
v13:
- Fix some minor issues found by Dave
- Add Reviewed-by tag

---
 migration/colo.c | 51 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 15 deletions(-)
migration/colo.c +36 -15
index 5641031..c995a1a 100644
@@ -289,16 +289,6 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
         goto out;
     }
 
-    /* Disable block migration */
-    s->params.blk = 0;
-    s->params.shared = 0;
-    qemu_savevm_state_begin(s->to_dst_file, &s->params);
-    ret = qemu_file_get_error(s->to_dst_file);
-    if (ret < 0) {
-        error_report("Save vm state begin error");
-        goto out;
-    }
-
     qemu_mutex_lock_iothread();
     /*
      * Only save VM's live state, which not including device state.
@@ -373,6 +363,21 @@ out:
     return ret;
 }
 
+static int colo_prepare_before_save(MigrationState *s)
+{
+    int ret;
+
+    /* Disable block migration */
+    s->params.blk = 0;
+    s->params.shared = 0;
+    qemu_savevm_state_begin(s->to_dst_file, &s->params);
+    ret = qemu_file_get_error(s->to_dst_file);
+    if (ret < 0) {
+        error_report("Save vm state begin error");
+    }
+    return ret;
+}
+
 static void colo_process_checkpoint(MigrationState *s)
 {
     QIOChannelBuffer *bioc;
@@ -389,6 +394,11 @@ static void colo_process_checkpoint(MigrationState *s)
         goto out;
     }
 
+    ret = colo_prepare_before_save(s);
+    if (ret < 0) {
+        goto out;
+    }
+
     /*
      * Wait for Secondary finish loading vm states and enter COLO
      * restore.
@@ -510,6 +520,17 @@ static void colo_wait_handle_message(QEMUFile *f, int *checkpoint_request,
     }
 }
 
+static int colo_prepare_before_load(QEMUFile *f)
+{
+    int ret;
+
+    ret = qemu_loadvm_state_begin(f);
+    if (ret < 0) {
+        error_report("Load VM state begin error, ret=%d", ret);
+    }
+    return ret;
+}
+
 void *colo_process_incoming_thread(void *opaque)
 {
     MigrationIncomingState *mis = opaque;
@@ -549,6 +570,11 @@ void *colo_process_incoming_thread(void *opaque)
     fb = qemu_fopen_channel_input(QIO_CHANNEL(bioc));
     object_unref(OBJECT(bioc));
 
+    ret = colo_prepare_before_load(mis->from_src_file);
+    if (ret < 0) {
+        goto out;
+    }
+
     colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY,
                       &local_err);
     if (local_err) {
@@ -581,11 +607,6 @@ void *colo_process_incoming_thread(void *opaque)
             goto out;
         }
 
-        ret = qemu_loadvm_state_begin(mis->from_src_file);
-        if (ret < 0) {
-            error_report("Load vm state begin error, ret=%d", ret);
-            goto out;
-        }
         ret = qemu_loadvm_state_main(mis->from_src_file, mis);
         if (ret < 0) {
             error_report("Load VM's live state (ram) error");
Signature · 1 line
1.8.3.1
#30 lore raw

PATCH v17 30/34 filter-buffer: Accept zero interval

In reply to zhanghailiang

We may want to accept zero interval when VM FT solutions like MC or COLO use this filter to release packets on demand.

---
 net/filter-buffer.c | 10 ----------
 1 file changed, 10 deletions(-)
net/filter-buffer.c +0 -10
index cc6bd94..346306a 100644
@@ -118,16 +118,6 @@ static void filter_buffer_setup(NetFilterState *nf, Error **errp)
 {
     FilterBufferState *s = FILTER_BUFFER(nf);
 
-    /*
-     * We may want to accept zero interval when VM FT solutions like MC
-     * or COLO use this filter to release packets on demand.
-     */
-    if (!s->interval) {
-        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "interval",
-                   "a non-zero interval");
-        return;
-    }
-
     s->incoming_queue = qemu_new_net_queue(qemu_netfilter_pass_to_next, nf);
     filter_buffer_setup_timer(nf);
 }
Signature · 1 line
1.8.3.1
#31 lore raw

PATCH v17 31/34 net: Add notifier/callback for netdev init

In reply to zhanghailiang

We can register some callback for this notifier, this will be used by COLO to register a callback which will add each netdev a buffer filter.

Cc Jason Wang <[email protected]>
Cc Yang Hongyang <[email protected]>

---
v17:
- Rename netdev_init_add_notifier() to netdev_register_init_notifier() v16:
- Simplify the codes by using some helpers in QEMU
v14:
- New patch

---
 include/net/net.h |  3 +++
 net/net.c         | 12 ++++++++++++
 2 files changed, 15 insertions(+)
include/net/net.h +3 -0
index a69e382..c5ebab3 100644
@@ -8,6 +8,7 @@
 #include "net/queue.h"
 #include "migration/vmstate.h"
 #include "qapi-types.h"
+#include "qemu/notify.h"
 
 #define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X"
 #define MAC_ARG(x) ((uint8_t *)(x))[0], ((uint8_t *)(x))[1], \
@@ -194,6 +195,8 @@ struct NICInfo {
     int nvectors;
 };
 
+void netdev_register_init_notifier(Notifier *notify);
+
 extern int nb_nics;
 extern NICInfo nd_table[MAX_NICS];
 extern const char *host_net_devices[];
net/net.c +12 -0
index 5f3e5a9..b19f107 100644
@@ -56,6 +56,9 @@
 static VMChangeStateEntry *net_change_state_entry;
 static QTAILQ_HEAD(, NetClientState) net_clients;
 
+static NotifierList netdev_init_notifiers =
+    NOTIFIER_LIST_INITIALIZER(netdev_init_notifiers);
+
 const char *host_net_devices[] = {
     "tap",
     "socket",
@@ -929,6 +932,10 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
     return idx;
 }
 
+void netdev_register_init_notifier(Notifier *notify)
+{
+    notifier_list_add(&netdev_init_notifiers, notify);
+}
 
 static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND__MAX])(
     const NetClientOptions *opts,
@@ -1015,6 +1022,11 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
         }
         return -1;
     }
+    if (is_netdev) {
+        const Netdev *netdev = object;
+
+        notifier_list_notify(&netdev_init_notifiers, netdev->id);
+    }
     return 0;
 }
 
Signature · 1 line
1.8.3.1
#32 lore raw

PATCH v17 32/34 COLO/filter: Add each netdev a buffer filter

In reply to zhanghailiang

For COLO periodic mode, it needs to buffer packets that sent by VM, and we will not release these packets until finish a checkpoint.

Here, we add each netdev a buffer-filter that will be controlled by COLO. It is off by default, and the packets will not pass through these filters. If users don't enable COLO while configure qemu, these buffer-filters will not be added.

Cc Jason Wang <[email protected]>
Cc Yang Hongyang <[email protected]>

---
v16:
- Remove the useless check in colo_add_buffer_filter() v15:
- call object_new_with_props() directly to add filter in colo_add_buffer_filter. (Jason's suggestion)
v14:
- New patch

---
 include/migration/colo.h |  3 +++
 include/net/filter.h     |  2 ++
 migration/colo-comm.c    |  7 +++++++
 migration/colo.c         | 39 +++++++++++++++++++++++++++++++++++++++
 net/filter-buffer.c      |  2 --
 stubs/migration-colo.c   |  4 ++++
 6 files changed, 55 insertions(+), 2 deletions(-)
include/migration/colo.h +3 -0
index b16c642..b08715a 100644
@@ -37,4 +37,7 @@ COLOMode get_colo_mode(void);
 void colo_do_failover(MigrationState *s);
 
 bool colo_handle_shutdown(void);
+bool colo_shutdown(void);
+void colo_add_buffer_filter(Notifier *notifier, void *data);
+
 #endif
include/net/filter.h +2 -0
index 0c4a2ea..817eaf4 100644
@@ -21,6 +21,8 @@
 #define NETFILTER_CLASS(klass) \
     OBJECT_CLASS_CHECK(NetFilterClass, (klass), TYPE_NETFILTER)
 
+#define TYPE_FILTER_BUFFER "filter-buffer"
+
 typedef void (FilterSetup) (NetFilterState *nf, Error **errp);
 typedef void (FilterCleanup) (NetFilterState *nf);
 /*
migration/colo-comm.c +7 -0
index 716a4f7..44ac76a 100644
@@ -14,12 +14,14 @@
 #include "qemu/osdep.h"
 #include <migration/colo.h>
 #include "trace.h"
+#include <net/net.h>
 
 typedef struct {
      bool colo_requested;
 } COLOInfo;
 
 static COLOInfo colo_info;
+static Notifier netdev_init_notifier;
 
 COLOMode get_colo_mode(void)
 {
@@ -59,6 +61,11 @@ static const VMStateDescription colo_state = {
 void colo_info_init(void)
 {
     vmstate_register(NULL, 0, &colo_state, &colo_info);
+    /* FIXME: Remove this after COLO switch to using colo-proxy */
+    if (colo_supported()) {
+        netdev_init_notifier.notify = colo_add_buffer_filter;
+        netdev_register_init_notifier(&netdev_init_notifier);
+    }
 }
 
 bool migration_incoming_enable_colo(void)
migration/colo.c +39 -0
index c995a1a..f9bd62c 100644
@@ -20,11 +20,22 @@
 #include "qapi/error.h"
 #include "migration/failover.h"
 #include "qapi-event.h"
+#include "net/net.h"
+#include "net/filter.h"
+#include "net/vhost_net.h"
 
 static bool vmstate_loading;
 
 #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)
 
+typedef struct COLOListNode {
+    void *opaque;
+    QLIST_ENTRY(COLOListNode) node;
+} COLOListNode;
+
+static QLIST_HEAD(, COLOListNode) COLOBufferFilters =
+    QLIST_HEAD_INITIALIZER(COLOBufferFilters);
+
 bool colo_supported(void)
 {
     return true;
@@ -378,6 +389,34 @@ static int colo_prepare_before_save(MigrationState *s)
     return ret;
 }
 
+void colo_add_buffer_filter(Notifier *notifier, void *data)
+{
+    char *netdev_id = data;
+    NetFilterState *nf;
+    char filter_name[128];
+    Object *filter;
+    COLOListNode *filternode;
+
+    snprintf(filter_name, sizeof(filter_name),
+            "%scolo", netdev_id);
+
+    filter = object_new_with_props(TYPE_FILTER_BUFFER,
+                        object_get_objects_root(),
+                        filter_name, NULL,
+                        "netdev", netdev_id,
+                        "status", "off",
+                        NULL);
+    if (!filter) {
+        return;
+    }
+    nf =  NETFILTER(filter);
+    /* Only buffer the packets that sent out by VM */
+    nf->direction = NET_FILTER_DIRECTION_RX;
+    filternode = g_new0(COLOListNode, 1);
+    filternode->opaque = nf;
+    QLIST_INSERT_HEAD(&COLOBufferFilters, filternode, node);
+}
+
 static void colo_process_checkpoint(MigrationState *s)
 {
     QIOChannelBuffer *bioc;
net/filter-buffer.c +0 -2
index 346306a..d1cf595 100644
@@ -17,8 +17,6 @@
 #include "qapi-visit.h"
 #include "qom/object.h"
 
-#define TYPE_FILTER_BUFFER "filter-buffer"
-
 #define FILTER_BUFFER(obj) \
     OBJECT_CHECK(FilterBufferState, (obj), TYPE_FILTER_BUFFER)
 
stubs/migration-colo.c +4 -0
index 167b191..ae29d47 100644
@@ -49,3 +49,7 @@ bool colo_handle_shutdown(void)
 {
     return false;
 }
+
+void colo_add_buffer_filter(Notifier *notifier, void *data)
+{
+}
Signature · 1 line
1.8.3.1
#33 lore raw

PATCH v17 33/34 COLO: Control the status of buffer filters for PVM

In reply to zhanghailiang

Enable all buffer filters that added by COLO while go into COLO process, and disable them while exit COLO.

Cc Jason Wang <[email protected]>
Cc Yang Hongyang <[email protected]>

---
v16:
- Stop buffer filter while doing checkpoint and resume it after checkpoint.
v15:
- Re-implement colo_set_filter_status() based on COLOBufferFilters list.
- Fix the title of this patch

---
 migration/colo.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
migration/colo.c +32 -1
index f9bd62c..de7174f 100644
@@ -114,10 +114,22 @@ static void secondary_vm_do_failover(void)
     }
 }
 
+static void colo_set_filter_status(const char *status, Error **errp)
+{
+    struct COLOListNode *e, *next;
+    NetFilterState *nf;
+
+    QLIST_FOREACH_SAFE(e, &COLOBufferFilters, node, next) {
+        nf = e->opaque;
+        object_property_set_str(OBJECT(nf), status, "status", errp);
+    }
+}
+
 static void primary_vm_do_failover(void)
 {
     MigrationState *s = migrate_get_current();
     int old_state;
+    Error *local_err = NULL;
 
     migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
                       MIGRATION_STATUS_COMPLETED);
@@ -141,6 +153,12 @@ static void primary_vm_do_failover(void)
                      old_state);
         return;
     }
+
+    colo_set_filter_status("off", &local_err);
+    if (local_err) {
+        error_report_err(local_err);
+    }
+
     /* Notify COLO thread that failover work is finished */
     qemu_sem_post(&s->colo_exit_sem);
 }
@@ -294,7 +312,11 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
     if (failover_request_is_active()) {
         goto out;
     }
-
+    /* Stop buffer filter and flush the buffered packets */
+    colo_set_filter_status("off", &local_err);
+    if (local_err) {
+        goto out;
+    }
     colo_send_message(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err);
     if (local_err) {
         goto out;
@@ -360,6 +382,10 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
         qemu_thread_exit(0);
     }
 
+    colo_set_filter_status("on", &local_err);
+    if (local_err) {
+        goto out;
+    }
     ret = 0;
 
     qemu_mutex_lock_iothread();
@@ -427,6 +453,11 @@ static void colo_process_checkpoint(MigrationState *s)
 
     failover_init_state();
 
+    colo_set_filter_status("on", &local_err);
+    if (local_err) {
+        goto out;
+    }
+
     s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file);
     if (!s->rp_state.from_dst_file) {
         error_report("Open QEMUFile from_dst_file failed");
Signature · 1 line
1.8.3.1
#34 lore raw

PATCH v17 34/34 COLO: Add block replication into colo process

In reply to zhanghailiang

Make sure master start block replication after slave's block replication started.

---
 migration/colo.c      | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 migration/migration.c |  6 +++++-
 2 files changed, 54 insertions(+), 1 deletion(-)
migration/colo.c +49 -0
index de7174f..649c01f 100644
@@ -23,6 +23,8 @@
 #include "net/net.h"
 #include "net/filter.h"
 #include "net/vhost_net.h"
+#include "block/block.h"
+#include "replication.h"
 
 static bool vmstate_loading;
 
@@ -64,6 +66,7 @@ static void secondary_vm_do_failover(void)
 {
     int old_state;
     MigrationIncomingState *mis = migration_incoming_get_current();
+    Error *local_err = NULL;
 
     /* Can not do failover during the process of VM's loading VMstate, Or
      * it will break the secondary VM.
@@ -81,6 +84,11 @@ static void secondary_vm_do_failover(void)
     migrate_set_state(&mis->state, MIGRATION_STATUS_COLO,
                       MIGRATION_STATUS_COMPLETED);
 
+    replication_stop_all(true, &local_err);
+    if (local_err) {
+        error_report_err(local_err);
+    }
+
     if (!autostart) {
         error_report("\"-S\" qemu option will be ignored in secondary side");
         /* recover runstate to normal migration finish state */
@@ -159,6 +167,11 @@ static void primary_vm_do_failover(void)
         error_report_err(local_err);
     }
 
+    replication_stop_all(true, &local_err);
+    if (local_err) {
+        error_report_err(local_err);
+    }
+
     /* Notify COLO thread that failover work is finished */
     qemu_sem_post(&s->colo_exit_sem);
 }
@@ -317,6 +330,15 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
     if (local_err) {
         goto out;
     }
+
+    /* We call this API although this may do nothing on primary side. */
+    qemu_mutex_lock_iothread();
+    replication_do_checkpoint_all(&local_err);
+    qemu_mutex_unlock_iothread();
+    if (local_err) {
+        goto out;
+    }
+
     colo_send_message(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err);
     if (local_err) {
         goto out;
@@ -483,6 +505,12 @@ static void colo_process_checkpoint(MigrationState *s)
     object_unref(OBJECT(bioc));
 
     qemu_mutex_lock_iothread();
+    replication_start_all(REPLICATION_MODE_PRIMARY, &local_err);
+    if (local_err) {
+        qemu_mutex_unlock_iothread();
+        goto out;
+    }
+
     vm_start();
     qemu_mutex_unlock_iothread();
     trace_colo_vm_state_change("stop", "run");
@@ -576,6 +604,7 @@ static void colo_wait_handle_message(QEMUFile *f, int *checkpoint_request,
     case COLO_MESSAGE_GUEST_SHUTDOWN:
         qemu_mutex_lock_iothread();
         vm_stop_force_state(RUN_STATE_COLO);
+        replication_stop_all(false, NULL);
         qemu_system_shutdown_request_core();
         qemu_mutex_unlock_iothread();
         /*
@@ -645,6 +674,14 @@ void *colo_process_incoming_thread(void *opaque)
         goto out;
     }
 
+    qemu_mutex_lock_iothread();
+    bdrv_invalidate_cache_all(&local_err);
+    replication_start_all(REPLICATION_MODE_SECONDARY, &local_err);
+    qemu_mutex_unlock_iothread();
+    if (local_err) {
+        goto out;
+    }
+
     colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY,
                       &local_err);
     if (local_err) {
@@ -725,6 +762,18 @@ void *colo_process_incoming_thread(void *opaque)
             goto out;
         }
 
+        replication_get_error_all(&local_err);
+        if (local_err) {
+            qemu_mutex_unlock_iothread();
+            goto out;
+        }
+        /* discard colo disk buffer */
+        replication_do_checkpoint_all(&local_err);
+        if (local_err) {
+            qemu_mutex_unlock_iothread();
+            goto out;
+        }
+
         vmstate_loading = false;
         qemu_mutex_unlock_iothread();
 
migration/migration.c +5 -1
index 8d735fc..9528713 100644
@@ -1676,7 +1676,11 @@ static void migration_completion(MigrationState *s, int current_active_state,
 
         if (!ret) {
             ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
-            if (ret >= 0) {
+            /*
+             * Don't mark the image with BDRV_O_INACTIVE flag if
+             * we will go into COLO stage later.
+             */
+            if (ret >= 0 && !migrate_colo_enabled()) {
                 ret = bdrv_inactivate_all();
             }
             if (ret >= 0) {
Signature · 1 line
1.8.3.1
#35 lore raw
In reply to zhanghailiang
Quoted 5 lines · * zhanghailiang ([email protected]) wrote:

This is the 17th version of COLO FT feature.

Here is only COLO frame part, you can get the whole codes from github:
https://github.com/coloft/qemu/commits/colo-v3.0-periodic-mode

Quoted 7 lines

Migration now switches to use the new QIOChannel API. It only affects COLO's patch 9 and patch 12, which we used the old qsb buffer before, and we updated them with the new API. It's only involving tiny changes.

Patch status:
Unreviewed: patch 32 ~ 35
Updated: patch 9, 12, 32

You've posted patches 1..34 - does 35 really exist?

Dave

Quoted 130 lines
Cc Stefan Hajnoczi <[email protected]>
Cc Jeff Cody <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>
Cc Juan Quintela <[email protected]>
Cc Amit Shah <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
Cc Jason Wang <[email protected]>

PS: These series has been in community for a long time, it depends on Changlong's block-replicaton series, but that has been blocked for a long time, we really need help on reviewing that and this series. Thanks.

TODO:
1. Checkpoint based on proxy in qemu
2. The capability of continuous FT
3. Optimize the VM's downtime during checkpoint

v17:
- Rebase master to use the new QIOChannel API, only affect patch 9 and 12
- Reorganize some ugly comments
- Rename colo_sem to colo_exit_sem (patch 21)

v16:
- Fix compile broken due to missing osdep.h
- Add reviewed-by tag for patch 27, 28, 29
- Rename the message send/receive helper function (patch 7, 13)
- Simplify the codes by using some notifier helpers in QEMU (patch 32)
- Remove the useless check in colo_add_buffer_filter() (patch 33)
- Remove the previous patch 36, 37 which export filter_buffer_flush() to release the buffered packets, we simplify it by stopping buffer filter while doing checkpoint, which will flush the buffered packets by default. (patch 34)
v15:
- Go on the shutdown process if encounter error while sending shutdown message to SVM. (patch 24)
- Rename qemu_need_skip_netfilter to qemu_netfilter_can_skip and Remove some useless comment. (patch 31, Jason)
- Call object_new_with_props() directly to add filter in colo_add_buffer_filter. (patch 34, Jason)
- Re-implement colo_set_filter_status() based on COLOBufferFilters list. (patch 35)
- Re-implement colo_flush_filter_packets() based on COLOBufferFilters list. (patch 37)
v14:
- Re-implement the network processing based on netfilter (Jason Wang)
- Rename 'COLOCommand' to 'COLOMessage'. (Markus's suggestion)
- Split two new patches (patch 27/28) from patch 29
- Fix some other comments from Dave and Markus.

v13:
- Refactor colo_*_cmd helper functions to use 'Error **errp' parameter instead of return value to indicate success or failure. (patch 10)
- Remove the optional error message for COLO_EXIT event. (patch 25)
- Use semaphore to notify colo/colo incoming loop that failover work is finished. (patch 26)
- Move COLO shutdown related codes to colo.c file. (patch 28)
- Fix memory leak bug for colo incoming loop. (new patch 31)
- Re-use some existed helper functions to realize the process of saving/loading ram and device. (patch 32)
- Fix some other comments from Dave and Markus.

zhanghailiang (34):
configure: Add parameter for configure to enable/disable COLO support
migration: Introduce capability 'x-colo' to migration
COLO: migrate colo related info to secondary node
migration: Integrate COLO checkpoint process into migration
migration: Integrate COLO checkpoint process into loadvm COLO/migration: Create a new communication path from destination to
source
COLO: Implement COLO checkpoint protocol
COLO: Add a new RunState RUN_STATE_COLO
COLO: Save PVM state to secondary side when do checkpoint
COLO: Load PVM's dirty pages into SVM's RAM cache temporarily ram/COLO: Record the dirty pages that SVM received
COLO: Load VMState into buffer before restore it
COLO: Flush PVM's cached RAM into SVM's memory
COLO: Add checkpoint-delay parameter for migrate-set-parameters
COLO: Synchronize PVM's state to SVM periodically
COLO failover: Introduce a new command to trigger a failover COLO failover: Introduce state to record failover process
COLO: Implement failover work for Primary VM
COLO: Implement failover work for Secondary VM
qmp event: Add COLO_EXIT event to notify users while exited from COLO COLO failover: Shutdown related socket fd when do failover COLO failover: Don't do failover during loading VM's state
COLO: Process shutdown command for VM in COLO state
COLO: Update the global runstate after going into colo state
savevm: Introduce two helper functions for save/find loadvm_handlers
entry
migration/savevm: Add new helpers to process the different stages of
loadvm
migration/savevm: Export two helper functions for savevm process
COLO: Separate the process of saving/loading ram and device state
COLO: Split qemu_savevm_state_begin out of checkpoint process
filter-buffer: Accept zero interval
net: Add notifier/callback for netdev init
COLO/filter: Add each netdev a buffer filter
COLO: Control the status of buffer filters for PVM
COLO: Add block replication into colo process

 configure                     |  11 +
 docs/qmp-events.txt           |  16 +
 hmp-commands.hx               |  15 +
 hmp.c                         |  15 +
 hmp.h                         |   1 +
 include/exec/ram_addr.h       |   1 +
 include/migration/colo.h      |  43 +++
 include/migration/failover.h  |  33 ++
 include/migration/migration.h |  16 +
 include/net/filter.h          |   2 +
 include/net/net.h             |   3 +
 include/sysemu/sysemu.h       |   9 +
 migration/Makefile.objs       |   2 +
 migration/colo-comm.c         |  79 ++++
 migration/colo-failover.c     |  84 +++++
 migration/colo.c              | 844 ++++++++++++++++++++++++++++++++++++++++++
 migration/migration.c         |  84 ++++-
 migration/ram.c               | 175 ++++++++-
 migration/savevm.c            | 114 ++++--
 net/filter-buffer.c           |  12 -
 net/net.c                     |  12 +
 qapi-schema.json              | 102 ++++-
 qapi/event.json               |  15 +
 qmp-commands.hx               |  24 +-
 stubs/Makefile.objs           |   1 +
 stubs/migration-colo.c        |  55 +++
 trace-events                  |   8 +
Quoted 13 lines
 vl.c                          |  31 +-
 28 files changed, 1744 insertions(+), 63 deletions(-)
 create mode 100644 include/migration/colo.h
 create mode 100644 include/migration/failover.h
 create mode 100644 migration/colo-comm.c
 create mode 100644 migration/colo-failover.c
 create mode 100644 migration/colo.c
 create mode 100644 stubs/migration-colo.c
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#36 lore raw
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 9 lines · * zhanghailiang ([email protected]) wrote:

This is the 17th version of COLO FT feature.

Here is only COLO frame part, you can get the whole codes from github:
https://github.com/coloft/qemu/commits/colo-v3.0-periodic-mode

Migration now switches to use the new QIOChannel API. It only affects COLO's patch 9 and patch 12, which we used the old qsb buffer before, and we updated them with the new API. It's only involving tiny changes.

Quoted 6 lines
Quoted 3 lines

Patch status:
Unreviewed: patch 32 ~ 35
Updated: patch 9, 12, 32

You've posted patches 1..34 - does 35 really exist?

Sorry, i made a mistake, there is no patch 35,
Compared with last series, we dropped one patch that related to qsb buffer.

Thanks.
Hailiang

Quoted 150 lines

Dave

Quoted 139 lines
Cc Stefan Hajnoczi <[email protected]>
Cc Jeff Cody <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>
Cc Juan Quintela <[email protected]>
Cc Amit Shah <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
Cc Jason Wang <[email protected]>

PS: These series has been in community for a long time, it depends on Changlong's block-replicaton series, but that has been blocked for a long time, we really need help on reviewing that and this series. Thanks.

TODO:
1. Checkpoint based on proxy in qemu
2. The capability of continuous FT
3. Optimize the VM's downtime during checkpoint

v17:
- Rebase master to use the new QIOChannel API, only affect patch 9 and 12
- Reorganize some ugly comments
- Rename colo_sem to colo_exit_sem (patch 21)

v16:
- Fix compile broken due to missing osdep.h
- Add reviewed-by tag for patch 27, 28, 29
- Rename the message send/receive helper function (patch 7, 13)
- Simplify the codes by using some notifier helpers in QEMU (patch 32)
- Remove the useless check in colo_add_buffer_filter() (patch 33)
- Remove the previous patch 36, 37 which export filter_buffer_flush() to release the buffered packets, we simplify it by stopping buffer filter while doing checkpoint, which will flush the buffered packets by default. (patch 34)
v15:
- Go on the shutdown process if encounter error while sending shutdown message to SVM. (patch 24)
- Rename qemu_need_skip_netfilter to qemu_netfilter_can_skip and Remove some useless comment. (patch 31, Jason)
- Call object_new_with_props() directly to add filter in colo_add_buffer_filter. (patch 34, Jason)
- Re-implement colo_set_filter_status() based on COLOBufferFilters

    list. (patch 35)
  - Re-implement colo_flush_filter_packets() based on COLOBufferFilters
    list. (patch 37)

v14:
- Re-implement the network processing based on netfilter (Jason Wang)
- Rename 'COLOCommand' to 'COLOMessage'. (Markus's suggestion)
- Split two new patches (patch 27/28) from patch 29
- Fix some other comments from Dave and Markus.

v13:
- Refactor colo_*_cmd helper functions to use 'Error **errp' parameter instead of return value to indicate success or failure. (patch 10)
- Remove the optional error message for COLO_EXIT event. (patch 25)
- Use semaphore to notify colo/colo incoming loop that failover work is finished. (patch 26)
- Move COLO shutdown related codes to colo.c file. (patch 28)
- Fix memory leak bug for colo incoming loop. (new patch 31)
- Re-use some existed helper functions to realize the process of saving/loading ram and device. (patch 32)
- Fix some other comments from Dave and Markus.

zhanghailiang (34):
configure: Add parameter for configure to enable/disable COLO support
migration: Introduce capability 'x-colo' to migration
COLO: migrate colo related info to secondary node
migration: Integrate COLO checkpoint process into migration
migration: Integrate COLO checkpoint process into loadvm COLO/migration: Create a new communication path from destination to
source
COLO: Implement COLO checkpoint protocol
COLO: Add a new RunState RUN_STATE_COLO
COLO: Save PVM state to secondary side when do checkpoint
COLO: Load PVM's dirty pages into SVM's RAM cache temporarily ram/COLO: Record the dirty pages that SVM received
COLO: Load VMState into buffer before restore it
COLO: Flush PVM's cached RAM into SVM's memory
COLO: Add checkpoint-delay parameter for migrate-set-parameters
COLO: Synchronize PVM's state to SVM periodically
COLO failover: Introduce a new command to trigger a failover COLO failover: Introduce state to record failover process
COLO: Implement failover work for Primary VM
COLO: Implement failover work for Secondary VM
qmp event: Add COLO_EXIT event to notify users while exited from COLO COLO failover: Shutdown related socket fd when do failover COLO failover: Don't do failover during loading VM's state
COLO: Process shutdown command for VM in COLO state
COLO: Update the global runstate after going into colo state
savevm: Introduce two helper functions for save/find loadvm_handlers
entry
migration/savevm: Add new helpers to process the different stages of
loadvm
migration/savevm: Export two helper functions for savevm process
COLO: Separate the process of saving/loading ram and device state
COLO: Split qemu_savevm_state_begin out of checkpoint process
filter-buffer: Accept zero interval
net: Add notifier/callback for netdev init
COLO/filter: Add each netdev a buffer filter
COLO: Control the status of buffer filters for PVM
COLO: Add block replication into colo process

  configure                     |  11 +
  docs/qmp-events.txt           |  16 +
  hmp-commands.hx               |  15 +
  hmp.c                         |  15 +
  hmp.h                         |   1 +
  include/exec/ram_addr.h       |   1 +
  include/migration/colo.h      |  43 +++
  include/migration/failover.h  |  33 ++
  include/migration/migration.h |  16 +
  include/net/filter.h          |   2 +
  include/net/net.h             |   3 +
  include/sysemu/sysemu.h       |   9 +
  migration/Makefile.objs       |   2 +
  migration/colo-comm.c         |  79 ++++
  migration/colo-failover.c     |  84 +++++
  migration/colo.c              | 844 ++++++++++++++++++++++++++++++++++++++++++
  migration/migration.c         |  84 ++++-
  migration/ram.c               | 175 ++++++++-
  migration/savevm.c            | 114 ++++--
  net/filter-buffer.c           |  12 -
  net/net.c                     |  12 +
  qapi-schema.json              | 102 ++++-
  qapi/event.json               |  15 +
  qmp-commands.hx               |  24 +-
  stubs/Makefile.objs           |   1 +
  stubs/migration-colo.c        |  55 +++
  trace-events                  |   8 +
  vl.c                          |  31 +-
  28 files changed, 1744 insertions(+), 63 deletions(-)

create mode 100644 include/migration/colo.h
create mode 100644 include/migration/failover.h
create mode 100644 migration/colo-comm.c
create mode 100644 migration/colo-failover.c
create mode 100644 migration/colo.c
create mode 100644 stubs/migration-colo.c

Quoted 4 lines

--
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

.

#37 lore raw
In reply to zhanghailiang
Quoted 8 lines · * zhanghailiang ([email protected]) wrote:

This is the 17th version of COLO FT feature.

Here is only COLO frame part, you can get the whole codes from github:
https://github.com/coloft/qemu/commits/colo-v3.0-periodic-mode

Migration now switches to use the new QIOChannel API. It only affects COLO's patch 9 and patch 12, which we used the old qsb buffer before, and we updated them with the new API. It's only involving tiny changes.

I notice that the block code has nearly been accepted; so perhaps it's worth posting a version rebased on the current rc and then hopefully we can line this core code up for the start of 2.8 as soon as the block code lands.

Dave

Quoted 133 lines

Patch status:
Unreviewed: patch 32 ~ 35
Updated: patch 9, 12, 32

Cc Stefan Hajnoczi <[email protected]>
Cc Jeff Cody <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>
Cc Juan Quintela <[email protected]>
Cc Amit Shah <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
Cc Jason Wang <[email protected]>

PS: These series has been in community for a long time, it depends on Changlong's block-replicaton series, but that has been blocked for a long time, we really need help on reviewing that and this series. Thanks.

TODO:
1. Checkpoint based on proxy in qemu
2. The capability of continuous FT
3. Optimize the VM's downtime during checkpoint

v17:
- Rebase master to use the new QIOChannel API, only affect patch 9 and 12
- Reorganize some ugly comments
- Rename colo_sem to colo_exit_sem (patch 21)

v16:
- Fix compile broken due to missing osdep.h
- Add reviewed-by tag for patch 27, 28, 29
- Rename the message send/receive helper function (patch 7, 13)
- Simplify the codes by using some notifier helpers in QEMU (patch 32)
- Remove the useless check in colo_add_buffer_filter() (patch 33)
- Remove the previous patch 36, 37 which export filter_buffer_flush() to release the buffered packets, we simplify it by stopping buffer filter while doing checkpoint, which will flush the buffered packets by default. (patch 34)
v15:
- Go on the shutdown process if encounter error while sending shutdown message to SVM. (patch 24)
- Rename qemu_need_skip_netfilter to qemu_netfilter_can_skip and Remove some useless comment. (patch 31, Jason)
- Call object_new_with_props() directly to add filter in colo_add_buffer_filter. (patch 34, Jason)
- Re-implement colo_set_filter_status() based on COLOBufferFilters list. (patch 35)
- Re-implement colo_flush_filter_packets() based on COLOBufferFilters list. (patch 37)
v14:
- Re-implement the network processing based on netfilter (Jason Wang)
- Rename 'COLOCommand' to 'COLOMessage'. (Markus's suggestion)
- Split two new patches (patch 27/28) from patch 29
- Fix some other comments from Dave and Markus.

v13:
- Refactor colo_*_cmd helper functions to use 'Error **errp' parameter instead of return value to indicate success or failure. (patch 10)
- Remove the optional error message for COLO_EXIT event. (patch 25)
- Use semaphore to notify colo/colo incoming loop that failover work is finished. (patch 26)
- Move COLO shutdown related codes to colo.c file. (patch 28)
- Fix memory leak bug for colo incoming loop. (new patch 31)
- Re-use some existed helper functions to realize the process of saving/loading ram and device. (patch 32)
- Fix some other comments from Dave and Markus.

zhanghailiang (34):
configure: Add parameter for configure to enable/disable COLO support
migration: Introduce capability 'x-colo' to migration
COLO: migrate colo related info to secondary node
migration: Integrate COLO checkpoint process into migration
migration: Integrate COLO checkpoint process into loadvm COLO/migration: Create a new communication path from destination to
source
COLO: Implement COLO checkpoint protocol
COLO: Add a new RunState RUN_STATE_COLO
COLO: Save PVM state to secondary side when do checkpoint
COLO: Load PVM's dirty pages into SVM's RAM cache temporarily ram/COLO: Record the dirty pages that SVM received
COLO: Load VMState into buffer before restore it
COLO: Flush PVM's cached RAM into SVM's memory
COLO: Add checkpoint-delay parameter for migrate-set-parameters
COLO: Synchronize PVM's state to SVM periodically
COLO failover: Introduce a new command to trigger a failover COLO failover: Introduce state to record failover process
COLO: Implement failover work for Primary VM
COLO: Implement failover work for Secondary VM
qmp event: Add COLO_EXIT event to notify users while exited from COLO COLO failover: Shutdown related socket fd when do failover COLO failover: Don't do failover during loading VM's state
COLO: Process shutdown command for VM in COLO state
COLO: Update the global runstate after going into colo state
savevm: Introduce two helper functions for save/find loadvm_handlers
entry
migration/savevm: Add new helpers to process the different stages of
loadvm
migration/savevm: Export two helper functions for savevm process
COLO: Separate the process of saving/loading ram and device state
COLO: Split qemu_savevm_state_begin out of checkpoint process
filter-buffer: Accept zero interval
net: Add notifier/callback for netdev init
COLO/filter: Add each netdev a buffer filter
COLO: Control the status of buffer filters for PVM
COLO: Add block replication into colo process

 configure                     |  11 +
 docs/qmp-events.txt           |  16 +
 hmp-commands.hx               |  15 +
 hmp.c                         |  15 +
 hmp.h                         |   1 +
 include/exec/ram_addr.h       |   1 +
 include/migration/colo.h      |  43 +++
 include/migration/failover.h  |  33 ++
 include/migration/migration.h |  16 +
 include/net/filter.h          |   2 +
 include/net/net.h             |   3 +
 include/sysemu/sysemu.h       |   9 +
 migration/Makefile.objs       |   2 +
 migration/colo-comm.c         |  79 ++++
 migration/colo-failover.c     |  84 +++++
 migration/colo.c              | 844 ++++++++++++++++++++++++++++++++++++++++++
 migration/migration.c         |  84 ++++-
 migration/ram.c               | 175 ++++++++-
 migration/savevm.c            | 114 ++++--
 net/filter-buffer.c           |  12 -
 net/net.c                     |  12 +
 qapi-schema.json              | 102 ++++-
 qapi/event.json               |  15 +
 qmp-commands.hx               |  24 +-
 stubs/Makefile.objs           |   1 +
 stubs/migration-colo.c        |  55 +++
 trace-events                  |   8 +
Quoted 13 lines
 vl.c                          |  31 +-
 28 files changed, 1744 insertions(+), 63 deletions(-)
 create mode 100644 include/migration/colo.h
 create mode 100644 include/migration/failover.h
 create mode 100644 migration/colo-comm.c
 create mode 100644 migration/colo-failover.c
 create mode 100644 migration/colo.c
 create mode 100644 stubs/migration-colo.c
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#38 lore raw
Quoted 6 lines · Dr. David Alan Gilbert
Quoted 5 lines · * zhanghailiang ([email protected]) wrote:

This is the 17th version of COLO FT feature.

Here is only COLO frame part, you can get the whole codes from github:
https://github.com/coloft/qemu/commits/colo-v3.0-periodic-mode

Quoted 9 lines
Quoted 3 lines

Migration now switches to use the new QIOChannel API. It only affects COLO's patch 9 and patch 12, which we used the old qsb buffer before, and we updated them with the new API. It's only involving tiny changes.

I notice that the block code has nearly been accepted; so perhaps it's worth posting a version rebased on the current rc and then hopefully we can line this core code up for the start of 2.8 as soon as the block code lands.

Yes, thanks for reminding, I'll post next version in the next few days.

Hailiang

Quoted 153 lines

Dave

Quoted 142 lines

Patch status:
Unreviewed: patch 32 ~ 35
Updated: patch 9, 12, 32

Cc Stefan Hajnoczi <[email protected]>
Cc Jeff Cody <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>
Cc Juan Quintela <[email protected]>
Cc Amit Shah <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
Cc Jason Wang <[email protected]>

PS: These series has been in community for a long time, it depends on Changlong's block-replicaton series, but that has been blocked for a long time, we really need help on reviewing that and this series. Thanks.

TODO:
1. Checkpoint based on proxy in qemu
2. The capability of continuous FT
3. Optimize the VM's downtime during checkpoint

v17:
- Rebase master to use the new QIOChannel API, only affect patch 9 and 12
- Reorganize some ugly comments
- Rename colo_sem to colo_exit_sem (patch 21)

v16:
- Fix compile broken due to missing osdep.h
- Add reviewed-by tag for patch 27, 28, 29
- Rename the message send/receive helper function (patch 7, 13)
- Simplify the codes by using some notifier helpers in QEMU (patch 32)
- Remove the useless check in colo_add_buffer_filter() (patch 33)
- Remove the previous patch 36, 37 which export filter_buffer_flush() to release the buffered packets, we simplify it by stopping buffer filter while doing checkpoint, which will flush the buffered packets by default. (patch 34)
v15:
- Go on the shutdown process if encounter error while sending shutdown message to SVM. (patch 24)
- Rename qemu_need_skip_netfilter to qemu_netfilter_can_skip and Remove some useless comment. (patch 31, Jason)
- Call object_new_with_props() directly to add filter in colo_add_buffer_filter. (patch 34, Jason)
- Re-implement colo_set_filter_status() based on COLOBufferFilters

    list. (patch 35)
  - Re-implement colo_flush_filter_packets() based on COLOBufferFilters
    list. (patch 37)

v14:
- Re-implement the network processing based on netfilter (Jason Wang)
- Rename 'COLOCommand' to 'COLOMessage'. (Markus's suggestion)
- Split two new patches (patch 27/28) from patch 29
- Fix some other comments from Dave and Markus.

v13:
- Refactor colo_*_cmd helper functions to use 'Error **errp' parameter instead of return value to indicate success or failure. (patch 10)
- Remove the optional error message for COLO_EXIT event. (patch 25)
- Use semaphore to notify colo/colo incoming loop that failover work is finished. (patch 26)
- Move COLO shutdown related codes to colo.c file. (patch 28)
- Fix memory leak bug for colo incoming loop. (new patch 31)
- Re-use some existed helper functions to realize the process of saving/loading ram and device. (patch 32)
- Fix some other comments from Dave and Markus.

zhanghailiang (34):
configure: Add parameter for configure to enable/disable COLO support
migration: Introduce capability 'x-colo' to migration
COLO: migrate colo related info to secondary node
migration: Integrate COLO checkpoint process into migration
migration: Integrate COLO checkpoint process into loadvm COLO/migration: Create a new communication path from destination to
source
COLO: Implement COLO checkpoint protocol
COLO: Add a new RunState RUN_STATE_COLO
COLO: Save PVM state to secondary side when do checkpoint
COLO: Load PVM's dirty pages into SVM's RAM cache temporarily ram/COLO: Record the dirty pages that SVM received
COLO: Load VMState into buffer before restore it
COLO: Flush PVM's cached RAM into SVM's memory
COLO: Add checkpoint-delay parameter for migrate-set-parameters
COLO: Synchronize PVM's state to SVM periodically
COLO failover: Introduce a new command to trigger a failover COLO failover: Introduce state to record failover process
COLO: Implement failover work for Primary VM
COLO: Implement failover work for Secondary VM
qmp event: Add COLO_EXIT event to notify users while exited from COLO COLO failover: Shutdown related socket fd when do failover COLO failover: Don't do failover during loading VM's state
COLO: Process shutdown command for VM in COLO state
COLO: Update the global runstate after going into colo state
savevm: Introduce two helper functions for save/find loadvm_handlers
entry
migration/savevm: Add new helpers to process the different stages of
loadvm
migration/savevm: Export two helper functions for savevm process
COLO: Separate the process of saving/loading ram and device state
COLO: Split qemu_savevm_state_begin out of checkpoint process
filter-buffer: Accept zero interval
net: Add notifier/callback for netdev init
COLO/filter: Add each netdev a buffer filter
COLO: Control the status of buffer filters for PVM
COLO: Add block replication into colo process

  configure                     |  11 +
  docs/qmp-events.txt           |  16 +
  hmp-commands.hx               |  15 +
  hmp.c                         |  15 +
  hmp.h                         |   1 +
  include/exec/ram_addr.h       |   1 +
  include/migration/colo.h      |  43 +++
  include/migration/failover.h  |  33 ++
  include/migration/migration.h |  16 +
  include/net/filter.h          |   2 +
  include/net/net.h             |   3 +
  include/sysemu/sysemu.h       |   9 +
  migration/Makefile.objs       |   2 +
  migration/colo-comm.c         |  79 ++++
  migration/colo-failover.c     |  84 +++++
  migration/colo.c              | 844 ++++++++++++++++++++++++++++++++++++++++++
  migration/migration.c         |  84 ++++-
  migration/ram.c               | 175 ++++++++-
  migration/savevm.c            | 114 ++++--
  net/filter-buffer.c           |  12 -
  net/net.c                     |  12 +
  qapi-schema.json              | 102 ++++-
  qapi/event.json               |  15 +
  qmp-commands.hx               |  24 +-
  stubs/Makefile.objs           |   1 +
  stubs/migration-colo.c        |  55 +++
  trace-events                  |   8 +
  vl.c                          |  31 +-
  28 files changed, 1744 insertions(+), 63 deletions(-)

create mode 100644 include/migration/colo.h
create mode 100644 include/migration/failover.h
create mode 100644 migration/colo-comm.c
create mode 100644 migration/colo-failover.c
create mode 100644 migration/colo.c
create mode 100644 stubs/migration-colo.c

Quoted 4 lines

--
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

.

#39 lore raw
Quoted 13 lines · Hailiang Zhang
Quoted 12 lines · Dr. David Alan Gilbert
Quoted 10 lines · * zhanghailiang ([email protected]) wrote:

This is the 17th version of COLO FT feature.

Here is only COLO frame part, you can get the whole codes from github:
https://github.com/coloft/qemu/commits/colo-v3.0-periodic-mode

Migration now switches to use the new QIOChannel API. It only affects COLO's
patch 9 and patch 12, which we used the old qsb buffer before, and we updated
them with the new API. It's only involving tiny changes.

Quoted 8 lines
Quoted 5 lines

I notice that the block code has nearly been accepted; so perhaps it's worth posting a version rebased on the current rc and then hopefully we can line this core code up for the start of 2.8 as soon as the block code lands.

Yes, thanks for reminding, I'll post next version in the next few days.

Hi hailiang

Just a warm reminder. Since colo framework bases on replication, and the replication feature is #optional. Maybe you need check CONFIG_REPLICATION in your new version.

https://github.com//Pating/qemu/tree/block-replication-v24, see "configure: support replication"

Thanks
-Xie

Quoted 165 lines

Hailiang

Quoted 149 lines

Dave

Quoted 147 lines

Patch status:
Unreviewed: patch 32 ~ 35
Updated: patch 9, 12, 32

Cc Stefan Hajnoczi <[email protected]>
Cc Jeff Cody <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>
Cc Juan Quintela <[email protected]>
Cc Amit Shah <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
Cc Jason Wang <[email protected]>

PS: These series has been in community for a long time, it depends on Changlong's block-replicaton series, but that has been blocked for a long
time, we really need help on reviewing that and this series. Thanks.

TODO:
1. Checkpoint based on proxy in qemu
2. The capability of continuous FT
3. Optimize the VM's downtime during checkpoint

v17:
- Rebase master to use the new QIOChannel API, only affect patch 9
and 12
- Reorganize some ugly comments
- Rename colo_sem to colo_exit_sem (patch 21)

v16:
- Fix compile broken due to missing osdep.h
- Add reviewed-by tag for patch 27, 28, 29
- Rename the message send/receive helper function (patch 7, 13)
- Simplify the codes by using some notifier helpers in QEMU (patch 32)
- Remove the useless check in colo_add_buffer_filter() (patch 33)
- Remove the previous patch 36, 37 which export filter_buffer_flush() to release the buffered packets, we simplify it by stopping buffer filter while doing checkpoint, which will flush the buffered packets by default. (patch 34)
v15:
- Go on the shutdown process if encounter error while sending shutdown message to SVM. (patch 24)
- Rename qemu_need_skip_netfilter to qemu_netfilter_can_skip and
Remove
some useless comment. (patch 31, Jason)
- Call object_new_with_props() directly to add filter in colo_add_buffer_filter. (patch 34, Jason)
- Re-implement colo_set_filter_status() based on COLOBufferFilters

    list. (patch 35)
  - Re-implement colo_flush_filter_packets() based on COLOBufferFilters
    list. (patch 37)

v14:
- Re-implement the network processing based on netfilter (Jason Wang)
- Rename 'COLOCommand' to 'COLOMessage'. (Markus's suggestion)
- Split two new patches (patch 27/28) from patch 29
- Fix some other comments from Dave and Markus.

v13:
- Refactor colo_*_cmd helper functions to use 'Error **errp' parameter instead of return value to indicate success or failure. (patch 10)
- Remove the optional error message for COLO_EXIT event. (patch 25)
- Use semaphore to notify colo/colo incoming loop that failover
work is
finished. (patch 26)
- Move COLO shutdown related codes to colo.c file. (patch 28)
- Fix memory leak bug for colo incoming loop. (new patch 31)
- Re-use some existed helper functions to realize the process of saving/loading ram and device. (patch 32)
- Fix some other comments from Dave and Markus.

zhanghailiang (34):
configure: Add parameter for configure to enable/disable COLO support
migration: Introduce capability 'x-colo' to migration
COLO: migrate colo related info to secondary node
migration: Integrate COLO checkpoint process into migration
migration: Integrate COLO checkpoint process into loadvm COLO/migration: Create a new communication path from destination to
source
COLO: Implement COLO checkpoint protocol
COLO: Add a new RunState RUN_STATE_COLO
COLO: Save PVM state to secondary side when do checkpoint
COLO: Load PVM's dirty pages into SVM's RAM cache temporarily ram/COLO: Record the dirty pages that SVM received
COLO: Load VMState into buffer before restore it
COLO: Flush PVM's cached RAM into SVM's memory
COLO: Add checkpoint-delay parameter for migrate-set-parameters
COLO: Synchronize PVM's state to SVM periodically
COLO failover: Introduce a new command to trigger a failover COLO failover: Introduce state to record failover process
COLO: Implement failover work for Primary VM
COLO: Implement failover work for Secondary VM
qmp event: Add COLO_EXIT event to notify users while exited from COLO COLO failover: Shutdown related socket fd when do failover COLO failover: Don't do failover during loading VM's state
COLO: Process shutdown command for VM in COLO state
COLO: Update the global runstate after going into colo state
savevm: Introduce two helper functions for save/find loadvm_handlers
entry
migration/savevm: Add new helpers to process the different stages of
loadvm
migration/savevm: Export two helper functions for savevm process
COLO: Separate the process of saving/loading ram and device state
COLO: Split qemu_savevm_state_begin out of checkpoint process
filter-buffer: Accept zero interval
net: Add notifier/callback for netdev init
COLO/filter: Add each netdev a buffer filter
COLO: Control the status of buffer filters for PVM
COLO: Add block replication into colo process

  configure                     |  11 +
  docs/qmp-events.txt           |  16 +
  hmp-commands.hx               |  15 +
  hmp.c                         |  15 +
  hmp.h                         |   1 +
  include/exec/ram_addr.h       |   1 +
  include/migration/colo.h      |  43 +++
  include/migration/failover.h  |  33 ++
  include/migration/migration.h |  16 +
  include/net/filter.h          |   2 +
  include/net/net.h             |   3 +
  include/sysemu/sysemu.h       |   9 +
  migration/Makefile.objs       |   2 +
  migration/colo-comm.c         |  79 ++++
  migration/colo-failover.c     |  84 +++++
  migration/colo.c              | 844
++++++++++++++++++++++++++++++++++++++++++
  migration/migration.c         |  84 ++++-
  migration/ram.c               | 175 ++++++++-
  migration/savevm.c            | 114 ++++--
  net/filter-buffer.c           |  12 -
  net/net.c                     |  12 +
  qapi-schema.json              | 102 ++++-
  qapi/event.json               |  15 +
  qmp-commands.hx               |  24 +-
  stubs/Makefile.objs           |   1 +
  stubs/migration-colo.c        |  55 +++
  trace-events                  |   8 +
  vl.c                          |  31 +-
  28 files changed, 1744 insertions(+), 63 deletions(-)

create mode 100644 include/migration/colo.h
create mode 100644 include/migration/failover.h
create mode 100644 migration/colo-comm.c
create mode 100644 migration/colo-failover.c
create mode 100644 migration/colo.c
create mode 100644 stubs/migration-colo.c

Quoted 9 lines
Quoted 4 lines

--
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

.

.

#40 lore raw
Quoted 20 lines · Changlong Xie
Quoted 19 lines · Hailiang Zhang
Quoted 17 lines · Dr. David Alan Gilbert
Quoted 10 lines · * zhanghailiang ([email protected]) wrote:

This is the 17th version of COLO FT feature.

Here is only COLO frame part, you can get the whole codes from github:
https://github.com/coloft/qemu/commits/colo-v3.0-periodic-mode

Migration now switches to use the new QIOChannel API. It only affects COLO's
patch 9 and patch 12, which we used the old qsb buffer before, and we updated
them with the new API. It's only involving tiny changes.

I notice that the block code has nearly been accepted; so perhaps it's worth posting a version rebased on the current rc and then hopefully we can line this core code up for the start of 2.8 as soon as the block code lands.

Quoted 9 lines
Quoted 2 lines

Yes, thanks for reminding, I'll post next version in the next few days.

Hi hailiang

Just a warm reminder. Since colo framework bases on replication, and the replication feature is #optional. Maybe you need check CONFIG_REPLICATION in your new version.

OK, i noticed that, thanks.

Quoted 176 lines

https://github.com//Pating/qemu/tree/block-replication-v24, see "configure: support replication"

Thanks
-Xie

Quoted 158 lines

Hailiang

Quoted 156 lines

Dave

Quoted 147 lines

Patch status:
Unreviewed: patch 32 ~ 35
Updated: patch 9, 12, 32

Cc Stefan Hajnoczi <[email protected]>
Cc Jeff Cody <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>
Cc Juan Quintela <[email protected]>
Cc Amit Shah <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
Cc Jason Wang <[email protected]>

PS: These series has been in community for a long time, it depends on Changlong's block-replicaton series, but that has been blocked for a long
time, we really need help on reviewing that and this series. Thanks.

TODO:
1. Checkpoint based on proxy in qemu
2. The capability of continuous FT
3. Optimize the VM's downtime during checkpoint

v17:
- Rebase master to use the new QIOChannel API, only affect patch 9
and 12
- Reorganize some ugly comments
- Rename colo_sem to colo_exit_sem (patch 21)

v16:
- Fix compile broken due to missing osdep.h
- Add reviewed-by tag for patch 27, 28, 29
- Rename the message send/receive helper function (patch 7, 13)
- Simplify the codes by using some notifier helpers in QEMU (patch 32)
- Remove the useless check in colo_add_buffer_filter() (patch 33)
- Remove the previous patch 36, 37 which export filter_buffer_flush() to release the buffered packets, we simplify it by stopping buffer filter while doing checkpoint, which will flush the buffered packets by default. (patch 34)
v15:
- Go on the shutdown process if encounter error while sending shutdown message to SVM. (patch 24)
- Rename qemu_need_skip_netfilter to qemu_netfilter_can_skip and
Remove
some useless comment. (patch 31, Jason)
- Call object_new_with_props() directly to add filter in colo_add_buffer_filter. (patch 34, Jason)
- Re-implement colo_set_filter_status() based on COLOBufferFilters

     list. (patch 35)
   - Re-implement colo_flush_filter_packets() based on COLOBufferFilters
     list. (patch 37)

v14:
- Re-implement the network processing based on netfilter (Jason Wang)
- Rename 'COLOCommand' to 'COLOMessage'. (Markus's suggestion)
- Split two new patches (patch 27/28) from patch 29
- Fix some other comments from Dave and Markus.

v13:
- Refactor colo_*_cmd helper functions to use 'Error **errp' parameter instead of return value to indicate success or failure. (patch 10)
- Remove the optional error message for COLO_EXIT event. (patch 25)
- Use semaphore to notify colo/colo incoming loop that failover
work is
finished. (patch 26)
- Move COLO shutdown related codes to colo.c file. (patch 28)
- Fix memory leak bug for colo incoming loop. (new patch 31)
- Re-use some existed helper functions to realize the process of saving/loading ram and device. (patch 32)
- Fix some other comments from Dave and Markus.

zhanghailiang (34):
configure: Add parameter for configure to enable/disable COLO support
migration: Introduce capability 'x-colo' to migration
COLO: migrate colo related info to secondary node
migration: Integrate COLO checkpoint process into migration
migration: Integrate COLO checkpoint process into loadvm COLO/migration: Create a new communication path from destination to
source
COLO: Implement COLO checkpoint protocol
COLO: Add a new RunState RUN_STATE_COLO
COLO: Save PVM state to secondary side when do checkpoint
COLO: Load PVM's dirty pages into SVM's RAM cache temporarily ram/COLO: Record the dirty pages that SVM received
COLO: Load VMState into buffer before restore it
COLO: Flush PVM's cached RAM into SVM's memory
COLO: Add checkpoint-delay parameter for migrate-set-parameters
COLO: Synchronize PVM's state to SVM periodically
COLO failover: Introduce a new command to trigger a failover COLO failover: Introduce state to record failover process
COLO: Implement failover work for Primary VM
COLO: Implement failover work for Secondary VM
qmp event: Add COLO_EXIT event to notify users while exited from COLO COLO failover: Shutdown related socket fd when do failover COLO failover: Don't do failover during loading VM's state
COLO: Process shutdown command for VM in COLO state
COLO: Update the global runstate after going into colo state
savevm: Introduce two helper functions for save/find loadvm_handlers
entry
migration/savevm: Add new helpers to process the different stages of
loadvm
migration/savevm: Export two helper functions for savevm process
COLO: Separate the process of saving/loading ram and device state
COLO: Split qemu_savevm_state_begin out of checkpoint process
filter-buffer: Accept zero interval
net: Add notifier/callback for netdev init
COLO/filter: Add each netdev a buffer filter
COLO: Control the status of buffer filters for PVM
COLO: Add block replication into colo process

   configure                     |  11 +
   docs/qmp-events.txt           |  16 +
   hmp-commands.hx               |  15 +
   hmp.c                         |  15 +
   hmp.h                         |   1 +
   include/exec/ram_addr.h       |   1 +
   include/migration/colo.h      |  43 +++
   include/migration/failover.h  |  33 ++
   include/migration/migration.h |  16 +
   include/net/filter.h          |   2 +
   include/net/net.h             |   3 +
   include/sysemu/sysemu.h       |   9 +
   migration/Makefile.objs       |   2 +
   migration/colo-comm.c         |  79 ++++
   migration/colo-failover.c     |  84 +++++
   migration/colo.c              | 844
++++++++++++++++++++++++++++++++++++++++++
   migration/migration.c         |  84 ++++-
   migration/ram.c               | 175 ++++++++-
   migration/savevm.c            | 114 ++++--
   net/filter-buffer.c           |  12 -
   net/net.c                     |  12 +
   qapi-schema.json              | 102 ++++-
   qapi/event.json               |  15 +
   qmp-commands.hx               |  24 +-
   stubs/Makefile.objs           |   1 +
   stubs/migration-colo.c        |  55 +++
   trace-events                  |   8 +
   vl.c                          |  31 +-
   28 files changed, 1744 insertions(+), 63 deletions(-)

create mode 100644 include/migration/colo.h create mode 100644 include/migration/failover.h create mode 100644 migration/colo-comm.c create mode 100644 migration/colo-failover.c create mode 100644 migration/colo.c create mode 100644 stubs/migration-colo.c

Quoted 4 lines

--
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Quoted 7 lines
Quoted 2 lines

.

.

.