4
0

cpg.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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 <corosync/corotypes.h>
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /**
  43. * @addtogroup cpg_corosync
  44. *
  45. * @{
  46. */
  47. /**
  48. * @brief cpg_handle_t
  49. */
  50. typedef uint64_t cpg_handle_t;
  51. /**
  52. * @brief cpg_iteration_handle_t
  53. */
  54. typedef uint64_t cpg_iteration_handle_t;
  55. /**
  56. * @brief The cpg_guarantee_t enum
  57. */
  58. typedef enum {
  59. CPG_TYPE_UNORDERED, /**< not implemented */
  60. CPG_TYPE_FIFO, /**< same as agreed */
  61. CPG_TYPE_AGREED,
  62. CPG_TYPE_SAFE /**< not implemented */
  63. } cpg_guarantee_t;
  64. /**
  65. * @brief The cpg_flow_control_state_t enum
  66. */
  67. typedef enum {
  68. CPG_FLOW_CONTROL_DISABLED, /**< flow control is disabled - new messages may be sent */
  69. CPG_FLOW_CONTROL_ENABLED /**< flow control is enabled - new messages should not be sent */
  70. } cpg_flow_control_state_t;
  71. /**
  72. * @brief The cpg_reason_t enum
  73. */
  74. typedef enum {
  75. CPG_REASON_UNDEFINED = 0,
  76. CPG_REASON_JOIN = 1,
  77. CPG_REASON_LEAVE = 2,
  78. CPG_REASON_NODEDOWN = 3,
  79. CPG_REASON_NODEUP = 4,
  80. CPG_REASON_PROCDOWN = 5
  81. } cpg_reason_t;
  82. /**
  83. * @brief The cpg_iteration_type_t enum
  84. */
  85. typedef enum {
  86. CPG_ITERATION_NAME_ONLY = 1,
  87. CPG_ITERATION_ONE_GROUP = 2,
  88. CPG_ITERATION_ALL = 3,
  89. } cpg_iteration_type_t;
  90. /**
  91. * @brief The cpg_model_t enum
  92. */
  93. typedef enum {
  94. CPG_MODEL_V1 = 1,
  95. } cpg_model_t;
  96. /**
  97. * @brief The cpg_address struct
  98. */
  99. struct cpg_address {
  100. uint32_t nodeid;
  101. uint32_t pid;
  102. uint32_t reason;
  103. };
  104. #define CPG_MAX_NAME_LENGTH 128
  105. /**
  106. * @brief The cpg_name struct
  107. */
  108. struct cpg_name {
  109. uint32_t length;
  110. char value[CPG_MAX_NAME_LENGTH];
  111. };
  112. #define CPG_MEMBERS_MAX 128
  113. /**
  114. * @brief The cpg_iteration_description_t struct
  115. */
  116. struct cpg_iteration_description_t {
  117. struct cpg_name group;
  118. uint32_t nodeid;
  119. uint32_t pid;
  120. };
  121. /**
  122. * @brief The cpg_ring_id struct
  123. */
  124. struct cpg_ring_id {
  125. uint32_t nodeid;
  126. uint64_t seq;
  127. };
  128. /**
  129. * @brief The cpg_deliver_fn_t callback
  130. */
  131. typedef void (*cpg_deliver_fn_t) (
  132. cpg_handle_t handle,
  133. const struct cpg_name *group_name,
  134. uint32_t nodeid,
  135. uint32_t pid,
  136. /**
  137. * Unlike many "msg" pointers, this one is deliberately *not*
  138. * declared const in order to permit in-place endian conversion.
  139. */
  140. void *msg,
  141. size_t msg_len);
  142. /**
  143. * @brief The cpg_confchg_fn_t callback
  144. */
  145. typedef void (*cpg_confchg_fn_t) (
  146. cpg_handle_t handle,
  147. const struct cpg_name *group_name,
  148. const struct cpg_address *member_list, size_t member_list_entries,
  149. const struct cpg_address *left_list, size_t left_list_entries,
  150. const struct cpg_address *joined_list, size_t joined_list_entries);
  151. /**
  152. * @brief The cpg_totem_confchg_fn_t callback
  153. */
  154. typedef void (*cpg_totem_confchg_fn_t) (
  155. cpg_handle_t handle,
  156. struct cpg_ring_id ring_id,
  157. uint32_t member_list_entries,
  158. const uint32_t *member_list);
  159. /**
  160. * @brief The cpg_callbacks_t struct
  161. */
  162. typedef struct {
  163. cpg_deliver_fn_t cpg_deliver_fn;
  164. cpg_confchg_fn_t cpg_confchg_fn;
  165. } cpg_callbacks_t;
  166. /**
  167. * @brief The cpg_model_data_t struct
  168. */
  169. typedef struct {
  170. cpg_model_t model;
  171. } cpg_model_data_t;
  172. #define CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF 0x01
  173. /**
  174. * @brief The cpg_model_v1_data_t struct
  175. */
  176. typedef struct {
  177. cpg_model_t model;
  178. cpg_deliver_fn_t cpg_deliver_fn;
  179. cpg_confchg_fn_t cpg_confchg_fn;
  180. cpg_totem_confchg_fn_t cpg_totem_confchg_fn;
  181. unsigned int flags;
  182. } cpg_model_v1_data_t;
  183. /** @} */
  184. /**
  185. * @brief Create a new cpg connection
  186. * @param handle
  187. * @param callbacks
  188. * @return
  189. */
  190. cs_error_t cpg_initialize (
  191. cpg_handle_t *handle,
  192. cpg_callbacks_t *callbacks);
  193. /**
  194. * @brief Create a new cpg connection, initialize with model
  195. * @param handle
  196. * @param model
  197. * @param model_data
  198. * @param context
  199. * @return
  200. */
  201. cs_error_t cpg_model_initialize (
  202. cpg_handle_t *handle,
  203. cpg_model_t model,
  204. cpg_model_data_t *model_data,
  205. void *context);
  206. /**
  207. * @brief Close the cpg handle
  208. * @param handle
  209. * @return
  210. */
  211. cs_error_t cpg_finalize (
  212. cpg_handle_t handle);
  213. /**
  214. * @brief Get a file descriptor on which to poll.
  215. *
  216. * cpg_handle_t is NOT a file descriptor and may not be used directly.
  217. *
  218. * @param handle
  219. * @param fd
  220. * @return
  221. */
  222. cs_error_t cpg_fd_get (
  223. cpg_handle_t handle,
  224. int *fd);
  225. /**
  226. * @brief Get maximum size of a message that will not be fragmented
  227. * @param handle
  228. * @param size
  229. * @return
  230. */
  231. cs_error_t cpg_max_atomic_msgsize_get (
  232. cpg_handle_t handle,
  233. uint32_t *size);
  234. /**
  235. * @brief Get contexts for a CPG handle
  236. * @param handle
  237. * @param context
  238. * @return
  239. */
  240. cs_error_t cpg_context_get (
  241. cpg_handle_t handle,
  242. void **context);
  243. /**
  244. * @brief Set contexts for a CPG handle
  245. * @param handle
  246. * @param context
  247. * @return
  248. */
  249. cs_error_t cpg_context_set (
  250. cpg_handle_t handle,
  251. void *context);
  252. /**
  253. * @brief Dispatch messages and configuration changes
  254. * @param handle
  255. * @param dispatch_types
  256. * @return
  257. */
  258. cs_error_t cpg_dispatch (
  259. cpg_handle_t handle,
  260. cs_dispatch_flags_t dispatch_types);
  261. /**
  262. * @brief Join one or more groups.
  263. *
  264. * messages multicasted with cpg_mcast_joined will be sent to every
  265. * group that has been joined on handle handle. Any message multicasted
  266. * to a group that has been previously joined will be delivered in cpg_dispatch
  267. *
  268. * @param handle
  269. * @param group
  270. * @return
  271. */
  272. cs_error_t cpg_join (
  273. cpg_handle_t handle,
  274. const struct cpg_name *group);
  275. /**
  276. * @brief Leave one or more groups
  277. * @param handle
  278. * @param group
  279. * @return
  280. */
  281. cs_error_t cpg_leave (
  282. cpg_handle_t handle,
  283. const struct cpg_name *group);
  284. /**
  285. * @brief Multicast to groups joined with cpg_join.
  286. *
  287. * @param handle
  288. * @param guarantee
  289. * @param iovec This iovec will be multicasted to all groups joined with
  290. * the cpg_join interface for handle.
  291. * @param iov_len
  292. */
  293. cs_error_t cpg_mcast_joined (
  294. cpg_handle_t handle,
  295. cpg_guarantee_t guarantee,
  296. const struct iovec *iovec,
  297. unsigned int iov_len);
  298. /**
  299. * @brief Get membership information from cpg
  300. * @param handle
  301. * @param groupName
  302. * @param member_list
  303. * @param member_list_entries
  304. * @return
  305. */
  306. cs_error_t cpg_membership_get (
  307. cpg_handle_t handle,
  308. struct cpg_name *groupName,
  309. struct cpg_address *member_list,
  310. int *member_list_entries);
  311. /**
  312. * @brief cpg_local_get
  313. * @param handle
  314. * @param local_nodeid
  315. * @return
  316. */
  317. cs_error_t cpg_local_get (
  318. cpg_handle_t handle,
  319. unsigned int *local_nodeid);
  320. /**
  321. * @brief cpg_flow_control_state_get
  322. * @param handle
  323. * @param flow_control_enabled
  324. * @return
  325. */
  326. cs_error_t cpg_flow_control_state_get (
  327. cpg_handle_t handle,
  328. cpg_flow_control_state_t *flow_control_enabled);
  329. /**
  330. * @brief cpg_zcb_alloc
  331. * @param handle
  332. * @param size
  333. * @param buffer
  334. * @return
  335. */
  336. cs_error_t cpg_zcb_alloc (
  337. cpg_handle_t handle,
  338. size_t size,
  339. void **buffer);
  340. /**
  341. * @brief cpg_zcb_free
  342. * @param handle
  343. * @param buffer
  344. * @return
  345. */
  346. cs_error_t cpg_zcb_free (
  347. cpg_handle_t handle,
  348. void *buffer);
  349. /**
  350. * @brief cpg_zcb_mcast_joined
  351. * @param handle
  352. * @param guarantee
  353. * @param msg
  354. * @param msg_len
  355. * @return
  356. */
  357. cs_error_t cpg_zcb_mcast_joined (
  358. cpg_handle_t handle,
  359. cpg_guarantee_t guarantee,
  360. void *msg,
  361. size_t msg_len);
  362. /**
  363. * @brief cpg_iteration_initialize
  364. * @param handle
  365. * @param iteration_type
  366. * @param group
  367. * @param cpg_iteration_handle
  368. * @return
  369. */
  370. cs_error_t cpg_iteration_initialize(
  371. cpg_handle_t handle,
  372. cpg_iteration_type_t iteration_type,
  373. const struct cpg_name *group,
  374. cpg_iteration_handle_t *cpg_iteration_handle);
  375. /**
  376. * @brief cpg_iteration_next
  377. * @param handle
  378. * @param description
  379. * @return
  380. */
  381. cs_error_t cpg_iteration_next(
  382. cpg_iteration_handle_t handle,
  383. struct cpg_iteration_description_t *description);
  384. /**
  385. * @brief cpg_iteration_finalize
  386. * @param handle
  387. * @return
  388. */
  389. cs_error_t cpg_iteration_finalize (
  390. cpg_iteration_handle_t handle);
  391. #ifdef __cplusplus
  392. }
  393. #endif
  394. #endif /* COROSYNC_CPG_H_DEFINED */