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