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