ckpt.c 123 KB

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