Skip to contentSkip to conversation

Remove old MigrationParams

PATCH Superseded Juan Quintela 3 participants 18 messages May 16, 2017

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Remove old MigrationParams

changes from v3

- patch 1 included again. We have a 'block' capability and a 'block_incremental' parameter
Make Dave happy: rename shared into incremental Make Eric and Markus happy:

    block: off -> no block migration, we don't care about
                  block_incremental value
    block: on block_incremental: off -> no incremental block migration
    block: on block_incremental: on  -> incremental block migration

- Use visitors.
You ask if there is not a better way than hand coding a boolean parser. QAPI people (a.k.a. Markus) answer to use a visitor.
Once there, I used it also for integers, not only booleans.

- Use -b/-i parameters. OK, I bit the bullet: You can't use capabilities/parameters and -b/-i: it gives you one error If you use -b/-i, capability parameter is cleanup after the migration ends (Who would have guessed that there are cases where we call migration_fd_error(), but not migration_fd_cleanup()
I think this should make Peter and Markus and Dave happy.

- Integrate migrate block compile time disabling
Well, it conflicted left and right, so I fixed it
Once there, I disable setting/getting block capability if it is disabled.

Please review.

[v3]

- Patch 1 included in pull request
- disable block_shared when we disable block_enable
- enable block_enabled when we enable block_shared

Please, review.

[v2]

- make migrate_block_set_* take a boolean
- disable block migration in colo to maintain semantics.

[v1]
Upon a time there were MigrationParms (only used for block migration) and then MigrationParams used for everything else. This series:

- create migration capabilities for block parameters
- make the migrate command line parameters to use capabilities
- remove MigrationParams completely

Dr. David Alan Gilbert (1):
block migration: Allow compile time disable

Juan Quintela (4):
hmp: Use visitor api for hmp_migrate_set_parameter()
migration: Create block capability
migration: Remove use of old MigrationParams
migration: Remove old MigrationParams

 configure                     |  11 +++++
 hmp.c                         |  23 +++++++--
 include/migration/block.h     |  24 +++++++++
 include/migration/migration.h |  18 +++----
 include/migration/vmstate.h   |   1 -
 include/qemu/typedefs.h       |   1 -
 include/sysemu/sysemu.h       |   3 +-
 migration/Makefile.objs       |   2 +-
 migration/block.c             |  17 +------
 migration/colo.c              |   6 +--
 migration/migration.c         | 112 +++++++++++++++++++++++++++++++++++++++---
 migration/savevm.c            |  24 ++++-----
 qapi-schema.json              |  14 ++++--
 13 files changed, 194 insertions(+), 62 deletions(-)
Signature · 1 line
2.9.3
#1 lore raw

PATCH v4 1/5 hmp: Use visitor api for hmp_migrate_set_parameter()

We only use it for int64 at this point, I am not able to find a way to parse an int with MiB units.

---
 hmp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hmp.c +6 -4
index b9dd933..acbbc5c 100644
@@ -29,6 +29,7 @@
 #include "monitor/qdev.h"
 #include "qapi/opts-visitor.h"
 #include "qapi/qmp/qerror.h"
+#include "qapi/string-input-visitor.h"
 #include "qapi/string-output-visitor.h"
 #include "qapi/util.h"
 #include "qapi-visit.h"
@@ -1523,8 +1524,9 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
 {
     const char *param = qdict_get_str(qdict, "parameter");
     const char *valuestr = qdict_get_str(qdict, "value");
+    Visitor *v = string_input_visitor_new(valuestr);
     uint64_t valuebw = 0;
-    long valueint = 0;
+    int64_t valueint = 0;
     Error *err = NULL;
     bool use_int_value = false;
     int i, ret;
@@ -1582,9 +1584,8 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
             }
 
             if (use_int_value) {
-                if (qemu_strtol(valuestr, NULL, 10, &valueint) < 0) {
-                    error_setg(&err, "Unable to parse '%s' as an int",
-                               valuestr);
+                visit_type_int(v, param, &valueint, &err);
+                if (err) {
                     goto cleanup;
                 }
                 /* Set all integers; only one has_FOO will be set, and
@@ -1608,6 +1609,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     }
 
  cleanup:
+    visit_free(v);
     if (err) {
         error_report_err(err);
     }
Signature · 1 line
2.9.3
Reviewed-by on v4 1/5
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] hmp: Use visitor api for hmp_migrate_set_parameter()

Quoted 2 lines · Juan Quintela

We only use it for int64 at this point, I am not able to find a way to parse an int with MiB units.

Use the string input visitor and visit_type_size() to parse with unit suffixes. The problem is hmp_migrate_set_parameter() wants "no suffix" to mean "mebibytes", which the string input visitor can't do. Good for new code, because it helps keeping things consistent. Not so good for converting existing code.

Quoted 29 lines
---
 hmp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hmp.c +3 -1
index b9dd933..acbbc5c 100644
@@ -29,6 +29,7 @@
 #include "monitor/qdev.h"
 #include "qapi/opts-visitor.h"
 #include "qapi/qmp/qerror.h"
+#include "qapi/string-input-visitor.h"
 #include "qapi/string-output-visitor.h"
 #include "qapi/util.h"
 #include "qapi-visit.h"
@@ -1523,8 +1524,9 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
 {
     const char *param = qdict_get_str(qdict, "parameter");
     const char *valuestr = qdict_get_str(qdict, "value");
+    Visitor *v = string_input_visitor_new(valuestr);
     uint64_t valuebw = 0;
-    long valueint = 0;
+    int64_t valueint = 0;
     Error *err = NULL;
     bool use_int_value = false;
     int i, ret;

hmp.c void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) · line 1587

Quoted 7 lines
hmp.c +1 -3
@@ -1582,9 +1584,8 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
             }
 
             if (use_int_value) {
-                if (qemu_strtol(valuestr, NULL, 10, &valueint) < 0) {
-                    error_setg(&err, "Unable to parse '%s' as an int",
-                               valuestr);
+                visit_type_int(v, param, &valueint, &err);

I figure the error message changes from

Unable to parse 'PARAM' as an int

to

Parameter 'PARAM' expects an int64 value or range

The "or range" part is due to the string input visitor's support for integer list, which is basically horrible.

hmp.c void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) · line 1615

Quoted 12 lines
hmp.c +2 -0
+                if (err) {
                     goto cleanup;
                 }
                 /* Set all integers; only one has_FOO will be set, and
@@ -1608,6 +1609,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     }
 
  cleanup:
+    visit_free(v);
     if (err) {
         error_report_err(err);
     }
#3 lore raw

PATCH v4 2/5 migration: Create block capability

In reply to Juan Quintela

Create one capability for block migration and one parameter for incremental block migration.

---
 hmp.c                         | 13 +++++++
 include/migration/block.h     |  2 +
 include/migration/migration.h |  7 ++++
 migration/migration.c         | 88 +++++++++++++++++++++++++++++++++++++++++++
 qapi-schema.json              | 14 +++++--
 5 files changed, 121 insertions(+), 3 deletions(-)
hmp.c +13 -0
index acbbc5c..208154c 100644
@@ -326,6 +326,10 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "%s: %" PRId64 "\n",
             MigrationParameter_lookup[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY],
             params->x_checkpoint_delay);
+        assert(params->has_block_incremental);
+        monitor_printf(mon, "%s: %s\n",
+            MigrationParameter_lookup[MIGRATION_PARAMETER_BLOCK_INCREMENTAL],
+                       params->block_incremental ? "on" : "off");
     }
 
     qapi_free_MigrationParameters(params);
@@ -1527,6 +1531,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     Visitor *v = string_input_visitor_new(valuestr);
     uint64_t valuebw = 0;
     int64_t valueint = 0;
+    bool valuebool = false;
     Error *err = NULL;
     bool use_int_value = false;
     int i, ret;
@@ -1581,6 +1586,14 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
                 p.has_x_checkpoint_delay = true;
                 use_int_value = true;
                 break;
+            case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
+                p.has_block_incremental = true;
+                visit_type_bool(v, param, &valuebool, &err);
+                if (err) {
+                    goto cleanup;
+                }
+                p.block_incremental = valuebool;
+                break;
             }
 
             if (use_int_value) {
include/migration/block.h +2 -0
index 41a1ac8..5225af9 100644
@@ -20,4 +20,6 @@ uint64_t blk_mig_bytes_transferred(void);
 uint64_t blk_mig_bytes_remaining(void);
 uint64_t blk_mig_bytes_total(void);
 
+void migrate_set_block_enabled(bool value, Error **errp);
+
 #endif /* MIGRATION_BLOCK_H */
include/migration/migration.h +7 -0
index 47262bd..adcb8f6 100644
@@ -179,6 +179,10 @@ struct MigrationState
 
     /* The last error that occurred */
     Error *error;
+    /* Do we have to clean up -b/-i from old migrate paramteres */
+    /* This feature is deprecated and will be removed */
+    bool must_remove_block;
+    bool must_remove_block_incremental;
 };
 
 void migrate_set_state(int *state, int old_state, int new_state);
@@ -293,6 +297,9 @@ bool migrate_colo_enabled(void);
 
 int64_t xbzrle_cache_resize(int64_t new_size);
 
+bool migrate_use_block(void);
+bool migrate_use_block_incremental(void);
+
 bool migrate_use_compression(void);
 int migrate_compress_level(void);
 int migrate_compress_threads(void);
migration/migration.c +88 -0

142 lines not on this page · raw message

qapi-schema.json +11 -3
index 5728b7f..62246bc 100644
@@ -894,11 +894,14 @@
 # @release-ram: if enabled, qemu will free the migrated ram pages on the source
 #        during postcopy-ram migration. (since 2.9)
 #
+# @block: enable block migration (Since 2.10)
+#
 # Since: 1.2
 ##
 { 'enum': 'MigrationCapability',
   'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks',
-           'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram'] }
+           'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram',
+           'block' ] }
 
 ##
 # @MigrationCapabilityStatus:
