ckpt.c 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239
  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. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointopen->checkpointName);
  1059. /*
  1060. * If checkpoint doesn't exist, create one
  1061. */
  1062. if (ckptCheckpoint == 0) {
  1063. if ((req_lib_ckpt_checkpointopen->checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) {
  1064. error = SA_AIS_ERR_NOT_EXIST;
  1065. goto error_exit;
  1066. }
  1067. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1068. if (ckptCheckpoint == 0) {
  1069. error = SA_AIS_ERR_NO_MEMORY;
  1070. goto error_exit;
  1071. }
  1072. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1073. if (ckptCheckpointSection == 0) {
  1074. free (ckptCheckpoint);
  1075. error = SA_AIS_ERR_NO_MEMORY;
  1076. goto error_exit;
  1077. }
  1078. memcpy (&ckptCheckpoint->name,
  1079. &req_lib_ckpt_checkpointopen->checkpointName,
  1080. sizeof (SaNameT));
  1081. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1082. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  1083. sizeof (SaCkptCheckpointCreationAttributesT));
  1084. ckptCheckpoint->unlinked = 0;
  1085. list_init (&ckptCheckpoint->list);
  1086. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1087. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1088. ckptCheckpoint->referenceCount = 0;
  1089. ckptCheckpoint->retention_timer = 0;
  1090. ckptCheckpoint->expired = 0;
  1091. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_WR_ALL_REPLICAS) == 1 &&
  1092. (ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) {
  1093. ckptCheckpoint->active_replica_set = 1;
  1094. } else {
  1095. ckptCheckpoint->active_replica_set = 0;
  1096. }
  1097. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1098. /*
  1099. * Add in default checkpoint section
  1100. */
  1101. list_init (&ckptCheckpointSection->list);
  1102. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1103. /*
  1104. * Default section id
  1105. */
  1106. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1107. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1108. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1109. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1110. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1111. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1112. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1113. assert(ckptCheckpointSection->sectionData);
  1114. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1115. ckptCheckpointSection->expiration_timer = 0;
  1116. } else {
  1117. if (req_lib_ckpt_checkpointopen->checkpointCreationAttributesSet &&
  1118. memcmp (&ckptCheckpoint->checkpointCreationAttributes,
  1119. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  1120. sizeof (SaCkptCheckpointCreationAttributesT)) != 0) {
  1121. error = SA_AIS_ERR_EXIST;
  1122. goto error_exit;
  1123. }
  1124. }
  1125. /*
  1126. * If the checkpoint has been unlinked, it is an invalid name
  1127. */
  1128. if (ckptCheckpoint->unlinked) {
  1129. error = SA_AIS_ERR_NOT_EXIST; /* Is this the correct return ? */
  1130. goto error_exit;
  1131. }
  1132. /*
  1133. * Setup connection information and mark checkpoint as referenced
  1134. */
  1135. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", ckptCheckpoint);
  1136. ckptCheckpoint->referenceCount += 1;
  1137. /*
  1138. * Add the connection reference information to the Checkpoint to be
  1139. * sent out later as a part of the sync process.
  1140. *
  1141. */
  1142. proc_index = processor_index_find(&source_addr,ckptCheckpoint->ckpt_refcount);
  1143. if (proc_index == -1) {/* Could not find, lets set the processor to an index.*/
  1144. proc_index = processor_index_set(&source_addr,ckptCheckpoint->ckpt_refcount);
  1145. }
  1146. if (proc_index != -1 ) {
  1147. ckptCheckpoint->ckpt_refcount[proc_index].addr = source_addr;
  1148. ckptCheckpoint->ckpt_refcount[proc_index].count++;
  1149. }
  1150. else {
  1151. log_printf (LOG_LEVEL_ERROR,
  1152. "CKPT: MAX LIMIT OF PROCESSORS reached. Cannot store new proc %p info.\n",
  1153. ckptCheckpoint);
  1154. }
  1155. /*
  1156. * Reset retention duration since this checkpoint was just opened
  1157. */
  1158. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1159. ckptCheckpoint->retention_timer = 0;
  1160. /*
  1161. * Send error result to CKPT library
  1162. */
  1163. error_exit:
  1164. /*
  1165. * If this node was the source of the message, respond to this node
  1166. */
  1167. if (message_source_is_local(&req_exec_ckpt_checkpointopen->source)) {
  1168. /*
  1169. * If its an async call respond with the invocation and handle
  1170. */
  1171. if (req_exec_ckpt_checkpointopen->async_call) {
  1172. res_lib_ckpt_checkpointopenasync.header.size = sizeof (struct res_lib_ckpt_checkpointopenasync);
  1173. res_lib_ckpt_checkpointopenasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  1174. res_lib_ckpt_checkpointopenasync.header.error = error;
  1175. res_lib_ckpt_checkpointopenasync.checkpointHandle = req_exec_ckpt_checkpointopen->checkpointHandle;
  1176. res_lib_ckpt_checkpointopenasync.invocation = req_exec_ckpt_checkpointopen->invocation;
  1177. libais_send_response (
  1178. req_exec_ckpt_checkpointopen->source.conn_info,
  1179. &res_lib_ckpt_checkpointopenasync,
  1180. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1181. libais_send_response (
  1182. req_exec_ckpt_checkpointopen->source.conn_info->conn_info_partner,
  1183. &res_lib_ckpt_checkpointopenasync,
  1184. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1185. } else {
  1186. /*
  1187. * otherwise respond with the normal checkpointopen response
  1188. */
  1189. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  1190. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  1191. res_lib_ckpt_checkpointopen.header.error = error;
  1192. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info, &res_lib_ckpt_checkpointopen,
  1193. sizeof (struct res_lib_ckpt_checkpointopen));
  1194. }
  1195. if (error == SA_AIS_OK) {
  1196. checkpoint_cleanup = malloc (sizeof (struct checkpoint_cleanup));
  1197. if (checkpoint_cleanup == 0) {
  1198. free (ckptCheckpoint);
  1199. error = SA_AIS_ERR_NO_MEMORY;
  1200. } else {
  1201. memcpy(&checkpoint_cleanup->checkpoint,ckptCheckpoint,sizeof(struct saCkptCheckpoint));
  1202. list_add (&checkpoint_cleanup->list,
  1203. &req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  1204. }
  1205. }
  1206. }
  1207. return (0);
  1208. }
  1209. static int recovery_checkpoint_open(SaNameT *checkpointName,
  1210. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  1211. struct ckpt_refcnt *ref_cnt)
  1212. {
  1213. int i;
  1214. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1215. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1216. SaErrorT error = SA_AIS_OK;
  1217. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open %s\n", &checkpointName->value);
  1218. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open refcount Values\n");
  1219. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  1220. if (ref_cnt[i].addr.s_addr == 0) {
  1221. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc 0 and count %d\n", i,
  1222. ref_cnt[i].count);
  1223. }
  1224. else {
  1225. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc %s and count %d\n",
  1226. i,
  1227. inet_ntoa(ref_cnt[i].addr),
  1228. ref_cnt[i].count);
  1229. }
  1230. }
  1231. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1232. /*
  1233. * If checkpoint doesn't exist, create one
  1234. */
  1235. if (ckptCheckpoint == 0) {
  1236. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open Allocating new Checkpoint %s\n", &checkpointName->value);
  1237. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1238. if (ckptCheckpoint == 0) {
  1239. error = SA_AIS_ERR_NO_MEMORY;
  1240. goto error_exit;
  1241. }
  1242. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1243. if (ckptCheckpointSection == 0) {
  1244. free (ckptCheckpoint);
  1245. error = SA_AIS_ERR_NO_MEMORY;
  1246. goto error_exit;
  1247. }
  1248. memcpy (&ckptCheckpoint->name,
  1249. checkpointName,
  1250. sizeof (SaNameT));
  1251. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1252. ckptAttributes,
  1253. sizeof (SaCkptCheckpointCreationAttributesT));
  1254. ckptCheckpoint->unlinked = 0;
  1255. list_init (&ckptCheckpoint->list);
  1256. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1257. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1258. ckptCheckpoint->retention_timer = 0;
  1259. ckptCheckpoint->expired = 0;
  1260. /*
  1261. * Add in default checkpoint section
  1262. */
  1263. list_init (&ckptCheckpointSection->list);
  1264. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1265. /*
  1266. * Default section id
  1267. */
  1268. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1269. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1270. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1271. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1272. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1273. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1274. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1275. assert(ckptCheckpointSection->sectionData);
  1276. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1277. ckptCheckpointSection->expiration_timer = 0;
  1278. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1279. }
  1280. else {
  1281. /*
  1282. * Setup connection information and mark checkpoint as referenced
  1283. */
  1284. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery CHECKPOINT reopened is %p\n", ckptCheckpoint);
  1285. }
  1286. /*
  1287. * If the checkpoint has been unlinked, it is an invalid name
  1288. */
  1289. if (ckptCheckpoint->unlinked) {
  1290. error = SA_AIS_ERR_BAD_OPERATION; /* Is this the correct return ? */
  1291. goto error_exit;
  1292. }
  1293. /*CHECK to see if there are any existing ckpts*/
  1294. if ((ckptCheckpoint->ckpt_refcount) && (ckpt_refcount_total(ckptCheckpoint->ckpt_refcount) > 0)) {
  1295. log_printf (LOG_LEVEL_DEBUG,"calling merge_ckpt_refcounts\n");
  1296. merge_ckpt_refcounts(ckptCheckpoint->ckpt_refcount, ref_cnt);
  1297. }
  1298. else {
  1299. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1300. }
  1301. /*No Existing ckpts. Lets assign what we got over the network or the merged with network values*/
  1302. ckptCheckpoint->referenceCount = ckpt_refcount_total(ref_cnt);
  1303. log_printf (LOG_LEVEL_DEBUG, "CKPT: OPEN ckptCheckpoint->referenceCount %d\n",ckptCheckpoint->referenceCount);
  1304. memcpy(ckptCheckpoint->ckpt_refcount,ref_cnt,sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  1305. /*
  1306. * Reset retention duration since this checkpoint was just opened
  1307. */
  1308. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1309. ckptCheckpoint->retention_timer = 0;
  1310. /*
  1311. * Send error result to CKPT library
  1312. */
  1313. error_exit:
  1314. return (error);
  1315. }
  1316. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct in_addr source_addr, int endian_conversion_required)
  1317. {
  1318. int retcode;
  1319. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1320. = (struct req_exec_ckpt_synchronize_state *)message;
  1321. /*
  1322. * If the Incoming message's previous ring id == saved_ring_id
  1323. * Ignore because we have seen this message before.
  1324. */
  1325. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1326. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1327. return(0);
  1328. }
  1329. retcode = recovery_checkpoint_open(&req_exec_ckpt_sync_state->checkpointName,
  1330. &req_exec_ckpt_sync_state->checkpointCreationAttributes,
  1331. req_exec_ckpt_sync_state->ckpt_refcount);
  1332. if (retcode != SA_AIS_OK) {
  1333. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1334. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open returned %d\n",retcode);
  1335. }
  1336. retcode = recovery_section_create (&req_exec_ckpt_sync_state->sectionDescriptor,
  1337. &req_exec_ckpt_sync_state->checkpointName,
  1338. (char*)req_exec_ckpt_sync_state
  1339. + sizeof (struct req_exec_ckpt_synchronize_state));
  1340. if (retcode != SA_AIS_OK) {
  1341. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1342. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_section_create returned %d\n",retcode);
  1343. }
  1344. return (0);
  1345. }
  1346. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct in_addr source_addr, int endian_conversion_required)
  1347. {
  1348. int retcode;
  1349. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1350. = (struct req_exec_ckpt_synchronize_section *)message;
  1351. /*
  1352. * If the Incoming message's previous ring id == saved_ring_id
  1353. * Ignore because we have seen this message before.
  1354. */
  1355. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1356. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1357. return(0);
  1358. }
  1359. /*
  1360. * Write the contents of the section to the checkpoint section.
  1361. */
  1362. retcode = recovery_section_write(req_exec_ckpt_sync_section->sectionId.idLen,
  1363. (char*)req_exec_ckpt_sync_section
  1364. + sizeof (struct req_exec_ckpt_synchronize_section),
  1365. &req_exec_ckpt_sync_section->checkpointName,
  1366. (char*)req_exec_ckpt_sync_section
  1367. + sizeof (struct req_exec_ckpt_synchronize_section)
  1368. + req_exec_ckpt_sync_section->sectionId.idLen,
  1369. req_exec_ckpt_sync_section->dataOffSet,
  1370. req_exec_ckpt_sync_section->dataSize);
  1371. if (retcode != SA_AIS_OK) {
  1372. log_printf(LOG_LEVEL_ERROR, "CKPT: message_handler_req_exec_ckpt_synchronize_section\n");
  1373. log_printf(LOG_LEVEL_ERROR, "CKPT: recovery_section_write returned %d\n",retcode);
  1374. }
  1375. return (0);
  1376. }
  1377. unsigned int abstime_to_msec (SaTimeT time)
  1378. {
  1379. struct timeval tv;
  1380. unsigned long long curr_time;
  1381. unsigned long long msec_time;
  1382. gettimeofday (&tv, NULL);
  1383. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1384. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1385. msec_time = (((unsigned long long)time) / 1000000) -
  1386. (unsigned long long)curr_time;
  1387. return ((unsigned int)(msec_time));
  1388. }
  1389. void timer_function_section_expire (void *data)
  1390. {
  1391. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1392. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1393. struct ckpt_identifier *ckpt_id = 0;
  1394. ckpt_id = (struct ckpt_identifier *)data;
  1395. log_printf (LOG_LEVEL_DEBUG, "CKPT: timer_function_section_expire data = 0x%x \n",data);
  1396. if (ckpt_id->ckpt_section_id.idLen && ckpt_id->ckpt_section_id.id) {
  1397. log_printf (LOG_LEVEL_DEBUG, "CKPT: Attempting to Expire section %s in ckpt %s\n",
  1398. ckpt_id->ckpt_section_id.id,
  1399. (char *)&ckpt_id->ckpt_name.value);
  1400. }
  1401. else {
  1402. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire data incorect\n");
  1403. goto free_mem;
  1404. }
  1405. ckptCheckpoint = ckpt_checkpoint_find_global (&ckpt_id->ckpt_name);
  1406. if (ckptCheckpoint == 0) {
  1407. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find ckpt %s\n",
  1408. (char *)&ckpt_id->ckpt_name.value);
  1409. goto free_mem;
  1410. }
  1411. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1412. ckpt_id->ckpt_section_id.id,
  1413. (int)ckpt_id->ckpt_section_id.idLen);
  1414. if (ckptCheckpointSection == 0) {
  1415. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find section %s in ckpt %s\n",
  1416. ckpt_id->ckpt_section_id.id,
  1417. (char *)&ckpt_id->ckpt_name.value);
  1418. goto free_mem;
  1419. }
  1420. log_printf (LOG_LEVEL_DEBUG, "CKPT: Expiring section %s in ckpt %s\n",
  1421. ckpt_id->ckpt_section_id.id,
  1422. (char *)&ckpt_id->ckpt_name.value);
  1423. checkpoint_section_release (ckptCheckpointSection);
  1424. free_mem :
  1425. free (ckpt_id);
  1426. }
  1427. void timer_function_retention (void *data)
  1428. {
  1429. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  1430. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  1431. struct iovec iovec;
  1432. checkpoint->retention_timer = 0;
  1433. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  1434. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  1435. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  1436. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  1437. &checkpoint->name,
  1438. sizeof (SaNameT));
  1439. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  1440. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  1441. assert (totempg_mcast (&iovec, 1, TOTEMPG_AGREED) == 0);
  1442. }
  1443. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required)
  1444. {
  1445. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  1446. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  1447. struct saCkptCheckpoint *checkpoint = 0;
  1448. SaAisErrorT error = SA_AIS_OK;
  1449. int proc_index;
  1450. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  1451. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointclose->checkpointName);
  1452. if (checkpoint == 0) {
  1453. goto error_exit;
  1454. }
  1455. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1456. checkpoint->referenceCount--;
  1457. /*
  1458. * Modify the connection reference information to the Checkpoint to be
  1459. * sent out later as a part of the sync process.
  1460. */
  1461. proc_index = processor_index_find(&source_addr, checkpoint->ckpt_refcount);
  1462. if (proc_index != -1 ) {
  1463. checkpoint->ckpt_refcount[proc_index].count--;
  1464. }
  1465. else {
  1466. log_printf (LOG_LEVEL_ERROR,
  1467. "CKPT: Could Not find Processor Info %p info.\n",
  1468. checkpoint);
  1469. }
  1470. assert (checkpoint->referenceCount >= 0);
  1471. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  1472. checkpoint->referenceCount);
  1473. /*
  1474. * If checkpoint has been unlinked and this is the last reference, delete it
  1475. */
  1476. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  1477. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  1478. checkpoint_release (checkpoint);
  1479. } else
  1480. if (checkpoint->referenceCount == 0) {
  1481. poll_timer_add (aisexec_poll_handle,
  1482. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1483. checkpoint,
  1484. timer_function_retention,
  1485. &checkpoint->retention_timer);
  1486. }
  1487. error_exit:
  1488. if (message_source_is_local(&req_exec_ckpt_checkpointclose->source)) {
  1489. ckpt_checkpoint_remove_cleanup (req_exec_ckpt_checkpointclose->source.conn_info,
  1490. checkpoint);
  1491. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  1492. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  1493. res_lib_ckpt_checkpointclose.header.error = error;
  1494. libais_send_response (req_exec_ckpt_checkpointclose->source.conn_info,
  1495. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  1496. }
  1497. return (0);
  1498. }
  1499. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required)
  1500. {
  1501. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  1502. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  1503. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  1504. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1505. SaErrorT error = SA_AIS_OK;
  1506. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  1507. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointunlink->checkpointName);
  1508. if (ckptCheckpoint == 0) {
  1509. error = SA_AIS_ERR_NOT_EXIST;
  1510. goto error_exit;
  1511. }
  1512. if (ckptCheckpoint->unlinked) {
  1513. error = SA_AIS_ERR_INVALID_PARAM;
  1514. goto error_exit;
  1515. }
  1516. ckptCheckpoint->unlinked = 1;
  1517. /*
  1518. * Immediately delete entry if reference count is zero
  1519. */
  1520. if (ckptCheckpoint->referenceCount == 0) {
  1521. /*
  1522. * Remove retention timer since this checkpoint was unlinked and is no
  1523. * longer referenced
  1524. */
  1525. checkpoint_release (ckptCheckpoint);
  1526. }
  1527. else if ( ckptCheckpoint->referenceCount > 0 ) {
  1528. ckptCheckpoint->unlinked = 0;
  1529. ckptCheckpoint->expired = 0;
  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. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2221. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2222. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2223. return (0);
  2224. }
  2225. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  2226. {
  2227. struct req_lib_ckpt_checkpointopenasync *req_lib_ckpt_checkpointopenasync = (struct req_lib_ckpt_checkpointopenasync *)message;
  2228. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2229. struct iovec iovecs[2];
  2230. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint async.\n");
  2231. req_exec_ckpt_checkpointopen.header.size =
  2232. sizeof (struct req_exec_ckpt_checkpointopen);
  2233. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  2234. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  2235. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2236. req_lib_ckpt_checkpointopenasync,
  2237. sizeof (struct req_lib_ckpt_checkpointopen));
  2238. req_exec_ckpt_checkpointopen.async_call = 1;
  2239. req_exec_ckpt_checkpointopen.invocation = req_lib_ckpt_checkpointopenasync->invocation;
  2240. req_exec_ckpt_checkpointopen.checkpointHandle = req_lib_ckpt_checkpointopenasync->checkpointHandle;
  2241. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2242. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2243. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2244. return (0);
  2245. }
  2246. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message) {
  2247. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)message;
  2248. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  2249. struct iovec iovecs[2];
  2250. struct saCkptCheckpoint *checkpoint;
  2251. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  2252. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointclose->checkpointName);
  2253. if (checkpoint && (checkpoint->expired == 0)) {
  2254. req_exec_ckpt_checkpointclose.header.size =
  2255. sizeof (struct req_exec_ckpt_checkpointclose);
  2256. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  2257. message_source_set (&req_exec_ckpt_checkpointclose.source, conn_info);
  2258. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  2259. &req_lib_ckpt_checkpointclose->checkpointName, sizeof (SaNameT));
  2260. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  2261. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  2262. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  2263. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2264. }
  2265. }
  2266. else {
  2267. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to close so Returning Error. ####\n");
  2268. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  2269. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  2270. res_lib_ckpt_checkpointclose.header.error = SA_AIS_ERR_NOT_EXIST;
  2271. libais_send_response (conn_info,
  2272. &res_lib_ckpt_checkpointclose,
  2273. sizeof (struct res_lib_ckpt_checkpointclose));
  2274. }
  2275. return (0);
  2276. }
  2277. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  2278. {
  2279. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  2280. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  2281. struct iovec iovecs[2];
  2282. req_exec_ckpt_checkpointunlink.header.size =
  2283. sizeof (struct req_exec_ckpt_checkpointunlink);
  2284. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  2285. message_source_set (&req_exec_ckpt_checkpointunlink.source, conn_info);
  2286. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  2287. req_lib_ckpt_checkpointunlink,
  2288. sizeof (struct req_lib_ckpt_checkpointunlink));
  2289. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  2290. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  2291. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2292. return (0);
  2293. }
  2294. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  2295. {
  2296. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  2297. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  2298. struct iovec iovecs[2];
  2299. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info->fd);
  2300. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  2301. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  2302. message_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn_info);
  2303. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  2304. &req_lib_ckpt_checkpointretentiondurationset->checkpointName,
  2305. sizeof (SaNameT));
  2306. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  2307. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  2308. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  2309. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2310. return (0);
  2311. }
  2312. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message)
  2313. {
  2314. struct req_lib_ckpt_activereplicaset *req_lib_ckpt_activereplicaset = (struct req_lib_ckpt_activereplicaset *)message;
  2315. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  2316. struct saCkptCheckpoint *checkpoint;
  2317. SaAisErrorT error = SA_AIS_OK;
  2318. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_activereplicaset->checkpointName);
  2319. /*
  2320. * Make sure checkpoint is collocated and async update option
  2321. */
  2322. if (((checkpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) ||
  2323. (checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2324. error = SA_AIS_ERR_BAD_OPERATION;
  2325. }
  2326. checkpoint->active_replica_set = 1;
  2327. res_lib_ckpt_activereplicaset.header.size = sizeof (struct res_lib_ckpt_activereplicaset);
  2328. res_lib_ckpt_activereplicaset.header.id = MESSAGE_RES_CKPT_ACTIVEREPLICASET;
  2329. res_lib_ckpt_activereplicaset.header.error = error;
  2330. libais_send_response (conn_info, &res_lib_ckpt_activereplicaset,
  2331. sizeof (struct res_lib_ckpt_activereplicaset));
  2332. return (0);
  2333. }
  2334. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  2335. {
  2336. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  2337. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  2338. struct saCkptCheckpoint *checkpoint;
  2339. int memoryUsed = 0;
  2340. int numberOfSections = 0;
  2341. struct list_head *checkpoint_section_list;
  2342. struct saCkptCheckpointSection *checkpointSection;
  2343. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  2344. /*
  2345. * Count memory used by checkpoint sections
  2346. */
  2347. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointstatusget->checkpointName);
  2348. if (checkpoint && (checkpoint->expired == 0)) {
  2349. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  2350. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  2351. checkpoint_section_list = checkpoint_section_list->next) {
  2352. checkpointSection = list_entry (checkpoint_section_list,
  2353. struct saCkptCheckpointSection, list);
  2354. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  2355. numberOfSections += 1;
  2356. }
  2357. /*
  2358. * Build checkpoint status get response
  2359. */
  2360. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2361. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2362. if (checkpoint->active_replica_set == 1) {
  2363. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  2364. } else {
  2365. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2366. }
  2367. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointDescriptor.checkpointCreationAttributes,
  2368. &checkpoint->checkpointCreationAttributes,
  2369. sizeof (SaCkptCheckpointCreationAttributesT));
  2370. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.numberOfSections = numberOfSections;
  2371. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.memoryUsed = memoryUsed;
  2372. }
  2373. else {
  2374. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint's status so Returning Error. ####\n");
  2375. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2376. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2377. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2378. }
  2379. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  2380. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  2381. sizeof (struct res_lib_ckpt_checkpointstatusget));
  2382. return (0);
  2383. }
  2384. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  2385. {
  2386. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  2387. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  2388. struct iovec iovecs[2];
  2389. struct saCkptCheckpoint *checkpoint;
  2390. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  2391. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info->fd);
  2392. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioncreate->checkpointName);
  2393. if (checkpoint && (checkpoint->expired == 0)) {
  2394. /*
  2395. * checkpoint opened is writeable mode so send message to cluster
  2396. */
  2397. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  2398. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  2399. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  2400. req_lib_ckpt_sectioncreate,
  2401. sizeof (struct req_lib_ckpt_sectioncreate));
  2402. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  2403. &req_lib_ckpt_sectioncreate->checkpointName,
  2404. sizeof (SaNameT));
  2405. message_source_set (&req_exec_ckpt_sectioncreate.source, conn_info);
  2406. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  2407. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  2408. /*
  2409. * Send section name and initial data in message
  2410. */
  2411. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  2412. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  2413. req_exec_ckpt_sectioncreate.header.size += iovecs[1].iov_len;
  2414. if (iovecs[1].iov_len) {
  2415. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_lib_ckpt_sectioncreate Section = %s, idLen = %d\n",
  2416. iovecs[1].iov_base,
  2417. iovecs[1].iov_len);
  2418. }
  2419. #ifdef DEBUG
  2420. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  2421. iovecs[1].iov_len);
  2422. printf ("|\n");
  2423. { int i;
  2424. char *abc = iovecs[1].iov_base;
  2425. for (i = 0; i < 14;i++) {
  2426. printf ("%c ", abc[i]);
  2427. }
  2428. }
  2429. printf ("|\n");
  2430. #endif
  2431. if (iovecs[1].iov_len > 0) {
  2432. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2433. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2434. } else {
  2435. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2436. }
  2437. }
  2438. else {
  2439. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to create a section in so Returning Error. ####\n");
  2440. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  2441. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  2442. res_lib_ckpt_sectioncreate.header.error = SA_AIS_ERR_NOT_EXIST;
  2443. libais_send_response (conn_info,
  2444. &res_lib_ckpt_sectioncreate,
  2445. sizeof (struct res_lib_ckpt_sectioncreate));
  2446. }
  2447. return (0);
  2448. }
  2449. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  2450. {
  2451. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  2452. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  2453. struct iovec iovecs[2];
  2454. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info->fd);
  2455. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  2456. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  2457. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  2458. &req_lib_ckpt_sectiondelete->checkpointName,
  2459. sizeof (SaNameT));
  2460. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  2461. req_lib_ckpt_sectiondelete,
  2462. sizeof (struct req_lib_ckpt_sectiondelete));
  2463. message_source_set (&req_exec_ckpt_sectiondelete.source, conn_info);
  2464. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  2465. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  2466. /*
  2467. * Send section name
  2468. */
  2469. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  2470. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  2471. req_exec_ckpt_sectiondelete.header.size += iovecs[1].iov_len;
  2472. if (iovecs[1].iov_len > 0) {
  2473. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2474. } else {
  2475. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2476. }
  2477. return (0);
  2478. }
  2479. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  2480. {
  2481. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  2482. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  2483. struct iovec iovecs[2];
  2484. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info->fd);
  2485. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  2486. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  2487. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  2488. &req_lib_ckpt_sectionexpirationtimeset->checkpointName,
  2489. sizeof (SaNameT));
  2490. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  2491. req_lib_ckpt_sectionexpirationtimeset,
  2492. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  2493. message_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn_info);
  2494. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  2495. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  2496. /*
  2497. * Send section name
  2498. */
  2499. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2500. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2501. req_exec_ckpt_sectionexpirationtimeset.header.size += iovecs[1].iov_len;
  2502. if (iovecs[1].iov_len > 0) {
  2503. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2504. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2505. } else {
  2506. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2507. }
  2508. return (0);
  2509. }
  2510. int write_inv = 0;
  2511. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  2512. {
  2513. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  2514. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  2515. struct iovec iovecs[2];
  2516. struct saCkptCheckpoint *checkpoint;
  2517. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2518. log_printf (LOG_LEVEL_DEBUG, "CKPT: Received data from lib with len = %d and ref = 0x%x\n",
  2519. req_lib_ckpt_sectionwrite->dataSize,
  2520. req_lib_ckpt_sectionwrite->dataOffset);
  2521. log_printf (LOG_LEVEL_DEBUG, "CKPT: Checkpoint section being written to is %s, idLen = %d\n",
  2522. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  2523. req_lib_ckpt_sectionwrite->idLen);
  2524. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info->fd);
  2525. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionwrite->checkpointName);
  2526. if (checkpoint && (checkpoint->expired == 0)) {
  2527. /*
  2528. * checkpoint opened is writeable mode so send message to cluster
  2529. */
  2530. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  2531. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  2532. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  2533. req_lib_ckpt_sectionwrite,
  2534. sizeof (struct req_lib_ckpt_sectionwrite));
  2535. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  2536. &req_lib_ckpt_sectionwrite->checkpointName,
  2537. sizeof (SaNameT));
  2538. message_source_set (&req_exec_ckpt_sectionwrite.source, conn_info);
  2539. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  2540. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  2541. /*
  2542. * Send section name and data to write in message
  2543. */
  2544. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  2545. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  2546. req_exec_ckpt_sectionwrite.header.size += iovecs[1].iov_len;
  2547. if (iovecs[1].iov_len > 0) {
  2548. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2549. } else {
  2550. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2551. }
  2552. }
  2553. else {
  2554. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to write to Returning Error. ####\n");
  2555. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2556. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2557. res_lib_ckpt_sectionwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  2558. libais_send_response (conn_info,
  2559. &res_lib_ckpt_sectionwrite,
  2560. sizeof (struct res_lib_ckpt_sectionwrite));
  2561. }
  2562. return (0);
  2563. }
  2564. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  2565. {
  2566. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  2567. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  2568. struct iovec iovecs[2];
  2569. struct saCkptCheckpoint *checkpoint;
  2570. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2571. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2572. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionoverwrite->checkpointName);
  2573. if (checkpoint && (checkpoint->expired == 0)) {
  2574. /*
  2575. * checkpoint opened is writeable mode so send message to cluster
  2576. */
  2577. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  2578. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  2579. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  2580. req_lib_ckpt_sectionoverwrite,
  2581. sizeof (struct req_lib_ckpt_sectionoverwrite));
  2582. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  2583. &req_lib_ckpt_sectionoverwrite->checkpointName,
  2584. sizeof (SaNameT));
  2585. message_source_set (&req_exec_ckpt_sectionoverwrite.source, conn_info);
  2586. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  2587. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  2588. /*
  2589. * Send section name and data to overwrite in message
  2590. */
  2591. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  2592. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  2593. req_exec_ckpt_sectionoverwrite.header.size += iovecs[1].iov_len;
  2594. if (iovecs[1].iov_len > 0) {
  2595. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2596. } else {
  2597. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2598. }
  2599. }
  2600. else {
  2601. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to over write so Returning Error. ####\n");
  2602. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2603. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2604. res_lib_ckpt_sectionoverwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  2605. libais_send_response (conn_info,
  2606. &res_lib_ckpt_sectionoverwrite,
  2607. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2608. }
  2609. return (0);
  2610. }
  2611. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  2612. {
  2613. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  2614. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  2615. struct iovec iovecs[2];
  2616. struct saCkptCheckpoint *checkpoint;
  2617. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2618. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2619. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionread->checkpointName);
  2620. if (checkpoint && (checkpoint->expired == 0)) {
  2621. /*
  2622. * checkpoint opened is writeable mode so send message to cluster
  2623. */
  2624. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  2625. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  2626. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  2627. req_lib_ckpt_sectionread,
  2628. sizeof (struct req_lib_ckpt_sectionread));
  2629. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  2630. &req_lib_ckpt_sectionread->checkpointName,
  2631. sizeof (SaNameT));
  2632. message_source_set (&req_exec_ckpt_sectionread.source, conn_info);
  2633. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  2634. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  2635. /*
  2636. * Send section name and data to overwrite in message
  2637. */
  2638. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  2639. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  2640. req_exec_ckpt_sectionread.header.size += iovecs[1].iov_len;
  2641. if (iovecs[1].iov_len > 0) {
  2642. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2643. } else {
  2644. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2645. }
  2646. }
  2647. else {
  2648. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to read so Returning Error. ####\n");
  2649. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread);
  2650. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2651. res_lib_ckpt_sectionread.header.error = SA_AIS_ERR_NOT_EXIST;
  2652. libais_send_response (conn_info,
  2653. &res_lib_ckpt_sectionread,
  2654. sizeof (struct res_lib_ckpt_sectionread));
  2655. }
  2656. return (0);
  2657. }
  2658. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  2659. {
  2660. return (0);
  2661. }
  2662. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  2663. {
  2664. return (0);
  2665. }
  2666. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message)
  2667. {
  2668. struct req_lib_ckpt_sectioniteratorinitialize *req_lib_ckpt_sectioniteratorinitialize = (struct req_lib_ckpt_sectioniteratorinitialize *)message;
  2669. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  2670. struct saCkptCheckpoint *ckptCheckpoint;
  2671. struct saCkptCheckpointSection *ckptCheckpointSection;
  2672. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  2673. struct saCkptSectionIterator *ckptSectionIterator;
  2674. struct list_head *checkpoint_section_list;
  2675. int addEntry = 0;
  2676. int iteratorEntries = 0;
  2677. SaErrorT error = SA_AIS_OK;
  2678. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  2679. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2680. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniteratorinitialize->checkpointName);
  2681. if (ckptCheckpoint == 0) {
  2682. error = SA_AIS_ERR_NOT_EXIST;
  2683. goto error_exit;
  2684. }
  2685. /*
  2686. * Iterate list of checkpoint sections
  2687. */
  2688. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  2689. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  2690. checkpoint_section_list = checkpoint_section_list->next) {
  2691. ckptCheckpointSection = list_entry (checkpoint_section_list,
  2692. struct saCkptCheckpointSection, list);
  2693. addEntry = 1;
  2694. /*
  2695. * Item should be added to iterator list
  2696. */
  2697. if (addEntry) {
  2698. iteratorEntries += 1;
  2699. ckptSectionIteratorEntries =
  2700. realloc (ckptSectionIterator->sectionIteratorEntries,
  2701. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  2702. if (ckptSectionIteratorEntries == 0) {
  2703. if (ckptSectionIterator->sectionIteratorEntries) {
  2704. free (ckptSectionIterator->sectionIteratorEntries);
  2705. }
  2706. error = SA_AIS_ERR_NO_MEMORY;
  2707. goto error_exit;
  2708. }
  2709. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  2710. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  2711. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  2712. }
  2713. }
  2714. ckptSectionIterator->iteratorCount = iteratorEntries;
  2715. error_exit:
  2716. res_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize);
  2717. res_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  2718. res_lib_ckpt_sectioniteratorinitialize.header.error = error;
  2719. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratorinitialize,
  2720. sizeof (struct res_lib_ckpt_sectioniteratorinitialize));
  2721. return (0);
  2722. }
  2723. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  2724. {
  2725. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  2726. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  2727. struct saCkptSectionIterator *ckptSectionIterator;
  2728. SaErrorT error = SA_AIS_OK;
  2729. int sectionIdSize = 0;
  2730. int iteratorPos = 0;
  2731. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  2732. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  2733. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2734. /*
  2735. * Find active iterator entry
  2736. */
  2737. for (;;) {
  2738. /*
  2739. * No more sections in iterator
  2740. */
  2741. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  2742. error = SA_AIS_ERR_NOT_EXIST;
  2743. goto error_exit;
  2744. }
  2745. /*
  2746. * active iterator entry
  2747. */
  2748. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  2749. break;
  2750. }
  2751. ckptSectionIterator->iteratorPos += 1;
  2752. }
  2753. /*
  2754. * Prepare response to API
  2755. */
  2756. iteratorPos = ckptSectionIterator->iteratorPos;
  2757. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  2758. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  2759. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  2760. sizeof (SaCkptSectionDescriptorT));
  2761. /*
  2762. * Get to next iterator entry
  2763. */
  2764. ckptSectionIterator->iteratorPos += 1;
  2765. error_exit:
  2766. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  2767. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  2768. res_lib_ckpt_sectioniteratornext.header.error = error;
  2769. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  2770. sizeof (struct res_lib_ckpt_sectioniteratornext));
  2771. libais_send_response (conn_info,
  2772. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  2773. sectionIdSize);
  2774. return (0);
  2775. }