1 #ifndef __LINUX_CLASS_OBD_H
2 #define __LINUX_CLASS_OBD_H
4 * Copyright (C) 2001 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
13 #include <linux/list.h>
16 #include <asm/segment.h>
17 #include <asm/uaccess.h>
18 #include <linux/types.h>
20 #include <linux/time.h>
21 #include <linux/obd.h>
23 #include <linux/obd_ext2.h>
24 #include <linux/obd_filter.h>
25 #include <linux/obd_snap.h>
26 #include <linux/obd_trace.h>
27 /* #include <linux/obd_fc.h> */
28 #include <linux/obd_raid1.h>
29 #include <linux/obd_rpc.h>
34 * ======== OBD type Declarations ===========
36 #define MIN(a,b) (((a)<(b)) ? (a): (b))
37 #define MAX(a,b) (((a)>(b)) ? (a): (b))
38 #define MKSTR(ptr) ((ptr))? (ptr) : ""
40 static inline int size_round(int val)
42 return (val + 3) & (~0x3);
45 static inline size_t round_strlen(char *str)
47 return size_round(strlen(str) + 1);
51 static inline char *strdup(char *str)
53 char *tmp = kmalloc(strlen(str) + 1, GFP_KERNEL);
55 memcpy(tmp, str, strlen(str) + 1);
61 * copy sizeof(type) bytes from pointer to var and move ptr forward.
62 * return EFAULT if pointer goes beyond end
64 #define UNLOGV(var,type,ptr,end) do {var = *(type *)ptr; ptr += sizeof(type); if (ptr > end ) return -EFAULT;} while (0)
67 /* the following two macros convert to little endian */
68 /* type must be 32 or 64 */
69 #define LUNLOGV(var,type,ptr,end) \
71 var = le_to_cpu##type(*(type *)ptr); \
72 ptr += sizeof(type); \
78 #define LOGV(var,type,ptr) \
80 *((type *)ptr) = var; \
81 ptr += sizeof(type); \
84 /* and in network order */
85 #define LLOGV(var,type,ptr) \
87 *((type *)ptr) = cpu_to_le##type(var); \
88 ptr += sizeof(type); \
92 * set var to point at (type *)ptr, move ptr forward with sizeof(type)
93 * return from function with EFAULT if ptr goes beyond end
95 #define UNLOGP(var,type,ptr,end) do {var = (type *)ptr; ptr += sizeof(type); if (ptr > end ) return -EFAULT; } while (0)
98 * set var to point at (char *)ptr, move ptr forward by size_round(len);
99 * return from function with EFAULT if ptr goes beyond end
101 #define UNLOGL(var,type,len,ptr,end) do {var = (type *)ptr; ptr += size_round(len * sizeof(type)); if (ptr > end ) return -EFAULT; } while (0)
104 #define LOGL(var,len,ptr) do {memcpy((char *)ptr, (const char *)var, len); ptr += size_round(len);} while (0)
106 typedef uint64_t obd_id;
107 typedef uint64_t obd_gr;
108 typedef uint64_t obd_time;
109 typedef uint64_t obd_size;
110 typedef uint64_t obd_off;
111 typedef uint64_t obd_blocks;
112 typedef uint32_t obd_blksize;
113 typedef uint32_t obd_mode;
114 typedef uint32_t obd_uid;
115 typedef uint32_t obd_gid;
116 typedef uint32_t obd_rdev;
117 typedef uint32_t obd_flag;
118 typedef uint32_t obd_count;
122 #define OBD_FL_INLINEDATA (0x00000001UL)
123 #define OBD_FL_OBDMDEXISTS (0x00000002UL)
125 #define OBD_INLINESZ 60
126 #define OBD_OBDMDSZ 60
127 /* Note: 64-bit types are 64-bit aligned in structure */
136 obd_blksize o_blksize;
143 obd_count o_generation;
144 obd_flag o_valid; /* hot fields in this obdo */
145 char o_inline[OBD_INLINESZ];
146 char o_obdmd[OBD_OBDMDSZ];
147 struct list_head o_list;
148 struct obd_ops *o_op;
152 struct obd_ioctl_data {
154 uint32_t ioc_version;
157 struct obdo ioc_obdo1;
158 struct obdo ioc_obdo2;
163 /* buffers the kernel will treat as user pointers */
169 /* two inline buffers */
170 uint32_t ioc_inllen1;
172 uint32_t ioc_inllen2;
178 #define OBD_MD_FLALL (~0UL)
179 #define OBD_MD_FLID (0x00000001UL)
180 #define OBD_MD_FLATIME (0x00000002UL)
181 #define OBD_MD_FLMTIME (0x00000004UL)
182 #define OBD_MD_FLCTIME (0x00000008UL)
183 #define OBD_MD_FLSIZE (0x00000010UL)
184 #define OBD_MD_FLBLOCKS (0x00000020UL)
185 #define OBD_MD_FLBLKSZ (0x00000040UL)
186 #define OBD_MD_FLMODE (0x00000080UL)
187 #define OBD_MD_FLTYPE (0x00000100UL)
188 #define OBD_MD_FLUID (0x00000200UL)
189 #define OBD_MD_FLGID (0x00000400UL)
190 #define OBD_MD_FLFLAGS (0x00000800UL)
191 #define OBD_MD_FLOBDFLG (0x00001000UL)
192 #define OBD_MD_FLNLINK (0x00002000UL)
193 #define OBD_MD_FLGENER (0x00004000UL)
194 #define OBD_MD_FLINLINE (0x00008000UL)
195 #define OBD_MD_FLOBDMD (0x00010000UL)
196 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS))
199 * ======== OBD Device Declarations ===========
203 #define OBD_PSDEV_MAJOR 186
204 #define MAX_OBD_DEVICES 8
208 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
211 #define OBD_ATTACHED 0x1
212 #define OBD_SET_UP 0x2
215 struct obd_device *oc_dev;
222 struct dentry *dentry; /* file system obd device names */
223 __u8 _uuid[16]; /* uuid obd device names */
228 /* corresponds to one of the obdx */
230 struct obd_type *obd_type;
234 obd_devicename obd_fsname;
235 struct proc_dir_entry *obd_proc_entry;
237 struct obd_conn obd_multi_conn[MAX_MULTI];
238 unsigned int obd_gen_last_id;
239 unsigned long obd_gen_prealloc_quota;
240 struct list_head obd_gen_clients;
242 struct ext2_obd ext2;
243 struct filter_obd filter;
244 struct raid1_obd raid1;
245 struct snap_obd snap;
246 struct trace_obd trace;
247 /* struct fc_obd fc; */
251 extern struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd);
252 extern void proc_lustre_release_obd_device(struct obd_device *obd);
253 extern void proc_lustre_remove_obd_entry(const char* name, struct obd_device *obd);
256 * ======== OBD Operations Declarations ===========
259 #define OBD_BRW_READ (READ)
260 #define OBD_BRW_WRITE (WRITE)
261 #define OBD_BRW_RWMASK (READ | WRITE)
262 #define OBD_BRW_CREATE (0x00000010UL)
265 int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg,
267 int (*o_get_info)(struct obd_conn *, obd_count keylen, void *key,
268 obd_count *vallen, void **val);
269 int (*o_set_info)(struct obd_conn *, obd_count keylen, void *key,
270 obd_count vallen, void *val);
271 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
272 int (*o_detach)(struct obd_device *dev);
273 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
274 int (*o_cleanup)(struct obd_device *dev);
275 int (*o_connect)(struct obd_conn *conn);
276 int (*o_disconnect)(struct obd_conn *conn);
277 int (*o_statfs)(struct obd_conn *conn, struct statfs *statfs);
278 int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids);
279 int (*o_create)(struct obd_conn *conn, struct obdo *oa);
280 int (*o_destroy)(struct obd_conn *conn, struct obdo *oa);
281 int (*o_setattr)(struct obd_conn *conn, struct obdo *oa);
282 int (*o_getattr)(struct obd_conn *conn, struct obdo *oa);
283 int (*o_read)(struct obd_conn *conn, struct obdo *oa, char *buf,
284 obd_size *count, obd_off offset);
285 int (*o_write)(struct obd_conn *conn, struct obdo *oa, char *buf,
286 obd_size *count, obd_off offset);
287 int (*o_brw)(int rw, struct obd_conn *conn, obd_count num_oa,
288 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
289 obd_size *count, obd_off *offset, obd_flag *flags);
290 int (*o_punch)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
292 int (*o_sync)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
294 int (*o_migrate)(struct obd_conn *conn, struct obdo *dst,
295 struct obdo *src, obd_size count, obd_off offset);
296 int (*o_copy)(struct obd_conn *dstconn, struct obdo *dst,
297 struct obd_conn *srconn, struct obdo *src,
298 obd_size count, obd_off offset);
299 int (*o_iterate)(struct obd_conn *conn, int (*)(obd_id, obd_gr, void *),
300 obd_id *startid, obd_gr group, void *data);
303 #define OBT(dev) dev->obd_type->typ_ops
304 #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op
308 /* This value is not arbitrarily chosen. KIO_STATIC_PAGES from linux/iobuf.h */
309 #define MAX_IOVEC (KIO_STATIC_PAGES - 1)
313 * ======== OBD Metadata Support ===========
316 extern int obd_init_obdo_cache(void);
317 extern void obd_cleanup_obdo_cache(void);
320 static inline int obdo_has_inline(struct obdo *obdo)
322 return (obdo->o_valid & OBD_MD_FLINLINE &&
323 obdo->o_obdflags & OBD_FL_INLINEDATA);
326 static inline int obdo_has_obdmd(struct obdo *obdo)
328 return (obdo->o_valid & OBD_MD_FLOBDMD &&
329 obdo->o_obdflags & OBD_FL_OBDMDEXISTS);
333 /* support routines */
334 extern kmem_cache_t *obdo_cachep;
336 static __inline__ struct obdo *obdo_alloc(void)
338 struct obdo *oa = NULL;
340 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
341 memset(oa, 0, sizeof (*oa));
346 static __inline__ void obdo_free(struct obdo *oa)
350 kmem_cache_free(obdo_cachep, oa);
355 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id,
356 obd_mode mode, obd_flag valid)
365 return ERR_PTR(-ENOMEM);
371 if ((err = OBP(conn->oc_dev, getattr)(conn, oa))) {
380 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
382 unsigned int ia_valid = attr->ia_valid;
384 if (ia_valid & ATTR_ATIME) {
385 oa->o_atime = attr->ia_atime;
386 oa->o_valid |= OBD_MD_FLATIME;
388 if (ia_valid & ATTR_MTIME) {
389 oa->o_mtime = attr->ia_mtime;
390 oa->o_valid |= OBD_MD_FLMTIME;
392 if (ia_valid & ATTR_CTIME) {
393 oa->o_ctime = attr->ia_ctime;
394 oa->o_valid |= OBD_MD_FLCTIME;
396 if (ia_valid & ATTR_SIZE) {
397 oa->o_size = attr->ia_size;
398 oa->o_valid |= OBD_MD_FLSIZE;
400 if (ia_valid & ATTR_MODE) {
401 oa->o_mode = attr->ia_mode;
402 oa->o_valid |= OBD_MD_FLMODE;
403 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
404 oa->o_mode &= ~S_ISGID;
406 if (ia_valid & ATTR_UID)
408 oa->o_uid = attr->ia_uid;
409 oa->o_valid |= OBD_MD_FLUID;
411 if (ia_valid & ATTR_GID) {
412 oa->o_gid = attr->ia_gid;
413 oa->o_valid |= OBD_MD_FLGID;
418 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa)
420 unsigned int ia_valid = oa->o_valid;
422 memset(attr, 0, sizeof(*attr));
423 if (ia_valid & OBD_MD_FLATIME) {
424 attr->ia_atime = oa->o_atime;
425 attr->ia_valid |= ATTR_ATIME;
427 if (ia_valid & OBD_MD_FLMTIME) {
428 attr->ia_mtime = oa->o_mtime;
429 attr->ia_valid |= ATTR_MTIME;
431 if (ia_valid & OBD_MD_FLCTIME) {
432 attr->ia_ctime = oa->o_ctime;
433 attr->ia_valid |= ATTR_CTIME;
435 if (ia_valid & OBD_MD_FLSIZE) {
436 attr->ia_size = oa->o_size;
437 attr->ia_valid |= ATTR_SIZE;
439 if (ia_valid & OBD_MD_FLMODE) {
440 attr->ia_mode = oa->o_mode;
441 attr->ia_valid |= ATTR_MODE;
442 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
443 attr->ia_mode &= ~S_ISGID;
445 if (ia_valid & OBD_MD_FLUID)
447 attr->ia_uid = oa->o_uid;
448 attr->ia_valid |= ATTR_UID;
450 if (ia_valid & OBD_MD_FLGID) {
451 attr->ia_gid = oa->o_gid;
452 attr->ia_valid |= ATTR_GID;
457 /* WARNING: the file systems must take care not to tinker with
458 attributes they don't manage (such as blocks). */
460 static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src)
462 if ( dst->o_valid & OBD_MD_FLID )
463 dst->o_id = src->i_ino;
464 if ( dst->o_valid & OBD_MD_FLATIME )
465 dst->o_atime = src->i_atime;
466 if ( dst->o_valid & OBD_MD_FLMTIME )
467 dst->o_mtime = src->i_mtime;
468 if ( dst->o_valid & OBD_MD_FLCTIME )
469 dst->o_ctime = src->i_ctime;
470 if ( dst->o_valid & OBD_MD_FLSIZE )
471 dst->o_size = src->i_size;
472 if ( dst->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
473 dst->o_blocks = src->i_blocks;
474 if ( dst->o_valid & OBD_MD_FLBLKSZ )
475 dst->o_blksize = src->i_blksize;
476 if ( dst->o_valid & OBD_MD_FLMODE )
477 dst->o_mode = src->i_mode;
478 if ( dst->o_valid & OBD_MD_FLUID )
479 dst->o_uid = src->i_uid;
480 if ( dst->o_valid & OBD_MD_FLGID )
481 dst->o_gid = src->i_gid;
482 if ( dst->o_valid & OBD_MD_FLFLAGS )
483 dst->o_flags = src->i_flags;
484 if ( dst->o_valid & OBD_MD_FLNLINK )
485 dst->o_nlink = src->i_nlink;
486 if ( dst->o_valid & OBD_MD_FLGENER )
487 dst->o_generation = src->i_generation;
490 static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src)
493 if ( src->o_valid & OBD_MD_FLID )
494 dst->i_ino = src->o_id;
495 if ( src->o_valid & OBD_MD_FLATIME )
496 dst->i_atime = src->o_atime;
497 if ( src->o_valid & OBD_MD_FLMTIME )
498 dst->i_mtime = src->o_mtime;
499 if ( src->o_valid & OBD_MD_FLCTIME )
500 dst->i_ctime = src->o_ctime;
501 if ( src->o_valid & OBD_MD_FLSIZE )
502 dst->i_size = src->o_size;
503 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
504 dst->i_blocks = src->o_blocks;
505 if ( src->o_valid & OBD_MD_FLBLKSZ )
506 dst->i_blksize = src->o_blksize;
507 if ( src->o_valid & OBD_MD_FLMODE )
508 dst->i_mode = src->o_mode;
509 if ( src->o_valid & OBD_MD_FLUID )
510 dst->i_uid = src->o_uid;
511 if ( src->o_valid & OBD_MD_FLGID )
512 dst->i_gid = src->o_gid;
513 if ( src->o_valid & OBD_MD_FLFLAGS )
514 dst->i_flags = src->o_flags;
515 if ( src->o_valid & OBD_MD_FLNLINK )
516 dst->i_nlink = src->o_nlink;
517 if ( src->o_valid & OBD_MD_FLGENER )
518 dst->i_generation = src->o_generation;
523 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
526 CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
527 src->o_id, src->o_valid, dst->o_id);
529 if ( src->o_valid & OBD_MD_FLATIME )
530 dst->o_atime = src->o_atime;
531 if ( src->o_valid & OBD_MD_FLMTIME )
532 dst->o_mtime = src->o_mtime;
533 if ( src->o_valid & OBD_MD_FLCTIME )
534 dst->o_ctime = src->o_ctime;
535 if ( src->o_valid & OBD_MD_FLSIZE )
536 dst->o_size = src->o_size;
537 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
538 dst->o_blocks = src->o_blocks;
539 if ( src->o_valid & OBD_MD_FLBLKSZ )
540 dst->o_blksize = src->o_blksize;
541 if ( src->o_valid & OBD_MD_FLMODE )
542 dst->o_mode = src->o_mode;
543 if ( src->o_valid & OBD_MD_FLUID )
544 dst->o_uid = src->o_uid;
545 if ( src->o_valid & OBD_MD_FLGID )
546 dst->o_gid = src->o_gid;
547 if ( src->o_valid & OBD_MD_FLFLAGS )
548 dst->o_flags = src->o_flags;
550 if ( src->o_valid & OBD_MD_FLOBDFLG )
551 dst->o_obdflags = src->o_obdflags;
553 if ( src->o_valid & OBD_MD_FLNLINK )
554 dst->o_nlink = src->o_nlink;
555 if ( src->o_valid & OBD_MD_FLGENER )
556 dst->o_generation = src->o_generation;
557 if ( src->o_valid & OBD_MD_FLINLINE &&
558 src->o_obdflags & OBD_FL_INLINEDATA) {
559 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
560 dst->o_obdflags |= OBD_FL_INLINEDATA;
562 if ( src->o_valid & OBD_MD_FLOBDMD &&
563 src->o_obdflags & OBD_FL_OBDMDEXISTS) {
564 memcpy(dst->o_obdmd, src->o_obdmd, sizeof(src->o_obdmd));
565 dst->o_obdflags |= OBD_FL_OBDMDEXISTS;
568 dst->o_valid |= src->o_valid;
572 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
573 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src,
578 if ( compare & OBD_MD_FLATIME )
579 res = (res || (dst->o_atime != src->o_atime));
580 if ( compare & OBD_MD_FLMTIME )
581 res = (res || (dst->o_mtime != src->o_mtime));
582 if ( compare & OBD_MD_FLCTIME )
583 res = (res || (dst->o_ctime != src->o_ctime));
584 if ( compare & OBD_MD_FLSIZE )
585 res = (res || (dst->o_size != src->o_size));
586 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
587 res = (res || (dst->o_blocks != src->o_blocks));
588 if ( compare & OBD_MD_FLBLKSZ )
589 res = (res || (dst->o_blksize != src->o_blksize));
590 if ( compare & OBD_MD_FLMODE )
591 res = (res || (dst->o_mode != src->o_mode));
592 if ( compare & OBD_MD_FLUID )
593 res = (res || (dst->o_uid != src->o_uid));
594 if ( compare & OBD_MD_FLGID )
595 res = (res || (dst->o_gid != src->o_gid));
596 if ( compare & OBD_MD_FLFLAGS )
597 res = (res || (dst->o_flags != src->o_flags));
598 if ( compare & OBD_MD_FLNLINK )
599 res = (res || (dst->o_nlink != src->o_nlink));
600 if ( compare & OBD_MD_FLGENER )
601 res = (res || (dst->o_generation != src->o_generation));
602 /* XXX Don't know if thses should be included here - wasn't previously
603 if ( compare & OBD_MD_FLINLINE )
604 res = (res || memcmp(dst->o_inline, src->o_inline));
605 if ( compare & OBD_MD_FLOBDMD )
606 res = (res || memcmp(dst->o_obdmd, src->o_obdmd));
613 int obd_register_type(struct obd_ops *ops, char *nm);
614 int obd_unregister_type(char *nm);
617 struct list_head cli_chain;
618 struct obd_device *cli_obd;
620 unsigned long cli_prealloc_quota;
621 struct list_head cli_prealloc_inodes;
625 struct obd_prealloc_inode {
626 struct list_head obd_prealloc_chain;
630 /* generic operations shared by various OBD types */
631 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
632 int gen_multi_cleanup(struct obd_device *obddev);
633 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
634 int gen_multi_detach(struct obd_device *obddev);
635 int gen_connect (struct obd_conn *conn);
636 int gen_disconnect(struct obd_conn *conn);
637 struct obd_client *gen_client(const struct obd_conn *);
638 int gen_cleanup(struct obd_device *obddev);
639 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
640 struct obd_conn *src_conn, struct obdo *src,
641 obd_size count, obd_off offset);
646 * ======== OBD IOCL Declarations ===========
649 #define OBD_IOCTL_VERSION 0x00010001
651 struct obd_ioctl_hdr {
653 uint32_t ioc_version;
656 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
658 int len = sizeof(struct obd_ioctl_data);
659 len += size_round(data->ioc_inllen1);
660 len += size_round(data->ioc_inllen2);
664 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
666 if (data->ioc_len > (1<<30)) {
667 printk("OBD ioctl: ioc_len larger than 1<<30\n");
670 if (data->ioc_inllen1 > (1<<30)) {
671 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
674 if (data->ioc_inllen2 > (1<<30)) {
675 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
678 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
679 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
682 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
683 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
686 if (data->ioc_pbuf1 && !data->ioc_plen1) {
687 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
690 if (data->ioc_pbuf2 && !data->ioc_plen2) {
691 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
694 if (obd_ioctl_packlen(data) != data->ioc_len ) {
695 printk("OBD ioctl: packlen exceeds ioc_len\n");
698 if (data->ioc_inllen1 &&
699 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
700 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
703 if (data->ioc_inllen2 &&
704 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
705 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
712 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max)
715 struct obd_ioctl_data *overlay;
716 data->ioc_len = obd_ioctl_packlen(data);
717 data->ioc_version = OBD_IOCTL_VERSION;
719 if (*pbuf && obd_ioctl_packlen(data) > max)
722 *pbuf = malloc(data->ioc_len);
726 overlay = (struct obd_ioctl_data *)*pbuf;
727 memcpy(*pbuf, data, sizeof(*data));
729 ptr = overlay->ioc_bulk;
730 if (data->ioc_inlbuf1)
731 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
732 if (data->ioc_inlbuf2)
733 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
734 if (obd_ioctl_is_invalid(overlay))
742 /* buffer MUST be at least the size of obd_ioctl_hdr */
743 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
745 struct obd_ioctl_hdr *hdr;
746 struct obd_ioctl_data *data;
750 hdr = (struct obd_ioctl_hdr *)buf;
751 data = (struct obd_ioctl_data *)buf;
753 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
759 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
760 printk("OBD: version mismatch kernel vs application\n");
764 if (hdr->ioc_len + buf >= end) {
765 printk("OBD: user buffer exceeds kernel buffer\n");
770 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
771 printk("OBD: user buffer too small for ioctl\n");
775 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
781 if (obd_ioctl_is_invalid(data)) {
782 printk("OBD: ioctl not correctly formatted\n");
786 if (data->ioc_inllen1) {
787 data->ioc_inlbuf1 = &data->ioc_bulk[0];
790 if (data->ioc_inllen2) {
791 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
800 #define OBD_IOC_CREATE _IOR ('f', 3, long)
801 #define OBD_IOC_SETUP _IOW ('f', 4, long)
802 #define OBD_IOC_CLEANUP _IO ('f', 5 )
803 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
804 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
805 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
806 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
807 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
808 #define OBD_IOC_READ _IOWR('f', 11, long)
809 #define OBD_IOC_WRITE _IOWR('f', 12, long)
810 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
811 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
812 #define OBD_IOC_STATFS _IOWR('f', 15, long)
813 #define OBD_IOC_SYNC _IOR ('f', 16, long)
814 #define OBD_IOC_READ2 _IOWR('f', 17, long)
815 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
816 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
817 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
818 #define OBD_IOC_DETACH _IOWR('f', 21, long)
819 #define OBD_IOC_COPY _IOWR('f', 22, long)
820 #define OBD_IOC_MIGR _IOWR('f', 23, long)
821 #define OBD_IOC_PUNCH _IOWR('f', 24, long)
822 #define OBD_IOC_DEVICE _IOWR('f', 25, long)
824 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )
828 extern void obd_sysctl_init (void);
829 extern void obd_sysctl_clean (void);
831 #define CHKCONN(conn) do { if (!gen_client(conn)) {\
832 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
834 return -EINVAL; }} while (0)
838 #endif /* __LINUX_CLASS_OBD_H */