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
49 typedef __u8 uuid_t[37];
53 #define PTL_RPC_MSG_REQUEST 4711
54 #define PTL_RPC_MSG_ERR 4712
56 #define PTLRPC_MSG_MAGIC (cpu_to_le32(0x0BD00BD0))
57 #define PTLRPC_MSG_VERSION (cpu_to_le32(0x00040001))
59 struct lustre_handle {
66 __u64 cookie; /* security token */
79 #define N_LOCAL_TEMP_PAGE 0x00000001
82 * OST requests: OBDO & OBD request records
91 #define OST_GET_INFO 6
93 #define OST_DISCONNECT 8
100 typedef uint64_t obd_id;
101 typedef uint64_t obd_gr;
102 typedef uint64_t obd_time;
103 typedef uint64_t obd_size;
104 typedef uint64_t obd_off;
105 typedef uint64_t obd_blocks;
106 typedef uint32_t obd_blksize;
107 typedef uint32_t obd_mode;
108 typedef uint32_t obd_uid;
109 typedef uint32_t obd_gid;
110 typedef uint32_t obd_rdev;
111 typedef uint32_t obd_flag;
112 typedef uint32_t obd_count;
114 #define OBD_FL_INLINEDATA (0x00000001)
115 #define OBD_FL_OBDMDEXISTS (0x00000002)
116 #define OBD_FL_CREATEONOPEN (0x00000004)
118 #define OBD_INLINESZ 60
119 #define OBD_OBDMDSZ 60
120 /* Note: 64-bit types are 64-bit aligned in structure */
129 obd_blksize o_blksize;
135 obd_count o_generation;
137 obd_flag o_valid; /* hot fields in this obdo */
139 char o_inline[OBD_INLINESZ];
142 #define OBD_MD_FLALL (0xffffffff)
143 #define OBD_MD_FLID (0x00000001)
144 #define OBD_MD_FLATIME (0x00000002)
145 #define OBD_MD_FLMTIME (0x00000004)
146 #define OBD_MD_FLCTIME (0x00000008)
147 #define OBD_MD_FLSIZE (0x00000010)
148 #define OBD_MD_FLBLOCKS (0x00000020)
149 #define OBD_MD_FLBLKSZ (0x00000040)
150 #define OBD_MD_FLMODE (0x00000080)
151 #define OBD_MD_FLTYPE (0x00000100)
152 #define OBD_MD_FLUID (0x00000200)
153 #define OBD_MD_FLGID (0x00000400)
154 #define OBD_MD_FLFLAGS (0x00000800)
155 #define OBD_MD_FLOBDFLG (0x00001000)
156 #define OBD_MD_FLNLINK (0x00002000)
157 #define OBD_MD_FLGENER (0x00004000)
158 #define OBD_MD_FLINLINE (0x00008000)
159 #define OBD_MD_FLOBDMD (0x00010000)
160 #define OBD_MD_FLOBJID (0x00020000)
161 #define OBD_MD_LINKNAME (0x00040000)
162 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS |\
185 struct niobuf_remote {
192 struct niobuf_local {
199 void *target_private;
200 struct dentry *dentry;
203 /* request structure for OST's */
205 #define OST_REQ_HAS_OA1 0x1
218 #define MDS_GETATTR 1
222 #define MDS_READPAGE 6
223 #define MDS_CONNECT 7
224 #define MDS_DISCONNECT 8
225 #define MDS_GETSTATUS 9
226 #define MDS_STATFS 10
227 #define MDS_LOVINFO 11
229 #define REINT_SETATTR 1
230 #define REINT_CREATE 2
232 #define REINT_UNLINK 4
233 #define REINT_RENAME 5
234 #define REINT_RECREATE 6
244 #define MDS_STATUS_CONN 1
245 #define MDS_STATUS_LOV 2
247 struct mds_status_req {
252 struct mds_conn_status {
253 struct ll_fid rootfid;
255 __u64 last_committed;
257 /* XXX preallocated quota & obj fields here */
281 /* MDS update records */
282 struct mds_update_record_hdr {
286 struct mds_rec_setattr {
288 struct ll_fid sa_fid;
300 struct mds_rec_create {
302 struct ll_fid cr_fid;
310 struct mds_rec_link {
312 struct ll_fid lk_fid1;
313 struct ll_fid lk_fid2;
316 struct mds_rec_unlink {
318 struct ll_fid ul_fid1;
319 struct ll_fid ul_fid2;
322 struct mds_rec_rename {
324 struct ll_fid rn_fid1;
325 struct ll_fid rn_fid2;
330 * LOV data structures
335 __u32 ld_tgt_count; /* how many OBD's */
336 __u32 ld_default_stripecount;
337 __u32 ld_default_stripesize; /* in bytes */
338 __u32 ld_pattern; /* RAID 0,1 etc */
347 #define LDLM_ENQUEUE 1
348 #define LDLM_CONVERT 2
349 #define LDLM_CANCEL 3
350 #define LDLM_CALLBACK 4
352 #define RES_NAME_SIZE 3
353 #define RES_VERSION_SIZE 4
374 struct ldlm_resource_desc {
376 __u64 lr_name[RES_NAME_SIZE];
377 __u64 lr_version[RES_VERSION_SIZE];
380 struct ldlm_lock_desc {
381 struct ldlm_resource_desc l_resource;
382 ldlm_mode_t l_req_mode;
383 ldlm_mode_t l_granted_mode;
384 struct ldlm_extent l_extent;
385 __u32 l_version[RES_VERSION_SIZE];
388 struct ldlm_request {
390 struct ldlm_lock_desc lock_desc;
391 struct lustre_handle lock_handle1;
392 struct lustre_handle lock_handle2;
397 __u64 lock_resource_name[3];
398 struct lustre_handle lock_handle;
399 struct ldlm_extent lock_extent; /* XXX make this policy 1 &2 */
400 __u64 lock_policy_res1;
401 __u64 lock_policy_res2;
407 #define OBD_IOCTL_VERSION 0x00010001
409 struct obd_ioctl_data {
411 uint32_t ioc_version;
418 struct obdo ioc_obdo1;
419 struct obdo ioc_obdo2;
424 uint32_t ____padding;
426 /* buffers the kernel will treat as user pointers */
432 /* two inline buffers */
433 uint32_t ioc_inllen1;
435 uint32_t ioc_inllen2;
437 uint32_t ioc_inllen3;
443 struct obd_ioctl_hdr {
445 uint32_t ioc_version;
448 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
450 int len = size_round(sizeof(struct obd_ioctl_data));
451 len += size_round(data->ioc_inllen1);
452 len += size_round(data->ioc_inllen2);
453 len += size_round(data->ioc_inllen3);
458 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
460 if (data->ioc_len > (1<<30)) {
461 printk("OBD ioctl: ioc_len larger than 1<<30\n");
464 if (data->ioc_inllen1 > (1<<30)) {
465 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
468 if (data->ioc_inllen2 > (1<<30)) {
469 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
473 if (data->ioc_inllen3 > (1<<30)) {
474 printk("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
477 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
478 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
481 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
482 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
485 if (data->ioc_inlbuf3 && !data->ioc_inllen3) {
486 printk("OBD ioctl: inlbuf3 pointer but 0 length\n");
489 if (data->ioc_pbuf1 && !data->ioc_plen1) {
490 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
493 if (data->ioc_pbuf2 && !data->ioc_plen2) {
494 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
498 if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
499 printk("OBD ioctl: inllen1 set but NULL pointer\n");
502 if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
503 printk("OBD ioctl: inllen2 set but NULL pointer\n");
506 if (data->ioc_inllen3 && !data->ioc_inlbuf3) {
507 printk("OBD ioctl: inllen3 set but NULL pointer\n");
511 if (data->ioc_plen1 && !data->ioc_pbuf1) {
512 printk("OBD ioctl: plen1 set but NULL pointer\n");
515 if (data->ioc_plen2 && !data->ioc_pbuf2) {
516 printk("OBD ioctl: plen2 set but NULL pointer\n");
519 if (obd_ioctl_packlen(data) != data->ioc_len ) {
520 printk("OBD ioctl: packlen exceeds ioc_len\n");
524 if (data->ioc_inllen1 &&
525 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
526 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
529 if (data->ioc_inllen2 &&
530 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
531 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
534 if (data->ioc_inllen3 &&
535 data->ioc_bulk[size_round(data->ioc_inllen1) + size_round(data->ioc_inllen2)
536 + data->ioc_inllen3 - 1] != '\0') {
537 printk("OBD ioctl: inlbuf3 not 0 terminated\n");
545 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
549 struct obd_ioctl_data *overlay;
550 data->ioc_len = obd_ioctl_packlen(data);
551 data->ioc_version = OBD_IOCTL_VERSION;
553 if (*pbuf && obd_ioctl_packlen(data) > max)
556 *pbuf = malloc(data->ioc_len);
560 overlay = (struct obd_ioctl_data *)*pbuf;
561 memcpy(*pbuf, data, sizeof(*data));
563 ptr = overlay->ioc_bulk;
564 if (data->ioc_inlbuf1)
565 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
566 if (data->ioc_inlbuf2)
567 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
568 if (data->ioc_inlbuf3)
569 LOGL(data->ioc_inlbuf3, data->ioc_inllen3, ptr);
570 if (obd_ioctl_is_invalid(overlay))
578 /* buffer MUST be at least the size of obd_ioctl_hdr */
579 static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
581 struct obd_ioctl_hdr hdr;
582 struct obd_ioctl_data *data;
587 err = copy_from_user(&hdr, (void *)arg, sizeof(hdr));
593 if (hdr.ioc_version != OBD_IOCTL_VERSION) {
594 printk("OBD: version mismatch kernel vs application\n");
598 if (hdr.ioc_len > *len) {
599 printk("OBD: user buffer exceeds kernel buffer\n");
603 if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
604 printk("OBD: user buffer too small for ioctl\n");
608 OBD_ALLOC(*buf, hdr.ioc_len);
610 CERROR("Cannot allocate control buffer of len %d\n",
615 data = (struct obd_ioctl_data *)*buf;
617 err = copy_from_user(*buf, (void *)arg, hdr.ioc_len);
623 if (obd_ioctl_is_invalid(data)) {
624 printk("OBD: ioctl not correctly formatted\n");
628 if (data->ioc_inllen1) {
629 data->ioc_inlbuf1 = &data->ioc_bulk[0];
632 if (data->ioc_inllen2) {
633 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
636 if (data->ioc_inllen3) {
637 data->ioc_inlbuf3 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1) +
638 size_round(data->ioc_inllen2);
647 #define OBD_IOC_CREATE _IOR ('f', 101, long)
648 #define OBD_IOC_SETUP _IOW ('f', 102, long)
649 #define OBD_IOC_CLEANUP _IO ('f', 103 )
650 #define OBD_IOC_DESTROY _IOW ('f', 104, long)
651 #define OBD_IOC_PREALLOCATE _IOWR('f', 105, long)
652 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 106 )
653 #define OBD_IOC_SETATTR _IOW ('f', 107, long)
654 #define OBD_IOC_GETATTR _IOR ('f', 108, long)
655 #define OBD_IOC_READ _IOWR('f', 109, long)
656 #define OBD_IOC_WRITE _IOWR('f', 110, long)
657 #define OBD_IOC_CONNECT _IOR ('f', 111, long)
658 #define OBD_IOC_DISCONNECT _IOW ('f', 112, long)
659 #define OBD_IOC_STATFS _IOWR('f', 113, long)
660 #define OBD_IOC_SYNC _IOR ('f', 114, long)
661 #define OBD_IOC_READ2 _IOWR('f', 115, long)
662 #define OBD_IOC_FORMAT _IOWR('f', 116, long)
663 #define OBD_IOC_PARTITION _IOWR('f', 117, long)
664 #define OBD_IOC_ATTACH _IOWR('f', 118, long)
665 #define OBD_IOC_DETACH _IOWR('f', 119, long)
666 #define OBD_IOC_COPY _IOWR('f', 120, long)
667 #define OBD_IOC_MIGR _IOWR('f', 121, long)
668 #define OBD_IOC_PUNCH _IOWR('f', 122, long)
669 #define OBD_IOC_DEVICE _IOWR('f', 123, long)
670 #define OBD_IOC_MODULE_DEBUG _IOWR('f', 124, long)
671 #define OBD_IOC_BRW_READ _IOWR('f', 125, long)
672 #define OBD_IOC_BRW_WRITE _IOWR('f', 126, long)
673 #define OBD_IOC_NAME2DEV _IOWR('f', 127, long)
674 #define OBD_IOC_NEWDEV _IOWR('f', 128, long)
675 #define OBD_IOC_LIST _IOWR('f', 129, long)
676 #define OBD_IOC_UUID2DEV _IOWR('f', 130, long)
678 #define OBD_IOC_RECOVD_NEWCONN _IOWR('f', 131, long)
679 #define OBD_IOC_LOV_CONFIG _IOWR('f', 132, long)
681 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 133 )