@@ -1009,13 +1012,15 @@
 # @x-checkpoint-delay: The delay time (in ms) between two COLO checkpoints in
 #          periodic mode. (Since 2.8)
 #
+# @block-incremental: enable block incremental migration (Since 2.10)
+#
 # Since: 2.4
 ##
 { 'enum': 'MigrationParameter',
   'data': ['compress-level', 'compress-threads', 'decompress-threads',
            'cpu-throttle-initial', 'cpu-throttle-increment',
            'tls-creds', 'tls-hostname', 'max-bandwidth',
-           'downtime-limit', 'x-checkpoint-delay' ] }
+           'downtime-limit', 'x-checkpoint-delay', 'block-incremental' ] }
 
 ##
 # @migrate-set-parameters:
@@ -1082,6 +1087,8 @@
 #
 # @x-checkpoint-delay: the delay time between two COLO checkpoints. (Since 2.8)
 #
+# @block-incremental: enable block incremental migration (Since 2.10)
+#
 # Since: 2.4
 ##
 { 'struct': 'MigrationParameters',
@@ -1094,7 +1101,8 @@
             '*tls-hostname': 'str',
             '*max-bandwidth': 'int',
             '*downtime-limit': 'int',
-            '*x-checkpoint-delay': 'int'} }
+            '*x-checkpoint-delay': 'int',
+            '*block-incremental': 'bool' } }
 
 ##
 # @query-migrate-parameters:
Signature · 1 line
2.9.3
#4 lore raw

Re: [Qemu-devel] [PATCH 2/5] migration: Create block capability

Quoted 66 lines · Juan Quintela

Create one capability for block migration and one parameter for incremental block migration.

---
 hmp.c                         | 13 +++++++
 include/migration/block.h     |  2 +
 include/migration/migration.h |  7 ++++
 migration/migration.c         | 88 +++++++++++++++++++++++++++++++++++++++++++
 qapi-schema.json              | 14 +++++--
 5 files changed, 121 insertions(+), 3 deletions(-)
hmp.c +13 -0
index acbbc5c..208154c 100644
@@ -326,6 +326,10 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "%s: %" PRId64 "\n",
             MigrationParameter_lookup[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY],
             params->x_checkpoint_delay);
+        assert(params->has_block_incremental);
+        monitor_printf(mon, "%s: %s\n",
+            MigrationParameter_lookup[MIGRATION_PARAMETER_BLOCK_INCREMENTAL],
+                       params->block_incremental ? "on" : "off");
     }
 
     qapi_free_MigrationParameters(params);
@@ -1527,6 +1531,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     Visitor *v = string_input_visitor_new(valuestr);
     uint64_t valuebw = 0;
     int64_t valueint = 0;
+    bool valuebool = false;
     Error *err = NULL;
     bool use_int_value = false;
     int i, ret;
@@ -1581,6 +1586,14 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
                 p.has_x_checkpoint_delay = true;
                 use_int_value = true;
                 break;
+            case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
+                p.has_block_incremental = true;
+                visit_type_bool(v, param, &valuebool, &err);
+                if (err) {
+                    goto cleanup;
+                }
+                p.block_incremental = valuebool;
+                break;
             }
 
             if (use_int_value) {
include/migration/block.h +2 -0
index 41a1ac8..5225af9 100644
@@ -20,4 +20,6 @@ uint64_t blk_mig_bytes_transferred(void);
 uint64_t blk_mig_bytes_remaining(void);
 uint64_t blk_mig_bytes_total(void);
 
+void migrate_set_block_enabled(bool value, Error **errp);
+
 #endif /* MIGRATION_BLOCK_H */
include/migration/migration.h +0 -0
index 47262bd..adcb8f6 100644

include/migration/migration.h struct MigrationState · line 182

Quoted 4 lines
include/migration/migration.h +1 -0
@@ -179,6 +179,10 @@ struct MigrationState
 
     /* The last error that occurred */
     Error *error;
+    /* Do we have to clean up -b/-i from old migrate paramteres */

parameters

Quoted 40 lines
include/migration/migration.h +6 -0
+    /* This feature is deprecated and will be removed */
+    bool must_remove_block;
+    bool must_remove_block_incremental;
 };
 
 void migrate_set_state(int *state, int old_state, int new_state);
@@ -293,6 +297,9 @@ bool migrate_colo_enabled(void);
 
 int64_t xbzrle_cache_resize(int64_t new_size);
 
+bool migrate_use_block(void);
+bool migrate_use_block_incremental(void);
+
 bool migrate_use_compression(void);
 int migrate_compress_level(void);
 int migrate_compress_threads(void);
migration/migration.c +5 -0
index 5c92851..03f96df 100644
@@ -599,6 +599,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->downtime_limit = s->parameters.downtime_limit;
     params->has_x_checkpoint_delay = true;
     params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
+    params->has_block_incremental = true;
+    params->block_incremental = s->parameters.block_incremental;
 
     return params;
 }
@@ -907,6 +909,9 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
             colo_checkpoint_notify(s);
         }
     }
+    if (params->has_block_incremental) {
+        s->parameters.block_incremental = params->block_incremental;
+    }
 }
 
 

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 955

Quoted 9 lines
migration/migration.c +6 -0
@@ -942,6 +947,35 @@ void migrate_set_state(int *state, int old_state, int new_state)
     }
 }
 
+void migrate_set_block_enabled(bool value, Error **errp)
+{
+    MigrationCapabilityStatusList *cap;
+
+    cap = g_malloc0(sizeof(*cap));
+    cap->value = g_malloc(sizeof(*cap->value));

I prefer g_new() for extra type checking. Your choice.

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 960

Quoted 5 lines
migration/migration.c +5 -0
+    cap->value->capability = MIGRATION_CAPABILITY_BLOCK;
+    cap->value->state = value;
+    qmp_migrate_set_capabilities(cap, errp);
+    qapi_free_MigrationCapabilityStatusList(cap);
+}

The objective is to set one bit. The means is building a MigrationCapabilityStatusList. When you have to build an elaborate data structure just so you can set one bit, your interfaces are likely deficient. Observation, not change request.

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 965

Quoted 5 lines
migration/migration.c +5 -0
+
+static void migrate_set_block_incremental(MigrationState *s, bool value)
+{
+    s->parameters.block_incremental = value;
+}

This is how setting one bit should look like.

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 970

