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
45 * OST requests: OBDO & OBD request records
50 #define OST_GET_INFO 6
52 #define OST_DISCONNECT 8
60 #define OST_TYPE_REQ 1
61 #define OST_TYPE_REP 2
62 #define OST_TYPE_ERR 3
78 typedef uint64_t obd_id;
79 typedef uint64_t obd_gr;
80 typedef uint64_t obd_time;
81 typedef uint64_t obd_size;
82 typedef uint64_t obd_off;
83 typedef uint64_t obd_blocks;
84 typedef uint32_t obd_blksize;
85 typedef uint32_t obd_mode;
86 typedef uint32_t obd_uid;
87 typedef uint32_t obd_gid;
88 typedef uint32_t obd_rdev;
89 typedef uint32_t obd_flag;
90 typedef uint32_t obd_count;
92 #define OBD_FL_INLINEDATA (0x00000001UL)
93 #define OBD_FL_OBDMDEXISTS (0x00000002UL)
95 #define OBD_INLINESZ 60
96 #define OBD_OBDMDSZ 60
97 /* Note: 64-bit types are 64-bit aligned in structure */
106 obd_blksize o_blksize;
113 obd_count o_generation;
114 obd_flag o_valid; /* hot fields in this obdo */
115 char o_inline[OBD_INLINESZ];
116 char o_obdmd[OBD_OBDMDSZ];
117 struct list_head o_list;
118 struct obd_ops *o_op;
121 #define OBD_MD_FLALL (~0UL)
122 #define OBD_MD_FLID (0x00000001UL)
123 #define OBD_MD_FLATIME (0x00000002UL)
124 #define OBD_MD_FLMTIME (0x00000004UL)
125 #define OBD_MD_FLCTIME (0x00000008UL)
126 #define OBD_MD_FLSIZE (0x00000010UL)
127 #define OBD_MD_FLBLOCKS (0x00000020UL)
128 #define OBD_MD_FLBLKSZ (0x00000040UL)
129 #define OBD_MD_FLMODE (0x00000080UL)
130 #define OBD_MD_FLTYPE (0x00000100UL)
131 #define OBD_MD_FLUID (0x00000200UL)
132 #define OBD_MD_FLGID (0x00000400UL)
133 #define OBD_MD_FLFLAGS (0x00000800UL)
134 #define OBD_MD_FLOBDFLG (0x00001000UL)
135 #define OBD_MD_FLNLINK (0x00002000UL)
136 #define OBD_MD_FLGENER (0x00004000UL)
137 #define OBD_MD_FLINLINE (0x00008000UL)
138 #define OBD_MD_FLOBDMD (0x00010000UL)
139 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS))
141 /* request structure for OST's */
143 #define OST_REQ_HAS_OA1 0x1
145 struct ost_req_packed {
155 struct ost_rep_packed {
166 __u64 addr; // address
167 __u64 handle; // DMA handle
168 __u64 matchbits; // portals match bits
169 __u32 offset; // first bit after addr that is relevant
170 __u32 size; // size from addr + offset that needs moving
181 /* reply structure for OST's */
192 #define MDS_TYPE_REQ 1
193 #define MDS_TYPE_REP 2
194 #define MDS_TYPE_ERR 3
217 struct mds_req_packed {
218 struct lustre_fid fid1;
219 struct lustre_fid fid2;
239 struct mds_rep_packed {
240 struct lustre_fid fid1;
241 struct lustre_fid fid2;
266 #define OBD_IOCTL_VERSION 0x00010001
268 struct obd_ioctl_data {
270 uint32_t ioc_version;
273 struct obdo ioc_obdo1;
274 struct obdo ioc_obdo2;
279 /* buffers the kernel will treat as user pointers */
285 /* two inline buffers */
286 uint32_t ioc_inllen1;
288 uint32_t ioc_inllen2;
294 struct obd_ioctl_hdr {
296 uint32_t ioc_version;
299 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
301 int len = sizeof(struct obd_ioctl_data);
302 len += size_round(data->ioc_inllen1);
303 len += size_round(data->ioc_inllen2);
307 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
309 if (data->ioc_len > (1<<30)) {
310 printk("OBD ioctl: ioc_len larger than 1<<30\n");
313 if (data->ioc_inllen1 > (1<<30)) {
314 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
317 if (data->ioc_inllen2 > (1<<30)) {
318 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
321 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
322 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
325 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
326 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
329 if (data->ioc_pbuf1 && !data->ioc_plen1) {
330 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
333 if (data->ioc_pbuf2 && !data->ioc_plen2) {
334 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
337 if (obd_ioctl_packlen(data) != data->ioc_len ) {
338 printk("OBD ioctl: packlen exceeds ioc_len\n");
341 if (data->ioc_inllen1 &&
342 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
343 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
346 if (data->ioc_inllen2 &&
347 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
348 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
355 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max)
358 struct obd_ioctl_data *overlay;
359 data->ioc_len = obd_ioctl_packlen(data);
360 data->ioc_version = OBD_IOCTL_VERSION;
362 if (*pbuf && obd_ioctl_packlen(data) > max)
365 *pbuf = malloc(data->ioc_len);
369 overlay = (struct obd_ioctl_data *)*pbuf;
370 memcpy(*pbuf, data, sizeof(*data));
372 ptr = overlay->ioc_bulk;
373 if (data->ioc_inlbuf1)
374 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
375 if (data->ioc_inlbuf2)
376 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
377 if (obd_ioctl_is_invalid(overlay))
385 /* buffer MUST be at least the size of obd_ioctl_hdr */
386 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
388 struct obd_ioctl_hdr *hdr;
389 struct obd_ioctl_data *data;
393 hdr = (struct obd_ioctl_hdr *)buf;
394 data = (struct obd_ioctl_data *)buf;
396 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
402 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
403 printk("OBD: version mismatch kernel vs application\n");
407 if (hdr->ioc_len + buf >= end) {
408 printk("OBD: user buffer exceeds kernel buffer\n");
413 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
414 printk("OBD: user buffer too small for ioctl\n");
418 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
424 if (obd_ioctl_is_invalid(data)) {
425 printk("OBD: ioctl not correctly formatted\n");
429 if (data->ioc_inllen1) {
430 data->ioc_inlbuf1 = &data->ioc_bulk[0];
433 if (data->ioc_inllen2) {
434 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
443 #define OBD_IOC_CREATE _IOR ('f', 3, long)
444 #define OBD_IOC_SETUP _IOW ('f', 4, long)
445 #define OBD_IOC_CLEANUP _IO ('f', 5 )
446 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
447 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
448 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
449 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
450 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
451 #define OBD_IOC_READ _IOWR('f', 11, long)
452 #define OBD_IOC_WRITE _IOWR('f', 12, long)
453 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
454 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
455 #define OBD_IOC_STATFS _IOWR('f', 15, long)
456 #define OBD_IOC_SYNC _IOR ('f', 16, long)
457 #define OBD_IOC_READ2 _IOWR('f', 17, long)
458 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
459 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
460 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
461 #define OBD_IOC_DETACH _IOWR('f', 21, long)
462 #define OBD_IOC_COPY _IOWR('f', 22, long)
463 #define OBD_IOC_MIGR _IOWR('f', 23, long)
464 #define OBD_IOC_PUNCH _IOWR('f', 24, long)
465 #define OBD_IOC_DEVICE _IOWR('f', 25, long)
467 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )