ckpt.c 131 KB

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