| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439 |
- /*
- * Copyright (c) 2002-2004 MontaVista Software, Inc.
- *
- * All rights reserved.
- *
- * Author: Steven Dake (sdake@mvista.com)
- *
- * This software licensed under BSD license, the text of which follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * - Neither the name of the MontaVista Software, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <errno.h>
- #include <pthread.h>
- #include <sys/types.h>
- #include <sys/uio.h>
- #include <sys/socket.h>
- #include <sys/select.h>
- #include <sys/un.h>
- #include "../include/list.h"
- #include "../include/ais_types.h"
- #include "../include/ais_ckpt.h"
- #include "../include/ais_msg.h"
- #include "util.h"
- struct message_overlay {
- struct req_header header;
- char data[4096];
- };
- /*
- * Data structure for instance data
- */
- struct ckptInstance {
- int fd;
- struct queue inq;
- SaCkptCallbacksT callbacks;
- int finalize;
- pthread_mutex_t mutex;
- };
- struct ckptCheckpointInstance {
- int fd;
- SaNameT checkpointName;
- SaUint32T maxSectionIdSize;
- pthread_mutex_t mutex;
- };
- struct ckptSectionIteratorInstance {
- int fd;
- struct list_head sectionIdListHead;
- SaUint32T maxSectionIdSize;
- pthread_mutex_t mutex;
- };
- void ckptHandleInstanceDestructor (void *instance);
- void checkpointHandleInstanceDestructor (void *instance);
- void ckptSectionIteratorHandleInstanceDestructor (void *instance);
- /*
- * All CKPT instances in this database
- */
- static struct saHandleDatabase ckptHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = ckptHandleInstanceDestructor
- };
- /*
- * All Checkpoint instances in this database
- */
- static struct saHandleDatabase checkpointHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = checkpointHandleInstanceDestructor
- };
- /*
- * All section iterators in this database
- */
- static struct saHandleDatabase ckptSectionIteratorHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = ckptSectionIteratorHandleInstanceDestructor
- };
- /*
- * Versions supported
- */
- static SaVersionT ckptVersionsSupported[] = {
- { 'A', 1, 1 },
- { 'a', 1, 1 }
- };
- static struct saVersionDatabase ckptVersionDatabase = {
- sizeof (ckptVersionsSupported) / sizeof (SaVersionT),
- ckptVersionsSupported
- };
- /*
- * Implementation
- */
- void ckptHandleInstanceDestructor (void *instance)
- {
- struct ckptInstance *ckptInstance = (struct ckptInstance *)instance;
- if (ckptInstance->fd != -1) {
- shutdown (ckptInstance->fd, 0);
- close (ckptInstance->fd);
- }
- if (ckptInstance->inq.items) {
- free (ckptInstance->inq.items);
- }
- }
- void checkpointHandleInstanceDestructor (void *instance)
- {
- struct ckptCheckpointInstance *ckptCheckpointInstance = (struct ckptCheckpointInstance *)instance;
- if (ckptCheckpointInstance->fd != -1) {
- shutdown (ckptCheckpointInstance->fd, 0);
- close (ckptCheckpointInstance->fd);
- }
- }
- void ckptSectionIteratorHandleInstanceDestructor (void *instance)
- {
- struct ckptSectionIteratorInstance *ckptSectionIteratorInstance = (struct ckptSectionIteratorInstance *)instance;
- if (ckptSectionIteratorInstance->fd != -1) {
- shutdown (ckptSectionIteratorInstance->fd, 0);
- close (ckptSectionIteratorInstance->fd);
- }
- }
- SaErrorT
- saCkptInitialize (
- SaCkptHandleT *ckptHandle,
- const SaCkptCallbacksT *callbacks,
- const SaVersionT *version)
- {
- struct ckptInstance *ckptInstance;
- SaErrorT error = SA_OK;
- error = saVersionVerify (&ckptVersionDatabase, version);
- if (error != SA_OK) {
- goto error_no_destroy;
- }
- error = saHandleCreate (&ckptHandleDatabase, sizeof (struct ckptInstance),
- ckptHandle);
- if (error != SA_OK) {
- goto error_no_destroy;
- }
- error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle,
- (void *)&ckptInstance);
- if (error != SA_OK) {
- goto error_destroy;
- }
- ckptInstance->fd = -1;
- /*
- * An inq is needed to store async messages while waiting for a
- * sync response
- */
- error = saQueueInit (&ckptInstance->inq, 512, sizeof (void *));
- if (error != SA_OK) {
- goto error_put_destroy;
- }
- error = saServiceConnect (&ckptInstance->fd, MESSAGE_REQ_CKPT_CHECKPOINT_INIT);
- if (error != SA_OK) {
- goto error_put_destroy;
- }
- memcpy (&ckptInstance->callbacks, callbacks, sizeof (SaCkptCallbacksT));
- pthread_mutex_init (&ckptInstance->mutex, NULL);
- saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
- return (SA_OK);
- error_put_destroy:
- saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
- error_destroy:
- saHandleDestroy (&ckptHandleDatabase, *ckptHandle);
- error_no_destroy:
- return (error);
- }
- SaErrorT
- saCkptSelectionObjectGet (
- const SaCkptHandleT *ckptHandle,
- SaSelectionObjectT *selectionObject)
- {
- struct ckptInstance *ckptInstance;
- SaErrorT error;
- error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle, (void *)&ckptInstance);
- if (error != SA_OK) {
- return (error);
- }
- *selectionObject = ckptInstance->fd;
- saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
- return (SA_OK);
- }
- #ifdef COMPILE_OUT
- SaErrorT
- saCkptDispatch (
- const SaCkptHandleT *ckptHandle,
- SaDispatchFlagsT dispatchFlags)
- {
- fd_set read_fds;
- SaErrorT error;
- int dispatch_avail;
- struct timeval *timeout = 0;
- struct ckptInstance *ckptInstance;
- struct req_header **queue_msg;
- struct req_header *msg;
- int empty;
- int ignore_dispatch = 0;
- int cont = 1; /* always continue do loop except when set to 0 */
- error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle, (void *)&ckptInstance);
- if (error != SA_OK) {
- return (error);
- }
- /*
- * Timeout instantly for SA_DISPATCH_ALL
- */
- if (dispatchFlags & SA_DISPATCH_ALL) {
- timeout = &zerousec;
- }
- do {
- /*
- * Read data directly from socket
- */
- FD_ZERO (&read_fds);
- FD_SET (ckptInstance->fd, &read_fds);
- error = saSelectRetry (ckptInstance->fd + 1, &read_fds, 0, 0, timeout);
- if (error != SA_OK) {
- goto error_exit;
- }
- dispatch_avail = FD_ISSET (ckptInstance->fd, &read_fds);
- if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
- break; /* exit do while cont is 1 loop */
- } else
- if (dispatch_avail == 0) {
- continue; /* next select */
- }
- saQueueIsEmpty(&ckptInstance->inq, &empty);
- if (empty == 0) {
- /*
- * Queue is not empty, read data from queue
- */
- saQueueItemGet (&ckptInstance->inq, (void **)&queue_msg);
- msg = *queue_msg;
- memcpy (&ckptInstance->message, msg, msg->size);
- saQueueItemRemove (&ckptInstance->inq);
- free (msg);
- } else {
- /*
- * Queue empty, read response from socket
- */
- error = saRecvRetry (ckptInstance->fd, &ckptInstance->message.header, sizeof (struct req_header), MSG_WAITALL | MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- if (ckptInstance->message.header.size > sizeof (struct req_header)) {
- error = saRecvRetry (ckptInstance->fd, &ckptInstance->message.data,
- ckptInstance->message.header.size - sizeof (struct req_header),
- MSG_WAITALL | MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- }
- }
- /*
- * Dispatch incoming response
- */
- switch (ckptInstance->message.header.id) {
- #ifdef COMPILE_OUT
- case MESSAGE_RES_CKPT_CHECKPOINT_ACTIVATEPOLL:
- /*
- * This is a do nothing message which the node executive sends
- * to activate the file handle in poll when the library has
- * queued a message into amfHandle->inq
- * The dispatch is ignored for the following two cases:
- * 1) setting of timeout to zero for the DISPATCH_ALL case
- * 2) expiration of the do loop for the DISPATCH_ONE case
- */
- ignore_dispatch = 1;
- break;
- case MESSAGE_RES_CKPT_CHECKPOINT_HEALTHCHECKCALLBACK:
- res_amf_healthcheckcallback = (struct res_amf_healthcheckcallback *)&ckptInstance->message;
- amfInstance->callbacks.saAmfHealthcheckCallback (
- res_amf_healthcheckcallback->invocation,
- &res_amf_healthcheckcallback->compName,
- res_amf_healthcheckcallback->checkType);
- break;
- case MESSAGE_RES_CKPT_CHECKPOINT_READINESSSTATESETCALLBACK:
- res_amf_readinessstatesetcallback = (struct res_amf_readinessstatesetcallback *)&ckptInstance->message;
- amfInstance->callbacks.saAmfReadinessStateSetCallback (
- res_amf_readinessstatesetcallback->invocation,
- &res_amf_readinessstatesetcallback->compName,
- res_amf_readinessstatesetcallback->readinessState);
- break;
- case MESSAGE_RES_CKPT_CHECKPOINT_CSISETCALLBACK:
- res_amf_csisetcallback = (struct res_amf_csisetcallback *)&ckptInstance->message;
- amfInstance->callbacks.saAmfCSISetCallback (
- res_amf_csisetcallback->invocation,
- &res_amf_csisetcallback->compName,
- &res_amf_csisetcallback->csiName,
- res_amf_csisetcallback->csiFlags,
- &res_amf_csisetcallback->haState,
- &res_amf_csisetcallback->activeCompName,
- res_amf_csisetcallback->transitionDescriptor);
- break;
- case MESSAGE_RES_CKPT_CHECKPOINT_CSIREMOVECALLBACK:
- res_amf_csiremovecallback = (struct res_amf_csiremovecallback *)&ckptInstance->message;
- amfInstance->callbacks.saAmfCSIRemoveCallback (
- res_amf_csiremovecallback->invocation,
- &res_amf_csiremovecallback->compName,
- &res_amf_csiremovecallback->csiName,
- &res_amf_csiremovecallback->csiFlags);
- break;
- case MESSAGE_RES_CKPT_CHECKPOINT_PROTECTIONGROUPTRACKCALLBACK:
- res_amf_protectiongrouptrackcallback = (struct res_amf_protectiongrouptrackcallback *)&ckptInstance->message;
- memcpy (res_amf_protectiongrouptrackcallback->notificationBufferAddress,
- res_amf_protectiongrouptrackcallback->notificationBuffer,
- res_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
- amfInstance->callbacks.saAmfProtectionGroupTrackCallback(
- &res_amf_protectiongrouptrackcallback->csiName,
- res_amf_protectiongrouptrackcallback->notificationBufferAddress,
- res_amf_protectiongrouptrackcallback->numberOfItems,
- res_amf_protectiongrouptrackcallback->numberOfMembers,
- res_amf_protectiongrouptrackcallback->error);
- break;
- #endif
- default:
- /* TODO */
- break;
- }
- /*
- * Determine if more messages should be processed
- */
- switch (dispatchFlags) {
- case SA_DISPATCH_ONE:
- if (ignore_dispatch) {
- ignore_dispatch = 0;
- } else {
- cont = 0;
- }
- break;
- case SA_DISPATCH_ALL:
- if (ignore_dispatch) {
- ignore_dispatch = 0;
- }
- break;
- case SA_DISPATCH_BLOCKING:
- break;
- }
- } while (cont);
- error_exit:
- return (error);
- }
- #endif
- SaErrorT
- saCkptFinalize (
- const SaCkptHandleT *ckptHandle)
- {
- struct ckptInstance *ckptInstance;
- SaErrorT error;
- error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle,
- (void *)&ckptInstance);
- if (error != SA_OK) {
- return (error);
- }
- pthread_mutex_lock (&ckptInstance->mutex);
- /*
- * Another thread has already started finalizing
- */
- if (ckptInstance->finalize) {
- pthread_mutex_unlock (&ckptInstance->mutex);
- saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
- return (SA_ERR_BAD_HANDLE);
- }
- ckptInstance->finalize = 1;
- saActivatePoll (ckptInstance->fd);
- pthread_mutex_unlock (&ckptInstance->mutex);
- saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
- saHandleDestroy (&ckptHandleDatabase, *ckptHandle);
- return (SA_OK);
- }
- SaErrorT
- saCkptCheckpointOpen (
- const SaNameT *checkpointName,
- const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
- SaCkptCheckpointOpenFlagsT checkpointOpenFlags,
- SaTimeT timeout,
- SaCkptCheckpointHandleT *checkpointHandle)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_checkpointopen req_lib_ckpt_checkpointopen;
- struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
- error = saHandleCreate (&checkpointHandleDatabase,
- sizeof (struct ckptCheckpointInstance), checkpointHandle);
- if (error != SA_OK) {
- goto error_no_destroy;
- }
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- goto error_destroy;
- }
- ckptCheckpointInstance->fd = -1;
- ckptCheckpointInstance->maxSectionIdSize =
- checkpointCreationAttributes->maxSectionIdSize;
- error = saServiceConnect (&ckptCheckpointInstance->fd, MESSAGE_REQ_CKPT_CHECKPOINT_INIT);
- if (error != SA_OK) {
- goto error_put_destroy;
- }
- req_lib_ckpt_checkpointopen.header.size = sizeof (struct req_lib_ckpt_checkpointopen);
- req_lib_ckpt_checkpointopen.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPEN;
- memcpy (&req_lib_ckpt_checkpointopen.checkpointName, checkpointName, sizeof (SaNameT));
- memcpy (&ckptCheckpointInstance->checkpointName, checkpointName, sizeof (SaNameT));
- memcpy (&req_lib_ckpt_checkpointopen.checkpointCreationAttributes,
- checkpointCreationAttributes,
- sizeof (SaCkptCheckpointCreationAttributesT));
- req_lib_ckpt_checkpointopen.checkpointOpenFlags = checkpointOpenFlags;
- error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointopen,
- sizeof (struct req_lib_ckpt_checkpointopen), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_put_destroy;
- }
- error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_checkpointopen,
- sizeof (struct res_lib_ckpt_checkpointopen), MSG_WAITALL | MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_put_destroy;
- }
-
- if (res_lib_ckpt_checkpointopen.header.error != SA_OK) {
- error = res_lib_ckpt_checkpointopen.header.error;
- goto error_put_destroy;
- }
- pthread_mutex_init (&ckptCheckpointInstance->mutex, NULL);
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- return (error);
- error_put_destroy:
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- error_destroy:
- saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle);
- error_no_destroy:
- return (error);
- }
- SaErrorT
- saCkptCheckpointOpenAsync (
- const SaCkptHandleT *ckptHandle,
- SaInvocationT invocation,
- const SaNameT *checkpointName,
- const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
- SaCkptCheckpointOpenFlagsT checkpointOpenFlags)
- {
- struct ckptInstance *ckptInstance;
- SaErrorT error;
- struct req_lib_ckpt_checkpointopenasync req_lib_ckpt_checkpointopenasync;
- error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle, (void *)&ckptInstance);
- if (error != SA_OK) {
- return (error);
- }
- req_lib_ckpt_checkpointopenasync.header.size = sizeof (struct req_lib_ckpt_checkpointopenasync);
- req_lib_ckpt_checkpointopenasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
- req_lib_ckpt_checkpointopenasync.invocation = invocation;
- memcpy (&req_lib_ckpt_checkpointopenasync.checkpointName, checkpointName, sizeof (SaNameT));
- memcpy (&req_lib_ckpt_checkpointopenasync.checkpointCreationAttributes,
- checkpointCreationAttributes,
- sizeof (SaCkptCheckpointCreationAttributesT));
-
- req_lib_ckpt_checkpointopenasync.checkpointOpenFlags = checkpointOpenFlags;
- pthread_mutex_lock (&ckptInstance->mutex);
- error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointopenasync,
- sizeof (struct req_lib_ckpt_checkpointopenasync), MSG_NOSIGNAL);
- pthread_mutex_unlock (&ckptInstance->mutex);
- saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
- return (error);
- }
- SaErrorT
- saCkptCheckpointClose (
- const SaCkptCheckpointHandleT *checkpointHandle)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- goto error_exit;
- }
- saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle);
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- error_exit:
- return (error);
- }
- SaErrorT
- saCkptCheckpointUnlink (
- const SaNameT *checkpointName)
- {
- SaErrorT error;
- struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink;
- struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
- int fd;
- error = saServiceConnect (&fd, MESSAGE_REQ_CKPT_CHECKPOINT_INIT);
- if (error != SA_OK) {
- goto exit_noclose;
- }
- req_lib_ckpt_checkpointunlink.header.size = sizeof (struct req_lib_ckpt_checkpointunlink);
- req_lib_ckpt_checkpointunlink.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
- memcpy (&req_lib_ckpt_checkpointunlink.checkpointName, checkpointName, sizeof (SaNameT));
- error = saSendRetry (fd, &req_lib_ckpt_checkpointunlink, sizeof (struct req_lib_ckpt_checkpointunlink), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto exit_close;
- }
- error = saRecvRetry (fd, &res_lib_ckpt_checkpointunlink,
- sizeof (struct res_lib_ckpt_checkpointunlink), MSG_WAITALL | MSG_NOSIGNAL);
- exit_close:
- close (fd);
- return (error == SA_OK ? res_lib_ckpt_checkpointunlink.header.error : error);
- exit_noclose:
- return (error);
- }
- SaErrorT
- saCkptCheckpointRetentionDurationSet (
- const SaCkptCheckpointHandleT *checkpointHandle,
- SaTimeT retentionDuration)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_checkpointretentiondurationset req_lib_ckpt_checkpointretentiondurationset;
- struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- goto error_exit_noput;
- }
- req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset);
- req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
- req_lib_ckpt_checkpointretentiondurationset.retentionDuration = retentionDuration;
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- error = saRecvRetry (ckptCheckpointInstance->fd,
- &res_lib_ckpt_checkpointretentiondurationset,
- sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
- MSG_WAITALL | MSG_NOSIGNAL);
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- error_exit:
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- error_exit_noput:
- return (error == SA_OK ? res_lib_ckpt_checkpointretentiondurationset.header.error : error);
- }
- SaErrorT
- saCkptActiveCheckpointSet (
- const SaCkptCheckpointHandleT *checkpointHandle)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_activecheckpointset req_lib_ckpt_activecheckpointset;
- struct res_lib_ckpt_activecheckpointset res_lib_ckpt_activecheckpointset;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- goto error_exit;
- }
- req_lib_ckpt_activecheckpointset.header.size = sizeof (struct req_lib_ckpt_activecheckpointset);
- req_lib_ckpt_activecheckpointset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_ACTIVECHECKPOINTSET;
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_activecheckpointset,
- sizeof (struct req_lib_ckpt_activecheckpointset), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- error = saRecvRetry (ckptCheckpointInstance->fd,
- &res_lib_ckpt_activecheckpointset,
- sizeof (struct res_lib_ckpt_activecheckpointset),
- MSG_WAITALL | MSG_NOSIGNAL);
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- error_exit:
- return (error == SA_OK ? res_lib_ckpt_activecheckpointset.header.error : error);
- }
- SaErrorT
- saCkptCheckpointStatusGet (
- const SaCkptCheckpointHandleT *checkpointHandle,
- SaCkptCheckpointStatusT *checkpointStatus)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
- struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- return (error);
- }
- req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
- req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointstatusget,
- sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- error = saRecvRetry (ckptCheckpointInstance->fd,
- &res_lib_ckpt_checkpointstatusget,
- sizeof (struct res_lib_ckpt_checkpointstatusget),
- MSG_WAITALL | MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- memcpy (checkpointStatus,
- &res_lib_ckpt_checkpointstatusget.checkpointStatus,
- sizeof (SaCkptCheckpointStatusT));
- error_exit:
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- return (error);
- }
- SaErrorT
- saCkptSectionCreate (
- const SaCkptCheckpointHandleT *checkpointHandle,
- SaCkptSectionCreationAttributesT *sectionCreationAttributes,
- const void *initialData,
- SaUint32T initialDataSize)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
- struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- return (error);
- }
- req_lib_ckpt_sectioncreate.header.size =
- sizeof (struct req_lib_ckpt_sectioncreate) +
- sectionCreationAttributes->sectionId->idLen +
- initialDataSize;
- req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
- req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
- req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
- req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectioncreate,
- sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- /*
- * Write section identifier to server
- */
- error = saSendRetry (ckptCheckpointInstance->fd, sectionCreationAttributes->sectionId->id,
- sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- error = saSendRetry (ckptCheckpointInstance->fd, initialData,
- initialDataSize, MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- error = saRecvRetry (ckptCheckpointInstance->fd,
- &res_lib_ckpt_sectioncreate,
- sizeof (struct res_lib_ckpt_sectioncreate),
- MSG_WAITALL | MSG_NOSIGNAL);
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- error_exit:
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- return (error == SA_OK ? res_lib_ckpt_sectioncreate.header.error : error);
- }
- SaErrorT
- saCkptSectionDelete (
- const SaCkptCheckpointHandleT *checkpointHandle,
- const SaCkptSectionIdT *sectionId)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
- struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- return (error);
- }
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
- req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
- req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
- error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectiondelete,
- sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- /*
- * Write section identifier to server
- */
- error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
- sectionId->idLen, MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- error = saRecvRetry (ckptCheckpointInstance->fd,
- &res_lib_ckpt_sectiondelete,
- sizeof (struct res_lib_ckpt_sectiondelete),
- MSG_WAITALL | MSG_NOSIGNAL);
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- error_exit:
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- return (error == SA_OK ? res_lib_ckpt_sectiondelete.header.error : error);
- }
- SaErrorT
- saCkptSectionExpirationTimeSet (
- const SaCkptCheckpointHandleT *checkpointHandle,
- const SaCkptSectionIdT *sectionId,
- SaTimeT expirationTime)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
- struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- goto error_exit_noput;
- }
- req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen;
- req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
- req_lib_ckpt_sectionexpirationtimeset.idLen = sectionId->idLen;
- req_lib_ckpt_sectionexpirationtimeset.expirationTime = expirationTime;
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionexpirationtimeset,
- sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- /*
- * Write section identifier to server
- */
- if (sectionId->idLen) {
- error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
- sectionId->idLen, MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- }
- error = saRecvRetry (ckptCheckpointInstance->fd,
- &res_lib_ckpt_sectionexpirationtimeset,
- sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
- MSG_WAITALL | MSG_NOSIGNAL);
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- error_exit:
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- error_exit_noput:
- return (error == SA_OK ? res_lib_ckpt_sectionexpirationtimeset.header.error : error);
- }
- SaErrorT
- saCkptSectionIteratorInitialize (
- const SaCkptCheckpointHandleT *checkpointHandle,
- SaCkptSectionsChosenT sectionsChosen,
- SaTimeT expirationTime,
- SaCkptSectionIteratorT *sectionIterator)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
- struct req_lib_ckpt_sectioniteratorinitialize req_lib_ckpt_sectioniteratorinitialize;
- struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- goto error_no_destroy;
- }
- error = saHandleCreate (&ckptSectionIteratorHandleDatabase,
- sizeof (struct ckptSectionIteratorInstance), sectionIterator);
- if (error != SA_OK) {
- goto error_put_checkpoint_db;
- }
- error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
- *sectionIterator,
- (void *)&ckptSectionIteratorInstance);
- if (error != SA_OK) {
- goto error_destroy;
- }
- ckptSectionIteratorInstance->fd = -1;
- pthread_mutex_init (&ckptSectionIteratorInstance->mutex, NULL);
- /*
- * Setup section id list for iterator next
- */
- list_init (&ckptSectionIteratorInstance->sectionIdListHead);
- ckptSectionIteratorInstance->maxSectionIdSize =
- ckptCheckpointInstance->maxSectionIdSize;
- error = saServiceConnect (&ckptSectionIteratorInstance->fd,
- MESSAGE_REQ_CKPT_SECTIONITERATOR_INIT);
- if (error != SA_OK) {
- goto error_put_destroy;
- }
- req_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniteratorinitialize);
- req_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
- req_lib_ckpt_sectioniteratorinitialize.sectionsChosen = sectionsChosen;
- req_lib_ckpt_sectioniteratorinitialize.expirationTime = expirationTime;
- memcpy (&req_lib_ckpt_sectioniteratorinitialize.checkpointName,
- &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
- pthread_mutex_lock (&ckptSectionIteratorInstance->mutex);
- error = saSendRetry (ckptSectionIteratorInstance->fd,
- &req_lib_ckpt_sectioniteratorinitialize,
- sizeof (struct req_lib_ckpt_sectioniteratorinitialize),
- MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_put_destroy;
- }
- error = saRecvRetry (ckptSectionIteratorInstance->fd,
- &res_lib_ckpt_sectioniteratorinitialize,
- sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
- MSG_WAITALL | MSG_NOSIGNAL);
- pthread_mutex_unlock (&ckptSectionIteratorInstance->mutex);
- saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- return (error == SA_OK ? res_lib_ckpt_sectioniteratorinitialize.header.error : error);
- error_put_destroy:
- saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
- error_destroy:
- saHandleDestroy (&ckptSectionIteratorHandleDatabase, *sectionIterator);
- error_put_checkpoint_db:
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- error_no_destroy:
- return (error);
- }
- struct iteratorSectionIdListEntry {
- struct list_head list;
- char data[0];
- };
- SaErrorT
- saCkptSectionIteratorNext (
- SaCkptSectionIteratorT *sectionIterator,
- SaCkptSectionDescriptorT *sectionDescriptor)
- {
- SaErrorT error;
- struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
- struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
- struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
- struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
- error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
- *sectionIterator, (void *)&ckptSectionIteratorInstance);
- if (error != SA_OK) {
- goto error_exit;
- }
- /*
- * Allocate section id storage area
- */
- iteratorSectionIdListEntry = malloc (sizeof (struct list_head) +
- ckptSectionIteratorInstance->maxSectionIdSize);
- if (iteratorSectionIdListEntry == 0) {
- error = SA_ERR_NO_MEMORY;
- goto error_put_nounlock;
- }
- req_lib_ckpt_sectioniteratornext.header.size = sizeof (struct req_lib_ckpt_sectioniteratornext);
- req_lib_ckpt_sectioniteratornext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
- pthread_mutex_lock (&ckptSectionIteratorInstance->mutex);
- error = saSendRetry (ckptSectionIteratorInstance->fd,
- &req_lib_ckpt_sectioniteratornext,
- sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_put;
- }
- error = saRecvRetry (ckptSectionIteratorInstance->fd, &res_lib_ckpt_sectioniteratornext,
- sizeof (struct res_lib_ckpt_sectioniteratornext), MSG_WAITALL | MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_put;
- }
- memcpy (sectionDescriptor,
- &res_lib_ckpt_sectioniteratornext.sectionDescriptor,
- sizeof (SaCkptSectionDescriptorT));
- sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0];
-
- if ((res_lib_ckpt_sectioniteratornext.header.size - sizeof (struct res_lib_ckpt_sectioniteratornext)) > 0) {
- error = saRecvRetry (ckptSectionIteratorInstance->fd,
- sectionDescriptor->sectionId.id,
- res_lib_ckpt_sectioniteratornext.header.size -
- sizeof (struct res_lib_ckpt_sectioniteratornext),
- MSG_WAITALL | MSG_NOSIGNAL);
- }
- /*
- * Add to persistent memory list for this sectioniterator
- */
- if (error == SA_OK && res_lib_ckpt_sectioniteratornext.header.error == SA_OK) {
- list_init (&iteratorSectionIdListEntry->list);
- list_add (&iteratorSectionIdListEntry->list, &ckptSectionIteratorInstance->sectionIdListHead);
- }
- error_put:
- pthread_mutex_unlock (&ckptSectionIteratorInstance->mutex);
- error_put_nounlock:
- saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
- error_exit:
- return (error == SA_OK ? res_lib_ckpt_sectioniteratornext.header.error : error);
- }
-
- SaErrorT
- saCkptSectionIteratorFinalize (
- SaCkptSectionIteratorT *sectionIterator)
- {
- SaErrorT error;
- struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
- struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
- struct list_head *sectionIdIteratorList;
- struct list_head *sectionIdIteratorListNext;
- error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
- *sectionIterator, (void *)&ckptSectionIteratorInstance);
- if (error != SA_OK) {
- goto error_noput;
- }
- /*
- * iterate list of section ids for this iterator to free the allocated memory
- * be careful to cache next pointer because free removes memory from use
- */
- for (sectionIdIteratorList = ckptSectionIteratorInstance->sectionIdListHead.next,
- sectionIdIteratorListNext = sectionIdIteratorList->next;
- sectionIdIteratorList != &ckptSectionIteratorInstance->sectionIdListHead;
- sectionIdIteratorList = sectionIdIteratorListNext,
- sectionIdIteratorListNext = sectionIdIteratorList->next) {
- iteratorSectionIdListEntry = list_entry (sectionIdIteratorList,
- struct iteratorSectionIdListEntry, list);
- free (iteratorSectionIdListEntry);
- }
- saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
- saHandleDestroy (&ckptSectionIteratorHandleDatabase, *sectionIterator);
- error_noput:
- return (error);
- }
- SaErrorT
- saCkptCheckpointWrite (
- const SaCkptCheckpointHandleT *checkpointHandle,
- const SaCkptIOVectorElementT *ioVector,
- SaUint32T numberOfElements,
- SaUint32T *erroneousVectorIndex)
- {
- SaErrorT error = SA_OK;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
- struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
- int i;
- struct iovec iov[3];
- int iov_len = 0;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- return (error);
- }
- req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- for (i = 0; i < numberOfElements; i++) {
- req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
- req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
- req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
- req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
- iov_len = 0;
- /* TODO check for zero length stuff */
- iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
- iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
- iov[1].iov_base = ioVector[i].sectionId.id;
- iov[1].iov_len = ioVector[i].sectionId.idLen;
- iov[2].iov_base = ioVector[i].dataBuffer;
- iov[2].iov_len = ioVector[i].dataSize;
- error = saSendMsgRetry (ckptCheckpointInstance->fd,
- iov,
- 3);
- if (error != SA_OK) {
- goto error_exit;
- }
- /*
- * Receive response
- */
- error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionwrite,
- sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- if (res_lib_ckpt_sectionwrite.header.error == SA_ERR_TRY_AGAIN) {
- error = SA_ERR_TRY_AGAIN;
- goto error_exit;
- }
- /*
- * If error, report back erroneous index
- */
- if (res_lib_ckpt_sectionwrite.header.error != SA_OK) {
- if (erroneousVectorIndex) {
- *erroneousVectorIndex = i;
- }
- goto error_exit;
- }
- }
- error_exit:
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- return (error == SA_OK ? res_lib_ckpt_sectionwrite.header.error : error);
- }
- SaErrorT
- saCkptSectionOverwrite (
- const SaCkptCheckpointHandleT *checkpointHandle,
- const SaCkptSectionIdT *sectionId,
- SaUint8T *dataBuffer,
- SaSizeT dataSize)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
- struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- return (error);
- }
- req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
- req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
- req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
- req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
-
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionoverwrite,
- sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- if (sectionId->idLen) {
- error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
- sectionId->idLen, MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- }
- error = saSendRetry (ckptCheckpointInstance->fd, dataBuffer, dataSize, MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- error = saRecvRetry (ckptCheckpointInstance->fd,
- &res_lib_ckpt_sectionoverwrite,
- sizeof (struct res_lib_ckpt_sectionoverwrite),
- MSG_WAITALL | MSG_NOSIGNAL);
- error_exit:
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- return (error == SA_OK ? res_lib_ckpt_sectionoverwrite.header.error : error);
- }
- SaErrorT
- saCkptCheckpointRead (
- const SaCkptCheckpointHandleT *checkpointHandle,
- SaCkptIOVectorElementT *ioVector,
- SaUint32T numberOfElements,
- SaUint32T *erroneousVectorIndex)
- {
- SaErrorT error = SA_OK;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
- struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
- int dataLength;
- int i;
- struct iovec iov[3];
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- return (error);
- }
- req_lib_ckpt_sectionread.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD;
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- for (i = 0; i < numberOfElements; i++) {
- req_lib_ckpt_sectionread.header.size = sizeof (struct req_lib_ckpt_sectionread) +
- ioVector[i].sectionId.idLen;
- req_lib_ckpt_sectionread.idLen = ioVector[i].sectionId.idLen;
- req_lib_ckpt_sectionread.dataOffset = ioVector[i].dataOffset;
- req_lib_ckpt_sectionread.dataSize = ioVector[i].dataSize;
- iov[0].iov_base = (char *)&req_lib_ckpt_sectionread;
- iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread);
- iov[1].iov_base = ioVector[i].sectionId.id;
- iov[1].iov_len = ioVector[i].sectionId.idLen;
- error = saSendMsgRetry (ckptCheckpointInstance->fd,
- iov,
- 2);
- /*
- * Receive response header
- */
- error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionread,
- sizeof (struct res_lib_ckpt_sectionread), MSG_WAITALL | MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
-
- dataLength = res_lib_ckpt_sectionread.header.size - sizeof (struct res_lib_ckpt_sectionread);
- /*
- * Receive checkpoint section data
- */
- if (dataLength > 0) {
- error = saRecvRetry (ckptCheckpointInstance->fd, ioVector[i].dataBuffer,
- dataLength, MSG_WAITALL | MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- }
- if (res_lib_ckpt_sectionread.header.error != SA_OK) {
- if (erroneousVectorIndex) {
- *erroneousVectorIndex = i;
- }
- goto error_exit;
- }
- /*
- * Report back bytes of data read
- */
- ioVector[i].readSize = res_lib_ckpt_sectionread.dataRead;
- }
- error_exit:
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- return (error == SA_OK ? res_lib_ckpt_sectionread.header.error : error);
- }
- SaErrorT
- saCkptCheckpointSynchronize (
- const SaCkptCheckpointHandleT *checkpointHandle,
- SaTimeT timeout)
- {
- SaErrorT error;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- struct req_lib_ckpt_checkpointsynchronize req_lib_ckpt_checkpointsynchronize;
- struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- return (error);
- }
- req_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronize);
- req_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointsynchronize,
- sizeof (struct req_lib_ckpt_checkpointsynchronize), MSG_NOSIGNAL);
- if (error != SA_OK) {
- goto error_exit;
- }
- error = saRecvRetry (ckptCheckpointInstance->fd,
- &res_lib_ckpt_checkpointsynchronize,
- sizeof (struct res_lib_ckpt_checkpointsynchronize),
- MSG_WAITALL | MSG_NOSIGNAL);
- error_exit:
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- return (error == SA_OK ? res_lib_ckpt_checkpointsynchronize.header.error : error);
- }
- SaErrorT
- saCkptCheckpointSynchronizeAsync (
- const SaCkptHandleT *ckptHandle,
- SaInvocationT invocation,
- const SaCkptCheckpointHandleT *checkpointHandle)
- {
- return (SA_OK);
- /* TODO not implemented in executive
- struct ckptInstance *ckptInstance;
- struct ckptCheckpointInstance *ckptCheckpointInstance;
- SaErrorT error;
- struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync;
- error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
- (void *)&ckptCheckpointInstance);
- if (error != SA_OK) {
- return (error);
- }
- req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync);
- req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
- req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation;
- pthread_mutex_lock (&ckptCheckpointInstance->mutex);
- pthread_mutex_lock (&ckptInstance->mutex);
- error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointsynchronizeasync,
- sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL);
- pthread_mutex_unlock (&ckptInstance->mutex);
- pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
- saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
- return (error);
- */
- }
|