From 1eb3fc0a0b61b5d22adee2a9add3162a6c03a47e Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Wed, 17 May 2017 17:58:09 +0100 Subject: [PATCH 01/18] migration: Fix non-multiple of page size migration Unfortunately it's legal to create a VM with a RAM size that's not a multiple of the underlying host page or huge page size. Recently I'd changed things to always send host sized pages, and that breaks if we have say a 1025MB guest on 2MB hugepages. Unfortunately we can't just make that illegal since it would break migration from/to existing oddly configured VMs. Symptom: qemu-system-x86_64: Illegal RAM offset 40100000 as it transmits the fraction of the hugepage after the end of the RAMBlock (may also cause a crash on the source - possibly due to clearing bits after the bitmap) Reported-by: Yumei Huang Red Hat bug: https://bugzilla.redhat.com/show_bug.cgi?id=1449037 Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index f59fdd41a4..59459efe18 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1312,6 +1312,8 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss, * a host page in which case the remainder of the hostpage is sent. * Only dirty target pages are sent. Note that the host page size may * be a huge page for this block. + * The saving stops at the boundary of the used_length of the block + * if the RAMBlock isn't a multiple of the host page size. * * Returns the number of pages written or negative on error * @@ -1335,7 +1337,8 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, pages += tmppages; pss->page++; - } while (pss->page & (pagesize_bits - 1)); + } while ((pss->page & (pagesize_bits - 1)) && + offset_in_ramblock(pss->block, pss->page << TARGET_PAGE_BITS)); /* The offset we leave with is the last one we looked at */ pss->page--; From 5d214a92acb38979ee1abd1883a225903cb171b6 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Wed, 17 May 2017 17:58:10 +0100 Subject: [PATCH 02/18] postcopy: Require RAMBlocks that are whole pages It turns out that it's legal to create a VM with RAMBlocks that aren't a multiple of the pagesize in use; e.g. a 1025M main memory using 2M host pages. That breaks postcopy's atomic placement of pages, so disallow it. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/postcopy-ram.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index a0489f6542..63b850128e 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -96,14 +96,24 @@ static bool ufd_version_check(int ufd) /* Callback from postcopy_ram_supported_by_host block iterator. */ -static int test_range_shared(const char *block_name, void *host_addr, +static int test_ramblock_postcopiable(const char *block_name, void *host_addr, ram_addr_t offset, ram_addr_t length, void *opaque) { - if (qemu_ram_is_shared(qemu_ram_block_by_name(block_name))) { + RAMBlock *rb = qemu_ram_block_by_name(block_name); + size_t pagesize = qemu_ram_pagesize(rb); + + if (qemu_ram_is_shared(rb)) { error_report("Postcopy on shared RAM (%s) is not yet supported", block_name); return 1; } + + if (length % pagesize) { + error_report("Postcopy requires RAM blocks to be a page size multiple," + " block %s is 0x" RAM_ADDR_FMT " bytes with a " + "page size of 0x%zx", block_name, length, pagesize); + return 1; + } return 0; } @@ -140,7 +150,7 @@ bool postcopy_ram_supported_by_host(void) } /* We don't support postcopy with shared RAM yet */ - if (qemu_ram_foreach_block(test_range_shared, NULL)) { + if (qemu_ram_foreach_block(test_ramblock_postcopiable, NULL)) { goto out; } From f4a06d1391acf919da3f4291f2d6a70344d21c66 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Tue, 16 May 2017 11:37:45 +0200 Subject: [PATCH 03/18] 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. Signed-off-by: Juan Quintela Reviewed-by: Markus Armbruster --- hmp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hmp.c b/hmp.c index 3dceaf809b..83e45c8994 100644 --- a/hmp.c +++ b/hmp.c @@ -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" @@ -1524,8 +1525,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; @@ -1583,9 +1585,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 @@ -1609,6 +1610,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) } cleanup: + visit_free(v); if (err) { error_report_err(err); } From 2833c59b947cf909020c4d6194aac35f383e832b Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 5 Apr 2017 18:32:37 +0200 Subject: [PATCH 04/18] migration: Create block capability Create one capability for block migration and one parameter for incremental block migration. Signed-off-by: Juan Quintela Reviewed-by: Eric Blake --- - address all Markus comments - use Markus and Eric text descriptions - change logic another time - improve text messages --- hmp.c | 13 +++++++ include/migration/block.h | 2 + include/migration/migration.h | 6 +++ migration/migration.c | 71 +++++++++++++++++++++++++++++++++++ qapi-schema.json | 28 ++++++++++++-- 5 files changed, 117 insertions(+), 3 deletions(-) diff --git a/hmp.c b/hmp.c index 83e45c8994..20f5daba5e 100644 --- a/hmp.c +++ b/hmp.c @@ -327,6 +327,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); @@ -1528,6 +1532,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; @@ -1582,6 +1587,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) { diff --git a/include/migration/block.h b/include/migration/block.h index 41a1ac8f79..5225af9d2b 100644 --- a/include/migration/block.h +++ b/include/migration/block.h @@ -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 */ diff --git a/include/migration/migration.h b/include/migration/migration.h index 49ec5015e5..024a048ee4 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -153,6 +153,9 @@ struct MigrationState /* The last error that occurred */ Error *error; + /* Do we have to clean up -b/-i from old migrate parameters */ + /* This feature is deprecated and will be removed */ + bool must_remove_block_options; }; void migrate_set_state(int *state, int old_state, int new_state); @@ -265,6 +268,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); diff --git a/migration/migration.c b/migration/migration.c index 0304c013f3..c13c0a293e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -592,6 +592,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; } @@ -900,6 +902,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; + } } @@ -935,6 +940,33 @@ 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_new0(MigrationCapabilityStatusList, 1); + cap->value = g_new0(MigrationCapabilityStatus, 1); + cap->value->capability = MIGRATION_CAPABILITY_BLOCK; + cap->value->state = value; + qmp_migrate_set_capabilities(cap, errp); + qapi_free_MigrationCapabilityStatusList(cap); +} + +static void migrate_set_block_incremental(MigrationState *s, bool value) +{ + s->parameters.block_incremental = value; +} + +static void block_cleanup_parameters(MigrationState *s) +{ + if (s->must_remove_block_options) { + /* setting to false can never fail */ + migrate_set_block_enabled(false, &error_abort); + migrate_set_block_incremental(s, false); + s->must_remove_block_options = false; + } +} + static void migrate_fd_cleanup(void *opaque) { MigrationState *s = opaque; @@ -967,6 +999,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) @@ -979,6 +1012,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) @@ -1020,6 +1054,7 @@ static void migrate_fd_cancel(MigrationState *s) s->block_inactive = false; } } + block_cleanup_parameters(s); } void add_migration_state_change_notifier(Notifier *notify) @@ -1207,6 +1242,24 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, return; } + if ((has_blk && blk) || (has_inc && inc)) { + if (migrate_use_block() || migrate_use_block_incremental()) { + error_setg(errp, "Command options are incompatible with " + "current migration capabilities"); + return; + } + migrate_set_block_enabled(true, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + s->must_remove_block_options = true; + } + + if (has_inc && inc) { + migrate_set_block_incremental(s, true); + } + s = migrate_init(¶ms); if (strstart(uri, "tcp:", &p)) { @@ -1404,6 +1457,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 diff --git a/qapi-schema.json b/qapi-schema.json index 80603cfc51..e38c5f0423 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -894,11 +894,18 @@ # @release-ram: if enabled, qemu will free the migrated ram pages on the source # during postcopy-ram migration. (since 2.9) # +# @block: If enabled, QEMU will also migrate the contents of all block +# devices. Default is disabled. A possible alternative uses +# mirror jobs to a builtin NBD server on the destination, which +# offers more flexibility. +# (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 +1016,20 @@ # @x-checkpoint-delay: The delay time (in ms) between two COLO checkpoints in # periodic mode. (Since 2.8) # +# @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) +# # 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 +1096,13 @@ # # @x-checkpoint-delay: the delay time between two COLO checkpoints. (Since 2.8) # +# @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) +# # Since: 2.4 ## { 'struct': 'MigrationParameters', @@ -1094,7 +1115,8 @@ '*tls-hostname': 'str', '*max-bandwidth': 'int', '*downtime-limit': 'int', - '*x-checkpoint-delay': 'int'} } + '*x-checkpoint-delay': 'int', + '*block-incremental': 'bool' } } ## # @query-migrate-parameters: From ce7c817c85e704b2f5dc3a976c7a1c5ce0fd93c2 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 5 Apr 2017 20:45:22 +0200 Subject: [PATCH 05/18] migration: Remove use of old MigrationParams 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. For savevm, one can't do a: savevm -b/-i foo but now one can do: migrate_set_capability block on savevm foo And we can't use block migration. We could disable block capability unconditionally, but it would not be much better. Signed-off-by: Juan Quintela Reviewed-by: Eric Blake --- - Maintain shared/enabled dependency (Xu suggestion) - Now we maintain the dependency on the setter functions - improve error messages --- 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(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 024a048ee4..4dedc66a48 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -39,8 +39,7 @@ #define QEMU_VM_SECTION_FOOTER 0x7e struct MigrationParams { - bool blk; - bool shared; + bool unused; /* C doesn't allow empty structs */ }; /* Messages sent on the return path from destination to source */ diff --git a/migration/block.c b/migration/block.c index 060087fa32..5d229264bf 100644 --- a/migration/block.c +++ b/migration/block.c @@ -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, diff --git a/migration/colo.c b/migration/colo.c index 963c80256d..8c86892246 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -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(); diff --git a/migration/migration.c b/migration/migration.c index c13c0a293e..b3d300d181 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1224,9 +1224,6 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, MigrationParams params; 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) { diff --git a/migration/savevm.c b/migration/savevm.c index f5e81948e6..2f1f4eb547 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -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(¶ms); 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, ¶ms); From a0762d9e34404d671bf9241bbd5b67c38953c63a Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 5 Apr 2017 21:00:09 +0200 Subject: [PATCH 06/18] migration: Remove old MigrationParams Not used anymore after moving block migration to use capabilities. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: zhanghailiang Reviewed-by: Peter Xu --- 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(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 4dedc66a48..b80a6edbb3 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -38,10 +38,6 @@ #define QEMU_VM_COMMAND 0x08 #define QEMU_VM_SECTION_FOOTER 0x7e -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 */ @@ -109,12 +105,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 { @@ -207,7 +201,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); diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 848965963a..dacb052551 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -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); diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 7d8505730c..33a6aa18e3 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -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; diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 83c1ceb33e..765358ea45 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -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); diff --git a/migration/colo.c b/migration/colo.c index 8c86892246..dd38fed2d8 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -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(); diff --git a/migration/migration.c b/migration/migration.c index b3d300d181..ed66158377 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1118,7 +1118,7 @@ bool migration_is_idle(void) return false; } -MigrationState *migrate_init(const MigrationParams *params) +MigrationState *migrate_init(void) { MigrationState *s = migrate_get_current(); @@ -1132,7 +1132,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; @@ -1221,7 +1220,6 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, { Error *local_err = NULL; MigrationState *s = migrate_get_current(); - MigrationParams params; const char *p; if (migration_is_setup_or_active(s->state) || @@ -1257,7 +1255,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, migrate_set_block_incremental(s, true); } - s = migrate_init(¶ms); + s = migrate_init(); if (strstart(uri, "tcp:", &p)) { tcp_start_outgoing_migration(s, p, &local_err); @@ -1981,7 +1979,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, diff --git a/migration/savevm.c b/migration/savevm.c index 2f1f4eb547..a728414b33 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -966,20 +966,12 @@ 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(¶ms); + 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, ¶ms); + qemu_savevm_state_begin(f); qemu_mutex_lock_iothread(); while (qemu_file_get_error(f) == 0) { From ed1701c6a5a7d08f33148c50c4d28799ee0568c4 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Mon, 15 May 2017 15:05:29 +0100 Subject: [PATCH 07/18] block migration: Allow compile time disable 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. Signed-off-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela Reviewed-by: Eric Blake -- - When compiled out, allow seting block only with false value (eric) --- configure | 11 +++++++++++ include/migration/block.h | 24 +++++++++++++++++++++++- migration/Makefile.objs | 2 +- migration/migration.c | 14 ++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 139638e922..1a5ee4b909 100755 --- a/configure +++ b/configure @@ -316,6 +316,7 @@ vte="" virglrenderer="" tpm="yes" libssh2="" +live_block_migration="yes" numa="" tcmalloc="no" jemalloc="no" @@ -1169,6 +1170,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" @@ -1401,6 +1406,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 @@ -5216,6 +5222,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" @@ -5782,6 +5789,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 diff --git a/include/migration/block.h b/include/migration/block.h index 5225af9d2b..28cff53a23 100644 --- a/include/migration/block.h +++ b/include/migration/block.h @@ -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); -void migrate_set_block_enabled(bool value, Error **errp); +#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 */ diff --git a/migration/Makefile.objs b/migration/Makefile.objs index c1920b6fc0..00a3f4a1d9 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -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 diff --git a/migration/migration.c b/migration/migration.c index ed66158377..2feeee8787 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -547,6 +547,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; } @@ -763,6 +768,15 @@ 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 + && cap->value->state) { + 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" From 709e3fe82581f866350ff3be5198ea73cda09f0d Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 5 Apr 2017 21:47:50 +0200 Subject: [PATCH 08/18] migration: Create migration/xbzrle.h Signed-off-by: Juan Quintela Reviewed-by: Peter Xu --- include/migration/migration.h | 4 ---- migration/ram.c | 1 + migration/xbzrle.c | 2 +- migration/xbzrle.h | 21 +++++++++++++++++++++ tests/test-xbzrle.c | 2 +- 5 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 migration/xbzrle.h diff --git a/include/migration/migration.h b/include/migration/migration.h index b80a6edbb3..7d1eef717e 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -251,10 +251,6 @@ bool migrate_zero_blocks(void); bool migrate_auto_converge(void); -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); bool migrate_colo_enabled(void); diff --git a/migration/ram.c b/migration/ram.c index 59459efe18..c14269fd16 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -35,6 +35,7 @@ #include "qemu/bitmap.h" #include "qemu/timer.h" #include "qemu/main-loop.h" +#include "xbzrle.h" #include "migration/migration.h" #include "postcopy-ram.h" #include "exec/address-spaces.h" diff --git a/migration/xbzrle.c b/migration/xbzrle.c index c858339259..1ba482ded9 100644 --- a/migration/xbzrle.c +++ b/migration/xbzrle.c @@ -12,7 +12,7 @@ */ #include "qemu/osdep.h" #include "qemu/cutils.h" -#include "include/migration/migration.h" +#include "xbzrle.h" /* page = zrun nzrun diff --git a/migration/xbzrle.h b/migration/xbzrle.h new file mode 100644 index 0000000000..a0db507b9c --- /dev/null +++ b/migration/xbzrle.h @@ -0,0 +1,21 @@ +/* + * QEMU live migration + * + * Copyright IBM, Corp. 2008 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#ifndef QEMU_MIGRATION_XBZRLE_H +#define QEMU_MIGRATION_XBZRLE_H + +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 diff --git a/tests/test-xbzrle.c b/tests/test-xbzrle.c index 49f64195a6..f5e08de91e 100644 --- a/tests/test-xbzrle.c +++ b/tests/test-xbzrle.c @@ -13,7 +13,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/cutils.h" -#include "include/migration/migration.h" +#include "../migration/xbzrle.h" #define PAGE_SIZE 4096 From dd4339c540285b3a0904c631f8174a59d04be767 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Mon, 17 Apr 2017 17:07:04 +0200 Subject: [PATCH 09/18] migration: Split migration/channel.c for channel operations Create an include for its exported functions. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- Add proper header --- include/migration/migration.h | 7 ---- migration/Makefile.objs | 2 +- migration/channel.c | 66 +++++++++++++++++++++++++++++++++++ migration/channel.h | 27 ++++++++++++++ migration/exec.c | 1 + migration/fd.c | 1 + migration/migration.c | 50 -------------------------- migration/socket.c | 1 + migration/tls.c | 1 + 9 files changed, 98 insertions(+), 58 deletions(-) create mode 100644 migration/channel.c create mode 100644 migration/channel.h diff --git a/include/migration/migration.h b/include/migration/migration.h index 7d1eef717e..e831259c3b 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -157,17 +157,10 @@ void migration_fd_process_incoming(QEMUFile *f); void qemu_start_incoming_migration(const char *uri, Error **errp); -void migration_channel_process_incoming(MigrationState *s, - QIOChannel *ioc); - void migration_tls_channel_process_incoming(MigrationState *s, QIOChannel *ioc, Error **errp); -void migration_channel_connect(MigrationState *s, - QIOChannel *ioc, - const char *hostname); - void migration_tls_channel_connect(MigrationState *s, QIOChannel *ioc, const char *hostname, diff --git a/migration/Makefile.objs b/migration/Makefile.objs index 00a3f4a1d9..4e8ab0a918 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -1,5 +1,5 @@ common-obj-y += migration.o socket.o fd.o exec.o -common-obj-y += tls.o +common-obj-y += tls.o channel.o common-obj-y += colo-comm.o colo.o colo-failover.o common-obj-y += vmstate.o page_cache.o common-obj-y += qemu-file.o diff --git a/migration/channel.c b/migration/channel.c new file mode 100644 index 0000000000..40c63824c1 --- /dev/null +++ b/migration/channel.c @@ -0,0 +1,66 @@ +/* + * QEMU live migration channel operations + * + * Copyright Red Hat, Inc. 2016 + * + * Authors: + * Daniel P. Berrange + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#include "qemu/osdep.h" +#include "channel.h" +#include "migration/migration.h" +#include "trace.h" +#include "qapi/error.h" +#include "io/channel-tls.h" + +void migration_channel_process_incoming(MigrationState *s, + QIOChannel *ioc) +{ + trace_migration_set_incoming_channel( + ioc, object_get_typename(OBJECT(ioc))); + + if (s->parameters.tls_creds && + *s->parameters.tls_creds && + !object_dynamic_cast(OBJECT(ioc), + TYPE_QIO_CHANNEL_TLS)) { + Error *local_err = NULL; + migration_tls_channel_process_incoming(s, ioc, &local_err); + if (local_err) { + error_report_err(local_err); + } + } else { + QEMUFile *f = qemu_fopen_channel_input(ioc); + migration_fd_process_incoming(f); + } +} + + +void migration_channel_connect(MigrationState *s, + QIOChannel *ioc, + const char *hostname) +{ + trace_migration_set_outgoing_channel( + ioc, object_get_typename(OBJECT(ioc)), hostname); + + if (s->parameters.tls_creds && + *s->parameters.tls_creds && + !object_dynamic_cast(OBJECT(ioc), + TYPE_QIO_CHANNEL_TLS)) { + Error *local_err = NULL; + migration_tls_channel_connect(s, ioc, hostname, &local_err); + if (local_err) { + migrate_fd_error(s, local_err); + error_free(local_err); + } + } else { + QEMUFile *f = qemu_fopen_channel_output(ioc); + + s->to_dst_file = f; + + migrate_fd_connect(s); + } +} diff --git a/migration/channel.h b/migration/channel.h new file mode 100644 index 0000000000..2e0a7e33cc --- /dev/null +++ b/migration/channel.h @@ -0,0 +1,27 @@ +/* + * QEMU live migration channel operations + * + * Copyright Red Hat, Inc. 2016 + * + * Authors: + * Daniel P. Berrange + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#ifndef QEMU_MIGRATION_CHANNEL_H +#define QEMU_MIGRATION_CHANNEL_H + +#include "io/channel.h" + +void migration_channel_process_incoming(MigrationState *s, + QIOChannel *ioc); + +void migration_channel_connect(MigrationState *s, + QIOChannel *ioc, + const char *hostname); +#endif diff --git a/migration/exec.c b/migration/exec.c index aba9089466..57a93355d1 100644 --- a/migration/exec.c +++ b/migration/exec.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu-common.h" +#include "channel.h" #include "migration/migration.h" #include "io/channel-command.h" #include "trace.h" diff --git a/migration/fd.c b/migration/fd.c index 58cb51a9e6..05e0a5cca8 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -17,6 +17,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu-common.h" +#include "channel.h" #include "migration/migration.h" #include "monitor/monitor.h" #include "io/channel-util.h" diff --git a/migration/migration.c b/migration/migration.c index 2feeee8787..217616df6a 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -444,56 +444,6 @@ void migration_fd_process_incoming(QEMUFile *f) qemu_coroutine_enter(co); } - -void migration_channel_process_incoming(MigrationState *s, - QIOChannel *ioc) -{ - trace_migration_set_incoming_channel( - ioc, object_get_typename(OBJECT(ioc))); - - if (s->parameters.tls_creds && - *s->parameters.tls_creds && - !object_dynamic_cast(OBJECT(ioc), - TYPE_QIO_CHANNEL_TLS)) { - Error *local_err = NULL; - migration_tls_channel_process_incoming(s, ioc, &local_err); - if (local_err) { - error_report_err(local_err); - } - } else { - QEMUFile *f = qemu_fopen_channel_input(ioc); - migration_fd_process_incoming(f); - } -} - - -void migration_channel_connect(MigrationState *s, - QIOChannel *ioc, - const char *hostname) -{ - trace_migration_set_outgoing_channel( - ioc, object_get_typename(OBJECT(ioc)), hostname); - - if (s->parameters.tls_creds && - *s->parameters.tls_creds && - !object_dynamic_cast(OBJECT(ioc), - TYPE_QIO_CHANNEL_TLS)) { - Error *local_err = NULL; - migration_tls_channel_connect(s, ioc, hostname, &local_err); - if (local_err) { - migrate_fd_error(s, local_err); - error_free(local_err); - } - } else { - QEMUFile *f = qemu_fopen_channel_output(ioc); - - s->to_dst_file = f; - - migrate_fd_connect(s); - } -} - - /* * Send a message on the return channel back to the source * of the migration. diff --git a/migration/socket.c b/migration/socket.c index 1cfbe81e69..53f9d61605 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -19,6 +19,7 @@ #include "qemu-common.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "channel.h" #include "migration/migration.h" #include "migration/qemu-file.h" #include "io/channel-socket.h" diff --git a/migration/tls.c b/migration/tls.c index a33ecb767e..34ad121abf 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -19,6 +19,7 @@ */ #include "qemu/osdep.h" +#include "channel.h" #include "migration/migration.h" #include "io/channel-tls.h" #include "crypto/tlscreds.h" From 40014d81f2c7793781c8afa74713d72da10e6f0f Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Mon, 17 Apr 2017 19:34:36 +0200 Subject: [PATCH 10/18] migration: Export qemu-file-channel.c functions in its own file Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- include/migration/migration.h | 1 + include/migration/qemu-file.h | 4 ---- migration/channel.c | 1 + migration/colo.c | 1 + migration/migration.c | 1 + migration/qemu-file-channel.c | 1 + migration/qemu-file-channel.h | 32 ++++++++++++++++++++++++++++++++ migration/rdma.c | 1 + migration/savevm.c | 1 + tests/test-vmstate.c | 1 + 10 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 migration/qemu-file-channel.h diff --git a/include/migration/migration.h b/include/migration/migration.h index e831259c3b..8280df12e5 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -19,6 +19,7 @@ #include "qemu/thread.h" #include "qemu/notify.h" #include "migration/vmstate.h" +#include "io/channel.h" #include "qapi-types.h" #include "exec/cpu-common.h" #include "qemu/coroutine_int.h" diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index 0cd648a733..b5ac800258 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -27,8 +27,6 @@ #include "qemu-common.h" #include "exec/cpu-common.h" -#include "io/channel.h" - /* Read a chunk of data from a file at the given position. The pos argument * can be ignored if the file is only be used for streaming. The number of @@ -119,8 +117,6 @@ typedef struct QEMUFileHooks { } QEMUFileHooks; QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops); -QEMUFile *qemu_fopen_channel_input(QIOChannel *ioc); -QEMUFile *qemu_fopen_channel_output(QIOChannel *ioc); void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); diff --git a/migration/channel.c b/migration/channel.c index 40c63824c1..2e78905cc7 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "channel.h" #include "migration/migration.h" +#include "qemu-file-channel.h" #include "trace.h" #include "qapi/error.h" #include "io/channel-tls.h" diff --git a/migration/colo.c b/migration/colo.c index dd38fed2d8..9cd0250da7 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "qemu/timer.h" #include "sysemu/sysemu.h" +#include "qemu-file-channel.h" #include "migration/colo.h" #include "migration/block.h" #include "io/channel-buffer.h" diff --git a/migration/migration.c b/migration/migration.c index 217616df6a..2d9379cc4e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -19,6 +19,7 @@ #include "qemu/main-loop.h" #include "migration/blocker.h" #include "migration/migration.h" +#include "qemu-file-channel.h" #include "migration/qemu-file.h" #include "sysemu/sysemu.h" #include "block/block.h" diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index 45c13f1028..dc991c9051 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -23,6 +23,7 @@ */ #include "qemu/osdep.h" +#include "qemu-file-channel.h" #include "migration/qemu-file.h" #include "io/channel-socket.h" #include "qemu/iov.h" diff --git a/migration/qemu-file-channel.h b/migration/qemu-file-channel.h new file mode 100644 index 0000000000..0028a09eb6 --- /dev/null +++ b/migration/qemu-file-channel.h @@ -0,0 +1,32 @@ +/* + * QEMUFile backend for QIOChannel objects + * + * Copyright (c) 2015-2016 Red Hat, Inc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef QEMU_FILE_CHANNEL_H +#define QEMU_FILE_CHANNEL_H + +#include "io/channel.h" + +QEMUFile *qemu_fopen_channel_input(QIOChannel *ioc); +QEMUFile *qemu_fopen_channel_output(QIOChannel *ioc); +#endif diff --git a/migration/rdma.c b/migration/rdma.c index 7eaaf96479..166cd60a77 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -20,6 +20,7 @@ #include "migration/migration.h" #include "migration/qemu-file.h" #include "exec/cpu-common.h" +#include "qemu-file-channel.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/sockets.h" diff --git a/migration/savevm.c b/migration/savevm.c index a728414b33..85651030b4 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -36,6 +36,7 @@ #include "sysemu/sysemu.h" #include "qemu/timer.h" #include "migration/migration.h" +#include "qemu-file-channel.h" #include "postcopy-ram.h" #include "qapi/qmp/qerror.h" #include "qemu/error-report.h" diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index f694a89782..1c135708f4 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -27,6 +27,7 @@ #include "qemu-common.h" #include "migration/migration.h" #include "migration/vmstate.h" +#include "../migration/qemu-file-channel.h" #include "qemu/coroutine.h" #include "io/channel-file.h" From c59be019e9a55737a58af251aae34ebe0799a65b Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 6 Apr 2017 12:03:13 +0200 Subject: [PATCH 11/18] migration: Remove migration.h from colo.h migration.h is not included in any includes now. Signed-off-by: Juan Quintela Reviewed-by: Peter Xu --- include/migration/colo.h | 1 - migration/colo-comm.c | 3 ++- migration/colo.c | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/migration/colo.h b/include/migration/colo.h index 2bbff9e6c2..ba0bb6e6d5 100644 --- a/include/migration/colo.h +++ b/include/migration/colo.h @@ -14,7 +14,6 @@ #define QEMU_COLO_H #include "qemu-common.h" -#include "migration/migration.h" #include "qemu/coroutine_int.h" #include "qemu/thread.h" #include "qemu/main-loop.h" diff --git a/migration/colo-comm.c b/migration/colo-comm.c index 20b60ec384..3d917988e9 100644 --- a/migration/colo-comm.c +++ b/migration/colo-comm.c @@ -12,7 +12,8 @@ */ #include "qemu/osdep.h" -#include +#include "migration/migration.h" +#include "migration/colo.h" #include "trace.h" typedef struct { diff --git a/migration/colo.c b/migration/colo.c index 9cd0250da7..73ebd64cbb 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -14,6 +14,7 @@ #include "qemu/timer.h" #include "sysemu/sysemu.h" #include "qemu-file-channel.h" +#include "migration/migration.h" #include "migration/colo.h" #include "migration/block.h" #include "io/channel-buffer.h" From 05b98c22f837228a6492e31b2a1e38d59bdb7530 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 20 Apr 2017 13:10:28 +0200 Subject: [PATCH 12/18] migration: Move qjson.h to migration/ It is only used for migration code. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/qjson.c | 2 +- {include/migration => migration}/qjson.h | 0 migration/vmstate.c | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename {include/migration => migration}/qjson.h (100%) diff --git a/migration/qjson.c b/migration/qjson.c index f345904919..9d7f6eb9eb 100644 --- a/migration/qjson.c +++ b/migration/qjson.c @@ -25,7 +25,7 @@ #include "qemu/osdep.h" #include "qapi/qmp/qstring.h" -#include "migration/qjson.h" +#include "qjson.h" struct QJSON { QString *str; diff --git a/include/migration/qjson.h b/migration/qjson.h similarity index 100% rename from include/migration/qjson.h rename to migration/qjson.h diff --git a/migration/vmstate.c b/migration/vmstate.c index 7b4a607c51..66c50ee3f4 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -7,7 +7,7 @@ #include "qemu/error-report.h" #include "qemu/queue.h" #include "trace.h" -#include "migration/qjson.h" +#include "qjson.h" static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, QJSON *vmdesc); From 576d1abc205fb1c135a7448df96bc9d47cb360dc Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 20 Apr 2017 13:41:20 +0200 Subject: [PATCH 13/18] migration: Split vmstate-types.c from vmstate.c Now one just has the interperter, and the other has the basic types. Once there, add copyright boilerplate. Signed-off-by: Juan Quintela Reviewed-by: Peter Xu -- Use GPL v2 or later. Detected by David. --- migration/Makefile.objs | 2 +- migration/vmstate-types.c | 661 ++++++++++++++++++++++++++++++++++++++ migration/vmstate.c | 654 +------------------------------------ tests/Makefile.include | 2 +- 4 files changed, 675 insertions(+), 644 deletions(-) create mode 100644 migration/vmstate-types.c diff --git a/migration/Makefile.objs b/migration/Makefile.objs index 4e8ab0a918..3272415de8 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -1,7 +1,7 @@ common-obj-y += migration.o socket.o fd.o exec.o common-obj-y += tls.o channel.o common-obj-y += colo-comm.o colo.o colo-failover.o -common-obj-y += vmstate.o page_cache.o +common-obj-y += vmstate.o vmstate-types.o page_cache.o common-obj-y += qemu-file.o common-obj-y += qemu-file-channel.o common-obj-y += xbzrle.o postcopy-ram.o diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c new file mode 100644 index 0000000000..cc95e47775 --- /dev/null +++ b/migration/vmstate-types.c @@ -0,0 +1,661 @@ +/* + * VMStateInfo's for basic typse + * + * Copyright (c) 2009-2017 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "migration/migration.h" +#include "migration/qemu-file.h" +#include "migration/vmstate.h" +#include "qemu/error-report.h" +#include "qemu/queue.h" +#include "trace.h" + +/* bool */ + +static int get_bool(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + bool *v = pv; + *v = qemu_get_byte(f); + return 0; +} + +static int put_bool(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + bool *v = pv; + qemu_put_byte(f, *v); + return 0; +} + +const VMStateInfo vmstate_info_bool = { + .name = "bool", + .get = get_bool, + .put = put_bool, +}; + +/* 8 bit int */ + +static int get_int8(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + int8_t *v = pv; + qemu_get_s8s(f, v); + return 0; +} + +static int put_int8(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + int8_t *v = pv; + qemu_put_s8s(f, v); + return 0; +} + +const VMStateInfo vmstate_info_int8 = { + .name = "int8", + .get = get_int8, + .put = put_int8, +}; + +/* 16 bit int */ + +static int get_int16(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + int16_t *v = pv; + qemu_get_sbe16s(f, v); + return 0; +} + +static int put_int16(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + int16_t *v = pv; + qemu_put_sbe16s(f, v); + return 0; +} + +const VMStateInfo vmstate_info_int16 = { + .name = "int16", + .get = get_int16, + .put = put_int16, +}; + +/* 32 bit int */ + +static int get_int32(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + int32_t *v = pv; + qemu_get_sbe32s(f, v); + return 0; +} + +static int put_int32(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + int32_t *v = pv; + qemu_put_sbe32s(f, v); + return 0; +} + +const VMStateInfo vmstate_info_int32 = { + .name = "int32", + .get = get_int32, + .put = put_int32, +}; + +/* 32 bit int. See that the received value is the same than the one + in the field */ + +static int get_int32_equal(QEMUFile *f, void *pv, size_t size, + VMStateField *field) +{ + int32_t *v = pv; + int32_t v2; + qemu_get_sbe32s(f, &v2); + + if (*v == v2) { + return 0; + } + error_report("%" PRIx32 " != %" PRIx32, *v, v2); + return -EINVAL; +} + +const VMStateInfo vmstate_info_int32_equal = { + .name = "int32 equal", + .get = get_int32_equal, + .put = put_int32, +}; + +/* 32 bit int. Check that the received value is non-negative + * and less than or equal to the one in the field. + */ + +static int get_int32_le(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + int32_t *cur = pv; + int32_t loaded; + qemu_get_sbe32s(f, &loaded); + + if (loaded >= 0 && loaded <= *cur) { + *cur = loaded; + return 0; + } + error_report("Invalid value %" PRId32 + " expecting positive value <= %" PRId32, + loaded, *cur); + return -EINVAL; +} + +const VMStateInfo vmstate_info_int32_le = { + .name = "int32 le", + .get = get_int32_le, + .put = put_int32, +}; + +/* 64 bit int */ + +static int get_int64(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + int64_t *v = pv; + qemu_get_sbe64s(f, v); + return 0; +} + +static int put_int64(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + int64_t *v = pv; + qemu_put_sbe64s(f, v); + return 0; +} + +const VMStateInfo vmstate_info_int64 = { + .name = "int64", + .get = get_int64, + .put = put_int64, +}; + +/* 8 bit unsigned int */ + +static int get_uint8(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + uint8_t *v = pv; + qemu_get_8s(f, v); + return 0; +} + +static int put_uint8(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + uint8_t *v = pv; + qemu_put_8s(f, v); + return 0; +} + +const VMStateInfo vmstate_info_uint8 = { + .name = "uint8", + .get = get_uint8, + .put = put_uint8, +}; + +/* 16 bit unsigned int */ + +static int get_uint16(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + uint16_t *v = pv; + qemu_get_be16s(f, v); + return 0; +} + +static int put_uint16(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + uint16_t *v = pv; + qemu_put_be16s(f, v); + return 0; +} + +const VMStateInfo vmstate_info_uint16 = { + .name = "uint16", + .get = get_uint16, + .put = put_uint16, +}; + +/* 32 bit unsigned int */ + +static int get_uint32(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + uint32_t *v = pv; + qemu_get_be32s(f, v); + return 0; +} + +static int put_uint32(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + uint32_t *v = pv; + qemu_put_be32s(f, v); + return 0; +} + +const VMStateInfo vmstate_info_uint32 = { + .name = "uint32", + .get = get_uint32, + .put = put_uint32, +}; + +/* 32 bit uint. See that the received value is the same than the one + in the field */ + +static int get_uint32_equal(QEMUFile *f, void *pv, size_t size, + VMStateField *field) +{ + uint32_t *v = pv; + uint32_t v2; + qemu_get_be32s(f, &v2); + + if (*v == v2) { + return 0; + } + error_report("%" PRIx32 " != %" PRIx32, *v, v2); + return -EINVAL; +} + +const VMStateInfo vmstate_info_uint32_equal = { + .name = "uint32 equal", + .get = get_uint32_equal, + .put = put_uint32, +}; + +/* 64 bit unsigned int */ + +static int get_uint64(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + uint64_t *v = pv; + qemu_get_be64s(f, v); + return 0; +} + +static int put_uint64(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + uint64_t *v = pv; + qemu_put_be64s(f, v); + return 0; +} + +const VMStateInfo vmstate_info_uint64 = { + .name = "uint64", + .get = get_uint64, + .put = put_uint64, +}; + +static int get_nullptr(QEMUFile *f, void *pv, size_t size, VMStateField *field) + +{ + if (qemu_get_byte(f) == VMS_NULLPTR_MARKER) { + return 0; + } + error_report("vmstate: get_nullptr expected VMS_NULLPTR_MARKER"); + return -EINVAL; +} + +static int put_nullptr(QEMUFile *f, void *pv, size_t size, + VMStateField *field, QJSON *vmdesc) + +{ + if (pv == NULL) { + qemu_put_byte(f, VMS_NULLPTR_MARKER); + return 0; + } + error_report("vmstate: put_nullptr must be called with pv == NULL"); + return -EINVAL; +} + +const VMStateInfo vmstate_info_nullptr = { + .name = "uint64", + .get = get_nullptr, + .put = put_nullptr, +}; + +/* 64 bit unsigned int. See that the received value is the same than the one + in the field */ + +static int get_uint64_equal(QEMUFile *f, void *pv, size_t size, + VMStateField *field) +{ + uint64_t *v = pv; + uint64_t v2; + qemu_get_be64s(f, &v2); + + if (*v == v2) { + return 0; + } + error_report("%" PRIx64 " != %" PRIx64, *v, v2); + return -EINVAL; +} + +const VMStateInfo vmstate_info_uint64_equal = { + .name = "int64 equal", + .get = get_uint64_equal, + .put = put_uint64, +}; + +/* 8 bit int. See that the received value is the same than the one + in the field */ + +static int get_uint8_equal(QEMUFile *f, void *pv, size_t size, + VMStateField *field) +{ + uint8_t *v = pv; + uint8_t v2; + qemu_get_8s(f, &v2); + + if (*v == v2) { + return 0; + } + error_report("%x != %x", *v, v2); + return -EINVAL; +} + +const VMStateInfo vmstate_info_uint8_equal = { + .name = "uint8 equal", + .get = get_uint8_equal, + .put = put_uint8, +}; + +/* 16 bit unsigned int int. See that the received value is the same than the one + in the field */ + +static int get_uint16_equal(QEMUFile *f, void *pv, size_t size, + VMStateField *field) +{ + uint16_t *v = pv; + uint16_t v2; + qemu_get_be16s(f, &v2); + + if (*v == v2) { + return 0; + } + error_report("%x != %x", *v, v2); + return -EINVAL; +} + +const VMStateInfo vmstate_info_uint16_equal = { + .name = "uint16 equal", + .get = get_uint16_equal, + .put = put_uint16, +}; + +/* floating point */ + +static int get_float64(QEMUFile *f, void *pv, size_t size, + VMStateField *field) +{ + float64 *v = pv; + + *v = make_float64(qemu_get_be64(f)); + return 0; +} + +static int put_float64(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + uint64_t *v = pv; + + qemu_put_be64(f, float64_val(*v)); + return 0; +} + +const VMStateInfo vmstate_info_float64 = { + .name = "float64", + .get = get_float64, + .put = put_float64, +}; + +/* CPU_DoubleU type */ + +static int get_cpudouble(QEMUFile *f, void *pv, size_t size, + VMStateField *field) +{ + CPU_DoubleU *v = pv; + qemu_get_be32s(f, &v->l.upper); + qemu_get_be32s(f, &v->l.lower); + return 0; +} + +static int put_cpudouble(QEMUFile *f, void *pv, size_t size, + VMStateField *field, QJSON *vmdesc) +{ + CPU_DoubleU *v = pv; + qemu_put_be32s(f, &v->l.upper); + qemu_put_be32s(f, &v->l.lower); + return 0; +} + +const VMStateInfo vmstate_info_cpudouble = { + .name = "CPU_Double_U", + .get = get_cpudouble, + .put = put_cpudouble, +}; + +/* uint8_t buffers */ + +static int get_buffer(QEMUFile *f, void *pv, size_t size, + VMStateField *field) +{ + uint8_t *v = pv; + qemu_get_buffer(f, v, size); + return 0; +} + +static int put_buffer(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + uint8_t *v = pv; + qemu_put_buffer(f, v, size); + return 0; +} + +const VMStateInfo vmstate_info_buffer = { + .name = "buffer", + .get = get_buffer, + .put = put_buffer, +}; + +/* unused buffers: space that was used for some fields that are + not useful anymore */ + +static int get_unused_buffer(QEMUFile *f, void *pv, size_t size, + VMStateField *field) +{ + uint8_t buf[1024]; + int block_len; + + while (size > 0) { + block_len = MIN(sizeof(buf), size); + size -= block_len; + qemu_get_buffer(f, buf, block_len); + } + return 0; +} + +static int put_unused_buffer(QEMUFile *f, void *pv, size_t size, + VMStateField *field, QJSON *vmdesc) +{ + static const uint8_t buf[1024]; + int block_len; + + while (size > 0) { + block_len = MIN(sizeof(buf), size); + size -= block_len; + qemu_put_buffer(f, buf, block_len); + } + + return 0; +} + +const VMStateInfo vmstate_info_unused_buffer = { + .name = "unused_buffer", + .get = get_unused_buffer, + .put = put_unused_buffer, +}; + +/* vmstate_info_tmp, see VMSTATE_WITH_TMP, the idea is that we allocate + * a temporary buffer and the pre_load/pre_save methods in the child vmsd + * copy stuff from the parent into the child and do calculations to fill + * in fields that don't really exist in the parent but need to be in the + * stream. + */ +static int get_tmp(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + int ret; + const VMStateDescription *vmsd = field->vmsd; + int version_id = field->version_id; + void *tmp = g_malloc(size); + + /* Writes the parent field which is at the start of the tmp */ + *(void **)tmp = pv; + ret = vmstate_load_state(f, vmsd, tmp, version_id); + g_free(tmp); + return ret; +} + +static int put_tmp(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + const VMStateDescription *vmsd = field->vmsd; + void *tmp = g_malloc(size); + + /* Writes the parent field which is at the start of the tmp */ + *(void **)tmp = pv; + vmstate_save_state(f, vmsd, tmp, vmdesc); + g_free(tmp); + + return 0; +} + +const VMStateInfo vmstate_info_tmp = { + .name = "tmp", + .get = get_tmp, + .put = put_tmp, +}; + +/* bitmaps (as defined by bitmap.h). Note that size here is the size + * of the bitmap in bits. The on-the-wire format of a bitmap is 64 + * bit words with the bits in big endian order. The in-memory format + * is an array of 'unsigned long', which may be either 32 or 64 bits. + */ +/* This is the number of 64 bit words sent over the wire */ +#define BITS_TO_U64S(nr) DIV_ROUND_UP(nr, 64) +static int get_bitmap(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + unsigned long *bmp = pv; + int i, idx = 0; + for (i = 0; i < BITS_TO_U64S(size); i++) { + uint64_t w = qemu_get_be64(f); + bmp[idx++] = w; + if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) { + bmp[idx++] = w >> 32; + } + } + return 0; +} + +static int put_bitmap(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + unsigned long *bmp = pv; + int i, idx = 0; + for (i = 0; i < BITS_TO_U64S(size); i++) { + uint64_t w = bmp[idx++]; + if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) { + w |= ((uint64_t)bmp[idx++]) << 32; + } + qemu_put_be64(f, w); + } + + return 0; +} + +const VMStateInfo vmstate_info_bitmap = { + .name = "bitmap", + .get = get_bitmap, + .put = put_bitmap, +}; + +/* get for QTAILQ + * meta data about the QTAILQ is encoded in a VMStateField structure + */ +static int get_qtailq(QEMUFile *f, void *pv, size_t unused_size, + VMStateField *field) +{ + int ret = 0; + const VMStateDescription *vmsd = field->vmsd; + /* size of a QTAILQ element */ + size_t size = field->size; + /* offset of the QTAILQ entry in a QTAILQ element */ + size_t entry_offset = field->start; + int version_id = field->version_id; + void *elm; + + trace_get_qtailq(vmsd->name, version_id); + if (version_id > vmsd->version_id) { + error_report("%s %s", vmsd->name, "too new"); + trace_get_qtailq_end(vmsd->name, "too new", -EINVAL); + + return -EINVAL; + } + if (version_id < vmsd->minimum_version_id) { + error_report("%s %s", vmsd->name, "too old"); + trace_get_qtailq_end(vmsd->name, "too old", -EINVAL); + return -EINVAL; + } + + while (qemu_get_byte(f)) { + elm = g_malloc(size); + ret = vmstate_load_state(f, vmsd, elm, version_id); + if (ret) { + return ret; + } + QTAILQ_RAW_INSERT_TAIL(pv, elm, entry_offset); + } + + trace_get_qtailq_end(vmsd->name, "end", ret); + return ret; +} + +/* put for QTAILQ */ +static int put_qtailq(QEMUFile *f, void *pv, size_t unused_size, + VMStateField *field, QJSON *vmdesc) +{ + const VMStateDescription *vmsd = field->vmsd; + /* offset of the QTAILQ entry in a QTAILQ element*/ + size_t entry_offset = field->start; + void *elm; + + trace_put_qtailq(vmsd->name, vmsd->version_id); + + QTAILQ_RAW_FOREACH(elm, pv, entry_offset) { + qemu_put_byte(f, true); + vmstate_save_state(f, vmsd, elm, vmdesc); + } + qemu_put_byte(f, false); + + trace_put_qtailq_end(vmsd->name, "end"); + + return 0; +} +const VMStateInfo vmstate_info_qtailq = { + .name = "qtailq", + .get = get_qtailq, + .put = put_qtailq, +}; diff --git a/migration/vmstate.c b/migration/vmstate.c index 66c50ee3f4..ff54531b44 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -1,3 +1,15 @@ +/* + * VMState interpreter + * + * Copyright (c) 2009-2017 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + #include "qemu/osdep.h" #include "qemu-common.h" #include "migration/migration.h" @@ -5,7 +17,6 @@ #include "migration/vmstate.h" #include "qemu/bitops.h" #include "qemu/error-report.h" -#include "qemu/queue.h" #include "trace.h" #include "qjson.h" @@ -475,644 +486,3 @@ static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd, json_end_array(vmdesc); } } - -/* bool */ - -static int get_bool(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - bool *v = pv; - *v = qemu_get_byte(f); - return 0; -} - -static int put_bool(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - bool *v = pv; - qemu_put_byte(f, *v); - return 0; -} - -const VMStateInfo vmstate_info_bool = { - .name = "bool", - .get = get_bool, - .put = put_bool, -}; - -/* 8 bit int */ - -static int get_int8(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - int8_t *v = pv; - qemu_get_s8s(f, v); - return 0; -} - -static int put_int8(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - int8_t *v = pv; - qemu_put_s8s(f, v); - return 0; -} - -const VMStateInfo vmstate_info_int8 = { - .name = "int8", - .get = get_int8, - .put = put_int8, -}; - -/* 16 bit int */ - -static int get_int16(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - int16_t *v = pv; - qemu_get_sbe16s(f, v); - return 0; -} - -static int put_int16(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - int16_t *v = pv; - qemu_put_sbe16s(f, v); - return 0; -} - -const VMStateInfo vmstate_info_int16 = { - .name = "int16", - .get = get_int16, - .put = put_int16, -}; - -/* 32 bit int */ - -static int get_int32(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - int32_t *v = pv; - qemu_get_sbe32s(f, v); - return 0; -} - -static int put_int32(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - int32_t *v = pv; - qemu_put_sbe32s(f, v); - return 0; -} - -const VMStateInfo vmstate_info_int32 = { - .name = "int32", - .get = get_int32, - .put = put_int32, -}; - -/* 32 bit int. See that the received value is the same than the one - in the field */ - -static int get_int32_equal(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - int32_t *v = pv; - int32_t v2; - qemu_get_sbe32s(f, &v2); - - if (*v == v2) { - return 0; - } - error_report("%" PRIx32 " != %" PRIx32, *v, v2); - return -EINVAL; -} - -const VMStateInfo vmstate_info_int32_equal = { - .name = "int32 equal", - .get = get_int32_equal, - .put = put_int32, -}; - -/* 32 bit int. Check that the received value is non-negative - * and less than or equal to the one in the field. - */ - -static int get_int32_le(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - int32_t *cur = pv; - int32_t loaded; - qemu_get_sbe32s(f, &loaded); - - if (loaded >= 0 && loaded <= *cur) { - *cur = loaded; - return 0; - } - error_report("Invalid value %" PRId32 - " expecting positive value <= %" PRId32, - loaded, *cur); - return -EINVAL; -} - -const VMStateInfo vmstate_info_int32_le = { - .name = "int32 le", - .get = get_int32_le, - .put = put_int32, -}; - -/* 64 bit int */ - -static int get_int64(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - int64_t *v = pv; - qemu_get_sbe64s(f, v); - return 0; -} - -static int put_int64(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - int64_t *v = pv; - qemu_put_sbe64s(f, v); - return 0; -} - -const VMStateInfo vmstate_info_int64 = { - .name = "int64", - .get = get_int64, - .put = put_int64, -}; - -/* 8 bit unsigned int */ - -static int get_uint8(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - uint8_t *v = pv; - qemu_get_8s(f, v); - return 0; -} - -static int put_uint8(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - uint8_t *v = pv; - qemu_put_8s(f, v); - return 0; -} - -const VMStateInfo vmstate_info_uint8 = { - .name = "uint8", - .get = get_uint8, - .put = put_uint8, -}; - -/* 16 bit unsigned int */ - -static int get_uint16(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - uint16_t *v = pv; - qemu_get_be16s(f, v); - return 0; -} - -static int put_uint16(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - uint16_t *v = pv; - qemu_put_be16s(f, v); - return 0; -} - -const VMStateInfo vmstate_info_uint16 = { - .name = "uint16", - .get = get_uint16, - .put = put_uint16, -}; - -/* 32 bit unsigned int */ - -static int get_uint32(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - uint32_t *v = pv; - qemu_get_be32s(f, v); - return 0; -} - -static int put_uint32(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - uint32_t *v = pv; - qemu_put_be32s(f, v); - return 0; -} - -const VMStateInfo vmstate_info_uint32 = { - .name = "uint32", - .get = get_uint32, - .put = put_uint32, -}; - -/* 32 bit uint. See that the received value is the same than the one - in the field */ - -static int get_uint32_equal(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - uint32_t *v = pv; - uint32_t v2; - qemu_get_be32s(f, &v2); - - if (*v == v2) { - return 0; - } - error_report("%" PRIx32 " != %" PRIx32, *v, v2); - return -EINVAL; -} - -const VMStateInfo vmstate_info_uint32_equal = { - .name = "uint32 equal", - .get = get_uint32_equal, - .put = put_uint32, -}; - -/* 64 bit unsigned int */ - -static int get_uint64(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - uint64_t *v = pv; - qemu_get_be64s(f, v); - return 0; -} - -static int put_uint64(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - uint64_t *v = pv; - qemu_put_be64s(f, v); - return 0; -} - -const VMStateInfo vmstate_info_uint64 = { - .name = "uint64", - .get = get_uint64, - .put = put_uint64, -}; - -static int get_nullptr(QEMUFile *f, void *pv, size_t size, VMStateField *field) - -{ - if (qemu_get_byte(f) == VMS_NULLPTR_MARKER) { - return 0; - } - error_report("vmstate: get_nullptr expected VMS_NULLPTR_MARKER"); - return -EINVAL; -} - -static int put_nullptr(QEMUFile *f, void *pv, size_t size, - VMStateField *field, QJSON *vmdesc) - -{ - if (pv == NULL) { - qemu_put_byte(f, VMS_NULLPTR_MARKER); - return 0; - } - error_report("vmstate: put_nullptr must be called with pv == NULL"); - return -EINVAL; -} - -const VMStateInfo vmstate_info_nullptr = { - .name = "uint64", - .get = get_nullptr, - .put = put_nullptr, -}; - -/* 64 bit unsigned int. See that the received value is the same than the one - in the field */ - -static int get_uint64_equal(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - uint64_t *v = pv; - uint64_t v2; - qemu_get_be64s(f, &v2); - - if (*v == v2) { - return 0; - } - error_report("%" PRIx64 " != %" PRIx64, *v, v2); - return -EINVAL; -} - -const VMStateInfo vmstate_info_uint64_equal = { - .name = "int64 equal", - .get = get_uint64_equal, - .put = put_uint64, -}; - -/* 8 bit int. See that the received value is the same than the one - in the field */ - -static int get_uint8_equal(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - uint8_t *v = pv; - uint8_t v2; - qemu_get_8s(f, &v2); - - if (*v == v2) { - return 0; - } - error_report("%x != %x", *v, v2); - return -EINVAL; -} - -const VMStateInfo vmstate_info_uint8_equal = { - .name = "uint8 equal", - .get = get_uint8_equal, - .put = put_uint8, -}; - -/* 16 bit unsigned int int. See that the received value is the same than the one - in the field */ - -static int get_uint16_equal(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - uint16_t *v = pv; - uint16_t v2; - qemu_get_be16s(f, &v2); - - if (*v == v2) { - return 0; - } - error_report("%x != %x", *v, v2); - return -EINVAL; -} - -const VMStateInfo vmstate_info_uint16_equal = { - .name = "uint16 equal", - .get = get_uint16_equal, - .put = put_uint16, -}; - -/* floating point */ - -static int get_float64(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - float64 *v = pv; - - *v = make_float64(qemu_get_be64(f)); - return 0; -} - -static int put_float64(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - uint64_t *v = pv; - - qemu_put_be64(f, float64_val(*v)); - return 0; -} - -const VMStateInfo vmstate_info_float64 = { - .name = "float64", - .get = get_float64, - .put = put_float64, -}; - -/* CPU_DoubleU type */ - -static int get_cpudouble(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - CPU_DoubleU *v = pv; - qemu_get_be32s(f, &v->l.upper); - qemu_get_be32s(f, &v->l.lower); - return 0; -} - -static int put_cpudouble(QEMUFile *f, void *pv, size_t size, - VMStateField *field, QJSON *vmdesc) -{ - CPU_DoubleU *v = pv; - qemu_put_be32s(f, &v->l.upper); - qemu_put_be32s(f, &v->l.lower); - return 0; -} - -const VMStateInfo vmstate_info_cpudouble = { - .name = "CPU_Double_U", - .get = get_cpudouble, - .put = put_cpudouble, -}; - -/* uint8_t buffers */ - -static int get_buffer(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - uint8_t *v = pv; - qemu_get_buffer(f, v, size); - return 0; -} - -static int put_buffer(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - uint8_t *v = pv; - qemu_put_buffer(f, v, size); - return 0; -} - -const VMStateInfo vmstate_info_buffer = { - .name = "buffer", - .get = get_buffer, - .put = put_buffer, -}; - -/* unused buffers: space that was used for some fields that are - not useful anymore */ - -static int get_unused_buffer(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - uint8_t buf[1024]; - int block_len; - - while (size > 0) { - block_len = MIN(sizeof(buf), size); - size -= block_len; - qemu_get_buffer(f, buf, block_len); - } - return 0; -} - -static int put_unused_buffer(QEMUFile *f, void *pv, size_t size, - VMStateField *field, QJSON *vmdesc) -{ - static const uint8_t buf[1024]; - int block_len; - - while (size > 0) { - block_len = MIN(sizeof(buf), size); - size -= block_len; - qemu_put_buffer(f, buf, block_len); - } - - return 0; -} - -const VMStateInfo vmstate_info_unused_buffer = { - .name = "unused_buffer", - .get = get_unused_buffer, - .put = put_unused_buffer, -}; - -/* vmstate_info_tmp, see VMSTATE_WITH_TMP, the idea is that we allocate - * a temporary buffer and the pre_load/pre_save methods in the child vmsd - * copy stuff from the parent into the child and do calculations to fill - * in fields that don't really exist in the parent but need to be in the - * stream. - */ -static int get_tmp(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - int ret; - const VMStateDescription *vmsd = field->vmsd; - int version_id = field->version_id; - void *tmp = g_malloc(size); - - /* Writes the parent field which is at the start of the tmp */ - *(void **)tmp = pv; - ret = vmstate_load_state(f, vmsd, tmp, version_id); - g_free(tmp); - return ret; -} - -static int put_tmp(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - const VMStateDescription *vmsd = field->vmsd; - void *tmp = g_malloc(size); - - /* Writes the parent field which is at the start of the tmp */ - *(void **)tmp = pv; - vmstate_save_state(f, vmsd, tmp, vmdesc); - g_free(tmp); - - return 0; -} - -const VMStateInfo vmstate_info_tmp = { - .name = "tmp", - .get = get_tmp, - .put = put_tmp, -}; - -/* bitmaps (as defined by bitmap.h). Note that size here is the size - * of the bitmap in bits. The on-the-wire format of a bitmap is 64 - * bit words with the bits in big endian order. The in-memory format - * is an array of 'unsigned long', which may be either 32 or 64 bits. - */ -/* This is the number of 64 bit words sent over the wire */ -#define BITS_TO_U64S(nr) DIV_ROUND_UP(nr, 64) -static int get_bitmap(QEMUFile *f, void *pv, size_t size, VMStateField *field) -{ - unsigned long *bmp = pv; - int i, idx = 0; - for (i = 0; i < BITS_TO_U64S(size); i++) { - uint64_t w = qemu_get_be64(f); - bmp[idx++] = w; - if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) { - bmp[idx++] = w >> 32; - } - } - return 0; -} - -static int put_bitmap(QEMUFile *f, void *pv, size_t size, VMStateField *field, - QJSON *vmdesc) -{ - unsigned long *bmp = pv; - int i, idx = 0; - for (i = 0; i < BITS_TO_U64S(size); i++) { - uint64_t w = bmp[idx++]; - if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) { - w |= ((uint64_t)bmp[idx++]) << 32; - } - qemu_put_be64(f, w); - } - - return 0; -} - -const VMStateInfo vmstate_info_bitmap = { - .name = "bitmap", - .get = get_bitmap, - .put = put_bitmap, -}; - -/* get for QTAILQ - * meta data about the QTAILQ is encoded in a VMStateField structure - */ -static int get_qtailq(QEMUFile *f, void *pv, size_t unused_size, - VMStateField *field) -{ - int ret = 0; - const VMStateDescription *vmsd = field->vmsd; - /* size of a QTAILQ element */ - size_t size = field->size; - /* offset of the QTAILQ entry in a QTAILQ element */ - size_t entry_offset = field->start; - int version_id = field->version_id; - void *elm; - - trace_get_qtailq(vmsd->name, version_id); - if (version_id > vmsd->version_id) { - error_report("%s %s", vmsd->name, "too new"); - trace_get_qtailq_end(vmsd->name, "too new", -EINVAL); - - return -EINVAL; - } - if (version_id < vmsd->minimum_version_id) { - error_report("%s %s", vmsd->name, "too old"); - trace_get_qtailq_end(vmsd->name, "too old", -EINVAL); - return -EINVAL; - } - - while (qemu_get_byte(f)) { - elm = g_malloc(size); - ret = vmstate_load_state(f, vmsd, elm, version_id); - if (ret) { - return ret; - } - QTAILQ_RAW_INSERT_TAIL(pv, elm, entry_offset); - } - - trace_get_qtailq_end(vmsd->name, "end", ret); - return ret; -} - -/* put for QTAILQ */ -static int put_qtailq(QEMUFile *f, void *pv, size_t unused_size, - VMStateField *field, QJSON *vmdesc) -{ - const VMStateDescription *vmsd = field->vmsd; - /* offset of the QTAILQ entry in a QTAILQ element*/ - size_t entry_offset = field->start; - void *elm; - - trace_put_qtailq(vmsd->name, vmsd->version_id); - - QTAILQ_RAW_FOREACH(elm, pv, entry_offset) { - qemu_put_byte(f, true); - vmstate_save_state(f, vmsd, elm, vmdesc); - } - qemu_put_byte(f, false); - - trace_put_qtailq_end(vmsd->name, "end"); - - return 0; -} -const VMStateInfo vmstate_info_qtailq = { - .name = "qtailq", - .get = get_qtailq, - .put = put_qtailq, -}; diff --git a/tests/Makefile.include b/tests/Makefile.include index 4277597e93..75893838e5 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -574,7 +574,7 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ hw/core/reset.o \ $(test-qapi-obj-y) tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ - migration/vmstate.o migration/qemu-file.o \ + migration/vmstate.o migration/vmstate-types.o migration/qemu-file.o \ migration/qemu-file-channel.o migration/qjson.o \ $(test-io-obj-y) tests/test-timed-average$(EXESUF): tests/test-timed-average.o $(test-util-obj-y) From 82b9d0f06ab23c0c06b0a8c3adac4c39c38db67a Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Mon, 17 Apr 2017 18:59:13 +0200 Subject: [PATCH 14/18] migration: Remove qemu-file.h from vmstate.h Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert -- minor rearangements due to the rebase --- include/hw/hw.h | 1 + include/migration/vmstate.h | 3 --- migration/block.c | 1 + migration/colo.c | 1 + migration/postcopy-ram.c | 1 + migration/ram.c | 1 + tests/test-vmstate.c | 1 + 7 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/hw/hw.h b/include/hw/hw.h index e22d4ce5fa..af9eae11c5 100644 --- a/include/hw/hw.h +++ b/include/hw/hw.h @@ -11,6 +11,7 @@ #include "exec/memory.h" #include "hw/irq.h" #include "migration/vmstate.h" +#include "migration/qemu-file.h" #include "qemu/module.h" #include "sysemu/reset.h" diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index dacb052551..f97411d31f 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -27,9 +27,6 @@ #ifndef QEMU_VMSTATE_H #define QEMU_VMSTATE_H -#ifndef CONFIG_USER_ONLY -#include "migration/qemu-file.h" -#endif #include "migration/qjson.h" typedef void SaveStateHandler(QEMUFile *f, void *opaque); diff --git a/migration/block.c b/migration/block.c index 5d229264bf..5baf46d0e3 100644 --- a/migration/block.c +++ b/migration/block.c @@ -26,6 +26,7 @@ #include "migration/block.h" #include "migration/migration.h" #include "sysemu/blockdev.h" +#include "migration/qemu-file.h" #include "sysemu/block-backend.h" #define BLOCK_SIZE (1 << 20) diff --git a/migration/colo.c b/migration/colo.c index 73ebd64cbb..929b31c50c 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -15,6 +15,7 @@ #include "sysemu/sysemu.h" #include "qemu-file-channel.h" #include "migration/migration.h" +#include "migration/qemu-file.h" #include "migration/colo.h" #include "migration/block.h" #include "io/channel-buffer.h" diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 63b850128e..0e2a996168 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -20,6 +20,7 @@ #include "qemu-common.h" #include "migration/migration.h" +#include "migration/qemu-file.h" #include "postcopy-ram.h" #include "sysemu/sysemu.h" #include "sysemu/balloon.h" diff --git a/migration/ram.c b/migration/ram.c index c14269fd16..8ce8c07a68 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -37,6 +37,7 @@ #include "qemu/main-loop.h" #include "xbzrle.h" #include "migration/migration.h" +#include "migration/qemu-file.h" #include "postcopy-ram.h" #include "exec/address-spaces.h" #include "migration/page_cache.h" diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index 1c135708f4..25389bcce4 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -27,6 +27,7 @@ #include "qemu-common.h" #include "migration/migration.h" #include "migration/vmstate.h" +#include "migration/qemu-file.h" #include "../migration/qemu-file-channel.h" #include "qemu/coroutine.h" #include "io/channel-file.h" From 987772d9e704eb251f4a96e045e991f81778fdd4 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Mon, 17 Apr 2017 19:02:59 +0200 Subject: [PATCH 15/18] migration: Remove vmstate.h from migration.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daudé --- Minor rearrangements due to rebase --- include/migration/migration.h | 1 - migration/block.c | 1 + migration/colo-comm.c | 1 + migration/migration.c | 1 + migration/ram.c | 1 + 5 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 8280df12e5..0e807b63b8 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -18,7 +18,6 @@ #include "qemu-common.h" #include "qemu/thread.h" #include "qemu/notify.h" -#include "migration/vmstate.h" #include "io/channel.h" #include "qapi-types.h" #include "exec/cpu-common.h" diff --git a/migration/block.c b/migration/block.c index 5baf46d0e3..13f90d3f17 100644 --- a/migration/block.c +++ b/migration/block.c @@ -27,6 +27,7 @@ #include "migration/migration.h" #include "sysemu/blockdev.h" #include "migration/qemu-file.h" +#include "migration/vmstate.h" #include "sysemu/block-backend.h" #define BLOCK_SIZE (1 << 20) diff --git a/migration/colo-comm.c b/migration/colo-comm.c index 3d917988e9..8bfdf6825a 100644 --- a/migration/colo-comm.c +++ b/migration/colo-comm.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" #include "migration/migration.h" #include "migration/colo.h" +#include "migration/vmstate.h" #include "trace.h" typedef struct { diff --git a/migration/migration.c b/migration/migration.c index 2d9379cc4e..9fe474b63b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -21,6 +21,7 @@ #include "migration/migration.h" #include "qemu-file-channel.h" #include "migration/qemu-file.h" +#include "migration/vmstate.h" #include "sysemu/sysemu.h" #include "block/block.h" #include "qapi/qmp/qerror.h" diff --git a/migration/ram.c b/migration/ram.c index 8ce8c07a68..c07a9c08d9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -38,6 +38,7 @@ #include "xbzrle.h" #include "migration/migration.h" #include "migration/qemu-file.h" +#include "migration/vmstate.h" #include "postcopy-ram.h" #include "exec/address-spaces.h" #include "migration/page_cache.h" From 68ba3b07436396733f7313c81956410af6d17083 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 6 Apr 2017 12:12:21 +0200 Subject: [PATCH 16/18] migration: migration.h was not needed This files don't use any function from migration.h, so drop it. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu --- block/qed.c | 1 - hw/i386/pc_q35.c | 1 - hw/virtio/vhost-user.c | 1 - hw/virtio/vhost-vsock.c | 1 - hw/virtio/virtio.c | 1 - monitor.c | 1 - 6 files changed, 6 deletions(-) diff --git a/block/qed.c b/block/qed.c index fd76817cbb..8d899fd479 100644 --- a/block/qed.c +++ b/block/qed.c @@ -19,7 +19,6 @@ #include "trace.h" #include "qed.h" #include "qapi/qmp/qerror.h" -#include "migration/migration.h" #include "sysemu/block-backend.h" static const AIOCBInfo qed_aiocb_info = { diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index f243203844..1523ef39e1 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -46,7 +46,6 @@ #include "hw/ide/ahci.h" #include "hw/usb.h" #include "qemu/error-report.h" -#include "migration/migration.h" #include "sysemu/numa.h" /* ICH9 AHCI has 6 ports */ diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 32a95a8c69..b87a176770 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -17,7 +17,6 @@ #include "sysemu/kvm.h" #include "qemu/error-report.h" #include "qemu/sockets.h" -#include "migration/migration.h" #include #include diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index b4815629e1..49e0022533 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -17,7 +17,6 @@ #include "qapi/error.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" -#include "migration/migration.h" #include "qemu/error-report.h" #include "hw/virtio/vhost-vsock.h" #include "qemu/iov.h" diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 890b4d7eb7..f99d99fd78 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -21,7 +21,6 @@ #include "hw/virtio/virtio.h" #include "qemu/atomic.h" #include "hw/virtio/virtio-bus.h" -#include "migration/migration.h" #include "hw/virtio/virtio-access.h" #include "sysemu/dma.h" diff --git a/monitor.c b/monitor.c index afbacfe1cb..baa73c98b7 100644 --- a/monitor.c +++ b/monitor.c @@ -49,7 +49,6 @@ #include "disas/disas.h" #include "sysemu/balloon.h" #include "qemu/timer.h" -#include "migration/migration.h" #include "sysemu/hw_accel.h" #include "qemu/acl.h" #include "sysemu/tpm.h" From 51180423a226adbd80d64bf75b8522256b1266f1 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Mon, 24 Apr 2017 20:50:19 +0200 Subject: [PATCH 17/18] exec: Create include for target_page_size() That is the only function that we need from exec.c, and having to include the whole sysemu.h for this. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- /me leans to be less sloppy with copyright notices thanks Dave --- exec.c | 1 + include/exec/target_page.h | 19 +++++++++++++++++++ include/sysemu/sysemu.h | 1 - migration/migration.c | 1 + migration/postcopy-ram.c | 1 + migration/savevm.c | 1 + 6 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 include/exec/target_page.h diff --git a/exec.c b/exec.c index 96e3ac98e1..de2961b583 100644 --- a/exec.c +++ b/exec.c @@ -24,6 +24,7 @@ #include "qemu/cutils.h" #include "cpu.h" #include "exec/exec-all.h" +#include "exec/target_page.h" #include "tcg.h" #include "hw/qdev-core.h" #if !defined(CONFIG_USER_ONLY) diff --git a/include/exec/target_page.h b/include/exec/target_page.h new file mode 100644 index 0000000000..626eda8029 --- /dev/null +++ b/include/exec/target_page.h @@ -0,0 +1,19 @@ +/* + * Target page sizes and friends for non target files + * + * Copyright (c) 2017 Red Hat Inc + * + * Authors: + * David Alan Gilbert + * Juan Quintela + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef EXEC_TARGET_PAGE_H +#define EXEC_TARGET_PAGE_H + +size_t qemu_target_page_size(void); + +#endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 765358ea45..ed8fe3bf34 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -67,7 +67,6 @@ int qemu_reset_requested_get(void); void qemu_system_killed(int signal, pid_t pid); void qemu_system_reset(bool report); void qemu_system_guest_panicked(GuestPanicInformation *info); -size_t qemu_target_page_size(void); void qemu_add_exit_notifier(Notifier *notify); void qemu_remove_exit_notifier(Notifier *notify); diff --git a/migration/migration.c b/migration/migration.c index 9fe474b63b..ad29e53400 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -37,6 +37,7 @@ #include "qom/cpu.h" #include "exec/memory.h" #include "exec/address-spaces.h" +#include "exec/target_page.h" #include "io/channel-buffer.h" #include "io/channel-tls.h" #include "migration/colo.h" diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 0e2a996168..a37620dac6 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "exec/target_page.h" #include "migration/migration.h" #include "migration/qemu-file.h" #include "postcopy-ram.h" diff --git a/migration/savevm.c b/migration/savevm.c index 85651030b4..8763700bd5 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -43,6 +43,7 @@ #include "qemu/queue.h" #include "sysemu/cpus.h" #include "exec/memory.h" +#include "exec/target_page.h" #include "qmp-commands.h" #include "trace.h" #include "qemu/bitops.h" From 46d702b106d20beda2fcd0f96ddc44855ba262b3 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Mon, 24 Apr 2017 21:03:48 +0200 Subject: [PATCH 18/18] migration: Make savevm.c target independent It only needed TARGET_PAGE_SIZE/BITS/BITS_MIN values, so just export them from exec.h Signed-off-by: Juan Quintela Reviewed-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- Makefile.target | 2 +- exec.c | 9 +++++++++ include/exec/target_page.h | 2 ++ migration/Makefile.objs | 2 +- migration/savevm.c | 14 +++++++------- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Makefile.target b/Makefile.target index 465a633367..ce8dfe44a8 100644 --- a/Makefile.target +++ b/Makefile.target @@ -146,7 +146,7 @@ obj-$(CONFIG_KVM) += kvm-all.o obj-y += memory.o cputlb.o obj-y += memory_mapping.o obj-y += dump.o -obj-y += migration/ram.o migration/savevm.o +obj-y += migration/ram.o LIBS := $(libs_softmmu) $(LIBS) # Hardware support diff --git a/exec.c b/exec.c index de2961b583..ff16f04f2b 100644 --- a/exec.c +++ b/exec.c @@ -3444,6 +3444,15 @@ size_t qemu_target_page_size(void) return TARGET_PAGE_SIZE; } +int qemu_target_page_bits(void) +{ + return TARGET_PAGE_BITS; +} + +int qemu_target_page_bits_min(void) +{ + return TARGET_PAGE_BITS_MIN; +} #endif /* diff --git a/include/exec/target_page.h b/include/exec/target_page.h index 626eda8029..96726c36a4 100644 --- a/include/exec/target_page.h +++ b/include/exec/target_page.h @@ -15,5 +15,7 @@ #define EXEC_TARGET_PAGE_H size_t qemu_target_page_size(void); +int qemu_target_page_bits(void); +int qemu_target_page_bits_min(void); #endif diff --git a/migration/Makefile.objs b/migration/Makefile.objs index 3272415de8..90f8c1f177 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -1,5 +1,5 @@ common-obj-y += migration.o socket.o fd.o exec.o -common-obj-y += tls.o channel.o +common-obj-y += tls.o channel.o savevm.o common-obj-y += colo-comm.o colo.o colo-failover.o common-obj-y += vmstate.o vmstate-types.o page_cache.o common-obj-y += qemu-file.o diff --git a/migration/savevm.c b/migration/savevm.c index 8763700bd5..d971e5ee47 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -27,7 +27,6 @@ */ #include "qemu/osdep.h" -#include "cpu.h" #include "hw/boards.h" #include "hw/hw.h" #include "hw/qdev.h" @@ -288,7 +287,7 @@ static void configuration_pre_save(void *opaque) state->len = strlen(current_name); state->name = current_name; - state->target_page_bits = TARGET_PAGE_BITS; + state->target_page_bits = qemu_target_page_bits(); } static int configuration_pre_load(void *opaque) @@ -299,7 +298,7 @@ static int configuration_pre_load(void *opaque) * predates the variable-target-page-bits support and is using the * minimum possible value for this CPU. */ - state->target_page_bits = TARGET_PAGE_BITS_MIN; + state->target_page_bits = qemu_target_page_bits_min(); return 0; } @@ -314,9 +313,9 @@ static int configuration_post_load(void *opaque, int version_id) return -EINVAL; } - if (state->target_page_bits != TARGET_PAGE_BITS) { + if (state->target_page_bits != qemu_target_page_bits()) { error_report("Received TARGET_PAGE_BITS is %d but local is %d", - state->target_page_bits, TARGET_PAGE_BITS); + state->target_page_bits, qemu_target_page_bits()); return -EINVAL; } @@ -332,7 +331,8 @@ static int configuration_post_load(void *opaque, int version_id) */ static bool vmstate_target_page_bits_needed(void *opaque) { - return TARGET_PAGE_BITS > TARGET_PAGE_BITS_MIN; + return qemu_target_page_bits() + > qemu_target_page_bits_min(); } static const VMStateDescription vmstate_target_page_bits = { @@ -1138,7 +1138,7 @@ void qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only) } vmdesc = qjson_new(); - json_prop_int(vmdesc, "page_size", TARGET_PAGE_SIZE); + json_prop_int(vmdesc, "page_size", qemu_target_page_size()); json_start_array(vmdesc, "devices"); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {