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