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
48 struct lustre_handle {
54 __u64 conn; /* pointer to ptlrpc_connection */
55 __u64 token; /* security token */
68 #define N_LOCAL_TEMP_PAGE 0x00000001
71 * OST requests: OBDO & OBD request records
80 #define OST_GET_INFO 6
82 #define OST_DISCONNECT 8
89 typedef uint64_t obd_id;
90 typedef uint64_t obd_gr;
91 typedef uint64_t obd_time;
92 typedef uint64_t obd_size;
93 typedef uint64_t obd_off;
94 typedef uint64_t obd_blocks;
95 typedef uint32_t obd_blksize;
96 typedef uint32_t obd_mode;
97 typedef uint32_t obd_uid;
98 typedef uint32_t obd_gid;
99 typedef uint32_t obd_rdev;
100 typedef uint32_t obd_flag;
101 typedef uint32_t obd_count;
103 #define OBD_FL_INLINEDATA (0x00000001)
104 #define OBD_FL_OBDMDEXISTS (0x00000002)
105 #define OBD_FL_CREATEONOPEN (0x00000004)
107 #define OBD_INLINESZ 60
108 #define OBD_OBDMDSZ 60
109 /* Note: 64-bit types are 64-bit aligned in structure */
118 obd_blksize o_blksize;
125 obd_count o_generation;
126 obd_flag o_valid; /* hot fields in this obdo */
127 char o_inline[OBD_INLINESZ];
128 char o_obdmd[OBD_OBDMDSZ];
129 struct list_head o_list;
130 struct obd_ops *o_op;
133 #define OBD_MD_FLALL 0xffffffff
134 #define OBD_MD_FLID (0x00000001)
135 #define OBD_MD_FLATIME (0x00000002)
136 #define OBD_MD_FLMTIME (0x00000004)
137 #define OBD_MD_FLCTIME (0x00000008)
138 #define OBD_MD_FLSIZE (0x00000010)
139 #define OBD_MD_FLBLOCKS (0x00000020)
140 #define OBD_MD_FLBLKSZ (0x00000040)
141 #define OBD_MD_FLMODE (0x00000080)
142 #define OBD_MD_FLTYPE (0x00000100)
143 #define OBD_MD_FLUID (0x00000200)
144 #define OBD_MD_FLGID (0x00000400)
145 #define OBD_MD_FLFLAGS (0x00000800)
146 #define OBD_MD_FLOBDFLG (0x00001000)
147 #define OBD_MD_FLNLINK (0x00002000)
148 #define OBD_MD_FLGENER (0x00004000)
149 #define OBD_MD_FLINLINE (0x00008000)
150 #define OBD_MD_FLOBDMD (0x00010000)
151 #define OBD_MD_FLOBJID (0x00020000)
152 #define OBD_MD_LINKNAME (0x00040000)
153 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS |\
163 struct niobuf_remote {
170 struct niobuf_local {
177 void *target_private;
178 struct dentry *dentry;
181 /* request structure for OST's */
183 #define OST_REQ_HAS_OA1 0x1
196 #define MDS_GETATTR 1
200 #define MDS_READPAGE 6
201 #define MDS_CONNECT 7
202 #define MDS_DISCONNECT 8
203 #define MDS_GETSTATUS 9
204 #define MDS_STATFS 10
206 #define REINT_SETATTR 1
207 #define REINT_CREATE 2
209 #define REINT_UNLINK 4
210 #define REINT_RENAME 5
211 #define REINT_RECREATE 6
241 /* MDS update records */
242 struct mds_update_record_hdr {
246 struct mds_rec_setattr {
248 struct ll_fid sa_fid;
260 struct mds_rec_create {
262 struct ll_fid cr_fid;
270 struct mds_rec_link {
272 struct ll_fid lk_fid1;
273 struct ll_fid lk_fid2;
276 struct mds_rec_unlink {
278 struct ll_fid ul_fid1;
279 struct ll_fid ul_fid2;
282 struct mds_rec_rename {
284 struct ll_fid rn_fid1;
285 struct ll_fid rn_fid2;
294 #define LDLM_ENQUEUE 1
295 #define LDLM_CONVERT 2
296 #define LDLM_CANCEL 3
297 #define LDLM_CALLBACK 4
299 #define RES_NAME_SIZE 3
300 #define RES_VERSION_SIZE 4
321 struct ldlm_resource_desc {
323 __u64 lr_name[RES_NAME_SIZE];
324 __u64 lr_version[RES_VERSION_SIZE];
327 struct ldlm_lock_desc {
328 struct ldlm_resource_desc l_resource;
329 ldlm_mode_t l_req_mode;
330 ldlm_mode_t l_granted_mode;
331 struct ldlm_extent l_extent;
332 __u32 l_version[RES_VERSION_SIZE];
335 struct ldlm_request {
337 struct ldlm_lock_desc lock_desc;
338 struct lustre_handle lock_handle1;
339 struct lustre_handle lock_handle2;
344 __u64 lock_resource_name[3];
345 struct lustre_handle lock_handle;
346 struct ldlm_extent lock_extent; /* XXX make this policy 1 &2 */
347 __u64 lock_policy_res1;
348 __u64 lock_policy_res2;
354 #define OBD_IOCTL_VERSION 0x00010001
356 struct obd_ioctl_data {
358 uint32_t ioc_version;
361 struct obdo ioc_obdo1;
362 struct obdo ioc_obdo2;
367 /* buffers the kernel will treat as user pointers */
373 /* two inline buffers */
374 uint32_t ioc_inllen1;
376 uint32_t ioc_inllen2;
382 struct obd_ioctl_hdr {
384 uint32_t ioc_version;
387 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
389 int len = sizeof(struct obd_ioctl_data);
390 len += size_round(data->ioc_inllen1);
391 len += size_round(data->ioc_inllen2);
395 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
397 if (data->ioc_len > (1<<30)) {
398 printk("OBD ioctl: ioc_len larger than 1<<30\n");
401 if (data->ioc_inllen1 > (1<<30)) {
402 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
405 if (data->ioc_inllen2 > (1<<30)) {
406 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
409 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
410 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
413 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
414 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
417 if (data->ioc_pbuf1 && !data->ioc_plen1) {
418 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
421 if (data->ioc_pbuf2 && !data->ioc_plen2) {
422 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
426 if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
427 printk("OBD ioctl: inllen1 set but NULL pointer\n");
430 if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
431 printk("OBD ioctl: inllen2 set but NULL pointer\n");
434 if (data->ioc_plen1 && !data->ioc_pbuf1) {
435 printk("OBD ioctl: plen1 set but NULL pointer\n");
438 if (data->ioc_plen2 && !data->ioc_pbuf2) {
439 printk("OBD ioctl: plen2 set but NULL pointer\n");
443 if (obd_ioctl_packlen(data) != data->ioc_len ) {
444 printk("OBD ioctl: packlen exceeds ioc_len\n");
447 if (data->ioc_inllen1 &&
448 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
449 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
452 if (data->ioc_inllen2 &&
453 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
454 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
461 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
465 struct obd_ioctl_data *overlay;
466 data->ioc_len = obd_ioctl_packlen(data);
467 data->ioc_version = OBD_IOCTL_VERSION;
469 if (*pbuf && obd_ioctl_packlen(data) > max)
472 *pbuf = malloc(data->ioc_len);
476 overlay = (struct obd_ioctl_data *)*pbuf;
477 memcpy(*pbuf, data, sizeof(*data));
479 ptr = overlay->ioc_bulk;
480 if (data->ioc_inlbuf1)
481 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
482 if (data->ioc_inlbuf2)
483 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
484 if (obd_ioctl_is_invalid(overlay))
492 /* buffer MUST be at least the size of obd_ioctl_hdr */
493 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
495 struct obd_ioctl_hdr *hdr;
496 struct obd_ioctl_data *data;
500 hdr = (struct obd_ioctl_hdr *)buf;
501 data = (struct obd_ioctl_data *)buf;
503 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
509 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
510 printk("OBD: version mismatch kernel vs application\n");
514 if (hdr->ioc_len + buf >= end) {
515 printk("OBD: user buffer exceeds kernel buffer\n");
520 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
521 printk("OBD: user buffer too small for ioctl\n");
525 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
531 if (obd_ioctl_is_invalid(data)) {
532 printk("OBD: ioctl not correctly formatted\n");
536 if (data->ioc_inllen1) {
537 data->ioc_inlbuf1 = &data->ioc_bulk[0];
540 if (data->ioc_inllen2) {
541 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
550 #define OBD_IOC_CREATE _IOR ('f', 101, long)
551 #define OBD_IOC_SETUP _IOW ('f', 102, long)
552 #define OBD_IOC_CLEANUP _IO ('f', 103 )
553 #define OBD_IOC_DESTROY _IOW ('f', 104, long)
554 #define OBD_IOC_PREALLOCATE _IOWR('f', 105, long)
555 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 106 )
556 #define OBD_IOC_SETATTR _IOW ('f', 107, long)
557 #define OBD_IOC_GETATTR _IOR ('f', 108, long)
558 #define OBD_IOC_READ _IOWR('f', 109, long)
559 #define OBD_IOC_WRITE _IOWR('f', 110, long)
560 #define OBD_IOC_CONNECT _IOR ('f', 111, long)
561 #define OBD_IOC_DISCONNECT _IOW ('f', 112, long)
562 #define OBD_IOC_STATFS _IOWR('f', 113, long)
563 #define OBD_IOC_SYNC _IOR ('f', 114, long)
564 #define OBD_IOC_READ2 _IOWR('f', 115, long)
565 #define OBD_IOC_FORMAT _IOWR('f', 116, long)
566 #define OBD_IOC_PARTITION _IOWR('f', 117, long)
567 #define OBD_IOC_ATTACH _IOWR('f', 118, long)
568 #define OBD_IOC_DETACH _IOWR('f', 119, long)
569 #define OBD_IOC_COPY _IOWR('f', 120, long)
570 #define OBD_IOC_MIGR _IOWR('f', 121, long)
571 #define OBD_IOC_PUNCH _IOWR('f', 122, long)
572 #define OBD_IOC_DEVICE _IOWR('f', 123, long)
573 #define OBD_IOC_MODULE_DEBUG _IOWR('f', 124, long)
574 #define OBD_IOC_BRW_READ _IOWR('f', 125, long)
575 #define OBD_IOC_BRW_WRITE _IOWR('f', 126, long)
576 #define OBD_IOC_NAME2DEV _IOWR('f', 127, long)
577 #define OBD_IOC_NEWDEV _IOWR('f', 128, long)
579 #define OBD_IOC_RECOVD_NEWCONN _IOWR('f', 131, long)
581 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 132 )