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