Skip to contentSkip to conversation

Localhost live migration

RFC PATCH Superseded Lei Li 4 participants 21 messages Jun 16, 2013 – Aug 2, 2013 Kbuild

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Lei Li

author
#0 lore raw

cover Localhost live migration

Hi,

This patch series tries to add localhost live migration support to Qemu. It is just a draft version which is far from completing and I am still working on, send it out to have your suggestions and make sure it is the way should be headed. Your comments are very appreciated!

When doing localhost live migration, the host memory will balloon up during the period, might consume double memories for some time. So we want to add a new live migration mechanism localhost live migration.

The plan is:

1) Add new command to do localhost migration.

The qmp interface introduced like:

{ 'command': 'localhost-migrate', 'data': {'uri': 'str'} }

2) Use different mechanism than current live migration.

The very basic work flow like:

       qemu on the source (the source and destination are both on localhost)
              |
              V
           Stop VM
              |
              V   
          Create threads
              |
              V
       Page flipping through vmspice
              |
              V
       MADV_DONTNEED the ram pages which are already flipped
              |
              V
       Migration completes

As stopping VM first, we expect/resume the page flipping through vmspice is fast enough to meet *live migration (low downtime).

Notes:
Currently the work flow is not exactly the same as description above. For the first step, the work flow we plan to implement is:
stop VM and copy ram pages via unix domain socket, MADV_DONTNEED ram pages that already copied. After that, will replace to vmsplice mechanism instead of copying pages.

TODO:
- Working on the completing of ram copy and MADV_DONTNEED part.
- Introduce a mechanism to exchange a PIPE via SCM_RIGHTS.
- benchmark/evaluation.

Lei Li (7):
migration: export MIG_STATE_xxx flags
savevm: export qemu_save_device_state()
arch_init: add ram_madvise_free()
migration-local: implementation of outgoing part
migration-local: impelementation of incoming part
migration-local: add option to command line for local incoming hmp:add hmp_localhost_migration interface

 Makefile.objs                 |    1 +
 arch_init.c                   |   13 ++++
 hmp-commands.hx               |   17 +++++
 hmp.c                         |   13 ++++
 hmp.h                         |    1 +
 include/migration/migration.h |   32 +++++++++
 include/sysemu/sysemu.h       |    1 +
 migration-local.c             |  155 +++++++++++++++++++++++++++++++++++++++++
 migration-unix.c              |   60 ++++++++++++++++
 migration.c                   |    8 --
 qapi-schema.json              |   14 ++++
 qemu-options.hx               |    9 +++
 qmp-commands.hx               |   22 ++++++
 savevm.c                      |    2 +-
 vl.c                          |   14 ++++
 15 files changed, 353 insertions(+), 9 deletions(-)
 create mode 100644 migration-local.c
author
#1 lore raw

PATCH 1/7 migration: export MIG_STATE_xxx flags

---
 include/migration/migration.h |    8 ++++++++
 migration.c                   |    8 --------
 2 files changed, 8 insertions(+), 8 deletions(-)
include/migration/migration.h +8 -0
index e2acec6..8866c3c 100644
@@ -22,6 +22,14 @@
 #include "migration/vmstate.h"
 #include "qapi-types.h"
 
+enum {
+    MIG_STATE_ERROR,
+    MIG_STATE_SETUP,
+    MIG_STATE_CANCELLED,
+    MIG_STATE_ACTIVE,
+    MIG_STATE_COMPLETED,
+};
+
 struct MigrationParams {
     bool blk;
     bool shared;
migration.c +0 -8
index 058f9e6..0921ace 100644
@@ -35,14 +35,6 @@
     do { } while (0)
 #endif
 
-enum {
-    MIG_STATE_ERROR,
-    MIG_STATE_SETUP,
-    MIG_STATE_CANCELLED,
-    MIG_STATE_ACTIVE,
-    MIG_STATE_COMPLETED,
-};
-
 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
 
 /* Amount of time to allocate to each "chunk" of bandwidth-throttled
Signature · 1 line
1.7.7.6
#2 lore raw

Re: [Qemu-devel] [PATCH 1/7] migration: export MIG_STATE_xxx flags

Quoted 12 lines · Lei Li
---
 include/migration/migration.h |    8 ++++++++
 migration.c                   |    8 --------
 2 files changed, 8 insertions(+), 8 deletions(-)
include/migration/migration.h +0 -0
index e2acec6..8866c3c 100644
@@ -22,6 +22,14 @@
 #include "migration/vmstate.h"

include/migration/migration.h line 32

Quoted 10 lines
include/migration/migration.h +8 -0
 #include "qapi-types.h"
 
+enum {
+    MIG_STATE_ERROR,
+    MIG_STATE_SETUP,
+    MIG_STATE_CANCELLED,
+    MIG_STATE_ACTIVE,
+    MIG_STATE_COMPLETED,
+};
+

If these flags are being exported, it would be nice to provide comments describing what each state corresponded to.

Regards,

Anthony Liguori

Quoted 24 lines
include/migration/migration.h +0 -0
 struct MigrationParams {
     bool blk;
     bool shared;
migration.c +0 -8
index 058f9e6..0921ace 100644
@@ -35,14 +35,6 @@
     do { } while (0)
 #endif
 
-enum {
-    MIG_STATE_ERROR,
-    MIG_STATE_SETUP,
-    MIG_STATE_CANCELLED,
-    MIG_STATE_ACTIVE,
-    MIG_STATE_COMPLETED,
-};
-
 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
 
 /* Amount of time to allocate to each "chunk" of bandwidth-throttled
Signature · 1 line
1.7.7.6
author
#3 lore raw

Re: [Qemu-devel] [PATCH 1/7] migration: export MIG_STATE_xxx flags

Quoted 16 lines · Anthony Liguori
Quoted 14 lines · Lei Li
---
  include/migration/migration.h |    8 ++++++++
  migration.c                   |    8 --------
  2 files changed, 8 insertions(+), 8 deletions(-)
include/migration/migration.h +0 -0
index e2acec6..8866c3c 100644
@@ -22,6 +22,14 @@
  #include "migration/vmstate.h"
  #include "qapi-types.h"
 
Quoted 10 lines

include/migration/migration.h line 32

Quoted 8 lines
include/migration/migration.h +8 -0
+enum {
+    MIG_STATE_ERROR,
+    MIG_STATE_SETUP,
+    MIG_STATE_CANCELLED,
+    MIG_STATE_ACTIVE,
+    MIG_STATE_COMPLETED,
+};
+

If these flags are being exported, it would be nice to provide comments describing what each state corresponded to.

Got it, thanks.

Quoted 29 lines

Regards,

Anthony Liguori

Quoted 24 lines
include/migration/migration.h +0 -0
  struct MigrationParams {
      bool blk;
      bool shared;
migration.c +0 -8
index 058f9e6..0921ace 100644
@@ -35,14 +35,6 @@
      do { } while (0)
  #endif
 
-enum {
-    MIG_STATE_ERROR,
-    MIG_STATE_SETUP,
-    MIG_STATE_CANCELLED,
-    MIG_STATE_ACTIVE,
-    MIG_STATE_COMPLETED,
-};
-
  #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
 
  /* Amount of time to allocate to each "chunk" of bandwidth-throttled
Signature · 1 line
1.7.7.6
Signature · 1 line
Lei
author
#4 lore raw

PATCH 2/7 savevm: export qemu_save_device_state()

In reply to Lei Li
---
 include/sysemu/sysemu.h |    1 +
 savevm.c                |    2 +-
 2 files changed, 2 insertions(+), 1 deletions(-)
include/sysemu/sysemu.h +1 -0
index 2fb71af..5b90027 100644
@@ -80,6 +80,7 @@ int qemu_savevm_state_iterate(QEMUFile *f);
 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_save_device_state(QEMUFile *f);
 int qemu_loadvm_state(QEMUFile *f);
 
 /* SLIRP */
savevm.c +1 -1
index 2ce439f..e3ad5da 100644
@@ -2006,7 +2006,7 @@ static int qemu_savevm_state(QEMUFile *f)
     return ret;
 }
 
