Motr  M0
bob.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include "xcode/xcode.h"
24 #include "lib/tlist.h"
25 #include "lib/assert.h"
26 #include "lib/bob.h"
27 
34 static bool bob_type_invariant(const struct m0_bob_type *bt)
35 {
36  return
37  _0C(bt->bt_name != NULL) && _0C(*bt->bt_name != '\0') &&
38  _0C(bt->bt_magix != 0);
39 }
40 
41 M0_INTERNAL void m0_bob_type_tlist_init(struct m0_bob_type *bt,
42  const struct m0_tl_descr *td)
43 {
44  M0_PRE(td->td_link_magic != 0);
45 
46  bt->bt_name = td->td_name;
47  bt->bt_magix = td->td_link_magic;
48  bt->bt_magix_offset = td->td_link_magic_offset;
49 
51 }
52 
59 #define MAGIX(bt, bob) ((uint64_t *)(bob + bt->bt_magix_offset))
60 
61 M0_INTERNAL void m0_bob_init(const struct m0_bob_type *bt, void *bob)
62 {
64 
65  *MAGIX(bt, bob) = bt->bt_magix;
66 }
67 
68 M0_INTERNAL void m0_bob_fini(const struct m0_bob_type *bt, void *bob)
69 {
70  M0_ASSERT(m0_bob_check(bt, bob));
71  *MAGIX(bt, bob) = 0;
72 }
73 
74 M0_INTERNAL bool m0_bob_check(const struct m0_bob_type *bt, const void *bob)
75 {
76  return
77  _0C((unsigned long)bob + 4096 > 8192) &&
78  _0C(*MAGIX(bt, bob) == bt->bt_magix) &&
79  ergo(bt->bt_check != NULL, _0C(bt->bt_check(bob)));
80 }
81 
84 /*
85  * Local variables:
86  * c-indentation-style: "K&R"
87  * c-basic-offset: 8
88  * tab-width: 8
89  * fill-column: 80
90  * scroll-step: 1
91  * End:
92  */
#define MAGIX(bt, bob)
Definition: bob.c:59
#define M0_PRE(cond)
int td_link_magic_offset
Definition: tlist.h:215
#define NULL
Definition: misc.h:38
#define ergo(a, b)
Definition: misc.h:293
static bool bob_type_invariant(const struct m0_bob_type *bt)
Definition: bob.c:34
static struct btype bt[]
Definition: beck.c:459
M0_INTERNAL void m0_bob_init(const struct m0_bob_type *bt, void *bob)
Definition: bob.c:61
#define M0_ASSERT(cond)
M0_INTERNAL void m0_bob_fini(const struct m0_bob_type *bt, void *bob)
Definition: bob.c:68
#define M0_POST(cond)
uint64_t td_link_magic
Definition: tlist.h:221
#define _0C(exp)
Definition: assert.h:311
M0_INTERNAL void m0_bob_type_tlist_init(struct m0_bob_type *bt, const struct m0_tl_descr *td)
Definition: bob.c:41
M0_INTERNAL bool m0_bob_check(const struct m0_bob_type *bt, const void *bob)
Definition: bob.c:74
const char * td_name
Definition: tlist.h:206