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 256
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);
68 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
71 int oig_init(struct obd_io_group **oig);
72 void oig_add_one(struct obd_io_group *oig,
73 struct oig_callback_context *occ);
74 void oig_complete_one(struct obd_io_group *oig,
75 struct oig_callback_context *occ, int rc);
76 void oig_release(struct obd_io_group *oig);
77 int oig_wait(struct obd_io_group *oig);
80 int class_process_config(struct lustre_cfg *lcfg);
81 int class_attach(struct lustre_cfg *lcfg);
82 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
83 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
84 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
86 /* Passed as data param to class_config_parse_llog */
87 struct config_llog_instance {
89 struct obd_uuid cfg_uuid;
90 ptl_nid_t cfg_local_nid;
92 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
93 struct config_llog_instance *cfg);
94 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
95 struct config_llog_instance *cfg);
97 struct lustre_profile {
98 struct list_head lp_list;
104 struct lustre_profile *class_get_profile(char * prof);
105 void class_del_profile(char *prof);
107 #define class_export_get(exp) \
109 struct obd_export *exp_ = exp; \
110 atomic_inc(&exp_->exp_refcount); \
111 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
112 atomic_read(&exp_->exp_refcount)); \
116 #define class_export_put(exp) \
118 LASSERT((exp) != NULL); \
119 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
120 atomic_read(&(exp)->exp_refcount) - 1); \
121 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
122 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
123 __class_export_put(exp); \
125 void __class_export_put(struct obd_export *);
126 struct obd_export *class_new_export(struct obd_device *obddev);
127 void class_unlink_export(struct obd_export *exp);
129 struct obd_import *class_import_get(struct obd_import *);
130 void class_import_put(struct obd_import *);
131 struct obd_import *class_new_import(void);
132 void class_destroy_import(struct obd_import *exp);
134 struct obd_type *class_get_type(char *name);
135 void class_put_type(struct obd_type *type);
136 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
137 struct obd_uuid *cluuid);
138 int class_disconnect(struct obd_export *exp, int failover);
139 void class_disconnect_exports(struct obd_device *obddev, int failover);
140 /* generic operations shared by various OBD types */
141 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
142 int class_multi_cleanup(struct obd_device *obddev);
146 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
147 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
148 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
149 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
150 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
152 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
153 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
154 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
156 static inline int obd_check_conn(struct lustre_handle *conn)
158 struct obd_device *obd;
160 CERROR("NULL conn\n");
164 obd = class_conn2obd(conn);
166 CERROR("NULL obd\n");
170 if (!obd->obd_attached) {
171 CERROR("obd %d not attached\n", obd->obd_minor);
175 if (!obd->obd_set_up) {
176 CERROR("obd %d not setup\n", obd->obd_minor);
180 if (!obd->obd_type) {
181 CERROR("obd %d not typed\n", obd->obd_minor);
185 if (!obd->obd_type->typ_ops) {
186 CERROR("obd_check_conn: obd %d no operations\n",
194 #define OBT(dev) (dev)->obd_type
195 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
196 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
198 /* Ensure obd_setup: used for disconnect which might be called while
199 an obd is stopping. */
200 #define OBD_CHECK_SETUP(conn, exp) \
203 CERROR("NULL connection\n"); \
207 exp = class_conn2export(conn); \
209 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
213 if (!(exp)->exp_obd->obd_set_up) { \
214 CERROR("Device %d not setup\n", \
215 (exp)->exp_obd->obd_minor); \
216 class_export_put(exp); \
221 /* Ensure obd_setup and !obd_stopping. */
222 #define OBD_CHECK_ACTIVE(conn, exp) \
225 CERROR("NULL connection\n"); \
229 exp = class_conn2export(conn); \
231 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
235 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
236 CERROR("Device %d not setup\n", \
237 (exp)->exp_obd->obd_minor); \
238 class_export_put(exp); \
243 /* Ensure obd_setup: used for cleanup which must be called
244 while obd is stopping */
245 #define OBD_CHECK_DEV_STOPPING(obd) \
248 CERROR("NULL device\n"); \
252 if (!(obd)->obd_set_up) { \
253 CERROR("Device %d not setup\n", \
258 if (!(obd)->obd_stopping) { \
259 CERROR("Device %d not stopping\n", \
265 /* ensure obd_setup and !obd_stopping */
266 #define OBD_CHECK_DEV_ACTIVE(obd) \
269 CERROR("NULL device\n"); \
273 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
274 CERROR("Device %d not setup\n", \
282 #define OBD_COUNTER_OFFSET(op) \
283 ((offsetof(struct obd_ops, o_ ## op) - \
284 offsetof(struct obd_ops, o_iocontrol)) \
285 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
287 #define OBD_COUNTER_INCREMENT(obd, op) \
288 if ((obd)->obd_stats != NULL) { \
289 unsigned int coffset; \
290 coffset = (unsigned int)(obd)->obd_cntr_base + \
291 OBD_COUNTER_OFFSET(op); \
292 LASSERT(coffset < obd->obd_stats->ls_num); \
293 lprocfs_counter_incr(obd->obd_stats, coffset); \
296 #define OBD_COUNTER_OFFSET(op)
297 #define OBD_COUNTER_INCREMENT(obd, op)
300 #define OBD_CHECK_OP(obd, op, err) \
302 if (!OBT(obd) || !OBP((obd), op)) {\
304 CERROR("obd_" #op ": dev %d no operation\n", \
310 #define EXP_CHECK_OP(exp, op) \
312 if ((exp) == NULL) { \
313 CERROR("obd_" #op ": NULL export\n"); \
316 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
317 CERROR("obd_" #op ": cleaned up obd\n"); \
318 RETURN(-EOPNOTSUPP); \
320 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
321 CERROR("obd_" #op ": dev %d no operation\n", \
322 (exp)->exp_obd->obd_minor); \
323 RETURN(-EOPNOTSUPP); \
327 #define CTXT_CHECK_OP(ctxt, op, err) \
329 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
331 CERROR("lop_" #op ": dev %d no operation\n", \
332 ctxt->loc_obd->obd_minor); \
337 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
338 void *key, __u32 *vallen, void *val)
343 EXP_CHECK_OP(exp, get_info);
344 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
346 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
350 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
351 void *key, obd_count vallen, void *val)
356 EXP_CHECK_OP(exp, set_info);
357 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
359 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
363 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
368 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
369 OBD_COUNTER_INCREMENT(obd, setup);
371 rc = OBP(obd, setup)(obd, datalen, data);
375 static inline int obd_precleanup(struct obd_device *obd, int flags)
380 OBD_CHECK_OP(obd, precleanup, 0);
381 OBD_COUNTER_INCREMENT(obd, precleanup);
383 rc = OBP(obd, precleanup)(obd, flags);
387 static inline int obd_cleanup(struct obd_device *obd, int flags)
392 OBD_CHECK_DEV_STOPPING(obd);
393 OBD_CHECK_OP(obd, cleanup, 0);
394 OBD_COUNTER_INCREMENT(obd, cleanup);
396 rc = OBP(obd, cleanup)(obd, flags);
400 /* Pack an in-memory MD struct for storage on disk.
401 * Returns +ve size of packed MD (0 for free), or -ve error.
403 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
404 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
405 * If @*disk_tgt == NULL, it will be allocated
407 static inline int obd_packmd(struct obd_export *exp,
408 struct lov_mds_md **disk_tgt,
409 struct lov_stripe_md *mem_src)
414 EXP_CHECK_OP(exp, packmd);
415 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
417 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
421 static inline int obd_size_diskmd(struct obd_export *exp,
422 struct lov_stripe_md *mem_src)
424 return obd_packmd(exp, NULL, mem_src);
427 /* helper functions */
428 static inline int obd_alloc_diskmd(struct obd_export *exp,
429 struct lov_mds_md **disk_tgt)
432 LASSERT(*disk_tgt == NULL);
433 return obd_packmd(exp, disk_tgt, NULL);
436 static inline int obd_free_diskmd(struct obd_export *exp,
437 struct lov_mds_md **disk_tgt)
441 return obd_packmd(exp, disk_tgt, NULL);
444 /* Unpack an MD struct from disk to in-memory format.
445 * Returns +ve size of unpacked MD (0 for free), or -ve error.
447 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
448 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
449 * If @*mem_tgt == NULL, it will be allocated
451 static inline int obd_unpackmd(struct obd_export *exp,
452 struct lov_stripe_md **mem_tgt,
453 struct lov_mds_md *disk_src,
459 EXP_CHECK_OP(exp, unpackmd);
460 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
462 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
466 /* helper functions */
467 static inline int obd_alloc_memmd(struct obd_export *exp,
468 struct lov_stripe_md **mem_tgt)
471 LASSERT(*mem_tgt == NULL);
472 return obd_unpackmd(exp, mem_tgt, NULL, 0);
475 static inline int obd_free_memmd(struct obd_export *exp,
476 struct lov_stripe_md **mem_tgt)
480 return obd_unpackmd(exp, mem_tgt, NULL, 0);
483 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
484 struct lov_stripe_md **ea,
485 struct obd_trans_info *oti)
490 EXP_CHECK_OP(exp, create);
491 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
493 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
497 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
498 struct lov_stripe_md *ea,
499 struct obd_trans_info *oti)
504 EXP_CHECK_OP(exp, destroy);
505 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
507 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
511 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
512 struct lov_stripe_md *ea)
517 EXP_CHECK_OP(exp, getattr);
518 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
520 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
524 static inline int obd_getattr_async(struct obd_export *exp,
525 struct obdo *obdo, struct lov_stripe_md *ea,
526 struct ptlrpc_request_set *set)
531 EXP_CHECK_OP(exp, getattr);
532 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
534 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
538 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
539 struct lov_stripe_md *ea,
540 struct obd_trans_info *oti)
545 EXP_CHECK_OP(exp, setattr);
546 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
548 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
552 static inline int obd_connect(struct lustre_handle *conn,
553 struct obd_device *obd, struct obd_uuid *cluuid)
558 OBD_CHECK_DEV_ACTIVE(obd);
559 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
560 OBD_COUNTER_INCREMENT(obd, connect);
562 rc = OBP(obd, connect)(conn, obd, cluuid);
566 static inline int obd_disconnect(struct obd_export *exp, int flags)
571 EXP_CHECK_OP(exp, disconnect);
572 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
574 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
578 static inline int obd_init_export(struct obd_export *exp)
583 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
584 OBP((exp)->exp_obd, init_export))
585 rc = OBP(exp->exp_obd, init_export)(exp);
589 static inline int obd_destroy_export(struct obd_export *exp)
592 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
593 OBP((exp)->exp_obd, destroy_export))
594 OBP(exp->exp_obd, destroy_export)(exp);
598 static inline struct dentry *
599 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
601 LASSERT(exp->exp_obd);
603 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
608 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
611 /* @max_age is the oldest time in jiffies that we accept using a cached data.
612 * If the cache is older than @max_age we will get a new value from the
613 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
614 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
615 unsigned long max_age)
623 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
624 OBD_COUNTER_INCREMENT(obd, statfs);
626 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
627 if (time_before(obd->obd_osfs_age, max_age)) {
628 rc = OBP(obd, statfs)(obd, osfs, max_age);
630 spin_lock(&obd->obd_osfs_lock);
631 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
632 obd->obd_osfs_age = jiffies;
633 spin_unlock(&obd->obd_osfs_lock);
636 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
637 spin_lock(&obd->obd_osfs_lock);
638 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
639 spin_unlock(&obd->obd_osfs_lock);
644 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
645 struct lov_stripe_md *ea, obd_size start,
651 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
652 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
654 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
658 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
659 struct lov_stripe_md *ea, obd_size start,
660 obd_size end, struct obd_trans_info *oti)
665 EXP_CHECK_OP(exp, punch);
666 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
668 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
672 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
673 struct lov_stripe_md *ea, obd_count oa_bufs,
674 struct brw_page *pg, struct obd_trans_info *oti)
679 EXP_CHECK_OP(exp, brw);
680 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
682 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
683 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
684 "or OBD_BRW_CHECK\n");
688 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
692 static inline int obd_brw_async(int cmd, struct obd_export *exp,
693 struct obdo *oa, struct lov_stripe_md *ea,
694 obd_count oa_bufs, struct brw_page *pg,
695 struct ptlrpc_request_set *set,
696 struct obd_trans_info *oti)
701 EXP_CHECK_OP(exp, brw_async);
702 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
704 if (!(cmd & OBD_BRW_RWMASK)) {
705 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
709 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
714 static inline int obd_prep_async_page(struct obd_export *exp,
715 struct lov_stripe_md *lsm,
716 struct lov_oinfo *loi,
717 struct page *page, obd_off offset,
718 struct obd_async_page_ops *ops,
719 void *data, void **res)
724 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
725 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
727 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
732 static inline int obd_queue_async_io(struct obd_export *exp,
733 struct lov_stripe_md *lsm,
734 struct lov_oinfo *loi, void *cookie,
735 int cmd, obd_off off, int count,
736 obd_flag brw_flags, obd_flag async_flags)
741 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
742 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
743 LASSERT(cmd & OBD_BRW_RWMASK);
745 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
746 count, brw_flags, async_flags);
750 static inline int obd_set_async_flags(struct obd_export *exp,
751 struct lov_stripe_md *lsm,
752 struct lov_oinfo *loi, void *cookie,
753 obd_flag async_flags)
758 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
759 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
761 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
766 static inline int obd_queue_group_io(struct obd_export *exp,
767 struct lov_stripe_md *lsm,
768 struct lov_oinfo *loi,
769 struct obd_io_group *oig,
770 void *cookie, int cmd, obd_off off,
771 int count, obd_flag brw_flags,
772 obd_flag async_flags)
777 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
778 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
779 LASSERT(cmd & OBD_BRW_RWMASK);
781 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
782 cmd, off, count, brw_flags,
787 static inline int obd_trigger_group_io(struct obd_export *exp,
788 struct lov_stripe_md *lsm,
789 struct lov_oinfo *loi,
790 struct obd_io_group *oig)
795 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
796 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
798 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
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, int rc)
840 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
841 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
843 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
848 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
849 int len, void *karg, void *uarg)
854 EXP_CHECK_OP(exp, iocontrol);
855 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
857 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
861 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
862 __u32 type, ldlm_policy_data_t *policy,
863 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
864 void *gl_cb, void *data, __u32 lvb_len,
865 void *lvb_swabber, struct lustre_handle *lockh)
870 EXP_CHECK_OP(exp, enqueue);
871 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
873 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
874 bl_cb, cp_cb, gl_cb, data, lvb_len,
879 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
880 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
881 int *flags, void *data, struct lustre_handle *lockh)
886 EXP_CHECK_OP(exp, match);
887 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
889 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
894 static inline int obd_change_cbdata(struct obd_export *exp,
895 struct lov_stripe_md *lsm,
896 ldlm_iterator_t it, void *data)
901 EXP_CHECK_OP(exp, change_cbdata);
902 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
904 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
908 static inline int obd_cancel(struct obd_export *exp,
909 struct lov_stripe_md *ea, __u32 mode,
910 struct lustre_handle *lockh)
915 EXP_CHECK_OP(exp, cancel);
916 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
918 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
922 static inline int obd_cancel_unused(struct obd_export *exp,
923 struct lov_stripe_md *ea, int flags,
929 EXP_CHECK_OP(exp, cancel_unused);
930 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
932 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
937 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
939 int objcount, struct obd_ioobj *obj,
940 int niocount, struct niobuf_remote *remote)
944 EXP_CHECK_OP(exp, preprw);
945 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
947 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
949 class_export_put(exp);
953 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
954 int type, struct obd_client_handle *handle, int flag)
958 EXP_CHECK_OP(exp, pin);
959 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
961 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
965 static inline int obd_unpin(struct obd_export *exp,
966 struct obd_client_handle *handle, int flag)
970 EXP_CHECK_OP(exp, unpin);
971 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
973 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
978 static inline void obd_import_event(struct obd_device *obd,
979 struct obd_import *imp,
980 enum obd_import_event event)
982 if (obd->obd_set_up && OBP(obd, import_event)) {
983 OBD_COUNTER_INCREMENT(obd, import_event);
984 OBP(obd, import_event)(obd, imp, event);
988 static inline int obd_notify(struct obd_device *obd,
989 struct obd_device *watched,
992 if (!obd->obd_set_up) {
993 CERROR("obd %s not set up\n", obd->obd_name);
997 if (!OBP(obd, notify)) {
998 CERROR("obd %s has no notify handler\n", obd->obd_name);
1002 OBD_COUNTER_INCREMENT(obd, notify);
1003 return OBP(obd, notify)(obd, watched, active);
1006 static inline int obd_register_observer(struct obd_device *obd,
1007 struct obd_device *observer)
1010 if (obd->obd_observer && observer)
1012 obd->obd_observer = observer;
1016 /* OBD Metadata Support */
1018 extern int obd_init_caches(void);
1019 extern void obd_cleanup_caches(void);
1021 /* support routines */
1022 extern kmem_cache_t *obdo_cachep;
1023 static inline struct obdo *obdo_alloc(void)
1027 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1030 CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1031 memset(oa, 0, sizeof (*oa));
1036 static inline void obdo_free(struct obdo *oa)
1040 CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1041 kmem_cache_free(obdo_cachep, oa);
1044 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1045 #define to_kdev_t(dev) dev
1046 #define kdev_t_to_nr(dev) dev
1049 /* I'm as embarrassed about this as you are.
1051 * <shaver> // XXX do not look into _superhack with remaining eye
1052 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1053 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1054 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1057 extern void obd_sysctl_init (void);
1058 extern void obd_sysctl_clean (void);
1061 typedef __u8 class_uuid_t[16];
1062 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1063 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1066 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1067 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1068 int class_del_uuid (char *uuid);
1069 void class_init_uuidlist(void);
1070 void class_exit_uuidlist(void);
1071 #endif /* __LINUX_OBD_CLASS_H */