-static int qemu_save_device_state(QEMUFile *f)
+int qemu_save_device_state(QEMUFile *f)
 {
     SaveStateEntry *se;
 
Signature · 1 line
1.7.7.6
#5 lore raw

Re: [Qemu-devel] [PATCH 2/7] savevm: export qemu_save_device_state()

Quoted 11 lines · Lei Li
---
 include/sysemu/sysemu.h |    1 +
 savevm.c                |    2 +-
 2 files changed, 2 insertions(+), 1 deletions(-)
include/sysemu/sysemu.h +0 -0
index 2fb71af..5b90027 100644

include/sysemu/sysemu.h int qemu_savevm_state_iterate(QEMUFile *f); · line 84

Quoted 5 lines
include/sysemu/sysemu.h +1 -0
@@ -80,6 +80,7 @@ int qemu_savevm_state_iterate(QEMUFile *f);
 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_save_device_state(QEMUFile *f);
 int qemu_loadvm_state(QEMUFile *f);

Please add comments describing what this function does. I know they're absent for the rest of the functions but we have to start somewhere.

Regards,

Anthony Liguori

Quoted 17 lines
include/sysemu/sysemu.h +0 -0
 /* SLIRP */
savevm.c +1 -1
index 2ce439f..e3ad5da 100644
@@ -2006,7 +2006,7 @@ static int qemu_savevm_state(QEMUFile *f)
     return ret;
 }
 
-static int qemu_save_device_state(QEMUFile *f)
+int qemu_save_device_state(QEMUFile *f)
 {
     SaveStateEntry *se;
 
Signature · 1 line
1.7.7.6
author
#6 lore raw

Re: [Qemu-devel] [PATCH 2/7] savevm: export qemu_save_device_state()

Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Lei Li
---
  include/sysemu/sysemu.h |    1 +
  savevm.c                |    2 +-
  2 files changed, 2 insertions(+), 1 deletions(-)
Quoted 12 lines

include/sysemu/sysemu.h int qemu_savevm_state_iterate(QEMUFile *f); · line 84

Quoted 10 lines
include/sysemu/sysemu.h +1 -0
index 2fb71af..5b90027 100644
@@ -80,6 +80,7 @@ int qemu_savevm_state_iterate(QEMUFile *f);
  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_save_device_state(QEMUFile *f);
  int qemu_loadvm_state(QEMUFile *f);

Please add comments describing what this function does. I know they're absent for the rest of the functions but we have to start somewhere.

OK, will do.

Quoted 22 lines

Regards,

Anthony Liguori

Quoted 17 lines
include/sysemu/sysemu.h +0 -0
  /* SLIRP */
savevm.c +1 -1
index 2ce439f..e3ad5da 100644
@@ -2006,7 +2006,7 @@ static int qemu_savevm_state(QEMUFile *f)
      return ret;
  }
 
-static int qemu_save_device_state(QEMUFile *f)
+int qemu_save_device_state(QEMUFile *f)
  {
      SaveStateEntry *se;
 
Signature · 1 line
1.7.7.6
Signature · 1 line
Lei
author
#7 lore raw

PATCH 3/7 arch_init: add ram_madvise_free()

In reply to Lei Li
---
 arch_init.c                   |   13 +++++++++++++
 include/migration/migration.h |    3 +++
 2 files changed, 16 insertions(+), 0 deletions(-)
arch_init.c +13 -0
index 872020e..fc66bd2 100644
@@ -524,6 +524,19 @@ uint64_t ram_bytes_total(void)
     return total;
 }
 
