1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 # include <liblustre.h>
30 #include <obd_support.h>
31 #include <lustre_import.h>
32 #include <lustre_net.h>
34 #include <lustre_lib.h>
35 #include <lustre/lustre_idl.h>
36 #include <lprocfs_status.h>
38 #if defined(__linux__)
39 #include <linux/obd_class.h>
40 #elif defined(__APPLE__)
41 #include <darwin/obd_class.h>
42 #elif defined(__WINNT__)
43 #include <winnt/obd_class.h>
45 #error Unsupported operating system.
48 /* OBD Device Declarations */
49 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
50 extern spinlock_t obd_dev_lock;
52 /* OBD Operations Declarations */
53 extern struct obd_device *class_conn2obd(struct lustre_handle *);
54 extern struct obd_device *class_exp2obd(struct obd_export *);
56 struct lu_device_type;
59 struct obd_export *class_conn2export(struct lustre_handle *);
60 int class_register_type(struct obd_ops *, struct md_ops *,
61 struct lprocfs_vars *, const char *nm,
62 struct lu_device_type *ldt);
63 int class_unregister_type(const char *nm);
65 struct obd_device *class_newdev(const char *type_name, const char *name);
66 void class_release_dev(struct obd_device *obd);
68 int class_name2dev(const char *name);
69 struct obd_device *class_name2obd(const char *name);
70 int class_uuid2dev(struct obd_uuid *uuid);
71 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
72 void class_obd_list(void);
73 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
74 const char * typ_name,
75 struct obd_uuid *grp_uuid);
76 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
77 struct obd_uuid *grp_uuid);
78 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
80 struct obd_device * class_num2obd(int num);
82 int oig_init(struct obd_io_group **oig);
83 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
84 void oig_complete_one(struct obd_io_group *oig,
85 struct oig_callback_context *occ, int rc);
86 void oig_release(struct obd_io_group *oig);
87 int oig_wait(struct obd_io_group *oig);
89 char *obd_export_nid2str(struct obd_export *exp);
91 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
92 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
95 int class_process_config(struct lustre_cfg *lcfg);
96 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
97 struct lustre_cfg *lcfg, void *data);
98 int class_attach(struct lustre_cfg *lcfg);
99 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
100 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
101 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
102 struct obd_device *class_incref(struct obd_device *obd);
103 void class_decref(struct obd_device *obd);
105 #define CFG_F_START 0x01 /* Set when we start updating from a log */
106 #define CFG_F_MARKER 0x02 /* We are within a maker */
107 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
108 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
109 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
111 /* Passed as data param to class_config_parse_llog */
112 struct config_llog_instance {
114 struct super_block *cfg_sb;
115 struct obd_uuid cfg_uuid;
116 int cfg_last_idx; /* for partial llog processing */
119 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
120 struct config_llog_instance *cfg);
121 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
122 struct config_llog_instance *cfg);
124 /* list of active configuration logs */
125 struct config_llog_data {
127 struct ldlm_res_id cld_resid;
128 struct config_llog_instance cld_cfg;
129 struct list_head cld_list_chain;
130 atomic_t cld_refcount;
131 struct obd_export *cld_mgcexp;
132 unsigned int cld_stopping:1, /* we were told to stop watching */
133 cld_lostlock:1; /* lock not requeued */
136 struct lustre_profile {
137 struct list_head lp_list;
143 struct lustre_profile *class_get_profile(const char * prof);
144 void class_del_profile(const char *prof);
145 void class_del_profiles(void);
147 #define class_export_rpc_get(exp) \
149 atomic_inc(&(exp)->exp_rpc_count); \
150 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
151 (exp), atomic_read(&(exp)->exp_rpc_count)); \
152 class_export_get(exp); \
155 #define class_export_rpc_put(exp) \
157 atomic_dec(&(exp)->exp_rpc_count); \
158 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
159 (exp), atomic_read(&(exp)->exp_rpc_count)); \
160 class_export_put(exp); \
164 #define class_export_get(exp) \
166 struct obd_export *exp_ = exp; \
167 atomic_inc(&exp_->exp_refcount); \
168 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
169 atomic_read(&exp_->exp_refcount)); \
173 #define class_export_put(exp) \
175 LASSERT((exp) != NULL); \
176 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
177 atomic_read(&(exp)->exp_refcount) - 1); \
178 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
179 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
180 __class_export_put(exp); \
183 void __class_export_put(struct obd_export *);
184 struct obd_export *class_new_export(struct obd_device *obddev,
185 struct obd_uuid *cluuid);
186 void class_unlink_export(struct obd_export *exp);
188 struct obd_import *class_import_get(struct obd_import *);
189 void class_import_put(struct obd_import *);
190 struct obd_import *class_new_import(struct obd_device *obd);
191 void class_destroy_import(struct obd_import *exp);
193 struct obd_type *class_search_type(const char *name);
194 struct obd_type *class_get_type(const char *name);
195 void class_put_type(struct obd_type *type);
196 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
197 struct obd_uuid *cluuid);
198 int class_disconnect(struct obd_export *exp);
199 void class_fail_export(struct obd_export *exp);
200 void class_disconnect_exports(struct obd_device *obddev);
201 int class_disconnect_stale_exports(struct obd_device *,
202 int (*test_export)(struct obd_export *));
203 int class_manual_cleanup(struct obd_device *obd);
205 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
206 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
207 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
208 unsigned int ia_valid);
209 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
210 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
211 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
214 #define OBT(dev) (dev)->obd_type
215 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
216 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
217 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
219 /* Ensure obd_setup: used for cleanup which must be called
220 while obd is stopping */
221 #define OBD_CHECK_DEV(obd) \
224 CERROR("NULL device\n"); \
229 /* ensure obd_setup and !obd_stopping */
230 #define OBD_CHECK_DEV_ACTIVE(obd) \
232 OBD_CHECK_DEV(obd); \
233 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
234 CERROR("Device %d not setup\n", \
242 #define OBD_COUNTER_OFFSET(op) \
243 ((offsetof(struct obd_ops, o_ ## op) - \
244 offsetof(struct obd_ops, o_iocontrol)) \
245 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
247 #define OBD_COUNTER_INCREMENT(obdx, op) \
248 if ((obdx)->obd_stats != NULL) { \
249 unsigned int coffset; \
250 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
251 OBD_COUNTER_OFFSET(op); \
252 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
253 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
256 #define EXP_COUNTER_INCREMENT(export, op) \
257 if ((export)->exp_obd->obd_stats != NULL) { \
258 unsigned int coffset; \
259 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
260 OBD_COUNTER_OFFSET(op); \
261 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
262 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
263 if ((export)->exp_ops_stats != NULL) \
264 lprocfs_counter_incr( \
265 (export)->exp_ops_stats, coffset); \
268 #define MD_COUNTER_OFFSET(op) \
269 ((offsetof(struct md_ops, m_ ## op) - \
270 offsetof(struct md_ops, m_getstatus)) \
271 / sizeof(((struct md_ops *)(0))->m_getstatus))
273 #define MD_COUNTER_INCREMENT(obdx, op) \
274 if ((obd)->md_stats != NULL) { \
275 unsigned int coffset; \
276 coffset = (unsigned int)((obdx)->md_cntr_base) + \
277 MD_COUNTER_OFFSET(op); \
278 LASSERT(coffset < (obdx)->md_stats->ls_num); \
279 lprocfs_counter_incr((obdx)->md_stats, coffset); \
282 #define EXP_MD_COUNTER_INCREMENT(export, op) \
283 if ((export)->exp_obd->obd_stats != NULL) { \
284 unsigned int coffset; \
285 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
286 MD_COUNTER_OFFSET(op); \
287 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
288 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
289 if ((export)->exp_md_stats != NULL) \
290 lprocfs_counter_incr( \
291 (export)->exp_md_stats, coffset); \
295 #define OBD_COUNTER_OFFSET(op)
296 #define OBD_COUNTER_INCREMENT(obd, op)
297 #define EXP_COUNTER_INCREMENT(exp, op)
298 #define MD_COUNTER_INCREMENT(obd, op)
299 #define EXP_MD_COUNTER_INCREMENT(exp, op)
302 #define OBD_CHECK_MD_OP(obd, op, err) \
304 if (!OBT(obd) || !MDP((obd), op)) { \
306 CERROR("md_" #op ": dev %s/%d no operation\n", \
307 obd->obd_name, obd->obd_minor); \
312 #define EXP_CHECK_MD_OP(exp, op) \
314 if ((exp) == NULL) { \
315 CERROR("obd_" #op ": NULL export\n"); \
318 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
319 CERROR("obd_" #op ": cleaned up obd\n"); \
320 RETURN(-EOPNOTSUPP); \
322 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
323 CERROR("obd_" #op ": dev %s/%d no operation\n", \
324 (exp)->exp_obd->obd_name, \
325 (exp)->exp_obd->obd_minor); \
326 RETURN(-EOPNOTSUPP); \
331 #define OBD_CHECK_DT_OP(obd, op, err) \
333 if (!OBT(obd) || !OBP((obd), op)) { \
335 CERROR("obd_" #op ": dev %d no operation\n", \
341 #define EXP_CHECK_DT_OP(exp, op) \
343 if ((exp) == NULL) { \
344 CERROR("obd_" #op ": NULL export\n"); \
347 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
348 CERROR("obd_" #op ": cleaned up obd\n"); \
349 RETURN(-EOPNOTSUPP); \
351 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
352 CERROR("obd_" #op ": dev %d no operation\n", \
353 (exp)->exp_obd->obd_minor); \
354 RETURN(-EOPNOTSUPP); \
358 #define CTXT_CHECK_OP(ctxt, op, err) \
360 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
362 CERROR("lop_" #op ": dev %d no operation\n", \
363 ctxt->loc_obd->obd_minor); \
368 static inline int class_devno_max(void)
370 return MAX_OBD_DEVICES;
373 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
374 void *key, __u32 *vallen, void *val)
379 EXP_CHECK_DT_OP(exp, get_info);
380 EXP_COUNTER_INCREMENT(exp, get_info);
382 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
386 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
387 void *key, obd_count vallen, void *val,
388 struct ptlrpc_request_set *set)
393 EXP_CHECK_DT_OP(exp, set_info_async);
394 EXP_COUNTER_INCREMENT(exp, set_info_async);
396 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
402 #define DECLARE_LU_VARS(ldt, d) \
403 struct lu_device_type *ldt; \
406 #define DECLARE_LU_VARS(ldt, d) \
407 extern void __placeholder_to_put_a_semicolon(void)
409 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
412 DECLARE_LU_VARS(ldt, d);
416 ldt = obd->obd_type->typ_lu;
420 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
422 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
434 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
435 OBD_COUNTER_INCREMENT(obd, setup);
436 rc = OBP(obd, setup)(obd, cfg);
441 static inline int obd_precleanup(struct obd_device *obd,
442 enum obd_cleanup_stage cleanup_stage)
445 DECLARE_LU_VARS(ldt, d);
450 ldt = obd->obd_type->typ_lu;
454 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
457 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
459 ldt->ldt_ops->ldto_device_fini(&env, d);
468 OBD_CHECK_DT_OP(obd, precleanup, 0);
469 rc = OBP(obd, precleanup)(obd, cleanup_stage);
472 OBD_COUNTER_INCREMENT(obd, precleanup);
476 static inline int obd_cleanup(struct obd_device *obd)
479 DECLARE_LU_VARS(ldt, d);
485 ldt = obd->obd_type->typ_lu;
491 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
493 ldt->ldt_ops->ldto_device_free(&env, d);
495 obd->obd_lu_dev = NULL;
500 OBD_CHECK_DT_OP(obd, cleanup, 0);
501 rc = OBP(obd, cleanup)(obd);
503 OBD_COUNTER_INCREMENT(obd, cleanup);
508 obd_process_config(struct obd_device *obd, int datalen, void *data)
511 DECLARE_LU_VARS(ldt, d);
517 ldt = obd->obd_type->typ_lu;
519 if (ldt != NULL && d != NULL) {
522 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
524 rc = d->ld_ops->ldo_process_config(&env, d, data);
530 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
531 rc = OBP(obd, process_config)(obd, datalen, data);
533 OBD_COUNTER_INCREMENT(obd, process_config);
538 /* Pack an in-memory MD struct for storage on disk.
539 * Returns +ve size of packed MD (0 for free), or -ve error.
541 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
542 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
543 * If @*disk_tgt == NULL, it will be allocated
545 static inline int obd_packmd(struct obd_export *exp,
546 struct lov_mds_md **disk_tgt,
547 struct lov_stripe_md *mem_src)
552 EXP_CHECK_DT_OP(exp, packmd);
553 EXP_COUNTER_INCREMENT(exp, packmd);
555 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
559 static inline int obd_size_diskmd(struct obd_export *exp,
560 struct lov_stripe_md *mem_src)
562 return obd_packmd(exp, NULL, mem_src);
565 /* helper functions */
566 static inline int obd_alloc_diskmd(struct obd_export *exp,
567 struct lov_mds_md **disk_tgt)
570 LASSERT(*disk_tgt == NULL);
571 return obd_packmd(exp, disk_tgt, NULL);
574 static inline int obd_free_diskmd(struct obd_export *exp,
575 struct lov_mds_md **disk_tgt)
579 return obd_packmd(exp, disk_tgt, NULL);
582 /* Unpack an MD struct from disk to in-memory format.
583 * Returns +ve size of unpacked MD (0 for free), or -ve error.
585 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
586 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
587 * If @*mem_tgt == NULL, it will be allocated
589 static inline int obd_unpackmd(struct obd_export *exp,
590 struct lov_stripe_md **mem_tgt,
591 struct lov_mds_md *disk_src,
597 EXP_CHECK_DT_OP(exp, unpackmd);
598 EXP_COUNTER_INCREMENT(exp, unpackmd);
600 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
604 /* helper functions */
605 static inline int obd_alloc_memmd(struct obd_export *exp,
606 struct lov_stripe_md **mem_tgt)
609 LASSERT(*mem_tgt == NULL);
610 return obd_unpackmd(exp, mem_tgt, NULL, 0);
613 static inline int obd_free_memmd(struct obd_export *exp,
614 struct lov_stripe_md **mem_tgt)
618 return obd_unpackmd(exp, mem_tgt, NULL, 0);
621 static inline int obd_checkmd(struct obd_export *exp,
622 struct obd_export *md_exp,
623 struct lov_stripe_md *mem_tgt)
628 EXP_CHECK_DT_OP(exp, checkmd);
629 EXP_COUNTER_INCREMENT(exp, checkmd);
631 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
635 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
636 struct lov_stripe_md **ea,
637 struct obd_trans_info *oti)
642 EXP_CHECK_DT_OP(exp, create);
643 EXP_COUNTER_INCREMENT(exp, create);
645 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
649 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
650 struct lov_stripe_md *ea,
651 struct obd_trans_info *oti,
652 struct obd_export *md_exp)
657 EXP_CHECK_DT_OP(exp, destroy);
658 EXP_COUNTER_INCREMENT(exp, destroy);
660 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
664 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
669 EXP_CHECK_DT_OP(exp, getattr);
670 EXP_COUNTER_INCREMENT(exp, getattr);
672 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
676 static inline int obd_getattr_async(struct obd_export *exp,
677 struct obd_info *oinfo,
678 struct ptlrpc_request_set *set)
683 EXP_CHECK_DT_OP(exp, getattr_async);
684 EXP_COUNTER_INCREMENT(exp, getattr_async);
686 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
690 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
691 struct obd_trans_info *oti)
696 EXP_CHECK_DT_OP(exp, setattr);
697 EXP_COUNTER_INCREMENT(exp, setattr);
699 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
703 /* This performs all the requests set init/wait/destroy actions. */
704 static inline int obd_setattr_rqset(struct obd_export *exp,
705 struct obd_info *oinfo,
706 struct obd_trans_info *oti)
708 struct ptlrpc_request_set *set = NULL;
712 EXP_CHECK_DT_OP(exp, setattr_async);
713 EXP_COUNTER_INCREMENT(exp, setattr_async);
715 set = ptlrpc_prep_set();
719 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
721 rc = ptlrpc_set_wait(set);
722 ptlrpc_set_destroy(set);
726 /* This adds all the requests into @set if @set != NULL, otherwise
727 all requests are sent asynchronously without waiting for response. */
728 static inline int obd_setattr_async(struct obd_export *exp,
729 struct obd_info *oinfo,
730 struct obd_trans_info *oti,
731 struct ptlrpc_request_set *set)
736 EXP_CHECK_DT_OP(exp, setattr_async);
737 EXP_COUNTER_INCREMENT(exp, setattr_async);
739 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
743 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
746 struct obd_device *obd = imp->imp_obd;
750 OBD_CHECK_DEV_ACTIVE(obd);
751 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
752 OBD_COUNTER_INCREMENT(obd, add_conn);
754 rc = OBP(obd, add_conn)(imp, uuid, priority);
758 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
760 struct obd_device *obd = imp->imp_obd;
764 OBD_CHECK_DEV_ACTIVE(obd);
765 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
766 OBD_COUNTER_INCREMENT(obd, del_conn);
768 rc = OBP(obd, del_conn)(imp, uuid);
772 static inline int obd_connect(const struct lu_env *env,
773 struct lustre_handle *conn,struct obd_device *obd,
774 struct obd_uuid *cluuid,
775 struct obd_connect_data *d)
779 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
784 OBD_CHECK_DEV_ACTIVE(obd);
785 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
786 OBD_COUNTER_INCREMENT(obd, connect);
788 rc = OBP(obd, connect)(env, conn, obd, cluuid, d);
789 /* check that only subset is granted */
790 LASSERT(ergo(d != NULL,
791 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
795 static inline int obd_reconnect(struct obd_export *exp,
796 struct obd_device *obd,
797 struct obd_uuid *cluuid,
798 struct obd_connect_data *d)
802 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
808 OBD_CHECK_DEV_ACTIVE(obd);
809 OBD_CHECK_DT_OP(obd, reconnect, 0);
810 OBD_COUNTER_INCREMENT(obd, reconnect);
812 rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
813 /* check that only subset is granted */
814 LASSERT(ergo(d != NULL,
815 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
819 static inline int obd_disconnect(struct obd_export *exp)
824 EXP_CHECK_DT_OP(exp, disconnect);
825 EXP_COUNTER_INCREMENT(exp, disconnect);
827 rc = OBP(exp->exp_obd, disconnect)(exp);
831 static inline int obd_fid_init(struct obd_export *exp)
836 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
837 EXP_COUNTER_INCREMENT(exp, fid_init);
839 rc = OBP(exp->exp_obd, fid_init)(exp);
843 static inline int obd_fid_fini(struct obd_export *exp)
848 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
849 EXP_COUNTER_INCREMENT(exp, fid_fini);
851 rc = OBP(exp->exp_obd, fid_fini)(exp);
855 static inline int obd_fid_alloc(struct obd_export *exp,
857 struct md_op_data *op_data)
862 EXP_CHECK_DT_OP(exp, fid_alloc);
863 EXP_COUNTER_INCREMENT(exp, fid_alloc);
865 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
869 static inline int obd_fid_delete(struct obd_export *exp,
870 const struct lu_fid *fid)
875 EXP_CHECK_DT_OP(exp, fid_delete);
876 EXP_COUNTER_INCREMENT(exp, fid_delete);
878 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
882 static inline int obd_ping(struct obd_export *exp)
887 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
888 EXP_COUNTER_INCREMENT(exp, ping);
890 rc = OBP(exp->exp_obd, ping)(exp);
894 static inline int obd_init_export(struct obd_export *exp)
899 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
900 OBP((exp)->exp_obd, init_export))
901 rc = OBP(exp->exp_obd, init_export)(exp);
905 static inline int obd_destroy_export(struct obd_export *exp)
908 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
909 OBP((exp)->exp_obd, destroy_export))
910 OBP(exp->exp_obd, destroy_export)(exp);
914 static inline int obd_extent_calc(struct obd_export *exp,
915 struct lov_stripe_md *md,
916 int cmd, obd_off *offset)
920 EXP_CHECK_DT_OP(exp, extent_calc);
921 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
925 static inline struct dentry *
926 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
928 LASSERT(exp->exp_obd);
930 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
935 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
937 LASSERT(exp->exp_obd);
938 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
940 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
941 dentry, exp->exp_obd);
947 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
950 /* @max_age is the oldest time in jiffies that we accept using a cached data.
951 * If the cache is older than @max_age we will get a new value from the
952 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
953 static inline int obd_statfs_async(struct obd_device *obd,
954 struct obd_info *oinfo,
956 struct ptlrpc_request_set *rqset)
964 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
965 OBD_COUNTER_INCREMENT(obd, statfs);
967 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
968 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
969 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
970 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
972 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
973 " objects "LPU64"/"LPU64"\n",
974 obd->obd_name, &obd->obd_osfs,
975 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
976 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
977 spin_lock(&obd->obd_osfs_lock);
978 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
979 spin_unlock(&obd->obd_osfs_lock);
981 oinfo->oi_cb_up(oinfo, 0);
986 static inline int obd_statfs_rqset(struct obd_device *obd,
987 struct obd_statfs *osfs, __u64 max_age)
989 struct ptlrpc_request_set *set = NULL;
990 struct obd_info oinfo = { { { 0 } } };
994 set = ptlrpc_prep_set();
998 oinfo.oi_osfs = osfs;
999 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1001 rc = ptlrpc_set_wait(set);
1002 ptlrpc_set_destroy(set);
1006 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1007 * If the cache is older than @max_age we will get a new value from the
1008 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1009 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1018 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1019 OBD_COUNTER_INCREMENT(obd, statfs);
1021 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1022 obd->obd_osfs_age, max_age);
1023 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1024 rc = OBP(obd, statfs)(obd, osfs, max_age);
1026 spin_lock(&obd->obd_osfs_lock);
1027 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1028 obd->obd_osfs_age = cfs_time_current_64();
1029 spin_unlock(&obd->obd_osfs_lock);
1032 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1033 " objects "LPU64"/"LPU64"\n",
1034 obd->obd_name, &obd->obd_osfs,
1035 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1036 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1037 spin_lock(&obd->obd_osfs_lock);
1038 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1039 spin_unlock(&obd->obd_osfs_lock);
1044 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1045 struct lov_stripe_md *ea, obd_size start,
1046 obd_size end, void *capa)
1051 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1052 EXP_COUNTER_INCREMENT(exp, sync);
1054 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1058 static inline int obd_punch_rqset(struct obd_export *exp,
1059 struct obd_info *oinfo,
1060 struct obd_trans_info *oti)
1062 struct ptlrpc_request_set *set = NULL;
1066 EXP_CHECK_DT_OP(exp, punch);
1067 EXP_COUNTER_INCREMENT(exp, punch);
1069 set = ptlrpc_prep_set();
1073 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1075 rc = ptlrpc_set_wait(set);
1076 ptlrpc_set_destroy(set);
1080 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1081 struct obd_trans_info *oti,
1082 struct ptlrpc_request_set *rqset)
1087 EXP_CHECK_DT_OP(exp, punch);
1088 EXP_COUNTER_INCREMENT(exp, punch);
1090 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1094 static inline int obd_brw(int cmd, struct obd_export *exp,
1095 struct obd_info *oinfo, obd_count oa_bufs,
1096 struct brw_page *pg, struct obd_trans_info *oti)
1101 EXP_CHECK_DT_OP(exp, brw);
1102 EXP_COUNTER_INCREMENT(exp, brw);
1104 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1105 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1106 "or OBD_BRW_CHECK\n");
1110 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1114 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1115 struct obd_info *oinfo, obd_count oa_bufs,
1116 struct brw_page *pg, struct obd_trans_info *oti,
1117 struct ptlrpc_request_set *set)
1122 EXP_CHECK_DT_OP(exp, brw_async);
1123 EXP_COUNTER_INCREMENT(exp, brw_async);
1125 if (!(cmd & OBD_BRW_RWMASK)) {
1126 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1130 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1134 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1135 struct obdo *oa, struct lov_stripe_md *lsm,
1136 obd_count oa_bufs, struct brw_page *pg,
1137 struct obd_trans_info *oti,
1138 struct obd_capa *ocapa)
1140 struct ptlrpc_request_set *set = NULL;
1141 struct obd_info oinfo = { { { 0 } } };
1146 set = ptlrpc_prep_set();
1149 atomic_set(&nob, 0);
1150 set->set_countp = &nob;
1154 oinfo.oi_capa = ocapa;
1155 rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1157 rc = ptlrpc_set_wait(set);
1159 CERROR("error from callback: rc = %d\n", rc);
1161 rc = atomic_read(&nob);
1163 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
1164 "error from obd_brw_async: rc = %d\n", rc);
1166 ptlrpc_set_destroy(set);
1170 static inline int obd_prep_async_page(struct obd_export *exp,
1171 struct lov_stripe_md *lsm,
1172 struct lov_oinfo *loi,
1173 cfs_page_t *page, obd_off offset,
1174 struct obd_async_page_ops *ops,
1175 void *data, void **res)
1180 EXP_CHECK_DT_OP(exp, prep_async_page);
1181 EXP_COUNTER_INCREMENT(exp, prep_async_page);
1183 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1188 static inline int obd_queue_async_io(struct obd_export *exp,
1189 struct lov_stripe_md *lsm,
1190 struct lov_oinfo *loi, void *cookie,
1191 int cmd, obd_off off, int count,
1192 obd_flag brw_flags, obd_flag async_flags)
1197 EXP_CHECK_DT_OP(exp, queue_async_io);
1198 EXP_COUNTER_INCREMENT(exp, queue_async_io);
1199 LASSERT(cmd & OBD_BRW_RWMASK);
1201 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1202 count, brw_flags, async_flags);
1206 static inline int obd_set_async_flags(struct obd_export *exp,
1207 struct lov_stripe_md *lsm,
1208 struct lov_oinfo *loi, void *cookie,
1209 obd_flag async_flags)
1214 EXP_CHECK_DT_OP(exp, set_async_flags);
1215 EXP_COUNTER_INCREMENT(exp, set_async_flags);
1217 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1222 static inline int obd_queue_group_io(struct obd_export *exp,
1223 struct lov_stripe_md *lsm,
1224 struct lov_oinfo *loi,
1225 struct obd_io_group *oig,
1226 void *cookie, int cmd, obd_off off,
1227 int count, obd_flag brw_flags,
1228 obd_flag async_flags)
1233 EXP_CHECK_DT_OP(exp, queue_group_io);
1234 EXP_COUNTER_INCREMENT(exp, queue_group_io);
1235 LASSERT(cmd & OBD_BRW_RWMASK);
1237 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1238 cmd, off, count, brw_flags,
1243 static inline int obd_trigger_group_io(struct obd_export *exp,
1244 struct lov_stripe_md *lsm,
1245 struct lov_oinfo *loi,
1246 struct obd_io_group *oig)
1251 EXP_CHECK_DT_OP(exp, trigger_group_io);
1252 EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1254 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1258 static inline int obd_teardown_async_page(struct obd_export *exp,
1259 struct lov_stripe_md *lsm,
1260 struct lov_oinfo *loi, void *cookie)
1265 EXP_CHECK_DT_OP(exp, teardown_async_page);
1266 EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1268 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1272 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1273 int objcount, struct obd_ioobj *obj,
1274 int niocount, struct niobuf_remote *remote,
1275 struct niobuf_local *local,
1276 struct obd_trans_info *oti,
1277 struct lustre_capa *capa)
1282 EXP_CHECK_DT_OP(exp, preprw);
1283 EXP_COUNTER_INCREMENT(exp, preprw);
1285 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1286 remote, local, oti, capa);
1290 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1291 int objcount, struct obd_ioobj *obj,
1292 int niocount, struct niobuf_local *local,
1293 struct obd_trans_info *oti, int rc)
1297 EXP_CHECK_DT_OP(exp, commitrw);
1298 EXP_COUNTER_INCREMENT(exp, commitrw);
1300 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1305 static inline int obd_merge_lvb(struct obd_export *exp,
1306 struct lov_stripe_md *lsm,
1307 struct ost_lvb *lvb, int kms_only)
1312 EXP_CHECK_DT_OP(exp, merge_lvb);
1313 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1315 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1319 static inline int obd_adjust_kms(struct obd_export *exp,
1320 struct lov_stripe_md *lsm, obd_off size,
1326 EXP_CHECK_DT_OP(exp, adjust_kms);
1327 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1329 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1333 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1334 int len, void *karg, void *uarg)
1339 EXP_CHECK_DT_OP(exp, iocontrol);
1340 EXP_COUNTER_INCREMENT(exp, iocontrol);
1342 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1346 static inline int obd_enqueue_rqset(struct obd_export *exp,
1347 struct obd_info *oinfo,
1348 struct obd_enqueue_info *einfo)
1353 EXP_CHECK_DT_OP(exp, enqueue);
1354 EXP_COUNTER_INCREMENT(exp, enqueue);
1356 einfo->ei_rqset = ptlrpc_prep_set();
1357 if (einfo->ei_rqset == NULL)
1360 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1362 rc = ptlrpc_set_wait(einfo->ei_rqset);
1363 ptlrpc_set_destroy(einfo->ei_rqset);
1364 einfo->ei_rqset = NULL;
1369 static inline int obd_enqueue(struct obd_export *exp,
1370 struct obd_info *oinfo,
1371 struct obd_enqueue_info *einfo)
1376 EXP_CHECK_DT_OP(exp, enqueue);
1377 EXP_COUNTER_INCREMENT(exp, enqueue);
1379 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1383 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1384 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1385 int *flags, void *data, struct lustre_handle *lockh)
1390 EXP_CHECK_DT_OP(exp, match);
1391 EXP_COUNTER_INCREMENT(exp, match);
1393 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1398 static inline int obd_change_cbdata(struct obd_export *exp,
1399 struct lov_stripe_md *lsm,
1400 ldlm_iterator_t it, void *data)
1405 EXP_CHECK_DT_OP(exp, change_cbdata);
1406 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1408 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1412 static inline int obd_cancel(struct obd_export *exp,
1413 struct lov_stripe_md *ea, __u32 mode,
1414 struct lustre_handle *lockh)
1419 EXP_CHECK_DT_OP(exp, cancel);
1420 EXP_COUNTER_INCREMENT(exp, cancel);
1422 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1426 static inline int obd_cancel_unused(struct obd_export *exp,
1427 struct lov_stripe_md *ea,
1428 int flags, void *opaque)
1433 EXP_CHECK_DT_OP(exp, cancel_unused);
1434 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1436 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1440 static inline int obd_join_lru(struct obd_export *exp,
1441 struct lov_stripe_md *ea, int join)
1446 EXP_CHECK_DT_OP(exp, join_lru);
1447 EXP_COUNTER_INCREMENT(exp, join_lru);
1449 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1453 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1454 struct obd_capa *oc, struct obd_client_handle *handle,
1460 EXP_CHECK_DT_OP(exp, pin);
1461 EXP_COUNTER_INCREMENT(exp, pin);
1463 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1467 static inline int obd_unpin(struct obd_export *exp,
1468 struct obd_client_handle *handle, int flag)
1473 EXP_CHECK_DT_OP(exp, unpin);
1474 EXP_COUNTER_INCREMENT(exp, unpin);
1476 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1481 static inline void obd_import_event(struct obd_device *obd,
1482 struct obd_import *imp,
1483 enum obd_import_event event)
1487 CERROR("NULL device\n");
1491 if (obd->obd_set_up && OBP(obd, import_event)) {
1492 OBD_COUNTER_INCREMENT(obd, import_event);
1493 OBP(obd, import_event)(obd, imp, event);
1498 static inline int obd_llog_connect(struct obd_export *exp,
1499 struct llogd_conn_body *body)
1504 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1505 EXP_COUNTER_INCREMENT(exp, llog_connect);
1507 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1512 static inline int obd_notify(struct obd_device *obd,
1513 struct obd_device *watched,
1514 enum obd_notify_event ev,
1521 /* the check for async_recov is a complete hack - I'm hereby
1522 overloading the meaning to also mean "this was called from
1523 mds_postsetup". I know that my mds is able to handle notifies
1524 by this point, and it needs to get them to execute mds_postrecov. */
1525 if (!obd->obd_set_up && !obd->obd_async_recov) {
1526 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1530 if (!OBP(obd, notify)) {
1531 CERROR("obd %s has no notify handler\n", obd->obd_name);
1535 OBD_COUNTER_INCREMENT(obd, notify);
1536 rc = OBP(obd, notify)(obd, watched, ev, data);
1540 static inline int obd_notify_observer(struct obd_device *observer,
1541 struct obd_device *observed,
1542 enum obd_notify_event ev,
1548 struct obd_notify_upcall *onu;
1550 if (observer->obd_observer)
1551 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1555 * Also, call non-obd listener, if any
1557 onu = &observer->obd_upcall;
1558 if (onu->onu_upcall != NULL)
1559 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1563 return rc1 ? rc1 : rc2;
1566 static inline int obd_quotacheck(struct obd_export *exp,
1567 struct obd_quotactl *oqctl)
1572 EXP_CHECK_DT_OP(exp, quotacheck);
1573 EXP_COUNTER_INCREMENT(exp, quotacheck);
1575 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1579 static inline int obd_quotactl(struct obd_export *exp,
1580 struct obd_quotactl *oqctl)
1585 EXP_CHECK_DT_OP(exp, quotactl);
1586 EXP_COUNTER_INCREMENT(exp, quotactl);
1588 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1592 static inline int obd_health_check(struct obd_device *obd)
1594 /* returns: 0 on healthy
1595 * >0 on unhealthy + reason code/flag
1596 * however the only suppored reason == 1 right now
1597 * We'll need to define some better reasons
1598 * or flags in the future.
1604 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1605 if (obd == NULL || !OBT(obd)) {
1606 CERROR("cleaned up obd\n");
1607 RETURN(-EOPNOTSUPP);
1609 if (!obd->obd_set_up || obd->obd_stopping)
1611 if (!OBP(obd, health_check))
1614 rc = OBP(obd, health_check)(obd);
1618 static inline int obd_register_observer(struct obd_device *obd,
1619 struct obd_device *observer)
1623 if (obd->obd_observer && observer)
1625 obd->obd_observer = observer;
1629 /* metadata helpers */
1630 static inline int md_getstatus(struct obd_export *exp,
1631 struct lu_fid *fid, struct obd_capa **pc)
1636 EXP_CHECK_MD_OP(exp, getstatus);
1637 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1638 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1642 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1643 struct obd_capa *oc, obd_valid valid, int ea_size,
1644 struct ptlrpc_request **request)
1648 EXP_CHECK_MD_OP(exp, getattr);
1649 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1650 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1655 static inline int md_change_cbdata(struct obd_export *exp,
1656 const struct lu_fid *fid,
1657 ldlm_iterator_t it, void *data)
1661 EXP_CHECK_MD_OP(exp, change_cbdata);
1662 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1663 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1667 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1668 struct obd_client_handle *och,
1669 struct ptlrpc_request **request)
1673 EXP_CHECK_MD_OP(exp, close);
1674 EXP_MD_COUNTER_INCREMENT(exp, close);
1675 rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1679 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1680 const void *data, int datalen, int mode, __u32 uid,
1681 __u32 gid, __u32 cap_effective, __u64 rdev,
1682 struct ptlrpc_request **request)
1686 EXP_CHECK_MD_OP(exp, create);
1687 EXP_MD_COUNTER_INCREMENT(exp, create);
1688 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1689 uid, gid, cap_effective, rdev, request);
1693 static inline int md_done_writing(struct obd_export *exp,
1694 struct md_op_data *op_data,
1695 struct obd_client_handle *och)
1699 EXP_CHECK_MD_OP(exp, done_writing);
1700 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1701 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, och);
1705 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1706 struct lookup_intent *it, int lock_mode,
1707 struct md_op_data *op_data,
1708 struct lustre_handle *lockh,
1709 void *lmm, int lmmsize,
1710 ldlm_completion_callback cb_completion,
1711 ldlm_blocking_callback cb_blocking,
1712 void *cb_data, int extra_lock_flags)
1716 EXP_CHECK_MD_OP(exp, enqueue);
1717 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1718 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1719 op_data, lockh, lmm, lmmsize,
1720 cb_completion, cb_blocking,
1721 cb_data, extra_lock_flags);
1725 static inline int md_getattr_name(struct obd_export *exp,
1726 const struct lu_fid *fid, struct obd_capa *oc,
1727 const char *name, int namelen,
1728 obd_valid valid, int ea_size,
1729 struct ptlrpc_request **request)
1733 EXP_CHECK_MD_OP(exp, getattr_name);
1734 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1735 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1736 valid, ea_size, request);
1740 static inline int md_intent_lock(struct obd_export *exp,
1741 struct md_op_data *op_data, void *lmm,
1742 int lmmsize, struct lookup_intent *it,
1743 int flags, struct ptlrpc_request **reqp,
1744 ldlm_blocking_callback cb_blocking,
1745 int extra_lock_flags)
1749 EXP_CHECK_MD_OP(exp, intent_lock);
1750 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1751 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1752 it, flags, reqp, cb_blocking,
1757 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1758 struct ptlrpc_request **request)
1762 EXP_CHECK_MD_OP(exp, link);
1763 EXP_MD_COUNTER_INCREMENT(exp, link);
1764 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1768 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1769 const char *old, int oldlen, const char *new,
1770 int newlen, struct ptlrpc_request **request)
1774 EXP_CHECK_MD_OP(exp, rename);
1775 EXP_MD_COUNTER_INCREMENT(exp, rename);
1776 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1781 static inline int md_is_subdir(struct obd_export *exp,
1782 const struct lu_fid *pfid,
1783 const struct lu_fid *cfid,
1784 struct ptlrpc_request **request)
1788 EXP_CHECK_MD_OP(exp, is_subdir);
1789 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1790 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1794 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1795 void *ea, int ealen, void *ea2, int ea2len,
1796 struct ptlrpc_request **request)
1800 EXP_CHECK_MD_OP(exp, setattr);
1801 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1802 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1803 ea2, ea2len, request);
1807 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1808 struct obd_capa *oc, struct ptlrpc_request **request)
1812 EXP_CHECK_MD_OP(exp, sync);
1813 EXP_MD_COUNTER_INCREMENT(exp, sync);
1814 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1818 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1819 struct obd_capa *oc, __u64 offset,
1821 struct ptlrpc_request **request)
1825 EXP_CHECK_MD_OP(exp, readpage);
1826 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1827 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1831 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1832 struct ptlrpc_request **request)
1836 EXP_CHECK_MD_OP(exp, unlink);
1837 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1838 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1842 static inline int md_get_lustre_md(struct obd_export *exp,
1843 struct ptlrpc_request *req,
1844 int offset, struct obd_export *dt_exp,
1845 struct obd_export *md_exp,
1846 struct lustre_md *md)
1849 EXP_CHECK_MD_OP(exp, get_lustre_md);
1850 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1851 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1852 dt_exp, md_exp, md));
1855 static inline int md_free_lustre_md(struct obd_export *exp,
1856 struct lustre_md *md)
1859 EXP_CHECK_MD_OP(exp, free_lustre_md);
1860 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1861 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1864 static inline int md_setxattr(struct obd_export *exp,
1865 const struct lu_fid *fid, struct obd_capa *oc,
1866 obd_valid valid, const char *name,
1867 const char *input, int input_size,
1868 int output_size, int flags,
1869 struct ptlrpc_request **request)
1872 EXP_CHECK_MD_OP(exp, setxattr);
1873 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1874 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1875 input_size, output_size, flags,
1879 static inline int md_getxattr(struct obd_export *exp,
1880 const struct lu_fid *fid, struct obd_capa *oc,
1881 obd_valid valid, const char *name,
1882 const char *input, int input_size,
1883 int output_size, int flags,
1884 struct ptlrpc_request **request)
1887 EXP_CHECK_MD_OP(exp, getxattr);
1888 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1889 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1890 input_size, output_size, flags,
1894 static inline int md_set_open_replay_data(struct obd_export *exp,
1895 struct obd_client_handle *och,
1896 struct ptlrpc_request *open_req)
1899 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1900 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1901 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1904 static inline int md_clear_open_replay_data(struct obd_export *exp,
1905 struct obd_client_handle *och)
1908 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1909 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1910 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1913 static inline int md_set_lock_data(struct obd_export *exp,
1914 __u64 *lockh, void *data)
1917 EXP_CHECK_MD_OP(exp, set_lock_data);
1918 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1919 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1922 static inline int md_cancel_unused(struct obd_export *exp,
1923 const struct lu_fid *fid,
1924 ldlm_policy_data_t *policy,
1925 ldlm_mode_t mode, int flags, void *opaque)
1930 EXP_CHECK_MD_OP(exp, cancel_unused);
1931 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1933 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1938 static inline int md_lock_match(struct obd_export *exp, int flags,
1939 const struct lu_fid *fid, ldlm_type_t type,
1940 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1941 struct lustre_handle *lockh)
1944 EXP_CHECK_MD_OP(exp, lock_match);
1945 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1946 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1947 policy, mode, lockh));
1950 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1951 int def_asize, int cookiesize)
1954 EXP_CHECK_MD_OP(exp, init_ea_size);
1955 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1956 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1960 static inline int md_get_remote_perm(struct obd_export *exp,
1961 const struct lu_fid *fid,
1962 struct obd_capa *oc,
1963 struct ptlrpc_request **request)
1966 EXP_CHECK_MD_OP(exp, get_remote_perm);
1967 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1968 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, request));
1971 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1976 EXP_CHECK_MD_OP(exp, renew_capa);
1977 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1978 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1982 /* OBD Metadata Support */
1984 extern int obd_init_caches(void);
1985 extern void obd_cleanup_caches(void);
1987 /* support routines */
1988 extern cfs_mem_cache_t *obdo_cachep;
1990 #define OBDO_ALLOC(ptr) \
1992 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
1995 #define OBDO_FREE(ptr) \
1997 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2001 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2003 /* something here */
2006 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2008 /* something here */
2011 /* I'm as embarrassed about this as you are.
2013 * <shaver> // XXX do not look into _superhack with remaining eye
2014 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2015 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2018 extern void obd_sysctl_init (void);
2019 extern void obd_sysctl_clean (void);
2022 typedef __u8 class_uuid_t[16];
2023 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2026 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2027 int class_add_uuid(const char *uuid, __u64 nid);
2028 int class_del_uuid (const char *uuid);
2029 void class_init_uuidlist(void);
2030 void class_exit_uuidlist(void);
2033 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2034 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2037 void ll_generate_random_uuid(class_uuid_t uuid_out);
2039 #endif /* __LINUX_OBD_CLASS_H */