ckpt.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  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. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_HIGH);
  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. int result;
  527. struct iovec iovec;
  528. checkpoint->retention_timer = 0;
  529. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  530. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  531. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  532. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  533. &checkpoint->name,
  534. sizeof (SaNameT));
  535. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  536. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  537. result = gmi_mcast (&aisexec_groupname, &iovec, 1, GMI_PRIO_MED);
  538. }
  539. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr)
  540. {
  541. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  542. struct saCkptCheckpoint *checkpoint = 0;
  543. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  544. checkpoint = findCheckpoint (&req_exec_ckpt_checkpointclose->checkpointName);
  545. if (checkpoint == 0) {
  546. return (0);
  547. }
  548. checkpoint->referenceCount--;
  549. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  550. checkpoint->referenceCount);
  551. /*
  552. * If checkpoint has been unlinked and this is the last reference, delete it
  553. */
  554. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  555. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  556. checkpoint_release (checkpoint);
  557. } else
  558. if (checkpoint->referenceCount == 0) {
  559. poll_timer_add (*gmi_poll_handle,
  560. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  561. checkpoint,
  562. timer_function_retention,
  563. &checkpoint->retention_timer);
  564. }
  565. return (0);
  566. }
  567. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr)
  568. {
  569. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  570. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  571. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  572. struct saCkptCheckpoint *ckptCheckpoint = 0;
  573. SaErrorT error = SA_OK;
  574. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  575. ckptCheckpoint = findCheckpoint (&req_lib_ckpt_checkpointunlink->checkpointName);
  576. if (ckptCheckpoint == 0) {
  577. error = SA_ERR_NOT_EXIST;
  578. goto error_exit;
  579. }
  580. if (ckptCheckpoint->unlinked) {
  581. error = SA_ERR_INVALID_PARAM;
  582. goto error_exit;
  583. }
  584. ckptCheckpoint->unlinked = 1;
  585. /*
  586. * Immediately delete entry if reference count is zero
  587. */
  588. if (ckptCheckpoint->referenceCount == 0) {
  589. /*
  590. * Remove retention timer since this checkpoint was unlinked and is no
  591. * longer referenced
  592. */
  593. checkpoint_release (ckptCheckpoint);
  594. }
  595. error_exit:
  596. /*
  597. * If this node was the source of the message, respond to this node
  598. */
  599. if (req_exec_ckpt_checkpointunlink->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  600. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  601. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  602. res_lib_ckpt_checkpointunlink.header.error = error;
  603. libais_send_response (req_exec_ckpt_checkpointunlink->source.conn_info, &res_lib_ckpt_checkpointunlink,
  604. sizeof (struct res_lib_ckpt_checkpointunlink));
  605. }
  606. return (0);
  607. }
  608. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr)
  609. {
  610. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  611. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  612. struct saCkptCheckpoint *checkpoint;
  613. checkpoint = findCheckpoint (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  614. if (checkpoint) {
  615. log_printf (LOG_LEVEL_NOTICE, "CKPT: Setting retention duration for checkpoint %s\n",
  616. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  617. checkpoint->checkpointCreationAttributes.retentionDuration = req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  618. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  619. poll_timer_delete (*gmi_poll_handle, checkpoint->retention_timer);
  620. poll_timer_add (*gmi_poll_handle,
  621. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  622. checkpoint,
  623. timer_function_retention,
  624. &checkpoint->retention_timer);
  625. }
  626. }
  627. /*
  628. * Respond to library if this processor sent the duration set request
  629. */
  630. if (req_exec_ckpt_checkpointretentiondurationset->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  631. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  632. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  633. res_lib_ckpt_checkpointretentiondurationset.header.error = SA_OK;
  634. libais_send_response (req_exec_ckpt_checkpointretentiondurationset->source.conn_info,
  635. &res_lib_ckpt_checkpointretentiondurationset,
  636. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  637. }
  638. return (0);
  639. }
  640. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr)
  641. {
  642. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  643. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  644. struct saCkptCheckpoint *checkpoint;
  645. struct iovec iovecs[2];
  646. checkpoint = findCheckpoint (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  647. if (checkpoint && checkpoint->expired == 0) {
  648. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  649. checkpoint->expired = 1;
  650. req_exec_ckpt_checkpointunlink.header.size =
  651. sizeof (struct req_exec_ckpt_checkpointunlink);
  652. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  653. req_exec_ckpt_checkpointunlink.source.conn_info = 0;
  654. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = 0;
  655. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  656. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  657. sizeof (SaNameT));
  658. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  659. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  660. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  661. }
  662. return (0);
  663. }
  664. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr) {
  665. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  666. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  667. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  668. struct saCkptCheckpoint *ckptCheckpoint;
  669. struct saCkptCheckpointSection *ckptCheckpointSection;
  670. void *initialData;
  671. void *sectionId;
  672. SaErrorT error = SA_OK;
  673. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  674. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectioncreate->checkpointName);
  675. if (ckptCheckpoint == 0) {
  676. error = SA_ERR_SYSTEM; // TODO find the right error for this
  677. goto error_exit;
  678. }
  679. /*
  680. * Determine if user-specified checkpoint ID already exists
  681. */
  682. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  683. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  684. req_lib_ckpt_sectioncreate->idLen);
  685. if (ckptCheckpointSection) {
  686. error = SA_ERR_EXIST;
  687. goto error_exit;
  688. }
  689. /*
  690. * Allocate checkpoint section
  691. */
  692. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  693. if (ckptCheckpointSection == 0) {
  694. error = SA_ERR_NO_MEMORY;
  695. goto error_exit;
  696. }
  697. /*
  698. * Allocate checkpoint section data
  699. */
  700. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  701. if (initialData == 0) {
  702. free (ckptCheckpointSection);
  703. error = SA_ERR_NO_MEMORY;
  704. goto error_exit;
  705. }
  706. /*
  707. * Allocate checkpoint section id
  708. */
  709. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  710. if (sectionId == 0) {
  711. free (ckptCheckpointSection);
  712. free (initialData);
  713. error = SA_ERR_NO_MEMORY;
  714. goto error_exit;
  715. }
  716. /*
  717. * Copy checkpoint section and section ID
  718. */
  719. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  720. req_lib_ckpt_sectioncreate->idLen);
  721. memcpy (initialData,
  722. ((char *)req_lib_ckpt_sectioncreate) +
  723. sizeof (struct req_lib_ckpt_sectioncreate) +
  724. req_lib_ckpt_sectioncreate->idLen,
  725. req_lib_ckpt_sectioncreate->initialDataSize);
  726. /*
  727. * Configure checkpoint section
  728. */
  729. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  730. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  731. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  732. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  733. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  734. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; // TODO current time
  735. ckptCheckpointSection->sectionData = initialData;
  736. ckptCheckpointSection->expiration_timer = 0;
  737. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  738. poll_timer_add (*gmi_poll_handle,
  739. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  740. ckptCheckpointSection,
  741. timer_function_section_expire,
  742. &ckptCheckpointSection->expiration_timer);
  743. }
  744. /*
  745. * Add checkpoint section to checkpoint
  746. */
  747. list_init (&ckptCheckpointSection->list);
  748. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  749. error_exit:
  750. if (req_exec_ckpt_sectioncreate->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  751. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  752. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  753. res_lib_ckpt_sectioncreate.header.error = error;
  754. libais_send_response (req_exec_ckpt_sectioncreate->source.conn_info,
  755. &res_lib_ckpt_sectioncreate,
  756. sizeof (struct res_lib_ckpt_sectioncreate));
  757. }
  758. return (0);
  759. }
  760. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr) {
  761. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  762. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  763. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  764. struct saCkptCheckpoint *ckptCheckpoint;
  765. struct saCkptCheckpointSection *ckptCheckpointSection;
  766. SaErrorT error = SA_OK;
  767. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectiondelete->checkpointName);
  768. if (ckptCheckpoint == 0) {
  769. error = SA_ERR_NOT_EXIST;
  770. goto error_exit;
  771. }
  772. /*
  773. * Determine if the user is trying to delete the default section
  774. */
  775. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  776. error = SA_ERR_INVALID_PARAM;
  777. goto error_exit;
  778. }
  779. /*
  780. * Find checkpoint section to be deleted
  781. */
  782. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  783. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  784. req_lib_ckpt_sectiondelete->idLen);
  785. if (ckptCheckpointSection == 0) {
  786. printf ("section not found\n");
  787. error = SA_ERR_NOT_EXIST;
  788. goto error_exit;
  789. }
  790. /*
  791. * Delete checkpoint section
  792. */
  793. checkpoint_section_release (ckptCheckpointSection);
  794. /*
  795. * return result to CKPT library
  796. */
  797. error_exit:
  798. if (req_exec_ckpt_sectiondelete->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  799. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  800. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  801. res_lib_ckpt_sectiondelete.header.error = error;
  802. libais_send_response (req_exec_ckpt_sectiondelete->source.conn_info,
  803. &res_lib_ckpt_sectiondelete,
  804. sizeof (struct res_lib_ckpt_sectiondelete));
  805. }
  806. return (0);
  807. }
  808. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr) {
  809. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  810. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  811. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  812. struct saCkptCheckpoint *ckptCheckpoint;
  813. struct saCkptCheckpointSection *ckptCheckpointSection;
  814. SaErrorT error = SA_OK;
  815. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  816. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  817. if (ckptCheckpoint == 0) {
  818. error = SA_ERR_NOT_EXIST;
  819. goto error_exit;
  820. }
  821. /*
  822. * Determine if the user is trying to set expiration time for the default section
  823. */
  824. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  825. error = SA_ERR_INVALID_PARAM;
  826. goto error_exit;
  827. }
  828. /*
  829. * Find checkpoint section that expiration time should be set for
  830. */
  831. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  832. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  833. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  834. req_lib_ckpt_sectionexpirationtimeset->idLen);
  835. if (ckptCheckpointSection == 0) {
  836. error = SA_ERR_NOT_EXIST;
  837. goto error_exit;
  838. }
  839. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  840. poll_timer_delete (*gmi_poll_handle, ckptCheckpointSection->expiration_timer);
  841. ckptCheckpointSection->expiration_timer = 0;
  842. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  843. poll_timer_add (*gmi_poll_handle,
  844. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  845. ckptCheckpointSection,
  846. timer_function_section_expire,
  847. &ckptCheckpointSection->expiration_timer);
  848. }
  849. error_exit:
  850. if (req_exec_ckpt_sectionexpirationtimeset->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  851. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  852. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  853. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  854. libais_send_response (req_exec_ckpt_sectionexpirationtimeset->source.conn_info,
  855. &res_lib_ckpt_sectionexpirationtimeset,
  856. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  857. }
  858. return (0);
  859. }
  860. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr) {
  861. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  862. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  863. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  864. struct saCkptCheckpoint *ckptCheckpoint;
  865. struct saCkptCheckpointSection *ckptCheckpointSection;
  866. int sizeRequired;
  867. void *sectionData;
  868. SaErrorT error = SA_OK;
  869. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  870. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectionwrite->checkpointName);
  871. if (ckptCheckpoint == 0) {
  872. error = SA_ERR_NOT_EXIST;
  873. goto error_exit;
  874. }
  875. //printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  876. /*
  877. * Find checkpoint section to be written
  878. */
  879. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  880. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  881. req_lib_ckpt_sectionwrite->idLen);
  882. if (ckptCheckpointSection == 0) {
  883. printf ("CANT FIND SECTION '%s'\n",
  884. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  885. error = SA_ERR_NOT_EXIST;
  886. goto error_exit;
  887. }
  888. /*
  889. * If write would extend past end of section data, enlarge section
  890. */
  891. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  892. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  893. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  894. if (sectionData == 0) {
  895. error = SA_ERR_NO_MEMORY;
  896. goto error_exit;
  897. }
  898. /*
  899. * Install new section data
  900. */
  901. ckptCheckpointSection->sectionData = sectionData;
  902. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  903. }
  904. /*
  905. * Write checkpoint section to section data
  906. */
  907. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  908. char *sd;
  909. int *val;
  910. val = ckptCheckpointSection->sectionData;
  911. sd = (char *)ckptCheckpointSection->sectionData;
  912. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  913. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  914. req_lib_ckpt_sectionwrite->idLen,
  915. req_lib_ckpt_sectionwrite->dataSize);
  916. }
  917. /*
  918. * Write write response to CKPT library
  919. */
  920. error_exit:
  921. if (req_exec_ckpt_sectionwrite->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  922. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  923. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  924. res_lib_ckpt_sectionwrite.header.error = error;
  925. libais_send_response (req_exec_ckpt_sectionwrite->source.conn_info,
  926. &res_lib_ckpt_sectionwrite,
  927. sizeof (struct res_lib_ckpt_sectionwrite));
  928. }
  929. return (0);
  930. }
  931. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr) {
  932. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  933. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  934. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  935. struct saCkptCheckpoint *ckptCheckpoint;
  936. struct saCkptCheckpointSection *ckptCheckpointSection;
  937. void *sectionData;
  938. SaErrorT error = SA_OK;
  939. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  940. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectionoverwrite->checkpointName);
  941. if (ckptCheckpoint == 0) {
  942. error = SA_ERR_NOT_EXIST;
  943. goto error_exit;
  944. }
  945. /*
  946. * Find checkpoint section to be overwritten
  947. */
  948. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  949. ((char *)req_lib_ckpt_sectionoverwrite) +
  950. sizeof (struct req_lib_ckpt_sectionoverwrite),
  951. req_lib_ckpt_sectionoverwrite->idLen);
  952. if (ckptCheckpointSection == 0) {
  953. error = SA_ERR_NOT_EXIST;
  954. goto error_exit;
  955. }
  956. /*
  957. * Allocate checkpoint section data
  958. */
  959. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  960. if (sectionData == 0) {
  961. error = SA_ERR_NO_MEMORY;
  962. goto error_exit;
  963. }
  964. memcpy (sectionData,
  965. ((char *)req_lib_ckpt_sectionoverwrite) +
  966. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  967. req_lib_ckpt_sectionoverwrite->idLen,
  968. req_lib_ckpt_sectionoverwrite->dataSize);
  969. /*
  970. * release old checkpoint section data
  971. */
  972. free (ckptCheckpointSection->sectionData);
  973. /*
  974. * Install overwritten checkpoint section data
  975. */
  976. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  977. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  978. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; // TODO current time
  979. ckptCheckpointSection->sectionData = sectionData;
  980. /*
  981. * return result to CKPT library
  982. */
  983. error_exit:
  984. if (req_exec_ckpt_sectionoverwrite->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  985. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  986. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  987. res_lib_ckpt_sectionoverwrite.header.error = error;
  988. libais_send_response (req_exec_ckpt_sectionoverwrite->source.conn_info,
  989. &res_lib_ckpt_sectionoverwrite,
  990. sizeof (struct res_lib_ckpt_sectionoverwrite));
  991. }
  992. return (0);
  993. }
  994. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr) {
  995. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  996. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  997. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  998. struct saCkptCheckpoint *ckptCheckpoint;
  999. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1000. int sectionSize = 0;
  1001. SaErrorT error = SA_OK;
  1002. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  1003. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectionread->checkpointName);
  1004. if (ckptCheckpoint == 0) {
  1005. error = SA_ERR_SYSTEM; // TODO find the right error for this
  1006. goto error_exit;
  1007. }
  1008. /*
  1009. * Find checkpoint section to be read
  1010. */
  1011. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  1012. ((char *)req_lib_ckpt_sectionread) +
  1013. sizeof (struct req_lib_ckpt_sectionread),
  1014. req_lib_ckpt_sectionread->idLen);
  1015. if (ckptCheckpointSection == 0) {
  1016. error = SA_ERR_NOT_EXIST;
  1017. goto error_exit;
  1018. }
  1019. /*
  1020. * Determine the section size
  1021. */
  1022. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  1023. req_lib_ckpt_sectionread->dataOffset;
  1024. /*
  1025. * If the library has less space available then can be sent from the
  1026. * section, reduce bytes sent to library to max requested
  1027. */
  1028. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  1029. sectionSize = req_lib_ckpt_sectionread->dataSize;
  1030. }
  1031. /*
  1032. * If dataOffset is past end of data, return INVALID PARAM
  1033. */
  1034. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  1035. sectionSize = 0;
  1036. error = SA_ERR_INVALID_PARAM;
  1037. goto error_exit;
  1038. }
  1039. /*
  1040. * Write read response to CKPT library
  1041. */
  1042. error_exit:
  1043. if (req_exec_ckpt_sectionread->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1044. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  1045. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  1046. res_lib_ckpt_sectionread.header.error = error;
  1047. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1048. &res_lib_ckpt_sectionread,
  1049. sizeof (struct res_lib_ckpt_sectionread));
  1050. /*
  1051. * Write checkpoint to CKPT library section if section has data
  1052. */
  1053. if (sectionSize) {
  1054. char *sd;
  1055. sd = (char *)ckptCheckpointSection->sectionData;
  1056. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1057. &sd[req_lib_ckpt_sectionread->dataOffset],
  1058. sectionSize);
  1059. }
  1060. }
  1061. return (0);
  1062. }
  1063. static int message_handler_req_lib_ckpt_init (struct conn_info *conn_info, void *message)
  1064. {
  1065. struct res_lib_init res_lib_init;
  1066. SaErrorT error = SA_ERR_SECURITY;
  1067. log_printf (LOG_LEVEL_DEBUG, "Got request to initialize CKPT.\n");
  1068. if (conn_info->authenticated) {
  1069. conn_info->service = SOCKET_SERVICE_CKPT;
  1070. error = SA_OK;
  1071. }
  1072. res_lib_init.header.size = sizeof (struct res_lib_init);
  1073. res_lib_init.header.id = MESSAGE_RES_INIT;
  1074. res_lib_init.header.error = error;
  1075. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1076. if (conn_info->authenticated) {
  1077. return (0);
  1078. }
  1079. return (-1);
  1080. }
  1081. static int message_handler_req_lib_ckpt_checkpoint_init (struct conn_info *conn_info, void *message)
  1082. {
  1083. struct res_lib_init res_lib_init;
  1084. SaErrorT error = SA_ERR_SECURITY;
  1085. log_printf (LOG_LEVEL_DEBUG, "Got request to initialize CKPT checkpoint.\n");
  1086. if (conn_info->authenticated) {
  1087. conn_info->service = SOCKET_SERVICE_CKPT_CHECKPOINT;
  1088. conn_info->ais_ci.u.libckpt_ci.checkpoint = 0;
  1089. conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags = 0;
  1090. error = SA_OK;
  1091. }
  1092. res_lib_init.header.size = sizeof (struct res_lib_init);
  1093. res_lib_init.header.id = MESSAGE_RES_INIT;
  1094. res_lib_init.header.error = error;
  1095. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1096. if (conn_info->authenticated) {
  1097. return (0);
  1098. }
  1099. return (-1);
  1100. }
  1101. static int message_handler_req_lib_ckpt_sectioniterator_init (struct conn_info *conn_info, void *message)
  1102. {
  1103. struct res_lib_init res_lib_init;
  1104. SaErrorT error = SA_ERR_SECURITY;
  1105. log_printf (LOG_LEVEL_DEBUG, "Got request to initialize CKPT section iterator.\n");
  1106. if (conn_info->authenticated) {
  1107. conn_info->service = SOCKET_SERVICE_CKPT_SECTIONITERATOR;
  1108. list_init (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list);
  1109. conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  1110. conn_info->ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  1111. conn_info->ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  1112. list_add (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list,
  1113. &checkpointIteratorListHead);
  1114. error = SA_OK;
  1115. }
  1116. res_lib_init.header.size = sizeof (struct res_lib_init);
  1117. res_lib_init.header.id = MESSAGE_RES_INIT;
  1118. res_lib_init.header.error = error;
  1119. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1120. if (conn_info->authenticated) {
  1121. return (0);
  1122. }
  1123. return (-1);
  1124. }
  1125. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message)
  1126. {
  1127. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)message;
  1128. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  1129. struct iovec iovecs[2];
  1130. int result;
  1131. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  1132. req_exec_ckpt_checkpointopen.header.size =
  1133. sizeof (struct req_exec_ckpt_checkpointopen);
  1134. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  1135. req_exec_ckpt_checkpointopen.source.conn_info = conn_info;
  1136. req_exec_ckpt_checkpointopen.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1137. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  1138. req_lib_ckpt_checkpointopen,
  1139. sizeof (struct req_lib_ckpt_checkpointopen));
  1140. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  1141. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  1142. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1143. return (0);
  1144. }
  1145. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  1146. {
  1147. return (0);
  1148. }
  1149. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  1150. {
  1151. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  1152. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1153. struct iovec iovecs[2];
  1154. int result;
  1155. req_exec_ckpt_checkpointunlink.header.size =
  1156. sizeof (struct req_exec_ckpt_checkpointunlink);
  1157. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1158. req_exec_ckpt_checkpointunlink.source.conn_info = conn_info;
  1159. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1160. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  1161. req_lib_ckpt_checkpointunlink,
  1162. sizeof (struct req_lib_ckpt_checkpointunlink));
  1163. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1164. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1165. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1166. return (0);
  1167. }
  1168. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  1169. {
  1170. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  1171. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  1172. struct iovec iovecs[2];
  1173. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info);
  1174. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  1175. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  1176. req_exec_ckpt_checkpointretentiondurationset.source.conn_info = conn_info;
  1177. req_exec_ckpt_checkpointretentiondurationset.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1178. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  1179. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1180. sizeof (SaNameT));
  1181. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  1182. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  1183. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  1184. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_LOW);
  1185. return (0);
  1186. }
  1187. static int message_handler_req_lib_ckpt_activecheckpointset (struct conn_info *conn_info, void *message)
  1188. {
  1189. return (0);
  1190. }
  1191. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  1192. {
  1193. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  1194. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  1195. struct saCkptCheckpoint *checkpoint;
  1196. int memoryUsed = 0;
  1197. int numberOfSections = 0;
  1198. struct list_head *checkpointSectionList;
  1199. struct saCkptCheckpointSection *checkpointSection;
  1200. req_lib_ckpt_checkpointstatusget = 0; /* The request info isn't used */
  1201. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  1202. /*
  1203. * Count memory used by checkpoint sections
  1204. */
  1205. checkpoint = conn_info->ais_ci.u.libckpt_ci.checkpoint;
  1206. for (checkpointSectionList = checkpoint->checkpointSectionsListHead.next;
  1207. checkpointSectionList != &checkpoint->checkpointSectionsListHead;
  1208. checkpointSectionList = checkpointSectionList->next) {
  1209. checkpointSection = list_entry (checkpointSectionList,
  1210. struct saCkptCheckpointSection, list);
  1211. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  1212. numberOfSections += 1;
  1213. }
  1214. /*
  1215. * Build checkpoint status get response
  1216. */
  1217. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  1218. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  1219. res_lib_ckpt_checkpointstatusget.header.error = SA_OK;
  1220. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointStatus.checkpointCreationAttributes,
  1221. &checkpoint->checkpointCreationAttributes,
  1222. sizeof (SaCkptCheckpointCreationAttributesT));
  1223. res_lib_ckpt_checkpointstatusget.checkpointStatus.numberOfSections = numberOfSections;
  1224. res_lib_ckpt_checkpointstatusget.checkpointStatus.memoryUsed = memoryUsed;
  1225. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  1226. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  1227. sizeof (struct res_lib_ckpt_checkpointstatusget));
  1228. return (0);
  1229. }
  1230. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  1231. {
  1232. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  1233. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  1234. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  1235. struct iovec iovecs[2];
  1236. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info);
  1237. /*
  1238. * Determine if checkpoint is opened in write mode If not, send error to api
  1239. */
  1240. if ((conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1241. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  1242. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  1243. res_lib_ckpt_sectioncreate.header.error = SA_ERR_ACCESS;
  1244. libais_send_response (conn_info, &res_lib_ckpt_sectioncreate,
  1245. sizeof (struct res_lib_ckpt_sectioncreate));
  1246. return (0);
  1247. }
  1248. /*
  1249. * checkpoint opened is writeable mode so send message to cluster
  1250. */
  1251. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  1252. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  1253. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  1254. req_lib_ckpt_sectioncreate,
  1255. sizeof (struct req_lib_ckpt_sectioncreate));
  1256. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  1257. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1258. sizeof (SaNameT));
  1259. req_exec_ckpt_sectioncreate.source.conn_info = conn_info;
  1260. req_exec_ckpt_sectioncreate.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1261. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  1262. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  1263. /*
  1264. * Send section name and initial data in message
  1265. */
  1266. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  1267. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  1268. #ifdef DEBUG
  1269. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  1270. iovecs[1].iov_len);
  1271. printf ("|\n");
  1272. { int i;
  1273. char *abc = iovecs[1].iov_base;
  1274. for (i = 0; i < 14;i++) {
  1275. printf ("%c ", abc[i]);
  1276. }
  1277. }
  1278. printf ("|\n");
  1279. #endif
  1280. if (iovecs[1].iov_len > 0) {
  1281. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %s\n", iovecs[1].iov_base);
  1282. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_MED);
  1283. } else {
  1284. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1285. }
  1286. return (0);
  1287. }
  1288. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  1289. {
  1290. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  1291. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  1292. struct iovec iovecs[2];
  1293. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info);
  1294. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  1295. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  1296. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  1297. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1298. sizeof (SaNameT));
  1299. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  1300. req_lib_ckpt_sectiondelete,
  1301. sizeof (struct req_lib_ckpt_sectiondelete));
  1302. req_exec_ckpt_sectiondelete.source.conn_info = conn_info;
  1303. req_exec_ckpt_sectiondelete.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1304. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  1305. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  1306. /*
  1307. * Send section name
  1308. */
  1309. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  1310. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  1311. if (iovecs[1].iov_len > 0) {
  1312. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_MED);
  1313. } else {
  1314. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1315. }
  1316. return (0);
  1317. }
  1318. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  1319. {
  1320. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  1321. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  1322. struct iovec iovecs[2];
  1323. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info);
  1324. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  1325. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  1326. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  1327. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1328. sizeof (SaNameT));
  1329. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  1330. req_lib_ckpt_sectionexpirationtimeset,
  1331. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  1332. req_exec_ckpt_sectionexpirationtimeset.source.conn_info = conn_info;
  1333. req_exec_ckpt_sectionexpirationtimeset.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1334. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  1335. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  1336. /*
  1337. * Send section name
  1338. */
  1339. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  1340. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  1341. if (iovecs[1].iov_len > 0) {
  1342. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %s\n", iovecs[1].iov_base);
  1343. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_LOW);
  1344. } else {
  1345. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_LOW);
  1346. }
  1347. return (0);
  1348. }
  1349. int write_inv = 0;
  1350. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  1351. {
  1352. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  1353. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  1354. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1355. struct iovec iovecs[2];
  1356. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info);
  1357. // UNDO printf ("section write %d\n", write_inv++);
  1358. /*
  1359. * Determine if checkpoint is opened in write mode If not, send error to api
  1360. */
  1361. if ((conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1362. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  1363. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  1364. res_lib_ckpt_sectionwrite.header.error = SA_ERR_ACCESS;
  1365. libais_send_response (conn_info, &res_lib_ckpt_sectionwrite,
  1366. sizeof (struct res_lib_ckpt_sectionwrite));
  1367. return (0);
  1368. }
  1369. /*
  1370. * checkpoint opened is writeable mode so send message to cluster
  1371. */
  1372. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  1373. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  1374. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  1375. req_lib_ckpt_sectionwrite,
  1376. sizeof (struct req_lib_ckpt_sectionwrite));
  1377. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  1378. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1379. sizeof (SaNameT));
  1380. req_exec_ckpt_sectionwrite.source.conn_info = conn_info;
  1381. req_exec_ckpt_sectionwrite.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1382. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  1383. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  1384. /*
  1385. * Send section name and data to write in message
  1386. */
  1387. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  1388. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  1389. //printf ("LIB writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1390. if (iovecs[1].iov_len > 0) {
  1391. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_LOW);
  1392. } else {
  1393. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_LOW);
  1394. }
  1395. return (0);
  1396. }
  1397. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  1398. {
  1399. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  1400. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  1401. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1402. struct iovec iovecs[2];
  1403. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info);
  1404. /*
  1405. * Determine if checkpoint is opened in write mode If not, send error to api
  1406. */
  1407. if ((conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1408. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  1409. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1410. res_lib_ckpt_sectionoverwrite.header.error = SA_ERR_ACCESS;
  1411. libais_send_response (conn_info, &res_lib_ckpt_sectionoverwrite,
  1412. sizeof (struct res_lib_ckpt_sectionoverwrite));
  1413. return (0);
  1414. }
  1415. /*
  1416. * checkpoint opened is writeable mode so send message to cluster
  1417. */
  1418. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  1419. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  1420. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  1421. req_lib_ckpt_sectionoverwrite,
  1422. sizeof (struct req_lib_ckpt_sectionoverwrite));
  1423. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  1424. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1425. sizeof (SaNameT));
  1426. req_exec_ckpt_sectionoverwrite.source.conn_info = conn_info;
  1427. req_exec_ckpt_sectionoverwrite.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1428. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  1429. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  1430. /*
  1431. * Send section name and data to overwrite in message
  1432. */
  1433. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  1434. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  1435. if (iovecs[1].iov_len > 0) {
  1436. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_LOW);
  1437. } else {
  1438. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_LOW);
  1439. }
  1440. return (0);
  1441. }
  1442. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  1443. {
  1444. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  1445. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  1446. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1447. struct iovec iovecs[2];
  1448. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info);
  1449. /*
  1450. * Determine if checkpoint is opened in write mode If not, send error to api
  1451. */
  1452. if ((conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_READ) == 0) {
  1453. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread);
  1454. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  1455. res_lib_ckpt_sectionread.header.error = SA_ERR_ACCESS;
  1456. libais_send_response (conn_info, &res_lib_ckpt_sectionread,
  1457. sizeof (struct res_lib_ckpt_sectionread));
  1458. return (0);
  1459. }
  1460. /*
  1461. * checkpoint opened is writeable mode so send message to cluster
  1462. */
  1463. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  1464. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  1465. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  1466. req_lib_ckpt_sectionread,
  1467. sizeof (struct req_lib_ckpt_sectionread));
  1468. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  1469. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1470. sizeof (SaNameT));
  1471. req_exec_ckpt_sectionread.source.conn_info = conn_info;
  1472. req_exec_ckpt_sectionread.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1473. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  1474. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  1475. /*
  1476. * Send section name and data to overwrite in message
  1477. */
  1478. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  1479. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  1480. if (iovecs[1].iov_len > 0) {
  1481. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_LOW);
  1482. } else {
  1483. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_LOW);
  1484. }
  1485. return (0);
  1486. }
  1487. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  1488. {
  1489. return (0);
  1490. }
  1491. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  1492. {
  1493. return (0);
  1494. }
  1495. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message)
  1496. {
  1497. struct req_lib_ckpt_sectioniteratorinitialize *req_lib_ckpt_sectioniteratorinitialize = (struct req_lib_ckpt_sectioniteratorinitialize *)message;
  1498. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  1499. struct saCkptCheckpoint *ckptCheckpoint;
  1500. struct saCkptCheckpointSection *ckptCheckpointSection;
  1501. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  1502. struct saCkptSectionIterator *ckptSectionIterator;
  1503. struct list_head *checkpointSectionList;
  1504. int addEntry = 0;
  1505. int iteratorEntries = 0;
  1506. SaErrorT error = SA_OK;
  1507. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  1508. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  1509. ckptCheckpoint = findCheckpoint (&req_lib_ckpt_sectioniteratorinitialize->checkpointName);
  1510. if (ckptCheckpoint == 0) {
  1511. error = SA_ERR_NOT_EXIST;
  1512. goto error_exit;
  1513. }
  1514. /*
  1515. * Iterate list of checkpoint sections
  1516. */
  1517. for (checkpointSectionList = ckptCheckpoint->checkpointSectionsListHead.next;
  1518. checkpointSectionList != &ckptCheckpoint->checkpointSectionsListHead;
  1519. checkpointSectionList = checkpointSectionList->next) {
  1520. ckptCheckpointSection = list_entry (checkpointSectionList,
  1521. struct saCkptCheckpointSection, list);
  1522. addEntry = 1;
  1523. /*
  1524. * Item should be added to iterator list
  1525. */
  1526. if (addEntry) {
  1527. iteratorEntries += 1;
  1528. ckptSectionIteratorEntries =
  1529. realloc (ckptSectionIterator->sectionIteratorEntries,
  1530. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  1531. if (ckptSectionIteratorEntries == 0) {
  1532. if (ckptSectionIterator->sectionIteratorEntries) {
  1533. free (ckptSectionIterator->sectionIteratorEntries);
  1534. }
  1535. error = SA_ERR_NO_MEMORY;
  1536. goto error_exit;
  1537. }
  1538. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  1539. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  1540. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  1541. }
  1542. }
  1543. ckptSectionIterator->iteratorCount = iteratorEntries;
  1544. error_exit:
  1545. res_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize);
  1546. res_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  1547. res_lib_ckpt_sectioniteratorinitialize.header.error = error;
  1548. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratorinitialize,
  1549. sizeof (struct res_lib_ckpt_sectioniteratorinitialize));
  1550. return (0);
  1551. }
  1552. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  1553. {
  1554. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  1555. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  1556. struct saCkptSectionIterator *ckptSectionIterator;
  1557. SaErrorT error = SA_OK;
  1558. int sectionIdSize = 0;
  1559. int iteratorPos = 0;
  1560. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  1561. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  1562. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  1563. /*
  1564. * Find active iterator entry
  1565. */
  1566. for (;;) {
  1567. /*
  1568. * No more sections in iterator
  1569. */
  1570. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  1571. error = SA_ERR_NOT_EXIST;
  1572. goto error_exit;
  1573. }
  1574. /*
  1575. * active iterator entry
  1576. */
  1577. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  1578. break;
  1579. }
  1580. ckptSectionIterator->iteratorPos += 1;
  1581. }
  1582. /*
  1583. * Prepare response to API
  1584. */
  1585. iteratorPos = ckptSectionIterator->iteratorPos;
  1586. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  1587. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  1588. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  1589. sizeof (SaCkptSectionDescriptorT));
  1590. /*
  1591. * Get to next iterator entry
  1592. */
  1593. ckptSectionIterator->iteratorPos += 1;
  1594. error_exit:
  1595. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  1596. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  1597. res_lib_ckpt_sectioniteratornext.header.error = error;
  1598. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  1599. sizeof (struct res_lib_ckpt_sectioniteratornext));
  1600. libais_send_response (conn_info,
  1601. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  1602. sectionIdSize);
  1603. return (0);
  1604. }