1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
21 * (Un)packing of OST requests
24 #ifndef __LUSTRE_IDL_H__
25 #define __LUSTRE_IDL_H__
27 #include <linux/ioctl.h>
28 #include <asm/types.h>
30 #include <linux/types.h>
33 #include <linux/list.h>
38 * this file contains all data structures used in Lustre interfaces:
39 * - obdo and obd_request records
40 * - mds_request records
56 * OST requests: OBDO & OBD request records
65 #define OST_GET_INFO 6
67 #define OST_DISCONNECT 8
73 typedef uint64_t obd_id;
74 typedef uint64_t obd_gr;
75 typedef uint64_t obd_time;
76 typedef uint64_t obd_size;
77 typedef uint64_t obd_off;
78 typedef uint64_t obd_blocks;
79 typedef uint32_t obd_blksize;
80 typedef uint32_t obd_mode;
81 typedef uint32_t obd_uid;
82 typedef uint32_t obd_gid;
83 typedef uint32_t obd_rdev;
84 typedef uint32_t obd_flag;
85 typedef uint32_t obd_count;
87 #define OBD_FL_INLINEDATA (0x00000001UL)
88 #define OBD_FL_OBDMDEXISTS (0x00000002UL)
90 #define OBD_INLINESZ 60
91 #define OBD_OBDMDSZ 60
92 /* Note: 64-bit types are 64-bit aligned in structure */
101 obd_blksize o_blksize;
108 obd_count o_generation;
109 obd_flag o_valid; /* hot fields in this obdo */
110 char o_inline[OBD_INLINESZ];
111 char o_obdmd[OBD_OBDMDSZ];
112 struct list_head o_list;
113 struct obd_ops *o_op;
116 #define OBD_MD_FLALL (~0UL)
117 #define OBD_MD_FLID (0x00000001UL)
118 #define OBD_MD_FLATIME (0x00000002UL)
119 #define OBD_MD_FLMTIME (0x00000004UL)
120 #define OBD_MD_FLCTIME (0x00000008UL)
121 #define OBD_MD_FLSIZE (0x00000010UL)
122 #define OBD_MD_FLBLOCKS (0x00000020UL)
123 #define OBD_MD_FLBLKSZ (0x00000040UL)
124 #define OBD_MD_FLMODE (0x00000080UL)
125 #define OBD_MD_FLTYPE (0x00000100UL)
126 #define OBD_MD_FLUID (0x00000200UL)
127 #define OBD_MD_FLGID (0x00000400UL)
128 #define OBD_MD_FLFLAGS (0x00000800UL)
129 #define OBD_MD_FLOBDFLG (0x00001000UL)
130 #define OBD_MD_FLNLINK (0x00002000UL)
131 #define OBD_MD_FLGENER (0x00004000UL)
132 #define OBD_MD_FLINLINE (0x00008000UL)
133 #define OBD_MD_FLOBDMD (0x00010000UL)
134 #define OBD_MD_FLOBJID (0x00020000UL)
135 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS))
137 /* request structure for OST's */
139 #define OST_REQ_HAS_OA1 0x1
158 #define MDS_GETATTR 1
162 #define MDS_READPAGE 5
164 #define REINT_SETATTR 1
165 #define REINT_CREATE 2
167 #define REINT_UNLINK 4
168 #define REINT_RENAME 5
206 /* MDS update records */
207 struct mds_update_record_hdr {
211 struct mds_rec_setattr {
213 struct ll_fid sa_fid;
225 struct mds_rec_create {
227 struct ll_fid cr_fid;
232 /* overloaded: id for create, tgtlen for symlink, rdev for mknod */
236 struct mds_rec_link {
238 struct ll_fid lk_fid1;
239 struct ll_fid lk_fid2;
242 struct mds_rec_unlink {
244 struct ll_fid ul_fid1;
245 struct ll_fid ul_fid2;
248 struct mds_rec_rename {
250 struct ll_fid rn_fid1;
251 struct ll_fid rn_fid2;
256 static inline void ll_ino2fid(struct ll_fid *fid, ino_t ino, __u32 generation,
259 fid->id = HTON__u64((__u64)ino);
260 fid->generation = HTON__u32(generation);
261 fid->f_type = HTON__u32(type);
264 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
266 ll_ino2fid(fid, inode->i_ino, inode->i_generation,
267 inode->i_mode & S_IFMT);
277 #define LDLM_ENQUEUE 1
278 #define LDLM_CONVERT 2
279 #define LDLM_CANCEL 3
280 #define LDLM_CALLBACK 4
282 #define RES_NAME_SIZE 3
283 #define RES_VERSION_SIZE 4
305 struct ldlm_request {
307 __u64 res_id[RES_NAME_SIZE];
310 struct ldlm_extent lock_extent;
311 struct ldlm_handle parent_res_handle;
312 struct ldlm_handle parent_lock_handle;
317 struct ldlm_handle lock_handle;
325 #define OBD_IOCTL_VERSION 0x00010001
327 struct obd_ioctl_data {
329 uint32_t ioc_version;
332 struct obdo ioc_obdo1;
333 struct obdo ioc_obdo2;
338 /* buffers the kernel will treat as user pointers */
344 /* two inline buffers */
345 uint32_t ioc_inllen1;
347 uint32_t ioc_inllen2;
353 struct obd_ioctl_hdr {
355 uint32_t ioc_version;
358 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
360 int len = sizeof(struct obd_ioctl_data);
361 len += size_round(data->ioc_inllen1);
362 len += size_round(data->ioc_inllen2);
366 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
368 if (data->ioc_len > (1<<30)) {
369 printk("OBD ioctl: ioc_len larger than 1<<30\n");
372 if (data->ioc_inllen1 > (1<<30)) {
373 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
376 if (data->ioc_inllen2 > (1<<30)) {
377 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
380 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
381 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
384 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
385 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
388 if (data->ioc_pbuf1 && !data->ioc_plen1) {
389 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
392 if (data->ioc_pbuf2 && !data->ioc_plen2) {
393 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
397 if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
398 printk("OBD ioctl: inllen1 set but NULL pointer\n");
401 if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
402 printk("OBD ioctl: inllen2 set but NULL pointer\n");
405 if (data->ioc_plen1 && !data->ioc_pbuf1) {
406 printk("OBD ioctl: plen1 set but NULL pointer\n");
409 if (data->ioc_plen2 && !data->ioc_pbuf2) {
410 printk("OBD ioctl: plen2 set but NULL pointer\n");
414 if (obd_ioctl_packlen(data) != data->ioc_len ) {
415 printk("OBD ioctl: packlen exceeds ioc_len\n");
418 if (data->ioc_inllen1 &&
419 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
420 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
423 if (data->ioc_inllen2 &&
424 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
425 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
432 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
436 struct obd_ioctl_data *overlay;
437 data->ioc_len = obd_ioctl_packlen(data);
438 data->ioc_version = OBD_IOCTL_VERSION;
440 if (*pbuf && obd_ioctl_packlen(data) > max)
443 *pbuf = malloc(data->ioc_len);
447 overlay = (struct obd_ioctl_data *)*pbuf;
448 memcpy(*pbuf, data, sizeof(*data));
450 ptr = overlay->ioc_bulk;
451 if (data->ioc_inlbuf1)
452 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
453 if (data->ioc_inlbuf2)
454 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
455 if (obd_ioctl_is_invalid(overlay))
463 /* buffer MUST be at least the size of obd_ioctl_hdr */
464 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
466 struct obd_ioctl_hdr *hdr;
467 struct obd_ioctl_data *data;
471 hdr = (struct obd_ioctl_hdr *)buf;
472 data = (struct obd_ioctl_data *)buf;
474 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
480 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
481 printk("OBD: version mismatch kernel vs application\n");
485 if (hdr->ioc_len + buf >= end) {
486 printk("OBD: user buffer exceeds kernel buffer\n");
491 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
492 printk("OBD: user buffer too small for ioctl\n");
496 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
502 if (obd_ioctl_is_invalid(data)) {
503 printk("OBD: ioctl not correctly formatted\n");
507 if (data->ioc_inllen1) {
508 data->ioc_inlbuf1 = &data->ioc_bulk[0];
511 if (data->ioc_inllen2) {
512 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
521 #define OBD_IOC_CREATE _IOR ('f', 3, long)
522 #define OBD_IOC_SETUP _IOW ('f', 4, long)
523 #define OBD_IOC_CLEANUP _IO ('f', 5 )
524 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
525 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
526 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
527 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
528 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
529 #define OBD_IOC_READ _IOWR('f', 11, long)
530 #define OBD_IOC_WRITE _IOWR('f', 12, long)
531 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
532 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
533 #define OBD_IOC_STATFS _IOWR('f', 15, long)
534 #define OBD_IOC_SYNC _IOR ('f', 16, long)
535 #define OBD_IOC_READ2 _IOWR('f', 17, long)
536 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
537 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
538 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
539 #define OBD_IOC_DETACH _IOWR('f', 21, long)
540 #define OBD_IOC_COPY _IOWR('f', 22, long)
541 #define OBD_IOC_MIGR _IOWR('f', 23, long)
542 #define OBD_IOC_PUNCH _IOWR('f', 24, long)
543 #define OBD_IOC_DEVICE _IOWR('f', 25, long)
544 #define OBD_IOC_MODULE_DEBUG _IOWR('f', 26, long)
545 #define OBD_IOC_BRW_READ _IOWR('f', 27, long)
546 #define OBD_IOC_BRW_WRITE _IOWR('f', 28, long)
548 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )