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>
31 # include <linux/list.h>
34 # include <linux/list.h>
39 * this file contains all data structures used in Lustre interfaces:
40 * - obdo and obd_request records
41 * - mds_request records
46 #define PTL_RPC_MSG_REQUEST 4711
47 #define PTL_RPC_MSG_ERR 4712
49 struct lustre_handle {
56 __u64 cookie; /* security token */
57 __u64 conn2; /* pointer to ptlrpc_connection: should go */
70 #define N_LOCAL_TEMP_PAGE 0x00000001
73 * OST requests: OBDO & OBD request records
82 #define OST_GET_INFO 6
84 #define OST_DISCONNECT 8
91 typedef uint64_t obd_id;
92 typedef uint64_t obd_gr;
93 typedef uint64_t obd_time;
94 typedef uint64_t obd_size;
95 typedef uint64_t obd_off;
96 typedef uint64_t obd_blocks;
97 typedef uint32_t obd_blksize;
98 typedef uint32_t obd_mode;
99 typedef uint32_t obd_uid;
100 typedef uint32_t obd_gid;
101 typedef uint32_t obd_rdev;
102 typedef uint32_t obd_flag;
103 typedef uint32_t obd_count;
105 #define OBD_FL_INLINEDATA (0x00000001)
106 #define OBD_FL_OBDMDEXISTS (0x00000002)
107 #define OBD_FL_CREATEONOPEN (0x00000004)
109 #define OBD_INLINESZ 60
110 #define OBD_OBDMDSZ 60
111 /* Note: 64-bit types are 64-bit aligned in structure */
120 obd_blksize o_blksize;
127 obd_count o_generation;
128 obd_flag o_valid; /* hot fields in this obdo */
129 char o_inline[OBD_INLINESZ];
130 char o_obdmd[OBD_OBDMDSZ];
131 struct list_head o_list;
132 struct obd_ops *o_op;
135 #define OBD_MD_FLALL (0xffffffff)
136 #define OBD_MD_FLID (0x00000001)
137 #define OBD_MD_FLATIME (0x00000002)
138 #define OBD_MD_FLMTIME (0x00000004)
139 #define OBD_MD_FLCTIME (0x00000008)
140 #define OBD_MD_FLSIZE (0x00000010)
141 #define OBD_MD_FLBLOCKS (0x00000020)
142 #define OBD_MD_FLBLKSZ (0x00000040)
143 #define OBD_MD_FLMODE (0x00000080)
144 #define OBD_MD_FLTYPE (0x00000100)
145 #define OBD_MD_FLUID (0x00000200)
146 #define OBD_MD_FLGID (0x00000400)
147 #define OBD_MD_FLFLAGS (0x00000800)
148 #define OBD_MD_FLOBDFLG (0x00001000)
149 #define OBD_MD_FLNLINK (0x00002000)
150 #define OBD_MD_FLGENER (0x00004000)
151 #define OBD_MD_FLINLINE (0x00008000)
152 #define OBD_MD_FLOBDMD (0x00010000)
153 #define OBD_MD_FLOBJID (0x00020000)
154 #define OBD_MD_LINKNAME (0x00040000)
155 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS |\
178 struct niobuf_remote {
185 struct niobuf_local {
192 void *target_private;
193 struct dentry *dentry;
196 /* request structure for OST's */
198 #define OST_REQ_HAS_OA1 0x1
211 #define MDS_GETATTR 1
215 #define MDS_READPAGE 6
216 #define MDS_CONNECT 7
217 #define MDS_DISCONNECT 8
218 #define MDS_GETSTATUS 9
219 #define MDS_STATFS 10
221 #define REINT_SETATTR 1
222 #define REINT_CREATE 2
224 #define REINT_UNLINK 4
225 #define REINT_RENAME 5
226 #define REINT_RECREATE 6
256 /* MDS update records */
257 struct mds_update_record_hdr {
261 struct mds_rec_setattr {
263 struct ll_fid sa_fid;
275 struct mds_rec_create {
277 struct ll_fid cr_fid;
285 struct mds_rec_link {
287 struct ll_fid lk_fid1;
288 struct ll_fid lk_fid2;
291 struct mds_rec_unlink {
293 struct ll_fid ul_fid1;
294 struct ll_fid ul_fid2;
297 struct mds_rec_rename {
299 struct ll_fid rn_fid1;
300 struct ll_fid rn_fid2;
309 #define LDLM_ENQUEUE 1
310 #define LDLM_CONVERT 2
311 #define LDLM_CANCEL 3
312 #define LDLM_CALLBACK 4
314 #define RES_NAME_SIZE 3
315 #define RES_VERSION_SIZE 4
336 struct ldlm_resource_desc {
338 __u64 lr_name[RES_NAME_SIZE];
339 __u64 lr_version[RES_VERSION_SIZE];
342 struct ldlm_lock_desc {
343 struct ldlm_resource_desc l_resource;
344 ldlm_mode_t l_req_mode;
345 ldlm_mode_t l_granted_mode;
346 struct ldlm_extent l_extent;
347 __u32 l_version[RES_VERSION_SIZE];
350 struct ldlm_request {
352 struct ldlm_lock_desc lock_desc;
353 struct lustre_handle lock_handle1;
354 struct lustre_handle lock_handle2;
359 __u64 lock_resource_name[3];
360 struct lustre_handle lock_handle;
361 struct ldlm_extent lock_extent; /* XXX make this policy 1 &2 */
362 __u64 lock_policy_res1;
363 __u64 lock_policy_res2;
369 #define OBD_IOCTL_VERSION 0x00010001
371 struct obd_ioctl_data {
373 uint32_t ioc_version;
380 struct obdo ioc_obdo1;
381 struct obdo ioc_obdo2;
386 uint32_t ____padding;
388 /* buffers the kernel will treat as user pointers */
394 /* two inline buffers */
395 uint32_t ioc_inllen1;
397 uint32_t ioc_inllen2;
399 uint32_t ioc_inllen3;
405 struct obd_ioctl_hdr {
407 uint32_t ioc_version;
410 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
412 int len = size_round(sizeof(struct obd_ioctl_data));
413 len += size_round(data->ioc_inllen1);
414 len += size_round(data->ioc_inllen2);
415 len += size_round(data->ioc_inllen3);
419 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
421 if (data->ioc_len > (1<<30)) {
422 printk("OBD ioctl: ioc_len larger than 1<<30\n");
425 if (data->ioc_inllen1 > (1<<30)) {
426 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
429 if (data->ioc_inllen2 > (1<<30)) {
430 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
434 if (data->ioc_inllen3 > (1<<30)) {
435 printk("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
438 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
439 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
442 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
443 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
446 if (data->ioc_inlbuf3 && !data->ioc_inllen3) {
447 printk("OBD ioctl: inlbuf3 pointer but 0 length\n");
450 if (data->ioc_pbuf1 && !data->ioc_plen1) {
451 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
454 if (data->ioc_pbuf2 && !data->ioc_plen2) {
455 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
459 if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
460 printk("OBD ioctl: inllen1 set but NULL pointer\n");
463 if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
464 printk("OBD ioctl: inllen2 set but NULL pointer\n");
467 if (data->ioc_inllen3 && !data->ioc_inlbuf3) {
468 printk("OBD ioctl: inllen3 set but NULL pointer\n");
472 if (data->ioc_plen1 && !data->ioc_pbuf1) {
473 printk("OBD ioctl: plen1 set but NULL pointer\n");
476 if (data->ioc_plen2 && !data->ioc_pbuf2) {
477 printk("OBD ioctl: plen2 set but NULL pointer\n");
480 if (obd_ioctl_packlen(data) != data->ioc_len ) {
481 printk("OBD ioctl: packlen exceeds ioc_len\n");
484 if (data->ioc_inllen1 &&
485 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
486 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
489 if (data->ioc_inllen2 &&
490 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
491 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
494 if (data->ioc_inllen3 &&
495 data->ioc_bulk[size_round(data->ioc_inllen1) + size_round(data->ioc_inllen2)
496 + data->ioc_inllen3 - 1] != '\0') {
497 printk("OBD ioctl: inlbuf3 not 0 terminated\n");
504 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
508 struct obd_ioctl_data *overlay;
509 data->ioc_len = obd_ioctl_packlen(data);
510 data->ioc_version = OBD_IOCTL_VERSION;
512 if (*pbuf && obd_ioctl_packlen(data) > max)
515 *pbuf = malloc(data->ioc_len);
519 overlay = (struct obd_ioctl_data *)*pbuf;
520 memcpy(*pbuf, data, sizeof(*data));
522 ptr = overlay->ioc_bulk;
523 if (data->ioc_inlbuf1)
524 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
525 if (data->ioc_inlbuf2)
526 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
527 if (data->ioc_inlbuf3)
528 LOGL(data->ioc_inlbuf3, data->ioc_inllen3, ptr);
529 if (obd_ioctl_is_invalid(overlay))
537 /* buffer MUST be at least the size of obd_ioctl_hdr */
538 static inline int obd_ioctl_getdata(char *buf, int *len, void *arg)
540 struct obd_ioctl_hdr *hdr;
541 struct obd_ioctl_data *data;
545 hdr = (struct obd_ioctl_hdr *)buf;
546 data = (struct obd_ioctl_data *)buf;
548 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
554 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
555 printk("OBD: version mismatch kernel vs application\n");
559 if (hdr->ioc_len > *len) {
560 printk("OBD: user buffer exceeds kernel buffer\n");
565 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
566 printk("OBD: user buffer too small for ioctl\n");
570 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
576 if (obd_ioctl_is_invalid(data)) {
577 printk("OBD: ioctl not correctly formatted\n");
581 if (data->ioc_inllen1) {
582 data->ioc_inlbuf1 = &data->ioc_bulk[0];
585 if (data->ioc_inllen2) {
586 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
589 if (data->ioc_inllen3) {
590 data->ioc_inlbuf3 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1) +
591 size_round(data->ioc_inllen2);
600 #define OBD_IOC_CREATE _IOR ('f', 101, long)
601 #define OBD_IOC_SETUP _IOW ('f', 102, long)
602 #define OBD_IOC_CLEANUP _IO ('f', 103 )
603 #define OBD_IOC_DESTROY _IOW ('f', 104, long)
604 #define OBD_IOC_PREALLOCATE _IOWR('f', 105, long)
605 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 106 )
606 #define OBD_IOC_SETATTR _IOW ('f', 107, long)
607 #define OBD_IOC_GETATTR _IOR ('f', 108, long)
608 #define OBD_IOC_READ _IOWR('f', 109, long)
609 #define OBD_IOC_WRITE _IOWR('f', 110, long)
610 #define OBD_IOC_CONNECT _IOR ('f', 111, long)
611 #define OBD_IOC_DISCONNECT _IOW ('f', 112, long)
612 #define OBD_IOC_STATFS _IOWR('f', 113, long)
613 #define OBD_IOC_SYNC _IOR ('f', 114, long)
614 #define OBD_IOC_READ2 _IOWR('f', 115, long)
615 #define OBD_IOC_FORMAT _IOWR('f', 116, long)
616 #define OBD_IOC_PARTITION _IOWR('f', 117, long)
617 #define OBD_IOC_ATTACH _IOWR('f', 118, long)
618 #define OBD_IOC_DETACH _IOWR('f', 119, long)
619 #define OBD_IOC_COPY _IOWR('f', 120, long)
620 #define OBD_IOC_MIGR _IOWR('f', 121, long)
621 #define OBD_IOC_PUNCH _IOWR('f', 122, long)
622 #define OBD_IOC_DEVICE _IOWR('f', 123, long)
623 #define OBD_IOC_MODULE_DEBUG _IOWR('f', 124, long)
624 #define OBD_IOC_BRW_READ _IOWR('f', 125, long)
625 #define OBD_IOC_BRW_WRITE _IOWR('f', 126, long)
626 #define OBD_IOC_NAME2DEV _IOWR('f', 127, long)
627 #define OBD_IOC_NEWDEV _IOWR('f', 128, long)
628 #define OBD_IOC_LIST _IOWR('f', 129, long)
629 #define OBD_IOC_UUID2DEV _IOWR('f', 130, long)
631 #define OBD_IOC_RECOVD_NEWCONN _IOWR('f', 131, long)
633 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 132 )