Quoted 5 lines
migration/migration.c +5 -0
+
+static void block_cleanup_parameters(MigrationState *s)
+{
+    if (s->must_remove_block) {
+        migrate_set_block_enabled(false, NULL);

NULL ignores errors. If an error happens, and we ignore it, we're screwed, aren't we? I suspect we want &error_abort here.

Quoted 44 lines
migration/migration.c +12 -0
+        s->must_remove_block = false;
+    }
+    if (s->must_remove_block_incremental) {
+        migrate_set_block_incremental(s, false);
+        s->must_remove_block_incremental = false;
+    }
+}
+
 static void migrate_fd_cleanup(void *opaque)
 {
     MigrationState *s = opaque;
@@ -974,6 +1008,7 @@ static void migrate_fd_cleanup(void *opaque)
     }
 
     notifier_list_notify(&migration_state_notifiers, s);
+    block_cleanup_parameters(s);
 }
 
 void migrate_fd_error(MigrationState *s, const Error *error)
@@ -986,6 +1021,7 @@ void migrate_fd_error(MigrationState *s, const Error *error)
         s->error = error_copy(error);
     }
     notifier_list_notify(&migration_state_notifiers, s);
+    block_cleanup_parameters(s);
 }
 
 static void migrate_fd_cancel(MigrationState *s)
@@ -1027,6 +1063,7 @@ static void migrate_fd_cancel(MigrationState *s)
             s->block_inactive = false;
         }
     }
+    block_cleanup_parameters(s);
 }
 
 void add_migration_state_change_notifier(Notifier *notify)
@@ -1209,6 +1246,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
     Error *local_err = NULL;
     MigrationState *s = migrate_get_current();
     MigrationParams params;
+    bool block_enabled = false;
     const char *p;
 
     params.blk = has_blk && blk;

migration/migration.c void qmp_migrate(const char *uri, bool has_blk, bool blk, · line 1272

Quoted 6 lines
migration/migration.c +3 -0
@@ -1229,6 +1267,38 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         return;
     }
 
+    if (has_blk && blk) {
+        if (migrate_use_block() || migrate_use_block_incremental()) {
+            error_setg(errp, "You can't use block capability and -b/i");

Error message assumes HMP. In QMP, the thing is called 'blk', not -b. Perhaps we can sidestep the issue like this: "Command options are incompatible with current migration capabilities".

Quoted 5 lines
migration/migration.c +5 -0
+            return;
+        }
+        migrate_set_block_enabled(true, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);

migration/migration.c void qmp_migrate(const char *uri, bool has_blk, bool blk, · line 1287

Quoted 10 lines
migration/migration.c +10 -0
+            return;
+        }
+        block_enabled = true;
+        s->must_remove_block = true;
+    }
+
+    if (has_inc && inc) {
+        if ((migrate_use_block() && !block_enabled)
+            || migrate_use_block_incremental()) {
+            error_setg(errp, "You can't use block capability and -b/i");

Likewise.

The condition would be slightly simpler if you completed error checking before changing global state. Matter of taste.

Quoted 47 lines
migration/migration.c +32 -0
+            return;
+        }
+        if (!block_enabled) {
+            migrate_set_block_enabled(true, &local_err);
+            if (local_err) {
+                error_propagate(errp, local_err);
+                return;
+            }
+            s->must_remove_block = true;
+        }
+        migrate_set_block_incremental(s, true);
+        s->must_remove_block_incremental = true;
+    }
+
     s = migrate_init(&params);
 
     if (strstart(uri, "tcp:", &p)) {
@@ -1426,6 +1496,24 @@ int64_t migrate_xbzrle_cache_size(void)
     return s->xbzrle_cache_size;
 }
 
+bool migrate_use_block(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_BLOCK];
+}
+
+bool migrate_use_block_incremental(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->parameters.block_incremental;
+}
+
 /* migration thread support */
 /*
  * Something bad happened to the RP stream, mark an error
qapi-schema.json +0 -0
index 5728b7f..62246bc 100644

qapi-schema.json line 898

Quoted 5 lines
qapi-schema.json +2 -0
@@ -894,11 +894,14 @@
 # @release-ram: if enabled, qemu will free the migrated ram pages on the source
 #        during postcopy-ram migration. (since 2.9)
 #
+# @block: enable block migration (Since 2.10)
+#

What's "block migration" and why should I care?

Quoted 11 lines
qapi-schema.json +2 -1
 # Since: 1.2
 ##
 { 'enum': 'MigrationCapability',
   'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks',
-           'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram'] }
+           'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram',
+           'block' ] }
 
 ##
 # @MigrationCapabilityStatus:

qapi-schema.json line 1016

Quoted 5 lines
qapi-schema.json +2 -0
@@ -1009,13 +1012,15 @@
 # @x-checkpoint-delay: The delay time (in ms) between two COLO checkpoints in
 #          periodic mode. (Since 2.8)
 #
+# @block-incremental: enable block incremental migration (Since 2.10)
+#

What's "block incremental migration" and why should I care?

Quoted 21 lines
qapi-schema.json +3 -1
 # Since: 2.4
 ##
 { 'enum': 'MigrationParameter',
   'data': ['compress-level', 'compress-threads', 'decompress-threads',
            'cpu-throttle-initial', 'cpu-throttle-increment',
            'tls-creds', 'tls-hostname', 'max-bandwidth',
-           'downtime-limit', 'x-checkpoint-delay' ] }
+           'downtime-limit', 'x-checkpoint-delay', 'block-incremental' ] }
 
 ##
 # @migrate-set-parameters:
@@ -1082,6 +1087,8 @@
 #
 # @x-checkpoint-delay: the delay time between two COLO checkpoints. (Since 2.8)
 #
+# @block-incremental: enable block incremental migration (Since 2.10)
+#
 # Since: 2.4
 ##
 { 'struct': 'MigrationParameters',

qapi-schema.json line 1108

Quoted 9 lines
qapi-schema.json +2 -1
@@ -1094,7 +1101,8 @@
             '*tls-hostname': 'str',
             '*max-bandwidth': 'int',
             '*downtime-limit': 'int',
-            '*x-checkpoint-delay': 'int'} }
+            '*x-checkpoint-delay': 'int',
+            '*block-incremental': 'bool' } }
 
 ##
 # @query-migrate-parameters:

Can't say I like the split between MigrationCapability and MigrationParameters, but we got to work with what we have.

#5 lore raw

Re: [Qemu-devel] [PATCH 2/5] migration: Create block capability

Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Juan Quintela

Create one capability for block migration and one parameter for incremental block migration.

Quoted 8 lines
Quoted 6 lines
     /* The last error that occurred */
     Error *error;

+ /* Do we have to clean up -b/-i from old migrate paramteres */

parameters

ok.

Quoted 8 lines

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 955

Quoted 6 lines
migration/migration.c +6 -0
+void migrate_set_block_enabled(bool value, Error **errp)
+{
+    MigrationCapabilityStatusList *cap;
+
+    cap = g_malloc0(sizeof(*cap));
+    cap->value = g_malloc(sizeof(*cap->value));

I prefer g_new() for extra type checking. Your choice.

ok.

Quoted 10 lines

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 960

Quoted 5 lines
migration/migration.c +5 -0
+    cap->value->capability = MIGRATION_CAPABILITY_BLOCK;
+    cap->value->state = value;
+    qmp_migrate_set_capabilities(cap, errp);
+    qapi_free_MigrationCapabilityStatusList(cap);
+}

The objective is to set one bit. The means is building a MigrationCapabilityStatusList. When you have to build an elaborate data structure just so you can set one bit, your interfaces are likely deficient. Observation, not change request.

This was Dave suggestion. The reason for doing this is in the following patch when we enable compile disable of block migration to put the ifdef in a single place. Otherwise, I have to put it in two places.

Quoted 6 lines

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 965

Quoted 4 lines
migration/migration.c +4 -0
+static void migrate_set_block_incremental(MigrationState *s, bool value)
+{
+    s->parameters.block_incremental = value;
+}

This is how setting one bit should look like.

See previous comment.

Quoted 9 lines

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 970

