aboutsummaryrefslogtreecommitdiffstats
path: root/replication.c
diff options
context:
space:
mode:
authorTimos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>2023-10-10 11:40:56 +0000
committerTimos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>2023-10-10 11:40:56 +0000
commite02cda008591317b1625707ff8e115a4841aa889 (patch)
treeaee302e3cf8b59ec2d32ec481be3d1afddfc8968 /replication.c
parentcc668e6b7e0ffd8c9d130513d12053cf5eda1d3b (diff)
Introduce Virtio-loopback epsilon release:
Epsilon release introduces a new compatibility layer which make virtio-loopback design to work with QEMU and rust-vmm vhost-user backend without require any changes. Signed-off-by: Timos Ampelikiotis <t.ampelikiotis@virtualopensystems.com> Change-Id: I52e57563e08a7d0bdc002f8e928ee61ba0c53dd9
Diffstat (limited to 'replication.c')
-rw-r--r--replication.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/replication.c b/replication.c
new file mode 100644
index 000000000..4acd3f800
--- /dev/null
+++ b/replication.c
@@ -0,0 +1,107 @@
+/*
+ * Replication filter
+ *
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
+ * Copyright (c) 2016 Intel Corporation
+ * Copyright (c) 2016 FUJITSU LIMITED
+ *
+ * Author:
+ * Changlong Xie <xiecl.fnst@cn.fujitsu.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "block/replication.h"
+
+static QLIST_HEAD(, ReplicationState) replication_states;
+
+ReplicationState *replication_new(void *opaque, ReplicationOps *ops)
+{
+ ReplicationState *rs;
+
+ assert(ops != NULL);
+ rs = g_new0(ReplicationState, 1);
+ rs->opaque = opaque;
+ rs->ops = ops;
+ QLIST_INSERT_HEAD(&replication_states, rs, node);
+
+ return rs;
+}
+
+void replication_remove(ReplicationState *rs)
+{
+ if (rs) {
+ QLIST_REMOVE(rs, node);
+ g_free(rs);
+ }
+}
+
+/*
+ * The caller of the function MUST make sure vm stopped
+ */
+void replication_start_all(ReplicationMode mode, Error **errp)
+{
+ ReplicationState *rs, *next;
+ Error *local_err = NULL;
+
+ QLIST_FOREACH_SAFE(rs, &replication_states, node, next) {
+ if (rs->ops && rs->ops->start) {
+ rs->ops->start(rs, mode, &local_err);
+ }
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ }
+}
+
+void replication_do_checkpoint_all(Error **errp)
+{
+ ReplicationState *rs, *next;
+ Error *local_err = NULL;
+
+ QLIST_FOREACH_SAFE(rs, &replication_states, node, next) {
+ if (rs->ops && rs->ops->checkpoint) {
+ rs->ops->checkpoint(rs, &local_err);
+ }
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ }
+}
+
+void replication_get_error_all(Error **errp)
+{
+ ReplicationState *rs, *next;
+ Error *local_err = NULL;
+
+ QLIST_FOREACH_SAFE(rs, &replication_states, node, next) {
+ if (rs->ops && rs->ops->get_error) {
+ rs->ops->get_error(rs, &local_err);
+ }
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ }
+}
+
+void replication_stop_all(bool failover, Error **errp)
+{
+ ReplicationState *rs, *next;
+ Error *local_err = NULL;
+
+ QLIST_FOREACH_SAFE(rs, &replication_states, node, next) {
+ if (rs->ops && rs->ops->stop) {
+ rs->ops->stop(rs, failover, &local_err);
+ }
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ }
+}