cpg.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * Copyright (c) 2006-2019 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfi@redhat.com)
  7. * Author: Jan Friesse (jfriesse@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef COROSYNC_CPG_H_DEFINED
  36. #define COROSYNC_CPG_H_DEFINED
  37. #include <netinet/in.h>
  38. #include <sys/socket.h>
  39. #include <corosync/corotypes.h>
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /**
  44. * @addtogroup cpg_corosync
  45. *
  46. * @{
  47. */
  48. /**
  49. * @brief cpg_handle_t
  50. */
  51. typedef uint64_t cpg_handle_t;
  52. /**
  53. * @brief cpg_iteration_handle_t
  54. */
  55. typedef uint64_t cpg_iteration_handle_t;
  56. /**
  57. * @brief The cpg_guarantee_t enum
  58. */
  59. typedef enum {
  60. CPG_TYPE_UNORDERED, /**< not implemented */
  61. CPG_TYPE_FIFO, /**< same as agreed */
  62. CPG_TYPE_AGREED,
  63. CPG_TYPE_SAFE /**< not implemented */
  64. } cpg_guarantee_t;
  65. /**
  66. * @brief The cpg_flow_control_state_t enum
  67. */
  68. typedef enum {
  69. CPG_FLOW_CONTROL_DISABLED, /**< flow control is disabled - new messages may be sent */
  70. CPG_FLOW_CONTROL_ENABLED /**< flow control is enabled - new messages should not be sent */
  71. } cpg_flow_control_state_t;
  72. /**
  73. * @brief The cpg_reason_t enum
  74. */
  75. typedef enum {
  76. CPG_REASON_UNDEFINED = 0,
  77. CPG_REASON_JOIN = 1,
  78. CPG_REASON_LEAVE = 2,
  79. CPG_REASON_NODEDOWN = 3,
  80. CPG_REASON_NODEUP = 4,
  81. CPG_REASON_PROCDOWN = 5
  82. } cpg_reason_t;
  83. /**
  84. * @brief The cpg_iteration_type_t enum
  85. */
  86. typedef enum {
  87. CPG_ITERATION_NAME_ONLY = 1,
  88. CPG_ITERATION_ONE_GROUP = 2,
  89. CPG_ITERATION_ALL = 3,
  90. } cpg_iteration_type_t;
  91. /**
  92. * @brief The cpg_model_t enum
  93. */
  94. typedef enum {
  95. CPG_MODEL_V1 = 1,
  96. } cpg_model_t;
  97. /**
  98. * @brief The cpg_address struct
  99. */
  100. struct cpg_address {
  101. uint32_t nodeid;
  102. uint32_t pid;
  103. uint32_t reason;
  104. };
  105. #define CPG_MAX_NAME_LENGTH 128
  106. /**
  107. * @brief The cpg_name struct
  108. */
  109. struct cpg_name {
  110. uint32_t length;
  111. char value[CPG_MAX_NAME_LENGTH];
  112. };
  113. #define CPG_MEMBERS_MAX 128
  114. /**
  115. * @brief The cpg_iteration_description_t struct
  116. */
  117. struct cpg_iteration_description_t {
  118. struct cpg_name group;
  119. uint32_t nodeid;
  120. uint32_t pid;
  121. };
  122. /**
  123. * @brief The cpg_ring_id struct
  124. */
  125. struct cpg_ring_id {
  126. uint32_t nodeid;
  127. uint64_t seq;
  128. };
  129. /**
  130. * @brief The cpg_deliver_fn_t callback
  131. */
  132. typedef void (*cpg_deliver_fn_t) (
  133. cpg_handle_t handle,
  134. const struct cpg_name *group_name,
  135. uint32_t nodeid,
  136. uint32_t pid,
  137. /**
  138. * Unlike many "msg" pointers, this one is deliberately *not*
  139. * declared const in order to permit in-place endian conversion.
  140. */
  141. void *msg,
  142. size_t msg_len);
  143. /**
  144. * @brief The cpg_confchg_fn_t callback
  145. */
  146. typedef void (*cpg_confchg_fn_t) (
  147. cpg_handle_t handle,
  148. const struct cpg_name *group_name,
  149. const struct cpg_address *member_list, size_t member_list_entries,
  150. const struct cpg_address *left_list, size_t left_list_entries,
  151. const struct cpg_address *joined_list, size_t joined_list_entries);
  152. /**
  153. * @brief The cpg_totem_confchg_fn_t callback
  154. */
  155. typedef void (*cpg_totem_confchg_fn_t) (
  156. cpg_handle_t handle,
  157. struct cpg_ring_id ring_id,
  158. uint32_t member_list_entries,
  159. const uint32_t *member_list);
  160. /**
  161. * @brief The cpg_callbacks_t struct
  162. */
  163. typedef struct {
  164. cpg_deliver_fn_t cpg_deliver_fn;
  165. cpg_confchg_fn_t cpg_confchg_fn;
  166. } cpg_callbacks_t;
  167. /**
  168. * @brief The cpg_model_data_t struct
  169. */
  170. typedef struct {
  171. cpg_model_t model;
  172. } cpg_model_data_t;
  173. #define CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF 0x01
  174. /**
  175. * @brief The cpg_model_v1_data_t struct
  176. */
  177. typedef struct {
  178. cpg_model_t model;
  179. cpg_deliver_fn_t cpg_deliver_fn;
  180. cpg_confchg_fn_t cpg_confchg_fn;
  181. cpg_totem_confchg_fn_t cpg_totem_confchg_fn;
  182. unsigned int flags;
  183. } cpg_model_v1_data_t;
  184. /** @} */
  185. /**
  186. * @brief Create a new cpg connection
  187. * @param handle
  188. * @param callbacks
  189. * @return
  190. */
  191. cs_error_t cpg_initialize (
  192. cpg_handle_t *handle,
  193. cpg_callbacks_t *callbacks);
  194. /**
  195. * @brief Create a new cpg connection, initialize with model
  196. * @param handle
  197. * @param model
  198. * @param model_data
  199. * @param context
  200. * @return
  201. */
  202. cs_error_t cpg_model_initialize (
  203. cpg_handle_t *handle,
  204. cpg_model_t model,
  205. cpg_model_data_t *model_data,
  206. void *context);
  207. /**
  208. * @brief Close the cpg handle
  209. * @param handle
  210. * @return
  211. */
  212. cs_error_t cpg_finalize (
  213. cpg_handle_t handle);
  214. /**
  215. * @brief Get a file descriptor on which to poll.
  216. *
  217. * cpg_handle_t is NOT a file descriptor and may not be used directly.
  218. *
  219. * @param handle
  220. * @param fd
  221. * @return
  222. */
  223. cs_error_t cpg_fd_get (
  224. cpg_handle_t handle,
  225. int *fd);
  226. /**
  227. * @brief Get maximum size of a message that will not be fragmented
  228. * @param handle
  229. * @param size
  230. * @return
  231. */
  232. cs_error_t cpg_max_atomic_msgsize_get (
  233. cpg_handle_t handle,
  234. uint32_t *size);
  235. /**
  236. * @brief Get contexts for a CPG handle
  237. * @param handle
  238. * @param context
  239. * @return
  240. */
  241. cs_error_t cpg_context_get (
  242. cpg_handle_t handle,
  243. void **context);
  244. /**
  245. * @brief Set contexts for a CPG handle
  246. * @param handle
  247. * @param context
  248. * @return
  249. */
  250. cs_error_t cpg_context_set (
  251. cpg_handle_t handle,
  252. void *context);
  253. /**
  254. * @brief Dispatch messages and configuration changes
  255. * @param handle
  256. * @param dispatch_types
  257. * @return
  258. */
  259. cs_error_t cpg_dispatch (
  260. cpg_handle_t handle,
  261. cs_dispatch_flags_t dispatch_types);
  262. /**
  263. * @brief Join one or more groups.
  264. *
  265. * messages multicasted with cpg_mcast_joined will be sent to every
  266. * group that has been joined on handle handle. Any message multicasted
  267. * to a group that has been previously joined will be delivered in cpg_dispatch
  268. *
  269. * @param handle
  270. * @param group
  271. * @return
  272. */
  273. cs_error_t cpg_join (
  274. cpg_handle_t handle,
  275. const struct cpg_name *group);
  276. /**
  277. * @brief Leave one or more groups
  278. * @param handle
  279. * @param group
  280. * @return
  281. */
  282. cs_error_t cpg_leave (
  283. cpg_handle_t handle,
  284. const struct cpg_name *group);
  285. /**
  286. * @brief Multicast to groups joined with cpg_join.
  287. *
  288. * @param handle
  289. * @param guarantee
  290. * @param iovec This iovec will be multicasted to all groups joined with
  291. * the cpg_join interface for handle.
  292. * @param iov_len
  293. */
  294. cs_error_t cpg_mcast_joined (
  295. cpg_handle_t handle,
  296. cpg_guarantee_t guarantee,
  297. const struct iovec *iovec,
  298. unsigned int iov_len);
  299. /**
  300. * @brief Get membership information from cpg
  301. * @param handle
  302. * @param groupName
  303. * @param member_list
  304. * @param member_list_entries
  305. * @return
  306. */
  307. cs_error_t cpg_membership_get (
  308. cpg_handle_t handle,
  309. struct cpg_name *groupName,
  310. struct cpg_address *member_list,
  311. int *member_list_entries);
  312. /**
  313. * @brief cpg_local_get
  314. * @param handle
  315. * @param local_nodeid
  316. * @return
  317. */
  318. cs_error_t cpg_local_get (
  319. cpg_handle_t handle,
  320. unsigned int *local_nodeid);
  321. /**
  322. * @brief cpg_flow_control_state_get
  323. * @param handle
  324. * @param flow_control_enabled
  325. * @return
  326. */
  327. cs_error_t cpg_flow_control_state_get (
  328. cpg_handle_t handle,
  329. cpg_flow_control_state_t *flow_control_enabled);
  330. /**
  331. * @brief cpg_zcb_alloc
  332. * @param handle
  333. * @param size
  334. * @param buffer
  335. * @return
  336. */
  337. cs_error_t cpg_zcb_alloc (
  338. cpg_handle_t handle,
  339. size_t size,
  340. void **buffer);
  341. /**
  342. * @brief cpg_zcb_free
  343. * @param handle
  344. * @param buffer
  345. * @return
  346. */
  347. cs_error_t cpg_zcb_free (
  348. cpg_handle_t handle,
  349. void *buffer);
  350. /**
  351. * @brief cpg_zcb_mcast_joined
  352. * @param handle
  353. * @param guarantee
  354. * @param msg
  355. * @param msg_len
  356. * @return
  357. */
  358. cs_error_t cpg_zcb_mcast_joined (
  359. cpg_handle_t handle,
  360. cpg_guarantee_t guarantee,
  361. void *msg,
  362. size_t msg_len);
  363. /**
  364. * @brief cpg_iteration_initialize
  365. * @param handle
  366. * @param iteration_type
  367. * @param group
  368. * @param cpg_iteration_handle
  369. * @return
  370. */
  371. cs_error_t cpg_iteration_initialize(
  372. cpg_handle_t handle,
  373. cpg_iteration_type_t iteration_type,
  374. const struct cpg_name *group,
  375. cpg_iteration_handle_t *cpg_iteration_handle);
  376. /**
  377. * @brief cpg_iteration_next
  378. * @param handle
  379. * @param description
  380. * @return
  381. */
  382. cs_error_t cpg_iteration_next(
  383. cpg_iteration_handle_t handle,
  384. struct cpg_iteration_description_t *description);
  385. /**
  386. * @brief cpg_iteration_finalize
  387. * @param handle
  388. * @return
  389. */
  390. cs_error_t cpg_iteration_finalize (
  391. cpg_iteration_handle_t handle);
  392. #ifdef __cplusplus
  393. }
  394. #endif
  395. #endif /* COROSYNC_CPG_H_DEFINED */