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 <liblustre.h>
43 #include <obd_support.h>
44 #include <lustre_import.h>
45 #include <lustre_net.h>
47 #include <lustre_lib.h>
48 #include <lustre/lustre_idl.h>
49 #include <lprocfs_status.h>
51 #if defined(__linux__)
52 #include <linux/obd_class.h>
53 #elif defined(__APPLE__)
54 #include <darwin/obd_class.h>
55 #elif defined(__WINNT__)
56 #include <winnt/obd_class.h>
58 #error Unsupported operating system.
61 /* OBD Device Declarations */
62 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
63 extern spinlock_t obd_dev_lock;
65 /* OBD Operations Declarations */
66 extern struct obd_device *class_conn2obd(struct lustre_handle *);
67 extern struct obd_device *class_exp2obd(struct obd_export *);
69 struct lu_device_type;
72 struct obd_export *class_conn2export(struct lustre_handle *);
73 int class_register_type(struct obd_ops *, struct md_ops *,
74 struct lprocfs_vars *, const char *nm,
75 struct lu_device_type *ldt);
76 int class_unregister_type(const char *nm);
78 struct obd_device *class_newdev(const char *type_name, const char *name);
79 void class_release_dev(struct obd_device *obd);
81 int class_name2dev(const char *name);
82 struct obd_device *class_name2obd(const char *name);
83 int class_uuid2dev(struct obd_uuid *uuid);
84 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
85 void class_obd_list(void);
86 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
87 const char * typ_name,
88 struct obd_uuid *grp_uuid);
89 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
91 struct obd_device * class_num2obd(int num);
93 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
95 char *obd_export_nid2str(struct obd_export *exp);
97 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
98 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
100 int obd_zombie_impexp_init(void);
101 void obd_zombie_impexp_stop(void);
102 void obd_zombie_impexp_cull(void);
103 void obd_zombie_barrier(void);
104 void obd_exports_barrier(struct obd_device *obd);
107 int class_process_config(struct lustre_cfg *lcfg);
108 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
109 struct lustre_cfg *lcfg, void *data);
110 int class_attach(struct lustre_cfg *lcfg);
111 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
112 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
113 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
114 struct obd_device *class_incref(struct obd_device *obd,
115 const char *scope, const void *source);
116 void class_decref(struct obd_device *obd,
117 const char *scope, const void *source);
118 void dump_exports(struct obd_device *obd, int locks);
122 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
124 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
126 memset(lvars, 0, sizeof(*lvars));
130 #define CFG_F_START 0x01 /* Set when we start updating from a log */
131 #define CFG_F_MARKER 0x02 /* We are within a maker */
132 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
133 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
134 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
136 /* Passed as data param to class_config_parse_llog */
137 struct config_llog_instance {
140 struct super_block *cfg_sb;
141 struct obd_uuid cfg_uuid;
142 int cfg_last_idx; /* for partial llog processing */
145 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
146 struct config_llog_instance *cfg);
147 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
148 struct config_llog_instance *cfg);
150 /* list of active configuration logs */
151 struct config_llog_data {
153 struct ldlm_res_id cld_resid;
154 struct config_llog_instance cld_cfg;
155 struct list_head cld_list_chain;
156 atomic_t cld_refcount;
157 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
158 struct obd_export *cld_mgcexp;
159 unsigned int cld_stopping:1, /* we were told to stop watching */
160 cld_lostlock:1, /* lock not requeued */
164 struct lustre_profile {
165 struct list_head lp_list;
171 struct lustre_profile *class_get_profile(const char * prof);
172 void class_del_profile(const char *prof);
173 void class_del_profiles(void);
175 #if LUSTRE_TRACKS_LOCK_EXP_REFS
177 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
178 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
179 extern void (*class_export_dump_hook)(struct obd_export *);
183 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
184 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
188 #define class_export_rpc_get(exp) \
190 atomic_inc(&(exp)->exp_rpc_count); \
191 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
192 (exp), atomic_read(&(exp)->exp_rpc_count)); \
193 class_export_get(exp); \
196 #define class_export_rpc_put(exp) \
198 LASSERT(atomic_read(&exp->exp_rpc_count) > 0); \
199 atomic_dec(&(exp)->exp_rpc_count); \
200 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
201 (exp), atomic_read(&(exp)->exp_rpc_count)); \
202 class_export_put(exp); \
205 #define class_export_lock_get(exp, lock) \
207 atomic_inc(&(exp)->exp_locks_count); \
208 __class_export_add_lock_ref(exp, lock); \
209 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
210 (exp), atomic_read(&(exp)->exp_locks_count)); \
211 class_export_get(exp); \
214 #define class_export_lock_put(exp, lock) \
216 LASSERT(atomic_read(&exp->exp_locks_count) > 0); \
217 atomic_dec(&(exp)->exp_locks_count); \
218 __class_export_del_lock_ref(exp, lock); \
219 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
220 (exp), atomic_read(&(exp)->exp_locks_count)); \
221 class_export_put(exp); \
224 #define class_export_cb_get(exp) \
226 atomic_inc(&(exp)->exp_cb_count); \
227 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
228 (exp), atomic_read(&(exp)->exp_cb_count)); \
229 class_export_get(exp); \
232 #define class_export_cb_put(exp) \
234 LASSERT(atomic_read(&exp->exp_cb_count) > 0); \
235 atomic_dec(&(exp)->exp_cb_count); \
236 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
237 (exp), atomic_read(&(exp)->exp_cb_count)); \
238 class_export_put(exp); \
242 struct obd_export *class_export_get(struct obd_export *exp);
243 void class_export_put(struct obd_export *exp);
244 struct obd_export *class_new_export(struct obd_device *obddev,
245 struct obd_uuid *cluuid);
246 void class_unlink_export(struct obd_export *exp);
248 struct obd_import *class_import_get(struct obd_import *);
249 void class_import_put(struct obd_import *);
250 struct obd_import *class_new_import(struct obd_device *obd);
251 void class_destroy_import(struct obd_import *exp);
253 struct obd_type *class_search_type(const char *name);
254 struct obd_type *class_get_type(const char *name);
255 void class_put_type(struct obd_type *type);
256 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
257 struct obd_uuid *cluuid);
258 int class_disconnect(struct obd_export *exp);
259 void class_fail_export(struct obd_export *exp);
260 void class_disconnect_exports(struct obd_device *obddev);
261 int class_manual_cleanup(struct obd_device *obd);
262 void class_disconnect_stale_exports(struct obd_device *,
263 int (*test_export)(struct obd_export *));
264 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
266 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
267 (obd->obd_force ? OBD_OPT_FORCE : 0) |
268 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
272 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
273 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
274 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
275 unsigned int ia_valid);
276 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
277 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
278 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
281 #define OBT(dev) (dev)->obd_type
282 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
283 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
284 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
286 /* Ensure obd_setup: used for cleanup which must be called
287 while obd is stopping */
288 #define OBD_CHECK_DEV(obd) \
291 CERROR("NULL device\n"); \
296 /* ensure obd_setup and !obd_stopping */
297 #define OBD_CHECK_DEV_ACTIVE(obd) \
299 OBD_CHECK_DEV(obd); \
300 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
301 CERROR("Device %d not setup\n", \
309 #define OBD_COUNTER_OFFSET(op) \
310 ((offsetof(struct obd_ops, o_ ## op) - \
311 offsetof(struct obd_ops, o_iocontrol)) \
312 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
314 #define OBD_COUNTER_INCREMENT(obdx, op) \
315 if ((obdx)->obd_stats != NULL) { \
316 unsigned int coffset; \
317 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
318 OBD_COUNTER_OFFSET(op); \
319 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
320 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
323 #define EXP_COUNTER_INCREMENT(export, op) \
324 if ((export)->exp_obd->obd_stats != NULL) { \
325 unsigned int coffset; \
326 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
327 OBD_COUNTER_OFFSET(op); \
328 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
329 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
330 if ((export)->exp_nid_stats != NULL && \
331 (export)->exp_nid_stats->nid_stats != NULL) \
332 lprocfs_counter_incr( \
333 (export)->exp_nid_stats->nid_stats, coffset);\
336 #define MD_COUNTER_OFFSET(op) \
337 ((offsetof(struct md_ops, m_ ## op) - \
338 offsetof(struct md_ops, m_getstatus)) \
339 / sizeof(((struct md_ops *)(0))->m_getstatus))
341 #define MD_COUNTER_INCREMENT(obdx, op) \
342 if ((obd)->md_stats != NULL) { \
343 unsigned int coffset; \
344 coffset = (unsigned int)((obdx)->md_cntr_base) + \
345 MD_COUNTER_OFFSET(op); \
346 LASSERT(coffset < (obdx)->md_stats->ls_num); \
347 lprocfs_counter_incr((obdx)->md_stats, coffset); \
350 #define EXP_MD_COUNTER_INCREMENT(export, op) \
351 if ((export)->exp_obd->obd_stats != NULL) { \
352 unsigned int coffset; \
353 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
354 MD_COUNTER_OFFSET(op); \
355 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
356 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
357 if ((export)->exp_md_stats != NULL) \
358 lprocfs_counter_incr( \
359 (export)->exp_md_stats, coffset); \
363 #define OBD_COUNTER_OFFSET(op)
364 #define OBD_COUNTER_INCREMENT(obd, op)
365 #define EXP_COUNTER_INCREMENT(exp, op)
366 #define MD_COUNTER_INCREMENT(obd, op)
367 #define EXP_MD_COUNTER_INCREMENT(exp, op)
370 #define OBD_CHECK_MD_OP(obd, op, err) \
372 if (!OBT(obd) || !MDP((obd), op)) { \
374 CERROR("md_" #op ": dev %s/%d no operation\n", \
375 obd->obd_name, obd->obd_minor); \
380 #define EXP_CHECK_MD_OP(exp, op) \
382 if ((exp) == NULL) { \
383 CERROR("obd_" #op ": NULL export\n"); \
386 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
387 CERROR("obd_" #op ": cleaned up obd\n"); \
388 RETURN(-EOPNOTSUPP); \
390 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
391 CERROR("obd_" #op ": dev %s/%d no operation\n", \
392 (exp)->exp_obd->obd_name, \
393 (exp)->exp_obd->obd_minor); \
394 RETURN(-EOPNOTSUPP); \
399 #define OBD_CHECK_DT_OP(obd, op, err) \
401 if (!OBT(obd) || !OBP((obd), op)) { \
403 CERROR("obd_" #op ": dev %d no operation\n", \
409 #define EXP_CHECK_DT_OP(exp, op) \
411 if ((exp) == NULL) { \
412 CERROR("obd_" #op ": NULL export\n"); \
415 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
416 CERROR("obd_" #op ": cleaned up obd\n"); \
417 RETURN(-EOPNOTSUPP); \
419 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
420 CERROR("obd_" #op ": dev %d no operation\n", \
421 (exp)->exp_obd->obd_minor); \
422 RETURN(-EOPNOTSUPP); \
426 #define CTXT_CHECK_OP(ctxt, op, err) \
428 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
430 CERROR("lop_" #op ": dev %d no operation\n", \
431 ctxt->loc_obd->obd_minor); \
436 static inline int class_devno_max(void)
438 return MAX_OBD_DEVICES;
441 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
442 void *key, __u32 *vallen, void *val,
443 struct lov_stripe_md *lsm)
448 EXP_CHECK_DT_OP(exp, get_info);
449 EXP_COUNTER_INCREMENT(exp, get_info);
451 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
455 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
456 void *key, obd_count vallen, void *val,
457 struct ptlrpc_request_set *set)
462 EXP_CHECK_DT_OP(exp, set_info_async);
463 EXP_COUNTER_INCREMENT(exp, set_info_async);
465 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
471 * obd-lu integration.
473 * Functionality is being moved into new lu_device-based layering, but some
474 * pieces of configuration process are still based on obd devices.
476 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
477 * subsume ->o_setup() methods of obd devices they replace. The same for
478 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
479 * result, obd_setup() and obd_process_config() branch and call one XOR
482 * Yet neither lu_device_type_operations::ldto_device_fini() nor
483 * lu_device_type_operations::ldto_device_free() fully implement the
484 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
485 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
488 #define DECLARE_LU_VARS(ldt, d) \
489 struct lu_device_type *ldt; \
492 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
495 DECLARE_LU_VARS(ldt, d);
498 ldt = obd->obd_type->typ_lu;
500 struct lu_context session_ctx;
502 lu_context_init(&session_ctx, LCT_SESSION);
503 session_ctx.lc_thread = NULL;
504 lu_context_enter(&session_ctx);
506 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
508 env.le_ses = &session_ctx;
509 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
518 lu_context_exit(&session_ctx);
519 lu_context_fini(&session_ctx);
522 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
523 OBD_COUNTER_INCREMENT(obd, setup);
524 rc = OBP(obd, setup)(obd, cfg);
529 static inline int obd_precleanup(struct obd_device *obd,
530 enum obd_cleanup_stage cleanup_stage)
533 DECLARE_LU_VARS(ldt, d);
537 ldt = obd->obd_type->typ_lu;
539 if (ldt != NULL && d != NULL) {
540 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
543 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
545 ldt->ldt_ops->ldto_device_fini(&env, d);
550 OBD_CHECK_DT_OP(obd, precleanup, 0);
551 OBD_COUNTER_INCREMENT(obd, precleanup);
553 rc = OBP(obd, precleanup)(obd, cleanup_stage);
557 static inline int obd_cleanup(struct obd_device *obd)
560 DECLARE_LU_VARS(ldt, d);
565 ldt = obd->obd_type->typ_lu;
567 if (ldt != NULL && d != NULL) {
570 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
572 ldt->ldt_ops->ldto_device_free(&env, d);
574 obd->obd_lu_dev = NULL;
577 OBD_CHECK_DT_OP(obd, cleanup, 0);
578 OBD_COUNTER_INCREMENT(obd, cleanup);
580 rc = OBP(obd, cleanup)(obd);
585 obd_process_config(struct obd_device *obd, int datalen, void *data)
588 DECLARE_LU_VARS(ldt, d);
593 obd->obd_process_conf = 1;
594 ldt = obd->obd_type->typ_lu;
596 if (ldt != NULL && d != NULL) {
599 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
601 rc = d->ld_ops->ldo_process_config(&env, d, data);
605 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
606 rc = OBP(obd, process_config)(obd, datalen, data);
608 OBD_COUNTER_INCREMENT(obd, process_config);
609 obd->obd_process_conf = 0;
614 /* Pack an in-memory MD struct for storage on disk.
615 * Returns +ve size of packed MD (0 for free), or -ve error.
617 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
618 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
619 * If @*disk_tgt == NULL, it will be allocated
621 static inline int obd_packmd(struct obd_export *exp,
622 struct lov_mds_md **disk_tgt,
623 struct lov_stripe_md *mem_src)
628 EXP_CHECK_DT_OP(exp, packmd);
629 EXP_COUNTER_INCREMENT(exp, packmd);
631 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
635 static inline int obd_size_diskmd(struct obd_export *exp,
636 struct lov_stripe_md *mem_src)
638 return obd_packmd(exp, NULL, mem_src);
641 /* helper functions */
642 static inline int obd_alloc_diskmd(struct obd_export *exp,
643 struct lov_mds_md **disk_tgt)
646 LASSERT(*disk_tgt == NULL);
647 return obd_packmd(exp, disk_tgt, NULL);
650 static inline int obd_free_diskmd(struct obd_export *exp,
651 struct lov_mds_md **disk_tgt)
655 return obd_packmd(exp, disk_tgt, NULL);
658 /* Unpack an MD struct from disk to in-memory format.
659 * Returns +ve size of unpacked MD (0 for free), or -ve error.
661 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
662 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
663 * If @*mem_tgt == NULL, it will be allocated
665 static inline int obd_unpackmd(struct obd_export *exp,
666 struct lov_stripe_md **mem_tgt,
667 struct lov_mds_md *disk_src,
673 EXP_CHECK_DT_OP(exp, unpackmd);
674 EXP_COUNTER_INCREMENT(exp, unpackmd);
676 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
680 /* helper functions */
681 static inline int obd_alloc_memmd(struct obd_export *exp,
682 struct lov_stripe_md **mem_tgt)
685 LASSERT(*mem_tgt == NULL);
686 return obd_unpackmd(exp, mem_tgt, NULL, 0);
689 static inline int obd_free_memmd(struct obd_export *exp,
690 struct lov_stripe_md **mem_tgt)
696 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
701 static inline int obd_precreate(struct obd_export *exp)
706 EXP_CHECK_DT_OP(exp, precreate);
707 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
709 rc = OBP(exp->exp_obd, precreate)(exp);
713 static inline int obd_create_async(struct obd_export *exp,
714 struct obd_info *oinfo,
715 struct lov_stripe_md **ea,
716 struct obd_trans_info *oti)
721 EXP_CHECK_DT_OP(exp, create_async);
722 EXP_COUNTER_INCREMENT(exp, create_async);
724 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
728 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
729 struct lov_stripe_md **ea,
730 struct obd_trans_info *oti)
735 EXP_CHECK_DT_OP(exp, create);
736 EXP_COUNTER_INCREMENT(exp, create);
738 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
742 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
743 struct lov_stripe_md *ea,
744 struct obd_trans_info *oti,
745 struct obd_export *md_exp, void *capa)
750 EXP_CHECK_DT_OP(exp, destroy);
751 EXP_COUNTER_INCREMENT(exp, destroy);
753 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
757 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
762 EXP_CHECK_DT_OP(exp, getattr);
763 EXP_COUNTER_INCREMENT(exp, getattr);
765 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
769 static inline int obd_getattr_async(struct obd_export *exp,
770 struct obd_info *oinfo,
771 struct ptlrpc_request_set *set)
776 EXP_CHECK_DT_OP(exp, getattr_async);
777 EXP_COUNTER_INCREMENT(exp, getattr_async);
779 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
783 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
784 struct obd_trans_info *oti)
789 EXP_CHECK_DT_OP(exp, setattr);
790 EXP_COUNTER_INCREMENT(exp, setattr);
792 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
796 /* This performs all the requests set init/wait/destroy actions. */
797 static inline int obd_setattr_rqset(struct obd_export *exp,
798 struct obd_info *oinfo,
799 struct obd_trans_info *oti)
801 struct ptlrpc_request_set *set = NULL;
805 EXP_CHECK_DT_OP(exp, setattr_async);
806 EXP_COUNTER_INCREMENT(exp, setattr_async);
808 set = ptlrpc_prep_set();
812 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
814 rc = ptlrpc_set_wait(set);
815 ptlrpc_set_destroy(set);
819 /* This adds all the requests into @set if @set != NULL, otherwise
820 all requests are sent asynchronously without waiting for response. */
821 static inline int obd_setattr_async(struct obd_export *exp,
822 struct obd_info *oinfo,
823 struct obd_trans_info *oti,
824 struct ptlrpc_request_set *set)
829 EXP_CHECK_DT_OP(exp, setattr_async);
830 EXP_COUNTER_INCREMENT(exp, setattr_async);
832 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
836 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
839 struct obd_device *obd = imp->imp_obd;
843 OBD_CHECK_DEV_ACTIVE(obd);
844 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
845 OBD_COUNTER_INCREMENT(obd, add_conn);
847 rc = OBP(obd, add_conn)(imp, uuid, priority);
851 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
853 struct obd_device *obd = imp->imp_obd;
857 OBD_CHECK_DEV_ACTIVE(obd);
858 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
859 OBD_COUNTER_INCREMENT(obd, del_conn);
861 rc = OBP(obd, del_conn)(imp, uuid);
865 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
867 struct obd_uuid *uuid;
870 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
871 EXP_COUNTER_INCREMENT(exp, get_uuid);
873 uuid = OBP(exp->exp_obd, get_uuid)(exp);
877 static inline int obd_connect(const struct lu_env *env,
878 struct obd_export **exp,struct obd_device *obd,
879 struct obd_uuid *cluuid,
880 struct obd_connect_data *d,
884 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
888 OBD_CHECK_DEV_ACTIVE(obd);
889 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
890 OBD_COUNTER_INCREMENT(obd, connect);
892 rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
893 /* check that only subset is granted */
894 LASSERT(ergo(d != NULL,
895 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
899 static inline int obd_reconnect(const struct lu_env *env,
900 struct obd_export *exp,
901 struct obd_device *obd,
902 struct obd_uuid *cluuid,
903 struct obd_connect_data *d,
907 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
912 OBD_CHECK_DEV_ACTIVE(obd);
913 OBD_CHECK_DT_OP(obd, reconnect, 0);
914 OBD_COUNTER_INCREMENT(obd, reconnect);
916 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
917 /* check that only subset is granted */
918 LASSERT(ergo(d != NULL,
919 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
923 static inline int obd_disconnect(struct obd_export *exp)
928 EXP_CHECK_DT_OP(exp, disconnect);
929 EXP_COUNTER_INCREMENT(exp, disconnect);
931 rc = OBP(exp->exp_obd, disconnect)(exp);
935 static inline int obd_fid_init(struct obd_export *exp)
940 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
941 EXP_COUNTER_INCREMENT(exp, fid_init);
943 rc = OBP(exp->exp_obd, fid_init)(exp);
947 static inline int obd_fid_fini(struct obd_export *exp)
952 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
953 EXP_COUNTER_INCREMENT(exp, fid_fini);
955 rc = OBP(exp->exp_obd, fid_fini)(exp);
959 static inline int obd_fid_alloc(struct obd_export *exp,
961 struct md_op_data *op_data)
966 EXP_CHECK_DT_OP(exp, fid_alloc);
967 EXP_COUNTER_INCREMENT(exp, fid_alloc);
969 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
973 static inline int obd_fid_delete(struct obd_export *exp,
974 const struct lu_fid *fid)
979 EXP_CHECK_DT_OP(exp, fid_delete);
980 EXP_COUNTER_INCREMENT(exp, fid_delete);
982 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
986 static inline int obd_ping(struct obd_export *exp)
991 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
992 EXP_COUNTER_INCREMENT(exp, ping);
994 rc = OBP(exp->exp_obd, ping)(exp);
998 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1003 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1004 OBD_COUNTER_INCREMENT(obd, pool_new);
1006 rc = OBP(obd, pool_new)(obd, poolname);
1010 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1015 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1016 OBD_COUNTER_INCREMENT(obd, pool_del);
1018 rc = OBP(obd, pool_del)(obd, poolname);
1022 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1027 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1028 OBD_COUNTER_INCREMENT(obd, pool_add);
1030 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1034 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1039 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1040 OBD_COUNTER_INCREMENT(obd, pool_rem);
1042 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1046 static inline void obd_getref(struct obd_device *obd)
1049 if (OBT(obd) && OBP(obd, getref)) {
1050 OBD_COUNTER_INCREMENT(obd, getref);
1051 OBP(obd, getref)(obd);
1056 static inline void obd_putref(struct obd_device *obd)
1059 if (OBT(obd) && OBP(obd, putref)) {
1060 OBD_COUNTER_INCREMENT(obd, putref);
1061 OBP(obd, putref)(obd);
1066 static inline int obd_init_export(struct obd_export *exp)
1071 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1072 OBP((exp)->exp_obd, init_export))
1073 rc = OBP(exp->exp_obd, init_export)(exp);
1077 static inline int obd_destroy_export(struct obd_export *exp)
1080 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1081 OBP((exp)->exp_obd, destroy_export))
1082 OBP(exp->exp_obd, destroy_export)(exp);
1086 static inline int obd_extent_calc(struct obd_export *exp,
1087 struct lov_stripe_md *md,
1088 int cmd, obd_off *offset)
1092 EXP_CHECK_DT_OP(exp, extent_calc);
1093 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1097 static inline struct dentry *
1098 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1100 LASSERT(exp->exp_obd);
1102 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1107 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1109 LASSERT(exp->exp_obd);
1110 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1112 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1113 dentry, exp->exp_obd);
1119 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
1122 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1123 * If the cache is older than @max_age we will get a new value from the
1124 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1125 static inline int obd_statfs_async(struct obd_device *obd,
1126 struct obd_info *oinfo,
1128 struct ptlrpc_request_set *rqset)
1136 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1137 OBD_COUNTER_INCREMENT(obd, statfs);
1139 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1140 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1141 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1142 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1144 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1145 " objects "LPU64"/"LPU64"\n",
1146 obd->obd_name, &obd->obd_osfs,
1147 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1148 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1149 spin_lock(&obd->obd_osfs_lock);
1150 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1151 spin_unlock(&obd->obd_osfs_lock);
1152 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1153 if (oinfo->oi_cb_up)
1154 oinfo->oi_cb_up(oinfo, 0);
1159 static inline int obd_statfs_rqset(struct obd_device *obd,
1160 struct obd_statfs *osfs, __u64 max_age,
1163 struct ptlrpc_request_set *set = NULL;
1164 struct obd_info oinfo = { { { 0 } } };
1168 set = ptlrpc_prep_set();
1172 oinfo.oi_osfs = osfs;
1173 oinfo.oi_flags = flags;
1174 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1176 rc = ptlrpc_set_wait(set);
1177 ptlrpc_set_destroy(set);
1181 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1182 * If the cache is older than @max_age we will get a new value from the
1183 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1184 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1185 __u64 max_age, __u32 flags)
1193 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1194 OBD_COUNTER_INCREMENT(obd, statfs);
1196 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1197 obd->obd_osfs_age, max_age);
1198 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1199 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1201 spin_lock(&obd->obd_osfs_lock);
1202 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1203 obd->obd_osfs_age = cfs_time_current_64();
1204 spin_unlock(&obd->obd_osfs_lock);
1207 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1208 " objects "LPU64"/"LPU64"\n",
1209 obd->obd_name, &obd->obd_osfs,
1210 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1211 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1212 spin_lock(&obd->obd_osfs_lock);
1213 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1214 spin_unlock(&obd->obd_osfs_lock);
1219 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1220 struct lov_stripe_md *ea, obd_size start,
1221 obd_size end, void *capa)
1226 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1227 EXP_COUNTER_INCREMENT(exp, sync);
1229 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1233 static inline int obd_punch_rqset(struct obd_export *exp,
1234 struct obd_info *oinfo,
1235 struct obd_trans_info *oti)
1237 struct ptlrpc_request_set *set = NULL;
1241 EXP_CHECK_DT_OP(exp, punch);
1242 EXP_COUNTER_INCREMENT(exp, punch);
1244 set = ptlrpc_prep_set();
1248 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1250 rc = ptlrpc_set_wait(set);
1251 ptlrpc_set_destroy(set);
1255 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1256 struct obd_trans_info *oti,
1257 struct ptlrpc_request_set *rqset)
1262 EXP_CHECK_DT_OP(exp, punch);
1263 EXP_COUNTER_INCREMENT(exp, punch);
1265 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1269 static inline int obd_brw(int cmd, struct obd_export *exp,
1270 struct obd_info *oinfo, obd_count oa_bufs,
1271 struct brw_page *pg, struct obd_trans_info *oti)
1276 EXP_CHECK_DT_OP(exp, brw);
1277 EXP_COUNTER_INCREMENT(exp, brw);
1279 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1280 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1281 "or OBD_BRW_CHECK\n");
1285 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1289 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1290 int objcount, struct obd_ioobj *obj,
1291 struct niobuf_remote *remote, int *pages,
1292 struct niobuf_local *local,
1293 struct obd_trans_info *oti,
1294 struct lustre_capa *capa)
1299 EXP_CHECK_DT_OP(exp, preprw);
1300 EXP_COUNTER_INCREMENT(exp, preprw);
1302 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1303 pages, local, oti, capa);
1307 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1308 int objcount, struct obd_ioobj *obj,
1309 struct niobuf_remote *rnb, int pages,
1310 struct niobuf_local *local,
1311 struct obd_trans_info *oti, int rc)
1315 EXP_CHECK_DT_OP(exp, commitrw);
1316 EXP_COUNTER_INCREMENT(exp, commitrw);
1318 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1319 rnb, pages, local, oti, rc);
1323 static inline int obd_merge_lvb(struct obd_export *exp,
1324 struct lov_stripe_md *lsm,
1325 struct ost_lvb *lvb, int kms_only)
1330 EXP_CHECK_DT_OP(exp, merge_lvb);
1331 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1333 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1337 static inline int obd_adjust_kms(struct obd_export *exp,
1338 struct lov_stripe_md *lsm, obd_off size,
1344 EXP_CHECK_DT_OP(exp, adjust_kms);
1345 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1347 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1351 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1352 int len, void *karg, void *uarg)
1357 EXP_CHECK_DT_OP(exp, iocontrol);
1358 EXP_COUNTER_INCREMENT(exp, iocontrol);
1360 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1364 static inline int obd_enqueue_rqset(struct obd_export *exp,
1365 struct obd_info *oinfo,
1366 struct ldlm_enqueue_info *einfo)
1368 struct ptlrpc_request_set *set = NULL;
1372 EXP_CHECK_DT_OP(exp, enqueue);
1373 EXP_COUNTER_INCREMENT(exp, enqueue);
1375 set = ptlrpc_prep_set();
1379 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1381 rc = ptlrpc_set_wait(set);
1382 ptlrpc_set_destroy(set);
1386 static inline int obd_enqueue(struct obd_export *exp,
1387 struct obd_info *oinfo,
1388 struct ldlm_enqueue_info *einfo,
1389 struct ptlrpc_request_set *set)
1394 EXP_CHECK_DT_OP(exp, enqueue);
1395 EXP_COUNTER_INCREMENT(exp, enqueue);
1397 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1401 static inline int obd_change_cbdata(struct obd_export *exp,
1402 struct lov_stripe_md *lsm,
1403 ldlm_iterator_t it, void *data)
1408 EXP_CHECK_DT_OP(exp, change_cbdata);
1409 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1411 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1415 static inline int obd_cancel(struct obd_export *exp,
1416 struct lov_stripe_md *ea, __u32 mode,
1417 struct lustre_handle *lockh)
1422 EXP_CHECK_DT_OP(exp, cancel);
1423 EXP_COUNTER_INCREMENT(exp, cancel);
1425 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1429 static inline int obd_cancel_unused(struct obd_export *exp,
1430 struct lov_stripe_md *ea,
1431 int flags, void *opaque)
1436 EXP_CHECK_DT_OP(exp, cancel_unused);
1437 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1439 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1443 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1444 struct obd_capa *oc, struct obd_client_handle *handle,
1450 EXP_CHECK_DT_OP(exp, pin);
1451 EXP_COUNTER_INCREMENT(exp, pin);
1453 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1457 static inline int obd_unpin(struct obd_export *exp,
1458 struct obd_client_handle *handle, int flag)
1463 EXP_CHECK_DT_OP(exp, unpin);
1464 EXP_COUNTER_INCREMENT(exp, unpin);
1466 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1471 static inline void obd_import_event(struct obd_device *obd,
1472 struct obd_import *imp,
1473 enum obd_import_event event)
1477 CERROR("NULL device\n");
1481 if (obd->obd_set_up && OBP(obd, import_event)) {
1482 OBD_COUNTER_INCREMENT(obd, import_event);
1483 OBP(obd, import_event)(obd, imp, event);
1488 static inline int obd_llog_connect(struct obd_export *exp,
1489 struct llogd_conn_body *body)
1494 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1495 EXP_COUNTER_INCREMENT(exp, llog_connect);
1497 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1502 static inline int obd_notify(struct obd_device *obd,
1503 struct obd_device *watched,
1504 enum obd_notify_event ev,
1511 /* the check for async_recov is a complete hack - I'm hereby
1512 overloading the meaning to also mean "this was called from
1513 mds_postsetup". I know that my mds is able to handle notifies
1514 by this point, and it needs to get them to execute mds_postrecov. */
1515 if (!obd->obd_set_up && !obd->obd_async_recov) {
1516 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1520 if (!OBP(obd, notify)) {
1521 CERROR("obd %s has no notify handler\n", obd->obd_name);
1525 OBD_COUNTER_INCREMENT(obd, notify);
1526 rc = OBP(obd, notify)(obd, watched, ev, data);
1530 static inline int obd_notify_observer(struct obd_device *observer,
1531 struct obd_device *observed,
1532 enum obd_notify_event ev,
1538 struct obd_notify_upcall *onu;
1540 if (observer->obd_observer)
1541 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1545 * Also, call non-obd listener, if any
1547 onu = &observer->obd_upcall;
1548 if (onu->onu_upcall != NULL)
1549 rc2 = onu->onu_upcall(observer, observed, ev,
1550 onu->onu_owner, NULL);
1554 return rc1 ? rc1 : rc2;
1557 static inline int obd_quotacheck(struct obd_export *exp,
1558 struct obd_quotactl *oqctl)
1563 EXP_CHECK_DT_OP(exp, quotacheck);
1564 EXP_COUNTER_INCREMENT(exp, quotacheck);
1566 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1570 static inline int obd_quotactl(struct obd_export *exp,
1571 struct obd_quotactl *oqctl)
1576 EXP_CHECK_DT_OP(exp, quotactl);
1577 EXP_COUNTER_INCREMENT(exp, quotactl);
1579 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1583 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1584 struct quota_adjust_qunit *oqaq,
1585 struct lustre_quota_ctxt *qctxt)
1587 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1588 struct timeval work_start;
1589 struct timeval work_end;
1595 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1597 do_gettimeofday(&work_start);
1599 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1600 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1602 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1604 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1606 do_gettimeofday(&work_end);
1607 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1608 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1615 static inline int obd_health_check(struct obd_device *obd)
1617 /* returns: 0 on healthy
1618 * >0 on unhealthy + reason code/flag
1619 * however the only suppored reason == 1 right now
1620 * We'll need to define some better reasons
1621 * or flags in the future.
1627 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1628 if (obd == NULL || !OBT(obd)) {
1629 CERROR("cleaned up obd\n");
1630 RETURN(-EOPNOTSUPP);
1632 if (!obd->obd_set_up || obd->obd_stopping)
1634 if (!OBP(obd, health_check))
1637 rc = OBP(obd, health_check)(obd);
1641 static inline int obd_register_observer(struct obd_device *obd,
1642 struct obd_device *observer)
1646 down_write(&obd->obd_observer_link_sem);
1647 if (obd->obd_observer && observer) {
1648 up_write(&obd->obd_observer_link_sem);
1651 obd->obd_observer = observer;
1652 up_write(&obd->obd_observer_link_sem);
1656 static inline int obd_pin_observer(struct obd_device *obd,
1657 struct obd_device **observer)
1660 down_read(&obd->obd_observer_link_sem);
1661 if (!obd->obd_observer) {
1663 up_read(&obd->obd_observer_link_sem);
1666 *observer = obd->obd_observer;
1670 static inline int obd_unpin_observer(struct obd_device *obd)
1673 up_read(&obd->obd_observer_link_sem);
1678 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1679 obd_page_removal_cb_t cb,
1680 obd_pin_extent_cb pin_cb)
1685 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1686 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1688 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1692 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1693 obd_page_removal_cb_t cb)
1698 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1699 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1701 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1705 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1706 obd_lock_cancel_cb cb)
1711 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1712 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1714 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1718 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1719 obd_lock_cancel_cb cb)
1724 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1725 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1727 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1732 /* metadata helpers */
1733 static inline int md_getstatus(struct obd_export *exp,
1734 struct lu_fid *fid, struct obd_capa **pc)
1739 EXP_CHECK_MD_OP(exp, getstatus);
1740 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1741 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1745 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1746 struct obd_capa *oc, obd_valid valid, int ea_size,
1747 struct ptlrpc_request **request)
1751 EXP_CHECK_MD_OP(exp, getattr);
1752 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1753 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1758 static inline int md_change_cbdata(struct obd_export *exp,
1759 const struct lu_fid *fid,
1760 ldlm_iterator_t it, void *data)
1764 EXP_CHECK_MD_OP(exp, change_cbdata);
1765 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1766 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1770 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1771 struct md_open_data *mod,
1772 struct ptlrpc_request **request)
1776 EXP_CHECK_MD_OP(exp, close);
1777 EXP_MD_COUNTER_INCREMENT(exp, close);
1778 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1782 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1783 const void *data, int datalen, int mode, __u32 uid,
1784 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1785 struct ptlrpc_request **request)
1789 EXP_CHECK_MD_OP(exp, create);
1790 EXP_MD_COUNTER_INCREMENT(exp, create);
1791 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1792 uid, gid, cap_effective, rdev, request);
1796 static inline int md_done_writing(struct obd_export *exp,
1797 struct md_op_data *op_data,
1798 struct md_open_data *mod)
1802 EXP_CHECK_MD_OP(exp, done_writing);
1803 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1804 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1808 static inline int md_enqueue(struct obd_export *exp,
1809 struct ldlm_enqueue_info *einfo,
1810 struct lookup_intent *it,
1811 struct md_op_data *op_data,
1812 struct lustre_handle *lockh,
1813 void *lmm, int lmmsize,
1814 struct ptlrpc_request **req,
1815 int extra_lock_flags)
1819 EXP_CHECK_MD_OP(exp, enqueue);
1820 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1821 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1822 lmm, lmmsize, req, extra_lock_flags);
1826 static inline int md_getattr_name(struct obd_export *exp,
1827 const struct lu_fid *fid, struct obd_capa *oc,
1828 const char *name, int namelen,
1829 obd_valid valid, int ea_size, __u32 suppgid,
1830 struct ptlrpc_request **request)
1834 EXP_CHECK_MD_OP(exp, getattr_name);
1835 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1836 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1837 valid, ea_size, suppgid, request);
1841 static inline int md_intent_lock(struct obd_export *exp,
1842 struct md_op_data *op_data, void *lmm,
1843 int lmmsize, struct lookup_intent *it,
1844 int flags, struct ptlrpc_request **reqp,
1845 ldlm_blocking_callback cb_blocking,
1846 int extra_lock_flags)
1850 EXP_CHECK_MD_OP(exp, intent_lock);
1851 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1852 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1853 it, flags, reqp, cb_blocking,
1858 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1859 struct ptlrpc_request **request)
1863 EXP_CHECK_MD_OP(exp, link);
1864 EXP_MD_COUNTER_INCREMENT(exp, link);
1865 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1869 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1870 const char *old, int oldlen, const char *new,
1871 int newlen, struct ptlrpc_request **request)
1875 EXP_CHECK_MD_OP(exp, rename);
1876 EXP_MD_COUNTER_INCREMENT(exp, rename);
1877 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1882 static inline int md_is_subdir(struct obd_export *exp,
1883 const struct lu_fid *pfid,
1884 const struct lu_fid *cfid,
1885 struct ptlrpc_request **request)
1889 EXP_CHECK_MD_OP(exp, is_subdir);
1890 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1891 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1895 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1896 void *ea, int ealen, void *ea2, int ea2len,
1897 struct ptlrpc_request **request,
1898 struct md_open_data **mod)
1902 EXP_CHECK_MD_OP(exp, setattr);
1903 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1904 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1905 ea2, ea2len, request, mod);
1909 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1910 struct obd_capa *oc, struct ptlrpc_request **request)
1914 EXP_CHECK_MD_OP(exp, sync);
1915 EXP_MD_COUNTER_INCREMENT(exp, sync);
1916 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1920 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1921 struct obd_capa *oc, __u64 offset,
1923 struct ptlrpc_request **request)
1927 EXP_CHECK_MD_OP(exp, readpage);
1928 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1929 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1933 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1934 struct ptlrpc_request **request)
1938 EXP_CHECK_MD_OP(exp, unlink);
1939 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1940 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1944 static inline int md_get_lustre_md(struct obd_export *exp,
1945 struct ptlrpc_request *req,
1946 struct obd_export *dt_exp,
1947 struct obd_export *md_exp,
1948 struct lustre_md *md)
1951 EXP_CHECK_MD_OP(exp, get_lustre_md);
1952 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1953 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1956 static inline int md_free_lustre_md(struct obd_export *exp,
1957 struct lustre_md *md)
1960 EXP_CHECK_MD_OP(exp, free_lustre_md);
1961 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1962 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1965 static inline int md_setxattr(struct obd_export *exp,
1966 const struct lu_fid *fid, struct obd_capa *oc,
1967 obd_valid valid, const char *name,
1968 const char *input, int input_size,
1969 int output_size, int flags, __u32 suppgid,
1970 struct ptlrpc_request **request)
1973 EXP_CHECK_MD_OP(exp, setxattr);
1974 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1975 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1976 input_size, output_size, flags,
1980 static inline int md_getxattr(struct obd_export *exp,
1981 const struct lu_fid *fid, struct obd_capa *oc,
1982 obd_valid valid, const char *name,
1983 const char *input, int input_size,
1984 int output_size, int flags,
1985 struct ptlrpc_request **request)
1988 EXP_CHECK_MD_OP(exp, getxattr);
1989 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1990 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1991 input_size, output_size, flags,
1995 static inline int md_set_open_replay_data(struct obd_export *exp,
1996 struct obd_client_handle *och,
1997 struct ptlrpc_request *open_req)
2000 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2001 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2002 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2005 static inline int md_clear_open_replay_data(struct obd_export *exp,
2006 struct obd_client_handle *och)
2009 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2010 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2011 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2014 static inline int md_set_lock_data(struct obd_export *exp,
2015 __u64 *lockh, void *data, __u32 *bits)
2018 EXP_CHECK_MD_OP(exp, set_lock_data);
2019 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2020 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2023 static inline int md_cancel_unused(struct obd_export *exp,
2024 const struct lu_fid *fid,
2025 ldlm_policy_data_t *policy,
2026 ldlm_mode_t mode, int flags, void *opaque)
2031 EXP_CHECK_MD_OP(exp, cancel_unused);
2032 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2034 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2039 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2040 const struct lu_fid *fid,
2042 ldlm_policy_data_t *policy,
2044 struct lustre_handle *lockh)
2047 EXP_CHECK_MD_OP(exp, lock_match);
2048 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2049 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2050 policy, mode, lockh));
2053 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2054 int def_asize, int cookiesize)
2057 EXP_CHECK_MD_OP(exp, init_ea_size);
2058 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2059 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2063 static inline int md_get_remote_perm(struct obd_export *exp,
2064 const struct lu_fid *fid,
2065 struct obd_capa *oc, __u32 suppgid,
2066 struct ptlrpc_request **request)
2069 EXP_CHECK_MD_OP(exp, get_remote_perm);
2070 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2071 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2075 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2080 EXP_CHECK_MD_OP(exp, renew_capa);
2081 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2082 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2086 static inline int md_unpack_capa(struct obd_export *exp,
2087 struct ptlrpc_request *req,
2088 const struct req_msg_field *field,
2089 struct obd_capa **oc)
2093 EXP_CHECK_MD_OP(exp, unpack_capa);
2094 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2095 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2099 static inline int md_intent_getattr_async(struct obd_export *exp,
2100 struct md_enqueue_info *minfo,
2101 struct ldlm_enqueue_info *einfo)
2105 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2106 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2107 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2111 static inline int md_revalidate_lock(struct obd_export *exp,
2112 struct lookup_intent *it,
2117 EXP_CHECK_MD_OP(exp, revalidate_lock);
2118 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2119 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2124 /* OBD Metadata Support */
2126 extern int obd_init_caches(void);
2127 extern void obd_cleanup_caches(void);
2129 /* support routines */
2130 extern cfs_mem_cache_t *obdo_cachep;
2132 #define OBDO_ALLOC(ptr) \
2134 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
2137 #define OBDO_FREE(ptr) \
2139 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2143 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2145 /* something here */
2148 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2150 /* something here */
2153 /* I'm as embarrassed about this as you are.
2155 * <shaver> // XXX do not look into _superhack with remaining eye
2156 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2157 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2160 extern void obd_sysctl_init (void);
2161 extern void obd_sysctl_clean (void);
2164 typedef __u8 class_uuid_t[16];
2165 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2168 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2169 int class_add_uuid(const char *uuid, __u64 nid);
2170 int class_del_uuid (const char *uuid);
2171 void class_init_uuidlist(void);
2172 void class_exit_uuidlist(void);
2175 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2176 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2179 void ll_generate_random_uuid(class_uuid_t uuid_out);
2181 #endif /* __LINUX_OBD_CLASS_H */