corosync  2.4.2-dirty
totemmrp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 MontaVista Software, Inc.
3  * Copyright (c) 2006-2007, 2009 Red Hat, Inc.
4  *
5  * All rights reserved.
6  *
7  * Author: Steven Dake (sdake@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 
36 #include <config.h>
37 
38 #include <sys/mman.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #include <sys/socket.h>
42 #include <netdb.h>
43 #include <sys/un.h>
44 #include <sys/ioctl.h>
45 #include <sys/param.h>
46 #include <netinet/in.h>
47 #include <arpa/inet.h>
48 #include <unistd.h>
49 #include <fcntl.h>
50 #include <stdlib.h>
51 #include <stdio.h>
52 #include <errno.h>
53 #include <sched.h>
54 #include <time.h>
55 #include <sys/time.h>
56 #include <sys/poll.h>
57 
58 #include <corosync/totem/totem.h>
59 #include <qb/qbloop.h>
60 
61 #include "totemmrp.h"
62 #include "totemsrp.h"
63 
65 
67  unsigned int nodeid,
68  const void *msg,
69  unsigned int msg_len,
70  int endian_conversion_required);
71 
73  enum totem_configuration_type configuration_type,
74  const unsigned int *member_list, size_t member_list_entries,
75  const unsigned int *left_list, size_t left_list_entries,
76  const unsigned int *joined_list, size_t joined_list_entries,
77  const struct memb_ring_id *ring_id);
78 
79 void (*pg_deliver_fn) (
80  unsigned int nodeid,
81  const void *msg,
82  unsigned int msg_len,
83  int endian_conversion_required) = 0;
84 
85 void (*pg_confchg_fn) (
86  enum totem_configuration_type configuration_type,
87  const unsigned int *member_list, size_t member_list_entries,
88  const unsigned int *left_list, size_t left_list_entries,
89  const unsigned int *joined_list, size_t joined_list_entries,
90  const struct memb_ring_id *ring_id) = 0;
91 
93  unsigned int nodeid,
94  const void *msg,
95  unsigned int msg_len,
96  int endian_conversion_required)
97 {
98  pg_deliver_fn (nodeid, msg, msg_len, endian_conversion_required);
99 }
100 
102  enum totem_configuration_type configuration_type,
103  const unsigned int *member_list, size_t member_list_entries,
104  const unsigned int *left_list, size_t left_list_entries,
105  const unsigned int *joined_list, size_t joined_list_entries,
106  const struct memb_ring_id *ring_id)
107 {
108  pg_confchg_fn (configuration_type,
109  member_list, member_list_entries,
110  left_list, left_list_entries,
111  joined_list, joined_list_entries,
112  ring_id);
113 }
114 
115 /*
116  * Initialize the totem multiple ring protocol
117  */
119  qb_loop_t *poll_handle,
120  struct totem_config *totem_config,
121  totempg_stats_t *stats,
122 
123  void (*deliver_fn) (
124  unsigned int nodeid,
125  const void *msg,
126  unsigned int msg_len,
127  int endian_conversion_required),
128  void (*confchg_fn) (
129  enum totem_configuration_type configuration_type,
130  const unsigned int *member_list, size_t member_list_entries,
131  const unsigned int *left_list, size_t left_list_entries,
132  const unsigned int *joined_list, size_t joined_list_entries,
133  const struct memb_ring_id *ring_id),
134  void (*waiting_trans_ack_cb_fn) (
135  int waiting_trans_ack))
136 {
137  int result;
138  pg_deliver_fn = deliver_fn;
139  pg_confchg_fn = confchg_fn;
140 
141  stats->mrp = calloc (sizeof(totemmrp_stats_t), 1);
142  result = totemsrp_initialize (
143  poll_handle,
145  totem_config,
146  stats->mrp,
149  waiting_trans_ack_cb_fn);
150 
151  return (result);
152 }
153 
154 void totemmrp_finalize (void)
155 {
157 }
158 
159 /*
160  * Multicast a message
161  */
163  struct iovec *iovec,
164  unsigned int iov_len,
165  int priority)
166 {
167  return totemsrp_mcast (totemsrp_context, iovec, iov_len, priority);
168 }
169 
170 /*
171  * Return number of available messages that can be queued
172  */
173 int totemmrp_avail (void)
174 {
175  return (totemsrp_avail (totemsrp_context));
176 }
177 
179  void **handle_out,
181  int delete,
182  int (*callback_fn) (enum totem_callback_token_type type, const void *),
183  const void *data)
184 {
185  return totemsrp_callback_token_create (totemsrp_context, handle_out, type, delete, callback_fn, data);
186 }
187 
189  void *handle_out)
190 {
192 }
193 
195 {
197 }
198 
200  unsigned int nodeid,
201  struct totem_ip_address *interfaces,
202  unsigned int interfaces_size,
203  char ***status,
204  unsigned int *iface_count)
205 {
206  int res;
207 
208  res = totemsrp_ifaces_get (
210  nodeid,
211  interfaces,
212  interfaces_size,
213  status,
214  iface_count);
215 
216  return (res);
217 }
218 
220  const char *cipher_type,
221  const char *hash_type)
222 {
224  cipher_type,
225  hash_type);
226 }
227 
228 unsigned int totemmrp_my_nodeid_get (void)
229 {
231 }
232 
234 {
236 }
237 
238 extern int totemmrp_ring_reenable (void)
239 {
240  int res;
241 
242  res = totemsrp_ring_reenable (
244 
245  return (res);
246 }
247 
249  void (*totem_service_ready) (void))
250 {
253  totem_service_ready);
254 }
255 
257  const struct totem_ip_address *member,
258  int ring_no)
259 {
260  int res;
261 
262  res = totemsrp_member_add (totemsrp_context, member, ring_no);
263 
264  return (res);
265 }
266 
268  const struct totem_ip_address *member,
269  int ring_no)
270 {
271  int res;
272 
273  res = totemsrp_member_remove (totemsrp_context, member, ring_no);
274 
275  return (res);
276 }
277 
279 {
281 }
282 
284 {
286 }
int totemmrp_ifaces_get(unsigned int nodeid, struct totem_ip_address *interfaces, unsigned int interfaces_size, char ***status, unsigned int *iface_count)
Definition: totemmrp.c:199
void totemmrp_finalize(void)
Definition: totemmrp.c:154
Totem Single Ring Protocol.
uint32_t value
int totemsrp_my_family_get(void *srp_context)
Definition: totemsrp.c:1145
void totemmrp_callback_token_destroy(void *handle_out)
Definition: totemmrp.c:188
The totem_ip_address struct.
Definition: coroapi.h:111
void(* pg_confchg_fn)(enum totem_configuration_type configuration_type, const unsigned int *member_list, size_t member_list_entries, const unsigned int *left_list, size_t left_list_entries, const unsigned int *joined_list, size_t joined_list_entries, const struct memb_ring_id *ring_id)=0
Definition: totemmrp.c:85
int totemsrp_member_add(void *context, const struct totem_ip_address *member, int ring_no)
Definition: totemsrp.c:4810
totem_configuration_type
The totem_configuration_type enum.
Definition: coroapi.h:132
unsigned int totemsrp_my_nodeid_get(void *srp_context)
Definition: totemsrp.c:1134
int totemmrp_initialize(qb_loop_t *poll_handle, struct totem_config *totem_config, totempg_stats_t *stats, void(*deliver_fn)(unsigned int nodeid, const void *msg, unsigned int msg_len, int endian_conversion_required), void(*confchg_fn)(enum totem_configuration_type configuration_type, const unsigned int *member_list, size_t member_list_entries, const unsigned int *left_list, size_t left_list_entries, const unsigned int *joined_list, size_t joined_list_entries, const struct memb_ring_id *ring_id), void(*waiting_trans_ack_cb_fn)(int waiting_trans_ack))
Initialize the group messaging interface.
Definition: totemmrp.c:118
int totemsrp_crypto_set(void *srp_context, const char *cipher_type, const char *hash_type)
Definition: totemsrp.c:1120
int totemmrp_member_add(const struct totem_ip_address *member, int ring_no)
Definition: totemmrp.c:256
int totemmrp_avail(void)
Return number of available messages that can be queued.
Definition: totemmrp.c:173
int totemsrp_ifaces_get(void *srp_context, unsigned int nodeid, struct totem_ip_address *interfaces, unsigned int interfaces_size, char ***status, unsigned int *iface_count)
Definition: totemsrp.c:1062
int totemmrp_my_family_get(void)
Definition: totemmrp.c:233
void totemsrp_callback_token_destroy(void *srp_context, void **handle_out)
Definition: totemsrp.c:3490
int totemmrp_crypto_set(const char *cipher_type, const char *hash_type)
Definition: totemmrp.c:219
void totemmrp_trans_ack(void)
Definition: totemmrp.c:283
void totemmrp_deliver_fn(unsigned int nodeid, const void *msg, unsigned int msg_len, int endian_conversion_required)
Definition: totemmrp.c:92
int totemsrp_callback_token_create(void *srp_context, void **handle_out, enum totem_callback_token_type type, int delete, int(*callback_fn)(enum totem_callback_token_type type, const void *), const void *data)
Definition: totemsrp.c:3455
void totemsrp_service_ready_register(void *context, void(*totem_service_ready)(void))
Definition: totemsrp.c:4801
int totemsrp_mcast(void *srp_context, struct iovec *iovec, unsigned int iov_len, int guarantee)
Multicast a message.
Definition: totemsrp.c:2487
int totemmrp_member_remove(const struct totem_ip_address *member, int ring_no)
Definition: totemmrp.c:267
int totemsrp_ring_reenable(void *srp_context)
Definition: totemsrp.c:1157
int totemmrp_mcast(struct iovec *iovec, unsigned int iov_len, int priority)
Multicast a message.
Definition: totemmrp.c:162
int totemmrp_callback_token_create(void **handle_out, enum totem_callback_token_type type, int delete, int(*callback_fn)(enum totem_callback_token_type type, const void *), const void *data)
Definition: totemmrp.c:178
int totemmrp_ring_reenable(void)
Definition: totemmrp.c:238
int totemsrp_avail(void *srp_context)
Return number of available messages that can be queued.
Definition: totemsrp.c:2556
totemmrp_stats_t * mrp
Definition: totem.h:288
totem_event_type
Definition: totem.h:212
unsigned int totemmrp_my_nodeid_get(void)
Definition: totemmrp.c:228
void totemsrp_threaded_mode_enable(void *context)
Definition: totemsrp.c:4836
int totemsrp_initialize(qb_loop_t *poll_handle, void **srp_context, struct totem_config *totem_config, totemmrp_stats_t *stats, void(*deliver_fn)(unsigned int nodeid, const void *msg, unsigned int msg_len, int endian_conversion_required), void(*confchg_fn)(enum totem_configuration_type configuration_type, const unsigned int *member_list, size_t member_list_entries, const unsigned int *left_list, size_t left_list_entries, const unsigned int *joined_list, size_t joined_list_entries, const struct memb_ring_id *ring_id), void(*waiting_trans_ack_cb_fn)(int waiting_trans_ack))
Create a protocol instance.
Definition: totemsrp.c:832
void totemsrp_event_signal(void *srp_context, enum totem_event_type type, int value)
Definition: totemsrp.c:2478
void totemmrp_service_ready_register(void(*totem_service_ready)(void))
Definition: totemmrp.c:248
void totemmrp_confchg_fn(enum totem_configuration_type configuration_type, const unsigned int *member_list, size_t member_list_entries, const unsigned int *left_list, size_t left_list_entries, const unsigned int *joined_list, size_t joined_list_entries, const struct memb_ring_id *ring_id)
Definition: totemmrp.c:101
The memb_ring_id struct.
Definition: coroapi.h:122
void totemsrp_finalize(void *srp_context)
Definition: totemsrp.c:1038
void totemmrp_threaded_mode_enable(void)
Definition: totemmrp.c:278
void * totemsrp_context
Definition: totemmrp.c:64
void totemsrp_trans_ack(void *context)
Definition: totemsrp.c:4843
void totemmrp_event_signal(enum totem_event_type type, int value)
Definition: totemmrp.c:194
char type
Definition: totemrrp.c:518
int totemsrp_member_remove(void *context, const struct totem_ip_address *member, int ring_no)
Definition: totemsrp.c:4823
void(* pg_deliver_fn)(unsigned int nodeid, const void *msg, unsigned int msg_len, int endian_conversion_required)=0
Definition: totemmrp.c:79
unsigned int nodeid
Definition: coroapi.h:75
struct memb_ring_id ring_id
Definition: totemsrp.c:64
Totem Single Ring Protocol.
totem_callback_token_type
The totem_callback_token_type enum.
Definition: coroapi.h:142