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