Motr  M0
layout_pver.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2015-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 
30 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_LAYOUT
31 #include "lib/trace.h"
32 
33 #include "lib/errno.h"
34 #include "lib/tlist.h" /* struct m0_tl */
35 #include "lib/vec.h" /* m0_bufvec_cursor_step(), m0_bufvec_cursor_addr() */
36 #include "lib/memory.h" /* M0_ALLOC_PTR() */
37 #include "lib/misc.h" /* M0_IN() */
38 #include "lib/bob.h"
39 #include "lib/finject.h"
40 
41 #include "motr/magic.h"
42 #include "fid/fid.h" /* m0_fid_set(), m0_fid_is_valid() */
43 #include "pool/pool.h"
44 #include "layout/linear_enum.h"
45 #include "layout/pdclust.h"
46 #include "layout/layout_internal.h" /* M0_PDCLUST_SEED */
47 
49  const uint32_t pool_width,
50  struct m0_layout_enum **lay_enum)
51 {
52  struct m0_layout_linear_attr lin_attr;
53  struct m0_layout_linear_enum *lle;
54  int rc;
55 
56  M0_ENTRY();
57  M0_PRE(pool_width > 0 && lay_enum != NULL);
58  /*
59  * cob_fid = fid { B * idx + A, gob_fid.key }
60  * where idx is in [0, pool_width)
61  */
62  lin_attr = (struct m0_layout_linear_attr){
63  .lla_nr = pool_width,
64  .lla_A = 1,
65  .lla_B = 1
66  };
67 
68  *lay_enum = NULL;
69  rc = m0_linear_enum_build(dom, &lin_attr, &lle);
70  if (rc == 0)
71  *lay_enum = &lle->lle_base;
72  return M0_RC(rc);
73 }
74 
75 
76 static int __layout_build(struct m0_layout_domain *dom,
77  const uint64_t layout_id,
78  struct m0_pool_version *pv,
79  struct m0_layout_enum *le,
80  struct m0_layout **layout)
81 {
82  struct m0_pdclust_layout *pdlayout = NULL;
83  int rc;
84 
85  M0_ENTRY();
86  M0_PRE(pv->pv_attr.pa_P > 0);
87  M0_PRE(le != NULL && layout != NULL);
88 
89  *layout = NULL;
90  rc = m0_pdclust_build(dom, layout_id, &pv->pv_attr, le, &pdlayout);
91  if (rc == 0) {
92  *layout = m0_pdl_to_layout(pdlayout);
93  (*layout)->l_pver = pv;
94  }
95 
96  return M0_RC(rc);
97 }
98 
100  [ 0] = -1, /* invalid */
101  [ 1] = 4096,
102  [ 2] = 8192,
103  [ 3] = 16384,
104  [ 4] = 32768,
105  [ 5] = 65536,
106  [ 6] = 131072,
107  [ 7] = 262144,
108  [ 8] = 524288,
109  [ 9] = 1048576,
110  [10] = 2097152,
111  [11] = 4194304,
112  [12] = 8388608,
113  [13] = 16777216,
114  [14] = 33554432,
115 };
117 
119  struct m0_pool_version *pv,
120  int *count)
121 {
122  struct m0_pdclust_attr *pa = &pv->pv_attr;
123  struct m0_layout_enum *layout_enum;
124  uint64_t layout_id;
125  struct m0_layout *layout;
126  int rc;
127  int i;
128 
129  M0_ENTRY();
130  for (i = M0_DEFAULT_LAYOUT_ID; i < m0_lid_to_unit_map_nr; ++i) {
131  /* Use current unit size. */
134 
136 
137  rc = layout_enum_build(dom, pa->pa_P, &layout_enum);
138  if (rc != 0) {
139  M0_LOG(M0_ERROR, "layout %" PRIu64 " enum build failed: rc=%d",
140  layout_id, rc);
141  return M0_RC(rc);
142  }
143 
147  rc = __layout_build(dom, layout_id, pv, layout_enum, &layout);
148  if (rc != 0) {
149  M0_LOG(M0_ERROR, "layout %" PRIu64 " build failed: rc=%d",
150  layout_id, rc);
151  m0_layout_enum_fini(layout_enum);
152  return M0_RC(rc);
153  }
154  if (count != NULL)
155  (*count)++;
156  }
157  return M0_RC(rc);
158 }
159 
160 #undef M0_TRACE_SUBSYSTEM
161 
164 /*
165  * Local variables:
166  * c-indentation-style: "K&R"
167  * c-basic-offset: 8
168  * tab-width: 8
169  * fill-column: 80
170  * scroll-step: 1
171  * End:
172  */
173 /*
174  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
175  */
#define M0_PRE(cond)
static int __layout_build(struct m0_layout_domain *dom, const uint64_t layout_id, struct m0_pool_version *pv, struct m0_layout_enum *le, struct m0_layout **layout)
Definition: layout_pver.c:76
#define NULL
Definition: misc.h:38
uint64_t pa_unit_size
Definition: pdclust.h:118
struct m0_pool_version * pv
Definition: dir.c:629
#define M0_LOG(level,...)
Definition: trace.h:167
M0_INTERNAL void m0_uint128_init(struct m0_uint128 *u128, const char *magic)
Definition: misc.c:150
M0_INTERNAL int m0_linear_enum_build(struct m0_layout_domain *dom, const struct m0_layout_linear_attr *attr, struct m0_layout_linear_enum **out)
Definition: linear_enum.c:138
M0_INTERNAL void m0_layout_enum_fini(struct m0_layout_enum *le)
Definition: layout.c:518
static int layout_enum_build(struct m0_layout_domain *dom, const uint32_t pool_width, struct m0_layout_enum **lay_enum)
Definition: layout_pver.c:48
static m0_bcount_t count
Definition: xcode.c:167
int m0_lid_to_unit_map[]
Definition: layout_pver.c:99
return M0_RC(rc)
#define M0_ENTRY(...)
Definition: trace.h:170
int i
Definition: dir.c:1033
#define PRIu64
Definition: types.h:58
struct m0_layout_enum lle_base
Definition: linear_enum.h:69
M0_INTERNAL uint64_t m0_pool_version2layout_id(const struct m0_fid *pv_fid, uint64_t lid)
Definition: pool.c:1900
struct m0_fid pv_id
Definition: pool.h:113
#define M0_PDCLUST_SEED
Definition: pdclust.h:76
static struct m0_stob_domain * dom
Definition: storage.c:38
int layout_id
Definition: dir.c:331
M0_INTERNAL int m0_layout_init_by_pver(struct m0_layout_domain *dom, struct m0_pool_version *pv, int *count)
Definition: layout_pver.c:118
struct m0_uint128 pa_seed
Definition: pdclust.h:121
M0_INTERNAL struct m0_layout * m0_pdl_to_layout(struct m0_pdclust_layout *pl)
Definition: pdclust.c:393
const int m0_lid_to_unit_map_nr
Definition: layout_pver.c:116
uint32_t pa_P
Definition: pdclust.h:115
M0_INTERNAL int m0_pdclust_build(struct m0_layout_domain *dom, uint64_t lid, const struct m0_pdclust_attr *attr, struct m0_layout_enum *le, struct m0_pdclust_layout **out)
Definition: pdclust.c:305
struct m0_pdclust_attr pv_attr
Definition: pool.h:122
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45