+void ram_madvise_free(ram_addr_t size)
+{
+    void *ram;
+    RAMBlock *block = NULL;
+
+    ram = memory_region_get_ram_ptr(block->mr);
+
+    /* XXX. Here just simplely madvise(.., MADV_DONTNEED) the whole ram
+     * pages, need more work to keep MADV_DONTNEED ram pages that
+     * already sent. */
+    qemu_madvise(ram, size, MADV_DONTNEED);
+}
+
 static void migration_end(void)
 {
     if (migration_bitmap) {
include/migration/migration.h +3 -0
index 8866c3c..9cc5285 100644
@@ -21,6 +21,7 @@
 #include "qapi/error.h"
 #include "migration/vmstate.h"
 #include "qapi-types.h"
+#include "exec/memory.h"
 
 enum {
     MIG_STATE_ERROR,
@@ -100,6 +101,8 @@ uint64_t ram_bytes_remaining(void);
 uint64_t ram_bytes_transferred(void);
 uint64_t ram_bytes_total(void);
 
+void ram_madvise_free(ram_addr_t size);
+
 extern SaveVMHandlers savevm_ram_handlers;
 
 uint64_t dup_mig_bytes_transferred(void);
Signature · 1 line
1.7.7.6
#8 lore raw

Re: [Qemu-devel] [PATCH 3/7] arch_init: add ram_madvise_free()

Quoted 17 lines · Lei Li
---
 arch_init.c                   |   13 +++++++++++++
 include/migration/migration.h |    3 +++
 2 files changed, 16 insertions(+), 0 deletions(-)
arch_init.c +3 -0
index 872020e..fc66bd2 100644
@@ -524,6 +524,19 @@ uint64_t ram_bytes_total(void)
     return total;
 }
 
+void ram_madvise_free(ram_addr_t size)
+{
+    void *ram;

arch_init.c uint64_t ram_bytes_total(void) · line 539

Quoted 10 lines
arch_init.c +10 -0
+    RAMBlock *block = NULL;
+
+    ram = memory_region_get_ram_ptr(block->mr);
+
+    /* XXX. Here just simplely madvise(.., MADV_DONTNEED) the whole ram
+     * pages, need more work to keep MADV_DONTNEED ram pages that
+     * already sent. */
+    qemu_madvise(ram, size, MADV_DONTNEED);
+}
+

I don't think this is right at all. There's no guarantee we have a single linear mapping of all ram.

I think you need something a bit more clever than this.

Quoted 16 lines
arch_init.c +0 -0
 static void migration_end(void)
 {
     if (migration_bitmap) {
include/migration/migration.h +1 -0
index 8866c3c..9cc5285 100644
@@ -21,6 +21,7 @@
 #include "qapi/error.h"
 #include "migration/vmstate.h"
 #include "qapi-types.h"
+#include "exec/memory.h"
 
 enum {
     MIG_STATE_ERROR,

include/migration/migration.h uint64_t ram_bytes_remaining(void); · line 105

Quoted 5 lines
include/migration/migration.h +2 -0
@@ -100,6 +101,8 @@ uint64_t ram_bytes_remaining(void);
 uint64_t ram_bytes_transferred(void);
 uint64_t ram_bytes_total(void);
 
+void ram_madvise_free(ram_addr_t size);
+

If you introduce new interfaces, please include documentation in the header.

Regards,

Anthony Liguori

Quoted 5 lines
include/migration/migration.h +0 -0
 extern SaveVMHandlers savevm_ram_handlers;
 
 uint64_t dup_mig_bytes_transferred(void);
Signature · 1 line
1.7.7.6
author
#9 lore raw

Re: [Qemu-devel] [PATCH 3/7] arch_init: add ram_madvise_free()

Quoted 16 lines · Anthony Liguori
Quoted 14 lines · Lei Li
---
  arch_init.c                   |   13 +++++++++++++
  include/migration/migration.h |    3 +++
  2 files changed, 16 insertions(+), 0 deletions(-)
arch_init.c +0 -0
index 872020e..fc66bd2 100644
@@ -524,6 +524,19 @@ uint64_t ram_bytes_total(void)
      return total;
  }
 
Quoted 15 lines

arch_init.c uint64_t ram_bytes_total(void) · line 539

Quoted 13 lines
arch_init.c +13 -0
+void ram_madvise_free(ram_addr_t size)
+{
+    void *ram;
+    RAMBlock *block = NULL;
+
+    ram = memory_region_get_ram_ptr(block->mr);
+
+    /* XXX. Here just simplely madvise(.., MADV_DONTNEED) the whole ram
+     * pages, need more work to keep MADV_DONTNEED ram pages that
+     * already sent. */
+    qemu_madvise(ram, size, MADV_DONTNEED);
+}
+

I don't think this is right at all. There's no guarantee we have a single linear mapping of all ram.

Ah, thanks for yourclarification!

Quoted 2 lines

I think you need something a bit more clever than this.

Yes, this need more work.

Quoted 20 lines
Quoted 20 lines
arch_init.c +0 -0
  static void migration_end(void)
  {
      if (migration_bitmap) {
include/migration/migration.h +1 -0
index 8866c3c..9cc5285 100644
@@ -21,6 +21,7 @@
  #include "qapi/error.h"
  #include "migration/vmstate.h"
  #include "qapi-types.h"
+#include "exec/memory.h"
 
  enum {
      MIG_STATE_ERROR,
@@ -100,6 +101,8 @@ uint64_t ram_bytes_remaining(void);
  uint64_t ram_bytes_transferred(void);
  uint64_t ram_bytes_total(void);
 
Quoted 4 lines

include/migration/migration.h uint64_t ram_bytes_remaining(void); · line 105

Quoted 2 lines
include/migration/migration.h +2 -0
+void ram_madvise_free(ram_addr_t size);
+

If you introduce new interfaces, please include documentation in the header.

Good to know, thanks!

Quoted 9 lines

Regards,

Anthony Liguori

Quoted 5 lines
include/migration/migration.h +0 -0
  extern SaveVMHandlers savevm_ram_handlers;
 
  uint64_t dup_mig_bytes_transferred(void);
Signature · 1 line
1.7.7.6
Signature · 1 line
Lei
#10 lore raw

Re: [Qemu-devel] [PATCH 3/7] arch_init: add ram_madvise_free()

In reply to Anthony Liguori
Quoted 53 lines · Anthony Liguori
Quoted 17 lines · Lei Li
---
  arch_init.c                   |   13 +++++++++++++
  include/migration/migration.h |    3 +++
  2 files changed, 16 insertions(+), 0 deletions(-)
arch_init.c +3 -0
index 872020e..fc66bd2 100644
@@ -524,6 +524,19 @@ uint64_t ram_bytes_total(void)
      return total;
  }
 
+void ram_madvise_free(ram_addr_t size)
+{
+    void *ram;

arch_init.c uint64_t ram_bytes_total(void) · line 539

Quoted 10 lines
arch_init.c +10 -0
+    RAMBlock *block = NULL;
+
+    ram = memory_region_get_ram_ptr(block->mr);
+
+    /* XXX. Here just simplely madvise(.., MADV_DONTNEED) the whole ram
+     * pages, need more work to keep MADV_DONTNEED ram pages that
+     * already sent. */
+    qemu_madvise(ram, size, MADV_DONTNEED);
+}
+

I don't think this is right at all. There's no guarantee we have a single linear mapping of all ram.

I think you need something a bit more clever than this.

Quoted 19 lines
arch_init.c +0 -0
  static void migration_end(void)
  {
      if (migration_bitmap) {
include/migration/migration.h +1 -0
index 8866c3c..9cc5285 100644
@@ -21,6 +21,7 @@
  #include "qapi/error.h"
  #include "migration/vmstate.h"
  #include "qapi-types.h"
+#include "exec/memory.h"
 
  enum {
      MIG_STATE_ERROR,
@@ -100,6 +101,8 @@ uint64_t ram_bytes_remaining(void);
  uint64_t ram_bytes_transferred(void);
  uint64_t ram_bytes_total(void);
 
Quoted 15 lines

include/migration/migration.h uint64_t ram_bytes_remaining(void); · line 105

Quoted 2 lines
include/migration/migration.h +2 -0
+void ram_madvise_free(ram_addr_t size);
+

If you introduce new interfaces, please include documentation in the header.

Regards,

Anthony Liguori

Quoted 5 lines
include/migration/migration.h +0 -0
  extern SaveVMHandlers savevm_ram_handlers;
 
  uint64_t dup_mig_bytes_transferred(void);
Signature · 1 line
1.7.7.6

We have a new function in master...... ram_handle_compressed() (was exported for RDMA).

Perhaps this could be used.....

- Michael

author
#11 lore raw

PATCH 4/7 migration-local: implementation of outgoing part

In reply to Lei Li
---
 Makefile.objs                 |    1 +
 include/migration/migration.h |   15 +++++
 migration-local.c             |  116 +++++++++++++++++++++++++++++++++++++++++
 migration-unix.c              |   13 +++++
 qapi-schema.json              |   14 +++++
 qmp-commands.hx               |   22 ++++++++
 6 files changed, 181 insertions(+), 0 deletions(-)
 create mode 100644 migration-local.c
Makefile.objs +1 -0
index 5b288ba..2a3d9a5 100644
@@ -53,6 +53,7 @@ common-obj-$(CONFIG_LINUX) += fsdev/
 common-obj-y += migration.o migration-tcp.o
 common-obj-y += qemu-char.o #aio.o
 common-obj-y += block-migration.o
+common-obj-y += migration-local.o
 common-obj-y += page_cache.o xbzrle.o
 
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
include/migration/migration.h +15 -0
index 9cc5285..12c75cf 100644
@@ -58,6 +58,17 @@ struct MigrationState
     int64_t xbzrle_cache_size;
 };
 
+
+typedef struct LocalMigState LocalMigState;
+
+struct LocalMigState
+{
+    int fd;
+    int state;
+    QEMUFile *file;
+    QemuThread thread;
+};
+
 void process_incoming_migration(QEMUFile *f);
 
 void qemu_start_incoming_migration(const char *uri, Error **errp);
@@ -80,6 +91,8 @@ void unix_start_incoming_migration(const char *path, Error **errp);
 
 void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp);
 
+void unix_start_local_outgoing_migration(LocalMigState *s, const char *path, Error **errp);
+
 void fd_start_incoming_migration(const char *path, Error **errp);
 
 void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp);
@@ -90,6 +103,8 @@ void migrate_fd_connect(MigrationState *s);
 
 int migrate_fd_close(MigrationState *s);
 
+void migrate_fd_connect_local(LocalMigState *s);
+
 void add_migration_state_change_notifier(Notifier *notify);
 void remove_migration_state_change_notifier(Notifier *notify);
 bool migration_is_active(MigrationState *);
migration-local.c new file +116 -0

116 lines not on this page · raw message

migration-unix.c +13 -0
index 94b7022..a21262a 100644
@@ -49,6 +49,19 @@ void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **
     unix_nonblocking_connect(path, unix_wait_for_connect, s, errp);
 }
 
+void unix_start_local_outgoing_migration(LocalMigState *s, const char *path, Error **errp)
+{
+    s->fd = unix_connect(path, errp);
+    if (s->fd < 0) {
+        s->file = NULL;
+        /* There should be a fd_error_set function */
+        s->state = MIG_STATE_ERROR;
+    } else {
+        s->file = qemu_fopen_socket(s->fd, "wb");
+        migrate_fd_connect_local(s);
+    }
+}
+
 static void unix_accept_incoming_migration(void *opaque)
 {
     struct sockaddr_un addr;
qapi-schema.json +14 -0
index 5ad6894..2890f70 100644
@@ -648,6 +648,20 @@
 { 'command': 'query-migrate-capabilities', 'returns':   ['MigrationCapabilityStatus']}
 
 ##
+# @localhost-migrate
+#
+# Migrates the current running guest to another localhost VM.
+#
+# @uri: the Uniform Resource Identifier of the destination VM
+#
+# Returns: nothing on success
+#
+# Since: 1.7
+##
+{ 'command': 'localhost-migrate',
+  'data': {'uri': 'str'} }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +22 -0
index 8cea5e5..bf6d042 100644
@@ -787,6 +787,28 @@ Example:
 EQMP
 
     {
+        .name      = "localhost-migrate",
+        .args_type = "uri:s",
+        .mhandler.cmd_new = qmp_marshal_input_localhost_migrate,
+    },
+
+SQMP
+localhost-migrate
+
+Migrate VM in localhost.
+
+Arguments:
+
+- "uri": Destination URI (json-string)
+
+Example:
+
+-> { "execute": "localhost-migrate", "arguments": { "uri": "/tmp/foo" }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "dump-guest-memory",
         .args_type  = "paging:b,protocol:s,begin:i?,end:i?",
         .params     = "-p protocol [begin] [length]",
Signature · 1 line
1.7.7.6
#12 lore raw

Re: [Qemu-devel] [PATCH 4/7] migration-local: implementation of outgoing part

Quoted 69 lines · Lei Li
---
 Makefile.objs                 |    1 +
 include/migration/migration.h |   15 +++++
 migration-local.c             |  116 +++++++++++++++++++++++++++++++++++++++++
 migration-unix.c              |   13 +++++
 qapi-schema.json              |   14 +++++
 qmp-commands.hx               |   22 ++++++++
 6 files changed, 181 insertions(+), 0 deletions(-)
 create mode 100644 migration-local.c
Makefile.objs +1 -0
index 5b288ba..2a3d9a5 100644
@@ -53,6 +53,7 @@ common-obj-$(CONFIG_LINUX) += fsdev/
 common-obj-y += migration.o migration-tcp.o
 common-obj-y += qemu-char.o #aio.o
 common-obj-y += block-migration.o
+common-obj-y += migration-local.o
 common-obj-y += page_cache.o xbzrle.o
 
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
include/migration/migration.h +15 -0
index 9cc5285..12c75cf 100644
@@ -58,6 +58,17 @@ struct MigrationState
     int64_t xbzrle_cache_size;
 };
 
+
+typedef struct LocalMigState LocalMigState;
+
+struct LocalMigState
+{
+    int fd;
+    int state;
+    QEMUFile *file;
+    QemuThread thread;
+};
+
 void process_incoming_migration(QEMUFile *f);
 
 void qemu_start_incoming_migration(const char *uri, Error **errp);
@@ -80,6 +91,8 @@ void unix_start_incoming_migration(const char *path, Error **errp);
 
 void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp);
 
+void unix_start_local_outgoing_migration(LocalMigState *s, const char *path, Error **errp);
+
 void fd_start_incoming_migration(const char *path, Error **errp);
 
 void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp);
@@ -90,6 +103,8 @@ void migrate_fd_connect(MigrationState *s);
 
 int migrate_fd_close(MigrationState *s);
 
+void migrate_fd_connect_local(LocalMigState *s);
+
 void add_migration_state_change_notifier(Notifier *notify);
 void remove_migration_state_change_notifier(Notifier *notify);
 bool migration_is_active(MigrationState *);
migration-local.c new file +0 -0
new file mode 100644
index 0000000..a97dd3a

migration-local.c line 10

Quoted 10 lines
migration-local.c new file +10 -0
@@ -0,0 +1,116 @@
+/*
+ * QEMU localhost live migration
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions are licensed under the terms of the GNU GPL, version 2
+ * or (at your option) any later version.

You can just add the "or later" clause to the first paragraph.

Quoted 117 lines
migration-local.c new file +106 -0
+ */
+
+#include "qemu-common.h"
+#include "migration/migration.h"
+#include "monitor/monitor.h"
+#include "migration/qemu-file.h"
+#include "sysemu/sysemu.h"
+#include "block/block.h"
+#include "qemu/sockets.h"
+#include "migration/block.h"
+#include "qemu/thread.h"
+#include "qmp-commands.h"
+#include "exec/memory.h"
+#include "trace.h"
+#include "qemu/osdep.h"
+
+//#define DEBUG_MIGRATION_LOCAL
+
+#ifdef DEBUG_MIGRATION_LOCAL
+#define DPRINTF(fmt, ...) \
+    do { printf("migration-local: " fmt, ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...) \
+    do { } while (0)
+#endif
+
+
+/************************************************************************
+ * Outgoing part
+ */
+
+static void *migration_local_thread(void *opaque)
+{
+    LocalMigState *s = opaque;
+    int ret;
+    ram_addr_t size;
+
+    DPRINTF("Beginning savevm\n");
+
+    /* This will be replaced by new function qemu_save_local_state(). */
+    ret = qemu_save_device_state(s->file);
+    qemu_fclose(s->file);
+
+    if (ret < 0) {
+        s->state = MIG_STATE_ERROR;
+        return NULL;
+    } else {
+        /* XXX: The logic will be changed, need more work here. */
+        s->state = MIG_STATE_COMPLETED;
+
+        size = ram_bytes_total();
+        ram_madvise_free(size);
+    }
+
+    return NULL;
+}
+
+void migrate_fd_connect_local(LocalMigState *s)
+{
+    s->state = MIG_STATE_ACTIVE;
+    trace_migrate_set_state(MIG_STATE_ACTIVE);
+
+    qemu_thread_create(&s->thread, migration_local_thread, s,
+                       QEMU_THREAD_JOINABLE);
+}
+
+void qmp_localhost_migrate(const char *uri, Error **errp)
+{
+    const char *path;
+    Error *local_err = NULL;
+    int is_vm_running;
+    LocalMigState *s;
+
+    is_vm_running = runstate_is_running();
+
+    /* Stop the VM first */
+    if (is_vm_running) {
+        vm_stop(RUN_STATE_SAVE_VM);
+    }
+
+    bdrv_flush_all();
+
+    s = g_malloc0(sizeof(LocalMigState));
+
+    /* Start outgoing migration by unix socket. */
+    if (strstart(uri, "unix:", &path)) {
+        /* XXX. Creat a new unix_start_outgoing_migration_* is not necessary,
+         * just for the first step. This will be replaced by vmsplice
+         * mechanism. */
+        unix_start_local_outgoing_migration(s, path, &local_err);
+    } else {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
+        goto fail;
+    }
+
+    if (local_err) {
+        s->state = MIG_STATE_ERROR;
+        error_propagate(errp, local_err);
+        goto fail;
+    }
+
+fail:
+    if (!is_vm_running) {
+        vm_start();
+    }
+}
migration-unix.c +3 -0
index 94b7022..a21262a 100644
@@ -49,6 +49,19 @@ void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **
     unix_nonblocking_connect(path, unix_wait_for_connect, s, errp);
 }
 
+void unix_start_local_outgoing_migration(LocalMigState *s, const char *path, Error **errp)
+{
+    s->fd = unix_connect(path, errp);

migration-unix.c void unix_start_outgoing_migration(MigrationState *s, const char *path, Error ** · line 64

Quoted 10 lines
migration-unix.c +10 -0
+    if (s->fd < 0) {
+        s->file = NULL;
+        /* There should be a fd_error_set function */
+        s->state = MIG_STATE_ERROR;
+    } else {
+        s->file = qemu_fopen_socket(s->fd, "wb");
+        migrate_fd_connect_local(s);
+    }
+}
+

Skipping most of the above as it's a work-in-progress.

Quoted 13 lines
migration-unix.c +0 -0
 static void unix_accept_incoming_migration(void *opaque)
 {
     struct sockaddr_un addr;
qapi-schema.json +2 -0
index 5ad6894..2890f70 100644
@@ -648,6 +648,20 @@
 { 'command': 'query-migrate-capabilities', 'returns':   ['MigrationCapabilityStatus']}
 
 ##
+# @localhost-migrate
+#

qapi-schema.json line 662

Quoted 10 lines
qapi-schema.json +10 -0
+# Migrates the current running guest to another localhost VM.
+#
+# @uri: the Uniform Resource Identifier of the destination VM
+#
+# Returns: nothing on success
+#
+# Since: 1.7
+##
+{ 'command': 'localhost-migrate',
+  'data': {'uri': 'str'} }

I suspect we should just do this as a flag to the existing migration command. Perhaps we could even just use a capability.

Regards,

Anthony Liguori

Quoted 40 lines
qapi-schema.json +2 -0
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +22 -0
index 8cea5e5..bf6d042 100644
@@ -787,6 +787,28 @@ Example:
 EQMP
 
     {
+        .name      = "localhost-migrate",
+        .args_type = "uri:s",
+        .mhandler.cmd_new = qmp_marshal_input_localhost_migrate,
+    },
+
+SQMP
+localhost-migrate
+
+Migrate VM in localhost.
+
+Arguments:
+
+- "uri": Destination URI (json-string)
+
+Example:
+
+-> { "execute": "localhost-migrate", "arguments": { "uri": "/tmp/foo" }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "dump-guest-memory",
         .args_type  = "paging:b,protocol:s,begin:i?,end:i?",
         .params     = "-p protocol [begin] [length]",
Signature · 1 line
1.7.7.6
author
#13 lore raw

Re: [Qemu-devel] [PATCH 4/7] migration-local: implementation of outgoing part

Quoted 74 lines · Anthony Liguori
Quoted 72 lines · Lei Li
---
  Makefile.objs                 |    1 +
  include/migration/migration.h |   15 +++++
  migration-local.c             |  116 +++++++++++++++++++++++++++++++++++++++++
  migration-unix.c              |   13 +++++
  qapi-schema.json              |   14 +++++
  qmp-commands.hx               |   22 ++++++++
  6 files changed, 181 insertions(+), 0 deletions(-)

create mode 100644 migration-local.c

Makefile.objs +1 -0
index 5b288ba..2a3d9a5 100644
@@ -53,6 +53,7 @@ common-obj-$(CONFIG_LINUX) += fsdev/
  common-obj-y += migration.o migration-tcp.o
  common-obj-y += qemu-char.o #aio.o
  common-obj-y += block-migration.o
+common-obj-y += migration-local.o
  common-obj-y += page_cache.o xbzrle.o
 
  common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
include/migration/migration.h +15 -0
index 9cc5285..12c75cf 100644
@@ -58,6 +58,17 @@ struct MigrationState
      int64_t xbzrle_cache_size;
  };
 
+
+typedef struct LocalMigState LocalMigState;
+
+struct LocalMigState
+{
+    int fd;
+    int state;
+    QEMUFile *file;
+    QemuThread thread;
+};
+
  void process_incoming_migration(QEMUFile *f);
 
  void qemu_start_incoming_migration(const char *uri, Error **errp);
@@ -80,6 +91,8 @@ void unix_start_incoming_migration(const char *path, Error **errp);
 
  void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp);
 
+void unix_start_local_outgoing_migration(LocalMigState *s, const char *path, Error **errp);
+
  void fd_start_incoming_migration(const char *path, Error **errp);
 
  void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp);
@@ -90,6 +103,8 @@ void migrate_fd_connect(MigrationState *s);
 
  int migrate_fd_close(MigrationState *s);
 
+void migrate_fd_connect_local(LocalMigState *s);
+
  void add_migration_state_change_notifier(Notifier *notify);
  void remove_migration_state_change_notifier(Notifier *notify);
  bool migration_is_active(MigrationState *);
migration-local.c new file +3 -0
new file mode 100644
index 0000000..a97dd3a
@@ -0,0 +1,116 @@
+/*
+ * QEMU localhost live migration
+ *
Quoted 8 lines

migration-local.c line 10

Quoted 7 lines
migration-local.c new file +7 -0
+ * Copyright IBM, Corp. 2013
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions are licensed under the terms of the GNU GPL, version 2
+ * or (at your option) any later version.

You can just add the "or later" clause to the first paragraph.

Sure.

Quoted 140 lines
Quoted 118 lines
migration-local.c new file +106 -0
+ */
+
+#include "qemu-common.h"
+#include "migration/migration.h"
+#include "monitor/monitor.h"
+#include "migration/qemu-file.h"
+#include "sysemu/sysemu.h"
+#include "block/block.h"
+#include "qemu/sockets.h"
+#include "migration/block.h"
+#include "qemu/thread.h"
+#include "qmp-commands.h"
+#include "exec/memory.h"
+#include "trace.h"
+#include "qemu/osdep.h"
+
+//#define DEBUG_MIGRATION_LOCAL
+
+#ifdef DEBUG_MIGRATION_LOCAL
+#define DPRINTF(fmt, ...) \
+    do { printf("migration-local: " fmt, ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...) \
+    do { } while (0)
+#endif
+
+
+/************************************************************************
+ * Outgoing part
+ */
+
+static void *migration_local_thread(void *opaque)
+{
+    LocalMigState *s = opaque;
+    int ret;
+    ram_addr_t size;
+
+    DPRINTF("Beginning savevm\n");
+
+    /* This will be replaced by new function qemu_save_local_state(). */
+    ret = qemu_save_device_state(s->file);
+    qemu_fclose(s->file);
+
+    if (ret < 0) {
+        s->state = MIG_STATE_ERROR;
+        return NULL;
+    } else {
+        /* XXX: The logic will be changed, need more work here. */
+        s->state = MIG_STATE_COMPLETED;
+
+        size = ram_bytes_total();
+        ram_madvise_free(size);
+    }
+
+    return NULL;
+}
+
+void migrate_fd_connect_local(LocalMigState *s)
+{
+    s->state = MIG_STATE_ACTIVE;
+    trace_migrate_set_state(MIG_STATE_ACTIVE);
+
+    qemu_thread_create(&s->thread, migration_local_thread, s,
+                       QEMU_THREAD_JOINABLE);
+}
+
+void qmp_localhost_migrate(const char *uri, Error **errp)
+{
+    const char *path;
+    Error *local_err = NULL;
+    int is_vm_running;
+    LocalMigState *s;
+
+    is_vm_running = runstate_is_running();
+
+    /* Stop the VM first */
+    if (is_vm_running) {
+        vm_stop(RUN_STATE_SAVE_VM);
+    }
+
+    bdrv_flush_all();
+
+    s = g_malloc0(sizeof(LocalMigState));
+
+    /* Start outgoing migration by unix socket. */
+    if (strstart(uri, "unix:", &path)) {
+        /* XXX. Creat a new unix_start_outgoing_migration_* is not necessary,
+         * just for the first step. This will be replaced by vmsplice
+         * mechanism. */
+        unix_start_local_outgoing_migration(s, path, &local_err);
+    } else {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
+        goto fail;
+    }
+
+    if (local_err) {
+        s->state = MIG_STATE_ERROR;
+        error_propagate(errp, local_err);
+        goto fail;
+    }
+
+fail:
+    if (!is_vm_running) {
+        vm_start();
+    }
+}
migration-unix.c +3 -0
index 94b7022..a21262a 100644
@@ -49,6 +49,19 @@ void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **
      unix_nonblocking_connect(path, unix_wait_for_connect, s, errp);
  }
 
+void unix_start_local_outgoing_migration(LocalMigState *s, const char *path, Error **errp)
+{
+    s->fd = unix_connect(path, errp);

migration-unix.c void unix_start_outgoing_migration(MigrationState *s, const char *path, Error ** · line 64

Quoted 10 lines
migration-unix.c +10 -0
+    if (s->fd < 0) {
+        s->file = NULL;
+        /* There should be a fd_error_set function */
+        s->state = MIG_STATE_ERROR;
+    } else {
+        s->file = qemu_fopen_socket(s->fd, "wb");
+        migrate_fd_connect_local(s);
+    }
+}
+

Skipping most of the above as it's a work-in-progress.

Quoted 10 lines
migration-unix.c +0 -0
  static void unix_accept_incoming_migration(void *opaque)
  {
      struct sockaddr_un addr;
qapi-schema.json +0 -0
index 5ad6894..2890f70 100644
@@ -648,6 +648,20 @@
  { 'command': 'query-migrate-capabilities', 'returns':   ['MigrationCapabilityStatus']}
 
Quoted 15 lines

qapi-schema.json line 662

Quoted 13 lines
qapi-schema.json +12 -0
  ##
+# @localhost-migrate
+#
+# Migrates the current running guest to another localhost VM.
+#
+# @uri: the Uniform Resource Identifier of the destination VM
+#
+# Returns: nothing on success
+#
+# Since: 1.7
+##
+{ 'command': 'localhost-migrate',
+  'data': {'uri': 'str'} }

I suspect we should just do this as a flag to the existing migration command. Perhaps we could even just use a capability.

Yeah, I had thought about this by adding a flag to the existing migration command like:

migrate -l for localhost migration.

This is just for a easy start.

Quoted 45 lines

Regards,

Anthony Liguori

Quoted 40 lines
qapi-schema.json +2 -0
+
+##
  # @MouseInfo:
  #
  # Information about a mouse device.
qmp-commands.hx +22 -0
index 8cea5e5..bf6d042 100644
@@ -787,6 +787,28 @@ Example:
  EQMP
 
      {
+        .name      = "localhost-migrate",
+        .args_type = "uri:s",
+        .mhandler.cmd_new = qmp_marshal_input_localhost_migrate,
+    },
+
+SQMP
+localhost-migrate
+
+Migrate VM in localhost.
+
+Arguments:
+
+- "uri": Destination URI (json-string)
+
+Example:
+
+-> { "execute": "localhost-migrate", "arguments": { "uri": "/tmp/foo" }
+<- { "return": {} }
+
+EQMP
+
+    {
          .name       = "dump-guest-memory",
          .args_type  = "paging:b,protocol:s,begin:i?,end:i?",
          .params     = "-p protocol [begin] [length]",
Signature · 1 line
1.7.7.6
Signature · 1 line
Lei
author
#14 lore raw

PATCH 5/7 migration-local: implementation of incoming part

In reply to Lei Li
---
 include/migration/migration.h |    6 +++++
 migration-local.c             |   39 ++++++++++++++++++++++++++++++++++
 migration-unix.c              |   47 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+), 0 deletions(-)
include/migration/migration.h +6 -0
index 12c75cf..e0693c2 100644
@@ -73,6 +73,10 @@ void process_incoming_migration(QEMUFile *f);
 
 void qemu_start_incoming_migration(const char *uri, Error **errp);
 
+void start_local_incoming_migration(QEMUFile *f);
+
+void qemu_start_local_incoming_migration(const char *uri, Error **errp);
+
 uint64_t migrate_max_downtime(void);
 
 void do_info_migrate_print(Monitor *mon, const QObject *data);
@@ -89,6 +93,8 @@ void tcp_start_outgoing_migration(MigrationState *s, const char *host_port, Erro
 
 void unix_start_incoming_migration(const char *path, Error **errp);
 
+void unix_start_local_incoming_migration(const char *path, Error **errp);
+
 void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp);
 
 void unix_start_local_outgoing_migration(LocalMigState *s, const char *path, Error **errp);
migration-local.c +39 -0
index a97dd3a..61da76f 100644
@@ -114,3 +114,42 @@ fail:
         vm_start();
     }
 }
+
+/**********************************************************************
+ * Incoming part
+ */
+
+void qemu_start_local_incoming_migration(const char *uri, Error **errp)
+{
+    const char *p;
+
+    if (strstart(uri, "unix:", &p)) {
+        unix_start_local_incoming_migration(p, errp);
+    } else {
+        error_setg(errp, "unknown migration protocol: %s", uri);
+    }
+}
+
+void start_local_incoming_migration(QEMUFile *f)
+{
+    int ret;
+
+    ret = qemu_loadvm_state(f);
+    if (ret < 0) {
+        fprintf(stderr, "load of migration failed\n");
+        exit(EXIT_FAILURE);
+    }
+    qemu_announce_self();
+
+    DPRINTF("successfully loaded vm state\n");
+
+    bdrv_clear_incoming_migration_all();
+    /* Make sure all file formats flush their mutable metadata */
+    bdrv_invalidate_cache_all();
+
+    if (autostart) {
+        vm_start();
+    } else {
+        runstate_set(RUN_STATE_PAUSED);
+    }
+}
migration-unix.c +47 -0

50 lines not on this page · raw message

Signature · 1 line
1.7.7.6
author
#15 lore raw

PATCH 6/7 migration-local: add option to command line for -incoming-local

In reply to Lei Li
---
 qemu-options.hx |    9 +++++++++
 vl.c            |   14 ++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
qemu-options.hx +9 -0
index bf94862..bb1a88a 100644
@@ -2913,6 +2913,15 @@ STEXI
 Prepare for incoming migration, listen on @var{port}.
 ETEXI
 
+DEF("incoming-local", HAS_ARG, QEMU_OPTION_incoming_local, \
+    "-incoming-local p prepare for localhost incoming migration, listen on domain unix socket p\n",
+    QEMU_ARCH_ALL)
+STEXI
+@item -incoming-local @var{port}
+@findex -incoming-local
+Prepare for localhost incoming migration, listen on @var{port}
+ETEXI
+
 DEF("nodefaults", 0, QEMU_OPTION_nodefaults, \
     "-nodefaults     don't create default devices\n", QEMU_ARCH_ALL)
 STEXI
vl.c +14 -0
index 9f8fd6e..496a264 100644
@@ -2856,6 +2856,7 @@ int main(int argc, char **argv, char **envp)
     const char *vga_model = "none";
     const char *pid_file = NULL;
     const char *incoming = NULL;
+    const char *incoming_local = NULL;
 #ifdef CONFIG_VNC
     int show_vnc_port = 0;
 #endif
@@ -3755,6 +3756,10 @@ int main(int argc, char **argv, char **envp)
                 incoming = optarg;
                 runstate_set(RUN_STATE_INMIGRATE);
                 break;
+            case QEMU_OPTION_incoming_local:
+                incoming_local = optarg;
+                runstate_set(RUN_STATE_INMIGRATE);
+                break;
             case QEMU_OPTION_nodefaults:
                 default_serial = 0;
                 default_parallel = 0;
@@ -4418,6 +4423,15 @@ int main(int argc, char **argv, char **envp)
             error_free(local_err);
             exit(1);
         }
+    } else if (incoming_local) {
+        Error *local_err = NULL;
+        qemu_start_local_incoming_migration(incoming_local, &local_err);
+        if (local_err) {
+            fprintf(stderr, "-incoming_local %s: %s\n", incoming_local,
+                    error_get_pretty(local_err));
+            error_free(local_err);
+            exit(1);
+        }
     } else if (autostart) {
         vm_start();
     }
Signature · 1 line
1.7.7.6
author
#16 lore raw

PATCH 7/7 hmp: add hmp_localhost_migration interface

In reply to Lei Li
---
 hmp-commands.hx |   17 +++++++++++++++++
 hmp.c           |   13 +++++++++++++
 hmp.h           |    1 +
 3 files changed, 31 insertions(+), 0 deletions(-)
hmp-commands.hx +17 -0
index 915b0d1..ed21970 100644
@@ -989,6 +989,23 @@ STEXI
 Set the spice/vnc connection info for the migration target.  The spice/vnc
 server will ask the spice/vnc client to automatically reconnect using the
 new parameters (if specified) once the vm migration finished successfully.
+
+ETEXI
+
+    {
+        .name       = "localhost_migrate",
+        .args_type  = "uri:s",
+        .params     = "uri",
+        .help       = "migrate to domain socket URI on localhost",
+        .mhandler.cmd = hmp_localhost_migrate,
+    },
+
+
+STEXI
+@item localhost_migrate @var{uri}
+@findex localhost_migrate
+Migrate to @var{uri}.
+
 ETEXI
 
     {
hmp.c +13 -0
index 494a9aa..a7e779f 100644
@@ -1191,6 +1191,19 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     }
 }
 
+void hmp_localhost_migrate(Monitor *mon, const QDict *qdict)
+{
+    const char *uri = qdict_get_str(qdict, "uri");
+    Error *errp = NULL;
+
+    qmp_localhost_migrate(uri, &errp);
+    if (errp) {
+        monitor_printf(mon, "local_migrate: %s\n", error_get_pretty(errp));
+        error_free(errp);
+        return;
+    }
+}
+
 void hmp_device_del(Monitor *mon, const QDict *qdict)
 {
     const char *id = qdict_get_str(qdict, "id");
hmp.h +1 -0
index 56d2e92..878bd0c 100644
@@ -72,6 +72,7 @@ void hmp_block_job_pause(Monitor *mon, const QDict *qdict);
 void hmp_block_job_resume(Monitor *mon, const QDict *qdict);
 void hmp_block_job_complete(Monitor *mon, const QDict *qdict);
 void hmp_migrate(Monitor *mon, const QDict *qdict);
+void hmp_localhost_migrate(Monitor *mon, const QDict *qdict);
 void hmp_device_del(Monitor *mon, const QDict *qdict);
 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
 void hmp_netdev_add(Monitor *mon, const QDict *qdict);
Signature · 1 line
1.7.7.6
#17 lore raw
In reply to Lei Li
Quoted 7 lines · Lei Li

Hi,

This patch series tries to add localhost live migration support to Qemu. It is just a draft version which is far from completing and I am still working on, send it out to have your suggestions and make sure it is the way should be headed. Your comments are very appreciated!

Thanks for posting Lei!

For the benefit of the other reviewers, the goal here is to allow "live upgrade" of a running QEMU instance. The work flow would look like this:

1) Guests are running QEMU release 1.6.1
2) Admin installs QEMU release 1.6.2 via RPM or deb
3) Admin does localhost migration with page flipping to use new version of QEMU.

