Skip to contentSkip to conversation

Curling: KVM Fault Tolerance

PATCH Superseded Jules Wang 2 participants 9 messages Sep 29, 2013 – Oct 10, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jules Wang

author
#0 lore raw

v2 cover Curling: KVM Fault Tolerance

v1 -> v2:
* cmdline: migrate curling:tcp:<address>:<port>

       ->  migrate -f tcp:<address>:<port>

* sender: use QEMU_VM_FILE_MAGIC_FT as the header of the migration to indicate this is a ft migration.

* receiver: look for the signature:
QEMU_VM_EOF_MAGIC + QEMU_VM_FILE_MAGIC_FT(64bit total) which indicates the end of one migration.
--
Jules Wang (4):
Curling: add doc
Curling: cmdline interface.
Curling: the sender
Curling: the receiver

 arch_init.c                   |  25 ++++--
 docs/curling.txt              |  51 ++++++++++++
 hmp-commands.hx               |  11 ++-
 hmp.c                         |   3 +-
 include/migration/migration.h |   1 +
 include/migration/qemu-file.h |   1 +
 include/sysemu/sysemu.h       |   5 +-
 migration.c                   |  50 ++++++++++--
 qapi-schema.json              |   3 +-
 qmp-commands.hx               |   3 +-
 savevm.c                      | 178 +++++++++++++++++++++++++++++++++++++++---
 11 files changed, 301 insertions(+), 30 deletions(-)
 create mode 100644 docs/curling.txt
Signature · 1 line
1.8.0.1
author
#1 lore raw

PATCH v2 1/4 Curling: add doc

Curling provides fault tolerant mechanism for KVM. For more info, see 'doc/curling.txt'.

---
 docs/curling.txt | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 docs/curling.txt
docs/curling.txt new file +51 -0
new file mode 100644
index 0000000..f506a77
@@ -0,0 +1,51 @@
+KVM Fault Tolerance Specification
+=================================
+
+
+Contents:
+=========
+* Introduction
+* Usage
+* Design & Implement
+* Performance
+
+Introduction
+============
+The goal of Curling(sports) is to provide a fault tolerant(ft for short)
+mechanism for KVM, so that in the event of a hardware failure, the virtual
+machine fails over to the backup in a way that is completely transparent
+to the guest operating system.
+
+
+Usage
+=====
+The steps of curling are the same as the steps of live migration except the
+following:
+1. Start ft in the qemu monitor of sender vm by following cmdline:
+   > migrate_set_speed <full bandwidth>
+   > migrate -f tcp:<address>:<port>
+2. Connect to the receiver vm by vnc or spice. The screen of the vm is displayed
+when ft is ready.
+3. Now, the sender vm is protected by ft, When it encounters a failure,
+the failover kicks in.
+
+
+
+Design & Implement
+==================
+* By leveraging live migration feature, we do endless live migrations between
+the sender and receiver, so the two virtual machines are synchronized.
+
+* The receiver does not load vm state once the migration begins, instead, it
+perfetches one whole migration data into a buffer, then loads vm state from
+that buffer afterwards. This "all or nothing" approach prevents the
+broken-in-the-middle problem Kemari has.
+
+* The sender sleeps a little while after each migration, to ease the
+performance penalty entailed by vm_stop and iothread locks. This is a
+tradeoff between performance and accuracy.
+....
+
+
+Performance
+===========
Signature · 1 line
1.8.0.1
author
#2 lore raw

PATCH v2 2/4 Curling: cmdline interface.

In reply to Jules Wang

Add an option '-f' to migration cmdline. Indicating whether to enable fault tolerant or not.

---
 hmp-commands.hx               | 11 +++++++----
 hmp.c                         |  3 ++-
 include/migration/migration.h |  1 +
 migration.c                   |  3 ++-
 qapi-schema.json              |  3 ++-
 qmp-commands.hx               |  3 ++-
 6 files changed, 16 insertions(+), 8 deletions(-)
