Motr  M0
ad.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 
25 #ifndef __MOTR_STOB_AD_INTERNAL_H__
26 #define __MOTR_STOB_AD_INTERNAL_H__
27 
28 #include "be/extmap.h" /* m0_be_emap */
29 #include "fid/fid.h" /* m0_fid */
30 #include "lib/types.h" /* m0_bcount_t */
31 #include "stob/domain.h" /* m0_stob_domain */
32 #include "stob/io.h" /* m0_stob_io */
33 #include "stob/stob.h" /* m0_stob */
34 #include "stob/stob_xc.h"
35 
54 struct m0_ad_balloc;
55 struct m0_ad_balloc_ops;
56 struct m0_be_seg;
57 
64 struct m0_ad_balloc {
65  const struct m0_ad_balloc_ops *ab_ops;
66 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
67 
77  int (*bo_init)(struct m0_ad_balloc *ballroom, struct m0_be_seg *db,
78  uint32_t bshift, m0_bcount_t container_size,
79  m0_bcount_t blocks_per_group,
80  m0_bcount_t spare_blocks_per_group);
82  void (*bo_fini)(struct m0_ad_balloc *ballroom);
85  int (*bo_alloc)(struct m0_ad_balloc *ballroom, struct m0_dtx *dtx,
86  m0_bcount_t count, struct m0_ext *out,
87  uint64_t alloc_zone);
90  int (*bo_free)(struct m0_ad_balloc *ballroom, struct m0_dtx *dtx,
91  struct m0_ext *ext);
92  void (*bo_alloc_credit)(const struct m0_ad_balloc *ballroom, int nr,
93  struct m0_be_tx_credit *accum);
94  void (*bo_free_credit)(const struct m0_ad_balloc *ballroom, int nr,
95  struct m0_be_tx_credit *accum);
104  int (*bo_reserve_extent)(struct m0_ad_balloc *ballroom,
105  struct m0_be_tx *tx, struct m0_ext *ext,
106  uint64_t alloc_zone);
107 };
108 
109 enum { AD_PATHLEN = 4096 };
110 
113  uint64_t sad_dom_key;
117  uint32_t sad_bshift;
118  int32_t sad_babshift;
123  char sad_pad[7];
125  /*
126  * m0_be_emap has it's own volatile-only fields, so it can't be placed
127  * before the m0_format_footer, where only persistent fields allowed
128  */
130  /*
131  * volatile-only fields
132  */
135  uint64_t sad_magix;
136 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
137 M0_BASSERT(sizeof(M0_FIELD_VALUE(struct m0_stob_ad_domain, sad_path)) % 8 == 0);
138 M0_BASSERT(sizeof(bool) == 1);
139 
144  uint64_t adm_magic;
145 };
146 
149 
150  /* future versions, uncomment and update M0_STOB_AD_DOMAIN_FORMAT_VERSION */
151  /*M0_STOB_AD_DOMAIN_FORMAT_VERSION_2,*/
152  /*M0_STOB_AD_DOMAIN_FORMAT_VERSION_3,*/
153 
156 };
157 
158 enum {
159  STOB_TYPE_AD = 0x02,
160  /*
161  * As balloc space is exhausted or fragmented -
162  * we may not succeed the allocation in one request.
163  * From another side, we need to establish maximum
164  * possible number of fragments we may have from balloc
165  * to calculate BE credits at stob_ad_write_credit().
166  * That's why we have this constant. Too big value
167  * will result in excess credits, too low value will
168  * result in early ENOSPC errors when there is still
169  * some space available in balloc. So here might be
170  * the tradeoff.
171  */
173 };
174 
186  AET_MIN = M0_BINDEX_MAX - (1ULL << 32),
191 };
192 
193 struct m0_stob_ad {
194  struct m0_stob ad_stob;
195 };
196 
207  uint64_t ai_balloc_flags;
208 };
209 
210 extern const struct m0_stob_type m0_stob_ad_type;
211 
212 M0_INTERNAL struct m0_balloc *
214 
215 M0_INTERNAL bool m0_stob_ad_domain__invariant(struct m0_stob_ad_domain *adom);
216 
217 M0_INTERNAL void m0_stob_ad_init_cfg_make(char **str, struct m0_be_domain *dom);
218 M0_INTERNAL void m0_stob_ad_cfg_make(char **str,
219  const struct m0_be_seg *seg,
220  const struct m0_stob_id *bstore_id,
221  const m0_bcount_t size);
222 M0_INTERNAL int stob_ad_cursor(struct m0_stob_ad_domain *adom,
223  struct m0_stob *obj,
224  uint64_t offset,
225  struct m0_be_emap_cursor *it);
226 
230 M0_INTERNAL void m0_stob_ad_balloc_set(struct m0_stob_io *io, uint64_t flags);
231 
235 M0_INTERNAL void m0_stob_ad_balloc_clear(struct m0_stob_io *io);
236 
241 
245 M0_INTERNAL void * m0_stob_ad_get_checksum_addr(struct m0_stob_io *io,
246  m0_bindex_t off);
247 
250 /* __MOTR_STOB_AD_INTERNAL_H__ */
251 #endif
252 
253 /*
254  * Local variables:
255  * c-indentation-style: "K&R"
256  * c-basic-offset: 8
257  * tab-width: 8
258  * fill-column: 80
259  * scroll-step: 1
260  * End:
261  */
struct m0_ad_balloc_ops M0_XCA_DOMAIN
static size_t nr
Definition: dump.c:1505
Definition: dtm.h:554
Definition: ad.h:193
M0_BASSERT(sizeof(M0_FIELD_VALUE(struct m0_stob_ad_domain, sad_path)) % 8==0)
int(* bo_alloc)(struct m0_ad_balloc *ballroom, struct m0_dtx *dtx, m0_bcount_t count, struct m0_ext *out, uint64_t alloc_zone)
Definition: ad.h:85
#define MAXPATHLEN
Definition: stob.h:41
int const char const void size_t int flags
Definition: dir.c:328
uint64_t ai_balloc_flags
Definition: ad.h:207
#define M0_FIELD_VALUE(type, field)
Definition: misc.h:339
static struct m0_sm_group * grp
Definition: bytecount.c:38
struct m0_stob_io * ai_fore
Definition: ad.h:198
Definition: ad.h:190
int(* bo_init)(struct m0_ad_balloc *ballroom, struct m0_be_seg *db, uint32_t bshift, m0_bcount_t container_size, m0_bcount_t blocks_per_group, m0_bcount_t spare_blocks_per_group)
Definition: ad.h:77
M0_INTERNAL bool m0_stob_ad_domain__invariant(struct m0_stob_ad_domain *adom)
Definition: ad.c:371
m0_bcount_t sad_container_size
Definition: ad.h:116
const struct m0_stob_type m0_stob_ad_type
Definition: ad.c:1003
char sad_pad[7]
Definition: ad.h:123
static struct m0_be_emap_cursor it
Definition: extmap.c:46
M0_INTERNAL void m0_stob_ad_balloc_set(struct m0_stob_io *io, uint64_t flags)
Definition: ad.c:2204
const struct m0_ad_balloc_ops * ab_ops
Definition: ad.h:65
m0_stob_ad_domain_format_version
Definition: ad.h:147
uint32_t sad_bshift
Definition: ad.h:117
uint64_t m0_bindex_t
Definition: types.h:80
char adm_path[MAXPATHLEN]
Definition: ad.h:141
uint64_t m0_bcount_t
Definition: types.h:77
M0_INTERNAL int stob_ad_cursor(struct m0_stob_ad_domain *adom, struct m0_stob *obj, uint64_t offset, struct m0_be_emap_cursor *it)
Definition: ad.c:1101
M0_INTERNAL void m0_stob_ad_init_cfg_make(char **str, struct m0_be_domain *dom)
Definition: ad.c:212
bool sad_overwrite
Definition: ad.h:122
static struct foo * obj
Definition: tlist.c:302
static m0_bcount_t count
Definition: xcode.c:167
struct m0_stob_ad_domain * adm_dom
Definition: ad.h:142
struct m0_ad_balloc * sad_ballroom
Definition: ad.h:115
struct m0_be_seg * sad_be_seg
Definition: ad.h:134
Definition: stob.h:163
uint64_t adm_magic
Definition: ad.h:144
static struct m0_stob_domain * dom
Definition: storage.c:38
uint64_t sad_magix
Definition: ad.h:135
M0_INTERNAL void * m0_stob_ad_get_checksum_addr(struct m0_stob_io *io, m0_bindex_t off)
Definition: ad.c:333
void(* bo_free_credit)(const struct m0_ad_balloc *ballroom, int nr, struct m0_be_tx_credit *accum)
Definition: ad.h:94
struct m0_stob_id sad_bstore_id
Definition: ad.h:114
uint64_t sad_dom_key
Definition: ad.h:113
static m0_bindex_t offset
Definition: dump.c:173
Definition: io.h:285
int(* bo_free)(struct m0_ad_balloc *ballroom, struct m0_dtx *dtx, struct m0_ext *ext)
Definition: ad.h:90
void(* bo_fini)(struct m0_ad_balloc *ballroom)
Definition: ad.h:82
Definition: seg.h:66
static struct m0_stob_io io
Definition: ad.c:59
char sad_path[AD_PATHLEN]
Definition: ad.h:121
int32_t sad_babshift
Definition: ad.h:118
struct m0_stob * sad_bstore
Definition: ad.h:133
struct m0_be_emap sad_adata
Definition: ad.h:129
stob_ad_allocation_extent_type
Definition: ad.h:181
struct m0_clink ai_clink
Definition: ad.h:200
M0_INTERNAL void m0_stob_ad_balloc_clear(struct m0_stob_io *io)
Definition: ad.c:2213
m0_bcount_t sad_spare_blocks_per_group
Definition: ad.h:120
Definition: ext.h:37
int(* bo_reserve_extent)(struct m0_ad_balloc *ballroom, struct m0_be_tx *tx, struct m0_ext *ext, uint64_t alloc_zone)
Definition: ad.h:104
Definition: ad.h:109
m0_bcount_t size
Definition: di.c:39
M0_INTERNAL m0_bcount_t m0_stob_ad_spares_calc(m0_bcount_t grp_blocks)
Definition: ad.c:313
struct m0_format_header sad_header
Definition: ad.h:112
struct m0_format_footer sad_footer
Definition: ad.h:124
M0_INTERNAL struct m0_balloc * m0_stob_ad_domain2balloc(const struct m0_stob_domain *dom)
Definition: ad.c:179
struct m0_stob ad_stob
Definition: ad.h:194
static struct m0_be_seg * seg
Definition: btree.c:40
#define out(...)
Definition: gen.c:41
M0_INTERNAL void m0_stob_ad_cfg_make(char **str, const struct m0_be_seg *seg, const struct m0_stob_id *bstore_id, const m0_bcount_t size)
Definition: ad.c:220
m0_bcount_t sad_blocks_per_group
Definition: ad.h:119
struct m0_tlink adm_linkage
Definition: ad.h:143
struct m0_stob_io ai_back
Definition: ad.h:199
void(* bo_alloc_credit)(const struct m0_ad_balloc *ballroom, int nr, struct m0_be_tx_credit *accum)
Definition: ad.h:92
static struct m0_be_ut_backend be
Definition: service_ut.c:59
Definition: tx.h:280
char sad_path[AD_PATHLEN]
Definition: ad.h:1533
Definition: ad.h:186