ckpt.c 62 KB

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