Whamcloud - gitweb
201939b56f8fd8f93063f87a4d56b0ee383ee61f
[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.
5  */
6
7 #ifndef __LUSTRE_IDL_H__
8 #define __LUSTRE_IDL_H__
9 #ifdef __KERNEL__
10 #include <linux/ioctl.h>
11 #include <asm/types.h>
12
13 #include <linux/types.h>
14 #else 
15 #define __KERNEL__
16 #include <linux/list.h>
17 #undef __KERNEL__
18 #include <stdint.h>
19 #endif
20 /* 
21  * this file contains all data structures used in Lustre interfaces:
22  * - obdo and obd_request records
23  * - mds_request records
24  * - ioctl's
25  */ 
26
27 /* 
28  *   OBDO & OBD request records
29  */
30
31 typedef uint64_t        obd_id;
32 typedef uint64_t        obd_gr;
33 typedef uint64_t        obd_time;
34 typedef uint64_t        obd_size;
35 typedef uint64_t        obd_off;
36 typedef uint64_t        obd_blocks;
37 typedef uint32_t        obd_blksize;
38 typedef uint32_t        obd_mode;
39 typedef uint32_t        obd_uid;
40 typedef uint32_t        obd_gid;
41 typedef uint32_t        obd_rdev;
42 typedef uint32_t        obd_flag;
43 typedef uint32_t        obd_count;
44
45 #define OBD_FL_INLINEDATA       (0x00000001UL)  
46 #define OBD_FL_OBDMDEXISTS      (0x00000002UL)
47
48 #define OBD_INLINESZ    60
49 #define OBD_OBDMDSZ     60
50 /* Note: 64-bit types are 64-bit aligned in structure */
51 struct obdo {
52         obd_id                  o_id;
53         obd_gr                  o_gr;
54         obd_time                o_atime;
55         obd_time                o_mtime;
56         obd_time                o_ctime;
57         obd_size                o_size;
58         obd_blocks              o_blocks;
59         obd_blksize             o_blksize;
60         obd_mode                o_mode;
61         obd_uid                 o_uid;
62         obd_gid                 o_gid;
63         obd_flag                o_flags;
64         obd_flag                o_obdflags;
65         obd_count               o_nlink;
66         obd_count               o_generation;
67         obd_flag                o_valid;        /* hot fields in this obdo */
68         char                    o_inline[OBD_INLINESZ];
69         char                    o_obdmd[OBD_OBDMDSZ];
70         struct list_head        o_list;
71         struct obd_ops          *o_op;
72 };
73
74 #define OBD_MD_FLALL    (~0UL)
75 #define OBD_MD_FLID     (0x00000001UL)
76 #define OBD_MD_FLATIME  (0x00000002UL)
77 #define OBD_MD_FLMTIME  (0x00000004UL)
78 #define OBD_MD_FLCTIME  (0x00000008UL)
79 #define OBD_MD_FLSIZE   (0x00000010UL)
80 #define OBD_MD_FLBLOCKS (0x00000020UL)
81 #define OBD_MD_FLBLKSZ  (0x00000040UL)
82 #define OBD_MD_FLMODE   (0x00000080UL)
83 #define OBD_MD_FLTYPE   (0x00000100UL)
84 #define OBD_MD_FLUID    (0x00000200UL)
85 #define OBD_MD_FLGID    (0x00000400UL)
86 #define OBD_MD_FLFLAGS  (0x00000800UL)
87 #define OBD_MD_FLOBDFLG (0x00001000UL)
88 #define OBD_MD_FLNLINK  (0x00002000UL)
89 #define OBD_MD_FLGENER  (0x00004000UL)
90 #define OBD_MD_FLINLINE (0x00008000UL)
91 #define OBD_MD_FLOBDMD  (0x00010000UL)
92 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS))
93
94
95 /* 
96  *   MDS REQ RECORDS
97  */
98
99
100 #define MDS_TYPE_REQ 1
101 #define MDS_TYPE_REP 2
102 #define MDS_TYPE_ERR 3
103
104 struct mds_req_hdr { 
105         __u32 opc;
106         __u64 seqno;
107         __u32 status;
108         __u32 type;
109 };
110
111 struct lustre_fid { 
112         __u64 id;
113         __u32 generation;
114         __u32 f_type;
115 };
116
117 struct mds_req {
118         struct lustre_fid        fid1;
119         struct lustre_fid        fid2;
120         char                       *name;
121         int                        namelen;
122         char                      *tgt;
123         int                        tgtlen;
124         __u32                       valid;
125         __u32                       mode;
126         __u32                       uid;
127         __u32                       gid;
128         __u64                       size;
129         __u32                       mtime;
130         __u32                       ctime;
131         __u32                       atime;
132         __u32                       flags;
133         __u32                       major;
134         __u32                       minor;
135         __u32                       ino;
136         __u32                       generation;
137 };
138
139 struct mds_rep_hdr { 
140         __u32 opc;
141         __u64 seqno;
142         __u32 status;
143         __u32 type;
144 };
145
146 struct mds_rep {
147         struct lustre_fid        fid1;
148         struct lustre_fid        fid2;
149         char                       *name;
150         int                        namelen;
151         char                      *tgt;
152         int                        tgtlen;
153         __u32                       valid;
154         __u32                       mode;
155         __u32                       uid;
156         __u32                       gid;
157         __u64                       size;
158         __u32                       mtime;
159         __u32                       ctime;
160         __u32                       atime;
161         __u32                       flags;
162         __u32                       major;
163         __u32                       minor;
164         __u32                       ino;
165         __u32                       generation;
166 };
167
168 /* 
169  *   OBD IOCTLS
170  */
171
172
173 #define OBD_IOCTL_VERSION 0x00010001
174
175 struct obd_ioctl_data { 
176         uint32_t ioc_len;
177         uint32_t ioc_version;
178         uint32_t ioc_conn1;
179         uint32_t ioc_conn2;
180         struct obdo ioc_obdo1;
181         struct obdo ioc_obdo2;
182         obd_size         ioc_count;
183         obd_off          ioc_offset;
184         uint32_t         ioc_dev;
185
186         /* buffers the kernel will treat as user pointers */
187         uint32_t ioc_plen1;
188         char    *ioc_pbuf1;
189         uint32_t ioc_plen2;
190         char    *ioc_pbuf2;
191
192         /* two inline buffers */
193         uint32_t ioc_inllen1;
194         char    *ioc_inlbuf1;
195         uint32_t ioc_inllen2;
196         char    *ioc_inlbuf2;
197
198         char    ioc_bulk[0];
199 };
200
201 struct obd_ioctl_hdr { 
202         uint32_t ioc_len;
203         uint32_t ioc_version;
204 };
205
206 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
207 {
208         int len = sizeof(struct obd_ioctl_data);
209         len += size_round(data->ioc_inllen1);
210         len += size_round(data->ioc_inllen2);
211         return len;
212 }
213
214 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
215 {
216         if (data->ioc_len > (1<<30)) { 
217                 printk("OBD ioctl: ioc_len larger than 1<<30\n");
218                 return 1;
219         }
220         if (data->ioc_inllen1 > (1<<30)) { 
221                 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
222                 return 1;
223         }
224         if (data->ioc_inllen2 > (1<<30)) { 
225                 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
226                 return 1;
227         }
228         if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
229                 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
230                 return 1;
231         }
232         if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
233                 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
234                 return 1;
235         }
236         if (data->ioc_pbuf1 && !data->ioc_plen1) {
237                 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
238                 return 1;
239         }
240         if (data->ioc_pbuf2 && !data->ioc_plen2) {
241                 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
242                 return 1;
243         }
244         if (obd_ioctl_packlen(data) != data->ioc_len ) {
245                 printk("OBD ioctl: packlen exceeds ioc_len\n");
246                 return 1;
247         }
248         if (data->ioc_inllen1 && 
249             data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') { 
250                 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
251                 return 1;
252         }
253         if (data->ioc_inllen2 && 
254             data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') { 
255                 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
256                 return 1;
257         }
258         return 0;
259 }
260
261 #ifndef __KERNEL__
262 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max)
263 {
264         char *ptr;
265         struct obd_ioctl_data *overlay;
266         data->ioc_len = obd_ioctl_packlen(data);
267         data->ioc_version = OBD_IOCTL_VERSION;
268
269         if (*pbuf && obd_ioctl_packlen(data) > max) 
270                 return 1;
271         if (*pbuf == NULL) { 
272                 *pbuf = malloc(data->ioc_len);
273         }
274         if (!*pbuf)
275                 return 1;
276         overlay = (struct obd_ioctl_data *)*pbuf;
277         memcpy(*pbuf, data, sizeof(*data));
278
279         ptr = overlay->ioc_bulk;
280         if (data->ioc_inlbuf1)
281                 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
282         if (data->ioc_inlbuf2)
283                 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
284         if (obd_ioctl_is_invalid(overlay))
285                 return 1;
286
287         return 0;
288 }
289 #else
290
291
292 /* buffer MUST be at least the size of obd_ioctl_hdr */
293 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
294 {
295         struct obd_ioctl_hdr *hdr;
296         struct obd_ioctl_data *data;
297         int err;
298         ENTRY;
299
300         hdr = (struct obd_ioctl_hdr *)buf;
301         data = (struct obd_ioctl_data *)buf;
302
303         err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
304         if ( err ) {
305                 EXIT;
306                 return err;
307         }
308
309         if (hdr->ioc_version != OBD_IOCTL_VERSION) { 
310                 printk("OBD: version mismatch kernel vs application\n");
311                 return -EINVAL;
312         }
313
314         if (hdr->ioc_len + buf >= end) { 
315                 printk("OBD: user buffer exceeds kernel buffer\n");
316                 return -EINVAL;
317         }
318
319
320         if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) { 
321                 printk("OBD: user buffer too small for ioctl\n");
322                 return -EINVAL;
323         }
324
325         err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
326         if ( err ) {
327                 EXIT;
328                 return err;
329         }
330
331         if (obd_ioctl_is_invalid(data)) { 
332                 printk("OBD: ioctl not correctly formatted\n");
333                 return -EINVAL;
334         }
335
336         if (data->ioc_inllen1) { 
337                 data->ioc_inlbuf1 = &data->ioc_bulk[0];
338         }
339
340         if (data->ioc_inllen2) { 
341                 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
342         }
343
344         EXIT;
345         return 0;
346 }
347 #endif
348
349
350 #define OBD_IOC_CREATE                 _IOR ('f',  3, long)
351 #define OBD_IOC_SETUP                  _IOW ('f',  4, long)
352 #define OBD_IOC_CLEANUP                _IO  ('f',  5      )
353 #define OBD_IOC_DESTROY                _IOW ('f',  6, long)
354 #define OBD_IOC_PREALLOCATE            _IOWR('f',  7, long)
355 #define OBD_IOC_DEC_USE_COUNT          _IO  ('f',  8      )
356 #define OBD_IOC_SETATTR                _IOW ('f',  9, long)
357 #define OBD_IOC_GETATTR                _IOR ('f', 10, long)
358 #define OBD_IOC_READ                   _IOWR('f', 11, long)
359 #define OBD_IOC_WRITE                  _IOWR('f', 12, long)
360 #define OBD_IOC_CONNECT                _IOR ('f', 13, long)
361 #define OBD_IOC_DISCONNECT             _IOW ('f', 14, long)
362 #define OBD_IOC_STATFS                 _IOWR('f', 15, long)
363 #define OBD_IOC_SYNC                   _IOR ('f', 16, long)
364 #define OBD_IOC_READ2                  _IOWR('f', 17, long)
365 #define OBD_IOC_FORMAT                 _IOWR('f', 18, long)
366 #define OBD_IOC_PARTITION              _IOWR('f', 19, long)
367 #define OBD_IOC_ATTACH                 _IOWR('f', 20, long)
368 #define OBD_IOC_DETACH                 _IOWR('f', 21, long)
369 #define OBD_IOC_COPY                   _IOWR('f', 22, long)
370 #define OBD_IOC_MIGR                   _IOWR('f', 23, long)
371 #define OBD_IOC_PUNCH                  _IOWR('f', 24, long)
372 #define OBD_IOC_DEVICE                 _IOWR('f', 25, long)
373
374 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 32      )
375
376
377
378
379 #endif