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