ckpt.c 60 KB

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