Page flipping is used in order to avoid requiring that there is enough free memory to fit an additional copy of the largest guest which is the requirement today with localhost migration.

Quoted 17 lines

When doing localhost live migration, the host memory will balloon up during the period, might consume double memories for some time. So we want to add a new live migration mechanism localhost live migration.

The plan is:

1) Add new command to do localhost migration.

The qmp interface introduced like:

   { 'command': 'localhost-migrate', 'data': {'uri': 'str'} }

2) Use different mechanism than current live migration.

The very basic work flow like:

Quoted 13 lines
       qemu on the source (the source and destination are both on localhost)
              |
              V
           Stop VM
              |
              V   
          Create threads
              |
              V
       Page flipping through vmspice
              |
              V
       MADV_DONTNEED the ram pages which are already flipped

vmsplice() is a weird system call.

You would think that SPLICE_F_GIFT would imply MADV_DONTNEED but it doesn't appear today. So to start with, we're doing it explicitly.

We're planning on also looking at the kernel side of this as today the combination of vmsplice() to a pipe plus vmsplice() from a pipe() will not actually flip the page but instead copy it. But I think this is a fixable problem.

It would also be handy to flip large pages when THP is active but that's future work.

Regards,

Anthony Liguori

Quoted 46 lines
              |
              V
       Migration completes

