Motr  M0
seg.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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 #ifndef __MOTR_BE_SEG_H__
25 #define __MOTR_BE_SEG_H__
26 
27 #include "be/alloc.h" /* m0_be_allocator */
28 #include "be/seg_dict.h" /* m0_be_seg_dict_init */ /* XXX */
29 
30 #include "lib/tlist.h" /* m0_tlink */
31 #include "lib/types.h" /* m0_bcount_t */
32 
33 struct m0_be_op;
34 struct m0_be_reg_d;
35 struct m0_stob;
36 struct m0_stob_id;
37 
48 };
49 
50 enum {
60  M0_BE_SEG_PAGE_SIZE = 1ULL << 12,
61 };
62 
63 #define M0_BE_SEG_PG_PRESENT 0x8000000000000000ULL
64 #define M0_BE_SEG_PG_PIN_CNT_MASK (~M0_BE_SEG_PG_PRESENT)
65 
66 struct m0_be_seg {
67  uint64_t bs_id;
68  struct m0_stob *bs_stob;
71  void *bs_addr;
76  uint64_t bs_gen;
83  int bs_state;
84  uint64_t bs_magic;
86 };
87 
88 /* helper for m0_be_seg__create_multiple() */
91  void *sg_addr;
93  uint64_t sg_id;
95  uint64_t sg_gen;
96 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
97 
98 /* this is passed as the last element inside @geom of
99  * m0_be_seg_create_multiple() */
100 #define M0_BE_SEG_GEOM0 \
101  ((struct m0_be_seg_geom) { \
102  .sg_size = (0ULL), \
103  .sg_addr = (NULL), \
104  .sg_offset = (0ULL), \
105  .sg_id = (0ULL) \
106  })
107 
108 M0_INTERNAL bool m0_be_seg_geom_eq(const struct m0_be_seg_geom *left,
109  const struct m0_be_seg_geom *right);
110 
111 M0_INTERNAL int m0_be_seg_create_multiple(struct m0_stob *stob,
112  const struct m0_be_seg_geom *geom);
113 
114 M0_INTERNAL void m0_be_seg_init(struct m0_be_seg *seg,
115  struct m0_stob *stob,
116  struct m0_be_domain *dom,
117  uint64_t seg_id);
118 M0_INTERNAL void m0_be_seg_fini(struct m0_be_seg *seg);
119 M0_INTERNAL bool m0_be_seg__invariant(const struct m0_be_seg *seg);
120 
122 M0_INTERNAL int m0_be_seg_open(struct m0_be_seg *seg);
123 M0_INTERNAL void m0_be_seg_close(struct m0_be_seg *seg);
124 
126 M0_INTERNAL int m0_be_seg_create(struct m0_be_seg *seg,
128  void *addr);
129 
130 M0_INTERNAL int m0_be_seg_destroy(struct m0_be_seg *seg);
131 
132 M0_INTERNAL bool m0_be_seg_contains(const struct m0_be_seg *seg,
133  const void *addr);
134 
135 M0_INTERNAL m0_bindex_t m0_be_seg_offset(const struct m0_be_seg *seg,
136  const void *addr);
137 
139 M0_INTERNAL m0_bcount_t m0_be_seg_reserved(const struct m0_be_seg *seg);
140 M0_INTERNAL struct m0_be_allocator *m0_be_seg_allocator(struct m0_be_seg *seg);
141 
142 struct m0_be_reg {
143  struct m0_be_seg *br_seg;
145  void *br_addr;
146 };
147 
148 #define M0_BE_REG(seg, size, addr) \
149  ((struct m0_be_reg) { \
150  .br_seg = (seg), \
151  .br_size = (size), \
152  .br_addr = (addr) })
153 
154 #define M0_BE_REG_PTR(seg, ptr) M0_BE_REG((seg), sizeof *(ptr), (ptr))
155 #define M0_BE_REG_SEG(seg) M0_BE_REG((seg), (seg)->bs_size, (seg)->bs_addr)
156 
157 M0_INTERNAL m0_bindex_t m0_be_reg_offset(const struct m0_be_reg *reg);
158 
159 M0_INTERNAL bool m0_be_reg_eq(const struct m0_be_reg *r1,
160  const struct m0_be_reg *r2);
161 
165 M0_INTERNAL bool m0_be_reg__invariant(const struct m0_be_reg *reg);
166 
167 /*
168  * XXX Synchronous operations.
169  * m0_be_io and m0_be_op should be be added if necessary.
170  */
171 M0_INTERNAL int m0_be_seg__read(struct m0_be_reg *reg, void *dst);
172 M0_INTERNAL int m0_be_seg__write(struct m0_be_reg *reg, void *src);
173 M0_INTERNAL int m0_be_reg__read(struct m0_be_reg *reg);
174 M0_INTERNAL int m0_be_reg__write(struct m0_be_reg *reg);
175 
185 M0_INTERNAL unsigned long m0_be_reg_gen_idx(const struct m0_be_reg *reg);
186 
187 M0_INTERNAL bool m0_be_seg_contains_stob(struct m0_be_seg *seg,
188  const struct m0_stob_id *stob_id);
189 
191 #endif /* __MOTR_BE_SEG_H__ */
192 
193 /*
194  * Local variables:
195  * c-indentation-style: "K&R"
196  * c-basic-offset: 8
197  * tab-width: 8
198  * fill-column: 80
199  * scroll-step: 1
200  * End:
201  */
202 /*
203  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
204  */
void * bs_addr
Definition: seg.h:71
M0_INTERNAL int m0_be_seg__write(struct m0_be_reg *reg, void *src)
Definition: seg.c:452
struct m0_be_domain * bs_domain
Definition: seg.h:82
uint64_t bs_gen
Definition: seg.h:76
M0_INTERNAL void m0_be_seg_fini(struct m0_be_seg *seg)
Definition: stubs.c:128
M0_INTERNAL m0_bindex_t m0_be_seg_offset(const struct m0_be_seg *seg, const void *addr)
Definition: seg.c:418
static struct m0_bufvec dst
Definition: xform.c:61
M0_INTERNAL int m0_be_seg_create_multiple(struct m0_stob *stob, const struct m0_be_seg_geom *geom)
Definition: seg.c:195
m0_bcount_t bs_offset
Definition: seg.h:70
uint64_t bs_id
Definition: seg.h:67
struct m0_be_allocator bs_allocator
Definition: seg.h:81
M0_INTERNAL void m0_be_seg_init(struct m0_be_seg *seg, struct m0_stob *stob, struct m0_be_domain *dom, uint64_t seg_id)
Definition: stubs.c:118
M0_INTERNAL int m0_be_seg_create(struct m0_be_seg *seg, m0_bcount_t size, void *addr)
Definition: seg.c:224
m0_bcount_t bs_size
Definition: seg.h:69
M0_INTERNAL bool m0_be_seg_contains_stob(struct m0_be_seg *seg, const struct m0_stob_id *stob_id)
Definition: seg.c:484
Allocator.
Definition: alloc.h:132
uint64_t sg_gen
Definition: seg.h:95
M0_INTERNAL int m0_be_reg__write(struct m0_be_reg *reg)
Definition: seg.c:462
m0_bcount_t br_size
Definition: seg.h:144
uint64_t m0_bindex_t
Definition: types.h:80
uint64_t m0_bcount_t
Definition: types.h:77
static int left
Definition: locality.c:280
M0_INTERNAL bool m0_be_seg__invariant(const struct m0_be_seg *seg)
Definition: stubs.c:221
M0_INTERNAL int m0_be_reg__read(struct m0_be_reg *reg)
Definition: seg.c:457
M0_INTERNAL unsigned long m0_be_reg_gen_idx(const struct m0_be_reg *reg)
Definition: seg.c:469
m0_bcount_t bs_reserved
Definition: seg.h:74
bool m0_be_reg__invariant(const struct m0_be_reg *reg)
Definition: seg.c:290
M0_INTERNAL void m0_be_seg_close(struct m0_be_seg *seg)
Definition: stubs.c:140
m0_bcount_t sg_offset
Definition: seg.h:92
M0_INTERNAL m0_bcount_t m0_be_seg_reserved(const struct m0_be_seg *seg)
Definition: seg.c:430
struct m0_be_reg M0_XCA_DOMAIN
Definition: stob.h:163
static struct m0_stob * stob
Definition: storage.c:39
M0_INTERNAL int m0_be_seg__read(struct m0_be_reg *reg, void *dst)
Definition: seg.c:447
M0_INTERNAL struct m0_be_allocator * m0_be_seg_allocator(struct m0_be_seg *seg)
Definition: stubs.c:113
static struct m0_stob_domain * dom
Definition: storage.c:38
void * sg_addr
Definition: seg.h:91
Definition: xcode.h:73
Definition: seg.h:66
Definition: seg.h:142
M0_INTERNAL bool m0_be_reg_eq(const struct m0_be_reg *r1, const struct m0_be_reg *r2)
Definition: seg.c:410
M0_INTERNAL bool m0_be_seg_contains(const struct m0_be_seg *seg, const void *addr)
Definition: stubs.c:144
m0_bcount_t sg_size
Definition: seg.h:90
struct m0_tlink bs_linkage
Definition: seg.h:85
int bs_state
Definition: seg.h:83
M0_INTERNAL m0_bindex_t m0_be_reg_offset(const struct m0_be_reg *reg)
Definition: seg.c:425
M0_INTERNAL int m0_be_seg_destroy(struct m0_be_seg *seg)
Definition: seg.c:243
m0_bcount_t size
Definition: di.c:39
m0_be_seg_states
Definition: seg.h:44
M0_INTERNAL bool m0_be_seg_geom_eq(const struct m0_be_seg_geom *left, const struct m0_be_seg_geom *right)
Definition: seg.c:150
M0_INTERNAL int m0_be_seg_open(struct m0_be_seg *seg)
Definition: stubs.c:132
static struct m0_be_seg * seg
Definition: btree.c:40
struct m0_stob * bs_stob
Definition: seg.h:68
uint64_t bs_magic
Definition: seg.h:84
uint64_t sg_id
Definition: seg.h:93
Definition: op.h:74
struct m0_be_seg * br_seg
Definition: seg.h:143
void * br_addr
Definition: seg.h:145
struct m0_pdclust_src_addr src
Definition: fd.c:108
static struct m0_be_ut_backend be
Definition: service_ut.c:59