ckpt.c 61 KB

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