Skip to contentSkip to conversation

Migration next

PATCH In review Juan Quintela 4 participants 35 messages Jul 13, 2012 – Jul 25, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Migration next

Hi

This includes ram_save_live split + XBZRE changes.

Changes for the previous posts of this series:

ram_save_split:
- recalculate expected_time (Igor).
- Use PRIu64 consistently everywhere

XBZRE:
- rebased on top of previous series
- remove stage3 optimization, now XBZRE don't know about stages (code is much simpler)
- reintroduce the stage3(complete) optimization. We now sent the page compressed if the page is on the cache, otherwise, we sent the page uncompressed without putting it on the cache. This is better than the previous optimization.

Please review, Juan.

Juan Quintela (13):
savevm: Use a struct to pass all handlers
savevm: Live migration handlers register the struct directly
savevm: remove SaveSetParamsHandler
savevm: remove SaveLiveStateHandler
savevm: Refactor cancel operation in its own operation
savevm: introduce is_active method
savevm: split save_live_setup from save_live_state
savevm: split save_live into stage2 and stage3
ram: save_live_setup() don't need to sent pages
ram: save_live_complete() only do one loop
ram: iterate phase
ram: save_live_setup() we don't need to synchronize the dirty bitmap.
ram: save live optimization

Orit Wasserman (9):
Add migration capabilities
Add XBZRLE documentation
Add cache handling functions
Add uleb encoding/decoding functions
Change ram_save_block to return -1 if there are no more changes Add xbzrle_encode_buffer and xbzrle_decode_buffer functions Add XBZRLE to ram_save_block and ram_save_live
Add migrate_set_cachesize command
Add XBZRLE statistics

 Makefile.objs             |    1 +
 arch_init.c               |  380 +++++++++++++++++++++++++++++++++++++++------
 block-migration.c         |  153 +++++++++++-------
 cutils.c                  |   42 +++++
 docs/xbzrle.txt           |  136 ++++++++++++++++
 hmp-commands.hx           |   36 +++++
 hmp.c                     |   90 +++++++++++
 hmp.h                     |    3 +
 include/qemu/page_cache.h |   79 ++++++++++
 migration.c               |  159 ++++++++++++++++++-
 migration.h               |   25 ++-
 monitor.c                 |    7 +
 page_cache.c              |  216 ++++++++++++++++++++++++++
 qapi-schema.json          |  102 +++++++++++-
 qemu-common.h             |   21 +++
 qmp-commands.hx           |  127 ++++++++++++++-
 savevm.c                  |  236 +++++++++++++++++++++++-----
 vl.c                      |    3 +-
 vmstate.h                 |   18 ++-
 19 files changed, 1676 insertions(+), 158 deletions(-)
 create mode 100644 docs/xbzrle.txt
 create mode 100644 include/qemu/page_cache.h
 create mode 100644 page_cache.c
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/22 savevm: Use a struct to pass all handlers

This would make easier to add more operations in the next patches.

---
 savevm.c  |   54 +++++++++++++++++++++++++-----------------------------
 vmstate.h |    7 +++++++
 2 files changed, 32 insertions(+), 29 deletions(-)
savevm.c +25 -29
index a15c163..73626d4 100644
@@ -1171,10 +1171,7 @@ typedef struct SaveStateEntry {
     int alias_id;
     int version_id;
     int section_id;
-    SaveSetParamsHandler *set_params;
-    SaveLiveStateHandler *save_live_state;
-    SaveStateHandler *save_state;
-    LoadStateHandler *load_state;
+    SaveVMHandlers *ops;
     const VMStateDescription *vmsd;
     void *opaque;
     CompatEntry *compat;
@@ -1237,10 +1234,11 @@ int register_savevm_live(DeviceState *dev,
     se = g_malloc0(sizeof(SaveStateEntry));
     se->version_id = version_id;
     se->section_id = global_section_id++;
-    se->set_params = set_params;
-    se->save_live_state = save_live_state;
-    se->save_state = save_state;
-    se->load_state = load_state;
+    se->ops = g_malloc0(sizeof(SaveVMHandlers));
+    se->ops->set_params = set_params;
+    se->ops->save_live_state = save_live_state;
+    se->ops->save_state = save_state;
+    se->ops->load_state = load_state;
     se->opaque = opaque;
     se->vmsd = NULL;
     se->no_migrate = 0;
@@ -1309,6 +1307,7 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque)
             if (se->compat) {
                 g_free(se->compat);
             }
+            g_free(se->ops);
             g_free(se);
         }
     }
@@ -1327,9 +1326,6 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
     se = g_malloc0(sizeof(SaveStateEntry));
     se->version_id = vmsd->version_id;
     se->section_id = global_section_id++;
-    se->save_live_state = NULL;
-    se->save_state = NULL;
-    se->load_state = NULL;
     se->opaque = opaque;
     se->vmsd = vmsd;
     se->alias_id = alias_id;
@@ -1524,7 +1520,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
 static int vmstate_load(QEMUFile *f, SaveStateEntry *se, int version_id)
 {
     if (!se->vmsd) {         /* Old style */
-        return se->load_state(f, se->opaque, version_id);
+        return se->ops->load_state(f, se->opaque, version_id);
     }
     return vmstate_load_state(f, se->vmsd, se->opaque, version_id);
 }
