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.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. #ifndef REPLICATION_H
  15. #define REPLICATION_H
  16. #include "qapi/qapi-types-block-core.h"
  17. #include "qemu/module.h"
  18. #include "qemu/queue.h"
  19. typedef struct ReplicationOps ReplicationOps;
  20. typedef struct ReplicationState ReplicationState;
  21. /**
  22. * SECTION:replication.h
  23. * @title:Base Replication System
  24. * @short_description: interfaces for handling replication
  25. *
  26. * The Replication Model provides a framework for handling Replication
  27. *
  28. * <example>
  29. * <title>How to use replication interfaces</title>
  30. * <programlisting>
  31. * #include "replication.h"
  32. *
  33. * typedef struct BDRVReplicationState {
  34. * ReplicationState *rs;
  35. * } BDRVReplicationState;
  36. *
  37. * static void replication_start(ReplicationState *rs, ReplicationMode mode,
  38. * Error **errp);
  39. * static void replication_do_checkpoint(ReplicationState *rs, Error **errp);
  40. * static void replication_get_error(ReplicationState *rs, Error **errp);
  41. * static void replication_stop(ReplicationState *rs, bool failover,
  42. * Error **errp);
  43. *
  44. * static ReplicationOps replication_ops = {
  45. * .start = replication_start,
  46. * .checkpoint = replication_do_checkpoint,
  47. * .get_error = replication_get_error,
  48. * .stop = replication_stop,
  49. * }
  50. *
  51. * static int replication_open(BlockDriverState *bs, QDict *options,
  52. * int flags, Error **errp)
  53. * {
  54. * BDRVReplicationState *s = bs->opaque;
  55. * s->rs = replication_new(bs, &replication_ops);
  56. * return 0;
  57. * }
  58. *
  59. * static void replication_close(BlockDriverState *bs)
  60. * {
  61. * BDRVReplicationState *s = bs->opaque;
  62. * replication_remove(s->rs);
  63. * }
  64. *
  65. * BlockDriver bdrv_replication = {
  66. * .format_name = "replication",
  67. * .instance_size = sizeof(BDRVReplicationState),
  68. *
  69. * .bdrv_open = replication_open,
  70. * .bdrv_close = replication_close,
  71. * };
  72. *
  73. * static void bdrv_replication_init(void)
  74. * {
  75. * bdrv_register(&bdrv_replication);
  76. * }
  77. *
  78. * block_init(bdrv_replication_init);
  79. * </programlisting>
  80. * </example>
  81. *
  82. * We create an example about how to use replication interfaces in above.
  83. * Then in migration, we can use replication_(start/stop/do_checkpoint/
  84. * get_error)_all to handle all replication operations.
  85. */
  86. /**
  87. * ReplicationState:
  88. * @opaque: opaque pointer value passed to this ReplicationState
  89. * @ops: replication operation of this ReplicationState
  90. * @node: node that we will insert into @replication_states QLIST
  91. */
  92. struct ReplicationState {
  93. void *opaque;
  94. ReplicationOps *ops;
  95. QLIST_ENTRY(ReplicationState) node;
  96. };
  97. /**
  98. * ReplicationOps:
  99. * @start: callback to start replication
  100. * @stop: callback to stop replication
  101. * @checkpoint: callback to do checkpoint
  102. * @get_error: callback to check if error occurred during replication
  103. */
  104. struct ReplicationOps {
  105. void (*start)(ReplicationState *rs, ReplicationMode mode, Error **errp);
  106. void (*stop)(ReplicationState *rs, bool failover, Error **errp);
  107. void (*checkpoint)(ReplicationState *rs, Error **errp);
  108. void (*get_error)(ReplicationState *rs, Error **errp);
  109. };
  110. /**
  111. * replication_new:
  112. * @opaque: opaque pointer value passed to ReplicationState
  113. * @ops: replication operation of the new relevant ReplicationState
  114. *
  115. * Called to create a new ReplicationState instance, and then insert it
  116. * into @replication_states QLIST
  117. *
  118. * Returns: the new ReplicationState instance
  119. */
  120. ReplicationState *replication_new(void *opaque, ReplicationOps *ops);
  121. /**
  122. * replication_remove:
  123. * @rs: the ReplicationState instance to remove
  124. *
  125. * Called to remove a ReplicationState instance, and then delete it from
  126. * @replication_states QLIST
  127. */
  128. void replication_remove(ReplicationState *rs);
  129. /**
  130. * replication_start_all:
  131. * @mode: replication mode that could be "primary" or "secondary"
  132. * @errp: returns an error if this function fails
  133. *
  134. * Start replication, called in migration/checkpoint thread
  135. *
  136. * Note: the caller of the function MUST make sure vm stopped
  137. */
  138. void replication_start_all(ReplicationMode mode, Error **errp);
  139. /**
  140. * replication_do_checkpoint_all:
  141. * @errp: returns an error if this function fails
  142. *
  143. * This interface is called after all VM state is transferred to Secondary QEMU
  144. */
  145. void replication_do_checkpoint_all(Error **errp);
  146. /**
  147. * replication_get_error_all:
  148. * @errp: returns an error if this function fails
  149. *
  150. * This interface is called to check if error occurred during replication
  151. */
  152. void replication_get_error_all(Error **errp);
  153. /**
  154. * replication_stop_all:
  155. * @failover: boolean value that indicates if we need do failover or not
  156. * @errp: returns an error if this function fails
  157. *
  158. * It is called on failover. The vm should be stopped before calling it, if you
  159. * use this API to shutdown the guest, or other things except failover
  160. */
  161. void replication_stop_all(bool failover, Error **errp);
  162. #endif /* REPLICATION_H */