Motr  M0
cookie.h
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 #pragma once
24 
25 #ifndef __MOTR_LIB_COOKIE_H__
26 #define __MOTR_LIB_COOKIE_H__
27 
28 #include "lib/types.h"
29 #include "xcode/xcode.h"
30 
57 struct m0_cookie {
58  uint64_t co_addr;
59  uint64_t co_generation;
60 } M0_XCA_RECORD M0_XCA_DOMAIN(be|rpc);
61 
65 M0_INTERNAL int m0_cookie_global_init(void);
66 
67 M0_INTERNAL void m0_cookie_global_fini(void);
68 
72 M0_INTERNAL void m0_cookie_new(uint64_t * gen);
73 
80 M0_INTERNAL void m0_cookie_init(struct m0_cookie *cookie, const uint64_t *obj);
81 
89 M0_INTERNAL int m0_cookie_dereference(const struct m0_cookie *cookie,
90  uint64_t **addr);
91 
96 M0_INTERNAL bool m0_addr_is_sane(const uint64_t *addr);
97 
103 M0_INTERNAL bool m0_addr_is_sane_and_aligned(const uint64_t *addr);
104 
105 
109 M0_INTERNAL bool m0_cookie_is_null(const struct m0_cookie *cookie);
110 
114 M0_INTERNAL bool m0_cookie_is_eq(const struct m0_cookie *cookie1,
115  const struct m0_cookie *cookie2);
116 
121 #define m0_cookie_of(cookie, type, field) \
122 ({ \
123  uint64_t *__gen; \
124  const struct m0_cookie *__cookie = (cookie); \
125  m0_cookie_dereference(__cookie, &__gen) != 0 ? NULL : \
126  container_of(__gen, type, field); \
127 })
128 
130 /*__M0_LIB_COOKIE_H__*/
131 #endif
132 
133 M0_EXTERN const struct m0_cookie M0_COOKIE_NULL;
134 /*
135  * Local variables:
136  * c-indentation-style: "K&R"
137  * c-basic-offset: 8
138  * tab-width: 8
139  * fill-column: 80
140  * scroll-step: 1
141  * End:
142  */
Definition: beck.c:170
struct m0_ha_cookie_xc M0_XCA_DOMAIN(rpc)
static struct foo * obj
Definition: tlist.c:302
Definition: xcode.h:73
M0_EXTERN const struct m0_cookie M0_COOKIE_NULL
Definition: cookie.h:133
static struct m0_be_ut_backend be
Definition: service_ut.c:59