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