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 <libcfs/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 520
48 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
49 extern spinlock_t obd_dev_lock;
51 /* OBD Operations Declarations */
52 extern struct obd_device *class_conn2obd(struct lustre_handle *);
53 extern struct obd_device *class_exp2obd(struct obd_export *);
56 struct obd_export *class_conn2export(struct lustre_handle *);
57 int class_register_type(struct obd_ops *ops, struct lprocfs_vars *, char *nm);
58 int class_unregister_type(char *nm);
60 struct obd_device *class_newdev(struct obd_type *type, char *name);
61 void class_release_dev(struct obd_device *obd);
63 int class_name2dev(char *name);
64 struct obd_device *class_name2obd(char *name);
65 int class_uuid2dev(struct obd_uuid *uuid);
66 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
67 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
69 struct obd_uuid *grp_uuid);
70 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
71 struct obd_uuid *grp_uuid);
72 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
75 int oig_init(struct obd_io_group **oig);
76 void oig_add_one(struct obd_io_group *oig,
77 struct oig_callback_context *occ);
78 void oig_complete_one(struct obd_io_group *oig,
79 struct oig_callback_context *occ, int rc);
80 void oig_release(struct obd_io_group *oig);
81 int oig_wait(struct obd_io_group *oig);
84 void ping_evictor_start(void);
85 void ping_evictor_stop(void);
87 #define ping_evictor_start() do {} while (0)
88 #define ping_evictor_stop() do {} while (0)
92 char *obd_export_nid2str(struct obd_export *exp);
95 int class_process_config(struct lustre_cfg *lcfg);
96 int class_attach(struct lustre_cfg *lcfg);
97 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
98 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
99 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
100 void class_decref(struct obd_device *obd);
102 /* Passed as data param to class_config_parse_llog */
103 struct config_llog_instance {
105 struct obd_uuid cfg_uuid;
107 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
108 struct config_llog_instance *cfg);
109 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
110 struct config_llog_instance *cfg);
112 struct lustre_profile {
113 struct list_head lp_list;
119 struct lustre_profile *class_get_profile(char * prof);
120 void class_del_profile(char *prof);
122 #define class_export_get(exp) \
124 struct obd_export *exp_ = exp; \
125 atomic_inc(&exp_->exp_refcount); \
126 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
127 atomic_read(&exp_->exp_refcount)); \
131 #define class_export_put(exp) \
133 LASSERT((exp) != NULL); \
134 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
135 atomic_read(&(exp)->exp_refcount) - 1); \
136 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
137 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
138 __class_export_put(exp); \
140 void __class_export_put(struct obd_export *);
141 struct obd_export *class_new_export(struct obd_device *obddev);
142 void class_unlink_export(struct obd_export *exp);
143 void class_update_export_timer(struct obd_export *exp, time_t extra_delay);
145 struct obd_import *class_import_get(struct obd_import *);
146 void class_import_put(struct obd_import *);
147 struct obd_import *class_new_import(void);
148 void class_destroy_import(struct obd_import *exp);
150 struct obd_type *class_get_type(char *name);
151 void class_put_type(struct obd_type *type);
152 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
153 struct obd_uuid *cluuid);
154 int class_disconnect(struct obd_export *exp);
155 void class_fail_export(struct obd_export *exp);
156 void class_disconnect_exports(struct obd_device *obddev);
157 void class_disconnect_stale_exports(struct obd_device *obddev);
158 /* generic operations shared by various OBD types */
159 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
160 int class_multi_cleanup(struct obd_device *obddev);
164 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
165 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
166 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
167 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
168 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
170 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
171 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
172 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
175 #define OBT(dev) (dev)->obd_type
176 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
177 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
179 /* Ensure obd_setup: used for cleanup which must be called
180 while obd is stopping */
181 #define OBD_CHECK_DEV(obd) \
184 CERROR("NULL device\n"); \
189 /* ensure obd_setup and !obd_stopping */
190 #define OBD_CHECK_DEV_ACTIVE(obd) \
192 OBD_CHECK_DEV(obd); \
193 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
194 CERROR("Device %d not setup\n", \
202 #define OBD_COUNTER_OFFSET(op) \
203 ((offsetof(struct obd_ops, o_ ## op) - \
204 offsetof(struct obd_ops, o_iocontrol)) \
205 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
207 #define OBD_COUNTER_INCREMENT(obd, op) \
208 if ((obd)->obd_stats != NULL) { \
209 unsigned int coffset; \
210 coffset = (unsigned int)(obd)->obd_cntr_base + \
211 OBD_COUNTER_OFFSET(op); \
212 LASSERT(coffset < obd->obd_stats->ls_num); \
213 lprocfs_counter_incr(obd->obd_stats, coffset); \
216 #define OBD_COUNTER_OFFSET(op)
217 #define OBD_COUNTER_INCREMENT(obd, op)
220 #define OBD_CHECK_OP(obd, op, err) \
222 if (!OBT(obd) || !OBP((obd), op)) {\
224 CERROR("obd_" #op ": dev %d no operation\n", \
230 #define EXP_CHECK_OP(exp, op) \
232 if ((exp) == NULL) { \
233 CERROR("obd_" #op ": NULL export\n"); \
236 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
237 CERROR("obd_" #op ": cleaned up obd\n"); \
238 RETURN(-EOPNOTSUPP); \
240 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
241 CERROR("obd_" #op ": dev %d no operation\n", \
242 (exp)->exp_obd->obd_minor); \
243 RETURN(-EOPNOTSUPP); \
247 #define CTXT_CHECK_OP(ctxt, op, err) \
249 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
251 CERROR("lop_" #op ": dev %d no operation\n", \
252 ctxt->loc_obd->obd_minor); \
257 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
258 void *key, __u32 *vallen, void *val)
263 EXP_CHECK_OP(exp, get_info);
264 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
266 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
270 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
271 void *key, obd_count vallen, void *val)
276 EXP_CHECK_OP(exp, set_info);
277 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
279 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
283 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
288 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
289 OBD_COUNTER_INCREMENT(obd, setup);
291 rc = OBP(obd, setup)(obd, datalen, data);
295 static inline int obd_precleanup(struct obd_device *obd, int cleanup_stage)
300 OBD_CHECK_OP(obd, precleanup, 0);
301 OBD_COUNTER_INCREMENT(obd, precleanup);
303 rc = OBP(obd, precleanup)(obd, cleanup_stage);
307 static inline int obd_cleanup(struct obd_device *obd)
313 OBD_CHECK_OP(obd, cleanup, 0);
314 OBD_COUNTER_INCREMENT(obd, cleanup);
316 rc = OBP(obd, cleanup)(obd);
321 obd_process_config(struct obd_device *obd, int datalen, void *data)
326 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
327 OBD_COUNTER_INCREMENT(obd, process_config);
329 rc = OBP(obd, process_config)(obd, datalen, data);
333 /* Pack an in-memory MD struct for storage on disk.
334 * Returns +ve size of packed MD (0 for free), or -ve error.
336 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
337 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
338 * If @*disk_tgt == NULL, it will be allocated
340 static inline int obd_packmd(struct obd_export *exp,
341 struct lov_mds_md **disk_tgt,
342 struct lov_stripe_md *mem_src)
347 EXP_CHECK_OP(exp, packmd);
348 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
350 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
354 static inline int obd_size_diskmd(struct obd_export *exp,
355 struct lov_stripe_md *mem_src)
357 return obd_packmd(exp, NULL, mem_src);
360 /* helper functions */
361 static inline int obd_alloc_diskmd(struct obd_export *exp,
362 struct lov_mds_md **disk_tgt)
365 LASSERT(*disk_tgt == NULL);
366 return obd_packmd(exp, disk_tgt, NULL);
369 static inline int obd_free_diskmd(struct obd_export *exp,
370 struct lov_mds_md **disk_tgt)
374 return obd_packmd(exp, disk_tgt, NULL);
377 /* Unpack an MD struct from disk to in-memory format.
378 * Returns +ve size of unpacked MD (0 for free), or -ve error.
380 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
381 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
382 * If @*mem_tgt == NULL, it will be allocated
384 static inline int obd_unpackmd(struct obd_export *exp,
385 struct lov_stripe_md **mem_tgt,
386 struct lov_mds_md *disk_src,
392 EXP_CHECK_OP(exp, unpackmd);
393 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
395 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
399 /* helper functions */
400 static inline int obd_alloc_memmd(struct obd_export *exp,
401 struct lov_stripe_md **mem_tgt)
404 LASSERT(*mem_tgt == NULL);
405 return obd_unpackmd(exp, mem_tgt, NULL, 0);
408 static inline int obd_free_memmd(struct obd_export *exp,
409 struct lov_stripe_md **mem_tgt)
413 return obd_unpackmd(exp, mem_tgt, NULL, 0);
416 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
417 struct lov_stripe_md **ea,
418 struct obd_trans_info *oti)
423 EXP_CHECK_OP(exp, create);
424 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
426 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
430 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
431 struct lov_stripe_md *ea,
432 struct obd_trans_info *oti)
437 EXP_CHECK_OP(exp, destroy);
438 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
440 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
444 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
445 struct lov_stripe_md *ea)
450 EXP_CHECK_OP(exp, getattr);
451 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
453 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
457 static inline int obd_getattr_async(struct obd_export *exp,
458 struct obdo *obdo, struct lov_stripe_md *ea,
459 struct ptlrpc_request_set *set)
464 EXP_CHECK_OP(exp, getattr);
465 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
467 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
471 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
472 struct lov_stripe_md *ea,
473 struct obd_trans_info *oti)
478 EXP_CHECK_OP(exp, setattr);
479 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
481 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
485 static inline int obd_setattr_async(struct obd_export *exp,
487 struct lov_stripe_md *ea,
488 struct obd_trans_info *oti)
493 EXP_CHECK_OP(exp, setattr_async);
494 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
496 rc = OBP(exp->exp_obd, setattr_async)(exp, obdo, ea, oti);
500 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
503 struct obd_device *obd = imp->imp_obd;
507 OBD_CHECK_DEV_ACTIVE(obd);
508 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
509 OBD_COUNTER_INCREMENT(obd, add_conn);
511 rc = OBP(obd, add_conn)(imp, uuid, priority);
515 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
517 struct obd_device *obd = imp->imp_obd;
521 OBD_CHECK_DEV_ACTIVE(obd);
522 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
523 OBD_COUNTER_INCREMENT(obd, del_conn);
525 rc = OBP(obd, del_conn)(imp, uuid);
529 static inline int obd_connect(struct lustre_handle *conn, struct obd_device *obd,
530 struct obd_uuid *cluuid,
531 struct obd_connect_data *data)
536 OBD_CHECK_DEV_ACTIVE(obd);
537 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
538 OBD_COUNTER_INCREMENT(obd, connect);
540 rc = OBP(obd, connect)(conn, obd, cluuid, data);
544 static inline int obd_disconnect(struct obd_export *exp)
549 EXP_CHECK_OP(exp, disconnect);
550 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
552 rc = OBP(exp->exp_obd, disconnect)(exp);
556 static inline int obd_init_export(struct obd_export *exp)
561 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
562 OBP((exp)->exp_obd, init_export))
563 rc = OBP(exp->exp_obd, init_export)(exp);
567 static inline int obd_destroy_export(struct obd_export *exp)
570 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
571 OBP((exp)->exp_obd, destroy_export))
572 OBP(exp->exp_obd, destroy_export)(exp);
576 static inline struct dentry *
577 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
579 LASSERT(exp->exp_obd);
581 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
586 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
589 /* @max_age is the oldest time in jiffies that we accept using a cached data.
590 * If the cache is older than @max_age we will get a new value from the
591 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
592 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
593 unsigned long max_age)
601 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
602 OBD_COUNTER_INCREMENT(obd, statfs);
604 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
605 if (time_before(obd->obd_osfs_age, max_age)) {
606 rc = OBP(obd, statfs)(obd, osfs, max_age);
608 spin_lock(&obd->obd_osfs_lock);
609 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
610 obd->obd_osfs_age = jiffies;
611 spin_unlock(&obd->obd_osfs_lock);
614 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
615 spin_lock(&obd->obd_osfs_lock);
616 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
617 spin_unlock(&obd->obd_osfs_lock);
622 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
623 struct lov_stripe_md *ea, obd_size start,
629 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
630 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
632 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
636 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
637 struct lov_stripe_md *ea, obd_size start,
638 obd_size end, struct obd_trans_info *oti)
643 EXP_CHECK_OP(exp, punch);
644 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
646 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
650 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
651 struct lov_stripe_md *ea, obd_count oa_bufs,
652 struct brw_page *pg, struct obd_trans_info *oti)
657 EXP_CHECK_OP(exp, brw);
658 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
660 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
661 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
662 "or OBD_BRW_CHECK\n");
666 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
670 static inline int obd_brw_async(int cmd, struct obd_export *exp,
671 struct obdo *oa, struct lov_stripe_md *ea,
672 obd_count oa_bufs, struct brw_page *pg,
673 struct ptlrpc_request_set *set,
674 struct obd_trans_info *oti)
679 EXP_CHECK_OP(exp, brw_async);
680 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
682 if (!(cmd & OBD_BRW_RWMASK)) {
683 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
687 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
692 static inline int obd_prep_async_page(struct obd_export *exp,
693 struct lov_stripe_md *lsm,
694 struct lov_oinfo *loi,
695 struct page *page, obd_off offset,
696 struct obd_async_page_ops *ops,
697 void *data, void **res)
702 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
703 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
705 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
710 static inline int obd_queue_async_io(struct obd_export *exp,
711 struct lov_stripe_md *lsm,
712 struct lov_oinfo *loi, void *cookie,
713 int cmd, obd_off off, int count,
714 obd_flag brw_flags, obd_flag async_flags)
719 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
720 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
721 LASSERT(cmd & OBD_BRW_RWMASK);
723 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
724 count, brw_flags, async_flags);
728 static inline int obd_set_async_flags(struct obd_export *exp,
729 struct lov_stripe_md *lsm,
730 struct lov_oinfo *loi, void *cookie,
731 obd_flag async_flags)
736 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
737 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
739 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
744 static inline int obd_queue_group_io(struct obd_export *exp,
745 struct lov_stripe_md *lsm,
746 struct lov_oinfo *loi,
747 struct obd_io_group *oig,
748 void *cookie, int cmd, obd_off off,
749 int count, obd_flag brw_flags,
750 obd_flag async_flags)
755 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
756 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
757 LASSERT(cmd & OBD_BRW_RWMASK);
759 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
760 cmd, off, count, brw_flags,
765 static inline int obd_trigger_group_io(struct obd_export *exp,
766 struct lov_stripe_md *lsm,
767 struct lov_oinfo *loi,
768 struct obd_io_group *oig)
773 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
774 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
776 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
780 static inline int obd_teardown_async_page(struct obd_export *exp,
781 struct lov_stripe_md *lsm,
782 struct lov_oinfo *loi, void *cookie)
787 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
788 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
790 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
794 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
795 int objcount, struct obd_ioobj *obj,
796 int niocount, struct niobuf_remote *remote,
797 struct niobuf_local *local,
798 struct obd_trans_info *oti)
803 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
804 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
806 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
811 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
812 int objcount, struct obd_ioobj *obj,
813 int niocount, struct niobuf_local *local,
814 struct obd_trans_info *oti, int rc)
818 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
819 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
821 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
826 /* b1_4_bug5047 has changes to make this an obd_merge_lvb() method */
827 __u64 lov_merge_size(struct lov_stripe_md *lsm, int kms_only);
828 __u64 lov_merge_blocks(struct lov_stripe_md *lsm);
829 __u64 lov_merge_mtime(struct lov_stripe_md *lsm, __u64 current_time);
831 static inline int obd_adjust_kms(struct obd_export *exp,
832 struct lov_stripe_md *lsm, obd_off size,
838 OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
839 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
841 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
845 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
846 int len, void *karg, void *uarg)
851 EXP_CHECK_OP(exp, iocontrol);
852 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
854 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
858 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
859 __u32 type, ldlm_policy_data_t *policy,
860 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
861 void *gl_cb, void *data, __u32 lvb_len,
862 void *lvb_swabber, struct lustre_handle *lockh)
867 EXP_CHECK_OP(exp, enqueue);
868 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
870 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
871 bl_cb, cp_cb, gl_cb, data, lvb_len,
876 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
877 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
878 int *flags, void *data, struct lustre_handle *lockh)
883 EXP_CHECK_OP(exp, match);
884 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
886 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
891 static inline int obd_change_cbdata(struct obd_export *exp,
892 struct lov_stripe_md *lsm,
893 ldlm_iterator_t it, void *data)
898 EXP_CHECK_OP(exp, change_cbdata);
899 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
901 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
905 static inline int obd_cancel(struct obd_export *exp,
906 struct lov_stripe_md *ea, __u32 mode,
907 struct lustre_handle *lockh)
912 EXP_CHECK_OP(exp, cancel);
913 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
915 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
919 static inline int obd_cancel_unused(struct obd_export *exp,
920 struct lov_stripe_md *ea, int flags,
926 EXP_CHECK_OP(exp, cancel_unused);
927 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
929 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
933 static inline int obd_join_lru(struct obd_export *exp,
934 struct lov_stripe_md *ea, int join)
939 EXP_CHECK_OP(exp, join_lru);
940 OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
942 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
946 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
948 int objcount, struct obd_ioobj *obj,
949 int niocount, struct niobuf_remote *remote)
953 EXP_CHECK_OP(exp, preprw);
954 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
956 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
958 class_export_put(exp);
962 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
963 int type, struct obd_client_handle *handle, int flag)
967 EXP_CHECK_OP(exp, pin);
968 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
970 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
974 static inline int obd_unpin(struct obd_export *exp,
975 struct obd_client_handle *handle, int flag)
979 EXP_CHECK_OP(exp, unpin);
980 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
982 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
987 static inline void obd_import_event(struct obd_device *obd,
988 struct obd_import *imp,
989 enum obd_import_event event)
992 CERROR("NULL device\n");
996 if (obd->obd_set_up && OBP(obd, import_event)) {
997 OBD_COUNTER_INCREMENT(obd, import_event);
998 OBP(obd, import_event)(obd, imp, event);
1002 static inline int obd_notify(struct obd_device *obd,
1003 struct obd_device *watched,
1007 if (!obd->obd_set_up) {
1008 CERROR("obd %s not set up\n", obd->obd_name);
1012 if (!OBP(obd, notify)) {
1013 CERROR("obd %s has no notify handler\n", obd->obd_name);
1017 OBD_COUNTER_INCREMENT(obd, notify);
1018 return OBP(obd, notify)(obd, watched, active);
1021 static inline int obd_quotacheck(struct obd_export *exp,
1022 struct obd_quotactl *oqctl)
1027 EXP_CHECK_OP(exp, quotacheck);
1028 OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1030 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1034 static inline int obd_quotactl(struct obd_export *exp,
1035 struct obd_quotactl *oqctl)
1040 EXP_CHECK_OP(exp, quotactl);
1041 OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1043 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1048 static inline int obd_register_observer(struct obd_device *obd,
1049 struct obd_device *observer)
1053 if (obd->obd_observer && observer)
1055 obd->obd_observer = observer;
1059 /* OBD Metadata Support */
1061 extern int obd_init_caches(void);
1062 extern void obd_cleanup_caches(void);
1064 /* support routines */
1065 extern kmem_cache_t *obdo_cachep;
1066 static inline struct obdo *obdo_alloc(void)
1070 OBD_SLAB_ALLOC(oa, obdo_cachep, SLAB_KERNEL, sizeof(*oa));
1075 /* qunit hash stuff */
1076 extern kmem_cache_t *qunit_cachep;
1077 extern struct list_head qunit_hash[];
1078 extern spinlock_t qunit_hash_lock;
1080 static inline void obdo_free(struct obdo *oa)
1082 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1085 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1086 #define to_kdev_t(dev) dev
1087 #define kdev_t_to_nr(dev) dev
1090 /* I'm as embarrassed about this as you are.
1092 * <shaver> // XXX do not look into _superhack with remaining eye
1093 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1094 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1095 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1098 extern void obd_sysctl_init (void);
1099 extern void obd_sysctl_clean (void);
1102 typedef __u8 class_uuid_t[16];
1103 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1104 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1107 int lustre_uuid_to_peer(char *uuid, ptl_nid_t *peer_nid);
1108 int class_add_uuid(char *uuid, __u64 nid);
1109 int class_del_uuid (char *uuid);
1110 void class_init_uuidlist(void);
1111 void class_exit_uuidlist(void);
1113 #endif /* __LINUX_OBD_CLASS_H */