1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 #include <obd_support.h>
41 #include <lustre_import.h>
42 #include <lustre_net.h>
44 #include <lustre_lib.h>
45 #include <lustre/lustre_idl.h>
46 #include <lprocfs_status.h>
48 #if defined(__linux__)
49 #include <linux/obd_class.h>
50 #elif defined(__APPLE__)
51 #include <darwin/obd_class.h>
52 #elif defined(__WINNT__)
53 #include <winnt/obd_class.h>
55 #error Unsupported operating system.
58 /* OBD Device Declarations */
59 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
60 extern spinlock_t obd_dev_lock;
61 extern cfs_mem_cache_t *obd_lvfs_ctxt_cache;
63 /* OBD Operations Declarations */
64 extern struct obd_device *class_conn2obd(struct lustre_handle *);
65 extern struct obd_device *class_exp2obd(struct obd_export *);
66 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
69 struct obd_export *class_conn2export(struct lustre_handle *);
70 int class_register_type(struct obd_ops *ops, struct lprocfs_vars *,
72 int class_unregister_type(const char *nm);
74 struct obd_device *class_newdev(const char *type_name, const char *name);
75 void class_release_dev(struct obd_device *obd);
77 int class_name2dev(const char *name);
78 struct obd_device *class_name2obd(const char *name);
79 int class_uuid2dev(struct obd_uuid *uuid);
80 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
81 void class_obd_list(void);
82 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
83 const char * typ_name,
84 struct obd_uuid *grp_uuid);
85 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
86 struct obd_uuid *grp_uuid);
87 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
89 struct obd_device * class_num2obd(int num);
91 int oig_init(struct obd_io_group **oig);
92 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
93 void oig_complete_one(struct obd_io_group *oig,
94 struct oig_callback_context *occ, int rc);
95 void oig_release(struct obd_io_group *oig);
96 int oig_wait(struct obd_io_group *oig);
98 char *obd_export_nid2str(struct obd_export *exp);
100 int obd_export_evict_by_nid(struct obd_device *obd, char *nid);
101 int obd_export_evict_by_uuid(struct obd_device *obd, char *uuid);
103 int obd_zombie_impexp_init(void);
104 void obd_zombie_impexp_stop(void);
105 void obd_zombie_impexp_cull(void);
106 void obd_zombie_barrier(void);
109 int class_process_config(struct lustre_cfg *lcfg);
110 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
111 struct lustre_cfg *lcfg, void *data);
112 int class_attach(struct lustre_cfg *lcfg);
113 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
114 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
115 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
116 struct obd_device *class_incref(struct obd_device *obd);
117 void class_decref(struct obd_device *obd);
121 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
123 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
125 memset(lvars, 0, sizeof(*lvars));
129 #define CFG_F_START 0x01 /* Set when we start updating from a log */
130 #define CFG_F_MARKER 0x02 /* We are within a maker */
131 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
132 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
133 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
135 /* Passed as data param to class_config_parse_llog */
136 struct config_llog_instance {
138 struct super_block *cfg_sb;
139 struct obd_uuid cfg_uuid;
140 int cfg_last_idx; /* for partial llog processing */
143 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
144 struct config_llog_instance *cfg);
145 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
146 struct config_llog_instance *cfg);
148 /* list of active configuration logs */
149 struct config_llog_data {
151 struct ldlm_res_id cld_resid;
152 struct config_llog_instance cld_cfg;
153 struct list_head cld_list_chain;
154 atomic_t cld_refcount;
155 struct obd_export *cld_mgcexp;
156 unsigned int cld_stopping:1; /* we were told to stop watching */
157 unsigned int cld_lostlock:1; /* lock not requeued */
158 struct semaphore cld_sem; /* for exclusive processing of the log */
161 struct lustre_profile {
162 struct list_head lp_list;
168 struct lustre_profile *class_get_profile(char * prof);
169 void class_del_profile(char *prof);
170 void class_del_profiles(void);
172 #define class_export_rpc_get(exp) \
174 atomic_inc(&(exp)->exp_rpc_count); \
175 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
176 (exp), atomic_read(&(exp)->exp_rpc_count)); \
177 class_export_get(exp); \
180 #define class_export_rpc_put(exp) \
182 atomic_dec(&(exp)->exp_rpc_count); \
183 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
184 (exp), atomic_read(&(exp)->exp_rpc_count)); \
185 class_export_put(exp); \
189 #define class_export_get(exp) \
191 struct obd_export *exp_ = exp; \
192 atomic_inc(&exp_->exp_refcount); \
193 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
194 atomic_read(&exp_->exp_refcount)); \
198 /* class_export_put() is non-blocking */
199 #define class_export_put(exp) \
201 LASSERT((exp) != NULL); \
202 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
203 atomic_read(&(exp)->exp_refcount) - 1); \
204 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
205 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
206 __class_export_put(exp); \
209 void __class_export_put(struct obd_export *);
210 struct obd_export *class_new_export(struct obd_device *obddev,
211 struct obd_uuid *cluuid);
212 void class_unlink_export(struct obd_export *exp);
214 struct obd_import *class_import_get(struct obd_import *);
215 void class_import_put(struct obd_import *);
216 struct obd_import *class_new_import(struct obd_device *obd);
217 void class_destroy_import(struct obd_import *exp);
219 struct obd_type *class_search_type(const char *name);
220 struct obd_type *class_get_type(const char *name);
221 void class_put_type(struct obd_type *type);
222 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
223 struct obd_uuid *cluuid);
224 int class_disconnect(struct obd_export *exp);
225 void class_fail_export(struct obd_export *exp);
226 int class_connected_export(struct obd_export *exp);
227 void class_disconnect_exports(struct obd_device *obddev);
228 void class_set_export_delayed(struct obd_export *exp);
229 void class_handle_stale_exports(struct obd_device *obddev);
230 void class_disconnect_expired_exports(struct obd_device *obd);
231 void class_disconnect_stale_exports(struct obd_device *obddev,
232 enum obd_option flags);
233 int class_stale_export_list(struct obd_device *obd, struct obd_ioctl_data *data);
234 int class_manual_cleanup(struct obd_device *obd);
236 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
238 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
239 (obd->obd_force ? OBD_OPT_FORCE : 0) |
240 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
245 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
246 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
249 #define OBT(dev) (dev)->obd_type
250 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
251 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
253 /* Ensure obd_setup: used for cleanup which must be called
254 while obd is stopping */
255 #define OBD_CHECK_DEV(obd) \
258 CERROR("NULL device\n"); \
263 /* ensure obd_setup and !obd_stopping */
264 #define OBD_CHECK_DEV_ACTIVE(obd) \
266 OBD_CHECK_DEV(obd); \
267 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
268 CERROR("Device %d not setup\n", \
276 #define OBD_COUNTER_OFFSET(op) \
277 ((offsetof(struct obd_ops, o_ ## op) - \
278 offsetof(struct obd_ops, o_iocontrol)) \
279 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
281 #define OBD_COUNTER_INCREMENT(obdx, op) \
282 if ((obdx)->obd_stats != NULL) { \
283 unsigned int coffset; \
284 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
285 OBD_COUNTER_OFFSET(op); \
286 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
287 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
290 #define EXP_COUNTER_INCREMENT(export, op) \
291 if ((export)->exp_obd->obd_stats != NULL) { \
292 unsigned int coffset; \
293 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
294 OBD_COUNTER_OFFSET(op); \
295 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
296 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
297 if ((export)->exp_nid_stats != NULL && \
298 (export)->exp_nid_stats->nid_stats != NULL) \
299 lprocfs_counter_incr( \
300 (export)->exp_nid_stats->nid_stats, coffset);\
304 #define OBD_COUNTER_OFFSET(op)
305 #define OBD_COUNTER_INCREMENT(obd, op)
306 #define EXP_COUNTER_INCREMENT(exp, op);
309 #define OBD_CHECK_OP(obd, op, err) \
311 if (!OBT(obd) || !OBP((obd), op)) {\
313 CERROR("obd_" #op ": dev %d no operation\n", \
319 #define EXP_CHECK_OP(exp, op) \
321 if ((exp) == NULL) { \
322 CERROR("obd_" #op ": NULL export\n"); \
325 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
326 CERROR("obd_" #op ": cleaned up obd\n"); \
327 RETURN(-EOPNOTSUPP); \
329 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
330 CERROR("obd_" #op ": dev %d no operation\n", \
331 (exp)->exp_obd->obd_minor); \
332 RETURN(-EOPNOTSUPP); \
336 #define CTXT_CHECK_OP(ctxt, op, err) \
338 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
340 CERROR("lop_" #op ": dev %d no operation\n", \
341 ctxt->loc_obd->obd_minor); \
346 static inline int class_devno_max(void)
348 return MAX_OBD_DEVICES;
351 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
352 void *key, __u32 *vallen, void *val,
353 struct lov_stripe_md *lsm)
358 EXP_CHECK_OP(exp, get_info);
359 EXP_COUNTER_INCREMENT(exp, get_info);
361 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
365 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
366 void *key, obd_count vallen, void *val,
367 struct ptlrpc_request_set *set)
372 EXP_CHECK_OP(exp, set_info_async);
373 EXP_COUNTER_INCREMENT(exp, set_info_async);
375 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
380 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
385 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
386 OBD_COUNTER_INCREMENT(obd, setup);
388 rc = OBP(obd, setup)(obd, datalen, data);
392 static inline int obd_precleanup(struct obd_device *obd,
393 enum obd_cleanup_stage cleanup_stage)
398 OBD_CHECK_OP(obd, precleanup, 0);
399 OBD_COUNTER_INCREMENT(obd, precleanup);
401 rc = OBP(obd, precleanup)(obd, cleanup_stage);
405 static inline int obd_cleanup(struct obd_device *obd)
411 OBD_CHECK_OP(obd, cleanup, 0);
412 OBD_COUNTER_INCREMENT(obd, cleanup);
414 rc = OBP(obd, cleanup)(obd);
419 obd_process_config(struct obd_device *obd, int datalen, void *data)
424 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
425 OBD_COUNTER_INCREMENT(obd, process_config);
427 rc = OBP(obd, process_config)(obd, datalen, data);
431 /* Pack an in-memory MD struct for storage on disk.
432 * Returns +ve size of packed MD (0 for free), or -ve error.
434 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
435 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
436 * If @*disk_tgt == NULL, it will be allocated
438 static inline int obd_packmd(struct obd_export *exp,
439 struct lov_mds_md **disk_tgt,
440 struct lov_stripe_md *mem_src)
445 EXP_CHECK_OP(exp, packmd);
446 EXP_COUNTER_INCREMENT(exp, packmd);
448 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
452 static inline int obd_size_diskmd(struct obd_export *exp,
453 struct lov_stripe_md *mem_src)
455 return obd_packmd(exp, NULL, mem_src);
458 /* helper functions */
459 static inline int obd_alloc_diskmd(struct obd_export *exp,
460 struct lov_mds_md **disk_tgt)
463 LASSERT(*disk_tgt == NULL);
464 return obd_packmd(exp, disk_tgt, NULL);
467 static inline int obd_free_diskmd(struct obd_export *exp,
468 struct lov_mds_md **disk_tgt)
472 return obd_packmd(exp, disk_tgt, NULL);
475 /* Unpack an MD struct from disk to in-memory format.
476 * Returns +ve size of unpacked MD (0 for free), or -ve error.
478 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
479 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
480 * If @*mem_tgt == NULL, it will be allocated
482 static inline int obd_unpackmd(struct obd_export *exp,
483 struct lov_stripe_md **mem_tgt,
484 struct lov_mds_md *disk_src,
490 EXP_CHECK_OP(exp, unpackmd);
491 EXP_COUNTER_INCREMENT(exp, unpackmd);
493 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
497 /* helper functions */
498 static inline int obd_alloc_memmd(struct obd_export *exp,
499 struct lov_stripe_md **mem_tgt)
502 LASSERT(*mem_tgt == NULL);
503 return obd_unpackmd(exp, mem_tgt, NULL, 0);
506 static inline int obd_free_memmd(struct obd_export *exp,
507 struct lov_stripe_md **mem_tgt)
511 return obd_unpackmd(exp, mem_tgt, NULL, 0);
514 static inline int obd_checkmd(struct obd_export *exp,
515 struct obd_export *md_exp,
516 struct lov_stripe_md *mem_tgt)
521 EXP_CHECK_OP(exp, checkmd);
522 EXP_COUNTER_INCREMENT(exp, checkmd);
524 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
528 static inline int obd_precreate(struct obd_export *exp)
533 EXP_CHECK_OP(exp, precreate);
534 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
536 rc = OBP(exp->exp_obd, precreate)(exp);
540 static inline int obd_create_async(struct obd_export *exp,
541 struct obd_info *oinfo,
542 struct lov_stripe_md **ea,
543 struct obd_trans_info *oti)
548 EXP_CHECK_OP(exp, create_async);
549 EXP_COUNTER_INCREMENT(exp, create_async);
551 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
555 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
556 struct lov_stripe_md **ea,
557 struct obd_trans_info *oti)
562 EXP_CHECK_OP(exp, create);
563 EXP_COUNTER_INCREMENT(exp, create);
565 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
569 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
570 struct lov_stripe_md *ea,
571 struct obd_trans_info *oti,
572 struct obd_export *md_exp)
577 EXP_CHECK_OP(exp, destroy);
578 EXP_COUNTER_INCREMENT(exp, destroy);
580 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
584 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
589 EXP_CHECK_OP(exp, getattr);
590 EXP_COUNTER_INCREMENT(exp, getattr);
592 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
596 static inline int obd_getattr_async(struct obd_export *exp,
597 struct obd_info *oinfo,
598 struct ptlrpc_request_set *set)
603 EXP_CHECK_OP(exp, getattr_async);
604 EXP_COUNTER_INCREMENT(exp, getattr_async);
606 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
610 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
611 struct obd_trans_info *oti)
616 EXP_CHECK_OP(exp, setattr);
617 EXP_COUNTER_INCREMENT(exp, setattr);
619 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
623 /* This performs all the requests set init/wait/destroy actions. */
624 static inline int obd_setattr_rqset(struct obd_export *exp,
625 struct obd_info *oinfo,
626 struct obd_trans_info *oti)
628 struct ptlrpc_request_set *set = NULL;
632 EXP_CHECK_OP(exp, setattr_async);
633 EXP_COUNTER_INCREMENT(exp, setattr_async);
635 set = ptlrpc_prep_set();
639 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
641 rc = ptlrpc_set_wait(set);
642 ptlrpc_set_destroy(set);
646 /* This adds all the requests into @set if @set != NULL, otherwise
647 all requests are sent asynchronously without waiting for response. */
648 static inline int obd_setattr_async(struct obd_export *exp,
649 struct obd_info *oinfo,
650 struct obd_trans_info *oti,
651 struct ptlrpc_request_set *set)
656 EXP_CHECK_OP(exp, setattr_async);
657 EXP_COUNTER_INCREMENT(exp, setattr_async);
659 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
663 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
666 struct obd_device *obd = imp->imp_obd;
670 OBD_CHECK_DEV_ACTIVE(obd);
671 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
672 OBD_COUNTER_INCREMENT(obd, add_conn);
674 rc = OBP(obd, add_conn)(imp, uuid, priority);
678 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
680 struct obd_device *obd = imp->imp_obd;
684 OBD_CHECK_DEV_ACTIVE(obd);
685 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
686 OBD_COUNTER_INCREMENT(obd, del_conn);
688 rc = OBP(obd, del_conn)(imp, uuid);
692 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
693 struct obd_uuid *cluuid,
694 struct obd_connect_data *d,
698 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
701 OBD_CHECK_DEV_ACTIVE(obd);
702 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
703 OBD_COUNTER_INCREMENT(obd, connect);
705 rc = OBP(obd, connect)(conn, obd, cluuid, d, localdata);
706 /* check that only subset is granted */
707 LASSERT(ergo(d != NULL,
708 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
712 static inline int obd_reconnect(struct obd_export *exp,
713 struct obd_device *obd,
714 struct obd_uuid *cluuid,
715 struct obd_connect_data *d,
719 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
722 OBD_CHECK_DEV_ACTIVE(obd);
723 OBD_CHECK_OP(obd, reconnect, 0);
724 OBD_COUNTER_INCREMENT(obd, reconnect);
726 rc = OBP(obd, reconnect)(exp, obd, cluuid, d, localdata);
727 /* check that only subset is granted */
728 LASSERT(ergo(d != NULL,
729 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
733 static inline int obd_disconnect(struct obd_export *exp)
738 EXP_CHECK_OP(exp, disconnect);
739 EXP_COUNTER_INCREMENT(exp, disconnect);
741 rc = OBP(exp->exp_obd, disconnect)(exp);
745 static inline int obd_fid_init(struct obd_export *exp)
750 OBD_CHECK_OP(exp->exp_obd, fid_init, 0);
751 EXP_COUNTER_INCREMENT(exp, fid_init);
753 rc = OBP(exp->exp_obd, fid_init)(exp);
757 static inline int obd_fid_fini(struct obd_export *exp)
762 OBD_CHECK_OP(exp->exp_obd, fid_fini, 0);
763 EXP_COUNTER_INCREMENT(exp, fid_fini);
765 rc = OBP(exp->exp_obd, fid_fini)(exp);
769 static inline int obd_ping(struct obd_export *exp)
774 OBD_CHECK_OP(exp->exp_obd, ping, 0);
775 EXP_COUNTER_INCREMENT(exp, ping);
777 rc = OBP(exp->exp_obd, ping)(exp);
781 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
786 OBD_CHECK_OP(obd, pool_new, -EOPNOTSUPP);
787 OBD_COUNTER_INCREMENT(obd, pool_new);
789 rc = OBP(obd, pool_new)(obd, poolname);
793 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
798 OBD_CHECK_OP(obd, pool_del, -EOPNOTSUPP);
799 OBD_COUNTER_INCREMENT(obd, pool_del);
801 rc = OBP(obd, pool_del)(obd, poolname);
805 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
810 OBD_CHECK_OP(obd, pool_add, -EOPNOTSUPP);
811 OBD_COUNTER_INCREMENT(obd, pool_add);
813 rc = OBP(obd, pool_add)(obd, poolname, ostname);
817 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
822 OBD_CHECK_OP(obd, pool_rem, -EOPNOTSUPP);
823 OBD_COUNTER_INCREMENT(obd, pool_rem);
825 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
829 static inline void obd_getref(struct obd_device *obd)
832 if (OBT(obd) && OBP(obd, getref)) {
833 OBD_COUNTER_INCREMENT(obd, getref);
834 OBP(obd, getref)(obd);
839 static inline void obd_putref(struct obd_device *obd)
842 if (OBT(obd) && OBP(obd, putref)) {
843 OBD_COUNTER_INCREMENT(obd, putref);
844 OBP(obd, putref)(obd);
849 static inline int obd_init_export(struct obd_export *exp)
854 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
855 OBP((exp)->exp_obd, init_export))
856 rc = OBP(exp->exp_obd, init_export)(exp);
860 static inline int obd_destroy_export(struct obd_export *exp)
863 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
864 OBP((exp)->exp_obd, destroy_export))
865 OBP(exp->exp_obd, destroy_export)(exp);
869 static inline int obd_extent_calc(struct obd_export *exp,
870 struct lov_stripe_md *md,
871 int cmd, obd_off *offset)
875 EXP_CHECK_OP(exp, extent_calc);
876 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
880 static inline struct dentry *
881 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
883 LASSERT(exp->exp_obd);
885 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
890 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
893 /* @max_age is the oldest time in jiffies that we accept using a cached data.
894 * If the cache is older than @max_age we will get a new value from the
895 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
896 static inline int obd_statfs_async(struct obd_device *obd,
897 struct obd_info *oinfo,
899 struct ptlrpc_request_set *rqset)
907 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
908 OBD_COUNTER_INCREMENT(obd, statfs);
910 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
911 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
912 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
913 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
915 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
916 " objects "LPU64"/"LPU64"\n",
917 obd->obd_name, &obd->obd_osfs,
918 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
919 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
920 spin_lock(&obd->obd_osfs_lock);
921 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
922 spin_unlock(&obd->obd_osfs_lock);
923 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
925 oinfo->oi_cb_up(oinfo, 0);
930 static inline int obd_statfs_rqset(struct obd_device *obd,
931 struct obd_statfs *osfs, __u64 max_age,
934 struct ptlrpc_request_set *set = NULL;
935 struct obd_info oinfo = { { { 0 } } };
939 set = ptlrpc_prep_set();
943 oinfo.oi_osfs = osfs;
944 oinfo.oi_flags = flags;
945 rc = obd_statfs_async(obd, &oinfo, max_age, set);
947 rc = ptlrpc_set_wait(set);
948 ptlrpc_set_destroy(set);
952 /* @max_age is the oldest time in jiffies that we accept using a cached data.
953 * If the cache is older than @max_age we will get a new value from the
954 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
955 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
956 __u64 max_age, __u32 flags)
964 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
965 OBD_COUNTER_INCREMENT(obd, statfs);
967 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
968 obd->obd_osfs_age, max_age);
969 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
970 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
972 spin_lock(&obd->obd_osfs_lock);
973 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
974 obd->obd_osfs_age = cfs_time_current_64();
975 spin_unlock(&obd->obd_osfs_lock);
978 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
979 " objects "LPU64"/"LPU64"\n",
980 obd->obd_name, &obd->obd_osfs,
981 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
982 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
983 spin_lock(&obd->obd_osfs_lock);
984 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
985 spin_unlock(&obd->obd_osfs_lock);
990 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
991 obd_size start, obd_size end)
993 struct ptlrpc_request_set *set = NULL;
997 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
998 EXP_COUNTER_INCREMENT(exp, sync);
1000 set = ptlrpc_prep_set();
1004 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1006 rc = ptlrpc_set_wait(set);
1007 ptlrpc_set_destroy(set);
1011 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1012 obd_size start, obd_size end,
1013 struct ptlrpc_request_set *set)
1018 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1019 EXP_COUNTER_INCREMENT(exp, sync);
1021 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1025 static inline int obd_punch_rqset(struct obd_export *exp,
1026 struct obd_info *oinfo,
1027 struct obd_trans_info *oti)
1029 struct ptlrpc_request_set *set = NULL;
1033 EXP_CHECK_OP(exp, punch);
1034 EXP_COUNTER_INCREMENT(exp, punch);
1036 set = ptlrpc_prep_set();
1040 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1042 rc = ptlrpc_set_wait(set);
1043 ptlrpc_set_destroy(set);
1047 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1048 struct obd_trans_info *oti,
1049 struct ptlrpc_request_set *rqset)
1054 EXP_CHECK_OP(exp, punch);
1055 EXP_COUNTER_INCREMENT(exp, punch);
1057 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1061 static inline int obd_brw(int cmd, struct obd_export *exp,
1062 struct obd_info *oinfo, obd_count oa_bufs,
1063 struct brw_page *pg, struct obd_trans_info *oti)
1068 EXP_CHECK_OP(exp, brw);
1069 EXP_COUNTER_INCREMENT(exp, brw);
1071 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1072 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1073 "or OBD_BRW_CHECK\n");
1077 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1081 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1082 struct obd_info *oinfo, obd_count oa_bufs,
1083 struct brw_page *pg, struct obd_trans_info *oti,
1084 struct ptlrpc_request_set *set, int pshift)
1089 EXP_CHECK_OP(exp, brw_async);
1090 EXP_COUNTER_INCREMENT(exp, brw_async);
1092 if (!(cmd & OBD_BRW_RWMASK)) {
1093 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1097 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs,
1098 pg, oti,set, pshift);
1102 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1103 struct obdo *oa, struct lov_stripe_md *lsm,
1104 obd_count oa_bufs, struct brw_page *pg,
1105 struct obd_trans_info *oti)
1107 struct ptlrpc_request_set *set = NULL;
1108 struct obd_info oinfo = { { { 0 } } };
1112 set = ptlrpc_prep_set();
1118 rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set, 0);
1120 rc = ptlrpc_set_wait(set);
1122 CERROR("error from callback: rc = %d\n", rc);
1124 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
1125 "error from obd_brw_async: rc = %d\n", rc);
1127 ptlrpc_set_destroy(set);
1131 /* flags used by obd_prep_async_page */
1132 #define OBD_PAGE_NO_CACHE 0x00000001 /* don't add to cache */
1133 #define OBD_FAST_LOCK 0x00000002 /* lockh refers to a "fast lock" */
1135 static inline int obd_prep_async_page(struct obd_export *exp,
1136 struct lov_stripe_md *lsm,
1137 struct lov_oinfo *loi,
1138 cfs_page_t *page, obd_off offset,
1139 struct obd_async_page_ops *ops,
1140 void *data, void **res, int flags,
1141 struct lustre_handle *lockh)
1146 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
1147 EXP_COUNTER_INCREMENT(exp, prep_async_page);
1149 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1150 ops, data, res, flags,
1155 static inline int obd_get_lock(struct obd_export *exp,
1156 struct lov_stripe_md *lsm, void **res, int rw,
1157 obd_off start, obd_off end,
1158 struct lustre_handle *lockh, int flags)
1162 OBD_CHECK_OP(exp->exp_obd, get_lock, -EOPNOTSUPP);
1163 EXP_COUNTER_INCREMENT(exp, get_lock);
1165 RETURN(OBP(exp->exp_obd, get_lock)(exp, lsm, res, rw, start, end,
1169 static inline int obd_queue_async_io(struct obd_export *exp,
1170 struct lov_stripe_md *lsm,
1171 struct lov_oinfo *loi, void *cookie,
1172 int cmd, obd_off off, int count,
1173 obd_flag brw_flags, obd_flag async_flags)
1178 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
1179 EXP_COUNTER_INCREMENT(exp, queue_async_io);
1180 LASSERT(cmd & OBD_BRW_RWMASK);
1182 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1183 count, brw_flags, async_flags);
1187 static inline int obd_set_async_flags(struct obd_export *exp,
1188 struct lov_stripe_md *lsm,
1189 struct lov_oinfo *loi, void *cookie,
1190 obd_flag async_flags)
1195 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1196 EXP_COUNTER_INCREMENT(exp, set_async_flags);
1198 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1203 static inline int obd_queue_group_io(struct obd_export *exp,
1204 struct lov_stripe_md *lsm,
1205 struct lov_oinfo *loi,
1206 struct obd_io_group *oig,
1207 void *cookie, int cmd, obd_off off,
1208 int count, obd_flag brw_flags,
1209 obd_flag async_flags)
1214 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1215 EXP_COUNTER_INCREMENT(exp, queue_group_io);
1216 LASSERT(cmd & OBD_BRW_RWMASK);
1218 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1219 cmd, off, count, brw_flags,
1224 static inline int obd_trigger_group_io(struct obd_export *exp,
1225 struct lov_stripe_md *lsm,
1226 struct lov_oinfo *loi,
1227 struct obd_io_group *oig)
1232 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1233 EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1235 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1239 static inline int obd_teardown_async_page(struct obd_export *exp,
1240 struct lov_stripe_md *lsm,
1241 struct lov_oinfo *loi, void *cookie)
1246 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1247 EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1249 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1253 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1254 int objcount, struct obd_ioobj *obj,
1255 struct niobuf_remote *remote, int *pages,
1256 struct niobuf_local *local,
1257 struct obd_trans_info *oti)
1262 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1263 EXP_COUNTER_INCREMENT(exp, preprw);
1265 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1270 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1271 int objcount, struct obd_ioobj *obj,
1272 struct niobuf_remote *rnb, int pages,
1273 struct niobuf_local *local,
1274 struct obd_trans_info *oti, int rc)
1278 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1279 EXP_COUNTER_INCREMENT(exp, commitrw);
1281 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1282 rnb, pages, local, oti, rc);
1286 static inline int obd_merge_lvb(struct obd_export *exp,
1287 struct lov_stripe_md *lsm,
1288 struct ost_lvb *lvb, int kms_only)
1293 OBD_CHECK_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1294 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1296 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1300 static inline int obd_update_lvb(struct obd_export *exp,
1301 struct lov_stripe_md *lsm,
1302 struct ost_lvb *lvb, obd_flag valid)
1307 OBD_CHECK_OP(exp->exp_obd, update_lvb, -EOPNOTSUPP);
1308 EXP_COUNTER_INCREMENT(exp, update_lvb);
1310 rc = OBP(exp->exp_obd, update_lvb)(exp, lsm, lvb, valid);
1314 static inline int obd_adjust_kms(struct obd_export *exp,
1315 struct lov_stripe_md *lsm, obd_off size,
1321 OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1322 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1324 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1328 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1329 int len, void *karg, void *uarg)
1334 EXP_CHECK_OP(exp, iocontrol);
1335 EXP_COUNTER_INCREMENT(exp, iocontrol);
1337 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1341 static inline int obd_enqueue_rqset(struct obd_export *exp,
1342 struct obd_info *oinfo,
1343 struct ldlm_enqueue_info *einfo)
1345 struct ptlrpc_request_set *set = NULL;
1349 EXP_CHECK_OP(exp, enqueue);
1350 EXP_COUNTER_INCREMENT(exp, enqueue);
1352 set = ptlrpc_prep_set();
1356 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1358 rc = ptlrpc_set_wait(set);
1359 ptlrpc_set_destroy(set);
1363 static inline int obd_enqueue(struct obd_export *exp,
1364 struct obd_info *oinfo,
1365 struct ldlm_enqueue_info *einfo,
1366 struct ptlrpc_request_set *set)
1371 EXP_CHECK_OP(exp, enqueue);
1372 EXP_COUNTER_INCREMENT(exp, enqueue);
1374 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1378 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1379 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1380 int *flags, void *data, struct lustre_handle *lockh,
1386 EXP_CHECK_OP(exp, match);
1387 EXP_COUNTER_INCREMENT(exp, match);
1389 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1394 static inline int obd_change_cbdata(struct obd_export *exp,
1395 struct lov_stripe_md *lsm,
1396 ldlm_iterator_t it, void *data)
1401 EXP_CHECK_OP(exp, change_cbdata);
1402 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1404 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1408 static inline int obd_cancel(struct obd_export *exp, struct lov_stripe_md *ea,
1409 __u32 mode, struct lustre_handle *lockh, int flags,
1415 EXP_CHECK_OP(exp, cancel);
1416 EXP_COUNTER_INCREMENT(exp, cancel);
1418 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh, flags, end);
1422 static inline int obd_cancel_unused(struct obd_export *exp,
1423 struct lov_stripe_md *ea, int flags,
1429 EXP_CHECK_OP(exp, cancel_unused);
1430 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1432 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1436 static inline int obd_join_lru(struct obd_export *exp,
1437 struct lov_stripe_md *ea, int join)
1442 EXP_CHECK_OP(exp, join_lru);
1443 EXP_COUNTER_INCREMENT(exp, join_lru);
1445 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1449 static inline int obd_pin(struct obd_export *exp, struct ll_fid *fid,
1450 struct obd_client_handle *handle, int flag)
1455 EXP_CHECK_OP(exp, pin);
1456 EXP_COUNTER_INCREMENT(exp, pin);
1458 rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1462 static inline int obd_unpin(struct obd_export *exp,
1463 struct obd_client_handle *handle, int flag)
1468 EXP_CHECK_OP(exp, unpin);
1469 EXP_COUNTER_INCREMENT(exp, unpin);
1471 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1476 static inline void obd_import_event(struct obd_device *obd,
1477 struct obd_import *imp,
1478 enum obd_import_event event)
1482 CERROR("NULL device\n");
1486 if (obd->obd_set_up && OBP(obd, import_event)) {
1487 OBD_COUNTER_INCREMENT(obd, import_event);
1488 OBP(obd, import_event)(obd, imp, event);
1493 static inline int obd_notify(struct obd_device *obd,
1494 struct obd_device *watched,
1495 enum obd_notify_event ev, void *data)
1500 /* the check for async_recov is a complete hack - I'm hereby
1501 overloading the meaning to also mean "this was called from
1502 mds_postsetup". I know that my mds is able to handle notifies
1503 by this point, and it needs to get them to execute mds_postrecov. */
1504 if (!obd->obd_set_up && !obd->obd_async_recov) {
1505 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1509 if (!OBP(obd, notify))
1512 OBD_COUNTER_INCREMENT(obd, notify);
1513 RETURN(OBP(obd, notify)(obd, watched, ev, data));
1516 static inline int obd_notify_observer(struct obd_device *observer,
1517 struct obd_device *observed,
1518 enum obd_notify_event ev, void *data)
1523 struct obd_notify_upcall *onu;
1525 if (observer->obd_observer)
1526 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1530 * Also, call non-obd listener, if any
1532 onu = &observer->obd_upcall;
1533 if (onu->onu_upcall != NULL)
1534 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1541 static inline int obd_quotacheck(struct obd_export *exp,
1542 struct obd_quotactl *oqctl)
1547 EXP_CHECK_OP(exp, quotacheck);
1548 EXP_COUNTER_INCREMENT(exp, quotacheck);
1550 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1554 static inline int obd_quotactl(struct obd_export *exp,
1555 struct obd_quotactl *oqctl)
1560 EXP_CHECK_OP(exp, quotactl);
1561 EXP_COUNTER_INCREMENT(exp, quotactl);
1563 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1567 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1568 struct quota_adjust_qunit *oqaq,
1569 struct lustre_quota_ctxt *qctxt)
1571 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1572 struct timeval work_start;
1573 struct timeval work_end;
1579 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1581 do_gettimeofday(&work_start);
1583 EXP_CHECK_OP(exp, quota_adjust_qunit);
1584 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1586 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1588 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1590 do_gettimeofday(&work_end);
1591 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1592 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1599 static inline int obd_health_check(struct obd_device *obd)
1601 /* returns: 0 on healthy
1602 * >0 on unhealthy + reason code/flag
1603 * however the only suppored reason == 1 right now
1604 * We'll need to define some better reasons
1605 * or flags in the future.
1611 /* don't use EXP_CHECK_OP, because NULL method is normal here */
1612 if (obd == NULL || !OBT(obd)) {
1613 CERROR("cleaned up obd\n");
1614 RETURN(-EOPNOTSUPP);
1616 if (!obd->obd_set_up || obd->obd_stopping)
1618 if (!OBP(obd, health_check))
1621 rc = OBP(obd, health_check)(obd);
1625 static inline int obd_register_observer(struct obd_device *obd,
1626 struct obd_device *observer)
1630 down_write(&obd->obd_observer_link_sem);
1631 if (obd->obd_observer && observer) {
1632 up_write(&obd->obd_observer_link_sem);
1635 obd->obd_observer = observer;
1636 up_write(&obd->obd_observer_link_sem);
1640 static inline int obd_pin_observer(struct obd_device *obd,
1641 struct obd_device **observer)
1644 down_read(&obd->obd_observer_link_sem);
1645 if (!obd->obd_observer) {
1647 up_read(&obd->obd_observer_link_sem);
1650 *observer = obd->obd_observer;
1654 static inline int obd_unpin_observer(struct obd_device *obd)
1657 up_read(&obd->obd_observer_link_sem);
1661 static inline int obd_register_page_removal_cb(struct obd_device *obd,
1662 obd_page_removal_cb_t cb,
1663 obd_pin_extent_cb pin_cb)
1668 OBD_CHECK_OP(obd, register_page_removal_cb, 0);
1669 OBD_COUNTER_INCREMENT(obd, register_page_removal_cb);
1671 rc = OBP(obd, register_page_removal_cb)(obd, cb, pin_cb);
1675 static inline int obd_unregister_page_removal_cb(struct obd_device *obd,
1676 obd_page_removal_cb_t cb)
1681 OBD_CHECK_OP(obd, unregister_page_removal_cb, 0);
1682 OBD_COUNTER_INCREMENT(obd, unregister_page_removal_cb);
1684 rc = OBP(obd, unregister_page_removal_cb)(obd, cb);
1688 static inline int obd_register_lock_cancel_cb(struct obd_device *obd,
1689 obd_lock_cancel_cb cb)
1694 OBD_CHECK_OP(obd, register_lock_cancel_cb, 0);
1695 OBD_COUNTER_INCREMENT(obd, register_lock_cancel_cb);
1697 rc = OBP(obd, register_lock_cancel_cb)(obd, cb);
1701 static inline int obd_unregister_lock_cancel_cb(struct obd_device *obd,
1702 obd_lock_cancel_cb cb)
1707 OBD_CHECK_OP(obd, unregister_lock_cancel_cb, 0);
1708 OBD_COUNTER_INCREMENT(obd, unregister_lock_cancel_cb);
1710 rc = OBP(obd, unregister_lock_cancel_cb)(obd, cb);
1714 /* OBD Metadata Support */
1716 extern int obd_init_caches(void);
1717 extern void obd_cleanup_caches(void);
1719 /* support routines */
1720 extern cfs_mem_cache_t *obdo_cachep;
1722 #define OBDO_ALLOC(ptr) \
1724 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
1727 #define OBDO_FREE(ptr) \
1729 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1732 /* I'm as embarrassed about this as you are.
1734 * <shaver> // XXX do not look into _superhack with remaining eye
1735 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1736 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1739 extern void obd_sysctl_init (void);
1740 extern void obd_sysctl_clean (void);
1743 typedef __u8 class_uuid_t[16];
1744 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1747 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index);
1748 int class_add_uuid(char *uuid, __u64 nid);
1749 int class_del_uuid (char *uuid);
1750 void class_init_uuidlist(void);
1751 void class_exit_uuidlist(void);
1754 void ll_generate_random_uuid(class_uuid_t uuid_out);
1756 #endif /* __LINUX_OBD_CLASS_H */