1f2a8f0a6SJuan Quintela /* 2f2a8f0a6SJuan Quintela * QEMU migration vmstate registration 3f2a8f0a6SJuan Quintela * 4f2a8f0a6SJuan Quintela * Copyright IBM, Corp. 2008 5f2a8f0a6SJuan Quintela * 6f2a8f0a6SJuan Quintela * Authors: 7f2a8f0a6SJuan Quintela * Anthony Liguori <aliguori@us.ibm.com> 8f2a8f0a6SJuan Quintela * 9f2a8f0a6SJuan Quintela * This work is licensed under the terms of the GNU GPL, version 2. See 10f2a8f0a6SJuan Quintela * the COPYING file in the top-level directory. 11f2a8f0a6SJuan Quintela * 12f2a8f0a6SJuan Quintela */ 13f2a8f0a6SJuan Quintela 14f2a8f0a6SJuan Quintela #ifndef MIGRATION_REGISTER_H 15f2a8f0a6SJuan Quintela #define MIGRATION_REGISTER_H 16f2a8f0a6SJuan Quintela 17107b5969SMarc-André Lureau #include "hw/vmstate-if.h" 18107b5969SMarc-André Lureau 19f2a8f0a6SJuan Quintela typedef struct SaveVMHandlers { 20f2a8f0a6SJuan Quintela /* This runs inside the iothread lock. */ 21f2a8f0a6SJuan Quintela SaveStateHandler *save_state; 22f2a8f0a6SJuan Quintela 2308fc4cb5SAvihai Horon /* 2408fc4cb5SAvihai Horon * save_prepare is called early, even before migration starts, and can be 2508fc4cb5SAvihai Horon * used to perform early checks. 2608fc4cb5SAvihai Horon */ 2708fc4cb5SAvihai Horon int (*save_prepare)(void *opaque, Error **errp); 2870f794fcSJuan Quintela void (*save_cleanup)(void *opaque); 29f2a8f0a6SJuan Quintela int (*save_live_complete_postcopy)(QEMUFile *f, void *opaque); 30f2a8f0a6SJuan Quintela int (*save_live_complete_precopy)(QEMUFile *f, void *opaque); 31f2a8f0a6SJuan Quintela 32f2a8f0a6SJuan Quintela /* This runs both outside and inside the iothread lock. */ 33f2a8f0a6SJuan Quintela bool (*is_active)(void *opaque); 34c6467627SVladimir Sementsov-Ogievskiy bool (*has_postcopy)(void *opaque); 35f2a8f0a6SJuan Quintela 36c865d848SVladimir Sementsov-Ogievskiy /* is_active_iterate 37c865d848SVladimir Sementsov-Ogievskiy * If it is not NULL then qemu_savevm_state_iterate will skip iteration if 38c865d848SVladimir Sementsov-Ogievskiy * it returns false. For example, it is needed for only-postcopy-states, 39c865d848SVladimir Sementsov-Ogievskiy * which needs to be handled by qemu_savevm_state_setup and 40c865d848SVladimir Sementsov-Ogievskiy * qemu_savevm_state_pending, but do not need iterations until not in 41c865d848SVladimir Sementsov-Ogievskiy * postcopy stage. 42c865d848SVladimir Sementsov-Ogievskiy */ 43c865d848SVladimir Sementsov-Ogievskiy bool (*is_active_iterate)(void *opaque); 44c865d848SVladimir Sementsov-Ogievskiy 45f2a8f0a6SJuan Quintela /* This runs outside the iothread lock in the migration case, and 46f2a8f0a6SJuan Quintela * within the lock in the savevm case. The callback had better only 47f2a8f0a6SJuan Quintela * use data that is local to the migration thread or protected 48f2a8f0a6SJuan Quintela * by other locks. 49f2a8f0a6SJuan Quintela */ 50f2a8f0a6SJuan Quintela int (*save_live_iterate)(QEMUFile *f, void *opaque); 51f2a8f0a6SJuan Quintela 52f2a8f0a6SJuan Quintela /* This runs outside the iothread lock! */ 539907e842SJuan Quintela int (*save_setup)(QEMUFile *f, void *opaque); 5447995026SVladimir Sementsov-Ogievskiy /* Note for save_live_pending: 5524beea4eSJuan Quintela * must_precopy: 5624beea4eSJuan Quintela * - must be migrated in precopy or in stopped state 5724beea4eSJuan Quintela * - i.e. must be migrated before target start 5847995026SVladimir Sementsov-Ogievskiy * 5924beea4eSJuan Quintela * can_postcopy: 6024beea4eSJuan Quintela * - can migrate in postcopy or in stopped state 6124beea4eSJuan Quintela * - i.e. can migrate after target start 6224beea4eSJuan Quintela * - some can also be migrated during precopy (RAM) 6324beea4eSJuan Quintela * - some must be migrated after source stops (block-dirty-bitmap) 6424beea4eSJuan Quintela * 6524beea4eSJuan Quintela * Sum of can_postcopy and must_postcopy is the whole amount of 6624beea4eSJuan Quintela * pending data. 6747995026SVladimir Sementsov-Ogievskiy */ 68c8df4a7aSJuan Quintela /* This estimates the remaining data to transfer */ 6924beea4eSJuan Quintela void (*state_pending_estimate)(void *opaque, uint64_t *must_precopy, 7024beea4eSJuan Quintela uint64_t *can_postcopy); 71c8df4a7aSJuan Quintela /* This calculate the exact remaining data to transfer */ 7224beea4eSJuan Quintela void (*state_pending_exact)(void *opaque, uint64_t *must_precopy, 7324beea4eSJuan Quintela uint64_t *can_postcopy); 74f2a8f0a6SJuan Quintela LoadStateHandler *load_state; 75acb5ea86SJuan Quintela int (*load_setup)(QEMUFile *f, void *opaque); 76acb5ea86SJuan Quintela int (*load_cleanup)(void *opaque); 77d1b8eadbSPeter Xu /* Called when postcopy migration wants to resume from failure */ 78d1b8eadbSPeter Xu int (*resume_prepare)(MigrationState *s, void *opaque); 791b4adb10SAvihai Horon /* Checks if switchover ack should be used. Called only in dest */ 801b4adb10SAvihai Horon bool (*switchover_ack_needed)(void *opaque); 81f2a8f0a6SJuan Quintela } SaveVMHandlers; 82f2a8f0a6SJuan Quintela 83ce62df53SDr. David Alan Gilbert int register_savevm_live(const char *idstr, 8493062e23SPeter Xu uint32_t instance_id, 85f2a8f0a6SJuan Quintela int version_id, 86de22ded0SMarc-André Lureau const SaveVMHandlers *ops, 87f2a8f0a6SJuan Quintela void *opaque); 88f2a8f0a6SJuan Quintela 893cad405bSMarc-André Lureau void unregister_savevm(VMStateIf *obj, const char *idstr, void *opaque); 90f2a8f0a6SJuan Quintela 91f2a8f0a6SJuan Quintela #endif 92