ckpt.c 64 KB

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