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