Quoted 6 lines
migration/migration.c +5 -0
+
+static void block_cleanup_parameters(MigrationState *s)
+{
+    if (s->must_remove_block) {
+        migrate_set_block_enabled(false, NULL);

NULL ignores errors. If an error happens, and we ignore it, we're screwed, aren't we? I suspect we want &error_abort here.

setting to false can't never fail. It is when we set it to true that it can fail because it is compiled out (that will be in next patch).

Quoted 11 lines

migration/migration.c void qmp_migrate(const char *uri, bool has_blk, bool blk, · line 1272

Quoted 7 lines
migration/migration.c +3 -0
@@ -1229,6 +1267,38 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         return;
     }
 
+    if (has_blk && blk) {
+        if (migrate_use_block() || migrate_use_block_incremental()) {
+            error_setg(errp, "You can't use block capability and -b/i");

Error message assumes HMP. In QMP, the thing is called 'blk', not -b. Perhaps we can sidestep the issue like this: "Command options are incompatible with current migration capabilities".

ok.

Quoted 17 lines
Quoted 6 lines
migration/migration.c +5 -0
+            return;
+        }
+        migrate_set_block_enabled(true, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);

migration/migration.c void qmp_migrate(const char *uri, bool has_blk, bool blk, · line 1287

Quoted 10 lines
migration/migration.c +10 -0
+            return;
+        }
+        block_enabled = true;
+        s->must_remove_block = true;
+    }
+
+    if (has_inc && inc) {
+        if ((migrate_use_block() && !block_enabled)
+            || migrate_use_block_incremental()) {
+            error_setg(errp, "You can't use block capability and -b/i");
Quoted 4 lines

Likewise.

The condition would be slightly simpler if you completed error checking before changing global state. Matter of taste.

Being bug compatible has this drawbacks. I also hate that -i implies -b.

Quoted 10 lines

qapi-schema.json line 898

Quoted 8 lines
qapi-schema.json +2 -0
@@ -894,11 +894,14 @@
 # @release-ram: if enabled, qemu will free the migrated ram pages on the source
 #        during postcopy-ram migration. (since 2.9)
 #
+# @block: enable block migration (Since 2.10)
+#

What's "block migration" and why should I care?

"enable migration of block devices. The granularity is all devices or no devices, nothing in the middle."

I will be happy with suggestions.

Quoted 9 lines
Quoted 9 lines
qapi-schema.json +2 -1
 # Since: 1.2
 ##
 { 'enum': 'MigrationCapability',
   'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks',
-           'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram'] }
+           'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram',
+           'block' ] }
 
Quoted 10 lines

qapi-schema.json line 1016

Quoted 8 lines
qapi-schema.json +2 -0
 ##
 # @MigrationCapabilityStatus:
@@ -1009,13 +1012,15 @@
 # @x-checkpoint-delay: The delay time (in ms) between two COLO checkpoints in
 #          periodic mode. (Since 2.8)
 #
+# @block-incremental: enable block incremental migration (Since 2.10)
+#

What's "block incremental migration" and why should I care?

This is good, I will try.

"block incremental migration assumes that we have a base image in both sides, and then we continue writting in one of the sides. This way we need to only migrate the changes since the previous state where it was the same in both sides".

I am not sure what to put there, really.

Quoted 29 lines
Quoted 29 lines
qapi-schema.json +5 -2
 # Since: 2.4
 ##
 { 'enum': 'MigrationParameter',
   'data': ['compress-level', 'compress-threads', 'decompress-threads',
            'cpu-throttle-initial', 'cpu-throttle-increment',
            'tls-creds', 'tls-hostname', 'max-bandwidth',
-           'downtime-limit', 'x-checkpoint-delay' ] }
+           'downtime-limit', 'x-checkpoint-delay', 'block-incremental' ] }
 
 ##
 # @migrate-set-parameters:
@@ -1082,6 +1087,8 @@
 #
 # @x-checkpoint-delay: the delay time between two COLO checkpoints. (Since 2.8)
 #
+# @block-incremental: enable block incremental migration (Since 2.10)
+#
 # Since: 2.4
 ##
 { 'struct': 'MigrationParameters',
@@ -1094,7 +1101,8 @@
             '*tls-hostname': 'str',
             '*max-bandwidth': 'int',
             '*downtime-limit': 'int',
-            '*x-checkpoint-delay': 'int'} }
+            '*x-checkpoint-delay': 'int',
+            '*block-incremental': 'bool' } }
 
Quoted 5 lines

qapi-schema.json line 1108

Quoted 2 lines
qapi-schema.json +0 -0
 ##
 # @query-migrate-parameters:

Can't say I like the split between MigrationCapability and MigrationParameters, but we got to work with what we have.

:-(

And it is still not good enough. There are parameters that make sense to change in middle migration (max-bandwidth for example) and others that you shouldn't, like tls-hostname or compression-threads.

Go figure.

Thanks, Juan.

#6 lore raw

Re: [Qemu-devel] [PATCH 2/5] migration: Create block capability

Quoted 64 lines · Juan Quintela
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Juan Quintela

Create one capability for block migration and one parameter for incremental block migration.

Quoted 8 lines
Quoted 6 lines
     /* The last error that occurred */
     Error *error;

+ /* Do we have to clean up -b/-i from old migrate paramteres */

parameters

ok.

Quoted 8 lines

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 955

Quoted 6 lines
migration/migration.c +6 -0
+void migrate_set_block_enabled(bool value, Error **errp)
+{
+    MigrationCapabilityStatusList *cap;
+
+    cap = g_malloc0(sizeof(*cap));
+    cap->value = g_malloc(sizeof(*cap->value));

I prefer g_new() for extra type checking. Your choice.

ok.

Quoted 10 lines

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 960

Quoted 5 lines
migration/migration.c +5 -0
+    cap->value->capability = MIGRATION_CAPABILITY_BLOCK;
+    cap->value->state = value;
+    qmp_migrate_set_capabilities(cap, errp);
+    qapi_free_MigrationCapabilityStatusList(cap);
+}

The objective is to set one bit. The means is building a MigrationCapabilityStatusList. When you have to build an elaborate data structure just so you can set one bit, your interfaces are likely deficient. Observation, not change request.

This was Dave suggestion. The reason for doing this is in the following patch when we enable compile disable of block migration to put the ifdef in a single place. Otherwise, I have to put it in two places.

Quoted 6 lines

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 965

Quoted 4 lines
migration/migration.c +4 -0
+static void migrate_set_block_incremental(MigrationState *s, bool value)
+{
+    s->parameters.block_incremental = value;
+}

This is how setting one bit should look like.

See previous comment.

Quoted 9 lines

migration/migration.c void migrate_set_state(int *state, int old_state, int new_state) · line 970

Quoted 6 lines
migration/migration.c +5 -0
+
+static void block_cleanup_parameters(MigrationState *s)
+{
+    if (s->must_remove_block) {
+        migrate_set_block_enabled(false, NULL);

NULL ignores errors. If an error happens, and we ignore it, we're screwed, aren't we? I suspect we want &error_abort here.

Quoted 2 lines

setting to false can't never fail. It is when we set it to true that it can fail because it is compiled out (that will be in next patch).

Sounds like a job for &error_abort to me.

Quoted 49 lines
Quoted 11 lines

migration/migration.c void qmp_migrate(const char *uri, bool has_blk, bool blk, · line 1272

Quoted 7 lines
migration/migration.c +3 -0
@@ -1229,6 +1267,38 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         return;
     }
 
+    if (has_blk && blk) {
+        if (migrate_use_block() || migrate_use_block_incremental()) {
+            error_setg(errp, "You can't use block capability and -b/i");

Error message assumes HMP. In QMP, the thing is called 'blk', not -b. Perhaps we can sidestep the issue like this: "Command options are incompatible with current migration capabilities".

ok.

Quoted 17 lines
Quoted 6 lines
migration/migration.c +5 -0
+            return;
+        }
+        migrate_set_block_enabled(true, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);

migration/migration.c void qmp_migrate(const char *uri, bool has_blk, bool blk, · line 1287

Quoted 10 lines
migration/migration.c +10 -0
+            return;
+        }
+        block_enabled = true;
+        s->must_remove_block = true;
+    }
+
+    if (has_inc && inc) {
+        if ((migrate_use_block() && !block_enabled)
+            || migrate_use_block_incremental()) {
+            error_setg(errp, "You can't use block capability and -b/i");
Quoted 4 lines

Likewise.

The condition would be slightly simpler if you completed error checking before changing global state. Matter of taste.

Being bug compatible has this drawbacks. I also hate that -i implies -b.

Quoted 10 lines

qapi-schema.json line 898

Quoted 8 lines
qapi-schema.json +2 -0
@@ -894,11 +894,14 @@
 # @release-ram: if enabled, qemu will free the migrated ram pages on the source
 #        during postcopy-ram migration. (since 2.9)
 #
+# @block: enable block migration (Since 2.10)
+#

What's "block migration" and why should I care?

Quoted 4 lines

"enable migration of block devices. The granularity is all devices or no devices, nothing in the middle."

I will be happy with suggestions.

# @block: If enabled, QEMU will also migrate the contents of all block

#          devices.  Default is disabled.  A possible alternative are
#          mirror jobs to a builtin NBD server on the destination, which
#          are more flexible.
#          (Since 2.10)
Quoted 19 lines
Quoted 8 lines
Quoted 8 lines
qapi-schema.json +2 -1
 # Since: 1.2
 ##
 { 'enum': 'MigrationCapability',
   'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks',
-           'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram'] }
+           'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram',
+           'block' ] }
 
Quoted 10 lines

qapi-schema.json line 1016

Quoted 8 lines
qapi-schema.json +2 -0
 ##
 # @MigrationCapabilityStatus:
@@ -1009,13 +1012,15 @@
 # @x-checkpoint-delay: The delay time (in ms) between two COLO checkpoints in
 #          periodic mode. (Since 2.8)
 #
+# @block-incremental: enable block incremental migration (Since 2.10)
+#

What's "block incremental migration" and why should I care?

Quoted 8 lines

This is good, I will try.

"block incremental migration assumes that we have a base image in both sides, and then we continue writting in one of the sides. This way we need to only migrate the changes since the previous state where it was the same in both sides".

I am not sure what to put there, really.

Well, to suggest something, I'd first have to figure out WTF incremental block migration does. Your text helps me some, but not enough. What exactly is being migrated, and what exactly is assumed to be shared between source and destination?

Block migration is scandalously underdocumented.

Quoted 34 lines
Quoted 28 lines
Quoted 28 lines
qapi-schema.json +5 -2
 # Since: 2.4
 ##
 { 'enum': 'MigrationParameter',
   'data': ['compress-level', 'compress-threads', 'decompress-threads',
            'cpu-throttle-initial', 'cpu-throttle-increment',
            'tls-creds', 'tls-hostname', 'max-bandwidth',
-           'downtime-limit', 'x-checkpoint-delay' ] }
+           'downtime-limit', 'x-checkpoint-delay', 'block-incremental' ] }
 
 ##
 # @migrate-set-parameters:
