forked from Seagate/cortx-motr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout_pver.c
175 lines (152 loc) · 5.11 KB
/
layout_pver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* -*- C -*- */
/*
* Copyright (c) 2015-2020 Seagate Technology LLC and/or its Affiliates
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For any questions about this software or licensing,
* please email [email protected] or [email protected].
*
*/
/**
* @addtogroup layout_conf
*
* @{
*/
#define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_LAYOUT
#include "lib/trace.h"
#include "lib/errno.h"
#include "lib/tlist.h" /* struct m0_tl */
#include "lib/vec.h" /* m0_bufvec_cursor_step(), m0_bufvec_cursor_addr() */
#include "lib/memory.h" /* M0_ALLOC_PTR() */
#include "lib/misc.h" /* M0_IN() */
#include "lib/bob.h"
#include "lib/finject.h"
#include "motr/magic.h"
#include "fid/fid.h" /* m0_fid_set(), m0_fid_is_valid() */
#include "pool/pool.h"
#include "layout/linear_enum.h"
#include "layout/pdclust.h"
#include "layout/layout_internal.h" /* M0_PDCLUST_SEED */
static int layout_enum_build(struct m0_layout_domain *dom,
const uint32_t pool_width,
struct m0_layout_enum **lay_enum)
{
struct m0_layout_linear_attr lin_attr;
struct m0_layout_linear_enum *lle;
int rc;
M0_ENTRY();
M0_PRE(pool_width > 0 && lay_enum != NULL);
/*
* cob_fid = fid { B * idx + A, gob_fid.key }
* where idx is in [0, pool_width)
*/
lin_attr = (struct m0_layout_linear_attr){
.lla_nr = pool_width,
.lla_A = 1,
.lla_B = 1
};
*lay_enum = NULL;
rc = m0_linear_enum_build(dom, &lin_attr, &lle);
if (rc == 0)
*lay_enum = &lle->lle_base;
return M0_RC(rc);
}
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)
{
struct m0_pdclust_layout *pdlayout = NULL;
int rc;
M0_ENTRY();
M0_PRE(pv->pv_attr.pa_P > 0);
M0_PRE(le != NULL && layout != NULL);
*layout = NULL;
rc = m0_pdclust_build(dom, layout_id, &pv->pv_attr, le, &pdlayout);
if (rc == 0) {
*layout = m0_pdl_to_layout(pdlayout);
(*layout)->l_pver = pv;
}
return M0_RC(rc);
}
int m0_lid_to_unit_map[] = {
[ 0] = -1, /* invalid */
[ 1] = (1<<12), /* 4096 or 4K */
[ 2] = (1<<13), /* 8192 or 8K */
[ 3] = (1<<14), /* 16384 or 16K */
[ 4] = (1<<15), /* 32768 or 32K */
[ 5] = (1<<16), /* 65536 or 64K */
[ 6] = (1<<17), /* 131072 or 128K */
[ 7] = (1<<18), /* 262144 or 256K */
[ 8] = (1<<19), /* 524288 or 512K */
[ 9] = (1<<20), /* 1048576 or 1MB */
[10] = (1<<21), /* 2097152 or 2MB */
[11] = (1<<22), /* 4194304 or 4MB */
[12] = (1<<23), /* 8388608 or 8MB */
[13] = (1<<24), /* 16777216 or 16MB */
[14] = (1<<25), /* 33554432 or 32MB */
};
const int m0_lid_to_unit_map_nr = ARRAY_SIZE(m0_lid_to_unit_map);
M0_INTERNAL int m0_layout_init_by_pver(struct m0_layout_domain *dom,
struct m0_pool_version *pv,
int *count)
{
struct m0_pdclust_attr *pa = &pv->pv_attr;
struct m0_layout_enum *layout_enum;
uint64_t layout_id;
struct m0_layout *layout;
int rc;
int i;
M0_ENTRY();
for (i = M0_DEFAULT_LAYOUT_ID; i < m0_lid_to_unit_map_nr; ++i) {
/* Use current unit size. */
pa->pa_unit_size = m0_lid_to_unit_map[i];
m0_uint128_init(&pa->pa_seed, M0_PDCLUST_SEED);
layout_id = m0_pool_version2layout_id(&pv->pv_id, i);
rc = layout_enum_build(dom, pa->pa_P, &layout_enum);
if (rc != 0) {
M0_LOG(M0_ERROR, "layout %" PRIu64 " enum build failed: rc=%d",
layout_id, rc);
return M0_RC(rc);
}
/**
At this point layout has also added to the list in domain.
*/
rc = __layout_build(dom, layout_id, pv, layout_enum, &layout);
if (rc != 0) {
M0_LOG(M0_ERROR, "layout %" PRIu64 " build failed: rc=%d",
layout_id, rc);
m0_layout_enum_fini(layout_enum);
return M0_RC(rc);
}
if (count != NULL)
(*count)++;
}
return M0_RC(rc);
}
#undef M0_TRACE_SUBSYSTEM
/** @} end of layout_conf group */
/*
* Local variables:
* c-indentation-style: "K&R"
* c-basic-offset: 8
* tab-width: 8
* fill-column: 80
* scroll-step: 1
* End:
*/
/*
* vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
*/