hmp-commands.hx +7 -4
index 65b7f60..8418d37 100644
@@ -877,23 +877,26 @@ ETEXI
 
     {
         .name       = "migrate",
-        .args_type  = "detach:-d,blk:-b,inc:-i,uri:s",
-        .params     = "[-d] [-b] [-i] uri",
+        .args_type  = "detach:-d,blk:-b,inc:-i,ft:-f,uri:s",
+        .params     = "[-d] [-b] [-i] [-f] uri",
         .help       = "migrate to URI (using -d to not wait for completion)"
 		      "\n\t\t\t -b for migration without shared storage with"
 		      " full copy of disk\n\t\t\t -i for migration without "
 		      "shared storage with incremental copy of disk "
-		      "(base image shared between src and destination)",
+		      "(base image shared between src and destination)"
+		      "\n\t\t\t -f for fault tolerant, this is another "
+		      "feature rather than migrate",
         .mhandler.cmd = hmp_migrate,
     },
 
 
 STEXI
-@item migrate [-d] [-b] [-i] @var{uri}
+@item migrate [-d] [-b] [-i] [-f] @var{uri}
 @findex migrate
 Migrate to @var{uri} (using -d to not wait for completion).
 	-b for migration with full copy of disk
 	-i for migration with incremental copy of disk (base image is shared)
+	-f for fault tolerant
 ETEXI
 
     {
hmp.c +2 -1
index fcca6ae..91beae9 100644
@@ -1213,10 +1213,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     int detach = qdict_get_try_bool(qdict, "detach", 0);
     int blk = qdict_get_try_bool(qdict, "blk", 0);
     int inc = qdict_get_try_bool(qdict, "inc", 0);
+    int ft  = qdict_get_try_bool(qdict, "ft", 0);
     const char *uri = qdict_get_str(qdict, "uri");
     Error *err = NULL;
 
-    qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
+    qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, !!ft, ft, &err);
     if (err) {
         monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
         error_free(err);
include/migration/migration.h +1 -0
index 140e6b4..fc2b066 100644
@@ -25,6 +25,7 @@
 
 struct MigrationParams {
     bool blk;
+    bool ft;
     bool shared;
 };
 
migration.c +2 -1
index 200d404..8989a51 100644
@@ -394,7 +394,7 @@ void migrate_del_blocker(Error *reason)
 
 void qmp_migrate(const char *uri, bool has_blk, bool blk,
                  bool has_inc, bool inc, bool has_detach, bool detach,
-                 Error **errp)
+                 bool has_ft, bool ft, Error **errp)
 {
     Error *local_err = NULL;
     MigrationState *s = migrate_get_current();
@@ -403,6 +403,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 
     params.blk = has_blk && blk;
     params.shared = has_inc && inc;
+    params.ft = has_ft && ft;
 
     if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP) {
         error_set(errp, QERR_MIGRATION_ACTIVE);
qapi-schema.json +2 -1
index a51f7d2..a8187cf 100644
@@ -2420,7 +2420,8 @@
 # Since: 0.14.0
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
+  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool',
+           '*ft': 'bool' } }
 
 # @xen-save-devices-state:
 #
qmp-commands.hx +2 -1
index 8a8f342..1fa0e60 100644
@@ -611,7 +611,7 @@ EQMP
 
     {
         .name       = "migrate",
-        .args_type  = "detach:-d,blk:-b,inc:-i,uri:s",
+        .args_type  = "detach:-d,blk:-b,inc:-i,ft:-f,uri:s",
         .mhandler.cmd_new = qmp_marshal_input_migrate,
     },
 
@@ -625,6 +625,7 @@ Arguments:
 
 - "blk": block migration, full disk copy (json-bool, optional)
 - "inc": incremental disk copy (json-bool, optional)
+- "ft" : fault tolerant (json-bool, optional)
 - "uri": Destination URI (json-string)
 
 Example:
Signature · 1 line
1.8.0.1
#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/4] Curling: cmdline interface.

hmp-commands.hx ETEXI · line 888

Quoted 13 lines · Jules Wang

Add an option '-f' to migration cmdline. Indicating whether to enable fault tolerant or not.

---
.help = "migrate to URI (using -d to not wait for completion)"

hmp-commands.hx +3 -1
 		      "\n\t\t\t -b for migration without shared storage with"
 		      " full copy of disk\n\t\t\t -i for migration without "
 		      "shared storage with incremental copy of disk "
