ckpt.c 72 KB

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