| 1 | /* |
| 2 | * QEMU migration miscellaneus exported functions |
| 3 | * |
| 4 | * Copyright IBM, Corp. 2008 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Anthony Liguori <aliguori@us.ibm.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 10 | * the COPYING file in the top-level directory. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef MIGRATION_MISC_H |
| 15 | #define MIGRATION_MISC_H |
| 16 | |
| 17 | #include "qemu/notify.h" |
| 18 | #include "qapi/qapi-types-migration.h" |
| 19 | #include "qapi/qapi-types-net.h" |
| 20 | #include "migration/client-options.h" |
| 21 | |
| 22 | /* migration/ram.c */ |
| 23 | |
| 24 | typedef enum PrecopyNotifyReason { |
| 25 | PRECOPY_NOTIFY_SETUP = 0, |
| 26 | PRECOPY_NOTIFY_BEFORE_BITMAP_SYNC = 1, |
| 27 | PRECOPY_NOTIFY_AFTER_BITMAP_SYNC = 2, |
| 28 | PRECOPY_NOTIFY_COMPLETE = 3, |
| 29 | PRECOPY_NOTIFY_CLEANUP = 4, |
| 30 | PRECOPY_NOTIFY_MAX = 5, |
| 31 | } PrecopyNotifyReason; |
| 32 | |
| 33 | typedef struct PrecopyNotifyData { |
| 34 | enum PrecopyNotifyReason reason; |
| 35 | } PrecopyNotifyData; |
| 36 | |
| 37 | void precopy_infrastructure_init(void); |
| 38 | void precopy_add_notifier(NotifierWithReturn *n); |
| 39 | void precopy_remove_notifier(NotifierWithReturn *n); |
| 40 | int precopy_notify(PrecopyNotifyReason reason, Error **errp); |
| 41 | |
| 42 | void qemu_guest_free_page_hint(void *addr, size_t len); |
| 43 | bool migrate_ram_is_ignored(RAMBlock *block); |
| 44 | |
| 45 | /* migration/block.c */ |
| 46 | |
| 47 | AnnounceParameters *migrate_announce_params(void); |
| 48 | |
| 49 | /* migration/savevm.c */ |
| 50 | |
| 51 | void dump_vmstate_json_to_file(FILE *out_fp); |
| 52 | void qemu_loadvm_start_load_thread(MigrationLoadThread function, |
| 53 | void *opaque); |
| 54 | |
| 55 | /* migration/migration.c */ |
| 56 | void migration_object_init(void); |
| 57 | void migration_shutdown(void); |
| 58 | |
| 59 | bool migration_is_running(void); |
| 60 | bool migration_thread_is_self(void); |
| 61 | |
| 62 | /* |
| 63 | * Notifiers may receive events in any of the following orders: |
| 64 | * |
| 65 | * - MIG_EVENT_SETUP [-> MIG_EVENT_POSTCOPY_START] -> MIG_EVENT_DONE |
| 66 | * - MIG_EVENT_SETUP [-> MIG_EVENT_POSTCOPY_START] -> MIG_EVENT_FAILED |
| 67 | * - MIG_EVENT_FAILED |
| 68 | */ |
| 69 | typedef enum MigrationEventType { |
| 70 | MIG_EVENT_SETUP, |
| 71 | MIG_EVENT_POSTCOPY_START, |
| 72 | MIG_EVENT_DONE, |
| 73 | MIG_EVENT_FAILED, |
| 74 | MIG_EVENT_MAX |
| 75 | } MigrationEventType; |
| 76 | |
| 77 | typedef struct MigrationEvent { |
| 78 | MigrationEventType type; |
| 79 | } MigrationEvent; |
| 80 | |
| 81 | /* |
| 82 | * A MigrationNotifyFunc may return an error code and an Error object, |
| 83 | * but only when @e->type is MIG_EVENT_SETUP. The code is an int |
| 84 | * to allow for different failure modes and recovery actions. |
| 85 | */ |
| 86 | typedef int (*MigrationNotifyFunc)(NotifierWithReturn *notify, |
| 87 | MigrationEvent *e, Error **errp); |
| 88 | |
| 89 | /* |
| 90 | * Register the notifier @notify to be called when a migration event occurs |
| 91 | * for MIG_MODE_NORMAL, as specified by the MigrationEvent passed to @func. |
| 92 | */ |
| 93 | void migration_add_notifier(NotifierWithReturn *notify, |
| 94 | MigrationNotifyFunc func); |
| 95 | |
| 96 | /* |
| 97 | * Same as migration_add_notifier, but applies to the specified @mode |
| 98 | * instead of MIG_MODE_NORMAL. |
| 99 | */ |
| 100 | void migration_add_notifier_mode(NotifierWithReturn *notify, |
| 101 | MigrationNotifyFunc func, MigMode mode); |
| 102 | |
| 103 | /* |
| 104 | * Same as migration_add_notifier, but applies to the specified @modes |
| 105 | * (a bitset of MigMode). |
| 106 | */ |
| 107 | void migration_add_notifier_modes(NotifierWithReturn *notify, |
| 108 | MigrationNotifyFunc func, unsigned modes); |
| 109 | |
| 110 | /* |
| 111 | * Remove a notifier from all modes. |
| 112 | */ |
| 113 | void migration_remove_notifier(NotifierWithReturn *notify); |
| 114 | |
| 115 | void migration_file_set_error(int ret, Error *err); |
| 116 | |
| 117 | /* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */ |
| 118 | bool migration_in_incoming_postcopy(void); |
| 119 | |
| 120 | /* True while the destination still receives guest RAM (precopy or postcopy) */ |
| 121 | bool migration_guest_ram_loading(void); |
| 122 | |
| 123 | /* True if incoming migration entered POSTCOPY_INCOMING_ADVISE */ |
| 124 | bool migration_incoming_postcopy_advised(void); |
| 125 | |
| 126 | /* True if background snapshot is active */ |
| 127 | bool migration_in_bg_snapshot(void); |
| 128 | |
| 129 | /* Wrapper for block active/inactive operations */ |
| 130 | bool migration_block_activate(Error **errp); |
| 131 | bool migration_block_inactivate(void); |
| 132 | |
| 133 | /* True if @uri starts with a syntactically valid URI prefix */ |
| 134 | bool migrate_is_uri(const char *uri); |
| 135 | |
| 136 | /* Parse @uri and return @channel, returning true on success */ |
| 137 | bool migrate_uri_parse(const char *uri, MigrationChannel **channel, |
| 138 | Error **errp); |
| 139 | |
| 140 | /* migration/multifd-device-state.c */ |
| 141 | typedef struct SaveCompletePrecopyThreadData { |
| 142 | SaveCompletePrecopyThreadHandler hdlr; |
| 143 | char *idstr; |
| 144 | uint32_t instance_id; |
| 145 | void *handler_opaque; |
| 146 | } SaveCompletePrecopyThreadData; |
| 147 | |
| 148 | bool multifd_queue_device_state(char *idstr, uint32_t instance_id, |
| 149 | char *data, size_t len); |
| 150 | bool multifd_device_state_supported(void); |
| 151 | |
| 152 | void |
| 153 | multifd_spawn_device_state_save_thread(SaveCompletePrecopyThreadHandler hdlr, |
| 154 | char *idstr, uint32_t instance_id, |
| 155 | void *opaque); |
| 156 | |
| 157 | bool multifd_device_state_save_thread_should_exit(void); |
| 158 | |
| 159 | void multifd_abort_device_state_save_threads(void); |
| 160 | bool multifd_join_device_state_save_threads(void); |
| 161 | |
| 162 | void migration_request_switchover_ack_legacy(const char *requester); |
| 163 | |
| 164 | #endif |