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 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp) {
312 rc = lprocfs_register_stats(tmp->nid_proc, "stats",
317 /* Always add in ldlm_stats */
318 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
319 ,LPROCFS_STATS_FLAG_NOPERCPU);
320 if (tmp->nid_ldlm_stats == NULL)
323 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
325 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
326 tmp->nid_ldlm_stats);
329 #define OBD_CHECK_OP(obd, op, err) \
331 if (!OBT(obd) || !OBP((obd), op)) {\
333 CERROR("obd_" #op ": dev %d no operation\n", \
339 #define EXP_CHECK_OP(exp, op) \
341 if ((exp) == NULL) { \
342 CERROR("obd_" #op ": NULL export\n"); \
345 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
346 CERROR("obd_" #op ": cleaned up obd\n"); \
347 RETURN(-EOPNOTSUPP); \
349 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
350 CERROR("obd_" #op ": dev %d no operation\n", \
351 (exp)->exp_obd->obd_minor); \
352 RETURN(-EOPNOTSUPP); \
356 #define CTXT_CHECK_OP(ctxt, op, err) \
358 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
360 CERROR("lop_" #op ": dev %d no operation\n", \
361 ctxt->loc_obd->obd_minor); \
366 static inline int class_devno_max(void)
368 return MAX_OBD_DEVICES;
371 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
372 void *key, __u32 *vallen, void *val,
373 struct lov_stripe_md *lsm)
378 EXP_CHECK_OP(exp, get_info);
379 EXP_COUNTER_INCREMENT(exp, get_info);
381 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
385 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
386 void *key, obd_count vallen, void *val,
387 struct ptlrpc_request_set *set)
392 EXP_CHECK_OP(exp, set_info_async);
393 EXP_COUNTER_INCREMENT(exp, set_info_async);
395 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
400 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
405 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
406 OBD_COUNTER_INCREMENT(obd, setup);
408 rc = OBP(obd, setup)(obd, datalen, data);
412 static inline int obd_precleanup(struct obd_device *obd,
413 enum obd_cleanup_stage cleanup_stage)
418 OBD_CHECK_OP(obd, precleanup, 0);
419 OBD_COUNTER_INCREMENT(obd, precleanup);
421 rc = OBP(obd, precleanup)(obd, cleanup_stage);
425 static inline int obd_cleanup(struct obd_device *obd)
431 OBD_CHECK_OP(obd, cleanup, 0);
432 OBD_COUNTER_INCREMENT(obd, cleanup);
434 rc = OBP(obd, cleanup)(obd);
439 obd_process_config(struct obd_device *obd, int datalen, void *data)
444 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
445 OBD_COUNTER_INCREMENT(obd, process_config);
447 rc = OBP(obd, process_config)(obd, datalen, data);
451 /* Pack an in-memory MD struct for storage on disk.
452 * Returns +ve size of packed MD (0 for free), or -ve error.
454 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
455 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
456 * If @*disk_tgt == NULL, it will be allocated
458 static inline int obd_packmd(struct obd_export *exp,
459 struct lov_mds_md **disk_tgt,
460 struct lov_stripe_md *mem_src)
465 EXP_CHECK_OP(exp, packmd);
466 EXP_COUNTER_INCREMENT(exp, packmd);
468 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
472 static inline int obd_size_diskmd(struct obd_export *exp,
473 struct lov_stripe_md *mem_src)
475 return obd_packmd(exp, NULL, mem_src);
478 /* helper functions */
479 static inline int obd_alloc_diskmd(struct obd_export *exp,
480 struct lov_mds_md **disk_tgt)
483 LASSERT(*disk_tgt == NULL);
484 return obd_packmd(exp, disk_tgt, NULL);
487 static inline int obd_free_diskmd(struct obd_export *exp,
488 struct lov_mds_md **disk_tgt)
492 return obd_packmd(exp, disk_tgt, NULL);
495 /* Unpack an MD struct from disk to in-memory format.
496 * Returns +ve size of unpacked MD (0 for free), or -ve error.
498 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
499 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
500 * If @*mem_tgt == NULL, it will be allocated
502 static inline int obd_unpackmd(struct obd_export *exp,
503 struct lov_stripe_md **mem_tgt,
504 struct lov_mds_md *disk_src,
510 EXP_CHECK_OP(exp, unpackmd);
511 EXP_COUNTER_INCREMENT(exp, unpackmd);
513 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
517 /* helper functions */
518 static inline int obd_alloc_memmd(struct obd_export *exp,
519 struct lov_stripe_md **mem_tgt)
522 LASSERT(*mem_tgt == NULL);
523 return obd_unpackmd(exp, mem_tgt, NULL, 0);
526 static inline int obd_free_memmd(struct obd_export *exp,
527 struct lov_stripe_md **mem_tgt)
531 return obd_unpackmd(exp, mem_tgt, NULL, 0);
534 static inline int obd_checkmd(struct obd_export *exp,
535 struct obd_export *md_exp,
536 struct lov_stripe_md *mem_tgt)
541 EXP_CHECK_OP(exp, checkmd);
542 EXP_COUNTER_INCREMENT(exp, checkmd);
544 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
548 static inline int obd_precreate(struct obd_export *exp)
553 EXP_CHECK_OP(exp, precreate);
554 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
556 rc = OBP(exp->exp_obd, precreate)(exp);
560 static inline int obd_create_async(struct obd_export *exp,
561 struct obd_info *oinfo,
562 struct lov_stripe_md **ea,
563 struct obd_trans_info *oti)
568 EXP_CHECK_OP(exp, create_async);
569 EXP_COUNTER_INCREMENT(exp, create_async);
571 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
575 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
576 struct lov_stripe_md **ea,
577 struct obd_trans_info *oti)
582 EXP_CHECK_OP(exp, create);
583 EXP_COUNTER_INCREMENT(exp, create);
585 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
589 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
590 struct lov_stripe_md *ea,
591 struct obd_trans_info *oti,
592 struct obd_export *md_exp)
597 EXP_CHECK_OP(exp, destroy);
598 EXP_COUNTER_INCREMENT(exp, destroy);
600 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
604 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
609 EXP_CHECK_OP(exp, getattr);
610 EXP_COUNTER_INCREMENT(exp, getattr);
612 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
616 static inline int obd_getattr_async(struct obd_export *exp,
617 struct obd_info *oinfo,
618 struct ptlrpc_request_set *set)
623 EXP_CHECK_OP(exp, getattr_async);
624 EXP_COUNTER_INCREMENT(exp, getattr_async);
626 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
630 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
631 struct obd_trans_info *oti)
636 EXP_CHECK_OP(exp, setattr);
637 EXP_COUNTER_INCREMENT(exp, setattr);
639 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
643 /* This performs all the requests set init/wait/destroy actions. */
644 static inline int obd_setattr_rqset(struct obd_export *exp,
645 struct obd_info *oinfo,
646 struct obd_trans_info *oti)
648 struct ptlrpc_request_set *set = NULL;
652 EXP_CHECK_OP(exp, setattr_async);
653 EXP_COUNTER_INCREMENT(exp, setattr_async);
655 set = ptlrpc_prep_set();
659 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
661 rc = ptlrpc_set_wait(set);
662 ptlrpc_set_destroy(set);
666 /* This adds all the requests into @set if @set != NULL, otherwise
667 all requests are sent asynchronously without waiting for response. */
668 static inline int obd_setattr_async(struct obd_export *exp,
669 struct obd_info *oinfo,
670 struct obd_trans_info *oti,
671 struct ptlrpc_request_set *set)
676 EXP_CHECK_OP(exp, setattr_async);
677 EXP_COUNTER_INCREMENT(exp, setattr_async);
679 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
683 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
686 struct obd_device *obd = imp->imp_obd;
690 OBD_CHECK_DEV_ACTIVE(obd);
691 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
692 OBD_COUNTER_INCREMENT(obd, add_conn);
694 rc = OBP(obd, add_conn)(imp, uuid, priority);
698 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
700 struct obd_device *obd = imp->imp_obd;
704 OBD_CHECK_DEV_ACTIVE(obd);
705 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
706 OBD_COUNTER_INCREMENT(obd, del_conn);
708 rc = OBP(obd, del_conn)(imp, uuid);
712 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
713 struct obd_uuid *cluuid,
714 struct obd_connect_data *d,
718 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
721 OBD_CHECK_DEV_ACTIVE(obd);
722 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
723 OBD_COUNTER_INCREMENT(obd, connect);
725 rc = OBP(obd, connect)(conn, obd, cluuid, d, localdata);
726 /* check that only subset is granted */
727 LASSERT(ergo(d != NULL,
728 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
732 static inline int obd_reconnect(struct obd_export *exp,
733 struct obd_device *obd,
734 struct obd_uuid *cluuid,
735 struct obd_connect_data *d,
739 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
742 OBD_CHECK_DEV_ACTIVE(obd);
743 OBD_CHECK_OP(obd, reconnect, 0);
744 OBD_COUNTER_INCREMENT(obd, reconnect);
746 rc = OBP(obd, reconnect)(exp, obd, cluuid, d, localdata);
747 /* check that only subset is granted */
748 LASSERT(ergo(d != NULL,
749 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
753 static inline int obd_disconnect(struct obd_export *exp)
758 EXP_CHECK_OP(exp, disconnect);
759 EXP_COUNTER_INCREMENT(exp, disconnect);
761 rc = OBP(exp->exp_obd, disconnect)(exp);
765 static inline int obd_fid_init(struct obd_export *exp)
770 OBD_CHECK_OP(exp->exp_obd, fid_init, 0);
771 EXP_COUNTER_INCREMENT(exp, fid_init);
773 rc = OBP(exp->exp_obd, fid_init)(exp);
777 static inline int obd_fid_fini(struct obd_export *exp)
782 OBD_CHECK_OP(exp->exp_obd, fid_fini, 0);
783 EXP_COUNTER_INCREMENT(exp, fid_fini);
785 rc = OBP(exp->exp_obd, fid_fini)(exp);
789 static inline int obd_ping(struct obd_export *exp)
794 OBD_CHECK_OP(exp->exp_obd, ping, 0);
795 EXP_COUNTER_INCREMENT(exp, ping);
797 rc = OBP(exp->exp_obd, ping)(exp);
801 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
806 OBD_CHECK_OP(obd, pool_new, -EOPNOTSUPP);
807 OBD_COUNTER_INCREMENT(obd, pool_new);
809 rc = OBP(obd, pool_new)(obd, poolname);
813 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
818 OBD_CHECK_OP(obd, pool_del, -EOPNOTSUPP);
819 OBD_COUNTER_INCREMENT(obd, pool_del);
821 rc = OBP(obd, pool_del)(obd, poolname);
825 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
830 OBD_CHECK_OP(obd, pool_add, -EOPNOTSUPP);
831 OBD_COUNTER_INCREMENT(obd, pool_add);
833 rc = OBP(obd, pool_add)(obd, poolname, ostname);
837 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
842 OBD_CHECK_OP(obd, pool_rem, -EOPNOTSUPP);
843 OBD_COUNTER_INCREMENT(obd, pool_rem);
845 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
849 static inline void obd_getref(struct obd_device *obd)
852 if (OBT(obd) && OBP(obd, getref)) {
853 OBD_COUNTER_INCREMENT(obd, getref);
854 OBP(obd, getref)(obd);
859 static inline void obd_putref(struct obd_device *obd)
862 if (OBT(obd) && OBP(obd, putref)) {
863 OBD_COUNTER_INCREMENT(obd, putref);
864 OBP(obd, putref)(obd);
869 static inline int obd_init_export(struct obd_export *exp)
874 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
875 OBP((exp)->exp_obd, init_export))
876 rc = OBP(exp->exp_obd, init_export)(exp);
880 static inline int obd_destroy_export(struct obd_export *exp)
883 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
884 OBP((exp)->exp_obd, destroy_export))
885 OBP(exp->exp_obd, destroy_export)(exp);
889 static inline int obd_extent_calc(struct obd_export *exp,
890 struct lov_stripe_md *md,
891 int cmd, obd_off *offset)
895 EXP_CHECK_OP(exp, extent_calc);
896 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
900 static inline struct dentry *
901 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
903 LASSERT(exp->exp_obd);
905 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
910 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
913 /* @max_age is the oldest time in jiffies that we accept using a cached data.
914 * If the cache is older than @max_age we will get a new value from the
915 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
916 static inline int obd_statfs_async(struct obd_device *obd,
917 struct obd_info *oinfo,
919 struct ptlrpc_request_set *rqset)
927 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
928 OBD_COUNTER_INCREMENT(obd, statfs);
930 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
931 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
932 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
933 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
935 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
936 " objects "LPU64"/"LPU64"\n",
937 obd->obd_name, &obd->obd_osfs,
938 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
939 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
940 spin_lock(&obd->obd_osfs_lock);
941 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
942 spin_unlock(&obd->obd_osfs_lock);
943 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
945 oinfo->oi_cb_up(oinfo, 0);
950 static inline int obd_statfs_rqset(struct obd_device *obd,
951 struct obd_statfs *osfs, __u64 max_age,
954 struct ptlrpc_request_set *set = NULL;
955 struct obd_info oinfo = { { { 0 } } };
959 set = ptlrpc_prep_set();
963 oinfo.oi_osfs = osfs;
964 oinfo.oi_flags = flags;
965 rc = obd_statfs_async(obd, &oinfo, max_age, set);
967 rc = ptlrpc_set_wait(set);
968 ptlrpc_set_destroy(set);
972 /* @max_age is the oldest time in jiffies that we accept using a cached data.
973 * If the cache is older than @max_age we will get a new value from the
974 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
975 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
976 __u64 max_age, __u32 flags)
984 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
985 OBD_COUNTER_INCREMENT(obd, statfs);
987 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
988 obd->obd_osfs_age, max_age);
989 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
990 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
992 spin_lock(&obd->obd_osfs_lock);
993 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
994 obd->obd_osfs_age = cfs_time_current_64();
995 spin_unlock(&obd->obd_osfs_lock);
998 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
999 " objects "LPU64"/"LPU64"\n",
1000 obd->obd_name, &obd->obd_osfs,
1001 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1002 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1003 spin_lock(&obd->obd_osfs_lock);
1004 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1005 spin_unlock(&obd->obd_osfs_lock);
1010 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1011 obd_size start, obd_size end)
1013 struct ptlrpc_request_set *set = NULL;
1017 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1018 EXP_COUNTER_INCREMENT(exp, sync);
1020 set = ptlrpc_prep_set();
1024 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1026 rc = ptlrpc_set_wait(set);
1027 ptlrpc_set_destroy(set);
1031 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1032 obd_size start, obd_size end,
1033 struct ptlrpc_request_set *set)
1038 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1039 EXP_COUNTER_INCREMENT(exp, sync);
1041 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1045 static inline int obd_punch_rqset(struct obd_export *exp,
1046 struct obd_info *oinfo,
1047 struct obd_trans_info *oti)
1049 struct ptlrpc_request_set *set = NULL;
1053 EXP_CHECK_OP(exp, punch);
1054 EXP_COUNTER_INCREMENT(exp, punch);
1056 set = ptlrpc_prep_set();
1060 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1062 rc = ptlrpc_set_wait(set);
1063 ptlrpc_set_destroy(set);
1067 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1068 struct obd_trans_info *oti,
1069 struct ptlrpc_request_set *rqset)
1074 EXP_CHECK_OP(exp, punch);
1075 EXP_COUNTER_INCREMENT(exp, punch);
1077 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1081 static inline int obd_brw(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)
1088 EXP_CHECK_OP(exp, brw);
1089 EXP_COUNTER_INCREMENT(exp, brw);
1091 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1092 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1093 "or OBD_BRW_CHECK\n");
1097 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1101 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1102 struct obd_info *oinfo, obd_count oa_bufs,
1103 struct brw_page *pg, struct obd_trans_info *oti,
1104 struct ptlrpc_request_set *set, int pshift)
1109 EXP_CHECK_OP(exp, brw_async);
1110 EXP_COUNTER_INCREMENT(exp, brw_async);
1112 if (!(cmd & OBD_BRW_RWMASK)) {
1113 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1117 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs,
1118 pg, oti,set, pshift);
1122 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1123 struct obdo *oa, struct lov_stripe_md *lsm,
1124 obd_count oa_bufs, struct brw_page *pg,
1125 struct obd_trans_info *oti)
1127 struct ptlrpc_request_set *set = NULL;
1128 struct obd_info oinfo = { { { 0 } } };
1132 set = ptlrpc_prep_set();
1138 rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set, 0);
1140 rc = ptlrpc_set_wait(set);
1142 CERROR("error from callback: rc = %d\n", rc);
1144 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
1145 "error from obd_brw_async: rc = %d\n", rc);
1147 ptlrpc_set_destroy(set);
1151 /* flags used by obd_prep_async_page */
1152 #define OBD_PAGE_NO_CACHE 0x00000001 /* don't add to cache */
1153 #define OBD_FAST_LOCK 0x00000002 /* lockh refers to a "fast lock" */
1155 static inline int obd_prep_async_page(struct obd_export *exp,
1156 struct lov_stripe_md *lsm,
1157 struct lov_oinfo *loi,
1158 cfs_page_t *page, obd_off offset,
1159 struct obd_async_page_ops *ops,
1160 void *data, void **res, int flags,
1161 struct lustre_handle *lockh)
1166 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
1167 EXP_COUNTER_INCREMENT(exp, prep_async_page);
1169 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1170 ops, data, res, flags,
1175 static inline int obd_get_lock(struct obd_export *exp,
1176 struct lov_stripe_md *lsm, void **res, int rw,
1177 obd_off start, obd_off end,
1178 struct lustre_handle *lockh, int flags)
1182 OBD_CHECK_OP(exp->exp_obd, get_lock, -EOPNOTSUPP);
1183 EXP_COUNTER_INCREMENT(exp, get_lock);
1185 RETURN(OBP(exp->exp_obd, get_lock)(exp, lsm, res, rw, start, end,
1189 static inline int obd_queue_async_io(struct obd_export *exp,
1190 struct lov_stripe_md *lsm,
1191 struct lov_oinfo *loi, void *cookie,
1192 int cmd, obd_off off, int count,
1193 obd_flag brw_flags, obd_flag async_flags)
1198 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
1199 EXP_COUNTER_INCREMENT(exp, queue_async_io);
1200 LASSERT(cmd & OBD_BRW_RWMASK);
1202 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1203 count, brw_flags, async_flags);
1207 static inline int obd_set_async_flags(struct obd_export *exp,
1208 struct lov_stripe_md *lsm,
1209 struct lov_oinfo *loi, void *cookie,
1210 obd_flag async_flags)
1215 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1216 EXP_COUNTER_INCREMENT(exp, set_async_flags);
1218 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1223 static inline int obd_queue_group_io(struct obd_export *exp,
1224 struct lov_stripe_md *lsm,
1225 struct lov_oinfo *loi,
1226 struct obd_io_group *oig,
1227 void *cookie, int cmd, obd_off off,
1228 int count, obd_flag brw_flags,
1229 obd_flag async_flags)
1234 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1235 EXP_COUNTER_INCREMENT(exp, queue_group_io);
1236 LASSERT(cmd & OBD_BRW_RWMASK);
1238 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1239 cmd, off, count, brw_flags,
1244 static inline int obd_trigger_group_io(struct obd_export *exp,
1245 struct lov_stripe_md *lsm,
1246 struct lov_oinfo *loi,
1247 struct obd_io_group *oig)
1252 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1253 EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1255 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1259 static inline int obd_teardown_async_page(struct obd_export *exp,
1260 struct lov_stripe_md *lsm,
1261 struct lov_oinfo *loi, void *cookie)
1266 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1267 EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1269 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1273 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1274 int objcount, struct obd_ioobj *obj,
1275 struct niobuf_remote *remote, int *pages,
1276 struct niobuf_local *local,
1277 struct obd_trans_info *oti)
1282 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1283 EXP_COUNTER_INCREMENT(exp, preprw);
1285 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1290 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1291 int objcount, struct obd_ioobj *obj,
1292 struct niobuf_remote *rnb, int pages,
1293 struct niobuf_local *local,
1294 struct obd_trans_info *oti, int rc)
1298 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1299 EXP_COUNTER_INCREMENT(exp, commitrw);
1301 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1302 rnb, pages, local, oti, rc);
1306 static inline int obd_merge_lvb(struct obd_export *exp,
1307 struct lov_stripe_md *lsm,
1308 struct ost_lvb *lvb, int kms_only)
1313 OBD_CHECK_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1314 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1316 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1320 static inline int obd_update_lvb(struct obd_export *exp,
1321 struct lov_stripe_md *lsm,
1322 struct ost_lvb *lvb, obd_flag valid)
1327 OBD_CHECK_OP(exp->exp_obd, update_lvb, -EOPNOTSUPP);
1328 EXP_COUNTER_INCREMENT(exp, update_lvb);
1330 rc = OBP(exp->exp_obd, update_lvb)(exp, lsm, lvb, valid);
1334 static inline int obd_adjust_kms(struct obd_export *exp,
1335 struct lov_stripe_md *lsm, obd_off size,
1341 OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1342 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1344 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1348 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1349 int len, void *karg, void *uarg)
1354 EXP_CHECK_OP(exp, iocontrol);
1355 EXP_COUNTER_INCREMENT(exp, iocontrol);
1357 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1361 static inline int obd_enqueue_rqset(struct obd_export *exp,
1362 struct obd_info *oinfo,
1363 struct ldlm_enqueue_info *einfo)
1365 struct ptlrpc_request_set *set = NULL;
1369 EXP_CHECK_OP(exp, enqueue);
1370 EXP_COUNTER_INCREMENT(exp, enqueue);
1372 set = ptlrpc_prep_set();
1376 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1378 rc = ptlrpc_set_wait(set);
1379 ptlrpc_set_destroy(set);
1383 static inline int obd_enqueue(struct obd_export *exp,
1384 struct obd_info *oinfo,
1385 struct ldlm_enqueue_info *einfo,
1386 struct ptlrpc_request_set *set)
1391 EXP_CHECK_OP(exp, enqueue);
1392 EXP_COUNTER_INCREMENT(exp, enqueue);
1394 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1398 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1399 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1400 int *flags, void *data, struct lustre_handle *lockh,
1406 EXP_CHECK_OP(exp, match);
1407 EXP_COUNTER_INCREMENT(exp, match);
1409 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1414 static inline int obd_change_cbdata(struct obd_export *exp,
1415 struct lov_stripe_md *lsm,
1416 ldlm_iterator_t it, void *data)
1421 EXP_CHECK_OP(exp, change_cbdata);
1422 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1424 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1428 static inline int obd_find_cbdata(struct obd_export *exp,
1429 struct lov_stripe_md *lsm,
1430 ldlm_iterator_t it, void *data)
1435 EXP_CHECK_OP(exp, find_cbdata);
1436 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1438 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1442 static inline int obd_cancel(struct obd_export *exp, struct lov_stripe_md *ea,
1443 __u32 mode, struct lustre_handle *lockh, int flags,
1449 EXP_CHECK_OP(exp, cancel);
1450 EXP_COUNTER_INCREMENT(exp, cancel);
1452 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh, flags, end);
1456 static inline int obd_cancel_unused(struct obd_export *exp,
1457 struct lov_stripe_md *ea, int flags,
1463 EXP_CHECK_OP(exp, cancel_unused);
1464 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1466 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1470 static inline int obd_join_lru(struct obd_export *exp,
1471 struct lov_stripe_md *ea, int join)
1476 EXP_CHECK_OP(exp, join_lru);
1477 EXP_COUNTER_INCREMENT(exp, join_lru);
1479 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1483 static inline int obd_pin(struct obd_export *exp, struct ll_fid *fid,
1484 struct obd_client_handle *handle, int flag)
1489 EXP_CHECK_OP(exp, pin);
1490 EXP_COUNTER_INCREMENT(exp, pin);
1492 rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1496 static inline int obd_unpin(struct obd_export *exp,
1497 struct obd_client_handle *handle, int flag)
1502 EXP_CHECK_OP(exp, unpin);
1503 EXP_COUNTER_INCREMENT(exp, unpin);
1505 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1510 static inline void obd_import_event(struct obd_device *obd,
1511 struct obd_import *imp,
1512 enum obd_import_event event)
1516 CERROR("NULL device\n");
1520 if (obd->obd_set_up && OBP(obd, import_event)) {
1521 OBD_COUNTER_INCREMENT(obd, import_event);
1522 OBP(obd, import_event)(obd, imp, event);
1527 static inline int obd_notify(struct obd_device *obd,
1528 struct obd_device *watched,
1529 enum obd_notify_event ev, void *data)
1534 /* the check for async_recov is a complete hack - I'm hereby
1535 overloading the meaning to also mean "this was called from
1536 mds_postsetup". I know that my mds is able to handle notifies
1537 by this point, and it needs to get them to execute mds_postrecov. */
1538 if (!obd->obd_set_up && !obd->obd_async_recov) {
1539 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1543 if (!OBP(obd, notify))
1546 OBD_COUNTER_INCREMENT(obd, notify);
1547 RETURN(OBP(obd, notify)(obd, watched, ev, data));
1550 static inline int obd_notify_observer(struct obd_device *observer,
1551 struct obd_device *observed,
1552 enum obd_notify_event ev, void *data)
1557 struct obd_notify_upcall *onu;
1559 if (observer->obd_observer)
1560 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1564 * Also, call non-obd listener, if any
1566 onu = &observer->obd_upcall;
1567 if (onu->onu_upcall != NULL)
1568 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1575 static inline int obd_quotacheck(struct obd_export *exp,
1576 struct obd_quotactl *oqctl)
1581 EXP_CHECK_OP(exp, quotacheck);
1582 EXP_COUNTER_INCREMENT(exp, quotacheck);
1584 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1588 static inline int obd_quotactl(struct obd_export *exp,
1589 struct obd_quotactl *oqctl)
1594 EXP_CHECK_OP(exp, quotactl);
1595 EXP_COUNTER_INCREMENT(exp, quotactl);
1597 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1601 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1602 struct quota_adjust_qunit *oqaq,
1603 struct lustre_quota_ctxt *qctxt)
1605 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1606 struct timeval work_start;
1607 struct timeval work_end;
1613 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1615 do_gettimeofday(&work_start);
1617 EXP_CHECK_OP(exp, quota_adjust_qunit);
1618 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1620 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1622 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1624 do_gettimeofday(&work_end);
1625 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1626 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1633 static inline int obd_health_check(struct obd_device *obd)
1635 /* returns: 0 on healthy
1636 * >0 on unhealthy + reason code/flag
1637 * however the only suppored reason == 1 right now
1638 * We'll need to define some better reasons
1639 * or flags in the future.
1645 /* don't use EXP_CHECK_OP, because NULL method is normal here */
1646 if (obd == NULL || !OBT(obd)) {
1647 CERROR("cleaned up obd\n");
1648 RETURN(-EOPNOTSUPP);
1650 if (!obd->obd_set_up || obd->obd_stopping)
1652 if (!OBP(obd, health_check))
1655 rc = OBP(obd, health_check)(obd);
1659 static inline int obd_register_observer(struct obd_device *obd,
1660 struct obd_device *observer)
1664 down_write(&obd->obd_observer_link_sem);
1665 if (obd->obd_observer && observer) {
1666 up_write(&obd->obd_observer_link_sem);
1669 obd->obd_observer = observer;
1670 up_write(&obd->obd_observer_link_sem);
1674 static inline int obd_pin_observer(struct obd_device *obd,
1675 struct obd_device **observer)
1678 down_read(&obd->obd_observer_link_sem);
1679 if (!obd->obd_observer) {
1681 up_read(&obd->obd_observer_link_sem);
1684 *observer = obd->obd_observer;
1688 static inline int obd_unpin_observer(struct obd_device *obd)
1691 up_read(&obd->obd_observer_link_sem);
1695 static inline int obd_register_page_removal_cb(struct obd_device *obd,
1696 obd_page_removal_cb_t cb,
1697 obd_pin_extent_cb pin_cb)
1702 OBD_CHECK_OP(obd, register_page_removal_cb, 0);
1703 OBD_COUNTER_INCREMENT(obd, register_page_removal_cb);
1705 rc = OBP(obd, register_page_removal_cb)(obd, cb, pin_cb);
1709 static inline int obd_unregister_page_removal_cb(struct obd_device *obd,
1710 obd_page_removal_cb_t cb)
1715 OBD_CHECK_OP(obd, unregister_page_removal_cb, 0);
1716 OBD_COUNTER_INCREMENT(obd, unregister_page_removal_cb);
1718 rc = OBP(obd, unregister_page_removal_cb)(obd, cb);
1722 static inline int obd_register_lock_cancel_cb(struct obd_device *obd,
1723 obd_lock_cancel_cb cb)
1728 OBD_CHECK_OP(obd, register_lock_cancel_cb, 0);
1729 OBD_COUNTER_INCREMENT(obd, register_lock_cancel_cb);
1731 rc = OBP(obd, register_lock_cancel_cb)(obd, cb);
1735 static inline int obd_unregister_lock_cancel_cb(struct obd_device *obd,
1736 obd_lock_cancel_cb cb)
1741 OBD_CHECK_OP(obd, unregister_lock_cancel_cb, 0);
1742 OBD_COUNTER_INCREMENT(obd, unregister_lock_cancel_cb);
1744 rc = OBP(obd, unregister_lock_cancel_cb)(obd, cb);
1748 /* OBD Metadata Support */
1750 extern int obd_init_caches(void);
1751 extern void obd_cleanup_caches(void);
1753 /* support routines */
1754 extern cfs_mem_cache_t *obdo_cachep;
1756 #define OBDO_ALLOC(ptr) \
1758 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
1761 #define OBDO_FREE(ptr) \
1763 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1766 /* I'm as embarrassed about this as you are.
1768 * <shaver> // XXX do not look into _superhack with remaining eye
1769 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1770 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1773 extern void obd_sysctl_init (void);
1774 extern void obd_sysctl_clean (void);
1777 typedef __u8 class_uuid_t[16];
1778 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1781 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index);
1782 int class_add_uuid(char *uuid, __u64 nid);
1783 int class_del_uuid (char *uuid);
1784 void class_init_uuidlist(void);
1785 void class_exit_uuidlist(void);
1788 void ll_generate_random_uuid(class_uuid_t uuid_out);
1790 #endif /* __LINUX_OBD_CLASS_H */