ckpt.c 132 KB

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