1 #ifndef _FS_CEPH_OSDMAP_H
2 #define _FS_CEPH_OSDMAP_H
4 #include <linux/rbtree.h>
5 #include <linux/ceph/types.h>
6 #include <linux/ceph/decode.h>
7 #include <linux/ceph/ceph_fs.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 int ceph_pg_compare(const struct ceph_pg *lhs, const struct ceph_pg *rhs);
29 #define CEPH_POOL_FLAG_HASHPSPOOL (1ULL << 0) /* hash pg seed and pool id
31 #define CEPH_POOL_FLAG_FULL (1ULL << 1) /* pool is full */
33 struct ceph_pg_pool_info {
36 u8 type; /* CEPH_POOL_TYPE_* */
41 u32 last_force_request_resend;
43 int pg_num_mask, pgp_num_mask;
45 s64 write_tier; /* wins for read+write ops */
46 u64 flags; /* CEPH_POOL_FLAG_* */
50 static inline bool ceph_can_shift_osds(struct ceph_pg_pool_info *pool)
53 case CEPH_POOL_TYPE_REP:
55 case CEPH_POOL_TYPE_EC:
62 struct ceph_object_locator {
66 static inline void ceph_oloc_init(struct ceph_object_locator *oloc)
71 static inline bool ceph_oloc_empty(const struct ceph_object_locator *oloc)
73 return oloc->pool == -1;
76 static inline void ceph_oloc_copy(struct ceph_object_locator *dest,
77 const struct ceph_object_locator *src)
79 dest->pool = src->pool;
83 * Maximum supported by kernel client object name length
85 * (probably outdated: must be >= RBD_MAX_MD_NAME_LEN -- currently 100)
87 #define CEPH_MAX_OID_NAME_LEN 100
90 * 51-char inline_name is long enough for all cephfs and all but one
91 * rbd requests: <imgname> in "<imgname>.rbd"/"rbd_id.<imgname>" can be
92 * arbitrarily long (~PAGE_SIZE). It's done once during rbd map; all
93 * other rbd requests fit into inline_name.
95 * Makes ceph_object_id 64 bytes on 64-bit.
97 #define CEPH_OID_INLINE_LEN 52
100 * Both inline and external buffers have space for a NUL-terminator,
101 * which is carried around. It's not required though - RADOS object
102 * names don't have to be NUL-terminated and may contain NULs.
104 struct ceph_object_id {
106 char inline_name[CEPH_OID_INLINE_LEN];
110 static inline void ceph_oid_init(struct ceph_object_id *oid)
112 oid->name = oid->inline_name;
116 static inline bool ceph_oid_empty(const struct ceph_object_id *oid)
118 return oid->name == oid->inline_name && !oid->name_len;
121 void ceph_oid_copy(struct ceph_object_id *dest,
122 const struct ceph_object_id *src);
124 void ceph_oid_printf(struct ceph_object_id *oid, const char *fmt, ...);
126 int ceph_oid_aprintf(struct ceph_object_id *oid, gfp_t gfp,
127 const char *fmt, ...);
128 void ceph_oid_destroy(struct ceph_object_id *oid);
130 struct ceph_pg_mapping {
146 struct ceph_fsid fsid;
148 struct ceph_timespec created, modified;
150 u32 flags; /* CEPH_OSDMAP_* */
152 u32 max_osd; /* size of osd_state, _offload, _addr arrays */
153 u8 *osd_state; /* CEPH_OSD_* */
154 u32 *osd_weight; /* 0 = failed, 0x10000 = 100% normal */
155 struct ceph_entity_addr *osd_addr;
157 struct rb_root pg_temp;
158 struct rb_root primary_temp;
160 u32 *osd_primary_affinity;
162 struct rb_root pg_pools;
165 /* the CRUSH map specifies the mapping of placement groups to
166 * the list of osds that store+replicate them. */
167 struct crush_map *crush;
169 struct mutex crush_scratch_mutex;
170 int crush_scratch_ary[CEPH_PG_MAX_SIZE * 3];
173 static inline int ceph_osd_exists(struct ceph_osdmap *map, int osd)
175 return osd >= 0 && osd < map->max_osd &&
176 (map->osd_state[osd] & CEPH_OSD_EXISTS);
179 static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd)
181 return ceph_osd_exists(map, osd) &&
182 (map->osd_state[osd] & CEPH_OSD_UP);
185 static inline int ceph_osd_is_down(struct ceph_osdmap *map, int osd)
187 return !ceph_osd_is_up(map, osd);
190 static inline bool ceph_osdmap_flag(struct ceph_osdmap *map, int flag)
192 return map && (map->flags & flag);
195 extern char *ceph_osdmap_state_str(char *str, int len, int state);
196 extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd);
198 static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
201 if (osd >= map->max_osd)
203 return &map->osd_addr[osd];
206 static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid)
210 if (!ceph_has_room(p, end, 1 + 8 + 4 + 4)) {
211 pr_warn("incomplete pg encoding\n");
214 version = ceph_decode_8(p);
216 pr_warn("do not understand pg encoding %d > 1\n",
221 pgid->pool = ceph_decode_64(p);
222 pgid->seed = ceph_decode_32(p);
223 *p += 4; /* skip deprecated preferred value */
228 struct ceph_osdmap *ceph_osdmap_alloc(void);
229 extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end);
230 struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
231 struct ceph_osdmap *map);
232 extern void ceph_osdmap_destroy(struct ceph_osdmap *map);
235 int osds[CEPH_PG_MAX_SIZE];
237 int primary; /* id, NOT index */
240 static inline void ceph_osds_init(struct ceph_osds *set)
246 void ceph_osds_copy(struct ceph_osds *dest, const struct ceph_osds *src);
248 bool ceph_is_new_interval(const struct ceph_osds *old_acting,
249 const struct ceph_osds *new_acting,
250 const struct ceph_osds *old_up,
251 const struct ceph_osds *new_up,
258 bool old_sort_bitwise,
259 bool new_sort_bitwise,
260 const struct ceph_pg *pgid);
261 bool ceph_osds_changed(const struct ceph_osds *old_acting,
262 const struct ceph_osds *new_acting,
265 /* calculate mapping of a file extent to an object */
266 extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
268 u64 *bno, u64 *oxoff, u64 *oxlen);
270 int ceph_object_locator_to_pg(struct ceph_osdmap *osdmap,
271 struct ceph_object_id *oid,
272 struct ceph_object_locator *oloc,
273 struct ceph_pg *raw_pgid);
275 void ceph_pg_to_up_acting_osds(struct ceph_osdmap *osdmap,
276 const struct ceph_pg *raw_pgid,
277 struct ceph_osds *up,
278 struct ceph_osds *acting);
279 int ceph_pg_to_acting_primary(struct ceph_osdmap *osdmap,
280 const struct ceph_pg *raw_pgid);
282 extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map,
285 extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id);
286 extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name);