xref: /qemu/include/migration/register.h (revision 93062e23)
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 
2370f794fcSJuan Quintela     void (*save_cleanup)(void *opaque);
24f2a8f0a6SJuan Quintela     int (*save_live_complete_postcopy)(QEMUFile *f, void *opaque);
25f2a8f0a6SJuan Quintela     int (*save_live_complete_precopy)(QEMUFile *f, void *opaque);
26f2a8f0a6SJuan Quintela 
27f2a8f0a6SJuan Quintela     /* This runs both outside and inside the iothread lock.  */
28f2a8f0a6SJuan Quintela     bool (*is_active)(void *opaque);
29c6467627SVladimir Sementsov-Ogievskiy     bool (*has_postcopy)(void *opaque);
30f2a8f0a6SJuan Quintela 
31c865d848SVladimir Sementsov-Ogievskiy     /* is_active_iterate
32c865d848SVladimir Sementsov-Ogievskiy      * If it is not NULL then qemu_savevm_state_iterate will skip iteration if
33c865d848SVladimir Sementsov-Ogievskiy      * it returns false. For example, it is needed for only-postcopy-states,
34c865d848SVladimir Sementsov-Ogievskiy      * which needs to be handled by qemu_savevm_state_setup and
35c865d848SVladimir Sementsov-Ogievskiy      * qemu_savevm_state_pending, but do not need iterations until not in
36c865d848SVladimir Sementsov-Ogievskiy      * postcopy stage.
37c865d848SVladimir Sementsov-Ogievskiy      */
38c865d848SVladimir Sementsov-Ogievskiy     bool (*is_active_iterate)(void *opaque);
39c865d848SVladimir Sementsov-Ogievskiy 
40f2a8f0a6SJuan Quintela     /* This runs outside the iothread lock in the migration case, and
41f2a8f0a6SJuan Quintela      * within the lock in the savevm case.  The callback had better only
42f2a8f0a6SJuan Quintela      * use data that is local to the migration thread or protected
43f2a8f0a6SJuan Quintela      * by other locks.
44f2a8f0a6SJuan Quintela      */
45f2a8f0a6SJuan Quintela     int (*save_live_iterate)(QEMUFile *f, void *opaque);
46f2a8f0a6SJuan Quintela 
47f2a8f0a6SJuan Quintela     /* This runs outside the iothread lock!  */
489907e842SJuan Quintela     int (*save_setup)(QEMUFile *f, void *opaque);
49f2a8f0a6SJuan Quintela     void (*save_live_pending)(QEMUFile *f, void *opaque,
50f2a8f0a6SJuan Quintela                               uint64_t threshold_size,
5147995026SVladimir Sementsov-Ogievskiy                               uint64_t *res_precopy_only,
5247995026SVladimir Sementsov-Ogievskiy                               uint64_t *res_compatible,
5347995026SVladimir Sementsov-Ogievskiy                               uint64_t *res_postcopy_only);
5447995026SVladimir Sementsov-Ogievskiy     /* Note for save_live_pending:
5547995026SVladimir Sementsov-Ogievskiy      * - res_precopy_only is for data which must be migrated in precopy phase
5647995026SVladimir Sementsov-Ogievskiy      *     or in stopped state, in other words - before target vm start
5747995026SVladimir Sementsov-Ogievskiy      * - res_compatible is for data which may be migrated in any phase
5847995026SVladimir Sementsov-Ogievskiy      * - res_postcopy_only is for data which must be migrated in postcopy phase
5947995026SVladimir Sementsov-Ogievskiy      *     or in stopped state, in other words - after source vm stop
6047995026SVladimir Sementsov-Ogievskiy      *
6147995026SVladimir Sementsov-Ogievskiy      * Sum of res_postcopy_only, res_compatible and res_postcopy_only is the
6247995026SVladimir Sementsov-Ogievskiy      * whole amount of pending data.
6347995026SVladimir Sementsov-Ogievskiy      */
6447995026SVladimir Sementsov-Ogievskiy 
6547995026SVladimir Sementsov-Ogievskiy 
66f2a8f0a6SJuan Quintela     LoadStateHandler *load_state;
67acb5ea86SJuan Quintela     int (*load_setup)(QEMUFile *f, void *opaque);
68acb5ea86SJuan Quintela     int (*load_cleanup)(void *opaque);
69d1b8eadbSPeter Xu     /* Called when postcopy migration wants to resume from failure */
70d1b8eadbSPeter Xu     int (*resume_prepare)(MigrationState *s, void *opaque);
71f2a8f0a6SJuan Quintela } SaveVMHandlers;
72f2a8f0a6SJuan Quintela 
73ce62df53SDr. David Alan Gilbert int register_savevm_live(const char *idstr,
74*93062e23SPeter Xu                          uint32_t instance_id,
75f2a8f0a6SJuan Quintela                          int version_id,
76de22ded0SMarc-André Lureau                          const SaveVMHandlers *ops,
77f2a8f0a6SJuan Quintela                          void *opaque);
78f2a8f0a6SJuan Quintela 
793cad405bSMarc-André Lureau void unregister_savevm(VMStateIf *obj, const char *idstr, void *opaque);
80f2a8f0a6SJuan Quintela 
81f2a8f0a6SJuan Quintela #endif
82