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/ceph/ceph_fs.h>
9 #include <linux/crush/crush.h>
12 * The osd map describes the current membership of the osd cluster and
13 * specifies the mapping of objects to placement groups and placement
14 * groups to (sets of) osds. That is, it completely specifies the
15 * (desired) distribution of all data objects in the system at some
18 * Each map version is identified by an epoch, which increases monotonically.
20 * The map can be updated either via an incremental map (diff) describing
21 * the change between two successive epochs, or as a fully encoded map.
28 #define CEPH_SPG_NOSHARD -1
35 int ceph_pg_compare(const struct ceph_pg
*lhs
, const struct ceph_pg
*rhs
);
36 int ceph_spg_compare(const struct ceph_spg
*lhs
, const struct ceph_spg
*rhs
);
38 #define CEPH_POOL_FLAG_HASHPSPOOL (1ULL << 0) /* hash pg seed and pool id
40 #define CEPH_POOL_FLAG_FULL (1ULL << 1) /* pool is full */
42 struct ceph_pg_pool_info
{
45 u8 type
; /* CEPH_POOL_TYPE_* */
50 u32 last_force_request_resend
;
52 int pg_num_mask
, pgp_num_mask
;
54 s64 write_tier
; /* wins for read+write ops */
55 u64 flags
; /* CEPH_POOL_FLAG_* */
58 bool was_full
; /* for handle_one_map() */
61 static inline bool ceph_can_shift_osds(struct ceph_pg_pool_info
*pool
)
64 case CEPH_POOL_TYPE_REP
:
66 case CEPH_POOL_TYPE_EC
:
73 struct ceph_object_locator
{
75 struct ceph_string
*pool_ns
;
78 static inline void ceph_oloc_init(struct ceph_object_locator
*oloc
)
84 static inline bool ceph_oloc_empty(const struct ceph_object_locator
*oloc
)
86 return oloc
->pool
== -1;
89 void ceph_oloc_copy(struct ceph_object_locator
*dest
,
90 const struct ceph_object_locator
*src
);
91 void ceph_oloc_destroy(struct ceph_object_locator
*oloc
);
94 * 51-char inline_name is long enough for all cephfs and all but one
95 * rbd requests: <imgname> in "<imgname>.rbd"/"rbd_id.<imgname>" can be
96 * arbitrarily long (~PAGE_SIZE). It's done once during rbd map; all
97 * other rbd requests fit into inline_name.
99 * Makes ceph_object_id 64 bytes on 64-bit.
101 #define CEPH_OID_INLINE_LEN 52
104 * Both inline and external buffers have space for a NUL-terminator,
105 * which is carried around. It's not required though - RADOS object
106 * names don't have to be NUL-terminated and may contain NULs.
108 struct ceph_object_id
{
110 char inline_name
[CEPH_OID_INLINE_LEN
];
114 static inline void ceph_oid_init(struct ceph_object_id
*oid
)
116 oid
->name
= oid
->inline_name
;
120 #define CEPH_OID_INIT_ONSTACK(oid) \
121 ({ ceph_oid_init(&oid); oid; })
122 #define CEPH_DEFINE_OID_ONSTACK(oid) \
123 struct ceph_object_id oid = CEPH_OID_INIT_ONSTACK(oid)
125 static inline bool ceph_oid_empty(const struct ceph_object_id
*oid
)
127 return oid
->name
== oid
->inline_name
&& !oid
->name_len
;
130 void ceph_oid_copy(struct ceph_object_id
*dest
,
131 const struct ceph_object_id
*src
);
133 void ceph_oid_printf(struct ceph_object_id
*oid
, const char *fmt
, ...);
135 int ceph_oid_aprintf(struct ceph_object_id
*oid
, gfp_t gfp
,
136 const char *fmt
, ...);
137 void ceph_oid_destroy(struct ceph_object_id
*oid
);
139 struct ceph_pg_mapping
{
159 struct ceph_fsid fsid
;
161 struct ceph_timespec created
, modified
;
163 u32 flags
; /* CEPH_OSDMAP_* */
165 u32 max_osd
; /* size of osd_state, _offload, _addr arrays */
166 u32
*osd_state
; /* CEPH_OSD_* */
167 u32
*osd_weight
; /* 0 = failed, 0x10000 = 100% normal */
168 struct ceph_entity_addr
*osd_addr
;
170 struct rb_root pg_temp
;
171 struct rb_root primary_temp
;
173 /* remap (post-CRUSH, pre-up) */
174 struct rb_root pg_upmap
; /* PG := raw set */
175 struct rb_root pg_upmap_items
; /* from -> to within raw set */
177 u32
*osd_primary_affinity
;
179 struct rb_root pg_pools
;
182 /* the CRUSH map specifies the mapping of placement groups to
183 * the list of osds that store+replicate them. */
184 struct crush_map
*crush
;
186 struct mutex crush_workspace_mutex
;
187 void *crush_workspace
;
190 static inline bool ceph_osd_exists(struct ceph_osdmap
*map
, int osd
)
192 return osd
>= 0 && osd
< map
->max_osd
&&
193 (map
->osd_state
[osd
] & CEPH_OSD_EXISTS
);
196 static inline bool ceph_osd_is_up(struct ceph_osdmap
*map
, int osd
)
198 return ceph_osd_exists(map
, osd
) &&
199 (map
->osd_state
[osd
] & CEPH_OSD_UP
);
202 static inline bool ceph_osd_is_down(struct ceph_osdmap
*map
, int osd
)
204 return !ceph_osd_is_up(map
, osd
);
207 char *ceph_osdmap_state_str(char *str
, int len
, u32 state
);
208 extern u32
ceph_get_primary_affinity(struct ceph_osdmap
*map
, int osd
);
210 static inline struct ceph_entity_addr
*ceph_osd_addr(struct ceph_osdmap
*map
,
213 if (osd
>= map
->max_osd
)
215 return &map
->osd_addr
[osd
];
218 #define CEPH_PGID_ENCODING_LEN (1 + 8 + 4 + 4)
220 static inline int ceph_decode_pgid(void **p
, void *end
, struct ceph_pg
*pgid
)
224 if (!ceph_has_room(p
, end
, CEPH_PGID_ENCODING_LEN
)) {
225 pr_warn("incomplete pg encoding\n");
228 version
= ceph_decode_8(p
);
230 pr_warn("do not understand pg encoding %d > 1\n",
235 pgid
->pool
= ceph_decode_64(p
);
236 pgid
->seed
= ceph_decode_32(p
);
237 *p
+= 4; /* skip deprecated preferred value */
242 struct ceph_osdmap
*ceph_osdmap_alloc(void);
243 extern struct ceph_osdmap
*ceph_osdmap_decode(void **p
, void *end
);
244 struct ceph_osdmap
*osdmap_apply_incremental(void **p
, void *end
,
245 struct ceph_osdmap
*map
);
246 extern void ceph_osdmap_destroy(struct ceph_osdmap
*map
);
249 int osds
[CEPH_PG_MAX_SIZE
];
251 int primary
; /* id, NOT index */
254 static inline void ceph_osds_init(struct ceph_osds
*set
)
260 void ceph_osds_copy(struct ceph_osds
*dest
, const struct ceph_osds
*src
);
262 bool ceph_pg_is_split(const struct ceph_pg
*pgid
, u32 old_pg_num
,
264 bool ceph_is_new_interval(const struct ceph_osds
*old_acting
,
265 const struct ceph_osds
*new_acting
,
266 const struct ceph_osds
*old_up
,
267 const struct ceph_osds
*new_up
,
274 bool old_sort_bitwise
,
275 bool new_sort_bitwise
,
276 bool old_recovery_deletes
,
277 bool new_recovery_deletes
,
278 const struct ceph_pg
*pgid
);
279 bool ceph_osds_changed(const struct ceph_osds
*old_acting
,
280 const struct ceph_osds
*new_acting
,
283 /* calculate mapping of a file extent to an object */
284 extern int ceph_calc_file_object_mapping(struct ceph_file_layout
*layout
,
286 u64
*bno
, u64
*oxoff
, u64
*oxlen
);
288 int __ceph_object_locator_to_pg(struct ceph_pg_pool_info
*pi
,
289 const struct ceph_object_id
*oid
,
290 const struct ceph_object_locator
*oloc
,
291 struct ceph_pg
*raw_pgid
);
292 int ceph_object_locator_to_pg(struct ceph_osdmap
*osdmap
,
293 const struct ceph_object_id
*oid
,
294 const struct ceph_object_locator
*oloc
,
295 struct ceph_pg
*raw_pgid
);
297 void ceph_pg_to_up_acting_osds(struct ceph_osdmap
*osdmap
,
298 struct ceph_pg_pool_info
*pi
,
299 const struct ceph_pg
*raw_pgid
,
300 struct ceph_osds
*up
,
301 struct ceph_osds
*acting
);
302 bool ceph_pg_to_primary_shard(struct ceph_osdmap
*osdmap
,
303 struct ceph_pg_pool_info
*pi
,
304 const struct ceph_pg
*raw_pgid
,
305 struct ceph_spg
*spgid
);
306 int ceph_pg_to_acting_primary(struct ceph_osdmap
*osdmap
,
307 const struct ceph_pg
*raw_pgid
);
309 extern struct ceph_pg_pool_info
*ceph_pg_pool_by_id(struct ceph_osdmap
*map
,
312 extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap
*map
, u64 id
);
313 extern int ceph_pg_poolid_by_name(struct ceph_osdmap
*map
, const char *name
);