void *th_dispatch (void *arg)
{
	struct thread_data *td = (struct thread_data *)arg;
	SaCkptHandleT ckptHandle;
	SaCkptCheckpointHandleT handle;
	SaAisErrorT error;
	int i;
	SaUint32T erroroneousVectorIndex = 0;

	error = saCkptInitialize (&ckptHandle, &callbacks, &version);

	error = saCkptCheckpointOpen (ckptHandle,
		&checkpointName,
		&checkpointCreationAttributes,
		SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
		0,
		&handle);
	for (i = 0; i < 1000; i++) {
		error = saCkptCheckpointWrite (handle,
			WriteVectorElements,
			1,
			&erroroneousVectorIndex);
		printf ("Thread %d: Attempt %d: error %d\n",
			td->thread_no, i, error);
		if (error != SA_AIS_OK) {
			printf ("Thread %d: Error from write.\n", td->thread_no);
		}
	}

    error = saCkptFinalize (ckptHandle);

	return (0);
}
void *benchmark_thread (void *arg) 
{
	
	SaCkptCheckpointHandleT checkpoint_handle;
	SaCkptHandleT ckpt_handle;
	int write_size;
	SaAisErrorT error;
	SaUint32T erroroneousVectorIndex = 0;
	struct threaddata *td = (struct threaddata *)arg;

	checkpoint_handle = td->checkpoint_handle;
	ckpt_handle = td->ckpt_handle;
	write_size = td->write_size;

	WriteVectorElements[0].dataSize = write_size;

	do {
		/*
		 * Test checkpoint write
		 */
		do {
		error = saCkptCheckpointWrite (checkpoint_handle,
			WriteVectorElements,
			1,
			&erroroneousVectorIndex);
		} while (error == SA_AIS_ERR_TRY_AGAIN);
		fail_on_error(error, "saCkptCheckpointWrite");
		td->written += 1;
	} while (alarm_notice == 0);
	pthread_exit (0);
}
/*******************************************************************************
Feature  API: alarmClockCkptWrite

Description : 

This API will not attempt to validate arguments, the thinking being that 
this is a volitional act by the invoker of this API to ensure that invalid 
parameters can be handled gracefully by the subsystem

Arguments In: 
    1. ClCkptHdlT : ckpt handle
    2. section number
    3. data to write
    4. size of data to write 

*******************************************************************************/
SaAisErrorT  
alarmClockCkptWrite (
    SaCkptCheckpointHandleT ckpt_hdl,
    SaUint32T               section_num,
    void*                   data,
    SaUint32T               data_size )
{
    SaAisErrorT          ret_code = SA_AIS_OK; 
    SaCkptSectionIdT     *section_id = NULL;
    SaCkptSectionIdT     *ctrl_section_id = NULL;
    SaCkptIOVectorElementT *ioVecIter = ioVecs;
    ClUint32T errVecIndex = 0;

    if(section_num > NUM_SECTION_ID_MAPS || 
       (data_size != sizeof(acClockT)))
        return SA_AIS_ERR_INVALID_PARAM;

    data_size = sizeof(SessionT);
    section_id = &sectionIdMap[section_num-1].sectionId;
    ctrl_section_id = &sectionIdMap[section_num-1].ctrlSectionId;
    memset(ioVecs, 0, sizeof(*ioVecs) * MAX_NUM_IOVECS);
    SessionCtrlT *sessionCtrl = sessionAddCkpt((acClockT*)data, &ioVecIter, ctrl_section_id);
    CL_ASSERT(sessionCtrl != NULL);
    memcpy(&ioVecIter->sectionId, section_id, sizeof(ioVecIter->sectionId));
    ioVecIter->dataOffset = sessionCtrl->offset * data_size;
    ioVecIter->dataBuffer = &sessionCtrl->session;
    ioVecIter->readSize = ioVecIter->dataSize = sizeof(sessionCtrl->session);
    ++ioVecIter;
    ret_code = saCkptCheckpointWrite(ckpt_hdl, ioVecs, (ClUint32T)(ioVecIter - ioVecs),
                                     &errVecIndex);

    if (ret_code != SA_AIS_OK)
    {
        alarmClockLogWrite(CL_LOG_SEV_ERROR, "alarmClockCkptWrite(hdl=%llx): Failed to write: 0x%x "
                           "for session [%d] at offset [%d]. Error iovec index [%d]\n", 
                           ckpt_hdl, ret_code, sessionCtrl->session.id,
                           sessionCtrl->offset, errVecIndex); 
    }
    else
    {
        alarmClockLogWrite(CL_LOG_SEV_DEBUG, "alarmClockCkptWrite: wrote %d bytes to section: %.*s, "
                           "iovecs [%d] for session [%d] at offset [%d]", 
                           data_size, section_id->idLen, (char*)section_id->id,
                           (ClUint32T)(ioVecIter - ioVecs), 
                           sessionCtrl->session.id, sessionCtrl->offset); 
    }

    return ret_code;
}
SaAisErrorT alarmClockCkptSessionDelete(SaCkptCheckpointHandleT ckpt_hdl, 
                                        ClUint32T section_num,
                                        ClUint32T id)
{
    SaCkptIOVectorElementT *ioVecIter = ioVecs;
    SessionCtrlT ctrl;
    SaCkptSectionIdT *ctrl_section_id;
    SaCkptSectionIdT *section_id;
    SaUint32T errVecIndex = 0;
    SaAisErrorT rc = SA_AIS_OK;
    if(section_num > NUM_SECTION_ID_MAPS)
        return SA_AIS_ERR_INVALID_PARAM;
    ctrl_section_id = &sectionIdMap[section_num-1].ctrlSectionId;
    section_id = &sectionIdMap[section_num-1].sectionId;
    memset(ioVecs, 0, sizeof(*ioVecs) * MAX_NUM_IOVECS);
    rc = sessionDelCkpt(id, &ctrl, &ioVecIter, ctrl_section_id);
    if(rc != CL_OK)
    {
        alarmClockLogWrite(CL_LOG_SEV_ERROR, "alarmClockCkptSessionDelete: "
                           "Session id [%d] delete failed with [%#x]", 
                           id, rc);
        rc = SA_AIS_ERR_NOT_EXIST;
        goto out;
    }
    /*
     * Write a delete entry by marking the session as deleted
     */
    memcpy(&ioVecIter->sectionId, section_id, sizeof(ioVecIter->sectionId));
    ioVecIter->dataOffset = ctrl.offset * sizeof(SessionT);
    ioVecIter->dataBuffer = &ctrl.session;
    ioVecIter->readSize = ioVecIter->dataSize = sizeof(ctrl.session);
    ++ioVecIter;
    rc = saCkptCheckpointWrite(ckpt_hdl, ioVecs, (ClUint32T)(ioVecIter - ioVecs), 
                               &errVecIndex);
    if(rc != SA_AIS_OK)
    {
        alarmClockLogWrite(CL_LOG_SEV_ERROR, "alarmClockCkptSessionDelete: "
                           "Session delete for id [%d] at offset [%d] failed with ckpt error [%#x]",
                           id, ctrl.offset, rc);
        goto out;
    }
    alarmClockLogWrite(CL_LOG_SEV_DEBUG, "alarmClockCkptSessionDelete: "
                       "Session delete success for id [%d] at offset [%d]",
                       id, ctrl.offset);

    out:
    return rc;
}
void ckpt_benchmark (SaCkptCheckpointHandleT checkpointHandle,
	int write_size)
{
	struct timeval tv1, tv2, tv_elapsed;
	SaUint32T erroroneousVectorIndex = 0;
	SaAisErrorT error;
	int write_count = 0;

	alarm_notice = 0;
	alarm (10);
	WriteVectorElements[0].dataSize = write_size;

	gettimeofday (&tv1, NULL);
	do {
		/*
		 * Test checkpoint write
		 */
retry:
		error = saCkptCheckpointWrite (checkpointHandle,
			WriteVectorElements,
			1,
			&erroroneousVectorIndex);
		if (error == SA_AIS_ERR_TRY_AGAIN) {
			goto retry;
		}
		fail_on_error(error, "saCkptCheckpointWrite");
		write_count += 1;
	} while (alarm_notice == 0);
	gettimeofday (&tv2, NULL);
	timersub (&tv2, &tv1, &tv_elapsed);

	printf ("%5d Writes ", write_count);
	printf ("%5d bytes per write ", write_size);
	printf ("%7.3f Seconds runtime ", 
		(tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
	printf ("%9.3f TP/s ",
		((float)write_count) /  (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
	printf ("%7.3f MB/s.\n", 
		((float)write_count) * ((float)write_size) /  ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
}
コード例 #6
0
ファイル: vm_states.c プロジェクト: Thermi/fence-virt
int
ckpt_write(void *hp, const char *secid, void *buf, size_t maxlen)
{
	ckpt_handle *h = (ckpt_handle *)hp;
	SaCkptIOVectorElementT iov = {SA_CKPT_DEFAULT_SECTION_ID,
				      NULL, 0, 0, 0};
	SaAisErrorT err;
	SaCkptSectionCreationAttributesT attrs;

	VALIDATE(h);

	/* Set section ID here */
	iov.sectionId.id = (uint8_t *)secid;
	iov.sectionId.idLen = strlen(secid);
	iov.dataBuffer = buf;
	iov.dataSize = (SaSizeT)maxlen;
	iov.dataOffset = 0;
	iov.readSize = 0;

	err = saCkptCheckpointWrite(h->ck_checkpoint, &iov, 1, NULL);

	if (err == SA_AIS_ERR_NOT_EXIST) {
		attrs.sectionId = &iov.sectionId;
		attrs.expirationTime = SA_TIME_END;

		err = saCkptSectionCreate(h->ck_checkpoint, &attrs, 
					  buf, maxlen);
	}

	if (err == SA_AIS_OK)
		saCkptCheckpointSynchronize(h->ck_checkpoint,
					    h->ck_timeout);

	errno = ais_to_posix(err);
	if (errno)
		return -1;
	return maxlen; /* XXX */
}
コード例 #7
0
void process_message()
{
        struct timeval tv;
        long t1;
        long t2;
	long told;
        SaCkptIOVectorElementT writeElement; // KJS

        SaUint32T erroroneousVectorIndex = 0;
        SaAisErrorT error;
        
        writeElement.sectionId = sectionId;
        writeElement.dataBuffer = getPayload(200); 
        writeElement.dataSize = 200;
        writeElement.dataOffset = 0;
        writeElement.readSize = 0;

        gettimeofday(&tv, NULL);
        t1 = tv.tv_usec;
	told = tv.tv_sec;
        
        do {
                error = saCkptCheckpointWrite (WriteCheckpointHandle,
                                               &writeElement,
                                               1,
                                               &erroroneousVectorIndex);

                if (error != SA_AIS_OK) {
                        fprintf(stderr,"saCkptCheckpointWrite result %d (should be 1)\n", error);
                }
                sendCount++;
                fprintf(stderr,"sendCount = %d",(int)sendCount);
        } while (error == SA_AIS_ERR_TRY_AGAIN);

        gettimeofday(&tv, NULL);
        t2 = tv.tv_usec;        
        fprintf(stderr," ,RTT::%d.%d\n",(long)tv.tv_sec - told, t2-t1);
}
コード例 #8
0
/****************************************************************************
 * Name          : cpsv_test_sync_app_process
 *
 * Description   : This is the function which is given as the input to the
 *                 Application task.
 *
 * Arguments     : info  - This is the information which is passed during
 *                         spawing Application task.
 *
 * Return Values : None.
 *
 * Notes         : None.
 *****************************************************************************/
void cpsv_test_sync_app_process(void *info)
{
   SaCkptHandleT ckptHandle;
   SaCkptCheckpointHandleT  checkpointHandle;
   SaCkptCallbacksT callbk;
   SaVersionT version;
   SaNameT ckptName;
   SaAisErrorT rc;
   SaCkptCheckpointCreationAttributesT ckptCreateAttr;
   SaCkptCheckpointOpenFlagsT ckptOpenFlags;
   SaCkptSectionCreationAttributesT sectionCreationAttributes;
   SaCkptIOVectorElementT writeVector, readVector;
   SaUint32T erroneousVectorIndex;
   void *initialData = "Default data in the section";
   unsigned char read_buff[100] = {0};
   SaTimeT timeout = 1000000000;
   unsigned int  temp_var = (unsigned int)(long)info; 


   memset(&ckptName, 0, 255);
   ckptName.length = strlen(DEMO_CKPT_NAME);
   memcpy(ckptName.value,DEMO_CKPT_NAME,strlen(DEMO_CKPT_NAME));

   callbk.saCkptCheckpointOpenCallback = AppCkptOpenCallback;
   callbk.saCkptCheckpointSynchronizeCallback = AppCkptSyncCallback;
   version.releaseCode= 'B';
   version.majorVersion = 2;
   version.minorVersion = 2;
   
   printf("*******************************************************************\n");
   printf("Demonstrating Checkpoint Service Usage with a collocated Checkpoint \n");
   printf("*******************************************************************\n");
   sleep(2);

   printf("Initialising With Checkpoint Service....\n");
   rc = saCkptInitialize(&ckptHandle,&callbk,&version);
   if(rc == SA_AIS_OK)
      printf("PASSED \n");
   else
      printf("Failed \n");

   ckptCreateAttr.creationFlags = SA_CKPT_CHECKPOINT_COLLOCATED|SA_CKPT_WR_ACTIVE_REPLICA;
   ckptCreateAttr.checkpointSize = 1024;
   ckptCreateAttr.retentionDuration= 100000;
   ckptCreateAttr.maxSections= 2;
   ckptCreateAttr.maxSectionSize = 700;
   ckptCreateAttr.maxSectionIdSize = 4;

   ckptOpenFlags = SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE;
   printf("Opening Collocated Checkpoint = %s with create flags....\n",ckptName.value);
   rc = saCkptCheckpointOpen(ckptHandle,&ckptName,&ckptCreateAttr,ckptOpenFlags,timeout,&checkpointHandle);
   if(rc == SA_AIS_OK)
      printf("PASSED \n");
   else
      printf("Failed \n");


   
   if(temp_var == 1)
   {
 
      printf("Setting the Active Replica for my checkpoint ....\t");
      rc = saCkptActiveReplicaSet(checkpointHandle);
      if(rc == SA_AIS_OK)
         printf("PASSED \n");
      else
         printf("Failed \n");
    

   sectionCreationAttributes.sectionId = (SaCkptSectionIdT*) malloc(sizeof \
                                (SaCkptSectionIdT));
   sectionCreationAttributes.sectionId->id = (unsigned char *)"11";
   sectionCreationAttributes.sectionId->idLen = 2;
   sectionCreationAttributes.expirationTime = 3600000000000ll;   /* One Hour */

   printf("Created Section ....\t");
   rc = saCkptSectionCreate(checkpointHandle,&sectionCreationAttributes,initialData,28);
   if(rc == SA_AIS_OK)
      printf("PASSED \n");
   else
      printf("Failed \n");

  
      writeVector.sectionId.id = (unsigned char *)"11";
      writeVector.sectionId.idLen = 2;
      writeVector.dataBuffer = "The Checkpoint Service provides a facility for processes to store checkpoint data";
      writeVector.dataSize = strlen(writeVector.dataBuffer);
      writeVector.dataOffset = 0;
      writeVector.readSize = 0;

      printf("Writing to Checkpoint %s ....\n",DEMO_CKPT_NAME);
      printf("Section-Id = %s ....\n",writeVector.sectionId.id);
      printf("CheckpointData being written = \"%s\"\n",(char *)writeVector.dataBuffer);
      printf("DataOffset = %llu ....\n",writeVector.dataOffset);
      rc = saCkptCheckpointWrite(checkpointHandle,&writeVector,1,&erroneousVectorIndex);
      if(rc == SA_AIS_OK)
         printf("PASSED \n");
      else
         printf("Failed \n");
      sleep(1); 

      printf("Press <Enter> key to continue...\n");
      getchar();
    }
    else
    {  
       sleep(4);
       readVector.sectionId.id = (unsigned char *)"11";
       readVector.sectionId.idLen = 2;
       readVector.dataBuffer = read_buff;
       readVector.dataSize = 90;
       readVector.dataOffset = 0;                                                                                                                                                                 
       printf("Waiting to Read from Checkpoint %s....\n",DEMO_CKPT_NAME);
       printf("Press <Enter> key to continue...\n");
       getchar();	
       rc = saCkptCheckpointRead(checkpointHandle,&readVector,1,&erroneousVectorIndex);
       printf("Checkpoint Data Read = \"%s\"\n",(char *)readVector.dataBuffer);
       if(rc == SA_AIS_OK)
          printf("PASSED \n");
       else
          printf("Failed \n");   
   }
   printf("Synchronizing My Checkpoint being called ....\n");
   rc = saCkptCheckpointSynchronize(checkpointHandle,timeout);
   if(rc == SA_AIS_OK)
      printf("PASSED \n");
   else
      printf("Failed \n");
                                             
   if(temp_var==1)
   {
      printf("Unlink My Checkpoint ....\t");
      rc = saCkptCheckpointUnlink(ckptHandle,&ckptName);
      if(rc == SA_AIS_OK)
         printf("PASSED \n");
      else
         printf("Failed \n");
   }
   printf("Ckpt Closed ....\t");
   rc = saCkptCheckpointClose(checkpointHandle);
   if(rc == SA_AIS_OK)
      printf("PASSED \n");
   else
      printf("Failed \n");
                                                                                                                                                                      

   printf("Ckpt Finalize being called ....\t");
   rc = saCkptFinalize(ckptHandle);
   if(rc == SA_AIS_OK)
      printf("PASSED \n");
   else
      printf("Failed \n");
                                                                                                                                                                      
   sleep(2);
  return;
}
コード例 #9
0
ファイル: ckpt-wr.c プロジェクト: ystk/debian-openais
int main (void) {
	SaCkptHandleT ckptHandle;
	SaCkptCheckpointHandleT checkpointHandle;
	SaAisErrorT error;
	char data[MAX_DATA_SIZE];
	struct timespec delay;
	struct timespec delay2;
	SaCkptIOVectorElementT writeElement;
	long count = 0;
	SaUint32T erroroneousVectorIndex = 0;

	delay.tv_sec = 1;
	delay.tv_nsec = 0;

	error = saCkptInitialize (&ckptHandle, &callbacks, &version);

	error = saCkptCheckpointOpen (ckptHandle,
			&checkpointName,
			&checkpointCreationAttributes,
			SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
			0,
			&checkpointHandle);
	printf ("%s: initial open of checkpoint\n",
		get_test_output (error, SA_AIS_OK));


    do{
			error = saCkptCheckpointRead (checkpointHandle,
				ReadVectorElements,
				1,
				&erroroneousVectorIndex);
			if (error != SA_AIS_OK) {
				if (error == SA_AIS_ERR_TRY_AGAIN) {
					continue;
				}
printf ("error is %d\n", error);
				return (0);
			}

			if (ReadVectorElements->dataBuffer == 0) {
				printf ("Default Checkpoint has no data\n");
			} else {
				count = atol((char *)ReadVectorElements->dataBuffer);
			}

			count++;
			sprintf((char*)&data, "%d",(int)count);
			writeElement.sectionId = (SaCkptSectionIdT)SA_CKPT_DEFAULT_SECTION_ID;
			writeElement.dataBuffer = data;
			writeElement.dataSize = strlen (data) + 1;
			writeElement.dataOffset = 0;
			writeElement.readSize = 0;

			do {
				error = saCkptCheckpointWrite (checkpointHandle,
					&writeElement,
					1,
					&erroroneousVectorIndex);

				printf ("%s: checkpoint write with data %s\n",
							get_test_output (error, SA_AIS_OK), (char*)data);
			}while (error == SA_AIS_ERR_TRY_AGAIN);

			nanosleep(&delay,&delay2);
	}while (1);

	return (0);

}