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 1
31 struct ceph_pg_pool_info {
39 int pg_num_mask, pgp_num_mask;
41 s64 write_tier; /* wins for read+write ops */
46 static inline bool ceph_can_shift_osds(struct ceph_pg_pool_info *pool)
49 case CEPH_POOL_TYPE_REP:
51 case CEPH_POOL_TYPE_EC:
58 struct ceph_object_locator {
63 * Maximum supported by kernel client object name length
65 * (probably outdated: must be >= RBD_MAX_MD_NAME_LEN -- currently 100)
67 #define CEPH_MAX_OID_NAME_LEN 100
70 * 51-char inline_name is long enough for all cephfs and all but one
71 * rbd requests: <imgname> in "<imgname>.rbd"/"rbd_id.<imgname>" can be
72 * arbitrarily long (~PAGE_SIZE). It's done once during rbd map; all
73 * other rbd requests fit into inline_name.
75 * Makes ceph_object_id 64 bytes on 64-bit.
77 #define CEPH_OID_INLINE_LEN 52
80 * Both inline and external buffers have space for a NUL-terminator,
81 * which is carried around. It's not required though - RADOS object
82 * names don't have to be NUL-terminated and may contain NULs.
84 struct ceph_object_id {
86 char inline_name[CEPH_OID_INLINE_LEN];
90 static inline void ceph_oid_init(struct ceph_object_id *oid)
92 oid->name = oid->inline_name;
96 static inline bool ceph_oid_empty(const struct ceph_object_id *oid)
98 return oid->name == oid->inline_name && !oid->name_len;
101 void ceph_oid_copy(struct ceph_object_id *dest,
102 const struct ceph_object_id *src);
104 void ceph_oid_printf(struct ceph_object_id *oid, const char *fmt, ...);
106 int ceph_oid_aprintf(struct ceph_object_id *oid, gfp_t gfp,
107 const char *fmt, ...);
108 void ceph_oid_destroy(struct ceph_object_id *oid);
110 struct ceph_pg_mapping {
126 struct ceph_fsid fsid;
128 struct ceph_timespec created, modified;
130 u32 flags; /* CEPH_OSDMAP_* */
132 u32 max_osd; /* size of osd_state, _offload, _addr arrays */
133 u8 *osd_state; /* CEPH_OSD_* */
134 u32 *osd_weight; /* 0 = failed, 0x10000 = 100% normal */
135 struct ceph_entity_addr *osd_addr;
137 struct rb_root pg_temp;
138 struct rb_root primary_temp;
140 u32 *osd_primary_affinity;
142 struct rb_root pg_pools;
145 /* the CRUSH map specifies the mapping of placement groups to
146 * the list of osds that store+replicate them. */
147 struct crush_map *crush;
149 struct mutex crush_scratch_mutex;
150 int crush_scratch_ary[CEPH_PG_MAX_SIZE * 3];
153 static inline int ceph_osd_exists(struct ceph_osdmap *map, int osd)
155 return osd >= 0 && osd < map->max_osd &&
156 (map->osd_state[osd] & CEPH_OSD_EXISTS);
159 static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd)
161 return ceph_osd_exists(map, osd) &&
162 (map->osd_state[osd] & CEPH_OSD_UP);
165 static inline int ceph_osd_is_down(struct ceph_osdmap *map, int osd)
167 return !ceph_osd_is_up(map, osd);
170 static inline bool ceph_osdmap_flag(struct ceph_osdmap *map, int flag)
172 return map && (map->flags & flag);
175 extern char *ceph_osdmap_state_str(char *str, int len, int state);
176 extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd);
178 static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
181 if (osd >= map->max_osd)
183 return &map->osd_addr[osd];
186 static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid)
190 if (!ceph_has_room(p, end, 1 + 8 + 4 + 4)) {
191 pr_warn("incomplete pg encoding\n");
194 version = ceph_decode_8(p);
196 pr_warn("do not understand pg encoding %d > 1\n",
201 pgid->pool = ceph_decode_64(p);
202 pgid->seed = ceph_decode_32(p);
203 *p += 4; /* skip deprecated preferred value */
208 extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end);
209 struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
210 struct ceph_osdmap *map);
211 extern void ceph_osdmap_destroy(struct ceph_osdmap *map);
214 int osds[CEPH_PG_MAX_SIZE];
216 int primary; /* id, NOT index */
219 static inline void ceph_osds_init(struct ceph_osds *set)
225 void ceph_osds_copy(struct ceph_osds *dest, const struct ceph_osds *src);
227 /* calculate mapping of a file extent to an object */
228 extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
230 u64 *bno, u64 *oxoff, u64 *oxlen);
232 int ceph_object_locator_to_pg(struct ceph_osdmap *osdmap,
233 struct ceph_object_id *oid,
234 struct ceph_object_locator *oloc,
235 struct ceph_pg *raw_pgid);
237 void ceph_pg_to_up_acting_osds(struct ceph_osdmap *osdmap,
238 const struct ceph_pg *raw_pgid,
239 struct ceph_osds *up,
240 struct ceph_osds *acting);
241 int ceph_pg_to_acting_primary(struct ceph_osdmap *osdmap,
242 const struct ceph_pg *raw_pgid);
244 extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map,
247 extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id);
248 extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name);