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