ipc.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  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. int libais_connection_active (struct conn_info *conn_info);
  332. int libais_connection_active (struct conn_info *conn_info)
  333. {
  334. return (conn_info->state == CONN_STATE_ACTIVE);
  335. }
  336. static void libais_disconnect_request (struct conn_info *conn_info)
  337. {
  338. if (conn_info->state == CONN_STATE_ACTIVE) {
  339. conn_info->state = CONN_STATE_REQUESTED;
  340. conn_info->conn_info_partner->state = CONN_STATE_REQUESTED;
  341. }
  342. }
  343. static int libais_disconnect (struct conn_info *conn_info)
  344. {
  345. int res = 0;
  346. assert (conn_info->state != CONN_STATE_ACTIVE);
  347. if (conn_info->state == CONN_STATE_DISCONNECTED) {
  348. assert (0);
  349. }
  350. /*
  351. * Close active connections
  352. */
  353. if (conn_info->state == CONN_STATE_ACTIVE || conn_info->state == CONN_STATE_REQUESTED) {
  354. close (conn_info->fd);
  355. conn_info->state = CONN_STATE_CLOSED;
  356. close (conn_info->conn_info_partner->fd);
  357. conn_info->conn_info_partner->state = CONN_STATE_CLOSED;
  358. }
  359. /*
  360. * Note we will only call the close operation once on the first time
  361. * one of the connections is closed
  362. */
  363. if (conn_info->state == CONN_STATE_CLOSED) {
  364. if (conn_info->lib_exit_fn) {
  365. res = conn_info->lib_exit_fn (conn_info);
  366. }
  367. if (res == -1) {
  368. return (-1);
  369. }
  370. if (conn_info->conn_info_partner->lib_exit_fn) {
  371. res = conn_info->conn_info_partner->lib_exit_fn (conn_info);
  372. }
  373. if (res == -1) {
  374. return (-1);
  375. }
  376. }
  377. conn_info->state = CONN_STATE_DISCONNECTED;
  378. conn_info->conn_info_partner->state = CONN_STATE_DISCONNECTED;
  379. if (conn_info->flow_control_enabled == 1) {
  380. openais_flow_control_disable (conn_info->flow_control_handle);
  381. }
  382. return (0);
  383. }
  384. static inline void conn_info_mutex_lock (
  385. struct conn_info *conn_info,
  386. unsigned int service)
  387. {
  388. if (service == SOCKET_SERVICE_INIT) {
  389. pthread_mutex_lock (&conn_info->mutex);
  390. } else {
  391. pthread_mutex_lock (conn_info->shared_mutex);
  392. }
  393. }
  394. static inline void conn_info_mutex_unlock (
  395. struct conn_info *conn_info,
  396. unsigned int service)
  397. {
  398. if (service == SOCKET_SERVICE_INIT) {
  399. pthread_mutex_unlock (&conn_info->mutex);
  400. } else {
  401. pthread_mutex_unlock (conn_info->shared_mutex);
  402. }
  403. }
  404. /*
  405. * This thread runs in a specific thread priority mode to handle
  406. * I/O requests from the library
  407. */
  408. static void *prioritized_poll_thread (void *conn)
  409. {
  410. struct conn_info *conn_info = (struct conn_info *)conn;
  411. struct pollfd ufd;
  412. int fds;
  413. struct sched_param sched_param;
  414. int res;
  415. pthread_mutex_t *rel_mutex;
  416. unsigned int service;
  417. struct conn_info *cinfo_partner;
  418. void *private_data;
  419. sched_param.sched_priority = 1;
  420. res = pthread_setschedparam (conn_info->thread, SCHED_RR, &sched_param);
  421. ufd.fd = conn_info->fd;
  422. for (;;) {
  423. retry_poll:
  424. service = conn_info->service;
  425. ufd.events = conn_info->events;
  426. ufd.revents = 0;
  427. fds = poll (&ufd, 1, -1);
  428. conn_info_mutex_lock (conn_info, service);
  429. switch (conn_info->state) {
  430. case CONN_STATE_SECURITY:
  431. conn_info_mutex_unlock (conn_info, service);
  432. pthread_mutex_destroy (conn_info->shared_mutex);
  433. free (conn_info->shared_mutex);
  434. conn_info_destroy (conn);
  435. pthread_exit (0);
  436. break;
  437. case CONN_STATE_REQUESTED:
  438. case CONN_STATE_CLOSED:
  439. res = libais_disconnect (conn);
  440. if (res != 0) {
  441. conn_info_mutex_unlock (conn_info, service);
  442. goto retry_poll;
  443. }
  444. break;
  445. case CONN_STATE_DISCONNECTED:
  446. rel_mutex = conn_info->shared_mutex;
  447. private_data = conn_info->private_data;
  448. cinfo_partner = conn_info->conn_info_partner;
  449. conn_info_destroy (conn);
  450. if (service == SOCKET_SERVICE_INIT) {
  451. pthread_mutex_unlock (&conn_info->mutex);
  452. } else {
  453. pthread_mutex_unlock (rel_mutex);
  454. }
  455. if (cinfo_partner == NULL) {
  456. pthread_mutex_destroy (rel_mutex);
  457. free (rel_mutex);
  458. free (private_data);
  459. }
  460. pthread_exit (0);
  461. /*
  462. * !! NOTE !! this is the exit point for this thread
  463. */
  464. break;
  465. default:
  466. break;
  467. }
  468. if (fds == -1) {
  469. conn_info_mutex_unlock (conn_info, service);
  470. goto retry_poll;
  471. }
  472. ipc_serialize_lock_fn ();
  473. if (fds == 1 && ufd.revents) {
  474. if (ufd.revents & (POLLERR|POLLHUP)) {
  475. libais_disconnect_request (conn_info);
  476. conn_info_mutex_unlock (conn_info, service);
  477. ipc_serialize_unlock_fn ();
  478. continue;
  479. }
  480. if (ufd.revents & POLLOUT) {
  481. conn_info_outq_flush (conn_info);
  482. }
  483. if ((ufd.revents & POLLIN) == POLLIN) {
  484. libais_deliver (conn_info);
  485. }
  486. ipc_flow_control (conn_info);
  487. }
  488. ipc_serialize_unlock_fn ();
  489. conn_info_mutex_unlock (conn_info, service);
  490. }
  491. /*
  492. * This code never reached
  493. */
  494. return (0);
  495. }
  496. #if defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)
  497. /* SUN_LEN is broken for abstract namespace
  498. */
  499. #define AIS_SUN_LEN(a) sizeof(*(a))
  500. #else
  501. #define AIS_SUN_LEN(a) SUN_LEN(a)
  502. #endif
  503. #if defined(OPENAIS_LINUX)
  504. char *socketname = "libais.socket";
  505. #else
  506. char *socketname = "/var/run/libais.socket";
  507. #endif
  508. static void ipc_flow_control (struct conn_info *conn_info)
  509. {
  510. unsigned int entries_used;
  511. unsigned int entries_usedhw;
  512. unsigned int flow_control_local_count;
  513. unsigned int fcc;
  514. /*
  515. * Determine FCC variable and printing variables
  516. */
  517. entries_used = queue_used (&conn_info->outq);
  518. if (conn_info->conn_info_partner &&
  519. queue_used (&conn_info->conn_info_partner->outq) > entries_used) {
  520. entries_used = queue_used (&conn_info->conn_info_partner->outq);
  521. }
  522. entries_usedhw = queue_usedhw (&conn_info->outq);
  523. if (conn_info->conn_info_partner &&
  524. queue_usedhw (&conn_info->conn_info_partner->outq) > entries_used) {
  525. entries_usedhw = queue_usedhw (&conn_info->conn_info_partner->outq);
  526. }
  527. flow_control_local_count = conn_info->flow_control_local_count;
  528. if (conn_info->conn_info_partner &&
  529. conn_info->conn_info_partner->flow_control_local_count > flow_control_local_count) {
  530. flow_control_local_count = conn_info->conn_info_partner->flow_control_local_count;
  531. }
  532. fcc = entries_used;
  533. if (flow_control_local_count > fcc) {
  534. fcc = flow_control_local_count;
  535. }
  536. /*
  537. * IPC group-wide flow control
  538. */
  539. if (conn_info->flow_control == OPENAIS_FLOW_CONTROL_REQUIRED) {
  540. if (conn_info->flow_control_enabled == 0 &&
  541. ((fcc + FLOW_CONTROL_ENTRIES_ENABLE) > SIZEQUEUE)) {
  542. log_printf (LOG_LEVEL_NOTICE, "Enabling flow control [%d/%d] - [%d].\n",
  543. entries_usedhw, SIZEQUEUE,
  544. flow_control_local_count);
  545. openais_flow_control_enable (conn_info->flow_control_handle);
  546. conn_info->flow_control_enabled = 1;
  547. conn_info->conn_info_partner->flow_control_enabled = 1;
  548. }
  549. if (conn_info->flow_control_enabled == 1 &&
  550. fcc <= FLOW_CONTROL_ENTRIES_DISABLE) {
  551. log_printf (LOG_LEVEL_NOTICE, "Disabling flow control [%d/%d] - [%d].\n",
  552. entries_usedhw, SIZEQUEUE,
  553. flow_control_local_count);
  554. openais_flow_control_disable (conn_info->flow_control_handle);
  555. conn_info->flow_control_enabled = 0;
  556. conn_info->conn_info_partner->flow_control_enabled = 0;
  557. }
  558. }
  559. }
  560. static int conn_info_outq_flush (struct conn_info *conn_info) {
  561. struct queue *outq;
  562. int res = 0;
  563. struct outq_item *queue_item;
  564. struct msghdr msg_send;
  565. struct iovec iov_send;
  566. char *msg_addr;
  567. if (!libais_connection_active (conn_info)) {
  568. return (-1);
  569. }
  570. outq = &conn_info->outq;
  571. msg_send.msg_iov = &iov_send;
  572. msg_send.msg_name = 0;
  573. msg_send.msg_namelen = 0;
  574. msg_send.msg_iovlen = 1;
  575. #ifndef OPENAIS_SOLARIS
  576. msg_send.msg_control = 0;
  577. msg_send.msg_controllen = 0;
  578. msg_send.msg_flags = 0;
  579. #else
  580. msg_send.msg_accrights = 0;
  581. msg_send.msg_accrightslen = 0;
  582. #endif
  583. while (!queue_is_empty (outq)) {
  584. queue_item = queue_item_get (outq);
  585. msg_addr = (char *)queue_item->msg;
  586. msg_addr = &msg_addr[conn_info->byte_start];
  587. iov_send.iov_base = msg_addr;
  588. iov_send.iov_len = queue_item->mlen - conn_info->byte_start;
  589. retry_sendmsg:
  590. res = sendmsg (conn_info->fd, &msg_send, MSG_NOSIGNAL);
  591. if (res == -1 && errno == EINTR) {
  592. goto retry_sendmsg;
  593. }
  594. if (res == -1 && errno == EAGAIN) {
  595. return (0);
  596. }
  597. if (res == -1 && errno == EPIPE) {
  598. libais_disconnect_request (conn_info);
  599. return (0);
  600. }
  601. if (res == -1) {
  602. printf ("ERRNO is %d\n", errno);
  603. assert (0); /* some other unhandled error here */
  604. }
  605. if (res + conn_info->byte_start != queue_item->mlen) {
  606. conn_info->byte_start += res;
  607. return (0);
  608. }
  609. /*
  610. * Message sent, try sending another message
  611. */
  612. queue_item_remove (outq);
  613. conn_info->byte_start = 0;
  614. free (queue_item->msg);
  615. } /* while queue not empty */
  616. if (queue_is_empty (outq)) {
  617. conn_info->events = POLLIN|POLLNVAL;
  618. }
  619. return (0);
  620. }
  621. struct res_overlay {
  622. mar_res_header_t header __attribute((aligned(8)));
  623. char buf[4096];
  624. };
  625. static void libais_deliver (struct conn_info *conn_info)
  626. {
  627. int res;
  628. mar_req_header_t *header;
  629. int service;
  630. struct msghdr msg_recv;
  631. struct iovec iov_recv;
  632. #ifdef OPENAIS_LINUX
  633. struct cmsghdr *cmsg;
  634. char cmsg_cred[CMSG_SPACE (sizeof (struct ucred))];
  635. struct ucred *cred;
  636. int on = 0;
  637. #endif
  638. int send_ok = 0;
  639. int send_ok_joined = 0;
  640. struct iovec send_ok_joined_iovec;
  641. struct res_overlay res_overlay;
  642. msg_recv.msg_iov = &iov_recv;
  643. msg_recv.msg_iovlen = 1;
  644. msg_recv.msg_name = 0;
  645. msg_recv.msg_namelen = 0;
  646. #ifndef OPENAIS_SOLARIS
  647. msg_recv.msg_flags = 0;
  648. if (conn_info->authenticated) {
  649. msg_recv.msg_control = 0;
  650. msg_recv.msg_controllen = 0;
  651. } else {
  652. #ifdef OPENAIS_LINUX
  653. msg_recv.msg_control = (void *)cmsg_cred;
  654. msg_recv.msg_controllen = sizeof (cmsg_cred);
  655. #else
  656. uid_t euid = -1;
  657. gid_t egid = -1;
  658. if (getpeereid(conn_info->fd, &euid, &egid) != -1 &&
  659. (euid == 0 || egid == g_gid_valid)) {
  660. conn_info->authenticated = 1;
  661. }
  662. if (conn_info->authenticated == 0) {
  663. log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", egid, g_gid_valid);
  664. }
  665. #endif
  666. }
  667. #else /* OPENAIS_SOLARIS */
  668. msg_recv.msg_accrights = 0;
  669. msg_recv.msg_accrightslen = 0;
  670. if (! conn_info->authenticated) {
  671. #ifdef HAVE_GETPEERUCRED
  672. ucred_t *uc;
  673. uid_t euid = -1;
  674. gid_t egid = -1;
  675. if (getpeerucred(conn_info->fd, &uc) == 0) {
  676. euid = ucred_geteuid(uc);
  677. egid = ucred_getegid(uc);
  678. if ((euid == 0) || (egid == g_gid_valid)) {
  679. conn_info->authenticated = 1;
  680. }
  681. ucred_free(uc);
  682. }
  683. if (conn_info->authenticated == 0) {
  684. log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", (int)egid, g_gid_valid);
  685. }
  686. #else
  687. log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated "
  688. "because platform does not support "
  689. "authentication with sockets, continuing "
  690. "with a fake authentication\n");
  691. conn_info->authenticated = 1;
  692. #endif
  693. }
  694. #endif
  695. iov_recv.iov_base = &conn_info->inb[conn_info->inb_start];
  696. iov_recv.iov_len = (SIZEINB) - conn_info->inb_start;
  697. if (conn_info->inb_inuse == SIZEINB) {
  698. return;
  699. }
  700. retry_recv:
  701. res = recvmsg (conn_info->fd, &msg_recv, MSG_NOSIGNAL);
  702. if (res == -1 && errno == EINTR) {
  703. goto retry_recv;
  704. } else
  705. if (res == -1 && errno != EAGAIN) {
  706. return;
  707. } else
  708. if (res == 0) {
  709. #if defined(OPENAIS_SOLARIS) || defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  710. /* On many OS poll never return POLLHUP or POLLERR.
  711. * EOF is detected when recvmsg return 0.
  712. */
  713. libais_disconnect_request (conn_info);
  714. #endif
  715. return;
  716. }
  717. /*
  718. * Authenticate if this connection has not been authenticated
  719. */
  720. #ifdef OPENAIS_LINUX
  721. if (conn_info->authenticated == 0) {
  722. cmsg = CMSG_FIRSTHDR (&msg_recv);
  723. assert (cmsg);
  724. cred = (struct ucred *)CMSG_DATA (cmsg);
  725. if (cred) {
  726. if (cred->uid == 0 || cred->gid == g_gid_valid) {
  727. setsockopt(conn_info->fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on));
  728. conn_info->authenticated = 1;
  729. }
  730. }
  731. if (conn_info->authenticated == 0) {
  732. log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", cred->gid, g_gid_valid);
  733. }
  734. }
  735. #endif
  736. /*
  737. * Dispatch all messages received in recvmsg that can be dispatched
  738. * sizeof (mar_req_header_t) needed at minimum to do any processing
  739. */
  740. conn_info->inb_inuse += res;
  741. conn_info->inb_start += res;
  742. while (conn_info->inb_inuse >= sizeof (mar_req_header_t) && res != -1) {
  743. header = (mar_req_header_t *)&conn_info->inb[conn_info->inb_start - conn_info->inb_inuse];
  744. if (header->size > conn_info->inb_inuse) {
  745. break;
  746. }
  747. service = conn_info->service;
  748. /*
  749. * If this service is in init phase, initialize service
  750. * else handle message using service service
  751. */
  752. if (service == SOCKET_SERVICE_INIT) {
  753. res = ais_init_service[header->id] (conn_info, header);
  754. } else {
  755. /*
  756. * Not an init service, but a standard service
  757. */
  758. if (header->id < 0 || header->id > ais_service[service]->lib_service_count) {
  759. log_printf (LOG_LEVEL_SECURITY, "Invalid header id is %d min 0 max %d\n",
  760. header->id, ais_service[service]->lib_service_count);
  761. return ;
  762. }
  763. /*
  764. * If flow control is required of the library handle, determine that
  765. * openais is not in synchronization and that totempg has room available
  766. * to queue a message, otherwise tell the library we are busy and to
  767. * try again later
  768. */
  769. send_ok_joined_iovec.iov_base = (char *)header;
  770. send_ok_joined_iovec.iov_len = header->size;
  771. send_ok_joined = totempg_groups_send_ok_joined (openais_group_handle,
  772. &send_ok_joined_iovec, 1);
  773. send_ok =
  774. (sync_primary_designated() == 1) && (
  775. (ais_service[service]->lib_service[header->id].flow_control == OPENAIS_FLOW_CONTROL_NOT_REQUIRED) ||
  776. ((ais_service[service]->lib_service[header->id].flow_control == OPENAIS_FLOW_CONTROL_REQUIRED) &&
  777. (send_ok_joined) &&
  778. (sync_in_process() == 0)));
  779. if (send_ok) {
  780. ais_service[service]->lib_service[header->id].lib_handler_fn(conn_info, header);
  781. } else {
  782. /*
  783. * Overload, tell library to retry
  784. */
  785. res_overlay.header.size =
  786. ais_service[service]->lib_service[header->id].response_size;
  787. res_overlay.header.id =
  788. ais_service[service]->lib_service[header->id].response_id;
  789. res_overlay.header.error = SA_AIS_ERR_TRY_AGAIN;
  790. openais_conn_send_response (
  791. conn_info,
  792. &res_overlay,
  793. res_overlay.header.size);
  794. }
  795. }
  796. conn_info->inb_inuse -= header->size;
  797. } /* while */
  798. if (conn_info->inb_inuse == 0) {
  799. conn_info->inb_start = 0;
  800. } else
  801. // BUG if (connections[conn_info->fd].inb_start + connections[conn_info->fd].inb_inuse >= SIZEINB) {
  802. if (conn_info->inb_start >= SIZEINB) {
  803. /*
  804. * If in buffer is full, move it back to start
  805. */
  806. memmove (conn_info->inb,
  807. &conn_info->inb[conn_info->inb_start - conn_info->inb_inuse],
  808. sizeof (char) * conn_info->inb_inuse);
  809. conn_info->inb_start = conn_info->inb_inuse;
  810. }
  811. return;
  812. }
  813. static int poll_handler_libais_accept (
  814. poll_handle handle,
  815. int fd,
  816. int revent,
  817. void *data)
  818. {
  819. socklen_t addrlen;
  820. struct sockaddr_un un_addr;
  821. int new_fd;
  822. #ifdef OPENAIS_LINUX
  823. int on = 1;
  824. #endif
  825. int res;
  826. addrlen = sizeof (struct sockaddr_un);
  827. retry_accept:
  828. new_fd = accept (fd, (struct sockaddr *)&un_addr, &addrlen);
  829. if (new_fd == -1 && errno == EINTR) {
  830. goto retry_accept;
  831. }
  832. if (new_fd == -1) {
  833. log_printf (LOG_LEVEL_ERROR, "ERROR: Could not accept Library connection: %s\n", strerror (errno));
  834. return (0); /* This is an error, but -1 would indicate disconnect from poll loop */
  835. }
  836. totemip_nosigpipe(new_fd);
  837. res = fcntl (new_fd, F_SETFL, O_NONBLOCK);
  838. if (res == -1) {
  839. log_printf (LOG_LEVEL_ERROR, "Could not set non-blocking operation on library connection: %s\n", strerror (errno));
  840. close (new_fd);
  841. return (0); /* This is an error, but -1 would indicate disconnect from poll loop */
  842. }
  843. /*
  844. * Valid accept
  845. */
  846. /*
  847. * Request credentials of sender provided by kernel
  848. */
  849. #ifdef OPENAIS_LINUX
  850. setsockopt(new_fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on));
  851. #endif
  852. log_printf (LOG_LEVEL_DEBUG, "connection received from libais client %d.\n", new_fd);
  853. res = conn_info_create (new_fd);
  854. if (res != 0) {
  855. close (new_fd);
  856. }
  857. return (0);
  858. }
  859. /*
  860. * Exported functions
  861. */
  862. int message_source_is_local(mar_message_source_t *source)
  863. {
  864. int ret = 0;
  865. assert (source != NULL);
  866. if (source->nodeid == totempg_my_nodeid_get ()) {
  867. ret = 1;
  868. }
  869. return ret;
  870. }
  871. void message_source_set (
  872. mar_message_source_t *source,
  873. void *conn)
  874. {
  875. assert ((source != NULL) && (conn != NULL));
  876. memset (source, 0, sizeof (mar_message_source_t));
  877. source->nodeid = totempg_my_nodeid_get ();
  878. source->conn = conn;
  879. }
  880. static void ipc_confchg_fn (
  881. enum totem_configuration_type configuration_type,
  882. unsigned int *member_list, int member_list_entries,
  883. unsigned int *left_list, int left_list_entries,
  884. unsigned int *joined_list, int joined_list_entries,
  885. struct memb_ring_id *ring_id)
  886. {
  887. }
  888. void openais_ipc_init (
  889. void (*serialize_lock_fn) (void),
  890. void (*serialize_unlock_fn) (void),
  891. unsigned int gid_valid)
  892. {
  893. int libais_server_fd;
  894. struct sockaddr_un un_addr;
  895. int res;
  896. ipc_serialize_lock_fn = serialize_lock_fn;
  897. ipc_serialize_unlock_fn = serialize_unlock_fn;
  898. /*
  899. * Create socket for libais clients, name socket, listen for connections
  900. */
  901. libais_server_fd = socket (PF_UNIX, SOCK_STREAM, 0);
  902. if (libais_server_fd == -1) {
  903. log_printf (LOG_LEVEL_ERROR ,"Cannot create libais client connections socket.\n");
  904. openais_exit_error (AIS_DONE_LIBAIS_SOCKET);
  905. };
  906. totemip_nosigpipe(libais_server_fd);
  907. res = fcntl (libais_server_fd, F_SETFL, O_NONBLOCK);
  908. if (res == -1) {
  909. log_printf (LOG_LEVEL_ERROR, "Could not set non-blocking operation on server socket: %s\n", strerror (errno));
  910. openais_exit_error (AIS_DONE_LIBAIS_SOCKET);
  911. }
  912. #if !defined(OPENAIS_LINUX)
  913. unlink(socketname);
  914. #endif
  915. memset (&un_addr, 0, sizeof (struct sockaddr_un));
  916. un_addr.sun_family = AF_UNIX;
  917. #if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  918. un_addr.sun_len = sizeof(struct sockaddr_un);
  919. #endif
  920. #if defined(OPENAIS_LINUX)
  921. strcpy (un_addr.sun_path + 1, socketname);
  922. #else
  923. strcpy (un_addr.sun_path, socketname);
  924. #endif
  925. res = bind (libais_server_fd, (struct sockaddr *)&un_addr, AIS_SUN_LEN(&un_addr));
  926. if (res) {
  927. log_printf (LOG_LEVEL_ERROR, "ERROR: Could not bind AF_UNIX: %s.\n", strerror (errno));
  928. openais_exit_error (AIS_DONE_LIBAIS_BIND);
  929. }
  930. listen (libais_server_fd, SERVER_BACKLOG);
  931. /*
  932. * Setup libais connection dispatch routine
  933. */
  934. poll_dispatch_add (aisexec_poll_handle, libais_server_fd,
  935. POLLIN, 0, poll_handler_libais_accept);
  936. g_gid_valid = gid_valid;
  937. /*
  938. * Reset internal state of flow control when
  939. * configuration change occurs
  940. */
  941. res = totempg_groups_initialize (
  942. &ipc_handle,
  943. NULL,
  944. ipc_confchg_fn);
  945. }
  946. /*
  947. * Get the conn info private data
  948. */
  949. void *openais_conn_private_data_get (void *conn)
  950. {
  951. struct conn_info *conn_info = (struct conn_info *)conn;
  952. if (conn != NULL) {
  953. return ((void *)conn_info->private_data);
  954. } else {
  955. return NULL;
  956. }
  957. }
  958. /*
  959. * Get the conn info partner connection
  960. */
  961. void *openais_conn_partner_get (void *conn)
  962. {
  963. struct conn_info *conn_info = (struct conn_info *)conn;
  964. if (conn != NULL) {
  965. return ((void *)conn_info->conn_info_partner);
  966. } else {
  967. return NULL;
  968. }
  969. }
  970. int openais_conn_send_response (
  971. void *conn,
  972. void *msg,
  973. int mlen)
  974. {
  975. struct queue *outq;
  976. char *cmsg;
  977. int res = 0;
  978. int queue_empty;
  979. struct outq_item *queue_item;
  980. struct outq_item queue_item_out;
  981. struct msghdr msg_send;
  982. struct iovec iov_send;
  983. char *msg_addr;
  984. struct conn_info *conn_info = (struct conn_info *)conn;
  985. if (conn_info == NULL) {
  986. return -1;
  987. }
  988. if (!libais_connection_active (conn_info)) {
  989. return (-1);
  990. }
  991. ipc_flow_control (conn_info);
  992. outq = &conn_info->outq;
  993. msg_send.msg_iov = &iov_send;
  994. msg_send.msg_name = 0;
  995. msg_send.msg_namelen = 0;
  996. msg_send.msg_iovlen = 1;
  997. #ifndef OPENAIS_SOLARIS
  998. msg_send.msg_control = 0;
  999. msg_send.msg_controllen = 0;
  1000. msg_send.msg_flags = 0;
  1001. #else
  1002. msg_send.msg_accrights = 0;
  1003. msg_send.msg_accrightslen = 0;
  1004. #endif
  1005. if (queue_is_full (outq)) {
  1006. /*
  1007. * Start a disconnect if we have not already started one
  1008. * and report that the outgoing queue is full
  1009. */
  1010. log_printf (LOG_LEVEL_ERROR, "Library queue is full, disconnecting library connection.\n");
  1011. libais_disconnect_request (conn_info);
  1012. return (-1);
  1013. }
  1014. while (!queue_is_empty (outq)) {
  1015. queue_item = queue_item_get (outq);
  1016. msg_addr = (char *)queue_item->msg;
  1017. msg_addr = &msg_addr[conn_info->byte_start];
  1018. iov_send.iov_base = msg_addr;
  1019. iov_send.iov_len = queue_item->mlen - conn_info->byte_start;
  1020. retry_sendmsg:
  1021. res = sendmsg (conn_info->fd, &msg_send, MSG_NOSIGNAL);
  1022. if (res == -1 && errno == EINTR) {
  1023. goto retry_sendmsg;
  1024. }
  1025. if (res == -1 && errno == EAGAIN) {
  1026. break; /* outgoing kernel queue full */
  1027. }
  1028. if (res == -1 && errno == EPIPE) {
  1029. libais_disconnect_request (conn_info);
  1030. return (0);
  1031. }
  1032. if (res == -1) {
  1033. assert (0);
  1034. break; /* some other error, stop trying to send message */
  1035. }
  1036. if (res + conn_info->byte_start != queue_item->mlen) {
  1037. conn_info->byte_start += res;
  1038. break;
  1039. }
  1040. /*
  1041. * Message sent, try sending another message
  1042. */
  1043. queue_item_remove (outq);
  1044. conn_info->byte_start = 0;
  1045. free (queue_item->msg);
  1046. } /* while queue not empty */
  1047. res = -1;
  1048. queue_empty = queue_is_empty (outq);
  1049. /*
  1050. * Send request message
  1051. */
  1052. if (queue_empty) {
  1053. iov_send.iov_base = msg;
  1054. iov_send.iov_len = mlen;
  1055. retry_sendmsg_two:
  1056. res = sendmsg (conn_info->fd, &msg_send, MSG_NOSIGNAL);
  1057. if (res == -1 && errno == EINTR) {
  1058. goto retry_sendmsg_two;
  1059. }
  1060. if (res == -1 && errno == EAGAIN) {
  1061. conn_info->byte_start = 0;
  1062. conn_info->events = POLLIN|POLLNVAL;
  1063. }
  1064. if (res != -1) {
  1065. if (res != mlen) {
  1066. conn_info->byte_start += res;
  1067. res = -1;
  1068. } else {
  1069. conn_info->byte_start = 0;
  1070. conn_info->events = POLLIN|POLLNVAL;
  1071. }
  1072. }
  1073. }
  1074. /*
  1075. * If res == -1 , errrno == EAGAIN which means kernel queue full
  1076. */
  1077. if (res == -1) {
  1078. cmsg = malloc (mlen);
  1079. if (cmsg == 0) {
  1080. log_printf (LOG_LEVEL_ERROR, "Library queue couldn't allocate a message, disconnecting library connection.\n");
  1081. libais_disconnect_request (conn_info);
  1082. return (-1);
  1083. }
  1084. queue_item_out.msg = cmsg;
  1085. queue_item_out.mlen = mlen;
  1086. memcpy (cmsg, msg, mlen);
  1087. queue_item_add (outq, &queue_item_out);
  1088. /*
  1089. * Send a pthread_kill to interrupt the poll syscall
  1090. * and start a new poll operation in the thread
  1091. */
  1092. conn_info->events = POLLIN|POLLOUT|POLLNVAL;
  1093. pthread_kill (conn_info->thread, SIGUSR1);
  1094. }
  1095. return (0);
  1096. }
  1097. void openais_ipc_flow_control_create (
  1098. void *conn,
  1099. unsigned int service,
  1100. char *id,
  1101. int id_len,
  1102. void (*flow_control_state_set_fn) (void *conn, enum openais_flow_control_state),
  1103. void *context)
  1104. {
  1105. struct conn_info *conn_info = (struct conn_info *)conn;
  1106. openais_flow_control_create (
  1107. conn_info->flow_control_handle,
  1108. service,
  1109. id,
  1110. id_len,
  1111. flow_control_state_set_fn,
  1112. context);
  1113. conn_info->conn_info_partner->flow_control_handle = conn_info->flow_control_handle;
  1114. }
  1115. void openais_ipc_flow_control_destroy (
  1116. void *conn,
  1117. unsigned int service,
  1118. unsigned char *id,
  1119. int id_len)
  1120. {
  1121. struct conn_info *conn_info = (struct conn_info *)conn;
  1122. openais_flow_control_destroy (
  1123. conn_info->flow_control_handle,
  1124. service,
  1125. id,
  1126. id_len);
  1127. }
  1128. void openais_ipc_flow_control_local_increment (
  1129. void *conn)
  1130. {
  1131. struct conn_info *conn_info = (struct conn_info *)conn;
  1132. pthread_mutex_lock (&conn_info->flow_control_mutex);
  1133. conn_info->flow_control_local_count++;
  1134. pthread_mutex_unlock (&conn_info->flow_control_mutex);
  1135. }
  1136. void openais_ipc_flow_control_local_decrement (
  1137. void *conn)
  1138. {
  1139. struct conn_info *conn_info = (struct conn_info *)conn;
  1140. pthread_mutex_lock (&conn_info->flow_control_mutex);
  1141. conn_info->flow_control_local_count--;
  1142. pthread_mutex_unlock (&conn_info->flow_control_mutex);
  1143. }