Whamcloud - gitweb
r=adilger
[fs/lustre-release.git] / lustre / include / linux / lustre_idl.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *   This file is part of Lustre, http://www.lustre.org
5  *
6  * Lustre wire protocol definitions.
7  *
8  * All structs passing over the wire should be declared here (lov_mds_md
9  * being the lone exception).  Structs must be properly aligned to put
10  * 64-bit values on an 8-byte boundary.  Any structs being added here
11  * must also be added to utils/wirecheck.c and "make newwiretest" run
12  * to regenerate the utils/wiretest.c sources.  This allows us to verify
13  * that wire structs have the proper alignment/size on all architectures.
14  *
15  * We assume all nodes are either little-endian or big-endian, and we
16  * always send messages in the sender's native format.  The receiver
17  * detects the message format by checking the 'magic' field of the message
18  * (see lustre_msg_swabbed() below).
19  *
20  * Each wire type has corresponding 'lustre_swab_xxxtypexxx()' routines,
21  * implemented either here, inline (trivial implementations) or in
22  * ptlrpc/pack_generic.c.  These 'swabbers' convert the type from "other"
23  * endian, in-place in the message buffer.
24  *
25  * A swabber takes a single pointer argument.  The caller must already have
26  * verified that the length of the message buffer >= sizeof (type).
27  *
28  * For variable length types, a second 'lustre_swab_v_xxxtypexxx()' routine
29  * may be defined that swabs just the variable part, after the caller has
30  * verified that the message buffer is large enough.
31  */
32
33 #ifndef _LUSTRE_IDL_H_
34 #define _LUSTRE_IDL_H_
35
36 #ifdef __KERNEL__
37 # include <asm/types.h>
38 # include <linux/types.h>
39 # include <linux/fs.h> /* to check for FMODE_EXEC, lest we redefine */
40 #else
41 #ifdef __CYGWIN__
42 # include <sys/types.h>
43 #else
44 # include <asm/types.h>
45 # include <stdint.h>
46 #endif
47 #endif
48
49 /* Defn's shared with user-space. */
50 #include <lustre/lustre_user.h>
51
52 /*
53  * this file contains all data structures used in Lustre interfaces:
54  * - obdo and obd_request records
55  * - mds_request records
56  * - ldlm data
57  * - ioctl's
58  */
59
60 /*
61  *  GENERAL STUFF
62  */
63 /* FOO_REQUEST_PORTAL is for incoming requests on the FOO
64  * FOO_REPLY_PORTAL   is for incoming replies on the FOO
65  * FOO_BULK_PORTAL    is for incoming bulk on the FOO
66  */
67
68 #define CONNMGR_REQUEST_PORTAL          1
69 #define CONNMGR_REPLY_PORTAL            2
70 //#define OSC_REQUEST_PORTAL            3
71 #define OSC_REPLY_PORTAL                4
72 //#define OSC_BULK_PORTAL               5
73 #define OST_REQUEST_PORTAL              6
74 #define OST_CREATE_PORTAL               7
75 #define OST_BULK_PORTAL                 8
76 //#define MDC_REQUEST_PORTAL            9
77 #define MDC_REPLY_PORTAL               10
78 //#define MDC_BULK_PORTAL              11
79 #define MDS_REQUEST_PORTAL             12
80 //#define MDS_REPLY_PORTAL             13
81 #define MDS_BULK_PORTAL                14
82 #define LDLM_CB_REQUEST_PORTAL         15
83 #define LDLM_CB_REPLY_PORTAL           16
84 #define LDLM_CANCEL_REQUEST_PORTAL     17
85 #define LDLM_CANCEL_REPLY_PORTAL       18
86 #define PTLBD_REQUEST_PORTAL           19
87 #define PTLBD_REPLY_PORTAL             20
88 #define PTLBD_BULK_PORTAL              21
89 #define MDS_SETATTR_PORTAL             22
90 #define MDS_READPAGE_PORTAL            23
91 #define MGMT_REQUEST_PORTAL            24
92 #define MGMT_REPLY_PORTAL              25
93 #define MGMT_CLI_REQUEST_PORTAL        26
94 #define MGMT_CLI_REPLY_PORTAL          27
95
96 #define SVC_KILLED               1
97 #define SVC_EVENT                2
98 #define SVC_SIGNAL               4
99 #define SVC_RUNNING              8
100 #define SVC_STOPPING            16
101 #define SVC_STOPPED             32
102
103 /* packet types */
104 #define PTL_RPC_MSG_REQUEST 4711
105 #define PTL_RPC_MSG_ERR     4712
106 #define PTL_RPC_MSG_REPLY   4713
107
108 #define PTLRPC_MSG_MAGIC    0x0BD00BD0
109
110
111 #define PTLRPC_MSG_VERSION  0x00000003
112 #define LUSTRE_MDS_VERSION  (0x00040000|PTLRPC_MSG_VERSION)
113 #define LUSTRE_OST_VERSION  (0x00040000|PTLRPC_MSG_VERSION)
114 #define LUSTRE_DLM_VERSION  (0x00040000|PTLRPC_MSG_VERSION)
115
116 struct lustre_handle {
117         __u64 cookie;
118 };
119 #define DEAD_HANDLE_MAGIC 0xdeadbeefcafebabeULL
120
121 /* we depend on this structure to be 8-byte aligned */
122 /* this type is only endian-adjusted in lustre_unpack_msg() */
123 struct lustre_msg {
124         struct lustre_handle handle;
125         __u32 magic;
126         __u32 type;
127         __u32 version;
128         __u32 opc;
129         __u64 last_xid;
130         __u64 last_committed;
131         __u64 transno;
132         __u32 status;
133         __u32 flags;
134         __u32 conn_cnt;
135         __u32 bufcount;
136         __u32 buflens[0];
137 };
138
139 /* Flags that are operation-specific go in the top 16 bits. */
140 #define MSG_OP_FLAG_MASK   0xffff0000
141 #define MSG_OP_FLAG_SHIFT  16
142
143 /* Flags that apply to all requests are in the bottom 16 bits */
144 #define MSG_GEN_FLAG_MASK      0x0000ffff
145 #define MSG_LAST_REPLAY        1
146 #define MSG_RESENT             2
147 #define MSG_REPLAY             4
148
149 static inline int lustre_msg_get_flags(struct lustre_msg *msg)
150 {
151         return (msg->flags & MSG_GEN_FLAG_MASK);
152 }
153
154 static inline void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
155 {
156         msg->flags |= MSG_GEN_FLAG_MASK & flags;
157 }
158
159 static inline void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
160 {
161         msg->flags &= ~MSG_GEN_FLAG_MASK;
162         lustre_msg_add_flags(msg, flags);
163 }
164
165 static inline void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
166 {
167         msg->flags &= ~(MSG_GEN_FLAG_MASK & flags);
168 }
169
170 static inline int lustre_msg_get_op_flags(struct lustre_msg *msg)
171 {
172         return (msg->flags >> MSG_OP_FLAG_SHIFT);
173 }
174
175 static inline void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
176 {
177         msg->flags |= ((flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT);
178 }
179
180 static inline void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
181 {
182         msg->flags &= ~MSG_OP_FLAG_MASK;
183         lustre_msg_add_op_flags(msg, flags);
184 }
185
186 /*
187  * Flags for all connect opcodes (MDS_CONNECT, OST_CONNECT)
188  */
189
190 #define MSG_CONNECT_RECOVERING  0x1
191 #define MSG_CONNECT_RECONNECT   0x2
192 #define MSG_CONNECT_REPLAYABLE  0x4
193 //#define MSG_CONNECT_PEER        0x8
194 #define MSG_CONNECT_LIBCLIENT   0x10
195
196 /*
197  *   OST requests: OBDO & OBD request records
198  */
199
200 /* opcodes */
201 typedef enum {
202         OST_REPLY      =  0,       /* reply ? */
203         OST_GETATTR    =  1,
204         OST_SETATTR    =  2,
205         OST_READ       =  3,
206         OST_WRITE      =  4,
207         OST_CREATE     =  5,
208         OST_DESTROY    =  6,
209         OST_GET_INFO   =  7,
210         OST_CONNECT    =  8,
211         OST_DISCONNECT =  9,
212         OST_PUNCH      = 10,
213         OST_OPEN       = 11,
214         OST_CLOSE      = 12,
215         OST_STATFS     = 13,
216         OST_SAN_READ   = 14,
217         OST_SAN_WRITE  = 15,
218         OST_SYNC       = 16,
219         OST_SET_INFO   = 17,
220         OST_LAST_OPC
221 } ost_cmd_t;
222 #define OST_FIRST_OPC  OST_REPLY
223
224 typedef uint64_t        obd_id;
225 typedef uint64_t        obd_gr;
226 typedef uint64_t        obd_time;
227 typedef uint64_t        obd_size;
228 typedef uint64_t        obd_off;
229 typedef uint64_t        obd_blocks;
230 typedef uint32_t        obd_blksize;
231 typedef uint32_t        obd_mode;
232 typedef uint32_t        obd_uid;
233 typedef uint32_t        obd_gid;
234 typedef uint32_t        obd_flag;
235 typedef uint32_t        obd_count;
236
237 #define OBD_FL_DELORPHAN    (0x00000004) /* if set in o_flags delete orphans */
238 #define OBD_FL_RECREATE_OBJS (0x00000020) // recreate missing obj
239 #define OBD_FL_DEBUG_CHECK  (0x00000040) /* echo client/server debug check */
240
241 #define OBD_INLINESZ    64
242
243 /* Note: 64-bit types are 64-bit aligned in structure */
244 struct obdo {
245         obd_id                  o_id;
246         obd_gr                  o_gr;
247         obd_time                o_atime;
248         obd_time                o_mtime;
249         obd_time                o_ctime;
250         obd_size                o_size;
251         obd_blocks              o_blocks;       /* brw: cli sent cached bytes */
252         obd_size                o_grant;
253         obd_blksize             o_blksize;      /* optimal IO blocksize */
254         obd_mode                o_mode;         /* brw: cli sent cache remain */
255         obd_uid                 o_uid;
256         obd_gid                 o_gid;
257         obd_flag                o_flags;
258         obd_count               o_nlink;        /* brw: checksum */
259         obd_count               o_generation;
260         obd_flag                o_valid;        /* hot fields in this obdo */
261         obd_count               o_misc;         /* brw: o_dropped */
262         __u32                   o_easize;       /* epoch in ost writes */
263         char                    o_inline[OBD_INLINESZ]; /* fid in ost writes */
264 };
265
266 #define o_dirty   o_blocks
267 #define o_undirty o_mode
268 #define o_dropped o_misc
269 #define o_cksum   o_nlink
270
271 extern void lustre_swab_obdo (struct obdo *o);
272
273 #define LOV_MAGIC_V1      0x0BD10BD0
274 #define LOV_MAGIC         LOV_MAGIC_V1
275
276 #define LOV_PATTERN_RAID0 0x001   /* stripes are used round-robin */
277 #define LOV_PATTERN_RAID1 0x002   /* stripes are mirrors of each other */
278 #define LOV_PATTERN_FIRST 0x100   /* first stripe is not in round-robin */
279
280 #define lov_ost_data lov_ost_data_v1
281 struct lov_ost_data_v1 {          /* per-stripe data structure (little-endian)*/
282         __u64 l_object_id;        /* OST object ID */
283         __u64 l_object_gr;        /* OST object group (creating MDS number) */
284         __u32 l_ost_gen;          /* generation of this l_ost_idx */
285         __u32 l_ost_idx;          /* OST index in LOV (lov_tgt_desc->tgts) */
286 };
287
288 #define lov_mds_md lov_mds_md_v1
289 struct lov_mds_md_v1 {            /* LOV EA mds/wire data (little-endian) */
290         __u32 lmm_magic;          /* magic number = LOV_MAGIC_V1 */
291         __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
292         __u64 lmm_object_id;      /* LOV object ID */
293         __u64 lmm_object_gr;      /* LOV object group */
294         __u32 lmm_stripe_size;    /* size of stripe in bytes */
295         __u32 lmm_stripe_count;   /* num stripes in use for this object */
296         struct lov_ost_data_v1 lmm_objects[0]; /* per-stripe data */
297 };
298
299 #define OBD_MD_FLALL    (0xffffffff)
300 #define OBD_MD_FLID     (0x00000001)    /* object ID */
301 #define OBD_MD_FLATIME  (0x00000002)    /* access time */
302 #define OBD_MD_FLMTIME  (0x00000004)    /* data modification time */
303 #define OBD_MD_FLCTIME  (0x00000008)    /* change time */
304 #define OBD_MD_FLSIZE   (0x00000010)    /* size */
305 #define OBD_MD_FLBLOCKS (0x00000020)    /* allocated blocks count */
306 #define OBD_MD_FLBLKSZ  (0x00000040)    /* block size */
307 #define OBD_MD_FLMODE   (0x00000080)    /* access bits (mode & ~S_IFMT) */
308 #define OBD_MD_FLTYPE   (0x00000100)    /* object type (mode & S_IFMT) */
309 #define OBD_MD_FLUID    (0x00000200)    /* user ID */
310 #define OBD_MD_FLGID    (0x00000400)    /* group ID */
311 #define OBD_MD_FLFLAGS  (0x00000800)    /* flags word */
312 #define OBD_MD_FLNLINK  (0x00002000)    /* link count */
313 #define OBD_MD_FLGENER  (0x00004000)    /* generation number */
314 #define OBD_MD_FLINLINE (0x00008000)    /* inline data */
315 #define OBD_MD_FLRDEV   (0x00010000)    /* device number */
316 #define OBD_MD_FLEASIZE (0x00020000)    /* extended attribute data */
317 #define OBD_MD_LINKNAME (0x00040000)    /* symbolic link target */
318 #define OBD_MD_FLHANDLE (0x00080000)    /* file handle */
319 #define OBD_MD_FLCKSUM  (0x00100000)    /* bulk data checksum */
320 #define OBD_MD_FLQOS    (0x00200000)    /* quality of service stats */
321 #define OBD_MD_FLOSCOPQ (0x00400000)    /* osc opaque data */
322 #define OBD_MD_FLCOOKIE (0x00800000)    /* log cancellation cookie */
323 #define OBD_MD_FLGROUP  (0x01000000)    /* group */
324 #define OBD_MD_FLIFID   (0x02000000)    /* ->ost write inline fid */
325 #define OBD_MD_FLEPOCH  (0x04000000)    /* ->ost write easize is epoch */
326 #define OBD_MD_FLGRANT  (0x08000000)    /* ost preallocation space grant */
327 #define OBD_MD_FLDIREA  (0x10000000)    /* dir's extended attribute data */
328 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLBLOCKS | OBD_MD_LINKNAME|\
329                            OBD_MD_FLEASIZE | OBD_MD_FLHANDLE | OBD_MD_FLCKSUM|\
330                            OBD_MD_FLQOS | OBD_MD_FLOSCOPQ | OBD_MD_FLCOOKIE))
331
332
333 static inline struct lustre_handle *obdo_handle(struct obdo *oa)
334 {
335         return (struct lustre_handle *)oa->o_inline;
336 }
337
338 static inline struct llog_cookie *obdo_logcookie(struct obdo *oa)
339 {
340         return (struct llog_cookie *)(oa->o_inline +
341                                       sizeof(struct lustre_handle));
342 }
343 /* don't forget obdo_fid which is way down at the bottom so it can
344  * come after the definition of llog_cookie */
345
346 struct obd_statfs {
347         __u64           os_type;
348         __u64           os_blocks;
349         __u64           os_bfree;
350         __u64           os_bavail;
351         __u64           os_files;
352         __u64           os_ffree;
353         __u8            os_fsid[40];
354         __u32           os_bsize;
355         __u32           os_namelen;
356         __u64           os_maxbytes;
357         __u32           os_spare[10];
358 };
359
360 extern void lustre_swab_obd_statfs (struct obd_statfs *os);
361
362 /* ost_body.data values for OST_BRW */
363
364 #define OBD_BRW_READ       0x01
365 #define OBD_BRW_WRITE      0x02
366 #define OBD_BRW_RWMASK     (OBD_BRW_READ | OBD_BRW_WRITE)
367 #define OBD_BRW_SYNC       0x08
368 #define OBD_BRW_CHECK      0x10
369 #define OBD_BRW_FROM_GRANT 0x20 /* the osc manages this under llite */
370 #define OBD_BRW_GRANTED    0x40 /* the ost manages this */
371 #define OBD_BRW_DROP       0x80 /* drop the page after IO */
372
373 #define OBD_OBJECT_EOF 0xffffffffffffffffULL
374
375 #define OST_MIN_PRECREATE 32
376 #define OST_MAX_PRECREATE 20000
377
378 struct obd_ioobj {
379         obd_id               ioo_id;
380         obd_gr               ioo_gr;
381         __u32                ioo_type;
382         __u32                ioo_bufcnt;
383 };
384
385 extern void lustre_swab_obd_ioobj (struct obd_ioobj *ioo);
386
387 /* multiple of 8 bytes => can array */
388 struct niobuf_remote {
389         __u64 offset;
390         __u32 len;
391         __u32 flags;
392 };
393
394 extern void lustre_swab_niobuf_remote (struct niobuf_remote *nbr);
395
396 /* request structure for OST's */
397
398 #define OST_REQ_HAS_OA1  0x1
399
400 struct ost_body {
401         struct  obdo oa;
402 };
403
404 extern void lustre_swab_ost_body (struct ost_body *b);
405 extern void lustre_swab_ost_last_id(obd_id *id);
406
407 /* lock value block communicated between the filter and llite */
408
409 struct ost_lvb {
410         __u64 lvb_size;
411         __u64 lvb_mtime;
412         __u64 lvb_atime;
413         __u64 lvb_ctime;
414         __u64 lvb_blocks;
415 };
416
417 extern void lustre_swab_ost_lvb(struct ost_lvb *);
418
419 /*
420  *   MDS REQ RECORDS
421  */
422
423 /* opcodes */
424 typedef enum {
425         MDS_GETATTR      = 33,
426         MDS_GETATTR_NAME = 34,
427         MDS_CLOSE        = 35,
428         MDS_REINT        = 36,
429         MDS_READPAGE     = 37,
430         MDS_CONNECT      = 38,
431         MDS_DISCONNECT   = 39,
432         MDS_GETSTATUS    = 40,
433         MDS_STATFS       = 41,
434         MDS_PIN          = 42,
435         MDS_UNPIN        = 43,
436         MDS_SYNC         = 44,
437         MDS_DONE_WRITING = 45,
438         MDS_LAST_OPC
439 } mds_cmd_t;
440
441 #define MDS_FIRST_OPC    MDS_GETATTR
442
443 /*
444  * Do not exceed 63
445  */
446
447 #define REINT_SETATTR    1
448 #define REINT_CREATE     2
449 #define REINT_LINK       3
450 #define REINT_UNLINK     4
451 #define REINT_RENAME     5
452 #define REINT_OPEN       6
453 #define REINT_MAX        6
454
455 /* the disposition of the intent outlines what was executed */
456 #define DISP_IT_EXECD     0x01
457 #define DISP_LOOKUP_EXECD 0x02
458 #define DISP_LOOKUP_NEG   0x04
459 #define DISP_LOOKUP_POS   0x08
460 #define DISP_OPEN_CREATE  0x10
461 #define DISP_OPEN_OPEN    0x20
462 #define DISP_ENQ_COMPLETE 0x40
463
464 struct ll_fid {
465         __u64 id;
466         __u32 generation;
467         __u32 f_type;
468 };
469
470 extern void lustre_swab_ll_fid (struct ll_fid *fid);
471
472 #define MDS_STATUS_CONN 1
473 #define MDS_STATUS_LOV 2
474
475 struct mds_status_req {
476         __u32  flags;
477         __u32  repbuf;
478 };
479
480 extern void lustre_swab_mds_status_req (struct mds_status_req *r);
481
482 #define MDS_BFLAG_UNCOMMITTED_WRITES   0x1
483
484 struct mds_body {
485         struct ll_fid  fid1;
486         struct ll_fid  fid2;
487         struct lustre_handle handle;
488         __u64          size;   /* Offset, in the case of MDS_READPAGE */
489         __u64          blocks; /* XID, in the case of MDS_READPAGE */
490         __u64          io_epoch;
491         __u32          ino;   /* make this a __u64 */
492         __u32          valid;
493         __u32          fsuid;
494         __u32          fsgid;
495         __u32          capability;
496         __u32          mode;
497         __u32          uid;
498         __u32          gid;
499         __u32          mtime;
500         __u32          ctime;
501         __u32          atime;
502         __u32          flags; /* from vfs for pin/unpin, MDS_BFLAG for close */
503         __u32          rdev;
504         __u32          nlink; /* #bytes to read in the case of MDS_READPAGE */
505         __u32          generation;
506         __u32          suppgid;
507         __u32          eadatasize;
508         __u32          packing;
509 };
510
511 extern void lustre_swab_mds_body (struct mds_body *b);
512
513
514 struct mds_rec_setattr {
515         __u32           sa_opcode;
516         __u32           sa_fsuid;
517         __u32           sa_fsgid;
518         __u32           sa_cap;
519         __u32           sa_suppgid;
520         __u32           sa_valid;
521         struct ll_fid   sa_fid;
522         __u32           sa_mode;
523         __u32           sa_uid;
524         __u32           sa_gid;
525         __u32           sa_attr_flags;
526         __u64           sa_size;
527         __u64           sa_atime;
528         __u64           sa_mtime;
529         __u64           sa_ctime;
530 };
531
532 /* Remove this once we declare it in include/linux/fs.h (v21 kernel patch?) */
533 #ifndef ATTR_CTIME_SET
534 #define ATTR_CTIME_SET 0x2000
535 #endif
536
537 extern void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa);
538
539 #ifndef FMODE_READ
540 #define FMODE_READ               00000001
541 #define FMODE_WRITE              00000002
542 #endif
543 #ifndef FMODE_EXEC
544 #define FMODE_EXEC               00000004
545 #endif
546 #define MDS_OPEN_CREAT           00000100
547 #define MDS_OPEN_EXCL            00000200
548 #define MDS_OPEN_TRUNC           00001000
549 #define MDS_OPEN_APPEND          00002000
550 #define MDS_OPEN_SYNC            00010000
551 #define MDS_OPEN_DIRECTORY       00200000
552
553 #define MDS_OPEN_DELAY_CREATE  0100000000 /* delay initial object create */
554 #define MDS_OPEN_OWNEROVERRIDE 0200000000 /* NFSD rw-reopen ro file for owner */
555 #define MDS_OPEN_HAS_EA      010000000000 /* specify object create pattern */
556 #define MDS_OPEN_HAS_OBJS    020000000000 /* Just set the EA the obj exist */
557
558 struct mds_rec_create {
559         __u32           cr_opcode;
560         __u32           cr_fsuid;
561         __u32           cr_fsgid;
562         __u32           cr_cap;
563         __u32           cr_flags; /* for use with open */
564         __u32           cr_mode;
565         struct ll_fid   cr_fid;
566         struct ll_fid   cr_replayfid;
567         __u64           cr_time;
568         __u64           cr_rdev;
569         __u32           cr_suppgid;
570         __u32           cr_packing;
571 };
572
573 extern void lustre_swab_mds_rec_create (struct mds_rec_create *cr);
574
575 struct mds_rec_link {
576         __u32           lk_opcode;
577         __u32           lk_fsuid;
578         __u32           lk_fsgid;
579         __u32           lk_cap;
580         __u32           lk_suppgid1;
581         __u32           lk_suppgid2;
582         struct ll_fid   lk_fid1;
583         struct ll_fid   lk_fid2;
584         __u64           lk_time;
585 };
586
587 extern void lustre_swab_mds_rec_link (struct mds_rec_link *lk);
588
589 struct mds_rec_unlink {
590         __u32           ul_opcode;
591         __u32           ul_fsuid;
592         __u32           ul_fsgid;
593         __u32           ul_cap;
594         __u32           ul_suppgid;
595         __u32           ul_mode;
596         struct ll_fid   ul_fid1;
597         struct ll_fid   ul_fid2;
598         __u64           ul_time;
599 };
600
601 extern void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul);
602
603 struct mds_rec_rename {
604         __u32           rn_opcode;
605         __u32           rn_fsuid;
606         __u32           rn_fsgid;
607         __u32           rn_cap;
608         __u32           rn_suppgid1;
609         __u32           rn_suppgid2;
610         struct ll_fid   rn_fid1;
611         struct ll_fid   rn_fid2;
612         __u64           rn_time;
613 };
614
615 extern void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn);
616
617 /*
618  *  LOV data structures
619  */
620
621 #define LOV_MAX_UUID_BUFFER_SIZE  8192
622 /* The size of the buffer the lov/mdc reserves for the
623  * array of UUIDs returned by the MDS.  With the current
624  * protocol, this will limit the max number of OSTs per LOV */
625
626 struct lov_desc {
627         __u32 ld_tgt_count;                /* how many OBD's */
628         __u32 ld_active_tgt_count;         /* how many active */
629         __u32 ld_default_stripe_count;     /* how many objects are used */
630         __u32 ld_pattern;                  /* PATTERN_RAID0, PATTERN_RAID1 */
631         __u64 ld_default_stripe_size;      /* in bytes */
632         __u64 ld_default_stripe_offset;    /* in bytes */
633         struct obd_uuid ld_uuid;
634 };
635
636 extern void lustre_swab_lov_desc (struct lov_desc *ld);
637
638 /*
639  *   LDLM requests:
640  */
641 /* opcodes -- MUST be distinct from OST/MDS opcodes */
642 typedef enum {
643         LDLM_ENQUEUE     = 101,
644         LDLM_CONVERT     = 102,
645         LDLM_CANCEL      = 103,
646         LDLM_BL_CALLBACK = 104,
647         LDLM_CP_CALLBACK = 105,
648         LDLM_GL_CALLBACK = 106,
649         LDLM_LAST_OPC
650 } ldlm_cmd_t;
651 #define LDLM_FIRST_OPC LDLM_ENQUEUE
652
653 #define RES_NAME_SIZE 4
654 struct ldlm_res_id {
655         __u64 name[RES_NAME_SIZE];
656 };
657
658 extern void lustre_swab_ldlm_res_id (struct ldlm_res_id *id);
659
660 /* lock types */
661 typedef enum {
662         LCK_EX = 1,
663         LCK_PW = 2,
664         LCK_PR = 4,
665         LCK_CW = 8,
666         LCK_CR = 16,
667         LCK_NL = 32
668 } ldlm_mode_t;
669
670 typedef enum {
671         LDLM_PLAIN     = 10,
672         LDLM_EXTENT    = 11,
673         LDLM_FLOCK     = 12,
674         LDLM_MAX_TYPE
675 } ldlm_type_t;
676
677 #define LDLM_MIN_TYPE LDLM_PLAIN
678
679 struct ldlm_extent {
680         __u64 start;
681         __u64 end;
682 };
683
684 struct ldlm_flock {
685         __u64 start;
686         __u64 end;
687         __u64 blocking_export;
688         pid_t blocking_pid;
689         pid_t pid;
690 };
691
692 /* it's important that the fields of the ldlm_extent structure match
693  * the first fields of the ldlm_flock structure because there is only
694  * one ldlm_swab routine to process the ldlm_policy_data_t union. if
695  * this ever changes we will need to swab the union differently based
696  * on the resource type. */
697
698 typedef union {
699         struct ldlm_extent l_extent;
700         struct ldlm_flock  l_flock;
701 } ldlm_policy_data_t;
702
703 extern void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d);
704
705 struct ldlm_intent {
706         __u64 opc;
707 };
708
709 extern void lustre_swab_ldlm_intent (struct ldlm_intent *i);
710
711 struct ldlm_resource_desc {
712         ldlm_type_t lr_type;
713         __u32 lr_padding;
714         struct ldlm_res_id lr_name;
715 };
716
717 extern void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r);
718
719 struct ldlm_lock_desc {
720         struct ldlm_resource_desc l_resource;
721         ldlm_mode_t l_req_mode;
722         ldlm_mode_t l_granted_mode;
723         ldlm_policy_data_t l_policy_data;
724 };
725
726 extern void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l);
727
728 struct ldlm_request {
729         __u32 lock_flags;
730         __u32 lock_padding;
731         struct ldlm_lock_desc lock_desc;
732         struct lustre_handle lock_handle1;
733         struct lustre_handle lock_handle2;
734 };
735
736 extern void lustre_swab_ldlm_request (struct ldlm_request *rq);
737
738 struct ldlm_reply {
739         __u32 lock_flags;
740         __u32 lock_padding;
741         struct ldlm_lock_desc lock_desc;
742         struct lustre_handle lock_handle;
743         __u64  lock_policy_res1;
744         __u64  lock_policy_res2;
745 };
746
747 extern void lustre_swab_ldlm_reply (struct ldlm_reply *r);
748
749 /*
750  * ptlbd, portal block device requests
751  */
752 typedef enum {
753         PTLBD_QUERY = 200,
754         PTLBD_READ = 201,
755         PTLBD_WRITE = 202,
756         PTLBD_FLUSH = 203,
757         PTLBD_CONNECT = 204,
758         PTLBD_DISCONNECT = 205,
759         PTLBD_LAST_OPC
760 } ptlbd_cmd_t;
761 #define PTLBD_FIRST_OPC PTLBD_QUERY
762
763 struct ptlbd_op {
764         __u16 op_cmd;
765         __u16 op_lun;
766         __u16 op_niob_cnt;
767         __u16 op__padding;
768         __u32 op_block_cnt;
769 };
770
771 extern void lustre_swab_ptlbd_op (struct ptlbd_op *op);
772
773 struct ptlbd_niob {
774         __u64 n_xid;
775         __u64 n_block_nr;
776         __u32 n_offset;
777         __u32 n_length;
778 };
779
780 extern void lustre_swab_ptlbd_niob (struct ptlbd_niob *n);
781
782 struct ptlbd_rsp {
783         __u16 r_status;
784         __u16 r_error_cnt;
785 };
786
787 extern void lustre_swab_ptlbd_rsp (struct ptlbd_rsp *r);
788
789 /*
790  * Opcodes for management/monitoring node.
791  */
792 typedef enum {
793         MGMT_CONNECT = 250,
794         MGMT_DISCONNECT,
795         MGMT_EXCEPTION,         /* node died, etc. */
796         MGMT_LAST_OPC
797 } mgmt_cmd_t;
798 #define MGMT_FIRST_OPC MGMT_CONNECT
799
800 /*
801  * Opcodes for multiple servers.
802  */
803
804 typedef enum {
805         OBD_PING = 400,
806         OBD_LOG_CANCEL,
807         OBD_LAST_OPC
808 } obd_cmd_t;
809 #define OBD_FIRST_OPC OBD_PING
810
811 /* catalog of log objects */
812
813 /* Identifier for a single log object */
814 struct llog_logid {
815         __u64                   lgl_oid;
816         __u64                   lgl_ogr;
817         __u32                   lgl_ogen;
818 } __attribute__((packed));
819
820 /* Records written to the CATALOGS list */
821 #define CATLIST "CATALOGS"
822 struct llog_catid {
823         struct llog_logid       lci_logid;
824         __u32                   lci_padding[3];
825 } __attribute__((packed));
826
827 /* Log data record types - there is no specific reason that these need to
828  * be related to the RPC opcodes, but no reason not to (may be handy later?)
829  */
830 typedef enum {
831         OST_SZ_REC       = 0x10600000 | (OST_SAN_WRITE << 8),
832         OST_RAID1_REC    = 0x10600000 | ((OST_SAN_WRITE + 1) << 8),
833         MDS_UNLINK_REC   = 0x10610000 | (MDS_REINT << 8) | REINT_UNLINK,
834         OBD_CFG_REC      = 0x10620000,
835         PTL_CFG_REC      = 0x10630000,
836         LLOG_GEN_REC     = 0x10640000,
837         LLOG_HDR_MAGIC   = 0x10645539,
838         LLOG_LOGID_MAGIC = 0x1064553b,
839 } llog_op_type;
840
841 /* Log record header - stored in little endian order.
842  * Each record must start with this struct, end with a llog_rec_tail,
843  * and be a multiple of 256 bits in size.
844  */
845 struct llog_rec_hdr {
846         __u32                   lrh_len;
847         __u32                   lrh_index;
848         __u32                   lrh_type;
849         __u32                   padding;
850 };
851
852 struct llog_rec_tail {
853         __u32 lrt_len;
854         __u32 lrt_index;
855 };
856
857 struct llog_logid_rec {
858         struct llog_rec_hdr     lid_hdr;
859         struct llog_logid       lid_id;
860         __u32                   padding[5];
861         struct llog_rec_tail    lid_tail;
862 } __attribute__((packed));
863
864 struct llog_create_rec {
865         struct llog_rec_hdr     lcr_hdr;
866         struct ll_fid           lcr_fid;
867         obd_id                  lcr_oid;
868         obd_count               lcr_ogen;
869         __u32                   padding;
870         struct llog_rec_tail    lcr_tail;
871 } __attribute__((packed));
872
873 struct llog_orphan_rec {
874         struct llog_rec_hdr     lor_hdr;
875         obd_id                  lor_oid;
876         obd_count               lor_ogen;
877         __u32                   padding;
878         struct llog_rec_tail    lor_tail;
879 } __attribute__((packed));
880
881 struct llog_unlink_rec {
882         struct llog_rec_hdr     lur_hdr;
883         obd_id                  lur_oid;
884         obd_count               lur_ogen;
885         __u32                   padding;
886         struct llog_rec_tail    lur_tail;
887 } __attribute__((packed));
888
889 struct llog_size_change_rec {
890         struct llog_rec_hdr     lsc_hdr;
891         struct ll_fid           lsc_fid;
892         __u32                   lsc_io_epoch;
893         __u32                   padding;
894         struct llog_rec_tail    lsc_tail;
895 } __attribute__((packed));
896
897 struct llog_gen {
898         __u64 mnt_cnt;
899         __u64 conn_cnt;
900 } __attribute__((packed));
901
902 struct llog_gen_rec {
903         struct llog_rec_hdr     lgr_hdr;
904         struct llog_gen         lgr_gen;
905         struct llog_rec_tail    lgr_tail;
906 };
907 /* On-disk header structure of each log object, stored in little endian order */
908 #define LLOG_CHUNK_SIZE         8192
909 #define LLOG_HEADER_SIZE        (96)
910 #define LLOG_BITMAP_BYTES       (LLOG_CHUNK_SIZE - LLOG_HEADER_SIZE)
911
912 #define LLOG_MIN_REC_SIZE       (24) /* round(llog_rec_hdr + llog_rec_tail) */
913
914 /* flags for the logs */
915 #define LLOG_F_ZAP_WHEN_EMPTY   0x1
916 #define LLOG_F_IS_CAT           0x2
917 #define LLOG_F_IS_PLAIN         0x4
918
919 struct llog_log_hdr {
920         struct llog_rec_hdr     llh_hdr;
921         __u64                   llh_timestamp;
922         __u32                   llh_count;
923         __u32                   llh_bitmap_offset;
924         __u32                   llh_size;
925         __u32                   llh_flags;
926         __u32                   llh_cat_idx;
927         /* for a catalog the first plain slot is next to it */
928         struct obd_uuid         llh_tgtuuid;
929         __u32                   llh_reserved[LLOG_HEADER_SIZE/sizeof(__u32) - 23];
930         __u32                   llh_bitmap[LLOG_BITMAP_BYTES/sizeof(__u32)];
931         struct llog_rec_tail    llh_tail;
932 } __attribute__((packed));
933
934 #define LLOG_BITMAP_SIZE(llh)  ((llh->llh_hdr.lrh_len -         \
935                                  llh->llh_bitmap_offset -       \
936                                  sizeof(llh->llh_tail)) * 8)
937
938 /* log cookies are used to reference a specific log file and a record therein */
939 struct llog_cookie {
940         struct llog_logid       lgc_lgl;
941         __u32                   lgc_subsys;
942         __u32                   lgc_index;
943         __u32                   lgc_padding;
944 } __attribute__((packed));
945
946 /* llog protocol */
947 enum llogd_rpc_ops {
948         LLOG_ORIGIN_HANDLE_CREATE       = 501,
949         LLOG_ORIGIN_HANDLE_NEXT_BLOCK   = 502,
950         LLOG_ORIGIN_HANDLE_READ_HEADER  = 503,
951         LLOG_ORIGIN_HANDLE_WRITE_REC    = 504,
952         LLOG_ORIGIN_HANDLE_CLOSE        = 505,
953         LLOG_ORIGIN_CONNECT             = 506,
954         LLOG_CATINFO                    = 507,  /* for lfs catinfo */
955 };
956
957 struct llogd_body {
958         struct llog_logid  lgd_logid;
959         __u32 lgd_ctxt_idx;
960         __u32 lgd_llh_flags;
961         __u32 lgd_index;
962         __u32 lgd_saved_index;
963         __u32 lgd_len;
964         __u64 lgd_cur_offset;
965 } __attribute__((packed));
966
967 struct llogd_conn_body {
968         struct llog_gen         lgdc_gen;
969         struct llog_logid       lgdc_logid;
970         __u32                   lgdc_ctxt_idx;
971 } __attribute__((packed));
972
973 extern void lustre_swab_llogd_body (struct llogd_body *d);
974 extern void lustre_swab_llog_hdr (struct llog_log_hdr *h);
975 extern void lustre_swab_llogd_conn_body (struct llogd_conn_body *d);
976
977 static inline struct ll_fid *obdo_fid(struct obdo *oa)
978 {
979         return (struct ll_fid *)(oa->o_inline + sizeof(struct lustre_handle) +
980                                  sizeof(struct llog_cookie));
981 }
982
983 #endif