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 struct osic_callback_context *occ);
72 void osic_complete_one(struct obd_sync_io_container *osic,
73 struct osic_callback_context *occ, int rc);
74 void osic_release(struct obd_sync_io_container *osic);
75 int osic_wait(struct obd_sync_io_container *osic);
78 int class_process_config(struct lustre_cfg *lcfg);
79 int class_attach(struct lustre_cfg *lcfg);
80 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
81 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
82 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
84 /* Passed as data param to class_config_parse_llog */
85 struct config_llog_instance {
87 struct obd_uuid cfg_uuid;
88 ptl_nid_t cfg_local_nid;
90 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
91 struct config_llog_instance *cfg);
92 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
93 struct config_llog_instance *cfg);
95 struct lustre_profile {
96 struct list_head lp_list;
102 struct lustre_profile *class_get_profile(char * prof);
104 #define class_export_get(exp) \
106 struct obd_export *exp_ = exp; \
107 atomic_inc(&exp_->exp_refcount); \
108 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
109 atomic_read(&exp_->exp_refcount)); \
113 #define class_export_put(exp) \
115 LASSERT((exp) != NULL); \
116 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
117 atomic_read(&(exp)->exp_refcount) - 1); \
118 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
119 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
120 __class_export_put(exp); \
122 void __class_export_put(struct obd_export *);
123 struct obd_export *class_new_export(struct obd_device *obddev);
124 void class_unlink_export(struct obd_export *exp);
126 struct obd_import *class_import_get(struct obd_import *);
127 void class_import_put(struct obd_import *);
128 struct obd_import *class_new_import(void);
129 void class_destroy_import(struct obd_import *exp);
131 struct obd_type *class_get_type(char *name);
132 void class_put_type(struct obd_type *type);
133 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
134 struct obd_uuid *cluuid);
135 int class_disconnect(struct obd_export *exp, int failover);
136 void class_disconnect_exports(struct obd_device *obddev, int failover);
137 /* generic operations shared by various OBD types */
138 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
139 int class_multi_cleanup(struct obd_device *obddev);
143 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
144 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
145 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
146 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
147 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
149 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
150 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
151 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
153 static inline int obd_check_conn(struct lustre_handle *conn)
155 struct obd_device *obd;
157 CERROR("NULL conn\n");
161 obd = class_conn2obd(conn);
163 CERROR("NULL obd\n");
167 if (!obd->obd_attached) {
168 CERROR("obd %d not attached\n", obd->obd_minor);
172 if (!obd->obd_set_up) {
173 CERROR("obd %d not setup\n", obd->obd_minor);
177 if (!obd->obd_type) {
178 CERROR("obd %d not typed\n", obd->obd_minor);
182 if (!obd->obd_type->typ_ops) {
183 CERROR("obd_check_conn: obd %d no operations\n",
191 #define OBT(dev) (dev)->obd_type
192 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
193 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
195 /* Ensure obd_setup: used for disconnect which might be called while
196 an obd is stopping. */
197 #define OBD_CHECK_SETUP(conn, exp) \
200 CERROR("NULL connection\n"); \
204 exp = class_conn2export(conn); \
206 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
210 if (!(exp)->exp_obd->obd_set_up) { \
211 CERROR("Device %d not setup\n", \
212 (exp)->exp_obd->obd_minor); \
213 class_export_put(exp); \
218 /* Ensure obd_setup and !obd_stopping. */
219 #define OBD_CHECK_ACTIVE(conn, exp) \
222 CERROR("NULL connection\n"); \
226 exp = class_conn2export(conn); \
228 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
232 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
233 CERROR("Device %d not setup\n", \
234 (exp)->exp_obd->obd_minor); \
235 class_export_put(exp); \
240 /* Ensure obd_setup: used for cleanup which must be called
241 while obd is stopping */
242 #define OBD_CHECK_DEV_STOPPING(obd) \
245 CERROR("NULL device\n"); \
249 if (!(obd)->obd_set_up) { \
250 CERROR("Device %d not setup\n", \
255 if (!(obd)->obd_stopping) { \
256 CERROR("Device %d not stopping\n", \
262 /* ensure obd_setup and !obd_stopping */
263 #define OBD_CHECK_DEV_ACTIVE(obd) \
266 CERROR("NULL device\n"); \
270 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
271 CERROR("Device %d not setup\n", \
279 #define OBD_COUNTER_OFFSET(op) \
280 ((offsetof(struct obd_ops, o_ ## op) - \
281 offsetof(struct obd_ops, o_iocontrol)) \
282 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
284 #define OBD_COUNTER_INCREMENT(obd, op) \
285 if ((obd)->obd_stats != NULL) { \
286 unsigned int coffset; \
287 coffset = (unsigned int)(obd)->obd_cntr_base + \
288 OBD_COUNTER_OFFSET(op); \
289 LASSERT(coffset < obd->obd_stats->ls_num); \
290 lprocfs_counter_incr(obd->obd_stats, coffset); \
293 #define OBD_COUNTER_OFFSET(op)
294 #define OBD_COUNTER_INCREMENT(obd, op)
297 #define OBD_CHECK_OP(obd, op, err) \
299 if (!OBT(obd) || !OBP((obd), op)) {\
301 CERROR("obd_" #op ": dev %d no operation\n", \
307 #define EXP_CHECK_OP(exp, op) \
309 if ((exp) == NULL) { \
310 CERROR("obd_" #op ": NULL export\n"); \
313 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
314 CERROR("obd_" #op ": cleaned up obd\n"); \
315 RETURN(-EOPNOTSUPP); \
317 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
318 CERROR("obd_" #op ": dev %d no operation\n", \
319 (exp)->exp_obd->obd_minor); \
320 RETURN(-EOPNOTSUPP); \
324 #define CTXT_CHECK_OP(ctxt, op, err) \
326 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
328 CERROR("lop_" #op ": dev %d no operation\n", \
329 ctxt->loc_obd->obd_minor); \
334 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
335 void *key, __u32 *vallen, void *val)
340 EXP_CHECK_OP(exp, get_info);
341 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
343 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
347 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
348 void *key, obd_count vallen, void *val)
353 EXP_CHECK_OP(exp, set_info);
354 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
356 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
360 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
365 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
366 OBD_COUNTER_INCREMENT(obd, setup);
368 rc = OBP(obd, setup)(obd, datalen, data);
372 static inline int obd_postsetup(struct obd_device *obd)
377 OBD_CHECK_DEV_ACTIVE(obd);
378 OBD_CHECK_OP(obd, postsetup, 0);
379 OBD_COUNTER_INCREMENT(obd, postsetup);
381 rc = OBP(obd, postsetup)(obd);
385 static inline int obd_precleanup(struct obd_device *obd, int flags)
390 OBD_CHECK_OP(obd, precleanup, 0);
391 OBD_COUNTER_INCREMENT(obd, precleanup);
393 rc = OBP(obd, precleanup)(obd, flags);
397 static inline int obd_cleanup(struct obd_device *obd, int flags)
402 OBD_CHECK_DEV_STOPPING(obd);
403 OBD_CHECK_OP(obd, cleanup, 0);
404 OBD_COUNTER_INCREMENT(obd, cleanup);
406 rc = OBP(obd, cleanup)(obd, flags);
410 /* Pack an in-memory MD struct for storage on disk.
411 * Returns +ve size of packed MD (0 for free), or -ve error.
413 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
414 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
415 * If @*disk_tgt == NULL, it will be allocated
417 static inline int obd_packmd(struct obd_export *exp,
418 struct lov_mds_md **disk_tgt,
419 struct lov_stripe_md *mem_src)
424 EXP_CHECK_OP(exp, packmd);
425 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
427 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
431 static inline int obd_size_diskmd(struct obd_export *exp,
432 struct lov_stripe_md *mem_src)
434 return obd_packmd(exp, NULL, mem_src);
437 /* helper functions */
438 static inline int obd_alloc_diskmd(struct obd_export *exp,
439 struct lov_mds_md **disk_tgt)
442 LASSERT(*disk_tgt == NULL);
443 return obd_packmd(exp, disk_tgt, NULL);
446 static inline int obd_free_diskmd(struct obd_export *exp,
447 struct lov_mds_md **disk_tgt)
451 return obd_packmd(exp, disk_tgt, NULL);
454 /* Unpack an MD struct from disk to in-memory format.
455 * Returns +ve size of unpacked MD (0 for free), or -ve error.
457 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
458 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
459 * If @*mem_tgt == NULL, it will be allocated
461 static inline int obd_unpackmd(struct obd_export *exp,
462 struct lov_stripe_md **mem_tgt,
463 struct lov_mds_md *disk_src,
469 EXP_CHECK_OP(exp, unpackmd);
470 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
472 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
476 /* helper functions */
477 static inline int obd_alloc_memmd(struct obd_export *exp,
478 struct lov_stripe_md **mem_tgt)
481 LASSERT(*mem_tgt == NULL);
482 return obd_unpackmd(exp, mem_tgt, NULL, 0);
485 static inline int obd_free_memmd(struct obd_export *exp,
486 struct lov_stripe_md **mem_tgt)
490 return obd_unpackmd(exp, mem_tgt, NULL, 0);
493 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
494 struct lov_stripe_md **ea,
495 struct obd_trans_info *oti)
500 EXP_CHECK_OP(exp, create);
501 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
503 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
507 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
508 struct lov_stripe_md *ea,
509 struct obd_trans_info *oti)
514 EXP_CHECK_OP(exp, destroy);
515 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
517 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
521 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
522 struct lov_stripe_md *ea)
527 EXP_CHECK_OP(exp, getattr);
528 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
530 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
534 static inline int obd_getattr_async(struct obd_export *exp,
535 struct obdo *obdo, struct lov_stripe_md *ea,
536 struct ptlrpc_request_set *set)
541 EXP_CHECK_OP(exp, getattr);
542 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
544 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
548 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
549 struct lov_stripe_md *ea,
550 struct obd_trans_info *oti)
555 EXP_CHECK_OP(exp, setattr);
556 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
558 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
562 static inline int obd_connect(struct lustre_handle *conn,
563 struct obd_device *obd, struct obd_uuid *cluuid)
568 OBD_CHECK_DEV_ACTIVE(obd);
569 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
570 OBD_COUNTER_INCREMENT(obd, connect);
572 rc = OBP(obd, connect)(conn, obd, cluuid);
576 static inline int obd_disconnect(struct obd_export *exp, int flags)
581 EXP_CHECK_OP(exp, disconnect);
582 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
584 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
588 static inline int obd_init_export(struct obd_export *exp)
593 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
594 OBP((exp)->exp_obd, init_export))
595 rc = OBP(exp->exp_obd, init_export)(exp);
599 static inline int obd_destroy_export(struct obd_export *exp)
602 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
603 OBP((exp)->exp_obd, destroy_export))
604 OBP(exp->exp_obd, destroy_export)(exp);
608 static inline struct dentry *
609 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
611 LASSERT(exp->exp_obd);
613 return lvfs_fid2dentry(&exp->exp_obd->obd_ctxt, id_ino, gen, gr,
618 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
621 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
622 unsigned long max_age)
630 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
631 OBD_COUNTER_INCREMENT(obd, statfs);
633 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
634 if (obd->obd_osfs_age == 0 || time_before(obd->obd_osfs_age, max_age)) {
635 rc = OBP(obd, statfs)(obd, osfs, max_age);
636 spin_lock(&obd->obd_dev_lock);
637 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
638 obd->obd_osfs_age = jiffies;
639 spin_unlock(&obd->obd_dev_lock);
641 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
642 spin_lock(&obd->obd_dev_lock);
643 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
644 spin_unlock(&obd->obd_dev_lock);
649 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
650 struct lov_stripe_md *ea, obd_size start,
656 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
657 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
659 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
663 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
664 struct lov_stripe_md *ea, obd_size start,
665 obd_size end, struct obd_trans_info *oti)
670 EXP_CHECK_OP(exp, punch);
671 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
673 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
677 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
678 struct lov_stripe_md *ea, obd_count oa_bufs,
679 struct brw_page *pg, struct obd_trans_info *oti)
684 EXP_CHECK_OP(exp, brw);
685 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
687 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
688 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
689 "or OBD_BRW_CHECK\n");
693 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
697 static inline int obd_brw_async(int cmd, struct obd_export *exp,
698 struct obdo *oa, struct lov_stripe_md *ea,
699 obd_count oa_bufs, struct brw_page *pg,
700 struct ptlrpc_request_set *set,
701 struct obd_trans_info *oti)
706 EXP_CHECK_OP(exp, brw_async);
707 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
709 if (!(cmd & OBD_BRW_RWMASK)) {
710 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
714 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
719 static inline int obd_prep_async_page(struct obd_export *exp,
720 struct lov_stripe_md *lsm,
721 struct lov_oinfo *loi,
722 struct page *page, obd_off offset,
723 struct obd_async_page_ops *ops,
724 void *data, void **res)
729 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
730 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
732 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
737 static inline int obd_queue_async_io(struct obd_export *exp,
738 struct lov_stripe_md *lsm,
739 struct lov_oinfo *loi, void *cookie,
740 int cmd, obd_off off, int count,
741 obd_flag brw_flags, obd_flag async_flags)
746 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
747 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
748 LASSERT(cmd & OBD_BRW_RWMASK);
750 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
751 count, brw_flags, async_flags);
755 static inline int obd_set_async_flags(struct obd_export *exp,
756 struct lov_stripe_md *lsm,
757 struct lov_oinfo *loi, void *cookie,
758 obd_flag async_flags)
763 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
764 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
766 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
771 static inline int obd_queue_sync_io(struct obd_export *exp,
772 struct lov_stripe_md *lsm,
773 struct lov_oinfo *loi,
774 struct obd_sync_io_container *osic,
775 void *cookie, int cmd, obd_off off,
776 int count, obd_flag brw_flags)
781 OBD_CHECK_OP(exp->exp_obd, queue_sync_io, -EOPNOTSUPP);
782 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_sync_io);
783 LASSERT(cmd & OBD_BRW_RWMASK);
785 rc = OBP(exp->exp_obd, queue_sync_io)(exp, lsm, loi, osic, cookie,
786 cmd, off, count, brw_flags);
790 static inline int obd_trigger_sync_io(struct obd_export *exp,
791 struct lov_stripe_md *lsm,
792 struct lov_oinfo *loi,
793 struct obd_sync_io_container *osic)
798 OBD_CHECK_OP(exp->exp_obd, trigger_sync_io, -EOPNOTSUPP);
799 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_sync_io);
801 rc = OBP(exp->exp_obd, trigger_sync_io)(exp, lsm, loi, osic);
805 static inline int obd_teardown_async_page(struct obd_export *exp,
806 struct lov_stripe_md *lsm,
807 struct lov_oinfo *loi, void *cookie)
812 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
813 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
815 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
819 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
820 int objcount, struct obd_ioobj *obj,
821 int niocount, struct niobuf_remote *remote,
822 struct niobuf_local *local,
823 struct obd_trans_info *oti)
828 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
829 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
831 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
836 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
837 int objcount, struct obd_ioobj *obj,
838 int niocount, struct niobuf_local *local,
839 struct obd_trans_info *oti)
844 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
845 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
847 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
852 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
853 int len, void *karg, void *uarg)
858 EXP_CHECK_OP(exp, iocontrol);
859 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
861 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
865 static inline int obd_enqueue(struct obd_export *exp,
866 struct lov_stripe_md *ea,
867 struct lustre_handle *parent_lock,
868 __u32 type, void *cookie, int cookielen,
869 __u32 mode, int *flags, void *cb, void *data,
870 struct lustre_handle *lockh)
875 EXP_CHECK_OP(exp, enqueue);
876 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
878 rc = OBP(exp->exp_obd, enqueue)(exp, ea, parent_lock, type,
879 cookie, cookielen, mode, flags, cb,
884 static inline int obd_match(struct obd_export *exp,
885 struct lov_stripe_md *ea, __u32 type, void *cookie,
886 int cookielen, __u32 mode, int *flags, void *data,
887 struct lustre_handle *lockh)
892 EXP_CHECK_OP(exp, match);
893 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
895 rc = OBP(exp->exp_obd, match)(exp, ea, type, cookie, cookielen, mode,
901 static inline int obd_change_cbdata(struct obd_export *exp,
902 struct lov_stripe_md *lsm,
903 ldlm_iterator_t it, void *data)
908 EXP_CHECK_OP(exp, change_cbdata);
909 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
911 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
915 static inline int obd_cancel(struct obd_export *exp,
916 struct lov_stripe_md *ea, __u32 mode,
917 struct lustre_handle *lockh)
922 EXP_CHECK_OP(exp, cancel);
923 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
925 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
929 static inline int obd_cancel_unused(struct obd_export *exp,
930 struct lov_stripe_md *ea, int flags,
936 EXP_CHECK_OP(exp, cancel_unused);
937 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
939 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
944 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
946 int objcount, struct obd_ioobj *obj,
947 int niocount, struct niobuf_remote *remote)
951 EXP_CHECK_OP(exp, preprw);
952 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
954 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
956 class_export_put(exp);
960 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
961 int type, struct obd_client_handle *handle, int flag)
965 EXP_CHECK_OP(exp, pin);
966 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
968 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
972 static inline int obd_unpin(struct obd_export *exp,
973 struct obd_client_handle *handle, int flag)
977 EXP_CHECK_OP(exp, unpin);
978 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
980 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
984 static inline int obd_lock_contains(struct obd_export *exp,
985 struct lov_stripe_md *lsm,
986 struct ldlm_lock *lock, obd_off offset)
991 EXP_CHECK_OP(exp, lock_contains);
992 OBD_COUNTER_INCREMENT(exp->exp_obd, lock_contains);
994 rc = OBP(exp->exp_obd, lock_contains)(exp, lsm, lock, offset);
998 static inline void obd_invalidate_import(struct obd_device *obd,
999 struct obd_import *imp)
1001 if (obd->obd_set_up && OBP(obd, invalidate_import)) {
1002 OBD_COUNTER_INCREMENT(obd, invalidate_import);
1003 OBP(obd, invalidate_import)(obd, imp);
1007 static inline int obd_notify(struct obd_device *obd,
1008 struct obd_device *watched,
1011 if (!obd->obd_set_up) {
1012 CERROR("obd %s not set up\n", obd->obd_name);
1016 if (!OBP(obd, notify)) {
1017 CERROR("obd %s has no notify handler\n", obd->obd_name);
1021 OBD_COUNTER_INCREMENT(obd, notify);
1022 return OBP(obd, notify)(obd, watched, active);
1025 static inline int obd_register_observer(struct obd_device *obd,
1026 struct obd_device *observer)
1029 if (obd->obd_observer && observer)
1031 obd->obd_observer = observer;
1035 /* OBD Metadata Support */
1037 extern int obd_init_caches(void);
1038 extern void obd_cleanup_caches(void);
1040 /* support routines */
1041 extern kmem_cache_t *obdo_cachep;
1042 static inline struct obdo *obdo_alloc(void)
1046 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1049 CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1050 memset(oa, 0, sizeof (*oa));
1055 static inline void obdo_free(struct obdo *oa)
1059 CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1060 kmem_cache_free(obdo_cachep, oa);
1063 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1064 #define to_kdev_t(dev) dev
1065 #define kdev_t_to_nr(dev) dev
1068 /* I'm as embarrassed about this as you are.
1070 * <shaver> // XXX do not look into _superhack with remaining eye
1071 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1072 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1073 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1076 extern void obd_sysctl_init (void);
1077 extern void obd_sysctl_clean (void);
1080 typedef __u8 class_uuid_t[16];
1081 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1082 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1085 int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer);
1086 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1087 int class_del_uuid (char *uuid);
1088 void class_init_uuidlist(void);
1089 void class_exit_uuidlist(void);
1090 #endif /* __LINUX_OBD_CLASS_H */