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