xref: /openbmc/qemu/include/migration/cpr.h (revision abe80c8ae24cc853b21e9574cf99bf9b97a78bc8)
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 "qemu/queue.h"
13 
14 #define MIG_MODE_NONE           -1
15 
16 #define QEMU_CPR_FILE_MAGIC     0x51435052
17 #define QEMU_CPR_FILE_VERSION   0x00000001
18 #define CPR_STATE "CprState"
19 
20 typedef QLIST_HEAD(CprFdList, CprFd) CprFdList;
21 typedef QLIST_HEAD(CprVFIODeviceList, CprVFIODevice) CprVFIODeviceList;
22 
23 typedef struct CprState {
24     CprFdList fds;
25     CprVFIODeviceList vfio_devices;
26 } CprState;
27 
28 extern CprState cpr_state;
29 
30 void cpr_save_fd(const char *name, int id, int fd);
31 void cpr_delete_fd(const char *name, int id);
32 int cpr_find_fd(const char *name, int id);
33 void cpr_resave_fd(const char *name, int id, int fd);
34 int cpr_open_fd(const char *path, int flags, const char *name, int id,
35                 Error **errp);
36 
37 typedef bool (*cpr_walk_fd_cb)(int fd);
38 bool cpr_walk_fd(cpr_walk_fd_cb cb);
39 
40 MigMode cpr_get_incoming_mode(void);
41 void cpr_set_incoming_mode(MigMode mode);
42 bool cpr_is_incoming(void);
43 
44 bool cpr_state_save(MigrationChannel *channel, Error **errp);
45 int cpr_state_load(MigrationChannel *channel, Error **errp);
46 void cpr_state_close(void);
47 struct QIOChannel *cpr_state_ioc(void);
48 
49 bool cpr_incoming_needed(void *opaque);
50 int cpr_get_fd_param(const char *name, const char *fdname, int index,
51                      Error **errp);
52 
53 QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp);
54 QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp);
55 
56 void cpr_exec_init(void);
57 QEMUFile *cpr_exec_output(Error **errp);
58 QEMUFile *cpr_exec_input(Error **errp);
59 bool cpr_exec_persist_state(QEMUFile *f, Error **errp);
60 bool cpr_exec_has_state(void);
61 void cpr_exec_unpersist_state(void);
62 void cpr_exec_unpreserve_fds(void);
63 #endif
64