Motr  M0
layout.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2021 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_LAYOUT_LAYOUT_H__
26 #define __MOTR_LAYOUT_LAYOUT_H__
27 
125 /* import */
126 #include "lib/types.h" /* uint64_t */
127 #include "lib/tlist.h" /* struct m0_tl */
128 #include "lib/mutex.h" /* struct m0_mutex */
129 #include "lib/arith.h" /* M0_IS_8ALIGNED */
130 #include "lib/refs.h" /* struct m0_ref */
131 
132 #include "fid/fid.h" /* struct m0_fid */
133 #include "layout/layout_pver.h" /* m0_layout_init_by_pver() */
134 
135 struct m0_bufvec_cursor;
136 struct m0_be_tx;
137 struct m0_client;
138 
139 /* export */
140 struct m0_layout_domain;
141 struct m0_layout;
142 struct m0_layout_ops;
143 struct m0_layout_type;
144 struct m0_layout_type_ops;
145 struct m0_layout_enum;
146 struct m0_layout_enum_ops;
147 struct m0_layout_enum_type;
149 struct m0_striped_layout;
150 struct m0_layout_instance;
152 struct m0_layout_rec;
153 struct m0_pools_common;
154 
162  M0_LXO_BUFFER_OP, /* Operate on a buffer. */
163  M0_LXO_DB_LOOKUP, /* Lookup for layout from the DB. */
164  M0_LXO_DB_ADD, /* Add layout to the DB. */
165  M0_LXO_DB_UPDATE, /* Update layout in the DB. */
166  M0_LXO_DB_DELETE /* Delete layout from the DB. */
167 };
168 
169 enum {
172 };
173 
174 #ifdef CONFIG_X86_64
175  enum { M0_DEFAULT_LAYOUT_ID = 1 };
176 #elif defined (CONFIG_AARCH64)
177 /*
178  * Layout id defines the object unit size which cannot be less than
179  * the page size: 1 - 4KB, 2 - 8KB, 3 - 16KB and so on. On RHEL aarch64
180  * platform the page size is 64KB, hence the default layout id must be 5.
181  */
182  enum { M0_DEFAULT_LAYOUT_ID = 5 };
183 #else
184 #error "The platform is not supported"
185 #endif
186 
197 
200 
203 
206 
209 
212 
218 };
219 
223 struct m0_layout {
225  uint64_t l_id;
226 
229 
232 
234  struct m0_ref l_ref;
235 
242  uint32_t l_user_count;
247  struct m0_mutex l_lock;
249  const struct m0_layout_ops *l_ops;
251  uint64_t l_magic;
262 };
263 
275  void (*lo_fini)(struct m0_ref *ref);
276 
286  void (*lo_delete)(struct m0_layout *l);
287 
297  m0_bcount_t (*lo_recsize)(const struct m0_layout *l);
298 
304  const struct m0_fid *fid,
305  struct m0_layout_instance **linst);
306 
324  int (*lo_decode)(struct m0_layout *l,
325  struct m0_bufvec_cursor *cur,
326  enum m0_layout_xcode_op op,
327  struct m0_be_tx *tx,
328  uint32_t user_count);
329 
343  int (*lo_encode)(struct m0_layout *l,
344  enum m0_layout_xcode_op op,
345  struct m0_be_tx *tx,
346  struct m0_bufvec_cursor *out);
347 };
348 
357  const char *lt_name;
358 
360  uint32_t lt_id;
361 
367  uint32_t lt_ref_count;
368 
370  const struct m0_layout_type_ops *lt_ops;
371 };
372 
379  const struct m0_layout_type *lt);
380 
383  const struct m0_layout_type *lt);
384 
392 
402  uint64_t lid,
403  struct m0_layout **out);
404 };
405 
410 
418 
421 
423  const struct m0_layout_enum_ops *le_ops;
424 
426  uint64_t le_magic;
427 };
428 
431  uint32_t (*leo_nr)(const struct m0_layout_enum *e);
432 
437  void (*leo_get)(const struct m0_layout_enum *e, uint32_t idx,
438  const struct m0_fid *gfid, struct m0_fid *out);
439 
448 
460  void (*leo_fini)(struct m0_layout_enum *e);
461 
466  void (*leo_delete)(struct m0_layout_enum *e);
467 
483  struct m0_bufvec_cursor *cur,
484  enum m0_layout_xcode_op op,
485  struct m0_be_tx *tx,
486  struct m0_striped_layout *stl);
487 
502  int (*leo_encode)(const struct m0_layout_enum *le,
503  enum m0_layout_xcode_op op,
504  struct m0_be_tx *tx,
505  struct m0_bufvec_cursor *out);
506 };
507 
517 M0_INTERNAL void m0_layout_enum_fini(struct m0_layout_enum *le);
518 
527  const char *let_name;
528 
530  uint32_t let_id;
531 
537  uint32_t let_ref_count;
538 
541 };
542 
549  const struct m0_layout_enum_type *et);
550 
553  const struct m0_layout_enum_type *et);
554 
560 
568  struct m0_layout_enum **out);
569 };
570 
575 
578 };
579 
587  struct m0_fid li_gfid;
588 
590  struct m0_layout *li_l;
591 
594 
596  uint64_t li_magic;
597 };
598 
607  void (*lio_fini)(struct m0_layout_instance *li);
608 
613  struct m0_layout_enum *
614  (*lio_to_enum)(const struct m0_layout_instance *li);
615 };
616 
620 M0_INTERNAL struct m0_layout_enum *m0_layout_instance_to_enum(const struct
622  *li);
623 
631 M0_INTERNAL int m0_layout_instance_build(struct m0_layout *l,
632  const struct m0_fid *fid,
633  struct m0_layout_instance **out);
634 
641 M0_INTERNAL void m0_layout_instance_fini(struct m0_layout_instance *li);
642 
653  uint32_t lr_lt_id;
654 
659  uint32_t lr_user_count;
660 
666  char lr_data[0];
667 };
668 M0_BASSERT(M0_IS_8ALIGNED(sizeof(struct m0_layout_rec)));
669 
670 M0_INTERNAL int m0_layouts_init(void);
671 M0_INTERNAL void m0_layouts_fini(void);
672 
677 M0_INTERNAL int m0_layout_domain_init(struct m0_layout_domain *dom);
678 
684 M0_INTERNAL void m0_layout_domain_fini(struct m0_layout_domain *dom);
685 
689 M0_INTERNAL void m0_layout_domain_cleanup(struct m0_layout_domain *dom);
690 
693 
696  *dom);
697 
703 M0_INTERNAL int m0_layout_type_register(struct m0_layout_domain *dom,
704  struct m0_layout_type *lt);
705 
711 M0_INTERNAL void m0_layout_type_unregister(struct m0_layout_domain *dom,
712  struct m0_layout_type *lt);
713 
719 M0_INTERNAL int m0_layout_enum_type_register(struct m0_layout_domain *dom,
720  struct m0_layout_enum_type *et);
721 
727 M0_INTERNAL void m0_layout_enum_type_unregister(struct m0_layout_domain *dom,
728  struct m0_layout_enum_type *et);
729 
733 M0_INTERNAL void m0_layout_add(struct m0_layout_domain *dom, struct m0_layout *l);
734 
745 M0_INTERNAL struct m0_layout *m0_layout_find(struct m0_layout_domain *dom,
746  uint64_t lid);
747 
758 M0_INTERNAL int64_t m0_layout_find_by_buffsize(struct m0_layout_domain *dom,
759  struct m0_fid *pver,
760  size_t buffsize);
761 
770 M0_INTERNAL int64_t m0_layout_find_by_objsz(struct m0_client *cli,
771  struct m0_fid *pool, size_t sz);
772 
778 M0_INTERNAL void m0_layout_get(struct m0_layout *l);
779 
789 M0_INTERNAL void m0_layout_put(struct m0_layout *l);
790 
796 M0_INTERNAL void m0_layout_user_count_inc(struct m0_layout *l);
797 
803 M0_INTERNAL void m0_layout_user_count_dec(struct m0_layout *l);
804 
858 M0_INTERNAL int m0_layout_decode(struct m0_layout *l,
859  struct m0_bufvec_cursor *cur,
860  enum m0_layout_xcode_op op,
861  struct m0_be_tx *tx);
862 
902 M0_INTERNAL int m0_layout_encode(struct m0_layout *l,
903  enum m0_layout_xcode_op op,
904  struct m0_be_tx *tx,
905  struct m0_bufvec_cursor *out);
906 
912 M0_INTERNAL m0_bcount_t m0_layout_max_recsize(const struct m0_layout_domain
913  *dom);
914 
916 M0_INTERNAL struct m0_striped_layout *m0_layout_to_striped(const struct
917  m0_layout *l);
918 
923 M0_INTERNAL struct m0_layout_enum *m0_striped_layout_to_enum(const struct
925  *stl);
926 
927 M0_INTERNAL struct m0_layout_enum *m0_layout_to_enum(const struct m0_layout *l);
928 
930 M0_INTERNAL uint32_t m0_layout_enum_nr(const struct m0_layout_enum *e);
931 
932 
944 M0_INTERNAL void m0_layout_enum_get(const struct m0_layout_enum *e,
945  uint32_t idx,
946  const struct m0_fid *gfid,
947  struct m0_fid *out);
948 
950 M0_INTERNAL uint32_t m0_layout_enum_find(const struct m0_layout_enum *e,
951  const struct m0_fid *gfid,
952  const struct m0_fid *target);
953 
956 /* __MOTR_LAYOUT_LAYOUT_H__ */
957 #endif
958 
959 /*
960  * Local variables:
961  * c-indentation-style: "K&R"
962  * c-basic-offset: 8
963  * tab-width: 8
964  * fill-column: 80
965  * scroll-step: 1
966  * End:
967  */
M0_INTERNAL struct m0_layout * m0_layout_find(struct m0_layout_domain *dom, uint64_t lid)
Definition: layout.c:861
char lr_data[0]
Definition: layout.h:666
int(* leto_register)(struct m0_layout_domain *dom, const struct m0_layout_enum_type *et)
Definition: layout.h:548
M0_INTERNAL m0_bcount_t m0_layout_max_recsize(const struct m0_layout_domain *dom)
Definition: layout.c:1037
M0_INTERNAL struct m0_striped_layout * m0_layout_to_striped(const struct m0_layout *l)
Definition: layout.c:1045
int(* lo_decode)(struct m0_layout *l, struct m0_bufvec_cursor *cur, enum m0_layout_xcode_op op, struct m0_be_tx *tx, uint32_t user_count)
Definition: layout.h:324
uint64_t le_magic
Definition: layout.h:426
struct m0_ref l_ref
Definition: layout.h:234
struct m0_layout * li_l
Definition: layout.h:590
M0_INTERNAL void m0_layout_enum_type_unregister(struct m0_layout_domain *dom, struct m0_layout_enum_type *let)
Definition: layout.c:793
struct m0_pool_version * l_pver
Definition: layout.h:261
static struct buffer * cur(struct m0_addb2_mach *mach, m0_bcount_t space)
Definition: addb2.c:791
const struct m0_layout_enum_type_ops * let_ops
Definition: layout.h:540
M0_INTERNAL int m0_layout_domain_init(struct m0_layout_domain *dom)
Definition: layout.c:610
void(* leo_fini)(struct m0_layout_enum *e)
Definition: layout.h:460
m0_bcount_t(* leto_max_recsize)(void)
Definition: layout.h:559
M0_INTERNAL struct m0_layout_enum * m0_striped_layout_to_enum(const struct m0_striped_layout *stl)
Definition: layout.c:1056
M0_INTERNAL void m0_layout_domain_fini(struct m0_layout_domain *dom)
Definition: layout.c:633
M0_INTERNAL void m0_layout_enum_fini(struct m0_layout_enum *le)
Definition: layout.c:518
uint64_t m0_bcount_t
Definition: types.h:77
m0_bcount_t(* leo_recsize)(struct m0_layout_enum *e)
Definition: layout.h:447
void(* lto_unregister)(struct m0_layout_domain *dom, const struct m0_layout_type *lt)
Definition: layout.h:382
struct m0_layout_enum_type * le_type
Definition: layout.h:409
int(* leo_decode)(struct m0_layout_enum *e, struct m0_bufvec_cursor *cur, enum m0_layout_xcode_op op, struct m0_be_tx *tx, struct m0_striped_layout *stl)
Definition: layout.h:482
M0_INTERNAL int m0_layout_instance_build(struct m0_layout *l, const struct m0_fid *fid, struct m0_layout_instance **out)
Definition: layout.c:1113
M0_BASSERT(M0_IS_8ALIGNED(sizeof(struct m0_layout_rec)))
uint32_t let_ref_count
Definition: layout.h:537
struct m0_fid fid
Definition: di.c:46
op
Definition: libdemo.c:64
struct m0_layout_type * ld_type[M0_LAYOUT_TYPE_MAX]
Definition: layout.h:196
struct m0_tl ld_layout_list
Definition: layout.h:202
M0_INTERNAL void m0_layout_add(struct m0_layout_domain *dom, struct m0_layout *l)
Definition: layout.c:262
int(* leo_encode)(const struct m0_layout_enum *le, enum m0_layout_xcode_op op, struct m0_be_tx *tx, struct m0_bufvec_cursor *out)
Definition: layout.h:502
M0_INTERNAL uint32_t m0_layout_enum_find(const struct m0_layout_enum *e, const struct m0_fid *gfid, const struct m0_fid *target)
Definition: layout.c:1142
int(* lto_allocate)(struct m0_layout_domain *dom, uint64_t lid, struct m0_layout **out)
Definition: layout.h:401
int(* lo_encode)(struct m0_layout *l, enum m0_layout_xcode_op op, struct m0_be_tx *tx, struct m0_bufvec_cursor *out)
Definition: layout.h:343
m0_bcount_t(* lto_max_recsize)(struct m0_layout_domain *dom)
Definition: layout.h:391
uint64_t li_magic
Definition: layout.h:596
Definition: refs.h:34
const struct m0_layout_enum_ops * le_ops
Definition: layout.h:423
struct m0_layout_type * l_type
Definition: layout.h:228
struct m0_layout_domain * le_dom
Definition: layout.h:412
M0_INTERNAL int m0_layout_encode(struct m0_layout *l, enum m0_layout_xcode_op op, struct m0_be_tx *tx, struct m0_bufvec_cursor *out)
Definition: layout.c:1000
M0_INTERNAL int64_t m0_layout_find_by_objsz(struct m0_client *cli, struct m0_fid *pool, size_t sz)
Definition: layout.c:851
uint64_t l_magic
Definition: layout.h:251
uint32_t l_user_count
Definition: layout.h:242
struct m0_fid pver
Definition: idx_dix.c:74
uint32_t lt_ref_count
Definition: layout.h:367
Definition: tlist.h:251
struct m0_layout_enum * sl_enum
Definition: layout.h:577
static struct m0_stob_domain * dom
Definition: storage.c:38
const char * lt_name
Definition: layout.h:357
M0_INTERNAL void m0_layout_enum_get(const struct m0_layout_enum *e, uint32_t idx, const struct m0_fid *gfid, struct m0_fid *out)
Definition: layout.c:1080
M0_INTERNAL uint32_t m0_layout_enum_nr(const struct m0_layout_enum *e)
Definition: layout.c:1074
M0_INTERNAL void m0_layout_user_count_dec(struct m0_layout *l)
Definition: layout.c:934
int(* lo_instance_build)(struct m0_layout *l, const struct m0_fid *fid, struct m0_layout_instance **linst)
Definition: layout.h:303
struct m0_mutex l_lock
Definition: layout.h:247
M0_INTERNAL int m0_layout_enum_type_register(struct m0_layout_domain *dom, struct m0_layout_enum_type *let)
Definition: layout.c:759
m0_bcount_t(* lo_recsize)(const struct m0_layout *l)
Definition: layout.h:297
uint32_t lr_lt_id
Definition: layout.h:653
uint32_t lt_id
Definition: layout.h:360
M0_INTERNAL int m0_layout_standard_types_register(struct m0_layout_domain *dom)
Definition: layout.c:671
M0_INTERNAL int m0_layout_decode(struct m0_layout *l, struct m0_bufvec_cursor *cur, enum m0_layout_xcode_op op, struct m0_be_tx *tx)
Definition: layout.c:947
static struct m0_clink l[NR]
Definition: chan.c:37
void(* leo_get)(const struct m0_layout_enum *e, uint32_t idx, const struct m0_fid *gfid, struct m0_fid *out)
Definition: layout.h:437
struct m0_layout_enum_type * ld_enum[M0_LAYOUT_ENUM_TYPE_MAX]
Definition: layout.h:199
static struct m0_pool pool
Definition: iter_ut.c:58
struct m0_fid li_gfid
Definition: layout.h:587
const char * let_name
Definition: layout.h:527
const struct m0_layout_type_ops * lt_ops
Definition: layout.h:370
M0_INTERNAL int64_t m0_layout_find_by_buffsize(struct m0_layout_domain *dom, struct m0_fid *pver, size_t buffsize)
Definition: layout.c:810
M0_INTERNAL void m0_layout_get(struct m0_layout *l)
Definition: layout.c:880
bool le_sl_is_set
Definition: layout.h:417
M0_INTERNAL void m0_layout_user_count_inc(struct m0_layout *l)
Definition: layout.c:921
struct m0_mutex ld_lock
Definition: layout.h:217
const struct m0_layout_instance_ops * li_ops
Definition: layout.h:593
M0_INTERNAL void m0_layout_domain_cleanup(struct m0_layout_domain *dom)
Definition: layout.c:653
m0_bcount_t ld_max_recsize
Definition: layout.h:211
Definition: fid.h:38
int(* lto_register)(struct m0_layout_domain *dom, const struct m0_layout_type *lt)
Definition: layout.h:378
M0_INTERNAL struct m0_layout_enum * m0_layout_instance_to_enum(const struct m0_layout_instance *li)
Definition: layout.c:1132
void(* lio_fini)(struct m0_layout_instance *li)
Definition: layout.h:607
M0_INTERNAL void m0_layouts_fini(void)
Definition: layout.c:606
struct m0_layout sl_base
Definition: layout.h:574
M0_INTERNAL int m0_layout_type_register(struct m0_layout_domain *dom, struct m0_layout_type *lt)
Definition: layout.c:707
struct m0_striped_layout * le_sl
Definition: layout.h:420
M0_INTERNAL void m0_layout_standard_types_unregister(struct m0_layout_domain *dom)
Definition: layout.c:697
struct m0_tlink l_list_linkage
Definition: layout.h:256
M0_INTERNAL struct m0_layout_enum * m0_layout_to_enum(const struct m0_layout *l)
Definition: layout.c:1064
int(* leto_allocate)(struct m0_layout_domain *dom, struct m0_layout_enum **out)
Definition: layout.h:567
M0_INTERNAL void m0_layout_type_unregister(struct m0_layout_domain *dom, struct m0_layout_type *lt)
Definition: layout.c:741
void * ld_enum_data[M0_LAYOUT_ENUM_TYPE_MAX]
Definition: layout.h:208
void * ld_type_data[M0_LAYOUT_TYPE_MAX]
Definition: layout.h:205
M0_INTERNAL void m0_layout_instance_fini(struct m0_layout_instance *li)
Definition: layout.c:1123
uint32_t lr_user_count
Definition: layout.h:659
void(* lo_delete)(struct m0_layout *l)
Definition: layout.h:286
uint32_t(* leo_nr)(const struct m0_layout_enum *e)
Definition: layout.h:431
M0_INTERNAL void m0_layout_put(struct m0_layout *l)
Definition: layout.c:893
#define M0_IS_8ALIGNED(val)
Definition: arith.h:190
#define out(...)
Definition: gen.c:41
struct m0_fid gfid
Definition: dir.c:626
void(* leto_unregister)(struct m0_layout_domain *dom, const struct m0_layout_enum_type *et)
Definition: layout.h:552
struct m0_layout_domain * l_dom
Definition: layout.h:231
Definition: mutex.h:47
M0_INTERNAL int m0_layouts_init(void)
Definition: layout.c:601
m0_layout_xcode_op
Definition: layout.h:161
uint32_t let_id
Definition: layout.h:530
Definition: tx.h:280
uint64_t l_id
Definition: layout.h:225
void(* leo_delete)(struct m0_layout_enum *e)
Definition: layout.h:466
void(* lo_fini)(struct m0_ref *ref)
Definition: layout.h:275
const struct m0_layout_ops * l_ops
Definition: layout.h:249