totemknet.c 36 KB

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