-		      "(base image shared between src and destination)",
+		      "(base image shared between src and destination)"
+		      "\n\t\t\t -f for fault tolerant, this is another "
+		      "feature rather than migrate",

That sounds awkward, and overly long. Maybe go with just:

-f for fault tolerance mode

and let the user then read the full documentation for what it entails.

hmp-commands.hx ETEXI · line 899

Quoted 7 lines

-@item migrate [-d] [-b] [-i] @var{uri}
+@item migrate [-d] [-b] [-i] [-f] @var{uri}
@findex migrate
Migrate to @var{uri} (using -d to not wait for completion).

hmp-commands.hx +1 -0
 	-b for migration with full copy of disk
 	-i for migration with incremental copy of disk (base image is shared)
+	-f for fault tolerant

Can -d and -f be used at the same time, or are they exclusive?

hmp.c void hmp_migrate(Monitor *mon, const QDict *qdict) · line 1216

Quoted 6 lines

+++ b/hmp.c

hmp.c +1 -0
@@ -1213,10 +1213,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     int detach = qdict_get_try_bool(qdict, "detach", 0);
     int blk = qdict_get_try_bool(qdict, "blk", 0);
     int inc = qdict_get_try_bool(qdict, "inc", 0);
+    int ft  = qdict_get_try_bool(qdict, "ft", 0);

Why two spaces?

qapi-schema.json line 2424

Quoted 8 lines
qapi-schema.json +3 -1
+++ b/qapi-schema.json
@@ -2420,7 +2420,8 @@
 # Since: 0.14.0
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
+  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool',
+           '*ft': 'bool' } }

Missing documentation, including mention that the new option was only made available in 1.7. We still don't have introspection; is there some other means by which libvirt and other management apps can tell whether this feature is available? Furthermore, 'ft' is an awfully short name; for QMP, we prefer to use full words where possible, such as 'fault-tolerant'.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw

Re: [Qemu-devel] [PATCH v2 2/4] Curling: cmdline interface.

At 2013-10-01 06:16:34,"Eric Blake" <[email protected]> wrote: >On 09/29/2013 02:14 PM, Jules Wang wrote: >> Add an option '-f' to migration cmdline. >> Indicating whether to enable fault tolerant or not. >> >> Signed-off-by: Jules Wang <[email protected]> >> --- >> .help = "migrate to URI (using -d to not wait for completion)" >> "\n\t\t\t -b for migration without shared storage with" >> " full copy of disk\n\t\t\t -i for migration without " >> "shared storage with incremental copy of disk " >> - "(base image shared between src and destination)", >> + "(base image shared between src and destination)" >> + "\n\t\t\t -f for fault tolerant, this is another " >> + "feature rather than migrate", > >That sounds awkward, and overly long. Maybe go with just: > >-f for fault tolerance mode > >and let the user then read the full documentation for what it entails.

Agree.

Quoted 9 lines

hmp-commands.hx ETEXI · line 899

Quoted 7 lines

-@item migrate [-d] [-b] [-i] @var{uri}
+@item migrate [-d] [-b] [-i] [-f] @var{uri}
@findex migrate
Migrate to @var{uri} (using -d to not wait for completion).

hmp-commands.hx +1 -0
 	-b for migration with full copy of disk
 	-i for migration with incremental copy of disk (base image is shared)
+	-f for fault tolerant

Can -d and -f be used at the same time, or are they exclusive?

AFAK, The migration is always detached(In the code, the -d option is always false), -d and -f can be used at the same time with no doubt. qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, !!ft, ft, &err);

By the way, neither -b nor -i could be used at the same time with -f, fault tolerant needs shared storage.

Quoted 8 lines

hmp.c void hmp_migrate(Monitor *mon, const QDict *qdict) · line 1216

Quoted 6 lines

+++ b/hmp.c

hmp.c +1 -0
@@ -1213,10 +1213,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     int detach = qdict_get_try_bool(qdict, "detach", 0);
     int blk = qdict_get_try_bool(qdict, "blk", 0);
     int inc = qdict_get_try_bool(qdict, "inc", 0);
+   int ft   = qdict_get_try_bool(qdict, "ft", 0);

Why two spaces?

To align the '=', I will remove them if you like.

Quoted 14 lines

qapi-schema.json line 2424

