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 */
14struct ceph_fsid {
15	unsigned char fsid[16];
16};
17
18static 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 */
27typedef __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
32struct 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 */
59struct 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_POOL_TYPE_REP     1
85#define CEPH_POOL_TYPE_RAID4   2 /* never implemented */
86#define CEPH_POOL_TYPE_EC      3
87
88/*
89 * stable_mod func is used to control number of placement groups.
90 * similar to straight-up modulo, but produces a stable mapping as b
91 * increases over time.  b is the number of bins, and bmask is the
92 * containing power of 2 minus 1.
93 *
94 * b <= bmask and bmask=(2**n)-1
95 * e.g., b=12 -> bmask=15, b=123 -> bmask=127
96 */
97static inline int ceph_stable_mod(int x, int b, int bmask)
98{
99	if ((x & bmask) < b)
100		return x & bmask;
101	else
102		return x & (bmask >> 1);
103}
104
105/*
106 * object layout - how a given object should be stored.
107 */
108struct ceph_object_layout {
109	struct ceph_pg_v1 ol_pgid;   /* raw pg, with _full_ ps precision. */
110	__le32 ol_stripe_unit;    /* for per-object parity, if any */
111} __attribute__ ((packed));
112
113/*
114 * compound epoch+version, used by storage layer to serialize mutations
115 */
116struct ceph_eversion {
117	__le32 epoch;
118	__le64 version;
119} __attribute__ ((packed));
120
121/*
122 * osd map bits
123 */
124
125/* status bits */
126#define CEPH_OSD_EXISTS  (1<<0)
127#define CEPH_OSD_UP      (1<<1)
128#define CEPH_OSD_AUTOOUT (1<<2)  /* osd was automatically marked out */
129#define CEPH_OSD_NEW     (1<<3)  /* osd is new, never marked in */
130
131extern const char *ceph_osd_state_name(int s);
132
133/* osd weights.  fixed point value: 0x10000 == 1.0 ("in"), 0 == "out" */
134#define CEPH_OSD_IN  0x10000
135#define CEPH_OSD_OUT 0
136
137/* osd primary-affinity.  fixed point value: 0x10000 == baseline */
138#define CEPH_OSD_MAX_PRIMARY_AFFINITY 0x10000
139#define CEPH_OSD_DEFAULT_PRIMARY_AFFINITY 0x10000
140
141
142/*
143 * osd map flag bits
144 */
145#define CEPH_OSDMAP_NEARFULL (1<<0)  /* sync writes (near ENOSPC) */
146#define CEPH_OSDMAP_FULL     (1<<1)  /* no data writes (ENOSPC) */
147#define CEPH_OSDMAP_PAUSERD  (1<<2)  /* pause all reads */
148#define CEPH_OSDMAP_PAUSEWR  (1<<3)  /* pause all writes */
149#define CEPH_OSDMAP_PAUSEREC (1<<4)  /* pause recovery */
150#define CEPH_OSDMAP_NOUP     (1<<5)  /* block osd boot */
151#define CEPH_OSDMAP_NODOWN   (1<<6)  /* block osd mark-down/failure */
152#define CEPH_OSDMAP_NOOUT    (1<<7)  /* block osd auto mark-out */
153#define CEPH_OSDMAP_NOIN     (1<<8)  /* block osd auto mark-in */
154#define CEPH_OSDMAP_NOBACKFILL (1<<9) /* block osd backfill */
155#define CEPH_OSDMAP_NORECOVER (1<<10) /* block osd recovery and backfill */
156
157/*
158 * The error code to return when an OSD can't handle a write
159 * because it is too large.
160 */
161#define OSD_WRITETOOBIG EMSGSIZE
162
163/*
164 * osd ops
165 *
166 * WARNING: do not use these op codes directly.  Use the helpers
167 * defined below instead.  In certain cases, op code behavior was
168 * redefined, resulting in special-cases in the helpers.
169 */
170#define CEPH_OSD_OP_MODE       0xf000
171#define CEPH_OSD_OP_MODE_RD    0x1000
172#define CEPH_OSD_OP_MODE_WR    0x2000
173#define CEPH_OSD_OP_MODE_RMW   0x3000
174#define CEPH_OSD_OP_MODE_SUB   0x4000
175#define CEPH_OSD_OP_MODE_CACHE 0x8000
176
177#define CEPH_OSD_OP_TYPE       0x0f00
178#define CEPH_OSD_OP_TYPE_LOCK  0x0100
179#define CEPH_OSD_OP_TYPE_DATA  0x0200
180#define CEPH_OSD_OP_TYPE_ATTR  0x0300
181#define CEPH_OSD_OP_TYPE_EXEC  0x0400
182#define CEPH_OSD_OP_TYPE_PG    0x0500
183#define CEPH_OSD_OP_TYPE_MULTI 0x0600 /* multiobject */
184
185#define __CEPH_OSD_OP1(mode, nr) \
186	(CEPH_OSD_OP_MODE_##mode | (nr))
187
188#define __CEPH_OSD_OP(mode, type, nr) \
189	(CEPH_OSD_OP_MODE_##mode | CEPH_OSD_OP_TYPE_##type | (nr))
190
191#define __CEPH_FORALL_OSD_OPS(f)					    \
192	/** data **/							    \
193	/* read */							    \
194	f(READ,		__CEPH_OSD_OP(RD, DATA, 1),	"read")		    \
195	f(STAT,		__CEPH_OSD_OP(RD, DATA, 2),	"stat")		    \
196	f(MAPEXT,	__CEPH_OSD_OP(RD, DATA, 3),	"mapext")	    \
197									    \
198	/* fancy read */						    \
199	f(MASKTRUNC,	__CEPH_OSD_OP(RD, DATA, 4),	"masktrunc")	    \
200	f(SPARSE_READ,	__CEPH_OSD_OP(RD, DATA, 5),	"sparse-read")	    \
201									    \
202	f(NOTIFY,	__CEPH_OSD_OP(RD, DATA, 6),	"notify")	    \
203	f(NOTIFY_ACK,	__CEPH_OSD_OP(RD, DATA, 7),	"notify-ack")	    \
204									    \
205	/* versioning */						    \
206	f(ASSERT_VER,	__CEPH_OSD_OP(RD, DATA, 8),	"assert-version")   \
207									    \
208	f(LIST_WATCHERS, __CEPH_OSD_OP(RD, DATA, 9),	"list-watchers")    \
209									    \
210	f(LIST_SNAPS,	__CEPH_OSD_OP(RD, DATA, 10),	"list-snaps")	    \
211									    \
212	/* sync */							    \
213	f(SYNC_READ,	__CEPH_OSD_OP(RD, DATA, 11),	"sync_read")	    \
214									    \
215	/* write */							    \
216	f(WRITE,	__CEPH_OSD_OP(WR, DATA, 1),	"write")	    \
217	f(WRITEFULL,	__CEPH_OSD_OP(WR, DATA, 2),	"writefull")	    \
218	f(TRUNCATE,	__CEPH_OSD_OP(WR, DATA, 3),	"truncate")	    \
219	f(ZERO,		__CEPH_OSD_OP(WR, DATA, 4),	"zero")		    \
220	f(DELETE,	__CEPH_OSD_OP(WR, DATA, 5),	"delete")	    \
221									    \
222	/* fancy write */						    \
223	f(APPEND,	__CEPH_OSD_OP(WR, DATA, 6),	"append")	    \
224	f(STARTSYNC,	__CEPH_OSD_OP(WR, DATA, 7),	"startsync")	    \
225	f(SETTRUNC,	__CEPH_OSD_OP(WR, DATA, 8),	"settrunc")	    \
226	f(TRIMTRUNC,	__CEPH_OSD_OP(WR, DATA, 9),	"trimtrunc")	    \
227									    \
228	f(TMAPUP,	__CEPH_OSD_OP(RMW, DATA, 10),	"tmapup")	    \
229	f(TMAPPUT,	__CEPH_OSD_OP(WR, DATA, 11),	"tmapput")	    \
230	f(TMAPGET,	__CEPH_OSD_OP(RD, DATA, 12),	"tmapget")	    \
231									    \
232	f(CREATE,	__CEPH_OSD_OP(WR, DATA, 13),	"create")	    \
233	f(ROLLBACK,	__CEPH_OSD_OP(WR, DATA, 14),	"rollback")	    \
234									    \
235	f(WATCH,	__CEPH_OSD_OP(WR, DATA, 15),	"watch")	    \
236									    \
237	/* omap */							    \
238	f(OMAPGETKEYS,	__CEPH_OSD_OP(RD, DATA, 17),	"omap-get-keys")    \
239	f(OMAPGETVALS,	__CEPH_OSD_OP(RD, DATA, 18),	"omap-get-vals")    \
240	f(OMAPGETHEADER, __CEPH_OSD_OP(RD, DATA, 19),	"omap-get-header")  \
241	f(OMAPGETVALSBYKEYS, __CEPH_OSD_OP(RD, DATA, 20), "omap-get-vals-by-keys") \
242	f(OMAPSETVALS,	__CEPH_OSD_OP(WR, DATA, 21),	"omap-set-vals")    \
243	f(OMAPSETHEADER, __CEPH_OSD_OP(WR, DATA, 22),	"omap-set-header")  \
244	f(OMAPCLEAR,	__CEPH_OSD_OP(WR, DATA, 23),	"omap-clear")	    \
245	f(OMAPRMKEYS,	__CEPH_OSD_OP(WR, DATA, 24),	"omap-rm-keys")	    \
246	f(OMAP_CMP,	__CEPH_OSD_OP(RD, DATA, 25),	"omap-cmp")	    \
247									    \
248	/* tiering */							    \
249	f(COPY_FROM,	__CEPH_OSD_OP(WR, DATA, 26),	"copy-from")	    \
250	f(COPY_GET_CLASSIC, __CEPH_OSD_OP(RD, DATA, 27), "copy-get-classic") \
251	f(UNDIRTY,	__CEPH_OSD_OP(WR, DATA, 28),	"undirty")	    \
252	f(ISDIRTY,	__CEPH_OSD_OP(RD, DATA, 29),	"isdirty")	    \
253	f(COPY_GET,	__CEPH_OSD_OP(RD, DATA, 30),	"copy-get")	    \
254	f(CACHE_FLUSH,	__CEPH_OSD_OP(CACHE, DATA, 31),	"cache-flush")	    \
255	f(CACHE_EVICT,	__CEPH_OSD_OP(CACHE, DATA, 32),	"cache-evict")	    \
256	f(CACHE_TRY_FLUSH, __CEPH_OSD_OP(CACHE, DATA, 33), "cache-try-flush") \
257									    \
258	/* convert tmap to omap */					    \
259	f(TMAP2OMAP,	__CEPH_OSD_OP(RMW, DATA, 34),	"tmap2omap")	    \
260									    \
261	/* hints */							    \
262	f(SETALLOCHINT,	__CEPH_OSD_OP(WR, DATA, 35),	"set-alloc-hint")   \
263									    \
264	/** multi **/							    \
265	f(CLONERANGE,	__CEPH_OSD_OP(WR, MULTI, 1),	"clonerange")	    \
266	f(ASSERT_SRC_VERSION, __CEPH_OSD_OP(RD, MULTI, 2), "assert-src-version") \
267	f(SRC_CMPXATTR,	__CEPH_OSD_OP(RD, MULTI, 3),	"src-cmpxattr")	    \
268									    \
269	/** attrs **/							    \
270	/* read */							    \
271	f(GETXATTR,	__CEPH_OSD_OP(RD, ATTR, 1),	"getxattr")	    \
272	f(GETXATTRS,	__CEPH_OSD_OP(RD, ATTR, 2),	"getxattrs")	    \
273	f(CMPXATTR,	__CEPH_OSD_OP(RD, ATTR, 3),	"cmpxattr")	    \
274									    \
275	/* write */							    \
276	f(SETXATTR,	__CEPH_OSD_OP(WR, ATTR, 1),	"setxattr")	    \
277	f(SETXATTRS,	__CEPH_OSD_OP(WR, ATTR, 2),	"setxattrs")	    \
278	f(RESETXATTRS,	__CEPH_OSD_OP(WR, ATTR, 3),	"resetxattrs")	    \
279	f(RMXATTR,	__CEPH_OSD_OP(WR, ATTR, 4),	"rmxattr")	    \
280									    \
281	/** subop **/							    \
282	f(PULL,		__CEPH_OSD_OP1(SUB, 1),		"pull")		    \
283	f(PUSH,		__CEPH_OSD_OP1(SUB, 2),		"push")		    \
284	f(BALANCEREADS,	__CEPH_OSD_OP1(SUB, 3),		"balance-reads")    \
285	f(UNBALANCEREADS, __CEPH_OSD_OP1(SUB, 4),	"unbalance-reads")  \
286	f(SCRUB,	__CEPH_OSD_OP1(SUB, 5),		"scrub")	    \
287	f(SCRUB_RESERVE, __CEPH_OSD_OP1(SUB, 6),	"scrub-reserve")    \
288	f(SCRUB_UNRESERVE, __CEPH_OSD_OP1(SUB, 7),	"scrub-unreserve")  \
289	f(SCRUB_STOP,	__CEPH_OSD_OP1(SUB, 8),		"scrub-stop")	    \
290	f(SCRUB_MAP,	__CEPH_OSD_OP1(SUB, 9),		"scrub-map")	    \
291									    \
292	/** lock **/							    \
293	f(WRLOCK,	__CEPH_OSD_OP(WR, LOCK, 1),	"wrlock")	    \
294	f(WRUNLOCK,	__CEPH_OSD_OP(WR, LOCK, 2),	"wrunlock")	    \
295	f(RDLOCK,	__CEPH_OSD_OP(WR, LOCK, 3),	"rdlock")	    \
296	f(RDUNLOCK,	__CEPH_OSD_OP(WR, LOCK, 4),	"rdunlock")	    \
297	f(UPLOCK,	__CEPH_OSD_OP(WR, LOCK, 5),	"uplock")	    \
298	f(DNLOCK,	__CEPH_OSD_OP(WR, LOCK, 6),	"dnlock")	    \
299									    \
300	/** exec **/							    \
301	/* note: the RD bit here is wrong; see special-case below in helper */ \
302	f(CALL,		__CEPH_OSD_OP(RD, EXEC, 1),	"call")		    \
303									    \
304	/** pg **/							    \
305	f(PGLS,		__CEPH_OSD_OP(RD, PG, 1),	"pgls")		    \
306	f(PGLS_FILTER,	__CEPH_OSD_OP(RD, PG, 2),	"pgls-filter")	    \
307	f(PG_HITSET_LS,	__CEPH_OSD_OP(RD, PG, 3),	"pg-hitset-ls")	    \
308	f(PG_HITSET_GET, __CEPH_OSD_OP(RD, PG, 4),	"pg-hitset-get")
309
310enum {
311#define GENERATE_ENUM_ENTRY(op, opcode, str)	CEPH_OSD_OP_##op = (opcode),
312__CEPH_FORALL_OSD_OPS(GENERATE_ENUM_ENTRY)
313#undef GENERATE_ENUM_ENTRY
314};
315
316static inline int ceph_osd_op_type_lock(int op)
317{
318	return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_LOCK;
319}
320static inline int ceph_osd_op_type_data(int op)
321{
322	return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_DATA;
323}
324static inline int ceph_osd_op_type_attr(int op)
325{
326	return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_ATTR;
327}
328static inline int ceph_osd_op_type_exec(int op)
329{
330	return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_EXEC;
331}
332static inline int ceph_osd_op_type_pg(int op)
333{
334	return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_PG;
335}
336static inline int ceph_osd_op_type_multi(int op)
337{
338	return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_MULTI;
339}
340
341static inline int ceph_osd_op_mode_subop(int op)
342{
343	return (op & CEPH_OSD_OP_MODE) == CEPH_OSD_OP_MODE_SUB;
344}
345static inline int ceph_osd_op_mode_read(int op)
346{
347	return (op & CEPH_OSD_OP_MODE_RD) &&
348		op != CEPH_OSD_OP_CALL;
349}
350static inline int ceph_osd_op_mode_modify(int op)
351{
352	return op & CEPH_OSD_OP_MODE_WR;
353}
354
355/*
356 * note that the following tmap stuff is also defined in the ceph librados.h
357 * any modification here needs to be updated there
358 */
359#define CEPH_OSD_TMAP_HDR 'h'
360#define CEPH_OSD_TMAP_SET 's'
361#define CEPH_OSD_TMAP_CREATE 'c' /* create key */
362#define CEPH_OSD_TMAP_RM  'r'
363#define CEPH_OSD_TMAP_RMSLOPPY 'R'
364
365extern const char *ceph_osd_op_name(int op);
366
367/*
368 * osd op flags
369 *
370 * An op may be READ, WRITE, or READ|WRITE.
371 */
372enum {
373	CEPH_OSD_FLAG_ACK =            0x0001,  /* want (or is) "ack" ack */
374	CEPH_OSD_FLAG_ONNVRAM =        0x0002,  /* want (or is) "onnvram" ack */
375	CEPH_OSD_FLAG_ONDISK =         0x0004,  /* want (or is) "ondisk" ack */
376	CEPH_OSD_FLAG_RETRY =          0x0008,  /* resend attempt */
377	CEPH_OSD_FLAG_READ =           0x0010,  /* op may read */
378	CEPH_OSD_FLAG_WRITE =          0x0020,  /* op may write */
379	CEPH_OSD_FLAG_ORDERSNAP =      0x0040,  /* EOLDSNAP if snapc is out of order */
380	CEPH_OSD_FLAG_PEERSTAT_OLD =   0x0080,  /* DEPRECATED msg includes osd_peer_stat */
381	CEPH_OSD_FLAG_BALANCE_READS =  0x0100,
382	CEPH_OSD_FLAG_PARALLELEXEC =   0x0200,  /* execute op in parallel */
383	CEPH_OSD_FLAG_PGOP =           0x0400,  /* pg op, no object */
384	CEPH_OSD_FLAG_EXEC =           0x0800,  /* op may exec */
385	CEPH_OSD_FLAG_EXEC_PUBLIC =    0x1000,  /* DEPRECATED op may exec (public) */
386	CEPH_OSD_FLAG_LOCALIZE_READS = 0x2000,  /* read from nearby replica, if any */
387	CEPH_OSD_FLAG_RWORDERED =      0x4000,  /* order wrt concurrent reads */
388	CEPH_OSD_FLAG_IGNORE_CACHE =   0x8000,  /* ignore cache logic */
389	CEPH_OSD_FLAG_SKIPRWLOCKS =   0x10000,  /* skip rw locks */
390	CEPH_OSD_FLAG_IGNORE_OVERLAY = 0x20000, /* ignore pool overlay */
391	CEPH_OSD_FLAG_FLUSH =         0x40000,  /* this is part of flush */
392};
393
394enum {
395	CEPH_OSD_OP_FLAG_EXCL = 1,      /* EXCL object create */
396	CEPH_OSD_OP_FLAG_FAILOK = 2,    /* continue despite failure */
397};
398
399#define EOLDSNAPC    ERESTART  /* ORDERSNAP flag set; writer has old snapc*/
400#define EBLACKLISTED ESHUTDOWN /* blacklisted */
401
402/* xattr comparison */
403enum {
404	CEPH_OSD_CMPXATTR_OP_NOP = 0,
405	CEPH_OSD_CMPXATTR_OP_EQ  = 1,
406	CEPH_OSD_CMPXATTR_OP_NE  = 2,
407	CEPH_OSD_CMPXATTR_OP_GT  = 3,
408	CEPH_OSD_CMPXATTR_OP_GTE = 4,
409	CEPH_OSD_CMPXATTR_OP_LT  = 5,
410	CEPH_OSD_CMPXATTR_OP_LTE = 6
411};
412
413enum {
414	CEPH_OSD_CMPXATTR_MODE_STRING = 1,
415	CEPH_OSD_CMPXATTR_MODE_U64    = 2
416};
417
418#define RADOS_NOTIFY_VER	1
419
420/*
421 * an individual object operation.  each may be accompanied by some data
422 * payload
423 */
424struct ceph_osd_op {
425	__le16 op;           /* CEPH_OSD_OP_* */
426	__le32 flags;        /* CEPH_OSD_OP_FLAG_* */
427	union {
428		struct {
429			__le64 offset, length;
430			__le64 truncate_size;
431			__le32 truncate_seq;
432		} __attribute__ ((packed)) extent;
433		struct {
434			__le32 name_len;
435			__le32 value_len;
436			__u8 cmp_op;       /* CEPH_OSD_CMPXATTR_OP_* */
437			__u8 cmp_mode;     /* CEPH_OSD_CMPXATTR_MODE_* */
438		} __attribute__ ((packed)) xattr;
439		struct {
440			__u8 class_len;
441			__u8 method_len;
442			__u8 argc;
443			__le32 indata_len;
444		} __attribute__ ((packed)) cls;
445		struct {
446			__le64 cookie, count;
447		} __attribute__ ((packed)) pgls;
448	        struct {
449		        __le64 snapid;
450	        } __attribute__ ((packed)) snap;
451		struct {
452			__le64 cookie;
453			__le64 ver;
454			__u8 flag;	/* 0 = unwatch, 1 = watch */
455		} __attribute__ ((packed)) watch;
456		struct {
457			__le64 offset, length;
458			__le64 src_offset;
459		} __attribute__ ((packed)) clonerange;
460		struct {
461			__le64 expected_object_size;
462			__le64 expected_write_size;
463		} __attribute__ ((packed)) alloc_hint;
464	};
465	__le32 payload_len;
466} __attribute__ ((packed));
467
468
469#endif
470