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