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