Whamcloud - gitweb
b0d41903823210e202f1d9e75ce4ecedbfe0caf1
[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  * All structs passing over the wire should be declared here (lov_mds_md
24  * being the lone exception).  Structs must be properly aligned to put
25  * 64-bit values on an 8-byte boundary.  Any structs being added here
26  * must also be added to utils/wirecheck.c and "make newwiretest" run
27  * to regenerate the utils/wiretest.c sources.  This allows us to verify
28  * that wire structs have the proper alignment/size on all architectures.
29  *
30  * We assume all nodes are either little-endian or big-endian, and we
31  * always send messages in the sender's native format.  The receiver
32  * detects the message format by checking the 'magic' field of the message
33  * (see lustre_msg_swabbed() below).
34  *
35  * Each wire type has corresponding 'lustre_swab_xxxtypexxx()' routines,
36  * implemented either here, inline (trivial implementations) or in
37  * ptlrpc/pack_generic.c.  These 'swabbers' convert the type from "other"
38  * endian, in-place in the message buffer.
39  *
40  * A swabber takes a single pointer argument.  The caller must already have
41  * verified that the length of the message buffer >= sizeof (type).
42  *
43  * For variable length types, a second 'lustre_swab_v_xxxtypexxx()' routine
44  * may be defined that swabs just the variable part, after the caller has
45  * verified that the message buffer is large enough.
46  */
47
48 #ifndef _LUSTRE_IDL_H_
49 #define _LUSTRE_IDL_H_
50
51 #ifdef HAVE_ASM_TYPES_H
52 #include <asm/types.h>
53 #else
54 #include "types.h"
55 #endif
56
57
58 #ifdef __KERNEL__
59 # include <linux/ioctl.h>
60 # include <linux/types.h>
61 # include <linux/list.h>
62 # include <linux/string.h> /* for strncpy, below */
63 # include <linux/fs.h>     /* to check for FMODE_EXEC, dev_t, lest we redefine */
64 #else
65 #ifdef __CYGWIN__
66 # include <sys/types.h>
67 #else
68 # include <stdint.h>
69 #endif
70 # include <libcfs/list.h>
71 # include <string.h>
72 #endif
73
74 /* Defn's shared with user-space. */
75 #include <lustre/lustre_user.h>
76
77 /*
78  * this file contains all data structures used in Lustre interfaces:
79  * - obdo and obd_request records
80  * - mds_request records
81  * - ldlm data
82  * - ioctl's
83  */
84
85 /*
86  *  GENERAL STUFF
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_CREATE_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 /* packet types */
129 #define PTL_RPC_MSG_REQUEST 4711
130 #define PTL_RPC_MSG_ERR     4712
131 #define PTL_RPC_MSG_REPLY   4713
132
133 #define PTLRPC_MSG_MAGIC    0x0BD00BD0
134
135
136 #define PTLRPC_MSG_VERSION  0x00000003
137 #define LUSTRE_VERSION_MASK 0xffff0000
138 #define LUSTRE_OBD_VERSION  0x00010000
139 #define LUSTRE_MDS_VERSION  0x00020000
140 #define LUSTRE_OST_VERSION  0x00030000
141 #define LUSTRE_DLM_VERSION  0x00040000
142 #define LUSTRE_LOG_VERSION  0x00050000
143 #define LUSTRE_PBD_VERSION  0x00060000
144
145 struct lustre_handle {
146         __u64 cookie;
147 };
148 #define DEAD_HANDLE_MAGIC 0xdeadbeefcafebabeULL
149
150 /* we depend on this structure to be 8-byte aligned */
151 /* this type is only endian-adjusted in lustre_unpack_msg() */
152 struct lustre_msg {
153         struct lustre_handle handle;
154         __u32 magic;
155         __u32 type;
156         __u32 version;
157         __u32 opc;
158         __u64 last_xid;
159         __u64 last_committed;
160         __u64 transno;
161         __u32 status;
162         __u32 flags;
163         __u32 conn_cnt;
164         __u32 bufcount;
165         __u32 buflens[0];
166 };
167
168 /* Flags that are operation-specific go in the top 16 bits. */
169 #define MSG_OP_FLAG_MASK   0xffff0000
170 #define MSG_OP_FLAG_SHIFT  16
171
172 /* Flags that apply to all requests are in the bottom 16 bits */
173 #define MSG_GEN_FLAG_MASK      0x0000ffff
174 #define MSG_LAST_REPLAY        1
175 #define MSG_RESENT             2
176 #define MSG_REPLAY             4
177 #define MSG_REQ_REPLAY_DONE    8
178 #define MSG_LOCK_REPLAY_DONE  16
179
180 static inline int lustre_msg_get_flags(struct lustre_msg *msg)
181 {
182         return (msg->flags & MSG_GEN_FLAG_MASK);
183 }
184
185 static inline void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
186 {
187         msg->flags |= MSG_GEN_FLAG_MASK & flags;
188 }
189
190 static inline void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
191 {
192         msg->flags &= ~MSG_GEN_FLAG_MASK;
193         lustre_msg_add_flags(msg, flags);
194 }
195
196 static inline void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
197 {
198         msg->flags &= ~(MSG_GEN_FLAG_MASK & flags);
199 }
200
201 static inline int lustre_msg_get_op_flags(struct lustre_msg *msg)
202 {
203         return (msg->flags >> MSG_OP_FLAG_SHIFT);
204 }
205
206 static inline void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
207 {
208         msg->flags |= ((flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT);
209 }
210
211 static inline void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
212 {
213         msg->flags &= ~MSG_OP_FLAG_MASK;
214         lustre_msg_add_op_flags(msg, flags);
215 }
216
217 /*
218  * Flags for all connect opcodes (MDS_CONNECT, OST_CONNECT)
219  */
220
221 #define MSG_CONNECT_RECOVERING  0x1
222 #define MSG_CONNECT_RECONNECT   0x2
223 #define MSG_CONNECT_REPLAYABLE  0x4
224 #define MSG_CONNECT_PEER        0x8
225 #define MSG_CONNECT_LIBCLIENT   0x10
226 #define MSG_CONNECT_INITIAL     0x20
227 #define MSG_CONNECT_ASYNC       0x40
228 #define MSG_CONNECT_TRANSNO     0X80    /* report transno */
229
230 /* Connect flags */
231
232 #define OBD_CONNECT_RDONLY      (0x00000001LL)
233 #define OBD_CONNECT_REMOTE      (0x40000000LL)
234 #define OBD_CONNECT_LOCAL       (0x80000000LL)
235
236 #define OBD_CONNECT_SUPPORTED (OBD_CONNECT_RDONLY |     \
237                                OBD_CONNECT_REMOTE |     \
238                                OBD_CONNECT_LOCAL)
239
240 /* This structure is used for both request and reply.
241  *
242  * If we eventually have separate connect data for different types, which we
243  * almost certainly will, then perhaps we stick a union in here. */
244 struct obd_connect_data {
245         __u64 ocd_connect_flags;
246         __u32 ocd_nllu[2];
247         __u64 transno;          /* first transno from client to be replayed */
248         __u64 padding[5];
249 };
250
251 extern void lustre_swab_connect(struct obd_connect_data *ocd);
252
253 /*
254  *   OST requests: OBDO & OBD request records
255  */
256
257 /* opcodes */
258 typedef enum {
259         OST_REPLY      =  0,       /* reply ? */
260         OST_GETATTR    =  1,
261         OST_SETATTR    =  2,
262         OST_READ       =  3,
263         OST_WRITE      =  4,
264         OST_CREATE     =  5,
265         OST_DESTROY    =  6,
266         OST_GET_INFO   =  7,
267         OST_CONNECT    =  8,
268         OST_DISCONNECT =  9,
269         OST_PUNCH      = 10,
270         OST_OPEN       = 11,
271         OST_CLOSE      = 12,
272         OST_STATFS     = 13,
273         OST_SAN_READ   = 14,
274         OST_SAN_WRITE  = 15,
275         OST_SYNC       = 16,
276         OST_SET_INFO   = 17,
277         OST_LAST_OPC
278 } ost_cmd_t;
279 #define OST_FIRST_OPC  OST_REPLY
280
281 typedef uint64_t        obd_id;
282 typedef uint64_t        obd_gr;
283 typedef uint64_t        obd_time;
284 typedef uint64_t        obd_size;
285 typedef uint64_t        obd_off;
286 typedef uint64_t        obd_blocks;
287 typedef uint32_t        obd_blksize;
288 typedef uint32_t        obd_mode;
289 typedef uint32_t        obd_uid;
290 typedef uint32_t        obd_gid;
291 typedef uint32_t        obd_flags;
292 typedef uint64_t        obd_valid;
293 typedef uint32_t        obd_count;
294
295 #define OBD_FL_INLINEDATA    (0x00000001)
296 #define OBD_FL_OBDMDEXISTS   (0x00000002)
297 #define OBD_FL_DELORPHAN     (0x00000004) /* if set in o_flags delete orphans */
298 #define OBD_FL_NORPC         (0x00000008) // if set in o_flags set in OSC not OST
299 #define OBD_FL_IDONLY        (0x00000010) // if set in o_flags only adjust obj id
300 #define OBD_FL_RECREATE_OBJS (0x00000020) // recreate missing obj
301 #define OBD_FL_DEBUG_CHECK   (0x00000040) /* echo client/server debug check */
302
303 /* this should be sizeof(struct lustre_handle) + sizeof(struct llog_cookie) +
304  * sizeof(struct lustre_id). */
305 #define OBD_INLINESZ (80)
306
307 /* Note: 64-bit types are 64-bit aligned in structure */
308 struct obdo {
309         obd_id                  o_id;
310         obd_gr                  o_gr;
311         obd_size                o_size;
312         obd_time                o_mtime;
313         obd_time                o_atime;
314         obd_time                o_ctime;
315         obd_blocks              o_blocks;       /* brw: cli sent cached bytes */
316         obd_size                o_grant;
317         obd_blksize             o_blksize;      /* optimal IO blocksize */
318         obd_mode                o_mode;         /* brw: cli sent cache remain */
319         obd_uid                 o_uid;
320         obd_gid                 o_gid;
321         obd_flags               o_flags;
322         obd_count               o_nlink;        /* brw: checksum */
323         obd_count               o_generation;
324         obd_valid               o_valid;        /* hot fields in this obdo */
325         obd_count               o_misc;         /* brw: o_dropped */
326         __u32                   o_easize;       /* epoch in ost writes */
327         __u32                   o_mds;
328         __u64                   o_fid;
329         __u32                   o_padding;
330         char                    o_inline[OBD_INLINESZ];
331 };
332
333 #define o_dirty   o_blocks
334 #define o_undirty o_mode
335 #define o_dropped o_misc
336 #define o_cksum   o_nlink
337
338 extern void lustre_swab_obdo (struct obdo *o);
339
340 #define LOV_MAGIC_V1      0x0BD10BD0
341 #define LOV_MAGIC         LOV_MAGIC_V1
342
343 #define LOV_PATTERN_RAID0 0x001   /* stripes are used round-robin */
344 #define LOV_PATTERN_RAID1 0x002   /* stripes are mirrors of each other */
345 #define LOV_PATTERN_FIRST 0x100   /* first stripe is not in round-robin */
346 #define LOV_PATTERN_CMOBD 0x200  
347  
348 #define lov_ost_data lov_ost_data_v1
349 struct lov_ost_data_v1 {          /* per-stripe data structure (little-endian)*/
350         __u64 l_object_id;        /* OST object ID */
351         __u64 l_object_gr;        /* OST object group (creating MDS number) */
352         __u32 l_ost_gen;          /* generation of this l_ost_idx */
353         __u32 l_ost_idx;          /* OST index in LOV (lov_tgt_desc->tgts) */
354 };
355
356 #define lov_mds_md lov_mds_md_v1
357 struct lov_mds_md_v1 {            /* LOV EA mds/wire data (little-endian) */
358         __u32 lmm_magic;          /* magic number = LOV_MAGIC_V1 */
359         __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
360         __u64 lmm_object_id;      /* LOV object ID */
361         __u64 lmm_object_gr;      /* LOV object group */
362         __u32 lmm_stripe_size;    /* size of stripe in bytes */
363         __u32 lmm_stripe_count;   /* num stripes in use for this object */
364         struct lov_ost_data_v1 lmm_objects[0]; /* per-stripe data */
365 };
366
367 #define LOV_MAGIC_V0      0x0BD00BD0
368
369 struct lov_ost_data_v0 {          /* per-stripe data structure (little-endian)*/
370         __u64 l_object_id;        /* OST object ID */
371 };
372
373 struct lov_mds_md_v0 {            /* LOV EA mds/wire data (little-endian) */
374         __u32 lmm_magic;          /* magic number = LOV_MAGIC_V0 */
375         __u64 lmm_object_id;      /* LOV object ID */
376         __u32 lmm_stripe_size;    /* size of the stripe in bytes (not RAID1) */
377         __u32 lmm_stripe_offset;  /* starting stripe offset in lmm_objects */
378         __u16 lmm_stripe_count;   /* number of stipes in use for this object */
379         __u16 lmm_ost_count;      /* how many OST idx are in this LOV md */
380         struct lov_ost_data_v0 lmm_objects[0];
381 } __attribute__((packed));
382
383 #define OBD_MD_FLALL    (0xffffffffffffffffLL)
384 #define OBD_MD_FLID     (0x0000000000000001LL)    /* object ID */
385 #define OBD_MD_FLATIME  (0x0000000000000002LL)    /* access time */
386 #define OBD_MD_FLMTIME  (0x0000000000000004LL)    /* data modification time */
387 #define OBD_MD_FLCTIME  (0x0000000000000008LL)    /* change time */
388 #define OBD_MD_FLSIZE   (0x0000000000000010LL)    /* size */
389 #define OBD_MD_FLBLOCKS (0x0000000000000020LL)    /* allocated blocks count */
390 #define OBD_MD_FLBLKSZ  (0x0000000000000040LL)    /* block size */
391 #define OBD_MD_FLMODE   (0x0000000000000080LL)    /* access bits (mode & ~S_IFMT) */
392 #define OBD_MD_FLTYPE   (0x0000000000000100LL)    /* object type (mode & S_IFMT) */
393 #define OBD_MD_FLUID    (0x0000000000000200LL)    /* user ID */
394 #define OBD_MD_FLGID    (0x0000000000000400LL)    /* group ID */
395 #define OBD_MD_FLFLAGS  (0x0000000000000800LL)    /* flags word */
396 #define OBD_MD_FLEA     (0x0000000000001000LL)    /* extended attributes */
397 #define OBD_MD_FLNLINK  (0x0000000000002000LL)    /* link count */
398 #define OBD_MD_FLGENER  (0x0000000000004000LL)    /* generation number */
399 #define OBD_MD_FLINLINE (0x0000000000008000LL)    /* inline data */
400 #define OBD_MD_FLRDEV   (0x0000000000010000LL)    /* device number */
401 #define OBD_MD_FLEASIZE (0x0000000000020000LL)    /* extended attribute data */
402 #define OBD_MD_LINKNAME (0x0000000000040000LL)    /* symbolic link target */
403 #define OBD_MD_FLHANDLE (0x0000000000080000LL)    /* file handle */
404 #define OBD_MD_FLCKSUM  (0x0000000000100000LL)    /* bulk data checksum */
405 #define OBD_MD_FLQOS    (0x0000000000200000LL)    /* quality of service stats */
406 #define OBD_MD_FLOSCOPQ (0x0000000000400000LL)    /* osc opaque data */
407 #define OBD_MD_FLCOOKIE (0x0000000000800000LL)    /* log cancellation cookie */
408 #define OBD_MD_FLGROUP  (0x0000000001000000LL)    /* group */
409 #define OBD_MD_FLIFID   (0x0000000002000000LL)    /* ->ost write inline fid */
410 #define OBD_MD_FLEPOCH  (0x0000000004000000LL)    /* ->ost write easize is epoch */
411 #define OBD_MD_FLGRANT  (0x0000000008000000LL)    /* ost preallocation space grant */
412 #define OBD_MD_MDS      (0x0000000010000000LL)    /* where an inode lives on */
413 #define OBD_MD_FLDIREA  (0x0000000020000000LL)    /* dir's extended attribute data */
414 #define OBD_MD_REINT    (0x0000000040000000LL)    /* reintegrate oa */
415 #define OBD_MD_FID      (0x0000000080000000LL)    /* lustre_id data */
416 #define OBD_MD_MEA      (0x0000000100000000LL)    /* shows we are interested in MEA */
417 #define OBD_MD_FLEALIST (0x0000000200000000LL)    /* list extended attributes */
418 #define OBD_MD_FLACL_ACCESS (0x0000000400000000LL) /* access acl */
419 #define OBD_MD_RACL     (0x0000000800000000LL)    /* remote acl */
420
421 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLBLOCKS | OBD_MD_LINKNAME |          \
422                            OBD_MD_FLEASIZE | OBD_MD_FLHANDLE |          \
423                            OBD_MD_FLCKSUM | OBD_MD_FLQOS |              \
424                            OBD_MD_FLOSCOPQ | OBD_MD_FLCOOKIE |          \
425                            OBD_MD_FLEA | OBD_MD_FLEALIST |              \
426                            OBD_MD_FLACL_ACCESS | OBD_MD_MDS))
427
428 static inline struct lustre_handle *obdo_handle(struct obdo *oa)
429 {
430         return (struct lustre_handle *)oa->o_inline;
431 }
432
433 static inline struct llog_cookie *obdo_logcookie(struct obdo *oa)
434 {
435         return (struct llog_cookie *)(oa->o_inline +
436                                       sizeof(struct lustre_handle));
437 }
438
439 /* don't forget obdo_fid which is way down at the bottom so it can come after
440  * the definition of llog_cookie */
441 struct obd_statfs {
442         __u64           os_type;
443         __u64           os_blocks;
444         __u64           os_bfree;
445         __u64           os_bavail;
446         __u64           os_files;
447         __u64           os_ffree;
448         __u8            os_fsid[40];
449         __u32           os_bsize;
450         __u32           os_namelen;
451         __u64           os_maxbytes;
452         __u32           os_spare[10];
453 };
454
455 extern void lustre_swab_obd_statfs (struct obd_statfs *os);
456
457 /* ost_body.data values for OST_BRW */
458
459 #define OBD_BRW_READ       0x01
460 #define OBD_BRW_WRITE      0x02
461 #define OBD_BRW_RWMASK     (OBD_BRW_READ | OBD_BRW_WRITE)
462 #define OBD_BRW_SYNC       0x08
463 #define OBD_BRW_CHECK      0x10
464 #define OBD_BRW_FROM_GRANT 0x20 /* the osc manages this under llite */
465 #define OBD_BRW_GRANTED    0x40 /* the ost manages this */
466
467 #define OBD_OBJECT_EOF     0xffffffffffffffffULL
468
469 struct obd_ioobj {
470         obd_id               ioo_id;
471         obd_gr               ioo_gr;
472         __u32                ioo_type;
473         __u32                ioo_bufcnt;
474 };
475
476 extern void lustre_swab_obd_ioobj (struct obd_ioobj *ioo);
477
478 /* multiple of 8 bytes => can array */
479 struct niobuf_remote {
480         __u64 offset;
481         __u32 len;
482         __u32 flags;
483 };
484
485 extern void lustre_swab_niobuf_remote (struct niobuf_remote *nbr);
486
487 /* request structure for OST's */
488
489 #define OST_REQ_HAS_OA1  0x1
490
491 struct ost_body {
492         struct  obdo oa;
493 };
494
495 extern void lustre_swab_ost_body (struct ost_body *b);
496 extern void lustre_swab_ost_last_id(obd_id *id);
497 extern void lustre_swab_generic_32s(__u32 *val);
498
499 /* lock value block communicated between the filter and llite */
500
501 struct ost_lvb {
502         __u64 lvb_size;
503         __u64 lvb_mtime;
504         __u64 lvb_atime;
505         __u64 lvb_ctime;
506         __u64 lvb_blocks;
507 };
508
509 extern void lustre_swab_ost_lvb(struct ost_lvb *);
510
511 /*
512  *   MDS REQ RECORDS
513  */
514
515 /* offsets in the request */
516 #define MDS_REQ_SECDESC_OFF             0
517 #define MDS_REQ_REC_OFF                 1
518
519 #define MDS_REQ_INTENT_LOCKREQ_OFF      1
520 #define MDS_REQ_INTENT_IT_OFF           2
521 #define MDS_REQ_INTENT_REC_OFF          3
522
523 /* maximum supplementary groups */
524 #define LUSTRE_MAX_GROUPS               128
525
526 /* 
527  * security descriptor in mds request
528  */
529 struct mds_req_sec_desc {
530         __u32           rsd_uid;
531         __u32           rsd_gid;
532         __u32           rsd_fsuid;
533         __u32           rsd_fsgid;
534         __u32           rsd_cap;
535         __u32           rsd_ngroups;
536         __u32           rsd_groups[0];
537 };
538
539 struct ptlrpc_request;
540 struct mds_req_sec_desc *lustre_swab_mds_secdesc(struct ptlrpc_request *req,
541                                                  int offset);
542
543 /* opcodes */
544 typedef enum {
545         MDS_GETATTR      = 33,
546         MDS_GETATTR_LOCK = 34,
547         MDS_CLOSE        = 35,
548         MDS_REINT        = 36,
549         MDS_READPAGE     = 37,
550         MDS_CONNECT      = 38,
551         MDS_DISCONNECT   = 39,
552         MDS_GETSTATUS    = 40,
553         MDS_STATFS       = 41,
554         MDS_PIN          = 42,
555         MDS_UNPIN        = 43,
556         MDS_SYNC         = 44,
557         MDS_DONE_WRITING = 45,
558         MDS_ACCESS_CHECK = 46,
559         MDS_LAST_OPC
560 } mds_cmd_t;
561
562 #define MDS_FIRST_OPC    MDS_GETATTR
563
564 /*
565  * Do not exceed 63
566  */
567
568 #define REINT_SETATTR      1
569 #define REINT_CREATE       2
570 #define REINT_LINK         3
571 #define REINT_UNLINK       4
572 #define REINT_RENAME       5
573 #define REINT_SETXATTR     6 
574 #define REINT_OPEN         7 
575 #define REINT_CLOSE        8 
576 #define REINT_WRITE        9 
577 #define REINT_MAX          9 
578
579 /* the disposition of the intent outlines what was executed */
580 #define DISP_IT_EXECD     (1 << 0)
581 #define DISP_LOOKUP_EXECD (1 << 1)
582 #define DISP_LOOKUP_NEG   (1 << 2)
583 #define DISP_LOOKUP_POS   (1 << 3)
584 #define DISP_OPEN_CREATE  (1 << 4)
585 #define DISP_OPEN_OPEN    (1 << 5)
586 #define DISP_ENQ_COMPLETE (1 << 6)
587
588 /* INODE LOCK PARTS */
589 #define MDS_INODELOCK_LOOKUP 0x000001  /* dentry, mode, owner, group */
590 #define MDS_INODELOCK_UPDATE 0x000002  /* size, links, timestamps */
591 #define MDS_INODELOCK_OPEN   0x000004  /* for opened files */
592
593 /* do not forget to increase MDS_INODELOCK_MAXSHIFT when adding new bits */
594 #define MDS_INODELOCK_MAXSHIFT 2
595
596 /* this FULL lock is useful to take on unlink sort of operations */
597 #define MDS_INODELOCK_FULL ((1 << (MDS_INODELOCK_MAXSHIFT + 1)) - 1)
598
599 /* lustre store cookie */
600 struct lustre_stc {
601         union {
602                 struct {
603                     __u64 l3s_ino;     /* inode number on local MDS */
604                     __u32 l3s_gen;     /* inode generation */
605                     __u32 l3s_type;    /* inode type */
606                 } e3s;
607         } u;
608 };
609
610 /* lustre file id */
611 struct lustre_fid {
612         __u64 lf_id;                   /* fid counter maintained on per 
613                                           group basis */
614         __u64 lf_group;                /* sequence group num */
615 #if 0
616         __u32 lf_version;              /* what snapfs version of inode */
617         __u32 lf_padding;
618 #endif
619 };
620
621 struct lustre_id {
622         struct lustre_stc li_stc;      /* store cookie */
623         struct lustre_fid li_fid;      /* fid cookie */
624 };
625
626 struct mea_old {
627         __u32 mea_count;
628         __u32 mea_master;
629         struct lustre_id mea_ids[0];
630 };
631
632 #define MEA_MAGIC_LAST_CHAR      0xb2221ca1
633 #define MEA_MAGIC_ALL_CHARS      0xb222a11c
634
635 struct mea {
636         __u32 mea_magic;
637         __u32 mea_count;
638         __u32 mea_master;
639         struct lustre_id mea_ids[0];
640 };
641
642 #define MDS_STATUS_CONN 1
643 #define MDS_STATUS_LOV 2
644
645 struct mds_status_req {
646         __u32  flags;
647         __u32  repbuf;
648 };
649
650 #define MDS_BFLAG_UNCOMMITTED_WRITES   0x1
651
652 struct mds_body {
653         struct lustre_id id1;
654         struct lustre_id id2;
655         struct lustre_handle handle;
656         __u64          size;   /* Offset, in the case of MDS_READPAGE */
657         __u64          blocks; /* XID, in the case of MDS_READPAGE */
658         __u64          io_epoch;
659         __u64          valid;
660         __u32          mode;
661         __u32          uid;
662         __u32          gid;
663         __u32          mtime;
664         __u32          ctime;
665         __u32          atime;
666         __u32          flags;  /* from vfs for pin/unpin, MDS_BFLAG for close */
667         __u32          rdev;
668         __u32          nlink;  /* #bytes to read in the case of MDS_READPAGE */
669         __u32          eadatasize;
670 };
671
672 extern void lustre_swab_mds_body (struct mds_body *b);
673
674 struct mds_remote_perm {
675         __u32           mrp_auth_uid;
676         __u32           mrp_auth_gid;
677         __u16           mrp_perm;
678         __u8            mrp_allow_setuid;
679         __u8            mrp_allow_setgid;
680 };
681
682 struct lustre_md {
683         struct mds_body        *body;
684         struct lov_stripe_md   *lsm;
685         struct mea             *mea;
686         struct posix_acl       *posix_acl;
687         struct mds_remote_perm *remote_perm;
688 };
689
690 void lustre_swab_remote_perm(struct mds_remote_perm *p);
691
692 struct mdc_op_data {
693         struct lustre_id id1;
694         struct lustre_id id2;
695         __u64            mod_time;
696         const char      *name;
697         int              namelen;
698         __u32            create_mode;
699         struct mea      *mea1;       /* mea of inode1 */
700         struct mea      *mea2;       /* mea of inode2 */
701         __u64            valid;
702 };
703
704 #define MDS_MODE_DONT_LOCK      (1 << 30)
705 #define MDS_MODE_REPLAY         (1 << 31)
706
707 struct mds_rec_setattr {
708         __u32            sa_opcode;
709         __u32            sa_valid;
710         struct lustre_id sa_id;
711         __u32            sa_mode;
712         __u32            sa_uid;
713         __u32            sa_gid;
714         __u32            sa_attr_flags;
715         __u64            sa_size;
716         __u64            sa_atime;
717         __u64            sa_mtime;
718         __u64            sa_ctime;
719 };
720
721 /* XXX Following ATTR_XXX should go to vfs patch...  */
722 #ifdef ATTR_CTIME_SET
723 #error "ATTR_CTIME_SET has been defined somewhere else"
724 #endif
725 #ifdef ATTR_EA
726 #error "ATTR_EA has been defined somewhere else"
727 #endif
728 #ifdef ATTR_EA_RM
729 #error "ATTR_EA_RM has been defined somewhere else"
730 #endif
731
732 #define ATTR_CTIME_SET  0x00002000
733 #define ATTR_EA         0x00040000
734 #define ATTR_EA_RM      0x00080000
735 #define ATTR_EA_CMOBD   0x00100000
736 extern void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa);
737
738 #ifndef FMODE_READ
739 #define FMODE_READ               00000001
740 #define FMODE_WRITE              00000002
741 #endif
742 #ifndef FMODE_EXEC
743 #define FMODE_EXEC               00000004
744 #endif
745 #define MDS_OPEN_CREAT           00000100
746 #define MDS_OPEN_EXCL            00000200
747 #define MDS_OPEN_TRUNC           00001000
748 #define MDS_OPEN_APPEND          00002000
749 #define MDS_OPEN_SYNC            00010000
750 #define MDS_OPEN_DIRECTORY       00200000
751
752 #define MDS_OPEN_DELAY_CREATE    0100000000   /* delay initial object create */
753 #define MDS_OPEN_HAS_EA          010000000000 /* specify object create pattern */
754 #define MDS_OPEN_HAS_OBJS        020000000000 /* just set the EA the obj exist */
755
756 struct mds_rec_create {
757         __u32            cr_opcode;
758         __u32            cr_flags; /* for use with open */
759         __u32            cr_mode;
760         __u32            cr_padding;
761         struct lustre_id cr_id;
762         struct lustre_id cr_replayid;
763         __u64            cr_time;
764         __u64            cr_rdev;
765 };
766
767 extern void lustre_swab_mds_rec_create (struct mds_rec_create *cr);
768
769 struct mds_rec_link {
770         __u32            lk_opcode;
771         __u32            lk_padding;
772         struct lustre_id lk_id1;
773         struct lustre_id lk_id2;
774         __u64            lk_time;
775 };
776
777 extern void lustre_swab_mds_rec_link (struct mds_rec_link *lk);
778
779 struct mds_rec_unlink {
780         __u32            ul_opcode;
781         __u32            ul_mode;
782         struct lustre_id ul_id1;
783         struct lustre_id ul_id2;
784         __u64            ul_time;
785 };
786
787 extern void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul);
788
789 struct mds_rec_rename {
790         __u32            rn_opcode;
791         __u32            rn_padding;
792         struct lustre_id rn_id1;
793         struct lustre_id rn_id2;
794         __u64            rn_time;
795 };
796
797 extern void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn);
798
799 /*
800  *  LOV data structures
801  */
802
803 #define LOV_MAX_UUID_BUFFER_SIZE  8192
804 /* The size of the buffer the lov/mdc reserves for the
805  * array of UUIDs returned by the MDS.  With the current
806  * protocol, this will limit the max number of OSTs per LOV */
807
808 struct lov_desc {
809         __u32 ld_tgt_count;                /* how many OBD's */
810         __u32 ld_active_tgt_count;         /* how many active */
811         __u32 ld_default_stripe_count;     /* how many objects are used */
812         __u32 ld_pattern;                  /* PATTERN_RAID0, PATTERN_RAID1 */
813         __u64 ld_default_stripe_size;      /* in bytes */
814         __u64 ld_default_stripe_offset;    /* in bytes */
815         struct obd_uuid ld_uuid;
816 };
817
818 struct lmv_desc {
819         __u32 ld_tgt_count;                /* how many MDS's */
820         __u32 ld_active_tgt_count;         /* how many active */
821         struct obd_uuid ld_uuid;
822 };
823
824 /*
825  *   LDLM requests:
826  */
827 /* opcodes -- MUST be distinct from OST/MDS opcodes */
828 typedef enum {
829         LDLM_ENQUEUE     = 101,
830         LDLM_CONVERT     = 102,
831         LDLM_CANCEL      = 103,
832         LDLM_BL_CALLBACK = 104,
833         LDLM_CP_CALLBACK = 105,
834         LDLM_GL_CALLBACK = 106,
835         LDLM_LAST_OPC
836 } ldlm_cmd_t;
837 #define LDLM_FIRST_OPC LDLM_ENQUEUE
838
839 #define RES_NAME_SIZE 4
840 struct ldlm_res_id {
841         __u64 name[RES_NAME_SIZE];
842 };
843
844 extern void lustre_swab_ldlm_res_id (struct ldlm_res_id *id);
845
846 /* lock types */
847 typedef enum {
848         LCK_EX = 1,
849         LCK_PW = 2,
850         LCK_PR = 4,
851         LCK_CW = 8,
852         LCK_CR = 16,
853         LCK_NL = 32,
854         LCK_GROUP = 64
855 } ldlm_mode_t;
856
857 struct ldlm_extent {
858         __u64 start;
859         __u64 end;
860         __u64 gid;
861 };
862 struct ldlm_inodebits {
863         __u64 bits;
864 };
865
866 struct ldlm_flock {
867         __u64 start;
868         __u64 end;
869         __u64 pid;
870         __u64 blocking_pid;
871         __u64 blocking_export;
872 };
873
874 /* it's important that the fields of the ldlm_extent structure match
875  * the first fields of the ldlm_flock structure because there is only
876  * one ldlm_swab routine to process the ldlm_policy_data_t union. if
877  * this ever changes we will need to swab the union differently based
878  * on the resource type. */
879
880 typedef union {
881         struct ldlm_extent l_extent;
882         struct ldlm_flock  l_flock;
883         struct ldlm_inodebits l_inodebits;
884 } ldlm_policy_data_t;
885
886 extern void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d);
887
888 struct ldlm_intent {
889         __u64 opc;
890 };
891
892 extern void lustre_swab_ldlm_intent (struct ldlm_intent *i);
893
894 struct ldlm_resource_desc {
895         __u32 lr_type;
896         __u32 lr_padding;
897         struct ldlm_res_id lr_name;
898 };
899
900 extern void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r);
901
902 struct ldlm_lock_desc {
903         struct ldlm_resource_desc l_resource;
904         ldlm_mode_t l_req_mode;
905         ldlm_mode_t l_granted_mode;
906         ldlm_policy_data_t l_policy_data;
907 };
908
909 extern void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l);
910
911 struct ldlm_request {
912         __u32 lock_flags;
913         __u32 lock_padding;
914         struct ldlm_lock_desc lock_desc;
915         struct lustre_handle lock_handle1;
916         struct lustre_handle lock_handle2;
917 };
918
919 extern void lustre_swab_ldlm_request (struct ldlm_request *rq);
920
921 struct ldlm_reply {
922         __u32 lock_flags;
923         __u32 lock_padding;
924         struct ldlm_lock_desc lock_desc;
925         struct lustre_handle lock_handle;
926         __u64  lock_policy_res1;
927         __u64  lock_policy_res2;
928 };
929
930 extern void lustre_swab_ldlm_reply (struct ldlm_reply *r);
931
932 /*
933  * ptlbd, portal block device requests
934  */
935 typedef enum {
936         PTLBD_QUERY      = 200,
937         PTLBD_READ       = 201,
938         PTLBD_WRITE      = 202,
939         PTLBD_FLUSH      = 203,
940         PTLBD_CONNECT    = 204,
941         PTLBD_DISCONNECT = 205,
942         PTLBD_LAST_OPC
943 } ptlbd_cmd_t;
944 #define PTLBD_FIRST_OPC PTLBD_QUERY
945
946 struct ptlbd_op {
947         __u16 op_cmd;
948         __u16 op_lun;
949         __u16 op_niob_cnt;
950         __u16 op__padding;
951         __u32 op_block_cnt;
952 };
953
954 extern void lustre_swab_ptlbd_op (struct ptlbd_op *op);
955
956 struct ptlbd_niob {
957         __u64 n_xid;
958         __u64 n_block_nr;
959         __u32 n_offset;
960         __u32 n_length;
961 };
962
963 extern void lustre_swab_ptlbd_niob (struct ptlbd_niob *n);
964
965 struct ptlbd_rsp {
966         __u16 r_status;
967         __u16 r_error_cnt;
968 };
969
970 extern void lustre_swab_ptlbd_rsp (struct ptlbd_rsp *r);
971
972 /*
973  * Opcodes for management/monitoring node.
974  */
975 typedef enum {
976         MGMT_CONNECT = 250,
977         MGMT_DISCONNECT,
978         MGMT_EXCEPTION,         /* node died, etc. */
979         MGMT_LAST_OPC
980 } mgmt_cmd_t;
981 #define MGMT_FIRST_OPC MGMT_CONNECT
982
983 /*
984  * Opcodes for multiple servers.
985  */
986
987 typedef enum {
988         OBD_PING = 400,
989         OBD_LOG_CANCEL,
990         OBD_LAST_OPC
991 } obd_cmd_t;
992 #define OBD_FIRST_OPC OBD_PING
993
994 /* catalog of log objects */
995
996 /* Identifier for a single log object */
997 struct llog_logid {
998         __u64                   lgl_oid;
999         __u64                   lgl_ogr;
1000         __u32                   lgl_ogen;
1001 } __attribute__((packed));
1002
1003 /* Records written to the CATALOGS list */
1004 #define CATLIST "CATALOGS"
1005 struct llog_catid {
1006         struct llog_logid       lci_logid;
1007         __u32                   lci_padding[3];
1008 } __attribute__((packed));
1009
1010 /* Log data record types - there is no specific reason that these need to
1011  * be related to the RPC opcodes, but no reason not to (may be handy later?)
1012  */
1013 typedef enum {
1014         OST_SZ_REC       = 0x10600000 | (OST_SAN_WRITE << 8),
1015         OST_RAID1_REC    = 0x10600000 | ((OST_SAN_WRITE + 1) << 8),
1016         MDS_UNLINK_REC   = 0x10610000 | (MDS_REINT << 8) | REINT_UNLINK,
1017         OBD_CFG_REC      = 0x10620000,
1018         PTL_CFG_REC      = 0x10630000,
1019         LLOG_GEN_REC     = 0x10640000,
1020         LLOG_HDR_MAGIC   = 0x10645539,
1021         LLOG_LOGID_MAGIC = 0x1064553b,
1022         SMFS_UPDATE_REC  = 0x10650000,
1023         CACHE_LRU_REC    = 0x10660000,
1024 } llog_op_type;
1025
1026 /* Log record header - stored in little endian order.
1027  * Each record must start with this struct, end with a llog_rec_tail,
1028  * and be a multiple of 256 bits in size.
1029  */
1030 struct llog_rec_hdr {
1031         __u32                   lrh_len;
1032         __u32                   lrh_index;
1033         __u32                   lrh_type;
1034         __u32                   padding;
1035 };
1036
1037 struct llog_rec_tail {
1038         __u32 lrt_len;
1039         __u32 lrt_index;
1040 };
1041
1042 struct llog_logid_rec {
1043         struct llog_rec_hdr     lid_hdr;
1044         struct llog_logid       lid_id;
1045         __u32                   padding[5];
1046         struct llog_rec_tail    lid_tail;
1047 } __attribute__((packed));
1048
1049 struct llog_create_rec {
1050         struct llog_rec_hdr     lcr_hdr;
1051         struct lustre_id        lcr_id;
1052         obd_id                  lcr_oid;
1053         obd_count               lcr_ogen;
1054         __u32                   padding;
1055         struct llog_rec_tail    lcr_tail;
1056 } __attribute__((packed));
1057
1058 struct llog_orphan_rec {
1059         struct llog_rec_hdr     lor_hdr;
1060         obd_id                  lor_oid;
1061         obd_count               lor_ogen;
1062         __u32                   padding;
1063         struct llog_rec_tail    lor_tail;
1064 } __attribute__((packed));
1065
1066 struct llog_unlink_rec {
1067         struct llog_rec_hdr     lur_hdr;
1068         obd_id                  lur_oid;
1069         obd_count               lur_ogen;
1070         __u32                   padding;
1071         struct llog_rec_tail    lur_tail;
1072 } __attribute__((packed));
1073
1074 struct llog_size_change_rec {
1075         struct llog_rec_hdr     lsc_hdr;
1076         struct lustre_id        lsc_id;
1077         __u32                   lsc_io_epoch;
1078         __u32                   padding;
1079         struct llog_rec_tail    lsc_tail;
1080 } __attribute__((packed));
1081
1082 struct llog_gen {
1083         __u64 mnt_cnt;
1084         __u64 conn_cnt;
1085 };
1086
1087 struct llog_gen_rec {
1088         struct llog_rec_hdr     lgr_hdr;
1089         struct llog_gen         lgr_gen;
1090         struct llog_rec_tail    lgr_tail;
1091 } __attribute__((packed));
1092
1093 struct llog_lru_rec {
1094         struct llog_rec_hdr     llr_hdr;
1095         struct lustre_id        llr_cid;
1096         struct lustre_id        llr_pid;
1097         struct llog_rec_tail    llr_tail;
1098 } __attribute__((packed));
1099
1100 /* On-disk header structure of each log object, stored in little endian order */
1101 #define LLOG_CHUNK_SIZE         8192
1102 #define LLOG_HEADER_SIZE        (96)
1103 #define LLOG_BITMAP_BYTES       (LLOG_CHUNK_SIZE - LLOG_HEADER_SIZE)
1104
1105 #define LLOG_MIN_REC_SIZE       (24) /* round(llog_rec_hdr + llog_rec_tail) */
1106
1107 /* flags for the logs */
1108 #define LLOG_F_ZAP_WHEN_EMPTY   0x1
1109 #define LLOG_F_IS_CAT           0x2
1110 #define LLOG_F_IS_PLAIN         0x4
1111
1112 struct llog_log_hdr {
1113         struct llog_rec_hdr     llh_hdr;
1114         __u64                   llh_timestamp;
1115         __u32                   llh_count;
1116         __u32                   llh_bitmap_offset;
1117         __u32                   llh_size;
1118         __u32                   llh_flags;
1119         __u32                   llh_cat_idx;
1120         /* for a catalog the first plain slot is next to it */
1121         struct obd_uuid         llh_tgtuuid;
1122         __u32                 llh_reserved[LLOG_HEADER_SIZE/sizeof(__u32) - 23];
1123         __u32                   llh_bitmap[LLOG_BITMAP_BYTES/sizeof(__u32)];
1124         struct llog_rec_tail    llh_tail;
1125 } __attribute__((packed));
1126
1127 #define LLOG_BITMAP_SIZE(llh)  ((llh->llh_hdr.lrh_len -         \
1128                                  llh->llh_bitmap_offset -       \
1129                                  sizeof(llh->llh_tail)) * 8)
1130
1131 /* log cookies are used to reference a specific log file and a record therein */
1132 struct llog_cookie {
1133         struct llog_logid       lgc_lgl;
1134         __u32                   lgc_subsys;
1135         __u32                   lgc_index;
1136         __u32                   lgc_flags;
1137 } __attribute__((packed));
1138
1139 /* llog protocol */
1140 enum llogd_rpc_ops {
1141         LLOG_ORIGIN_HANDLE_OPEN         = 501,
1142         LLOG_ORIGIN_HANDLE_NEXT_BLOCK   = 502,
1143         LLOG_ORIGIN_HANDLE_READ_HEADER  = 503,
1144         LLOG_ORIGIN_HANDLE_WRITE_REC    = 504,
1145         LLOG_ORIGIN_HANDLE_CLOSE        = 505,
1146         LLOG_ORIGIN_CONNECT             = 506,
1147         LLOG_CATINFO                    = 507,  /* for lfs catinfo */
1148         LLOG_ORIGIN_HANDLE_PREV_BLOCK   = 508,
1149 };
1150
1151 struct llogd_body {
1152         struct llog_logid  lgd_logid;
1153         __u32 lgd_ctxt_idx;
1154         __u32 lgd_llh_flags;
1155         __u32 lgd_index;
1156         __u32 lgd_saved_index;
1157         __u32 lgd_len;
1158         __u64 lgd_cur_offset;
1159 } __attribute__((packed));
1160
1161 struct llogd_conn_body {
1162         struct llog_gen         lgdc_gen;
1163         struct llog_logid       lgdc_logid;
1164         __u32                   lgdc_ctxt_idx;
1165 } __attribute__((packed));
1166
1167 extern void lustre_swab_llogd_body (struct llogd_body *d);
1168 extern void lustre_swab_llog_hdr (struct llog_log_hdr *h);
1169 extern void lustre_swab_llogd_conn_body (struct llogd_conn_body *d);
1170
1171 struct lustre_cfg;
1172 extern void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg);
1173
1174 static inline struct lustre_id *obdo_id(struct obdo *oa)
1175 {
1176         void *raw_id = oa->o_inline + sizeof(struct lustre_handle) +
1177                 sizeof(struct llog_cookie);
1178         
1179         return (struct lustre_id *)raw_id;
1180 }
1181
1182 /* security negotiate */
1183 typedef enum {
1184         SEC_INIT                = 600,
1185         SEC_INIT_CONTINUE       = 601,
1186         SEC_FINI                = 602,
1187         SEC_LAST_OPC
1188 } sec_cmd_t;
1189 #define SEC_FIRST_OPC SEC_INIT
1190
1191 extern void lustre_swab_lustre_id(struct lustre_id *id);
1192 extern void lustre_swab_lov_desc(struct lov_desc *desc);
1193 extern void lustre_swab_lustre_stc(struct lustre_stc *stc);
1194 extern void lustre_swab_lustre_fid(struct lustre_fid *fid);
1195 extern void lustre_swab_mds_status_req(struct mds_status_req *r);
1196
1197 #endif