@@ -1532,7 +1528,7 @@ static int vmstate_load(QEMUFile *f, SaveStateEntry *se, int version_id)
 static void vmstate_save(QEMUFile *f, SaveStateEntry *se)
 {
     if (!se->vmsd) {         /* Old style */
-        se->save_state(f, se->opaque);
+        se->ops->save_state(f, se->opaque);
         return;
     }
     vmstate_save_state(f,se->vmsd, se->opaque);
@@ -1569,10 +1565,10 @@ int qemu_savevm_state_begin(QEMUFile *f,
     int ret;
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
-        if(se->set_params == NULL) {
+        if (!se->ops || !se->ops->set_params) {
             continue;
         }
-        se->set_params(params, se->opaque);
+        se->ops->set_params(params, se->opaque);
     }
     
     qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
@@ -1581,9 +1577,9 @@ int qemu_savevm_state_begin(QEMUFile *f,
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
         int len;
 
-        if (se->save_live_state == NULL)
+        if (!se->ops || !se->ops->save_live_state) {
             continue;
-
+        }
         /* Section type */
         qemu_put_byte(f, QEMU_VM_SECTION_START);
         qemu_put_be32(f, se->section_id);
@@ -1596,7 +1592,7 @@ int qemu_savevm_state_begin(QEMUFile *f,
         qemu_put_be32(f, se->instance_id);
         qemu_put_be32(f, se->version_id);
 
-        ret = se->save_live_state(f, QEMU_VM_SECTION_START, se->opaque);
+        ret = se->ops->save_live_state(f, QEMU_VM_SECTION_START, se->opaque);
         if (ret < 0) {
             qemu_savevm_state_cancel(f);
             return ret;
@@ -1623,9 +1619,9 @@ int qemu_savevm_state_iterate(QEMUFile *f)
     int ret = 1;
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
-        if (se->save_live_state == NULL)
+        if (!se->ops || !se->ops->save_live_state) {
             continue;
-
+        }
         if (qemu_file_rate_limit(f)) {
             return 0;
         }
@@ -1634,7 +1630,7 @@ int qemu_savevm_state_iterate(QEMUFile *f)
         qemu_put_byte(f, QEMU_VM_SECTION_PART);
         qemu_put_be32(f, se->section_id);
 
-        ret = se->save_live_state(f, QEMU_VM_SECTION_PART, se->opaque);
+        ret = se->ops->save_live_state(f, QEMU_VM_SECTION_PART, se->opaque);
         trace_savevm_section_end(se->section_id);
 
         if (ret <= 0) {
@@ -1663,15 +1659,15 @@ int qemu_savevm_state_complete(QEMUFile *f)
     cpu_synchronize_all_states();
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
-        if (se->save_live_state == NULL)
+        if (!se->ops || !se->ops->save_live_state) {
             continue;
-
+        }
         trace_savevm_section_start();
         /* Section type */
         qemu_put_byte(f, QEMU_VM_SECTION_END);
         qemu_put_be32(f, se->section_id);
 
-        ret = se->save_live_state(f, QEMU_VM_SECTION_END, se->opaque);
+        ret = se->ops->save_live_state(f, QEMU_VM_SECTION_END, se->opaque);
         trace_savevm_section_end(se->section_id);
         if (ret < 0) {
             return ret;
@@ -1681,9 +1677,9 @@ int qemu_savevm_state_complete(QEMUFile *f)
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
         int len;
 
-	if (se->save_state == NULL && se->vmsd == NULL)
+        if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
 	    continue;
-
+        }
         trace_savevm_section_start();
         /* Section type */
         qemu_put_byte(f, QEMU_VM_SECTION_FULL);
@@ -1711,8 +1707,8 @@ void qemu_savevm_state_cancel(QEMUFile *f)
     SaveStateEntry *se;
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
-        if (se->save_live_state) {
-            se->save_live_state(f, -1, se->opaque);
+        if (se->ops && se->ops->save_live_state) {
+            se->ops->save_live_state(f, -1, se->opaque);
         }
     }
 }
@@ -1765,7 +1761,7 @@ static int qemu_save_device_state(QEMUFile *f)
         if (se->is_ram) {
             continue;
         }
-        if (se->save_state == NULL && se->vmsd == NULL) {
+        if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
             continue;
         }
 
vmstate.h +7 -0
index 5af45e0..909af69 100644
@@ -31,6 +31,13 @@ typedef void SaveStateHandler(QEMUFile *f, void *opaque);
 typedef int SaveLiveStateHandler(QEMUFile *f, int stage, void *opaque);
 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
 
+typedef struct SaveVMHandlers {
+    SaveSetParamsHandler *set_params;
+    SaveStateHandler *save_state;
+    SaveLiveStateHandler *save_live_state;
+    LoadStateHandler *load_state;
+} SaveVMHandlers;
+
 int register_savevm(DeviceState *dev,
                     const char *idstr,
                     int instance_id,
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/22 savevm: Live migration handlers register the struct directly

In reply to Juan Quintela

Notice that the live migration users never unregister, so no problem about freeing the ops structure.

---
 arch_init.c       |    9 +++++++--
 block-migration.c |   10 ++++++++--
 migration.h       |    4 ++--
 savevm.c          |   18 +++++++-----------
 vl.c              |    3 +--
 vmstate.h         |    5 +----
 6 files changed, 26 insertions(+), 23 deletions(-)
arch_init.c +7 -2
index 5b0f562..606b848 100644
@@ -298,7 +298,7 @@ static void migration_end(void)
 
 #define MAX_WAIT 50 /* ms, half buffered_file limit */
 
-int ram_save_live(QEMUFile *f, int stage, void *opaque)
+static int ram_save_live(QEMUFile *f, int stage, void *opaque)
 {
     ram_addr_t addr;
     uint64_t bytes_transferred_last;
@@ -437,7 +437,7 @@ static inline void *host_from_stream_offset(QEMUFile *f,
     return NULL;
 }
 
-int ram_load(QEMUFile *f, void *opaque, int version_id)
+static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
     ram_addr_t addr;
     int flags, ret = 0;
@@ -534,6 +534,11 @@ done:
     return ret;
 }
 
+SaveVMHandlers savevm_ram_handlers = {
+    .save_live_state = ram_save_live,
+    .load_state = ram_load,
+};
+
 #ifdef HAS_AUDIO
 struct soundhw {
     const char *name;
block-migration.c +8 -2
index b95b4e1..00151a0 100644
@@ -709,11 +709,17 @@ static void block_set_params(const MigrationParams *params, void *opaque)
     block_mig_state.blk_enable |= params->shared;
 }
 
+SaveVMHandlers savevm_block_handlers = {
+    .set_params = block_set_params,
+    .save_live_state = block_save_live,
+    .load_state = block_load,
+};
+
 void blk_mig_init(void)
 {
     QSIMPLEQ_INIT(&block_mig_state.bmds_list);
     QSIMPLEQ_INIT(&block_mig_state.blk_list);
 
-    register_savevm_live(NULL, "block", 0, 1, block_set_params,
-                         block_save_live, NULL, block_load, &block_mig_state);
+    register_savevm_live(NULL, "block", 0, 1, &savevm_block_handlers,
+                         &block_mig_state);
 }
migration.h +2 -2
index de13004..57572a6 100644
@@ -18,6 +18,7 @@
 #include "qemu-common.h"
 #include "notify.h"
 #include "error.h"
+#include "vmstate.h"
 
 struct MigrationParams {
     bool blk;
@@ -81,8 +82,7 @@ uint64_t ram_bytes_remaining(void);
 uint64_t ram_bytes_transferred(void);
 uint64_t ram_bytes_total(void);
 
-int ram_save_live(QEMUFile *f, int stage, void *opaque);
-int ram_load(QEMUFile *f, void *opaque, int version_id);
+extern SaveVMHandlers savevm_ram_handlers;
 
 /**
  * @migrate_add_blocker - prevent migration from proceeding
savevm.c +7 -11
index 73626d4..a451be2 100644
@@ -1223,10 +1223,7 @@ int register_savevm_live(DeviceState *dev,
                          const char *idstr,
                          int instance_id,
                          int version_id,
-                         SaveSetParamsHandler *set_params,
-                         SaveLiveStateHandler *save_live_state,
-                         SaveStateHandler *save_state,
-                         LoadStateHandler *load_state,
+                         SaveVMHandlers *ops,
                          void *opaque)
 {
     SaveStateEntry *se;
@@ -1234,16 +1231,12 @@ int register_savevm_live(DeviceState *dev,
     se = g_malloc0(sizeof(SaveStateEntry));
     se->version_id = version_id;
     se->section_id = global_section_id++;
-    se->ops = g_malloc0(sizeof(SaveVMHandlers));
-    se->ops->set_params = set_params;
-    se->ops->save_live_state = save_live_state;
-    se->ops->save_state = save_state;
-    se->ops->load_state = load_state;
+    se->ops = ops;
     se->opaque = opaque;
     se->vmsd = NULL;
     se->no_migrate = 0;
     /* if this is a live_savem then set is_ram */
-    if (save_live_state != NULL) {
+    if (ops->save_live_state != NULL) {
         se->is_ram = 1;
     }
 
@@ -1282,8 +1275,11 @@ int register_savevm(DeviceState *dev,
                     LoadStateHandler *load_state,
                     void *opaque)
 {
+    SaveVMHandlers *ops = g_malloc0(sizeof(SaveVMHandlers));
+    ops->save_state = save_state;
+    ops->load_state = load_state;
     return register_savevm_live(dev, idstr, instance_id, version_id,
-                                NULL, NULL, save_state, load_state, opaque);
+                                ops, opaque);
 }
 
 void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque)
vl.c +1 -2
index 2e140f5..61fe7df 100644
@@ -3437,8 +3437,7 @@ int main(int argc, char **argv, char **envp)
     default_drive(default_sdcard, snapshot, machine->use_scsi,
                   IF_SD, 0, SD_OPTS);
 
-    register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
-                         ram_load, NULL);
+    register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
 
     if (nb_numa_nodes > 0) {
         int i;
vmstate.h +1 -4
index 909af69..4bce53b 100644
@@ -50,10 +50,7 @@ int register_savevm_live(DeviceState *dev,
                          const char *idstr,
                          int instance_id,
                          int version_id,
-                         SaveSetParamsHandler *set_params,
-                         SaveLiveStateHandler *save_live_state,
-                         SaveStateHandler *save_state,
-                         LoadStateHandler *load_state,
+                         SaveVMHandlers *ops,
                          void *opaque);
 
 void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/22 savevm: remove SaveSetParamsHandler

In reply to Juan Quintela

It was used only once, just unfold.

---
 vmstate.h |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
vmstate.h +1 -2
index 4bce53b..5e1a7cc 100644
@@ -26,13 +26,12 @@
 #ifndef QEMU_VMSTATE_H
 #define QEMU_VMSTATE_H 1
 
-typedef void SaveSetParamsHandler(const MigrationParams *params, void * opaque);
 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
 typedef int SaveLiveStateHandler(QEMUFile *f, int stage, void *opaque);
 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
 
 typedef struct SaveVMHandlers {
-    SaveSetParamsHandler *set_params;
+    void (*set_params)(const MigrationParams *params, void * opaque);
     SaveStateHandler *save_state;
     SaveLiveStateHandler *save_live_state;
     LoadStateHandler *load_state;
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 4/22 savevm: remove SaveLiveStateHandler

In reply to Juan Quintela

It was used only once, just unfold.

---
 vmstate.h |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
vmstate.h +1 -2
index 5e1a7cc..0e24834 100644
@@ -27,13 +27,12 @@
 #define QEMU_VMSTATE_H 1
 
 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
-typedef int SaveLiveStateHandler(QEMUFile *f, int stage, void *opaque);
 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
 
 typedef struct SaveVMHandlers {
     void (*set_params)(const MigrationParams *params, void * opaque);
     SaveStateHandler *save_state;
-    SaveLiveStateHandler *save_live_state;
+    int (*save_live_state)(QEMUFile *f, int stage, void *opaque);
     LoadStateHandler *load_state;
 } SaveVMHandlers;
 
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 5/22 savevm: Refactor cancel operation in its own operation

In reply to Juan Quintela

Intead of abusing stage with value -1.

---
 arch_init.c       |   11 ++++++-----
 block-migration.c |   10 ++++++----
 savevm.c          |    4 ++--
 vmstate.h         |    1 +
 4 files changed, 15 insertions(+), 11 deletions(-)
arch_init.c +6 -5
index 606b848..f6bc3fe 100644
@@ -296,6 +296,11 @@ static void migration_end(void)
     memory_global_dirty_log_stop();
 }
 
+static void ram_migration_cancel(void *opaque)
+{
+    migration_end();
+}
+
 #define MAX_WAIT 50 /* ms, half buffered_file limit */
 
 static int ram_save_live(QEMUFile *f, int stage, void *opaque)
@@ -306,11 +311,6 @@ static int ram_save_live(QEMUFile *f, int stage, void *opaque)
     int ret;
     int i;
 
-    if (stage < 0) {
-        migration_end();
-        return 0;
-    }
-
     memory_global_sync_dirty_bitmap(get_system_memory());
 
     if (stage == 1) {
@@ -537,6 +537,7 @@ done:
 SaveVMHandlers savevm_ram_handlers = {
     .save_live_state = ram_save_live,
     .load_state = ram_load,
+    .cancel = ram_migration_cancel,
 };
 
 #ifdef HAS_AUDIO
block-migration.c +6 -4
index 00151a0..cd8a8dd 100644
@@ -536,6 +536,11 @@ static void blk_mig_cleanup(void)
     }
 }
 
+static void block_migration_cancel(void *opaque)
+{
+    blk_mig_cleanup();
+}
+
 static int block_save_live(QEMUFile *f, int stage, void *opaque)
 {
     int ret;
@@ -543,10 +548,6 @@ static int block_save_live(QEMUFile *f, int stage, void *opaque)
     DPRINTF("Enter save live stage %d submitted %d transferred %d\n",
             stage, block_mig_state.submitted, block_mig_state.transferred);
 
-    if (stage < 0) {
-        blk_mig_cleanup();
-        return 0;
-    }
 
     if (block_mig_state.blk_enable != 1) {
         /* no need to migrate storage */
@@ -713,6 +714,7 @@ SaveVMHandlers savevm_block_handlers = {
     .set_params = block_set_params,
     .save_live_state = block_save_live,
     .load_state = block_load,
+    .cancel = block_migration_cancel,
 };
 
 void blk_mig_init(void)
savevm.c +2 -2
index a451be2..888c5a2 100644
@@ -1703,8 +1703,8 @@ void qemu_savevm_state_cancel(QEMUFile *f)
     SaveStateEntry *se;
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
-        if (se->ops && se->ops->save_live_state) {
-            se->ops->save_live_state(f, -1, se->opaque);
+        if (se->ops && se->ops->cancel) {
+            se->ops->cancel(se->opaque);
         }
     }
 }
vmstate.h +1 -0
index 0e24834..1dd42f5 100644
@@ -33,6 +33,7 @@ typedef struct SaveVMHandlers {
     void (*set_params)(const MigrationParams *params, void * opaque);
     SaveStateHandler *save_state;
     int (*save_live_state)(QEMUFile *f, int stage, void *opaque);
+    void (*cancel)(void *opaque);
     LoadStateHandler *load_state;
 } SaveVMHandlers;
 
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH 6/22 savevm: introduce is_active method

In reply to Juan Quintela

Enable the creation of a method to tell migration if that section is active and should be migrate. We use it for blk-migration, that is normally not active. We don't create the method for RAM, as setups without RAM are very strange O:-)

---
 block-migration.c |   13 ++++++-------
 savevm.c          |   15 +++++++++++++++
 vmstate.h         |    1 +
 3 files changed, 22 insertions(+), 7 deletions(-)
block-migration.c +6 -7
index cd8a8dd..6d37dc1 100644
@@ -548,13 +548,6 @@ static int block_save_live(QEMUFile *f, int stage, void *opaque)
     DPRINTF("Enter save live stage %d submitted %d transferred %d\n",
             stage, block_mig_state.submitted, block_mig_state.transferred);
 
-
-    if (block_mig_state.blk_enable != 1) {
-        /* no need to migrate storage */
-        qemu_put_be64(f, BLK_MIG_FLAG_EOS);
-        return 1;
-    }
-
     if (stage == 1) {
         init_blk_migration(f);
 
@@ -710,11 +703,17 @@ static void block_set_params(const MigrationParams *params, void *opaque)
     block_mig_state.blk_enable |= params->shared;
 }
 
+static bool block_is_active(void *opaque)
+{
+    return block_mig_state.blk_enable == 1;
+}
+
 SaveVMHandlers savevm_block_handlers = {
     .set_params = block_set_params,
     .save_live_state = block_save_live,
     .load_state = block_load,
     .cancel = block_migration_cancel,
+    .is_active = block_is_active,
 };
 
 void blk_mig_init(void)
savevm.c +15 -0
index 888c5a2..afa0c9e 100644
@@ -1576,6 +1576,11 @@ int qemu_savevm_state_begin(QEMUFile *f,
         if (!se->ops || !se->ops->save_live_state) {
             continue;
         }
+        if (se->ops && se->ops->is_active) {
+            if (!se->ops->is_active(se->opaque)) {
+                continue;
+            }
+        }
         /* Section type */
         qemu_put_byte(f, QEMU_VM_SECTION_START);
         qemu_put_be32(f, se->section_id);
@@ -1618,6 +1623,11 @@ int qemu_savevm_state_iterate(QEMUFile *f)
         if (!se->ops || !se->ops->save_live_state) {
             continue;
         }
+        if (se->ops && se->ops->is_active) {
+            if (!se->ops->is_active(se->opaque)) {
+                continue;
+            }
+        }
         if (qemu_file_rate_limit(f)) {
             return 0;
         }
@@ -1658,6 +1668,11 @@ int qemu_savevm_state_complete(QEMUFile *f)
         if (!se->ops || !se->ops->save_live_state) {
             continue;
         }
+        if (se->ops && se->ops->is_active) {
+            if (!se->ops->is_active(se->opaque)) {
+                continue;
+            }
+        }
         trace_savevm_section_start();
         /* Section type */
         qemu_put_byte(f, QEMU_VM_SECTION_END);
vmstate.h +1 -0
index 1dd42f5..96651a5 100644
@@ -35,6 +35,7 @@ typedef struct SaveVMHandlers {
     int (*save_live_state)(QEMUFile *f, int stage, void *opaque);
     void (*cancel)(void *opaque);
     LoadStateHandler *load_state;
+    bool (*is_active)(void *opaque);
 } SaveVMHandlers;
 
 int register_savevm(DeviceState *dev,
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 7/22 savevm: split save_live_setup from save_live_state

In reply to Juan Quintela

This patch splits stage 1 to its own function for both save_live users, ram and block. It is just a copy of the function, removing the parts of the other stages. Optimizations would came later.

---
 arch_init.c       |   87 +++++++++++++++++++++++++++++++++++++++--------------
 block-migration.c |   35 ++++++++++++++++-----
 savevm.c          |    4 +--
 vmstate.h         |    1 +
 4 files changed, 96 insertions(+), 31 deletions(-)
arch_init.c +65 -22
index f6bc3fe..2a4903c 100644
@@ -303,44 +303,86 @@ static void ram_migration_cancel(void *opaque)
 
 #define MAX_WAIT 50 /* ms, half buffered_file limit */
 
-static int ram_save_live(QEMUFile *f, int stage, void *opaque)
+static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     ram_addr_t addr;
-    uint64_t bytes_transferred_last;
+    RAMBlock *block;
     double bwidth = 0;
     int ret;
     int i;
 
     memory_global_sync_dirty_bitmap(get_system_memory());
 
-    if (stage == 1) {
-        RAMBlock *block;
-        bytes_transferred = 0;
-        last_block = NULL;
-        last_offset = 0;
-        sort_ram_list();
-
-        /* Make sure all dirty bits are set */
-        QLIST_FOREACH(block, &ram_list.blocks, next) {
-            for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
-                if (!memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE,
-                                             DIRTY_MEMORY_MIGRATION)) {
-                    memory_region_set_dirty(block->mr, addr, TARGET_PAGE_SIZE);
-                }
+    bytes_transferred = 0;
+    last_block = NULL;
+    last_offset = 0;
+    sort_ram_list();
+
+    /* Make sure all dirty bits are set */
+    QLIST_FOREACH(block, &ram_list.blocks, next) {
+        for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
+            if (!memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE,
+                                         DIRTY_MEMORY_MIGRATION)) {
+                memory_region_set_dirty(block->mr, addr, TARGET_PAGE_SIZE);
             }
         }
+    }
 
-        memory_global_dirty_log_start();
+    memory_global_dirty_log_start();
+
+    qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);
+
+    QLIST_FOREACH(block, &ram_list.blocks, next) {
+        qemu_put_byte(f, strlen(block->idstr));
+        qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr));
+        qemu_put_be64(f, block->length);
+    }
+
+    bwidth = qemu_get_clock_ns(rt_clock);
 
-        qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);
+    i = 0;
+    while ((ret = qemu_file_rate_limit(f)) == 0) {
+        int bytes_sent;
 
-        QLIST_FOREACH(block, &ram_list.blocks, next) {
-            qemu_put_byte(f, strlen(block->idstr));
-            qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr));
-            qemu_put_be64(f, block->length);
+        bytes_sent = ram_save_block(f);
+        bytes_transferred += bytes_sent;
+        if (bytes_sent == 0) { /* no more blocks */
+            break;
+        }
+        /* we want to check in the 1st loop, just in case it was the 1st time
+           and we had to sync the dirty bitmap.
+           qemu_get_clock_ns() is a bit expensive, so we only check each some
+           iterations
+        */
+        if ((i & 63) == 0) {
+            uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000;
+            if (t1 > MAX_WAIT) {
+                DPRINTF("big wait: " PRIu64 " milliseconds, %d iterations\n",
+                        t1, i);
+                break;
+            }
         }
+        i++;
+    }
+
+    if (ret < 0) {
+        return ret;
     }
 
+    qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
+
+    return 0;
+}
+
+static int ram_save_live(QEMUFile *f, int stage, void *opaque)
+{
+    uint64_t bytes_transferred_last;
+    double bwidth = 0;
+    int ret;
+    int i;
+
+    memory_global_sync_dirty_bitmap(get_system_memory());
+
     bytes_transferred_last = bytes_transferred;
     bwidth = qemu_get_clock_ns(rt_clock);
 
@@ -535,6 +577,7 @@ done:
 }
 
 SaveVMHandlers savevm_ram_handlers = {
+    .save_live_setup = ram_save_setup,
     .save_live_state = ram_save_live,
     .load_state = ram_load,
     .cancel = ram_migration_cancel,
block-migration.c +28 -7
index 6d37dc1..fc3d1f4 100644
@@ -541,20 +541,40 @@ static void block_migration_cancel(void *opaque)
     blk_mig_cleanup();
 }
 
-static int block_save_live(QEMUFile *f, int stage, void *opaque)
+static int block_save_setup(QEMUFile *f, void *opaque)
 {
     int ret;
 
-    DPRINTF("Enter save live stage %d submitted %d transferred %d\n",
-            stage, block_mig_state.submitted, block_mig_state.transferred);
+    DPRINTF("Enter save live setup submitted %d transferred %d\n",
+            block_mig_state.submitted, block_mig_state.transferred);
 
-    if (stage == 1) {
-        init_blk_migration(f);
+    init_blk_migration(f);
+
+    /* start track dirty blocks */
+    set_dirty_tracking(1);
+
+    flush_blks(f);
 
-        /* start track dirty blocks */
-        set_dirty_tracking(1);
+    ret = qemu_file_get_error(f);
+    if (ret) {
+        blk_mig_cleanup();
+        return ret;
     }
 
+    blk_mig_reset_dirty_cursor();
+
+    qemu_put_be64(f, BLK_MIG_FLAG_EOS);
+
+    return 0;
+}
+
+static int block_save_live(QEMUFile *f, int stage, void *opaque)
+{
+    int ret;
+
+    DPRINTF("Enter save live stage %d submitted %d transferred %d\n",
+            stage, block_mig_state.submitted, block_mig_state.transferred);
+
     flush_blks(f);
 
     ret = qemu_file_get_error(f);
@@ -710,6 +730,7 @@ static bool block_is_active(void *opaque)
 
 SaveVMHandlers savevm_block_handlers = {
     .set_params = block_set_params,
+    .save_live_setup = block_save_setup,
     .save_live_state = block_save_live,
     .load_state = block_load,
     .cancel = block_migration_cancel,
savevm.c +2 -2
index afa0c9e..0b80a94 100644
@@ -1573,7 +1573,7 @@ int qemu_savevm_state_begin(QEMUFile *f,
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
         int len;
 
-        if (!se->ops || !se->ops->save_live_state) {
+        if (!se->ops || !se->ops->save_live_setup) {
             continue;
         }
         if (se->ops && se->ops->is_active) {
@@ -1593,7 +1593,7 @@ int qemu_savevm_state_begin(QEMUFile *f,
         qemu_put_be32(f, se->instance_id);
         qemu_put_be32(f, se->version_id);
 
-        ret = se->ops->save_live_state(f, QEMU_VM_SECTION_START, se->opaque);
+        ret = se->ops->save_live_setup(f, se->opaque);
         if (ret < 0) {
             qemu_savevm_state_cancel(f);
             return ret;
vmstate.h +1 -0
index 96651a5..049f2b7 100644
@@ -32,6 +32,7 @@ typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
 typedef struct SaveVMHandlers {
     void (*set_params)(const MigrationParams *params, void * opaque);
     SaveStateHandler *save_state;
+    int (*save_live_setup)(QEMUFile *f, void *opaque);
     int (*save_live_state)(QEMUFile *f, int stage, void *opaque);
     void (*cancel)(void *opaque);
     LoadStateHandler *load_state;
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH 8/22 savevm: split save_live into stage2 and stage3

In reply to Juan Quintela

We split it into 2 functions, foo_live_iterate, and foo_live_complete. At this point, we only remove the bits that are for the other stage, functionally this is equivalent to previous code.

---
 arch_init.c       |   72 +++++++++++++++++++++++++++++---------
 block-migration.c |   99 ++++++++++++++++++++++++++++++++---------------------
 savevm.c          |   10 +++---
 vmstate.h         |    3 +-
 4 files changed, 122 insertions(+), 62 deletions(-)
arch_init.c +55 -17
index 2a4903c..7e04ea5 100644
@@ -374,12 +374,13 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
     return 0;
 }
 
-static int ram_save_live(QEMUFile *f, int stage, void *opaque)
+static int ram_save_iterate(QEMUFile *f, void *opaque)
 {
     uint64_t bytes_transferred_last;
     double bwidth = 0;
     int ret;
     int i;
+    uint64_t expected_time;
 
     memory_global_sync_dirty_bitmap(get_system_memory());
 
@@ -424,28 +425,64 @@ static int ram_save_live(QEMUFile *f, int stage, void *opaque)
         bwidth = 0.000001;
     }
 
-    /* try transferring iterative blocks of memory */
-    if (stage == 3) {
-        int bytes_sent;
+    qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
+
+    expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
+
+    DPRINTF("ram_save_live: expected(" PRIu64 ") <= max(" PRIu64 ")?\n",
+            expected_time, migrate_max_downtime());
+
+    return expected_time <= migrate_max_downtime();
+}
+
+static int ram_save_complete(QEMUFile *f, void *opaque)
+{
+    double bwidth = 0;
+    int ret;
+    int i;
+    int bytes_sent;
 
-        /* flush all remaining blocks regardless of rate limiting */
-        while ((bytes_sent = ram_save_block(f)) != 0) {
-            bytes_transferred += bytes_sent;
+    memory_global_sync_dirty_bitmap(get_system_memory());
+
+    bwidth = qemu_get_clock_ns(rt_clock);
+
+    i = 0;
+    while ((ret = qemu_file_rate_limit(f)) == 0) {
+        bytes_sent = ram_save_block(f);
+        bytes_transferred += bytes_sent;
+        if (bytes_sent == 0) { /* no more blocks */
+            break;
         }
-        memory_global_dirty_log_stop();
+        /* we want to check in the 1st loop, just in case it was the 1st time
+           and we had to sync the dirty bitmap.
+           qemu_get_clock_ns() is a bit expensive, so we only check each some
+           iterations
+        */
+        if ((i & 63) == 0) {
+            uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000;
+            if (t1 > MAX_WAIT) {
+                DPRINTF("big wait: " PRIu64 " milliseconds, %d iterations\n",
+                        t1, i);
+                break;
+            }
+        }
+        i++;
     }
 
-    qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
-
-    if (stage == 2) {
-        uint64_t expected_time;
-        expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
+    if (ret < 0) {
+        return ret;
+    }
 
-        DPRINTF("ram_save_live: expected(" PRIu64 ") <= max(" PRIu64 ")?\n",
-                expected_time, migrate_max_downtime());
+    /* try transferring iterative blocks of memory */
 
-        return expected_time <= migrate_max_downtime();
+    /* flush all remaining blocks regardless of rate limiting */
+    while ((bytes_sent = ram_save_block(f)) != 0) {
+        bytes_transferred += bytes_sent;
     }
+    memory_global_dirty_log_stop();
+
+    qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
+
     return 0;
 }
 
@@ -578,7 +615,8 @@ done:
 
 SaveVMHandlers savevm_ram_handlers = {
     .save_live_setup = ram_save_setup,
-    .save_live_state = ram_save_live,
+    .save_live_iterate = ram_save_iterate,
+    .save_live_complete = ram_save_complete,
     .load_state = ram_load,
     .cancel = ram_migration_cancel,
 };
block-migration.c +60 -39

135 lines not on this page · raw message

savevm.c +5 -5
index 0b80a94..6e82b2d 100644
@@ -1236,7 +1236,7 @@ int register_savevm_live(DeviceState *dev,
     se->vmsd = NULL;
     se->no_migrate = 0;
     /* if this is a live_savem then set is_ram */
-    if (ops->save_live_state != NULL) {
+    if (ops->save_live_setup != NULL) {
         se->is_ram = 1;
     }
 
@@ -1620,7 +1620,7 @@ int qemu_savevm_state_iterate(QEMUFile *f)
     int ret = 1;
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
-        if (!se->ops || !se->ops->save_live_state) {
+        if (!se->ops || !se->ops->save_live_iterate) {
             continue;
         }
         if (se->ops && se->ops->is_active) {
@@ -1636,7 +1636,7 @@ int qemu_savevm_state_iterate(QEMUFile *f)
         qemu_put_byte(f, QEMU_VM_SECTION_PART);
         qemu_put_be32(f, se->section_id);
 
-        ret = se->ops->save_live_state(f, QEMU_VM_SECTION_PART, se->opaque);
+        ret = se->ops->save_live_iterate(f, se->opaque);
         trace_savevm_section_end(se->section_id);
 
         if (ret <= 0) {
@@ -1665,7 +1665,7 @@ int qemu_savevm_state_complete(QEMUFile *f)
     cpu_synchronize_all_states();
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
-        if (!se->ops || !se->ops->save_live_state) {
+        if (!se->ops || !se->ops->save_live_complete) {
             continue;
         }
         if (se->ops && se->ops->is_active) {
@@ -1678,7 +1678,7 @@ int qemu_savevm_state_complete(QEMUFile *f)
         qemu_put_byte(f, QEMU_VM_SECTION_END);
         qemu_put_be32(f, se->section_id);
 
-        ret = se->ops->save_live_state(f, QEMU_VM_SECTION_END, se->opaque);
+        ret = se->ops->save_live_complete(f, se->opaque);
         trace_savevm_section_end(se->section_id);
         if (ret < 0) {
             return ret;
vmstate.h +2 -1
index 049f2b7..5bd2b76 100644
@@ -33,7 +33,8 @@ typedef struct SaveVMHandlers {
     void (*set_params)(const MigrationParams *params, void * opaque);
     SaveStateHandler *save_state;
     int (*save_live_setup)(QEMUFile *f, void *opaque);
-    int (*save_live_state)(QEMUFile *f, int stage, void *opaque);
+    int (*save_live_iterate)(QEMUFile *f, void *opaque);
+    int (*save_live_complete)(QEMUFile *f, void *opaque);
     void (*cancel)(void *opaque);
     LoadStateHandler *load_state;
     bool (*is_active)(void *opaque);
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH 9/22 ram: save_live_setup() don't need to sent pages

In reply to Juan Quintela

We should send pages on interate phase, not in setup one. This was a "bug". Just removing the loop does what we want. Tested that it works with current ram_load().

---
 arch_init.c |   34 ----------------------------------
 1 file changed, 34 deletions(-)
arch_init.c +0 -34
index 7e04ea5..2a6fc77 100644
@@ -307,9 +307,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     ram_addr_t addr;
     RAMBlock *block;
-    double bwidth = 0;
-    int ret;
-    int i;
 
     memory_global_sync_dirty_bitmap(get_system_memory());
 
@@ -338,37 +335,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
         qemu_put_be64(f, block->length);
     }
 
-    bwidth = qemu_get_clock_ns(rt_clock);
-
-    i = 0;
-    while ((ret = qemu_file_rate_limit(f)) == 0) {
-        int bytes_sent;
-
-        bytes_sent = ram_save_block(f);
-        bytes_transferred += bytes_sent;
-        if (bytes_sent == 0) { /* no more blocks */
-            break;
-        }
-        /* we want to check in the 1st loop, just in case it was the 1st time
-           and we had to sync the dirty bitmap.
-           qemu_get_clock_ns() is a bit expensive, so we only check each some
-           iterations
-        */
-        if ((i & 63) == 0) {
-            uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000;
-            if (t1 > MAX_WAIT) {
-                DPRINTF("big wait: " PRIu64 " milliseconds, %d iterations\n",
-                        t1, i);
-                break;
-            }
-        }
-        i++;
-    }
-
-    if (ret < 0) {
-        return ret;
-    }
-
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
 
     return 0;
Signature · 1 line
1.7.10.4
#10 lore raw

PATCH 10/22 ram: save_live_complete() only do one loop

In reply to Juan Quintela

We were doing the same loop that stage2, and a new one for stage3. We only need the one for stage3.

---
 arch_init.c |   32 --------------------------------
 1 file changed, 32 deletions(-)
arch_init.c +0 -32
index 2a6fc77..3c38a52 100644
@@ -403,42 +403,10 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 
 static int ram_save_complete(QEMUFile *f, void *opaque)
 {
-    double bwidth = 0;
-    int ret;
-    int i;
     int bytes_sent;
 
     memory_global_sync_dirty_bitmap(get_system_memory());
 
-    bwidth = qemu_get_clock_ns(rt_clock);
-
-    i = 0;
-    while ((ret = qemu_file_rate_limit(f)) == 0) {
-        bytes_sent = ram_save_block(f);
-        bytes_transferred += bytes_sent;
-        if (bytes_sent == 0) { /* no more blocks */
-            break;
-        }
-        /* we want to check in the 1st loop, just in case it was the 1st time
-           and we had to sync the dirty bitmap.
-           qemu_get_clock_ns() is a bit expensive, so we only check each some
-           iterations
-        */
-        if ((i & 63) == 0) {
-            uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000;
-            if (t1 > MAX_WAIT) {
-                DPRINTF("big wait: " PRIu64 " milliseconds, %d iterations\n",
-                        t1, i);
-                break;
-            }
-        }
-        i++;
-    }
-
-    if (ret < 0) {
-        return ret;
-    }
-
     /* try transferring iterative blocks of memory */
 
     /* flush all remaining blocks regardless of rate limiting */
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH 11/22 ram: iterate phase

In reply to Juan Quintela

We only need to synchronize the bitmap when the number of dirty pages is low. Not every time that we call the function.

---
 arch_init.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
arch_init.c +7 -3
index 3c38a52..b08c615 100644
@@ -348,8 +348,6 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
     int i;
     uint64_t expected_time;
 
-    memory_global_sync_dirty_bitmap(get_system_memory());
-
     bytes_transferred_last = bytes_transferred;
     bwidth = qemu_get_clock_ns(rt_clock);
 
@@ -398,7 +396,13 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
     DPRINTF("ram_save_live: expected(" PRIu64 ") <= max(" PRIu64 ")?\n",
             expected_time, migrate_max_downtime());
 
-    return expected_time <= migrate_max_downtime();
+    if (expected_time <= migrate_max_downtime()) {
+        memory_global_sync_dirty_bitmap(get_system_memory());
+        expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
+
+        return expected_time <= migrate_max_downtime();
+    }
+    return 0;
 }
 
 static int ram_save_complete(QEMUFile *f, void *opaque)
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH 12/22 ram: save_live_setup() we don't need to synchronize the dirty bitmap.

In reply to Juan Quintela

1st: we were synchonizing the dirty bitmap before calling
memory_global_dirty_log_start().

2nd: We are marking all pages as dirty anywhere, no reason to go
through all the bitmap to "mark" dirty same pages twice.

So, call removed.

---
 arch_init.c |    2 --
 1 file changed, 2 deletions(-)
arch_init.c +0 -2
index b08c615..8cbf8f4 100644
@@ -308,8 +308,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
     ram_addr_t addr;
     RAMBlock *block;
 
-    memory_global_sync_dirty_bitmap(get_system_memory());
-
     bytes_transferred = 0;
     last_block = NULL;
     last_offset = 0;
Signature · 1 line
1.7.10.4
#13 lore raw

PATCH 13/22 Add migration capabilities

In reply to Juan Quintela

From: Orit Wasserman <[email protected]>

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

---
 hmp-commands.hx  |   16 ++++++++++++
 hmp.c            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    2 ++
 migration.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.h      |    2 ++
 monitor.c        |    7 ++++++
 qapi-schema.json |   53 ++++++++++++++++++++++++++++++++++++++--
 qmp-commands.hx  |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 280 insertions(+), 7 deletions(-)
hmp-commands.hx +16 -0
index f5d9d91..9245bef 100644
@@ -861,6 +861,20 @@ Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
 
     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "",
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+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",
@@ -1419,6 +1433,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migration_capabilities
+show migration capabilities
 @item info balloon
 show balloon information
 @item info qtree
hmp.c +64 -0

85 lines not on this page · raw message

hmp.h +2 -0
index 79d138d..09ba198 100644
@@ -25,6 +25,7 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_info_mice(Monitor *mon);
 void hmp_info_migrate(Monitor *mon);
+void hmp_info_migration_capabilities(Monitor *mon);
 void hmp_info_cpus(Monitor *mon);
 void hmp_info_block(Monitor *mon);
 void hmp_info_blockstats(Monitor *mon);
@@ -51,6 +52,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(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);
migration.c +70 -2

106 lines not on this page · raw message

migration.h +2 -0
index 57572a6..713aae0 100644
@@ -19,6 +19,7 @@
 #include "notify.h"
 #include "error.h"
 #include "vmstate.h"
+#include "qapi-types.h"
 
 struct MigrationParams {
     bool blk;
@@ -39,6 +40,7 @@ struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };
 
 void process_incoming_migration(QEMUFile *f);
monitor.c +7 -0
index f6107ba..e2be6cd 100644
@@ -2687,6 +2687,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_migrate,
     },
     {
+        .name       = "migration_capabilities",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration capabilities",
+        .mhandler.info = hmp_info_migration_capabilities,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
qapi-schema.json +51 -2

68 lines not on this page · raw message

qmp-commands.hx +68 -3

104 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#14 lore raw

Re: [Qemu-devel] [PATCH 13/22] Add migration capabilities

Quoted 7 lines · On Fri, 13 Jul 2012 09:23:35 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

Please, split this into one command per-patch. Otherwise it's difficult to review.

Have libvirt folks acked this approach btw? It looks fine to me, but we need their ack too.

More comments below.

Quoted 19 lines
---
 hmp-commands.hx  |   16 ++++++++++++
 hmp.c            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    2 ++
 migration.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.h      |    2 ++
 monitor.c        |    7 ++++++
 qapi-schema.json |   53 ++++++++++++++++++++++++++++++++++++++--
 qmp-commands.hx  |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 280 insertions(+), 7 deletions(-)
hmp-commands.hx +0 -0
index f5d9d91..9245bef 100644

hmp-commands.hx Set maximum tolerated downtime (in seconds) for migration. · line 866

Quoted 6 lines
hmp-commands.hx +3 -0
@@ -861,6 +861,20 @@ Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
 
     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "",

Please, fill in params.

Quoted 33 lines
hmp-commands.hx +13 -0
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+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",
@@ -1419,6 +1433,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migration_capabilities
+show migration capabilities
 @item info balloon
 show balloon information
 @item info qtree
hmp.c +1 -0
index 4c6d4ae..b0440e6 100644
@@ -131,9 +131,19 @@ void hmp_info_mice(Monitor *mon)
 void hmp_info_migrate(Monitor *mon)
 {
     MigrationInfo *info;
+    MigrationCapabilityInfoList *cap;
 

hmp.c void hmp_info_mice(Monitor *mon) · line 145

Quoted 10 lines
hmp.c +8 -0
     info = qmp_query_migrate(NULL);
 
+    if (info->has_capabilities && info->capabilities) {
+        monitor_printf(mon, "capabilities: ");
+        for (cap = info->capabilities; cap; cap = cap->next) {
+            monitor_printf(mon, "%s: %s ",
+                           MigrationCapability_lookup[cap->value->capability],
+                           cap->value->state ? "on" : "off");
+        }
+        monitor_printf(mon, "\n");

Why is this is needed? Isn't info migration-capabilities good enough? Besides, info migrate should only contain information about current migration process...

Quoted 139 lines
hmp.c +55 -0
+    }
     if (info->has_status) {
         monitor_printf(mon, "Migration status: %s\n", info->status);
     }
@@ -161,6 +171,25 @@ void hmp_info_migrate(Monitor *mon)
     qapi_free_MigrationInfo(info);
 }
 
+void hmp_info_migration_capabilities(Monitor *mon)
+{
+    MigrationCapabilityInfoList *caps_list, *cap;
+
+    caps_list = qmp_query_migration_capabilities(NULL);
+    if (!caps_list) {
+        monitor_printf(mon, "No migration capabilities found\n");
+        return;
+    }
+
+    for (cap = caps_list; cap; cap = cap->next) {
+        monitor_printf(mon, "%s: %s ",
+                       MigrationCapability_lookup[cap->value->capability],
+                       cap->value->state ? "on" : "off");
+    }
+
+    qapi_free_MigrationCapabilityInfoList(caps_list);
+}
+
 void hmp_info_cpus(Monitor *mon)
 {
     CpuInfoList *cpu_list, *cpu;
@@ -735,6 +764,41 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_speed(value, NULL);
 }
 
+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
+{
+    const char *cap = qdict_get_str(qdict, "capability");
+    bool state = qdict_get_bool(qdict, "state");
+    Error *err = NULL;
+    MigrationCapabilityInfoList *params = NULL;
+    int i;
+
+    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
+            if (!params) {
+                params = g_malloc0(sizeof(*params));
+            }
+            params->value = g_malloc0(sizeof(*params->value));
+            params->value->capability = i;
+            params->value->state = state;
+            params->next = NULL;
+            qmp_migrate_set_parameters(params, &err);
+            break;
+        }
+    }
+
+    if (i == MIGRATION_CAPABILITY_MAX) {
+        error_set(&err, QERR_INVALID_PARAMETER, cap);
+    }
+
+    qapi_free_MigrationCapabilityInfoList(params);
+
+    if (err) {
+        monitor_printf(mon, "migrate_set_parameter: %s\n",
+                       error_get_pretty(err));
+        error_free(err);
+    }
+}
+
 void hmp_set_password(Monitor *mon, const QDict *qdict)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
hmp.h +2 -0
index 79d138d..09ba198 100644
@@ -25,6 +25,7 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_info_mice(Monitor *mon);
 void hmp_info_migrate(Monitor *mon);
+void hmp_info_migration_capabilities(Monitor *mon);
 void hmp_info_cpus(Monitor *mon);
 void hmp_info_block(Monitor *mon);
 void hmp_info_blockstats(Monitor *mon);
@@ -51,6 +52,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(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);
migration.c +26 -1
index 8db1b43..fd004d7 100644
@@ -117,12 +117,36 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 {
     MigrationInfo *info = g_malloc0(sizeof(*info));
     MigrationState *s = migrate_get_current();
+    int i;
 
     switch (s->state) {
     case MIG_STATE_SETUP:
-        /* no migration has happened ever */
+        /* no migration has ever happened; show enabled capabilities */
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
         break;
     case MIG_STATE_ACTIVE:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
+
         info->has_status = true;
         info->status = g_strdup("active");
 
@@ -143,6 +167,18 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         }
         break;
     case MIG_STATE_COMPLETED:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 180

Quoted 10 lines
migration.c +10 -0
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }

Code triplication :)

Why is this is needed? Isn't query-migration-capabilities good enough? Besides, query-migrate should only contain information about current migration process...

Quoted 5 lines
migration.c +1 -0
+
         info->has_status = true;
         info->status = g_strdup("completed");
 

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 211

Quoted 10 lines
migration.c +7 -0
@@ -166,6 +202,33 @@ MigrationInfo *qmp_query_migrate(Error **errp)
     return info;
 }
 
+MigrationCapabilityInfoList *qmp_query_migration_capabilities(Error **errp)
+{
+    MigrationCapabilityInfoList *caps_list = g_malloc0(sizeof(*caps_list));
+
+    caps_list->value = g_malloc(sizeof(*caps_list->value));
+    caps_list->value->capability = MIGRATION_CAPABILITY_XBZRLE;
+    caps_list->next = NULL;

Shouldn't this get the capabilities array from migrate_get_current()?

I mean, this makes query-migration-capabilities always return true for xbzrle, even if we set it to off.

Quoted 67 lines
migration.c +26 -1
+
+    return caps_list;
+}
+
+void qmp_migrate_set_parameters(MigrationCapabilityInfoList *params,
+                                Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+    MigrationCapabilityInfoList *cap;
+
+    if (s->state == MIG_STATE_ACTIVE) {
+        error_set(errp, QERR_MIGRATION_ACTIVE);
+        return;
+    }
+
+    for (cap = params; cap; cap = cap->next) {
+        s->enabled_capabilities[cap->value->capability] = cap->value->state;
+    }
+}
+
 /* shared migration helpers */
 
 static int migrate_fd_cleanup(MigrationState *s)
@@ -375,12 +438,17 @@ static MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+
+    memcpy(enabled_capabilities, s->enabled_capabilities,
+           sizeof(enabled_capabilities));
 
     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
     s->params = *params;
+    memcpy(s->enabled_capabilities, enabled_capabilities,
+           sizeof(enabled_capabilities));
 
-    s->bandwidth_limit = bandwidth_limit;
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);
 
migration.h +2 -0
index 57572a6..713aae0 100644
@@ -19,6 +19,7 @@
 #include "notify.h"
 #include "error.h"
 #include "vmstate.h"
+#include "qapi-types.h"
 
 struct MigrationParams {
     bool blk;
@@ -39,6 +40,7 @@ struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };
 
 void process_incoming_migration(QEMUFile *f);
monitor.c +0 -0
index f6107ba..e2be6cd 100644

monitor.c static mon_cmd_t info_cmds[] = { · line 2690

Quoted 4 lines
monitor.c +1 -0
@@ -2687,6 +2687,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_migrate,
     },
     {
+        .name       = "migration_capabilities",

migration-capabilities is better.

Quoted 14 lines
monitor.c +6 -0
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration capabilities",
+        .mhandler.info = hmp_info_migration_capabilities,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
qapi-schema.json +0 -0
index 1ab5dbd..a8408fd 100644

qapi-schema.json line 292

Quoted 6 lines
qapi-schema.json +2 -1
@@ -288,11 +288,15 @@
 #        status, only returned if status is 'active' and it is a block
 #        migration
 #
-# Since: 0.14.0
+# @capabilities: #optional a list describing all the migration capabilities
+#                state

I don't think this is needed, as I've said above.

Quoted 12 lines
qapi-schema.json +4 -1
+#
+# Since: 0.14.0, 'capabilities' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
-           '*disk': 'MigrationStats'} }
+           '*disk': 'MigrationStats',
+           '*capabilities': ['MigrationCapabilityInfo']} }
 
 ##
 # @query-migrate

qapi-schema.json line 317

Quoted 8 lines
qapi-schema.json +5 -0
@@ -306,6 +310,51 @@
 { 'command': 'query-migrate', 'returns': 'MigrationInfo' }
 
 ##
+# @MigrationCapability
+#
+# Migration capabilities enumeration
+#
+# @xbzrle: current migration supports xbzrle

You should explain what xbzrle is.

qapi-schema.json line 325

Quoted 8 lines
qapi-schema.json +8 -0
+#
+# Since: 1.2
+##
+{ 'enum': 'MigrationCapability',
+  'data': ['xbzrle'] }
+
+##
+# @MigrationCapabilityInfo

MigrationCapabilityStatus?

qapi-schema.json line 329

Quoted 4 lines
qapi-schema.json +4 -0
+#
+# Migration capability information
+#
+# @capability: capability enum

Please, document state too.

Quoted 143 lines
qapi-schema.json +28 -0
+#
+# Since: 1.2
+##
+{ 'type': 'MigrationCapabilityInfo',
+  'data': { 'capability' : 'MigrationCapability', 'state' : 'bool' } }
+
+##
+# @query-migration-capabilities
+#
+# Returns information about current migration process capabilties.
+#
+# Returns: @MigrationCapabilityInfo list
+#
+# Since: 1.2
+##
+{ 'command': 'query-migration-capabilities', 'returns': ['MigrationCapabilityInfo'] }
+
+##
+# @migrate_set_parameters
+#
+# Enable/Disable the following migration capabilities (like xbzrle)
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-parameters',
+  'data': { 'capabilities': ['MigrationCapabilityInfo'] } }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +68 -3
index 2e1a38e..3ee6e00 100644
@@ -2075,18 +2075,31 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
-
+- "capabilities": migration capabilities state
+         - "xbzrle" : XBZRLE state (json-bool)
 Examples:
 
 1. Before the first migration
 
 -> { "execute": "query-migrate" }
-<- { "return": {} }
+<- { "return": {
+        "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
+     }
+   }
 
 2. Migration is done and has succeeded
 
 -> { "execute": "query-migrate" }
-<- { "return": { "status": "completed" } }
+<- { "return": {
+        "status": "completed",
+        "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
+        "ram":{
+          "transferred":123,
+          "remaining":123,
+          "total":246
+        }
+     }
+   }
 
 3. Migration is done and has failed
 
@@ -2099,6 +2112,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "transferred":123,
             "remaining":123,
@@ -2113,6 +2127,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "total":1057024,
             "remaining":1053304,
@@ -2135,6 +2150,56 @@ EQMP
     },
 
 SQMP
+query-migration-capabilities
+-------
+
+Query migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "query-migration-capabilities"}
+<- { "return": [ { "capability": "xbzrle", "state": true },
+                 { "capability": "foobar", "state": false } ] }
+
+EQMP
+
+    {
+        .name       = "query-migration-capabilities",
+        .args_type  = "",
+	.mhandler.cmd_new = qmp_marshal_input_query_migration_capabilities,
+    },
+
+SQMP
+migrate_set_parameters
+-------
+
+Enable/Disable migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "migrate_set_parameters" , "arguments":
+     { "parameters": [ { "capability": "xbzrle", "state": true } ] } }
+
+EQMP
+
+    {
+        .name       = "migrate_set_parameters",
+        .args_type  = "parameters:O",
+	.params     = "capability:s,state:b",
+	.mhandler.cmd_new = qmp_marshal_input_migrate_set_parameters,
+    },
+
+
+
+SQMP
 query-balloon
 -------------
 
#15 lore raw

Re: [Qemu-devel] [PATCH 13/22] Add migration capabilities

Quoted 11 lines · Luiz Capitulino
Quoted 7 lines · On Fri, 13 Jul 2012 09:23:35 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

Quoted 5 lines

Please, split this into one command per-patch. Otherwise it's difficult to review.

Have libvirt folks acked this approach btw? It looks fine to me, but we need their ack too.

Yes, I've been reviewing versions of this series, and am okay with the libvirt impact with the current proposed set of new QMP commands.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#16 lore raw

Re: [Qemu-devel] [PATCH 13/22] Add migration capabilities

In reply to Luiz Capitulino
Quoted 5 lines · Luiz Capitulino
Quoted 2 lines · On Fri, 13 Jul 2012 09:23:35 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

Quoted 9 lines
Quoted 5 lines

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

Please, split this into one command per-patch. Otherwise it's difficult to review.

Sure.

Quoted 26 lines

Have libvirt folks acked this approach btw? It looks fine to me, but we need their ack too.

More comments below.

Quoted 21 lines
---
 hmp-commands.hx  |   16 ++++++++++++
 hmp.c            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    2 ++
 migration.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.h      |    2 ++
 monitor.c        |    7 ++++++
 qapi-schema.json |   53 ++++++++++++++++++++++++++++++++++++++--
 qmp-commands.hx  |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 280 insertions(+), 7 deletions(-)
hmp-commands.hx +0 -0
index f5d9d91..9245bef 100644
@@ -861,6 +861,20 @@ Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
 
Quoted 6 lines

hmp-commands.hx Set maximum tolerated downtime (in seconds) for migration. · line 866

Quoted 4 lines
hmp-commands.hx +3 -0
     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "",

Please, fill in params.

ok

Quoted 36 lines
Quoted 36 lines
hmp-commands.hx +13 -0
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+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",
@@ -1419,6 +1433,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migration_capabilities
+show migration capabilities
 @item info balloon
 show balloon information
 @item info qtree
hmp.c +1 -0
index 4c6d4ae..b0440e6 100644
@@ -131,9 +131,19 @@ void hmp_info_mice(Monitor *mon)
 void hmp_info_migrate(Monitor *mon)
 {
     MigrationInfo *info;
+    MigrationCapabilityInfoList *cap;
 
     info = qmp_query_migrate(NULL);
 
Quoted 12 lines

hmp.c void hmp_info_mice(Monitor *mon) · line 145

Quoted 8 lines
hmp.c +8 -0
+    if (info->has_capabilities && info->capabilities) {
+        monitor_printf(mon, "capabilities: ");
+        for (cap = info->capabilities; cap; cap = cap->next) {
+            monitor_printf(mon, "%s: %s ",
+                           MigrationCapability_lookup[cap->value->capability],
+                           cap->value->state ? "on" : "off");
+        }
+        monitor_printf(mon, "\n");

Why is this is needed? Isn't info migration-capabilities good enough? Besides, info migrate should only contain information about current migration process...

The reason we introduced capabilities is that xbzrle needs for both source and destination QEMU to be able to handle it. Even if both side support xbzrle the user may decide not to use it. User that wants to use xbzrle needs to check that both sides have support for it (using info capabilities) , than enable it in both sides (using migrate-set-parameter/s commands). This is a parameter for the current migration. So the user needs to know if xbzrle was enabled or disabled for the current migration, this code displays it.

some day when there will be better migration protocol, feature negotiations can be part of it ...

Quoted 153 lines
Quoted 140 lines
hmp.c +55 -0
+    }
     if (info->has_status) {
         monitor_printf(mon, "Migration status: %s\n", info->status);
     }
@@ -161,6 +171,25 @@ void hmp_info_migrate(Monitor *mon)
     qapi_free_MigrationInfo(info);
 }
 
+void hmp_info_migration_capabilities(Monitor *mon)
+{
+    MigrationCapabilityInfoList *caps_list, *cap;
+
+    caps_list = qmp_query_migration_capabilities(NULL);
+    if (!caps_list) {
+        monitor_printf(mon, "No migration capabilities found\n");
+        return;
+    }
+
+    for (cap = caps_list; cap; cap = cap->next) {
+        monitor_printf(mon, "%s: %s ",
+                       MigrationCapability_lookup[cap->value->capability],
+                       cap->value->state ? "on" : "off");
+    }
+
+    qapi_free_MigrationCapabilityInfoList(caps_list);
+}
+
 void hmp_info_cpus(Monitor *mon)
 {
     CpuInfoList *cpu_list, *cpu;
@@ -735,6 +764,41 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_speed(value, NULL);
 }
 
+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
+{
+    const char *cap = qdict_get_str(qdict, "capability");
+    bool state = qdict_get_bool(qdict, "state");
+    Error *err = NULL;
+    MigrationCapabilityInfoList *params = NULL;
+    int i;
+
+    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
+            if (!params) {
+                params = g_malloc0(sizeof(*params));
+            }
+            params->value = g_malloc0(sizeof(*params->value));
+            params->value->capability = i;
+            params->value->state = state;
+            params->next = NULL;
+            qmp_migrate_set_parameters(params, &err);
+            break;
+        }
+    }
+
+    if (i == MIGRATION_CAPABILITY_MAX) {
+        error_set(&err, QERR_INVALID_PARAMETER, cap);
+    }
+
+    qapi_free_MigrationCapabilityInfoList(params);
+
+    if (err) {
+        monitor_printf(mon, "migrate_set_parameter: %s\n",
+                       error_get_pretty(err));
+        error_free(err);
+    }
+}
+
 void hmp_set_password(Monitor *mon, const QDict *qdict)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
hmp.h +2 -0
index 79d138d..09ba198 100644
@@ -25,6 +25,7 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_info_mice(Monitor *mon);
 void hmp_info_migrate(Monitor *mon);
+void hmp_info_migration_capabilities(Monitor *mon);
 void hmp_info_cpus(Monitor *mon);
 void hmp_info_block(Monitor *mon);
 void hmp_info_blockstats(Monitor *mon);
@@ -51,6 +52,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(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);
migration.c +26 -1
index 8db1b43..fd004d7 100644
@@ -117,12 +117,36 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 {
     MigrationInfo *info = g_malloc0(sizeof(*info));
     MigrationState *s = migrate_get_current();
+    int i;
 
     switch (s->state) {
     case MIG_STATE_SETUP:
-        /* no migration has happened ever */
+        /* no migration has ever happened; show enabled capabilities */
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
         break;
     case MIG_STATE_ACTIVE:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
+
         info->has_status = true;
         info->status = g_strdup("active");
 
@@ -143,6 +167,18 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         }
         break;
     case MIG_STATE_COMPLETED:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 180

Quoted 10 lines
migration.c +10 -0
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }

Code triplication :)

Quoted 4 lines

Why is this is needed? Isn't query-migration-capabilities good enough? Besides, query-migrate should only contain information about current migration process...

see above

Quoted 18 lines
Quoted 5 lines
migration.c +1 -0
+
         info->has_status = true;
         info->status = g_strdup("completed");
 

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 211

Quoted 10 lines
migration.c +7 -0
@@ -166,6 +202,33 @@ MigrationInfo *qmp_query_migrate(Error **errp)
     return info;
 }
 
+MigrationCapabilityInfoList *qmp_query_migration_capabilities(Error **errp)
+{
+    MigrationCapabilityInfoList *caps_list = g_malloc0(sizeof(*caps_list));
+
+    caps_list->value = g_malloc(sizeof(*caps_list->value));
+    caps_list->value->capability = MIGRATION_CAPABILITY_XBZRLE;
+    caps_list->next = NULL;

Shouldn't this get the capabilities array from migrate_get_current()?

Quoted 2 lines

I mean, this makes query-migration-capabilities always return true for xbzrle, even if we set it to off.

Those are the general capabilities , if I want to use xbzrle ,does this QEMU support it ?
this is required because we need both the destination and the source to be able to handle it.
If one QEMU doesn't (older version of qemu, maybe it will be disbaled for certain architectures) we can't use the feature. This is for management and the user to check what migration capabilities this QEMU supports.

Quoted 62 lines
Quoted 62 lines
migration.c +26 -1
+
+    return caps_list;
+}
+
+void qmp_migrate_set_parameters(MigrationCapabilityInfoList *params,
+                                Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+    MigrationCapabilityInfoList *cap;
+
+    if (s->state == MIG_STATE_ACTIVE) {
+        error_set(errp, QERR_MIGRATION_ACTIVE);
+        return;
+    }
+
+    for (cap = params; cap; cap = cap->next) {
+        s->enabled_capabilities[cap->value->capability] = cap->value->state;
+    }
+}
+
 /* shared migration helpers */
 
 static int migrate_fd_cleanup(MigrationState *s)
@@ -375,12 +438,17 @@ static MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+
+    memcpy(enabled_capabilities, s->enabled_capabilities,
+           sizeof(enabled_capabilities));
 
     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
     s->params = *params;
+    memcpy(s->enabled_capabilities, enabled_capabilities,
+           sizeof(enabled_capabilities));
 
-    s->bandwidth_limit = bandwidth_limit;
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);
 
migration.h +2 -0
index 57572a6..713aae0 100644
@@ -19,6 +19,7 @@
 #include "notify.h"
 #include "error.h"
 #include "vmstate.h"
+#include "qapi-types.h"
 
 struct MigrationParams {
     bool blk;
@@ -39,6 +40,7 @@ struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };
 
Quoted 12 lines

monitor.c static mon_cmd_t info_cmds[] = { · line 2690

Quoted 10 lines
migration.h +0 -0
 void process_incoming_migration(QEMUFile *f);
monitor.c +1 -0
index f6107ba..e2be6cd 100644
@@ -2687,6 +2687,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_migrate,
     },
     {
+        .name       = "migration_capabilities",

migration-capabilities is better.

ok

Quoted 15 lines
Quoted 15 lines
monitor.c +6 -0
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration capabilities",
+        .mhandler.info = hmp_info_migration_capabilities,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
qapi-schema.json +0 -0
index 1ab5dbd..a8408fd 100644
@@ -288,11 +288,15 @@
Quoted 8 lines

qapi-schema.json line 292

Quoted 6 lines
qapi-schema.json +2 -1
 #        status, only returned if status is 'active' and it is a block
 #        migration
 #
-# Since: 0.14.0
+# @capabilities: #optional a list describing all the migration capabilities
+#                state

I don't think this is needed, as I've said above.

see above

Quoted 15 lines
Quoted 15 lines
qapi-schema.json +4 -1
+#
+# Since: 0.14.0, 'capabilities' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
-           '*disk': 'MigrationStats'} }
+           '*disk': 'MigrationStats',
+           '*capabilities': ['MigrationCapabilityInfo']} }
 
 ##
 # @query-migrate
