cpg.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250
  1. /*
  2. * Copyright (c) 2006-2015 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfie@redhat.com)
  7. * Author: Jan Friesse (jfriesse@redhat.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 CONTIBUTORS "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 <config.h>
  36. #ifdef HAVE_ALLOCA_H
  37. #include <alloca.h>
  38. #endif
  39. #include <sys/types.h>
  40. #include <sys/socket.h>
  41. #include <sys/un.h>
  42. #include <sys/ioctl.h>
  43. #include <netinet/in.h>
  44. #include <sys/uio.h>
  45. #include <unistd.h>
  46. #include <fcntl.h>
  47. #include <stdlib.h>
  48. #include <stdio.h>
  49. #include <errno.h>
  50. #include <time.h>
  51. #include <assert.h>
  52. #include <arpa/inet.h>
  53. #include <sys/mman.h>
  54. #include <qb/qblist.h>
  55. #include <qb/qbmap.h>
  56. #include <corosync/corotypes.h>
  57. #include <qb/qbipc_common.h>
  58. #include <corosync/corodefs.h>
  59. #include <corosync/logsys.h>
  60. #include <corosync/coroapi.h>
  61. #include <corosync/cpg.h>
  62. #include <corosync/ipc_cpg.h>
  63. #ifndef MAP_ANONYMOUS
  64. #define MAP_ANONYMOUS MAP_ANON
  65. #endif
  66. #include "service.h"
  67. LOGSYS_DECLARE_SUBSYS ("CPG");
  68. #define GROUP_HASH_SIZE 32
  69. enum cpg_message_req_types {
  70. MESSAGE_REQ_EXEC_CPG_PROCJOIN = 0,
  71. MESSAGE_REQ_EXEC_CPG_PROCLEAVE = 1,
  72. MESSAGE_REQ_EXEC_CPG_JOINLIST = 2,
  73. MESSAGE_REQ_EXEC_CPG_MCAST = 3,
  74. MESSAGE_REQ_EXEC_CPG_DOWNLIST_OLD = 4,
  75. MESSAGE_REQ_EXEC_CPG_DOWNLIST = 5,
  76. MESSAGE_REQ_EXEC_CPG_PARTIAL_MCAST = 6,
  77. };
  78. struct zcb_mapped {
  79. struct qb_list_head list;
  80. void *addr;
  81. size_t size;
  82. };
  83. /*
  84. * state` exec deliver
  85. * match group name, pid -> if matched deliver for YES:
  86. * XXX indicates impossible state
  87. *
  88. * join leave mcast
  89. * UNJOINED XXX XXX NO
  90. * LEAVE_STARTED XXX YES(unjoined_enter) YES
  91. * JOIN_STARTED YES(join_started_enter) XXX NO
  92. * JOIN_COMPLETED XXX NO YES
  93. *
  94. * join_started_enter
  95. * set JOIN_COMPLETED
  96. * add entry to process_info list
  97. * unjoined_enter
  98. * set UNJOINED
  99. * delete entry from process_info list
  100. *
  101. *
  102. * library accept join error codes
  103. * UNJOINED YES(CS_OK) set JOIN_STARTED
  104. * LEAVE_STARTED NO(CS_ERR_BUSY)
  105. * JOIN_STARTED NO(CS_ERR_EXIST)
  106. * JOIN_COMPlETED NO(CS_ERR_EXIST)
  107. *
  108. * library accept leave error codes
  109. * UNJOINED NO(CS_ERR_NOT_EXIST)
  110. * LEAVE_STARTED NO(CS_ERR_NOT_EXIST)
  111. * JOIN_STARTED NO(CS_ERR_BUSY)
  112. * JOIN_COMPLETED YES(CS_OK) set LEAVE_STARTED
  113. *
  114. * library accept mcast
  115. * UNJOINED NO(CS_ERR_NOT_EXIST)
  116. * LEAVE_STARTED NO(CS_ERR_NOT_EXIST)
  117. * JOIN_STARTED YES(CS_OK)
  118. * JOIN_COMPLETED YES(CS_OK)
  119. */
  120. enum cpd_state {
  121. CPD_STATE_UNJOINED,
  122. CPD_STATE_LEAVE_STARTED,
  123. CPD_STATE_JOIN_STARTED,
  124. CPD_STATE_JOIN_COMPLETED
  125. };
  126. enum cpg_sync_state {
  127. CPGSYNC_DOWNLIST,
  128. CPGSYNC_JOINLIST
  129. };
  130. static struct qb_list_head joinlist_messages_head;
  131. struct cpg_pd {
  132. void *conn;
  133. mar_cpg_name_t group_name;
  134. uint32_t pid;
  135. enum cpd_state cpd_state;
  136. unsigned int flags;
  137. int initial_totem_conf_sent;
  138. uint64_t transition_counter; /* These two are used when sending fragmented messages */
  139. uint64_t initial_transition_counter;
  140. struct qb_list_head list;
  141. struct qb_list_head iteration_instance_list_head;
  142. struct qb_list_head zcb_mapped_list_head;
  143. };
  144. struct cpg_iteration_instance {
  145. hdb_handle_t handle;
  146. struct qb_list_head list;
  147. struct qb_list_head items_list_head; /* List of process_info */
  148. struct qb_list_head *current_pointer;
  149. };
  150. DECLARE_HDB_DATABASE(cpg_iteration_handle_t_db,NULL);
  151. QB_LIST_DECLARE (cpg_pd_list_head);
  152. static unsigned int my_member_list[PROCESSOR_COUNT_MAX];
  153. static unsigned int my_member_list_entries;
  154. static unsigned int my_old_member_list[PROCESSOR_COUNT_MAX];
  155. static unsigned int my_old_member_list_entries = 0;
  156. static struct corosync_api_v1 *api = NULL;
  157. static enum cpg_sync_state my_sync_state = CPGSYNC_DOWNLIST;
  158. static mar_cpg_ring_id_t last_sync_ring_id;
  159. struct process_info {
  160. unsigned int nodeid;
  161. uint32_t pid;
  162. mar_cpg_name_t group;
  163. struct qb_list_head list; /* on the group_info members list */
  164. };
  165. QB_LIST_DECLARE (process_info_list_head);
  166. struct join_list_entry {
  167. uint32_t pid;
  168. mar_cpg_name_t group_name;
  169. };
  170. /*
  171. * Service Interfaces required by service_message_handler struct
  172. */
  173. static char *cpg_exec_init_fn (struct corosync_api_v1 *);
  174. static int cpg_lib_init_fn (void *conn);
  175. static int cpg_lib_exit_fn (void *conn);
  176. static void message_handler_req_exec_cpg_procjoin (
  177. const void *message,
  178. unsigned int nodeid);
  179. static void message_handler_req_exec_cpg_procleave (
  180. const void *message,
  181. unsigned int nodeid);
  182. static void message_handler_req_exec_cpg_joinlist (
  183. const void *message,
  184. unsigned int nodeid);
  185. static void message_handler_req_exec_cpg_mcast (
  186. const void *message,
  187. unsigned int nodeid);
  188. static void message_handler_req_exec_cpg_partial_mcast (
  189. const void *message,
  190. unsigned int nodeid);
  191. static void message_handler_req_exec_cpg_downlist_old (
  192. const void *message,
  193. unsigned int nodeid);
  194. static void message_handler_req_exec_cpg_downlist (
  195. const void *message,
  196. unsigned int nodeid);
  197. static void exec_cpg_procjoin_endian_convert (void *msg);
  198. static void exec_cpg_joinlist_endian_convert (void *msg);
  199. static void exec_cpg_mcast_endian_convert (void *msg);
  200. static void exec_cpg_partial_mcast_endian_convert (void *msg);
  201. static void exec_cpg_downlist_endian_convert_old (void *msg);
  202. static void exec_cpg_downlist_endian_convert (void *msg);
  203. static void message_handler_req_lib_cpg_join (void *conn, const void *message);
  204. static void message_handler_req_lib_cpg_leave (void *conn, const void *message);
  205. static void message_handler_req_lib_cpg_finalize (void *conn, const void *message);
  206. static void message_handler_req_lib_cpg_mcast (void *conn, const void *message);
  207. static void message_handler_req_lib_cpg_partial_mcast (void *conn, const void *message);
  208. static void message_handler_req_lib_cpg_membership (void *conn,
  209. const void *message);
  210. static void message_handler_req_lib_cpg_local_get (void *conn,
  211. const void *message);
  212. static void message_handler_req_lib_cpg_iteration_initialize (
  213. void *conn,
  214. const void *message);
  215. static void message_handler_req_lib_cpg_iteration_next (
  216. void *conn,
  217. const void *message);
  218. static void message_handler_req_lib_cpg_iteration_finalize (
  219. void *conn,
  220. const void *message);
  221. static void message_handler_req_lib_cpg_zc_alloc (
  222. void *conn,
  223. const void *message);
  224. static void message_handler_req_lib_cpg_zc_free (
  225. void *conn,
  226. const void *message);
  227. static void message_handler_req_lib_cpg_zc_execute (
  228. void *conn,
  229. const void *message);
  230. static int cpg_node_joinleave_send (unsigned int pid, const mar_cpg_name_t *group_name, int fn, int reason);
  231. static int cpg_exec_send_downlist(void);
  232. static int cpg_exec_send_joinlist(void);
  233. static void downlist_inform_clients (void);
  234. static void joinlist_inform_clients (void);
  235. static void joinlist_messages_delete (void);
  236. static void cpg_sync_init (
  237. const unsigned int *trans_list,
  238. size_t trans_list_entries,
  239. const unsigned int *member_list,
  240. size_t member_list_entries,
  241. const struct memb_ring_id *ring_id);
  242. static int cpg_sync_process (void);
  243. static void cpg_sync_activate (void);
  244. static void cpg_sync_abort (void);
  245. static void do_proc_join(
  246. const mar_cpg_name_t *name,
  247. uint32_t pid,
  248. unsigned int nodeid,
  249. int reason);
  250. static void do_proc_leave(
  251. const mar_cpg_name_t *name,
  252. uint32_t pid,
  253. unsigned int nodeid,
  254. int reason);
  255. static int notify_lib_totem_membership (
  256. void *conn,
  257. int member_list_entries,
  258. const unsigned int *member_list);
  259. static inline int zcb_all_free (
  260. struct cpg_pd *cpd);
  261. static char *cpg_print_group_name (
  262. const mar_cpg_name_t *group);
  263. /*
  264. * Library Handler Definition
  265. */
  266. static struct corosync_lib_handler cpg_lib_engine[] =
  267. {
  268. { /* 0 - MESSAGE_REQ_CPG_JOIN */
  269. .lib_handler_fn = message_handler_req_lib_cpg_join,
  270. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  271. },
  272. { /* 1 - MESSAGE_REQ_CPG_LEAVE */
  273. .lib_handler_fn = message_handler_req_lib_cpg_leave,
  274. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  275. },
  276. { /* 2 - MESSAGE_REQ_CPG_MCAST */
  277. .lib_handler_fn = message_handler_req_lib_cpg_mcast,
  278. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  279. },
  280. { /* 3 - MESSAGE_REQ_CPG_MEMBERSHIP */
  281. .lib_handler_fn = message_handler_req_lib_cpg_membership,
  282. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  283. },
  284. { /* 4 - MESSAGE_REQ_CPG_LOCAL_GET */
  285. .lib_handler_fn = message_handler_req_lib_cpg_local_get,
  286. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  287. },
  288. { /* 5 - MESSAGE_REQ_CPG_ITERATIONINITIALIZE */
  289. .lib_handler_fn = message_handler_req_lib_cpg_iteration_initialize,
  290. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  291. },
  292. { /* 6 - MESSAGE_REQ_CPG_ITERATIONNEXT */
  293. .lib_handler_fn = message_handler_req_lib_cpg_iteration_next,
  294. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  295. },
  296. { /* 7 - MESSAGE_REQ_CPG_ITERATIONFINALIZE */
  297. .lib_handler_fn = message_handler_req_lib_cpg_iteration_finalize,
  298. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  299. },
  300. { /* 8 - MESSAGE_REQ_CPG_FINALIZE */
  301. .lib_handler_fn = message_handler_req_lib_cpg_finalize,
  302. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  303. },
  304. { /* 9 */
  305. .lib_handler_fn = message_handler_req_lib_cpg_zc_alloc,
  306. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  307. },
  308. { /* 10 */
  309. .lib_handler_fn = message_handler_req_lib_cpg_zc_free,
  310. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  311. },
  312. { /* 11 */
  313. .lib_handler_fn = message_handler_req_lib_cpg_zc_execute,
  314. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  315. },
  316. { /* 12 */
  317. .lib_handler_fn = message_handler_req_lib_cpg_partial_mcast,
  318. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  319. },
  320. };
  321. static struct corosync_exec_handler cpg_exec_engine[] =
  322. {
  323. { /* 0 - MESSAGE_REQ_EXEC_CPG_PROCJOIN */
  324. .exec_handler_fn = message_handler_req_exec_cpg_procjoin,
  325. .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
  326. },
  327. { /* 1 - MESSAGE_REQ_EXEC_CPG_PROCLEAVE */
  328. .exec_handler_fn = message_handler_req_exec_cpg_procleave,
  329. .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
  330. },
  331. { /* 2 - MESSAGE_REQ_EXEC_CPG_JOINLIST */
  332. .exec_handler_fn = message_handler_req_exec_cpg_joinlist,
  333. .exec_endian_convert_fn = exec_cpg_joinlist_endian_convert
  334. },
  335. { /* 3 - MESSAGE_REQ_EXEC_CPG_MCAST */
  336. .exec_handler_fn = message_handler_req_exec_cpg_mcast,
  337. .exec_endian_convert_fn = exec_cpg_mcast_endian_convert
  338. },
  339. { /* 4 - MESSAGE_REQ_EXEC_CPG_DOWNLIST_OLD */
  340. .exec_handler_fn = message_handler_req_exec_cpg_downlist_old,
  341. .exec_endian_convert_fn = exec_cpg_downlist_endian_convert_old
  342. },
  343. { /* 5 - MESSAGE_REQ_EXEC_CPG_DOWNLIST */
  344. .exec_handler_fn = message_handler_req_exec_cpg_downlist,
  345. .exec_endian_convert_fn = exec_cpg_downlist_endian_convert
  346. },
  347. { /* 6 - MESSAGE_REQ_EXEC_CPG_PARTIAL_MCAST */
  348. .exec_handler_fn = message_handler_req_exec_cpg_partial_mcast,
  349. .exec_endian_convert_fn = exec_cpg_partial_mcast_endian_convert
  350. },
  351. };
  352. struct corosync_service_engine cpg_service_engine = {
  353. .name = "corosync cluster closed process group service v1.01",
  354. .id = CPG_SERVICE,
  355. .priority = 1,
  356. .private_data_size = sizeof (struct cpg_pd),
  357. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED,
  358. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  359. .lib_init_fn = cpg_lib_init_fn,
  360. .lib_exit_fn = cpg_lib_exit_fn,
  361. .lib_engine = cpg_lib_engine,
  362. .lib_engine_count = sizeof (cpg_lib_engine) / sizeof (struct corosync_lib_handler),
  363. .exec_init_fn = cpg_exec_init_fn,
  364. .exec_dump_fn = NULL,
  365. .exec_engine = cpg_exec_engine,
  366. .exec_engine_count = sizeof (cpg_exec_engine) / sizeof (struct corosync_exec_handler),
  367. .sync_init = cpg_sync_init,
  368. .sync_process = cpg_sync_process,
  369. .sync_activate = cpg_sync_activate,
  370. .sync_abort = cpg_sync_abort
  371. };
  372. struct corosync_service_engine *cpg_get_service_engine_ver0 (void)
  373. {
  374. return (&cpg_service_engine);
  375. }
  376. struct req_exec_cpg_procjoin {
  377. struct qb_ipc_request_header header __attribute__((aligned(8)));
  378. mar_cpg_name_t group_name __attribute__((aligned(8)));
  379. mar_uint32_t pid __attribute__((aligned(8)));
  380. mar_uint32_t reason __attribute__((aligned(8)));
  381. };
  382. struct req_exec_cpg_mcast {
  383. struct qb_ipc_request_header header __attribute__((aligned(8)));
  384. mar_cpg_name_t group_name __attribute__((aligned(8)));
  385. mar_uint32_t msglen __attribute__((aligned(8)));
  386. mar_uint32_t pid __attribute__((aligned(8)));
  387. mar_message_source_t source __attribute__((aligned(8)));
  388. mar_uint8_t message[] __attribute__((aligned(8)));
  389. };
  390. struct req_exec_cpg_partial_mcast {
  391. struct qb_ipc_request_header header __attribute__((aligned(8)));
  392. mar_cpg_name_t group_name __attribute__((aligned(8)));
  393. mar_uint32_t msglen __attribute__((aligned(8)));
  394. mar_uint32_t fraglen __attribute__((aligned(8)));
  395. mar_uint32_t pid __attribute__((aligned(8)));
  396. mar_uint32_t type __attribute__((aligned(8)));
  397. mar_message_source_t source __attribute__((aligned(8)));
  398. mar_uint8_t message[] __attribute__((aligned(8)));
  399. };
  400. struct req_exec_cpg_downlist_old {
  401. struct qb_ipc_request_header header __attribute__((aligned(8)));
  402. mar_uint32_t left_nodes __attribute__((aligned(8)));
  403. mar_uint32_t nodeids[PROCESSOR_COUNT_MAX] __attribute__((aligned(8)));
  404. };
  405. struct req_exec_cpg_downlist {
  406. struct qb_ipc_request_header header __attribute__((aligned(8)));
  407. /* merge decisions */
  408. mar_uint32_t old_members __attribute__((aligned(8)));
  409. /* downlist below */
  410. mar_uint32_t left_nodes __attribute__((aligned(8)));
  411. mar_uint32_t nodeids[PROCESSOR_COUNT_MAX] __attribute__((aligned(8)));
  412. };
  413. struct joinlist_msg {
  414. mar_uint32_t sender_nodeid;
  415. uint32_t pid;
  416. mar_cpg_name_t group_name;
  417. struct qb_list_head list;
  418. };
  419. static struct req_exec_cpg_downlist g_req_exec_cpg_downlist;
  420. /*
  421. * Function print group name. It's not reentrant
  422. */
  423. static char *cpg_print_group_name(const mar_cpg_name_t *group)
  424. {
  425. static char res[CPG_MAX_NAME_LENGTH * 4 + 1];
  426. int dest_pos = 0;
  427. char c;
  428. int i;
  429. for (i = 0; i < group->length; i++) {
  430. c = group->value[i];
  431. if (c >= ' ' && c < 0x7f && c != '\\') {
  432. res[dest_pos++] = c;
  433. } else {
  434. if (c == '\\') {
  435. res[dest_pos++] = '\\';
  436. res[dest_pos++] = '\\';
  437. } else {
  438. snprintf(res + dest_pos, sizeof(res) - dest_pos, "\\x%02X", c);
  439. dest_pos += 4;
  440. }
  441. }
  442. }
  443. res[dest_pos] = 0;
  444. return (res);
  445. }
  446. static void cpg_sync_init (
  447. const unsigned int *trans_list,
  448. size_t trans_list_entries,
  449. const unsigned int *member_list,
  450. size_t member_list_entries,
  451. const struct memb_ring_id *ring_id)
  452. {
  453. int entries;
  454. int i, j;
  455. int found;
  456. my_sync_state = CPGSYNC_DOWNLIST;
  457. memcpy (my_member_list, member_list, member_list_entries *
  458. sizeof (unsigned int));
  459. my_member_list_entries = member_list_entries;
  460. last_sync_ring_id.nodeid = ring_id->nodeid;
  461. last_sync_ring_id.seq = ring_id->seq;
  462. entries = 0;
  463. /*
  464. * Determine list of nodeids for downlist message
  465. */
  466. for (i = 0; i < my_old_member_list_entries; i++) {
  467. found = 0;
  468. for (j = 0; j < trans_list_entries; j++) {
  469. if (my_old_member_list[i] == trans_list[j]) {
  470. found = 1;
  471. break;
  472. }
  473. }
  474. if (found == 0) {
  475. g_req_exec_cpg_downlist.nodeids[entries++] =
  476. my_old_member_list[i];
  477. }
  478. }
  479. g_req_exec_cpg_downlist.left_nodes = entries;
  480. }
  481. static int cpg_sync_process (void)
  482. {
  483. int res = -1;
  484. if (my_sync_state == CPGSYNC_DOWNLIST) {
  485. res = cpg_exec_send_downlist();
  486. if (res == -1) {
  487. return (-1);
  488. }
  489. my_sync_state = CPGSYNC_JOINLIST;
  490. }
  491. if (my_sync_state == CPGSYNC_JOINLIST) {
  492. res = cpg_exec_send_joinlist();
  493. }
  494. return (res);
  495. }
  496. static void cpg_sync_activate (void)
  497. {
  498. memcpy (my_old_member_list, my_member_list,
  499. my_member_list_entries * sizeof (unsigned int));
  500. my_old_member_list_entries = my_member_list_entries;
  501. downlist_inform_clients ();
  502. joinlist_inform_clients ();
  503. joinlist_messages_delete ();
  504. notify_lib_totem_membership (NULL, my_member_list_entries, my_member_list);
  505. }
  506. static void cpg_sync_abort (void)
  507. {
  508. joinlist_messages_delete ();
  509. }
  510. static int notify_lib_totem_membership (
  511. void *conn,
  512. int member_list_entries,
  513. const unsigned int *member_list)
  514. {
  515. struct qb_list_head *iter;
  516. char *buf;
  517. int size;
  518. struct res_lib_cpg_totem_confchg_callback *res;
  519. size = sizeof(struct res_lib_cpg_totem_confchg_callback) +
  520. sizeof(mar_uint32_t) * (member_list_entries);
  521. buf = alloca(size);
  522. if (!buf)
  523. return CS_ERR_LIBRARY;
  524. res = (struct res_lib_cpg_totem_confchg_callback *)buf;
  525. res->member_list_entries = member_list_entries;
  526. res->header.size = size;
  527. res->header.id = MESSAGE_RES_CPG_TOTEM_CONFCHG_CALLBACK;
  528. res->header.error = CS_OK;
  529. memcpy (&res->ring_id, &last_sync_ring_id, sizeof (mar_cpg_ring_id_t));
  530. memcpy (res->member_list, member_list, res->member_list_entries * sizeof (mar_uint32_t));
  531. if (conn == NULL) {
  532. qb_list_for_each(iter, &cpg_pd_list_head) {
  533. struct cpg_pd *cpg_pd = qb_list_entry (iter, struct cpg_pd, list);
  534. api->ipc_dispatch_send (cpg_pd->conn, buf, size);
  535. }
  536. } else {
  537. api->ipc_dispatch_send (conn, buf, size);
  538. }
  539. return CS_OK;
  540. }
  541. static int notify_lib_joinlist(
  542. const mar_cpg_name_t *group_name,
  543. void *conn,
  544. int joined_list_entries,
  545. mar_cpg_address_t *joined_list,
  546. int left_list_entries,
  547. mar_cpg_address_t *left_list,
  548. int id)
  549. {
  550. int size;
  551. char *buf;
  552. struct qb_list_head *iter;
  553. int count;
  554. struct res_lib_cpg_confchg_callback *res;
  555. mar_cpg_address_t *retgi;
  556. count = 0;
  557. qb_list_for_each(iter, &process_info_list_head) {
  558. struct process_info *pi = qb_list_entry (iter, struct process_info, list);
  559. if (mar_name_compare (&pi->group, group_name) == 0) {
  560. int i;
  561. int founded = 0;
  562. for (i = 0; i < left_list_entries; i++) {
  563. if (left_list[i].nodeid == pi->nodeid && left_list[i].pid == pi->pid) {
  564. founded++;
  565. }
  566. }
  567. if (!founded)
  568. count++;
  569. }
  570. }
  571. size = sizeof(struct res_lib_cpg_confchg_callback) +
  572. sizeof(mar_cpg_address_t) * (count + left_list_entries + joined_list_entries);
  573. buf = alloca(size);
  574. if (!buf)
  575. return CS_ERR_LIBRARY;
  576. res = (struct res_lib_cpg_confchg_callback *)buf;
  577. res->joined_list_entries = joined_list_entries;
  578. res->left_list_entries = left_list_entries;
  579. res->member_list_entries = count;
  580. retgi = res->member_list;
  581. res->header.size = size;
  582. res->header.id = id;
  583. res->header.error = CS_OK;
  584. memcpy(&res->group_name, group_name, sizeof(mar_cpg_name_t));
  585. qb_list_for_each(iter, &process_info_list_head) {
  586. struct process_info *pi=qb_list_entry (iter, struct process_info, list);
  587. if (mar_name_compare (&pi->group, group_name) == 0) {
  588. int i;
  589. int founded = 0;
  590. for (i = 0;i < left_list_entries; i++) {
  591. if (left_list[i].nodeid == pi->nodeid && left_list[i].pid == pi->pid) {
  592. founded++;
  593. }
  594. }
  595. if (!founded) {
  596. retgi->nodeid = pi->nodeid;
  597. retgi->pid = pi->pid;
  598. retgi++;
  599. }
  600. }
  601. }
  602. if (left_list_entries) {
  603. memcpy (retgi, left_list, left_list_entries * sizeof(mar_cpg_address_t));
  604. retgi += left_list_entries;
  605. }
  606. if (joined_list_entries) {
  607. memcpy (retgi, joined_list, joined_list_entries * sizeof(mar_cpg_address_t));
  608. retgi += joined_list_entries;
  609. }
  610. if (conn) {
  611. api->ipc_dispatch_send (conn, buf, size);
  612. } else {
  613. qb_list_for_each(iter, &cpg_pd_list_head) {
  614. struct cpg_pd *cpd = qb_list_entry (iter, struct cpg_pd, list);
  615. if (mar_name_compare (&cpd->group_name, group_name) == 0) {
  616. assert (joined_list_entries <= 1);
  617. if (joined_list_entries) {
  618. if (joined_list[0].pid == cpd->pid &&
  619. joined_list[0].nodeid == api->totem_nodeid_get()) {
  620. cpd->cpd_state = CPD_STATE_JOIN_COMPLETED;
  621. }
  622. }
  623. if (cpd->cpd_state == CPD_STATE_JOIN_COMPLETED ||
  624. cpd->cpd_state == CPD_STATE_LEAVE_STARTED) {
  625. api->ipc_dispatch_send (cpd->conn, buf, size);
  626. cpd->transition_counter++;
  627. }
  628. if (left_list_entries) {
  629. if (left_list[0].pid == cpd->pid &&
  630. left_list[0].nodeid == api->totem_nodeid_get() &&
  631. left_list[0].reason == CONFCHG_CPG_REASON_LEAVE) {
  632. cpd->pid = 0;
  633. memset (&cpd->group_name, 0, sizeof(cpd->group_name));
  634. cpd->cpd_state = CPD_STATE_UNJOINED;
  635. }
  636. }
  637. }
  638. }
  639. }
  640. /*
  641. * Traverse thru cpds and send totem membership for cpd, where it is not send yet
  642. */
  643. qb_list_for_each(iter, &cpg_pd_list_head) {
  644. struct cpg_pd *cpd = qb_list_entry (iter, struct cpg_pd, list);
  645. if ((cpd->flags & CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF) && (cpd->initial_totem_conf_sent == 0)) {
  646. cpd->initial_totem_conf_sent = 1;
  647. notify_lib_totem_membership (cpd->conn, my_old_member_list_entries, my_old_member_list);
  648. }
  649. }
  650. return CS_OK;
  651. }
  652. static void downlist_log(const char *msg, struct req_exec_cpg_downlist *dl)
  653. {
  654. log_printf (LOG_DEBUG,
  655. "%s: members(old:%d left:%d)",
  656. msg,
  657. dl->old_members,
  658. dl->left_nodes);
  659. }
  660. static void downlist_inform_clients (void)
  661. {
  662. struct qb_list_head *iter, *tmp_iter;
  663. struct process_info *left_pi;
  664. qb_map_t *group_map;
  665. struct cpg_name cpg_group;
  666. mar_cpg_name_t group;
  667. struct confchg_data{
  668. struct cpg_name cpg_group;
  669. mar_cpg_address_t left_list[CPG_MEMBERS_MAX];
  670. int left_list_entries;
  671. struct qb_list_head list;
  672. } *pcd;
  673. qb_map_iter_t *miter;
  674. int i, size;
  675. downlist_log("my downlist", &g_req_exec_cpg_downlist);
  676. group_map = qb_skiplist_create();
  677. /*
  678. * only the cpg groups included in left nodes should receive
  679. * confchg event, so we will collect these cpg groups and
  680. * relative left_lists here.
  681. */
  682. qb_list_for_each_safe(iter, tmp_iter, &process_info_list_head) {
  683. struct process_info *pi = qb_list_entry(iter, struct process_info, list);
  684. left_pi = NULL;
  685. for (i = 0; i < g_req_exec_cpg_downlist.left_nodes; i++) {
  686. if (pi->nodeid == g_req_exec_cpg_downlist.nodeids[i]) {
  687. left_pi = pi;
  688. break;
  689. }
  690. }
  691. if (left_pi) {
  692. marshall_from_mar_cpg_name_t(&cpg_group, &left_pi->group);
  693. cpg_group.value[cpg_group.length] = 0;
  694. pcd = (struct confchg_data *)qb_map_get(group_map, cpg_group.value);
  695. if (pcd == NULL) {
  696. pcd = (struct confchg_data *)calloc(1, sizeof(struct confchg_data));
  697. memcpy(&pcd->cpg_group, &cpg_group, sizeof(struct cpg_name));
  698. qb_map_put(group_map, pcd->cpg_group.value, pcd);
  699. }
  700. size = pcd->left_list_entries;
  701. pcd->left_list[size].nodeid = left_pi->nodeid;
  702. pcd->left_list[size].pid = left_pi->pid;
  703. pcd->left_list[size].reason = CONFCHG_CPG_REASON_NODEDOWN;
  704. pcd->left_list_entries++;
  705. qb_list_del (&left_pi->list);
  706. free (left_pi);
  707. }
  708. }
  709. /* send only one confchg event per cpg group */
  710. miter = qb_map_iter_create(group_map);
  711. while (qb_map_iter_next(miter, (void **)&pcd)) {
  712. marshall_to_mar_cpg_name_t(&group, &pcd->cpg_group);
  713. log_printf (LOG_DEBUG, "left_list_entries:%d", pcd->left_list_entries);
  714. for (i=0; i<pcd->left_list_entries; i++) {
  715. log_printf (LOG_DEBUG, "left_list[%d] group:%s, ip:%s, pid:%d",
  716. i, cpg_print_group_name(&group),
  717. (char*)api->totem_ifaces_print(pcd->left_list[i].nodeid),
  718. pcd->left_list[i].pid);
  719. }
  720. /* send confchg event */
  721. notify_lib_joinlist(&group, NULL,
  722. 0, NULL,
  723. pcd->left_list_entries,
  724. pcd->left_list,
  725. MESSAGE_RES_CPG_CONFCHG_CALLBACK);
  726. free(pcd);
  727. }
  728. qb_map_iter_free(miter);
  729. qb_map_destroy(group_map);
  730. }
  731. /*
  732. * Remove processes that might have left the group while we were suspended.
  733. */
  734. static void joinlist_remove_zombie_pi_entries (void)
  735. {
  736. struct qb_list_head *pi_iter, *tmp_iter;
  737. struct qb_list_head *jl_iter;
  738. struct process_info *pi;
  739. struct joinlist_msg *stored_msg;
  740. int found;
  741. qb_list_for_each_safe(pi_iter, tmp_iter, &process_info_list_head) {
  742. pi = qb_list_entry (pi_iter, struct process_info, list);
  743. /*
  744. * Ignore local node
  745. */
  746. if (pi->nodeid == api->totem_nodeid_get()) {
  747. continue ;
  748. }
  749. /*
  750. * Try to find message in joinlist messages
  751. */
  752. found = 0;
  753. qb_list_for_each(jl_iter, &joinlist_messages_head) {
  754. stored_msg = qb_list_entry(jl_iter, struct joinlist_msg, list);
  755. if (stored_msg->sender_nodeid == api->totem_nodeid_get()) {
  756. continue ;
  757. }
  758. if (pi->nodeid == stored_msg->sender_nodeid &&
  759. pi->pid == stored_msg->pid &&
  760. mar_name_compare (&pi->group, &stored_msg->group_name) == 0) {
  761. found = 1;
  762. break ;
  763. }
  764. }
  765. if (!found) {
  766. do_proc_leave(&pi->group, pi->pid, pi->nodeid, CONFCHG_CPG_REASON_PROCDOWN);
  767. }
  768. }
  769. }
  770. static void joinlist_inform_clients (void)
  771. {
  772. struct joinlist_msg *stored_msg;
  773. struct qb_list_head *iter;
  774. unsigned int i;
  775. i = 0;
  776. qb_list_for_each(iter, &joinlist_messages_head) {
  777. stored_msg = qb_list_entry(iter, struct joinlist_msg, list);
  778. log_printf (LOG_DEBUG, "joinlist_messages[%u] group:%s, ip:%s, pid:%d",
  779. i++, cpg_print_group_name(&stored_msg->group_name),
  780. (char*)api->totem_ifaces_print(stored_msg->sender_nodeid),
  781. stored_msg->pid);
  782. /* Ignore our own messages */
  783. if (stored_msg->sender_nodeid == api->totem_nodeid_get()) {
  784. continue ;
  785. }
  786. do_proc_join (&stored_msg->group_name, stored_msg->pid, stored_msg->sender_nodeid,
  787. CONFCHG_CPG_REASON_NODEUP);
  788. }
  789. joinlist_remove_zombie_pi_entries ();
  790. }
  791. static void joinlist_messages_delete (void)
  792. {
  793. struct joinlist_msg *stored_msg;
  794. struct qb_list_head *iter, *tmp_iter;
  795. qb_list_for_each_safe(iter, tmp_iter, &joinlist_messages_head) {
  796. stored_msg = qb_list_entry(iter, struct joinlist_msg, list);
  797. qb_list_del (&stored_msg->list);
  798. free (stored_msg);
  799. }
  800. qb_list_init (&joinlist_messages_head);
  801. }
  802. static char *cpg_exec_init_fn (struct corosync_api_v1 *corosync_api)
  803. {
  804. qb_list_init (&joinlist_messages_head);
  805. api = corosync_api;
  806. return (NULL);
  807. }
  808. static void cpg_iteration_instance_finalize (struct cpg_iteration_instance *cpg_iteration_instance)
  809. {
  810. struct qb_list_head *iter, *tmp_iter;
  811. struct process_info *pi;
  812. qb_list_for_each_safe(iter, tmp_iter, &(cpg_iteration_instance->items_list_head)) {
  813. pi = qb_list_entry (iter, struct process_info, list);
  814. qb_list_del (&pi->list);
  815. free (pi);
  816. }
  817. qb_list_del (&cpg_iteration_instance->list);
  818. hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_instance->handle);
  819. }
  820. static void cpg_pd_finalize (struct cpg_pd *cpd)
  821. {
  822. struct qb_list_head *iter, *tmp_iter;
  823. struct cpg_iteration_instance *cpii;
  824. zcb_all_free(cpd);
  825. qb_list_for_each_safe(iter, tmp_iter, &(cpd->iteration_instance_list_head)) {
  826. cpii = qb_list_entry (iter, struct cpg_iteration_instance, list);
  827. cpg_iteration_instance_finalize (cpii);
  828. }
  829. qb_list_del (&cpd->list);
  830. }
  831. static int cpg_lib_exit_fn (void *conn)
  832. {
  833. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  834. log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p", conn);
  835. if (cpd->group_name.length > 0 && cpd->cpd_state != CPD_STATE_LEAVE_STARTED) {
  836. cpg_node_joinleave_send (cpd->pid, &cpd->group_name,
  837. MESSAGE_REQ_EXEC_CPG_PROCLEAVE, CONFCHG_CPG_REASON_PROCDOWN);
  838. }
  839. cpg_pd_finalize (cpd);
  840. api->ipc_refcnt_dec (conn);
  841. return (0);
  842. }
  843. static int cpg_node_joinleave_send (unsigned int pid, const mar_cpg_name_t *group_name, int fn, int reason)
  844. {
  845. struct req_exec_cpg_procjoin req_exec_cpg_procjoin;
  846. struct iovec req_exec_cpg_iovec;
  847. int result;
  848. memcpy(&req_exec_cpg_procjoin.group_name, group_name, sizeof(mar_cpg_name_t));
  849. req_exec_cpg_procjoin.pid = pid;
  850. req_exec_cpg_procjoin.reason = reason;
  851. req_exec_cpg_procjoin.header.size = sizeof(req_exec_cpg_procjoin);
  852. req_exec_cpg_procjoin.header.id = SERVICE_ID_MAKE(CPG_SERVICE, fn);
  853. req_exec_cpg_iovec.iov_base = (char *)&req_exec_cpg_procjoin;
  854. req_exec_cpg_iovec.iov_len = sizeof(req_exec_cpg_procjoin);
  855. result = api->totem_mcast (&req_exec_cpg_iovec, 1, TOTEM_AGREED);
  856. return (result);
  857. }
  858. /* Can byteswap join & leave messages */
  859. static void exec_cpg_procjoin_endian_convert (void *msg)
  860. {
  861. struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = msg;
  862. req_exec_cpg_procjoin->pid = swab32(req_exec_cpg_procjoin->pid);
  863. swab_mar_cpg_name_t (&req_exec_cpg_procjoin->group_name);
  864. req_exec_cpg_procjoin->reason = swab32(req_exec_cpg_procjoin->reason);
  865. }
  866. static void exec_cpg_joinlist_endian_convert (void *msg_v)
  867. {
  868. char *msg = msg_v;
  869. struct qb_ipc_response_header *res = (struct qb_ipc_response_header *)msg;
  870. struct join_list_entry *jle = (struct join_list_entry *)(msg + sizeof(struct qb_ipc_response_header));
  871. swab_mar_int32_t (&res->size);
  872. while ((const char*)jle < msg + res->size) {
  873. jle->pid = swab32(jle->pid);
  874. swab_mar_cpg_name_t (&jle->group_name);
  875. jle++;
  876. }
  877. }
  878. static void exec_cpg_downlist_endian_convert_old (void *msg)
  879. {
  880. }
  881. static void exec_cpg_downlist_endian_convert (void *msg)
  882. {
  883. struct req_exec_cpg_downlist *req_exec_cpg_downlist = msg;
  884. unsigned int i;
  885. req_exec_cpg_downlist->left_nodes = swab32(req_exec_cpg_downlist->left_nodes);
  886. req_exec_cpg_downlist->old_members = swab32(req_exec_cpg_downlist->old_members);
  887. for (i = 0; i < req_exec_cpg_downlist->left_nodes; i++) {
  888. req_exec_cpg_downlist->nodeids[i] = swab32(req_exec_cpg_downlist->nodeids[i]);
  889. }
  890. }
  891. static void exec_cpg_mcast_endian_convert (void *msg)
  892. {
  893. struct req_exec_cpg_mcast *req_exec_cpg_mcast = msg;
  894. swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
  895. swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
  896. req_exec_cpg_mcast->pid = swab32(req_exec_cpg_mcast->pid);
  897. req_exec_cpg_mcast->msglen = swab32(req_exec_cpg_mcast->msglen);
  898. swab_mar_message_source_t (&req_exec_cpg_mcast->source);
  899. }
  900. static void exec_cpg_partial_mcast_endian_convert (void *msg)
  901. {
  902. struct req_exec_cpg_partial_mcast *req_exec_cpg_mcast = msg;
  903. swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
  904. swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
  905. req_exec_cpg_mcast->pid = swab32(req_exec_cpg_mcast->pid);
  906. req_exec_cpg_mcast->msglen = swab32(req_exec_cpg_mcast->msglen);
  907. req_exec_cpg_mcast->fraglen = swab32(req_exec_cpg_mcast->fraglen);
  908. req_exec_cpg_mcast->type = swab32(req_exec_cpg_mcast->type);
  909. swab_mar_message_source_t (&req_exec_cpg_mcast->source);
  910. }
  911. static struct process_info *process_info_find(const mar_cpg_name_t *group_name, uint32_t pid, unsigned int nodeid) {
  912. struct qb_list_head *iter;
  913. qb_list_for_each(iter, &process_info_list_head) {
  914. struct process_info *pi = qb_list_entry (iter, struct process_info, list);
  915. if (pi->pid == pid && pi->nodeid == nodeid &&
  916. mar_name_compare (&pi->group, group_name) == 0) {
  917. return pi;
  918. }
  919. }
  920. return NULL;
  921. }
  922. static void do_proc_join(
  923. const mar_cpg_name_t *name,
  924. uint32_t pid,
  925. unsigned int nodeid,
  926. int reason)
  927. {
  928. struct process_info *pi;
  929. struct process_info *pi_entry;
  930. mar_cpg_address_t notify_info;
  931. struct qb_list_head *list;
  932. struct qb_list_head *list_to_add = NULL;
  933. if (process_info_find (name, pid, nodeid) != NULL) {
  934. return ;
  935. }
  936. pi = malloc (sizeof (struct process_info));
  937. if (!pi) {
  938. log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate process_info struct");
  939. return;
  940. }
  941. pi->nodeid = nodeid;
  942. pi->pid = pid;
  943. memcpy(&pi->group, name, sizeof(*name));
  944. qb_list_init(&pi->list);
  945. /*
  946. * Insert new process in sorted order so synchronization works properly
  947. */
  948. list_to_add = &process_info_list_head;
  949. qb_list_for_each(list, &process_info_list_head) {
  950. pi_entry = qb_list_entry(list, struct process_info, list);
  951. if (pi_entry->nodeid > pi->nodeid ||
  952. (pi_entry->nodeid == pi->nodeid && pi_entry->pid > pi->pid)) {
  953. break;
  954. }
  955. list_to_add = list;
  956. }
  957. qb_list_add (&pi->list, list_to_add);
  958. notify_info.pid = pi->pid;
  959. notify_info.nodeid = nodeid;
  960. notify_info.reason = reason;
  961. notify_lib_joinlist(&pi->group, NULL,
  962. 1, &notify_info,
  963. 0, NULL,
  964. MESSAGE_RES_CPG_CONFCHG_CALLBACK);
  965. }
  966. static void do_proc_leave(
  967. const mar_cpg_name_t *name,
  968. uint32_t pid,
  969. unsigned int nodeid,
  970. int reason)
  971. {
  972. struct process_info *pi;
  973. struct qb_list_head *iter, *tmp_iter;
  974. mar_cpg_address_t notify_info;
  975. notify_info.pid = pid;
  976. notify_info.nodeid = nodeid;
  977. notify_info.reason = reason;
  978. notify_lib_joinlist(name, NULL,
  979. 0, NULL,
  980. 1, &notify_info,
  981. MESSAGE_RES_CPG_CONFCHG_CALLBACK);
  982. qb_list_for_each_safe(iter, tmp_iter, &process_info_list_head) {
  983. pi = qb_list_entry(iter, struct process_info, list);
  984. if (pi->pid == pid && pi->nodeid == nodeid &&
  985. mar_name_compare (&pi->group, name)==0) {
  986. qb_list_del (&pi->list);
  987. free (pi);
  988. }
  989. }
  990. }
  991. static void message_handler_req_exec_cpg_downlist_old (
  992. const void *message,
  993. unsigned int nodeid)
  994. {
  995. log_printf (LOGSYS_LEVEL_WARNING, "downlist OLD from node 0x%x",
  996. nodeid);
  997. }
  998. static void message_handler_req_exec_cpg_downlist(
  999. const void *message,
  1000. unsigned int nodeid)
  1001. {
  1002. const struct req_exec_cpg_downlist *req_exec_cpg_downlist = message;
  1003. log_printf (LOGSYS_LEVEL_WARNING, "downlist left_list: %d received",
  1004. req_exec_cpg_downlist->left_nodes);
  1005. }
  1006. static void message_handler_req_exec_cpg_procjoin (
  1007. const void *message,
  1008. unsigned int nodeid)
  1009. {
  1010. const struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = message;
  1011. log_printf(LOGSYS_LEVEL_DEBUG, "got procjoin message from cluster node 0x%x (%s) for pid %u",
  1012. nodeid,
  1013. api->totem_ifaces_print(nodeid),
  1014. (unsigned int)req_exec_cpg_procjoin->pid);
  1015. do_proc_join (&req_exec_cpg_procjoin->group_name,
  1016. req_exec_cpg_procjoin->pid, nodeid,
  1017. CONFCHG_CPG_REASON_JOIN);
  1018. }
  1019. static void message_handler_req_exec_cpg_procleave (
  1020. const void *message,
  1021. unsigned int nodeid)
  1022. {
  1023. const struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = message;
  1024. log_printf(LOGSYS_LEVEL_DEBUG, "got procleave message from cluster node 0x%x (%s) for pid %u",
  1025. nodeid,
  1026. api->totem_ifaces_print(nodeid),
  1027. (unsigned int)req_exec_cpg_procjoin->pid);
  1028. do_proc_leave (&req_exec_cpg_procjoin->group_name,
  1029. req_exec_cpg_procjoin->pid, nodeid,
  1030. req_exec_cpg_procjoin->reason);
  1031. }
  1032. /* Got a proclist from another node */
  1033. static void message_handler_req_exec_cpg_joinlist (
  1034. const void *message_v,
  1035. unsigned int nodeid)
  1036. {
  1037. const char *message = message_v;
  1038. const struct qb_ipc_response_header *res = (const struct qb_ipc_response_header *)message;
  1039. const struct join_list_entry *jle = (const struct join_list_entry *)(message + sizeof(struct qb_ipc_response_header));
  1040. struct joinlist_msg *stored_msg;
  1041. log_printf(LOGSYS_LEVEL_DEBUG, "got joinlist message from node 0x%x",
  1042. nodeid);
  1043. while ((const char*)jle < message + res->size) {
  1044. stored_msg = malloc (sizeof (struct joinlist_msg));
  1045. memset(stored_msg, 0, sizeof (struct joinlist_msg));
  1046. stored_msg->sender_nodeid = nodeid;
  1047. stored_msg->pid = jle->pid;
  1048. memcpy(&stored_msg->group_name, &jle->group_name, sizeof(mar_cpg_name_t));
  1049. qb_list_init (&stored_msg->list);
  1050. qb_list_add (&stored_msg->list, &joinlist_messages_head);
  1051. jle++;
  1052. }
  1053. }
  1054. static void message_handler_req_exec_cpg_mcast (
  1055. const void *message,
  1056. unsigned int nodeid)
  1057. {
  1058. const struct req_exec_cpg_mcast *req_exec_cpg_mcast = message;
  1059. struct res_lib_cpg_deliver_callback res_lib_cpg_mcast;
  1060. int msglen = req_exec_cpg_mcast->msglen;
  1061. struct qb_list_head *iter, *pi_iter, *tmp_iter;
  1062. struct cpg_pd *cpd;
  1063. struct iovec iovec[2];
  1064. int known_node = 0;
  1065. res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_DELIVER_CALLBACK;
  1066. res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast) + msglen;
  1067. res_lib_cpg_mcast.msglen = msglen;
  1068. res_lib_cpg_mcast.pid = req_exec_cpg_mcast->pid;
  1069. res_lib_cpg_mcast.nodeid = nodeid;
  1070. memcpy(&res_lib_cpg_mcast.group_name, &req_exec_cpg_mcast->group_name,
  1071. sizeof(mar_cpg_name_t));
  1072. iovec[0].iov_base = (void *)&res_lib_cpg_mcast;
  1073. iovec[0].iov_len = sizeof (res_lib_cpg_mcast);
  1074. iovec[1].iov_base = (char*)message+sizeof(*req_exec_cpg_mcast);
  1075. iovec[1].iov_len = msglen;
  1076. qb_list_for_each_safe(iter, tmp_iter, &cpg_pd_list_head) {
  1077. cpd = qb_list_entry(iter, struct cpg_pd, list);
  1078. if ((cpd->cpd_state == CPD_STATE_LEAVE_STARTED || cpd->cpd_state == CPD_STATE_JOIN_COMPLETED)
  1079. && (mar_name_compare (&cpd->group_name, &req_exec_cpg_mcast->group_name) == 0)) {
  1080. if (!known_node) {
  1081. /* Try to find, if we know the node */
  1082. qb_list_for_each(pi_iter, &process_info_list_head) {
  1083. struct process_info *pi = qb_list_entry (pi_iter, struct process_info, list);
  1084. if (pi->nodeid == nodeid &&
  1085. mar_name_compare (&pi->group, &req_exec_cpg_mcast->group_name) == 0) {
  1086. known_node = 1;
  1087. break;
  1088. }
  1089. }
  1090. }
  1091. if (!known_node) {
  1092. log_printf(LOGSYS_LEVEL_WARNING, "Unknown node -> we will not deliver message");
  1093. return ;
  1094. }
  1095. api->ipc_dispatch_iov_send (cpd->conn, iovec, 2);
  1096. }
  1097. }
  1098. }
  1099. static void message_handler_req_exec_cpg_partial_mcast (
  1100. const void *message,
  1101. unsigned int nodeid)
  1102. {
  1103. const struct req_exec_cpg_partial_mcast *req_exec_cpg_mcast = message;
  1104. struct res_lib_cpg_partial_deliver_callback res_lib_cpg_mcast;
  1105. int msglen = req_exec_cpg_mcast->fraglen;
  1106. struct qb_list_head *iter, *pi_iter, *tmp_iter;
  1107. struct cpg_pd *cpd;
  1108. struct iovec iovec[2];
  1109. int known_node = 0;
  1110. log_printf(LOGSYS_LEVEL_DEBUG, "Got fragmented message from node %d, size = %d bytes\n", nodeid, msglen);
  1111. res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_PARTIAL_DELIVER_CALLBACK;
  1112. res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast) + msglen;
  1113. res_lib_cpg_mcast.fraglen = msglen;
  1114. res_lib_cpg_mcast.msglen = req_exec_cpg_mcast->msglen;
  1115. res_lib_cpg_mcast.pid = req_exec_cpg_mcast->pid;
  1116. res_lib_cpg_mcast.type = req_exec_cpg_mcast->type;
  1117. res_lib_cpg_mcast.nodeid = nodeid;
  1118. memcpy(&res_lib_cpg_mcast.group_name, &req_exec_cpg_mcast->group_name,
  1119. sizeof(mar_cpg_name_t));
  1120. iovec[0].iov_base = (void *)&res_lib_cpg_mcast;
  1121. iovec[0].iov_len = sizeof (res_lib_cpg_mcast);
  1122. iovec[1].iov_base = (char*)message+sizeof(*req_exec_cpg_mcast);
  1123. iovec[1].iov_len = msglen;
  1124. qb_list_for_each_safe(iter, tmp_iter, &cpg_pd_list_head) {
  1125. cpd = qb_list_entry(iter, struct cpg_pd, list);
  1126. if ((cpd->cpd_state == CPD_STATE_LEAVE_STARTED || cpd->cpd_state == CPD_STATE_JOIN_COMPLETED)
  1127. && (mar_name_compare (&cpd->group_name, &req_exec_cpg_mcast->group_name) == 0)) {
  1128. if (!known_node) {
  1129. /* Try to find, if we know the node */
  1130. qb_list_for_each(pi_iter, &process_info_list_head) {
  1131. struct process_info *pi = qb_list_entry (pi_iter, struct process_info, list);
  1132. if (pi->nodeid == nodeid &&
  1133. mar_name_compare (&pi->group, &req_exec_cpg_mcast->group_name) == 0) {
  1134. known_node = 1;
  1135. break;
  1136. }
  1137. }
  1138. }
  1139. if (!known_node) {
  1140. log_printf(LOGSYS_LEVEL_WARNING, "Unknown node -> we will not deliver message");
  1141. return ;
  1142. }
  1143. api->ipc_dispatch_iov_send (cpd->conn, iovec, 2);
  1144. }
  1145. }
  1146. }
  1147. static int cpg_exec_send_downlist(void)
  1148. {
  1149. struct iovec iov;
  1150. g_req_exec_cpg_downlist.header.id = SERVICE_ID_MAKE(CPG_SERVICE, MESSAGE_REQ_EXEC_CPG_DOWNLIST);
  1151. g_req_exec_cpg_downlist.header.size = sizeof(struct req_exec_cpg_downlist);
  1152. g_req_exec_cpg_downlist.old_members = my_old_member_list_entries;
  1153. iov.iov_base = (void *)&g_req_exec_cpg_downlist;
  1154. iov.iov_len = g_req_exec_cpg_downlist.header.size;
  1155. return (api->totem_mcast (&iov, 1, TOTEM_AGREED));
  1156. }
  1157. static int cpg_exec_send_joinlist(void)
  1158. {
  1159. int count = 0;
  1160. struct qb_list_head *iter;
  1161. struct qb_ipc_response_header *res;
  1162. char *buf;
  1163. struct join_list_entry *jle;
  1164. struct iovec req_exec_cpg_iovec;
  1165. qb_list_for_each(iter, &process_info_list_head) {
  1166. struct process_info *pi = qb_list_entry (iter, struct process_info, list);
  1167. if (pi->nodeid == api->totem_nodeid_get ()) {
  1168. count++;
  1169. }
  1170. }
  1171. /* Nothing to send */
  1172. if (!count)
  1173. return 0;
  1174. buf = alloca(sizeof(struct qb_ipc_response_header) + sizeof(struct join_list_entry) * count);
  1175. if (!buf) {
  1176. log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate joinlist buffer");
  1177. return -1;
  1178. }
  1179. jle = (struct join_list_entry *)(buf + sizeof(struct qb_ipc_response_header));
  1180. res = (struct qb_ipc_response_header *)buf;
  1181. qb_list_for_each(iter, &process_info_list_head) {
  1182. struct process_info *pi = qb_list_entry (iter, struct process_info, list);
  1183. if (pi->nodeid == api->totem_nodeid_get ()) {
  1184. memcpy (&jle->group_name, &pi->group, sizeof (mar_cpg_name_t));
  1185. jle->pid = pi->pid;
  1186. jle++;
  1187. }
  1188. }
  1189. res->id = SERVICE_ID_MAKE(CPG_SERVICE, MESSAGE_REQ_EXEC_CPG_JOINLIST);
  1190. res->size = sizeof(struct qb_ipc_response_header)+sizeof(struct join_list_entry) * count;
  1191. req_exec_cpg_iovec.iov_base = buf;
  1192. req_exec_cpg_iovec.iov_len = res->size;
  1193. return (api->totem_mcast (&req_exec_cpg_iovec, 1, TOTEM_AGREED));
  1194. }
  1195. static int cpg_lib_init_fn (void *conn)
  1196. {
  1197. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1198. memset (cpd, 0, sizeof(struct cpg_pd));
  1199. cpd->conn = conn;
  1200. qb_list_add (&cpd->list, &cpg_pd_list_head);
  1201. qb_list_init (&cpd->iteration_instance_list_head);
  1202. qb_list_init (&cpd->zcb_mapped_list_head);
  1203. api->ipc_refcnt_inc (conn);
  1204. log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p, cpd=%p", conn, cpd);
  1205. return (0);
  1206. }
  1207. /* Join message from the library */
  1208. static void message_handler_req_lib_cpg_join (void *conn, const void *message)
  1209. {
  1210. const struct req_lib_cpg_join *req_lib_cpg_join = message;
  1211. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1212. struct res_lib_cpg_join res_lib_cpg_join;
  1213. cs_error_t error = CS_OK;
  1214. struct qb_list_head *iter;
  1215. /* Test, if we don't have same pid and group name joined */
  1216. qb_list_for_each(iter, &cpg_pd_list_head) {
  1217. struct cpg_pd *cpd_item = qb_list_entry (iter, struct cpg_pd, list);
  1218. if (cpd_item->pid == req_lib_cpg_join->pid &&
  1219. mar_name_compare(&req_lib_cpg_join->group_name, &cpd_item->group_name) == 0) {
  1220. /* We have same pid and group name joined -> return error */
  1221. error = CS_ERR_EXIST;
  1222. goto response_send;
  1223. }
  1224. }
  1225. /*
  1226. * Same check must be done in process info list, because there may be not yet delivered
  1227. * leave of client.
  1228. */
  1229. qb_list_for_each(iter, &process_info_list_head) {
  1230. struct process_info *pi = qb_list_entry (iter, struct process_info, list);
  1231. if (pi->nodeid == api->totem_nodeid_get () && pi->pid == req_lib_cpg_join->pid &&
  1232. mar_name_compare(&req_lib_cpg_join->group_name, &pi->group) == 0) {
  1233. /* We have same pid and group name joined -> return error */
  1234. error = CS_ERR_TRY_AGAIN;
  1235. goto response_send;
  1236. }
  1237. }
  1238. if (req_lib_cpg_join->group_name.length > CPG_MAX_NAME_LENGTH) {
  1239. error = CS_ERR_NAME_TOO_LONG;
  1240. goto response_send;
  1241. }
  1242. switch (cpd->cpd_state) {
  1243. case CPD_STATE_UNJOINED:
  1244. error = CS_OK;
  1245. cpd->cpd_state = CPD_STATE_JOIN_STARTED;
  1246. cpd->pid = req_lib_cpg_join->pid;
  1247. cpd->flags = req_lib_cpg_join->flags;
  1248. memcpy (&cpd->group_name, &req_lib_cpg_join->group_name,
  1249. sizeof (cpd->group_name));
  1250. cpg_node_joinleave_send (req_lib_cpg_join->pid,
  1251. &req_lib_cpg_join->group_name,
  1252. MESSAGE_REQ_EXEC_CPG_PROCJOIN, CONFCHG_CPG_REASON_JOIN);
  1253. break;
  1254. case CPD_STATE_LEAVE_STARTED:
  1255. error = CS_ERR_BUSY;
  1256. break;
  1257. case CPD_STATE_JOIN_STARTED:
  1258. error = CS_ERR_EXIST;
  1259. break;
  1260. case CPD_STATE_JOIN_COMPLETED:
  1261. error = CS_ERR_EXIST;
  1262. break;
  1263. }
  1264. response_send:
  1265. res_lib_cpg_join.header.size = sizeof(res_lib_cpg_join);
  1266. res_lib_cpg_join.header.id = MESSAGE_RES_CPG_JOIN;
  1267. res_lib_cpg_join.header.error = error;
  1268. api->ipc_response_send (conn, &res_lib_cpg_join, sizeof(res_lib_cpg_join));
  1269. }
  1270. /* Leave message from the library */
  1271. static void message_handler_req_lib_cpg_leave (void *conn, const void *message)
  1272. {
  1273. struct res_lib_cpg_leave res_lib_cpg_leave;
  1274. cs_error_t error = CS_OK;
  1275. struct req_lib_cpg_leave *req_lib_cpg_leave = (struct req_lib_cpg_leave *)message;
  1276. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1277. log_printf(LOGSYS_LEVEL_DEBUG, "got leave request on %p", conn);
  1278. switch (cpd->cpd_state) {
  1279. case CPD_STATE_UNJOINED:
  1280. error = CS_ERR_NOT_EXIST;
  1281. break;
  1282. case CPD_STATE_LEAVE_STARTED:
  1283. error = CS_ERR_NOT_EXIST;
  1284. break;
  1285. case CPD_STATE_JOIN_STARTED:
  1286. error = CS_ERR_BUSY;
  1287. break;
  1288. case CPD_STATE_JOIN_COMPLETED:
  1289. error = CS_OK;
  1290. cpd->cpd_state = CPD_STATE_LEAVE_STARTED;
  1291. cpg_node_joinleave_send (req_lib_cpg_leave->pid,
  1292. &req_lib_cpg_leave->group_name,
  1293. MESSAGE_REQ_EXEC_CPG_PROCLEAVE,
  1294. CONFCHG_CPG_REASON_LEAVE);
  1295. break;
  1296. }
  1297. /* send return */
  1298. res_lib_cpg_leave.header.size = sizeof(res_lib_cpg_leave);
  1299. res_lib_cpg_leave.header.id = MESSAGE_RES_CPG_LEAVE;
  1300. res_lib_cpg_leave.header.error = error;
  1301. api->ipc_response_send(conn, &res_lib_cpg_leave, sizeof(res_lib_cpg_leave));
  1302. }
  1303. /* Finalize message from library */
  1304. static void message_handler_req_lib_cpg_finalize (
  1305. void *conn,
  1306. const void *message)
  1307. {
  1308. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1309. struct res_lib_cpg_finalize res_lib_cpg_finalize;
  1310. cs_error_t error = CS_OK;
  1311. log_printf (LOGSYS_LEVEL_DEBUG, "cpg finalize for conn=%p", conn);
  1312. /*
  1313. * We will just remove cpd from list. After this call, connection will be
  1314. * closed on lib side, and cpg_lib_exit_fn will be called
  1315. */
  1316. qb_list_del (&cpd->list);
  1317. qb_list_init (&cpd->list);
  1318. res_lib_cpg_finalize.header.size = sizeof (res_lib_cpg_finalize);
  1319. res_lib_cpg_finalize.header.id = MESSAGE_RES_CPG_FINALIZE;
  1320. res_lib_cpg_finalize.header.error = error;
  1321. api->ipc_response_send (conn, &res_lib_cpg_finalize,
  1322. sizeof (res_lib_cpg_finalize));
  1323. }
  1324. static int
  1325. memory_map (
  1326. const char *path,
  1327. size_t bytes,
  1328. void **buf)
  1329. {
  1330. int32_t fd;
  1331. void *addr;
  1332. int32_t res;
  1333. fd = open (path, O_RDWR, 0600);
  1334. unlink (path);
  1335. if (fd == -1) {
  1336. return (-1);
  1337. }
  1338. res = ftruncate (fd, bytes);
  1339. if (res == -1) {
  1340. goto error_close_unlink;
  1341. }
  1342. addr = mmap (NULL, bytes, PROT_READ | PROT_WRITE,
  1343. MAP_SHARED, fd, 0);
  1344. if (addr == MAP_FAILED) {
  1345. goto error_close_unlink;
  1346. }
  1347. #ifdef MADV_NOSYNC
  1348. madvise(addr, bytes, MADV_NOSYNC);
  1349. #endif
  1350. res = close (fd);
  1351. if (res) {
  1352. munmap (addr, bytes);
  1353. return (-1);
  1354. }
  1355. *buf = addr;
  1356. return (0);
  1357. error_close_unlink:
  1358. close (fd);
  1359. unlink(path);
  1360. return -1;
  1361. }
  1362. static inline int zcb_alloc (
  1363. struct cpg_pd *cpd,
  1364. const char *path_to_file,
  1365. size_t size,
  1366. void **addr)
  1367. {
  1368. struct zcb_mapped *zcb_mapped;
  1369. unsigned int res;
  1370. zcb_mapped = malloc (sizeof (struct zcb_mapped));
  1371. if (zcb_mapped == NULL) {
  1372. return (-1);
  1373. }
  1374. res = memory_map (
  1375. path_to_file,
  1376. size,
  1377. addr);
  1378. if (res == -1) {
  1379. free (zcb_mapped);
  1380. return (-1);
  1381. }
  1382. qb_list_init (&zcb_mapped->list);
  1383. zcb_mapped->addr = *addr;
  1384. zcb_mapped->size = size;
  1385. qb_list_add_tail (&zcb_mapped->list, &cpd->zcb_mapped_list_head);
  1386. return (0);
  1387. }
  1388. static inline int zcb_free (struct zcb_mapped *zcb_mapped)
  1389. {
  1390. unsigned int res;
  1391. res = munmap (zcb_mapped->addr, zcb_mapped->size);
  1392. qb_list_del (&zcb_mapped->list);
  1393. free (zcb_mapped);
  1394. return (res);
  1395. }
  1396. static inline int zcb_by_addr_free (struct cpg_pd *cpd, void *addr)
  1397. {
  1398. struct qb_list_head *list, *tmp_iter;
  1399. struct zcb_mapped *zcb_mapped;
  1400. unsigned int res = 0;
  1401. qb_list_for_each_safe(list, tmp_iter, &(cpd->zcb_mapped_list_head)) {
  1402. zcb_mapped = qb_list_entry (list, struct zcb_mapped, list);
  1403. if (zcb_mapped->addr == addr) {
  1404. res = zcb_free (zcb_mapped);
  1405. break;
  1406. }
  1407. }
  1408. return (res);
  1409. }
  1410. static inline int zcb_all_free (
  1411. struct cpg_pd *cpd)
  1412. {
  1413. struct qb_list_head *list, *tmp_iter;
  1414. struct zcb_mapped *zcb_mapped;
  1415. qb_list_for_each_safe(list, tmp_iter, &(cpd->zcb_mapped_list_head)) {
  1416. zcb_mapped = qb_list_entry (list, struct zcb_mapped, list);
  1417. zcb_free (zcb_mapped);
  1418. }
  1419. return (0);
  1420. }
  1421. union u {
  1422. uint64_t server_addr;
  1423. void *server_ptr;
  1424. };
  1425. static uint64_t void2serveraddr (void *server_ptr)
  1426. {
  1427. union u u;
  1428. u.server_ptr = server_ptr;
  1429. return (u.server_addr);
  1430. }
  1431. static void *serveraddr2void (uint64_t server_addr)
  1432. {
  1433. union u u;
  1434. u.server_addr = server_addr;
  1435. return (u.server_ptr);
  1436. };
  1437. static void message_handler_req_lib_cpg_zc_alloc (
  1438. void *conn,
  1439. const void *message)
  1440. {
  1441. mar_req_coroipcc_zc_alloc_t *hdr = (mar_req_coroipcc_zc_alloc_t *)message;
  1442. struct qb_ipc_response_header res_header;
  1443. void *addr = NULL;
  1444. struct coroipcs_zc_header *zc_header;
  1445. unsigned int res;
  1446. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1447. log_printf(LOGSYS_LEVEL_DEBUG, "path: %s", hdr->path_to_file);
  1448. res = zcb_alloc (cpd, hdr->path_to_file, hdr->map_size,
  1449. &addr);
  1450. assert(res == 0);
  1451. zc_header = (struct coroipcs_zc_header *)addr;
  1452. zc_header->server_address = void2serveraddr(addr);
  1453. res_header.size = sizeof (struct qb_ipc_response_header);
  1454. res_header.id = 0;
  1455. api->ipc_response_send (conn,
  1456. &res_header,
  1457. res_header.size);
  1458. }
  1459. static void message_handler_req_lib_cpg_zc_free (
  1460. void *conn,
  1461. const void *message)
  1462. {
  1463. mar_req_coroipcc_zc_free_t *hdr = (mar_req_coroipcc_zc_free_t *)message;
  1464. struct qb_ipc_response_header res_header;
  1465. void *addr = NULL;
  1466. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1467. log_printf(LOGSYS_LEVEL_DEBUG, " free'ing");
  1468. addr = serveraddr2void (hdr->server_address);
  1469. zcb_by_addr_free (cpd, addr);
  1470. res_header.size = sizeof (struct qb_ipc_response_header);
  1471. res_header.id = 0;
  1472. api->ipc_response_send (
  1473. conn, &res_header,
  1474. res_header.size);
  1475. }
  1476. /* Fragmented mcast message from the library */
  1477. static void message_handler_req_lib_cpg_partial_mcast (void *conn, const void *message)
  1478. {
  1479. const struct req_lib_cpg_partial_mcast *req_lib_cpg_mcast = message;
  1480. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1481. mar_cpg_name_t group_name = cpd->group_name;
  1482. struct iovec req_exec_cpg_iovec[2];
  1483. struct req_exec_cpg_partial_mcast req_exec_cpg_mcast;
  1484. struct res_lib_cpg_partial_send res_lib_cpg_partial_send;
  1485. int msglen = req_lib_cpg_mcast->fraglen;
  1486. int result;
  1487. cs_error_t error = CS_ERR_NOT_EXIST;
  1488. log_printf(LOGSYS_LEVEL_TRACE, "got fragmented mcast request on %p", conn);
  1489. log_printf(LOGSYS_LEVEL_DEBUG, "Sending fragmented message size = %d bytes\n", msglen);
  1490. switch (cpd->cpd_state) {
  1491. case CPD_STATE_UNJOINED:
  1492. error = CS_ERR_NOT_EXIST;
  1493. break;
  1494. case CPD_STATE_LEAVE_STARTED:
  1495. error = CS_ERR_NOT_EXIST;
  1496. break;
  1497. case CPD_STATE_JOIN_STARTED:
  1498. error = CS_OK;
  1499. break;
  1500. case CPD_STATE_JOIN_COMPLETED:
  1501. error = CS_OK;
  1502. break;
  1503. }
  1504. res_lib_cpg_partial_send.header.size = sizeof(res_lib_cpg_partial_send);
  1505. res_lib_cpg_partial_send.header.id = MESSAGE_RES_CPG_PARTIAL_SEND;
  1506. if (req_lib_cpg_mcast->type == LIBCPG_PARTIAL_FIRST) {
  1507. cpd->initial_transition_counter = cpd->transition_counter;
  1508. }
  1509. if (cpd->transition_counter != cpd->initial_transition_counter) {
  1510. error = CS_ERR_INTERRUPT;
  1511. }
  1512. if (error == CS_OK) {
  1513. req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + msglen;
  1514. req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
  1515. MESSAGE_REQ_EXEC_CPG_PARTIAL_MCAST);
  1516. req_exec_cpg_mcast.pid = cpd->pid;
  1517. req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen;
  1518. req_exec_cpg_mcast.type = req_lib_cpg_mcast->type;
  1519. req_exec_cpg_mcast.fraglen = req_lib_cpg_mcast->fraglen;
  1520. api->ipc_source_set (&req_exec_cpg_mcast.source, conn);
  1521. memcpy(&req_exec_cpg_mcast.group_name, &group_name,
  1522. sizeof(mar_cpg_name_t));
  1523. req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
  1524. req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
  1525. req_exec_cpg_iovec[1].iov_base = (char *)&req_lib_cpg_mcast->message;
  1526. req_exec_cpg_iovec[1].iov_len = msglen;
  1527. result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED);
  1528. assert(result == 0);
  1529. } else {
  1530. log_printf(LOGSYS_LEVEL_ERROR, "*** %p can't mcast to group %s state:%d, error:%d",
  1531. conn, group_name.value, cpd->cpd_state, error);
  1532. }
  1533. res_lib_cpg_partial_send.header.error = error;
  1534. api->ipc_response_send (conn, &res_lib_cpg_partial_send,
  1535. sizeof (res_lib_cpg_partial_send));
  1536. }
  1537. /* Mcast message from the library */
  1538. static void message_handler_req_lib_cpg_mcast (void *conn, const void *message)
  1539. {
  1540. const struct req_lib_cpg_mcast *req_lib_cpg_mcast = message;
  1541. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1542. mar_cpg_name_t group_name = cpd->group_name;
  1543. struct iovec req_exec_cpg_iovec[2];
  1544. struct req_exec_cpg_mcast req_exec_cpg_mcast;
  1545. int msglen = req_lib_cpg_mcast->msglen;
  1546. int result;
  1547. cs_error_t error = CS_ERR_NOT_EXIST;
  1548. log_printf(LOGSYS_LEVEL_TRACE, "got mcast request on %p", conn);
  1549. switch (cpd->cpd_state) {
  1550. case CPD_STATE_UNJOINED:
  1551. error = CS_ERR_NOT_EXIST;
  1552. break;
  1553. case CPD_STATE_LEAVE_STARTED:
  1554. error = CS_ERR_NOT_EXIST;
  1555. break;
  1556. case CPD_STATE_JOIN_STARTED:
  1557. error = CS_OK;
  1558. break;
  1559. case CPD_STATE_JOIN_COMPLETED:
  1560. error = CS_OK;
  1561. break;
  1562. }
  1563. if (error == CS_OK) {
  1564. req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + msglen;
  1565. req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
  1566. MESSAGE_REQ_EXEC_CPG_MCAST);
  1567. req_exec_cpg_mcast.pid = cpd->pid;
  1568. req_exec_cpg_mcast.msglen = msglen;
  1569. api->ipc_source_set (&req_exec_cpg_mcast.source, conn);
  1570. memcpy(&req_exec_cpg_mcast.group_name, &group_name,
  1571. sizeof(mar_cpg_name_t));
  1572. req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
  1573. req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
  1574. req_exec_cpg_iovec[1].iov_base = (char *)&req_lib_cpg_mcast->message;
  1575. req_exec_cpg_iovec[1].iov_len = msglen;
  1576. result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED);
  1577. assert(result == 0);
  1578. } else {
  1579. log_printf(LOGSYS_LEVEL_ERROR, "*** %p can't mcast to group %s state:%d, error:%d",
  1580. conn, group_name.value, cpd->cpd_state, error);
  1581. }
  1582. }
  1583. static void message_handler_req_lib_cpg_zc_execute (
  1584. void *conn,
  1585. const void *message)
  1586. {
  1587. mar_req_coroipcc_zc_execute_t *hdr = (mar_req_coroipcc_zc_execute_t *)message;
  1588. struct qb_ipc_request_header *header;
  1589. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  1590. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1591. struct iovec req_exec_cpg_iovec[2];
  1592. struct req_exec_cpg_mcast req_exec_cpg_mcast;
  1593. struct req_lib_cpg_mcast *req_lib_cpg_mcast;
  1594. int result;
  1595. cs_error_t error = CS_ERR_NOT_EXIST;
  1596. log_printf(LOGSYS_LEVEL_TRACE, "got ZC mcast request on %p", conn);
  1597. header = (struct qb_ipc_request_header *)(((char *)serveraddr2void(hdr->server_address) + sizeof (struct coroipcs_zc_header)));
  1598. req_lib_cpg_mcast = (struct req_lib_cpg_mcast *)header;
  1599. switch (cpd->cpd_state) {
  1600. case CPD_STATE_UNJOINED:
  1601. error = CS_ERR_NOT_EXIST;
  1602. break;
  1603. case CPD_STATE_LEAVE_STARTED:
  1604. error = CS_ERR_NOT_EXIST;
  1605. break;
  1606. case CPD_STATE_JOIN_STARTED:
  1607. error = CS_OK;
  1608. break;
  1609. case CPD_STATE_JOIN_COMPLETED:
  1610. error = CS_OK;
  1611. break;
  1612. }
  1613. res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast);
  1614. res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_MCAST;
  1615. if (error == CS_OK) {
  1616. req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + req_lib_cpg_mcast->msglen;
  1617. req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
  1618. MESSAGE_REQ_EXEC_CPG_MCAST);
  1619. req_exec_cpg_mcast.pid = cpd->pid;
  1620. req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen;
  1621. api->ipc_source_set (&req_exec_cpg_mcast.source, conn);
  1622. memcpy(&req_exec_cpg_mcast.group_name, &cpd->group_name,
  1623. sizeof(mar_cpg_name_t));
  1624. req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
  1625. req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
  1626. req_exec_cpg_iovec[1].iov_base = (char *)header + sizeof(struct req_lib_cpg_mcast);
  1627. req_exec_cpg_iovec[1].iov_len = req_exec_cpg_mcast.msglen;
  1628. result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED);
  1629. if (result == 0) {
  1630. res_lib_cpg_mcast.header.error = CS_OK;
  1631. } else {
  1632. res_lib_cpg_mcast.header.error = CS_ERR_TRY_AGAIN;
  1633. }
  1634. } else {
  1635. res_lib_cpg_mcast.header.error = error;
  1636. }
  1637. api->ipc_response_send (conn, &res_lib_cpg_mcast,
  1638. sizeof (res_lib_cpg_mcast));
  1639. }
  1640. static void message_handler_req_lib_cpg_membership (void *conn,
  1641. const void *message)
  1642. {
  1643. struct req_lib_cpg_membership_get *req_lib_cpg_membership_get =
  1644. (struct req_lib_cpg_membership_get *)message;
  1645. struct res_lib_cpg_membership_get res_lib_cpg_membership_get;
  1646. struct qb_list_head *iter;
  1647. int member_count = 0;
  1648. res_lib_cpg_membership_get.header.id = MESSAGE_RES_CPG_MEMBERSHIP;
  1649. res_lib_cpg_membership_get.header.error = CS_OK;
  1650. res_lib_cpg_membership_get.header.size =
  1651. sizeof (struct res_lib_cpg_membership_get);
  1652. qb_list_for_each(iter, &process_info_list_head) {
  1653. struct process_info *pi = qb_list_entry (iter, struct process_info, list);
  1654. if (mar_name_compare (&pi->group, &req_lib_cpg_membership_get->group_name) == 0) {
  1655. res_lib_cpg_membership_get.member_list[member_count].nodeid = pi->nodeid;
  1656. res_lib_cpg_membership_get.member_list[member_count].pid = pi->pid;
  1657. member_count += 1;
  1658. }
  1659. }
  1660. res_lib_cpg_membership_get.member_count = member_count;
  1661. api->ipc_response_send (conn, &res_lib_cpg_membership_get,
  1662. sizeof (res_lib_cpg_membership_get));
  1663. }
  1664. static void message_handler_req_lib_cpg_local_get (void *conn,
  1665. const void *message)
  1666. {
  1667. struct res_lib_cpg_local_get res_lib_cpg_local_get;
  1668. res_lib_cpg_local_get.header.size = sizeof (res_lib_cpg_local_get);
  1669. res_lib_cpg_local_get.header.id = MESSAGE_RES_CPG_LOCAL_GET;
  1670. res_lib_cpg_local_get.header.error = CS_OK;
  1671. res_lib_cpg_local_get.local_nodeid = api->totem_nodeid_get ();
  1672. api->ipc_response_send (conn, &res_lib_cpg_local_get,
  1673. sizeof (res_lib_cpg_local_get));
  1674. }
  1675. static void message_handler_req_lib_cpg_iteration_initialize (
  1676. void *conn,
  1677. const void *message)
  1678. {
  1679. const struct req_lib_cpg_iterationinitialize *req_lib_cpg_iterationinitialize = message;
  1680. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1681. hdb_handle_t cpg_iteration_handle = 0;
  1682. struct res_lib_cpg_iterationinitialize res_lib_cpg_iterationinitialize;
  1683. struct qb_list_head *iter, *iter2;
  1684. struct cpg_iteration_instance *cpg_iteration_instance;
  1685. cs_error_t error = CS_OK;
  1686. int res;
  1687. log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration initialize");
  1688. /* Because between calling this function and *next can be some operations which will
  1689. * change list, we must do full copy.
  1690. */
  1691. /*
  1692. * Create new iteration instance
  1693. */
  1694. res = hdb_handle_create (&cpg_iteration_handle_t_db, sizeof (struct cpg_iteration_instance),
  1695. &cpg_iteration_handle);
  1696. if (res != 0) {
  1697. error = CS_ERR_NO_MEMORY;
  1698. goto response_send;
  1699. }
  1700. res = hdb_handle_get (&cpg_iteration_handle_t_db, cpg_iteration_handle, (void *)&cpg_iteration_instance);
  1701. if (res != 0) {
  1702. error = CS_ERR_BAD_HANDLE;
  1703. goto error_destroy;
  1704. }
  1705. qb_list_init (&cpg_iteration_instance->items_list_head);
  1706. cpg_iteration_instance->handle = cpg_iteration_handle;
  1707. /*
  1708. * Create copy of process_info list "grouped by" group name
  1709. */
  1710. qb_list_for_each(iter, &process_info_list_head) {
  1711. struct process_info *pi = qb_list_entry (iter, struct process_info, list);
  1712. struct process_info *new_pi;
  1713. if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_NAME_ONLY) {
  1714. /*
  1715. * Try to find processed group name in our list new list
  1716. */
  1717. int found = 0;
  1718. qb_list_for_each(iter2, &(cpg_iteration_instance->items_list_head)) {
  1719. struct process_info *pi2 = qb_list_entry (iter2, struct process_info, list);
  1720. if (mar_name_compare (&pi2->group, &pi->group) == 0) {
  1721. found = 1;
  1722. break;
  1723. }
  1724. }
  1725. if (found) {
  1726. /*
  1727. * We have this name in list -> don't add
  1728. */
  1729. continue ;
  1730. }
  1731. } else if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_ONE_GROUP) {
  1732. /*
  1733. * Test pi group name with request
  1734. */
  1735. if (mar_name_compare (&pi->group, &req_lib_cpg_iterationinitialize->group_name) != 0)
  1736. /*
  1737. * Not same -> don't add
  1738. */
  1739. continue ;
  1740. }
  1741. new_pi = malloc (sizeof (struct process_info));
  1742. if (!new_pi) {
  1743. log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate process_info struct");
  1744. error = CS_ERR_NO_MEMORY;
  1745. goto error_put_destroy;
  1746. }
  1747. memcpy (new_pi, pi, sizeof (struct process_info));
  1748. qb_list_init (&new_pi->list);
  1749. if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_NAME_ONLY) {
  1750. /*
  1751. * pid and nodeid -> undefined
  1752. */
  1753. new_pi->pid = new_pi->nodeid = 0;
  1754. }
  1755. /*
  1756. * We will return list "grouped" by "group name", so try to find right place to add
  1757. */
  1758. qb_list_for_each(iter2, &(cpg_iteration_instance->items_list_head)) {
  1759. struct process_info *pi2 = qb_list_entry (iter2, struct process_info, list);
  1760. if (mar_name_compare (&pi2->group, &pi->group) == 0) {
  1761. break;
  1762. }
  1763. }
  1764. qb_list_add (&new_pi->list, iter2);
  1765. }
  1766. /*
  1767. * Now we have a full "grouped by" copy of process_info list
  1768. */
  1769. /*
  1770. * Add instance to current cpd list
  1771. */
  1772. qb_list_init (&cpg_iteration_instance->list);
  1773. qb_list_add (&cpg_iteration_instance->list, &cpd->iteration_instance_list_head);
  1774. cpg_iteration_instance->current_pointer = &cpg_iteration_instance->items_list_head;
  1775. error_put_destroy:
  1776. hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_handle);
  1777. error_destroy:
  1778. if (error != CS_OK) {
  1779. hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_handle);
  1780. }
  1781. response_send:
  1782. res_lib_cpg_iterationinitialize.header.size = sizeof (res_lib_cpg_iterationinitialize);
  1783. res_lib_cpg_iterationinitialize.header.id = MESSAGE_RES_CPG_ITERATIONINITIALIZE;
  1784. res_lib_cpg_iterationinitialize.header.error = error;
  1785. res_lib_cpg_iterationinitialize.iteration_handle = cpg_iteration_handle;
  1786. api->ipc_response_send (conn, &res_lib_cpg_iterationinitialize,
  1787. sizeof (res_lib_cpg_iterationinitialize));
  1788. }
  1789. static void message_handler_req_lib_cpg_iteration_next (
  1790. void *conn,
  1791. const void *message)
  1792. {
  1793. const struct req_lib_cpg_iterationnext *req_lib_cpg_iterationnext = message;
  1794. struct res_lib_cpg_iterationnext res_lib_cpg_iterationnext;
  1795. struct cpg_iteration_instance *cpg_iteration_instance;
  1796. cs_error_t error = CS_OK;
  1797. int res;
  1798. struct process_info *pi;
  1799. log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration next");
  1800. res = hdb_handle_get (&cpg_iteration_handle_t_db,
  1801. req_lib_cpg_iterationnext->iteration_handle,
  1802. (void *)&cpg_iteration_instance);
  1803. if (res != 0) {
  1804. error = CS_ERR_LIBRARY;
  1805. goto error_exit;
  1806. }
  1807. assert (cpg_iteration_instance);
  1808. cpg_iteration_instance->current_pointer = cpg_iteration_instance->current_pointer->next;
  1809. if (cpg_iteration_instance->current_pointer == &cpg_iteration_instance->items_list_head) {
  1810. error = CS_ERR_NO_SECTIONS;
  1811. goto error_put;
  1812. }
  1813. pi = qb_list_entry (cpg_iteration_instance->current_pointer, struct process_info, list);
  1814. /*
  1815. * Copy iteration data
  1816. */
  1817. res_lib_cpg_iterationnext.description.nodeid = pi->nodeid;
  1818. res_lib_cpg_iterationnext.description.pid = pi->pid;
  1819. memcpy (&res_lib_cpg_iterationnext.description.group,
  1820. &pi->group,
  1821. sizeof (mar_cpg_name_t));
  1822. error_put:
  1823. hdb_handle_put (&cpg_iteration_handle_t_db, req_lib_cpg_iterationnext->iteration_handle);
  1824. error_exit:
  1825. res_lib_cpg_iterationnext.header.size = sizeof (res_lib_cpg_iterationnext);
  1826. res_lib_cpg_iterationnext.header.id = MESSAGE_RES_CPG_ITERATIONNEXT;
  1827. res_lib_cpg_iterationnext.header.error = error;
  1828. api->ipc_response_send (conn, &res_lib_cpg_iterationnext,
  1829. sizeof (res_lib_cpg_iterationnext));
  1830. }
  1831. static void message_handler_req_lib_cpg_iteration_finalize (
  1832. void *conn,
  1833. const void *message)
  1834. {
  1835. const struct req_lib_cpg_iterationfinalize *req_lib_cpg_iterationfinalize = message;
  1836. struct res_lib_cpg_iterationfinalize res_lib_cpg_iterationfinalize;
  1837. struct cpg_iteration_instance *cpg_iteration_instance;
  1838. cs_error_t error = CS_OK;
  1839. int res;
  1840. log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration finalize");
  1841. res = hdb_handle_get (&cpg_iteration_handle_t_db,
  1842. req_lib_cpg_iterationfinalize->iteration_handle,
  1843. (void *)&cpg_iteration_instance);
  1844. if (res != 0) {
  1845. error = CS_ERR_LIBRARY;
  1846. goto error_exit;
  1847. }
  1848. assert (cpg_iteration_instance);
  1849. cpg_iteration_instance_finalize (cpg_iteration_instance);
  1850. hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_instance->handle);
  1851. error_exit:
  1852. res_lib_cpg_iterationfinalize.header.size = sizeof (res_lib_cpg_iterationfinalize);
  1853. res_lib_cpg_iterationfinalize.header.id = MESSAGE_RES_CPG_ITERATIONFINALIZE;
  1854. res_lib_cpg_iterationfinalize.header.error = error;
  1855. api->ipc_response_send (conn, &res_lib_cpg_iterationfinalize,
  1856. sizeof (res_lib_cpg_iterationfinalize));
  1857. }