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