2 * Copyright (c) 2002-2005 MontaVista Software, Inc.
6 * Author: Steven Dake (sdake@mvista.com)
8 * This software licensed under BSD license, the text of which follows:
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
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.
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.
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <sys/select.h>
50 #define SECONDS_TO_EXPIRE 500
53 void printSaNameT (SaNameT
*name
)
57 for (i
= 0; i
< name
->length
; i
++) {
58 printf ("%c", name
->value
[i
]);
62 SaVersionT version
= { 'B', 1, 1 };
64 SaNameT checkpointName
= { 16, "checkpoint-sync\0" };
66 SaCkptCheckpointCreationAttributesT checkpointCreationAttributes
= {
67 .creationFlags
= SA_CKPT_WR_ALL_REPLICAS
,
68 .checkpointSize
= 250000,
69 .retentionDuration
= SA_TIME_ONE_SECOND
* 60,
71 .maxSectionSize
= 250000,
72 .maxSectionIdSize
= 10
75 char readBuffer1
[1025];
77 SaCkptIOVectorElementT ReadVectorElements
[] = {
79 SA_CKPT_DEFAULT_SECTION_ID
,
87 #define DATASIZE 127000
89 SaCkptIOVectorElementT WriteVectorElements
[] = {
91 SA_CKPT_DEFAULT_SECTION_ID
,
92 data
, /*"written data #1, this should extend past end of old section data", */
93 DATASIZE
, /*sizeof ("data #1, this should extend past end of old section data") + 1, */
99 SaCkptCallbacksT callbacks
= {
104 #define MAX_DATA_SIZE 100
107 SaCkptHandleT ckptHandle
;
108 SaCkptCheckpointHandleT checkpointHandle
;
110 char data
[MAX_DATA_SIZE
];
111 struct timespec delay
;
112 struct timespec delay2
;
113 SaCkptIOVectorElementT writeElement
;
115 SaUint32T erroroneousVectorIndex
= 0;
120 error
= saCkptInitialize (&ckptHandle
, &callbacks
, &version
);
122 error
= saCkptCheckpointOpen (ckptHandle
,
124 &checkpointCreationAttributes
,
125 SA_CKPT_CHECKPOINT_CREATE
|SA_CKPT_CHECKPOINT_READ
|SA_CKPT_CHECKPOINT_WRITE
,
128 printf ("%s: initial open of checkpoint\n",
129 get_test_output (error
, SA_AIS_OK
));
133 error
= saCkptCheckpointRead (checkpointHandle
,
136 &erroroneousVectorIndex
);
137 if (error
!= SA_AIS_OK
) {
138 if (error
== SA_AIS_ERR_TRY_AGAIN
) {
141 printf ("error is %d\n", error
);
145 if (ReadVectorElements
->dataBuffer
== 0) {
146 printf ("Default Checkpoint has no data\n");
148 count
= atol((char *)ReadVectorElements
->dataBuffer
);
152 sprintf((char*)&data
, "%d",(int)count
);
153 writeElement
.sectionId
= (SaCkptSectionIdT
)SA_CKPT_DEFAULT_SECTION_ID
;
154 writeElement
.dataBuffer
= data
;
155 writeElement
.dataSize
= strlen (data
) + 1;
156 writeElement
.dataOffset
= 0;
157 writeElement
.readSize
= 0;
160 error
= saCkptCheckpointWrite (checkpointHandle
,
163 &erroroneousVectorIndex
);
165 printf ("%s: checkpoint write with data %s\n",
166 get_test_output (error
, SA_AIS_OK
), (char*)data
);
167 }while (error
== SA_AIS_ERR_TRY_AGAIN
);
169 nanosleep(&delay
,&delay2
);