blob: 2ad7b860f06232d76ae5a4f208d081a17825a9ae [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
Sage Weil752727a2009-10-09 16:38:45 -070056#define CEPH_MIN_STRIPE_UNIT 65536
Sage Weil0dee3c22009-10-06 11:31:06 -070057
Sage Weil752727a2009-10-09 16:38:45 -070058int ceph_file_layout_is_valid(const struct ceph_file_layout *layout);
Sage Weil0dee3c22009-10-06 11:31:06 -070059
Sage Weil6c0f3af2010-11-16 11:14:34 -080060struct ceph_dir_layout {
61 __u8 dl_dir_hash; /* see ceph_hash.h for ids */
62 __u8 dl_unused1;
63 __u16 dl_unused2;
64 __u32 dl_unused3;
65} __attribute__ ((packed));
Sage Weil0dee3c22009-10-06 11:31:06 -070066
Sage Weil4e7a5dc2009-11-18 16:19:57 -080067/* crypto algorithms */
68#define CEPH_CRYPTO_NONE 0x0
69#define CEPH_CRYPTO_AES 0x1
70
Sage Weilcbbfe492010-08-02 15:48:23 -070071#define CEPH_AES_IV "cephsageyudagreg"
72
Sage Weil4e7a5dc2009-11-18 16:19:57 -080073/* security/authentication protocols */
74#define CEPH_AUTH_UNKNOWN 0x0
75#define CEPH_AUTH_NONE 0x1
76#define CEPH_AUTH_CEPHX 0x2
77
Sage Weilca9d93a2010-05-12 14:48:20 -070078#define CEPH_AUTH_UID_DEFAULT ((__u64) -1)
79
Sage Weil4e7a5dc2009-11-18 16:19:57 -080080
Sage Weil0dee3c22009-10-06 11:31:06 -070081/*********************************************
82 * message layer
83 */
84
85/*
86 * message types
87 */
88
89/* misc */
90#define CEPH_MSG_SHUTDOWN 1
91#define CEPH_MSG_PING 2
92
93/* client <-> monitor */
94#define CEPH_MSG_MON_MAP 4
95#define CEPH_MSG_MON_GET_MAP 5
Sage Weil0dee3c22009-10-06 11:31:06 -070096#define CEPH_MSG_STATFS 13
97#define CEPH_MSG_STATFS_REPLY 14
98#define CEPH_MSG_MON_SUBSCRIBE 15
99#define CEPH_MSG_MON_SUBSCRIBE_ACK 16
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800100#define CEPH_MSG_AUTH 17
101#define CEPH_MSG_AUTH_REPLY 18
Alex Elderdd6f5e12013-02-15 11:42:30 -0600102#define CEPH_MSG_MON_GET_VERSION 19
103#define CEPH_MSG_MON_GET_VERSION_REPLY 20
Sage Weil0dee3c22009-10-06 11:31:06 -0700104
105/* client <-> mds */
Sage Weil0dee3c22009-10-06 11:31:06 -0700106#define CEPH_MSG_MDS_MAP 21
107
108#define CEPH_MSG_CLIENT_SESSION 22
109#define CEPH_MSG_CLIENT_RECONNECT 23
110
111#define CEPH_MSG_CLIENT_REQUEST 24
112#define CEPH_MSG_CLIENT_REQUEST_FORWARD 25
113#define CEPH_MSG_CLIENT_REPLY 26
114#define CEPH_MSG_CLIENT_CAPS 0x310
115#define CEPH_MSG_CLIENT_LEASE 0x311
116#define CEPH_MSG_CLIENT_SNAP 0x312
117#define CEPH_MSG_CLIENT_CAPRELEASE 0x313
118
Sage Weilca9d93a2010-05-12 14:48:20 -0700119/* pool ops */
120#define CEPH_MSG_POOLOP_REPLY 48
121#define CEPH_MSG_POOLOP 49
122
123
Sage Weil0dee3c22009-10-06 11:31:06 -0700124/* osd */
Yehuda Sadeh483fac72011-01-20 16:36:06 -0800125#define CEPH_MSG_OSD_MAP 41
126#define CEPH_MSG_OSD_OP 42
127#define CEPH_MSG_OSD_OPREPLY 43
128#define CEPH_MSG_WATCH_NOTIFY 44
129
130
131/* watch-notify operations */
132enum {
133 WATCH_NOTIFY = 1, /* notifying watcher */
134 WATCH_NOTIFY_COMPLETE = 2, /* notifier notified when done */
135};
136
Sage Weil0dee3c22009-10-06 11:31:06 -0700137
Sage Weilca9d93a2010-05-12 14:48:20 -0700138/* pool operations */
139enum {
140 POOL_OP_CREATE = 0x01,
141 POOL_OP_DELETE = 0x02,
142 POOL_OP_AUID_CHANGE = 0x03,
143 POOL_OP_CREATE_SNAP = 0x11,
144 POOL_OP_DELETE_SNAP = 0x12,
145 POOL_OP_CREATE_UNMANAGED_SNAP = 0x21,
146 POOL_OP_DELETE_UNMANAGED_SNAP = 0x22,
147};
148
Sage Weil13e38c82009-10-09 16:36:34 -0700149struct ceph_mon_request_header {
150 __le64 have_version;
151 __le16 session_mon;
152 __le64 session_mon_tid;
153} __attribute__ ((packed));
Sage Weil0dee3c22009-10-06 11:31:06 -0700154
155struct ceph_mon_statfs {
Sage Weil13e38c82009-10-09 16:36:34 -0700156 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700157 struct ceph_fsid fsid;
Sage Weil0dee3c22009-10-06 11:31:06 -0700158} __attribute__ ((packed));
159
160struct ceph_statfs {
161 __le64 kb, kb_used, kb_avail;
162 __le64 num_objects;
163} __attribute__ ((packed));
164
165struct ceph_mon_statfs_reply {
166 struct ceph_fsid fsid;
Sage Weil0dee3c22009-10-06 11:31:06 -0700167 __le64 version;
168 struct ceph_statfs st;
169} __attribute__ ((packed));
170
Sage Weilca9d93a2010-05-12 14:48:20 -0700171const char *ceph_pool_op_name(int op);
172
173struct ceph_mon_poolop {
174 struct ceph_mon_request_header monhdr;
175 struct ceph_fsid fsid;
176 __le32 pool;
177 __le32 op;
178 __le64 auid;
179 __le64 snapid;
180 __le32 name_len;
181} __attribute__ ((packed));
182
183struct ceph_mon_poolop_reply {
184 struct ceph_mon_request_header monhdr;
185 struct ceph_fsid fsid;
186 __le32 reply_code;
187 __le32 epoch;
188 char has_data;
189 char data[0];
190} __attribute__ ((packed));
191
192struct ceph_mon_unmanaged_snap {
193 __le64 snapid;
194} __attribute__ ((packed));
195
Sage Weil0dee3c22009-10-06 11:31:06 -0700196struct ceph_osd_getmap {
Sage Weil13e38c82009-10-09 16:36:34 -0700197 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700198 struct ceph_fsid fsid;
199 __le32 start;
200} __attribute__ ((packed));
201
202struct ceph_mds_getmap {
Sage Weil13e38c82009-10-09 16:36:34 -0700203 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700204 struct ceph_fsid fsid;
205} __attribute__ ((packed));
206
207struct ceph_client_mount {
Sage Weil13e38c82009-10-09 16:36:34 -0700208 struct ceph_mon_request_header monhdr;
Sage Weil0dee3c22009-10-06 11:31:06 -0700209} __attribute__ ((packed));
210
Yehuda Sadeh483fac72011-01-20 16:36:06 -0800211#define CEPH_SUBSCRIBE_ONETIME 1 /* i want only 1 update after have */
212
Sage Weil0dee3c22009-10-06 11:31:06 -0700213struct ceph_mon_subscribe_item {
Yehuda Sadeh483fac72011-01-20 16:36:06 -0800214 __le64 have_version; __le64 have;
Sage Weil0dee3c22009-10-06 11:31:06 -0700215 __u8 onetime;
216} __attribute__ ((packed));
217
Sage Weil07bd10f2009-10-14 17:26:40 -0700218struct ceph_mon_subscribe_ack {
219 __le32 duration; /* seconds */
220 struct ceph_fsid fsid;
221} __attribute__ ((packed));
222
Sage Weil0dee3c22009-10-06 11:31:06 -0700223/*
Alex Elderdd6f5e12013-02-15 11:42:30 -0600224 * mdsmap flags
225 */
226#define CEPH_MDSMAP_DOWN (1<<0) /* cluster deliberately down */
227
228/*
Sage Weil0dee3c22009-10-06 11:31:06 -0700229 * mds states
230 * > 0 -> in
231 * <= 0 -> out
232 */
233#define CEPH_MDS_STATE_DNE 0 /* down, does not exist. */
234#define CEPH_MDS_STATE_STOPPED -1 /* down, once existed, but no subtrees.
235 empty log. */
236#define CEPH_MDS_STATE_BOOT -4 /* up, boot announcement. */
237#define CEPH_MDS_STATE_STANDBY -5 /* up, idle. waiting for assignment. */
238#define CEPH_MDS_STATE_CREATING -6 /* up, creating MDS instance. */
239#define CEPH_MDS_STATE_STARTING -7 /* up, starting previously stopped mds */
240#define CEPH_MDS_STATE_STANDBY_REPLAY -8 /* up, tailing active node's journal */
Alex Elderdd6f5e12013-02-15 11:42:30 -0600241#define CEPH_MDS_STATE_REPLAYONCE -9 /* up, replaying an active node's journal */
Sage Weil0dee3c22009-10-06 11:31:06 -0700242
243#define CEPH_MDS_STATE_REPLAY 8 /* up, replaying journal. */
244#define CEPH_MDS_STATE_RESOLVE 9 /* up, disambiguating distributed
245 operations (import, rename, etc.) */
246#define CEPH_MDS_STATE_RECONNECT 10 /* up, reconnect to clients */
247#define CEPH_MDS_STATE_REJOIN 11 /* up, rejoining distributed cache */
248#define CEPH_MDS_STATE_CLIENTREPLAY 12 /* up, replaying client operations */
249#define CEPH_MDS_STATE_ACTIVE 13 /* up, active */
250#define CEPH_MDS_STATE_STOPPING 14 /* up, but exporting metadata */
251
252extern const char *ceph_mds_state_name(int s);
253
254
255/*
256 * metadata lock types.
257 * - these are bitmasks.. we can compose them
258 * - they also define the lock ordering by the MDS
259 * - a few of these are internal to the mds
260 */
Sage Weildd1c9052010-05-25 16:45:25 -0700261#define CEPH_LOCK_DVERSION 1
262#define CEPH_LOCK_DN 2
263#define CEPH_LOCK_ISNAP 16
264#define CEPH_LOCK_IVERSION 32 /* mds internal */
265#define CEPH_LOCK_IFILE 64
266#define CEPH_LOCK_IAUTH 128
267#define CEPH_LOCK_ILINK 256
268#define CEPH_LOCK_IDFT 512 /* dir frag tree */
269#define CEPH_LOCK_INEST 1024 /* mds internal */
270#define CEPH_LOCK_IXATTR 2048
Sage Weilf0b18d92010-07-07 08:39:03 -0700271#define CEPH_LOCK_IFLOCK 4096 /* advisory file locks */
Sage Weildd1c9052010-05-25 16:45:25 -0700272#define CEPH_LOCK_INO 8192 /* immutable inode bits; not a lock */
Alex Elderdd6f5e12013-02-15 11:42:30 -0600273#define CEPH_LOCK_IPOLICY 16384 /* policy lock on dirs. MDS internal */
Sage Weil0dee3c22009-10-06 11:31:06 -0700274
275/* client_session ops */
276enum {
277 CEPH_SESSION_REQUEST_OPEN,
278 CEPH_SESSION_OPEN,
279 CEPH_SESSION_REQUEST_CLOSE,
280 CEPH_SESSION_CLOSE,
281 CEPH_SESSION_REQUEST_RENEWCAPS,
282 CEPH_SESSION_RENEWCAPS,
283 CEPH_SESSION_STALE,
284 CEPH_SESSION_RECALL_STATE,
285};
286
287extern const char *ceph_session_op_name(int op);
288
289struct ceph_mds_session_head {
290 __le32 op;
291 __le64 seq;
292 struct ceph_timespec stamp;
293 __le32 max_caps, max_leases;
294} __attribute__ ((packed));
295
296/* client_request */
297/*
298 * metadata ops.
299 * & 0x001000 -> write op
300 * & 0x010000 -> follow symlink (e.g. stat(), not lstat()).
301 & & 0x100000 -> use weird ino/path trace
302 */
303#define CEPH_MDS_OP_WRITE 0x001000
304enum {
305 CEPH_MDS_OP_LOOKUP = 0x00100,
306 CEPH_MDS_OP_GETATTR = 0x00101,
307 CEPH_MDS_OP_LOOKUPHASH = 0x00102,
308 CEPH_MDS_OP_LOOKUPPARENT = 0x00103,
Sage Weil3c454cf2011-04-06 09:31:40 -0700309 CEPH_MDS_OP_LOOKUPINO = 0x00104,
Sage Weil0dee3c22009-10-06 11:31:06 -0700310
311 CEPH_MDS_OP_SETXATTR = 0x01105,
312 CEPH_MDS_OP_RMXATTR = 0x01106,
313 CEPH_MDS_OP_SETLAYOUT = 0x01107,
314 CEPH_MDS_OP_SETATTR = 0x01108,
Greg Farnumfbaad972010-08-02 15:30:08 -0700315 CEPH_MDS_OP_SETFILELOCK= 0x01109,
316 CEPH_MDS_OP_GETFILELOCK= 0x00110,
Greg Farnum571dba52010-09-24 14:56:40 -0700317 CEPH_MDS_OP_SETDIRLAYOUT=0x0110a,
Sage Weil0dee3c22009-10-06 11:31:06 -0700318
319 CEPH_MDS_OP_MKNOD = 0x01201,
320 CEPH_MDS_OP_LINK = 0x01202,
321 CEPH_MDS_OP_UNLINK = 0x01203,
322 CEPH_MDS_OP_RENAME = 0x01204,
323 CEPH_MDS_OP_MKDIR = 0x01220,
324 CEPH_MDS_OP_RMDIR = 0x01221,
325 CEPH_MDS_OP_SYMLINK = 0x01222,
326
Sage Weil3ea25f92010-01-25 11:18:17 -0800327 CEPH_MDS_OP_CREATE = 0x01301,
Sage Weil0dee3c22009-10-06 11:31:06 -0700328 CEPH_MDS_OP_OPEN = 0x00302,
329 CEPH_MDS_OP_READDIR = 0x00305,
330
331 CEPH_MDS_OP_LOOKUPSNAP = 0x00400,
332 CEPH_MDS_OP_MKSNAP = 0x01400,
333 CEPH_MDS_OP_RMSNAP = 0x01401,
334 CEPH_MDS_OP_LSSNAP = 0x00402,
335};
336
337extern const char *ceph_mds_op_name(int op);
338
339
340#define CEPH_SETATTR_MODE 1
341#define CEPH_SETATTR_UID 2
342#define CEPH_SETATTR_GID 4
343#define CEPH_SETATTR_MTIME 8
344#define CEPH_SETATTR_ATIME 16
345#define CEPH_SETATTR_SIZE 32
346#define CEPH_SETATTR_CTIME 64
347
Alex Elderdd6f5e12013-02-15 11:42:30 -0600348/*
349 * Ceph setxattr request flags.
350 */
351#define CEPH_XATTR_CREATE 1
352#define CEPH_XATTR_REPLACE 2
353
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;
Sage Weil0dee3c22009-10-06 11:31:06 -0700371 } __attribute__ ((packed)) readdir;
372 struct {
373 __le32 mode;
374 __le32 rdev;
375 } __attribute__ ((packed)) mknod;
376 struct {
377 __le32 mode;
378 } __attribute__ ((packed)) mkdir;
379 struct {
380 __le32 flags;
381 __le32 mode;
382 __le32 stripe_unit; /* layout for newly created file */
383 __le32 stripe_count; /* ... */
384 __le32 object_size;
385 __le32 file_replication;
Sage Weil3469ac1a2012-05-07 15:33:36 -0700386 __le32 unused; /* used to be preferred osd */
Sage Weil0dee3c22009-10-06 11:31:06 -0700387 } __attribute__ ((packed)) open;
388 struct {
389 __le32 flags;
390 } __attribute__ ((packed)) setxattr;
391 struct {
392 struct ceph_file_layout layout;
393 } __attribute__ ((packed)) setlayout;
Greg Farnumfbaad972010-08-02 15:30:08 -0700394 struct {
395 __u8 rule; /* currently fcntl or flock */
396 __u8 type; /* shared, exclusive, remove*/
397 __le64 pid; /* process id requesting the lock */
398 __le64 pid_namespace;
399 __le64 start; /* initial location to lock */
400 __le64 length; /* num bytes to lock from start */
401 __u8 wait; /* will caller wait for lock to become available? */
402 } __attribute__ ((packed)) filelock_change;
Sage Weil0dee3c22009-10-06 11:31:06 -0700403} __attribute__ ((packed));
404
405#define CEPH_MDS_FLAG_REPLAY 1 /* this is a replayed op */
406#define CEPH_MDS_FLAG_WANT_DENTRY 2 /* want dentry in reply */
407
408struct ceph_mds_request_head {
Sage Weil6df058c2009-12-22 11:24:33 -0800409 __le64 oldest_client_tid;
Sage Weil0dee3c22009-10-06 11:31:06 -0700410 __le32 mdsmap_epoch; /* on client */
411 __le32 flags; /* CEPH_MDS_FLAG_* */
412 __u8 num_retry, num_fwd; /* count retry, fwd attempts */
413 __le16 num_releases; /* # include cap/lease release records */
414 __le32 op; /* mds op code */
415 __le32 caller_uid, caller_gid;
416 __le64 ino; /* use this ino for openc, mkdir, mknod,
417 etc. (if replaying) */
418 union ceph_mds_request_args args;
419} __attribute__ ((packed));
420
421/* cap/lease release record */
422struct ceph_mds_request_release {
423 __le64 ino, cap_id; /* ino and unique cap id */
424 __le32 caps, wanted; /* new issued, wanted */
425 __le32 seq, issue_seq, mseq;
426 __le32 dname_seq; /* if releasing a dentry lease, a */
427 __le32 dname_len; /* string follows. */
428} __attribute__ ((packed));
429
430/* client reply */
431struct ceph_mds_reply_head {
Sage Weil0dee3c22009-10-06 11:31:06 -0700432 __le32 op;
433 __le32 result;
434 __le32 mdsmap_epoch;
435 __u8 safe; /* true if committed to disk */
436 __u8 is_dentry, is_target; /* true if dentry, target inode records
437 are included with reply */
438} __attribute__ ((packed));
439
440/* one for each node split */
441struct ceph_frag_tree_split {
442 __le32 frag; /* this frag splits... */
443 __le32 by; /* ...by this many bits */
444} __attribute__ ((packed));
445
446struct ceph_frag_tree_head {
447 __le32 nsplits; /* num ceph_frag_tree_split records */
448 struct ceph_frag_tree_split splits[];
449} __attribute__ ((packed));
450
451/* capability issue, for bundling with mds reply */
452struct ceph_mds_reply_cap {
453 __le32 caps, wanted; /* caps issued, wanted */
454 __le64 cap_id;
455 __le32 seq, mseq;
456 __le64 realm; /* snap realm */
457 __u8 flags; /* CEPH_CAP_FLAG_* */
458} __attribute__ ((packed));
459
460#define CEPH_CAP_FLAG_AUTH 1 /* cap is issued by auth mds */
461
462/* inode record, for bundling with mds reply */
463struct ceph_mds_reply_inode {
464 __le64 ino;
465 __le64 snapid;
466 __le32 rdev;
467 __le64 version; /* inode version */
468 __le64 xattr_version; /* version for xattr blob */
469 struct ceph_mds_reply_cap cap; /* caps issued for this inode */
470 struct ceph_file_layout layout;
471 struct ceph_timespec ctime, mtime, atime;
472 __le32 time_warp_seq;
473 __le64 size, max_size, truncate_size;
474 __le32 truncate_seq;
475 __le32 mode, uid, gid;
476 __le32 nlink;
477 __le64 files, subdirs, rbytes, rfiles, rsubdirs; /* dir stats */
478 struct ceph_timespec rctime;
479 struct ceph_frag_tree_head fragtree; /* (must be at end of struct) */
480} __attribute__ ((packed));
Sage Weil6c0f3af2010-11-16 11:14:34 -0800481/* followed by frag array, symlink string, dir layout, xattr blob */
Sage Weil0dee3c22009-10-06 11:31:06 -0700482
483/* reply_lease follows dname, and reply_inode */
484struct ceph_mds_reply_lease {
485 __le16 mask; /* lease type(s) */
486 __le32 duration_ms; /* lease duration */
487 __le32 seq;
488} __attribute__ ((packed));
489
490struct ceph_mds_reply_dirfrag {
491 __le32 frag; /* fragment */
492 __le32 auth; /* auth mds, if this is a delegation point */
493 __le32 ndist; /* number of mds' this is replicated on */
494 __le32 dist[];
495} __attribute__ ((packed));
496
Greg Farnumfbaad972010-08-02 15:30:08 -0700497#define CEPH_LOCK_FCNTL 1
498#define CEPH_LOCK_FLOCK 2
499
500#define CEPH_LOCK_SHARED 1
501#define CEPH_LOCK_EXCL 2
502#define CEPH_LOCK_UNLOCK 4
503
504struct ceph_filelock {
505 __le64 start;/* file offset to start lock at */
506 __le64 length; /* num bytes to lock; 0 for all following start */
507 __le64 client; /* which client holds the lock */
508 __le64 pid; /* process id holding the lock on the client */
509 __le64 pid_namespace;
510 __u8 type; /* shared lock, exclusive lock, or unlock */
511} __attribute__ ((packed));
512
513
Sage Weil0dee3c22009-10-06 11:31:06 -0700514/* file access modes */
515#define CEPH_FILE_MODE_PIN 0
516#define CEPH_FILE_MODE_RD 1
517#define CEPH_FILE_MODE_WR 2
518#define CEPH_FILE_MODE_RDWR 3 /* RD | WR */
519#define CEPH_FILE_MODE_LAZY 4 /* lazy io */
520#define CEPH_FILE_MODE_NUM 8 /* bc these are bit fields.. mostly */
521
522int ceph_flags_to_mode(int flags);
523
524
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)
588
589#define CEPH_CAP_ANY_SHARED (CEPH_CAP_AUTH_SHARED | \
590 CEPH_CAP_LINK_SHARED | \
591 CEPH_CAP_XATTR_SHARED | \
592 CEPH_CAP_FILE_SHARED)
593#define CEPH_CAP_ANY_RD (CEPH_CAP_ANY_SHARED | CEPH_CAP_FILE_RD | \
594 CEPH_CAP_FILE_CACHE)
595
596#define CEPH_CAP_ANY_EXCL (CEPH_CAP_AUTH_EXCL | \
597 CEPH_CAP_LINK_EXCL | \
598 CEPH_CAP_XATTR_EXCL | \
599 CEPH_CAP_FILE_EXCL)
600#define CEPH_CAP_ANY_FILE_WR (CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER | \
601 CEPH_CAP_FILE_EXCL)
602#define CEPH_CAP_ANY_WR (CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_FILE_WR)
603#define CEPH_CAP_ANY (CEPH_CAP_ANY_RD | CEPH_CAP_ANY_EXCL | \
Sage Weil84d95092010-05-25 16:46:24 -0700604 CEPH_CAP_ANY_FILE_WR | CEPH_CAP_FILE_LAZYIO | \
605 CEPH_CAP_PIN)
Sage Weil0dee3c22009-10-06 11:31:06 -0700606
607#define CEPH_CAP_LOCKS (CEPH_LOCK_IFILE | CEPH_LOCK_IAUTH | CEPH_LOCK_ILINK | \
608 CEPH_LOCK_IXATTR)
609
610int ceph_caps_for_mode(int mode);
611
612enum {
613 CEPH_CAP_OP_GRANT, /* mds->client grant */
614 CEPH_CAP_OP_REVOKE, /* mds->client revoke */
615 CEPH_CAP_OP_TRUNC, /* mds->client trunc notify */
616 CEPH_CAP_OP_EXPORT, /* mds has exported the cap */
617 CEPH_CAP_OP_IMPORT, /* mds has imported the cap */
618 CEPH_CAP_OP_UPDATE, /* client->mds update */
619 CEPH_CAP_OP_DROP, /* client->mds drop cap bits */
620 CEPH_CAP_OP_FLUSH, /* client->mds cap writeback */
621 CEPH_CAP_OP_FLUSH_ACK, /* mds->client flushed */
622 CEPH_CAP_OP_FLUSHSNAP, /* client->mds flush snapped metadata */
623 CEPH_CAP_OP_FLUSHSNAP_ACK, /* mds->client flushed snapped metadata */
624 CEPH_CAP_OP_RELEASE, /* client->mds release (clean) cap */
625 CEPH_CAP_OP_RENEW, /* client->mds renewal request */
626};
627
628extern const char *ceph_cap_op_name(int op);
629
630/*
631 * caps message, used for capability callbacks, acks, requests, etc.
632 */
633struct ceph_mds_caps {
634 __le32 op; /* CEPH_CAP_OP_* */
635 __le64 ino, realm;
636 __le64 cap_id;
637 __le32 seq, issue_seq;
638 __le32 caps, wanted, dirty; /* latest issued/wanted/dirty */
639 __le32 migrate_seq;
640 __le64 snap_follows;
641 __le32 snap_trace_len;
Sage Weil0dee3c22009-10-06 11:31:06 -0700642
643 /* authlock */
644 __le32 uid, gid, mode;
645
646 /* linklock */
647 __le32 nlink;
648
649 /* xattrlock */
650 __le32 xattr_len;
651 __le64 xattr_version;
652
653 /* filelock */
654 __le64 size, max_size, truncate_size;
655 __le32 truncate_seq;
656 struct ceph_timespec mtime, atime, ctime;
657 struct ceph_file_layout layout;
658 __le32 time_warp_seq;
659} __attribute__ ((packed));
660
661/* cap release msg head */
662struct ceph_mds_cap_release {
663 __le32 num; /* number of cap_items that follow */
664} __attribute__ ((packed));
665
666struct ceph_mds_cap_item {
667 __le64 ino;
668 __le64 cap_id;
669 __le32 migrate_seq, seq;
670} __attribute__ ((packed));
671
672#define CEPH_MDS_LEASE_REVOKE 1 /* mds -> client */
673#define CEPH_MDS_LEASE_RELEASE 2 /* client -> mds */
674#define CEPH_MDS_LEASE_RENEW 3 /* client <-> mds */
675#define CEPH_MDS_LEASE_REVOKE_ACK 4 /* client -> mds */
676
677extern const char *ceph_lease_op_name(int o);
678
679/* lease msg header */
680struct ceph_mds_lease {
681 __u8 action; /* CEPH_MDS_LEASE_* */
682 __le16 mask; /* which lease */
683 __le64 ino;
684 __le64 first, last; /* snap range */
685 __le32 seq;
686 __le32 duration_ms; /* duration of renewal */
687} __attribute__ ((packed));
688/* followed by a __le32+string for dname */
689
690/* client reconnect */
691struct ceph_mds_cap_reconnect {
692 __le64 cap_id;
693 __le32 wanted;
694 __le32 issued;
Sage Weil20cb34a2010-05-12 15:21:32 -0700695 __le64 snaprealm;
696 __le64 pathbase; /* base ino for our path to this ino */
697 __le32 flock_len; /* size of flock state blob, if any */
698} __attribute__ ((packed));
699/* followed by flock blob */
700
701struct ceph_mds_cap_reconnect_v1 {
702 __le64 cap_id;
703 __le32 wanted;
704 __le32 issued;
Sage Weil0dee3c22009-10-06 11:31:06 -0700705 __le64 size;
706 struct ceph_timespec mtime, atime;
707 __le64 snaprealm;
708 __le64 pathbase; /* base ino for our path to this ino */
709} __attribute__ ((packed));
Sage Weil0dee3c22009-10-06 11:31:06 -0700710
711struct ceph_mds_snaprealm_reconnect {
712 __le64 ino; /* snap realm base */
713 __le64 seq; /* snap seq for this snap realm */
714 __le64 parent; /* parent realm */
715} __attribute__ ((packed));
716
717/*
718 * snaps
719 */
720enum {
721 CEPH_SNAP_OP_UPDATE, /* CREATE or DESTROY */
722 CEPH_SNAP_OP_CREATE,
723 CEPH_SNAP_OP_DESTROY,
724 CEPH_SNAP_OP_SPLIT,
725};
726
727extern const char *ceph_snap_op_name(int o);
728
729/* snap msg header */
730struct ceph_mds_snap_head {
731 __le32 op; /* CEPH_SNAP_OP_* */
732 __le64 split; /* ino to split off, if any */
733 __le32 num_split_inos; /* # inos belonging to new child realm */
734 __le32 num_split_realms; /* # child realms udner new child realm */
735 __le32 trace_len; /* size of snap trace blob */
736} __attribute__ ((packed));
737/* followed by split ino list, then split realms, then the trace blob */
738
739/*
740 * encode info about a snaprealm, as viewed by a client
741 */
742struct ceph_mds_snap_realm {
743 __le64 ino; /* ino */
744 __le64 created; /* snap: when created */
745 __le64 parent; /* ino: parent realm */
746 __le64 parent_since; /* snap: same parent since */
747 __le64 seq; /* snap: version */
748 __le32 num_snaps;
749 __le32 num_prior_parent_snaps;
750} __attribute__ ((packed));
751/* followed by my snap list, then prior parent snap list */
752
753#endif