Whamcloud - gitweb
- small issues
[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 <linux/list.h>
35 # undef __KERNEL__
36 # include <stdint.h>
37 #endif
38 /*
39  * this file contains all data structures used in Lustre interfaces:
40  * - obdo and obd_request records
41  * - mds_request records
42  * - ldlm data
43  * - ioctl's
44  */
45
46 #define PTL_RPC_MSG_REQUEST 4711
47 #define PTL_RPC_MSG_ERR 4712
48
49 #define PTLRPC_MSG_MAGIC (cpu_to_le32(0x0BD00BD0))
50 #define PTLRPC_MSG_VERSION (cpu_to_le32(0x00040001))
51
52 struct lustre_handle {
53         __u64 addr;
54         __u64 cookie;
55 };
56
57 struct lustre_msg {
58         __u64 addr;
59         __u64 cookie; /* security token */
60         __u32 magic;
61         __u32 version;
62         __u64 last_rcvd;
63         __u64 last_committed;
64         __u64 transno;
65         __u32 opc;
66         __u32 status;
67         __u32 type;
68         __u32   bufcount;
69         __u32   buflens[0];
70 };
71
72 #define N_LOCAL_TEMP_PAGE 0x00000001
73
74 /*
75  *   OST requests: OBDO & OBD request records
76  */
77
78 /* opcodes */
79 #define OST_GETATTR    1
80 #define OST_SETATTR    2
81 #define OST_BRW        3
82 #define OST_CREATE     4
83 #define OST_DESTROY    5
84 #define OST_GET_INFO   6
85 #define OST_CONNECT    7
86 #define OST_DISCONNECT 8
87 #define OST_PUNCH      9
88 #define OST_OPEN      10
89 #define OST_CLOSE     11
90 #define OST_STATFS    12
91
92
93 typedef uint64_t        obd_id;
94 typedef uint64_t        obd_gr;
95 typedef uint64_t        obd_time;
96 typedef uint64_t        obd_size;
97 typedef uint64_t        obd_off;
98 typedef uint64_t        obd_blocks;
99 typedef uint32_t        obd_blksize;
100 typedef uint32_t        obd_mode;
101 typedef uint32_t        obd_uid;
102 typedef uint32_t        obd_gid;
103 typedef uint32_t        obd_rdev;
104 typedef uint32_t        obd_flag;
105 typedef uint32_t        obd_count;
106
107 #define OBD_FL_INLINEDATA       (0x00000001)
108 #define OBD_FL_OBDMDEXISTS      (0x00000002)
109 #define OBD_FL_CREATEONOPEN     (0x00000004)
110
111 #define OBD_INLINESZ    60
112 #define OBD_OBDMDSZ     60
113 /* Note: 64-bit types are 64-bit aligned in structure */
114 struct obdo {
115         obd_id                  o_id;
116         obd_gr                  o_gr;
117         obd_time                o_atime;
118         obd_time                o_mtime;
119         obd_time                o_ctime;
120         obd_size                o_size;
121         obd_blocks              o_blocks;
122         obd_blksize             o_blksize;
123         obd_mode                o_mode;
124         obd_uid                 o_uid;
125         obd_gid                 o_gid;
126         obd_flag                o_flags;
127         obd_count               o_nlink;
128         obd_count               o_generation;
129         obd_rdev                o_rdev;
130         obd_flag                o_valid;        /* hot fields in this obdo */
131         obd_flag                o_obdflags;
132         char                    o_inline[OBD_INLINESZ];
133 };
134
135 #define OBD_MD_FLALL    (0xffffffff)
136 #define OBD_MD_FLID     (0x00000001)
137 #define OBD_MD_FLATIME  (0x00000002)
138 #define OBD_MD_FLMTIME  (0x00000004)
139 #define OBD_MD_FLCTIME  (0x00000008)
140 #define OBD_MD_FLSIZE   (0x00000010)
141 #define OBD_MD_FLBLOCKS (0x00000020)
142 #define OBD_MD_FLBLKSZ  (0x00000040)
143 #define OBD_MD_FLMODE   (0x00000080)
144 #define OBD_MD_FLTYPE   (0x00000100)
145 #define OBD_MD_FLUID    (0x00000200)
146 #define OBD_MD_FLGID    (0x00000400)
147 #define OBD_MD_FLFLAGS  (0x00000800)
148 #define OBD_MD_FLOBDFLG (0x00001000)
149 #define OBD_MD_FLNLINK  (0x00002000)
150 #define OBD_MD_FLGENER  (0x00004000)
151 #define OBD_MD_FLINLINE (0x00008000)
152 #define OBD_MD_FLOBDMD  (0x00010000)
153 #define OBD_MD_FLOBJID  (0x00020000)
154 #define OBD_MD_LINKNAME (0x00040000)
155 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS |\
156                            OBD_MD_LINKNAME))
157
158 struct obd_statfs {
159         __u64           os_type;
160         __u64           os_blocks;
161         __u64           os_bfree;
162         __u64           os_bavail;
163         __u64           os_files;
164         __u64           os_ffree;
165         __u64           os_fsid;
166         __u32           os_bsize;
167         __u32           os_namelen;
168         __u32           os_spare[12];
169 };
170
171 struct obd_ioobj {
172         obd_id    ioo_id;
173         obd_gr    ioo_gr;
174         __u32     ioo_type;
175         __u32     ioo_bufcnt;
176 };
177
178 struct niobuf_remote {
179         __u64 offset;
180         __u32 len;
181         __u32 xid;
182         __u32 flags;
183 };
184
185 struct niobuf_local {
186         __u64 offset;
187         __u32 len;
188         __u32 xid;
189         __u32 flags;
190         void *addr;
191         struct page *page;
192         void *target_private;
193         struct dentry *dentry;
194 };
195
196 /* request structure for OST's */
197
198 #define OST_REQ_HAS_OA1  0x1
199
200 struct ost_body {
201         __u32   connid;
202         __u32   data;
203         struct  obdo oa;
204 };
205
206 /*
207  *   MDS REQ RECORDS
208  */
209
210 /* opcodes */
211 #define MDS_GETATTR    1
212 #define MDS_OPEN       2
213 #define MDS_CLOSE      3
214 #define MDS_REINT      4
215 #define MDS_READPAGE   6
216 #define MDS_CONNECT    7
217 #define MDS_DISCONNECT 8
218 #define MDS_GETSTATUS  9
219 #define MDS_STATFS     10
220
221 #define REINT_SETATTR  1
222 #define REINT_CREATE   2
223 #define REINT_LINK     3
224 #define REINT_UNLINK   4
225 #define REINT_RENAME   5
226 #define REINT_RECREATE 6
227 #define REINT_MAX      6
228
229 struct ll_fid {
230         __u64 id;
231         __u32 generation;
232         __u32 f_type;
233 };
234
235 struct mds_body {
236         struct ll_fid  fid1;
237         struct ll_fid  fid2;
238         __u64          size;
239         __u64          extra;
240         __u32          valid;
241         __u32          mode;
242         __u32          uid;
243         __u32          gid;
244         __u32          mtime;
245         __u32          ctime;
246         __u32          atime;
247         __u32          flags;
248         __u32          major;
249         __u32          minor;
250         __u32          ino;
251         __u32          nlink;
252         __u32          generation;
253         __u32          last_xid;
254 };
255
256 /* MDS update records */
257 struct mds_update_record_hdr {
258         __u32 ur_opcode;
259 };
260
261 struct mds_rec_setattr {
262         __u32           sa_opcode;
263         struct ll_fid   sa_fid;
264         __u32           sa_valid;
265         __u32           sa_mode;
266         __u32           sa_uid;
267         __u32           sa_gid;
268         __u64           sa_size;
269         __u64           sa_atime;
270         __u64           sa_mtime;
271         __u64           sa_ctime;
272         __u32           sa_attr_flags;
273 };
274
275 struct mds_rec_create {
276         __u32           cr_opcode;
277         struct ll_fid   cr_fid;
278         __u32           cr_uid;
279         __u32           cr_gid;
280         __u64           cr_time;
281         __u32           cr_mode;
282         __u64           cr_rdev;
283 };
284
285 struct mds_rec_link {
286         __u32           lk_opcode;
287         struct ll_fid   lk_fid1;
288         struct ll_fid   lk_fid2;
289 };
290
291 struct mds_rec_unlink {
292         __u32           ul_opcode;
293         struct ll_fid   ul_fid1;
294         struct ll_fid   ul_fid2;
295 };
296
297 struct mds_rec_rename {
298         __u32           rn_opcode;
299         struct ll_fid   rn_fid1;
300         struct ll_fid   rn_fid2;
301 };
302
303
304 /*
305  *   LDLM requests:
306  */
307
308 /* opcodes */
309 #define LDLM_ENQUEUE       1
310 #define LDLM_CONVERT       2
311 #define LDLM_CANCEL        3
312 #define LDLM_CALLBACK      4
313
314 #define RES_NAME_SIZE 3
315 #define RES_VERSION_SIZE 4
316
317 /* lock types */
318 typedef enum {
319         LCK_EX = 1,
320         LCK_PW,
321         LCK_PR,
322         LCK_CW,
323         LCK_CR,
324         LCK_NL
325 } ldlm_mode_t;
326
327 struct ldlm_extent {
328         __u64 start;
329         __u64 end;
330 };
331
332 struct ldlm_intent {
333         __u64 opc;
334 };
335
336 struct ldlm_resource_desc {
337         __u32 lr_type;
338         __u64 lr_name[RES_NAME_SIZE];
339         __u64 lr_version[RES_VERSION_SIZE];
340 };
341
342 struct ldlm_lock_desc {
343         struct ldlm_resource_desc l_resource;
344         ldlm_mode_t l_req_mode;
345         ldlm_mode_t l_granted_mode;
346         struct ldlm_extent l_extent;
347         __u32 l_version[RES_VERSION_SIZE];
348 };
349
350 struct ldlm_request {
351         __u32 lock_flags;
352         struct ldlm_lock_desc lock_desc;
353         struct lustre_handle lock_handle1;
354         struct lustre_handle lock_handle2;
355 };
356
357 struct ldlm_reply {
358         __u32 lock_flags;
359         __u64 lock_resource_name[3];
360         struct lustre_handle lock_handle;
361         struct ldlm_extent lock_extent;   /* XXX make this policy 1 &2 */
362         __u64  lock_policy_res1;
363         __u64  lock_policy_res2;
364 };
365
366 /*
367  *   OBD IOCTLS
368  */
369 #define OBD_IOCTL_VERSION 0x00010001
370
371 struct obd_ioctl_data {
372         uint32_t ioc_len;
373         uint32_t ioc_version;
374
375         uint64_t ioc_addr;
376         uint64_t ioc_cookie;
377         uint32_t ioc_conn1;
378         uint32_t ioc_conn2;
379
380         struct obdo ioc_obdo1;
381         struct obdo ioc_obdo2;
382
383         obd_size         ioc_count;
384         obd_off          ioc_offset;
385         uint32_t         ioc_dev;
386         uint32_t         ____padding;
387
388         /* buffers the kernel will treat as user pointers */
389         uint32_t ioc_plen1;
390         char    *ioc_pbuf1;
391         uint32_t ioc_plen2;
392         char    *ioc_pbuf2;
393
394         /* two inline buffers */
395         uint32_t ioc_inllen1;
396         char    *ioc_inlbuf1;
397         uint32_t ioc_inllen2;
398         char    *ioc_inlbuf2;
399         uint32_t ioc_inllen3;
400         char    *ioc_inlbuf3;
401
402         char    ioc_bulk[0];
403 };
404
405 struct obd_ioctl_hdr {
406         uint32_t ioc_len;
407         uint32_t ioc_version;
408 };
409
410 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
411 {
412         int len = size_round(sizeof(struct obd_ioctl_data));
413         len += size_round(data->ioc_inllen1);
414         len += size_round(data->ioc_inllen2);
415         len += size_round(data->ioc_inllen3);
416         return len;
417 }
418
419 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
420 {
421         if (data->ioc_len > (1<<30)) {
422                 printk("OBD ioctl: ioc_len larger than 1<<30\n");
423                 return 1;
424         }
425         if (data->ioc_inllen1 > (1<<30)) {
426                 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
427                 return 1;
428         }
429         if (data->ioc_inllen2 > (1<<30)) {
430                 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
431                 return 1;
432         }
433
434         if (data->ioc_inllen3 > (1<<30)) {
435                 printk("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
436                 return 1;
437         }
438         if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
439                 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
440                 return 1;
441         }
442         if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
443                 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
444                 return 1;
445         }
446         if (data->ioc_inlbuf3 && !data->ioc_inllen3) {
447                 printk("OBD ioctl: inlbuf3 pointer but 0 length\n");
448                 return 1;
449         }
450         if (data->ioc_pbuf1 && !data->ioc_plen1) {
451                 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
452                 return 1;
453         }
454         if (data->ioc_pbuf2 && !data->ioc_plen2) {
455                 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
456                 return 1;
457         }
458         /*
459         if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
460                 printk("OBD ioctl: inllen1 set but NULL pointer\n");
461                 return 1;
462         }
463         if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
464                 printk("OBD ioctl: inllen2 set but NULL pointer\n");
465                 return 1;
466         }
467         if (data->ioc_inllen3 && !data->ioc_inlbuf3) {
468                 printk("OBD ioctl: inllen3 set but NULL pointer\n");
469                 return 1;
470         }
471         */
472         if (data->ioc_plen1 && !data->ioc_pbuf1) {
473                 printk("OBD ioctl: plen1 set but NULL pointer\n");
474                 return 1;
475         }
476         if (data->ioc_plen2 && !data->ioc_pbuf2) {
477                 printk("OBD ioctl: plen2 set but NULL pointer\n");
478                 return 1;
479         }
480         if (obd_ioctl_packlen(data) != data->ioc_len ) {
481                 printk("OBD ioctl: packlen exceeds ioc_len\n");
482                 return 1;
483         }
484         if (data->ioc_inllen1 &&
485             data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
486                 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
487                 return 1;
488         }
489         if (data->ioc_inllen2 &&
490             data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
491                 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
492                 return 1;
493         }
494         if (data->ioc_inllen3 &&
495             data->ioc_bulk[size_round(data->ioc_inllen1) + size_round(data->ioc_inllen2) 
496                            + data->ioc_inllen3 - 1] != '\0') {
497                 printk("OBD ioctl: inlbuf3 not 0 terminated\n");
498                 return 1;
499         }
500         return 0;
501 }
502
503 #ifndef __KERNEL__
504 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
505                                  int max)
506 {
507         char *ptr;
508         struct obd_ioctl_data *overlay;
509         data->ioc_len = obd_ioctl_packlen(data);
510         data->ioc_version = OBD_IOCTL_VERSION;
511
512         if (*pbuf && obd_ioctl_packlen(data) > max)
513                 return 1;
514         if (*pbuf == NULL) {
515                 *pbuf = malloc(data->ioc_len);
516         }
517         if (!*pbuf)
518                 return 1;
519         overlay = (struct obd_ioctl_data *)*pbuf;
520         memcpy(*pbuf, data, sizeof(*data));
521
522         ptr = overlay->ioc_bulk;
523         if (data->ioc_inlbuf1)
524                 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
525         if (data->ioc_inlbuf2)
526                 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
527         if (data->ioc_inlbuf3)
528                 LOGL(data->ioc_inlbuf3, data->ioc_inllen3, ptr);
529         if (obd_ioctl_is_invalid(overlay))
530                 return 1;
531
532         return 0;
533 }
534 #else
535
536
537 /* buffer MUST be at least the size of obd_ioctl_hdr */
538 static inline int obd_ioctl_getdata(char *buf, int *len, void *arg)
539 {
540         struct obd_ioctl_hdr *hdr;
541         struct obd_ioctl_data *data;
542         int err;
543         ENTRY;
544
545         hdr = (struct obd_ioctl_hdr *)buf;
546         data = (struct obd_ioctl_data *)buf;
547
548         err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
549         if ( err ) {
550                 EXIT;
551                 return err;
552         }
553
554         if (hdr->ioc_version != OBD_IOCTL_VERSION) {
555                 printk("OBD: version mismatch kernel vs application\n");
556                 return -EINVAL;
557         }
558
559         if (hdr->ioc_len > *len) {
560                 printk("OBD: user buffer exceeds kernel buffer\n");
561                 return -EINVAL;
562         }
563
564
565         if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
566                 printk("OBD: user buffer too small for ioctl\n");
567                 return -EINVAL;
568         }
569
570         err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
571         if ( err ) {
572                 EXIT;
573                 return err;
574         }
575
576         if (obd_ioctl_is_invalid(data)) {
577                 printk("OBD: ioctl not correctly formatted\n");
578                 return -EINVAL;
579         }
580
581         if (data->ioc_inllen1) {
582                 data->ioc_inlbuf1 = &data->ioc_bulk[0];
583         }
584
585         if (data->ioc_inllen2) {
586                 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
587         }
588
589         if (data->ioc_inllen3) {
590                 data->ioc_inlbuf3 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1) + 
591                         size_round(data->ioc_inllen2);
592         }
593
594         EXIT;
595         return 0;
596 }
597 #endif
598
599
600 #define OBD_IOC_CREATE                 _IOR ('f', 101, long)
601 #define OBD_IOC_SETUP                  _IOW ('f', 102, long)
602 #define OBD_IOC_CLEANUP                _IO  ('f', 103      )
603 #define OBD_IOC_DESTROY                _IOW ('f', 104, long)
604 #define OBD_IOC_PREALLOCATE            _IOWR('f', 105, long)
605 #define OBD_IOC_DEC_USE_COUNT          _IO  ('f', 106      )
606 #define OBD_IOC_SETATTR                _IOW ('f', 107, long)
607 #define OBD_IOC_GETATTR                _IOR ('f', 108, long)
608 #define OBD_IOC_READ                   _IOWR('f', 109, long)
609 #define OBD_IOC_WRITE                  _IOWR('f', 110, long)
610 #define OBD_IOC_CONNECT                _IOR ('f', 111, long)
611 #define OBD_IOC_DISCONNECT             _IOW ('f', 112, long)
612 #define OBD_IOC_STATFS                 _IOWR('f', 113, long)
613 #define OBD_IOC_SYNC                   _IOR ('f', 114, long)
614 #define OBD_IOC_READ2                  _IOWR('f', 115, long)
615 #define OBD_IOC_FORMAT                 _IOWR('f', 116, long)
616 #define OBD_IOC_PARTITION              _IOWR('f', 117, long)
617 #define OBD_IOC_ATTACH                 _IOWR('f', 118, long)
618 #define OBD_IOC_DETACH                 _IOWR('f', 119, long)
619 #define OBD_IOC_COPY                   _IOWR('f', 120, long)
620 #define OBD_IOC_MIGR                   _IOWR('f', 121, long)
621 #define OBD_IOC_PUNCH                  _IOWR('f', 122, long)
622 #define OBD_IOC_DEVICE                 _IOWR('f', 123, long)
623 #define OBD_IOC_MODULE_DEBUG           _IOWR('f', 124, long)
624 #define OBD_IOC_BRW_READ               _IOWR('f', 125, long)
625 #define OBD_IOC_BRW_WRITE              _IOWR('f', 126, long)
626 #define OBD_IOC_NAME2DEV               _IOWR('f', 127, long)
627 #define OBD_IOC_NEWDEV                 _IOWR('f', 128, long)
628 #define OBD_IOC_LIST                   _IOWR('f', 129, long)
629 #define OBD_IOC_UUID2DEV               _IOWR('f', 130, long)
630
631 #define OBD_IOC_RECOVD_NEWCONN         _IOWR('f', 131, long)
632
633 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 132      )
634
635 #endif