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