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 * LGPL-2.1 or LGPL-3.0
10 */
11
12 #ifndef CEPH_FS_H
13 #define CEPH_FS_H
14
15 #include "msgr.h"
16 #include "rados.h"
17
18 /*
19 * The data structures defined here are shared between Linux kernel and
20 * user space. Also, those data structures are maintained always in
21 * little-endian byte order, even on big-endian systems. This is handled
22 * differently in kernel vs. user space. For use as kernel headers, the
23 * little-endian fields need to use the __le16/__le32/__le64 types. These
24 * are markers that indicate endian conversion routines must be used
25 * whenever such fields are accessed, which can be verified by checker
26 * tools like "sparse". For use as user-space headers, the little-endian
27 * fields instead use types ceph_le16/ceph_le32/ceph_le64, which are C++
28 * classes that implement automatic endian conversion on every access.
29 * To still allow for header sharing, this file uses the __le types, but
30 * redefines those to the ceph_ types when compiled in user space.
31 */
32 #ifndef __KERNEL__
33 #include "byteorder.h"
34 #define __le16 ceph_le16
35 #define __le32 ceph_le32
36 #define __le64 ceph_le64
37 #endif
38
39 /*
40 * subprotocol versions. when specific messages types or high-level
41 * protocols change, bump the affected components. we keep rev
42 * internal cluster protocols separately from the public,
43 * client-facing protocol.
44 */
45 #define CEPH_OSDC_PROTOCOL 24 /* server/client */
46 #define CEPH_MDSC_PROTOCOL 32 /* server/client */
47 #define CEPH_MONC_PROTOCOL 15 /* server/client */
48
49
50 #define CEPH_INO_ROOT 1
51 #define CEPH_INO_CEPH 2 /* hidden .ceph dir */
52 #define CEPH_INO_LOST_AND_FOUND 4 /* reserved ino for use in recovery */
53
54 /* arbitrary limit on max # of monitors (cluster of 3 is typical) */
55 #define CEPH_MAX_MON 31
56
57 /*
58 * ceph_file_layout - describe data layout for a file/inode
59 */
60 struct ceph_file_layout {
61 /* file -> object mapping */
62 __le32 fl_stripe_unit; /* stripe unit, in bytes. must be multiple
63 of page size. */
64 __le32 fl_stripe_count; /* over this many objects */
65 __le32 fl_object_size; /* until objects are this big, then move to
66 new objects */
67 __le32 fl_cas_hash; /* UNUSED. 0 = none; 1 = sha256 */
68
69 /* pg -> disk layout */
70 __le32 fl_object_stripe_unit; /* UNUSED. for per-object parity, if any */
71
72 /* object -> pg layout */
73 __le32 fl_unused; /* unused; used to be preferred primary for pg (-1 for none) */
74 __le32 fl_pg_pool; /* namespace, crush ruleset, rep level */
75 } __attribute__ ((packed));
76
77 #define CEPH_MIN_STRIPE_UNIT 65536
78
79 struct ceph_dir_layout {
80 __u8 dl_dir_hash; /* see ceph_hash.h for ids */
81 __u8 dl_unused1;
82 __u16 dl_unused2;
83 __u32 dl_unused3;
84 } __attribute__ ((packed));
85
86 /* crypto algorithms */
87 #define CEPH_CRYPTO_NONE 0x0
88 #define CEPH_CRYPTO_AES 0x1
89
90 #define CEPH_AES_IV "cephsageyudagreg"
91
92 /* security/authentication protocols */
93 #define CEPH_AUTH_UNKNOWN 0x0
94 #define CEPH_AUTH_NONE 0x1
95 #define CEPH_AUTH_CEPHX 0x2
96
97 /* msgr2 protocol modes */
98 #define CEPH_CON_MODE_UNKNOWN 0x0
99 #define CEPH_CON_MODE_CRC 0x1
100 #define CEPH_CON_MODE_SECURE 0x2
101
102 extern const char *ceph_con_mode_name(int con_mode);
103
104 /* For options with "_", like: GSS_GSS
105 which means: Mode/Protocol to validate "authentication_authorization",
106 where:
107 - Authentication: Verifying the identity of an entity.
108 - Authorization: Verifying that an authenticated entity has
109 the right to access a particular resource.
110 */
111 #define CEPH_AUTH_GSS 0x4
112 #define CEPH_AUTH_GSS_GSS CEPH_AUTH_GSS
113
114 #define CEPH_AUTH_UID_DEFAULT ((__u64) -1)
115
116
117 /*********************************************
118 * message layer
119 */
120
121 /*
122 * message types
123 */
124
125 /* misc */
126 #define CEPH_MSG_SHUTDOWN 1
127 #define CEPH_MSG_PING 2
128
129 /* client <-> monitor */
130 #define CEPH_MSG_MON_MAP 4
131 #define CEPH_MSG_MON_GET_MAP 5
132 #define CEPH_MSG_MON_GET_OSDMAP 6
133 #define CEPH_MSG_MON_METADATA 7
134 #define CEPH_MSG_STATFS 13
135 #define CEPH_MSG_STATFS_REPLY 14
136 #define CEPH_MSG_MON_SUBSCRIBE 15
137 #define CEPH_MSG_MON_SUBSCRIBE_ACK 16
138 #define CEPH_MSG_AUTH 17
139 #define CEPH_MSG_AUTH_REPLY 18
140 #define CEPH_MSG_MON_GET_VERSION 19
141 #define CEPH_MSG_MON_GET_VERSION_REPLY 20
142
143 /* client <-> mds */
144 #define CEPH_MSG_MDS_MAP 21
145
146 #define CEPH_MSG_CLIENT_SESSION 22
147 #define CEPH_MSG_CLIENT_RECONNECT 23
148
149 #define CEPH_MSG_CLIENT_REQUEST 24
150 #define CEPH_MSG_CLIENT_REQUEST_FORWARD 25
151 #define CEPH_MSG_CLIENT_REPLY 26
152 #define CEPH_MSG_CLIENT_RECLAIM 27
153 #define CEPH_MSG_CLIENT_RECLAIM_REPLY 28
154 #define CEPH_MSG_CLIENT_CAPS 0x310
155 #define CEPH_MSG_CLIENT_LEASE 0x311
156 #define CEPH_MSG_CLIENT_SNAP 0x312
157 #define CEPH_MSG_CLIENT_CAPRELEASE 0x313
158 #define CEPH_MSG_CLIENT_QUOTA 0x314
159
160 /* pool ops */
161 #define CEPH_MSG_POOLOP_REPLY 48
162 #define CEPH_MSG_POOLOP 49
163
164
165 /* osd */
166 #define CEPH_MSG_OSD_MAP 41
167 #define CEPH_MSG_OSD_OP 42
168 #define CEPH_MSG_OSD_OPREPLY 43
169 #define CEPH_MSG_WATCH_NOTIFY 44
170 #define CEPH_MSG_OSD_BACKOFF 61
171
172 /* FSMap subscribers (see all MDS clusters at once) */
173 #define CEPH_MSG_FS_MAP 45
174 /* FSMapUser subscribers (get MDS clusters name->ID mapping) */
175 #define CEPH_MSG_FS_MAP_USER 103
176
177 /* watch-notify operations */
178 enum {
179 CEPH_WATCH_EVENT_NOTIFY = 1, /* notifying watcher */
180 CEPH_WATCH_EVENT_NOTIFY_COMPLETE = 2, /* notifier notified when done */
181 CEPH_WATCH_EVENT_DISCONNECT = 3, /* we were disconnected */
182 };
183
184 const char *ceph_watch_event_name(int o);
185
186 /* pool operations */
187 enum {
188 POOL_OP_CREATE = 0x01,
189 POOL_OP_DELETE = 0x02,
190 POOL_OP_AUID_CHANGE = 0x03,
191 POOL_OP_CREATE_SNAP = 0x11,
192 POOL_OP_DELETE_SNAP = 0x12,
193 POOL_OP_CREATE_UNMANAGED_SNAP = 0x21,
194 POOL_OP_DELETE_UNMANAGED_SNAP = 0x22,
195 };
196
197 struct ceph_mon_request_header {
198 __le64 have_version;
199 __le16 session_mon;
200 __le64 session_mon_tid;
201 } __attribute__ ((packed));
202
203 struct ceph_mon_statfs {
204 struct ceph_mon_request_header monhdr;
205 struct ceph_fsid fsid;
206 } __attribute__ ((packed));
207
208 struct ceph_statfs {
209 __le64 kb, kb_used, kb_avail;
210 __le64 num_objects;
211 } __attribute__ ((packed));
212
213 struct ceph_mon_statfs_reply {
214 struct ceph_fsid fsid;
215 __le64 version;
216 struct ceph_statfs st;
217 } __attribute__ ((packed));
218
219 const char *ceph_pool_op_name(int op);
220
221 struct ceph_mon_poolop {
222 struct ceph_mon_request_header monhdr;
223 struct ceph_fsid fsid;
224 __le32 pool;
225 __le32 op;
226 __le64 __old_auid; // obsolete
227 __le64 snapid;
228 __le32 name_len;
229 } __attribute__ ((packed));
230
231 struct ceph_mon_poolop_reply {
232 struct ceph_mon_request_header monhdr;
233 struct ceph_fsid fsid;
234 __le32 reply_code;
235 __le32 epoch;
236 char has_data;
237 char data[0];
238 } __attribute__ ((packed));
239
240 struct ceph_mon_unmanaged_snap {
241 __le64 snapid;
242 } __attribute__ ((packed));
243
244 struct ceph_osd_getmap {
245 struct ceph_mon_request_header monhdr;
246 struct ceph_fsid fsid;
247 __le32 start;
248 } __attribute__ ((packed));
249
250 struct ceph_mds_getmap {
251 struct ceph_mon_request_header monhdr;
252 struct ceph_fsid fsid;
253 } __attribute__ ((packed));
254
255 struct ceph_client_mount {
256 struct ceph_mon_request_header monhdr;
257 } __attribute__ ((packed));
258
259 #define CEPH_SUBSCRIBE_ONETIME 1 /* i want only 1 update after have */
260
261 struct ceph_mon_subscribe_item {
262 __le64 start;
263 __u8 flags;
264 } __attribute__ ((packed));
265
266 struct ceph_mon_subscribe_ack {
267 __le32 duration; /* seconds */
268 struct ceph_fsid fsid;
269 } __attribute__ ((packed));
270
271 /*
272 * mdsmap flags
273 */
274 #define CEPH_MDSMAP_NOT_JOINABLE (1<<0) /* standbys cannot join */
275 #define CEPH_MDSMAP_DOWN (CEPH_MDSMAP_NOT_JOINABLE) /* backwards compat */
276 #define CEPH_MDSMAP_ALLOW_SNAPS (1<<1) /* cluster allowed to create snapshots */
277 /* deprecated #define CEPH_MDSMAP_ALLOW_MULTIMDS (1<<2) cluster allowed to have >1 active MDS */
278 /* deprecated #define CEPH_MDSMAP_ALLOW_DIRFRAGS (1<<3) cluster allowed to fragment directories */
279 #define CEPH_MDSMAP_ALLOW_MULTIMDS_SNAPS (1<<4) /* cluster alllowed to enable MULTIMDS
280 and SNAPS at the same time */
281 #define CEPH_MDSMAP_ALLOW_STANDBY_REPLAY (1<<5) /* cluster alllowed to enable MULTIMDS */
282
283 #define CEPH_MDSMAP_DEFAULTS (CEPH_MDSMAP_ALLOW_SNAPS | \
284 CEPH_MDSMAP_ALLOW_MULTIMDS_SNAPS)
285
286 /*
287 * mds states
288 * > 0 -> in
289 * <= 0 -> out
290 */
291 #define CEPH_MDS_STATE_DNE 0 /* down, does not exist. */
292 #define CEPH_MDS_STATE_STOPPED -1 /* down, once existed, but no subtrees.
293 empty log. */
294 #define CEPH_MDS_STATE_BOOT -4 /* up, boot announcement. */
295 #define CEPH_MDS_STATE_STANDBY -5 /* up, idle. waiting for assignment. */
296 #define CEPH_MDS_STATE_CREATING -6 /* up, creating MDS instance. */
297 #define CEPH_MDS_STATE_STARTING -7 /* up, starting previously stopped mds */
298 #define CEPH_MDS_STATE_STANDBY_REPLAY -8 /* up, tailing active node's journal */
299 #define CEPH_MDS_STATE_REPLAYONCE -9 /* Legacy, unused */
300 #define CEPH_MDS_STATE_NULL -10
301
302 #define CEPH_MDS_STATE_REPLAY 8 /* up, replaying journal. */
303 #define CEPH_MDS_STATE_RESOLVE 9 /* up, disambiguating distributed
304 operations (import, rename, etc.) */
305 #define CEPH_MDS_STATE_RECONNECT 10 /* up, reconnect to clients */
306 #define CEPH_MDS_STATE_REJOIN 11 /* up, rejoining distributed cache */
307 #define CEPH_MDS_STATE_CLIENTREPLAY 12 /* up, replaying client operations */
308 #define CEPH_MDS_STATE_ACTIVE 13 /* up, active */
309 #define CEPH_MDS_STATE_STOPPING 14 /* up, but exporting metadata */
310 #define CEPH_MDS_STATE_DAMAGED 15 /* rank not replayable, need repair */
311
312 extern const char *ceph_mds_state_name(int s);
313
314
315 /*
316 * metadata lock types.
317 * - these are bitmasks.. we can compose them
318 * - they also define the lock ordering by the MDS
319 * - a few of these are internal to the mds
320 */
321 #define CEPH_LOCK_DVERSION 1
322 #define CEPH_LOCK_DN 2
323 #define CEPH_LOCK_IVERSION 16 /* mds internal */
324 #define CEPH_LOCK_ISNAP 32
325 #define CEPH_LOCK_IFILE 64
326 #define CEPH_LOCK_IAUTH 128
327 #define CEPH_LOCK_ILINK 256
328 #define CEPH_LOCK_IDFT 512 /* dir frag tree */
329 #define CEPH_LOCK_INEST 1024 /* mds internal */
330 #define CEPH_LOCK_IXATTR 2048
331 #define CEPH_LOCK_IFLOCK 4096 /* advisory file locks */
332 #define CEPH_LOCK_INO 8192 /* immutable inode bits; not a lock */
333 #define CEPH_LOCK_IPOLICY 16384 /* policy lock on dirs. MDS internal */
334
335 /* client_session ops */
336 enum {
337 CEPH_SESSION_REQUEST_OPEN,
338 CEPH_SESSION_OPEN,
339 CEPH_SESSION_REQUEST_CLOSE,
340 CEPH_SESSION_CLOSE,
341 CEPH_SESSION_REQUEST_RENEWCAPS,
342 CEPH_SESSION_RENEWCAPS,
343 CEPH_SESSION_STALE,
344 CEPH_SESSION_RECALL_STATE,
345 CEPH_SESSION_FLUSHMSG,
346 CEPH_SESSION_FLUSHMSG_ACK,
347 CEPH_SESSION_FORCE_RO,
348 // A response to REQUEST_OPEN indicating that the client should
349 // permanently desist from contacting the MDS
350 CEPH_SESSION_REJECT,
351 CEPH_SESSION_REQUEST_FLUSH_MDLOG
352 };
353
354 // flags for state reclaim
355 #define CEPH_RECLAIM_RESET 1
356
357 extern const char *ceph_session_op_name(int op);
358
359 struct ceph_mds_session_head {
360 __le32 op;
361 __le64 seq;
362 struct ceph_timespec stamp;
363 __le32 max_caps, max_leases;
364 } __attribute__ ((packed));
365
366 /* client_request */
367 /*
368 * metadata ops.
369 * & 0x001000 -> write op
370 * & 0x010000 -> follow symlink (e.g. stat(), not lstat()).
371 & & 0x100000 -> use weird ino/path trace
372 */
373 #define CEPH_MDS_OP_WRITE 0x001000
374 enum {
375 CEPH_MDS_OP_LOOKUP = 0x00100,
376 CEPH_MDS_OP_GETATTR = 0x00101,
377 CEPH_MDS_OP_LOOKUPHASH = 0x00102,
378 CEPH_MDS_OP_LOOKUPPARENT = 0x00103,
379 CEPH_MDS_OP_LOOKUPINO = 0x00104,
380 CEPH_MDS_OP_LOOKUPNAME = 0x00105,
381
382 CEPH_MDS_OP_SETXATTR = 0x01105,
383 CEPH_MDS_OP_RMXATTR = 0x01106,
384 CEPH_MDS_OP_SETLAYOUT = 0x01107,
385 CEPH_MDS_OP_SETATTR = 0x01108,
386 CEPH_MDS_OP_SETFILELOCK= 0x01109,
387 CEPH_MDS_OP_GETFILELOCK= 0x00110,
388 CEPH_MDS_OP_SETDIRLAYOUT=0x0110a,
389
390 CEPH_MDS_OP_MKNOD = 0x01201,
391 CEPH_MDS_OP_LINK = 0x01202,
392 CEPH_MDS_OP_UNLINK = 0x01203,
393 CEPH_MDS_OP_RENAME = 0x01204,
394 CEPH_MDS_OP_MKDIR = 0x01220,
395 CEPH_MDS_OP_RMDIR = 0x01221,
396 CEPH_MDS_OP_SYMLINK = 0x01222,
397
398 CEPH_MDS_OP_CREATE = 0x01301,
399 CEPH_MDS_OP_OPEN = 0x00302,
400 CEPH_MDS_OP_READDIR = 0x00305,
401
402 CEPH_MDS_OP_LOOKUPSNAP = 0x00400,
403 CEPH_MDS_OP_MKSNAP = 0x01400,
404 CEPH_MDS_OP_RMSNAP = 0x01401,
405 CEPH_MDS_OP_LSSNAP = 0x00402,
406 CEPH_MDS_OP_RENAMESNAP = 0x01403,
407
408 // internal op
409 CEPH_MDS_OP_FRAGMENTDIR= 0x01500,
410 CEPH_MDS_OP_EXPORTDIR = 0x01501,
411 CEPH_MDS_OP_FLUSH = 0x01502,
412 CEPH_MDS_OP_ENQUEUE_SCRUB = 0x01503,
413 CEPH_MDS_OP_REPAIR_FRAGSTATS = 0x01504,
414 CEPH_MDS_OP_REPAIR_INODESTATS = 0x01505,
415 CEPH_MDS_OP_UPGRADE_SNAPREALM = 0x01506
416 };
417
418 extern const char *ceph_mds_op_name(int op);
419
420 #ifndef CEPH_SETATTR_MODE
421 #define CEPH_SETATTR_MODE (1 << 0)
422 #define CEPH_SETATTR_UID (1 << 1)
423 #define CEPH_SETATTR_GID (1 << 2)
424 #define CEPH_SETATTR_MTIME (1 << 3)
425 #define CEPH_SETATTR_ATIME (1 << 4)
426 #define CEPH_SETATTR_SIZE (1 << 5)
427 #define CEPH_SETATTR_CTIME (1 << 6)
428 #define CEPH_SETATTR_MTIME_NOW (1 << 7)
429 #define CEPH_SETATTR_ATIME_NOW (1 << 8)
430 #define CEPH_SETATTR_BTIME (1 << 9)
431 #endif
432 #define CEPH_SETATTR_KILL_SGUID (1 << 10)
433
434 /*
435 * open request flags
436 */
437 #define CEPH_O_RDONLY 00000000
438 #define CEPH_O_WRONLY 00000001
439 #define CEPH_O_RDWR 00000002
440 #define CEPH_O_CREAT 00000100
441 #define CEPH_O_EXCL 00000200
442 #define CEPH_O_TRUNC 00001000
443 #define CEPH_O_LAZY 00020000
444 #define CEPH_O_DIRECTORY 00200000
445 #define CEPH_O_NOFOLLOW 00400000
446
447 int ceph_flags_sys2wire(int flags);
448
449 /*
450 * Ceph setxattr request flags.
451 */
452 #define CEPH_XATTR_CREATE (1 << 0)
453 #define CEPH_XATTR_REPLACE (1 << 1)
454 #define CEPH_XATTR_REMOVE (1 << 31)
455
456 /*
457 * readdir request flags;
458 */
459 #define CEPH_READDIR_REPLY_BITFLAGS (1<<0)
460
461 /*
462 * readdir reply flags.
463 */
464 #define CEPH_READDIR_FRAG_END (1<<0)
465 #define CEPH_READDIR_FRAG_COMPLETE (1<<8)
466 #define CEPH_READDIR_HASH_ORDER (1<<9)
467 #define CEPH_READDIR_OFFSET_HASH (1<<10)
468
469 /* Note that this is embedded wthin ceph_mds_request_head_legacy. */
470 union ceph_mds_request_args_legacy {
471 struct {
472 __le32 mask; /* CEPH_CAP_* */
473 } __attribute__ ((packed)) getattr;
474 struct {
475 __le32 mode;
476 __le32 uid;
477 __le32 gid;
478 struct ceph_timespec mtime;
479 struct ceph_timespec atime;
480 __le64 size, old_size; /* old_size needed by truncate */
481 __le32 mask; /* CEPH_SETATTR_* */
482 } __attribute__ ((packed)) setattr;
483 struct {
484 __le32 frag; /* which dir fragment */
485 __le32 max_entries; /* how many dentries to grab */
486 __le32 max_bytes;
487 __le16 flags;
488 __le32 offset_hash;
489 } __attribute__ ((packed)) readdir;
490 struct {
491 __le32 mode;
492 __le32 rdev;
493 } __attribute__ ((packed)) mknod;
494 struct {
495 __le32 mode;
496 } __attribute__ ((packed)) mkdir;
497 struct {
498 __le32 flags;
499 __le32 mode;
500 __le32 stripe_unit; /* layout for newly created file */
501 __le32 stripe_count; /* ... */
502 __le32 object_size;
503 __le32 pool; /* if >= 0 and CREATEPOOLID feature */
504 __le32 mask; /* CEPH_CAP_* */
505 __le64 old_size; /* if O_TRUNC */
506 } __attribute__ ((packed)) open;
507 struct {
508 __le32 flags;
509 __le32 osdmap_epoch; /* use for set file/dir layout */
510 } __attribute__ ((packed)) setxattr;
511 struct {
512 struct ceph_file_layout layout;
513 } __attribute__ ((packed)) setlayout;
514 struct {
515 __u8 rule; /* currently fcntl or flock */
516 __u8 type; /* shared, exclusive, remove*/
517 __le64 owner; /* who requests/holds the lock */
518 __le64 pid; /* process id requesting the lock */
519 __le64 start; /* initial location to lock */
520 __le64 length; /* num bytes to lock from start */
521 __u8 wait; /* will caller wait for lock to become available? */
522 } __attribute__ ((packed)) filelock_change;
523 } __attribute__ ((packed));
524
525 #define CEPH_MDS_FLAG_REPLAY 1 /* this is a replayed op */
526 #define CEPH_MDS_FLAG_WANT_DENTRY 2 /* want dentry in reply */
527
528 struct ceph_mds_request_head_legacy {
529 __le64 oldest_client_tid;
530 __le32 mdsmap_epoch; /* on client */
531 __le32 flags; /* CEPH_MDS_FLAG_* */
532 __u8 num_retry, num_fwd; /* count retry, fwd attempts */
533 __le16 num_releases; /* # include cap/lease release records */
534 __le32 op; /* mds op code */
535 __le32 caller_uid, caller_gid;
536 __le64 ino; /* use this ino for openc, mkdir, mknod,
537 etc. (if replaying) */
538 union ceph_mds_request_args_legacy args;
539 } __attribute__ ((packed));
540
541 /*
542 * Note that this is embedded wthin ceph_mds_request_head. Also, compatibility
543 * with the ceph_mds_request_args_legacy must be maintained!
544 */
545 union ceph_mds_request_args {
546 struct {
547 __le32 mask; /* CEPH_CAP_* */
548 } __attribute__ ((packed)) getattr;
549 struct {
550 __le32 mode;
551 __le32 uid;
552 __le32 gid;
553 struct ceph_timespec mtime;
554 struct ceph_timespec atime;
555 __le64 size, old_size; /* old_size needed by truncate */
556 __le32 mask; /* CEPH_SETATTR_* */
557 struct ceph_timespec btime;
558 } __attribute__ ((packed)) setattr;
559 struct {
560 __le32 frag; /* which dir fragment */
561 __le32 max_entries; /* how many dentries to grab */
562 __le32 max_bytes;
563 __le16 flags;
564 __le32 offset_hash;
565 } __attribute__ ((packed)) readdir;
566 struct {
567 __le32 mode;
568 __le32 rdev;
569 } __attribute__ ((packed)) mknod;
570 struct {
571 __le32 mode;
572 } __attribute__ ((packed)) mkdir;
573 struct {
574 __le32 flags;
575 __le32 mode;
576 __le32 stripe_unit; /* layout for newly created file */
577 __le32 stripe_count; /* ... */
578 __le32 object_size;
579 __le32 pool; /* if >= 0 and CREATEPOOLID feature */
580 __le32 mask; /* CEPH_CAP_* */
581 __le64 old_size; /* if O_TRUNC */
582 } __attribute__ ((packed)) open;
583 struct {
584 __le32 flags;
585 __le32 osdmap_epoch; /* use for set file/dir layout */
586 } __attribute__ ((packed)) setxattr;
587 struct {
588 struct ceph_file_layout layout;
589 } __attribute__ ((packed)) setlayout;
590 struct {
591 __u8 rule; /* currently fcntl or flock */
592 __u8 type; /* shared, exclusive, remove*/
593 __le64 owner; /* who requests/holds the lock */
594 __le64 pid; /* process id requesting the lock */
595 __le64 start; /* initial location to lock */
596 __le64 length; /* num bytes to lock from start */
597 __u8 wait; /* will caller wait for lock to become available? */
598 } __attribute__ ((packed)) filelock_change;
599 struct {
600 __le32 mask; /* CEPH_CAP_* */
601 __le64 snapid;
602 __le64 parent;
603 __le32 hash;
604 } __attribute__ ((packed)) lookupino;
605 } __attribute__ ((packed));
606
607 #define CEPH_MDS_REQUEST_HEAD_VERSION 1
608
609 /*
610 * Note that any change to this structure must ensure that it is compatible
611 * with ceph_mds_request_head_legacy.
612 */
613 struct ceph_mds_request_head {
614 __le16 version;
615 __le64 oldest_client_tid;
616 __le32 mdsmap_epoch; /* on client */
617 __le32 flags; /* CEPH_MDS_FLAG_* */
618 __u8 num_retry, num_fwd; /* count retry, fwd attempts */
619 __le16 num_releases; /* # include cap/lease release records */
620 __le32 op; /* mds op code */
621 __le32 caller_uid, caller_gid;
622 __le64 ino; /* use this ino for openc, mkdir, mknod,
623 etc. (if replaying) */
624 union ceph_mds_request_args args;
625 } __attribute__ ((packed));
626
627 /* cap/lease release record */
628 struct ceph_mds_request_release {
629 __le64 ino, cap_id; /* ino and unique cap id */
630 __le32 caps, wanted; /* new issued, wanted */
631 __le32 seq, issue_seq, mseq;
632 __le32 dname_seq; /* if releasing a dentry lease, a */
633 __le32 dname_len; /* string follows. */
634 } __attribute__ ((packed));
635
636 static inline void
637 copy_from_legacy_head(struct ceph_mds_request_head *head,
638 struct ceph_mds_request_head_legacy *legacy)
639 {
640 struct ceph_mds_request_head_legacy *embedded_legacy =
641 (struct ceph_mds_request_head_legacy *)&head->oldest_client_tid;
642 *embedded_legacy = *legacy;
643 }
644
645 static inline void
646 copy_to_legacy_head(struct ceph_mds_request_head_legacy *legacy,
647 struct ceph_mds_request_head *head)
648 {
649 struct ceph_mds_request_head_legacy *embedded_legacy =
650 (struct ceph_mds_request_head_legacy *)&head->oldest_client_tid;
651 *legacy = *embedded_legacy;
652 }
653
654 /* client reply */
655 struct ceph_mds_reply_head {
656 __le32 op;
657 __le32 result;
658 __le32 mdsmap_epoch;
659 __u8 safe; /* true if committed to disk */
660 __u8 is_dentry, is_target; /* true if dentry, target inode records
661 are included with reply */
662 } __attribute__ ((packed));
663
664 /* one for each node split */
665 struct ceph_frag_tree_split {
666 __le32 frag; /* this frag splits... */
667 __le32 by; /* ...by this many bits */
668 } __attribute__ ((packed));
669
670 struct ceph_frag_tree_head {
671 __le32 nsplits; /* num ceph_frag_tree_split records */
672 struct ceph_frag_tree_split splits[];
673 } __attribute__ ((packed));
674
675 /* capability issue, for bundling with mds reply */
676 struct ceph_mds_reply_cap {
677 __le32 caps, wanted; /* caps issued, wanted */
678 __le64 cap_id;
679 __le32 seq, mseq;
680 __le64 realm; /* snap realm */
681 __u8 flags; /* CEPH_CAP_FLAG_* */
682 } __attribute__ ((packed));
683
684 #define CEPH_CAP_FLAG_AUTH (1 << 0) /* cap is issued by auth mds */
685 #define CEPH_CAP_FLAG_RELEASE (1 << 1) /* ask client to release the cap */
686
687 /* reply_lease follows dname, and reply_inode */
688 struct ceph_mds_reply_lease {
689 __le16 mask; /* lease type(s) */
690 __le32 duration_ms; /* lease duration */
691 __le32 seq;
692 } __attribute__ ((packed));
693
694 struct ceph_mds_reply_dirfrag {
695 __le32 frag; /* fragment */
696 __le32 auth; /* auth mds, if this is a delegation point */
697 __le32 ndist; /* number of mds' this is replicated on */
698 __le32 dist[];
699 } __attribute__ ((packed));
700
701 #define CEPH_LOCK_FCNTL 1
702 #define CEPH_LOCK_FLOCK 2
703 #define CEPH_LOCK_FCNTL_INTR 3
704 #define CEPH_LOCK_FLOCK_INTR 4
705
706 #define CEPH_LOCK_SHARED 1
707 #define CEPH_LOCK_EXCL 2
708 #define CEPH_LOCK_UNLOCK 4
709
710 struct ceph_filelock {
711 __le64 start;/* file offset to start lock at */
712 __le64 length; /* num bytes to lock; 0 for all following start */
713 __le64 client; /* which client holds the lock */
714 __le64 owner; /* who requests/holds the lock */
715 __le64 pid; /* process id holding the lock on the client */
716 __u8 type; /* shared lock, exclusive lock, or unlock */
717 } __attribute__ ((packed));
718
719
720 /* file access modes */
721 #define CEPH_FILE_MODE_PIN 0
722 #define CEPH_FILE_MODE_RD 1
723 #define CEPH_FILE_MODE_WR 2
724 #define CEPH_FILE_MODE_RDWR 3 /* RD | WR */
725 #define CEPH_FILE_MODE_LAZY 4 /* lazy io */
726 #define CEPH_FILE_MODE_NUM 8 /* bc these are bit fields.. mostly */
727
728 int ceph_flags_to_mode(int flags);
729
730 /* inline data state */
731 #define CEPH_INLINE_NONE ((__u64)-1)
732 #define CEPH_INLINE_MAX_SIZE CEPH_MIN_STRIPE_UNIT
733
734 /* capability bits */
735 #define CEPH_CAP_PIN 1 /* no specific capabilities beyond the pin */
736
737 /* generic cap bits */
738 /* note: these definitions are duplicated in mds/locks.c */
739 #define CEPH_CAP_GSHARED 1 /* client can reads */
740 #define CEPH_CAP_GEXCL 2 /* client can read and update */
741 #define CEPH_CAP_GCACHE 4 /* (file) client can cache reads */
742 #define CEPH_CAP_GRD 8 /* (file) client can read */
743 #define CEPH_CAP_GWR 16 /* (file) client can write */
744 #define CEPH_CAP_GBUFFER 32 /* (file) client can buffer writes */
745 #define CEPH_CAP_GWREXTEND 64 /* (file) client can extend EOF */
746 #define CEPH_CAP_GLAZYIO 128 /* (file) client can perform lazy io */
747
748 #define CEPH_CAP_SIMPLE_BITS 2
749 #define CEPH_CAP_FILE_BITS 8
750
751 /* per-lock shift */
752 #define CEPH_CAP_SAUTH 2
753 #define CEPH_CAP_SLINK 4
754 #define CEPH_CAP_SXATTR 6
755 #define CEPH_CAP_SFILE 8
756
757 /* composed values */
758 #define CEPH_CAP_AUTH_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SAUTH)
759 #define CEPH_CAP_AUTH_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SAUTH)
760 #define CEPH_CAP_LINK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SLINK)
761 #define CEPH_CAP_LINK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SLINK)
762 #define CEPH_CAP_XATTR_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SXATTR)
763 #define CEPH_CAP_XATTR_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SXATTR)
764 #define CEPH_CAP_FILE(x) (x << CEPH_CAP_SFILE)
765 #define CEPH_CAP_FILE_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFILE)
766 #define CEPH_CAP_FILE_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFILE)
767 #define CEPH_CAP_FILE_CACHE (CEPH_CAP_GCACHE << CEPH_CAP_SFILE)
768 #define CEPH_CAP_FILE_RD (CEPH_CAP_GRD << CEPH_CAP_SFILE)
769 #define CEPH_CAP_FILE_WR (CEPH_CAP_GWR << CEPH_CAP_SFILE)
770 #define CEPH_CAP_FILE_BUFFER (CEPH_CAP_GBUFFER << CEPH_CAP_SFILE)
771 #define CEPH_CAP_FILE_WREXTEND (CEPH_CAP_GWREXTEND << CEPH_CAP_SFILE)
772 #define CEPH_CAP_FILE_LAZYIO (CEPH_CAP_GLAZYIO << CEPH_CAP_SFILE)
773
774 /* cap masks (for getattr) */
775 #define CEPH_STAT_CAP_INODE CEPH_CAP_PIN
776 #define CEPH_STAT_CAP_TYPE CEPH_CAP_PIN /* mode >> 12 */
777 #define CEPH_STAT_CAP_SYMLINK CEPH_CAP_PIN
778 #define CEPH_STAT_CAP_UID CEPH_CAP_AUTH_SHARED
779 #define CEPH_STAT_CAP_GID CEPH_CAP_AUTH_SHARED
780 #define CEPH_STAT_CAP_MODE CEPH_CAP_AUTH_SHARED
781 #define CEPH_STAT_CAP_NLINK CEPH_CAP_LINK_SHARED
782 #define CEPH_STAT_CAP_LAYOUT CEPH_CAP_FILE_SHARED
783 #define CEPH_STAT_CAP_MTIME CEPH_CAP_FILE_SHARED
784 #define CEPH_STAT_CAP_SIZE CEPH_CAP_FILE_SHARED
785 #define CEPH_STAT_CAP_ATIME CEPH_CAP_FILE_SHARED /* fixme */
786 #define CEPH_STAT_CAP_XATTR CEPH_CAP_XATTR_SHARED
787 #define CEPH_STAT_CAP_INODE_ALL (CEPH_CAP_PIN | \
788 CEPH_CAP_AUTH_SHARED | \
789 CEPH_CAP_LINK_SHARED | \
790 CEPH_CAP_FILE_SHARED | \
791 CEPH_CAP_XATTR_SHARED)
792 #define CEPH_STAT_CAP_INLINE_DATA (CEPH_CAP_FILE_SHARED | \
793 CEPH_CAP_FILE_RD)
794 #define CEPH_STAT_RSTAT CEPH_CAP_FILE_WREXTEND
795
796 #define CEPH_CAP_ANY_SHARED (CEPH_CAP_AUTH_SHARED | \
797 CEPH_CAP_LINK_SHARED | \
798 CEPH_CAP_XATTR_SHARED | \
799 CEPH_CAP_FILE_SHARED)
800 #define CEPH_CAP_ANY_RD (CEPH_CAP_ANY_SHARED | CEPH_CAP_FILE_RD | \
801 CEPH_CAP_FILE_CACHE)
802
803 #define CEPH_CAP_ANY_EXCL (CEPH_CAP_AUTH_EXCL | \
804 CEPH_CAP_LINK_EXCL | \
805 CEPH_CAP_XATTR_EXCL | \
806 CEPH_CAP_FILE_EXCL)
807 #define CEPH_CAP_ANY_FILE_RD (CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE | \
808 CEPH_CAP_FILE_SHARED)
809 #define CEPH_CAP_ANY_FILE_WR (CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER | \
810 CEPH_CAP_FILE_EXCL)
811 #define CEPH_CAP_ANY_WR (CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_FILE_WR)
812 #define CEPH_CAP_ANY (CEPH_CAP_ANY_RD | CEPH_CAP_ANY_EXCL | \
813 CEPH_CAP_ANY_FILE_WR | CEPH_CAP_FILE_LAZYIO | \
814 CEPH_CAP_PIN)
815
816 #define CEPH_CAP_LOCKS (CEPH_LOCK_IFILE | CEPH_LOCK_IAUTH | CEPH_LOCK_ILINK | \
817 CEPH_LOCK_IXATTR)
818
819 int ceph_caps_for_mode(int mode);
820
821 enum {
822 CEPH_CAP_OP_GRANT, /* mds->client grant */
823 CEPH_CAP_OP_REVOKE, /* mds->client revoke */
824 CEPH_CAP_OP_TRUNC, /* mds->client trunc notify */
825 CEPH_CAP_OP_EXPORT, /* mds has exported the cap */
826 CEPH_CAP_OP_IMPORT, /* mds has imported the cap */
827 CEPH_CAP_OP_UPDATE, /* client->mds update */
828 CEPH_CAP_OP_DROP, /* client->mds drop cap bits */
829 CEPH_CAP_OP_FLUSH, /* client->mds cap writeback */
830 CEPH_CAP_OP_FLUSH_ACK, /* mds->client flushed */
831 CEPH_CAP_OP_FLUSHSNAP, /* client->mds flush snapped metadata */
832 CEPH_CAP_OP_FLUSHSNAP_ACK, /* mds->client flushed snapped metadata */
833 CEPH_CAP_OP_RELEASE, /* client->mds release (clean) cap */
834 CEPH_CAP_OP_RENEW, /* client->mds renewal request */
835 };
836
837 extern const char *ceph_cap_op_name(int op);
838
839 /* extra info for cap import/export */
840 struct ceph_mds_cap_peer {
841 __le64 cap_id;
842 __le32 seq;
843 __le32 mseq;
844 __le32 mds;
845 __u8 flags;
846 } __attribute__ ((packed));
847
848 /*
849 * caps message, used for capability callbacks, acks, requests, etc.
850 */
851 struct ceph_mds_caps_head {
852 __le32 op; /* CEPH_CAP_OP_* */
853 __le64 ino, realm;
854 __le64 cap_id;
855 __le32 seq, issue_seq;
856 __le32 caps, wanted, dirty; /* latest issued/wanted/dirty */
857 __le32 migrate_seq;
858 __le64 snap_follows;
859 __le32 snap_trace_len;
860
861 /* authlock */
862 __le32 uid, gid, mode;
863
864 /* linklock */
865 __le32 nlink;
866
867 /* xattrlock */
868 __le32 xattr_len;
869 __le64 xattr_version;
870 } __attribute__ ((packed));
871
872 struct ceph_mds_caps_body_legacy {
873 union {
874 /* all except export */
875 struct {
876 /* filelock */
877 __le64 size, max_size, truncate_size;
878 __le32 truncate_seq;
879 struct ceph_timespec mtime, atime, ctime;
880 struct ceph_file_layout layout;
881 __le32 time_warp_seq;
882 } __attribute__ ((packed));
883 /* export message */
884 struct ceph_mds_cap_peer peer;
885 } __attribute__ ((packed));
886 } __attribute__ ((packed));
887
888 /* cap release msg head */
889 struct ceph_mds_cap_release {
890 __le32 num; /* number of cap_items that follow */
891 } __attribute__ ((packed));
892
893 struct ceph_mds_cap_item {
894 __le64 ino;
895 __le64 cap_id;
896 __le32 migrate_seq, seq;
897 } __attribute__ ((packed));
898
899 #define CEPH_MDS_LEASE_REVOKE 1 /* mds -> client */
900 #define CEPH_MDS_LEASE_RELEASE 2 /* client -> mds */
901 #define CEPH_MDS_LEASE_RENEW 3 /* client <-> mds */
902 #define CEPH_MDS_LEASE_REVOKE_ACK 4 /* client -> mds */
903
904 extern const char *ceph_lease_op_name(int o);
905
906 /* lease msg header */
907 struct ceph_mds_lease {
908 __u8 action; /* CEPH_MDS_LEASE_* */
909 __le16 mask; /* which lease */
910 __le64 ino;
911 __le64 first, last; /* snap range */
912 __le32 seq;
913 __le32 duration_ms; /* duration of renewal */
914 } __attribute__ ((packed));
915 /* followed by a __le32+string for dname */
916
917 /* client reconnect */
918 struct ceph_mds_cap_reconnect {
919 __le64 cap_id;
920 __le32 wanted;
921 __le32 issued;
922 __le64 snaprealm;
923 __le64 pathbase; /* base ino for our path to this ino */
924 __le32 flock_len; /* size of flock state blob, if any */
925 } __attribute__ ((packed));
926 /* followed by flock blob */
927
928 struct ceph_mds_cap_reconnect_v1 {
929 __le64 cap_id;
930 __le32 wanted;
931 __le32 issued;
932 __le64 size;
933 struct ceph_timespec mtime, atime;
934 __le64 snaprealm;
935 __le64 pathbase; /* base ino for our path to this ino */
936 } __attribute__ ((packed));
937
938 struct ceph_mds_snaprealm_reconnect {
939 __le64 ino; /* snap realm base */
940 __le64 seq; /* snap seq for this snap realm */
941 __le64 parent; /* parent realm */
942 } __attribute__ ((packed));
943
944 /*
945 * snaps
946 */
947 enum {
948 CEPH_SNAP_OP_UPDATE, /* CREATE or DESTROY */
949 CEPH_SNAP_OP_CREATE,
950 CEPH_SNAP_OP_DESTROY,
951 CEPH_SNAP_OP_SPLIT,
952 };
953
954 extern const char *ceph_snap_op_name(int o);
955
956 /* snap msg header */
957 struct ceph_mds_snap_head {
958 __le32 op; /* CEPH_SNAP_OP_* */
959 __le64 split; /* ino to split off, if any */
960 __le32 num_split_inos; /* # inos belonging to new child realm */
961 __le32 num_split_realms; /* # child realms udner new child realm */
962 __le32 trace_len; /* size of snap trace blob */
963 } __attribute__ ((packed));
964 /* followed by split ino list, then split realms, then the trace blob */
965
966 /*
967 * encode info about a snaprealm, as viewed by a client
968 */
969 struct ceph_mds_snap_realm {
970 __le64 ino; /* ino */
971 __le64 created; /* snap: when created */
972 __le64 parent; /* ino: parent realm */
973 __le64 parent_since; /* snap: same parent since */
974 __le64 seq; /* snap: version */
975 __le32 num_snaps;
976 __le32 num_prior_parent_snaps;
977 } __attribute__ ((packed));
978 /* followed by my snap list, then prior parent snap list */
979
980 #ifndef __KERNEL__
981 #undef __le16
982 #undef __le32
983 #undef __le64
984 #endif
985
986 #endif
987