Motr  M0
balloc.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_BALLOC_BALLOC_H__
26 #define __MOTR_BALLOC_BALLOC_H__
27 
28 #include "lib/ext.h"
29 #include "lib/types.h"
30 #include "lib/list.h"
31 #include "lib/mutex.h"
32 #include "be/btree.h"
33 #include "be/btree_xc.h"
34 #include "format/format.h"
35 #include "stob/ad.h"
36 #include "stob/ad_xc.h"
37 
63 #ifdef __SPARE_SPACE__
64 
65  m0_bcount_t bgd_spare_frags;
67  m0_bcount_t bgd_spare_freeblocks;
69  m0_bcount_t bgd_sparestart;
71  m0_bcount_t bgd_spare_maxchunk;
72 #endif
74 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
75 
78 
79  /* future versions, uncomment and update M0_BALLOC_GROUP_DESC_FORMAT_VERSION */
80  /*M0_BALLOC_GROUP_DESC_FORMAT_VERSION_2,*/
81  /*M0_BALLOC_GROUP_DESC_FORMAT_VERSION_3,*/
82 
85 };
86 
90 
93 
96 
99 
102 
105 
108 
111 
114 
117 
120 
123 
126 
129 };
130 
138 };
139 
141 struct m0_lext {
145  struct m0_ext le_ext;
146 };
147 
153  uint64_t bgi_state;
162 };
163 
169 };
170 
175  uint64_t bsb_magic;
176  uint64_t bsb_state;
177  uint64_t bsb_version;
178  uint8_t bsb_uuid[128];
179 
182 #ifdef __SPARE_SPACE__
183  m0_bcount_t bsb_freespare;
184  m0_bcount_t bsb_sparesize;
185 #endif
188  uint32_t bsb_bsbits;
189  uint32_t bsb_gsbits;
193  uint64_t bsb_format_time;
194  uint64_t bsb_write_time;
195  uint64_t bsb_mnt_time;
197 
198  uint64_t bsb_mnt_count;
200 
202 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
203 
206 };
207 
210 };
211 
212 enum {
214 };
215 
221 struct m0_balloc {
223 
225  uint64_t cb_container_id;
228 
230 
233 
234  /*
235  * m0_be_btree has it's own volatile-only fields, so it can't be placed
236  * before the m0_format_footer, where only persistent fields allowed
237  */
242 
243  /*
244  * volatile-only fields
245  */
246 
252 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
253 
256 
257  /* future versions, uncomment and update M0_BALLOC_FORMAT_VERSION */
258  /*M0_BALLOC_FORMAT_VERSION_2,*/
259  /*M0_BALLOC_FORMAT_VERSION_3,*/
260 
263 };
264 
265 static inline struct m0_balloc *b2m0(const struct m0_ad_balloc *ballroom)
266 {
267  return container_of(ballroom, struct m0_balloc, cb_ballroom);
268 }
269 
282 };
283 
285  m0_bindex_t bfe_logical; /*< logical offset within the object */
286  m0_bindex_t bfe_groupno; /*< goal group # */
287  m0_bindex_t bfe_start; /*< relative start offset */
288  m0_bindex_t bfe_end; /*< relative start offset */
289 };
290 
299  m0_bindex_t bar_logical; /*< [in]logical offset within the object */
300  m0_bcount_t bar_len; /*< [in]count of blocks, */
301  m0_bindex_t bar_goal; /*< [in]prefered physical block number */
302  uint64_t bar_flags; /*< [in]allocation flags from
303  * m0_balloc_allocation_flag */
304  struct m0_ext bar_result; /*< [out]physical offset, result */
305 
306  void *bar_prealloc;/*< [in][out]User opaque prealloc result */
307 };
308 
313  m0_bindex_t bfr_logical; /*< logical offset within the object */
314  m0_bcount_t bfr_len; /*< count of blocks */
315  m0_bindex_t bfr_physical; /*< physical block number */
316  uint32_t bfr_flags; /*< free flags */
317 };
318 
320  void *bdr_prealloc; /*< User opaque prealloc result */
321 };
322 
323 /*
324  * BALLOC_DEF_BLOCKS_PER_GROUP * (1 << BALLOC_DEF_BLOCK_SHIFT) = 128 MB -->
325  * which equals group size in ext4
326  */
327 enum {
329  BALLOC_DEF_CONTAINER_SIZE = 4096ULL * 32 * 1024 * 1000,
330  BALLOC_DEF_BLOCK_SHIFT = 12,// 4K Blocks
338 };
339 
343 M0_INTERNAL void m0_balloc_init(struct m0_balloc *cb);
344 
355 M0_INTERNAL int m0_balloc_create(uint64_t cid,
356  struct m0_be_seg *seg,
357  struct m0_sm_group *grp,
358  struct m0_balloc **out,
359  const struct m0_fid *fid);
360 
361 M0_INTERNAL void m0_balloc_group_desc_init(struct m0_balloc_group_desc *desc);
362 
363 /* Interfaces for UT */
364 M0_INTERNAL void m0_balloc_debug_dump_sb(const char *tag,
365  struct m0_balloc_super_block *sb);
366 M0_INTERNAL void m0_balloc_debug_dump_group_extent(const char *tag,
367  struct m0_balloc_group_info
368  *grp);
369 
370 M0_INTERNAL int m0_balloc_release_extents(struct m0_balloc_group_info *grp);
371 M0_INTERNAL int m0_balloc_load_extents(struct m0_balloc *cb,
372  struct m0_balloc_group_info *grp);
373 M0_INTERNAL struct m0_balloc_group_info *m0_balloc_gn2info(struct m0_balloc *cb,
374  m0_bindex_t groupno);
375 M0_INTERNAL void m0_balloc_debug_dump_group(const char *tag,
376  struct m0_balloc_group_info *grp);
377 M0_INTERNAL void m0_balloc_lock_group(struct m0_balloc_group_info *grp);
378 M0_INTERNAL int m0_balloc_trylock_group(struct m0_balloc_group_info *grp);
379 M0_INTERNAL void m0_balloc_unlock_group(struct m0_balloc_group_info *grp);
380 
383 #endif /*__MOTR_BALLOC_BALLOC_H__*/
384 
385 /*
386  * Local variables:
387  * c-indentation-style: "K&R"
388  * c-basic-offset: 8
389  * tab-width: 8
390  * fill-column: 80
391  * scroll-step: 1
392  * End:
393  */
m0_bcount_t bfr_spare_reserved_blocks
Definition: balloc.h:281
struct m0_be_btree cb_db_group_desc
Definition: balloc.h:241
m0_bindex_t bfr_logical
Definition: balloc.h:313
uint64_t bsb_max_mnt_count
Definition: balloc.h:199
uint64_t cb_container_id
Definition: balloc.h:225
m0_bcount_t bsb_freeblocks
Definition: balloc.h:181
uint64_t bsb_version
Definition: balloc.h:177
m0_bcount_t bfr_len
Definition: balloc.h:314
struct m0_ad_balloc cb_ballroom
Definition: balloc.h:231
M0_INTERNAL int m0_balloc_load_extents(struct m0_balloc *cb, struct m0_balloc_group_info *grp)
Definition: balloc.c:1273
M0_INTERNAL void m0_balloc_debug_dump_sb(const char *tag, struct m0_balloc_super_block *sb)
Definition: balloc.c:212
enum m0_balloc_group_desc_format_version M0_XCA_DOMAIN
struct m0_ext le_ext
Definition: balloc.h:145
uint64_t bsb_format_time
Definition: balloc.h:193
static uint64_t tag(uint8_t code, uint64_t id)
Definition: addb2.c:1047
static struct m0_sm_group * grp
Definition: bytecount.c:38
m0_bcount_t bzp_freeblocks
Definition: balloc.h:134
struct m0_balloc_group_info * cb_group_info
Definition: balloc.h:248
struct m0_be_btree cb_db_group_extents
Definition: balloc.h:239
m0_bcount_t bsb_totalsize
Definition: balloc.h:180
uint64_t bsb_mnt_time
Definition: balloc.h:195
m0_bindex_t bar_logical
Definition: balloc.h:299
m0_bcount_t bgd_fragments
Definition: balloc.h:60
uint64_t m0_bindex_t
Definition: types.h:80
uint64_t m0_bcount_t
Definition: types.h:77
m0_bcount_t bgd_maxchunk
Definition: balloc.h:62
M0_INTERNAL int m0_balloc_create(uint64_t cid, struct m0_be_seg *seg, struct m0_sm_group *grp, struct m0_balloc **out, const struct m0_fid *fid)
Definition: balloc.c:3015
#define container_of(ptr, type, member)
Definition: misc.h:33
m0_balloc_group_desc_format_version
Definition: balloc.h:76
m0_bcount_t bsb_groupsize
Definition: balloc.h:187
struct m0_fid fid
Definition: di.c:46
m0_bindex_t cb_last
Definition: balloc.h:229
struct m0_list bzp_extents
Definition: balloc.h:137
struct m0_format_footer cb_footer
Definition: balloc.h:232
m0_bcount_t bzp_maxchunk
Definition: balloc.h:136
M0_INTERNAL int m0_balloc_trylock_group(struct m0_balloc_group_info *grp)
Definition: balloc.c:329
struct m0_ext bzp_range
Definition: balloc.h:133
m0_bcount_t bfr_blocksize
Definition: balloc.h:277
M0_INTERNAL void m0_balloc_lock_group(struct m0_balloc_group_info *grp)
Definition: balloc.c:324
m0_bindex_t bar_goal
Definition: balloc.h:301
m0_bcount_t bsb_prealloc_count
Definition: balloc.h:191
m0_balloc_super_block_state
Definition: balloc.h:204
m0_bindex_t bfr_physical
Definition: balloc.h:315
m0_bindex_t bfe_start
Definition: balloc.h:287
static struct m0_balloc * b2m0(const struct m0_ad_balloc *ballroom)
Definition: balloc.h:265
struct m0_balloc_zone_param bgi_normal
Definition: balloc.h:156
struct m0_be_mutex cb_sb_mutex
Definition: balloc.h:250
struct m0_balloc_zone_param bgi_spare
Definition: balloc.h:157
M0_INTERNAL void m0_balloc_unlock_group(struct m0_balloc_group_info *grp)
Definition: balloc.c:334
m0_bcount_t bfr_totalsize
Definition: balloc.h:275
uint64_t bar_flags
Definition: balloc.h:302
M0_INTERNAL void m0_balloc_init(struct m0_balloc *cb)
Definition: balloc.c:3010
M0_INTERNAL void m0_balloc_debug_dump_group_extent(const char *tag, struct m0_balloc_group_info *grp)
Definition: balloc.c:192
m0_bcount_t bfr_groupsize
Definition: balloc.h:279
M0_INTERNAL void m0_balloc_debug_dump_group(const char *tag, struct m0_balloc_group_info *grp)
Definition: balloc.c:171
m0_bcount_t bsb_stripe_size
Definition: balloc.h:201
uint64_t bgi_state
Definition: balloc.h:153
m0_bcount_t bzp_fragments
Definition: balloc.h:135
m0_bcount_t bsb_blocksize
Definition: balloc.h:186
uint32_t bsb_gsbits
Definition: balloc.h:189
m0_balloc_super_block_version
Definition: balloc.h:208
struct m0_ad_balloc cb_ballroom
Definition: balloc.h:643
Definition: seg.h:66
m0_bindex_t bfe_logical
Definition: balloc.h:285
struct m0_lext * bgi_extents
Definition: balloc.h:159
uint32_t bsb_bsbits
Definition: balloc.h:188
m0_balloc_format_version
Definition: balloc.h:254
uint64_t bsb_magic
Definition: balloc.h:175
bool le_is_alloc
Definition: balloc.h:143
Definition: list.h:72
m0_bcount_t bsb_groupcount
Definition: balloc.h:190
M0_INTERNAL int m0_balloc_release_extents(struct m0_balloc_group_info *grp)
Definition: balloc.c:312
struct m0_ext bar_result
Definition: balloc.h:304
static struct super_block sb
Definition: file.c:85
Definition: fid.h:38
Definition: ext.h:37
m0_balloc_group_info_state
Definition: balloc.h:164
uint8_t bsb_uuid[128]
Definition: balloc.h:178
uint64_t bsb_write_time
Definition: balloc.h:194
struct m0_format_header bgd_header
Definition: balloc.h:54
uint64_t bsb_mnt_count
Definition: balloc.h:198
struct m0_format_footer bgd_footer
Definition: balloc.h:73
static struct m0_be_seg * seg
Definition: btree.c:40
m0_bindex_t bgi_groupno
Definition: balloc.h:155
m0_balloc_allocation_flag
Definition: balloc.h:87
struct m0_balloc_super_block cb_sb
Definition: balloc.h:227
uint32_t bfr_flags
Definition: balloc.h:316
#define out(...)
Definition: gen.c:41
m0_bindex_t bgd_groupno
Definition: balloc.h:56
M0_INTERNAL struct m0_balloc_group_info * m0_balloc_gn2info(struct m0_balloc *cb, m0_bindex_t groupno)
Definition: balloc.c:260
m0_bcount_t bar_len
Definition: balloc.h:300
struct m0_be_seg * cb_be_seg
Definition: balloc.h:251
struct m0_list_link le_link
Definition: balloc.h:144
m0_bcount_t bgd_freeblocks
Definition: balloc.h:58
uint64_t bsb_state
Definition: balloc.h:176
m0_bindex_t bfe_end
Definition: balloc.h:288
m0_bindex_t bfe_groupno
Definition: balloc.h:286
uint64_t bsb_last_check_time
Definition: balloc.h:196
struct m0_be_mutex bgi_mutex
Definition: balloc.h:161
M0_INTERNAL void m0_balloc_group_desc_init(struct m0_balloc_group_desc *desc)
Definition: balloc.c:341
enum m0_balloc_allocation_flag bzp_type
Definition: balloc.h:132
static struct m0_be_ut_backend be
Definition: service_ut.c:59
struct m0_format_header cb_header
Definition: balloc.h:222