ckpt.c 120 KB

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