cpg.h 9.3 KB

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