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 cfs_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 *);
68 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
70 struct lu_device_type;
73 struct obd_export *class_conn2export(struct lustre_handle *);
74 int class_register_type(struct obd_ops *, struct md_ops *,
75 struct lprocfs_vars *, const char *nm,
76 struct lu_device_type *ldt);
77 int class_unregister_type(const char *nm);
79 struct obd_device *class_newdev(const char *type_name, const char *name);
80 void class_release_dev(struct obd_device *obd);
82 int class_name2dev(const char *name);
83 struct obd_device *class_name2obd(const char *name);
84 int class_uuid2dev(struct obd_uuid *uuid);
85 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
86 void class_obd_list(void);
87 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
88 const char * typ_name,
89 struct obd_uuid *grp_uuid);
90 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
92 struct obd_device * class_num2obd(int num);
94 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
96 char *obd_export_nid2str(struct obd_export *exp);
98 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
99 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
101 int obd_zombie_impexp_init(void);
102 void obd_zombie_impexp_stop(void);
103 void obd_zombie_impexp_cull(void);
104 void obd_zombie_barrier(void);
105 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 cfs_list_t cld_list_chain;
156 cfs_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
161 cld_lostlock:1, /* lock not requeued */
165 struct lustre_profile {
172 struct lustre_profile *class_get_profile(const char * prof);
173 void class_del_profile(const char *prof);
174 void class_del_profiles(void);
176 #if LUSTRE_TRACKS_LOCK_EXP_REFS
178 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
179 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
180 extern void (*class_export_dump_hook)(struct obd_export *);
184 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
185 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
189 #define class_export_rpc_get(exp) \
191 cfs_atomic_inc(&(exp)->exp_rpc_count); \
192 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
193 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
194 class_export_get(exp); \
197 #define class_export_rpc_put(exp) \
199 LASSERT(cfs_atomic_read(&exp->exp_rpc_count) > 0); \
200 cfs_atomic_dec(&(exp)->exp_rpc_count); \
201 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
202 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
203 class_export_put(exp); \
206 #define class_export_lock_get(exp, lock) \
208 cfs_atomic_inc(&(exp)->exp_locks_count); \
209 __class_export_add_lock_ref(exp, lock); \
210 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
211 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
212 class_export_get(exp); \
215 #define class_export_lock_put(exp, lock) \
217 LASSERT(cfs_atomic_read(&exp->exp_locks_count) > 0); \
218 cfs_atomic_dec(&(exp)->exp_locks_count); \
219 __class_export_del_lock_ref(exp, lock); \
220 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
221 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
222 class_export_put(exp); \
225 #define class_export_cb_get(exp) \
227 cfs_atomic_inc(&(exp)->exp_cb_count); \
228 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
229 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
230 class_export_get(exp); \
233 #define class_export_cb_put(exp) \
235 LASSERT(cfs_atomic_read(&exp->exp_cb_count) > 0); \
236 cfs_atomic_dec(&(exp)->exp_cb_count); \
237 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
238 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
239 class_export_put(exp); \
243 struct obd_export *class_export_get(struct obd_export *exp);
244 void class_export_put(struct obd_export *exp);
245 struct obd_export *class_new_export(struct obd_device *obddev,
246 struct obd_uuid *cluuid);
247 void class_unlink_export(struct obd_export *exp);
249 struct obd_import *class_import_get(struct obd_import *);
250 void class_import_put(struct obd_import *);
251 struct obd_import *class_new_import(struct obd_device *obd);
252 void class_destroy_import(struct obd_import *exp);
254 struct obd_type *class_search_type(const char *name);
255 struct obd_type *class_get_type(const char *name);
256 void class_put_type(struct obd_type *type);
257 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
258 struct obd_uuid *cluuid);
259 int class_disconnect(struct obd_export *exp);
260 void class_fail_export(struct obd_export *exp);
261 int class_connected_export(struct obd_export *exp);
262 void class_disconnect_exports(struct obd_device *obddev);
263 int class_manual_cleanup(struct obd_device *obd);
264 void class_disconnect_stale_exports(struct obd_device *,
265 int (*test_export)(struct obd_export *));
266 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
268 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
269 (obd->obd_force ? OBD_OPT_FORCE : 0) |
270 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
274 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
276 LASSERT(exp->exp_obd);
277 return exp->exp_obd->u.obt.obt_lut;
280 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
282 LASSERT(obd->u.obt.obt_lut);
283 return &obd->u.obt.obt_lut->lut_lsd;
286 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
287 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
288 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
289 unsigned int ia_valid);
290 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
291 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
292 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
295 #define OBT(dev) (dev)->obd_type
296 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
297 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
298 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
300 /* Ensure obd_setup: used for cleanup which must be called
301 while obd is stopping */
302 #define OBD_CHECK_DEV(obd) \
305 CERROR("NULL device\n"); \
310 /* ensure obd_setup and !obd_stopping */
311 #define OBD_CHECK_DEV_ACTIVE(obd) \
313 OBD_CHECK_DEV(obd); \
314 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
315 CERROR("Device %d not setup\n", \
323 #define OBD_COUNTER_OFFSET(op) \
324 ((offsetof(struct obd_ops, o_ ## op) - \
325 offsetof(struct obd_ops, o_iocontrol)) \
326 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
328 #define OBD_COUNTER_INCREMENT(obdx, op) \
329 if ((obdx)->obd_stats != NULL) { \
330 unsigned int coffset; \
331 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
332 OBD_COUNTER_OFFSET(op); \
333 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
334 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
337 #define EXP_COUNTER_INCREMENT(export, op) \
338 if ((export)->exp_obd->obd_stats != NULL) { \
339 unsigned int coffset; \
340 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
341 OBD_COUNTER_OFFSET(op); \
342 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
343 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
344 if ((export)->exp_nid_stats != NULL && \
345 (export)->exp_nid_stats->nid_stats != NULL) \
346 lprocfs_counter_incr( \
347 (export)->exp_nid_stats->nid_stats, coffset);\
350 #define MD_COUNTER_OFFSET(op) \
351 ((offsetof(struct md_ops, m_ ## op) - \
352 offsetof(struct md_ops, m_getstatus)) \
353 / sizeof(((struct md_ops *)(0))->m_getstatus))
355 #define MD_COUNTER_INCREMENT(obdx, op) \
356 if ((obd)->md_stats != NULL) { \
357 unsigned int coffset; \
358 coffset = (unsigned int)((obdx)->md_cntr_base) + \
359 MD_COUNTER_OFFSET(op); \
360 LASSERT(coffset < (obdx)->md_stats->ls_num); \
361 lprocfs_counter_incr((obdx)->md_stats, coffset); \
364 #define EXP_MD_COUNTER_INCREMENT(export, op) \
365 if ((export)->exp_obd->obd_stats != NULL) { \
366 unsigned int coffset; \
367 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
368 MD_COUNTER_OFFSET(op); \
369 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
370 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
371 if ((export)->exp_md_stats != NULL) \
372 lprocfs_counter_incr( \
373 (export)->exp_md_stats, coffset); \
377 #define OBD_COUNTER_OFFSET(op)
378 #define OBD_COUNTER_INCREMENT(obd, op)
379 #define EXP_COUNTER_INCREMENT(exp, op)
380 #define MD_COUNTER_INCREMENT(obd, op)
381 #define EXP_MD_COUNTER_INCREMENT(exp, op)
384 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp) {
385 /* Always add in ldlm_stats */
386 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
387 ,LPROCFS_STATS_FLAG_NOPERCPU);
388 if (tmp->nid_ldlm_stats == NULL)
391 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
393 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
394 tmp->nid_ldlm_stats);
397 #define OBD_CHECK_MD_OP(obd, op, err) \
399 if (!OBT(obd) || !MDP((obd), op)) { \
401 CERROR("md_" #op ": dev %s/%d no operation\n", \
402 obd->obd_name, obd->obd_minor); \
407 #define EXP_CHECK_MD_OP(exp, op) \
409 if ((exp) == NULL) { \
410 CERROR("obd_" #op ": NULL export\n"); \
413 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
414 CERROR("obd_" #op ": cleaned up obd\n"); \
415 RETURN(-EOPNOTSUPP); \
417 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
418 CERROR("obd_" #op ": dev %s/%d no operation\n", \
419 (exp)->exp_obd->obd_name, \
420 (exp)->exp_obd->obd_minor); \
421 RETURN(-EOPNOTSUPP); \
426 #define OBD_CHECK_DT_OP(obd, op, err) \
428 if (!OBT(obd) || !OBP((obd), op)) { \
430 CERROR("obd_" #op ": dev %d no operation\n", \
436 #define EXP_CHECK_DT_OP(exp, op) \
438 if ((exp) == NULL) { \
439 CERROR("obd_" #op ": NULL export\n"); \
442 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
443 CERROR("obd_" #op ": cleaned up obd\n"); \
444 RETURN(-EOPNOTSUPP); \
446 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
447 CERROR("obd_" #op ": dev %d no operation\n", \
448 (exp)->exp_obd->obd_minor); \
449 RETURN(-EOPNOTSUPP); \
453 #define CTXT_CHECK_OP(ctxt, op, err) \
455 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
457 CERROR("lop_" #op ": dev %d no operation\n", \
458 ctxt->loc_obd->obd_minor); \
463 static inline int class_devno_max(void)
465 return MAX_OBD_DEVICES;
468 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
469 void *key, __u32 *vallen, void *val,
470 struct lov_stripe_md *lsm)
475 EXP_CHECK_DT_OP(exp, get_info);
476 EXP_COUNTER_INCREMENT(exp, get_info);
478 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
482 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
483 void *key, obd_count vallen, void *val,
484 struct ptlrpc_request_set *set)
489 EXP_CHECK_DT_OP(exp, set_info_async);
490 EXP_COUNTER_INCREMENT(exp, set_info_async);
492 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
498 * obd-lu integration.
500 * Functionality is being moved into new lu_device-based layering, but some
501 * pieces of configuration process are still based on obd devices.
503 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
504 * subsume ->o_setup() methods of obd devices they replace. The same for
505 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
506 * result, obd_setup() and obd_process_config() branch and call one XOR
509 * Yet neither lu_device_type_operations::ldto_device_fini() nor
510 * lu_device_type_operations::ldto_device_free() fully implement the
511 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
512 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
515 #define DECLARE_LU_VARS(ldt, d) \
516 struct lu_device_type *ldt; \
519 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
522 DECLARE_LU_VARS(ldt, d);
525 ldt = obd->obd_type->typ_lu;
527 struct lu_context session_ctx;
529 lu_context_init(&session_ctx, LCT_SESSION);
530 session_ctx.lc_thread = NULL;
531 lu_context_enter(&session_ctx);
533 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
535 env.le_ses = &session_ctx;
536 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
545 lu_context_exit(&session_ctx);
546 lu_context_fini(&session_ctx);
549 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
550 OBD_COUNTER_INCREMENT(obd, setup);
551 rc = OBP(obd, setup)(obd, cfg);
556 static inline int obd_precleanup(struct obd_device *obd,
557 enum obd_cleanup_stage cleanup_stage)
560 DECLARE_LU_VARS(ldt, d);
564 ldt = obd->obd_type->typ_lu;
566 if (ldt != NULL && d != NULL) {
567 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
570 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
572 ldt->ldt_ops->ldto_device_fini(&env, d);
577 OBD_CHECK_DT_OP(obd, precleanup, 0);
578 OBD_COUNTER_INCREMENT(obd, precleanup);
580 rc = OBP(obd, precleanup)(obd, cleanup_stage);
584 static inline int obd_cleanup(struct obd_device *obd)
587 DECLARE_LU_VARS(ldt, d);
592 ldt = obd->obd_type->typ_lu;
594 if (ldt != NULL && d != NULL) {
597 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
599 ldt->ldt_ops->ldto_device_free(&env, d);
601 obd->obd_lu_dev = NULL;
604 OBD_CHECK_DT_OP(obd, cleanup, 0);
605 OBD_COUNTER_INCREMENT(obd, cleanup);
607 rc = OBP(obd, cleanup)(obd);
612 obd_process_config(struct obd_device *obd, int datalen, void *data)
615 DECLARE_LU_VARS(ldt, d);
620 obd->obd_process_conf = 1;
621 ldt = obd->obd_type->typ_lu;
623 if (ldt != NULL && d != NULL) {
626 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
628 rc = d->ld_ops->ldo_process_config(&env, d, data);
632 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
633 rc = OBP(obd, process_config)(obd, datalen, data);
635 OBD_COUNTER_INCREMENT(obd, process_config);
636 obd->obd_process_conf = 0;
641 /* Pack an in-memory MD struct for storage on disk.
642 * Returns +ve size of packed MD (0 for free), or -ve error.
644 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
645 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
646 * If @*disk_tgt == NULL, it will be allocated
648 static inline int obd_packmd(struct obd_export *exp,
649 struct lov_mds_md **disk_tgt,
650 struct lov_stripe_md *mem_src)
655 EXP_CHECK_DT_OP(exp, packmd);
656 EXP_COUNTER_INCREMENT(exp, packmd);
658 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
662 static inline int obd_size_diskmd(struct obd_export *exp,
663 struct lov_stripe_md *mem_src)
665 return obd_packmd(exp, NULL, mem_src);
668 /* helper functions */
669 static inline int obd_alloc_diskmd(struct obd_export *exp,
670 struct lov_mds_md **disk_tgt)
673 LASSERT(*disk_tgt == NULL);
674 return obd_packmd(exp, disk_tgt, NULL);
677 static inline int obd_free_diskmd(struct obd_export *exp,
678 struct lov_mds_md **disk_tgt)
682 return obd_packmd(exp, disk_tgt, NULL);
685 /* Unpack an MD struct from disk to in-memory format.
686 * Returns +ve size of unpacked MD (0 for free), or -ve error.
688 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
689 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
690 * If @*mem_tgt == NULL, it will be allocated
692 static inline int obd_unpackmd(struct obd_export *exp,
693 struct lov_stripe_md **mem_tgt,
694 struct lov_mds_md *disk_src,
700 EXP_CHECK_DT_OP(exp, unpackmd);
701 EXP_COUNTER_INCREMENT(exp, unpackmd);
703 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
707 /* helper functions */
708 static inline int obd_alloc_memmd(struct obd_export *exp,
709 struct lov_stripe_md **mem_tgt)
712 LASSERT(*mem_tgt == NULL);
713 return obd_unpackmd(exp, mem_tgt, NULL, 0);
716 static inline int obd_free_memmd(struct obd_export *exp,
717 struct lov_stripe_md **mem_tgt)
723 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
728 static inline int obd_precreate(struct obd_export *exp)
733 EXP_CHECK_DT_OP(exp, precreate);
734 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
736 rc = OBP(exp->exp_obd, precreate)(exp);
740 static inline int obd_create_async(struct obd_export *exp,
741 struct obd_info *oinfo,
742 struct lov_stripe_md **ea,
743 struct obd_trans_info *oti)
748 EXP_CHECK_DT_OP(exp, create_async);
749 EXP_COUNTER_INCREMENT(exp, create_async);
751 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
755 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
756 struct lov_stripe_md **ea,
757 struct obd_trans_info *oti)
762 EXP_CHECK_DT_OP(exp, create);
763 EXP_COUNTER_INCREMENT(exp, create);
765 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
769 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
770 struct lov_stripe_md *ea,
771 struct obd_trans_info *oti,
772 struct obd_export *md_exp, void *capa)
777 EXP_CHECK_DT_OP(exp, destroy);
778 EXP_COUNTER_INCREMENT(exp, destroy);
780 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
784 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
789 EXP_CHECK_DT_OP(exp, getattr);
790 EXP_COUNTER_INCREMENT(exp, getattr);
792 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
796 static inline int obd_getattr_async(struct obd_export *exp,
797 struct obd_info *oinfo,
798 struct ptlrpc_request_set *set)
803 EXP_CHECK_DT_OP(exp, getattr_async);
804 EXP_COUNTER_INCREMENT(exp, getattr_async);
806 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
810 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
811 struct obd_trans_info *oti)
816 EXP_CHECK_DT_OP(exp, setattr);
817 EXP_COUNTER_INCREMENT(exp, setattr);
819 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
823 /* This performs all the requests set init/wait/destroy actions. */
824 static inline int obd_setattr_rqset(struct obd_export *exp,
825 struct obd_info *oinfo,
826 struct obd_trans_info *oti)
828 struct ptlrpc_request_set *set = NULL;
832 EXP_CHECK_DT_OP(exp, setattr_async);
833 EXP_COUNTER_INCREMENT(exp, setattr_async);
835 set = ptlrpc_prep_set();
839 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
841 rc = ptlrpc_set_wait(set);
842 ptlrpc_set_destroy(set);
846 /* This adds all the requests into @set if @set != NULL, otherwise
847 all requests are sent asynchronously without waiting for response. */
848 static inline int obd_setattr_async(struct obd_export *exp,
849 struct obd_info *oinfo,
850 struct obd_trans_info *oti,
851 struct ptlrpc_request_set *set)
856 EXP_CHECK_DT_OP(exp, setattr_async);
857 EXP_COUNTER_INCREMENT(exp, setattr_async);
859 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
863 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
866 struct obd_device *obd = imp->imp_obd;
870 OBD_CHECK_DEV_ACTIVE(obd);
871 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
872 OBD_COUNTER_INCREMENT(obd, add_conn);
874 rc = OBP(obd, add_conn)(imp, uuid, priority);
878 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
880 struct obd_device *obd = imp->imp_obd;
884 OBD_CHECK_DEV_ACTIVE(obd);
885 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
886 OBD_COUNTER_INCREMENT(obd, del_conn);
888 rc = OBP(obd, del_conn)(imp, uuid);
892 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
894 struct obd_uuid *uuid;
897 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
898 EXP_COUNTER_INCREMENT(exp, get_uuid);
900 uuid = OBP(exp->exp_obd, get_uuid)(exp);
904 static inline int obd_connect(const struct lu_env *env,
905 struct obd_export **exp,struct obd_device *obd,
906 struct obd_uuid *cluuid,
907 struct obd_connect_data *d,
911 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
915 OBD_CHECK_DEV_ACTIVE(obd);
916 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
917 OBD_COUNTER_INCREMENT(obd, connect);
919 rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
920 /* check that only subset is granted */
921 LASSERT(ergo(d != NULL,
922 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
926 static inline int obd_reconnect(const struct lu_env *env,
927 struct obd_export *exp,
928 struct obd_device *obd,
929 struct obd_uuid *cluuid,
930 struct obd_connect_data *d,
934 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
939 OBD_CHECK_DEV_ACTIVE(obd);
940 OBD_CHECK_DT_OP(obd, reconnect, 0);
941 OBD_COUNTER_INCREMENT(obd, reconnect);
943 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
944 /* check that only subset is granted */
945 LASSERT(ergo(d != NULL,
946 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
950 static inline int obd_disconnect(struct obd_export *exp)
955 EXP_CHECK_DT_OP(exp, disconnect);
956 EXP_COUNTER_INCREMENT(exp, disconnect);
958 rc = OBP(exp->exp_obd, disconnect)(exp);
962 static inline int obd_fid_init(struct obd_export *exp)
967 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
968 EXP_COUNTER_INCREMENT(exp, fid_init);
970 rc = OBP(exp->exp_obd, fid_init)(exp);
974 static inline int obd_fid_fini(struct obd_export *exp)
979 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
980 EXP_COUNTER_INCREMENT(exp, fid_fini);
982 rc = OBP(exp->exp_obd, fid_fini)(exp);
986 static inline int obd_fid_alloc(struct obd_export *exp,
988 struct md_op_data *op_data)
993 EXP_CHECK_DT_OP(exp, fid_alloc);
994 EXP_COUNTER_INCREMENT(exp, fid_alloc);
996 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1000 static inline int obd_fid_delete(struct obd_export *exp,
1001 const struct lu_fid *fid)
1006 EXP_CHECK_DT_OP(exp, fid_delete);
1007 EXP_COUNTER_INCREMENT(exp, fid_delete);
1009 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
1013 static inline int obd_ping(struct obd_export *exp)
1018 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1019 EXP_COUNTER_INCREMENT(exp, ping);
1021 rc = OBP(exp->exp_obd, ping)(exp);
1025 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1030 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1031 OBD_COUNTER_INCREMENT(obd, pool_new);
1033 rc = OBP(obd, pool_new)(obd, poolname);
1037 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1042 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1043 OBD_COUNTER_INCREMENT(obd, pool_del);
1045 rc = OBP(obd, pool_del)(obd, poolname);
1049 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1054 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1055 OBD_COUNTER_INCREMENT(obd, pool_add);
1057 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1061 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1066 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1067 OBD_COUNTER_INCREMENT(obd, pool_rem);
1069 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1073 static inline void obd_getref(struct obd_device *obd)
1076 if (OBT(obd) && OBP(obd, getref)) {
1077 OBD_COUNTER_INCREMENT(obd, getref);
1078 OBP(obd, getref)(obd);
1083 static inline void obd_putref(struct obd_device *obd)
1086 if (OBT(obd) && OBP(obd, putref)) {
1087 OBD_COUNTER_INCREMENT(obd, putref);
1088 OBP(obd, putref)(obd);
1093 static inline int obd_init_export(struct obd_export *exp)
1098 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1099 OBP((exp)->exp_obd, init_export))
1100 rc = OBP(exp->exp_obd, init_export)(exp);
1104 static inline int obd_destroy_export(struct obd_export *exp)
1107 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1108 OBP((exp)->exp_obd, destroy_export))
1109 OBP(exp->exp_obd, destroy_export)(exp);
1113 static inline int obd_extent_calc(struct obd_export *exp,
1114 struct lov_stripe_md *md,
1115 int cmd, obd_off *offset)
1119 EXP_CHECK_DT_OP(exp, extent_calc);
1120 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1124 static inline struct dentry *
1125 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1127 LASSERT(exp->exp_obd);
1129 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1134 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1136 LASSERT(exp->exp_obd);
1137 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1139 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1140 dentry, exp->exp_obd);
1145 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1146 * If the cache is older than @max_age we will get a new value from the
1147 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1148 static inline int obd_statfs_async(struct obd_device *obd,
1149 struct obd_info *oinfo,
1151 struct ptlrpc_request_set *rqset)
1159 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1160 OBD_COUNTER_INCREMENT(obd, statfs);
1162 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1163 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1164 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1165 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1167 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1168 " objects "LPU64"/"LPU64"\n",
1169 obd->obd_name, &obd->obd_osfs,
1170 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1171 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1172 cfs_spin_lock(&obd->obd_osfs_lock);
1173 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1174 cfs_spin_unlock(&obd->obd_osfs_lock);
1175 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1176 if (oinfo->oi_cb_up)
1177 oinfo->oi_cb_up(oinfo, 0);
1182 static inline int obd_statfs_rqset(struct obd_device *obd,
1183 struct obd_statfs *osfs, __u64 max_age,
1186 struct ptlrpc_request_set *set = NULL;
1187 struct obd_info oinfo = { { { 0 } } };
1191 set = ptlrpc_prep_set();
1195 oinfo.oi_osfs = osfs;
1196 oinfo.oi_flags = flags;
1197 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1199 rc = ptlrpc_set_wait(set);
1200 ptlrpc_set_destroy(set);
1204 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1205 * If the cache is older than @max_age we will get a new value from the
1206 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1207 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1208 __u64 max_age, __u32 flags)
1216 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1217 OBD_COUNTER_INCREMENT(obd, statfs);
1219 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1220 obd->obd_osfs_age, max_age);
1221 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1222 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1224 cfs_spin_lock(&obd->obd_osfs_lock);
1225 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1226 obd->obd_osfs_age = cfs_time_current_64();
1227 cfs_spin_unlock(&obd->obd_osfs_lock);
1230 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1231 " objects "LPU64"/"LPU64"\n",
1232 obd->obd_name, &obd->obd_osfs,
1233 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1234 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1235 cfs_spin_lock(&obd->obd_osfs_lock);
1236 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1237 cfs_spin_unlock(&obd->obd_osfs_lock);
1242 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1243 struct lov_stripe_md *ea, obd_size start,
1244 obd_size end, void *capa)
1249 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1250 EXP_COUNTER_INCREMENT(exp, sync);
1252 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1256 static inline int obd_punch_rqset(struct obd_export *exp,
1257 struct obd_info *oinfo,
1258 struct obd_trans_info *oti)
1260 struct ptlrpc_request_set *set = NULL;
1264 EXP_CHECK_DT_OP(exp, punch);
1265 EXP_COUNTER_INCREMENT(exp, punch);
1267 set = ptlrpc_prep_set();
1271 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1273 rc = ptlrpc_set_wait(set);
1274 ptlrpc_set_destroy(set);
1278 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1279 struct obd_trans_info *oti,
1280 struct ptlrpc_request_set *rqset)
1285 EXP_CHECK_DT_OP(exp, punch);
1286 EXP_COUNTER_INCREMENT(exp, punch);
1288 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1292 static inline int obd_brw(int cmd, struct obd_export *exp,
1293 struct obd_info *oinfo, obd_count oa_bufs,
1294 struct brw_page *pg, struct obd_trans_info *oti)
1299 EXP_CHECK_DT_OP(exp, brw);
1300 EXP_COUNTER_INCREMENT(exp, brw);
1302 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1303 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1304 "or OBD_BRW_CHECK\n");
1308 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1312 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1313 int objcount, struct obd_ioobj *obj,
1314 struct niobuf_remote *remote, int *pages,
1315 struct niobuf_local *local,
1316 struct obd_trans_info *oti,
1317 struct lustre_capa *capa)
1322 EXP_CHECK_DT_OP(exp, preprw);
1323 EXP_COUNTER_INCREMENT(exp, preprw);
1325 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1326 pages, local, oti, capa);
1330 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1331 int objcount, struct obd_ioobj *obj,
1332 struct niobuf_remote *rnb, int pages,
1333 struct niobuf_local *local,
1334 struct obd_trans_info *oti, int rc)
1338 EXP_CHECK_DT_OP(exp, commitrw);
1339 EXP_COUNTER_INCREMENT(exp, commitrw);
1341 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1342 rnb, pages, local, oti, rc);
1346 static inline int obd_merge_lvb(struct obd_export *exp,
1347 struct lov_stripe_md *lsm,
1348 struct ost_lvb *lvb, int kms_only)
1353 EXP_CHECK_DT_OP(exp, merge_lvb);
1354 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1356 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1360 static inline int obd_adjust_kms(struct obd_export *exp,
1361 struct lov_stripe_md *lsm, obd_off size,
1367 EXP_CHECK_DT_OP(exp, adjust_kms);
1368 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1370 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1374 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1375 int len, void *karg, void *uarg)
1380 EXP_CHECK_DT_OP(exp, iocontrol);
1381 EXP_COUNTER_INCREMENT(exp, iocontrol);
1383 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1387 static inline int obd_enqueue_rqset(struct obd_export *exp,
1388 struct obd_info *oinfo,
1389 struct ldlm_enqueue_info *einfo)
1391 struct ptlrpc_request_set *set = NULL;
1395 EXP_CHECK_DT_OP(exp, enqueue);
1396 EXP_COUNTER_INCREMENT(exp, enqueue);
1398 set = ptlrpc_prep_set();
1402 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1404 rc = ptlrpc_set_wait(set);
1405 ptlrpc_set_destroy(set);
1409 static inline int obd_enqueue(struct obd_export *exp,
1410 struct obd_info *oinfo,
1411 struct ldlm_enqueue_info *einfo,
1412 struct ptlrpc_request_set *set)
1417 EXP_CHECK_DT_OP(exp, enqueue);
1418 EXP_COUNTER_INCREMENT(exp, enqueue);
1420 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1424 static inline int obd_change_cbdata(struct obd_export *exp,
1425 struct lov_stripe_md *lsm,
1426 ldlm_iterator_t it, void *data)
1431 EXP_CHECK_DT_OP(exp, change_cbdata);
1432 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1434 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1438 static inline int obd_find_cbdata(struct obd_export *exp,
1439 struct lov_stripe_md *lsm,
1440 ldlm_iterator_t it, void *data)
1445 EXP_CHECK_DT_OP(exp, find_cbdata);
1446 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1448 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1452 static inline int obd_cancel(struct obd_export *exp,
1453 struct lov_stripe_md *ea, __u32 mode,
1454 struct lustre_handle *lockh)
1459 EXP_CHECK_DT_OP(exp, cancel);
1460 EXP_COUNTER_INCREMENT(exp, cancel);
1462 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1466 static inline int obd_cancel_unused(struct obd_export *exp,
1467 struct lov_stripe_md *ea,
1468 ldlm_cancel_flags_t flags,
1474 EXP_CHECK_DT_OP(exp, cancel_unused);
1475 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1477 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1481 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1482 struct obd_capa *oc, struct obd_client_handle *handle,
1488 EXP_CHECK_DT_OP(exp, pin);
1489 EXP_COUNTER_INCREMENT(exp, pin);
1491 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1495 static inline int obd_unpin(struct obd_export *exp,
1496 struct obd_client_handle *handle, int flag)
1501 EXP_CHECK_DT_OP(exp, unpin);
1502 EXP_COUNTER_INCREMENT(exp, unpin);
1504 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1509 static inline void obd_import_event(struct obd_device *obd,
1510 struct obd_import *imp,
1511 enum obd_import_event event)
1515 CERROR("NULL device\n");
1519 if (obd->obd_set_up && OBP(obd, import_event)) {
1520 OBD_COUNTER_INCREMENT(obd, import_event);
1521 OBP(obd, import_event)(obd, imp, event);
1526 static inline int obd_llog_connect(struct obd_export *exp,
1527 struct llogd_conn_body *body)
1532 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1533 EXP_COUNTER_INCREMENT(exp, llog_connect);
1535 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1540 static inline int obd_notify(struct obd_device *obd,
1541 struct obd_device *watched,
1542 enum obd_notify_event ev,
1549 /* the check for async_recov is a complete hack - I'm hereby
1550 overloading the meaning to also mean "this was called from
1551 mds_postsetup". I know that my mds is able to handle notifies
1552 by this point, and it needs to get them to execute mds_postrecov. */
1553 if (!obd->obd_set_up && !obd->obd_async_recov) {
1554 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1558 if (!OBP(obd, notify)) {
1559 CERROR("obd %s has no notify handler\n", obd->obd_name);
1563 OBD_COUNTER_INCREMENT(obd, notify);
1564 rc = OBP(obd, notify)(obd, watched, ev, data);
1568 static inline int obd_notify_observer(struct obd_device *observer,
1569 struct obd_device *observed,
1570 enum obd_notify_event ev,
1576 struct obd_notify_upcall *onu;
1578 if (observer->obd_observer)
1579 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1583 * Also, call non-obd listener, if any
1585 onu = &observer->obd_upcall;
1586 if (onu->onu_upcall != NULL)
1587 rc2 = onu->onu_upcall(observer, observed, ev,
1588 onu->onu_owner, NULL);
1592 return rc1 ? rc1 : rc2;
1595 static inline int obd_quotacheck(struct obd_export *exp,
1596 struct obd_quotactl *oqctl)
1601 EXP_CHECK_DT_OP(exp, quotacheck);
1602 EXP_COUNTER_INCREMENT(exp, quotacheck);
1604 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1608 static inline int obd_quotactl(struct obd_export *exp,
1609 struct obd_quotactl *oqctl)
1614 EXP_CHECK_DT_OP(exp, quotactl);
1615 EXP_COUNTER_INCREMENT(exp, quotactl);
1617 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1621 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1622 struct quota_adjust_qunit *oqaq,
1623 struct lustre_quota_ctxt *qctxt)
1625 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1626 struct timeval work_start;
1627 struct timeval work_end;
1633 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1635 cfs_gettimeofday(&work_start);
1637 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1638 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1640 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1642 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1644 cfs_gettimeofday(&work_end);
1645 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1646 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1653 static inline int obd_health_check(struct obd_device *obd)
1655 /* returns: 0 on healthy
1656 * >0 on unhealthy + reason code/flag
1657 * however the only suppored reason == 1 right now
1658 * We'll need to define some better reasons
1659 * or flags in the future.
1665 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1666 if (obd == NULL || !OBT(obd)) {
1667 CERROR("cleaned up obd\n");
1668 RETURN(-EOPNOTSUPP);
1670 if (!obd->obd_set_up || obd->obd_stopping)
1672 if (!OBP(obd, health_check))
1675 rc = OBP(obd, health_check)(obd);
1679 static inline int obd_register_observer(struct obd_device *obd,
1680 struct obd_device *observer)
1684 cfs_down_write(&obd->obd_observer_link_sem);
1685 if (obd->obd_observer && observer) {
1686 cfs_up_write(&obd->obd_observer_link_sem);
1689 obd->obd_observer = observer;
1690 cfs_up_write(&obd->obd_observer_link_sem);
1694 static inline int obd_pin_observer(struct obd_device *obd,
1695 struct obd_device **observer)
1698 cfs_down_read(&obd->obd_observer_link_sem);
1699 if (!obd->obd_observer) {
1701 cfs_up_read(&obd->obd_observer_link_sem);
1704 *observer = obd->obd_observer;
1708 static inline int obd_unpin_observer(struct obd_device *obd)
1711 cfs_up_read(&obd->obd_observer_link_sem);
1716 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1717 obd_page_removal_cb_t cb,
1718 obd_pin_extent_cb pin_cb)
1723 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1724 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1726 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1730 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1731 obd_page_removal_cb_t cb)
1736 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1737 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1739 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1743 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1744 obd_lock_cancel_cb cb)
1749 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1750 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1752 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1756 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1757 obd_lock_cancel_cb cb)
1762 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1763 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1765 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1770 /* metadata helpers */
1771 static inline int md_getstatus(struct obd_export *exp,
1772 struct lu_fid *fid, struct obd_capa **pc)
1777 EXP_CHECK_MD_OP(exp, getstatus);
1778 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1779 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1783 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1784 struct ptlrpc_request **request)
1788 EXP_CHECK_MD_OP(exp, getattr);
1789 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1790 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1794 static inline int md_change_cbdata(struct obd_export *exp,
1795 const struct lu_fid *fid,
1796 ldlm_iterator_t it, void *data)
1800 EXP_CHECK_MD_OP(exp, change_cbdata);
1801 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1802 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1806 static inline int md_find_cbdata(struct obd_export *exp,
1807 const struct lu_fid *fid,
1808 ldlm_iterator_t it, void *data)
1812 EXP_CHECK_MD_OP(exp, find_cbdata);
1813 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1814 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1818 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1819 struct md_open_data *mod,
1820 struct ptlrpc_request **request)
1824 EXP_CHECK_MD_OP(exp, close);
1825 EXP_MD_COUNTER_INCREMENT(exp, close);
1826 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1830 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1831 const void *data, int datalen, int mode, __u32 uid,
1832 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1833 struct ptlrpc_request **request)
1837 EXP_CHECK_MD_OP(exp, create);
1838 EXP_MD_COUNTER_INCREMENT(exp, create);
1839 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1840 uid, gid, cap_effective, rdev, request);
1844 static inline int md_done_writing(struct obd_export *exp,
1845 struct md_op_data *op_data,
1846 struct md_open_data *mod)
1850 EXP_CHECK_MD_OP(exp, done_writing);
1851 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1852 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1856 static inline int md_enqueue(struct obd_export *exp,
1857 struct ldlm_enqueue_info *einfo,
1858 struct lookup_intent *it,
1859 struct md_op_data *op_data,
1860 struct lustre_handle *lockh,
1861 void *lmm, int lmmsize,
1862 struct ptlrpc_request **req,
1863 int extra_lock_flags)
1867 EXP_CHECK_MD_OP(exp, enqueue);
1868 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1869 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1870 lmm, lmmsize, req, extra_lock_flags);
1874 static inline int md_getattr_name(struct obd_export *exp,
1875 struct md_op_data *op_data,
1876 struct ptlrpc_request **request)
1880 EXP_CHECK_MD_OP(exp, getattr_name);
1881 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1882 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1886 static inline int md_intent_lock(struct obd_export *exp,
1887 struct md_op_data *op_data, void *lmm,
1888 int lmmsize, struct lookup_intent *it,
1889 int flags, struct ptlrpc_request **reqp,
1890 ldlm_blocking_callback cb_blocking,
1891 int extra_lock_flags)
1895 EXP_CHECK_MD_OP(exp, intent_lock);
1896 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1897 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1898 it, flags, reqp, cb_blocking,
1903 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1904 struct ptlrpc_request **request)
1908 EXP_CHECK_MD_OP(exp, link);
1909 EXP_MD_COUNTER_INCREMENT(exp, link);
1910 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1914 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1915 const char *old, int oldlen, const char *new,
1916 int newlen, struct ptlrpc_request **request)
1920 EXP_CHECK_MD_OP(exp, rename);
1921 EXP_MD_COUNTER_INCREMENT(exp, rename);
1922 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1927 static inline int md_is_subdir(struct obd_export *exp,
1928 const struct lu_fid *pfid,
1929 const struct lu_fid *cfid,
1930 struct ptlrpc_request **request)
1934 EXP_CHECK_MD_OP(exp, is_subdir);
1935 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1936 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1940 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1941 void *ea, int ealen, void *ea2, int ea2len,
1942 struct ptlrpc_request **request,
1943 struct md_open_data **mod)
1947 EXP_CHECK_MD_OP(exp, setattr);
1948 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1949 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1950 ea2, ea2len, request, mod);
1954 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1955 struct obd_capa *oc, struct ptlrpc_request **request)
1959 EXP_CHECK_MD_OP(exp, sync);
1960 EXP_MD_COUNTER_INCREMENT(exp, sync);
1961 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1965 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1966 struct obd_capa *oc, __u64 offset,
1968 struct ptlrpc_request **request)
1972 EXP_CHECK_MD_OP(exp, readpage);
1973 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1974 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1978 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1979 struct ptlrpc_request **request)
1983 EXP_CHECK_MD_OP(exp, unlink);
1984 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1985 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1989 static inline int md_get_lustre_md(struct obd_export *exp,
1990 struct ptlrpc_request *req,
1991 struct obd_export *dt_exp,
1992 struct obd_export *md_exp,
1993 struct lustre_md *md)
1996 EXP_CHECK_MD_OP(exp, get_lustre_md);
1997 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1998 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2001 static inline int md_free_lustre_md(struct obd_export *exp,
2002 struct lustre_md *md)
2005 EXP_CHECK_MD_OP(exp, free_lustre_md);
2006 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2007 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2010 static inline int md_setxattr(struct obd_export *exp,
2011 const struct lu_fid *fid, struct obd_capa *oc,
2012 obd_valid valid, const char *name,
2013 const char *input, int input_size,
2014 int output_size, int flags, __u32 suppgid,
2015 struct ptlrpc_request **request)
2018 EXP_CHECK_MD_OP(exp, setxattr);
2019 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2020 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2021 input_size, output_size, flags,
2025 static inline int md_getxattr(struct obd_export *exp,
2026 const struct lu_fid *fid, struct obd_capa *oc,
2027 obd_valid valid, const char *name,
2028 const char *input, int input_size,
2029 int output_size, int flags,
2030 struct ptlrpc_request **request)
2033 EXP_CHECK_MD_OP(exp, getxattr);
2034 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2035 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2036 input_size, output_size, flags,
2040 static inline int md_set_open_replay_data(struct obd_export *exp,
2041 struct obd_client_handle *och,
2042 struct ptlrpc_request *open_req)
2045 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2046 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2047 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2050 static inline int md_clear_open_replay_data(struct obd_export *exp,
2051 struct obd_client_handle *och)
2054 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2055 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2056 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2059 static inline int md_set_lock_data(struct obd_export *exp,
2060 __u64 *lockh, void *data, __u32 *bits)
2063 EXP_CHECK_MD_OP(exp, set_lock_data);
2064 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2065 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2068 static inline int md_cancel_unused(struct obd_export *exp,
2069 const struct lu_fid *fid,
2070 ldlm_policy_data_t *policy,
2072 ldlm_cancel_flags_t flags,
2078 EXP_CHECK_MD_OP(exp, cancel_unused);
2079 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2081 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2086 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2087 const struct lu_fid *fid,
2089 ldlm_policy_data_t *policy,
2091 struct lustre_handle *lockh)
2094 EXP_CHECK_MD_OP(exp, lock_match);
2095 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2096 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2097 policy, mode, lockh));
2100 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2101 int def_asize, int cookiesize)
2104 EXP_CHECK_MD_OP(exp, init_ea_size);
2105 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2106 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2110 static inline int md_get_remote_perm(struct obd_export *exp,
2111 const struct lu_fid *fid,
2112 struct obd_capa *oc, __u32 suppgid,
2113 struct ptlrpc_request **request)
2116 EXP_CHECK_MD_OP(exp, get_remote_perm);
2117 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2118 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2122 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2127 EXP_CHECK_MD_OP(exp, renew_capa);
2128 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2129 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2133 static inline int md_unpack_capa(struct obd_export *exp,
2134 struct ptlrpc_request *req,
2135 const struct req_msg_field *field,
2136 struct obd_capa **oc)
2140 EXP_CHECK_MD_OP(exp, unpack_capa);
2141 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2142 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2146 static inline int md_intent_getattr_async(struct obd_export *exp,
2147 struct md_enqueue_info *minfo,
2148 struct ldlm_enqueue_info *einfo)
2152 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2153 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2154 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2158 static inline int md_revalidate_lock(struct obd_export *exp,
2159 struct lookup_intent *it,
2160 struct lu_fid *fid, __u32 *bits)
2164 EXP_CHECK_MD_OP(exp, revalidate_lock);
2165 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2166 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
2171 /* OBD Metadata Support */
2173 extern int obd_init_caches(void);
2174 extern void obd_cleanup_caches(void);
2176 /* support routines */
2177 extern cfs_mem_cache_t *obdo_cachep;
2179 #define OBDO_ALLOC(ptr) \
2181 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
2184 #define OBDO_FREE(ptr) \
2186 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2190 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2192 /* something here */
2195 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2197 /* something here */
2200 /* I'm as embarrassed about this as you are.
2202 * <shaver> // XXX do not look into _superhack with remaining eye
2203 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2204 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2207 extern void obd_sysctl_init (void);
2208 extern void obd_sysctl_clean (void);
2211 typedef __u8 class_uuid_t[16];
2212 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2215 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2216 int class_add_uuid(const char *uuid, __u64 nid);
2217 int class_del_uuid (const char *uuid);
2218 void class_init_uuidlist(void);
2219 void class_exit_uuidlist(void);
2222 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2223 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2226 void ll_generate_random_uuid(class_uuid_t uuid_out);
2228 #endif /* __LINUX_OBD_CLASS_H */