You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

replication.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Replication filter
  3. *
  4. * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
  5. * Copyright (c) 2016 Intel Corporation
  6. * Copyright (c) 2016 FUJITSU LIMITED
  7. *
  8. * Author:
  9. * Changlong Xie <xiecl.fnst@cn.fujitsu.com>
  10. *
  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.
  13. */
  14. #include "qemu/osdep.h"
  15. #include "qapi/error.h"
  16. #include "replication.h"
  17. static QLIST_HEAD(, ReplicationState) replication_states;
  18. ReplicationState *replication_new(void *opaque, ReplicationOps *ops)
  19. {
  20. ReplicationState *rs;
  21. assert(ops != NULL);
  22. rs = g_new0(ReplicationState, 1);
  23. rs->opaque = opaque;
  24. rs->ops = ops;
  25. QLIST_INSERT_HEAD(&replication_states, rs, node);
  26. return rs;
  27. }
  28. void replication_remove(ReplicationState *rs)
  29. {
  30. if (rs) {
  31. QLIST_REMOVE(rs, node);
  32. g_free(rs);
  33. }
  34. }
  35. /*
  36. * The caller of the function MUST make sure vm stopped
  37. */
  38. void replication_start_all(ReplicationMode mode, Error **errp)
  39. {
  40. ReplicationState *rs, *next;
  41. Error *local_err = NULL;
  42. QLIST_FOREACH_SAFE(rs, &replication_states, node, next) {
  43. if (rs->ops && rs->ops->start) {
  44. rs->ops->start(rs, mode, &local_err);
  45. }
  46. if (local_err) {
  47. error_propagate(errp, local_err);
  48. return;
  49. }
  50. }
  51. }
  52. void replication_do_checkpoint_all(Error **errp)
  53. {
  54. ReplicationState *rs, *next;
  55. Error *local_err = NULL;
  56. QLIST_FOREACH_SAFE(rs, &replication_states, node, next) {
  57. if (rs->ops && rs->ops->checkpoint) {
  58. rs->ops->checkpoint(rs, &local_err);
  59. }
  60. if (local_err) {
  61. error_propagate(errp, local_err);
  62. return;
  63. }
  64. }
  65. }
  66. void replication_get_error_all(Error **errp)
  67. {
  68. ReplicationState *rs, *next;
  69. Error *local_err = NULL;
  70. QLIST_FOREACH_SAFE(rs, &replication_states, node, next) {
  71. if (rs->ops && rs->ops->get_error) {
  72. rs->ops->get_error(rs, &local_err);
  73. }
  74. if (local_err) {
  75. error_propagate(errp, local_err);
  76. return;
  77. }
  78. }
  79. }
  80. void replication_stop_all(bool failover, Error **errp)
  81. {
  82. ReplicationState *rs, *next;
  83. Error *local_err = NULL;
  84. QLIST_FOREACH_SAFE(rs, &replication_states, node, next) {
  85. if (rs->ops && rs->ops->stop) {
  86. rs->ops->stop(rs, failover, &local_err);
  87. }
  88. if (local_err) {
  89. error_propagate(errp, local_err);
  90. return;
  91. }
  92. }
  93. }