a6120803c3ca0a2333810b04c7cabf697e972f11
[cascardo/linux.git] / drivers / staging / lustre / lustre / include / lustre / lustre_idl.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/include/lustre/lustre_idl.h
33  *
34  * Lustre wire protocol definitions.
35  */
36
37 /** \defgroup lustreidl lustreidl
38  *
39  * Lustre wire protocol definitions.
40  *
41  * ALL structs passing over the wire should be declared here.  Structs
42  * that are used in interfaces with userspace should go in lustre_user.h.
43  *
44  * All structs being declared here should be built from simple fixed-size
45  * types (__u8, __u16, __u32, __u64) or be built from other types or
46  * structs also declared in this file.  Similarly, all flags and magic
47  * values in those structs should also be declared here.  This ensures
48  * that the Lustre wire protocol is not influenced by external dependencies.
49  *
50  * The only other acceptable items in this file are VERY SIMPLE accessor
51  * functions to avoid callers grubbing inside the structures, and the
52  * prototypes of the swabber functions for each struct.  Nothing that
53  * depends on external functions or definitions should be in here.
54  *
55  * Structs must be properly aligned to put 64-bit values on an 8-byte
56  * boundary.  Any structs being added here must also be added to
57  * utils/wirecheck.c and "make newwiretest" run to regenerate the
58  * utils/wiretest.c sources.  This allows us to verify that wire structs
59  * have the proper alignment/size on all architectures.
60  *
61  * DO NOT CHANGE any of the structs, flags, values declared here and used
62  * in released Lustre versions.  Some structs may have padding fields that
63  * can be used.  Some structs might allow addition at the end (verify this
64  * in the code to ensure that new/old clients that see this larger struct
65  * do not fail, otherwise you need to implement protocol compatibility).
66  *
67  * We assume all nodes are either little-endian or big-endian, and we
68  * always send messages in the sender's native format.  The receiver
69  * detects the message format by checking the 'magic' field of the message
70  * (see lustre_msg_swabbed() below).
71  *
72  * Each wire type has corresponding 'lustre_swab_xxxtypexxx()' routines,
73  * implemented either here, inline (trivial implementations) or in
74  * ptlrpc/pack_generic.c.  These 'swabbers' convert the type from "other"
75  * endian, in-place in the message buffer.
76  *
77  * A swabber takes a single pointer argument.  The caller must already have
78  * verified that the length of the message buffer >= sizeof (type).
79  *
80  * For variable length types, a second 'lustre_swab_v_xxxtypexxx()' routine
81  * may be defined that swabs just the variable part, after the caller has
82  * verified that the message buffer is large enough.
83  *
84  * @{
85  */
86
87 #ifndef _LUSTRE_IDL_H_
88 #define _LUSTRE_IDL_H_
89
90 #include "../../../include/linux/libcfs/libcfs.h"
91 #include "../../../include/linux/lnet/types.h"
92
93 /* Defn's shared with user-space. */
94 #include "lustre_user.h"
95 #include "lustre_errno.h"
96
97 /*
98  *  GENERAL STUFF
99  */
100 /* FOO_REQUEST_PORTAL is for incoming requests on the FOO
101  * FOO_REPLY_PORTAL   is for incoming replies on the FOO
102  * FOO_BULK_PORTAL    is for incoming bulk on the FOO
103  */
104
105 /* Lustre service names are following the format
106  * service name + MDT + seq name
107  */
108 #define LUSTRE_MDT_MAXNAMELEN   80
109
110 #define CONNMGR_REQUEST_PORTAL    1
111 #define CONNMGR_REPLY_PORTAL        2
112 /*#define OSC_REQUEST_PORTAL        3 */
113 #define OSC_REPLY_PORTAL                4
114 /*#define OSC_BULK_PORTAL              5 */
115 #define OST_IO_PORTAL              6
116 #define OST_CREATE_PORTAL              7
117 #define OST_BULK_PORTAL          8
118 /*#define MDC_REQUEST_PORTAL        9 */
119 #define MDC_REPLY_PORTAL               10
120 /*#define MDC_BULK_PORTAL             11 */
121 #define MDS_REQUEST_PORTAL           12
122 /*#define MDS_REPLY_PORTAL           13 */
123 #define MDS_BULK_PORTAL         14
124 #define LDLM_CB_REQUEST_PORTAL   15
125 #define LDLM_CB_REPLY_PORTAL       16
126 #define LDLM_CANCEL_REQUEST_PORTAL     17
127 #define LDLM_CANCEL_REPLY_PORTAL       18
128 /*#define PTLBD_REQUEST_PORTAL     19 */
129 /*#define PTLBD_REPLY_PORTAL         20 */
130 /*#define PTLBD_BULK_PORTAL           21 */
131 #define MDS_SETATTR_PORTAL           22
132 #define MDS_READPAGE_PORTAL         23
133 #define OUT_PORTAL                  24
134
135 #define MGC_REPLY_PORTAL               25
136 #define MGS_REQUEST_PORTAL           26
137 #define MGS_REPLY_PORTAL               27
138 #define OST_REQUEST_PORTAL           28
139 #define FLD_REQUEST_PORTAL           29
140 #define SEQ_METADATA_PORTAL         30
141 #define SEQ_DATA_PORTAL         31
142 #define SEQ_CONTROLLER_PORTAL     32
143 #define MGS_BULK_PORTAL         33
144
145 /* Portal 63 is reserved for the Cray Inc DVS - nic@cray.com, roe@cray.com,
146  *                                              n8851@cray.com
147  */
148
149 /* packet types */
150 #define PTL_RPC_MSG_REQUEST 4711
151 #define PTL_RPC_MSG_ERR     4712
152 #define PTL_RPC_MSG_REPLY   4713
153
154 /* DON'T use swabbed values of MAGIC as magic! */
155 #define LUSTRE_MSG_MAGIC_V2 0x0BD00BD3
156 #define LUSTRE_MSG_MAGIC_V2_SWABBED 0xD30BD00B
157
158 #define LUSTRE_MSG_MAGIC LUSTRE_MSG_MAGIC_V2
159
160 #define PTLRPC_MSG_VERSION  0x00000003
161 #define LUSTRE_VERSION_MASK 0xffff0000
162 #define LUSTRE_OBD_VERSION  0x00010000
163 #define LUSTRE_MDS_VERSION  0x00020000
164 #define LUSTRE_OST_VERSION  0x00030000
165 #define LUSTRE_DLM_VERSION  0x00040000
166 #define LUSTRE_LOG_VERSION  0x00050000
167 #define LUSTRE_MGS_VERSION  0x00060000
168
169 /**
170  * Describes a range of sequence, lsr_start is included but lsr_end is
171  * not in the range.
172  * Same structure is used in fld module where lsr_index field holds mdt id
173  * of the home mdt.
174  */
175 struct lu_seq_range {
176         __u64 lsr_start;
177         __u64 lsr_end;
178         __u32 lsr_index;
179         __u32 lsr_flags;
180 };
181
182 struct lu_seq_range_array {
183         __u32 lsra_count;
184         __u32 lsra_padding;
185         struct lu_seq_range lsra_lsr[0];
186 };
187
188 #define LU_SEQ_RANGE_MDT        0x0
189 #define LU_SEQ_RANGE_OST        0x1
190 #define LU_SEQ_RANGE_ANY        0x3
191
192 #define LU_SEQ_RANGE_MASK       0x3
193
194 static inline unsigned fld_range_type(const struct lu_seq_range *range)
195 {
196         return range->lsr_flags & LU_SEQ_RANGE_MASK;
197 }
198
199 static inline int fld_range_is_ost(const struct lu_seq_range *range)
200 {
201         return fld_range_type(range) == LU_SEQ_RANGE_OST;
202 }
203
204 static inline int fld_range_is_mdt(const struct lu_seq_range *range)
205 {
206         return fld_range_type(range) == LU_SEQ_RANGE_MDT;
207 }
208
209 /**
210  * This all range is only being used when fld client sends fld query request,
211  * but it does not know whether the seq is MDT or OST, so it will send req
212  * with ALL type, which means either seq type gotten from lookup can be
213  * expected.
214  */
215 static inline unsigned fld_range_is_any(const struct lu_seq_range *range)
216 {
217         return fld_range_type(range) == LU_SEQ_RANGE_ANY;
218 }
219
220 static inline void fld_range_set_type(struct lu_seq_range *range,
221                                       unsigned flags)
222 {
223         range->lsr_flags |= flags;
224 }
225
226 static inline void fld_range_set_mdt(struct lu_seq_range *range)
227 {
228         fld_range_set_type(range, LU_SEQ_RANGE_MDT);
229 }
230
231 static inline void fld_range_set_ost(struct lu_seq_range *range)
232 {
233         fld_range_set_type(range, LU_SEQ_RANGE_OST);
234 }
235
236 static inline void fld_range_set_any(struct lu_seq_range *range)
237 {
238         fld_range_set_type(range, LU_SEQ_RANGE_ANY);
239 }
240
241 /**
242  * returns  width of given range \a r
243  */
244
245 static inline __u64 range_space(const struct lu_seq_range *range)
246 {
247         return range->lsr_end - range->lsr_start;
248 }
249
250 /**
251  * initialize range to zero
252  */
253
254 static inline void range_init(struct lu_seq_range *range)
255 {
256         memset(range, 0, sizeof(*range));
257 }
258
259 /**
260  * check if given seq id \a s is within given range \a r
261  */
262
263 static inline int range_within(const struct lu_seq_range *range,
264                                __u64 s)
265 {
266         return s >= range->lsr_start && s < range->lsr_end;
267 }
268
269 static inline int range_is_sane(const struct lu_seq_range *range)
270 {
271         return (range->lsr_end >= range->lsr_start);
272 }
273
274 static inline int range_is_zero(const struct lu_seq_range *range)
275 {
276         return (range->lsr_start == 0 && range->lsr_end == 0);
277 }
278
279 static inline int range_is_exhausted(const struct lu_seq_range *range)
280
281 {
282         return range_space(range) == 0;
283 }
284
285 /* return 0 if two range have the same location */
286 static inline int range_compare_loc(const struct lu_seq_range *r1,
287                                     const struct lu_seq_range *r2)
288 {
289         return r1->lsr_index != r2->lsr_index ||
290                r1->lsr_flags != r2->lsr_flags;
291 }
292
293 #define DRANGE "[%#16.16Lx-%#16.16Lx):%x:%s"
294
295 #define PRANGE(range)           \
296         (range)->lsr_start,     \
297         (range)->lsr_end,       \
298         (range)->lsr_index,     \
299         fld_range_is_mdt(range) ? "mdt" : "ost"
300
301 /** \defgroup lu_fid lu_fid
302  * @{
303  */
304
305 /**
306  * Flags for lustre_mdt_attrs::lma_compat and lustre_mdt_attrs::lma_incompat.
307  * Deprecated since HSM and SOM attributes are now stored in separate on-disk
308  * xattr.
309  */
310 enum lma_compat {
311         LMAC_HSM        = 0x00000001,
312         LMAC_SOM        = 0x00000002,
313         LMAC_NOT_IN_OI  = 0x00000004, /* the object does NOT need OI mapping */
314         LMAC_FID_ON_OST = 0x00000008, /* For OST-object, its OI mapping is
315                                        * under /O/<seq>/d<x>.
316                                        */
317 };
318
319 /**
320  * Masks for all features that should be supported by a Lustre version to
321  * access a specific file.
322  * This information is stored in lustre_mdt_attrs::lma_incompat.
323  */
324 enum lma_incompat {
325         LMAI_RELEASED           = 0x00000001, /* file is released */
326         LMAI_AGENT              = 0x00000002, /* agent inode */
327         LMAI_REMOTE_PARENT      = 0x00000004, /* the parent of the object
328                                                * is on the remote MDT
329                                                */
330 };
331
332 #define LMA_INCOMPAT_SUPP       (LMAI_AGENT | LMAI_REMOTE_PARENT)
333
334 /**
335  * fid constants
336  */
337 enum {
338         /** LASTID file has zero OID */
339         LUSTRE_FID_LASTID_OID = 0UL,
340         /** initial fid id value */
341         LUSTRE_FID_INIT_OID  = 1UL
342 };
343
344 /** returns fid object sequence */
345 static inline __u64 fid_seq(const struct lu_fid *fid)
346 {
347         return fid->f_seq;
348 }
349
350 /** returns fid object id */
351 static inline __u32 fid_oid(const struct lu_fid *fid)
352 {
353         return fid->f_oid;
354 }
355
356 /** returns fid object version */
357 static inline __u32 fid_ver(const struct lu_fid *fid)
358 {
359         return fid->f_ver;
360 }
361
362 static inline void fid_zero(struct lu_fid *fid)
363 {
364         memset(fid, 0, sizeof(*fid));
365 }
366
367 static inline __u64 fid_ver_oid(const struct lu_fid *fid)
368 {
369         return ((__u64)fid_ver(fid) << 32 | fid_oid(fid));
370 }
371
372 /* copytool uses a 32b bitmask field to encode archive-Ids during register
373  * with MDT thru kuc.
374  * archive num = 0 => all
375  * archive num from 1 to 32
376  */
377 #define LL_HSM_MAX_ARCHIVE (sizeof(__u32) * 8)
378
379 /**
380  * Note that reserved SEQ numbers below 12 will conflict with ldiskfs
381  * inodes in the IGIF namespace, so these reserved SEQ numbers can be
382  * used for other purposes and not risk collisions with existing inodes.
383  *
384  * Different FID Format
385  * http://wiki.old.lustre.org/index.php/Architecture_-_Interoperability_fids_zfs
386  */
387 enum fid_seq {
388         FID_SEQ_OST_MDT0        = 0,
389         FID_SEQ_LLOG            = 1, /* unnamed llogs */
390         FID_SEQ_ECHO            = 2,
391         FID_SEQ_OST_MDT1        = 3,
392         FID_SEQ_OST_MAX         = 9, /* Max MDT count before OST_on_FID */
393         FID_SEQ_LLOG_NAME       = 10, /* named llogs */
394         FID_SEQ_RSVD            = 11,
395         FID_SEQ_IGIF            = 12,
396         FID_SEQ_IGIF_MAX        = 0x0ffffffffULL,
397         FID_SEQ_IDIF            = 0x100000000ULL,
398         FID_SEQ_IDIF_MAX        = 0x1ffffffffULL,
399         /* Normal FID sequence starts from this value, i.e. 1<<33 */
400         FID_SEQ_START           = 0x200000000ULL,
401         /* sequence for local pre-defined FIDs listed in local_oid */
402         FID_SEQ_LOCAL_FILE      = 0x200000001ULL,
403         FID_SEQ_DOT_LUSTRE      = 0x200000002ULL,
404         /* sequence is used for local named objects FIDs generated
405          * by local_object_storage library
406          */
407         FID_SEQ_LOCAL_NAME      = 0x200000003ULL,
408         /* Because current FLD will only cache the fid sequence, instead
409          * of oid on the client side, if the FID needs to be exposed to
410          * clients sides, it needs to make sure all of fids under one
411          * sequence will be located in one MDT.
412          */
413         FID_SEQ_SPECIAL         = 0x200000004ULL,
414         FID_SEQ_QUOTA           = 0x200000005ULL,
415         FID_SEQ_QUOTA_GLB       = 0x200000006ULL,
416         FID_SEQ_ROOT            = 0x200000007ULL,  /* Located on MDT0 */
417         FID_SEQ_NORMAL          = 0x200000400ULL,
418         FID_SEQ_LOV_DEFAULT     = 0xffffffffffffffffULL
419 };
420
421 #define OBIF_OID_MAX_BITS          32
422 #define OBIF_MAX_OID            (1ULL << OBIF_OID_MAX_BITS)
423 #define OBIF_OID_MASK          ((1ULL << OBIF_OID_MAX_BITS) - 1)
424 #define IDIF_OID_MAX_BITS          48
425 #define IDIF_MAX_OID            (1ULL << IDIF_OID_MAX_BITS)
426 #define IDIF_OID_MASK          ((1ULL << IDIF_OID_MAX_BITS) - 1)
427
428 /** OID for FID_SEQ_SPECIAL */
429 enum special_oid {
430         /* Big Filesystem Lock to serialize rename operations */
431         FID_OID_SPECIAL_BFL     = 1UL,
432 };
433
434 /** OID for FID_SEQ_DOT_LUSTRE */
435 enum dot_lustre_oid {
436         FID_OID_DOT_LUSTRE  = 1UL,
437         FID_OID_DOT_LUSTRE_OBF = 2UL,
438 };
439
440 static inline int fid_seq_is_mdt0(__u64 seq)
441 {
442         return (seq == FID_SEQ_OST_MDT0);
443 }
444
445 static inline int fid_seq_is_mdt(const __u64 seq)
446 {
447         return seq == FID_SEQ_OST_MDT0 || seq >= FID_SEQ_NORMAL;
448 };
449
450 static inline int fid_seq_is_echo(__u64 seq)
451 {
452         return (seq == FID_SEQ_ECHO);
453 }
454
455 static inline int fid_is_echo(const struct lu_fid *fid)
456 {
457         return fid_seq_is_echo(fid_seq(fid));
458 }
459
460 static inline int fid_seq_is_llog(__u64 seq)
461 {
462         return (seq == FID_SEQ_LLOG);
463 }
464
465 static inline int fid_is_llog(const struct lu_fid *fid)
466 {
467         /* file with OID == 0 is not llog but contains last oid */
468         return fid_seq_is_llog(fid_seq(fid)) && fid_oid(fid) > 0;
469 }
470
471 static inline int fid_seq_is_rsvd(const __u64 seq)
472 {
473         return (seq > FID_SEQ_OST_MDT0 && seq <= FID_SEQ_RSVD);
474 };
475
476 static inline int fid_seq_is_special(const __u64 seq)
477 {
478         return seq == FID_SEQ_SPECIAL;
479 };
480
481 static inline int fid_seq_is_local_file(const __u64 seq)
482 {
483         return seq == FID_SEQ_LOCAL_FILE ||
484                seq == FID_SEQ_LOCAL_NAME;
485 };
486
487 static inline int fid_seq_is_root(const __u64 seq)
488 {
489         return seq == FID_SEQ_ROOT;
490 }
491
492 static inline int fid_seq_is_dot(const __u64 seq)
493 {
494         return seq == FID_SEQ_DOT_LUSTRE;
495 }
496
497 static inline int fid_seq_is_default(const __u64 seq)
498 {
499         return seq == FID_SEQ_LOV_DEFAULT;
500 }
501
502 static inline int fid_is_mdt0(const struct lu_fid *fid)
503 {
504         return fid_seq_is_mdt0(fid_seq(fid));
505 }
506
507 static inline void lu_root_fid(struct lu_fid *fid)
508 {
509         fid->f_seq = FID_SEQ_ROOT;
510         fid->f_oid = 1;
511         fid->f_ver = 0;
512 }
513
514 /**
515  * Check if a fid is igif or not.
516  * \param fid the fid to be tested.
517  * \return true if the fid is a igif; otherwise false.
518  */
519 static inline int fid_seq_is_igif(const __u64 seq)
520 {
521         return seq >= FID_SEQ_IGIF && seq <= FID_SEQ_IGIF_MAX;
522 }
523
524 static inline int fid_is_igif(const struct lu_fid *fid)
525 {
526         return fid_seq_is_igif(fid_seq(fid));
527 }
528
529 /**
530  * Check if a fid is idif or not.
531  * \param fid the fid to be tested.
532  * \return true if the fid is a idif; otherwise false.
533  */
534 static inline int fid_seq_is_idif(const __u64 seq)
535 {
536         return seq >= FID_SEQ_IDIF && seq <= FID_SEQ_IDIF_MAX;
537 }
538
539 static inline int fid_is_idif(const struct lu_fid *fid)
540 {
541         return fid_seq_is_idif(fid_seq(fid));
542 }
543
544 static inline int fid_is_local_file(const struct lu_fid *fid)
545 {
546         return fid_seq_is_local_file(fid_seq(fid));
547 }
548
549 static inline int fid_seq_is_norm(const __u64 seq)
550 {
551         return (seq >= FID_SEQ_NORMAL);
552 }
553
554 static inline int fid_is_norm(const struct lu_fid *fid)
555 {
556         return fid_seq_is_norm(fid_seq(fid));
557 }
558
559 /* convert an OST objid into an IDIF FID SEQ number */
560 static inline __u64 fid_idif_seq(__u64 id, __u32 ost_idx)
561 {
562         return FID_SEQ_IDIF | (ost_idx << 16) | ((id >> 32) & 0xffff);
563 }
564
565 /* convert a packed IDIF FID into an OST objid */
566 static inline __u64 fid_idif_id(__u64 seq, __u32 oid, __u32 ver)
567 {
568         return ((__u64)ver << 48) | ((seq & 0xffff) << 32) | oid;
569 }
570
571 /* extract ost index from IDIF FID */
572 static inline __u32 fid_idif_ost_idx(const struct lu_fid *fid)
573 {
574         return (fid_seq(fid) >> 16) & 0xffff;
575 }
576
577 /* extract OST sequence (group) from a wire ost_id (id/seq) pair */
578 static inline __u64 ostid_seq(const struct ost_id *ostid)
579 {
580         if (fid_seq_is_mdt0(ostid->oi.oi_seq))
581                 return FID_SEQ_OST_MDT0;
582
583         if (unlikely(fid_seq_is_default(ostid->oi.oi_seq)))
584                 return FID_SEQ_LOV_DEFAULT;
585
586         if (fid_is_idif(&ostid->oi_fid))
587                 return FID_SEQ_OST_MDT0;
588
589         return fid_seq(&ostid->oi_fid);
590 }
591
592 /* extract OST objid from a wire ost_id (id/seq) pair */
593 static inline __u64 ostid_id(const struct ost_id *ostid)
594 {
595         if (fid_seq_is_mdt0(ostid->oi.oi_seq))
596                 return ostid->oi.oi_id & IDIF_OID_MASK;
597
598         if (unlikely(fid_seq_is_default(ostid->oi.oi_seq)))
599                 return ostid->oi.oi_id;
600
601         if (fid_is_idif(&ostid->oi_fid))
602                 return fid_idif_id(fid_seq(&ostid->oi_fid),
603                                    fid_oid(&ostid->oi_fid), 0);
604
605         return fid_oid(&ostid->oi_fid);
606 }
607
608 static inline void ostid_set_seq(struct ost_id *oi, __u64 seq)
609 {
610         if (fid_seq_is_mdt0(seq) || fid_seq_is_default(seq)) {
611                 oi->oi.oi_seq = seq;
612         } else {
613                 oi->oi_fid.f_seq = seq;
614                 /* Note: if f_oid + f_ver is zero, we need init it
615                  * to be 1, otherwise, ostid_seq will treat this
616                  * as old ostid (oi_seq == 0)
617                  */
618                 if (oi->oi_fid.f_oid == 0 && oi->oi_fid.f_ver == 0)
619                         oi->oi_fid.f_oid = LUSTRE_FID_INIT_OID;
620         }
621 }
622
623 static inline void ostid_set_seq_mdt0(struct ost_id *oi)
624 {
625         ostid_set_seq(oi, FID_SEQ_OST_MDT0);
626 }
627
628 static inline void ostid_set_seq_echo(struct ost_id *oi)
629 {
630         ostid_set_seq(oi, FID_SEQ_ECHO);
631 }
632
633 static inline void ostid_set_seq_llog(struct ost_id *oi)
634 {
635         ostid_set_seq(oi, FID_SEQ_LLOG);
636 }
637
638 /**
639  * Note: we need check oi_seq to decide where to set oi_id,
640  * so oi_seq should always be set ahead of oi_id.
641  */
642 static inline void ostid_set_id(struct ost_id *oi, __u64 oid)
643 {
644         if (fid_seq_is_mdt0(oi->oi.oi_seq)) {
645                 if (oid >= IDIF_MAX_OID) {
646                         CERROR("Bad %llu to set " DOSTID "\n", oid, POSTID(oi));
647                         return;
648                 }
649                 oi->oi.oi_id = oid;
650         } else if (fid_is_idif(&oi->oi_fid)) {
651                 if (oid >= IDIF_MAX_OID) {
652                         CERROR("Bad %llu to set "DOSTID"\n",
653                                oid, POSTID(oi));
654                         return;
655                 }
656                 oi->oi_fid.f_seq = fid_idif_seq(oid,
657                                                 fid_idif_ost_idx(&oi->oi_fid));
658                 oi->oi_fid.f_oid = oid;
659                 oi->oi_fid.f_ver = oid >> 48;
660         } else {
661                 if (oid > OBIF_MAX_OID) {
662                         CERROR("Bad %llu to set " DOSTID "\n", oid, POSTID(oi));
663                         return;
664                 }
665                 oi->oi_fid.f_oid = oid;
666         }
667 }
668
669 static inline int fid_set_id(struct lu_fid *fid, __u64 oid)
670 {
671         if (unlikely(fid_seq_is_igif(fid->f_seq))) {
672                 CERROR("bad IGIF, "DFID"\n", PFID(fid));
673                 return -EBADF;
674         }
675
676         if (fid_is_idif(fid)) {
677                 if (oid >= IDIF_MAX_OID) {
678                         CERROR("Too large OID %#llx to set IDIF "DFID"\n",
679                                (unsigned long long)oid, PFID(fid));
680                         return -EBADF;
681                 }
682                 fid->f_seq = fid_idif_seq(oid, fid_idif_ost_idx(fid));
683                 fid->f_oid = oid;
684                 fid->f_ver = oid >> 48;
685         } else {
686                 if (oid > OBIF_MAX_OID) {
687                         CERROR("Too large OID %#llx to set REG "DFID"\n",
688                                (unsigned long long)oid, PFID(fid));
689                         return -EBADF;
690                 }
691                 fid->f_oid = oid;
692         }
693         return 0;
694 }
695
696 /**
697  * Unpack an OST object id/seq (group) into a FID.  This is needed for
698  * converting all obdo, lmm, lsm, etc. 64-bit id/seq pairs into proper
699  * FIDs.  Note that if an id/seq is already in FID/IDIF format it will
700  * be passed through unchanged.  Only legacy OST objects in "group 0"
701  * will be mapped into the IDIF namespace so that they can fit into the
702  * struct lu_fid fields without loss.  For reference see:
703  * http://wiki.old.lustre.org/index.php/Architecture_-_Interoperability_fids_zfs
704  */
705 static inline int ostid_to_fid(struct lu_fid *fid, struct ost_id *ostid,
706                                __u32 ost_idx)
707 {
708         __u64 seq = ostid_seq(ostid);
709
710         if (ost_idx > 0xffff) {
711                 CERROR("bad ost_idx, "DOSTID" ost_idx:%u\n", POSTID(ostid),
712                        ost_idx);
713                 return -EBADF;
714         }
715
716         if (fid_seq_is_mdt0(seq)) {
717                 __u64 oid = ostid_id(ostid);
718
719                 /* This is a "legacy" (old 1.x/2.early) OST object in "group 0"
720                  * that we map into the IDIF namespace.  It allows up to 2^48
721                  * objects per OST, as this is the object namespace that has
722                  * been in production for years.  This can handle create rates
723                  * of 1M objects/s/OST for 9 years, or combinations thereof.
724                  */
725                 if (oid >= IDIF_MAX_OID) {
726                         CERROR("bad MDT0 id, " DOSTID " ost_idx:%u\n",
727                                POSTID(ostid), ost_idx);
728                         return -EBADF;
729                 }
730                 fid->f_seq = fid_idif_seq(oid, ost_idx);
731                 /* truncate to 32 bits by assignment */
732                 fid->f_oid = oid;
733                 /* in theory, not currently used */
734                 fid->f_ver = oid >> 48;
735         } else if (likely(!fid_seq_is_default(seq))) {
736                /* This is either an IDIF object, which identifies objects across
737                 * all OSTs, or a regular FID.  The IDIF namespace maps legacy
738                 * OST objects into the FID namespace.  In both cases, we just
739                 * pass the FID through, no conversion needed.
740                 */
741                 if (ostid->oi_fid.f_ver != 0) {
742                         CERROR("bad MDT0 id, " DOSTID " ost_idx:%u\n",
743                                POSTID(ostid), ost_idx);
744                         return -EBADF;
745                 }
746                 *fid = ostid->oi_fid;
747         }
748
749         return 0;
750 }
751
752 /* pack any OST FID into an ostid (id/seq) for the wire/disk */
753 static inline int fid_to_ostid(const struct lu_fid *fid, struct ost_id *ostid)
754 {
755         if (unlikely(fid_seq_is_igif(fid->f_seq))) {
756                 CERROR("bad IGIF, "DFID"\n", PFID(fid));
757                 return -EBADF;
758         }
759
760         if (fid_is_idif(fid)) {
761                 ostid_set_seq_mdt0(ostid);
762                 ostid_set_id(ostid, fid_idif_id(fid_seq(fid), fid_oid(fid),
763                                                 fid_ver(fid)));
764         } else {
765                 ostid->oi_fid = *fid;
766         }
767
768         return 0;
769 }
770
771 /* Check whether the fid is for LAST_ID */
772 static inline int fid_is_last_id(const struct lu_fid *fid)
773 {
774         return (fid_oid(fid) == 0);
775 }
776
777 /**
778  * Get inode number from a igif.
779  * \param fid a igif to get inode number from.
780  * \return inode number for the igif.
781  */
782 static inline ino_t lu_igif_ino(const struct lu_fid *fid)
783 {
784         return fid_seq(fid);
785 }
786
787 void lustre_swab_ost_id(struct ost_id *oid);
788
789 /**
790  * Get inode generation from a igif.
791  * \param fid a igif to get inode generation from.
792  * \return inode generation for the igif.
793  */
794 static inline __u32 lu_igif_gen(const struct lu_fid *fid)
795 {
796         return fid_oid(fid);
797 }
798
799 /**
800  * Build igif from the inode number/generation.
801  */
802 static inline void lu_igif_build(struct lu_fid *fid, __u32 ino, __u32 gen)
803 {
804         fid->f_seq = ino;
805         fid->f_oid = gen;
806         fid->f_ver = 0;
807 }
808
809 /*
810  * Fids are transmitted across network (in the sender byte-ordering),
811  * and stored on disk in big-endian order.
812  */
813 static inline void fid_cpu_to_le(struct lu_fid *dst, const struct lu_fid *src)
814 {
815         dst->f_seq = cpu_to_le64(fid_seq(src));
816         dst->f_oid = cpu_to_le32(fid_oid(src));
817         dst->f_ver = cpu_to_le32(fid_ver(src));
818 }
819
820 static inline void fid_le_to_cpu(struct lu_fid *dst, const struct lu_fid *src)
821 {
822         dst->f_seq = le64_to_cpu(fid_seq(src));
823         dst->f_oid = le32_to_cpu(fid_oid(src));
824         dst->f_ver = le32_to_cpu(fid_ver(src));
825 }
826
827 static inline void fid_cpu_to_be(struct lu_fid *dst, const struct lu_fid *src)
828 {
829         dst->f_seq = cpu_to_be64(fid_seq(src));
830         dst->f_oid = cpu_to_be32(fid_oid(src));
831         dst->f_ver = cpu_to_be32(fid_ver(src));
832 }
833
834 static inline void fid_be_to_cpu(struct lu_fid *dst, const struct lu_fid *src)
835 {
836         dst->f_seq = be64_to_cpu(fid_seq(src));
837         dst->f_oid = be32_to_cpu(fid_oid(src));
838         dst->f_ver = be32_to_cpu(fid_ver(src));
839 }
840
841 static inline int fid_is_sane(const struct lu_fid *fid)
842 {
843         return fid &&
844                ((fid_seq(fid) >= FID_SEQ_START && fid_ver(fid) == 0) ||
845                 fid_is_igif(fid) || fid_is_idif(fid) ||
846                 fid_seq_is_rsvd(fid_seq(fid)));
847 }
848
849 static inline int fid_is_zero(const struct lu_fid *fid)
850 {
851         return fid_seq(fid) == 0 && fid_oid(fid) == 0;
852 }
853
854 void lustre_swab_lu_fid(struct lu_fid *fid);
855 void lustre_swab_lu_seq_range(struct lu_seq_range *range);
856
857 static inline int lu_fid_eq(const struct lu_fid *f0, const struct lu_fid *f1)
858 {
859         return memcmp(f0, f1, sizeof(*f0)) == 0;
860 }
861
862 #define __diff_normalize(val0, val1)                        \
863 ({                                                            \
864         typeof(val0) __val0 = (val0);                      \
865         typeof(val1) __val1 = (val1);                      \
866                                                                 \
867         (__val0 == __val1 ? 0 : __val0 > __val1 ? 1 : -1);     \
868 })
869
870 static inline int lu_fid_cmp(const struct lu_fid *f0,
871                              const struct lu_fid *f1)
872 {
873         return
874                 __diff_normalize(fid_seq(f0), fid_seq(f1)) ?:
875                 __diff_normalize(fid_oid(f0), fid_oid(f1)) ?:
876                 __diff_normalize(fid_ver(f0), fid_ver(f1));
877 }
878
879 static inline void ostid_cpu_to_le(const struct ost_id *src_oi,
880                                    struct ost_id *dst_oi)
881 {
882         if (fid_seq_is_mdt0(ostid_seq(src_oi))) {
883                 dst_oi->oi.oi_id = cpu_to_le64(src_oi->oi.oi_id);
884                 dst_oi->oi.oi_seq = cpu_to_le64(src_oi->oi.oi_seq);
885         } else {
886                 fid_cpu_to_le(&dst_oi->oi_fid, &src_oi->oi_fid);
887         }
888 }
889
890 static inline void ostid_le_to_cpu(const struct ost_id *src_oi,
891                                    struct ost_id *dst_oi)
892 {
893         if (fid_seq_is_mdt0(ostid_seq(src_oi))) {
894                 dst_oi->oi.oi_id = le64_to_cpu(src_oi->oi.oi_id);
895                 dst_oi->oi.oi_seq = le64_to_cpu(src_oi->oi.oi_seq);
896         } else {
897                 fid_le_to_cpu(&dst_oi->oi_fid, &src_oi->oi_fid);
898         }
899 }
900
901 /** @} lu_fid */
902
903 /** \defgroup lu_dir lu_dir
904  * @{
905  */
906
907 /**
908  * Enumeration of possible directory entry attributes.
909  *
910  * Attributes follow directory entry header in the order they appear in this
911  * enumeration.
912  */
913 enum lu_dirent_attrs {
914         LUDA_FID                = 0x0001,
915         LUDA_TYPE               = 0x0002,
916         LUDA_64BITHASH          = 0x0004,
917 };
918
919 /**
920  * Layout of readdir pages, as transmitted on wire.
921  */
922 struct lu_dirent {
923         /** valid if LUDA_FID is set. */
924         struct lu_fid lde_fid;
925         /** a unique entry identifier: a hash or an offset. */
926         __u64    lde_hash;
927         /** total record length, including all attributes. */
928         __u16    lde_reclen;
929         /** name length */
930         __u16    lde_namelen;
931         /** optional variable size attributes following this entry.
932          *  taken from enum lu_dirent_attrs.
933          */
934         __u32    lde_attrs;
935         /** name is followed by the attributes indicated in ->ldp_attrs, in
936          *  their natural order. After the last attribute, padding bytes are
937          *  added to make ->lde_reclen a multiple of 8.
938          */
939         char      lde_name[0];
940 };
941
942 /*
943  * Definitions of optional directory entry attributes formats.
944  *
945  * Individual attributes do not have their length encoded in a generic way. It
946  * is assumed that consumer of an attribute knows its format. This means that
947  * it is impossible to skip over an unknown attribute, except by skipping over all
948  * remaining attributes (by using ->lde_reclen), which is not too
949  * constraining, because new server versions will append new attributes at
950  * the end of an entry.
951  */
952
953 /**
954  * Fid directory attribute: a fid of an object referenced by the entry. This
955  * will be almost always requested by the client and supplied by the server.
956  *
957  * Aligned to 8 bytes.
958  */
959 /* To have compatibility with 1.8, lets have fid in lu_dirent struct. */
960
961 /**
962  * File type.
963  *
964  * Aligned to 2 bytes.
965  */
966 struct luda_type {
967         __u16 lt_type;
968 };
969
970 #ifndef IFSHIFT
971 #define IFSHIFT                 12
972 #endif
973
974 #ifndef IFTODT
975 #define IFTODT(type)            (((type) & S_IFMT) >> IFSHIFT)
976 #endif
977 #ifndef DTTOIF
978 #define DTTOIF(dirtype)         ((dirtype) << IFSHIFT)
979 #endif
980
981 struct lu_dirpage {
982         __u64       ldp_hash_start;
983         __u64       ldp_hash_end;
984         __u32       ldp_flags;
985         __u32       ldp_pad0;
986         struct lu_dirent ldp_entries[0];
987 };
988
989 enum lu_dirpage_flags {
990         /**
991          * dirpage contains no entry.
992          */
993         LDF_EMPTY   = 1 << 0,
994         /**
995          * last entry's lde_hash equals ldp_hash_end.
996          */
997         LDF_COLLIDE = 1 << 1
998 };
999
1000 static inline struct lu_dirent *lu_dirent_start(struct lu_dirpage *dp)
1001 {
1002         if (le32_to_cpu(dp->ldp_flags) & LDF_EMPTY)
1003                 return NULL;
1004         else
1005                 return dp->ldp_entries;
1006 }
1007
1008 static inline struct lu_dirent *lu_dirent_next(struct lu_dirent *ent)
1009 {
1010         struct lu_dirent *next;
1011
1012         if (le16_to_cpu(ent->lde_reclen) != 0)
1013                 next = ((void *)ent) + le16_to_cpu(ent->lde_reclen);
1014         else
1015                 next = NULL;
1016
1017         return next;
1018 }
1019
1020 static inline int lu_dirent_calc_size(int namelen, __u16 attr)
1021 {
1022         int size;
1023
1024         if (attr & LUDA_TYPE) {
1025                 const unsigned align = sizeof(struct luda_type) - 1;
1026
1027                 size = (sizeof(struct lu_dirent) + namelen + align) & ~align;
1028                 size += sizeof(struct luda_type);
1029         } else {
1030                 size = sizeof(struct lu_dirent) + namelen;
1031         }
1032
1033         return (size + 7) & ~7;
1034 }
1035
1036 static inline int lu_dirent_size(struct lu_dirent *ent)
1037 {
1038         if (le16_to_cpu(ent->lde_reclen) == 0) {
1039                 return lu_dirent_calc_size(le16_to_cpu(ent->lde_namelen),
1040                                            le32_to_cpu(ent->lde_attrs));
1041         }
1042         return le16_to_cpu(ent->lde_reclen);
1043 }
1044
1045 #define MDS_DIR_END_OFF 0xfffffffffffffffeULL
1046
1047 /**
1048  * MDS_READPAGE page size
1049  *
1050  * This is the directory page size packed in MDS_READPAGE RPC.
1051  * It's different than PAGE_SIZE because the client needs to
1052  * access the struct lu_dirpage header packed at the beginning of
1053  * the "page" and without this there isn't any way to know find the
1054  * lu_dirpage header is if client and server PAGE_SIZE differ.
1055  */
1056 #define LU_PAGE_SHIFT 12
1057 #define LU_PAGE_SIZE  (1UL << LU_PAGE_SHIFT)
1058 #define LU_PAGE_MASK  (~(LU_PAGE_SIZE - 1))
1059
1060 #define LU_PAGE_COUNT (1 << (PAGE_SHIFT - LU_PAGE_SHIFT))
1061
1062 /** @} lu_dir */
1063
1064 struct lustre_handle {
1065         __u64 cookie;
1066 };
1067
1068 #define DEAD_HANDLE_MAGIC 0xdeadbeefcafebabeULL
1069
1070 static inline int lustre_handle_is_used(struct lustre_handle *lh)
1071 {
1072         return lh->cookie != 0ull;
1073 }
1074
1075 static inline int lustre_handle_equal(const struct lustre_handle *lh1,
1076                                       const struct lustre_handle *lh2)
1077 {
1078         return lh1->cookie == lh2->cookie;
1079 }
1080
1081 static inline void lustre_handle_copy(struct lustre_handle *tgt,
1082                                       struct lustre_handle *src)
1083 {
1084         tgt->cookie = src->cookie;
1085 }
1086
1087 /* flags for lm_flags */
1088 #define MSGHDR_AT_SUPPORT              0x1
1089 #define MSGHDR_CKSUM_INCOMPAT18  0x2
1090
1091 #define lustre_msg lustre_msg_v2
1092 /* we depend on this structure to be 8-byte aligned */
1093 /* this type is only endian-adjusted in lustre_unpack_msg() */
1094 struct lustre_msg_v2 {
1095         __u32 lm_bufcount;
1096         __u32 lm_secflvr;
1097         __u32 lm_magic;
1098         __u32 lm_repsize;
1099         __u32 lm_cksum;
1100         __u32 lm_flags;
1101         __u32 lm_padding_2;
1102         __u32 lm_padding_3;
1103         __u32 lm_buflens[0];
1104 };
1105
1106 /* without gss, ptlrpc_body is put at the first buffer. */
1107 #define PTLRPC_NUM_VERSIONS     4
1108 #define JOBSTATS_JOBID_SIZE     32  /* 32 bytes string */
1109 struct ptlrpc_body_v3 {
1110         struct lustre_handle pb_handle;
1111         __u32 pb_type;
1112         __u32 pb_version;
1113         __u32 pb_opc;
1114         __u32 pb_status;
1115         __u64 pb_last_xid;
1116         __u64 pb_last_seen;
1117         __u64 pb_last_committed;
1118         __u64 pb_transno;
1119         __u32 pb_flags;
1120         __u32 pb_op_flags;
1121         __u32 pb_conn_cnt;
1122         __u32 pb_timeout;  /* for req, the deadline, for rep, the service est */
1123         __u32 pb_service_time; /* for rep, actual service time */
1124         __u32 pb_limit;
1125         __u64 pb_slv;
1126         /* VBR: pre-versions */
1127         __u64 pb_pre_versions[PTLRPC_NUM_VERSIONS];
1128         /* padding for future needs */
1129         __u64 pb_padding[4];
1130         char  pb_jobid[JOBSTATS_JOBID_SIZE];
1131 };
1132
1133 #define ptlrpc_body     ptlrpc_body_v3
1134
1135 struct ptlrpc_body_v2 {
1136         struct lustre_handle pb_handle;
1137         __u32 pb_type;
1138         __u32 pb_version;
1139         __u32 pb_opc;
1140         __u32 pb_status;
1141         __u64 pb_last_xid;
1142         __u64 pb_last_seen;
1143         __u64 pb_last_committed;
1144         __u64 pb_transno;
1145         __u32 pb_flags;
1146         __u32 pb_op_flags;
1147         __u32 pb_conn_cnt;
1148         __u32 pb_timeout;  /* for req, the deadline, for rep, the service est */
1149         __u32 pb_service_time; /* for rep, actual service time, also used for
1150                                 * net_latency of req
1151                                 */
1152         __u32 pb_limit;
1153         __u64 pb_slv;
1154         /* VBR: pre-versions */
1155         __u64 pb_pre_versions[PTLRPC_NUM_VERSIONS];
1156         /* padding for future needs */
1157         __u64 pb_padding[4];
1158 };
1159
1160 void lustre_swab_ptlrpc_body(struct ptlrpc_body *pb);
1161
1162 /* message body offset for lustre_msg_v2 */
1163 /* ptlrpc body offset in all request/reply messages */
1164 #define MSG_PTLRPC_BODY_OFF          0
1165
1166 /* normal request/reply message record offset */
1167 #define REQ_REC_OFF                  1
1168 #define REPLY_REC_OFF              1
1169
1170 /* ldlm request message body offset */
1171 #define DLM_LOCKREQ_OFF          1 /* lockreq offset */
1172 #define DLM_REQ_REC_OFF          2 /* normal dlm request record offset */
1173
1174 /* ldlm intent lock message body offset */
1175 #define DLM_INTENT_IT_OFF              2 /* intent lock it offset */
1176 #define DLM_INTENT_REC_OFF            3 /* intent lock record offset */
1177
1178 /* ldlm reply message body offset */
1179 #define DLM_LOCKREPLY_OFF              1 /* lockrep offset */
1180 #define DLM_REPLY_REC_OFF              2 /* reply record offset */
1181
1182 /** only use in req->rq_{req,rep}_swab_mask */
1183 #define MSG_PTLRPC_HEADER_OFF      31
1184
1185 /* Flags that are operation-specific go in the top 16 bits. */
1186 #define MSG_OP_FLAG_MASK   0xffff0000
1187 #define MSG_OP_FLAG_SHIFT  16
1188
1189 /* Flags that apply to all requests are in the bottom 16 bits */
1190 #define MSG_GEN_FLAG_MASK     0x0000ffff
1191 #define MSG_LAST_REPLAY    0x0001
1192 #define MSG_RESENT              0x0002
1193 #define MSG_REPLAY              0x0004
1194 /* #define MSG_AT_SUPPORT        0x0008
1195  * This was used in early prototypes of adaptive timeouts, and while there
1196  * shouldn't be any users of that code there also isn't a need for using this
1197  * bits. Defer usage until at least 1.10 to avoid potential conflict.
1198  */
1199 #define MSG_DELAY_REPLAY          0x0010
1200 #define MSG_VERSION_REPLAY      0x0020
1201 #define MSG_REQ_REPLAY_DONE       0x0040
1202 #define MSG_LOCK_REPLAY_DONE      0x0080
1203
1204 /*
1205  * Flags for all connect opcodes (MDS_CONNECT, OST_CONNECT)
1206  */
1207
1208 #define MSG_CONNECT_RECOVERING  0x00000001
1209 #define MSG_CONNECT_RECONNECT   0x00000002
1210 #define MSG_CONNECT_REPLAYABLE  0x00000004
1211 /*#define MSG_CONNECT_PEER      0x8 */
1212 #define MSG_CONNECT_LIBCLIENT   0x00000010
1213 #define MSG_CONNECT_INITIAL     0x00000020
1214 #define MSG_CONNECT_ASYNC       0x00000040
1215 #define MSG_CONNECT_NEXT_VER    0x00000080 /* use next version of lustre_msg */
1216 #define MSG_CONNECT_TRANSNO     0x00000100 /* report transno */
1217
1218 /* Connect flags */
1219 #define OBD_CONNECT_RDONLY                0x1ULL /*client has read-only access*/
1220 #define OBD_CONNECT_INDEX                 0x2ULL /*connect specific LOV idx */
1221 #define OBD_CONNECT_MDS                   0x4ULL /*connect from MDT to OST */
1222 #define OBD_CONNECT_GRANT                 0x8ULL /*OSC gets grant at connect */
1223 #define OBD_CONNECT_SRVLOCK              0x10ULL /*server takes locks for cli */
1224 #define OBD_CONNECT_VERSION              0x20ULL /*Lustre versions in ocd */
1225 #define OBD_CONNECT_REQPORTAL            0x40ULL /*Separate non-IO req portal */
1226 #define OBD_CONNECT_ACL                  0x80ULL /*access control lists */
1227 #define OBD_CONNECT_XATTR               0x100ULL /*client use extended attr */
1228 #define OBD_CONNECT_CROW                0x200ULL /*MDS+OST create obj on write*/
1229 #define OBD_CONNECT_TRUNCLOCK           0x400ULL /*locks on server for punch */
1230 #define OBD_CONNECT_TRANSNO             0x800ULL /*replay sends init transno */
1231 #define OBD_CONNECT_IBITS              0x1000ULL /*support for inodebits locks*/
1232 #define OBD_CONNECT_JOIN               0x2000ULL /*files can be concatenated.
1233                                                   *We do not support JOIN FILE
1234                                                   *anymore, reserve this flags
1235                                                   *just for preventing such bit
1236                                                   *to be reused.
1237                                                   */
1238 #define OBD_CONNECT_ATTRFID            0x4000ULL /*Server can GetAttr By Fid*/
1239 #define OBD_CONNECT_NODEVOH            0x8000ULL /*No open hndl on specl nodes*/
1240 #define OBD_CONNECT_RMT_CLIENT        0x10000ULL /* Remote client, never used
1241                                                   * in production. Removed in
1242                                                   * 2.9. Keep this flag to
1243                                                   * avoid reuse.
1244                                                   */
1245 #define OBD_CONNECT_RMT_CLIENT_FORCE  0x20000ULL /* Remote client by force,
1246                                                   * never used in production.
1247                                                   * Removed in 2.9. Keep this
1248                                                   * flag to avoid reuse
1249                                                   */
1250 #define OBD_CONNECT_BRW_SIZE          0x40000ULL /*Max bytes per rpc */
1251 #define OBD_CONNECT_QUOTA64           0x80000ULL /*Not used since 2.4 */
1252 #define OBD_CONNECT_MDS_CAPA         0x100000ULL /*MDS capability */
1253 #define OBD_CONNECT_OSS_CAPA         0x200000ULL /*OSS capability */
1254 #define OBD_CONNECT_CANCELSET        0x400000ULL /*Early batched cancels. */
1255 #define OBD_CONNECT_SOM              0x800000ULL /*Size on MDS */
1256 #define OBD_CONNECT_AT              0x1000000ULL /*client uses AT */
1257 #define OBD_CONNECT_LRU_RESIZE      0x2000000ULL /*LRU resize feature. */
1258 #define OBD_CONNECT_MDS_MDS         0x4000000ULL /*MDS-MDS connection */
1259 #define OBD_CONNECT_REAL            0x8000000ULL /*real connection */
1260 #define OBD_CONNECT_CHANGE_QS      0x10000000ULL /*Not used since 2.4 */
1261 #define OBD_CONNECT_CKSUM          0x20000000ULL /*support several cksum algos*/
1262 #define OBD_CONNECT_FID            0x40000000ULL /*FID is supported by server */
1263 #define OBD_CONNECT_VBR            0x80000000ULL /*version based recovery */
1264 #define OBD_CONNECT_LOV_V3        0x100000000ULL /*client supports LOV v3 EA */
1265 #define OBD_CONNECT_GRANT_SHRINK  0x200000000ULL /* support grant shrink */
1266 #define OBD_CONNECT_SKIP_ORPHAN   0x400000000ULL /* don't reuse orphan objids */
1267 #define OBD_CONNECT_MAX_EASIZE    0x800000000ULL /* preserved for large EA */
1268 #define OBD_CONNECT_FULL20       0x1000000000ULL /* it is 2.0 client */
1269 #define OBD_CONNECT_LAYOUTLOCK   0x2000000000ULL /* client uses layout lock */
1270 #define OBD_CONNECT_64BITHASH    0x4000000000ULL /* client supports 64-bits
1271                                                   * directory hash
1272                                                   */
1273 #define OBD_CONNECT_MAXBYTES     0x8000000000ULL /* max stripe size */
1274 #define OBD_CONNECT_IMP_RECOV   0x10000000000ULL /* imp recovery support */
1275 #define OBD_CONNECT_JOBSTATS    0x20000000000ULL /* jobid in ptlrpc_body */
1276 #define OBD_CONNECT_UMASK       0x40000000000ULL /* create uses client umask */
1277 #define OBD_CONNECT_EINPROGRESS 0x80000000000ULL /* client handles -EINPROGRESS
1278                                                   * RPC error properly
1279                                                   */
1280 #define OBD_CONNECT_GRANT_PARAM 0x100000000000ULL/* extra grant params used for
1281                                                   * finer space reservation
1282                                                   */
1283 #define OBD_CONNECT_FLOCK_OWNER 0x200000000000ULL /* for the fixed 1.8
1284                                                    * policy and 2.x server
1285                                                    */
1286 #define OBD_CONNECT_LVB_TYPE    0x400000000000ULL /* variable type of LVB */
1287 #define OBD_CONNECT_NANOSEC_TIME 0x800000000000ULL /* nanosecond timestamps */
1288 #define OBD_CONNECT_LIGHTWEIGHT 0x1000000000000ULL/* lightweight connection */
1289 #define OBD_CONNECT_SHORTIO     0x2000000000000ULL/* short io */
1290 #define OBD_CONNECT_PINGLESS    0x4000000000000ULL/* pings not required */
1291 #define OBD_CONNECT_FLOCK_DEAD  0x8000000000000ULL/* flock deadlock detection */
1292 #define OBD_CONNECT_DISP_STRIPE 0x10000000000000ULL/*create stripe disposition*/
1293 #define OBD_CONNECT_OPEN_BY_FID 0x20000000000000ULL     /* open by fid won't pack
1294                                                          * name in request
1295                                                          */
1296
1297 /* XXX README XXX:
1298  * Please DO NOT add flag values here before first ensuring that this same
1299  * flag value is not in use on some other branch.  Please clear any such
1300  * changes with senior engineers before starting to use a new flag.  Then,
1301  * submit a small patch against EVERY branch that ONLY adds the new flag,
1302  * updates obd_connect_names[] for lprocfs_rd_connect_flags(), adds the
1303  * flag to check_obd_connect_data(), and updates wiretests accordingly, so it
1304  * can be approved and landed easily to reserve the flag for future use.
1305  */
1306
1307 /* The MNE_SWAB flag is overloading the MDS_MDS bit only for the MGS
1308  * connection.  It is a temporary bug fix for Imperative Recovery interop
1309  * between 2.2 and 2.3 x86/ppc nodes, and can be removed when interop for
1310  * 2.2 clients/servers is no longer needed.  LU-1252/LU-1644.
1311  */
1312 #define OBD_CONNECT_MNE_SWAB             OBD_CONNECT_MDS_MDS
1313
1314 #define OCD_HAS_FLAG(ocd, flg)  \
1315         (!!((ocd)->ocd_connect_flags & OBD_CONNECT_##flg))
1316
1317 /* Features required for this version of the client to work with server */
1318 #define CLIENT_CONNECT_MDT_REQD (OBD_CONNECT_IBITS | OBD_CONNECT_FID | \
1319                                  OBD_CONNECT_FULL20)
1320
1321 #define OBD_OCD_VERSION(major, minor, patch, fix) (((major)<<24) + \
1322                                                   ((minor)<<16) + \
1323                                                   ((patch)<<8) + (fix))
1324 #define OBD_OCD_VERSION_MAJOR(version) ((int)((version)>>24)&255)
1325 #define OBD_OCD_VERSION_MINOR(version) ((int)((version)>>16)&255)
1326 #define OBD_OCD_VERSION_PATCH(version) ((int)((version)>>8)&255)
1327 #define OBD_OCD_VERSION_FIX(version)   ((int)(version)&255)
1328
1329 /* This structure is used for both request and reply.
1330  *
1331  * If we eventually have separate connect data for different types, which we
1332  * almost certainly will, then perhaps we stick a union in here.
1333  */
1334 struct obd_connect_data_v1 {
1335         __u64 ocd_connect_flags; /* OBD_CONNECT_* per above */
1336         __u32 ocd_version;       /* lustre release version number */
1337         __u32 ocd_grant;         /* initial cache grant amount (bytes) */
1338         __u32 ocd_index;         /* LOV index to connect to */
1339         __u32 ocd_brw_size;      /* Maximum BRW size in bytes, must be 2^n */
1340         __u64 ocd_ibits_known;   /* inode bits this client understands */
1341         __u8  ocd_blocksize;     /* log2 of the backend filesystem blocksize */
1342         __u8  ocd_inodespace;    /* log2 of the per-inode space consumption */
1343         __u16 ocd_grant_extent;  /* per-extent grant overhead, in 1K blocks */
1344         __u32 ocd_unused;       /* also fix lustre_swab_connect */
1345         __u64 ocd_transno;       /* first transno from client to be replayed */
1346         __u32 ocd_group;         /* MDS group on OST */
1347         __u32 ocd_cksum_types;   /* supported checksum algorithms */
1348         __u32 ocd_max_easize;    /* How big LOV EA can be on MDS */
1349         __u32 ocd_instance;      /* also fix lustre_swab_connect */
1350         __u64 ocd_maxbytes;      /* Maximum stripe size in bytes */
1351 };
1352
1353 struct obd_connect_data {
1354         __u64 ocd_connect_flags; /* OBD_CONNECT_* per above */
1355         __u32 ocd_version;       /* lustre release version number */
1356         __u32 ocd_grant;         /* initial cache grant amount (bytes) */
1357         __u32 ocd_index;         /* LOV index to connect to */
1358         __u32 ocd_brw_size;      /* Maximum BRW size in bytes */
1359         __u64 ocd_ibits_known;   /* inode bits this client understands */
1360         __u8  ocd_blocksize;     /* log2 of the backend filesystem blocksize */
1361         __u8  ocd_inodespace;    /* log2 of the per-inode space consumption */
1362         __u16 ocd_grant_extent;  /* per-extent grant overhead, in 1K blocks */
1363         __u32 ocd_unused;        /* also fix lustre_swab_connect */
1364         __u64 ocd_transno;       /* first transno from client to be replayed */
1365         __u32 ocd_group;         /* MDS group on OST */
1366         __u32 ocd_cksum_types;   /* supported checksum algorithms */
1367         __u32 ocd_max_easize;    /* How big LOV EA can be on MDS */
1368         __u32 ocd_instance;      /* instance # of this target */
1369         __u64 ocd_maxbytes;      /* Maximum stripe size in bytes */
1370         /* Fields after ocd_maxbytes are only accessible by the receiver
1371          * if the corresponding flag in ocd_connect_flags is set. Accessing
1372          * any field after ocd_maxbytes on the receiver without a valid flag
1373          * may result in out-of-bound memory access and kernel oops.
1374          */
1375         __u64 padding1;   /* added 2.1.0. also fix lustre_swab_connect */
1376         __u64 padding2;   /* added 2.1.0. also fix lustre_swab_connect */
1377         __u64 padding3;   /* added 2.1.0. also fix lustre_swab_connect */
1378         __u64 padding4;   /* added 2.1.0. also fix lustre_swab_connect */
1379         __u64 padding5;   /* added 2.1.0. also fix lustre_swab_connect */
1380         __u64 padding6;   /* added 2.1.0. also fix lustre_swab_connect */
1381         __u64 padding7;   /* added 2.1.0. also fix lustre_swab_connect */
1382         __u64 padding8;   /* added 2.1.0. also fix lustre_swab_connect */
1383         __u64 padding9;   /* added 2.1.0. also fix lustre_swab_connect */
1384         __u64 paddingA;   /* added 2.1.0. also fix lustre_swab_connect */
1385         __u64 paddingB;   /* added 2.1.0. also fix lustre_swab_connect */
1386         __u64 paddingC;   /* added 2.1.0. also fix lustre_swab_connect */
1387         __u64 paddingD;   /* added 2.1.0. also fix lustre_swab_connect */
1388         __u64 paddingE;   /* added 2.1.0. also fix lustre_swab_connect */
1389         __u64 paddingF;   /* added 2.1.0. also fix lustre_swab_connect */
1390 };
1391
1392 /* XXX README XXX:
1393  * Please DO NOT use any fields here before first ensuring that this same
1394  * field is not in use on some other branch.  Please clear any such changes
1395  * with senior engineers before starting to use a new field.  Then, submit
1396  * a small patch against EVERY branch that ONLY adds the new field along with
1397  * the matching OBD_CONNECT flag, so that can be approved and landed easily to
1398  * reserve the flag for future use.
1399  */
1400
1401 void lustre_swab_connect(struct obd_connect_data *ocd);
1402
1403 /*
1404  * Supported checksum algorithms. Up to 32 checksum types are supported.
1405  * (32-bit mask stored in obd_connect_data::ocd_cksum_types)
1406  * Please update DECLARE_CKSUM_NAME/OBD_CKSUM_ALL in obd.h when adding a new
1407  * algorithm and also the OBD_FL_CKSUM* flags.
1408  */
1409 enum cksum_type {
1410         OBD_CKSUM_CRC32  = 0x00000001,
1411         OBD_CKSUM_ADLER  = 0x00000002,
1412         OBD_CKSUM_CRC32C = 0x00000004,
1413 };
1414
1415 /*
1416  *   OST requests: OBDO & OBD request records
1417  */
1418
1419 /* opcodes */
1420 enum ost_cmd {
1421         OST_REPLY      =  0,       /* reply ? */
1422         OST_GETATTR    =  1,
1423         OST_SETATTR    =  2,
1424         OST_READ       =  3,
1425         OST_WRITE      =  4,
1426         OST_CREATE     =  5,
1427         OST_DESTROY    =  6,
1428         OST_GET_INFO   =  7,
1429         OST_CONNECT    =  8,
1430         OST_DISCONNECT =  9,
1431         OST_PUNCH      = 10,
1432         OST_OPEN       = 11,
1433         OST_CLOSE      = 12,
1434         OST_STATFS     = 13,
1435         OST_SYNC       = 16,
1436         OST_SET_INFO   = 17,
1437         OST_QUOTACHECK = 18,
1438         OST_QUOTACTL   = 19,
1439         OST_QUOTA_ADJUST_QUNIT = 20, /* not used since 2.4 */
1440         OST_LAST_OPC
1441 };
1442 #define OST_FIRST_OPC  OST_REPLY
1443
1444 enum obdo_flags {
1445         OBD_FL_INLINEDATA   = 0x00000001,
1446         OBD_FL_OBDMDEXISTS  = 0x00000002,
1447         OBD_FL_DELORPHAN    = 0x00000004, /* if set in o_flags delete orphans */
1448         OBD_FL_NORPC        = 0x00000008, /* set in o_flags do in OSC not OST */
1449         OBD_FL_IDONLY       = 0x00000010, /* set in o_flags only adjust obj id*/
1450         OBD_FL_RECREATE_OBJS = 0x00000020, /* recreate missing obj */
1451         OBD_FL_DEBUG_CHECK  = 0x00000040, /* echo client/server debug check */
1452         OBD_FL_NO_USRQUOTA  = 0x00000100, /* the object's owner is over quota */
1453         OBD_FL_NO_GRPQUOTA  = 0x00000200, /* the object's group is over quota */
1454         OBD_FL_CREATE_CROW  = 0x00000400, /* object should be create on write */
1455         OBD_FL_SRVLOCK      = 0x00000800, /* delegate DLM locking to server */
1456         OBD_FL_CKSUM_CRC32  = 0x00001000, /* CRC32 checksum type */
1457         OBD_FL_CKSUM_ADLER  = 0x00002000, /* ADLER checksum type */
1458         OBD_FL_CKSUM_CRC32C = 0x00004000, /* CRC32C checksum type */
1459         OBD_FL_CKSUM_RSVD2  = 0x00008000, /* for future cksum types */
1460         OBD_FL_CKSUM_RSVD3  = 0x00010000, /* for future cksum types */
1461         OBD_FL_SHRINK_GRANT = 0x00020000, /* object shrink the grant */
1462         OBD_FL_MMAP         = 0x00040000, /* object is mmapped on the client.
1463                                            * XXX: obsoleted - reserved for old
1464                                            * clients prior than 2.2
1465                                            */
1466         OBD_FL_RECOV_RESEND = 0x00080000, /* recoverable resent */
1467         OBD_FL_NOSPC_BLK    = 0x00100000, /* no more block space on OST */
1468         OBD_FL_FLUSH        = 0x00200000, /* flush pages on the OST */
1469         OBD_FL_SHORT_IO     = 0x00400000, /* short io request */
1470
1471         /* Note that while these checksum values are currently separate bits,
1472          * in 2.x we can actually allow all values from 1-31 if we wanted.
1473          */
1474         OBD_FL_CKSUM_ALL    = OBD_FL_CKSUM_CRC32 | OBD_FL_CKSUM_ADLER |
1475                               OBD_FL_CKSUM_CRC32C,
1476
1477         /* mask for local-only flag, which won't be sent over network */
1478         OBD_FL_LOCAL_MASK   = 0xF0000000,
1479 };
1480
1481 #define LOV_MAGIC_V1      0x0BD10BD0
1482 #define LOV_MAGIC        LOV_MAGIC_V1
1483 #define LOV_MAGIC_JOIN_V1 0x0BD20BD0
1484 #define LOV_MAGIC_V3      0x0BD30BD0
1485
1486 /*
1487  * magic for fully defined striping
1488  * the idea is that we should have different magics for striping "hints"
1489  * (struct lov_user_md_v[13]) and defined ready-to-use striping (struct
1490  * lov_mds_md_v[13]). at the moment the magics are used in wire protocol,
1491  * we can't just change it w/o long way preparation, but we still need a
1492  * mechanism to allow LOD to differentiate hint versus ready striping.
1493  * so, at the moment we do a trick: MDT knows what to expect from request
1494  * depending on the case (replay uses ready striping, non-replay req uses
1495  * hints), so MDT replaces magic with appropriate one and now LOD can
1496  * easily understand what's inside -bzzz
1497  */
1498 #define LOV_MAGIC_V1_DEF  0x0CD10BD0
1499 #define LOV_MAGIC_V3_DEF  0x0CD30BD0
1500
1501 #define LOV_PATTERN_RAID0       0x001   /* stripes are used round-robin */
1502 #define LOV_PATTERN_RAID1       0x002   /* stripes are mirrors of each other */
1503 #define LOV_PATTERN_FIRST       0x100   /* first stripe is not in round-robin */
1504 #define LOV_PATTERN_CMOBD       0x200
1505
1506 #define LOV_PATTERN_F_MASK      0xffff0000
1507 #define LOV_PATTERN_F_RELEASED  0x80000000 /* HSM released file */
1508
1509 #define lov_pattern(pattern)            (pattern & ~LOV_PATTERN_F_MASK)
1510 #define lov_pattern_flags(pattern)      (pattern & LOV_PATTERN_F_MASK)
1511
1512 #define lov_ost_data lov_ost_data_v1
1513 struct lov_ost_data_v1 {          /* per-stripe data structure (little-endian)*/
1514         struct ost_id l_ost_oi;   /* OST object ID */
1515         __u32 l_ost_gen;          /* generation of this l_ost_idx */
1516         __u32 l_ost_idx;          /* OST index in LOV (lov_tgt_desc->tgts) */
1517 };
1518
1519 #define lov_mds_md lov_mds_md_v1
1520 struct lov_mds_md_v1 {      /* LOV EA mds/wire data (little-endian) */
1521         __u32 lmm_magic;          /* magic number = LOV_MAGIC_V1 */
1522         __u32 lmm_pattern;      /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
1523         struct ost_id   lmm_oi;   /* LOV object ID */
1524         __u32 lmm_stripe_size;    /* size of stripe in bytes */
1525         /* lmm_stripe_count used to be __u32 */
1526         __u16 lmm_stripe_count;   /* num stripes in use for this object */
1527         __u16 lmm_layout_gen;     /* layout generation number */
1528         struct lov_ost_data_v1 lmm_objects[0]; /* per-stripe data */
1529 };
1530
1531 /**
1532  * Sigh, because pre-2.4 uses
1533  * struct lov_mds_md_v1 {
1534  *      ........
1535  *      __u64 lmm_object_id;
1536  *      __u64 lmm_object_seq;
1537  *      ......
1538  *      }
1539  * to identify the LOV(MDT) object, and lmm_object_seq will
1540  * be normal_fid, which make it hard to combine these conversion
1541  * to ostid_to FID. so we will do lmm_oi/fid conversion separately
1542  *
1543  * We can tell the lmm_oi by this way,
1544  * 1.8: lmm_object_id = {inode}, lmm_object_gr = 0
1545  * 2.1: lmm_object_id = {oid < 128k}, lmm_object_seq = FID_SEQ_NORMAL
1546  * 2.4: lmm_oi.f_seq = FID_SEQ_NORMAL, lmm_oi.f_oid = {oid < 128k},
1547  *      lmm_oi.f_ver = 0
1548  *
1549  * But currently lmm_oi/lsm_oi does not have any "real" usages,
1550  * except for printing some information, and the user can always
1551  * get the real FID from LMA, besides this multiple case check might
1552  * make swab more complicate. So we will keep using id/seq for lmm_oi.
1553  */
1554
1555 static inline void fid_to_lmm_oi(const struct lu_fid *fid,
1556                                  struct ost_id *oi)
1557 {
1558         oi->oi.oi_id = fid_oid(fid);
1559         oi->oi.oi_seq = fid_seq(fid);
1560 }
1561
1562 static inline void lmm_oi_set_seq(struct ost_id *oi, __u64 seq)
1563 {
1564         oi->oi.oi_seq = seq;
1565 }
1566
1567 static inline void lmm_oi_set_id(struct ost_id *oi, __u64 oid)
1568 {
1569         oi->oi.oi_id = oid;
1570 }
1571
1572 static inline __u64 lmm_oi_id(struct ost_id *oi)
1573 {
1574         return oi->oi.oi_id;
1575 }
1576
1577 static inline __u64 lmm_oi_seq(struct ost_id *oi)
1578 {
1579         return oi->oi.oi_seq;
1580 }
1581
1582 static inline void lmm_oi_le_to_cpu(struct ost_id *dst_oi,
1583                                     struct ost_id *src_oi)
1584 {
1585         dst_oi->oi.oi_id = le64_to_cpu(src_oi->oi.oi_id);
1586         dst_oi->oi.oi_seq = le64_to_cpu(src_oi->oi.oi_seq);
1587 }
1588
1589 static inline void lmm_oi_cpu_to_le(struct ost_id *dst_oi,
1590                                     struct ost_id *src_oi)
1591 {
1592         dst_oi->oi.oi_id = cpu_to_le64(src_oi->oi.oi_id);
1593         dst_oi->oi.oi_seq = cpu_to_le64(src_oi->oi.oi_seq);
1594 }
1595
1596 /* extern void lustre_swab_lov_mds_md(struct lov_mds_md *llm); */
1597
1598 #define MAX_MD_SIZE                                                     \
1599         (sizeof(struct lov_mds_md) + 4 * sizeof(struct lov_ost_data))
1600 #define MIN_MD_SIZE                                                     \
1601         (sizeof(struct lov_mds_md) + 1 * sizeof(struct lov_ost_data))
1602
1603 #define XATTR_NAME_ACL_ACCESS   "system.posix_acl_access"
1604 #define XATTR_NAME_ACL_DEFAULT  "system.posix_acl_default"
1605 #define XATTR_USER_PREFIX       "user."
1606 #define XATTR_TRUSTED_PREFIX    "trusted."
1607 #define XATTR_SECURITY_PREFIX   "security."
1608 #define XATTR_LUSTRE_PREFIX     "lustre."
1609
1610 #define XATTR_NAME_LOV    "trusted.lov"
1611 #define XATTR_NAME_LMA    "trusted.lma"
1612 #define XATTR_NAME_LMV    "trusted.lmv"
1613 #define XATTR_NAME_DEFAULT_LMV  "trusted.dmv"
1614 #define XATTR_NAME_LINK  "trusted.link"
1615 #define XATTR_NAME_FID    "trusted.fid"
1616 #define XATTR_NAME_VERSION      "trusted.version"
1617 #define XATTR_NAME_SOM          "trusted.som"
1618 #define XATTR_NAME_HSM          "trusted.hsm"
1619 #define XATTR_NAME_LFSCK_NAMESPACE "trusted.lfsck_namespace"
1620
1621 struct lov_mds_md_v3 {      /* LOV EA mds/wire data (little-endian) */
1622         __u32 lmm_magic;          /* magic number = LOV_MAGIC_V3 */
1623         __u32 lmm_pattern;      /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
1624         struct ost_id   lmm_oi;   /* LOV object ID */
1625         __u32 lmm_stripe_size;    /* size of stripe in bytes */
1626         /* lmm_stripe_count used to be __u32 */
1627         __u16 lmm_stripe_count;   /* num stripes in use for this object */
1628         __u16 lmm_layout_gen;     /* layout generation number */
1629         char  lmm_pool_name[LOV_MAXPOOLNAME]; /* must be 32bit aligned */
1630         struct lov_ost_data_v1 lmm_objects[0]; /* per-stripe data */
1631 };
1632
1633 static inline __u32 lov_mds_md_size(__u16 stripes, __u32 lmm_magic)
1634 {
1635         if (lmm_magic == LOV_MAGIC_V3)
1636                 return sizeof(struct lov_mds_md_v3) +
1637                                 stripes * sizeof(struct lov_ost_data_v1);
1638         else
1639                 return sizeof(struct lov_mds_md_v1) +
1640                                 stripes * sizeof(struct lov_ost_data_v1);
1641 }
1642
1643 static inline __u32
1644 lov_mds_md_max_stripe_count(size_t buf_size, __u32 lmm_magic)
1645 {
1646         switch (lmm_magic) {
1647         case LOV_MAGIC_V1: {
1648                 struct lov_mds_md_v1 lmm;
1649
1650                 if (buf_size < sizeof(lmm))
1651                         return 0;
1652
1653                 return (buf_size - sizeof(lmm)) / sizeof(lmm.lmm_objects[0]);
1654         }
1655         case LOV_MAGIC_V3: {
1656                 struct lov_mds_md_v3 lmm;
1657
1658                 if (buf_size < sizeof(lmm))
1659                         return 0;
1660
1661                 return (buf_size - sizeof(lmm)) / sizeof(lmm.lmm_objects[0]);
1662         }
1663         default:
1664                 return 0;
1665         }
1666 }
1667
1668 #define OBD_MD_FLID        (0x00000001ULL) /* object ID */
1669 #define OBD_MD_FLATIME     (0x00000002ULL) /* access time */
1670 #define OBD_MD_FLMTIME     (0x00000004ULL) /* data modification time */
1671 #define OBD_MD_FLCTIME     (0x00000008ULL) /* change time */
1672 #define OBD_MD_FLSIZE      (0x00000010ULL) /* size */
1673 #define OBD_MD_FLBLOCKS    (0x00000020ULL) /* allocated blocks count */
1674 #define OBD_MD_FLBLKSZ     (0x00000040ULL) /* block size */
1675 #define OBD_MD_FLMODE      (0x00000080ULL) /* access bits (mode & ~S_IFMT) */
1676 #define OBD_MD_FLTYPE      (0x00000100ULL) /* object type (mode & S_IFMT) */
1677 #define OBD_MD_FLUID       (0x00000200ULL) /* user ID */
1678 #define OBD_MD_FLGID       (0x00000400ULL) /* group ID */
1679 #define OBD_MD_FLFLAGS     (0x00000800ULL) /* flags word */
1680 #define OBD_MD_FLNLINK     (0x00002000ULL) /* link count */
1681 #define OBD_MD_FLGENER     (0x00004000ULL) /* generation number */
1682 /*#define OBD_MD_FLINLINE    (0x00008000ULL)  inline data. used until 1.6.5 */
1683 #define OBD_MD_FLRDEV      (0x00010000ULL) /* device number */
1684 #define OBD_MD_FLEASIZE    (0x00020000ULL) /* extended attribute data */
1685 #define OBD_MD_LINKNAME    (0x00040000ULL) /* symbolic link target */
1686 #define OBD_MD_FLHANDLE    (0x00080000ULL) /* file/lock handle */
1687 #define OBD_MD_FLCKSUM     (0x00100000ULL) /* bulk data checksum */
1688 #define OBD_MD_FLQOS       (0x00200000ULL) /* quality of service stats */
1689 /*#define OBD_MD_FLOSCOPQ    (0x00400000ULL) osc opaque data, never used */
1690 #define OBD_MD_FLCOOKIE    (0x00800000ULL) /* log cancellation cookie */
1691 #define OBD_MD_FLGROUP     (0x01000000ULL) /* group */
1692 #define OBD_MD_FLFID       (0x02000000ULL) /* ->ost write inline fid */
1693 #define OBD_MD_FLEPOCH     (0x04000000ULL) /* ->ost write with ioepoch */
1694                                            /* ->mds if epoch opens or closes
1695                                             */
1696 #define OBD_MD_FLGRANT     (0x08000000ULL) /* ost preallocation space grant */
1697 #define OBD_MD_FLDIREA     (0x10000000ULL) /* dir's extended attribute data */
1698 #define OBD_MD_FLUSRQUOTA  (0x20000000ULL) /* over quota flags sent from ost */
1699 #define OBD_MD_FLGRPQUOTA  (0x40000000ULL) /* over quota flags sent from ost */
1700 #define OBD_MD_FLMODEASIZE (0x80000000ULL) /* EA size will be changed */
1701
1702 #define OBD_MD_MDS         (0x0000000100000000ULL) /* where an inode lives on */
1703 #define OBD_MD_REINT       (0x0000000200000000ULL) /* reintegrate oa */
1704 #define OBD_MD_MEA         (0x0000000400000000ULL) /* CMD split EA  */
1705 #define OBD_MD_TSTATE      (0x0000000800000000ULL) /* transient state field */
1706
1707 #define OBD_MD_FLXATTR       (0x0000001000000000ULL) /* xattr */
1708 #define OBD_MD_FLXATTRLS     (0x0000002000000000ULL) /* xattr list */
1709 #define OBD_MD_FLXATTRRM     (0x0000004000000000ULL) /* xattr remove */
1710 #define OBD_MD_FLACL         (0x0000008000000000ULL) /* ACL */
1711 /*      OBD_MD_FLRMTPERM     (0x0000010000000000ULL) remote perm, obsolete */
1712 #define OBD_MD_FLMDSCAPA     (0x0000020000000000ULL) /* MDS capability */
1713 #define OBD_MD_FLOSSCAPA     (0x0000040000000000ULL) /* OSS capability */
1714 #define OBD_MD_FLCKSPLIT     (0x0000080000000000ULL) /* Check split on server */
1715 #define OBD_MD_FLCROSSREF    (0x0000100000000000ULL) /* Cross-ref case */
1716 #define OBD_MD_FLGETATTRLOCK (0x0000200000000000ULL) /* Get IOEpoch attributes
1717                                                       * under lock; for xattr
1718                                                       * requests means the
1719                                                       * client holds the lock
1720                                                       */
1721 #define OBD_MD_FLOBJCOUNT    (0x0000400000000000ULL) /* for multiple destroy */
1722
1723 /*      OBD_MD_FLRMTLSETFACL (0x0001000000000000ULL) lfs lsetfacl, obsolete */
1724 /*      OBD_MD_FLRMTLGETFACL (0x0002000000000000ULL) lfs lgetfacl, obsolete */
1725 /*      OBD_MD_FLRMTRSETFACL (0x0004000000000000ULL) lfs rsetfacl, obsolete */
1726 /*      OBD_MD_FLRMTRGETFACL (0x0008000000000000ULL) lfs rgetfacl, obsolete */
1727
1728 #define OBD_MD_FLDATAVERSION (0x0010000000000000ULL) /* iversion sum */
1729 #define OBD_MD_FLRELEASED    (0x0020000000000000ULL) /* file released */
1730
1731 #define OBD_MD_FLGETATTR (OBD_MD_FLID    | OBD_MD_FLATIME | OBD_MD_FLMTIME | \
1732                           OBD_MD_FLCTIME | OBD_MD_FLSIZE  | OBD_MD_FLBLKSZ | \
1733                           OBD_MD_FLMODE  | OBD_MD_FLTYPE  | OBD_MD_FLUID   | \
1734                           OBD_MD_FLGID   | OBD_MD_FLFLAGS | OBD_MD_FLNLINK | \
1735                           OBD_MD_FLGENER | OBD_MD_FLRDEV  | OBD_MD_FLGROUP)
1736
1737 #define OBD_MD_FLXATTRALL (OBD_MD_FLXATTR | OBD_MD_FLXATTRLS)
1738
1739 /* don't forget obdo_fid which is way down at the bottom so it can
1740  * come after the definition of llog_cookie
1741  */
1742
1743 enum hss_valid {
1744         HSS_SETMASK     = 0x01,
1745         HSS_CLEARMASK   = 0x02,
1746         HSS_ARCHIVE_ID  = 0x04,
1747 };
1748
1749 struct hsm_state_set {
1750         __u32   hss_valid;
1751         __u32   hss_archive_id;
1752         __u64   hss_setmask;
1753         __u64   hss_clearmask;
1754 };
1755
1756 void lustre_swab_hsm_user_state(struct hsm_user_state *hus);
1757 void lustre_swab_hsm_state_set(struct hsm_state_set *hss);
1758
1759 void lustre_swab_obd_statfs(struct obd_statfs *os);
1760
1761 /* ost_body.data values for OST_BRW */
1762
1763 #define OBD_BRW_READ            0x01
1764 #define OBD_BRW_WRITE           0x02
1765 #define OBD_BRW_RWMASK          (OBD_BRW_READ | OBD_BRW_WRITE)
1766 #define OBD_BRW_SYNC            0x08 /* this page is a part of synchronous
1767                                       * transfer and is not accounted in
1768                                       * the grant.
1769                                       */
1770 #define OBD_BRW_CHECK           0x10
1771 #define OBD_BRW_FROM_GRANT      0x20 /* the osc manages this under llite */
1772 #define OBD_BRW_GRANTED         0x40 /* the ost manages this */
1773 #define OBD_BRW_NOCACHE         0x80 /* this page is a part of non-cached IO */
1774 #define OBD_BRW_NOQUOTA        0x100
1775 #define OBD_BRW_SRVLOCK        0x200 /* Client holds no lock over this page */
1776 #define OBD_BRW_ASYNC          0x400 /* Server may delay commit to disk */
1777 #define OBD_BRW_MEMALLOC       0x800 /* Client runs in the "kswapd" context */
1778 #define OBD_BRW_OVER_USRQUOTA 0x1000 /* Running out of user quota */
1779 #define OBD_BRW_OVER_GRPQUOTA 0x2000 /* Running out of group quota */
1780 #define OBD_BRW_SOFT_SYNC     0x4000 /* This flag notifies the server
1781                                       * that the client is running low on
1782                                       * space for unstable pages; asking
1783                                       * it to sync quickly
1784                                       */
1785
1786 #define OBD_OBJECT_EOF 0xffffffffffffffffULL
1787
1788 #define OST_MIN_PRECREATE 32
1789 #define OST_MAX_PRECREATE 20000
1790
1791 struct obd_ioobj {
1792         struct ost_id   ioo_oid;        /* object ID, if multi-obj BRW */
1793         __u32           ioo_max_brw;    /* low 16 bits were o_mode before 2.4,
1794                                          * now (PTLRPC_BULK_OPS_COUNT - 1) in
1795                                          * high 16 bits in 2.4 and later
1796                                          */
1797         __u32           ioo_bufcnt;     /* number of niobufs for this object */
1798 };
1799
1800 #define IOOBJ_MAX_BRW_BITS      16
1801 #define IOOBJ_TYPE_MASK         ((1U << IOOBJ_MAX_BRW_BITS) - 1)
1802 #define ioobj_max_brw_get(ioo)  (((ioo)->ioo_max_brw >> IOOBJ_MAX_BRW_BITS) + 1)
1803 #define ioobj_max_brw_set(ioo, num)                                     \
1804 do { (ioo)->ioo_max_brw = ((num) - 1) << IOOBJ_MAX_BRW_BITS; } while (0)
1805
1806 void lustre_swab_obd_ioobj(struct obd_ioobj *ioo);
1807
1808 /* multiple of 8 bytes => can array */
1809 struct niobuf_remote {
1810         __u64 offset;
1811         __u32 len;
1812         __u32 flags;
1813 };
1814
1815 void lustre_swab_niobuf_remote(struct niobuf_remote *nbr);
1816
1817 /* lock value block communicated between the filter and llite */
1818
1819 /* OST_LVB_ERR_INIT is needed because the return code in rc is
1820  * negative, i.e. because ((MASK + rc) & MASK) != MASK.
1821  */
1822 #define OST_LVB_ERR_INIT 0xffbadbad80000000ULL
1823 #define OST_LVB_ERR_MASK 0xffbadbad00000000ULL
1824 #define OST_LVB_IS_ERR(blocks)                                    \
1825         ((blocks & OST_LVB_ERR_MASK) == OST_LVB_ERR_MASK)
1826 #define OST_LVB_SET_ERR(blocks, rc)                                  \
1827         do { blocks = OST_LVB_ERR_INIT + rc; } while (0)
1828 #define OST_LVB_GET_ERR(blocks)    (int)(blocks - OST_LVB_ERR_INIT)
1829
1830 struct ost_lvb_v1 {
1831         __u64           lvb_size;
1832         __s64           lvb_mtime;
1833         __s64           lvb_atime;
1834         __s64           lvb_ctime;
1835         __u64           lvb_blocks;
1836 };
1837
1838 void lustre_swab_ost_lvb_v1(struct ost_lvb_v1 *lvb);
1839
1840 struct ost_lvb {
1841         __u64           lvb_size;
1842         __s64           lvb_mtime;
1843         __s64           lvb_atime;
1844         __s64           lvb_ctime;
1845         __u64           lvb_blocks;
1846         __u32           lvb_mtime_ns;
1847         __u32           lvb_atime_ns;
1848         __u32           lvb_ctime_ns;
1849         __u32           lvb_padding;
1850 };
1851
1852 void lustre_swab_ost_lvb(struct ost_lvb *lvb);
1853
1854 /*
1855  *   lquota data structures
1856  */
1857
1858 /* The lquota_id structure is an union of all the possible identifier types that
1859  * can be used with quota, this includes:
1860  * - 64-bit user ID
1861  * - 64-bit group ID
1862  * - a FID which can be used for per-directory quota in the future
1863  */
1864 union lquota_id {
1865         struct lu_fid   qid_fid; /* FID for per-directory quota */
1866         __u64           qid_uid; /* user identifier */
1867         __u64           qid_gid; /* group identifier */
1868 };
1869
1870 /* quotactl management */
1871 struct obd_quotactl {
1872         __u32                   qc_cmd;
1873         __u32                   qc_type; /* see Q_* flag below */
1874         __u32                   qc_id;
1875         __u32                   qc_stat;
1876         struct obd_dqinfo       qc_dqinfo;
1877         struct obd_dqblk        qc_dqblk;
1878 };
1879
1880 void lustre_swab_obd_quotactl(struct obd_quotactl *q);
1881
1882 #define Q_QUOTACHECK    0x800100 /* deprecated as of 2.4 */
1883 #define Q_INITQUOTA     0x800101 /* deprecated as of 2.4  */
1884 #define Q_GETOINFO      0x800102 /* get obd quota info */
1885 #define Q_GETOQUOTA     0x800103 /* get obd quotas */
1886 #define Q_FINVALIDATE   0x800104 /* deprecated as of 2.4 */
1887
1888 #define Q_COPY(out, in, member) (out)->member = (in)->member
1889
1890 #define QCTL_COPY(out, in)              \
1891 do {                                    \
1892         Q_COPY(out, in, qc_cmd);        \
1893         Q_COPY(out, in, qc_type);       \
1894         Q_COPY(out, in, qc_id);         \
1895         Q_COPY(out, in, qc_stat);       \
1896         Q_COPY(out, in, qc_dqinfo);     \
1897         Q_COPY(out, in, qc_dqblk);      \
1898 } while (0)
1899
1900 /* Data structures associated with the quota locks */
1901
1902 /* Glimpse descriptor used for the index & per-ID quota locks */
1903 struct ldlm_gl_lquota_desc {
1904         union lquota_id gl_id;    /* quota ID subject to the glimpse */
1905         __u64           gl_flags; /* see LQUOTA_FL* below */
1906         __u64           gl_ver;   /* new index version */
1907         __u64           gl_hardlimit; /* new hardlimit or qunit value */
1908         __u64           gl_softlimit; /* new softlimit */
1909         __u64           gl_time;
1910         __u64           gl_pad2;
1911 };
1912
1913 /* quota glimpse flags */
1914 #define LQUOTA_FL_EDQUOT 0x1 /* user/group out of quota space on QMT */
1915
1916 /* LVB used with quota (global and per-ID) locks */
1917 struct lquota_lvb {
1918         __u64   lvb_flags;      /* see LQUOTA_FL* above */
1919         __u64   lvb_id_may_rel; /* space that might be released later */
1920         __u64   lvb_id_rel;     /* space released by the slave for this ID */
1921         __u64   lvb_id_qunit;   /* current qunit value */
1922         __u64   lvb_pad1;
1923 };
1924
1925 void lustre_swab_lquota_lvb(struct lquota_lvb *lvb);
1926
1927 /* op codes */
1928 enum quota_cmd {
1929         QUOTA_DQACQ     = 601,
1930         QUOTA_DQREL     = 602,
1931         QUOTA_LAST_OPC
1932 };
1933 #define QUOTA_FIRST_OPC QUOTA_DQACQ
1934
1935 /*
1936  *   MDS REQ RECORDS
1937  */
1938
1939 /* opcodes */
1940 enum mds_cmd {
1941         MDS_GETATTR             = 33,
1942         MDS_GETATTR_NAME        = 34,
1943         MDS_CLOSE               = 35,
1944         MDS_REINT               = 36,
1945         MDS_READPAGE            = 37,
1946         MDS_CONNECT             = 38,
1947         MDS_DISCONNECT          = 39,
1948         MDS_GETSTATUS           = 40,
1949         MDS_STATFS              = 41,
1950         MDS_PIN                 = 42,
1951         MDS_UNPIN               = 43,
1952         MDS_SYNC                = 44,
1953         MDS_DONE_WRITING        = 45,
1954         MDS_SET_INFO            = 46,
1955         MDS_QUOTACHECK          = 47,
1956         MDS_QUOTACTL            = 48,
1957         MDS_GETXATTR            = 49,
1958         MDS_SETXATTR            = 50, /* obsolete, now it's MDS_REINT op */
1959         MDS_WRITEPAGE           = 51,
1960         MDS_IS_SUBDIR           = 52,
1961         MDS_GET_INFO            = 53,
1962         MDS_HSM_STATE_GET       = 54,
1963         MDS_HSM_STATE_SET       = 55,
1964         MDS_HSM_ACTION          = 56,
1965         MDS_HSM_PROGRESS        = 57,
1966         MDS_HSM_REQUEST         = 58,
1967         MDS_HSM_CT_REGISTER     = 59,
1968         MDS_HSM_CT_UNREGISTER   = 60,
1969         MDS_SWAP_LAYOUTS        = 61,
1970         MDS_LAST_OPC
1971 };
1972
1973 #define MDS_FIRST_OPC    MDS_GETATTR
1974
1975 /*
1976  * Do not exceed 63
1977  */
1978
1979 enum mdt_reint_cmd {
1980         REINT_SETATTR  = 1,
1981         REINT_CREATE   = 2,
1982         REINT_LINK     = 3,
1983         REINT_UNLINK   = 4,
1984         REINT_RENAME   = 5,
1985         REINT_OPEN     = 6,
1986         REINT_SETXATTR = 7,
1987         REINT_RMENTRY  = 8,
1988 /*      REINT_WRITE    = 9, */
1989         REINT_MAX
1990 };
1991
1992 void lustre_swab_generic_32s(__u32 *val);
1993
1994 /* the disposition of the intent outlines what was executed */
1995 #define DISP_IT_EXECD   0x00000001
1996 #define DISP_LOOKUP_EXECD    0x00000002
1997 #define DISP_LOOKUP_NEG      0x00000004
1998 #define DISP_LOOKUP_POS      0x00000008
1999 #define DISP_OPEN_CREATE     0x00000010
2000 #define DISP_OPEN_OPEN       0x00000020
2001 #define DISP_ENQ_COMPLETE    0x00400000         /* obsolete and unused */
2002 #define DISP_ENQ_OPEN_REF    0x00800000
2003 #define DISP_ENQ_CREATE_REF  0x01000000
2004 #define DISP_OPEN_LOCK       0x02000000
2005 #define DISP_OPEN_LEASE      0x04000000
2006 #define DISP_OPEN_STRIPE     0x08000000
2007
2008 /* INODE LOCK PARTS */
2009 #define MDS_INODELOCK_LOOKUP 0x000001   /* For namespace, dentry etc, and also
2010                                          * was used to protect permission (mode,
2011                                          * owner, group etc) before 2.4.
2012                                          */
2013 #define MDS_INODELOCK_UPDATE 0x000002   /* size, links, timestamps */
2014 #define MDS_INODELOCK_OPEN   0x000004   /* For opened files */
2015 #define MDS_INODELOCK_LAYOUT 0x000008   /* for layout */
2016
2017 /* The PERM bit is added int 2.4, and it is used to protect permission(mode,
2018  * owner, group, acl etc), so to separate the permission from LOOKUP lock.
2019  * Because for remote directories(in DNE), these locks will be granted by
2020  * different MDTs(different ldlm namespace).
2021  *
2022  * For local directory, MDT will always grant UPDATE_LOCK|PERM_LOCK together.
2023  * For Remote directory, the master MDT, where the remote directory is, will
2024  * grant UPDATE_LOCK|PERM_LOCK, and the remote MDT, where the name entry is,
2025  * will grant LOOKUP_LOCK.
2026  */
2027 #define MDS_INODELOCK_PERM   0x000010
2028 #define MDS_INODELOCK_XATTR  0x000020   /* extended attributes */
2029
2030 #define MDS_INODELOCK_MAXSHIFT 5
2031 /* This FULL lock is useful to take on unlink sort of operations */
2032 #define MDS_INODELOCK_FULL ((1<<(MDS_INODELOCK_MAXSHIFT+1))-1)
2033
2034 /* NOTE: until Lustre 1.8.7/2.1.1 the fid_ver() was packed into name[2],
2035  * but was moved into name[1] along with the OID to avoid consuming the
2036  * name[2,3] fields that need to be used for the quota id (also a FID).
2037  */
2038 enum {
2039         LUSTRE_RES_ID_SEQ_OFF = 0,
2040         LUSTRE_RES_ID_VER_OID_OFF = 1,
2041         LUSTRE_RES_ID_WAS_VER_OFF = 2, /* see note above */
2042         LUSTRE_RES_ID_QUOTA_SEQ_OFF = 2,
2043         LUSTRE_RES_ID_QUOTA_VER_OID_OFF = 3,
2044         LUSTRE_RES_ID_HSH_OFF = 3
2045 };
2046
2047 #define MDS_STATUS_CONN 1
2048 #define MDS_STATUS_LOV 2
2049
2050 /* mdt_thread_info.mti_flags. */
2051 enum md_op_flags {
2052         /* The flag indicates Size-on-MDS attributes are changed. */
2053         MF_SOM_CHANGE      = (1 << 0),
2054         /* Flags indicates an epoch opens or closes. */
2055         MF_EPOCH_OPEN      = (1 << 1),
2056         MF_EPOCH_CLOSE    = (1 << 2),
2057         MF_MDC_CANCEL_FID1      = (1 << 3),
2058         MF_MDC_CANCEL_FID2      = (1 << 4),
2059         MF_MDC_CANCEL_FID3      = (1 << 5),
2060         MF_MDC_CANCEL_FID4      = (1 << 6),
2061         /* There is a pending attribute update. */
2062         MF_SOM_AU              = (1 << 7),
2063         /* Cancel OST locks while getattr OST attributes. */
2064         MF_GETATTR_LOCK  = (1 << 8),
2065         MF_GET_MDT_IDX    = (1 << 9),
2066 };
2067
2068 #define MF_SOM_LOCAL_FLAGS (MF_SOM_CHANGE | MF_EPOCH_OPEN | MF_EPOCH_CLOSE)
2069
2070 #define LUSTRE_BFLAG_UNCOMMITTED_WRITES   0x1
2071
2072 /* these should be identical to their EXT4_*_FL counterparts, they are
2073  * redefined here only to avoid dragging in fs/ext4/ext4.h
2074  */
2075 #define LUSTRE_SYNC_FL   0x00000008 /* Synchronous updates */
2076 #define LUSTRE_IMMUTABLE_FL    0x00000010 /* Immutable file */
2077 #define LUSTRE_APPEND_FL       0x00000020 /* writes to file may only append */
2078 #define LUSTRE_NOATIME_FL      0x00000080 /* do not update atime */
2079 #define LUSTRE_DIRSYNC_FL      0x00010000 /* dirsync behaviour (dir only) */
2080
2081 /* Convert wire LUSTRE_*_FL to corresponding client local VFS S_* values
2082  * for the client inode i_flags.  The LUSTRE_*_FL are the Lustre wire
2083  * protocol equivalents of LDISKFS_*_FL values stored on disk, while
2084  * the S_* flags are kernel-internal values that change between kernel
2085  * versions.  These flags are set/cleared via FSFILT_IOC_{GET,SET}_FLAGS.
2086  * See b=16526 for a full history.
2087  */
2088 static inline int ll_ext_to_inode_flags(int flags)
2089 {
2090         return (((flags & LUSTRE_SYNC_FL)      ? S_SYNC      : 0) |
2091                 ((flags & LUSTRE_NOATIME_FL)   ? S_NOATIME   : 0) |
2092                 ((flags & LUSTRE_APPEND_FL)    ? S_APPEND    : 0) |
2093                 ((flags & LUSTRE_DIRSYNC_FL)   ? S_DIRSYNC   : 0) |
2094                 ((flags & LUSTRE_IMMUTABLE_FL) ? S_IMMUTABLE : 0));
2095 }
2096
2097 static inline int ll_inode_to_ext_flags(int iflags)
2098 {
2099         return (((iflags & S_SYNC)      ? LUSTRE_SYNC_FL      : 0) |
2100                 ((iflags & S_NOATIME)   ? LUSTRE_NOATIME_FL   : 0) |
2101                 ((iflags & S_APPEND)    ? LUSTRE_APPEND_FL    : 0) |
2102                 ((iflags & S_DIRSYNC)   ? LUSTRE_DIRSYNC_FL   : 0) |
2103                 ((iflags & S_IMMUTABLE) ? LUSTRE_IMMUTABLE_FL : 0));
2104 }
2105
2106 /* 64 possible states */
2107 enum md_transient_state {
2108         MS_RESTORE      = (1 << 0),     /* restore is running */
2109 };
2110
2111 struct mdt_body {
2112         struct lu_fid  fid1;
2113         struct lu_fid  fid2;
2114         struct lustre_handle handle;
2115         __u64     valid;
2116         __u64     size;   /* Offset, in the case of MDS_READPAGE */
2117         __s64     mtime;
2118         __s64     atime;
2119         __s64     ctime;
2120         __u64     blocks; /* XID, in the case of MDS_READPAGE */
2121         __u64     ioepoch;
2122         __u64     t_state; /* transient file state defined in
2123                             * enum md_transient_state
2124                             * was "ino" until 2.4.0
2125                             */
2126         __u32     fsuid;
2127         __u32     fsgid;
2128         __u32     capability;
2129         __u32     mode;
2130         __u32     uid;
2131         __u32     gid;
2132         __u32     flags; /* from vfs for pin/unpin, LUSTRE_BFLAG close */
2133         __u32     rdev;
2134         __u32     nlink; /* #bytes to read in the case of MDS_READPAGE */
2135         __u32     unused2; /* was "generation" until 2.4.0 */
2136         __u32     suppgid;
2137         __u32     eadatasize;
2138         __u32     aclsize;
2139         __u32     max_mdsize;
2140         __u32     max_cookiesize;
2141         __u32     uid_h; /* high 32-bits of uid, for FUID */
2142         __u32     gid_h; /* high 32-bits of gid, for FUID */
2143         __u32     padding_5; /* also fix lustre_swab_mdt_body */
2144         __u64     padding_6;
2145         __u64     padding_7;
2146         __u64     padding_8;
2147         __u64     padding_9;
2148         __u64     padding_10;
2149 }; /* 216 */
2150
2151 void lustre_swab_mdt_body(struct mdt_body *b);
2152
2153 struct mdt_ioepoch {
2154         struct lustre_handle handle;
2155         __u64  ioepoch;
2156         __u32  flags;
2157         __u32  padding;
2158 };
2159
2160 void lustre_swab_mdt_ioepoch(struct mdt_ioepoch *b);
2161
2162 /* permissions for md_perm.mp_perm */
2163 enum {
2164         CFS_SETUID_PERM = 0x01,
2165         CFS_SETGID_PERM = 0x02,
2166         CFS_SETGRP_PERM = 0x04,
2167 };
2168
2169 struct mdt_rec_setattr {
2170         __u32      sa_opcode;
2171         __u32      sa_cap;
2172         __u32      sa_fsuid;
2173         __u32      sa_fsuid_h;
2174         __u32      sa_fsgid;
2175         __u32      sa_fsgid_h;
2176         __u32      sa_suppgid;
2177         __u32      sa_suppgid_h;
2178         __u32      sa_padding_1;
2179         __u32      sa_padding_1_h;
2180         struct lu_fid   sa_fid;
2181         __u64      sa_valid;
2182         __u32      sa_uid;
2183         __u32      sa_gid;
2184         __u64      sa_size;
2185         __u64      sa_blocks;
2186         __s64      sa_mtime;
2187         __s64      sa_atime;
2188         __s64      sa_ctime;
2189         __u32      sa_attr_flags;
2190         __u32      sa_mode;
2191         __u32      sa_bias;      /* some operation flags */
2192         __u32      sa_padding_3;
2193         __u32      sa_padding_4;
2194         __u32      sa_padding_5;
2195 };
2196
2197 void lustre_swab_mdt_rec_setattr(struct mdt_rec_setattr *sa);
2198
2199 /*
2200  * Attribute flags used in mdt_rec_setattr::sa_valid.
2201  * The kernel's #defines for ATTR_* should not be used over the network
2202  * since the client and MDS may run different kernels (see bug 13828)
2203  * Therefore, we should only use MDS_ATTR_* attributes for sa_valid.
2204  */
2205 #define MDS_ATTR_MODE          0x1ULL /* = 1 */
2206 #define MDS_ATTR_UID           0x2ULL /* = 2 */
2207 #define MDS_ATTR_GID           0x4ULL /* = 4 */
2208 #define MDS_ATTR_SIZE          0x8ULL /* = 8 */
2209 #define MDS_ATTR_ATIME        0x10ULL /* = 16 */
2210 #define MDS_ATTR_MTIME        0x20ULL /* = 32 */
2211 #define MDS_ATTR_CTIME        0x40ULL /* = 64 */
2212 #define MDS_ATTR_ATIME_SET    0x80ULL /* = 128 */
2213 #define MDS_ATTR_MTIME_SET   0x100ULL /* = 256 */
2214 #define MDS_ATTR_FORCE       0x200ULL /* = 512, Not a change, but a change it */
2215 #define MDS_ATTR_ATTR_FLAG   0x400ULL /* = 1024 */
2216 #define MDS_ATTR_KILL_SUID   0x800ULL /* = 2048 */
2217 #define MDS_ATTR_KILL_SGID  0x1000ULL /* = 4096 */
2218 #define MDS_ATTR_CTIME_SET  0x2000ULL /* = 8192 */
2219 #define MDS_ATTR_FROM_OPEN  0x4000ULL /* = 16384, called from open path,
2220                                        * ie O_TRUNC
2221                                        */
2222 #define MDS_ATTR_BLOCKS     0x8000ULL /* = 32768 */
2223
2224 #define MDS_FMODE_CLOSED         00000000
2225 #define MDS_FMODE_EXEC     00000004
2226 /* IO Epoch is opened on a closed file. */
2227 #define MDS_FMODE_EPOCH   01000000
2228 /* IO Epoch is opened on a file truncate. */
2229 #define MDS_FMODE_TRUNC   02000000
2230 /* Size-on-MDS Attribute Update is pending. */
2231 #define MDS_FMODE_SOM       04000000
2232
2233 #define MDS_OPEN_CREATED         00000010
2234 #define MDS_OPEN_CROSS     00000020
2235
2236 #define MDS_OPEN_CREAT     00000100
2237 #define MDS_OPEN_EXCL       00000200
2238 #define MDS_OPEN_TRUNC     00001000
2239 #define MDS_OPEN_APPEND   00002000
2240 #define MDS_OPEN_SYNC       00010000
2241 #define MDS_OPEN_DIRECTORY       00200000
2242
2243 #define MDS_OPEN_BY_FID         040000000 /* open_by_fid for known object */
2244 #define MDS_OPEN_DELAY_CREATE  0100000000 /* delay initial object create */
2245 #define MDS_OPEN_OWNEROVERRIDE 0200000000 /* NFSD rw-reopen ro file for owner */
2246 #define MDS_OPEN_JOIN_FILE     0400000000 /* open for join file.
2247                                            * We do not support JOIN FILE
2248                                            * anymore, reserve this flags
2249                                            * just for preventing such bit
2250                                            * to be reused.
2251                                            */
2252
2253 #define MDS_OPEN_LOCK         04000000000 /* This open requires open lock */
2254 #define MDS_OPEN_HAS_EA      010000000000 /* specify object create pattern */
2255 #define MDS_OPEN_HAS_OBJS    020000000000 /* Just set the EA the obj exist */
2256 #define MDS_OPEN_NORESTORE  0100000000000ULL /* Do not restore file at open */
2257 #define MDS_OPEN_NEWSTRIPE  0200000000000ULL /* New stripe needed (restripe or
2258                                               * hsm restore) */
2259 #define MDS_OPEN_VOLATILE   0400000000000ULL /* File is volatile = created
2260                                                 unlinked */
2261 #define MDS_OPEN_LEASE     01000000000000ULL /* Open the file and grant lease
2262                                               * delegation, succeed if it's not
2263                                               * being opened with conflict mode.
2264                                               */
2265 #define MDS_OPEN_RELEASE   02000000000000ULL /* Open the file for HSM release */
2266
2267 enum mds_op_bias {
2268         MDS_CHECK_SPLIT         = 1 << 0,
2269         MDS_CROSS_REF           = 1 << 1,
2270         MDS_VTX_BYPASS          = 1 << 2,
2271         MDS_PERM_BYPASS         = 1 << 3,
2272         MDS_SOM                 = 1 << 4,
2273         MDS_QUOTA_IGNORE        = 1 << 5,
2274         MDS_CLOSE_CLEANUP       = 1 << 6,
2275         MDS_KEEP_ORPHAN         = 1 << 7,
2276         MDS_RECOV_OPEN          = 1 << 8,
2277         MDS_DATA_MODIFIED       = 1 << 9,
2278         MDS_CREATE_VOLATILE     = 1 << 10,
2279         MDS_OWNEROVERRIDE       = 1 << 11,
2280         MDS_HSM_RELEASE         = 1 << 12,
2281 };
2282
2283 /* instance of mdt_reint_rec */
2284 struct mdt_rec_create {
2285         __u32      cr_opcode;
2286         __u32      cr_cap;
2287         __u32      cr_fsuid;
2288         __u32      cr_fsuid_h;
2289         __u32      cr_fsgid;
2290         __u32      cr_fsgid_h;
2291         __u32      cr_suppgid1;
2292         __u32      cr_suppgid1_h;
2293         __u32      cr_suppgid2;
2294         __u32      cr_suppgid2_h;
2295         struct lu_fid   cr_fid1;
2296         struct lu_fid   cr_fid2;
2297         struct lustre_handle cr_old_handle; /* handle in case of open replay */
2298         __s64      cr_time;
2299         __u64      cr_rdev;
2300         __u64      cr_ioepoch;
2301         __u64      cr_padding_1;   /* rr_blocks */
2302         __u32      cr_mode;
2303         __u32      cr_bias;
2304         /* use of helpers set/get_mrc_cr_flags() is needed to access
2305          * 64 bits cr_flags [cr_flags_l, cr_flags_h], this is done to
2306          * extend cr_flags size without breaking 1.8 compat
2307          */
2308         __u32      cr_flags_l;     /* for use with open, low  32 bits  */
2309         __u32      cr_flags_h;     /* for use with open, high 32 bits */
2310         __u32      cr_umask;       /* umask for create */
2311         __u32      cr_padding_4;   /* rr_padding_4 */
2312 };
2313
2314 static inline void set_mrc_cr_flags(struct mdt_rec_create *mrc, __u64 flags)
2315 {
2316         mrc->cr_flags_l = (__u32)(flags & 0xFFFFFFFFUll);
2317         mrc->cr_flags_h = (__u32)(flags >> 32);
2318 }
2319
2320 static inline __u64 get_mrc_cr_flags(struct mdt_rec_create *mrc)
2321 {
2322         return ((__u64)(mrc->cr_flags_l) | ((__u64)mrc->cr_flags_h << 32));
2323 }
2324
2325 /* instance of mdt_reint_rec */
2326 struct mdt_rec_link {
2327         __u32      lk_opcode;
2328         __u32      lk_cap;
2329         __u32      lk_fsuid;
2330         __u32      lk_fsuid_h;
2331         __u32      lk_fsgid;
2332         __u32      lk_fsgid_h;
2333         __u32      lk_suppgid1;
2334         __u32      lk_suppgid1_h;
2335         __u32      lk_suppgid2;
2336         __u32      lk_suppgid2_h;
2337         struct lu_fid   lk_fid1;
2338         struct lu_fid   lk_fid2;
2339         __s64      lk_time;
2340         __u64      lk_padding_1;   /* rr_atime */
2341         __u64      lk_padding_2;   /* rr_ctime */
2342         __u64      lk_padding_3;   /* rr_size */
2343         __u64      lk_padding_4;   /* rr_blocks */
2344         __u32      lk_bias;
2345         __u32      lk_padding_5;   /* rr_mode */
2346         __u32      lk_padding_6;   /* rr_flags */
2347         __u32      lk_padding_7;   /* rr_padding_2 */
2348         __u32      lk_padding_8;   /* rr_padding_3 */
2349         __u32      lk_padding_9;   /* rr_padding_4 */
2350 };
2351
2352 /* instance of mdt_reint_rec */
2353 struct mdt_rec_unlink {
2354         __u32      ul_opcode;
2355         __u32      ul_cap;
2356         __u32      ul_fsuid;
2357         __u32      ul_fsuid_h;
2358         __u32      ul_fsgid;
2359         __u32      ul_fsgid_h;
2360         __u32      ul_suppgid1;
2361         __u32      ul_suppgid1_h;
2362         __u32      ul_suppgid2;
2363         __u32      ul_suppgid2_h;
2364         struct lu_fid   ul_fid1;
2365         struct lu_fid   ul_fid2;
2366         __s64      ul_time;
2367         __u64      ul_padding_2;   /* rr_atime */
2368         __u64      ul_padding_3;   /* rr_ctime */
2369         __u64      ul_padding_4;   /* rr_size */
2370         __u64      ul_padding_5;   /* rr_blocks */
2371         __u32      ul_bias;
2372         __u32      ul_mode;
2373         __u32      ul_padding_6;   /* rr_flags */
2374         __u32      ul_padding_7;   /* rr_padding_2 */
2375         __u32      ul_padding_8;   /* rr_padding_3 */
2376         __u32      ul_padding_9;   /* rr_padding_4 */
2377 };
2378
2379 /* instance of mdt_reint_rec */
2380 struct mdt_rec_rename {
2381         __u32      rn_opcode;
2382         __u32      rn_cap;
2383         __u32      rn_fsuid;
2384         __u32      rn_fsuid_h;
2385         __u32      rn_fsgid;
2386         __u32      rn_fsgid_h;
2387         __u32      rn_suppgid1;
2388         __u32      rn_suppgid1_h;
2389         __u32      rn_suppgid2;
2390         __u32      rn_suppgid2_h;
2391         struct lu_fid   rn_fid1;
2392         struct lu_fid   rn_fid2;
2393         __s64      rn_time;
2394         __u64      rn_padding_1;   /* rr_atime */
2395         __u64      rn_padding_2;   /* rr_ctime */
2396         __u64      rn_padding_3;   /* rr_size */
2397         __u64      rn_padding_4;   /* rr_blocks */
2398         __u32      rn_bias;     /* some operation flags */
2399         __u32      rn_mode;     /* cross-ref rename has mode */
2400         __u32      rn_padding_5;   /* rr_flags */
2401         __u32      rn_padding_6;   /* rr_padding_2 */
2402         __u32      rn_padding_7;   /* rr_padding_3 */
2403         __u32      rn_padding_8;   /* rr_padding_4 */
2404 };
2405
2406 /* instance of mdt_reint_rec */
2407 struct mdt_rec_setxattr {
2408         __u32      sx_opcode;
2409         __u32      sx_cap;
2410         __u32      sx_fsuid;
2411         __u32      sx_fsuid_h;
2412         __u32      sx_fsgid;
2413         __u32      sx_fsgid_h;
2414         __u32      sx_suppgid1;
2415         __u32      sx_suppgid1_h;
2416         __u32      sx_suppgid2;
2417         __u32      sx_suppgid2_h;
2418         struct lu_fid   sx_fid;
2419         __u64      sx_padding_1;   /* These three are rr_fid2 */
2420         __u32      sx_padding_2;
2421         __u32      sx_padding_3;
2422         __u64      sx_valid;
2423         __s64      sx_time;
2424         __u64      sx_padding_5;   /* rr_ctime */
2425         __u64      sx_padding_6;   /* rr_size */
2426         __u64      sx_padding_7;   /* rr_blocks */
2427         __u32      sx_size;
2428         __u32      sx_flags;
2429         __u32      sx_padding_8;   /* rr_flags */
2430         __u32      sx_padding_9;   /* rr_padding_2 */
2431         __u32      sx_padding_10;  /* rr_padding_3 */
2432         __u32      sx_padding_11;  /* rr_padding_4 */
2433 };
2434
2435 /*
2436  * mdt_rec_reint is the template for all mdt_reint_xxx structures.
2437  * Do NOT change the size of various members, otherwise the value
2438  * will be broken in lustre_swab_mdt_rec_reint().
2439  *
2440  * If you add new members in other mdt_reint_xxx structures and need to use the
2441  * rr_padding_x fields, then update lustre_swab_mdt_rec_reint() also.
2442  */
2443 struct mdt_rec_reint {
2444         __u32      rr_opcode;
2445         __u32      rr_cap;
2446         __u32      rr_fsuid;
2447         __u32      rr_fsuid_h;
2448         __u32      rr_fsgid;
2449         __u32      rr_fsgid_h;
2450         __u32      rr_suppgid1;
2451         __u32      rr_suppgid1_h;
2452         __u32      rr_suppgid2;
2453         __u32      rr_suppgid2_h;
2454         struct lu_fid   rr_fid1;
2455         struct lu_fid   rr_fid2;
2456         __s64      rr_mtime;
2457         __s64      rr_atime;
2458         __s64      rr_ctime;
2459         __u64      rr_size;
2460         __u64      rr_blocks;
2461         __u32      rr_bias;
2462         __u32      rr_mode;
2463         __u32      rr_flags;
2464         __u32      rr_flags_h;
2465         __u32      rr_umask;
2466         __u32      rr_padding_4; /* also fix lustre_swab_mdt_rec_reint */
2467 };
2468
2469 void lustre_swab_mdt_rec_reint(struct mdt_rec_reint *rr);
2470
2471 /* lmv structures */
2472 struct lmv_desc {
2473         __u32 ld_tgt_count;             /* how many MDS's */
2474         __u32 ld_active_tgt_count;       /* how many active */
2475         __u32 ld_default_stripe_count;     /* how many objects are used */
2476         __u32 ld_pattern;                 /* default hash pattern */
2477         __u64 ld_default_hash_size;
2478         __u64 ld_padding_1;             /* also fix lustre_swab_lmv_desc */
2479         __u32 ld_padding_2;             /* also fix lustre_swab_lmv_desc */
2480         __u32 ld_qos_maxage;           /* in second */
2481         __u32 ld_padding_3;             /* also fix lustre_swab_lmv_desc */
2482         __u32 ld_padding_4;             /* also fix lustre_swab_lmv_desc */
2483         struct obd_uuid ld_uuid;
2484 };
2485
2486 /* lmv structures */
2487 #define LMV_MAGIC_V1    0x0CD10CD0      /* normal stripe lmv magic */
2488 #define LMV_USER_MAGIC  0x0CD20CD0      /* default lmv magic*/
2489 #define LMV_MAGIC       LMV_MAGIC_V1
2490
2491 enum lmv_hash_type {
2492         LMV_HASH_TYPE_ALL_CHARS = 1,
2493         LMV_HASH_TYPE_FNV_1A_64 = 2,
2494 };
2495
2496 #define LMV_HASH_NAME_ALL_CHARS         "all_char"
2497 #define LMV_HASH_NAME_FNV_1A_64         "fnv_1a_64"
2498
2499 /**
2500  * The FNV-1a hash algorithm is as follows:
2501  *     hash = FNV_offset_basis
2502  *     for each octet_of_data to be hashed
2503  *             hash = hash XOR octet_of_data
2504  *             hash = hash Ã— FNV_prime
2505  *     return hash
2506  * http://en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function#FNV-1a_hash
2507  *
2508  * http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-reference-source
2509  * FNV_prime is 2^40 + 2^8 + 0xb3 = 0x100000001b3ULL
2510  **/
2511 #define LUSTRE_FNV_1A_64_PRIME          0x100000001b3ULL
2512 #define LUSTRE_FNV_1A_64_OFFSET_BIAS    0xcbf29ce484222325ULL
2513 static inline __u64 lustre_hash_fnv_1a_64(const void *buf, size_t size)
2514 {
2515         __u64 hash = LUSTRE_FNV_1A_64_OFFSET_BIAS;
2516         const unsigned char *p = buf;
2517         size_t i;
2518
2519         for (i = 0; i < size; i++) {
2520                 hash ^= p[i];
2521                 hash *= LUSTRE_FNV_1A_64_PRIME;
2522         }
2523
2524         return hash;
2525 }
2526
2527 struct lmv_mds_md_v1 {
2528         __u32 lmv_magic;
2529         __u32 lmv_stripe_count;         /* stripe count */
2530         __u32 lmv_master_mdt_index;     /* master MDT index */
2531         __u32 lmv_hash_type;            /* dir stripe policy, i.e. indicate
2532                                          * which hash function to be used
2533                                          */
2534         __u32 lmv_layout_version;       /* Used for directory restriping */
2535         __u32 lmv_padding;
2536         char lmv_pool_name[LOV_MAXPOOLNAME];    /* pool name */
2537         struct lu_fid lmv_stripe_fids[0];       /* FIDs for each stripe */
2538 };
2539
2540 union lmv_mds_md {
2541         __u32                   lmv_magic;
2542         struct lmv_mds_md_v1    lmv_md_v1;
2543         struct lmv_user_md      lmv_user_md;
2544 };
2545
2546 static inline ssize_t lmv_mds_md_size(int stripe_count, unsigned int lmm_magic)
2547 {
2548         ssize_t len = -EINVAL;
2549
2550         switch (lmm_magic) {
2551         case LMV_MAGIC_V1: {
2552                 struct lmv_mds_md_v1 *lmm1;
2553
2554                 len = sizeof(*lmm1);
2555                 len += stripe_count * sizeof(lmm1->lmv_stripe_fids[0]);
2556                 break; }
2557         default:
2558                 break;
2559         }
2560         return len;
2561 }
2562
2563 static inline int lmv_mds_md_stripe_count_get(const union lmv_mds_md *lmm)
2564 {
2565         switch (le32_to_cpu(lmm->lmv_magic)) {
2566         case LMV_MAGIC_V1:
2567                 return le32_to_cpu(lmm->lmv_md_v1.lmv_stripe_count);
2568         case LMV_USER_MAGIC:
2569                 return le32_to_cpu(lmm->lmv_user_md.lum_stripe_count);
2570         default:
2571                 return -EINVAL;
2572         }
2573 }
2574
2575 static inline int lmv_mds_md_stripe_count_set(union lmv_mds_md *lmm,
2576                                               unsigned int stripe_count)
2577 {
2578         int rc = 0;
2579
2580         switch (le32_to_cpu(lmm->lmv_magic)) {
2581         case LMV_MAGIC_V1:
2582                 lmm->lmv_md_v1.lmv_stripe_count = cpu_to_le32(stripe_count);
2583                 break;
2584         case LMV_USER_MAGIC:
2585                 lmm->lmv_user_md.lum_stripe_count = cpu_to_le32(stripe_count);
2586                 break;
2587         default:
2588                 rc = -EINVAL;
2589                 break;
2590         }
2591         return rc;
2592 }
2593
2594 enum fld_rpc_opc {
2595         FLD_QUERY       = 900,
2596         FLD_READ        = 901,
2597         FLD_LAST_OPC,
2598         FLD_FIRST_OPC   = FLD_QUERY
2599 };
2600
2601 enum seq_rpc_opc {
2602         SEQ_QUERY                      = 700,
2603         SEQ_LAST_OPC,
2604         SEQ_FIRST_OPC              = SEQ_QUERY
2605 };
2606
2607 enum seq_op {
2608         SEQ_ALLOC_SUPER = 0,
2609         SEQ_ALLOC_META = 1
2610 };
2611
2612 enum fld_op {
2613         FLD_CREATE = 0,
2614         FLD_DELETE = 1,
2615         FLD_LOOKUP = 2,
2616 };
2617
2618 /*
2619  *  LOV data structures
2620  */
2621
2622 #define LOV_MAX_UUID_BUFFER_SIZE  8192
2623 /* The size of the buffer the lov/mdc reserves for the
2624  * array of UUIDs returned by the MDS.  With the current
2625  * protocol, this will limit the max number of OSTs per LOV
2626  */
2627
2628 #define LOV_DESC_MAGIC 0xB0CCDE5C
2629 #define LOV_DESC_QOS_MAXAGE_DEFAULT 5  /* Seconds */
2630 #define LOV_DESC_STRIPE_SIZE_DEFAULT (1 << LNET_MTU_BITS)
2631
2632 /* LOV settings descriptor (should only contain static info) */
2633 struct lov_desc {
2634         __u32 ld_tgt_count;             /* how many OBD's */
2635         __u32 ld_active_tgt_count;      /* how many active */
2636         __u32 ld_default_stripe_count;  /* how many objects are used */
2637         __u32 ld_pattern;               /* default PATTERN_RAID0 */
2638         __u64 ld_default_stripe_size;   /* in bytes */
2639         __u64 ld_default_stripe_offset; /* in bytes */
2640         __u32 ld_padding_0;             /* unused */
2641         __u32 ld_qos_maxage;            /* in second */
2642         __u32 ld_padding_1;             /* also fix lustre_swab_lov_desc */
2643         __u32 ld_padding_2;             /* also fix lustre_swab_lov_desc */
2644         struct obd_uuid ld_uuid;
2645 };
2646
2647 #define ld_magic ld_active_tgt_count       /* for swabbing from llogs */
2648
2649 void lustre_swab_lov_desc(struct lov_desc *ld);
2650
2651 /*
2652  *   LDLM requests:
2653  */
2654 /* opcodes -- MUST be distinct from OST/MDS opcodes */
2655 enum ldlm_cmd {
2656         LDLM_ENQUEUE     = 101,
2657         LDLM_CONVERT     = 102,
2658         LDLM_CANCEL      = 103,
2659         LDLM_BL_CALLBACK = 104,
2660         LDLM_CP_CALLBACK = 105,
2661         LDLM_GL_CALLBACK = 106,
2662         LDLM_SET_INFO    = 107,
2663         LDLM_LAST_OPC
2664 };
2665 #define LDLM_FIRST_OPC LDLM_ENQUEUE
2666
2667 #define RES_NAME_SIZE 4
2668 struct ldlm_res_id {
2669         __u64 name[RES_NAME_SIZE];
2670 };
2671
2672 #define DLDLMRES        "[%#llx:%#llx:%#llx].%llx"
2673 #define PLDLMRES(res)   (res)->lr_name.name[0], (res)->lr_name.name[1], \
2674                         (res)->lr_name.name[2], (res)->lr_name.name[3]
2675
2676 static inline int ldlm_res_eq(const struct ldlm_res_id *res0,
2677                               const struct ldlm_res_id *res1)
2678 {
2679         return !memcmp(res0, res1, sizeof(*res0));
2680 }
2681
2682 /* lock types */
2683 enum ldlm_mode {
2684         LCK_MINMODE = 0,
2685         LCK_EX      = 1,
2686         LCK_PW      = 2,
2687         LCK_PR      = 4,
2688         LCK_CW      = 8,
2689         LCK_CR      = 16,
2690         LCK_NL      = 32,
2691         LCK_GROUP   = 64,
2692         LCK_COS     = 128,
2693         LCK_MAXMODE
2694 };
2695
2696 #define LCK_MODE_NUM    8
2697
2698 enum ldlm_type {
2699         LDLM_PLAIN     = 10,
2700         LDLM_EXTENT    = 11,
2701         LDLM_FLOCK     = 12,
2702         LDLM_IBITS     = 13,
2703         LDLM_MAX_TYPE
2704 };
2705
2706 #define LDLM_MIN_TYPE LDLM_PLAIN
2707
2708 struct ldlm_extent {
2709         __u64 start;
2710         __u64 end;
2711         __u64 gid;
2712 };
2713
2714 #define LDLM_GID_ANY ((__u64)-1)
2715
2716 static inline int ldlm_extent_overlap(struct ldlm_extent *ex1,
2717                                       struct ldlm_extent *ex2)
2718 {
2719         return (ex1->start <= ex2->end) && (ex2->start <= ex1->end);
2720 }
2721
2722 /* check if @ex1 contains @ex2 */
2723 static inline int ldlm_extent_contain(struct ldlm_extent *ex1,
2724                                       struct ldlm_extent *ex2)
2725 {
2726         return (ex1->start <= ex2->start) && (ex1->end >= ex2->end);
2727 }
2728
2729 struct ldlm_inodebits {
2730         __u64 bits;
2731 };
2732
2733 struct ldlm_flock_wire {
2734         __u64 lfw_start;
2735         __u64 lfw_end;
2736         __u64 lfw_owner;
2737         __u32 lfw_padding;
2738         __u32 lfw_pid;
2739 };
2740
2741 /* it's important that the fields of the ldlm_extent structure match
2742  * the first fields of the ldlm_flock structure because there is only
2743  * one ldlm_swab routine to process the ldlm_policy_data_t union. if
2744  * this ever changes we will need to swab the union differently based
2745  * on the resource type.
2746  */
2747
2748 typedef union {
2749         struct ldlm_extent l_extent;
2750         struct ldlm_flock_wire l_flock;
2751         struct ldlm_inodebits l_inodebits;
2752 } ldlm_wire_policy_data_t;
2753
2754 union ldlm_gl_desc {
2755         struct ldlm_gl_lquota_desc      lquota_desc;
2756 };
2757
2758 void lustre_swab_gl_desc(union ldlm_gl_desc *);
2759
2760 struct ldlm_intent {
2761         __u64 opc;
2762 };
2763
2764 void lustre_swab_ldlm_intent(struct ldlm_intent *i);
2765
2766 struct ldlm_resource_desc {
2767         enum ldlm_type lr_type;
2768         __u32 lr_padding;       /* also fix lustre_swab_ldlm_resource_desc */
2769         struct ldlm_res_id lr_name;
2770 };
2771
2772 struct ldlm_lock_desc {
2773         struct ldlm_resource_desc l_resource;
2774         enum ldlm_mode l_req_mode;
2775         enum ldlm_mode l_granted_mode;
2776         ldlm_wire_policy_data_t l_policy_data;
2777 };
2778
2779 #define LDLM_LOCKREQ_HANDLES 2
2780 #define LDLM_ENQUEUE_CANCEL_OFF 1
2781
2782 struct ldlm_request {
2783         __u32 lock_flags;
2784         __u32 lock_count;
2785         struct ldlm_lock_desc lock_desc;
2786         struct lustre_handle lock_handle[LDLM_LOCKREQ_HANDLES];
2787 };
2788
2789 void lustre_swab_ldlm_request(struct ldlm_request *rq);
2790
2791 /* If LDLM_ENQUEUE, 1 slot is already occupied, 1 is available.
2792  * Otherwise, 2 are available.
2793  */
2794 #define ldlm_request_bufsize(count, type)                               \
2795 ({                                                                    \
2796         int _avail = LDLM_LOCKREQ_HANDLES;                            \
2797         _avail -= (type == LDLM_ENQUEUE ? LDLM_ENQUEUE_CANCEL_OFF : 0); \
2798         sizeof(struct ldlm_request) +                              \
2799         (count > _avail ? count - _avail : 0) *                  \
2800         sizeof(struct lustre_handle);                              \
2801 })
2802
2803 struct ldlm_reply {
2804         __u32 lock_flags;
2805         __u32 lock_padding;     /* also fix lustre_swab_ldlm_reply */
2806         struct ldlm_lock_desc lock_desc;
2807         struct lustre_handle lock_handle;
2808         __u64  lock_policy_res1;
2809         __u64  lock_policy_res2;
2810 };
2811
2812 void lustre_swab_ldlm_reply(struct ldlm_reply *r);
2813
2814 #define ldlm_flags_to_wire(flags)    ((__u32)(flags))
2815 #define ldlm_flags_from_wire(flags)  ((__u64)(flags))
2816
2817 /*
2818  * Opcodes for mountconf (mgs and mgc)
2819  */
2820 enum mgs_cmd {
2821         MGS_CONNECT = 250,
2822         MGS_DISCONNECT,
2823         MGS_EXCEPTION,   /* node died, etc. */
2824         MGS_TARGET_REG, /* whenever target starts up */
2825         MGS_TARGET_DEL,
2826         MGS_SET_INFO,
2827         MGS_CONFIG_READ,
2828         MGS_LAST_OPC
2829 };
2830 #define MGS_FIRST_OPC MGS_CONNECT
2831
2832 #define MGS_PARAM_MAXLEN 1024
2833 #define KEY_SET_INFO "set_info"
2834
2835 struct mgs_send_param {
2836         char         mgs_param[MGS_PARAM_MAXLEN];
2837 };
2838
2839 /* We pass this info to the MGS so it can write config logs */
2840 #define MTI_NAME_MAXLEN  64
2841 #define MTI_PARAM_MAXLEN 4096
2842 #define MTI_NIDS_MAX     32
2843 struct mgs_target_info {
2844         __u32       mti_lustre_ver;
2845         __u32       mti_stripe_index;
2846         __u32       mti_config_ver;
2847         __u32       mti_flags;
2848         __u32       mti_nid_count;
2849         __u32       mti_instance; /* Running instance of target */
2850         char         mti_fsname[MTI_NAME_MAXLEN];
2851         char         mti_svname[MTI_NAME_MAXLEN];
2852         char         mti_uuid[sizeof(struct obd_uuid)];
2853         __u64       mti_nids[MTI_NIDS_MAX];     /* host nids (lnet_nid_t)*/
2854         char         mti_params[MTI_PARAM_MAXLEN];
2855 };
2856
2857 void lustre_swab_mgs_target_info(struct mgs_target_info *oinfo);
2858
2859 struct mgs_nidtbl_entry {
2860         __u64      mne_version;    /* table version of this entry */
2861         __u32      mne_instance;   /* target instance # */
2862         __u32      mne_index;      /* target index */
2863         __u32      mne_length;     /* length of this entry - by bytes */
2864         __u8        mne_type;       /* target type LDD_F_SV_TYPE_OST/MDT */
2865         __u8        mne_nid_type;   /* type of nid(mbz). for ipv6. */
2866         __u8        mne_nid_size;   /* size of each NID, by bytes */
2867         __u8        mne_nid_count;  /* # of NIDs in buffer */
2868         union {
2869                 lnet_nid_t nids[0];     /* variable size buffer for NIDs. */
2870         } u;
2871 };
2872
2873 void lustre_swab_mgs_nidtbl_entry(struct mgs_nidtbl_entry *oinfo);
2874
2875 struct mgs_config_body {
2876         char     mcb_name[MTI_NAME_MAXLEN]; /* logname */
2877         __u64    mcb_offset;    /* next index of config log to request */
2878         __u16    mcb_type;      /* type of log: CONFIG_T_[CONFIG|RECOVER] */
2879         __u8     mcb_reserved;
2880         __u8     mcb_bits;      /* bits unit size of config log */
2881         __u32    mcb_units;     /* # of units for bulk transfer */
2882 };
2883
2884 void lustre_swab_mgs_config_body(struct mgs_config_body *body);
2885
2886 struct mgs_config_res {
2887         __u64    mcr_offset;    /* index of last config log */
2888         __u64    mcr_size;      /* size of the log */
2889 };
2890
2891 void lustre_swab_mgs_config_res(struct mgs_config_res *body);
2892
2893 /* Config marker flags (in config log) */
2894 #define CM_START       0x01
2895 #define CM_END   0x02
2896 #define CM_SKIP 0x04
2897 #define CM_UPGRADE146  0x08
2898 #define CM_EXCLUDE     0x10
2899 #define CM_START_SKIP (CM_START | CM_SKIP)
2900
2901 struct cfg_marker {
2902         __u32        cm_step;       /* aka config version */
2903         __u32        cm_flags;
2904         __u32        cm_vers;       /* lustre release version number */
2905         __u32        cm_padding;    /* 64 bit align */
2906         __s64        cm_createtime; /*when this record was first created */
2907         __s64        cm_canceltime; /*when this record is no longer valid*/
2908         char          cm_tgtname[MTI_NAME_MAXLEN];
2909         char          cm_comment[MTI_NAME_MAXLEN];
2910 };
2911
2912 void lustre_swab_cfg_marker(struct cfg_marker *marker, int swab, int size);
2913
2914 /*
2915  * Opcodes for multiple servers.
2916  */
2917
2918 enum obd_cmd {
2919         OBD_PING = 400,
2920         OBD_LOG_CANCEL,
2921         OBD_QC_CALLBACK,
2922         OBD_IDX_READ,
2923         OBD_LAST_OPC
2924 };
2925 #define OBD_FIRST_OPC OBD_PING
2926
2927 /* catalog of log objects */
2928
2929 /** Identifier for a single log object */
2930 struct llog_logid {
2931         struct ost_id           lgl_oi;
2932         __u32              lgl_ogen;
2933 } __packed;
2934
2935 /** Records written to the CATALOGS list */
2936 #define CATLIST "CATALOGS"
2937 struct llog_catid {
2938         struct llog_logid       lci_logid;
2939         __u32              lci_padding1;
2940         __u32              lci_padding2;
2941         __u32              lci_padding3;
2942 } __packed;
2943
2944 /* Log data record types - there is no specific reason that these need to
2945  * be related to the RPC opcodes, but no reason not to (may be handy later?)
2946  */
2947 #define LLOG_OP_MAGIC 0x10600000
2948 #define LLOG_OP_MASK  0xfff00000
2949
2950 enum llog_op_type {
2951         LLOG_PAD_MAGIC          = LLOG_OP_MAGIC | 0x00000,
2952         OST_SZ_REC              = LLOG_OP_MAGIC | 0x00f00,
2953         /* OST_RAID1_REC        = LLOG_OP_MAGIC | 0x01000, never used */
2954         MDS_UNLINK_REC          = LLOG_OP_MAGIC | 0x10000 | (MDS_REINT << 8) |
2955                                   REINT_UNLINK, /* obsolete after 2.5.0 */
2956         MDS_UNLINK64_REC        = LLOG_OP_MAGIC | 0x90000 | (MDS_REINT << 8) |
2957                                   REINT_UNLINK,
2958         /* MDS_SETATTR_REC      = LLOG_OP_MAGIC | 0x12401, obsolete 1.8.0 */
2959         MDS_SETATTR64_REC       = LLOG_OP_MAGIC | 0x90000 | (MDS_REINT << 8) |
2960                                   REINT_SETATTR,
2961         OBD_CFG_REC             = LLOG_OP_MAGIC | 0x20000,
2962         /* PTL_CFG_REC          = LLOG_OP_MAGIC | 0x30000, obsolete 1.4.0 */
2963         LLOG_GEN_REC            = LLOG_OP_MAGIC | 0x40000,
2964         /* LLOG_JOIN_REC        = LLOG_OP_MAGIC | 0x50000, obsolete  1.8.0 */
2965         CHANGELOG_REC           = LLOG_OP_MAGIC | 0x60000,
2966         CHANGELOG_USER_REC      = LLOG_OP_MAGIC | 0x70000,
2967         HSM_AGENT_REC           = LLOG_OP_MAGIC | 0x80000,
2968         LLOG_HDR_MAGIC          = LLOG_OP_MAGIC | 0x45539,
2969         LLOG_LOGID_MAGIC        = LLOG_OP_MAGIC | 0x4553b,
2970 };
2971
2972 #define LLOG_REC_HDR_NEEDS_SWABBING(r) \
2973         (((r)->lrh_type & __swab32(LLOG_OP_MASK)) == __swab32(LLOG_OP_MAGIC))
2974
2975 /** Log record header - stored in little endian order.
2976  * Each record must start with this struct, end with a llog_rec_tail,
2977  * and be a multiple of 256 bits in size.
2978  */
2979 struct llog_rec_hdr {
2980         __u32   lrh_len;
2981         __u32   lrh_index;
2982         __u32   lrh_type;
2983         __u32   lrh_id;
2984 };
2985
2986 struct llog_rec_tail {
2987         __u32   lrt_len;
2988         __u32   lrt_index;
2989 };
2990
2991 /* Where data follow just after header */
2992 #define REC_DATA(ptr)                                           \
2993         ((void *)((char *)ptr + sizeof(struct llog_rec_hdr)))
2994
2995 #define REC_DATA_LEN(rec)                                       \
2996         (rec->lrh_len - sizeof(struct llog_rec_hdr) -           \
2997          sizeof(struct llog_rec_tail))
2998
2999 struct llog_logid_rec {
3000         struct llog_rec_hdr     lid_hdr;
3001         struct llog_logid       lid_id;
3002         __u32                   lid_padding1;
3003         __u64                   lid_padding2;
3004         __u64                   lid_padding3;
3005         struct llog_rec_tail    lid_tail;
3006 } __packed;
3007
3008 struct llog_unlink_rec {
3009         struct llog_rec_hdr     lur_hdr;
3010         __u64                   lur_oid;
3011         __u32                   lur_oseq;
3012         __u32                   lur_count;
3013         struct llog_rec_tail    lur_tail;
3014 } __packed;
3015
3016 struct llog_unlink64_rec {
3017         struct llog_rec_hdr     lur_hdr;
3018         struct lu_fid           lur_fid;
3019         __u32                   lur_count; /* to destroy the lost precreated */
3020         __u32                   lur_padding1;
3021         __u64                   lur_padding2;
3022         __u64                   lur_padding3;
3023         struct llog_rec_tail    lur_tail;
3024 } __packed;
3025
3026 struct llog_setattr64_rec {
3027         struct llog_rec_hdr     lsr_hdr;
3028         struct ost_id           lsr_oi;
3029         __u32                   lsr_uid;
3030         __u32                   lsr_uid_h;
3031         __u32                   lsr_gid;
3032         __u32                   lsr_gid_h;
3033         __u64                   lsr_padding;
3034         struct llog_rec_tail    lsr_tail;
3035 } __packed;
3036
3037 struct llog_size_change_rec {
3038         struct llog_rec_hdr     lsc_hdr;
3039         struct ll_fid           lsc_fid;
3040         __u32                   lsc_ioepoch;
3041         __u32                   lsc_padding1;
3042         __u64                   lsc_padding2;
3043         __u64                   lsc_padding3;
3044         struct llog_rec_tail    lsc_tail;
3045 } __packed;
3046
3047 /* changelog llog name, needed by client replicators */
3048 #define CHANGELOG_CATALOG "changelog_catalog"
3049
3050 struct changelog_setinfo {
3051         __u64 cs_recno;
3052         __u32 cs_id;
3053 } __packed;
3054
3055 /** changelog record */
3056 struct llog_changelog_rec {
3057         struct llog_rec_hdr  cr_hdr;
3058         struct changelog_rec cr;
3059         struct llog_rec_tail cr_tail; /**< for_sizezof_only */
3060 } __packed;
3061
3062 struct llog_changelog_ext_rec {
3063         struct llog_rec_hdr      cr_hdr;
3064         struct changelog_ext_rec cr;
3065         struct llog_rec_tail     cr_tail; /**< for_sizezof_only */
3066 } __packed;
3067
3068 struct llog_changelog_user_rec {
3069         struct llog_rec_hdr   cur_hdr;
3070         __u32            cur_id;
3071         __u32            cur_padding;
3072         __u64            cur_endrec;
3073         struct llog_rec_tail  cur_tail;
3074 } __packed;
3075
3076 enum agent_req_status {
3077         ARS_WAITING,
3078         ARS_STARTED,
3079         ARS_FAILED,
3080         ARS_CANCELED,
3081         ARS_SUCCEED,
3082 };
3083
3084 static inline char *agent_req_status2name(enum agent_req_status ars)
3085 {
3086         switch (ars) {
3087         case ARS_WAITING:
3088                 return "WAITING";
3089         case ARS_STARTED:
3090                 return "STARTED";
3091         case ARS_FAILED:
3092                 return "FAILED";
3093         case ARS_CANCELED:
3094                 return "CANCELED";
3095         case ARS_SUCCEED:
3096                 return "SUCCEED";
3097         default:
3098                 return "UNKNOWN";
3099         }
3100 }
3101
3102 static inline bool agent_req_in_final_state(enum agent_req_status ars)
3103 {
3104         return ((ars == ARS_SUCCEED) || (ars == ARS_FAILED) ||
3105                 (ars == ARS_CANCELED));
3106 }
3107
3108 struct llog_agent_req_rec {
3109         struct llog_rec_hdr     arr_hdr;        /**< record header */
3110         __u32                   arr_status;     /**< status of the request */
3111                                                 /* must match enum
3112                                                  * agent_req_status
3113                                                  */
3114         __u32                   arr_archive_id; /**< backend archive number */
3115         __u64                   arr_flags;      /**< req flags */
3116         __u64                   arr_compound_id;/**< compound cookie */
3117         __u64                   arr_req_create; /**< req. creation time */
3118         __u64                   arr_req_change; /**< req. status change time */
3119         struct hsm_action_item  arr_hai;        /**< req. to the agent */
3120         struct llog_rec_tail    arr_tail;   /**< record tail for_sizezof_only */
3121 } __packed;
3122
3123 /* Old llog gen for compatibility */
3124 struct llog_gen {
3125         __u64 mnt_cnt;
3126         __u64 conn_cnt;
3127 } __packed;
3128
3129 struct llog_gen_rec {
3130         struct llog_rec_hdr     lgr_hdr;
3131         struct llog_gen         lgr_gen;
3132         __u64                   padding1;
3133         __u64                   padding2;
3134         __u64                   padding3;
3135         struct llog_rec_tail    lgr_tail;
3136 };
3137
3138 /* On-disk header structure of each log object, stored in little endian order */
3139 #define LLOG_CHUNK_SIZE  8192
3140 #define LLOG_HEADER_SIZE        (96)
3141 #define LLOG_BITMAP_BYTES       (LLOG_CHUNK_SIZE - LLOG_HEADER_SIZE)
3142
3143 #define LLOG_MIN_REC_SIZE       (24) /* round(llog_rec_hdr + llog_rec_tail) */
3144
3145 /* flags for the logs */
3146 enum llog_flag {
3147         LLOG_F_ZAP_WHEN_EMPTY   = 0x1,
3148         LLOG_F_IS_CAT           = 0x2,
3149         LLOG_F_IS_PLAIN         = 0x4,
3150 };
3151
3152 struct llog_log_hdr {
3153         struct llog_rec_hdr     llh_hdr;
3154         __s64              llh_timestamp;
3155         __u32              llh_count;
3156         __u32              llh_bitmap_offset;
3157         __u32              llh_size;
3158         __u32              llh_flags;
3159         __u32              llh_cat_idx;
3160         /* for a catalog the first plain slot is next to it */
3161         struct obd_uuid  llh_tgtuuid;
3162         __u32              llh_reserved[LLOG_HEADER_SIZE/sizeof(__u32) - 23];
3163         __u32              llh_bitmap[LLOG_BITMAP_BYTES/sizeof(__u32)];
3164         struct llog_rec_tail    llh_tail;
3165 } __packed;
3166
3167 #define LLOG_BITMAP_SIZE(llh)  (__u32)((llh->llh_hdr.lrh_len -          \
3168                                         llh->llh_bitmap_offset -        \
3169                                         sizeof(llh->llh_tail)) * 8)
3170
3171 /** log cookies are used to reference a specific log file and a record
3172  * therein
3173  */
3174 struct llog_cookie {
3175         struct llog_logid       lgc_lgl;
3176         __u32              lgc_subsys;
3177         __u32              lgc_index;
3178         __u32              lgc_padding;
3179 } __packed;
3180
3181 /** llog protocol */
3182 enum llogd_rpc_ops {
3183         LLOG_ORIGIN_HANDLE_CREATE       = 501,
3184         LLOG_ORIGIN_HANDLE_NEXT_BLOCK   = 502,
3185         LLOG_ORIGIN_HANDLE_READ_HEADER  = 503,
3186         LLOG_ORIGIN_HANDLE_WRITE_REC    = 504,
3187         LLOG_ORIGIN_HANDLE_CLOSE        = 505,
3188         LLOG_ORIGIN_CONNECT             = 506,
3189         LLOG_CATINFO                    = 507,  /* deprecated */
3190         LLOG_ORIGIN_HANDLE_PREV_BLOCK   = 508,
3191         LLOG_ORIGIN_HANDLE_DESTROY      = 509,  /* for destroy llog object*/
3192         LLOG_LAST_OPC,
3193         LLOG_FIRST_OPC            = LLOG_ORIGIN_HANDLE_CREATE
3194 };
3195
3196 struct llogd_body {
3197         struct llog_logid  lgd_logid;
3198         __u32 lgd_ctxt_idx;
3199         __u32 lgd_llh_flags;
3200         __u32 lgd_index;
3201         __u32 lgd_saved_index;
3202         __u32 lgd_len;
3203         __u64 lgd_cur_offset;
3204 } __packed;
3205
3206 struct llogd_conn_body {
3207         struct llog_gen  lgdc_gen;
3208         struct llog_logid       lgdc_logid;
3209         __u32              lgdc_ctxt_idx;
3210 } __packed;
3211
3212 /* Note: 64-bit types are 64-bit aligned in structure */
3213 struct obdo {
3214         __u64           o_valid;        /* hot fields in this obdo */
3215         struct ost_id   o_oi;
3216         __u64           o_parent_seq;
3217         __u64           o_size;  /* o_size-o_blocks == ost_lvb */
3218         __s64           o_mtime;
3219         __s64           o_atime;
3220         __s64           o_ctime;
3221         __u64           o_blocks;       /* brw: cli sent cached bytes */
3222         __u64           o_grant;
3223
3224         /* 32-bit fields start here: keep an even number of them via padding */
3225         __u32           o_blksize;      /* optimal IO blocksize */
3226         __u32           o_mode;  /* brw: cli sent cache remain */
3227         __u32           o_uid;
3228         __u32           o_gid;
3229         __u32           o_flags;
3230         __u32           o_nlink;        /* brw: checksum */
3231         __u32           o_parent_oid;
3232         __u32           o_misc;         /* brw: o_dropped */
3233
3234         __u64              o_ioepoch;      /* epoch in ost writes */
3235         __u32              o_stripe_idx;   /* holds stripe idx */
3236         __u32              o_parent_ver;
3237         struct lustre_handle    o_handle;  /* brw: lock handle to prolong locks
3238                                             */
3239         struct llog_cookie      o_lcookie; /* destroy: unlink cookie from MDS
3240                                             */
3241         __u32                   o_uid_h;
3242         __u32                   o_gid_h;
3243
3244         __u64                   o_data_version; /* getattr: sum of iversion for
3245                                                  * each stripe.
3246                                                  * brw: grant space consumed on
3247                                                  * the client for the write
3248                                                  */
3249         __u64                   o_padding_4;
3250         __u64                   o_padding_5;
3251         __u64                   o_padding_6;
3252 };
3253
3254 #define o_dirty   o_blocks
3255 #define o_undirty o_mode
3256 #define o_dropped o_misc
3257 #define o_cksum   o_nlink
3258 #define o_grant_used o_data_version
3259
3260 static inline void lustre_set_wire_obdo(struct obd_connect_data *ocd,
3261                                         struct obdo *wobdo,
3262                                         const struct obdo *lobdo)
3263 {
3264         *wobdo = *lobdo;
3265         wobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
3266         if (!ocd)
3267                 return;
3268
3269         if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
3270             fid_seq_is_echo(ostid_seq(&lobdo->o_oi))) {
3271                 /* Currently OBD_FL_OSTID will only be used when 2.4 echo
3272                  * client communicate with pre-2.4 server
3273                  */
3274                 wobdo->o_oi.oi.oi_id = fid_oid(&lobdo->o_oi.oi_fid);
3275                 wobdo->o_oi.oi.oi_seq = fid_seq(&lobdo->o_oi.oi_fid);
3276         }
3277 }
3278
3279 static inline void lustre_get_wire_obdo(struct obd_connect_data *ocd,
3280                                         struct obdo *lobdo,
3281                                         const struct obdo *wobdo)
3282 {
3283         __u32 local_flags = 0;
3284
3285         if (lobdo->o_valid & OBD_MD_FLFLAGS)
3286                 local_flags = lobdo->o_flags & OBD_FL_LOCAL_MASK;
3287
3288         *lobdo = *wobdo;
3289         if (local_flags != 0) {
3290                 lobdo->o_valid |= OBD_MD_FLFLAGS;
3291                 lobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
3292                 lobdo->o_flags |= local_flags;
3293         }
3294         if (!ocd)
3295                 return;
3296
3297         if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
3298             fid_seq_is_echo(wobdo->o_oi.oi.oi_seq)) {
3299                 /* see above */
3300                 lobdo->o_oi.oi_fid.f_seq = wobdo->o_oi.oi.oi_seq;
3301                 lobdo->o_oi.oi_fid.f_oid = wobdo->o_oi.oi.oi_id;
3302                 lobdo->o_oi.oi_fid.f_ver = 0;
3303         }
3304 }
3305
3306 /* request structure for OST's */
3307 struct ost_body {
3308         struct  obdo oa;
3309 };
3310
3311 /* Key for FIEMAP to be used in get_info calls */
3312 struct ll_fiemap_info_key {
3313         char    name[8];
3314         struct  obdo oa;
3315         struct  ll_user_fiemap fiemap;
3316 };
3317
3318 void lustre_swab_ost_body(struct ost_body *b);
3319 void lustre_swab_ost_last_id(__u64 *id);
3320 void lustre_swab_fiemap(struct ll_user_fiemap *fiemap);
3321
3322 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum);
3323 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum);
3324 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
3325                                      int stripe_count);
3326 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm);
3327
3328 /* llog_swab.c */
3329 void lustre_swab_llogd_body(struct llogd_body *d);
3330 void lustre_swab_llog_hdr(struct llog_log_hdr *h);
3331 void lustre_swab_llogd_conn_body(struct llogd_conn_body *d);
3332 void lustre_swab_llog_rec(struct llog_rec_hdr *rec);
3333
3334 struct lustre_cfg;
3335 void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg);
3336
3337 /* Functions for dumping PTLRPC fields */
3338 void dump_rniobuf(struct niobuf_remote *rnb);
3339 void dump_ioo(struct obd_ioobj *nb);
3340 void dump_ost_body(struct ost_body *ob);
3341 void dump_rcs(__u32 *rc);
3342
3343 /* security opcodes */
3344 enum sec_cmd {
3345         SEC_CTX_INIT        = 801,
3346         SEC_CTX_INIT_CONT       = 802,
3347         SEC_CTX_FINI        = 803,
3348         SEC_LAST_OPC,
3349         SEC_FIRST_OPC      = SEC_CTX_INIT
3350 };
3351
3352 /*
3353  * capa related definitions
3354  */
3355 #define CAPA_HMAC_MAX_LEN       64
3356 #define CAPA_HMAC_KEY_MAX_LEN   56
3357
3358 /* NB take care when changing the sequence of elements this struct,
3359  * because the offset info is used in find_capa()
3360  */
3361 struct lustre_capa {
3362         struct lu_fid   lc_fid;  /** fid */
3363         __u64      lc_opc;       /** operations allowed */
3364         __u64      lc_uid;       /** file owner */
3365         __u64      lc_gid;       /** file group */
3366         __u32      lc_flags;       /** HMAC algorithm & flags */
3367         __u32      lc_keyid;       /** key# used for the capability */
3368         __u32      lc_timeout;     /** capa timeout value (sec) */
3369 /* FIXME: y2038 time_t overflow: */
3370         __u32      lc_expiry;      /** expiry time (sec) */
3371         __u8        lc_hmac[CAPA_HMAC_MAX_LEN];   /** HMAC */
3372 } __packed;
3373
3374 void lustre_swab_lustre_capa(struct lustre_capa *c);
3375
3376 /** lustre_capa::lc_opc */
3377 enum {
3378         CAPA_OPC_BODY_WRITE   = 1<<0,  /**< write object data */
3379         CAPA_OPC_BODY_READ    = 1<<1,  /**< read object data */
3380         CAPA_OPC_INDEX_LOOKUP = 1<<2,  /**< lookup object fid */
3381         CAPA_OPC_INDEX_INSERT = 1<<3,  /**< insert object fid */
3382         CAPA_OPC_INDEX_DELETE = 1<<4,  /**< delete object fid */
3383         CAPA_OPC_OSS_WRITE    = 1<<5,  /**< write oss object data */
3384         CAPA_OPC_OSS_READ     = 1<<6,  /**< read oss object data */
3385         CAPA_OPC_OSS_TRUNC    = 1<<7,  /**< truncate oss object */
3386         CAPA_OPC_OSS_DESTROY  = 1<<8,  /**< destroy oss object */
3387         CAPA_OPC_META_WRITE   = 1<<9,  /**< write object meta data */
3388         CAPA_OPC_META_READ    = 1<<10, /**< read object meta data */
3389 };
3390
3391 #define CAPA_OPC_OSS_RW (CAPA_OPC_OSS_READ | CAPA_OPC_OSS_WRITE)
3392 #define CAPA_OPC_MDS_ONLY                                                  \
3393         (CAPA_OPC_BODY_WRITE | CAPA_OPC_BODY_READ | CAPA_OPC_INDEX_LOOKUP | \
3394          CAPA_OPC_INDEX_INSERT | CAPA_OPC_INDEX_DELETE)
3395 #define CAPA_OPC_OSS_ONLY                                                  \
3396         (CAPA_OPC_OSS_WRITE | CAPA_OPC_OSS_READ | CAPA_OPC_OSS_TRUNC |      \
3397          CAPA_OPC_OSS_DESTROY)
3398 #define CAPA_OPC_MDS_DEFAULT ~CAPA_OPC_OSS_ONLY
3399 #define CAPA_OPC_OSS_DEFAULT ~(CAPA_OPC_MDS_ONLY | CAPA_OPC_OSS_ONLY)
3400
3401 struct lustre_capa_key {
3402         __u64   lk_seq;       /**< mds# */
3403         __u32   lk_keyid;     /**< key# */
3404         __u32   lk_padding;
3405         __u8    lk_key[CAPA_HMAC_KEY_MAX_LEN];    /**< key */
3406 } __packed;
3407
3408 /** The link ea holds 1 \a link_ea_entry for each hardlink */
3409 #define LINK_EA_MAGIC 0x11EAF1DFUL
3410 struct link_ea_header {
3411         __u32 leh_magic;
3412         __u32 leh_reccount;
3413         __u64 leh_len;      /* total size */
3414         /* future use */
3415         __u32 padding1;
3416         __u32 padding2;
3417 };
3418
3419 /** Hardlink data is name and parent fid.
3420  * Stored in this crazy struct for maximum packing and endian-neutrality
3421  */
3422 struct link_ea_entry {
3423         /** __u16 stored big-endian, unaligned */
3424         unsigned char      lee_reclen[2];
3425         unsigned char      lee_parent_fid[sizeof(struct lu_fid)];
3426         char           lee_name[0];
3427 } __packed;
3428
3429 /** fid2path request/reply structure */
3430 struct getinfo_fid2path {
3431         struct lu_fid   gf_fid;
3432         __u64      gf_recno;
3433         __u32      gf_linkno;
3434         __u32      gf_pathlen;
3435         char        gf_path[0];
3436 } __packed;
3437
3438 void lustre_swab_fid2path(struct getinfo_fid2path *gf);
3439
3440 enum {
3441         LAYOUT_INTENT_ACCESS    = 0,
3442         LAYOUT_INTENT_READ      = 1,
3443         LAYOUT_INTENT_WRITE     = 2,
3444         LAYOUT_INTENT_GLIMPSE   = 3,
3445         LAYOUT_INTENT_TRUNC     = 4,
3446         LAYOUT_INTENT_RELEASE   = 5,
3447         LAYOUT_INTENT_RESTORE   = 6
3448 };
3449
3450 /* enqueue layout lock with intent */
3451 struct layout_intent {
3452         __u32 li_opc; /* intent operation for enqueue, read, write etc */
3453         __u32 li_flags;
3454         __u64 li_start;
3455         __u64 li_end;
3456 };
3457
3458 void lustre_swab_layout_intent(struct layout_intent *li);
3459
3460 /**
3461  * On the wire version of hsm_progress structure.
3462  *
3463  * Contains the userspace hsm_progress and some internal fields.
3464  */
3465 struct hsm_progress_kernel {
3466         /* Field taken from struct hsm_progress */
3467         struct lu_fid           hpk_fid;
3468         __u64                   hpk_cookie;
3469         struct hsm_extent       hpk_extent;
3470         __u16                   hpk_flags;
3471         __u16                   hpk_errval; /* positive val */
3472         __u32                   hpk_padding1;
3473         /* Additional fields */
3474         __u64                   hpk_data_version;
3475         __u64                   hpk_padding2;
3476 } __packed;
3477
3478 void lustre_swab_hsm_user_state(struct hsm_user_state *hus);
3479 void lustre_swab_hsm_current_action(struct hsm_current_action *action);
3480 void lustre_swab_hsm_progress_kernel(struct hsm_progress_kernel *hpk);
3481 void lustre_swab_hsm_user_state(struct hsm_user_state *hus);
3482 void lustre_swab_hsm_user_item(struct hsm_user_item *hui);
3483 void lustre_swab_hsm_request(struct hsm_request *hr);
3484
3485 /** layout swap request structure
3486  * fid1 and fid2 are in mdt_body
3487  */
3488 struct mdc_swap_layouts {
3489         __u64      msl_flags;
3490 } __packed;
3491
3492 void lustre_swab_swap_layouts(struct mdc_swap_layouts *msl);
3493
3494 struct close_data {
3495         struct lustre_handle    cd_handle;
3496         struct lu_fid           cd_fid;
3497         __u64                   cd_data_version;
3498         __u64                   cd_reserved[8];
3499 };
3500
3501 void lustre_swab_close_data(struct close_data *data);
3502
3503 #endif
3504 /** @} lustreidl */