]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * ceph_fs.h - Ceph constants and data types to share between kernel and | |
3 | * user space. | |
4 | * | |
5 | * Most types in this file are defined as little-endian, and are | |
6 | * primarily intended to describe data structures that pass over the | |
7 | * wire or that are stored on disk. | |
8 | * | |
9 | * LGPL2 | |
10 | */ | |
11 | ||
12 | #ifndef CEPH_FS_H | |
13 | #define CEPH_FS_H | |
14 | ||
15 | #include "msgr.h" | |
16 | #include "rados.h" | |
17 | ||
18 | /* | |
19 | * subprotocol versions. when specific messages types or high-level | |
20 | * protocols change, bump the affected components. we keep rev | |
21 | * internal cluster protocols separately from the public, | |
22 | * client-facing protocol. | |
23 | */ | |
24 | #define CEPH_OSD_PROTOCOL 8 /* cluster internal */ | |
25 | #define CEPH_MDS_PROTOCOL 12 /* cluster internal */ | |
26 | #define CEPH_MON_PROTOCOL 5 /* cluster internal */ | |
27 | #define CEPH_OSDC_PROTOCOL 24 /* server/client */ | |
28 | #define CEPH_MDSC_PROTOCOL 32 /* server/client */ | |
29 | #define CEPH_MONC_PROTOCOL 15 /* server/client */ | |
30 | ||
31 | ||
32 | #define CEPH_INO_ROOT 1 | |
33 | #define CEPH_INO_CEPH 2 /* hidden .ceph dir */ | |
34 | ||
35 | /* arbitrary limit on max # of monitors (cluster of 3 is typical) */ | |
36 | #define CEPH_MAX_MON 31 | |
37 | ||
38 | ||
39 | /* | |
40 | * feature bits | |
41 | */ | |
42 | #define CEPH_FEATURE_UID (1<<0) | |
43 | #define CEPH_FEATURE_NOSRCADDR (1<<1) | |
44 | #define CEPH_FEATURE_MONCLOCKCHECK (1<<2) | |
45 | #define CEPH_FEATURE_FLOCK (1<<3) | |
46 | ||
47 | ||
48 | /* | |
49 | * ceph_file_layout - describe data layout for a file/inode | |
50 | */ | |
51 | struct ceph_file_layout { | |
52 | /* file -> object mapping */ | |
53 | __le32 fl_stripe_unit; /* stripe unit, in bytes. must be multiple | |
54 | of page size. */ | |
55 | __le32 fl_stripe_count; /* over this many objects */ | |
56 | __le32 fl_object_size; /* until objects are this big, then move to | |
57 | new objects */ | |
58 | __le32 fl_cas_hash; /* 0 = none; 1 = sha256 */ | |
59 | ||
60 | /* pg -> disk layout */ | |
61 | __le32 fl_object_stripe_unit; /* for per-object parity, if any */ | |
62 | ||
63 | /* object -> pg layout */ | |
64 | __le32 fl_pg_preferred; /* preferred primary for pg (-1 for none) */ | |
65 | __le32 fl_pg_pool; /* namespace, crush ruleset, rep level */ | |
66 | } __attribute__ ((packed)); | |
67 | ||
68 | #define CEPH_MIN_STRIPE_UNIT 65536 | |
69 | ||
70 | int ceph_file_layout_is_valid(const struct ceph_file_layout *layout); | |
71 | ||
72 | ||
73 | /* crypto algorithms */ | |
74 | #define CEPH_CRYPTO_NONE 0x0 | |
75 | #define CEPH_CRYPTO_AES 0x1 | |
76 | ||
77 | #define CEPH_AES_IV "cephsageyudagreg" | |
78 | ||
79 | /* security/authentication protocols */ | |
80 | #define CEPH_AUTH_UNKNOWN 0x0 | |
81 | #define CEPH_AUTH_NONE 0x1 | |
82 | #define CEPH_AUTH_CEPHX 0x2 | |
83 | ||
84 | #define CEPH_AUTH_UID_DEFAULT ((__u64) -1) | |
85 | ||
86 | ||
87 | /********************************************* | |
88 | * message layer | |
89 | */ | |
90 | ||
91 | /* | |
92 | * message types | |
93 | */ | |
94 | ||
95 | /* misc */ | |
96 | #define CEPH_MSG_SHUTDOWN 1 | |
97 | #define CEPH_MSG_PING 2 | |
98 | ||
99 | /* client <-> monitor */ | |
100 | #define CEPH_MSG_MON_MAP 4 | |
101 | #define CEPH_MSG_MON_GET_MAP 5 | |
102 | #define CEPH_MSG_STATFS 13 | |
103 | #define CEPH_MSG_STATFS_REPLY 14 | |
104 | #define CEPH_MSG_MON_SUBSCRIBE 15 | |
105 | #define CEPH_MSG_MON_SUBSCRIBE_ACK 16 | |
106 | #define CEPH_MSG_AUTH 17 | |
107 | #define CEPH_MSG_AUTH_REPLY 18 | |
108 | ||
109 | /* client <-> mds */ | |
110 | #define CEPH_MSG_MDS_MAP 21 | |
111 | ||
112 | #define CEPH_MSG_CLIENT_SESSION 22 | |
113 | #define CEPH_MSG_CLIENT_RECONNECT 23 | |
114 | ||
115 | #define CEPH_MSG_CLIENT_REQUEST 24 | |
116 | #define CEPH_MSG_CLIENT_REQUEST_FORWARD 25 | |
117 | #define CEPH_MSG_CLIENT_REPLY 26 | |
118 | #define CEPH_MSG_CLIENT_CAPS 0x310 | |
119 | #define CEPH_MSG_CLIENT_LEASE 0x311 | |
120 | #define CEPH_MSG_CLIENT_SNAP 0x312 | |
121 | #define CEPH_MSG_CLIENT_CAPRELEASE 0x313 | |
122 | ||
123 | /* pool ops */ | |
124 | #define CEPH_MSG_POOLOP_REPLY 48 | |
125 | #define CEPH_MSG_POOLOP 49 | |
126 | ||
127 | ||
128 | /* osd */ | |
129 | #define CEPH_MSG_OSD_MAP 41 | |
130 | #define CEPH_MSG_OSD_OP 42 | |
131 | #define CEPH_MSG_OSD_OPREPLY 43 | |
132 | ||
133 | /* pool operations */ | |
134 | enum { | |
135 | POOL_OP_CREATE = 0x01, | |
136 | POOL_OP_DELETE = 0x02, | |
137 | POOL_OP_AUID_CHANGE = 0x03, | |
138 | POOL_OP_CREATE_SNAP = 0x11, | |
139 | POOL_OP_DELETE_SNAP = 0x12, | |
140 | POOL_OP_CREATE_UNMANAGED_SNAP = 0x21, | |
141 | POOL_OP_DELETE_UNMANAGED_SNAP = 0x22, | |
142 | }; | |
143 | ||
144 | struct ceph_mon_request_header { | |
145 | __le64 have_version; | |
146 | __le16 session_mon; | |
147 | __le64 session_mon_tid; | |
148 | } __attribute__ ((packed)); | |
149 | ||
150 | struct ceph_mon_statfs { | |
151 | struct ceph_mon_request_header monhdr; | |
152 | struct ceph_fsid fsid; | |
153 | } __attribute__ ((packed)); | |
154 | ||
155 | struct ceph_statfs { | |
156 | __le64 kb, kb_used, kb_avail; | |
157 | __le64 num_objects; | |
158 | } __attribute__ ((packed)); | |
159 | ||
160 | struct ceph_mon_statfs_reply { | |
161 | struct ceph_fsid fsid; | |
162 | __le64 version; | |
163 | struct ceph_statfs st; | |
164 | } __attribute__ ((packed)); | |
165 | ||
166 | const char *ceph_pool_op_name(int op); | |
167 | ||
168 | struct ceph_mon_poolop { | |
169 | struct ceph_mon_request_header monhdr; | |
170 | struct ceph_fsid fsid; | |
171 | __le32 pool; | |
172 | __le32 op; | |
173 | __le64 auid; | |
174 | __le64 snapid; | |
175 | __le32 name_len; | |
176 | } __attribute__ ((packed)); | |
177 | ||
178 | struct ceph_mon_poolop_reply { | |
179 | struct ceph_mon_request_header monhdr; | |
180 | struct ceph_fsid fsid; | |
181 | __le32 reply_code; | |
182 | __le32 epoch; | |
183 | char has_data; | |
184 | char data[0]; | |
185 | } __attribute__ ((packed)); | |
186 | ||
187 | struct ceph_mon_unmanaged_snap { | |
188 | __le64 snapid; | |
189 | } __attribute__ ((packed)); | |
190 | ||
191 | struct ceph_osd_getmap { | |
192 | struct ceph_mon_request_header monhdr; | |
193 | struct ceph_fsid fsid; | |
194 | __le32 start; | |
195 | } __attribute__ ((packed)); | |
196 | ||
197 | struct ceph_mds_getmap { | |
198 | struct ceph_mon_request_header monhdr; | |
199 | struct ceph_fsid fsid; | |
200 | } __attribute__ ((packed)); | |
201 | ||
202 | struct ceph_client_mount { | |
203 | struct ceph_mon_request_header monhdr; | |
204 | } __attribute__ ((packed)); | |
205 | ||
206 | struct ceph_mon_subscribe_item { | |
207 | __le64 have_version; __le64 have; | |
208 | __u8 onetime; | |
209 | } __attribute__ ((packed)); | |
210 | ||
211 | struct ceph_mon_subscribe_ack { | |
212 | __le32 duration; /* seconds */ | |
213 | struct ceph_fsid fsid; | |
214 | } __attribute__ ((packed)); | |
215 | ||
216 | /* | |
217 | * mds states | |
218 | * > 0 -> in | |
219 | * <= 0 -> out | |
220 | */ | |
221 | #define CEPH_MDS_STATE_DNE 0 /* down, does not exist. */ | |
222 | #define CEPH_MDS_STATE_STOPPED -1 /* down, once existed, but no subtrees. | |
223 | empty log. */ | |
224 | #define CEPH_MDS_STATE_BOOT -4 /* up, boot announcement. */ | |
225 | #define CEPH_MDS_STATE_STANDBY -5 /* up, idle. waiting for assignment. */ | |
226 | #define CEPH_MDS_STATE_CREATING -6 /* up, creating MDS instance. */ | |
227 | #define CEPH_MDS_STATE_STARTING -7 /* up, starting previously stopped mds */ | |
228 | #define CEPH_MDS_STATE_STANDBY_REPLAY -8 /* up, tailing active node's journal */ | |
229 | ||
230 | #define CEPH_MDS_STATE_REPLAY 8 /* up, replaying journal. */ | |
231 | #define CEPH_MDS_STATE_RESOLVE 9 /* up, disambiguating distributed | |
232 | operations (import, rename, etc.) */ | |
233 | #define CEPH_MDS_STATE_RECONNECT 10 /* up, reconnect to clients */ | |
234 | #define CEPH_MDS_STATE_REJOIN 11 /* up, rejoining distributed cache */ | |
235 | #define CEPH_MDS_STATE_CLIENTREPLAY 12 /* up, replaying client operations */ | |
236 | #define CEPH_MDS_STATE_ACTIVE 13 /* up, active */ | |
237 | #define CEPH_MDS_STATE_STOPPING 14 /* up, but exporting metadata */ | |
238 | ||
239 | extern const char *ceph_mds_state_name(int s); | |
240 | ||
241 | ||
242 | /* | |
243 | * metadata lock types. | |
244 | * - these are bitmasks.. we can compose them | |
245 | * - they also define the lock ordering by the MDS | |
246 | * - a few of these are internal to the mds | |
247 | */ | |
248 | #define CEPH_LOCK_DVERSION 1 | |
249 | #define CEPH_LOCK_DN 2 | |
250 | #define CEPH_LOCK_ISNAP 16 | |
251 | #define CEPH_LOCK_IVERSION 32 /* mds internal */ | |
252 | #define CEPH_LOCK_IFILE 64 | |
253 | #define CEPH_LOCK_IAUTH 128 | |
254 | #define CEPH_LOCK_ILINK 256 | |
255 | #define CEPH_LOCK_IDFT 512 /* dir frag tree */ | |
256 | #define CEPH_LOCK_INEST 1024 /* mds internal */ | |
257 | #define CEPH_LOCK_IXATTR 2048 | |
258 | #define CEPH_LOCK_IFLOCK 4096 /* advisory file locks */ | |
259 | #define CEPH_LOCK_INO 8192 /* immutable inode bits; not a lock */ | |
260 | ||
261 | /* client_session ops */ | |
262 | enum { | |
263 | CEPH_SESSION_REQUEST_OPEN, | |
264 | CEPH_SESSION_OPEN, | |
265 | CEPH_SESSION_REQUEST_CLOSE, | |
266 | CEPH_SESSION_CLOSE, | |
267 | CEPH_SESSION_REQUEST_RENEWCAPS, | |
268 | CEPH_SESSION_RENEWCAPS, | |
269 | CEPH_SESSION_STALE, | |
270 | CEPH_SESSION_RECALL_STATE, | |
271 | }; | |
272 | ||
273 | extern const char *ceph_session_op_name(int op); | |
274 | ||
275 | struct ceph_mds_session_head { | |
276 | __le32 op; | |
277 | __le64 seq; | |
278 | struct ceph_timespec stamp; | |
279 | __le32 max_caps, max_leases; | |
280 | } __attribute__ ((packed)); | |
281 | ||
282 | /* client_request */ | |
283 | /* | |
284 | * metadata ops. | |
285 | * & 0x001000 -> write op | |
286 | * & 0x010000 -> follow symlink (e.g. stat(), not lstat()). | |
287 | & & 0x100000 -> use weird ino/path trace | |
288 | */ | |
289 | #define CEPH_MDS_OP_WRITE 0x001000 | |
290 | enum { | |
291 | CEPH_MDS_OP_LOOKUP = 0x00100, | |
292 | CEPH_MDS_OP_GETATTR = 0x00101, | |
293 | CEPH_MDS_OP_LOOKUPHASH = 0x00102, | |
294 | CEPH_MDS_OP_LOOKUPPARENT = 0x00103, | |
295 | ||
296 | CEPH_MDS_OP_SETXATTR = 0x01105, | |
297 | CEPH_MDS_OP_RMXATTR = 0x01106, | |
298 | CEPH_MDS_OP_SETLAYOUT = 0x01107, | |
299 | CEPH_MDS_OP_SETATTR = 0x01108, | |
300 | CEPH_MDS_OP_SETFILELOCK= 0x01109, | |
301 | CEPH_MDS_OP_GETFILELOCK= 0x00110, | |
302 | CEPH_MDS_OP_SETDIRLAYOUT=0x0110a, | |
303 | ||
304 | CEPH_MDS_OP_MKNOD = 0x01201, | |
305 | CEPH_MDS_OP_LINK = 0x01202, | |
306 | CEPH_MDS_OP_UNLINK = 0x01203, | |
307 | CEPH_MDS_OP_RENAME = 0x01204, | |
308 | CEPH_MDS_OP_MKDIR = 0x01220, | |
309 | CEPH_MDS_OP_RMDIR = 0x01221, | |
310 | CEPH_MDS_OP_SYMLINK = 0x01222, | |
311 | ||
312 | CEPH_MDS_OP_CREATE = 0x01301, | |
313 | CEPH_MDS_OP_OPEN = 0x00302, | |
314 | CEPH_MDS_OP_READDIR = 0x00305, | |
315 | ||
316 | CEPH_MDS_OP_LOOKUPSNAP = 0x00400, | |
317 | CEPH_MDS_OP_MKSNAP = 0x01400, | |
318 | CEPH_MDS_OP_RMSNAP = 0x01401, | |
319 | CEPH_MDS_OP_LSSNAP = 0x00402, | |
320 | }; | |
321 | ||
322 | extern const char *ceph_mds_op_name(int op); | |
323 | ||
324 | ||
325 | #define CEPH_SETATTR_MODE 1 | |
326 | #define CEPH_SETATTR_UID 2 | |
327 | #define CEPH_SETATTR_GID 4 | |
328 | #define CEPH_SETATTR_MTIME 8 | |
329 | #define CEPH_SETATTR_ATIME 16 | |
330 | #define CEPH_SETATTR_SIZE 32 | |
331 | #define CEPH_SETATTR_CTIME 64 | |
332 | ||
333 | union ceph_mds_request_args { | |
334 | struct { | |
335 | __le32 mask; /* CEPH_CAP_* */ | |
336 | } __attribute__ ((packed)) getattr; | |
337 | struct { | |
338 | __le32 mode; | |
339 | __le32 uid; | |
340 | __le32 gid; | |
341 | struct ceph_timespec mtime; | |
342 | struct ceph_timespec atime; | |
343 | __le64 size, old_size; /* old_size needed by truncate */ | |
344 | __le32 mask; /* CEPH_SETATTR_* */ | |
345 | } __attribute__ ((packed)) setattr; | |
346 | struct { | |
347 | __le32 frag; /* which dir fragment */ | |
348 | __le32 max_entries; /* how many dentries to grab */ | |
349 | __le32 max_bytes; | |
350 | } __attribute__ ((packed)) readdir; | |
351 | struct { | |
352 | __le32 mode; | |
353 | __le32 rdev; | |
354 | } __attribute__ ((packed)) mknod; | |
355 | struct { | |
356 | __le32 mode; | |
357 | } __attribute__ ((packed)) mkdir; | |
358 | struct { | |
359 | __le32 flags; | |
360 | __le32 mode; | |
361 | __le32 stripe_unit; /* layout for newly created file */ | |
362 | __le32 stripe_count; /* ... */ | |
363 | __le32 object_size; | |
364 | __le32 file_replication; | |
365 | __le32 preferred; | |
366 | } __attribute__ ((packed)) open; | |
367 | struct { | |
368 | __le32 flags; | |
369 | } __attribute__ ((packed)) setxattr; | |
370 | struct { | |
371 | struct ceph_file_layout layout; | |
372 | } __attribute__ ((packed)) setlayout; | |
373 | struct { | |
374 | __u8 rule; /* currently fcntl or flock */ | |
375 | __u8 type; /* shared, exclusive, remove*/ | |
376 | __le64 pid; /* process id requesting the lock */ | |
377 | __le64 pid_namespace; | |
378 | __le64 start; /* initial location to lock */ | |
379 | __le64 length; /* num bytes to lock from start */ | |
380 | __u8 wait; /* will caller wait for lock to become available? */ | |
381 | } __attribute__ ((packed)) filelock_change; | |
382 | } __attribute__ ((packed)); | |
383 | ||
384 | #define CEPH_MDS_FLAG_REPLAY 1 /* this is a replayed op */ | |
385 | #define CEPH_MDS_FLAG_WANT_DENTRY 2 /* want dentry in reply */ | |
386 | ||
387 | struct ceph_mds_request_head { | |
388 | __le64 oldest_client_tid; | |
389 | __le32 mdsmap_epoch; /* on client */ | |
390 | __le32 flags; /* CEPH_MDS_FLAG_* */ | |
391 | __u8 num_retry, num_fwd; /* count retry, fwd attempts */ | |
392 | __le16 num_releases; /* # include cap/lease release records */ | |
393 | __le32 op; /* mds op code */ | |
394 | __le32 caller_uid, caller_gid; | |
395 | __le64 ino; /* use this ino for openc, mkdir, mknod, | |
396 | etc. (if replaying) */ | |
397 | union ceph_mds_request_args args; | |
398 | } __attribute__ ((packed)); | |
399 | ||
400 | /* cap/lease release record */ | |
401 | struct ceph_mds_request_release { | |
402 | __le64 ino, cap_id; /* ino and unique cap id */ | |
403 | __le32 caps, wanted; /* new issued, wanted */ | |
404 | __le32 seq, issue_seq, mseq; | |
405 | __le32 dname_seq; /* if releasing a dentry lease, a */ | |
406 | __le32 dname_len; /* string follows. */ | |
407 | } __attribute__ ((packed)); | |
408 | ||
409 | /* client reply */ | |
410 | struct ceph_mds_reply_head { | |
411 | __le32 op; | |
412 | __le32 result; | |
413 | __le32 mdsmap_epoch; | |
414 | __u8 safe; /* true if committed to disk */ | |
415 | __u8 is_dentry, is_target; /* true if dentry, target inode records | |
416 | are included with reply */ | |
417 | } __attribute__ ((packed)); | |
418 | ||
419 | /* one for each node split */ | |
420 | struct ceph_frag_tree_split { | |
421 | __le32 frag; /* this frag splits... */ | |
422 | __le32 by; /* ...by this many bits */ | |
423 | } __attribute__ ((packed)); | |
424 | ||
425 | struct ceph_frag_tree_head { | |
426 | __le32 nsplits; /* num ceph_frag_tree_split records */ | |
427 | struct ceph_frag_tree_split splits[]; | |
428 | } __attribute__ ((packed)); | |
429 | ||
430 | /* capability issue, for bundling with mds reply */ | |
431 | struct ceph_mds_reply_cap { | |
432 | __le32 caps, wanted; /* caps issued, wanted */ | |
433 | __le64 cap_id; | |
434 | __le32 seq, mseq; | |
435 | __le64 realm; /* snap realm */ | |
436 | __u8 flags; /* CEPH_CAP_FLAG_* */ | |
437 | } __attribute__ ((packed)); | |
438 | ||
439 | #define CEPH_CAP_FLAG_AUTH 1 /* cap is issued by auth mds */ | |
440 | ||
441 | /* inode record, for bundling with mds reply */ | |
442 | struct ceph_mds_reply_inode { | |
443 | __le64 ino; | |
444 | __le64 snapid; | |
445 | __le32 rdev; | |
446 | __le64 version; /* inode version */ | |
447 | __le64 xattr_version; /* version for xattr blob */ | |
448 | struct ceph_mds_reply_cap cap; /* caps issued for this inode */ | |
449 | struct ceph_file_layout layout; | |
450 | struct ceph_timespec ctime, mtime, atime; | |
451 | __le32 time_warp_seq; | |
452 | __le64 size, max_size, truncate_size; | |
453 | __le32 truncate_seq; | |
454 | __le32 mode, uid, gid; | |
455 | __le32 nlink; | |
456 | __le64 files, subdirs, rbytes, rfiles, rsubdirs; /* dir stats */ | |
457 | struct ceph_timespec rctime; | |
458 | struct ceph_frag_tree_head fragtree; /* (must be at end of struct) */ | |
459 | } __attribute__ ((packed)); | |
460 | /* followed by frag array, then symlink string, then xattr blob */ | |
461 | ||
462 | /* reply_lease follows dname, and reply_inode */ | |
463 | struct ceph_mds_reply_lease { | |
464 | __le16 mask; /* lease type(s) */ | |
465 | __le32 duration_ms; /* lease duration */ | |
466 | __le32 seq; | |
467 | } __attribute__ ((packed)); | |
468 | ||
469 | struct ceph_mds_reply_dirfrag { | |
470 | __le32 frag; /* fragment */ | |
471 | __le32 auth; /* auth mds, if this is a delegation point */ | |
472 | __le32 ndist; /* number of mds' this is replicated on */ | |
473 | __le32 dist[]; | |
474 | } __attribute__ ((packed)); | |
475 | ||
476 | #define CEPH_LOCK_FCNTL 1 | |
477 | #define CEPH_LOCK_FLOCK 2 | |
478 | ||
479 | #define CEPH_LOCK_SHARED 1 | |
480 | #define CEPH_LOCK_EXCL 2 | |
481 | #define CEPH_LOCK_UNLOCK 4 | |
482 | ||
483 | struct ceph_filelock { | |
484 | __le64 start;/* file offset to start lock at */ | |
485 | __le64 length; /* num bytes to lock; 0 for all following start */ | |
486 | __le64 client; /* which client holds the lock */ | |
487 | __le64 pid; /* process id holding the lock on the client */ | |
488 | __le64 pid_namespace; | |
489 | __u8 type; /* shared lock, exclusive lock, or unlock */ | |
490 | } __attribute__ ((packed)); | |
491 | ||
492 | ||
493 | /* file access modes */ | |
494 | #define CEPH_FILE_MODE_PIN 0 | |
495 | #define CEPH_FILE_MODE_RD 1 | |
496 | #define CEPH_FILE_MODE_WR 2 | |
497 | #define CEPH_FILE_MODE_RDWR 3 /* RD | WR */ | |
498 | #define CEPH_FILE_MODE_LAZY 4 /* lazy io */ | |
499 | #define CEPH_FILE_MODE_NUM 8 /* bc these are bit fields.. mostly */ | |
500 | ||
501 | int ceph_flags_to_mode(int flags); | |
502 | ||
503 | ||
504 | /* capability bits */ | |
505 | #define CEPH_CAP_PIN 1 /* no specific capabilities beyond the pin */ | |
506 | ||
507 | /* generic cap bits */ | |
508 | #define CEPH_CAP_GSHARED 1 /* client can reads */ | |
509 | #define CEPH_CAP_GEXCL 2 /* client can read and update */ | |
510 | #define CEPH_CAP_GCACHE 4 /* (file) client can cache reads */ | |
511 | #define CEPH_CAP_GRD 8 /* (file) client can read */ | |
512 | #define CEPH_CAP_GWR 16 /* (file) client can write */ | |
513 | #define CEPH_CAP_GBUFFER 32 /* (file) client can buffer writes */ | |
514 | #define CEPH_CAP_GWREXTEND 64 /* (file) client can extend EOF */ | |
515 | #define CEPH_CAP_GLAZYIO 128 /* (file) client can perform lazy io */ | |
516 | ||
517 | /* per-lock shift */ | |
518 | #define CEPH_CAP_SAUTH 2 | |
519 | #define CEPH_CAP_SLINK 4 | |
520 | #define CEPH_CAP_SXATTR 6 | |
521 | #define CEPH_CAP_SFILE 8 | |
522 | #define CEPH_CAP_SFLOCK 20 | |
523 | ||
524 | #define CEPH_CAP_BITS 22 | |
525 | ||
526 | /* composed values */ | |
527 | #define CEPH_CAP_AUTH_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SAUTH) | |
528 | #define CEPH_CAP_AUTH_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SAUTH) | |
529 | #define CEPH_CAP_LINK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SLINK) | |
530 | #define CEPH_CAP_LINK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SLINK) | |
531 | #define CEPH_CAP_XATTR_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SXATTR) | |
532 | #define CEPH_CAP_XATTR_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SXATTR) | |
533 | #define CEPH_CAP_FILE(x) (x << CEPH_CAP_SFILE) | |
534 | #define CEPH_CAP_FILE_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFILE) | |
535 | #define CEPH_CAP_FILE_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFILE) | |
536 | #define CEPH_CAP_FILE_CACHE (CEPH_CAP_GCACHE << CEPH_CAP_SFILE) | |
537 | #define CEPH_CAP_FILE_RD (CEPH_CAP_GRD << CEPH_CAP_SFILE) | |
538 | #define CEPH_CAP_FILE_WR (CEPH_CAP_GWR << CEPH_CAP_SFILE) | |
539 | #define CEPH_CAP_FILE_BUFFER (CEPH_CAP_GBUFFER << CEPH_CAP_SFILE) | |
540 | #define CEPH_CAP_FILE_WREXTEND (CEPH_CAP_GWREXTEND << CEPH_CAP_SFILE) | |
541 | #define CEPH_CAP_FILE_LAZYIO (CEPH_CAP_GLAZYIO << CEPH_CAP_SFILE) | |
542 | #define CEPH_CAP_FLOCK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFLOCK) | |
543 | #define CEPH_CAP_FLOCK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFLOCK) | |
544 | ||
545 | ||
546 | /* cap masks (for getattr) */ | |
547 | #define CEPH_STAT_CAP_INODE CEPH_CAP_PIN | |
548 | #define CEPH_STAT_CAP_TYPE CEPH_CAP_PIN /* mode >> 12 */ | |
549 | #define CEPH_STAT_CAP_SYMLINK CEPH_CAP_PIN | |
550 | #define CEPH_STAT_CAP_UID CEPH_CAP_AUTH_SHARED | |
551 | #define CEPH_STAT_CAP_GID CEPH_CAP_AUTH_SHARED | |
552 | #define CEPH_STAT_CAP_MODE CEPH_CAP_AUTH_SHARED | |
553 | #define CEPH_STAT_CAP_NLINK CEPH_CAP_LINK_SHARED | |
554 | #define CEPH_STAT_CAP_LAYOUT CEPH_CAP_FILE_SHARED | |
555 | #define CEPH_STAT_CAP_MTIME CEPH_CAP_FILE_SHARED | |
556 | #define CEPH_STAT_CAP_SIZE CEPH_CAP_FILE_SHARED | |
557 | #define CEPH_STAT_CAP_ATIME CEPH_CAP_FILE_SHARED /* fixme */ | |
558 | #define CEPH_STAT_CAP_XATTR CEPH_CAP_XATTR_SHARED | |
559 | #define CEPH_STAT_CAP_INODE_ALL (CEPH_CAP_PIN | \ | |
560 | CEPH_CAP_AUTH_SHARED | \ | |
561 | CEPH_CAP_LINK_SHARED | \ | |
562 | CEPH_CAP_FILE_SHARED | \ | |
563 | CEPH_CAP_XATTR_SHARED) | |
564 | ||
565 | #define CEPH_CAP_ANY_SHARED (CEPH_CAP_AUTH_SHARED | \ | |
566 | CEPH_CAP_LINK_SHARED | \ | |
567 | CEPH_CAP_XATTR_SHARED | \ | |
568 | CEPH_CAP_FILE_SHARED) | |
569 | #define CEPH_CAP_ANY_RD (CEPH_CAP_ANY_SHARED | CEPH_CAP_FILE_RD | \ | |
570 | CEPH_CAP_FILE_CACHE) | |
571 | ||
572 | #define CEPH_CAP_ANY_EXCL (CEPH_CAP_AUTH_EXCL | \ | |
573 | CEPH_CAP_LINK_EXCL | \ | |
574 | CEPH_CAP_XATTR_EXCL | \ | |
575 | CEPH_CAP_FILE_EXCL) | |
576 | #define CEPH_CAP_ANY_FILE_WR (CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER | \ | |
577 | CEPH_CAP_FILE_EXCL) | |
578 | #define CEPH_CAP_ANY_WR (CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_FILE_WR) | |
579 | #define CEPH_CAP_ANY (CEPH_CAP_ANY_RD | CEPH_CAP_ANY_EXCL | \ | |
580 | CEPH_CAP_ANY_FILE_WR | CEPH_CAP_FILE_LAZYIO | \ | |
581 | CEPH_CAP_PIN) | |
582 | ||
583 | #define CEPH_CAP_LOCKS (CEPH_LOCK_IFILE | CEPH_LOCK_IAUTH | CEPH_LOCK_ILINK | \ | |
584 | CEPH_LOCK_IXATTR) | |
585 | ||
586 | int ceph_caps_for_mode(int mode); | |
587 | ||
588 | enum { | |
589 | CEPH_CAP_OP_GRANT, /* mds->client grant */ | |
590 | CEPH_CAP_OP_REVOKE, /* mds->client revoke */ | |
591 | CEPH_CAP_OP_TRUNC, /* mds->client trunc notify */ | |
592 | CEPH_CAP_OP_EXPORT, /* mds has exported the cap */ | |
593 | CEPH_CAP_OP_IMPORT, /* mds has imported the cap */ | |
594 | CEPH_CAP_OP_UPDATE, /* client->mds update */ | |
595 | CEPH_CAP_OP_DROP, /* client->mds drop cap bits */ | |
596 | CEPH_CAP_OP_FLUSH, /* client->mds cap writeback */ | |
597 | CEPH_CAP_OP_FLUSH_ACK, /* mds->client flushed */ | |
598 | CEPH_CAP_OP_FLUSHSNAP, /* client->mds flush snapped metadata */ | |
599 | CEPH_CAP_OP_FLUSHSNAP_ACK, /* mds->client flushed snapped metadata */ | |
600 | CEPH_CAP_OP_RELEASE, /* client->mds release (clean) cap */ | |
601 | CEPH_CAP_OP_RENEW, /* client->mds renewal request */ | |
602 | }; | |
603 | ||
604 | extern const char *ceph_cap_op_name(int op); | |
605 | ||
606 | /* | |
607 | * caps message, used for capability callbacks, acks, requests, etc. | |
608 | */ | |
609 | struct ceph_mds_caps { | |
610 | __le32 op; /* CEPH_CAP_OP_* */ | |
611 | __le64 ino, realm; | |
612 | __le64 cap_id; | |
613 | __le32 seq, issue_seq; | |
614 | __le32 caps, wanted, dirty; /* latest issued/wanted/dirty */ | |
615 | __le32 migrate_seq; | |
616 | __le64 snap_follows; | |
617 | __le32 snap_trace_len; | |
618 | ||
619 | /* authlock */ | |
620 | __le32 uid, gid, mode; | |
621 | ||
622 | /* linklock */ | |
623 | __le32 nlink; | |
624 | ||
625 | /* xattrlock */ | |
626 | __le32 xattr_len; | |
627 | __le64 xattr_version; | |
628 | ||
629 | /* filelock */ | |
630 | __le64 size, max_size, truncate_size; | |
631 | __le32 truncate_seq; | |
632 | struct ceph_timespec mtime, atime, ctime; | |
633 | struct ceph_file_layout layout; | |
634 | __le32 time_warp_seq; | |
635 | } __attribute__ ((packed)); | |
636 | ||
637 | /* cap release msg head */ | |
638 | struct ceph_mds_cap_release { | |
639 | __le32 num; /* number of cap_items that follow */ | |
640 | } __attribute__ ((packed)); | |
641 | ||
642 | struct ceph_mds_cap_item { | |
643 | __le64 ino; | |
644 | __le64 cap_id; | |
645 | __le32 migrate_seq, seq; | |
646 | } __attribute__ ((packed)); | |
647 | ||
648 | #define CEPH_MDS_LEASE_REVOKE 1 /* mds -> client */ | |
649 | #define CEPH_MDS_LEASE_RELEASE 2 /* client -> mds */ | |
650 | #define CEPH_MDS_LEASE_RENEW 3 /* client <-> mds */ | |
651 | #define CEPH_MDS_LEASE_REVOKE_ACK 4 /* client -> mds */ | |
652 | ||
653 | extern const char *ceph_lease_op_name(int o); | |
654 | ||
655 | /* lease msg header */ | |
656 | struct ceph_mds_lease { | |
657 | __u8 action; /* CEPH_MDS_LEASE_* */ | |
658 | __le16 mask; /* which lease */ | |
659 | __le64 ino; | |
660 | __le64 first, last; /* snap range */ | |
661 | __le32 seq; | |
662 | __le32 duration_ms; /* duration of renewal */ | |
663 | } __attribute__ ((packed)); | |
664 | /* followed by a __le32+string for dname */ | |
665 | ||
666 | /* client reconnect */ | |
667 | struct ceph_mds_cap_reconnect { | |
668 | __le64 cap_id; | |
669 | __le32 wanted; | |
670 | __le32 issued; | |
671 | __le64 snaprealm; | |
672 | __le64 pathbase; /* base ino for our path to this ino */ | |
673 | __le32 flock_len; /* size of flock state blob, if any */ | |
674 | } __attribute__ ((packed)); | |
675 | /* followed by flock blob */ | |
676 | ||
677 | struct ceph_mds_cap_reconnect_v1 { | |
678 | __le64 cap_id; | |
679 | __le32 wanted; | |
680 | __le32 issued; | |
681 | __le64 size; | |
682 | struct ceph_timespec mtime, atime; | |
683 | __le64 snaprealm; | |
684 | __le64 pathbase; /* base ino for our path to this ino */ | |
685 | } __attribute__ ((packed)); | |
686 | ||
687 | struct ceph_mds_snaprealm_reconnect { | |
688 | __le64 ino; /* snap realm base */ | |
689 | __le64 seq; /* snap seq for this snap realm */ | |
690 | __le64 parent; /* parent realm */ | |
691 | } __attribute__ ((packed)); | |
692 | ||
693 | /* | |
694 | * snaps | |
695 | */ | |
696 | enum { | |
697 | CEPH_SNAP_OP_UPDATE, /* CREATE or DESTROY */ | |
698 | CEPH_SNAP_OP_CREATE, | |
699 | CEPH_SNAP_OP_DESTROY, | |
700 | CEPH_SNAP_OP_SPLIT, | |
701 | }; | |
702 | ||
703 | extern const char *ceph_snap_op_name(int o); | |
704 | ||
705 | /* snap msg header */ | |
706 | struct ceph_mds_snap_head { | |
707 | __le32 op; /* CEPH_SNAP_OP_* */ | |
708 | __le64 split; /* ino to split off, if any */ | |
709 | __le32 num_split_inos; /* # inos belonging to new child realm */ | |
710 | __le32 num_split_realms; /* # child realms udner new child realm */ | |
711 | __le32 trace_len; /* size of snap trace blob */ | |
712 | } __attribute__ ((packed)); | |
713 | /* followed by split ino list, then split realms, then the trace blob */ | |
714 | ||
715 | /* | |
716 | * encode info about a snaprealm, as viewed by a client | |
717 | */ | |
718 | struct ceph_mds_snap_realm { | |
719 | __le64 ino; /* ino */ | |
720 | __le64 created; /* snap: when created */ | |
721 | __le64 parent; /* ino: parent realm */ | |
722 | __le64 parent_since; /* snap: same parent since */ | |
723 | __le64 seq; /* snap: version */ | |
724 | __le32 num_snaps; | |
725 | __le32 num_prior_parent_snaps; | |
726 | } __attribute__ ((packed)); | |
727 | /* followed by my snap list, then prior parent snap list */ | |
728 | ||
729 | #endif |