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