Whamcloud - gitweb
b=17485
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/include/lustre/lustre_idl.h
37  *
38  * Lustre wire protocol definitions.
39  *
40  * ALL structs passing over the wire should be declared here.  Structs
41  * that are used in interfaces with userspace should go in lustre_user.h.
42  *
43  * All structs being declared here should be built from simple fixed-size
44  * types (__u8, __u16, __u32, __u64) or be built from other types or
45  * structs also declared in this file.  Similarly, all flags and magic
46  * values in those structs should also be declared here.  This ensures
47  * that the Lustre wire protocol is not influenced by external dependencies.
48  *
49  * The only other acceptable items in this file are VERY SIMPLE accessor
50  * functions to avoid callers grubbing inside the structures, and the
51  * prototypes of the swabber functions for each struct.  Nothing that
52  * depends on external functions or definitions should be in here.
53  *
54  * Structs must be properly aligned to put 64-bit values on an 8-byte
55  * boundary.  Any structs being added here must also be added to
56  * utils/wirecheck.c and "make newwiretest" run to regenerate the
57  * utils/wiretest.c sources.  This allows us to verify that wire structs
58  * have the proper alignment/size on all architectures.
59  *
60  * DO NOT CHANGE any of the structs, flags, values declared here and used
61  * in released Lustre versions.  Some structs may have padding fields that
62  * can be used.  Some structs might allow addition at the end (verify this
63  * in the code to ensure that new/old clients that see this larger struct
64  * do not fail, otherwise you need to implement protocol compatibility).
65  *
66  * We assume all nodes are either little-endian or big-endian, and we
67  * always send messages in the sender's native format.  The receiver
68  * detects the message format by checking the 'magic' field of the message.
69  *
70  * Each wire type has corresponding 'lustre_swab_xxxtypexxx()' routines,
71  * implemented either here, inline (trivial implementations) or in
72  * ptlrpc/pack_generic.c.  These 'swabbers' convert the type from "other"
73  * endian, in-place in the message buffer.
74  *
75  * A swabber takes a single pointer argument.  The caller must already have
76  * verified that the length of the message buffer >= sizeof (type).
77  *
78  * For variable length types, a second 'lustre_swab_v_xxxtypexxx()' routine
79  * may be defined that swabs just the variable part, after the caller has
80  * verified that the message buffer is large enough.
81  */
82
83 #ifndef _LUSTRE_IDL_H_
84 #define _LUSTRE_IDL_H_
85
86 #if defined(__linux__)
87 #include <linux/lustre_types.h>
88 #elif defined(__APPLE__)
89 #include <darwin/lustre_types.h>
90 #elif defined(__WINNT__)
91 #include <winnt/lustre_types.h>
92 #else
93 #error Unsupported operating system.
94 #endif
95
96 /* Defn's shared with user-space. */
97 #include <lustre/lustre_user.h>
98 #include <lustre_ver.h>
99 #include <lustre/ll_fiemap.h>
100
101 #include <libcfs/kp30.h>
102
103 /*
104  * this file contains all data structures used in Lustre interfaces:
105  * - obdo and obd_request records
106  * - mds_request records
107  * - ldlm data
108  * - ioctl's
109  */
110
111 /*
112  *  GENERAL STUFF
113  */
114 /* FOO_REQUEST_PORTAL is for incoming requests on the FOO
115  * FOO_REPLY_PORTAL   is for incoming replies on the FOO
116  * FOO_BULK_PORTAL    is for incoming bulk on the FOO
117  */
118
119 #define CONNMGR_REQUEST_PORTAL          1
120 #define CONNMGR_REPLY_PORTAL            2
121 //#define OSC_REQUEST_PORTAL            3
122 #define OSC_REPLY_PORTAL                4
123 //#define OSC_BULK_PORTAL               5
124 #define OST_IO_PORTAL                   6
125 #define OST_CREATE_PORTAL               7
126 #define OST_BULK_PORTAL                 8
127 //#define MDC_REQUEST_PORTAL            9
128 #define MDC_REPLY_PORTAL               10
129 //#define MDC_BULK_PORTAL              11
130 #define MDS_REQUEST_PORTAL             12
131 //#define MDS_REPLY_PORTAL             13
132 #define MDS_BULK_PORTAL                14
133 #define LDLM_CB_REQUEST_PORTAL         15
134 #define LDLM_CB_REPLY_PORTAL           16
135 #define LDLM_CANCEL_REQUEST_PORTAL     17
136 #define LDLM_CANCEL_REPLY_PORTAL       18
137 //#define PTLBD_REQUEST_PORTAL           19
138 //#define PTLBD_REPLY_PORTAL             20
139 //#define PTLBD_BULK_PORTAL              21
140 #define MDS_SETATTR_PORTAL             22
141 #define MDS_READPAGE_PORTAL            23
142 #define MDS_MDS_PORTAL                 24
143
144 #define MGC_REPLY_PORTAL               25
145 #define MGS_REQUEST_PORTAL             26
146 #define MGS_REPLY_PORTAL               27
147 #define OST_REQUEST_PORTAL             28
148 #define FLD_REQUEST_PORTAL             29
149 #define SEQ_METADATA_PORTAL            30
150 #define SEQ_DATA_PORTAL                31
151 #define SEQ_CONTROLLER_PORTAL          32
152
153 #define SVC_KILLED               1
154 #define SVC_EVENT                2
155 #define SVC_SIGNAL               4
156 #define SVC_RUNNING              8
157 #define SVC_STOPPING            16
158 #define SVC_STOPPED             32
159
160 /* packet types */
161 #define PTL_RPC_MSG_REQUEST 4711
162 #define PTL_RPC_MSG_ERR     4712
163 #define PTL_RPC_MSG_REPLY   4713
164
165 /* DON'T use swabbed values of MAGIC as magic! */
166 #define LUSTRE_MSG_MAGIC_V1 0x0BD00BD0
167 #define LUSTRE_MSG_MAGIC_V2 0x0BD00BD3
168
169 #define LUSTRE_MSG_MAGIC_V1_SWABBED 0xD00BD00B
170 #define LUSTRE_MSG_MAGIC_V2_SWABBED 0xD30BD00B
171
172 #define LUSTRE_MSG_MAGIC LUSTRE_MSG_MAGIC_V2
173
174 #define PTLRPC_MSG_VERSION  0x00000003
175 #define LUSTRE_VERSION_MASK 0xffff0000
176 #define LUSTRE_OBD_VERSION  0x00010000
177 #define LUSTRE_MDS_VERSION  0x00020000
178 #define LUSTRE_OST_VERSION  0x00030000
179 #define LUSTRE_DLM_VERSION  0x00040000
180 #define LUSTRE_LOG_VERSION  0x00050000
181 #define LUSTRE_MGS_VERSION  0x00060000
182
183 struct lustre_handle {
184         __u64 cookie;
185 };
186 #define DEAD_HANDLE_MAGIC 0xdeadbeefcafebabeULL
187
188 static inline int lustre_handle_is_used(struct lustre_handle *lh)
189 {
190         return lh->cookie != 0ull;
191 }
192
193 static inline int lustre_handle_equal(struct lustre_handle *lh1,
194                                       struct lustre_handle *lh2)
195 {
196         return lh1->cookie == lh2->cookie;
197 }
198
199 static inline void lustre_handle_copy(struct lustre_handle *tgt,
200                                       struct lustre_handle *src)
201 {
202         tgt->cookie = src->cookie;
203 }
204
205 /* we depend on this structure to be 8-byte aligned */
206 /* this type is only endian-adjusted in lustre_unpack_msg() */
207 struct lustre_msg_v1 {
208         struct lustre_handle lm_handle;
209         __u32 lm_magic;
210         __u32 lm_type;
211         __u32 lm_version;
212         __u32 lm_opc;
213         __u64 lm_last_xid;
214         __u64 lm_last_committed;
215         __u64 lm_transno;
216         __u32 lm_status;
217         __u32 lm_flags;
218         __u32 lm_conn_cnt;
219         __u32 lm_bufcount;
220         __u32 lm_buflens[0];
221 };
222
223 /* flags for lm_flags */
224 #define MSGHDR_AT_SUPPORT               0x1
225
226 #define lustre_msg lustre_msg_v2
227 /* we depend on this structure to be 8-byte aligned */
228 /* this type is only endian-adjusted in lustre_unpack_msg() */
229 struct lustre_msg_v2 {
230         __u32 lm_bufcount;
231         __u32 lm_secflvr;
232         __u32 lm_magic;
233         __u32 lm_repsize;
234         __u32 lm_cksum;
235         __u32 lm_flags;
236         __u32 lm_padding_2;
237         __u32 lm_padding_3;
238         __u32 lm_buflens[0];
239 };
240
241 /* without gss, ptlrpc_body is put at the first buffer. */
242 #define PTLRPC_NUM_VERSIONS     4
243 struct ptlrpc_body {
244         struct lustre_handle pb_handle;
245         __u32 pb_type;
246         __u32 pb_version;
247         __u32 pb_opc;
248         __u32 pb_status;
249         __u64 pb_last_xid;
250         __u64 pb_last_seen; /* not used */
251         __u64 pb_last_committed;
252         __u64 pb_transno;
253         __u32 pb_flags;
254         __u32 pb_op_flags;
255         __u32 pb_conn_cnt;
256         __u32 pb_timeout;  /* for req, the deadline, for rep, the service est */
257         __u32 pb_service_time; /* for rep, actual service time */
258         __u32 pb_limit;
259         __u64 pb_slv;
260         /* VBR: pre-versions */
261         __u64 pb_pre_versions[PTLRPC_NUM_VERSIONS];
262         /* padding for future needs */
263         __u64 pb_padding[4];
264 };
265
266 extern void lustre_swab_ptlrpc_body(struct ptlrpc_body *pb, int msgsize);
267
268 /* message body offset for lustre_msg_v2 */
269 /* ptlrpc body offset in all request/reply messages */
270 #define MSG_PTLRPC_BODY_OFF             0
271
272 /* normal request/reply message record offset */
273 #define REQ_REC_OFF                     1
274 #define REPLY_REC_OFF                   1
275
276 /* ldlm request message body offset */
277 #define DLM_LOCKREQ_OFF                 1 /* lockreq offset */
278 #define DLM_REQ_REC_OFF                 2 /* normal dlm request record offset */
279
280 /* ldlm intent lock message body offset */
281 #define DLM_INTENT_IT_OFF               2 /* intent lock it offset */
282 #define DLM_INTENT_REC_OFF              3 /* intent lock record offset */
283
284 /* ldlm reply message body offset */
285 #define DLM_LOCKREPLY_OFF               1 /* lockrep offset */
286 #define DLM_REPLY_REC_OFF               2 /* reply record offset */
287
288 /* only use in req->rq_{req,rep}_swab_mask */
289 #define MSG_PTLRPC_HEADER_OFF           31
290
291 /* Flags that are operation-specific go in the top 16 bits. */
292 #define MSG_OP_FLAG_MASK   0xffff0000
293 #define MSG_OP_FLAG_SHIFT  16
294
295 /* Flags that apply to all requests are in the bottom 16 bits */
296 #define MSG_GEN_FLAG_MASK     0x0000ffff
297 #define MSG_LAST_REPLAY           0x0001
298 #define MSG_RESENT                0x0002
299 #define MSG_REPLAY                0x0004
300 /* #define MSG_AT_SUPPORT         0x0008
301  * This was used in early prototypes of adaptive timeouts, and while there
302  * shouldn't be any users of that code there also isn't a need for using this
303  * bits. Defer usage until at least 1.10 to avoid potential conflict. */
304 #define MSG_DELAY_REPLAY          0x0010
305 #define MSG_VERSION_REPLAY        0x0020
306 #define MSG_REQ_REPLAY_DONE       0x0040
307 #define MSG_LOCK_REPLAY_DONE      0x0080
308
309 /*
310  * Flags for all connect opcodes (MDS_CONNECT, OST_CONNECT)
311  */
312
313 #define MSG_CONNECT_RECOVERING  0x00000001
314 #define MSG_CONNECT_RECONNECT   0x00000002
315 #define MSG_CONNECT_REPLAYABLE  0x00000004
316 //#define MSG_CONNECT_PEER        0x8
317 #define MSG_CONNECT_LIBCLIENT   0x00000010
318 #define MSG_CONNECT_INITIAL     0x00000020
319 #define MSG_CONNECT_ASYNC       0x00000040
320 #define MSG_CONNECT_NEXT_VER    0x00000080 /* use next version of lustre_msg */
321 #define MSG_CONNECT_TRANSNO     0x00000100 /* report transno */
322 #define MSG_CONNECT_DELAYED     0x00000200
323
324 /* Connect flags */
325 #define OBD_CONNECT_RDONLY            0x1ULL /*client allowed read-only access*/
326 #define OBD_CONNECT_INDEX             0x2ULL /*connect to specific LOV idx */
327 #define OBD_CONNECT_MDS               0x4ULL /*connect from MDT to OST */
328 #define OBD_CONNECT_GRANT             0x8ULL /*OSC acquires grant at connect */
329 #define OBD_CONNECT_SRVLOCK          0x10ULL /*server takes locks for client */
330 #define OBD_CONNECT_VERSION          0x20ULL /*Lustre versions in ocd */
331 #define OBD_CONNECT_REQPORTAL        0x40ULL /*Separate non-IO request portal */
332 #define OBD_CONNECT_ACL              0x80ULL /*access control lists */
333 #define OBD_CONNECT_XATTR           0x100ULL /*client use extended attributes */
334 #define OBD_CONNECT_CROW            0x200ULL /*MDS+OST create objects on write*/
335 #define OBD_CONNECT_TRUNCLOCK       0x400ULL /*locks on server for punch */
336 #define OBD_CONNECT_TRANSNO         0x800ULL /*replay sends initial transno */
337 #define OBD_CONNECT_IBITS          0x1000ULL /*support for inodebits locks */
338 #define OBD_CONNECT_JOIN           0x2000ULL /*files can be concatenated */
339 #define OBD_CONNECT_ATTRFID        0x4000ULL /*Server supports GetAttr By Fid */
340 #define OBD_CONNECT_NODEVOH        0x8000ULL /*No open handle on special nodes*/
341 #define OBD_CONNECT_RMT_CLIENT    0x10000ULL /*Remote client */
342 #define OBD_CONNECT_RMT_CLIENT_FORCE 0x20000ULL /*Remote client by force */
343 #define OBD_CONNECT_BRW_SIZE      0x40000ULL /*Max bytes per rpc */
344 #define OBD_CONNECT_QUOTA64       0x80000ULL /*64bit qunit_data.qd_count */
345 #define OBD_CONNECT_MDS_CAPA     0x100000ULL /*MDS capability */
346 #define OBD_CONNECT_OSS_CAPA     0x200000ULL /*OSS capability */
347 #define OBD_CONNECT_CANCELSET    0x400000ULL /*Early batched cancels. */
348 #define OBD_CONNECT_SOM        0x00800000ULL /*Size on MDS */
349 #define OBD_CONNECT_AT         0x01000000ULL /*client uses adaptive timeouts */
350 #define OBD_CONNECT_LRU_RESIZE 0x02000000ULL /*LRU resize feature. */
351 #define OBD_CONNECT_MDS_MDS    0x04000000ULL /*MDS-MDS connection */
352 #define OBD_CONNECT_REAL       0x08000000ULL /*real connection */
353 #define OBD_CONNECT_CHANGE_QS  0x10000000ULL /*shrink/enlarge qunit b=10600 */
354 #define OBD_CONNECT_CKSUM      0x20000000ULL /*support several cksum algos */
355 #define OBD_CONNECT_FID        0x40000000ULL /*FID is supported by server */
356 #define OBD_CONNECT_VBR        0x80000000ULL /*version based recovery */
357 #define OBD_CONNECT_LOV_V3    0x100000000ULL /*client supports LOV v3 EA */
358 #define OBD_CONNECT_GRANT_SHRINK  0x200000000ULL /* support grant shrink */
359 #define OBD_CONNECT_SKIP_ORPHAN   0x400000000ULL /* don't reuse orphan objids */
360 /* also update obd_connect_names[] for lprocfs_rd_connect_flags()
361  * and lustre/utils/wirecheck.c */
362
363 #ifdef HAVE_LRU_RESIZE_SUPPORT
364 #define LRU_RESIZE_CONNECT_FLAG OBD_CONNECT_LRU_RESIZE
365 #else
366 #define LRU_RESIZE_CONNECT_FLAG 0
367 #endif
368
369 #define MDS_CONNECT_SUPPORTED  (OBD_CONNECT_RDONLY | OBD_CONNECT_VERSION | \
370                                 OBD_CONNECT_ACL | OBD_CONNECT_XATTR | \
371                                 OBD_CONNECT_IBITS | OBD_CONNECT_JOIN | \
372                                 OBD_CONNECT_NODEVOH | OBD_CONNECT_ATTRFID | \
373                                 OBD_CONNECT_CANCELSET | OBD_CONNECT_AT | \
374                                 LRU_RESIZE_CONNECT_FLAG | OBD_CONNECT_VBR |\
375                                 OBD_CONNECT_LOV_V3)
376 #define OST_CONNECT_SUPPORTED  (OBD_CONNECT_SRVLOCK | OBD_CONNECT_GRANT | \
377                                 OBD_CONNECT_REQPORTAL | OBD_CONNECT_VERSION | \
378                                 OBD_CONNECT_TRUNCLOCK | OBD_CONNECT_INDEX | \
379                                 OBD_CONNECT_BRW_SIZE | OBD_CONNECT_QUOTA64 | \
380                                 OBD_CONNECT_CANCELSET | OBD_CONNECT_AT | \
381                                 LRU_RESIZE_CONNECT_FLAG | OBD_CONNECT_CKSUM | \
382                                 OBD_CONNECT_VBR | OBD_CONNECT_CHANGE_QS | \
383                                 OBD_CONNECT_MDS | OBD_CONNECT_GRANT_SHRINK | \
384                                 OBD_CONNECT_SKIP_ORPHAN)
385 #define ECHO_CONNECT_SUPPORTED (0)
386 #define MGS_CONNECT_SUPPORTED  (OBD_CONNECT_VERSION | OBD_CONNECT_AT)
387
388 #define OBD_OCD_VERSION(major,minor,patch,fix) (((major)<<24) + ((minor)<<16) +\
389                                                 ((patch)<<8) + (fix))
390 #define OBD_OCD_VERSION_MAJOR(version) ((int)((version)>>24)&255)
391 #define OBD_OCD_VERSION_MINOR(version) ((int)((version)>>16)&255)
392 #define OBD_OCD_VERSION_PATCH(version) ((int)((version)>>8)&255)
393 #define OBD_OCD_VERSION_FIX(version)   ((int)(version)&255)
394
395 /* This structure is used for both request and reply.
396  *
397  * If we eventually have separate connect data for different types, which we
398  * almost certainly will, then perhaps we stick a union in here. */
399 struct obd_connect_data {
400         __u64 ocd_connect_flags; /* OBD_CONNECT_* per above */
401         __u32 ocd_version;       /* lustre release version number */
402         __u32 ocd_grant;         /* initial cache grant amount (bytes) */
403         __u32 ocd_index;         /* LOV index to connect to */
404         __u32 ocd_brw_size;      /* Maximum BRW size in bytes */
405         __u64 ocd_ibits_known;   /* inode bits this client understands */
406         __u32 ocd_nllu;          /* non-local-lustre-user */
407         __u32 ocd_nllg;          /* non-local-lustre-group */
408         __u64 ocd_transno;       /* Used in lustre 1.8 */
409         __u32 ocd_group;         /* Used in lustre 1.8 */
410         __u32 ocd_cksum_types;   /* supported checksum algorithms */
411         __u64 padding1;          /* also fix lustre_swab_connect */
412         __u64 padding2;          /* also fix lustre_swab_connect */
413 };
414
415 extern void lustre_swab_connect(struct obd_connect_data *ocd);
416
417 /* b1_6 has smaller body. The defines below is for interoperability */
418 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2,0,0,0)
419 #define PTLRPC_INTEROP_1_6      1
420 #define PTLRPC_BODY_MIN_SIZE    offsetof(struct ptlrpc_body, pb_pre_versions)
421 #else
422 #define PTLRPC_BODY_MIN_SIZE    sizeof(struct ptlrpc_body)
423 #endif
424
425 /*
426  * Supported checksum algorithms. Up to 32 checksum types are supported.
427  * (32-bit mask stored in obd_connect_data::ocd_cksum_types)
428  * Please update DECLARE_CKSUM_NAME/OBD_CKSUM_ALL in obd.h when adding a new
429  * algorithm and also the OBD_FL_CKSUM* flags.
430  */
431 typedef enum {
432         OBD_CKSUM_CRC32 = 0x00000001,
433         OBD_CKSUM_ADLER = 0x00000002,
434 } cksum_type_t;
435
436 /*
437  *   OST requests: OBDO & OBD request records
438  */
439
440 /* opcodes */
441 typedef enum {
442         OST_REPLY      =  0,       /* reply ? */
443         OST_GETATTR    =  1,
444         OST_SETATTR    =  2,
445         OST_READ       =  3,
446         OST_WRITE      =  4,
447         OST_CREATE     =  5,
448         OST_DESTROY    =  6,
449         OST_GET_INFO   =  7,
450         OST_CONNECT    =  8,
451         OST_DISCONNECT =  9,
452         OST_PUNCH      = 10,
453         OST_OPEN       = 11,
454         OST_CLOSE      = 12,
455         OST_STATFS     = 13,
456 /*      OST_SAN_READ   = 14,    deprecated */
457 /*      OST_SAN_WRITE  = 15,    deprecated */
458         OST_SYNC       = 16,
459         OST_SET_INFO   = 17,
460         OST_QUOTACHECK = 18,
461         OST_QUOTACTL   = 19,
462         OST_QUOTA_ADJUST_QUNIT = 20,
463         OST_LAST_OPC
464 } ost_cmd_t;
465 #define OST_FIRST_OPC  OST_REPLY
466
467 typedef __u64 obd_id;
468 typedef __u64 obd_gr;
469 typedef __u64 obd_time;
470 typedef __u64 obd_size;
471 typedef __u64 obd_off;
472 typedef __u64 obd_blocks;
473 typedef __u64 obd_valid;
474 typedef __u32 obd_blksize;
475 typedef __u32 obd_mode;
476 typedef __u32 obd_uid;
477 typedef __u32 obd_gid;
478 typedef __u32 obd_flag;
479 typedef __u32 obd_count;
480
481 enum obdo_flags {
482         OBD_FL_INLINEDATA   = 0x00000001,
483         OBD_FL_OBDMDEXISTS  = 0x00000002,
484         OBD_FL_DELORPHAN    = 0x00000004, /* if set in o_flags delete orphans */
485         OBD_FL_NORPC        = 0x00000008, /* set in o_flags do in OSC not OST */
486         OBD_FL_IDONLY       = 0x00000010, /* set in o_flags only adjust obj id*/
487         OBD_FL_RECREATE_OBJS= 0x00000020, /* recreate missing obj */
488         OBD_FL_DEBUG_CHECK  = 0x00000040, /* echo client/server debug check */
489         OBD_FL_NO_USRQUOTA  = 0x00000100, /* the object's owner is over quota */
490         OBD_FL_NO_GRPQUOTA  = 0x00000200, /* the object's group is over quota */
491         OBD_FL_CREATE_CROW  = 0x00000400, /* object should be create on write */
492         OBD_FL_TRUNCLOCK    = 0x00000800, /* delegate DLM locking during punch*/
493         OBD_FL_CKSUM_CRC32  = 0x00001000, /* CRC32 checksum type */
494         OBD_FL_CKSUM_ADLER  = 0x00002000, /* ADLER checksum type */
495         OBD_FL_CKSUM_RSVD1  = 0x00004000, /* for future cksum types */
496         OBD_FL_CKSUM_RSVD2  = 0x00008000, /* for future cksum types */
497         OBD_FL_CKSUM_RSVD3  = 0x00010000, /* for future cksum types */
498         OBD_FL_SHRINK_GRANT = 0x00020000, /* object shrink the grant */
499
500         OBD_FL_CKSUM_ALL    = OBD_FL_CKSUM_CRC32 | OBD_FL_CKSUM_ADLER,
501
502         /* mask for local-only flag, which won't be sent over network */
503         OBD_FL_LOCAL_MASK   = 0xF0000000,
504         /* temporary OBDO used by osc_brw_async (see bug 18364) */
505         OBD_FL_TEMPORARY    = 0x10000000,
506 };
507
508 #define LOV_MAGIC_V1      0x0BD10BD0
509 #define LOV_MAGIC         LOV_MAGIC_V1
510 #define LOV_MAGIC_JOIN    0x0BD20BD0
511 #define LOV_MAGIC_V3      0x0BD30BD0
512
513 #define LOV_PATTERN_RAID0 0x001   /* stripes are used round-robin */
514 #define LOV_PATTERN_RAID1 0x002   /* stripes are mirrors of each other */
515 #define LOV_PATTERN_FIRST 0x100   /* first stripe is not in round-robin */
516 #define LOV_PATTERN_CMOBD 0x200
517
518 #define LOV_OBJECT_GROUP_DEFAULT ~0ULL
519 #define LOV_OBJECT_GROUP_CLEAR 0ULL
520
521 #define lov_ost_data lov_ost_data_v1
522 struct lov_ost_data_v1 {          /* per-stripe data structure (little-endian)*/
523         __u64 l_object_id;        /* OST object ID */
524         __u64 l_object_gr;        /* OST object group (creating MDS number) */
525         __u32 l_ost_gen;          /* generation of this l_ost_idx */
526         __u32 l_ost_idx;          /* OST index in LOV (lov_tgt_desc->tgts) */
527 };
528
529 #define lov_mds_md lov_mds_md_v1
530 struct lov_mds_md_v1 {            /* LOV EA mds/wire data (little-endian) */
531         __u32 lmm_magic;          /* magic number = LOV_MAGIC_V1 */
532         __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
533         __u64 lmm_object_id;      /* LOV object ID */
534         __u64 lmm_object_gr;      /* LOV object group */
535         __u32 lmm_stripe_size;    /* size of stripe in bytes */
536         __u32 lmm_stripe_count;   /* num stripes in use for this object */
537         struct lov_ost_data_v1 lmm_objects[0]; /* per-stripe data */
538 };
539
540 struct lov_mds_md_v3 {            /* LOV EA mds/wire data (little-endian) */
541         __u32 lmm_magic;          /* magic number = LOV_MAGIC_V3 */
542         __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
543         __u64 lmm_object_id;      /* LOV object ID */
544         __u64 lmm_object_gr;      /* LOV object group */
545         __u32 lmm_stripe_size;    /* size of stripe in bytes */
546         __u32 lmm_stripe_count;   /* num stripes in use for this object */
547         char  lmm_pool_name[LOV_MAXPOOLNAME]; /* must be 32bit aligned */
548         struct lov_ost_data_v1 lmm_objects[0]; /* per-stripe data */
549 };
550
551
552 #define OBD_MD_FLID        (0x00000001ULL) /* object ID */
553 #define OBD_MD_FLATIME     (0x00000002ULL) /* access time */
554 #define OBD_MD_FLMTIME     (0x00000004ULL) /* data modification time */
555 #define OBD_MD_FLCTIME     (0x00000008ULL) /* change time */
556 #define OBD_MD_FLSIZE      (0x00000010ULL) /* size */
557 #define OBD_MD_FLBLOCKS    (0x00000020ULL) /* allocated blocks count */
558 #define OBD_MD_FLBLKSZ     (0x00000040ULL) /* block size */
559 #define OBD_MD_FLMODE      (0x00000080ULL) /* access bits (mode & ~S_IFMT) */
560 #define OBD_MD_FLTYPE      (0x00000100ULL) /* object type (mode & S_IFMT) */
561 #define OBD_MD_FLUID       (0x00000200ULL) /* user ID */
562 #define OBD_MD_FLGID       (0x00000400ULL) /* group ID */
563 #define OBD_MD_FLFLAGS     (0x00000800ULL) /* flags word */
564 #define OBD_MD_FLNLINK     (0x00002000ULL) /* link count */
565 #define OBD_MD_FLGENER     (0x00004000ULL) /* generation number */
566 /*#define OBD_MD_FLINLINE    (0x00008000ULL) inline data. used until 1.6.5 */
567 #define OBD_MD_FLRDEV      (0x00010000ULL) /* device number */
568 #define OBD_MD_FLEASIZE    (0x00020000ULL) /* extended attribute data */
569 #define OBD_MD_LINKNAME    (0x00040000ULL) /* symbolic link target */
570 #define OBD_MD_FLHANDLE    (0x00080000ULL) /* file/lock handle */
571 #define OBD_MD_FLCKSUM     (0x00100000ULL) /* bulk data checksum */
572 #define OBD_MD_FLQOS       (0x00200000ULL) /* quality of service stats */
573 /*#define OBD_MD_FLOSCOPQ    (0x00400000ULL) osc opaque data, never used */
574 #define OBD_MD_FLCOOKIE    (0x00800000ULL) /* log cancellation cookie */
575 #define OBD_MD_FLGROUP     (0x01000000ULL) /* group */
576 #define OBD_MD_FLFID       (0x02000000ULL) /* ->ost write inline fid */
577 #define OBD_MD_FLEPOCH     (0x04000000ULL) /* ->ost write easize is epoch */
578                                            /* ->mds if epoch opens or closes */
579 #define OBD_MD_FLGRANT     (0x08000000ULL) /* ost preallocation space grant */
580 #define OBD_MD_FLDIREA     (0x10000000ULL) /* dir's extended attribute data */
581 #define OBD_MD_FLUSRQUOTA  (0x20000000ULL) /* over quota flags sent from ost */
582 #define OBD_MD_FLGRPQUOTA  (0x40000000ULL) /* over quota flags sent from ost */
583 #define OBD_MD_FLMODEASIZE (0x80000000ULL) /* EA size will be changed */
584
585 #define OBD_MD_MDS         (0x0000000100000000ULL) /* where an inode lives on */
586 #define OBD_MD_REINT       (0x0000000200000000ULL) /* reintegrate oa */
587 #define OBD_MD_MEA         (0x0000000400000000ULL) /* CMD split EA  */
588
589 #define OBD_MD_FLXATTR     (0x0000001000000000ULL) /* xattr */
590 #define OBD_MD_FLXATTRLS   (0x0000002000000000ULL) /* xattr list */
591 #define OBD_MD_FLXATTRRM   (0x0000004000000000ULL) /* xattr remove */
592 #define OBD_MD_FLACL       (0x0000008000000000ULL) /* ACL */
593 #define OBD_MD_FLRMTPERM   (0x0000010000000000ULL) /* remote permission */
594 #define OBD_MD_FLMDSCAPA   (0x0000020000000000ULL) /* MDS capability */
595 #define OBD_MD_FLOSSCAPA   (0x0000040000000000ULL) /* OSS capability */
596 #define OBD_MD_FLCKSPLIT   (0x0000080000000000ULL) /* Check split on server */
597 #define OBD_MD_FLCROSSREF  (0x0000100000000000ULL) /* Cross-ref case */
598
599 #define OBD_FL_TRUNC       (0x0000200000000000ULL) /* for filter_truncate */
600
601 #define OBD_MD_FLRMTLSETFACL    (0x0001000000000000ULL) /* lfs lsetfacl case */
602 #define OBD_MD_FLRMTLGETFACL    (0x0002000000000000ULL) /* lfs lgetfacl case */
603 #define OBD_MD_FLRMTRSETFACL    (0x0004000000000000ULL) /* lfs rsetfacl case */
604 #define OBD_MD_FLRMTRGETFACL    (0x0008000000000000ULL) /* lfs rgetfacl case */
605
606 #define OBD_MD_FLGETATTR (OBD_MD_FLID    | OBD_MD_FLATIME | OBD_MD_FLMTIME | \
607                           OBD_MD_FLCTIME | OBD_MD_FLSIZE  | OBD_MD_FLBLKSZ | \
608                           OBD_MD_FLMODE  | OBD_MD_FLTYPE  | OBD_MD_FLUID   | \
609                           OBD_MD_FLGID   | OBD_MD_FLFLAGS | OBD_MD_FLNLINK | \
610                           OBD_MD_FLGENER | OBD_MD_FLRDEV  | OBD_MD_FLGROUP)
611
612 /* don't forget obdo_fid which is way down at the bottom so it can
613  * come after the definition of llog_cookie */
614
615 enum obd_statfs_state {
616         OS_STATE_DEGRADED       = 0x00000001, /**< RAID degraded/rebuilding */
617         OS_STATE_READONLY       = 0x00000002, /**< filesystem is read-only */
618         OS_STATE_RDONLY_1       = 0x00000004, /**< obsolete 1.6, was EROFS=30 */
619         OS_STATE_RDONLY_2       = 0x00000008, /**< obsolete 1.6, was EROFS=30 */
620         OS_STATE_RDONLY_3       = 0x00000010, /**< obsolete 1.6, was EROFS=30 */
621 };
622
623 struct obd_statfs {
624         __u64           os_type;
625         __u64           os_blocks;
626         __u64           os_bfree;
627         __u64           os_bavail;
628         __u64           os_files;
629         __u64           os_ffree;
630         __u8            os_fsid[40];
631         __u32           os_bsize;
632         __u32           os_namelen;
633         __u64           os_maxbytes;
634         __u32           os_state;       /**< obd_statfs_state OS_STATE_* flag */
635         __u32           os_spare1;
636         __u32           os_spare2;
637         __u32           os_spare3;
638         __u32           os_spare4;
639         __u32           os_spare5;
640         __u32           os_spare6;
641         __u32           os_spare7;
642         __u32           os_spare8;
643         __u32           os_spare9;
644 };
645
646 extern void lustre_swab_obd_statfs (struct obd_statfs *os);
647 #define OBD_STATFS_NODELAY      0x0001  /* requests should be send without delay
648                                          * and resends for avoid deadlocks */
649 #define OBD_STATFS_FROM_CACHE   0x0002  /* the statfs callback should not update
650                                          * obd_osfs_age */
651 #define OBD_STATFS_PTLRPCD      0x0004  /* requests will be sent via ptlrpcd
652                                          * instead of a specific set. This
653                                          * means that we cannot rely on the set
654                                          * interpret routine to be called.
655                                          * lov_statfs_fini() must thus be called
656                                          * by the request interpret routine */
657
658 /* ost_body.data values for OST_BRW */
659
660 #define OBD_BRW_READ            0x01
661 #define OBD_BRW_WRITE           0x02
662 #define OBD_BRW_RWMASK          (OBD_BRW_READ | OBD_BRW_WRITE)
663 #define OBD_BRW_SYNC            0x08
664 #define OBD_BRW_CHECK           0x10
665 #define OBD_BRW_FROM_GRANT      0x20 /* the osc manages this under llite */
666 #define OBD_BRW_GRANTED         0x40 /* the ost manages this */
667 #define OBD_BRW_DROP            0x80 /* drop the page after IO */
668 #define OBD_BRW_NOQUOTA        0x100
669 #define OBD_BRW_SRVLOCK        0x200 /* Client holds no lock over this page */
670 #define OBD_BRW_ASYNC          0x400 /* Server may delay commit to disk */
671
672 #define OBD_OBJECT_EOF 0xffffffffffffffffULL
673
674 #define OST_MIN_PRECREATE 32
675 #define OST_MAX_PRECREATE 20000
676
677 struct obd_ioobj {
678         obd_id               ioo_id;
679         obd_gr               ioo_gr;
680         __u32                ioo_type;
681         __u32                ioo_bufcnt;
682 };
683
684 extern void lustre_swab_obd_ioobj (struct obd_ioobj *ioo);
685
686 /* multiple of 8 bytes => can array */
687 struct niobuf_remote {
688         __u64 offset;
689         __u32 len;
690         __u32 flags;
691 };
692
693 extern void lustre_swab_niobuf_remote (struct niobuf_remote *nbr);
694
695 /* lock value block communicated between the filter and llite */
696
697 /* OST_LVB_ERR_INIT is needed because the return code in rc is
698  * negative, i.e. because ((MASK + rc) & MASK) != MASK. */
699 #define OST_LVB_ERR_INIT 0xffbadbad80000000ULL
700 #define OST_LVB_ERR_MASK 0xffbadbad00000000ULL
701 #define OST_LVB_IS_ERR(blocks)                                          \
702         ((blocks & OST_LVB_ERR_MASK) == OST_LVB_ERR_MASK)
703 #define OST_LVB_SET_ERR(blocks, rc)                                     \
704         do { blocks = OST_LVB_ERR_INIT + rc; } while (0)
705 #define OST_LVB_GET_ERR(blocks)    (int)(blocks - OST_LVB_ERR_INIT)
706
707 struct ost_lvb {
708         __u64 lvb_size;
709         __u64 lvb_mtime;
710         __u64 lvb_atime;
711         __u64 lvb_ctime;
712         __u64 lvb_blocks;
713 };
714
715 extern void lustre_swab_ost_lvb(struct ost_lvb *);
716
717 /*
718  *   MDS REQ RECORDS
719  */
720
721 /* opcodes */
722 typedef enum {
723         MDS_GETATTR      = 33,
724         MDS_GETATTR_NAME = 34,
725         MDS_CLOSE        = 35,
726         MDS_REINT        = 36,
727         MDS_READPAGE     = 37,
728         MDS_CONNECT      = 38,
729         MDS_DISCONNECT   = 39,
730         MDS_GETSTATUS    = 40,
731         MDS_STATFS       = 41,
732         MDS_PIN          = 42,
733         MDS_UNPIN        = 43,
734         MDS_SYNC         = 44,
735         MDS_DONE_WRITING = 45,
736         MDS_SET_INFO     = 46,
737         MDS_QUOTACHECK   = 47,
738         MDS_QUOTACTL     = 48,
739         MDS_GETXATTR     = 49,
740         MDS_SETXATTR     = 50,
741         MDS_WRITEPAGE    = 51,
742         MDS_IS_SUBDIR    = 52,
743         MDS_LAST_OPC
744 } mds_cmd_t;
745
746 #define MDS_FIRST_OPC    MDS_GETATTR
747
748 /*
749  * Do not exceed 63
750  */
751
752 typedef enum {
753         REINT_SETATTR  = 1,
754         REINT_CREATE   = 2,
755         REINT_LINK     = 3,
756         REINT_UNLINK   = 4,
757         REINT_RENAME   = 5,
758         REINT_OPEN     = 6,
759         REINT_SETXATTR = 7,
760 //      REINT_CLOSE    = 8,
761 //      REINT_WRITE    = 9,
762         REINT_MAX
763 } mds_reint_t;
764
765 /* the disposition of the intent outlines what was executed */
766 #define DISP_IT_EXECD        0x00000001
767 #define DISP_LOOKUP_EXECD    0x00000002
768 #define DISP_LOOKUP_NEG      0x00000004
769 #define DISP_LOOKUP_POS      0x00000008
770 #define DISP_OPEN_CREATE     0x00000010
771 #define DISP_OPEN_OPEN       0x00000020
772 #define DISP_ENQ_COMPLETE    0x00400000
773 #define DISP_ENQ_OPEN_REF    0x00800000
774 #define DISP_ENQ_CREATE_REF  0x01000000
775 #define DISP_OPEN_LOCK       0x02000000
776
777 /* INODE LOCK PARTS */
778 #define MDS_INODELOCK_LOOKUP 0x000001       /* dentry, mode, owner, group */
779 #define MDS_INODELOCK_UPDATE 0x000002       /* size, links, timestamps */
780 #define MDS_INODELOCK_OPEN   0x000004       /* For opened files */
781
782 /* Do not forget to increase MDS_INODELOCK_MAXSHIFT when adding new bits */
783 #define MDS_INODELOCK_MAXSHIFT 2
784 /* This FULL lock is useful to take on unlink sort of operations */
785 #define MDS_INODELOCK_FULL ((1<<(MDS_INODELOCK_MAXSHIFT+1))-1)
786
787
788 /**
789  * Enumeration of possible directory entry attributes.
790  *
791  * Attributes follow directory entry header in the order they appear in this
792  * enumeration.
793  */
794 enum lu_dirent_attrs {
795         LUDA_FID    = 0x0001,
796         LUDA_TYPE   = 0x0002,
797 };
798
799
800 extern void lustre_swab_ll_fid (struct ll_fid *fid);
801
802 struct lu_fid {
803         __u64 f_seq;  /* holds fid sequence. Lustre should support 2^64
804                        * objects, thus even if one sequence has one object we
805                        * reach this value. */
806         __u32 f_oid;  /* fid number within its sequence. */
807         __u32 f_ver;  /* holds fid version. */
808 };
809
810 #define DFID "[0x%16.16"LPF64"x/0x%8.8x:0x%8.8x]"
811
812 #define PFID(fid)     \
813         fid_seq(fid), \
814         fid_oid(fid), \
815         fid_ver(fid)
816
817 enum {
818         /** put FID sequence at this offset in ldlm_res_id. */
819         LUSTRE_RES_ID_SEQ_OFF = 0,
820         /** put FID oid at this offset in ldlm_res_id. */
821         LUSTRE_RES_ID_OID_OFF = 1,
822         /** put FID version at this offset in ldlm_res_id. */
823         LUSTRE_RES_ID_VER_OFF = 2,
824         /** put pdo hash at this offset in ldlm_res_id. */
825         LUSTRE_RES_ID_HSH_OFF = 3
826 };
827
828 typedef __u64 seqno_t;
829
830 /**
831  * Describes a range of sequence, lsr_start is included but lsr_end is
832  * not in the range.
833  */
834 struct lu_seq_range {
835         __u64 lsr_start;
836         __u64 lsr_end;
837         /** this feild is not used in 1.8 client interop */
838         __u32 lsr_mdt;
839         __u32 lsr_padding;
840 };
841
842 /**
843  * returns  width of given range \a r
844  */
845
846 static inline __u64 range_space(const struct lu_seq_range *r)
847 {
848         return r->lsr_end - r->lsr_start;
849 }
850
851 /**
852  * initialize range to zero
853  */
854 static inline void range_init(struct lu_seq_range *r)
855 {
856         r->lsr_start = r->lsr_end = 0;
857 }
858
859 /**
860  * check if given seq id \a s is within given range \a r
861  */
862 static inline int range_within(const struct lu_seq_range *r,
863                                __u64 s)
864 {
865         return s >= r->lsr_start && s < r->lsr_end;
866 }
867
868 /**
869  * sanity check for range \a r
870  */
871 static inline int range_is_sane(const struct lu_seq_range *r)
872 {
873         return (r->lsr_end >= r->lsr_start);
874 }
875
876 static inline int range_is_zero(struct lu_seq_range *r)
877 {
878         return (r->lsr_start == 0 && r->lsr_end == 0);
879 }
880
881 static inline int range_is_exhausted(const struct lu_seq_range *r)
882 {
883         return range_space(r) == 0;
884 }
885
886 #define DRANGE "[%#16.16"LPF64"x-%#16.16"LPF64"x)"
887
888 #define PRANGE(range)      \
889         (range)->lsr_start, \
890         (range)->lsr_end
891
892 enum {
893         /*
894          * This is how may FIDs may be allocated in one sequence.
895          */
896         LUSTRE_SEQ_MAX_WIDTH = 0x0000000000004000ULL,
897 };
898
899 enum lu_cli_type {
900         LUSTRE_SEQ_METADATA,
901         LUSTRE_SEQ_DATA
902 };
903
904 struct lu_client_seq {
905         /* Sequence-controller export. */
906         struct obd_export      *lcs_exp;
907         struct semaphore        lcs_sem;
908
909         /*
910          * Range of allowed for allocation sequences. When using lu_client_seq
911          * on clients, this contains meta-sequence range. And for servers this
912          * contains super-sequence range.
913          */
914         struct lu_seq_range         lcs_space;
915
916         /* This holds last allocated fid in last obtained seq */
917         struct lu_fid           lcs_fid;
918
919         /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
920         enum lu_cli_type        lcs_type;
921         /*
922          * Service uuid, passed from MDT + seq name to form unique seq name to
923          * use it with procfs.
924          */
925         char                    lcs_name[80];
926
927         /*
928          * Sequence width, that is how many objects may be allocated in one
929          * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
930          */
931         __u64                   lcs_width;
932
933 };
934
935 /*
936  * fid constants
937  */
938 enum {
939         /* initial fid id value */
940         LUSTRE_FID_INIT_OID  = 1UL
941 };
942
943 extern void lustre_swab_lu_fid(struct lu_fid *fid);
944
945 /* get object sequence */
946 static inline __u64 fid_seq(const struct lu_fid *fid)
947 {
948         return fid->f_seq;
949 }
950
951 /* get object id */
952 static inline __u32 fid_oid(const struct lu_fid *fid)
953 {
954         return fid->f_oid;
955 }
956
957 /* get object version */
958 static inline __u32 fid_ver(const struct lu_fid *fid)
959 {
960         return fid->f_ver;
961 }
962
963 static inline void fid_init(struct lu_fid *fid)
964 {
965         memset(fid, 0, sizeof(*fid));
966 }
967
968 /* Normal FID sequence starts from this value, i.e. 1<<33 */
969 #define FID_SEQ_START  0x200000000ULL
970
971 /* IDIF sequence starts from this value, i.e. 1<<32 */
972 #define IDIF_SEQ_START 0x100000000ULL
973
974 /**
975  * Check if a fid is igif or not.
976  * \param fid the fid to be tested.
977  * \return true if the fid is a igif; otherwise false.
978  */
979 static inline int fid_is_igif(const struct lu_fid *fid)
980 {
981         return fid_seq(fid) > 0 && fid_seq(fid) < IDIF_SEQ_START;
982 }
983
984 /**
985  * Check if a fid is idif or not.
986  * \param fid the fid to be tested.
987  * \return true if the fid is a idif; otherwise false.
988  */
989 static inline int fid_is_idif(const struct lu_fid *fid)
990 {
991         return fid_seq(fid) >= IDIF_SEQ_START  && fid_seq(fid) < FID_SEQ_START;
992 }
993
994 /**
995  * Check if a fid sequence is sane or not
996  * \param seq the sequence to be tested.
997  * \return true if the sequence is a sane sequence; otherwise false.
998  */
999 static inline int fid_seq_is_sane(__u64 seq)
1000 {
1001         return seq != 0;
1002 }
1003
1004 /**
1005  * Check if a fid is sane or not
1006  * \param fid the fid to be tested.
1007  * \return true if the fid is sane; otherwise false.
1008  */
1009 static inline int fid_is_sane(const struct lu_fid *fid)
1010 {
1011         return
1012                 fid != NULL &&
1013                 ((fid_seq_is_sane(fid_seq(fid)) && fid_oid(fid) != 0
1014                                                 && fid_ver(fid) == 0) ||
1015                 fid_is_igif(fid));
1016 }
1017 /**
1018  * Check if a fid is zero.
1019  * \param fid the fid to be tested.
1020  * \return true if the fid is zero; otherwise false.
1021  */
1022 static inline int fid_is_zero(const struct lu_fid *fid)
1023 {
1024         return fid_seq(fid) == 0 && fid_oid(fid) == 0;
1025 }
1026
1027 /**
1028  * Get inode number from a igif.
1029  * \param fid a igif to get inode number from.
1030  * \return inode number for the igif.
1031  */
1032 static inline ino_t lu_igif_ino(const struct lu_fid *fid)
1033 {
1034         return fid_seq(fid);
1035 }
1036
1037 /**
1038  * Get inode generation from a igif.
1039  * \param fid a igif to get inode generation from.
1040  * \return inode generation for the igif.
1041  */
1042 static inline __u32 lu_igif_gen(const struct lu_fid *fid)
1043 {
1044         return fid_oid(fid);
1045 }
1046
1047 /**
1048  * Check if two fids are equal or not.
1049  * \param f0 the first fid
1050  * \param f1 the second fid
1051  * \return true if the two fids are equal; otherwise false.
1052  */
1053 static inline int lu_fid_eq(const struct lu_fid *f0,
1054                             const struct lu_fid *f1)
1055 {
1056         /* Check that there is no alignment padding. */
1057         CLASSERT(sizeof *f0 ==
1058                  sizeof f0->f_seq + sizeof f0->f_oid + sizeof f0->f_ver);
1059         LASSERTF(fid_is_igif(f0) || fid_ver(f0) == 0, DFID"\n", PFID(f0));
1060         LASSERTF(fid_is_igif(f1) || fid_ver(f1) == 0, DFID"\n", PFID(f1));
1061         return memcmp(f0, f1, sizeof *f0) == 0;
1062 }
1063
1064 void fid_cpu_to_le(struct lu_fid *dst, const struct lu_fid *src);
1065 void fid_le_to_cpu(struct lu_fid *dst, const struct lu_fid *src);
1066
1067 struct ldlm_res_id *
1068 fid_build_reg_res_name(const struct lu_fid *f, struct ldlm_res_id *name);
1069 int fid_res_name_eq(const struct lu_fid *f, const struct ldlm_res_id *name);
1070
1071 #define MDS_STATUS_CONN 1
1072 #define MDS_STATUS_LOV 2
1073
1074 struct mds_status_req {
1075         __u32  flags;
1076         __u32  repbuf;
1077 };
1078
1079 extern void lustre_swab_mds_status_req (struct mds_status_req *r);
1080
1081 #define MDS_BFLAG_UNCOMMITTED_WRITES   0x1
1082 #define MDS_BFLAG_EXT_FLAGS     0x80000000 /* == EXT3_RESERVED_FL */
1083
1084 /* these should be identical to their EXT3_*_FL counterparts, and are
1085  * redefined here only to avoid dragging in ext3_fs.h */
1086 #define MDS_SYNC_FL             0x00000008 /* Synchronous updates */
1087 #define MDS_IMMUTABLE_FL        0x00000010 /* Immutable file */
1088 #define MDS_APPEND_FL           0x00000020 /* writes to file may only append */
1089 #define MDS_NOATIME_FL          0x00000080 /* do not update atime */
1090 #define MDS_DIRSYNC_FL          0x00010000 /* dirsync behaviour (dir only) */
1091
1092 #ifdef __KERNEL__
1093 /* If MDS_BFLAG_IOC_FLAGS is set it means we requested EXT3_*_FL inode flags
1094  * and we need to decode these into local S_* flags in the inode.  Otherwise
1095  * we pass flags straight through (see bug 9486). */
1096 static inline int ll_ext_to_inode_flags(int flags)
1097 {
1098         return (flags & MDS_BFLAG_EXT_FLAGS) ?
1099                (((flags & MDS_SYNC_FL)      ? S_SYNC      : 0) |
1100                 ((flags & MDS_NOATIME_FL)   ? S_NOATIME   : 0) |
1101                 ((flags & MDS_APPEND_FL)    ? S_APPEND    : 0) |
1102 #if defined(S_DIRSYNC)
1103                 ((flags & MDS_DIRSYNC_FL)   ? S_DIRSYNC   : 0) |
1104 #endif
1105                 ((flags & MDS_IMMUTABLE_FL) ? S_IMMUTABLE : 0)) :
1106                (flags & ~MDS_BFLAG_EXT_FLAGS);
1107 }
1108
1109 /* If keep is set, we do not do anything with iflags, if it is not set, we
1110  * assume that iflags are inode flags and we need to conver those to
1111  * EXT3_*_FL flags (see bug 9486 and 12848) */
1112 static inline int ll_inode_to_ext_flags(int iflags, int keep)
1113 {
1114         return keep ? (iflags & ~MDS_BFLAG_EXT_FLAGS) :
1115                (((iflags & S_SYNC)      ? MDS_SYNC_FL      : 0) |
1116                 ((iflags & S_NOATIME)   ? MDS_NOATIME_FL   : 0) |
1117                 ((iflags & S_APPEND)    ? MDS_APPEND_FL    : 0) |
1118 #if defined(S_DIRSYNC)
1119                 ((iflags & S_DIRSYNC)   ? MDS_DIRSYNC_FL   : 0) |
1120 #endif
1121                 ((iflags & S_IMMUTABLE) ? MDS_IMMUTABLE_FL : 0));
1122 }
1123 #endif
1124
1125 /*
1126  * while mds_body is to interact with 1.6, mdt_body is to interact with 2.0.
1127  * both of them should have the same fields layout, because at client side
1128  * one could be dynamically cast to the other.
1129  *
1130  * mdt_body has large size than mds_body, with unused padding (48 bytes)
1131  * at the end. client always use size of mdt_body to prepare request/reply
1132  * buffers, and actual data could be interepeted as mdt_body or mds_body
1133  * accordingly.
1134  */
1135 struct mds_body {
1136         struct ll_fid  fid1;
1137         struct ll_fid  fid2;
1138         struct lustre_handle handle;
1139         __u64          valid;
1140         __u64          size;   /* Offset, in the case of MDS_READPAGE */
1141         __u64          mtime;
1142         __u64          atime;
1143         __u64          ctime;
1144         __u64          blocks; /* XID, in the case of MDS_READPAGE */
1145         __u64          io_epoch;
1146         __u64          ino;
1147         __u32          fsuid;
1148         __u32          fsgid;
1149         __u32          capability;
1150         __u32          mode;
1151         __u32          uid;
1152         __u32          gid;
1153         __u32          flags; /* from vfs for pin/unpin, MDS_BFLAG for close */
1154         __u32          rdev;
1155         __u32          nlink; /* #bytes to read in the case of MDS_READPAGE */
1156         __u32          generation;
1157         __u32          suppgid;
1158         __u32          eadatasize;
1159         __u32          aclsize;
1160         __u32          max_mdsize;
1161         __u32          max_cookiesize;
1162         __u32          padding_4; /* also fix lustre_swab_mds_body */
1163 };
1164
1165 extern void lustre_swab_mds_body (struct mds_body *b);
1166
1167 struct mdt_body {
1168         struct lu_fid  fid1;
1169         struct lu_fid  fid2;
1170         struct lustre_handle handle;
1171         __u64          valid;
1172         __u64          size;   /* Offset, in the case of MDS_READPAGE */
1173         __u64          mtime;
1174         __u64          atime;
1175         __u64          ctime;
1176         __u64          blocks; /* XID, in the case of MDS_READPAGE */
1177         __u64          ioepoch;
1178         __u64          ino;    /* for 1.6 compatibility */
1179         __u32          fsuid;
1180         __u32          fsgid;
1181         __u32          capability;
1182         __u32          mode;
1183         __u32          uid;
1184         __u32          gid;
1185         __u32          flags; /* from vfs for pin/unpin, MDS_BFLAG for close */
1186         __u32          rdev;
1187         __u32          nlink; /* #bytes to read in the case of MDS_READPAGE */
1188         __u32          generation; /* for 1.6 compatibility */
1189         __u32          suppgid;
1190         __u32          eadatasize;
1191         __u32          aclsize;
1192         __u32          max_mdsize;
1193         __u32          max_cookiesize;
1194         __u32          padding_4; /* also fix lustre_swab_mdt_body */
1195         __u64          padding_5;
1196         __u64          padding_6;
1197         __u64          padding_7;
1198         __u64          padding_8;
1199         __u64          padding_9;
1200         __u64          padding_10;
1201 };
1202
1203 #define Q_QUOTACHECK    0x800100
1204 #define Q_INITQUOTA     0x800101        /* init slave limits */
1205 #define Q_GETOINFO      0x800102        /* get obd quota info */
1206 #define Q_GETOQUOTA     0x800103        /* get obd quotas */
1207 #define Q_FINVALIDATE   0x800104        /* invalidate operational quotas */
1208
1209 #define Q_TYPEMATCH(id, type) \
1210         ((id) == (type) || (id) == UGQUOTA)
1211
1212 #define Q_TYPESET(oqc, type) Q_TYPEMATCH((oqc)->qc_type, type)
1213
1214 #define Q_GETOCMD(oqc) \
1215         ((oqc)->qc_cmd == Q_GETOINFO || (oqc)->qc_cmd == Q_GETOQUOTA)
1216
1217 struct obd_quotactl {
1218         __u32                   qc_cmd;
1219         __u32                   qc_type;
1220         __u32                   qc_id;
1221         __u32                   qc_stat;
1222         struct obd_dqinfo       qc_dqinfo;
1223         struct obd_dqblk        qc_dqblk;
1224 };
1225
1226 extern void lustre_swab_obd_quotactl(struct obd_quotactl *q);
1227
1228 struct quota_adjust_qunit {
1229         __u32 qaq_flags;
1230         __u32 qaq_id;
1231         __u64 qaq_bunit_sz;
1232         __u64 qaq_iunit_sz;
1233         __u64 padding1;
1234 };
1235 extern void lustre_swab_quota_adjust_qunit(struct quota_adjust_qunit *q);
1236
1237 /* flags in qunit_data and quota_adjust_qunit will use macroes below */
1238 #define LQUOTA_FLAGS_GRP       1UL   /* 0 is user, 1 is group */
1239 #define LQUOTA_FLAGS_BLK       2UL   /* 0 is inode, 1 is block */
1240 #define LQUOTA_FLAGS_ADJBLK    4UL   /* adjust the block qunit size */
1241 #define LQUOTA_FLAGS_ADJINO    8UL   /* adjust the inode qunit size */
1242 #define LQUOTA_FLAGS_CHG_QS   16UL   /* indicate whether it has capability of
1243                                       * OBD_CONNECT_CHANGE_QS */
1244
1245 /* the status of lqs_flags in struct lustre_qunit_size  */
1246 #define LQUOTA_QUNIT_FLAGS (LQUOTA_FLAGS_GRP | LQUOTA_FLAGS_BLK)
1247
1248 #define QAQ_IS_GRP(qaq)    ((qaq)->qaq_flags & LQUOTA_FLAGS_GRP)
1249 #define QAQ_IS_ADJBLK(qaq) ((qaq)->qaq_flags & LQUOTA_FLAGS_ADJBLK)
1250 #define QAQ_IS_ADJINO(qaq) ((qaq)->qaq_flags & LQUOTA_FLAGS_ADJINO)
1251
1252 #define QAQ_SET_GRP(qaq)    ((qaq)->qaq_flags |= LQUOTA_FLAGS_GRP)
1253 #define QAQ_SET_ADJBLK(qaq) ((qaq)->qaq_flags |= LQUOTA_FLAGS_ADJBLK)
1254 #define QAQ_SET_ADJINO(qaq) ((qaq)->qaq_flags |= LQUOTA_FLAGS_ADJINO)
1255
1256 struct mds_rec_setattr {
1257         __u32           sa_opcode;
1258         __u32           sa_fsuid;
1259         __u32           sa_fsgid;
1260         __u32           sa_cap;
1261         __u32           sa_suppgid;
1262         __u32           sa_mode;
1263         struct ll_fid   sa_fid;
1264         __u64           sa_valid; /* MDS_ATTR_* attributes */
1265         __u64           sa_size;
1266         __u64           sa_mtime;
1267         __u64           sa_atime;
1268         __u64           sa_ctime;
1269         __u32           sa_uid;
1270         __u32           sa_gid;
1271         __u32           sa_attr_flags;
1272         __u32           sa_padding; /* also fix lustre_swab_mds_rec_setattr */
1273 };
1274
1275 extern void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa);
1276
1277 /*
1278  * Attribute flags used in mds_rec_setattr::sa_valid.
1279  * The kernel's #defines for ATTR_* should not be used over the network
1280  * since the client and MDS may run different kernels (see bug 13828)
1281  * Therefore, we should only use MDS_ATTR_* attributes for sa_valid.
1282  */
1283 #define MDS_ATTR_MODE          0x1ULL /* = 1 */
1284 #define MDS_ATTR_UID           0x2ULL /* = 2 */
1285 #define MDS_ATTR_GID           0x4ULL /* = 4 */
1286 #define MDS_ATTR_SIZE          0x8ULL /* = 8 */
1287 #define MDS_ATTR_ATIME        0x10ULL /* = 16 */
1288 #define MDS_ATTR_MTIME        0x20ULL /* = 32 */
1289 #define MDS_ATTR_CTIME        0x40ULL /* = 64 */
1290 #define MDS_ATTR_ATIME_SET    0x80ULL /* = 128 */
1291 #define MDS_ATTR_MTIME_SET   0x100ULL /* = 256 */
1292 #define MDS_ATTR_FORCE       0x200ULL /* = 512, Not a change, but a change it */
1293 #define MDS_ATTR_ATTR_FLAG   0x400ULL /* = 1024 */
1294 #define MDS_ATTR_KILL_SUID   0x800ULL /* = 2048 */
1295 #define MDS_ATTR_KILL_SGID  0x1000ULL /* = 4096 */
1296 #define MDS_ATTR_CTIME_SET  0x2000ULL /* = 8192 */
1297 #define MDS_ATTR_FROM_OPEN  0x4000ULL /* = 16384, called from open path, ie O_TRUNC */
1298 #define MDS_ATTR_BLOCKS     0x8000ULL /* = 32768 */
1299
1300 #ifndef FMODE_READ
1301 #define FMODE_READ               00000001
1302 #define FMODE_WRITE              00000002
1303 #endif
1304 #define MDS_FMODE_EXEC           00000004
1305 #define MDS_OPEN_CREAT           00000100
1306 #define MDS_OPEN_EXCL            00000200
1307 #define MDS_OPEN_TRUNC           00001000
1308 #define MDS_OPEN_APPEND          00002000
1309 #define MDS_OPEN_SYNC            00010000
1310 #define MDS_OPEN_DIRECTORY       00200000
1311
1312 #define MDS_OPEN_DELAY_CREATE  0100000000 /* delay initial object create */
1313 #define MDS_OPEN_OWNEROVERRIDE 0200000000 /* NFSD rw-reopen ro file for owner */
1314 #define MDS_OPEN_JOIN_FILE     0400000000 /* open for join file*/
1315 #define MDS_CREATE_RMT_ACL    01000000000 /* indicate create on remote server
1316                                            * with default ACL */
1317 #define MDS_CREATE_SLAVE_OBJ  02000000000 /* indicate create slave object
1318                                            * actually, this is for create, not
1319                                            * conflict with other open flags */
1320 #define MDS_OPEN_LOCK         04000000000 /* This open requires open lock */
1321 #define MDS_OPEN_HAS_EA      010000000000 /* specify object create pattern */
1322 #define MDS_OPEN_HAS_OBJS    020000000000 /* Just set the EA the obj exist */
1323
1324 struct mds_rec_create {
1325         __u32           cr_opcode;
1326         __u32           cr_fsuid;
1327         __u32           cr_fsgid;
1328         __u32           cr_cap;
1329         __u32           cr_flags; /* for use with open */
1330         __u32           cr_mode;
1331         struct ll_fid   cr_fid;
1332         struct ll_fid   cr_replayfid;
1333         __u64           cr_time;
1334         __u64           cr_rdev;
1335         __u32           cr_suppgid;
1336         __u32           cr_padding_1; /* also fix lustre_swab_mds_rec_create */
1337         __u32           cr_padding_2; /* also fix lustre_swab_mds_rec_create */
1338         __u32           cr_padding_3; /* also fix lustre_swab_mds_rec_create */
1339         __u32           cr_padding_4; /* also fix lustre_swab_mds_rec_create */
1340         __u32           cr_padding_5; /* also fix lustre_swab_mds_rec_create */
1341 };
1342
1343 extern void lustre_swab_mds_rec_create (struct mds_rec_create *cr);
1344
1345 struct mdt_rec_create {
1346         __u32           cr_opcode;
1347         __u32           cr_cap;
1348         __u32           cr_fsuid;
1349         __u32           cr_fsuid_h;
1350         __u32           cr_fsgid;
1351         __u32           cr_fsgid_h;
1352         __u32           cr_suppgid1;
1353         __u32           cr_suppgid1_h;
1354         __u32           cr_suppgid2;
1355         __u32           cr_suppgid2_h;
1356         struct lu_fid   cr_fid1;
1357         struct lu_fid   cr_fid2;
1358         struct lustre_handle cr_old_handle; /* handle in case of open replay */
1359         __u64           cr_time;
1360         __u64           cr_rdev;
1361         __u64           cr_ioepoch;
1362         __u64           cr_padding_1; /* pad for 64 bits*/
1363         __u32           cr_mode;
1364         __u32           cr_bias;
1365         __u32           cr_flags;     /* for use with open */
1366         __u32           cr_padding_2; /* pad for 64 bits*/
1367         __u32           cr_padding_3; /* pad for 64 bits*/
1368         __u32           cr_padding_4; /* pad for 64 bits*/
1369 };
1370
1371 struct mdt_epoch {
1372         struct lustre_handle handle;
1373         __u64  ioepoch;
1374         __u32  flags;
1375         __u32  padding;
1376 };
1377
1378 struct mds_rec_join {
1379         struct ll_fid  jr_fid;
1380         __u64          jr_headsize;
1381 };
1382
1383 extern void lustre_swab_mds_rec_join (struct mds_rec_join *jr);
1384
1385 struct mdt_rec_join {
1386         struct lu_fid  jr_fid;
1387         __u64          jr_headsize;
1388 };
1389
1390 extern void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr);
1391
1392 struct mds_rec_link {
1393         __u32           lk_opcode;
1394         __u32           lk_fsuid;
1395         __u32           lk_fsgid;
1396         __u32           lk_cap;
1397         __u32           lk_suppgid1;
1398         __u32           lk_suppgid2;
1399         struct ll_fid   lk_fid1;
1400         struct ll_fid   lk_fid2;
1401         __u64           lk_time;
1402         __u32           lk_padding_1;  /* also fix lustre_swab_mds_rec_link */
1403         __u32           lk_padding_2;  /* also fix lustre_swab_mds_rec_link */
1404         __u32           lk_padding_3;  /* also fix lustre_swab_mds_rec_link */
1405         __u32           lk_padding_4;  /* also fix lustre_swab_mds_rec_link */
1406 };
1407
1408 extern void lustre_swab_mds_rec_link (struct mds_rec_link *lk);
1409
1410 struct mdt_rec_link {
1411         __u32           lk_opcode;
1412         __u32           lk_cap;
1413         __u32           lk_fsuid;
1414         __u32           lk_fsuid_h;
1415         __u32           lk_fsgid;
1416         __u32           lk_fsgid_h;
1417         __u32           lk_suppgid1;
1418         __u32           lk_suppgid1_h;
1419         __u32           lk_suppgid2;
1420         __u32           lk_suppgid2_h;
1421         struct lu_fid   lk_fid1;
1422         struct lu_fid   lk_fid2;
1423         __u64           lk_time;
1424         __u64           lk_padding_1;
1425         __u64           lk_padding_2;
1426         __u64           lk_padding_3;
1427         __u64           lk_padding_4;
1428         __u32           lk_bias;
1429         __u32           lk_padding_5;
1430         __u32           lk_padding_6;
1431         __u32           lk_padding_7;
1432         __u32           lk_padding_8;
1433         __u32           lk_padding_9;
1434 };
1435
1436 struct mds_rec_unlink {
1437         __u32           ul_opcode;
1438         __u32           ul_fsuid;
1439         __u32           ul_fsgid;
1440         __u32           ul_cap;
1441         __u32           ul_suppgid;
1442         __u32           ul_mode;
1443         struct ll_fid   ul_fid1;
1444         struct ll_fid   ul_fid2;
1445         __u64           ul_time;
1446         __u32           ul_padding_1; /* also fix lustre_swab_mds_rec_unlink */
1447         __u32           ul_padding_2; /* also fix lustre_swab_mds_rec_unlink */
1448         __u32           ul_padding_3; /* also fix lustre_swab_mds_rec_unlink */
1449         __u32           ul_padding_4; /* also fix lustre_swab_mds_rec_unlink */
1450 };
1451
1452 extern void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul);
1453
1454 struct mdt_rec_unlink {
1455         __u32           ul_opcode;
1456         __u32           ul_cap;
1457         __u32           ul_fsuid;
1458         __u32           ul_fsuid_h;
1459         __u32           ul_fsgid;
1460         __u32           ul_fsgid_h;
1461         __u32           ul_suppgid1;
1462         __u32           ul_suppgid1_h;
1463         __u32           ul_suppgid2;
1464         __u32           ul_suppgid2_h;
1465         struct lu_fid   ul_fid1;
1466         struct lu_fid   ul_fid2;
1467         __u64           ul_time;
1468         __u64           ul_padding_2;
1469         __u64           ul_padding_3;
1470         __u64           ul_padding_4;
1471         __u64           ul_padding_5;
1472         __u32           ul_bias;
1473         __u32           ul_mode;
1474         __u32           ul_padding_6;
1475         __u32           ul_padding_7;
1476         __u32           ul_padding_8;
1477         __u32           ul_padding_9;
1478 };
1479
1480 struct mds_rec_rename {
1481         __u32           rn_opcode;
1482         __u32           rn_fsuid;
1483         __u32           rn_fsgid;
1484         __u32           rn_cap;
1485         __u32           rn_suppgid1;
1486         __u32           rn_suppgid2;
1487         struct ll_fid   rn_fid1;
1488         struct ll_fid   rn_fid2;
1489         __u64           rn_time;
1490         __u32           rn_padding_1; /* also fix lustre_swab_mds_rec_rename */
1491         __u32           rn_padding_2; /* also fix lustre_swab_mds_rec_rename */
1492         __u32           rn_padding_3; /* also fix lustre_swab_mds_rec_rename */
1493         __u32           rn_padding_4; /* also fix lustre_swab_mds_rec_rename */
1494 };
1495
1496 extern void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn);
1497
1498 struct mdt_rec_rename {
1499         __u32           rn_opcode;
1500         __u32           rn_cap;
1501         __u32           rn_fsuid;
1502         __u32           rn_fsuid_h;
1503         __u32           rn_fsgid;
1504         __u32           rn_fsgid_h;
1505         __u32           rn_suppgid1;
1506         __u32           rn_suppgid1_h;
1507         __u32           rn_suppgid2;
1508         __u32           rn_suppgid2_h;
1509         struct lu_fid   rn_fid1;
1510         struct lu_fid   rn_fid2;
1511         __u64           rn_time;
1512         __u64           rn_padding_1;
1513         __u64           rn_padding_2;
1514         __u64           rn_padding_3;
1515         __u64           rn_padding_4;
1516         __u32           rn_bias;      /* some operation flags */
1517         __u32           rn_mode;      /* cross-ref rename has mode */
1518         __u32           rn_padding_5;
1519         __u32           rn_padding_6;
1520         __u32           rn_padding_7;
1521         __u32           rn_padding_8;
1522 };
1523
1524 struct mdt_rec_setattr {
1525         __u32           sa_opcode;
1526         __u32           sa_cap;
1527         __u32           sa_fsuid;
1528         __u32           sa_fsuid_h;
1529         __u32           sa_fsgid;
1530         __u32           sa_fsgid_h;
1531         __u32           sa_suppgid;
1532         __u32           sa_suppgid_h;
1533         __u32           sa_padding_1;
1534         __u32           sa_padding_1_h;
1535         struct lu_fid   sa_fid;
1536         __u64           sa_valid;
1537         __u32           sa_uid;
1538         __u32           sa_gid;
1539         __u64           sa_size;
1540         __u64           sa_blocks;
1541         __u64           sa_mtime;
1542         __u64           sa_atime;
1543         __u64           sa_ctime;
1544         __u32           sa_attr_flags;
1545         __u32           sa_mode;
1546         __u32           sa_padding_2;
1547         __u32           sa_padding_3;
1548         __u32           sa_padding_4;
1549         __u32           sa_padding_5;
1550 };
1551
1552 struct mdt_rec_setxattr {
1553         __u32           sx_opcode;
1554         __u32           sx_cap;
1555         __u32           sx_fsuid;
1556         __u32           sx_fsuid_h;
1557         __u32           sx_fsgid;
1558         __u32           sx_fsgid_h;
1559         __u32           sx_suppgid1;
1560         __u32           sx_suppgid1_h;
1561         __u32           sx_suppgid2;
1562         __u32           sx_suppgid2_h;
1563         struct lu_fid   sx_fid;
1564         __u64           sx_padding_1; /* These three members are lu_fid size */
1565         __u32           sx_padding_2;
1566         __u32           sx_padding_3;
1567         __u64           sx_valid;
1568         __u64           sx_time;
1569         __u64           sx_padding_5;
1570         __u64           sx_padding_6;
1571         __u64           sx_padding_7;
1572         __u32           sx_size;
1573         __u32           sx_flags;
1574         __u32           sx_padding_8;
1575         __u32           sx_padding_9;
1576         __u32           sx_padding_10;
1577         __u32           sx_padding_11;
1578 };
1579
1580 enum seq_rpc_opc {
1581         SEQ_QUERY                       = 700,
1582         SEQ_LAST_OPC,
1583         SEQ_FIRST_OPC                   = SEQ_QUERY
1584 };
1585
1586 enum seq_op {
1587         SEQ_ALLOC_SUPER = 0,
1588         SEQ_ALLOC_META = 1
1589 };
1590
1591
1592 /*
1593  *  LOV data structures
1594  */
1595
1596 #define LOV_MIN_STRIPE_BITS 16   /* maximum PAGE_SIZE (ia64), power of 2 */
1597 #define LOV_MIN_STRIPE_SIZE (1<<LOV_MIN_STRIPE_BITS)
1598 #define LOV_MAX_STRIPE_COUNT  160   /* until bug 4424 is fixed */
1599 #define LOV_V1_INSANE_STRIPE_COUNT 65532 /* maximum stripe count bz13933 */
1600
1601 #define LOV_MAX_UUID_BUFFER_SIZE  8192
1602 /* The size of the buffer the lov/mdc reserves for the
1603  * array of UUIDs returned by the MDS.  With the current
1604  * protocol, this will limit the max number of OSTs per LOV */
1605
1606 #define LOV_DESC_MAGIC 0xB0CCDE5C
1607
1608 /* LOV settings descriptor (should only contain static info) */
1609 struct lov_desc {
1610         __u32 ld_tgt_count;                /* how many OBD's */
1611         __u32 ld_active_tgt_count;         /* how many active */
1612         __u32 ld_default_stripe_count;     /* how many objects are used */
1613         __u32 ld_pattern;                  /* default PATTERN_RAID0 */
1614         __u64 ld_default_stripe_size;      /* in bytes */
1615         __u64 ld_default_stripe_offset;    /* in bytes */
1616         __u32 ld_padding_0;                /* unused */
1617         __u32 ld_qos_maxage;               /* in second */
1618         __u32 ld_padding_1;                /* also fix lustre_swab_lov_desc */
1619         __u32 ld_padding_2;                /* also fix lustre_swab_lov_desc */
1620         struct obd_uuid ld_uuid;
1621 };
1622
1623 #define ld_magic ld_active_tgt_count       /* for swabbing from llogs */
1624
1625 extern void lustre_swab_lov_desc (struct lov_desc *ld);
1626
1627 /*
1628  *   LDLM requests:
1629  */
1630 /* opcodes -- MUST be distinct from OST/MDS opcodes */
1631 typedef enum {
1632         LDLM_ENQUEUE     = 101,
1633         LDLM_CONVERT     = 102,
1634         LDLM_CANCEL      = 103,
1635         LDLM_BL_CALLBACK = 104,
1636         LDLM_CP_CALLBACK = 105,
1637         LDLM_GL_CALLBACK = 106,
1638         LDLM_LAST_OPC
1639 } ldlm_cmd_t;
1640 #define LDLM_FIRST_OPC LDLM_ENQUEUE
1641
1642 #define RES_NAME_SIZE 4
1643 struct ldlm_res_id {
1644         __u64 name[RES_NAME_SIZE];
1645 };
1646
1647 extern void lustre_swab_ldlm_res_id (struct ldlm_res_id *id);
1648
1649 /* lock types */
1650 typedef enum {
1651         LCK_MINMODE = 0,
1652         LCK_EX      = 1,
1653         LCK_PW      = 2,
1654         LCK_PR      = 4,
1655         LCK_CW      = 8,
1656         LCK_CR      = 16,
1657         LCK_NL      = 32,
1658         LCK_GROUP   = 64,
1659         LCK_MAXMODE
1660 } ldlm_mode_t;
1661
1662 #define LCK_MODE_NUM    7
1663
1664 typedef enum {
1665         LDLM_PLAIN     = 10,
1666         LDLM_EXTENT    = 11,
1667         LDLM_FLOCK     = 12,
1668         LDLM_IBITS     = 13,
1669         LDLM_MAX_TYPE
1670 } ldlm_type_t;
1671
1672 #define LDLM_MIN_TYPE LDLM_PLAIN
1673
1674 struct ldlm_extent {
1675         __u64 start;
1676         __u64 end;
1677         __u64 gid;
1678 };
1679
1680 static inline int ldlm_extent_overlap(struct ldlm_extent *ex1,
1681                                       struct ldlm_extent *ex2)
1682 {
1683         return (ex1->start <= ex2->end) && (ex2->start <= ex1->end);
1684 }
1685
1686 struct ldlm_inodebits {
1687         __u64 bits;
1688 };
1689
1690 struct ldlm_flock {
1691         __u64 start;
1692         __u64 end;
1693         __u64 blocking_export;  /* not actually used over the wire */
1694         __u32 blocking_pid;     /* not actually used over the wire */
1695         __u32 pid;
1696 };
1697
1698 /* it's important that the fields of the ldlm_extent structure match
1699  * the first fields of the ldlm_flock structure because there is only
1700  * one ldlm_swab routine to process the ldlm_policy_data_t union. if
1701  * this ever changes we will need to swab the union differently based
1702  * on the resource type. */
1703
1704 typedef union {
1705         struct ldlm_extent l_extent;
1706         struct ldlm_flock  l_flock;
1707         struct ldlm_inodebits l_inodebits;
1708 } ldlm_policy_data_t;
1709
1710 extern void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d);
1711
1712 struct ldlm_intent {
1713         __u64 opc;
1714 };
1715
1716 extern void lustre_swab_ldlm_intent (struct ldlm_intent *i);
1717
1718 struct ldlm_resource_desc {
1719         ldlm_type_t lr_type;
1720         __u32 lr_padding;       /* also fix lustre_swab_ldlm_resource_desc */
1721         struct ldlm_res_id lr_name;
1722 };
1723
1724 extern void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r);
1725
1726 struct ldlm_lock_desc {
1727         struct ldlm_resource_desc l_resource;
1728         ldlm_mode_t l_req_mode;
1729         ldlm_mode_t l_granted_mode;
1730         ldlm_policy_data_t l_policy_data;
1731 };
1732
1733 extern void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l);
1734
1735 #define LDLM_LOCKREQ_HANDLES 2
1736 #define LDLM_ENQUEUE_CANCEL_OFF 1
1737
1738 struct ldlm_request {
1739         __u32 lock_flags;
1740         __u32 lock_count;
1741         struct ldlm_lock_desc lock_desc;
1742         struct lustre_handle lock_handle[LDLM_LOCKREQ_HANDLES];
1743 };
1744
1745 extern void lustre_swab_ldlm_request (struct ldlm_request *rq);
1746
1747 /* If LDLM_ENQUEUE, 1 slot is already occupied, 1 is available.
1748  * Otherwise, 2 are available. */
1749 #define ldlm_request_bufsize(count,type)                                \
1750 ({                                                                      \
1751         int _avail = LDLM_LOCKREQ_HANDLES;                              \
1752         _avail -= (type == LDLM_ENQUEUE ? LDLM_ENQUEUE_CANCEL_OFF : 0); \
1753         sizeof(struct ldlm_request) +                                   \
1754         (count - _avail > 0 ? count - _avail : 0) *                     \
1755         sizeof(struct lustre_handle);                                   \
1756 })
1757
1758 struct ldlm_reply {
1759         __u32 lock_flags;
1760         __u32 lock_padding;     /* also fix lustre_swab_ldlm_reply */
1761         struct ldlm_lock_desc lock_desc;
1762         struct lustre_handle lock_handle;
1763         __u64  lock_policy_res1;
1764         __u64  lock_policy_res2;
1765 };
1766
1767 extern void lustre_swab_ldlm_reply (struct ldlm_reply *r);
1768
1769 /*
1770  * Opcodes for mountconf (mgs and mgc)
1771  */
1772 typedef enum {
1773         MGS_CONNECT = 250,
1774         MGS_DISCONNECT,
1775         MGS_EXCEPTION,         /* node died, etc. */
1776         MGS_TARGET_REG,        /* whenever target starts up */
1777         MGS_TARGET_DEL,
1778         MGS_SET_INFO,
1779         MGS_LAST_OPC
1780 } mgs_cmd_t;
1781 #define MGS_FIRST_OPC MGS_CONNECT
1782
1783 #define MGS_PARAM_MAXLEN 1024
1784 #define KEY_SET_INFO "set_info"
1785
1786 struct mgs_send_param {
1787         char             mgs_param[MGS_PARAM_MAXLEN];
1788 };
1789
1790 /* We pass this info to the MGS so it can write config logs */
1791 #define MTI_NAME_MAXLEN 64
1792 #define MTI_PARAM_MAXLEN 4096
1793 #define MTI_NIDS_MAX 32
1794 struct mgs_target_info {
1795         __u32            mti_lustre_ver;
1796         __u32            mti_stripe_index;
1797         __u32            mti_config_ver;
1798         __u32            mti_flags;
1799         __u32            mti_nid_count;
1800         __u32            padding;                    /* 64 bit align */
1801         char             mti_fsname[MTI_NAME_MAXLEN];
1802         char             mti_svname[MTI_NAME_MAXLEN];
1803         char             mti_uuid[sizeof(struct obd_uuid)];
1804         __u64            mti_nids[MTI_NIDS_MAX];     /* host nids (lnet_nid_t)*/
1805         char             mti_params[MTI_PARAM_MAXLEN];
1806 };
1807
1808 extern void lustre_swab_mgs_target_info(struct mgs_target_info *oinfo);
1809
1810 /* Config marker flags (in config log) */
1811 #define CM_START       0x01
1812 #define CM_END         0x02
1813 #define CM_SKIP        0x04
1814 #define CM_UPGRADE146  0x08
1815 #define CM_EXCLUDE     0x10
1816 #define CM_START_SKIP (CM_START | CM_SKIP)
1817
1818 struct cfg_marker {
1819         __u32             cm_step;       /* aka config version */
1820         __u32             cm_flags;
1821         __u32             cm_vers;       /* lustre release version number */
1822         __u32             padding;       /* 64 bit align */
1823         __u64             cm_createtime; /*when this record was first created */
1824         __u64             cm_canceltime; /*when this record is no longer valid*/
1825         char              cm_tgtname[MTI_NAME_MAXLEN];
1826         char              cm_comment[MTI_NAME_MAXLEN];
1827 };
1828
1829 extern void lustre_swab_cfg_marker(struct cfg_marker *marker,
1830                                    int swab, int size);
1831
1832 /*
1833  * Opcodes for multiple servers.
1834  */
1835
1836 typedef enum {
1837         OBD_PING = 400,
1838         OBD_LOG_CANCEL,
1839         OBD_QC_CALLBACK,
1840         OBD_LAST_OPC
1841 } obd_cmd_t;
1842 #define OBD_FIRST_OPC OBD_PING
1843
1844 /* catalog of log objects */
1845
1846 /** Identifier for a single log object */
1847 struct llog_logid {
1848         __u64                   lgl_oid;
1849         __u64                   lgl_ogr;
1850         __u32                   lgl_ogen;
1851 } __attribute__((packed));
1852
1853 /** Records written to the CATALOGS list */
1854 #define CATLIST "CATALOGS"
1855 struct llog_catid {
1856         struct llog_logid       lci_logid;
1857         __u32                   lci_padding1;
1858         __u32                   lci_padding2;
1859         __u32                   lci_padding3;
1860 } __attribute__((packed));
1861
1862 /** join file lov mds md*/
1863 struct lov_mds_md_join {
1864         struct lov_mds_md lmmj_md;
1865         /*join private info*/
1866         struct llog_logid lmmj_array_id; /*array object id*/
1867         __u32  lmmj_extent_count;        /*array extent count*/
1868 };
1869
1870 /* Log data record types - there is no specific reason that these need to
1871  * be related to the RPC opcodes, but no reason not to (may be handy later?)
1872  */
1873 #define LLOG_OP_MAGIC 0x10600000
1874 #define LLOG_OP_MASK  0xfff00000
1875
1876 typedef enum {
1877         LLOG_PAD_MAGIC   = LLOG_OP_MAGIC | 0x00000,
1878         OST_SZ_REC       = LLOG_OP_MAGIC | 0x00f00,
1879         OST_RAID1_REC    = LLOG_OP_MAGIC | 0x01000,
1880         MDS_UNLINK_REC   = LLOG_OP_MAGIC | 0x10000 | (MDS_REINT << 8) | REINT_UNLINK,
1881         MDS_SETATTR_REC  = LLOG_OP_MAGIC | 0x10000 | (MDS_REINT << 8) | REINT_SETATTR,
1882         MDS_SETATTR64_REC= LLOG_OP_MAGIC | 0x90000 | (MDS_REINT << 8) | REINT_SETATTR,
1883         OBD_CFG_REC      = LLOG_OP_MAGIC | 0x20000,
1884         PTL_CFG_REC      = LLOG_OP_MAGIC | 0x30000, /* obsolete */
1885         LLOG_GEN_REC     = LLOG_OP_MAGIC | 0x40000,
1886         LLOG_JOIN_REC    = LLOG_OP_MAGIC | 0x50000,
1887          /** changelog record type */
1888         CHANGELOG_REC    = LLOG_OP_MAGIC | 0x60000,
1889         LLOG_HDR_MAGIC   = LLOG_OP_MAGIC | 0x45539,
1890         LLOG_LOGID_MAGIC = LLOG_OP_MAGIC | 0x4553b,
1891 } llog_op_type;
1892
1893 /*
1894  * for now, continue to support old pad records which have 0 for their
1895  * type but still need to be swabbed for their length
1896  */
1897 #define LLOG_REC_HDR_NEEDS_SWABBING(r)                                  \
1898         (((r)->lrh_type & __swab32(LLOG_OP_MASK)) ==                    \
1899          __swab32(LLOG_OP_MAGIC) ||                                     \
1900          (((r)->lrh_type == 0) && ((r)->lrh_len > LLOG_CHUNK_SIZE)))
1901
1902 /** Log record header - stored in little endian order.
1903  * Each record must start with this struct, end with a llog_rec_tail,
1904  * and be a multiple of 256 bits in size.
1905  */
1906 struct llog_rec_hdr {
1907         __u32                   lrh_len;
1908         __u32                   lrh_index;
1909         __u32                   lrh_type;
1910         __u32                   padding;
1911 };
1912
1913 struct llog_rec_tail {
1914         __u32 lrt_len;
1915         __u32 lrt_index;
1916 };
1917
1918 struct llog_logid_rec {
1919         struct llog_rec_hdr     lid_hdr;
1920         struct llog_logid       lid_id;
1921         __u32                   padding1;
1922         __u32                   padding2;
1923         __u32                   padding3;
1924         __u32                   padding4;
1925         __u32                   padding5;
1926         struct llog_rec_tail    lid_tail;
1927 } __attribute__((packed));
1928
1929 /** MDS extent description
1930  * It is for joined file extent info, each extent info for joined file
1931  * just like (start, end, lmm).
1932  */
1933 struct mds_extent_desc {
1934         __u64                   med_start; /* extent start */
1935         __u64                   med_len;   /* extent length */
1936         struct lov_mds_md       med_lmm;   /* extent's lmm  */
1937 };
1938
1939 /** Joined file array extent log record*/
1940 struct llog_array_rec {
1941         struct llog_rec_hdr     lmr_hdr;
1942         struct mds_extent_desc  lmr_med;
1943         struct llog_rec_tail    lmr_tail;
1944 };
1945
1946 struct llog_create_rec {
1947         struct llog_rec_hdr     lcr_hdr;
1948         struct ll_fid           lcr_fid;
1949         obd_id                  lcr_oid;
1950         obd_count               lcr_ogr;
1951         __u32                   padding;
1952         struct llog_rec_tail    lcr_tail;
1953 } __attribute__((packed));
1954
1955 struct llog_orphan_rec {
1956         struct llog_rec_hdr     lor_hdr;
1957         obd_id                  lor_oid;
1958         obd_count               lor_ogen;
1959         __u32                   padding;
1960         struct llog_rec_tail    lor_tail;
1961 } __attribute__((packed));
1962
1963 struct llog_unlink_rec {
1964         struct llog_rec_hdr     lur_hdr;
1965         obd_id                  lur_oid;
1966         obd_count               lur_ogr;
1967         obd_count               lur_count; /* to destroy the lost precreated */
1968         struct llog_rec_tail    lur_tail;
1969 } __attribute__((packed));
1970
1971 struct llog_setattr_rec {
1972         struct llog_rec_hdr     lsr_hdr;
1973         obd_id                  lsr_oid;
1974         obd_count               lsr_ogr;
1975         __u32                   lsr_uid;
1976         __u32                   lsr_gid;
1977         __u32                   padding;
1978         struct llog_rec_tail    lsr_tail;
1979 } __attribute__((packed));
1980
1981 struct llog_setattr64_rec {
1982         struct llog_rec_hdr     lsr_hdr;
1983         obd_id                  lsr_oid;
1984         obd_count               lsr_ogr;
1985         __u32                   padding;
1986         __u32                   lsr_uid;
1987         __u32                   lsr_uid_h;
1988         __u32                   lsr_gid;
1989         __u32                   lsr_gid_h;
1990         struct llog_rec_tail    lsr_tail;
1991 } __attribute__((packed));
1992
1993 struct llog_size_change_rec {
1994         struct llog_rec_hdr     lsc_hdr;
1995         struct ll_fid           lsc_fid;
1996         __u32                   lsc_io_epoch;
1997         __u32                   padding;
1998         struct llog_rec_tail    lsc_tail;
1999 } __attribute__((packed));
2000
2001 struct llog_gen {
2002         __u64 mnt_cnt;
2003         __u64 conn_cnt;
2004 } __attribute__((packed));
2005
2006 struct llog_gen_rec {
2007         struct llog_rec_hdr     lgr_hdr;
2008         struct llog_gen         lgr_gen;
2009         struct llog_rec_tail    lgr_tail;
2010 };
2011 /* On-disk header structure of each log object, stored in little endian order */
2012 #define LLOG_CHUNK_SIZE         8192
2013 #define LLOG_HEADER_SIZE        (96)
2014 #define LLOG_BITMAP_BYTES       (LLOG_CHUNK_SIZE - LLOG_HEADER_SIZE)
2015
2016 #define LLOG_MIN_REC_SIZE       (24) /* round(llog_rec_hdr + llog_rec_tail) */
2017
2018 /* flags for the logs */
2019 #define LLOG_F_ZAP_WHEN_EMPTY   0x1
2020 #define LLOG_F_IS_CAT           0x2
2021 #define LLOG_F_IS_PLAIN         0x4
2022
2023 struct llog_log_hdr {
2024         struct llog_rec_hdr     llh_hdr;
2025         __u64                   llh_timestamp;
2026         __u32                   llh_count;
2027         __u32                   llh_bitmap_offset;
2028         __u32                   llh_size;
2029         __u32                   llh_flags;
2030         __u32                   llh_cat_idx;
2031         /* for a catalog the first plain slot is next to it */
2032         struct obd_uuid         llh_tgtuuid;
2033         __u32                   llh_reserved[LLOG_HEADER_SIZE/sizeof(__u32) - 23];
2034         __u32                   llh_bitmap[LLOG_BITMAP_BYTES/sizeof(__u32)];
2035         struct llog_rec_tail    llh_tail;
2036 } __attribute__((packed));
2037
2038 #define LLOG_BITMAP_SIZE(llh)  ((llh->llh_hdr.lrh_len -         \
2039                                  llh->llh_bitmap_offset -       \
2040                                  sizeof(llh->llh_tail)) * 8)
2041
2042 /** log cookies are used to reference a specific log file and a record therein */
2043 struct llog_cookie {
2044         struct llog_logid       lgc_lgl;
2045         __u32                   lgc_subsys;
2046         __u32                   lgc_index;
2047         __u32                   lgc_padding;
2048 } __attribute__((packed));
2049
2050 /** llog protocol */
2051 typedef enum llogd_rpc_ops {
2052         LLOG_ORIGIN_HANDLE_CREATE       = 501,
2053         LLOG_ORIGIN_HANDLE_NEXT_BLOCK   = 502,
2054         LLOG_ORIGIN_HANDLE_READ_HEADER  = 503,
2055         LLOG_ORIGIN_HANDLE_WRITE_REC    = 504,
2056         LLOG_ORIGIN_HANDLE_CLOSE        = 505,
2057         LLOG_ORIGIN_CONNECT             = 506,
2058         LLOG_CATINFO                    = 507,  /* for lfs catinfo */
2059         LLOG_ORIGIN_HANDLE_PREV_BLOCK   = 508,
2060         LLOG_ORIGIN_HANDLE_DESTROY      = 509,  /* for destroy llog object*/
2061         LLOG_LAST_OPC
2062 } llog_cmd_t;
2063 #define LLOG_FIRST_OPC LLOG_ORIGIN_HANDLE_CREATE
2064
2065 struct llogd_body {
2066         struct llog_logid  lgd_logid;
2067         __u32 lgd_ctxt_idx;
2068         __u32 lgd_llh_flags;
2069         __u32 lgd_index;
2070         __u32 lgd_saved_index;
2071         __u32 lgd_len;
2072         __u64 lgd_cur_offset;
2073 } __attribute__((packed));
2074
2075 struct llogd_conn_body {
2076         struct llog_gen         lgdc_gen;
2077         struct llog_logid       lgdc_logid;
2078         __u32                   lgdc_ctxt_idx;
2079 } __attribute__((packed));
2080
2081 struct lov_user_ost_data_join {   /* per-stripe data structure */
2082         __u64 l_extent_start;     /* extent start*/
2083         __u64 l_extent_end;       /* extent end*/
2084         __u64 l_object_id;        /* OST object ID */
2085         __u64 l_object_gr;        /* OST object group (creating MDS number) */
2086         __u32 l_ost_gen;          /* generation of this OST index */
2087         __u32 l_ost_idx;          /* OST index in LOV */
2088 } __attribute__((packed));
2089
2090 struct lov_user_md_join {         /* LOV EA user data (host-endian) */
2091         __u32 lmm_magic;          /* magic number = LOV_MAGIC_JOIN */
2092         __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
2093         __u64 lmm_object_id;      /* LOV object ID */
2094         __u64 lmm_object_gr;      /* LOV object group */
2095         __u32 lmm_stripe_size;    /* size of stripe in bytes */
2096         __u32 lmm_stripe_count;   /* num stripes in use for this object */
2097         __u32 lmm_extent_count;   /* extent count of lmm*/
2098         __u64 lmm_tree_id;        /* mds tree object id */
2099         __u64 lmm_tree_gen;       /* mds tree object gen */
2100         struct llog_logid lmm_array_id; /* mds extent desc llog object id */
2101         struct lov_user_ost_data_join lmm_objects[0]; /* per-stripe data */
2102 } __attribute__((packed));
2103
2104 /* Note: 64-bit types are 64-bit aligned in structure */
2105 struct obdo {
2106         obd_valid               o_valid;        /* hot fields in this obdo */
2107         obd_id                  o_id;
2108         obd_gr                  o_gr;
2109         obd_id                  o_fid;
2110         obd_size                o_size;         /* o_size-o_blocks == ost_lvb */
2111         obd_time                o_mtime;
2112         obd_time                o_atime;
2113         obd_time                o_ctime;
2114         obd_blocks              o_blocks;       /* brw: cli sent cached bytes */
2115         obd_size                o_grant;
2116
2117         /* 32-bit fields start here: keep an even number of them via padding */
2118         obd_blksize             o_blksize;      /* optimal IO blocksize */
2119         obd_mode                o_mode;         /* brw: cli sent cache remain */
2120         obd_uid                 o_uid;
2121         obd_gid                 o_gid;
2122         obd_flag                o_flags;
2123         obd_count               o_nlink;        /* brw: checksum */
2124         obd_count               o_generation;
2125         obd_count               o_misc;         /* brw: o_dropped */
2126         __u32                   o_easize;       /* epoch in ost writes */
2127         __u32                   o_mds;
2128         __u32                   o_stripe_idx;   /* holds stripe idx */
2129         __u32                   o_padding_1;
2130         struct lustre_handle    o_handle;       /* brw: lock handle to prolong locks */
2131         struct llog_cookie      o_lcookie;      /* destroy: unlink cookie from MDS */
2132
2133         __u64                   o_padding_2;
2134         __u64                   o_padding_3;
2135         __u64                   o_padding_4;
2136         __u64                   o_padding_5;
2137         __u64                   o_padding_6;
2138 };
2139
2140 #define o_dirty   o_blocks
2141 #define o_undirty o_mode
2142 #define o_dropped o_misc
2143 #define o_cksum   o_nlink
2144
2145 static inline void lustre_set_wire_obdo(struct obdo *wobdo, struct obdo *lobdo)
2146 {
2147         memcpy(wobdo, lobdo, sizeof(*lobdo));
2148         wobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
2149 }
2150
2151 static inline void lustre_get_wire_obdo(struct obdo *lobdo, struct obdo *wobdo)
2152 {
2153         obd_flag local_flags = lobdo->o_flags & OBD_FL_LOCAL_MASK;
2154
2155         LASSERT(!(wobdo->o_flags & OBD_FL_LOCAL_MASK));
2156         
2157         memcpy(lobdo, wobdo, sizeof(*lobdo));
2158         lobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
2159         lobdo->o_flags |= local_flags;
2160 }
2161
2162 extern void lustre_swab_obdo (struct obdo *o);
2163
2164 /* request structure for OST's */
2165 struct ost_body {
2166         struct  obdo oa;
2167 };
2168
2169 /* Key for FIEMAP to be used in get_info calls */
2170 struct ll_fiemap_info_key {
2171         char    name[8];
2172         struct  obdo oa;
2173         struct  ll_user_fiemap fiemap;
2174 };
2175
2176 extern void lustre_swab_ost_body (struct ost_body *b);
2177 extern void lustre_swab_ost_last_id(obd_id *id);
2178 extern void lustre_swab_fiemap(struct ll_user_fiemap *fiemap);
2179
2180 extern int  lustre_swab_lov_user_md(struct lov_user_md_v1 *lum);
2181 extern int  lustre_swab_lov_user_md_objects(struct lov_user_md *lod);
2182 extern void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj);
2183 extern void lustre_swab_lov_mds_md(struct lov_mds_md *lmm);
2184
2185 /* llog_swab.c */
2186 extern void lustre_swab_llogd_body (struct llogd_body *d);
2187 extern void lustre_swab_llog_hdr (struct llog_log_hdr *h);
2188 extern void lustre_swab_llogd_conn_body (struct llogd_conn_body *d);
2189 extern void lustre_swab_llog_rec(struct llog_rec_hdr  *rec,
2190                                  struct llog_rec_tail *tail);
2191
2192 struct lustre_cfg;
2193 extern void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg);
2194
2195 /* this will be used when OBD_CONNECT_CHANGE_QS is set */
2196 struct qunit_data {
2197         __u32 qd_id;    /* ID appiles to (uid, gid) */
2198         __u32 qd_flags; /* LQUOTA_FLAGS_* affect the responding bits */
2199         __u64 qd_count; /* acquire/release count (bytes for block quota) */
2200         __u64 qd_qunit; /* when a master returns the reply to a slave, it will
2201                          * contain the current corresponding qunit size */
2202         __u64 padding;
2203 };
2204
2205 #define QDATA_IS_GRP(qdata)    ((qdata)->qd_flags & LQUOTA_FLAGS_GRP)
2206 #define QDATA_IS_BLK(qdata)    ((qdata)->qd_flags & LQUOTA_FLAGS_BLK)
2207 #define QDATA_IS_ADJBLK(qdata) ((qdata)->qd_flags & LQUOTA_FLAGS_ADJBLK)
2208 #define QDATA_IS_ADJINO(qdata) ((qdata)->qd_flags & LQUOTA_FLAGS_ADJINO)
2209 #define QDATA_IS_CHANGE_QS(qdata) ((qdata)->qd_flags & LQUOTA_FLAGS_CHG_QS)
2210
2211 #define QDATA_SET_GRP(qdata)    ((qdata)->qd_flags |= LQUOTA_FLAGS_GRP)
2212 #define QDATA_SET_BLK(qdata)    ((qdata)->qd_flags |= LQUOTA_FLAGS_BLK)
2213 #define QDATA_SET_ADJBLK(qdata) ((qdata)->qd_flags |= LQUOTA_FLAGS_ADJBLK)
2214 #define QDATA_SET_ADJINO(qdata) ((qdata)->qd_flags |= LQUOTA_FLAGS_ADJINO)
2215 #define QDATA_SET_CHANGE_QS(qdata) ((qdata)->qd_flags |= LQUOTA_FLAGS_CHG_QS)
2216
2217 #define QDATA_CLR_GRP(qdata)        ((qdata)->qd_flags &= ~LQUOTA_FLAGS_GRP)
2218 #define QDATA_CLR_CHANGE_QS(qdata)  ((qdata)->qd_flags &= ~LQUOTA_FLAGS_CHG_QS)
2219
2220 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(1, 9, 0, 0)
2221 /* this will be used when OBD_CONNECT_QUOTA64 is set */
2222 struct qunit_data_old2 {
2223         __u32 qd_id; /* ID appiles to (uid, gid) */
2224         __u32 qd_flags; /* Quota type (USRQUOTA, GRPQUOTA) occupy one bit;
2225                          * Block quota or file quota occupy one bit */
2226         __u64 qd_count; /* acquire/release count (bytes for block quota) */
2227 };
2228 #else
2229 #warning "remove quota code above for format absolete in new release"
2230 #endif
2231
2232 extern void lustre_swab_qdata(struct qunit_data *d);
2233 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(1, 9, 0, 0)
2234 extern void lustre_swab_qdata_old2(struct qunit_data_old2 *d);
2235 #else
2236 #warning "remove quota code above for format absolete in new release"
2237 #endif
2238 extern int quota_get_qdata(void*req, struct qunit_data *qdata,
2239                            int is_req, int is_exp);
2240 extern int quota_copy_qdata(void *request, struct qunit_data *qdata,
2241                             int is_req, int is_exp);
2242
2243 typedef enum {
2244         QUOTA_DQACQ     = 601,
2245         QUOTA_DQREL     = 602,
2246         QUOTA_LAST_OPC
2247 } quota_cmd_t;
2248 #define QUOTA_FIRST_OPC QUOTA_DQACQ
2249
2250 #define JOIN_FILE_ALIGN 4096
2251
2252 #define QUOTA_REQUEST   1
2253 #define QUOTA_REPLY     0
2254 #define QUOTA_EXPORT    1
2255 #define QUOTA_IMPORT    0
2256
2257 /* quota check function */
2258 #define QUOTA_RET_OK           0 /**< return successfully */
2259 #define QUOTA_RET_NOQUOTA      1 /**< not support quota */
2260 #define QUOTA_RET_NOLIMIT      2 /**< quota limit isn't set */
2261 #define QUOTA_RET_ACQUOTA      4 /**< need to acquire extra quota */
2262
2263 extern int quota_get_qunit_data_size(__u64 flag);
2264
2265 /* security opcodes */
2266 typedef enum {
2267         SEC_CTX_INIT            = 801,
2268         SEC_CTX_INIT_CONT       = 802,
2269         SEC_CTX_FINI            = 803,
2270         SEC_LAST_OPC,
2271         SEC_FIRST_OPC           = SEC_CTX_INIT
2272 } sec_cmd_t;
2273
2274 /*
2275  * capa related definitions
2276  */
2277 #define CAPA_HMAC_MAX_LEN       64
2278 #define CAPA_HMAC_KEY_MAX_LEN   56
2279
2280 /* NB take care when changing the sequence of elements this struct,
2281  * because the offset info is used in find_capa() */
2282 struct lustre_capa {
2283         struct lu_fid   lc_fid;         /** fid */
2284         __u64           lc_opc;         /** operations allowed */
2285         __u64           lc_uid;         /** file owner */
2286         __u64           lc_gid;         /** file group */
2287         __u32           lc_flags;       /** HMAC algorithm & flags */
2288         __u32           lc_keyid;       /** key# used for the capability */
2289         __u32           lc_timeout;     /** capa timeout value (sec) */
2290         __u32           lc_expiry;      /** expiry time (sec) */
2291         __u8            lc_hmac[CAPA_HMAC_MAX_LEN];   /** HMAC */
2292 } __attribute__((packed));
2293
2294 #endif