ckpt.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  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_lib_activatepoll (int fd, void *message);
  63. static int message_handler_req_exec_ckpt_checkpointopen (void *message);
  64. static int message_handler_req_exec_ckpt_checkpointclose (void *message);
  65. static int message_handler_req_exec_ckpt_checkpointunlink (void *message);
  66. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message);
  67. static int message_handler_req_exec_ckpt_sectioncreate (void *message);
  68. static int message_handler_req_exec_ckpt_sectiondelete (void *message);
  69. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message);
  70. static int message_handler_req_exec_ckpt_sectionwrite (void *message);
  71. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message);
  72. static int message_handler_req_exec_ckpt_sectionread (void *message);
  73. static int message_handler_req_lib_ckpt_init (int fd, void *message);
  74. static int message_handler_req_lib_ckpt_checkpoint_init (int fd, void *message);
  75. static int message_handler_req_lib_ckpt_sectioniterator_init (int fd, void *message);
  76. static int message_handler_req_lib_ckpt_checkpointopen (int fd, void *message);
  77. static int message_handler_req_lib_ckpt_checkpointopenasync (int fd, void *message);
  78. static int message_handler_req_lib_ckpt_checkpointunlink (int fd, void *message);
  79. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (int fd, void *message);
  80. static int message_handler_req_lib_ckpt_activecheckpointset (int fd, void *message);
  81. static int message_handler_req_lib_ckpt_checkpointstatusget (int fd, void *message);
  82. static int message_handler_req_lib_ckpt_sectioncreate (int fd, void *message);
  83. static int message_handler_req_lib_ckpt_sectiondelete (int fd, void *message);
  84. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (int fd, void *message);
  85. static int message_handler_req_lib_ckpt_sectionwrite (int fd, void *message);
  86. static int message_handler_req_lib_ckpt_sectionoverwrite (int fd, void *message);
  87. static int message_handler_req_lib_ckpt_sectionread (int fd, void *message);
  88. static int message_handler_req_lib_ckpt_checkpointsynchronize (int fd, void *message);
  89. static int message_handler_req_lib_ckpt_checkpointsyncronizeasync (int fd, void *message);
  90. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (int fd, void *message);
  91. static int message_handler_req_lib_ckpt_sectioniteratornext (int fd, void *message);
  92. static int ckptConfChg (
  93. struct sockaddr_in *member_list, int member_list_entries,
  94. struct sockaddr_in *left_list, int left_list_entries,
  95. struct sockaddr_in *joined_list, int joined_list_entries) {
  96. return (0);
  97. }
  98. int (*ckpt_libais_handler_fns[]) (int fd, void *) = {
  99. message_handler_req_lib_activatepoll
  100. };
  101. /*
  102. * TODO
  103. */
  104. int (*ckpt_aisexec_handler_fns[]) (void *) = {
  105. };
  106. /*
  107. * exported service
  108. */
  109. struct service_handler ckpt_service_handler = {
  110. libais_handler_fns: ckpt_libais_handler_fns,
  111. libais_handler_fns_count: sizeof (ckpt_libais_handler_fns) / sizeof (int (*)),
  112. aisexec_handler_fns: ckpt_aisexec_handler_fns ,
  113. aisexec_handler_fns_count: sizeof (ckpt_aisexec_handler_fns) / sizeof (int (*)),
  114. confchg_fn: 0, /* ckpt service handler is not distributed */
  115. libais_init_fn: message_handler_req_lib_ckpt_init,
  116. libais_exit_fn: 0,
  117. aisexec_init_fn: 0
  118. };
  119. static int (*ckpt_checkpoint_libais_handler_fns[]) (int fd, void *) = {
  120. message_handler_req_lib_activatepoll,
  121. message_handler_req_lib_ckpt_checkpointopen,
  122. message_handler_req_lib_ckpt_checkpointopenasync,
  123. message_handler_req_lib_ckpt_checkpointunlink,
  124. message_handler_req_lib_ckpt_checkpointretentiondurationset,
  125. message_handler_req_lib_ckpt_activecheckpointset,
  126. message_handler_req_lib_ckpt_checkpointstatusget,
  127. message_handler_req_lib_ckpt_sectioncreate,
  128. message_handler_req_lib_ckpt_sectiondelete,
  129. message_handler_req_lib_ckpt_sectionexpirationtimeset,
  130. message_handler_req_lib_ckpt_sectionwrite,
  131. message_handler_req_lib_ckpt_sectionoverwrite,
  132. message_handler_req_lib_ckpt_sectionread,
  133. message_handler_req_lib_ckpt_checkpointsynchronize,
  134. message_handler_req_lib_ckpt_checkpointsyncronizeasync
  135. };
  136. static int (*ckpt_checkpoint_aisexec_handler_fns[]) (void *msg) = {
  137. message_handler_req_exec_ckpt_checkpointopen,
  138. message_handler_req_exec_ckpt_checkpointclose,
  139. message_handler_req_exec_ckpt_checkpointunlink,
  140. message_handler_req_exec_ckpt_checkpointretentiondurationset,
  141. message_handler_req_exec_ckpt_sectioncreate,
  142. message_handler_req_exec_ckpt_sectiondelete,
  143. message_handler_req_exec_ckpt_sectionexpirationtimeset,
  144. message_handler_req_exec_ckpt_sectionwrite,
  145. message_handler_req_exec_ckpt_sectionoverwrite,
  146. message_handler_req_exec_ckpt_sectionread
  147. };
  148. struct service_handler ckpt_checkpoint_service_handler = {
  149. libais_handler_fns: ckpt_checkpoint_libais_handler_fns,
  150. libais_handler_fns_count: sizeof (ckpt_checkpoint_libais_handler_fns) / sizeof (int (*)),
  151. aisexec_handler_fns: ckpt_checkpoint_aisexec_handler_fns ,
  152. aisexec_handler_fns_count: sizeof (ckpt_checkpoint_aisexec_handler_fns) / sizeof (int (*)),
  153. confchg_fn: ckptConfChg,
  154. libais_init_fn: message_handler_req_lib_ckpt_checkpoint_init,
  155. libais_exit_fn: ckptCheckpointApiFinalize,
  156. aisexec_init_fn: 0
  157. };
  158. static int (*ckpt_sectioniterator_libais_handler_fns[]) (int fd, void *) = {
  159. message_handler_req_lib_activatepoll,
  160. message_handler_req_lib_ckpt_sectioniteratorinitialize,
  161. message_handler_req_lib_ckpt_sectioniteratornext
  162. };
  163. static int (*ckpt_sectioniterator_aisexec_handler_fns[]) (void *msg) = {
  164. };
  165. struct service_handler ckpt_sectioniterator_service_handler = {
  166. libais_handler_fns: ckpt_sectioniterator_libais_handler_fns,
  167. libais_handler_fns_count: sizeof (ckpt_sectioniterator_libais_handler_fns) / sizeof (int (*)),
  168. aisexec_handler_fns: ckpt_sectioniterator_aisexec_handler_fns ,
  169. aisexec_handler_fns_count: sizeof (ckpt_sectioniterator_aisexec_handler_fns) / sizeof (int (*)),
  170. confchg_fn: 0, /* Section Iterators are not distributed */
  171. libais_init_fn: message_handler_req_lib_ckpt_sectioniterator_init,
  172. libais_exit_fn: ckptSectionIteratorApiFinalize,
  173. aisexec_init_fn: 0
  174. };
  175. static struct saCkptCheckpoint *findCheckpoint (SaNameT *name)
  176. {
  177. struct list_head *checkpointList;
  178. struct saCkptCheckpoint *checkpoint;
  179. for (checkpointList = checkpointListHead.next;
  180. checkpointList != &checkpointListHead;
  181. checkpointList = checkpointList->next) {
  182. checkpoint = list_entry (checkpointList,
  183. struct saCkptCheckpoint, list);
  184. if (SaNameTisNameT (name, &checkpoint->name)) {
  185. return (checkpoint);
  186. }
  187. }
  188. return (0);
  189. }
  190. static struct saCkptCheckpointSection *findCheckpointSection (
  191. struct saCkptCheckpoint *ckptCheckpoint,
  192. char *id,
  193. int idLen)
  194. {
  195. struct list_head *checkpointSectionList;
  196. struct saCkptCheckpointSection *ckptCheckpointSection;
  197. log_printf (LOG_LEVEL_DEBUG, "Finding checkpoint section id %s %d\n", id, idLen);
  198. for (checkpointSectionList = ckptCheckpoint->checkpointSectionsListHead.next;
  199. checkpointSectionList != &ckptCheckpoint->checkpointSectionsListHead;
  200. checkpointSectionList = checkpointSectionList->next) {
  201. ckptCheckpointSection = list_entry (checkpointSectionList,
  202. struct saCkptCheckpointSection, list);
  203. log_printf (LOG_LEVEL_DEBUG, "Checking section id %s %d\n",
  204. ckptCheckpointSection->sectionDescriptor.sectionId.id,
  205. ckptCheckpointSection->sectionDescriptor.sectionId.idLen);
  206. if (ckptCheckpointSection->sectionDescriptor.sectionId.idLen == idLen &&
  207. (memcmp (ckptCheckpointSection->sectionDescriptor.sectionId.id,
  208. id, idLen) == 0)) {
  209. return (ckptCheckpointSection);
  210. }
  211. }
  212. return 0;
  213. }
  214. void sendCkptCheckpointClose (struct saCkptCheckpoint *checkpoint) {
  215. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  216. struct iovec iovecs[2];
  217. int result;
  218. req_exec_ckpt_checkpointclose.header.magic = MESSAGE_MAGIC;
  219. req_exec_ckpt_checkpointclose.header.size =
  220. sizeof (struct req_exec_ckpt_checkpointclose);
  221. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  222. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  223. &checkpoint->name,
  224. sizeof (SaNameT));
  225. iovecs[0].iov_base = &req_exec_ckpt_checkpointclose;
  226. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  227. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  228. }
  229. static int ckptCheckpointApiFinalize (int fd)
  230. {
  231. /*
  232. * close checkpoint opened from this fd
  233. */
  234. if (connections[fd].service == SOCKET_SERVICE_CKPT_CHECKPOINT &&
  235. connections[fd].ais_ci.u.libckpt_ci.checkpoint) {
  236. log_printf (LOG_LEVEL_DEBUG, "APIFinalize fd is %d %s\n", fd, getSaNameT (&connections[fd].ais_ci.u.libckpt_ci.checkpoint->name));
  237. sendCkptCheckpointClose (connections[fd].ais_ci.u.libckpt_ci.checkpoint);
  238. }
  239. return (0);
  240. }
  241. static int ckptSectionIteratorApiFinalize (int fd) {
  242. /*
  243. * If section iterator connection, unlink from list and free section iterator data
  244. */
  245. if (connections[fd].service == SOCKET_SERVICE_CKPT_SECTIONITERATOR) {
  246. log_printf (LOG_LEVEL_DEBUG, "freeing section iterator\n");
  247. if (connections[fd].ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries) {
  248. free (connections[fd].ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries);
  249. }
  250. list_del (&connections[fd].ais_ci.u.libckpt_ci.sectionIterator.list);
  251. }
  252. return (0);
  253. }
  254. static int message_handler_req_lib_activatepoll (int fd, 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 (fd, &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. connections[req_exec_ckpt_checkpointopen->source.fd].ais_ci.u.libckpt_ci.checkpoint = ckptCheckpoint;
  338. connections[req_exec_ckpt_checkpointopen->source.fd].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.fd, &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.fd, &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.fd,
  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.fd,
  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.fd,
  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.fd,
  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.fd,
  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.fd,
  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.fd,
  815. &sd[req_lib_ckpt_sectionread->dataOffset],
  816. sectionSize);
  817. }
  818. }
  819. return (0);
  820. }
  821. static int message_handler_req_lib_ckpt_init (int fd, 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 (connections[fd].authenticated) {
  827. connections[fd].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 (fd, &res_lib_init, sizeof (res_lib_init));
  835. if (connections[fd].authenticated) {
  836. return (0);
  837. }
  838. return (-1);
  839. }
  840. static int message_handler_req_lib_ckpt_checkpoint_init (int fd, 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 (connections[fd].authenticated) {
  846. connections[fd].service = SOCKET_SERVICE_CKPT_CHECKPOINT;
  847. connections[fd].ais_ci.u.libckpt_ci.checkpoint = 0;
  848. connections[fd].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 (fd, &res_lib_init, sizeof (res_lib_init));
  856. if (connections[fd].authenticated) {
  857. return (0);
  858. }
  859. return (-1);
  860. }
  861. static int message_handler_req_lib_ckpt_sectioniterator_init (int fd, 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 (connections[fd].authenticated) {
  867. connections[fd].service = SOCKET_SERVICE_CKPT_SECTIONITERATOR;
  868. list_init (&connections[fd].ais_ci.u.libckpt_ci.sectionIterator.list);
  869. connections[fd].ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  870. connections[fd].ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  871. connections[fd].ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  872. list_add (&connections[fd].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 (fd, &res_lib_init, sizeof (res_lib_init));
  881. if (connections[fd].authenticated) {
  882. return (0);
  883. }
  884. return (-1);
  885. }
  886. static int message_handler_req_lib_ckpt_checkpointopen (int fd, 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.fd = fd;
  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 (int fd, void *message)
  908. {
  909. return (0);
  910. }
  911. static int message_handler_req_lib_ckpt_checkpointunlink (int fd, 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.fd = fd;
  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 (int fd, 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", fd);
  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. &connections[fd].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 (int fd, void *message)
  950. {
  951. return (0);
  952. }
  953. static int message_handler_req_lib_ckpt_checkpointstatusget (int fd, 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 = connections[fd].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 (fd, &res_lib_ckpt_checkpointstatusget,
  989. sizeof (struct res_lib_ckpt_checkpointstatusget));
  990. return (0);
  991. }
  992. static int message_handler_req_lib_ckpt_sectioncreate (int fd, 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", fd);
  999. /*
  1000. * Determine if checkpoint is opened in write mode If not, send error to api
  1001. */
  1002. if ((connections[fd].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 (fd, &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. &connections[fd].ais_ci.u.libckpt_ci.checkpoint->name,
  1022. sizeof (SaNameT));
  1023. req_exec_ckpt_sectioncreate.source.fd = fd;
  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", iovecs[1].iov_base, iovecs[1].iov_len);
  1034. printf ("|\n");
  1035. { int i;
  1036. char *suck = iovecs[1].iov_base;
  1037. for (i = 0; i < 14;i++) {
  1038. printf ("%c ", suck[i]);
  1039. }
  1040. }
  1041. printf ("|\n");
  1042. #endif
  1043. if (iovecs[1].iov_len > 0) {
  1044. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %s\n", iovecs[1].iov_base);
  1045. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_MED);
  1046. } else {
  1047. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1048. }
  1049. return (0);
  1050. }
  1051. static int message_handler_req_lib_ckpt_sectiondelete (int fd, void *message)
  1052. {
  1053. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  1054. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  1055. struct iovec iovecs[2];
  1056. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", fd);
  1057. req_exec_ckpt_sectiondelete.header.magic = MESSAGE_MAGIC;
  1058. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  1059. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  1060. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  1061. &connections[fd].ais_ci.u.libckpt_ci.checkpoint->name,
  1062. sizeof (SaNameT));
  1063. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  1064. req_lib_ckpt_sectiondelete,
  1065. sizeof (struct req_lib_ckpt_sectiondelete));
  1066. req_exec_ckpt_sectiondelete.source.fd = fd;
  1067. req_exec_ckpt_sectiondelete.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1068. iovecs[0].iov_base = &req_exec_ckpt_sectiondelete;
  1069. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  1070. /*
  1071. * Send section name
  1072. */
  1073. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  1074. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  1075. if (iovecs[1].iov_len > 0) {
  1076. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %s\n", iovecs[1].iov_base);
  1077. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_MED);
  1078. } else {
  1079. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1080. }
  1081. return (0);
  1082. }
  1083. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (int fd, void *message)
  1084. {
  1085. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  1086. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  1087. struct iovec iovecs[2];
  1088. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", fd);
  1089. req_exec_ckpt_sectionexpirationtimeset.header.magic = MESSAGE_MAGIC;
  1090. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  1091. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  1092. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  1093. &connections[fd].ais_ci.u.libckpt_ci.checkpoint->name,
  1094. sizeof (SaNameT));
  1095. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  1096. req_lib_ckpt_sectionexpirationtimeset,
  1097. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  1098. req_exec_ckpt_sectionexpirationtimeset.source.fd = fd;
  1099. req_exec_ckpt_sectionexpirationtimeset.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1100. iovecs[0].iov_base = &req_exec_ckpt_sectionexpirationtimeset;
  1101. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  1102. /*
  1103. * Send section name
  1104. */
  1105. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  1106. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  1107. if (iovecs[1].iov_len > 0) {
  1108. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %s\n", iovecs[1].iov_base);
  1109. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_MED);
  1110. } else {
  1111. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1112. }
  1113. return (0);
  1114. }
  1115. int write_inv = 0;
  1116. static int message_handler_req_lib_ckpt_sectionwrite (int fd, void *message)
  1117. {
  1118. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  1119. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  1120. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1121. struct iovec iovecs[2];
  1122. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", fd);
  1123. // UNDO printf ("section write %d\n", write_inv++);
  1124. /*
  1125. * Determine if checkpoint is opened in write mode If not, send error to api
  1126. */
  1127. if ((connections[fd].ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1128. res_lib_ckpt_sectionwrite.header.magic = MESSAGE_MAGIC;
  1129. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  1130. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  1131. res_lib_ckpt_sectionwrite.error = SA_ERR_ACCESS;
  1132. libais_send_response (fd, &res_lib_ckpt_sectionwrite,
  1133. sizeof (struct res_lib_ckpt_sectionwrite));
  1134. return (0);
  1135. }
  1136. /*
  1137. * checkpoint opened is writeable mode so send message to cluster
  1138. */
  1139. req_exec_ckpt_sectionwrite.header.magic = MESSAGE_MAGIC;
  1140. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  1141. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  1142. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  1143. req_lib_ckpt_sectionwrite,
  1144. sizeof (struct req_lib_ckpt_sectionwrite));
  1145. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  1146. &connections[fd].ais_ci.u.libckpt_ci.checkpoint->name,
  1147. sizeof (SaNameT));
  1148. req_exec_ckpt_sectionwrite.source.fd = fd;
  1149. req_exec_ckpt_sectionwrite.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1150. iovecs[0].iov_base = &req_exec_ckpt_sectionwrite;
  1151. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  1152. /*
  1153. * Send section name and data to write in message
  1154. */
  1155. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  1156. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  1157. //printf ("LIB writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1158. if (iovecs[1].iov_len > 0) {
  1159. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_MED);
  1160. } else {
  1161. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1162. }
  1163. return (0);
  1164. }
  1165. static int message_handler_req_lib_ckpt_sectionoverwrite (int fd, void *message)
  1166. {
  1167. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  1168. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  1169. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1170. struct iovec iovecs[2];
  1171. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", fd);
  1172. /*
  1173. * Determine if checkpoint is opened in write mode If not, send error to api
  1174. */
  1175. if ((connections[fd].ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1176. res_lib_ckpt_sectionoverwrite.header.magic = MESSAGE_MAGIC;
  1177. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  1178. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1179. res_lib_ckpt_sectionoverwrite.error = SA_ERR_ACCESS;
  1180. libais_send_response (fd, &res_lib_ckpt_sectionoverwrite,
  1181. sizeof (struct res_lib_ckpt_sectionoverwrite));
  1182. return (0);
  1183. }
  1184. /*
  1185. * checkpoint opened is writeable mode so send message to cluster
  1186. */
  1187. req_exec_ckpt_sectionoverwrite.header.magic = MESSAGE_MAGIC;
  1188. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  1189. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  1190. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  1191. req_lib_ckpt_sectionoverwrite,
  1192. sizeof (struct req_lib_ckpt_sectionoverwrite));
  1193. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  1194. &connections[fd].ais_ci.u.libckpt_ci.checkpoint->name,
  1195. sizeof (SaNameT));
  1196. req_exec_ckpt_sectionoverwrite.source.fd = fd;
  1197. req_exec_ckpt_sectionoverwrite.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1198. iovecs[0].iov_base = &req_exec_ckpt_sectionoverwrite;
  1199. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  1200. /*
  1201. * Send section name and data to overwrite in message
  1202. */
  1203. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  1204. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  1205. if (iovecs[1].iov_len > 0) {
  1206. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_MED);
  1207. } else {
  1208. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1209. }
  1210. return (0);
  1211. }
  1212. static int message_handler_req_lib_ckpt_sectionread (int fd, void *message)
  1213. {
  1214. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  1215. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  1216. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1217. struct iovec iovecs[2];
  1218. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", fd);
  1219. /*
  1220. * Determine if checkpoint is opened in write mode If not, send error to api
  1221. */
  1222. if ((connections[fd].ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_READ) == 0) {
  1223. res_lib_ckpt_sectionread.header.magic = MESSAGE_MAGIC;
  1224. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread);
  1225. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  1226. res_lib_ckpt_sectionread.error = SA_ERR_ACCESS;
  1227. libais_send_response (fd, &res_lib_ckpt_sectionread,
  1228. sizeof (struct res_lib_ckpt_sectionread));
  1229. return (0);
  1230. }
  1231. /*
  1232. * checkpoint opened is writeable mode so send message to cluster
  1233. */
  1234. req_exec_ckpt_sectionread.header.magic = MESSAGE_MAGIC;
  1235. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  1236. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  1237. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  1238. req_lib_ckpt_sectionread,
  1239. sizeof (struct req_lib_ckpt_sectionread));
  1240. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  1241. &connections[fd].ais_ci.u.libckpt_ci.checkpoint->name,
  1242. sizeof (SaNameT));
  1243. req_exec_ckpt_sectionread.source.fd = fd;
  1244. req_exec_ckpt_sectionread.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1245. iovecs[0].iov_base = &req_exec_ckpt_sectionread;
  1246. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  1247. /*
  1248. * Send section name and data to overwrite in message
  1249. */
  1250. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  1251. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  1252. if (iovecs[1].iov_len > 0) {
  1253. gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_MED);
  1254. } else {
  1255. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1256. }
  1257. return (0);
  1258. }
  1259. static int message_handler_req_lib_ckpt_checkpointsynchronize (int fd, void *message)
  1260. {
  1261. return (0);
  1262. }
  1263. static int message_handler_req_lib_ckpt_checkpointsyncronizeasync (int fd, void *message)
  1264. {
  1265. return (0);
  1266. }
  1267. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (int fd, void *message)
  1268. {
  1269. struct req_lib_ckpt_sectioniteratorinitialize *req_lib_ckpt_sectioniteratorinitialize = (struct req_lib_ckpt_sectioniteratorinitialize *)message;
  1270. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  1271. struct saCkptCheckpoint *ckptCheckpoint;
  1272. struct saCkptCheckpointSection *ckptCheckpointSection;
  1273. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  1274. struct saCkptSectionIterator *ckptSectionIterator;
  1275. struct list_head *checkpointSectionList;
  1276. int addEntry = 0;
  1277. int iteratorEntries = 0;
  1278. SaErrorT error = SA_OK;
  1279. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  1280. ckptSectionIterator = &connections[fd].ais_ci.u.libckpt_ci.sectionIterator;
  1281. ckptCheckpoint = findCheckpoint (&req_lib_ckpt_sectioniteratorinitialize->checkpointName);
  1282. if (ckptCheckpoint == 0) {
  1283. error = SA_ERR_NOT_EXIST;
  1284. goto error_exit;
  1285. }
  1286. /*
  1287. * Iterate list of checkpoint sections
  1288. */
  1289. for (checkpointSectionList = ckptCheckpoint->checkpointSectionsListHead.next;
  1290. checkpointSectionList != &ckptCheckpoint->checkpointSectionsListHead;
  1291. checkpointSectionList = checkpointSectionList->next) {
  1292. ckptCheckpointSection = list_entry (checkpointSectionList,
  1293. struct saCkptCheckpointSection, list);
  1294. addEntry = 1;
  1295. /*
  1296. * Item should be added to iterator list
  1297. */
  1298. if (addEntry) {
  1299. iteratorEntries += 1;
  1300. ckptSectionIteratorEntries =
  1301. realloc (ckptSectionIterator->sectionIteratorEntries,
  1302. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  1303. if (ckptSectionIteratorEntries == 0) {
  1304. if (ckptSectionIterator->sectionIteratorEntries) {
  1305. free (ckptSectionIterator->sectionIteratorEntries);
  1306. }
  1307. error = SA_ERR_NO_MEMORY;
  1308. goto error_exit;
  1309. }
  1310. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  1311. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  1312. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  1313. }
  1314. }
  1315. ckptSectionIterator->iteratorCount = iteratorEntries;
  1316. error_exit:
  1317. res_lib_ckpt_sectioniteratorinitialize.header.magic = MESSAGE_MAGIC;
  1318. res_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize);
  1319. res_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  1320. res_lib_ckpt_sectioniteratorinitialize.error = error;
  1321. libais_send_response (fd, &res_lib_ckpt_sectioniteratorinitialize,
  1322. sizeof (struct res_lib_ckpt_sectioniteratorinitialize));
  1323. return (0);
  1324. }
  1325. static int message_handler_req_lib_ckpt_sectioniteratornext (int fd, void *message)
  1326. {
  1327. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  1328. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  1329. struct saCkptSectionIterator *ckptSectionIterator;
  1330. SaErrorT error = SA_OK;
  1331. int sectionIdSize = 0;
  1332. int iteratorPos = 0;
  1333. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  1334. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  1335. ckptSectionIterator = &connections[fd].ais_ci.u.libckpt_ci.sectionIterator;
  1336. /*
  1337. * Find active iterator entry
  1338. */
  1339. for (;;) {
  1340. /*
  1341. * No more sections in iterator
  1342. */
  1343. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  1344. error = SA_ERR_NOT_EXIST;
  1345. goto error_exit;
  1346. }
  1347. /*
  1348. * active iterator entry
  1349. */
  1350. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  1351. break;
  1352. }
  1353. ckptSectionIterator->iteratorPos += 1;
  1354. }
  1355. /*
  1356. * Prepare response to API
  1357. */
  1358. iteratorPos = ckptSectionIterator->iteratorPos;
  1359. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  1360. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  1361. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  1362. sizeof (SaCkptSectionDescriptorT));
  1363. /*
  1364. * Get to next iterator entry
  1365. */
  1366. ckptSectionIterator->iteratorPos += 1;
  1367. error_exit:
  1368. res_lib_ckpt_sectioniteratornext.header.magic = MESSAGE_MAGIC;
  1369. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  1370. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  1371. res_lib_ckpt_sectioniteratornext.error = error;
  1372. libais_send_response (fd, &res_lib_ckpt_sectioniteratornext,
  1373. sizeof (struct res_lib_ckpt_sectioniteratornext));
  1374. libais_send_response (fd,
  1375. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  1376. sectionIdSize);
  1377. return (0);
  1378. }