]>
Commit | Line | Data |
---|---|---|
f24e9980 SW |
1 | #ifndef _FS_CEPH_OSDMAP_H |
2 | #define _FS_CEPH_OSDMAP_H | |
3 | ||
4 | #include <linux/rbtree.h> | |
a1ce3928 | 5 | #include <linux/ceph/types.h> |
ef4859d6 | 6 | #include <linux/ceph/decode.h> |
a1ce3928 | 7 | #include <linux/ceph/ceph_fs.h> |
3d14c5d2 | 8 | #include <linux/crush/crush.h> |
f24e9980 SW |
9 | |
10 | /* | |
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 | |
15 | * point in time. | |
16 | * | |
17 | * Each map version is identified by an epoch, which increases monotonically. | |
18 | * | |
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. | |
21 | */ | |
5b191d99 SW |
22 | struct ceph_pg { |
23 | uint64_t pool; | |
24 | uint32_t seed; | |
25 | }; | |
26 | ||
f984cb76 ID |
27 | int ceph_pg_compare(const struct ceph_pg *lhs, const struct ceph_pg *rhs); |
28 | ||
83ca14fd SW |
29 | #define CEPH_POOL_FLAG_HASHPSPOOL 1 |
30 | ||
f24e9980 | 31 | struct ceph_pg_pool_info { |
4fc51be8 | 32 | struct rb_node node; |
4f6a7e5e SW |
33 | s64 id; |
34 | u8 type; | |
35 | u8 size; | |
36 | u8 crush_ruleset; | |
37 | u8 object_hash; | |
38 | u32 pg_num, pgp_num; | |
39 | int pg_num_mask, pgp_num_mask; | |
17a13e40 ID |
40 | s64 read_tier; |
41 | s64 write_tier; /* wins for read+write ops */ | |
4f6a7e5e | 42 | u64 flags; |
2844a76a | 43 | char *name; |
f24e9980 SW |
44 | }; |
45 | ||
2abebdbc ID |
46 | static inline bool ceph_can_shift_osds(struct ceph_pg_pool_info *pool) |
47 | { | |
48 | switch (pool->type) { | |
49 | case CEPH_POOL_TYPE_REP: | |
50 | return true; | |
51 | case CEPH_POOL_TYPE_EC: | |
52 | return false; | |
53 | default: | |
54 | BUG_ON(1); | |
55 | } | |
56 | } | |
57 | ||
4f6a7e5e | 58 | struct ceph_object_locator { |
22116525 | 59 | s64 pool; |
4f6a7e5e SW |
60 | }; |
61 | ||
4295f221 ID |
62 | /* |
63 | * Maximum supported by kernel client object name length | |
64 | * | |
65 | * (probably outdated: must be >= RBD_MAX_MD_NAME_LEN -- currently 100) | |
66 | */ | |
67 | #define CEPH_MAX_OID_NAME_LEN 100 | |
68 | ||
d30291b9 ID |
69 | /* |
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. | |
74 | * | |
75 | * Makes ceph_object_id 64 bytes on 64-bit. | |
76 | */ | |
77 | #define CEPH_OID_INLINE_LEN 52 | |
78 | ||
79 | /* | |
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. | |
83 | */ | |
4295f221 | 84 | struct ceph_object_id { |
d30291b9 ID |
85 | char *name; |
86 | char inline_name[CEPH_OID_INLINE_LEN]; | |
4295f221 ID |
87 | int name_len; |
88 | }; | |
89 | ||
d30291b9 ID |
90 | static inline void ceph_oid_init(struct ceph_object_id *oid) |
91 | { | |
92 | oid->name = oid->inline_name; | |
93 | oid->name_len = 0; | |
94 | } | |
95 | ||
96 | static inline bool ceph_oid_empty(const struct ceph_object_id *oid) | |
97 | { | |
98 | return oid->name == oid->inline_name && !oid->name_len; | |
99 | } | |
100 | ||
101 | void ceph_oid_copy(struct ceph_object_id *dest, | |
102 | const struct ceph_object_id *src); | |
103 | __printf(2, 3) | |
104 | void ceph_oid_printf(struct ceph_object_id *oid, const char *fmt, ...); | |
105 | __printf(3, 4) | |
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); | |
109 | ||
f24e9980 SW |
110 | struct ceph_pg_mapping { |
111 | struct rb_node node; | |
5b191d99 | 112 | struct ceph_pg pgid; |
35a935d7 ID |
113 | |
114 | union { | |
115 | struct { | |
116 | int len; | |
117 | int osds[]; | |
118 | } pg_temp; | |
9686f94c ID |
119 | struct { |
120 | int osd; | |
121 | } primary_temp; | |
35a935d7 | 122 | }; |
f24e9980 SW |
123 | }; |
124 | ||
125 | struct ceph_osdmap { | |
126 | struct ceph_fsid fsid; | |
127 | u32 epoch; | |
f24e9980 SW |
128 | struct ceph_timespec created, modified; |
129 | ||
130 | u32 flags; /* CEPH_OSDMAP_* */ | |
131 | ||
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; | |
136 | ||
137 | struct rb_root pg_temp; | |
9686f94c ID |
138 | struct rb_root primary_temp; |
139 | ||
2cfa34f2 ID |
140 | u32 *osd_primary_affinity; |
141 | ||
4fc51be8 SW |
142 | struct rb_root pg_pools; |
143 | u32 pool_max; | |
f24e9980 SW |
144 | |
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; | |
9d521470 ID |
148 | |
149 | struct mutex crush_scratch_mutex; | |
150 | int crush_scratch_ary[CEPH_PG_MAX_SIZE * 3]; | |
f24e9980 SW |
151 | }; |
152 | ||
246138fa ID |
153 | static inline int ceph_osd_exists(struct ceph_osdmap *map, int osd) |
154 | { | |
155 | return osd >= 0 && osd < map->max_osd && | |
156 | (map->osd_state[osd] & CEPH_OSD_EXISTS); | |
157 | } | |
158 | ||
f24e9980 SW |
159 | static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd) |
160 | { | |
246138fa ID |
161 | return ceph_osd_exists(map, osd) && |
162 | (map->osd_state[osd] & CEPH_OSD_UP); | |
163 | } | |
164 | ||
165 | static inline int ceph_osd_is_down(struct ceph_osdmap *map, int osd) | |
166 | { | |
167 | return !ceph_osd_is_up(map, osd); | |
f24e9980 SW |
168 | } |
169 | ||
170 | static inline bool ceph_osdmap_flag(struct ceph_osdmap *map, int flag) | |
171 | { | |
172 | return map && (map->flags & flag); | |
173 | } | |
174 | ||
175 | extern char *ceph_osdmap_state_str(char *str, int len, int state); | |
2cfa34f2 | 176 | extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd); |
f24e9980 SW |
177 | |
178 | static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map, | |
179 | int osd) | |
180 | { | |
181 | if (osd >= map->max_osd) | |
182 | return NULL; | |
183 | return &map->osd_addr[osd]; | |
184 | } | |
185 | ||
ef4859d6 AE |
186 | static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid) |
187 | { | |
188 | __u8 version; | |
189 | ||
190 | if (!ceph_has_room(p, end, 1 + 8 + 4 + 4)) { | |
3ef650d3 | 191 | pr_warn("incomplete pg encoding\n"); |
ef4859d6 AE |
192 | return -EINVAL; |
193 | } | |
194 | version = ceph_decode_8(p); | |
195 | if (version > 1) { | |
3ef650d3 | 196 | pr_warn("do not understand pg encoding %d > 1\n", |
ef4859d6 AE |
197 | (int)version); |
198 | return -EINVAL; | |
199 | } | |
200 | ||
201 | pgid->pool = ceph_decode_64(p); | |
202 | pgid->seed = ceph_decode_32(p); | |
203 | *p += 4; /* skip deprecated preferred value */ | |
204 | ||
205 | return 0; | |
206 | } | |
207 | ||
a2505d63 | 208 | extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end); |
0c0a8de1 ID |
209 | struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, |
210 | struct ceph_osdmap *map); | |
f24e9980 SW |
211 | extern void ceph_osdmap_destroy(struct ceph_osdmap *map); |
212 | ||
6f3bfd45 ID |
213 | struct ceph_osds { |
214 | int osds[CEPH_PG_MAX_SIZE]; | |
215 | int size; | |
216 | int primary; /* id, NOT index */ | |
217 | }; | |
218 | ||
219 | static inline void ceph_osds_init(struct ceph_osds *set) | |
220 | { | |
221 | set->size = 0; | |
222 | set->primary = -1; | |
223 | } | |
224 | ||
225 | void ceph_osds_copy(struct ceph_osds *dest, const struct ceph_osds *src); | |
226 | ||
f24e9980 | 227 | /* calculate mapping of a file extent to an object */ |
d63b77f4 | 228 | extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout, |
e8afad65 | 229 | u64 off, u64 len, |
d63b77f4 | 230 | u64 *bno, u64 *oxoff, u64 *oxlen); |
f24e9980 | 231 | |
d9591f5e ID |
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); | |
7c13cb64 | 236 | |
6f3bfd45 ID |
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); | |
f81f1633 ID |
241 | int ceph_pg_to_acting_primary(struct ceph_osdmap *osdmap, |
242 | const struct ceph_pg *raw_pgid); | |
f24e9980 | 243 | |
ce7f6a27 ID |
244 | extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map, |
245 | u64 id); | |
246 | ||
72afc71f | 247 | extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id); |
7669a2c9 YS |
248 | extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name); |
249 | ||
f24e9980 | 250 | #endif |