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_find_client_notype(struct obd_uuid *tgt_uuid,
90 struct obd_uuid *grp_uuid);
91 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
93 struct obd_device * class_num2obd(int num);
95 int oig_init(struct obd_io_group **oig);
96 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
97 void oig_complete_one(struct obd_io_group *oig,
98 struct oig_callback_context *occ, int rc);
99 void oig_release(struct obd_io_group *oig);
100 int oig_wait(struct obd_io_group *oig);
102 char *obd_export_nid2str(struct obd_export *exp);
104 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
105 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
107 int obd_zombie_impexp_init(void);
108 void obd_zombie_impexp_stop(void);
109 void obd_zombie_impexp_cull(void);
112 int class_process_config(struct lustre_cfg *lcfg);
113 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
114 struct lustre_cfg *lcfg, void *data);
115 int class_attach(struct lustre_cfg *lcfg);
116 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
117 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
118 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
119 struct obd_device *class_incref(struct obd_device *obd);
120 void class_decref(struct obd_device *obd);
124 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
126 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
128 memset(lvars, 0, sizeof(*lvars));
132 #define CFG_F_START 0x01 /* Set when we start updating from a log */
133 #define CFG_F_MARKER 0x02 /* We are within a maker */
134 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
135 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
136 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
138 /* Passed as data param to class_config_parse_llog */
139 struct config_llog_instance {
141 struct super_block *cfg_sb;
142 struct obd_uuid cfg_uuid;
143 int cfg_last_idx; /* for partial llog processing */
146 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
147 struct config_llog_instance *cfg);
148 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
149 struct config_llog_instance *cfg);
151 /* list of active configuration logs */
152 struct config_llog_data {
154 struct ldlm_res_id cld_resid;
155 struct config_llog_instance cld_cfg;
156 struct list_head cld_list_chain;
157 atomic_t cld_refcount;
158 struct obd_export *cld_mgcexp;
159 unsigned int cld_stopping:1, /* we were told to stop watching */
160 cld_lostlock:1; /* lock not requeued */
163 struct lustre_profile {
164 struct list_head lp_list;
170 struct lustre_profile *class_get_profile(const char * prof);
171 void class_del_profile(const char *prof);
172 void class_del_profiles(void);
174 #define class_export_rpc_get(exp) \
176 atomic_inc(&(exp)->exp_rpc_count); \
177 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
178 (exp), atomic_read(&(exp)->exp_rpc_count)); \
179 class_export_get(exp); \
182 #define class_export_rpc_put(exp) \
184 atomic_dec(&(exp)->exp_rpc_count); \
185 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
186 (exp), atomic_read(&(exp)->exp_rpc_count)); \
187 class_export_put(exp); \
191 #define class_export_get(exp) \
193 struct obd_export *exp_ = exp; \
194 atomic_inc(&exp_->exp_refcount); \
195 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
196 atomic_read(&exp_->exp_refcount)); \
200 #define class_export_put(exp) \
202 LASSERT((exp) != NULL); \
203 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
204 atomic_read(&(exp)->exp_refcount) - 1); \
205 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
206 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
207 __class_export_put(exp); \
210 void __class_export_put(struct obd_export *);
211 struct obd_export *class_new_export(struct obd_device *obddev,
212 struct obd_uuid *cluuid);
213 void class_unlink_export(struct obd_export *exp);
215 struct obd_import *class_import_get(struct obd_import *);
216 void class_import_put(struct obd_import *);
217 struct obd_import *class_new_import(struct obd_device *obd);
218 void class_destroy_import(struct obd_import *exp);
220 struct obd_type *class_search_type(const char *name);
221 struct obd_type *class_get_type(const char *name);
222 void class_put_type(struct obd_type *type);
223 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
224 struct obd_uuid *cluuid);
225 int class_disconnect(struct obd_export *exp);
226 void class_fail_export(struct obd_export *exp);
227 void class_disconnect_exports(struct obd_device *obddev);
228 int class_disconnect_stale_exports(struct obd_device *,
229 int (*test_export)(struct obd_export *));
230 int class_manual_cleanup(struct obd_device *obd);
232 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
233 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
234 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
235 unsigned int ia_valid);
236 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
237 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
238 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
241 #define OBT(dev) (dev)->obd_type
242 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
243 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
244 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
246 /* Ensure obd_setup: used for cleanup which must be called
247 while obd is stopping */
248 #define OBD_CHECK_DEV(obd) \
251 CERROR("NULL device\n"); \
256 /* ensure obd_setup and !obd_stopping */
257 #define OBD_CHECK_DEV_ACTIVE(obd) \
259 OBD_CHECK_DEV(obd); \
260 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
261 CERROR("Device %d not setup\n", \
269 #define OBD_COUNTER_OFFSET(op) \
270 ((offsetof(struct obd_ops, o_ ## op) - \
271 offsetof(struct obd_ops, o_iocontrol)) \
272 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
274 #define OBD_COUNTER_INCREMENT(obdx, op) \
275 if ((obdx)->obd_stats != NULL) { \
276 unsigned int coffset; \
277 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
278 OBD_COUNTER_OFFSET(op); \
279 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
280 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
283 #define EXP_COUNTER_INCREMENT(export, op) \
284 if ((export)->exp_obd->obd_stats != NULL) { \
285 unsigned int coffset; \
286 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
287 OBD_COUNTER_OFFSET(op); \
288 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
289 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
290 if ((export)->exp_nid_stats != NULL && \
291 (export)->exp_nid_stats->nid_stats != NULL) \
292 lprocfs_counter_incr( \
293 (export)->exp_nid_stats->nid_stats, coffset);\
296 #define MD_COUNTER_OFFSET(op) \
297 ((offsetof(struct md_ops, m_ ## op) - \
298 offsetof(struct md_ops, m_getstatus)) \
299 / sizeof(((struct md_ops *)(0))->m_getstatus))
301 #define MD_COUNTER_INCREMENT(obdx, op) \
302 if ((obd)->md_stats != NULL) { \
303 unsigned int coffset; \
304 coffset = (unsigned int)((obdx)->md_cntr_base) + \
305 MD_COUNTER_OFFSET(op); \
306 LASSERT(coffset < (obdx)->md_stats->ls_num); \
307 lprocfs_counter_incr((obdx)->md_stats, coffset); \
310 #define EXP_MD_COUNTER_INCREMENT(export, op) \
311 if ((export)->exp_obd->obd_stats != NULL) { \
312 unsigned int coffset; \
313 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
314 MD_COUNTER_OFFSET(op); \
315 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
316 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
317 if ((export)->exp_md_stats != NULL) \
318 lprocfs_counter_incr( \
319 (export)->exp_md_stats, coffset); \
323 #define OBD_COUNTER_OFFSET(op)
324 #define OBD_COUNTER_INCREMENT(obd, op)
325 #define EXP_COUNTER_INCREMENT(exp, op)
326 #define MD_COUNTER_INCREMENT(obd, op)
327 #define EXP_MD_COUNTER_INCREMENT(exp, op)
330 #define OBD_CHECK_MD_OP(obd, op, err) \
332 if (!OBT(obd) || !MDP((obd), op)) { \
334 CERROR("md_" #op ": dev %s/%d no operation\n", \
335 obd->obd_name, obd->obd_minor); \
340 #define EXP_CHECK_MD_OP(exp, op) \
342 if ((exp) == NULL) { \
343 CERROR("obd_" #op ": NULL export\n"); \
346 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
347 CERROR("obd_" #op ": cleaned up obd\n"); \
348 RETURN(-EOPNOTSUPP); \
350 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
351 CERROR("obd_" #op ": dev %s/%d no operation\n", \
352 (exp)->exp_obd->obd_name, \
353 (exp)->exp_obd->obd_minor); \
354 RETURN(-EOPNOTSUPP); \
359 #define OBD_CHECK_DT_OP(obd, op, err) \
361 if (!OBT(obd) || !OBP((obd), op)) { \
363 CERROR("obd_" #op ": dev %d no operation\n", \
369 #define EXP_CHECK_DT_OP(exp, op) \
371 if ((exp) == NULL) { \
372 CERROR("obd_" #op ": NULL export\n"); \
375 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
376 CERROR("obd_" #op ": cleaned up obd\n"); \
377 RETURN(-EOPNOTSUPP); \
379 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
380 CERROR("obd_" #op ": dev %d no operation\n", \
381 (exp)->exp_obd->obd_minor); \
382 RETURN(-EOPNOTSUPP); \
386 #define CTXT_CHECK_OP(ctxt, op, err) \
388 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
390 CERROR("lop_" #op ": dev %d no operation\n", \
391 ctxt->loc_obd->obd_minor); \
396 static inline int class_devno_max(void)
398 return MAX_OBD_DEVICES;
401 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
402 void *key, __u32 *vallen, void *val,
403 struct lov_stripe_md *lsm)
408 EXP_CHECK_DT_OP(exp, get_info);
409 EXP_COUNTER_INCREMENT(exp, get_info);
411 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
415 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
416 void *key, obd_count vallen, void *val,
417 struct ptlrpc_request_set *set)
422 EXP_CHECK_DT_OP(exp, set_info_async);
423 EXP_COUNTER_INCREMENT(exp, set_info_async);
425 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
431 #define DECLARE_LU_VARS(ldt, d) \
432 struct lu_device_type *ldt; \
435 #define DECLARE_LU_VARS(ldt, d) \
436 extern void __placeholder_to_put_a_semicolon(void)
438 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
441 DECLARE_LU_VARS(ldt, d);
445 ldt = obd->obd_type->typ_lu;
449 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
451 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
463 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
464 OBD_COUNTER_INCREMENT(obd, setup);
465 rc = OBP(obd, setup)(obd, cfg);
470 static inline int obd_precleanup(struct obd_device *obd,
471 enum obd_cleanup_stage cleanup_stage)
474 DECLARE_LU_VARS(ldt, d);
479 ldt = obd->obd_type->typ_lu;
483 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
486 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
488 ldt->ldt_ops->ldto_device_fini(&env, d);
497 OBD_CHECK_DT_OP(obd, precleanup, 0);
498 rc = OBP(obd, precleanup)(obd, cleanup_stage);
501 OBD_COUNTER_INCREMENT(obd, precleanup);
505 static inline int obd_cleanup(struct obd_device *obd)
508 DECLARE_LU_VARS(ldt, d);
514 ldt = obd->obd_type->typ_lu;
520 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
522 ldt->ldt_ops->ldto_device_free(&env, d);
524 obd->obd_lu_dev = NULL;
529 OBD_CHECK_DT_OP(obd, cleanup, 0);
530 rc = OBP(obd, cleanup)(obd);
532 OBD_COUNTER_INCREMENT(obd, cleanup);
537 obd_process_config(struct obd_device *obd, int datalen, void *data)
540 DECLARE_LU_VARS(ldt, d);
546 ldt = obd->obd_type->typ_lu;
548 if (ldt != NULL && d != NULL) {
551 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
553 rc = d->ld_ops->ldo_process_config(&env, d, data);
559 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
560 rc = OBP(obd, process_config)(obd, datalen, data);
562 OBD_COUNTER_INCREMENT(obd, process_config);
567 /* Pack an in-memory MD struct for storage on disk.
568 * Returns +ve size of packed MD (0 for free), or -ve error.
570 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
571 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
572 * If @*disk_tgt == NULL, it will be allocated
574 static inline int obd_packmd(struct obd_export *exp,
575 struct lov_mds_md **disk_tgt,
576 struct lov_stripe_md *mem_src)
581 EXP_CHECK_DT_OP(exp, packmd);
582 EXP_COUNTER_INCREMENT(exp, packmd);
584 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
588 static inline int obd_size_diskmd(struct obd_export *exp,
589 struct lov_stripe_md *mem_src)
591 return obd_packmd(exp, NULL, mem_src);
594 /* helper functions */
595 static inline int obd_alloc_diskmd(struct obd_export *exp,
596 struct lov_mds_md **disk_tgt)
599 LASSERT(*disk_tgt == NULL);
600 return obd_packmd(exp, disk_tgt, NULL);
603 static inline int obd_free_diskmd(struct obd_export *exp,
604 struct lov_mds_md **disk_tgt)
608 return obd_packmd(exp, disk_tgt, NULL);
611 /* Unpack an MD struct from disk to in-memory format.
612 * Returns +ve size of unpacked MD (0 for free), or -ve error.
614 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
615 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
616 * If @*mem_tgt == NULL, it will be allocated
618 static inline int obd_unpackmd(struct obd_export *exp,
619 struct lov_stripe_md **mem_tgt,
620 struct lov_mds_md *disk_src,
626 EXP_CHECK_DT_OP(exp, unpackmd);
627 EXP_COUNTER_INCREMENT(exp, unpackmd);
629 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
633 /* helper functions */
634 static inline int obd_alloc_memmd(struct obd_export *exp,
635 struct lov_stripe_md **mem_tgt)
638 LASSERT(*mem_tgt == NULL);
639 return obd_unpackmd(exp, mem_tgt, NULL, 0);
642 static inline int obd_free_memmd(struct obd_export *exp,
643 struct lov_stripe_md **mem_tgt)
647 return obd_unpackmd(exp, mem_tgt, NULL, 0);
650 static inline int obd_checkmd(struct obd_export *exp,
651 struct obd_export *md_exp,
652 struct lov_stripe_md *mem_tgt)
657 EXP_CHECK_DT_OP(exp, checkmd);
658 EXP_COUNTER_INCREMENT(exp, checkmd);
660 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
664 static inline int obd_precreate(struct obd_export *exp)
669 EXP_CHECK_DT_OP(exp, precreate);
670 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
672 rc = OBP(exp->exp_obd, precreate)(exp);
676 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
677 struct lov_stripe_md **ea,
678 struct obd_trans_info *oti)
683 EXP_CHECK_DT_OP(exp, create);
684 EXP_COUNTER_INCREMENT(exp, create);
686 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
690 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
691 struct lov_stripe_md *ea,
692 struct obd_trans_info *oti,
693 struct obd_export *md_exp)
698 EXP_CHECK_DT_OP(exp, destroy);
699 EXP_COUNTER_INCREMENT(exp, destroy);
701 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
705 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
710 EXP_CHECK_DT_OP(exp, getattr);
711 EXP_COUNTER_INCREMENT(exp, getattr);
713 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
717 static inline int obd_getattr_async(struct obd_export *exp,
718 struct obd_info *oinfo,
719 struct ptlrpc_request_set *set)
724 EXP_CHECK_DT_OP(exp, getattr_async);
725 EXP_COUNTER_INCREMENT(exp, getattr_async);
727 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
731 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
732 struct obd_trans_info *oti)
737 EXP_CHECK_DT_OP(exp, setattr);
738 EXP_COUNTER_INCREMENT(exp, setattr);
740 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
744 /* This performs all the requests set init/wait/destroy actions. */
745 static inline int obd_setattr_rqset(struct obd_export *exp,
746 struct obd_info *oinfo,
747 struct obd_trans_info *oti)
749 struct ptlrpc_request_set *set = NULL;
753 EXP_CHECK_DT_OP(exp, setattr_async);
754 EXP_COUNTER_INCREMENT(exp, setattr_async);
756 set = ptlrpc_prep_set();
760 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
762 rc = ptlrpc_set_wait(set);
763 ptlrpc_set_destroy(set);
767 /* This adds all the requests into @set if @set != NULL, otherwise
768 all requests are sent asynchronously without waiting for response. */
769 static inline int obd_setattr_async(struct obd_export *exp,
770 struct obd_info *oinfo,
771 struct obd_trans_info *oti,
772 struct ptlrpc_request_set *set)
777 EXP_CHECK_DT_OP(exp, setattr_async);
778 EXP_COUNTER_INCREMENT(exp, setattr_async);
780 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
784 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
787 struct obd_device *obd = imp->imp_obd;
791 OBD_CHECK_DEV_ACTIVE(obd);
792 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
793 OBD_COUNTER_INCREMENT(obd, add_conn);
795 rc = OBP(obd, add_conn)(imp, uuid, priority);
799 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
801 struct obd_device *obd = imp->imp_obd;
805 OBD_CHECK_DEV_ACTIVE(obd);
806 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
807 OBD_COUNTER_INCREMENT(obd, del_conn);
809 rc = OBP(obd, del_conn)(imp, uuid);
813 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
815 struct obd_uuid *uuid;
818 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
819 EXP_COUNTER_INCREMENT(exp, get_uuid);
821 uuid = OBP(exp->exp_obd, get_uuid)(exp);
825 static inline int obd_connect(const struct lu_env *env,
826 struct lustre_handle *conn,struct obd_device *obd,
827 struct obd_uuid *cluuid,
828 struct obd_connect_data *d,
833 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
838 OBD_CHECK_DEV_ACTIVE(obd);
839 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
840 OBD_COUNTER_INCREMENT(obd, connect);
842 rc = OBP(obd, connect)(env, conn, obd, cluuid, d, localdata);
843 /* check that only subset is granted */
844 LASSERT(ergo(d != NULL,
845 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
849 static inline int obd_reconnect(const struct lu_env *env,
850 struct obd_export *exp,
851 struct obd_device *obd,
852 struct obd_uuid *cluuid,
853 struct obd_connect_data *d)
857 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
863 OBD_CHECK_DEV_ACTIVE(obd);
864 OBD_CHECK_DT_OP(obd, reconnect, 0);
865 OBD_COUNTER_INCREMENT(obd, reconnect);
867 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d);
868 /* check that only subset is granted */
869 LASSERT(ergo(d != NULL,
870 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
874 static inline int obd_disconnect(struct obd_export *exp)
879 EXP_CHECK_DT_OP(exp, disconnect);
880 EXP_COUNTER_INCREMENT(exp, disconnect);
882 rc = OBP(exp->exp_obd, disconnect)(exp);
886 static inline int obd_fid_init(struct obd_export *exp)
891 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
892 EXP_COUNTER_INCREMENT(exp, fid_init);
894 rc = OBP(exp->exp_obd, fid_init)(exp);
898 static inline int obd_fid_fini(struct obd_export *exp)
903 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
904 EXP_COUNTER_INCREMENT(exp, fid_fini);
906 rc = OBP(exp->exp_obd, fid_fini)(exp);
910 static inline int obd_fid_alloc(struct obd_export *exp,
912 struct md_op_data *op_data)
917 EXP_CHECK_DT_OP(exp, fid_alloc);
918 EXP_COUNTER_INCREMENT(exp, fid_alloc);
920 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
924 static inline int obd_fid_delete(struct obd_export *exp,
925 const struct lu_fid *fid)
930 EXP_CHECK_DT_OP(exp, fid_delete);
931 EXP_COUNTER_INCREMENT(exp, fid_delete);
933 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
937 static inline int obd_ping(struct obd_export *exp)
942 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
943 EXP_COUNTER_INCREMENT(exp, ping);
945 rc = OBP(exp->exp_obd, ping)(exp);
949 static inline int obd_init_export(struct obd_export *exp)
954 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
955 OBP((exp)->exp_obd, init_export))
956 rc = OBP(exp->exp_obd, init_export)(exp);
960 static inline int obd_destroy_export(struct obd_export *exp)
963 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
964 OBP((exp)->exp_obd, destroy_export))
965 OBP(exp->exp_obd, destroy_export)(exp);
969 static inline int obd_extent_calc(struct obd_export *exp,
970 struct lov_stripe_md *md,
971 int cmd, obd_off *offset)
975 EXP_CHECK_DT_OP(exp, extent_calc);
976 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
980 static inline struct dentry *
981 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
983 LASSERT(exp->exp_obd);
985 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
990 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
992 LASSERT(exp->exp_obd);
993 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
995 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
996 dentry, exp->exp_obd);
1002 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
1005 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1006 * If the cache is older than @max_age we will get a new value from the
1007 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1008 static inline int obd_statfs_async(struct obd_device *obd,
1009 struct obd_info *oinfo,
1011 struct ptlrpc_request_set *rqset)
1019 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1020 OBD_COUNTER_INCREMENT(obd, statfs);
1022 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1023 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1024 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1025 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1027 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1028 " objects "LPU64"/"LPU64"\n",
1029 obd->obd_name, &obd->obd_osfs,
1030 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1031 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1032 spin_lock(&obd->obd_osfs_lock);
1033 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1034 spin_unlock(&obd->obd_osfs_lock);
1035 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1036 if (oinfo->oi_cb_up)
1037 oinfo->oi_cb_up(oinfo, 0);
1042 static inline int obd_statfs_rqset(struct obd_device *obd,
1043 struct obd_statfs *osfs, __u64 max_age,
1046 struct ptlrpc_request_set *set = NULL;
1047 struct obd_info oinfo = { { { 0 } } };
1051 set = ptlrpc_prep_set();
1055 oinfo.oi_osfs = osfs;
1056 oinfo.oi_flags = flags;
1057 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1059 rc = ptlrpc_set_wait(set);
1060 ptlrpc_set_destroy(set);
1064 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1065 * If the cache is older than @max_age we will get a new value from the
1066 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1067 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1068 __u64 max_age, __u32 flags)
1076 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1077 OBD_COUNTER_INCREMENT(obd, statfs);
1079 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1080 obd->obd_osfs_age, max_age);
1081 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1082 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1084 spin_lock(&obd->obd_osfs_lock);
1085 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1086 obd->obd_osfs_age = cfs_time_current_64();
1087 spin_unlock(&obd->obd_osfs_lock);
1090 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1091 " objects "LPU64"/"LPU64"\n",
1092 obd->obd_name, &obd->obd_osfs,
1093 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1094 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1095 spin_lock(&obd->obd_osfs_lock);
1096 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1097 spin_unlock(&obd->obd_osfs_lock);
1102 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1103 struct lov_stripe_md *ea, obd_size start,
1104 obd_size end, void *capa)
1109 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1110 EXP_COUNTER_INCREMENT(exp, sync);
1112 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1116 static inline int obd_punch_rqset(struct obd_export *exp,
1117 struct obd_info *oinfo,
1118 struct obd_trans_info *oti)
1120 struct ptlrpc_request_set *set = NULL;
1124 EXP_CHECK_DT_OP(exp, punch);
1125 EXP_COUNTER_INCREMENT(exp, punch);
1127 set = ptlrpc_prep_set();
1131 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1133 rc = ptlrpc_set_wait(set);
1134 ptlrpc_set_destroy(set);
1138 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1139 struct obd_trans_info *oti,
1140 struct ptlrpc_request_set *rqset)
1145 EXP_CHECK_DT_OP(exp, punch);
1146 EXP_COUNTER_INCREMENT(exp, punch);
1148 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1152 static inline int obd_brw(int cmd, struct obd_export *exp,
1153 struct obd_info *oinfo, obd_count oa_bufs,
1154 struct brw_page *pg, struct obd_trans_info *oti)
1159 EXP_CHECK_DT_OP(exp, brw);
1160 EXP_COUNTER_INCREMENT(exp, brw);
1162 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1163 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1164 "or OBD_BRW_CHECK\n");
1168 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1172 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1173 struct obd_info *oinfo, obd_count oa_bufs,
1174 struct brw_page *pg, struct obd_trans_info *oti,
1175 struct ptlrpc_request_set *set)
1180 EXP_CHECK_DT_OP(exp, brw_async);
1181 EXP_COUNTER_INCREMENT(exp, brw_async);
1183 if (!(cmd & OBD_BRW_RWMASK)) {
1184 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1188 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1192 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1193 struct obdo *oa, struct lov_stripe_md *lsm,
1194 obd_count oa_bufs, struct brw_page *pg,
1195 struct obd_trans_info *oti,
1196 struct obd_capa *ocapa)
1198 struct ptlrpc_request_set *set = NULL;
1199 struct obd_info oinfo = { { { 0 } } };
1203 set = ptlrpc_prep_set();
1209 oinfo.oi_capa = ocapa;
1210 rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1212 rc = ptlrpc_set_wait(set);
1214 CERROR("error from callback: rc = %d\n", rc);
1216 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
1217 "error from obd_brw_async: rc = %d\n", rc);
1219 ptlrpc_set_destroy(set);
1223 static inline int obd_prep_async_page(struct obd_export *exp,
1224 struct lov_stripe_md *lsm,
1225 struct lov_oinfo *loi,
1226 cfs_page_t *page, obd_off offset,
1227 struct obd_async_page_ops *ops,
1228 void *data, void **res, int nocache,
1229 struct lustre_handle *lockh)
1234 EXP_CHECK_DT_OP(exp, prep_async_page);
1235 EXP_COUNTER_INCREMENT(exp, prep_async_page);
1237 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1238 ops, data, res, nocache,
1244 * Checks if requested extent lock is compatible with a lock under the page.
1246 * Checks if the lock under \a page is compatible with a read or write lock
1247 * (specified by \a rw) for an extent [\a start , \a end].
1249 * \param exp obd export (lov or osc)
1250 * \param lsm striping information for the file
1251 * \param res async_page placeholder
1252 * \param rw OBD_BRW_READ if requested for reading,
1253 * OBD_BRW_WRITE if requested for writing
1254 * \param start start of the requested extent
1255 * \param end end of the requested extent
1256 * \param cookie transparent parameter for passing locking context
1258 * \post result == 1, *cookie == context, appropriate lock is referenced or
1260 * \retval 1 owned lock is reused for the request
1261 * \retval 0 no lock reused for the request
1262 * \retval -ENOTSUPP reget_short_lock is not exported at this layer
1264 * \see obd_release_short_lock
1266 static inline int obd_reget_short_lock(struct obd_export *exp,
1267 struct lov_stripe_md *lsm,
1269 obd_off start, obd_off end,
1274 EXP_CHECK_DT_OP(exp, reget_short_lock);
1275 EXP_COUNTER_INCREMENT(exp, reget_short_lock);
1277 RETURN(OBP(exp->exp_obd, reget_short_lock)(exp, lsm, res, rw,
1278 start, end, cookie));
1283 * Releases a reference to a lock taken in a "fast" way.
1285 * Releases a read or write (specified by \a rw) lock
1286 * referenced by \a cookie.
1288 * \param exp obd export (lov or osc)
1289 * \param lsm striping information for the file
1290 * \param end end of the locked extent
1291 * \param rw OBD_BRW_READ if requested for reading,
1292 * OBD_BRW_WRITE if requested for writing
1293 * \param cookie transparent parameter for passing locking context
1295 * \post appropriate lock is dereferenced
1297 * \see obd_reget_short_lock
1299 static inline int obd_release_short_lock(struct obd_export *exp,
1300 struct lov_stripe_md *lsm, obd_off end,
1301 void *cookie, int rw)
1305 EXP_CHECK_DT_OP(exp, release_short_lock);
1306 EXP_COUNTER_INCREMENT(exp, release_short_lock);
1308 RETURN(OBP(exp->exp_obd, release_short_lock)(exp, lsm, end,
1312 static inline int obd_queue_async_io(struct obd_export *exp,
1313 struct lov_stripe_md *lsm,
1314 struct lov_oinfo *loi, void *cookie,
1315 int cmd, obd_off off, int count,
1316 obd_flag brw_flags, obd_flag async_flags)
1321 EXP_CHECK_DT_OP(exp, queue_async_io);
1322 EXP_COUNTER_INCREMENT(exp, queue_async_io);
1323 LASSERT(cmd & OBD_BRW_RWMASK);
1325 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1326 count, brw_flags, async_flags);
1330 static inline int obd_set_async_flags(struct obd_export *exp,
1331 struct lov_stripe_md *lsm,
1332 struct lov_oinfo *loi, void *cookie,
1333 obd_flag async_flags)
1338 EXP_CHECK_DT_OP(exp, set_async_flags);
1339 EXP_COUNTER_INCREMENT(exp, set_async_flags);
1341 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1346 static inline int obd_queue_group_io(struct obd_export *exp,
1347 struct lov_stripe_md *lsm,
1348 struct lov_oinfo *loi,
1349 struct obd_io_group *oig,
1350 void *cookie, int cmd, obd_off off,
1351 int count, obd_flag brw_flags,
1352 obd_flag async_flags)
1357 EXP_CHECK_DT_OP(exp, queue_group_io);
1358 EXP_COUNTER_INCREMENT(exp, queue_group_io);
1359 LASSERT(cmd & OBD_BRW_RWMASK);
1361 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1362 cmd, off, count, brw_flags,
1367 static inline int obd_trigger_group_io(struct obd_export *exp,
1368 struct lov_stripe_md *lsm,
1369 struct lov_oinfo *loi,
1370 struct obd_io_group *oig)
1375 EXP_CHECK_DT_OP(exp, trigger_group_io);
1376 EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1378 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1382 static inline int obd_teardown_async_page(struct obd_export *exp,
1383 struct lov_stripe_md *lsm,
1384 struct lov_oinfo *loi, void *cookie)
1389 EXP_CHECK_DT_OP(exp, teardown_async_page);
1390 EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1392 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1396 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1397 int objcount, struct obd_ioobj *obj,
1398 int niocount, struct niobuf_remote *remote,
1399 struct niobuf_local *local,
1400 struct obd_trans_info *oti,
1401 struct lustre_capa *capa)
1406 EXP_CHECK_DT_OP(exp, preprw);
1407 EXP_COUNTER_INCREMENT(exp, preprw);
1409 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1410 remote, local, oti, capa);
1414 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1415 int objcount, struct obd_ioobj *obj,
1416 int niocount, struct niobuf_local *local,
1417 struct obd_trans_info *oti, int rc)
1421 EXP_CHECK_DT_OP(exp, commitrw);
1422 EXP_COUNTER_INCREMENT(exp, commitrw);
1424 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1429 static inline int obd_merge_lvb(struct obd_export *exp,
1430 struct lov_stripe_md *lsm,
1431 struct ost_lvb *lvb, int kms_only)
1436 EXP_CHECK_DT_OP(exp, merge_lvb);
1437 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1439 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1443 static inline int obd_adjust_kms(struct obd_export *exp,
1444 struct lov_stripe_md *lsm, obd_off size,
1450 EXP_CHECK_DT_OP(exp, adjust_kms);
1451 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1453 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1457 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1458 int len, void *karg, void *uarg)
1463 EXP_CHECK_DT_OP(exp, iocontrol);
1464 EXP_COUNTER_INCREMENT(exp, iocontrol);
1466 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1470 static inline int obd_enqueue_rqset(struct obd_export *exp,
1471 struct obd_info *oinfo,
1472 struct ldlm_enqueue_info *einfo)
1474 struct ptlrpc_request_set *set = NULL;
1478 EXP_CHECK_DT_OP(exp, enqueue);
1479 EXP_COUNTER_INCREMENT(exp, enqueue);
1481 set = ptlrpc_prep_set();
1485 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1487 rc = ptlrpc_set_wait(set);
1488 ptlrpc_set_destroy(set);
1492 static inline int obd_enqueue(struct obd_export *exp,
1493 struct obd_info *oinfo,
1494 struct ldlm_enqueue_info *einfo,
1495 struct ptlrpc_request_set *set)
1500 EXP_CHECK_DT_OP(exp, enqueue);
1501 EXP_COUNTER_INCREMENT(exp, enqueue);
1503 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1507 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1508 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1509 int *flags, void *data, struct lustre_handle *lockh)
1514 EXP_CHECK_DT_OP(exp, match);
1515 EXP_COUNTER_INCREMENT(exp, match);
1517 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1522 static inline int obd_change_cbdata(struct obd_export *exp,
1523 struct lov_stripe_md *lsm,
1524 ldlm_iterator_t it, void *data)
1529 EXP_CHECK_DT_OP(exp, change_cbdata);
1530 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1532 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1536 static inline int obd_cancel(struct obd_export *exp,
1537 struct lov_stripe_md *ea, __u32 mode,
1538 struct lustre_handle *lockh)
1543 EXP_CHECK_DT_OP(exp, cancel);
1544 EXP_COUNTER_INCREMENT(exp, cancel);
1546 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1550 static inline int obd_cancel_unused(struct obd_export *exp,
1551 struct lov_stripe_md *ea,
1552 int flags, void *opaque)
1557 EXP_CHECK_DT_OP(exp, cancel_unused);
1558 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1560 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1564 static inline int obd_join_lru(struct obd_export *exp,
1565 struct lov_stripe_md *ea, int join)
1570 EXP_CHECK_DT_OP(exp, join_lru);
1571 EXP_COUNTER_INCREMENT(exp, join_lru);
1573 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1577 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1578 struct obd_capa *oc, struct obd_client_handle *handle,
1584 EXP_CHECK_DT_OP(exp, pin);
1585 EXP_COUNTER_INCREMENT(exp, pin);
1587 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1591 static inline int obd_unpin(struct obd_export *exp,
1592 struct obd_client_handle *handle, int flag)
1597 EXP_CHECK_DT_OP(exp, unpin);
1598 EXP_COUNTER_INCREMENT(exp, unpin);
1600 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1605 static inline void obd_import_event(struct obd_device *obd,
1606 struct obd_import *imp,
1607 enum obd_import_event event)
1611 CERROR("NULL device\n");
1615 if (obd->obd_set_up && OBP(obd, import_event)) {
1616 OBD_COUNTER_INCREMENT(obd, import_event);
1617 OBP(obd, import_event)(obd, imp, event);
1622 static inline int obd_llog_connect(struct obd_export *exp,
1623 struct llogd_conn_body *body)
1628 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1629 EXP_COUNTER_INCREMENT(exp, llog_connect);
1631 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1636 static inline int obd_notify(struct obd_device *obd,
1637 struct obd_device *watched,
1638 enum obd_notify_event ev,
1645 /* the check for async_recov is a complete hack - I'm hereby
1646 overloading the meaning to also mean "this was called from
1647 mds_postsetup". I know that my mds is able to handle notifies
1648 by this point, and it needs to get them to execute mds_postrecov. */
1649 if (!obd->obd_set_up && !obd->obd_async_recov) {
1650 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1654 if (!OBP(obd, notify)) {
1655 CERROR("obd %s has no notify handler\n", obd->obd_name);
1659 OBD_COUNTER_INCREMENT(obd, notify);
1660 rc = OBP(obd, notify)(obd, watched, ev, data);
1664 static inline int obd_notify_observer(struct obd_device *observer,
1665 struct obd_device *observed,
1666 enum obd_notify_event ev,
1672 struct obd_notify_upcall *onu;
1674 if (observer->obd_observer)
1675 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1679 * Also, call non-obd listener, if any
1681 onu = &observer->obd_upcall;
1682 if (onu->onu_upcall != NULL)
1683 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1687 return rc1 ? rc1 : rc2;
1690 static inline int obd_quotacheck(struct obd_export *exp,
1691 struct obd_quotactl *oqctl)
1696 EXP_CHECK_DT_OP(exp, quotacheck);
1697 EXP_COUNTER_INCREMENT(exp, quotacheck);
1699 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1703 static inline int obd_quotactl(struct obd_export *exp,
1704 struct obd_quotactl *oqctl)
1709 EXP_CHECK_DT_OP(exp, quotactl);
1710 EXP_COUNTER_INCREMENT(exp, quotactl);
1712 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1716 static inline int obd_health_check(struct obd_device *obd)
1718 /* returns: 0 on healthy
1719 * >0 on unhealthy + reason code/flag
1720 * however the only suppored reason == 1 right now
1721 * We'll need to define some better reasons
1722 * or flags in the future.
1728 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1729 if (obd == NULL || !OBT(obd)) {
1730 CERROR("cleaned up obd\n");
1731 RETURN(-EOPNOTSUPP);
1733 if (!obd->obd_set_up || obd->obd_stopping)
1735 if (!OBP(obd, health_check))
1738 rc = OBP(obd, health_check)(obd);
1742 static inline int obd_register_observer(struct obd_device *obd,
1743 struct obd_device *observer)
1747 if (obd->obd_observer && observer)
1749 obd->obd_observer = observer;
1753 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1754 obd_page_removal_cb_t cb,
1755 obd_pin_extent_cb pin_cb)
1760 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1761 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1763 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1767 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1768 obd_page_removal_cb_t cb)
1773 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1774 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1776 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1780 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1781 obd_lock_cancel_cb cb)
1786 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1787 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1789 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1793 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1794 obd_lock_cancel_cb cb)
1799 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1800 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1802 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1806 /* metadata helpers */
1807 static inline int md_getstatus(struct obd_export *exp,
1808 struct lu_fid *fid, struct obd_capa **pc)
1813 EXP_CHECK_MD_OP(exp, getstatus);
1814 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1815 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1819 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1820 struct obd_capa *oc, obd_valid valid, int ea_size,
1821 struct ptlrpc_request **request)
1825 EXP_CHECK_MD_OP(exp, getattr);
1826 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1827 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1832 static inline int md_change_cbdata(struct obd_export *exp,
1833 const struct lu_fid *fid,
1834 ldlm_iterator_t it, void *data)
1838 EXP_CHECK_MD_OP(exp, change_cbdata);
1839 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1840 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1844 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1845 struct md_open_data *mod,
1846 struct ptlrpc_request **request)
1850 EXP_CHECK_MD_OP(exp, close);
1851 EXP_MD_COUNTER_INCREMENT(exp, close);
1852 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1856 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1857 const void *data, int datalen, int mode, __u32 uid,
1858 __u32 gid, __u32 cap_effective, __u64 rdev,
1859 struct ptlrpc_request **request)
1863 EXP_CHECK_MD_OP(exp, create);
1864 EXP_MD_COUNTER_INCREMENT(exp, create);
1865 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1866 uid, gid, cap_effective, rdev, request);
1870 static inline int md_done_writing(struct obd_export *exp,
1871 struct md_op_data *op_data,
1872 struct md_open_data *mod)
1876 EXP_CHECK_MD_OP(exp, done_writing);
1877 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1878 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1882 static inline int md_enqueue(struct obd_export *exp,
1883 struct ldlm_enqueue_info *einfo,
1884 struct lookup_intent *it,
1885 struct md_op_data *op_data,
1886 struct lustre_handle *lockh,
1887 void *lmm, int lmmsize,
1888 struct ptlrpc_request **req,
1889 int extra_lock_flags)
1893 EXP_CHECK_MD_OP(exp, enqueue);
1894 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1895 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1896 lmm, lmmsize, req, extra_lock_flags);
1900 static inline int md_getattr_name(struct obd_export *exp,
1901 const struct lu_fid *fid, struct obd_capa *oc,
1902 const char *name, int namelen,
1903 obd_valid valid, int ea_size, __u32 suppgid,
1904 struct ptlrpc_request **request)
1908 EXP_CHECK_MD_OP(exp, getattr_name);
1909 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1910 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1911 valid, ea_size, suppgid, request);
1915 static inline int md_intent_lock(struct obd_export *exp,
1916 struct md_op_data *op_data, void *lmm,
1917 int lmmsize, struct lookup_intent *it,
1918 int flags, struct ptlrpc_request **reqp,
1919 ldlm_blocking_callback cb_blocking,
1920 int extra_lock_flags)
1924 EXP_CHECK_MD_OP(exp, intent_lock);
1925 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1926 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1927 it, flags, reqp, cb_blocking,
1932 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1933 struct ptlrpc_request **request)
1937 EXP_CHECK_MD_OP(exp, link);
1938 EXP_MD_COUNTER_INCREMENT(exp, link);
1939 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1943 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1944 const char *old, int oldlen, const char *new,
1945 int newlen, struct ptlrpc_request **request)
1949 EXP_CHECK_MD_OP(exp, rename);
1950 EXP_MD_COUNTER_INCREMENT(exp, rename);
1951 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1956 static inline int md_is_subdir(struct obd_export *exp,
1957 const struct lu_fid *pfid,
1958 const struct lu_fid *cfid,
1959 struct ptlrpc_request **request)
1963 EXP_CHECK_MD_OP(exp, is_subdir);
1964 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1965 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1969 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1970 void *ea, int ealen, void *ea2, int ea2len,
1971 struct ptlrpc_request **request,
1972 struct md_open_data **mod)
1976 EXP_CHECK_MD_OP(exp, setattr);
1977 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1978 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1979 ea2, ea2len, request, mod);
1983 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1984 struct obd_capa *oc, struct ptlrpc_request **request)
1988 EXP_CHECK_MD_OP(exp, sync);
1989 EXP_MD_COUNTER_INCREMENT(exp, sync);
1990 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1994 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1995 struct obd_capa *oc, __u64 offset,
1997 struct ptlrpc_request **request)
2001 EXP_CHECK_MD_OP(exp, readpage);
2002 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2003 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
2007 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2008 struct ptlrpc_request **request)
2012 EXP_CHECK_MD_OP(exp, unlink);
2013 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2014 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2018 static inline int md_get_lustre_md(struct obd_export *exp,
2019 struct ptlrpc_request *req,
2020 struct obd_export *dt_exp,
2021 struct obd_export *md_exp,
2022 struct lustre_md *md)
2025 EXP_CHECK_MD_OP(exp, get_lustre_md);
2026 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2027 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2030 static inline int md_free_lustre_md(struct obd_export *exp,
2031 struct lustre_md *md)
2034 EXP_CHECK_MD_OP(exp, free_lustre_md);
2035 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2036 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2039 static inline int md_setxattr(struct obd_export *exp,
2040 const struct lu_fid *fid, struct obd_capa *oc,
2041 obd_valid valid, const char *name,
2042 const char *input, int input_size,
2043 int output_size, int flags, __u32 suppgid,
2044 struct ptlrpc_request **request)
2047 EXP_CHECK_MD_OP(exp, setxattr);
2048 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2049 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2050 input_size, output_size, flags,
2054 static inline int md_getxattr(struct obd_export *exp,
2055 const struct lu_fid *fid, struct obd_capa *oc,
2056 obd_valid valid, const char *name,
2057 const char *input, int input_size,
2058 int output_size, int flags,
2059 struct ptlrpc_request **request)
2062 EXP_CHECK_MD_OP(exp, getxattr);
2063 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2064 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2065 input_size, output_size, flags,
2069 static inline int md_set_open_replay_data(struct obd_export *exp,
2070 struct obd_client_handle *och,
2071 struct ptlrpc_request *open_req)
2074 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2075 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2076 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2079 static inline int md_clear_open_replay_data(struct obd_export *exp,
2080 struct obd_client_handle *och)
2083 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2084 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2085 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2088 static inline int md_set_lock_data(struct obd_export *exp,
2089 __u64 *lockh, void *data)
2092 EXP_CHECK_MD_OP(exp, set_lock_data);
2093 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2094 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
2097 static inline int md_cancel_unused(struct obd_export *exp,
2098 const struct lu_fid *fid,
2099 ldlm_policy_data_t *policy,
2100 ldlm_mode_t mode, int flags, void *opaque)
2105 EXP_CHECK_MD_OP(exp, cancel_unused);
2106 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2108 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2113 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2114 const struct lu_fid *fid,
2116 ldlm_policy_data_t *policy,
2118 struct lustre_handle *lockh)
2121 EXP_CHECK_MD_OP(exp, lock_match);
2122 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2123 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2124 policy, mode, lockh));
2127 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2128 int def_asize, int cookiesize)
2131 EXP_CHECK_MD_OP(exp, init_ea_size);
2132 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2133 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2137 static inline int md_get_remote_perm(struct obd_export *exp,
2138 const struct lu_fid *fid,
2139 struct obd_capa *oc, __u32 suppgid,
2140 struct ptlrpc_request **request)
2143 EXP_CHECK_MD_OP(exp, get_remote_perm);
2144 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2145 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2149 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2154 EXP_CHECK_MD_OP(exp, renew_capa);
2155 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2156 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2160 static inline int md_intent_getattr_async(struct obd_export *exp,
2161 struct md_enqueue_info *minfo,
2162 struct ldlm_enqueue_info *einfo)
2166 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2167 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2168 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2172 static inline int md_revalidate_lock(struct obd_export *exp,
2173 struct lookup_intent *it,
2178 EXP_CHECK_MD_OP(exp, revalidate_lock);
2179 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2180 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2185 /* OBD Metadata Support */
2187 extern int obd_init_caches(void);
2188 extern void obd_cleanup_caches(void);
2190 /* support routines */
2191 extern cfs_mem_cache_t *obdo_cachep;
2193 #define OBDO_ALLOC(ptr) \
2195 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
2198 #define OBDO_FREE(ptr) \
2200 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2204 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2206 /* something here */
2209 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2211 /* something here */
2214 /* I'm as embarrassed about this as you are.
2216 * <shaver> // XXX do not look into _superhack with remaining eye
2217 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2218 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2221 extern void obd_sysctl_init (void);
2222 extern void obd_sysctl_clean (void);
2225 typedef __u8 class_uuid_t[16];
2226 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2229 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2230 int class_add_uuid(const char *uuid, __u64 nid);
2231 int class_del_uuid (const char *uuid);
2232 void class_init_uuidlist(void);
2233 void class_exit_uuidlist(void);
2236 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2237 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2240 void ll_generate_random_uuid(class_uuid_t uuid_out);
2242 #endif /* __LINUX_OBD_CLASS_H */