]>
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 | ||
83ca14fd SW |
27 | #define CEPH_POOL_FLAG_HASHPSPOOL 1 |
28 | ||
f24e9980 | 29 | struct ceph_pg_pool_info { |
4fc51be8 | 30 | struct rb_node node; |
4f6a7e5e SW |
31 | s64 id; |
32 | u8 type; | |
33 | u8 size; | |
34 | u8 crush_ruleset; | |
35 | u8 object_hash; | |
36 | u32 pg_num, pgp_num; | |
37 | int pg_num_mask, pgp_num_mask; | |
17a13e40 ID |
38 | s64 read_tier; |
39 | s64 write_tier; /* wins for read+write ops */ | |
4f6a7e5e | 40 | u64 flags; |
2844a76a | 41 | char *name; |
f24e9980 SW |
42 | }; |
43 | ||
2abebdbc ID |
44 | static inline bool ceph_can_shift_osds(struct ceph_pg_pool_info *pool) |
45 | { | |
46 | switch (pool->type) { | |
47 | case CEPH_POOL_TYPE_REP: | |
48 | return true; | |
49 | case CEPH_POOL_TYPE_EC: | |
50 | return false; | |
51 | default: | |
52 | BUG_ON(1); | |
53 | } | |
54 | } | |
55 | ||
4f6a7e5e | 56 | struct ceph_object_locator { |
22116525 | 57 | s64 pool; |
4f6a7e5e SW |
58 | }; |
59 | ||
4295f221 ID |
60 | /* |
61 | * Maximum supported by kernel client object name length | |
62 | * | |
63 | * (probably outdated: must be >= RBD_MAX_MD_NAME_LEN -- currently 100) | |
64 | */ | |
65 | #define CEPH_MAX_OID_NAME_LEN 100 | |
66 | ||
d30291b9 ID |
67 | /* |
68 | * 51-char inline_name is long enough for all cephfs and all but one | |
69 | * rbd requests: <imgname> in "<imgname>.rbd"/"rbd_id.<imgname>" can be | |
70 | * arbitrarily long (~PAGE_SIZE). It's done once during rbd map; all | |
71 | * other rbd requests fit into inline_name. | |
72 | * | |
73 | * Makes ceph_object_id 64 bytes on 64-bit. | |
74 | */ | |
75 | #define CEPH_OID_INLINE_LEN 52 | |
76 | ||
77 | /* | |
78 | * Both inline and external buffers have space for a NUL-terminator, | |
79 | * which is carried around. It's not required though - RADOS object | |
80 | * names don't have to be NUL-terminated and may contain NULs. | |
81 | */ | |
4295f221 | 82 | struct ceph_object_id { |
d30291b9 ID |
83 | char *name; |
84 | char inline_name[CEPH_OID_INLINE_LEN]; | |
4295f221 ID |
85 | int name_len; |
86 | }; | |
87 | ||
d30291b9 ID |
88 | static inline void ceph_oid_init(struct ceph_object_id *oid) |
89 | { | |
90 | oid->name = oid->inline_name; | |
91 | oid->name_len = 0; | |
92 | } | |
93 | ||
94 | static inline bool ceph_oid_empty(const struct ceph_object_id *oid) | |
95 | { | |
96 | return oid->name == oid->inline_name && !oid->name_len; | |
97 | } | |
98 | ||
99 | void ceph_oid_copy(struct ceph_object_id *dest, | |
100 | const struct ceph_object_id *src); | |
101 | __printf(2, 3) | |
102 | void ceph_oid_printf(struct ceph_object_id *oid, const char *fmt, ...); | |
103 | __printf(3, 4) | |
104 | int ceph_oid_aprintf(struct ceph_object_id *oid, gfp_t gfp, | |
105 | const char *fmt, ...); | |
106 | void ceph_oid_destroy(struct ceph_object_id *oid); | |
107 | ||
f24e9980 SW |
108 | struct ceph_pg_mapping { |
109 | struct rb_node node; | |
5b191d99 | 110 | struct ceph_pg pgid; |
35a935d7 ID |
111 | |
112 | union { | |
113 | struct { | |
114 | int len; | |
115 | int osds[]; | |
116 | } pg_temp; | |
9686f94c ID |
117 | struct { |
118 | int osd; | |
119 | } primary_temp; | |
35a935d7 | 120 | }; |
f24e9980 SW |
121 | }; |
122 | ||
123 | struct ceph_osdmap { | |
124 | struct ceph_fsid fsid; | |
125 | u32 epoch; | |
126 | u32 mkfs_epoch; | |
127 | struct ceph_timespec created, modified; | |
128 | ||
129 | u32 flags; /* CEPH_OSDMAP_* */ | |
130 | ||
131 | u32 max_osd; /* size of osd_state, _offload, _addr arrays */ | |
132 | u8 *osd_state; /* CEPH_OSD_* */ | |
133 | u32 *osd_weight; /* 0 = failed, 0x10000 = 100% normal */ | |
134 | struct ceph_entity_addr *osd_addr; | |
135 | ||
136 | struct rb_root pg_temp; | |
9686f94c ID |
137 | struct rb_root primary_temp; |
138 | ||
2cfa34f2 ID |
139 | u32 *osd_primary_affinity; |
140 | ||
4fc51be8 SW |
141 | struct rb_root pg_pools; |
142 | u32 pool_max; | |
f24e9980 SW |
143 | |
144 | /* the CRUSH map specifies the mapping of placement groups to | |
145 | * the list of osds that store+replicate them. */ | |
146 | struct crush_map *crush; | |
9d521470 ID |
147 | |
148 | struct mutex crush_scratch_mutex; | |
149 | int crush_scratch_ary[CEPH_PG_MAX_SIZE * 3]; | |
f24e9980 SW |
150 | }; |
151 | ||
246138fa ID |
152 | static inline int ceph_osd_exists(struct ceph_osdmap *map, int osd) |
153 | { | |
154 | return osd >= 0 && osd < map->max_osd && | |
155 | (map->osd_state[osd] & CEPH_OSD_EXISTS); | |
156 | } | |
157 | ||
f24e9980 SW |
158 | static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd) |
159 | { | |
246138fa ID |
160 | return ceph_osd_exists(map, osd) && |
161 | (map->osd_state[osd] & CEPH_OSD_UP); | |
162 | } | |
163 | ||
164 | static inline int ceph_osd_is_down(struct ceph_osdmap *map, int osd) | |
165 | { | |
166 | return !ceph_osd_is_up(map, osd); | |
f24e9980 SW |
167 | } |
168 | ||
169 | static inline bool ceph_osdmap_flag(struct ceph_osdmap *map, int flag) | |
170 | { | |
171 | return map && (map->flags & flag); | |
172 | } | |
173 | ||
174 | extern char *ceph_osdmap_state_str(char *str, int len, int state); | |
2cfa34f2 | 175 | extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd); |
f24e9980 SW |
176 | |
177 | static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map, | |
178 | int osd) | |
179 | { | |
180 | if (osd >= map->max_osd) | |
181 | return NULL; | |
182 | return &map->osd_addr[osd]; | |
183 | } | |
184 | ||
ef4859d6 AE |
185 | static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid) |
186 | { | |
187 | __u8 version; | |
188 | ||
189 | if (!ceph_has_room(p, end, 1 + 8 + 4 + 4)) { | |
3ef650d3 | 190 | pr_warn("incomplete pg encoding\n"); |
ef4859d6 AE |
191 | return -EINVAL; |
192 | } | |
193 | version = ceph_decode_8(p); | |
194 | if (version > 1) { | |
3ef650d3 | 195 | pr_warn("do not understand pg encoding %d > 1\n", |
ef4859d6 AE |
196 | (int)version); |
197 | return -EINVAL; | |
198 | } | |
199 | ||
200 | pgid->pool = ceph_decode_64(p); | |
201 | pgid->seed = ceph_decode_32(p); | |
202 | *p += 4; /* skip deprecated preferred value */ | |
203 | ||
204 | return 0; | |
205 | } | |
206 | ||
a2505d63 | 207 | extern struct ceph_osdmap *ceph_osdmap_decode(void **p, void *end); |
f24e9980 SW |
208 | extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, |
209 | struct ceph_osdmap *map, | |
210 | struct ceph_messenger *msgr); | |
211 | extern void ceph_osdmap_destroy(struct ceph_osdmap *map); | |
212 | ||
213 | /* calculate mapping of a file extent to an object */ | |
d63b77f4 | 214 | extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout, |
e8afad65 | 215 | u64 off, u64 len, |
d63b77f4 | 216 | u64 *bno, u64 *oxoff, u64 *oxlen); |
f24e9980 SW |
217 | |
218 | /* calculate mapping of object to a placement group */ | |
7c13cb64 ID |
219 | extern int ceph_oloc_oid_to_pg(struct ceph_osdmap *osdmap, |
220 | struct ceph_object_locator *oloc, | |
221 | struct ceph_object_id *oid, | |
222 | struct ceph_pg *pg_out); | |
223 | ||
12979354 | 224 | extern int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, |
5b191d99 | 225 | struct ceph_pg pgid, |
8008ab10 | 226 | int *osds, int *primary); |
51042122 | 227 | extern int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, |
5b191d99 | 228 | struct ceph_pg pgid); |
f24e9980 | 229 | |
ce7f6a27 ID |
230 | extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map, |
231 | u64 id); | |
232 | ||
72afc71f | 233 | extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id); |
7669a2c9 YS |
234 | extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name); |
235 | ||
f24e9980 | 236 | #endif |