diff options
Diffstat (limited to 'fs/ceph/rados.h')
-rw-r--r-- | fs/ceph/rados.h | 374 |
1 files changed, 374 insertions, 0 deletions
diff --git a/fs/ceph/rados.h b/fs/ceph/rados.h new file mode 100644 index 000000000000..26ac8b89a676 --- /dev/null +++ b/fs/ceph/rados.h | |||
@@ -0,0 +1,374 @@ | |||
1 | #ifndef __RADOS_H | ||
2 | #define __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 "msgr.h" | ||
10 | |||
11 | /* | ||
12 | * osdmap encoding versions | ||
13 | */ | ||
14 | #define CEPH_OSDMAP_INC_VERSION 4 | ||
15 | #define CEPH_OSDMAP_VERSION 4 | ||
16 | |||
17 | /* | ||
18 | * fs id | ||
19 | */ | ||
20 | struct ceph_fsid { | ||
21 | unsigned char fsid[16]; | ||
22 | }; | ||
23 | |||
24 | static inline int ceph_fsid_compare(const struct ceph_fsid *a, | ||
25 | const struct ceph_fsid *b) | ||
26 | { | ||
27 | return memcmp(a, b, sizeof(*a)); | ||
28 | } | ||
29 | |||
30 | /* | ||
31 | * ino, object, etc. | ||
32 | */ | ||
33 | typedef __le64 ceph_snapid_t; | ||
34 | #define CEPH_SNAPDIR ((__u64)(-1)) /* reserved for hidden .snap dir */ | ||
35 | #define CEPH_NOSNAP ((__u64)(-2)) /* "head", "live" revision */ | ||
36 | #define CEPH_MAXSNAP ((__u64)(-3)) /* largest valid snapid */ | ||
37 | |||
38 | struct ceph_timespec { | ||
39 | __le32 tv_sec; | ||
40 | __le32 tv_nsec; | ||
41 | } __attribute__ ((packed)); | ||
42 | |||
43 | |||
44 | /* | ||
45 | * object layout - how objects are mapped into PGs | ||
46 | */ | ||
47 | #define CEPH_OBJECT_LAYOUT_HASH 1 | ||
48 | #define CEPH_OBJECT_LAYOUT_LINEAR 2 | ||
49 | #define CEPH_OBJECT_LAYOUT_HASHINO 3 | ||
50 | |||
51 | /* | ||
52 | * pg layout -- how PGs are mapped onto (sets of) OSDs | ||
53 | */ | ||
54 | #define CEPH_PG_LAYOUT_CRUSH 0 | ||
55 | #define CEPH_PG_LAYOUT_HASH 1 | ||
56 | #define CEPH_PG_LAYOUT_LINEAR 2 | ||
57 | #define CEPH_PG_LAYOUT_HYBRID 3 | ||
58 | |||
59 | |||
60 | /* | ||
61 | * placement group. | ||
62 | * we encode this into one __le64. | ||
63 | */ | ||
64 | struct ceph_pg { | ||
65 | __le16 preferred; /* preferred primary osd */ | ||
66 | __le16 ps; /* placement seed */ | ||
67 | __le32 pool; /* object pool */ | ||
68 | } __attribute__ ((packed)); | ||
69 | |||
70 | /* | ||
71 | * pg_pool is a set of pgs storing a pool of objects | ||
72 | * | ||
73 | * pg_num -- base number of pseudorandomly placed pgs | ||
74 | * | ||
75 | * pgp_num -- effective number when calculating pg placement. this | ||
76 | * is used for pg_num increases. new pgs result in data being "split" | ||
77 | * into new pgs. for this to proceed smoothly, new pgs are intiially | ||
78 | * colocated with their parents; that is, pgp_num doesn't increase | ||
79 | * until the new pgs have successfully split. only _then_ are the new | ||
80 | * pgs placed independently. | ||
81 | * | ||
82 | * lpg_num -- localized pg count (per device). replicas are randomly | ||
83 | * selected. | ||
84 | * | ||
85 | * lpgp_num -- as above. | ||
86 | */ | ||
87 | #define CEPH_PG_TYPE_REP 1 | ||
88 | #define CEPH_PG_TYPE_RAID4 2 | ||
89 | #define CEPH_PG_POOL_VERSION 2 | ||
90 | struct ceph_pg_pool { | ||
91 | __u8 type; /* CEPH_PG_TYPE_* */ | ||
92 | __u8 size; /* number of osds in each pg */ | ||
93 | __u8 crush_ruleset; /* crush placement rule */ | ||
94 | __u8 object_hash; /* hash mapping object name to ps */ | ||
95 | __le32 pg_num, pgp_num; /* number of pg's */ | ||
96 | __le32 lpg_num, lpgp_num; /* number of localized pg's */ | ||
97 | __le32 last_change; /* most recent epoch changed */ | ||
98 | __le64 snap_seq; /* seq for per-pool snapshot */ | ||
99 | __le32 snap_epoch; /* epoch of last snap */ | ||
100 | __le32 num_snaps; | ||
101 | __le32 num_removed_snap_intervals; | ||
102 | __le64 uid; | ||
103 | } __attribute__ ((packed)); | ||
104 | |||
105 | /* | ||
106 | * stable_mod func is used to control number of placement groups. | ||
107 | * similar to straight-up modulo, but produces a stable mapping as b | ||
108 | * increases over time. b is the number of bins, and bmask is the | ||
109 | * containing power of 2 minus 1. | ||
110 | * | ||
111 | * b <= bmask and bmask=(2**n)-1 | ||
112 | * e.g., b=12 -> bmask=15, b=123 -> bmask=127 | ||
113 | */ | ||
114 | static inline int ceph_stable_mod(int x, int b, int bmask) | ||
115 | { | ||
116 | if ((x & bmask) < b) | ||
117 | return x & bmask; | ||
118 | else | ||
119 | return x & (bmask >> 1); | ||
120 | } | ||
121 | |||
122 | /* | ||
123 | * object layout - how a given object should be stored. | ||
124 | */ | ||
125 | struct ceph_object_layout { | ||
126 | struct ceph_pg ol_pgid; /* raw pg, with _full_ ps precision. */ | ||
127 | __le32 ol_stripe_unit; /* for per-object parity, if any */ | ||
128 | } __attribute__ ((packed)); | ||
129 | |||
130 | /* | ||
131 | * compound epoch+version, used by storage layer to serialize mutations | ||
132 | */ | ||
133 | struct ceph_eversion { | ||
134 | __le32 epoch; | ||
135 | __le64 version; | ||
136 | } __attribute__ ((packed)); | ||
137 | |||
138 | /* | ||
139 | * osd map bits | ||
140 | */ | ||
141 | |||
142 | /* status bits */ | ||
143 | #define CEPH_OSD_EXISTS 1 | ||
144 | #define CEPH_OSD_UP 2 | ||
145 | |||
146 | /* osd weights. fixed point value: 0x10000 == 1.0 ("in"), 0 == "out" */ | ||
147 | #define CEPH_OSD_IN 0x10000 | ||
148 | #define CEPH_OSD_OUT 0 | ||
149 | |||
150 | |||
151 | /* | ||
152 | * osd map flag bits | ||
153 | */ | ||
154 | #define CEPH_OSDMAP_NEARFULL (1<<0) /* sync writes (near ENOSPC) */ | ||
155 | #define CEPH_OSDMAP_FULL (1<<1) /* no data writes (ENOSPC) */ | ||
156 | #define CEPH_OSDMAP_PAUSERD (1<<2) /* pause all reads */ | ||
157 | #define CEPH_OSDMAP_PAUSEWR (1<<3) /* pause all writes */ | ||
158 | #define CEPH_OSDMAP_PAUSEREC (1<<4) /* pause recovery */ | ||
159 | |||
160 | /* | ||
161 | * osd ops | ||
162 | */ | ||
163 | #define CEPH_OSD_OP_MODE 0xf000 | ||
164 | #define CEPH_OSD_OP_MODE_RD 0x1000 | ||
165 | #define CEPH_OSD_OP_MODE_WR 0x2000 | ||
166 | #define CEPH_OSD_OP_MODE_RMW 0x3000 | ||
167 | #define CEPH_OSD_OP_MODE_SUB 0x4000 | ||
168 | |||
169 | #define CEPH_OSD_OP_TYPE 0x0f00 | ||
170 | #define CEPH_OSD_OP_TYPE_LOCK 0x0100 | ||
171 | #define CEPH_OSD_OP_TYPE_DATA 0x0200 | ||
172 | #define CEPH_OSD_OP_TYPE_ATTR 0x0300 | ||
173 | #define CEPH_OSD_OP_TYPE_EXEC 0x0400 | ||
174 | #define CEPH_OSD_OP_TYPE_PG 0x0500 | ||
175 | |||
176 | enum { | ||
177 | /** data **/ | ||
178 | /* read */ | ||
179 | CEPH_OSD_OP_READ = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 1, | ||
180 | CEPH_OSD_OP_STAT = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 2, | ||
181 | |||
182 | /* fancy read */ | ||
183 | CEPH_OSD_OP_MASKTRUNC = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 4, | ||
184 | |||
185 | /* write */ | ||
186 | CEPH_OSD_OP_WRITE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 1, | ||
187 | CEPH_OSD_OP_WRITEFULL = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 2, | ||
188 | CEPH_OSD_OP_TRUNCATE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 3, | ||
189 | CEPH_OSD_OP_ZERO = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 4, | ||
190 | CEPH_OSD_OP_DELETE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 5, | ||
191 | |||
192 | /* fancy write */ | ||
193 | CEPH_OSD_OP_APPEND = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 6, | ||
194 | CEPH_OSD_OP_STARTSYNC = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 7, | ||
195 | CEPH_OSD_OP_SETTRUNC = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 8, | ||
196 | CEPH_OSD_OP_TRIMTRUNC = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 9, | ||
197 | |||
198 | CEPH_OSD_OP_TMAPUP = CEPH_OSD_OP_MODE_RMW | CEPH_OSD_OP_TYPE_DATA | 10, | ||
199 | CEPH_OSD_OP_TMAPPUT = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 11, | ||
200 | CEPH_OSD_OP_TMAPGET = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 12, | ||
201 | |||
202 | CEPH_OSD_OP_CREATE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 13, | ||
203 | |||
204 | /** attrs **/ | ||
205 | /* read */ | ||
206 | CEPH_OSD_OP_GETXATTR = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_ATTR | 1, | ||
207 | CEPH_OSD_OP_GETXATTRS = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_ATTR | 2, | ||
208 | |||
209 | /* write */ | ||
210 | CEPH_OSD_OP_SETXATTR = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_ATTR | 1, | ||
211 | CEPH_OSD_OP_SETXATTRS = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_ATTR | 2, | ||
212 | CEPH_OSD_OP_RESETXATTRS = CEPH_OSD_OP_MODE_WR|CEPH_OSD_OP_TYPE_ATTR | 3, | ||
213 | CEPH_OSD_OP_RMXATTR = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_ATTR | 4, | ||
214 | |||
215 | /** subop **/ | ||
216 | CEPH_OSD_OP_PULL = CEPH_OSD_OP_MODE_SUB | 1, | ||
217 | CEPH_OSD_OP_PUSH = CEPH_OSD_OP_MODE_SUB | 2, | ||
218 | CEPH_OSD_OP_BALANCEREADS = CEPH_OSD_OP_MODE_SUB | 3, | ||
219 | CEPH_OSD_OP_UNBALANCEREADS = CEPH_OSD_OP_MODE_SUB | 4, | ||
220 | CEPH_OSD_OP_SCRUB = CEPH_OSD_OP_MODE_SUB | 5, | ||
221 | |||
222 | /** lock **/ | ||
223 | CEPH_OSD_OP_WRLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 1, | ||
224 | CEPH_OSD_OP_WRUNLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 2, | ||
225 | CEPH_OSD_OP_RDLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 3, | ||
226 | CEPH_OSD_OP_RDUNLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 4, | ||
227 | CEPH_OSD_OP_UPLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 5, | ||
228 | CEPH_OSD_OP_DNLOCK = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_LOCK | 6, | ||
229 | |||
230 | /** exec **/ | ||
231 | CEPH_OSD_OP_CALL = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_EXEC | 1, | ||
232 | |||
233 | /** pg **/ | ||
234 | CEPH_OSD_OP_PGLS = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_PG | 1, | ||
235 | }; | ||
236 | |||
237 | static inline int ceph_osd_op_type_lock(int op) | ||
238 | { | ||
239 | return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_LOCK; | ||
240 | } | ||
241 | static inline int ceph_osd_op_type_data(int op) | ||
242 | { | ||
243 | return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_DATA; | ||
244 | } | ||
245 | static inline int ceph_osd_op_type_attr(int op) | ||
246 | { | ||
247 | return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_ATTR; | ||
248 | } | ||
249 | static inline int ceph_osd_op_type_exec(int op) | ||
250 | { | ||
251 | return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_EXEC; | ||
252 | } | ||
253 | static inline int ceph_osd_op_type_pg(int op) | ||
254 | { | ||
255 | return (op & CEPH_OSD_OP_TYPE) == CEPH_OSD_OP_TYPE_PG; | ||
256 | } | ||
257 | |||
258 | static inline int ceph_osd_op_mode_subop(int op) | ||
259 | { | ||
260 | return (op & CEPH_OSD_OP_MODE) == CEPH_OSD_OP_MODE_SUB; | ||
261 | } | ||
262 | static inline int ceph_osd_op_mode_read(int op) | ||
263 | { | ||
264 | return (op & CEPH_OSD_OP_MODE) == CEPH_OSD_OP_MODE_RD; | ||
265 | } | ||
266 | static inline int ceph_osd_op_mode_modify(int op) | ||
267 | { | ||
268 | return (op & CEPH_OSD_OP_MODE) == CEPH_OSD_OP_MODE_WR; | ||
269 | } | ||
270 | |||
271 | #define CEPH_OSD_TMAP_HDR 'h' | ||
272 | #define CEPH_OSD_TMAP_SET 's' | ||
273 | #define CEPH_OSD_TMAP_RM 'r' | ||
274 | |||
275 | extern const char *ceph_osd_op_name(int op); | ||
276 | |||
277 | |||
278 | /* | ||
279 | * osd op flags | ||
280 | * | ||
281 | * An op may be READ, WRITE, or READ|WRITE. | ||
282 | */ | ||
283 | enum { | ||
284 | CEPH_OSD_FLAG_ACK = 1, /* want (or is) "ack" ack */ | ||
285 | CEPH_OSD_FLAG_ONNVRAM = 2, /* want (or is) "onnvram" ack */ | ||
286 | CEPH_OSD_FLAG_ONDISK = 4, /* want (or is) "ondisk" ack */ | ||
287 | CEPH_OSD_FLAG_RETRY = 8, /* resend attempt */ | ||
288 | CEPH_OSD_FLAG_READ = 16, /* op may read */ | ||
289 | CEPH_OSD_FLAG_WRITE = 32, /* op may write */ | ||
290 | CEPH_OSD_FLAG_ORDERSNAP = 64, /* EOLDSNAP if snapc is out of order */ | ||
291 | CEPH_OSD_FLAG_PEERSTAT = 128, /* msg includes osd_peer_stat */ | ||
292 | CEPH_OSD_FLAG_BALANCE_READS = 256, | ||
293 | CEPH_OSD_FLAG_PARALLELEXEC = 512, /* execute op in parallel */ | ||
294 | CEPH_OSD_FLAG_PGOP = 1024, /* pg op, no object */ | ||
295 | CEPH_OSD_FLAG_EXEC = 2048, /* op may exec */ | ||
296 | }; | ||
297 | |||
298 | enum { | ||
299 | CEPH_OSD_OP_FLAG_EXCL = 1, /* EXCL object create */ | ||
300 | }; | ||
301 | |||
302 | #define EOLDSNAPC ERESTART /* ORDERSNAP flag set; writer has old snapc*/ | ||
303 | #define EBLACKLISTED ESHUTDOWN /* blacklisted */ | ||
304 | |||
305 | /* | ||
306 | * an individual object operation. each may be accompanied by some data | ||
307 | * payload | ||
308 | */ | ||
309 | struct ceph_osd_op { | ||
310 | __le16 op; /* CEPH_OSD_OP_* */ | ||
311 | __le32 flags; /* CEPH_OSD_FLAG_* */ | ||
312 | union { | ||
313 | struct { | ||
314 | __le64 offset, length; | ||
315 | __le64 truncate_size; | ||
316 | __le32 truncate_seq; | ||
317 | } __attribute__ ((packed)) extent; | ||
318 | struct { | ||
319 | __le32 name_len; | ||
320 | __le32 value_len; | ||
321 | } __attribute__ ((packed)) xattr; | ||
322 | struct { | ||
323 | __u8 class_len; | ||
324 | __u8 method_len; | ||
325 | __u8 argc; | ||
326 | __le32 indata_len; | ||
327 | } __attribute__ ((packed)) cls; | ||
328 | struct { | ||
329 | __le64 cookie, count; | ||
330 | } __attribute__ ((packed)) pgls; | ||
331 | }; | ||
332 | __le32 payload_len; | ||
333 | } __attribute__ ((packed)); | ||
334 | |||
335 | /* | ||
336 | * osd request message header. each request may include multiple | ||
337 | * ceph_osd_op object operations. | ||
338 | */ | ||
339 | struct ceph_osd_request_head { | ||
340 | __le32 client_inc; /* client incarnation */ | ||
341 | struct ceph_object_layout layout; /* pgid */ | ||
342 | __le32 osdmap_epoch; /* client's osdmap epoch */ | ||
343 | |||
344 | __le32 flags; | ||
345 | |||
346 | struct ceph_timespec mtime; /* for mutations only */ | ||
347 | struct ceph_eversion reassert_version; /* if we are replaying op */ | ||
348 | |||
349 | __le32 object_len; /* length of object name */ | ||
350 | |||
351 | __le64 snapid; /* snapid to read */ | ||
352 | __le64 snap_seq; /* writer's snap context */ | ||
353 | __le32 num_snaps; | ||
354 | |||
355 | __le16 num_ops; | ||
356 | struct ceph_osd_op ops[]; /* followed by ops[], obj, ticket, snaps */ | ||
357 | } __attribute__ ((packed)); | ||
358 | |||
359 | struct ceph_osd_reply_head { | ||
360 | __le32 client_inc; /* client incarnation */ | ||
361 | __le32 flags; | ||
362 | struct ceph_object_layout layout; | ||
363 | __le32 osdmap_epoch; | ||
364 | struct ceph_eversion reassert_version; /* for replaying uncommitted */ | ||
365 | |||
366 | __le32 result; /* result code */ | ||
367 | |||
368 | __le32 object_len; /* length of object name */ | ||
369 | __le32 num_ops; | ||
370 | struct ceph_osd_op ops[0]; /* ops[], object */ | ||
371 | } __attribute__ ((packed)); | ||
372 | |||
373 | |||
374 | #endif | ||