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 void osic_release(struct obd_sync_io_container *osic);
73 int osic_wait(struct obd_sync_io_container *osic);
76 int class_process_config(struct lustre_cfg *lcfg);
77 int class_attach(struct lustre_cfg *lcfg);
78 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
79 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
80 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
82 /* Passed as data param to class_config_parse_llog */
83 struct config_llog_instance {
85 struct obd_uuid cfg_uuid;
86 ptl_nid_t cfg_local_nid;
88 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
89 struct config_llog_instance *cfg);
90 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
91 struct config_llog_instance *cfg);
93 struct lustre_profile {
94 struct list_head lp_list;
100 struct lustre_profile *class_get_profile(char * prof);
102 #define class_export_get(exp) \
104 struct obd_export *exp_ = exp; \
105 atomic_inc(&exp_->exp_refcount); \
106 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
107 atomic_read(&exp_->exp_refcount)); \
111 #define class_export_put(exp) \
113 LASSERT((exp) != NULL); \
114 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
115 atomic_read(&(exp)->exp_refcount) - 1); \
116 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
117 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
118 __class_export_put(exp); \
120 void __class_export_put(struct obd_export *);
121 struct obd_export *class_new_export(struct obd_device *obddev);
122 void class_unlink_export(struct obd_export *exp);
124 struct obd_import *class_import_get(struct obd_import *);
125 void class_import_put(struct obd_import *);
126 struct obd_import *class_new_import(void);
127 void class_destroy_import(struct obd_import *exp);
129 struct obd_type *class_get_type(char *name);
130 void class_put_type(struct obd_type *type);
131 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
132 struct obd_uuid *cluuid);
133 int class_disconnect(struct obd_export *exp, int failover);
134 void class_disconnect_exports(struct obd_device *obddev, int failover);
135 /* generic operations shared by various OBD types */
136 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
137 int class_multi_cleanup(struct obd_device *obddev);
141 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
142 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
143 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
144 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
145 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
147 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
148 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
149 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
151 static inline int obd_check_conn(struct lustre_handle *conn)
153 struct obd_device *obd;
155 CERROR("NULL conn\n");
159 obd = class_conn2obd(conn);
161 CERROR("NULL obd\n");
165 if (!obd->obd_attached) {
166 CERROR("obd %d not attached\n", obd->obd_minor);
170 if (!obd->obd_set_up) {
171 CERROR("obd %d not setup\n", obd->obd_minor);
175 if (!obd->obd_type) {
176 CERROR("obd %d not typed\n", obd->obd_minor);
180 if (!obd->obd_type->typ_ops) {
181 CERROR("obd_check_conn: obd %d no operations\n",
189 #define OBT(dev) (dev)->obd_type
190 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
191 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
193 /* Ensure obd_setup: used for disconnect which might be called while
194 an obd is stopping. */
195 #define OBD_CHECK_SETUP(conn, exp) \
198 CERROR("NULL connection\n"); \
202 exp = class_conn2export(conn); \
204 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
208 if (!(exp)->exp_obd->obd_set_up) { \
209 CERROR("Device %d not setup\n", \
210 (exp)->exp_obd->obd_minor); \
211 class_export_put(exp); \
216 /* Ensure obd_setup and !obd_stopping. */
217 #define OBD_CHECK_ACTIVE(conn, exp) \
220 CERROR("NULL connection\n"); \
224 exp = class_conn2export(conn); \
226 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
230 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
231 CERROR("Device %d not setup\n", \
232 (exp)->exp_obd->obd_minor); \
233 class_export_put(exp); \
238 /* Ensure obd_setup: used for cleanup which must be called
239 while obd is stopping */
240 #define OBD_CHECK_DEV_STOPPING(obd) \
243 CERROR("NULL device\n"); \
247 if (!(obd)->obd_set_up) { \
248 CERROR("Device %d not setup\n", \
253 if (!(obd)->obd_stopping) { \
254 CERROR("Device %d not stopping\n", \
260 /* ensure obd_setup and !obd_stopping */
261 #define OBD_CHECK_DEV_ACTIVE(obd) \
264 CERROR("NULL device\n"); \
268 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
269 CERROR("Device %d not setup\n", \
277 #define OBD_COUNTER_OFFSET(op) \
278 ((offsetof(struct obd_ops, o_ ## op) - \
279 offsetof(struct obd_ops, o_iocontrol)) \
280 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
282 #define OBD_COUNTER_INCREMENT(obd, op) \
283 if ((obd)->obd_stats != NULL) { \
284 unsigned int coffset; \
285 coffset = (unsigned int)(obd)->obd_cntr_base + \
286 OBD_COUNTER_OFFSET(op); \
287 LASSERT(coffset < obd->obd_stats->ls_num); \
288 lprocfs_counter_incr(obd->obd_stats, coffset); \
291 #define OBD_COUNTER_OFFSET(op)
292 #define OBD_COUNTER_INCREMENT(obd, op)
295 #define OBD_CHECK_OP(obd, op, err) \
297 if (!OBT(obd) || !OBP((obd), op)) {\
299 CERROR("obd_" #op ": dev %d no operation\n", \
305 #define EXP_CHECK_OP(exp, op) \
307 if ((exp) == NULL) { \
308 CERROR("obd_" #op ": NULL export\n"); \
311 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
312 CERROR("obd_" #op ": cleaned up obd\n"); \
313 RETURN(-EOPNOTSUPP); \
315 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
316 CERROR("obd_" #op ": dev %d no operation\n", \
317 (exp)->exp_obd->obd_minor); \
318 RETURN(-EOPNOTSUPP); \
322 #define CTXT_CHECK_OP(ctxt, op, err) \
324 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
326 CERROR("lop_" #op ": dev %d no operation\n", \
327 ctxt->loc_obd->obd_minor); \
332 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
333 void *key, __u32 *vallen, void *val)
338 EXP_CHECK_OP(exp, get_info);
339 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
341 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
345 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
346 void *key, obd_count vallen, void *val)
351 EXP_CHECK_OP(exp, set_info);
352 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
354 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
358 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
363 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
364 OBD_COUNTER_INCREMENT(obd, setup);
366 rc = OBP(obd, setup)(obd, datalen, data);
370 static inline int obd_postsetup(struct obd_device *obd)
375 OBD_CHECK_DEV_ACTIVE(obd);
376 OBD_CHECK_OP(obd, postsetup, 0);
377 OBD_COUNTER_INCREMENT(obd, postsetup);
379 rc = OBP(obd, postsetup)(obd);
383 static inline int obd_precleanup(struct obd_device *obd, int flags)
388 OBD_CHECK_OP(obd, precleanup, 0);
389 OBD_COUNTER_INCREMENT(obd, precleanup);
391 rc = OBP(obd, precleanup)(obd, flags);
395 static inline int obd_cleanup(struct obd_device *obd, int flags)
400 OBD_CHECK_DEV_STOPPING(obd);
401 OBD_CHECK_OP(obd, cleanup, 0);
402 OBD_COUNTER_INCREMENT(obd, cleanup);
404 rc = OBP(obd, cleanup)(obd, flags);
408 /* Pack an in-memory MD struct for storage on disk.
409 * Returns +ve size of packed MD (0 for free), or -ve error.
411 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
412 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
413 * If @*disk_tgt == NULL, it will be allocated
415 static inline int obd_packmd(struct obd_export *exp,
416 struct lov_mds_md **disk_tgt,
417 struct lov_stripe_md *mem_src)
422 EXP_CHECK_OP(exp, packmd);
423 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
425 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
429 static inline int obd_size_diskmd(struct obd_export *exp,
430 struct lov_stripe_md *mem_src)
432 return obd_packmd(exp, NULL, mem_src);
435 /* helper functions */
436 static inline int obd_alloc_diskmd(struct obd_export *exp,
437 struct lov_mds_md **disk_tgt)
440 LASSERT(*disk_tgt == NULL);
441 return obd_packmd(exp, disk_tgt, NULL);
444 static inline int obd_free_diskmd(struct obd_export *exp,
445 struct lov_mds_md **disk_tgt)
449 return obd_packmd(exp, disk_tgt, NULL);
452 /* Unpack an MD struct from disk to in-memory format.
453 * Returns +ve size of unpacked MD (0 for free), or -ve error.
455 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
456 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
457 * If @*mem_tgt == NULL, it will be allocated
459 static inline int obd_unpackmd(struct obd_export *exp,
460 struct lov_stripe_md **mem_tgt,
461 struct lov_mds_md *disk_src,
467 EXP_CHECK_OP(exp, unpackmd);
468 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
470 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
474 /* helper functions */
475 static inline int obd_alloc_memmd(struct obd_export *exp,
476 struct lov_stripe_md **mem_tgt)
479 LASSERT(*mem_tgt == NULL);
480 return obd_unpackmd(exp, mem_tgt, NULL, 0);
483 static inline int obd_free_memmd(struct obd_export *exp,
484 struct lov_stripe_md **mem_tgt)
488 return obd_unpackmd(exp, mem_tgt, NULL, 0);
491 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
492 struct lov_stripe_md **ea,
493 struct obd_trans_info *oti)
498 EXP_CHECK_OP(exp, create);
499 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
501 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
505 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
506 struct lov_stripe_md *ea,
507 struct obd_trans_info *oti)
512 EXP_CHECK_OP(exp, destroy);
513 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
515 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
519 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
520 struct lov_stripe_md *ea)
525 EXP_CHECK_OP(exp, getattr);
526 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
528 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
532 static inline int obd_getattr_async(struct obd_export *exp,
533 struct obdo *obdo, struct lov_stripe_md *ea,
534 struct ptlrpc_request_set *set)
539 EXP_CHECK_OP(exp, getattr);
540 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
542 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
546 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
547 struct lov_stripe_md *ea,
548 struct obd_trans_info *oti)
553 EXP_CHECK_OP(exp, setattr);
554 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
556 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
560 static inline int obd_connect(struct lustre_handle *conn,
561 struct obd_device *obd, struct obd_uuid *cluuid)
566 OBD_CHECK_DEV_ACTIVE(obd);
567 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
568 OBD_COUNTER_INCREMENT(obd, connect);
570 rc = OBP(obd, connect)(conn, obd, cluuid);
574 static inline int obd_disconnect(struct obd_export *exp, int flags)
579 EXP_CHECK_OP(exp, disconnect);
580 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
582 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
586 static inline int obd_init_export(struct obd_export *exp)
591 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
592 OBP((exp)->exp_obd, init_export))
593 rc = OBP(exp->exp_obd, init_export)(exp);
597 static inline int obd_destroy_export(struct obd_export *exp)
600 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
601 OBP((exp)->exp_obd, destroy_export))
602 OBP(exp->exp_obd, destroy_export)(exp);
606 static inline struct dentry *
607 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
609 LASSERT(exp->exp_obd);
611 return lvfs_fid2dentry(&exp->exp_obd->obd_ctxt, id_ino, gen, gr,
616 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
619 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
620 unsigned long max_age)
628 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
629 OBD_COUNTER_INCREMENT(obd, statfs);
631 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
632 if (time_before(obd->obd_osfs_age, max_age)) {
633 rc = OBP(obd, statfs)(obd, osfs, max_age);
634 spin_lock(&obd->obd_osfs_lock);
635 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
636 obd->obd_osfs_age = jiffies;
637 spin_unlock(&obd->obd_osfs_lock);
639 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
640 spin_lock(&obd->obd_osfs_lock);
641 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
642 spin_unlock(&obd->obd_osfs_lock);
647 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
648 struct lov_stripe_md *ea, obd_size start,
654 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
655 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
657 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
661 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
662 struct lov_stripe_md *ea, obd_size start,
663 obd_size end, struct obd_trans_info *oti)
668 EXP_CHECK_OP(exp, punch);
669 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
671 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
675 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
676 struct lov_stripe_md *ea, obd_count oa_bufs,
677 struct brw_page *pg, struct obd_trans_info *oti)
682 EXP_CHECK_OP(exp, brw);
683 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
685 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
686 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
687 "or OBD_BRW_CHECK\n");
691 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
695 static inline int obd_brw_async(int cmd, struct obd_export *exp,
696 struct obdo *oa, struct lov_stripe_md *ea,
697 obd_count oa_bufs, struct brw_page *pg,
698 struct ptlrpc_request_set *set,
699 struct obd_trans_info *oti)
704 EXP_CHECK_OP(exp, brw_async);
705 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
707 if (!(cmd & OBD_BRW_RWMASK)) {
708 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
712 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
717 static inline int obd_prep_async_page(struct obd_export *exp,
718 struct lov_stripe_md *lsm,
719 struct lov_oinfo *loi,
720 struct page *page, obd_off offset,
721 struct obd_async_page_ops *ops,
722 void *data, void **res)
727 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
728 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
730 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
735 static inline int obd_queue_async_io(struct obd_export *exp,
736 struct lov_stripe_md *lsm,
737 struct lov_oinfo *loi, void *cookie,
738 int cmd, obd_off off, int count,
739 obd_flag brw_flags, obd_flag async_flags)
744 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
745 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
746 LASSERT(cmd & OBD_BRW_RWMASK);
748 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
749 count, brw_flags, async_flags);
753 static inline int obd_set_async_flags(struct obd_export *exp,
754 struct lov_stripe_md *lsm,
755 struct lov_oinfo *loi, void *cookie,
756 obd_flag async_flags)
761 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
762 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
764 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
769 static inline int obd_queue_sync_io(struct obd_export *exp,
770 struct lov_stripe_md *lsm,
771 struct lov_oinfo *loi,
772 struct obd_sync_io_container *osic,
773 void *cookie, int cmd, obd_off off,
774 int count, obd_flag brw_flags)
779 OBD_CHECK_OP(exp->exp_obd, queue_sync_io, -EOPNOTSUPP);
780 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_sync_io);
781 LASSERT(cmd & OBD_BRW_RWMASK);
783 rc = OBP(exp->exp_obd, queue_sync_io)(exp, lsm, loi, osic, cookie,
784 cmd, off, count, brw_flags);
788 static inline int obd_trigger_sync_io(struct obd_export *exp,
789 struct lov_stripe_md *lsm,
790 struct lov_oinfo *loi,
791 struct obd_sync_io_container *osic)
796 OBD_CHECK_OP(exp->exp_obd, trigger_sync_io, -EOPNOTSUPP);
797 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_sync_io);
799 rc = OBP(exp->exp_obd, trigger_sync_io)(exp, lsm, loi, osic);
803 static inline int obd_teardown_async_page(struct obd_export *exp,
804 struct lov_stripe_md *lsm,
805 struct lov_oinfo *loi, void *cookie)
810 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
811 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
813 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
817 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
818 int objcount, struct obd_ioobj *obj,
819 int niocount, struct niobuf_remote *remote,
820 struct niobuf_local *local,
821 struct obd_trans_info *oti)
826 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
827 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
829 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
834 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
835 int objcount, struct obd_ioobj *obj,
836 int niocount, struct niobuf_local *local,
837 struct obd_trans_info *oti)
842 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
843 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
845 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
850 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
851 int len, void *karg, void *uarg)
856 EXP_CHECK_OP(exp, iocontrol);
857 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
859 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
863 static inline int obd_enqueue(struct obd_export *exp,
864 struct lov_stripe_md *ea,
865 struct lustre_handle *parent_lock,
866 __u32 type, void *cookie, int cookielen,
867 __u32 mode, int *flags, void *cb, void *data,
868 struct lustre_handle *lockh)
873 EXP_CHECK_OP(exp, enqueue);
874 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
876 rc = OBP(exp->exp_obd, enqueue)(exp, ea, parent_lock, type,
877 cookie, cookielen, mode, flags, cb,
882 static inline int obd_match(struct obd_export *exp,
883 struct lov_stripe_md *ea, __u32 type, void *cookie,
884 int cookielen, __u32 mode, int *flags, void *data,
885 struct lustre_handle *lockh)
890 EXP_CHECK_OP(exp, match);
891 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
893 rc = OBP(exp->exp_obd, match)(exp, ea, type, cookie, cookielen, mode,
899 static inline int obd_change_cbdata(struct obd_export *exp,
900 struct lov_stripe_md *lsm,
901 ldlm_iterator_t it, void *data)
906 EXP_CHECK_OP(exp, change_cbdata);
907 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
909 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
913 static inline int obd_cancel(struct obd_export *exp,
914 struct lov_stripe_md *ea, __u32 mode,
915 struct lustre_handle *lockh)
920 EXP_CHECK_OP(exp, cancel);
921 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
923 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
927 static inline int obd_cancel_unused(struct obd_export *exp,
928 struct lov_stripe_md *ea, int flags,
934 EXP_CHECK_OP(exp, cancel_unused);
935 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
937 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
942 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
944 int objcount, struct obd_ioobj *obj,
945 int niocount, struct niobuf_remote *remote)
949 EXP_CHECK_OP(exp, preprw);
950 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
952 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
954 class_export_put(exp);
958 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
959 int type, struct obd_client_handle *handle, int flag)
963 EXP_CHECK_OP(exp, pin);
964 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
966 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
970 static inline int obd_unpin(struct obd_export *exp,
971 struct obd_client_handle *handle, int flag)
975 EXP_CHECK_OP(exp, unpin);
976 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
978 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
982 static inline int obd_lock_contains(struct obd_export *exp,
983 struct lov_stripe_md *lsm,
984 struct ldlm_lock *lock, obd_off offset)
989 EXP_CHECK_OP(exp, lock_contains);
990 OBD_COUNTER_INCREMENT(exp->exp_obd, lock_contains);
992 rc = OBP(exp->exp_obd, lock_contains)(exp, lsm, lock, offset);
996 static inline void obd_invalidate_import(struct obd_device *obd,
997 struct obd_import *imp)
999 if (obd->obd_set_up && OBP(obd, invalidate_import)) {
1000 OBD_COUNTER_INCREMENT(obd, invalidate_import);
1001 OBP(obd, invalidate_import)(obd, imp);
1005 static inline int obd_notify(struct obd_device *obd,
1006 struct obd_device *watched,
1009 if (!obd->obd_set_up) {
1010 CERROR("obd %s not set up\n", obd->obd_name);
1014 if (!OBP(obd, notify)) {
1015 CERROR("obd %s has no notify handler\n", obd->obd_name);
1019 OBD_COUNTER_INCREMENT(obd, notify);
1020 return OBP(obd, notify)(obd, watched, active);
1023 static inline int obd_register_observer(struct obd_device *obd,
1024 struct obd_device *observer)
1027 if (obd->obd_observer && observer)
1029 obd->obd_observer = observer;
1033 /* OBD Metadata Support */
1035 extern int obd_init_caches(void);
1036 extern void obd_cleanup_caches(void);
1038 /* async page pushing io helpers */
1039 struct obd_client_page *ocp_alloc(struct page *page);
1040 void ocp_free(struct page *page);
1042 /* support routines */
1043 extern kmem_cache_t *obdo_cachep;
1044 static inline struct obdo *obdo_alloc(void)
1048 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1051 CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1052 memset(oa, 0, sizeof (*oa));
1057 static inline void obdo_free(struct obdo *oa)
1061 CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1062 kmem_cache_free(obdo_cachep, oa);
1065 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1066 #define to_kdev_t(dev) dev
1067 #define kdev_t_to_nr(dev) dev
1070 /* I'm as embarrassed about this as you are.
1072 * <shaver> // XXX do not look into _superhack with remaining eye
1073 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1074 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1075 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1077 struct obd_class_user_state {
1078 struct obd_device *ocus_current_obd;
1079 struct list_head ocus_conns;
1082 struct obd_class_user_conn {
1083 struct list_head ocuc_chain;
1084 struct obd_export *ocuc_exp;
1089 extern void obd_sysctl_init (void);
1090 extern void obd_sysctl_clean (void);
1093 typedef __u8 class_uuid_t[16];
1094 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1095 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1098 int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer);
1099 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1100 int class_del_uuid (char *uuid);
1101 void class_init_uuidlist(void);
1102 void class_exit_uuidlist(void);
1103 #endif /* __LINUX_OBD_CLASS_H */