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.
7 #ifndef __LUSTRE_IDL_H__
8 #define __LUSTRE_IDL_H__
10 #include <linux/ioctl.h>
11 #include <asm/types.h>
13 #include <linux/types.h>
16 #include <linux/list.h>
21 * this file contains all data structures used in Lustre interfaces:
22 * - obdo and obd_request records
23 * - mds_request records
28 * OBDO & OBD request records
31 typedef uint64_t obd_id;
32 typedef uint64_t obd_gr;
33 typedef uint64_t obd_time;
34 typedef uint64_t obd_size;
35 typedef uint64_t obd_off;
36 typedef uint64_t obd_blocks;
37 typedef uint32_t obd_blksize;
38 typedef uint32_t obd_mode;
39 typedef uint32_t obd_uid;
40 typedef uint32_t obd_gid;
41 typedef uint32_t obd_rdev;
42 typedef uint32_t obd_flag;
43 typedef uint32_t obd_count;
45 #define OBD_FL_INLINEDATA (0x00000001UL)
46 #define OBD_FL_OBDMDEXISTS (0x00000002UL)
48 #define OBD_INLINESZ 60
49 #define OBD_OBDMDSZ 60
50 /* Note: 64-bit types are 64-bit aligned in structure */
59 obd_blksize o_blksize;
66 obd_count o_generation;
67 obd_flag o_valid; /* hot fields in this obdo */
68 char o_inline[OBD_INLINESZ];
69 char o_obdmd[OBD_OBDMDSZ];
70 struct list_head o_list;
74 #define OBD_MD_FLALL (~0UL)
75 #define OBD_MD_FLID (0x00000001UL)
76 #define OBD_MD_FLATIME (0x00000002UL)
77 #define OBD_MD_FLMTIME (0x00000004UL)
78 #define OBD_MD_FLCTIME (0x00000008UL)
79 #define OBD_MD_FLSIZE (0x00000010UL)
80 #define OBD_MD_FLBLOCKS (0x00000020UL)
81 #define OBD_MD_FLBLKSZ (0x00000040UL)
82 #define OBD_MD_FLMODE (0x00000080UL)
83 #define OBD_MD_FLTYPE (0x00000100UL)
84 #define OBD_MD_FLUID (0x00000200UL)
85 #define OBD_MD_FLGID (0x00000400UL)
86 #define OBD_MD_FLFLAGS (0x00000800UL)
87 #define OBD_MD_FLOBDFLG (0x00001000UL)
88 #define OBD_MD_FLNLINK (0x00002000UL)
89 #define OBD_MD_FLGENER (0x00004000UL)
90 #define OBD_MD_FLINLINE (0x00008000UL)
91 #define OBD_MD_FLOBDMD (0x00010000UL)
92 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS))
100 #define MDS_TYPE_REQ 1
101 #define MDS_TYPE_REP 2
102 #define MDS_TYPE_ERR 3
118 struct lustre_fid fid1;
119 struct lustre_fid fid2;
147 struct lustre_fid fid1;
148 struct lustre_fid fid2;
173 #define OBD_IOCTL_VERSION 0x00010001
175 struct obd_ioctl_data {
177 uint32_t ioc_version;
180 struct obdo ioc_obdo1;
181 struct obdo ioc_obdo2;
186 /* buffers the kernel will treat as user pointers */
192 /* two inline buffers */
193 uint32_t ioc_inllen1;
195 uint32_t ioc_inllen2;
201 struct obd_ioctl_hdr {
203 uint32_t ioc_version;
206 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
208 int len = sizeof(struct obd_ioctl_data);
209 len += size_round(data->ioc_inllen1);
210 len += size_round(data->ioc_inllen2);
214 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
216 if (data->ioc_len > (1<<30)) {
217 printk("OBD ioctl: ioc_len larger than 1<<30\n");
220 if (data->ioc_inllen1 > (1<<30)) {
221 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
224 if (data->ioc_inllen2 > (1<<30)) {
225 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
228 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
229 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
232 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
233 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
236 if (data->ioc_pbuf1 && !data->ioc_plen1) {
237 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
240 if (data->ioc_pbuf2 && !data->ioc_plen2) {
241 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
244 if (obd_ioctl_packlen(data) != data->ioc_len ) {
245 printk("OBD ioctl: packlen exceeds ioc_len\n");
248 if (data->ioc_inllen1 &&
249 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
250 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
253 if (data->ioc_inllen2 &&
254 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
255 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
262 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max)
265 struct obd_ioctl_data *overlay;
266 data->ioc_len = obd_ioctl_packlen(data);
267 data->ioc_version = OBD_IOCTL_VERSION;
269 if (*pbuf && obd_ioctl_packlen(data) > max)
272 *pbuf = malloc(data->ioc_len);
276 overlay = (struct obd_ioctl_data *)*pbuf;
277 memcpy(*pbuf, data, sizeof(*data));
279 ptr = overlay->ioc_bulk;
280 if (data->ioc_inlbuf1)
281 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
282 if (data->ioc_inlbuf2)
283 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
284 if (obd_ioctl_is_invalid(overlay))
292 /* buffer MUST be at least the size of obd_ioctl_hdr */
293 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
295 struct obd_ioctl_hdr *hdr;
296 struct obd_ioctl_data *data;
300 hdr = (struct obd_ioctl_hdr *)buf;
301 data = (struct obd_ioctl_data *)buf;
303 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
309 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
310 printk("OBD: version mismatch kernel vs application\n");
314 if (hdr->ioc_len + buf >= end) {
315 printk("OBD: user buffer exceeds kernel buffer\n");
320 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
321 printk("OBD: user buffer too small for ioctl\n");
325 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
331 if (obd_ioctl_is_invalid(data)) {
332 printk("OBD: ioctl not correctly formatted\n");
336 if (data->ioc_inllen1) {
337 data->ioc_inlbuf1 = &data->ioc_bulk[0];
340 if (data->ioc_inllen2) {
341 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
350 #define OBD_IOC_CREATE _IOR ('f', 3, long)
351 #define OBD_IOC_SETUP _IOW ('f', 4, long)
352 #define OBD_IOC_CLEANUP _IO ('f', 5 )
353 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
354 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
355 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
356 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
357 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
358 #define OBD_IOC_READ _IOWR('f', 11, long)
359 #define OBD_IOC_WRITE _IOWR('f', 12, long)
360 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
361 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
362 #define OBD_IOC_STATFS _IOWR('f', 15, long)
363 #define OBD_IOC_SYNC _IOR ('f', 16, long)
364 #define OBD_IOC_READ2 _IOWR('f', 17, long)
365 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
366 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
367 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
368 #define OBD_IOC_DETACH _IOWR('f', 21, long)
369 #define OBD_IOC_COPY _IOWR('f', 22, long)
370 #define OBD_IOC_MIGR _IOWR('f', 23, long)
371 #define OBD_IOC_PUNCH _IOWR('f', 24, long)
372 #define OBD_IOC_DEVICE _IOWR('f', 25, long)
374 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )