ceph_fs.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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. * LGPL2
  10. */
  11. #ifndef CEPH_FS_H
  12. #define CEPH_FS_H
  13. #include <linux/ceph/msgr.h>
  14. #include <linux/ceph/rados.h>
  15. /*
  16. * subprotocol versions. when specific messages types or high-level
  17. * protocols change, bump the affected components. we keep rev
  18. * internal cluster protocols separately from the public,
  19. * client-facing protocol.
  20. */
  21. #define CEPH_OSDC_PROTOCOL 24 /* server/client */
  22. #define CEPH_MDSC_PROTOCOL 32 /* server/client */
  23. #define CEPH_MONC_PROTOCOL 15 /* server/client */
  24. #define CEPH_INO_ROOT 1
  25. #define CEPH_INO_CEPH 2 /* hidden .ceph dir */
  26. #define CEPH_INO_DOTDOT 3 /* used by ceph fuse for parent (..) */
  27. /* arbitrary limit on max # of monitors (cluster of 3 is typical) */
  28. #define CEPH_MAX_MON 31
  29. /*
  30. * ceph_file_layout - describe data layout for a file/inode
  31. */
  32. struct ceph_file_layout {
  33. /* file -> object mapping */
  34. __le32 fl_stripe_unit; /* stripe unit, in bytes. must be multiple
  35. of page size. */
  36. __le32 fl_stripe_count; /* over this many objects */
  37. __le32 fl_object_size; /* until objects are this big, then move to
  38. new objects */
  39. __le32 fl_cas_hash; /* UNUSED. 0 = none; 1 = sha256 */
  40. /* pg -> disk layout */
  41. __le32 fl_object_stripe_unit; /* UNUSED. for per-object parity, if any */
  42. /* object -> pg layout */
  43. __le32 fl_unused; /* unused; used to be preferred primary for pg (-1 for none) */
  44. __le32 fl_pg_pool; /* namespace, crush ruleset, rep level */
  45. } __attribute__ ((packed));
  46. #define ceph_file_layout_su(l) ((__s32)le32_to_cpu((l).fl_stripe_unit))
  47. #define ceph_file_layout_stripe_count(l) \
  48. ((__s32)le32_to_cpu((l).fl_stripe_count))
  49. #define ceph_file_layout_object_size(l) ((__s32)le32_to_cpu((l).fl_object_size))
  50. #define ceph_file_layout_cas_hash(l) ((__s32)le32_to_cpu((l).fl_cas_hash))
  51. #define ceph_file_layout_object_su(l) \
  52. ((__s32)le32_to_cpu((l).fl_object_stripe_unit))
  53. #define ceph_file_layout_pg_pool(l) \
  54. ((__s32)le32_to_cpu((l).fl_pg_pool))
  55. static inline unsigned ceph_file_layout_stripe_width(struct ceph_file_layout *l)
  56. {
  57. return le32_to_cpu(l->fl_stripe_unit) *
  58. le32_to_cpu(l->fl_stripe_count);
  59. }
  60. /* "period" == bytes before i start on a new set of objects */
  61. static inline unsigned ceph_file_layout_period(struct ceph_file_layout *l)
  62. {
  63. return le32_to_cpu(l->fl_object_size) *
  64. le32_to_cpu(l->fl_stripe_count);
  65. }
  66. #define CEPH_MIN_STRIPE_UNIT 65536
  67. int ceph_file_layout_is_valid(const struct ceph_file_layout *layout);
  68. struct ceph_dir_layout {
  69. __u8 dl_dir_hash; /* see ceph_hash.h for ids */
  70. __u8 dl_unused1;
  71. __u16 dl_unused2;
  72. __u32 dl_unused3;
  73. } __attribute__ ((packed));
  74. /* crypto algorithms */
  75. #define CEPH_CRYPTO_NONE 0x0
  76. #define CEPH_CRYPTO_AES 0x1
  77. #define CEPH_AES_IV "cephsageyudagreg"
  78. /* security/authentication protocols */
  79. #define CEPH_AUTH_UNKNOWN 0x0
  80. #define CEPH_AUTH_NONE 0x1
  81. #define CEPH_AUTH_CEPHX 0x2
  82. #define CEPH_AUTH_UID_DEFAULT ((__u64) -1)
  83. /*********************************************
  84. * message layer
  85. */
  86. /*
  87. * message types
  88. */
  89. /* misc */
  90. #define CEPH_MSG_SHUTDOWN 1
  91. #define CEPH_MSG_PING 2
  92. /* client <-> monitor */
  93. #define CEPH_MSG_MON_MAP 4
  94. #define CEPH_MSG_MON_GET_MAP 5
  95. #define CEPH_MSG_STATFS 13
  96. #define CEPH_MSG_STATFS_REPLY 14
  97. #define CEPH_MSG_MON_SUBSCRIBE 15
  98. #define CEPH_MSG_MON_SUBSCRIBE_ACK 16
  99. #define CEPH_MSG_AUTH 17
  100. #define CEPH_MSG_AUTH_REPLY 18
  101. #define CEPH_MSG_MON_GET_VERSION 19
  102. #define CEPH_MSG_MON_GET_VERSION_REPLY 20
  103. /* client <-> mds */
  104. #define CEPH_MSG_MDS_MAP 21
  105. #define CEPH_MSG_CLIENT_SESSION 22
  106. #define CEPH_MSG_CLIENT_RECONNECT 23
  107. #define CEPH_MSG_CLIENT_REQUEST 24
  108. #define CEPH_MSG_CLIENT_REQUEST_FORWARD 25
  109. #define CEPH_MSG_CLIENT_REPLY 26
  110. #define CEPH_MSG_CLIENT_CAPS 0x310
  111. #define CEPH_MSG_CLIENT_LEASE 0x311
  112. #define CEPH_MSG_CLIENT_SNAP 0x312
  113. #define CEPH_MSG_CLIENT_CAPRELEASE 0x313
  114. /* pool ops */
  115. #define CEPH_MSG_POOLOP_REPLY 48
  116. #define CEPH_MSG_POOLOP 49
  117. /* osd */
  118. #define CEPH_MSG_OSD_MAP 41
  119. #define CEPH_MSG_OSD_OP 42
  120. #define CEPH_MSG_OSD_OPREPLY 43
  121. #define CEPH_MSG_WATCH_NOTIFY 44
  122. /* watch-notify operations */
  123. enum {
  124. WATCH_NOTIFY = 1, /* notifying watcher */
  125. WATCH_NOTIFY_COMPLETE = 2, /* notifier notified when done */
  126. };
  127. struct ceph_mon_request_header {
  128. __le64 have_version;
  129. __le16 session_mon;
  130. __le64 session_mon_tid;
  131. } __attribute__ ((packed));
  132. struct ceph_mon_statfs {
  133. struct ceph_mon_request_header monhdr;
  134. struct ceph_fsid fsid;
  135. } __attribute__ ((packed));
  136. struct ceph_statfs {
  137. __le64 kb, kb_used, kb_avail;
  138. __le64 num_objects;
  139. } __attribute__ ((packed));
  140. struct ceph_mon_statfs_reply {
  141. struct ceph_fsid fsid;
  142. __le64 version;
  143. struct ceph_statfs st;
  144. } __attribute__ ((packed));
  145. struct ceph_osd_getmap {
  146. struct ceph_mon_request_header monhdr;
  147. struct ceph_fsid fsid;
  148. __le32 start;
  149. } __attribute__ ((packed));
  150. struct ceph_mds_getmap {
  151. struct ceph_mon_request_header monhdr;
  152. struct ceph_fsid fsid;
  153. } __attribute__ ((packed));
  154. struct ceph_client_mount {
  155. struct ceph_mon_request_header monhdr;
  156. } __attribute__ ((packed));
  157. #define CEPH_SUBSCRIBE_ONETIME 1 /* i want only 1 update after have */
  158. struct ceph_mon_subscribe_item {
  159. __le64 have_version; __le64 have;
  160. __u8 onetime;
  161. } __attribute__ ((packed));
  162. struct ceph_mon_subscribe_ack {
  163. __le32 duration; /* seconds */
  164. struct ceph_fsid fsid;
  165. } __attribute__ ((packed));
  166. /*
  167. * mdsmap flags
  168. */
  169. #define CEPH_MDSMAP_DOWN (1<<0) /* cluster deliberately down */
  170. /*
  171. * mds states
  172. * > 0 -> in
  173. * <= 0 -> out
  174. */
  175. #define CEPH_MDS_STATE_DNE 0 /* down, does not exist. */
  176. #define CEPH_MDS_STATE_STOPPED -1 /* down, once existed, but no subtrees.
  177. empty log. */
  178. #define CEPH_MDS_STATE_BOOT -4 /* up, boot announcement. */
  179. #define CEPH_MDS_STATE_STANDBY -5 /* up, idle. waiting for assignment. */
  180. #define CEPH_MDS_STATE_CREATING -6 /* up, creating MDS instance. */
  181. #define CEPH_MDS_STATE_STARTING -7 /* up, starting previously stopped mds */
  182. #define CEPH_MDS_STATE_STANDBY_REPLAY -8 /* up, tailing active node's journal */
  183. #define CEPH_MDS_STATE_REPLAYONCE -9 /* up, replaying an active node's journal */
  184. #define CEPH_MDS_STATE_REPLAY 8 /* up, replaying journal. */
  185. #define CEPH_MDS_STATE_RESOLVE 9 /* up, disambiguating distributed
  186. operations (import, rename, etc.) */
  187. #define CEPH_MDS_STATE_RECONNECT 10 /* up, reconnect to clients */
  188. #define CEPH_MDS_STATE_REJOIN 11 /* up, rejoining distributed cache */
  189. #define CEPH_MDS_STATE_CLIENTREPLAY 12 /* up, replaying client operations */
  190. #define CEPH_MDS_STATE_ACTIVE 13 /* up, active */
  191. #define CEPH_MDS_STATE_STOPPING 14 /* up, but exporting metadata */
  192. extern const char *ceph_mds_state_name(int s);
  193. /*
  194. * metadata lock types.
  195. * - these are bitmasks.. we can compose them
  196. * - they also define the lock ordering by the MDS
  197. * - a few of these are internal to the mds
  198. */
  199. #define CEPH_LOCK_DVERSION 1
  200. #define CEPH_LOCK_DN 2
  201. #define CEPH_LOCK_ISNAP 16
  202. #define CEPH_LOCK_IVERSION 32 /* mds internal */
  203. #define CEPH_LOCK_IFILE 64
  204. #define CEPH_LOCK_IAUTH 128
  205. #define CEPH_LOCK_ILINK 256
  206. #define CEPH_LOCK_IDFT 512 /* dir frag tree */
  207. #define CEPH_LOCK_INEST 1024 /* mds internal */
  208. #define CEPH_LOCK_IXATTR 2048
  209. #define CEPH_LOCK_IFLOCK 4096 /* advisory file locks */
  210. #define CEPH_LOCK_INO 8192 /* immutable inode bits; not a lock */
  211. #define CEPH_LOCK_IPOLICY 16384 /* policy lock on dirs. MDS internal */
  212. /* client_session ops */
  213. enum {
  214. CEPH_SESSION_REQUEST_OPEN,
  215. CEPH_SESSION_OPEN,
  216. CEPH_SESSION_REQUEST_CLOSE,
  217. CEPH_SESSION_CLOSE,
  218. CEPH_SESSION_REQUEST_RENEWCAPS,
  219. CEPH_SESSION_RENEWCAPS,
  220. CEPH_SESSION_STALE,
  221. CEPH_SESSION_RECALL_STATE,
  222. CEPH_SESSION_FLUSHMSG,
  223. CEPH_SESSION_FLUSHMSG_ACK,
  224. CEPH_SESSION_FORCE_RO,
  225. };
  226. extern const char *ceph_session_op_name(int op);
  227. struct ceph_mds_session_head {
  228. __le32 op;
  229. __le64 seq;
  230. struct ceph_timespec stamp;
  231. __le32 max_caps, max_leases;
  232. } __attribute__ ((packed));
  233. /* client_request */
  234. /*
  235. * metadata ops.
  236. * & 0x001000 -> write op
  237. * & 0x010000 -> follow symlink (e.g. stat(), not lstat()).
  238. & & 0x100000 -> use weird ino/path trace
  239. */
  240. #define CEPH_MDS_OP_WRITE 0x001000
  241. enum {
  242. CEPH_MDS_OP_LOOKUP = 0x00100,
  243. CEPH_MDS_OP_GETATTR = 0x00101,
  244. CEPH_MDS_OP_LOOKUPHASH = 0x00102,
  245. CEPH_MDS_OP_LOOKUPPARENT = 0x00103,
  246. CEPH_MDS_OP_LOOKUPINO = 0x00104,
  247. CEPH_MDS_OP_LOOKUPNAME = 0x00105,
  248. CEPH_MDS_OP_SETXATTR = 0x01105,
  249. CEPH_MDS_OP_RMXATTR = 0x01106,
  250. CEPH_MDS_OP_SETLAYOUT = 0x01107,
  251. CEPH_MDS_OP_SETATTR = 0x01108,
  252. CEPH_MDS_OP_SETFILELOCK= 0x01109,
  253. CEPH_MDS_OP_GETFILELOCK= 0x00110,
  254. CEPH_MDS_OP_SETDIRLAYOUT=0x0110a,
  255. CEPH_MDS_OP_MKNOD = 0x01201,
  256. CEPH_MDS_OP_LINK = 0x01202,
  257. CEPH_MDS_OP_UNLINK = 0x01203,
  258. CEPH_MDS_OP_RENAME = 0x01204,
  259. CEPH_MDS_OP_MKDIR = 0x01220,
  260. CEPH_MDS_OP_RMDIR = 0x01221,
  261. CEPH_MDS_OP_SYMLINK = 0x01222,
  262. CEPH_MDS_OP_CREATE = 0x01301,
  263. CEPH_MDS_OP_OPEN = 0x00302,
  264. CEPH_MDS_OP_READDIR = 0x00305,
  265. CEPH_MDS_OP_LOOKUPSNAP = 0x00400,
  266. CEPH_MDS_OP_MKSNAP = 0x01400,
  267. CEPH_MDS_OP_RMSNAP = 0x01401,
  268. CEPH_MDS_OP_LSSNAP = 0x00402,
  269. CEPH_MDS_OP_RENAMESNAP = 0x01403,
  270. };
  271. extern const char *ceph_mds_op_name(int op);
  272. #define CEPH_SETATTR_MODE 1
  273. #define CEPH_SETATTR_UID 2
  274. #define CEPH_SETATTR_GID 4
  275. #define CEPH_SETATTR_MTIME 8
  276. #define CEPH_SETATTR_ATIME 16
  277. #define CEPH_SETATTR_SIZE 32
  278. #define CEPH_SETATTR_CTIME 64
  279. /*
  280. * Ceph setxattr request flags.
  281. */
  282. #define CEPH_XATTR_CREATE (1 << 0)
  283. #define CEPH_XATTR_REPLACE (1 << 1)
  284. #define CEPH_XATTR_REMOVE (1 << 31)
  285. union ceph_mds_request_args {
  286. struct {
  287. __le32 mask; /* CEPH_CAP_* */
  288. } __attribute__ ((packed)) getattr;
  289. struct {
  290. __le32 mode;
  291. __le32 uid;
  292. __le32 gid;
  293. struct ceph_timespec mtime;
  294. struct ceph_timespec atime;
  295. __le64 size, old_size; /* old_size needed by truncate */
  296. __le32 mask; /* CEPH_SETATTR_* */
  297. } __attribute__ ((packed)) setattr;
  298. struct {
  299. __le32 frag; /* which dir fragment */
  300. __le32 max_entries; /* how many dentries to grab */
  301. __le32 max_bytes;
  302. } __attribute__ ((packed)) readdir;
  303. struct {
  304. __le32 mode;
  305. __le32 rdev;
  306. } __attribute__ ((packed)) mknod;
  307. struct {
  308. __le32 mode;
  309. } __attribute__ ((packed)) mkdir;
  310. struct {
  311. __le32 flags;
  312. __le32 mode;
  313. __le32 stripe_unit; /* layout for newly created file */
  314. __le32 stripe_count; /* ... */
  315. __le32 object_size;
  316. __le32 file_replication;
  317. __le32 unused; /* used to be preferred osd */
  318. } __attribute__ ((packed)) open;
  319. struct {
  320. __le32 flags;
  321. } __attribute__ ((packed)) setxattr;
  322. struct {
  323. struct ceph_file_layout layout;
  324. } __attribute__ ((packed)) setlayout;
  325. struct {
  326. __u8 rule; /* currently fcntl or flock */
  327. __u8 type; /* shared, exclusive, remove*/
  328. __le64 owner; /* owner of the lock */
  329. __le64 pid; /* process id requesting the lock */
  330. __le64 start; /* initial location to lock */
  331. __le64 length; /* num bytes to lock from start */
  332. __u8 wait; /* will caller wait for lock to become available? */
  333. } __attribute__ ((packed)) filelock_change;
  334. } __attribute__ ((packed));
  335. #define CEPH_MDS_FLAG_REPLAY 1 /* this is a replayed op */
  336. #define CEPH_MDS_FLAG_WANT_DENTRY 2 /* want dentry in reply */
  337. struct ceph_mds_request_head {
  338. __le64 oldest_client_tid;
  339. __le32 mdsmap_epoch; /* on client */
  340. __le32 flags; /* CEPH_MDS_FLAG_* */
  341. __u8 num_retry, num_fwd; /* count retry, fwd attempts */
  342. __le16 num_releases; /* # include cap/lease release records */
  343. __le32 op; /* mds op code */
  344. __le32 caller_uid, caller_gid;
  345. __le64 ino; /* use this ino for openc, mkdir, mknod,
  346. etc. (if replaying) */
  347. union ceph_mds_request_args args;
  348. } __attribute__ ((packed));
  349. /* cap/lease release record */
  350. struct ceph_mds_request_release {
  351. __le64 ino, cap_id; /* ino and unique cap id */
  352. __le32 caps, wanted; /* new issued, wanted */
  353. __le32 seq, issue_seq, mseq;
  354. __le32 dname_seq; /* if releasing a dentry lease, a */
  355. __le32 dname_len; /* string follows. */
  356. } __attribute__ ((packed));
  357. /* client reply */
  358. struct ceph_mds_reply_head {
  359. __le32 op;
  360. __le32 result;
  361. __le32 mdsmap_epoch;
  362. __u8 safe; /* true if committed to disk */
  363. __u8 is_dentry, is_target; /* true if dentry, target inode records
  364. are included with reply */
  365. } __attribute__ ((packed));
  366. /* one for each node split */
  367. struct ceph_frag_tree_split {
  368. __le32 frag; /* this frag splits... */
  369. __le32 by; /* ...by this many bits */
  370. } __attribute__ ((packed));
  371. struct ceph_frag_tree_head {
  372. __le32 nsplits; /* num ceph_frag_tree_split records */
  373. struct ceph_frag_tree_split splits[];
  374. } __attribute__ ((packed));
  375. /* capability issue, for bundling with mds reply */
  376. struct ceph_mds_reply_cap {
  377. __le32 caps, wanted; /* caps issued, wanted */
  378. __le64 cap_id;
  379. __le32 seq, mseq;
  380. __le64 realm; /* snap realm */
  381. __u8 flags; /* CEPH_CAP_FLAG_* */
  382. } __attribute__ ((packed));
  383. #define CEPH_CAP_FLAG_AUTH (1 << 0) /* cap is issued by auth mds */
  384. #define CEPH_CAP_FLAG_RELEASE (1 << 1) /* release the cap */
  385. /* inode record, for bundling with mds reply */
  386. struct ceph_mds_reply_inode {
  387. __le64 ino;
  388. __le64 snapid;
  389. __le32 rdev;
  390. __le64 version; /* inode version */
  391. __le64 xattr_version; /* version for xattr blob */
  392. struct ceph_mds_reply_cap cap; /* caps issued for this inode */
  393. struct ceph_file_layout layout;
  394. struct ceph_timespec ctime, mtime, atime;
  395. __le32 time_warp_seq;
  396. __le64 size, max_size, truncate_size;
  397. __le32 truncate_seq;
  398. __le32 mode, uid, gid;
  399. __le32 nlink;
  400. __le64 files, subdirs, rbytes, rfiles, rsubdirs; /* dir stats */
  401. struct ceph_timespec rctime;
  402. struct ceph_frag_tree_head fragtree; /* (must be at end of struct) */
  403. } __attribute__ ((packed));
  404. /* followed by frag array, symlink string, dir layout, xattr blob */
  405. /* reply_lease follows dname, and reply_inode */
  406. struct ceph_mds_reply_lease {
  407. __le16 mask; /* lease type(s) */
  408. __le32 duration_ms; /* lease duration */
  409. __le32 seq;
  410. } __attribute__ ((packed));
  411. struct ceph_mds_reply_dirfrag {
  412. __le32 frag; /* fragment */
  413. __le32 auth; /* auth mds, if this is a delegation point */
  414. __le32 ndist; /* number of mds' this is replicated on */
  415. __le32 dist[];
  416. } __attribute__ ((packed));
  417. #define CEPH_LOCK_FCNTL 1
  418. #define CEPH_LOCK_FLOCK 2
  419. #define CEPH_LOCK_FCNTL_INTR 3
  420. #define CEPH_LOCK_FLOCK_INTR 4
  421. #define CEPH_LOCK_SHARED 1
  422. #define CEPH_LOCK_EXCL 2
  423. #define CEPH_LOCK_UNLOCK 4
  424. struct ceph_filelock {
  425. __le64 start;/* file offset to start lock at */
  426. __le64 length; /* num bytes to lock; 0 for all following start */
  427. __le64 client; /* which client holds the lock */
  428. __le64 owner; /* owner the lock */
  429. __le64 pid; /* process id holding the lock on the client */
  430. __u8 type; /* shared lock, exclusive lock, or unlock */
  431. } __attribute__ ((packed));
  432. /* file access modes */
  433. #define CEPH_FILE_MODE_PIN 0
  434. #define CEPH_FILE_MODE_RD 1
  435. #define CEPH_FILE_MODE_WR 2
  436. #define CEPH_FILE_MODE_RDWR 3 /* RD | WR */
  437. #define CEPH_FILE_MODE_LAZY 4 /* lazy io */
  438. #define CEPH_FILE_MODE_NUM 8 /* bc these are bit fields.. mostly */
  439. int ceph_flags_to_mode(int flags);
  440. #define CEPH_INLINE_NONE ((__u64)-1)
  441. /* capability bits */
  442. #define CEPH_CAP_PIN 1 /* no specific capabilities beyond the pin */
  443. /* generic cap bits */
  444. #define CEPH_CAP_GSHARED 1 /* client can reads */
  445. #define CEPH_CAP_GEXCL 2 /* client can read and update */
  446. #define CEPH_CAP_GCACHE 4 /* (file) client can cache reads */
  447. #define CEPH_CAP_GRD 8 /* (file) client can read */
  448. #define CEPH_CAP_GWR 16 /* (file) client can write */
  449. #define CEPH_CAP_GBUFFER 32 /* (file) client can buffer writes */
  450. #define CEPH_CAP_GWREXTEND 64 /* (file) client can extend EOF */
  451. #define CEPH_CAP_GLAZYIO 128 /* (file) client can perform lazy io */
  452. #define CEPH_CAP_SIMPLE_BITS 2
  453. #define CEPH_CAP_FILE_BITS 8
  454. /* per-lock shift */
  455. #define CEPH_CAP_SAUTH 2
  456. #define CEPH_CAP_SLINK 4
  457. #define CEPH_CAP_SXATTR 6
  458. #define CEPH_CAP_SFILE 8
  459. #define CEPH_CAP_SFLOCK 20
  460. #define CEPH_CAP_BITS 22
  461. /* composed values */
  462. #define CEPH_CAP_AUTH_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SAUTH)
  463. #define CEPH_CAP_AUTH_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SAUTH)
  464. #define CEPH_CAP_LINK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SLINK)
  465. #define CEPH_CAP_LINK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SLINK)
  466. #define CEPH_CAP_XATTR_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SXATTR)
  467. #define CEPH_CAP_XATTR_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SXATTR)
  468. #define CEPH_CAP_FILE(x) (x << CEPH_CAP_SFILE)
  469. #define CEPH_CAP_FILE_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFILE)
  470. #define CEPH_CAP_FILE_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFILE)
  471. #define CEPH_CAP_FILE_CACHE (CEPH_CAP_GCACHE << CEPH_CAP_SFILE)
  472. #define CEPH_CAP_FILE_RD (CEPH_CAP_GRD << CEPH_CAP_SFILE)
  473. #define CEPH_CAP_FILE_WR (CEPH_CAP_GWR << CEPH_CAP_SFILE)
  474. #define CEPH_CAP_FILE_BUFFER (CEPH_CAP_GBUFFER << CEPH_CAP_SFILE)
  475. #define CEPH_CAP_FILE_WREXTEND (CEPH_CAP_GWREXTEND << CEPH_CAP_SFILE)
  476. #define CEPH_CAP_FILE_LAZYIO (CEPH_CAP_GLAZYIO << CEPH_CAP_SFILE)
  477. #define CEPH_CAP_FLOCK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFLOCK)
  478. #define CEPH_CAP_FLOCK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFLOCK)
  479. /* cap masks (for getattr) */
  480. #define CEPH_STAT_CAP_INODE CEPH_CAP_PIN
  481. #define CEPH_STAT_CAP_TYPE CEPH_CAP_PIN /* mode >> 12 */
  482. #define CEPH_STAT_CAP_SYMLINK CEPH_CAP_PIN
  483. #define CEPH_STAT_CAP_UID CEPH_CAP_AUTH_SHARED
  484. #define CEPH_STAT_CAP_GID CEPH_CAP_AUTH_SHARED
  485. #define CEPH_STAT_CAP_MODE CEPH_CAP_AUTH_SHARED
  486. #define CEPH_STAT_CAP_NLINK CEPH_CAP_LINK_SHARED
  487. #define CEPH_STAT_CAP_LAYOUT CEPH_CAP_FILE_SHARED
  488. #define CEPH_STAT_CAP_MTIME CEPH_CAP_FILE_SHARED
  489. #define CEPH_STAT_CAP_SIZE CEPH_CAP_FILE_SHARED
  490. #define CEPH_STAT_CAP_ATIME CEPH_CAP_FILE_SHARED /* fixme */
  491. #define CEPH_STAT_CAP_XATTR CEPH_CAP_XATTR_SHARED
  492. #define CEPH_STAT_CAP_INODE_ALL (CEPH_CAP_PIN | \
  493. CEPH_CAP_AUTH_SHARED | \
  494. CEPH_CAP_LINK_SHARED | \
  495. CEPH_CAP_FILE_SHARED | \
  496. CEPH_CAP_XATTR_SHARED)
  497. #define CEPH_STAT_CAP_INLINE_DATA (CEPH_CAP_FILE_SHARED | \
  498. CEPH_CAP_FILE_RD)
  499. #define CEPH_CAP_ANY_SHARED (CEPH_CAP_AUTH_SHARED | \
  500. CEPH_CAP_LINK_SHARED | \
  501. CEPH_CAP_XATTR_SHARED | \
  502. CEPH_CAP_FILE_SHARED)
  503. #define CEPH_CAP_ANY_RD (CEPH_CAP_ANY_SHARED | CEPH_CAP_FILE_RD | \
  504. CEPH_CAP_FILE_CACHE)
  505. #define CEPH_CAP_ANY_EXCL (CEPH_CAP_AUTH_EXCL | \
  506. CEPH_CAP_LINK_EXCL | \
  507. CEPH_CAP_XATTR_EXCL | \
  508. CEPH_CAP_FILE_EXCL)
  509. #define CEPH_CAP_ANY_FILE_RD (CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE | \
  510. CEPH_CAP_FILE_SHARED)
  511. #define CEPH_CAP_ANY_FILE_WR (CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER | \
  512. CEPH_CAP_FILE_EXCL)
  513. #define CEPH_CAP_ANY_WR (CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_FILE_WR)
  514. #define CEPH_CAP_ANY (CEPH_CAP_ANY_RD | CEPH_CAP_ANY_EXCL | \
  515. CEPH_CAP_ANY_FILE_WR | CEPH_CAP_FILE_LAZYIO | \
  516. CEPH_CAP_PIN)
  517. #define CEPH_CAP_LOCKS (CEPH_LOCK_IFILE | CEPH_LOCK_IAUTH | CEPH_LOCK_ILINK | \
  518. CEPH_LOCK_IXATTR)
  519. int ceph_caps_for_mode(int mode);
  520. enum {
  521. CEPH_CAP_OP_GRANT, /* mds->client grant */
  522. CEPH_CAP_OP_REVOKE, /* mds->client revoke */
  523. CEPH_CAP_OP_TRUNC, /* mds->client trunc notify */
  524. CEPH_CAP_OP_EXPORT, /* mds has exported the cap */
  525. CEPH_CAP_OP_IMPORT, /* mds has imported the cap */
  526. CEPH_CAP_OP_UPDATE, /* client->mds update */
  527. CEPH_CAP_OP_DROP, /* client->mds drop cap bits */
  528. CEPH_CAP_OP_FLUSH, /* client->mds cap writeback */
  529. CEPH_CAP_OP_FLUSH_ACK, /* mds->client flushed */
  530. CEPH_CAP_OP_FLUSHSNAP, /* client->mds flush snapped metadata */
  531. CEPH_CAP_OP_FLUSHSNAP_ACK, /* mds->client flushed snapped metadata */
  532. CEPH_CAP_OP_RELEASE, /* client->mds release (clean) cap */
  533. CEPH_CAP_OP_RENEW, /* client->mds renewal request */
  534. };
  535. extern const char *ceph_cap_op_name(int op);
  536. /*
  537. * caps message, used for capability callbacks, acks, requests, etc.
  538. */
  539. struct ceph_mds_caps {
  540. __le32 op; /* CEPH_CAP_OP_* */
  541. __le64 ino, realm;
  542. __le64 cap_id;
  543. __le32 seq, issue_seq;
  544. __le32 caps, wanted, dirty; /* latest issued/wanted/dirty */
  545. __le32 migrate_seq;
  546. __le64 snap_follows;
  547. __le32 snap_trace_len;
  548. /* authlock */
  549. __le32 uid, gid, mode;
  550. /* linklock */
  551. __le32 nlink;
  552. /* xattrlock */
  553. __le32 xattr_len;
  554. __le64 xattr_version;
  555. /* filelock */
  556. __le64 size, max_size, truncate_size;
  557. __le32 truncate_seq;
  558. struct ceph_timespec mtime, atime, ctime;
  559. struct ceph_file_layout layout;
  560. __le32 time_warp_seq;
  561. } __attribute__ ((packed));
  562. struct ceph_mds_cap_peer {
  563. __le64 cap_id;
  564. __le32 seq;
  565. __le32 mseq;
  566. __le32 mds;
  567. __u8 flags;
  568. } __attribute__ ((packed));
  569. /* cap release msg head */
  570. struct ceph_mds_cap_release {
  571. __le32 num; /* number of cap_items that follow */
  572. } __attribute__ ((packed));
  573. struct ceph_mds_cap_item {
  574. __le64 ino;
  575. __le64 cap_id;
  576. __le32 migrate_seq, seq;
  577. } __attribute__ ((packed));
  578. #define CEPH_MDS_LEASE_REVOKE 1 /* mds -> client */
  579. #define CEPH_MDS_LEASE_RELEASE 2 /* client -> mds */
  580. #define CEPH_MDS_LEASE_RENEW 3 /* client <-> mds */
  581. #define CEPH_MDS_LEASE_REVOKE_ACK 4 /* client -> mds */
  582. extern const char *ceph_lease_op_name(int o);
  583. /* lease msg header */
  584. struct ceph_mds_lease {
  585. __u8 action; /* CEPH_MDS_LEASE_* */
  586. __le16 mask; /* which lease */
  587. __le64 ino;
  588. __le64 first, last; /* snap range */
  589. __le32 seq;
  590. __le32 duration_ms; /* duration of renewal */
  591. } __attribute__ ((packed));
  592. /* followed by a __le32+string for dname */
  593. /* client reconnect */
  594. struct ceph_mds_cap_reconnect {
  595. __le64 cap_id;
  596. __le32 wanted;
  597. __le32 issued;
  598. __le64 snaprealm;
  599. __le64 pathbase; /* base ino for our path to this ino */
  600. __le32 flock_len; /* size of flock state blob, if any */
  601. } __attribute__ ((packed));
  602. /* followed by flock blob */
  603. struct ceph_mds_cap_reconnect_v1 {
  604. __le64 cap_id;
  605. __le32 wanted;
  606. __le32 issued;
  607. __le64 size;
  608. struct ceph_timespec mtime, atime;
  609. __le64 snaprealm;
  610. __le64 pathbase; /* base ino for our path to this ino */
  611. } __attribute__ ((packed));
  612. struct ceph_mds_snaprealm_reconnect {
  613. __le64 ino; /* snap realm base */
  614. __le64 seq; /* snap seq for this snap realm */
  615. __le64 parent; /* parent realm */
  616. } __attribute__ ((packed));
  617. /*
  618. * snaps
  619. */
  620. enum {
  621. CEPH_SNAP_OP_UPDATE, /* CREATE or DESTROY */
  622. CEPH_SNAP_OP_CREATE,
  623. CEPH_SNAP_OP_DESTROY,
  624. CEPH_SNAP_OP_SPLIT,
  625. };
  626. extern const char *ceph_snap_op_name(int o);
  627. /* snap msg header */
  628. struct ceph_mds_snap_head {
  629. __le32 op; /* CEPH_SNAP_OP_* */
  630. __le64 split; /* ino to split off, if any */
  631. __le32 num_split_inos; /* # inos belonging to new child realm */
  632. __le32 num_split_realms; /* # child realms udner new child realm */
  633. __le32 trace_len; /* size of snap trace blob */
  634. } __attribute__ ((packed));
  635. /* followed by split ino list, then split realms, then the trace blob */
  636. /*
  637. * encode info about a snaprealm, as viewed by a client
  638. */
  639. struct ceph_mds_snap_realm {
  640. __le64 ino; /* ino */
  641. __le64 created; /* snap: when created */
  642. __le64 parent; /* ino: parent realm */
  643. __le64 parent_since; /* snap: same parent since */
  644. __le64 seq; /* snap: version */
  645. __le32 num_snaps;
  646. __le32 num_prior_parent_snaps;
  647. } __attribute__ ((packed));
  648. /* followed by my snap list, then prior parent snap list */
  649. #endif