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 */
41 struct ceph_pg_pool_info {
44 u8 type; /* CEPH_POOL_TYPE_* */
49 u32 last_force_request_resend;
51 int pg_num_mask, pgp_num_mask;
53 s64 write_tier; /* wins for read+write ops */
54 u64 flags; /* CEPH_POOL_FLAG_* */
57 bool was_full; /* for handle_one_map() */
60 static inline bool ceph_can_shift_osds(struct ceph_pg_pool_info *pool)
63 case CEPH_POOL_TYPE_REP:
65 case CEPH_POOL_TYPE_EC:
72 struct ceph_object_locator {
74 struct ceph_string *pool_ns;
77 static inline void ceph_oloc_init(struct ceph_object_locator *oloc)
83 static inline bool ceph_oloc_empty(const struct ceph_object_locator *oloc)
85 return oloc->pool == -1;
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);
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.
98 * Makes ceph_object_id 64 bytes on 64-bit.
100 #define CEPH_OID_INLINE_LEN 52
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.
107 struct ceph_object_id {
109 char inline_name[CEPH_OID_INLINE_LEN];
113 #define __CEPH_OID_INITIALIZER(oid) { .name = (oid).inline_name }
115 #define CEPH_DEFINE_OID_ONSTACK(oid) \
116 struct ceph_object_id oid = __CEPH_OID_INITIALIZER(oid)
118 static inline void ceph_oid_init(struct ceph_object_id *oid)
120 *oid = (struct ceph_object_id) __CEPH_OID_INITIALIZER(*oid);
123 static inline bool ceph_oid_empty(const struct ceph_object_id *oid)
125 return oid->name == oid->inline_name && !oid->name_len;
128 void ceph_oid_copy(struct ceph_object_id *dest,
129 const struct ceph_object_id *src);
131 void ceph_oid_printf(struct ceph_object_id *oid, const char *fmt, ...);
133 int ceph_oid_aprintf(struct ceph_object_id *oid, gfp_t gfp,
134 const char *fmt, ...);
135 void ceph_oid_destroy(struct ceph_object_id *oid);
137 struct ceph_pg_mapping {
157 struct ceph_fsid fsid;
159 struct ceph_timespec created, modified;
161 u32 flags; /* CEPH_OSDMAP_* */
163 u32 max_osd; /* size of osd_state, _offload, _addr arrays */
164 u32 *osd_state; /* CEPH_OSD_* */
165 u32 *osd_weight; /* 0 = failed, 0x10000 = 100% normal */
166 struct ceph_entity_addr *osd_addr;
168 struct rb_root pg_temp;
169 struct rb_root primary_temp;
171 /* remap (post-CRUSH, pre-up) */
172 struct rb_root pg_upmap; /* PG := raw set */
173 struct rb_root pg_upmap_items; /* from -> to within raw set */
175 u32 *osd_primary_affinity;
177 struct rb_root pg_pools;
180 /* the CRUSH map specifies the mapping of placement groups to
181 * the list of osds that store+replicate them. */
182 struct crush_map *crush;
184 struct mutex crush_workspace_mutex;
185 void *crush_workspace;
188 static inline bool ceph_osd_exists(struct ceph_osdmap *map, int osd)
190 return osd >= 0 && osd < map->max_osd &&
191 (map->osd_state[osd] & CEPH_OSD_EXISTS);
194 static inline bool ceph_osd_is_up(struct ceph_osdmap *map, int osd)
196 return ceph_osd_exists(map, osd) &&
197 (map->osd_state[osd] & CEPH_OSD_UP);
200 static inline bool ceph_osd_is_down(struct ceph_osdmap *map, int osd)
202 return !ceph_osd_is_up(map, osd);
205 char *ceph_osdmap_state_str(char *str, int len, u32 state);
206 extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd);
208 static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
211 if (osd >= map->max_osd)
213 return &map->osd_addr[osd];
216 #define CEPH_PGID_ENCODING_LEN (1 + 8 + 4 + 4)
218 static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid)
222 if (!ceph_has_room(p, end, CEPH_PGID_ENCODING_LEN)) {
223 pr_warn("incomplete pg encoding\n");
226 version = ceph_decode_8(p);
228 pr_warn("do not understand pg encoding %d > 1\n",
233 pgid->pool = ceph_decode_64(p);
234 pgid->seed = ceph_decode_32(p);
235 *p += 4; /* skip deprecated preferred value */
240 struct ceph_osdmap *ceph_osdmap_alloc(void);
241 extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end);
242 struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
243 struct ceph_osdmap *map);
244 extern void ceph_osdmap_destroy(struct ceph_osdmap *map);
247 int osds[CEPH_PG_MAX_SIZE];
249 int primary; /* id, NOT index */
252 static inline void ceph_osds_init(struct ceph_osds *set)
258 void ceph_osds_copy(struct ceph_osds *dest, const struct ceph_osds *src);
260 bool ceph_pg_is_split(const struct ceph_pg *pgid, u32 old_pg_num,
262 bool 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,
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);
277 bool ceph_osds_changed(const struct ceph_osds *old_acting,
278 const struct ceph_osds *new_acting,
281 void __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);
285 int 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);
290 void 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);
295 bool 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);
299 int ceph_pg_to_acting_primary(struct ceph_osdmap *osdmap,
300 const struct ceph_pg *raw_pgid);
302 extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map,
305 extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id);
306 extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name);