Whamcloud - gitweb
Merge b_md to HEAD for 0.5.19 release.
[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 #define PTLBD_REQUEST_PORTAL           19
76 #define PTLBD_REPLY_PORTAL             20
77 #define PTLBD_BULK_PORTAL              21
78
79 #define SVC_KILLED               1
80 #define SVC_EVENT                2
81 #define SVC_SIGNAL               4
82 #define SVC_RUNNING              8
83 #define SVC_STOPPING            16
84 #define SVC_STOPPED             32
85
86 #define LUSTRE_CONN_NEW          1
87 #define LUSTRE_CONN_CON          2
88 #define LUSTRE_CONN_RECOVD       3
89 #define LUSTRE_CONN_FULL         4
90
91 /* packet types */
92 #define PTL_RPC_MSG_REQUEST 4711
93 #define PTL_RPC_MSG_ERR     4712
94 #define PTL_RPC_MSG_REPLY   4713
95
96 #define PTLRPC_MSG_MAGIC (cpu_to_le32(0x0BD00BD0))
97 #define PTLRPC_MSG_VERSION (cpu_to_le32(0x00040001))
98
99 struct lustre_handle {
100         __u64 addr;
101         __u64 cookie;
102 };
103 #define DEAD_HANDLE_MAGIC 0xdeadbeefcafebabe
104
105 static inline void ptlrpc_invalidate_handle(struct lustre_handle *hdl)
106 {
107         hdl->addr = hdl->cookie = 0; /* XXX invalid enough? */
108 }
109
110 /* we depend on this structure to be 8-byte aligned */
111 struct lustre_msg {
112         __u64 addr;
113         __u64 cookie; /* security token */
114         __u32 magic;
115         __u32 type;
116         __u32 version;
117         __u32 opc;
118         __u64 last_xid;
119         __u64 last_committed;
120         __u64 transno;
121         __u32 status;
122         __u32 bufcount;
123         __u32 flags;
124         __u32 buflens[0];
125 };
126
127 /* Flags that are operation-specific go in the top 16 bits. */
128 #define MSG_OP_FLAG_MASK   0xffff0000
129 #define MSG_OP_FLAG_SHIFT  16
130
131 /* Flags that apply to all requests are in the bottom 16 bits */
132 #define MSG_GEN_FLAG_MASK      0x0000ffff
133 #define MSG_LAST_REPLAY        1
134 #define MSG_RESENT             2
135
136 /* XXX horrible interim hack -- see bug 578 */
137 #define MSG_REPLAY_IN_PROGRESS 4
138
139 static inline int lustre_msg_get_flags(struct lustre_msg *msg)
140 {
141         return (msg->flags & MSG_GEN_FLAG_MASK);
142 }
143
144 static inline void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
145 {
146         msg->flags |= MSG_GEN_FLAG_MASK & flags;
147 }
148
149 static inline void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
150 {
151         msg->flags &= ~MSG_GEN_FLAG_MASK;
152         lustre_msg_add_flags(msg, flags);
153 }
154
155 static inline int lustre_msg_get_op_flags(struct lustre_msg *msg)
156 {
157         return (msg->flags >> MSG_OP_FLAG_SHIFT);
158 }
159
160 static inline void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
161 {
162         msg->flags &= ~MSG_OP_FLAG_MASK;
163         msg->flags |= ((flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT);
164 }
165
166 #define CONNMGR_REPLY   0
167 #define CONNMGR_CONNECT 1
168
169 /*
170  *   OST requests: OBDO & OBD request records
171  */
172
173 /* opcodes */
174 #define OST_REPLY       0        /* reply ? */
175 #define OST_GETATTR     1
176 #define OST_SETATTR     2
177 #define OST_READ        3
178 #define OST_WRITE       4
179 #define OST_CREATE      5
180 #define OST_DESTROY     6
181 #define OST_GET_INFO    7
182 #define OST_CONNECT     8
183 #define OST_DISCONNECT  9
184 #define OST_PUNCH      10
185 #define OST_OPEN       11
186 #define OST_CLOSE      12
187 #define OST_STATFS     13
188
189
190 typedef uint64_t        obd_id;
191 typedef uint64_t        obd_gr;
192 typedef uint64_t        obd_time;
193 typedef uint64_t        obd_size;
194 typedef uint64_t        obd_off;
195 typedef uint64_t        obd_blocks;
196 typedef uint32_t        obd_blksize;
197 typedef uint32_t        obd_mode;
198 typedef uint32_t        obd_uid;
199 typedef uint32_t        obd_gid;
200 typedef uint64_t        obd_rdev;
201 typedef uint32_t        obd_flag;
202 typedef uint32_t        obd_count;
203
204 #define OBD_FL_INLINEDATA       (0x00000001)
205 #define OBD_FL_OBDMDEXISTS      (0x00000002)
206
207 #define OBD_INLINESZ    60
208
209 /* Note: 64-bit types are 64-bit aligned in structure */
210 struct obdo {
211         obd_id                  o_id;
212         obd_gr                  o_gr;
213         obd_time                o_atime;
214         obd_time                o_mtime;
215         obd_time                o_ctime;
216         obd_size                o_size;
217         obd_blocks              o_blocks;
218         obd_rdev                o_rdev;
219         obd_blksize             o_blksize;
220         obd_mode                o_mode;
221         obd_uid                 o_uid;
222         obd_gid                 o_gid;
223         obd_flag                o_flags;
224         obd_count               o_nlink;
225         obd_count               o_generation;
226         obd_flag                o_valid;        /* hot fields in this obdo */
227         obd_flag                o_obdflags;
228         __u32                   o_easize;
229         char                    o_inline[OBD_INLINESZ];
230 };
231
232 struct lov_object_id { /* per-child structure */
233         __u64 l_object_id;
234 };
235
236 #define LOV_MAGIC  0x0BD00BD0
237
238 struct lov_mds_md {
239         __u32 lmm_magic;
240         __u64 lmm_object_id;       /* lov object id */
241         __u32 lmm_stripe_size;     /* size of the stripe */
242         __u32 lmm_stripe_offset;   /* starting stripe offset in lmm_objects */
243         __u16 lmm_stripe_count;    /* number of stipes in use for this object */
244         __u16 lmm_ost_count;       /* how many OST idx are in this LOV md */
245         struct lov_object_id lmm_objects[0];
246 };
247
248 #define OBD_MD_FLALL    (0xffffffff)
249 #define OBD_MD_FLID     (0x00000001)    /* object ID */
250 #define OBD_MD_FLATIME  (0x00000002)    /* access time */
251 #define OBD_MD_FLMTIME  (0x00000004)    /* data modification time */
252 #define OBD_MD_FLCTIME  (0x00000008)    /* change time */
253 #define OBD_MD_FLSIZE   (0x00000010)    /* size */
254 #define OBD_MD_FLBLOCKS (0x00000020)    /* allocated blocks count */
255 #define OBD_MD_FLBLKSZ  (0x00000040)    /* block size */
256 #define OBD_MD_FLMODE   (0x00000080)    /* access bits (mode & ~S_IFMT) */
257 #define OBD_MD_FLTYPE   (0x00000100)    /* object type (mode & S_IFMT) */
258 #define OBD_MD_FLUID    (0x00000200)    /* user ID */
259 #define OBD_MD_FLGID    (0x00000400)    /* group ID */
260 #define OBD_MD_FLFLAGS  (0x00000800)    /* flags word */
261 #define OBD_MD_FLOBDFLG (0x00001000)
262 #define OBD_MD_FLNLINK  (0x00002000)    /* link count */
263 #define OBD_MD_FLGENER  (0x00004000)    /* generation number */
264 #define OBD_MD_FLINLINE (0x00008000)    /* inline data */
265 #define OBD_MD_FLRDEV   (0x00010000)    /* device number */
266 #define OBD_MD_FLEASIZE (0x00020000)    /* extended attribute data */
267 #define OBD_MD_LINKNAME (0x00040000)    /* symbolic link target */
268 #define OBD_MD_FLHANDLE (0x00080000)    /* file handle */
269 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS | OBD_MD_LINKNAME|\
270                            OBD_MD_FLEASIZE | OBD_MD_FLHANDLE))
271
272 struct obd_statfs {
273         __u64           os_type;
274         __u64           os_blocks;
275         __u64           os_bfree;
276         __u64           os_bavail;
277         __u64           os_files;
278         __u64           os_ffree;
279         __u8            os_fsid[40];
280         __u32           os_bsize;
281         __u32           os_namelen;
282         __u32           os_spare[12];
283 };
284
285 /* ost_body.data values for OST_BRW */
286
287 #define OBD_BRW_READ    0x1
288 #define OBD_BRW_WRITE   0x2
289 #define OBD_BRW_RWMASK  (OBD_BRW_READ | OBD_BRW_WRITE)
290 #define OBD_BRW_CREATE  0x4
291
292 #define OBD_OBJECT_EOF 0xffffffffffffffffULL
293
294 struct obd_ioobj {
295         obd_id               ioo_id;
296         obd_gr               ioo_gr;
297         __u32                ioo_type;
298         __u32                ioo_bufcnt;
299 };
300
301 struct niobuf_remote {
302         __u64 offset;
303         __u32 len;
304         __u32 xid;
305         __u32 flags;
306 };
307
308 #define CONNMGR_REPLY   0
309 #define CONNMGR_CONNECT 1
310
311 struct connmgr_body {
312         __u64 conn;
313         __u64 conn_token;
314         __u32 generation;
315         obd_uuid_t conn_uuid;
316 };
317
318 /* request structure for OST's */
319
320 #define OST_REQ_HAS_OA1  0x1
321
322 struct ost_body {
323         struct  obdo oa;
324 };
325
326 /*
327  *   MDS REQ RECORDS
328  */
329
330 /* opcodes */
331 #define MDS_GETATTR    1
332 #define MDS_OPEN       2
333 #define MDS_CLOSE      3
334 #define MDS_REINT      4
335 #define MDS_READPAGE   6
336 #define MDS_CONNECT    7
337 #define MDS_DISCONNECT 8
338 #define MDS_GETSTATUS  9
339 #define MDS_STATFS     10
340 #define MDS_GETLOVINFO 11
341 #define MDS_GETATTR_NAME 12
342
343 #define REINT_SETATTR  1
344 #define REINT_CREATE   2
345 #define REINT_LINK     3
346 #define REINT_UNLINK   4
347 #define REINT_RENAME   5
348 #define REINT_MAX      5
349
350 #define REINT_OPCODE_MASK 0xff /* opcodes must fit into this mask */
351 #define REINT_REPLAYING 0x1000 /* masked into the opcode to indicate replay */
352
353 struct ll_fid {
354         __u64 id;
355         __u32 generation;
356         __u32 f_type;
357 };
358
359
360 #define MDS_STATUS_CONN 1
361 #define MDS_STATUS_LOV 2
362
363 struct mds_status_req {
364         __u32  flags;
365         __u32  repbuf;
366 };
367
368 struct mds_fileh_body {
369         struct ll_fid f_fid;
370         struct lustre_handle f_handle;
371 };
372
373 struct mds_conn_status {
374         struct ll_fid rootfid;
375         __u64          xid;
376         __u64          last_committed;
377         __u64          last_rcvd;
378         /* XXX preallocated quota & obj fields here */
379 };
380
381 struct mds_body {
382         struct ll_fid  fid1;
383         struct ll_fid  fid2;
384         struct lustre_handle handle;
385         __u64          size;
386         __u32          ino;   /* make this a __u64 */
387         __u32          valid;
388         __u32          fsuid;
389         __u32          fsgid;
390         __u32          capability;
391         __u32          mode;
392         __u32          uid;
393         __u32          gid;
394         __u32          mtime;
395         __u32          ctime;
396         __u32          atime;
397         __u32          flags;
398         __u32          rdev;
399         __u32          nlink;
400         __u32          generation;
401 };
402
403 /* This is probably redundant with OBD_MD_FLEASIZE, but we need an audit */
404 #define MDS_OPEN_HAS_EA 1 /* this open has an EA, for a delayed create*/
405
406 /* MDS update records */
407
408
409 //struct mds_update_record_hdr {
410 //        __u32 ur_opcode;
411 //};
412
413 struct mds_rec_setattr {
414         __u32           sa_opcode;
415         __u32           sa_fsuid;
416         __u32           sa_fsgid;
417         __u32           sa_cap;
418         __u32           sa_reserved;
419         __u32           sa_valid;
420         struct ll_fid   sa_fid;
421         __u32           sa_mode;
422         __u32           sa_uid;
423         __u32           sa_gid;
424         __u32           sa_attr_flags;
425         __u64           sa_size;
426         __u64           sa_atime;
427         __u64           sa_mtime;
428         __u64           sa_ctime;
429 };
430
431 struct mds_rec_create {
432         __u32           cr_opcode;
433         __u32           cr_fsuid;
434         __u32           cr_fsgid;
435         __u32           cr_cap;
436         __u32           cr_reserved;
437         __u32           cr_mode;
438         struct ll_fid   cr_fid;
439         struct ll_fid   cr_replayfid;
440         __u32           cr_uid;
441         __u32           cr_gid;
442         __u64           cr_time;
443         __u64           cr_rdev;
444 };
445
446 struct mds_rec_link {
447         __u32           lk_opcode;
448         __u32           lk_fsuid;
449         __u32           lk_fsgid;
450         __u32           lk_cap;
451         struct ll_fid   lk_fid1;
452         struct ll_fid   lk_fid2;
453 };
454
455 struct mds_rec_unlink {
456         __u32           ul_opcode;
457         __u32           ul_fsuid;
458         __u32           ul_fsgid;
459         __u32           ul_cap;
460         __u32           ul_reserved;
461         __u32           ul_mode;
462         struct ll_fid   ul_fid1;
463         struct ll_fid   ul_fid2;
464 };
465
466 struct mds_rec_rename {
467         __u32           rn_opcode;
468         __u32           rn_fsuid;
469         __u32           rn_fsgid;
470         __u32           rn_cap;
471         struct ll_fid   rn_fid1;
472         struct ll_fid   rn_fid2;
473 };
474
475
476 /*
477  *  LOV data structures
478  */
479
480 #define LOV_RAID0   0
481 #define LOV_RAIDRR  1
482
483 struct lov_desc {
484         __u32 ld_tgt_count;                /* how many OBD's */
485         __u32 ld_active_tgt_count;         /* how many active */
486         __u32 ld_default_stripe_count;     /* how many objects are used */
487         __u64 ld_default_stripe_size;      /* in bytes */
488         __u64 ld_default_stripe_offset;    /* in bytes */
489         __u32 ld_pattern;                  /* RAID 0,1 etc */
490         obd_uuid_t ld_uuid;
491 };
492
493 /*
494  *   LDLM requests:
495  */
496 /* opcodes -- MUST be distinct from OST/MDS opcodes */
497 #define LDLM_ENQUEUE       101
498 #define LDLM_CONVERT       102
499 #define LDLM_CANCEL        103
500 #define LDLM_BL_CALLBACK   104
501 #define LDLM_CP_CALLBACK   105
502
503 #define RES_NAME_SIZE 3
504 #define RES_VERSION_SIZE 4
505
506 /* lock types */
507 typedef enum {
508         LCK_EX = 1,
509         LCK_PW,
510         LCK_PR,
511         LCK_CW,
512         LCK_CR,
513         LCK_NL
514 } ldlm_mode_t;
515
516 struct ldlm_extent {
517         __u64 start;
518         __u64 end;
519 };
520
521 struct ldlm_intent {
522         __u64 opc;
523 };
524
525 /* Note this unaligned structure; as long as it's only used in ldlm_request
526  * below, we're probably fine. */
527 struct ldlm_resource_desc {
528         __u32 lr_type;
529         __u64 lr_name[RES_NAME_SIZE];
530         __u32 lr_version[RES_VERSION_SIZE];
531 };
532
533 struct ldlm_lock_desc {
534         struct ldlm_resource_desc l_resource;
535         ldlm_mode_t l_req_mode;
536         ldlm_mode_t l_granted_mode;
537         struct ldlm_extent l_extent;
538         __u32 l_version[RES_VERSION_SIZE];
539 };
540
541 struct ldlm_request {
542         __u32 lock_flags;
543         struct ldlm_lock_desc lock_desc;
544         struct lustre_handle lock_handle1;
545         struct lustre_handle lock_handle2;
546 };
547
548 struct ldlm_reply {
549         __u32 lock_flags;
550         __u32 lock_mode;
551         __u64 lock_resource_name[RES_NAME_SIZE];
552         struct lustre_handle lock_handle;
553         struct ldlm_extent lock_extent;   /* XXX make this policy 1 &2 */
554         __u64  lock_policy_res1;
555         __u64  lock_policy_res2;
556 };
557
558 /*
559  * ptlbd, portal block device requests
560  */
561 typedef enum {
562         PTLBD_QUERY = 200,
563         PTLBD_READ = 201,
564         PTLBD_WRITE = 202,
565 } ptlbd_cmd_t;
566
567 struct ptlbd_op {
568         __u16 op_cmd;
569         __u16 op_lun;
570         __u16 op_niob_cnt;
571         __u16 op__padding;
572         __u32 op_block_cnt;
573 };
574
575 struct ptlbd_niob {
576         __u64 n_xid;
577         __u64 n_block_nr;
578         __u32 n_offset;
579         __u32 n_length;
580 };
581
582 struct ptlbd_rsp {
583         __u16 r_status;
584         __u16 r_error_cnt;
585 };
586 #endif