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);
68 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
71 void osic_init(struct obd_sync_io_container **osic);
72 void osic_add_one(struct obd_sync_io_container *osic,
73 struct osic_callback_context *occ);
74 void osic_complete_one(struct obd_sync_io_container *osic,
75 struct osic_callback_context *occ, int rc);
76 void osic_release(struct obd_sync_io_container *osic);
77 int osic_wait(struct obd_sync_io_container *osic);
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_ctxt, id_ino, gen, gr,
608 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
611 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
612 unsigned long max_age)
620 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
621 OBD_COUNTER_INCREMENT(obd, statfs);
623 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
624 if (obd->obd_osfs_age == 0 || time_before(obd->obd_osfs_age, max_age)) {
625 rc = OBP(obd, statfs)(obd, osfs, max_age);
626 spin_lock(&obd->obd_dev_lock);
627 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
628 obd->obd_osfs_age = jiffies;
629 spin_unlock(&obd->obd_dev_lock);
631 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
632 spin_lock(&obd->obd_dev_lock);
633 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
634 spin_unlock(&obd->obd_dev_lock);
639 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
640 struct lov_stripe_md *ea, obd_size start,
646 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
647 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
649 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
653 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
654 struct lov_stripe_md *ea, obd_size start,
655 obd_size end, struct obd_trans_info *oti)
660 EXP_CHECK_OP(exp, punch);
661 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
663 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
667 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
668 struct lov_stripe_md *ea, obd_count oa_bufs,
669 struct brw_page *pg, struct obd_trans_info *oti)
674 EXP_CHECK_OP(exp, brw);
675 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
677 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
678 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
679 "or OBD_BRW_CHECK\n");
683 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
687 static inline int obd_brw_async(int cmd, struct obd_export *exp,
688 struct obdo *oa, struct lov_stripe_md *ea,
689 obd_count oa_bufs, struct brw_page *pg,
690 struct ptlrpc_request_set *set,
691 struct obd_trans_info *oti)
696 EXP_CHECK_OP(exp, brw_async);
697 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
699 if (!(cmd & OBD_BRW_RWMASK)) {
700 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
704 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
709 static inline int obd_prep_async_page(struct obd_export *exp,
710 struct lov_stripe_md *lsm,
711 struct lov_oinfo *loi,
712 struct page *page, obd_off offset,
713 struct obd_async_page_ops *ops,
714 void *data, void **res)
719 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
720 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
722 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
727 static inline int obd_queue_async_io(struct obd_export *exp,
728 struct lov_stripe_md *lsm,
729 struct lov_oinfo *loi, void *cookie,
730 int cmd, obd_off off, int count,
731 obd_flag brw_flags, obd_flag async_flags)
736 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
737 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
738 LASSERT(cmd & OBD_BRW_RWMASK);
740 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
741 count, brw_flags, async_flags);
745 static inline int obd_set_async_flags(struct obd_export *exp,
746 struct lov_stripe_md *lsm,
747 struct lov_oinfo *loi, void *cookie,
748 obd_flag async_flags)
753 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
754 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
756 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
761 static inline int obd_queue_sync_io(struct obd_export *exp,
762 struct lov_stripe_md *lsm,
763 struct lov_oinfo *loi,
764 struct obd_sync_io_container *osic,
765 void *cookie, int cmd, obd_off off,
766 int count, obd_flag brw_flags)
771 OBD_CHECK_OP(exp->exp_obd, queue_sync_io, -EOPNOTSUPP);
772 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_sync_io);
773 LASSERT(cmd & OBD_BRW_RWMASK);
775 rc = OBP(exp->exp_obd, queue_sync_io)(exp, lsm, loi, osic, cookie,
776 cmd, off, count, brw_flags);
780 static inline int obd_trigger_sync_io(struct obd_export *exp,
781 struct lov_stripe_md *lsm,
782 struct lov_oinfo *loi,
783 struct obd_sync_io_container *osic)
788 OBD_CHECK_OP(exp->exp_obd, trigger_sync_io, -EOPNOTSUPP);
789 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_sync_io);
791 rc = OBP(exp->exp_obd, trigger_sync_io)(exp, lsm, loi, osic);
795 static inline int obd_teardown_async_page(struct obd_export *exp,
796 struct lov_stripe_md *lsm,
797 struct lov_oinfo *loi, void *cookie)
802 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
803 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
805 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
809 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
810 int objcount, struct obd_ioobj *obj,
811 int niocount, struct niobuf_remote *remote,
812 struct niobuf_local *local,
813 struct obd_trans_info *oti)
818 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
819 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
821 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
826 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
827 int objcount, struct obd_ioobj *obj,
828 int niocount, struct niobuf_local *local,
829 struct obd_trans_info *oti)
834 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
835 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
837 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
842 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
843 int len, void *karg, void *uarg)
848 EXP_CHECK_OP(exp, iocontrol);
849 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
851 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
855 static inline int obd_enqueue(struct obd_export *exp,
856 struct lov_stripe_md *ea,
857 struct lustre_handle *parent_lock,
858 __u32 type, void *cookie, int cookielen,
859 __u32 mode, int *flags, void *cb, void *data,
860 struct lustre_handle *lockh)
865 EXP_CHECK_OP(exp, enqueue);
866 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
868 rc = OBP(exp->exp_obd, enqueue)(exp, ea, parent_lock, type,
869 cookie, cookielen, mode, flags, cb,
874 static inline int obd_match(struct obd_export *exp,
875 struct lov_stripe_md *ea, __u32 type, void *cookie,
876 int cookielen, __u32 mode, int *flags, void *data,
877 struct lustre_handle *lockh)
882 EXP_CHECK_OP(exp, match);
883 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
885 rc = OBP(exp->exp_obd, match)(exp, ea, type, cookie, cookielen, mode,
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);
934 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
936 int objcount, struct obd_ioobj *obj,
937 int niocount, struct niobuf_remote *remote)
941 EXP_CHECK_OP(exp, preprw);
942 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
944 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
946 class_export_put(exp);
950 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
951 int type, struct obd_client_handle *handle, int flag)
955 EXP_CHECK_OP(exp, pin);
956 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
958 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
962 static inline int obd_unpin(struct obd_export *exp,
963 struct obd_client_handle *handle, int flag)
967 EXP_CHECK_OP(exp, unpin);
968 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
970 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
974 static inline int obd_lock_contains(struct obd_export *exp,
975 struct lov_stripe_md *lsm,
976 struct ldlm_lock *lock, obd_off offset)
981 EXP_CHECK_OP(exp, lock_contains);
982 OBD_COUNTER_INCREMENT(exp->exp_obd, lock_contains);
984 rc = OBP(exp->exp_obd, lock_contains)(exp, lsm, lock, offset);
988 static inline void obd_invalidate_import(struct obd_device *obd,
989 struct obd_import *imp)
991 if (obd->obd_set_up && OBP(obd, invalidate_import)) {
992 OBD_COUNTER_INCREMENT(obd, invalidate_import);
993 OBP(obd, invalidate_import)(obd, imp);
997 static inline int obd_notify(struct obd_device *obd,
998 struct obd_device *watched,
1001 if (!obd->obd_set_up) {
1002 CERROR("obd %s not set up\n", obd->obd_name);
1006 if (!OBP(obd, notify)) {
1007 CERROR("obd %s has no notify handler\n", obd->obd_name);
1011 OBD_COUNTER_INCREMENT(obd, notify);
1012 return OBP(obd, notify)(obd, watched, active);
1015 static inline int obd_register_observer(struct obd_device *obd,
1016 struct obd_device *observer)
1019 if (obd->obd_observer && observer)
1021 obd->obd_observer = observer;
1025 /* OBD Metadata Support */
1027 extern int obd_init_caches(void);
1028 extern void obd_cleanup_caches(void);
1030 /* support routines */
1031 extern kmem_cache_t *obdo_cachep;
1032 static inline struct obdo *obdo_alloc(void)
1036 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1039 CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1040 memset(oa, 0, sizeof (*oa));
1045 static inline void obdo_free(struct obdo *oa)
1049 CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1050 kmem_cache_free(obdo_cachep, oa);
1053 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1054 #define to_kdev_t(dev) dev
1055 #define kdev_t_to_nr(dev) dev
1058 /* I'm as embarrassed about this as you are.
1060 * <shaver> // XXX do not look into _superhack with remaining eye
1061 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1062 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1063 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1066 extern void obd_sysctl_init (void);
1067 extern void obd_sysctl_clean (void);
1070 typedef __u8 class_uuid_t[16];
1071 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1072 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1075 int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer);
1076 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1077 int class_del_uuid (char *uuid);
1078 void class_init_uuidlist(void);
1079 void class_exit_uuidlist(void);
1080 #endif /* __LINUX_OBD_CLASS_H */