Lines Matching +full:cmd +full:- +full:cnt +full:- +full:name
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 * Copyright (c) 2009-2015 Red Hat Inc
34 #include "migration-stats.h"
39 #include "migration/channel-block.h"
42 #include "qemu-file.h"
44 #include "postcopy-ram.h"
46 #include "qapi/qapi-commands-migration.h"
47 #include "qapi/clone-visitor.h"
48 #include "qapi/qapi-builtin-visit.h"
49 #include "qemu/error-report.h"
53 #include "exec/page-vary.h"
57 #include "qemu/main-loop.h"
59 #include "block/thread-pool.h"
61 #include "io/channel-buffer.h"
62 #include "io/channel-file.h"
102 ssize_t len; /* -1 = variable */
103 const char *name; member
105 [MIG_CMD_INVALID] = { .len = -1, .name = "INVALID" },
106 [MIG_CMD_OPEN_RETURN_PATH] = { .len = 0, .name = "OPEN_RETURN_PATH" },
107 [MIG_CMD_PING] = { .len = sizeof(uint32_t), .name = "PING" },
108 [MIG_CMD_POSTCOPY_ADVISE] = { .len = -1, .name = "POSTCOPY_ADVISE" },
109 [MIG_CMD_POSTCOPY_LISTEN] = { .len = 0, .name = "POSTCOPY_LISTEN" },
110 [MIG_CMD_POSTCOPY_RUN] = { .len = 0, .name = "POSTCOPY_RUN" },
112 .len = -1, .name = "POSTCOPY_RAM_DISCARD" },
113 [MIG_CMD_POSTCOPY_RESUME] = { .len = 0, .name = "POSTCOPY_RESUME" },
114 [MIG_CMD_PACKAGED] = { .len = 4, .name = "PACKAGED" },
115 [MIG_CMD_RECV_BITMAP] = { .len = -1, .name = "RECV_BITMAP" },
116 [MIG_CMD_SWITCHOVER_START] = { .len = 0, .name = "SWITCHOVER_START" },
117 [MIG_CMD_MAX] = { .len = -1, .name = "MAX" },
122 * - postcopy RAM only
126 * - postcopy RAM and postcopy dirty bitmaps
129 * - postcopy dirty bitmaps only
133 * not break format self-description ability. Good way is to introduce some
142 assert(!mis->load_threads); in qemu_loadvm_thread_pool_create()
143 mis->load_threads = thread_pool_new(); in qemu_loadvm_thread_pool_create()
144 mis->load_threads_abort = false; in qemu_loadvm_thread_pool_create()
149 qatomic_set(&mis->load_threads_abort, true); in qemu_loadvm_thread_pool_destroy()
152 g_clear_pointer(&mis->load_threads, thread_pool_free); in qemu_loadvm_thread_pool_destroy()
160 thread_pool_wait(mis->load_threads); in qemu_loadvm_thread_pool_wait()
180 * Not in qemu-file.c to not add qemu-timer.c as dependency to qemu-file.c
196 if (expire_time != -1) { in timer_get()
205 * Not in vmstate.c to not add qemu-timer.c as dependency to vmstate.c
226 .name = "timer",
260 const char *name; member
294 if (should_validate_capability(i) && s->capabilities[i]) { in get_validatable_capabilities_count()
304 const char *current_name = MACHINE_GET_CLASS(current_machine)->name; in configuration_pre_save()
308 state->len = strlen(current_name); in configuration_pre_save()
309 state->name = current_name; in configuration_pre_save()
310 state->target_page_bits = qemu_target_page_bits(); in configuration_pre_save()
312 state->caps_count = get_validatable_capabilities_count(); in configuration_pre_save()
313 state->capabilities = g_renew(MigrationCapability, state->capabilities, in configuration_pre_save()
314 state->caps_count); in configuration_pre_save()
316 if (should_validate_capability(i) && s->capabilities[i]) { in configuration_pre_save()
317 state->capabilities[j++] = i; in configuration_pre_save()
320 state->uuid = qemu_uuid; in configuration_pre_save()
329 g_free(state->capabilities); in configuration_post_save()
330 state->capabilities = NULL; in configuration_post_save()
331 state->caps_count = 0; in configuration_post_save()
339 /* If there is no target-page-bits subsection it means the source in configuration_pre_load()
340 * predates the variable-target-page-bits support and is using the in configuration_pre_load()
343 state->target_page_bits = migration_legacy_page_bits(); in configuration_pre_load()
355 for (i = 0; i < state->caps_count; i++) { in configuration_validate_capabilities()
356 MigrationCapability capability = state->capabilities[i]; in configuration_validate_capabilities()
366 target_state = s->capabilities[i]; in configuration_validate_capabilities()
384 const char *current_name = MACHINE_GET_CLASS(current_machine)->name; in configuration_post_load()
387 if (strncmp(state->name, current_name, state->len) != 0) { in configuration_post_load()
389 (int) state->len, state->name, current_name); in configuration_post_load()
390 ret = -EINVAL; in configuration_post_load()
394 if (state->target_page_bits != qemu_target_page_bits()) { in configuration_post_load()
396 state->target_page_bits, qemu_target_page_bits()); in configuration_post_load()
397 ret = -EINVAL; in configuration_post_load()
402 ret = -EINVAL; in configuration_post_load()
407 g_free((void *)state->name); in configuration_post_load()
408 state->name = NULL; in configuration_post_load()
409 state->len = 0; in configuration_post_load()
410 g_free(state->capabilities); in configuration_post_load()
411 state->capabilities = NULL; in configuration_post_load()
412 state->caps_count = 0; in configuration_post_load()
435 return -EINVAL; in get_capability()
452 .name = "capability",
457 /* The target-page-bits subsection is present only if the
459 * minimum page size for a variable-page-size guest CPU).
470 .name = "configuration/target-page-bits",
486 .name = "configuration/capabilities",
515 qemu_uuid_unparse(&state->uuid, uuid_src); in vmstate_uuid_post_load()
520 if (!qemu_uuid_is_equal(&state->uuid, &qemu_uuid)) { in vmstate_uuid_post_load()
521 qemu_uuid_unparse(&state->uuid, uuid_src); in vmstate_uuid_post_load()
524 return -EINVAL; in vmstate_uuid_post_load()
530 .name = "configuration/uuid",
542 .name = "configuration",
550 VMSTATE_VBUFFER_ALLOC_UINT32(name, SaveState, 0, NULL, len),
570 fprintf(out_file, "%*s\"field\": \"%s\",\n", indent, "", field->name); in dump_vmstate_vmsf()
572 field->version_id); in dump_vmstate_vmsf()
574 field->field_exists ? "true" : "false"); in dump_vmstate_vmsf()
575 if (field->flags & VMS_ARRAY) { in dump_vmstate_vmsf()
576 fprintf(out_file, "%*s\"num\": %d,\n", indent, "", field->num); in dump_vmstate_vmsf()
578 fprintf(out_file, "%*s\"size\": %zu", indent, "", field->size); in dump_vmstate_vmsf()
579 if (field->vmsd != NULL) { in dump_vmstate_vmsf()
581 dump_vmstate_vmsd(out_file, field->vmsd, indent, false); in dump_vmstate_vmsf()
583 fprintf(out_file, "\n%*s}", indent - 2, ""); in dump_vmstate_vmsf()
605 fprintf(out_file, "%*s\"name\": \"%s\",\n", indent, "", vmsd->name); in dump_vmstate_vmsd()
607 vmsd->version_id); in dump_vmstate_vmsd()
609 vmsd->minimum_version_id); in dump_vmstate_vmsd()
610 if (vmsd->fields != NULL) { in dump_vmstate_vmsd()
611 const VMStateField *field = vmsd->fields; in dump_vmstate_vmsd()
616 while (field->name != NULL) { in dump_vmstate_vmsd()
617 if (field->flags & VMS_MUST_EXIST) { in dump_vmstate_vmsd()
629 assert(field->flags == VMS_END); in dump_vmstate_vmsd()
632 if (vmsd->subsections != NULL) { in dump_vmstate_vmsd()
633 const VMStateDescription * const *subsection = vmsd->subsections; in dump_vmstate_vmsd()
648 fprintf(out_file, "\n%*s}", indent - 2, ""); in dump_vmstate_vmsd()
658 fprintf(out_file, " \"Name\": \"%s\"\n", mc->name); in dump_machine_type()
672 for (elt = list; elt; elt = elt->next) { in dump_vmstate_json_to_file()
673 DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data, in dump_vmstate_json_to_file()
675 const char *name; in dump_vmstate_json_to_file() local
678 if (!dc->vmsd) { in dump_vmstate_json_to_file()
685 name = object_class_get_name(OBJECT_CLASS(dc)); in dump_vmstate_json_to_file()
686 fprintf(out_file, "%*s\"%s\": {\n", indent, "", name); in dump_vmstate_json_to_file()
688 fprintf(out_file, "%*s\"Name\": \"%s\",\n", indent, "", name); in dump_vmstate_json_to_file()
690 dc->vmsd->version_id); in dump_vmstate_json_to_file()
692 dc->vmsd->minimum_version_id); in dump_vmstate_json_to_file()
694 dump_vmstate_vmsd(out_file, dc->vmsd, indent, false); in dump_vmstate_json_to_file()
696 fprintf(out_file, "\n%*s}", indent - 2, ""); in dump_vmstate_json_to_file()
710 if (strcmp(idstr, se->idstr) == 0 in calculate_new_instance_id()
711 && instance_id <= se->instance_id) { in calculate_new_instance_id()
712 instance_id = se->instance_id + 1; in calculate_new_instance_id()
726 if (!se->compat) { in calculate_compat_instance_id()
730 if (strcmp(idstr, se->compat->idstr) == 0 in calculate_compat_instance_id()
731 && instance_id <= se->compat->instance_id) { in calculate_compat_instance_id()
732 instance_id = se->compat->instance_id + 1; in calculate_compat_instance_id()
740 if (se->vmsd) { in save_state_priority()
741 return se->vmsd->priority; in save_state_priority()
759 if (find_se(nse->idstr, nse->instance_id)) { in savevm_state_handler_insert()
762 nse->idstr, nse->instance_id); in savevm_state_handler_insert()
766 for (i = priority - 1; i >= 0; i--) { in savevm_state_handler_insert()
803 Meanwhile pass -1 as instance_id if you do not already have a clearly
814 se->version_id = version_id; in register_savevm_live()
815 se->section_id = savevm_state.global_section_id++; in register_savevm_live()
816 se->ops = ops; in register_savevm_live()
817 se->opaque = opaque; in register_savevm_live()
818 se->vmsd = NULL; in register_savevm_live()
820 if (ops->save_setup != NULL) { in register_savevm_live()
821 se->is_ram = 1; in register_savevm_live()
824 pstrcat(se->idstr, sizeof(se->idstr), idstr); in register_savevm_live()
827 se->instance_id = calculate_new_instance_id(se->idstr); in register_savevm_live()
829 se->instance_id = instance_id; in register_savevm_live()
831 assert(!se->compat || se->instance_id == 0); in register_savevm_live()
852 if (strcmp(se->idstr, id) == 0 && se->opaque == opaque) { in unregister_savevm()
854 g_free(se->compat); in unregister_savevm()
866 const VMStateField *field = vmsd->fields; in vmstate_check()
867 const VMStateDescription * const *subsection = vmsd->subsections; in vmstate_check()
870 while (field->name) { in vmstate_check()
871 if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) { in vmstate_check()
873 vmstate_check(field->vmsd); in vmstate_check()
879 if (field->flags != VMS_END) { in vmstate_check()
880 error_report("VMSTATE not ending with VMS_END: %s", vmsd->name); in vmstate_check()
887 * The name of a subsection should start with the name of the in vmstate_check()
890 assert(!strncmp(vmsd->name, (*subsection)->name, strlen(vmsd->name))); in vmstate_check()
906 assert(alias_id == -1 || required_for_version >= vmsd->minimum_version_id); in vmstate_register_with_alias_id()
909 se->version_id = vmsd->version_id; in vmstate_register_with_alias_id()
910 se->section_id = savevm_state.global_section_id++; in vmstate_register_with_alias_id()
911 se->opaque = opaque; in vmstate_register_with_alias_id()
912 se->vmsd = vmsd; in vmstate_register_with_alias_id()
913 se->alias_id = alias_id; in vmstate_register_with_alias_id()
918 if (snprintf(se->idstr, sizeof(se->idstr), "%s/", id) >= in vmstate_register_with_alias_id()
919 sizeof(se->idstr)) { in vmstate_register_with_alias_id()
924 return -1; in vmstate_register_with_alias_id()
928 se->compat = g_new0(CompatEntry, 1); in vmstate_register_with_alias_id()
929 pstrcpy(se->compat->idstr, sizeof(se->compat->idstr), vmsd->name); in vmstate_register_with_alias_id()
930 se->compat->instance_id = instance_id == VMSTATE_INSTANCE_ID_ANY ? in vmstate_register_with_alias_id()
931 calculate_compat_instance_id(vmsd->name) : instance_id; in vmstate_register_with_alias_id()
935 pstrcat(se->idstr, sizeof(se->idstr), vmsd->name); in vmstate_register_with_alias_id()
938 se->instance_id = calculate_new_instance_id(se->idstr); in vmstate_register_with_alias_id()
940 se->instance_id = instance_id; in vmstate_register_with_alias_id()
947 assert(!se->compat || se->instance_id == 0); in vmstate_register_with_alias_id()
958 if (se->vmsd == vmsd && se->opaque == opaque) { in vmstate_unregister()
960 g_free(se->compat); in vmstate_unregister()
968 trace_vmstate_load(se->idstr, se->vmsd ? se->vmsd->name : "(old)"); in vmstate_load()
969 if (!se->vmsd) { /* Old style */ in vmstate_load()
970 return se->ops->load_state(f, se->opaque, se->load_version_id); in vmstate_load()
972 return vmstate_load_state(f, se->vmsd, se->opaque, se->load_version_id); in vmstate_load()
979 se->ops->save_state(f, se->opaque); in vmstate_save_old_style()
980 uint64_t size = qemu_file_transferred(f) - old_offset; in vmstate_save_old_style()
986 json_writer_str(vmdesc, "name", "data"); in vmstate_save_old_style()
1001 qemu_put_be32(f, se->section_id); in save_section_header()
1006 size_t len = strlen(se->idstr); in save_section_header()
1008 qemu_put_buffer(f, (uint8_t *)se->idstr, len); in save_section_header()
1010 qemu_put_be32(f, se->instance_id); in save_section_header()
1011 qemu_put_be32(f, se->version_id); in save_section_header()
1021 if (migrate_get_current()->send_section_footer) { in save_section_footer()
1023 qemu_put_be32(f, se->section_id); in save_section_footer()
1032 if ((!se->ops || !se->ops->save_state) && !se->vmsd) { in vmstate_save()
1035 if (se->vmsd && !vmstate_section_needed(se->vmsd, se->opaque)) { in vmstate_save()
1036 trace_savevm_section_skip(se->idstr, se->section_id); in vmstate_save()
1040 trace_savevm_section_start(se->idstr, se->section_id); in vmstate_save()
1044 json_writer_str(vmdesc, "name", se->idstr); in vmstate_save()
1045 json_writer_int64(vmdesc, "instance_id", se->instance_id); in vmstate_save()
1048 trace_vmstate_save(se->idstr, se->vmsd ? se->vmsd->name : "(old)"); in vmstate_save()
1049 if (!se->vmsd) { in vmstate_save()
1052 ret = vmstate_save_state_with_err(f, se->vmsd, se->opaque, vmdesc, in vmstate_save()
1059 trace_savevm_section_end(se->idstr, se->section_id, 0); in vmstate_save()
1116 * -ve on error
1129 return -1; in qemu_savevm_send_packaged()
1162 * byte Length of name field (not including 0)
1163 * n x byte RAM block name
1169 * name: RAMBlock name that these entries are part of
1175 void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f, const char *name, in qemu_savevm_send_postcopy_ram_discard() argument
1183 size_t name_len = strlen(name); in qemu_savevm_send_postcopy_ram_discard()
1185 trace_qemu_savevm_send_postcopy_ram_discard(name, len); in qemu_savevm_send_postcopy_ram_discard()
1190 memcpy(buf + 2, name, name_len); in qemu_savevm_send_postcopy_ram_discard()
1255 if (se->vmsd && se->vmsd->unmigratable) { in qemu_savevm_state_blocked()
1256 error_setg(errp, "State blocked by non-migratable device '%s'", in qemu_savevm_state_blocked()
1257 se->idstr); in qemu_savevm_state_blocked()
1269 if (se->vmsd && se->vmsd->unmigratable) { in qemu_savevm_non_migratable_list()
1271 g_strdup_printf("non-migratable device: %s", in qemu_savevm_non_migratable_list()
1272 se->idstr)); in qemu_savevm_non_migratable_list()
1280 JSONWriter *vmdesc = s->vmdesc; in qemu_savevm_state_header()
1286 if (s->send_configuration) { in qemu_savevm_state_header()
1312 if (se->vmsd && se->vmsd->dev_unplug_pending && in qemu_savevm_state_guest_unplug_pending()
1313 se->vmsd->dev_unplug_pending(se->opaque)) { in qemu_savevm_state_guest_unplug_pending()
1327 if (!se->ops || !se->ops->save_prepare) { in qemu_savevm_state_prepare()
1330 if (se->ops->is_active) { in qemu_savevm_state_prepare()
1331 if (!se->ops->is_active(se->opaque)) { in qemu_savevm_state_prepare()
1336 ret = se->ops->save_prepare(se->opaque, errp); in qemu_savevm_state_prepare()
1349 JSONWriter *vmdesc = ms->vmdesc; in qemu_savevm_state_setup()
1360 if (se->vmsd && se->vmsd->early_setup) { in qemu_savevm_state_setup()
1370 if (!se->ops || !se->ops->save_setup) { in qemu_savevm_state_setup()
1373 if (se->ops->is_active) { in qemu_savevm_state_setup()
1374 if (!se->ops->is_active(se->opaque)) { in qemu_savevm_state_setup()
1380 ret = se->ops->save_setup(f, se->opaque, errp); in qemu_savevm_state_setup()
1404 if (!se->ops || !se->ops->resume_prepare) { in qemu_savevm_state_resume_prepare()
1407 if (se->ops->is_active) { in qemu_savevm_state_resume_prepare()
1408 if (!se->ops->is_active(se->opaque)) { in qemu_savevm_state_resume_prepare()
1412 ret = se->ops->resume_prepare(s, se->opaque); in qemu_savevm_state_resume_prepare()
1423 * negative: there was one error, and we have -errno.
1435 if (!se->ops || !se->ops->save_live_iterate) { in qemu_savevm_state_iterate()
1438 if (se->ops->is_active && in qemu_savevm_state_iterate()
1439 !se->ops->is_active(se->opaque)) { in qemu_savevm_state_iterate()
1442 if (se->ops->is_active_iterate && in qemu_savevm_state_iterate()
1443 !se->ops->is_active_iterate(se->opaque)) { in qemu_savevm_state_iterate()
1453 !(se->ops->has_postcopy && se->ops->has_postcopy(se->opaque))) { in qemu_savevm_state_iterate()
1459 trace_savevm_section_start(se->idstr, se->section_id); in qemu_savevm_state_iterate()
1463 ret = se->ops->save_live_iterate(f, se->opaque); in qemu_savevm_state_iterate()
1464 trace_savevm_section_end(se->idstr, se->section_id, ret); in qemu_savevm_state_iterate()
1468 error_report("failed to save SaveStateEntry with id(name): " in qemu_savevm_state_iterate()
1470 se->section_id, se->idstr, ret); in qemu_savevm_state_iterate()
1484 return !machine->suppress_vmdesc; in should_send_vmdesc()
1500 if (!se->ops || !se->ops->save_live_complete_postcopy) { in qemu_savevm_state_complete_postcopy()
1503 if (se->ops->is_active) { in qemu_savevm_state_complete_postcopy()
1504 if (!se->ops->is_active(se->opaque)) { in qemu_savevm_state_complete_postcopy()
1508 trace_savevm_section_start(se->idstr, se->section_id); in qemu_savevm_state_complete_postcopy()
1511 qemu_put_be32(f, se->section_id); in qemu_savevm_state_complete_postcopy()
1513 ret = se->ops->save_live_complete_postcopy(f, se->opaque); in qemu_savevm_state_complete_postcopy()
1514 trace_savevm_section_end(se->idstr, se->section_id, ret); in qemu_savevm_state_complete_postcopy()
1532 if (!se->ops || !se->ops->save_postcopy_prepare) { in qemu_savevm_state_postcopy_prepare()
1536 if (se->ops->is_active) { in qemu_savevm_state_postcopy_prepare()
1537 if (!se->ops->is_active(se->opaque)) { in qemu_savevm_state_postcopy_prepare()
1542 trace_savevm_section_start(se->idstr, se->section_id); in qemu_savevm_state_postcopy_prepare()
1545 ret = se->ops->save_postcopy_prepare(f, se->opaque, errp); in qemu_savevm_state_postcopy_prepare()
1548 trace_savevm_section_end(se->idstr, se->section_id, ret); in qemu_savevm_state_postcopy_prepare()
1570 if (!se->ops || (in_postcopy && se->ops->has_postcopy && in qemu_savevm_state_complete_precopy_iterable()
1571 se->ops->has_postcopy(se->opaque)) || in qemu_savevm_state_complete_precopy_iterable()
1572 !se->ops->save_live_complete_precopy_thread) { in qemu_savevm_state_complete_precopy_iterable()
1576 hdlr = se->ops->save_live_complete_precopy_thread; in qemu_savevm_state_complete_precopy_iterable()
1578 se->idstr, se->instance_id, in qemu_savevm_state_complete_precopy_iterable()
1579 se->opaque); in qemu_savevm_state_complete_precopy_iterable()
1584 if (!se->ops || in qemu_savevm_state_complete_precopy_iterable()
1585 (in_postcopy && se->ops->has_postcopy && in qemu_savevm_state_complete_precopy_iterable()
1586 se->ops->has_postcopy(se->opaque)) || in qemu_savevm_state_complete_precopy_iterable()
1587 !se->ops->save_live_complete_precopy) { in qemu_savevm_state_complete_precopy_iterable()
1591 if (se->ops->is_active) { in qemu_savevm_state_complete_precopy_iterable()
1592 if (!se->ops->is_active(se->opaque)) { in qemu_savevm_state_complete_precopy_iterable()
1598 trace_savevm_section_start(se->idstr, se->section_id); in qemu_savevm_state_complete_precopy_iterable()
1602 ret = se->ops->save_live_complete_precopy(f, se->opaque); in qemu_savevm_state_complete_precopy_iterable()
1603 trace_savevm_section_end(se->idstr, se->section_id, ret); in qemu_savevm_state_complete_precopy_iterable()
1610 trace_vmstate_downtime_save("iterable", se->idstr, se->instance_id, in qemu_savevm_state_complete_precopy_iterable()
1611 end_ts_each - start_ts_each); in qemu_savevm_state_complete_precopy_iterable()
1620 qemu_file_set_error(f, -EINVAL); in qemu_savevm_state_complete_precopy_iterable()
1621 return -1; in qemu_savevm_state_complete_precopy_iterable()
1625 trace_vmstate_downtime_checkpoint("src-iterable-saved"); in qemu_savevm_state_complete_precopy_iterable()
1635 return -1; in qemu_savevm_state_complete_precopy_iterable()
1643 JSONWriter *vmdesc = ms->vmdesc; in qemu_savevm_state_complete_precopy_non_iterable()
1649 /* Making sure cpu states are synchronized before saving non-iterable */ in qemu_savevm_state_complete_precopy_non_iterable()
1653 if (se->vmsd && se->vmsd->early_setup) { in qemu_savevm_state_complete_precopy_non_iterable()
1669 trace_vmstate_downtime_save("non-iterable", se->idstr, se->instance_id, in qemu_savevm_state_complete_precopy_non_iterable()
1670 end_ts_each - start_ts_each); in qemu_savevm_state_complete_precopy_non_iterable()
1688 trace_vmstate_downtime_checkpoint("src-non-iterable-saved"); in qemu_savevm_state_complete_precopy_non_iterable()
1725 if (!se->ops || !se->ops->state_pending_estimate) { in qemu_savevm_state_pending_estimate()
1728 if (se->ops->is_active) { in qemu_savevm_state_pending_estimate()
1729 if (!se->ops->is_active(se->opaque)) { in qemu_savevm_state_pending_estimate()
1733 se->ops->state_pending_estimate(se->opaque, must_precopy, can_postcopy); in qemu_savevm_state_pending_estimate()
1746 if (!se->ops || !se->ops->state_pending_exact) { in qemu_savevm_state_pending_exact()
1749 if (se->ops->is_active) { in qemu_savevm_state_pending_exact()
1750 if (!se->ops->is_active(se->opaque)) { in qemu_savevm_state_pending_exact()
1754 se->ops->state_pending_exact(se->opaque, must_precopy, can_postcopy); in qemu_savevm_state_pending_exact()
1769 if (se->ops && se->ops->save_cleanup) { in qemu_savevm_state_cleanup()
1770 se->ops->save_cleanup(se->opaque); in qemu_savevm_state_cleanup()
1783 return -EINVAL; in qemu_savevm_state()
1790 ms->to_dst_file = f; in qemu_savevm_state()
1811 error_setg_errno(errp, -ret, "Error while writing VM state"); in qemu_savevm_state()
1821 migrate_set_state(&ms->state, MIGRATION_STATUS_SETUP, status); in qemu_savevm_state()
1825 ms->to_dst_file = NULL; in qemu_savevm_state()
1852 if (se->is_ram) { in qemu_save_device_state()
1873 if (!strcmp(se->idstr, idstr) && in find_se()
1874 (instance_id == se->instance_id || in find_se()
1875 instance_id == se->alias_id)) in find_se()
1878 if (strstr(se->idstr, idstr) && se->compat) { in find_se()
1879 if (!strcmp(se->compat->idstr, idstr) && in find_se()
1880 (instance_id == se->compat->instance_id || in find_se()
1881 instance_id == se->alias_id)) in find_se()
1893 /* ------ incoming postcopy messages ------ */
1895 * *might* happen - it might be skipped if precopy transferred everything
1909 return -1; in loadvm_postcopy_handle_advise()
1916 return -EINVAL; in loadvm_postcopy_handle_advise()
1922 return -EINVAL; in loadvm_postcopy_handle_advise()
1927 return -EINVAL; in loadvm_postcopy_handle_advise()
1933 return -1; in loadvm_postcopy_handle_advise()
1936 remote_pagesize_summary = qemu_get_be64(mis->from_src_file); in loadvm_postcopy_handle_advise()
1957 return -1; in loadvm_postcopy_handle_advise()
1960 remote_tps = qemu_get_be64(mis->from_src_file); in loadvm_postcopy_handle_advise()
1968 return -1; in loadvm_postcopy_handle_advise()
1973 return -1; in loadvm_postcopy_handle_advise()
1977 return -1; in loadvm_postcopy_handle_advise()
2013 return -1; in loadvm_postcopy_ram_handle_discard()
2017 * a RAM ID string (length byte, name, 0 term) in loadvm_postcopy_ram_handle_discard()
2022 return -1; in loadvm_postcopy_ram_handle_discard()
2025 tmp = qemu_get_byte(mis->from_src_file); in loadvm_postcopy_ram_handle_discard()
2028 return -1; in loadvm_postcopy_ram_handle_discard()
2031 if (!qemu_get_counted_string(mis->from_src_file, ramid)) { in loadvm_postcopy_ram_handle_discard()
2033 return -1; in loadvm_postcopy_ram_handle_discard()
2035 tmp = qemu_get_byte(mis->from_src_file); in loadvm_postcopy_ram_handle_discard()
2038 return -1; in loadvm_postcopy_ram_handle_discard()
2041 len -= 3 + strlen(ramid); in loadvm_postcopy_ram_handle_discard()
2044 return -1; in loadvm_postcopy_ram_handle_discard()
2049 start_addr = qemu_get_be64(mis->from_src_file); in loadvm_postcopy_ram_handle_discard()
2050 block_length = qemu_get_be64(mis->from_src_file); in loadvm_postcopy_ram_handle_discard()
2052 len -= 16; in loadvm_postcopy_ram_handle_discard()
2067 * (TODO:This could do with being in a postcopy file - but there again it's
2073 QEMUFile *f = mis->from_src_file; in postcopy_ram_listen_thread()
2079 migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, in postcopy_ram_listen_thread()
2081 qemu_event_set(&mis->thread_sync_event); in postcopy_ram_listen_thread()
2095 * This is tricky, but, mis->from_src_file can change after it in postcopy_ram_listen_thread()
2099 f = mis->from_src_file; in postcopy_ram_listen_thread()
2101 /* And non-blocking again so we don't block in any cleanup */ in postcopy_ram_listen_thread()
2119 migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, in postcopy_ram_listen_thread()
2129 qemu_event_wait(&mis->main_thread_load_event); in postcopy_ram_listen_thread()
2144 migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, in postcopy_ram_listen_thread()
2157 mis->have_listen_thread = false; in postcopy_ram_listen_thread()
2175 return -1; in loadvm_postcopy_handle_listen()
2190 * Sensitise RAM - can now generate requests for blocks that don't exist in loadvm_postcopy_handle_listen()
2197 return -1; in loadvm_postcopy_handle_listen()
2205 return -1; in loadvm_postcopy_handle_listen()
2208 mis->have_listen_thread = true; in loadvm_postcopy_handle_listen()
2209 postcopy_thread_create(mis, &mis->listen_thread, in loadvm_postcopy_handle_listen()
2221 trace_vmstate_downtime_checkpoint("dst-postcopy-bh-enter"); in loadvm_postcopy_handle_run_bh()
2228 trace_vmstate_downtime_checkpoint("dst-postcopy-bh-cpu-synced"); in loadvm_postcopy_handle_run_bh()
2230 qemu_announce_self(&mis->announce_timer, migrate_announce_params()); in loadvm_postcopy_handle_run_bh()
2232 trace_vmstate_downtime_checkpoint("dst-postcopy-bh-announced"); in loadvm_postcopy_handle_run_bh()
2243 trace_vmstate_downtime_checkpoint("dst-postcopy-bh-cache-invalidated"); in loadvm_postcopy_handle_run_bh()
2253 trace_vmstate_downtime_checkpoint("dst-postcopy-bh-vm-started"); in loadvm_postcopy_handle_run_bh()
2264 return -1; in loadvm_postcopy_handle_run()
2316 WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) { in migrate_send_rp_req_pages_pending()
2317 g_tree_foreach(mis->page_requested, postcopy_sync_page_req, mis); in migrate_send_rp_req_pages_pending()
2323 if (mis->state != MIGRATION_STATUS_POSTCOPY_RECOVER) { in loadvm_postcopy_handle_resume()
2333 mis->last_rb = NULL; in loadvm_postcopy_handle_resume()
2338 migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_RECOVER, in loadvm_postcopy_handle_resume()
2349 * the network down phase. Let's re-sync with the source VM by re-sending in loadvm_postcopy_handle_resume()
2366 qemu_sem_post(&mis->postcopy_pause_sem_fault); in loadvm_postcopy_handle_resume()
2373 qemu_sem_wait(&mis->postcopy_qemufile_dst_done); in loadvm_postcopy_handle_resume()
2374 assert(mis->postcopy_qemufile_dst); in loadvm_postcopy_handle_resume()
2376 qemu_sem_post(&mis->postcopy_pause_sem_fast_load); in loadvm_postcopy_handle_resume()
2398 length = qemu_get_be32(mis->from_src_file); in loadvm_handle_cmd_packaged()
2403 return -1; in loadvm_handle_cmd_packaged()
2407 qio_channel_set_name(QIO_CHANNEL(bioc), "migration-loadvm-buffer"); in loadvm_handle_cmd_packaged()
2408 ret = qemu_get_buffer(mis->from_src_file, in loadvm_handle_cmd_packaged()
2409 bioc->data, in loadvm_handle_cmd_packaged()
2415 return (ret < 0) ? ret : -EAGAIN; in loadvm_handle_cmd_packaged()
2417 bioc->usage += length; in loadvm_handle_cmd_packaged()
2435 mis->postcopy_qemufile_dst) { in loadvm_handle_cmd_packaged()
2460 QEMUFile *file = mis->from_src_file; in loadvm_handle_recv_bitmap()
2463 size_t cnt; in loadvm_handle_recv_bitmap() local
2465 cnt = qemu_get_counted_string(file, block_name); in loadvm_handle_recv_bitmap()
2466 if (!cnt) { in loadvm_handle_recv_bitmap()
2467 error_report("%s: failed to read block name", __func__); in loadvm_handle_recv_bitmap()
2468 return -EINVAL; in loadvm_handle_recv_bitmap()
2476 if (len != cnt + 1) { in loadvm_handle_recv_bitmap()
2478 return -EINVAL; in loadvm_handle_recv_bitmap()
2484 return -EINVAL; in loadvm_handle_recv_bitmap()
2514 if (!se->ops || !se->ops->switchover_start) { in loadvm_postcopy_handle_switchover_start()
2518 ret = se->ops->switchover_start(se->opaque); in loadvm_postcopy_handle_switchover_start()
2536 uint16_t cmd; in loadvm_process_command() local
2540 cmd = qemu_get_be16(f); in loadvm_process_command()
2548 if (cmd >= MIG_CMD_MAX || cmd == MIG_CMD_INVALID) { in loadvm_process_command()
2549 error_report("MIG_CMD 0x%x unknown (len 0x%x)", cmd, len); in loadvm_process_command()
2550 return -EINVAL; in loadvm_process_command()
2553 trace_loadvm_process_command(mig_cmd_args[cmd].name, len); in loadvm_process_command()
2555 if (mig_cmd_args[cmd].len != -1 && mig_cmd_args[cmd].len != len) { in loadvm_process_command()
2556 error_report("%s received with bad length - expecting %zu, got %d", in loadvm_process_command()
2557 mig_cmd_args[cmd].name, in loadvm_process_command()
2558 (size_t)mig_cmd_args[cmd].len, len); in loadvm_process_command()
2559 return -ERANGE; in loadvm_process_command()
2562 switch (cmd) { in loadvm_process_command()
2564 if (mis->to_src_file) { in loadvm_process_command()
2569 mis->to_src_file = qemu_file_get_return_path(f); in loadvm_process_command()
2570 if (!mis->to_src_file) { in loadvm_process_command()
2572 return -1; in loadvm_process_command()
2580 if (migrate_switchover_ack() && !mis->switchover_ack_pending_num) { in loadvm_process_command()
2585 strerror(-ret)); in loadvm_process_command()
2594 if (!mis->to_src_file) { in loadvm_process_command()
2597 return -1; in loadvm_process_command()
2645 if (!migrate_get_current()->send_section_footer) { in check_section_footer()
2660 error_report("Missing section footer for %s", se->idstr); in check_section_footer()
2665 if (read_section_id != se->load_section_id) { in check_section_footer()
2666 error_report("Mismatched section id in footer for %s -" in check_section_footer()
2668 se->idstr, read_section_id, se->load_section_id); in check_section_footer()
2691 return -EINVAL; in qemu_loadvm_section_start_full()
2712 return -EINVAL; in qemu_loadvm_section_start_full()
2716 if (version_id > se->version_id) { in qemu_loadvm_section_start_full()
2718 version_id, idstr, se->version_id); in qemu_loadvm_section_start_full()
2719 return -EINVAL; in qemu_loadvm_section_start_full()
2721 se->load_version_id = version_id; in qemu_loadvm_section_start_full()
2722 se->load_section_id = section_id; in qemu_loadvm_section_start_full()
2725 if (xen_enabled() && se->is_ram) { in qemu_loadvm_section_start_full()
2727 return -EINVAL; in qemu_loadvm_section_start_full()
2743 trace_vmstate_downtime_load("non-iterable", se->idstr, in qemu_loadvm_section_start_full()
2744 se->instance_id, end_ts - start_ts); in qemu_loadvm_section_start_full()
2748 return -EINVAL; in qemu_loadvm_section_start_full()
2774 if (se->load_section_id == section_id) { in qemu_loadvm_section_part_end()
2780 return -EINVAL; in qemu_loadvm_section_part_end()
2790 section_id, se->idstr); in qemu_loadvm_section_part_end()
2796 trace_vmstate_downtime_load("iterable", se->idstr, in qemu_loadvm_section_part_end()
2797 se->instance_id, end_ts - start_ts); in qemu_loadvm_section_part_end()
2801 return -EINVAL; in qemu_loadvm_section_part_end()
2815 return -EINVAL; in qemu_loadvm_state_header()
2821 return -ENOTSUP; in qemu_loadvm_state_header()
2825 return -ENOTSUP; in qemu_loadvm_state_header()
2828 if (migrate_get_current()->send_configuration) { in qemu_loadvm_state_header()
2831 return -EINVAL; in qemu_loadvm_state_header()
2847 if (!se->ops || !se->ops->switchover_ack_needed) { in qemu_loadvm_state_switchover_ack_needed()
2851 if (se->ops->switchover_ack_needed(se->opaque)) { in qemu_loadvm_state_switchover_ack_needed()
2852 mis->switchover_ack_pending_num++; in qemu_loadvm_state_switchover_ack_needed()
2856 trace_loadvm_state_switchover_ack_needed(mis->switchover_ack_pending_num); in qemu_loadvm_state_switchover_ack_needed()
2867 if (!se->ops || !se->ops->load_setup) { in qemu_loadvm_state_setup()
2870 if (se->ops->is_active) { in qemu_loadvm_state_setup()
2871 if (!se->ops->is_active(se->opaque)) { in qemu_loadvm_state_setup()
2876 ret = se->ops->load_setup(f, se->opaque, errp); in qemu_loadvm_state_setup()
2879 se->idstr); in qemu_loadvm_state_setup()
2898 if (!data->function(data->opaque, &mis->load_threads_abort, &local_err)) { in qemu_loadvm_load_thread()
2926 assert(!mis->load_threads_abort); in qemu_loadvm_start_load_thread()
2929 data->function = function; in qemu_loadvm_start_load_thread()
2930 data->opaque = opaque; in qemu_loadvm_start_load_thread()
2932 thread_pool_submit_immediate(mis->load_threads, qemu_loadvm_load_thread, in qemu_loadvm_start_load_thread()
2943 if (se->ops && se->ops->load_cleanup) { in qemu_loadvm_state_cleanup()
2944 se->ops->load_cleanup(se->opaque); in qemu_loadvm_state_cleanup()
2964 migration_ioc_unregister_yank_from_file(mis->from_src_file); in postcopy_pause_incoming()
2966 assert(mis->from_src_file); in postcopy_pause_incoming()
2967 qemu_file_shutdown(mis->from_src_file); in postcopy_pause_incoming()
2968 qemu_fclose(mis->from_src_file); in postcopy_pause_incoming()
2969 mis->from_src_file = NULL; in postcopy_pause_incoming()
2971 assert(mis->to_src_file); in postcopy_pause_incoming()
2972 qemu_file_shutdown(mis->to_src_file); in postcopy_pause_incoming()
2973 qemu_mutex_lock(&mis->rp_mutex); in postcopy_pause_incoming()
2974 qemu_fclose(mis->to_src_file); in postcopy_pause_incoming()
2975 mis->to_src_file = NULL; in postcopy_pause_incoming()
2976 qemu_mutex_unlock(&mis->rp_mutex); in postcopy_pause_incoming()
2983 if (mis->postcopy_qemufile_dst) { in postcopy_pause_incoming()
2984 qemu_file_shutdown(mis->postcopy_qemufile_dst); in postcopy_pause_incoming()
2986 qemu_mutex_lock(&mis->postcopy_prio_thread_mutex); in postcopy_pause_incoming()
2987 migration_ioc_unregister_yank_from_file(mis->postcopy_qemufile_dst); in postcopy_pause_incoming()
2988 qemu_fclose(mis->postcopy_qemufile_dst); in postcopy_pause_incoming()
2989 mis->postcopy_qemufile_dst = NULL; in postcopy_pause_incoming()
2990 qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex); in postcopy_pause_incoming()
2994 migrate_set_state(&mis->state, mis->state, in postcopy_pause_incoming()
3006 for (i = 0; i < mis->postcopy_channels; i++) { in postcopy_pause_incoming()
3007 postcopy_temp_page_reset(&mis->postcopy_tmp_pages[i]); in postcopy_pause_incoming()
3014 qemu_sem_wait(&mis->postcopy_pause_sem_dst); in postcopy_pause_incoming()
3015 } while (postcopy_is_paused(mis->state)); in postcopy_pause_incoming()
3031 ret = qemu_file_get_error_obj_any(f, mis->postcopy_qemufile_dst, NULL); in qemu_loadvm_state_main()
3064 ret = -EINVAL; in qemu_loadvm_state_main()
3090 f = mis->from_src_file; in qemu_loadvm_state_main()
3106 return -EINVAL; in qemu_loadvm_state()
3118 return -EINVAL; in qemu_loadvm_state()
3128 qemu_event_set(&mis->main_thread_load_event); in qemu_loadvm_state()
3132 if (mis->have_listen_thread) { in qemu_loadvm_state()
3144 ret = -EINVAL; in qemu_loadvm_state()
3153 qatomic_set(&mis->load_threads_abort, true); in qemu_loadvm_state()
3184 size -= read_chunk; in qemu_loadvm_state()
3215 if (!mis->switchover_ack_pending_num) { in qemu_loadvm_approve_switchover()
3216 return -EINVAL; in qemu_loadvm_approve_switchover()
3219 mis->switchover_ack_pending_num--; in qemu_loadvm_approve_switchover()
3220 trace_loadvm_approve_switchover(mis->switchover_ack_pending_num); in qemu_loadvm_approve_switchover()
3222 if (mis->switchover_ack_pending_num) { in qemu_loadvm_approve_switchover()
3242 if (!se->ops || !se->ops->load_state_buffer) { in qemu_loadvm_load_state_buffer()
3249 return se->ops->load_state_buffer(se->opaque, buf, len, errp); in qemu_loadvm_load_state_buffer()
3252 bool save_snapshot(const char *name, bool overwrite, const char *vmstate, in save_snapshot() argument
3257 int ret = -1, ret2; in save_snapshot()
3279 /* Delete old snapshots of the same name */ in save_snapshot()
3280 if (name) { in save_snapshot()
3282 if (bdrv_all_delete_snapshot(name, has_devices, in save_snapshot()
3287 ret2 = bdrv_all_has_snapshot(name, has_devices, devices, errp); in save_snapshot()
3294 name); in save_snapshot()
3313 sn->date_sec = g_date_time_to_unix(now); in save_snapshot()
3314 sn->date_nsec = g_date_time_get_microsecond(now) * 1000; in save_snapshot()
3315 sn->vm_clock_nsec = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); in save_snapshot()
3317 sn->icount = replay_get_current_icount(); in save_snapshot()
3319 sn->icount = -1ULL; in save_snapshot()
3322 if (name) { in save_snapshot()
3323 pstrcpy(sn->name, sizeof(sn->name), name); in save_snapshot()
3325 g_autofree char *autoname = g_date_time_format(now, "vm-%Y%m%d%H%M%S"); in save_snapshot()
3326 pstrcpy(sn->name, sizeof(sn->name), autoname); in save_snapshot()
3349 bdrv_all_delete_snapshot(sn->name, has_devices, devices, NULL); in save_snapshot()
3385 qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-save-state"); in qmp_xen_save_devices_state()
3393 * "xen-save-devices-state" and in case of migration failure, libxl in qmp_xen_save_devices_state()
3428 qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-load-state"); in qmp_xen_load_devices_state()
3440 bool load_snapshot(const char *name, const char *vmstate, in load_snapshot() argument
3452 ret = bdrv_all_has_snapshot(name, has_devices, devices, errp); in load_snapshot()
3458 name); in load_snapshot()
3468 ret = bdrv_snapshot_find(bs_vm_state, &sn, name); in load_snapshot()
3473 error_setg(errp, "This is a disk-only snapshot. Revert to it " in load_snapshot()
3474 " offline using qemu-img"); in load_snapshot()
3487 ret = bdrv_all_goto_snapshot(name, has_devices, devices, errp); in load_snapshot()
3500 mis->from_src_file = f; in load_snapshot()
3503 ret = -EINVAL; in load_snapshot()
3531 bool delete_snapshot(const char *name, bool has_devices, in delete_snapshot() argument
3538 if (bdrv_all_delete_snapshot(name, has_devices, devices, errp) < 0) { in delete_snapshot()
3547 qemu_ram_set_idstr(mr->ram_block, in vmstate_register_ram()
3549 qemu_ram_set_migratable(mr->ram_block); in vmstate_register_ram()
3550 ram_block_add_cpr_blocker(mr->ram_block, &error_fatal); in vmstate_register_ram()
3555 qemu_ram_unset_idstr(mr->ram_block); in vmstate_unregister_ram()
3556 qemu_ram_unset_migratable(mr->ram_block); in vmstate_unregister_ram()
3557 ram_block_del_cpr_blocker(mr->ram_block); in vmstate_unregister_ram()
3567 /* check needed if --only-migratable is specified */ in vmstate_check_only_migratable()
3572 return !(vmsd && vmsd->unmigratable); in vmstate_check_only_migratable()
3587 g_free(s->tag); in qmp_snapshot_job_free()
3588 g_free(s->vmstate); in qmp_snapshot_job_free()
3589 qapi_free_strList(s->devices); in qmp_snapshot_job_free()
3599 job_progress_set_remaining(&s->common, 1); in snapshot_load_job_bh()
3603 s->ret = load_snapshot(s->tag, s->vmstate, true, s->devices, s->errp); in snapshot_load_job_bh()
3604 if (s->ret) { in snapshot_load_job_bh()
3608 job_progress_update(&s->common, 1); in snapshot_load_job_bh()
3611 aio_co_wake(s->co); in snapshot_load_job_bh()
3619 job_progress_set_remaining(&s->common, 1); in snapshot_save_job_bh()
3620 s->ret = save_snapshot(s->tag, false, s->vmstate, in snapshot_save_job_bh()
3621 true, s->devices, s->errp); in snapshot_save_job_bh()
3622 job_progress_update(&s->common, 1); in snapshot_save_job_bh()
3625 aio_co_wake(s->co); in snapshot_save_job_bh()
3633 job_progress_set_remaining(&s->common, 1); in snapshot_delete_job_bh()
3634 s->ret = delete_snapshot(s->tag, true, s->devices, s->errp); in snapshot_delete_job_bh()
3635 job_progress_update(&s->common, 1); in snapshot_delete_job_bh()
3638 aio_co_wake(s->co); in snapshot_delete_job_bh()
3644 s->errp = errp; in snapshot_save_job_run()
3645 s->co = qemu_coroutine_self(); in snapshot_save_job_run()
3649 return s->ret ? 0 : -1; in snapshot_save_job_run()
3655 s->errp = errp; in snapshot_load_job_run()
3656 s->co = qemu_coroutine_self(); in snapshot_load_job_run()
3660 return s->ret ? 0 : -1; in snapshot_load_job_run()
3666 s->errp = errp; in snapshot_delete_job_run()
3667 s->co = qemu_coroutine_self(); in snapshot_delete_job_run()
3671 return s->ret ? 0 : -1; in snapshot_delete_job_run()
3709 s->tag = g_strdup(tag); in qmp_snapshot_save()
3710 s->vmstate = g_strdup(vmstate); in qmp_snapshot_save()
3711 s->devices = QAPI_CLONE(strList, devices); in qmp_snapshot_save()
3713 job_start(&s->common); in qmp_snapshot_save()
3731 s->tag = g_strdup(tag); in qmp_snapshot_load()
3732 s->vmstate = g_strdup(vmstate); in qmp_snapshot_load()
3733 s->devices = QAPI_CLONE(strList, devices); in qmp_snapshot_load()
3735 job_start(&s->common); in qmp_snapshot_load()
3752 s->tag = g_strdup(tag); in qmp_snapshot_delete()
3753 s->devices = QAPI_CLONE(strList, devices); in qmp_snapshot_delete()
3755 job_start(&s->common); in qmp_snapshot_delete()