As stopping VM first, we expect/resume the page flipping through vmspice is fast enough to meet *live migration (low downtime).

Notes:
Currently the work flow is not exactly the same as description above. For the first step, the work flow we plan to implement is:
stop VM and copy ram pages via unix domain socket, MADV_DONTNEED ram pages that already copied. After that, will replace to vmsplice mechanism instead of copying pages.

TODO:
- Working on the completing of ram copy and MADV_DONTNEED part.
- Introduce a mechanism to exchange a PIPE via SCM_RIGHTS.
- benchmark/evaluation.

Lei Li (7):
migration: export MIG_STATE_xxx flags
savevm: export qemu_save_device_state()
arch_init: add ram_madvise_free()
migration-local: implementation of outgoing part
migration-local: impelementation of incoming part
migration-local: add option to command line for local incoming hmp:add hmp_localhost_migration interface

 Makefile.objs                 |    1 +
 arch_init.c                   |   13 ++++
 hmp-commands.hx               |   17 +++++
 hmp.c                         |   13 ++++
 hmp.h                         |    1 +
 include/migration/migration.h |   32 +++++++++
 include/sysemu/sysemu.h       |    1 +
 migration-local.c             |  155 +++++++++++++++++++++++++++++++++++++++++
 migration-unix.c              |   60 ++++++++++++++++
 migration.c                   |    8 --
 qapi-schema.json              |   14 ++++
 qemu-options.hx               |    9 +++
 qmp-commands.hx               |   22 ++++++
 savevm.c                      |    2 +-
 vl.c                          |   14 ++++
 15 files changed, 353 insertions(+), 9 deletions(-)
 create mode 100644 migration-local.c
author
#18 lore raw
Quoted 54 lines · Anthony Liguori
Quoted 7 lines · Lei Li

Hi,

This patch series tries to add localhost live migration support to Qemu. It is just a draft version which is far from completing and I am still working on, send it out to have your suggestions and make sure it is the way should be headed. Your comments are very appreciated!

Thanks for posting Lei!

For the benefit of the other reviewers, the goal here is to allow "live upgrade" of a running QEMU instance. The work flow would look like this:

1) Guests are running QEMU release 1.6.1
2) Admin installs QEMU release 1.6.2 via RPM or deb
3) Admin does localhost migration with page flipping to use new version of QEMU.

Page flipping is used in order to avoid requiring that there is enough free memory to fit an additional copy of the largest guest which is the requirement today with localhost migration.

Quoted 17 lines

When doing localhost live migration, the host memory will balloon up during the period, might consume double memories for some time. So we want to add a new live migration mechanism localhost live migration.

The plan is:

1) Add new command to do localhost migration.

The qmp interface introduced like:

{ 'command': 'localhost-migrate', 'data': {'uri': 'str'} }

2) Use different mechanism than current live migration.

The very basic work flow like:

Quoted 13 lines

qemu on the source (the source and destination are both on localhost)
|
V
Stop VM
|
V
Create threads
|
V
Page flipping through vmspice
|
V
MADV_DONTNEED the ram pages which are already flipped

