Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20180323' into...
[qemu/ar7.git] / replication.h
blob8faefe005f83584c39e66e5a80cbb2aa1bc0c1ca
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/queue.h"
21 typedef struct ReplicationOps ReplicationOps;
22 typedef struct ReplicationState ReplicationState;
24 /**
25 * SECTION:replication.h
26 * @title:Base Replication System
27 * @short_description: interfaces for handling replication
29 * The Replication Model provides a framework for handling Replication
31 * <example>
32 * <title>How to use replication interfaces</title>
33 * <programlisting>
34 * #include "replication.h"
36 * typedef struct BDRVReplicationState {
37 * ReplicationState *rs;
38 * } BDRVReplicationState;
40 * static void replication_start(ReplicationState *rs, ReplicationMode mode,
41 * Error **errp);
42 * static void replication_do_checkpoint(ReplicationState *rs, Error **errp);
43 * static void replication_get_error(ReplicationState *rs, Error **errp);
44 * static void replication_stop(ReplicationState *rs, bool failover,
45 * Error **errp);
47 * static ReplicationOps replication_ops = {
48 * .start = replication_start,
49 * .checkpoint = replication_do_checkpoint,
50 * .get_error = replication_get_error,
51 * .stop = replication_stop,
52 * }
54 * static int replication_open(BlockDriverState *bs, QDict *options,
55 * int flags, Error **errp)
56 * {
57 * BDRVReplicationState *s = bs->opaque;
58 * s->rs = replication_new(bs, &replication_ops);
59 * return 0;
60 * }
62 * static void replication_close(BlockDriverState *bs)
63 * {
64 * BDRVReplicationState *s = bs->opaque;
65 * replication_remove(s->rs);
66 * }
68 * BlockDriver bdrv_replication = {
69 * .format_name = "replication",
70 * .protocol_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 */