cpg.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (c) 2006 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Patrick Caulfield (pcaulfi@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef OPENAIS_CPG_H_DEFINED
  35. #define OPENAIS_CPG_H_DEFINED
  36. #include <netinet/in.h>
  37. typedef uint64_t cpg_handle_t;
  38. typedef enum {
  39. CPG_DISPATCH_ONE,
  40. CPG_DISPATCH_ALL,
  41. CPG_DISPATCH_BLOCKING
  42. } cpg_dispatch_t;
  43. typedef enum {
  44. CPG_TYPE_UNORDERED, /* not implemented */
  45. CPG_TYPE_FIFO, /* same as agreed */
  46. CPG_TYPE_AGREED,
  47. CPG_TYPE_SAFE /* not implemented */
  48. } cpg_guarantee_t;
  49. typedef enum {
  50. CPG_OK = 1,
  51. CPG_ERR_LIBRARY = 2,
  52. CPG_ERR_TIMEOUT = 5,
  53. CPG_ERR_TRY_AGAIN = 6,
  54. CPG_ERR_INVALID_PARAM = 7,
  55. CPG_ERR_NO_MEMORY = 8,
  56. CPG_ERR_BAD_HANDLE = 9,
  57. CPG_ERR_ACCESS = 11,
  58. CPG_ERR_NOT_EXIST = 12,
  59. CPG_ERR_EXIST = 14,
  60. CPG_ERR_NOT_SUPPORTED = 20,
  61. CPG_ERR_SECURITY = 29,
  62. CPG_ERR_TOO_MANY_GROUPS=30
  63. } cpg_error_t;
  64. typedef enum {
  65. CPG_REASON_JOIN = 1,
  66. CPG_REASON_LEAVE = 2,
  67. CPG_REASON_NODEDOWN = 3,
  68. CPG_REASON_NODEUP = 4,
  69. CPG_REASON_PROCDOWN = 5
  70. } cpg_reason_t;
  71. struct cpg_address {
  72. uint32_t nodeId;
  73. uint32_t pid;
  74. uint32_t reason;
  75. };
  76. #ifndef CPG_MAX_NAME_LENGTH
  77. #define CPG_MAX_NAME_LENGTH 128
  78. struct cpg_name {
  79. uint32_t length;
  80. char value[CPG_MAX_NAME_LENGTH];
  81. };
  82. #endif
  83. typedef void (*cpg_deliver_fn_t) (
  84. cpg_handle_t handle,
  85. struct cpg_name *group_name,
  86. uint32_t nodeid,
  87. uint32_t pid,
  88. void *msg,
  89. int msg_len);
  90. typedef void (*cpg_confchg_fn_t) (
  91. cpg_handle_t handle,
  92. struct cpg_name *group_name,
  93. struct cpg_address *member_list, int member_list_entries,
  94. struct cpg_address *left_list, int left_list_entries,
  95. struct cpg_address *joined_list, int joined_list_entries);
  96. typedef struct {
  97. cpg_deliver_fn_t cpg_deliver_fn;
  98. cpg_confchg_fn_t cpg_confchg_fn;
  99. } cpg_callbacks_t;
  100. /*
  101. * Create a new cpg connection
  102. */
  103. cpg_error_t cpg_initialize (
  104. cpg_handle_t *handle,
  105. cpg_callbacks_t *callbacks);
  106. /*
  107. * Close the cpg handle
  108. */
  109. cpg_error_t cpg_finalize (
  110. cpg_handle_t handle);
  111. /*
  112. * Get a file descriptor on which to poll. cpg_handle_t is NOT a
  113. * file descriptor and may not be used directly.
  114. */
  115. cpg_error_t cpg_fd_get (
  116. cpg_handle_t handle,
  117. int *fd);
  118. /*
  119. * Dispatch messages and configuration changes
  120. */
  121. cpg_error_t cpg_dispatch (
  122. cpg_handle_t handle,
  123. cpg_dispatch_t dispatch_types);
  124. /*
  125. * Join one or more groups.
  126. * messages multicasted with cpg_mcast_joined will be sent to every
  127. * group that has been joined on handle handle. Any message multicasted
  128. * to a group that has been previously joined will be delivered in cpg_dispatch
  129. */
  130. cpg_error_t cpg_join (
  131. cpg_handle_t handle,
  132. struct cpg_name *group);
  133. /*
  134. * Leave one or more groups
  135. */
  136. cpg_error_t cpg_leave (
  137. cpg_handle_t handle,
  138. struct cpg_name *group);
  139. /*
  140. * Multicast to groups joined with cpg_join.
  141. * The iovec described by iovec will be multicasted to all groups joined with
  142. * the cpg_join interface for handle.
  143. */
  144. cpg_error_t cpg_mcast_joined (
  145. cpg_handle_t handle,
  146. cpg_guarantee_t guarantee,
  147. struct iovec *iovec,
  148. int iov_len);
  149. /*
  150. * Get membership information from cpg
  151. */
  152. cpg_error_t cpg_membership_get (
  153. cpg_handle_t handle,
  154. struct cpg_name *groupName,
  155. struct cpg_address *member_list,
  156. int *member_list_entries);
  157. #endif /* OPENAIS_CPG_H_DEFINED */