ipc.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. /*
  2. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@mvista.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <pthread.h>
  36. #include <assert.h>
  37. #include <pwd.h>
  38. #include <grp.h>
  39. #include <sys/types.h>
  40. #include <sys/poll.h>
  41. #include <sys/uio.h>
  42. #include <sys/mman.h>
  43. #include <sys/socket.h>
  44. #include <sys/un.h>
  45. #include <sys/time.h>
  46. #include <sys/resource.h>
  47. #include <netinet/in.h>
  48. #include <arpa/inet.h>
  49. #include <unistd.h>
  50. #include <fcntl.h>
  51. #include <stdlib.h>
  52. #include <stdio.h>
  53. #include <errno.h>
  54. #include <signal.h>
  55. #include <sched.h>
  56. #include <time.h>
  57. #if defined(OPENAIS_SOLARIS) && defined(HAVE_GETPEERUCRED)
  58. #include <ucred.h>
  59. #endif
  60. #include "../include/saAis.h"
  61. #include "../include/list.h"
  62. #include "../include/queue.h"
  63. #include "../lcr/lcr_ifact.h"
  64. #include "poll.h"
  65. #include "totempg.h"
  66. #include "totemsrp.h"
  67. #include "mempool.h"
  68. #include "mainconfig.h"
  69. #include "totemconfig.h"
  70. #include "main.h"
  71. #include "ipc.h"
  72. #include "flow.h"
  73. #include "service.h"
  74. #include "sync.h"
  75. #include "swab.h"
  76. #include "objdb.h"
  77. #include "config.h"
  78. #include "tlist.h"
  79. #define LOG_SERVICE LOG_SERVICE_IPC
  80. #include "print.h"
  81. #include "util.h"
  82. #ifdef OPENAIS_SOLARIS
  83. #define MSG_NOSIGNAL 0
  84. #endif
  85. #define SERVER_BACKLOG 5
  86. /*
  87. * When there are this many entries left in a queue, turn on flow control
  88. */
  89. #define FLOW_CONTROL_ENTRIES_ENABLE 400
  90. /*
  91. * When there are this many entries in a queue, turn off flow control
  92. */
  93. #define FLOW_CONTROL_ENTRIES_DISABLE 64
  94. static unsigned int g_gid_valid = 0;
  95. static struct totem_ip_address *my_ip;
  96. static totempg_groups_handle ipc_handle;
  97. DECLARE_LIST_INIT (conn_info_list_head);
  98. static void (*ipc_serialize_lock_fn) (void);
  99. static void (*ipc_serialize_unlock_fn) (void);
  100. struct outq_item {
  101. void *msg;
  102. size_t mlen;
  103. };
  104. enum conn_state {
  105. CONN_STATE_ACTIVE,
  106. CONN_STATE_SECURITY,
  107. CONN_STATE_REQUESTED,
  108. CONN_STATE_CLOSED,
  109. CONN_STATE_DISCONNECTED
  110. };
  111. struct conn_info {
  112. int fd; /* File descriptor */
  113. unsigned int events; /* events polled for by file descriptor */
  114. enum conn_state state; /* State of this connection */
  115. pthread_t thread; /* thread identifier */
  116. pthread_attr_t thread_attr; /* thread attribute */
  117. char *inb; /* Input buffer for non-blocking reads */
  118. int inb_nextheader; /* Next message header starts here */
  119. int inb_start; /* Start location of input buffer */
  120. int inb_inuse; /* Bytes currently stored in input buffer */
  121. struct queue outq; /* Circular queue for outgoing requests */
  122. int byte_start; /* Byte to start sending from in head of queue */
  123. enum service_types service;/* Type of service so dispatch knows how to route message */
  124. int authenticated; /* Is this connection authenticated? */
  125. void *private_data; /* library connection private data */
  126. struct conn_info *conn_info_partner; /* partner connection dispatch<->response */
  127. unsigned int flow_control_handle; /* flow control identifier */
  128. unsigned int flow_control_enabled; /* flow control enabled bit */
  129. unsigned int flow_control_local_count; /* flow control local count */
  130. enum openais_flow_control flow_control; /* Does this service use IPC flow control */
  131. pthread_mutex_t flow_control_mutex;
  132. int (*lib_exit_fn) (void *conn);
  133. struct timerlist timerlist;
  134. pthread_mutex_t mutex;
  135. pthread_mutex_t *shared_mutex;
  136. struct list_head list;
  137. };
  138. static void *prioritized_poll_thread (void *conn);
  139. static int conn_info_outq_flush (struct conn_info *conn_info);
  140. static void libais_deliver (struct conn_info *conn_info);
  141. static void ipc_flow_control (struct conn_info *conn_info);
  142. /*
  143. * IPC Initializers
  144. */
  145. static int response_init_send_response (
  146. struct conn_info *conn_info,
  147. void *message);
  148. static int dispatch_init_send_response (
  149. struct conn_info *conn_info,
  150. void *message);
  151. static int (*ais_init_service[]) (struct conn_info *conn_info, void *message) = {
  152. response_init_send_response,
  153. dispatch_init_send_response
  154. };
  155. static void libais_disconnect_security (struct conn_info *conn_info)
  156. {
  157. conn_info->state = CONN_STATE_SECURITY;
  158. close (conn_info->fd);
  159. }
  160. static int response_init_send_response (
  161. struct conn_info *conn_info,
  162. void *message)
  163. {
  164. SaAisErrorT error = SA_AIS_ERR_ACCESS;
  165. uintptr_t cinfo = (uintptr_t)conn_info;
  166. mar_req_lib_response_init_t *req_lib_response_init = (mar_req_lib_response_init_t *)message;
  167. mar_res_lib_response_init_t res_lib_response_init;
  168. if (conn_info->authenticated) {
  169. conn_info->service = req_lib_response_init->resdis_header.service;
  170. error = SA_AIS_OK;
  171. }
  172. res_lib_response_init.header.size = sizeof (mar_res_lib_response_init_t);
  173. res_lib_response_init.header.id = MESSAGE_RES_INIT;
  174. res_lib_response_init.header.error = error;
  175. res_lib_response_init.conn_info = (mar_uint64_t)cinfo;
  176. openais_conn_send_response (
  177. conn_info,
  178. &res_lib_response_init,
  179. sizeof (res_lib_response_init));
  180. if (error == SA_AIS_ERR_ACCESS) {
  181. libais_disconnect_security (conn_info);
  182. return (-1);
  183. }
  184. return (0);
  185. }
  186. static int dispatch_init_send_response (
  187. struct conn_info *conn_info,
  188. void *message)
  189. {
  190. SaAisErrorT error = SA_AIS_ERR_ACCESS;
  191. uintptr_t cinfo;
  192. mar_req_lib_dispatch_init_t *req_lib_dispatch_init = (mar_req_lib_dispatch_init_t *)message;
  193. mar_res_lib_dispatch_init_t res_lib_dispatch_init;
  194. struct conn_info *msg_conn_info;
  195. if (conn_info->authenticated) {
  196. conn_info->service = req_lib_dispatch_init->resdis_header.service;
  197. if (!ais_service[req_lib_dispatch_init->resdis_header.service])
  198. error = SA_AIS_ERR_NOT_SUPPORTED;
  199. else
  200. error = SA_AIS_OK;
  201. cinfo = (uintptr_t)req_lib_dispatch_init->conn_info;
  202. conn_info->conn_info_partner = (struct conn_info *)cinfo;
  203. /* temporary fix for memory leak
  204. */
  205. pthread_mutex_destroy (conn_info->conn_info_partner->shared_mutex);
  206. free (conn_info->conn_info_partner->shared_mutex);
  207. conn_info->conn_info_partner->shared_mutex = conn_info->shared_mutex;
  208. list_add (&conn_info_list_head, &conn_info->list);
  209. list_add (&conn_info_list_head, &conn_info->conn_info_partner->list);
  210. msg_conn_info = (struct conn_info *)cinfo;
  211. msg_conn_info->conn_info_partner = conn_info;
  212. if (error == SA_AIS_OK) {
  213. int private_data_size;
  214. private_data_size = ais_service[req_lib_dispatch_init->resdis_header.service]->private_data_size;
  215. if (private_data_size) {
  216. conn_info->private_data = malloc (private_data_size);
  217. conn_info->conn_info_partner->private_data = conn_info->private_data;
  218. if (conn_info->private_data == NULL) {
  219. error = SA_AIS_ERR_NO_MEMORY;
  220. } else {
  221. memset (conn_info->private_data, 0, private_data_size);
  222. }
  223. } else {
  224. conn_info->private_data = NULL;
  225. conn_info->conn_info_partner->private_data = NULL;
  226. }
  227. }
  228. }
  229. res_lib_dispatch_init.header.size = sizeof (mar_res_lib_dispatch_init_t);
  230. res_lib_dispatch_init.header.id = MESSAGE_RES_INIT;
  231. res_lib_dispatch_init.header.error = error;
  232. openais_conn_send_response (
  233. conn_info,
  234. &res_lib_dispatch_init,
  235. sizeof (res_lib_dispatch_init));
  236. if (error == SA_AIS_ERR_ACCESS) {
  237. libais_disconnect_security (conn_info);
  238. return (-1);
  239. }
  240. if (error != SA_AIS_OK) {
  241. return (-1);
  242. }
  243. conn_info->state = CONN_STATE_ACTIVE;
  244. conn_info->conn_info_partner->state = CONN_STATE_ACTIVE;
  245. conn_info->lib_exit_fn = ais_service[conn_info->service]->lib_exit_fn;
  246. ais_service[conn_info->service]->lib_init_fn (conn_info);
  247. conn_info->flow_control = ais_service[conn_info->service]->flow_control;
  248. conn_info->conn_info_partner->flow_control = ais_service[conn_info->service]->flow_control;
  249. if (ais_service[conn_info->service]->flow_control == OPENAIS_FLOW_CONTROL_REQUIRED) {
  250. openais_flow_control_ipc_init (
  251. &conn_info->flow_control_handle,
  252. conn_info->service);
  253. }
  254. return (0);
  255. }
  256. /*
  257. * Create a connection data structure
  258. */
  259. static inline unsigned int conn_info_create (int fd) {
  260. struct conn_info *conn_info;
  261. int res;
  262. conn_info = malloc (sizeof (struct conn_info));
  263. if (conn_info == 0) {
  264. return (ENOMEM);
  265. }
  266. memset (conn_info, 0, sizeof (struct conn_info));
  267. res = queue_init (&conn_info->outq, SIZEQUEUE,
  268. sizeof (struct outq_item));
  269. if (res != 0) {
  270. free (conn_info);
  271. return (ENOMEM);
  272. }
  273. conn_info->inb = malloc (sizeof (char) * SIZEINB);
  274. if (conn_info->inb == NULL) {
  275. queue_free (&conn_info->outq);
  276. free (conn_info);
  277. return (ENOMEM);
  278. }
  279. conn_info->shared_mutex = malloc (sizeof (pthread_mutex_t));
  280. if (conn_info->shared_mutex == NULL) {
  281. free (conn_info->inb);
  282. queue_free (&conn_info->outq);
  283. free (conn_info);
  284. return (ENOMEM);
  285. }
  286. pthread_mutex_init (&conn_info->mutex, NULL);
  287. pthread_mutex_init (&conn_info->flow_control_mutex, NULL);
  288. pthread_mutex_init (conn_info->shared_mutex, NULL);
  289. list_init (&conn_info->list);
  290. conn_info->state = CONN_STATE_ACTIVE;
  291. conn_info->fd = fd;
  292. conn_info->events = POLLIN|POLLNVAL;
  293. conn_info->service = SOCKET_SERVICE_INIT;
  294. pthread_attr_init (&conn_info->thread_attr);
  295. /*
  296. * IA64 needs more stack space then other arches
  297. */
  298. #if defined(__ia64__)
  299. pthread_attr_setstacksize (&conn_info->thread_attr, 400000);
  300. #else
  301. pthread_attr_setstacksize (&conn_info->thread_attr, 200000);
  302. #endif
  303. pthread_attr_setdetachstate (&conn_info->thread_attr, PTHREAD_CREATE_DETACHED);
  304. res = pthread_create (&conn_info->thread, &conn_info->thread_attr,
  305. prioritized_poll_thread, conn_info);
  306. return (res);
  307. }
  308. static void conn_info_destroy (struct conn_info *conn_info)
  309. {
  310. struct outq_item *outq_item;
  311. /*
  312. * Free the outq queued items
  313. */
  314. while (!queue_is_empty (&conn_info->outq)) {
  315. outq_item = queue_item_get (&conn_info->outq);
  316. free (outq_item->msg);
  317. queue_item_remove (&conn_info->outq);
  318. }
  319. queue_free (&conn_info->outq);
  320. free (conn_info->inb);
  321. if (conn_info->conn_info_partner) {
  322. conn_info->conn_info_partner->conn_info_partner = NULL;
  323. }
  324. pthread_attr_destroy (&conn_info->thread_attr);
  325. pthread_mutex_destroy (&conn_info->mutex);
  326. list_del (&conn_info->list);
  327. free (conn_info);
  328. }
  329. static int libais_connection_active (struct conn_info *conn_info)
  330. {
  331. return (conn_info->state == CONN_STATE_ACTIVE);
  332. }
  333. static void libais_disconnect_request (struct conn_info *conn_info)
  334. {
  335. if (conn_info->state == CONN_STATE_ACTIVE) {
  336. conn_info->state = CONN_STATE_REQUESTED;
  337. conn_info->conn_info_partner->state = CONN_STATE_REQUESTED;
  338. }
  339. }
  340. static int libais_disconnect (struct conn_info *conn_info)
  341. {
  342. int res = 0;
  343. assert (conn_info->state != CONN_STATE_ACTIVE);
  344. if (conn_info->state == CONN_STATE_DISCONNECTED) {
  345. assert (0);
  346. }
  347. /*
  348. * Close active connections
  349. */
  350. if (conn_info->state == CONN_STATE_ACTIVE || conn_info->state == CONN_STATE_REQUESTED) {
  351. close (conn_info->fd);
  352. conn_info->state = CONN_STATE_CLOSED;
  353. close (conn_info->conn_info_partner->fd);
  354. conn_info->conn_info_partner->state = CONN_STATE_CLOSED;
  355. }
  356. /*
  357. * Note we will only call the close operation once on the first time
  358. * one of the connections is closed
  359. */
  360. if (conn_info->state == CONN_STATE_CLOSED) {
  361. if (conn_info->lib_exit_fn) {
  362. res = conn_info->lib_exit_fn (conn_info);
  363. }
  364. if (res == -1) {
  365. return (-1);
  366. }
  367. if (conn_info->conn_info_partner->lib_exit_fn) {
  368. res = conn_info->conn_info_partner->lib_exit_fn (conn_info);
  369. }
  370. if (res == -1) {
  371. return (-1);
  372. }
  373. }
  374. conn_info->state = CONN_STATE_DISCONNECTED;
  375. conn_info->conn_info_partner->state = CONN_STATE_DISCONNECTED;
  376. if (conn_info->flow_control_enabled == 1) {
  377. openais_flow_control_disable (conn_info->flow_control_handle);
  378. }
  379. return (0);
  380. }
  381. static inline void conn_info_mutex_lock (
  382. struct conn_info *conn_info,
  383. unsigned int service)
  384. {
  385. if (service == SOCKET_SERVICE_INIT) {
  386. pthread_mutex_lock (&conn_info->mutex);
  387. } else {
  388. pthread_mutex_lock (conn_info->shared_mutex);
  389. }
  390. }
  391. static inline void conn_info_mutex_unlock (
  392. struct conn_info *conn_info,
  393. unsigned int service)
  394. {
  395. if (service == SOCKET_SERVICE_INIT) {
  396. pthread_mutex_unlock (&conn_info->mutex);
  397. } else {
  398. pthread_mutex_unlock (conn_info->shared_mutex);
  399. }
  400. }
  401. /*
  402. * This thread runs in a specific thread priority mode to handle
  403. * I/O requests from the library
  404. */
  405. static void *prioritized_poll_thread (void *conn)
  406. {
  407. struct conn_info *conn_info = (struct conn_info *)conn;
  408. struct pollfd ufd;
  409. int fds;
  410. struct sched_param sched_param;
  411. int res;
  412. pthread_mutex_t *rel_mutex;
  413. unsigned int service;
  414. struct conn_info *cinfo_partner;
  415. void *private_data;
  416. sched_param.sched_priority = 1;
  417. res = pthread_setschedparam (conn_info->thread, SCHED_RR, &sched_param);
  418. ufd.fd = conn_info->fd;
  419. for (;;) {
  420. retry_poll:
  421. service = conn_info->service;
  422. ufd.events = conn_info->events;
  423. ufd.revents = 0;
  424. fds = poll (&ufd, 1, -1);
  425. conn_info_mutex_lock (conn_info, service);
  426. switch (conn_info->state) {
  427. case CONN_STATE_SECURITY:
  428. conn_info_mutex_unlock (conn_info, service);
  429. pthread_mutex_destroy (conn_info->shared_mutex);
  430. free (conn_info->shared_mutex);
  431. conn_info_destroy (conn);
  432. pthread_exit (0);
  433. break;
  434. case CONN_STATE_REQUESTED:
  435. case CONN_STATE_CLOSED:
  436. res = libais_disconnect (conn);
  437. if (res != 0) {
  438. conn_info_mutex_unlock (conn_info, service);
  439. goto retry_poll;
  440. }
  441. break;
  442. case CONN_STATE_DISCONNECTED:
  443. rel_mutex = conn_info->shared_mutex;
  444. private_data = conn_info->private_data;
  445. cinfo_partner = conn_info->conn_info_partner;
  446. conn_info_destroy (conn);
  447. if (service == SOCKET_SERVICE_INIT) {
  448. pthread_mutex_unlock (&conn_info->mutex);
  449. } else {
  450. pthread_mutex_unlock (rel_mutex);
  451. }
  452. if (cinfo_partner == NULL) {
  453. pthread_mutex_destroy (rel_mutex);
  454. free (rel_mutex);
  455. free (private_data);
  456. }
  457. pthread_exit (0);
  458. /*
  459. * !! NOTE !! this is the exit point for this thread
  460. */
  461. break;
  462. default:
  463. break;
  464. }
  465. if (fds == -1) {
  466. conn_info_mutex_unlock (conn_info, service);
  467. goto retry_poll;
  468. }
  469. ipc_serialize_lock_fn ();
  470. if (fds == 1 && ufd.revents) {
  471. if (ufd.revents & (POLLERR|POLLHUP)) {
  472. libais_disconnect_request (conn_info);
  473. conn_info_mutex_unlock (conn_info, service);
  474. ipc_serialize_unlock_fn ();
  475. continue;
  476. }
  477. if (ufd.revents & POLLOUT) {
  478. conn_info_outq_flush (conn_info);
  479. }
  480. if ((ufd.revents & POLLIN) == POLLIN) {
  481. libais_deliver (conn_info);
  482. }
  483. ipc_flow_control (conn_info);
  484. }
  485. ipc_serialize_unlock_fn ();
  486. conn_info_mutex_unlock (conn_info, service);
  487. }
  488. /*
  489. * This code never reached
  490. */
  491. return (0);
  492. }
  493. #if defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)
  494. /* SUN_LEN is broken for abstract namespace
  495. */
  496. #define AIS_SUN_LEN(a) sizeof(*(a))
  497. #else
  498. #define AIS_SUN_LEN(a) SUN_LEN(a)
  499. #endif
  500. #if defined(OPENAIS_LINUX)
  501. char *socketname = "libais.socket";
  502. #else
  503. char *socketname = "/var/run/libais.socket";
  504. #endif
  505. static void ipc_flow_control (struct conn_info *conn_info)
  506. {
  507. unsigned int entries_used;
  508. unsigned int entries_usedhw;
  509. unsigned int flow_control_local_count;
  510. unsigned int fcc;
  511. /*
  512. * Determine FCC variable and printing variables
  513. */
  514. entries_used = queue_used (&conn_info->outq);
  515. if (conn_info->conn_info_partner &&
  516. queue_used (&conn_info->conn_info_partner->outq) > entries_used) {
  517. entries_used = queue_used (&conn_info->conn_info_partner->outq);
  518. }
  519. entries_usedhw = queue_usedhw (&conn_info->outq);
  520. if (conn_info->conn_info_partner &&
  521. queue_usedhw (&conn_info->conn_info_partner->outq) > entries_used) {
  522. entries_usedhw = queue_usedhw (&conn_info->conn_info_partner->outq);
  523. }
  524. flow_control_local_count = conn_info->flow_control_local_count;
  525. if (conn_info->conn_info_partner &&
  526. conn_info->conn_info_partner->flow_control_local_count > flow_control_local_count) {
  527. flow_control_local_count = conn_info->conn_info_partner->flow_control_local_count;
  528. }
  529. fcc = entries_used;
  530. if (flow_control_local_count > fcc) {
  531. fcc = flow_control_local_count;
  532. }
  533. /*
  534. * IPC group-wide flow control
  535. */
  536. if (conn_info->flow_control == OPENAIS_FLOW_CONTROL_REQUIRED) {
  537. if (conn_info->flow_control_enabled == 0 &&
  538. ((fcc + FLOW_CONTROL_ENTRIES_ENABLE) > SIZEQUEUE)) {
  539. log_printf (LOG_LEVEL_NOTICE, "Enabling flow control [%d/%d] - [%d].\n",
  540. entries_usedhw, SIZEQUEUE,
  541. flow_control_local_count);
  542. openais_flow_control_enable (conn_info->flow_control_handle);
  543. conn_info->flow_control_enabled = 1;
  544. conn_info->conn_info_partner->flow_control_enabled = 1;
  545. }
  546. if (conn_info->flow_control_enabled == 1 &&
  547. fcc <= FLOW_CONTROL_ENTRIES_DISABLE) {
  548. log_printf (LOG_LEVEL_NOTICE, "Disabling flow control [%d/%d] - [%d].\n",
  549. entries_usedhw, SIZEQUEUE,
  550. flow_control_local_count);
  551. openais_flow_control_disable (conn_info->flow_control_handle);
  552. conn_info->flow_control_enabled = 0;
  553. conn_info->conn_info_partner->flow_control_enabled = 0;
  554. }
  555. }
  556. }
  557. static int conn_info_outq_flush (struct conn_info *conn_info) {
  558. struct queue *outq;
  559. int res = 0;
  560. struct outq_item *queue_item;
  561. struct msghdr msg_send;
  562. struct iovec iov_send;
  563. char *msg_addr;
  564. if (!libais_connection_active (conn_info)) {
  565. return (-1);
  566. }
  567. outq = &conn_info->outq;
  568. msg_send.msg_iov = &iov_send;
  569. msg_send.msg_name = 0;
  570. msg_send.msg_namelen = 0;
  571. msg_send.msg_iovlen = 1;
  572. #ifndef OPENAIS_SOLARIS
  573. msg_send.msg_control = 0;
  574. msg_send.msg_controllen = 0;
  575. msg_send.msg_flags = 0;
  576. #else
  577. msg_send.msg_accrights = 0;
  578. msg_send.msg_accrightslen = 0;
  579. #endif
  580. while (!queue_is_empty (outq)) {
  581. queue_item = queue_item_get (outq);
  582. msg_addr = (char *)queue_item->msg;
  583. msg_addr = &msg_addr[conn_info->byte_start];
  584. iov_send.iov_base = msg_addr;
  585. iov_send.iov_len = queue_item->mlen - conn_info->byte_start;
  586. retry_sendmsg:
  587. res = sendmsg (conn_info->fd, &msg_send, MSG_NOSIGNAL);
  588. if (res == -1 && errno == EINTR) {
  589. goto retry_sendmsg;
  590. }
  591. if (res == -1 && errno == EAGAIN) {
  592. return (0);
  593. }
  594. if (res == -1 && errno == EPIPE) {
  595. libais_disconnect_request (conn_info);
  596. return (0);
  597. }
  598. if (res == -1) {
  599. printf ("ERRNO is %d\n", errno);
  600. assert (0); /* some other unhandled error here */
  601. }
  602. if (res + conn_info->byte_start != queue_item->mlen) {
  603. conn_info->byte_start += res;
  604. return (0);
  605. }
  606. /*
  607. * Message sent, try sending another message
  608. */
  609. queue_item_remove (outq);
  610. conn_info->byte_start = 0;
  611. free (queue_item->msg);
  612. } /* while queue not empty */
  613. if (queue_is_empty (outq)) {
  614. conn_info->events = POLLIN|POLLNVAL;
  615. }
  616. return (0);
  617. }
  618. struct res_overlay {
  619. mar_res_header_t header __attribute((aligned(8)));
  620. char buf[4096];
  621. };
  622. static void libais_deliver (struct conn_info *conn_info)
  623. {
  624. int res;
  625. mar_req_header_t *header;
  626. int service;
  627. struct msghdr msg_recv;
  628. struct iovec iov_recv;
  629. #ifdef OPENAIS_LINUX
  630. struct cmsghdr *cmsg;
  631. char cmsg_cred[CMSG_SPACE (sizeof (struct ucred))];
  632. struct ucred *cred;
  633. int on = 0;
  634. #endif
  635. int send_ok = 0;
  636. int send_ok_joined = 0;
  637. struct iovec send_ok_joined_iovec;
  638. struct res_overlay res_overlay;
  639. msg_recv.msg_iov = &iov_recv;
  640. msg_recv.msg_iovlen = 1;
  641. msg_recv.msg_name = 0;
  642. msg_recv.msg_namelen = 0;
  643. #ifndef OPENAIS_SOLARIS
  644. msg_recv.msg_flags = 0;
  645. if (conn_info->authenticated) {
  646. msg_recv.msg_control = 0;
  647. msg_recv.msg_controllen = 0;
  648. } else {
  649. #ifdef OPENAIS_LINUX
  650. msg_recv.msg_control = (void *)cmsg_cred;
  651. msg_recv.msg_controllen = sizeof (cmsg_cred);
  652. #else
  653. uid_t euid = -1;
  654. gid_t egid = -1;
  655. if (getpeereid(conn_info->fd, &euid, &egid) != -1 &&
  656. (euid == 0 || egid == g_gid_valid)) {
  657. conn_info->authenticated = 1;
  658. }
  659. if (conn_info->authenticated == 0) {
  660. log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", egid, g_gid_valid);
  661. }
  662. #endif
  663. }
  664. #else /* OPENAIS_SOLARIS */
  665. msg_recv.msg_accrights = 0;
  666. msg_recv.msg_accrightslen = 0;
  667. if (! conn_info->authenticated) {
  668. #ifdef HAVE_GETPEERUCRED
  669. ucred_t *uc;
  670. uid_t euid = -1;
  671. gid_t egid = -1;
  672. if (getpeerucred(conn_info->fd, &uc) == 0) {
  673. euid = ucred_geteuid(uc);
  674. egid = ucred_getegid(uc);
  675. if ((euid == 0) || (egid == g_gid_valid)) {
  676. conn_info->authenticated = 1;
  677. }
  678. ucred_free(uc);
  679. }
  680. if (conn_info->authenticated == 0) {
  681. log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", (int)egid, g_gid_valid);
  682. }
  683. #else
  684. log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated "
  685. "because platform does not support "
  686. "authentication with sockets, continuing "
  687. "with a fake authentication\n");
  688. conn_info->authenticated = 1;
  689. #endif
  690. }
  691. #endif
  692. iov_recv.iov_base = &conn_info->inb[conn_info->inb_start];
  693. iov_recv.iov_len = (SIZEINB) - conn_info->inb_start;
  694. if (conn_info->inb_inuse == SIZEINB) {
  695. return;
  696. }
  697. retry_recv:
  698. res = recvmsg (conn_info->fd, &msg_recv, MSG_NOSIGNAL);
  699. if (res == -1 && errno == EINTR) {
  700. goto retry_recv;
  701. } else
  702. if (res == -1 && errno != EAGAIN) {
  703. return;
  704. } else
  705. if (res == 0) {
  706. #if defined(OPENAIS_SOLARIS) || defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  707. /* On many OS poll never return POLLHUP or POLLERR.
  708. * EOF is detected when recvmsg return 0.
  709. */
  710. libais_disconnect_request (conn_info);
  711. #endif
  712. return;
  713. }
  714. /*
  715. * Authenticate if this connection has not been authenticated
  716. */
  717. #ifdef OPENAIS_LINUX
  718. if (conn_info->authenticated == 0) {
  719. cmsg = CMSG_FIRSTHDR (&msg_recv);
  720. assert (cmsg);
  721. cred = (struct ucred *)CMSG_DATA (cmsg);
  722. if (cred) {
  723. if (cred->uid == 0 || cred->gid == g_gid_valid) {
  724. setsockopt(conn_info->fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on));
  725. conn_info->authenticated = 1;
  726. }
  727. }
  728. if (conn_info->authenticated == 0) {
  729. log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", cred->gid, g_gid_valid);
  730. }
  731. }
  732. #endif
  733. /*
  734. * Dispatch all messages received in recvmsg that can be dispatched
  735. * sizeof (mar_req_header_t) needed at minimum to do any processing
  736. */
  737. conn_info->inb_inuse += res;
  738. conn_info->inb_start += res;
  739. while (conn_info->inb_inuse >= sizeof (mar_req_header_t) && res != -1) {
  740. header = (mar_req_header_t *)&conn_info->inb[conn_info->inb_start - conn_info->inb_inuse];
  741. if (header->size > conn_info->inb_inuse) {
  742. break;
  743. }
  744. service = conn_info->service;
  745. /*
  746. * If this service is in init phase, initialize service
  747. * else handle message using service service
  748. */
  749. if (service == SOCKET_SERVICE_INIT) {
  750. res = ais_init_service[header->id] (conn_info, header);
  751. } else {
  752. /*
  753. * Not an init service, but a standard service
  754. */
  755. if (header->id < 0 || header->id > ais_service[service]->lib_service_count) {
  756. log_printf (LOG_LEVEL_SECURITY, "Invalid header id is %d min 0 max %d\n",
  757. header->id, ais_service[service]->lib_service_count);
  758. return ;
  759. }
  760. /*
  761. * If flow control is required of the library handle, determine that
  762. * openais is not in synchronization and that totempg has room available
  763. * to queue a message, otherwise tell the library we are busy and to
  764. * try again later
  765. */
  766. send_ok_joined_iovec.iov_base = (char *)header;
  767. send_ok_joined_iovec.iov_len = header->size;
  768. send_ok_joined = totempg_groups_send_ok_joined (openais_group_handle,
  769. &send_ok_joined_iovec, 1);
  770. send_ok =
  771. (sync_primary_designated() == 1) && (
  772. (ais_service[service]->lib_service[header->id].flow_control == OPENAIS_FLOW_CONTROL_NOT_REQUIRED) ||
  773. ((ais_service[service]->lib_service[header->id].flow_control == OPENAIS_FLOW_CONTROL_REQUIRED) &&
  774. (send_ok_joined) &&
  775. (sync_in_process() == 0)));
  776. if (send_ok) {
  777. ais_service[service]->lib_service[header->id].lib_handler_fn(conn_info, header);
  778. } else {
  779. /*
  780. * Overload, tell library to retry
  781. */
  782. res_overlay.header.size =
  783. ais_service[service]->lib_service[header->id].response_size;
  784. res_overlay.header.id =
  785. ais_service[service]->lib_service[header->id].response_id;
  786. res_overlay.header.error = SA_AIS_ERR_TRY_AGAIN;
  787. openais_conn_send_response (
  788. conn_info,
  789. &res_overlay,
  790. res_overlay.header.size);
  791. }
  792. }
  793. conn_info->inb_inuse -= header->size;
  794. } /* while */
  795. if (conn_info->inb_inuse == 0) {
  796. conn_info->inb_start = 0;
  797. } else
  798. // BUG if (connections[conn_info->fd].inb_start + connections[conn_info->fd].inb_inuse >= SIZEINB) {
  799. if (conn_info->inb_start >= SIZEINB) {
  800. /*
  801. * If in buffer is full, move it back to start
  802. */
  803. memmove (conn_info->inb,
  804. &conn_info->inb[conn_info->inb_start - conn_info->inb_inuse],
  805. sizeof (char) * conn_info->inb_inuse);
  806. conn_info->inb_start = conn_info->inb_inuse;
  807. }
  808. return;
  809. }
  810. static int poll_handler_libais_accept (
  811. poll_handle handle,
  812. int fd,
  813. int revent,
  814. void *data)
  815. {
  816. socklen_t addrlen;
  817. struct sockaddr_un un_addr;
  818. int new_fd;
  819. #ifdef OPENAIS_LINUX
  820. int on = 1;
  821. #endif
  822. int res;
  823. addrlen = sizeof (struct sockaddr_un);
  824. retry_accept:
  825. new_fd = accept (fd, (struct sockaddr *)&un_addr, &addrlen);
  826. if (new_fd == -1 && errno == EINTR) {
  827. goto retry_accept;
  828. }
  829. if (new_fd == -1) {
  830. log_printf (LOG_LEVEL_ERROR, "ERROR: Could not accept Library connection: %s\n", strerror (errno));
  831. return (0); /* This is an error, but -1 would indicate disconnect from poll loop */
  832. }
  833. totemip_nosigpipe(new_fd);
  834. res = fcntl (new_fd, F_SETFL, O_NONBLOCK);
  835. if (res == -1) {
  836. log_printf (LOG_LEVEL_ERROR, "Could not set non-blocking operation on library connection: %s\n", strerror (errno));
  837. close (new_fd);
  838. return (0); /* This is an error, but -1 would indicate disconnect from poll loop */
  839. }
  840. /*
  841. * Valid accept
  842. */
  843. /*
  844. * Request credentials of sender provided by kernel
  845. */
  846. #ifdef OPENAIS_LINUX
  847. setsockopt(new_fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on));
  848. #endif
  849. log_printf (LOG_LEVEL_DEBUG, "connection received from libais client %d.\n", new_fd);
  850. res = conn_info_create (new_fd);
  851. if (res != 0) {
  852. close (new_fd);
  853. }
  854. return (0);
  855. }
  856. /*
  857. * Exported functions
  858. */
  859. int message_source_is_local(mar_message_source_t *source)
  860. {
  861. int ret = 0;
  862. assert (source != NULL);
  863. if (source->nodeid == my_ip->nodeid) {
  864. ret = 1;
  865. }
  866. return ret;
  867. }
  868. void message_source_set (
  869. mar_message_source_t *source,
  870. void *conn)
  871. {
  872. assert ((source != NULL) && (conn != NULL));
  873. source->nodeid = my_ip->nodeid;
  874. source->conn = conn;
  875. }
  876. static void ipc_confchg_fn (
  877. enum totem_configuration_type configuration_type,
  878. unsigned int *member_list, int member_list_entries,
  879. unsigned int *left_list, int left_list_entries,
  880. unsigned int *joined_list, int joined_list_entries,
  881. struct memb_ring_id *ring_id)
  882. {
  883. }
  884. void openais_ipc_init (
  885. void (*serialize_lock_fn) (void),
  886. void (*serialize_unlock_fn) (void),
  887. unsigned int gid_valid,
  888. struct totem_ip_address *my_ip_in)
  889. {
  890. int libais_server_fd;
  891. struct sockaddr_un un_addr;
  892. int res;
  893. log_init ("IPC");
  894. ipc_serialize_lock_fn = serialize_lock_fn;
  895. ipc_serialize_unlock_fn = serialize_unlock_fn;
  896. /*
  897. * Create socket for libais clients, name socket, listen for connections
  898. */
  899. libais_server_fd = socket (PF_UNIX, SOCK_STREAM, 0);
  900. if (libais_server_fd == -1) {
  901. log_printf (LOG_LEVEL_ERROR ,"Cannot create libais client connections socket.\n");
  902. openais_exit_error (AIS_DONE_LIBAIS_SOCKET);
  903. };
  904. totemip_nosigpipe(libais_server_fd);
  905. res = fcntl (libais_server_fd, F_SETFL, O_NONBLOCK);
  906. if (res == -1) {
  907. log_printf (LOG_LEVEL_ERROR, "Could not set non-blocking operation on server socket: %s\n", strerror (errno));
  908. openais_exit_error (AIS_DONE_LIBAIS_SOCKET);
  909. }
  910. #if !defined(OPENAIS_LINUX)
  911. unlink(socketname);
  912. #endif
  913. memset (&un_addr, 0, sizeof (struct sockaddr_un));
  914. un_addr.sun_family = AF_UNIX;
  915. #if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  916. un_addr.sun_len = sizeof(struct sockaddr_un);
  917. #endif
  918. #if defined(OPENAIS_LINUX)
  919. strcpy (un_addr.sun_path + 1, socketname);
  920. #else
  921. strcpy (un_addr.sun_path, socketname);
  922. #endif
  923. res = bind (libais_server_fd, (struct sockaddr *)&un_addr, AIS_SUN_LEN(&un_addr));
  924. if (res) {
  925. log_printf (LOG_LEVEL_ERROR, "ERROR: Could not bind AF_UNIX: %s.\n", strerror (errno));
  926. openais_exit_error (AIS_DONE_LIBAIS_BIND);
  927. }
  928. listen (libais_server_fd, SERVER_BACKLOG);
  929. /*
  930. * Setup libais connection dispatch routine
  931. */
  932. poll_dispatch_add (aisexec_poll_handle, libais_server_fd,
  933. POLLIN, 0, poll_handler_libais_accept);
  934. g_gid_valid = gid_valid;
  935. my_ip = my_ip_in;
  936. /*
  937. * Reset internal state of flow control when
  938. * configuration change occurs
  939. */
  940. res = totempg_groups_initialize (
  941. &ipc_handle,
  942. NULL,
  943. ipc_confchg_fn);
  944. }
  945. /*
  946. * Get the conn info private data
  947. */
  948. void *openais_conn_private_data_get (void *conn)
  949. {
  950. struct conn_info *conn_info = (struct conn_info *)conn;
  951. if (conn != NULL) {
  952. return ((void *)conn_info->private_data);
  953. } else {
  954. return NULL;
  955. }
  956. }
  957. /*
  958. * Get the conn info partner connection
  959. */
  960. void *openais_conn_partner_get (void *conn)
  961. {
  962. struct conn_info *conn_info = (struct conn_info *)conn;
  963. if (conn != NULL) {
  964. return ((void *)conn_info->conn_info_partner);
  965. } else {
  966. return NULL;
  967. }
  968. }
  969. int openais_conn_send_response (
  970. void *conn,
  971. void *msg,
  972. int mlen)
  973. {
  974. struct queue *outq;
  975. char *cmsg;
  976. int res = 0;
  977. int queue_empty;
  978. struct outq_item *queue_item;
  979. struct outq_item queue_item_out;
  980. struct msghdr msg_send;
  981. struct iovec iov_send;
  982. char *msg_addr;
  983. struct conn_info *conn_info = (struct conn_info *)conn;
  984. if (conn_info == NULL) {
  985. return -1;
  986. }
  987. if (!libais_connection_active (conn_info)) {
  988. return (-1);
  989. }
  990. ipc_flow_control (conn_info);
  991. outq = &conn_info->outq;
  992. msg_send.msg_iov = &iov_send;
  993. msg_send.msg_name = 0;
  994. msg_send.msg_namelen = 0;
  995. msg_send.msg_iovlen = 1;
  996. #ifndef OPENAIS_SOLARIS
  997. msg_send.msg_control = 0;
  998. msg_send.msg_controllen = 0;
  999. msg_send.msg_flags = 0;
  1000. #else
  1001. msg_send.msg_accrights = 0;
  1002. msg_send.msg_accrightslen = 0;
  1003. #endif
  1004. if (queue_is_full (outq)) {
  1005. /*
  1006. * Start a disconnect if we have not already started one
  1007. * and report that the outgoing queue is full
  1008. */
  1009. log_printf (LOG_LEVEL_ERROR, "Library queue is full, disconnecting library connection.\n");
  1010. libais_disconnect_request (conn_info);
  1011. return (-1);
  1012. }
  1013. while (!queue_is_empty (outq)) {
  1014. queue_item = queue_item_get (outq);
  1015. msg_addr = (char *)queue_item->msg;
  1016. msg_addr = &msg_addr[conn_info->byte_start];
  1017. iov_send.iov_base = msg_addr;
  1018. iov_send.iov_len = queue_item->mlen - conn_info->byte_start;
  1019. retry_sendmsg:
  1020. res = sendmsg (conn_info->fd, &msg_send, MSG_NOSIGNAL);
  1021. if (res == -1 && errno == EINTR) {
  1022. goto retry_sendmsg;
  1023. }
  1024. if (res == -1 && errno == EAGAIN) {
  1025. break; /* outgoing kernel queue full */
  1026. }
  1027. if (res == -1 && errno == EPIPE) {
  1028. libais_disconnect_request (conn_info);
  1029. return (0);
  1030. }
  1031. if (res == -1) {
  1032. assert (0);
  1033. break; /* some other error, stop trying to send message */
  1034. }
  1035. if (res + conn_info->byte_start != queue_item->mlen) {
  1036. conn_info->byte_start += res;
  1037. break;
  1038. }
  1039. /*
  1040. * Message sent, try sending another message
  1041. */
  1042. queue_item_remove (outq);
  1043. conn_info->byte_start = 0;
  1044. free (queue_item->msg);
  1045. } /* while queue not empty */
  1046. res = -1;
  1047. queue_empty = queue_is_empty (outq);
  1048. /*
  1049. * Send request message
  1050. */
  1051. if (queue_empty) {
  1052. iov_send.iov_base = msg;
  1053. iov_send.iov_len = mlen;
  1054. retry_sendmsg_two:
  1055. res = sendmsg (conn_info->fd, &msg_send, MSG_NOSIGNAL);
  1056. if (res == -1 && errno == EINTR) {
  1057. goto retry_sendmsg_two;
  1058. }
  1059. if (res == -1 && errno == EAGAIN) {
  1060. conn_info->byte_start = 0;
  1061. conn_info->events = POLLIN|POLLNVAL;
  1062. }
  1063. if (res != -1) {
  1064. if (res != mlen) {
  1065. conn_info->byte_start += res;
  1066. res = -1;
  1067. } else {
  1068. conn_info->byte_start = 0;
  1069. conn_info->events = POLLIN|POLLNVAL;
  1070. }
  1071. }
  1072. }
  1073. /*
  1074. * If res == -1 , errrno == EAGAIN which means kernel queue full
  1075. */
  1076. if (res == -1) {
  1077. cmsg = malloc (mlen);
  1078. if (cmsg == 0) {
  1079. log_printf (LOG_LEVEL_ERROR, "Library queue couldn't allocate a message, disconnecting library connection.\n");
  1080. libais_disconnect_request (conn_info);
  1081. return (-1);
  1082. }
  1083. queue_item_out.msg = cmsg;
  1084. queue_item_out.mlen = mlen;
  1085. memcpy (cmsg, msg, mlen);
  1086. queue_item_add (outq, &queue_item_out);
  1087. /*
  1088. * Send a pthread_kill to interrupt the poll syscall
  1089. * and start a new poll operation in the thread
  1090. */
  1091. conn_info->events = POLLIN|POLLOUT|POLLNVAL;
  1092. pthread_kill (conn_info->thread, SIGUSR1);
  1093. }
  1094. return (0);
  1095. }
  1096. int openais_ipc_timer_add (
  1097. void *conn,
  1098. void (*timer_fn) (void *data),
  1099. void *data,
  1100. unsigned int msec_in_future,
  1101. timer_handle *handle)
  1102. {
  1103. struct conn_info *conn_info = (struct conn_info *)conn;
  1104. int res;
  1105. res = timerlist_add_future (
  1106. &conn_info->timerlist,
  1107. timer_fn,
  1108. data,
  1109. msec_in_future,
  1110. handle);
  1111. return (res);
  1112. }
  1113. void openais_ipc_timer_del (
  1114. void *conn,
  1115. timer_handle timer_handle)
  1116. {
  1117. struct conn_info *conn_info = (struct conn_info *)conn;
  1118. timerlist_del (&conn_info->timerlist, timer_handle);
  1119. }
  1120. void openais_ipc_timer_del_data (
  1121. void *conn,
  1122. timer_handle timer_handle)
  1123. {
  1124. struct conn_info *conn_info = (struct conn_info *)conn;
  1125. timerlist_del (&conn_info->timerlist, timer_handle);
  1126. }
  1127. void openais_ipc_flow_control_create (
  1128. void *conn,
  1129. unsigned int service,
  1130. char *id,
  1131. int id_len,
  1132. void (*flow_control_state_set_fn) (void *conn, enum openais_flow_control_state),
  1133. void *context)
  1134. {
  1135. struct conn_info *conn_info = (struct conn_info *)conn;
  1136. openais_flow_control_create (
  1137. conn_info->flow_control_handle,
  1138. service,
  1139. id,
  1140. id_len,
  1141. flow_control_state_set_fn,
  1142. context);
  1143. conn_info->conn_info_partner->flow_control_handle = conn_info->flow_control_handle;
  1144. }
  1145. void openais_ipc_flow_control_destroy (
  1146. void *conn,
  1147. unsigned int service,
  1148. unsigned char *id,
  1149. int id_len)
  1150. {
  1151. struct conn_info *conn_info = (struct conn_info *)conn;
  1152. openais_flow_control_destroy (
  1153. conn_info->flow_control_handle,
  1154. service,
  1155. id,
  1156. id_len);
  1157. }
  1158. void openais_ipc_flow_control_local_increment (
  1159. void *conn)
  1160. {
  1161. struct conn_info *conn_info = (struct conn_info *)conn;
  1162. pthread_mutex_lock (&conn_info->flow_control_mutex);
  1163. conn_info->flow_control_local_count++;
  1164. pthread_mutex_unlock (&conn_info->flow_control_mutex);
  1165. }
  1166. void openais_ipc_flow_control_local_decrement (
  1167. void *conn)
  1168. {
  1169. struct conn_info *conn_info = (struct conn_info *)conn;
  1170. pthread_mutex_lock (&conn_info->flow_control_mutex);
  1171. conn_info->flow_control_local_count--;
  1172. pthread_mutex_unlock (&conn_info->flow_control_mutex);
  1173. }