ckpt.c 102 KB

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