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