ckpt.c 100 KB

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