@@ -306,6 +310,51 @@
 { 'command': 'query-migrate', 'returns': 'MigrationInfo' }
 
Quoted 8 lines

qapi-schema.json line 317

Quoted 6 lines
qapi-schema.json +5 -0
 ##
+# @MigrationCapability
+#
+# Migration capabilities enumeration
+#
+# @xbzrle: current migration supports xbzrle

You should explain what xbzrle is.

ok

Quoted 12 lines

qapi-schema.json line 325

Quoted 9 lines
qapi-schema.json +8 -0
+#
+# Since: 1.2
+##
+{ 'enum': 'MigrationCapability',
+  'data': ['xbzrle'] }
+
+##
+# @MigrationCapabilityInfo

MigrationCapabilityStatus?

Quoted 6 lines

qapi-schema.json line 329

Quoted 4 lines
qapi-schema.json +4 -0
+#
+# Migration capability information
+#
+# @capability: capability enum

Please, document state too.

ok

Orit

Quoted 145 lines
Quoted 144 lines
qapi-schema.json +28 -0
+#
+# Since: 1.2
+##
+{ 'type': 'MigrationCapabilityInfo',
+  'data': { 'capability' : 'MigrationCapability', 'state' : 'bool' } }
+
+##
+# @query-migration-capabilities
+#
+# Returns information about current migration process capabilties.
+#
+# Returns: @MigrationCapabilityInfo list
+#
+# Since: 1.2
+##
+{ 'command': 'query-migration-capabilities', 'returns': ['MigrationCapabilityInfo'] }
+
+##
+# @migrate_set_parameters
+#
+# Enable/Disable the following migration capabilities (like xbzrle)
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-parameters',
+  'data': { 'capabilities': ['MigrationCapabilityInfo'] } }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +68 -3
index 2e1a38e..3ee6e00 100644
@@ -2075,18 +2075,31 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
-
+- "capabilities": migration capabilities state
+         - "xbzrle" : XBZRLE state (json-bool)
 Examples:
 
 1. Before the first migration
 
 -> { "execute": "query-migrate" }
-<- { "return": {} }
+<- { "return": {
+        "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
+     }
+   }
 
 2. Migration is done and has succeeded
 
 -> { "execute": "query-migrate" }
-<- { "return": { "status": "completed" } }
+<- { "return": {
+        "status": "completed",
+        "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
+        "ram":{
+          "transferred":123,
+          "remaining":123,
+          "total":246
+        }
+     }
+   }
 
 3. Migration is done and has failed
 
@@ -2099,6 +2112,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "transferred":123,
             "remaining":123,
@@ -2113,6 +2127,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "total":1057024,
             "remaining":1053304,
@@ -2135,6 +2150,56 @@ EQMP
     },
 
 SQMP
+query-migration-capabilities
+-------
+
+Query migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "query-migration-capabilities"}
+<- { "return": [ { "capability": "xbzrle", "state": true },
+                 { "capability": "foobar", "state": false } ] }
+
+EQMP
+
+    {
+        .name       = "query-migration-capabilities",
+        .args_type  = "",
+	.mhandler.cmd_new = qmp_marshal_input_query_migration_capabilities,
+    },
+
+SQMP
+migrate_set_parameters
+-------
+
+Enable/Disable migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "migrate_set_parameters" , "arguments":
+     { "parameters": [ { "capability": "xbzrle", "state": true } ] } }
+
+EQMP
+
+    {
+        .name       = "migrate_set_parameters",
+        .args_type  = "parameters:O",
+	.params     = "capability:s,state:b",
+	.mhandler.cmd_new = qmp_marshal_input_migrate_set_parameters,
+    },
+
+
+
+SQMP
 query-balloon
 -------------
 
#17 lore raw

Re: [Qemu-devel] [PATCH 13/22] Add migration capabilities

Quoted 97 lines · On Tue, 24 Jul 2012 09:25:11 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
Quoted 2 lines · On Fri, 13 Jul 2012 09:23:35 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

Quoted 9 lines
Quoted 5 lines

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

Please, split this into one command per-patch. Otherwise it's difficult to review.

Sure.

Quoted 26 lines

Have libvirt folks acked this approach btw? It looks fine to me, but we need their ack too.

More comments below.

Quoted 21 lines
---
 hmp-commands.hx  |   16 ++++++++++++
 hmp.c            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    2 ++
 migration.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.h      |    2 ++
 monitor.c        |    7 ++++++
 qapi-schema.json |   53 ++++++++++++++++++++++++++++++++++++++--
 qmp-commands.hx  |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 280 insertions(+), 7 deletions(-)
hmp-commands.hx +0 -0
index f5d9d91..9245bef 100644
@@ -861,6 +861,20 @@ Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
 
Quoted 6 lines

hmp-commands.hx Set maximum tolerated downtime (in seconds) for migration. · line 866

Quoted 4 lines
hmp-commands.hx +3 -0
     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "",

Please, fill in params.

ok

Quoted 36 lines
Quoted 36 lines
hmp-commands.hx +13 -0
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+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",
@@ -1419,6 +1433,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migration_capabilities
+show migration capabilities
 @item info balloon
 show balloon information
 @item info qtree
hmp.c +1 -0
index 4c6d4ae..b0440e6 100644
@@ -131,9 +131,19 @@ void hmp_info_mice(Monitor *mon)
 void hmp_info_migrate(Monitor *mon)
 {
     MigrationInfo *info;
+    MigrationCapabilityInfoList *cap;
 
     info = qmp_query_migrate(NULL);
 
Quoted 12 lines

hmp.c void hmp_info_mice(Monitor *mon) · line 145

Quoted 8 lines
hmp.c +8 -0
+    if (info->has_capabilities && info->capabilities) {
+        monitor_printf(mon, "capabilities: ");
+        for (cap = info->capabilities; cap; cap = cap->next) {
+            monitor_printf(mon, "%s: %s ",
+                           MigrationCapability_lookup[cap->value->capability],
+                           cap->value->state ? "on" : "off");
+        }
+        monitor_printf(mon, "\n");

Why is this is needed? Isn't info migration-capabilities good enough? Besides, info migrate should only contain information about current migration process...

Quoted 5 lines

The reason we introduced capabilities is that xbzrle needs for both source and destination QEMU to be able to handle it. Even if both side support xbzrle the user may decide not to use it. User that wants to use xbzrle needs to check that both sides have support for it (using info capabilities) , than enable it in both sides (using migrate-set-parameter/s commands). This is a parameter for the current migration. So the user needs to know if xbzrle was enabled or disabled for the current migration, this code displays it.

But this is being returned even when there is no migration taking place. I'm answering this here in the 'info migrate' hunk, but my main concern is query-migrate.

query-migrate shouldn't return this info in MIG_STATE_SETUP, and for MIG_STATE_COMPLETED it should only be returned if there was a migration.

Quoted 177 lines

some day when there will be better migration protocol, feature negotiations can be part of it ...

Quoted 153 lines
Quoted 140 lines
hmp.c +55 -0
+    }
     if (info->has_status) {
         monitor_printf(mon, "Migration status: %s\n", info->status);
     }
@@ -161,6 +171,25 @@ void hmp_info_migrate(Monitor *mon)
     qapi_free_MigrationInfo(info);
 }
 
+void hmp_info_migration_capabilities(Monitor *mon)
+{
+    MigrationCapabilityInfoList *caps_list, *cap;
+
+    caps_list = qmp_query_migration_capabilities(NULL);
+    if (!caps_list) {
+        monitor_printf(mon, "No migration capabilities found\n");
+        return;
+    }
+
+    for (cap = caps_list; cap; cap = cap->next) {
+        monitor_printf(mon, "%s: %s ",
+                       MigrationCapability_lookup[cap->value->capability],
+                       cap->value->state ? "on" : "off");
+    }
+
+    qapi_free_MigrationCapabilityInfoList(caps_list);
+}
+
 void hmp_info_cpus(Monitor *mon)
 {
     CpuInfoList *cpu_list, *cpu;
@@ -735,6 +764,41 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_speed(value, NULL);
 }
 
+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
+{
+    const char *cap = qdict_get_str(qdict, "capability");
+    bool state = qdict_get_bool(qdict, "state");
+    Error *err = NULL;
+    MigrationCapabilityInfoList *params = NULL;
+    int i;
+
+    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
+            if (!params) {
+                params = g_malloc0(sizeof(*params));
+            }
+            params->value = g_malloc0(sizeof(*params->value));
+            params->value->capability = i;
+            params->value->state = state;
+            params->next = NULL;
+            qmp_migrate_set_parameters(params, &err);
+            break;
+        }
+    }
+
+    if (i == MIGRATION_CAPABILITY_MAX) {
+        error_set(&err, QERR_INVALID_PARAMETER, cap);
+    }
+
+    qapi_free_MigrationCapabilityInfoList(params);
+
+    if (err) {
+        monitor_printf(mon, "migrate_set_parameter: %s\n",
+                       error_get_pretty(err));
+        error_free(err);
+    }
+}
+
 void hmp_set_password(Monitor *mon, const QDict *qdict)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
hmp.h +2 -0
index 79d138d..09ba198 100644
@@ -25,6 +25,7 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_info_mice(Monitor *mon);
 void hmp_info_migrate(Monitor *mon);
+void hmp_info_migration_capabilities(Monitor *mon);
 void hmp_info_cpus(Monitor *mon);
 void hmp_info_block(Monitor *mon);
 void hmp_info_blockstats(Monitor *mon);
@@ -51,6 +52,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(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);
migration.c +26 -1
index 8db1b43..fd004d7 100644
@@ -117,12 +117,36 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 {
     MigrationInfo *info = g_malloc0(sizeof(*info));
     MigrationState *s = migrate_get_current();
+    int i;
 
     switch (s->state) {
     case MIG_STATE_SETUP:
-        /* no migration has happened ever */
+        /* no migration has ever happened; show enabled capabilities */
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
         break;
     case MIG_STATE_ACTIVE:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
+
         info->has_status = true;
         info->status = g_strdup("active");
 
@@ -143,6 +167,18 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         }
         break;
     case MIG_STATE_COMPLETED:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 180

Quoted 10 lines
migration.c +10 -0
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }

Code triplication :)

Quoted 4 lines

Why is this is needed? Isn't query-migration-capabilities good enough? Besides, query-migrate should only contain information about current migration process...

see above

Quoted 18 lines
Quoted 5 lines
migration.c +1 -0
+
         info->has_status = true;
         info->status = g_strdup("completed");
 

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 211

Quoted 10 lines
migration.c +7 -0
@@ -166,6 +202,33 @@ MigrationInfo *qmp_query_migrate(Error **errp)
     return info;
 }
 
+MigrationCapabilityInfoList *qmp_query_migration_capabilities(Error **errp)
+{
+    MigrationCapabilityInfoList *caps_list = g_malloc0(sizeof(*caps_list));
+
+    caps_list->value = g_malloc(sizeof(*caps_list->value));
+    caps_list->value->capability = MIGRATION_CAPABILITY_XBZRLE;
+    caps_list->next = NULL;

Shouldn't this get the capabilities array from migrate_get_current()?

Quoted 6 lines
Quoted 2 lines

I mean, this makes query-migration-capabilities always return true for xbzrle, even if we set it to off.

Those are the general capabilities , if I want to use xbzrle ,does this QEMU support it ?
this is required because we need both the destination and the source to be able to handle it.
If one QEMU doesn't (older version of qemu, maybe it will be disbaled for certain architectures) we can't use the feature. This is for management and the user to check what migration capabilities this QEMU supports.

My point was that query-migration-capabilities will always return state=true for all existing capabilities. Don't we want users/mngt app to know which states have been turned off?

Quoted 292 lines
Quoted 63 lines
Quoted 63 lines
migration.c +26 -1
+
+    return caps_list;
+}
+
+void qmp_migrate_set_parameters(MigrationCapabilityInfoList *params,
+                                Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+    MigrationCapabilityInfoList *cap;
+
+    if (s->state == MIG_STATE_ACTIVE) {
+        error_set(errp, QERR_MIGRATION_ACTIVE);
+        return;
+    }
+
+    for (cap = params; cap; cap = cap->next) {
+        s->enabled_capabilities[cap->value->capability] = cap->value->state;
+    }
+}
+
 /* shared migration helpers */
 
 static int migrate_fd_cleanup(MigrationState *s)
@@ -375,12 +438,17 @@ static MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+
+    memcpy(enabled_capabilities, s->enabled_capabilities,
+           sizeof(enabled_capabilities));
 
     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
     s->params = *params;
+    memcpy(s->enabled_capabilities, enabled_capabilities,
+           sizeof(enabled_capabilities));
 
-    s->bandwidth_limit = bandwidth_limit;
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);
 
migration.h +2 -0
index 57572a6..713aae0 100644
@@ -19,6 +19,7 @@
 #include "notify.h"
 #include "error.h"
 #include "vmstate.h"
+#include "qapi-types.h"
 
 struct MigrationParams {
     bool blk;
@@ -39,6 +40,7 @@ struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };
 
Quoted 12 lines

monitor.c static mon_cmd_t info_cmds[] = { · line 2690

Quoted 10 lines
migration.h +0 -0
 void process_incoming_migration(QEMUFile *f);
monitor.c +1 -0
index f6107ba..e2be6cd 100644
@@ -2687,6 +2687,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_migrate,
     },
     {
+        .name       = "migration_capabilities",

migration-capabilities is better.

ok

Quoted 15 lines
Quoted 15 lines
monitor.c +6 -0
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration capabilities",
+        .mhandler.info = hmp_info_migration_capabilities,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
qapi-schema.json +0 -0
index 1ab5dbd..a8408fd 100644
@@ -288,11 +288,15 @@
Quoted 8 lines

qapi-schema.json line 292

Quoted 6 lines
qapi-schema.json +2 -1
 #        status, only returned if status is 'active' and it is a block
 #        migration
 #
-# Since: 0.14.0
+# @capabilities: #optional a list describing all the migration capabilities
+#                state

I don't think this is needed, as I've said above.

see above

Quoted 15 lines
Quoted 15 lines
qapi-schema.json +4 -1
+#
+# Since: 0.14.0, 'capabilities' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
-           '*disk': 'MigrationStats'} }
+           '*disk': 'MigrationStats',
+           '*capabilities': ['MigrationCapabilityInfo']} }
 
 ##
 # @query-migrate
@@ -306,6 +310,51 @@
 { 'command': 'query-migrate', 'returns': 'MigrationInfo' }
 
Quoted 8 lines

qapi-schema.json line 317

Quoted 6 lines
qapi-schema.json +5 -0
 ##
+# @MigrationCapability
+#
+# Migration capabilities enumeration
+#
+# @xbzrle: current migration supports xbzrle

You should explain what xbzrle is.

ok

Quoted 12 lines

qapi-schema.json line 325

Quoted 9 lines
qapi-schema.json +8 -0
+#
+# Since: 1.2
+##
+{ 'enum': 'MigrationCapability',
+  'data': ['xbzrle'] }
+
+##
+# @MigrationCapabilityInfo

MigrationCapabilityStatus?

Quoted 6 lines

qapi-schema.json line 329

Quoted 4 lines
qapi-schema.json +4 -0
+#
+# Migration capability information
+#
+# @capability: capability enum

Please, document state too.

ok

Orit

Quoted 145 lines
Quoted 144 lines
qapi-schema.json +28 -0
+#
+# Since: 1.2
+##
+{ 'type': 'MigrationCapabilityInfo',
+  'data': { 'capability' : 'MigrationCapability', 'state' : 'bool' } }
+
+##
+# @query-migration-capabilities
+#
+# Returns information about current migration process capabilties.
+#
+# Returns: @MigrationCapabilityInfo list
+#
+# Since: 1.2
+##
+{ 'command': 'query-migration-capabilities', 'returns': ['MigrationCapabilityInfo'] }
+
+##
+# @migrate_set_parameters
+#
+# Enable/Disable the following migration capabilities (like xbzrle)
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-parameters',
+  'data': { 'capabilities': ['MigrationCapabilityInfo'] } }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +68 -3
index 2e1a38e..3ee6e00 100644
@@ -2075,18 +2075,31 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
-
+- "capabilities": migration capabilities state
+         - "xbzrle" : XBZRLE state (json-bool)
 Examples:
 
 1. Before the first migration
 
 -> { "execute": "query-migrate" }
-<- { "return": {} }
+<- { "return": {
+        "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
+     }
+   }
 
 2. Migration is done and has succeeded
 
 -> { "execute": "query-migrate" }
-<- { "return": { "status": "completed" } }
+<- { "return": {
+        "status": "completed",
+        "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
+        "ram":{
+          "transferred":123,
+          "remaining":123,
+          "total":246
+        }
+     }
+   }
 
 3. Migration is done and has failed
 
@@ -2099,6 +2112,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "transferred":123,
             "remaining":123,
@@ -2113,6 +2127,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "total":1057024,
             "remaining":1053304,
@@ -2135,6 +2150,56 @@ EQMP
     },
 
 SQMP
+query-migration-capabilities
+-------
+
+Query migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "query-migration-capabilities"}
+<- { "return": [ { "capability": "xbzrle", "state": true },
+                 { "capability": "foobar", "state": false } ] }
+
+EQMP
+
+    {
+        .name       = "query-migration-capabilities",
+        .args_type  = "",
+	.mhandler.cmd_new = qmp_marshal_input_query_migration_capabilities,
+    },
+
+SQMP
+migrate_set_parameters
+-------
+
+Enable/Disable migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "migrate_set_parameters" , "arguments":
+     { "parameters": [ { "capability": "xbzrle", "state": true } ] } }
+
+EQMP
+
+    {
+        .name       = "migrate_set_parameters",
+        .args_type  = "parameters:O",
+	.params     = "capability:s,state:b",
+	.mhandler.cmd_new = qmp_marshal_input_migrate_set_parameters,
+    },
+
+
+
+SQMP
 query-balloon
 -------------
 
#18 lore raw

Re: [Qemu-devel] [PATCH 13/22] Add migration capabilities

Quoted 106 lines · Luiz Capitulino
Quoted 97 lines · On Tue, 24 Jul 2012 09:25:11 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
Quoted 2 lines · On Fri, 13 Jul 2012 09:23:35 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

Quoted 9 lines
Quoted 5 lines

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

Please, split this into one command per-patch. Otherwise it's difficult to review.

Sure.

Quoted 26 lines

Have libvirt folks acked this approach btw? It looks fine to me, but we need their ack too.

More comments below.

Quoted 21 lines
---
 hmp-commands.hx  |   16 ++++++++++++
 hmp.c            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    2 ++
 migration.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.h      |    2 ++
 monitor.c        |    7 ++++++
 qapi-schema.json |   53 ++++++++++++++++++++++++++++++++++++++--
 qmp-commands.hx  |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 280 insertions(+), 7 deletions(-)
hmp-commands.hx +0 -0
index f5d9d91..9245bef 100644
@@ -861,6 +861,20 @@ Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
 
Quoted 6 lines

hmp-commands.hx Set maximum tolerated downtime (in seconds) for migration. · line 866

Quoted 4 lines
hmp-commands.hx +3 -0
     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "",

Please, fill in params.

ok

Quoted 36 lines
Quoted 36 lines
hmp-commands.hx +13 -0
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+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",
@@ -1419,6 +1433,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migration_capabilities
+show migration capabilities
 @item info balloon
 show balloon information
 @item info qtree
hmp.c +1 -0
index 4c6d4ae..b0440e6 100644
@@ -131,9 +131,19 @@ void hmp_info_mice(Monitor *mon)
 void hmp_info_migrate(Monitor *mon)
 {
     MigrationInfo *info;
+    MigrationCapabilityInfoList *cap;
 
     info = qmp_query_migrate(NULL);
 
Quoted 12 lines

hmp.c void hmp_info_mice(Monitor *mon) · line 145

Quoted 8 lines
hmp.c +8 -0
+    if (info->has_capabilities && info->capabilities) {
+        monitor_printf(mon, "capabilities: ");
+        for (cap = info->capabilities; cap; cap = cap->next) {
+            monitor_printf(mon, "%s: %s ",
+                           MigrationCapability_lookup[cap->value->capability],
+                           cap->value->state ? "on" : "off");
+        }
+        monitor_printf(mon, "\n");

Why is this is needed? Isn't info migration-capabilities good enough? Besides, info migrate should only contain information about current migration process...

Quoted 5 lines

The reason we introduced capabilities is that xbzrle needs for both source and destination QEMU to be able to handle it. Even if both side support xbzrle the user may decide not to use it. User that wants to use xbzrle needs to check that both sides have support for it (using info capabilities) , than enable it in both sides (using migrate-set-parameter/s commands). This is a parameter for the current migration. So the user needs to know if xbzrle was enabled or disabled for the current migration, this code displays it.

Quoted 3 lines

But this is being returned even when there is no migration taking place. I'm answering this here in the 'info migrate' hunk, but my main concern is query-migrate.

I think migration configuration is part of migration information and should be available to the user in 'info migration'. Especially before he starts running it to see if he need to change the configuration. Also it is very helpful for the user during the migration and also after it's completes. There is no way today to query the downtime and migration speed at all . you can always set them again
but there is no way to know how it is configured.
I was actually thinking to add them to info migration (also for SETUP).

Quoted 3 lines

query-migrate shouldn't return this info in MIG_STATE_SETUP, and for MIG_STATE_COMPLETED it should only be returned if there was a migration.

I think is case of MIG_SETUP we should return the configuration and params for the next migration. MIG_STATE_COMPLETED happens only if there was a successful migration other wise there will be another state.

Quoted 180 lines
Quoted 180 lines

some day when there will be better migration protocol, feature negotiations can be part of it ...

Quoted 153 lines
Quoted 140 lines
hmp.c +55 -0
+    }
     if (info->has_status) {
         monitor_printf(mon, "Migration status: %s\n", info->status);
     }
@@ -161,6 +171,25 @@ void hmp_info_migrate(Monitor *mon)
     qapi_free_MigrationInfo(info);
 }
 
+void hmp_info_migration_capabilities(Monitor *mon)
+{
+    MigrationCapabilityInfoList *caps_list, *cap;
+
+    caps_list = qmp_query_migration_capabilities(NULL);
+    if (!caps_list) {
+        monitor_printf(mon, "No migration capabilities found\n");
+        return;
+    }
+
+    for (cap = caps_list; cap; cap = cap->next) {
+        monitor_printf(mon, "%s: %s ",
+                       MigrationCapability_lookup[cap->value->capability],
+                       cap->value->state ? "on" : "off");
+    }
+
+    qapi_free_MigrationCapabilityInfoList(caps_list);
+}
+
 void hmp_info_cpus(Monitor *mon)
 {
     CpuInfoList *cpu_list, *cpu;
@@ -735,6 +764,41 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_speed(value, NULL);
 }
 
