1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 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
27 #include <sys/types.h>
28 #include <portals/list.h>
30 #include <asm/segment.h>
31 #include <asm/uaccess.h>
32 #include <linux/types.h>
34 #include <linux/time.h>
35 #include <linux/timer.h>
38 #include <linux/obd_support.h>
39 #include <linux/lustre_import.h>
40 #include <linux/lustre_net.h>
41 #include <linux/obd.h>
42 #include <linux/lustre_lib.h>
43 #include <linux/lustre_idl.h>
44 #include <linux/lprocfs_status.h>
46 /* OBD Device Declarations */
47 #define MAX_OBD_DEVICES 128
48 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
50 /* OBD Operations Declarations */
51 extern struct obd_device *class_conn2obd(struct lustre_handle *);
52 extern struct obd_device *class_exp2obd(struct obd_export *);
55 struct obd_export *class_conn2export(struct lustre_handle *);
56 int class_register_type(struct obd_ops *ops, struct lprocfs_vars *, char *nm);
57 int class_unregister_type(char *nm);
59 struct obd_device *class_newdev(int *dev);
61 int class_name2dev(char *name);
62 struct obd_device *class_name2obd(char *name);
63 int class_uuid2dev(struct obd_uuid *uuid);
64 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
65 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
67 struct obd_uuid *grp_uuid);
69 void osic_init(struct obd_sync_io_container *osic);
70 void osic_add_one(struct obd_sync_io_container *osic);
71 void osic_complete_one(struct obd_sync_io_container *osic, int rc);
72 int osic_wait(struct obd_sync_io_container *osic);
75 int class_process_config(struct lustre_cfg *lcfg);
76 int class_attach(struct lustre_cfg *lcfg);
77 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
78 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
79 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
81 /* Passed as data param to class_config_parse_llog */
82 struct config_llog_instance {
84 struct obd_uuid cfg_uuid;
85 ptl_nid_t cfg_local_nid;
87 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
88 struct config_llog_instance *cfg);
89 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
90 struct config_llog_instance *cfg);
92 struct lustre_profile {
93 struct list_head lp_list;
99 struct lustre_profile *class_get_profile(char * prof);
101 #define class_export_get(exp) \
103 struct obd_export *exp_ = exp; \
104 atomic_inc(&exp_->exp_refcount); \
105 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
106 atomic_read(&exp_->exp_refcount)); \
110 #define class_export_put(exp) \
112 LASSERT((exp) != NULL); \
113 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
114 atomic_read(&(exp)->exp_refcount) - 1); \
115 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
116 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
117 __class_export_put(exp); \
119 void __class_export_put(struct obd_export *);
120 struct obd_export *class_new_export(struct obd_device *obddev);
121 void class_unlink_export(struct obd_export *exp);
123 struct obd_import *class_import_get(struct obd_import *);
124 void class_import_put(struct obd_import *);
125 struct obd_import *class_new_import(void);
126 void class_destroy_import(struct obd_import *exp);
128 struct obd_type *class_get_type(char *name);
129 void class_put_type(struct obd_type *type);
130 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
131 struct obd_uuid *cluuid);
132 int class_disconnect(struct obd_export *exp, int failover);
133 void class_disconnect_exports(struct obd_device *obddev, int failover);
134 /* generic operations shared by various OBD types */
135 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
136 int class_multi_cleanup(struct obd_device *obddev);
140 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
141 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
142 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
143 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
144 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
146 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
147 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
148 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
150 static inline int obd_check_conn(struct lustre_handle *conn)
152 struct obd_device *obd;
154 CERROR("NULL conn\n");
158 obd = class_conn2obd(conn);
160 CERROR("NULL obd\n");
164 if (!obd->obd_attached) {
165 CERROR("obd %d not attached\n", obd->obd_minor);
169 if (!obd->obd_set_up) {
170 CERROR("obd %d not setup\n", obd->obd_minor);
174 if (!obd->obd_type) {
175 CERROR("obd %d not typed\n", obd->obd_minor);
179 if (!obd->obd_type->typ_ops) {
180 CERROR("obd_check_conn: obd %d no operations\n",
188 #define OBT(dev) (dev)->obd_type
189 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
190 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
192 /* Ensure obd_setup: used for disconnect which might be called while
193 an obd is stopping. */
194 #define OBD_CHECK_SETUP(conn, exp) \
197 CERROR("NULL connection\n"); \
201 exp = class_conn2export(conn); \
203 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
207 if (!(exp)->exp_obd->obd_set_up) { \
208 CERROR("Device %d not setup\n", \
209 (exp)->exp_obd->obd_minor); \
210 class_export_put(exp); \
215 /* Ensure obd_setup and !obd_stopping. */
216 #define OBD_CHECK_ACTIVE(conn, exp) \
219 CERROR("NULL connection\n"); \
223 exp = class_conn2export(conn); \
225 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
229 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
230 CERROR("Device %d not setup\n", \
231 (exp)->exp_obd->obd_minor); \
232 class_export_put(exp); \
237 /* Ensure obd_setup: used for cleanup which must be called
238 while obd is stopping */
239 #define OBD_CHECK_DEV_STOPPING(obd) \
242 CERROR("NULL device\n"); \
246 if (!(obd)->obd_set_up) { \
247 CERROR("Device %d not setup\n", \
252 if (!(obd)->obd_stopping) { \
253 CERROR("Device %d not stopping\n", \
259 /* ensure obd_setup and !obd_stopping */
260 #define OBD_CHECK_DEV_ACTIVE(obd) \
263 CERROR("NULL device\n"); \
267 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
268 CERROR("Device %d not setup\n", \
276 #define OBD_COUNTER_OFFSET(op) \
277 ((offsetof(struct obd_ops, o_ ## op) - \
278 offsetof(struct obd_ops, o_iocontrol)) \
279 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
281 #define OBD_COUNTER_INCREMENT(obd, op) \
282 if ((obd)->obd_stats != NULL) { \
283 unsigned int coffset; \
284 coffset = (unsigned int)(obd)->obd_cntr_base + \
285 OBD_COUNTER_OFFSET(op); \
286 LASSERT(coffset < obd->obd_stats->ls_num); \
287 lprocfs_counter_incr(obd->obd_stats, coffset); \
290 #define OBD_COUNTER_OFFSET(op)
291 #define OBD_COUNTER_INCREMENT(obd, op)
294 #define OBD_CHECK_OP(obd, op, err) \
296 if (!OBT(obd) || !OBP((obd), op)) {\
298 CERROR("obd_" #op ": dev %d no operation\n", \
304 #define EXP_CHECK_OP(exp, op) \
306 if ((exp) == NULL) { \
307 CERROR("obd_" #op ": NULL export\n"); \
310 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
311 CERROR("obd_" #op ": cleaned up obd\n"); \
312 RETURN(-EOPNOTSUPP); \
314 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
315 CERROR("obd_" #op ": dev %d no operation\n", \
316 (exp)->exp_obd->obd_minor); \
317 RETURN(-EOPNOTSUPP); \
321 #define CTXT_CHECK_OP(ctxt, op, err) \
323 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
325 CERROR("lop_" #op ": dev %d no operation\n", \
326 ctxt->loc_obd->obd_minor); \
331 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
332 void *key, __u32 *vallen, void *val)
337 EXP_CHECK_OP(exp, get_info);
338 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
340 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
344 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
345 void *key, obd_count vallen, void *val)
350 EXP_CHECK_OP(exp, set_info);
351 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
353 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
357 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
362 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
363 OBD_COUNTER_INCREMENT(obd, setup);
365 rc = OBP(obd, setup)(obd, datalen, data);
369 static inline int obd_postsetup(struct obd_device *obd)
374 OBD_CHECK_DEV_ACTIVE(obd);
375 OBD_CHECK_OP(obd, postsetup, 0);
376 OBD_COUNTER_INCREMENT(obd, postsetup);
378 rc = OBP(obd, postsetup)(obd);
382 static inline int obd_precleanup(struct obd_device *obd, int flags)
387 OBD_CHECK_OP(obd, precleanup, 0);
388 OBD_COUNTER_INCREMENT(obd, precleanup);
390 rc = OBP(obd, precleanup)(obd, flags);
394 static inline int obd_cleanup(struct obd_device *obd, int flags)
399 OBD_CHECK_DEV_STOPPING(obd);
400 OBD_CHECK_OP(obd, cleanup, 0);
401 OBD_COUNTER_INCREMENT(obd, cleanup);
403 rc = OBP(obd, cleanup)(obd, flags);
407 /* Pack an in-memory MD struct for storage on disk.
408 * Returns +ve size of packed MD (0 for free), or -ve error.
410 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
411 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
412 * If @*disk_tgt == NULL, it will be allocated
414 static inline int obd_packmd(struct obd_export *exp,
415 struct lov_mds_md **disk_tgt,
416 struct lov_stripe_md *mem_src)
421 EXP_CHECK_OP(exp, packmd);
422 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
424 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
428 static inline int obd_size_diskmd(struct obd_export *exp,
429 struct lov_stripe_md *mem_src)
431 return obd_packmd(exp, NULL, mem_src);
434 /* helper functions */
435 static inline int obd_alloc_diskmd(struct obd_export *exp,
436 struct lov_mds_md **disk_tgt)
439 LASSERT(*disk_tgt == NULL);
440 return obd_packmd(exp, disk_tgt, NULL);
443 static inline int obd_free_diskmd(struct obd_export *exp,
444 struct lov_mds_md **disk_tgt)
448 return obd_packmd(exp, disk_tgt, NULL);
451 /* Unpack an MD struct from disk to in-memory format.
452 * Returns +ve size of unpacked MD (0 for free), or -ve error.
454 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
455 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
456 * If @*mem_tgt == NULL, it will be allocated
458 static inline int obd_unpackmd(struct obd_export *exp,
459 struct lov_stripe_md **mem_tgt,
460 struct lov_mds_md *disk_src,
466 EXP_CHECK_OP(exp, unpackmd);
467 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
469 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
473 /* helper functions */
474 static inline int obd_alloc_memmd(struct obd_export *exp,
475 struct lov_stripe_md **mem_tgt)
478 LASSERT(*mem_tgt == NULL);
479 return obd_unpackmd(exp, mem_tgt, NULL, 0);
482 static inline int obd_free_memmd(struct obd_export *exp,
483 struct lov_stripe_md **mem_tgt)
487 return obd_unpackmd(exp, mem_tgt, NULL, 0);
490 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
491 struct lov_stripe_md **ea,
492 struct obd_trans_info *oti)
497 EXP_CHECK_OP(exp, create);
498 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
500 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
504 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
505 struct lov_stripe_md *ea,
506 struct obd_trans_info *oti)
511 EXP_CHECK_OP(exp, destroy);
512 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
514 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
518 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
519 struct lov_stripe_md *ea)
524 EXP_CHECK_OP(exp, getattr);
525 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
527 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
531 static inline int obd_getattr_async(struct obd_export *exp,
532 struct obdo *obdo, struct lov_stripe_md *ea,
533 struct ptlrpc_request_set *set)
538 EXP_CHECK_OP(exp, getattr);
539 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
541 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
545 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
546 struct lov_stripe_md *ea,
547 struct obd_trans_info *oti)
552 EXP_CHECK_OP(exp, setattr);
553 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
555 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
559 static inline int obd_connect(struct lustre_handle *conn,
560 struct obd_device *obd, struct obd_uuid *cluuid)
565 OBD_CHECK_DEV_ACTIVE(obd);
566 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
567 OBD_COUNTER_INCREMENT(obd, connect);
569 rc = OBP(obd, connect)(conn, obd, cluuid);
573 static inline int obd_disconnect(struct obd_export *exp, int flags)
578 EXP_CHECK_OP(exp, disconnect);
579 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
581 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
585 static inline int obd_init_export(struct obd_export *exp)
590 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
591 OBP((exp)->exp_obd, init_export))
592 rc = OBP(exp->exp_obd, init_export)(exp);
596 static inline int obd_destroy_export(struct obd_export *exp)
599 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
600 OBP((exp)->exp_obd, destroy_export))
601 OBP(exp->exp_obd, destroy_export)(exp);
605 static inline struct dentry *
606 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
608 LASSERT(exp->exp_obd);
610 return lvfs_fid2dentry(&exp->exp_obd->obd_ctxt, id_ino, gen, gr,
615 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
618 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
619 unsigned long max_age)
627 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
628 OBD_COUNTER_INCREMENT(obd, statfs);
630 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
631 if (obd->obd_osfs_age == 0 || time_before(obd->obd_osfs_age, max_age)) {
632 rc = OBP(obd, statfs)(obd, osfs, max_age);
633 spin_lock(&obd->obd_dev_lock);
634 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
635 obd->obd_osfs_age = jiffies;
636 spin_unlock(&obd->obd_dev_lock);
638 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
639 spin_lock(&obd->obd_dev_lock);
640 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
641 spin_unlock(&obd->obd_dev_lock);
646 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
647 struct lov_stripe_md *ea, obd_size start,
653 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
654 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
656 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
660 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
661 struct lov_stripe_md *ea, obd_size start,
662 obd_size end, struct obd_trans_info *oti)
667 EXP_CHECK_OP(exp, punch);
668 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
670 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
674 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
675 struct lov_stripe_md *ea, obd_count oa_bufs,
676 struct brw_page *pg, struct obd_trans_info *oti)
681 EXP_CHECK_OP(exp, brw);
682 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
684 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
685 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
686 "or OBD_BRW_CHECK\n");
690 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
694 static inline int obd_brw_async(int cmd, struct obd_export *exp,
695 struct obdo *oa, struct lov_stripe_md *ea,
696 obd_count oa_bufs, struct brw_page *pg,
697 struct ptlrpc_request_set *set,
698 struct obd_trans_info *oti)
703 EXP_CHECK_OP(exp, brw_async);
704 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
706 if (!(cmd & OBD_BRW_RWMASK)) {
707 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
711 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
716 static inline int obd_prep_async_page(struct obd_export *exp,
717 struct lov_stripe_md *lsm,
718 struct lov_oinfo *loi,
719 struct page *page, obd_off offset,
720 struct obd_async_page_ops *ops,
721 void *data, void **res)
726 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
727 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
729 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
734 static inline int obd_queue_async_io(struct obd_export *exp,
735 struct lov_stripe_md *lsm,
736 struct lov_oinfo *loi, void *cookie,
737 int cmd, obd_off off, int count,
738 obd_flag brw_flags, obd_flag async_flags)
743 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
744 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
745 LASSERT(cmd & OBD_BRW_RWMASK);
747 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
748 count, brw_flags, async_flags);
752 static inline int obd_set_async_flags(struct obd_export *exp,
753 struct lov_stripe_md *lsm,
754 struct lov_oinfo *loi, void *cookie,
755 obd_flag async_flags)
760 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
761 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
763 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
768 static inline int obd_queue_sync_io(struct obd_export *exp,
769 struct lov_stripe_md *lsm,
770 struct lov_oinfo *loi,
771 struct obd_sync_io_container *osic,
772 void *cookie, int cmd, obd_off off,
773 int count, obd_flag brw_flags)
778 OBD_CHECK_OP(exp->exp_obd, queue_sync_io, -EOPNOTSUPP);
779 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_sync_io);
780 LASSERT(cmd & OBD_BRW_RWMASK);
782 rc = OBP(exp->exp_obd, queue_sync_io)(exp, lsm, loi, osic, cookie,
783 cmd, off, count, brw_flags);
787 static inline int obd_trigger_sync_io(struct obd_export *exp,
788 struct lov_stripe_md *lsm,
789 struct lov_oinfo *loi,
790 struct obd_sync_io_container *osic)
795 OBD_CHECK_OP(exp->exp_obd, trigger_sync_io, -EOPNOTSUPP);
796 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_sync_io);
798 rc = OBP(exp->exp_obd, trigger_sync_io)(exp, lsm, loi, osic);
802 static inline int obd_teardown_async_page(struct obd_export *exp,
803 struct lov_stripe_md *lsm,
804 struct lov_oinfo *loi, void *cookie)
809 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
810 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
812 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
816 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
817 int objcount, struct obd_ioobj *obj,
818 int niocount, struct niobuf_remote *remote,
819 struct niobuf_local *local,
820 struct obd_trans_info *oti)
825 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
826 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
828 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
833 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
834 int objcount, struct obd_ioobj *obj,
835 int niocount, struct niobuf_local *local,
836 struct obd_trans_info *oti)
841 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
842 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
844 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
849 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
850 int len, void *karg, void *uarg)
855 EXP_CHECK_OP(exp, iocontrol);
856 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
858 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
862 static inline int obd_enqueue(struct obd_export *exp,
863 struct lov_stripe_md *ea,
864 struct lustre_handle *parent_lock,
865 __u32 type, void *cookie, int cookielen,
866 __u32 mode, int *flags, void *cb, void *data,
867 struct lustre_handle *lockh)
872 EXP_CHECK_OP(exp, enqueue);
873 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
875 rc = OBP(exp->exp_obd, enqueue)(exp, ea, parent_lock, type,
876 cookie, cookielen, mode, flags, cb,
881 static inline int obd_match(struct obd_export *exp,
882 struct lov_stripe_md *ea, __u32 type, void *cookie,
883 int cookielen, __u32 mode, int *flags, void *data,
884 struct lustre_handle *lockh)
889 EXP_CHECK_OP(exp, match);
890 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
892 rc = OBP(exp->exp_obd, match)(exp, ea, type, cookie, cookielen, mode,
898 static inline int obd_change_cbdata(struct obd_export *exp,
899 struct lov_stripe_md *lsm,
900 ldlm_iterator_t it, void *data)
905 EXP_CHECK_OP(exp, change_cbdata);
906 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
908 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
912 static inline int obd_cancel(struct obd_export *exp,
913 struct lov_stripe_md *ea, __u32 mode,
914 struct lustre_handle *lockh)
919 EXP_CHECK_OP(exp, cancel);
920 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
922 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
926 static inline int obd_cancel_unused(struct obd_export *exp,
927 struct lov_stripe_md *ea, int flags,
933 EXP_CHECK_OP(exp, cancel_unused);
934 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
936 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
941 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
943 int objcount, struct obd_ioobj *obj,
944 int niocount, struct niobuf_remote *remote)
948 EXP_CHECK_OP(exp, preprw);
949 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
951 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
953 class_export_put(exp);
957 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
958 int type, struct obd_client_handle *handle, int flag)
962 EXP_CHECK_OP(exp, pin);
963 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
965 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
969 static inline int obd_unpin(struct obd_export *exp,
970 struct obd_client_handle *handle, int flag)
974 EXP_CHECK_OP(exp, unpin);
975 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
977 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
981 static inline int obd_lock_contains(struct obd_export *exp,
982 struct lov_stripe_md *lsm,
983 struct ldlm_lock *lock, obd_off offset)
988 EXP_CHECK_OP(exp, lock_contains);
989 OBD_COUNTER_INCREMENT(exp->exp_obd, lock_contains);
991 rc = OBP(exp->exp_obd, lock_contains)(exp, lsm, lock, offset);
995 static inline void obd_invalidate_import(struct obd_device *obd,
996 struct obd_import *imp)
998 if (obd->obd_set_up && OBP(obd, invalidate_import)) {
999 OBD_COUNTER_INCREMENT(obd, invalidate_import);
1000 OBP(obd, invalidate_import)(obd, imp);
1004 static inline int obd_notify(struct obd_device *obd,
1005 struct obd_device *watched,
1008 if (!obd->obd_set_up) {
1009 CERROR("obd %s not set up\n", obd->obd_name);
1013 if (!OBP(obd, notify)) {
1014 CERROR("obd %s has no notify handler\n", obd->obd_name);
1018 OBD_COUNTER_INCREMENT(obd, notify);
1019 return OBP(obd, notify)(obd, watched, active);
1022 static inline int obd_register_observer(struct obd_device *obd,
1023 struct obd_device *observer)
1026 if (obd->obd_observer && observer)
1028 obd->obd_observer = observer;
1032 /* OBD Metadata Support */
1034 extern int obd_init_caches(void);
1035 extern void obd_cleanup_caches(void);
1037 /* async page pushing io helpers */
1038 struct obd_client_page *ocp_alloc(struct page *page);
1039 void ocp_free(struct page *page);
1041 /* support routines */
1042 extern kmem_cache_t *obdo_cachep;
1043 static inline struct obdo *obdo_alloc(void)
1047 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1050 CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1051 memset(oa, 0, sizeof (*oa));
1056 static inline void obdo_free(struct obdo *oa)
1060 CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1061 kmem_cache_free(obdo_cachep, oa);
1064 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1065 #define to_kdev_t(dev) dev
1066 #define kdev_t_to_nr(dev) dev
1069 /* I'm as embarrassed about this as you are.
1071 * <shaver> // XXX do not look into _superhack with remaining eye
1072 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1073 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1074 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1076 struct obd_class_user_state {
1077 struct obd_device *ocus_current_obd;
1078 struct list_head ocus_conns;
1081 struct obd_class_user_conn {
1082 struct list_head ocuc_chain;
1083 struct obd_export *ocuc_exp;
1088 extern void obd_sysctl_init (void);
1089 extern void obd_sysctl_clean (void);
1092 typedef __u8 class_uuid_t[16];
1093 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1094 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1097 int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer);
1098 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1099 int class_del_uuid (char *uuid);
1100 void class_init_uuidlist(void);
1101 void class_exit_uuidlist(void);
1102 #endif /* __LINUX_OBD_CLASS_H */