Whamcloud - gitweb
* Landing fix on HEAD, originally committed to b_devel
[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  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Lustre wire protocol definitions.
22  *
23  * We assume all nodes are either little-endian or big-endian, and we
24  * always send messages in the sender's native format.  The receiver
25  * detects the message format by checking the 'magic' field of the message
26  * (see lustre_msg_swabbed() below).
27  *
28  * Each wire type has corresponding 'lustre_swab_xxxtypexxx()' routines,
29  * implemented either here, inline (trivial implementations) or in
30  * ptlrpc/pack_generic.c.  These 'swabbers' convert the type from "other"
31  * endian, in-place in the message buffer.
32  *
33  * A swabber takes a single pointer argument.  The caller must already have
34  * verified that the length of the message buffer >= sizeof (type).
35  *
36  * For variable length types, a second 'lustre_swab_v_xxxtypexxx()' routine
37  * may be defined that swabs just the variable part, after the caller has
38  * verified that the message buffer is large enough.
39  */
40
41 #ifndef _LUSTRE_IDL_H_
42 #define _LUSTRE_IDL_H_
43
44 #ifdef __KERNEL__
45 # include <linux/ioctl.h>
46 # include <asm/types.h>
47 # include <linux/types.h>
48 # include <linux/list.h>
49 # include <linux/string.h> /* for strncpy, below */
50 # include <asm/byteorder.h>
51 #else
52 #ifdef __CYGWIN__
53 # include <sys/types.h>
54 #else
55 # include <asm/types.h>
56 # include <stdint.h>
57 #endif
58 # include <portals/list.h>
59 #endif
60 /*
61  * this file contains all data structures used in Lustre interfaces:
62  * - obdo and obd_request records
63  * - mds_request records
64  * - ldlm data
65  * - ioctl's
66  */
67
68 /*
69  *  GENERAL STUFF
70  */
71 struct obd_uuid {
72         __u8 uuid[37];
73 };
74
75 static inline int obd_uuid_equals(struct obd_uuid *u1, struct obd_uuid *u2)
76 {
77         return strcmp(u1->uuid, u2->uuid) == 0;
78 }
79
80 static inline void obd_str2uuid(struct obd_uuid *uuid, char *tmp)
81 {
82         strncpy(uuid->uuid, tmp, sizeof(*uuid));
83         uuid->uuid[sizeof(*uuid) - 1] = '\0';
84 }
85
86 extern struct obd_uuid lctl_fake_uuid;
87
88 /* FOO_REQUEST_PORTAL is for incoming requests on the FOO
89  * FOO_REPLY_PORTAL   is for incoming replies on the FOO
90  * FOO_BULK_PORTAL    is for incoming bulk on the FOO
91  */
92
93 #define CONNMGR_REQUEST_PORTAL          1
94 #define CONNMGR_REPLY_PORTAL            2
95 //#define OSC_REQUEST_PORTAL            3
96 #define OSC_REPLY_PORTAL                4
97 //#define OSC_BULK_PORTAL               5
98 #define OST_REQUEST_PORTAL              6
99 //#define OST_REPLY_PORTAL              7
100 #define OST_BULK_PORTAL                 8
101 //#define MDC_REQUEST_PORTAL            9
102 #define MDC_REPLY_PORTAL               10
103 //#define MDC_BULK_PORTAL              11
104 #define MDS_REQUEST_PORTAL             12
105 //#define MDS_REPLY_PORTAL             13
106 #define MDS_BULK_PORTAL                14
107 #define LDLM_CB_REQUEST_PORTAL         15
108 #define LDLM_CB_REPLY_PORTAL           16
109 #define LDLM_CANCEL_REQUEST_PORTAL     17
110 #define LDLM_CANCEL_REPLY_PORTAL       18
111 #define PTLBD_REQUEST_PORTAL           19
112 #define PTLBD_REPLY_PORTAL             20
113 #define PTLBD_BULK_PORTAL              21
114 #define MDS_SETATTR_PORTAL             22
115 #define MDS_READPAGE_PORTAL            23
116 #define MGMT_REQUEST_PORTAL            24
117 #define MGMT_REPLY_PORTAL              25
118 #define MGMT_CLI_REQUEST_PORTAL        26
119 #define MGMT_CLI_REPLY_PORTAL          27
120
121 #define SVC_KILLED               1
122 #define SVC_EVENT                2
123 #define SVC_SIGNAL               4
124 #define SVC_RUNNING              8
125 #define SVC_STOPPING            16
126 #define SVC_STOPPED             32
127
128 #define LUSTRE_CONN_NEW          1
129 #define LUSTRE_CONN_CON          2
130 #define LUSTRE_CONN_NOTCONN      3
131 #define LUSTRE_CONN_RECOVER      4
132 #define LUSTRE_CONN_FULL         5
133
134 /* packet types */
135 #define PTL_RPC_MSG_REQUEST 4711
136 #define PTL_RPC_MSG_ERR     4712
137 #define PTL_RPC_MSG_REPLY   4713
138
139 #define PTLRPC_MSG_MAGIC    0x0BD00BD0
140 #define PTLRPC_MSG_VERSION  0x00040002
141
142 struct lustre_handle {
143         __u64 cookie;
144 };
145 #define DEAD_HANDLE_MAGIC 0xdeadbeefcafebabe
146
147 /* we depend on this structure to be 8-byte aligned */
148 /* this type is only endian-adjusted in lustre_unpack_msg() */
149 struct lustre_msg {
150         struct lustre_handle handle;
151         __u32 magic;
152         __u32 type;
153         __u32 version;
154         __u32 opc;
155         __u64 last_xid;
156         __u64 last_committed;
157         __u64 transno;
158         __u32 status;
159         __u32 flags;
160         __u32 bufcount;
161         __u32 buflens[0];
162 };
163
164 static inline int lustre_msg_swabbed (struct lustre_msg *msg)
165 {
166         return (msg->magic == __swab32(PTLRPC_MSG_MAGIC));
167 }
168
169 /* Flags that are operation-specific go in the top 16 bits. */
170 #define MSG_OP_FLAG_MASK   0xffff0000
171 #define MSG_OP_FLAG_SHIFT  16
172
173 /* Flags that apply to all requests are in the bottom 16 bits */
174 #define MSG_GEN_FLAG_MASK      0x0000ffff
175 #define MSG_LAST_REPLAY        1
176 #define MSG_RESENT             2
177
178 static inline int lustre_msg_get_flags(struct lustre_msg *msg)
179 {
180         return (msg->flags & MSG_GEN_FLAG_MASK);
181 }
182
183 static inline void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
184 {
185         msg->flags |= MSG_GEN_FLAG_MASK & flags;
186 }
187
188 static inline void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
189 {
190         msg->flags &= ~MSG_GEN_FLAG_MASK;
191         lustre_msg_add_flags(msg, flags);
192 }
193
194 static inline int lustre_msg_get_op_flags(struct lustre_msg *msg)
195 {
196         return (msg->flags >> MSG_OP_FLAG_SHIFT);
197 }
198
199 static inline void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
200 {
201         msg->flags |= ((flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT);
202 }
203
204 static inline void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
205 {
206         msg->flags &= ~MSG_OP_FLAG_MASK;
207         lustre_msg_add_op_flags(msg, flags);
208 }
209
210 /*
211  * Flags for all connect opcodes (MDS_CONNECT, OST_CONNECT)
212  */
213
214 #define MSG_CONNECT_RECOVERING  0x1
215 #define MSG_CONNECT_RECONNECT   0x2
216 #define MSG_CONNECT_REPLAYABLE  0x4
217 #define MSG_CONNECT_PEER        0x8
218
219 /*
220  *   OST requests: OBDO & OBD request records
221  */
222
223 /* opcodes */
224 typedef enum {
225         OST_REPLY      =  0,       /* reply ? */
226         OST_GETATTR    =  1,
227         OST_SETATTR    =  2,
228         OST_READ       =  3,
229         OST_WRITE      =  4,
230         OST_CREATE     =  5,
231         OST_DESTROY    =  6,
232         OST_GET_INFO   =  7,
233         OST_CONNECT    =  8,
234         OST_DISCONNECT =  9,
235         OST_PUNCH      = 10,
236         OST_OPEN       = 11,
237         OST_CLOSE      = 12,
238         OST_STATFS     = 13,
239         OST_SAN_READ   = 14,
240         OST_SAN_WRITE  = 15,
241         OST_SYNCFS     = 16,
242         OST_SET_INFO   = 17,
243         OST_LAST_OPC
244 } ost_cmd_t;
245 #define OST_FIRST_OPC  OST_REPLY
246 /* When adding OST RPC opcodes, please update 
247  * LAST/FIRST macros used in ptlrpc/ptlrpc_internals.h */
248
249 typedef uint64_t        obd_id;
250 typedef uint64_t        obd_gr;
251 typedef uint64_t        obd_time;
252 typedef uint64_t        obd_size;
253 typedef uint64_t        obd_off;
254 typedef uint64_t        obd_blocks;
255 typedef uint32_t        obd_blksize;
256 typedef uint32_t        obd_mode;
257 typedef uint32_t        obd_uid;
258 typedef uint32_t        obd_gid;
259 typedef uint64_t        obd_rdev;
260 typedef uint32_t        obd_flag;
261 typedef uint32_t        obd_count;
262
263 #define OBD_FL_INLINEDATA       (0x00000001)
264 #define OBD_FL_OBDMDEXISTS      (0x00000002)
265
266 #define OBD_INLINESZ    60
267 #define FD_OSTDATA_SIZE sizeof(struct obd_client_handle)
268
269 /* Note: 64-bit types are 64-bit aligned in structure */
270 struct obdo {
271         obd_id                  o_id;
272         obd_gr                  o_gr;
273         obd_time                o_atime;
274         obd_time                o_mtime;
275         obd_time                o_ctime;
276         obd_size                o_size;
277         obd_blocks              o_blocks; /* brw: clients sent cached bytes */
278         obd_rdev                o_rdev; /* brw: clients/servers sent grant */
279         obd_blksize             o_blksize;      /* optimal IO blocksize */
280         obd_mode                o_mode;
281         obd_uid                 o_uid;
282         obd_gid                 o_gid;
283         obd_flag                o_flags;
284         obd_count               o_nlink; /* brw: checksum */
285         obd_count               o_generation;
286         obd_flag                o_valid;        /* hot fields in this obdo */
287         obd_flag                o_obdflags;
288         __u32                   o_easize;
289         char                    o_inline[OBD_INLINESZ];
290 };
291
292 extern void lustre_swab_obdo (struct obdo *o);
293
294 struct lov_object_id { /* per-child structure */
295         __u64 l_object_id;
296 };
297
298 #define LOV_MAGIC  0x0BD00BD0
299
300 struct lov_mds_md {
301         __u32 lmm_magic;
302         __u64 lmm_object_id;       /* lov object id */
303         __u32 lmm_stripe_size;     /* size of the stripe */
304         __u32 lmm_stripe_offset;   /* starting stripe offset in lmm_objects */
305         __u16 lmm_stripe_count;    /* number of stipes in use for this object */
306         __u16 lmm_ost_count;       /* how many OST idx are in this LOV md */
307         struct lov_object_id lmm_objects[0];
308 } __attribute__((packed));
309
310 #define OBD_MD_FLALL    (0xffffffff)
311 #define OBD_MD_FLID     (0x00000001)    /* object ID */
312 #define OBD_MD_FLATIME  (0x00000002)    /* access time */
313 #define OBD_MD_FLMTIME  (0x00000004)    /* data modification time */
314 #define OBD_MD_FLCTIME  (0x00000008)    /* change time */
315 #define OBD_MD_FLSIZE   (0x00000010)    /* size */
316 #define OBD_MD_FLBLOCKS (0x00000020)    /* allocated blocks count */
317 #define OBD_MD_FLBLKSZ  (0x00000040)    /* block size */
318 #define OBD_MD_FLMODE   (0x00000080)    /* access bits (mode & ~S_IFMT) */
319 #define OBD_MD_FLTYPE   (0x00000100)    /* object type (mode & S_IFMT) */
320 #define OBD_MD_FLUID    (0x00000200)    /* user ID */
321 #define OBD_MD_FLGID    (0x00000400)    /* group ID */
322 #define OBD_MD_FLFLAGS  (0x00000800)    /* flags word */
323 #define OBD_MD_FLOBDFLG (0x00001000)
324 #define OBD_MD_FLNLINK  (0x00002000)    /* link count */
325 #define OBD_MD_FLGENER  (0x00004000)    /* generation number */
326 #define OBD_MD_FLINLINE (0x00008000)    /* inline data */
327 #define OBD_MD_FLRDEV   (0x00010000)    /* device number */
328 #define OBD_MD_FLEASIZE (0x00020000)    /* extended attribute data */
329 #define OBD_MD_LINKNAME (0x00040000)    /* symbolic link target */
330 #define OBD_MD_FLHANDLE (0x00080000)    /* file handle */
331 #define OBD_MD_FLCKSUM  (0x00100000)    /* bulk data checksum */
332 #define OBD_MD_FLQOS    (0x00200000)    /* quality of service stats */
333 #define OBD_MD_FLOSCOPQ (0x00400000)    /* osc opaque data */
334 #define OBD_MD_FLCOOKIE (0x00800000)    /* log cancellation cookie */
335 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS | OBD_MD_LINKNAME|\
336                            OBD_MD_FLEASIZE | OBD_MD_FLHANDLE | OBD_MD_FLCKSUM|\
337                            OBD_MD_FLQOS | OBD_MD_FLOSCOPQ | OBD_MD_FLCOOKIE))
338
339 static inline struct lustre_handle *obdo_handle(struct obdo *oa)
340 {
341         return (struct lustre_handle *)oa->o_inline;
342 }
343
344 static inline struct llog_cookie *obdo_logcookie(struct obdo *oa)
345 {
346         return (struct llog_cookie *)(oa->o_inline +
347                                       sizeof(struct lustre_handle));
348 }
349
350 struct obd_statfs {
351         __u64           os_type;
352         __u64           os_blocks;
353         __u64           os_bfree;
354         __u64           os_bavail;
355         __u64           os_files;
356         __u64           os_ffree;
357         __u8            os_fsid[40];
358         __u32           os_bsize;
359         __u32           os_namelen;
360         __u64           os_maxbytes;
361         __u32           os_spare[10];
362 };
363
364 extern void lustre_swab_obd_statfs (struct obd_statfs *os);
365
366 /* ost_body.data values for OST_BRW */
367
368 #define OBD_BRW_READ       0x01
369 #define OBD_BRW_WRITE      0x02
370 #define OBD_BRW_RWMASK     (OBD_BRW_READ | OBD_BRW_WRITE)
371 #define OBD_BRW_CREATE     0x04
372 #define OBD_BRW_SYNC       0x08
373 #define OBD_BRW_CHECK      0x10
374 #define OBD_BRW_FROM_GRANT 0x20
375
376 #define OBD_OBJECT_EOF 0xffffffffffffffffULL
377
378 struct obd_ioobj {
379         obd_id               ioo_id;
380         obd_gr               ioo_gr;
381         __u32                ioo_type;
382         __u32                ioo_bufcnt;
383 } __attribute__((packed));
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 } __attribute__((packed));
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
406 /*
407  *   MDS REQ RECORDS
408  */
409
410 /* opcodes */
411 typedef enum {
412         MDS_GETATTR      = 33,
413         MDS_GETATTR_NAME = 34,
414         MDS_CLOSE        = 35,
415         MDS_REINT        = 36,
416         MDS_READPAGE     = 37,
417         MDS_CONNECT      = 38,
418         MDS_DISCONNECT   = 39,
419         MDS_GETSTATUS    = 40,
420         MDS_STATFS       = 41,
421         MDS_GETLOVINFO   = 42,
422         MDS_PIN          = 43,
423         MDS_UNPIN        = 44,
424         MDS_LAST_OPC
425 } mds_cmd_t;
426 #define MDS_FIRST_OPC    MDS_GETATTR
427 /* When adding MDS RPC opcodes, please update 
428  * LAST/FIRST macros used in ptlrpc/ptlrpc_internals.h */
429
430 /*
431  * Do not exceed 63 
432  */
433
434 #define REINT_SETATTR  1
435 #define REINT_CREATE   2
436 #define REINT_LINK     3
437 #define REINT_UNLINK   4
438 #define REINT_RENAME   5
439 #define REINT_OPEN     6
440 #define REINT_MAX      6
441
442 /* the disposition of the intent outlines what was executed */
443 #define DISP_IT_EXECD   1
444 #define DISP_LOOKUP_EXECD  (1 << 1)
445 #define DISP_LOOKUP_NEG     (1 << 2)
446 #define DISP_LOOKUP_POS     (1 << 3)
447 #define DISP_OPEN_CREATE  (1 << 4)
448 #define DISP_OPEN_OPEN    (1 << 5)
449 #define DISP_ENQ_COMPLETE (1<<6)
450
451
452 struct ll_uctxt {
453         __u32 gid1;
454         __u32 gid2;
455 };
456
457 struct ll_fid {
458         __u64 id;
459         __u32 generation;
460         __u32 f_type;
461 };
462
463 extern void lustre_swab_ll_fid (struct ll_fid *fid);
464
465 #define MDS_STATUS_CONN 1
466 #define MDS_STATUS_LOV 2
467
468 struct mds_status_req {
469         __u32  flags;
470         __u32  repbuf;
471 };
472
473 extern void lustre_swab_mds_status_req (struct mds_status_req *r);
474
475 struct mds_fileh_body {
476         struct ll_fid f_fid;
477         struct lustre_handle f_handle;
478 };
479
480 extern void lustre_swab_mds_fileh_body (struct mds_fileh_body *f);
481
482 struct mds_body {
483         struct ll_fid  fid1;
484         struct ll_fid  fid2;
485         struct lustre_handle handle;
486         __u64          size;   /* Offset, in the case of MDS_READPAGE */
487         __u64          blocks; /* XID, in the case of MDS_READPAGE */
488         __u32          ino;   /* make this a __u64 */
489         __u32          valid;
490         __u32          fsuid;
491         __u32          fsgid;
492         __u32          capability;
493         __u32          mode;
494         __u32          uid;
495         __u32          gid;
496         __u32          mtime;
497         __u32          ctime;
498         __u32          atime;
499         __u32          flags;
500         __u32          rdev;
501         __u32          nlink; /* #bytes to read in the case of MDS_READPAGE */
502         __u32          generation;
503         __u32          suppgid;
504         __u32          eadatasize;
505 };
506
507 extern void lustre_swab_mds_body (struct mds_body *b);
508
509 /* This is probably redundant with OBD_MD_FLEASIZE, but we need an audit */
510 #define MDS_OPEN_HAS_EA 1 /* this open has an EA, for a delayed create*/
511
512 /* MDS update records */
513
514 //struct mds_update_record_hdr {
515 //        __u32 ur_opcode;
516 //};
517
518 struct mds_rec_setattr {
519         __u32           sa_opcode;
520         __u32           sa_fsuid;
521         __u32           sa_fsgid;
522         __u32           sa_cap;
523         __u32           sa_reserved;
524         __u32           sa_valid;
525         struct ll_fid   sa_fid;
526         __u32           sa_mode;
527         __u32           sa_uid;
528         __u32           sa_gid;
529         __u32           sa_attr_flags;
530         __u64           sa_size;
531         __u64           sa_atime;
532         __u64           sa_mtime;
533         __u64           sa_ctime;
534         __u32           sa_suppgid;
535 };
536
537 /* Remove this once we declare it in include/linux/fs.h (v21 kernel patch?) */
538 #ifndef ATTR_CTIME_SET
539 #define ATTR_CTIME_SET 0x2000
540 #endif
541
542 extern void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa);
543
544 struct mds_rec_create {
545         __u32           cr_opcode;
546         __u32           cr_fsuid;
547         __u32           cr_fsgid;
548         __u32           cr_cap;
549         __u32           cr_flags; /* for use with open */
550         __u32           cr_mode;
551         struct ll_fid   cr_fid;
552         struct ll_fid   cr_replayfid;
553         __u32           cr_uid;
554         __u32           cr_gid;
555         __u64           cr_time;
556         __u64           cr_rdev;
557         __u32           cr_suppgid;
558 };
559
560 extern void lustre_swab_mds_rec_create (struct mds_rec_create *cr);
561
562 struct mds_rec_link {
563         __u32           lk_opcode;
564         __u32           lk_fsuid;
565         __u32           lk_fsgid;
566         __u32           lk_cap;
567         __u32           lk_suppgid1;
568         __u32           lk_suppgid2;
569         struct ll_fid   lk_fid1;
570         struct ll_fid   lk_fid2;
571 };
572
573 extern void lustre_swab_mds_rec_link (struct mds_rec_link *lk);
574
575 struct mds_rec_unlink {
576         __u32           ul_opcode;
577         __u32           ul_fsuid;
578         __u32           ul_fsgid;
579         __u32           ul_cap;
580         __u32           ul_reserved;
581         __u32           ul_mode;
582         __u32           ul_suppgid;
583         struct ll_fid   ul_fid1;
584         struct ll_fid   ul_fid2;
585 };
586
587 extern void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul);
588
589 struct mds_rec_rename {
590         __u32           rn_opcode;
591         __u32           rn_fsuid;
592         __u32           rn_fsgid;
593         __u32           rn_cap;
594         __u32           rn_suppgid1;
595         __u32           rn_suppgid2;
596         struct ll_fid   rn_fid1;
597         struct ll_fid   rn_fid2;
598 };
599
600 extern void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn);
601
602 /*
603  *  LOV data structures
604  */
605
606 #define LOV_RAID0   0
607 #define LOV_RAIDRR  1
608
609 #define LOV_MAX_UUID_BUFFER_SIZE  8192
610 /* The size of the buffer the lov/mdc reserves for the 
611  * array of UUIDs returned by the MDS.  With the current
612  * protocol, this will limit the max number of OSTs per LOV */
613
614 struct lov_desc {
615         __u32 ld_tgt_count;                /* how many OBD's */
616         __u32 ld_active_tgt_count;         /* how many active */
617         __u32 ld_default_stripe_count;     /* how many objects are used */
618         __u64 ld_default_stripe_size;      /* in bytes */
619         __u64 ld_default_stripe_offset;    /* in bytes */
620         __u32 ld_pattern;                  /* RAID 0,1 etc */
621         struct obd_uuid ld_uuid;
622 };
623
624 extern void lustre_swab_lov_desc (struct lov_desc *ld);
625
626 /*
627  *   LDLM requests:
628  */
629 /* opcodes -- MUST be distinct from OST/MDS opcodes */
630 typedef enum {
631         LDLM_ENQUEUE     = 101,
632         LDLM_CONVERT     = 102,
633         LDLM_CANCEL      = 103,
634         LDLM_BL_CALLBACK = 104,
635         LDLM_CP_CALLBACK = 105,
636         LDLM_LAST_OPC
637 } ldlm_cmd_t;
638 #define LDLM_FIRST_OPC LDLM_ENQUEUE
639 /* When adding LDLM RPC opcodes, please update 
640  * LAST/FIRST macros used in ptlrpc/ptlrpc_internals.h */
641
642 #define RES_NAME_SIZE 3
643 #define RES_VERSION_SIZE 4
644
645 struct ldlm_res_id {
646         __u64 name[RES_NAME_SIZE];
647 };
648
649 extern void lustre_swab_ldlm_res_id (struct ldlm_res_id *id);
650
651 /* lock types */
652 typedef enum {
653         LCK_EX = 1,
654         LCK_PW,
655         LCK_PR,
656         LCK_CW,
657         LCK_CR,
658         LCK_NL
659 } ldlm_mode_t;
660
661 struct ldlm_extent {
662         __u64 start;
663         __u64 end;
664 };
665
666 extern void lustre_swab_ldlm_extent (struct ldlm_extent *e);
667
668 struct ldlm_intent {
669         __u64 opc;
670 };
671
672 extern void lustre_swab_ldlm_intent (struct ldlm_intent *i);
673
674 /* Note this unaligned structure; as long as it's only used in ldlm_request
675  * below, we're probably fine. */
676 struct ldlm_resource_desc {
677         __u32 lr_type;
678         struct ldlm_res_id lr_name;
679         __u32 lr_version[RES_VERSION_SIZE];
680 };
681
682 extern void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r);
683
684 struct ldlm_lock_desc {
685         struct ldlm_resource_desc l_resource;
686         ldlm_mode_t l_req_mode;
687         ldlm_mode_t l_granted_mode;
688         struct ldlm_extent l_extent;
689         __u32 l_version[RES_VERSION_SIZE];
690 };
691
692 extern void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l);
693
694 struct ldlm_request {
695         __u32 lock_flags;
696         struct ldlm_lock_desc lock_desc;
697         struct lustre_handle lock_handle1;
698         struct lustre_handle lock_handle2;
699 };
700
701 extern void lustre_swab_ldlm_request (struct ldlm_request *rq);
702
703 struct ldlm_reply {
704         __u32 lock_flags;
705         __u32 lock_mode;
706         struct ldlm_res_id lock_resource_name;
707         struct lustre_handle lock_handle;
708         struct ldlm_extent lock_extent;   /* XXX make this policy 1 &2 */
709         __u64  lock_policy_res1;
710         __u64  lock_policy_res2;
711 };
712
713 extern void lustre_swab_ldlm_reply (struct ldlm_reply *r);
714
715 /*
716  * ptlbd, portal block device requests
717  */
718 typedef enum {
719         PTLBD_QUERY = 200,
720         PTLBD_READ = 201,
721         PTLBD_WRITE = 202,
722         PTLBD_FLUSH = 203,
723         PTLBD_CONNECT = 204,
724         PTLBD_DISCONNECT = 205,
725         PTLBD_LAST_OPC
726 } ptlbd_cmd_t;
727 #define PTLBD_FIRST_OPC PTLBD_QUERY
728 /* When adding PTLBD RPC opcodes, please update 
729  * LAST/FIRST macros used in ptlrpc/ptlrpc_internals.h */
730
731 struct ptlbd_op {
732         __u16 op_cmd;
733         __u16 op_lun;
734         __u16 op_niob_cnt;
735         __u16 op__padding;
736         __u32 op_block_cnt;
737 };
738
739 extern void lustre_swab_ptlbd_op (struct ptlbd_op *op);
740
741 struct ptlbd_niob {
742         __u64 n_xid;
743         __u64 n_block_nr;
744         __u32 n_offset;
745         __u32 n_length;
746 };
747
748 extern void lustre_swab_ptlbd_niob (struct ptlbd_niob *n);
749
750 struct ptlbd_rsp {
751         __u16 r_status;
752         __u16 r_error_cnt;
753 };
754
755 extern void lustre_swab_ptlbd_rsp (struct ptlbd_rsp *r);
756
757 /*
758  * Opcodes for management/monitoring node.
759  */
760 #define MGMT_CONNECT    250
761 #define MGMT_DISCONNECT 251
762 #define MGMT_EXCEPTION  252 /* node died, etc. */
763
764 /*
765  * Opcodes for multiple servers.
766  */
767
768 #define OBD_PING       400
769 #define OBD_LOG_CANCEL 401
770 #define OBD_LAST_OPC  (OBD_LOG_CANCEL + 1)
771 #define OBD_FIRST_OPC OBD_PING
772
773 /* catalog of log objects */
774
775 /* Identifier for a single log object */
776 struct llog_logid {
777         __u64                   lgl_oid;
778         __u32                   lgl_ogen;
779 };
780
781 /* Log data record types - there is no specific reason that these need to
782  * be related to the RPC opcodes, but no reason not to (may be handy later?)
783  */
784 typedef enum {
785         OST_CREATE_REC = 0x10600000 | (OST_CREATE << 8),
786         OST_ORPHAN_REC = 0x10600000 | (OST_DESTROY << 8),
787         MDS_UNLINK_REC = 0x10610000 | (MDS_REINT << 8) | REINT_UNLINK,
788         LLOG_CATALOG_MAGIC = 0x1062e67d,
789         LLOG_OBJECT_MAGIC = 0x10645539,
790 } llog_op_type;
791
792 /* Log record header - stored in originating host endian order (use magic to
793  * check order).
794  * Each record must start with this struct, end with a __u32 for the struct
795  * length, and be a multiple of 64 bits in size.
796  */
797 struct llog_trans_hdr {
798         __u32                   lth_len;
799         __u32                   lth_type;
800 };
801
802 struct llog_create_rec {
803         struct llog_trans_hdr   lcr_hdr;
804         struct ll_fid           lcr_fid;
805         obd_id                  lcr_oid;
806         obd_count               lcr_ogen;
807         __u32                   lcr_end_len;
808 } __attribute__((packed));
809
810 struct llog_orphan_rec {
811         struct llog_trans_hdr   lor_hdr;
812         obd_id                  lor_oid;
813         obd_count               lor_ogen;
814         __u32                   lor_end_len;
815 } __attribute__((packed));
816
817 struct llog_unlink_rec {
818         struct llog_trans_hdr   lur_hdr;
819         obd_id                  lur_oid;
820         obd_count               lur_ogen;
821         __u32                   lur_end_len;
822 } __attribute__((packed));
823
824 /* On-disk header structure of each log object - stored in creating host
825  * endian order, with the exception of the bitmap - stored in little endian
826  * order so that we can use ext2_{clear,set,test}_bit() for proper/optimized
827  * little-endian handling of bitmaps (which are otherwise a pain to handle).
828  */
829 #define LLOG_CHUNK_SIZE         4096
830 #define LLOG_HEADER_SIZE        (96)
831 #define LLOG_BITMAP_BYTES       (LLOG_CHUNK_SIZE - LLOG_HEADER_SIZE)
832
833 #define LLOG_MIN_REC_SIZE       (16) /* round(struct llog_trans_hdr+end_len) */
834
835 struct llog_object_hdr {
836         struct llog_trans_hdr   llh_hdr;
837         __u64                   llh_timestamp;
838         __u32                   llh_count;
839         __u16                   llh_bitmap_offset;
840         __u16                   llh_unused;
841         struct obd_uuid         llh_tgtuuid;
842         __u8                    llh_padding[3];
843         __u32                   llh_reserved[LLOG_HEADER_SIZE/sizeof(__u32)-17];
844         __u32                   llh_bitmap[LLOG_BITMAP_BYTES/sizeof(__u32)];
845         __u32                   llh_hdr_end_len;
846 };
847
848 static inline int llog_log_swabbed(struct llog_object_hdr *hdr)
849 {
850         if (hdr->llh_hdr.lth_type == __swab32(LLOG_OBJECT_MAGIC))
851                 return 1;
852         if (hdr->llh_hdr.lth_type == LLOG_OBJECT_MAGIC)
853                 return 0;
854         return -1;
855 }
856
857 /* log cookies are used to reference a specific log file and a record therein */
858 struct llog_cookie {
859         struct llog_logid       lgc_lgl;
860         __u32                   lgc_index;
861 };
862
863 #endif