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