ckpt.c 127 KB

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