blob: e5a5fb9ca3f5872f3ae3e6f197ecba03cfb08211 [file] [log] [blame]
Sage Weil0dee3c22009-10-06 11:31:06 -07001/*
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
Sage Weil5cd068c2010-07-07 08:38:17 -070012#ifndef CEPH_FS_H
13#define CEPH_FS_H
Sage Weil0dee3c22009-10-06 11:31:06 -070014
David Howellsa1ce3922012-10-02 18:01:25 +010015#include <linux/ceph/msgr.h>
16#include <linux/ceph/rados.h>
Sage Weil0dee3c22009-10-06 11:31:06 -070017
18/*
Sage Weil0dee3c22009-10-06 11:31:06 -070019 * subprotocol versions. when specific messages types or high-level
20 * protocols change, bump the affected components. we keep rev
21 * internal cluster protocols separately from the public,
22 * client-facing protocol.
23 */
Yehuda Sadeh0c948992010-02-01 16:10:45 -080024#define CEPH_OSDC_PROTOCOL 24 /* server/client */
Sage Weil3ea25f92010-01-25 11:18:17 -080025#define CEPH_MDSC_PROTOCOL 32 /* server/client */
Sage Weil13e38c82009-10-09 16:36:34 -070026#define CEPH_MONC_PROTOCOL 15 /* server/client */
Sage Weil0dee3c22009-10-06 11:31:06 -070027
28
Alex Elderdd6f5e12013-02-15 11:42:30 -060029#define CEPH_INO_ROOT 1
30#define CEPH_INO_CEPH 2 /* hidden .ceph dir */
31#define CEPH_INO_DOTDOT 3 /* used by ceph fuse for parent (..) */
Sage Weil0dee3c22009-10-06 11:31:06 -070032
33/* arbitrary limit on max # of monitors (cluster of 3 is typical) */
34#define CEPH_MAX_MON 31
35
Sage Weil0dee3c22009-10-06 11:31:06 -070036/*
Yan, Zheng76271512016-02-03 21:24:49 +080037 * legacy ceph_file_layoute
Sage Weil0dee3c22009-10-06 11:31:06 -070038 */
Yan, Zheng76271512016-02-03 21:24:49 +080039struct ceph_file_layout_legacy {
Sage Weil0dee3c22009-10-06 11:31:06 -070040 /* file -> object mapping */
41 __le32 fl_stripe_unit; /* stripe unit, in bytes. must be multiple
42 of page size. */
43 __le32 fl_stripe_count; /* over this many objects */
44 __le32 fl_object_size; /* until objects are this big, then move to
45 new objects */
Sage Weil6c0f3af2010-11-16 11:14:34 -080046 __le32 fl_cas_hash; /* UNUSED. 0 = none; 1 = sha256 */
Sage Weil0dee3c22009-10-06 11:31:06 -070047
48 /* pg -> disk layout */
Sage Weil6c0f3af2010-11-16 11:14:34 -080049 __le32 fl_object_stripe_unit; /* UNUSED. for per-object parity, if any */
Sage Weil0dee3c22009-10-06 11:31:06 -070050
51 /* object -> pg layout */
Alex Elderdd6f5e12013-02-15 11:42:30 -060052 __le32 fl_unused; /* unused; used to be preferred primary for pg (-1 for none) */
Sage Weil0dee3c22009-10-06 11:31:06 -070053 __le32 fl_pg_pool; /* namespace, crush ruleset, rep level */
54} __attribute__ ((packed));
55
Yan, Zheng76271512016-02-03 21:24:49 +080056/*
57 * ceph_file_layout - describe data layout for a file/inode
58 */
59struct ceph_file_layout {
60 /* file -> object mapping */
61 u32 stripe_unit; /* stripe unit, in bytes */
62 u32 stripe_count; /* over this many objects */
63 u32 object_size; /* until objects are this big */
64 s64 pool_id; /* rados pool id */
65};
Ilya Dryomove8221462014-01-27 17:40:18 +020066
Yan, Zheng76271512016-02-03 21:24:49 +080067extern int ceph_file_layout_is_valid(const struct ceph_file_layout *layout);
68extern void ceph_file_layout_from_legacy(struct ceph_file_layout *fl,
69 struct ceph_file_layout_legacy *legacy);
70extern void ceph_file_layout_to_legacy(struct ceph_file_layout *fl,
71 struct ceph_file_layout_legacy *legacy);
Ilya Dryomove8221462014-01-27 17:40:18 +020072
Sage Weil752727a2009-10-09 16:38:45 -070073#define CEPH_MIN_STRIPE_UNIT 65536
Sage Weil0dee3c22009-10-06 11:31:06 -070074
Sage Weil6c0f3af2010-11-16 11:14:34 -080075struct ceph_dir_layout {
76 __u8 dl_dir_hash; /* see ceph_hash.h for ids */
77 __u8 dl_unused1;
78 __u16 dl_unused2;
79 __u32 dl_unused3;
80} __attribute__ ((packed));
Sage Weil0dee3c22009-10-06 11:31:06 -070081
Sage Weil4e7a5dc2009-11-18 16:19:57 -080082/* crypto algorithms */
83#define CEPH_CRYPTO_NONE 0x0
84#define CEPH_CRYPTO_AES 0x1
85
Sage Weilcbbfe492010-08-02 15:48:23 -070086#define CEPH_AES_IV "cephsageyudagreg"
87
Sage Weil4e7a5dc2009-11-18 16:19:57 -080088/* security/authentication protocols */
89#define CEPH_AUTH_UNKNOWN 0x0
90#define CEPH_AUTH_NONE 0x1
91#define CEPH_AUTH_CEPHX 0x2
92
Sage Weilca9d93a2010-05-12 14:48:20 -070093#define CEPH_AUTH_UID_DEFAULT ((__u64) -1)
94
Sage Weil4e7a5dc2009-11-18 16:19:57 -080095
Sage Weil0dee3c22009-10-06 11:31:06 -070096/*********************************************
97 * message layer
98 */
99
100/*
101 * message types
102 */
103
104/* misc */
105#define CEPH_MSG_SHUTDOWN 1
106#define CEPH_MSG_PING 2
107
108/* client <-> monitor */
109#define CEPH_MSG_MON_MAP 4
110#define CEPH_MSG_MON_GET_MAP 5
Sage Weil0dee3c22009-10-06 11:31:06 -0700111#define CEPH_MSG_STATFS 13
112#define CEPH_MSG_STATFS_REPLY 14
113#define CEPH_MSG_MON_SUBSCRIBE 15
114#define CEPH_MSG_MON_SUBSCRIBE_ACK 16
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800115#define CEPH_MSG_AUTH 17
116#define CEPH_MSG_AUTH_REPLY 18
Alex Elderdd6f5e12013-02-15 11:42:30 -0600117#define CEPH_MSG_MON_GET_VERSION 19
118#define CEPH_MSG_MON_GET_VERSION_REPLY 20
Sage Weil0dee3c22009-10-06 11:31:06 -0700119
120/* client <-> mds */
Sage Weil0dee3c22009-10-06 11:31:06 -0700121#define CEPH_MSG_MDS_MAP 21
122
123#define CEPH_MSG_CLIENT_SESSION 22
124#define CEPH_MSG_CLIENT_RECONNECT 23
125
126#define CEPH_MSG_CLIENT_REQUEST 24
127#define CEPH_MSG_CLIENT_REQUEST_FORWARD 25
128#define CEPH_MSG_CLIENT_REPLY 26
129#define CEPH_MSG_CLIENT_CAPS 0x310
130#define CEPH_MSG_CLIENT_LEASE 0x311
131#define CEPH_MSG_CLIENT_SNAP 0x312
132#define CEPH_MSG_CLIENT_CAPRELEASE 0x313
133
Sage Weilca9d93a2010-05-12 14:48:20 -0700134/* pool ops */
135#define CEPH_MSG_POOLOP_REPLY 48
136#define CEPH_MSG_POOLOP 49
137
138
Sage Weil0dee3c22009-10-06 11:31:06 -0700139/* osd */
Yehuda Sadeh483fac72011-01-20 16:36:06 -0800140#define CEPH_MSG_OSD_MAP 41
141#define CEPH_MSG_OSD_OP 42
142#define CEPH_MSG_OSD_OPREPLY 43
143#define CEPH_MSG_WATCH_NOTIFY 44
144
145
146/* watch-notify operations */
147enum {
Ilya Dryomov922dab62016-05-26 01:15:02 +0200148 CEPH_WATCH_EVENT_NOTIFY = 1, /* notifying watcher */
149 CEPH_WATCH_EVENT_NOTIFY_COMPLETE = 2, /* notifier notified when done */
150 CEPH_WATCH_EVENT_DISCONNECT = 3, /* we were disconnected */
Yehuda Sadeh483fac72011-01-20 16:36:06 -0800151};
152
Sage Weil0dee3c22009-10-06 11:31:06 -0700153
Sage Weil13e38c82009-10-09 16:36:34 -0700154struct ceph_mon_request_header {
155 __le64 have_version;
156 __le16 session_mon;
157 __le64 session_mon_tid;
158} __attribute__ ((packed));
Sage Weil0dee3c22009-10-06 11:31:06 -0700159
160struct ceph_mon_statfs {
Sage Weil13e38c82009-10-09 16:36:34 -0700161 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700162 struct ceph_fsid fsid;
Sage Weil0dee3c22009-10-06 11:31:06 -0700163} __attribute__ ((packed));
164
165struct ceph_statfs {
166 __le64 kb, kb_used, kb_avail;
167 __le64 num_objects;
168} __attribute__ ((packed));
169
170struct ceph_mon_statfs_reply {
171 struct ceph_fsid fsid;
Sage Weil0dee3c22009-10-06 11:31:06 -0700172 __le64 version;
173 struct ceph_statfs st;
174} __attribute__ ((packed));
175
176struct ceph_osd_getmap {
Sage Weil13e38c82009-10-09 16:36:34 -0700177 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700178 struct ceph_fsid fsid;
179 __le32 start;
180} __attribute__ ((packed));
181
182struct ceph_mds_getmap {
Sage Weil13e38c82009-10-09 16:36:34 -0700183 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700184 struct ceph_fsid fsid;
185} __attribute__ ((packed));
186
187struct ceph_client_mount {
Sage Weil13e38c82009-10-09 16:36:34 -0700188 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700189} __attribute__ ((packed));
190
Yehuda Sadeh483fac72011-01-20 16:36:06 -0800191#define CEPH_SUBSCRIBE_ONETIME 1 /* i want only 1 update after have */
192
Sage Weil0dee3c22009-10-06 11:31:06 -0700193struct ceph_mon_subscribe_item {
Ilya Dryomov82dcaba2016-01-19 16:19:06 +0100194 __le64 start;
195 __u8 flags;
Sage Weil0dee3c22009-10-06 11:31:06 -0700196} __attribute__ ((packed));
197
Sage Weil07bd10f2009-10-14 17:26:40 -0700198struct ceph_mon_subscribe_ack {
199 __le32 duration; /* seconds */
200 struct ceph_fsid fsid;
201} __attribute__ ((packed));
202
Ilya Dryomov737cc81e2016-05-26 00:05:01 +0200203#define CEPH_FS_CLUSTER_ID_NONE -1
204
Sage Weil0dee3c22009-10-06 11:31:06 -0700205/*
Alex Elderdd6f5e12013-02-15 11:42:30 -0600206 * mdsmap flags
207 */
208#define CEPH_MDSMAP_DOWN (1<<0) /* cluster deliberately down */
209
210/*
Sage Weil0dee3c22009-10-06 11:31:06 -0700211 * mds states
212 * > 0 -> in
213 * <= 0 -> out
214 */
215#define CEPH_MDS_STATE_DNE 0 /* down, does not exist. */
216#define CEPH_MDS_STATE_STOPPED -1 /* down, once existed, but no subtrees.
217 empty log. */
218#define CEPH_MDS_STATE_BOOT -4 /* up, boot announcement. */
219#define CEPH_MDS_STATE_STANDBY -5 /* up, idle. waiting for assignment. */
220#define CEPH_MDS_STATE_CREATING -6 /* up, creating MDS instance. */
221#define CEPH_MDS_STATE_STARTING -7 /* up, starting previously stopped mds */
222#define CEPH_MDS_STATE_STANDBY_REPLAY -8 /* up, tailing active node's journal */
Alex Elderdd6f5e12013-02-15 11:42:30 -0600223#define CEPH_MDS_STATE_REPLAYONCE -9 /* up, replaying an active node's journal */
Sage Weil0dee3c22009-10-06 11:31:06 -0700224
225#define CEPH_MDS_STATE_REPLAY 8 /* up, replaying journal. */
226#define CEPH_MDS_STATE_RESOLVE 9 /* up, disambiguating distributed
227 operations (import, rename, etc.) */
228#define CEPH_MDS_STATE_RECONNECT 10 /* up, reconnect to clients */
229#define CEPH_MDS_STATE_REJOIN 11 /* up, rejoining distributed cache */
230#define CEPH_MDS_STATE_CLIENTREPLAY 12 /* up, replaying client operations */
231#define CEPH_MDS_STATE_ACTIVE 13 /* up, active */
232#define CEPH_MDS_STATE_STOPPING 14 /* up, but exporting metadata */
233
234extern const char *ceph_mds_state_name(int s);
235
236
237/*
238 * metadata lock types.
239 * - these are bitmasks.. we can compose them
240 * - they also define the lock ordering by the MDS
241 * - a few of these are internal to the mds
242 */
Sage Weildd1c9052010-05-25 16:45:25 -0700243#define CEPH_LOCK_DVERSION 1
244#define CEPH_LOCK_DN 2
245#define CEPH_LOCK_ISNAP 16
246#define CEPH_LOCK_IVERSION 32 /* mds internal */
247#define CEPH_LOCK_IFILE 64
248#define CEPH_LOCK_IAUTH 128
249#define CEPH_LOCK_ILINK 256
250#define CEPH_LOCK_IDFT 512 /* dir frag tree */
251#define CEPH_LOCK_INEST 1024 /* mds internal */
252#define CEPH_LOCK_IXATTR 2048
Sage Weilf0b18d92010-07-07 08:39:03 -0700253#define CEPH_LOCK_IFLOCK 4096 /* advisory file locks */
Sage Weildd1c9052010-05-25 16:45:25 -0700254#define CEPH_LOCK_INO 8192 /* immutable inode bits; not a lock */
Alex Elderdd6f5e12013-02-15 11:42:30 -0600255#define CEPH_LOCK_IPOLICY 16384 /* policy lock on dirs. MDS internal */
Sage Weil0dee3c22009-10-06 11:31:06 -0700256
257/* client_session ops */
258enum {
259 CEPH_SESSION_REQUEST_OPEN,
260 CEPH_SESSION_OPEN,
261 CEPH_SESSION_REQUEST_CLOSE,
262 CEPH_SESSION_CLOSE,
263 CEPH_SESSION_REQUEST_RENEWCAPS,
264 CEPH_SESSION_RENEWCAPS,
265 CEPH_SESSION_STALE,
266 CEPH_SESSION_RECALL_STATE,
Yan, Zheng186e4f72013-11-22 14:48:37 +0800267 CEPH_SESSION_FLUSHMSG,
268 CEPH_SESSION_FLUSHMSG_ACK,
Yan, Zheng03f4fcb2015-01-05 11:04:04 +0800269 CEPH_SESSION_FORCE_RO,
Sage Weil0dee3c22009-10-06 11:31:06 -0700270};
271
272extern const char *ceph_session_op_name(int op);
273
274struct ceph_mds_session_head {
275 __le32 op;
276 __le64 seq;
277 struct ceph_timespec stamp;
278 __le32 max_caps, max_leases;
279} __attribute__ ((packed));
280
281/* client_request */
282/*
283 * metadata ops.
284 * & 0x001000 -> write op
285 * & 0x010000 -> follow symlink (e.g. stat(), not lstat()).
286 & & 0x100000 -> use weird ino/path trace
287 */
288#define CEPH_MDS_OP_WRITE 0x001000
289enum {
290 CEPH_MDS_OP_LOOKUP = 0x00100,
291 CEPH_MDS_OP_GETATTR = 0x00101,
292 CEPH_MDS_OP_LOOKUPHASH = 0x00102,
293 CEPH_MDS_OP_LOOKUPPARENT = 0x00103,
Sage Weil3c454cf2011-04-06 09:31:40 -0700294 CEPH_MDS_OP_LOOKUPINO = 0x00104,
Yan, Zheng19913b42014-03-06 16:40:32 +0800295 CEPH_MDS_OP_LOOKUPNAME = 0x00105,
Sage Weil0dee3c22009-10-06 11:31:06 -0700296
297 CEPH_MDS_OP_SETXATTR = 0x01105,
298 CEPH_MDS_OP_RMXATTR = 0x01106,
299 CEPH_MDS_OP_SETLAYOUT = 0x01107,
300 CEPH_MDS_OP_SETATTR = 0x01108,
Greg Farnumfbaad972010-08-02 15:30:08 -0700301 CEPH_MDS_OP_SETFILELOCK= 0x01109,
302 CEPH_MDS_OP_GETFILELOCK= 0x00110,
Greg Farnum571dba52010-09-24 14:56:40 -0700303 CEPH_MDS_OP_SETDIRLAYOUT=0x0110a,
Sage Weil0dee3c22009-10-06 11:31:06 -0700304
305 CEPH_MDS_OP_MKNOD = 0x01201,
306 CEPH_MDS_OP_LINK = 0x01202,
307 CEPH_MDS_OP_UNLINK = 0x01203,
308 CEPH_MDS_OP_RENAME = 0x01204,
309 CEPH_MDS_OP_MKDIR = 0x01220,
310 CEPH_MDS_OP_RMDIR = 0x01221,
311 CEPH_MDS_OP_SYMLINK = 0x01222,
312
Sage Weil3ea25f92010-01-25 11:18:17 -0800313 CEPH_MDS_OP_CREATE = 0x01301,
Sage Weil0dee3c22009-10-06 11:31:06 -0700314 CEPH_MDS_OP_OPEN = 0x00302,
315 CEPH_MDS_OP_READDIR = 0x00305,
316
317 CEPH_MDS_OP_LOOKUPSNAP = 0x00400,
318 CEPH_MDS_OP_MKSNAP = 0x01400,
319 CEPH_MDS_OP_RMSNAP = 0x01401,
320 CEPH_MDS_OP_LSSNAP = 0x00402,
Yan, Zheng0ea611a2015-04-07 15:36:32 +0800321 CEPH_MDS_OP_RENAMESNAP = 0x01403,
Sage Weil0dee3c22009-10-06 11:31:06 -0700322};
323
324extern const char *ceph_mds_op_name(int op);
325
326
327#define CEPH_SETATTR_MODE 1
328#define CEPH_SETATTR_UID 2
329#define CEPH_SETATTR_GID 4
330#define CEPH_SETATTR_MTIME 8
331#define CEPH_SETATTR_ATIME 16
332#define CEPH_SETATTR_SIZE 32
333#define CEPH_SETATTR_CTIME 64
334
Alex Elderdd6f5e12013-02-15 11:42:30 -0600335/*
336 * Ceph setxattr request flags.
337 */
Yan, Zhengbcdfeb22014-02-11 13:04:19 +0800338#define CEPH_XATTR_CREATE (1 << 0)
339#define CEPH_XATTR_REPLACE (1 << 1)
340#define CEPH_XATTR_REMOVE (1 << 31)
Alex Elderdd6f5e12013-02-15 11:42:30 -0600341
Yan, Zheng956d39d2016-04-27 17:48:30 +0800342/*
343 * readdir request flags;
344 */
345#define CEPH_READDIR_REPLY_BITFLAGS (1<<0)
346
347/*
348 * readdir reply flags.
349 */
350#define CEPH_READDIR_FRAG_END (1<<0)
351#define CEPH_READDIR_FRAG_COMPLETE (1<<8)
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800352#define CEPH_READDIR_HASH_ORDER (1<<9)
Yan, Zheng956d39d2016-04-27 17:48:30 +0800353
Sage Weil0dee3c22009-10-06 11:31:06 -0700354union ceph_mds_request_args {
355 struct {
356 __le32 mask; /* CEPH_CAP_* */
357 } __attribute__ ((packed)) getattr;
358 struct {
359 __le32 mode;
360 __le32 uid;
361 __le32 gid;
362 struct ceph_timespec mtime;
363 struct ceph_timespec atime;
364 __le64 size, old_size; /* old_size needed by truncate */
365 __le32 mask; /* CEPH_SETATTR_* */
366 } __attribute__ ((packed)) setattr;
367 struct {
368 __le32 frag; /* which dir fragment */
369 __le32 max_entries; /* how many dentries to grab */
Sage Weil23804d92010-05-14 13:06:30 -0700370 __le32 max_bytes;
Yan, Zheng956d39d2016-04-27 17:48:30 +0800371 __le16 flags;
Sage Weil0dee3c22009-10-06 11:31:06 -0700372 } __attribute__ ((packed)) readdir;
373 struct {
374 __le32 mode;
375 __le32 rdev;
376 } __attribute__ ((packed)) mknod;
377 struct {
378 __le32 mode;
379 } __attribute__ ((packed)) mkdir;
380 struct {
381 __le32 flags;
382 __le32 mode;
383 __le32 stripe_unit; /* layout for newly created file */
384 __le32 stripe_count; /* ... */
385 __le32 object_size;
386 __le32 file_replication;
Yan, Zheng315f2402016-03-07 10:34:50 +0800387 __le32 mask; /* CEPH_CAP_* */
388 __le32 old_size;
Sage Weil0dee3c22009-10-06 11:31:06 -0700389 } __attribute__ ((packed)) open;
390 struct {
391 __le32 flags;
392 } __attribute__ ((packed)) setxattr;
393 struct {
Yan, Zheng76271512016-02-03 21:24:49 +0800394 struct ceph_file_layout_legacy layout;
Sage Weil0dee3c22009-10-06 11:31:06 -0700395 } __attribute__ ((packed)) setlayout;
Greg Farnumfbaad972010-08-02 15:30:08 -0700396 struct {
397 __u8 rule; /* currently fcntl or flock */
398 __u8 type; /* shared, exclusive, remove*/
Yan, Zhengeb13e832014-03-09 23:16:40 +0800399 __le64 owner; /* owner of the lock */
Greg Farnumfbaad972010-08-02 15:30:08 -0700400 __le64 pid; /* process id requesting the lock */
Greg Farnumfbaad972010-08-02 15:30:08 -0700401 __le64 start; /* initial location to lock */
402 __le64 length; /* num bytes to lock from start */
403 __u8 wait; /* will caller wait for lock to become available? */
404 } __attribute__ ((packed)) filelock_change;
Sage Weil0dee3c22009-10-06 11:31:06 -0700405} __attribute__ ((packed));
406
407#define CEPH_MDS_FLAG_REPLAY 1 /* this is a replayed op */
408#define CEPH_MDS_FLAG_WANT_DENTRY 2 /* want dentry in reply */
409
410struct ceph_mds_request_head {
Sage Weil6df058c2009-12-22 11:24:33 -0800411 __le64 oldest_client_tid;
Sage Weil0dee3c22009-10-06 11:31:06 -0700412 __le32 mdsmap_epoch; /* on client */
413 __le32 flags; /* CEPH_MDS_FLAG_* */
414 __u8 num_retry, num_fwd; /* count retry, fwd attempts */
415 __le16 num_releases; /* # include cap/lease release records */
416 __le32 op; /* mds op code */
417 __le32 caller_uid, caller_gid;
418 __le64 ino; /* use this ino for openc, mkdir, mknod,
419 etc. (if replaying) */
420 union ceph_mds_request_args args;
421} __attribute__ ((packed));
422
423/* cap/lease release record */
424struct ceph_mds_request_release {
425 __le64 ino, cap_id; /* ino and unique cap id */
426 __le32 caps, wanted; /* new issued, wanted */
427 __le32 seq, issue_seq, mseq;
428 __le32 dname_seq; /* if releasing a dentry lease, a */
429 __le32 dname_len; /* string follows. */
430} __attribute__ ((packed));
431
432/* client reply */
433struct ceph_mds_reply_head {
Sage Weil0dee3c22009-10-06 11:31:06 -0700434 __le32 op;
435 __le32 result;
436 __le32 mdsmap_epoch;
437 __u8 safe; /* true if committed to disk */
438 __u8 is_dentry, is_target; /* true if dentry, target inode records
439 are included with reply */
440} __attribute__ ((packed));
441
442/* one for each node split */
443struct ceph_frag_tree_split {
444 __le32 frag; /* this frag splits... */
445 __le32 by; /* ...by this many bits */
446} __attribute__ ((packed));
447
448struct ceph_frag_tree_head {
449 __le32 nsplits; /* num ceph_frag_tree_split records */
450 struct ceph_frag_tree_split splits[];
451} __attribute__ ((packed));
452
453/* capability issue, for bundling with mds reply */
454struct ceph_mds_reply_cap {
455 __le32 caps, wanted; /* caps issued, wanted */
456 __le64 cap_id;
457 __le32 seq, mseq;
458 __le64 realm; /* snap realm */
459 __u8 flags; /* CEPH_CAP_FLAG_* */
460} __attribute__ ((packed));
461
Yan, Zheng4ee6a912013-11-24 14:43:46 +0800462#define CEPH_CAP_FLAG_AUTH (1 << 0) /* cap is issued by auth mds */
463#define CEPH_CAP_FLAG_RELEASE (1 << 1) /* release the cap */
Sage Weil0dee3c22009-10-06 11:31:06 -0700464
465/* inode record, for bundling with mds reply */
466struct ceph_mds_reply_inode {
467 __le64 ino;
468 __le64 snapid;
469 __le32 rdev;
470 __le64 version; /* inode version */
471 __le64 xattr_version; /* version for xattr blob */
472 struct ceph_mds_reply_cap cap; /* caps issued for this inode */
Yan, Zheng76271512016-02-03 21:24:49 +0800473 struct ceph_file_layout_legacy layout;
Sage Weil0dee3c22009-10-06 11:31:06 -0700474 struct ceph_timespec ctime, mtime, atime;
475 __le32 time_warp_seq;
476 __le64 size, max_size, truncate_size;
477 __le32 truncate_seq;
478 __le32 mode, uid, gid;
479 __le32 nlink;
480 __le64 files, subdirs, rbytes, rfiles, rsubdirs; /* dir stats */
481 struct ceph_timespec rctime;
482 struct ceph_frag_tree_head fragtree; /* (must be at end of struct) */
483} __attribute__ ((packed));
Sage Weil6c0f3af2010-11-16 11:14:34 -0800484/* followed by frag array, symlink string, dir layout, xattr blob */
Sage Weil0dee3c22009-10-06 11:31:06 -0700485
486/* reply_lease follows dname, and reply_inode */
487struct ceph_mds_reply_lease {
488 __le16 mask; /* lease type(s) */
489 __le32 duration_ms; /* lease duration */
490 __le32 seq;
491} __attribute__ ((packed));
492
493struct ceph_mds_reply_dirfrag {
494 __le32 frag; /* fragment */
495 __le32 auth; /* auth mds, if this is a delegation point */
496 __le32 ndist; /* number of mds' this is replicated on */
497 __le32 dist[];
498} __attribute__ ((packed));
499
Yan, Zheng9280be22014-10-14 10:33:35 +0800500#define CEPH_LOCK_FCNTL 1
501#define CEPH_LOCK_FLOCK 2
502#define CEPH_LOCK_FCNTL_INTR 3
503#define CEPH_LOCK_FLOCK_INTR 4
504
Greg Farnumfbaad972010-08-02 15:30:08 -0700505
506#define CEPH_LOCK_SHARED 1
507#define CEPH_LOCK_EXCL 2
508#define CEPH_LOCK_UNLOCK 4
509
510struct ceph_filelock {
511 __le64 start;/* file offset to start lock at */
512 __le64 length; /* num bytes to lock; 0 for all following start */
513 __le64 client; /* which client holds the lock */
Yan, Zhengeb13e832014-03-09 23:16:40 +0800514 __le64 owner; /* owner the lock */
Greg Farnumfbaad972010-08-02 15:30:08 -0700515 __le64 pid; /* process id holding the lock on the client */
Greg Farnumfbaad972010-08-02 15:30:08 -0700516 __u8 type; /* shared lock, exclusive lock, or unlock */
517} __attribute__ ((packed));
518
519
Sage Weil0dee3c22009-10-06 11:31:06 -0700520/* file access modes */
521#define CEPH_FILE_MODE_PIN 0
522#define CEPH_FILE_MODE_RD 1
523#define CEPH_FILE_MODE_WR 2
524#define CEPH_FILE_MODE_RDWR 3 /* RD | WR */
525#define CEPH_FILE_MODE_LAZY 4 /* lazy io */
526#define CEPH_FILE_MODE_NUM 8 /* bc these are bit fields.. mostly */
527
528int ceph_flags_to_mode(int flags);
529
Yan, Zheng31c542a2014-11-14 21:41:55 +0800530#define CEPH_INLINE_NONE ((__u64)-1)
Sage Weil0dee3c22009-10-06 11:31:06 -0700531
532/* capability bits */
533#define CEPH_CAP_PIN 1 /* no specific capabilities beyond the pin */
534
535/* generic cap bits */
536#define CEPH_CAP_GSHARED 1 /* client can reads */
537#define CEPH_CAP_GEXCL 2 /* client can read and update */
538#define CEPH_CAP_GCACHE 4 /* (file) client can cache reads */
539#define CEPH_CAP_GRD 8 /* (file) client can read */
540#define CEPH_CAP_GWR 16 /* (file) client can write */
541#define CEPH_CAP_GBUFFER 32 /* (file) client can buffer writes */
542#define CEPH_CAP_GWREXTEND 64 /* (file) client can extend EOF */
543#define CEPH_CAP_GLAZYIO 128 /* (file) client can perform lazy io */
544
Alex Elderdd6f5e12013-02-15 11:42:30 -0600545#define CEPH_CAP_SIMPLE_BITS 2
546#define CEPH_CAP_FILE_BITS 8
547
Sage Weil0dee3c22009-10-06 11:31:06 -0700548/* per-lock shift */
549#define CEPH_CAP_SAUTH 2
550#define CEPH_CAP_SLINK 4
551#define CEPH_CAP_SXATTR 6
Greg Farnumfbaad972010-08-02 15:30:08 -0700552#define CEPH_CAP_SFILE 8
Alex Elderdd6f5e12013-02-15 11:42:30 -0600553#define CEPH_CAP_SFLOCK 20
Sage Weil0dee3c22009-10-06 11:31:06 -0700554
Alex Elderdd6f5e12013-02-15 11:42:30 -0600555#define CEPH_CAP_BITS 22
Sage Weil0dee3c22009-10-06 11:31:06 -0700556
557/* composed values */
558#define CEPH_CAP_AUTH_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SAUTH)
559#define CEPH_CAP_AUTH_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SAUTH)
560#define CEPH_CAP_LINK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SLINK)
561#define CEPH_CAP_LINK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SLINK)
562#define CEPH_CAP_XATTR_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SXATTR)
563#define CEPH_CAP_XATTR_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SXATTR)
564#define CEPH_CAP_FILE(x) (x << CEPH_CAP_SFILE)
565#define CEPH_CAP_FILE_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFILE)
566#define CEPH_CAP_FILE_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFILE)
567#define CEPH_CAP_FILE_CACHE (CEPH_CAP_GCACHE << CEPH_CAP_SFILE)
568#define CEPH_CAP_FILE_RD (CEPH_CAP_GRD << CEPH_CAP_SFILE)
569#define CEPH_CAP_FILE_WR (CEPH_CAP_GWR << CEPH_CAP_SFILE)
570#define CEPH_CAP_FILE_BUFFER (CEPH_CAP_GBUFFER << CEPH_CAP_SFILE)
571#define CEPH_CAP_FILE_WREXTEND (CEPH_CAP_GWREXTEND << CEPH_CAP_SFILE)
572#define CEPH_CAP_FILE_LAZYIO (CEPH_CAP_GLAZYIO << CEPH_CAP_SFILE)
Greg Farnumfbaad972010-08-02 15:30:08 -0700573#define CEPH_CAP_FLOCK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFLOCK)
574#define CEPH_CAP_FLOCK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFLOCK)
575
Sage Weil0dee3c22009-10-06 11:31:06 -0700576
577/* cap masks (for getattr) */
578#define CEPH_STAT_CAP_INODE CEPH_CAP_PIN
579#define CEPH_STAT_CAP_TYPE CEPH_CAP_PIN /* mode >> 12 */
580#define CEPH_STAT_CAP_SYMLINK CEPH_CAP_PIN
581#define CEPH_STAT_CAP_UID CEPH_CAP_AUTH_SHARED
582#define CEPH_STAT_CAP_GID CEPH_CAP_AUTH_SHARED
583#define CEPH_STAT_CAP_MODE CEPH_CAP_AUTH_SHARED
584#define CEPH_STAT_CAP_NLINK CEPH_CAP_LINK_SHARED
585#define CEPH_STAT_CAP_LAYOUT CEPH_CAP_FILE_SHARED
586#define CEPH_STAT_CAP_MTIME CEPH_CAP_FILE_SHARED
587#define CEPH_STAT_CAP_SIZE CEPH_CAP_FILE_SHARED
588#define CEPH_STAT_CAP_ATIME CEPH_CAP_FILE_SHARED /* fixme */
589#define CEPH_STAT_CAP_XATTR CEPH_CAP_XATTR_SHARED
590#define CEPH_STAT_CAP_INODE_ALL (CEPH_CAP_PIN | \
591 CEPH_CAP_AUTH_SHARED | \
592 CEPH_CAP_LINK_SHARED | \
593 CEPH_CAP_FILE_SHARED | \
594 CEPH_CAP_XATTR_SHARED)
Yan, Zheng01deead2014-11-14 21:56:29 +0800595#define CEPH_STAT_CAP_INLINE_DATA (CEPH_CAP_FILE_SHARED | \
596 CEPH_CAP_FILE_RD)
Sage Weil0dee3c22009-10-06 11:31:06 -0700597
598#define CEPH_CAP_ANY_SHARED (CEPH_CAP_AUTH_SHARED | \
599 CEPH_CAP_LINK_SHARED | \
600 CEPH_CAP_XATTR_SHARED | \
601 CEPH_CAP_FILE_SHARED)
602#define CEPH_CAP_ANY_RD (CEPH_CAP_ANY_SHARED | CEPH_CAP_FILE_RD | \
603 CEPH_CAP_FILE_CACHE)
604
605#define CEPH_CAP_ANY_EXCL (CEPH_CAP_AUTH_EXCL | \
606 CEPH_CAP_LINK_EXCL | \
607 CEPH_CAP_XATTR_EXCL | \
608 CEPH_CAP_FILE_EXCL)
Yan, Zhengf98a1282014-04-17 08:55:50 +0800609#define CEPH_CAP_ANY_FILE_RD (CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE | \
610 CEPH_CAP_FILE_SHARED)
Sage Weil0dee3c22009-10-06 11:31:06 -0700611#define CEPH_CAP_ANY_FILE_WR (CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER | \
612 CEPH_CAP_FILE_EXCL)
613#define CEPH_CAP_ANY_WR (CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_FILE_WR)
614#define CEPH_CAP_ANY (CEPH_CAP_ANY_RD | CEPH_CAP_ANY_EXCL | \
Sage Weil84d95092010-05-25 16:46:24 -0700615 CEPH_CAP_ANY_FILE_WR | CEPH_CAP_FILE_LAZYIO | \
616 CEPH_CAP_PIN)
Sage Weil0dee3c22009-10-06 11:31:06 -0700617
618#define CEPH_CAP_LOCKS (CEPH_LOCK_IFILE | CEPH_LOCK_IAUTH | CEPH_LOCK_ILINK | \
619 CEPH_LOCK_IXATTR)
620
621int ceph_caps_for_mode(int mode);
622
623enum {
624 CEPH_CAP_OP_GRANT, /* mds->client grant */
625 CEPH_CAP_OP_REVOKE, /* mds->client revoke */
626 CEPH_CAP_OP_TRUNC, /* mds->client trunc notify */
627 CEPH_CAP_OP_EXPORT, /* mds has exported the cap */
628 CEPH_CAP_OP_IMPORT, /* mds has imported the cap */
629 CEPH_CAP_OP_UPDATE, /* client->mds update */
630 CEPH_CAP_OP_DROP, /* client->mds drop cap bits */
631 CEPH_CAP_OP_FLUSH, /* client->mds cap writeback */
632 CEPH_CAP_OP_FLUSH_ACK, /* mds->client flushed */
633 CEPH_CAP_OP_FLUSHSNAP, /* client->mds flush snapped metadata */
634 CEPH_CAP_OP_FLUSHSNAP_ACK, /* mds->client flushed snapped metadata */
635 CEPH_CAP_OP_RELEASE, /* client->mds release (clean) cap */
636 CEPH_CAP_OP_RENEW, /* client->mds renewal request */
637};
638
639extern const char *ceph_cap_op_name(int op);
640
641/*
642 * caps message, used for capability callbacks, acks, requests, etc.
643 */
644struct ceph_mds_caps {
645 __le32 op; /* CEPH_CAP_OP_* */
646 __le64 ino, realm;
647 __le64 cap_id;
648 __le32 seq, issue_seq;
649 __le32 caps, wanted, dirty; /* latest issued/wanted/dirty */
650 __le32 migrate_seq;
651 __le64 snap_follows;
652 __le32 snap_trace_len;
Sage Weil0dee3c22009-10-06 11:31:06 -0700653
654 /* authlock */
655 __le32 uid, gid, mode;
656
657 /* linklock */
658 __le32 nlink;
659
660 /* xattrlock */
661 __le32 xattr_len;
662 __le64 xattr_version;
663
664 /* filelock */
665 __le64 size, max_size, truncate_size;
666 __le32 truncate_seq;
667 struct ceph_timespec mtime, atime, ctime;
Yan, Zheng76271512016-02-03 21:24:49 +0800668 struct ceph_file_layout_legacy layout;
Sage Weil0dee3c22009-10-06 11:31:06 -0700669 __le32 time_warp_seq;
670} __attribute__ ((packed));
671
Yan, Zheng4ee6a912013-11-24 14:43:46 +0800672struct ceph_mds_cap_peer {
673 __le64 cap_id;
674 __le32 seq;
675 __le32 mseq;
676 __le32 mds;
677 __u8 flags;
678} __attribute__ ((packed));
679
Sage Weil0dee3c22009-10-06 11:31:06 -0700680/* cap release msg head */
681struct ceph_mds_cap_release {
682 __le32 num; /* number of cap_items that follow */
683} __attribute__ ((packed));
684
685struct ceph_mds_cap_item {
686 __le64 ino;
687 __le64 cap_id;
688 __le32 migrate_seq, seq;
689} __attribute__ ((packed));
690
691#define CEPH_MDS_LEASE_REVOKE 1 /* mds -> client */
692#define CEPH_MDS_LEASE_RELEASE 2 /* client -> mds */
693#define CEPH_MDS_LEASE_RENEW 3 /* client <-> mds */
694#define CEPH_MDS_LEASE_REVOKE_ACK 4 /* client -> mds */
695
696extern const char *ceph_lease_op_name(int o);
697
698/* lease msg header */
699struct ceph_mds_lease {
700 __u8 action; /* CEPH_MDS_LEASE_* */
701 __le16 mask; /* which lease */
702 __le64 ino;
703 __le64 first, last; /* snap range */
704 __le32 seq;
705 __le32 duration_ms; /* duration of renewal */
706} __attribute__ ((packed));
707/* followed by a __le32+string for dname */
708
709/* client reconnect */
710struct ceph_mds_cap_reconnect {
711 __le64 cap_id;
712 __le32 wanted;
713 __le32 issued;
Sage Weil20cb34a2010-05-12 15:21:32 -0700714 __le64 snaprealm;
715 __le64 pathbase; /* base ino for our path to this ino */
716 __le32 flock_len; /* size of flock state blob, if any */
717} __attribute__ ((packed));
718/* followed by flock blob */
719
720struct ceph_mds_cap_reconnect_v1 {
721 __le64 cap_id;
722 __le32 wanted;
723 __le32 issued;
Sage Weil0dee3c22009-10-06 11:31:06 -0700724 __le64 size;
725 struct ceph_timespec mtime, atime;
726 __le64 snaprealm;
727 __le64 pathbase; /* base ino for our path to this ino */
728} __attribute__ ((packed));
Sage Weil0dee3c22009-10-06 11:31:06 -0700729
730struct ceph_mds_snaprealm_reconnect {
731 __le64 ino; /* snap realm base */
732 __le64 seq; /* snap seq for this snap realm */
733 __le64 parent; /* parent realm */
734} __attribute__ ((packed));
735
736/*
737 * snaps
738 */
739enum {
740 CEPH_SNAP_OP_UPDATE, /* CREATE or DESTROY */
741 CEPH_SNAP_OP_CREATE,
742 CEPH_SNAP_OP_DESTROY,
743 CEPH_SNAP_OP_SPLIT,
744};
745
746extern const char *ceph_snap_op_name(int o);
747
748/* snap msg header */
749struct ceph_mds_snap_head {
750 __le32 op; /* CEPH_SNAP_OP_* */
751 __le64 split; /* ino to split off, if any */
752 __le32 num_split_inos; /* # inos belonging to new child realm */
753 __le32 num_split_realms; /* # child realms udner new child realm */
754 __le32 trace_len; /* size of snap trace blob */
755} __attribute__ ((packed));
756/* followed by split ino list, then split realms, then the trace blob */
757
758/*
759 * encode info about a snaprealm, as viewed by a client
760 */
761struct ceph_mds_snap_realm {
762 __le64 ino; /* ino */
763 __le64 created; /* snap: when created */
764 __le64 parent; /* ino: parent realm */
765 __le64 parent_since; /* snap: same parent since */
766 __le64 seq; /* snap: version */
767 __le32 num_snaps;
768 __le32 num_prior_parent_snaps;
769} __attribute__ ((packed));
770/* followed by my snap list, then prior parent snap list */
771
772#endif