ckpt.c 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235
  1. /*
  2. * Copyright (c) 2003-2004 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <sys/types.h>
  35. #include <sys/uio.h>
  36. #include <sys/socket.h>
  37. #include <sys/un.h>
  38. #include <sys/time.h>
  39. #include <netinet/in.h>
  40. #include <unistd.h>
  41. #include <fcntl.h>
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #include <errno.h>
  45. #include <signal.h>
  46. #include <arpa/inet.h>
  47. #include "../include/ais_types.h"
  48. #include "../include/saCkpt.h"
  49. #include "../include/ipc_ckpt.h"
  50. #include "../include/list.h"
  51. #include "../include/queue.h"
  52. #include "aispoll.h"
  53. #include "mempool.h"
  54. #include "util.h"
  55. #include "parse.h"
  56. #include "main.h"
  57. #include "totempg.h"
  58. #define LOG_SERVICE LOG_SERVICE_CKPT
  59. #define CKPT_MAX_SECTION_DATA_SEND (1024*400)
  60. #include "print.h"
  61. struct ckpt_identifier {
  62. SaNameT ckpt_name;
  63. SaCkptSectionIdT ckpt_section_id;
  64. };
  65. static int process_localhost_transition = 0;
  66. DECLARE_LIST_INIT(checkpoint_list_head);
  67. DECLARE_LIST_INIT(checkpoint_iterator_list_head);
  68. DECLARE_LIST_INIT(checkpoint_recovery_list_head);
  69. struct checkpoint_cleanup {
  70. struct list_head list;
  71. struct saCkptCheckpoint checkpoint;
  72. };
  73. typedef enum {
  74. SYNCHRONY_STATE_STARTED,
  75. SYNCHRONY_STATE_ENDED
  76. }synchrony_state;
  77. /* TODO static totempg_recovery_plug_handle ckpt_checkpoint_recovery_plug_handle; */
  78. static int ckpt_exec_init_fn (struct openais_config *);
  79. static int ckpt_exit_fn (struct conn_info *conn_info);
  80. static int ckpt_init_two_fn (struct conn_info *conn_info);
  81. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr, int endian_conversion_required);
  82. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct in_addr source_addr, int endian_conversion_required);
  83. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct in_addr source_addr, int endian_conversion_required);
  84. static int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required);
  85. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required);
  86. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required);
  87. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required);
  88. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required);
  89. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required);
  90. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required);
  91. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required);
  92. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required);
  93. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required);
  94. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message);
  95. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message);
  96. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message);
  97. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message);
  98. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message);
  99. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message);
  100. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message);
  101. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message);
  102. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message);
  103. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message);
  104. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message);
  105. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message);
  106. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message);
  107. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message);
  108. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message);
  109. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message);
  110. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message);
  111. static void ckpt_recovery_activate (void);
  112. static void ckpt_recovery_initialize (void);
  113. static int ckpt_recovery_process (void);
  114. static void ckpt_recovery_finalize();
  115. static void ckpt_recovery_abort(void);
  116. static void ckpt_recovery_process_members_exit(struct in_addr *left_list,
  117. int left_list_entries);
  118. static void ckpt_replace_localhost_ip (struct in_addr *joined_list);
  119. void checkpoint_release (struct saCkptCheckpoint *checkpoint);
  120. void timer_function_retention (void *data);
  121. unsigned int abstime_to_msec (SaTimeT time);
  122. void timer_function_section_expire (void *data);
  123. static int recovery_checkpoint_open(SaNameT *checkpointName,
  124. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  125. struct ckpt_refcnt *ref_cnt);
  126. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  127. SaNameT *checkpointName,
  128. char* SectionId);
  129. static int recovery_section_write(int sectionIdLen, char* sectionId , SaNameT *checkpointName,
  130. void *newData, SaUint32T dataOffSet, SaUint32T dataSize);
  131. static synchrony_state recovery_state = SYNCHRONY_STATE_ENDED;
  132. static struct list_head *recovery_ckpt_next = 0;
  133. static struct list_head *recovery_ckpt_section_next = 0;
  134. static int recovery_section_data_offset = 0;
  135. static int recovery_section_send_flag = 0;
  136. static int recovery_abort = 0;
  137. static struct memb_ring_id saved_ring_id;
  138. static int ckpt_confchg_fn(
  139. enum totem_configuration_type configuration_type,
  140. struct in_addr *member_list, int member_list_entries,
  141. struct in_addr *left_list, int left_list_entries,
  142. struct in_addr *joined_list, int joined_list_entries,
  143. struct memb_ring_id *ring_id);
  144. struct libais_handler ckpt_libais_handlers[] =
  145. {
  146. { /* 0 */
  147. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointopen,
  148. .response_size = sizeof (struct res_lib_ckpt_checkpointopen),
  149. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN,
  150. .flow_control = FLOW_CONTROL_REQUIRED
  151. },
  152. { /* 1 */
  153. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointopenasync,
  154. .response_size = sizeof (struct res_lib_ckpt_checkpointopenasync),
  155. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC,
  156. .flow_control = FLOW_CONTROL_REQUIRED
  157. },
  158. { /* 2 */
  159. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointclose,
  160. .response_size = sizeof (struct res_lib_ckpt_checkpointclose),
  161. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE,
  162. .flow_control = FLOW_CONTROL_REQUIRED
  163. },
  164. { /* 3 */
  165. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointunlink,
  166. .response_size = sizeof (struct res_lib_ckpt_checkpointunlink),
  167. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK,
  168. .flow_control = FLOW_CONTROL_REQUIRED
  169. },
  170. { /* 4 */
  171. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointretentiondurationset,
  172. .response_size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  173. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET,
  174. .flow_control = FLOW_CONTROL_REQUIRED
  175. },
  176. { /* 5 */
  177. .libais_handler_fn = message_handler_req_lib_ckpt_activereplicaset,
  178. .response_size = sizeof (struct res_lib_ckpt_activereplicaset),
  179. .response_id = MESSAGE_RES_CKPT_ACTIVEREPLICASET,
  180. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  181. },
  182. { /* 6 */
  183. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointstatusget,
  184. .response_size = sizeof (struct res_lib_ckpt_checkpointstatusget),
  185. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET,
  186. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  187. },
  188. { /* 7 */
  189. .libais_handler_fn = message_handler_req_lib_ckpt_sectioncreate,
  190. .response_size = sizeof (struct res_lib_ckpt_sectioncreate),
  191. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE,
  192. .flow_control = FLOW_CONTROL_REQUIRED
  193. },
  194. { /* 8 */
  195. .libais_handler_fn = message_handler_req_lib_ckpt_sectiondelete,
  196. .response_size = sizeof (struct res_lib_ckpt_sectiondelete),
  197. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE,
  198. .flow_control = FLOW_CONTROL_REQUIRED
  199. },
  200. { /* 9 */
  201. .libais_handler_fn = message_handler_req_lib_ckpt_sectionexpirationtimeset,
  202. .response_size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  203. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET,
  204. .flow_control = FLOW_CONTROL_REQUIRED
  205. },
  206. { /* 10 */
  207. .libais_handler_fn = message_handler_req_lib_ckpt_sectionwrite,
  208. .response_size = sizeof (struct res_lib_ckpt_sectionwrite),
  209. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE,
  210. .flow_control = FLOW_CONTROL_REQUIRED
  211. },
  212. { /* 11 */
  213. .libais_handler_fn = message_handler_req_lib_ckpt_sectionoverwrite,
  214. .response_size = sizeof (struct res_lib_ckpt_sectionoverwrite),
  215. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE,
  216. .flow_control = FLOW_CONTROL_REQUIRED
  217. },
  218. { /* 12 */
  219. .libais_handler_fn = message_handler_req_lib_ckpt_sectionread,
  220. .response_size = sizeof (struct res_lib_ckpt_sectionread),
  221. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD,
  222. .flow_control = FLOW_CONTROL_REQUIRED
  223. },
  224. { /* 13 */
  225. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronize,
  226. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronize),
  227. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE,
  228. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  229. },
  230. { /* 14 */
  231. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronizeasync,
  232. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync), /* TODO RESPONSE */
  233. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC,
  234. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  235. },
  236. { /* 15 */
  237. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniteratorinitialize,
  238. .response_size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
  239. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE,
  240. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  241. },
  242. { /* 16 */
  243. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniteratornext,
  244. .response_size = sizeof (struct res_lib_ckpt_sectioniteratornext),
  245. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT,
  246. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  247. }
  248. };
  249. static int (*ckpt_aisexec_handler_fns[]) (void *msg, struct in_addr source_addr, int endian_conversion_required) = {
  250. message_handler_req_exec_ckpt_checkpointopen,
  251. message_handler_req_exec_ckpt_checkpointclose,
  252. message_handler_req_exec_ckpt_checkpointunlink,
  253. message_handler_req_exec_ckpt_checkpointretentiondurationset,
  254. message_handler_req_exec_ckpt_checkpointretentiondurationexpire,
  255. message_handler_req_exec_ckpt_sectioncreate,
  256. message_handler_req_exec_ckpt_sectiondelete,
  257. message_handler_req_exec_ckpt_sectionexpirationtimeset,
  258. message_handler_req_exec_ckpt_sectionwrite,
  259. message_handler_req_exec_ckpt_sectionoverwrite,
  260. message_handler_req_exec_ckpt_sectionread,
  261. message_handler_req_exec_ckpt_synchronize_state,
  262. message_handler_req_exec_ckpt_synchronize_section
  263. };
  264. struct service_handler ckpt_service_handler = {
  265. .libais_handlers = ckpt_libais_handlers,
  266. .libais_handlers_count = sizeof (ckpt_libais_handlers) / sizeof (struct libais_handler),
  267. .aisexec_handler_fns = ckpt_aisexec_handler_fns,
  268. .aisexec_handler_fns_count = sizeof (ckpt_aisexec_handler_fns) / sizeof (int (*)),
  269. .confchg_fn = ckpt_confchg_fn,
  270. .libais_init_two_fn = ckpt_init_two_fn,
  271. .libais_exit_fn = ckpt_exit_fn,
  272. .exec_init_fn = ckpt_exec_init_fn,
  273. .exec_dump_fn = 0,
  274. .sync_init = ckpt_recovery_initialize,
  275. .sync_process = ckpt_recovery_process,
  276. .sync_activate = ckpt_recovery_activate,
  277. .sync_abort = ckpt_recovery_abort,
  278. };
  279. static int processor_index_set(struct in_addr *proc_addr,
  280. struct ckpt_refcnt *ckpt_refcount)
  281. {
  282. int i;
  283. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  284. if (ckpt_refcount[i].addr.s_addr == 0) {
  285. /*
  286. * If the source addresses do not match and this element
  287. * has no stored value then store the new value and
  288. * return the Index.
  289. */
  290. memcpy(&ckpt_refcount[i].addr, proc_addr, sizeof(struct in_addr));
  291. return i;
  292. }
  293. /*
  294. * If the source addresses match then this processor index
  295. * has already been set
  296. */
  297. else if (ckpt_refcount[i].addr.s_addr == proc_addr->s_addr) {
  298. return -1;
  299. }
  300. }
  301. /*
  302. * Could not Find an empty slot
  303. * to store the new Processor.
  304. */
  305. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  306. if (ckpt_refcount[i].addr.s_addr == 0) {
  307. log_printf (LOG_LEVEL_ERROR,"Processor Set: Index %d has proc 0 and count 0\n", i);
  308. }
  309. else {
  310. log_printf (LOG_LEVEL_ERROR,"Processor Set: Index %d has proc %s and count %d\n",
  311. i,
  312. inet_ntoa(ckpt_refcount[i].addr),
  313. ckpt_refcount[i].count);
  314. }
  315. }
  316. return -1;
  317. }
  318. static int processor_add (struct in_addr *proc_addr, int count, struct ckpt_refcnt *ckpt_refcount)
  319. {
  320. int i;
  321. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  322. if (ckpt_refcount[i].addr.s_addr == 0) {
  323. log_printf (LOG_LEVEL_DEBUG,"processor_add found empty slot to insert new item\n");
  324. memcpy(&ckpt_refcount[i].addr, proc_addr, sizeof(struct in_addr));
  325. ckpt_refcount[i].count = count;
  326. return i;
  327. }
  328. /*Dont know how we missed this in the processor find but update this*/
  329. else if (ckpt_refcount[i].addr.s_addr == proc_addr->s_addr) {
  330. ckpt_refcount[i].count += count;
  331. log_printf (LOG_LEVEL_DEBUG,"processor_add for existent proc. ip %s, New count = %d\n",
  332. inet_ntoa(ckpt_refcount[i].addr),
  333. ckpt_refcount[i].count);
  334. return i;
  335. }
  336. }
  337. /*
  338. * Could not Find an empty slot
  339. * to store the new Processor.
  340. */
  341. log_printf (LOG_LEVEL_ERROR,"Processor Add Failed. Dumping Refcount Array\n");
  342. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  343. if (ckpt_refcount[i].addr.s_addr == 0) {
  344. log_printf (LOG_LEVEL_ERROR,"Processor Add: Index %d has proc 0 and count 0\n", i);
  345. }
  346. else {
  347. log_printf (LOG_LEVEL_ERROR,"Processor Add: Index %d has proc %s and count %d\n",
  348. i,
  349. inet_ntoa(ckpt_refcount[i].addr),
  350. ckpt_refcount[i].count);
  351. }
  352. }
  353. return -1;
  354. }
  355. static int processor_index_find(struct in_addr *proc_addr,
  356. struct ckpt_refcnt *ckpt_refcount)
  357. {
  358. int i;
  359. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  360. /*
  361. * If the source addresses match then return the index
  362. */
  363. if (ckpt_refcount[i].addr.s_addr == proc_addr->s_addr) {
  364. return i;
  365. }
  366. }
  367. /*
  368. * Could not Find the Processor
  369. */
  370. return -1;
  371. }
  372. static int ckpt_refcount_total(struct ckpt_refcnt *ckpt_refcount)
  373. {
  374. int i;
  375. int total = 0;
  376. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  377. total += ckpt_refcount[i].count;
  378. }
  379. return total;
  380. }
  381. static void initialize_ckpt_refcount_array (struct ckpt_refcnt *ckpt_refcount)
  382. {
  383. memset((char*)ckpt_refcount, 0, PROCESSOR_COUNT_MAX * sizeof(struct ckpt_refcnt));
  384. }
  385. static void merge_ckpt_refcounts(struct ckpt_refcnt *local, struct ckpt_refcnt *network)
  386. {
  387. int index,i;
  388. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  389. if (local[i].addr.s_addr == 0) {
  390. continue;
  391. }
  392. index = processor_index_find (&local[i].addr, network);
  393. if (index == -1) { /*Could Not Find the Local Entry in the remote.Add to it*/
  394. log_printf (LOG_LEVEL_DEBUG,"calling processor_add for ip %s, count %d\n",
  395. inet_ntoa(local[i].addr),
  396. local[i].count);
  397. index = processor_add (&local[i].addr, local[i].count, network);
  398. if (index == -1) {
  399. log_printf(LOG_LEVEL_ERROR,
  400. "merge_ckpt_refcounts : could not add a new processor as the MAX limit of procs is reached.Exiting\n");
  401. assert(0);
  402. }
  403. }
  404. else {
  405. if (local[i].count == network[index].count) {
  406. /*Nothing to do here as the network is already up 2 date*/
  407. log_printf (LOG_LEVEL_DEBUG,"merge_ckpt_refcounts counts match, continue\n");
  408. continue;
  409. }
  410. else {
  411. /*Found a match for this proc in the Network choose the larger of the 2.*/
  412. network[index].count += local[i].count;
  413. log_printf (LOG_LEVEL_DEBUG,"setting count for %s = %d\n",
  414. inet_ntoa(network[index].addr),
  415. network[index].count);
  416. }
  417. }
  418. }
  419. }
  420. static void ckpt_recovery_initialize (void)
  421. {
  422. struct list_head *checkpoint_list;
  423. struct list_head *checkpoint_section_list;
  424. struct saCkptCheckpoint *checkpoint;
  425. struct saCkptCheckpointSection *section;
  426. struct saCkptCheckpoint *savedCheckpoint;
  427. struct saCkptCheckpointSection *savedSection;
  428. if (recovery_abort) { /*Abort was called.*/
  429. return;
  430. }
  431. /*
  432. * Save off the existing Checkpoints to be used by ckpt_recovery_process
  433. */
  434. for (checkpoint_list = checkpoint_list_head.next;
  435. checkpoint_list != &checkpoint_list_head;
  436. checkpoint_list = checkpoint_list->next) {
  437. checkpoint = list_entry (checkpoint_list,
  438. struct saCkptCheckpoint, list);
  439. if (checkpoint->referenceCount <= 0) {
  440. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_initialize checkpoint %s has referenceCount 0 ignoring.\n",
  441. (char*)&checkpoint->name.value);
  442. continue;
  443. }
  444. savedCheckpoint =
  445. (struct saCkptCheckpoint *) malloc (sizeof(struct saCkptCheckpoint));
  446. assert(savedCheckpoint);
  447. memcpy(savedCheckpoint, checkpoint, sizeof(struct saCkptCheckpoint));
  448. list_init(&savedCheckpoint->list);
  449. list_add(&savedCheckpoint->list,&checkpoint_recovery_list_head);
  450. list_init(&savedCheckpoint->checkpointSectionsListHead);
  451. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  452. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  453. checkpoint_section_list = checkpoint_section_list->next) {
  454. section = list_entry (checkpoint_section_list,
  455. struct saCkptCheckpointSection, list);
  456. savedSection =
  457. (struct saCkptCheckpointSection *) malloc (sizeof(struct saCkptCheckpointSection));
  458. assert(savedSection);
  459. poll_timer_delete_data (aisexec_poll_handle, section->expiration_timer);
  460. memcpy(savedSection, section, sizeof(struct saCkptCheckpointSection));
  461. list_init(&savedSection->list);
  462. list_add(&savedSection->list,&savedCheckpoint->checkpointSectionsListHead);
  463. }
  464. }
  465. if (list_empty (&checkpoint_recovery_list_head)) {
  466. return;
  467. }
  468. recovery_ckpt_next = checkpoint_recovery_list_head.next;
  469. savedCheckpoint = list_entry (recovery_ckpt_next,
  470. struct saCkptCheckpoint, list);
  471. recovery_ckpt_section_next = savedCheckpoint->checkpointSectionsListHead.next;
  472. }
  473. static int ckpt_recovery_process (void)
  474. {
  475. int i;
  476. struct req_exec_ckpt_synchronize_state request_exec_sync_state;
  477. struct req_exec_ckpt_synchronize_section request_exec_sync_section;
  478. struct iovec iovecs[3];
  479. struct saCkptCheckpoint *checkpoint;
  480. struct saCkptCheckpointSection *ckptCheckpointSection;
  481. SaSizeT origSectionSize;
  482. SaSizeT newSectionSize;
  483. if (recovery_abort) { /*Abort was called.*/
  484. goto recovery_exit_clean;
  485. }
  486. /*So Initialize did not have any checkpoints to Synchronize*/
  487. if ((recovery_ckpt_next == 0) && (recovery_ckpt_section_next == 0)) {
  488. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_process Nothing to Process ...\n");
  489. goto recovery_exit_clean;
  490. }
  491. /*
  492. * ALGORITHM :
  493. * 1.) extract the checkpoint if there.
  494. * 2.) If there is a checkpoint then there has to be a section
  495. * 3.) If the recovery_section_send_flag was not set in the previous
  496. * invocation that means we have to send out a sync_msg before
  497. * we send out the sections
  498. * 4.) Set the recovery_section_send_flag and send the sections.
  499. */
  500. while (1) { /*Go for as long as the oubound queue is not full*/
  501. if(recovery_ckpt_next != &checkpoint_recovery_list_head) {
  502. checkpoint = list_entry (recovery_ckpt_next,
  503. struct saCkptCheckpoint, list);
  504. if (recovery_ckpt_section_next == 0) {
  505. recovery_ckpt_section_next = checkpoint->checkpointSectionsListHead.next;
  506. }
  507. if (recovery_ckpt_section_next != &checkpoint->checkpointSectionsListHead) {
  508. ckptCheckpointSection = list_entry (recovery_ckpt_section_next,
  509. struct saCkptCheckpointSection, list);
  510. /*
  511. * None of the section data msgs have been sent
  512. * so lets start with sending the sync_msg
  513. */
  514. if (recovery_section_send_flag == 0) {
  515. if ((int)ckptCheckpointSection->sectionDescriptor.sectionId.id) {
  516. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync State Message for ckpt = %s, section = %s.\n",
  517. (char*)&checkpoint->name.value,
  518. ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id));
  519. } else {
  520. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync State Message for ckpt = %s, section = default section.\n",
  521. (char*)&checkpoint->name.value);
  522. }
  523. request_exec_sync_state.header.size = sizeof (struct req_exec_ckpt_synchronize_state);
  524. request_exec_sync_state.header.id = MESSAGE_REQ_EXEC_CKPT_SYNCHRONIZESTATE;
  525. memcpy(&request_exec_sync_state.previous_ring_id, &saved_ring_id, sizeof(struct memb_ring_id));
  526. memcpy(&request_exec_sync_state.checkpointName, &checkpoint->name, sizeof(SaNameT));
  527. memcpy(&request_exec_sync_state.checkpointCreationAttributes,
  528. &checkpoint->checkpointCreationAttributes,
  529. sizeof(SaCkptCheckpointCreationAttributesT));
  530. memcpy(&request_exec_sync_state.sectionDescriptor,
  531. &ckptCheckpointSection->sectionDescriptor,
  532. sizeof(SaCkptSectionDescriptorT));
  533. memcpy(&request_exec_sync_state.source_addr, &this_ip->sin_addr, sizeof(struct in_addr));
  534. memcpy(request_exec_sync_state.ckpt_refcount,
  535. checkpoint->ckpt_refcount,
  536. sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  537. request_exec_sync_state.sectionDescriptor.sectionId.id = 0;
  538. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync State Message Values\n");
  539. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  540. if (request_exec_sync_state.ckpt_refcount[i].addr.s_addr == 0) {
  541. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc 0 and count %d\n", i,
  542. request_exec_sync_state.ckpt_refcount[i].count);
  543. }
  544. else {
  545. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc %s and count %d\n",
  546. i,
  547. inet_ntoa(request_exec_sync_state.ckpt_refcount[i].addr),
  548. request_exec_sync_state.ckpt_refcount[i].count);
  549. }
  550. }
  551. iovecs[0].iov_base = (char *)&request_exec_sync_state;
  552. iovecs[0].iov_len = sizeof (struct req_exec_ckpt_synchronize_state);
  553. /*
  554. * Populate the Section ID
  555. */
  556. iovecs[1].iov_base = ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id);
  557. iovecs[1].iov_len = ckptCheckpointSection->sectionDescriptor.sectionId.idLen;
  558. request_exec_sync_state.header.size += iovecs[1].iov_len;
  559. /*
  560. * Check to see if we can queue the new message and if you can
  561. * then mcast the message else break and create callback.
  562. */
  563. if (totempg_send_ok(iovecs[0].iov_len + iovecs[1].iov_len)){
  564. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  565. log_printf (LOG_LEVEL_DEBUG, "CKPT: Multicasted Sync State Message.\n");
  566. }
  567. else {
  568. log_printf (LOG_LEVEL_DEBUG, "CKPT: Sync State Message Outbound Queue full need to Wait for Callback.\n");
  569. return (1);
  570. }
  571. recovery_section_send_flag = 1;
  572. }
  573. origSectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize;
  574. newSectionSize = 0;
  575. /*
  576. * Now Create SyncSection messsages in chunks of CKPT_MAX_SECTION_DATA_SEND or less
  577. */
  578. while (recovery_section_data_offset < origSectionSize) {
  579. /*
  580. * Send a Max of CKPT_MAX_SECTION_DATA_SEND of section data
  581. */
  582. if ((origSectionSize - recovery_section_data_offset) > CKPT_MAX_SECTION_DATA_SEND) {
  583. newSectionSize = CKPT_MAX_SECTION_DATA_SEND;
  584. }
  585. else {
  586. newSectionSize = (origSectionSize - recovery_section_data_offset);
  587. }
  588. /*
  589. * Create and save a new Sync Section message.
  590. */
  591. request_exec_sync_section.header.size = sizeof (struct req_exec_ckpt_synchronize_section);
  592. request_exec_sync_section.header.id = MESSAGE_REQ_EXEC_CKPT_SYNCHRONIZESECTION;
  593. memcpy (&request_exec_sync_section.previous_ring_id, &saved_ring_id, sizeof(struct memb_ring_id));
  594. memcpy (&request_exec_sync_section.checkpointName, &checkpoint->name, sizeof(SaNameT));
  595. memcpy (&request_exec_sync_section.sectionId,
  596. &ckptCheckpointSection->sectionDescriptor.sectionId,
  597. sizeof(SaCkptSectionIdT));
  598. request_exec_sync_section.sectionId.id = 0;
  599. memcpy (&request_exec_sync_section.dataOffSet, &recovery_section_data_offset, sizeof(SaUint32T));
  600. memcpy (&request_exec_sync_section.dataSize, &newSectionSize, sizeof(SaUint32T));
  601. if (ckptCheckpointSection->sectionDescriptor.sectionId.id) {
  602. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync Section Message for ckpt = %s, section = %s, Data size = %d.\n",
  603. (char*)&checkpoint->name.value,
  604. ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id),
  605. newSectionSize);
  606. } else {
  607. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync Section Message for ckpt = %s, default section, Data size = %d.\n",
  608. (char*)&checkpoint->name.value,newSectionSize);
  609. }
  610. /*
  611. * Populate the Sync Section Request
  612. */
  613. iovecs[0].iov_base = (char *)&request_exec_sync_section;
  614. iovecs[0].iov_len = sizeof (struct req_exec_ckpt_synchronize_section);
  615. /*
  616. * Populate the Section ID
  617. */
  618. iovecs[1].iov_base = ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id);
  619. iovecs[1].iov_len = ckptCheckpointSection->sectionDescriptor.sectionId.idLen;
  620. request_exec_sync_section.header.size += iovecs[1].iov_len;
  621. /*
  622. * Populate the Section Data.
  623. */
  624. iovecs[2].iov_base = ((char*)ckptCheckpointSection->sectionData + recovery_section_data_offset);
  625. iovecs[2].iov_len = newSectionSize;
  626. request_exec_sync_section.header.size += iovecs[2].iov_len;
  627. /*
  628. * Check to see if we can queue the new message and if you can
  629. * then mcast the message else break and create callback.
  630. */
  631. if (totempg_send_ok(iovecs[0].iov_len + iovecs[1].iov_len + iovecs[2].iov_len)){
  632. assert (totempg_mcast (iovecs, 3, TOTEMPG_AGREED) == 0);
  633. log_printf (LOG_LEVEL_DEBUG, "CKPT: Multicasted Sync Section Message.\n");
  634. }
  635. else {
  636. log_printf (LOG_LEVEL_DEBUG, "CKPT: Sync Section Message Outbound Queue full need to Wait for Callback.\n");
  637. return (1);
  638. }
  639. recovery_section_data_offset += newSectionSize;
  640. }
  641. recovery_section_send_flag = 0;
  642. recovery_section_data_offset = 0;
  643. recovery_ckpt_section_next = recovery_ckpt_section_next->next;
  644. continue;
  645. }
  646. else {
  647. /*
  648. * We have reached the end of a section List.
  649. * Move to the next element in the ckpt list.
  650. * Init the section ptr to 0 so it is re evaled
  651. */
  652. recovery_ckpt_next = recovery_ckpt_next->next;
  653. recovery_ckpt_section_next = 0;
  654. continue;
  655. }
  656. }
  657. /*Should only be here at the end of the traversal of the ckpt list*/
  658. ckpt_recovery_finalize();
  659. recovery_exit_clean:
  660. /*Re - Initialize the static's*/
  661. recovery_ckpt_next = 0;
  662. recovery_ckpt_section_next = 0;
  663. recovery_section_data_offset = 0;
  664. recovery_section_send_flag = 0;
  665. recovery_abort = 0;
  666. return (0);
  667. }
  668. }
  669. static void ckpt_recovery_finalize ()
  670. {
  671. struct list_head *checkpoint_list;
  672. struct list_head *checkpoint_section_list;
  673. struct saCkptCheckpoint *checkpoint;
  674. struct saCkptCheckpointSection *section;
  675. struct ckpt_identifier *ckpt_id;
  676. /*
  677. * Remove All elements from old checkpoint
  678. * list
  679. */
  680. checkpoint_list = checkpoint_list_head.next;
  681. while (!list_empty(&checkpoint_list_head)) {
  682. checkpoint = list_entry (checkpoint_list,
  683. struct saCkptCheckpoint, list);
  684. checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  685. while (!list_empty(&checkpoint->checkpointSectionsListHead)) {
  686. section = list_entry (checkpoint_section_list,
  687. struct saCkptCheckpointSection, list);
  688. list_del (&section->list);
  689. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_finalize removed 0x%x.\n", section);
  690. free (section);
  691. checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  692. }
  693. list_del(&checkpoint->list);
  694. free(checkpoint);
  695. checkpoint_list = checkpoint_list_head.next;
  696. }
  697. /*
  698. * Initialize the old list again.
  699. */
  700. list_init(&checkpoint_list_head);
  701. /*
  702. * Copy the contents of the new list_head into the old list head
  703. */
  704. checkpoint_recovery_list_head.prev->next = &checkpoint_list_head;
  705. checkpoint_recovery_list_head.next->prev = &checkpoint_list_head;
  706. memcpy(&checkpoint_list_head, &checkpoint_recovery_list_head, sizeof(struct list_head));
  707. /*Timers might have been started before recovery happened .. restart them ..*/
  708. for (checkpoint_list = checkpoint_list_head.next;
  709. checkpoint_list != &checkpoint_list_head;
  710. checkpoint_list = checkpoint_list->next) {
  711. checkpoint = list_entry (checkpoint_list,
  712. struct saCkptCheckpoint, list);
  713. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  714. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  715. checkpoint_section_list = checkpoint_section_list->next) {
  716. section = list_entry (checkpoint_section_list,
  717. struct saCkptCheckpointSection, list);
  718. if (section->sectionDescriptor.expirationTime != SA_TIME_END) {
  719. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  720. assert(ckpt_id);
  721. memcpy(&ckpt_id->ckpt_name,&checkpoint->name,sizeof(SaNameT));
  722. memcpy(&ckpt_id->ckpt_section_id, &section->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  723. poll_timer_add (aisexec_poll_handle,
  724. abstime_to_msec (section->sectionDescriptor.expirationTime),
  725. ckpt_id,
  726. timer_function_section_expire,
  727. &section->expiration_timer);
  728. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_initialize expiration timer = 0x%x\n",
  729. section->expiration_timer);
  730. }
  731. }
  732. }
  733. /*
  734. * Initialize the new list head for reuse.
  735. */
  736. list_init(&checkpoint_recovery_list_head);
  737. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_finalize Done.\n");
  738. }
  739. static void ckpt_recovery_activate (void)
  740. {
  741. recovery_state = SYNCHRONY_STATE_ENDED;
  742. return;
  743. }
  744. static void ckpt_recovery_abort (void)
  745. {
  746. recovery_abort = 1;
  747. return;
  748. }
  749. static void ckpt_replace_localhost_ip (struct in_addr *joined_list) {
  750. struct list_head *checkpoint_list;
  751. struct saCkptCheckpoint *checkpoint;
  752. struct in_addr local_ip;
  753. int index;
  754. assert(joined_list);
  755. local_ip.s_addr = inet_addr("127.0.0.1");
  756. for (checkpoint_list = checkpoint_list_head.next;
  757. checkpoint_list != &checkpoint_list_head;
  758. checkpoint_list = checkpoint_list->next) {
  759. checkpoint = list_entry (checkpoint_list,
  760. struct saCkptCheckpoint, list);
  761. index = processor_index_find(&local_ip, checkpoint->ckpt_refcount);
  762. if (index == -1) {
  763. continue;
  764. }
  765. memcpy(&checkpoint->ckpt_refcount[index].addr, joined_list, sizeof(struct in_addr));
  766. log_printf (LOG_LEVEL_DEBUG, "Transitioning From Local Host replacing 127.0.0.1 with %s ...\n",
  767. inet_ntoa(*joined_list));
  768. }
  769. process_localhost_transition = 0;
  770. }
  771. static void ckpt_recovery_process_members_exit(struct in_addr *left_list,
  772. int left_list_entries)
  773. {
  774. struct list_head *checkpoint_list;
  775. struct saCkptCheckpoint *checkpoint;
  776. struct in_addr *member;
  777. struct in_addr local_ip;
  778. int index;
  779. int i;
  780. local_ip.s_addr = inet_addr("127.0.0.1");
  781. if (left_list_entries == 0) {
  782. return;
  783. }
  784. if ((left_list_entries == 1) &&
  785. (left_list->s_addr == local_ip.s_addr)) {
  786. process_localhost_transition = 1;
  787. return;
  788. }
  789. /*
  790. * Iterate left_list_entries.
  791. */
  792. member = left_list;
  793. for (i = 0; i < left_list_entries; i++) {
  794. for (checkpoint_list = checkpoint_list_head.next;
  795. checkpoint_list != &checkpoint_list_head;
  796. checkpoint_list = checkpoint_list->next) {
  797. checkpoint = list_entry (checkpoint_list,
  798. struct saCkptCheckpoint, list);
  799. index = processor_index_find(member, checkpoint->ckpt_refcount);
  800. if (index == -1) {
  801. continue;
  802. }
  803. /*
  804. * Decrement
  805. *
  806. */
  807. if (checkpoint->referenceCount >= 0) {
  808. checkpoint->referenceCount -= checkpoint->ckpt_refcount[index].count;
  809. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process_members_exit: refCount for %s = %d.\n",
  810. &checkpoint->name.value,checkpoint->referenceCount);
  811. assert (checkpoint->referenceCount >= 0);
  812. } else {
  813. log_printf (LOG_LEVEL_ERROR, "ckpt_recovery_process_members_exit: refCount for %s = %d.\n",
  814. &checkpoint->name.value,checkpoint->referenceCount);
  815. assert(0);
  816. }
  817. checkpoint->ckpt_refcount[index].count = 0;
  818. memset((char*)&checkpoint->ckpt_refcount[index].addr, 0, sizeof(struct in_addr));
  819. /*
  820. * If checkpoint has been unlinked and this is the last reference, delete it
  821. */
  822. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  823. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process_members_exit: Unlinking checkpoint %s.\n",
  824. &checkpoint->name.value);
  825. checkpoint_release (checkpoint);
  826. } else
  827. if ((checkpoint->expired == 0) && (checkpoint->referenceCount == 0)) {
  828. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process_members_exit: Starting timer to release checkpoint %s.\n",
  829. &checkpoint->name.value);
  830. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  831. poll_timer_add (aisexec_poll_handle,
  832. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  833. checkpoint,
  834. timer_function_retention,
  835. &checkpoint->retention_timer);
  836. }
  837. }
  838. member++;
  839. }
  840. return;
  841. }
  842. static int ckpt_confchg_fn (
  843. enum totem_configuration_type configuration_type,
  844. struct in_addr *member_list, int member_list_entries,
  845. struct in_addr *left_list, int left_list_entries,
  846. struct in_addr *joined_list, int joined_list_entries,
  847. struct memb_ring_id *ring_id)
  848. {
  849. if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
  850. #ifdef TODO
  851. totempg_recovery_plug_unplug (ckpt_checkpoint_recovery_plug_handle);
  852. #endif
  853. if (recovery_state == SYNCHRONY_STATE_ENDED) {
  854. memcpy (&saved_ring_id, ring_id, sizeof(struct memb_ring_id));
  855. }
  856. if (process_localhost_transition) {
  857. ckpt_replace_localhost_ip (joined_list);
  858. }
  859. }
  860. else if (configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) {
  861. ckpt_recovery_process_members_exit(left_list, left_list_entries);
  862. recovery_state = SYNCHRONY_STATE_STARTED;
  863. recovery_abort = 0;
  864. }
  865. return (0);
  866. }
  867. static struct saCkptCheckpoint *ckpt_checkpoint_find_global (SaNameT *name)
  868. {
  869. struct list_head *checkpoint_list;
  870. struct saCkptCheckpoint *checkpoint;
  871. for (checkpoint_list = checkpoint_list_head.next;
  872. checkpoint_list != &checkpoint_list_head;
  873. checkpoint_list = checkpoint_list->next) {
  874. checkpoint = list_entry (checkpoint_list,
  875. struct saCkptCheckpoint, list);
  876. if (name_match (name, &checkpoint->name)) {
  877. return (checkpoint);
  878. }
  879. }
  880. return (0);
  881. }
  882. static void ckpt_checkpoint_remove_cleanup (
  883. struct conn_info *conn_info,
  884. struct saCkptCheckpoint *checkpoint)
  885. {
  886. struct list_head *list;
  887. struct checkpoint_cleanup *checkpoint_cleanup;
  888. for (list = conn_info->ais_ci.u.libckpt_ci.checkpoint_list.next;
  889. list != &conn_info->ais_ci.u.libckpt_ci.checkpoint_list;
  890. list = list->next) {
  891. checkpoint_cleanup = list_entry (list,
  892. struct checkpoint_cleanup, list);
  893. if (name_match (&checkpoint_cleanup->checkpoint.name, &checkpoint->name)
  894. || (checkpoint_cleanup->checkpoint.name.length == 0)) {
  895. list_del (&checkpoint_cleanup->list);
  896. free (checkpoint_cleanup);
  897. return;
  898. }
  899. }
  900. }
  901. static struct saCkptCheckpointSection *ckpt_checkpoint_find_globalSection (
  902. struct saCkptCheckpoint *ckptCheckpoint,
  903. char *id,
  904. int idLen)
  905. {
  906. struct list_head *checkpoint_section_list;
  907. struct saCkptCheckpointSection *ckptCheckpointSection;
  908. if (idLen != 0) {
  909. log_printf (LOG_LEVEL_DEBUG, "Finding checkpoint section id %s %d\n", (char*)id, idLen);
  910. }
  911. else {
  912. log_printf (LOG_LEVEL_DEBUG, "Finding default checkpoint section\n");
  913. }
  914. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  915. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  916. checkpoint_section_list = checkpoint_section_list->next) {
  917. ckptCheckpointSection = list_entry (checkpoint_section_list,
  918. struct saCkptCheckpointSection, list);
  919. if (ckptCheckpointSection->sectionDescriptor.sectionId.idLen) {
  920. log_printf (LOG_LEVEL_DEBUG, "Checking section id %*s\n",
  921. ckptCheckpointSection->sectionDescriptor.sectionId.idLen,
  922. ckptCheckpointSection->sectionDescriptor.sectionId.id);
  923. }
  924. else {
  925. log_printf (LOG_LEVEL_DEBUG, "Checking default section id\n");
  926. }
  927. /*
  928. All 3 of these values being checked MUST be = 0 to return
  929. The default section. If even one of them is NON zero follow
  930. the normal route
  931. */
  932. if ((idLen ||
  933. ckptCheckpointSection->sectionDescriptor.sectionId.id ||
  934. ckptCheckpointSection->sectionDescriptor.sectionId.idLen) == 0) {
  935. log_printf (LOG_LEVEL_DEBUG, "Returning default section\n");
  936. return (ckptCheckpointSection);
  937. }
  938. if (ckptCheckpointSection->sectionDescriptor.sectionId.idLen == idLen &&
  939. (ckptCheckpointSection->sectionDescriptor.sectionId.id)&&
  940. (id)&&
  941. (memcmp (ckptCheckpointSection->sectionDescriptor.sectionId.id,
  942. id, idLen) == 0)) {
  943. log_printf (LOG_LEVEL_DEBUG, "Returning section %s(0x%x)\n", ckptCheckpointSection->sectionDescriptor.sectionId.id,
  944. ckptCheckpointSection);
  945. return (ckptCheckpointSection);
  946. }
  947. }
  948. return 0;
  949. }
  950. void checkpoint_section_release (struct saCkptCheckpointSection *section)
  951. {
  952. log_printf (LOG_LEVEL_DEBUG, "CKPT: checkpoint_section_release expiration timer = 0x%x\n", section->expiration_timer);
  953. list_del (&section->list);
  954. if (section->sectionDescriptor.sectionId.id) {
  955. free (section->sectionDescriptor.sectionId.id);
  956. }
  957. if (section->sectionData) {
  958. free (section->sectionData);
  959. }
  960. poll_timer_delete (aisexec_poll_handle, section->expiration_timer);
  961. free (section);
  962. }
  963. void checkpoint_release (struct saCkptCheckpoint *checkpoint)
  964. {
  965. struct list_head *list;
  966. struct saCkptCheckpointSection *section;
  967. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  968. /*
  969. * Release all checkpoint sections for this checkpoint
  970. */
  971. for (list = checkpoint->checkpointSectionsListHead.next;
  972. list != &checkpoint->checkpointSectionsListHead;) {
  973. section = list_entry (list,
  974. struct saCkptCheckpointSection, list);
  975. list = list->next;
  976. checkpoint_section_release (section);
  977. }
  978. list_del (&checkpoint->list);
  979. free (checkpoint);
  980. }
  981. int ckpt_checkpoint_close (struct saCkptCheckpoint *checkpoint) {
  982. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  983. struct iovec iovecs[2];
  984. if (checkpoint->expired == 1) {
  985. return (0);
  986. }
  987. req_exec_ckpt_checkpointclose.header.size =
  988. sizeof (struct req_exec_ckpt_checkpointclose);
  989. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  990. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  991. &checkpoint->name, sizeof (SaNameT));
  992. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  993. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  994. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  995. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  996. return (0);
  997. }
  998. return (-1);
  999. }
  1000. static int ckpt_exec_init_fn (struct openais_config *openais_config)
  1001. {
  1002. /*
  1003. * Initialize the saved ring ID.
  1004. */
  1005. saved_ring_id.seq = 0;
  1006. saved_ring_id.rep.s_addr = this_ip->sin_addr.s_addr;
  1007. #ifdef TODO
  1008. int res;
  1009. res = totempg_recovery_plug_create (&ckpt_checkpoint_recovery_plug_handle);
  1010. if (res != 0) {
  1011. log_printf(LOG_LEVEL_ERROR,
  1012. "Could not create recovery plug for clm service.\n");
  1013. return (-1);
  1014. }
  1015. #endif
  1016. return (0);
  1017. }
  1018. static int ckpt_exit_fn (struct conn_info *conn_info)
  1019. {
  1020. struct checkpoint_cleanup *checkpoint_cleanup;
  1021. struct list_head *cleanup_list;
  1022. if (conn_info->conn_info_partner->service != CKPT_SERVICE) {
  1023. return 0;
  1024. }
  1025. log_printf(LOG_LEVEL_DEBUG, "ckpt_exit_fn conn_info = %#x, with fd = %d\n", conn_info, conn_info->fd);
  1026. /*
  1027. * close all checkpoints opened on this fd
  1028. */
  1029. cleanup_list = conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list.next;
  1030. while (!list_empty(&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list)) {
  1031. checkpoint_cleanup = list_entry (cleanup_list,
  1032. struct checkpoint_cleanup, list);
  1033. if (checkpoint_cleanup->checkpoint.name.length > 0) {
  1034. ckpt_checkpoint_close (&checkpoint_cleanup->checkpoint);
  1035. }
  1036. list_del (&checkpoint_cleanup->list);
  1037. free (checkpoint_cleanup);
  1038. cleanup_list = conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list.next;
  1039. }
  1040. if (conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries) {
  1041. free (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries);
  1042. }
  1043. list_del (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.list);
  1044. return (0);
  1045. }
  1046. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr, int endian_conversion_required)
  1047. {
  1048. struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)message;
  1049. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)&req_exec_ckpt_checkpointopen->req_lib_ckpt_checkpointopen;
  1050. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  1051. struct res_lib_ckpt_checkpointopenasync res_lib_ckpt_checkpointopenasync;
  1052. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1053. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1054. struct checkpoint_cleanup *checkpoint_cleanup;
  1055. SaErrorT error = SA_AIS_OK;
  1056. int proc_index;
  1057. log_printf (LOG_LEVEL_DEBUG, "Executive request to open checkpoint %p\n", req_exec_ckpt_checkpointopen);
  1058. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointopen->checkpointName);
  1059. /*
  1060. * If checkpoint doesn't exist, create one
  1061. */
  1062. if (ckptCheckpoint == 0) {
  1063. if ((req_lib_ckpt_checkpointopen->checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) {
  1064. error = SA_AIS_ERR_NOT_EXIST;
  1065. goto error_exit;
  1066. }
  1067. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1068. if (ckptCheckpoint == 0) {
  1069. error = SA_AIS_ERR_NO_MEMORY;
  1070. goto error_exit;
  1071. }
  1072. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1073. if (ckptCheckpointSection == 0) {
  1074. free (ckptCheckpoint);
  1075. error = SA_AIS_ERR_NO_MEMORY;
  1076. goto error_exit;
  1077. }
  1078. memcpy (&ckptCheckpoint->name,
  1079. &req_lib_ckpt_checkpointopen->checkpointName,
  1080. sizeof (SaNameT));
  1081. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1082. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  1083. sizeof (SaCkptCheckpointCreationAttributesT));
  1084. ckptCheckpoint->unlinked = 0;
  1085. list_init (&ckptCheckpoint->list);
  1086. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1087. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1088. ckptCheckpoint->referenceCount = 0;
  1089. ckptCheckpoint->retention_timer = 0;
  1090. ckptCheckpoint->expired = 0;
  1091. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_WR_ALL_REPLICAS) == 1 &&
  1092. (ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) {
  1093. ckptCheckpoint->active_replica_set = 1;
  1094. } else {
  1095. ckptCheckpoint->active_replica_set = 0;
  1096. }
  1097. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1098. /*
  1099. * Add in default checkpoint section
  1100. */
  1101. list_init (&ckptCheckpointSection->list);
  1102. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1103. /*
  1104. * Default section id
  1105. */
  1106. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1107. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1108. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1109. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1110. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1111. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1112. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1113. assert(ckptCheckpointSection->sectionData);
  1114. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1115. ckptCheckpointSection->expiration_timer = 0;
  1116. } else {
  1117. if (req_lib_ckpt_checkpointopen->checkpointCreationAttributesSet &&
  1118. memcmp (&ckptCheckpoint->checkpointCreationAttributes,
  1119. &req_lib_ckpt_checkpointopen->checkpointCreationAttributesSet,
  1120. sizeof (SaCkptCheckpointCreationAttributesT)) == 0) {
  1121. error = SA_AIS_ERR_EXIST;
  1122. goto error_exit;
  1123. }
  1124. }
  1125. /*
  1126. * If the checkpoint has been unlinked, it is an invalid name
  1127. */
  1128. if (ckptCheckpoint->unlinked) {
  1129. error = SA_AIS_ERR_NOT_EXIST; /* Is this the correct return ? */
  1130. goto error_exit;
  1131. }
  1132. /*
  1133. * Setup connection information and mark checkpoint as referenced
  1134. */
  1135. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", ckptCheckpoint);
  1136. ckptCheckpoint->referenceCount += 1;
  1137. /*
  1138. * Add the connection reference information to the Checkpoint to be
  1139. * sent out later as a part of the sync process.
  1140. *
  1141. */
  1142. proc_index = processor_index_find(&source_addr,ckptCheckpoint->ckpt_refcount);
  1143. if (proc_index == -1) {/* Could not find, lets set the processor to an index.*/
  1144. proc_index = processor_index_set(&source_addr,ckptCheckpoint->ckpt_refcount);
  1145. }
  1146. if (proc_index != -1 ) {
  1147. ckptCheckpoint->ckpt_refcount[proc_index].addr = source_addr;
  1148. ckptCheckpoint->ckpt_refcount[proc_index].count++;
  1149. }
  1150. else {
  1151. log_printf (LOG_LEVEL_ERROR,
  1152. "CKPT: MAX LIMIT OF PROCESSORS reached. Cannot store new proc %p info.\n",
  1153. ckptCheckpoint);
  1154. }
  1155. /*
  1156. * Reset retention duration since this checkpoint was just opened
  1157. */
  1158. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1159. ckptCheckpoint->retention_timer = 0;
  1160. /*
  1161. * Send error result to CKPT library
  1162. */
  1163. error_exit:
  1164. /*
  1165. * If this node was the source of the message, respond to this node
  1166. */
  1167. if (message_source_is_local(&req_exec_ckpt_checkpointopen->source)) {
  1168. /*
  1169. * If its an async call respond with the invocation and handle
  1170. */
  1171. if (req_exec_ckpt_checkpointopen->async_call) {
  1172. res_lib_ckpt_checkpointopenasync.header.size = sizeof (struct res_lib_ckpt_checkpointopenasync);
  1173. res_lib_ckpt_checkpointopenasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  1174. res_lib_ckpt_checkpointopenasync.header.error = error;
  1175. res_lib_ckpt_checkpointopenasync.checkpointHandle = req_exec_ckpt_checkpointopen->checkpointHandle;
  1176. res_lib_ckpt_checkpointopenasync.invocation = req_exec_ckpt_checkpointopen->invocation;
  1177. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info->conn_info_partner,
  1178. &res_lib_ckpt_checkpointopenasync,
  1179. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1180. } else {
  1181. /*
  1182. * otherwise respond with the normal checkpointopen response
  1183. */
  1184. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  1185. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  1186. res_lib_ckpt_checkpointopen.header.error = error;
  1187. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info, &res_lib_ckpt_checkpointopen,
  1188. sizeof (struct res_lib_ckpt_checkpointopen));
  1189. }
  1190. if (error == SA_AIS_OK) {
  1191. checkpoint_cleanup = malloc (sizeof (struct checkpoint_cleanup));
  1192. if (checkpoint_cleanup == 0) {
  1193. free (ckptCheckpoint);
  1194. error = SA_AIS_ERR_NO_MEMORY;
  1195. } else {
  1196. memcpy(&checkpoint_cleanup->checkpoint,ckptCheckpoint,sizeof(struct saCkptCheckpoint));
  1197. list_add (&checkpoint_cleanup->list,
  1198. &req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  1199. }
  1200. }
  1201. }
  1202. return (0);
  1203. }
  1204. static int recovery_checkpoint_open(SaNameT *checkpointName,
  1205. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  1206. struct ckpt_refcnt *ref_cnt)
  1207. {
  1208. int i;
  1209. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1210. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1211. SaErrorT error = SA_AIS_OK;
  1212. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open %s\n", &checkpointName->value);
  1213. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open refcount Values\n");
  1214. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  1215. if (ref_cnt[i].addr.s_addr == 0) {
  1216. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc 0 and count %d\n", i,
  1217. ref_cnt[i].count);
  1218. }
  1219. else {
  1220. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc %s and count %d\n",
  1221. i,
  1222. inet_ntoa(ref_cnt[i].addr),
  1223. ref_cnt[i].count);
  1224. }
  1225. }
  1226. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1227. /*
  1228. * If checkpoint doesn't exist, create one
  1229. */
  1230. if (ckptCheckpoint == 0) {
  1231. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open Allocating new Checkpoint %s\n", &checkpointName->value);
  1232. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1233. if (ckptCheckpoint == 0) {
  1234. error = SA_AIS_ERR_NO_MEMORY;
  1235. goto error_exit;
  1236. }
  1237. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1238. if (ckptCheckpointSection == 0) {
  1239. free (ckptCheckpoint);
  1240. error = SA_AIS_ERR_NO_MEMORY;
  1241. goto error_exit;
  1242. }
  1243. memcpy (&ckptCheckpoint->name,
  1244. checkpointName,
  1245. sizeof (SaNameT));
  1246. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1247. ckptAttributes,
  1248. sizeof (SaCkptCheckpointCreationAttributesT));
  1249. ckptCheckpoint->unlinked = 0;
  1250. list_init (&ckptCheckpoint->list);
  1251. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1252. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1253. ckptCheckpoint->retention_timer = 0;
  1254. ckptCheckpoint->expired = 0;
  1255. /*
  1256. * Add in default checkpoint section
  1257. */
  1258. list_init (&ckptCheckpointSection->list);
  1259. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1260. /*
  1261. * Default section id
  1262. */
  1263. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1264. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1265. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1266. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1267. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1268. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1269. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1270. assert(ckptCheckpointSection->sectionData);
  1271. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1272. ckptCheckpointSection->expiration_timer = 0;
  1273. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1274. }
  1275. else {
  1276. /*
  1277. * Setup connection information and mark checkpoint as referenced
  1278. */
  1279. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery CHECKPOINT reopened is %p\n", ckptCheckpoint);
  1280. }
  1281. /*
  1282. * If the checkpoint has been unlinked, it is an invalid name
  1283. */
  1284. if (ckptCheckpoint->unlinked) {
  1285. error = SA_AIS_ERR_BAD_OPERATION; /* Is this the correct return ? */
  1286. goto error_exit;
  1287. }
  1288. /*CHECK to see if there are any existing ckpts*/
  1289. if ((ckptCheckpoint->ckpt_refcount) && (ckpt_refcount_total(ckptCheckpoint->ckpt_refcount) > 0)) {
  1290. log_printf (LOG_LEVEL_DEBUG,"calling merge_ckpt_refcounts\n");
  1291. merge_ckpt_refcounts(ckptCheckpoint->ckpt_refcount, ref_cnt);
  1292. }
  1293. else {
  1294. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1295. }
  1296. /*No Existing ckpts. Lets assign what we got over the network or the merged with network values*/
  1297. ckptCheckpoint->referenceCount = ckpt_refcount_total(ref_cnt);
  1298. log_printf (LOG_LEVEL_DEBUG, "CKPT: OPEN ckptCheckpoint->referenceCount %d\n",ckptCheckpoint->referenceCount);
  1299. memcpy(ckptCheckpoint->ckpt_refcount,ref_cnt,sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  1300. /*
  1301. * Reset retention duration since this checkpoint was just opened
  1302. */
  1303. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1304. ckptCheckpoint->retention_timer = 0;
  1305. /*
  1306. * Send error result to CKPT library
  1307. */
  1308. error_exit:
  1309. return (error);
  1310. }
  1311. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct in_addr source_addr, int endian_conversion_required)
  1312. {
  1313. int retcode;
  1314. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1315. = (struct req_exec_ckpt_synchronize_state *)message;
  1316. /*
  1317. * If the Incoming message's previous ring id == saved_ring_id
  1318. * Ignore because we have seen this message before.
  1319. */
  1320. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1321. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1322. return(0);
  1323. }
  1324. retcode = recovery_checkpoint_open(&req_exec_ckpt_sync_state->checkpointName,
  1325. &req_exec_ckpt_sync_state->checkpointCreationAttributes,
  1326. req_exec_ckpt_sync_state->ckpt_refcount);
  1327. if (retcode != SA_AIS_OK) {
  1328. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1329. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open returned %d\n",retcode);
  1330. }
  1331. retcode = recovery_section_create (&req_exec_ckpt_sync_state->sectionDescriptor,
  1332. &req_exec_ckpt_sync_state->checkpointName,
  1333. (char*)req_exec_ckpt_sync_state
  1334. + sizeof (struct req_exec_ckpt_synchronize_state));
  1335. if (retcode != SA_AIS_OK) {
  1336. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1337. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_section_create returned %d\n",retcode);
  1338. }
  1339. return (0);
  1340. }
  1341. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct in_addr source_addr, int endian_conversion_required)
  1342. {
  1343. int retcode;
  1344. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1345. = (struct req_exec_ckpt_synchronize_section *)message;
  1346. /*
  1347. * If the Incoming message's previous ring id == saved_ring_id
  1348. * Ignore because we have seen this message before.
  1349. */
  1350. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1351. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1352. return(0);
  1353. }
  1354. /*
  1355. * Write the contents of the section to the checkpoint section.
  1356. */
  1357. retcode = recovery_section_write(req_exec_ckpt_sync_section->sectionId.idLen,
  1358. (char*)req_exec_ckpt_sync_section
  1359. + sizeof (struct req_exec_ckpt_synchronize_section),
  1360. &req_exec_ckpt_sync_section->checkpointName,
  1361. (char*)req_exec_ckpt_sync_section
  1362. + sizeof (struct req_exec_ckpt_synchronize_section)
  1363. + req_exec_ckpt_sync_section->sectionId.idLen,
  1364. req_exec_ckpt_sync_section->dataOffSet,
  1365. req_exec_ckpt_sync_section->dataSize);
  1366. if (retcode != SA_AIS_OK) {
  1367. log_printf(LOG_LEVEL_ERROR, "CKPT: message_handler_req_exec_ckpt_synchronize_section\n");
  1368. log_printf(LOG_LEVEL_ERROR, "CKPT: recovery_section_write returned %d\n",retcode);
  1369. }
  1370. return (0);
  1371. }
  1372. unsigned int abstime_to_msec (SaTimeT time)
  1373. {
  1374. struct timeval tv;
  1375. unsigned long long curr_time;
  1376. unsigned long long msec_time;
  1377. gettimeofday (&tv, NULL);
  1378. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1379. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1380. msec_time = (((unsigned long long)time) / 1000000) -
  1381. (unsigned long long)curr_time;
  1382. return ((unsigned int)(msec_time));
  1383. }
  1384. void timer_function_section_expire (void *data)
  1385. {
  1386. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1387. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1388. struct ckpt_identifier *ckpt_id = 0;
  1389. ckpt_id = (struct ckpt_identifier *)data;
  1390. log_printf (LOG_LEVEL_DEBUG, "CKPT: timer_function_section_expire data = 0x%x \n",data);
  1391. if (ckpt_id->ckpt_section_id.idLen && ckpt_id->ckpt_section_id.id) {
  1392. log_printf (LOG_LEVEL_DEBUG, "CKPT: Attempting to Expire section %s in ckpt %s\n",
  1393. ckpt_id->ckpt_section_id.id,
  1394. (char *)&ckpt_id->ckpt_name.value);
  1395. }
  1396. else {
  1397. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire data incorect\n");
  1398. goto free_mem;
  1399. }
  1400. ckptCheckpoint = ckpt_checkpoint_find_global (&ckpt_id->ckpt_name);
  1401. if (ckptCheckpoint == 0) {
  1402. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find ckpt %s\n",
  1403. (char *)&ckpt_id->ckpt_name.value);
  1404. goto free_mem;
  1405. }
  1406. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1407. ckpt_id->ckpt_section_id.id,
  1408. (int)ckpt_id->ckpt_section_id.idLen);
  1409. if (ckptCheckpointSection == 0) {
  1410. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find section %s in ckpt %s\n",
  1411. ckpt_id->ckpt_section_id.id,
  1412. (char *)&ckpt_id->ckpt_name.value);
  1413. goto free_mem;
  1414. }
  1415. log_printf (LOG_LEVEL_DEBUG, "CKPT: Expiring section %s in ckpt %s\n",
  1416. ckpt_id->ckpt_section_id.id,
  1417. (char *)&ckpt_id->ckpt_name.value);
  1418. checkpoint_section_release (ckptCheckpointSection);
  1419. free_mem :
  1420. free (ckpt_id);
  1421. }
  1422. void timer_function_retention (void *data)
  1423. {
  1424. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  1425. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  1426. struct iovec iovec;
  1427. checkpoint->retention_timer = 0;
  1428. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  1429. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  1430. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  1431. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  1432. &checkpoint->name,
  1433. sizeof (SaNameT));
  1434. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  1435. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  1436. assert (totempg_mcast (&iovec, 1, TOTEMPG_AGREED) == 0);
  1437. }
  1438. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required)
  1439. {
  1440. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  1441. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  1442. struct saCkptCheckpoint *checkpoint = 0;
  1443. SaAisErrorT error = SA_AIS_OK;
  1444. int proc_index;
  1445. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  1446. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointclose->checkpointName);
  1447. if (checkpoint == 0) {
  1448. goto error_exit;
  1449. }
  1450. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1451. checkpoint->referenceCount--;
  1452. /*
  1453. * Modify the connection reference information to the Checkpoint to be
  1454. * sent out later as a part of the sync process.
  1455. */
  1456. proc_index = processor_index_find(&source_addr, checkpoint->ckpt_refcount);
  1457. if (proc_index != -1 ) {
  1458. checkpoint->ckpt_refcount[proc_index].count--;
  1459. }
  1460. else {
  1461. log_printf (LOG_LEVEL_ERROR,
  1462. "CKPT: Could Not find Processor Info %p info.\n",
  1463. checkpoint);
  1464. }
  1465. assert (checkpoint->referenceCount >= 0);
  1466. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  1467. checkpoint->referenceCount);
  1468. /*
  1469. * If checkpoint has been unlinked and this is the last reference, delete it
  1470. */
  1471. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  1472. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  1473. checkpoint_release (checkpoint);
  1474. } else
  1475. if (checkpoint->referenceCount == 0) {
  1476. poll_timer_add (aisexec_poll_handle,
  1477. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1478. checkpoint,
  1479. timer_function_retention,
  1480. &checkpoint->retention_timer);
  1481. }
  1482. error_exit:
  1483. if (message_source_is_local(&req_exec_ckpt_checkpointclose->source)) {
  1484. ckpt_checkpoint_remove_cleanup (req_exec_ckpt_checkpointclose->source.conn_info,
  1485. checkpoint);
  1486. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  1487. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  1488. res_lib_ckpt_checkpointclose.header.error = error;
  1489. libais_send_response (req_exec_ckpt_checkpointclose->source.conn_info,
  1490. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  1491. }
  1492. return (0);
  1493. }
  1494. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required)
  1495. {
  1496. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  1497. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  1498. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  1499. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1500. SaErrorT error = SA_AIS_OK;
  1501. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  1502. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointunlink->checkpointName);
  1503. if (ckptCheckpoint == 0) {
  1504. error = SA_AIS_ERR_NOT_EXIST;
  1505. goto error_exit;
  1506. }
  1507. if (ckptCheckpoint->unlinked) {
  1508. error = SA_AIS_ERR_INVALID_PARAM;
  1509. goto error_exit;
  1510. }
  1511. ckptCheckpoint->unlinked = 1;
  1512. /*
  1513. * Immediately delete entry if reference count is zero
  1514. */
  1515. if (ckptCheckpoint->referenceCount == 0) {
  1516. /*
  1517. * Remove retention timer since this checkpoint was unlinked and is no
  1518. * longer referenced
  1519. */
  1520. checkpoint_release (ckptCheckpoint);
  1521. }
  1522. else if ( ckptCheckpoint->referenceCount > 0 ) {
  1523. ckptCheckpoint->unlinked = 0;
  1524. ckptCheckpoint->expired = 0;
  1525. }
  1526. error_exit:
  1527. /*
  1528. * If this node was the source of the message, respond to this node
  1529. */
  1530. if (message_source_is_local(&req_exec_ckpt_checkpointunlink->source)) {
  1531. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  1532. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  1533. res_lib_ckpt_checkpointunlink.header.error = error;
  1534. libais_send_response (req_exec_ckpt_checkpointunlink->source.conn_info, &res_lib_ckpt_checkpointunlink,
  1535. sizeof (struct res_lib_ckpt_checkpointunlink));
  1536. }
  1537. return (0);
  1538. }
  1539. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1540. {
  1541. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  1542. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  1543. struct saCkptCheckpoint *checkpoint;
  1544. SaAisErrorT error = SA_AIS_ERR_BAD_OPERATION;
  1545. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  1546. if (checkpoint) {
  1547. log_printf (LOG_LEVEL_DEBUG, "CKPT: Setting retention duration for checkpoint %s\n",
  1548. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  1549. if (checkpoint->unlinked == 0) {
  1550. checkpoint->checkpointCreationAttributes.retentionDuration =
  1551. req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  1552. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  1553. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  1554. poll_timer_add (aisexec_poll_handle,
  1555. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1556. checkpoint,
  1557. timer_function_retention,
  1558. &checkpoint->retention_timer);
  1559. }
  1560. error = SA_AIS_OK;
  1561. }
  1562. }
  1563. /*
  1564. * Respond to library if this processor sent the duration set request
  1565. */
  1566. if (message_source_is_local(&req_exec_ckpt_checkpointretentiondurationset->source)) {
  1567. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  1568. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  1569. res_lib_ckpt_checkpointretentiondurationset.header.error = error;
  1570. libais_send_response (req_exec_ckpt_checkpointretentiondurationset->source.conn_info,
  1571. &res_lib_ckpt_checkpointretentiondurationset,
  1572. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  1573. }
  1574. return (0);
  1575. }
  1576. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required)
  1577. {
  1578. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  1579. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1580. struct saCkptCheckpoint *checkpoint;
  1581. struct iovec iovecs[2];
  1582. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  1583. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->referenceCount < 1)) {
  1584. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  1585. checkpoint->expired = 1;
  1586. req_exec_ckpt_checkpointunlink.header.size =
  1587. sizeof (struct req_exec_ckpt_checkpointunlink);
  1588. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1589. req_exec_ckpt_checkpointunlink.source.conn_info = 0;
  1590. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = 0;
  1591. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  1592. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  1593. sizeof (SaNameT));
  1594. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1595. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1596. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1597. }
  1598. return (0);
  1599. }
  1600. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  1601. SaNameT *checkpointName,
  1602. char* SectionId)
  1603. {
  1604. struct saCkptCheckpoint *ckptCheckpoint;
  1605. struct saCkptCheckpointSection *ckptCheckpointSection;
  1606. void *initialData;
  1607. void *sectionId;
  1608. struct ckpt_identifier *ckpt_id = 0;
  1609. SaErrorT error = SA_AIS_OK;
  1610. if ((int)sectionDescriptor->sectionId.idLen) {
  1611. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, section %s.\n",
  1612. &checkpointName->value, SectionId);
  1613. } else {
  1614. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, default section.\n",
  1615. &checkpointName->value);
  1616. }
  1617. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1618. if (ckptCheckpoint == 0) {
  1619. error = SA_AIS_ERR_NOT_EXIST;
  1620. goto error_exit;
  1621. }
  1622. /*
  1623. * Determine if user-specified checkpoint ID already exists
  1624. */
  1625. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1626. SectionId,
  1627. (int)sectionDescriptor->sectionId.idLen);
  1628. if (ckptCheckpointSection) {
  1629. error = SA_AIS_ERR_EXIST;
  1630. goto error_exit;
  1631. }
  1632. /*
  1633. * Allocate checkpoint section
  1634. */
  1635. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1636. if (ckptCheckpointSection == 0) {
  1637. error = SA_AIS_ERR_NO_MEMORY;
  1638. goto error_exit;
  1639. }
  1640. /*
  1641. * Allocate checkpoint section data
  1642. */
  1643. initialData = malloc (sectionDescriptor->sectionSize);
  1644. if (initialData == 0) {
  1645. free (ckptCheckpointSection);
  1646. error = SA_AIS_ERR_NO_MEMORY;
  1647. goto error_exit;
  1648. }
  1649. /*
  1650. * Allocate checkpoint section id
  1651. */
  1652. if (sectionDescriptor->sectionId.idLen) {
  1653. sectionId = malloc ((int)sectionDescriptor->sectionId.idLen);
  1654. if (sectionId == 0) {
  1655. free (ckptCheckpointSection);
  1656. free (initialData);
  1657. error = SA_AIS_ERR_NO_MEMORY;
  1658. goto error_exit;
  1659. }
  1660. } else {
  1661. sectionId = 0;
  1662. }
  1663. /*
  1664. * Copy checkpoint section ID and initialize data.
  1665. */
  1666. if (SectionId) {
  1667. memcpy ((char*)sectionId, (char*)SectionId, (int)sectionDescriptor->sectionId.idLen);
  1668. } else {
  1669. sectionId = 0;
  1670. }
  1671. memset (initialData, 0, sectionDescriptor->sectionSize);
  1672. /*
  1673. * Configure checkpoint section
  1674. */
  1675. memcpy(&ckptCheckpointSection->sectionDescriptor,
  1676. sectionDescriptor,
  1677. sizeof(SaCkptSectionDescriptorT));
  1678. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1679. ckptCheckpointSection->sectionData = initialData;
  1680. ckptCheckpointSection->expiration_timer = 0;
  1681. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1682. if (sectionDescriptor->expirationTime != SA_TIME_END) {
  1683. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  1684. assert(ckpt_id);
  1685. memcpy(&ckpt_id->ckpt_name,checkpointName,sizeof(SaNameT));
  1686. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  1687. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create Enqueuing Timer to Expire section %s in ckpt %s\n",
  1688. ckpt_id->ckpt_section_id.id,
  1689. (char *)&ckpt_id->ckpt_name.value);
  1690. poll_timer_add (aisexec_poll_handle,
  1691. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1692. ckpt_id,
  1693. timer_function_section_expire,
  1694. &ckptCheckpointSection->expiration_timer);
  1695. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create expiration timer = 0x%x\n",
  1696. ckptCheckpointSection->expiration_timer);
  1697. }
  1698. /*
  1699. * Add checkpoint section to checkpoint
  1700. */
  1701. list_init (&ckptCheckpointSection->list);
  1702. list_add (&ckptCheckpointSection->list,
  1703. &ckptCheckpoint->checkpointSectionsListHead);
  1704. error_exit:
  1705. return (error);
  1706. }
  1707. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1708. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  1709. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  1710. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  1711. struct saCkptCheckpoint *ckptCheckpoint;
  1712. struct saCkptCheckpointSection *ckptCheckpointSection;
  1713. void *initialData;
  1714. void *sectionId;
  1715. struct ckpt_identifier *ckpt_id = 0;
  1716. SaErrorT error = SA_AIS_OK;
  1717. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  1718. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectioncreate->checkpointName);
  1719. if (ckptCheckpoint == 0) {
  1720. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this*/
  1721. goto error_exit;
  1722. }
  1723. /*
  1724. * Determine if user-specified checkpoint ID already exists
  1725. */
  1726. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1727. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1728. req_lib_ckpt_sectioncreate->idLen);
  1729. if (ckptCheckpointSection) {
  1730. error = SA_AIS_ERR_EXIST;
  1731. goto error_exit;
  1732. }
  1733. /*
  1734. * Allocate checkpoint section
  1735. */
  1736. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1737. if (ckptCheckpointSection == 0) {
  1738. error = SA_AIS_ERR_NO_MEMORY;
  1739. goto error_exit;
  1740. }
  1741. /*
  1742. * Allocate checkpoint section data
  1743. */
  1744. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  1745. if (initialData == 0) {
  1746. free (ckptCheckpointSection);
  1747. error = SA_AIS_ERR_NO_MEMORY;
  1748. goto error_exit;
  1749. }
  1750. /*
  1751. * Allocate checkpoint section id
  1752. */
  1753. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  1754. if (sectionId == 0) {
  1755. free (ckptCheckpointSection);
  1756. free (initialData);
  1757. error = SA_AIS_ERR_NO_MEMORY;
  1758. goto error_exit;
  1759. }
  1760. /*
  1761. * Copy checkpoint section and section ID
  1762. */
  1763. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1764. req_lib_ckpt_sectioncreate->idLen);
  1765. memcpy (initialData,
  1766. ((char *)req_lib_ckpt_sectioncreate) +
  1767. sizeof (struct req_lib_ckpt_sectioncreate) +
  1768. req_lib_ckpt_sectioncreate->idLen,
  1769. req_lib_ckpt_sectioncreate->initialDataSize);
  1770. /*
  1771. * Configure checkpoint section
  1772. */
  1773. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1774. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  1775. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  1776. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  1777. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1778. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  1779. ckptCheckpointSection->sectionData = initialData;
  1780. ckptCheckpointSection->expiration_timer = 0;
  1781. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  1782. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  1783. assert(ckpt_id);
  1784. memcpy(&ckpt_id->ckpt_name,&req_exec_ckpt_sectioncreate->checkpointName,sizeof(SaNameT));
  1785. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  1786. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectioncreate Enqueuing Timer to Expire section %s in ckpt %s\n",
  1787. ckpt_id->ckpt_section_id.id,
  1788. (char *)&ckpt_id->ckpt_name.value);
  1789. poll_timer_add (aisexec_poll_handle,
  1790. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1791. ckpt_id,
  1792. timer_function_section_expire,
  1793. &ckptCheckpointSection->expiration_timer);
  1794. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionicreate expiration timer = 0x%x\n",
  1795. ckptCheckpointSection->expiration_timer);
  1796. }
  1797. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_sectioncreate created section with id = %s, idLen = %d\n",
  1798. ckptCheckpointSection->sectionDescriptor.sectionId.id,
  1799. ckptCheckpointSection->sectionDescriptor.sectionId.idLen);
  1800. /*
  1801. * Add checkpoint section to checkpoint
  1802. */
  1803. list_init (&ckptCheckpointSection->list);
  1804. list_add (&ckptCheckpointSection->list,
  1805. &ckptCheckpoint->checkpointSectionsListHead);
  1806. error_exit:
  1807. if (message_source_is_local(&req_exec_ckpt_sectioncreate->source)) {
  1808. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  1809. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  1810. res_lib_ckpt_sectioncreate.header.error = error;
  1811. libais_send_response (req_exec_ckpt_sectioncreate->source.conn_info,
  1812. &res_lib_ckpt_sectioncreate,
  1813. sizeof (struct res_lib_ckpt_sectioncreate));
  1814. }
  1815. return (0);
  1816. }
  1817. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1818. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  1819. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  1820. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  1821. struct saCkptCheckpoint *ckptCheckpoint;
  1822. struct saCkptCheckpointSection *ckptCheckpointSection;
  1823. SaErrorT error = SA_AIS_OK;
  1824. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectiondelete->checkpointName);
  1825. if (ckptCheckpoint == 0) {
  1826. error = SA_AIS_ERR_NOT_EXIST;
  1827. goto error_exit;
  1828. }
  1829. /*
  1830. * Determine if the user is trying to delete the default section
  1831. */
  1832. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  1833. error = SA_AIS_ERR_INVALID_PARAM;
  1834. goto error_exit;
  1835. }
  1836. /*
  1837. * Find checkpoint section to be deleted
  1838. */
  1839. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1840. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  1841. req_lib_ckpt_sectiondelete->idLen);
  1842. if (ckptCheckpointSection == 0) {
  1843. error = SA_AIS_ERR_NOT_EXIST;
  1844. goto error_exit;
  1845. }
  1846. /*
  1847. * Delete checkpoint section
  1848. */
  1849. checkpoint_section_release (ckptCheckpointSection);
  1850. /*
  1851. * return result to CKPT library
  1852. */
  1853. error_exit:
  1854. if (message_source_is_local(&req_exec_ckpt_sectiondelete->source)) {
  1855. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  1856. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  1857. res_lib_ckpt_sectiondelete.header.error = error;
  1858. libais_send_response (req_exec_ckpt_sectiondelete->source.conn_info,
  1859. &res_lib_ckpt_sectiondelete,
  1860. sizeof (struct res_lib_ckpt_sectiondelete));
  1861. }
  1862. return (0);
  1863. }
  1864. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1865. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  1866. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  1867. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  1868. struct saCkptCheckpoint *ckptCheckpoint;
  1869. struct saCkptCheckpointSection *ckptCheckpointSection;
  1870. struct ckpt_identifier *ckpt_id = 0;
  1871. SaErrorT error = SA_AIS_OK;
  1872. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  1873. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  1874. if (ckptCheckpoint == 0) {
  1875. error = SA_AIS_ERR_NOT_EXIST;
  1876. goto error_exit;
  1877. }
  1878. /*
  1879. * Determine if the user is trying to set expiration time for the default section
  1880. */
  1881. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  1882. error = SA_AIS_ERR_INVALID_PARAM;
  1883. goto error_exit;
  1884. }
  1885. /*
  1886. * Find checkpoint section that expiration time should be set for
  1887. */
  1888. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1889. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  1890. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  1891. req_lib_ckpt_sectionexpirationtimeset->idLen);
  1892. if (ckptCheckpointSection == 0) {
  1893. error = SA_AIS_ERR_NOT_EXIST;
  1894. goto error_exit;
  1895. }
  1896. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  1897. poll_timer_delete (aisexec_poll_handle, ckptCheckpointSection->expiration_timer);
  1898. ckptCheckpointSection->expiration_timer = 0;
  1899. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  1900. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  1901. assert(ckpt_id);
  1902. memcpy(&ckpt_id->ckpt_name,&req_exec_ckpt_sectionexpirationtimeset->checkpointName,sizeof(SaNameT));
  1903. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  1904. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionexpirationtimeset Enqueuing Timer to Expire section %s in ckpt %s, ref = 0x%x\n",
  1905. ckpt_id->ckpt_section_id.id,
  1906. (char *)&ckpt_id->ckpt_name.value,
  1907. ckpt_id);
  1908. poll_timer_add (aisexec_poll_handle,
  1909. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1910. ckpt_id,
  1911. timer_function_section_expire,
  1912. &ckptCheckpointSection->expiration_timer);
  1913. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionexpirationtimeset expiration timer = 0x%x\n",
  1914. ckptCheckpointSection->expiration_timer);
  1915. }
  1916. error_exit:
  1917. if (message_source_is_local(&req_exec_ckpt_sectionexpirationtimeset->source)) {
  1918. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  1919. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  1920. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  1921. libais_send_response (req_exec_ckpt_sectionexpirationtimeset->source.conn_info,
  1922. &res_lib_ckpt_sectionexpirationtimeset,
  1923. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  1924. }
  1925. return (0);
  1926. }
  1927. static int recovery_section_write(int sectionIdLen,
  1928. char* sectionId,
  1929. SaNameT *checkpointName,
  1930. void *newData,
  1931. SaUint32T dataOffSet,
  1932. SaUint32T dataSize)
  1933. {
  1934. struct saCkptCheckpoint *ckptCheckpoint;
  1935. struct saCkptCheckpointSection *ckptCheckpointSection;
  1936. int sizeRequired;
  1937. SaErrorT error = SA_AIS_OK;
  1938. char *sd;
  1939. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_write.\n");
  1940. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1941. if (ckptCheckpoint == 0) {
  1942. error = SA_AIS_ERR_NOT_EXIST;
  1943. goto error_exit;
  1944. }
  1945. /*
  1946. * Find checkpoint section to be written
  1947. */
  1948. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1949. sectionId,
  1950. sectionIdLen);
  1951. if (ckptCheckpointSection == 0) {
  1952. error = SA_AIS_ERR_NOT_EXIST;
  1953. goto error_exit;
  1954. }
  1955. /*
  1956. * If write would extend past end of section data, return error;
  1957. */
  1958. sizeRequired = dataOffSet + dataSize;
  1959. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  1960. error = SA_AIS_ERR_ACCESS;
  1961. goto error_exit;
  1962. }
  1963. /*
  1964. * Write checkpoint section to section data
  1965. */
  1966. if (dataSize > 0) {
  1967. sd = (char *)ckptCheckpointSection->sectionData;
  1968. memcpy (&sd[dataOffSet],
  1969. newData,
  1970. dataSize);
  1971. }
  1972. error_exit:
  1973. return (error);
  1974. }
  1975. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1976. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  1977. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  1978. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1979. struct saCkptCheckpoint *ckptCheckpoint;
  1980. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1981. int sizeRequired;
  1982. void *sectionData;
  1983. SaErrorT error = SA_AIS_OK;
  1984. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  1985. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionwrite->checkpointName);
  1986. if (ckptCheckpoint == 0) {
  1987. log_printf (LOG_LEVEL_ERROR, "CKPT: ckpt_checkpoint_find_global returned 0 Calling error_exit.\n");
  1988. error = SA_AIS_ERR_NOT_EXIST;
  1989. goto error_exit;
  1990. }
  1991. /*
  1992. printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1993. */
  1994. /*
  1995. * Find checkpoint section to be written
  1996. */
  1997. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1998. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  1999. req_lib_ckpt_sectionwrite->idLen);
  2000. if (ckptCheckpointSection == 0) {
  2001. if (req_lib_ckpt_sectionwrite->idLen == 0) {
  2002. log_printf (LOG_LEVEL_DEBUG, "CANT FIND DEFAULT SECTION.\n");
  2003. }
  2004. else {
  2005. log_printf (LOG_LEVEL_DEBUG, "CANT FIND SECTION '%s'\n",
  2006. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2007. }
  2008. error = SA_AIS_ERR_NOT_EXIST;
  2009. goto error_exit;
  2010. }
  2011. /*
  2012. * If write would extend past end of section data, enlarge section
  2013. */
  2014. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  2015. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  2016. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  2017. if (sectionData == 0) {
  2018. log_printf (LOG_LEVEL_ERROR, "CKPT: sectionData realloc returned 0 Calling error_exit.\n");
  2019. error = SA_AIS_ERR_NO_MEMORY;
  2020. goto error_exit;
  2021. }
  2022. /*
  2023. * Install new section data
  2024. */
  2025. ckptCheckpointSection->sectionData = sectionData;
  2026. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  2027. }
  2028. /*
  2029. * Write checkpoint section to section data
  2030. */
  2031. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  2032. char *sd;
  2033. int *val;
  2034. val = ckptCheckpointSection->sectionData;
  2035. sd = (char *)ckptCheckpointSection->sectionData;
  2036. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  2037. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  2038. req_lib_ckpt_sectionwrite->idLen,
  2039. req_lib_ckpt_sectionwrite->dataSize);
  2040. }
  2041. /*
  2042. * Write write response to CKPT library
  2043. */
  2044. error_exit:
  2045. if (message_source_is_local(&req_exec_ckpt_sectionwrite->source)) {
  2046. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2047. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2048. res_lib_ckpt_sectionwrite.header.error = error;
  2049. libais_send_response (req_exec_ckpt_sectionwrite->source.conn_info,
  2050. &res_lib_ckpt_sectionwrite,
  2051. sizeof (struct res_lib_ckpt_sectionwrite));
  2052. }
  2053. return (0);
  2054. }
  2055. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  2056. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  2057. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  2058. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2059. struct saCkptCheckpoint *ckptCheckpoint;
  2060. struct saCkptCheckpointSection *ckptCheckpointSection;
  2061. void *sectionData;
  2062. SaErrorT error = SA_AIS_OK;
  2063. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  2064. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionoverwrite->checkpointName);
  2065. if (ckptCheckpoint == 0) {
  2066. error = SA_AIS_ERR_NOT_EXIST;
  2067. goto error_exit;
  2068. }
  2069. /*
  2070. * Find checkpoint section to be overwritten
  2071. */
  2072. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2073. ((char *)req_lib_ckpt_sectionoverwrite) +
  2074. sizeof (struct req_lib_ckpt_sectionoverwrite),
  2075. req_lib_ckpt_sectionoverwrite->idLen);
  2076. if (ckptCheckpointSection == 0) {
  2077. error = SA_AIS_ERR_NOT_EXIST;
  2078. goto error_exit;
  2079. }
  2080. /*
  2081. * Allocate checkpoint section data
  2082. */
  2083. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  2084. if (sectionData == 0) {
  2085. error = SA_AIS_ERR_NO_MEMORY;
  2086. goto error_exit;
  2087. }
  2088. memcpy (sectionData,
  2089. ((char *)req_lib_ckpt_sectionoverwrite) +
  2090. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  2091. req_lib_ckpt_sectionoverwrite->idLen,
  2092. req_lib_ckpt_sectionoverwrite->dataSize);
  2093. /*
  2094. * release old checkpoint section data
  2095. */
  2096. free (ckptCheckpointSection->sectionData);
  2097. /*
  2098. * Install overwritten checkpoint section data
  2099. */
  2100. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  2101. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  2102. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  2103. ckptCheckpointSection->sectionData = sectionData;
  2104. /*
  2105. * return result to CKPT library
  2106. */
  2107. error_exit:
  2108. if (message_source_is_local(&req_exec_ckpt_sectionoverwrite->source)) {
  2109. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  2110. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2111. res_lib_ckpt_sectionoverwrite.header.error = error;
  2112. libais_send_response (req_exec_ckpt_sectionoverwrite->source.conn_info,
  2113. &res_lib_ckpt_sectionoverwrite,
  2114. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2115. }
  2116. return (0);
  2117. }
  2118. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required) {
  2119. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  2120. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  2121. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2122. struct saCkptCheckpoint *ckptCheckpoint;
  2123. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  2124. int sectionSize = 0;
  2125. SaErrorT error = SA_AIS_OK;
  2126. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  2127. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionread->checkpointName);
  2128. if (ckptCheckpoint == 0) {
  2129. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this */
  2130. goto error_exit;
  2131. }
  2132. /*
  2133. * Find checkpoint section to be read
  2134. */
  2135. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2136. ((char *)req_lib_ckpt_sectionread) +
  2137. sizeof (struct req_lib_ckpt_sectionread),
  2138. req_lib_ckpt_sectionread->idLen);
  2139. if (ckptCheckpointSection == 0) {
  2140. error = SA_AIS_ERR_NOT_EXIST;
  2141. goto error_exit;
  2142. }
  2143. /*
  2144. * Determine the section size
  2145. */
  2146. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  2147. req_lib_ckpt_sectionread->dataOffset;
  2148. /*
  2149. * If the library has less space available then can be sent from the
  2150. * section, reduce bytes sent to library to max requested
  2151. */
  2152. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  2153. sectionSize = req_lib_ckpt_sectionread->dataSize;
  2154. }
  2155. /*
  2156. * If dataOffset is past end of data, return INVALID PARAM
  2157. */
  2158. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  2159. sectionSize = 0;
  2160. error = SA_AIS_ERR_INVALID_PARAM;
  2161. goto error_exit;
  2162. }
  2163. /*
  2164. * Write read response to CKPT library
  2165. */
  2166. error_exit:
  2167. if (message_source_is_local(&req_exec_ckpt_sectionread->source)) {
  2168. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  2169. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2170. res_lib_ckpt_sectionread.header.error = error;
  2171. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  2172. &res_lib_ckpt_sectionread,
  2173. sizeof (struct res_lib_ckpt_sectionread));
  2174. /*
  2175. * Write checkpoint to CKPT library section if section has data
  2176. */
  2177. if (sectionSize) {
  2178. char *sd;
  2179. sd = (char *)ckptCheckpointSection->sectionData;
  2180. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  2181. &sd[req_lib_ckpt_sectionread->dataOffset],
  2182. sectionSize);
  2183. }
  2184. }
  2185. return (0);
  2186. }
  2187. static int ckpt_init_two_fn (struct conn_info *conn_info)
  2188. {
  2189. list_init (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator
  2190. .list);
  2191. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  2192. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  2193. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  2194. list_add (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.list,
  2195. &checkpoint_iterator_list_head);
  2196. list_init (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list);
  2197. return (0);
  2198. }
  2199. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message)
  2200. {
  2201. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)message;
  2202. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2203. struct iovec iovecs[2];
  2204. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  2205. req_exec_ckpt_checkpointopen.header.size =
  2206. sizeof (struct req_exec_ckpt_checkpointopen);
  2207. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  2208. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  2209. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2210. req_lib_ckpt_checkpointopen,
  2211. sizeof (struct req_lib_ckpt_checkpointopen));
  2212. req_exec_ckpt_checkpointopen.async_call = 0;
  2213. req_exec_ckpt_checkpointopen.invocation = 0;
  2214. req_exec_ckpt_checkpointopen.checkpointHandle = 0;
  2215. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2216. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2217. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2218. return (0);
  2219. }
  2220. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  2221. {
  2222. struct req_lib_ckpt_checkpointopenasync *req_lib_ckpt_checkpointopenasync = (struct req_lib_ckpt_checkpointopenasync *)message;
  2223. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2224. struct iovec iovecs[2];
  2225. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint async.\n");
  2226. req_exec_ckpt_checkpointopen.header.size =
  2227. sizeof (struct req_exec_ckpt_checkpointopen);
  2228. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  2229. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  2230. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2231. req_lib_ckpt_checkpointopenasync,
  2232. sizeof (struct req_lib_ckpt_checkpointopen));
  2233. req_exec_ckpt_checkpointopen.async_call = 1;
  2234. req_exec_ckpt_checkpointopen.invocation = req_lib_ckpt_checkpointopenasync->invocation;
  2235. req_exec_ckpt_checkpointopen.checkpointHandle = req_lib_ckpt_checkpointopenasync->checkpointHandle;
  2236. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2237. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2238. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2239. return (0);
  2240. }
  2241. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message) {
  2242. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)message;
  2243. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  2244. struct iovec iovecs[2];
  2245. struct saCkptCheckpoint *checkpoint;
  2246. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  2247. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointclose->checkpointName);
  2248. if (checkpoint && (checkpoint->expired == 0)) {
  2249. req_exec_ckpt_checkpointclose.header.size =
  2250. sizeof (struct req_exec_ckpt_checkpointclose);
  2251. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  2252. message_source_set (&req_exec_ckpt_checkpointclose.source, conn_info);
  2253. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  2254. &req_lib_ckpt_checkpointclose->checkpointName, sizeof (SaNameT));
  2255. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  2256. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  2257. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  2258. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2259. }
  2260. }
  2261. else {
  2262. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to close so Returning Error. ####\n");
  2263. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  2264. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  2265. res_lib_ckpt_checkpointclose.header.error = SA_AIS_ERR_NOT_EXIST;
  2266. libais_send_response (conn_info,
  2267. &res_lib_ckpt_checkpointclose,
  2268. sizeof (struct res_lib_ckpt_checkpointclose));
  2269. }
  2270. return (0);
  2271. }
  2272. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  2273. {
  2274. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  2275. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  2276. struct iovec iovecs[2];
  2277. req_exec_ckpt_checkpointunlink.header.size =
  2278. sizeof (struct req_exec_ckpt_checkpointunlink);
  2279. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  2280. message_source_set (&req_exec_ckpt_checkpointunlink.source, conn_info);
  2281. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  2282. req_lib_ckpt_checkpointunlink,
  2283. sizeof (struct req_lib_ckpt_checkpointunlink));
  2284. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  2285. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  2286. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2287. return (0);
  2288. }
  2289. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  2290. {
  2291. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  2292. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  2293. struct iovec iovecs[2];
  2294. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info->fd);
  2295. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  2296. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  2297. message_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn_info);
  2298. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  2299. &req_lib_ckpt_checkpointretentiondurationset->checkpointName,
  2300. sizeof (SaNameT));
  2301. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  2302. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  2303. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  2304. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2305. return (0);
  2306. }
  2307. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message)
  2308. {
  2309. struct req_lib_ckpt_activereplicaset *req_lib_ckpt_activereplicaset = (struct req_lib_ckpt_activereplicaset *)message;
  2310. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  2311. struct saCkptCheckpoint *checkpoint;
  2312. SaAisErrorT error = SA_AIS_OK;
  2313. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_activereplicaset->checkpointName);
  2314. /*
  2315. * Make sure checkpoint is collocated and async update option
  2316. */
  2317. if (((checkpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) ||
  2318. (checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2319. error = SA_AIS_ERR_BAD_OPERATION;
  2320. }
  2321. checkpoint->active_replica_set = 1;
  2322. res_lib_ckpt_activereplicaset.header.size = sizeof (struct res_lib_ckpt_activereplicaset);
  2323. res_lib_ckpt_activereplicaset.header.id = MESSAGE_RES_CKPT_ACTIVEREPLICASET;
  2324. res_lib_ckpt_activereplicaset.header.error = error;
  2325. libais_send_response (conn_info, &res_lib_ckpt_activereplicaset,
  2326. sizeof (struct res_lib_ckpt_activereplicaset));
  2327. return (0);
  2328. }
  2329. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  2330. {
  2331. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  2332. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  2333. struct saCkptCheckpoint *checkpoint;
  2334. int memoryUsed = 0;
  2335. int numberOfSections = 0;
  2336. struct list_head *checkpoint_section_list;
  2337. struct saCkptCheckpointSection *checkpointSection;
  2338. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  2339. /*
  2340. * Count memory used by checkpoint sections
  2341. */
  2342. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointstatusget->checkpointName);
  2343. if (checkpoint && (checkpoint->expired == 0)) {
  2344. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  2345. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  2346. checkpoint_section_list = checkpoint_section_list->next) {
  2347. checkpointSection = list_entry (checkpoint_section_list,
  2348. struct saCkptCheckpointSection, list);
  2349. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  2350. numberOfSections += 1;
  2351. }
  2352. /*
  2353. * Build checkpoint status get response
  2354. */
  2355. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2356. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2357. if (checkpoint->active_replica_set == 1) {
  2358. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  2359. } else {
  2360. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2361. }
  2362. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointDescriptor.checkpointCreationAttributes,
  2363. &checkpoint->checkpointCreationAttributes,
  2364. sizeof (SaCkptCheckpointCreationAttributesT));
  2365. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.numberOfSections = numberOfSections;
  2366. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.memoryUsed = memoryUsed;
  2367. }
  2368. else {
  2369. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint's status so Returning Error. ####\n");
  2370. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2371. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2372. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2373. }
  2374. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  2375. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  2376. sizeof (struct res_lib_ckpt_checkpointstatusget));
  2377. return (0);
  2378. }
  2379. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  2380. {
  2381. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  2382. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  2383. struct iovec iovecs[2];
  2384. struct saCkptCheckpoint *checkpoint;
  2385. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  2386. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info->fd);
  2387. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioncreate->checkpointName);
  2388. if (checkpoint && (checkpoint->expired == 0)) {
  2389. /*
  2390. * checkpoint opened is writeable mode so send message to cluster
  2391. */
  2392. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  2393. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  2394. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  2395. req_lib_ckpt_sectioncreate,
  2396. sizeof (struct req_lib_ckpt_sectioncreate));
  2397. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  2398. &req_lib_ckpt_sectioncreate->checkpointName,
  2399. sizeof (SaNameT));
  2400. message_source_set (&req_exec_ckpt_sectioncreate.source, conn_info);
  2401. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  2402. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  2403. /*
  2404. * Send section name and initial data in message
  2405. */
  2406. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  2407. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  2408. req_exec_ckpt_sectioncreate.header.size += iovecs[1].iov_len;
  2409. if (iovecs[1].iov_len) {
  2410. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_lib_ckpt_sectioncreate Section = %s, idLen = %d\n",
  2411. iovecs[1].iov_base,
  2412. iovecs[1].iov_len);
  2413. }
  2414. #ifdef DEBUG
  2415. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  2416. iovecs[1].iov_len);
  2417. printf ("|\n");
  2418. { int i;
  2419. char *abc = iovecs[1].iov_base;
  2420. for (i = 0; i < 14;i++) {
  2421. printf ("%c ", abc[i]);
  2422. }
  2423. }
  2424. printf ("|\n");
  2425. #endif
  2426. if (iovecs[1].iov_len > 0) {
  2427. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2428. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2429. } else {
  2430. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2431. }
  2432. }
  2433. else {
  2434. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to create a section in so Returning Error. ####\n");
  2435. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  2436. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  2437. res_lib_ckpt_sectioncreate.header.error = SA_AIS_ERR_NOT_EXIST;
  2438. libais_send_response (conn_info,
  2439. &res_lib_ckpt_sectioncreate,
  2440. sizeof (struct res_lib_ckpt_sectioncreate));
  2441. }
  2442. return (0);
  2443. }
  2444. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  2445. {
  2446. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  2447. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  2448. struct iovec iovecs[2];
  2449. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info->fd);
  2450. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  2451. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  2452. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  2453. &req_lib_ckpt_sectiondelete->checkpointName,
  2454. sizeof (SaNameT));
  2455. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  2456. req_lib_ckpt_sectiondelete,
  2457. sizeof (struct req_lib_ckpt_sectiondelete));
  2458. message_source_set (&req_exec_ckpt_sectiondelete.source, conn_info);
  2459. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  2460. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  2461. /*
  2462. * Send section name
  2463. */
  2464. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  2465. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  2466. req_exec_ckpt_sectiondelete.header.size += iovecs[1].iov_len;
  2467. if (iovecs[1].iov_len > 0) {
  2468. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2469. } else {
  2470. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2471. }
  2472. return (0);
  2473. }
  2474. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  2475. {
  2476. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  2477. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  2478. struct iovec iovecs[2];
  2479. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info->fd);
  2480. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  2481. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  2482. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  2483. &req_lib_ckpt_sectionexpirationtimeset->checkpointName,
  2484. sizeof (SaNameT));
  2485. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  2486. req_lib_ckpt_sectionexpirationtimeset,
  2487. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  2488. message_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn_info);
  2489. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  2490. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  2491. /*
  2492. * Send section name
  2493. */
  2494. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2495. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2496. req_exec_ckpt_sectionexpirationtimeset.header.size += iovecs[1].iov_len;
  2497. if (iovecs[1].iov_len > 0) {
  2498. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2499. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2500. } else {
  2501. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2502. }
  2503. return (0);
  2504. }
  2505. int write_inv = 0;
  2506. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  2507. {
  2508. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  2509. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  2510. struct iovec iovecs[2];
  2511. struct saCkptCheckpoint *checkpoint;
  2512. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2513. log_printf (LOG_LEVEL_DEBUG, "CKPT: Received data from lib with len = %d and ref = 0x%x\n",
  2514. req_lib_ckpt_sectionwrite->dataSize,
  2515. req_lib_ckpt_sectionwrite->dataOffset);
  2516. log_printf (LOG_LEVEL_DEBUG, "CKPT: Checkpoint section being written to is %s, idLen = %d\n",
  2517. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  2518. req_lib_ckpt_sectionwrite->idLen);
  2519. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info->fd);
  2520. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionwrite->checkpointName);
  2521. if (checkpoint && (checkpoint->expired == 0)) {
  2522. /*
  2523. * checkpoint opened is writeable mode so send message to cluster
  2524. */
  2525. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  2526. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  2527. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  2528. req_lib_ckpt_sectionwrite,
  2529. sizeof (struct req_lib_ckpt_sectionwrite));
  2530. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  2531. &req_lib_ckpt_sectionwrite->checkpointName,
  2532. sizeof (SaNameT));
  2533. message_source_set (&req_exec_ckpt_sectionwrite.source, conn_info);
  2534. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  2535. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  2536. /*
  2537. * Send section name and data to write in message
  2538. */
  2539. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  2540. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  2541. req_exec_ckpt_sectionwrite.header.size += iovecs[1].iov_len;
  2542. if (iovecs[1].iov_len > 0) {
  2543. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2544. } else {
  2545. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2546. }
  2547. }
  2548. else {
  2549. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to write to Returning Error. ####\n");
  2550. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2551. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2552. res_lib_ckpt_sectionwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  2553. libais_send_response (conn_info,
  2554. &res_lib_ckpt_sectionwrite,
  2555. sizeof (struct res_lib_ckpt_sectionwrite));
  2556. }
  2557. return (0);
  2558. }
  2559. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  2560. {
  2561. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  2562. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  2563. struct iovec iovecs[2];
  2564. struct saCkptCheckpoint *checkpoint;
  2565. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2566. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2567. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionoverwrite->checkpointName);
  2568. if (checkpoint && (checkpoint->expired == 0)) {
  2569. /*
  2570. * checkpoint opened is writeable mode so send message to cluster
  2571. */
  2572. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  2573. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  2574. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  2575. req_lib_ckpt_sectionoverwrite,
  2576. sizeof (struct req_lib_ckpt_sectionoverwrite));
  2577. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  2578. &req_lib_ckpt_sectionoverwrite->checkpointName,
  2579. sizeof (SaNameT));
  2580. message_source_set (&req_exec_ckpt_sectionoverwrite.source, conn_info);
  2581. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  2582. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  2583. /*
  2584. * Send section name and data to overwrite in message
  2585. */
  2586. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  2587. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  2588. req_exec_ckpt_sectionoverwrite.header.size += iovecs[1].iov_len;
  2589. if (iovecs[1].iov_len > 0) {
  2590. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2591. } else {
  2592. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2593. }
  2594. }
  2595. else {
  2596. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to over write so Returning Error. ####\n");
  2597. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2598. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2599. res_lib_ckpt_sectionoverwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  2600. libais_send_response (conn_info,
  2601. &res_lib_ckpt_sectionoverwrite,
  2602. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2603. }
  2604. return (0);
  2605. }
  2606. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  2607. {
  2608. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  2609. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  2610. struct iovec iovecs[2];
  2611. struct saCkptCheckpoint *checkpoint;
  2612. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2613. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2614. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionread->checkpointName);
  2615. if (checkpoint && (checkpoint->expired == 0)) {
  2616. /*
  2617. * checkpoint opened is writeable mode so send message to cluster
  2618. */
  2619. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  2620. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  2621. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  2622. req_lib_ckpt_sectionread,
  2623. sizeof (struct req_lib_ckpt_sectionread));
  2624. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  2625. &req_lib_ckpt_sectionread->checkpointName,
  2626. sizeof (SaNameT));
  2627. message_source_set (&req_exec_ckpt_sectionread.source, conn_info);
  2628. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  2629. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  2630. /*
  2631. * Send section name and data to overwrite in message
  2632. */
  2633. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  2634. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  2635. req_exec_ckpt_sectionread.header.size += iovecs[1].iov_len;
  2636. if (iovecs[1].iov_len > 0) {
  2637. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2638. } else {
  2639. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2640. }
  2641. }
  2642. else {
  2643. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to read so Returning Error. ####\n");
  2644. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread);
  2645. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2646. res_lib_ckpt_sectionread.header.error = SA_AIS_ERR_NOT_EXIST;
  2647. libais_send_response (conn_info,
  2648. &res_lib_ckpt_sectionread,
  2649. sizeof (struct res_lib_ckpt_sectionread));
  2650. }
  2651. return (0);
  2652. }
  2653. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  2654. {
  2655. return (0);
  2656. }
  2657. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  2658. {
  2659. return (0);
  2660. }
  2661. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message)
  2662. {
  2663. struct req_lib_ckpt_sectioniteratorinitialize *req_lib_ckpt_sectioniteratorinitialize = (struct req_lib_ckpt_sectioniteratorinitialize *)message;
  2664. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  2665. struct saCkptCheckpoint *ckptCheckpoint;
  2666. struct saCkptCheckpointSection *ckptCheckpointSection;
  2667. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  2668. struct saCkptSectionIterator *ckptSectionIterator;
  2669. struct list_head *checkpoint_section_list;
  2670. int addEntry = 0;
  2671. int iteratorEntries = 0;
  2672. SaErrorT error = SA_AIS_OK;
  2673. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  2674. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2675. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniteratorinitialize->checkpointName);
  2676. if (ckptCheckpoint == 0) {
  2677. error = SA_AIS_ERR_NOT_EXIST;
  2678. goto error_exit;
  2679. }
  2680. /*
  2681. * Iterate list of checkpoint sections
  2682. */
  2683. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  2684. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  2685. checkpoint_section_list = checkpoint_section_list->next) {
  2686. ckptCheckpointSection = list_entry (checkpoint_section_list,
  2687. struct saCkptCheckpointSection, list);
  2688. addEntry = 1;
  2689. /*
  2690. * Item should be added to iterator list
  2691. */
  2692. if (addEntry) {
  2693. iteratorEntries += 1;
  2694. ckptSectionIteratorEntries =
  2695. realloc (ckptSectionIterator->sectionIteratorEntries,
  2696. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  2697. if (ckptSectionIteratorEntries == 0) {
  2698. if (ckptSectionIterator->sectionIteratorEntries) {
  2699. free (ckptSectionIterator->sectionIteratorEntries);
  2700. }
  2701. error = SA_AIS_ERR_NO_MEMORY;
  2702. goto error_exit;
  2703. }
  2704. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  2705. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  2706. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  2707. }
  2708. }
  2709. ckptSectionIterator->iteratorCount = iteratorEntries;
  2710. error_exit:
  2711. res_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize);
  2712. res_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  2713. res_lib_ckpt_sectioniteratorinitialize.header.error = error;
  2714. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratorinitialize,
  2715. sizeof (struct res_lib_ckpt_sectioniteratorinitialize));
  2716. return (0);
  2717. }
  2718. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  2719. {
  2720. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  2721. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  2722. struct saCkptSectionIterator *ckptSectionIterator;
  2723. SaErrorT error = SA_AIS_OK;
  2724. int sectionIdSize = 0;
  2725. int iteratorPos = 0;
  2726. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  2727. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  2728. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2729. /*
  2730. * Find active iterator entry
  2731. */
  2732. for (;;) {
  2733. /*
  2734. * No more sections in iterator
  2735. */
  2736. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  2737. error = SA_AIS_ERR_NOT_EXIST;
  2738. goto error_exit;
  2739. }
  2740. /*
  2741. * active iterator entry
  2742. */
  2743. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  2744. break;
  2745. }
  2746. ckptSectionIterator->iteratorPos += 1;
  2747. }
  2748. /*
  2749. * Prepare response to API
  2750. */
  2751. iteratorPos = ckptSectionIterator->iteratorPos;
  2752. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  2753. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  2754. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  2755. sizeof (SaCkptSectionDescriptorT));
  2756. /*
  2757. * Get to next iterator entry
  2758. */
  2759. ckptSectionIterator->iteratorPos += 1;
  2760. error_exit:
  2761. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  2762. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  2763. res_lib_ckpt_sectioniteratornext.header.error = error;
  2764. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  2765. sizeof (struct res_lib_ckpt_sectioniteratornext));
  2766. libais_send_response (conn_info,
  2767. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  2768. sectionIdSize);
  2769. return (0);
  2770. }