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