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_FLUID (0x00000100UL)
188 #define OBD_MD_FLGID (0x00000200UL)
189 #define OBD_MD_FLFLAGS (0x00000400UL)
190 #define OBD_MD_FLOBDFLG (0x00000800UL)
191 #define OBD_MD_FLNLINK (0x00001000UL)
192 #define OBD_MD_FLGENER (0x00002000UL)
193 #define OBD_MD_FLINLINE (0x00004000UL)
194 #define OBD_MD_FLOBDMD (0x00008000UL)
195 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS))
198 * ======== OBD Device Declarations ===========
202 #define OBD_PSDEV_MAJOR 186
203 #define MAX_OBD_DEVICES 8
207 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
210 #define OBD_ATTACHED 0x1
211 #define OBD_SET_UP 0x2
214 struct obd_device *oc_dev;
221 struct dentry *dentry; /* file system obd device names */
222 __u8 _uuid[16]; /* uuid obd device names */
227 /* corresponds to one of the obdx */
229 struct obd_type *obd_type;
233 obd_devicename obd_fsname;
234 struct proc_dir_entry *obd_proc_entry;
236 struct obd_conn obd_multi_conn[MAX_MULTI];
237 unsigned int obd_gen_last_id;
238 unsigned long obd_gen_prealloc_quota;
239 struct list_head obd_gen_clients;
241 struct ext2_obd ext2;
242 struct filter_obd filter;
243 struct raid1_obd raid1;
244 struct snap_obd snap;
245 struct trace_obd trace;
246 /* struct fc_obd fc; */
250 extern struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd);
251 extern void proc_lustre_release_obd_device(struct obd_device *obd);
252 extern void proc_lustre_remove_obd_entry(const char* name, struct obd_device *obd);
255 * ======== OBD Operations Declarations ===========
258 #define OBD_BRW_READ (READ)
259 #define OBD_BRW_WRITE (WRITE)
260 #define OBD_BRW_RWMASK (READ | WRITE)
261 #define OBD_BRW_CREATE (0x00000010UL)
264 int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg,
266 int (*o_get_info)(struct obd_conn *, obd_count keylen, void *key,
267 obd_count *vallen, void **val);
268 int (*o_set_info)(struct obd_conn *, obd_count keylen, void *key,
269 obd_count vallen, void *val);
270 int (*o_attach)(struct obd_device *dev, struct obd_ioctl_data *data);
271 int (*o_detach)(struct obd_device *dev);
272 int (*o_setup) (struct obd_device *dev, struct obd_ioctl_data *data);
273 int (*o_cleanup)(struct obd_device *dev);
274 int (*o_connect)(struct obd_conn *conn);
275 int (*o_disconnect)(struct obd_conn *conn);
276 int (*o_statfs)(struct obd_conn *conn, struct statfs *statfs);
277 int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids);
278 int (*o_create)(struct obd_conn *conn, struct obdo *oa);
279 int (*o_destroy)(struct obd_conn *conn, struct obdo *oa);
280 int (*o_setattr)(struct obd_conn *conn, struct obdo *oa);
281 int (*o_getattr)(struct obd_conn *conn, struct obdo *oa);
282 int (*o_read)(struct obd_conn *conn, struct obdo *oa, char *buf,
283 obd_size *count, obd_off offset);
284 int (*o_write)(struct obd_conn *conn, struct obdo *oa, char *buf,
285 obd_size *count, obd_off offset);
286 int (*o_brw)(int rw, struct obd_conn *conn, obd_count num_oa,
287 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
288 obd_size *count, obd_off *offset, obd_flag *flags);
289 int (*o_punch)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
291 int (*o_sync)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
293 int (*o_migrate)(struct obd_conn *conn, struct obdo *dst,
294 struct obdo *src, obd_size count, obd_off offset);
295 int (*o_copy)(struct obd_conn *dstconn, struct obdo *dst,
296 struct obd_conn *srconn, struct obdo *src,
297 obd_size count, obd_off offset);
298 int (*o_iterate)(struct obd_conn *conn, int (*)(obd_id, obd_gr, void *),
299 obd_id *startid, obd_gr group, void *data);
302 #define OBT(dev) dev->obd_type->typ_ops
303 #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op
307 /* This value is not arbitrarily chosen. KIO_STATIC_PAGES from linux/iobuf.h */
308 #define MAX_IOVEC (KIO_STATIC_PAGES - 1)
312 * ======== OBD Metadata Support ===========
315 extern int obd_init_obdo_cache(void);
316 extern void obd_cleanup_obdo_cache(void);
319 static inline int obdo_has_inline(struct obdo *obdo)
321 return (obdo->o_valid & OBD_MD_FLINLINE &&
322 obdo->o_obdflags & OBD_FL_INLINEDATA);
325 static inline int obdo_has_obdmd(struct obdo *obdo)
327 return (obdo->o_valid & OBD_MD_FLOBDMD &&
328 obdo->o_obdflags & OBD_FL_OBDMDEXISTS);
332 /* support routines */
333 extern kmem_cache_t *obdo_cachep;
335 static __inline__ struct obdo *obdo_alloc(void)
337 struct obdo *oa = NULL;
339 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
340 memset(oa, 0, sizeof (*oa));
345 static __inline__ void obdo_free(struct obdo *oa)
349 kmem_cache_free(obdo_cachep, oa);
354 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id,
364 return ERR_PTR(-ENOMEM);
369 if ((err = OBP(conn->oc_dev, getattr)(conn, oa))) {
378 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
380 unsigned int ia_valid = attr->ia_valid;
382 if (ia_valid & ATTR_ATIME) {
383 oa->o_atime = attr->ia_atime;
384 oa->o_valid |= OBD_MD_FLATIME;
386 if (ia_valid & ATTR_MTIME) {
387 oa->o_mtime = attr->ia_mtime;
388 oa->o_valid |= OBD_MD_FLMTIME;
390 if (ia_valid & ATTR_CTIME) {
391 oa->o_ctime = attr->ia_ctime;
392 oa->o_valid |= OBD_MD_FLCTIME;
394 if (ia_valid & ATTR_SIZE) {
395 oa->o_size = attr->ia_size;
396 oa->o_valid |= OBD_MD_FLSIZE;
398 if (ia_valid & ATTR_MODE) {
399 oa->o_mode = attr->ia_mode;
400 oa->o_valid |= OBD_MD_FLMODE;
401 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
402 oa->o_mode &= ~S_ISGID;
404 if (ia_valid & ATTR_UID)
406 oa->o_uid = attr->ia_uid;
407 oa->o_valid |= OBD_MD_FLUID;
409 if (ia_valid & ATTR_GID) {
410 oa->o_gid = attr->ia_gid;
411 oa->o_valid |= OBD_MD_FLGID;
416 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa)
418 unsigned int ia_valid = oa->o_valid;
420 if (ia_valid & OBD_MD_FLATIME) {
421 attr->ia_atime = oa->o_atime;
422 attr->ia_valid |= ATTR_ATIME;
424 if (ia_valid & OBD_MD_FLMTIME) {
425 attr->ia_mtime = oa->o_mtime;
426 attr->ia_valid |= ATTR_MTIME;
428 if (ia_valid & OBD_MD_FLCTIME) {
429 attr->ia_ctime = oa->o_ctime;
430 attr->ia_valid |= ATTR_CTIME;
432 if (ia_valid & OBD_MD_FLSIZE) {
433 attr->ia_size = oa->o_size;
434 attr->ia_valid |= ATTR_SIZE;
436 if (ia_valid & OBD_MD_FLMODE) {
437 attr->ia_mode = oa->o_mode;
438 attr->ia_valid |= ATTR_MODE;
439 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
440 attr->ia_mode &= ~S_ISGID;
442 if (ia_valid & OBD_MD_FLUID)
444 attr->ia_uid = oa->o_uid;
445 attr->ia_valid |= ATTR_UID;
447 if (ia_valid & OBD_MD_FLGID) {
448 attr->ia_gid = oa->o_gid;
449 attr->ia_valid |= ATTR_GID;
454 /* WARNING: the file systems must take care not to tinker with
455 attributes they don't manage (such as blocks). */
457 static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src)
459 if ( dst->o_valid & OBD_MD_FLID )
460 dst->o_id = src->i_ino;
461 if ( dst->o_valid & OBD_MD_FLATIME )
462 dst->o_atime = src->i_atime;
463 if ( dst->o_valid & OBD_MD_FLMTIME )
464 dst->o_mtime = src->i_mtime;
465 if ( dst->o_valid & OBD_MD_FLCTIME )
466 dst->o_ctime = src->i_ctime;
467 if ( dst->o_valid & OBD_MD_FLSIZE )
468 dst->o_size = src->i_size;
469 if ( dst->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
470 dst->o_blocks = src->i_blocks;
471 if ( dst->o_valid & OBD_MD_FLBLKSZ )
472 dst->o_blksize = src->i_blksize;
473 if ( dst->o_valid & OBD_MD_FLMODE )
474 dst->o_mode = src->i_mode;
475 if ( dst->o_valid & OBD_MD_FLUID )
476 dst->o_uid = src->i_uid;
477 if ( dst->o_valid & OBD_MD_FLGID )
478 dst->o_gid = src->i_gid;
479 if ( dst->o_valid & OBD_MD_FLFLAGS )
480 dst->o_flags = src->i_flags;
481 if ( dst->o_valid & OBD_MD_FLNLINK )
482 dst->o_nlink = src->i_nlink;
483 if ( dst->o_valid & OBD_MD_FLGENER )
484 dst->o_generation = src->i_generation;
487 static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src)
490 if ( src->o_valid & OBD_MD_FLID )
491 dst->i_ino = src->o_id;
492 if ( src->o_valid & OBD_MD_FLATIME )
493 dst->i_atime = src->o_atime;
494 if ( src->o_valid & OBD_MD_FLMTIME )
495 dst->i_mtime = src->o_mtime;
496 if ( src->o_valid & OBD_MD_FLCTIME )
497 dst->i_ctime = src->o_ctime;
498 if ( src->o_valid & OBD_MD_FLSIZE )
499 dst->i_size = src->o_size;
500 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
501 dst->i_blocks = src->o_blocks;
502 if ( src->o_valid & OBD_MD_FLBLKSZ )
503 dst->i_blksize = src->o_blksize;
504 if ( src->o_valid & OBD_MD_FLMODE )
505 dst->i_mode = src->o_mode;
506 if ( src->o_valid & OBD_MD_FLUID )
507 dst->i_uid = src->o_uid;
508 if ( src->o_valid & OBD_MD_FLGID )
509 dst->i_gid = src->o_gid;
510 if ( src->o_valid & OBD_MD_FLFLAGS )
511 dst->i_flags = src->o_flags;
512 if ( src->o_valid & OBD_MD_FLNLINK )
513 dst->i_nlink = src->o_nlink;
514 if ( src->o_valid & OBD_MD_FLGENER )
515 dst->i_generation = src->o_generation;
520 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
523 CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
524 src->o_id, src->o_valid, dst->o_id);
526 if ( src->o_valid & OBD_MD_FLATIME )
527 dst->o_atime = src->o_atime;
528 if ( src->o_valid & OBD_MD_FLMTIME )
529 dst->o_mtime = src->o_mtime;
530 if ( src->o_valid & OBD_MD_FLCTIME )
531 dst->o_ctime = src->o_ctime;
532 if ( src->o_valid & OBD_MD_FLSIZE )
533 dst->o_size = src->o_size;
534 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
535 dst->o_blocks = src->o_blocks;
536 if ( src->o_valid & OBD_MD_FLBLKSZ )
537 dst->o_blksize = src->o_blksize;
538 if ( src->o_valid & OBD_MD_FLMODE )
539 dst->o_mode = src->o_mode;
540 if ( src->o_valid & OBD_MD_FLUID )
541 dst->o_uid = src->o_uid;
542 if ( src->o_valid & OBD_MD_FLGID )
543 dst->o_gid = src->o_gid;
544 if ( src->o_valid & OBD_MD_FLFLAGS )
545 dst->o_flags = src->o_flags;
547 if ( src->o_valid & OBD_MD_FLOBDFLG )
548 dst->o_obdflags = src->o_obdflags;
550 if ( src->o_valid & OBD_MD_FLNLINK )
551 dst->o_nlink = src->o_nlink;
552 if ( src->o_valid & OBD_MD_FLGENER )
553 dst->o_generation = src->o_generation;
554 if ( src->o_valid & OBD_MD_FLINLINE &&
555 src->o_obdflags & OBD_FL_INLINEDATA) {
556 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
557 dst->o_obdflags |= OBD_FL_INLINEDATA;
559 if ( src->o_valid & OBD_MD_FLOBDMD &&
560 src->o_obdflags & OBD_FL_OBDMDEXISTS) {
561 memcpy(dst->o_obdmd, src->o_obdmd, sizeof(src->o_obdmd));
562 dst->o_obdflags |= OBD_FL_OBDMDEXISTS;
565 dst->o_valid |= src->o_valid;
569 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
570 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src,
575 if ( compare & OBD_MD_FLATIME )
576 res = (res || (dst->o_atime != src->o_atime));
577 if ( compare & OBD_MD_FLMTIME )
578 res = (res || (dst->o_mtime != src->o_mtime));
579 if ( compare & OBD_MD_FLCTIME )
580 res = (res || (dst->o_ctime != src->o_ctime));
581 if ( compare & OBD_MD_FLSIZE )
582 res = (res || (dst->o_size != src->o_size));
583 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
584 res = (res || (dst->o_blocks != src->o_blocks));
585 if ( compare & OBD_MD_FLBLKSZ )
586 res = (res || (dst->o_blksize != src->o_blksize));
587 if ( compare & OBD_MD_FLMODE )
588 res = (res || (dst->o_mode != src->o_mode));
589 if ( compare & OBD_MD_FLUID )
590 res = (res || (dst->o_uid != src->o_uid));
591 if ( compare & OBD_MD_FLGID )
592 res = (res || (dst->o_gid != src->o_gid));
593 if ( compare & OBD_MD_FLFLAGS )
594 res = (res || (dst->o_flags != src->o_flags));
595 if ( compare & OBD_MD_FLNLINK )
596 res = (res || (dst->o_nlink != src->o_nlink));
597 if ( compare & OBD_MD_FLGENER )
598 res = (res || (dst->o_generation != src->o_generation));
599 /* XXX Don't know if thses should be included here - wasn't previously
600 if ( compare & OBD_MD_FLINLINE )
601 res = (res || memcmp(dst->o_inline, src->o_inline));
602 if ( compare & OBD_MD_FLOBDMD )
603 res = (res || memcmp(dst->o_obdmd, src->o_obdmd));
610 int obd_register_type(struct obd_ops *ops, char *nm);
611 int obd_unregister_type(char *nm);
614 struct list_head cli_chain;
615 struct obd_device *cli_obd;
617 unsigned long cli_prealloc_quota;
618 struct list_head cli_prealloc_inodes;
622 struct obd_prealloc_inode {
623 struct list_head obd_prealloc_chain;
627 /* generic operations shared by various OBD types */
628 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
629 int gen_multi_cleanup(struct obd_device *obddev);
630 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
631 int gen_multi_detach(struct obd_device *obddev);
632 int gen_connect (struct obd_conn *conn);
633 int gen_disconnect(struct obd_conn *conn);
634 struct obd_client *gen_client(const struct obd_conn *);
635 int gen_cleanup(struct obd_device *obddev);
636 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
637 struct obd_conn *src_conn, struct obdo *src,
638 obd_size count, obd_off offset);
643 * ======== OBD IOCL Declarations ===========
646 #define OBD_IOCTL_VERSION 0x00010001
648 struct obd_ioctl_hdr {
650 uint32_t ioc_version;
653 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
655 int len = sizeof(struct obd_ioctl_data);
656 len += size_round(data->ioc_inllen1);
657 len += size_round(data->ioc_inllen2);
661 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
663 if (data->ioc_len > (1<<30)) {
664 printk("OBD ioctl: ioc_len larger than 1<<30\n");
667 if (data->ioc_inllen1 > (1<<30)) {
668 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
671 if (data->ioc_inllen2 > (1<<30)) {
672 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
675 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
676 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
679 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
680 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
683 if (data->ioc_pbuf1 && !data->ioc_plen1) {
684 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
687 if (data->ioc_pbuf2 && !data->ioc_plen2) {
688 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
691 if (obd_ioctl_packlen(data) != data->ioc_len ) {
692 printk("OBD ioctl: packlen exceeds ioc_len\n");
695 if (data->ioc_inllen1 &&
696 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
697 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
700 if (data->ioc_inllen2 &&
701 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
702 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
709 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max)
712 struct obd_ioctl_data *overlay;
713 data->ioc_len = obd_ioctl_packlen(data);
714 data->ioc_version = OBD_IOCTL_VERSION;
716 if (*pbuf && obd_ioctl_packlen(data) > max)
719 *pbuf = malloc(data->ioc_len);
723 overlay = (struct obd_ioctl_data *)*pbuf;
724 memcpy(*pbuf, data, sizeof(*data));
726 ptr = overlay->ioc_bulk;
727 if (data->ioc_inlbuf1)
728 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
729 if (data->ioc_inlbuf2)
730 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
731 if (obd_ioctl_is_invalid(overlay))
739 /* buffer MUST be at least the size of obd_ioctl_hdr */
740 static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
742 struct obd_ioctl_hdr *hdr;
743 struct obd_ioctl_data *data;
747 hdr = (struct obd_ioctl_hdr *)buf;
748 data = (struct obd_ioctl_data *)buf;
750 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
756 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
757 printk("OBD: version mismatch kernel vs application\n");
761 if (hdr->ioc_len + buf >= end) {
762 printk("OBD: user buffer exceeds kernel buffer\n");
767 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
768 printk("OBD: user buffer too small for ioctl\n");
772 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
778 if (obd_ioctl_is_invalid(data)) {
779 printk("OBD: ioctl not correctly formatted\n");
783 if (data->ioc_inllen1) {
784 data->ioc_inlbuf1 = &data->ioc_bulk[0];
787 if (data->ioc_inllen2) {
788 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
797 #define OBD_IOC_CREATE _IOR ('f', 3, long)
798 #define OBD_IOC_SETUP _IOW ('f', 4, long)
799 #define OBD_IOC_CLEANUP _IO ('f', 5 )
800 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
801 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
802 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
803 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
804 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
805 #define OBD_IOC_READ _IOWR('f', 11, long)
806 #define OBD_IOC_WRITE _IOWR('f', 12, long)
807 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
808 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
809 #define OBD_IOC_STATFS _IOWR('f', 15, long)
810 #define OBD_IOC_SYNC _IOR ('f', 16, long)
811 #define OBD_IOC_READ2 _IOWR('f', 17, long)
812 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
813 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
814 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
815 #define OBD_IOC_DETACH _IOWR('f', 21, long)
816 #define OBD_IOC_COPY _IOWR('f', 22, long)
817 #define OBD_IOC_MIGR _IOWR('f', 23, long)
818 #define OBD_IOC_PUNCH _IOWR('f', 24, long)
819 #define OBD_IOC_DEVICE _IOWR('f', 25, long)
821 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )
825 extern void obd_sysctl_init (void);
826 extern void obd_sysctl_clean (void);
828 #define CHKCONN(conn) do { if (!gen_client(conn)) {\
829 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
831 return -EINVAL; }} while (0)
835 #endif /* __LINUX_CLASS_OBD_H */