Motr  M0
utils.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2016-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 "motr/client.h"
24 #include "motr/pg.h"
25 #include "motr/io.h"
26 #include "lib/trace.h" /* M0_LOG */
27 #include "lib/finject.h" /* M0_FI_ENABLE */
28 
29 M0_INTERNAL bool addr_is_network_aligned(void *addr)
30 {
31  return ((uint64_t)addr & M0_NETBUF_MASK) == 0;
32 }
33 
34 M0_INTERNAL uint64_t obj_buffer_size(const struct m0_obj *obj)
35 {
36  M0_PRE(obj != NULL);
37 
38  return 1ULL<<obj->ob_attr.oa_bshift;
39 }
40 
41 M0_INTERNAL uint64_t m0__page_size(const struct m0_op_io *ioo)
42 {
43  M0_PRE(ioo != NULL);
44  M0_PRE(ioo->ioo_obj != NULL);
45 
46  return obj_buffer_size(ioo->ioo_obj);
47 }
48 
49 M0_INTERNAL uint64_t page_nr(m0_bcount_t size, struct m0_obj *obj)
50 {
51  M0_PRE(obj != NULL);
52  M0_PRE(obj->ob_attr.oa_bshift >= M0_MIN_BUF_SHIFT);
53 
54  return size >> obj->ob_attr.oa_bshift;
55 }
56 
57 M0_INTERNAL uint32_t layout_n(struct m0_pdclust_layout *play)
58 {
59  M0_PRE(play != NULL);
60 
61  return play->pl_attr.pa_N;
62 }
63 
64 M0_INTERNAL uint32_t layout_k(struct m0_pdclust_layout *play)
65 {
66  M0_PRE(play != NULL);
67 
68  return play->pl_attr.pa_K;
69 }
70 
72 M0_INTERNAL uint64_t page_id(m0_bindex_t offset, struct m0_obj *obj)
73 {
74  M0_PRE(obj != NULL);
75  M0_PRE(obj->ob_attr.oa_bshift >= M0_MIN_BUF_SHIFT);
76 
77  return offset >> obj->ob_attr.oa_bshift;
78 }
79 
80 M0_INTERNAL uint64_t layout_unit_size(struct m0_pdclust_layout *play)
81 {
82  M0_PRE(play != NULL);
83 
84  return play->pl_attr.pa_unit_size;
85 }
86 
87 M0_INTERNAL uint32_t rows_nr(struct m0_pdclust_layout *play, struct m0_obj *obj)
88 {
89  M0_PRE(play != NULL);
90  M0_PRE(obj != NULL);
91 
92  return page_nr(layout_unit_size(play), obj);
93 }
94 
95 M0_INTERNAL uint64_t data_size(struct m0_pdclust_layout *play)
96 {
97  M0_PRE(play != NULL);
98 
99  return layout_n(play) * layout_unit_size(play);
100 }
101 
102 M0_INTERNAL struct m0_pdclust_instance *
104 {
105  M0_PRE(li != NULL);
106 
107  return m0_layout_instance_to_pdi(li);
108 }
109 
110 M0_INTERNAL struct m0_pdclust_layout *
111 pdlayout_get(const struct m0_op_io *ioo)
112 {
114 }
115 
116 M0_INTERNAL struct m0_layout_instance *
117 layout_instance(const struct m0_op_io *ioo)
118 {
119  M0_PRE(ioo != NULL);
120 
121  return ioo->ioo_oo.oo_layout_instance;
122 }
123 
124 M0_INTERNAL struct m0_parity_math *parity_math(struct m0_op_io *ioo)
125 {
127 }
128 
129 M0_INTERNAL uint64_t target_offset(uint64_t frame,
130  struct m0_pdclust_layout *play,
131  m0_bindex_t gob_offset)
132 {
133  M0_PRE(play != NULL);
134 
135  return frame * layout_unit_size(play) +
136  (gob_offset % layout_unit_size(play));
137 }
138 
139 M0_INTERNAL uint64_t group_id(m0_bindex_t index, m0_bcount_t dtsize)
140 {
141  /* XXX add any PRE()? => update UTs */
142  return index / dtsize;
143 }
144 
145 M0_INTERNAL m0_bcount_t seg_endpos(const struct m0_indexvec *ivec, uint32_t i)
146 {
147  M0_PRE(ivec != NULL);
148 
149  return ivec->iv_index[i] + ivec->iv_vec.v_count[i];
150 }
151 
152 M0_INTERNAL uint64_t indexvec_page_nr(const struct m0_vec *vec,
153  struct m0_obj *obj)
154 {
155  M0_PRE(vec != NULL);
156  M0_PRE(obj != NULL);
157 
158  return page_nr(m0_vec_count(vec), obj);
159 }
160 
161 M0_INTERNAL uint64_t iomap_page_nr(const struct pargrp_iomap *map)
162 {
163  M0_PRE(map != NULL);
164 
165  return indexvec_page_nr(&map->pi_ivec.iv_vec, map->pi_ioo->ioo_obj);
166 }
167 
168 M0_INTERNAL uint64_t parity_units_page_nr(struct m0_pdclust_layout *play,
169  struct m0_obj *obj)
170 {
171  M0_PRE(play != NULL);
172  M0_PRE(obj != NULL);
173 
174  return page_nr(layout_unit_size(play), obj) * layout_k(play);
175 }
176 
177 #if !defined(round_down)
178 M0_INTERNAL uint64_t round_down(uint64_t val, uint64_t size)
179 {
181 
182  /*
183  * Returns current value if it is already a multiple of size,
184  * else m0_round_down() is invoked.
185  */
186  return (val & (size - 1)) == 0 ?
188 }
189 #endif
190 
191 #if !defined(round_up)
192 M0_INTERNAL uint64_t round_up(uint64_t val, uint64_t size)
193 {
195 
196  /*
197  * Returns current value if it is already a multiple of size,
198  * else m0_round_up() is invoked.
199  */
200  return (val & (size - 1)) == 0 ?
201  val : m0_round_up(val, size);
202 }
203 #endif
204 
205 M0_INTERNAL uint32_t io_desc_size(struct m0_net_domain *ndom)
206 {
207  M0_PRE(ndom != NULL);
208 
209  return
210  /* size of variables ci_nr and nbd_len */
213 
214  /* size of nbd_data */
216 }
217 
218 M0_INTERNAL uint32_t io_seg_size(void)
219 {
220  return sizeof(struct m0_ioseg);
221 }
222 
224 M0_INTERNAL void page_pos_get(struct pargrp_iomap *map,
226  m0_bindex_t grp_off,
227  uint32_t *row,
228  uint32_t *col)
229 {
230  uint64_t pg_id;
231  struct m0_obj *obj;
232  struct m0_pdclust_layout *play;
233 
234  M0_PRE(map != NULL);
235  M0_PRE(row != NULL);
236  M0_PRE(col != NULL);
237 
238  obj = map->pi_ioo->ioo_obj;
239  play = pdlayout_get(map->pi_ioo);
240 
241  pg_id = page_id(index - grp_off, obj);
242  *row = pg_id % rows_nr(play, obj);
243  *col = play->pl_attr.pa_K == 0 ? 0 : pg_id / rows_nr(play, obj);
244 }
245 
247  uint32_t row,
248  uint32_t col)
249 {
250  struct m0_pdclust_layout *play;
251  struct m0_op_io *ioo;
253 
254  M0_PRE(map != NULL);
255 
256  ioo = map->pi_ioo;
257  play = pdlayout_get(ioo);
258 
259  M0_PRE(row < rows_nr(play, ioo->ioo_obj));
260  M0_PRE(col < layout_n(play));
261 
262  out = data_size(play) * map->pi_grpid +
263  col * layout_unit_size(play) + row * m0__page_size(ioo);
264 
265  return out;
266 }
267 
268 M0_INTERNAL uint32_t ioreq_sm_state(const struct m0_op_io *ioo)
269 {
270  M0_PRE(ioo != NULL);
271 
272  return ioo->ioo_sm.sm_state;
273 }
274 
275 M0_INTERNAL uint64_t tolerance_of_level(struct m0_op_io *ioo, uint64_t lv)
276 {
277  struct m0_pdclust_instance *play_instance;
278  struct m0_pool_version *pver;
279 
281 
282  if (M0_FI_ENABLED("fake_tolerance_of_level"))
283  return 0;
284 
285  play_instance = pdlayout_instance(layout_instance(ioo));
286  pver = play_instance->pi_base.li_l->l_pver;
287  return pver->pv_fd_tol_vec[lv];
288 }
289 
290 M0_INTERNAL bool m0__is_update_op(struct m0_op *op)
291 {
292  return M0_IN(op->op_code, (M0_OC_WRITE,
293  M0_OC_FREE));
294 }
295 
296 M0_INTERNAL bool m0__is_read_op(struct m0_op *op)
297 {
298  return op->op_code == M0_OC_READ;
299 }
300 
301 M0_INTERNAL struct m0_obj_attr *
302 m0_io_attr(struct m0_op_io *ioo)
303 {
304  return &ioo->ioo_obj->ob_attr;
305 }
306 
307 /*
308  * Local variables:
309  * c-indentation-style: "K&R"
310  * c-basic-offset: 8
311  * tab-width: 8
312  * fill-column: 80
313  * scroll-step: 1
314  * End:
315  */
316 /*
317  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
318  */
M0_INTERNAL uint64_t data_size(struct m0_pdclust_layout *play)
Definition: utils.c:95
M0_INTERNAL uint64_t obj_buffer_size(const struct m0_obj *obj)
Definition: utils.c:34
#define M0_PRE(cond)
Definition: client.h:788
struct m0_layout * li_l
Definition: layout.h:590
#define NULL
Definition: misc.h:38
map
Definition: processor.c:112
uint64_t pa_unit_size
Definition: pdclust.h:118
struct m0_pool_version * l_pver
Definition: layout.h:261
Definition: idx_mock.c:52
M0_INTERNAL struct m0_layout_instance * layout_instance(const struct m0_op_io *ioo)
Definition: utils.c:117
Definition: storage.c:103
uint32_t ci_nr
Definition: vec.h:618
#define M0_MEMBER_SIZE(type, member)
Definition: misc.h:62
M0_INTERNAL m0_bcount_t seg_endpos(const struct m0_indexvec *ivec, uint32_t i)
Definition: utils.c:145
uint32_t pa_N
Definition: pdclust.h:104
M0_INTERNAL uint64_t iomap_page_nr(const struct pargrp_iomap *map)
Definition: utils.c:161
M0_INTERNAL uint32_t rows_nr(struct m0_pdclust_layout *play, struct m0_obj *obj)
Definition: utils.c:87
struct m0_layout_instance pi_base
Definition: pdclust.h:173
uint32_t pa_K
Definition: pdclust.h:107
static bool m0_is_po2(uint64_t val)
Definition: arith.h:153
Definition: vec.h:49
uint32_t nbd_len
M0_INTERNAL uint64_t layout_unit_size(struct m0_pdclust_layout *play)
Definition: utils.c:80
uint64_t m0_bindex_t
Definition: types.h:80
M0_INTERNAL uint64_t m0__page_size(const struct m0_op_io *ioo)
Definition: utils.c:41
M0_INTERNAL uint32_t layout_n(struct m0_pdclust_layout *play)
Definition: utils.c:57
uint64_t m0_bcount_t
Definition: types.h:77
M0_INTERNAL uint64_t group_id(m0_bindex_t index, m0_bcount_t dtsize)
Definition: utils.c:139
M0_INTERNAL uint64_t target_offset(uint64_t frame, struct m0_pdclust_layout *play, m0_bindex_t gob_offset)
Definition: utils.c:129
M0_INTERNAL bool m0__is_read_op(struct m0_op *op)
Definition: utils.c:296
M0_INTERNAL bool m0__is_update_op(struct m0_op *op)
Definition: utils.c:290
struct m0_pdclust_attr pl_attr
Definition: pdclust.h:150
M0_INTERNAL uint32_t layout_k(struct m0_pdclust_layout *play)
Definition: utils.c:64
static struct foo * obj
Definition: tlist.c:302
M0_INTERNAL uint64_t page_id(m0_bindex_t offset, struct m0_obj *obj)
Definition: utils.c:72
M0_INTERNAL uint64_t m0_round_up(uint64_t val, uint64_t size)
Definition: misc.c:181
struct m0_sm ioo_sm
M0_INTERNAL uint64_t m0_round_down(uint64_t val, uint64_t size)
Definition: misc.c:187
struct m0_vec iv_vec
Definition: vec.h:139
M0_INTERNAL struct m0_pdclust_instance * pdlayout_instance(struct m0_layout_instance *li)
Definition: utils.c:103
op
Definition: libdemo.c:64
m0_bindex_t * iv_index
Definition: vec.h:141
Definition: vec.h:625
int i
Definition: dir.c:1033
M0_INTERNAL struct m0_parity_math * parity_math(struct m0_op_io *ioo)
Definition: utils.c:124
Definition: client.h:641
struct m0_op_obj ioo_oo
M0_INTERNAL uint64_t indexvec_page_nr(const struct m0_vec *vec, struct m0_obj *obj)
Definition: utils.c:152
struct m0_parity_math pi_math
Definition: pdclust.h:223
static void * vec
Definition: xcode.c:168
M0_INTERNAL struct m0_pdclust_layout * pdlayout_get(const struct m0_op_io *ioo)
Definition: utils.c:111
struct m0_fid pver
Definition: idx_dix.c:74
struct m0_obj * ioo_obj
M0_INTERNAL struct m0_pdclust_layout * m0_layout_to_pdl(const struct m0_layout *l)
Definition: pdclust.c:382
M0_INTERNAL uint32_t io_desc_size(struct m0_net_domain *ndom)
Definition: utils.c:205
Definition: xcode.h:73
static m0_bindex_t offset
Definition: dump.c:173
m0_bcount_t * v_count
Definition: vec.h:53
M0_INTERNAL m0_bcount_t m0_vec_count(const struct m0_vec *vec)
Definition: vec.c:53
M0_INTERNAL m0_bindex_t data_page_offset_get(struct pargrp_iomap *map, uint32_t row, uint32_t col)
Definition: utils.c:246
M0_INTERNAL uint64_t round_down(uint64_t val, uint64_t size)
Definition: utils.c:178
#define M0_FI_ENABLED(tag)
Definition: finject.h:231
M0_INTERNAL uint64_t parity_units_page_nr(struct m0_pdclust_layout *play, struct m0_obj *obj)
Definition: utils.c:168
M0_INTERNAL void page_pos_get(struct pargrp_iomap *map, m0_bindex_t index, m0_bindex_t grp_off, uint32_t *row, uint32_t *col)
Definition: utils.c:224
M0_INTERNAL m0_bcount_t m0_net_domain_get_max_buffer_desc_size(struct m0_net_domain *dom)
M0_INTERNAL uint64_t round_up(uint64_t val, uint64_t size)
Definition: utils.c:192
M0_INTERNAL uint64_t page_nr(m0_bcount_t size, struct m0_obj *obj)
Definition: utils.c:49
m0_bcount_t size
Definition: di.c:39
M0_INTERNAL uint32_t io_seg_size(void)
Definition: utils.c:218
M0_INTERNAL struct m0_pdclust_instance * m0_layout_instance_to_pdi(const struct m0_layout_instance *li)
Definition: pdclust.c:400
#define out(...)
Definition: gen.c:41
struct m0_layout_instance * oo_layout_instance
M0_INTERNAL uint32_t ioreq_sm_state(const struct m0_op_io *ioo)
Definition: utils.c:268
M0_INTERNAL uint64_t tolerance_of_level(struct m0_op_io *ioo, uint64_t lv)
Definition: utils.c:275
uint32_t sm_state
Definition: sm.h:307
M0_INTERNAL bool addr_is_network_aligned(void *addr)
Definition: utils.c:29
M0_INTERNAL struct m0_obj_attr * m0_io_attr(struct m0_op_io *ioo)
Definition: utils.c:302
struct m0_obj_attr ob_attr
Definition: client.h:790