Quoted 9 lines
qapi-schema.json +3 -1
+++ b/qapi-schema.json
@@ -2420,7 +2420,8 @@
 # Since: 0.14.0
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
+  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool',
+           '*ft': 'bool' } }

Missing documentation, including mention that the new option was only made available in 1.7. We still don't have introspection; is there some other means by which libvirt and other management apps can tell whether this feature is available?

I'm not clear about how to do that, could you pls give me some hints, where to add code and documentation.

Quoted 3 lines

Furthermore, 'ft' is an awfully short name;
for QMP, we prefer to use full words where possible, such as 'fault-tolerant'.

Agree.

Quoted 4 lines
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw

Re: [Qemu-devel] [PATCH v2 2/4] Curling: cmdline interface.

[your emailer munged the reply, making it a bit hard to read. Are you set for plain-text-only mail to the list?]

Quoted 10 lines · On 10/09/2013 12:49 AM, [email protected] wrote:
Quoted 8 lines

hmp.c void hmp_migrate(Monitor *mon, const QDict *qdict) · line 1216

Quoted 6 lines

+++ b/hmp.c

hmp.c +1 -0
@@ -1213,10 +1213,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     int detach = qdict_get_try_bool(qdict, "detach", 0);
     int blk = qdict_get_try_bool(qdict, "blk", 0);
     int inc = qdict_get_try_bool(qdict, "inc", 0);
+   int ft   = qdict_get_try_bool(qdict, "ft", 0);

Why two spaces?

To align the '=', I will remove them if you like.

It's not a problem with me either way, other than we have a lot of code that doesn't care about alignment and consistently uses one space, and a fair amount of code where everything in a block of code is consistently aligned. But your patch was neither, in the context of the block it lives within - if you're going to align, then line up everything with the longest line 'int detach' (including blk and inc).

Quoted 16 lines
Quoted 15 lines

qapi-schema.json line 2424

Quoted 10 lines
qapi-schema.json +3 -1
+++ b/qapi-schema.json
@@ -2420,7 +2420,8 @@
 # Since: 0.14.0
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
+  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool',
+           '*ft': 'bool' } }

Missing documentation, including mention that the new option was only made available in 1.7. We still don't have introspection; is there some other means by which libvirt and other management apps can tell whether this feature is available?

Quoted 2 lines

I'm not clear about how to do that, could you pls give me some hints, where to add code and documentation.

As for the documentation, qapi-schema.json has plenty of examples (look for a field with "(since 1.7)" as a hint for how to document an optional field added in a later release than the main struct).

As for the introspection, Amos Kong was most recently working on trying to add that (but missed the 1.6 deadline, and I haven't seen work on it since). Introspection is not a hard requirement, but it makes it harder for libvirt to know if it can use 'ft':true if there is no other 'query-*' command that it can call first that would give it a hint that this is a new enough qemu to support 'ft' during migration. Maybe even having something listed under query-migrate-capabilities would be sufficient (ie. modify the 'MigrationCapability' enum to advertise a new capability).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#6 lore raw

Re: [Qemu-devel] [PATCH v2 2/4] Curling: cmdline interface.

Quoted 2 lines · Eric Blake

[your emailer munged the reply, making it a bit hard to read. Are you set for plain-text-only mail to the list?]

Thanks VERY much for remind me that, I'm using another client now.

Quoted 11 lines · On 10/09/2013 12:49 AM, [email protected] wrote:
Quoted 10 lines
Quoted 9 lines

hmp.c void hmp_migrate(Monitor *mon, const QDict *qdict) · line 1216

Quoted 7 lines

+++ b/hmp.c

hmp.c +1 -0
@@ -1213,10 +1213,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     int detach = qdict_get_try_bool(qdict, "detach", 0);
     int blk = qdict_get_try_bool(qdict, "blk", 0);
     int inc = qdict_get_try_bool(qdict, "inc", 0);
+   int ft   = qdict_get_try_bool(qdict, "ft", 0);

Why two spaces?

Quoted 9 lines
Quoted 1 line

To align the '=', I will remove them if you like.

It's not a problem with me either way, other than we have a lot of code that doesn't care about alignment and consistently uses one space, and a fair amount of code where everything in a block of code is consistently aligned. But your patch was neither, in the context of the block it lives within - if you're going to align, then line up everything with the longest line 'int detach' (including blk and inc).

oh, I got it, you are right, I missed the longest line 'int detach ...' I'm not going to align them.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

qapi-schema.json line 2424

Quoted 10 lines
qapi-schema.json +3 -1
+++ b/qapi-schema.json
@@ -2420,7 +2420,8 @@
 # Since: 0.14.0
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
+  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool',
+           '*ft': 'bool' } }

