Motr  M0
format.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 #pragma once
22 #ifndef __MOTR_FORMAT_FORMAT_H__
23 #define __MOTR_FORMAT_FORMAT_H__
24 
25 #include "lib/types.h" /* uint64_t */
26 #include "lib/misc.h" /* M0_FIELD_VALUE */
27 #include "lib/mutex.h"
28 #include "lib/rwlock.h"
29 #include "lib/chan.h" /* m0_clink */
30 
43  uint64_t hd_magic;
53  uint64_t hd_bits;
54 } M0_XCA_RECORD M0_XCA_DOMAIN(be|rpc);
55 
58  uint64_t ft_magic;
59  uint64_t ft_checksum;
60 } M0_XCA_RECORD M0_XCA_DOMAIN(be|rpc);
61 
62 struct m0_format_tag {
63  uint16_t ot_version;
64  uint16_t ot_type;
65  union {
66  /*
67  * these are aliases to support different semantics of this
68  * field:
69  *
70  * size - can be used when header and footer don't belong
71  * to the same container struct
72  * offset - can be used when header and footer contained
73  * withing the same struct
74  */
75  uint32_t ot_size;
76  uint32_t ot_footer_offset;
77  /* NOTE: size and offset measured in bytes */
78  };
79 };
80 
83  /*
84  * ORDER MATTERS!!!
85  * Never rearrange items, add new at the end before placeholder
86  */
111 
112  /* ---> new items go here <--- */
113 
114  /* format types counter */
116 } M0_XCA_ENUM;
117 
118 /* format type IDs should fit into m0_format_tag::ot_type */
120 
121 M0_INTERNAL void m0_format_header_pack(struct m0_format_header *dest,
122  const struct m0_format_tag *src);
123 
124 M0_INTERNAL void m0_format_header_unpack(struct m0_format_tag *dest,
125  const struct m0_format_header *src);
126 
127 M0_INTERNAL void m0_format_footer_generate(struct m0_format_footer *footer,
128  const void *buffer,
129  uint32_t size);
130 
137 M0_INTERNAL void m0_format_footer_update(const void *buffer);
138 
151  const struct m0_format_footer *footer,
152  const void *buffer,
153  uint32_t size,
154  bool iem);
155 
168 M0_INTERNAL int m0_format_footer_verify(const void *buffer, bool iem);
169 
170 #ifdef FORMAT_BE_STRUCT_CONVERTED
172 /*
173  * Kernel doesn't store BE structure to a persistent storage. Therefore,
174  * padding doesn't have to be the same for kernelspace and ondisk format.
175  * Formula is the next: actual size of original structure plus ~20%.
176  * Numbers are calculated for debug kernel.
177  */
178 #ifdef __KERNEL__
179 #define M0_BE_MUTEX_PAD (184 + 56)
180 #define M0_BE_RWLOCK_PAD (144 + 48)
181 #define M0_BE_CLINK_PAD (152 + 48)
182 #else
183 #define M0_BE_MUTEX_PAD (56 + 16)
184 #define M0_BE_RWLOCK_PAD (56 + 16)
185 #define M0_BE_CLINK_PAD (88 + 24)
186 #endif /* __KERNEL__ */
187 
188 #else /* !FORMAT_BE_STRUCT_CONVERTED */
189 
190 /* These values are for "teacake" compatibility. */
191 #define M0_BE_MUTEX_PAD 168
192 #define M0_BE_RWLOCK_PAD 144
193 #define M0_BE_CLINK_PAD sizeof(struct m0_clink)
194 
195 #endif /* FORMAT_BE_STRUCT_CONVERTED */
196 
197 struct m0_be_mutex {
198  union {
199  struct m0_mutex mutex;
201  } bm_u;
203 M0_BASSERT(sizeof(struct m0_mutex) <=
204  sizeof(M0_FIELD_VALUE(struct m0_be_mutex, bm_u.pad)));
206 struct m0_be_rwlock {
207  union {
210  } bl_u;
212 M0_BASSERT(sizeof(struct m0_rwlock) <=
213  sizeof(M0_FIELD_VALUE(struct m0_be_rwlock, bl_u.pad)));
215 struct m0_be_clink {
216  union {
217  struct m0_clink clink;
219  } bc_u;
221 M0_BASSERT(sizeof(struct m0_clink) <=
222  sizeof(M0_FIELD_VALUE(struct m0_be_clink, bc_u.pad)));
223 
224 struct m0_be_chan {
227 
229 #endif /* __MOTR_FORMAT_FORMAT_H__ */
230 
231 /*
232  * Local variables:
233  * c-indentation-style: "K&R"
234  * c-basic-offset: 8
235  * tab-width: 8
236  * fill-column: 80
237  * scroll-step: 1
238  * End:
239  */
240 /*
241  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
242  */
M0_INTERNAL void m0_format_footer_generate(struct m0_format_footer *footer, const void *buffer, uint32_t size)
Definition: format.c:59
char pad[M0_BE_MUTEX_PAD]
Definition: format.h:200
char pad[M0_BE_RWLOCK_PAD]
Definition: format.h:209
#define M0_XCA_BLOB
Definition: xcode_attr.h:53
M0_INTERNAL void m0_format_header_pack(struct m0_format_header *dest, const struct m0_format_tag *src)
Definition: format.c:40
M0_INTERNAL void m0_format_header_unpack(struct m0_format_tag *dest, const struct m0_format_header *src)
Definition: format.c:49
uint64_t hd_bits
Definition: format.h:53
union @197 bm_u
#define M0_FIELD_VALUE(type, field)
Definition: misc.h:339
union m0_be_rwlock::@198 bl_u
struct m0_rwlock rwlock
Definition: format.h:208
uint32_t ot_size
Definition: format.h:75
m0_format_type
Definition: format.h:82
union m0_be_mutex::@196 bm_u
uint16_t ot_version
Definition: format.h:63
union @199 bl_u
#define M0_BE_MUTEX_PAD
Definition: format.h:191
#define UINT16_MAX
Definition: types.h:38
#define M0_BE_CLINK_PAD
Definition: format.h:193
struct m0_chan bch_chan
Definition: format.h:225
M0_INTERNAL int m0_format_footer_verify_generic(const struct m0_format_footer *footer, const void *buffer, uint32_t size, bool iem)
Definition: format.c:125
enum m0_format_type M0_XCA_ENUM
uint32_t ot_footer_offset
Definition: format.h:76
uint64_t hd_magic
Definition: format.h:43
Definition: chan.h:229
M0_INTERNAL int m0_format_footer_verify(const void *buffer, bool iem)
Definition: format.c:149
struct m0_format_tag M0_XCA_DOMAIN
uint16_t ot_type
Definition: format.h:64
M0_INTERNAL void m0_format_footer_update(const void *buffer)
Definition: format.c:95
Definition: addb2.c:200
m0_bcount_t size
Definition: di.c:39
union @201 bc_u
M0_BASSERT(M0_FORMAT_TYPE_NR< UINT16_MAX)
Definition: mutex.h:47
struct m0_pdclust_src_addr src
Definition: fd.c:108
struct m0_mutex mutex
Definition: format.h:199
static struct m0_be_ut_backend be
Definition: service_ut.c:59
#define M0_BE_RWLOCK_PAD
Definition: format.h:192