mar_ckpt.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * Copyright (C) 2006 Red Hat, 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. #ifndef AIS_MAR_CKPT_H_DEFINED
  35. #define AIS_MAR_CKPT_H_DEFINED
  36. #include "saAis.h"
  37. #include "saCkpt.h"
  38. #include "mar_gen.h"
  39. typedef mar_uint64_t mar_ckpt_checkpoint_handle_t;
  40. static inline void swab_mar_ckpt_checkpoint_handle_t (
  41. mar_ckpt_checkpoint_handle_t *to_swab)
  42. {
  43. swab_mar_uint64_t (to_swab);
  44. }
  45. typedef mar_uint32_t mar_ckpt_checkpoint_creation_flags_t;
  46. static inline void swab_mar_ckpt_checkpoint_creation_flags_t (
  47. mar_ckpt_checkpoint_creation_flags_t *to_swab)
  48. {
  49. swab_mar_uint32_t (to_swab);
  50. }
  51. /*
  52. * Marshalling the SaCkptCheckpointCreationAttributesT data structure
  53. */
  54. typedef struct {
  55. mar_ckpt_checkpoint_creation_flags_t creation_flags __attribute__((aligned(8)));
  56. mar_size_t checkpoint_size __attribute__((aligned(8)));
  57. mar_time_t retention_duration __attribute__((aligned(8)));
  58. mar_uint32_t max_sections __attribute__((aligned(8)));
  59. mar_size_t max_section_size __attribute__((aligned(8)));
  60. mar_size_t max_section_id_size __attribute__((aligned(8)));
  61. } mar_ckpt_checkpoint_creation_attributes_t;
  62. static inline void swab_mar_ckpt_checkpoint_creation_attributes_t (
  63. mar_ckpt_checkpoint_creation_attributes_t *to_swab)
  64. {
  65. swab_mar_ckpt_checkpoint_creation_flags_t (&to_swab->creation_flags);
  66. swab_mar_size_t (&to_swab->checkpoint_size);
  67. swab_mar_time_t (&to_swab->retention_duration);
  68. swab_mar_uint32_t (&to_swab->max_sections);
  69. swab_mar_size_t (&to_swab->max_section_size);
  70. swab_mar_size_t (&to_swab->max_section_id_size);
  71. }
  72. static inline void marshall_from_mar_ckpt_checkpoint_creation_attributes_t (
  73. SaCkptCheckpointCreationAttributesT *dest,
  74. mar_ckpt_checkpoint_creation_attributes_t *src)
  75. {
  76. dest->creationFlags = src->creation_flags;
  77. dest->checkpointSize = src->checkpoint_size;
  78. dest->retentionDuration = src->retention_duration;
  79. dest->maxSections = src->max_sections;
  80. dest->maxSectionSize = src->max_section_size;
  81. dest->maxSectionIdSize = src->max_section_id_size;
  82. }
  83. static inline void marshall_to_mar_ckpt_checkpoint_creation_attributes_t (
  84. mar_ckpt_checkpoint_creation_attributes_t *dest,
  85. SaCkptCheckpointCreationAttributesT *src)
  86. {
  87. memset (dest, 0, sizeof (mar_ckpt_checkpoint_creation_attributes_t));
  88. dest->creation_flags = src->creationFlags;
  89. dest->checkpoint_size = src->checkpointSize;
  90. dest->retention_duration = src->retentionDuration;
  91. dest->max_sections = src->maxSections;
  92. dest->max_section_size = src->maxSectionSize;
  93. dest->max_section_id_size = src->maxSectionIdSize;
  94. }
  95. #define MAR_CKPT_CHECKPOINT_READ 0x1
  96. #define MAR_CKPT_CHECKPOINT_WRITE 0x2
  97. #define MAR_CKPT_CHECKPOINT_CREATE 0x4
  98. typedef mar_uint32_t mar_ckpt_checkpoint_open_flags_t;
  99. static inline void swab_mar_ckpt_checkpoint_open_flags_t (mar_ckpt_checkpoint_open_flags_t *to_swab)
  100. {
  101. swab_mar_uint32_t (to_swab);
  102. }
  103. #define MAR_CKPT_DEFAULT_SECTION_ID { 0, 0 }
  104. #define MAR_CKPT_GENERATED_SECTION_ID { 0, 0 }
  105. /*
  106. * Marshalling the SaCkptSectionIdT data structure
  107. */
  108. typedef struct {
  109. mar_uint16_t id_len __attribute__((aligned(8)));
  110. mar_uint8_t *id __attribute__((aligned(8)));
  111. } mar_ckpt_section_id_t;
  112. static inline void swab_mar_ckpt_section_id_t (mar_ckpt_section_id_t *to_swab)
  113. {
  114. swab_mar_uint16_t (&to_swab->id_len);
  115. }
  116. static inline void marshall_from_mar_ckpt_section_id_t (
  117. SaCkptSectionIdT *dest,
  118. mar_ckpt_section_id_t *src)
  119. {
  120. dest->idLen = src->id_len;
  121. dest->id = src->id;
  122. }
  123. static inline void marshall_to_mar_ckpt_section_id_t (
  124. mar_ckpt_section_id_t *dest,
  125. SaCkptSectionIdT *src)
  126. {
  127. memset (dest, 0, sizeof (mar_ckpt_section_id_t));
  128. dest->id_len = src->idLen;
  129. dest->id = src->id;
  130. }
  131. /*
  132. * Marshalling the SaCkptSectionCreationAttributesT data structure
  133. */
  134. typedef struct {
  135. mar_ckpt_section_id_t *section_id __attribute__((aligned(8)));
  136. mar_time_t expiration_time __attribute__((aligned(8)));
  137. } mar_ckpt_section_creation_attributes_t;
  138. static inline void swab_mar_ckpt_section_creation_attributes_t (
  139. mar_ckpt_section_creation_attributes_t *to_swab)
  140. {
  141. swab_mar_ckpt_section_id_t (to_swab->section_id);
  142. swab_mar_time_t (&to_swab->expiration_time);
  143. }
  144. static inline void marshall_from_mar_ckpt_section_creation_attributes_t (
  145. SaCkptSectionCreationAttributesT *dest,
  146. mar_ckpt_section_creation_attributes_t *src)
  147. {
  148. marshall_from_mar_ckpt_section_id_t (dest->sectionId, src->section_id);
  149. dest->expirationTime = src->expiration_time;
  150. }
  151. static inline void marshall_to_mar_ckpt_section_creation_attributes_t (
  152. mar_ckpt_section_creation_attributes_t *dest,
  153. SaCkptSectionCreationAttributesT *src)
  154. {
  155. memset (dest, 0, sizeof (mar_ckpt_section_creation_attributes_t));
  156. marshall_to_mar_ckpt_section_id_t (dest->section_id, src->sectionId);
  157. dest->expiration_time = src->expirationTime;
  158. }
  159. typedef mar_uint32_t mar_ckpt_section_state_t;
  160. #define MAR_CKPT_SECTION_VALID 1
  161. #define MAR_CKPT_SECTION_CORRUPTED 2
  162. static inline void swab_mar_ckpt_section_state_t (
  163. mar_ckpt_section_state_t *to_swab)
  164. {
  165. swab_mar_uint32_t (to_swab);
  166. }
  167. /*
  168. * Marshalling the SaCkptSectionDescriptorT data structure
  169. */
  170. typedef struct {
  171. mar_ckpt_section_id_t section_id __attribute__((aligned(8)));
  172. mar_time_t expiration_time __attribute__((aligned(8)));
  173. mar_size_t section_size __attribute__((aligned(8)));
  174. mar_ckpt_section_state_t section_state __attribute__((aligned(8)));
  175. mar_time_t last_update __attribute__((aligned(8)));
  176. } mar_ckpt_section_descriptor_t;
  177. static inline void swab_mar_ckpt_section_descriptor_t (
  178. mar_ckpt_section_descriptor_t *to_swab)
  179. {
  180. swab_mar_ckpt_section_id_t (&to_swab->section_id);
  181. swab_mar_time_t (&to_swab->expiration_time);
  182. swab_mar_size_t (&to_swab->section_size);
  183. swab_mar_ckpt_section_state_t (&to_swab->section_state);
  184. swab_mar_time_t (&to_swab->last_update);
  185. }
  186. static inline void marshall_from_mar_ckpt_section_descriptor_t (
  187. SaCkptSectionDescriptorT *dest,
  188. mar_ckpt_section_descriptor_t *src)
  189. {
  190. marshall_from_mar_ckpt_section_id_t (&dest->sectionId, &src->section_id);
  191. dest->expirationTime = src->expiration_time;
  192. dest->sectionSize = src->section_size;
  193. dest->sectionState = src->section_state;
  194. dest->lastUpdate = src->last_update;
  195. }
  196. static inline void marshall_to_mar_ckpt_section_descriptor_t (
  197. mar_ckpt_section_descriptor_t *dest,
  198. SaCkptSectionDescriptorT *src)
  199. {
  200. memset (dest, 0, sizeof (mar_ckpt_section_descriptor_t));
  201. marshall_to_mar_ckpt_section_id_t (&dest->section_id, &src->sectionId);
  202. dest->expiration_time = src->expirationTime;
  203. dest->section_size = src->sectionSize;
  204. dest->section_state = src->sectionState;
  205. dest->last_update = src->lastUpdate;
  206. }
  207. typedef enum {
  208. MAR_CKPT_SECTIONS_FOREVER = 1,
  209. MAR_CKPT_SECTIONS_LEQ_EXPIRATION_TIME = 2,
  210. MAR_CKPT_SECTIONS_GEQ_EXPIRATION_TIME = 3,
  211. MAR_CKPT_SECTIONS_CORRUPTED = 4,
  212. MAR_CKPT_SECTIONS_ANY = 5
  213. } mar_ckpt_sections_chosen_t;
  214. typedef mar_uint64_t mar_offset_t;
  215. static inline void swab_mar_offset_t (
  216. mar_offset_t *to_swab)
  217. {
  218. swab_mar_uint64_t (to_swab);
  219. }
  220. /*
  221. * Marshalling the SaCkptIOVectorElementT (not needed)
  222. */
  223. typedef struct {
  224. mar_ckpt_section_id_t section_id __attribute__((aligned(8)));
  225. void *data_buffer __attribute__((aligned(8)));
  226. mar_size_t data_size __attribute__((aligned(8)));
  227. mar_offset_t data_offset __attribute__((aligned(8)));
  228. mar_size_t read_size __attribute__((aligned(8)));
  229. } mar_ckpt_io_vector_element_t;
  230. /*
  231. * Marshalling the SaCkptCheckpointDescriptorT
  232. */
  233. typedef struct {
  234. mar_ckpt_checkpoint_creation_attributes_t checkpoint_creation_attributes __attribute__((aligned(8)));
  235. mar_uint32_t number_of_sections __attribute__((aligned(8)));
  236. mar_uint32_t memory_used __attribute__((aligned(8)));
  237. } mar_ckpt_checkpoint_descriptor_t;
  238. static inline void marshall_from_mar_ckpt_checkpoint_descriptor_t (
  239. SaCkptCheckpointDescriptorT *dest,
  240. mar_ckpt_checkpoint_descriptor_t *src)
  241. {
  242. marshall_from_mar_ckpt_checkpoint_creation_attributes_t (
  243. &dest->checkpointCreationAttributes,
  244. &src->checkpoint_creation_attributes);
  245. dest->numberOfSections = src->number_of_sections;
  246. dest->memoryUsed = src->memory_used;
  247. }
  248. static inline void marshall_to_mar_ckpt_checkpoint_descriptor_t (
  249. mar_ckpt_checkpoint_descriptor_t *dest,
  250. SaCkptCheckpointDescriptorT *src)
  251. {
  252. memset (dest, 0, sizeof (mar_ckpt_checkpoint_descriptor_t));
  253. marshall_to_mar_ckpt_checkpoint_creation_attributes_t (
  254. &dest->checkpoint_creation_attributes,
  255. &src->checkpointCreationAttributes);
  256. dest->number_of_sections = src->numberOfSections;
  257. dest->memory_used = src->memoryUsed;
  258. }
  259. #endif /* AIS_MAR_CKPT_H_DEFINED */