Whamcloud - gitweb
0febd116b5a697afd9e2151b4839c6ba49bc4e94
[fs/lustre-release.git] / lustre / include / linux / lustre_idl.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * (Un)packing of OST requests
22  */
23
24 #ifndef _LUSTRE_IDL_H_
25 #define _LUSTRE_IDL_H_
26
27 #ifdef __KERNEL__
28 # include <linux/ioctl.h>
29 # include <asm/types.h>
30 # include <linux/types.h>
31 # include <linux/list.h>
32 #else
33 # define __KERNEL__
34 # include <asm/types.h>
35 # include <linux/list.h>
36 # undef __KERNEL__
37 # include <stdint.h>
38 #endif
39 /*
40  * this file contains all data structures used in Lustre interfaces:
41  * - obdo and obd_request records
42  * - mds_request records
43  * - ldlm data
44  * - ioctl's
45  */
46
47 /*
48  *  GENERAL STUFF
49  */
50 typedef __u8 obd_uuid_t[37];
51
52 /* FOO_REQUEST_PORTAL is for incoming requests on the FOO
53  * FOO_REPLY_PORTAL   is for incoming replies on the FOO
54  * FOO_BULK_PORTAL    is for incoming bulk on the FOO
55  */
56
57 #define CONNMGR_REQUEST_PORTAL  1
58 #define CONNMGR_REPLY_PORTAL    2
59 #define OSC_REQUEST_PORTAL      3
60 #define OSC_REPLY_PORTAL        4
61 #define OSC_BULK_PORTAL         5
62 #define OST_REQUEST_PORTAL      6
63 #define OST_REPLY_PORTAL        7
64 #define OST_BULK_PORTAL         8
65 #define MDC_REQUEST_PORTAL      9
66 #define MDC_REPLY_PORTAL        10
67 #define MDC_BULK_PORTAL         11
68 #define MDS_REQUEST_PORTAL      12
69 #define MDS_REPLY_PORTAL        13
70 #define MDS_BULK_PORTAL         14
71 #define LDLM_CB_REQUEST_PORTAL     15
72 #define LDLM_CB_REPLY_PORTAL       16
73 #define LDLM_CANCEL_REQUEST_PORTAL     17
74 #define LDLM_CANCEL_REPLY_PORTAL       18
75
76 #define SVC_KILLED               1
77 #define SVC_EVENT                2
78 #define SVC_SIGNAL               4
79 #define SVC_RUNNING              8
80 #define SVC_STOPPING            16
81 #define SVC_STOPPED             32
82
83 #define LUSTRE_CONN_NEW          1
84 #define LUSTRE_CONN_CON          2
85 #define LUSTRE_CONN_RECOVD       3
86 #define LUSTRE_CONN_FULL         4
87
88 /* packet types */
89 #define PTL_RPC_MSG_REQUEST 4711
90 #define PTL_RPC_MSG_ERR     4712
91 #define PTL_RPC_MSG_REPLY   4713
92
93 #define PTLRPC_MSG_MAGIC (cpu_to_le32(0x0BD00BD0))
94 #define PTLRPC_MSG_VERSION (cpu_to_le32(0x00040001))
95
96 struct lustre_handle {
97         __u64 addr;
98         __u64 cookie;
99 };
100 #define DEAD_HANDLE_MAGIC 0xdeadbeefcafebabe
101
102 static inline void ptlrpc_invalidate_handle(struct lustre_handle *hdl)
103 {
104         hdl->addr = hdl->cookie = 0; /* XXX invalid enough? */
105 }
106
107 /* we depend on this structure to be 8-byte aligned */
108 struct lustre_msg {
109         __u64 addr;
110         __u64 cookie; /* security token */
111         __u32 magic;
112         __u32 type;
113         __u32 version;
114         __u32 opc;
115         __u64 last_xid;
116         __u64 last_committed;
117         __u64 transno;
118         __u32 status;
119         __u32 bufcount;
120         __u32 flags;
121         __u32 buflens[0];
122 };
123
124 /* Flags that are operation-specific go in the top 16 bits. */
125 #define MSG_OP_FLAG_MASK   0xffff0000
126 #define MSG_OP_FLAG_SHIFT  16
127
128 /* Flags that apply to all requests are in the bottom 16 bits */
129 #define MSG_GEN_FLAG_MASK  0x0000ffff
130 #define MSG_LAST_REPLAY    1
131 #define MSG_RESENT         2
132
133 static inline int lustre_msg_get_flags(struct lustre_msg *msg)
134 {
135         return (msg->flags & MSG_GEN_FLAG_MASK);
136 }
137
138 static inline void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
139 {
140         msg->flags |= MSG_GEN_FLAG_MASK & flags;
141 }
142
143 static inline void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
144 {
145         msg->flags &= ~MSG_GEN_FLAG_MASK;
146         lustre_msg_add_flags(msg, flags);
147 }
148
149 static inline int lustre_msg_get_op_flags(struct lustre_msg *msg)
150 {
151         return (msg->flags >> MSG_OP_FLAG_SHIFT);
152 }
153
154 static inline void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
155 {
156         msg->flags &= ~MSG_OP_FLAG_MASK;
157         msg->flags |= ((flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT);
158 }
159
160 #define CONNMGR_REPLY   0
161 #define CONNMGR_CONNECT 1
162
163 /*
164  *   OST requests: OBDO & OBD request records
165  */
166
167 /* opcodes */
168 #define OST_REPLY       0        /* reply ? */
169 #define OST_GETATTR     1
170 #define OST_SETATTR     2
171 #define OST_READ        3
172 #define OST_WRITE       4
173 #define OST_CREATE      5
174 #define OST_DESTROY     6
175 #define OST_GET_INFO    7
176 #define OST_CONNECT     8
177 #define OST_DISCONNECT  9
178 #define OST_PUNCH      10
179 #define OST_OPEN       11
180 #define OST_CLOSE      12
181 #define OST_STATFS     13
182
183
184 typedef uint64_t        obd_id;
185 typedef uint64_t        obd_gr;
186 typedef uint64_t        obd_time;
187 typedef uint64_t        obd_size;
188 typedef uint64_t        obd_off;
189 typedef uint64_t        obd_blocks;
190 typedef uint32_t        obd_blksize;
191 typedef uint32_t        obd_mode;
192 typedef uint32_t        obd_uid;
193 typedef uint32_t        obd_gid;
194 typedef uint64_t        obd_rdev;
195 typedef uint32_t        obd_flag;
196 typedef uint32_t        obd_count;
197
198 #define OBD_FL_INLINEDATA       (0x00000001)
199 #define OBD_FL_OBDMDEXISTS      (0x00000002)
200
201 #define OBD_INLINESZ    60
202
203 /* Note: 64-bit types are 64-bit aligned in structure */
204 struct obdo {
205         obd_id                  o_id;
206         obd_gr                  o_gr;
207         obd_time                o_atime;
208         obd_time                o_mtime;
209         obd_time                o_ctime;
210         obd_size                o_size;
211         obd_blocks              o_blocks;
212         obd_rdev                o_rdev;
213         obd_blksize             o_blksize;
214         obd_mode                o_mode;
215         obd_uid                 o_uid;
216         obd_gid                 o_gid;
217         obd_flag                o_flags;
218         obd_count               o_nlink;
219         obd_count               o_generation;
220         obd_flag                o_valid;        /* hot fields in this obdo */
221         obd_flag                o_obdflags;
222         __u32                   o_easize;
223         char                    o_inline[OBD_INLINESZ];
224 };
225
226 struct lov_object_id { /* per-child structure */
227         __u64 l_object_id;
228 };
229
230 #define LOV_MAGIC  0x0BD00BD0
231
232 struct lov_mds_md {
233         __u32 lmm_magic;
234         __u32 lmm_unused;          /* was packed size of extended attribute */
235         __u64 lmm_object_id;       /* lov object id */
236         __u32 lmm_stripe_offset;   /* starting stripe offset in lmd_objects */
237         __u32 lmm_stripe_count;    /* number of stipes in use for this object */
238         __u64 lmm_stripe_size;     /* size of the stripe */
239         __u32 lmm_ost_count;       /* how many OST idx are in this LOV md */
240         __u32 lmm_stripe_pattern;  /* per-lov object stripe pattern */
241         struct lov_object_id lmm_objects[0];
242 };
243
244 #define OBD_MD_FLALL    (0xffffffff)
245 #define OBD_MD_FLID     (0x00000001)    /* object ID */
246 #define OBD_MD_FLATIME  (0x00000002)    /* access time */
247 #define OBD_MD_FLMTIME  (0x00000004)    /* data modification time */
248 #define OBD_MD_FLCTIME  (0x00000008)    /* change time */
249 #define OBD_MD_FLSIZE   (0x00000010)    /* size */
250 #define OBD_MD_FLBLOCKS (0x00000020)    /* allocated blocks count */
251 #define OBD_MD_FLBLKSZ  (0x00000040)    /* block size */
252 #define OBD_MD_FLMODE   (0x00000080)    /* access bits (mode & ~S_IFMT) */
253 #define OBD_MD_FLTYPE   (0x00000100)    /* object type (mode & S_IFMT) */
254 #define OBD_MD_FLUID    (0x00000200)    /* user ID */
255 #define OBD_MD_FLGID    (0x00000400)    /* group ID */
256 #define OBD_MD_FLFLAGS  (0x00000800)    /* flags word */
257 #define OBD_MD_FLOBDFLG (0x00001000)
258 #define OBD_MD_FLNLINK  (0x00002000)    /* link count */
259 #define OBD_MD_FLGENER  (0x00004000)    /* generation number */
260 #define OBD_MD_FLINLINE (0x00008000)    /* inline data */
261 #define OBD_MD_FLRDEV   (0x00010000)    /* device number */
262 #define OBD_MD_FLEASIZE (0x00020000)    /* extended attribute data */
263 #define OBD_MD_LINKNAME (0x00040000)    /* symbolic link target */
264 #define OBD_MD_FLHANDLE (0x00080000)    /* file handle */
265 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS | OBD_MD_LINKNAME|\
266                            OBD_MD_FLEASIZE | OBD_MD_FLHANDLE))
267
268 struct obd_statfs {
269         __u64           os_type;
270         __u64           os_blocks;
271         __u64           os_bfree;
272         __u64           os_bavail;
273         __u64           os_files;
274         __u64           os_ffree;
275         __u8            os_fsid[40];
276         __u32           os_bsize;
277         __u32           os_namelen;
278         __u32           os_spare[12];
279 };
280
281 /* ost_body.data values for OST_BRW */
282
283 #define OBD_BRW_READ    0x1
284 #define OBD_BRW_WRITE   0x2
285 #define OBD_BRW_RWMASK  (OBD_BRW_READ | OBD_BRW_WRITE)
286 #define OBD_BRW_CREATE  0x4
287
288 #define OBD_OBJECT_EOF 0xffffffffffffffffULL
289
290 struct obd_ioobj {
291         obd_id               ioo_id;
292         obd_gr               ioo_gr;
293         __u32                ioo_type;
294         __u32                ioo_bufcnt;
295 };
296
297 struct niobuf_remote {
298         __u64 offset;
299         __u32 len;
300         __u32 xid;
301         __u32 flags;
302 };
303
304 #define CONNMGR_REPLY   0
305 #define CONNMGR_CONNECT 1
306
307 struct connmgr_body {
308         __u64 conn;
309         __u64 conn_token;
310         __u32 generation;
311         obd_uuid_t conn_uuid;
312 };
313
314 /* request structure for OST's */
315
316 #define OST_REQ_HAS_OA1  0x1
317
318 struct ost_body {
319         struct  obdo oa;
320 };
321
322 /*
323  *   MDS REQ RECORDS
324  */
325
326 /* opcodes */
327 #define MDS_GETATTR    1
328 #define MDS_OPEN       2
329 #define MDS_CLOSE      3
330 #define MDS_REINT      4
331 #define MDS_READPAGE   6
332 #define MDS_CONNECT    7
333 #define MDS_DISCONNECT 8
334 #define MDS_GETSTATUS  9
335 #define MDS_STATFS     10
336 #define MDS_GETLOVINFO 11
337
338 #define REINT_SETATTR  1
339 #define REINT_CREATE   2
340 #define REINT_LINK     3
341 #define REINT_UNLINK   4
342 #define REINT_RENAME   5
343 #define REINT_MAX      5
344
345 #define REINT_OPCODE_MASK 0xff /* opcodes must fit into this mask */
346 #define REINT_REPLAYING 0x1000 /* masked into the opcode to indicate replay */
347
348 struct ll_fid {
349         __u64 id;
350         __u32 generation;
351         __u32 f_type;
352 };
353
354
355 #define MDS_STATUS_CONN 1
356 #define MDS_STATUS_LOV 2
357
358 struct mds_status_req {
359         __u32  flags;
360         __u32  repbuf;
361 };
362
363 struct mds_fileh_body {
364         struct ll_fid f_fid;
365         struct lustre_handle f_handle;
366 };
367
368 struct mds_conn_status {
369         struct ll_fid rootfid;
370         __u64          xid;
371         __u64          last_committed;
372         __u64          last_rcvd;
373         /* XXX preallocated quota & obj fields here */
374 };
375
376 struct mds_body {
377         struct ll_fid  fid1;
378         struct ll_fid  fid2;
379         struct lustre_handle handle;
380         __u64          size;
381         __u32          ino;   /* make this a __u64 */
382         __u32          valid;
383         __u32          fsuid;
384         __u32          fsgid;
385         __u32          capability;
386         __u32          mode;
387         __u32          uid;
388         __u32          gid;
389         __u32          mtime;
390         __u32          ctime;
391         __u32          atime;
392         __u32          flags;
393         __u32          rdev;
394         __u32          nlink;
395         __u32          generation;
396 };
397
398 /* This is probably redundant with OBD_MD_FLEASIZE, but we need an audit */
399 #define MDS_OPEN_HAS_EA 1 /* this open has an EA, for a delayed create*/
400
401 /* MDS update records */
402
403
404 //struct mds_update_record_hdr {
405 //        __u32 ur_opcode;
406 //};
407
408 struct mds_rec_setattr {
409         __u32           sa_opcode;
410         __u32           sa_fsuid;
411         __u32           sa_fsgid;
412         __u32           sa_cap;
413         __u32           sa_reserved;
414         __u32           sa_valid;
415         struct ll_fid   sa_fid;
416         __u32           sa_mode;
417         __u32           sa_uid;
418         __u32           sa_gid;
419         __u32           sa_attr_flags;
420         __u64           sa_size;
421         __u64           sa_atime;
422         __u64           sa_mtime;
423         __u64           sa_ctime;
424 };
425
426 struct mds_rec_create {
427         __u32           cr_opcode;
428         __u32           cr_fsuid;
429         __u32           cr_fsgid;
430         __u32           cr_cap;
431         __u32           cr_reserved;
432         __u32           cr_mode;
433         struct ll_fid   cr_fid;
434         struct ll_fid   cr_replayfid;
435         __u32           cr_uid;
436         __u32           cr_gid;
437         __u64           cr_time;
438         __u64           cr_rdev;
439 };
440
441 struct mds_rec_link {
442         __u32           lk_opcode;
443         __u32           lk_fsuid;
444         __u32           lk_fsgid;
445         __u32           lk_cap;
446         struct ll_fid   lk_fid1;
447         struct ll_fid   lk_fid2;
448 };
449
450 struct mds_rec_unlink {
451         __u32           ul_opcode;
452         __u32           ul_fsuid;
453         __u32           ul_fsgid;
454         __u32           ul_cap;
455         __u32           ul_reserved;
456         __u32           ul_mode;
457         struct ll_fid   ul_fid1;
458         struct ll_fid   ul_fid2;
459 };
460
461 struct mds_rec_rename {
462         __u32           rn_opcode;
463         __u32           rn_fsuid;
464         __u32           rn_fsgid;
465         __u32           rn_cap;
466         struct ll_fid   rn_fid1;
467         struct ll_fid   rn_fid2;
468 };
469
470
471 /*
472  *  LOV data structures
473  */
474
475 #define LOV_RAID0   0
476 #define LOV_RAIDRR  1
477
478 struct lov_desc {
479         __u32 ld_tgt_count;                /* how many OBD's */
480         __u32 ld_active_tgt_count;         /* how many active */
481         __u32 ld_default_stripe_count;     /* how many objects are used */
482         __u64 ld_default_stripe_size;      /* in bytes */
483         __u64 ld_default_stripe_offset;    /* in bytes */
484         __u32 ld_pattern;                  /* RAID 0,1 etc */
485         obd_uuid_t ld_uuid;
486 };
487
488 /*
489  *   LDLM requests:
490  */
491 /* opcodes -- MUST be distinct from OST/MDS opcodes */
492 #define LDLM_ENQUEUE       101
493 #define LDLM_CONVERT       102
494 #define LDLM_CANCEL        103
495 #define LDLM_BL_CALLBACK   104
496 #define LDLM_CP_CALLBACK   105
497
498 #define RES_NAME_SIZE 3
499 #define RES_VERSION_SIZE 4
500
501 /* lock types */
502 typedef enum {
503         LCK_EX = 1,
504         LCK_PW,
505         LCK_PR,
506         LCK_CW,
507         LCK_CR,
508         LCK_NL
509 } ldlm_mode_t;
510
511 struct ldlm_extent {
512         __u64 start;
513         __u64 end;
514 };
515
516 struct ldlm_intent {
517         __u64 opc;
518 };
519
520 /* Note this unaligned structure; as long as it's only used in ldlm_request
521  * below, we're probably fine. */
522 struct ldlm_resource_desc {
523         __u32 lr_type;
524         __u64 lr_name[RES_NAME_SIZE];
525         __u32 lr_version[RES_VERSION_SIZE];
526 };
527
528 struct ldlm_lock_desc {
529         struct ldlm_resource_desc l_resource;
530         ldlm_mode_t l_req_mode;
531         ldlm_mode_t l_granted_mode;
532         struct ldlm_extent l_extent;
533         __u32 l_version[RES_VERSION_SIZE];
534 };
535
536 struct ldlm_request {
537         __u32 lock_flags;
538         struct ldlm_lock_desc lock_desc;
539         struct lustre_handle lock_handle1;
540         struct lustre_handle lock_handle2;
541 };
542
543 struct ldlm_reply {
544         __u32 lock_flags;
545         __u32 lock_mode;
546         __u64 lock_resource_name[RES_NAME_SIZE];
547         struct lustre_handle lock_handle;
548         struct ldlm_extent lock_extent;   /* XXX make this policy 1 &2 */
549         __u64  lock_policy_res1;
550         __u64  lock_policy_res2;
551 };
552 #endif