ceph_fs.h 23 KB

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