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