cpg.c 64 KB

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