Quoted 4 lines

vmsplice() is a weird system call.

You would think that SPLICE_F_GIFT would imply MADV_DONTNEED but it doesn't appear today. So to start with, we're doing it explicitly.

I see, thanks for your explanation!

Quoted 60 lines

We're planning on also looking at the kernel side of this as today the combination of vmsplice() to a pipe plus vmsplice() from a pipe() will not actually flip the page but instead copy it. But I think this is a fixable problem.

It would also be handy to flip large pages when THP is active but that's future work.

Regards,

Anthony Liguori

Quoted 46 lines

|
V
Migration completes

As stopping VM first, we expect/resume the page flipping through vmspice is fast enough to meet *live migration (low downtime).

Notes:
Currently the work flow is not exactly the same as description above. For the first step, the work flow we plan to implement is:
stop VM and copy ram pages via unix domain socket, MADV_DONTNEED ram pages that already copied. After that, will replace to vmsplice mechanism instead of copying pages.

TODO:
- Working on the completing of ram copy and MADV_DONTNEED part.
- Introduce a mechanism to exchange a PIPE via SCM_RIGHTS.
- benchmark/evaluation.

Lei Li (7):
migration: export MIG_STATE_xxx flags
savevm: export qemu_save_device_state()
arch_init: add ram_madvise_free()
migration-local: implementation of outgoing part
migration-local: impelementation of incoming part
migration-local: add option to command line for local incoming hmp:add hmp_localhost_migration interface

  Makefile.objs                 |    1 +
  arch_init.c                   |   13 ++++
  hmp-commands.hx               |   17 +++++
  hmp.c                         |   13 ++++
  hmp.h                         |    1 +
  include/migration/migration.h |   32 +++++++++
  include/sysemu/sysemu.h       |    1 +
  migration-local.c             |  155 +++++++++++++++++++++++++++++++++++++++++
  migration-unix.c              |   60 ++++++++++++++++
  migration.c                   |    8 --
  qapi-schema.json              |   14 ++++
  qemu-options.hx               |    9 +++
  qmp-commands.hx               |   22 ++++++
  savevm.c                      |    2 +-
  vl.c                          |   14 ++++
  15 files changed, 353 insertions(+), 9 deletions(-)

