ipc.c 34 KB

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