4
0

cpg.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. /*
  2. * Copyright (c) 2006-2009 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 <unistd.h>
  52. #include <netinet/in.h>
  53. #include <arpa/inet.h>
  54. #include <corosync/corotypes.h>
  55. #include <corosync/coroipc_types.h>
  56. #include <corosync/corodefs.h>
  57. #include <corosync/list.h>
  58. #include <corosync/jhash.h>
  59. #include <corosync/lcr/lcr_comp.h>
  60. #include <corosync/engine/logsys.h>
  61. #include <corosync/engine/coroapi.h>
  62. #include <corosync/cpg.h>
  63. #include <corosync/ipc_cpg.h>
  64. LOGSYS_DECLARE_SUBSYS ("CPG");
  65. #define GROUP_HASH_SIZE 32
  66. enum cpg_message_req_types {
  67. MESSAGE_REQ_EXEC_CPG_PROCJOIN = 0,
  68. MESSAGE_REQ_EXEC_CPG_PROCLEAVE = 1,
  69. MESSAGE_REQ_EXEC_CPG_JOINLIST = 2,
  70. MESSAGE_REQ_EXEC_CPG_MCAST = 3,
  71. MESSAGE_REQ_EXEC_CPG_DOWNLIST_OLD = 4,
  72. MESSAGE_REQ_EXEC_CPG_DOWNLIST = 5
  73. };
  74. /*
  75. * state` exec deliver
  76. * match group name, pid -> if matched deliver for YES:
  77. * XXX indicates impossible state
  78. *
  79. * join leave mcast
  80. * UNJOINED XXX XXX NO
  81. * LEAVE_STARTED XXX YES(unjoined_enter) YES
  82. * JOIN_STARTED YES(join_started_enter) XXX NO
  83. * JOIN_COMPLETED XXX NO YES
  84. *
  85. * join_started_enter
  86. * set JOIN_COMPLETED
  87. * add entry to process_info list
  88. * unjoined_enter
  89. * set UNJOINED
  90. * delete entry from process_info list
  91. *
  92. *
  93. * library accept join error codes
  94. * UNJOINED YES(CPG_OK) set JOIN_STARTED
  95. * LEAVE_STARTED NO(CPG_ERR_BUSY)
  96. * JOIN_STARTED NO(CPG_ERR_EXIST)
  97. * JOIN_COMPlETED NO(CPG_ERR_EXIST)
  98. *
  99. * library accept leave error codes
  100. * UNJOINED NO(CPG_ERR_NOT_EXIST)
  101. * LEAVE_STARTED NO(CPG_ERR_NOT_EXIST)
  102. * JOIN_STARTED NO(CPG_ERR_BUSY)
  103. * JOIN_COMPLETED YES(CPG_OK) set LEAVE_STARTED
  104. *
  105. * library accept mcast
  106. * UNJOINED NO(CPG_ERR_NOT_EXIST)
  107. * LEAVE_STARTED NO(CPG_ERR_NOT_EXIST)
  108. * JOIN_STARTED YES(CPG_OK)
  109. * JOIN_COMPLETED YES(CPG_OK)
  110. */
  111. enum cpd_state {
  112. CPD_STATE_UNJOINED,
  113. CPD_STATE_LEAVE_STARTED,
  114. CPD_STATE_JOIN_STARTED,
  115. CPD_STATE_JOIN_COMPLETED
  116. };
  117. enum cpg_sync_state {
  118. CPGSYNC_DOWNLIST,
  119. CPGSYNC_JOINLIST
  120. };
  121. enum cpg_downlist_state_e {
  122. CPG_DOWNLIST_NONE,
  123. CPG_DOWNLIST_WAITING_FOR_MESSAGES,
  124. CPG_DOWNLIST_APPLYING,
  125. };
  126. static enum cpg_downlist_state_e downlist_state;
  127. static struct list_head downlist_messages_head;
  128. struct cpg_pd {
  129. void *conn;
  130. mar_cpg_name_t group_name;
  131. uint32_t pid;
  132. enum cpd_state cpd_state;
  133. unsigned int flags;
  134. int initial_totem_conf_sent;
  135. struct list_head list;
  136. struct list_head iteration_instance_list_head;
  137. };
  138. struct cpg_iteration_instance {
  139. hdb_handle_t handle;
  140. struct list_head list;
  141. struct list_head items_list_head; /* List of process_info */
  142. struct list_head *current_pointer;
  143. };
  144. DECLARE_HDB_DATABASE(cpg_iteration_handle_t_db,NULL);
  145. DECLARE_LIST_INIT(cpg_pd_list_head);
  146. static unsigned int my_member_list[PROCESSOR_COUNT_MAX];
  147. static unsigned int my_member_list_entries;
  148. static unsigned int my_old_member_list[PROCESSOR_COUNT_MAX];
  149. static unsigned int my_old_member_list_entries = 0;
  150. static struct corosync_api_v1 *api = NULL;
  151. static enum cpg_sync_state my_sync_state = CPGSYNC_DOWNLIST;
  152. static mar_cpg_ring_id_t last_sync_ring_id;
  153. struct process_info {
  154. unsigned int nodeid;
  155. uint32_t pid;
  156. mar_cpg_name_t group;
  157. struct list_head list; /* on the group_info members list */
  158. };
  159. DECLARE_LIST_INIT(process_info_list_head);
  160. struct join_list_entry {
  161. uint32_t pid;
  162. mar_cpg_name_t group_name;
  163. };
  164. /*
  165. * Service Interfaces required by service_message_handler struct
  166. */
  167. static int cpg_exec_init_fn (struct corosync_api_v1 *);
  168. static int cpg_lib_init_fn (void *conn);
  169. static int cpg_lib_exit_fn (void *conn);
  170. static void message_handler_req_exec_cpg_procjoin (
  171. const void *message,
  172. unsigned int nodeid);
  173. static void message_handler_req_exec_cpg_procleave (
  174. const void *message,
  175. unsigned int nodeid);
  176. static void message_handler_req_exec_cpg_joinlist (
  177. const void *message,
  178. unsigned int nodeid);
  179. static void message_handler_req_exec_cpg_mcast (
  180. const void *message,
  181. unsigned int nodeid);
  182. static void message_handler_req_exec_cpg_downlist_old (
  183. const void *message,
  184. unsigned int nodeid);
  185. static void message_handler_req_exec_cpg_downlist (
  186. const void *message,
  187. unsigned int nodeid);
  188. static void exec_cpg_procjoin_endian_convert (void *msg);
  189. static void exec_cpg_joinlist_endian_convert (void *msg);
  190. static void exec_cpg_mcast_endian_convert (void *msg);
  191. static void exec_cpg_downlist_endian_convert_old (void *msg);
  192. static void exec_cpg_downlist_endian_convert (void *msg);
  193. static void message_handler_req_lib_cpg_join (void *conn, const void *message);
  194. static void message_handler_req_lib_cpg_leave (void *conn, const void *message);
  195. static void message_handler_req_lib_cpg_finalize (void *conn, const void *message);
  196. static void message_handler_req_lib_cpg_mcast (void *conn, const void *message);
  197. static void message_handler_req_lib_cpg_membership (void *conn,
  198. const void *message);
  199. static void message_handler_req_lib_cpg_local_get (void *conn,
  200. const void *message);
  201. static void message_handler_req_lib_cpg_iteration_initialize (
  202. void *conn,
  203. const void *message);
  204. static void message_handler_req_lib_cpg_iteration_next (
  205. void *conn,
  206. const void *message);
  207. static void message_handler_req_lib_cpg_iteration_finalize (
  208. void *conn,
  209. const void *message);
  210. static int cpg_node_joinleave_send (unsigned int pid, const mar_cpg_name_t *group_name, int fn, int reason);
  211. static int cpg_exec_send_downlist(void);
  212. static int cpg_exec_send_joinlist(void);
  213. static void downlist_messages_delete (void);
  214. static void downlist_master_choose_and_send (void);
  215. static void cpg_sync_init_v2 (
  216. const unsigned int *trans_list,
  217. size_t trans_list_entries,
  218. const unsigned int *member_list,
  219. size_t member_list_entries,
  220. const struct memb_ring_id *ring_id);
  221. static int cpg_sync_process (void);
  222. static void cpg_sync_activate (void);
  223. static void cpg_sync_abort (void);
  224. static int notify_lib_totem_membership (
  225. void *conn,
  226. int member_list_entries,
  227. const unsigned int *member_list);
  228. /*
  229. * Library Handler Definition
  230. */
  231. static struct corosync_lib_handler cpg_lib_engine[] =
  232. {
  233. { /* 0 */
  234. .lib_handler_fn = message_handler_req_lib_cpg_join,
  235. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  236. },
  237. { /* 1 */
  238. .lib_handler_fn = message_handler_req_lib_cpg_leave,
  239. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  240. },
  241. { /* 2 */
  242. .lib_handler_fn = message_handler_req_lib_cpg_mcast,
  243. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  244. },
  245. { /* 3 */
  246. .lib_handler_fn = message_handler_req_lib_cpg_membership,
  247. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  248. },
  249. { /* 4 */
  250. .lib_handler_fn = message_handler_req_lib_cpg_local_get,
  251. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  252. },
  253. { /* 5 */
  254. .lib_handler_fn = message_handler_req_lib_cpg_iteration_initialize,
  255. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  256. },
  257. { /* 6 */
  258. .lib_handler_fn = message_handler_req_lib_cpg_iteration_next,
  259. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  260. },
  261. { /* 7 */
  262. .lib_handler_fn = message_handler_req_lib_cpg_iteration_finalize,
  263. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  264. },
  265. { /* 8 */
  266. .lib_handler_fn = message_handler_req_lib_cpg_finalize,
  267. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  268. },
  269. };
  270. static struct corosync_exec_handler cpg_exec_engine[] =
  271. {
  272. { /* 0 */
  273. .exec_handler_fn = message_handler_req_exec_cpg_procjoin,
  274. .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
  275. },
  276. { /* 1 */
  277. .exec_handler_fn = message_handler_req_exec_cpg_procleave,
  278. .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
  279. },
  280. { /* 2 */
  281. .exec_handler_fn = message_handler_req_exec_cpg_joinlist,
  282. .exec_endian_convert_fn = exec_cpg_joinlist_endian_convert
  283. },
  284. { /* 3 */
  285. .exec_handler_fn = message_handler_req_exec_cpg_mcast,
  286. .exec_endian_convert_fn = exec_cpg_mcast_endian_convert
  287. },
  288. { /* 4 */
  289. .exec_handler_fn = message_handler_req_exec_cpg_downlist_old,
  290. .exec_endian_convert_fn = exec_cpg_downlist_endian_convert_old
  291. },
  292. { /* 5 */
  293. .exec_handler_fn = message_handler_req_exec_cpg_downlist,
  294. .exec_endian_convert_fn = exec_cpg_downlist_endian_convert
  295. },
  296. };
  297. struct corosync_service_engine cpg_service_engine = {
  298. .name = "corosync cluster closed process group service v1.01",
  299. .id = CPG_SERVICE,
  300. .priority = 1,
  301. .private_data_size = sizeof (struct cpg_pd),
  302. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED,
  303. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  304. .lib_init_fn = cpg_lib_init_fn,
  305. .lib_exit_fn = cpg_lib_exit_fn,
  306. .lib_engine = cpg_lib_engine,
  307. .lib_engine_count = sizeof (cpg_lib_engine) / sizeof (struct corosync_lib_handler),
  308. .exec_init_fn = cpg_exec_init_fn,
  309. .exec_dump_fn = NULL,
  310. .exec_engine = cpg_exec_engine,
  311. .exec_engine_count = sizeof (cpg_exec_engine) / sizeof (struct corosync_exec_handler),
  312. .sync_mode = CS_SYNC_V1_APIV2,
  313. .sync_init = (sync_init_v1_fn_t)cpg_sync_init_v2,
  314. .sync_process = cpg_sync_process,
  315. .sync_activate = cpg_sync_activate,
  316. .sync_abort = cpg_sync_abort
  317. };
  318. /*
  319. * Dynamic loader definition
  320. */
  321. static struct corosync_service_engine *cpg_get_service_engine_ver0 (void);
  322. static struct corosync_service_engine_iface_ver0 cpg_service_engine_iface = {
  323. .corosync_get_service_engine_ver0 = cpg_get_service_engine_ver0
  324. };
  325. static struct lcr_iface corosync_cpg_ver0[1] = {
  326. {
  327. .name = "corosync_cpg",
  328. .version = 0,
  329. .versions_replace = 0,
  330. .versions_replace_count = 0,
  331. .dependencies = 0,
  332. .dependency_count = 0,
  333. .constructor = NULL,
  334. .destructor = NULL,
  335. .interfaces = NULL
  336. }
  337. };
  338. static struct lcr_comp cpg_comp_ver0 = {
  339. .iface_count = 1,
  340. .ifaces = corosync_cpg_ver0
  341. };
  342. static struct corosync_service_engine *cpg_get_service_engine_ver0 (void)
  343. {
  344. return (&cpg_service_engine);
  345. }
  346. #ifdef COROSYNC_SOLARIS
  347. void corosync_lcr_component_register (void);
  348. void corosync_lcr_component_register (void) {
  349. #else
  350. __attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
  351. #endif
  352. lcr_interfaces_set (&corosync_cpg_ver0[0], &cpg_service_engine_iface);
  353. lcr_component_register (&cpg_comp_ver0);
  354. }
  355. struct req_exec_cpg_procjoin {
  356. coroipc_request_header_t header __attribute__((aligned(8)));
  357. mar_cpg_name_t group_name __attribute__((aligned(8)));
  358. mar_uint32_t pid __attribute__((aligned(8)));
  359. mar_uint32_t reason __attribute__((aligned(8)));
  360. };
  361. struct req_exec_cpg_mcast {
  362. coroipc_request_header_t header __attribute__((aligned(8)));
  363. mar_cpg_name_t group_name __attribute__((aligned(8)));
  364. mar_uint32_t msglen __attribute__((aligned(8)));
  365. mar_uint32_t pid __attribute__((aligned(8)));
  366. mar_message_source_t source __attribute__((aligned(8)));
  367. mar_uint8_t message[] __attribute__((aligned(8)));
  368. };
  369. struct req_exec_cpg_downlist_old {
  370. coroipc_request_header_t header __attribute__((aligned(8)));
  371. mar_uint32_t left_nodes __attribute__((aligned(8)));
  372. mar_uint32_t nodeids[PROCESSOR_COUNT_MAX] __attribute__((aligned(8)));
  373. };
  374. struct req_exec_cpg_downlist {
  375. coroipc_request_header_t header __attribute__((aligned(8)));
  376. /* merge decisions */
  377. mar_uint32_t old_members __attribute__((aligned(8)));
  378. /* downlist below */
  379. mar_uint32_t left_nodes __attribute__((aligned(8)));
  380. mar_uint32_t nodeids[PROCESSOR_COUNT_MAX] __attribute__((aligned(8)));
  381. };
  382. struct downlist_msg {
  383. mar_uint32_t sender_nodeid;
  384. mar_uint32_t old_members __attribute__((aligned(8)));
  385. mar_uint32_t left_nodes __attribute__((aligned(8)));
  386. mar_uint32_t nodeids[PROCESSOR_COUNT_MAX] __attribute__((aligned(8)));
  387. struct list_head list;
  388. };
  389. static struct req_exec_cpg_downlist g_req_exec_cpg_downlist;
  390. static void cpg_sync_init_v2 (
  391. const unsigned int *trans_list,
  392. size_t trans_list_entries,
  393. const unsigned int *member_list,
  394. size_t member_list_entries,
  395. const struct memb_ring_id *ring_id)
  396. {
  397. int entries;
  398. int i, j;
  399. int found;
  400. my_sync_state = CPGSYNC_DOWNLIST;
  401. memcpy (my_member_list, member_list, member_list_entries *
  402. sizeof (unsigned int));
  403. my_member_list_entries = member_list_entries;
  404. last_sync_ring_id.nodeid = ring_id->rep.nodeid;
  405. last_sync_ring_id.seq = ring_id->seq;
  406. downlist_state = CPG_DOWNLIST_WAITING_FOR_MESSAGES;
  407. entries = 0;
  408. /*
  409. * Determine list of nodeids for downlist message
  410. */
  411. for (i = 0; i < my_old_member_list_entries; i++) {
  412. found = 0;
  413. for (j = 0; j < trans_list_entries; j++) {
  414. if (my_old_member_list[i] == trans_list[j]) {
  415. found = 1;
  416. break;
  417. }
  418. }
  419. if (found == 0) {
  420. g_req_exec_cpg_downlist.nodeids[entries++] =
  421. my_old_member_list[i];
  422. }
  423. }
  424. g_req_exec_cpg_downlist.left_nodes = entries;
  425. }
  426. static int cpg_sync_process (void)
  427. {
  428. int res = -1;
  429. if (my_sync_state == CPGSYNC_DOWNLIST) {
  430. res = cpg_exec_send_downlist();
  431. if (res == -1) {
  432. return (-1);
  433. }
  434. my_sync_state = CPGSYNC_JOINLIST;
  435. }
  436. if (my_sync_state == CPGSYNC_JOINLIST) {
  437. res = cpg_exec_send_joinlist();
  438. }
  439. return (res);
  440. }
  441. static void cpg_sync_activate (void)
  442. {
  443. memcpy (my_old_member_list, my_member_list,
  444. my_member_list_entries * sizeof (unsigned int));
  445. my_old_member_list_entries = my_member_list_entries;
  446. if (downlist_state == CPG_DOWNLIST_WAITING_FOR_MESSAGES) {
  447. downlist_master_choose_and_send ();
  448. }
  449. downlist_messages_delete ();
  450. downlist_state = CPG_DOWNLIST_NONE;
  451. notify_lib_totem_membership (NULL, my_member_list_entries, my_member_list);
  452. }
  453. static void cpg_sync_abort (void)
  454. {
  455. downlist_state = CPG_DOWNLIST_NONE;
  456. downlist_messages_delete ();
  457. }
  458. static int notify_lib_totem_membership (
  459. void *conn,
  460. int member_list_entries,
  461. const unsigned int *member_list)
  462. {
  463. struct list_head *iter;
  464. char *buf;
  465. int size;
  466. struct res_lib_cpg_totem_confchg_callback *res;
  467. size = sizeof(struct res_lib_cpg_totem_confchg_callback) +
  468. sizeof(mar_uint32_t) * (member_list_entries);
  469. buf = alloca(size);
  470. if (!buf)
  471. return CPG_ERR_LIBRARY;
  472. res = (struct res_lib_cpg_totem_confchg_callback *)buf;
  473. res->member_list_entries = member_list_entries;
  474. res->header.size = size;
  475. res->header.id = MESSAGE_RES_CPG_TOTEM_CONFCHG_CALLBACK;
  476. res->header.error = CS_OK;
  477. memcpy (&res->ring_id, &last_sync_ring_id, sizeof (mar_cpg_ring_id_t));
  478. memcpy (res->member_list, member_list, res->member_list_entries * sizeof (mar_uint32_t));
  479. if (conn == NULL) {
  480. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
  481. struct cpg_pd *cpg_pd = list_entry (iter, struct cpg_pd, list);
  482. api->ipc_dispatch_send (cpg_pd->conn, buf, size);
  483. }
  484. } else {
  485. api->ipc_dispatch_send (conn, buf, size);
  486. }
  487. return CPG_OK;
  488. }
  489. static int notify_lib_joinlist(
  490. const mar_cpg_name_t *group_name,
  491. void *conn,
  492. int joined_list_entries,
  493. mar_cpg_address_t *joined_list,
  494. int left_list_entries,
  495. mar_cpg_address_t *left_list,
  496. int id)
  497. {
  498. int size;
  499. char *buf;
  500. struct list_head *iter;
  501. int count;
  502. struct res_lib_cpg_confchg_callback *res;
  503. mar_cpg_address_t *retgi;
  504. count = 0;
  505. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  506. struct process_info *pi = list_entry (iter, struct process_info, list);
  507. if (mar_name_compare (&pi->group, group_name) == 0) {
  508. int i;
  509. int founded = 0;
  510. for (i = 0; i < left_list_entries; i++) {
  511. if (left_list[i].nodeid == pi->nodeid && left_list[i].pid == pi->pid) {
  512. founded++;
  513. }
  514. }
  515. if (!founded)
  516. count++;
  517. }
  518. }
  519. size = sizeof(struct res_lib_cpg_confchg_callback) +
  520. sizeof(mar_cpg_address_t) * (count + left_list_entries + joined_list_entries);
  521. buf = alloca(size);
  522. if (!buf)
  523. return CPG_ERR_LIBRARY;
  524. res = (struct res_lib_cpg_confchg_callback *)buf;
  525. res->joined_list_entries = joined_list_entries;
  526. res->left_list_entries = left_list_entries;
  527. res->member_list_entries = count;
  528. retgi = res->member_list;
  529. res->header.size = size;
  530. res->header.id = id;
  531. res->header.error = CS_OK;
  532. memcpy(&res->group_name, group_name, sizeof(mar_cpg_name_t));
  533. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  534. struct process_info *pi=list_entry (iter, struct process_info, list);
  535. if (mar_name_compare (&pi->group, group_name) == 0) {
  536. int i;
  537. int founded = 0;
  538. for (i = 0;i < left_list_entries; i++) {
  539. if (left_list[i].nodeid == pi->nodeid && left_list[i].pid == pi->pid) {
  540. founded++;
  541. }
  542. }
  543. if (!founded) {
  544. retgi->nodeid = pi->nodeid;
  545. retgi->pid = pi->pid;
  546. retgi++;
  547. }
  548. }
  549. }
  550. if (left_list_entries) {
  551. memcpy (retgi, left_list, left_list_entries * sizeof(mar_cpg_address_t));
  552. retgi += left_list_entries;
  553. }
  554. if (joined_list_entries) {
  555. memcpy (retgi, joined_list, joined_list_entries * sizeof(mar_cpg_address_t));
  556. retgi += joined_list_entries;
  557. }
  558. if (conn) {
  559. api->ipc_dispatch_send (conn, buf, size);
  560. } else {
  561. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
  562. struct cpg_pd *cpd = list_entry (iter, struct cpg_pd, list);
  563. if (mar_name_compare (&cpd->group_name, group_name) == 0) {
  564. assert (left_list_entries <= 1);
  565. assert (joined_list_entries <= 1);
  566. if (joined_list_entries) {
  567. if (joined_list[0].pid == cpd->pid &&
  568. joined_list[0].nodeid == api->totem_nodeid_get()) {
  569. cpd->cpd_state = CPD_STATE_JOIN_COMPLETED;
  570. }
  571. }
  572. if (cpd->cpd_state == CPD_STATE_JOIN_COMPLETED ||
  573. cpd->cpd_state == CPD_STATE_LEAVE_STARTED) {
  574. api->ipc_dispatch_send (cpd->conn, buf, size);
  575. }
  576. if (left_list_entries) {
  577. if (left_list[0].pid == cpd->pid &&
  578. left_list[0].nodeid == api->totem_nodeid_get()) {
  579. cpd->pid = 0;
  580. memset (&cpd->group_name, 0, sizeof(cpd->group_name));
  581. cpd->cpd_state = CPD_STATE_UNJOINED;
  582. }
  583. }
  584. }
  585. }
  586. }
  587. /*
  588. * Traverse thru cpds and send totem membership for cpd, where it is not send yet
  589. */
  590. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
  591. struct cpg_pd *cpd = list_entry (iter, struct cpg_pd, list);
  592. if ((cpd->flags & CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF) && (cpd->initial_totem_conf_sent == 0)) {
  593. cpd->initial_totem_conf_sent = 1;
  594. notify_lib_totem_membership (cpd->conn, my_old_member_list_entries, my_old_member_list);
  595. }
  596. }
  597. return CPG_OK;
  598. }
  599. static struct downlist_msg* downlist_master_choose (void)
  600. {
  601. struct downlist_msg *cmp;
  602. struct downlist_msg *best = NULL;
  603. struct list_head *iter;
  604. for (iter = downlist_messages_head.next;
  605. iter != &downlist_messages_head;
  606. iter = iter->next) {
  607. cmp = list_entry(iter, struct downlist_msg, list);
  608. if (best == NULL) {
  609. best = cmp;
  610. continue;
  611. }
  612. if (cmp->old_members < best->old_members) {
  613. continue;
  614. }
  615. else if (cmp->old_members > best->old_members) {
  616. best = cmp;
  617. }
  618. else if (cmp->sender_nodeid < best->sender_nodeid) {
  619. best = cmp;
  620. }
  621. }
  622. return best;
  623. }
  624. static void downlist_master_choose_and_send (void)
  625. {
  626. struct downlist_msg *stored_msg;
  627. struct list_head *iter;
  628. mar_cpg_address_t left_list;
  629. int i;
  630. downlist_state = CPG_DOWNLIST_APPLYING;
  631. stored_msg = downlist_master_choose ();
  632. if (!stored_msg) {
  633. log_printf (LOGSYS_LEVEL_INFO, "NO chosen downlist");
  634. return;
  635. }
  636. log_printf (LOGSYS_LEVEL_INFO, "chosen downlist from node %s",
  637. api->totem_ifaces_print(stored_msg->sender_nodeid));
  638. /* send events */
  639. for (iter = process_info_list_head.next; iter != &process_info_list_head; ) {
  640. struct process_info *pi = list_entry(iter, struct process_info, list);
  641. iter = iter->next;
  642. for (i = 0; i < stored_msg->left_nodes; i++) {
  643. if (pi->nodeid == stored_msg->nodeids[i]) {
  644. left_list.nodeid = pi->nodeid;
  645. left_list.pid = pi->pid;
  646. left_list.reason = CONFCHG_CPG_REASON_NODEDOWN;
  647. notify_lib_joinlist(&pi->group, NULL,
  648. 0, NULL,
  649. 1, &left_list,
  650. MESSAGE_RES_CPG_CONFCHG_CALLBACK);
  651. list_del (&pi->list);
  652. free (pi);
  653. break;
  654. }
  655. }
  656. }
  657. }
  658. static void downlist_messages_delete (void)
  659. {
  660. struct downlist_msg *stored_msg;
  661. struct list_head *iter, *iter_next;
  662. for (iter = downlist_messages_head.next;
  663. iter != &downlist_messages_head;
  664. iter = iter_next) {
  665. iter_next = iter->next;
  666. stored_msg = list_entry(iter, struct downlist_msg, list);
  667. list_del (&stored_msg->list);
  668. free (stored_msg);
  669. }
  670. }
  671. static int cpg_exec_init_fn (struct corosync_api_v1 *corosync_api)
  672. {
  673. #ifdef COROSYNC_SOLARIS
  674. logsys_subsys_init();
  675. #endif
  676. list_init (&downlist_messages_head);
  677. api = corosync_api;
  678. return (0);
  679. }
  680. static void cpg_iteration_instance_finalize (struct cpg_iteration_instance *cpg_iteration_instance)
  681. {
  682. struct list_head *iter, *iter_next;
  683. struct process_info *pi;
  684. for (iter = cpg_iteration_instance->items_list_head.next;
  685. iter != &cpg_iteration_instance->items_list_head;
  686. iter = iter_next) {
  687. iter_next = iter->next;
  688. pi = list_entry (iter, struct process_info, list);
  689. list_del (&pi->list);
  690. free (pi);
  691. }
  692. list_del (&cpg_iteration_instance->list);
  693. hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_instance->handle);
  694. }
  695. static void cpg_pd_finalize (struct cpg_pd *cpd)
  696. {
  697. struct list_head *iter, *iter_next;
  698. struct cpg_iteration_instance *cpii;
  699. for (iter = cpd->iteration_instance_list_head.next;
  700. iter != &cpd->iteration_instance_list_head;
  701. iter = iter_next) {
  702. iter_next = iter->next;
  703. cpii = list_entry (iter, struct cpg_iteration_instance, list);
  704. cpg_iteration_instance_finalize (cpii);
  705. }
  706. list_del (&cpd->list);
  707. }
  708. static int cpg_lib_exit_fn (void *conn)
  709. {
  710. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  711. log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
  712. if (cpd->group_name.length > 0) {
  713. cpg_node_joinleave_send (cpd->pid, &cpd->group_name,
  714. MESSAGE_REQ_EXEC_CPG_PROCLEAVE, CONFCHG_CPG_REASON_PROCDOWN);
  715. }
  716. cpg_pd_finalize (cpd);
  717. api->ipc_refcnt_dec (conn);
  718. return (0);
  719. }
  720. static int cpg_node_joinleave_send (unsigned int pid, const mar_cpg_name_t *group_name, int fn, int reason)
  721. {
  722. struct req_exec_cpg_procjoin req_exec_cpg_procjoin;
  723. struct iovec req_exec_cpg_iovec;
  724. int result;
  725. memcpy(&req_exec_cpg_procjoin.group_name, group_name, sizeof(mar_cpg_name_t));
  726. req_exec_cpg_procjoin.pid = pid;
  727. req_exec_cpg_procjoin.reason = reason;
  728. req_exec_cpg_procjoin.header.size = sizeof(req_exec_cpg_procjoin);
  729. req_exec_cpg_procjoin.header.id = SERVICE_ID_MAKE(CPG_SERVICE, fn);
  730. req_exec_cpg_iovec.iov_base = (char *)&req_exec_cpg_procjoin;
  731. req_exec_cpg_iovec.iov_len = sizeof(req_exec_cpg_procjoin);
  732. result = api->totem_mcast (&req_exec_cpg_iovec, 1, TOTEM_AGREED);
  733. return (result);
  734. }
  735. /* Can byteswap join & leave messages */
  736. static void exec_cpg_procjoin_endian_convert (void *msg)
  737. {
  738. struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = msg;
  739. req_exec_cpg_procjoin->pid = swab32(req_exec_cpg_procjoin->pid);
  740. swab_mar_cpg_name_t (&req_exec_cpg_procjoin->group_name);
  741. req_exec_cpg_procjoin->reason = swab32(req_exec_cpg_procjoin->reason);
  742. }
  743. static void exec_cpg_joinlist_endian_convert (void *msg_v)
  744. {
  745. char *msg = msg_v;
  746. coroipc_response_header_t *res = (coroipc_response_header_t *)msg;
  747. struct join_list_entry *jle = (struct join_list_entry *)(msg + sizeof(coroipc_response_header_t));
  748. swab_mar_int32_t (&res->size);
  749. while ((const char*)jle < msg + res->size) {
  750. jle->pid = swab32(jle->pid);
  751. swab_mar_cpg_name_t (&jle->group_name);
  752. jle++;
  753. }
  754. }
  755. static void exec_cpg_downlist_endian_convert_old (void *msg)
  756. {
  757. }
  758. static void exec_cpg_downlist_endian_convert (void *msg)
  759. {
  760. struct req_exec_cpg_downlist *req_exec_cpg_downlist = msg;
  761. unsigned int i;
  762. req_exec_cpg_downlist->left_nodes = swab32(req_exec_cpg_downlist->left_nodes);
  763. req_exec_cpg_downlist->old_members = swab32(req_exec_cpg_downlist->old_members);
  764. for (i = 0; i < req_exec_cpg_downlist->left_nodes; i++) {
  765. req_exec_cpg_downlist->nodeids[i] = swab32(req_exec_cpg_downlist->nodeids[i]);
  766. }
  767. }
  768. static void exec_cpg_mcast_endian_convert (void *msg)
  769. {
  770. struct req_exec_cpg_mcast *req_exec_cpg_mcast = msg;
  771. swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
  772. swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
  773. req_exec_cpg_mcast->pid = swab32(req_exec_cpg_mcast->pid);
  774. req_exec_cpg_mcast->msglen = swab32(req_exec_cpg_mcast->msglen);
  775. swab_mar_message_source_t (&req_exec_cpg_mcast->source);
  776. }
  777. static struct process_info *process_info_find(const mar_cpg_name_t *group_name, uint32_t pid, unsigned int nodeid) {
  778. struct list_head *iter;
  779. for (iter = process_info_list_head.next; iter != &process_info_list_head; ) {
  780. struct process_info *pi = list_entry (iter, struct process_info, list);
  781. iter = iter->next;
  782. if (pi->pid == pid && pi->nodeid == nodeid &&
  783. mar_name_compare (&pi->group, group_name) == 0) {
  784. return pi;
  785. }
  786. }
  787. return NULL;
  788. }
  789. static void do_proc_join(
  790. const mar_cpg_name_t *name,
  791. uint32_t pid,
  792. unsigned int nodeid,
  793. int reason)
  794. {
  795. struct process_info *pi;
  796. struct process_info *pi_entry;
  797. mar_cpg_address_t notify_info;
  798. struct list_head *list;
  799. struct list_head *list_to_add = NULL;
  800. if (process_info_find (name, pid, nodeid) != NULL) {
  801. return ;
  802. }
  803. pi = malloc (sizeof (struct process_info));
  804. if (!pi) {
  805. log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate process_info struct");
  806. return;
  807. }
  808. pi->nodeid = nodeid;
  809. pi->pid = pid;
  810. memcpy(&pi->group, name, sizeof(*name));
  811. list_init(&pi->list);
  812. /*
  813. * Insert new process in sorted order so synchronization works properly
  814. */
  815. list_to_add = &process_info_list_head;
  816. for (list = process_info_list_head.next; list != &process_info_list_head; list = list->next) {
  817. pi_entry = list_entry(list, struct process_info, list);
  818. if (pi_entry->nodeid > pi->nodeid ||
  819. (pi_entry->nodeid == pi->nodeid && pi_entry->pid > pi->pid)) {
  820. break;
  821. }
  822. list_to_add = list;
  823. }
  824. list_splice (&pi->list, list_to_add);
  825. notify_info.pid = pi->pid;
  826. notify_info.nodeid = nodeid;
  827. notify_info.reason = reason;
  828. notify_lib_joinlist(&pi->group, NULL,
  829. 1, &notify_info,
  830. 0, NULL,
  831. MESSAGE_RES_CPG_CONFCHG_CALLBACK);
  832. }
  833. static void message_handler_req_exec_cpg_downlist_old (
  834. const void *message,
  835. unsigned int nodeid)
  836. {
  837. log_printf (LOGSYS_LEVEL_WARNING, "downlist OLD from node %d",
  838. nodeid);
  839. }
  840. static void message_handler_req_exec_cpg_downlist(
  841. const void *message,
  842. unsigned int nodeid)
  843. {
  844. const struct req_exec_cpg_downlist *req_exec_cpg_downlist = message;
  845. int i;
  846. struct list_head *iter;
  847. struct downlist_msg *stored_msg;
  848. int found;
  849. if (downlist_state != CPG_DOWNLIST_WAITING_FOR_MESSAGES) {
  850. log_printf (LOGSYS_LEVEL_WARNING, "downlist left_list: %d received in state %d",
  851. req_exec_cpg_downlist->left_nodes, downlist_state);
  852. return;
  853. }
  854. else {
  855. log_printf (LOGSYS_LEVEL_INFO, "downlist received left_list: %d",
  856. req_exec_cpg_downlist->left_nodes);
  857. }
  858. stored_msg = malloc (sizeof (struct downlist_msg));
  859. stored_msg->sender_nodeid = nodeid;
  860. stored_msg->old_members = req_exec_cpg_downlist->old_members;
  861. stored_msg->left_nodes = req_exec_cpg_downlist->left_nodes;
  862. memcpy (stored_msg->nodeids, req_exec_cpg_downlist->nodeids,
  863. req_exec_cpg_downlist->left_nodes * sizeof (mar_uint32_t));
  864. list_init (&stored_msg->list);
  865. list_add (&stored_msg->list, &downlist_messages_head);
  866. for (i = 0; i < my_member_list_entries; i++) {
  867. found = 0;
  868. for (iter = downlist_messages_head.next;
  869. iter != &downlist_messages_head;
  870. iter = iter->next) {
  871. stored_msg = list_entry(iter, struct downlist_msg, list);
  872. if (my_member_list[i] == stored_msg->sender_nodeid) {
  873. found = 1;
  874. }
  875. }
  876. if (!found) {
  877. return;
  878. }
  879. }
  880. downlist_master_choose_and_send ();
  881. }
  882. static void message_handler_req_exec_cpg_procjoin (
  883. const void *message,
  884. unsigned int nodeid)
  885. {
  886. const struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = message;
  887. log_printf(LOGSYS_LEVEL_DEBUG, "got procjoin message from cluster node %d\n", nodeid);
  888. do_proc_join (&req_exec_cpg_procjoin->group_name,
  889. req_exec_cpg_procjoin->pid, nodeid,
  890. CONFCHG_CPG_REASON_JOIN);
  891. }
  892. static void message_handler_req_exec_cpg_procleave (
  893. const void *message,
  894. unsigned int nodeid)
  895. {
  896. const struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = message;
  897. struct process_info *pi;
  898. struct list_head *iter;
  899. mar_cpg_address_t notify_info;
  900. log_printf(LOGSYS_LEVEL_DEBUG, "got procleave message from cluster node %d\n", nodeid);
  901. notify_info.pid = req_exec_cpg_procjoin->pid;
  902. notify_info.nodeid = nodeid;
  903. notify_info.reason = req_exec_cpg_procjoin->reason;
  904. notify_lib_joinlist(&req_exec_cpg_procjoin->group_name, NULL,
  905. 0, NULL,
  906. 1, &notify_info,
  907. MESSAGE_RES_CPG_CONFCHG_CALLBACK);
  908. for (iter = process_info_list_head.next; iter != &process_info_list_head; ) {
  909. pi = list_entry(iter, struct process_info, list);
  910. iter = iter->next;
  911. if (pi->pid == req_exec_cpg_procjoin->pid && pi->nodeid == nodeid &&
  912. mar_name_compare (&pi->group, &req_exec_cpg_procjoin->group_name)==0) {
  913. list_del (&pi->list);
  914. free (pi);
  915. }
  916. }
  917. }
  918. /* Got a proclist from another node */
  919. static void message_handler_req_exec_cpg_joinlist (
  920. const void *message_v,
  921. unsigned int nodeid)
  922. {
  923. const char *message = message_v;
  924. const coroipc_response_header_t *res = (const coroipc_response_header_t *)message;
  925. const struct join_list_entry *jle = (const struct join_list_entry *)(message + sizeof(coroipc_response_header_t));
  926. log_printf(LOGSYS_LEVEL_DEBUG, "got joinlist message from node %x\n",
  927. nodeid);
  928. /* Ignore our own messages */
  929. if (nodeid == api->totem_nodeid_get()) {
  930. return;
  931. }
  932. while ((const char*)jle < message + res->size) {
  933. do_proc_join (&jle->group_name, jle->pid, nodeid,
  934. CONFCHG_CPG_REASON_NODEUP);
  935. jle++;
  936. }
  937. }
  938. static void message_handler_req_exec_cpg_mcast (
  939. const void *message,
  940. unsigned int nodeid)
  941. {
  942. const struct req_exec_cpg_mcast *req_exec_cpg_mcast = message;
  943. struct res_lib_cpg_deliver_callback res_lib_cpg_mcast;
  944. int msglen = req_exec_cpg_mcast->msglen;
  945. struct list_head *iter, *pi_iter;
  946. struct cpg_pd *cpd;
  947. struct iovec iovec[2];
  948. int known_node = 0;
  949. res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_DELIVER_CALLBACK;
  950. res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast) + msglen;
  951. res_lib_cpg_mcast.msglen = msglen;
  952. res_lib_cpg_mcast.pid = req_exec_cpg_mcast->pid;
  953. res_lib_cpg_mcast.nodeid = nodeid;
  954. memcpy(&res_lib_cpg_mcast.group_name, &req_exec_cpg_mcast->group_name,
  955. sizeof(mar_cpg_name_t));
  956. iovec[0].iov_base = (void *)&res_lib_cpg_mcast;
  957. iovec[0].iov_len = sizeof (res_lib_cpg_mcast);
  958. iovec[1].iov_base = (char*)message+sizeof(*req_exec_cpg_mcast);
  959. iovec[1].iov_len = msglen;
  960. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; ) {
  961. cpd = list_entry(iter, struct cpg_pd, list);
  962. iter = iter->next;
  963. if ((cpd->cpd_state == CPD_STATE_LEAVE_STARTED || cpd->cpd_state == CPD_STATE_JOIN_COMPLETED)
  964. && (mar_name_compare (&cpd->group_name, &req_exec_cpg_mcast->group_name) == 0)) {
  965. if (!known_node) {
  966. /* Try to find, if we know the node */
  967. for (pi_iter = process_info_list_head.next;
  968. pi_iter != &process_info_list_head; pi_iter = pi_iter->next) {
  969. struct process_info *pi = list_entry (pi_iter, struct process_info, list);
  970. if (pi->nodeid == nodeid &&
  971. mar_name_compare (&pi->group, &req_exec_cpg_mcast->group_name) == 0) {
  972. known_node = 1;
  973. break;
  974. }
  975. }
  976. }
  977. if (!known_node) {
  978. /* Unknown node -> we will not deliver message */
  979. return ;
  980. }
  981. api->ipc_dispatch_iov_send (cpd->conn, iovec, 2);
  982. }
  983. }
  984. }
  985. static int cpg_exec_send_downlist(void)
  986. {
  987. struct iovec iov;
  988. g_req_exec_cpg_downlist.header.id = SERVICE_ID_MAKE(CPG_SERVICE, MESSAGE_REQ_EXEC_CPG_DOWNLIST);
  989. g_req_exec_cpg_downlist.header.size = sizeof(struct req_exec_cpg_downlist);
  990. g_req_exec_cpg_downlist.old_members = my_old_member_list_entries;
  991. iov.iov_base = (void *)&g_req_exec_cpg_downlist;
  992. iov.iov_len = g_req_exec_cpg_downlist.header.size;
  993. return (api->totem_mcast (&iov, 1, TOTEM_AGREED));
  994. }
  995. static int cpg_exec_send_joinlist(void)
  996. {
  997. int count = 0;
  998. struct list_head *iter;
  999. coroipc_response_header_t *res;
  1000. char *buf;
  1001. struct join_list_entry *jle;
  1002. struct iovec req_exec_cpg_iovec;
  1003. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  1004. struct process_info *pi = list_entry (iter, struct process_info, list);
  1005. if (pi->nodeid == api->totem_nodeid_get ()) {
  1006. count++;
  1007. }
  1008. }
  1009. /* Nothing to send */
  1010. if (!count)
  1011. return 0;
  1012. buf = alloca(sizeof(coroipc_response_header_t) + sizeof(struct join_list_entry) * count);
  1013. if (!buf) {
  1014. log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate joinlist buffer");
  1015. return -1;
  1016. }
  1017. jle = (struct join_list_entry *)(buf + sizeof(coroipc_response_header_t));
  1018. res = (coroipc_response_header_t *)buf;
  1019. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  1020. struct process_info *pi = list_entry (iter, struct process_info, list);
  1021. if (pi->nodeid == api->totem_nodeid_get ()) {
  1022. memcpy (&jle->group_name, &pi->group, sizeof (mar_cpg_name_t));
  1023. jle->pid = pi->pid;
  1024. jle++;
  1025. }
  1026. }
  1027. res->id = SERVICE_ID_MAKE(CPG_SERVICE, MESSAGE_REQ_EXEC_CPG_JOINLIST);
  1028. res->size = sizeof(coroipc_response_header_t)+sizeof(struct join_list_entry) * count;
  1029. req_exec_cpg_iovec.iov_base = buf;
  1030. req_exec_cpg_iovec.iov_len = res->size;
  1031. return (api->totem_mcast (&req_exec_cpg_iovec, 1, TOTEM_AGREED));
  1032. }
  1033. static int cpg_lib_init_fn (void *conn)
  1034. {
  1035. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1036. memset (cpd, 0, sizeof(struct cpg_pd));
  1037. cpd->conn = conn;
  1038. list_add (&cpd->list, &cpg_pd_list_head);
  1039. list_init (&cpd->iteration_instance_list_head);
  1040. api->ipc_refcnt_inc (conn);
  1041. log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p, cpd=%p\n", conn, cpd);
  1042. return (0);
  1043. }
  1044. /* Join message from the library */
  1045. static void message_handler_req_lib_cpg_join (void *conn, const void *message)
  1046. {
  1047. const struct req_lib_cpg_join *req_lib_cpg_join = message;
  1048. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1049. struct res_lib_cpg_join res_lib_cpg_join;
  1050. cs_error_t error = CPG_OK;
  1051. struct list_head *iter;
  1052. /* Test, if we don't have same pid and group name joined */
  1053. for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
  1054. struct cpg_pd *cpd_item = list_entry (iter, struct cpg_pd, list);
  1055. if (cpd_item->pid == req_lib_cpg_join->pid &&
  1056. mar_name_compare(&req_lib_cpg_join->group_name, &cpd_item->group_name) == 0) {
  1057. /* We have same pid and group name joined -> return error */
  1058. error = CPG_ERR_EXIST;
  1059. goto response_send;
  1060. }
  1061. }
  1062. /*
  1063. * Same check must be done in process info list, because there may be not yet delivered
  1064. * leave of client.
  1065. */
  1066. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  1067. struct process_info *pi = list_entry (iter, struct process_info, list);
  1068. if (pi->nodeid == api->totem_nodeid_get () && pi->pid == req_lib_cpg_join->pid &&
  1069. mar_name_compare(&req_lib_cpg_join->group_name, &pi->group) == 0) {
  1070. /* We have same pid and group name joined -> return error */
  1071. error = CPG_ERR_TRY_AGAIN;
  1072. goto response_send;
  1073. }
  1074. }
  1075. switch (cpd->cpd_state) {
  1076. case CPD_STATE_UNJOINED:
  1077. error = CPG_OK;
  1078. cpd->cpd_state = CPD_STATE_JOIN_STARTED;
  1079. cpd->pid = req_lib_cpg_join->pid;
  1080. cpd->flags = req_lib_cpg_join->flags;
  1081. memcpy (&cpd->group_name, &req_lib_cpg_join->group_name,
  1082. sizeof (cpd->group_name));
  1083. cpg_node_joinleave_send (req_lib_cpg_join->pid,
  1084. &req_lib_cpg_join->group_name,
  1085. MESSAGE_REQ_EXEC_CPG_PROCJOIN, CONFCHG_CPG_REASON_JOIN);
  1086. break;
  1087. case CPD_STATE_LEAVE_STARTED:
  1088. error = CPG_ERR_BUSY;
  1089. break;
  1090. case CPD_STATE_JOIN_STARTED:
  1091. error = CPG_ERR_EXIST;
  1092. break;
  1093. case CPD_STATE_JOIN_COMPLETED:
  1094. error = CPG_ERR_EXIST;
  1095. break;
  1096. }
  1097. response_send:
  1098. res_lib_cpg_join.header.size = sizeof(res_lib_cpg_join);
  1099. res_lib_cpg_join.header.id = MESSAGE_RES_CPG_JOIN;
  1100. res_lib_cpg_join.header.error = error;
  1101. api->ipc_response_send (conn, &res_lib_cpg_join, sizeof(res_lib_cpg_join));
  1102. }
  1103. /* Leave message from the library */
  1104. static void message_handler_req_lib_cpg_leave (void *conn, const void *message)
  1105. {
  1106. struct res_lib_cpg_leave res_lib_cpg_leave;
  1107. cs_error_t error = CPG_OK;
  1108. struct req_lib_cpg_leave *req_lib_cpg_leave = (struct req_lib_cpg_leave *)message;
  1109. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1110. log_printf(LOGSYS_LEVEL_DEBUG, "got leave request on %p\n", conn);
  1111. switch (cpd->cpd_state) {
  1112. case CPD_STATE_UNJOINED:
  1113. error = CPG_ERR_NOT_EXIST;
  1114. break;
  1115. case CPD_STATE_LEAVE_STARTED:
  1116. error = CPG_ERR_NOT_EXIST;
  1117. break;
  1118. case CPD_STATE_JOIN_STARTED:
  1119. error = CPG_ERR_BUSY;
  1120. break;
  1121. case CPD_STATE_JOIN_COMPLETED:
  1122. error = CPG_OK;
  1123. cpd->cpd_state = CPD_STATE_LEAVE_STARTED;
  1124. cpg_node_joinleave_send (req_lib_cpg_leave->pid,
  1125. &req_lib_cpg_leave->group_name,
  1126. MESSAGE_REQ_EXEC_CPG_PROCLEAVE,
  1127. CONFCHG_CPG_REASON_LEAVE);
  1128. break;
  1129. }
  1130. /* send return */
  1131. res_lib_cpg_leave.header.size = sizeof(res_lib_cpg_leave);
  1132. res_lib_cpg_leave.header.id = MESSAGE_RES_CPG_LEAVE;
  1133. res_lib_cpg_leave.header.error = error;
  1134. api->ipc_response_send(conn, &res_lib_cpg_leave, sizeof(res_lib_cpg_leave));
  1135. }
  1136. /* Finalize message from library */
  1137. static void message_handler_req_lib_cpg_finalize (
  1138. void *conn,
  1139. const void *message)
  1140. {
  1141. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1142. struct res_lib_cpg_finalize res_lib_cpg_finalize;
  1143. cs_error_t error = CS_OK;
  1144. log_printf (LOGSYS_LEVEL_DEBUG, "cpg finalize for conn=%p\n", conn);
  1145. /*
  1146. * We will just remove cpd from list. After this call, connection will be
  1147. * closed on lib side, and cpg_lib_exit_fn will be called
  1148. */
  1149. list_del (&cpd->list);
  1150. list_init (&cpd->list);
  1151. res_lib_cpg_finalize.header.size = sizeof (res_lib_cpg_finalize);
  1152. res_lib_cpg_finalize.header.id = MESSAGE_RES_CPG_FINALIZE;
  1153. res_lib_cpg_finalize.header.error = error;
  1154. api->ipc_response_send (conn, &res_lib_cpg_finalize,
  1155. sizeof (res_lib_cpg_finalize));
  1156. }
  1157. /* Mcast message from the library */
  1158. static void message_handler_req_lib_cpg_mcast (void *conn, const void *message)
  1159. {
  1160. const struct req_lib_cpg_mcast *req_lib_cpg_mcast = message;
  1161. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1162. mar_cpg_name_t group_name = cpd->group_name;
  1163. struct iovec req_exec_cpg_iovec[2];
  1164. struct req_exec_cpg_mcast req_exec_cpg_mcast;
  1165. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  1166. int msglen = req_lib_cpg_mcast->msglen;
  1167. int result;
  1168. cs_error_t error = CPG_ERR_NOT_EXIST;
  1169. log_printf(LOGSYS_LEVEL_DEBUG, "got mcast request on %p\n", conn);
  1170. switch (cpd->cpd_state) {
  1171. case CPD_STATE_UNJOINED:
  1172. error = CPG_ERR_NOT_EXIST;
  1173. break;
  1174. case CPD_STATE_LEAVE_STARTED:
  1175. error = CPG_ERR_NOT_EXIST;
  1176. break;
  1177. case CPD_STATE_JOIN_STARTED:
  1178. error = CPG_OK;
  1179. break;
  1180. case CPD_STATE_JOIN_COMPLETED:
  1181. error = CPG_OK;
  1182. break;
  1183. }
  1184. if (error == CPG_OK) {
  1185. req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + msglen;
  1186. req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
  1187. MESSAGE_REQ_EXEC_CPG_MCAST);
  1188. req_exec_cpg_mcast.pid = cpd->pid;
  1189. req_exec_cpg_mcast.msglen = msglen;
  1190. api->ipc_source_set (&req_exec_cpg_mcast.source, conn);
  1191. memcpy(&req_exec_cpg_mcast.group_name, &group_name,
  1192. sizeof(mar_cpg_name_t));
  1193. req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
  1194. req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
  1195. req_exec_cpg_iovec[1].iov_base = (char *)&req_lib_cpg_mcast->message;
  1196. req_exec_cpg_iovec[1].iov_len = msglen;
  1197. result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED);
  1198. assert(result == 0);
  1199. }
  1200. res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast);
  1201. res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_MCAST;
  1202. res_lib_cpg_mcast.header.error = error;
  1203. api->ipc_response_send (conn, &res_lib_cpg_mcast,
  1204. sizeof (res_lib_cpg_mcast));
  1205. }
  1206. static void message_handler_req_lib_cpg_membership (void *conn,
  1207. const void *message)
  1208. {
  1209. struct req_lib_cpg_membership_get *req_lib_cpg_membership_get =
  1210. (struct req_lib_cpg_membership_get *)message;
  1211. struct res_lib_cpg_membership_get res_lib_cpg_membership_get;
  1212. struct list_head *iter;
  1213. int member_count = 0;
  1214. res_lib_cpg_membership_get.header.id = MESSAGE_RES_CPG_MEMBERSHIP;
  1215. res_lib_cpg_membership_get.header.error = CPG_OK;
  1216. res_lib_cpg_membership_get.header.size =
  1217. sizeof (struct req_lib_cpg_membership_get);
  1218. for (iter = process_info_list_head.next;
  1219. iter != &process_info_list_head; iter = iter->next) {
  1220. struct process_info *pi = list_entry (iter, struct process_info, list);
  1221. if (mar_name_compare (&pi->group, &req_lib_cpg_membership_get->group_name) == 0) {
  1222. res_lib_cpg_membership_get.member_list[member_count].nodeid = pi->nodeid;
  1223. res_lib_cpg_membership_get.member_list[member_count].pid = pi->pid;
  1224. member_count += 1;
  1225. }
  1226. }
  1227. res_lib_cpg_membership_get.member_count = member_count;
  1228. api->ipc_response_send (conn, &res_lib_cpg_membership_get,
  1229. sizeof (res_lib_cpg_membership_get));
  1230. }
  1231. static void message_handler_req_lib_cpg_local_get (void *conn,
  1232. const void *message)
  1233. {
  1234. struct res_lib_cpg_local_get res_lib_cpg_local_get;
  1235. res_lib_cpg_local_get.header.size = sizeof (res_lib_cpg_local_get);
  1236. res_lib_cpg_local_get.header.id = MESSAGE_RES_CPG_LOCAL_GET;
  1237. res_lib_cpg_local_get.header.error = CPG_OK;
  1238. res_lib_cpg_local_get.local_nodeid = api->totem_nodeid_get ();
  1239. api->ipc_response_send (conn, &res_lib_cpg_local_get,
  1240. sizeof (res_lib_cpg_local_get));
  1241. }
  1242. static void message_handler_req_lib_cpg_iteration_initialize (
  1243. void *conn,
  1244. const void *message)
  1245. {
  1246. const struct req_lib_cpg_iterationinitialize *req_lib_cpg_iterationinitialize = message;
  1247. struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
  1248. hdb_handle_t cpg_iteration_handle = 0;
  1249. struct res_lib_cpg_iterationinitialize res_lib_cpg_iterationinitialize;
  1250. struct list_head *iter, *iter2;
  1251. struct cpg_iteration_instance *cpg_iteration_instance;
  1252. cs_error_t error = CS_OK;
  1253. int res;
  1254. log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration initialize\n");
  1255. /* Because between calling this function and *next can be some operations which will
  1256. * change list, we must do full copy.
  1257. */
  1258. /*
  1259. * Create new iteration instance
  1260. */
  1261. res = hdb_handle_create (&cpg_iteration_handle_t_db, sizeof (struct cpg_iteration_instance),
  1262. &cpg_iteration_handle);
  1263. if (res != 0) {
  1264. error = CS_ERR_NO_MEMORY;
  1265. goto response_send;
  1266. }
  1267. res = hdb_handle_get (&cpg_iteration_handle_t_db, cpg_iteration_handle, (void *)&cpg_iteration_instance);
  1268. if (res != 0) {
  1269. error = CS_ERR_BAD_HANDLE;
  1270. goto error_destroy;
  1271. }
  1272. list_init (&cpg_iteration_instance->items_list_head);
  1273. cpg_iteration_instance->handle = cpg_iteration_handle;
  1274. /*
  1275. * Create copy of process_info list "grouped by" group name
  1276. */
  1277. for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
  1278. struct process_info *pi = list_entry (iter, struct process_info, list);
  1279. struct process_info *new_pi;
  1280. if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_NAME_ONLY) {
  1281. /*
  1282. * Try to find processed group name in our list new list
  1283. */
  1284. int found = 0;
  1285. for (iter2 = cpg_iteration_instance->items_list_head.next;
  1286. iter2 != &cpg_iteration_instance->items_list_head;
  1287. iter2 = iter2->next) {
  1288. struct process_info *pi2 = list_entry (iter2, struct process_info, list);
  1289. if (mar_name_compare (&pi2->group, &pi->group) == 0) {
  1290. found = 1;
  1291. break;
  1292. }
  1293. }
  1294. if (found) {
  1295. /*
  1296. * We have this name in list -> don't add
  1297. */
  1298. continue ;
  1299. }
  1300. } else if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_ONE_GROUP) {
  1301. /*
  1302. * Test pi group name with request
  1303. */
  1304. if (mar_name_compare (&pi->group, &req_lib_cpg_iterationinitialize->group_name) != 0)
  1305. /*
  1306. * Not same -> don't add
  1307. */
  1308. continue ;
  1309. }
  1310. new_pi = malloc (sizeof (struct process_info));
  1311. if (!new_pi) {
  1312. log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate process_info struct");
  1313. error = CS_ERR_NO_MEMORY;
  1314. goto error_put_destroy;
  1315. }
  1316. memcpy (new_pi, pi, sizeof (struct process_info));
  1317. list_init (&new_pi->list);
  1318. if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_NAME_ONLY) {
  1319. /*
  1320. * pid and nodeid -> undefined
  1321. */
  1322. new_pi->pid = new_pi->nodeid = 0;
  1323. }
  1324. /*
  1325. * We will return list "grouped" by "group name", so try to find right place to add
  1326. */
  1327. for (iter2 = cpg_iteration_instance->items_list_head.next;
  1328. iter2 != &cpg_iteration_instance->items_list_head;
  1329. iter2 = iter2->next) {
  1330. struct process_info *pi2 = list_entry (iter2, struct process_info, list);
  1331. if (mar_name_compare (&pi2->group, &pi->group) == 0) {
  1332. break;
  1333. }
  1334. }
  1335. list_add (&new_pi->list, iter2);
  1336. }
  1337. /*
  1338. * Now we have a full "grouped by" copy of process_info list
  1339. */
  1340. /*
  1341. * Add instance to current cpd list
  1342. */
  1343. list_init (&cpg_iteration_instance->list);
  1344. list_add (&cpg_iteration_instance->list, &cpd->iteration_instance_list_head);
  1345. cpg_iteration_instance->current_pointer = &cpg_iteration_instance->items_list_head;
  1346. error_put_destroy:
  1347. hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_handle);
  1348. error_destroy:
  1349. if (error != CS_OK) {
  1350. hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_handle);
  1351. }
  1352. response_send:
  1353. res_lib_cpg_iterationinitialize.header.size = sizeof (res_lib_cpg_iterationinitialize);
  1354. res_lib_cpg_iterationinitialize.header.id = MESSAGE_RES_CPG_ITERATIONINITIALIZE;
  1355. res_lib_cpg_iterationinitialize.header.error = error;
  1356. res_lib_cpg_iterationinitialize.iteration_handle = cpg_iteration_handle;
  1357. api->ipc_response_send (conn, &res_lib_cpg_iterationinitialize,
  1358. sizeof (res_lib_cpg_iterationinitialize));
  1359. }
  1360. static void message_handler_req_lib_cpg_iteration_next (
  1361. void *conn,
  1362. const void *message)
  1363. {
  1364. const struct req_lib_cpg_iterationnext *req_lib_cpg_iterationnext = message;
  1365. struct res_lib_cpg_iterationnext res_lib_cpg_iterationnext;
  1366. struct cpg_iteration_instance *cpg_iteration_instance;
  1367. cs_error_t error = CS_OK;
  1368. int res;
  1369. struct process_info *pi;
  1370. log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration next\n");
  1371. res = hdb_handle_get (&cpg_iteration_handle_t_db,
  1372. req_lib_cpg_iterationnext->iteration_handle,
  1373. (void *)&cpg_iteration_instance);
  1374. if (res != 0) {
  1375. error = CS_ERR_LIBRARY;
  1376. goto error_exit;
  1377. }
  1378. assert (cpg_iteration_instance);
  1379. cpg_iteration_instance->current_pointer = cpg_iteration_instance->current_pointer->next;
  1380. if (cpg_iteration_instance->current_pointer == &cpg_iteration_instance->items_list_head) {
  1381. error = CS_ERR_NO_SECTIONS;
  1382. goto error_put;
  1383. }
  1384. pi = list_entry (cpg_iteration_instance->current_pointer, struct process_info, list);
  1385. /*
  1386. * Copy iteration data
  1387. */
  1388. res_lib_cpg_iterationnext.description.nodeid = pi->nodeid;
  1389. res_lib_cpg_iterationnext.description.pid = pi->pid;
  1390. memcpy (&res_lib_cpg_iterationnext.description.group,
  1391. &pi->group,
  1392. sizeof (mar_cpg_name_t));
  1393. error_put:
  1394. hdb_handle_put (&cpg_iteration_handle_t_db, req_lib_cpg_iterationnext->iteration_handle);
  1395. error_exit:
  1396. res_lib_cpg_iterationnext.header.size = sizeof (res_lib_cpg_iterationnext);
  1397. res_lib_cpg_iterationnext.header.id = MESSAGE_RES_CPG_ITERATIONNEXT;
  1398. res_lib_cpg_iterationnext.header.error = error;
  1399. api->ipc_response_send (conn, &res_lib_cpg_iterationnext,
  1400. sizeof (res_lib_cpg_iterationnext));
  1401. }
  1402. static void message_handler_req_lib_cpg_iteration_finalize (
  1403. void *conn,
  1404. const void *message)
  1405. {
  1406. const struct req_lib_cpg_iterationfinalize *req_lib_cpg_iterationfinalize = message;
  1407. struct res_lib_cpg_iterationfinalize res_lib_cpg_iterationfinalize;
  1408. struct cpg_iteration_instance *cpg_iteration_instance;
  1409. cs_error_t error = CS_OK;
  1410. int res;
  1411. log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration finalize\n");
  1412. res = hdb_handle_get (&cpg_iteration_handle_t_db,
  1413. req_lib_cpg_iterationfinalize->iteration_handle,
  1414. (void *)&cpg_iteration_instance);
  1415. if (res != 0) {
  1416. error = CS_ERR_LIBRARY;
  1417. goto error_exit;
  1418. }
  1419. assert (cpg_iteration_instance);
  1420. cpg_iteration_instance_finalize (cpg_iteration_instance);
  1421. hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_instance->handle);
  1422. error_exit:
  1423. res_lib_cpg_iterationfinalize.header.size = sizeof (res_lib_cpg_iterationfinalize);
  1424. res_lib_cpg_iterationfinalize.header.id = MESSAGE_RES_CPG_ITERATIONFINALIZE;
  1425. res_lib_cpg_iterationfinalize.header.error = error;
  1426. api->ipc_response_send (conn, &res_lib_cpg_iterationfinalize,
  1427. sizeof (res_lib_cpg_iterationfinalize));
  1428. }