ckpt.c 62 KB

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