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