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