+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
+{
+    const char *cap = qdict_get_str(qdict, "capability");
+    bool state = qdict_get_bool(qdict, "state");
+    Error *err = NULL;
+    MigrationCapabilityInfoList *params = NULL;
+    int i;
+
+    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
+            if (!params) {
+                params = g_malloc0(sizeof(*params));
+            }
+            params->value = g_malloc0(sizeof(*params->value));
+            params->value->capability = i;
+            params->value->state = state;
+            params->next = NULL;
+            qmp_migrate_set_parameters(params, &err);
+            break;
+        }
+    }
+
+    if (i == MIGRATION_CAPABILITY_MAX) {
+        error_set(&err, QERR_INVALID_PARAMETER, cap);
+    }
+
+    qapi_free_MigrationCapabilityInfoList(params);
+
+    if (err) {
+        monitor_printf(mon, "migrate_set_parameter: %s\n",
+                       error_get_pretty(err));
+        error_free(err);
+    }
+}
+
 void hmp_set_password(Monitor *mon, const QDict *qdict)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
hmp.h +2 -0
index 79d138d..09ba198 100644
@@ -25,6 +25,7 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_info_mice(Monitor *mon);
 void hmp_info_migrate(Monitor *mon);
+void hmp_info_migration_capabilities(Monitor *mon);
 void hmp_info_cpus(Monitor *mon);
 void hmp_info_block(Monitor *mon);
 void hmp_info_blockstats(Monitor *mon);
@@ -51,6 +52,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(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);
migration.c +26 -1
index 8db1b43..fd004d7 100644
@@ -117,12 +117,36 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 {
     MigrationInfo *info = g_malloc0(sizeof(*info));
     MigrationState *s = migrate_get_current();
+    int i;
 
     switch (s->state) {
     case MIG_STATE_SETUP:
-        /* no migration has happened ever */
+        /* no migration has ever happened; show enabled capabilities */
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
         break;
     case MIG_STATE_ACTIVE:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
+
         info->has_status = true;
         info->status = g_strdup("active");
 
@@ -143,6 +167,18 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         }
         break;
     case MIG_STATE_COMPLETED:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 180

Quoted 10 lines
migration.c +10 -0
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }

Code triplication :)

Quoted 4 lines

Why is this is needed? Isn't query-migration-capabilities good enough? Besides, query-migrate should only contain information about current migration process...

see above

Quoted 20 lines
Quoted 5 lines
migration.c +1 -0
+
         info->has_status = true;
         info->status = g_strdup("completed");
 

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 211

Quoted 10 lines
migration.c +7 -0
@@ -166,6 +202,33 @@ MigrationInfo *qmp_query_migrate(Error **errp)
     return info;
 }
 
+MigrationCapabilityInfoList *qmp_query_migration_capabilities(Error **errp)
+{
+    MigrationCapabilityInfoList *caps_list = g_malloc0(sizeof(*caps_list));
+
+    caps_list->value = g_malloc(sizeof(*caps_list->value));
+    caps_list->value->capability = MIGRATION_CAPABILITY_XBZRLE;
+    caps_list->next = NULL;

Shouldn't this get the capabilities array from migrate_get_current()?

I mean, this makes query-migration-capabilities always return true for xbzrle, even if we set it to off.

Quoted 8 lines
Quoted 4 lines

Those are the general capabilities , if I want to use xbzrle ,does this QEMU support it ?
this is required because we need both the destination and the source to be able to handle it.
If one QEMU doesn't (older version of qemu, maybe it will be disbaled for certain architectures) we can't use the feature. This is for management and the user to check what migration capabilities this QEMU supports.

My point was that query-migration-capabilities will always return state=true for all existing capabilities. Don't we want users/mngt app to know which states have been turned off?

You need to separate the ability to use a capability and actually using it for migration. Also I don't want the user to be able to set some capability on, it depends on the code not user configuration. And for xbzrle we always return true for some version on QEMU , let say we decide we want to remove the code that implement it for some reason in some future version than it will return false. There is a reason the command that enables a capability for a migration was called 'migrate-set-parameter' and not set-capability to distinguish between them one is per QEMU code base and one is per migration.

Regards,
Orit

Quoted 294 lines
Quoted 293 lines
Quoted 64 lines
Quoted 64 lines
migration.c +26 -1
+
+    return caps_list;
+}
+
+void qmp_migrate_set_parameters(MigrationCapabilityInfoList *params,
+                                Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+    MigrationCapabilityInfoList *cap;
+
+    if (s->state == MIG_STATE_ACTIVE) {
+        error_set(errp, QERR_MIGRATION_ACTIVE);
+        return;
+    }
+
+    for (cap = params; cap; cap = cap->next) {
+        s->enabled_capabilities[cap->value->capability] = cap->value->state;
+    }
+}
+
 /* shared migration helpers */
 
 static int migrate_fd_cleanup(MigrationState *s)
@@ -375,12 +438,17 @@ static MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+
+    memcpy(enabled_capabilities, s->enabled_capabilities,
+           sizeof(enabled_capabilities));
 
     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
     s->params = *params;
+    memcpy(s->enabled_capabilities, enabled_capabilities,
+           sizeof(enabled_capabilities));
 
-    s->bandwidth_limit = bandwidth_limit;
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);
 
migration.h +2 -0
index 57572a6..713aae0 100644
@@ -19,6 +19,7 @@
 #include "notify.h"
 #include "error.h"
 #include "vmstate.h"
+#include "qapi-types.h"
 
 struct MigrationParams {
     bool blk;
@@ -39,6 +40,7 @@ struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };
 
Quoted 12 lines

monitor.c static mon_cmd_t info_cmds[] = { · line 2690

Quoted 10 lines
migration.h +0 -0
 void process_incoming_migration(QEMUFile *f);
monitor.c +1 -0
index f6107ba..e2be6cd 100644
@@ -2687,6 +2687,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_migrate,
     },
     {
+        .name       = "migration_capabilities",

migration-capabilities is better.

ok

Quoted 15 lines
Quoted 15 lines
monitor.c +6 -0
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration capabilities",
+        .mhandler.info = hmp_info_migration_capabilities,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
qapi-schema.json +0 -0
index 1ab5dbd..a8408fd 100644
@@ -288,11 +288,15 @@
Quoted 8 lines

qapi-schema.json line 292

Quoted 6 lines
qapi-schema.json +2 -1
 #        status, only returned if status is 'active' and it is a block
 #        migration
 #
-# Since: 0.14.0
+# @capabilities: #optional a list describing all the migration capabilities
+#                state

I don't think this is needed, as I've said above.

see above

Quoted 15 lines
Quoted 15 lines
qapi-schema.json +4 -1
+#
+# Since: 0.14.0, 'capabilities' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
-           '*disk': 'MigrationStats'} }
+           '*disk': 'MigrationStats',
+           '*capabilities': ['MigrationCapabilityInfo']} }
 
 ##
 # @query-migrate
@@ -306,6 +310,51 @@
 { 'command': 'query-migrate', 'returns': 'MigrationInfo' }
 
Quoted 8 lines

qapi-schema.json line 317

Quoted 6 lines
qapi-schema.json +5 -0
 ##
+# @MigrationCapability
+#
+# Migration capabilities enumeration
+#
+# @xbzrle: current migration supports xbzrle

You should explain what xbzrle is.

ok

Quoted 12 lines

qapi-schema.json line 325

Quoted 9 lines
qapi-schema.json +8 -0
+#
+# Since: 1.2
+##
+{ 'enum': 'MigrationCapability',
+  'data': ['xbzrle'] }
+
+##
+# @MigrationCapabilityInfo

MigrationCapabilityStatus?

Quoted 6 lines

qapi-schema.json line 329

Quoted 4 lines
qapi-schema.json +4 -0
+#
+# Migration capability information
+#
+# @capability: capability enum

Please, document state too.

ok

Orit

Quoted 145 lines
Quoted 144 lines
qapi-schema.json +28 -0
+#
+# Since: 1.2
+##
+{ 'type': 'MigrationCapabilityInfo',
+  'data': { 'capability' : 'MigrationCapability', 'state' : 'bool' } }
+
+##
+# @query-migration-capabilities
+#
+# Returns information about current migration process capabilties.
+#
+# Returns: @MigrationCapabilityInfo list
+#
+# Since: 1.2
+##
+{ 'command': 'query-migration-capabilities', 'returns': ['MigrationCapabilityInfo'] }
+
+##
+# @migrate_set_parameters
+#
+# Enable/Disable the following migration capabilities (like xbzrle)
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-parameters',
+  'data': { 'capabilities': ['MigrationCapabilityInfo'] } }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +68 -3
index 2e1a38e..3ee6e00 100644
@@ -2075,18 +2075,31 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
-
+- "capabilities": migration capabilities state
+         - "xbzrle" : XBZRLE state (json-bool)
 Examples:
 
 1. Before the first migration
 
 -> { "execute": "query-migrate" }
-<- { "return": {} }
+<- { "return": {
+        "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
+     }
+   }
 
 2. Migration is done and has succeeded
 
 -> { "execute": "query-migrate" }
-<- { "return": { "status": "completed" } }
+<- { "return": {
+        "status": "completed",
+        "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
+        "ram":{
+          "transferred":123,
+          "remaining":123,
+          "total":246
+        }
+     }
+   }
 
 3. Migration is done and has failed
 
@@ -2099,6 +2112,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "transferred":123,
             "remaining":123,
@@ -2113,6 +2127,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "total":1057024,
             "remaining":1053304,
@@ -2135,6 +2150,56 @@ EQMP
     },
 
 SQMP
+query-migration-capabilities
+-------
+
+Query migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "query-migration-capabilities"}
+<- { "return": [ { "capability": "xbzrle", "state": true },
+                 { "capability": "foobar", "state": false } ] }
+
+EQMP
+
+    {
+        .name       = "query-migration-capabilities",
+        .args_type  = "",
+	.mhandler.cmd_new = qmp_marshal_input_query_migration_capabilities,
+    },
+
+SQMP
+migrate_set_parameters
+-------
+
+Enable/Disable migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "migrate_set_parameters" , "arguments":
+     { "parameters": [ { "capability": "xbzrle", "state": true } ] } }
+
+EQMP
+
+    {
+        .name       = "migrate_set_parameters",
+        .args_type  = "parameters:O",
+	.params     = "capability:s,state:b",
+	.mhandler.cmd_new = qmp_marshal_input_migrate_set_parameters,
+    },
+
+
+
+SQMP
 query-balloon
 -------------
 
#19 lore raw

Re: [Qemu-devel] [PATCH 13/22] Add migration capabilities

Quoted 107 lines · On Tue, 24 Jul 2012 20:06:06 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 106 lines · Luiz Capitulino
Quoted 102 lines · On Tue, 24 Jul 2012 09:25:11 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
Quoted 2 lines · On Fri, 13 Jul 2012 09:23:35 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

Quoted 9 lines
Quoted 5 lines

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

Please, split this into one command per-patch. Otherwise it's difficult to review.

Sure.

Quoted 26 lines

Have libvirt folks acked this approach btw? It looks fine to me, but we need their ack too.

More comments below.

Quoted 21 lines
---
 hmp-commands.hx  |   16 ++++++++++++
 hmp.c            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    2 ++
 migration.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.h      |    2 ++
 monitor.c        |    7 ++++++
 qapi-schema.json |   53 ++++++++++++++++++++++++++++++++++++++--
 qmp-commands.hx  |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 280 insertions(+), 7 deletions(-)
hmp-commands.hx +0 -0
index f5d9d91..9245bef 100644
@@ -861,6 +861,20 @@ Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
 
Quoted 6 lines

hmp-commands.hx Set maximum tolerated downtime (in seconds) for migration. · line 866

Quoted 4 lines
hmp-commands.hx +3 -0
     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "",

Please, fill in params.

ok

Quoted 36 lines
Quoted 36 lines
hmp-commands.hx +13 -0
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+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",
@@ -1419,6 +1433,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migration_capabilities
+show migration capabilities
 @item info balloon
 show balloon information
 @item info qtree
hmp.c +1 -0
index 4c6d4ae..b0440e6 100644
@@ -131,9 +131,19 @@ void hmp_info_mice(Monitor *mon)
 void hmp_info_migrate(Monitor *mon)
 {
     MigrationInfo *info;
+    MigrationCapabilityInfoList *cap;
 
     info = qmp_query_migrate(NULL);
 
Quoted 12 lines

hmp.c void hmp_info_mice(Monitor *mon) · line 145

Quoted 8 lines
hmp.c +8 -0
+    if (info->has_capabilities && info->capabilities) {
+        monitor_printf(mon, "capabilities: ");
+        for (cap = info->capabilities; cap; cap = cap->next) {
+            monitor_printf(mon, "%s: %s ",
+                           MigrationCapability_lookup[cap->value->capability],
+                           cap->value->state ? "on" : "off");
+        }
+        monitor_printf(mon, "\n");

Why is this is needed? Isn't info migration-capabilities good enough? Besides, info migrate should only contain information about current migration process...

The reason we introduced capabilities is that xbzrle needs for both source and destination QEMU to be able to handle it. Even if both side support xbzrle the user may decide not to use it. User that wants to use xbzrle needs to check that both sides have support for it (using info capabilities) , than enable it in both sides (using migrate-set-parameter/s commands). This is a parameter for the current migration. So the user needs to know if xbzrle was enabled or disabled for the current migration, this code displays it.

Quoted 4 lines
Quoted 3 lines

But this is being returned even when there is no migration taking place. I'm answering this here in the 'info migrate' hunk, but my main concern is query-migrate.

I think migration configuration is part of migration information and should be available to the user in 'info migration'. Especially before he starts running it to see if he need to change the configuration. Also it is very helpful for the user during the migration and also after it's completes.

I don't mind having this in 'info migrate' because we can change it later case we regret, so it's fine with me having that info there.

But query-migrate is different, once we add anything there it's there forever, so we have to be careful.

Quoted 2 lines

There is no way today to query the downtime and migration speed at all . you can always set them again but there is no way to know how it is configured.

Good point, but I think it's better to concentrate on the needs of xbzrle for now.

Quoted 1 line

I was actually thinking to add them to info migration (also for SETUP).

But we're in SETUP state only once, what happens if the settings are changed after a migration completed? How is mngt going to be able to query it?

My advice to not delay the inclusion of this series is to drop the information from SETUP state and rely on query-migration-capabilities in 'info migrate'. We can extend later if needed (by means of new commands or adding info to query-migrate).

Quoted 190 lines
Quoted 3 lines

query-migrate shouldn't return this info in MIG_STATE_SETUP, and for MIG_STATE_COMPLETED it should only be returned if there was a migration.

I think is case of MIG_SETUP we should return the configuration and params for the next migration. MIG_STATE_COMPLETED happens only if there was a successful migration other wise there will be another state.

Quoted 185 lines
Quoted 184 lines

some day when there will be better migration protocol, feature negotiations can be part of it ...

Quoted 153 lines
Quoted 140 lines
hmp.c +55 -0
+    }
     if (info->has_status) {
         monitor_printf(mon, "Migration status: %s\n", info->status);
     }
@@ -161,6 +171,25 @@ void hmp_info_migrate(Monitor *mon)
     qapi_free_MigrationInfo(info);
 }
 
+void hmp_info_migration_capabilities(Monitor *mon)
+{
+    MigrationCapabilityInfoList *caps_list, *cap;
+
+    caps_list = qmp_query_migration_capabilities(NULL);
+    if (!caps_list) {
+        monitor_printf(mon, "No migration capabilities found\n");
+        return;
+    }
+
+    for (cap = caps_list; cap; cap = cap->next) {
+        monitor_printf(mon, "%s: %s ",
+                       MigrationCapability_lookup[cap->value->capability],
+                       cap->value->state ? "on" : "off");
+    }
+
+    qapi_free_MigrationCapabilityInfoList(caps_list);
+}
+
 void hmp_info_cpus(Monitor *mon)
 {
     CpuInfoList *cpu_list, *cpu;
@@ -735,6 +764,41 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_speed(value, NULL);
 }
 
+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
+{
+    const char *cap = qdict_get_str(qdict, "capability");
+    bool state = qdict_get_bool(qdict, "state");
+    Error *err = NULL;
+    MigrationCapabilityInfoList *params = NULL;
+    int i;
+
+    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
+            if (!params) {
+                params = g_malloc0(sizeof(*params));
+            }
+            params->value = g_malloc0(sizeof(*params->value));
+            params->value->capability = i;
+            params->value->state = state;
+            params->next = NULL;
+            qmp_migrate_set_parameters(params, &err);
+            break;
+        }
+    }
+
+    if (i == MIGRATION_CAPABILITY_MAX) {
+        error_set(&err, QERR_INVALID_PARAMETER, cap);
+    }
+
+    qapi_free_MigrationCapabilityInfoList(params);
+
+    if (err) {
+        monitor_printf(mon, "migrate_set_parameter: %s\n",
+                       error_get_pretty(err));
+        error_free(err);
+    }
+}
+
 void hmp_set_password(Monitor *mon, const QDict *qdict)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
hmp.h +2 -0
index 79d138d..09ba198 100644
@@ -25,6 +25,7 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_info_mice(Monitor *mon);
 void hmp_info_migrate(Monitor *mon);
+void hmp_info_migration_capabilities(Monitor *mon);
 void hmp_info_cpus(Monitor *mon);
 void hmp_info_block(Monitor *mon);
 void hmp_info_blockstats(Monitor *mon);
@@ -51,6 +52,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(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);
migration.c +26 -1
index 8db1b43..fd004d7 100644
@@ -117,12 +117,36 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 {
     MigrationInfo *info = g_malloc0(sizeof(*info));
     MigrationState *s = migrate_get_current();
+    int i;
 
     switch (s->state) {
     case MIG_STATE_SETUP:
-        /* no migration has happened ever */
+        /* no migration has ever happened; show enabled capabilities */
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
         break;
     case MIG_STATE_ACTIVE:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
+
         info->has_status = true;
         info->status = g_strdup("active");
 
@@ -143,6 +167,18 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         }
         break;
     case MIG_STATE_COMPLETED:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 180

Quoted 10 lines
migration.c +10 -0
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }

Code triplication :)

Quoted 4 lines

Why is this is needed? Isn't query-migration-capabilities good enough? Besides, query-migrate should only contain information about current migration process...

see above

Quoted 18 lines
Quoted 5 lines
migration.c +1 -0
+
         info->has_status = true;
         info->status = g_strdup("completed");
 

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 211

Quoted 10 lines
migration.c +7 -0
@@ -166,6 +202,33 @@ MigrationInfo *qmp_query_migrate(Error **errp)
     return info;
 }
 
+MigrationCapabilityInfoList *qmp_query_migration_capabilities(Error **errp)
+{
+    MigrationCapabilityInfoList *caps_list = g_malloc0(sizeof(*caps_list));
+
+    caps_list->value = g_malloc(sizeof(*caps_list->value));
+    caps_list->value->capability = MIGRATION_CAPABILITY_XBZRLE;
+    caps_list->next = NULL;

Shouldn't this get the capabilities array from migrate_get_current()?

Quoted 2 lines

I mean, this makes query-migration-capabilities always return true for xbzrle, even if we set it to off.

Those are the general capabilities , if I want to use xbzrle ,does this QEMU support it ?
this is required because we need both the destination and the source to be able to handle it.
If one QEMU doesn't (older version of qemu, maybe it will be disbaled for certain architectures) we can't use the feature. This is for management and the user to check what migration capabilities this QEMU supports.

Quoted 4 lines
Quoted 3 lines

My point was that query-migration-capabilities will always return state=true for all existing capabilities. Don't we want users/mngt app to know which states have been turned off?

You need to separate the ability to use a capability and actually using it for migration. Also I don't want the user to be able to set some capability on, it depends on the code not user configuration.

Not sure I can follow, a user can set xbzrle capability to off, no?

Quoted 1 line

And for xbzrle we always return true for some version on QEMU , let say we decide we want to remove the code that implement it for some reason in some future version than it will return false.

That's fine (I mean, I'm not sure we will ever do it, but shouldn't be a problem if we do).

Quoted 300 lines

There is a reason the command that enables a capability for a migration was called 'migrate-set-parameter' and not set-capability to distinguish between them one is per QEMU code base and one is per migration.

Regards,
Orit

Quoted 294 lines
Quoted 293 lines
Quoted 64 lines
Quoted 64 lines
migration.c +26 -1
+
+    return caps_list;
+}
+
+void qmp_migrate_set_parameters(MigrationCapabilityInfoList *params,
+                                Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+    MigrationCapabilityInfoList *cap;
+
+    if (s->state == MIG_STATE_ACTIVE) {
+        error_set(errp, QERR_MIGRATION_ACTIVE);
+        return;
+    }
+
+    for (cap = params; cap; cap = cap->next) {
+        s->enabled_capabilities[cap->value->capability] = cap->value->state;
+    }
+}
+
 /* shared migration helpers */
 
 static int migrate_fd_cleanup(MigrationState *s)
@@ -375,12 +438,17 @@ static MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+
+    memcpy(enabled_capabilities, s->enabled_capabilities,
+           sizeof(enabled_capabilities));
 
     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
     s->params = *params;
+    memcpy(s->enabled_capabilities, enabled_capabilities,
+           sizeof(enabled_capabilities));
 
-    s->bandwidth_limit = bandwidth_limit;
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);
 
migration.h +2 -0
index 57572a6..713aae0 100644
@@ -19,6 +19,7 @@
 #include "notify.h"
 #include "error.h"
 #include "vmstate.h"
+#include "qapi-types.h"
 
 struct MigrationParams {
     bool blk;
@@ -39,6 +40,7 @@ struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };
 
Quoted 12 lines

monitor.c static mon_cmd_t info_cmds[] = { · line 2690

Quoted 10 lines
migration.h +0 -0
 void process_incoming_migration(QEMUFile *f);
monitor.c +1 -0
index f6107ba..e2be6cd 100644
@@ -2687,6 +2687,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_migrate,
     },
     {
+        .name       = "migration_capabilities",

migration-capabilities is better.

ok

Quoted 15 lines
Quoted 15 lines
monitor.c +6 -0
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration capabilities",
+        .mhandler.info = hmp_info_migration_capabilities,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
qapi-schema.json +0 -0
index 1ab5dbd..a8408fd 100644
@@ -288,11 +288,15 @@
Quoted 8 lines

qapi-schema.json line 292

Quoted 6 lines
qapi-schema.json +2 -1
 #        status, only returned if status is 'active' and it is a block
 #        migration
 #
-# Since: 0.14.0
+# @capabilities: #optional a list describing all the migration capabilities
+#                state

I don't think this is needed, as I've said above.

see above

Quoted 15 lines
Quoted 15 lines
qapi-schema.json +4 -1
+#
+# Since: 0.14.0, 'capabilities' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
-           '*disk': 'MigrationStats'} }
+           '*disk': 'MigrationStats',
+           '*capabilities': ['MigrationCapabilityInfo']} }
 
 ##
 # @query-migrate
@@ -306,6 +310,51 @@
 { 'command': 'query-migrate', 'returns': 'MigrationInfo' }
 
Quoted 8 lines

qapi-schema.json line 317

Quoted 6 lines
qapi-schema.json +5 -0
 ##
+# @MigrationCapability
+#
+# Migration capabilities enumeration
+#
+# @xbzrle: current migration supports xbzrle

You should explain what xbzrle is.

ok

Quoted 12 lines

qapi-schema.json line 325

Quoted 9 lines
qapi-schema.json +8 -0
+#
+# Since: 1.2
+##
+{ 'enum': 'MigrationCapability',
+  'data': ['xbzrle'] }
+
+##
+# @MigrationCapabilityInfo

MigrationCapabilityStatus?

Quoted 6 lines

qapi-schema.json line 329

Quoted 4 lines
qapi-schema.json +4 -0
+#
+# Migration capability information
+#
+# @capability: capability enum

Please, document state too.

ok

Orit

Quoted 145 lines
Quoted 144 lines
qapi-schema.json +28 -0
+#
+# Since: 1.2
+##
+{ 'type': 'MigrationCapabilityInfo',
+  'data': { 'capability' : 'MigrationCapability', 'state' : 'bool' } }
+
+##
+# @query-migration-capabilities
+#
+# Returns information about current migration process capabilties.
+#
+# Returns: @MigrationCapabilityInfo list
+#
+# Since: 1.2
+##
+{ 'command': 'query-migration-capabilities', 'returns': ['MigrationCapabilityInfo'] }
+
+##
+# @migrate_set_parameters
+#
+# Enable/Disable the following migration capabilities (like xbzrle)
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-parameters',
+  'data': { 'capabilities': ['MigrationCapabilityInfo'] } }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +68 -3
index 2e1a38e..3ee6e00 100644
@@ -2075,18 +2075,31 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
-
+- "capabilities": migration capabilities state
+         - "xbzrle" : XBZRLE state (json-bool)
 Examples:
 
 1. Before the first migration
 
 -> { "execute": "query-migrate" }
-<- { "return": {} }
+<- { "return": {
+        "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
+     }
+   }
 
 2. Migration is done and has succeeded
 
 -> { "execute": "query-migrate" }
-<- { "return": { "status": "completed" } }
+<- { "return": {
+        "status": "completed",
+        "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
+        "ram":{
+          "transferred":123,
+          "remaining":123,
+          "total":246
+        }
+     }
+   }
 
 3. Migration is done and has failed
 
@@ -2099,6 +2112,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "transferred":123,
             "remaining":123,
@@ -2113,6 +2127,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "total":1057024,
             "remaining":1053304,
@@ -2135,6 +2150,56 @@ EQMP
     },
 
 SQMP
+query-migration-capabilities
+-------
+
+Query migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "query-migration-capabilities"}
+<- { "return": [ { "capability": "xbzrle", "state": true },
+                 { "capability": "foobar", "state": false } ] }
+
+EQMP
+
+    {
+        .name       = "query-migration-capabilities",
+        .args_type  = "",
+	.mhandler.cmd_new = qmp_marshal_input_query_migration_capabilities,
+    },
+
+SQMP
+migrate_set_parameters
+-------
+
+Enable/Disable migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "migrate_set_parameters" , "arguments":
+     { "parameters": [ { "capability": "xbzrle", "state": true } ] } }
+
+EQMP
+
+    {
+        .name       = "migrate_set_parameters",
+        .args_type  = "parameters:O",
+	.params     = "capability:s,state:b",
+	.mhandler.cmd_new = qmp_marshal_input_migrate_set_parameters,
+    },
+
+
+
+SQMP
 query-balloon
 -------------
 
#20 lore raw

Re: [Qemu-devel] [PATCH 13/22] Add migration capabilities

Quoted 113 lines · Luiz Capitulino
Quoted 110 lines · On Tue, 24 Jul 2012 20:06:06 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 109 lines · Luiz Capitulino
Quoted 97 lines · On Tue, 24 Jul 2012 09:25:11 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
Quoted 2 lines · On Fri, 13 Jul 2012 09:23:35 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

Quoted 9 lines
Quoted 5 lines

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

Please, split this into one command per-patch. Otherwise it's difficult to review.

Sure.

Quoted 26 lines

Have libvirt folks acked this approach btw? It looks fine to me, but we need their ack too.

More comments below.

Quoted 21 lines
---
 hmp-commands.hx  |   16 ++++++++++++
 hmp.c            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    2 ++
 migration.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.h      |    2 ++
 monitor.c        |    7 ++++++
 qapi-schema.json |   53 ++++++++++++++++++++++++++++++++++++++--
 qmp-commands.hx  |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 280 insertions(+), 7 deletions(-)
hmp-commands.hx +0 -0
index f5d9d91..9245bef 100644
@@ -861,6 +861,20 @@ Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
 
Quoted 6 lines

hmp-commands.hx Set maximum tolerated downtime (in seconds) for migration. · line 866

Quoted 4 lines
hmp-commands.hx +3 -0
     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "",

Please, fill in params.

ok

Quoted 36 lines
Quoted 36 lines
hmp-commands.hx +13 -0
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+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",
@@ -1419,6 +1433,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migration_capabilities
+show migration capabilities
 @item info balloon
 show balloon information
 @item info qtree
hmp.c +1 -0
index 4c6d4ae..b0440e6 100644
@@ -131,9 +131,19 @@ void hmp_info_mice(Monitor *mon)
 void hmp_info_migrate(Monitor *mon)
 {
     MigrationInfo *info;
+    MigrationCapabilityInfoList *cap;
 
     info = qmp_query_migrate(NULL);
 
Quoted 12 lines

hmp.c void hmp_info_mice(Monitor *mon) · line 145

Quoted 8 lines
hmp.c +8 -0
+    if (info->has_capabilities && info->capabilities) {
+        monitor_printf(mon, "capabilities: ");
+        for (cap = info->capabilities; cap; cap = cap->next) {
+            monitor_printf(mon, "%s: %s ",
+                           MigrationCapability_lookup[cap->value->capability],
+                           cap->value->state ? "on" : "off");
+        }
+        monitor_printf(mon, "\n");

Why is this is needed? Isn't info migration-capabilities good enough? Besides, info migrate should only contain information about current migration process...

Quoted 5 lines

The reason we introduced capabilities is that xbzrle needs for both source and destination QEMU to be able to handle it. Even if both side support xbzrle the user may decide not to use it. User that wants to use xbzrle needs to check that both sides have support for it (using info capabilities) , than enable it in both sides (using migrate-set-parameter/s commands). This is a parameter for the current migration. So the user needs to know if xbzrle was enabled or disabled for the current migration, this code displays it.

But this is being returned even when there is no migration taking place. I'm answering this here in the 'info migrate' hunk, but my main concern is query-migrate.

Quoted 7 lines
Quoted 1 line

I think migration configuration is part of migration information and should be available to the user in 'info migration'. Especially before he starts running it to see if he need to change the configuration. Also it is very helpful for the user during the migration and also after it's completes.

I don't mind having this in 'info migrate' because we can change it later case we regret, so it's fine with me having that info there.

But query-migrate is different, once we add anything there it's there forever, so we have to be careful.

ok I will remove them from query-migrate.

Quoted 11 lines
Quoted 3 lines

There is no way today to query the downtime and migration speed at all . you can always set them again but there is no way to know how it is configured.

Good point, but I think it's better to concentrate on the needs of xbzrle for now.

Quoted 1 line

I was actually thinking to add them to info migration (also for SETUP).

But we're in SETUP state only once, what happens if the settings are changed after a migration completed? How is mngt going to be able to query it?

After migration completes you can't change those setting , you should get an error.

Quoted 5 lines

My advice to not delay the inclusion of this series is to drop the information from SETUP state and rely on query-migration-capabilities in 'info migrate'. We can extend later if needed (by means of new commands or adding info to query-migrate).

It needs to be another command, I can add query-migration-parameters.
You can look at this as 64bit support - you have 64bit support in the processor (this is what query-capabilities) but the OS can decide not to work in 64bit mode (do nothing) or using 64 bit (migrate-set-parameter).

Orit

Quoted 504 lines
Quoted 191 lines
Quoted 4 lines

query-migrate shouldn't return this info in MIG_STATE_SETUP, and for MIG_STATE_COMPLETED it should only be returned if there was a migration.

I think is case of MIG_SETUP we should return the configuration and params for the next migration. MIG_STATE_COMPLETED happens only if there was a successful migration other wise there will be another state.

Quoted 185 lines
Quoted 184 lines

some day when there will be better migration protocol, feature negotiations can be part of it ...

Quoted 153 lines
Quoted 140 lines
hmp.c +55 -0
+    }
     if (info->has_status) {
         monitor_printf(mon, "Migration status: %s\n", info->status);
     }
@@ -161,6 +171,25 @@ void hmp_info_migrate(Monitor *mon)
     qapi_free_MigrationInfo(info);
 }
 
