ckpt.c 99 KB

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