ipc.c 34 KB

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