1
2#ifndef _FS_CEPH_OSDMAP_H
3#define _FS_CEPH_OSDMAP_H
4
5#include <linux/rbtree.h>
6#include <linux/ceph/types.h>
7#include <linux/ceph/decode.h>
8#include <linux/crush/crush.h>
9
10
11
12
13
14
15
16
17
18
19
20
21
22struct ceph_pg {
23 uint64_t pool;
24 uint32_t seed;
25};
26
27#define CEPH_SPG_NOSHARD -1
28
29struct ceph_spg {
30 struct ceph_pg pgid;
31 s8 shard;
32};
33
34int ceph_pg_compare(const struct ceph_pg *lhs, const struct ceph_pg *rhs);
35int ceph_spg_compare(const struct ceph_spg *lhs, const struct ceph_spg *rhs);
36
37#define CEPH_POOL_FLAG_HASHPSPOOL (1ULL << 0)
38
39#define CEPH_POOL_FLAG_FULL (1ULL << 1)
40
41struct ceph_pg_pool_info {
42 struct rb_node node;
43 s64 id;
44 u8 type;
45 u8 size;
46 u8 min_size;
47 u8 crush_ruleset;
48 u8 object_hash;
49 u32 last_force_request_resend;
50 u32 pg_num, pgp_num;
51 int pg_num_mask, pgp_num_mask;
52 s64 read_tier;
53 s64 write_tier;
54 u64 flags;
55 char *name;
56
57 bool was_full;
58};
59
60static 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:
68 BUG();
69 }
70}
71
72struct ceph_object_locator {
73 s64 pool;
74 struct ceph_string *pool_ns;
75};
76
77static inline void ceph_oloc_init(struct ceph_object_locator *oloc)
78{
79 oloc->pool = -1;
80 oloc->pool_ns = NULL;
81}
82
83static inline bool ceph_oloc_empty(const struct ceph_object_locator *oloc)
84{
85 return oloc->pool == -1;
86}
87
88void ceph_oloc_copy(struct ceph_object_locator *dest,
89 const struct ceph_object_locator *src);
90void ceph_oloc_destroy(struct ceph_object_locator *oloc);
91
92
93
94
95
96
97
98
99
100#define CEPH_OID_INLINE_LEN 52
101
102
103
104
105
106
107struct ceph_object_id {
108 char *name;
109 char inline_name[CEPH_OID_INLINE_LEN];
110 int name_len;
111};
112
113#define __CEPH_OID_INITIALIZER(oid) { .name = (oid).inline_name }
114
115#define CEPH_DEFINE_OID_ONSTACK(oid) \
116 struct ceph_object_id oid = __CEPH_OID_INITIALIZER(oid)
117
118static inline void ceph_oid_init(struct ceph_object_id *oid)
119{
120 *oid = (struct ceph_object_id) __CEPH_OID_INITIALIZER(*oid);
121}
122
123static inline bool ceph_oid_empty(const struct ceph_object_id *oid)
124{
125 return oid->name == oid->inline_name && !oid->name_len;
126}
127
128void ceph_oid_copy(struct ceph_object_id *dest,
129 const struct ceph_object_id *src);
130__printf(2, 3)
131void ceph_oid_printf(struct ceph_object_id *oid, const char *fmt, ...);
132__printf(3, 4)
133int ceph_oid_aprintf(struct ceph_object_id *oid, gfp_t gfp,
134 const char *fmt, ...);
135void ceph_oid_destroy(struct ceph_object_id *oid);
136
137struct ceph_pg_mapping {
138 struct rb_node node;
139 struct ceph_pg pgid;
140
141 union {
142 struct {
143 int len;
144 int osds[];
145 } pg_temp, pg_upmap;
146 struct {
147 int osd;
148 } primary_temp;
149 struct {
150 int len;
151 int from_to[][2];
152 } pg_upmap_items;
153 };
154};
155
156struct ceph_osdmap {
157 struct ceph_fsid fsid;
158 u32 epoch;
159 struct ceph_timespec created, modified;
160
161 u32 flags;
162
163 u32 max_osd;
164 u32 *osd_state;
165 u32 *osd_weight;
166 struct ceph_entity_addr *osd_addr;
167
168 struct rb_root pg_temp;
169 struct rb_root primary_temp;
170
171
172 struct rb_root pg_upmap;
173 struct rb_root pg_upmap_items;
174
175 u32 *osd_primary_affinity;
176
177 struct rb_root pg_pools;
178 u32 pool_max;
179
180
181
182 struct crush_map *crush;
183
184 struct mutex crush_workspace_mutex;
185 void *crush_workspace;
186};
187
188static inline bool ceph_osd_exists(struct ceph_osdmap *map, int osd)
189{
190 return osd >= 0 && osd < map->max_osd &&
191 (map->osd_state[osd] & CEPH_OSD_EXISTS);
192}
193
194static inline bool ceph_osd_is_up(struct ceph_osdmap *map, int osd)
195{
196 return ceph_osd_exists(map, osd) &&
197 (map->osd_state[osd] & CEPH_OSD_UP);
198}
199
200static inline bool ceph_osd_is_down(struct ceph_osdmap *map, int osd)
201{
202 return !ceph_osd_is_up(map, osd);
203}
204
205char *ceph_osdmap_state_str(char *str, int len, u32 state);
206extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd);
207
208static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
209 int osd)
210{
211 if (osd >= map->max_osd)
212 return NULL;
213 return &map->osd_addr[osd];
214}
215
216#define CEPH_PGID_ENCODING_LEN (1 + 8 + 4 + 4)
217
218static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid)
219{
220 __u8 version;
221
222 if (!ceph_has_room(p, end, CEPH_PGID_ENCODING_LEN)) {
223 pr_warn("incomplete pg encoding\n");
224 return -EINVAL;
225 }
226 version = ceph_decode_8(p);
227 if (version > 1) {
228 pr_warn("do not understand pg encoding %d > 1\n",
229 (int)version);
230 return -EINVAL;
231 }
232
233 pgid->pool = ceph_decode_64(p);
234 pgid->seed = ceph_decode_32(p);
235 *p += 4;
236
237 return 0;
238}
239
240struct ceph_osdmap *ceph_osdmap_alloc(void);
241extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end);
242struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
243 struct ceph_osdmap *map);
244extern void ceph_osdmap_destroy(struct ceph_osdmap *map);
245
246struct ceph_osds {
247 int osds[CEPH_PG_MAX_SIZE];
248 int size;
249 int primary;
250};
251
252static inline void ceph_osds_init(struct ceph_osds *set)
253{
254 set->size = 0;
255 set->primary = -1;
256}
257
258void ceph_osds_copy(struct ceph_osds *dest, const struct ceph_osds *src);
259
260bool ceph_pg_is_split(const struct ceph_pg *pgid, u32 old_pg_num,
261 u32 new_pg_num);
262bool ceph_is_new_interval(const struct ceph_osds *old_acting,
263 const struct ceph_osds *new_acting,
264 const struct ceph_osds *old_up,
265 const struct ceph_osds *new_up,
266 int old_size,
267 int new_size,
268 int old_min_size,
269 int new_min_size,
270 u32 old_pg_num,
271 u32 new_pg_num,
272 bool old_sort_bitwise,
273 bool new_sort_bitwise,
274 bool old_recovery_deletes,
275 bool new_recovery_deletes,
276 const struct ceph_pg *pgid);
277bool ceph_osds_changed(const struct ceph_osds *old_acting,
278 const struct ceph_osds *new_acting,
279 bool any_change);
280
281void __ceph_object_locator_to_pg(struct ceph_pg_pool_info *pi,
282 const struct ceph_object_id *oid,
283 const struct ceph_object_locator *oloc,
284 struct ceph_pg *raw_pgid);
285int ceph_object_locator_to_pg(struct ceph_osdmap *osdmap,
286 const struct ceph_object_id *oid,
287 const struct ceph_object_locator *oloc,
288 struct ceph_pg *raw_pgid);
289
290void ceph_pg_to_up_acting_osds(struct ceph_osdmap *osdmap,
291 struct ceph_pg_pool_info *pi,
292 const struct ceph_pg *raw_pgid,
293 struct ceph_osds *up,
294 struct ceph_osds *acting);
295bool ceph_pg_to_primary_shard(struct ceph_osdmap *osdmap,
296 struct ceph_pg_pool_info *pi,
297 const struct ceph_pg *raw_pgid,
298 struct ceph_spg *spgid);
299int ceph_pg_to_acting_primary(struct ceph_osdmap *osdmap,
300 const struct ceph_pg *raw_pgid);
301
302extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map,
303 u64 id);
304
305extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id);
306extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name);
307
308#endif
309