+void hmp_info_migration_capabilities(Monitor *mon)
+{
+    MigrationCapabilityInfoList *caps_list, *cap;
+
+    caps_list = qmp_query_migration_capabilities(NULL);
+    if (!caps_list) {
+        monitor_printf(mon, "No migration capabilities found\n");
+        return;
+    }
+
+    for (cap = caps_list; cap; cap = cap->next) {
+        monitor_printf(mon, "%s: %s ",
+                       MigrationCapability_lookup[cap->value->capability],
+                       cap->value->state ? "on" : "off");
+    }
+
+    qapi_free_MigrationCapabilityInfoList(caps_list);
+}
+
 void hmp_info_cpus(Monitor *mon)
 {
     CpuInfoList *cpu_list, *cpu;
@@ -735,6 +764,41 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_speed(value, NULL);
 }
 
+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
+{
+    const char *cap = qdict_get_str(qdict, "capability");
+    bool state = qdict_get_bool(qdict, "state");
+    Error *err = NULL;
+    MigrationCapabilityInfoList *params = NULL;
+    int i;
+
+    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
+            if (!params) {
+                params = g_malloc0(sizeof(*params));
+            }
+            params->value = g_malloc0(sizeof(*params->value));
+            params->value->capability = i;
+            params->value->state = state;
+            params->next = NULL;
+            qmp_migrate_set_parameters(params, &err);
+            break;
+        }
+    }
+
+    if (i == MIGRATION_CAPABILITY_MAX) {
+        error_set(&err, QERR_INVALID_PARAMETER, cap);
+    }
+
+    qapi_free_MigrationCapabilityInfoList(params);
+
+    if (err) {
+        monitor_printf(mon, "migrate_set_parameter: %s\n",
+                       error_get_pretty(err));
+        error_free(err);
+    }
+}
+
 void hmp_set_password(Monitor *mon, const QDict *qdict)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
hmp.h +2 -0
index 79d138d..09ba198 100644
@@ -25,6 +25,7 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_info_mice(Monitor *mon);
 void hmp_info_migrate(Monitor *mon);
+void hmp_info_migration_capabilities(Monitor *mon);
 void hmp_info_cpus(Monitor *mon);
 void hmp_info_block(Monitor *mon);
 void hmp_info_blockstats(Monitor *mon);
@@ -51,6 +52,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(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);
migration.c +26 -1
index 8db1b43..fd004d7 100644
@@ -117,12 +117,36 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 {
     MigrationInfo *info = g_malloc0(sizeof(*info));
     MigrationState *s = migrate_get_current();
+    int i;
 
     switch (s->state) {
     case MIG_STATE_SETUP:
-        /* no migration has happened ever */
+        /* no migration has ever happened; show enabled capabilities */
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
         break;
     case MIG_STATE_ACTIVE:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
+
         info->has_status = true;
         info->status = g_strdup("active");
 
@@ -143,6 +167,18 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         }
         break;
     case MIG_STATE_COMPLETED:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 180

Quoted 10 lines
migration.c +10 -0
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }

Code triplication :)

Quoted 4 lines

Why is this is needed? Isn't query-migration-capabilities good enough? Besides, query-migrate should only contain information about current migration process...

see above

Quoted 18 lines
Quoted 5 lines
migration.c +1 -0
+
         info->has_status = true;
         info->status = g_strdup("completed");
 

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 211

Quoted 10 lines
migration.c +7 -0
@@ -166,6 +202,33 @@ MigrationInfo *qmp_query_migrate(Error **errp)
     return info;
 }
 
+MigrationCapabilityInfoList *qmp_query_migration_capabilities(Error **errp)
+{
+    MigrationCapabilityInfoList *caps_list = g_malloc0(sizeof(*caps_list));
+
+    caps_list->value = g_malloc(sizeof(*caps_list->value));
+    caps_list->value->capability = MIGRATION_CAPABILITY_XBZRLE;
+    caps_list->next = NULL;

Shouldn't this get the capabilities array from migrate_get_current()?

Quoted 2 lines

I mean, this makes query-migration-capabilities always return true for xbzrle, even if we set it to off.

Those are the general capabilities , if I want to use xbzrle ,does this QEMU support it ?
this is required because we need both the destination and the source to be able to handle it.
If one QEMU doesn't (older version of qemu, maybe it will be disbaled for certain architectures) we can't use the feature. This is for management and the user to check what migration capabilities this QEMU supports.

Quoted 4 lines
Quoted 3 lines

My point was that query-migration-capabilities will always return state=true for all existing capabilities. Don't we want users/mngt app to know which states have been turned off?

You need to separate the ability to use a capability and actually using it for migration. Also I don't want the user to be able to set some capability on, it depends on the code not user configuration.

Not sure I can follow, a user can set xbzrle capability to off, no?

Quoted 1 line

And for xbzrle we always return true for some version on QEMU , let say we decide we want to remove the code that implement it for some reason in some future version than it will return false.

That's fine (I mean, I'm not sure we will ever do it, but shouldn't be a problem if we do).

Quoted 300 lines

There is a reason the command that enables a capability for a migration was called 'migrate-set-parameter' and not set-capability to distinguish between them one is per QEMU code base and one is per migration.

Regards,
Orit

Quoted 294 lines
Quoted 293 lines
Quoted 64 lines
Quoted 64 lines
migration.c +26 -1
+
+    return caps_list;
+}
+
+void qmp_migrate_set_parameters(MigrationCapabilityInfoList *params,
+                                Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+    MigrationCapabilityInfoList *cap;
+
+    if (s->state == MIG_STATE_ACTIVE) {
+        error_set(errp, QERR_MIGRATION_ACTIVE);
+        return;
+    }
+
+    for (cap = params; cap; cap = cap->next) {
+        s->enabled_capabilities[cap->value->capability] = cap->value->state;
+    }
+}
+
 /* shared migration helpers */
 
 static int migrate_fd_cleanup(MigrationState *s)
@@ -375,12 +438,17 @@ static MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+
+    memcpy(enabled_capabilities, s->enabled_capabilities,
+           sizeof(enabled_capabilities));
 
     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
     s->params = *params;
+    memcpy(s->enabled_capabilities, enabled_capabilities,
+           sizeof(enabled_capabilities));
 
-    s->bandwidth_limit = bandwidth_limit;
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);
 
migration.h +2 -0
index 57572a6..713aae0 100644
@@ -19,6 +19,7 @@
 #include "notify.h"
 #include "error.h"
 #include "vmstate.h"
+#include "qapi-types.h"
 
 struct MigrationParams {
     bool blk;
@@ -39,6 +40,7 @@ struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };
 
Quoted 12 lines

monitor.c static mon_cmd_t info_cmds[] = { · line 2690

Quoted 10 lines
migration.h +0 -0
 void process_incoming_migration(QEMUFile *f);
monitor.c +1 -0
index f6107ba..e2be6cd 100644
@@ -2687,6 +2687,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_migrate,
     },
     {
+        .name       = "migration_capabilities",

migration-capabilities is better.

ok

Quoted 15 lines
Quoted 15 lines
monitor.c +6 -0
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration capabilities",
+        .mhandler.info = hmp_info_migration_capabilities,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
qapi-schema.json +0 -0
index 1ab5dbd..a8408fd 100644
@@ -288,11 +288,15 @@
Quoted 8 lines

qapi-schema.json line 292

Quoted 6 lines
qapi-schema.json +2 -1
 #        status, only returned if status is 'active' and it is a block
 #        migration
 #
-# Since: 0.14.0
+# @capabilities: #optional a list describing all the migration capabilities
+#                state

I don't think this is needed, as I've said above.

see above

Quoted 15 lines
Quoted 15 lines
qapi-schema.json +4 -1
+#
+# Since: 0.14.0, 'capabilities' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
-           '*disk': 'MigrationStats'} }
+           '*disk': 'MigrationStats',
+           '*capabilities': ['MigrationCapabilityInfo']} }
 
 ##
 # @query-migrate
@@ -306,6 +310,51 @@
 { 'command': 'query-migrate', 'returns': 'MigrationInfo' }
 
Quoted 8 lines

qapi-schema.json line 317

Quoted 6 lines
qapi-schema.json +5 -0
 ##
+# @MigrationCapability
+#
+# Migration capabilities enumeration
+#
+# @xbzrle: current migration supports xbzrle

You should explain what xbzrle is.

ok

Quoted 12 lines

qapi-schema.json line 325

Quoted 9 lines
qapi-schema.json +8 -0
+#
+# Since: 1.2
+##
+{ 'enum': 'MigrationCapability',
+  'data': ['xbzrle'] }
+
+##
+# @MigrationCapabilityInfo

MigrationCapabilityStatus?

Quoted 6 lines

qapi-schema.json line 329

Quoted 4 lines
qapi-schema.json +4 -0
+#
+# Migration capability information
+#
+# @capability: capability enum

Please, document state too.

ok

Orit

Quoted 145 lines
Quoted 144 lines
qapi-schema.json +28 -0
+#
+# Since: 1.2
+##
+{ 'type': 'MigrationCapabilityInfo',
+  'data': { 'capability' : 'MigrationCapability', 'state' : 'bool' } }
+
+##
+# @query-migration-capabilities
+#
+# Returns information about current migration process capabilties.
+#
+# Returns: @MigrationCapabilityInfo list
+#
+# Since: 1.2
+##
+{ 'command': 'query-migration-capabilities', 'returns': ['MigrationCapabilityInfo'] }
+
+##
+# @migrate_set_parameters
+#
+# Enable/Disable the following migration capabilities (like xbzrle)
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-parameters',
+  'data': { 'capabilities': ['MigrationCapabilityInfo'] } }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +68 -3
index 2e1a38e..3ee6e00 100644
@@ -2075,18 +2075,31 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
-
+- "capabilities": migration capabilities state
+         - "xbzrle" : XBZRLE state (json-bool)
 Examples:
 
 1. Before the first migration
 
 -> { "execute": "query-migrate" }
-<- { "return": {} }
+<- { "return": {
+        "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
+     }
+   }
 
 2. Migration is done and has succeeded
 
 -> { "execute": "query-migrate" }
-<- { "return": { "status": "completed" } }
+<- { "return": {
+        "status": "completed",
+        "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
+        "ram":{
+          "transferred":123,
+          "remaining":123,
+          "total":246
+        }
+     }
+   }
 
 3. Migration is done and has failed
 
@@ -2099,6 +2112,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "transferred":123,
             "remaining":123,
@@ -2113,6 +2127,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "total":1057024,
             "remaining":1053304,
@@ -2135,6 +2150,56 @@ EQMP
     },
 
 SQMP
+query-migration-capabilities
+-------
+
+Query migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "query-migration-capabilities"}
+<- { "return": [ { "capability": "xbzrle", "state": true },
+                 { "capability": "foobar", "state": false } ] }
+
+EQMP
+
+    {
+        .name       = "query-migration-capabilities",
+        .args_type  = "",
+	.mhandler.cmd_new = qmp_marshal_input_query_migration_capabilities,
+    },
+
+SQMP
+migrate_set_parameters
+-------
+
+Enable/Disable migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "migrate_set_parameters" , "arguments":
+     { "parameters": [ { "capability": "xbzrle", "state": true } ] } }
+
+EQMP
+
+    {
+        .name       = "migrate_set_parameters",
+        .args_type  = "parameters:O",
+	.params     = "capability:s,state:b",
+	.mhandler.cmd_new = qmp_marshal_input_migrate_set_parameters,
+    },
+
+
+
+SQMP
 query-balloon
 -------------
 
#21 lore raw

Re: [Qemu-devel] [PATCH 13/22] Add migration capabilities

Quoted 114 lines · On Wed, 25 Jul 2012 16:05:10 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 113 lines · Luiz Capitulino
Quoted 110 lines · On Tue, 24 Jul 2012 20:06:06 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 109 lines · Luiz Capitulino
Quoted 97 lines · On Tue, 24 Jul 2012 09:25:11 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
Quoted 2 lines · On Fri, 13 Jul 2012 09:23:35 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

Quoted 9 lines
Quoted 5 lines

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

Please, split this into one command per-patch. Otherwise it's difficult to review.

Sure.

Quoted 26 lines

Have libvirt folks acked this approach btw? It looks fine to me, but we need their ack too.

More comments below.

Quoted 21 lines
---
 hmp-commands.hx  |   16 ++++++++++++
 hmp.c            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    2 ++
 migration.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.h      |    2 ++
 monitor.c        |    7 ++++++
 qapi-schema.json |   53 ++++++++++++++++++++++++++++++++++++++--
 qmp-commands.hx  |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 280 insertions(+), 7 deletions(-)
hmp-commands.hx +0 -0
index f5d9d91..9245bef 100644
@@ -861,6 +861,20 @@ Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
 
Quoted 6 lines

hmp-commands.hx Set maximum tolerated downtime (in seconds) for migration. · line 866

Quoted 4 lines
hmp-commands.hx +3 -0
     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "",

Please, fill in params.

ok

Quoted 36 lines
Quoted 36 lines
hmp-commands.hx +13 -0
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+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",
@@ -1419,6 +1433,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migration_capabilities
+show migration capabilities
 @item info balloon
 show balloon information
 @item info qtree
hmp.c +1 -0
index 4c6d4ae..b0440e6 100644
@@ -131,9 +131,19 @@ void hmp_info_mice(Monitor *mon)
 void hmp_info_migrate(Monitor *mon)
 {
     MigrationInfo *info;
+    MigrationCapabilityInfoList *cap;
 
     info = qmp_query_migrate(NULL);
 
Quoted 12 lines

hmp.c void hmp_info_mice(Monitor *mon) · line 145

Quoted 8 lines
hmp.c +8 -0
+    if (info->has_capabilities && info->capabilities) {
+        monitor_printf(mon, "capabilities: ");
+        for (cap = info->capabilities; cap; cap = cap->next) {
+            monitor_printf(mon, "%s: %s ",
+                           MigrationCapability_lookup[cap->value->capability],
+                           cap->value->state ? "on" : "off");
+        }
+        monitor_printf(mon, "\n");

Why is this is needed? Isn't info migration-capabilities good enough? Besides, info migrate should only contain information about current migration process...

Quoted 5 lines

The reason we introduced capabilities is that xbzrle needs for both source and destination QEMU to be able to handle it. Even if both side support xbzrle the user may decide not to use it. User that wants to use xbzrle needs to check that both sides have support for it (using info capabilities) , than enable it in both sides (using migrate-set-parameter/s commands). This is a parameter for the current migration. So the user needs to know if xbzrle was enabled or disabled for the current migration, this code displays it.

But this is being returned even when there is no migration taking place. I'm answering this here in the 'info migrate' hunk, but my main concern is query-migrate.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

I think migration configuration is part of migration information and should be available to the user in 'info migration'. Especially before he starts running it to see if he need to change the configuration. Also it is very helpful for the user during the migration and also after it's completes.

I don't mind having this in 'info migrate' because we can change it later case we regret, so it's fine with me having that info there.

But query-migrate is different, once we add anything there it's there forever, so we have to be careful.

ok I will remove them from query-migrate.

Note that I'm asking to remove it from MIG_SETUP, the others states are fine.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

There is no way today to query the downtime and migration speed at all . you can always set them again but there is no way to know how it is configured.

Quoted 8 lines
Quoted 7 lines

Good point, but I think it's better to concentrate on the needs of xbzrle for now.

Quoted 1 line

I was actually thinking to add them to info migration (also for SETUP).

But we're in SETUP state only once, what happens if the settings are changed after a migration completed? How is mngt going to be able to query it?

After migration completes you can't change those setting , you should get an error.

Really, why? I thought it would be fine to change them at any time (except during migration, of course).

Quoted 515 lines
Quoted 6 lines

My advice to not delay the inclusion of this series is to drop the information from SETUP state and rely on query-migration-capabilities in 'info migrate'. We can extend later if needed (by means of new commands or adding info to query-migrate).

It needs to be another command, I can add query-migration-parameters.
You can look at this as 64bit support - you have 64bit support in the processor (this is what query-capabilities) but the OS can decide not to work in 64bit mode (do nothing) or using 64 bit (migrate-set-parameter).

Orit

Quoted 504 lines
Quoted 191 lines
Quoted 4 lines

query-migrate shouldn't return this info in MIG_STATE_SETUP, and for MIG_STATE_COMPLETED it should only be returned if there was a migration.

I think is case of MIG_SETUP we should return the configuration and params for the next migration. MIG_STATE_COMPLETED happens only if there was a successful migration other wise there will be another state.

Quoted 185 lines
Quoted 184 lines

some day when there will be better migration protocol, feature negotiations can be part of it ...

Quoted 153 lines
Quoted 140 lines
hmp.c +55 -0
+    }
     if (info->has_status) {
         monitor_printf(mon, "Migration status: %s\n", info->status);
     }
@@ -161,6 +171,25 @@ void hmp_info_migrate(Monitor *mon)
     qapi_free_MigrationInfo(info);
 }
 
+void hmp_info_migration_capabilities(Monitor *mon)
+{
+    MigrationCapabilityInfoList *caps_list, *cap;
+
+    caps_list = qmp_query_migration_capabilities(NULL);
+    if (!caps_list) {
+        monitor_printf(mon, "No migration capabilities found\n");
+        return;
+    }
+
+    for (cap = caps_list; cap; cap = cap->next) {
+        monitor_printf(mon, "%s: %s ",
+                       MigrationCapability_lookup[cap->value->capability],
+                       cap->value->state ? "on" : "off");
+    }
+
+    qapi_free_MigrationCapabilityInfoList(caps_list);
+}
+
 void hmp_info_cpus(Monitor *mon)
 {
     CpuInfoList *cpu_list, *cpu;
@@ -735,6 +764,41 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_speed(value, NULL);
 }
 
+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
+{
+    const char *cap = qdict_get_str(qdict, "capability");
+    bool state = qdict_get_bool(qdict, "state");
+    Error *err = NULL;
+    MigrationCapabilityInfoList *params = NULL;
+    int i;
+
+    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
+            if (!params) {
+                params = g_malloc0(sizeof(*params));
+            }
+            params->value = g_malloc0(sizeof(*params->value));
+            params->value->capability = i;
+            params->value->state = state;
+            params->next = NULL;
+            qmp_migrate_set_parameters(params, &err);
+            break;
+        }
+    }
+
+    if (i == MIGRATION_CAPABILITY_MAX) {
+        error_set(&err, QERR_INVALID_PARAMETER, cap);
+    }
+
+    qapi_free_MigrationCapabilityInfoList(params);
+
+    if (err) {
+        monitor_printf(mon, "migrate_set_parameter: %s\n",
+                       error_get_pretty(err));
+        error_free(err);
+    }
+}
+
 void hmp_set_password(Monitor *mon, const QDict *qdict)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
hmp.h +2 -0
index 79d138d..09ba198 100644
@@ -25,6 +25,7 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_info_mice(Monitor *mon);
 void hmp_info_migrate(Monitor *mon);
+void hmp_info_migration_capabilities(Monitor *mon);
 void hmp_info_cpus(Monitor *mon);
 void hmp_info_block(Monitor *mon);
 void hmp_info_blockstats(Monitor *mon);
@@ -51,6 +52,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(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);
migration.c +26 -1
index 8db1b43..fd004d7 100644
@@ -117,12 +117,36 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 {
     MigrationInfo *info = g_malloc0(sizeof(*info));
     MigrationState *s = migrate_get_current();
+    int i;
 
     switch (s->state) {
     case MIG_STATE_SETUP:
-        /* no migration has happened ever */
+        /* no migration has ever happened; show enabled capabilities */
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
         break;
     case MIG_STATE_ACTIVE:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
+
         info->has_status = true;
         info->status = g_strdup("active");
 
@@ -143,6 +167,18 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         }
         break;
     case MIG_STATE_COMPLETED:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 180

Quoted 10 lines
migration.c +10 -0
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }

Code triplication :)

Quoted 4 lines

Why is this is needed? Isn't query-migration-capabilities good enough? Besides, query-migrate should only contain information about current migration process...

see above

Quoted 18 lines
Quoted 5 lines
migration.c +1 -0
+
         info->has_status = true;
         info->status = g_strdup("completed");
 

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 211

Quoted 10 lines
migration.c +7 -0
@@ -166,6 +202,33 @@ MigrationInfo *qmp_query_migrate(Error **errp)
     return info;
 }
 
+MigrationCapabilityInfoList *qmp_query_migration_capabilities(Error **errp)
+{
+    MigrationCapabilityInfoList *caps_list = g_malloc0(sizeof(*caps_list));
+
+    caps_list->value = g_malloc(sizeof(*caps_list->value));
+    caps_list->value->capability = MIGRATION_CAPABILITY_XBZRLE;
+    caps_list->next = NULL;

Shouldn't this get the capabilities array from migrate_get_current()?

Quoted 2 lines

I mean, this makes query-migration-capabilities always return true for xbzrle, even if we set it to off.

Those are the general capabilities , if I want to use xbzrle ,does this QEMU support it ?
this is required because we need both the destination and the source to be able to handle it.
If one QEMU doesn't (older version of qemu, maybe it will be disbaled for certain architectures) we can't use the feature. This is for management and the user to check what migration capabilities this QEMU supports.

Quoted 4 lines
Quoted 3 lines

My point was that query-migration-capabilities will always return state=true for all existing capabilities. Don't we want users/mngt app to know which states have been turned off?

You need to separate the ability to use a capability and actually using it for migration. Also I don't want the user to be able to set some capability on, it depends on the code not user configuration.

Not sure I can follow, a user can set xbzrle capability to off, no?

Quoted 1 line

And for xbzrle we always return true for some version on QEMU , let say we decide we want to remove the code that implement it for some reason in some future version than it will return false.

That's fine (I mean, I'm not sure we will ever do it, but shouldn't be a problem if we do).

Quoted 300 lines

There is a reason the command that enables a capability for a migration was called 'migrate-set-parameter' and not set-capability to distinguish between them one is per QEMU code base and one is per migration.

Regards,
Orit

Quoted 294 lines
Quoted 293 lines
Quoted 64 lines
Quoted 64 lines
migration.c +26 -1
+
+    return caps_list;
+}
+
+void qmp_migrate_set_parameters(MigrationCapabilityInfoList *params,
+                                Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+    MigrationCapabilityInfoList *cap;
+
+    if (s->state == MIG_STATE_ACTIVE) {
+        error_set(errp, QERR_MIGRATION_ACTIVE);
+        return;
+    }
+
+    for (cap = params; cap; cap = cap->next) {
+        s->enabled_capabilities[cap->value->capability] = cap->value->state;
+    }
+}
+
 /* shared migration helpers */
 
 static int migrate_fd_cleanup(MigrationState *s)
@@ -375,12 +438,17 @@ static MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+
+    memcpy(enabled_capabilities, s->enabled_capabilities,
+           sizeof(enabled_capabilities));
 
     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
     s->params = *params;
+    memcpy(s->enabled_capabilities, enabled_capabilities,
+           sizeof(enabled_capabilities));
 
-    s->bandwidth_limit = bandwidth_limit;
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);
 
migration.h +2 -0
index 57572a6..713aae0 100644
@@ -19,6 +19,7 @@
 #include "notify.h"
 #include "error.h"
 #include "vmstate.h"
+#include "qapi-types.h"
 
 struct MigrationParams {
     bool blk;
@@ -39,6 +40,7 @@ struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };
 
Quoted 12 lines

monitor.c static mon_cmd_t info_cmds[] = { · line 2690

Quoted 10 lines
migration.h +0 -0
 void process_incoming_migration(QEMUFile *f);
monitor.c +1 -0
index f6107ba..e2be6cd 100644
@@ -2687,6 +2687,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_migrate,
     },
     {
+        .name       = "migration_capabilities",

migration-capabilities is better.

ok

Quoted 15 lines
Quoted 15 lines
monitor.c +6 -0
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration capabilities",
+        .mhandler.info = hmp_info_migration_capabilities,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
qapi-schema.json +0 -0
index 1ab5dbd..a8408fd 100644
@@ -288,11 +288,15 @@
Quoted 8 lines

qapi-schema.json line 292

Quoted 6 lines
qapi-schema.json +2 -1
 #        status, only returned if status is 'active' and it is a block
 #        migration
 #
-# Since: 0.14.0
+# @capabilities: #optional a list describing all the migration capabilities
+#                state

I don't think this is needed, as I've said above.

see above

Quoted 15 lines
Quoted 15 lines
qapi-schema.json +4 -1
+#
+# Since: 0.14.0, 'capabilities' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
-           '*disk': 'MigrationStats'} }
+           '*disk': 'MigrationStats',
+           '*capabilities': ['MigrationCapabilityInfo']} }
 
 ##
 # @query-migrate
@@ -306,6 +310,51 @@
 { 'command': 'query-migrate', 'returns': 'MigrationInfo' }
 
Quoted 8 lines

qapi-schema.json line 317

Quoted 6 lines
qapi-schema.json +5 -0
 ##
+# @MigrationCapability
+#
+# Migration capabilities enumeration
+#
+# @xbzrle: current migration supports xbzrle

You should explain what xbzrle is.

ok

Quoted 12 lines

qapi-schema.json line 325

Quoted 9 lines
qapi-schema.json +8 -0
+#
+# Since: 1.2
+##
+{ 'enum': 'MigrationCapability',
+  'data': ['xbzrle'] }
+
+##
+# @MigrationCapabilityInfo

MigrationCapabilityStatus?

Quoted 6 lines

qapi-schema.json line 329

Quoted 4 lines
qapi-schema.json +4 -0
+#
+# Migration capability information
+#
+# @capability: capability enum

Please, document state too.

ok

Orit

Quoted 145 lines
Quoted 144 lines
qapi-schema.json +28 -0
+#
+# Since: 1.2
+##
+{ 'type': 'MigrationCapabilityInfo',
+  'data': { 'capability' : 'MigrationCapability', 'state' : 'bool' } }
+
+##
+# @query-migration-capabilities
+#
+# Returns information about current migration process capabilties.
+#
+# Returns: @MigrationCapabilityInfo list
+#
+# Since: 1.2
+##
+{ 'command': 'query-migration-capabilities', 'returns': ['MigrationCapabilityInfo'] }
+
+##
+# @migrate_set_parameters
+#
+# Enable/Disable the following migration capabilities (like xbzrle)
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-parameters',
+  'data': { 'capabilities': ['MigrationCapabilityInfo'] } }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +68 -3
index 2e1a38e..3ee6e00 100644
@@ -2075,18 +2075,31 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
-
+- "capabilities": migration capabilities state
+         - "xbzrle" : XBZRLE state (json-bool)
 Examples:
 
 1. Before the first migration
 
 -> { "execute": "query-migrate" }
-<- { "return": {} }
+<- { "return": {
+        "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
+     }
+   }
 
 2. Migration is done and has succeeded
 
 -> { "execute": "query-migrate" }
-<- { "return": { "status": "completed" } }
+<- { "return": {
+        "status": "completed",
+        "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
+        "ram":{
+          "transferred":123,
+          "remaining":123,
+          "total":246
+        }
+     }
+   }
 
 3. Migration is done and has failed
 
@@ -2099,6 +2112,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "transferred":123,
             "remaining":123,
@@ -2113,6 +2127,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "total":1057024,
             "remaining":1053304,
@@ -2135,6 +2150,56 @@ EQMP
     },
 
 SQMP
+query-migration-capabilities
+-------
+
+Query migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "query-migration-capabilities"}
+<- { "return": [ { "capability": "xbzrle", "state": true },
+                 { "capability": "foobar", "state": false } ] }
+
+EQMP
+
+    {
+        .name       = "query-migration-capabilities",
+        .args_type  = "",
+	.mhandler.cmd_new = qmp_marshal_input_query_migration_capabilities,
+    },
+
+SQMP
+migrate_set_parameters
+-------
+
+Enable/Disable migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "migrate_set_parameters" , "arguments":
+     { "parameters": [ { "capability": "xbzrle", "state": true } ] } }
+
+EQMP
+
+    {
+        .name       = "migrate_set_parameters",
+        .args_type  = "parameters:O",
+	.params     = "capability:s,state:b",
+	.mhandler.cmd_new = qmp_marshal_input_migrate_set_parameters,
+    },
+
+
+
+SQMP
 query-balloon
 -------------
 
#22 lore raw

Re: [Qemu-devel] [PATCH 13/22] Add migration capabilities

Quoted 119 lines · Luiz Capitulino
Quoted 116 lines · On Wed, 25 Jul 2012 16:05:10 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 115 lines · Luiz Capitulino
Quoted 111 lines · On Tue, 24 Jul 2012 20:06:06 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 106 lines · Luiz Capitulino
Quoted 97 lines · On Tue, 24 Jul 2012 09:25:11 +0300 Orit Wasserman <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
Quoted 2 lines · On Fri, 13 Jul 2012 09:23:35 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

Quoted 9 lines
Quoted 5 lines

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

Please, split this into one command per-patch. Otherwise it's difficult to review.

