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 {
79 struct dentry *dentry;
82 #define N_LOCAL_TEMP_PAGE 0x00000001
85 * OST requests: OBDO & OBD request records
94 #define OST_GET_INFO 6
96 #define OST_DISCONNECT 8
100 #define OST_STATFS 12
103 typedef uint64_t obd_id;
104 typedef uint64_t obd_gr;
105 typedef uint64_t obd_time;
106 typedef uint64_t obd_size;
107 typedef uint64_t obd_off;
108 typedef uint64_t obd_blocks;
109 typedef uint32_t obd_blksize;
110 typedef uint32_t obd_mode;
111 typedef uint32_t obd_uid;
112 typedef uint32_t obd_gid;
113 typedef uint32_t obd_rdev;
114 typedef uint32_t obd_flag;
115 typedef uint32_t obd_count;
117 #define OBD_FL_INLINEDATA (0x00000001UL)
118 #define OBD_FL_OBDMDEXISTS (0x00000002UL)
120 #define OBD_INLINESZ 60
121 #define OBD_OBDMDSZ 60
122 /* Note: 64-bit types are 64-bit aligned in structure */
131 obd_blksize o_blksize;
138 obd_count o_generation;
139 obd_flag o_valid; /* hot fields in this obdo */
140 char o_inline[OBD_INLINESZ];
141 char o_obdmd[OBD_OBDMDSZ];
142 struct list_head o_list;
143 struct obd_ops *o_op;
146 #define OBD_MD_FLALL 0xffffffff
147 #define OBD_MD_FLID (0x00000001)
148 #define OBD_MD_FLATIME (0x00000002)
149 #define OBD_MD_FLMTIME (0x00000004)
150 #define OBD_MD_FLCTIME (0x00000008)
151 #define OBD_MD_FLSIZE (0x00000010)
152 #define OBD_MD_FLBLOCKS (0x00000020)
153 #define OBD_MD_FLBLKSZ (0x00000040)
154 #define OBD_MD_FLMODE (0x00000080)
155 #define OBD_MD_FLTYPE (0x00000100)
156 #define OBD_MD_FLUID (0x00000200)
157 #define OBD_MD_FLGID (0x00000400)
158 #define OBD_MD_FLFLAGS (0x00000800)
159 #define OBD_MD_FLOBDFLG (0x00001000)
160 #define OBD_MD_FLNLINK (0x00002000)
161 #define OBD_MD_FLGENER (0x00004000)
162 #define OBD_MD_FLINLINE (0x00008000)
163 #define OBD_MD_FLOBDMD (0x00010000)
164 #define OBD_MD_FLOBJID (0x00020000)
165 #define OBD_MD_LINKNAME (0x00040000)
166 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS |\
169 /* request structure for OST's */
171 #define OST_REQ_HAS_OA1 0x1
191 #define MDS_GETATTR 1
195 #define MDS_READPAGE 6
196 #define MDS_CONNECT 7
199 #define REINT_SETATTR 1
200 #define REINT_CREATE 2
202 #define REINT_UNLINK 4
203 #define REINT_RENAME 5
204 #define REINT_RECREATE 6
234 /* MDS update records */
235 struct mds_update_record_hdr {
239 struct mds_rec_setattr {
241 struct ll_fid sa_fid;
253 struct mds_rec_create {
255 struct ll_fid cr_fid;
260 /* overloaded: id for create, tgtlen for symlink, rdev for mknod */
264 struct mds_rec_link {
266 struct ll_fid lk_fid1;
267 struct ll_fid lk_fid2;
270 struct mds_rec_unlink {
272 struct ll_fid ul_fid1;
273 struct ll_fid ul_fid2;
276 struct mds_rec_rename {
278 struct ll_fid rn_fid1;
279 struct ll_fid rn_fid2;
288 #define LDLM_ENQUEUE 1
289 #define LDLM_CONVERT 2
290 #define LDLM_CANCEL 3
291 #define LDLM_CALLBACK 4
293 #define RES_NAME_SIZE 3
294 #define RES_VERSION_SIZE 4
316 struct ldlm_resource_desc {
318 __u64 lr_name[RES_NAME_SIZE];
319 __u64 lr_version[RES_VERSION_SIZE];
322 struct ldlm_lock_desc {
323 struct ldlm_resource_desc l_resource;
324 ldlm_mode_t l_req_mode;
325 ldlm_mode_t l_granted_mode;
326 struct ldlm_extent l_extent;
327 __u32 l_version[RES_VERSION_SIZE];
330 struct ldlm_request {
332 struct ldlm_lock_desc lock_desc;
333 struct ldlm_handle lock_handle1;
334 struct ldlm_handle lock_handle2;
339 struct ldlm_handle lock_handle;
340 struct ldlm_extent lock_extent;
348 #define OBD_IOCTL_VERSION 0x00010001
350 struct obd_ioctl_data {
352 uint32_t ioc_version;
355 struct obdo ioc_obdo1;
356 struct obdo ioc_obdo2;
361 /* buffers the kernel will treat as user pointers */
367 /* two inline buffers */
368 uint32_t ioc_inllen1;
370 uint32_t ioc_inllen2;
376 struct obd_ioctl_hdr {
378 uint32_t ioc_version;
381 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
383 int len = sizeof(struct obd_ioctl_data);
384 len += size_round(data->ioc_inllen1);
385 len += size_round(data->ioc_inllen2);
389 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
391 if (data->ioc_len > (1<<30)) {
392 printk("OBD ioctl: ioc_len larger than 1<<30\n");
395 if (data->ioc_inllen1 > (1<<30)) {
396 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
399 if (data->ioc_inllen2 > (1<<30)) {
400 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
403 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
404 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
407 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
408 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
411 if (data->ioc_pbuf1 && !data->ioc_plen1) {
412 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
415 if (data->ioc_pbuf2 && !data->ioc_plen2) {
416 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
420 if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
421 printk("OBD ioctl: inllen1 set but NULL pointer\n");
424 if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
425 printk("OBD ioctl: inllen2 set but NULL pointer\n");
428 if (data->ioc_plen1 && !data->ioc_pbuf1) {
429 printk("OBD ioctl: plen1 set but NULL pointer\n");
432 if (data->ioc_plen2 && !data->ioc_pbuf2) {
433 printk("OBD ioctl: plen2 set but NULL pointer\n");
437 if (obd_ioctl_packlen(data) != data->ioc_len ) {
438 printk("OBD ioctl: packlen exceeds ioc_len\n");
441 if (data->ioc_inllen1 &&
442 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
443 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
446 if (data->ioc_inllen2 &&
447 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
448 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
455 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
459 struct obd_ioctl_data *overlay;
460 data->ioc_len = obd_ioctl_packlen(data);
461 data->ioc_version = OBD_IOCTL_VERSION;
463 if (*pbuf && obd_ioctl_packlen(data) > max)
466 *pbuf = malloc(data->ioc_len);
470 overlay = (struct obd_ioctl_data *)*pbuf;
471 memcpy(*pbuf, data, sizeof(*data));
473 ptr = overlay->ioc_bulk;
474 if (data->ioc_inlbuf1)
475 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
476 if (data->ioc_inlbuf2)
477 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
478 if (obd_ioctl_is_invalid(overlay))
486 /* buffer MUST be at least the size of obd_ioctl_hdr */
487 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
489 struct obd_ioctl_hdr *hdr;
490 struct obd_ioctl_data *data;
494 hdr = (struct obd_ioctl_hdr *)buf;
495 data = (struct obd_ioctl_data *)buf;
497 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
503 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
504 printk("OBD: version mismatch kernel vs application\n");
508 if (hdr->ioc_len + buf >= end) {
509 printk("OBD: user buffer exceeds kernel buffer\n");
514 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
515 printk("OBD: user buffer too small for ioctl\n");
519 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
525 if (obd_ioctl_is_invalid(data)) {
526 printk("OBD: ioctl not correctly formatted\n");
530 if (data->ioc_inllen1) {
531 data->ioc_inlbuf1 = &data->ioc_bulk[0];
534 if (data->ioc_inllen2) {
535 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
544 #define OBD_IOC_CREATE _IOR ('f', 101, long)
545 #define OBD_IOC_SETUP _IOW ('f', 102, long)
546 #define OBD_IOC_CLEANUP _IO ('f', 103 )
547 #define OBD_IOC_DESTROY _IOW ('f', 104, long)
548 #define OBD_IOC_PREALLOCATE _IOWR('f', 105, long)
549 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 106 )
550 #define OBD_IOC_SETATTR _IOW ('f', 107, long)
551 #define OBD_IOC_GETATTR _IOR ('f', 108, long)
552 #define OBD_IOC_READ _IOWR('f', 109, long)
553 #define OBD_IOC_WRITE _IOWR('f', 110, long)
554 #define OBD_IOC_CONNECT _IOR ('f', 111, long)
555 #define OBD_IOC_DISCONNECT _IOW ('f', 112, long)
556 #define OBD_IOC_STATFS _IOWR('f', 113, long)
557 #define OBD_IOC_SYNC _IOR ('f', 114, long)
558 #define OBD_IOC_READ2 _IOWR('f', 115, long)
559 #define OBD_IOC_FORMAT _IOWR('f', 116, long)
560 #define OBD_IOC_PARTITION _IOWR('f', 117, long)
561 #define OBD_IOC_ATTACH _IOWR('f', 118, long)
562 #define OBD_IOC_DETACH _IOWR('f', 119, long)
563 #define OBD_IOC_COPY _IOWR('f', 120, long)
564 #define OBD_IOC_MIGR _IOWR('f', 121, long)
565 #define OBD_IOC_PUNCH _IOWR('f', 122, long)
566 #define OBD_IOC_DEVICE _IOWR('f', 123, long)
567 #define OBD_IOC_MODULE_DEBUG _IOWR('f', 124, long)
568 #define OBD_IOC_BRW_READ _IOWR('f', 125, long)
569 #define OBD_IOC_BRW_WRITE _IOWR('f', 126, long)
570 #define OBD_IOC_NAME2DEV _IOWR('f', 127, long)
571 #define OBD_IOC_NEWDEV _IOWR('f', 128, long)
573 #define OBD_IOC_RECOVD_NEWCONN _IOWR('f', 131, long)
575 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 132 )