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 int class_process_config(struct lustre_cfg *lcfg);
85 int class_attach(struct lustre_cfg *lcfg);
86 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
87 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
88 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
89 void class_decref(struct obd_device *obd);
91 /* Passed as data param to class_config_parse_llog */
92 struct config_llog_instance {
94 struct obd_uuid cfg_uuid;
95 ptl_nid_t cfg_local_nid;
97 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
98 struct config_llog_instance *cfg);
99 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
100 struct config_llog_instance *cfg);
102 struct lustre_profile {
103 struct list_head lp_list;
109 struct lustre_profile *class_get_profile(char * prof);
110 void class_del_profile(char *prof);
112 #define class_export_get(exp) \
114 struct obd_export *exp_ = exp; \
115 atomic_inc(&exp_->exp_refcount); \
116 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
117 atomic_read(&exp_->exp_refcount)); \
121 #define class_export_put(exp) \
123 LASSERT((exp) != NULL); \
124 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
125 atomic_read(&(exp)->exp_refcount) - 1); \
126 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
127 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
128 __class_export_put(exp); \
130 void __class_export_put(struct obd_export *);
131 struct obd_export *class_new_export(struct obd_device *obddev);
132 void class_unlink_export(struct obd_export *exp);
133 void class_update_export_timer(struct obd_export *exp, time_t extra_delay);
135 struct obd_import *class_import_get(struct obd_import *);
136 void class_import_put(struct obd_import *);
137 struct obd_import *class_new_import(void);
138 void class_destroy_import(struct obd_import *exp);
140 struct obd_type *class_get_type(char *name);
141 void class_put_type(struct obd_type *type);
142 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
143 struct obd_uuid *cluuid);
144 int class_disconnect(struct obd_export *exp);
145 void class_disconnect_exports(struct obd_device *obddev);
146 void class_disconnect_stale_exports(struct obd_device *obddev);
147 /* generic operations shared by various OBD types */
148 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
149 int class_multi_cleanup(struct obd_device *obddev);
153 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
154 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
155 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
156 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
157 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
159 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
160 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
161 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
164 void ping_evictor_start(void);
165 void ping_evictor_stop(void);
168 #define OBT(dev) (dev)->obd_type
169 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
170 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
172 /* Ensure obd_setup: used for cleanup which must be called
173 while obd is stopping */
174 #define OBD_CHECK_DEV(obd) \
177 CERROR("NULL device\n"); \
182 /* ensure obd_setup and !obd_stopping */
183 #define OBD_CHECK_DEV_ACTIVE(obd) \
185 OBD_CHECK_DEV(obd); \
186 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
187 CERROR("Device %d not setup\n", \
195 #define OBD_COUNTER_OFFSET(op) \
196 ((offsetof(struct obd_ops, o_ ## op) - \
197 offsetof(struct obd_ops, o_iocontrol)) \
198 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
200 #define OBD_COUNTER_INCREMENT(obd, op) \
201 if ((obd)->obd_stats != NULL) { \
202 unsigned int coffset; \
203 coffset = (unsigned int)(obd)->obd_cntr_base + \
204 OBD_COUNTER_OFFSET(op); \
205 LASSERT(coffset < obd->obd_stats->ls_num); \
206 lprocfs_counter_incr(obd->obd_stats, coffset); \
209 #define OBD_COUNTER_OFFSET(op)
210 #define OBD_COUNTER_INCREMENT(obd, op)
213 #define OBD_CHECK_OP(obd, op, err) \
215 if (!OBT(obd) || !OBP((obd), op)) {\
217 CERROR("obd_" #op ": dev %d no operation\n", \
223 #define EXP_CHECK_OP(exp, op) \
225 if ((exp) == NULL) { \
226 CERROR("obd_" #op ": NULL export\n"); \
229 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
230 CERROR("obd_" #op ": cleaned up obd\n"); \
231 RETURN(-EOPNOTSUPP); \
233 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
234 CERROR("obd_" #op ": dev %d no operation\n", \
235 (exp)->exp_obd->obd_minor); \
236 RETURN(-EOPNOTSUPP); \
240 #define CTXT_CHECK_OP(ctxt, op, err) \
242 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
244 CERROR("lop_" #op ": dev %d no operation\n", \
245 ctxt->loc_obd->obd_minor); \
250 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
251 void *key, __u32 *vallen, void *val)
256 EXP_CHECK_OP(exp, get_info);
257 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
259 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
263 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
264 void *key, obd_count vallen, void *val)
269 EXP_CHECK_OP(exp, set_info);
270 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
272 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
276 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
281 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
282 OBD_COUNTER_INCREMENT(obd, setup);
284 rc = OBP(obd, setup)(obd, datalen, data);
288 static inline int obd_precleanup(struct obd_device *obd, int cleanup_stage)
293 OBD_CHECK_OP(obd, precleanup, 0);
294 OBD_COUNTER_INCREMENT(obd, precleanup);
296 rc = OBP(obd, precleanup)(obd, cleanup_stage);
300 static inline int obd_cleanup(struct obd_device *obd)
306 OBD_CHECK_OP(obd, cleanup, 0);
307 OBD_COUNTER_INCREMENT(obd, cleanup);
309 rc = OBP(obd, cleanup)(obd);
314 obd_process_config(struct obd_device *obd, int datalen, void *data)
319 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
320 OBD_COUNTER_INCREMENT(obd, process_config);
322 rc = OBP(obd, process_config)(obd, datalen, data);
326 /* Pack an in-memory MD struct for storage on disk.
327 * Returns +ve size of packed MD (0 for free), or -ve error.
329 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
330 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
331 * If @*disk_tgt == NULL, it will be allocated
333 static inline int obd_packmd(struct obd_export *exp,
334 struct lov_mds_md **disk_tgt,
335 struct lov_stripe_md *mem_src)
340 EXP_CHECK_OP(exp, packmd);
341 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
343 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
347 static inline int obd_size_diskmd(struct obd_export *exp,
348 struct lov_stripe_md *mem_src)
350 return obd_packmd(exp, NULL, mem_src);
353 /* helper functions */
354 static inline int obd_alloc_diskmd(struct obd_export *exp,
355 struct lov_mds_md **disk_tgt)
358 LASSERT(*disk_tgt == NULL);
359 return obd_packmd(exp, disk_tgt, NULL);
362 static inline int obd_free_diskmd(struct obd_export *exp,
363 struct lov_mds_md **disk_tgt)
367 return obd_packmd(exp, disk_tgt, NULL);
370 /* Unpack an MD struct from disk to in-memory format.
371 * Returns +ve size of unpacked MD (0 for free), or -ve error.
373 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
374 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
375 * If @*mem_tgt == NULL, it will be allocated
377 static inline int obd_unpackmd(struct obd_export *exp,
378 struct lov_stripe_md **mem_tgt,
379 struct lov_mds_md *disk_src,
385 EXP_CHECK_OP(exp, unpackmd);
386 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
388 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
392 /* helper functions */
393 static inline int obd_alloc_memmd(struct obd_export *exp,
394 struct lov_stripe_md **mem_tgt)
397 LASSERT(*mem_tgt == NULL);
398 return obd_unpackmd(exp, mem_tgt, NULL, 0);
401 static inline int obd_free_memmd(struct obd_export *exp,
402 struct lov_stripe_md **mem_tgt)
406 return obd_unpackmd(exp, mem_tgt, NULL, 0);
409 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
410 struct lov_stripe_md **ea,
411 struct obd_trans_info *oti)
416 EXP_CHECK_OP(exp, create);
417 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
419 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
423 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
424 struct lov_stripe_md *ea,
425 struct obd_trans_info *oti)
430 EXP_CHECK_OP(exp, destroy);
431 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
433 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
437 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
438 struct lov_stripe_md *ea)
443 EXP_CHECK_OP(exp, getattr);
444 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
446 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
450 static inline int obd_getattr_async(struct obd_export *exp,
451 struct obdo *obdo, struct lov_stripe_md *ea,
452 struct ptlrpc_request_set *set)
457 EXP_CHECK_OP(exp, getattr);
458 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
460 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
464 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
465 struct lov_stripe_md *ea,
466 struct obd_trans_info *oti)
471 EXP_CHECK_OP(exp, setattr);
472 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
474 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
478 static inline int obd_setattr_async(struct obd_export *exp,
480 struct lov_stripe_md *ea,
481 struct obd_trans_info *oti)
486 EXP_CHECK_OP(exp, setattr_async);
487 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
489 rc = OBP(exp->exp_obd, setattr_async)(exp, obdo, ea, oti);
493 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
496 struct obd_device *obd = imp->imp_obd;
500 OBD_CHECK_DEV_ACTIVE(obd);
501 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
502 OBD_COUNTER_INCREMENT(obd, add_conn);
504 rc = OBP(obd, add_conn)(imp, uuid, priority);
508 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
510 struct obd_device *obd = imp->imp_obd;
514 OBD_CHECK_DEV_ACTIVE(obd);
515 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
516 OBD_COUNTER_INCREMENT(obd, del_conn);
518 rc = OBP(obd, del_conn)(imp, uuid);
522 static inline int obd_connect(struct lustre_handle *conn, struct obd_device *obd,
523 struct obd_uuid *cluuid,
524 struct obd_connect_data *data)
529 OBD_CHECK_DEV_ACTIVE(obd);
530 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
531 OBD_COUNTER_INCREMENT(obd, connect);
533 rc = OBP(obd, connect)(conn, obd, cluuid, data);
537 static inline int obd_disconnect(struct obd_export *exp)
542 EXP_CHECK_OP(exp, disconnect);
543 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
545 rc = OBP(exp->exp_obd, disconnect)(exp);
549 static inline int obd_init_export(struct obd_export *exp)
554 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
555 OBP((exp)->exp_obd, init_export))
556 rc = OBP(exp->exp_obd, init_export)(exp);
560 static inline int obd_destroy_export(struct obd_export *exp)
563 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
564 OBP((exp)->exp_obd, destroy_export))
565 OBP(exp->exp_obd, destroy_export)(exp);
569 static inline struct dentry *
570 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
572 LASSERT(exp->exp_obd);
574 return lvfs_fid2dentry(&exp->exp_obd->obd_ctxt, id_ino, gen, gr,
579 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
582 /* @max_age is the oldest time in jiffies that we accept using a cached data.
583 * If the cache is older than @max_age we will get a new value from the
584 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
585 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
586 unsigned long max_age)
594 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
595 OBD_COUNTER_INCREMENT(obd, statfs);
597 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
598 if (time_before(obd->obd_osfs_age, max_age)) {
599 rc = OBP(obd, statfs)(obd, osfs, max_age);
601 spin_lock(&obd->obd_osfs_lock);
602 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
603 obd->obd_osfs_age = jiffies;
604 spin_unlock(&obd->obd_osfs_lock);
607 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
608 spin_lock(&obd->obd_osfs_lock);
609 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
610 spin_unlock(&obd->obd_osfs_lock);
615 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
616 struct lov_stripe_md *ea, obd_size start,
622 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
623 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
625 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
629 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
630 struct lov_stripe_md *ea, obd_size start,
631 obd_size end, struct obd_trans_info *oti)
636 EXP_CHECK_OP(exp, punch);
637 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
639 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
643 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
644 struct lov_stripe_md *ea, obd_count oa_bufs,
645 struct brw_page *pg, struct obd_trans_info *oti)
650 EXP_CHECK_OP(exp, brw);
651 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
653 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
654 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
655 "or OBD_BRW_CHECK\n");
659 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
663 static inline int obd_brw_async(int cmd, struct obd_export *exp,
664 struct obdo *oa, struct lov_stripe_md *ea,
665 obd_count oa_bufs, struct brw_page *pg,
666 struct ptlrpc_request_set *set,
667 struct obd_trans_info *oti)
672 EXP_CHECK_OP(exp, brw_async);
673 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
675 if (!(cmd & OBD_BRW_RWMASK)) {
676 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
680 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
685 static inline int obd_prep_async_page(struct obd_export *exp,
686 struct lov_stripe_md *lsm,
687 struct lov_oinfo *loi,
688 struct page *page, obd_off offset,
689 struct obd_async_page_ops *ops,
690 void *data, void **res)
695 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
696 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
698 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
703 static inline int obd_queue_async_io(struct obd_export *exp,
704 struct lov_stripe_md *lsm,
705 struct lov_oinfo *loi, void *cookie,
706 int cmd, obd_off off, int count,
707 obd_flag brw_flags, obd_flag async_flags)
712 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
713 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
714 LASSERT(cmd & OBD_BRW_RWMASK);
716 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
717 count, brw_flags, async_flags);
721 static inline int obd_set_async_flags(struct obd_export *exp,
722 struct lov_stripe_md *lsm,
723 struct lov_oinfo *loi, void *cookie,
724 obd_flag async_flags)
729 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
730 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
732 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
737 static inline int obd_queue_group_io(struct obd_export *exp,
738 struct lov_stripe_md *lsm,
739 struct lov_oinfo *loi,
740 struct obd_io_group *oig,
741 void *cookie, int cmd, obd_off off,
742 int count, obd_flag brw_flags,
743 obd_flag async_flags)
748 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
749 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
750 LASSERT(cmd & OBD_BRW_RWMASK);
752 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
753 cmd, off, count, brw_flags,
758 static inline int obd_trigger_group_io(struct obd_export *exp,
759 struct lov_stripe_md *lsm,
760 struct lov_oinfo *loi,
761 struct obd_io_group *oig)
766 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
767 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
769 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
773 static inline int obd_teardown_async_page(struct obd_export *exp,
774 struct lov_stripe_md *lsm,
775 struct lov_oinfo *loi, void *cookie)
780 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
781 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
783 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
787 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
788 int objcount, struct obd_ioobj *obj,
789 int niocount, struct niobuf_remote *remote,
790 struct niobuf_local *local,
791 struct obd_trans_info *oti)
796 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
797 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
799 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
804 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
805 int objcount, struct obd_ioobj *obj,
806 int niocount, struct niobuf_local *local,
807 struct obd_trans_info *oti, int rc)
811 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
812 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
814 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
819 static inline int obd_adjust_kms(struct obd_export *exp,
820 struct lov_stripe_md *lsm, obd_off size,
826 OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
827 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
829 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
833 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
834 int len, void *karg, void *uarg)
839 EXP_CHECK_OP(exp, iocontrol);
840 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
842 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
846 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
847 __u32 type, ldlm_policy_data_t *policy,
848 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
849 void *gl_cb, void *data, __u32 lvb_len,
850 void *lvb_swabber, struct lustre_handle *lockh)
855 EXP_CHECK_OP(exp, enqueue);
856 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
858 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
859 bl_cb, cp_cb, gl_cb, data, lvb_len,
864 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
865 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
866 int *flags, void *data, struct lustre_handle *lockh)
871 EXP_CHECK_OP(exp, match);
872 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
874 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
879 static inline int obd_change_cbdata(struct obd_export *exp,
880 struct lov_stripe_md *lsm,
881 ldlm_iterator_t it, void *data)
886 EXP_CHECK_OP(exp, change_cbdata);
887 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
889 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
893 static inline int obd_cancel(struct obd_export *exp,
894 struct lov_stripe_md *ea, __u32 mode,
895 struct lustre_handle *lockh)
900 EXP_CHECK_OP(exp, cancel);
901 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
903 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
907 static inline int obd_cancel_unused(struct obd_export *exp,
908 struct lov_stripe_md *ea, int flags,
914 EXP_CHECK_OP(exp, cancel_unused);
915 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
917 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
921 static inline int obd_join_lru(struct obd_export *exp,
922 struct lov_stripe_md *ea, int join)
927 EXP_CHECK_OP(exp, join_lru);
928 OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
930 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
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);
975 static inline void obd_import_event(struct obd_device *obd,
976 struct obd_import *imp,
977 enum obd_import_event event)
980 CERROR("NULL device\n");
984 if (obd->obd_set_up && OBP(obd, import_event)) {
985 OBD_COUNTER_INCREMENT(obd, import_event);
986 OBP(obd, import_event)(obd, imp, event);
990 static inline int obd_notify(struct obd_device *obd,
991 struct obd_device *watched,
995 if (!obd->obd_set_up) {
996 CERROR("obd %s not set up\n", obd->obd_name);
1000 if (!OBP(obd, notify)) {
1001 CERROR("obd %s has no notify handler\n", obd->obd_name);
1005 OBD_COUNTER_INCREMENT(obd, notify);
1006 return OBP(obd, notify)(obd, watched, active);
1009 static inline int obd_quotacheck(struct obd_export *exp,
1010 struct obd_quotactl *oqctl)
1015 EXP_CHECK_OP(exp, quotacheck);
1016 OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1018 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1022 static inline int obd_quotactl(struct obd_export *exp,
1023 struct obd_quotactl *oqctl)
1028 EXP_CHECK_OP(exp, quotactl);
1029 OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1031 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1036 static inline int obd_register_observer(struct obd_device *obd,
1037 struct obd_device *observer)
1041 if (obd->obd_observer && observer)
1043 obd->obd_observer = observer;
1047 /* OBD Metadata Support */
1049 extern int obd_init_caches(void);
1050 extern void obd_cleanup_caches(void);
1052 /* support routines */
1053 extern kmem_cache_t *obdo_cachep;
1054 static inline struct obdo *obdo_alloc(void)
1058 OBD_SLAB_ALLOC(oa, obdo_cachep, SLAB_KERNEL, sizeof(*oa));
1063 /* qunit hash stuff */
1064 extern kmem_cache_t *qunit_cachep;
1065 extern struct list_head qunit_hash[];
1066 extern spinlock_t qunit_hash_lock;
1068 static inline void obdo_free(struct obdo *oa)
1070 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1073 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1074 #define to_kdev_t(dev) dev
1075 #define kdev_t_to_nr(dev) dev
1078 /* I'm as embarrassed about this as you are.
1080 * <shaver> // XXX do not look into _superhack with remaining eye
1081 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1082 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1083 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1086 extern void obd_sysctl_init (void);
1087 extern void obd_sysctl_clean (void);
1090 typedef __u8 class_uuid_t[16];
1091 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1092 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1095 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1096 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1097 int class_del_uuid (char *uuid);
1098 void class_init_uuidlist(void);
1099 void class_exit_uuidlist(void);
1101 #endif /* __LINUX_OBD_CLASS_H */