apidef.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright (c) 2008, 2009 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@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. #include <config.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <corosync/corotypes.h>
  38. #include <corosync/lcr/lcr_ifact.h>
  39. #include <corosync/totem/totempg.h>
  40. #include <corosync/totem/totemip.h>
  41. #include <corosync/totem/totem.h>
  42. #include <corosync/engine/logsys.h>
  43. #include <qb/qbipcs.h>
  44. #include "util.h"
  45. #include "timer.h"
  46. #include "sync.h"
  47. #include "quorum.h"
  48. #include "schedwrk.h"
  49. #include "main.h"
  50. #include "apidef.h"
  51. #include <corosync/engine/coroapi.h>
  52. #include "service.h"
  53. LOGSYS_DECLARE_SUBSYS ("APIDEF");
  54. /*
  55. * Remove compile warnings about type name changes in corosync_tpg_group
  56. */
  57. typedef int (*typedef_tpg_join) (
  58. hdb_handle_t,
  59. const struct corosync_tpg_group *,
  60. size_t);
  61. typedef int (*typedef_tpg_leave) (hdb_handle_t,
  62. const struct corosync_tpg_group *,
  63. size_t);
  64. typedef int (*typedef_tpg_groups_mcast_groups) (
  65. hdb_handle_t, int,
  66. const struct corosync_tpg_group *,
  67. size_t groups_cnt,
  68. const struct iovec *,
  69. unsigned int);
  70. typedef int (*typedef_tpg_groups_send_ok) (
  71. hdb_handle_t,
  72. const struct corosync_tpg_group *,
  73. size_t groups_cnt,
  74. struct iovec *,
  75. int);
  76. static inline void _corosync_public_exit_error (cs_fatal_error_t err,
  77. const char *file,
  78. unsigned int line)
  79. __attribute__((noreturn));
  80. static inline void _corosync_public_exit_error (
  81. cs_fatal_error_t err, const char *file, unsigned int line)
  82. {
  83. _corosync_exit_error (err, file, line);
  84. }
  85. static struct corosync_api_v1 apidef_corosync_api_v1 = {
  86. .timer_add_duration = corosync_timer_add_duration,
  87. .timer_add_absolute = corosync_timer_add_absolute,
  88. .timer_delete = corosync_timer_delete,
  89. .timer_time_get = corosync_timer_time_get,
  90. .timer_expire_time_get = corosync_timer_expire_time_get,
  91. .ipc_source_set = message_source_set,
  92. .ipc_source_is_local = message_source_is_local,
  93. .ipc_private_data_get = cs_ipcs_private_data_get,
  94. .ipc_response_iov_send = cs_ipcs_response_iov_send,
  95. .ipc_response_send = cs_ipcs_response_send,
  96. .ipc_dispatch_send = cs_ipcs_dispatch_send,
  97. .ipc_dispatch_iov_send = cs_ipcs_dispatch_iov_send,
  98. .ipc_refcnt_inc = cs_ipc_refcnt_inc,
  99. .ipc_refcnt_dec = cs_ipc_refcnt_dec,
  100. .totem_nodeid_get = totempg_my_nodeid_get,
  101. .totem_family_get = totempg_my_family_get,
  102. .totem_ring_reenable = totempg_ring_reenable,
  103. .totem_mcast = main_mcast,
  104. .totem_ifaces_get = totempg_ifaces_get,
  105. .totem_ifaces_print = totempg_ifaces_print,
  106. .totem_ip_print = totemip_print,
  107. .totem_crypto_set = totempg_crypto_set,
  108. .totem_callback_token_create = totempg_callback_token_create,
  109. .totem_get_stats = totempg_get_stats,
  110. .tpg_init = totempg_groups_initialize,
  111. .tpg_exit = NULL, /* missing from totempg api */
  112. .tpg_join = (typedef_tpg_join)totempg_groups_join,
  113. .tpg_leave = (typedef_tpg_leave)totempg_groups_leave,
  114. .tpg_joined_mcast = totempg_groups_mcast_joined,
  115. .tpg_joined_reserve = totempg_groups_joined_reserve,
  116. .tpg_joined_release = totempg_groups_joined_release,
  117. .tpg_groups_mcast = (typedef_tpg_groups_mcast_groups)totempg_groups_mcast_groups,
  118. .tpg_groups_reserve = NULL,
  119. .tpg_groups_release = NULL,
  120. .schedwrk_create = schedwrk_create,
  121. .schedwrk_create_nolock = schedwrk_create_nolock,
  122. .schedwrk_destroy = schedwrk_destroy,
  123. .sync_request = NULL, //sync_request,
  124. .quorum_is_quorate = corosync_quorum_is_quorate,
  125. .quorum_register_callback = corosync_quorum_register_callback,
  126. .quorum_unregister_callback = corosync_quorum_unregister_callback,
  127. .quorum_initialize = corosync_quorum_initialize,
  128. .service_link_and_init = corosync_service_link_and_init,
  129. .service_unlink_and_exit = corosync_service_unlink_and_exit,
  130. .plugin_interface_reference = lcr_ifact_reference,
  131. .plugin_interface_release = lcr_ifact_release,
  132. .error_memory_failure = _corosync_out_of_memory_error,
  133. .fatal_error = _corosync_public_exit_error,
  134. .shutdown_request = corosync_shutdown_request,
  135. .state_dump = corosync_state_dump,
  136. .poll_handle_get = cs_poll_handle_get,
  137. .poll_dispatch_add = cs_poll_dispatch_add,
  138. .poll_dispatch_delete = cs_poll_dispatch_delete
  139. };
  140. void apidef_init (struct objdb_iface_ver0 *objdb) {
  141. apidef_corosync_api_v1.object_create = objdb->object_create;
  142. apidef_corosync_api_v1.object_priv_set = objdb->object_priv_set;
  143. apidef_corosync_api_v1.object_key_create = objdb->object_key_create;
  144. apidef_corosync_api_v1.object_destroy = objdb->object_destroy;
  145. apidef_corosync_api_v1.object_valid_set = objdb->object_valid_set;
  146. apidef_corosync_api_v1.object_key_valid_set = objdb->object_key_valid_set;
  147. apidef_corosync_api_v1.object_find_create = objdb->object_find_create;
  148. apidef_corosync_api_v1.object_find_next = objdb->object_find_next;
  149. apidef_corosync_api_v1.object_find_destroy = objdb->object_find_destroy;
  150. apidef_corosync_api_v1.object_key_get = objdb->object_key_get;
  151. apidef_corosync_api_v1.object_priv_get = objdb->object_priv_get;
  152. apidef_corosync_api_v1.object_key_replace = objdb->object_key_replace;
  153. apidef_corosync_api_v1.object_key_delete = objdb->object_key_delete;
  154. apidef_corosync_api_v1.object_iter_reset = objdb->object_iter_reset;
  155. apidef_corosync_api_v1.object_iter = objdb->object_iter;
  156. apidef_corosync_api_v1.object_key_iter = objdb->object_key_iter;
  157. apidef_corosync_api_v1.object_parent_get = objdb->object_parent_get;
  158. apidef_corosync_api_v1.object_name_get = objdb->object_name_get;
  159. apidef_corosync_api_v1.object_dump = objdb->object_dump;
  160. apidef_corosync_api_v1.object_key_iter_from = objdb->object_key_iter_from;
  161. apidef_corosync_api_v1.object_track_start = objdb->object_track_start;
  162. apidef_corosync_api_v1.object_track_stop = objdb->object_track_stop;
  163. apidef_corosync_api_v1.object_write_config = objdb->object_write_config;
  164. apidef_corosync_api_v1.object_reload_config = objdb->object_reload_config;
  165. apidef_corosync_api_v1.object_key_increment = objdb->object_key_increment;
  166. apidef_corosync_api_v1.object_key_decrement = objdb->object_key_decrement;
  167. apidef_corosync_api_v1.object_key_create_typed = objdb->object_key_create_typed;
  168. apidef_corosync_api_v1.object_key_get_typed = objdb->object_key_get_typed;
  169. apidef_corosync_api_v1.object_key_iter_typed = objdb->object_key_iter_typed;
  170. }
  171. struct corosync_api_v1 *apidef_get (void)
  172. {
  173. return (&apidef_corosync_api_v1);
  174. }