Sure.

Quoted 26 lines

Have libvirt folks acked this approach btw? It looks fine to me, but we need their ack too.

More comments below.

Quoted 21 lines
---
 hmp-commands.hx  |   16 ++++++++++++
 hmp.c            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    2 ++
 migration.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.h      |    2 ++
 monitor.c        |    7 ++++++
 qapi-schema.json |   53 ++++++++++++++++++++++++++++++++++++++--
 qmp-commands.hx  |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 280 insertions(+), 7 deletions(-)
hmp-commands.hx +0 -0
index f5d9d91..9245bef 100644
@@ -861,6 +861,20 @@ Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
 
Quoted 6 lines

hmp-commands.hx Set maximum tolerated downtime (in seconds) for migration. · line 866

Quoted 4 lines
hmp-commands.hx +3 -0
     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "",

Please, fill in params.

ok

Quoted 36 lines
Quoted 36 lines
hmp-commands.hx +13 -0
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+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",
@@ -1419,6 +1433,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migration_capabilities
+show migration capabilities
 @item info balloon
 show balloon information
 @item info qtree
hmp.c +1 -0
index 4c6d4ae..b0440e6 100644
@@ -131,9 +131,19 @@ void hmp_info_mice(Monitor *mon)
 void hmp_info_migrate(Monitor *mon)
 {
     MigrationInfo *info;
+    MigrationCapabilityInfoList *cap;
 
     info = qmp_query_migrate(NULL);
 
Quoted 12 lines

hmp.c void hmp_info_mice(Monitor *mon) · line 145

Quoted 8 lines
hmp.c +8 -0
+    if (info->has_capabilities && info->capabilities) {
+        monitor_printf(mon, "capabilities: ");
+        for (cap = info->capabilities; cap; cap = cap->next) {
+            monitor_printf(mon, "%s: %s ",
+                           MigrationCapability_lookup[cap->value->capability],
+                           cap->value->state ? "on" : "off");
+        }
+        monitor_printf(mon, "\n");

Why is this is needed? Isn't info migration-capabilities good enough? Besides, info migrate should only contain information about current migration process...

Quoted 5 lines

The reason we introduced capabilities is that xbzrle needs for both source and destination QEMU to be able to handle it. Even if both side support xbzrle the user may decide not to use it. User that wants to use xbzrle needs to check that both sides have support for it (using info capabilities) , than enable it in both sides (using migrate-set-parameter/s commands). This is a parameter for the current migration. So the user needs to know if xbzrle was enabled or disabled for the current migration, this code displays it.

Quoted 3 lines

But this is being returned even when there is no migration taking place. I'm answering this here in the 'info migrate' hunk, but my main concern is query-migrate.

I think migration configuration is part of migration information and should be available to the user in 'info migration'. Especially before he starts running it to see if he need to change the configuration. Also it is very helpful for the user during the migration and also after it's completes.

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

I don't mind having this in 'info migrate' because we can change it later case we regret, so it's fine with me having that info there.

But query-migrate is different, once we add anything there it's there forever, so we have to be careful.

ok I will remove them from query-migrate.

Note that I'm asking to remove it from MIG_SETUP, the others states are fine.

ok

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

There is no way today to query the downtime and migration speed at all . you can always set them again but there is no way to know how it is configured.

Good point, but I think it's better to concentrate on the needs of xbzrle for now.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

I was actually thinking to add them to info migration (also for SETUP).

But we're in SETUP state only once, what happens if the settings are changed after a migration completed? How is mngt going to be able to query it?

After migration completes you can't change those setting , you should get an error.

Really, why? I thought it would be fine to change them at any time (except during migration, of course).

you are right .
Orit

Quoted 517 lines
Quoted 516 lines
Quoted 7 lines

My advice to not delay the inclusion of this series is to drop the information from SETUP state and rely on query-migration-capabilities in 'info migrate'. We can extend later if needed (by means of new commands or adding info to query-migrate).

It needs to be another command, I can add query-migration-parameters.
You can look at this as 64bit support - you have 64bit support in the processor (this is what query-capabilities) but the OS can decide not to work in 64bit mode (do nothing) or using 64 bit (migrate-set-parameter).

Orit

Quoted 504 lines
Quoted 191 lines
Quoted 4 lines

query-migrate shouldn't return this info in MIG_STATE_SETUP, and for MIG_STATE_COMPLETED it should only be returned if there was a migration.

I think is case of MIG_SETUP we should return the configuration and params for the next migration. MIG_STATE_COMPLETED happens only if there was a successful migration other wise there will be another state.

Quoted 185 lines
Quoted 184 lines

some day when there will be better migration protocol, feature negotiations can be part of it ...

Quoted 153 lines
Quoted 140 lines
hmp.c +55 -0
+    }
     if (info->has_status) {
         monitor_printf(mon, "Migration status: %s\n", info->status);
     }
@@ -161,6 +171,25 @@ void hmp_info_migrate(Monitor *mon)
     qapi_free_MigrationInfo(info);
 }
 
+void hmp_info_migration_capabilities(Monitor *mon)
+{
+    MigrationCapabilityInfoList *caps_list, *cap;
+
+    caps_list = qmp_query_migration_capabilities(NULL);
+    if (!caps_list) {
+        monitor_printf(mon, "No migration capabilities found\n");
+        return;
+    }
+
+    for (cap = caps_list; cap; cap = cap->next) {
+        monitor_printf(mon, "%s: %s ",
+                       MigrationCapability_lookup[cap->value->capability],
+                       cap->value->state ? "on" : "off");
+    }
+
+    qapi_free_MigrationCapabilityInfoList(caps_list);
+}
+
 void hmp_info_cpus(Monitor *mon)
 {
     CpuInfoList *cpu_list, *cpu;
@@ -735,6 +764,41 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_speed(value, NULL);
 }
 
+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
+{
+    const char *cap = qdict_get_str(qdict, "capability");
+    bool state = qdict_get_bool(qdict, "state");
+    Error *err = NULL;
+    MigrationCapabilityInfoList *params = NULL;
+    int i;
+
+    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
+            if (!params) {
+                params = g_malloc0(sizeof(*params));
+            }
+            params->value = g_malloc0(sizeof(*params->value));
+            params->value->capability = i;
+            params->value->state = state;
+            params->next = NULL;
+            qmp_migrate_set_parameters(params, &err);
+            break;
+        }
+    }
+
+    if (i == MIGRATION_CAPABILITY_MAX) {
+        error_set(&err, QERR_INVALID_PARAMETER, cap);
+    }
+
+    qapi_free_MigrationCapabilityInfoList(params);
+
+    if (err) {
+        monitor_printf(mon, "migrate_set_parameter: %s\n",
+                       error_get_pretty(err));
+        error_free(err);
+    }
+}
+
 void hmp_set_password(Monitor *mon, const QDict *qdict)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
hmp.h +2 -0
index 79d138d..09ba198 100644
@@ -25,6 +25,7 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_info_mice(Monitor *mon);
 void hmp_info_migrate(Monitor *mon);
+void hmp_info_migration_capabilities(Monitor *mon);
 void hmp_info_cpus(Monitor *mon);
 void hmp_info_block(Monitor *mon);
 void hmp_info_blockstats(Monitor *mon);
@@ -51,6 +52,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(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);
migration.c +26 -1
index 8db1b43..fd004d7 100644
@@ -117,12 +117,36 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 {
     MigrationInfo *info = g_malloc0(sizeof(*info));
     MigrationState *s = migrate_get_current();
+    int i;
 
     switch (s->state) {
     case MIG_STATE_SETUP:
-        /* no migration has happened ever */
+        /* no migration has ever happened; show enabled capabilities */
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
         break;
     case MIG_STATE_ACTIVE:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }
+
         info->has_status = true;
         info->status = g_strdup("active");
 
@@ -143,6 +167,18 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         }
         break;
     case MIG_STATE_COMPLETED:
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 180

Quoted 10 lines
migration.c +10 -0
+            if (!info->has_capabilities) {
+                info->capabilities = g_malloc0(sizeof(*info->capabilities));
+                info->has_capabilities = true;
+            }
+            info->capabilities->value =
+                g_malloc(sizeof(*info->capabilities->value));
+            info->capabilities->value->capability = i;
+            info->capabilities->value->state = s->enabled_capabilities[i];
+            info->capabilities->next = NULL;
+        }

Code triplication :)

Quoted 4 lines

Why is this is needed? Isn't query-migration-capabilities good enough? Besides, query-migrate should only contain information about current migration process...

see above

Quoted 18 lines
Quoted 5 lines
migration.c +1 -0
+
         info->has_status = true;
         info->status = g_strdup("completed");
 

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 211

Quoted 10 lines
migration.c +7 -0
@@ -166,6 +202,33 @@ MigrationInfo *qmp_query_migrate(Error **errp)
     return info;
 }
 
+MigrationCapabilityInfoList *qmp_query_migration_capabilities(Error **errp)
+{
+    MigrationCapabilityInfoList *caps_list = g_malloc0(sizeof(*caps_list));
+
+    caps_list->value = g_malloc(sizeof(*caps_list->value));
+    caps_list->value->capability = MIGRATION_CAPABILITY_XBZRLE;
+    caps_list->next = NULL;

Shouldn't this get the capabilities array from migrate_get_current()?

Quoted 2 lines

I mean, this makes query-migration-capabilities always return true for xbzrle, even if we set it to off.

Those are the general capabilities , if I want to use xbzrle ,does this QEMU support it ?
this is required because we need both the destination and the source to be able to handle it.
If one QEMU doesn't (older version of qemu, maybe it will be disbaled for certain architectures) we can't use the feature. This is for management and the user to check what migration capabilities this QEMU supports.

Quoted 4 lines
Quoted 3 lines

My point was that query-migration-capabilities will always return state=true for all existing capabilities. Don't we want users/mngt app to know which states have been turned off?

You need to separate the ability to use a capability and actually using it for migration. Also I don't want the user to be able to set some capability on, it depends on the code not user configuration.

Not sure I can follow, a user can set xbzrle capability to off, no?

Quoted 1 line

And for xbzrle we always return true for some version on QEMU , let say we decide we want to remove the code that implement it for some reason in some future version than it will return false.

That's fine (I mean, I'm not sure we will ever do it, but shouldn't be a problem if we do).

Quoted 300 lines

There is a reason the command that enables a capability for a migration was called 'migrate-set-parameter' and not set-capability to distinguish between them one is per QEMU code base and one is per migration.

Regards,
Orit

Quoted 294 lines
Quoted 293 lines
Quoted 64 lines
Quoted 64 lines
migration.c +26 -1
+
+    return caps_list;
+}
+
+void qmp_migrate_set_parameters(MigrationCapabilityInfoList *params,
+                                Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+    MigrationCapabilityInfoList *cap;
+
+    if (s->state == MIG_STATE_ACTIVE) {
+        error_set(errp, QERR_MIGRATION_ACTIVE);
+        return;
+    }
+
+    for (cap = params; cap; cap = cap->next) {
+        s->enabled_capabilities[cap->value->capability] = cap->value->state;
+    }
+}
+
 /* shared migration helpers */
 
 static int migrate_fd_cleanup(MigrationState *s)
@@ -375,12 +438,17 @@ static MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+
+    memcpy(enabled_capabilities, s->enabled_capabilities,
+           sizeof(enabled_capabilities));
 
     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
     s->params = *params;
+    memcpy(s->enabled_capabilities, enabled_capabilities,
+           sizeof(enabled_capabilities));
 
-    s->bandwidth_limit = bandwidth_limit;
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);
 
migration.h +2 -0
index 57572a6..713aae0 100644
@@ -19,6 +19,7 @@
 #include "notify.h"
 #include "error.h"
 #include "vmstate.h"
+#include "qapi-types.h"
 
 struct MigrationParams {
     bool blk;
@@ -39,6 +40,7 @@ struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };
 
Quoted 12 lines

monitor.c static mon_cmd_t info_cmds[] = { · line 2690

Quoted 10 lines
migration.h +0 -0
 void process_incoming_migration(QEMUFile *f);
monitor.c +1 -0
index f6107ba..e2be6cd 100644
@@ -2687,6 +2687,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_migrate,
     },
     {
+        .name       = "migration_capabilities",

migration-capabilities is better.

ok

Quoted 15 lines
Quoted 15 lines
monitor.c +6 -0
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration capabilities",
+        .mhandler.info = hmp_info_migration_capabilities,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
qapi-schema.json +0 -0
index 1ab5dbd..a8408fd 100644
@@ -288,11 +288,15 @@
Quoted 8 lines

qapi-schema.json line 292

Quoted 6 lines
qapi-schema.json +2 -1
 #        status, only returned if status is 'active' and it is a block
 #        migration
 #
-# Since: 0.14.0
+# @capabilities: #optional a list describing all the migration capabilities
+#                state

I don't think this is needed, as I've said above.

see above

Quoted 15 lines
Quoted 15 lines
qapi-schema.json +4 -1
+#
+# Since: 0.14.0, 'capabilities' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
-           '*disk': 'MigrationStats'} }
+           '*disk': 'MigrationStats',
+           '*capabilities': ['MigrationCapabilityInfo']} }
 
 ##
 # @query-migrate
@@ -306,6 +310,51 @@
 { 'command': 'query-migrate', 'returns': 'MigrationInfo' }
 
Quoted 8 lines

qapi-schema.json line 317

Quoted 6 lines
qapi-schema.json +5 -0
 ##
+# @MigrationCapability
+#
+# Migration capabilities enumeration
+#
+# @xbzrle: current migration supports xbzrle

You should explain what xbzrle is.

ok

Quoted 12 lines

qapi-schema.json line 325

Quoted 9 lines
qapi-schema.json +8 -0
+#
+# Since: 1.2
+##
+{ 'enum': 'MigrationCapability',
+  'data': ['xbzrle'] }
+
+##
+# @MigrationCapabilityInfo

MigrationCapabilityStatus?

Quoted 6 lines

qapi-schema.json line 329

Quoted 4 lines
qapi-schema.json +4 -0
+#
+# Migration capability information
+#
+# @capability: capability enum

Please, document state too.

ok

Orit

Quoted 145 lines
Quoted 144 lines
qapi-schema.json +28 -0
+#
+# Since: 1.2
+##
+{ 'type': 'MigrationCapabilityInfo',
+  'data': { 'capability' : 'MigrationCapability', 'state' : 'bool' } }
+
+##
+# @query-migration-capabilities
+#
+# Returns information about current migration process capabilties.
+#
+# Returns: @MigrationCapabilityInfo list
+#
+# Since: 1.2
+##
+{ 'command': 'query-migration-capabilities', 'returns': ['MigrationCapabilityInfo'] }
+
+##
+# @migrate_set_parameters
+#
+# Enable/Disable the following migration capabilities (like xbzrle)
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-parameters',
+  'data': { 'capabilities': ['MigrationCapabilityInfo'] } }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
qmp-commands.hx +68 -3
index 2e1a38e..3ee6e00 100644
@@ -2075,18 +2075,31 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
-
+- "capabilities": migration capabilities state
+         - "xbzrle" : XBZRLE state (json-bool)
 Examples:
 
 1. Before the first migration
 
 -> { "execute": "query-migrate" }
-<- { "return": {} }
+<- { "return": {
+        "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
+     }
+   }
 
 2. Migration is done and has succeeded
 
 -> { "execute": "query-migrate" }
-<- { "return": { "status": "completed" } }
+<- { "return": {
+        "status": "completed",
+        "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
+        "ram":{
+          "transferred":123,
+          "remaining":123,
+          "total":246
+        }
+     }
+   }
 
 3. Migration is done and has failed
 
@@ -2099,6 +2112,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "transferred":123,
             "remaining":123,
@@ -2113,6 +2127,7 @@ Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "total":1057024,
             "remaining":1053304,
@@ -2135,6 +2150,56 @@ EQMP
     },
 
 SQMP
+query-migration-capabilities
+-------
+
+Query migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "query-migration-capabilities"}
+<- { "return": [ { "capability": "xbzrle", "state": true },
+                 { "capability": "foobar", "state": false } ] }
+
+EQMP
+
+    {
+        .name       = "query-migration-capabilities",
+        .args_type  = "",
+	.mhandler.cmd_new = qmp_marshal_input_query_migration_capabilities,
+    },
+
+SQMP
+migrate_set_parameters
+-------
+
+Enable/Disable migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "migrate_set_parameters" , "arguments":
+     { "parameters": [ { "capability": "xbzrle", "state": true } ] } }
+
+EQMP
+
+    {
+        .name       = "migrate_set_parameters",
+        .args_type  = "parameters:O",
+	.params     = "capability:s,state:b",
+	.mhandler.cmd_new = qmp_marshal_input_migrate_set_parameters,
+    },
+
+
+
+SQMP
 query-balloon
 -------------
 
#23 lore raw

PATCH 14/22 Add XBZRLE documentation

In reply to Juan Quintela

From: Orit Wasserman <[email protected]>

---
 docs/xbzrle.txt |  136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)
 create mode 100644 docs/xbzrle.txt
docs/xbzrle.txt new file +136 -0
new file mode 100644
index 0000000..f70e851
@@ -0,0 +1,136 @@
+XBZRLE (Xor Based Zero Run Length Encoding)
+===========================================
+
+Using XBZRLE (Xor Based Zero Run Length Encoding) allows for the reduction
+of VM downtime and the total live-migration time of Virtual machines.
+It is particularly useful for virtual machines running memory write intensive
+workloads that are typical of large enterprise applications such as SAP ERP
+Systems, and generally speaking for any application that uses a sparse memory
+update pattern.
+
+Instead of sending the changed guest memory page this solution will send a
+compressed version of the updates, thus reducing the amount of data sent during
+live migration.
+In order to be able to calculate the update, the previous memory pages need to
+be stored on the source. Those pages are stored in a dedicated cache
+(hash table) and are
+accessed by their address.
+The larger the cache size the better the chances are that the page has already
+been stored in the cache.
+A small cache size will result in high cache miss rate.
+Cache size can be changed before and during migration.
+
+Format
+=======
+
+The compression format performs a XOR between the previous and current content
+of the page, where zero represents an unchanged value.
+The page data delta is represented by zero and non zero runs.
+A zero run is represented by its length (in bytes).
+A non zero run is represented by its length (in bytes) and the new data.
+The run length is encoded using ULEB128 (http://en.wikipedia.org/wiki/LEB128)
+
+There can be more than one valid encoding, the sender may send a longer encoding
+for the benefit of reducing computation cost.
+
+page = zrun nzrun
+       | zrun nzrun page
+
+zrun = length
+
+nzrun = length byte...
+
+length = uleb128 encoded integer
+
+On the sender side XBZRLE is used as a compact delta encoding of page updates,
+retrieving the old page content from the cache (default size of 512 MB). The
+receiving side uses the existing page's content and XBZRLE to decode the new
+page's content.
+
+This work was originally based on research results published
+VEE 2011: Evaluation of Delta Compression Techniques for Efficient Live
+Migration of Large Virtual Machines by Benoit, Svard, Tordsson and Elmroth.
+Additionally the delta encoder XBRLE was improved further using the XBZRLE
+instead.
+
+XBZRLE has a sustained bandwidth of 2-2.5 GB/s for typical workloads making it
+ideal for in-line, real-time encoding such as is needed for live-migration.
+
+Example
+old buffer:
+1001 zeros
+05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 68 00 00 6b 00 6d
+3074 zeros
+
+new buffer:
+1001 zeros
+01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 68 00 00 67 00 69
+3074 zeros
+
+encoded buffer:
+
+encoded length 24
+e9 07 0f 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 03 01 67 01 01 69
+
+Migration Capabilities
+======================
+In order to use XBZRLE the destination QEMU version should be able to
+decode the new format.
+Adding a new migration capabilities command that will allow external management
+to query for it support.
+A typical use for the destination
+    {qemu} info migrate_capabilities
+    {qemu} xbzrle, ...
+
+In order to enable capabilities for future live migration,
+a new command migrate_set_parameter is introduced:
+    {qemu} migrate_set_parameter xbzrle
+
+Usage
+======
+
+1. Activate xbzrle
+2. Set the XBZRLE cache size - the cache size is in MBytes and should be a
+power of 2. The cache default value is 64MBytes.
+3. start outgoing migration
+
+A typical usage scenario:
+On the incoming QEMU:
+    {qemu} migrate_set_parameter xbzrle on
+On the outgoing QEMU:
+    {qemu} migrate_set_parameter xbzrle on
+    {qemu} migrate_set_cachesize 256m
+    {qemu} migrate -d tcp:destination.host:4444
+    {qemu} info migrate
+    ...
+    cache size: 67108864 bytes
+    transferred ram-duplicate: A kbytes
+    transferred ram-normal: B kbytes
+    transferred ram-xbrle: C kbytes
+    overflow ram-xbrle: D pages
+    cache-miss ram-xbrle: E pages
+
+cache-miss: the number of cache misses to date - high cache-miss rate
+indicates that the cache size is set too low.
+overflow: the number of overflows in the decoding which where the delta could
+not be compressed. This can happen if the changes in the pages are too large
+or there are many short changes; for example, changing every second byte (half a
+page).
+
+Testing: Testing indicated that live migration with XBZRLE was completed in 110
+seconds, whereas without it would not be able to complete.
+
+A simple synthetic memory r/w load generator:
+..    include <stdlib.h>
+..    include <stdio.h>
+..    int main()
+..    {
+..        char *buf = (char *) calloc(4096, 4096);
+..        while (1) {
+..            int i;
+..            for (i = 0; i < 4096 * 4; i++) {
+..                buf[i * 4096 / 4]++;
+..            }
+..            printf(".");
+..        }
+..    }
Signature · 1 line
1.7.10.4
#24 lore raw

PATCH 15/22 Add cache handling functions

In reply to Juan Quintela

From: Orit Wasserman <[email protected]>

Add LRU page cache mechanism.
The page are accessed by their address.

---
 Makefile.objs             |    1 +
 cutils.c                  |    9 ++
 include/qemu/page_cache.h |   79 +++++++++++++++++
 page_cache.c              |  216 +++++++++++++++++++++++++++++++++++++++++++++
 qemu-common.h             |   13 +++
 5 files changed, 318 insertions(+)
 create mode 100644 include/qemu/page_cache.h
 create mode 100644 page_cache.c
Makefile.objs +1 -0
index 5ebbcfa..e0fb69b 100644
@@ -77,6 +77,7 @@ common-obj-y += qemu-char.o #aio.o
 common-obj-y += block-migration.o iohandler.o
 common-obj-y += pflib.o
 common-obj-y += bitmap.o bitops.o
+common-obj-y += page_cache.o
 
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
 common-obj-$(CONFIG_WIN32) += version.o
cutils.c +9 -0
index e2bc1b8..b0bdd4b 100644
@@ -375,3 +375,12 @@ int qemu_parse_fd(const char *param)
     }
     return fd;
 }
+
+/* round down to the nearest power of 2*/
+int64_t pow2floor(int64_t value)
+{
+    if (!is_power_of_2(value)) {
+        value = 0x8000000000000000ULL >> clz64(value);
+    }
+    return value;
+}
include/qemu/page_cache.h new file +79 -0

79 lines not on this page · raw message

page_cache.c new file +216 -0

216 lines not on this page · raw message

qemu-common.h +13 -0
index 09676f5..195bab5 100644
@@ -1,3 +1,4 @@
+
 /* Common header file that is included by all of qemu.  */
 #ifndef QEMU_COMMON_H
 #define QEMU_COMMON_H
@@ -411,6 +412,18 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
 /* Round number up to multiple */
 #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m))
 
+static inline bool is_power_of_2(int64_t value)
+{
+    if (!value) {
+        return 0;
+    }
+
+    return !(value & (value - 1));
+}
+
+/* round down to the nearest power of 2*/
+int64_t pow2floor(int64_t value);
+
 #include "module.h"
 
 #endif
Signature · 1 line
1.7.10.4
#25 lore raw

PATCH 16/22 Add uleb encoding/decoding functions

In reply to Juan Quintela

From: Orit Wasserman <[email protected]>

Implement Unsigned Little Endian Base 128.

---
 cutils.c      |   33 +++++++++++++++++++++++++++++++++
 qemu-common.h |    8 ++++++++
 2 files changed, 41 insertions(+)
cutils.c +33 -0
index b0bdd4b..700f943 100644
@@ -384,3 +384,36 @@ int64_t pow2floor(int64_t value)
     }
     return value;
 }
+
+/*
+ * Implementation of  ULEB128 (http://en.wikipedia.org/wiki/LEB128)
+ * Input is limited to 14-bit numbers
+ */
+int uleb128_encode_small(uint8_t *out, uint32_t n)
+{
+    g_assert(n <= 0x3fff);
+    if (n < 0x80) {
+        *out++ = n;
+        return 1;
+    } else {
+        *out++ = (n & 0x7f) | 0x80;
+        *out++ = n >> 7;
+        return 2;
+    }
+}
+
+int uleb128_decode_small(const uint8_t *in, uint32_t *n)
+{
+    if (!(*in & 0x80)) {
+        *n = *in++;
+        return 1;
+    } else {
+        *n = *in++ & 0x7f;
+        /* we exceed 14 bit number */
+        if (*in & 0x80) {
+            return -1;
+        }
+        *n |= *in++ << 7;
+        return 2;
+    }
+}
qemu-common.h +8 -0
index 195bab5..3188bdd 100644
@@ -426,4 +426,12 @@ int64_t pow2floor(int64_t value);
 
 #include "module.h"
 
+/*
+ * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128)
+ * Input is limited to 14-bit numbers
+ */
+
+int uleb128_encode_small(uint8_t *out, uint32_t n);
+int uleb128_decode_small(const uint8_t *in, uint32_t *n);
+
 #endif
Signature · 1 line
1.7.10.4
#26 lore raw

PATCH 17/22 Change ram_save_block to return -1 if there are no more changes

In reply to Juan Quintela

From: Orit Wasserman <[email protected]>

It will return 0 if the page is unmodifed.

---
 arch_init.c |   26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
arch_init.c +20 -6
index 8cbf8f4..78cdf50 100644
@@ -184,11 +184,19 @@ static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
 static RAMBlock *last_block;
 static ram_addr_t last_offset;
 
+/*
+ * ram_save_block: Writes a page of memory to the stream f
+ *
+ * Returns:  0: if the page hasn't changed
+ *          -1: if there are no more dirty pages
+ *           n: the amount of bytes written in other case
+ */
+
 static int ram_save_block(QEMUFile *f)
 {
     RAMBlock *block = last_block;
     ram_addr_t offset = last_offset;
-    int bytes_sent = 0;
+    int bytes_sent = -1;
     MemoryRegion *mr;
 
     if (!block)
@@ -354,10 +362,11 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
         int bytes_sent;
 
         bytes_sent = ram_save_block(f);
-        bytes_transferred += bytes_sent;
-        if (bytes_sent == 0) { /* no more blocks */
+        /* no more blocks to sent */
+        if (bytes_sent < 0) {
             break;
         }
+        bytes_transferred += bytes_sent;
         /* we want to check in the 1st loop, just in case it was the 1st time
            and we had to sync the dirty bitmap.
            qemu_get_clock_ns() is a bit expensive, so we only check each some
@@ -405,14 +414,19 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 
 static int ram_save_complete(QEMUFile *f, void *opaque)
 {
-    int bytes_sent;
-
     memory_global_sync_dirty_bitmap(get_system_memory());
 
     /* try transferring iterative blocks of memory */
 
     /* flush all remaining blocks regardless of rate limiting */
-    while ((bytes_sent = ram_save_block(f)) != 0) {
+    while (true) {
+        int bytes_sent;
+
+        bytes_sent = ram_save_block(f);
+        /* no more blocks to sent */
+        if (bytes_sent < 0) {
+            break;
+        }
         bytes_transferred += bytes_sent;
     }
     memory_global_dirty_log_stop();
Signature · 1 line
1.7.10.4
#27 lore raw

PATCH 18/22 Add xbzrle_encode_buffer and xbzrle_decode_buffer functions

In reply to Juan Quintela

From: Orit Wasserman <[email protected]>

For performance we are encoding long word at a time.
For nzrun we use long-word-at-a-time NULL-detection tricks from strcmp():
using ((lword - 0x0101010101010101) & (~lword) & 0x8080808080808080) test to find out if any byte in the long word is zero.

---
 migration.h |    4 ++
 savevm.c    |  159 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 163 insertions(+)
migration.h +4 -0
index 713aae0..743c366 100644
@@ -100,4 +100,8 @@ void migrate_add_blocker(Error *reason);
  */
 void migrate_del_blocker(Error *reason);
 
+int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
+                         uint8_t *dst, int dlen);
+int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen);
+
 #endif
savevm.c +159 -0

162 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#28 lore raw

PATCH 19/22 Add XBZRLE to ram_save_block and ram_save_live

In reply to Juan Quintela

From: Orit Wasserman <[email protected]>

In the outgoing migration check to see if the page is cached and changed than send compressed page by using save_xbrle_page function. In the incoming migration check to see if RAM_SAVE_FLAG_XBZRLE is set and decompress the page (by using load_xbrle function).

---
 arch_init.c |  169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.c |   24 +++++++++
 migration.h |    4 ++
 3 files changed, 194 insertions(+), 3 deletions(-)
arch_init.c +166 -3
index 78cdf50..a3a4707 100644
@@ -43,6 +43,7 @@
 #include "hw/smbios.h"
 #include "exec-memory.h"
 #include "hw/pcspk.h"
+#include "qemu/page_cache.h"
 
 #ifdef DEBUG_ARCH_INIT
 #define DPRINTF(fmt, ...) \
@@ -102,6 +103,7 @@ const uint32_t arch_type = QEMU_ARCH;
 #define RAM_SAVE_FLAG_PAGE     0x08
 #define RAM_SAVE_FLAG_EOS      0x10
 #define RAM_SAVE_FLAG_CONTINUE 0x20
+#define RAM_SAVE_FLAG_XBZRLE   0x40
 
 #ifdef __ALTIVEC__
 #include <altivec.h>
@@ -169,6 +171,27 @@ static int is_dup_page(uint8_t *page)
     return 1;
 }
 
