1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
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.
23 #ifndef __LINUX_CLASS_OBD_H
24 #define __LINUX_CLASS_OBD_H
29 #include <linux/list.h>
32 #include <asm/segment.h>
33 #include <asm/uaccess.h>
34 #include <linux/types.h>
36 #include <linux/time.h>
38 #include <linux/lustre_lib.h>
39 #include <linux/lustre_idl.h>
40 #include <linux/lustre_net.h>
41 #include <linux/obd.h>
45 * ======== OBD Device Declarations ===========
47 #define MAX_OBD_DEVICES 8
49 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
51 #define OBD_ATTACHED 0x1
52 #define OBD_SET_UP 0x2
55 struct obd_device *oc_dev;
62 struct dentry *dentry; /* file system obd device names */
63 __u8 _uuid[16]; /* uuid obd device names */
66 #include <linux/obd_ext2.h>
67 #include <linux/obd_filter.h>
68 #include <linux/lustre_mds.h>
69 #include <linux/lustre_net.h>
70 #include <linux/obd_snap.h>
71 #include <linux/obd_trace.h>
72 /* #include <linux/obd_fc.h> */
73 #include <linux/obd_raid1.h>
74 #include <linux/obd_ost.h>
75 #include <linux/obd_osc.h>
78 /* corresponds to one of the obd's */
80 struct obd_type *obd_type;
84 obd_devicename obd_fsname;
85 struct proc_dir_entry *obd_proc_entry;
87 struct obd_conn obd_multi_conn[MAX_MULTI];
88 unsigned int obd_gen_last_id;
89 unsigned long obd_gen_prealloc_quota;
90 struct list_head obd_gen_clients;
91 struct list_head obd_req_list;
92 wait_queue_head_t obd_req_waitq;
95 struct filter_obd filter;
97 struct raid1_obd raid1;
99 struct trace_obd trace;
105 extern struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd);
106 extern void proc_lustre_release_obd_device(struct obd_device *obd);
107 extern void proc_lustre_remove_obd_entry(const char* name, struct obd_device *obd);
110 * ======== OBD Operations Declarations ===========
113 #define OBD_BRW_READ 1
114 #define OBD_BRW_WRITE 2
115 #define OBD_BRW_RWMASK OBD_BRW_READ | OBD_BRW_WRITE
116 #define OBD_BRW_CREATE 4
119 int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg,
121 int (*o_get_info)(struct obd_conn *, obd_count keylen, void *key,
122 obd_count *vallen, void **val);
123 int (*o_set_info)(struct obd_conn *, obd_count keylen, void *key,
124 obd_count vallen, void *val);
125 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
126 int (*o_detach)(struct obd_device *dev);
127 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
128 int (*o_cleanup)(struct obd_device *dev);
129 int (*o_connect)(struct obd_conn *conn);
130 int (*o_disconnect)(struct obd_conn *conn);
131 int (*o_statfs)(struct obd_conn *conn, struct statfs *statfs);
132 int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids);
133 int (*o_create)(struct obd_conn *conn, struct obdo *oa);
134 int (*o_destroy)(struct obd_conn *conn, struct obdo *oa);
135 int (*o_setattr)(struct obd_conn *conn, struct obdo *oa);
136 int (*o_getattr)(struct obd_conn *conn, struct obdo *oa);
137 int (*o_read)(struct obd_conn *conn, struct obdo *oa, char *buf,
138 obd_size *count, obd_off offset);
139 int (*o_write)(struct obd_conn *conn, struct obdo *oa, char *buf,
140 obd_size *count, obd_off offset);
141 int (*o_brw)(int rw, struct obd_conn *conn, obd_count num_oa,
142 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
143 obd_size *count, obd_off *offset, obd_flag *flags);
144 int (*o_punch)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
146 int (*o_sync)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
148 int (*o_migrate)(struct obd_conn *conn, struct obdo *dst,
149 struct obdo *src, obd_size count, obd_off offset);
150 int (*o_copy)(struct obd_conn *dstconn, struct obdo *dst,
151 struct obd_conn *srconn, struct obdo *src,
152 obd_size count, obd_off offset);
153 int (*o_iterate)(struct obd_conn *conn, int (*)(obd_id, obd_gr, void *),
154 obd_id *startid, obd_gr group, void *data);
155 int (*o_preprw)(int cmd, struct obd_conn *conn,
156 int objcount, struct obd_ioobj *obj,
157 int niocount, struct niobuf *nb,
159 int (*o_commitrw)(int cmd, struct obd_conn *conn,
160 int objcount, struct obd_ioobj *obj,
161 int niocount, struct niobuf *res);
166 struct obd_conn *conn;
171 static inline int obd_check_conn(struct obd_conn *conn)
173 struct obd_device *obd;
175 printk("obd_check_conn: NULL conn\n");
180 printk("obd_check_conn: NULL obd\n");
184 if (!obd->obd_flags & OBD_ATTACHED ) {
185 printk("obd_check_conn: obd %d not attached\n", obd->obd_minor);
189 if (!obd->obd_flags & OBD_SET_UP) {
190 printk("obd_check_conn: obd %d not setup\n", obd->obd_minor);
194 if (!obd->obd_type) {
195 printk("obd_check_conn: obd %d not typed\n", obd->obd_minor);
199 if (!obd->obd_type->typ_ops) {
200 printk("obd_check_conn: obd %d no operations\n", obd->obd_minor);
206 #define OBT(dev) dev->obd_type->typ_ops
207 #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op
209 #define OBD_CHECK_SETUP(conn) \
212 CERROR("NULL connection\n"); \
216 if (!((conn)->oc_dev)) { \
217 CERROR("NULL device\n"); \
221 if ( !((conn)->oc_dev->obd_flags & OBD_SET_UP) ) { \
222 CERROR("Device %d not setup\n", (conn)->oc_dev->obd_minor); \
227 #define OBD_CHECK_OP(conn,op) \
229 int rc = obd_check_conn(conn); \
231 printk("obd: error in operation: " #op "\n"); \
234 if (!OBP(conn->oc_dev,op)) { \
235 printk("obd_" #op ": dev %d no operation\n", \
236 conn->oc_dev->obd_minor); \
237 return -EOPNOTSUPP; \
241 static inline int obd_get_info(struct obd_conn *conn, obd_count keylen, void *key,
242 obd_count *vallen, void **val)
245 OBD_CHECK_SETUP(conn);
246 OBD_CHECK_OP(conn,get_info);
248 rc = OBP(conn->oc_dev, get_info)(conn, keylen, key, vallen, val);
253 static inline int obd_set_info(struct obd_conn *conn, obd_count keylen, void *key,
254 obd_count vallen, void *val)
257 OBD_CHECK_SETUP(conn);
258 OBD_CHECK_OP(conn,set_info);
260 rc = OBP(conn->oc_dev, set_info)(conn, keylen, key, vallen, val);
265 static inline int obd_cleanup(struct obd_device *obd)
267 struct obd_conn conn;
271 OBD_CHECK_SETUP(&conn);
272 OBD_CHECK_OP((&conn),cleanup);
274 rc = OBP(conn.oc_dev, cleanup)(obd);
279 static inline int obd_create(struct obd_conn *conn, struct obdo *obdo)
282 OBD_CHECK_SETUP(conn);
283 OBD_CHECK_OP(conn,create);
285 rc = OBP(conn->oc_dev, create)(conn, obdo);
290 static inline int obd_destroy(struct obd_conn *conn, struct obdo *obdo)
293 OBD_CHECK_SETUP(conn);
294 OBD_CHECK_OP(conn,destroy);
296 rc = OBP(conn->oc_dev, destroy)(conn, obdo);
301 static inline int obd_getattr(struct obd_conn *conn, struct obdo *obdo)
304 OBD_CHECK_SETUP(conn);
305 OBD_CHECK_OP(conn,getattr);
307 rc = OBP(conn->oc_dev, getattr)(conn, obdo);
312 static inline int obd_setattr(struct obd_conn *conn, struct obdo *obdo)
315 OBD_CHECK_SETUP(conn);
316 OBD_CHECK_OP(conn,setattr);
318 rc = OBP(conn->oc_dev, setattr)(conn, obdo);
323 static inline int obd_connect(struct obd_conn *conn)
326 OBD_CHECK_SETUP(conn);
327 OBD_CHECK_OP(conn,connect);
329 rc = OBP(conn->oc_dev, connect)(conn);
334 static inline int obd_disconnect(struct obd_conn *conn)
337 OBD_CHECK_SETUP(conn);
338 OBD_CHECK_OP(conn,disconnect);
340 rc = OBP(conn->oc_dev, disconnect)(conn);
345 static inline int obd_statfs(struct obd_conn *conn, struct statfs *buf)
348 OBD_CHECK_SETUP(conn);
349 OBD_CHECK_OP(conn,statfs);
351 rc = OBP(conn->oc_dev, statfs)(conn, buf);
356 static inline int obd_punch(struct obd_conn *conn, struct obdo *tgt, obd_size count, obd_off offset)
359 OBD_CHECK_SETUP(conn);
360 OBD_CHECK_OP(conn,punch);
362 rc = OBP(conn->oc_dev, punch)(conn, tgt, count, offset);
367 static inline int obd_brw(int rw, struct obd_conn *conn, obd_count num_oa,
368 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
369 obd_size *count, obd_off *offset, obd_flag *flags)
372 OBD_CHECK_SETUP(conn);
373 OBD_CHECK_OP(conn,brw);
375 rc = OBP(conn->oc_dev, brw)(rw, conn, num_oa, oa, oa_bufs, buf,
376 count, offset, flags);
381 static inline int obd_preprw(int cmd, struct obd_conn *conn,
382 int objcount, struct obd_ioobj *obj,
383 int niocount, struct niobuf *nb,
387 OBD_CHECK_SETUP(conn);
388 OBD_CHECK_OP(conn, preprw);
390 rc = OBP(conn->oc_dev, preprw)(cmd, conn, objcount, obj, niocount, nb, res);
395 static inline int obd_commitrw(int cmd, struct obd_conn *conn,
396 int objcount, struct obd_ioobj *obj,
397 int niocount, struct niobuf *res)
400 OBD_CHECK_SETUP(conn);
401 OBD_CHECK_OP(conn, commitrw);
403 rc = OBP(conn->oc_dev, commitrw)(cmd, conn, objcount, obj, niocount, res);
412 * ======== OBD Metadata Support ===========
415 extern int obd_init_obdo_cache(void);
416 extern void obd_cleanup_obdo_cache(void);
419 static inline int obdo_has_inline(struct obdo *obdo)
421 return (obdo->o_valid & OBD_MD_FLINLINE &&
422 obdo->o_obdflags & OBD_FL_INLINEDATA);
425 static inline int obdo_has_obdmd(struct obdo *obdo)
427 return (obdo->o_valid & OBD_MD_FLOBDMD &&
428 obdo->o_obdflags & OBD_FL_OBDMDEXISTS);
432 /* support routines */
433 extern kmem_cache_t *obdo_cachep;
435 static __inline__ struct obdo *obdo_alloc(void)
437 struct obdo *oa = NULL;
439 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
440 memset(oa, 0, sizeof (*oa));
445 static __inline__ void obdo_free(struct obdo *oa)
449 kmem_cache_free(obdo_cachep, oa);
452 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id,
453 obd_mode mode, obd_flag valid)
462 return ERR_PTR(-ENOMEM);
468 if ((err = OBP(conn->oc_dev, getattr)(conn, oa))) {
477 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
479 unsigned int ia_valid = attr->ia_valid;
481 if (ia_valid & ATTR_ATIME) {
482 oa->o_atime = attr->ia_atime;
483 oa->o_valid |= OBD_MD_FLATIME;
485 if (ia_valid & ATTR_MTIME) {
486 oa->o_mtime = attr->ia_mtime;
487 oa->o_valid |= OBD_MD_FLMTIME;
489 if (ia_valid & ATTR_CTIME) {
490 oa->o_ctime = attr->ia_ctime;
491 oa->o_valid |= OBD_MD_FLCTIME;
493 if (ia_valid & ATTR_SIZE) {
494 oa->o_size = attr->ia_size;
495 oa->o_valid |= OBD_MD_FLSIZE;
497 if (ia_valid & ATTR_MODE) {
498 oa->o_mode = attr->ia_mode;
499 oa->o_valid |= OBD_MD_FLMODE;
500 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
501 oa->o_mode &= ~S_ISGID;
503 if (ia_valid & ATTR_UID)
505 oa->o_uid = attr->ia_uid;
506 oa->o_valid |= OBD_MD_FLUID;
508 if (ia_valid & ATTR_GID) {
509 oa->o_gid = attr->ia_gid;
510 oa->o_valid |= OBD_MD_FLGID;
515 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa)
517 unsigned int ia_valid = oa->o_valid;
519 memset(attr, 0, sizeof(*attr));
520 if (ia_valid & OBD_MD_FLATIME) {
521 attr->ia_atime = oa->o_atime;
522 attr->ia_valid |= ATTR_ATIME;
524 if (ia_valid & OBD_MD_FLMTIME) {
525 attr->ia_mtime = oa->o_mtime;
526 attr->ia_valid |= ATTR_MTIME;
528 if (ia_valid & OBD_MD_FLCTIME) {
529 attr->ia_ctime = oa->o_ctime;
530 attr->ia_valid |= ATTR_CTIME;
532 if (ia_valid & OBD_MD_FLSIZE) {
533 attr->ia_size = oa->o_size;
534 attr->ia_valid |= ATTR_SIZE;
536 if (ia_valid & OBD_MD_FLMODE) {
537 attr->ia_mode = oa->o_mode;
538 attr->ia_valid |= ATTR_MODE;
539 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
540 attr->ia_mode &= ~S_ISGID;
542 if (ia_valid & OBD_MD_FLUID)
544 attr->ia_uid = oa->o_uid;
545 attr->ia_valid |= ATTR_UID;
547 if (ia_valid & OBD_MD_FLGID) {
548 attr->ia_gid = oa->o_gid;
549 attr->ia_valid |= ATTR_GID;
554 /* WARNING: the file systems must take care not to tinker with
555 attributes they don't manage (such as blocks). */
557 static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src)
559 if ( dst->o_valid & OBD_MD_FLID )
560 dst->o_id = src->i_ino;
561 if ( dst->o_valid & OBD_MD_FLATIME )
562 dst->o_atime = src->i_atime;
563 if ( dst->o_valid & OBD_MD_FLMTIME )
564 dst->o_mtime = src->i_mtime;
565 if ( dst->o_valid & OBD_MD_FLCTIME )
566 dst->o_ctime = src->i_ctime;
567 if ( dst->o_valid & OBD_MD_FLSIZE )
568 dst->o_size = src->i_size;
569 if ( dst->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
570 dst->o_blocks = src->i_blocks;
571 if ( dst->o_valid & OBD_MD_FLBLKSZ )
572 dst->o_blksize = src->i_blksize;
573 if ( dst->o_valid & OBD_MD_FLMODE )
574 dst->o_mode = src->i_mode;
575 if ( dst->o_valid & OBD_MD_FLUID )
576 dst->o_uid = src->i_uid;
577 if ( dst->o_valid & OBD_MD_FLGID )
578 dst->o_gid = src->i_gid;
579 if ( dst->o_valid & OBD_MD_FLFLAGS )
580 dst->o_flags = src->i_flags;
581 if ( dst->o_valid & OBD_MD_FLNLINK )
582 dst->o_nlink = src->i_nlink;
583 if ( dst->o_valid & OBD_MD_FLGENER )
584 dst->o_generation = src->i_generation;
587 static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src)
590 if ( src->o_valid & OBD_MD_FLID )
591 dst->i_ino = src->o_id;
592 if ( src->o_valid & OBD_MD_FLATIME )
593 dst->i_atime = src->o_atime;
594 if ( src->o_valid & OBD_MD_FLMTIME )
595 dst->i_mtime = src->o_mtime;
596 if ( src->o_valid & OBD_MD_FLCTIME )
597 dst->i_ctime = src->o_ctime;
598 if ( src->o_valid & OBD_MD_FLSIZE )
599 dst->i_size = src->o_size;
600 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
601 dst->i_blocks = src->o_blocks;
602 if ( src->o_valid & OBD_MD_FLBLKSZ )
603 dst->i_blksize = src->o_blksize;
604 if ( src->o_valid & OBD_MD_FLMODE )
605 dst->i_mode = src->o_mode;
606 if ( src->o_valid & OBD_MD_FLUID )
607 dst->i_uid = src->o_uid;
608 if ( src->o_valid & OBD_MD_FLGID )
609 dst->i_gid = src->o_gid;
610 if ( src->o_valid & OBD_MD_FLFLAGS )
611 dst->i_flags = src->o_flags;
612 if ( src->o_valid & OBD_MD_FLNLINK )
613 dst->i_nlink = src->o_nlink;
614 if ( src->o_valid & OBD_MD_FLGENER )
615 dst->i_generation = src->o_generation;
620 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
623 CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
624 src->o_id, src->o_valid, dst->o_id);
626 if ( src->o_valid & OBD_MD_FLATIME )
627 dst->o_atime = src->o_atime;
628 if ( src->o_valid & OBD_MD_FLMTIME )
629 dst->o_mtime = src->o_mtime;
630 if ( src->o_valid & OBD_MD_FLCTIME )
631 dst->o_ctime = src->o_ctime;
632 if ( src->o_valid & OBD_MD_FLSIZE )
633 dst->o_size = src->o_size;
634 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
635 dst->o_blocks = src->o_blocks;
636 if ( src->o_valid & OBD_MD_FLBLKSZ )
637 dst->o_blksize = src->o_blksize;
638 if ( src->o_valid & OBD_MD_FLMODE )
639 dst->o_mode = src->o_mode;
640 if ( src->o_valid & OBD_MD_FLUID )
641 dst->o_uid = src->o_uid;
642 if ( src->o_valid & OBD_MD_FLGID )
643 dst->o_gid = src->o_gid;
644 if ( src->o_valid & OBD_MD_FLFLAGS )
645 dst->o_flags = src->o_flags;
647 if ( src->o_valid & OBD_MD_FLOBDFLG )
648 dst->o_obdflags = src->o_obdflags;
650 if ( src->o_valid & OBD_MD_FLNLINK )
651 dst->o_nlink = src->o_nlink;
652 if ( src->o_valid & OBD_MD_FLGENER )
653 dst->o_generation = src->o_generation;
654 if ( src->o_valid & OBD_MD_FLINLINE &&
655 src->o_obdflags & OBD_FL_INLINEDATA) {
656 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
657 dst->o_obdflags |= OBD_FL_INLINEDATA;
659 if ( src->o_valid & OBD_MD_FLOBDMD &&
660 src->o_obdflags & OBD_FL_OBDMDEXISTS) {
661 memcpy(dst->o_obdmd, src->o_obdmd, sizeof(src->o_obdmd));
662 dst->o_obdflags |= OBD_FL_OBDMDEXISTS;
665 dst->o_valid |= src->o_valid;
669 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
670 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src,
675 if ( compare & OBD_MD_FLATIME )
676 res = (res || (dst->o_atime != src->o_atime));
677 if ( compare & OBD_MD_FLMTIME )
678 res = (res || (dst->o_mtime != src->o_mtime));
679 if ( compare & OBD_MD_FLCTIME )
680 res = (res || (dst->o_ctime != src->o_ctime));
681 if ( compare & OBD_MD_FLSIZE )
682 res = (res || (dst->o_size != src->o_size));
683 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
684 res = (res || (dst->o_blocks != src->o_blocks));
685 if ( compare & OBD_MD_FLBLKSZ )
686 res = (res || (dst->o_blksize != src->o_blksize));
687 if ( compare & OBD_MD_FLMODE )
688 res = (res || (dst->o_mode != src->o_mode));
689 if ( compare & OBD_MD_FLUID )
690 res = (res || (dst->o_uid != src->o_uid));
691 if ( compare & OBD_MD_FLGID )
692 res = (res || (dst->o_gid != src->o_gid));
693 if ( compare & OBD_MD_FLFLAGS )
694 res = (res || (dst->o_flags != src->o_flags));
695 if ( compare & OBD_MD_FLNLINK )
696 res = (res || (dst->o_nlink != src->o_nlink));
697 if ( compare & OBD_MD_FLGENER )
698 res = (res || (dst->o_generation != src->o_generation));
699 /* XXX Don't know if thses should be included here - wasn't previously
700 if ( compare & OBD_MD_FLINLINE )
701 res = (res || memcmp(dst->o_inline, src->o_inline));
702 if ( compare & OBD_MD_FLOBDMD )
703 res = (res || memcmp(dst->o_obdmd, src->o_obdmd));
710 int obd_register_type(struct obd_ops *ops, char *nm);
711 int obd_unregister_type(char *nm);
714 struct list_head cli_chain;
715 struct obd_device *cli_obd;
717 unsigned long cli_prealloc_quota;
718 struct list_head cli_prealloc_inodes;
722 struct obd_prealloc_inode {
723 struct list_head obd_prealloc_chain;
727 /* generic operations shared by various OBD types */
728 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
729 int gen_multi_cleanup(struct obd_device *obddev);
730 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
731 int gen_multi_detach(struct obd_device *obddev);
732 int gen_connect (struct obd_conn *conn);
733 int gen_disconnect(struct obd_conn *conn);
734 struct obd_client *gen_client(const struct obd_conn *);
735 int gen_cleanup(struct obd_device *obddev);
736 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
737 struct obd_conn *src_conn, struct obdo *src,
738 obd_size count, obd_off offset);
743 extern void obd_sysctl_init (void);
744 extern void obd_sysctl_clean (void);
746 #endif /* __LINUX_CLASS_OBD_H */