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);
106 int class_process_config(struct lustre_cfg *lcfg);
107 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
108 struct lustre_cfg *lcfg, void *data);
109 int class_attach(struct lustre_cfg *lcfg);
110 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
111 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
112 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
113 struct obd_device *class_incref(struct obd_device *obd,
114 const char *scope, const void *source);
115 void class_decref(struct obd_device *obd,
116 const char *scope, const void *source);
120 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
122 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
124 memset(lvars, 0, sizeof(*lvars));
128 #define CFG_F_START 0x01 /* Set when we start updating from a log */
129 #define CFG_F_MARKER 0x02 /* We are within a maker */
130 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
131 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
132 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
134 /* Passed as data param to class_config_parse_llog */
135 struct config_llog_instance {
138 struct super_block *cfg_sb;
139 struct obd_uuid cfg_uuid;
140 int cfg_last_idx; /* for partial llog processing */
143 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
144 struct config_llog_instance *cfg);
145 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
146 struct config_llog_instance *cfg);
148 /* list of active configuration logs */
149 struct config_llog_data {
151 struct ldlm_res_id cld_resid;
152 struct config_llog_instance cld_cfg;
153 struct list_head cld_list_chain;
154 atomic_t cld_refcount;
155 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
156 struct obd_export *cld_mgcexp;
157 unsigned int cld_stopping:1, /* we were told to stop watching */
158 cld_lostlock:1, /* lock not requeued */
162 struct lustre_profile {
163 struct list_head lp_list;
169 struct lustre_profile *class_get_profile(const char * prof);
170 void class_del_profile(const char *prof);
171 void class_del_profiles(void);
173 #define class_export_rpc_get(exp) \
175 atomic_inc(&(exp)->exp_rpc_count); \
176 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
177 (exp), atomic_read(&(exp)->exp_rpc_count)); \
178 class_export_get(exp); \
181 #define class_export_rpc_put(exp) \
183 atomic_dec(&(exp)->exp_rpc_count); \
184 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
185 (exp), atomic_read(&(exp)->exp_rpc_count)); \
186 class_export_put(exp); \
190 struct obd_export *class_export_get(struct obd_export *exp);
191 void class_export_put(struct obd_export *exp);
192 struct obd_export *class_new_export(struct obd_device *obddev,
193 struct obd_uuid *cluuid);
194 void class_unlink_export(struct obd_export *exp);
196 struct obd_import *class_import_get(struct obd_import *);
197 void class_import_put(struct obd_import *);
198 struct obd_import *class_new_import(struct obd_device *obd);
199 void class_destroy_import(struct obd_import *exp);
201 struct obd_type *class_search_type(const char *name);
202 struct obd_type *class_get_type(const char *name);
203 void class_put_type(struct obd_type *type);
204 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
205 struct obd_uuid *cluuid);
206 int class_disconnect(struct obd_export *exp);
207 void class_fail_export(struct obd_export *exp);
208 void class_disconnect_exports(struct obd_device *obddev);
209 int class_manual_cleanup(struct obd_device *obd);
210 int class_disconnect_stale_exports(struct obd_device *,
211 int (*test_export)(struct obd_export *),
212 enum obd_option flags);
214 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
216 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
217 (obd->obd_force ? OBD_OPT_FORCE : 0) |
218 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
222 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
223 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
224 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
225 unsigned int ia_valid);
226 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
227 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
228 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
231 #define OBT(dev) (dev)->obd_type
232 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
233 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
234 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
236 /* Ensure obd_setup: used for cleanup which must be called
237 while obd is stopping */
238 #define OBD_CHECK_DEV(obd) \
241 CERROR("NULL device\n"); \
246 /* ensure obd_setup and !obd_stopping */
247 #define OBD_CHECK_DEV_ACTIVE(obd) \
249 OBD_CHECK_DEV(obd); \
250 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
251 CERROR("Device %d not setup\n", \
259 #define OBD_COUNTER_OFFSET(op) \
260 ((offsetof(struct obd_ops, o_ ## op) - \
261 offsetof(struct obd_ops, o_iocontrol)) \
262 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
264 #define OBD_COUNTER_INCREMENT(obdx, op) \
265 if ((obdx)->obd_stats != NULL) { \
266 unsigned int coffset; \
267 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
268 OBD_COUNTER_OFFSET(op); \
269 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
270 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
273 #define EXP_COUNTER_INCREMENT(export, op) \
274 if ((export)->exp_obd->obd_stats != NULL) { \
275 unsigned int coffset; \
276 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
277 OBD_COUNTER_OFFSET(op); \
278 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
279 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
280 if ((export)->exp_nid_stats != NULL && \
281 (export)->exp_nid_stats->nid_stats != NULL) \
282 lprocfs_counter_incr( \
283 (export)->exp_nid_stats->nid_stats, coffset);\
286 #define MD_COUNTER_OFFSET(op) \
287 ((offsetof(struct md_ops, m_ ## op) - \
288 offsetof(struct md_ops, m_getstatus)) \
289 / sizeof(((struct md_ops *)(0))->m_getstatus))
291 #define MD_COUNTER_INCREMENT(obdx, op) \
292 if ((obd)->md_stats != NULL) { \
293 unsigned int coffset; \
294 coffset = (unsigned int)((obdx)->md_cntr_base) + \
295 MD_COUNTER_OFFSET(op); \
296 LASSERT(coffset < (obdx)->md_stats->ls_num); \
297 lprocfs_counter_incr((obdx)->md_stats, coffset); \
300 #define EXP_MD_COUNTER_INCREMENT(export, op) \
301 if ((export)->exp_obd->obd_stats != NULL) { \
302 unsigned int coffset; \
303 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
304 MD_COUNTER_OFFSET(op); \
305 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
306 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
307 if ((export)->exp_md_stats != NULL) \
308 lprocfs_counter_incr( \
309 (export)->exp_md_stats, coffset); \
313 #define OBD_COUNTER_OFFSET(op)
314 #define OBD_COUNTER_INCREMENT(obd, op)
315 #define EXP_COUNTER_INCREMENT(exp, op)
316 #define MD_COUNTER_INCREMENT(obd, op)
317 #define EXP_MD_COUNTER_INCREMENT(exp, op)
320 #define OBD_CHECK_MD_OP(obd, op, err) \
322 if (!OBT(obd) || !MDP((obd), op)) { \
324 CERROR("md_" #op ": dev %s/%d no operation\n", \
325 obd->obd_name, obd->obd_minor); \
330 #define EXP_CHECK_MD_OP(exp, op) \
332 if ((exp) == NULL) { \
333 CERROR("obd_" #op ": NULL export\n"); \
336 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
337 CERROR("obd_" #op ": cleaned up obd\n"); \
338 RETURN(-EOPNOTSUPP); \
340 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
341 CERROR("obd_" #op ": dev %s/%d no operation\n", \
342 (exp)->exp_obd->obd_name, \
343 (exp)->exp_obd->obd_minor); \
344 RETURN(-EOPNOTSUPP); \
349 #define OBD_CHECK_DT_OP(obd, op, err) \
351 if (!OBT(obd) || !OBP((obd), op)) { \
353 CERROR("obd_" #op ": dev %d no operation\n", \
359 #define EXP_CHECK_DT_OP(exp, op) \
361 if ((exp) == NULL) { \
362 CERROR("obd_" #op ": NULL export\n"); \
365 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
366 CERROR("obd_" #op ": cleaned up obd\n"); \
367 RETURN(-EOPNOTSUPP); \
369 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
370 CERROR("obd_" #op ": dev %d no operation\n", \
371 (exp)->exp_obd->obd_minor); \
372 RETURN(-EOPNOTSUPP); \
376 #define CTXT_CHECK_OP(ctxt, op, err) \
378 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
380 CERROR("lop_" #op ": dev %d no operation\n", \
381 ctxt->loc_obd->obd_minor); \
386 static inline int class_devno_max(void)
388 return MAX_OBD_DEVICES;
391 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
392 void *key, __u32 *vallen, void *val,
393 struct lov_stripe_md *lsm)
398 EXP_CHECK_DT_OP(exp, get_info);
399 EXP_COUNTER_INCREMENT(exp, get_info);
401 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
405 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
406 void *key, obd_count vallen, void *val,
407 struct ptlrpc_request_set *set)
412 EXP_CHECK_DT_OP(exp, set_info_async);
413 EXP_COUNTER_INCREMENT(exp, set_info_async);
415 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
421 * obd-lu integration.
423 * Functionality is being moved into new lu_device-based layering, but some
424 * pieces of configuration process are still based on obd devices.
426 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
427 * subsume ->o_setup() methods of obd devices they replace. The same for
428 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
429 * result, obd_setup() and obd_process_config() branch and call one XOR
432 * Yet neither lu_device_type_operations::ldto_device_fini() nor
433 * lu_device_type_operations::ldto_device_free() fully implement the
434 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
435 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
438 #define DECLARE_LU_VARS(ldt, d) \
439 struct lu_device_type *ldt; \
442 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
445 DECLARE_LU_VARS(ldt, d);
448 ldt = obd->obd_type->typ_lu;
450 struct lu_context session_ctx;
452 lu_context_init(&session_ctx, LCT_SESSION);
453 session_ctx.lc_thread = NULL;
454 lu_context_enter(&session_ctx);
456 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
458 env.le_ses = &session_ctx;
459 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
468 lu_context_exit(&session_ctx);
469 lu_context_fini(&session_ctx);
472 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
473 OBD_COUNTER_INCREMENT(obd, setup);
474 rc = OBP(obd, setup)(obd, cfg);
479 static inline int obd_precleanup(struct obd_device *obd,
480 enum obd_cleanup_stage cleanup_stage)
483 DECLARE_LU_VARS(ldt, d);
487 ldt = obd->obd_type->typ_lu;
489 if (ldt != NULL && d != NULL) {
490 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
493 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
495 ldt->ldt_ops->ldto_device_fini(&env, d);
500 OBD_CHECK_DT_OP(obd, precleanup, 0);
501 OBD_COUNTER_INCREMENT(obd, precleanup);
503 rc = OBP(obd, precleanup)(obd, cleanup_stage);
507 static inline int obd_cleanup(struct obd_device *obd)
510 DECLARE_LU_VARS(ldt, d);
515 ldt = obd->obd_type->typ_lu;
517 if (ldt != NULL && d != NULL) {
520 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
522 ldt->ldt_ops->ldto_device_free(&env, d);
524 obd->obd_lu_dev = NULL;
527 OBD_CHECK_DT_OP(obd, cleanup, 0);
528 OBD_COUNTER_INCREMENT(obd, cleanup);
530 rc = OBP(obd, cleanup)(obd);
535 obd_process_config(struct obd_device *obd, int datalen, void *data)
538 DECLARE_LU_VARS(ldt, d);
543 ldt = obd->obd_type->typ_lu;
545 if (ldt != NULL && d != NULL) {
548 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
550 rc = d->ld_ops->ldo_process_config(&env, d, data);
554 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
555 rc = OBP(obd, process_config)(obd, datalen, data);
557 OBD_COUNTER_INCREMENT(obd, process_config);
562 /* Pack an in-memory MD struct for storage on disk.
563 * Returns +ve size of packed MD (0 for free), or -ve error.
565 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
566 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
567 * If @*disk_tgt == NULL, it will be allocated
569 static inline int obd_packmd(struct obd_export *exp,
570 struct lov_mds_md **disk_tgt,
571 struct lov_stripe_md *mem_src)
576 EXP_CHECK_DT_OP(exp, packmd);
577 EXP_COUNTER_INCREMENT(exp, packmd);
579 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
583 static inline int obd_size_diskmd(struct obd_export *exp,
584 struct lov_stripe_md *mem_src)
586 return obd_packmd(exp, NULL, mem_src);
589 /* helper functions */
590 static inline int obd_alloc_diskmd(struct obd_export *exp,
591 struct lov_mds_md **disk_tgt)
594 LASSERT(*disk_tgt == NULL);
595 return obd_packmd(exp, disk_tgt, NULL);
598 static inline int obd_free_diskmd(struct obd_export *exp,
599 struct lov_mds_md **disk_tgt)
603 return obd_packmd(exp, disk_tgt, NULL);
606 /* Unpack an MD struct from disk to in-memory format.
607 * Returns +ve size of unpacked MD (0 for free), or -ve error.
609 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
610 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
611 * If @*mem_tgt == NULL, it will be allocated
613 static inline int obd_unpackmd(struct obd_export *exp,
614 struct lov_stripe_md **mem_tgt,
615 struct lov_mds_md *disk_src,
621 EXP_CHECK_DT_OP(exp, unpackmd);
622 EXP_COUNTER_INCREMENT(exp, unpackmd);
624 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
628 /* helper functions */
629 static inline int obd_alloc_memmd(struct obd_export *exp,
630 struct lov_stripe_md **mem_tgt)
633 LASSERT(*mem_tgt == NULL);
634 return obd_unpackmd(exp, mem_tgt, NULL, 0);
637 static inline int obd_free_memmd(struct obd_export *exp,
638 struct lov_stripe_md **mem_tgt)
644 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
649 static inline int obd_checkmd(struct obd_export *exp,
650 struct obd_export *md_exp,
651 struct lov_stripe_md *mem_tgt)
656 EXP_CHECK_DT_OP(exp, checkmd);
657 EXP_COUNTER_INCREMENT(exp, checkmd);
659 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
663 static inline int obd_precreate(struct obd_export *exp)
668 EXP_CHECK_DT_OP(exp, precreate);
669 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
671 rc = OBP(exp->exp_obd, precreate)(exp);
675 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
676 struct lov_stripe_md **ea,
677 struct obd_trans_info *oti)
682 EXP_CHECK_DT_OP(exp, create);
683 EXP_COUNTER_INCREMENT(exp, create);
685 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
689 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
690 struct lov_stripe_md *ea,
691 struct obd_trans_info *oti,
692 struct obd_export *md_exp, void *capa)
697 EXP_CHECK_DT_OP(exp, destroy);
698 EXP_COUNTER_INCREMENT(exp, destroy);
700 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
704 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
709 EXP_CHECK_DT_OP(exp, getattr);
710 EXP_COUNTER_INCREMENT(exp, getattr);
712 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
716 static inline int obd_getattr_async(struct obd_export *exp,
717 struct obd_info *oinfo,
718 struct ptlrpc_request_set *set)
723 EXP_CHECK_DT_OP(exp, getattr_async);
724 EXP_COUNTER_INCREMENT(exp, getattr_async);
726 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
730 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
731 struct obd_trans_info *oti)
736 EXP_CHECK_DT_OP(exp, setattr);
737 EXP_COUNTER_INCREMENT(exp, setattr);
739 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
743 /* This performs all the requests set init/wait/destroy actions. */
744 static inline int obd_setattr_rqset(struct obd_export *exp,
745 struct obd_info *oinfo,
746 struct obd_trans_info *oti)
748 struct ptlrpc_request_set *set = NULL;
752 EXP_CHECK_DT_OP(exp, setattr_async);
753 EXP_COUNTER_INCREMENT(exp, setattr_async);
755 set = ptlrpc_prep_set();
759 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
761 rc = ptlrpc_set_wait(set);
762 ptlrpc_set_destroy(set);
766 /* This adds all the requests into @set if @set != NULL, otherwise
767 all requests are sent asynchronously without waiting for response. */
768 static inline int obd_setattr_async(struct obd_export *exp,
769 struct obd_info *oinfo,
770 struct obd_trans_info *oti,
771 struct ptlrpc_request_set *set)
776 EXP_CHECK_DT_OP(exp, setattr_async);
777 EXP_COUNTER_INCREMENT(exp, setattr_async);
779 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
783 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
786 struct obd_device *obd = imp->imp_obd;
790 OBD_CHECK_DEV_ACTIVE(obd);
791 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
792 OBD_COUNTER_INCREMENT(obd, add_conn);
794 rc = OBP(obd, add_conn)(imp, uuid, priority);
798 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
800 struct obd_device *obd = imp->imp_obd;
804 OBD_CHECK_DEV_ACTIVE(obd);
805 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
806 OBD_COUNTER_INCREMENT(obd, del_conn);
808 rc = OBP(obd, del_conn)(imp, uuid);
812 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
814 struct obd_uuid *uuid;
817 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
818 EXP_COUNTER_INCREMENT(exp, get_uuid);
820 uuid = OBP(exp->exp_obd, get_uuid)(exp);
824 static inline int obd_connect(const struct lu_env *env,
825 struct obd_export **exp,struct obd_device *obd,
826 struct obd_uuid *cluuid,
827 struct obd_connect_data *d,
831 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
835 OBD_CHECK_DEV_ACTIVE(obd);
836 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
837 OBD_COUNTER_INCREMENT(obd, connect);
839 rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
840 /* check that only subset is granted */
841 LASSERT(ergo(d != NULL,
842 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
846 static inline int obd_reconnect(const struct lu_env *env,
847 struct obd_export *exp,
848 struct obd_device *obd,
849 struct obd_uuid *cluuid,
850 struct obd_connect_data *d,
854 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
859 OBD_CHECK_DEV_ACTIVE(obd);
860 OBD_CHECK_DT_OP(obd, reconnect, 0);
861 OBD_COUNTER_INCREMENT(obd, reconnect);
863 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
864 /* check that only subset is granted */
865 LASSERT(ergo(d != NULL,
866 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
870 static inline int obd_disconnect(struct obd_export *exp)
875 EXP_CHECK_DT_OP(exp, disconnect);
876 EXP_COUNTER_INCREMENT(exp, disconnect);
878 rc = OBP(exp->exp_obd, disconnect)(exp);
882 static inline int obd_fid_init(struct obd_export *exp)
887 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
888 EXP_COUNTER_INCREMENT(exp, fid_init);
890 rc = OBP(exp->exp_obd, fid_init)(exp);
894 static inline int obd_fid_fini(struct obd_export *exp)
899 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
900 EXP_COUNTER_INCREMENT(exp, fid_fini);
902 rc = OBP(exp->exp_obd, fid_fini)(exp);
906 static inline int obd_fid_alloc(struct obd_export *exp,
908 struct md_op_data *op_data)
913 EXP_CHECK_DT_OP(exp, fid_alloc);
914 EXP_COUNTER_INCREMENT(exp, fid_alloc);
916 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
920 static inline int obd_fid_delete(struct obd_export *exp,
921 const struct lu_fid *fid)
926 EXP_CHECK_DT_OP(exp, fid_delete);
927 EXP_COUNTER_INCREMENT(exp, fid_delete);
929 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
933 static inline int obd_ping(struct obd_export *exp)
938 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
939 EXP_COUNTER_INCREMENT(exp, ping);
941 rc = OBP(exp->exp_obd, ping)(exp);
945 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
950 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
951 OBD_COUNTER_INCREMENT(obd, pool_new);
953 rc = OBP(obd, pool_new)(obd, poolname);
957 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
962 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
963 OBD_COUNTER_INCREMENT(obd, pool_del);
965 rc = OBP(obd, pool_del)(obd, poolname);
969 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
974 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
975 OBD_COUNTER_INCREMENT(obd, pool_add);
977 rc = OBP(obd, pool_add)(obd, poolname, ostname);
981 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
986 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
987 OBD_COUNTER_INCREMENT(obd, pool_rem);
989 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
993 static inline int obd_init_export(struct obd_export *exp)
998 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
999 OBP((exp)->exp_obd, init_export))
1000 rc = OBP(exp->exp_obd, init_export)(exp);
1004 static inline int obd_destroy_export(struct obd_export *exp)
1007 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1008 OBP((exp)->exp_obd, destroy_export))
1009 OBP(exp->exp_obd, destroy_export)(exp);
1013 static inline int obd_extent_calc(struct obd_export *exp,
1014 struct lov_stripe_md *md,
1015 int cmd, obd_off *offset)
1019 EXP_CHECK_DT_OP(exp, extent_calc);
1020 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1024 static inline struct dentry *
1025 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1027 LASSERT(exp->exp_obd);
1029 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1034 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1036 LASSERT(exp->exp_obd);
1037 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1039 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1040 dentry, exp->exp_obd);
1046 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
1049 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1050 * If the cache is older than @max_age we will get a new value from the
1051 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1052 static inline int obd_statfs_async(struct obd_device *obd,
1053 struct obd_info *oinfo,
1055 struct ptlrpc_request_set *rqset)
1063 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1064 OBD_COUNTER_INCREMENT(obd, statfs);
1066 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1067 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1068 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1069 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1071 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1072 " objects "LPU64"/"LPU64"\n",
1073 obd->obd_name, &obd->obd_osfs,
1074 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1075 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1076 spin_lock(&obd->obd_osfs_lock);
1077 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1078 spin_unlock(&obd->obd_osfs_lock);
1079 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1080 if (oinfo->oi_cb_up)
1081 oinfo->oi_cb_up(oinfo, 0);
1086 static inline int obd_statfs_rqset(struct obd_device *obd,
1087 struct obd_statfs *osfs, __u64 max_age,
1090 struct ptlrpc_request_set *set = NULL;
1091 struct obd_info oinfo = { { { 0 } } };
1095 set = ptlrpc_prep_set();
1099 oinfo.oi_osfs = osfs;
1100 oinfo.oi_flags = flags;
1101 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1103 rc = ptlrpc_set_wait(set);
1104 ptlrpc_set_destroy(set);
1108 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1109 * If the cache is older than @max_age we will get a new value from the
1110 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1111 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1112 __u64 max_age, __u32 flags)
1120 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1121 OBD_COUNTER_INCREMENT(obd, statfs);
1123 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1124 obd->obd_osfs_age, max_age);
1125 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1126 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1128 spin_lock(&obd->obd_osfs_lock);
1129 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1130 obd->obd_osfs_age = cfs_time_current_64();
1131 spin_unlock(&obd->obd_osfs_lock);
1134 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1135 " objects "LPU64"/"LPU64"\n",
1136 obd->obd_name, &obd->obd_osfs,
1137 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1138 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1139 spin_lock(&obd->obd_osfs_lock);
1140 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1141 spin_unlock(&obd->obd_osfs_lock);
1146 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1147 struct lov_stripe_md *ea, obd_size start,
1148 obd_size end, void *capa)
1153 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1154 EXP_COUNTER_INCREMENT(exp, sync);
1156 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1160 static inline int obd_punch_rqset(struct obd_export *exp,
1161 struct obd_info *oinfo,
1162 struct obd_trans_info *oti)
1164 struct ptlrpc_request_set *set = NULL;
1168 EXP_CHECK_DT_OP(exp, punch);
1169 EXP_COUNTER_INCREMENT(exp, punch);
1171 set = ptlrpc_prep_set();
1175 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1177 rc = ptlrpc_set_wait(set);
1178 ptlrpc_set_destroy(set);
1182 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1183 struct obd_trans_info *oti,
1184 struct ptlrpc_request_set *rqset)
1189 EXP_CHECK_DT_OP(exp, punch);
1190 EXP_COUNTER_INCREMENT(exp, punch);
1192 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1196 static inline int obd_brw(int cmd, struct obd_export *exp,
1197 struct obd_info *oinfo, obd_count oa_bufs,
1198 struct brw_page *pg, struct obd_trans_info *oti)
1203 EXP_CHECK_DT_OP(exp, brw);
1204 EXP_COUNTER_INCREMENT(exp, brw);
1206 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1207 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1208 "or OBD_BRW_CHECK\n");
1212 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1216 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1217 int objcount, struct obd_ioobj *obj,
1218 struct niobuf_remote *remote, int *pages,
1219 struct niobuf_local *local,
1220 struct obd_trans_info *oti,
1221 struct lustre_capa *capa)
1226 EXP_CHECK_DT_OP(exp, preprw);
1227 EXP_COUNTER_INCREMENT(exp, preprw);
1229 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1230 pages, local, oti, capa);
1234 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1235 int objcount, struct obd_ioobj *obj,
1236 struct niobuf_remote *rnb, int pages,
1237 struct niobuf_local *local,
1238 struct obd_trans_info *oti, int rc)
1242 EXP_CHECK_DT_OP(exp, commitrw);
1243 EXP_COUNTER_INCREMENT(exp, commitrw);
1245 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1246 rnb, pages, local, oti, rc);
1250 static inline int obd_merge_lvb(struct obd_export *exp,
1251 struct lov_stripe_md *lsm,
1252 struct ost_lvb *lvb, int kms_only)
1257 EXP_CHECK_DT_OP(exp, merge_lvb);
1258 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1260 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1264 static inline int obd_adjust_kms(struct obd_export *exp,
1265 struct lov_stripe_md *lsm, obd_off size,
1271 EXP_CHECK_DT_OP(exp, adjust_kms);
1272 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1274 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1278 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1279 int len, void *karg, void *uarg)
1284 EXP_CHECK_DT_OP(exp, iocontrol);
1285 EXP_COUNTER_INCREMENT(exp, iocontrol);
1287 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1291 static inline int obd_enqueue_rqset(struct obd_export *exp,
1292 struct obd_info *oinfo,
1293 struct ldlm_enqueue_info *einfo)
1295 struct ptlrpc_request_set *set = NULL;
1299 EXP_CHECK_DT_OP(exp, enqueue);
1300 EXP_COUNTER_INCREMENT(exp, enqueue);
1302 set = ptlrpc_prep_set();
1306 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1308 rc = ptlrpc_set_wait(set);
1309 ptlrpc_set_destroy(set);
1313 static inline int obd_enqueue(struct obd_export *exp,
1314 struct obd_info *oinfo,
1315 struct ldlm_enqueue_info *einfo,
1316 struct ptlrpc_request_set *set)
1321 EXP_CHECK_DT_OP(exp, enqueue);
1322 EXP_COUNTER_INCREMENT(exp, enqueue);
1324 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1328 static inline int obd_change_cbdata(struct obd_export *exp,
1329 struct lov_stripe_md *lsm,
1330 ldlm_iterator_t it, void *data)
1335 EXP_CHECK_DT_OP(exp, change_cbdata);
1336 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1338 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1342 static inline int obd_cancel(struct obd_export *exp,
1343 struct lov_stripe_md *ea, __u32 mode,
1344 struct lustre_handle *lockh)
1349 EXP_CHECK_DT_OP(exp, cancel);
1350 EXP_COUNTER_INCREMENT(exp, cancel);
1352 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1356 static inline int obd_cancel_unused(struct obd_export *exp,
1357 struct lov_stripe_md *ea,
1358 int flags, void *opaque)
1363 EXP_CHECK_DT_OP(exp, cancel_unused);
1364 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1366 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1370 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1371 struct obd_capa *oc, struct obd_client_handle *handle,
1377 EXP_CHECK_DT_OP(exp, pin);
1378 EXP_COUNTER_INCREMENT(exp, pin);
1380 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1384 static inline int obd_unpin(struct obd_export *exp,
1385 struct obd_client_handle *handle, int flag)
1390 EXP_CHECK_DT_OP(exp, unpin);
1391 EXP_COUNTER_INCREMENT(exp, unpin);
1393 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1398 static inline void obd_import_event(struct obd_device *obd,
1399 struct obd_import *imp,
1400 enum obd_import_event event)
1404 CERROR("NULL device\n");
1408 if (obd->obd_set_up && OBP(obd, import_event)) {
1409 OBD_COUNTER_INCREMENT(obd, import_event);
1410 OBP(obd, import_event)(obd, imp, event);
1415 static inline int obd_llog_connect(struct obd_export *exp,
1416 struct llogd_conn_body *body)
1421 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1422 EXP_COUNTER_INCREMENT(exp, llog_connect);
1424 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1429 static inline int obd_notify(struct obd_device *obd,
1430 struct obd_device *watched,
1431 enum obd_notify_event ev,
1438 /* the check for async_recov is a complete hack - I'm hereby
1439 overloading the meaning to also mean "this was called from
1440 mds_postsetup". I know that my mds is able to handle notifies
1441 by this point, and it needs to get them to execute mds_postrecov. */
1442 if (!obd->obd_set_up && !obd->obd_async_recov) {
1443 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1447 if (!OBP(obd, notify)) {
1448 CERROR("obd %s has no notify handler\n", obd->obd_name);
1452 OBD_COUNTER_INCREMENT(obd, notify);
1453 rc = OBP(obd, notify)(obd, watched, ev, data);
1457 static inline int obd_notify_observer(struct obd_device *observer,
1458 struct obd_device *observed,
1459 enum obd_notify_event ev,
1465 struct obd_notify_upcall *onu;
1467 if (observer->obd_observer)
1468 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1472 * Also, call non-obd listener, if any
1474 onu = &observer->obd_upcall;
1475 if (onu->onu_upcall != NULL)
1476 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1480 return rc1 ? rc1 : rc2;
1483 static inline int obd_quotacheck(struct obd_export *exp,
1484 struct obd_quotactl *oqctl)
1489 EXP_CHECK_DT_OP(exp, quotacheck);
1490 EXP_COUNTER_INCREMENT(exp, quotacheck);
1492 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1496 static inline int obd_quotactl(struct obd_export *exp,
1497 struct obd_quotactl *oqctl)
1502 EXP_CHECK_DT_OP(exp, quotactl);
1503 EXP_COUNTER_INCREMENT(exp, quotactl);
1505 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1509 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1510 struct quota_adjust_qunit *oqaq,
1511 struct lustre_quota_ctxt *qctxt)
1513 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1514 struct timeval work_start;
1515 struct timeval work_end;
1521 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1523 do_gettimeofday(&work_start);
1525 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1526 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1528 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1530 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1532 do_gettimeofday(&work_end);
1533 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1534 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1541 static inline int obd_health_check(struct obd_device *obd)
1543 /* returns: 0 on healthy
1544 * >0 on unhealthy + reason code/flag
1545 * however the only suppored reason == 1 right now
1546 * We'll need to define some better reasons
1547 * or flags in the future.
1553 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1554 if (obd == NULL || !OBT(obd)) {
1555 CERROR("cleaned up obd\n");
1556 RETURN(-EOPNOTSUPP);
1558 if (!obd->obd_set_up || obd->obd_stopping)
1560 if (!OBP(obd, health_check))
1563 rc = OBP(obd, health_check)(obd);
1567 static inline int obd_register_observer(struct obd_device *obd,
1568 struct obd_device *observer)
1572 if (obd->obd_observer && observer)
1574 obd->obd_observer = observer;
1579 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1580 obd_page_removal_cb_t cb,
1581 obd_pin_extent_cb pin_cb)
1586 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1587 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1589 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1593 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1594 obd_page_removal_cb_t cb)
1599 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1600 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1602 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1606 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1607 obd_lock_cancel_cb cb)
1612 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1613 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1615 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1619 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1620 obd_lock_cancel_cb cb)
1625 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1626 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1628 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1633 /* metadata helpers */
1634 static inline int md_getstatus(struct obd_export *exp,
1635 struct lu_fid *fid, struct obd_capa **pc)
1640 EXP_CHECK_MD_OP(exp, getstatus);
1641 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1642 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1646 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1647 struct obd_capa *oc, obd_valid valid, int ea_size,
1648 struct ptlrpc_request **request)
1652 EXP_CHECK_MD_OP(exp, getattr);
1653 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1654 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1659 static inline int md_change_cbdata(struct obd_export *exp,
1660 const struct lu_fid *fid,
1661 ldlm_iterator_t it, void *data)
1665 EXP_CHECK_MD_OP(exp, change_cbdata);
1666 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1667 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1671 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1672 struct md_open_data *mod,
1673 struct ptlrpc_request **request)
1677 EXP_CHECK_MD_OP(exp, close);
1678 EXP_MD_COUNTER_INCREMENT(exp, close);
1679 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1683 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1684 const void *data, int datalen, int mode, __u32 uid,
1685 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1686 struct ptlrpc_request **request)
1690 EXP_CHECK_MD_OP(exp, create);
1691 EXP_MD_COUNTER_INCREMENT(exp, create);
1692 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1693 uid, gid, cap_effective, rdev, request);
1697 static inline int md_done_writing(struct obd_export *exp,
1698 struct md_op_data *op_data,
1699 struct md_open_data *mod)
1703 EXP_CHECK_MD_OP(exp, done_writing);
1704 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1705 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1709 static inline int md_enqueue(struct obd_export *exp,
1710 struct ldlm_enqueue_info *einfo,
1711 struct lookup_intent *it,
1712 struct md_op_data *op_data,
1713 struct lustre_handle *lockh,
1714 void *lmm, int lmmsize,
1715 struct ptlrpc_request **req,
1716 int extra_lock_flags)
1720 EXP_CHECK_MD_OP(exp, enqueue);
1721 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1722 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1723 lmm, lmmsize, req, extra_lock_flags);
1727 static inline int md_getattr_name(struct obd_export *exp,
1728 const struct lu_fid *fid, struct obd_capa *oc,
1729 const char *name, int namelen,
1730 obd_valid valid, int ea_size, __u32 suppgid,
1731 struct ptlrpc_request **request)
1735 EXP_CHECK_MD_OP(exp, getattr_name);
1736 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1737 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1738 valid, ea_size, suppgid, request);
1742 static inline int md_intent_lock(struct obd_export *exp,
1743 struct md_op_data *op_data, void *lmm,
1744 int lmmsize, struct lookup_intent *it,
1745 int flags, struct ptlrpc_request **reqp,
1746 ldlm_blocking_callback cb_blocking,
1747 int extra_lock_flags)
1751 EXP_CHECK_MD_OP(exp, intent_lock);
1752 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1753 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1754 it, flags, reqp, cb_blocking,
1759 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1760 struct ptlrpc_request **request)
1764 EXP_CHECK_MD_OP(exp, link);
1765 EXP_MD_COUNTER_INCREMENT(exp, link);
1766 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1770 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1771 const char *old, int oldlen, const char *new,
1772 int newlen, struct ptlrpc_request **request)
1776 EXP_CHECK_MD_OP(exp, rename);
1777 EXP_MD_COUNTER_INCREMENT(exp, rename);
1778 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1783 static inline int md_is_subdir(struct obd_export *exp,
1784 const struct lu_fid *pfid,
1785 const struct lu_fid *cfid,
1786 struct ptlrpc_request **request)
1790 EXP_CHECK_MD_OP(exp, is_subdir);
1791 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1792 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1796 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1797 void *ea, int ealen, void *ea2, int ea2len,
1798 struct ptlrpc_request **request,
1799 struct md_open_data **mod)
1803 EXP_CHECK_MD_OP(exp, setattr);
1804 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1805 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1806 ea2, ea2len, request, mod);
1810 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1811 struct obd_capa *oc, struct ptlrpc_request **request)
1815 EXP_CHECK_MD_OP(exp, sync);
1816 EXP_MD_COUNTER_INCREMENT(exp, sync);
1817 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1821 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1822 struct obd_capa *oc, __u64 offset,
1824 struct ptlrpc_request **request)
1828 EXP_CHECK_MD_OP(exp, readpage);
1829 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1830 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1834 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1835 struct ptlrpc_request **request)
1839 EXP_CHECK_MD_OP(exp, unlink);
1840 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1841 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1845 static inline int md_get_lustre_md(struct obd_export *exp,
1846 struct ptlrpc_request *req,
1847 struct obd_export *dt_exp,
1848 struct obd_export *md_exp,
1849 struct lustre_md *md)
1852 EXP_CHECK_MD_OP(exp, get_lustre_md);
1853 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1854 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1857 static inline int md_free_lustre_md(struct obd_export *exp,
1858 struct lustre_md *md)
1861 EXP_CHECK_MD_OP(exp, free_lustre_md);
1862 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1863 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1866 static inline int md_setxattr(struct obd_export *exp,
1867 const struct lu_fid *fid, struct obd_capa *oc,
1868 obd_valid valid, const char *name,
1869 const char *input, int input_size,
1870 int output_size, int flags, __u32 suppgid,
1871 struct ptlrpc_request **request)
1874 EXP_CHECK_MD_OP(exp, setxattr);
1875 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1876 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1877 input_size, output_size, flags,
1881 static inline int md_getxattr(struct obd_export *exp,
1882 const struct lu_fid *fid, struct obd_capa *oc,
1883 obd_valid valid, const char *name,
1884 const char *input, int input_size,
1885 int output_size, int flags,
1886 struct ptlrpc_request **request)
1889 EXP_CHECK_MD_OP(exp, getxattr);
1890 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1891 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1892 input_size, output_size, flags,
1896 static inline int md_set_open_replay_data(struct obd_export *exp,
1897 struct obd_client_handle *och,
1898 struct ptlrpc_request *open_req)
1901 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1902 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1903 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1906 static inline int md_clear_open_replay_data(struct obd_export *exp,
1907 struct obd_client_handle *och)
1910 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1911 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1912 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1915 static inline int md_set_lock_data(struct obd_export *exp,
1916 __u64 *lockh, void *data)
1919 EXP_CHECK_MD_OP(exp, set_lock_data);
1920 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1921 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1924 static inline int md_cancel_unused(struct obd_export *exp,
1925 const struct lu_fid *fid,
1926 ldlm_policy_data_t *policy,
1927 ldlm_mode_t mode, int flags, void *opaque)
1932 EXP_CHECK_MD_OP(exp, cancel_unused);
1933 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1935 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1940 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
1941 const struct lu_fid *fid,
1943 ldlm_policy_data_t *policy,
1945 struct lustre_handle *lockh)
1948 EXP_CHECK_MD_OP(exp, lock_match);
1949 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1950 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1951 policy, mode, lockh));
1954 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1955 int def_asize, int cookiesize)
1958 EXP_CHECK_MD_OP(exp, init_ea_size);
1959 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1960 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1964 static inline int md_get_remote_perm(struct obd_export *exp,
1965 const struct lu_fid *fid,
1966 struct obd_capa *oc, __u32 suppgid,
1967 struct ptlrpc_request **request)
1970 EXP_CHECK_MD_OP(exp, get_remote_perm);
1971 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1972 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1976 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1981 EXP_CHECK_MD_OP(exp, renew_capa);
1982 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1983 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1987 static inline int md_unpack_capa(struct obd_export *exp,
1988 struct ptlrpc_request *req,
1989 const struct req_msg_field *field,
1990 struct obd_capa **oc)
1994 EXP_CHECK_MD_OP(exp, unpack_capa);
1995 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1996 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2000 static inline int md_intent_getattr_async(struct obd_export *exp,
2001 struct md_enqueue_info *minfo,
2002 struct ldlm_enqueue_info *einfo)
2006 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2007 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2008 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2012 static inline int md_revalidate_lock(struct obd_export *exp,
2013 struct lookup_intent *it,
2018 EXP_CHECK_MD_OP(exp, revalidate_lock);
2019 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2020 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2025 /* OBD Metadata Support */
2027 extern int obd_init_caches(void);
2028 extern void obd_cleanup_caches(void);
2030 /* support routines */
2031 extern cfs_mem_cache_t *obdo_cachep;
2033 #define OBDO_ALLOC(ptr) \
2035 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
2038 #define OBDO_FREE(ptr) \
2040 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2044 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2046 /* something here */
2049 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2051 /* something here */
2054 /* I'm as embarrassed about this as you are.
2056 * <shaver> // XXX do not look into _superhack with remaining eye
2057 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2058 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2061 extern void obd_sysctl_init (void);
2062 extern void obd_sysctl_clean (void);
2065 typedef __u8 class_uuid_t[16];
2066 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2069 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2070 int class_add_uuid(const char *uuid, __u64 nid);
2071 int class_del_uuid (const char *uuid);
2072 void class_init_uuidlist(void);
2073 void class_exit_uuidlist(void);
2076 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2077 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2080 void ll_generate_random_uuid(class_uuid_t uuid_out);
2082 #endif /* __LINUX_OBD_CLASS_H */