ckpt-rd.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #define _BSD_SOURCE
  2. /*
  3. * Copyright (c) 2002-2004 MontaVista Software, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@mvista.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <errno.h>
  38. #include <unistd.h>
  39. #include <sys/types.h>
  40. #include <sys/socket.h>
  41. #include <sys/select.h>
  42. #include <sys/un.h>
  43. #include <sys/time.h>
  44. #include "ais_types.h"
  45. #include "saCkpt.h"
  46. #include "sa_error.h"
  47. #define SECONDS_TO_EXPIRE 4
  48. int ckptinv;
  49. void printSaNameT (SaNameT *name)
  50. {
  51. int i;
  52. for (i = 0; i < name->length; i++) {
  53. printf ("%c", name->value[i]);
  54. }
  55. }
  56. SaVersionT version = { 'B', 1, 1 };
  57. SaNameT checkpointName = { 16, "checkpoint-sync\0" };
  58. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
  59. SA_CKPT_WR_ALL_REPLICAS,
  60. 100000,
  61. 5000000000LL,
  62. 5,
  63. 20000,
  64. 10
  65. };
  66. SaCkptSectionIdT sectionId1 = {
  67. 14,
  68. "section ID #1"
  69. };
  70. SaCkptSectionIdT sectionId2 = {
  71. 14,
  72. "section ID #2"
  73. };
  74. SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
  75. &sectionId1,
  76. SA_TIME_END
  77. };
  78. SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
  79. &sectionId2,
  80. SA_TIME_END
  81. };
  82. char readBuffer1[1025];
  83. char readBuffer2[1025];
  84. SaCkptIOVectorElementT ReadVectorElements[] = {
  85. {
  86. {
  87. 14,
  88. "section ID #1"
  89. },
  90. readBuffer1,
  91. sizeof (readBuffer1),
  92. 0,
  93. 0
  94. },
  95. {
  96. {
  97. 14,
  98. "section ID #2"
  99. },
  100. readBuffer2,
  101. sizeof (readBuffer2),
  102. 0,
  103. 0
  104. }
  105. };
  106. #define DATASIZE 127000
  107. char data[DATASIZE];
  108. SaCkptCallbacksT callbacks = {
  109. 0,
  110. 0
  111. };
  112. int main (void) {
  113. SaCkptHandleT ckptHandle;
  114. SaCkptCheckpointHandleT checkpointHandle;
  115. SaAisErrorT error;
  116. SaUint32T erroroneousVectorIndex = 0;
  117. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  118. error = saCkptCheckpointOpen (ckptHandle,
  119. &checkpointName,
  120. &checkpointCreationAttributes,
  121. SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  122. 0,
  123. &checkpointHandle);
  124. printf ("%s: initial open of checkpoint\n",
  125. get_test_output (error, SA_AIS_OK));
  126. error = saCkptSectionCreate (checkpointHandle,
  127. &sectionCreationAttributes1,
  128. "Initial Data #0",
  129. strlen ("Initial Data #0") + 1);
  130. error = saCkptCheckpointRead (checkpointHandle,
  131. ReadVectorElements,
  132. 1,
  133. &erroroneousVectorIndex);
  134. printf ("%s: read checkpoint\n",
  135. get_test_output (error, SA_AIS_OK));
  136. printf ("Checkpoint contains %s\n", (char *)ReadVectorElements->dataBuffer);
  137. return (0);
  138. }