s390x/pci: Add routine to get the vfio dma available count
[qemu/ar7.git] / replication.h
blobd49fc22cb9fbb8c5506b3b27fe1bfab53128f9ab
1 /*
2 * Replication filter
4 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
5 * Copyright (c) 2016 Intel Corporation
6 * Copyright (c) 2016 FUJITSU LIMITED
8 * Author:
9 * Changlong Xie <xiecl.fnst@cn.fujitsu.com>
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
15 #ifndef REPLICATION_H
16 #define REPLICATION_H
18 #include "qapi/qapi-types-block-core.h"
19 #include "qemu/module.h"
20 #include "qemu/queue.h"
22 typedef struct ReplicationOps ReplicationOps;
23 typedef struct ReplicationState ReplicationState;
25 /**
26 * SECTION:replication.h
27 * @title:Base Replication System
28 * @short_description: interfaces for handling replication
30 * The Replication Model provides a framework for handling Replication
32 * <example>
33 * <title>How to use replication interfaces</title>
34 * <programlisting>
35 * #include "replication.h"
37 * typedef struct BDRVReplicationState {
38 * ReplicationState *rs;
39 * } BDRVReplicationState;
41 * static void replication_start(ReplicationState *rs, ReplicationMode mode,
42 * Error **errp);
43 * static void replication_do_checkpoint(ReplicationState *rs, Error **errp);
44 * static void replication_get_error(ReplicationState *rs, Error **errp);
45 * static void replication_stop(ReplicationState *rs, bool failover,
46 * Error **errp);
48 * static ReplicationOps replication_ops = {
49 * .start = replication_start,
50 * .checkpoint = replication_do_checkpoint,
51 * .get_error = replication_get_error,
52 * .stop = replication_stop,
53 * }
55 * static int replication_open(BlockDriverState *bs, QDict *options,
56 * int flags, Error **errp)
57 * {
58 * BDRVReplicationState *s = bs->opaque;
59 * s->rs = replication_new(bs, &replication_ops);
60 * return 0;
61 * }
63 * static void replication_close(BlockDriverState *bs)
64 * {
65 * BDRVReplicationState *s = bs->opaque;
66 * replication_remove(s->rs);
67 * }
69 * BlockDriver bdrv_replication = {
70 * .format_name = "replication",
71 * .instance_size = sizeof(BDRVReplicationState),
73 * .bdrv_open = replication_open,
74 * .bdrv_close = replication_close,
75 * };
77 * static void bdrv_replication_init(void)
78 * {
79 * bdrv_register(&bdrv_replication);
80 * }
82 * block_init(bdrv_replication_init);
83 * </programlisting>
84 * </example>
86 * We create an example about how to use replication interfaces in above.
87 * Then in migration, we can use replication_(start/stop/do_checkpoint/
88 * get_error)_all to handle all replication operations.
91 /**
92 * ReplicationState:
93 * @opaque: opaque pointer value passed to this ReplicationState
94 * @ops: replication operation of this ReplicationState
95 * @node: node that we will insert into @replication_states QLIST
97 struct ReplicationState {
98 void *opaque;
99 ReplicationOps *ops;
100 QLIST_ENTRY(ReplicationState) node;
104 * ReplicationOps:
105 * @start: callback to start replication
106 * @stop: callback to stop replication
107 * @checkpoint: callback to do checkpoint
108 * @get_error: callback to check if error occurred during replication
110 struct ReplicationOps {
111 void (*start)(ReplicationState *rs, ReplicationMode mode, Error **errp);
112 void (*stop)(ReplicationState *rs, bool failover, Error **errp);
113 void (*checkpoint)(ReplicationState *rs, Error **errp);
114 void (*get_error)(ReplicationState *rs, Error **errp);
118 * replication_new:
119 * @opaque: opaque pointer value passed to ReplicationState
120 * @ops: replication operation of the new relevant ReplicationState
122 * Called to create a new ReplicationState instance, and then insert it
123 * into @replication_states QLIST
125 * Returns: the new ReplicationState instance
127 ReplicationState *replication_new(void *opaque, ReplicationOps *ops);
130 * replication_remove:
131 * @rs: the ReplicationState instance to remove
133 * Called to remove a ReplicationState instance, and then delete it from
134 * @replication_states QLIST
136 void replication_remove(ReplicationState *rs);
139 * replication_start_all:
140 * @mode: replication mode that could be "primary" or "secondary"
141 * @errp: returns an error if this function fails
143 * Start replication, called in migration/checkpoint thread
145 * Note: the caller of the function MUST make sure vm stopped
147 void replication_start_all(ReplicationMode mode, Error **errp);
150 * replication_do_checkpoint_all:
151 * @errp: returns an error if this function fails
153 * This interface is called after all VM state is transferred to Secondary QEMU
155 void replication_do_checkpoint_all(Error **errp);
158 * replication_get_error_all:
159 * @errp: returns an error if this function fails
161 * This interface is called to check if error occurred during replication
163 void replication_get_error_all(Error **errp);
166 * replication_stop_all:
167 * @failover: boolean value that indicates if we need do failover or not
168 * @errp: returns an error if this function fails
170 * It is called on failover. The vm should be stopped before calling it, if you
171 * use this API to shutdown the guest, or other things except failover
173 void replication_stop_all(bool failover, Error **errp);
175 #endif /* REPLICATION_H */