ceph_fs.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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. /* pool operations */
  128. enum {
  129. POOL_OP_CREATE = 0x01,
  130. POOL_OP_DELETE = 0x02,
  131. POOL_OP_AUID_CHANGE = 0x03,
  132. POOL_OP_CREATE_SNAP = 0x11,
  133. POOL_OP_DELETE_SNAP = 0x12,
  134. POOL_OP_CREATE_UNMANAGED_SNAP = 0x21,
  135. POOL_OP_DELETE_UNMANAGED_SNAP = 0x22,
  136. };
  137. struct ceph_mon_request_header {
  138. __le64 have_version;
  139. __le16 session_mon;
  140. __le64 session_mon_tid;
  141. } __attribute__ ((packed));
  142. struct ceph_mon_statfs {
  143. struct ceph_mon_request_header monhdr;
  144. struct ceph_fsid fsid;
  145. } __attribute__ ((packed));
  146. struct ceph_statfs {
  147. __le64 kb, kb_used, kb_avail;
  148. __le64 num_objects;
  149. } __attribute__ ((packed));
  150. struct ceph_mon_statfs_reply {
  151. struct ceph_fsid fsid;
  152. __le64 version;
  153. struct ceph_statfs st;
  154. } __attribute__ ((packed));
  155. const char *ceph_pool_op_name(int op);
  156. struct ceph_mon_poolop {
  157. struct ceph_mon_request_header monhdr;
  158. struct ceph_fsid fsid;
  159. __le32 pool;
  160. __le32 op;
  161. __le64 auid;
  162. __le64 snapid;
  163. __le32 name_len;
  164. } __attribute__ ((packed));
  165. struct ceph_mon_poolop_reply {
  166. struct ceph_mon_request_header monhdr;
  167. struct ceph_fsid fsid;
  168. __le32 reply_code;
  169. __le32 epoch;
  170. char has_data;
  171. char data[0];
  172. } __attribute__ ((packed));
  173. struct ceph_mon_unmanaged_snap {
  174. __le64 snapid;
  175. } __attribute__ ((packed));
  176. struct ceph_osd_getmap {
  177. struct ceph_mon_request_header monhdr;
  178. struct ceph_fsid fsid;
  179. __le32 start;
  180. } __attribute__ ((packed));
  181. struct ceph_mds_getmap {
  182. struct ceph_mon_request_header monhdr;
  183. struct ceph_fsid fsid;
  184. } __attribute__ ((packed));
  185. struct ceph_client_mount {
  186. struct ceph_mon_request_header monhdr;
  187. } __attribute__ ((packed));
  188. #define CEPH_SUBSCRIBE_ONETIME 1 /* i want only 1 update after have */
  189. struct ceph_mon_subscribe_item {
  190. __le64 have_version; __le64 have;
  191. __u8 onetime;
  192. } __attribute__ ((packed));
  193. struct ceph_mon_subscribe_ack {
  194. __le32 duration; /* seconds */
  195. struct ceph_fsid fsid;
  196. } __attribute__ ((packed));
  197. /*
  198. * mdsmap flags
  199. */
  200. #define CEPH_MDSMAP_DOWN (1<<0) /* cluster deliberately down */
  201. /*
  202. * mds states
  203. * > 0 -> in
  204. * <= 0 -> out
  205. */
  206. #define CEPH_MDS_STATE_DNE 0 /* down, does not exist. */
  207. #define CEPH_MDS_STATE_STOPPED -1 /* down, once existed, but no subtrees.
  208. empty log. */
  209. #define CEPH_MDS_STATE_BOOT -4 /* up, boot announcement. */
  210. #define CEPH_MDS_STATE_STANDBY -5 /* up, idle. waiting for assignment. */
  211. #define CEPH_MDS_STATE_CREATING -6 /* up, creating MDS instance. */
  212. #define CEPH_MDS_STATE_STARTING -7 /* up, starting previously stopped mds */
  213. #define CEPH_MDS_STATE_STANDBY_REPLAY -8 /* up, tailing active node's journal */
  214. #define CEPH_MDS_STATE_REPLAYONCE -9 /* up, replaying an active node's journal */
  215. #define CEPH_MDS_STATE_REPLAY 8 /* up, replaying journal. */
  216. #define CEPH_MDS_STATE_RESOLVE 9 /* up, disambiguating distributed
  217. operations (import, rename, etc.) */
  218. #define CEPH_MDS_STATE_RECONNECT 10 /* up, reconnect to clients */
  219. #define CEPH_MDS_STATE_REJOIN 11 /* up, rejoining distributed cache */
  220. #define CEPH_MDS_STATE_CLIENTREPLAY 12 /* up, replaying client operations */
  221. #define CEPH_MDS_STATE_ACTIVE 13 /* up, active */
  222. #define CEPH_MDS_STATE_STOPPING 14 /* up, but exporting metadata */
  223. extern const char *ceph_mds_state_name(int s);
  224. /*
  225. * metadata lock types.
  226. * - these are bitmasks.. we can compose them
  227. * - they also define the lock ordering by the MDS
  228. * - a few of these are internal to the mds
  229. */
  230. #define CEPH_LOCK_DVERSION 1
  231. #define CEPH_LOCK_DN 2
  232. #define CEPH_LOCK_ISNAP 16
  233. #define CEPH_LOCK_IVERSION 32 /* mds internal */
  234. #define CEPH_LOCK_IFILE 64
  235. #define CEPH_LOCK_IAUTH 128
  236. #define CEPH_LOCK_ILINK 256
  237. #define CEPH_LOCK_IDFT 512 /* dir frag tree */
  238. #define CEPH_LOCK_INEST 1024 /* mds internal */
  239. #define CEPH_LOCK_IXATTR 2048
  240. #define CEPH_LOCK_IFLOCK 4096 /* advisory file locks */
  241. #define CEPH_LOCK_INO 8192 /* immutable inode bits; not a lock */
  242. #define CEPH_LOCK_IPOLICY 16384 /* policy lock on dirs. MDS internal */
  243. /* client_session ops */
  244. enum {
  245. CEPH_SESSION_REQUEST_OPEN,
  246. CEPH_SESSION_OPEN,
  247. CEPH_SESSION_REQUEST_CLOSE,
  248. CEPH_SESSION_CLOSE,
  249. CEPH_SESSION_REQUEST_RENEWCAPS,
  250. CEPH_SESSION_RENEWCAPS,
  251. CEPH_SESSION_STALE,
  252. CEPH_SESSION_RECALL_STATE,
  253. CEPH_SESSION_FLUSHMSG,
  254. CEPH_SESSION_FLUSHMSG_ACK,
  255. };
  256. extern const char *ceph_session_op_name(int op);
  257. struct ceph_mds_session_head {
  258. __le32 op;
  259. __le64 seq;
  260. struct ceph_timespec stamp;
  261. __le32 max_caps, max_leases;
  262. } __attribute__ ((packed));
  263. /* client_request */
  264. /*
  265. * metadata ops.
  266. * & 0x001000 -> write op
  267. * & 0x010000 -> follow symlink (e.g. stat(), not lstat()).
  268. & & 0x100000 -> use weird ino/path trace
  269. */
  270. #define CEPH_MDS_OP_WRITE 0x001000
  271. enum {
  272. CEPH_MDS_OP_LOOKUP = 0x00100,
  273. CEPH_MDS_OP_GETATTR = 0x00101,
  274. CEPH_MDS_OP_LOOKUPHASH = 0x00102,
  275. CEPH_MDS_OP_LOOKUPPARENT = 0x00103,
  276. CEPH_MDS_OP_LOOKUPINO = 0x00104,
  277. CEPH_MDS_OP_LOOKUPNAME = 0x00105,
  278. CEPH_MDS_OP_SETXATTR = 0x01105,
  279. CEPH_MDS_OP_RMXATTR = 0x01106,
  280. CEPH_MDS_OP_SETLAYOUT = 0x01107,
  281. CEPH_MDS_OP_SETATTR = 0x01108,
  282. CEPH_MDS_OP_SETFILELOCK= 0x01109,
  283. CEPH_MDS_OP_GETFILELOCK= 0x00110,
  284. CEPH_MDS_OP_SETDIRLAYOUT=0x0110a,
  285. CEPH_MDS_OP_MKNOD = 0x01201,
  286. CEPH_MDS_OP_LINK = 0x01202,
  287. CEPH_MDS_OP_UNLINK = 0x01203,
  288. CEPH_MDS_OP_RENAME = 0x01204,
  289. CEPH_MDS_OP_MKDIR = 0x01220,
  290. CEPH_MDS_OP_RMDIR = 0x01221,
  291. CEPH_MDS_OP_SYMLINK = 0x01222,
  292. CEPH_MDS_OP_CREATE = 0x01301,
  293. CEPH_MDS_OP_OPEN = 0x00302,
  294. CEPH_MDS_OP_READDIR = 0x00305,
  295. CEPH_MDS_OP_LOOKUPSNAP = 0x00400,
  296. CEPH_MDS_OP_MKSNAP = 0x01400,
  297. CEPH_MDS_OP_RMSNAP = 0x01401,
  298. CEPH_MDS_OP_LSSNAP = 0x00402,
  299. };
  300. extern const char *ceph_mds_op_name(int op);
  301. #define CEPH_SETATTR_MODE 1
  302. #define CEPH_SETATTR_UID 2
  303. #define CEPH_SETATTR_GID 4
  304. #define CEPH_SETATTR_MTIME 8
  305. #define CEPH_SETATTR_ATIME 16
  306. #define CEPH_SETATTR_SIZE 32
  307. #define CEPH_SETATTR_CTIME 64
  308. /*
  309. * Ceph setxattr request flags.
  310. */
  311. #define CEPH_XATTR_CREATE (1 << 0)
  312. #define CEPH_XATTR_REPLACE (1 << 1)
  313. #define CEPH_XATTR_REMOVE (1 << 31)
  314. union ceph_mds_request_args {
  315. struct {
  316. __le32 mask; /* CEPH_CAP_* */
  317. } __attribute__ ((packed)) getattr;
  318. struct {
  319. __le32 mode;
  320. __le32 uid;
  321. __le32 gid;
  322. struct ceph_timespec mtime;
  323. struct ceph_timespec atime;
  324. __le64 size, old_size; /* old_size needed by truncate */
  325. __le32 mask; /* CEPH_SETATTR_* */
  326. } __attribute__ ((packed)) setattr;
  327. struct {
  328. __le32 frag; /* which dir fragment */
  329. __le32 max_entries; /* how many dentries to grab */
  330. __le32 max_bytes;
  331. } __attribute__ ((packed)) readdir;
  332. struct {
  333. __le32 mode;
  334. __le32 rdev;
  335. } __attribute__ ((packed)) mknod;
  336. struct {
  337. __le32 mode;
  338. } __attribute__ ((packed)) mkdir;
  339. struct {
  340. __le32 flags;
  341. __le32 mode;
  342. __le32 stripe_unit; /* layout for newly created file */
  343. __le32 stripe_count; /* ... */
  344. __le32 object_size;
  345. __le32 file_replication;
  346. __le32 unused; /* used to be preferred osd */
  347. } __attribute__ ((packed)) open;
  348. struct {
  349. __le32 flags;
  350. } __attribute__ ((packed)) setxattr;
  351. struct {
  352. struct ceph_file_layout layout;
  353. } __attribute__ ((packed)) setlayout;
  354. struct {
  355. __u8 rule; /* currently fcntl or flock */
  356. __u8 type; /* shared, exclusive, remove*/
  357. __le64 owner; /* owner of the lock */
  358. __le64 pid; /* process id requesting the lock */
  359. __le64 start; /* initial location to lock */
  360. __le64 length; /* num bytes to lock from start */
  361. __u8 wait; /* will caller wait for lock to become available? */
  362. } __attribute__ ((packed)) filelock_change;
  363. } __attribute__ ((packed));
  364. #define CEPH_MDS_FLAG_REPLAY 1 /* this is a replayed op */
  365. #define CEPH_MDS_FLAG_WANT_DENTRY 2 /* want dentry in reply */
  366. struct ceph_mds_request_head {
  367. __le64 oldest_client_tid;
  368. __le32 mdsmap_epoch; /* on client */
  369. __le32 flags; /* CEPH_MDS_FLAG_* */
  370. __u8 num_retry, num_fwd; /* count retry, fwd attempts */
  371. __le16 num_releases; /* # include cap/lease release records */
  372. __le32 op; /* mds op code */
  373. __le32 caller_uid, caller_gid;
  374. __le64 ino; /* use this ino for openc, mkdir, mknod,
  375. etc. (if replaying) */
  376. union ceph_mds_request_args args;
  377. } __attribute__ ((packed));
  378. /* cap/lease release record */
  379. struct ceph_mds_request_release {
  380. __le64 ino, cap_id; /* ino and unique cap id */
  381. __le32 caps, wanted; /* new issued, wanted */
  382. __le32 seq, issue_seq, mseq;
  383. __le32 dname_seq; /* if releasing a dentry lease, a */
  384. __le32 dname_len; /* string follows. */
  385. } __attribute__ ((packed));
  386. /* client reply */
  387. struct ceph_mds_reply_head {
  388. __le32 op;
  389. __le32 result;
  390. __le32 mdsmap_epoch;
  391. __u8 safe; /* true if committed to disk */
  392. __u8 is_dentry, is_target; /* true if dentry, target inode records
  393. are included with reply */
  394. } __attribute__ ((packed));
  395. /* one for each node split */
  396. struct ceph_frag_tree_split {
  397. __le32 frag; /* this frag splits... */
  398. __le32 by; /* ...by this many bits */
  399. } __attribute__ ((packed));
  400. struct ceph_frag_tree_head {
  401. __le32 nsplits; /* num ceph_frag_tree_split records */
  402. struct ceph_frag_tree_split splits[];
  403. } __attribute__ ((packed));
  404. /* capability issue, for bundling with mds reply */
  405. struct ceph_mds_reply_cap {
  406. __le32 caps, wanted; /* caps issued, wanted */
  407. __le64 cap_id;
  408. __le32 seq, mseq;
  409. __le64 realm; /* snap realm */
  410. __u8 flags; /* CEPH_CAP_FLAG_* */
  411. } __attribute__ ((packed));
  412. #define CEPH_CAP_FLAG_AUTH (1 << 0) /* cap is issued by auth mds */
  413. #define CEPH_CAP_FLAG_RELEASE (1 << 1) /* release the cap */
  414. /* inode record, for bundling with mds reply */
  415. struct ceph_mds_reply_inode {
  416. __le64 ino;
  417. __le64 snapid;
  418. __le32 rdev;
  419. __le64 version; /* inode version */
  420. __le64 xattr_version; /* version for xattr blob */
  421. struct ceph_mds_reply_cap cap; /* caps issued for this inode */
  422. struct ceph_file_layout layout;
  423. struct ceph_timespec ctime, mtime, atime;
  424. __le32 time_warp_seq;
  425. __le64 size, max_size, truncate_size;
  426. __le32 truncate_seq;
  427. __le32 mode, uid, gid;
  428. __le32 nlink;
  429. __le64 files, subdirs, rbytes, rfiles, rsubdirs; /* dir stats */
  430. struct ceph_timespec rctime;
  431. struct ceph_frag_tree_head fragtree; /* (must be at end of struct) */
  432. } __attribute__ ((packed));
  433. /* followed by frag array, symlink string, dir layout, xattr blob */
  434. /* reply_lease follows dname, and reply_inode */
  435. struct ceph_mds_reply_lease {
  436. __le16 mask; /* lease type(s) */
  437. __le32 duration_ms; /* lease duration */
  438. __le32 seq;
  439. } __attribute__ ((packed));
  440. struct ceph_mds_reply_dirfrag {
  441. __le32 frag; /* fragment */
  442. __le32 auth; /* auth mds, if this is a delegation point */
  443. __le32 ndist; /* number of mds' this is replicated on */
  444. __le32 dist[];
  445. } __attribute__ ((packed));
  446. #define CEPH_LOCK_FCNTL 1
  447. #define CEPH_LOCK_FLOCK 2
  448. #define CEPH_LOCK_SHARED 1
  449. #define CEPH_LOCK_EXCL 2
  450. #define CEPH_LOCK_UNLOCK 4
  451. struct ceph_filelock {
  452. __le64 start;/* file offset to start lock at */
  453. __le64 length; /* num bytes to lock; 0 for all following start */
  454. __le64 client; /* which client holds the lock */
  455. __le64 owner; /* owner the lock */
  456. __le64 pid; /* process id holding the lock on the client */
  457. __u8 type; /* shared lock, exclusive lock, or unlock */
  458. } __attribute__ ((packed));
  459. /* file access modes */
  460. #define CEPH_FILE_MODE_PIN 0
  461. #define CEPH_FILE_MODE_RD 1
  462. #define CEPH_FILE_MODE_WR 2
  463. #define CEPH_FILE_MODE_RDWR 3 /* RD | WR */
  464. #define CEPH_FILE_MODE_LAZY 4 /* lazy io */
  465. #define CEPH_FILE_MODE_NUM 8 /* bc these are bit fields.. mostly */
  466. int ceph_flags_to_mode(int flags);
  467. /* capability bits */
  468. #define CEPH_CAP_PIN 1 /* no specific capabilities beyond the pin */
  469. /* generic cap bits */
  470. #define CEPH_CAP_GSHARED 1 /* client can reads */
  471. #define CEPH_CAP_GEXCL 2 /* client can read and update */
  472. #define CEPH_CAP_GCACHE 4 /* (file) client can cache reads */
  473. #define CEPH_CAP_GRD 8 /* (file) client can read */
  474. #define CEPH_CAP_GWR 16 /* (file) client can write */
  475. #define CEPH_CAP_GBUFFER 32 /* (file) client can buffer writes */
  476. #define CEPH_CAP_GWREXTEND 64 /* (file) client can extend EOF */
  477. #define CEPH_CAP_GLAZYIO 128 /* (file) client can perform lazy io */
  478. #define CEPH_CAP_SIMPLE_BITS 2
  479. #define CEPH_CAP_FILE_BITS 8
  480. /* per-lock shift */
  481. #define CEPH_CAP_SAUTH 2
  482. #define CEPH_CAP_SLINK 4
  483. #define CEPH_CAP_SXATTR 6
  484. #define CEPH_CAP_SFILE 8
  485. #define CEPH_CAP_SFLOCK 20
  486. #define CEPH_CAP_BITS 22
  487. /* composed values */
  488. #define CEPH_CAP_AUTH_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SAUTH)
  489. #define CEPH_CAP_AUTH_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SAUTH)
  490. #define CEPH_CAP_LINK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SLINK)
  491. #define CEPH_CAP_LINK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SLINK)
  492. #define CEPH_CAP_XATTR_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SXATTR)
  493. #define CEPH_CAP_XATTR_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SXATTR)
  494. #define CEPH_CAP_FILE(x) (x << CEPH_CAP_SFILE)
  495. #define CEPH_CAP_FILE_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFILE)
  496. #define CEPH_CAP_FILE_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFILE)
  497. #define CEPH_CAP_FILE_CACHE (CEPH_CAP_GCACHE << CEPH_CAP_SFILE)
  498. #define CEPH_CAP_FILE_RD (CEPH_CAP_GRD << CEPH_CAP_SFILE)
  499. #define CEPH_CAP_FILE_WR (CEPH_CAP_GWR << CEPH_CAP_SFILE)
  500. #define CEPH_CAP_FILE_BUFFER (CEPH_CAP_GBUFFER << CEPH_CAP_SFILE)
  501. #define CEPH_CAP_FILE_WREXTEND (CEPH_CAP_GWREXTEND << CEPH_CAP_SFILE)
  502. #define CEPH_CAP_FILE_LAZYIO (CEPH_CAP_GLAZYIO << CEPH_CAP_SFILE)
  503. #define CEPH_CAP_FLOCK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFLOCK)
  504. #define CEPH_CAP_FLOCK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFLOCK)
  505. /* cap masks (for getattr) */
  506. #define CEPH_STAT_CAP_INODE CEPH_CAP_PIN
  507. #define CEPH_STAT_CAP_TYPE CEPH_CAP_PIN /* mode >> 12 */
  508. #define CEPH_STAT_CAP_SYMLINK CEPH_CAP_PIN
  509. #define CEPH_STAT_CAP_UID CEPH_CAP_AUTH_SHARED
  510. #define CEPH_STAT_CAP_GID CEPH_CAP_AUTH_SHARED
  511. #define CEPH_STAT_CAP_MODE CEPH_CAP_AUTH_SHARED
  512. #define CEPH_STAT_CAP_NLINK CEPH_CAP_LINK_SHARED
  513. #define CEPH_STAT_CAP_LAYOUT CEPH_CAP_FILE_SHARED
  514. #define CEPH_STAT_CAP_MTIME CEPH_CAP_FILE_SHARED
  515. #define CEPH_STAT_CAP_SIZE CEPH_CAP_FILE_SHARED
  516. #define CEPH_STAT_CAP_ATIME CEPH_CAP_FILE_SHARED /* fixme */
  517. #define CEPH_STAT_CAP_XATTR CEPH_CAP_XATTR_SHARED
  518. #define CEPH_STAT_CAP_INODE_ALL (CEPH_CAP_PIN | \
  519. CEPH_CAP_AUTH_SHARED | \
  520. CEPH_CAP_LINK_SHARED | \
  521. CEPH_CAP_FILE_SHARED | \
  522. CEPH_CAP_XATTR_SHARED)
  523. #define CEPH_CAP_ANY_SHARED (CEPH_CAP_AUTH_SHARED | \
  524. CEPH_CAP_LINK_SHARED | \
  525. CEPH_CAP_XATTR_SHARED | \
  526. CEPH_CAP_FILE_SHARED)
  527. #define CEPH_CAP_ANY_RD (CEPH_CAP_ANY_SHARED | CEPH_CAP_FILE_RD | \
  528. CEPH_CAP_FILE_CACHE)
  529. #define CEPH_CAP_ANY_EXCL (CEPH_CAP_AUTH_EXCL | \
  530. CEPH_CAP_LINK_EXCL | \
  531. CEPH_CAP_XATTR_EXCL | \
  532. CEPH_CAP_FILE_EXCL)
  533. #define CEPH_CAP_ANY_FILE_RD (CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE | \
  534. CEPH_CAP_FILE_SHARED)
  535. #define CEPH_CAP_ANY_FILE_WR (CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER | \
  536. CEPH_CAP_FILE_EXCL)
  537. #define CEPH_CAP_ANY_WR (CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_FILE_WR)
  538. #define CEPH_CAP_ANY (CEPH_CAP_ANY_RD | CEPH_CAP_ANY_EXCL | \
  539. CEPH_CAP_ANY_FILE_WR | CEPH_CAP_FILE_LAZYIO | \
  540. CEPH_CAP_PIN)
  541. #define CEPH_CAP_LOCKS (CEPH_LOCK_IFILE | CEPH_LOCK_IAUTH | CEPH_LOCK_ILINK | \
  542. CEPH_LOCK_IXATTR)
  543. int ceph_caps_for_mode(int mode);
  544. enum {
  545. CEPH_CAP_OP_GRANT, /* mds->client grant */
  546. CEPH_CAP_OP_REVOKE, /* mds->client revoke */
  547. CEPH_CAP_OP_TRUNC, /* mds->client trunc notify */
  548. CEPH_CAP_OP_EXPORT, /* mds has exported the cap */
  549. CEPH_CAP_OP_IMPORT, /* mds has imported the cap */
  550. CEPH_CAP_OP_UPDATE, /* client->mds update */
  551. CEPH_CAP_OP_DROP, /* client->mds drop cap bits */
  552. CEPH_CAP_OP_FLUSH, /* client->mds cap writeback */
  553. CEPH_CAP_OP_FLUSH_ACK, /* mds->client flushed */
  554. CEPH_CAP_OP_FLUSHSNAP, /* client->mds flush snapped metadata */
  555. CEPH_CAP_OP_FLUSHSNAP_ACK, /* mds->client flushed snapped metadata */
  556. CEPH_CAP_OP_RELEASE, /* client->mds release (clean) cap */
  557. CEPH_CAP_OP_RENEW, /* client->mds renewal request */
  558. };
  559. extern const char *ceph_cap_op_name(int op);
  560. /*
  561. * caps message, used for capability callbacks, acks, requests, etc.
  562. */
  563. struct ceph_mds_caps {
  564. __le32 op; /* CEPH_CAP_OP_* */
  565. __le64 ino, realm;
  566. __le64 cap_id;
  567. __le32 seq, issue_seq;
  568. __le32 caps, wanted, dirty; /* latest issued/wanted/dirty */
  569. __le32 migrate_seq;
  570. __le64 snap_follows;
  571. __le32 snap_trace_len;
  572. /* authlock */
  573. __le32 uid, gid, mode;
  574. /* linklock */
  575. __le32 nlink;
  576. /* xattrlock */
  577. __le32 xattr_len;
  578. __le64 xattr_version;
  579. /* filelock */
  580. __le64 size, max_size, truncate_size;
  581. __le32 truncate_seq;
  582. struct ceph_timespec mtime, atime, ctime;
  583. struct ceph_file_layout layout;
  584. __le32 time_warp_seq;
  585. } __attribute__ ((packed));
  586. struct ceph_mds_cap_peer {
  587. __le64 cap_id;
  588. __le32 seq;
  589. __le32 mseq;
  590. __le32 mds;
  591. __u8 flags;
  592. } __attribute__ ((packed));
  593. /* cap release msg head */
  594. struct ceph_mds_cap_release {
  595. __le32 num; /* number of cap_items that follow */
  596. } __attribute__ ((packed));
  597. struct ceph_mds_cap_item {
  598. __le64 ino;
  599. __le64 cap_id;
  600. __le32 migrate_seq, seq;
  601. } __attribute__ ((packed));
  602. #define CEPH_MDS_LEASE_REVOKE 1 /* mds -> client */
  603. #define CEPH_MDS_LEASE_RELEASE 2 /* client -> mds */
  604. #define CEPH_MDS_LEASE_RENEW 3 /* client <-> mds */
  605. #define CEPH_MDS_LEASE_REVOKE_ACK 4 /* client -> mds */
  606. extern const char *ceph_lease_op_name(int o);
  607. /* lease msg header */
  608. struct ceph_mds_lease {
  609. __u8 action; /* CEPH_MDS_LEASE_* */
  610. __le16 mask; /* which lease */
  611. __le64 ino;
  612. __le64 first, last; /* snap range */
  613. __le32 seq;
  614. __le32 duration_ms; /* duration of renewal */
  615. } __attribute__ ((packed));
  616. /* followed by a __le32+string for dname */
  617. /* client reconnect */
  618. struct ceph_mds_cap_reconnect {
  619. __le64 cap_id;
  620. __le32 wanted;
  621. __le32 issued;
  622. __le64 snaprealm;
  623. __le64 pathbase; /* base ino for our path to this ino */
  624. __le32 flock_len; /* size of flock state blob, if any */
  625. } __attribute__ ((packed));
  626. /* followed by flock blob */
  627. struct ceph_mds_cap_reconnect_v1 {
  628. __le64 cap_id;
  629. __le32 wanted;
  630. __le32 issued;
  631. __le64 size;
  632. struct ceph_timespec mtime, atime;
  633. __le64 snaprealm;
  634. __le64 pathbase; /* base ino for our path to this ino */
  635. } __attribute__ ((packed));
  636. struct ceph_mds_snaprealm_reconnect {
  637. __le64 ino; /* snap realm base */
  638. __le64 seq; /* snap seq for this snap realm */
  639. __le64 parent; /* parent realm */
  640. } __attribute__ ((packed));
  641. /*
  642. * snaps
  643. */
  644. enum {
  645. CEPH_SNAP_OP_UPDATE, /* CREATE or DESTROY */
  646. CEPH_SNAP_OP_CREATE,
  647. CEPH_SNAP_OP_DESTROY,
  648. CEPH_SNAP_OP_SPLIT,
  649. };
  650. extern const char *ceph_snap_op_name(int o);
  651. /* snap msg header */
  652. struct ceph_mds_snap_head {
  653. __le32 op; /* CEPH_SNAP_OP_* */
  654. __le64 split; /* ino to split off, if any */
  655. __le32 num_split_inos; /* # inos belonging to new child realm */
  656. __le32 num_split_realms; /* # child realms udner new child realm */
  657. __le32 trace_len; /* size of snap trace blob */
  658. } __attribute__ ((packed));
  659. /* followed by split ino list, then split realms, then the trace blob */
  660. /*
  661. * encode info about a snaprealm, as viewed by a client
  662. */
  663. struct ceph_mds_snap_realm {
  664. __le64 ino; /* ino */
  665. __le64 created; /* snap: when created */
  666. __le64 parent; /* ino: parent realm */
  667. __le64 parent_since; /* snap: same parent since */
  668. __le64 seq; /* snap: version */
  669. __le32 num_snaps;
  670. __le32 num_prior_parent_snaps;
  671. } __attribute__ ((packed));
  672. /* followed by my snap list, then prior parent snap list */
  673. #endif