1 #ifndef CEPH_RADOS_H
2 #define CEPH_RADOS_H
3
4 /*
5 * Data types for the Ceph distributed object storage layer RADOS
6 * (Reliable Autonomic Distributed Object Store).
7 */
8
9 #include <linux/ceph/msgr.h>
10
11 /*
12 * fs id
13 */
14 struct ceph_fsid {
15 unsigned char fsid[16];
16 };
17
ceph_fsid_compare(const struct ceph_fsid * a,const struct ceph_fsid * b)18 static inline int ceph_fsid_compare(const struct ceph_fsid *a,
19 const struct ceph_fsid *b)
20 {
21 return memcmp(a, b, sizeof(*a));
22 }
23
24 /*
25 * ino, object, etc.
26 */
27 typedef __le64 ceph_snapid_t;
28 #define CEPH_SNAPDIR ((__u64)(-1)) /* reserved for hidden .snap dir */
29 #define CEPH_NOSNAP ((__u64)(-2)) /* "head", "live" revision */
30 #define CEPH_MAXSNAP ((__u64)(-3)) /* largest valid snapid */
31
32 struct ceph_timespec {
33 __le32 tv_sec;
34 __le32 tv_nsec;
35 } __attribute__ ((packed));
36
37
38 /*
39 * object layout - how objects are mapped into PGs
40 */
41 #define CEPH_OBJECT_LAYOUT_HASH 1
42 #define CEPH_OBJECT_LAYOUT_LINEAR 2
43 #define CEPH_OBJECT_LAYOUT_HASHINO 3
44
45 /*
46 * pg layout -- how PGs are mapped onto (sets of) OSDs
47 */
48 #define CEPH_PG_LAYOUT_CRUSH 0
49 #define CEPH_PG_LAYOUT_HASH 1
50 #define CEPH_PG_LAYOUT_LINEAR 2
51 #define CEPH_PG_LAYOUT_HYBRID 3
52
53 #define CEPH_PG_MAX_SIZE 16 /* max # osds in a single pg */
54
55 /*
56 * placement group.
57 * we encode this into one __le64.
58 */
59 struct ceph_pg_v1 {
60 __le16 preferred; /* preferred primary osd */
61 __le16 ps; /* placement seed */
62 __le32 pool; /* object pool */
63 } __attribute__ ((packed));
64
65 /*
66 * pg_pool is a set of pgs storing a pool of objects
67 *
68 * pg_num -- base number of pseudorandomly placed pgs
69 *
70 * pgp_num -- effective number when calculating pg placement. this
71 * is used for pg_num increases. new pgs result in data being "split"
72 * into new pgs. for this to proceed smoothly, new pgs are intiially
73 * colocated with their parents; that is, pgp_num doesn't increase
74 * until the new pgs have successfully split. only _then_ are the new
75 * pgs placed independently.
76 *
77 * lpg_num -- localized pg count (per device). replicas are randomly
78 * selected.
79 *
80 * lpgp_num -- as above.
81 */
82 #define CEPH_NOPOOL ((__u64) (-1)) /* pool id not defined */
83
84 #define CEPH_PG_TYPE_REP 1
85 #define CEPH_PG_TYPE_RAID4 2
86
87 /*
88 * stable_mod func is used to control number of placement groups.
89 * similar to straight-up modulo, but produces a stable mapping as b
90 * increases over time. b is the number of bins, and bmask is the
91 * containing power of 2 minus 1.
92 *
93 * b <= bmask and bmask=(2**n)-1
94 * e.g., b=12 -> bmask=15, b=123 -> bmask=127
95 */
ceph_stable_mod(int x,int b,int bmask)96 static inline int ceph_stable_mod(int x, int b, int bmask)
97 {
98 if ((x & bmask) < b)
99 return x & bmask;
100 else
101 return x & (bmask >> 1);
102 }
103
104 /*
105 * object layout - how a given object should be stored.
106 */
107 struct ceph_object_layout {
108 struct ceph_pg_v1 ol_pgid; /* raw pg, with _full_ ps precision. */
109 __le32 ol_stripe_unit; /* for per-object parity, if any */
110 } __attribute__ ((packed));
111
112 /*
113 * compound epoch+version, used by storage layer to serialize mutations
114 */
115 struct ceph_eversion {
116 __le32 epoch;
117 __le64 version;
118 } __attribute__ ((packed));
119
120 /*
121 * osd map bits
122 */
123
124 /* status bits */
125 #define CEPH_OSD_EXISTS (1<<0)
126 #define CEPH_OSD_UP (1<<1)
127 #define CEPH_OSD_AUTOOUT (1<<2) /* osd was automatically marked out */
128 #define CEPH_OSD_NEW (1<<3) /* osd is new, never marked in */
129
130 extern const char *ceph_osd_state_name(int s);
131
132 /* osd weights. fixed point value: 0x10000 == 1.0 ("in"), 0 == "out" */
133 #define CEPH_OSD_IN 0x10000
134 #define CEPH_OSD_OUT 0
135
136
137 /*
138 * osd map flag bits
139 */
140 #define CEPH_OSDMAP_NEARFULL (1<<0) /* sync writes (near ENOSPC) */
141 #define CEPH_OSDMAP_FULL (1<<1) /* no data writes (ENOSPC) */
142 #define CEPH_OSDMAP_PAUSERD (1<<2) /* pause all reads */
143 #define CEPH_OSDMAP_PAUSEWR (1<<3) /* pause all writes */
144 #define CEPH_OSDMAP_PAUSEREC (1<<4) /* pause recovery */
145 #define CEPH_OSDMAP_NOUP (1<<5) /* block osd boot */
146 #define CEPH_OSDMAP_NODOWN (1<<6) /* block osd mark-down/failure */
147 #define CEPH_OSDMAP_NOOUT (1<<7) /* block osd auto mark-out */
148 #define CEPH_OSDMAP_NOIN (1<<8) /* block osd auto mark-in */
149 #define CEPH_OSDMAP_NOBACKFILL (1<<9) /* block osd backfill */
150 #define CEPH_OSDMAP_NORECOVER (1<<10) /* block osd recovery and backfill */
151
152 /*
153 * The error code to return when an OSD can't handle a write
154 * because it is too large.
155 */
156 #define OSD_WRITETOOBIG EMSGSIZE
157
158 /*
159 * osd ops
160 *
161 * WARNING: do not use these op codes directly. Use the helpers
162 * defined below instead. In certain cases, op code behavior was
163 * redefined, resulting in special-cases in the helpers.
164 */
165 #define CEPH_OSD_OP_MODE 0xf000
166 #define CEPH_OSD_OP_MODE_RD 0x1000
167 #define CEPH_OSD_OP_MODE_WR 0x2000
168 #define CEPH_OSD_OP_MODE_RMW 0x3000
169 #define CEPH_OSD_OP_MODE_SUB 0x4000
170
171 #define CEPH_OSD_OP_TYPE 0x0f00
172 #define CEPH_OSD_OP_TYPE_LOCK 0x0100
173 #define CEPH_OSD_OP_TYPE_DATA 0x0200
174 #define CEPH_OSD_OP_TYPE_ATTR 0x0300
175 #define CEPH_OSD_OP_TYPE_EXEC 0x0400
176 #define CEPH_OSD_OP_TYPE_PG 0x0500
177 #define CEPH_OSD_OP_TYPE_MULTI 0x0600 /* multiobject */
178
179 enum {
180 /** data **/
181 /* read */
182 CEPH_OSD_OP_READ = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 1,
183 CEPH_OSD_OP_STAT = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 2,
184 CEPH_OSD_OP_MAPEXT = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 3,
185
186 /* fancy read */
187 CEPH_OSD_OP_MASKTRUNC = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 4,
188 CEPH_OSD_OP_SPARSE_READ = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 5,
189
190 CEPH_OSD_OP_NOTIFY = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 6,
191 CEPH_OSD_OP_NOTIFY_ACK = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 7,
192
193 /* versioning */
194 CEPH_OSD_OP_ASSERT_VER = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 8,
195
196 /* write */
197 CEPH_OSD_OP_WRITE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 1,
198 CEPH_OSD_OP_WRITEFULL = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 2,
199 CEPH_OSD_OP_TRUNCATE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 3,
200 CEPH_OSD_OP_ZERO = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 4,
201 CEPH_OSD_OP_DELETE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 5,
202
203 /* fancy write */
204 CEPH_OSD_OP_APPEND = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 6,
205 CEPH_OSD_OP_STARTSYNC = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 7,
206 CEPH_OSD_OP_SETTRUNC = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 8,
207 CEPH_OSD_OP_TRIMTRUNC = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 9,
208
209 CEPH_OSD_OP_TMAPUP = CEPH_OSD_OP_MODE_RMW | CEPH_OSD_OP_TYPE_DATA | 10,
210 CEPH_OSD_OP_TMAPPUT = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 11,
211 CEPH_OSD_OP_TMAPGET = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 12,
212
213 CEPH_OSD_OP_CREATE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 13,
214 CEPH_OSD_OP_ROLLBACK= CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 14,
215
216 CEPH_OSD_OP_WATCH = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 15,
217
218 /* omap */
219 CEPH_OSD_OP_OMAPGETKEYS = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 17,
220 CEPH_OSD_OP_OMAPGETVALS = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 18,
221 CEPH_OSD_OP_OMAPGETHEADER = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 19,
222 CEPH_OSD_OP_OMAPGETVALSBYKEYS =
223 CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 20,
224 CEPH_OSD_OP_OMAPSETVALS = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 21,
225 CEPH_OSD_OP_OMAPSETHEADER = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 22,
226 CEPH_OSD_OP_OMAPCLEAR = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 23,
227 CEPH_OSD_OP_OMAPRMKEYS = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 24,
228 CEPH_OSD_OP_OMAP_CMP = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 25,
229
230 /** multi **/
231 CEPH_OSD_OP_CLONERANGE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_MULTI | 1,
232 CEPH_OSD_OP_ASSERT_SRC_VERSION = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_MULTI | 2,
233 CEPH_OSD_OP_SRC_CMPXATTR = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_MULTI | 3,
234
235 /** attrs **/
236 /* read */
237 CEPH_OSD_OP_GETXATTR = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_ATTR | 1,
238 CEPH_OSD_OP_GETXATTRS = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_ATTR | 2,
239 CEPH_OSD_OP_CMPXATTR = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_ATTR | 3,
240
241 /* write */
242 CEPH_OSD_OP_SETXATTR = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_ATTR | 1,
243 CEPH_OSD_OP_SETXATTRS = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_ATTR | 2,
244 CEPH_OSD_OP_RESETXATTRS = CEPH_OSD_OP_MODE_WR|CEPH_OSD_OP_TYPE_ATTR | 3,
245 CEPH_OSD_OP_RMXATTR = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_ATTR | 4,
246
247 /** subop **/
248 CEPH_OSD_OP_PULL = CEPH_OSD_OP_MODE_SUB | 1,
249 CEPH_OSD_OP_PUSH = CEPH_OSD_OP_MODE_SUB | 2,
250 CEPH_OSD_OP_BALANCEREADS = CEPH_OSD_OP_MODE_SUB | 3,
251 CEPH_OSD_OP_UNBALANCEREADS = CEPH_OSD_OP_MODE_SUB | 4,
252 CEPH_OSD_OP_SCRUB = CEPH_OSD_OP_MODE_SUB | 5,
253 CEPH_OSD_OP_SCRUB_RESERVE = CEPH_OSD_OP_MODE_SUB | 6,
254 CEPH_OSD_OP_SCRUB_UNRESERVE = CEPH_OSD_OP_MODE_SUB | 7,
255 CEPH_OSD_OP_SCRUB_STOP = CEPH_OSD_OP_MODE_SUB | 8,
256 CEPH_OSD_OP_SCRUB_MAP = CEPH_OSD_OP_MODE_SUB | 9,
257
258 /** lock **/
259 CEPH_OSD_OP_WRLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 1,
260 CEPH_OSD_OP_WRUNLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 2,
261 CEPH_OSD_OP_RDLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 3,
262 CEPH_OSD_OP_RDUNLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 4,
263 CEPH_OSD_OP_UPLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 5,
264 CEPH_OSD_OP_DNLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 6,
265
266 /** exec **/
267 /* note: the RD bit here is wrong; see special-case below in helper */
268 CEPH_OSD_OP_CALL = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_EXEC | 1,
269
270 /** pg **/
271 CEPH_OSD_OP_PGLS = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_PG | 1,
272 CEPH_OSD_OP_PGLS_FILTER = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_PG | 2,
273 };
274
ceph_osd_op_type_lock(int op)275 static inline int ceph_osd_op_type_lock(int op)
276 {
277 return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_LOCK;
278 }
ceph_osd_op_type_data(int op)279 static inline int ceph_osd_op_type_data(int op)
280 {
281 return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_DATA;
282 }
ceph_osd_op_type_attr(int op)283 static inline int ceph_osd_op_type_attr(int op)
284 {
285 return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_ATTR;
286 }
ceph_osd_op_type_exec(int op)287 static inline int ceph_osd_op_type_exec(int op)
288 {
289 return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_EXEC;
290 }
ceph_osd_op_type_pg(int op)291 static inline int ceph_osd_op_type_pg(int op)
292 {
293 return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_PG;
294 }
ceph_osd_op_type_multi(int op)295 static inline int ceph_osd_op_type_multi(int op)
296 {
297 return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_MULTI;
298 }
299
ceph_osd_op_mode_subop(int op)300 static inline int ceph_osd_op_mode_subop(int op)
301 {
302 return (op & CEPH_OSD_OP_MODE) == CEPH_OSD_OP_MODE_SUB;
303 }
ceph_osd_op_mode_read(int op)304 static inline int ceph_osd_op_mode_read(int op)
305 {
306 return (op & CEPH_OSD_OP_MODE_RD) &&
307 op != CEPH_OSD_OP_CALL;
308 }
ceph_osd_op_mode_modify(int op)309 static inline int ceph_osd_op_mode_modify(int op)
310 {
311 return op & CEPH_OSD_OP_MODE_WR;
312 }
313
314 /*
315 * note that the following tmap stuff is also defined in the ceph librados.h
316 * any modification here needs to be updated there
317 */
318 #define CEPH_OSD_TMAP_HDR 'h'
319 #define CEPH_OSD_TMAP_SET 's'
320 #define CEPH_OSD_TMAP_CREATE 'c' /* create key */
321 #define CEPH_OSD_TMAP_RM 'r'
322 #define CEPH_OSD_TMAP_RMSLOPPY 'R'
323
324 extern const char *ceph_osd_op_name(int op);
325
326 /*
327 * osd op flags
328 *
329 * An op may be READ, WRITE, or READ|WRITE.
330 */
331 enum {
332 CEPH_OSD_FLAG_ACK = 0x0001, /* want (or is) "ack" ack */
333 CEPH_OSD_FLAG_ONNVRAM = 0x0002, /* want (or is) "onnvram" ack */
334 CEPH_OSD_FLAG_ONDISK = 0x0004, /* want (or is) "ondisk" ack */
335 CEPH_OSD_FLAG_RETRY = 0x0008, /* resend attempt */
336 CEPH_OSD_FLAG_READ = 0x0010, /* op may read */
337 CEPH_OSD_FLAG_WRITE = 0x0020, /* op may write */
338 CEPH_OSD_FLAG_ORDERSNAP = 0x0040, /* EOLDSNAP if snapc is out of order */
339 CEPH_OSD_FLAG_PEERSTAT_OLD = 0x0080, /* DEPRECATED msg includes osd_peer_stat */
340 CEPH_OSD_FLAG_BALANCE_READS = 0x0100,
341 CEPH_OSD_FLAG_PARALLELEXEC = 0x0200, /* execute op in parallel */
342 CEPH_OSD_FLAG_PGOP = 0x0400, /* pg op, no object */
343 CEPH_OSD_FLAG_EXEC = 0x0800, /* op may exec */
344 CEPH_OSD_FLAG_EXEC_PUBLIC = 0x1000, /* DEPRECATED op may exec (public) */
345 CEPH_OSD_FLAG_LOCALIZE_READS = 0x2000, /* read from nearby replica, if any */
346 CEPH_OSD_FLAG_RWORDERED = 0x4000, /* order wrt concurrent reads */
347 };
348
349 enum {
350 CEPH_OSD_OP_FLAG_EXCL = 1, /* EXCL object create */
351 CEPH_OSD_OP_FLAG_FAILOK = 2, /* continue despite failure */
352 };
353
354 #define EOLDSNAPC ERESTART /* ORDERSNAP flag set; writer has old snapc*/
355 #define EBLACKLISTED ESHUTDOWN /* blacklisted */
356
357 /* xattr comparison */
358 enum {
359 CEPH_OSD_CMPXATTR_OP_NOP = 0,
360 CEPH_OSD_CMPXATTR_OP_EQ = 1,
361 CEPH_OSD_CMPXATTR_OP_NE = 2,
362 CEPH_OSD_CMPXATTR_OP_GT = 3,
363 CEPH_OSD_CMPXATTR_OP_GTE = 4,
364 CEPH_OSD_CMPXATTR_OP_LT = 5,
365 CEPH_OSD_CMPXATTR_OP_LTE = 6
366 };
367
368 enum {
369 CEPH_OSD_CMPXATTR_MODE_STRING = 1,
370 CEPH_OSD_CMPXATTR_MODE_U64 = 2
371 };
372
373 #define RADOS_NOTIFY_VER 1
374
375 /*
376 * an individual object operation. each may be accompanied by some data
377 * payload
378 */
379 struct ceph_osd_op {
380 __le16 op; /* CEPH_OSD_OP_* */
381 __le32 flags; /* CEPH_OSD_FLAG_* */
382 union {
383 struct {
384 __le64 offset, length;
385 __le64 truncate_size;
386 __le32 truncate_seq;
387 } __attribute__ ((packed)) extent;
388 struct {
389 __le32 name_len;
390 __le32 value_len;
391 __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
392 __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
393 } __attribute__ ((packed)) xattr;
394 struct {
395 __u8 class_len;
396 __u8 method_len;
397 __u8 argc;
398 __le32 indata_len;
399 } __attribute__ ((packed)) cls;
400 struct {
401 __le64 cookie, count;
402 } __attribute__ ((packed)) pgls;
403 struct {
404 __le64 snapid;
405 } __attribute__ ((packed)) snap;
406 struct {
407 __le64 cookie;
408 __le64 ver;
409 __u8 flag; /* 0 = unwatch, 1 = watch */
410 } __attribute__ ((packed)) watch;
411 struct {
412 __le64 offset, length;
413 __le64 src_offset;
414 } __attribute__ ((packed)) clonerange;
415 };
416 __le32 payload_len;
417 } __attribute__ ((packed));
418
419
420 #endif
421