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__
28 # include <linux/ioctl.h>
29 # 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 #define PTL_RPC_MSG_REQUEST 4711
46 #define PTL_RPC_MSG_ERR 4712
64 struct niobuf_remote {
80 * OST requests: OBDO & OBD request records
89 #define OST_GET_INFO 6
91 #define OST_DISCONNECT 8
97 typedef uint64_t obd_id;
98 typedef uint64_t obd_gr;
99 typedef uint64_t obd_time;
100 typedef uint64_t obd_size;
101 typedef uint64_t obd_off;
102 typedef uint64_t obd_blocks;
103 typedef uint32_t obd_blksize;
104 typedef uint32_t obd_mode;
105 typedef uint32_t obd_uid;
106 typedef uint32_t obd_gid;
107 typedef uint32_t obd_rdev;
108 typedef uint32_t obd_flag;
109 typedef uint32_t obd_count;
111 #define OBD_FL_INLINEDATA (0x00000001UL)
112 #define OBD_FL_OBDMDEXISTS (0x00000002UL)
114 #define OBD_INLINESZ 60
115 #define OBD_OBDMDSZ 60
116 /* Note: 64-bit types are 64-bit aligned in structure */
125 obd_blksize o_blksize;
132 obd_count o_generation;
133 obd_flag o_valid; /* hot fields in this obdo */
134 char o_inline[OBD_INLINESZ];
135 char o_obdmd[OBD_OBDMDSZ];
136 struct list_head o_list;
137 struct obd_ops *o_op;
140 #define OBD_MD_FLALL (~0UL)
141 #define OBD_MD_FLID (0x00000001UL)
142 #define OBD_MD_FLATIME (0x00000002UL)
143 #define OBD_MD_FLMTIME (0x00000004UL)
144 #define OBD_MD_FLCTIME (0x00000008UL)
145 #define OBD_MD_FLSIZE (0x00000010UL)
146 #define OBD_MD_FLBLOCKS (0x00000020UL)
147 #define OBD_MD_FLBLKSZ (0x00000040UL)
148 #define OBD_MD_FLMODE (0x00000080UL)
149 #define OBD_MD_FLTYPE (0x00000100UL)
150 #define OBD_MD_FLUID (0x00000200UL)
151 #define OBD_MD_FLGID (0x00000400UL)
152 #define OBD_MD_FLFLAGS (0x00000800UL)
153 #define OBD_MD_FLOBDFLG (0x00001000UL)
154 #define OBD_MD_FLNLINK (0x00002000UL)
155 #define OBD_MD_FLGENER (0x00004000UL)
156 #define OBD_MD_FLINLINE (0x00008000UL)
157 #define OBD_MD_FLOBDMD (0x00010000UL)
158 #define OBD_MD_FLOBJID (0x00020000UL)
159 #define OBD_MD_LINKNAME (0x00040000UL)
160 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS |\
163 /* request structure for OST's */
165 #define OST_REQ_HAS_OA1 0x1
185 #define MDS_GETATTR 1
189 #define MDS_READPAGE 6
190 #define MDS_CONNECT 7
192 #define REINT_SETATTR 1
193 #define REINT_CREATE 2
195 #define REINT_UNLINK 4
196 #define REINT_RENAME 5
197 #define REINT_RECREATE 6
227 /* MDS update records */
228 struct mds_update_record_hdr {
232 struct mds_rec_setattr {
234 struct ll_fid sa_fid;
246 struct mds_rec_create {
248 struct ll_fid cr_fid;
253 /* overloaded: id for create, tgtlen for symlink, rdev for mknod */
257 struct mds_rec_link {
259 struct ll_fid lk_fid1;
260 struct ll_fid lk_fid2;
263 struct mds_rec_unlink {
265 struct ll_fid ul_fid1;
266 struct ll_fid ul_fid2;
269 struct mds_rec_rename {
271 struct ll_fid rn_fid1;
272 struct ll_fid rn_fid2;
281 #define LDLM_ENQUEUE 1
282 #define LDLM_CONVERT 2
283 #define LDLM_CANCEL 3
284 #define LDLM_CALLBACK 4
286 #define RES_NAME_SIZE 3
287 #define RES_VERSION_SIZE 4
309 struct ldlm_resource_desc {
311 __u64 lr_name[RES_NAME_SIZE];
312 __u64 lr_version[RES_VERSION_SIZE];
315 struct ldlm_lock_desc {
316 struct ldlm_resource_desc l_resource;
317 ldlm_mode_t l_req_mode;
318 ldlm_mode_t l_granted_mode;
319 struct ldlm_extent l_extent;
320 __u32 l_version[RES_VERSION_SIZE];
323 struct ldlm_request {
325 struct ldlm_lock_desc lock_desc;
326 struct ldlm_handle lock_handle1;
327 struct ldlm_handle lock_handle2;
332 struct ldlm_handle lock_handle;
333 struct ldlm_extent lock_extent;
341 #define OBD_IOCTL_VERSION 0x00010001
343 struct obd_ioctl_data {
345 uint32_t ioc_version;
348 struct obdo ioc_obdo1;
349 struct obdo ioc_obdo2;
354 /* buffers the kernel will treat as user pointers */
360 /* two inline buffers */
361 uint32_t ioc_inllen1;
363 uint32_t ioc_inllen2;
369 struct obd_ioctl_hdr {
371 uint32_t ioc_version;
374 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
376 int len = sizeof(struct obd_ioctl_data);
377 len += size_round(data->ioc_inllen1);
378 len += size_round(data->ioc_inllen2);
382 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
384 if (data->ioc_len > (1<<30)) {
385 printk("OBD ioctl: ioc_len larger than 1<<30\n");
388 if (data->ioc_inllen1 > (1<<30)) {
389 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
392 if (data->ioc_inllen2 > (1<<30)) {
393 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
396 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
397 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
400 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
401 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
404 if (data->ioc_pbuf1 && !data->ioc_plen1) {
405 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
408 if (data->ioc_pbuf2 && !data->ioc_plen2) {
409 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
413 if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
414 printk("OBD ioctl: inllen1 set but NULL pointer\n");
417 if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
418 printk("OBD ioctl: inllen2 set but NULL pointer\n");
421 if (data->ioc_plen1 && !data->ioc_pbuf1) {
422 printk("OBD ioctl: plen1 set but NULL pointer\n");
425 if (data->ioc_plen2 && !data->ioc_pbuf2) {
426 printk("OBD ioctl: plen2 set but NULL pointer\n");
430 if (obd_ioctl_packlen(data) != data->ioc_len ) {
431 printk("OBD ioctl: packlen exceeds ioc_len\n");
434 if (data->ioc_inllen1 &&
435 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
436 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
439 if (data->ioc_inllen2 &&
440 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
441 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
448 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
452 struct obd_ioctl_data *overlay;
453 data->ioc_len = obd_ioctl_packlen(data);
454 data->ioc_version = OBD_IOCTL_VERSION;
456 if (*pbuf && obd_ioctl_packlen(data) > max)
459 *pbuf = malloc(data->ioc_len);
463 overlay = (struct obd_ioctl_data *)*pbuf;
464 memcpy(*pbuf, data, sizeof(*data));
466 ptr = overlay->ioc_bulk;
467 if (data->ioc_inlbuf1)
468 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
469 if (data->ioc_inlbuf2)
470 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
471 if (obd_ioctl_is_invalid(overlay))
479 /* buffer MUST be at least the size of obd_ioctl_hdr */
480 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
482 struct obd_ioctl_hdr *hdr;
483 struct obd_ioctl_data *data;
487 hdr = (struct obd_ioctl_hdr *)buf;
488 data = (struct obd_ioctl_data *)buf;
490 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
496 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
497 printk("OBD: version mismatch kernel vs application\n");
501 if (hdr->ioc_len + buf >= end) {
502 printk("OBD: user buffer exceeds kernel buffer\n");
507 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
508 printk("OBD: user buffer too small for ioctl\n");
512 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
518 if (obd_ioctl_is_invalid(data)) {
519 printk("OBD: ioctl not correctly formatted\n");
523 if (data->ioc_inllen1) {
524 data->ioc_inlbuf1 = &data->ioc_bulk[0];
527 if (data->ioc_inllen2) {
528 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
537 #define OBD_IOC_CREATE _IOR ('f', 3, long)
538 #define OBD_IOC_SETUP _IOW ('f', 4, long)
539 #define OBD_IOC_CLEANUP _IO ('f', 5 )
540 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
541 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
542 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
543 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
544 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
545 #define OBD_IOC_READ _IOWR('f', 11, long)
546 #define OBD_IOC_WRITE _IOWR('f', 12, long)
547 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
548 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
549 #define OBD_IOC_STATFS _IOWR('f', 15, long)
550 #define OBD_IOC_SYNC _IOR ('f', 16, long)
551 #define OBD_IOC_READ2 _IOWR('f', 17, long)
552 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
553 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
554 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
555 #define OBD_IOC_DETACH _IOWR('f', 21, long)
556 #define OBD_IOC_COPY _IOWR('f', 22, long)
557 #define OBD_IOC_MIGR _IOWR('f', 23, long)
558 #define OBD_IOC_PUNCH _IOWR('f', 24, long)
559 #define OBD_IOC_DEVICE _IOWR('f', 25, long)
560 #define OBD_IOC_MODULE_DEBUG _IOWR('f', 26, long)
561 #define OBD_IOC_BRW_READ _IOWR('f', 27, long)
562 #define OBD_IOC_BRW_WRITE _IOWR('f', 28, long)
563 #define OBD_IOC_NAME2DEV _IOWR('f', 29, long)
564 #define OBD_IOC_NEWDEV _IOWR('f', 30, long)
566 #define OBD_RECOVD_NEWCONN _IOWR('f', 31, long)
568 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )