Whamcloud - gitweb
Removes all traces of mds_req, mds_rep, ost_req, and ost_rep. All subsystems
[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 #define MDS_GETATTR   1
159 #define MDS_OPEN      2
160 #define MDS_CLOSE     3
161 #define MDS_REINT     4
162 #define MDS_READPAGE  5
163
164 #define REINT_SETATTR 1
165 #define REINT_CREATE  2
166 #define REINT_LINK    3
167 #define REINT_UNLINK  4
168 #define REINT_RENAME  5
169 #define REINT_MAX     5
170
171 struct ll_fid {
172         __u64 id;
173         __u32 generation;
174         __u32 f_type;
175 };
176
177 struct niobuf {
178         __u64 addr;
179         __u64 offset;
180         __u32 len;
181         __u32 flags;
182         __u32 xid;
183         void *page;
184 };
185
186 struct mds_body {
187         struct ll_fid  fid1;
188         struct ll_fid  fid2;
189         __u64          objid;
190         __u64          size;
191         __u32          valid;
192         __u32          mode;
193         __u32          uid;
194         __u32          gid;
195         __u32          mtime;
196         __u32          ctime;
197         __u32          atime;
198         __u32          flags;
199         __u32          major;
200         __u32          minor;
201         __u32          ino;
202         __u32          nlink;
203         __u32          generation;
204 };
205
206 /* MDS update records */
207 struct mds_update_record_hdr {
208         __u32 ur_opcode;
209 };
210
211 struct mds_rec_setattr {
212         __u32           sa_opcode;
213         struct ll_fid   sa_fid;
214         __u32           sa_valid;
215         __u32           sa_mode;
216         __u32           sa_uid;
217         __u32           sa_gid;
218         __u64           sa_size;
219         __u64           sa_atime;
220         __u64           sa_mtime;
221         __u64           sa_ctime;
222         __u32           sa_attr_flags;
223 };
224
225 struct mds_rec_create {
226         __u32           cr_opcode;
227         struct ll_fid   cr_fid;
228         __u32           cr_uid;
229         __u32           cr_gid;
230         __u64           cr_time;
231         __u32           cr_mode;
232         /* overloaded: id for create, tgtlen for symlink, rdev for mknod */
233         __u64           cr_id;
234 };
235
236 struct mds_rec_link {
237         __u32           lk_opcode;
238         struct ll_fid   lk_fid1;
239         struct ll_fid   lk_fid2;
240 };
241
242 struct mds_rec_unlink {
243         __u32           ul_opcode;
244         struct ll_fid   ul_fid1;
245         struct ll_fid   ul_fid2;
246 };
247
248 struct mds_rec_rename {
249         __u32           rn_opcode;
250         struct ll_fid   rn_fid1;
251         struct ll_fid   rn_fid2;
252 };
253
254 #ifdef __KERNEL__
255
256 static inline void ll_ino2fid(struct ll_fid *fid, ino_t ino, __u32 generation,
257                               int type)
258 {
259         fid->id = HTON__u64((__u64)ino);
260         fid->generation = HTON__u32(generation);
261         fid->f_type = HTON__u32(type);
262 }
263
264 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
265 {
266         ll_ino2fid(fid, inode->i_ino, inode->i_generation,
267                    inode->i_mode & S_IFMT);
268 }
269
270 #endif
271
272 /*
273  *   LDLM requests:
274  */
275
276 /* opcodes */
277 #define LDLM_ENQUEUE   1
278 #define LDLM_CONVERT   2
279 #define LDLM_CANCEL    3
280 #define LDLM_CALLBACK  4
281
282 #define RES_NAME_SIZE 3
283 #define RES_VERSION_SIZE 4
284
285 /* lock types */
286 typedef enum {
287         LCK_EX = 1,
288         LCK_PW,
289         LCK_PR,
290         LCK_CW,
291         LCK_CR,
292         LCK_NL
293 } ldlm_mode_t;
294
295 struct ldlm_handle {
296         __u64 addr;
297         __u64 cookie;
298 };
299
300 struct ldlm_extent {
301         __u64 start;
302         __u64 end;
303 };
304
305 struct ldlm_request {
306         __u32 ns_id;
307         __u64 res_id[RES_NAME_SIZE];
308         __u32 res_type;
309         __u32 flags;
310         struct ldlm_extent lock_extent;
311         struct ldlm_handle parent_res_handle;
312         struct ldlm_handle parent_lock_handle;
313         ldlm_mode_t mode;
314 };
315
316 struct ldlm_reply {
317         struct ldlm_handle lock_handle;
318 };
319
320 /*
321  *   OBD IOCTLS
322  */
323
324
325 #define OBD_IOCTL_VERSION 0x00010001
326
327 struct obd_ioctl_data {
328         uint32_t ioc_len;
329         uint32_t ioc_version;
330         uint32_t ioc_conn1;
331         uint32_t ioc_conn2;
332         struct obdo ioc_obdo1;
333         struct obdo ioc_obdo2;
334         obd_size         ioc_count;
335         obd_off          ioc_offset;
336         uint32_t         ioc_dev;
337
338         /* buffers the kernel will treat as user pointers */
339         uint32_t ioc_plen1;
340         char    *ioc_pbuf1;
341         uint32_t ioc_plen2;
342         char    *ioc_pbuf2;
343
344         /* two inline buffers */
345         uint32_t ioc_inllen1;
346         char    *ioc_inlbuf1;
347         uint32_t ioc_inllen2;
348         char    *ioc_inlbuf2;
349
350         char    ioc_bulk[0];
351 };
352
353 struct obd_ioctl_hdr {
354         uint32_t ioc_len;
355         uint32_t ioc_version;
356 };
357
358 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
359 {
360         int len = sizeof(struct obd_ioctl_data);
361         len += size_round(data->ioc_inllen1);
362         len += size_round(data->ioc_inllen2);
363         return len;
364 }
365
366 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
367 {
368         if (data->ioc_len > (1<<30)) {
369                 printk("OBD ioctl: ioc_len larger than 1<<30\n");
370                 return 1;
371         }
372         if (data->ioc_inllen1 > (1<<30)) {
373                 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
374                 return 1;
375         }
376         if (data->ioc_inllen2 > (1<<30)) {
377                 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
378                 return 1;
379         }
380         if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
381                 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
382                 return 1;
383         }
384         if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
385                 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
386                 return 1;
387         }
388         if (data->ioc_pbuf1 && !data->ioc_plen1) {
389                 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
390                 return 1;
391         }
392         if (data->ioc_pbuf2 && !data->ioc_plen2) {
393                 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
394                 return 1;
395         }
396         /*
397         if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
398                 printk("OBD ioctl: inllen1 set but NULL pointer\n");
399                 return 1;
400         }
401         if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
402                 printk("OBD ioctl: inllen2 set but NULL pointer\n");
403                 return 1;
404         }
405         if (data->ioc_plen1 && !data->ioc_pbuf1) {
406                 printk("OBD ioctl: plen1 set but NULL pointer\n");
407                 return 1;
408         }
409         if (data->ioc_plen2 && !data->ioc_pbuf2) {
410                 printk("OBD ioctl: plen2 set but NULL pointer\n");
411                 return 1;
412         }
413         */
414         if (obd_ioctl_packlen(data) != data->ioc_len ) {
415                 printk("OBD ioctl: packlen exceeds ioc_len\n");
416                 return 1;
417         }
418         if (data->ioc_inllen1 &&
419             data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
420                 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
421                 return 1;
422         }
423         if (data->ioc_inllen2 &&
424             data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
425                 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
426                 return 1;
427         }
428         return 0;
429 }
430
431 #ifndef __KERNEL__
432 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
433                                  int max)
434 {
435         char *ptr;
436         struct obd_ioctl_data *overlay;
437         data->ioc_len = obd_ioctl_packlen(data);
438         data->ioc_version = OBD_IOCTL_VERSION;
439
440         if (*pbuf && obd_ioctl_packlen(data) > max)
441                 return 1;
442         if (*pbuf == NULL) {
443                 *pbuf = malloc(data->ioc_len);
444         }
445         if (!*pbuf)
446                 return 1;
447         overlay = (struct obd_ioctl_data *)*pbuf;
448         memcpy(*pbuf, data, sizeof(*data));
449
450         ptr = overlay->ioc_bulk;
451         if (data->ioc_inlbuf1)
452                 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
453         if (data->ioc_inlbuf2)
454                 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
455         if (obd_ioctl_is_invalid(overlay))
456                 return 1;
457
458         return 0;
459 }
460 #else
461
462
463 /* buffer MUST be at least the size of obd_ioctl_hdr */
464 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
465 {
466         struct obd_ioctl_hdr *hdr;
467         struct obd_ioctl_data *data;
468         int err;
469         ENTRY;
470
471         hdr = (struct obd_ioctl_hdr *)buf;
472         data = (struct obd_ioctl_data *)buf;
473
474         err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
475         if ( err ) {
476                 EXIT;
477                 return err;
478         }
479
480         if (hdr->ioc_version != OBD_IOCTL_VERSION) {
481                 printk("OBD: version mismatch kernel vs application\n");
482                 return -EINVAL;
483         }
484
485         if (hdr->ioc_len + buf >= end) {
486                 printk("OBD: user buffer exceeds kernel buffer\n");
487                 return -EINVAL;
488         }
489
490
491         if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
492                 printk("OBD: user buffer too small for ioctl\n");
493                 return -EINVAL;
494         }
495
496         err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
497         if ( err ) {
498                 EXIT;
499                 return err;
500         }
501
502         if (obd_ioctl_is_invalid(data)) {
503                 printk("OBD: ioctl not correctly formatted\n");
504                 return -EINVAL;
505         }
506
507         if (data->ioc_inllen1) {
508                 data->ioc_inlbuf1 = &data->ioc_bulk[0];
509         }
510
511         if (data->ioc_inllen2) {
512                 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
513         }
514
515         EXIT;
516         return 0;
517 }
518 #endif
519
520
521 #define OBD_IOC_CREATE                 _IOR ('f',  3, long)
522 #define OBD_IOC_SETUP                  _IOW ('f',  4, long)
523 #define OBD_IOC_CLEANUP                _IO  ('f',  5      )
524 #define OBD_IOC_DESTROY                _IOW ('f',  6, long)
525 #define OBD_IOC_PREALLOCATE            _IOWR('f',  7, long)
526 #define OBD_IOC_DEC_USE_COUNT          _IO  ('f',  8      )
527 #define OBD_IOC_SETATTR                _IOW ('f',  9, long)
528 #define OBD_IOC_GETATTR                _IOR ('f', 10, long)
529 #define OBD_IOC_READ                   _IOWR('f', 11, long)
530 #define OBD_IOC_WRITE                  _IOWR('f', 12, long)
531 #define OBD_IOC_CONNECT                _IOR ('f', 13, long)
532 #define OBD_IOC_DISCONNECT             _IOW ('f', 14, long)
533 #define OBD_IOC_STATFS                 _IOWR('f', 15, long)
534 #define OBD_IOC_SYNC                   _IOR ('f', 16, long)
535 #define OBD_IOC_READ2                  _IOWR('f', 17, long)
536 #define OBD_IOC_FORMAT                 _IOWR('f', 18, long)
537 #define OBD_IOC_PARTITION              _IOWR('f', 19, long)
538 #define OBD_IOC_ATTACH                 _IOWR('f', 20, long)
539 #define OBD_IOC_DETACH                 _IOWR('f', 21, long)
540 #define OBD_IOC_COPY                   _IOWR('f', 22, long)
541 #define OBD_IOC_MIGR                   _IOWR('f', 23, long)
542 #define OBD_IOC_PUNCH                  _IOWR('f', 24, long)
543 #define OBD_IOC_DEVICE                 _IOWR('f', 25, long)
544 #define OBD_IOC_MODULE_DEBUG           _IOWR('f', 26, long)
545 #define OBD_IOC_BRW_READ               _IOWR('f', 27, long)
546 #define OBD_IOC_BRW_WRITE              _IOWR('f', 28, long)
547
548 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 32      )
549
550 #endif