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