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__
27 #include <linux/ioctl.h>
28 #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
76 * OST requests: OBDO & OBD request records
85 #define OST_GET_INFO 6
87 #define OST_DISCONNECT 8
93 typedef uint64_t obd_id;
94 typedef uint64_t obd_gr;
95 typedef uint64_t obd_time;
96 typedef uint64_t obd_size;
97 typedef uint64_t obd_off;
98 typedef uint64_t obd_blocks;
99 typedef uint32_t obd_blksize;
100 typedef uint32_t obd_mode;
101 typedef uint32_t obd_uid;
102 typedef uint32_t obd_gid;
103 typedef uint32_t obd_rdev;
104 typedef uint32_t obd_flag;
105 typedef uint32_t obd_count;
107 #define OBD_FL_INLINEDATA (0x00000001UL)
108 #define OBD_FL_OBDMDEXISTS (0x00000002UL)
110 #define OBD_INLINESZ 60
111 #define OBD_OBDMDSZ 60
112 /* Note: 64-bit types are 64-bit aligned in structure */
121 obd_blksize o_blksize;
128 obd_count o_generation;
129 obd_flag o_valid; /* hot fields in this obdo */
130 char o_inline[OBD_INLINESZ];
131 char o_obdmd[OBD_OBDMDSZ];
132 struct list_head o_list;
133 struct obd_ops *o_op;
136 #define OBD_MD_FLALL (~0UL)
137 #define OBD_MD_FLID (0x00000001UL)
138 #define OBD_MD_FLATIME (0x00000002UL)
139 #define OBD_MD_FLMTIME (0x00000004UL)
140 #define OBD_MD_FLCTIME (0x00000008UL)
141 #define OBD_MD_FLSIZE (0x00000010UL)
142 #define OBD_MD_FLBLOCKS (0x00000020UL)
143 #define OBD_MD_FLBLKSZ (0x00000040UL)
144 #define OBD_MD_FLMODE (0x00000080UL)
145 #define OBD_MD_FLTYPE (0x00000100UL)
146 #define OBD_MD_FLUID (0x00000200UL)
147 #define OBD_MD_FLGID (0x00000400UL)
148 #define OBD_MD_FLFLAGS (0x00000800UL)
149 #define OBD_MD_FLOBDFLG (0x00001000UL)
150 #define OBD_MD_FLNLINK (0x00002000UL)
151 #define OBD_MD_FLGENER (0x00004000UL)
152 #define OBD_MD_FLINLINE (0x00008000UL)
153 #define OBD_MD_FLOBDMD (0x00010000UL)
154 #define OBD_MD_FLOBJID (0x00020000UL)
155 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS))
157 /* request structure for OST's */
159 #define OST_REQ_HAS_OA1 0x1
189 #define MDS_GETATTR 1
193 #define MDS_READPAGE 5
195 #define REINT_SETATTR 0
196 #define REINT_CREATE 1
198 #define REINT_UNLINK 3
199 #define REINT_RENAME 4
262 /* MDS update records */
263 struct mds_update_record_hdr {
268 struct mds_rec_setattr {
271 struct ll_fid sa_fid;
283 struct mds_rec_create {
286 struct ll_fid cr_fid;
291 /* overloaded: id for create, tgtlen for symlink, rdev for mknod */
296 /* symlink target here */
299 struct mds_rec_link {
302 struct ll_fid lk_fid1;
303 struct ll_fid lk_fid2;
307 struct mds_rec_unlink {
310 struct ll_fid ul_fid1;
311 struct ll_fid ul_fid2;
315 struct mds_rec_rename {
318 struct ll_fid rn_fid1;
319 struct ll_fid rn_fid2;
326 static inline void ll_ino2fid(struct ll_fid *fid, ino_t ino, __u32 generation,
329 fid->id = HTON__u64((__u64)ino);
330 fid->generation = HTON__u32(generation);
331 fid->f_type = HTON__u32(type);
334 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
336 ll_ino2fid(fid, inode->i_ino, inode->i_generation,
337 inode->i_mode & S_IFMT);
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
375 struct ldlm_request {
377 __u64 res_id[RES_NAME_SIZE];
380 struct ldlm_extent lock_extent;
381 struct ldlm_handle parent_res_handle;
382 struct ldlm_handle parent_lock_handle;
387 struct ldlm_handle lock_handle;
395 #define OBD_IOCTL_VERSION 0x00010001
397 struct obd_ioctl_data {
399 uint32_t ioc_version;
402 struct obdo ioc_obdo1;
403 struct obdo ioc_obdo2;
408 /* buffers the kernel will treat as user pointers */
414 /* two inline buffers */
415 uint32_t ioc_inllen1;
417 uint32_t ioc_inllen2;
423 struct obd_ioctl_hdr {
425 uint32_t ioc_version;
428 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
430 int len = sizeof(struct obd_ioctl_data);
431 len += size_round(data->ioc_inllen1);
432 len += size_round(data->ioc_inllen2);
436 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
438 if (data->ioc_len > (1<<30)) {
439 printk("OBD ioctl: ioc_len larger than 1<<30\n");
442 if (data->ioc_inllen1 > (1<<30)) {
443 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
446 if (data->ioc_inllen2 > (1<<30)) {
447 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
450 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
451 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
454 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
455 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
458 if (data->ioc_pbuf1 && !data->ioc_plen1) {
459 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
462 if (data->ioc_pbuf2 && !data->ioc_plen2) {
463 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
467 if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
468 printk("OBD ioctl: inllen1 set but NULL pointer\n");
471 if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
472 printk("OBD ioctl: inllen2 set but NULL pointer\n");
475 if (data->ioc_plen1 && !data->ioc_pbuf1) {
476 printk("OBD ioctl: plen1 set but NULL pointer\n");
479 if (data->ioc_plen2 && !data->ioc_pbuf2) {
480 printk("OBD ioctl: plen2 set but NULL pointer\n");
484 if (obd_ioctl_packlen(data) != data->ioc_len ) {
485 printk("OBD ioctl: packlen exceeds ioc_len\n");
488 if (data->ioc_inllen1 &&
489 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
490 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
493 if (data->ioc_inllen2 &&
494 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
495 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
502 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
506 struct obd_ioctl_data *overlay;
507 data->ioc_len = obd_ioctl_packlen(data);
508 data->ioc_version = OBD_IOCTL_VERSION;
510 if (*pbuf && obd_ioctl_packlen(data) > max)
513 *pbuf = malloc(data->ioc_len);
517 overlay = (struct obd_ioctl_data *)*pbuf;
518 memcpy(*pbuf, data, sizeof(*data));
520 ptr = overlay->ioc_bulk;
521 if (data->ioc_inlbuf1)
522 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
523 if (data->ioc_inlbuf2)
524 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
525 if (obd_ioctl_is_invalid(overlay))
533 /* buffer MUST be at least the size of obd_ioctl_hdr */
534 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
536 struct obd_ioctl_hdr *hdr;
537 struct obd_ioctl_data *data;
541 hdr = (struct obd_ioctl_hdr *)buf;
542 data = (struct obd_ioctl_data *)buf;
544 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
550 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
551 printk("OBD: version mismatch kernel vs application\n");
555 if (hdr->ioc_len + buf >= end) {
556 printk("OBD: user buffer exceeds kernel buffer\n");
561 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
562 printk("OBD: user buffer too small for ioctl\n");
566 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
572 if (obd_ioctl_is_invalid(data)) {
573 printk("OBD: ioctl not correctly formatted\n");
577 if (data->ioc_inllen1) {
578 data->ioc_inlbuf1 = &data->ioc_bulk[0];
581 if (data->ioc_inllen2) {
582 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
591 #define OBD_IOC_CREATE _IOR ('f', 3, long)
592 #define OBD_IOC_SETUP _IOW ('f', 4, long)
593 #define OBD_IOC_CLEANUP _IO ('f', 5 )
594 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
595 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
596 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
597 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
598 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
599 #define OBD_IOC_READ _IOWR('f', 11, long)
600 #define OBD_IOC_WRITE _IOWR('f', 12, long)
601 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
602 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
603 #define OBD_IOC_STATFS _IOWR('f', 15, long)
604 #define OBD_IOC_SYNC _IOR ('f', 16, long)
605 #define OBD_IOC_READ2 _IOWR('f', 17, long)
606 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
607 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
608 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
609 #define OBD_IOC_DETACH _IOWR('f', 21, long)
610 #define OBD_IOC_COPY _IOWR('f', 22, long)
611 #define OBD_IOC_MIGR _IOWR('f', 23, long)
612 #define OBD_IOC_PUNCH _IOWR('f', 24, long)
613 #define OBD_IOC_DEVICE _IOWR('f', 25, long)
614 #define OBD_IOC_MODULE_DEBUG _IOWR('f', 26, long)
615 #define OBD_IOC_BRW_READ _IOWR('f', 27, long)
616 #define OBD_IOC_BRW_WRITE _IOWR('f', 28, long)
618 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )
625 struct lustre_msg *lustre;
631 struct lustre_msg *lustre;