Whamcloud - gitweb
- much of the striping configuration managment and setup builds up
[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
27 #ifdef __KERNEL__
28 # include <linux/ioctl.h>
29 # include <asm/types.h>
30 # include <linux/types.h>
31 # include <linux/list.h>
32 #else
33 # define __KERNEL__
34 # include <linux/list.h>
35 # undef __KERNEL__
36 # include <stdint.h>
37 #endif
38 /*
39  * this file contains all data structures used in Lustre interfaces:
40  * - obdo and obd_request records
41  * - mds_request records
42  * - ldlm data
43  * - ioctl's
44  */
45
46 /*
47  *  GENERAL STUFF
48  */
49 typedef __u8 uuid_t[37];
50
51
52
53 #define PTL_RPC_MSG_REQUEST 4711
54 #define PTL_RPC_MSG_ERR 4712
55
56 #define PTLRPC_MSG_MAGIC (cpu_to_le32(0x0BD00BD0))
57 #define PTLRPC_MSG_VERSION (cpu_to_le32(0x00040001))
58
59 struct lustre_handle {
60         __u64 addr;
61         __u64 cookie;
62 };
63
64 struct lustre_msg {
65         __u64 addr;
66         __u64 cookie; /* security token */
67         __u32 magic;
68         __u32 version;
69         __u64 last_rcvd;
70         __u64 last_committed;
71         __u64 transno;
72         __u32 opc;
73         __u32 status;
74         __u32 type;
75         __u32   bufcount;
76         __u32   buflens[0];
77 };
78
79 #define N_LOCAL_TEMP_PAGE 0x00000001
80
81 /*
82  *   OST requests: OBDO & OBD request records
83  */
84
85 /* opcodes */
86 #define OST_GETATTR    1
87 #define OST_SETATTR    2
88 #define OST_BRW        3
89 #define OST_CREATE     4
90 #define OST_DESTROY    5
91 #define OST_GET_INFO   6
92 #define OST_CONNECT    7
93 #define OST_DISCONNECT 8
94 #define OST_PUNCH      9
95 #define OST_OPEN      10
96 #define OST_CLOSE     11
97 #define OST_STATFS    12
98
99
100 typedef uint64_t        obd_id;
101 typedef uint64_t        obd_gr;
102 typedef uint64_t        obd_time;
103 typedef uint64_t        obd_size;
104 typedef uint64_t        obd_off;
105 typedef uint64_t        obd_blocks;
106 typedef uint32_t        obd_blksize;
107 typedef uint32_t        obd_mode;
108 typedef uint32_t        obd_uid;
109 typedef uint32_t        obd_gid;
110 typedef uint32_t        obd_rdev;
111 typedef uint32_t        obd_flag;
112 typedef uint32_t        obd_count;
113
114 #define OBD_FL_INLINEDATA       (0x00000001)
115 #define OBD_FL_OBDMDEXISTS      (0x00000002)
116 #define OBD_FL_CREATEONOPEN     (0x00000004)
117
118 #define OBD_INLINESZ    60
119 #define OBD_OBDMDSZ     60
120 /* Note: 64-bit types are 64-bit aligned in structure */
121 struct obdo {
122         obd_id                  o_id;
123         obd_gr                  o_gr;
124         obd_time                o_atime;
125         obd_time                o_mtime;
126         obd_time                o_ctime;
127         obd_size                o_size;
128         obd_blocks              o_blocks;
129         obd_blksize             o_blksize;
130         obd_mode                o_mode;
131         obd_uid                 o_uid;
132         obd_gid                 o_gid;
133         obd_flag                o_flags;
134         obd_count               o_nlink;
135         obd_count               o_generation;
136         obd_rdev                o_rdev;
137         obd_flag                o_valid;        /* hot fields in this obdo */
138         obd_flag                o_obdflags;
139         char                    o_inline[OBD_INLINESZ];
140 };
141
142 #define OBD_MD_FLALL    (0xffffffff)
143 #define OBD_MD_FLID     (0x00000001)
144 #define OBD_MD_FLATIME  (0x00000002)
145 #define OBD_MD_FLMTIME  (0x00000004)
146 #define OBD_MD_FLCTIME  (0x00000008)
147 #define OBD_MD_FLSIZE   (0x00000010)
148 #define OBD_MD_FLBLOCKS (0x00000020)
149 #define OBD_MD_FLBLKSZ  (0x00000040)
150 #define OBD_MD_FLMODE   (0x00000080)
151 #define OBD_MD_FLTYPE   (0x00000100)
152 #define OBD_MD_FLUID    (0x00000200)
153 #define OBD_MD_FLGID    (0x00000400)
154 #define OBD_MD_FLFLAGS  (0x00000800)
155 #define OBD_MD_FLOBDFLG (0x00001000)
156 #define OBD_MD_FLNLINK  (0x00002000)
157 #define OBD_MD_FLGENER  (0x00004000)
158 #define OBD_MD_FLINLINE (0x00008000)
159 #define OBD_MD_FLOBDMD  (0x00010000)
160 #define OBD_MD_FLOBJID  (0x00020000)
161 #define OBD_MD_LINKNAME (0x00040000)
162 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS |\
163                            OBD_MD_LINKNAME))
164
165 struct obd_statfs {
166         __u64           os_type;
167         __u64           os_blocks;
168         __u64           os_bfree;
169         __u64           os_bavail;
170         __u64           os_files;
171         __u64           os_ffree;
172         __u64           os_fsid;
173         __u32           os_bsize;
174         __u32           os_namelen;
175         __u32           os_spare[12];
176 };
177
178 struct obd_ioobj {
179         obd_id    ioo_id;
180         obd_gr    ioo_gr;
181         __u32     ioo_type;
182         __u32     ioo_bufcnt;
183 };
184
185 struct niobuf_remote {
186         __u64 offset;
187         __u32 len;
188         __u32 xid;
189         __u32 flags;
190 };
191
192 struct niobuf_local {
193         __u64 offset;
194         __u32 len;
195         __u32 xid;
196         __u32 flags;
197         void *addr;
198         struct page *page;
199         void *target_private;
200         struct dentry *dentry;
201 };
202
203 /* request structure for OST's */
204
205 #define OST_REQ_HAS_OA1  0x1
206
207 struct ost_body {
208         __u32   connid;
209         __u32   data;
210         struct  obdo oa;
211 };
212
213 /*
214  *   MDS REQ RECORDS
215  */
216
217 /* opcodes */
218 #define MDS_GETATTR    1
219 #define MDS_OPEN       2
220 #define MDS_CLOSE      3
221 #define MDS_REINT      4
222 #define MDS_READPAGE   6
223 #define MDS_CONNECT    7
224 #define MDS_DISCONNECT 8
225 #define MDS_GETSTATUS  9
226 #define MDS_STATFS     10
227 #define MDS_LOVINFO    11
228
229 #define REINT_SETATTR  1
230 #define REINT_CREATE   2
231 #define REINT_LINK     3
232 #define REINT_UNLINK   4
233 #define REINT_RENAME   5
234 #define REINT_RECREATE 6
235 #define REINT_MAX      6
236
237 struct ll_fid {
238         __u64 id;
239         __u32 generation;
240         __u32 f_type;
241 };
242
243
244 #define MDS_STATUS_CONN 1
245 #define MDS_STATUS_LOV 2
246
247 struct mds_status_req { 
248         __u32  flags;
249         __u32  repbuf;
250 };
251
252 struct mds_conn_status { 
253         struct ll_fid rootfid;
254         __u64          xid;
255         __u64          last_committed;
256         __u64          last_rcvd;
257         /* XXX preallocated quota & obj fields here */
258 };
259
260 struct mds_body {
261         struct ll_fid  fid1;
262         struct ll_fid  fid2;
263         __u64          size;
264         __u64          extra;
265         __u32          valid;
266         __u32          mode;
267         __u32          uid;
268         __u32          gid;
269         __u32          mtime;
270         __u32          ctime;
271         __u32          atime;
272         __u32          flags;
273         __u32          major;
274         __u32          minor;
275         __u32          ino;
276         __u32          nlink;
277         __u32          generation;
278         __u32          last_xid;
279 };
280
281 /* MDS update records */
282 struct mds_update_record_hdr {
283         __u32 ur_opcode;
284 };
285
286 struct mds_rec_setattr {
287         __u32           sa_opcode;
288         struct ll_fid   sa_fid;
289         __u32           sa_valid;
290         __u32           sa_mode;
291         __u32           sa_uid;
292         __u32           sa_gid;
293         __u64           sa_size;
294         __u64           sa_atime;
295         __u64           sa_mtime;
296         __u64           sa_ctime;
297         __u32           sa_attr_flags;
298 };
299
300 struct mds_rec_create {
301         __u32           cr_opcode;
302         struct ll_fid   cr_fid;
303         __u32           cr_uid;
304         __u32           cr_gid;
305         __u64           cr_time;
306         __u32           cr_mode;
307         __u64           cr_rdev;
308 };
309
310 struct mds_rec_link {
311         __u32           lk_opcode;
312         struct ll_fid   lk_fid1;
313         struct ll_fid   lk_fid2;
314 };
315
316 struct mds_rec_unlink {
317         __u32           ul_opcode;
318         struct ll_fid   ul_fid1;
319         struct ll_fid   ul_fid2;
320 };
321
322 struct mds_rec_rename {
323         __u32           rn_opcode;
324         struct ll_fid   rn_fid1;
325         struct ll_fid   rn_fid2;
326 };
327
328
329 /* 
330  *  LOV data structures
331  */
332
333 #define LOV_RAID0  0
334 struct lov_desc { 
335         __u32 ld_tgt_count; /* how many OBD's */
336         __u32 ld_default_stripecount;
337         __u32 ld_default_stripesize;   /* in bytes */
338         __u32 ld_pattern; /* RAID 0,1 etc */
339          uuid_t ld_uuid;
340 }; 
341
342 /*
343  *   LDLM requests:
344  */
345
346 /* opcodes */
347 #define LDLM_ENQUEUE       1
348 #define LDLM_CONVERT       2
349 #define LDLM_CANCEL        3
350 #define LDLM_CALLBACK      4
351
352 #define RES_NAME_SIZE 3
353 #define RES_VERSION_SIZE 4
354
355 /* lock types */
356 typedef enum {
357         LCK_EX = 1,
358         LCK_PW,
359         LCK_PR,
360         LCK_CW,
361         LCK_CR,
362         LCK_NL
363 } ldlm_mode_t;
364
365 struct ldlm_extent {
366         __u64 start;
367         __u64 end;
368 };
369
370 struct ldlm_intent {
371         __u64 opc;
372 };
373
374 struct ldlm_resource_desc {
375         __u32 lr_type;
376         __u64 lr_name[RES_NAME_SIZE];
377         __u64 lr_version[RES_VERSION_SIZE];
378 };
379
380 struct ldlm_lock_desc {
381         struct ldlm_resource_desc l_resource;
382         ldlm_mode_t l_req_mode;
383         ldlm_mode_t l_granted_mode;
384         struct ldlm_extent l_extent;
385         __u32 l_version[RES_VERSION_SIZE];
386 };
387
388 struct ldlm_request {
389         __u32 lock_flags;
390         struct ldlm_lock_desc lock_desc;
391         struct lustre_handle lock_handle1;
392         struct lustre_handle lock_handle2;
393 };
394
395 struct ldlm_reply {
396         __u32 lock_flags;
397         __u64 lock_resource_name[3];
398         struct lustre_handle lock_handle;
399         struct ldlm_extent lock_extent;   /* XXX make this policy 1 &2 */
400         __u64  lock_policy_res1;
401         __u64  lock_policy_res2;
402 };
403
404 /*
405  *   OBD IOCTLS
406  */
407 #define OBD_IOCTL_VERSION 0x00010001
408
409 struct obd_ioctl_data {
410         uint32_t ioc_len;
411         uint32_t ioc_version;
412
413         uint64_t ioc_addr;
414         uint64_t ioc_cookie;
415         uint32_t ioc_conn1;
416         uint32_t ioc_conn2;
417
418         struct obdo ioc_obdo1;
419         struct obdo ioc_obdo2;
420
421         obd_size         ioc_count;
422         obd_off          ioc_offset;
423         uint32_t         ioc_dev;
424         uint32_t         ____padding;
425
426         /* buffers the kernel will treat as user pointers */
427         uint32_t ioc_plen1;
428         char    *ioc_pbuf1;
429         uint32_t ioc_plen2;
430         char    *ioc_pbuf2;
431
432         /* two inline buffers */
433         uint32_t ioc_inllen1;
434         char    *ioc_inlbuf1;
435         uint32_t ioc_inllen2;
436         char    *ioc_inlbuf2;
437         uint32_t ioc_inllen3;
438         char    *ioc_inlbuf3;
439
440         char    ioc_bulk[0];
441 };
442
443 struct obd_ioctl_hdr {
444         uint32_t ioc_len;
445         uint32_t ioc_version;
446 };
447
448 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
449 {
450         int len = size_round(sizeof(struct obd_ioctl_data));
451         len += size_round(data->ioc_inllen1);
452         len += size_round(data->ioc_inllen2);
453         len += size_round(data->ioc_inllen3);
454         return len;
455 }
456
457
458 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
459 {
460         if (data->ioc_len > (1<<30)) {
461                 printk("OBD ioctl: ioc_len larger than 1<<30\n");
462                 return 1;
463         }
464         if (data->ioc_inllen1 > (1<<30)) {
465                 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
466                 return 1;
467         }
468         if (data->ioc_inllen2 > (1<<30)) {
469                 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
470                 return 1;
471         }
472
473         if (data->ioc_inllen3 > (1<<30)) {
474                 printk("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
475                 return 1;
476         }
477         if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
478                 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
479                 return 1;
480         }
481         if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
482                 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
483                 return 1;
484         }
485         if (data->ioc_inlbuf3 && !data->ioc_inllen3) {
486                 printk("OBD ioctl: inlbuf3 pointer but 0 length\n");
487                 return 1;
488         }
489         if (data->ioc_pbuf1 && !data->ioc_plen1) {
490                 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
491                 return 1;
492         }
493         if (data->ioc_pbuf2 && !data->ioc_plen2) {
494                 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
495                 return 1;
496         }
497         /*
498         if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
499                 printk("OBD ioctl: inllen1 set but NULL pointer\n");
500                 return 1;
501         }
502         if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
503                 printk("OBD ioctl: inllen2 set but NULL pointer\n");
504                 return 1;
505         }
506         if (data->ioc_inllen3 && !data->ioc_inlbuf3) {
507                 printk("OBD ioctl: inllen3 set but NULL pointer\n");
508                 return 1;
509         }
510         */
511         if (data->ioc_plen1 && !data->ioc_pbuf1) {
512                 printk("OBD ioctl: plen1 set but NULL pointer\n");
513                 return 1;
514         }
515         if (data->ioc_plen2 && !data->ioc_pbuf2) {
516                 printk("OBD ioctl: plen2 set but NULL pointer\n");
517                 return 1;
518         }
519         if (obd_ioctl_packlen(data) != data->ioc_len ) {
520                 printk("OBD ioctl: packlen exceeds ioc_len\n");
521                 return 1;
522         }
523 #if 0 
524         if (data->ioc_inllen1 &&
525             data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
526                 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
527                 return 1;
528         }
529         if (data->ioc_inllen2 &&
530             data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
531                 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
532                 return 1;
533         }
534         if (data->ioc_inllen3 &&
535             data->ioc_bulk[size_round(data->ioc_inllen1) + size_round(data->ioc_inllen2) 
536                            + data->ioc_inllen3 - 1] != '\0') {
537                 printk("OBD ioctl: inlbuf3 not 0 terminated\n");
538                 return 1;
539         }
540 #endif 
541         return 0;
542 }
543
544 #ifndef __KERNEL__
545 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
546                                  int max)
547 {
548         char *ptr;
549         struct obd_ioctl_data *overlay;
550         data->ioc_len = obd_ioctl_packlen(data);
551         data->ioc_version = OBD_IOCTL_VERSION;
552
553         if (*pbuf && obd_ioctl_packlen(data) > max)
554                 return 1;
555         if (*pbuf == NULL) {
556                 *pbuf = malloc(data->ioc_len);
557         }
558         if (!*pbuf)
559                 return 1;
560         overlay = (struct obd_ioctl_data *)*pbuf;
561         memcpy(*pbuf, data, sizeof(*data));
562
563         ptr = overlay->ioc_bulk;
564         if (data->ioc_inlbuf1)
565                 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
566         if (data->ioc_inlbuf2)
567                 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
568         if (data->ioc_inlbuf3)
569                 LOGL(data->ioc_inlbuf3, data->ioc_inllen3, ptr);
570         if (obd_ioctl_is_invalid(overlay))
571                 return 1;
572
573         return 0;
574 }
575 #else
576
577
578 /* buffer MUST be at least the size of obd_ioctl_hdr */
579 static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
580 {
581         struct obd_ioctl_hdr hdr;
582         struct obd_ioctl_data *data;
583         int err;
584         ENTRY;
585
586
587         err = copy_from_user(&hdr, (void *)arg, sizeof(hdr));
588         if ( err ) {
589                 EXIT;
590                 return err;
591         }
592
593         if (hdr.ioc_version != OBD_IOCTL_VERSION) {
594                 printk("OBD: version mismatch kernel vs application\n");
595                 return -EINVAL;
596         }
597
598         if (hdr.ioc_len > *len) {
599                 printk("OBD: user buffer exceeds kernel buffer\n");
600                 return -EINVAL;
601         }
602
603         if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
604                 printk("OBD: user buffer too small for ioctl\n");
605                 return -EINVAL;
606         }
607
608         OBD_ALLOC(*buf, hdr.ioc_len); 
609         if (!*buf) { 
610                 CERROR("Cannot allocate control buffer of len %d\n",
611                        hdr.ioc_len); 
612                 RETURN(-EINVAL);
613         }
614         *len = hdr.ioc_len;
615         data = (struct obd_ioctl_data *)*buf;
616
617         err = copy_from_user(*buf, (void *)arg, hdr.ioc_len);
618         if ( err ) {
619                 EXIT;
620                 return err;
621         }
622
623         if (obd_ioctl_is_invalid(data)) {
624                 printk("OBD: ioctl not correctly formatted\n");
625                 return -EINVAL;
626         }
627
628         if (data->ioc_inllen1) {
629                 data->ioc_inlbuf1 = &data->ioc_bulk[0];
630         }
631
632         if (data->ioc_inllen2) {
633                 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
634         }
635
636         if (data->ioc_inllen3) {
637                 data->ioc_inlbuf3 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1) + 
638                         size_round(data->ioc_inllen2);
639         }
640
641         EXIT;
642         return 0;
643 }
644 #endif
645
646
647 #define OBD_IOC_CREATE                 _IOR ('f', 101, long)
648 #define OBD_IOC_SETUP                  _IOW ('f', 102, long)
649 #define OBD_IOC_CLEANUP                _IO  ('f', 103      )
650 #define OBD_IOC_DESTROY                _IOW ('f', 104, long)
651 #define OBD_IOC_PREALLOCATE            _IOWR('f', 105, long)
652 #define OBD_IOC_DEC_USE_COUNT          _IO  ('f', 106      )
653 #define OBD_IOC_SETATTR                _IOW ('f', 107, long)
654 #define OBD_IOC_GETATTR                _IOR ('f', 108, long)
655 #define OBD_IOC_READ                   _IOWR('f', 109, long)
656 #define OBD_IOC_WRITE                  _IOWR('f', 110, long)
657 #define OBD_IOC_CONNECT                _IOR ('f', 111, long)
658 #define OBD_IOC_DISCONNECT             _IOW ('f', 112, long)
659 #define OBD_IOC_STATFS                 _IOWR('f', 113, long)
660 #define OBD_IOC_SYNC                   _IOR ('f', 114, long)
661 #define OBD_IOC_READ2                  _IOWR('f', 115, long)
662 #define OBD_IOC_FORMAT                 _IOWR('f', 116, long)
663 #define OBD_IOC_PARTITION              _IOWR('f', 117, long)
664 #define OBD_IOC_ATTACH                 _IOWR('f', 118, long)
665 #define OBD_IOC_DETACH                 _IOWR('f', 119, long)
666 #define OBD_IOC_COPY                   _IOWR('f', 120, long)
667 #define OBD_IOC_MIGR                   _IOWR('f', 121, long)
668 #define OBD_IOC_PUNCH                  _IOWR('f', 122, long)
669 #define OBD_IOC_DEVICE                 _IOWR('f', 123, long)
670 #define OBD_IOC_MODULE_DEBUG           _IOWR('f', 124, long)
671 #define OBD_IOC_BRW_READ               _IOWR('f', 125, long)
672 #define OBD_IOC_BRW_WRITE              _IOWR('f', 126, long)
673 #define OBD_IOC_NAME2DEV               _IOWR('f', 127, long)
674 #define OBD_IOC_NEWDEV                 _IOWR('f', 128, long)
675 #define OBD_IOC_LIST                   _IOWR('f', 129, long)
676 #define OBD_IOC_UUID2DEV               _IOWR('f', 130, long)
677
678 #define OBD_IOC_RECOVD_NEWCONN         _IOWR('f', 131, long)
679 #define OBD_IOC_LOV_CONFIG             _IOWR('f', 132, long)
680
681 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 133      )
682
683 #endif