+/* XBZRLE (Xor Based Zero Length Encoding */
+typedef struct XBZRLEHeader {
+    uint16_t xh_len;
+    uint8_t xh_flags;
+} XBZRLEHeader;
+
+/* struct contains XBZRLE cache and a static page
+   used by the compression */
+static struct {
+    /* buffer used for XBZRLE encoding */
+    uint8_t *encoded_buf;
+    /* buffer used for XBZRLE decoding */
+    uint8_t *decoded_buf;
+    /* Cache for XBZRLE */
+    PageCache *cache;
+} XBZRLE = {
+    .encoded_buf = NULL,
+    .decoded_buf = NULL,
+    .cache = NULL,
+};
+
 static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
         int cont, int flag)
 {
@@ -181,6 +204,60 @@ static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
 
 }
 
+#define ENCODING_FLAG_XBZRLE 0x1
+
+static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
+                            ram_addr_t current_addr, RAMBlock *block,
+                            ram_addr_t offset, int cont)
+{
+    int encoded_len = 0, bytes_sent = -1, ret = -1;
+    XBZRLEHeader hdr = {
+        .xh_len = 0,
+        .xh_flags = 0,
+    };
+    uint8_t *prev_cached_page;
+
+    if (!cache_is_cached(XBZRLE.cache, current_addr)) {
+        cache_insert(XBZRLE.cache, current_addr,
+                     g_memdup(current_data, TARGET_PAGE_SIZE));
+        return -1;
+    }
+
+    prev_cached_page = get_cached_data(XBZRLE.cache, current_addr);
+
+    /* XBZRLE encoding (if there is no overflow) */
+    encoded_len = xbzrle_encode_buffer(prev_cached_page, current_data,
+                                       TARGET_PAGE_SIZE, XBZRLE.encoded_buf,
+                                       TARGET_PAGE_SIZE);
+    if (encoded_len == 0) {
+        DPRINTF("Skipping unmodified page\n");
+        return 0;
+    } else if (encoded_len == -1) {
+        DPRINTF("Overflow\n");
+        /* update data in the cache */
+        memcpy(prev_cached_page, current_data, TARGET_PAGE_SIZE);
+        return -1;
+    }
+
+    /* we need to update the data in the cache, in order to get the same data
+       we cached we decode the encoded page on the cached data */
+    ret = xbzrle_decode_buffer(XBZRLE.encoded_buf, encoded_len,
+                               prev_cached_page, TARGET_PAGE_SIZE);
+    g_assert(ret != -1);
+
+    hdr.xh_len = encoded_len;
+    hdr.xh_flags |= ENCODING_FLAG_XBZRLE;
+
+    /* Send XBZRLE based compressed page */
+    save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
+    qemu_put_byte(f, hdr.xh_flags);
+    qemu_put_be16(f, hdr.xh_len);
+    qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
+    bytes_sent = encoded_len + sizeof(hdr);
+
+    return bytes_sent;
+}
+
 static RAMBlock *last_block;
 static ram_addr_t last_offset;
 
@@ -198,6 +275,7 @@ static int ram_save_block(QEMUFile *f)
     ram_addr_t offset = last_offset;
     int bytes_sent = -1;
     MemoryRegion *mr;
+    ram_addr_t current_addr;
 
     if (!block)
         block = QLIST_FIRST(&ram_list.blocks);
@@ -218,13 +296,24 @@ static int ram_save_block(QEMUFile *f)
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
                 qemu_put_byte(f, *p);
                 bytes_sent = 1;
-            } else {
+            } else if (migrate_use_xbzrle()) {
+                current_addr = block->offset + offset;
+                bytes_sent = save_xbzrle_page(f, p, current_addr, block,
+                                              offset, cont);
+                p = get_cached_data(XBZRLE.cache, current_addr);
+            }
+
+            /* either we didn't send yet (we may have had XBZRLE overflow) */
+            if (bytes_sent == -1) {
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
                 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
                 bytes_sent = TARGET_PAGE_SIZE;
             }
 
-            break;
+            /* if page is unmodified, continue to the next */
+            if (bytes_sent != 0) {
+                break;
+            }
         }
 
         offset += TARGET_PAGE_SIZE;
@@ -302,6 +391,14 @@ static void sort_ram_list(void)
 static void migration_end(void)
 {
     memory_global_dirty_log_stop();
+
+    if (migrate_use_xbzrle()) {
+        cache_fini(XBZRLE.cache);
+        g_free(XBZRLE.cache);
+        g_free(XBZRLE.encoded_buf);
+        g_free(XBZRLE.decoded_buf);
+        XBZRLE.cache = NULL;
+    }
 }
 
 static void ram_migration_cancel(void *opaque)
@@ -321,7 +418,17 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
     last_offset = 0;
     sort_ram_list();
 
-    /* Make sure all dirty bits are set */
+    if (migrate_use_xbzrle()) {
+        XBZRLE.cache = cache_init(migrate_xbzrle_cache_size() /
+                                  TARGET_PAGE_SIZE,
+                                  TARGET_PAGE_SIZE);
+        if (!XBZRLE.cache) {
+            DPRINTF("Error creating cache\n");
+            return -1;
+        }
+        XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
+    }
+
     QLIST_FOREACH(block, &ram_list.blocks, next) {
         for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
             if (!memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE,
@@ -436,6 +543,49 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
     return 0;
 }
 
+static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
+{
+    int ret, rc = 0;
+    XBZRLEHeader hdr = {
+        .xh_len = 0,
+        .xh_flags = 0,
+    };
+
+    if (!XBZRLE.decoded_buf) {
+        XBZRLE.decoded_buf = g_malloc(TARGET_PAGE_SIZE);
+    }
+
+    /* extract RLE header */
+    hdr.xh_flags = qemu_get_byte(f);
+    hdr.xh_len = qemu_get_be16(f);
+
+    if (!(hdr.xh_flags & ENCODING_FLAG_XBZRLE)) {
+        fprintf(stderr, "Failed to load XBZRLE page - wrong compression!\n");
+        return -1;
+    }
+
+    if (hdr.xh_len > TARGET_PAGE_SIZE) {
+        fprintf(stderr, "Failed to load XBZRLE page - len overflow!\n");
+        return -1;
+    }
+    /* load data and decode */
+    qemu_get_buffer(f, XBZRLE.decoded_buf, hdr.xh_len);
+
+    /* decode RLE */
+    ret = xbzrle_decode_buffer(XBZRLE.decoded_buf, hdr.xh_len, host,
+                               TARGET_PAGE_SIZE);
+    if (ret == -1) {
+        fprintf(stderr, "Failed to load XBZRLE page - decode error!\n");
+        rc = -1;
+    } else  if (ret > TARGET_PAGE_SIZE) {
+        fprintf(stderr, "Failed to load XBZRLE page - size %d exceeds %d!\n",
+                ret, TARGET_PAGE_SIZE);
+        rc = -1;
+    }
+
+    return rc;
+}
+
 static inline void *host_from_stream_offset(QEMUFile *f,
                                             ram_addr_t offset,
                                             int flags)
@@ -549,6 +699,19 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             }
 
             qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
+        } else if (flags & RAM_SAVE_FLAG_XBZRLE) {
+            if (!migrate_use_xbzrle()) {
+                return -EINVAL;
+            }
+            void *host = host_from_stream_offset(f, addr, flags);
+            if (!host) {
+                return -EINVAL;
+            }
+
+            if (load_xbzrle(f, addr, host) < 0) {
+                ret = -EINVAL;
+                goto done;
+            }
         }
         error = qemu_file_get_error(f);
         if (error) {
migration.c +24 -0
index fd004d7..1a264a9 100644
@@ -43,6 +43,9 @@ enum {
 
 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
 
+/* Migration XBZRLE default cache size */
+#define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
+
 static NotifierList migration_state_notifiers =
     NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
 
@@ -55,6 +58,7 @@ static MigrationState *migrate_get_current(void)
     static MigrationState current_migration = {
         .state = MIG_STATE_SETUP,
         .bandwidth_limit = MAX_THROTTLE,
+        .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE,
     };
 
     return &current_migration;
@@ -439,6 +443,7 @@ static MigrationState *migrate_init(const MigrationParams *params)
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
     bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+    int64_t xbzrle_cache_size = s->xbzrle_cache_size;
 
     memcpy(enabled_capabilities, s->enabled_capabilities,
            sizeof(enabled_capabilities));
@@ -448,6 +453,7 @@ static MigrationState *migrate_init(const MigrationParams *params)
     s->params = *params;
     memcpy(s->enabled_capabilities, enabled_capabilities,
            sizeof(enabled_capabilities));
+    s->xbzrle_cache_size = xbzrle_cache_size;
 
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);
@@ -546,3 +552,21 @@ void qmp_migrate_set_downtime(double value, Error **errp)
     value = MAX(0, MIN(UINT64_MAX, value));
     max_downtime = (uint64_t)value;
 }
+
+int migrate_use_xbzrle(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE];
+}
+
+int64_t migrate_xbzrle_cache_size(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->xbzrle_cache_size;
+}
migration.h +4 -0
index 743c366..cdf6787 100644
@@ -41,6 +41,7 @@ struct MigrationState
     MigrationParams params;
     int64_t total_time;
     bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+    int64_t xbzrle_cache_size;
 };
 
 void process_incoming_migration(QEMUFile *f);
@@ -104,4 +105,7 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
                          uint8_t *dst, int dlen);
 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);
+
 #endif
Signature · 1 line
1.7.10.4
#29 lore raw

PATCH 20/22 Add migrate_set_cachesize command

In reply to Juan Quintela

From: Orit Wasserman <[email protected]>

Change XBZRLE cache size in bytes (the size should be a power of 2, it will be rounded down to the nearest power of 2).
If XBZRLE cache size is too small there will be many cache miss.

---
 arch_init.c      |   10 ++++++++++
 hmp-commands.hx  |   20 ++++++++++++++++++++
 hmp.c            |   13 +++++++++++++
 hmp.h            |    1 +
 migration.c      |   14 ++++++++++++++
 migration.h      |    2 ++
 qapi-schema.json |   16 ++++++++++++++++
 qmp-commands.hx  |   23 +++++++++++++++++++++++
 8 files changed, 99 insertions(+)
arch_init.c +10 -0
index a3a4707..d972d84 100644
@@ -192,6 +192,16 @@ static struct {
     .cache = NULL,
 };
 
+
+int64_t xbzrle_cache_resize(int64_t new_size)
+{
+    if (XBZRLE.cache != NULL) {
+        return cache_resize(XBZRLE.cache, new_size / TARGET_PAGE_SIZE) *
+            TARGET_PAGE_SIZE;
+    }
+    return pow2floor(new_size);
+}
+
 static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
         int cont, int flag)
 {
hmp-commands.hx +20 -0
index 9245bef..052a0a3 100644
@@ -829,6 +829,26 @@ STEXI
 @item migrate_cancel
 @findex migrate_cancel
 Cancel the current VM migration.
+
+ETEXI
+
+    {
+        .name       = "migrate_set_cachesize",
+        .args_type  = "value:o",
+        .params     = "value",
+        .help       = "set cache size (in bytes) for XBZRLE migrations,"
+                      "the cache size will be rounded down to the nearest "
+                      "power of 2.\n"
+                      "The cache size effects the number of cache misses."
+                      "In case of a high cache miss ratio you need to increase"
+                      " the cache size",
+        .mhandler.cmd = hmp_migrate_set_cachesize,
+    },
+
+STEXI
+@item migrate_set_cachesize @var{value}
+@findex migrate_set_cachesize
+Set cache size to @var{value} (in bytes) for xbzrle migrations.
 ETEXI
 
     {
hmp.c +13 -0
index b0440e6..99ad00a 100644
@@ -758,6 +758,19 @@ void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_downtime(value, NULL);
 }
 
+void hmp_migrate_set_cachesize(Monitor *mon, const QDict *qdict)
+{
+    int64_t value = qdict_get_int(qdict, "value");
+    Error *err = NULL;
+
+    qmp_migrate_set_cache_size(value, &err);
+    if (err) {
+        monitor_printf(mon, "%s\n", error_get_pretty(err));
+        error_free(err);
+        return;
+    }
+}
+
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
 {
     int64_t value = qdict_get_int(qdict, "value");
hmp.h +1 -0
index 09ba198..7c5117d 100644
@@ -53,6 +53,7 @@ void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_cachesize(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);
migration.c +14 -0
index 1a264a9..d134bf6 100644
@@ -533,6 +533,20 @@ void qmp_migrate_cancel(Error **errp)
     migrate_fd_cancel(migrate_get_current());
 }
 
+void qmp_migrate_set_cache_size(int64_t value, Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+
+    /* Check for truncation */
+    if (value != (size_t)value) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
+                  "exceeding address space");
+        return;
+    }
+
+    s->xbzrle_cache_size = xbzrle_cache_resize(value);
+}
+
 void qmp_migrate_set_speed(int64_t value, Error **errp)
 {
     MigrationState *s;
migration.h +2 -0
index cdf6787..337e225 100644
@@ -108,4 +108,6 @@ 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);
 
+int64_t xbzrle_cache_resize(int64_t new_size);
+
 #endif
qapi-schema.json +16 -0
index a8408fd..a0f0f95 100644
@@ -1390,6 +1390,22 @@
 { 'command': 'migrate_set_speed', 'data': {'value': 'int'} }
 
 ##
+# @migrate-set-cache-size
+#
+# Set XBZRLE cache size
+#
+# @value: cache size in bytes
+#
+# The size will be rounded down to the nearest power of 2.
+# The cache size can be modified before and during ongoing migration
+#
+# Returns: nothing on success
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-cache-size', 'data': {'value': 'int'} }
+
+##
 # @ObjectPropertyInfo:
 #
 # @name: the name of the property
qmp-commands.hx +23 -0
index 3ee6e00..a3d57ce 100644
@@ -520,6 +520,29 @@ Example:
 <- { "return": {} }
 
 EQMP
+{
+        .name       = "migrate-set-cache-size",
+        .args_type  = "value:o",
+        .mhandler.cmd_new = qmp_marshal_input_migrate_set_cache_size,
+    },
+
+SQMP
+migrate-set-cache-size
+---------------------
+
+Set cache size to be used by XBZRLE migration, the cache size will be rounded
+down to the nearest power of 2
+
+Arguments:
+
+- "value": cache size in bytes (json-int)
+
+Example:
+
+-> { "execute": "migrate-set-cache-size", "arguments": { "value": 536870912 } }
+<- { "return": {} }
+
+EQMP
 
     {
         .name       = "migrate_set_speed",
Signature · 1 line
1.7.10.4
Reviewed-by on v1 20/22
#30 lore raw

Re: [Qemu-devel] [PATCH 20/22] Add migrate_set_cachesize command

Quoted 5 lines · On Fri, 13 Jul 2012 09:23:42 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

Change XBZRLE cache size in bytes (the size should be a power of 2, it will be rounded down to the nearest power of 2).
If XBZRLE cache size is too small there will be many cache miss.

As far as QMP is concerned:

Quoted 202 lines
---
 arch_init.c      |   10 ++++++++++
 hmp-commands.hx  |   20 ++++++++++++++++++++
 hmp.c            |   13 +++++++++++++
 hmp.h            |    1 +
 migration.c      |   14 ++++++++++++++
 migration.h      |    2 ++
 qapi-schema.json |   16 ++++++++++++++++
 qmp-commands.hx  |   23 +++++++++++++++++++++++
 8 files changed, 99 insertions(+)
arch_init.c +10 -0
index a3a4707..d972d84 100644
@@ -192,6 +192,16 @@ static struct {
     .cache = NULL,
 };
 
+
+int64_t xbzrle_cache_resize(int64_t new_size)
+{
+    if (XBZRLE.cache != NULL) {
+        return cache_resize(XBZRLE.cache, new_size / TARGET_PAGE_SIZE) *
+            TARGET_PAGE_SIZE;
+    }
+    return pow2floor(new_size);
+}
+
 static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
         int cont, int flag)
 {
hmp-commands.hx +20 -0
index 9245bef..052a0a3 100644
@@ -829,6 +829,26 @@ STEXI
 @item migrate_cancel
 @findex migrate_cancel
 Cancel the current VM migration.
+
+ETEXI
+
+    {
+        .name       = "migrate_set_cachesize",
+        .args_type  = "value:o",
+        .params     = "value",
+        .help       = "set cache size (in bytes) for XBZRLE migrations,"
+                      "the cache size will be rounded down to the nearest "
+                      "power of 2.\n"
+                      "The cache size effects the number of cache misses."
+                      "In case of a high cache miss ratio you need to increase"
+                      " the cache size",
+        .mhandler.cmd = hmp_migrate_set_cachesize,
+    },
+
+STEXI
+@item migrate_set_cachesize @var{value}
+@findex migrate_set_cachesize
+Set cache size to @var{value} (in bytes) for xbzrle migrations.
 ETEXI
 
     {
hmp.c +13 -0
index b0440e6..99ad00a 100644
@@ -758,6 +758,19 @@ void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_downtime(value, NULL);
 }
 
+void hmp_migrate_set_cachesize(Monitor *mon, const QDict *qdict)
+{
+    int64_t value = qdict_get_int(qdict, "value");
+    Error *err = NULL;
+
+    qmp_migrate_set_cache_size(value, &err);
+    if (err) {
+        monitor_printf(mon, "%s\n", error_get_pretty(err));
+        error_free(err);
+        return;
+    }
+}
+
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
 {
     int64_t value = qdict_get_int(qdict, "value");
hmp.h +1 -0
index 09ba198..7c5117d 100644
@@ -53,6 +53,7 @@ void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_cachesize(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);
migration.c +14 -0
index 1a264a9..d134bf6 100644
@@ -533,6 +533,20 @@ void qmp_migrate_cancel(Error **errp)
     migrate_fd_cancel(migrate_get_current());
 }
 
+void qmp_migrate_set_cache_size(int64_t value, Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+
+    /* Check for truncation */
+    if (value != (size_t)value) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
+                  "exceeding address space");
+        return;
+    }
+
+    s->xbzrle_cache_size = xbzrle_cache_resize(value);
+}
+
 void qmp_migrate_set_speed(int64_t value, Error **errp)
 {
     MigrationState *s;
migration.h +2 -0
index cdf6787..337e225 100644
@@ -108,4 +108,6 @@ 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);
 
+int64_t xbzrle_cache_resize(int64_t new_size);
+
 #endif
qapi-schema.json +16 -0
index a8408fd..a0f0f95 100644
@@ -1390,6 +1390,22 @@
 { 'command': 'migrate_set_speed', 'data': {'value': 'int'} }
 
 ##
+# @migrate-set-cache-size
+#
+# Set XBZRLE cache size
+#
+# @value: cache size in bytes
+#
+# The size will be rounded down to the nearest power of 2.
+# The cache size can be modified before and during ongoing migration
+#
+# Returns: nothing on success
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-cache-size', 'data': {'value': 'int'} }
+
+##
 # @ObjectPropertyInfo:
 #
 # @name: the name of the property
qmp-commands.hx +23 -0
index 3ee6e00..a3d57ce 100644
@@ -520,6 +520,29 @@ Example:
 <- { "return": {} }
 
 EQMP
+{
+        .name       = "migrate-set-cache-size",
+        .args_type  = "value:o",
+        .mhandler.cmd_new = qmp_marshal_input_migrate_set_cache_size,
+    },
+
+SQMP
+migrate-set-cache-size
+---------------------
+
+Set cache size to be used by XBZRLE migration, the cache size will be rounded
+down to the nearest power of 2
+
+Arguments:
+
+- "value": cache size in bytes (json-int)
+
+Example:
+
+-> { "execute": "migrate-set-cache-size", "arguments": { "value": 536870912 } }
+<- { "return": {} }
+
+EQMP
 
     {
         .name       = "migrate_set_speed",
#31 lore raw

PATCH 21/22 Add XBZRLE statistics

In reply to Juan Quintela

From: Orit Wasserman <[email protected]>

---
 arch_init.c      |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.c            |   13 +++++++++++
 migration.c      |   49 ++++++++++++++++++++++++++++++++++++++++
 migration.h      |    9 ++++++++
 qapi-schema.json |   37 +++++++++++++++++++++++++-----
 qmp-commands.hx  |   35 ++++++++++++++++++++++++++++-
 6 files changed, 203 insertions(+), 6 deletions(-)
arch_init.c +66 -0
index d972d84..ab3fb2c 100644
@@ -202,6 +202,64 @@ int64_t xbzrle_cache_resize(int64_t new_size)
     return pow2floor(new_size);
 }
 
+/* accounting for migration statistics */
+typedef struct AccountingInfo {
+    uint64_t dup_pages;
+    uint64_t norm_pages;
+    uint64_t xbzrle_bytes;
+    uint64_t xbzrle_pages;
+    uint64_t xbzrle_cache_miss;
+    uint64_t iterations;
+    uint64_t xbzrle_overflows;
+} AccountingInfo;
+
+static AccountingInfo acct_info;
+
+static void acct_clear(void)
+{
+    memset(&acct_info, 0, sizeof(acct_info));
+}
+
+uint64_t dup_mig_bytes_transferred(void)
+{
+    return acct_info.dup_pages * TARGET_PAGE_SIZE;
+}
+
+uint64_t dup_mig_pages_transferred(void)
+{
+    return acct_info.dup_pages;
+}
+
+uint64_t norm_mig_bytes_transferred(void)
+{
+    return acct_info.norm_pages * TARGET_PAGE_SIZE;
+}
+
+uint64_t norm_mig_pages_transferred(void)
+{
+    return acct_info.norm_pages;
+}
+
+uint64_t xbzrle_mig_bytes_transferred(void)
+{
+    return acct_info.xbzrle_bytes;
+}
+
+uint64_t xbzrle_mig_pages_transferred(void)
+{
+    return acct_info.xbzrle_pages;
+}
+
+uint64_t xbzrle_mig_pages_cache_miss(void)
+{
+    return acct_info.xbzrle_cache_miss;
+}
+
+uint64_t xbzrle_mig_pages_overflow(void)
+{
+    return acct_info.xbzrle_overflows;
+}
+
 static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
         int cont, int flag)
 {
@@ -230,6 +288,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
     if (!cache_is_cached(XBZRLE.cache, current_addr)) {
         cache_insert(XBZRLE.cache, current_addr,
                      g_memdup(current_data, TARGET_PAGE_SIZE));
+        acct_info.xbzrle_cache_miss++;
         return -1;
     }
 
@@ -244,6 +303,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
         return 0;
     } else if (encoded_len == -1) {
         DPRINTF("Overflow\n");
+        acct_info.xbzrle_overflows++;
         /* update data in the cache */
         memcpy(prev_cached_page, current_data, TARGET_PAGE_SIZE);
         return -1;
@@ -263,7 +323,9 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
     qemu_put_byte(f, hdr.xh_flags);
     qemu_put_be16(f, hdr.xh_len);
     qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
+    acct_info.xbzrle_pages++;
     bytes_sent = encoded_len + sizeof(hdr);
+    acct_info.xbzrle_bytes += bytes_sent;
 
     return bytes_sent;
 }
@@ -303,6 +365,7 @@ static int ram_save_block(QEMUFile *f)
             p = memory_region_get_ram_ptr(mr) + offset;
 
             if (is_dup_page(p)) {
+                acct_info.dup_pages++;
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
                 qemu_put_byte(f, *p);
                 bytes_sent = 1;
@@ -318,6 +381,7 @@ static int ram_save_block(QEMUFile *f)
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
                 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
                 bytes_sent = TARGET_PAGE_SIZE;
+                acct_info.norm_pages++;
             }
 
             /* if page is unmodified, continue to the next */
@@ -437,6 +501,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
             return -1;
         }
         XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
+        acct_clear();
     }
 
     QLIST_FOREACH(block, &ram_list.blocks, next) {
@@ -484,6 +549,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
             break;
         }
         bytes_transferred += bytes_sent;
+        acct_info.iterations++;
         /* we want to check in the 1st loop, just in case it was the 1st time
            and we had to sync the dirty bitmap.
            qemu_get_clock_ns() is a bit expensive, so we only check each some
hmp.c +13 -0
index 99ad00a..0d7333b 100644
@@ -168,6 +168,19 @@ void hmp_info_migrate(Monitor *mon)
                        info->disk->total >> 10);
     }
 
+    if (info->has_cache) {
+        monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
+                       info->cache->cache_size);
+        monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
+                       info->cache->xbzrle_bytes >> 10);
+        monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
+                       info->cache->xbzrle_pages);
+        monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
+                       info->cache->xbzrle_cache_miss);
+        monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
+                       info->cache->xbzrle_overflow);
+    }
+
     qapi_free_MigrationInfo(info);
 }
 
migration.c +49 -0

73 lines not on this page · raw message

migration.h +9 -0
index 337e225..a9852fc 100644
@@ -87,6 +87,15 @@ uint64_t ram_bytes_total(void);
 
 extern SaveVMHandlers savevm_ram_handlers;
 
+uint64_t dup_mig_bytes_transferred(void);
+uint64_t dup_mig_pages_transferred(void);
+uint64_t norm_mig_bytes_transferred(void);
+uint64_t norm_mig_pages_transferred(void);
+uint64_t xbzrle_mig_bytes_transferred(void);
+uint64_t xbzrle_mig_pages_transferred(void);
+uint64_t xbzrle_mig_pages_overflow(void);
+uint64_t xbzrle_mig_pages_cache_miss(void);
+
 /**
  * @migrate_add_blocker - prevent migration from proceeding
  *
qapi-schema.json +32 -5
index a0f0f95..961810b 100644
@@ -264,11 +264,35 @@
 #        migration has ended, it returns the total migration
 #        time. (since 1.2)
 #
-# Since: 0.14.0.
+# @duplicate: #optional, number of duplicate pages
+#
+# @normal : #optional, number of normal pages
+#
+# Since: 0.14.0, 'duplicate' and 'normal' since 1.2
 ##
 { 'type': 'MigrationStats',
   'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' ,
-           'total_time': 'int' } }
+           'total_time': 'int', '*duplicate': 'int', '*normal': 'int' } }
+##
+# @CacheStats
+#
+# Detailed XBZRLE migration cache statistics
+#
+# @cache_size: XBZRLE cache size
+#
+# @xbzrle_bytes: amount of bytes already transferred to the target VM
+#
+# @xbzrle_pages: amount of pages transferred to the target VM
+#
+# @xbzrle_cache_miss: number of cache miss
+#
+# @xbzrle_overflow: number of overflows
+#
+# Since: 1.2
+##
+{ 'type': 'CacheStats',
+  'data': {'cache-size': 'int', 'xbzrle-bytes': 'int', 'xbzrle-pages': 'int',
+           'xbzrle-cache-miss': 'int', 'xbzrle-overflow': 'int' } }
 
 ##
 # @MigrationInfo
@@ -291,13 +315,16 @@
 # @capabilities: #optional a list describing all the migration capabilities
 #                state
 #
-# Since: 0.14.0, 'capabilities' since 1.2
+# @cache: #optional @MigrationStats containing detailed XBZRLE migration
+#         statistics
+#
+# Since: 0.14.0, 'capabilities' and 'cache' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
            '*disk': 'MigrationStats',
-           '*capabilities': ['MigrationCapabilityInfo']} }
-
+           '*capabilities': ['MigrationCapabilityInfo'],
+           '*cache': 'CacheStats'} }
 ##
 # @query-migrate
 #
qmp-commands.hx +34 -1
index a3d57ce..34d4675 100644
@@ -2093,6 +2093,8 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
+	 - "duplicate": number of duplicated pages (json-int)
+	 - "normal" : number of normal pages transferred (json-int)
 - "disk": only present if "status" is "active" and it is a block migration,
   it is a json-object with the following disk information (in bytes):
          - "transferred": amount transferred (json-int)
@@ -2100,10 +2102,17 @@ The main json-object contains the following:
          - "total": total (json-int)
 - "capabilities": migration capabilities state
          - "xbzrle" : XBZRLE state (json-bool)
+- "cache": only present if "status" and XBZRLE is active.
+  It is a json-object with the following XBZRLE information:
+         - "cache-size": XBZRLE cache size
+         - "xbzrle-bytes": total XBZRLE bytes transferred
+         - "xbzrle-pages": number of XBZRLE compressed pages
+         - "cache-miss": number of cache misses
+         - "overflow": number of XBZRLE overflows
+
 Examples:
 
 1. Before the first migration
-
 -> { "execute": "query-migrate" }
 <- { "return": {
         "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
@@ -2164,6 +2173,30 @@ Examples:
       }
    }
 
+6. Migration is being performed and XBZRLE is active:
+
+-> { "execute": "query-migrate" }
+<- {
+      "return":{
+         "status":"active",
+         "capabilities" : [ { "capability": "xbzrle", "state" : true } ],
+         "ram":{
+            "total":1057024,
+            "remaining":1053304,
+            "transferred":3720,
+            "duplicate": 10,
+            "normal" : 3333
+         },
+         "cache":{
+            "cache-size": 1024
+            "xbzrle-transferred":20971520,
+            "xbzrle-pages":2444343,
+            "xbzrle-cache-miss":2244,
+            "xbzrle-overflow":34434
+         }
+      }
+   }
+
 EQMP
 
     {
Signature · 1 line
1.7.10.4
#32 lore raw

Re: [Qemu-devel] [PATCH 21/22] Add XBZRLE statistics

Quoted 176 lines · On Fri, 13 Jul 2012 09:23:43 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

---
 arch_init.c      |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.c            |   13 +++++++++++
 migration.c      |   49 ++++++++++++++++++++++++++++++++++++++++
 migration.h      |    9 ++++++++
 qapi-schema.json |   37 +++++++++++++++++++++++++-----
 qmp-commands.hx  |   35 ++++++++++++++++++++++++++++-
 6 files changed, 203 insertions(+), 6 deletions(-)
arch_init.c +66 -0
index d972d84..ab3fb2c 100644
@@ -202,6 +202,64 @@ int64_t xbzrle_cache_resize(int64_t new_size)
     return pow2floor(new_size);
 }
 
+/* accounting for migration statistics */
+typedef struct AccountingInfo {
+    uint64_t dup_pages;
+    uint64_t norm_pages;
+    uint64_t xbzrle_bytes;
+    uint64_t xbzrle_pages;
+    uint64_t xbzrle_cache_miss;
+    uint64_t iterations;
+    uint64_t xbzrle_overflows;
+} AccountingInfo;
+
+static AccountingInfo acct_info;
+
+static void acct_clear(void)
+{
+    memset(&acct_info, 0, sizeof(acct_info));
+}
+
+uint64_t dup_mig_bytes_transferred(void)
+{
+    return acct_info.dup_pages * TARGET_PAGE_SIZE;
+}
+
+uint64_t dup_mig_pages_transferred(void)
+{
+    return acct_info.dup_pages;
+}
+
+uint64_t norm_mig_bytes_transferred(void)
+{
+    return acct_info.norm_pages * TARGET_PAGE_SIZE;
+}
+
+uint64_t norm_mig_pages_transferred(void)
+{
+    return acct_info.norm_pages;
+}
+
+uint64_t xbzrle_mig_bytes_transferred(void)
+{
+    return acct_info.xbzrle_bytes;
+}
+
+uint64_t xbzrle_mig_pages_transferred(void)
+{
+    return acct_info.xbzrle_pages;
+}
+
+uint64_t xbzrle_mig_pages_cache_miss(void)
+{
+    return acct_info.xbzrle_cache_miss;
+}
+
+uint64_t xbzrle_mig_pages_overflow(void)
+{
+    return acct_info.xbzrle_overflows;
+}
+
 static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
         int cont, int flag)
 {
@@ -230,6 +288,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
     if (!cache_is_cached(XBZRLE.cache, current_addr)) {
         cache_insert(XBZRLE.cache, current_addr,
                      g_memdup(current_data, TARGET_PAGE_SIZE));
+        acct_info.xbzrle_cache_miss++;
         return -1;
     }
 
@@ -244,6 +303,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
         return 0;
     } else if (encoded_len == -1) {
         DPRINTF("Overflow\n");
+        acct_info.xbzrle_overflows++;
         /* update data in the cache */
         memcpy(prev_cached_page, current_data, TARGET_PAGE_SIZE);
         return -1;
@@ -263,7 +323,9 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
     qemu_put_byte(f, hdr.xh_flags);
     qemu_put_be16(f, hdr.xh_len);
     qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
+    acct_info.xbzrle_pages++;
     bytes_sent = encoded_len + sizeof(hdr);
+    acct_info.xbzrle_bytes += bytes_sent;
 
     return bytes_sent;
 }