@@ -1082,6 +1087,8 @@
 #
 # @x-checkpoint-delay: the delay time between two COLO checkpoints. (Since 2.8)
 #
+# @block-incremental: enable block incremental migration (Since 2.10)
+#
 # Since: 2.4
 ##
 { 'struct': 'MigrationParameters',
@@ -1094,7 +1101,8 @@
             '*tls-hostname': 'str',
             '*max-bandwidth': 'int',
             '*downtime-limit': 'int',
-            '*x-checkpoint-delay': 'int'} }
+            '*x-checkpoint-delay': 'int',
+            '*block-incremental': 'bool' } }
 
Quoted 5 lines

qapi-schema.json line 1108

Quoted 2 lines
qapi-schema.json +0 -0
 ##
 # @query-migrate-parameters:

Can't say I like the split between MigrationCapability and MigrationParameters, but we got to work with what we have.

Quoted 7 lines

:-(

And it is still not good enough. There are parameters that make sense to change in middle migration (max-bandwidth for example) and others that you shouldn't, like tls-hostname or compression-threads.

Go figure.

Grown, not designed. It happens.

#7 lore raw

Re: [Qemu-devel] [PATCH 2/5] migration: Create block capability

Quoted 14 lines · Markus Armbruster
Quoted 14 lines
Quoted 6 lines

Review

Quoted 4 lines

# periodic mode. (Since 2.8)
#

(quoted diff) +2 -0
+# @block-incremental: enable block incremental migration (Since 2.10)
+#

What's "block incremental migration" and why should I care?

This is good, I will try.

"block incremental migration assumes that we have a base image in both sides, and then we continue writting in one of the sides. This way we need to only migrate the changes since the previous state where it was the same in both sides".

Quoted 8 lines
Quoted 1 line

I am not sure what to put there, really.

Well, to suggest something, I'd first have to figure out WTF incremental block migration does. Your text helps me some, but not enough. What exactly is being migrated, and what exactly is assumed to be shared between source and destination?

Block migration is scandalously underdocumented.

If I have:

base <- active

on the source, then:

block migration without incremental creates:

active

on the destination (the entire disk contents are migrated). Conversely, block migration WITH incremental assumes that I have pre-created 'base' on the destination (easy to do, since base is read-only so it can be copied prior to starting the migration), and the migration results in:

base <- active

on the destination, where only the contents of active were transferred by qemu.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#8 lore raw

Re: [Qemu-devel] [PATCH 2/5] migration: Create block capability

Quoted 40 lines · Eric Blake
Quoted 14 lines · Markus Armbruster
Quoted 14 lines
Quoted 6 lines

Review

Quoted 4 lines

# periodic mode. (Since 2.8)
#

(quoted diff) +2 -0
+# @block-incremental: enable block incremental migration (Since 2.10)
+#

What's "block incremental migration" and why should I care?

This is good, I will try.

"block incremental migration assumes that we have a base image in both sides, and then we continue writting in one of the sides. This way we need to only migrate the changes since the previous state where it was the same in both sides".

Quoted 8 lines
Quoted 1 line

I am not sure what to put there, really.

Well, to suggest something, I'd first have to figure out WTF incremental block migration does. Your text helps me some, but not enough. What exactly is being migrated, and what exactly is assumed to be shared between source and destination?

Block migration is scandalously underdocumented.

If I have:

base <- active

on the source, then:

block migration without incremental creates:

active

on the destination (the entire disk contents are migrated). Conversely, block migration WITH incremental assumes that I have pre-created 'base' on the destination (easy to do, since base is read-only so it can be copied prior to starting the migration), and the migration results in:

Quoted 4 lines

base <- active

on the destination, where only the contents of active were transferred by qemu.

Can you draft a documentation comment for @block-incremental?

#9 lore raw

Re: [Qemu-devel] [PATCH 2/5] migration: Create block capability

Quoted 9 lines · Markus Armbruster
Quoted 7 lines
Quoted 6 lines

Well, to suggest something, I'd first have to figure out WTF incremental block migration does. Your text helps me some, but not enough. What exactly is being migrated, and what exactly is assumed to be shared between source and destination?

Block migration is scandalously underdocumented.

Can you draft a documentation comment for @block-incremental?

How about:

@block-incremental: Affects how much storage is migrated when the block migration capability is enabled. When false, the entire storage backing chain is migrated into a flattened image at the destination; when true, only the active qcow2 layer is migrated and the destination must already have access to the same backing chain as was used on the source. (since 2.10)

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#10 lore raw

Re: [Qemu-devel] [PATCH 2/5] migration: Create block capability

Quoted 12 lines · Eric Blake
Quoted 9 lines · Markus Armbruster
Quoted 7 lines
Quoted 6 lines

Well, to suggest something, I'd first have to figure out WTF incremental block migration does. Your text helps me some, but not enough. What exactly is being migrated, and what exactly is assumed to be shared between source and destination?

Block migration is scandalously underdocumented.

Can you draft a documentation comment for @block-incremental?

Quoted 8 lines

How about:

@block-incremental: Affects how much storage is migrated when the block migration capability is enabled. When false, the entire storage backing chain is migrated into a flattened image at the destination; when true, only the active qcow2 layer is migrated and the destination must already have access to the same backing chain as was used on the source. (since 2.10)

Works for me, thanks!

#11 lore raw

Re: [Qemu-devel] [PATCH 2/5] migration: Create block capability

In reply to Eric Blake
Quoted 12 lines · Eric Blake
Quoted 9 lines · Markus Armbruster
Quoted 7 lines
Quoted 6 lines

Well, to suggest something, I'd first have to figure out WTF incremental block migration does. Your text helps me some, but not enough. What exactly is being migrated, and what exactly is assumed to be shared between source and destination?

Block migration is scandalously underdocumented.

Can you draft a documentation comment for @block-incremental?

Quoted 8 lines

How about:

@block-incremental: Affects how much storage is migrated when the block migration capability is enabled. When false, the entire storage backing chain is migrated into a flattened image at the destination; when true, only the active qcow2 layer is migrated and the destination must already have access to the same backing chain as was used on the source. (since 2.10)

Changed. Thanks.

#12 lore raw

PATCH v4 3/5 migration: Remove use of old MigrationParams

In reply to Juan Quintela

We have change in the previous patch to use migration capabilities for it. Notice that we continue using the old command line flags from migrate command from the time being. Remove the set_params method as now it is empty.

---
- Maintain shared/enabled dependency (Xu suggestion)
- Now we maintain the dependency on the setter functions

---
 include/migration/migration.h |  3 +--
 migration/block.c             | 17 ++---------------
 migration/colo.c              |  4 ++--
 migration/migration.c         |  3 ---
 migration/savevm.c            |  8 ++++++--
 5 files changed, 11 insertions(+), 24 deletions(-)
include/migration/migration.h +1 -2
index adcb8f6..1277226 100644
@@ -43,8 +43,7 @@
 extern int only_migratable;
 
 struct MigrationParams {
-    bool blk;
-    bool shared;
+    bool unused; /* C doesn't allow empty structs */
 };
 
 /* Messages sent on the return path from destination to source */
migration/block.c +2 -15
index 060087f..5d22926 100644
@@ -94,9 +94,6 @@ typedef struct BlkMigBlock {
 } BlkMigBlock;
 
 typedef struct BlkMigState {
-    /* Written during setup phase.  Can be read without a lock.  */
-    int blk_enable;
-    int shared_base;
     QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list;
     int64_t total_sector_sum;
     bool zero_blocks;
@@ -425,7 +422,7 @@ static int init_blk_migration(QEMUFile *f)
         bmds->bulk_completed = 0;
         bmds->total_sectors = sectors;
         bmds->completed_sectors = 0;
-        bmds->shared_base = block_mig_state.shared_base;
+        bmds->shared_base = migrate_use_block_incremental();
 
         assert(i < num_bs);
         bmds_bs[i].bmds = bmds;
@@ -994,22 +991,12 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-static void block_set_params(const MigrationParams *params, void *opaque)
-{
-    block_mig_state.blk_enable = params->blk;
-    block_mig_state.shared_base = params->shared;
-
-    /* shared base means that blk_enable = 1 */
-    block_mig_state.blk_enable |= params->shared;
-}
-
 static bool block_is_active(void *opaque)
 {
-    return block_mig_state.blk_enable == 1;
+    return migrate_use_block();
 }
 
 static SaveVMHandlers savevm_block_handlers = {
-    .set_params = block_set_params,
     .save_live_setup = block_save_setup,
     .save_live_iterate = block_save_iterate,
     .save_live_complete_precopy = block_save_complete,
migration/colo.c +2 -2
index 963c802..8c86892 100644
@@ -14,6 +14,7 @@
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 #include "migration/colo.h"
+#include "migration/block.h"
 #include "io/channel-buffer.h"
 #include "trace.h"
 #include "qemu/error-report.h"
@@ -345,8 +346,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
     }
 
     /* Disable block migration */
-    s->params.blk = 0;
-    s->params.shared = 0;
+    migrate_set_block_enabled(false, &local_err);
     qemu_savevm_state_header(fb);
     qemu_savevm_state_begin(fb, &s->params);
     qemu_mutex_lock_iothread();
migration/migration.c +0 -3
index 03f96df..c03f34e 100644
@@ -1249,9 +1249,6 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
     bool block_enabled = false;
     const char *p;
 
-    params.blk = has_blk && blk;
-    params.shared = has_inc && inc;
-
     if (migration_is_setup_or_active(s->state) ||
         s->state == MIGRATION_STATUS_CANCELLING ||
         s->state == MIGRATION_STATUS_COLO) {
migration/savevm.c +6 -2
index b4f736f..5fc10ab 100644
@@ -1233,8 +1233,6 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
 {
     int ret;
     MigrationParams params = {
-        .blk = 0,
-        .shared = 0
     };
     MigrationState *ms = migrate_init(&params);
     MigrationStatus status;
@@ -1245,6 +1243,12 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
         goto done;
     }
 
+    if (migrate_use_block()) {
+        error_setg(errp, "Block migration and snapshots are incompatible");
+        ret = -EINVAL;
+        goto done;
+    }
+
     qemu_mutex_unlock_iothread();
     qemu_savevm_state_header(f);
     qemu_savevm_state_begin(f, &params);
Signature · 1 line
2.9.3
#13 lore raw

Re: [Qemu-devel] [PATCH 3/5] migration: Remove use of old MigrationParams

Quoted 131 lines · Juan Quintela

We have change in the previous patch to use migration capabilities for it. Notice that we continue using the old command line flags from migrate command from the time being. Remove the set_params method as now it is empty.

---
- Maintain shared/enabled dependency (Xu suggestion)
- Now we maintain the dependency on the setter functions

---
 include/migration/migration.h |  3 +--
 migration/block.c             | 17 ++---------------
 migration/colo.c              |  4 ++--
 migration/migration.c         |  3 ---
 migration/savevm.c            |  8 ++++++--
 5 files changed, 11 insertions(+), 24 deletions(-)
include/migration/migration.h +1 -2
index adcb8f6..1277226 100644
@@ -43,8 +43,7 @@
 extern int only_migratable;
 
 struct MigrationParams {
-    bool blk;
-    bool shared;
+    bool unused; /* C doesn't allow empty structs */
 };
 
 /* Messages sent on the return path from destination to source */
migration/block.c +2 -15
index 060087f..5d22926 100644
@@ -94,9 +94,6 @@ typedef struct BlkMigBlock {
 } BlkMigBlock;
 
 typedef struct BlkMigState {
-    /* Written during setup phase.  Can be read without a lock.  */
-    int blk_enable;
-    int shared_base;
     QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list;
     int64_t total_sector_sum;
     bool zero_blocks;
@@ -425,7 +422,7 @@ static int init_blk_migration(QEMUFile *f)
         bmds->bulk_completed = 0;
         bmds->total_sectors = sectors;
         bmds->completed_sectors = 0;
-        bmds->shared_base = block_mig_state.shared_base;
+        bmds->shared_base = migrate_use_block_incremental();
 
         assert(i < num_bs);
         bmds_bs[i].bmds = bmds;
@@ -994,22 +991,12 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-static void block_set_params(const MigrationParams *params, void *opaque)
-{
-    block_mig_state.blk_enable = params->blk;
-    block_mig_state.shared_base = params->shared;
-
-    /* shared base means that blk_enable = 1 */
-    block_mig_state.blk_enable |= params->shared;
-}
-
 static bool block_is_active(void *opaque)
 {
-    return block_mig_state.blk_enable == 1;
+    return migrate_use_block();
 }
 
 static SaveVMHandlers savevm_block_handlers = {
-    .set_params = block_set_params,
     .save_live_setup = block_save_setup,
     .save_live_iterate = block_save_iterate,
     .save_live_complete_precopy = block_save_complete,
migration/colo.c +2 -2
index 963c802..8c86892 100644
@@ -14,6 +14,7 @@
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 #include "migration/colo.h"
+#include "migration/block.h"
 #include "io/channel-buffer.h"
 #include "trace.h"
 #include "qemu/error-report.h"
@@ -345,8 +346,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
     }
 
     /* Disable block migration */
-    s->params.blk = 0;
-    s->params.shared = 0;
+    migrate_set_block_enabled(false, &local_err);
     qemu_savevm_state_header(fb);
     qemu_savevm_state_begin(fb, &s->params);
     qemu_mutex_lock_iothread();
migration/migration.c +0 -3
index 03f96df..c03f34e 100644
@@ -1249,9 +1249,6 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
     bool block_enabled = false;
     const char *p;
 
-    params.blk = has_blk && blk;
-    params.shared = has_inc && inc;
-
     if (migration_is_setup_or_active(s->state) ||
         s->state == MIGRATION_STATUS_CANCELLING ||
         s->state == MIGRATION_STATUS_COLO) {
migration/savevm.c +0 -2
index b4f736f..5fc10ab 100644
@@ -1233,8 +1233,6 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
 {
     int ret;
     MigrationParams params = {
-        .blk = 0,
-        .shared = 0
     };
     MigrationState *ms = migrate_init(&params);
     MigrationStatus status;
@@ -1245,6 +1243,12 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
         goto done;
     }

migration/savevm.c static int qemu_savevm_state(QEMUFile *f, Error **errp) · line 1254

Quoted 10 lines
migration/savevm.c +6 -0
 
+    if (migrate_use_block()) {
+        error_setg(errp, "Block migration and snapshots are incompatible");
+        ret = -EINVAL;
+        goto done;
+    }
+
     qemu_mutex_unlock_iothread();
     qemu_savevm_state_header(f);
     qemu_savevm_state_begin(f, &params);

New error that isn't mentioned in the commit message. Does it belong here?

#14 lore raw

Re: [Qemu-devel] [PATCH 3/5] migration: Remove use of old MigrationParams

Quoted 26 lines · Markus Armbruster
Quoted 24 lines · Juan Quintela

We have change in the previous patch to use migration capabilities for it. Notice that we continue using the old command line flags from migrate command from the time being. Remove the set_params method as now it is empty.

migration/savevm.c +0 -2
index b4f736f..5fc10ab 100644
@@ -1233,8 +1233,6 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
 {
     int ret;
     MigrationParams params = {
-        .blk = 0,
-        .shared = 0
     };
     MigrationState *ms = migrate_init(&params);
     MigrationStatus status;
@@ -1245,6 +1243,12 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
         goto done;
     }
 
Quoted 12 lines

migration/savevm.c static int qemu_savevm_state(QEMUFile *f, Error **errp) · line 1254

Quoted 9 lines
migration/savevm.c +6 -0
+    if (migrate_use_block()) {
+        error_setg(errp, "Block migration and snapshots are incompatible");
+        ret = -EINVAL;
+        goto done;
+    }
+
     qemu_mutex_unlock_iothread();
     qemu_savevm_state_header(f);
     qemu_savevm_state_begin(f, &params);

New error that isn't mentioned in the commit message. Does it belong here?

It is the equivalent of the previous chunk.

If you do a savevm, you can't do a:

savevm -b/-i foo

but now you can do:

migrate_set_capability block on
savevm foo

And we can't use block migration. If you preffer, I can disable the feature unconditionally, but I am not sure that it is much better.

Later, Juan.

#15 lore raw

Re: [Qemu-devel] [PATCH 3/5] migration: Remove use of old MigrationParams

Quoted 46 lines · Juan Quintela
Quoted 26 lines · Markus Armbruster
Quoted 24 lines · Juan Quintela

We have change in the previous patch to use migration capabilities for it. Notice that we continue using the old command line flags from migrate command from the time being. Remove the set_params method as now it is empty.

migration/savevm.c +0 -2
index b4f736f..5fc10ab 100644
@@ -1233,8 +1233,6 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
 {
     int ret;
     MigrationParams params = {
-        .blk = 0,
-        .shared = 0
     };
     MigrationState *ms = migrate_init(&params);
     MigrationStatus status;
@@ -1245,6 +1243,12 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
         goto done;
     }
 
Quoted 12 lines

migration/savevm.c static int qemu_savevm_state(QEMUFile *f, Error **errp) · line 1254

Quoted 9 lines
migration/savevm.c +6 -0
+    if (migrate_use_block()) {
+        error_setg(errp, "Block migration and snapshots are incompatible");
+        ret = -EINVAL;
+        goto done;
+    }
+
     qemu_mutex_unlock_iothread();
     qemu_savevm_state_header(f);
     qemu_savevm_state_begin(f, &params);

New error that isn't mentioned in the commit message. Does it belong here?

It is the equivalent of the previous chunk.

If you do a savevm, you can't do a:

savevm -b/-i foo

Quoted 7 lines

but now you can do:

migrate_set_capability block on
savevm foo

And we can't use block migration. If you preffer, I can disable the feature unconditionally, but I am not sure that it is much better.

I see.

Add your explanation to the commit message, and I'm happy.

#16 lore raw

PATCH v4 4/5 migration: Remove old MigrationParams

In reply to Juan Quintela

Not used anymore after moving block migration to use capabilities.

---
 include/migration/migration.h | 10 ++--------
 include/migration/vmstate.h   |  1 -
 include/qemu/typedefs.h       |  1 -
 include/sysemu/sysemu.h       |  3 +--
 migration/colo.c              |  2 +-
 migration/migration.c         |  8 +++-----
 migration/savevm.c            | 16 +++-------------
 7 files changed, 10 insertions(+), 31 deletions(-)
include/migration/migration.h +2 -8
index 1277226..761ea0d 100644
@@ -42,10 +42,6 @@
 /* for vl.c */
 extern int only_migratable;
 
-struct MigrationParams {
-    bool unused; /* C doesn't allow empty structs */
-};
-
 /* Messages sent on the return path from destination to source */
 enum mig_rp_message_type {
     MIG_RP_MSG_INVALID = 0,  /* Must be 0 */
@@ -135,12 +131,10 @@ struct MigrationState
     QEMUBH *cleanup_bh;
     QEMUFile *to_dst_file;
 
-    /* New style params from 'migrate-set-parameters' */
+    /* params from 'migrate-set-parameters' */
     MigrationParameters parameters;
 
     int state;
-    /* Old style params from 'migrate' command */
-    MigrationParams params;
 
     /* State related to return path */
     struct {
@@ -234,7 +228,7 @@ void migrate_fd_connect(MigrationState *s);
 
 void add_migration_state_change_notifier(Notifier *notify);
 void remove_migration_state_change_notifier(Notifier *notify);
-MigrationState *migrate_init(const MigrationParams *params);
+MigrationState *migrate_init(void);
 bool migration_is_blocked(Error **errp);
 bool migration_in_setup(MigrationState *);
 bool migration_is_idle(void);
include/migration/vmstate.h +0 -1
index f4bf3f1..81af5fb 100644
@@ -37,7 +37,6 @@ typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
 
 typedef struct SaveVMHandlers {
     /* This runs inside the iothread lock.  */
-    void (*set_params)(const MigrationParams *params, void * opaque);
     SaveStateHandler *save_state;
 
     void (*cleanup)(void *opaque);
include/qemu/typedefs.h +0 -1
index f08d327..a388243 100644
@@ -49,7 +49,6 @@ typedef struct MemoryRegion MemoryRegion;
 typedef struct MemoryRegionCache MemoryRegionCache;
 typedef struct MemoryRegionSection MemoryRegionSection;
 typedef struct MigrationIncomingState MigrationIncomingState;
-typedef struct MigrationParams MigrationParams;
 typedef struct MigrationState MigrationState;
 typedef struct Monitor Monitor;
 typedef struct MonitorDef MonitorDef;
include/sysemu/sysemu.h +1 -2
index 058d5eb..3340202 100644
@@ -102,8 +102,7 @@ enum qemu_vm_cmd {
 #define MAX_VM_CMD_PACKAGED_SIZE (1ul << 24)
 
 bool qemu_savevm_state_blocked(Error **errp);
-void qemu_savevm_state_begin(QEMUFile *f,
-                             const MigrationParams *params);
+void qemu_savevm_state_begin(QEMUFile *f);
 void qemu_savevm_state_header(QEMUFile *f);
 int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy);
 void qemu_savevm_state_cleanup(void);
migration/colo.c +1 -1
index 8c86892..dd38fed 100644
@@ -348,7 +348,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
     /* Disable block migration */
     migrate_set_block_enabled(false, &local_err);
     qemu_savevm_state_header(fb);
-    qemu_savevm_state_begin(fb, &s->params);
+    qemu_savevm_state_begin(fb);
     qemu_mutex_lock_iothread();
     qemu_savevm_state_complete_precopy(fb, false);
     qemu_mutex_unlock_iothread();
migration/migration.c +3 -5
index c03f34e..e7633ff 100644
@@ -1127,7 +1127,7 @@ bool migration_is_idle(void)
     return false;
 }
 
-MigrationState *migrate_init(const MigrationParams *params)
+MigrationState *migrate_init(void)
 {
     MigrationState *s = migrate_get_current();
 
@@ -1141,7 +1141,6 @@ MigrationState *migrate_init(const MigrationParams *params)
     s->cleanup_bh = 0;
     s->to_dst_file = NULL;
     s->state = MIGRATION_STATUS_NONE;
-    s->params = *params;
     s->rp_state.from_dst_file = NULL;
     s->rp_state.error = false;
     s->mbps = 0.0;
@@ -1245,7 +1244,6 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 {
     Error *local_err = NULL;
     MigrationState *s = migrate_get_current();
-    MigrationParams params;
     bool block_enabled = false;
     const char *p;
 
@@ -1296,7 +1294,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         s->must_remove_block_incremental = true;
     }
 
-    s = migrate_init(&params);
+    s = migrate_init();
 
     if (strstart(uri, "tcp:", &p)) {
         tcp_start_outgoing_migration(s, p, &local_err);
@@ -2020,7 +2018,7 @@ static void *migration_thread(void *opaque)
         qemu_savevm_send_postcopy_advise(s->to_dst_file);
     }
 
-    qemu_savevm_state_begin(s->to_dst_file, &s->params);
+    qemu_savevm_state_begin(s->to_dst_file);
 
     s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start;
     migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
migration/savevm.c +3 -13
index 5fc10ab..43118b3 100644
@@ -966,21 +966,13 @@ void qemu_savevm_state_header(QEMUFile *f)
 
 }
 
-void qemu_savevm_state_begin(QEMUFile *f,
-                             const MigrationParams *params)
+void qemu_savevm_state_begin(QEMUFile *f)
 {
     SaveStateEntry *se;
     int ret;
 
     trace_savevm_state_begin();
     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
-        if (!se->ops || !se->ops->set_params) {
-            continue;
-        }
-        se->ops->set_params(params, se->opaque);
-    }
-
-    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (!se->ops || !se->ops->save_live_setup) {
             continue;
         }
@@ -1232,9 +1224,7 @@ void qemu_savevm_state_cleanup(void)
 static int qemu_savevm_state(QEMUFile *f, Error **errp)
 {
     int ret;
-    MigrationParams params = {
-    };
-    MigrationState *ms = migrate_init(&params);
+    MigrationState *ms = migrate_init();
     MigrationStatus status;
     ms->to_dst_file = f;
 
@@ -1251,7 +1241,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
 
     qemu_mutex_unlock_iothread();
     qemu_savevm_state_header(f);
-    qemu_savevm_state_begin(f, &params);
+    qemu_savevm_state_begin(f);
     qemu_mutex_lock_iothread();
 
     while (qemu_file_get_error(f) == 0) {
Signature · 1 line
2.9.3
#17 lore raw

PATCH v4 5/5 block migration: Allow compile time disable

In reply to Juan Quintela

From: "Dr. David Alan Gilbert" <[email protected]>

Many users now prefer to use drive_mirror over NBD as an alternative to the older migrate -b option; drive_mirror is more complex to setup but gives you more options (e.g. only migrating some of the disks if some of them are shared).

Allow the large chunk of block migration code to be compiled out for those who don't use it.

Based on a downstream-patch we've had for a while by Jeff Cody.

---
 configure                 | 11 +++++++++++
 include/migration/block.h | 24 +++++++++++++++++++++++-
 migration/Makefile.objs   |  2 +-
 migration/migration.c     | 13 +++++++++++++
 4 files changed, 48 insertions(+), 2 deletions(-)
configure +11 -0
index 39e727e..29f5f62 100755
@@ -316,6 +316,7 @@ vte=""
 virglrenderer=""
 tpm="yes"
 libssh2=""
+live_block_migration="yes"
 numa=""
 tcmalloc="no"
 jemalloc="no"
@@ -1168,6 +1169,10 @@ for opt do
   ;;
   --enable-libssh2) libssh2="yes"
   ;;
+  --disable-live-block-migration) live_block_migration="no"
+  ;;
+  --enable-live-block-migration) live_block_migration="yes"
+  ;;
   --disable-numa) numa="no"
   ;;
   --enable-numa) numa="yes"
@@ -1400,6 +1405,7 @@ disabled with --disable-FEATURE, default is enabled if available:
   libnfs          nfs support
   smartcard       smartcard support (libcacard)
   libusb          libusb (for usb passthrough)
+  live-block-migration   Block migration in the main migration stream
   usb-redir       usb network redirection support
   lzo             support of lzo compression library
   snappy          support of snappy compression library
@@ -5215,6 +5221,7 @@ echo "TPM support       $tpm"
 echo "libssh2 support   $libssh2"
 echo "TPM passthrough   $tpm_passthrough"
 echo "QOM debugging     $qom_cast_debug"
+echo "Live block migration $live_block_migration"
 echo "lzo support       $lzo"
 echo "snappy support    $snappy"
 echo "bzip2 support     $bzip2"
@@ -5781,6 +5788,10 @@ if test "$libssh2" = "yes" ; then
   echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak
 fi
 
+if test "$live_block_migration" = "yes" ; then
+  echo "CONFIG_LIVE_BLOCK_MIGRATION=y" >> $config_host_mak
+fi
+
 # USB host support
 if test "$libusb" = "yes"; then
   echo "HOST_USB=libusb legacy" >> $config_host_mak
include/migration/block.h +23 -1
index 5225af9..28cff53 100644
@@ -14,12 +14,34 @@
 #ifndef MIGRATION_BLOCK_H
 #define MIGRATION_BLOCK_H
 
+#ifdef CONFIG_LIVE_BLOCK_MIGRATION
 void blk_mig_init(void);
 int blk_mig_active(void);
 uint64_t blk_mig_bytes_transferred(void);
 uint64_t blk_mig_bytes_remaining(void);
 uint64_t blk_mig_bytes_total(void);
 
+#else
+static inline void blk_mig_init(void) { }
+static inline int blk_mig_active(void)
+{
+    return false;
+}
+static inline uint64_t blk_mig_bytes_transferred(void)
+{
+    return 0;
+}
+
+static inline uint64_t blk_mig_bytes_remaining(void)
+{
+    return 0;
+}
+
+static inline uint64_t blk_mig_bytes_total(void)
+{
+    return 0;
+}
+#endif /* CONFIG_LIVE_BLOCK_MIGRATION */
+
 void migrate_set_block_enabled(bool value, Error **errp);
-
 #endif /* MIGRATION_BLOCK_H */
migration/Makefile.objs +1 -1
index 480dd49..200b5e0 100644
@@ -9,5 +9,5 @@ common-obj-y += qjson.o
 
 common-obj-$(CONFIG_RDMA) += rdma.o
 
-common-obj-y += block.o
+common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o
 
migration/migration.c +13 -0
index e7633ff..892feb3 100644
@@ -554,6 +554,11 @@ MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
 
     caps = NULL; /* silence compiler warning */
     for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
+#ifndef CONFIG_LIVE_BLOCK_MIGRATION
+        if (i == MIGRATION_CAPABILITY_BLOCK) {
+            continue;
+        }
+#endif
         if (i == MIGRATION_CAPABILITY_X_COLO && !colo_supported()) {
             continue;
         }
@@ -770,6 +775,14 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
     }
 
     for (cap = params; cap; cap = cap->next) {
+#ifndef CONFIG_LIVE_BLOCK_MIGRATION
+        if (cap->value->capability == MIGRATION_CAPABILITY_BLOCK) {
+            error_setg(errp, "QEMU compiled without old-style (blk/-b, inc/-i) "
+                       "block migration");
+            error_append_hint(errp, "Use drive_mirror+NBD instead.\n");
+            continue;
+        }
+#endif
         if (cap->value->capability == MIGRATION_CAPABILITY_X_COLO) {
             if (!colo_supported()) {
                 error_setg(errp, "COLO is not currently supported, please"
Signature · 1 line
2.9.3