ckpt.c 103 KB

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