| 1 | /* |
| 2 | * Copyright (c) 2021, 2024 Oracle and/or its affiliates. |
| 3 | * |
| 4 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 5 | * See the COPYING file in the top-level directory. |
| 6 | */ |
| 7 | |
| 8 | #ifndef MIGRATION_CPR_H |
| 9 | #define MIGRATION_CPR_H |
| 10 | |
| 11 | #include "qapi/qapi-types-migration.h" |
| 12 | #include "io/channel.h" |
| 13 | #include "qemu/queue.h" |
| 14 | |
| 15 | #define MIG_MODE_NONE -1 |
| 16 | |
| 17 | #define QEMU_CPR_FILE_MAGIC 0x51435052 |
| 18 | #define QEMU_CPR_FILE_VERSION 0x00000001 |
| 19 | #define CPR_STATE "CprState" |
| 20 | |
| 21 | typedef QLIST_HEAD(CprFdList, CprFd) CprFdList; |
| 22 | typedef QLIST_HEAD(CprVFIODeviceList, CprVFIODevice) CprVFIODeviceList; |
| 23 | |
| 24 | typedef struct CprState { |
| 25 | CprFdList fds; |
| 26 | CprVFIODeviceList vfio_devices; |
| 27 | } CprState; |
| 28 | |
| 29 | extern CprState cpr_state; |
| 30 | |
| 31 | void cpr_save_fd(const char *name, int id, int fd); |
| 32 | void cpr_delete_fd(const char *name, int id); |
| 33 | int cpr_find_fd(const char *name, int id); |
| 34 | void cpr_resave_fd(const char *name, int id, int fd); |
| 35 | int cpr_open_fd(const char *path, int flags, const char *name, int id, |
| 36 | Error **errp); |
| 37 | |
| 38 | typedef bool (*cpr_walk_fd_cb)(int fd); |
| 39 | bool cpr_walk_fd(cpr_walk_fd_cb cb); |
| 40 | |
| 41 | MigMode cpr_get_incoming_mode(void); |
| 42 | void cpr_set_incoming_mode(MigMode mode); |
| 43 | bool cpr_is_incoming(void); |
| 44 | |
| 45 | bool cpr_state_save(MigrationChannel *channel, Error **errp); |
| 46 | bool cpr_state_load(MigrationChannel *channel, Error **errp); |
| 47 | void cpr_state_close(void); |
| 48 | struct QIOChannel *cpr_state_ioc(void); |
| 49 | |
| 50 | bool cpr_incoming_needed(void *opaque); |
| 51 | int cpr_get_fd_param(const char *name, const char *fdname, int index, |
| 52 | Error **errp); |
| 53 | |
| 54 | QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp); |
| 55 | QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp); |
| 56 | |
| 57 | void cpr_transfer_add_hup_watch(MigrationState *s, QIOChannelFunc func, |
| 58 | void *opaque); |
| 59 | void cpr_transfer_source_destroy(MigrationState *s); |
| 60 | bool cpr_transfer_source_active(MigrationState *s); |
| 61 | |
| 62 | void cpr_exec_init(void); |
| 63 | QEMUFile *cpr_exec_output(Error **errp); |
| 64 | QEMUFile *cpr_exec_input(Error **errp); |
| 65 | bool cpr_exec_persist_state(QEMUFile *f, Error **errp); |
| 66 | bool cpr_exec_has_state(void); |
| 67 | void cpr_exec_unpersist_state(void); |
| 68 | void cpr_exec_unpreserve_fds(void); |
| 69 | #endif |