1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _FS_CEPH_OSDMAP_H
3 #define _FS_CEPH_OSDMAP_H
5 #include <linux/rbtree.h>
6 #include <linux/ceph/types.h>
7 #include <linux/ceph/decode.h>
8 #include <linux/crush/crush.h>
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
17 * Each map version is identified by an epoch, which increases monotonically.
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.
27 #define CEPH_SPG_NOSHARD -1
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);
37 #define CEPH_POOL_FLAG_HASHPSPOOL (1ULL << 0) /* hash pg seed and pool id
39 #define CEPH_POOL_FLAG_FULL (1ULL << 1) /* pool is full */
40 #define CEPH_POOL_FLAG_FULL_QUOTA (1ULL << 10) /* pool ran out of quota,
42 #define CEPH_POOL_FLAG_NEARFULL (1ULL << 11) /* pool is nearfull */
44 struct ceph_pg_pool_info {
47 u8 type; /* CEPH_POOL_TYPE_* */
52 u32 last_force_request_resend;
54 int pg_num_mask, pgp_num_mask;
56 s64 write_tier; /* wins for read+write ops */
57 u64 flags; /* CEPH_POOL_FLAG_* */
60 bool was_full; /* for handle_one_map() */
63 static inline bool ceph_can_shift_osds(struct ceph_pg_pool_info *pool)
66 case CEPH_POOL_TYPE_REP:
68 case CEPH_POOL_TYPE_EC:
75 struct ceph_object_locator {
77 struct ceph_string *pool_ns;
80 static inline void ceph_oloc_init(struct ceph_object_locator *oloc)
86 static inline bool ceph_oloc_empty(const struct ceph_object_locator *oloc)
88 return oloc->pool == -1;
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);
96 * 51-char inline_name is long enough for all cephfs and all but one
97 * rbd requests: <imgname> in "<imgname>.rbd"/"rbd_id.<imgname>" can be
98 * arbitrarily long (~PAGE_SIZE). It's done once during rbd map; all
99 * other rbd requests fit into inline_name.
101 * Makes ceph_object_id 64 bytes on 64-bit.
103 #define CEPH_OID_INLINE_LEN 52
106 * Both inline and external buffers have space for a NUL-terminator,
107 * which is carried around. It's not required though - RADOS object
108 * names don't have to be NUL-terminated and may contain NULs.
110 struct ceph_object_id {
112 char inline_name[CEPH_OID_INLINE_LEN];
116 static inline void ceph_oid_init(struct ceph_object_id *oid)
118 oid->name = oid->inline_name;
122 #define CEPH_OID_INIT_ONSTACK(oid) \
123 ({ ceph_oid_init(&oid); oid; })
124 #define CEPH_DEFINE_OID_ONSTACK(oid) \
125 struct ceph_object_id oid = CEPH_OID_INIT_ONSTACK(oid)
127 static inline bool ceph_oid_empty(const struct ceph_object_id *oid)
129 return oid->name == oid->inline_name && !oid->name_len;
132 void ceph_oid_copy(struct ceph_object_id *dest,
133 const struct ceph_object_id *src);
135 void ceph_oid_printf(struct ceph_object_id *oid, const char *fmt, ...);
137 int ceph_oid_aprintf(struct ceph_object_id *oid, gfp_t gfp,
138 const char *fmt, ...);
139 void ceph_oid_destroy(struct ceph_object_id *oid);
141 struct ceph_pg_mapping {
161 struct ceph_fsid fsid;
163 struct ceph_timespec created, modified;
165 u32 flags; /* CEPH_OSDMAP_* */
167 u32 max_osd; /* size of osd_state, _offload, _addr arrays */
168 u32 *osd_state; /* CEPH_OSD_* */
169 u32 *osd_weight; /* 0 = failed, 0x10000 = 100% normal */
170 struct ceph_entity_addr *osd_addr;
172 struct rb_root pg_temp;
173 struct rb_root primary_temp;
175 /* remap (post-CRUSH, pre-up) */
176 struct rb_root pg_upmap; /* PG := raw set */
177 struct rb_root pg_upmap_items; /* from -> to within raw set */
179 u32 *osd_primary_affinity;
181 struct rb_root pg_pools;
184 /* the CRUSH map specifies the mapping of placement groups to
185 * the list of osds that store+replicate them. */
186 struct crush_map *crush;
188 struct mutex crush_workspace_mutex;
189 void *crush_workspace;
192 static inline bool ceph_osd_exists(struct ceph_osdmap *map, int osd)
194 return osd >= 0 && osd < map->max_osd &&
195 (map->osd_state[osd] & CEPH_OSD_EXISTS);
198 static inline bool ceph_osd_is_up(struct ceph_osdmap *map, int osd)
200 return ceph_osd_exists(map, osd) &&
201 (map->osd_state[osd] & CEPH_OSD_UP);
204 static inline bool ceph_osd_is_down(struct ceph_osdmap *map, int osd)
206 return !ceph_osd_is_up(map, osd);
209 char *ceph_osdmap_state_str(char *str, int len, u32 state);
210 extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd);
212 static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
215 if (osd >= map->max_osd)
217 return &map->osd_addr[osd];
220 #define CEPH_PGID_ENCODING_LEN (1 + 8 + 4 + 4)
222 static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid)
226 if (!ceph_has_room(p, end, CEPH_PGID_ENCODING_LEN)) {
227 pr_warn("incomplete pg encoding\n");
230 version = ceph_decode_8(p);
232 pr_warn("do not understand pg encoding %d > 1\n",
237 pgid->pool = ceph_decode_64(p);
238 pgid->seed = ceph_decode_32(p);
239 *p += 4; /* skip deprecated preferred value */
244 struct ceph_osdmap *ceph_osdmap_alloc(void);
245 extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end);
246 struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
247 struct ceph_osdmap *map);
248 extern void ceph_osdmap_destroy(struct ceph_osdmap *map);
251 int osds[CEPH_PG_MAX_SIZE];
253 int primary; /* id, NOT index */
256 static inline void ceph_osds_init(struct ceph_osds *set)
262 void ceph_osds_copy(struct ceph_osds *dest, const struct ceph_osds *src);
264 bool ceph_pg_is_split(const struct ceph_pg *pgid, u32 old_pg_num,
266 bool ceph_is_new_interval(const struct ceph_osds *old_acting,
267 const struct ceph_osds *new_acting,
268 const struct ceph_osds *old_up,
269 const struct ceph_osds *new_up,
276 bool old_sort_bitwise,
277 bool new_sort_bitwise,
278 bool old_recovery_deletes,
279 bool new_recovery_deletes,
280 const struct ceph_pg *pgid);
281 bool ceph_osds_changed(const struct ceph_osds *old_acting,
282 const struct ceph_osds *new_acting,
285 void __ceph_object_locator_to_pg(struct ceph_pg_pool_info *pi,
286 const struct ceph_object_id *oid,
287 const struct ceph_object_locator *oloc,
288 struct ceph_pg *raw_pgid);
289 int ceph_object_locator_to_pg(struct ceph_osdmap *osdmap,
290 const struct ceph_object_id *oid,
291 const struct ceph_object_locator *oloc,
292 struct ceph_pg *raw_pgid);
294 void ceph_pg_to_up_acting_osds(struct ceph_osdmap *osdmap,
295 struct ceph_pg_pool_info *pi,
296 const struct ceph_pg *raw_pgid,
297 struct ceph_osds *up,
298 struct ceph_osds *acting);
299 bool ceph_pg_to_primary_shard(struct ceph_osdmap *osdmap,
300 struct ceph_pg_pool_info *pi,
301 const struct ceph_pg *raw_pgid,
302 struct ceph_spg *spgid);
303 int ceph_pg_to_acting_primary(struct ceph_osdmap *osdmap,
304 const struct ceph_pg *raw_pgid);
306 extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map,
309 extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id);
310 extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name);
311 u64 ceph_pg_pool_flags(struct ceph_osdmap *map, u64 id);