Whamcloud - gitweb
149610bd41d4bad45d34ee929cd3dda1d07063a6
[fs/lustre-release.git] / lustre / include / lustre / 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.  Structs
9  * that are used in interfaces with userspace should go in lustre_user.h.
10  *
11  * All structs being declared here should be built from simple fixed-size
12  * types (__u8, __u16, __u32, __u64) or be built from other types or
13  * structs also declared in this file.  Similarly, all flags and magic
14  * values in those structs should also be declared here.  This ensures
15  * that the Lustre wire protocol is not influenced by external dependencies.
16  *
17  * The only other acceptable items in this file are VERY SIMPLE accessor
18  * functions to avoid callers grubbing inside the structures, and the
19  * prototypes of the swabber functions for each struct.  Nothing that
20  * depends on external functions or definitions should be in here.
21  *
22  * Structs must be properly aligned to put 64-bit values on an 8-byte
23  * boundary.  Any structs being added here must also be added to
24  * utils/wirecheck.c and "make newwiretest" run to regenerate the
25  * utils/wiretest.c sources.  This allows us to verify that wire structs
26  * have the proper alignment/size on all architectures.
27  *
28  * DO NOT CHANGE any of the structs, flags, values declared here and used
29  * in released Lustre versions.  Some structs may have padding fields that
30  * can be used.  Some structs might allow addition at the end (verify this
31  * in the code to ensure that new/old clients that see this larger struct
32  * do not fail, otherwise you need to implement protocol compatibility).
33  *
34  * We assume all nodes are either little-endian or big-endian, and we
35  * always send messages in the sender's native format.  The receiver
36  * detects the message format by checking the 'magic' field of the message
37  * (see lustre_msg_swabbed() below).
38  *
39  * Each wire type has corresponding 'lustre_swab_xxxtypexxx()' routines,
40  * implemented either here, inline (trivial implementations) or in
41  * ptlrpc/pack_generic.c.  These 'swabbers' convert the type from "other"
42  * endian, in-place in the message buffer.
43  *
44  * A swabber takes a single pointer argument.  The caller must already have
45  * verified that the length of the message buffer >= sizeof (type).
46  *
47  * For variable length types, a second 'lustre_swab_v_xxxtypexxx()' routine
48  * may be defined that swabs just the variable part, after the caller has
49  * verified that the message buffer is large enough.
50  */
51
52 #ifndef _LUSTRE_IDL_H_
53 #define _LUSTRE_IDL_H_
54
55 #if defined(__linux__)
56 #include <linux/lustre_types.h>
57 #elif defined(__APPLE__)
58 #include <darwin/lustre_types.h>
59 #elif defined(__WINNT__)
60 #include <winnt/lustre_types.h>
61 #else
62 #error Unsupported operating system.
63 #endif
64
65 /* Defn's shared with user-space. */
66 #include <lustre/lustre_user.h>
67
68 /*
69  * this file contains all data structures used in Lustre interfaces:
70  * - obdo and obd_request records
71  * - mds_request records
72  * - ldlm data
73  * - ioctl's
74  */
75
76 /*
77  *  GENERAL STUFF
78  */
79 /* FOO_REQUEST_PORTAL is for incoming requests on the FOO
80  * FOO_REPLY_PORTAL   is for incoming replies on the FOO
81  * FOO_BULK_PORTAL    is for incoming bulk on the FOO
82  */
83
84 #define CONNMGR_REQUEST_PORTAL          1
85 #define CONNMGR_REPLY_PORTAL            2
86 //#define OSC_REQUEST_PORTAL            3
87 #define OSC_REPLY_PORTAL                4
88 //#define OSC_BULK_PORTAL               5
89 #define OST_IO_PORTAL                   6
90 #define OST_CREATE_PORTAL               7
91 #define OST_BULK_PORTAL                 8
92 //#define MDC_REQUEST_PORTAL            9
93 #define MDC_REPLY_PORTAL               10
94 //#define MDC_BULK_PORTAL              11
95 #define MDS_REQUEST_PORTAL             12
96 //#define MDS_REPLY_PORTAL             13
97 #define MDS_BULK_PORTAL                14
98 #define LDLM_CB_REQUEST_PORTAL         15
99 #define LDLM_CB_REPLY_PORTAL           16
100 #define LDLM_CANCEL_REQUEST_PORTAL     17
101 #define LDLM_CANCEL_REPLY_PORTAL       18
102 //#define PTLBD_REQUEST_PORTAL           19
103 //#define PTLBD_REPLY_PORTAL             20
104 //#define PTLBD_BULK_PORTAL              21
105 #define MDS_SETATTR_PORTAL             22
106 #define MDS_READPAGE_PORTAL            23
107
108 #define MGC_REPLY_PORTAL               25
109 #define MGS_REQUEST_PORTAL             26
110 #define MGS_REPLY_PORTAL               27
111 #define OST_REQUEST_PORTAL             28
112
113 #define SVC_KILLED               1
114 #define SVC_EVENT                2
115 #define SVC_SIGNAL               4
116 #define SVC_RUNNING              8
117 #define SVC_STOPPING            16
118 #define SVC_STOPPED             32
119
120 /* packet types */
121 #define PTL_RPC_MSG_REQUEST 4711
122 #define PTL_RPC_MSG_ERR     4712
123 #define PTL_RPC_MSG_REPLY   4713
124
125 /* DON'T use swabbed values of MAGIC as magic! */
126 #define LUSTRE_MSG_MAGIC_V1 0x0BD00BD0
127 #define LUSTRE_MSG_MAGIC_V2 0x0BD00BD3
128
129 #define LUSTRE_MSG_MAGIC_V1_SWABBED 0xD00BD00B
130 #define LUSTRE_MSG_MAGIC_V2_SWABBED 0xD30BD00B
131
132 #define LUSTRE_MSG_MAGIC LUSTRE_MSG_MAGIC_V2
133
134 #define PTLRPC_MSG_VERSION  0x00000003
135 #define LUSTRE_VERSION_MASK 0xffff0000
136 #define LUSTRE_OBD_VERSION  0x00010000
137 #define LUSTRE_MDS_VERSION  0x00020000
138 #define LUSTRE_OST_VERSION  0x00030000
139 #define LUSTRE_DLM_VERSION  0x00040000
140 #define LUSTRE_LOG_VERSION  0x00050000
141 #define LUSTRE_MGS_VERSION  0x00060000
142
143 struct lustre_handle {
144         __u64 cookie;
145 };
146 #define DEAD_HANDLE_MAGIC 0xdeadbeefcafebabeULL
147
148 static inline int lustre_handle_is_used(struct lustre_handle *lh)
149 {
150         return lh->cookie != 0ull;
151 }
152
153 static inline int lustre_handle_equal(struct lustre_handle *lh1,
154                                       struct lustre_handle *lh2)
155 {
156         return lh1->cookie == lh2->cookie;
157 }
158
159 static inline void lustre_handle_copy(struct lustre_handle *tgt,
160                                       struct lustre_handle *src)
161 {
162         tgt->cookie = src->cookie;
163 }
164
165 /* we depend on this structure to be 8-byte aligned */
166 /* this type is only endian-adjusted in lustre_unpack_msg() */
167 struct lustre_msg_v1 {
168         struct lustre_handle lm_handle;
169         __u32 lm_magic;
170         __u32 lm_type;
171         __u32 lm_version;
172         __u32 lm_opc;
173         __u64 lm_last_xid;
174         __u64 lm_last_committed;
175         __u64 lm_transno;
176         __u32 lm_status;
177         __u32 lm_flags;
178         __u32 lm_conn_cnt;
179         __u32 lm_bufcount;
180         __u32 lm_buflens[0];
181 };
182
183 #define lustre_msg lustre_msg_v2
184 /* we depend on this structure to be 8-byte aligned */
185 /* this type is only endian-adjusted in lustre_unpack_msg() */
186 struct lustre_msg_v2 {
187         __u32 lm_bufcount;
188         __u32 lm_secflvr;
189         __u32 lm_magic;
190         __u32 lm_repsize;
191         __u32 lm_timeout;
192         __u32 lm_padding_1;
193         __u32 lm_padding_2;
194         __u32 lm_padding_3;
195         __u32 lm_buflens[0];
196 };
197
198 /* without security, ptlrpc_body is put in the first buffer. */
199 struct ptlrpc_body {
200         struct lustre_handle pb_handle;
201         __u32 pb_type;
202         __u32 pb_version;
203         __u32 pb_opc;
204         __u32 pb_status;
205         __u64 pb_last_xid;
206         __u64 pb_last_seen;
207         __u64 pb_last_committed;
208         __u64 pb_transno;
209         __u32 pb_flags;
210         __u32 pb_op_flags;
211         __u32 pb_conn_cnt;
212         __u32 pb_padding_1;
213         __u32 pb_padding_2;
214         __u32 pb_padding_3;
215         __u32 pb_padding_4;
216         __u32 pb_padding_5;
217 };
218
219 extern void lustre_swab_ptlrpc_body(struct ptlrpc_body *pb);
220
221 /* message body offset for lustre_msg_v2 */
222 /* ptlrpc body offset in all request/reply messages */
223 #define MSG_PTLRPC_BODY_OFF             0
224
225 /* normal request/reply message record offset */
226 #define REQ_REC_OFF                     1
227 #define REPLY_REC_OFF                   1
228
229 /* ldlm request message body offset */
230 #define DLM_LOCKREQ_OFF                 1 /* lockreq offset */
231 #define DLM_REQ_REC_OFF                 2 /* normal dlm request record offset */
232
233 /* ldlm intent lock message body offset */
234 #define DLM_INTENT_IT_OFF               2 /* intent lock it offset */
235 #define DLM_INTENT_REC_OFF              3 /* intent lock record offset */
236
237 /* ldlm reply message body offset */
238 #define DLM_LOCKREPLY_OFF               1 /* lockrep offset */
239 #define DLM_REPLY_REC_OFF               2 /* reply record offset */
240
241 /* Flags that are operation-specific go in the top 16 bits. */
242 #define MSG_OP_FLAG_MASK   0xffff0000
243 #define MSG_OP_FLAG_SHIFT  16
244
245 /* Flags that apply to all requests are in the bottom 16 bits */
246 #define MSG_GEN_FLAG_MASK      0x0000ffff
247 #define MSG_LAST_REPLAY        1
248 #define MSG_RESENT             2
249 #define MSG_REPLAY             4
250
251 /*
252  * Flags for all connect opcodes (MDS_CONNECT, OST_CONNECT)
253  */
254
255 #define MSG_CONNECT_RECOVERING  0x1
256 #define MSG_CONNECT_RECONNECT   0x2
257 #define MSG_CONNECT_REPLAYABLE  0x4
258 //#define MSG_CONNECT_PEER        0x8
259 #define MSG_CONNECT_LIBCLIENT   0x10
260 #define MSG_CONNECT_INITIAL     0x20
261 #define MSG_CONNECT_ASYNC       0x40
262 #define MSG_CONNECT_NEXT_VER    0x80 /* use next version of lustre_msg */
263
264 /* Connect flags */
265 #define OBD_CONNECT_RDONLY         0x1ULL /* client allowed read-only access */
266 #define OBD_CONNECT_INDEX          0x2ULL /* connect to specific LOV idx */
267 #define OBD_CONNECT_GRANT          0x8ULL /* OSC acquires grant at connect */
268 #define OBD_CONNECT_SRVLOCK       0x10ULL /* server takes locks for client */
269 #define OBD_CONNECT_VERSION       0x20ULL /* Server supports versions in ocd */
270 #define OBD_CONNECT_REQPORTAL     0x40ULL /* Separate portal for non-IO reqs */
271 #define OBD_CONNECT_ACL           0x80ULL /* client uses access control lists */
272 #define OBD_CONNECT_XATTR        0x100ULL /* client using extended attributes*/
273 #define OBD_CONNECT_CROW         0x200ULL /* MDS+OST create objects on write */
274 #define OBD_CONNECT_TRUNCLOCK    0x400ULL /* locks on server for punch b=9528 */
275 #define OBD_CONNECT_TRANSNO      0x800ULL /* replay sends initial transno */
276 #define OBD_CONNECT_IBITS       0x1000ULL /* support for inodebits locks */
277 #define OBD_CONNECT_JOIN        0x2000ULL /* files can be concatenated */
278 #define OBD_CONNECT_ATTRFID     0x4000ULL /* Server supports GetAttr By Fid */
279 #define OBD_CONNECT_NODEVOH     0x8000ULL /* No open handle for special nodes */
280 #define OBD_CONNECT_LCL_CLIENT 0x10000ULL /* local 1.8 client */
281 #define OBD_CONNECT_RMT_CLIENT 0x20000ULL /* Remote 1.8 client */
282 #define OBD_CONNECT_BRW_SIZE   0x40000ULL /* Max bytes per rpc */
283 #define OBD_CONNECT_QUOTA64    0x80000ULL /* 64bit qunit_data.qd_count b=10707*/
284 #define OBD_CONNECT_FID_CAPA  0x100000ULL /* fid capability */
285 #define OBD_CONNECT_OSS_CAPA  0x200000ULL /* OSS capability */
286 /* also update obd_connect_names[] for lprocfs_rd_connect_flags()
287  * and lustre/utils/wirecheck.c */
288
289 #define MDS_CONNECT_SUPPORTED  (OBD_CONNECT_RDONLY | OBD_CONNECT_VERSION | \
290                                 OBD_CONNECT_ACL | OBD_CONNECT_XATTR | \
291                                 OBD_CONNECT_IBITS | OBD_CONNECT_JOIN | \
292                                 OBD_CONNECT_NODEVOH | OBD_CONNECT_ATTRFID)
293 #define OST_CONNECT_SUPPORTED  (OBD_CONNECT_SRVLOCK | OBD_CONNECT_GRANT | \
294                                 OBD_CONNECT_REQPORTAL | OBD_CONNECT_VERSION | \
295                                 OBD_CONNECT_TRUNCLOCK | OBD_CONNECT_INDEX | \
296                                 OBD_CONNECT_BRW_SIZE | OBD_CONNECT_QUOTA64)
297 #define ECHO_CONNECT_SUPPORTED (0)
298 #define MGS_CONNECT_SUPPORTED  (OBD_CONNECT_VERSION)
299
300 #define MAX_QUOTA_COUNT32 ((0xffffffffULL >> QUOTABLOCK_BITS) << QUOTABLOCK_BITS)
301
302 #define OBD_OCD_VERSION(major,minor,patch,fix) (((major)<<24) + ((minor)<<16) +\
303                                                 ((patch)<<8) + (fix))
304 #define OBD_OCD_VERSION_MAJOR(version) ((int)((version)>>24)&255)
305 #define OBD_OCD_VERSION_MINOR(version) ((int)((version)>>16)&255)
306 #define OBD_OCD_VERSION_PATCH(version) ((int)((version)>>8)&255)
307 #define OBD_OCD_VERSION_FIX(version)   ((int)(version)&255)
308
309 /* This structure is used for both request and reply.
310  *
311  * If we eventually have separate connect data for different types, which we
312  * almost certainly will, then perhaps we stick a union in here. */
313 struct obd_connect_data {
314         __u64 ocd_connect_flags;        /* OBD_CONNECT_* per above */
315         __u32 ocd_version;              /* lustre release version number */
316         __u32 ocd_grant;                /* initial cache grant amount (bytes) */
317         __u32 ocd_index;                /* LOV index to connect to */
318         __u32 ocd_brw_size;             /* Maximum BRW size in bytes */
319         __u64 ocd_ibits_known;          /* inode bits this client understands */
320         __u32 ocd_nllu;                 /* non-local-lustre-user */
321         __u32 ocd_nllg;                 /* non-local-lustre-group */
322         __u64 padding1;                 /* also fix lustre_swab_connect */
323         __u64 padding2;                 /* also fix lustre_swab_connect */
324         __u64 padding3;                 /* also fix lustre_swab_connect */
325         __u64 padding4;                 /* also fix lustre_swab_connect */
326 };
327
328 extern void lustre_swab_connect(struct obd_connect_data *ocd);
329
330 /*
331  *   OST requests: OBDO & OBD request records
332  */
333
334 /* opcodes */
335 typedef enum {
336         OST_REPLY      =  0,       /* reply ? */
337         OST_GETATTR    =  1,
338         OST_SETATTR    =  2,
339         OST_READ       =  3,
340         OST_WRITE      =  4,
341         OST_CREATE     =  5,
342         OST_DESTROY    =  6,
343         OST_GET_INFO   =  7,
344         OST_CONNECT    =  8,
345         OST_DISCONNECT =  9,
346         OST_PUNCH      = 10,
347         OST_OPEN       = 11,
348         OST_CLOSE      = 12,
349         OST_STATFS     = 13,
350 /*      OST_SAN_READ   = 14,    deprecated */
351 /*      OST_SAN_WRITE  = 15,    deprecated */
352         OST_SYNC       = 16,
353         OST_SET_INFO   = 17,
354         OST_QUOTACHECK = 18,
355         OST_QUOTACTL   = 19,
356         OST_LAST_OPC
357 } ost_cmd_t;
358 #define OST_FIRST_OPC  OST_REPLY
359
360 typedef uint64_t        obd_id;
361 typedef uint64_t        obd_gr;
362 typedef uint64_t        obd_time;
363 typedef uint64_t        obd_size;
364 typedef uint64_t        obd_off;
365 typedef uint64_t        obd_blocks;
366 typedef uint32_t        obd_blksize;
367 typedef uint32_t        obd_mode;
368 typedef uint32_t        obd_uid;
369 typedef uint32_t        obd_gid;
370 typedef uint32_t        obd_flag;
371 typedef uint64_t        obd_valid;
372 typedef uint32_t        obd_count;
373
374 #define OBD_FL_INLINEDATA    (0x00000001)
375 #define OBD_FL_OBDMDEXISTS   (0x00000002)
376 #define OBD_FL_DELORPHAN     (0x00000004) /* if set in o_flags delete orphans */
377 #define OBD_FL_NORPC         (0x00000008) /* set in o_flags do in OSC not OST */
378 #define OBD_FL_IDONLY        (0x00000010) /* set in o_flags only adjust obj id*/
379 #define OBD_FL_RECREATE_OBJS (0x00000020) /* recreate missing obj */
380 #define OBD_FL_DEBUG_CHECK   (0x00000040) /* echo client/server debug check */
381 #define OBD_FL_NO_USRQUOTA   (0x00000100) /* the object's owner is over quota */
382 #define OBD_FL_NO_GRPQUOTA   (0x00000200) /* the object's group is over quota */
383 #define OBD_FL_CREATE_CROW   (0x00000400) /* object should be create on write */
384
385 /*
386  * set this to delegate DLM locking during obd_punch() to the OSTs. Only OSTs
387  * that declared OBD_CONNECT_TRUNCLOCK in their connect flags support this
388  * functionality.
389  */
390 #define OBD_FL_TRUNCLOCK     (0x00000800)
391
392 /* this should be not smaller than sizeof(struct lustre_handle) + sizeof(struct
393  * llog_cookie) + sizeof(ll_fid). Nevertheless struct ll_fid is not longer
394  * stored in o_inline, we keep this just for case. */
395 #define OBD_INLINESZ    80
396
397 /* Note: 64-bit types are 64-bit aligned in structure */
398 struct obdo {
399         obd_valid               o_valid;        /* hot fields in this obdo */
400         obd_id                  o_id;
401         obd_gr                  o_gr;
402         obd_id                  o_fid;
403         obd_size                o_size;         /* o_size-o_blocks == ost_lvb */
404         obd_time                o_mtime;
405         obd_time                o_atime;
406         obd_time                o_ctime;
407         obd_blocks              o_blocks;       /* brw: cli sent cached bytes */
408         obd_size                o_grant;
409
410         /* 32-bit fields start here: keep an even number of them via padding */
411         obd_blksize             o_blksize;      /* optimal IO blocksize */
412         obd_mode                o_mode;         /* brw: cli sent cache remain */
413         obd_uid                 o_uid;
414         obd_gid                 o_gid;
415         obd_flag                o_flags;
416         obd_count               o_nlink;        /* brw: checksum */
417         obd_count               o_generation;
418         obd_count               o_misc;         /* brw: o_dropped */
419         __u32                   o_easize;       /* epoch in ost writes */
420         __u32                   o_mds;
421         __u32                   o_stripe_idx;   /* holds stripe idx */
422         __u32                   o_padding_1;
423         char                    o_inline[OBD_INLINESZ];
424                                 /* lustre_handle + llog_cookie */
425 };
426
427 #define o_dirty   o_blocks
428 #define o_undirty o_mode
429 #define o_dropped o_misc
430 #define o_cksum   o_nlink
431
432 extern void lustre_swab_obdo (struct obdo *o);
433
434
435 #define LOV_MAGIC_V1      0x0BD10BD0
436 #define LOV_MAGIC         LOV_MAGIC_V1
437 #define LOV_MAGIC_JOIN    0x0BD20BD0
438
439 #define LOV_PATTERN_RAID0 0x001   /* stripes are used round-robin */
440 #define LOV_PATTERN_RAID1 0x002   /* stripes are mirrors of each other */
441 #define LOV_PATTERN_FIRST 0x100   /* first stripe is not in round-robin */
442 #define LOV_PATTERN_CMOBD 0x200
443
444 #define lov_ost_data lov_ost_data_v1
445 struct lov_ost_data_v1 {          /* per-stripe data structure (little-endian)*/
446         __u64 l_object_id;        /* OST object ID */
447         __u64 l_object_gr;        /* OST object group (creating MDS number) */
448         __u32 l_ost_gen;          /* generation of this l_ost_idx */
449         __u32 l_ost_idx;          /* OST index in LOV (lov_tgt_desc->tgts) */
450 };
451
452 #define lov_mds_md lov_mds_md_v1
453 struct lov_mds_md_v1 {            /* LOV EA mds/wire data (little-endian) */
454         __u32 lmm_magic;          /* magic number = LOV_MAGIC_V1 */
455         __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
456         __u64 lmm_object_id;      /* LOV object ID */
457         __u64 lmm_object_gr;      /* LOV object group */
458         __u32 lmm_stripe_size;    /* size of stripe in bytes */
459         __u32 lmm_stripe_count;   /* num stripes in use for this object */
460         struct lov_ost_data_v1 lmm_objects[0]; /* per-stripe data */
461 };
462
463 #define OBD_MD_FLID        (0x00000001ULL) /* object ID */
464 #define OBD_MD_FLATIME     (0x00000002ULL) /* access time */
465 #define OBD_MD_FLMTIME     (0x00000004ULL) /* data modification time */
466 #define OBD_MD_FLCTIME     (0x00000008ULL) /* change time */
467 #define OBD_MD_FLSIZE      (0x00000010ULL) /* size */
468 #define OBD_MD_FLBLOCKS    (0x00000020ULL) /* allocated blocks count */
469 #define OBD_MD_FLBLKSZ     (0x00000040ULL) /* block size */
470 #define OBD_MD_FLMODE      (0x00000080ULL) /* access bits (mode & ~S_IFMT) */
471 #define OBD_MD_FLTYPE      (0x00000100ULL) /* object type (mode & S_IFMT) */
472 #define OBD_MD_FLUID       (0x00000200ULL) /* user ID */
473 #define OBD_MD_FLGID       (0x00000400ULL) /* group ID */
474 #define OBD_MD_FLFLAGS     (0x00000800ULL) /* flags word */
475 #define OBD_MD_FLNLINK     (0x00002000ULL) /* link count */
476 #define OBD_MD_FLGENER     (0x00004000ULL) /* generation number */
477 #define OBD_MD_FLINLINE    (0x00008000ULL) /* inline data */
478 #define OBD_MD_FLRDEV      (0x00010000ULL) /* device number */
479 #define OBD_MD_FLEASIZE    (0x00020000ULL) /* extended attribute data */
480 #define OBD_MD_LINKNAME    (0x00040000ULL) /* symbolic link target */
481 #define OBD_MD_FLHANDLE    (0x00080000ULL) /* file handle */
482 #define OBD_MD_FLCKSUM     (0x00100000ULL) /* bulk data checksum */
483 #define OBD_MD_FLQOS       (0x00200000ULL) /* quality of service stats */
484 #define OBD_MD_FLOSCOPQ    (0x00400000ULL) /* osc opaque data */
485 #define OBD_MD_FLCOOKIE    (0x00800000ULL) /* log cancellation cookie */
486 #define OBD_MD_FLGROUP     (0x01000000ULL) /* group */
487 #define OBD_MD_FLFID       (0x02000000ULL) /* ->ost write inline fid */
488 #define OBD_MD_FLEPOCH     (0x04000000ULL) /* ->ost write easize is epoch */
489 #define OBD_MD_FLGRANT     (0x08000000ULL) /* ost preallocation space grant */
490 #define OBD_MD_FLDIREA     (0x10000000ULL) /* dir's extended attribute data */
491 #define OBD_MD_FLUSRQUOTA  (0x20000000ULL) /* over quota flags sent from ost */
492 #define OBD_MD_FLGRPQUOTA  (0x40000000ULL) /* over quota flags sent from ost */
493 #define OBD_MD_FLMODEASIZE (0x80000000ULL) /* EA size will be changed */
494
495 #define OBD_MD_MDS         (0x0000000100000000ULL) /* where an inode lives on */
496 #define OBD_MD_REINT       (0x0000000200000000ULL) /* reintegrate oa */
497
498 #define OBD_MD_FLXATTR     (0x0000001000000000ULL) /* xattr */
499 #define OBD_MD_FLXATTRLS   (0x0000002000000000ULL) /* xattr list */
500 #define OBD_MD_FLXATTRRM   (0x0000004000000000ULL) /* xattr remove */
501 #define OBD_MD_FLACL       (0x0000008000000000ULL) /* ACL */
502
503 #define OBD_MD_FLGETATTR (OBD_MD_FLID    | OBD_MD_FLATIME | OBD_MD_FLMTIME | \
504                           OBD_MD_FLCTIME | OBD_MD_FLSIZE  | OBD_MD_FLBLKSZ | \
505                           OBD_MD_FLMODE  | OBD_MD_FLTYPE  | OBD_MD_FLUID   | \
506                           OBD_MD_FLGID   | OBD_MD_FLFLAGS | OBD_MD_FLNLINK | \
507                           OBD_MD_FLGENER | OBD_MD_FLRDEV  | OBD_MD_FLGROUP)
508
509 static inline struct lustre_handle *obdo_handle(struct obdo *oa)
510 {
511         return (struct lustre_handle *)oa->o_inline;
512 }
513
514 static inline struct llog_cookie *obdo_logcookie(struct obdo *oa)
515 {
516         return (struct llog_cookie *)(oa->o_inline +
517                                       sizeof(struct lustre_handle));
518 }
519 /* don't forget obdo_fid which is way down at the bottom so it can
520  * come after the definition of llog_cookie */
521
522 struct obd_statfs {
523         __u64           os_type;
524         __u64           os_blocks;
525         __u64           os_bfree;
526         __u64           os_bavail;
527         __u64           os_files;
528         __u64           os_ffree;
529         __u8            os_fsid[40];
530         __u32           os_bsize;
531         __u32           os_namelen;
532         __u64           os_maxbytes;
533         __u32           os_state;       /* positive error code on server */
534         __u32           os_spare1;
535         __u32           os_spare2;
536         __u32           os_spare3;
537         __u32           os_spare4;
538         __u32           os_spare5;
539         __u32           os_spare6;
540         __u32           os_spare7;
541         __u32           os_spare8;
542         __u32           os_spare9;
543 };
544
545 extern void lustre_swab_obd_statfs (struct obd_statfs *os);
546
547 /* ost_body.data values for OST_BRW */
548
549 #define OBD_BRW_READ            0x01
550 #define OBD_BRW_WRITE           0x02
551 #define OBD_BRW_RWMASK          (OBD_BRW_READ | OBD_BRW_WRITE)
552 #define OBD_BRW_SYNC            0x08
553 #define OBD_BRW_CHECK           0x10
554 #define OBD_BRW_FROM_GRANT      0x20 /* the osc manages this under llite */
555 #define OBD_BRW_GRANTED         0x40 /* the ost manages this */
556 #define OBD_BRW_DROP            0x80 /* drop the page after IO */
557 #define OBD_BRW_NOQUOTA        0x100
558 #define OBD_BRW_SRVLOCK        0x200 /* Client holds no lock over this page */
559
560 #define OBD_OBJECT_EOF 0xffffffffffffffffULL
561
562 #define OST_MIN_PRECREATE 32
563 #define OST_MAX_PRECREATE 20000
564
565 struct obd_ioobj {
566         obd_id               ioo_id;
567         obd_gr               ioo_gr;
568         __u32                ioo_type;
569         __u32                ioo_bufcnt;
570 };
571
572 extern void lustre_swab_obd_ioobj (struct obd_ioobj *ioo);
573
574 /* multiple of 8 bytes => can array */
575 struct niobuf_remote {
576         __u64 offset;
577         __u32 len;
578         __u32 flags;
579 };
580
581 extern void lustre_swab_niobuf_remote (struct niobuf_remote *nbr);
582
583 /* request structure for OST's */
584
585 struct ost_body {
586         struct  obdo oa;
587 };
588
589 extern void lustre_swab_ost_body (struct ost_body *b);
590 extern void lustre_swab_ost_last_id(obd_id *id);
591
592 /* lock value block communicated between the filter and llite */
593
594 struct ost_lvb {
595         __u64 lvb_size;
596         __u64 lvb_mtime;
597         __u64 lvb_atime;
598         __u64 lvb_ctime;
599         __u64 lvb_blocks;
600 };
601
602 extern void lustre_swab_ost_lvb(struct ost_lvb *);
603
604 /*
605  *   MDS REQ RECORDS
606  */
607
608 /* opcodes */
609 typedef enum {
610         MDS_GETATTR      = 33,
611         MDS_GETATTR_NAME = 34,
612         MDS_CLOSE        = 35,
613         MDS_REINT        = 36,
614         MDS_READPAGE     = 37,
615         MDS_CONNECT      = 38,
616         MDS_DISCONNECT   = 39,
617         MDS_GETSTATUS    = 40,
618         MDS_STATFS       = 41,
619         MDS_PIN          = 42,
620         MDS_UNPIN        = 43,
621         MDS_SYNC         = 44,
622         MDS_DONE_WRITING = 45,
623         MDS_SET_INFO     = 46,
624         MDS_QUOTACHECK   = 47,
625         MDS_QUOTACTL     = 48,
626         MDS_GETXATTR     = 49,
627         MDS_SETXATTR     = 50,
628         MDS_LAST_OPC
629 } mds_cmd_t;
630
631 #define MDS_FIRST_OPC    MDS_GETATTR
632
633 /*
634  * Do not exceed 63
635  */
636
637 typedef enum {
638         REINT_SETATTR  = 1,
639         REINT_CREATE   = 2,
640         REINT_LINK     = 3,
641         REINT_UNLINK   = 4,
642         REINT_RENAME   = 5,
643         REINT_OPEN     = 6,
644 //      REINT_CLOSE    = 7,
645 //      REINT_WRITE    = 8,
646         REINT_MAX
647 } mds_reint_t;
648
649 /* the disposition of the intent outlines what was executed */
650 #define DISP_IT_EXECD        0x00000001
651 #define DISP_LOOKUP_EXECD    0x00000002
652 #define DISP_LOOKUP_NEG      0x00000004
653 #define DISP_LOOKUP_POS      0x00000008
654 #define DISP_OPEN_CREATE     0x00000010
655 #define DISP_OPEN_OPEN       0x00000020
656 #define DISP_ENQ_COMPLETE    0x00400000
657 #define DISP_ENQ_OPEN_REF    0x00800000
658 #define DISP_ENQ_CREATE_REF  0x01000000
659 #define DISP_OPEN_LOCK       0x02000000
660
661 /* INODE LOCK PARTS */
662 #define MDS_INODELOCK_LOOKUP 0x000001       /* dentry, mode, owner, group */
663 #define MDS_INODELOCK_UPDATE 0x000002       /* size, links, timestamps */
664 #define MDS_INODELOCK_OPEN   0x000004       /* For opened files */
665
666 /* Do not forget to increase MDS_INODELOCK_MAXSHIFT when adding new bits */
667 #define MDS_INODELOCK_MAXSHIFT 2
668 /* This FULL lock is useful to take on unlink sort of operations */
669 #define MDS_INODELOCK_FULL ((1<<(MDS_INODELOCK_MAXSHIFT+1))-1)
670
671 struct ll_fid {
672         __u64 id;         /* holds object id */
673         __u32 generation; /* holds object generation */
674
675         __u32 f_type;     /* holds object type or stripe idx when passing it to
676                            * OST for saving into EA. */
677 };
678
679 extern void lustre_swab_ll_fid (struct ll_fid *fid);
680
681 #define MDS_STATUS_CONN 1
682 #define MDS_STATUS_LOV 2
683
684 struct mds_status_req {
685         __u32  flags;
686         __u32  repbuf;
687 };
688
689 extern void lustre_swab_mds_status_req (struct mds_status_req *r);
690
691 #define MDS_BFLAG_UNCOMMITTED_WRITES   0x1
692 #define MDS_BFLAG_EXT_FLAGS     0x80000000 /* == EXT3_RESERVED_FL */
693
694 /* these should be identical to their EXT3_*_FL counterparts, and are
695  * redefined here only to avoid dragging in ext3_fs.h */
696 #define MDS_SYNC_FL             0x00000008 /* Synchronous updates */
697 #define MDS_IMMUTABLE_FL        0x00000010 /* Immutable file */
698 #define MDS_APPEND_FL           0x00000020 /* writes to file may only append */
699 #define MDS_NOATIME_FL          0x00000080 /* do not update atime */
700 #define MDS_DIRSYNC_FL          0x00010000 /* dirsync behaviour (dir only) */
701
702 #ifdef __KERNEL__
703 /* If MDS_BFLAG_IOC_FLAGS is set it means we requested EXT3_*_FL inode flags
704  * and we need to decode these into local S_* flags in the inode.  Otherwise
705  * we pass flags straight through (see bug 9486). */
706 static inline int ll_ext_to_inode_flags(int flags)
707 {
708         return (flags & MDS_BFLAG_EXT_FLAGS) ?
709                (((flags & MDS_SYNC_FL)      ? S_SYNC      : 0) |
710                 ((flags & MDS_NOATIME_FL)   ? S_NOATIME   : 0) |
711                 ((flags & MDS_APPEND_FL)    ? S_APPEND    : 0) |
712 #if defined(S_DIRSYNC)
713                 ((flags & MDS_DIRSYNC_FL)   ? S_DIRSYNC   : 0) |
714 #endif
715                 ((flags & MDS_IMMUTABLE_FL) ? S_IMMUTABLE : 0)) :
716                (flags & ~MDS_BFLAG_EXT_FLAGS);
717 }
718
719 /* If MDS_BFLAG_EXT_FLAGS is set it means we requested EXT3_*_FL inode flags
720  * and we pass these straight through.  Otherwise we need to convert from
721  * S_* flags to their EXT3_*_FL equivalents (see bug 9486). */
722 static inline int ll_inode_to_ext_flags(int oflags, int iflags)
723 {
724         return (oflags & MDS_BFLAG_EXT_FLAGS) ? (oflags & ~MDS_BFLAG_EXT_FLAGS):
725                (((iflags & S_SYNC)      ? MDS_SYNC_FL      : 0) |
726                 ((iflags & S_NOATIME)   ? MDS_NOATIME_FL   : 0) |
727                 ((iflags & S_APPEND)    ? MDS_APPEND_FL    : 0) |
728 #if defined(S_DIRSYNC)
729                 ((iflags & S_DIRSYNC)   ? MDS_DIRSYNC_FL   : 0) |
730 #endif
731                 ((iflags & S_IMMUTABLE) ? MDS_IMMUTABLE_FL : 0));
732 }
733 #endif
734
735 struct mds_body {
736         struct ll_fid  fid1;
737         struct ll_fid  fid2;
738         struct lustre_handle handle;
739         __u64          valid;
740         __u64          size;   /* Offset, in the case of MDS_READPAGE */
741         __u64          mtime;
742         __u64          atime;
743         __u64          ctime;
744         __u64          blocks; /* XID, in the case of MDS_READPAGE */
745         __u64          io_epoch;
746         __u64          ino;
747         __u32          fsuid;
748         __u32          fsgid;
749         __u32          capability;
750         __u32          mode;
751         __u32          uid;
752         __u32          gid;
753         __u32          flags; /* from vfs for pin/unpin, MDS_BFLAG for close */
754         __u32          rdev;
755         __u32          nlink; /* #bytes to read in the case of MDS_READPAGE */
756         __u32          generation;
757         __u32          suppgid;
758         __u32          eadatasize;
759         __u32          aclsize;
760         __u32          max_mdsize;
761         __u32          max_cookiesize; /* also fix lustre_swab_mds_body */
762         __u32          padding_4; /* also fix lustre_swab_mds_body */
763 };
764
765 extern void lustre_swab_mds_body (struct mds_body *b);
766
767 #define Q_QUOTACHECK    0x800100
768 #define Q_INITQUOTA     0x800101        /* init slave limits */
769 #define Q_GETOINFO      0x800102        /* get obd quota info */
770 #define Q_GETOQUOTA     0x800103        /* get obd quotas */
771
772 #define Q_TYPESET(oqc, type) \
773         ((oqc)->qc_type == type || (oqc)->qc_type == UGQUOTA)
774
775 #define Q_GETOCMD(oqc) \
776         ((oqc)->qc_cmd == Q_GETOINFO || (oqc)->qc_cmd == Q_GETOQUOTA)
777
778 struct obd_quotactl {
779         __u32                   qc_cmd;
780         __u32                   qc_type;
781         __u32                   qc_id;
782         __u32                   qc_stat;
783         struct obd_dqinfo       qc_dqinfo;
784         struct obd_dqblk        qc_dqblk;
785 };
786
787 extern void lustre_swab_obd_quotactl(struct obd_quotactl *q);
788
789 struct mds_rec_setattr {
790         __u32           sa_opcode;
791         __u32           sa_fsuid;
792         __u32           sa_fsgid;
793         __u32           sa_cap;
794         __u32           sa_suppgid;
795         __u32           sa_mode;
796         struct ll_fid   sa_fid;
797         __u64           sa_valid;
798         __u64           sa_size;
799         __u64           sa_mtime;
800         __u64           sa_atime;
801         __u64           sa_ctime;
802         __u32           sa_uid;
803         __u32           sa_gid;
804         __u32           sa_attr_flags;
805         __u32           sa_padding; /* also fix lustre_swab_mds_rec_setattr */
806 };
807
808 /* Remove this once we declare it in include/linux/fs.h (v21 kernel patch?) */
809 #ifndef ATTR_CTIME_SET
810 #define ATTR_CTIME_SET 0x2000
811 #endif
812
813 extern void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa);
814
815 #ifndef FMODE_READ
816 #define FMODE_READ               00000001
817 #define FMODE_WRITE              00000002
818 #endif
819 #define MDS_FMODE_EXEC           00000004
820 #define MDS_OPEN_CREAT           00000100
821 #define MDS_OPEN_EXCL            00000200
822 #define MDS_OPEN_TRUNC           00001000
823 #define MDS_OPEN_APPEND          00002000
824 #define MDS_OPEN_SYNC            00010000
825 #define MDS_OPEN_DIRECTORY       00200000
826
827 #define MDS_OPEN_DELAY_CREATE  0100000000 /* delay initial object create */
828 #define MDS_OPEN_OWNEROVERRIDE 0200000000 /* NFSD rw-reopen ro file for owner */
829 #define MDS_OPEN_JOIN_FILE     0400000000 /* open for join file*/
830 #define MDS_OPEN_LOCK         04000000000 /* This open requires open lock */
831 #define MDS_OPEN_HAS_EA      010000000000 /* specify object create pattern */
832 #define MDS_OPEN_HAS_OBJS    020000000000 /* Just set the EA the obj exist */
833
834 struct mds_rec_create {
835         __u32           cr_opcode;
836         __u32           cr_fsuid;
837         __u32           cr_fsgid;
838         __u32           cr_cap;
839         __u32           cr_flags; /* for use with open */
840         __u32           cr_mode;
841         struct ll_fid   cr_fid;
842         struct ll_fid   cr_replayfid;
843         __u64           cr_time;
844         __u64           cr_rdev;
845         __u32           cr_suppgid;
846         __u32           cr_padding_1; /* also fix lustre_swab_mds_rec_create */
847         __u32           cr_padding_2; /* also fix lustre_swab_mds_rec_create */
848         __u32           cr_padding_3; /* also fix lustre_swab_mds_rec_create */
849         __u32           cr_padding_4; /* also fix lustre_swab_mds_rec_create */
850         __u32           cr_padding_5; /* also fix lustre_swab_mds_rec_create */
851 };
852
853 extern void lustre_swab_mds_rec_create (struct mds_rec_create *cr);
854
855 struct mds_rec_join {
856         struct ll_fid  jr_fid;
857         __u64          jr_headsize;
858 };
859
860 extern void lustre_swab_mds_rec_join (struct mds_rec_join *jr);
861
862 struct mds_rec_link {
863         __u32           lk_opcode;
864         __u32           lk_fsuid;
865         __u32           lk_fsgid;
866         __u32           lk_cap;
867         __u32           lk_suppgid1;
868         __u32           lk_suppgid2;
869         struct ll_fid   lk_fid1;
870         struct ll_fid   lk_fid2;
871         __u64           lk_time;
872         __u32           lk_padding_1;  /* also fix lustre_swab_mds_rec_link */
873         __u32           lk_padding_2;  /* also fix lustre_swab_mds_rec_link */
874         __u32           lk_padding_3;  /* also fix lustre_swab_mds_rec_link */
875         __u32           lk_padding_4;  /* also fix lustre_swab_mds_rec_link */
876 };
877
878 extern void lustre_swab_mds_rec_link (struct mds_rec_link *lk);
879
880 struct mds_rec_unlink {
881         __u32           ul_opcode;
882         __u32           ul_fsuid;
883         __u32           ul_fsgid;
884         __u32           ul_cap;
885         __u32           ul_suppgid;
886         __u32           ul_mode;
887         struct ll_fid   ul_fid1;
888         struct ll_fid   ul_fid2;
889         __u64           ul_time;
890         __u32           ul_padding_1; /* also fix lustre_swab_mds_rec_unlink */
891         __u32           ul_padding_2; /* also fix lustre_swab_mds_rec_unlink */
892         __u32           ul_padding_3; /* also fix lustre_swab_mds_rec_unlink */
893         __u32           ul_padding_4; /* also fix lustre_swab_mds_rec_unlink */
894 };
895
896 extern void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul);
897
898 struct mds_rec_rename {
899         __u32           rn_opcode;
900         __u32           rn_fsuid;
901         __u32           rn_fsgid;
902         __u32           rn_cap;
903         __u32           rn_suppgid1;
904         __u32           rn_suppgid2;
905         struct ll_fid   rn_fid1;
906         struct ll_fid   rn_fid2;
907         __u64           rn_time;
908         __u32           rn_padding_1; /* also fix lustre_swab_mds_rec_rename */
909         __u32           rn_padding_2; /* also fix lustre_swab_mds_rec_rename */
910         __u32           rn_padding_3; /* also fix lustre_swab_mds_rec_rename */
911         __u32           rn_padding_4; /* also fix lustre_swab_mds_rec_rename */
912 };
913
914 extern void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn);
915
916 /*
917  *  LOV data structures
918  */
919
920 #define LOV_MIN_STRIPE_SIZE 65536   /* maximum PAGE_SIZE (ia64), power of 2 */
921 #define LOV_MAX_STRIPE_COUNT  160   /* until bug 4424 is fixed */
922
923 #define LOV_MAX_UUID_BUFFER_SIZE  8192
924 /* The size of the buffer the lov/mdc reserves for the
925  * array of UUIDs returned by the MDS.  With the current
926  * protocol, this will limit the max number of OSTs per LOV */
927
928 #define LOV_DESC_MAGIC 0xB0CCDE5C
929
930 /* LOV settings descriptor (should only contain static info) */
931 struct lov_desc {
932         __u32 ld_tgt_count;                /* how many OBD's */
933         __u32 ld_active_tgt_count;         /* how many active */
934         __u32 ld_default_stripe_count;     /* how many objects are used */
935         __u32 ld_pattern;                  /* default PATTERN_RAID0 */
936         __u64 ld_default_stripe_size;      /* in bytes */
937         __u64 ld_default_stripe_offset;    /* in bytes */
938         __u32 ld_padding_0;                /* unused */
939         __u32 ld_qos_maxage;               /* in second */
940         __u32 ld_padding_1;                /* also fix lustre_swab_lov_desc */
941         __u32 ld_padding_2;                /* also fix lustre_swab_lov_desc */
942         struct obd_uuid ld_uuid;
943 };
944
945 #define ld_magic ld_active_tgt_count       /* for swabbing from llogs */
946
947 extern void lustre_swab_lov_desc (struct lov_desc *ld);
948
949 /*
950  *   LDLM requests:
951  */
952 /* opcodes -- MUST be distinct from OST/MDS opcodes */
953 typedef enum {
954         LDLM_ENQUEUE     = 101,
955         LDLM_CONVERT     = 102,
956         LDLM_CANCEL      = 103,
957         LDLM_BL_CALLBACK = 104,
958         LDLM_CP_CALLBACK = 105,
959         LDLM_GL_CALLBACK = 106,
960         LDLM_LAST_OPC
961 } ldlm_cmd_t;
962 #define LDLM_FIRST_OPC LDLM_ENQUEUE
963
964 #define RES_NAME_SIZE 4
965 struct ldlm_res_id {
966         __u64 name[RES_NAME_SIZE];
967 };
968
969 extern void lustre_swab_ldlm_res_id (struct ldlm_res_id *id);
970
971 /* lock types */
972 typedef enum {
973         LCK_MINMODE = 0,
974         LCK_EX = 1,
975         LCK_PW = 2,
976         LCK_PR = 4,
977         LCK_CW = 8,
978         LCK_CR = 16,
979         LCK_NL = 32,
980         LCK_GROUP = 64,
981         LCK_MAXMODE
982 } ldlm_mode_t;
983
984 typedef enum {
985         LDLM_PLAIN     = 10,
986         LDLM_EXTENT    = 11,
987         LDLM_FLOCK     = 12,
988         LDLM_IBITS     = 13,
989         LDLM_MAX_TYPE
990 } ldlm_type_t;
991
992 #define LDLM_MIN_TYPE LDLM_PLAIN
993
994 struct ldlm_extent {
995         __u64 start;
996         __u64 end;
997         __u64 gid;
998 };
999
1000 struct ldlm_inodebits {
1001         __u64 bits;
1002 };
1003
1004 struct ldlm_flock {
1005         __u64 start;
1006         __u64 end;
1007         __u64 blocking_export;  /* not actually used over the wire */
1008         __u32 blocking_pid;     /* not actually used over the wire */
1009         __u32 pid;
1010 };
1011
1012 /* it's important that the fields of the ldlm_extent structure match
1013  * the first fields of the ldlm_flock structure because there is only
1014  * one ldlm_swab routine to process the ldlm_policy_data_t union. if
1015  * this ever changes we will need to swab the union differently based
1016  * on the resource type. */
1017
1018 typedef union {
1019         struct ldlm_extent l_extent;
1020         struct ldlm_flock  l_flock;
1021         struct ldlm_inodebits l_inodebits;
1022 } ldlm_policy_data_t;
1023
1024 extern void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d);
1025
1026 struct ldlm_intent {
1027         __u64 opc;
1028 };
1029
1030 extern void lustre_swab_ldlm_intent (struct ldlm_intent *i);
1031
1032 struct ldlm_resource_desc {
1033         ldlm_type_t lr_type;
1034         __u32 lr_padding;       /* also fix lustre_swab_ldlm_resource_desc */
1035         struct ldlm_res_id lr_name;
1036 };
1037
1038 extern void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r);
1039
1040 struct ldlm_lock_desc {
1041         struct ldlm_resource_desc l_resource;
1042         ldlm_mode_t l_req_mode;
1043         ldlm_mode_t l_granted_mode;
1044         ldlm_policy_data_t l_policy_data;
1045 };
1046
1047 extern void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l);
1048
1049 struct ldlm_request {
1050         __u32 lock_flags;
1051         __u32 lock_padding;     /* also fix lustre_swab_ldlm_request */
1052         struct ldlm_lock_desc lock_desc;
1053         struct lustre_handle lock_handle1;
1054         struct lustre_handle lock_handle2;
1055 };
1056
1057 extern void lustre_swab_ldlm_request (struct ldlm_request *rq);
1058
1059 struct ldlm_reply {
1060         __u32 lock_flags;
1061         __u32 lock_padding;     /* also fix lustre_swab_ldlm_reply */
1062         struct ldlm_lock_desc lock_desc;
1063         struct lustre_handle lock_handle;
1064         __u64  lock_policy_res1;
1065         __u64  lock_policy_res2;
1066 };
1067
1068 extern void lustre_swab_ldlm_reply (struct ldlm_reply *r);
1069
1070
1071 /*
1072  * Opcodes for mountconf (mgs and mgc)
1073  */
1074 typedef enum {
1075         MGS_CONNECT = 250,
1076         MGS_DISCONNECT,
1077         MGS_EXCEPTION,         /* node died, etc. */
1078         MGS_TARGET_REG,        /* whenever target starts up */
1079         MGS_TARGET_DEL,
1080         MGS_LAST_OPC
1081 } mgs_cmd_t;
1082
1083 /* We pass this info to the MGS so it can write config logs */
1084 #define MTI_NAME_MAXLEN 64
1085 #define MTI_PARAM_MAXLEN 4096
1086 #define MTI_NIDS_MAX 32
1087 struct mgs_target_info {
1088         __u32            mti_lustre_ver;
1089         __u32            mti_stripe_index;
1090         __u32            mti_config_ver;
1091         __u32            mti_flags;
1092         __u32            mti_nid_count;
1093         __u32            padding;                    /* 64 bit align */
1094         char             mti_fsname[MTI_NAME_MAXLEN];
1095         char             mti_svname[MTI_NAME_MAXLEN];
1096         char             mti_uuid[sizeof(struct obd_uuid)];
1097         __u64            mti_nids[MTI_NIDS_MAX];     /* host nids (lnet_nid_t)*/
1098         char             mti_params[MTI_PARAM_MAXLEN];
1099 };
1100
1101 extern void lustre_swab_mgs_target_info(struct mgs_target_info *oinfo);
1102
1103 /* Config marker flags (in config log) */
1104 #define CM_START       0x01
1105 #define CM_END         0x02
1106 #define CM_SKIP        0x04
1107 #define CM_UPGRADE146  0x08
1108 #define CM_EXCLUDE     0x10
1109 #define CM_START_SKIP (CM_START | CM_SKIP)
1110
1111 struct cfg_marker {
1112         __u32             cm_step;       /* aka config version */
1113         __u32             cm_flags;
1114         __u32             cm_vers;       /* lustre release version number */
1115         __u32             padding;       /* 64 bit align */
1116         time_t            cm_createtime; /*when this record was first created */
1117         time_t            cm_canceltime; /*when this record is no longer valid*/
1118         char              cm_tgtname[MTI_NAME_MAXLEN];
1119         char              cm_comment[MTI_NAME_MAXLEN];
1120 };
1121
1122 /*
1123  * Opcodes for multiple servers.
1124  */
1125
1126 typedef enum {
1127         OBD_PING = 400,
1128         OBD_LOG_CANCEL,
1129         OBD_QC_CALLBACK,
1130         OBD_LAST_OPC
1131 } obd_cmd_t;
1132 #define OBD_FIRST_OPC OBD_PING
1133
1134 /* catalog of log objects */
1135
1136 /* Identifier for a single log object */
1137 struct llog_logid {
1138         __u64                   lgl_oid;
1139         __u64                   lgl_ogr;
1140         __u32                   lgl_ogen;
1141 } __attribute__((packed));
1142
1143 /* Records written to the CATALOGS list */
1144 #define CATLIST "CATALOGS"
1145 struct llog_catid {
1146         struct llog_logid       lci_logid;
1147         __u32                   lci_padding1;
1148         __u32                   lci_padding2;
1149         __u32                   lci_padding3;
1150 } __attribute__((packed));
1151
1152 /*join file lov mds md*/
1153 struct lov_mds_md_join {
1154         struct lov_mds_md lmmj_md;
1155         /*join private info*/
1156         struct llog_logid lmmj_array_id; /*array object id*/
1157         __u32  lmmj_extent_count;        /*array extent count*/
1158 };
1159
1160 /* Log data record types - there is no specific reason that these need to
1161  * be related to the RPC opcodes, but no reason not to (may be handy later?)
1162  */
1163 #define LLOG_OP_MAGIC 0x10600000
1164 #define LLOG_OP_MASK  0xfff00000
1165
1166 typedef enum {
1167         LLOG_PAD_MAGIC   = LLOG_OP_MAGIC | 0x00000,
1168         OST_SZ_REC       = LLOG_OP_MAGIC | 0x00f00,
1169         OST_RAID1_REC    = LLOG_OP_MAGIC | 0x01000,
1170         MDS_UNLINK_REC   = LLOG_OP_MAGIC | 0x10000 | (MDS_REINT << 8) | REINT_UNLINK,
1171         MDS_SETATTR_REC  = LLOG_OP_MAGIC | 0x10000 | (MDS_REINT << 8) | REINT_SETATTR,
1172         OBD_CFG_REC      = LLOG_OP_MAGIC | 0x20000,
1173         PTL_CFG_REC      = LLOG_OP_MAGIC | 0x30000, /* obsolete */
1174         LLOG_GEN_REC     = LLOG_OP_MAGIC | 0x40000,
1175         LLOG_JOIN_REC    = LLOG_OP_MAGIC | 0x50000,
1176         LLOG_HDR_MAGIC   = LLOG_OP_MAGIC | 0x45539,
1177         LLOG_LOGID_MAGIC = LLOG_OP_MAGIC | 0x4553b,
1178 } llog_op_type;
1179
1180 /*
1181  * for now, continue to support old pad records which have 0 for their
1182  * type but still need to be swabbed for their length
1183  */
1184 #define LLOG_REC_HDR_NEEDS_SWABBING(r)                                  \
1185         (((r)->lrh_type & __swab32(LLOG_OP_MASK)) ==                    \
1186          __swab32(LLOG_OP_MAGIC) ||                                     \
1187          (((r)->lrh_type == 0) && ((r)->lrh_len > LLOG_CHUNK_SIZE)))
1188
1189 /* Log record header - stored in little endian order.
1190  * Each record must start with this struct, end with a llog_rec_tail,
1191  * and be a multiple of 256 bits in size.
1192  */
1193 struct llog_rec_hdr {
1194         __u32                   lrh_len;
1195         __u32                   lrh_index;
1196         __u32                   lrh_type;
1197         __u32                   padding;
1198 };
1199
1200 struct llog_rec_tail {
1201         __u32 lrt_len;
1202         __u32 lrt_index;
1203 };
1204
1205 struct llog_logid_rec {
1206         struct llog_rec_hdr     lid_hdr;
1207         struct llog_logid       lid_id;
1208         __u32                   padding1;
1209         __u32                   padding2;
1210         __u32                   padding3;
1211         __u32                   padding4;
1212         __u32                   padding5;
1213         struct llog_rec_tail    lid_tail;
1214 } __attribute__((packed));
1215
1216 /* MDS extent description
1217  * It is for joined file extent info, each extent info for joined file
1218  * just like (start, end, lmm).
1219  */
1220 struct mds_extent_desc {
1221         __u64                   med_start; /* extent start */
1222         __u64                   med_len;   /* extent length */
1223         struct lov_mds_md       med_lmm;   /* extent's lmm  */
1224 };
1225 /*Joined file array extent log record*/
1226 struct llog_array_rec {
1227         struct llog_rec_hdr     lmr_hdr;
1228         struct mds_extent_desc  lmr_med;
1229         struct llog_rec_tail    lmr_tail;
1230 };
1231
1232 struct llog_create_rec {
1233         struct llog_rec_hdr     lcr_hdr;
1234         struct ll_fid           lcr_fid;
1235         obd_id                  lcr_oid;
1236         obd_count               lcr_ogen;
1237         __u32                   padding;
1238         struct llog_rec_tail    lcr_tail;
1239 } __attribute__((packed));
1240
1241 struct llog_orphan_rec {
1242         struct llog_rec_hdr     lor_hdr;
1243         obd_id                  lor_oid;
1244         obd_count               lor_ogen;
1245         __u32                   padding;
1246         struct llog_rec_tail    lor_tail;
1247 } __attribute__((packed));
1248
1249 struct llog_unlink_rec {
1250         struct llog_rec_hdr     lur_hdr;
1251         obd_id                  lur_oid;
1252         obd_count               lur_ogen;
1253         __u32                   padding;
1254         struct llog_rec_tail    lur_tail;
1255 } __attribute__((packed));
1256
1257 struct llog_setattr_rec {
1258         struct llog_rec_hdr     lsr_hdr;
1259         obd_id                  lsr_oid;
1260         obd_count               lsr_ogen;
1261         __u32                   lsr_uid;
1262         __u32                   lsr_gid;
1263         __u32                   padding;
1264         struct llog_rec_tail    lsr_tail;
1265 } __attribute__((packed));
1266
1267 struct llog_size_change_rec {
1268         struct llog_rec_hdr     lsc_hdr;
1269         struct ll_fid           lsc_fid;
1270         __u32                   lsc_io_epoch;
1271         __u32                   padding;
1272         struct llog_rec_tail    lsc_tail;
1273 } __attribute__((packed));
1274
1275 struct llog_gen {
1276         __u64 mnt_cnt;
1277         __u64 conn_cnt;
1278 } __attribute__((packed));
1279
1280 struct llog_gen_rec {
1281         struct llog_rec_hdr     lgr_hdr;
1282         struct llog_gen         lgr_gen;
1283         struct llog_rec_tail    lgr_tail;
1284 };
1285 /* On-disk header structure of each log object, stored in little endian order */
1286 #define LLOG_CHUNK_SIZE         8192
1287 #define LLOG_HEADER_SIZE        (96)
1288 #define LLOG_BITMAP_BYTES       (LLOG_CHUNK_SIZE - LLOG_HEADER_SIZE)
1289
1290 #define LLOG_MIN_REC_SIZE       (24) /* round(llog_rec_hdr + llog_rec_tail) */
1291
1292 /* flags for the logs */
1293 #define LLOG_F_ZAP_WHEN_EMPTY   0x1
1294 #define LLOG_F_IS_CAT           0x2
1295 #define LLOG_F_IS_PLAIN         0x4
1296
1297 struct llog_log_hdr {
1298         struct llog_rec_hdr     llh_hdr;
1299         __u64                   llh_timestamp;
1300         __u32                   llh_count;
1301         __u32                   llh_bitmap_offset;
1302         __u32                   llh_size;
1303         __u32                   llh_flags;
1304         __u32                   llh_cat_idx;
1305         /* for a catalog the first plain slot is next to it */
1306         struct obd_uuid         llh_tgtuuid;
1307         __u32                   llh_reserved[LLOG_HEADER_SIZE/sizeof(__u32) - 23];
1308         __u32                   llh_bitmap[LLOG_BITMAP_BYTES/sizeof(__u32)];
1309         struct llog_rec_tail    llh_tail;
1310 } __attribute__((packed));
1311
1312 #define LLOG_BITMAP_SIZE(llh)  ((llh->llh_hdr.lrh_len -         \
1313                                  llh->llh_bitmap_offset -       \
1314                                  sizeof(llh->llh_tail)) * 8)
1315
1316 /* log cookies are used to reference a specific log file and a record therein */
1317 struct llog_cookie {
1318         struct llog_logid       lgc_lgl;
1319         __u32                   lgc_subsys;
1320         __u32                   lgc_index;
1321         __u32                   lgc_padding;
1322 } __attribute__((packed));
1323
1324 /* llog protocol */
1325 enum llogd_rpc_ops {
1326         LLOG_ORIGIN_HANDLE_CREATE       = 501,
1327         LLOG_ORIGIN_HANDLE_NEXT_BLOCK   = 502,
1328         LLOG_ORIGIN_HANDLE_READ_HEADER  = 503,
1329         LLOG_ORIGIN_HANDLE_WRITE_REC    = 504,
1330         LLOG_ORIGIN_HANDLE_CLOSE        = 505,
1331         LLOG_ORIGIN_CONNECT             = 506,
1332         LLOG_CATINFO                    = 507,  /* for lfs catinfo */
1333         LLOG_ORIGIN_HANDLE_PREV_BLOCK   = 508,
1334         LLOG_ORIGIN_HANDLE_DESTROY      = 509,  /* for destroy llog object*/
1335 };
1336
1337 struct llogd_body {
1338         struct llog_logid  lgd_logid;
1339         __u32 lgd_ctxt_idx;
1340         __u32 lgd_llh_flags;
1341         __u32 lgd_index;
1342         __u32 lgd_saved_index;
1343         __u32 lgd_len;
1344         __u64 lgd_cur_offset;
1345 } __attribute__((packed));
1346
1347 struct llogd_conn_body {
1348         struct llog_gen         lgdc_gen;
1349         struct llog_logid       lgdc_logid;
1350         __u32                   lgdc_ctxt_idx;
1351 } __attribute__((packed));
1352
1353 struct lov_user_ost_data_join {   /* per-stripe data structure */
1354         __u64 l_extent_start;     /* extent start*/
1355         __u64 l_extent_end;       /* extent end*/
1356         __u64 l_object_id;        /* OST object ID */
1357         __u64 l_object_gr;        /* OST object group (creating MDS number) */
1358         __u32 l_ost_gen;          /* generation of this OST index */
1359         __u32 l_ost_idx;          /* OST index in LOV */
1360 } __attribute__((packed));
1361
1362 struct lov_user_md_join {         /* LOV EA user data (host-endian) */
1363         __u32 lmm_magic;          /* magic number = LOV_MAGIC_JOIN */
1364         __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
1365         __u64 lmm_object_id;      /* LOV object ID */
1366         __u64 lmm_object_gr;      /* LOV object group */
1367         __u32 lmm_stripe_size;    /* size of stripe in bytes */
1368         __u32 lmm_stripe_count;   /* num stripes in use for this object */
1369         __u32 lmm_extent_count;   /* extent count of lmm*/
1370         __u64 lmm_tree_id;        /* mds tree object id */
1371         __u64 lmm_tree_gen;       /* mds tree object gen */
1372         struct llog_logid lmm_array_id; /* mds extent desc llog object id */
1373         struct lov_user_ost_data_join lmm_objects[0]; /* per-stripe data */
1374 } __attribute__((packed));
1375
1376 extern void lustre_swab_lov_user_md(struct lov_user_md *lum);
1377 extern void lustre_swab_lov_user_md_objects(struct lov_user_md *lum);
1378 extern void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj);
1379
1380 /* llog_swab.c */
1381 extern void lustre_swab_llogd_body (struct llogd_body *d);
1382 extern void lustre_swab_llog_hdr (struct llog_log_hdr *h);
1383 extern void lustre_swab_llogd_conn_body (struct llogd_conn_body *d);
1384 extern void lustre_swab_llog_rec(struct llog_rec_hdr  *rec,
1385                                  struct llog_rec_tail *tail);
1386
1387 struct lustre_cfg;
1388 extern void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg);
1389
1390 /* quota. fixed by tianzy for bug10707 */
1391 #define QUOTA_IS_GRP   0X1UL  /* 0 is user, 1 is group. Used by qd_flags*/
1392 #define QUOTA_IS_BLOCK 0x2UL  /* 0 is inode, 1 is block. Used by qd_flags*/
1393
1394 struct qunit_data {
1395         __u32 qd_id; /* ID appiles to (uid, gid) */
1396         __u32 qd_flags; /* Quota type (USRQUOTA, GRPQUOTA) occupy one bit;
1397                          * Block quota or file quota occupy one bit */
1398         __u64 qd_count; /* acquire/release count (bytes for block quota) */
1399 };
1400
1401 struct qunit_data_old {
1402         __u32 qd_id;    /* ID appiles to (uid, gid) */
1403         __u32 qd_type;  /* Quota type (USRQUOTA, GRPQUOTA) */
1404         __u32 qd_count; /* acquire/release count (bytes for block quota) */
1405         __u32 qd_isblk; /* Block quota or file quota */
1406 };
1407
1408 extern void lustre_swab_qdata(struct qunit_data *d);
1409 extern void lustre_swab_qdata_old(struct qunit_data_old *d);
1410 extern struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d);
1411 extern struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d);
1412
1413 typedef enum {
1414         QUOTA_DQACQ     = 601,
1415         QUOTA_DQREL     = 602,
1416 } quota_cmd_t;
1417
1418 #define JOIN_FILE_ALIGN 4096
1419 #endif