Missing documentation, including mention that the new option was only made available in 1.7. We still don't have introspection; is there some other means by which libvirt and other management apps can tell whether this feature is available?

Quoted 6 lines
Quoted 2 lines

I'm not clear about how to do that, could you pls give me some hints, where to add code and documentation.

As for the documentation, qapi-schema.json has plenty of examples (look for a field with "(since 1.7)" as a hint for how to document an optional field added in a later release than the main struct).

I see. Thanks.

Quoted 10 lines

As for the introspection, Amos Kong was most recently working on trying to add that (but missed the 1.6 deadline, and I haven't seen work on it since). Introspection is not a hard requirement, but it makes it harder for libvirt to know if it can use 'ft':true if there is no other 'query-*' command that it can call first that would give it a hint that this is a new enough qemu to support 'ft' during migration. Maybe even having something listed under query-migrate-capabilities would be sufficient (ie. modify the 'MigrationCapability' enum to advertise a new capability).

Adding a new migration capability is a work-around method. we turn on ft by using the -f option instead of setting fault-tolerant-capability to true. I hesitate to add it.

What about adding a query for the options of migration similar to @query-command-line-options?

author
#7 lore raw

PATCH v2 3/4 Curling: the sender

In reply to Jules Wang

By leveraging live migration feature, the sender simply starts a new migration when the previous migration is completed.

We need to handle the variables related to live migration very carefully. So the new migration does not restart from the very begin of the migration, instead, it continues the previous migration.

---
 arch_init.c             | 25 ++++++++++++++++++++-----
 include/sysemu/sysemu.h |  3 ++-
 migration.c             | 25 +++++++++++++++++++++++--
 savevm.c                | 20 ++++++++++++++++----
 4 files changed, 61 insertions(+), 12 deletions(-)
arch_init.c +20 -5
index e47e139..cd0e0b1 100644
@@ -107,6 +107,7 @@ const uint32_t arch_type = QEMU_ARCH;
 static bool mig_throttle_on;
 static int dirty_rate_high_cnt;
 static void check_guest_throttling(void);
+static MigrationParams ram_mig_params;
 
 /***********************************************************/
 /* ram save/restore */
@@ -596,6 +597,11 @@ static void ram_migration_cancel(void *opaque)
     migration_end();
 }
 
+static void ram_set_params(const MigrationParams *params, void *opaque)
+{
+    ram_mig_params.ft = params->ft;
+}
+
 static void reset_ram_globals(void)
 {
     last_seen_block = NULL;
@@ -611,10 +617,14 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
     int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS;
+    bool create = false;
 
-    migration_bitmap = bitmap_new(ram_pages);
-    bitmap_set(migration_bitmap, 0, ram_pages);
-    migration_dirty_pages = ram_pages;
+    if (!ram_mig_params.ft || !migration_bitmap)  {
+        migration_bitmap = bitmap_new(ram_pages);
+        bitmap_set(migration_bitmap, 0, ram_pages);
+        migration_dirty_pages = ram_pages;
+        create = true;
+    }
     mig_throttle_on = false;
     dirty_rate_high_cnt = 0;
 
@@ -634,7 +644,9 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
     qemu_mutex_lock_iothread();
     qemu_mutex_lock_ramlist();
     bytes_transferred = 0;
-    reset_ram_globals();
+    if (!ram_mig_params.ft || create) {
+        reset_ram_globals();
+    }
 
     memory_global_dirty_log_start();
     migration_bitmap_sync();
@@ -744,7 +756,9 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
     }
 
     ram_control_after_iterate(f, RAM_CONTROL_FINISH);
