4
0

cpg.c 63 KB

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