ckpt.c 71 KB

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