ckpt.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851
  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. #include "print.h"
  59. DECLARE_LIST_INIT(checkpointListHead);
  60. DECLARE_LIST_INIT(checkpointIteratorListHead);
  61. struct checkpoint_cleanup {
  62. struct list_head list;
  63. struct saCkptCheckpoint *checkpoint;
  64. };
  65. //TODO static totempg_recovery_plug_handle ckpt_checkpoint_recovery_plug_handle;
  66. static int ckpt_exec_init_fn (void);
  67. static int ckpt_exit_fn (struct conn_info *conn_info);
  68. static int message_handler_req_lib_activatepoll (struct conn_info *, void *message);
  69. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr, int endian_conversion_required);
  70. static int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required);
  71. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required);
  72. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required);
  73. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required);
  74. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required);
  75. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required);
  76. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required);
  77. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required);
  78. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required);
  79. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required);
  80. static int message_handler_req_lib_ckpt_init (struct conn_info *conn_info, void *message);
  81. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message);
  82. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message);
  83. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message);
  84. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message);
  85. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message);
  86. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message);
  87. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message);
  88. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message);
  89. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message);
  90. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message);
  91. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message);
  92. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message);
  93. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message);
  94. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message);
  95. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message);
  96. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message);
  97. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message);
  98. static int ckpt_confchg_fn (
  99. enum totempg_configuration_type configuration_type,
  100. struct in_addr *member_list, void *member_list_private,
  101. int member_list_entries,
  102. struct in_addr *left_list, void *left_list_private,
  103. int left_list_entries,
  104. struct in_addr *joined_list, void *joined_list_private,
  105. int joined_list_entries) {
  106. #ifdef TODO
  107. if (configuration_type == TOTEMPG_CONFIGURATION_REGULAR) {
  108. totempg_recovery_plug_unplug (ckpt_checkpoint_recovery_plug_handle);
  109. }
  110. #endif
  111. return (0);
  112. }
  113. struct libais_handler ckpt_libais_handlers[] =
  114. {
  115. { /* 0 */
  116. .libais_handler_fn = message_handler_req_lib_activatepoll,
  117. .response_size = sizeof (struct res_lib_activatepoll),
  118. .response_id = MESSAGE_RES_LIB_ACTIVATEPOLL,
  119. },
  120. { /* 1 */
  121. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointopen,
  122. .response_size = sizeof (struct res_lib_ckpt_checkpointopen),
  123. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN,
  124. },
  125. { /* 2 */
  126. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointopenasync,
  127. .response_size = sizeof (struct res_lib_ckpt_checkpointopenasync),
  128. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC,
  129. },
  130. { /* 3 */
  131. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointclose,
  132. .response_size = sizeof (struct res_lib_ckpt_checkpointclose),
  133. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE,
  134. },
  135. { /* 4 */
  136. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointunlink,
  137. .response_size = sizeof (struct res_lib_ckpt_checkpointunlink),
  138. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK,
  139. },
  140. { /* 5 */
  141. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointretentiondurationset,
  142. .response_size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  143. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET,
  144. },
  145. { /* 6 */
  146. .libais_handler_fn = message_handler_req_lib_ckpt_activereplicaset,
  147. .response_size = sizeof (struct res_lib_ckpt_activereplicaset),
  148. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_ACTIVEREPLICASET,
  149. },
  150. { /* 7 */
  151. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointstatusget,
  152. .response_size = sizeof (struct res_lib_ckpt_checkpointstatusget),
  153. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET,
  154. },
  155. { /* 8 */
  156. .libais_handler_fn = message_handler_req_lib_ckpt_sectioncreate,
  157. .response_size = sizeof (struct res_lib_ckpt_sectioncreate),
  158. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE,
  159. },
  160. { /* 9 */
  161. .libais_handler_fn = message_handler_req_lib_ckpt_sectiondelete,
  162. .response_size = sizeof (struct res_lib_ckpt_sectiondelete),
  163. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE,
  164. },
  165. { /* 10 */
  166. .libais_handler_fn = message_handler_req_lib_ckpt_sectionexpirationtimeset,
  167. .response_size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  168. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET,
  169. },
  170. { /* 11 */
  171. .libais_handler_fn = message_handler_req_lib_ckpt_sectionwrite,
  172. .response_size = sizeof (struct res_lib_ckpt_sectionwrite),
  173. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE,
  174. },
  175. { /* 12 */
  176. .libais_handler_fn = message_handler_req_lib_ckpt_sectionoverwrite,
  177. .response_size = sizeof (struct res_lib_ckpt_sectionoverwrite),
  178. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE,
  179. },
  180. { /* 13 */
  181. .libais_handler_fn = message_handler_req_lib_ckpt_sectionread,
  182. .response_size = sizeof (struct res_lib_ckpt_sectionread),
  183. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD,
  184. },
  185. { /* 14 */
  186. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronize,
  187. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronize),
  188. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE,
  189. },
  190. { /* 15 */
  191. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronizeasync,
  192. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync), // TODO RESPONSE
  193. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC,
  194. },
  195. { /* 16 */
  196. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniteratorinitialize,
  197. .response_size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
  198. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE,
  199. },
  200. { /* 17 */
  201. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniteratornext,
  202. .response_size = sizeof (struct res_lib_ckpt_sectioniteratornext),
  203. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT,
  204. }
  205. };
  206. static int (*ckpt_aisexec_handler_fns[]) (void *msg, struct in_addr source_addr, int endian_conversion_required) = {
  207. message_handler_req_exec_ckpt_checkpointopen,
  208. message_handler_req_exec_ckpt_checkpointclose,
  209. message_handler_req_exec_ckpt_checkpointunlink,
  210. message_handler_req_exec_ckpt_checkpointretentiondurationset,
  211. message_handler_req_exec_ckpt_checkpointretentiondurationexpire,
  212. message_handler_req_exec_ckpt_sectioncreate,
  213. message_handler_req_exec_ckpt_sectiondelete,
  214. message_handler_req_exec_ckpt_sectionexpirationtimeset,
  215. message_handler_req_exec_ckpt_sectionwrite,
  216. message_handler_req_exec_ckpt_sectionoverwrite,
  217. message_handler_req_exec_ckpt_sectionread
  218. };
  219. struct service_handler ckpt_service_handler = {
  220. .libais_handlers = ckpt_libais_handlers,
  221. .libais_handlers_count = sizeof (ckpt_libais_handlers) / sizeof (struct libais_handler),
  222. .aisexec_handler_fns = ckpt_aisexec_handler_fns,
  223. .aisexec_handler_fns_count = sizeof (ckpt_aisexec_handler_fns) / sizeof (int (*)),
  224. .confchg_fn = ckpt_confchg_fn,
  225. .libais_init_fn = message_handler_req_lib_ckpt_init,
  226. .libais_exit_fn = ckpt_exit_fn,
  227. .exec_init_fn = ckpt_exec_init_fn,
  228. .exec_dump_fn = 0
  229. };
  230. static struct saCkptCheckpoint *ckpt_checkpoint_find_global (SaNameT *name)
  231. {
  232. struct list_head *checkpointList;
  233. struct saCkptCheckpoint *checkpoint;
  234. for (checkpointList = checkpointListHead.next;
  235. checkpointList != &checkpointListHead;
  236. checkpointList = checkpointList->next) {
  237. checkpoint = list_entry (checkpointList,
  238. struct saCkptCheckpoint, list);
  239. if (name_match (name, &checkpoint->name)) {
  240. return (checkpoint);
  241. }
  242. }
  243. return (0);
  244. }
  245. static void ckpt_checkpoint_remove_cleanup (
  246. struct conn_info *conn_info,
  247. struct saCkptCheckpoint *checkpoint)
  248. {
  249. struct list_head *list;
  250. struct checkpoint_cleanup *checkpoint_cleanup;
  251. for (list = conn_info->ais_ci.u.libckpt_ci.checkpoint_list.next;
  252. list != &conn_info->ais_ci.u.libckpt_ci.checkpoint_list;
  253. list = list->next) {
  254. checkpoint_cleanup = list_entry (list,
  255. struct checkpoint_cleanup, list);
  256. if (checkpoint_cleanup->checkpoint == checkpoint) {
  257. list_del (&checkpoint_cleanup->list);
  258. free (checkpoint_cleanup);
  259. return;
  260. }
  261. }
  262. }
  263. static struct saCkptCheckpointSection *ckpt_checkpoint_find_globalSection (
  264. struct saCkptCheckpoint *ckptCheckpoint,
  265. char *id,
  266. int idLen)
  267. {
  268. struct list_head *checkpointSectionList;
  269. struct saCkptCheckpointSection *ckptCheckpointSection;
  270. log_printf (LOG_LEVEL_DEBUG, "Finding checkpoint section id %s %d\n", id, idLen);
  271. for (checkpointSectionList = ckptCheckpoint->checkpointSectionsListHead.next;
  272. checkpointSectionList != &ckptCheckpoint->checkpointSectionsListHead;
  273. checkpointSectionList = checkpointSectionList->next) {
  274. ckptCheckpointSection = list_entry (checkpointSectionList,
  275. struct saCkptCheckpointSection, list);
  276. log_printf (LOG_LEVEL_DEBUG, "Checking section id %*s\n",
  277. (int)ckptCheckpointSection->sectionDescriptor.sectionId.idLen,
  278. ckptCheckpointSection->sectionDescriptor.sectionId.id);
  279. if (ckptCheckpointSection->sectionDescriptor.sectionId.idLen == idLen &&
  280. (memcmp (ckptCheckpointSection->sectionDescriptor.sectionId.id,
  281. id, idLen) == 0)) {
  282. return (ckptCheckpointSection);
  283. }
  284. }
  285. return 0;
  286. }
  287. void checkpoint_section_release (struct saCkptCheckpointSection *section)
  288. {
  289. list_del (&section->list);
  290. free (section->sectionDescriptor.sectionId.id);
  291. free (section->sectionData);
  292. poll_timer_delete (aisexec_poll_handle, section->expiration_timer);
  293. free (section);
  294. }
  295. void checkpoint_release (struct saCkptCheckpoint *checkpoint)
  296. {
  297. struct list_head *list;
  298. struct saCkptCheckpointSection *section;
  299. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  300. /*
  301. * Release all checkpoint sections for this checkpoint
  302. */
  303. for (list = checkpoint->checkpointSectionsListHead.next;
  304. list != &checkpoint->checkpointSectionsListHead;) {
  305. section = list_entry (list,
  306. struct saCkptCheckpointSection, list);
  307. list = list->next;
  308. checkpoint_section_release (section);
  309. }
  310. list_del (&checkpoint->list);
  311. free (checkpoint);
  312. }
  313. int ckpt_checkpoint_close (struct saCkptCheckpoint *checkpoint) {
  314. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  315. struct iovec iovecs[2];
  316. if (checkpoint->expired == 1) {
  317. return (0);
  318. }
  319. req_exec_ckpt_checkpointclose.header.size =
  320. sizeof (struct req_exec_ckpt_checkpointclose);
  321. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  322. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  323. &checkpoint->name, sizeof (SaNameT));
  324. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  325. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  326. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  327. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  328. return (0);
  329. }
  330. return (-1);
  331. }
  332. static int ckpt_exec_init_fn (void)
  333. {
  334. #ifdef TODO
  335. int res;
  336. res = totempg_recovery_plug_create (&ckpt_checkpoint_recovery_plug_handle);
  337. if (res != 0) {
  338. log_printf(LOG_LEVEL_ERROR,
  339. "Could not create recovery plug for clm service.\n");
  340. return (-1);
  341. }
  342. #endif
  343. return (0);
  344. }
  345. static int ckpt_exit_fn (struct conn_info *conn_info)
  346. {
  347. struct checkpoint_cleanup *checkpoint_cleanup;
  348. struct list_head *list;
  349. if (conn_info->service != SOCKET_SERVICE_CKPT) {
  350. return 0;
  351. }
  352. /*
  353. * close all checkpoints opened on this fd
  354. */
  355. for (list = conn_info->ais_ci.u.libckpt_ci.checkpoint_list.next;
  356. list != &conn_info->ais_ci.u.libckpt_ci.checkpoint_list;) {
  357. checkpoint_cleanup = list_entry (list,
  358. struct checkpoint_cleanup, list);
  359. ckpt_checkpoint_close (checkpoint_cleanup->checkpoint);
  360. list = list->next;
  361. free (checkpoint_cleanup);
  362. }
  363. #ifdef TODO
  364. /* todo close section iterators
  365. */
  366. // TODO what about exit of open checkpoints
  367. if (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries) {
  368. free (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries);
  369. }
  370. list_del (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list);
  371. #endif
  372. return (0);
  373. }
  374. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  375. {
  376. struct res_lib_activatepoll res_lib_activatepoll;
  377. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  378. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  379. res_lib_activatepoll.header.error = SA_AIS_OK;
  380. libais_send_response (conn_info, &res_lib_activatepoll,
  381. sizeof (struct res_lib_activatepoll));
  382. return (0);
  383. }
  384. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr, int endian_conversion_required)
  385. {
  386. struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)message;
  387. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)&req_exec_ckpt_checkpointopen->req_lib_ckpt_checkpointopen;
  388. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  389. struct saCkptCheckpoint *ckptCheckpoint = 0;
  390. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  391. struct checkpoint_cleanup *checkpoint_cleanup;
  392. SaErrorT error = SA_AIS_OK;
  393. log_printf (LOG_LEVEL_DEBUG, "Executive request to open checkpoint %p\n", req_exec_ckpt_checkpointopen);
  394. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointopen->checkpointName);
  395. /*
  396. * If checkpoint doesn't exist, create one
  397. */
  398. if (ckptCheckpoint == 0) {
  399. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  400. if (ckptCheckpoint == 0) {
  401. error = SA_AIS_ERR_NO_MEMORY;
  402. goto error_exit;
  403. }
  404. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  405. if (ckptCheckpointSection == 0) {
  406. free (ckptCheckpoint);
  407. error = SA_AIS_ERR_NO_MEMORY;
  408. goto error_exit;
  409. }
  410. memcpy (&ckptCheckpoint->name,
  411. &req_lib_ckpt_checkpointopen->checkpointName,
  412. sizeof (SaNameT));
  413. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  414. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  415. sizeof (SaCkptCheckpointCreationAttributesT));
  416. ckptCheckpoint->unlinked = 0;
  417. list_init (&ckptCheckpoint->list);
  418. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  419. list_add (&ckptCheckpoint->list, &checkpointListHead);
  420. ckptCheckpoint->referenceCount = 0;
  421. ckptCheckpoint->retention_timer = 0;
  422. ckptCheckpoint->expired = 0;
  423. /*
  424. * Add in default checkpoint section
  425. */
  426. list_init (&ckptCheckpointSection->list);
  427. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  428. /*
  429. * Default section id
  430. */
  431. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  432. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  433. ckptCheckpointSection->sectionDescriptor.sectionSize = 0;
  434. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  435. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  436. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; // current time
  437. ckptCheckpointSection->sectionData = 0;
  438. ckptCheckpointSection->expiration_timer = 0;
  439. }
  440. /*
  441. * If the checkpoint has been unlinked, it is an invalid name
  442. */
  443. if (ckptCheckpoint->unlinked) {
  444. error = SA_AIS_ERR_INVALID_PARAM; /* Is this the correct return ? */
  445. goto error_exit;
  446. }
  447. /*
  448. * Setup connection information and mark checkpoint as referenced
  449. */
  450. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", ckptCheckpoint);
  451. ckptCheckpoint->referenceCount += 1;
  452. /*
  453. * Reset retention duration since this checkpoint was just opened
  454. */
  455. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  456. ckptCheckpoint->retention_timer = 0;
  457. /*
  458. * Send error result to CKPT library
  459. */
  460. error_exit:
  461. /*
  462. * If this node was the source of the message, respond to this node
  463. */
  464. if (req_exec_ckpt_checkpointopen->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  465. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  466. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  467. res_lib_ckpt_checkpointopen.header.error = error;
  468. checkpoint_cleanup = malloc (sizeof (struct checkpoint_cleanup));
  469. if (checkpoint_cleanup == 0) {
  470. free (ckptCheckpoint);
  471. error = SA_AIS_ERR_NO_MEMORY;
  472. } else {
  473. checkpoint_cleanup->checkpoint = ckptCheckpoint;
  474. list_add (&checkpoint_cleanup->list,
  475. &req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  476. }
  477. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info, &res_lib_ckpt_checkpointopen,
  478. sizeof (struct res_lib_ckpt_checkpointopen));
  479. }
  480. // return (error == SA_AIS_OK ? 0 : -1);
  481. return (0);
  482. }
  483. unsigned int abstime_to_msec (SaTimeT time)
  484. {
  485. struct timeval tv;
  486. unsigned long long curr_time;
  487. unsigned long long msec_time;
  488. gettimeofday (&tv, NULL);
  489. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  490. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  491. msec_time = (((unsigned long long)time) / 1000000) -
  492. (unsigned long long)curr_time;
  493. return ((unsigned int)(msec_time));
  494. }
  495. void timer_function_section_expire (void *data)
  496. {
  497. struct saCkptCheckpointSection *section = (struct saCkptCheckpointSection *)data;
  498. if (section->sectionDescriptor.sectionId.id) {
  499. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring section %s\n", section->sectionDescriptor.sectionId.id);
  500. }
  501. checkpoint_section_release (section);
  502. }
  503. void timer_function_retention (void *data)
  504. {
  505. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  506. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  507. struct iovec iovec;
  508. checkpoint->retention_timer = 0;
  509. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  510. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  511. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  512. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  513. &checkpoint->name,
  514. sizeof (SaNameT));
  515. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  516. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  517. assert (totempg_mcast (&iovec, 1, TOTEMPG_AGREED) == 0);
  518. }
  519. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required)
  520. {
  521. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  522. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  523. struct saCkptCheckpoint *checkpoint = 0;
  524. SaAisErrorT error = SA_AIS_OK;
  525. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  526. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointclose->checkpointName);
  527. if (checkpoint == 0) {
  528. goto error_exit;
  529. }
  530. checkpoint->referenceCount--;
  531. assert (checkpoint->referenceCount >= 0);
  532. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  533. checkpoint->referenceCount);
  534. /*
  535. * If checkpoint has been unlinked and this is the last reference, delete it
  536. */
  537. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  538. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  539. checkpoint_release (checkpoint);
  540. } else
  541. if (checkpoint->referenceCount == 0) {
  542. poll_timer_add (aisexec_poll_handle,
  543. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  544. checkpoint,
  545. timer_function_retention,
  546. &checkpoint->retention_timer);
  547. }
  548. error_exit:
  549. if (req_exec_ckpt_checkpointclose->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  550. ckpt_checkpoint_remove_cleanup (req_exec_ckpt_checkpointclose->source.conn_info,
  551. checkpoint);
  552. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  553. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  554. res_lib_ckpt_checkpointclose.header.error = error;
  555. libais_send_response (req_exec_ckpt_checkpointclose->source.conn_info,
  556. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  557. }
  558. return (0);
  559. }
  560. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required)
  561. {
  562. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  563. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  564. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  565. struct saCkptCheckpoint *ckptCheckpoint = 0;
  566. SaErrorT error = SA_AIS_OK;
  567. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  568. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointunlink->checkpointName);
  569. if (ckptCheckpoint == 0) {
  570. error = SA_AIS_ERR_NOT_EXIST;
  571. goto error_exit;
  572. }
  573. if (ckptCheckpoint->unlinked) {
  574. error = SA_AIS_ERR_INVALID_PARAM;
  575. goto error_exit;
  576. }
  577. ckptCheckpoint->unlinked = 1;
  578. /*
  579. * Immediately delete entry if reference count is zero
  580. */
  581. if (ckptCheckpoint->referenceCount == 0) {
  582. /*
  583. * Remove retention timer since this checkpoint was unlinked and is no
  584. * longer referenced
  585. */
  586. checkpoint_release (ckptCheckpoint);
  587. }
  588. error_exit:
  589. /*
  590. * If this node was the source of the message, respond to this node
  591. */
  592. if (req_exec_ckpt_checkpointunlink->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  593. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  594. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  595. res_lib_ckpt_checkpointunlink.header.error = error;
  596. libais_send_response (req_exec_ckpt_checkpointunlink->source.conn_info, &res_lib_ckpt_checkpointunlink,
  597. sizeof (struct res_lib_ckpt_checkpointunlink));
  598. }
  599. return (0);
  600. }
  601. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required)
  602. {
  603. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  604. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  605. struct saCkptCheckpoint *checkpoint;
  606. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  607. if (checkpoint) {
  608. log_printf (LOG_LEVEL_NOTICE, "CKPT: Setting retention duration for checkpoint %s\n",
  609. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  610. checkpoint->checkpointCreationAttributes.retentionDuration = req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  611. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  612. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  613. poll_timer_add (aisexec_poll_handle,
  614. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  615. checkpoint,
  616. timer_function_retention,
  617. &checkpoint->retention_timer);
  618. }
  619. }
  620. /*
  621. * Respond to library if this processor sent the duration set request
  622. */
  623. if (req_exec_ckpt_checkpointretentiondurationset->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  624. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  625. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  626. res_lib_ckpt_checkpointretentiondurationset.header.error = SA_AIS_OK;
  627. libais_send_response (req_exec_ckpt_checkpointretentiondurationset->source.conn_info,
  628. &res_lib_ckpt_checkpointretentiondurationset,
  629. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  630. }
  631. return (0);
  632. }
  633. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required)
  634. {
  635. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  636. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  637. struct saCkptCheckpoint *checkpoint;
  638. struct iovec iovecs[2];
  639. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  640. if (checkpoint && checkpoint->expired == 0) {
  641. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  642. checkpoint->expired = 1;
  643. req_exec_ckpt_checkpointunlink.header.size =
  644. sizeof (struct req_exec_ckpt_checkpointunlink);
  645. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  646. req_exec_ckpt_checkpointunlink.source.conn_info = 0;
  647. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = 0;
  648. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  649. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  650. sizeof (SaNameT));
  651. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  652. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  653. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  654. }
  655. return (0);
  656. }
  657. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required) {
  658. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  659. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  660. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  661. struct saCkptCheckpoint *ckptCheckpoint;
  662. struct saCkptCheckpointSection *ckptCheckpointSection;
  663. void *initialData;
  664. void *sectionId;
  665. SaErrorT error = SA_AIS_OK;
  666. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  667. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectioncreate->checkpointName);
  668. if (ckptCheckpoint == 0) {
  669. error = SA_AIS_ERR_LIBRARY; // TODO find the right error for this
  670. goto error_exit;
  671. }
  672. /*
  673. * Determine if user-specified checkpoint ID already exists
  674. */
  675. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  676. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  677. req_lib_ckpt_sectioncreate->idLen);
  678. if (ckptCheckpointSection) {
  679. error = SA_AIS_ERR_EXIST;
  680. goto error_exit;
  681. }
  682. /*
  683. * Allocate checkpoint section
  684. */
  685. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  686. if (ckptCheckpointSection == 0) {
  687. error = SA_AIS_ERR_NO_MEMORY;
  688. goto error_exit;
  689. }
  690. /*
  691. * Allocate checkpoint section data
  692. */
  693. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  694. if (initialData == 0) {
  695. free (ckptCheckpointSection);
  696. error = SA_AIS_ERR_NO_MEMORY;
  697. goto error_exit;
  698. }
  699. /*
  700. * Allocate checkpoint section id
  701. */
  702. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  703. if (sectionId == 0) {
  704. free (ckptCheckpointSection);
  705. free (initialData);
  706. error = SA_AIS_ERR_NO_MEMORY;
  707. goto error_exit;
  708. }
  709. /*
  710. * Copy checkpoint section and section ID
  711. */
  712. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  713. req_lib_ckpt_sectioncreate->idLen);
  714. memcpy (initialData,
  715. ((char *)req_lib_ckpt_sectioncreate) +
  716. sizeof (struct req_lib_ckpt_sectioncreate) +
  717. req_lib_ckpt_sectioncreate->idLen,
  718. req_lib_ckpt_sectioncreate->initialDataSize);
  719. /*
  720. * Configure checkpoint section
  721. */
  722. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  723. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  724. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  725. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  726. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  727. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; // TODO current time
  728. ckptCheckpointSection->sectionData = initialData;
  729. ckptCheckpointSection->expiration_timer = 0;
  730. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  731. poll_timer_add (aisexec_poll_handle,
  732. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  733. ckptCheckpointSection,
  734. timer_function_section_expire,
  735. &ckptCheckpointSection->expiration_timer);
  736. }
  737. /*
  738. * Add checkpoint section to checkpoint
  739. */
  740. list_init (&ckptCheckpointSection->list);
  741. list_add (&ckptCheckpointSection->list,
  742. &ckptCheckpoint->checkpointSectionsListHead);
  743. error_exit:
  744. if (req_exec_ckpt_sectioncreate->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  745. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  746. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  747. res_lib_ckpt_sectioncreate.header.error = error;
  748. libais_send_response (req_exec_ckpt_sectioncreate->source.conn_info,
  749. &res_lib_ckpt_sectioncreate,
  750. sizeof (struct res_lib_ckpt_sectioncreate));
  751. }
  752. return (0);
  753. }
  754. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required) {
  755. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  756. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  757. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  758. struct saCkptCheckpoint *ckptCheckpoint;
  759. struct saCkptCheckpointSection *ckptCheckpointSection;
  760. SaErrorT error = SA_AIS_OK;
  761. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectiondelete->checkpointName);
  762. if (ckptCheckpoint == 0) {
  763. error = SA_AIS_ERR_NOT_EXIST;
  764. goto error_exit;
  765. }
  766. /*
  767. * Determine if the user is trying to delete the default section
  768. */
  769. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  770. error = SA_AIS_ERR_INVALID_PARAM;
  771. goto error_exit;
  772. }
  773. /*
  774. * Find checkpoint section to be deleted
  775. */
  776. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  777. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  778. req_lib_ckpt_sectiondelete->idLen);
  779. if (ckptCheckpointSection == 0) {
  780. error = SA_AIS_ERR_NOT_EXIST;
  781. goto error_exit;
  782. }
  783. /*
  784. * Delete checkpoint section
  785. */
  786. checkpoint_section_release (ckptCheckpointSection);
  787. /*
  788. * return result to CKPT library
  789. */
  790. error_exit:
  791. if (req_exec_ckpt_sectiondelete->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  792. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  793. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  794. res_lib_ckpt_sectiondelete.header.error = error;
  795. libais_send_response (req_exec_ckpt_sectiondelete->source.conn_info,
  796. &res_lib_ckpt_sectiondelete,
  797. sizeof (struct res_lib_ckpt_sectiondelete));
  798. }
  799. return (0);
  800. }
  801. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required) {
  802. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  803. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  804. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  805. struct saCkptCheckpoint *ckptCheckpoint;
  806. struct saCkptCheckpointSection *ckptCheckpointSection;
  807. SaErrorT error = SA_AIS_OK;
  808. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  809. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  810. if (ckptCheckpoint == 0) {
  811. error = SA_AIS_ERR_NOT_EXIST;
  812. goto error_exit;
  813. }
  814. /*
  815. * Determine if the user is trying to set expiration time for the default section
  816. */
  817. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  818. error = SA_AIS_ERR_INVALID_PARAM;
  819. goto error_exit;
  820. }
  821. /*
  822. * Find checkpoint section that expiration time should be set for
  823. */
  824. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  825. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  826. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  827. req_lib_ckpt_sectionexpirationtimeset->idLen);
  828. if (ckptCheckpointSection == 0) {
  829. error = SA_AIS_ERR_NOT_EXIST;
  830. goto error_exit;
  831. }
  832. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  833. poll_timer_delete (aisexec_poll_handle, ckptCheckpointSection->expiration_timer);
  834. ckptCheckpointSection->expiration_timer = 0;
  835. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  836. poll_timer_add (aisexec_poll_handle,
  837. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  838. ckptCheckpointSection,
  839. timer_function_section_expire,
  840. &ckptCheckpointSection->expiration_timer);
  841. }
  842. error_exit:
  843. if (req_exec_ckpt_sectionexpirationtimeset->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  844. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  845. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  846. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  847. libais_send_response (req_exec_ckpt_sectionexpirationtimeset->source.conn_info,
  848. &res_lib_ckpt_sectionexpirationtimeset,
  849. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  850. }
  851. return (0);
  852. }
  853. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  854. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  855. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  856. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  857. struct saCkptCheckpoint *ckptCheckpoint;
  858. struct saCkptCheckpointSection *ckptCheckpointSection;
  859. int sizeRequired;
  860. void *sectionData;
  861. SaErrorT error = SA_AIS_OK;
  862. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  863. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionwrite->checkpointName);
  864. if (ckptCheckpoint == 0) {
  865. error = SA_AIS_ERR_NOT_EXIST;
  866. goto error_exit;
  867. }
  868. //printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  869. /*
  870. * Find checkpoint section to be written
  871. */
  872. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  873. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  874. req_lib_ckpt_sectionwrite->idLen);
  875. if (ckptCheckpointSection == 0) {
  876. printf ("CANT FIND SECTION '%s'\n",
  877. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  878. error = SA_AIS_ERR_NOT_EXIST;
  879. goto error_exit;
  880. }
  881. /*
  882. * If write would extend past end of section data, enlarge section
  883. */
  884. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  885. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  886. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  887. if (sectionData == 0) {
  888. error = SA_AIS_ERR_NO_MEMORY;
  889. goto error_exit;
  890. }
  891. /*
  892. * Install new section data
  893. */
  894. ckptCheckpointSection->sectionData = sectionData;
  895. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  896. }
  897. /*
  898. * Write checkpoint section to section data
  899. */
  900. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  901. char *sd;
  902. int *val;
  903. val = ckptCheckpointSection->sectionData;
  904. sd = (char *)ckptCheckpointSection->sectionData;
  905. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  906. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  907. req_lib_ckpt_sectionwrite->idLen,
  908. req_lib_ckpt_sectionwrite->dataSize);
  909. }
  910. /*
  911. * Write write response to CKPT library
  912. */
  913. error_exit:
  914. if (req_exec_ckpt_sectionwrite->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  915. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  916. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  917. res_lib_ckpt_sectionwrite.header.error = error;
  918. libais_send_response (req_exec_ckpt_sectionwrite->source.conn_info,
  919. &res_lib_ckpt_sectionwrite,
  920. sizeof (struct res_lib_ckpt_sectionwrite));
  921. }
  922. return (0);
  923. }
  924. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  925. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  926. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  927. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  928. struct saCkptCheckpoint *ckptCheckpoint;
  929. struct saCkptCheckpointSection *ckptCheckpointSection;
  930. void *sectionData;
  931. SaErrorT error = SA_AIS_OK;
  932. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  933. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionoverwrite->checkpointName);
  934. if (ckptCheckpoint == 0) {
  935. error = SA_AIS_ERR_NOT_EXIST;
  936. goto error_exit;
  937. }
  938. /*
  939. * Find checkpoint section to be overwritten
  940. */
  941. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  942. ((char *)req_lib_ckpt_sectionoverwrite) +
  943. sizeof (struct req_lib_ckpt_sectionoverwrite),
  944. req_lib_ckpt_sectionoverwrite->idLen);
  945. if (ckptCheckpointSection == 0) {
  946. error = SA_AIS_ERR_NOT_EXIST;
  947. goto error_exit;
  948. }
  949. /*
  950. * Allocate checkpoint section data
  951. */
  952. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  953. if (sectionData == 0) {
  954. error = SA_AIS_ERR_NO_MEMORY;
  955. goto error_exit;
  956. }
  957. memcpy (sectionData,
  958. ((char *)req_lib_ckpt_sectionoverwrite) +
  959. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  960. req_lib_ckpt_sectionoverwrite->idLen,
  961. req_lib_ckpt_sectionoverwrite->dataSize);
  962. /*
  963. * release old checkpoint section data
  964. */
  965. free (ckptCheckpointSection->sectionData);
  966. /*
  967. * Install overwritten checkpoint section data
  968. */
  969. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  970. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  971. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; // TODO current time
  972. ckptCheckpointSection->sectionData = sectionData;
  973. /*
  974. * return result to CKPT library
  975. */
  976. error_exit:
  977. if (req_exec_ckpt_sectionoverwrite->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  978. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  979. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  980. res_lib_ckpt_sectionoverwrite.header.error = error;
  981. libais_send_response (req_exec_ckpt_sectionoverwrite->source.conn_info,
  982. &res_lib_ckpt_sectionoverwrite,
  983. sizeof (struct res_lib_ckpt_sectionoverwrite));
  984. }
  985. return (0);
  986. }
  987. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required) {
  988. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  989. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  990. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  991. struct saCkptCheckpoint *ckptCheckpoint;
  992. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  993. int sectionSize = 0;
  994. SaErrorT error = SA_AIS_OK;
  995. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  996. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionread->checkpointName);
  997. if (ckptCheckpoint == 0) {
  998. error = SA_AIS_ERR_LIBRARY; // TODO find the right error for this
  999. goto error_exit;
  1000. }
  1001. /*
  1002. * Find checkpoint section to be read
  1003. */
  1004. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1005. ((char *)req_lib_ckpt_sectionread) +
  1006. sizeof (struct req_lib_ckpt_sectionread),
  1007. req_lib_ckpt_sectionread->idLen);
  1008. if (ckptCheckpointSection == 0) {
  1009. error = SA_AIS_ERR_NOT_EXIST;
  1010. goto error_exit;
  1011. }
  1012. /*
  1013. * Determine the section size
  1014. */
  1015. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  1016. req_lib_ckpt_sectionread->dataOffset;
  1017. /*
  1018. * If the library has less space available then can be sent from the
  1019. * section, reduce bytes sent to library to max requested
  1020. */
  1021. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  1022. sectionSize = req_lib_ckpt_sectionread->dataSize;
  1023. }
  1024. /*
  1025. * If dataOffset is past end of data, return INVALID PARAM
  1026. */
  1027. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  1028. sectionSize = 0;
  1029. error = SA_AIS_ERR_INVALID_PARAM;
  1030. goto error_exit;
  1031. }
  1032. /*
  1033. * Write read response to CKPT library
  1034. */
  1035. error_exit:
  1036. if (req_exec_ckpt_sectionread->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1037. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  1038. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  1039. res_lib_ckpt_sectionread.header.error = error;
  1040. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1041. &res_lib_ckpt_sectionread,
  1042. sizeof (struct res_lib_ckpt_sectionread));
  1043. /*
  1044. * Write checkpoint to CKPT library section if section has data
  1045. */
  1046. if (sectionSize) {
  1047. char *sd;
  1048. sd = (char *)ckptCheckpointSection->sectionData;
  1049. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1050. &sd[req_lib_ckpt_sectionread->dataOffset],
  1051. sectionSize);
  1052. }
  1053. }
  1054. return (0);
  1055. }
  1056. static int message_handler_req_lib_ckpt_init (struct conn_info *conn_info, void *message)
  1057. {
  1058. struct res_lib_init res_lib_init;
  1059. SaErrorT error = SA_AIS_ERR_ACCESS;
  1060. log_printf (LOG_LEVEL_DEBUG, "Got request to initialize CKPT checkpoint.\n");
  1061. if (conn_info->authenticated) {
  1062. conn_info->service = SOCKET_SERVICE_CKPT;
  1063. list_init (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list);
  1064. conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  1065. conn_info->ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  1066. conn_info->ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  1067. list_add (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list,
  1068. &checkpointIteratorListHead);
  1069. list_init (&conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  1070. error = SA_AIS_OK;
  1071. }
  1072. res_lib_init.header.size = sizeof (struct res_lib_init);
  1073. res_lib_init.header.id = MESSAGE_RES_INIT;
  1074. res_lib_init.header.error = error;
  1075. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1076. if (conn_info->authenticated) {
  1077. return (0);
  1078. }
  1079. return (-1);
  1080. }
  1081. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message)
  1082. {
  1083. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)message;
  1084. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  1085. struct iovec iovecs[2];
  1086. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  1087. req_exec_ckpt_checkpointopen.header.size =
  1088. sizeof (struct req_exec_ckpt_checkpointopen);
  1089. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  1090. req_exec_ckpt_checkpointopen.source.conn_info = conn_info;
  1091. req_exec_ckpt_checkpointopen.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1092. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  1093. req_lib_ckpt_checkpointopen,
  1094. sizeof (struct req_lib_ckpt_checkpointopen));
  1095. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  1096. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  1097. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1098. return (0);
  1099. }
  1100. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  1101. {
  1102. return (0);
  1103. }
  1104. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message) {
  1105. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)message;
  1106. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  1107. struct saCkptCheckpoint *checkpoint;
  1108. struct iovec iovecs[2];
  1109. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointclose->checkpointName);
  1110. if (checkpoint->expired == 1) {
  1111. return (0);
  1112. }
  1113. req_exec_ckpt_checkpointclose.header.size =
  1114. sizeof (struct req_exec_ckpt_checkpointclose);
  1115. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  1116. req_exec_ckpt_checkpointclose.source.conn_info = conn_info;
  1117. req_exec_ckpt_checkpointclose.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1118. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  1119. &checkpoint->name, sizeof (SaNameT));
  1120. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  1121. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  1122. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  1123. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1124. }
  1125. return (0);
  1126. }
  1127. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  1128. {
  1129. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  1130. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1131. struct iovec iovecs[2];
  1132. req_exec_ckpt_checkpointunlink.header.size =
  1133. sizeof (struct req_exec_ckpt_checkpointunlink);
  1134. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1135. req_exec_ckpt_checkpointunlink.source.conn_info = conn_info;
  1136. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1137. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  1138. req_lib_ckpt_checkpointunlink,
  1139. sizeof (struct req_lib_ckpt_checkpointunlink));
  1140. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1141. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1142. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1143. return (0);
  1144. }
  1145. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  1146. {
  1147. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  1148. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  1149. struct iovec iovecs[2];
  1150. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info->fd);
  1151. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  1152. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  1153. req_exec_ckpt_checkpointretentiondurationset.source.conn_info = conn_info;
  1154. req_exec_ckpt_checkpointretentiondurationset.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1155. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  1156. &req_lib_ckpt_checkpointretentiondurationset->checkpointName,
  1157. sizeof (SaNameT));
  1158. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  1159. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  1160. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  1161. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1162. return (0);
  1163. }
  1164. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message)
  1165. {
  1166. return (0);
  1167. }
  1168. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  1169. {
  1170. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  1171. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  1172. struct saCkptCheckpoint *checkpoint;
  1173. int memoryUsed = 0;
  1174. int numberOfSections = 0;
  1175. struct list_head *checkpointSectionList;
  1176. struct saCkptCheckpointSection *checkpointSection;
  1177. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  1178. /*
  1179. * Count memory used by checkpoint sections
  1180. */
  1181. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointstatusget->checkpointName);
  1182. for (checkpointSectionList = checkpoint->checkpointSectionsListHead.next;
  1183. checkpointSectionList != &checkpoint->checkpointSectionsListHead;
  1184. checkpointSectionList = checkpointSectionList->next) {
  1185. checkpointSection = list_entry (checkpointSectionList,
  1186. struct saCkptCheckpointSection, list);
  1187. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  1188. numberOfSections += 1;
  1189. }
  1190. /*
  1191. * Build checkpoint status get response
  1192. */
  1193. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  1194. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  1195. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  1196. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointDescriptor.checkpointCreationAttributes,
  1197. &checkpoint->checkpointCreationAttributes,
  1198. sizeof (SaCkptCheckpointCreationAttributesT));
  1199. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.numberOfSections = numberOfSections;
  1200. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.memoryUsed = memoryUsed;
  1201. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  1202. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  1203. sizeof (struct res_lib_ckpt_checkpointstatusget));
  1204. return (0);
  1205. }
  1206. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  1207. {
  1208. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  1209. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  1210. struct iovec iovecs[2];
  1211. struct saCkptCheckpoint *checkpoint;
  1212. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info->fd);
  1213. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioncreate->checkpointName);
  1214. /*
  1215. * checkpoint opened is writeable mode so send message to cluster
  1216. */
  1217. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  1218. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  1219. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  1220. req_lib_ckpt_sectioncreate,
  1221. sizeof (struct req_lib_ckpt_sectioncreate));
  1222. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  1223. &req_lib_ckpt_sectioncreate->checkpointName,
  1224. sizeof (SaNameT));
  1225. req_exec_ckpt_sectioncreate.source.conn_info = conn_info;
  1226. req_exec_ckpt_sectioncreate.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1227. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  1228. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  1229. /*
  1230. * Send section name and initial data in message
  1231. */
  1232. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  1233. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  1234. #ifdef DEBUG
  1235. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  1236. iovecs[1].iov_len);
  1237. printf ("|\n");
  1238. { int i;
  1239. char *abc = iovecs[1].iov_base;
  1240. for (i = 0; i < 14;i++) {
  1241. printf ("%c ", abc[i]);
  1242. }
  1243. }
  1244. printf ("|\n");
  1245. #endif
  1246. if (iovecs[1].iov_len > 0) {
  1247. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  1248. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  1249. } else {
  1250. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1251. }
  1252. return (0);
  1253. }
  1254. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  1255. {
  1256. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  1257. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  1258. struct iovec iovecs[2];
  1259. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info->fd);
  1260. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  1261. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  1262. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  1263. &req_lib_ckpt_sectiondelete->checkpointName,
  1264. sizeof (SaNameT));
  1265. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  1266. req_lib_ckpt_sectiondelete,
  1267. sizeof (struct req_lib_ckpt_sectiondelete));
  1268. req_exec_ckpt_sectiondelete.source.conn_info = conn_info;
  1269. req_exec_ckpt_sectiondelete.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1270. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  1271. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  1272. /*
  1273. * Send section name
  1274. */
  1275. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  1276. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  1277. if (iovecs[1].iov_len > 0) {
  1278. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  1279. } else {
  1280. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1281. }
  1282. return (0);
  1283. }
  1284. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  1285. {
  1286. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  1287. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  1288. struct iovec iovecs[2];
  1289. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info->fd);
  1290. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  1291. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  1292. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  1293. &req_lib_ckpt_sectionexpirationtimeset->checkpointName,
  1294. sizeof (SaNameT));
  1295. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  1296. req_lib_ckpt_sectionexpirationtimeset,
  1297. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  1298. req_exec_ckpt_sectionexpirationtimeset.source.conn_info = conn_info;
  1299. req_exec_ckpt_sectionexpirationtimeset.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1300. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  1301. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  1302. /*
  1303. * Send section name
  1304. */
  1305. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  1306. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  1307. if (iovecs[1].iov_len > 0) {
  1308. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  1309. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  1310. } else {
  1311. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1312. }
  1313. return (0);
  1314. }
  1315. int write_inv = 0;
  1316. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  1317. {
  1318. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  1319. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  1320. struct iovec iovecs[2];
  1321. struct saCkptCheckpoint *checkpoint;
  1322. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info->fd);
  1323. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionwrite->checkpointName);
  1324. /*
  1325. * checkpoint opened is writeable mode so send message to cluster
  1326. */
  1327. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  1328. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  1329. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  1330. req_lib_ckpt_sectionwrite,
  1331. sizeof (struct req_lib_ckpt_sectionwrite));
  1332. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  1333. &req_lib_ckpt_sectionwrite->checkpointName,
  1334. sizeof (SaNameT));
  1335. req_exec_ckpt_sectionwrite.source.conn_info = conn_info;
  1336. req_exec_ckpt_sectionwrite.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1337. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  1338. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  1339. /*
  1340. * Send section name and data to write in message
  1341. */
  1342. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  1343. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  1344. //printf ("LIB writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1345. if (iovecs[1].iov_len > 0) {
  1346. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  1347. } else {
  1348. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1349. }
  1350. return (0);
  1351. }
  1352. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  1353. {
  1354. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  1355. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  1356. struct iovec iovecs[2];
  1357. struct saCkptCheckpoint *checkpoint;
  1358. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  1359. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionoverwrite->checkpointName);
  1360. /*
  1361. * checkpoint opened is writeable mode so send message to cluster
  1362. */
  1363. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  1364. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  1365. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  1366. req_lib_ckpt_sectionoverwrite,
  1367. sizeof (struct req_lib_ckpt_sectionoverwrite));
  1368. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  1369. &req_lib_ckpt_sectionoverwrite->checkpointName,
  1370. sizeof (SaNameT));
  1371. req_exec_ckpt_sectionoverwrite.source.conn_info = conn_info;
  1372. req_exec_ckpt_sectionoverwrite.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1373. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  1374. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  1375. /*
  1376. * Send section name and data to overwrite in message
  1377. */
  1378. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  1379. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  1380. if (iovecs[1].iov_len > 0) {
  1381. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  1382. } else {
  1383. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1384. }
  1385. return (0);
  1386. }
  1387. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  1388. {
  1389. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  1390. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  1391. struct iovec iovecs[2];
  1392. struct saCkptCheckpoint *checkpoint;
  1393. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  1394. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionread->checkpointName);
  1395. /*
  1396. * checkpoint opened is writeable mode so send message to cluster
  1397. */
  1398. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  1399. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  1400. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  1401. req_lib_ckpt_sectionread,
  1402. sizeof (struct req_lib_ckpt_sectionread));
  1403. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  1404. &req_lib_ckpt_sectionread->checkpointName,
  1405. sizeof (SaNameT));
  1406. req_exec_ckpt_sectionread.source.conn_info = conn_info;
  1407. req_exec_ckpt_sectionread.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1408. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  1409. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  1410. /*
  1411. * Send section name and data to overwrite in message
  1412. */
  1413. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  1414. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  1415. if (iovecs[1].iov_len > 0) {
  1416. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  1417. } else {
  1418. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1419. }
  1420. return (0);
  1421. }
  1422. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  1423. {
  1424. return (0);
  1425. }
  1426. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  1427. {
  1428. return (0);
  1429. }
  1430. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message)
  1431. {
  1432. struct req_lib_ckpt_sectioniteratorinitialize *req_lib_ckpt_sectioniteratorinitialize = (struct req_lib_ckpt_sectioniteratorinitialize *)message;
  1433. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  1434. struct saCkptCheckpoint *ckptCheckpoint;
  1435. struct saCkptCheckpointSection *ckptCheckpointSection;
  1436. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  1437. struct saCkptSectionIterator *ckptSectionIterator;
  1438. struct list_head *checkpointSectionList;
  1439. int addEntry = 0;
  1440. int iteratorEntries = 0;
  1441. SaErrorT error = SA_AIS_OK;
  1442. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  1443. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  1444. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniteratorinitialize->checkpointName);
  1445. if (ckptCheckpoint == 0) {
  1446. error = SA_AIS_ERR_NOT_EXIST;
  1447. goto error_exit;
  1448. }
  1449. /*
  1450. * Iterate list of checkpoint sections
  1451. */
  1452. for (checkpointSectionList = ckptCheckpoint->checkpointSectionsListHead.next;
  1453. checkpointSectionList != &ckptCheckpoint->checkpointSectionsListHead;
  1454. checkpointSectionList = checkpointSectionList->next) {
  1455. ckptCheckpointSection = list_entry (checkpointSectionList,
  1456. struct saCkptCheckpointSection, list);
  1457. addEntry = 1;
  1458. /*
  1459. * Item should be added to iterator list
  1460. */
  1461. if (addEntry) {
  1462. iteratorEntries += 1;
  1463. ckptSectionIteratorEntries =
  1464. realloc (ckptSectionIterator->sectionIteratorEntries,
  1465. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  1466. if (ckptSectionIteratorEntries == 0) {
  1467. if (ckptSectionIterator->sectionIteratorEntries) {
  1468. free (ckptSectionIterator->sectionIteratorEntries);
  1469. }
  1470. error = SA_AIS_ERR_NO_MEMORY;
  1471. goto error_exit;
  1472. }
  1473. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  1474. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  1475. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  1476. }
  1477. }
  1478. ckptSectionIterator->iteratorCount = iteratorEntries;
  1479. error_exit:
  1480. res_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize);
  1481. res_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  1482. res_lib_ckpt_sectioniteratorinitialize.header.error = error;
  1483. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratorinitialize,
  1484. sizeof (struct res_lib_ckpt_sectioniteratorinitialize));
  1485. return (0);
  1486. }
  1487. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  1488. {
  1489. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  1490. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  1491. struct saCkptSectionIterator *ckptSectionIterator;
  1492. SaErrorT error = SA_AIS_OK;
  1493. int sectionIdSize = 0;
  1494. int iteratorPos = 0;
  1495. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  1496. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  1497. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  1498. /*
  1499. * Find active iterator entry
  1500. */
  1501. for (;;) {
  1502. /*
  1503. * No more sections in iterator
  1504. */
  1505. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  1506. error = SA_AIS_ERR_NOT_EXIST;
  1507. goto error_exit;
  1508. }
  1509. /*
  1510. * active iterator entry
  1511. */
  1512. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  1513. break;
  1514. }
  1515. ckptSectionIterator->iteratorPos += 1;
  1516. }
  1517. /*
  1518. * Prepare response to API
  1519. */
  1520. iteratorPos = ckptSectionIterator->iteratorPos;
  1521. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  1522. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  1523. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  1524. sizeof (SaCkptSectionDescriptorT));
  1525. /*
  1526. * Get to next iterator entry
  1527. */
  1528. ckptSectionIterator->iteratorPos += 1;
  1529. error_exit:
  1530. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  1531. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  1532. res_lib_ckpt_sectioniteratornext.header.error = error;
  1533. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  1534. sizeof (struct res_lib_ckpt_sectioniteratornext));
  1535. libais_send_response (conn_info,
  1536. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  1537. sectionIdSize);
  1538. return (0);
  1539. }