cpg.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295
  1. /*
  2. * Copyright (c) 2006-2019 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/qbmap.h>
  55. #include <corosync/corotypes.h>
  56. #include <qb/qbipc_common.h>
  57. #include <corosync/corodefs.h>
  58. #include <corosync/list.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 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 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 list_head list;
  141. struct list_head iteration_instance_list_head;
  142. struct list_head zcb_mapped_list_head;
  143. };
  144. struct cpg_iteration_instance {
  145. hdb_handle_t handle;
  146. struct list_head list;
  147. struct list_head items_list_head; /* List of process_info */
  148. struct list_head *current_pointer;
  149. };
  150. DECLARE_HDB_DATABASE(cpg_iteration_handle_t_db,NULL);
  151. DECLARE_LIST_INIT(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 list_head list; /* on the group_info members list */
  164. };
  165. DECLARE_LIST_INIT(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 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->rep.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 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. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
  533. struct cpg_pd *cpg_pd = 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 list_head *iter;
  553. int count;
  554. struct res_lib_cpg_confchg_callback *res;
  555. mar_cpg_address_t *retgi;
  556. count = 0;
  557. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  558. struct process_info *pi = 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. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  586. struct process_info *pi=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->reason = CPG_REASON_UNDEFINED;
  599. retgi++;
  600. }
  601. }
  602. }
  603. if (left_list_entries) {
  604. memcpy (retgi, left_list, left_list_entries * sizeof(mar_cpg_address_t));
  605. retgi += left_list_entries;
  606. }
  607. if (joined_list_entries) {
  608. memcpy (retgi, joined_list, joined_list_entries * sizeof(mar_cpg_address_t));
  609. retgi += joined_list_entries;
  610. }
  611. if (conn) {
  612. api->ipc_dispatch_send (conn, buf, size);
  613. } else {
  614. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
  615. struct cpg_pd *cpd = list_entry (iter, struct cpg_pd, list);
  616. if (mar_name_compare (&cpd->group_name, group_name) == 0) {
  617. assert (joined_list_entries <= 1);
  618. if (joined_list_entries) {
  619. if (joined_list[0].pid == cpd->pid &&
  620. joined_list[0].nodeid == api->totem_nodeid_get()) {
  621. cpd->cpd_state = CPD_STATE_JOIN_COMPLETED;
  622. }
  623. }
  624. if (cpd->cpd_state == CPD_STATE_JOIN_COMPLETED ||
  625. cpd->cpd_state == CPD_STATE_LEAVE_STARTED) {
  626. api->ipc_dispatch_send (cpd->conn, buf, size);
  627. cpd->transition_counter++;
  628. }
  629. if (left_list_entries) {
  630. if (left_list[0].pid == cpd->pid &&
  631. left_list[0].nodeid == api->totem_nodeid_get() &&
  632. left_list[0].reason == CONFCHG_CPG_REASON_LEAVE) {
  633. cpd->pid = 0;
  634. memset (&cpd->group_name, 0, sizeof(cpd->group_name));
  635. cpd->cpd_state = CPD_STATE_UNJOINED;
  636. }
  637. }
  638. }
  639. }
  640. }
  641. /*
  642. * Traverse thru cpds and send totem membership for cpd, where it is not send yet
  643. */
  644. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
  645. struct cpg_pd *cpd = list_entry (iter, struct cpg_pd, list);
  646. if ((cpd->flags & CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF) && (cpd->initial_totem_conf_sent == 0)) {
  647. cpd->initial_totem_conf_sent = 1;
  648. notify_lib_totem_membership (cpd->conn, my_old_member_list_entries, my_old_member_list);
  649. }
  650. }
  651. return CS_OK;
  652. }
  653. static void downlist_log(const char *msg, struct req_exec_cpg_downlist *dl)
  654. {
  655. log_printf (LOG_DEBUG,
  656. "%s: members(old:%d left:%d)",
  657. msg,
  658. dl->old_members,
  659. dl->left_nodes);
  660. }
  661. static void downlist_inform_clients (void)
  662. {
  663. struct list_head *iter;
  664. struct process_info *left_pi;
  665. qb_map_t *group_map;
  666. struct cpg_name cpg_group;
  667. mar_cpg_name_t group;
  668. struct confchg_data{
  669. struct cpg_name cpg_group;
  670. mar_cpg_address_t left_list[CPG_MEMBERS_MAX];
  671. int left_list_entries;
  672. struct list_head list;
  673. } *pcd;
  674. qb_map_iter_t *miter;
  675. int i, size;
  676. downlist_log("my downlist", &g_req_exec_cpg_downlist);
  677. group_map = qb_skiplist_create();
  678. /*
  679. * only the cpg groups included in left nodes should receive
  680. * confchg event, so we will collect these cpg groups and
  681. * relative left_lists here.
  682. */
  683. for (iter = process_info_list_head.next; iter != &process_info_list_head; ) {
  684. struct process_info *pi = list_entry(iter, struct process_info, list);
  685. iter = iter->next;
  686. left_pi = NULL;
  687. for (i = 0; i < g_req_exec_cpg_downlist.left_nodes; i++) {
  688. if (pi->nodeid == g_req_exec_cpg_downlist.nodeids[i]) {
  689. left_pi = pi;
  690. break;
  691. }
  692. }
  693. if (left_pi) {
  694. marshall_from_mar_cpg_name_t(&cpg_group, &left_pi->group);
  695. cpg_group.value[cpg_group.length] = 0;
  696. pcd = (struct confchg_data *)qb_map_get(group_map, cpg_group.value);
  697. if (pcd == NULL) {
  698. pcd = (struct confchg_data *)calloc(1, sizeof(struct confchg_data));
  699. memcpy(&pcd->cpg_group, &cpg_group, sizeof(struct cpg_name));
  700. qb_map_put(group_map, pcd->cpg_group.value, pcd);
  701. }
  702. size = pcd->left_list_entries;
  703. pcd->left_list[size].nodeid = left_pi->nodeid;
  704. pcd->left_list[size].pid = left_pi->pid;
  705. pcd->left_list[size].reason = CONFCHG_CPG_REASON_NODEDOWN;
  706. pcd->left_list_entries++;
  707. list_del (&left_pi->list);
  708. free (left_pi);
  709. }
  710. }
  711. /* send only one confchg event per cpg group */
  712. miter = qb_map_iter_create(group_map);
  713. while (qb_map_iter_next(miter, (void **)&pcd)) {
  714. marshall_to_mar_cpg_name_t(&group, &pcd->cpg_group);
  715. log_printf (LOG_DEBUG, "left_list_entries:%d", pcd->left_list_entries);
  716. for (i=0; i<pcd->left_list_entries; i++) {
  717. log_printf (LOG_DEBUG, "left_list[%d] group:%s, ip:%s, pid:%d",
  718. i, cpg_print_group_name(&group),
  719. (char*)api->totem_ifaces_print(pcd->left_list[i].nodeid),
  720. pcd->left_list[i].pid);
  721. }
  722. /* send confchg event */
  723. notify_lib_joinlist(&group, NULL,
  724. 0, NULL,
  725. pcd->left_list_entries,
  726. pcd->left_list,
  727. MESSAGE_RES_CPG_CONFCHG_CALLBACK);
  728. free(pcd);
  729. }
  730. qb_map_iter_free(miter);
  731. qb_map_destroy(group_map);
  732. }
  733. /*
  734. * Remove processes that might have left the group while we were suspended.
  735. */
  736. static void joinlist_remove_zombie_pi_entries (void)
  737. {
  738. struct list_head *pi_iter;
  739. struct list_head *jl_iter;
  740. struct process_info *pi;
  741. struct joinlist_msg *stored_msg;
  742. int found;
  743. for (pi_iter = process_info_list_head.next; pi_iter != &process_info_list_head; ) {
  744. pi = list_entry (pi_iter, struct process_info, list);
  745. pi_iter = pi_iter->next;
  746. /*
  747. * Ignore local node
  748. */
  749. if (pi->nodeid == api->totem_nodeid_get()) {
  750. continue ;
  751. }
  752. /*
  753. * Try to find message in joinlist messages
  754. */
  755. found = 0;
  756. for (jl_iter = joinlist_messages_head.next;
  757. jl_iter != &joinlist_messages_head;
  758. jl_iter = jl_iter->next) {
  759. stored_msg = list_entry(jl_iter, struct joinlist_msg, list);
  760. if (stored_msg->sender_nodeid == api->totem_nodeid_get()) {
  761. continue ;
  762. }
  763. if (pi->nodeid == stored_msg->sender_nodeid &&
  764. pi->pid == stored_msg->pid &&
  765. mar_name_compare (&pi->group, &stored_msg->group_name) == 0) {
  766. found = 1;
  767. break ;
  768. }
  769. }
  770. if (!found) {
  771. do_proc_leave(&pi->group, pi->pid, pi->nodeid, CONFCHG_CPG_REASON_PROCDOWN);
  772. }
  773. }
  774. }
  775. static void joinlist_inform_clients (void)
  776. {
  777. struct joinlist_msg *stored_msg;
  778. struct list_head *iter;
  779. unsigned int i;
  780. i = 0;
  781. for (iter = joinlist_messages_head.next;
  782. iter != &joinlist_messages_head;
  783. iter = iter->next) {
  784. stored_msg = list_entry(iter, struct joinlist_msg, list);
  785. log_printf (LOG_DEBUG, "joinlist_messages[%u] group:%s, ip:%s, pid:%d",
  786. i++, cpg_print_group_name(&stored_msg->group_name),
  787. (char*)api->totem_ifaces_print(stored_msg->sender_nodeid),
  788. stored_msg->pid);
  789. /* Ignore our own messages */
  790. if (stored_msg->sender_nodeid == api->totem_nodeid_get()) {
  791. continue ;
  792. }
  793. do_proc_join (&stored_msg->group_name, stored_msg->pid, stored_msg->sender_nodeid,
  794. CONFCHG_CPG_REASON_NODEUP);
  795. }
  796. joinlist_remove_zombie_pi_entries ();
  797. }
  798. static void joinlist_messages_delete (void)
  799. {
  800. struct joinlist_msg *stored_msg;
  801. struct list_head *iter, *iter_next;
  802. for (iter = joinlist_messages_head.next;
  803. iter != &joinlist_messages_head;
  804. iter = iter_next) {
  805. iter_next = iter->next;
  806. stored_msg = list_entry(iter, struct joinlist_msg, list);
  807. list_del (&stored_msg->list);
  808. free (stored_msg);
  809. }
  810. list_init (&joinlist_messages_head);
  811. }
  812. static char *cpg_exec_init_fn (struct corosync_api_v1 *corosync_api)
  813. {
  814. list_init (&joinlist_messages_head);
  815. api = corosync_api;
  816. return (NULL);
  817. }
  818. static void cpg_iteration_instance_finalize (struct cpg_iteration_instance *cpg_iteration_instance)
  819. {
  820. struct list_head *iter, *iter_next;
  821. struct process_info *pi;
  822. for (iter = cpg_iteration_instance->items_list_head.next;
  823. iter != &cpg_iteration_instance->items_list_head;
  824. iter = iter_next) {
  825. iter_next = iter->next;
  826. pi = list_entry (iter, struct process_info, list);
  827. list_del (&pi->list);
  828. free (pi);
  829. }
  830. list_del (&cpg_iteration_instance->list);
  831. hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_instance->handle);
  832. }
  833. static void cpg_pd_finalize (struct cpg_pd *cpd)
  834. {
  835. struct list_head *iter, *iter_next;
  836. struct cpg_iteration_instance *cpii;
  837. zcb_all_free(cpd);
  838. for (iter = cpd->iteration_instance_list_head.next;
  839. iter != &cpd->iteration_instance_list_head;
  840. iter = iter_next) {
  841. iter_next = iter->next;
  842. cpii = list_entry (iter, struct cpg_iteration_instance, list);
  843. cpg_iteration_instance_finalize (cpii);
  844. }
  845. list_del (&cpd->list);
  846. }
  847. static int cpg_lib_exit_fn (void *conn)
  848. {
  849. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  850. log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p", conn);
  851. if (cpd->group_name.length > 0 && cpd->cpd_state != CPD_STATE_LEAVE_STARTED) {
  852. cpg_node_joinleave_send (cpd->pid, &cpd->group_name,
  853. MESSAGE_REQ_EXEC_CPG_PROCLEAVE, CONFCHG_CPG_REASON_PROCDOWN);
  854. }
  855. cpg_pd_finalize (cpd);
  856. api->ipc_refcnt_dec (conn);
  857. return (0);
  858. }
  859. static int cpg_node_joinleave_send (unsigned int pid, const mar_cpg_name_t *group_name, int fn, int reason)
  860. {
  861. struct req_exec_cpg_procjoin req_exec_cpg_procjoin;
  862. struct iovec req_exec_cpg_iovec;
  863. int result;
  864. memcpy(&req_exec_cpg_procjoin.group_name, group_name, sizeof(mar_cpg_name_t));
  865. req_exec_cpg_procjoin.pid = pid;
  866. req_exec_cpg_procjoin.reason = reason;
  867. req_exec_cpg_procjoin.header.size = sizeof(req_exec_cpg_procjoin);
  868. req_exec_cpg_procjoin.header.id = SERVICE_ID_MAKE(CPG_SERVICE, fn);
  869. req_exec_cpg_iovec.iov_base = (char *)&req_exec_cpg_procjoin;
  870. req_exec_cpg_iovec.iov_len = sizeof(req_exec_cpg_procjoin);
  871. result = api->totem_mcast (&req_exec_cpg_iovec, 1, TOTEM_AGREED);
  872. return (result);
  873. }
  874. /* Can byteswap join & leave messages */
  875. static void exec_cpg_procjoin_endian_convert (void *msg)
  876. {
  877. struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = msg;
  878. req_exec_cpg_procjoin->pid = swab32(req_exec_cpg_procjoin->pid);
  879. swab_mar_cpg_name_t (&req_exec_cpg_procjoin->group_name);
  880. req_exec_cpg_procjoin->reason = swab32(req_exec_cpg_procjoin->reason);
  881. }
  882. static void exec_cpg_joinlist_endian_convert (void *msg_v)
  883. {
  884. char *msg = msg_v;
  885. struct qb_ipc_response_header *res = (struct qb_ipc_response_header *)msg;
  886. struct join_list_entry *jle = (struct join_list_entry *)(msg + sizeof(struct qb_ipc_response_header));
  887. swab_mar_int32_t (&res->size);
  888. while ((const char*)jle < msg + res->size) {
  889. jle->pid = swab32(jle->pid);
  890. swab_mar_cpg_name_t (&jle->group_name);
  891. jle++;
  892. }
  893. }
  894. static void exec_cpg_downlist_endian_convert_old (void *msg)
  895. {
  896. }
  897. static void exec_cpg_downlist_endian_convert (void *msg)
  898. {
  899. struct req_exec_cpg_downlist *req_exec_cpg_downlist = msg;
  900. unsigned int i;
  901. req_exec_cpg_downlist->left_nodes = swab32(req_exec_cpg_downlist->left_nodes);
  902. req_exec_cpg_downlist->old_members = swab32(req_exec_cpg_downlist->old_members);
  903. for (i = 0; i < req_exec_cpg_downlist->left_nodes; i++) {
  904. req_exec_cpg_downlist->nodeids[i] = swab32(req_exec_cpg_downlist->nodeids[i]);
  905. }
  906. }
  907. static void exec_cpg_mcast_endian_convert (void *msg)
  908. {
  909. struct req_exec_cpg_mcast *req_exec_cpg_mcast = msg;
  910. swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
  911. swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
  912. req_exec_cpg_mcast->pid = swab32(req_exec_cpg_mcast->pid);
  913. req_exec_cpg_mcast->msglen = swab32(req_exec_cpg_mcast->msglen);
  914. swab_mar_message_source_t (&req_exec_cpg_mcast->source);
  915. }
  916. static void exec_cpg_partial_mcast_endian_convert (void *msg)
  917. {
  918. struct req_exec_cpg_partial_mcast *req_exec_cpg_mcast = msg;
  919. swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
  920. swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
  921. req_exec_cpg_mcast->pid = swab32(req_exec_cpg_mcast->pid);
  922. req_exec_cpg_mcast->msglen = swab32(req_exec_cpg_mcast->msglen);
  923. req_exec_cpg_mcast->fraglen = swab32(req_exec_cpg_mcast->fraglen);
  924. req_exec_cpg_mcast->type = swab32(req_exec_cpg_mcast->type);
  925. swab_mar_message_source_t (&req_exec_cpg_mcast->source);
  926. }
  927. static struct process_info *process_info_find(const mar_cpg_name_t *group_name, uint32_t pid, unsigned int nodeid) {
  928. struct list_head *iter;
  929. for (iter = process_info_list_head.next; iter != &process_info_list_head; ) {
  930. struct process_info *pi = list_entry (iter, struct process_info, list);
  931. iter = iter->next;
  932. if (pi->pid == pid && pi->nodeid == nodeid &&
  933. mar_name_compare (&pi->group, group_name) == 0) {
  934. return pi;
  935. }
  936. }
  937. return NULL;
  938. }
  939. static void do_proc_join(
  940. const mar_cpg_name_t *name,
  941. uint32_t pid,
  942. unsigned int nodeid,
  943. int reason)
  944. {
  945. struct process_info *pi;
  946. struct process_info *pi_entry;
  947. mar_cpg_address_t notify_info;
  948. struct list_head *list;
  949. struct list_head *list_to_add = NULL;
  950. if (process_info_find (name, pid, nodeid) != NULL) {
  951. return ;
  952. }
  953. pi = malloc (sizeof (struct process_info));
  954. if (!pi) {
  955. log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate process_info struct");
  956. return;
  957. }
  958. pi->nodeid = nodeid;
  959. pi->pid = pid;
  960. memcpy(&pi->group, name, sizeof(*name));
  961. list_init(&pi->list);
  962. /*
  963. * Insert new process in sorted order so synchronization works properly
  964. */
  965. list_to_add = &process_info_list_head;
  966. for (list = process_info_list_head.next; list != &process_info_list_head; list = list->next) {
  967. pi_entry = list_entry(list, struct process_info, list);
  968. if (pi_entry->nodeid > pi->nodeid ||
  969. (pi_entry->nodeid == pi->nodeid && pi_entry->pid > pi->pid)) {
  970. break;
  971. }
  972. list_to_add = list;
  973. }
  974. list_add (&pi->list, list_to_add);
  975. notify_info.pid = pi->pid;
  976. notify_info.nodeid = nodeid;
  977. notify_info.reason = reason;
  978. notify_lib_joinlist(&pi->group, NULL,
  979. 1, &notify_info,
  980. 0, NULL,
  981. MESSAGE_RES_CPG_CONFCHG_CALLBACK);
  982. }
  983. static void do_proc_leave(
  984. const mar_cpg_name_t *name,
  985. uint32_t pid,
  986. unsigned int nodeid,
  987. int reason)
  988. {
  989. struct process_info *pi;
  990. struct list_head *iter;
  991. mar_cpg_address_t notify_info;
  992. notify_info.pid = pid;
  993. notify_info.nodeid = nodeid;
  994. notify_info.reason = reason;
  995. notify_lib_joinlist(name, NULL,
  996. 0, NULL,
  997. 1, &notify_info,
  998. MESSAGE_RES_CPG_CONFCHG_CALLBACK);
  999. for (iter = process_info_list_head.next; iter != &process_info_list_head; ) {
  1000. pi = list_entry(iter, struct process_info, list);
  1001. iter = iter->next;
  1002. if (pi->pid == pid && pi->nodeid == nodeid &&
  1003. mar_name_compare (&pi->group, name)==0) {
  1004. list_del (&pi->list);
  1005. free (pi);
  1006. }
  1007. }
  1008. }
  1009. static void message_handler_req_exec_cpg_downlist_old (
  1010. const void *message,
  1011. unsigned int nodeid)
  1012. {
  1013. log_printf (LOGSYS_LEVEL_WARNING, "downlist OLD from node 0x%x",
  1014. nodeid);
  1015. }
  1016. static void message_handler_req_exec_cpg_downlist(
  1017. const void *message,
  1018. unsigned int nodeid)
  1019. {
  1020. const struct req_exec_cpg_downlist *req_exec_cpg_downlist = message;
  1021. log_printf (LOGSYS_LEVEL_WARNING, "downlist left_list: %d received",
  1022. req_exec_cpg_downlist->left_nodes);
  1023. }
  1024. static void message_handler_req_exec_cpg_procjoin (
  1025. const void *message,
  1026. unsigned int nodeid)
  1027. {
  1028. const struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = message;
  1029. log_printf(LOGSYS_LEVEL_DEBUG, "got procjoin message from cluster node 0x%x (%s) for pid %u",
  1030. nodeid,
  1031. api->totem_ifaces_print(nodeid),
  1032. (unsigned int)req_exec_cpg_procjoin->pid);
  1033. do_proc_join (&req_exec_cpg_procjoin->group_name,
  1034. req_exec_cpg_procjoin->pid, nodeid,
  1035. CONFCHG_CPG_REASON_JOIN);
  1036. }
  1037. static void message_handler_req_exec_cpg_procleave (
  1038. const void *message,
  1039. unsigned int nodeid)
  1040. {
  1041. const struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = message;
  1042. log_printf(LOGSYS_LEVEL_DEBUG, "got procleave message from cluster node 0x%x (%s) for pid %u",
  1043. nodeid,
  1044. api->totem_ifaces_print(nodeid),
  1045. (unsigned int)req_exec_cpg_procjoin->pid);
  1046. do_proc_leave (&req_exec_cpg_procjoin->group_name,
  1047. req_exec_cpg_procjoin->pid, nodeid,
  1048. req_exec_cpg_procjoin->reason);
  1049. }
  1050. /* Got a proclist from another node */
  1051. static void message_handler_req_exec_cpg_joinlist (
  1052. const void *message_v,
  1053. unsigned int nodeid)
  1054. {
  1055. const char *message = message_v;
  1056. const struct qb_ipc_response_header *res = (const struct qb_ipc_response_header *)message;
  1057. const struct join_list_entry *jle = (const struct join_list_entry *)(message + sizeof(struct qb_ipc_response_header));
  1058. struct joinlist_msg *stored_msg;
  1059. log_printf(LOGSYS_LEVEL_DEBUG, "got joinlist message from node 0x%x",
  1060. nodeid);
  1061. while ((const char*)jle < message + res->size) {
  1062. stored_msg = malloc (sizeof (struct joinlist_msg));
  1063. memset(stored_msg, 0, sizeof (struct joinlist_msg));
  1064. stored_msg->sender_nodeid = nodeid;
  1065. stored_msg->pid = jle->pid;
  1066. memcpy(&stored_msg->group_name, &jle->group_name, sizeof(mar_cpg_name_t));
  1067. list_init (&stored_msg->list);
  1068. list_add (&stored_msg->list, &joinlist_messages_head);
  1069. jle++;
  1070. }
  1071. }
  1072. static void message_handler_req_exec_cpg_mcast (
  1073. const void *message,
  1074. unsigned int nodeid)
  1075. {
  1076. const struct req_exec_cpg_mcast *req_exec_cpg_mcast = message;
  1077. struct res_lib_cpg_deliver_callback res_lib_cpg_mcast;
  1078. int msglen = req_exec_cpg_mcast->msglen;
  1079. struct list_head *iter, *pi_iter;
  1080. struct cpg_pd *cpd;
  1081. struct iovec iovec[2];
  1082. int known_node = 0;
  1083. res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_DELIVER_CALLBACK;
  1084. res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast) + msglen;
  1085. res_lib_cpg_mcast.msglen = msglen;
  1086. res_lib_cpg_mcast.pid = req_exec_cpg_mcast->pid;
  1087. res_lib_cpg_mcast.nodeid = nodeid;
  1088. memcpy(&res_lib_cpg_mcast.group_name, &req_exec_cpg_mcast->group_name,
  1089. sizeof(mar_cpg_name_t));
  1090. iovec[0].iov_base = (void *)&res_lib_cpg_mcast;
  1091. iovec[0].iov_len = sizeof (res_lib_cpg_mcast);
  1092. iovec[1].iov_base = (char*)message+sizeof(*req_exec_cpg_mcast);
  1093. iovec[1].iov_len = msglen;
  1094. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; ) {
  1095. cpd = list_entry(iter, struct cpg_pd, list);
  1096. iter = iter->next;
  1097. if ((cpd->cpd_state == CPD_STATE_LEAVE_STARTED || cpd->cpd_state == CPD_STATE_JOIN_COMPLETED)
  1098. && (mar_name_compare (&cpd->group_name, &req_exec_cpg_mcast->group_name) == 0)) {
  1099. if (!known_node) {
  1100. /* Try to find, if we know the node */
  1101. for (pi_iter = process_info_list_head.next;
  1102. pi_iter != &process_info_list_head; pi_iter = pi_iter->next) {
  1103. struct process_info *pi = list_entry (pi_iter, struct process_info, list);
  1104. if (pi->nodeid == nodeid &&
  1105. mar_name_compare (&pi->group, &req_exec_cpg_mcast->group_name) == 0) {
  1106. known_node = 1;
  1107. break;
  1108. }
  1109. }
  1110. }
  1111. if (!known_node) {
  1112. log_printf(LOGSYS_LEVEL_WARNING, "Unknown node -> we will not deliver message");
  1113. return ;
  1114. }
  1115. api->ipc_dispatch_iov_send (cpd->conn, iovec, 2);
  1116. }
  1117. }
  1118. }
  1119. static void message_handler_req_exec_cpg_partial_mcast (
  1120. const void *message,
  1121. unsigned int nodeid)
  1122. {
  1123. const struct req_exec_cpg_partial_mcast *req_exec_cpg_mcast = message;
  1124. struct res_lib_cpg_partial_deliver_callback res_lib_cpg_mcast;
  1125. int msglen = req_exec_cpg_mcast->fraglen;
  1126. struct list_head *iter, *pi_iter;
  1127. struct cpg_pd *cpd;
  1128. struct iovec iovec[2];
  1129. int known_node = 0;
  1130. log_printf(LOGSYS_LEVEL_DEBUG, "Got fragmented message from node %d, size = %d bytes\n", nodeid, msglen);
  1131. res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_PARTIAL_DELIVER_CALLBACK;
  1132. res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast) + msglen;
  1133. res_lib_cpg_mcast.fraglen = msglen;
  1134. res_lib_cpg_mcast.msglen = req_exec_cpg_mcast->msglen;
  1135. res_lib_cpg_mcast.pid = req_exec_cpg_mcast->pid;
  1136. res_lib_cpg_mcast.type = req_exec_cpg_mcast->type;
  1137. res_lib_cpg_mcast.nodeid = nodeid;
  1138. memcpy(&res_lib_cpg_mcast.group_name, &req_exec_cpg_mcast->group_name,
  1139. sizeof(mar_cpg_name_t));
  1140. iovec[0].iov_base = (void *)&res_lib_cpg_mcast;
  1141. iovec[0].iov_len = sizeof (res_lib_cpg_mcast);
  1142. iovec[1].iov_base = (char*)message+sizeof(*req_exec_cpg_mcast);
  1143. iovec[1].iov_len = msglen;
  1144. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; ) {
  1145. cpd = list_entry(iter, struct cpg_pd, list);
  1146. iter = iter->next;
  1147. if ((cpd->cpd_state == CPD_STATE_LEAVE_STARTED || cpd->cpd_state == CPD_STATE_JOIN_COMPLETED)
  1148. && (mar_name_compare (&cpd->group_name, &req_exec_cpg_mcast->group_name) == 0)) {
  1149. if (!known_node) {
  1150. /* Try to find, if we know the node */
  1151. for (pi_iter = process_info_list_head.next;
  1152. pi_iter != &process_info_list_head; pi_iter = pi_iter->next) {
  1153. struct process_info *pi = list_entry (pi_iter, struct process_info, list);
  1154. if (pi->nodeid == nodeid &&
  1155. mar_name_compare (&pi->group, &req_exec_cpg_mcast->group_name) == 0) {
  1156. known_node = 1;
  1157. break;
  1158. }
  1159. }
  1160. }
  1161. if (!known_node) {
  1162. log_printf(LOGSYS_LEVEL_WARNING, "Unknown node -> we will not deliver message");
  1163. return ;
  1164. }
  1165. api->ipc_dispatch_iov_send (cpd->conn, iovec, 2);
  1166. }
  1167. }
  1168. }
  1169. static int cpg_exec_send_downlist(void)
  1170. {
  1171. struct iovec iov;
  1172. g_req_exec_cpg_downlist.header.id = SERVICE_ID_MAKE(CPG_SERVICE, MESSAGE_REQ_EXEC_CPG_DOWNLIST);
  1173. g_req_exec_cpg_downlist.header.size = sizeof(struct req_exec_cpg_downlist);
  1174. g_req_exec_cpg_downlist.old_members = my_old_member_list_entries;
  1175. iov.iov_base = (void *)&g_req_exec_cpg_downlist;
  1176. iov.iov_len = g_req_exec_cpg_downlist.header.size;
  1177. return (api->totem_mcast (&iov, 1, TOTEM_AGREED));
  1178. }
  1179. static int cpg_exec_send_joinlist(void)
  1180. {
  1181. int count = 0;
  1182. struct list_head *iter;
  1183. struct qb_ipc_response_header *res;
  1184. char *buf;
  1185. struct join_list_entry *jle;
  1186. struct iovec req_exec_cpg_iovec;
  1187. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  1188. struct process_info *pi = list_entry (iter, struct process_info, list);
  1189. if (pi->nodeid == api->totem_nodeid_get ()) {
  1190. count++;
  1191. }
  1192. }
  1193. /* Nothing to send */
  1194. if (!count)
  1195. return 0;
  1196. buf = alloca(sizeof(struct qb_ipc_response_header) + sizeof(struct join_list_entry) * count);
  1197. if (!buf) {
  1198. log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate joinlist buffer");
  1199. return -1;
  1200. }
  1201. jle = (struct join_list_entry *)(buf + sizeof(struct qb_ipc_response_header));
  1202. res = (struct qb_ipc_response_header *)buf;
  1203. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  1204. struct process_info *pi = list_entry (iter, struct process_info, list);
  1205. if (pi->nodeid == api->totem_nodeid_get ()) {
  1206. memcpy (&jle->group_name, &pi->group, sizeof (mar_cpg_name_t));
  1207. jle->pid = pi->pid;
  1208. jle++;
  1209. }
  1210. }
  1211. res->id = SERVICE_ID_MAKE(CPG_SERVICE, MESSAGE_REQ_EXEC_CPG_JOINLIST);
  1212. res->size = sizeof(struct qb_ipc_response_header)+sizeof(struct join_list_entry) * count;
  1213. req_exec_cpg_iovec.iov_base = buf;
  1214. req_exec_cpg_iovec.iov_len = res->size;
  1215. return (api->totem_mcast (&req_exec_cpg_iovec, 1, TOTEM_AGREED));
  1216. }
  1217. static int cpg_lib_init_fn (void *conn)
  1218. {
  1219. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1220. memset (cpd, 0, sizeof(struct cpg_pd));
  1221. cpd->conn = conn;
  1222. list_add (&cpd->list, &cpg_pd_list_head);
  1223. list_init (&cpd->iteration_instance_list_head);
  1224. list_init (&cpd->zcb_mapped_list_head);
  1225. api->ipc_refcnt_inc (conn);
  1226. log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p, cpd=%p", conn, cpd);
  1227. return (0);
  1228. }
  1229. /* Join message from the library */
  1230. static void message_handler_req_lib_cpg_join (void *conn, const void *message)
  1231. {
  1232. const struct req_lib_cpg_join *req_lib_cpg_join = message;
  1233. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1234. struct res_lib_cpg_join res_lib_cpg_join;
  1235. cs_error_t error = CS_OK;
  1236. struct list_head *iter;
  1237. /* Test, if we don't have same pid and group name joined */
  1238. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
  1239. struct cpg_pd *cpd_item = list_entry (iter, struct cpg_pd, list);
  1240. if (cpd_item->pid == req_lib_cpg_join->pid &&
  1241. mar_name_compare(&req_lib_cpg_join->group_name, &cpd_item->group_name) == 0) {
  1242. /* We have same pid and group name joined -> return error */
  1243. error = CS_ERR_EXIST;
  1244. goto response_send;
  1245. }
  1246. }
  1247. /*
  1248. * Same check must be done in process info list, because there may be not yet delivered
  1249. * leave of client.
  1250. */
  1251. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  1252. struct process_info *pi = list_entry (iter, struct process_info, list);
  1253. if (pi->nodeid == api->totem_nodeid_get () && pi->pid == req_lib_cpg_join->pid &&
  1254. mar_name_compare(&req_lib_cpg_join->group_name, &pi->group) == 0) {
  1255. /* We have same pid and group name joined -> return error */
  1256. error = CS_ERR_TRY_AGAIN;
  1257. goto response_send;
  1258. }
  1259. }
  1260. if (req_lib_cpg_join->group_name.length > CPG_MAX_NAME_LENGTH) {
  1261. error = CS_ERR_NAME_TOO_LONG;
  1262. goto response_send;
  1263. }
  1264. switch (cpd->cpd_state) {
  1265. case CPD_STATE_UNJOINED:
  1266. error = CS_OK;
  1267. cpd->cpd_state = CPD_STATE_JOIN_STARTED;
  1268. cpd->pid = req_lib_cpg_join->pid;
  1269. cpd->flags = req_lib_cpg_join->flags;
  1270. memcpy (&cpd->group_name, &req_lib_cpg_join->group_name,
  1271. sizeof (cpd->group_name));
  1272. cpg_node_joinleave_send (req_lib_cpg_join->pid,
  1273. &req_lib_cpg_join->group_name,
  1274. MESSAGE_REQ_EXEC_CPG_PROCJOIN, CONFCHG_CPG_REASON_JOIN);
  1275. break;
  1276. case CPD_STATE_LEAVE_STARTED:
  1277. error = CS_ERR_BUSY;
  1278. break;
  1279. case CPD_STATE_JOIN_STARTED:
  1280. error = CS_ERR_EXIST;
  1281. break;
  1282. case CPD_STATE_JOIN_COMPLETED:
  1283. error = CS_ERR_EXIST;
  1284. break;
  1285. }
  1286. response_send:
  1287. res_lib_cpg_join.header.size = sizeof(res_lib_cpg_join);
  1288. res_lib_cpg_join.header.id = MESSAGE_RES_CPG_JOIN;
  1289. res_lib_cpg_join.header.error = error;
  1290. api->ipc_response_send (conn, &res_lib_cpg_join, sizeof(res_lib_cpg_join));
  1291. }
  1292. /* Leave message from the library */
  1293. static void message_handler_req_lib_cpg_leave (void *conn, const void *message)
  1294. {
  1295. struct res_lib_cpg_leave res_lib_cpg_leave;
  1296. cs_error_t error = CS_OK;
  1297. struct req_lib_cpg_leave *req_lib_cpg_leave = (struct req_lib_cpg_leave *)message;
  1298. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1299. log_printf(LOGSYS_LEVEL_DEBUG, "got leave request on %p", conn);
  1300. switch (cpd->cpd_state) {
  1301. case CPD_STATE_UNJOINED:
  1302. error = CS_ERR_NOT_EXIST;
  1303. break;
  1304. case CPD_STATE_LEAVE_STARTED:
  1305. error = CS_ERR_NOT_EXIST;
  1306. break;
  1307. case CPD_STATE_JOIN_STARTED:
  1308. error = CS_ERR_BUSY;
  1309. break;
  1310. case CPD_STATE_JOIN_COMPLETED:
  1311. error = CS_OK;
  1312. cpd->cpd_state = CPD_STATE_LEAVE_STARTED;
  1313. cpg_node_joinleave_send (req_lib_cpg_leave->pid,
  1314. &req_lib_cpg_leave->group_name,
  1315. MESSAGE_REQ_EXEC_CPG_PROCLEAVE,
  1316. CONFCHG_CPG_REASON_LEAVE);
  1317. break;
  1318. }
  1319. /* send return */
  1320. res_lib_cpg_leave.header.size = sizeof(res_lib_cpg_leave);
  1321. res_lib_cpg_leave.header.id = MESSAGE_RES_CPG_LEAVE;
  1322. res_lib_cpg_leave.header.error = error;
  1323. api->ipc_response_send(conn, &res_lib_cpg_leave, sizeof(res_lib_cpg_leave));
  1324. }
  1325. /* Finalize message from library */
  1326. static void message_handler_req_lib_cpg_finalize (
  1327. void *conn,
  1328. const void *message)
  1329. {
  1330. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1331. struct res_lib_cpg_finalize res_lib_cpg_finalize;
  1332. cs_error_t error = CS_OK;
  1333. log_printf (LOGSYS_LEVEL_DEBUG, "cpg finalize for conn=%p", conn);
  1334. /*
  1335. * We will just remove cpd from list. After this call, connection will be
  1336. * closed on lib side, and cpg_lib_exit_fn will be called
  1337. */
  1338. list_del (&cpd->list);
  1339. list_init (&cpd->list);
  1340. res_lib_cpg_finalize.header.size = sizeof (res_lib_cpg_finalize);
  1341. res_lib_cpg_finalize.header.id = MESSAGE_RES_CPG_FINALIZE;
  1342. res_lib_cpg_finalize.header.error = error;
  1343. api->ipc_response_send (conn, &res_lib_cpg_finalize,
  1344. sizeof (res_lib_cpg_finalize));
  1345. }
  1346. static int
  1347. memory_map (
  1348. const char *path,
  1349. size_t bytes,
  1350. void **buf)
  1351. {
  1352. int32_t fd;
  1353. void *addr;
  1354. int32_t res;
  1355. fd = open (path, O_RDWR, 0600);
  1356. unlink (path);
  1357. if (fd == -1) {
  1358. return (-1);
  1359. }
  1360. res = ftruncate (fd, bytes);
  1361. if (res == -1) {
  1362. goto error_close_unlink;
  1363. }
  1364. addr = mmap (NULL, bytes, PROT_READ | PROT_WRITE,
  1365. MAP_SHARED, fd, 0);
  1366. if (addr == MAP_FAILED) {
  1367. goto error_close_unlink;
  1368. }
  1369. #ifdef MADV_NOSYNC
  1370. madvise(addr, bytes, MADV_NOSYNC);
  1371. #endif
  1372. res = close (fd);
  1373. if (res) {
  1374. munmap (addr, bytes);
  1375. return (-1);
  1376. }
  1377. *buf = addr;
  1378. return (0);
  1379. error_close_unlink:
  1380. close (fd);
  1381. unlink(path);
  1382. return -1;
  1383. }
  1384. static inline int zcb_alloc (
  1385. struct cpg_pd *cpd,
  1386. const char *path_to_file,
  1387. size_t size,
  1388. void **addr)
  1389. {
  1390. struct zcb_mapped *zcb_mapped;
  1391. unsigned int res;
  1392. zcb_mapped = malloc (sizeof (struct zcb_mapped));
  1393. if (zcb_mapped == NULL) {
  1394. return (-1);
  1395. }
  1396. res = memory_map (
  1397. path_to_file,
  1398. size,
  1399. addr);
  1400. if (res == -1) {
  1401. free (zcb_mapped);
  1402. return (-1);
  1403. }
  1404. list_init (&zcb_mapped->list);
  1405. zcb_mapped->addr = *addr;
  1406. zcb_mapped->size = size;
  1407. list_add_tail (&zcb_mapped->list, &cpd->zcb_mapped_list_head);
  1408. return (0);
  1409. }
  1410. static inline int zcb_free (struct zcb_mapped *zcb_mapped)
  1411. {
  1412. unsigned int res;
  1413. res = munmap (zcb_mapped->addr, zcb_mapped->size);
  1414. list_del (&zcb_mapped->list);
  1415. free (zcb_mapped);
  1416. return (res);
  1417. }
  1418. static inline int zcb_by_addr_free (struct cpg_pd *cpd, void *addr)
  1419. {
  1420. struct list_head *list;
  1421. struct zcb_mapped *zcb_mapped;
  1422. unsigned int res = 0;
  1423. for (list = cpd->zcb_mapped_list_head.next;
  1424. list != &cpd->zcb_mapped_list_head; list = list->next) {
  1425. zcb_mapped = list_entry (list, struct zcb_mapped, list);
  1426. if (zcb_mapped->addr == addr) {
  1427. res = zcb_free (zcb_mapped);
  1428. break;
  1429. }
  1430. }
  1431. return (res);
  1432. }
  1433. static inline int zcb_all_free (
  1434. struct cpg_pd *cpd)
  1435. {
  1436. struct list_head *list;
  1437. struct zcb_mapped *zcb_mapped;
  1438. for (list = cpd->zcb_mapped_list_head.next;
  1439. list != &cpd->zcb_mapped_list_head;) {
  1440. zcb_mapped = list_entry (list, struct zcb_mapped, list);
  1441. list = list->next;
  1442. zcb_free (zcb_mapped);
  1443. }
  1444. return (0);
  1445. }
  1446. union u {
  1447. uint64_t server_addr;
  1448. void *server_ptr;
  1449. };
  1450. static uint64_t void2serveraddr (void *server_ptr)
  1451. {
  1452. union u u;
  1453. u.server_ptr = server_ptr;
  1454. return (u.server_addr);
  1455. }
  1456. static void *serveraddr2void (uint64_t server_addr)
  1457. {
  1458. union u u;
  1459. u.server_addr = server_addr;
  1460. return (u.server_ptr);
  1461. };
  1462. static void message_handler_req_lib_cpg_zc_alloc (
  1463. void *conn,
  1464. const void *message)
  1465. {
  1466. mar_req_coroipcc_zc_alloc_t *hdr = (mar_req_coroipcc_zc_alloc_t *)message;
  1467. struct qb_ipc_response_header res_header;
  1468. void *addr = NULL;
  1469. struct coroipcs_zc_header *zc_header;
  1470. unsigned int res;
  1471. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1472. log_printf(LOGSYS_LEVEL_DEBUG, "path: %s", hdr->path_to_file);
  1473. res = zcb_alloc (cpd, hdr->path_to_file, hdr->map_size,
  1474. &addr);
  1475. assert(res == 0);
  1476. zc_header = (struct coroipcs_zc_header *)addr;
  1477. zc_header->server_address = void2serveraddr(addr);
  1478. res_header.size = sizeof (struct qb_ipc_response_header);
  1479. res_header.id = 0;
  1480. api->ipc_response_send (conn,
  1481. &res_header,
  1482. res_header.size);
  1483. }
  1484. static void message_handler_req_lib_cpg_zc_free (
  1485. void *conn,
  1486. const void *message)
  1487. {
  1488. mar_req_coroipcc_zc_free_t *hdr = (mar_req_coroipcc_zc_free_t *)message;
  1489. struct qb_ipc_response_header res_header;
  1490. void *addr = NULL;
  1491. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1492. log_printf(LOGSYS_LEVEL_DEBUG, " free'ing");
  1493. addr = serveraddr2void (hdr->server_address);
  1494. zcb_by_addr_free (cpd, addr);
  1495. res_header.size = sizeof (struct qb_ipc_response_header);
  1496. res_header.id = 0;
  1497. api->ipc_response_send (
  1498. conn, &res_header,
  1499. res_header.size);
  1500. }
  1501. /* Fragmented mcast message from the library */
  1502. static void message_handler_req_lib_cpg_partial_mcast (void *conn, const void *message)
  1503. {
  1504. const struct req_lib_cpg_partial_mcast *req_lib_cpg_mcast = message;
  1505. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1506. mar_cpg_name_t group_name = cpd->group_name;
  1507. struct iovec req_exec_cpg_iovec[2];
  1508. struct req_exec_cpg_partial_mcast req_exec_cpg_mcast;
  1509. struct res_lib_cpg_partial_send res_lib_cpg_partial_send;
  1510. int msglen = req_lib_cpg_mcast->fraglen;
  1511. int result;
  1512. cs_error_t error = CS_ERR_NOT_EXIST;
  1513. log_printf(LOGSYS_LEVEL_TRACE, "got fragmented mcast request on %p", conn);
  1514. log_printf(LOGSYS_LEVEL_DEBUG, "Sending fragmented message size = %d bytes\n", msglen);
  1515. switch (cpd->cpd_state) {
  1516. case CPD_STATE_UNJOINED:
  1517. error = CS_ERR_NOT_EXIST;
  1518. break;
  1519. case CPD_STATE_LEAVE_STARTED:
  1520. error = CS_ERR_NOT_EXIST;
  1521. break;
  1522. case CPD_STATE_JOIN_STARTED:
  1523. error = CS_OK;
  1524. break;
  1525. case CPD_STATE_JOIN_COMPLETED:
  1526. error = CS_OK;
  1527. break;
  1528. }
  1529. res_lib_cpg_partial_send.header.size = sizeof(res_lib_cpg_partial_send);
  1530. res_lib_cpg_partial_send.header.id = MESSAGE_RES_CPG_PARTIAL_SEND;
  1531. if (req_lib_cpg_mcast->type == LIBCPG_PARTIAL_FIRST) {
  1532. cpd->initial_transition_counter = cpd->transition_counter;
  1533. }
  1534. if (cpd->transition_counter != cpd->initial_transition_counter) {
  1535. error = CS_ERR_INTERRUPT;
  1536. }
  1537. if (error == CS_OK) {
  1538. req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + msglen;
  1539. req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
  1540. MESSAGE_REQ_EXEC_CPG_PARTIAL_MCAST);
  1541. req_exec_cpg_mcast.pid = cpd->pid;
  1542. req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen;
  1543. req_exec_cpg_mcast.type = req_lib_cpg_mcast->type;
  1544. req_exec_cpg_mcast.fraglen = req_lib_cpg_mcast->fraglen;
  1545. api->ipc_source_set (&req_exec_cpg_mcast.source, conn);
  1546. memcpy(&req_exec_cpg_mcast.group_name, &group_name,
  1547. sizeof(mar_cpg_name_t));
  1548. req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
  1549. req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
  1550. req_exec_cpg_iovec[1].iov_base = (char *)&req_lib_cpg_mcast->message;
  1551. req_exec_cpg_iovec[1].iov_len = msglen;
  1552. result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED);
  1553. assert(result == 0);
  1554. } else {
  1555. log_printf(LOGSYS_LEVEL_ERROR, "*** %p can't mcast to group %s state:%d, error:%d",
  1556. conn, group_name.value, cpd->cpd_state, error);
  1557. }
  1558. res_lib_cpg_partial_send.header.error = error;
  1559. api->ipc_response_send (conn, &res_lib_cpg_partial_send,
  1560. sizeof (res_lib_cpg_partial_send));
  1561. }
  1562. /* Mcast message from the library */
  1563. static void message_handler_req_lib_cpg_mcast (void *conn, const void *message)
  1564. {
  1565. const struct req_lib_cpg_mcast *req_lib_cpg_mcast = message;
  1566. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1567. mar_cpg_name_t group_name = cpd->group_name;
  1568. struct iovec req_exec_cpg_iovec[2];
  1569. struct req_exec_cpg_mcast req_exec_cpg_mcast;
  1570. int msglen = req_lib_cpg_mcast->msglen;
  1571. int result;
  1572. cs_error_t error = CS_ERR_NOT_EXIST;
  1573. log_printf(LOGSYS_LEVEL_TRACE, "got mcast request on %p", conn);
  1574. switch (cpd->cpd_state) {
  1575. case CPD_STATE_UNJOINED:
  1576. error = CS_ERR_NOT_EXIST;
  1577. break;
  1578. case CPD_STATE_LEAVE_STARTED:
  1579. error = CS_ERR_NOT_EXIST;
  1580. break;
  1581. case CPD_STATE_JOIN_STARTED:
  1582. error = CS_OK;
  1583. break;
  1584. case CPD_STATE_JOIN_COMPLETED:
  1585. error = CS_OK;
  1586. break;
  1587. }
  1588. if (error == CS_OK) {
  1589. req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + msglen;
  1590. req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
  1591. MESSAGE_REQ_EXEC_CPG_MCAST);
  1592. req_exec_cpg_mcast.pid = cpd->pid;
  1593. req_exec_cpg_mcast.msglen = msglen;
  1594. api->ipc_source_set (&req_exec_cpg_mcast.source, conn);
  1595. memcpy(&req_exec_cpg_mcast.group_name, &group_name,
  1596. sizeof(mar_cpg_name_t));
  1597. req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
  1598. req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
  1599. req_exec_cpg_iovec[1].iov_base = (char *)&req_lib_cpg_mcast->message;
  1600. req_exec_cpg_iovec[1].iov_len = msglen;
  1601. result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED);
  1602. assert(result == 0);
  1603. } else {
  1604. log_printf(LOGSYS_LEVEL_ERROR, "*** %p can't mcast to group %s state:%d, error:%d",
  1605. conn, group_name.value, cpd->cpd_state, error);
  1606. }
  1607. }
  1608. static void message_handler_req_lib_cpg_zc_execute (
  1609. void *conn,
  1610. const void *message)
  1611. {
  1612. mar_req_coroipcc_zc_execute_t *hdr = (mar_req_coroipcc_zc_execute_t *)message;
  1613. struct qb_ipc_request_header *header;
  1614. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  1615. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1616. struct iovec req_exec_cpg_iovec[2];
  1617. struct req_exec_cpg_mcast req_exec_cpg_mcast;
  1618. struct req_lib_cpg_mcast *req_lib_cpg_mcast;
  1619. int result;
  1620. cs_error_t error = CS_ERR_NOT_EXIST;
  1621. log_printf(LOGSYS_LEVEL_TRACE, "got ZC mcast request on %p", conn);
  1622. header = (struct qb_ipc_request_header *)(((char *)serveraddr2void(hdr->server_address) + sizeof (struct coroipcs_zc_header)));
  1623. req_lib_cpg_mcast = (struct req_lib_cpg_mcast *)header;
  1624. switch (cpd->cpd_state) {
  1625. case CPD_STATE_UNJOINED:
  1626. error = CS_ERR_NOT_EXIST;
  1627. break;
  1628. case CPD_STATE_LEAVE_STARTED:
  1629. error = CS_ERR_NOT_EXIST;
  1630. break;
  1631. case CPD_STATE_JOIN_STARTED:
  1632. error = CS_OK;
  1633. break;
  1634. case CPD_STATE_JOIN_COMPLETED:
  1635. error = CS_OK;
  1636. break;
  1637. }
  1638. res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast);
  1639. res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_MCAST;
  1640. if (error == CS_OK) {
  1641. req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + req_lib_cpg_mcast->msglen;
  1642. req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
  1643. MESSAGE_REQ_EXEC_CPG_MCAST);
  1644. req_exec_cpg_mcast.pid = cpd->pid;
  1645. req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen;
  1646. api->ipc_source_set (&req_exec_cpg_mcast.source, conn);
  1647. memcpy(&req_exec_cpg_mcast.group_name, &cpd->group_name,
  1648. sizeof(mar_cpg_name_t));
  1649. req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
  1650. req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
  1651. req_exec_cpg_iovec[1].iov_base = (char *)header + sizeof(struct req_lib_cpg_mcast);
  1652. req_exec_cpg_iovec[1].iov_len = req_exec_cpg_mcast.msglen;
  1653. result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED);
  1654. if (result == 0) {
  1655. res_lib_cpg_mcast.header.error = CS_OK;
  1656. } else {
  1657. res_lib_cpg_mcast.header.error = CS_ERR_TRY_AGAIN;
  1658. }
  1659. } else {
  1660. res_lib_cpg_mcast.header.error = error;
  1661. }
  1662. api->ipc_response_send (conn, &res_lib_cpg_mcast,
  1663. sizeof (res_lib_cpg_mcast));
  1664. }
  1665. static void message_handler_req_lib_cpg_membership (void *conn,
  1666. const void *message)
  1667. {
  1668. struct req_lib_cpg_membership_get *req_lib_cpg_membership_get =
  1669. (struct req_lib_cpg_membership_get *)message;
  1670. struct res_lib_cpg_membership_get res_lib_cpg_membership_get;
  1671. struct list_head *iter;
  1672. int member_count = 0;
  1673. res_lib_cpg_membership_get.header.id = MESSAGE_RES_CPG_MEMBERSHIP;
  1674. res_lib_cpg_membership_get.header.error = CS_OK;
  1675. res_lib_cpg_membership_get.header.size =
  1676. sizeof (struct res_lib_cpg_membership_get);
  1677. for (iter = process_info_list_head.next;
  1678. iter != &process_info_list_head; iter = iter->next) {
  1679. struct process_info *pi = list_entry (iter, struct process_info, list);
  1680. if (mar_name_compare (&pi->group, &req_lib_cpg_membership_get->group_name) == 0) {
  1681. res_lib_cpg_membership_get.member_list[member_count].nodeid = pi->nodeid;
  1682. res_lib_cpg_membership_get.member_list[member_count].pid = pi->pid;
  1683. member_count += 1;
  1684. }
  1685. }
  1686. res_lib_cpg_membership_get.member_count = member_count;
  1687. api->ipc_response_send (conn, &res_lib_cpg_membership_get,
  1688. sizeof (res_lib_cpg_membership_get));
  1689. }
  1690. static void message_handler_req_lib_cpg_local_get (void *conn,
  1691. const void *message)
  1692. {
  1693. struct res_lib_cpg_local_get res_lib_cpg_local_get;
  1694. res_lib_cpg_local_get.header.size = sizeof (res_lib_cpg_local_get);
  1695. res_lib_cpg_local_get.header.id = MESSAGE_RES_CPG_LOCAL_GET;
  1696. res_lib_cpg_local_get.header.error = CS_OK;
  1697. res_lib_cpg_local_get.local_nodeid = api->totem_nodeid_get ();
  1698. api->ipc_response_send (conn, &res_lib_cpg_local_get,
  1699. sizeof (res_lib_cpg_local_get));
  1700. }
  1701. static void message_handler_req_lib_cpg_iteration_initialize (
  1702. void *conn,
  1703. const void *message)
  1704. {
  1705. const struct req_lib_cpg_iterationinitialize *req_lib_cpg_iterationinitialize = message;
  1706. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1707. hdb_handle_t cpg_iteration_handle = 0;
  1708. struct res_lib_cpg_iterationinitialize res_lib_cpg_iterationinitialize;
  1709. struct list_head *iter, *iter2;
  1710. struct cpg_iteration_instance *cpg_iteration_instance;
  1711. cs_error_t error = CS_OK;
  1712. int res;
  1713. log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration initialize");
  1714. /* Because between calling this function and *next can be some operations which will
  1715. * change list, we must do full copy.
  1716. */
  1717. /*
  1718. * Create new iteration instance
  1719. */
  1720. res = hdb_handle_create (&cpg_iteration_handle_t_db, sizeof (struct cpg_iteration_instance),
  1721. &cpg_iteration_handle);
  1722. if (res != 0) {
  1723. error = CS_ERR_NO_MEMORY;
  1724. goto response_send;
  1725. }
  1726. res = hdb_handle_get (&cpg_iteration_handle_t_db, cpg_iteration_handle, (void *)&cpg_iteration_instance);
  1727. if (res != 0) {
  1728. error = CS_ERR_BAD_HANDLE;
  1729. goto error_destroy;
  1730. }
  1731. list_init (&cpg_iteration_instance->items_list_head);
  1732. cpg_iteration_instance->handle = cpg_iteration_handle;
  1733. /*
  1734. * Create copy of process_info list "grouped by" group name
  1735. */
  1736. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  1737. struct process_info *pi = list_entry (iter, struct process_info, list);
  1738. struct process_info *new_pi;
  1739. if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_NAME_ONLY) {
  1740. /*
  1741. * Try to find processed group name in our list new list
  1742. */
  1743. int found = 0;
  1744. for (iter2 = cpg_iteration_instance->items_list_head.next;
  1745. iter2 != &cpg_iteration_instance->items_list_head;
  1746. iter2 = iter2->next) {
  1747. struct process_info *pi2 = list_entry (iter2, struct process_info, list);
  1748. if (mar_name_compare (&pi2->group, &pi->group) == 0) {
  1749. found = 1;
  1750. break;
  1751. }
  1752. }
  1753. if (found) {
  1754. /*
  1755. * We have this name in list -> don't add
  1756. */
  1757. continue ;
  1758. }
  1759. } else if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_ONE_GROUP) {
  1760. /*
  1761. * Test pi group name with request
  1762. */
  1763. if (mar_name_compare (&pi->group, &req_lib_cpg_iterationinitialize->group_name) != 0)
  1764. /*
  1765. * Not same -> don't add
  1766. */
  1767. continue ;
  1768. }
  1769. new_pi = malloc (sizeof (struct process_info));
  1770. if (!new_pi) {
  1771. log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate process_info struct");
  1772. error = CS_ERR_NO_MEMORY;
  1773. goto error_put_destroy;
  1774. }
  1775. memcpy (new_pi, pi, sizeof (struct process_info));
  1776. list_init (&new_pi->list);
  1777. if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_NAME_ONLY) {
  1778. /*
  1779. * pid and nodeid -> undefined
  1780. */
  1781. new_pi->pid = new_pi->nodeid = 0;
  1782. }
  1783. /*
  1784. * We will return list "grouped" by "group name", so try to find right place to add
  1785. */
  1786. for (iter2 = cpg_iteration_instance->items_list_head.next;
  1787. iter2 != &cpg_iteration_instance->items_list_head;
  1788. iter2 = iter2->next) {
  1789. struct process_info *pi2 = list_entry (iter2, struct process_info, list);
  1790. if (mar_name_compare (&pi2->group, &pi->group) == 0) {
  1791. break;
  1792. }
  1793. }
  1794. list_add (&new_pi->list, iter2);
  1795. }
  1796. /*
  1797. * Now we have a full "grouped by" copy of process_info list
  1798. */
  1799. /*
  1800. * Add instance to current cpd list
  1801. */
  1802. list_init (&cpg_iteration_instance->list);
  1803. list_add (&cpg_iteration_instance->list, &cpd->iteration_instance_list_head);
  1804. cpg_iteration_instance->current_pointer = &cpg_iteration_instance->items_list_head;
  1805. error_put_destroy:
  1806. hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_handle);
  1807. error_destroy:
  1808. if (error != CS_OK) {
  1809. hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_handle);
  1810. }
  1811. response_send:
  1812. res_lib_cpg_iterationinitialize.header.size = sizeof (res_lib_cpg_iterationinitialize);
  1813. res_lib_cpg_iterationinitialize.header.id = MESSAGE_RES_CPG_ITERATIONINITIALIZE;
  1814. res_lib_cpg_iterationinitialize.header.error = error;
  1815. res_lib_cpg_iterationinitialize.iteration_handle = cpg_iteration_handle;
  1816. api->ipc_response_send (conn, &res_lib_cpg_iterationinitialize,
  1817. sizeof (res_lib_cpg_iterationinitialize));
  1818. }
  1819. static void message_handler_req_lib_cpg_iteration_next (
  1820. void *conn,
  1821. const void *message)
  1822. {
  1823. const struct req_lib_cpg_iterationnext *req_lib_cpg_iterationnext = message;
  1824. struct res_lib_cpg_iterationnext res_lib_cpg_iterationnext;
  1825. struct cpg_iteration_instance *cpg_iteration_instance;
  1826. cs_error_t error = CS_OK;
  1827. int res;
  1828. struct process_info *pi;
  1829. log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration next");
  1830. res = hdb_handle_get (&cpg_iteration_handle_t_db,
  1831. req_lib_cpg_iterationnext->iteration_handle,
  1832. (void *)&cpg_iteration_instance);
  1833. if (res != 0) {
  1834. error = CS_ERR_LIBRARY;
  1835. goto error_exit;
  1836. }
  1837. assert (cpg_iteration_instance);
  1838. cpg_iteration_instance->current_pointer = cpg_iteration_instance->current_pointer->next;
  1839. if (cpg_iteration_instance->current_pointer == &cpg_iteration_instance->items_list_head) {
  1840. error = CS_ERR_NO_SECTIONS;
  1841. goto error_put;
  1842. }
  1843. pi = list_entry (cpg_iteration_instance->current_pointer, struct process_info, list);
  1844. /*
  1845. * Copy iteration data
  1846. */
  1847. res_lib_cpg_iterationnext.description.nodeid = pi->nodeid;
  1848. res_lib_cpg_iterationnext.description.pid = pi->pid;
  1849. memcpy (&res_lib_cpg_iterationnext.description.group,
  1850. &pi->group,
  1851. sizeof (mar_cpg_name_t));
  1852. error_put:
  1853. hdb_handle_put (&cpg_iteration_handle_t_db, req_lib_cpg_iterationnext->iteration_handle);
  1854. error_exit:
  1855. res_lib_cpg_iterationnext.header.size = sizeof (res_lib_cpg_iterationnext);
  1856. res_lib_cpg_iterationnext.header.id = MESSAGE_RES_CPG_ITERATIONNEXT;
  1857. res_lib_cpg_iterationnext.header.error = error;
  1858. api->ipc_response_send (conn, &res_lib_cpg_iterationnext,
  1859. sizeof (res_lib_cpg_iterationnext));
  1860. }
  1861. static void message_handler_req_lib_cpg_iteration_finalize (
  1862. void *conn,
  1863. const void *message)
  1864. {
  1865. const struct req_lib_cpg_iterationfinalize *req_lib_cpg_iterationfinalize = message;
  1866. struct res_lib_cpg_iterationfinalize res_lib_cpg_iterationfinalize;
  1867. struct cpg_iteration_instance *cpg_iteration_instance;
  1868. cs_error_t error = CS_OK;
  1869. int res;
  1870. log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration finalize");
  1871. res = hdb_handle_get (&cpg_iteration_handle_t_db,
  1872. req_lib_cpg_iterationfinalize->iteration_handle,
  1873. (void *)&cpg_iteration_instance);
  1874. if (res != 0) {
  1875. error = CS_ERR_LIBRARY;
  1876. goto error_exit;
  1877. }
  1878. assert (cpg_iteration_instance);
  1879. cpg_iteration_instance_finalize (cpg_iteration_instance);
  1880. hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_instance->handle);
  1881. error_exit:
  1882. res_lib_cpg_iterationfinalize.header.size = sizeof (res_lib_cpg_iterationfinalize);
  1883. res_lib_cpg_iterationfinalize.header.id = MESSAGE_RES_CPG_ITERATIONFINALIZE;
  1884. res_lib_cpg_iterationfinalize.header.error = error;
  1885. api->ipc_response_send (conn, &res_lib_cpg_iterationfinalize,
  1886. sizeof (res_lib_cpg_iterationfinalize));
  1887. }