cpg.c 63 KB

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