]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - include/linux/ceph/osdmap.h
libceph: make pgid_cmp() global
[karo-tx-linux.git] / include / linux / ceph / osdmap.h
1 #ifndef _FS_CEPH_OSDMAP_H
2 #define _FS_CEPH_OSDMAP_H
3
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>
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  */
22 struct ceph_pg {
23         uint64_t pool;
24         uint32_t seed;
25 };
26
27 int ceph_pg_compare(const struct ceph_pg *lhs, const struct ceph_pg *rhs);
28
29 #define CEPH_POOL_FLAG_HASHPSPOOL  1
30
31 struct ceph_pg_pool_info {
32         struct rb_node node;
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;
40         s64 read_tier;
41         s64 write_tier; /* wins for read+write ops */
42         u64 flags;
43         char *name;
44 };
45
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
58 struct ceph_object_locator {
59         s64 pool;
60 };
61
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
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  */
84 struct ceph_object_id {
85         char *name;
86         char inline_name[CEPH_OID_INLINE_LEN];
87         int name_len;
88 };
89
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
110 struct ceph_pg_mapping {
111         struct rb_node node;
112         struct ceph_pg pgid;
113
114         union {
115                 struct {
116                         int len;
117                         int osds[];
118                 } pg_temp;
119                 struct {
120                         int osd;
121                 } primary_temp;
122         };
123 };
124
125 struct ceph_osdmap {
126         struct ceph_fsid fsid;
127         u32 epoch;
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;
138         struct rb_root primary_temp;
139
140         u32 *osd_primary_affinity;
141
142         struct rb_root pg_pools;
143         u32 pool_max;
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;
148
149         struct mutex crush_scratch_mutex;
150         int crush_scratch_ary[CEPH_PG_MAX_SIZE * 3];
151 };
152
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
159 static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd)
160 {
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);
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);
176 extern u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd);
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
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)) {
191                 pr_warn("incomplete pg encoding\n");
192                 return -EINVAL;
193         }
194         version = ceph_decode_8(p);
195         if (version > 1) {
196                 pr_warn("do not understand pg encoding %d > 1\n",
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
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);
212
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
227 /* calculate mapping of a file extent to an object */
228 extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
229                                          u64 off, u64 len,
230                                          u64 *bno, u64 *oxoff, u64 *oxlen);
231
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);
236
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);
243
244 extern struct ceph_pg_pool_info *ceph_pg_pool_by_id(struct ceph_osdmap *map,
245                                                     u64 id);
246
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);
249
250 #endif