@@ -303,6 +365,7 @@ static int ram_save_block(QEMUFile *f)
             p = memory_region_get_ram_ptr(mr) + offset;
 
             if (is_dup_page(p)) {
+                acct_info.dup_pages++;
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
                 qemu_put_byte(f, *p);
                 bytes_sent = 1;
@@ -318,6 +381,7 @@ static int ram_save_block(QEMUFile *f)
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
                 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
                 bytes_sent = TARGET_PAGE_SIZE;
+                acct_info.norm_pages++;
             }
 
             /* if page is unmodified, continue to the next */
@@ -437,6 +501,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
             return -1;
         }
         XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
+        acct_clear();
     }
 
     QLIST_FOREACH(block, &ram_list.blocks, next) {
@@ -484,6 +549,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
             break;
         }
         bytes_transferred += bytes_sent;
+        acct_info.iterations++;
         /* we want to check in the 1st loop, just in case it was the 1st time
            and we had to sync the dirty bitmap.
            qemu_get_clock_ns() is a bit expensive, so we only check each some
hmp.c +13 -0
index 99ad00a..0d7333b 100644
@@ -168,6 +168,19 @@ void hmp_info_migrate(Monitor *mon)
                        info->disk->total >> 10);
     }
 
+    if (info->has_cache) {
+        monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
+                       info->cache->cache_size);
+        monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
+                       info->cache->xbzrle_bytes >> 10);
+        monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
+                       info->cache->xbzrle_pages);
+        monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
+                       info->cache->xbzrle_cache_miss);
+        monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
+                       info->cache->xbzrle_overflow);
+    }
+
     qapi_free_MigrationInfo(info);
 }
 
migration.c +1 -0
index d134bf6..e11f451 100644
@@ -137,6 +137,17 @@ MigrationInfo *qmp_query_migrate(Error **errp)
             info->capabilities->value->state = s->enabled_capabilities[i];
             info->capabilities->next = NULL;
         }
+

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 150

Quoted 10 lines
migration.c +10 -0
+        /* display xbzrle cache size */
+        if (migrate_use_xbzrle()) {
+            info->has_cache = true;
+            info->cache = g_malloc0(sizeof(*info->cache));
+            info->cache->cache_size = migrate_xbzrle_cache_size();
+            info->cache->xbzrle_bytes = xbzrle_mig_bytes_transferred();
+            info->cache->xbzrle_pages = xbzrle_mig_pages_transferred();
+            info->cache->xbzrle_cache_miss = xbzrle_mig_pages_cache_miss();
+            info->cache->xbzrle_overflow = xbzrle_mig_pages_overflow();
+        }

Why do you need this in MIG_STATE_SETUP? I think having it only in MIG_STATE_ACTIVE is enough (and probably that's what we want).

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 176

Quoted 9 lines
migration.c +2 -0
         break;
     case MIG_STATE_ACTIVE:
         for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
@@ -161,6 +172,8 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         info->ram->total = ram_bytes_total();
         info->ram->total_time = qemu_get_clock_ms(rt_clock)
             - s->total_time;
+        info->ram->duplicate = dup_mig_pages_transferred();
+        info->ram->normal = norm_mig_pages_transferred();

Can we do this extension in a different patch?

Quoted 21 lines
migration.c +10 -0
         if (blk_mig_active()) {
             info->has_disk = true;
@@ -169,6 +182,16 @@ MigrationInfo *qmp_query_migrate(Error **errp)
             info->disk->remaining = blk_mig_bytes_remaining();
             info->disk->total = blk_mig_bytes_total();
         }
+
+        if (migrate_use_xbzrle()) {
+            info->has_cache = true;
+            info->cache = g_malloc0(sizeof(*info->cache));
+            info->cache->cache_size = migrate_xbzrle_cache_size();
+            info->cache->xbzrle_bytes = xbzrle_mig_bytes_transferred();
+            info->cache->xbzrle_pages = xbzrle_mig_pages_transferred();
+            info->cache->xbzrle_cache_miss = xbzrle_mig_pages_cache_miss();
+            info->cache->xbzrle_overflow = xbzrle_mig_pages_overflow();
+        }
         break;
     case MIG_STATE_COMPLETED:
         for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 215

Quoted 10 lines
migration.c +7 -0
@@ -183,6 +206,32 @@ MigrationInfo *qmp_query_migrate(Error **errp)
             info->capabilities->next = NULL;
         }
 
+        info->has_ram = true;
+        info->ram = g_malloc0(sizeof(*info->ram));
+        info->ram->transferred = ram_bytes_transferred();
+        info->ram->remaining = ram_bytes_remaining();
+        info->ram->total = ram_bytes_total();
+        info->ram->duplicate = dup_mig_pages_transferred();
+        info->ram->normal = norm_mig_pages_transferred();

This hunk is probably bad copy & paste, as this code already exists.

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 223

Quoted 8 lines
migration.c +8 -0
+
+        if (blk_mig_active()) {
+            info->has_disk = true;
+            info->disk = g_malloc0(sizeof(*info->disk));
+            info->disk->transferred = blk_mig_bytes_transferred();
+            info->disk->remaining = blk_mig_bytes_remaining();
+            info->disk->total = blk_mig_bytes_total();
+        }

Why are you doing this, bad copy & paste too?

Quoted 39 lines
migration.c +11 -0
+
+        if (migrate_use_xbzrle()) {
+            info->has_cache = true;
+            info->cache = g_malloc0(sizeof(*info->cache));
+            info->cache->cache_size = migrate_xbzrle_cache_size();
+            info->cache->xbzrle_bytes = xbzrle_mig_bytes_transferred();
+            info->cache->xbzrle_pages = xbzrle_mig_pages_transferred();
+            info->cache->xbzrle_cache_miss = xbzrle_mig_pages_cache_miss();
+            info->cache->xbzrle_overflow = xbzrle_mig_pages_overflow();
+        }
+
         info->has_status = true;
         info->status = g_strdup("completed");
 
migration.h +9 -0
index 337e225..a9852fc 100644
@@ -87,6 +87,15 @@ uint64_t ram_bytes_total(void);
 
 extern SaveVMHandlers savevm_ram_handlers;
 
+uint64_t dup_mig_bytes_transferred(void);
+uint64_t dup_mig_pages_transferred(void);
+uint64_t norm_mig_bytes_transferred(void);
+uint64_t norm_mig_pages_transferred(void);
+uint64_t xbzrle_mig_bytes_transferred(void);
+uint64_t xbzrle_mig_pages_transferred(void);
+uint64_t xbzrle_mig_pages_overflow(void);
+uint64_t xbzrle_mig_pages_cache_miss(void);
+
 /**
  * @migrate_add_blocker - prevent migration from proceeding
  *
qapi-schema.json +0 -0
index a0f0f95..961810b 100644

qapi-schema.json line 271

Quoted 9 lines
qapi-schema.json +5 -1
@@ -264,11 +264,35 @@
 #        migration has ended, it returns the total migration
 #        time. (since 1.2)
 #
-# Since: 0.14.0.
+# @duplicate: #optional, number of duplicate pages
+#
+# @normal : #optional, number of normal pages
+#
+# Since: 0.14.0, 'duplicate' and 'normal' since 1.2

Please, put 'since' in the same line of the field, like this:

@normal : #optional, number of normal pages (since 1.2)

qapi-schema.json line 277

Quoted 7 lines
qapi-schema.json +3 -1
 ##
 { 'type': 'MigrationStats',
   'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' ,
-           'total_time': 'int' } }
+           'total_time': 'int', '*duplicate': 'int', '*normal': 'int' } }
+##
+# @CacheStats

This is specific to xbzrle, right? So this should be called XBZRLECacheStats, or something.

Quoted 22 lines
qapi-schema.json +18 -0
+#
+# Detailed XBZRLE migration cache statistics
+#
+# @cache_size: XBZRLE cache size
+#
+# @xbzrle_bytes: amount of bytes already transferred to the target VM
+#
+# @xbzrle_pages: amount of pages transferred to the target VM
+#
+# @xbzrle_cache_miss: number of cache miss
+#
+# @xbzrle_overflow: number of overflows
+#
+# Since: 1.2
+##
+{ 'type': 'CacheStats',
+  'data': {'cache-size': 'int', 'xbzrle-bytes': 'int', 'xbzrle-pages': 'int',
+           'xbzrle-cache-miss': 'int', 'xbzrle-overflow': 'int' } }
 
 ##
 # @MigrationInfo

qapi-schema.json line 319

Quoted 6 lines
qapi-schema.json +2 -1
@@ -291,13 +315,16 @@
 # @capabilities: #optional a list describing all the migration capabilities
 #                state
 #
-# Since: 0.14.0, 'capabilities' since 1.2
+# @cache: #optional @MigrationStats containing detailed XBZRLE migration
+#         statistics

xbzrle-cache.

Quoted 76 lines
qapi-schema.json +4 -2
+#
+# Since: 0.14.0, 'capabilities' and 'cache' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
            '*disk': 'MigrationStats',
-           '*capabilities': ['MigrationCapabilityInfo']} }
-
+           '*capabilities': ['MigrationCapabilityInfo'],
+           '*cache': 'CacheStats'} }
 ##
 # @query-migrate
 #
qmp-commands.hx +34 -1
index a3d57ce..34d4675 100644
@@ -2093,6 +2093,8 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
+	 - "duplicate": number of duplicated pages (json-int)
+	 - "normal" : number of normal pages transferred (json-int)
 - "disk": only present if "status" is "active" and it is a block migration,
   it is a json-object with the following disk information (in bytes):
          - "transferred": amount transferred (json-int)
@@ -2100,10 +2102,17 @@ The main json-object contains the following:
          - "total": total (json-int)
 - "capabilities": migration capabilities state
          - "xbzrle" : XBZRLE state (json-bool)
+- "cache": only present if "status" and XBZRLE is active.
+  It is a json-object with the following XBZRLE information:
+         - "cache-size": XBZRLE cache size
+         - "xbzrle-bytes": total XBZRLE bytes transferred
+         - "xbzrle-pages": number of XBZRLE compressed pages
+         - "cache-miss": number of cache misses
+         - "overflow": number of XBZRLE overflows
+
 Examples:
 
 1. Before the first migration
-
 -> { "execute": "query-migrate" }
 <- { "return": {
         "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
@@ -2164,6 +2173,30 @@ Examples:
       }
    }
 
+6. Migration is being performed and XBZRLE is active:
+
+-> { "execute": "query-migrate" }
+<- {
+      "return":{
+         "status":"active",
+         "capabilities" : [ { "capability": "xbzrle", "state" : true } ],
+         "ram":{
+            "total":1057024,
+            "remaining":1053304,
+            "transferred":3720,
+            "duplicate": 10,
+            "normal" : 3333
+         },
+         "cache":{
+            "cache-size": 1024
+            "xbzrle-transferred":20971520,
+            "xbzrle-pages":2444343,
+            "xbzrle-cache-miss":2244,
+            "xbzrle-overflow":34434
+         }
+      }
+   }
+
 EQMP
 
     {
#33 lore raw

Re: [Qemu-devel] [PATCH 21/22] Add XBZRLE statistics

Quoted 184 lines · Luiz Capitulino
Quoted 181 lines · On Fri, 13 Jul 2012 09:23:43 +0200 Juan Quintela <[email protected]> wrote:

From: Orit Wasserman <[email protected]>

---
 arch_init.c      |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.c            |   13 +++++++++++
 migration.c      |   49 ++++++++++++++++++++++++++++++++++++++++
 migration.h      |    9 ++++++++
 qapi-schema.json |   37 +++++++++++++++++++++++++-----
 qmp-commands.hx  |   35 ++++++++++++++++++++++++++++-
 6 files changed, 203 insertions(+), 6 deletions(-)
arch_init.c +66 -0
index d972d84..ab3fb2c 100644
@@ -202,6 +202,64 @@ int64_t xbzrle_cache_resize(int64_t new_size)
     return pow2floor(new_size);
 }
 
+/* accounting for migration statistics */
+typedef struct AccountingInfo {
+    uint64_t dup_pages;
+    uint64_t norm_pages;
+    uint64_t xbzrle_bytes;
+    uint64_t xbzrle_pages;
+    uint64_t xbzrle_cache_miss;
+    uint64_t iterations;
+    uint64_t xbzrle_overflows;
+} AccountingInfo;
+
+static AccountingInfo acct_info;
+
+static void acct_clear(void)
+{
+    memset(&acct_info, 0, sizeof(acct_info));
+}
+
+uint64_t dup_mig_bytes_transferred(void)
+{
+    return acct_info.dup_pages * TARGET_PAGE_SIZE;
+}
+
+uint64_t dup_mig_pages_transferred(void)
+{
+    return acct_info.dup_pages;
+}
+
+uint64_t norm_mig_bytes_transferred(void)
+{
+    return acct_info.norm_pages * TARGET_PAGE_SIZE;
+}
+
+uint64_t norm_mig_pages_transferred(void)
+{
+    return acct_info.norm_pages;
+}
+
+uint64_t xbzrle_mig_bytes_transferred(void)
+{
+    return acct_info.xbzrle_bytes;
+}
+
+uint64_t xbzrle_mig_pages_transferred(void)
+{
+    return acct_info.xbzrle_pages;
+}
+
+uint64_t xbzrle_mig_pages_cache_miss(void)
+{
+    return acct_info.xbzrle_cache_miss;
+}
+
+uint64_t xbzrle_mig_pages_overflow(void)
+{
+    return acct_info.xbzrle_overflows;
+}
+
 static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
         int cont, int flag)
 {
@@ -230,6 +288,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
     if (!cache_is_cached(XBZRLE.cache, current_addr)) {
         cache_insert(XBZRLE.cache, current_addr,
                      g_memdup(current_data, TARGET_PAGE_SIZE));
+        acct_info.xbzrle_cache_miss++;
         return -1;
     }
 
@@ -244,6 +303,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
         return 0;
     } else if (encoded_len == -1) {
         DPRINTF("Overflow\n");
+        acct_info.xbzrle_overflows++;
         /* update data in the cache */
         memcpy(prev_cached_page, current_data, TARGET_PAGE_SIZE);
         return -1;
@@ -263,7 +323,9 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
     qemu_put_byte(f, hdr.xh_flags);
     qemu_put_be16(f, hdr.xh_len);
     qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
+    acct_info.xbzrle_pages++;
     bytes_sent = encoded_len + sizeof(hdr);
+    acct_info.xbzrle_bytes += bytes_sent;
 
     return bytes_sent;
 }
@@ -303,6 +365,7 @@ static int ram_save_block(QEMUFile *f)
             p = memory_region_get_ram_ptr(mr) + offset;
 
             if (is_dup_page(p)) {
+                acct_info.dup_pages++;
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
                 qemu_put_byte(f, *p);
                 bytes_sent = 1;
@@ -318,6 +381,7 @@ static int ram_save_block(QEMUFile *f)
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
                 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
                 bytes_sent = TARGET_PAGE_SIZE;
+                acct_info.norm_pages++;
             }
 
             /* if page is unmodified, continue to the next */
@@ -437,6 +501,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
             return -1;
         }
         XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
+        acct_clear();
     }
 
     QLIST_FOREACH(block, &ram_list.blocks, next) {
@@ -484,6 +549,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
             break;
         }
         bytes_transferred += bytes_sent;
+        acct_info.iterations++;
         /* we want to check in the 1st loop, just in case it was the 1st time
            and we had to sync the dirty bitmap.
            qemu_get_clock_ns() is a bit expensive, so we only check each some
hmp.c +13 -0
index 99ad00a..0d7333b 100644
@@ -168,6 +168,19 @@ void hmp_info_migrate(Monitor *mon)
                        info->disk->total >> 10);
     }
 
+    if (info->has_cache) {
+        monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
+                       info->cache->cache_size);
+        monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
+                       info->cache->xbzrle_bytes >> 10);
+        monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
+                       info->cache->xbzrle_pages);
+        monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
+                       info->cache->xbzrle_cache_miss);
+        monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
+                       info->cache->xbzrle_overflow);
+    }
+
     qapi_free_MigrationInfo(info);
 }
 
migration.c +6 -0
index d134bf6..e11f451 100644
@@ -137,6 +137,17 @@ MigrationInfo *qmp_query_migrate(Error **errp)
             info->capabilities->value->state = s->enabled_capabilities[i];
             info->capabilities->next = NULL;
         }
+
+        /* display xbzrle cache size */
+        if (migrate_use_xbzrle()) {
+            info->has_cache = true;
+            info->cache = g_malloc0(sizeof(*info->cache));
+            info->cache->cache_size = migrate_xbzrle_cache_size();
Quoted 8 lines

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 150

Quoted 5 lines
migration.c +5 -0
+            info->cache->xbzrle_bytes = xbzrle_mig_bytes_transferred();
+            info->cache->xbzrle_pages = xbzrle_mig_pages_transferred();
+            info->cache->xbzrle_cache_miss = xbzrle_mig_pages_cache_miss();
+            info->cache->xbzrle_overflow = xbzrle_mig_pages_overflow();
+        }

Why do you need this in MIG_STATE_SETUP? I think having it only in MIG_STATE_ACTIVE is enough (and probably that's what we want).

you are right we just need the cache size (which can be set before the migration).

Quoted 12 lines

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 176

Quoted 10 lines
migration.c +2 -0
         break;
     case MIG_STATE_ACTIVE:
         for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
@@ -161,6 +172,8 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         info->ram->total = ram_bytes_total();
         info->ram->total_time = qemu_get_clock_ms(rt_clock)
             - s->total_time;
+        info->ram->duplicate = dup_mig_pages_transferred();
+        info->ram->normal = norm_mig_pages_transferred();

Can we do this extension in a different patch?

ok

Quoted 25 lines
Quoted 25 lines
migration.c +10 -0
         if (blk_mig_active()) {
             info->has_disk = true;
@@ -169,6 +182,16 @@ MigrationInfo *qmp_query_migrate(Error **errp)
             info->disk->remaining = blk_mig_bytes_remaining();
             info->disk->total = blk_mig_bytes_total();
         }
+
+        if (migrate_use_xbzrle()) {
+            info->has_cache = true;
+            info->cache = g_malloc0(sizeof(*info->cache));
+            info->cache->cache_size = migrate_xbzrle_cache_size();
+            info->cache->xbzrle_bytes = xbzrle_mig_bytes_transferred();
+            info->cache->xbzrle_pages = xbzrle_mig_pages_transferred();
+            info->cache->xbzrle_cache_miss = xbzrle_mig_pages_cache_miss();
+            info->cache->xbzrle_overflow = xbzrle_mig_pages_overflow();
+        }
         break;
     case MIG_STATE_COMPLETED:
         for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
@@ -183,6 +206,32 @@ MigrationInfo *qmp_query_migrate(Error **errp)
             info->capabilities->next = NULL;
         }
 
Quoted 9 lines

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 215

Quoted 7 lines
migration.c +7 -0
+        info->has_ram = true;
+        info->ram = g_malloc0(sizeof(*info->ram));
+        info->ram->transferred = ram_bytes_transferred();
+        info->ram->remaining = ram_bytes_remaining();
+        info->ram->total = ram_bytes_total();
+        info->ram->duplicate = dup_mig_pages_transferred();
+        info->ram->normal = norm_mig_pages_transferred();

This hunk is probably bad copy & paste, as this code already exists.

looks like a bad merge I will remove it

Quoted 11 lines

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 223

Quoted 9 lines
migration.c +8 -0
+
+        if (blk_mig_active()) {
+            info->has_disk = true;
+            info->disk = g_malloc0(sizeof(*info->disk));
+            info->disk->transferred = blk_mig_bytes_transferred();
+            info->disk->remaining = blk_mig_bytes_remaining();
+            info->disk->total = blk_mig_bytes_total();
+        }

Why are you doing this, bad copy & paste too?

looks like a bad merge I will remove it

Quoted 52 lines
Quoted 40 lines
migration.c +11 -0
+
+        if (migrate_use_xbzrle()) {
+            info->has_cache = true;
+            info->cache = g_malloc0(sizeof(*info->cache));
+            info->cache->cache_size = migrate_xbzrle_cache_size();
+            info->cache->xbzrle_bytes = xbzrle_mig_bytes_transferred();
+            info->cache->xbzrle_pages = xbzrle_mig_pages_transferred();
+            info->cache->xbzrle_cache_miss = xbzrle_mig_pages_cache_miss();
+            info->cache->xbzrle_overflow = xbzrle_mig_pages_overflow();
+        }
+
         info->has_status = true;
         info->status = g_strdup("completed");
 
migration.h +9 -0
index 337e225..a9852fc 100644
@@ -87,6 +87,15 @@ uint64_t ram_bytes_total(void);
 
 extern SaveVMHandlers savevm_ram_handlers;
 
+uint64_t dup_mig_bytes_transferred(void);
+uint64_t dup_mig_pages_transferred(void);
+uint64_t norm_mig_bytes_transferred(void);
+uint64_t norm_mig_pages_transferred(void);
+uint64_t xbzrle_mig_bytes_transferred(void);
+uint64_t xbzrle_mig_pages_transferred(void);
+uint64_t xbzrle_mig_pages_overflow(void);
+uint64_t xbzrle_mig_pages_cache_miss(void);
+
 /**
  * @migrate_add_blocker - prevent migration from proceeding
  *
qapi-schema.json +0 -0
index a0f0f95..961810b 100644

qapi-schema.json line 271

Quoted 9 lines
qapi-schema.json +5 -1
@@ -264,11 +264,35 @@
 #        migration has ended, it returns the total migration
 #        time. (since 1.2)
 #
-# Since: 0.14.0.
+# @duplicate: #optional, number of duplicate pages
+#
+# @normal : #optional, number of normal pages
+#
+# Since: 0.14.0, 'duplicate' and 'normal' since 1.2

Please, put 'since' in the same line of the field, like this:

Quoted 1 line

@normal : #optional, number of normal pages (since 1.2)

ok

Quoted 11 lines

qapi-schema.json line 277

Quoted 8 lines
qapi-schema.json +3 -1
 ##
 { 'type': 'MigrationStats',
   'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' ,
-           'total_time': 'int' } }
+           'total_time': 'int', '*duplicate': 'int', '*normal': 'int' } }
+##
+# @CacheStats

This is specific to xbzrle, right? So this should be called XBZRLECacheStats, or something.

sure

Quoted 20 lines
Quoted 20 lines
qapi-schema.json +18 -0
+#
+# Detailed XBZRLE migration cache statistics
+#
+# @cache_size: XBZRLE cache size
+#
+# @xbzrle_bytes: amount of bytes already transferred to the target VM
+#
+# @xbzrle_pages: amount of pages transferred to the target VM
+#
+# @xbzrle_cache_miss: number of cache miss
+#
+# @xbzrle_overflow: number of overflows
+#
+# Since: 1.2
+##
+{ 'type': 'CacheStats',
+  'data': {'cache-size': 'int', 'xbzrle-bytes': 'int', 'xbzrle-pages': 'int',
+           'xbzrle-cache-miss': 'int', 'xbzrle-overflow': 'int' } }
 
Quoted 11 lines

qapi-schema.json line 319

Quoted 9 lines
qapi-schema.json +2 -1
 ##
 # @MigrationInfo
@@ -291,13 +315,16 @@
 # @capabilities: #optional a list describing all the migration capabilities
 #                state
 #
-# Since: 0.14.0, 'capabilities' since 1.2
+# @cache: #optional @MigrationStats containing detailed XBZRLE migration
+#         statistics

xbzrle-cache.

ok

Thanks,
Orit

Quoted 78 lines
Quoted 77 lines
qapi-schema.json +4 -2
+#
+# Since: 0.14.0, 'capabilities' and 'cache' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
            '*disk': 'MigrationStats',
-           '*capabilities': ['MigrationCapabilityInfo']} }
-
+           '*capabilities': ['MigrationCapabilityInfo'],
+           '*cache': 'CacheStats'} }
 ##
 # @query-migrate
 #
qmp-commands.hx +34 -1
index a3d57ce..34d4675 100644
@@ -2093,6 +2093,8 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
+	 - "duplicate": number of duplicated pages (json-int)
+	 - "normal" : number of normal pages transferred (json-int)
 - "disk": only present if "status" is "active" and it is a block migration,
   it is a json-object with the following disk information (in bytes):
          - "transferred": amount transferred (json-int)
@@ -2100,10 +2102,17 @@ The main json-object contains the following:
          - "total": total (json-int)
 - "capabilities": migration capabilities state
          - "xbzrle" : XBZRLE state (json-bool)
+- "cache": only present if "status" and XBZRLE is active.
+  It is a json-object with the following XBZRLE information:
+         - "cache-size": XBZRLE cache size
+         - "xbzrle-bytes": total XBZRLE bytes transferred
+         - "xbzrle-pages": number of XBZRLE compressed pages
+         - "cache-miss": number of cache misses
+         - "overflow": number of XBZRLE overflows
+
 Examples:
 
 1. Before the first migration
-
 -> { "execute": "query-migrate" }
 <- { "return": {
         "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
@@ -2164,6 +2173,30 @@ Examples:
       }
    }
 
+6. Migration is being performed and XBZRLE is active:
+
+-> { "execute": "query-migrate" }
+<- {
+      "return":{
+         "status":"active",
+         "capabilities" : [ { "capability": "xbzrle", "state" : true } ],
+         "ram":{
+            "total":1057024,
+            "remaining":1053304,
+            "transferred":3720,
+            "duplicate": 10,
+            "normal" : 3333
+         },
+         "cache":{
+            "cache-size": 1024
+            "xbzrle-transferred":20971520,
+            "xbzrle-pages":2444343,
+            "xbzrle-cache-miss":2244,
+            "xbzrle-overflow":34434
+         }
+      }
+   }
+
 EQMP
 
     {
#34 lore raw

PATCH 22/22 ram: save live optimization

In reply to Juan Quintela

Optimize stage3 (complete), to use the page cached if it is there, but not update the cache with new pages (they will never be reused).

---
 arch_init.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
arch_init.c +8 -6
index ab3fb2c..de2d801 100644
@@ -276,7 +276,7 @@ static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
 
 static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
                             ram_addr_t current_addr, RAMBlock *block,
-                            ram_addr_t offset, int cont)
+                            ram_addr_t offset, int cont, bool last_stage)
 {
     int encoded_len = 0, bytes_sent = -1, ret = -1;
     XBZRLEHeader hdr = {
@@ -341,7 +341,7 @@ static ram_addr_t last_offset;
  *           n: the amount of bytes written in other case
  */
 
-static int ram_save_block(QEMUFile *f)
+static int ram_save_block(QEMUFile *f, bool last_stage)
 {
     RAMBlock *block = last_block;
     ram_addr_t offset = last_offset;
@@ -372,8 +372,10 @@ static int ram_save_block(QEMUFile *f)
             } else if (migrate_use_xbzrle()) {
                 current_addr = block->offset + offset;
                 bytes_sent = save_xbzrle_page(f, p, current_addr, block,
-                                              offset, cont);
-                p = get_cached_data(XBZRLE.cache, current_addr);
+                                              offset, cont, last_stage);
+                if ((bytes_sent != -1) || !last_stage) {
+                    p = get_cached_data(XBZRLE.cache, current_addr);
+                }
             }
 
             /* either we didn't send yet (we may have had XBZRLE overflow) */
@@ -543,7 +545,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
     while ((ret = qemu_file_rate_limit(f)) == 0) {
         int bytes_sent;
 
-        bytes_sent = ram_save_block(f);
+        bytes_sent = ram_save_block(f, false);
         /* no more blocks to sent */
         if (bytes_sent < 0) {
             break;
@@ -605,7 +607,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
     while (true) {
         int bytes_sent;
 
-        bytes_sent = ram_save_block(f);
+        bytes_sent = ram_save_block(f, true);
         /* no more blocks to sent */
         if (bytes_sent < 0) {
             break;
Signature · 1 line
1.7.10.4