ckpt.c 100 KB

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