totemknet.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. /*
  2. * Copyright (c) 2016 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfie@redhat.com)
  7. * This software licensed under BSD license, the text of which follows:
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * - Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * - Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  31. * THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include <config.h>
  34. #include <assert.h>
  35. #include <sys/mman.h>
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #include <sys/socket.h>
  39. #include <netdb.h>
  40. #include <sys/un.h>
  41. #include <sys/ioctl.h>
  42. #include <sys/param.h>
  43. #include <netinet/in.h>
  44. #include <arpa/inet.h>
  45. #include <unistd.h>
  46. #include <fcntl.h>
  47. #include <stdlib.h>
  48. #include <stdio.h>
  49. #include <errno.h>
  50. #include <sched.h>
  51. #include <time.h>
  52. #include <sys/time.h>
  53. #include <sys/poll.h>
  54. #include <sys/uio.h>
  55. #include <limits.h>
  56. #include <qb/qbdefs.h>
  57. #include <qb/qbloop.h>
  58. #include <corosync/sq.h>
  59. #include <corosync/swab.h>
  60. #include <corosync/logsys.h>
  61. #include <corosync/icmap.h>
  62. #include <corosync/totem/totemip.h>
  63. #include "totemknet.h"
  64. #include "util.h"
  65. #include <nss.h>
  66. #include <pk11pub.h>
  67. #include <pkcs11.h>
  68. #include <prerror.h>
  69. #include <libknet.h>
  70. #ifndef MSG_NOSIGNAL
  71. #define MSG_NOSIGNAL 0
  72. #endif
  73. /* Should match that used by cfg */
  74. #define CFG_INTERFACE_STATUS_MAX_LEN 512
  75. struct totemknet_instance {
  76. struct crypto_instance *crypto_inst;
  77. qb_loop_t *poll_handle;
  78. knet_handle_t knet_handle;
  79. int link_mode;
  80. void *context;
  81. void (*totemknet_deliver_fn) (
  82. void *context,
  83. const void *msg,
  84. unsigned int msg_len);
  85. void (*totemknet_iface_change_fn) (
  86. void *context,
  87. const struct totem_ip_address *iface_address,
  88. unsigned int link_no);
  89. void (*totemknet_mtu_changed) (
  90. void *context,
  91. int net_mtu);
  92. void (*totemknet_target_set_completed) (void *context);
  93. /*
  94. * Function and data used to log messages
  95. */
  96. int totemknet_log_level_security;
  97. int totemknet_log_level_error;
  98. int totemknet_log_level_warning;
  99. int totemknet_log_level_notice;
  100. int totemknet_log_level_debug;
  101. int totemknet_subsys_id;
  102. int knet_subsys_id;
  103. void (*totemknet_log_printf) (
  104. int level,
  105. int subsys,
  106. const char *function,
  107. const char *file,
  108. int line,
  109. const char *format,
  110. ...)__attribute__((format(printf, 6, 7)));
  111. void *knet_context;
  112. char iov_buffer[KNET_MAX_PACKET_SIZE];
  113. int stats_sent;
  114. int stats_recv;
  115. int stats_delv;
  116. int stats_remcasts;
  117. int stats_orf_token;
  118. struct timeval stats_tv_start;
  119. char *link_status[INTERFACE_MAX];
  120. int num_links;
  121. struct totem_ip_address my_ids[INTERFACE_MAX];
  122. uint16_t ip_port[INTERFACE_MAX];
  123. int our_nodeid;
  124. struct totem_config *totem_config;
  125. totemsrp_stats_t *stats;
  126. struct totem_ip_address token_target;
  127. qb_loop_timer_handle timer_netif_check_timeout;
  128. qb_loop_timer_handle timer_merge_detect_timeout;
  129. int send_merge_detect_message;
  130. unsigned int merge_detect_messages_sent_before_timeout;
  131. int logpipes[2];
  132. int knet_fd;
  133. };
  134. struct work_item {
  135. const void *msg;
  136. unsigned int msg_len;
  137. struct totemknet_instance *instance;
  138. };
  139. int totemknet_member_list_rebind_ip (
  140. void *knet_context);
  141. static void totemknet_start_merge_detect_timeout(
  142. void *knet_context);
  143. static void totemknet_stop_merge_detect_timeout(
  144. void *knet_context);
  145. static void totemknet_instance_initialize (struct totemknet_instance *instance)
  146. {
  147. memset (instance, 0, sizeof (struct totemknet_instance));
  148. }
  149. #define knet_log_printf(level, format, args...) \
  150. do { \
  151. instance->totemknet_log_printf ( \
  152. level, instance->totemknet_subsys_id, \
  153. __FUNCTION__, __FILE__, __LINE__, \
  154. (const char *)format, ##args); \
  155. } while (0);
  156. #define libknet_log_printf(level, format, args...) \
  157. do { \
  158. instance->totemknet_log_printf ( \
  159. level, instance->knet_subsys_id, \
  160. __FUNCTION__, "libknet.h", __LINE__, \
  161. (const char *)format, ##args); \
  162. } while (0);
  163. #define KNET_LOGSYS_PERROR(err_num, level, fmt, args...) \
  164. do { \
  165. char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
  166. const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
  167. instance->totemknet_log_printf ( \
  168. level, instance->totemknet_subsys_id, \
  169. __FUNCTION__, __FILE__, __LINE__, \
  170. fmt ": %s (%d)", ##args, _error_ptr, err_num); \
  171. } while(0)
  172. static int dst_host_filter_callback_fn(void *private_data,
  173. const unsigned char *outdata,
  174. ssize_t outdata_len,
  175. uint8_t tx_rx,
  176. knet_node_id_t this_host_id,
  177. knet_node_id_t src_host_id,
  178. int8_t *channel,
  179. knet_node_id_t *dst_host_ids,
  180. size_t *dst_host_ids_entries)
  181. {
  182. struct totem_message_header *header = (struct totem_message_header *)outdata;
  183. int res;
  184. *channel = 0;
  185. if (header->target_nodeid) {
  186. dst_host_ids[0] = header->target_nodeid;
  187. *dst_host_ids_entries = 1;
  188. res = 0; /* unicast message */
  189. }
  190. else {
  191. *dst_host_ids_entries = 0;
  192. res = 1; /* multicast message */
  193. }
  194. return res;
  195. }
  196. static void socket_error_callback_fn(void *private_data, int datafd, int8_t channel, uint8_t tx_rx, int error, int errorno)
  197. {
  198. struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
  199. knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet socket ERROR notification called: txrx=%d, error=%d, errorno=%d", tx_rx, error, errorno);
  200. if ((error == -1 && errorno != EAGAIN) || (error == 0)) {
  201. knet_handle_remove_datafd(instance->knet_handle, datafd);
  202. }
  203. }
  204. static void host_change_callback_fn(void *private_data, knet_node_id_t host_id, uint8_t reachable, uint8_t remote, uint8_t external)
  205. {
  206. struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
  207. // TODO: what? if anything.
  208. knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet host change callback. nodeid: %d reachable: %d", host_id, reachable);
  209. }
  210. static void pmtu_change_callback_fn(void *private_data, unsigned int data_mtu)
  211. {
  212. struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
  213. knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet pMTU change: %d", data_mtu);
  214. /* We don't need to tell corosync the actual knet MTU */
  215. // instance->totemknet_mtu_changed(instance->context, data_mtu);
  216. }
  217. int totemknet_crypto_set (
  218. void *knet_context,
  219. const char *cipher_type,
  220. const char *hash_type)
  221. {
  222. return (0);
  223. }
  224. static inline void ucast_sendmsg (
  225. struct totemknet_instance *instance,
  226. struct totem_ip_address *system_to,
  227. const void *msg,
  228. unsigned int msg_len)
  229. {
  230. int res = 0;
  231. struct totem_message_header *header = (struct totem_message_header *)msg;
  232. struct msghdr msg_ucast;
  233. struct iovec iovec;
  234. header->target_nodeid = system_to->nodeid;
  235. iovec.iov_base = (void *)msg;
  236. iovec.iov_len = msg_len;
  237. /*
  238. * Build unicast message
  239. */
  240. memset(&msg_ucast, 0, sizeof(msg_ucast));
  241. msg_ucast.msg_iov = (void *)&iovec;
  242. msg_ucast.msg_iovlen = 1;
  243. #ifdef HAVE_MSGHDR_CONTROL
  244. msg_ucast.msg_control = 0;
  245. #endif
  246. #ifdef HAVE_MSGHDR_CONTROLLEN
  247. msg_ucast.msg_controllen = 0;
  248. #endif
  249. #ifdef HAVE_MSGHDR_FLAGS
  250. msg_ucast.msg_flags = 0;
  251. #endif
  252. #ifdef HAVE_MSGHDR_ACCRIGHTS
  253. msg_ucast.msg_accrights = NULL;
  254. #endif
  255. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  256. msg_ucast.msg_accrightslen = 0;
  257. #endif
  258. /*
  259. * Transmit unicast message
  260. * An error here is recovered by totemsrp
  261. */
  262. /*
  263. * If sending to ourself then just pass it through knet back to
  264. * the receive fn. knet does not do local->local delivery
  265. */
  266. if (system_to->nodeid == instance->our_nodeid) {
  267. res = sendmsg (instance->knet_fd+1, &msg_ucast, MSG_NOSIGNAL);
  268. if (res < 0) {
  269. KNET_LOGSYS_PERROR (errno, instance->totemknet_log_level_debug,
  270. "sendmsg(ucast-local) failed (non-critical)");
  271. }
  272. }
  273. else {
  274. res = sendmsg (instance->knet_fd, &msg_ucast, MSG_NOSIGNAL);
  275. if (res < 0) {
  276. KNET_LOGSYS_PERROR (errno, instance->totemknet_log_level_debug,
  277. "sendmsg(ucast) failed (non-critical)");
  278. }
  279. }
  280. }
  281. static inline void mcast_sendmsg (
  282. struct totemknet_instance *instance,
  283. const void *msg,
  284. unsigned int msg_len,
  285. int only_active)
  286. {
  287. int res;
  288. struct totem_message_header *header = (struct totem_message_header *)msg;
  289. struct msghdr msg_mcast;
  290. struct iovec iovec;
  291. iovec.iov_base = (void *)msg;
  292. iovec.iov_len = msg_len;
  293. header->target_nodeid = 0;
  294. /*
  295. * Build multicast message
  296. */
  297. memset(&msg_mcast, 0, sizeof(msg_mcast));
  298. msg_mcast.msg_iov = (void *)&iovec;
  299. msg_mcast.msg_iovlen = 1;
  300. #ifdef HAVE_MSGHDR_CONTROL
  301. msg_mcast.msg_control = 0;
  302. #endif
  303. #ifdef HAVE_MSGHDR_CONTROLLEN
  304. msg_mcast.msg_controllen = 0;
  305. #endif
  306. #ifdef HAVE_MSGHDR_FLAGS
  307. msg_mcast.msg_flags = 0;
  308. #endif
  309. #ifdef HAVE_MSGHDR_ACCRIGHTS
  310. msg_mcast.msg_accrights = NULL;
  311. #endif
  312. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  313. msg_mcast.msg_accrightslen = 0;
  314. #endif
  315. // log_printf (LOGSYS_LEVEL_DEBUG, "totemknet: mcast_sendmsg. only_active=%d, len=%d", only_active, msg_len);
  316. res = sendmsg (instance->knet_fd, &msg_mcast, MSG_NOSIGNAL);
  317. if (res < msg_len) {
  318. knet_log_printf (LOGSYS_LEVEL_DEBUG, "totemknet: mcast_send sendmsg returned %d", res);
  319. }
  320. /*
  321. * Also send it to ourself, directly into
  322. * the receive fn. knet does not to local->local delivery
  323. */
  324. res = sendmsg (instance->knet_fd+1, &msg_mcast, MSG_NOSIGNAL);
  325. if (res < msg_len) {
  326. knet_log_printf (LOGSYS_LEVEL_DEBUG, "totemknet: mcast_send sendmsg (local) returned %d", res);
  327. }
  328. if (!only_active || instance->send_merge_detect_message) {
  329. /*
  330. * Current message was sent to all nodes
  331. */
  332. instance->merge_detect_messages_sent_before_timeout++;
  333. instance->send_merge_detect_message = 0;
  334. }
  335. }
  336. static int node_compare(const void *aptr, const void *bptr)
  337. {
  338. uint16_t a,b;
  339. a = *(uint16_t *)aptr;
  340. b = *(uint16_t *)bptr;
  341. return a > b;
  342. }
  343. int totemknet_ifaces_get (void *knet_context,
  344. char ***status,
  345. unsigned int *iface_count)
  346. {
  347. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  348. struct knet_link_status link_status;
  349. knet_node_id_t host_list[KNET_MAX_HOST];
  350. size_t num_hosts;
  351. int i,j;
  352. char *ptr;
  353. int res = 0;
  354. /*
  355. * Don't do the whole 'link_info' bit if the caller just wants
  356. * a count of interfaces.
  357. */
  358. if (status) {
  359. res = knet_host_get_host_list(instance->knet_handle,
  360. host_list, &num_hosts);
  361. if (res) {
  362. return (-1);
  363. }
  364. qsort(host_list, num_hosts, sizeof(uint16_t), node_compare);
  365. /* num_links is actually the highest link ID */
  366. for (i=0; i <= instance->num_links; i++) {
  367. ptr = instance->link_status[i];
  368. for (j=0; j<num_hosts; j++) {
  369. res = knet_link_get_status(instance->knet_handle,
  370. host_list[j],
  371. i,
  372. &link_status);
  373. if (res == 0) {
  374. ptr[j] = '0' + (link_status.enabled |
  375. link_status.connected<<1 |
  376. link_status.dynconnected<<2);
  377. }
  378. else {
  379. ptr[j] += '?';
  380. }
  381. }
  382. ptr[num_hosts] = '\0';
  383. }
  384. *status = instance->link_status;
  385. }
  386. *iface_count = instance->num_links+1;
  387. return (res);
  388. }
  389. int totemknet_finalize (
  390. void *knet_context)
  391. {
  392. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  393. int res = 0;
  394. int i,j;
  395. static knet_node_id_t nodes[KNET_MAX_HOST]; /* static to save stack */
  396. uint8_t links[KNET_MAX_LINK];
  397. size_t num_nodes;
  398. size_t num_links;
  399. knet_log_printf(LOG_DEBUG, "totemknet: finalize");
  400. qb_loop_poll_del (instance->poll_handle, instance->logpipes[0]);
  401. qb_loop_poll_del (instance->poll_handle, instance->knet_fd);
  402. res = knet_host_get_host_list(instance->knet_handle, nodes, &num_nodes);
  403. if (res) {
  404. knet_log_printf (LOGSYS_LEVEL_ERROR, "Cannot get knet node list for shutdown: %s", strerror(errno));
  405. /* Crash out anyway */
  406. goto finalise_error;
  407. }
  408. /* Tidily shut down all nodes & links. This ensures that the LEAVE message will be sent */
  409. for (i=0; i<num_nodes; i++) {
  410. /* Don't try to shut local link down, there isn't one */
  411. if (nodes[i] == instance->our_nodeid) {
  412. continue;
  413. }
  414. res = knet_link_get_link_list(instance->knet_handle, nodes[i], links, &num_links);
  415. if (res) {
  416. knet_log_printf (LOGSYS_LEVEL_ERROR, "Cannot get knet link list for node %d: %s", nodes[i], strerror(errno));
  417. goto finalise_error;
  418. }
  419. for (j=0; j<num_links; j++) {
  420. res = knet_link_set_enable(instance->knet_handle, nodes[i], links[j], 0);
  421. if (res) {
  422. knet_log_printf (LOGSYS_LEVEL_ERROR, "totemknet: knet_link_set_enable(node %d, link %d) failed: %s", nodes[i], links[j], strerror(errno));
  423. }
  424. res = knet_link_clear_config(instance->knet_handle, nodes[i], links[j]);
  425. if (res) {
  426. knet_log_printf (LOGSYS_LEVEL_ERROR, "totemknet: knet_link_clear_config(node %d, link %d) failed: %s", nodes[i], links[j], strerror(errno));
  427. }
  428. }
  429. res = knet_host_remove(instance->knet_handle, nodes[i]);
  430. if (res) {
  431. knet_log_printf (LOGSYS_LEVEL_ERROR, "totemknet: knet_host_remove(node %d) failed: %s", nodes[i], strerror(errno));
  432. }
  433. }
  434. finalise_error:
  435. res = knet_handle_setfwd(instance->knet_handle, 0);
  436. if (res) {
  437. knet_log_printf (LOGSYS_LEVEL_CRIT, "totemknet: knet_handle_setfwd failed: %s", strerror(errno));
  438. }
  439. res = knet_handle_free(instance->knet_handle);
  440. if (res) {
  441. knet_log_printf (LOGSYS_LEVEL_CRIT, "totemknet: knet_handle_free failed: %s", strerror(errno));
  442. }
  443. totemknet_stop_merge_detect_timeout(instance);
  444. return (res);
  445. }
  446. static int log_deliver_fn (
  447. int fd,
  448. int revents,
  449. void *data)
  450. {
  451. struct totemknet_instance *instance = (struct totemknet_instance *)data;
  452. char buffer[KNET_MAX_LOG_MSG_SIZE*4];
  453. char *bufptr = buffer;
  454. int done = 0;
  455. int len;
  456. len = read(fd, buffer, sizeof(buffer));
  457. while (done < len) {
  458. struct knet_log_msg *msg = (struct knet_log_msg *)bufptr;
  459. switch (msg->msglevel) {
  460. case KNET_LOG_ERR:
  461. libknet_log_printf (LOGSYS_LEVEL_ERROR, "%s: %s",
  462. knet_log_get_subsystem_name(msg->subsystem),
  463. msg->msg);
  464. break;
  465. case KNET_LOG_WARN:
  466. libknet_log_printf (LOGSYS_LEVEL_WARNING, "%s: %s",
  467. knet_log_get_subsystem_name(msg->subsystem),
  468. msg->msg);
  469. break;
  470. case KNET_LOG_INFO:
  471. libknet_log_printf (LOGSYS_LEVEL_INFO, "%s: %s",
  472. knet_log_get_subsystem_name(msg->subsystem),
  473. msg->msg);
  474. break;
  475. case KNET_LOG_DEBUG:
  476. libknet_log_printf (LOGSYS_LEVEL_DEBUG, "%s: %s",
  477. knet_log_get_subsystem_name(msg->subsystem),
  478. msg->msg);
  479. break;
  480. }
  481. bufptr += KNET_MAX_LOG_MSG_SIZE;
  482. done += KNET_MAX_LOG_MSG_SIZE;
  483. }
  484. return 0;
  485. }
  486. static int data_deliver_fn (
  487. int fd,
  488. int revents,
  489. void *data)
  490. {
  491. struct totemknet_instance *instance = (struct totemknet_instance *)data;
  492. struct msghdr msg_hdr;
  493. struct iovec iov_recv;
  494. struct sockaddr_storage system_from;
  495. ssize_t msg_len;
  496. iov_recv.iov_base = instance->iov_buffer;
  497. iov_recv.iov_len = KNET_MAX_PACKET_SIZE;
  498. msg_hdr.msg_name = &system_from;
  499. msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
  500. msg_hdr.msg_iov = &iov_recv;
  501. msg_hdr.msg_iovlen = 1;
  502. #ifdef HAVE_MSGHDR_CONTROL
  503. msg_hdr.msg_control = 0;
  504. #endif
  505. #ifdef HAVE_MSGHDR_CONTROLLEN
  506. msg_hdr.msg_controllen = 0;
  507. #endif
  508. #ifdef HAVE_MSGHDR_FLAGS
  509. msg_hdr.msg_flags = 0;
  510. #endif
  511. #ifdef HAVE_MSGHDR_ACCRIGHTS
  512. msg_hdr.msg_accrights = NULL;
  513. #endif
  514. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  515. msg_hdr.msg_accrightslen = 0;
  516. #endif
  517. msg_len = recvmsg (fd, &msg_hdr, MSG_NOSIGNAL | MSG_DONTWAIT);
  518. if (msg_len <= 0) {
  519. return (0);
  520. }
  521. instance->stats_recv += msg_len;
  522. /*
  523. * Handle incoming message
  524. */
  525. instance->totemknet_deliver_fn (
  526. instance->context,
  527. instance->iov_buffer,
  528. msg_len);
  529. return (0);
  530. }
  531. static void timer_function_netif_check_timeout (
  532. void *data)
  533. {
  534. struct totemknet_instance *instance = (struct totemknet_instance *)data;
  535. int i;
  536. for (i=0; i<instance->totem_config->interface_count; i++)
  537. instance->totemknet_iface_change_fn (instance->context,
  538. &instance->my_ids[i],
  539. i);
  540. }
  541. static void totemknet_refresh_config(
  542. int32_t event,
  543. const char *key_name,
  544. struct icmap_notify_value new_val,
  545. struct icmap_notify_value old_val,
  546. void *user_data)
  547. {
  548. uint8_t reloading;
  549. uint32_t value;
  550. uint32_t link_no;
  551. size_t num_nodes;
  552. knet_node_id_t host_ids[KNET_MAX_HOST];
  553. int i;
  554. int err;
  555. char path[ICMAP_KEYNAME_MAXLEN];
  556. struct totemknet_instance *instance = (struct totemknet_instance *)user_data;
  557. ENTER();
  558. /*
  559. * If a full reload is in progress then don't do anything until it's done and
  560. * can reconfigure it all atomically
  561. */
  562. if (icmap_get_uint8("config.totemconfig_reload_in_progress", &reloading) == CS_OK && reloading) {
  563. return;
  564. }
  565. if (icmap_get_uint32("totem.knet_pmtud_interval", &value) == CS_OK) {
  566. instance->totem_config->knet_pmtud_interval = value;
  567. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_pmtud_interval now %d", value);
  568. err = knet_handle_pmtud_setfreq(instance->knet_handle, instance->totem_config->knet_pmtud_interval);
  569. if (err) {
  570. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
  571. }
  572. }
  573. /* Get link parameters */
  574. for (i = 0; i <= instance->num_links; i++) {
  575. sprintf(path, "totem.interface.%d.knet_link_priority", i);
  576. if (icmap_get_uint32(path, &value) == CS_OK) {
  577. instance->totem_config->interfaces[i].knet_link_priority = value;
  578. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_link_priority on link %d now %d", i, value);
  579. }
  580. sprintf(path, "totem.interface.%d.knet_ping_interval", i);
  581. if (icmap_get_uint32(path, &value) == CS_OK) {
  582. instance->totem_config->interfaces[i].knet_ping_interval = value;
  583. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_ping_interval on link %d now %d", i, value);
  584. }
  585. sprintf(path, "totem.interface.%d.knet_ping_timeout", i);
  586. if (icmap_get_uint32(path, &value) == CS_OK) {
  587. instance->totem_config->interfaces[i].knet_ping_timeout = value;
  588. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_ping_timeout on link %d now %d", i, value);
  589. }
  590. sprintf(path, "totem.interface.%d.knet_ping_precision", i);
  591. if (icmap_get_uint32(path, &value) == CS_OK) {
  592. instance->totem_config->interfaces[i].knet_ping_precision = value;
  593. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_ping_precision on link %d now %d", i, value);
  594. }
  595. sprintf(path, "totem.interface.%d.knet_pong_count", i);
  596. if (icmap_get_uint32(path, &value) == CS_OK) {
  597. instance->totem_config->interfaces[i].knet_pong_count = value;
  598. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_pong_count on link %d now %d", i, value);
  599. }
  600. }
  601. /* Configure link parameters for each node */
  602. err = knet_host_get_host_list(instance->knet_handle, host_ids, &num_nodes);
  603. if (err != 0) {
  604. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_get_host_list failed");
  605. }
  606. for (i=0; i<num_nodes; i++) {
  607. for (link_no = 0; link_no < instance->num_links; link_no++) {
  608. err = knet_link_set_ping_timers(instance->knet_handle, host_ids[i], link_no,
  609. instance->totem_config->interfaces[link_no].knet_ping_interval,
  610. instance->totem_config->interfaces[link_no].knet_ping_timeout,
  611. instance->totem_config->interfaces[link_no].knet_ping_precision);
  612. if (err) {
  613. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_ping_timers for node %d link %d failed", host_ids[i], link_no);
  614. }
  615. err = knet_link_set_pong_count(instance->knet_handle, host_ids[i], link_no,
  616. instance->totem_config->interfaces[link_no].knet_pong_count);
  617. if (err) {
  618. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_pong_count for node %d link %d failed",host_ids[i], link_no);
  619. }
  620. err = knet_link_set_priority(instance->knet_handle, host_ids[i], link_no,
  621. instance->totem_config->interfaces[link_no].knet_link_priority);
  622. if (err) {
  623. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_priority for node %d link %d failed", host_ids[i], link_no);
  624. }
  625. }
  626. }
  627. LEAVE();
  628. }
  629. static void totemknet_add_config_notifications(struct totemknet_instance *instance)
  630. {
  631. icmap_track_t icmap_track_totem = NULL;
  632. icmap_track_t icmap_track_reload = NULL;
  633. ENTER();
  634. icmap_track_add("totem.",
  635. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  636. totemknet_refresh_config,
  637. instance,
  638. &icmap_track_totem);
  639. icmap_track_add("config.totemconfig_reload_in_progress",
  640. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  641. totemknet_refresh_config,
  642. instance,
  643. &icmap_track_reload);
  644. LEAVE();
  645. }
  646. /*
  647. * Create an instance
  648. */
  649. int totemknet_initialize (
  650. qb_loop_t *poll_handle,
  651. void **knet_context,
  652. struct totem_config *totem_config,
  653. totemsrp_stats_t *stats,
  654. void *context,
  655. void (*deliver_fn) (
  656. void *context,
  657. const void *msg,
  658. unsigned int msg_len),
  659. void (*iface_change_fn) (
  660. void *context,
  661. const struct totem_ip_address *iface_address,
  662. unsigned int link_no),
  663. void (*mtu_changed) (
  664. void *context,
  665. int net_mtu),
  666. void (*target_set_completed) (
  667. void *context))
  668. {
  669. struct totemknet_instance *instance;
  670. int8_t channel=0;
  671. int res;
  672. int i;
  673. instance = malloc (sizeof (struct totemknet_instance));
  674. if (instance == NULL) {
  675. return (-1);
  676. }
  677. totemknet_instance_initialize (instance);
  678. instance->totem_config = totem_config;
  679. instance->stats = stats;
  680. /*
  681. * Configure logging
  682. */
  683. instance->totemknet_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
  684. instance->totemknet_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  685. instance->totemknet_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  686. instance->totemknet_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  687. instance->totemknet_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  688. instance->totemknet_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
  689. instance->totemknet_log_printf = totem_config->totem_logging_configuration.log_printf;
  690. instance->knet_subsys_id = _logsys_subsys_create("KNET", "libknet.h");
  691. /*
  692. * Initialize local variables for totemknet
  693. */
  694. instance->our_nodeid = instance->totem_config->node_id;
  695. for (i=0; i< instance->totem_config->interface_count; i++) {
  696. totemip_copy(&instance->my_ids[i], &totem_config->interfaces[i].bindnet);
  697. instance->my_ids[i].nodeid = instance->our_nodeid;
  698. instance->ip_port[i] = totem_config->interfaces[i].ip_port;
  699. /* Needed for totemsrp */
  700. totem_config->interfaces[i].boundto.nodeid = instance->our_nodeid;
  701. }
  702. instance->poll_handle = poll_handle;
  703. instance->context = context;
  704. instance->totemknet_deliver_fn = deliver_fn;
  705. instance->totemknet_iface_change_fn = iface_change_fn;
  706. instance->totemknet_mtu_changed = mtu_changed;
  707. instance->totemknet_target_set_completed = target_set_completed;
  708. res = pipe(instance->logpipes);
  709. if (res == -1) {
  710. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "failed to create pipe for instance->logpipes");
  711. return -1;
  712. }
  713. fcntl(instance->logpipes[0], F_SETFL, O_NONBLOCK);
  714. fcntl(instance->logpipes[1], F_SETFL, O_NONBLOCK);
  715. instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG);
  716. if (!instance->knet_handle) {
  717. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "knet_handle_new failed");
  718. return (-1);
  719. }
  720. res = knet_handle_pmtud_setfreq(instance->knet_handle, instance->totem_config->knet_pmtud_interval);
  721. if (res) {
  722. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
  723. }
  724. res = knet_handle_enable_filter(instance->knet_handle, instance, dst_host_filter_callback_fn);
  725. if (res) {
  726. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_filter failed");
  727. }
  728. res = knet_handle_enable_sock_notify(instance->knet_handle, instance, socket_error_callback_fn);
  729. if (res) {
  730. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_sock_notify failed");
  731. }
  732. res = knet_host_enable_status_change_notify(instance->knet_handle, instance, host_change_callback_fn);
  733. if (res) {
  734. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_host_enable_status_change_notify failed");
  735. }
  736. res = knet_handle_enable_pmtud_notify(instance->knet_handle, instance, pmtu_change_callback_fn);
  737. if (res) {
  738. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_pmtud_notify failed");
  739. }
  740. /* Get an fd into knet */
  741. instance->knet_fd = 0;
  742. res = knet_handle_add_datafd(instance->knet_handle, &instance->knet_fd, &channel);
  743. if (res) {
  744. knet_log_printf(LOG_DEBUG, "knet_handle_add_datafd failed: %s", strerror(errno));
  745. return -1;
  746. }
  747. /* Enable crypto if requested */
  748. if (strcmp(instance->totem_config->crypto_cipher_type, "none") != 0) {
  749. struct knet_handle_crypto_cfg crypto_cfg;
  750. strcpy(crypto_cfg.crypto_model, "nss");
  751. strcpy(crypto_cfg.crypto_cipher_type, instance->totem_config->crypto_cipher_type);
  752. strcpy(crypto_cfg.crypto_hash_type, instance->totem_config->crypto_hash_type);
  753. memcpy(crypto_cfg.private_key, instance->totem_config->private_key, instance->totem_config->private_key_len);
  754. crypto_cfg.private_key_len = instance->totem_config->private_key_len;
  755. res = knet_handle_crypto(instance->knet_handle, &crypto_cfg);
  756. if (res == -1) {
  757. knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto failed: %s", strerror(errno));
  758. return -1;
  759. }
  760. if (res == -2) {
  761. knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto failed: -2");
  762. return -1;
  763. }
  764. knet_log_printf(LOG_INFO, "kronosnet crypto initialized: %s/%s", crypto_cfg.crypto_cipher_type, crypto_cfg.crypto_hash_type);
  765. }
  766. knet_handle_setfwd(instance->knet_handle, 1);
  767. instance->link_mode = KNET_LINK_POLICY_PASSIVE;
  768. if (strcmp(instance->totem_config->link_mode, "active")==0) {
  769. instance->link_mode = KNET_LINK_POLICY_ACTIVE;
  770. }
  771. if (strcmp(instance->totem_config->link_mode, "rr")==0) {
  772. instance->link_mode = KNET_LINK_POLICY_RR;
  773. }
  774. for (i=0; i<INTERFACE_MAX; i++) {
  775. instance->link_status[i] = malloc(CFG_INTERFACE_STATUS_MAX_LEN);
  776. if (!instance->link_status[i]) {
  777. return -1;
  778. }
  779. }
  780. qb_loop_poll_add (instance->poll_handle,
  781. QB_LOOP_MED,
  782. instance->logpipes[0],
  783. POLLIN, instance, log_deliver_fn);
  784. qb_loop_poll_add (instance->poll_handle,
  785. QB_LOOP_HIGH,
  786. instance->knet_fd,
  787. POLLIN, instance, data_deliver_fn);
  788. /*
  789. * Upper layer isn't ready to receive message because it hasn't
  790. * initialized yet. Add short timer to check the interfaces.
  791. */
  792. qb_loop_timer_add (instance->poll_handle,
  793. QB_LOOP_MED,
  794. 100*QB_TIME_NS_IN_MSEC,
  795. (void *)instance,
  796. timer_function_netif_check_timeout,
  797. &instance->timer_netif_check_timeout);
  798. totemknet_start_merge_detect_timeout(instance);
  799. /* Start listening for config changes */
  800. totemknet_add_config_notifications(instance);
  801. knet_log_printf (LOGSYS_LEVEL_INFO, "totemknet initialized");
  802. *knet_context = instance;
  803. return (0);
  804. }
  805. void *totemknet_buffer_alloc (void)
  806. {
  807. return malloc(KNET_MAX_PACKET_SIZE);
  808. }
  809. void totemknet_buffer_release (void *ptr)
  810. {
  811. return free (ptr);
  812. }
  813. int totemknet_processor_count_set (
  814. void *knet_context,
  815. int processor_count)
  816. {
  817. return (0);
  818. }
  819. int totemknet_recv_flush (void *knet_context)
  820. {
  821. return (0);
  822. }
  823. int totemknet_send_flush (void *knet_context)
  824. {
  825. return (0);
  826. }
  827. int totemknet_token_send (
  828. void *knet_context,
  829. const void *msg,
  830. unsigned int msg_len)
  831. {
  832. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  833. int res = 0;
  834. ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
  835. return (res);
  836. }
  837. int totemknet_mcast_flush_send (
  838. void *knet_context,
  839. const void *msg,
  840. unsigned int msg_len)
  841. {
  842. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  843. int res = 0;
  844. mcast_sendmsg (instance, msg, msg_len, 0);
  845. return (res);
  846. }
  847. int totemknet_mcast_noflush_send (
  848. void *knet_context,
  849. const void *msg,
  850. unsigned int msg_len)
  851. {
  852. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  853. int res = 0;
  854. mcast_sendmsg (instance, msg, msg_len, 1);
  855. return (res);
  856. }
  857. extern int totemknet_iface_check (void *knet_context)
  858. {
  859. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  860. int res = 0;
  861. knet_log_printf(LOG_DEBUG, "totmeknet: iface_check");
  862. return (res);
  863. }
  864. extern void totemknet_net_mtu_adjust (void *knet_context, struct totem_config *totem_config)
  865. {
  866. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  867. knet_log_printf(LOG_DEBUG, "totemknet: Returning MTU of %d", totem_config->net_mtu);
  868. }
  869. int totemknet_token_target_set (
  870. void *knet_context,
  871. const struct totem_ip_address *token_target)
  872. {
  873. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  874. int res = 0;
  875. memcpy (&instance->token_target, token_target,
  876. sizeof (struct totem_ip_address));
  877. instance->totemknet_target_set_completed (instance->context);
  878. return (res);
  879. }
  880. extern int totemknet_recv_mcast_empty (
  881. void *knet_context)
  882. {
  883. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  884. unsigned int res;
  885. struct sockaddr_storage system_from;
  886. struct msghdr msg_hdr;
  887. struct iovec iov_recv;
  888. struct pollfd ufd;
  889. int nfds;
  890. int msg_processed = 0;
  891. iov_recv.iov_base = instance->iov_buffer;
  892. iov_recv.iov_len = KNET_MAX_PACKET_SIZE;
  893. msg_hdr.msg_name = &system_from;
  894. msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
  895. msg_hdr.msg_iov = &iov_recv;
  896. msg_hdr.msg_iovlen = 1;
  897. #ifdef HAVE_MSGHDR_CONTROL
  898. msg_hdr.msg_control = 0;
  899. #endif
  900. #ifdef HAVE_MSGHDR_CONTROLLEN
  901. msg_hdr.msg_controllen = 0;
  902. #endif
  903. #ifdef HAVE_MSGHDR_FLAGS
  904. msg_hdr.msg_flags = 0;
  905. #endif
  906. #ifdef HAVE_MSGHDR_ACCRIGHTS
  907. msg_msg_hdr.msg_accrights = NULL;
  908. #endif
  909. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  910. msg_msg_hdr.msg_accrightslen = 0;
  911. #endif
  912. do {
  913. ufd.fd = instance->knet_fd;
  914. ufd.events = POLLIN;
  915. nfds = poll (&ufd, 1, 0);
  916. if (nfds == 1 && ufd.revents & POLLIN) {
  917. res = recvmsg (instance->knet_fd, &msg_hdr, MSG_NOSIGNAL | MSG_DONTWAIT);
  918. if (res != -1) {
  919. msg_processed = 1;
  920. } else {
  921. msg_processed = -1;
  922. }
  923. }
  924. } while (nfds == 1);
  925. return (msg_processed);
  926. }
  927. int totemknet_member_add (
  928. void *knet_context,
  929. const struct totem_ip_address *local,
  930. const struct totem_ip_address *member,
  931. int link_no)
  932. {
  933. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  934. int err;
  935. int port = instance->ip_port[link_no];
  936. struct sockaddr_storage remote_ss;
  937. struct sockaddr_storage local_ss;
  938. int addrlen;
  939. if (member->nodeid == instance->our_nodeid) {
  940. return 0; /* Don't add ourself, we send loopback messages directly */
  941. }
  942. /* Keep track of the number of links */
  943. if (link_no > instance->num_links) {
  944. instance->num_links = link_no;
  945. }
  946. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: %d (%s), link=%d", member->nodeid, totemip_print(member), link_no);
  947. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: local: %d (%s)", local->nodeid, totemip_print(local));
  948. if (link_no == 0) {
  949. if (knet_host_add(instance->knet_handle, member->nodeid)) {
  950. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_add");
  951. return -1;
  952. }
  953. if (knet_host_set_policy(instance->knet_handle, member->nodeid, instance->link_mode)) {
  954. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_set_policy failed");
  955. return -1;
  956. }
  957. }
  958. /* Casts to remove const */
  959. totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)member, port+link_no, &remote_ss, &addrlen);
  960. totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)local, port+link_no, &local_ss, &addrlen);
  961. err = knet_link_set_config(instance->knet_handle, member->nodeid, link_no,
  962. instance->totem_config->interfaces[link_no].knet_transport,
  963. &local_ss, &remote_ss);
  964. if (err) {
  965. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_config failed");
  966. return -1;
  967. }
  968. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: Setting link prio to %d",
  969. instance->totem_config->interfaces[link_no].knet_link_priority);
  970. err = knet_link_set_priority(instance->knet_handle, member->nodeid, link_no,
  971. instance->totem_config->interfaces[link_no].knet_link_priority);
  972. if (err) {
  973. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_priority for nodeid %d, link %d failed", member->nodeid, link_no);
  974. }
  975. err = knet_link_set_ping_timers(instance->knet_handle, member->nodeid, link_no,
  976. instance->totem_config->interfaces[link_no].knet_ping_interval,
  977. instance->totem_config->interfaces[link_no].knet_ping_timeout,
  978. instance->totem_config->interfaces[link_no].knet_ping_precision);
  979. if (err) {
  980. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_ping_timers for nodeid %d, link %d failed", member->nodeid, link_no);
  981. }
  982. err = knet_link_set_pong_count(instance->knet_handle, member->nodeid, link_no,
  983. instance->totem_config->interfaces[link_no].knet_pong_count);
  984. if (err) {
  985. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_pong_count for nodeid %d, link %d failed", member->nodeid, link_no);
  986. }
  987. err = knet_link_set_enable(instance->knet_handle, member->nodeid, link_no, 1);
  988. if (err) {
  989. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_enable for nodeid %d, link %d failed", member->nodeid, link_no);
  990. return -1;
  991. }
  992. return (0);
  993. }
  994. int totemknet_member_remove (
  995. void *knet_context,
  996. const struct totem_ip_address *token_target,
  997. int link_no)
  998. {
  999. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  1000. int res;
  1001. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_remove: %d, link=%d", token_target->nodeid, link_no);
  1002. if (token_target->nodeid == instance->our_nodeid) {
  1003. return 0; /* Don't remove ourself */
  1004. }
  1005. /* Remove the link first */
  1006. res = knet_link_set_enable(instance->knet_handle, token_target->nodeid, link_no, 0);
  1007. if (res != 0) {
  1008. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set enable(off) for nodeid %d, link %d failed", token_target->nodeid, link_no);
  1009. return res;
  1010. }
  1011. res = knet_link_clear_config(instance->knet_handle, token_target->nodeid, link_no);
  1012. if (res != 0) {
  1013. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_clear_config for nodeid %d, link %d failed", token_target->nodeid, link_no);
  1014. return res;
  1015. }
  1016. return knet_host_remove(instance->knet_handle, token_target->nodeid);
  1017. }
  1018. int totemknet_member_list_rebind_ip (
  1019. void *knet_context)
  1020. {
  1021. return (0);
  1022. }
  1023. static void timer_function_merge_detect_timeout (
  1024. void *data)
  1025. {
  1026. struct totemknet_instance *instance = (struct totemknet_instance *)data;
  1027. if (instance->merge_detect_messages_sent_before_timeout == 0) {
  1028. instance->send_merge_detect_message = 1;
  1029. }
  1030. instance->merge_detect_messages_sent_before_timeout = 0;
  1031. totemknet_start_merge_detect_timeout(instance);
  1032. }
  1033. static void totemknet_start_merge_detect_timeout(
  1034. void *knet_context)
  1035. {
  1036. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  1037. qb_loop_timer_add(instance->poll_handle,
  1038. QB_LOOP_MED,
  1039. instance->totem_config->merge_timeout * 2 * QB_TIME_NS_IN_MSEC,
  1040. (void *)instance,
  1041. timer_function_merge_detect_timeout,
  1042. &instance->timer_merge_detect_timeout);
  1043. }
  1044. static void totemknet_stop_merge_detect_timeout(
  1045. void *knet_context)
  1046. {
  1047. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  1048. qb_loop_timer_del(instance->poll_handle,
  1049. instance->timer_merge_detect_timeout);
  1050. }