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