-    migration_end();
+    if (!ram_mig_params.ft) {
+        migration_end();
+    }
 
     qemu_mutex_unlock_ramlist();
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
@@ -970,6 +984,7 @@ SaveVMHandlers savevm_ram_handlers = {
     .save_live_pending = ram_save_pending,
     .load_state = ram_load,
     .cancel = ram_migration_cancel,
+    .set_params = ram_set_params,
 };
 
 struct soundhw {
include/sysemu/sysemu.h +2 -1
index b1aa059..dabade4 100644
@@ -77,7 +77,8 @@ bool qemu_savevm_state_blocked(Error **errp);
 void qemu_savevm_state_begin(QEMUFile *f,
                              const MigrationParams *params);
 int qemu_savevm_state_iterate(QEMUFile *f);
-void qemu_savevm_state_complete(QEMUFile *f);
+void qemu_savevm_state_complete(QEMUFile *f,
+                                const MigrationParams *params);
 void qemu_savevm_state_cancel(void);
 uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size);
 int qemu_loadvm_state(QEMUFile *f);
migration.c +23 -2
index 8989a51..bf17c63 100644
@@ -552,6 +552,7 @@ static void *migration_thread(void *opaque)
     int64_t max_size = 0;
     int64_t start_time = initial_time;
     bool old_vm_running = false;
+    int  time_window = 100;
 
     DPRINTF("beginning savevm\n");
     qemu_savevm_state_begin(s->file, &s->params);
@@ -563,6 +564,8 @@ static void *migration_thread(void *opaque)
 
     while (s->state == MIG_STATE_ACTIVE) {
         int64_t current_time;
+        int64_t time_spent;
+        int64_t migration_start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
         uint64_t pending_size;
 
         if (!qemu_file_rate_limit(s->file)) {
@@ -583,7 +586,7 @@ static void *migration_thread(void *opaque)
                 ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
                 if (ret >= 0) {
                     qemu_file_set_rate_limit(s->file, INT_MAX);
-                    qemu_savevm_state_complete(s->file);
+                    qemu_savevm_state_complete(s->file, &s->params);
                 }
                 qemu_mutex_unlock_iothread();
 
@@ -592,10 +595,28 @@ static void *migration_thread(void *opaque)
                     break;
                 }
 
-                if (!qemu_file_get_error(s->file)) {
+                if (!qemu_file_get_error(s->file) && !s->params.ft) {
                     migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED);
                     break;
                 }
+
+                if (s->params.ft) {
+                    if (old_vm_running) {
+                        qemu_mutex_lock_iothread();
+                        vm_start();
+                        qemu_mutex_unlock_iothread();
+
+                        current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+                        time_spent = current_time - migration_start_time;
+                        DPRINTF("this migration lasts for %" PRId64 "ms\n",
+                                time_spent);
+                        if (time_spent < time_window) {
+                            g_usleep((time_window - time_spent)*1000);
+                            initial_time += time_window - time_spent;
+                        }
+                    }
+                    qemu_savevm_state_begin(s->file, &s->params);
+                }
             }
         }
 
savevm.c +16 -4
index c536aa4..556c0e7 100644
@@ -1815,6 +1815,7 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se)
 }
 
 #define QEMU_VM_FILE_MAGIC           0x5145564d
+#define QEMU_VM_FILE_MAGIC_FT        0x51454654
 #define QEMU_VM_FILE_VERSION_COMPAT  0x00000002
 #define QEMU_VM_FILE_VERSION         0x00000003
 
@@ -1824,6 +1825,7 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se)
 #define QEMU_VM_SECTION_END          0x03
 #define QEMU_VM_SECTION_FULL         0x04
 #define QEMU_VM_SUBSECTION           0x05
+#define QEMU_VM_EOF_MAGIC            0xFEEDCAFE
 
 bool qemu_savevm_state_blocked(Error **errp)
 {
@@ -1851,7 +1853,12 @@ void qemu_savevm_state_begin(QEMUFile *f,
         se->ops->set_params(params, se->opaque);
     }
     
-    qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
+    if (params->ft) {
+        qemu_put_be32(f, QEMU_VM_FILE_MAGIC_FT);
+    } else {
+        qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
+    }
+
     qemu_put_be32(f, QEMU_VM_FILE_VERSION);
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
@@ -1930,7 +1937,8 @@ int qemu_savevm_state_iterate(QEMUFile *f)
     return ret;
 }
 
