totemknet.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  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. pipe(instance->logpipes);
  709. fcntl(instance->logpipes[0], F_SETFL, O_NONBLOCK);
  710. fcntl(instance->logpipes[1], F_SETFL, O_NONBLOCK);
  711. instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG);
  712. if (!instance->knet_handle) {
  713. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "knet_handle_new failed");
  714. return (-1);
  715. }
  716. res = knet_handle_pmtud_setfreq(instance->knet_handle, instance->totem_config->knet_pmtud_interval);
  717. if (res) {
  718. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
  719. }
  720. res = knet_handle_enable_filter(instance->knet_handle, instance, dst_host_filter_callback_fn);
  721. if (res) {
  722. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_filter failed");
  723. }
  724. res = knet_handle_enable_sock_notify(instance->knet_handle, instance, socket_error_callback_fn);
  725. if (res) {
  726. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_sock_notify failed");
  727. }
  728. res = knet_host_enable_status_change_notify(instance->knet_handle, instance, host_change_callback_fn);
  729. if (res) {
  730. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_host_enable_status_change_notify failed");
  731. }
  732. res = knet_handle_enable_pmtud_notify(instance->knet_handle, instance, pmtu_change_callback_fn);
  733. if (res) {
  734. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_pmtud_notify failed");
  735. }
  736. /* Get an fd into knet */
  737. instance->knet_fd = 0;
  738. res = knet_handle_add_datafd(instance->knet_handle, &instance->knet_fd, &channel);
  739. if (res) {
  740. knet_log_printf(LOG_DEBUG, "knet_handle_add_datafd failed: %s", strerror(errno));
  741. return -1;
  742. }
  743. /* Enable crypto if requested */
  744. if (strcmp(instance->totem_config->crypto_cipher_type, "none") != 0) {
  745. struct knet_handle_crypto_cfg crypto_cfg;
  746. strcpy(crypto_cfg.crypto_model, "nss");
  747. strcpy(crypto_cfg.crypto_cipher_type, instance->totem_config->crypto_cipher_type);
  748. strcpy(crypto_cfg.crypto_hash_type, instance->totem_config->crypto_hash_type);
  749. memcpy(crypto_cfg.private_key, instance->totem_config->private_key, instance->totem_config->private_key_len);
  750. crypto_cfg.private_key_len = instance->totem_config->private_key_len;
  751. res = knet_handle_crypto(instance->knet_handle, &crypto_cfg);
  752. if (res == -1) {
  753. knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto failed: %s", strerror(errno));
  754. return -1;
  755. }
  756. if (res == -2) {
  757. knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto failed: -2");
  758. return -1;
  759. }
  760. knet_log_printf(LOG_INFO, "kronosnet crypto initialized: %s/%s", crypto_cfg.crypto_cipher_type, crypto_cfg.crypto_hash_type);
  761. }
  762. knet_handle_setfwd(instance->knet_handle, 1);
  763. instance->link_mode = KNET_LINK_POLICY_PASSIVE;
  764. if (strcmp(instance->totem_config->link_mode, "active")==0) {
  765. instance->link_mode = KNET_LINK_POLICY_ACTIVE;
  766. }
  767. if (strcmp(instance->totem_config->link_mode, "rr")==0) {
  768. instance->link_mode = KNET_LINK_POLICY_RR;
  769. }
  770. for (i=0; i<INTERFACE_MAX; i++) {
  771. instance->link_status[i] = malloc(CFG_INTERFACE_STATUS_MAX_LEN);
  772. if (!instance->link_status[i]) {
  773. return -1;
  774. }
  775. }
  776. qb_loop_poll_add (instance->poll_handle,
  777. QB_LOOP_MED,
  778. instance->logpipes[0],
  779. POLLIN, instance, log_deliver_fn);
  780. qb_loop_poll_add (instance->poll_handle,
  781. QB_LOOP_HIGH,
  782. instance->knet_fd,
  783. POLLIN, instance, data_deliver_fn);
  784. /*
  785. * Upper layer isn't ready to receive message because it hasn't
  786. * initialized yet. Add short timer to check the interfaces.
  787. */
  788. qb_loop_timer_add (instance->poll_handle,
  789. QB_LOOP_MED,
  790. 100*QB_TIME_NS_IN_MSEC,
  791. (void *)instance,
  792. timer_function_netif_check_timeout,
  793. &instance->timer_netif_check_timeout);
  794. totemknet_start_merge_detect_timeout(instance);
  795. /* Start listening for config changes */
  796. totemknet_add_config_notifications(instance);
  797. knet_log_printf (LOGSYS_LEVEL_INFO, "totemknet initialized");
  798. *knet_context = instance;
  799. return (0);
  800. }
  801. void *totemknet_buffer_alloc (void)
  802. {
  803. return malloc(KNET_MAX_PACKET_SIZE);
  804. }
  805. void totemknet_buffer_release (void *ptr)
  806. {
  807. return free (ptr);
  808. }
  809. int totemknet_processor_count_set (
  810. void *knet_context,
  811. int processor_count)
  812. {
  813. return (0);
  814. }
  815. int totemknet_recv_flush (void *knet_context)
  816. {
  817. return (0);
  818. }
  819. int totemknet_send_flush (void *knet_context)
  820. {
  821. return (0);
  822. }
  823. int totemknet_token_send (
  824. void *knet_context,
  825. const void *msg,
  826. unsigned int msg_len)
  827. {
  828. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  829. int res = 0;
  830. ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
  831. return (res);
  832. }
  833. int totemknet_mcast_flush_send (
  834. void *knet_context,
  835. const void *msg,
  836. unsigned int msg_len)
  837. {
  838. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  839. int res = 0;
  840. mcast_sendmsg (instance, msg, msg_len, 0);
  841. return (res);
  842. }
  843. int totemknet_mcast_noflush_send (
  844. void *knet_context,
  845. const void *msg,
  846. unsigned int msg_len)
  847. {
  848. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  849. int res = 0;
  850. mcast_sendmsg (instance, msg, msg_len, 1);
  851. return (res);
  852. }
  853. extern int totemknet_iface_check (void *knet_context)
  854. {
  855. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  856. int res = 0;
  857. knet_log_printf(LOG_DEBUG, "totmeknet: iface_check");
  858. return (res);
  859. }
  860. extern void totemknet_net_mtu_adjust (void *knet_context, struct totem_config *totem_config)
  861. {
  862. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  863. knet_log_printf(LOG_DEBUG, "totemknet: Returning MTU of %d", totem_config->net_mtu);
  864. }
  865. int totemknet_token_target_set (
  866. void *knet_context,
  867. const struct totem_ip_address *token_target)
  868. {
  869. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  870. int res = 0;
  871. memcpy (&instance->token_target, token_target,
  872. sizeof (struct totem_ip_address));
  873. instance->totemknet_target_set_completed (instance->context);
  874. return (res);
  875. }
  876. extern int totemknet_recv_mcast_empty (
  877. void *knet_context)
  878. {
  879. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  880. unsigned int res;
  881. struct sockaddr_storage system_from;
  882. struct msghdr msg_hdr;
  883. struct iovec iov_recv;
  884. struct pollfd ufd;
  885. int nfds;
  886. int msg_processed = 0;
  887. iov_recv.iov_base = instance->iov_buffer;
  888. iov_recv.iov_len = KNET_MAX_PACKET_SIZE;
  889. msg_hdr.msg_name = &system_from;
  890. msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
  891. msg_hdr.msg_iov = &iov_recv;
  892. msg_hdr.msg_iovlen = 1;
  893. #ifdef HAVE_MSGHDR_CONTROL
  894. msg_hdr.msg_control = 0;
  895. #endif
  896. #ifdef HAVE_MSGHDR_CONTROLLEN
  897. msg_hdr.msg_controllen = 0;
  898. #endif
  899. #ifdef HAVE_MSGHDR_FLAGS
  900. msg_hdr.msg_flags = 0;
  901. #endif
  902. #ifdef HAVE_MSGHDR_ACCRIGHTS
  903. msg_msg_hdr.msg_accrights = NULL;
  904. #endif
  905. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  906. msg_msg_hdr.msg_accrightslen = 0;
  907. #endif
  908. do {
  909. ufd.fd = instance->knet_fd;
  910. ufd.events = POLLIN;
  911. nfds = poll (&ufd, 1, 0);
  912. if (nfds == 1 && ufd.revents & POLLIN) {
  913. res = recvmsg (instance->knet_fd, &msg_hdr, MSG_NOSIGNAL | MSG_DONTWAIT);
  914. if (res != -1) {
  915. msg_processed = 1;
  916. } else {
  917. msg_processed = -1;
  918. }
  919. }
  920. } while (nfds == 1);
  921. return (msg_processed);
  922. }
  923. int totemknet_member_add (
  924. void *knet_context,
  925. const struct totem_ip_address *local,
  926. const struct totem_ip_address *member,
  927. int link_no)
  928. {
  929. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  930. int err;
  931. int port = instance->ip_port[link_no];
  932. struct sockaddr_storage remote_ss;
  933. struct sockaddr_storage local_ss;
  934. int addrlen;
  935. if (member->nodeid == instance->our_nodeid) {
  936. return 0; /* Don't add ourself, we send loopback messages directly */
  937. }
  938. /* Keep track of the number of links */
  939. if (link_no > instance->num_links) {
  940. instance->num_links = link_no;
  941. }
  942. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: %d (%s), link=%d", member->nodeid, totemip_print(member), link_no);
  943. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: local: %d (%s)", local->nodeid, totemip_print(local));
  944. if (link_no == 0) {
  945. if (knet_host_add(instance->knet_handle, member->nodeid)) {
  946. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_add");
  947. return -1;
  948. }
  949. if (knet_host_set_policy(instance->knet_handle, member->nodeid, instance->link_mode)) {
  950. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_set_policy failed");
  951. return -1;
  952. }
  953. }
  954. /* Casts to remove const */
  955. totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)member, port+link_no, &remote_ss, &addrlen);
  956. totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)local, port+link_no, &local_ss, &addrlen);
  957. err = knet_link_set_config(instance->knet_handle, member->nodeid, link_no,
  958. instance->totem_config->interfaces[link_no].knet_transport,
  959. &local_ss, &remote_ss);
  960. if (err) {
  961. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_config failed");
  962. return -1;
  963. }
  964. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: Setting link prio to %d",
  965. instance->totem_config->interfaces[link_no].knet_link_priority);
  966. err = knet_link_set_priority(instance->knet_handle, member->nodeid, link_no,
  967. instance->totem_config->interfaces[link_no].knet_link_priority);
  968. if (err) {
  969. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_priority for nodeid %d, link %d failed", member->nodeid, link_no);
  970. }
  971. err = knet_link_set_ping_timers(instance->knet_handle, member->nodeid, link_no,
  972. instance->totem_config->interfaces[link_no].knet_ping_interval,
  973. instance->totem_config->interfaces[link_no].knet_ping_timeout,
  974. instance->totem_config->interfaces[link_no].knet_ping_precision);
  975. if (err) {
  976. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_ping_timers for nodeid %d, link %d failed", member->nodeid, link_no);
  977. }
  978. err = knet_link_set_pong_count(instance->knet_handle, member->nodeid, link_no,
  979. instance->totem_config->interfaces[link_no].knet_pong_count);
  980. if (err) {
  981. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_pong_count for nodeid %d, link %d failed", member->nodeid, link_no);
  982. }
  983. err = knet_link_set_enable(instance->knet_handle, member->nodeid, link_no, 1);
  984. if (err) {
  985. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_enable for nodeid %d, link %d failed", member->nodeid, link_no);
  986. return -1;
  987. }
  988. return (0);
  989. }
  990. int totemknet_member_remove (
  991. void *knet_context,
  992. const struct totem_ip_address *token_target,
  993. int link_no)
  994. {
  995. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  996. int res;
  997. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_remove: %d, link=%d", token_target->nodeid, link_no);
  998. if (token_target->nodeid == instance->our_nodeid) {
  999. return 0; /* Don't remove ourself */
  1000. }
  1001. /* Remove the link first */
  1002. res = knet_link_set_enable(instance->knet_handle, token_target->nodeid, link_no, 0);
  1003. if (res != 0) {
  1004. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set enable(off) for nodeid %d, link %d failed", token_target->nodeid, link_no);
  1005. return res;
  1006. }
  1007. res = knet_link_clear_config(instance->knet_handle, token_target->nodeid, link_no);
  1008. if (res != 0) {
  1009. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_clear_config for nodeid %d, link %d failed", token_target->nodeid, link_no);
  1010. return res;
  1011. }
  1012. return knet_host_remove(instance->knet_handle, token_target->nodeid);
  1013. }
  1014. int totemknet_member_list_rebind_ip (
  1015. void *knet_context)
  1016. {
  1017. return (0);
  1018. }
  1019. static void timer_function_merge_detect_timeout (
  1020. void *data)
  1021. {
  1022. struct totemknet_instance *instance = (struct totemknet_instance *)data;
  1023. if (instance->merge_detect_messages_sent_before_timeout == 0) {
  1024. instance->send_merge_detect_message = 1;
  1025. }
  1026. instance->merge_detect_messages_sent_before_timeout = 0;
  1027. totemknet_start_merge_detect_timeout(instance);
  1028. }
  1029. static void totemknet_start_merge_detect_timeout(
  1030. void *knet_context)
  1031. {
  1032. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  1033. qb_loop_timer_add(instance->poll_handle,
  1034. QB_LOOP_MED,
  1035. instance->totem_config->merge_timeout * 2 * QB_TIME_NS_IN_MSEC,
  1036. (void *)instance,
  1037. timer_function_merge_detect_timeout,
  1038. &instance->timer_merge_detect_timeout);
  1039. }
  1040. static void totemknet_stop_merge_detect_timeout(
  1041. void *knet_context)
  1042. {
  1043. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  1044. qb_loop_timer_del(instance->poll_handle,
  1045. instance->timer_merge_detect_timeout);
  1046. }