create mode 100644 migration-local.c

Signature · 1 line
Lei
#19 lore raw
In reply to Lei Li
Quoted 21 lines · Lei Li

2) Use different mechanism than current live migration.

The very basic work flow like:

       qemu on the source (the source and destination are both on localhost)
              |
              V
           Stop VM
              |
              V   
          Create threads
              |
              V
       Page flipping through vmspice
              |
              V
       MADV_DONTNEED the ram pages which are already flipped
              |
              V
       Migration completes
Quoted 2 lines

As stopping VM first, we expect/resume the page flipping through vmspice is fast enough to meet *live migration (low downtime).

Nice idea, that would allow low downtime QEMU upgrades.

Stefan

author
#20 lore raw
Quoted 22 lines · Stefan Hajnoczi
Quoted 21 lines · Lei Li

2) Use different mechanism than current live migration.

    The very basic work flow like:

        qemu on the source (the source and destination are both on localhost)
               |
               V
            Stop VM
               |
               V
           Create threads
               |
               V
        Page flipping through vmspice
               |
               V
        MADV_DONTNEED the ram pages which are already flipped
               |
               V
        Migration completes
Quoted 3 lines
Quoted 2 lines

As stopping VM first, we expect/resume the page flipping through vmspice is fast enough to meet *live migration (low downtime).

Nice idea, that would allow low downtime QEMU upgrades.

Well, the idea is from Anthony Liguori and Michael Roth :)

Quoted 3 lines

Stefan

Signature · 1 line
Lei