ckpt.c 71 KB

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