blob: 3b911ff889ddb4d59e6b4598c3c61940d24abb1f [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/*
37 * ceph_file_layout - describe data layout for a file/inode
38 */
39struct ceph_file_layout {
40 /* 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
Ilya Dryomove8221462014-01-27 17:40:18 +020056#define ceph_file_layout_su(l) ((__s32)le32_to_cpu((l).fl_stripe_unit))
57#define ceph_file_layout_stripe_count(l) \
58 ((__s32)le32_to_cpu((l).fl_stripe_count))
59#define ceph_file_layout_object_size(l) ((__s32)le32_to_cpu((l).fl_object_size))
60#define ceph_file_layout_cas_hash(l) ((__s32)le32_to_cpu((l).fl_cas_hash))
61#define ceph_file_layout_object_su(l) \
62 ((__s32)le32_to_cpu((l).fl_object_stripe_unit))
63#define ceph_file_layout_pg_pool(l) \
64 ((__s32)le32_to_cpu((l).fl_pg_pool))
65
66static inline unsigned ceph_file_layout_stripe_width(struct ceph_file_layout *l)
67{
68 return le32_to_cpu(l->fl_stripe_unit) *
69 le32_to_cpu(l->fl_stripe_count);
70}
71
72/* "period" == bytes before i start on a new set of objects */
73static inline unsigned ceph_file_layout_period(struct ceph_file_layout *l)
74{
75 return le32_to_cpu(l->fl_object_size) *
76 le32_to_cpu(l->fl_stripe_count);
77}
78
Sage Weil752727a2009-10-09 16:38:45 -070079#define CEPH_MIN_STRIPE_UNIT 65536
Sage Weil0dee3c22009-10-06 11:31:06 -070080
Sage Weil752727a2009-10-09 16:38:45 -070081int ceph_file_layout_is_valid(const struct ceph_file_layout *layout);
Sage Weil0dee3c22009-10-06 11:31:06 -070082
Sage Weil6c0f3af2010-11-16 11:14:34 -080083struct ceph_dir_layout {
84 __u8 dl_dir_hash; /* see ceph_hash.h for ids */
85 __u8 dl_unused1;
86 __u16 dl_unused2;
87 __u32 dl_unused3;
88} __attribute__ ((packed));
Sage Weil0dee3c22009-10-06 11:31:06 -070089
Sage Weil4e7a5dc2009-11-18 16:19:57 -080090/* crypto algorithms */
91#define CEPH_CRYPTO_NONE 0x0
92#define CEPH_CRYPTO_AES 0x1
93
Sage Weilcbbfe492010-08-02 15:48:23 -070094#define CEPH_AES_IV "cephsageyudagreg"
95
Sage Weil4e7a5dc2009-11-18 16:19:57 -080096/* security/authentication protocols */
97#define CEPH_AUTH_UNKNOWN 0x0
98#define CEPH_AUTH_NONE 0x1
99#define CEPH_AUTH_CEPHX 0x2
100
Sage Weilca9d93a2010-05-12 14:48:20 -0700101#define CEPH_AUTH_UID_DEFAULT ((__u64) -1)
102
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800103
Sage Weil0dee3c22009-10-06 11:31:06 -0700104/*********************************************
105 * message layer
106 */
107
108/*
109 * message types
110 */
111
112/* misc */
113#define CEPH_MSG_SHUTDOWN 1
114#define CEPH_MSG_PING 2
115
116/* client <-> monitor */
117#define CEPH_MSG_MON_MAP 4
118#define CEPH_MSG_MON_GET_MAP 5
Sage Weil0dee3c22009-10-06 11:31:06 -0700119#define CEPH_MSG_STATFS 13
120#define CEPH_MSG_STATFS_REPLY 14
121#define CEPH_MSG_MON_SUBSCRIBE 15
122#define CEPH_MSG_MON_SUBSCRIBE_ACK 16
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800123#define CEPH_MSG_AUTH 17
124#define CEPH_MSG_AUTH_REPLY 18
Alex Elderdd6f5e12013-02-15 11:42:30 -0600125#define CEPH_MSG_MON_GET_VERSION 19
126#define CEPH_MSG_MON_GET_VERSION_REPLY 20
Sage Weil0dee3c22009-10-06 11:31:06 -0700127
128/* client <-> mds */
Sage Weil0dee3c22009-10-06 11:31:06 -0700129#define CEPH_MSG_MDS_MAP 21
130
131#define CEPH_MSG_CLIENT_SESSION 22
132#define CEPH_MSG_CLIENT_RECONNECT 23
133
134#define CEPH_MSG_CLIENT_REQUEST 24
135#define CEPH_MSG_CLIENT_REQUEST_FORWARD 25
136#define CEPH_MSG_CLIENT_REPLY 26
137#define CEPH_MSG_CLIENT_CAPS 0x310
138#define CEPH_MSG_CLIENT_LEASE 0x311
139#define CEPH_MSG_CLIENT_SNAP 0x312
140#define CEPH_MSG_CLIENT_CAPRELEASE 0x313
141
Sage Weilca9d93a2010-05-12 14:48:20 -0700142/* pool ops */
143#define CEPH_MSG_POOLOP_REPLY 48
144#define CEPH_MSG_POOLOP 49
145
146
Sage Weil0dee3c22009-10-06 11:31:06 -0700147/* osd */
Yehuda Sadeh483fac72011-01-20 16:36:06 -0800148#define CEPH_MSG_OSD_MAP 41
149#define CEPH_MSG_OSD_OP 42
150#define CEPH_MSG_OSD_OPREPLY 43
151#define CEPH_MSG_WATCH_NOTIFY 44
152
153
154/* watch-notify operations */
155enum {
Ilya Dryomov922dab62016-05-26 01:15:02 +0200156 CEPH_WATCH_EVENT_NOTIFY = 1, /* notifying watcher */
157 CEPH_WATCH_EVENT_NOTIFY_COMPLETE = 2, /* notifier notified when done */
158 CEPH_WATCH_EVENT_DISCONNECT = 3, /* we were disconnected */
Yehuda Sadeh483fac72011-01-20 16:36:06 -0800159};
160
Sage Weil0dee3c22009-10-06 11:31:06 -0700161
Sage Weil13e38c82009-10-09 16:36:34 -0700162struct ceph_mon_request_header {
163 __le64 have_version;
164 __le16 session_mon;
165 __le64 session_mon_tid;
166} __attribute__ ((packed));
Sage Weil0dee3c22009-10-06 11:31:06 -0700167
168struct ceph_mon_statfs {
Sage Weil13e38c82009-10-09 16:36:34 -0700169 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700170 struct ceph_fsid fsid;
Sage Weil0dee3c22009-10-06 11:31:06 -0700171} __attribute__ ((packed));
172
173struct ceph_statfs {
174 __le64 kb, kb_used, kb_avail;
175 __le64 num_objects;
176} __attribute__ ((packed));
177
178struct ceph_mon_statfs_reply {
179 struct ceph_fsid fsid;
Sage Weil0dee3c22009-10-06 11:31:06 -0700180 __le64 version;
181 struct ceph_statfs st;
182} __attribute__ ((packed));
183
184struct ceph_osd_getmap {
Sage Weil13e38c82009-10-09 16:36:34 -0700185 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700186 struct ceph_fsid fsid;
187 __le32 start;
188} __attribute__ ((packed));
189
190struct ceph_mds_getmap {
Sage Weil13e38c82009-10-09 16:36:34 -0700191 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700192 struct ceph_fsid fsid;
193} __attribute__ ((packed));
194
195struct ceph_client_mount {
Sage Weil13e38c82009-10-09 16:36:34 -0700196 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700197} __attribute__ ((packed));
198
Yehuda Sadeh483fac72011-01-20 16:36:06 -0800199#define CEPH_SUBSCRIBE_ONETIME 1 /* i want only 1 update after have */
200
Sage Weil0dee3c22009-10-06 11:31:06 -0700201struct ceph_mon_subscribe_item {
Ilya Dryomov82dcaba2016-01-19 16:19:06 +0100202 __le64 start;
203 __u8 flags;
Sage Weil0dee3c22009-10-06 11:31:06 -0700204} __attribute__ ((packed));
205
Sage Weil07bd10f2009-10-14 17:26:40 -0700206struct ceph_mon_subscribe_ack {
207 __le32 duration; /* seconds */
208 struct ceph_fsid fsid;
209} __attribute__ ((packed));
210
Sage Weil0dee3c22009-10-06 11:31:06 -0700211/*
Alex Elderdd6f5e12013-02-15 11:42:30 -0600212 * mdsmap flags
213 */
214#define CEPH_MDSMAP_DOWN (1<<0) /* cluster deliberately down */
215
216/*
Sage Weil0dee3c22009-10-06 11:31:06 -0700217 * mds states
218 * > 0 -> in
219 * <= 0 -> out
220 */
221#define CEPH_MDS_STATE_DNE 0 /* down, does not exist. */
222#define CEPH_MDS_STATE_STOPPED -1 /* down, once existed, but no subtrees.
223 empty log. */
224#define CEPH_MDS_STATE_BOOT -4 /* up, boot announcement. */
225#define CEPH_MDS_STATE_STANDBY -5 /* up, idle. waiting for assignment. */
226#define CEPH_MDS_STATE_CREATING -6 /* up, creating MDS instance. */
227#define CEPH_MDS_STATE_STARTING -7 /* up, starting previously stopped mds */
228#define CEPH_MDS_STATE_STANDBY_REPLAY -8 /* up, tailing active node's journal */
Alex Elderdd6f5e12013-02-15 11:42:30 -0600229#define CEPH_MDS_STATE_REPLAYONCE -9 /* up, replaying an active node's journal */
Sage Weil0dee3c22009-10-06 11:31:06 -0700230
231#define CEPH_MDS_STATE_REPLAY 8 /* up, replaying journal. */
232#define CEPH_MDS_STATE_RESOLVE 9 /* up, disambiguating distributed
233 operations (import, rename, etc.) */
234#define CEPH_MDS_STATE_RECONNECT 10 /* up, reconnect to clients */
235#define CEPH_MDS_STATE_REJOIN 11 /* up, rejoining distributed cache */
236#define CEPH_MDS_STATE_CLIENTREPLAY 12 /* up, replaying client operations */
237#define CEPH_MDS_STATE_ACTIVE 13 /* up, active */
238#define CEPH_MDS_STATE_STOPPING 14 /* up, but exporting metadata */
239
240extern const char *ceph_mds_state_name(int s);
241
242
243/*
244 * metadata lock types.
245 * - these are bitmasks.. we can compose them
246 * - they also define the lock ordering by the MDS
247 * - a few of these are internal to the mds
248 */
Sage Weildd1c9052010-05-25 16:45:25 -0700249#define CEPH_LOCK_DVERSION 1
250#define CEPH_LOCK_DN 2
251#define CEPH_LOCK_ISNAP 16
252#define CEPH_LOCK_IVERSION 32 /* mds internal */
253#define CEPH_LOCK_IFILE 64
254#define CEPH_LOCK_IAUTH 128
255#define CEPH_LOCK_ILINK 256
256#define CEPH_LOCK_IDFT 512 /* dir frag tree */
257#define CEPH_LOCK_INEST 1024 /* mds internal */
258#define CEPH_LOCK_IXATTR 2048
Sage Weilf0b18d92010-07-07 08:39:03 -0700259#define CEPH_LOCK_IFLOCK 4096 /* advisory file locks */
Sage Weildd1c9052010-05-25 16:45:25 -0700260#define CEPH_LOCK_INO 8192 /* immutable inode bits; not a lock */
Alex Elderdd6f5e12013-02-15 11:42:30 -0600261#define CEPH_LOCK_IPOLICY 16384 /* policy lock on dirs. MDS internal */
Sage Weil0dee3c22009-10-06 11:31:06 -0700262
263/* client_session ops */
264enum {
265 CEPH_SESSION_REQUEST_OPEN,
266 CEPH_SESSION_OPEN,
267 CEPH_SESSION_REQUEST_CLOSE,
268 CEPH_SESSION_CLOSE,
269 CEPH_SESSION_REQUEST_RENEWCAPS,
270 CEPH_SESSION_RENEWCAPS,
271 CEPH_SESSION_STALE,
272 CEPH_SESSION_RECALL_STATE,
Yan, Zheng186e4f72013-11-22 14:48:37 +0800273 CEPH_SESSION_FLUSHMSG,
274 CEPH_SESSION_FLUSHMSG_ACK,
Yan, Zheng03f4fcb2015-01-05 11:04:04 +0800275 CEPH_SESSION_FORCE_RO,
Sage Weil0dee3c22009-10-06 11:31:06 -0700276};
277
278extern const char *ceph_session_op_name(int op);
279
280struct ceph_mds_session_head {
281 __le32 op;
282 __le64 seq;
283 struct ceph_timespec stamp;
284 __le32 max_caps, max_leases;
285} __attribute__ ((packed));
286
287/* client_request */
288/*
289 * metadata ops.
290 * & 0x001000 -> write op
291 * & 0x010000 -> follow symlink (e.g. stat(), not lstat()).
292 & & 0x100000 -> use weird ino/path trace
293 */
294#define CEPH_MDS_OP_WRITE 0x001000
295enum {
296 CEPH_MDS_OP_LOOKUP = 0x00100,
297 CEPH_MDS_OP_GETATTR = 0x00101,
298 CEPH_MDS_OP_LOOKUPHASH = 0x00102,
299 CEPH_MDS_OP_LOOKUPPARENT = 0x00103,
Sage Weil3c454cf2011-04-06 09:31:40 -0700300 CEPH_MDS_OP_LOOKUPINO = 0x00104,
Yan, Zheng19913b42014-03-06 16:40:32 +0800301 CEPH_MDS_OP_LOOKUPNAME = 0x00105,
Sage Weil0dee3c22009-10-06 11:31:06 -0700302
303 CEPH_MDS_OP_SETXATTR = 0x01105,
304 CEPH_MDS_OP_RMXATTR = 0x01106,
305 CEPH_MDS_OP_SETLAYOUT = 0x01107,
306 CEPH_MDS_OP_SETATTR = 0x01108,
Greg Farnumfbaad972010-08-02 15:30:08 -0700307 CEPH_MDS_OP_SETFILELOCK= 0x01109,
308 CEPH_MDS_OP_GETFILELOCK= 0x00110,
Greg Farnum571dba52010-09-24 14:56:40 -0700309 CEPH_MDS_OP_SETDIRLAYOUT=0x0110a,
Sage Weil0dee3c22009-10-06 11:31:06 -0700310
311 CEPH_MDS_OP_MKNOD = 0x01201,
312 CEPH_MDS_OP_LINK = 0x01202,
313 CEPH_MDS_OP_UNLINK = 0x01203,
314 CEPH_MDS_OP_RENAME = 0x01204,
315 CEPH_MDS_OP_MKDIR = 0x01220,
316 CEPH_MDS_OP_RMDIR = 0x01221,
317 CEPH_MDS_OP_SYMLINK = 0x01222,
318
Sage Weil3ea25f92010-01-25 11:18:17 -0800319 CEPH_MDS_OP_CREATE = 0x01301,
Sage Weil0dee3c22009-10-06 11:31:06 -0700320 CEPH_MDS_OP_OPEN = 0x00302,
321 CEPH_MDS_OP_READDIR = 0x00305,
322
323 CEPH_MDS_OP_LOOKUPSNAP = 0x00400,
324 CEPH_MDS_OP_MKSNAP = 0x01400,
325 CEPH_MDS_OP_RMSNAP = 0x01401,
326 CEPH_MDS_OP_LSSNAP = 0x00402,
Yan, Zheng0ea611a2015-04-07 15:36:32 +0800327 CEPH_MDS_OP_RENAMESNAP = 0x01403,
Sage Weil0dee3c22009-10-06 11:31:06 -0700328};
329
330extern const char *ceph_mds_op_name(int op);
331
332
333#define CEPH_SETATTR_MODE 1
334#define CEPH_SETATTR_UID 2
335#define CEPH_SETATTR_GID 4
336#define CEPH_SETATTR_MTIME 8
337#define CEPH_SETATTR_ATIME 16
338#define CEPH_SETATTR_SIZE 32
339#define CEPH_SETATTR_CTIME 64
340
Alex Elderdd6f5e12013-02-15 11:42:30 -0600341/*
342 * Ceph setxattr request flags.
343 */
Yan, Zhengbcdfeb22014-02-11 13:04:19 +0800344#define CEPH_XATTR_CREATE (1 << 0)
345#define CEPH_XATTR_REPLACE (1 << 1)
346#define CEPH_XATTR_REMOVE (1 << 31)
Alex Elderdd6f5e12013-02-15 11:42:30 -0600347
Sage Weil0dee3c22009-10-06 11:31:06 -0700348union ceph_mds_request_args {
349 struct {
350 __le32 mask; /* CEPH_CAP_* */
351 } __attribute__ ((packed)) getattr;
352 struct {
353 __le32 mode;
354 __le32 uid;
355 __le32 gid;
356 struct ceph_timespec mtime;
357 struct ceph_timespec atime;
358 __le64 size, old_size; /* old_size needed by truncate */
359 __le32 mask; /* CEPH_SETATTR_* */
360 } __attribute__ ((packed)) setattr;
361 struct {
362 __le32 frag; /* which dir fragment */
363 __le32 max_entries; /* how many dentries to grab */
Sage Weil23804d92010-05-14 13:06:30 -0700364 __le32 max_bytes;
Sage Weil0dee3c22009-10-06 11:31:06 -0700365 } __attribute__ ((packed)) readdir;
366 struct {
367 __le32 mode;
368 __le32 rdev;
369 } __attribute__ ((packed)) mknod;
370 struct {
371 __le32 mode;
372 } __attribute__ ((packed)) mkdir;
373 struct {
374 __le32 flags;
375 __le32 mode;
376 __le32 stripe_unit; /* layout for newly created file */
377 __le32 stripe_count; /* ... */
378 __le32 object_size;
379 __le32 file_replication;
Yan, Zheng315f2402016-03-07 10:34:50 +0800380 __le32 mask; /* CEPH_CAP_* */
381 __le32 old_size;
Sage Weil0dee3c22009-10-06 11:31:06 -0700382 } __attribute__ ((packed)) open;
383 struct {
384 __le32 flags;
385 } __attribute__ ((packed)) setxattr;
386 struct {
387 struct ceph_file_layout layout;
388 } __attribute__ ((packed)) setlayout;
Greg Farnumfbaad972010-08-02 15:30:08 -0700389 struct {
390 __u8 rule; /* currently fcntl or flock */
391 __u8 type; /* shared, exclusive, remove*/
Yan, Zhengeb13e832014-03-09 23:16:40 +0800392 __le64 owner; /* owner of the lock */
Greg Farnumfbaad972010-08-02 15:30:08 -0700393 __le64 pid; /* process id requesting the lock */
Greg Farnumfbaad972010-08-02 15:30:08 -0700394 __le64 start; /* initial location to lock */
395 __le64 length; /* num bytes to lock from start */
396 __u8 wait; /* will caller wait for lock to become available? */
397 } __attribute__ ((packed)) filelock_change;
Sage Weil0dee3c22009-10-06 11:31:06 -0700398} __attribute__ ((packed));
399
400#define CEPH_MDS_FLAG_REPLAY 1 /* this is a replayed op */
401#define CEPH_MDS_FLAG_WANT_DENTRY 2 /* want dentry in reply */
402
403struct ceph_mds_request_head {
Sage Weil6df058c2009-12-22 11:24:33 -0800404 __le64 oldest_client_tid;
Sage Weil0dee3c22009-10-06 11:31:06 -0700405 __le32 mdsmap_epoch; /* on client */
406 __le32 flags; /* CEPH_MDS_FLAG_* */
407 __u8 num_retry, num_fwd; /* count retry, fwd attempts */
408 __le16 num_releases; /* # include cap/lease release records */
409 __le32 op; /* mds op code */
410 __le32 caller_uid, caller_gid;
411 __le64 ino; /* use this ino for openc, mkdir, mknod,
412 etc. (if replaying) */
413 union ceph_mds_request_args args;
414} __attribute__ ((packed));
415
416/* cap/lease release record */
417struct ceph_mds_request_release {
418 __le64 ino, cap_id; /* ino and unique cap id */
419 __le32 caps, wanted; /* new issued, wanted */
420 __le32 seq, issue_seq, mseq;
421 __le32 dname_seq; /* if releasing a dentry lease, a */
422 __le32 dname_len; /* string follows. */
423} __attribute__ ((packed));
424
425/* client reply */
426struct ceph_mds_reply_head {
Sage Weil0dee3c22009-10-06 11:31:06 -0700427 __le32 op;
428 __le32 result;
429 __le32 mdsmap_epoch;
430 __u8 safe; /* true if committed to disk */
431 __u8 is_dentry, is_target; /* true if dentry, target inode records
432 are included with reply */
433} __attribute__ ((packed));
434
435/* one for each node split */
436struct ceph_frag_tree_split {
437 __le32 frag; /* this frag splits... */
438 __le32 by; /* ...by this many bits */
439} __attribute__ ((packed));
440
441struct ceph_frag_tree_head {
442 __le32 nsplits; /* num ceph_frag_tree_split records */
443 struct ceph_frag_tree_split splits[];
444} __attribute__ ((packed));
445
446/* capability issue, for bundling with mds reply */
447struct ceph_mds_reply_cap {
448 __le32 caps, wanted; /* caps issued, wanted */
449 __le64 cap_id;
450 __le32 seq, mseq;
451 __le64 realm; /* snap realm */
452 __u8 flags; /* CEPH_CAP_FLAG_* */
453} __attribute__ ((packed));
454
Yan, Zheng4ee6a912013-11-24 14:43:46 +0800455#define CEPH_CAP_FLAG_AUTH (1 << 0) /* cap is issued by auth mds */
456#define CEPH_CAP_FLAG_RELEASE (1 << 1) /* release the cap */
Sage Weil0dee3c22009-10-06 11:31:06 -0700457
458/* inode record, for bundling with mds reply */
459struct ceph_mds_reply_inode {
460 __le64 ino;
461 __le64 snapid;
462 __le32 rdev;
463 __le64 version; /* inode version */
464 __le64 xattr_version; /* version for xattr blob */
465 struct ceph_mds_reply_cap cap; /* caps issued for this inode */
466 struct ceph_file_layout layout;
467 struct ceph_timespec ctime, mtime, atime;
468 __le32 time_warp_seq;
469 __le64 size, max_size, truncate_size;
470 __le32 truncate_seq;
471 __le32 mode, uid, gid;
472 __le32 nlink;
473 __le64 files, subdirs, rbytes, rfiles, rsubdirs; /* dir stats */
474 struct ceph_timespec rctime;
475 struct ceph_frag_tree_head fragtree; /* (must be at end of struct) */
476} __attribute__ ((packed));
Sage Weil6c0f3af2010-11-16 11:14:34 -0800477/* followed by frag array, symlink string, dir layout, xattr blob */
Sage Weil0dee3c22009-10-06 11:31:06 -0700478
479/* reply_lease follows dname, and reply_inode */
480struct ceph_mds_reply_lease {
481 __le16 mask; /* lease type(s) */
482 __le32 duration_ms; /* lease duration */
483 __le32 seq;
484} __attribute__ ((packed));
485
486struct ceph_mds_reply_dirfrag {
487 __le32 frag; /* fragment */
488 __le32 auth; /* auth mds, if this is a delegation point */
489 __le32 ndist; /* number of mds' this is replicated on */
490 __le32 dist[];
491} __attribute__ ((packed));
492
Yan, Zheng9280be22014-10-14 10:33:35 +0800493#define CEPH_LOCK_FCNTL 1
494#define CEPH_LOCK_FLOCK 2
495#define CEPH_LOCK_FCNTL_INTR 3
496#define CEPH_LOCK_FLOCK_INTR 4
497
Greg Farnumfbaad972010-08-02 15:30:08 -0700498
499#define CEPH_LOCK_SHARED 1
500#define CEPH_LOCK_EXCL 2
501#define CEPH_LOCK_UNLOCK 4
502
503struct ceph_filelock {
504 __le64 start;/* file offset to start lock at */
505 __le64 length; /* num bytes to lock; 0 for all following start */
506 __le64 client; /* which client holds the lock */
Yan, Zhengeb13e832014-03-09 23:16:40 +0800507 __le64 owner; /* owner the lock */
Greg Farnumfbaad972010-08-02 15:30:08 -0700508 __le64 pid; /* process id holding the lock on the client */
Greg Farnumfbaad972010-08-02 15:30:08 -0700509 __u8 type; /* shared lock, exclusive lock, or unlock */
510} __attribute__ ((packed));
511
512
Sage Weil0dee3c22009-10-06 11:31:06 -0700513/* file access modes */
514#define CEPH_FILE_MODE_PIN 0
515#define CEPH_FILE_MODE_RD 1
516#define CEPH_FILE_MODE_WR 2
517#define CEPH_FILE_MODE_RDWR 3 /* RD | WR */
518#define CEPH_FILE_MODE_LAZY 4 /* lazy io */
519#define CEPH_FILE_MODE_NUM 8 /* bc these are bit fields.. mostly */
520
521int ceph_flags_to_mode(int flags);
522
Yan, Zheng31c542a2014-11-14 21:41:55 +0800523#define CEPH_INLINE_NONE ((__u64)-1)
Sage Weil0dee3c22009-10-06 11:31:06 -0700524
525/* capability bits */
526#define CEPH_CAP_PIN 1 /* no specific capabilities beyond the pin */
527
528/* generic cap bits */
529#define CEPH_CAP_GSHARED 1 /* client can reads */
530#define CEPH_CAP_GEXCL 2 /* client can read and update */
531#define CEPH_CAP_GCACHE 4 /* (file) client can cache reads */
532#define CEPH_CAP_GRD 8 /* (file) client can read */
533#define CEPH_CAP_GWR 16 /* (file) client can write */
534#define CEPH_CAP_GBUFFER 32 /* (file) client can buffer writes */
535#define CEPH_CAP_GWREXTEND 64 /* (file) client can extend EOF */
536#define CEPH_CAP_GLAZYIO 128 /* (file) client can perform lazy io */
537
Alex Elderdd6f5e12013-02-15 11:42:30 -0600538#define CEPH_CAP_SIMPLE_BITS 2
539#define CEPH_CAP_FILE_BITS 8
540
Sage Weil0dee3c22009-10-06 11:31:06 -0700541/* per-lock shift */
542#define CEPH_CAP_SAUTH 2
543#define CEPH_CAP_SLINK 4
544#define CEPH_CAP_SXATTR 6
Greg Farnumfbaad972010-08-02 15:30:08 -0700545#define CEPH_CAP_SFILE 8
Alex Elderdd6f5e12013-02-15 11:42:30 -0600546#define CEPH_CAP_SFLOCK 20
Sage Weil0dee3c22009-10-06 11:31:06 -0700547
Alex Elderdd6f5e12013-02-15 11:42:30 -0600548#define CEPH_CAP_BITS 22
Sage Weil0dee3c22009-10-06 11:31:06 -0700549
550/* composed values */
551#define CEPH_CAP_AUTH_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SAUTH)
552#define CEPH_CAP_AUTH_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SAUTH)
553#define CEPH_CAP_LINK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SLINK)
554#define CEPH_CAP_LINK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SLINK)
555#define CEPH_CAP_XATTR_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SXATTR)
556#define CEPH_CAP_XATTR_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SXATTR)
557#define CEPH_CAP_FILE(x) (x << CEPH_CAP_SFILE)
558#define CEPH_CAP_FILE_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFILE)
559#define CEPH_CAP_FILE_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFILE)
560#define CEPH_CAP_FILE_CACHE (CEPH_CAP_GCACHE << CEPH_CAP_SFILE)
561#define CEPH_CAP_FILE_RD (CEPH_CAP_GRD << CEPH_CAP_SFILE)
562#define CEPH_CAP_FILE_WR (CEPH_CAP_GWR << CEPH_CAP_SFILE)
563#define CEPH_CAP_FILE_BUFFER (CEPH_CAP_GBUFFER << CEPH_CAP_SFILE)
564#define CEPH_CAP_FILE_WREXTEND (CEPH_CAP_GWREXTEND << CEPH_CAP_SFILE)
565#define CEPH_CAP_FILE_LAZYIO (CEPH_CAP_GLAZYIO << CEPH_CAP_SFILE)
Greg Farnumfbaad972010-08-02 15:30:08 -0700566#define CEPH_CAP_FLOCK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFLOCK)
567#define CEPH_CAP_FLOCK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFLOCK)
568
Sage Weil0dee3c22009-10-06 11:31:06 -0700569
570/* cap masks (for getattr) */
571#define CEPH_STAT_CAP_INODE CEPH_CAP_PIN
572#define CEPH_STAT_CAP_TYPE CEPH_CAP_PIN /* mode >> 12 */
573#define CEPH_STAT_CAP_SYMLINK CEPH_CAP_PIN
574#define CEPH_STAT_CAP_UID CEPH_CAP_AUTH_SHARED
575#define CEPH_STAT_CAP_GID CEPH_CAP_AUTH_SHARED
576#define CEPH_STAT_CAP_MODE CEPH_CAP_AUTH_SHARED
577#define CEPH_STAT_CAP_NLINK CEPH_CAP_LINK_SHARED
578#define CEPH_STAT_CAP_LAYOUT CEPH_CAP_FILE_SHARED
579#define CEPH_STAT_CAP_MTIME CEPH_CAP_FILE_SHARED
580#define CEPH_STAT_CAP_SIZE CEPH_CAP_FILE_SHARED
581#define CEPH_STAT_CAP_ATIME CEPH_CAP_FILE_SHARED /* fixme */
582#define CEPH_STAT_CAP_XATTR CEPH_CAP_XATTR_SHARED
583#define CEPH_STAT_CAP_INODE_ALL (CEPH_CAP_PIN | \
584 CEPH_CAP_AUTH_SHARED | \
585 CEPH_CAP_LINK_SHARED | \
586 CEPH_CAP_FILE_SHARED | \
587 CEPH_CAP_XATTR_SHARED)
Yan, Zheng01deead2014-11-14 21:56:29 +0800588#define CEPH_STAT_CAP_INLINE_DATA (CEPH_CAP_FILE_SHARED | \
589 CEPH_CAP_FILE_RD)
Sage Weil0dee3c22009-10-06 11:31:06 -0700590
591#define CEPH_CAP_ANY_SHARED (CEPH_CAP_AUTH_SHARED | \
592 CEPH_CAP_LINK_SHARED | \
593 CEPH_CAP_XATTR_SHARED | \
594 CEPH_CAP_FILE_SHARED)
595#define CEPH_CAP_ANY_RD (CEPH_CAP_ANY_SHARED | CEPH_CAP_FILE_RD | \
596 CEPH_CAP_FILE_CACHE)
597
598#define CEPH_CAP_ANY_EXCL (CEPH_CAP_AUTH_EXCL | \
599 CEPH_CAP_LINK_EXCL | \
600 CEPH_CAP_XATTR_EXCL | \
601 CEPH_CAP_FILE_EXCL)
Yan, Zhengf98a1282014-04-17 08:55:50 +0800602#define CEPH_CAP_ANY_FILE_RD (CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE | \
603 CEPH_CAP_FILE_SHARED)
Sage Weil0dee3c22009-10-06 11:31:06 -0700604#define CEPH_CAP_ANY_FILE_WR (CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER | \
605 CEPH_CAP_FILE_EXCL)
606#define CEPH_CAP_ANY_WR (CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_FILE_WR)
607#define CEPH_CAP_ANY (CEPH_CAP_ANY_RD | CEPH_CAP_ANY_EXCL | \
Sage Weil84d95092010-05-25 16:46:24 -0700608 CEPH_CAP_ANY_FILE_WR | CEPH_CAP_FILE_LAZYIO | \
609 CEPH_CAP_PIN)
Sage Weil0dee3c22009-10-06 11:31:06 -0700610
611#define CEPH_CAP_LOCKS (CEPH_LOCK_IFILE | CEPH_LOCK_IAUTH | CEPH_LOCK_ILINK | \
612 CEPH_LOCK_IXATTR)
613
614int ceph_caps_for_mode(int mode);
615
616enum {
617 CEPH_CAP_OP_GRANT, /* mds->client grant */
618 CEPH_CAP_OP_REVOKE, /* mds->client revoke */
619 CEPH_CAP_OP_TRUNC, /* mds->client trunc notify */
620 CEPH_CAP_OP_EXPORT, /* mds has exported the cap */
621 CEPH_CAP_OP_IMPORT, /* mds has imported the cap */
622 CEPH_CAP_OP_UPDATE, /* client->mds update */
623 CEPH_CAP_OP_DROP, /* client->mds drop cap bits */
624 CEPH_CAP_OP_FLUSH, /* client->mds cap writeback */
625 CEPH_CAP_OP_FLUSH_ACK, /* mds->client flushed */
626 CEPH_CAP_OP_FLUSHSNAP, /* client->mds flush snapped metadata */
627 CEPH_CAP_OP_FLUSHSNAP_ACK, /* mds->client flushed snapped metadata */
628 CEPH_CAP_OP_RELEASE, /* client->mds release (clean) cap */
629 CEPH_CAP_OP_RENEW, /* client->mds renewal request */
630};
631
632extern const char *ceph_cap_op_name(int op);
633
634/*
635 * caps message, used for capability callbacks, acks, requests, etc.
636 */
637struct ceph_mds_caps {
638 __le32 op; /* CEPH_CAP_OP_* */
639 __le64 ino, realm;
640 __le64 cap_id;
641 __le32 seq, issue_seq;
642 __le32 caps, wanted, dirty; /* latest issued/wanted/dirty */
643 __le32 migrate_seq;
644 __le64 snap_follows;
645 __le32 snap_trace_len;
Sage Weil0dee3c22009-10-06 11:31:06 -0700646
647 /* authlock */
648 __le32 uid, gid, mode;
649
650 /* linklock */
651 __le32 nlink;
652
653 /* xattrlock */
654 __le32 xattr_len;
655 __le64 xattr_version;
656
657 /* filelock */
658 __le64 size, max_size, truncate_size;
659 __le32 truncate_seq;
660 struct ceph_timespec mtime, atime, ctime;
661 struct ceph_file_layout layout;
662 __le32 time_warp_seq;
663} __attribute__ ((packed));
664
Yan, Zheng4ee6a912013-11-24 14:43:46 +0800665struct ceph_mds_cap_peer {
666 __le64 cap_id;
667 __le32 seq;
668 __le32 mseq;
669 __le32 mds;
670 __u8 flags;
671} __attribute__ ((packed));
672
Sage Weil0dee3c22009-10-06 11:31:06 -0700673/* cap release msg head */
674struct ceph_mds_cap_release {
675 __le32 num; /* number of cap_items that follow */
676} __attribute__ ((packed));
677
678struct ceph_mds_cap_item {
679 __le64 ino;
680 __le64 cap_id;
681 __le32 migrate_seq, seq;
682} __attribute__ ((packed));
683
684#define CEPH_MDS_LEASE_REVOKE 1 /* mds -> client */
685#define CEPH_MDS_LEASE_RELEASE 2 /* client -> mds */
686#define CEPH_MDS_LEASE_RENEW 3 /* client <-> mds */
687#define CEPH_MDS_LEASE_REVOKE_ACK 4 /* client -> mds */
688
689extern const char *ceph_lease_op_name(int o);
690
691/* lease msg header */
692struct ceph_mds_lease {
693 __u8 action; /* CEPH_MDS_LEASE_* */
694 __le16 mask; /* which lease */
695 __le64 ino;
696 __le64 first, last; /* snap range */
697 __le32 seq;
698 __le32 duration_ms; /* duration of renewal */
699} __attribute__ ((packed));
700/* followed by a __le32+string for dname */
701
702/* client reconnect */
703struct ceph_mds_cap_reconnect {
704 __le64 cap_id;
705 __le32 wanted;
706 __le32 issued;
Sage Weil20cb34a2010-05-12 15:21:32 -0700707 __le64 snaprealm;
708 __le64 pathbase; /* base ino for our path to this ino */
709 __le32 flock_len; /* size of flock state blob, if any */
710} __attribute__ ((packed));
711/* followed by flock blob */
712
713struct ceph_mds_cap_reconnect_v1 {
714 __le64 cap_id;
715 __le32 wanted;
716 __le32 issued;
Sage Weil0dee3c22009-10-06 11:31:06 -0700717 __le64 size;
718 struct ceph_timespec mtime, atime;
719 __le64 snaprealm;
720 __le64 pathbase; /* base ino for our path to this ino */
721} __attribute__ ((packed));
Sage Weil0dee3c22009-10-06 11:31:06 -0700722
723struct ceph_mds_snaprealm_reconnect {
724 __le64 ino; /* snap realm base */
725 __le64 seq; /* snap seq for this snap realm */
726 __le64 parent; /* parent realm */
727} __attribute__ ((packed));
728
729/*
730 * snaps
731 */
732enum {
733 CEPH_SNAP_OP_UPDATE, /* CREATE or DESTROY */
734 CEPH_SNAP_OP_CREATE,
735 CEPH_SNAP_OP_DESTROY,
736 CEPH_SNAP_OP_SPLIT,
737};
738
739extern const char *ceph_snap_op_name(int o);
740
741/* snap msg header */
742struct ceph_mds_snap_head {
743 __le32 op; /* CEPH_SNAP_OP_* */
744 __le64 split; /* ino to split off, if any */
745 __le32 num_split_inos; /* # inos belonging to new child realm */
746 __le32 num_split_realms; /* # child realms udner new child realm */
747 __le32 trace_len; /* size of snap trace blob */
748} __attribute__ ((packed));
749/* followed by split ino list, then split realms, then the trace blob */
750
751/*
752 * encode info about a snaprealm, as viewed by a client
753 */
754struct ceph_mds_snap_realm {
755 __le64 ino; /* ino */
756 __le64 created; /* snap: when created */
757 __le64 parent; /* ino: parent realm */
758 __le64 parent_since; /* snap: same parent since */
759 __le64 seq; /* snap: version */
760 __le32 num_snaps;
761 __le32 num_prior_parent_snaps;
762} __attribute__ ((packed));
763/* followed by my snap list, then prior parent snap list */
764
765#endif