]>
Commit | Line | Data |
---|---|---|
f24e9980 SW |
1 | #ifndef _FS_CEPH_OSDMAP_H |
2 | #define _FS_CEPH_OSDMAP_H | |
3 | ||
4 | #include <linux/rbtree.h> | |
a1ce3928 | 5 | #include <linux/ceph/types.h> |
ef4859d6 | 6 | #include <linux/ceph/decode.h> |
a1ce3928 | 7 | #include <linux/ceph/ceph_fs.h> |
3d14c5d2 | 8 | #include <linux/crush/crush.h> |
f24e9980 SW |
9 | |
10 | /* | |
11 | * The osd map describes the current membership of the osd cluster and | |
12 | * specifies the mapping of objects to placement groups and placement | |
13 | * groups to (sets of) osds. That is, it completely specifies the | |
14 | * (desired) distribution of all data objects in the system at some | |
15 | * point in time. | |
16 | * | |
17 | * Each map version is identified by an epoch, which increases monotonically. | |
18 | * | |
19 | * The map can be updated either via an incremental map (diff) describing | |
20 | * the change between two successive epochs, or as a fully encoded map. | |
21 | */ | |
5b191d99 SW |
22 | struct ceph_pg { |
23 | uint64_t pool; | |
24 | uint32_t seed; | |
25 | }; | |
26 | ||
dc98ff72 ID |
27 | #define CEPH_SPG_NOSHARD -1 |
28 | ||
29 | struct ceph_spg { | |
30 | struct ceph_pg pgid; | |
31 | s8 shard; | |
32 | }; | |
33 | ||
f984cb76 | 34 | int ceph_pg_compare(const struct ceph_pg *lhs, const struct ceph_pg *rhs); |
a02a946d | 35 | int ceph_spg_compare(const struct ceph_spg *lhs, const struct ceph_spg *rhs); |
f984cb76 | 36 | |
04812acf ID |
37 | #define CEPH_POOL_FLAG_HASHPSPOOL (1ULL << 0) /* hash pg seed and pool id |
38 | together */ | |
63244fa1 | 39 | #define CEPH_POOL_FLAG_FULL (1ULL << 1) /* pool is full */ |
83ca14fd | 40 | |
f24e9980 | 41 | struct ceph_pg_pool_info { |
4fc51be8 | 42 | struct rb_node node; |
4f6a7e5e | 43 | s64 id; |
04812acf | 44 | u8 type; /* CEPH_POOL_TYPE_* */ |
4f6a7e5e | 45 | u8 size; |
04812acf | 46 | u8 min_size; |
4f6a7e5e SW |
47 | u8 crush_ruleset; |
48 | u8 object_hash; | |
04812acf | 49 | u32 last_force_request_resend; |
4f6a7e5e SW |
50 | u32 pg_num, pgp_num; |
51 | int pg_num_mask, pgp_num_mask; | |
17a13e40 ID |
52 | s64 read_tier; |
53 | s64 write_tier; /* wins for read+write ops */ | |
04812acf | 54 | u64 flags; /* CEPH_POOL_FLAG_* */ |
2844a76a | 55 | char *name; |
42c1b124 ID |
56 | |
57 | bool was_full; /* for handle_one_map() */ | |
f24e9980 SW |
58 | }; |
59 | ||
2abebdbc ID |
60 | static inline bool ceph_can_shift_osds(struct ceph_pg_pool_info *pool) |
61 | { | |
62 | switch (pool->type) { | |
63 | case CEPH_POOL_TYPE_REP: | |
64 | return true; | |
65 | case CEPH_POOL_TYPE_EC: | |
66 | return false; | |
67 | default: | |
d24cdcd3 | 68 | BUG(); |
2abebdbc ID |
69 | } |
70 | } | |
71 | ||
4f6a7e5e | 72 | struct ceph_object_locator { |
22116525 | 73 | s64 pool; |
30c156d9 | 74 | struct ceph_string *pool_ns; |
4f6a7e5e SW |
75 | }; |
76 | ||
63244fa1 ID |
77 | static inline void ceph_oloc_init(struct ceph_object_locator *oloc) |
78 | { | |
79 | oloc->pool = -1; | |
30c156d9 | 80 | oloc->pool_ns = NULL; |
63244fa1 ID |
81 | } |
82 | ||
83 | static inline bool ceph_oloc_empty(const struct ceph_object_locator *oloc) | |
84 | { | |
85 | return oloc->pool == -1; | |
86 | } | |
87 | ||
30c156d9 YZ |
88 | void ceph_oloc_copy(struct ceph_object_locator *dest, |
89 | const struct ceph_object_locator *src); | |
90 | void ceph_oloc_destroy(struct ceph_object_locator *oloc); | |
63244fa1 | 91 | |
d30291b9 ID |
92 | /* |
93 | * 51-char inline_name is long enough for all cephfs and all but one | |
94 | * rbd requests: <imgname> in "<imgname>.rbd"/"rbd_id.<imgname>" can be | |
95 | * arbitrarily long (~PAGE_SIZE). It's done once during rbd map; all | |
96 | * other rbd requests fit into inline_name. | |
97 | * | |
98 | * Makes ceph_object_id 64 bytes on 64-bit. | |
99 | */ | |
100 | #define CEPH_OID_INLINE_LEN 52 | |
101 | ||
102 | /* | |
103 | * Both inline and external buffers have space for a NUL-terminator, | |
104 | * which is carried around. It's not required though - RADOS object | |
105 | * names don't have to be NUL-terminated and may contain NULs. | |
106 | */ | |
4295f221 | 107 | struct ceph_object_id { |
d30291b9 ID |
108 | char *name; |
109 | char inline_name[CEPH_OID_INLINE_LEN]; | |
4295f221 ID |
110 | int name_len; |
111 | }; | |
112 | ||
d30291b9 ID |
113 | static inline void ceph_oid_init(struct ceph_object_id *oid) |
114 | { | |
115 | oid->name = oid->inline_name; | |
116 | oid->name_len = 0; | |
117 | } | |
118 | ||
281dbe5d ID |
119 | #define CEPH_OID_INIT_ONSTACK(oid) \ |
120 | ({ ceph_oid_init(&oid); oid; }) | |
121 | #define CEPH_DEFINE_OID_ONSTACK(oid) \ | |
122 | struct ceph_object_id oid = CEPH_OID_INIT_ONSTACK(oid) | |
123 | ||
d30291b9 ID |
124 | static inline bool ceph_oid_empty(const struct ceph_object_id *oid) |
125 | { | |
126 | return oid->name == oid->inline_name && !oid->name_len; | |
127 | } | |
128 | ||
129 | void ceph_oid_copy(struct ceph_object_id *dest, | |
130 | const struct ceph_object_id *src); | |
131 | __printf(2, 3) | |
132 | void ceph_oid_printf(struct ceph_object_id *oid, const char *fmt, ...); | |
133 | __printf(3, 4) | |
134 | int ceph_oid_aprintf(struct ceph_object_id *oid, gfp_t gfp, | |
135 | const char *fmt, ...); | |
136 | void ceph_oid_destroy(struct ceph_object_id *oid); | |
137 | ||
f24e9980 SW |
138 | struct ceph_pg_mapping { |
139 | struct rb_node node; | |
5b191d99 | 140 | struct ceph_pg pgid; |
35a935d7 ID |
141 | |
142 | union { | |
143 | struct { | |
144 | int len; | |
145 | int osds[]; | |
6f428df4 | 146 | } pg_temp, pg_upmap; |
9686f94c ID |
147 | struct { |
148 | int osd; | |
149 | } primary_temp; | |
6f428df4 ID |
150 | struct { |
151 | int len; | |
152 | int from_to[][2]; | |
153 | } pg_upmap_items; | |
35a935d7 | 154 | }; |
f24e9980 SW |
155 | }; |
156 | ||
157 | struct ceph_osdmap { | |
158 | struct ceph_fsid fsid; | |
159 | u32 epoch; | |
f24e9980 SW |
160 | struct ceph_timespec created, modified; |
161 | ||
162 | u32 flags; /* CEPH_OSDMAP_* */ | |
163 | ||
164 | u32 max_osd; /* size of osd_state, _offload, _addr arrays */ | |
0bb05da2 | 165 | u32 *osd_state; /* CEPH_OSD_* */ |
f24e9980 SW |
166 | u32 *osd_weight; /* 0 = failed, 0x10000 = 100% normal */ |
167 | struct ceph_entity_addr *osd_addr; | |
168 | ||
169 | struct rb_root pg_temp; | |
9686f94c ID |
170 | struct rb_root primary_temp; |
171 | ||
6f428df4 ID |
172 | /* remap (post-CRUSH, pre-up) */ |
173 | struct rb_root pg_upmap; /* PG := raw set */ | |
174 | struct rb_root pg_upmap_items; /* from -> to within raw set */ | |
175 | ||
2cfa34f2 ID |
176 | u32 *osd_primary_affinity; |
177 | ||
4fc51be8 SW |
178 | struct rb_root pg_pools; |
179 | u32 pool_max; | |
f24e9980 SW |
180 | |
181 | /* the CRUSH map specifies the mapping of placement groups to | |
182 | * the list of osds that store+replicate them. */ | |
183 | struct crush_map *crush; | |
9d521470 | 184 | |
743efcff | 185 | struct mutex crush_workspace_mutex; |
66a0e2d5 | 186 | void *crush_workspace; |
f24e9980 SW |
187 | }; |
188 | ||
3b33f692 | 189 | static inline bool ceph_osd_exists(struct ceph_osdmap *map, int osd) |
246138fa ID |
190 | { |
191 | return osd >= 0 && osd < map->max_osd && | |
192 | (map->osd_state[osd] & CEPH_OSD_EXISTS); | |
193 | } | |
194 | ||
3b33f692 | 195 | static inline bool ceph_osd_is_up(struct ceph_osdmap *map, int osd) |
f24e9980 | 196 | { |
246138fa ID |
197 | return ceph_osd_exists(map, osd) && |
198 | (map->osd_state[osd] & CEPH_OSD_UP); | |
199 | } | |
200 | ||
3b33f692 | 201 | static inline bool ceph_osd_is_down(struct ceph_osdmap *map, int osd) |
246138fa ID |
202 | { |
203 | return !ceph_osd_is_up(map, osd); | |
f24e9980 SW |
204 | } |
205 | ||
0bb05da2 | 206 | char *ceph_osdmap_state_str(char *str, int len, u32 state); |
2cfa34f2 | 207 | extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd); |
f24e9980 SW |
208 | |
209 | static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map, | |
210 | int osd) | |
211 | { | |
212 | if (osd >= map->max_osd) | |
213 | return NULL; | |
214 | return &map->osd_addr[osd]; | |
215 | } | |
216 | ||
8cb441c0 ID |
217 | #define CEPH_PGID_ENCODING_LEN (1 + 8 + 4 + 4) |
218 | ||
ef4859d6 AE |
219 | static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid) |
220 | { | |
221 | __u8 version; | |
222 | ||
8cb441c0 | 223 | if (!ceph_has_room(p, end, CEPH_PGID_ENCODING_LEN)) { |
3ef650d3 | 224 | pr_warn("incomplete pg encoding\n"); |
ef4859d6 AE |
225 | return -EINVAL; |
226 | } | |
227 | version = ceph_decode_8(p); | |
228 | if (version > 1) { | |
3ef650d3 | 229 | pr_warn("do not understand pg encoding %d > 1\n", |
ef4859d6 AE |
230 | (int)version); |
231 | return -EINVAL; | |
232 | } | |
233 | ||
234 | pgid->pool = ceph_decode_64(p); | |
235 | pgid->seed = ceph_decode_32(p); | |
236 | *p += 4; /* skip deprecated preferred value */ | |
237 | ||
238 | return 0; | |
239 | } | |
240 | ||
e5253a7b | 241 | struct ceph_osdmap *ceph_osdmap_alloc(void); |
a2505d63 | 242 | extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end); |
0c0a8de1 ID |
243 | struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, |
244 | struct ceph_osdmap *map); | |
f24e9980 SW |
245 | extern void ceph_osdmap_destroy(struct ceph_osdmap *map); |
246 | ||
6f3bfd45 ID |
247 | struct ceph_osds { |
248 | int osds[CEPH_PG_MAX_SIZE]; | |
249 | int size; | |
250 | int primary; /* id, NOT index */ | |
251 | }; | |
252 | ||
253 | static inline void ceph_osds_init(struct ceph_osds *set) | |
254 | { | |
255 | set->size = 0; | |
256 | set->primary = -1; | |
257 | } | |
258 | ||
259 | void ceph_osds_copy(struct ceph_osds *dest, const struct ceph_osds *src); | |
260 | ||
7de030d6 ID |
261 | bool ceph_pg_is_split(const struct ceph_pg *pgid, u32 old_pg_num, |
262 | u32 new_pg_num); | |
63244fa1 ID |
263 | bool ceph_is_new_interval(const struct ceph_osds *old_acting, |
264 | const struct ceph_osds *new_acting, | |
265 | const struct ceph_osds *old_up, | |
266 | const struct ceph_osds *new_up, | |
267 | int old_size, | |
268 | int new_size, | |
269 | int old_min_size, | |
270 | int new_min_size, | |
271 | u32 old_pg_num, | |
272 | u32 new_pg_num, | |
273 | bool old_sort_bitwise, | |
274 | bool new_sort_bitwise, | |
ae78dd81 ID |
275 | bool old_recovery_deletes, |
276 | bool new_recovery_deletes, | |
63244fa1 ID |
277 | const struct ceph_pg *pgid); |
278 | bool ceph_osds_changed(const struct ceph_osds *old_acting, | |
279 | const struct ceph_osds *new_acting, | |
280 | bool any_change); | |
281 | ||
f24e9980 | 282 | /* calculate mapping of a file extent to an object */ |
d63b77f4 | 283 | extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout, |
e8afad65 | 284 | u64 off, u64 len, |
d63b77f4 | 285 | u64 *bno, u64 *oxoff, u64 *oxlen); |
f24e9980 | 286 | |
df28152d ID |
287 | int __ceph_object_locator_to_pg(struct ceph_pg_pool_info *pi, |
288 | const struct ceph_object_id *oid, | |
289 | const struct ceph_object_locator *oloc, | |
290 | struct ceph_pg *raw_pgid); | |
d9591f5e | 291 | int ceph_object_locator_to_pg(struct ceph_osdmap *osdmap, |
df28152d ID |
292 | const struct ceph_object_id *oid, |
293 | const struct ceph_object_locator *oloc, | |
d9591f5e | 294 | struct ceph_pg *raw_pgid); |
7c13cb64 | 295 | |
6f3bfd45 | 296 | void ceph_pg_to_up_acting_osds(struct ceph_osdmap *osdmap, |
df28152d | 297 | struct ceph_pg_pool_info *pi, |
6f3bfd45 ID |
298 | const struct ceph_pg *raw_pgid, |
299 | struct ceph_osds *up, | |
300 | struct ceph_osds *acting); | |
dc98ff72 | 301 | bool ceph_pg_to_primary_shard(struct ceph_osdmap *osdmap, |
df28152d | 302 | struct ceph_pg_pool_info *pi, |
dc98ff72 ID |
303 | const struct ceph_pg *raw_pgid, |
304 | struct ceph_spg *spgid); | |
f81f1633 ID |
305 | int ceph_pg_to_acting_primary(struct ceph_osdmap *osdmap, |
306 | const struct ceph_pg *raw_pgid); | |
f24e9980 | 307 | |
ce7f6a27 ID |
308 | extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map, |
309 | u64 id); | |
310 | ||
72afc71f | 311 | extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id); |
7669a2c9 YS |
312 | extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name); |
313 | ||
f24e9980 | 314 | #endif |