ckpt.c 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816
  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_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. if ((req_lib_ckpt_checkpointopen->checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) {
  889. error = SA_AIS_ERR_NOT_EXIST;
  890. goto error_exit;
  891. }
  892. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  893. if (ckptCheckpoint == 0) {
  894. error = SA_AIS_ERR_NO_MEMORY;
  895. goto error_exit;
  896. }
  897. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  898. if (ckptCheckpointSection == 0) {
  899. free (ckptCheckpoint);
  900. error = SA_AIS_ERR_NO_MEMORY;
  901. goto error_exit;
  902. }
  903. memcpy (&ckptCheckpoint->name,
  904. &req_lib_ckpt_checkpointopen->checkpointName,
  905. sizeof (SaNameT));
  906. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  907. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  908. sizeof (SaCkptCheckpointCreationAttributesT));
  909. ckptCheckpoint->unlinked = 0;
  910. list_init (&ckptCheckpoint->list);
  911. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  912. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  913. ckptCheckpoint->referenceCount = 0;
  914. ckptCheckpoint->retention_timer = 0;
  915. ckptCheckpoint->expired = 0;
  916. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  917. /*
  918. * Add in default checkpoint section
  919. */
  920. list_init (&ckptCheckpointSection->list);
  921. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  922. /*
  923. * Default section id
  924. */
  925. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  926. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  927. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  928. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  929. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  930. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  931. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  932. assert(ckptCheckpointSection->sectionData);
  933. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  934. ckptCheckpointSection->expiration_timer = 0;
  935. } else {
  936. if (req_lib_ckpt_checkpointopen->checkpointCreationAttributesSet &&
  937. memcmp (&ckptCheckpoint->checkpointCreationAttributes,
  938. &req_lib_ckpt_checkpointopen->checkpointCreationAttributesSet,
  939. sizeof (SaCkptCheckpointCreationAttributesT)) == 0) {
  940. error = SA_AIS_ERR_EXIST;
  941. goto error_exit;
  942. }
  943. }
  944. /*
  945. * If the checkpoint has been unlinked, it is an invalid name
  946. */
  947. if (ckptCheckpoint->unlinked) {
  948. error = SA_AIS_ERR_INVALID_PARAM; /* Is this the correct return ? */
  949. goto error_exit;
  950. }
  951. /*
  952. * Setup connection information and mark checkpoint as referenced
  953. */
  954. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", ckptCheckpoint);
  955. ckptCheckpoint->referenceCount += 1;
  956. /*
  957. * Add the connection reference information to the Checkpoint to be
  958. * sent out later as a part of the sync process.
  959. *
  960. */
  961. proc_index = processor_index_find(&source_addr,ckptCheckpoint->ckpt_refcount);
  962. if (proc_index == -1) {/* Could not find, lets set the processor to an index.*/
  963. proc_index = processor_index_set(&source_addr,ckptCheckpoint->ckpt_refcount);
  964. }
  965. if (proc_index != -1 ) {
  966. ckptCheckpoint->ckpt_refcount[proc_index].addr = source_addr;
  967. ckptCheckpoint->ckpt_refcount[proc_index].count++;
  968. }
  969. else {
  970. log_printf (LOG_LEVEL_ERROR,
  971. "CKPT: MAX LIMIT OF PROCESSORS reached. Cannot store new proc %p info.\n",
  972. ckptCheckpoint);
  973. }
  974. /*
  975. * Reset retention duration since this checkpoint was just opened
  976. */
  977. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  978. ckptCheckpoint->retention_timer = 0;
  979. /*
  980. * Send error result to CKPT library
  981. */
  982. error_exit:
  983. /*
  984. * If this node was the source of the message, respond to this node
  985. */
  986. if (message_source_is_local(&req_exec_ckpt_checkpointopen->source)) {
  987. /*
  988. * If its an async call respond with the invocation and handle
  989. */
  990. if (req_exec_ckpt_checkpointopen->async_call) {
  991. res_lib_ckpt_checkpointopenasync.header.size = sizeof (struct res_lib_ckpt_checkpointopenasync);
  992. res_lib_ckpt_checkpointopenasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  993. res_lib_ckpt_checkpointopenasync.header.error = error;
  994. res_lib_ckpt_checkpointopenasync.checkpointHandle = req_exec_ckpt_checkpointopen->checkpointHandle;
  995. res_lib_ckpt_checkpointopenasync.invocation = req_exec_ckpt_checkpointopen->invocation;
  996. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info->conn_info_partner,
  997. &res_lib_ckpt_checkpointopenasync,
  998. sizeof (struct res_lib_ckpt_checkpointopenasync));
  999. } else {
  1000. /*
  1001. * otherwise respond with the normal checkpointopen response
  1002. */
  1003. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  1004. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  1005. res_lib_ckpt_checkpointopen.header.error = error;
  1006. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info, &res_lib_ckpt_checkpointopen,
  1007. sizeof (struct res_lib_ckpt_checkpointopen));
  1008. }
  1009. if (error == SA_AIS_OK) {
  1010. checkpoint_cleanup = malloc (sizeof (struct checkpoint_cleanup));
  1011. if (checkpoint_cleanup == 0) {
  1012. free (ckptCheckpoint);
  1013. error = SA_AIS_ERR_NO_MEMORY;
  1014. } else {
  1015. memcpy(&checkpoint_cleanup->checkpoint,ckptCheckpoint,sizeof(struct saCkptCheckpoint));
  1016. list_add (&checkpoint_cleanup->list,
  1017. &req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  1018. }
  1019. }
  1020. }
  1021. return (0);
  1022. }
  1023. static int recovery_checkpoint_open(SaNameT *checkpointName,
  1024. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  1025. struct ckpt_refcnt *ref_cnt)
  1026. {
  1027. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1028. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1029. SaErrorT error = SA_AIS_OK;
  1030. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open %s\n", &checkpointName->value);
  1031. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1032. /*
  1033. * If checkpoint doesn't exist, create one
  1034. */
  1035. if (ckptCheckpoint == 0) {
  1036. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1037. if (ckptCheckpoint == 0) {
  1038. error = SA_AIS_ERR_NO_MEMORY;
  1039. goto error_exit;
  1040. }
  1041. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1042. if (ckptCheckpointSection == 0) {
  1043. free (ckptCheckpoint);
  1044. error = SA_AIS_ERR_NO_MEMORY;
  1045. goto error_exit;
  1046. }
  1047. memcpy (&ckptCheckpoint->name,
  1048. checkpointName,
  1049. sizeof (SaNameT));
  1050. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1051. ckptAttributes,
  1052. sizeof (SaCkptCheckpointCreationAttributesT));
  1053. ckptCheckpoint->unlinked = 0;
  1054. list_init (&ckptCheckpoint->list);
  1055. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1056. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1057. ckptCheckpoint->retention_timer = 0;
  1058. ckptCheckpoint->expired = 0;
  1059. /*
  1060. * Add in default checkpoint section
  1061. */
  1062. list_init (&ckptCheckpointSection->list);
  1063. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1064. /*
  1065. * Default section id
  1066. */
  1067. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1068. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1069. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1070. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1071. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1072. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1073. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1074. assert(ckptCheckpointSection->sectionData);
  1075. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1076. ckptCheckpointSection->expiration_timer = 0;
  1077. }
  1078. /*
  1079. * If the checkpoint has been unlinked, it is an invalid name
  1080. */
  1081. if (ckptCheckpoint->unlinked) {
  1082. error = SA_AIS_ERR_BAD_CHECKPOINT; /* Is this the correct return ? */
  1083. goto error_exit;
  1084. }
  1085. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1086. ckptCheckpoint->referenceCount = ckpt_refcount_total(ref_cnt);
  1087. log_printf (LOG_LEVEL_DEBUG, "CKPT: OPEN ckptCheckpoint->referenceCount %d\n",ckptCheckpoint->referenceCount);
  1088. memcpy(ckptCheckpoint->ckpt_refcount,ref_cnt,sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  1089. /*
  1090. * Setup connection information and mark checkpoint as referenced
  1091. */
  1092. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery CHECKPOINT reopened is %p\n", ckptCheckpoint);
  1093. /*
  1094. * Reset retention duration since this checkpoint was just opened
  1095. */
  1096. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1097. ckptCheckpoint->retention_timer = 0;
  1098. /*
  1099. * Send error result to CKPT library
  1100. */
  1101. error_exit:
  1102. return (error);
  1103. }
  1104. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct in_addr source_addr, int endian_conversion_required)
  1105. {
  1106. int retcode;
  1107. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1108. = (struct req_exec_ckpt_synchronize_state *)message;
  1109. /*
  1110. * If the Incoming message's previous ring id == saved_ring_id
  1111. * Ignore because we have seen this message before.
  1112. */
  1113. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1114. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1115. return(0);
  1116. }
  1117. retcode = recovery_checkpoint_open(&req_exec_ckpt_sync_state->checkpointName,
  1118. &req_exec_ckpt_sync_state->checkpointCreationAttributes,
  1119. req_exec_ckpt_sync_state->ckpt_refcount);
  1120. if (retcode != SA_AIS_OK) {
  1121. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1122. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open returned %d\n",retcode);
  1123. }
  1124. retcode = recovery_section_create (&req_exec_ckpt_sync_state->sectionDescriptor,
  1125. &req_exec_ckpt_sync_state->checkpointName,
  1126. (char*)req_exec_ckpt_sync_state
  1127. + sizeof (struct req_exec_ckpt_synchronize_state));
  1128. if (retcode != SA_AIS_OK) {
  1129. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1130. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_section_create returned %d\n",retcode);
  1131. }
  1132. return (0);
  1133. }
  1134. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct in_addr source_addr, int endian_conversion_required)
  1135. {
  1136. int retcode;
  1137. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1138. = (struct req_exec_ckpt_synchronize_section *)message;
  1139. /*
  1140. * If the Incoming message's previous ring id == saved_ring_id
  1141. * Ignore because we have seen this message before.
  1142. */
  1143. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1144. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1145. return(0);
  1146. }
  1147. /*
  1148. * Write the contents of the section to the checkpoint section.
  1149. */
  1150. retcode = recovery_section_write(req_exec_ckpt_sync_section->sectionId.idLen,
  1151. (char*)req_exec_ckpt_sync_section
  1152. + sizeof (struct req_exec_ckpt_synchronize_section),
  1153. &req_exec_ckpt_sync_section->checkpointName,
  1154. (char*)req_exec_ckpt_sync_section
  1155. + sizeof (struct req_exec_ckpt_synchronize_section)
  1156. + req_exec_ckpt_sync_section->sectionId.idLen,
  1157. req_exec_ckpt_sync_section->dataOffSet,
  1158. req_exec_ckpt_sync_section->dataSize);
  1159. if (retcode != SA_AIS_OK) {
  1160. log_printf(LOG_LEVEL_ERROR, "CKPT: message_handler_req_exec_ckpt_synchronize_section\n");
  1161. log_printf(LOG_LEVEL_ERROR, "CKPT: recovery_section_write returned %d\n",retcode);
  1162. }
  1163. return (0);
  1164. }
  1165. unsigned int abstime_to_msec (SaTimeT time)
  1166. {
  1167. struct timeval tv;
  1168. unsigned long long curr_time;
  1169. unsigned long long msec_time;
  1170. gettimeofday (&tv, NULL);
  1171. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1172. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1173. msec_time = (((unsigned long long)time) / 1000000) -
  1174. (unsigned long long)curr_time;
  1175. return ((unsigned int)(msec_time));
  1176. }
  1177. void timer_function_section_expire (void *data)
  1178. {
  1179. struct saCkptCheckpointSection *section = (struct saCkptCheckpointSection *)data;
  1180. if (section->sectionDescriptor.sectionId.id) {
  1181. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring section %s\n", section->sectionDescriptor.sectionId.id);
  1182. }
  1183. checkpoint_section_release (section);
  1184. }
  1185. void timer_function_retention (void *data)
  1186. {
  1187. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  1188. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  1189. struct iovec iovec;
  1190. checkpoint->retention_timer = 0;
  1191. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  1192. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  1193. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  1194. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  1195. &checkpoint->name,
  1196. sizeof (SaNameT));
  1197. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  1198. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  1199. assert (totempg_mcast (&iovec, 1, TOTEMPG_AGREED) == 0);
  1200. }
  1201. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required)
  1202. {
  1203. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  1204. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  1205. struct saCkptCheckpoint *checkpoint = 0;
  1206. SaAisErrorT error = SA_AIS_OK;
  1207. int proc_index;
  1208. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  1209. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointclose->checkpointName);
  1210. if (checkpoint == 0) {
  1211. goto error_exit;
  1212. }
  1213. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1214. checkpoint->referenceCount--;
  1215. /*
  1216. * Modify the connection reference information to the Checkpoint to be
  1217. * sent out later as a part of the sync process.
  1218. */
  1219. proc_index = processor_index_find(&source_addr, checkpoint->ckpt_refcount);
  1220. if (proc_index != -1 ) {
  1221. checkpoint->ckpt_refcount[proc_index].count--;
  1222. }
  1223. else {
  1224. log_printf (LOG_LEVEL_ERROR,
  1225. "CKPT: Could Not find Processor Info %p info.\n",
  1226. checkpoint);
  1227. }
  1228. assert (checkpoint->referenceCount >= 0);
  1229. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  1230. checkpoint->referenceCount);
  1231. /*
  1232. * If checkpoint has been unlinked and this is the last reference, delete it
  1233. */
  1234. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  1235. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  1236. checkpoint_release (checkpoint);
  1237. } else
  1238. if (checkpoint->referenceCount == 0) {
  1239. poll_timer_add (aisexec_poll_handle,
  1240. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1241. checkpoint,
  1242. timer_function_retention,
  1243. &checkpoint->retention_timer);
  1244. }
  1245. error_exit:
  1246. if (message_source_is_local(&req_exec_ckpt_checkpointclose->source)) {
  1247. ckpt_checkpoint_remove_cleanup (req_exec_ckpt_checkpointclose->source.conn_info,
  1248. checkpoint);
  1249. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  1250. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  1251. res_lib_ckpt_checkpointclose.header.error = error;
  1252. libais_send_response (req_exec_ckpt_checkpointclose->source.conn_info,
  1253. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  1254. }
  1255. return (0);
  1256. }
  1257. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required)
  1258. {
  1259. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  1260. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  1261. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  1262. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1263. SaErrorT error = SA_AIS_OK;
  1264. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  1265. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointunlink->checkpointName);
  1266. if (ckptCheckpoint == 0) {
  1267. error = SA_AIS_ERR_NOT_EXIST;
  1268. goto error_exit;
  1269. }
  1270. if (ckptCheckpoint->unlinked) {
  1271. error = SA_AIS_ERR_INVALID_PARAM;
  1272. goto error_exit;
  1273. }
  1274. ckptCheckpoint->unlinked = 1;
  1275. /*
  1276. * Immediately delete entry if reference count is zero
  1277. */
  1278. if (ckptCheckpoint->referenceCount == 0) {
  1279. /*
  1280. * Remove retention timer since this checkpoint was unlinked and is no
  1281. * longer referenced
  1282. */
  1283. checkpoint_release (ckptCheckpoint);
  1284. }
  1285. error_exit:
  1286. /*
  1287. * If this node was the source of the message, respond to this node
  1288. */
  1289. if (message_source_is_local(&req_exec_ckpt_checkpointunlink->source)) {
  1290. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  1291. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  1292. res_lib_ckpt_checkpointunlink.header.error = error;
  1293. libais_send_response (req_exec_ckpt_checkpointunlink->source.conn_info, &res_lib_ckpt_checkpointunlink,
  1294. sizeof (struct res_lib_ckpt_checkpointunlink));
  1295. }
  1296. return (0);
  1297. }
  1298. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1299. {
  1300. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  1301. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  1302. struct saCkptCheckpoint *checkpoint;
  1303. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  1304. if (checkpoint) {
  1305. log_printf (LOG_LEVEL_NOTICE, "CKPT: Setting retention duration for checkpoint %s\n",
  1306. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  1307. checkpoint->checkpointCreationAttributes.retentionDuration = req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  1308. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  1309. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  1310. poll_timer_add (aisexec_poll_handle,
  1311. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1312. checkpoint,
  1313. timer_function_retention,
  1314. &checkpoint->retention_timer);
  1315. }
  1316. }
  1317. /*
  1318. * Respond to library if this processor sent the duration set request
  1319. */
  1320. if (message_source_is_local(&req_exec_ckpt_checkpointretentiondurationset->source)) {
  1321. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  1322. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  1323. res_lib_ckpt_checkpointretentiondurationset.header.error = SA_AIS_OK;
  1324. libais_send_response (req_exec_ckpt_checkpointretentiondurationset->source.conn_info,
  1325. &res_lib_ckpt_checkpointretentiondurationset,
  1326. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  1327. }
  1328. return (0);
  1329. }
  1330. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required)
  1331. {
  1332. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  1333. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1334. struct saCkptCheckpoint *checkpoint;
  1335. struct iovec iovecs[2];
  1336. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  1337. if (checkpoint && checkpoint->expired == 0) {
  1338. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  1339. checkpoint->expired = 1;
  1340. req_exec_ckpt_checkpointunlink.header.size =
  1341. sizeof (struct req_exec_ckpt_checkpointunlink);
  1342. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1343. req_exec_ckpt_checkpointunlink.source.conn_info = 0;
  1344. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = 0;
  1345. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  1346. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  1347. sizeof (SaNameT));
  1348. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1349. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1350. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1351. }
  1352. return (0);
  1353. }
  1354. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  1355. SaNameT *checkpointName,
  1356. char* SectionId)
  1357. {
  1358. struct saCkptCheckpoint *ckptCheckpoint;
  1359. struct saCkptCheckpointSection *ckptCheckpointSection;
  1360. void *initialData;
  1361. void *sectionId;
  1362. SaErrorT error = SA_AIS_OK;
  1363. if ((int)sectionDescriptor->sectionId.idLen) {
  1364. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, section %s.\n",
  1365. &checkpointName->value, SectionId);
  1366. } else {
  1367. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, default section.\n",
  1368. &checkpointName->value);
  1369. }
  1370. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1371. if (ckptCheckpoint == 0) {
  1372. error = SA_AIS_ERR_NOT_EXIST;
  1373. goto error_exit;
  1374. }
  1375. /*
  1376. * Determine if user-specified checkpoint ID already exists
  1377. */
  1378. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1379. SectionId,
  1380. (int)sectionDescriptor->sectionId.idLen);
  1381. if (ckptCheckpointSection) {
  1382. error = SA_AIS_ERR_EXIST;
  1383. goto error_exit;
  1384. }
  1385. /*
  1386. * Allocate checkpoint section
  1387. */
  1388. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1389. if (ckptCheckpointSection == 0) {
  1390. error = SA_AIS_ERR_NO_MEMORY;
  1391. goto error_exit;
  1392. }
  1393. /*
  1394. * Allocate checkpoint section data
  1395. */
  1396. initialData = malloc (sectionDescriptor->sectionSize);
  1397. if (initialData == 0) {
  1398. free (ckptCheckpointSection);
  1399. error = SA_AIS_ERR_NO_MEMORY;
  1400. goto error_exit;
  1401. }
  1402. /*
  1403. * Allocate checkpoint section id
  1404. */
  1405. if (sectionDescriptor->sectionId.idLen) {
  1406. sectionId = malloc ((int)sectionDescriptor->sectionId.idLen);
  1407. if (sectionId == 0) {
  1408. free (ckptCheckpointSection);
  1409. free (initialData);
  1410. error = SA_AIS_ERR_NO_MEMORY;
  1411. goto error_exit;
  1412. }
  1413. } else {
  1414. sectionId = 0;
  1415. }
  1416. /*
  1417. * Copy checkpoint section ID and initialize data.
  1418. */
  1419. if (SectionId) {
  1420. memcpy ((char*)sectionId, (char*)SectionId, (int)sectionDescriptor->sectionId.idLen);
  1421. } else {
  1422. sectionId = 0;
  1423. }
  1424. memset (initialData, 0, sectionDescriptor->sectionSize);
  1425. /*
  1426. * Configure checkpoint section
  1427. */
  1428. memcpy(&ckptCheckpointSection->sectionDescriptor,
  1429. sectionDescriptor,
  1430. sizeof(SaCkptSectionDescriptorT));
  1431. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1432. ckptCheckpointSection->sectionData = initialData;
  1433. ckptCheckpointSection->expiration_timer = 0;
  1434. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1435. if (sectionDescriptor->expirationTime != SA_TIME_END) {
  1436. poll_timer_add (aisexec_poll_handle,
  1437. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1438. ckptCheckpointSection,
  1439. timer_function_section_expire,
  1440. &ckptCheckpointSection->expiration_timer);
  1441. }
  1442. /*
  1443. * Add checkpoint section to checkpoint
  1444. */
  1445. list_init (&ckptCheckpointSection->list);
  1446. list_add (&ckptCheckpointSection->list,
  1447. &ckptCheckpoint->checkpointSectionsListHead);
  1448. error_exit:
  1449. return (error);
  1450. }
  1451. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1452. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  1453. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  1454. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  1455. struct saCkptCheckpoint *ckptCheckpoint;
  1456. struct saCkptCheckpointSection *ckptCheckpointSection;
  1457. void *initialData;
  1458. void *sectionId;
  1459. SaErrorT error = SA_AIS_OK;
  1460. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  1461. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectioncreate->checkpointName);
  1462. if (ckptCheckpoint == 0) {
  1463. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this*/
  1464. goto error_exit;
  1465. }
  1466. /*
  1467. * Determine if user-specified checkpoint ID already exists
  1468. */
  1469. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1470. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1471. req_lib_ckpt_sectioncreate->idLen);
  1472. if (ckptCheckpointSection) {
  1473. error = SA_AIS_ERR_EXIST;
  1474. goto error_exit;
  1475. }
  1476. /*
  1477. * Allocate checkpoint section
  1478. */
  1479. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1480. if (ckptCheckpointSection == 0) {
  1481. error = SA_AIS_ERR_NO_MEMORY;
  1482. goto error_exit;
  1483. }
  1484. /*
  1485. * Allocate checkpoint section data
  1486. */
  1487. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  1488. if (initialData == 0) {
  1489. free (ckptCheckpointSection);
  1490. error = SA_AIS_ERR_NO_MEMORY;
  1491. goto error_exit;
  1492. }
  1493. /*
  1494. * Allocate checkpoint section id
  1495. */
  1496. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  1497. if (sectionId == 0) {
  1498. free (ckptCheckpointSection);
  1499. free (initialData);
  1500. error = SA_AIS_ERR_NO_MEMORY;
  1501. goto error_exit;
  1502. }
  1503. /*
  1504. * Copy checkpoint section and section ID
  1505. */
  1506. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1507. req_lib_ckpt_sectioncreate->idLen);
  1508. memcpy (initialData,
  1509. ((char *)req_lib_ckpt_sectioncreate) +
  1510. sizeof (struct req_lib_ckpt_sectioncreate) +
  1511. req_lib_ckpt_sectioncreate->idLen,
  1512. req_lib_ckpt_sectioncreate->initialDataSize);
  1513. /*
  1514. * Configure checkpoint section
  1515. */
  1516. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1517. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  1518. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  1519. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  1520. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1521. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  1522. ckptCheckpointSection->sectionData = initialData;
  1523. ckptCheckpointSection->expiration_timer = 0;
  1524. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  1525. poll_timer_add (aisexec_poll_handle,
  1526. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1527. ckptCheckpointSection,
  1528. timer_function_section_expire,
  1529. &ckptCheckpointSection->expiration_timer);
  1530. }
  1531. /*
  1532. * Add checkpoint section to checkpoint
  1533. */
  1534. list_init (&ckptCheckpointSection->list);
  1535. list_add (&ckptCheckpointSection->list,
  1536. &ckptCheckpoint->checkpointSectionsListHead);
  1537. error_exit:
  1538. if (message_source_is_local(&req_exec_ckpt_sectioncreate->source)) {
  1539. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  1540. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  1541. res_lib_ckpt_sectioncreate.header.error = error;
  1542. libais_send_response (req_exec_ckpt_sectioncreate->source.conn_info,
  1543. &res_lib_ckpt_sectioncreate,
  1544. sizeof (struct res_lib_ckpt_sectioncreate));
  1545. }
  1546. return (0);
  1547. }
  1548. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1549. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  1550. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  1551. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  1552. struct saCkptCheckpoint *ckptCheckpoint;
  1553. struct saCkptCheckpointSection *ckptCheckpointSection;
  1554. SaErrorT error = SA_AIS_OK;
  1555. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectiondelete->checkpointName);
  1556. if (ckptCheckpoint == 0) {
  1557. error = SA_AIS_ERR_NOT_EXIST;
  1558. goto error_exit;
  1559. }
  1560. /*
  1561. * Determine if the user is trying to delete the default section
  1562. */
  1563. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  1564. error = SA_AIS_ERR_INVALID_PARAM;
  1565. goto error_exit;
  1566. }
  1567. /*
  1568. * Find checkpoint section to be deleted
  1569. */
  1570. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1571. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  1572. req_lib_ckpt_sectiondelete->idLen);
  1573. if (ckptCheckpointSection == 0) {
  1574. error = SA_AIS_ERR_NOT_EXIST;
  1575. goto error_exit;
  1576. }
  1577. /*
  1578. * Delete checkpoint section
  1579. */
  1580. checkpoint_section_release (ckptCheckpointSection);
  1581. /*
  1582. * return result to CKPT library
  1583. */
  1584. error_exit:
  1585. if (message_source_is_local(&req_exec_ckpt_sectiondelete->source)) {
  1586. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  1587. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  1588. res_lib_ckpt_sectiondelete.header.error = error;
  1589. libais_send_response (req_exec_ckpt_sectiondelete->source.conn_info,
  1590. &res_lib_ckpt_sectiondelete,
  1591. sizeof (struct res_lib_ckpt_sectiondelete));
  1592. }
  1593. return (0);
  1594. }
  1595. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1596. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  1597. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  1598. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  1599. struct saCkptCheckpoint *ckptCheckpoint;
  1600. struct saCkptCheckpointSection *ckptCheckpointSection;
  1601. SaErrorT error = SA_AIS_OK;
  1602. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  1603. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  1604. if (ckptCheckpoint == 0) {
  1605. error = SA_AIS_ERR_NOT_EXIST;
  1606. goto error_exit;
  1607. }
  1608. /*
  1609. * Determine if the user is trying to set expiration time for the default section
  1610. */
  1611. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  1612. error = SA_AIS_ERR_INVALID_PARAM;
  1613. goto error_exit;
  1614. }
  1615. /*
  1616. * Find checkpoint section that expiration time should be set for
  1617. */
  1618. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1619. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  1620. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  1621. req_lib_ckpt_sectionexpirationtimeset->idLen);
  1622. if (ckptCheckpointSection == 0) {
  1623. error = SA_AIS_ERR_NOT_EXIST;
  1624. goto error_exit;
  1625. }
  1626. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  1627. poll_timer_delete (aisexec_poll_handle, ckptCheckpointSection->expiration_timer);
  1628. ckptCheckpointSection->expiration_timer = 0;
  1629. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  1630. poll_timer_add (aisexec_poll_handle,
  1631. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1632. ckptCheckpointSection,
  1633. timer_function_section_expire,
  1634. &ckptCheckpointSection->expiration_timer);
  1635. }
  1636. error_exit:
  1637. if (message_source_is_local(&req_exec_ckpt_sectionexpirationtimeset->source)) {
  1638. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  1639. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  1640. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  1641. libais_send_response (req_exec_ckpt_sectionexpirationtimeset->source.conn_info,
  1642. &res_lib_ckpt_sectionexpirationtimeset,
  1643. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  1644. }
  1645. return (0);
  1646. }
  1647. static int recovery_section_write(int sectionIdLen,
  1648. char* sectionId,
  1649. SaNameT *checkpointName,
  1650. void *newData,
  1651. SaUint32T dataOffSet,
  1652. SaUint32T dataSize)
  1653. {
  1654. struct saCkptCheckpoint *ckptCheckpoint;
  1655. struct saCkptCheckpointSection *ckptCheckpointSection;
  1656. int sizeRequired;
  1657. SaErrorT error = SA_AIS_OK;
  1658. char *sd;
  1659. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_write.\n");
  1660. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1661. if (ckptCheckpoint == 0) {
  1662. error = SA_AIS_ERR_NOT_EXIST;
  1663. goto error_exit;
  1664. }
  1665. /*
  1666. * Find checkpoint section to be written
  1667. */
  1668. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1669. sectionId,
  1670. sectionIdLen);
  1671. if (ckptCheckpointSection == 0) {
  1672. error = SA_AIS_ERR_NOT_EXIST;
  1673. goto error_exit;
  1674. }
  1675. /*
  1676. * If write would extend past end of section data, return error;
  1677. */
  1678. sizeRequired = dataOffSet + dataSize;
  1679. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  1680. error = SA_AIS_ERR_ACCESS;
  1681. goto error_exit;
  1682. }
  1683. /*
  1684. * Write checkpoint section to section data
  1685. */
  1686. if (dataSize > 0) {
  1687. sd = (char *)ckptCheckpointSection->sectionData;
  1688. memcpy (&sd[dataOffSet],
  1689. newData,
  1690. dataSize);
  1691. }
  1692. error_exit:
  1693. return (error);
  1694. }
  1695. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1696. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  1697. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  1698. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1699. struct saCkptCheckpoint *ckptCheckpoint;
  1700. struct saCkptCheckpointSection *ckptCheckpointSection;
  1701. int sizeRequired;
  1702. void *sectionData;
  1703. SaErrorT error = SA_AIS_OK;
  1704. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  1705. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionwrite->checkpointName);
  1706. if (ckptCheckpoint == 0) {
  1707. error = SA_AIS_ERR_NOT_EXIST;
  1708. goto error_exit;
  1709. }
  1710. /*
  1711. printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1712. */
  1713. /*
  1714. * Find checkpoint section to be written
  1715. */
  1716. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1717. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  1718. req_lib_ckpt_sectionwrite->idLen);
  1719. if (ckptCheckpointSection == 0) {
  1720. if (req_lib_ckpt_sectionwrite->idLen == 0) {
  1721. log_printf (LOG_LEVEL_ERROR, "CANT FIND DEFAULT SECTION.\n");
  1722. }
  1723. else {
  1724. printf ("CANT FIND SECTION '%s'\n",
  1725. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1726. }
  1727. error = SA_AIS_ERR_NOT_EXIST;
  1728. goto error_exit;
  1729. }
  1730. /*
  1731. * If write would extend past end of section data, enlarge section
  1732. */
  1733. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  1734. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  1735. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  1736. if (sectionData == 0) {
  1737. error = SA_AIS_ERR_NO_MEMORY;
  1738. goto error_exit;
  1739. }
  1740. /*
  1741. * Install new section data
  1742. */
  1743. ckptCheckpointSection->sectionData = sectionData;
  1744. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  1745. }
  1746. /*
  1747. * Write checkpoint section to section data
  1748. */
  1749. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  1750. char *sd;
  1751. int *val;
  1752. val = ckptCheckpointSection->sectionData;
  1753. sd = (char *)ckptCheckpointSection->sectionData;
  1754. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  1755. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  1756. req_lib_ckpt_sectionwrite->idLen,
  1757. req_lib_ckpt_sectionwrite->dataSize);
  1758. }
  1759. /*
  1760. * Write write response to CKPT library
  1761. */
  1762. error_exit:
  1763. if (message_source_is_local(&req_exec_ckpt_sectionwrite->source)) {
  1764. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  1765. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  1766. res_lib_ckpt_sectionwrite.header.error = error;
  1767. libais_send_response (req_exec_ckpt_sectionwrite->source.conn_info,
  1768. &res_lib_ckpt_sectionwrite,
  1769. sizeof (struct res_lib_ckpt_sectionwrite));
  1770. }
  1771. return (0);
  1772. }
  1773. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1774. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  1775. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  1776. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1777. struct saCkptCheckpoint *ckptCheckpoint;
  1778. struct saCkptCheckpointSection *ckptCheckpointSection;
  1779. void *sectionData;
  1780. SaErrorT error = SA_AIS_OK;
  1781. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  1782. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionoverwrite->checkpointName);
  1783. if (ckptCheckpoint == 0) {
  1784. error = SA_AIS_ERR_NOT_EXIST;
  1785. goto error_exit;
  1786. }
  1787. /*
  1788. * Find checkpoint section to be overwritten
  1789. */
  1790. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1791. ((char *)req_lib_ckpt_sectionoverwrite) +
  1792. sizeof (struct req_lib_ckpt_sectionoverwrite),
  1793. req_lib_ckpt_sectionoverwrite->idLen);
  1794. if (ckptCheckpointSection == 0) {
  1795. error = SA_AIS_ERR_NOT_EXIST;
  1796. goto error_exit;
  1797. }
  1798. /*
  1799. * Allocate checkpoint section data
  1800. */
  1801. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  1802. if (sectionData == 0) {
  1803. error = SA_AIS_ERR_NO_MEMORY;
  1804. goto error_exit;
  1805. }
  1806. memcpy (sectionData,
  1807. ((char *)req_lib_ckpt_sectionoverwrite) +
  1808. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  1809. req_lib_ckpt_sectionoverwrite->idLen,
  1810. req_lib_ckpt_sectionoverwrite->dataSize);
  1811. /*
  1812. * release old checkpoint section data
  1813. */
  1814. free (ckptCheckpointSection->sectionData);
  1815. /*
  1816. * Install overwritten checkpoint section data
  1817. */
  1818. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  1819. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1820. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  1821. ckptCheckpointSection->sectionData = sectionData;
  1822. /*
  1823. * return result to CKPT library
  1824. */
  1825. error_exit:
  1826. if (message_source_is_local(&req_exec_ckpt_sectionoverwrite->source)) {
  1827. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  1828. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1829. res_lib_ckpt_sectionoverwrite.header.error = error;
  1830. libais_send_response (req_exec_ckpt_sectionoverwrite->source.conn_info,
  1831. &res_lib_ckpt_sectionoverwrite,
  1832. sizeof (struct res_lib_ckpt_sectionoverwrite));
  1833. }
  1834. return (0);
  1835. }
  1836. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1837. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  1838. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  1839. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1840. struct saCkptCheckpoint *ckptCheckpoint;
  1841. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1842. int sectionSize = 0;
  1843. SaErrorT error = SA_AIS_OK;
  1844. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  1845. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionread->checkpointName);
  1846. if (ckptCheckpoint == 0) {
  1847. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this */
  1848. goto error_exit;
  1849. }
  1850. /*
  1851. * Find checkpoint section to be read
  1852. */
  1853. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1854. ((char *)req_lib_ckpt_sectionread) +
  1855. sizeof (struct req_lib_ckpt_sectionread),
  1856. req_lib_ckpt_sectionread->idLen);
  1857. if (ckptCheckpointSection == 0) {
  1858. error = SA_AIS_ERR_NOT_EXIST;
  1859. goto error_exit;
  1860. }
  1861. /*
  1862. * Determine the section size
  1863. */
  1864. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  1865. req_lib_ckpt_sectionread->dataOffset;
  1866. /*
  1867. * If the library has less space available then can be sent from the
  1868. * section, reduce bytes sent to library to max requested
  1869. */
  1870. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  1871. sectionSize = req_lib_ckpt_sectionread->dataSize;
  1872. }
  1873. /*
  1874. * If dataOffset is past end of data, return INVALID PARAM
  1875. */
  1876. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  1877. sectionSize = 0;
  1878. error = SA_AIS_ERR_INVALID_PARAM;
  1879. goto error_exit;
  1880. }
  1881. /*
  1882. * Write read response to CKPT library
  1883. */
  1884. error_exit:
  1885. if (message_source_is_local(&req_exec_ckpt_sectionread->source)) {
  1886. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  1887. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  1888. res_lib_ckpt_sectionread.header.error = error;
  1889. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1890. &res_lib_ckpt_sectionread,
  1891. sizeof (struct res_lib_ckpt_sectionread));
  1892. /*
  1893. * Write checkpoint to CKPT library section if section has data
  1894. */
  1895. if (sectionSize) {
  1896. char *sd;
  1897. sd = (char *)ckptCheckpointSection->sectionData;
  1898. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1899. &sd[req_lib_ckpt_sectionread->dataOffset],
  1900. sectionSize);
  1901. }
  1902. }
  1903. return (0);
  1904. }
  1905. static int ckpt_init_two_fn (struct conn_info *conn_info)
  1906. {
  1907. list_init (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator
  1908. .list);
  1909. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  1910. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  1911. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  1912. list_add (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.list,
  1913. &checkpoint_iterator_list_head);
  1914. list_init (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list);
  1915. return (0);
  1916. }
  1917. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message)
  1918. {
  1919. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)message;
  1920. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  1921. struct iovec iovecs[2];
  1922. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  1923. req_exec_ckpt_checkpointopen.header.size =
  1924. sizeof (struct req_exec_ckpt_checkpointopen);
  1925. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  1926. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  1927. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  1928. req_lib_ckpt_checkpointopen,
  1929. sizeof (struct req_lib_ckpt_checkpointopen));
  1930. req_exec_ckpt_checkpointopen.async_call = 0;
  1931. req_exec_ckpt_checkpointopen.invocation = 0;
  1932. req_exec_ckpt_checkpointopen.checkpointHandle = 0;
  1933. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  1934. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  1935. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1936. return (0);
  1937. }
  1938. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  1939. {
  1940. struct req_lib_ckpt_checkpointopenasync *req_lib_ckpt_checkpointopenasync = (struct req_lib_ckpt_checkpointopenasync *)message;
  1941. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  1942. struct iovec iovecs[2];
  1943. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint async.\n");
  1944. req_exec_ckpt_checkpointopen.header.size =
  1945. sizeof (struct req_exec_ckpt_checkpointopen);
  1946. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  1947. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  1948. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  1949. req_lib_ckpt_checkpointopenasync,
  1950. sizeof (struct req_lib_ckpt_checkpointopen));
  1951. req_exec_ckpt_checkpointopen.async_call = 1;
  1952. req_exec_ckpt_checkpointopen.invocation = req_lib_ckpt_checkpointopenasync->invocation;
  1953. req_exec_ckpt_checkpointopen.checkpointHandle = req_lib_ckpt_checkpointopenasync->checkpointHandle;
  1954. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  1955. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  1956. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1957. return (0);
  1958. }
  1959. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message) {
  1960. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)message;
  1961. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  1962. struct iovec iovecs[2];
  1963. req_exec_ckpt_checkpointclose.header.size =
  1964. sizeof (struct req_exec_ckpt_checkpointclose);
  1965. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  1966. message_source_set (&req_exec_ckpt_checkpointclose.source, conn_info);
  1967. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  1968. &req_lib_ckpt_checkpointclose->checkpointName, sizeof (SaNameT));
  1969. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  1970. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  1971. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  1972. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1973. }
  1974. return (0);
  1975. }
  1976. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  1977. {
  1978. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  1979. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1980. struct iovec iovecs[2];
  1981. req_exec_ckpt_checkpointunlink.header.size =
  1982. sizeof (struct req_exec_ckpt_checkpointunlink);
  1983. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1984. message_source_set (&req_exec_ckpt_checkpointunlink.source, conn_info);
  1985. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  1986. req_lib_ckpt_checkpointunlink,
  1987. sizeof (struct req_lib_ckpt_checkpointunlink));
  1988. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1989. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1990. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1991. return (0);
  1992. }
  1993. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  1994. {
  1995. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  1996. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  1997. struct iovec iovecs[2];
  1998. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info->fd);
  1999. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  2000. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  2001. message_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn_info);
  2002. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  2003. &req_lib_ckpt_checkpointretentiondurationset->checkpointName,
  2004. sizeof (SaNameT));
  2005. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  2006. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  2007. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  2008. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2009. return (0);
  2010. }
  2011. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message)
  2012. {
  2013. struct req_lib_ckpt_activereplicaset *req_lib_ckpt_activereplicaset = (struct req_lib_ckpt_activereplicaset *)message;
  2014. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  2015. struct saCkptCheckpoint *checkpoint;
  2016. SaAisErrorT error = SA_AIS_OK;
  2017. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_activereplicaset->checkpointName);
  2018. /*
  2019. * Make sure checkpoint is collocated and async update option
  2020. */
  2021. if (((checkpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) ||
  2022. (checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2023. error = SA_AIS_ERR_BAD_OPERATION;
  2024. }
  2025. res_lib_ckpt_activereplicaset.header.size = sizeof (struct res_lib_ckpt_activereplicaset);
  2026. res_lib_ckpt_activereplicaset.header.id = MESSAGE_RES_CKPT_ACTIVEREPLICASET;
  2027. res_lib_ckpt_activereplicaset.header.error = error;
  2028. libais_send_response (conn_info, &res_lib_ckpt_activereplicaset,
  2029. sizeof (struct res_lib_ckpt_activereplicaset));
  2030. return (0);
  2031. }
  2032. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  2033. {
  2034. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  2035. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  2036. struct saCkptCheckpoint *checkpoint;
  2037. int memoryUsed = 0;
  2038. int numberOfSections = 0;
  2039. struct list_head *checkpoint_section_list;
  2040. struct saCkptCheckpointSection *checkpointSection;
  2041. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  2042. /*
  2043. * Count memory used by checkpoint sections
  2044. */
  2045. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointstatusget->checkpointName);
  2046. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  2047. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  2048. checkpoint_section_list = checkpoint_section_list->next) {
  2049. checkpointSection = list_entry (checkpoint_section_list,
  2050. struct saCkptCheckpointSection, list);
  2051. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  2052. numberOfSections += 1;
  2053. }
  2054. /*
  2055. * Build checkpoint status get response
  2056. */
  2057. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2058. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2059. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  2060. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointDescriptor.checkpointCreationAttributes,
  2061. &checkpoint->checkpointCreationAttributes,
  2062. sizeof (SaCkptCheckpointCreationAttributesT));
  2063. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.numberOfSections = numberOfSections;
  2064. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.memoryUsed = memoryUsed;
  2065. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  2066. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  2067. sizeof (struct res_lib_ckpt_checkpointstatusget));
  2068. return (0);
  2069. }
  2070. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  2071. {
  2072. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  2073. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  2074. struct iovec iovecs[2];
  2075. struct saCkptCheckpoint *checkpoint;
  2076. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info->fd);
  2077. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioncreate->checkpointName);
  2078. /*
  2079. * checkpoint opened is writeable mode so send message to cluster
  2080. */
  2081. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  2082. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  2083. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  2084. req_lib_ckpt_sectioncreate,
  2085. sizeof (struct req_lib_ckpt_sectioncreate));
  2086. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  2087. &req_lib_ckpt_sectioncreate->checkpointName,
  2088. sizeof (SaNameT));
  2089. message_source_set (&req_exec_ckpt_sectioncreate.source, conn_info);
  2090. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  2091. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  2092. /*
  2093. * Send section name and initial data in message
  2094. */
  2095. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  2096. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  2097. req_exec_ckpt_sectioncreate.header.size += iovecs[1].iov_len;
  2098. #ifdef DEBUG
  2099. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  2100. iovecs[1].iov_len);
  2101. printf ("|\n");
  2102. { int i;
  2103. char *abc = iovecs[1].iov_base;
  2104. for (i = 0; i < 14;i++) {
  2105. printf ("%c ", abc[i]);
  2106. }
  2107. }
  2108. printf ("|\n");
  2109. #endif
  2110. if (iovecs[1].iov_len > 0) {
  2111. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2112. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2113. } else {
  2114. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2115. }
  2116. return (0);
  2117. }
  2118. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  2119. {
  2120. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  2121. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  2122. struct iovec iovecs[2];
  2123. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info->fd);
  2124. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  2125. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  2126. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  2127. &req_lib_ckpt_sectiondelete->checkpointName,
  2128. sizeof (SaNameT));
  2129. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  2130. req_lib_ckpt_sectiondelete,
  2131. sizeof (struct req_lib_ckpt_sectiondelete));
  2132. message_source_set (&req_exec_ckpt_sectiondelete.source, conn_info);
  2133. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  2134. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  2135. /*
  2136. * Send section name
  2137. */
  2138. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  2139. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  2140. req_exec_ckpt_sectiondelete.header.size += iovecs[1].iov_len;
  2141. if (iovecs[1].iov_len > 0) {
  2142. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2143. } else {
  2144. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2145. }
  2146. return (0);
  2147. }
  2148. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  2149. {
  2150. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  2151. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  2152. struct iovec iovecs[2];
  2153. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info->fd);
  2154. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  2155. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  2156. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  2157. &req_lib_ckpt_sectionexpirationtimeset->checkpointName,
  2158. sizeof (SaNameT));
  2159. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  2160. req_lib_ckpt_sectionexpirationtimeset,
  2161. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  2162. message_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn_info);
  2163. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  2164. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  2165. /*
  2166. * Send section name
  2167. */
  2168. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2169. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2170. req_exec_ckpt_sectionexpirationtimeset.header.size += iovecs[1].iov_len;
  2171. if (iovecs[1].iov_len > 0) {
  2172. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2173. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2174. } else {
  2175. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2176. }
  2177. return (0);
  2178. }
  2179. int write_inv = 0;
  2180. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  2181. {
  2182. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  2183. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  2184. struct iovec iovecs[2];
  2185. struct saCkptCheckpoint *checkpoint;
  2186. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info->fd);
  2187. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionwrite->checkpointName);
  2188. /*
  2189. * checkpoint opened is writeable mode so send message to cluster
  2190. */
  2191. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  2192. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  2193. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  2194. req_lib_ckpt_sectionwrite,
  2195. sizeof (struct req_lib_ckpt_sectionwrite));
  2196. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  2197. &req_lib_ckpt_sectionwrite->checkpointName,
  2198. sizeof (SaNameT));
  2199. message_source_set (&req_exec_ckpt_sectionwrite.source, conn_info);
  2200. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  2201. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  2202. /*
  2203. * Send section name and data to write in message
  2204. */
  2205. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  2206. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  2207. req_exec_ckpt_sectionwrite.header.size += iovecs[1].iov_len;
  2208. if (iovecs[1].iov_len > 0) {
  2209. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2210. } else {
  2211. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2212. }
  2213. return (0);
  2214. }
  2215. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  2216. {
  2217. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  2218. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  2219. struct iovec iovecs[2];
  2220. struct saCkptCheckpoint *checkpoint;
  2221. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2222. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionoverwrite->checkpointName);
  2223. /*
  2224. * checkpoint opened is writeable mode so send message to cluster
  2225. */
  2226. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  2227. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  2228. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  2229. req_lib_ckpt_sectionoverwrite,
  2230. sizeof (struct req_lib_ckpt_sectionoverwrite));
  2231. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  2232. &req_lib_ckpt_sectionoverwrite->checkpointName,
  2233. sizeof (SaNameT));
  2234. message_source_set (&req_exec_ckpt_sectionoverwrite.source, conn_info);
  2235. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  2236. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  2237. /*
  2238. * Send section name and data to overwrite in message
  2239. */
  2240. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  2241. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  2242. req_exec_ckpt_sectionoverwrite.header.size += iovecs[1].iov_len;
  2243. if (iovecs[1].iov_len > 0) {
  2244. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2245. } else {
  2246. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2247. }
  2248. return (0);
  2249. }
  2250. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  2251. {
  2252. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  2253. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  2254. struct iovec iovecs[2];
  2255. struct saCkptCheckpoint *checkpoint;
  2256. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2257. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionread->checkpointName);
  2258. /*
  2259. * checkpoint opened is writeable mode so send message to cluster
  2260. */
  2261. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  2262. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  2263. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  2264. req_lib_ckpt_sectionread,
  2265. sizeof (struct req_lib_ckpt_sectionread));
  2266. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  2267. &req_lib_ckpt_sectionread->checkpointName,
  2268. sizeof (SaNameT));
  2269. message_source_set (&req_exec_ckpt_sectionread.source, conn_info);
  2270. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  2271. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  2272. /*
  2273. * Send section name and data to overwrite in message
  2274. */
  2275. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  2276. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  2277. req_exec_ckpt_sectionread.header.size += iovecs[1].iov_len;
  2278. if (iovecs[1].iov_len > 0) {
  2279. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2280. } else {
  2281. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2282. }
  2283. return (0);
  2284. }
  2285. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  2286. {
  2287. return (0);
  2288. }
  2289. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  2290. {
  2291. return (0);
  2292. }
  2293. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message)
  2294. {
  2295. struct req_lib_ckpt_sectioniteratorinitialize *req_lib_ckpt_sectioniteratorinitialize = (struct req_lib_ckpt_sectioniteratorinitialize *)message;
  2296. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  2297. struct saCkptCheckpoint *ckptCheckpoint;
  2298. struct saCkptCheckpointSection *ckptCheckpointSection;
  2299. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  2300. struct saCkptSectionIterator *ckptSectionIterator;
  2301. struct list_head *checkpoint_section_list;
  2302. int addEntry = 0;
  2303. int iteratorEntries = 0;
  2304. SaErrorT error = SA_AIS_OK;
  2305. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  2306. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2307. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniteratorinitialize->checkpointName);
  2308. if (ckptCheckpoint == 0) {
  2309. error = SA_AIS_ERR_NOT_EXIST;
  2310. goto error_exit;
  2311. }
  2312. /*
  2313. * Iterate list of checkpoint sections
  2314. */
  2315. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  2316. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  2317. checkpoint_section_list = checkpoint_section_list->next) {
  2318. ckptCheckpointSection = list_entry (checkpoint_section_list,
  2319. struct saCkptCheckpointSection, list);
  2320. addEntry = 1;
  2321. /*
  2322. * Item should be added to iterator list
  2323. */
  2324. if (addEntry) {
  2325. iteratorEntries += 1;
  2326. ckptSectionIteratorEntries =
  2327. realloc (ckptSectionIterator->sectionIteratorEntries,
  2328. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  2329. if (ckptSectionIteratorEntries == 0) {
  2330. if (ckptSectionIterator->sectionIteratorEntries) {
  2331. free (ckptSectionIterator->sectionIteratorEntries);
  2332. }
  2333. error = SA_AIS_ERR_NO_MEMORY;
  2334. goto error_exit;
  2335. }
  2336. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  2337. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  2338. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  2339. }
  2340. }
  2341. ckptSectionIterator->iteratorCount = iteratorEntries;
  2342. error_exit:
  2343. res_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize);
  2344. res_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  2345. res_lib_ckpt_sectioniteratorinitialize.header.error = error;
  2346. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratorinitialize,
  2347. sizeof (struct res_lib_ckpt_sectioniteratorinitialize));
  2348. return (0);
  2349. }
  2350. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  2351. {
  2352. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  2353. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  2354. struct saCkptSectionIterator *ckptSectionIterator;
  2355. SaErrorT error = SA_AIS_OK;
  2356. int sectionIdSize = 0;
  2357. int iteratorPos = 0;
  2358. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  2359. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  2360. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2361. /*
  2362. * Find active iterator entry
  2363. */
  2364. for (;;) {
  2365. /*
  2366. * No more sections in iterator
  2367. */
  2368. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  2369. error = SA_AIS_ERR_NOT_EXIST;
  2370. goto error_exit;
  2371. }
  2372. /*
  2373. * active iterator entry
  2374. */
  2375. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  2376. break;
  2377. }
  2378. ckptSectionIterator->iteratorPos += 1;
  2379. }
  2380. /*
  2381. * Prepare response to API
  2382. */
  2383. iteratorPos = ckptSectionIterator->iteratorPos;
  2384. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  2385. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  2386. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  2387. sizeof (SaCkptSectionDescriptorT));
  2388. /*
  2389. * Get to next iterator entry
  2390. */
  2391. ckptSectionIterator->iteratorPos += 1;
  2392. error_exit:
  2393. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  2394. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  2395. res_lib_ckpt_sectioniteratornext.header.error = error;
  2396. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  2397. sizeof (struct res_lib_ckpt_sectioniteratornext));
  2398. libais_send_response (conn_info,
  2399. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  2400. sectionIdSize);
  2401. return (0);
  2402. }