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