-void qemu_savevm_state_complete(QEMUFile *f)
+void qemu_savevm_state_complete(QEMUFile *f,
+                                const MigrationParams *params)
 {
     SaveStateEntry *se;
     int ret;
@@ -1983,6 +1991,9 @@ void qemu_savevm_state_complete(QEMUFile *f)
     }
 
     qemu_put_byte(f, QEMU_VM_EOF);
+    if (params->ft) {
+        qemu_put_be32(f, QEMU_VM_EOF_MAGIC);
+    }
     qemu_fflush(f);
 }
 
@@ -2021,7 +2032,8 @@ static int qemu_savevm_state(QEMUFile *f)
     int ret;
     MigrationParams params = {
         .blk = 0,
-        .shared = 0
+        .shared = 0,
+        .ft = 0
     };
 
     if (qemu_savevm_state_blocked(NULL)) {
@@ -2040,7 +2052,7 @@ static int qemu_savevm_state(QEMUFile *f)
 
     ret = qemu_file_get_error(f);
     if (ret == 0) {
-        qemu_savevm_state_complete(f);
+        qemu_savevm_state_complete(f, &params);
         ret = qemu_file_get_error(f);
     }
     if (ret != 0) {
Signature · 1 line
1.8.0.1
author
#8 lore raw

PATCH v2 4/4 Curling: the receiver

In reply to Jules Wang

The receiver does migration loop until the migration connection is lost. Then, it is started as a backup.

The receiver does not load vm state once the migration begins. Instead, it perfetches one whole migration data into a buffer, then loads vm state from that buffer afterwards.

---
 include/migration/qemu-file.h |   1 +
 include/sysemu/sysemu.h       |   2 +
 migration.c                   |  22 ++++--
 savevm.c                      | 158 ++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 173 insertions(+), 10 deletions(-)
include/migration/qemu-file.h +1 -0
index 0f757fb..f01ff10 100644
@@ -92,6 +92,7 @@ typedef struct QEMUFileOps {
     QEMURamHookFunc *after_ram_iterate;
     QEMURamHookFunc *hook_ram_load;
     QEMURamSaveFunc *save_page;
+    QEMUFileGetBufferFunc *get_prefetch_buffer;
 } QEMUFileOps;
 
 QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops);
include/sysemu/sysemu.h +2 -0
index dabade4..0058987 100644
@@ -82,6 +82,8 @@ void qemu_savevm_state_complete(QEMUFile *f,
 void qemu_savevm_state_cancel(void);
 uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size);
 int qemu_loadvm_state(QEMUFile *f);
+int qemu_loadvm_state_ft(QEMUFile *f);
+bool is_ft_migration(QEMUFile *f);
 
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
migration.c +17 -5
index bf17c63..64e7007 100644
@@ -19,6 +19,7 @@
 #include "monitor/monitor.h"
 #include "migration/qemu-file.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/cpus.h"
 #include "block/block.h"
 #include "qemu/sockets.h"
 #include "migration/block.h"
@@ -101,13 +102,24 @@ static void process_incoming_migration_co(void *opaque)
 {
     QEMUFile *f = opaque;
     int ret;
+    int count = 0;
 
-    ret = qemu_loadvm_state(f);
-    qemu_fclose(f);
-    if (ret < 0) {
-        fprintf(stderr, "load of migration failed\n");
-        exit(EXIT_FAILURE);
+    if (is_ft_migration(f)) {
+        while (qemu_loadvm_state_ft(f) >= 0) {
+            count++;
+            DPRINTF("incoming count %d\r", count);
+        }
+        qemu_fclose(f);
+        DPRINTF("ft connection lost, launching self..\n");
+    } else {
+        ret = qemu_loadvm_state(f);
+        qemu_fclose(f);
+        if (ret < 0) {
+            fprintf(stderr, "load of migration failed\n");
+            exit(EXIT_FAILURE);
+        }
     }
+    cpu_synchronize_all_post_init();
     qemu_announce_self();
     DPRINTF("successfully loaded vm state\n");
 
savevm.c +153 -5

249 lines not on this page · raw message

Signature · 1 line
1.8.0.1