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.
26 #include <obd_support.h>
27 #include <lustre_import.h>
28 #include <lustre_net.h>
30 #include <lustre_lib.h>
31 #include <lustre/lustre_idl.h>
32 #include <lprocfs_status.h>
34 #if defined(__linux__)
35 #include <linux/obd_class.h>
36 #elif defined(__APPLE__)
37 #include <darwin/obd_class.h>
38 #elif defined(__WINNT__)
39 #include <winnt/obd_class.h>
41 #error Unsupported operating system.
44 /* OBD Device Declarations */
45 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
46 extern spinlock_t obd_dev_lock;
48 /* OBD Operations Declarations */
49 extern struct obd_device *class_conn2obd(struct lustre_handle *);
50 extern struct obd_device *class_exp2obd(struct obd_export *);
52 struct lu_device_type;
55 struct obd_export *class_conn2export(struct lustre_handle *);
56 int class_register_type(struct obd_ops *, struct md_ops *,
57 struct lprocfs_vars *, const char *nm,
58 struct lu_device_type *ldt);
59 int class_unregister_type(const char *nm);
61 struct obd_device *class_newdev(const char *type_name, const char *name);
62 void class_release_dev(struct obd_device *obd);
64 int class_name2dev(const char *name);
65 struct obd_device *class_name2obd(const char *name);
66 int class_uuid2dev(struct obd_uuid *uuid);
67 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
68 void class_obd_list(void);
69 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
70 const char * typ_name,
71 struct obd_uuid *grp_uuid);
72 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
73 struct obd_uuid *grp_uuid);
74 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
76 struct obd_device * class_num2obd(int num);
78 int oig_init(struct obd_io_group **oig);
79 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
80 void oig_complete_one(struct obd_io_group *oig,
81 struct oig_callback_context *occ, int rc);
82 void oig_release(struct obd_io_group *oig);
83 int oig_wait(struct obd_io_group *oig);
85 char *obd_export_nid2str(struct obd_export *exp);
87 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
88 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
91 int class_process_config(struct lustre_cfg *lcfg);
92 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
93 struct lustre_cfg *lcfg, void *data);
94 int class_attach(struct lustre_cfg *lcfg);
95 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
96 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
97 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
98 struct obd_device *class_incref(struct obd_device *obd);
99 void class_decref(struct obd_device *obd);
101 #define CFG_F_START 0x01 /* Set when we start updating from a log */
102 #define CFG_F_MARKER 0x02 /* We are within a maker */
103 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
104 #define CFG_F_COMPAT146 0x08 /* Using old-style log */
105 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
107 /* Passed as data param to class_config_parse_llog */
108 struct config_llog_instance {
110 struct super_block *cfg_sb;
111 struct obd_uuid cfg_uuid;
112 int cfg_last_idx; /* for partial llog processing */
115 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
116 struct config_llog_instance *cfg);
117 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
118 struct config_llog_instance *cfg);
120 /* list of active configuration logs */
121 struct config_llog_data {
123 struct ldlm_res_id cld_resid;
124 struct config_llog_instance cld_cfg;
125 struct list_head cld_list_chain;
126 atomic_t cld_refcount;
127 struct obd_export *cld_mgcexp;
128 unsigned int cld_stopping:1;
131 struct lustre_profile {
132 struct list_head lp_list;
138 struct lustre_profile *class_get_profile(const char * prof);
139 void class_del_profile(const char *prof);
140 void class_del_profiles(void);
143 #define class_export_get(exp) \
145 struct obd_export *exp_ = exp; \
146 atomic_inc(&exp_->exp_refcount); \
147 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
148 atomic_read(&exp_->exp_refcount)); \
152 #define class_export_put(exp) \
154 LASSERT((exp) != NULL); \
155 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
156 atomic_read(&(exp)->exp_refcount) - 1); \
157 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
158 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
159 __class_export_put(exp); \
161 void __class_export_put(struct obd_export *);
162 struct obd_export *class_new_export(struct obd_device *obddev,
163 struct obd_uuid *cluuid);
164 void class_unlink_export(struct obd_export *exp);
166 struct obd_import *class_import_get(struct obd_import *);
167 void class_import_put(struct obd_import *);
168 struct obd_import *class_new_import(struct obd_device *obd);
169 void class_destroy_import(struct obd_import *exp);
171 struct obd_type *class_search_type(const char *name);
172 struct obd_type *class_get_type(const char *name);
173 void class_put_type(struct obd_type *type);
174 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
175 struct obd_uuid *cluuid);
176 int class_disconnect(struct obd_export *exp);
177 void class_fail_export(struct obd_export *exp);
178 void class_disconnect_exports(struct obd_device *obddev);
179 void class_disconnect_stale_exports(struct obd_device *obddev);
180 int class_manual_cleanup(struct obd_device *obd);
182 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
183 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
184 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
185 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
186 unsigned int ia_valid);
187 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
188 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
189 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
192 #define OBT(dev) (dev)->obd_type
193 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
194 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
195 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
197 /* Ensure obd_setup: used for cleanup which must be called
198 while obd is stopping */
199 #define OBD_CHECK_DEV(obd) \
202 CERROR("NULL device\n"); \
207 /* ensure obd_setup and !obd_stopping */
208 #define OBD_CHECK_DEV_ACTIVE(obd) \
210 OBD_CHECK_DEV(obd); \
211 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
212 CERROR("Device %d not setup\n", \
220 #define OBD_COUNTER_OFFSET(op) \
221 ((offsetof(struct obd_ops, o_ ## op) - \
222 offsetof(struct obd_ops, o_iocontrol)) \
223 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
225 #define OBD_COUNTER_INCREMENT(obd, op) \
226 if ((obd)->obd_stats != NULL) { \
227 unsigned int coffset; \
228 coffset = (unsigned int)(obd)->obd_cntr_base + \
229 OBD_COUNTER_OFFSET(op); \
230 LASSERT(coffset < obd->obd_stats->ls_num); \
231 lprocfs_counter_incr(obd->obd_stats, coffset); \
234 #define MD_COUNTER_OFFSET(op) \
235 ((offsetof(struct md_ops, m_ ## op) - \
236 offsetof(struct md_ops, m_getstatus)) \
237 / sizeof(((struct md_ops *)(0))->m_getstatus))
239 #define MD_COUNTER_INCREMENT(obd, op) \
240 if ((obd)->md_stats != NULL) { \
241 unsigned int coffset; \
242 coffset = (unsigned int)(obd)->md_cntr_base + \
243 MD_COUNTER_OFFSET(op); \
244 LASSERT(coffset < (obd)->md_stats->ls_num); \
245 lprocfs_counter_incr((obd)->md_stats, coffset); \
249 #define OBD_COUNTER_OFFSET(op)
250 #define OBD_COUNTER_INCREMENT(obd, op)
251 #define MD_COUNTER_INCREMENT(obd, op)
254 #define OBD_CHECK_MD_OP(obd, op, err) \
256 if (!OBT(obd) || !MDP((obd), op)) { \
258 CERROR("md_" #op ": dev %s/%d no operation\n", \
259 obd->obd_name, obd->obd_minor); \
264 #define EXP_CHECK_MD_OP(exp, op) \
266 if ((exp) == NULL) { \
267 CERROR("obd_" #op ": NULL export\n"); \
270 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
271 CERROR("obd_" #op ": cleaned up obd\n"); \
272 RETURN(-EOPNOTSUPP); \
274 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
275 CERROR("obd_" #op ": dev %s/%d no operation\n", \
276 (exp)->exp_obd->obd_name, \
277 (exp)->exp_obd->obd_minor); \
278 RETURN(-EOPNOTSUPP); \
283 #define OBD_CHECK_DT_OP(obd, op, err) \
285 if (!OBT(obd) || !OBP((obd), op)) { \
287 CERROR("obd_" #op ": dev %d no operation\n", \
293 #define EXP_CHECK_DT_OP(exp, op) \
295 if ((exp) == NULL) { \
296 CERROR("obd_" #op ": NULL export\n"); \
299 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
300 CERROR("obd_" #op ": cleaned up obd\n"); \
301 RETURN(-EOPNOTSUPP); \
303 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
304 CERROR("obd_" #op ": dev %d no operation\n", \
305 (exp)->exp_obd->obd_minor); \
306 RETURN(-EOPNOTSUPP); \
310 #define CTXT_CHECK_OP(ctxt, op, err) \
312 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
314 CERROR("lop_" #op ": dev %d no operation\n", \
315 ctxt->loc_obd->obd_minor); \
320 static inline int class_devno_max(void)
322 return MAX_OBD_DEVICES;
325 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
326 void *key, __u32 *vallen, void *val)
331 EXP_CHECK_DT_OP(exp, get_info);
332 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
334 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
338 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
339 void *key, obd_count vallen, void *val,
340 struct ptlrpc_request_set *set)
345 EXP_CHECK_DT_OP(exp, set_info_async);
346 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info_async);
348 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
354 #define DECLARE_LU_VARS(ldt, d) \
355 struct lu_device_type *ldt; \
358 #define DECLARE_LU_VARS(ldt, d) \
359 extern void __placeholder_to_put_a_semicolon(void)
361 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
364 DECLARE_LU_VARS(ldt, d);
368 ldt = obd->obd_type->typ_lu;
370 struct lu_context ctx;
372 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
374 lu_context_enter(&ctx);
375 d = ldt->ldt_ops->ldto_device_alloc(&ctx, ldt, cfg);
376 lu_context_exit(&ctx);
377 lu_context_fini(&ctx);
388 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
389 OBD_COUNTER_INCREMENT(obd, setup);
390 rc = OBP(obd, setup)(obd, cfg);
395 static inline int obd_precleanup(struct obd_device *obd,
396 enum obd_cleanup_stage cleanup_stage)
399 DECLARE_LU_VARS(ldt, d);
404 ldt = obd->obd_type->typ_lu;
408 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
409 struct lu_context ctx;
411 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
413 lu_context_enter(&ctx);
414 ldt->ldt_ops->ldto_device_fini(&ctx, d);
415 lu_context_exit(&ctx);
416 lu_context_fini(&ctx);
424 OBD_CHECK_DT_OP(obd, precleanup, 0);
425 rc = OBP(obd, precleanup)(obd, cleanup_stage);
428 OBD_COUNTER_INCREMENT(obd, precleanup);
432 static inline int obd_cleanup(struct obd_device *obd)
435 DECLARE_LU_VARS(ldt, d);
441 ldt = obd->obd_type->typ_lu;
444 struct lu_context ctx;
447 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
449 lu_context_enter(&ctx);
450 ldt->ldt_ops->ldto_device_free(&ctx, d);
451 lu_context_exit(&ctx);
452 lu_context_fini(&ctx);
453 obd->obd_lu_dev = NULL;
458 OBD_CHECK_DT_OP(obd, cleanup, 0);
459 rc = OBP(obd, cleanup)(obd);
461 OBD_COUNTER_INCREMENT(obd, cleanup);
466 obd_process_config(struct obd_device *obd, int datalen, void *data)
469 DECLARE_LU_VARS(ldt, d);
475 ldt = obd->obd_type->typ_lu;
477 if (ldt != NULL && d != NULL) {
478 struct lu_context ctx;
480 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
482 lu_context_enter(&ctx);
483 rc = d->ld_ops->ldo_process_config(&ctx, d, data);
484 lu_context_exit(&ctx);
485 lu_context_fini(&ctx);
490 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
491 rc = OBP(obd, process_config)(obd, datalen, data);
493 OBD_COUNTER_INCREMENT(obd, process_config);
498 /* Pack an in-memory MD struct for storage on disk.
499 * Returns +ve size of packed MD (0 for free), or -ve error.
501 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
502 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
503 * If @*disk_tgt == NULL, it will be allocated
505 static inline int obd_packmd(struct obd_export *exp,
506 struct lov_mds_md **disk_tgt,
507 struct lov_stripe_md *mem_src)
512 EXP_CHECK_DT_OP(exp, packmd);
513 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
515 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
519 static inline int obd_size_diskmd(struct obd_export *exp,
520 struct lov_stripe_md *mem_src)
522 return obd_packmd(exp, NULL, mem_src);
525 /* helper functions */
526 static inline int obd_alloc_diskmd(struct obd_export *exp,
527 struct lov_mds_md **disk_tgt)
530 LASSERT(*disk_tgt == NULL);
531 return obd_packmd(exp, disk_tgt, NULL);
534 static inline int obd_free_diskmd(struct obd_export *exp,
535 struct lov_mds_md **disk_tgt)
539 return obd_packmd(exp, disk_tgt, NULL);
542 /* Unpack an MD struct from disk to in-memory format.
543 * Returns +ve size of unpacked MD (0 for free), or -ve error.
545 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
546 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
547 * If @*mem_tgt == NULL, it will be allocated
549 static inline int obd_unpackmd(struct obd_export *exp,
550 struct lov_stripe_md **mem_tgt,
551 struct lov_mds_md *disk_src,
557 EXP_CHECK_DT_OP(exp, unpackmd);
558 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
560 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
564 /* helper functions */
565 static inline int obd_alloc_memmd(struct obd_export *exp,
566 struct lov_stripe_md **mem_tgt)
569 LASSERT(*mem_tgt == NULL);
570 return obd_unpackmd(exp, mem_tgt, NULL, 0);
573 static inline int obd_free_memmd(struct obd_export *exp,
574 struct lov_stripe_md **mem_tgt)
578 return obd_unpackmd(exp, mem_tgt, NULL, 0);
581 static inline int obd_checkmd(struct obd_export *exp,
582 struct obd_export *md_exp,
583 struct lov_stripe_md *mem_tgt)
588 EXP_CHECK_DT_OP(exp, checkmd);
589 OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
591 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
595 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
596 struct lov_stripe_md **ea,
597 struct obd_trans_info *oti)
602 EXP_CHECK_DT_OP(exp, create);
603 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
605 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
609 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
610 struct lov_stripe_md *ea,
611 struct obd_trans_info *oti,
612 struct obd_export *md_exp, void *capa)
617 EXP_CHECK_DT_OP(exp, destroy);
618 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
620 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
624 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
629 EXP_CHECK_DT_OP(exp, getattr);
630 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
632 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
636 static inline int obd_getattr_async(struct obd_export *exp,
637 struct obd_info *oinfo,
638 struct ptlrpc_request_set *set)
643 EXP_CHECK_DT_OP(exp, getattr_async);
644 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr_async);
646 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
650 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
651 struct obd_trans_info *oti)
656 EXP_CHECK_DT_OP(exp, setattr);
657 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
659 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
663 /* This performs all the requests set init/wait/destroy actions. */
664 static inline int obd_setattr_rqset(struct obd_export *exp,
665 struct obd_info *oinfo,
666 struct obd_trans_info *oti)
668 struct ptlrpc_request_set *set = NULL;
672 EXP_CHECK_DT_OP(exp, setattr_async);
673 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
675 set = ptlrpc_prep_set();
679 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
681 rc = ptlrpc_set_wait(set);
682 ptlrpc_set_destroy(set);
686 /* This adds all the requests into @set if @set != NULL, otherwise
687 all requests are sent asynchronously without waiting for response. */
688 static inline int obd_setattr_async(struct obd_export *exp,
689 struct obd_info *oinfo,
690 struct obd_trans_info *oti,
691 struct ptlrpc_request_set *set)
696 EXP_CHECK_DT_OP(exp, setattr_async);
697 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
699 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
703 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
706 struct obd_device *obd = imp->imp_obd;
710 OBD_CHECK_DEV_ACTIVE(obd);
711 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
712 OBD_COUNTER_INCREMENT(obd, add_conn);
714 rc = OBP(obd, add_conn)(imp, uuid, priority);
718 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
720 struct obd_device *obd = imp->imp_obd;
724 OBD_CHECK_DEV_ACTIVE(obd);
725 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
726 OBD_COUNTER_INCREMENT(obd, del_conn);
728 rc = OBP(obd, del_conn)(imp, uuid);
732 static inline int obd_connect(const struct lu_context *ctx,
733 struct lustre_handle *conn,struct obd_device *obd,
734 struct obd_uuid *cluuid,
735 struct obd_connect_data *d)
738 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
741 OBD_CHECK_DEV_ACTIVE(obd);
742 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
743 OBD_COUNTER_INCREMENT(obd, connect);
745 rc = OBP(obd, connect)(ctx, conn, obd, cluuid, d);
746 /* check that only subset is granted */
747 LASSERT(ergo(d != NULL,
748 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
752 static inline int obd_reconnect(struct obd_export *exp,
753 struct obd_device *obd,
754 struct obd_uuid *cluuid,
755 struct obd_connect_data *d)
758 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
761 OBD_CHECK_DEV_ACTIVE(obd);
762 OBD_CHECK_DT_OP(obd, reconnect, 0);
763 OBD_COUNTER_INCREMENT(obd, reconnect);
765 rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
766 /* check that only subset is granted */
767 LASSERT(ergo(d != NULL,
768 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
772 static inline int obd_disconnect(struct obd_export *exp)
777 EXP_CHECK_DT_OP(exp, disconnect);
778 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
780 rc = OBP(exp->exp_obd, disconnect)(exp);
784 static inline int obd_fid_init(struct obd_export *exp)
789 if (OBP(exp->exp_obd, fid_init) == NULL)
792 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_init);
794 rc = OBP(exp->exp_obd, fid_init)(exp);
798 static inline int obd_fid_fini(struct obd_export *exp)
803 if (OBP(exp->exp_obd, fid_fini) == NULL)
806 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_fini);
808 rc = OBP(exp->exp_obd, fid_fini)(exp);
812 static inline int obd_fid_alloc(struct obd_export *exp,
814 struct lu_placement_hint *hint)
819 if (OBP(exp->exp_obd, fid_alloc) == NULL)
822 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
824 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
828 static inline int obd_fid_delete(struct obd_export *exp,
829 const struct lu_fid *fid)
834 if (OBP(exp->exp_obd, fid_delete) == NULL)
837 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
838 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
842 static inline int obd_ping(struct obd_export *exp)
847 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
848 OBD_COUNTER_INCREMENT(exp->exp_obd, ping);
850 rc = OBP(exp->exp_obd, ping)(exp);
854 static inline int obd_init_export(struct obd_export *exp)
859 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
860 OBP((exp)->exp_obd, init_export))
861 rc = OBP(exp->exp_obd, init_export)(exp);
865 static inline int obd_destroy_export(struct obd_export *exp)
868 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
869 OBP((exp)->exp_obd, destroy_export))
870 OBP(exp->exp_obd, destroy_export)(exp);
874 static inline int obd_extent_calc(struct obd_export *exp,
875 struct lov_stripe_md *md,
876 int cmd, obd_off *offset)
880 EXP_CHECK_DT_OP(exp, extent_calc);
881 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
885 static inline struct dentry *
886 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
888 LASSERT(exp->exp_obd);
890 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
895 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
897 LASSERT(exp->exp_obd);
898 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
900 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
901 dentry, exp->exp_obd);
907 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
910 /* @max_age is the oldest time in jiffies that we accept using a cached data.
911 * If the cache is older than @max_age we will get a new value from the
912 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
913 static inline int obd_statfs_async(struct obd_device *obd,
914 struct obd_info *oinfo,
916 struct ptlrpc_request_set *rqset)
924 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
925 OBD_COUNTER_INCREMENT(obd, statfs);
927 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
928 obd->obd_osfs_age, max_age);
929 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
930 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
932 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
933 spin_lock(&obd->obd_osfs_lock);
934 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
935 spin_unlock(&obd->obd_osfs_lock);
937 oinfo->oi_cb_up(oinfo, 0);
942 static inline int obd_statfs_rqset(struct obd_device *obd,
943 struct obd_statfs *osfs, __u64 max_age)
945 struct ptlrpc_request_set *set = NULL;
946 struct obd_info oinfo = { { { 0 } } };
950 set = ptlrpc_prep_set();
954 oinfo.oi_osfs = osfs;
955 rc = obd_statfs_async(obd, &oinfo, max_age, set);
957 rc = ptlrpc_set_wait(set);
958 ptlrpc_set_destroy(set);
962 /* @max_age is the oldest time in jiffies that we accept using a cached data.
963 * If the cache is older than @max_age we will get a new value from the
964 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
965 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
974 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
975 OBD_COUNTER_INCREMENT(obd, statfs);
977 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
978 obd->obd_osfs_age, max_age);
979 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
980 rc = OBP(obd, statfs)(obd, osfs, max_age);
982 spin_lock(&obd->obd_osfs_lock);
983 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
984 obd->obd_osfs_age = cfs_time_current_64();
985 spin_unlock(&obd->obd_osfs_lock);
988 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
989 spin_lock(&obd->obd_osfs_lock);
990 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
991 spin_unlock(&obd->obd_osfs_lock);
996 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
997 struct lov_stripe_md *ea, obd_size start,
998 obd_size end, void *capa)
1003 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1004 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
1006 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1010 static inline int obd_punch_rqset(struct obd_export *exp,
1011 struct obd_info *oinfo,
1012 struct obd_trans_info *oti)
1014 struct ptlrpc_request_set *set = NULL;
1018 EXP_CHECK_DT_OP(exp, punch);
1019 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1021 set = ptlrpc_prep_set();
1025 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1027 rc = ptlrpc_set_wait(set);
1028 ptlrpc_set_destroy(set);
1032 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1033 struct obd_trans_info *oti,
1034 struct ptlrpc_request_set *rqset)
1039 EXP_CHECK_DT_OP(exp, punch);
1040 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1042 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1046 static inline int obd_brw(int cmd, struct obd_export *exp,
1047 struct obd_info *oinfo, obd_count oa_bufs,
1048 struct brw_page *pg, struct obd_trans_info *oti)
1053 EXP_CHECK_DT_OP(exp, brw);
1054 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
1056 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1057 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1058 "or OBD_BRW_CHECK\n");
1062 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1066 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1067 struct obd_info *oinfo, obd_count oa_bufs,
1068 struct brw_page *pg, struct obd_trans_info *oti,
1069 struct ptlrpc_request_set *set)
1074 EXP_CHECK_DT_OP(exp, brw_async);
1075 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
1077 if (!(cmd & OBD_BRW_RWMASK)) {
1078 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1082 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1086 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1087 struct obdo *oa, struct lov_stripe_md *lsm,
1088 obd_count oa_bufs, struct brw_page *pg,
1089 struct obd_trans_info *oti,
1090 struct obd_capa *ocapa)
1092 struct ptlrpc_request_set *set = NULL;
1093 struct obd_info oinfo = { { { 0 } } };
1097 set = ptlrpc_prep_set();
1103 oinfo.oi_capa = ocapa;
1104 rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1106 rc = ptlrpc_set_wait(set);
1108 CERROR("error from callback: rc = %d\n", rc);
1110 CDEBUG(D_INODE, "error from obd_brw_async: rc = %d\n", rc);
1112 ptlrpc_set_destroy(set);
1116 static inline int obd_prep_async_page(struct obd_export *exp,
1117 struct lov_stripe_md *lsm,
1118 struct lov_oinfo *loi,
1119 struct page *page, obd_off offset,
1120 struct obd_async_page_ops *ops,
1121 void *data, void **res)
1126 OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
1127 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
1129 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1134 static inline int obd_queue_async_io(struct obd_export *exp,
1135 struct lov_stripe_md *lsm,
1136 struct lov_oinfo *loi, void *cookie,
1137 int cmd, obd_off off, int count,
1138 obd_flag brw_flags, obd_flag async_flags)
1143 OBD_CHECK_DT_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
1144 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
1145 LASSERT(cmd & OBD_BRW_RWMASK);
1147 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1148 count, brw_flags, async_flags);
1152 static inline int obd_set_async_flags(struct obd_export *exp,
1153 struct lov_stripe_md *lsm,
1154 struct lov_oinfo *loi, void *cookie,
1155 obd_flag async_flags)
1160 OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1161 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
1163 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1168 static inline int obd_queue_group_io(struct obd_export *exp,
1169 struct lov_stripe_md *lsm,
1170 struct lov_oinfo *loi,
1171 struct obd_io_group *oig,
1172 void *cookie, int cmd, obd_off off,
1173 int count, obd_flag brw_flags,
1174 obd_flag async_flags)
1179 OBD_CHECK_DT_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1180 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
1181 LASSERT(cmd & OBD_BRW_RWMASK);
1183 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1184 cmd, off, count, brw_flags,
1189 static inline int obd_trigger_group_io(struct obd_export *exp,
1190 struct lov_stripe_md *lsm,
1191 struct lov_oinfo *loi,
1192 struct obd_io_group *oig)
1197 OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1198 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
1200 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1204 static inline int obd_teardown_async_page(struct obd_export *exp,
1205 struct lov_stripe_md *lsm,
1206 struct lov_oinfo *loi, void *cookie)
1211 OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1212 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
1214 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1218 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1219 int objcount, struct obd_ioobj *obj,
1220 int niocount, struct niobuf_remote *remote,
1221 struct niobuf_local *local,
1222 struct obd_trans_info *oti,
1223 struct lustre_capa *capa)
1228 OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1229 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1231 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1232 remote, local, oti, capa);
1236 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1237 int objcount, struct obd_ioobj *obj,
1238 int niocount, struct niobuf_local *local,
1239 struct obd_trans_info *oti, int rc)
1243 OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1244 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1246 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1251 static inline int obd_merge_lvb(struct obd_export *exp,
1252 struct lov_stripe_md *lsm,
1253 struct ost_lvb *lvb, int kms_only)
1258 OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1259 OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1261 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1265 static inline int obd_adjust_kms(struct obd_export *exp,
1266 struct lov_stripe_md *lsm, obd_off size,
1272 OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1273 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1275 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1279 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1280 int len, void *karg, void *uarg)
1285 EXP_CHECK_DT_OP(exp, iocontrol);
1286 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1288 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1292 static inline int obd_enqueue_rqset(struct obd_export *exp,
1293 struct obd_info *oinfo,
1294 struct obd_enqueue_info *einfo)
1299 EXP_CHECK_DT_OP(exp, enqueue);
1300 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1302 einfo->ei_rqset = ptlrpc_prep_set();
1303 if (einfo->ei_rqset == NULL)
1306 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1308 rc = ptlrpc_set_wait(einfo->ei_rqset);
1309 ptlrpc_set_destroy(einfo->ei_rqset);
1310 einfo->ei_rqset = NULL;
1315 static inline int obd_enqueue(struct obd_export *exp,
1316 struct obd_info *oinfo,
1317 struct obd_enqueue_info *einfo)
1322 EXP_CHECK_DT_OP(exp, enqueue);
1323 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1325 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1329 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1330 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1331 int *flags, void *data, struct lustre_handle *lockh)
1336 EXP_CHECK_DT_OP(exp, match);
1337 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1339 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1344 static inline int obd_change_cbdata(struct obd_export *exp,
1345 struct lov_stripe_md *lsm,
1346 ldlm_iterator_t it, void *data)
1351 EXP_CHECK_DT_OP(exp, change_cbdata);
1352 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1354 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1358 static inline int obd_cancel(struct obd_export *exp,
1359 struct lov_stripe_md *ea, __u32 mode,
1360 struct lustre_handle *lockh)
1365 EXP_CHECK_DT_OP(exp, cancel);
1366 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1368 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1372 static inline int obd_cancel_unused(struct obd_export *exp,
1373 struct lov_stripe_md *ea,
1374 int flags, void *opaque)
1379 EXP_CHECK_DT_OP(exp, cancel_unused);
1380 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1382 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1386 static inline int obd_join_lru(struct obd_export *exp,
1387 struct lov_stripe_md *ea, int join)
1392 EXP_CHECK_DT_OP(exp, join_lru);
1393 OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1395 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1399 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1400 struct obd_capa *oc, struct obd_client_handle *handle,
1405 EXP_CHECK_DT_OP(exp, pin);
1406 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1408 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1412 static inline int obd_unpin(struct obd_export *exp,
1413 struct obd_client_handle *handle, int flag)
1417 EXP_CHECK_DT_OP(exp, unpin);
1418 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1420 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1425 static inline void obd_import_event(struct obd_device *obd,
1426 struct obd_import *imp,
1427 enum obd_import_event event)
1430 CERROR("NULL device\n");
1434 if (obd->obd_set_up && OBP(obd, import_event)) {
1435 OBD_COUNTER_INCREMENT(obd, import_event);
1436 OBP(obd, import_event)(obd, imp, event);
1440 static inline int obd_llog_connect(struct obd_export *exp,
1441 struct llogd_conn_body *body)
1445 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1446 OBD_COUNTER_INCREMENT(exp->exp_obd, llog_connect);
1448 return OBP(exp->exp_obd, llog_connect)(exp, body);
1452 static inline int obd_notify(struct obd_device *obd,
1453 struct obd_device *watched,
1454 enum obd_notify_event ev,
1459 /* the check for async_recov is a complete hack - I'm hereby
1460 overloading the meaning to also mean "this was called from
1461 mds_postsetup". I know that my mds is able to handle notifies
1462 by this point, and it needs to get them to execute mds_postrecov. */
1463 if (!obd->obd_set_up && !obd->obd_async_recov) {
1464 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1468 if (!OBP(obd, notify)) {
1469 CERROR("obd %s has no notify handler\n", obd->obd_name);
1473 OBD_COUNTER_INCREMENT(obd, notify);
1474 return OBP(obd, notify)(obd, watched, ev, data);
1477 static inline int obd_notify_observer(struct obd_device *observer,
1478 struct obd_device *observed,
1479 enum obd_notify_event ev,
1485 struct obd_notify_upcall *onu;
1487 if (observer->obd_observer)
1488 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1492 * Also, call non-obd listener, if any
1494 onu = &observer->obd_upcall;
1495 if (onu->onu_upcall != NULL)
1496 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1500 return rc1 ? rc1 : rc2;
1503 static inline int obd_quotacheck(struct obd_export *exp,
1504 struct obd_quotactl *oqctl)
1509 EXP_CHECK_DT_OP(exp, quotacheck);
1510 OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1512 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1516 static inline int obd_quotactl(struct obd_export *exp,
1517 struct obd_quotactl *oqctl)
1522 EXP_CHECK_DT_OP(exp, quotactl);
1523 OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1525 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1529 static inline int obd_health_check(struct obd_device *obd)
1531 /* returns: 0 on healthy
1532 * >0 on unhealthy + reason code/flag
1533 * however the only suppored reason == 1 right now
1534 * We'll need to define some better reasons
1535 * or flags in the future.
1541 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1542 if (obd == NULL || !OBT(obd)) {
1543 CERROR("cleaned up obd\n");
1544 RETURN(-EOPNOTSUPP);
1546 if (!obd->obd_set_up || obd->obd_stopping)
1548 if (!OBP(obd, health_check))
1551 rc = OBP(obd, health_check)(obd);
1555 static inline int obd_register_observer(struct obd_device *obd,
1556 struct obd_device *observer)
1560 if (obd->obd_observer && observer)
1562 obd->obd_observer = observer;
1566 /* metadata helpers */
1567 static inline int md_getstatus(struct obd_export *exp,
1568 struct lu_fid *fid, struct obd_capa **pc)
1573 EXP_CHECK_MD_OP(exp, getstatus);
1574 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1575 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1579 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1580 struct obd_capa *oc, obd_valid valid, int ea_size,
1581 struct ptlrpc_request **request)
1585 EXP_CHECK_MD_OP(exp, getattr);
1586 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1587 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1592 static inline int md_change_cbdata(struct obd_export *exp,
1593 const struct lu_fid *fid,
1594 ldlm_iterator_t it, void *data)
1598 EXP_CHECK_MD_OP(exp, change_cbdata);
1599 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1600 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1604 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1605 struct obd_client_handle *och,
1606 struct ptlrpc_request **request)
1610 EXP_CHECK_MD_OP(exp, close);
1611 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1612 rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1616 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1617 const void *data, int datalen, int mode, __u32 uid,
1618 __u32 gid, __u32 cap_effective, __u64 rdev,
1619 struct ptlrpc_request **request)
1623 EXP_CHECK_MD_OP(exp, create);
1624 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1625 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1626 uid, gid, cap_effective, rdev, request);
1630 static inline int md_done_writing(struct obd_export *exp,
1631 struct md_op_data *op_data,
1632 struct obd_client_handle *och)
1636 EXP_CHECK_MD_OP(exp, done_writing);
1637 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1638 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, och);
1642 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1643 struct lookup_intent *it, int lock_mode,
1644 struct md_op_data *op_data,
1645 struct lustre_handle *lockh,
1646 void *lmm, int lmmsize,
1647 ldlm_completion_callback cb_completion,
1648 ldlm_blocking_callback cb_blocking,
1649 void *cb_data, int extra_lock_flags)
1653 EXP_CHECK_MD_OP(exp, enqueue);
1654 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1655 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1656 op_data, lockh, lmm, lmmsize,
1657 cb_completion, cb_blocking,
1658 cb_data, extra_lock_flags);
1662 static inline int md_getattr_name(struct obd_export *exp,
1663 const struct lu_fid *fid, struct obd_capa *oc,
1664 const char *name, int namelen,
1665 obd_valid valid, int ea_size,
1666 struct ptlrpc_request **request)
1670 EXP_CHECK_MD_OP(exp, getattr_name);
1671 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1672 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1673 valid, ea_size, request);
1677 static inline int md_intent_lock(struct obd_export *exp,
1678 struct md_op_data *op_data, void *lmm,
1679 int lmmsize, struct lookup_intent *it,
1680 int flags, struct ptlrpc_request **reqp,
1681 ldlm_blocking_callback cb_blocking,
1682 int extra_lock_flags)
1686 EXP_CHECK_MD_OP(exp, intent_lock);
1687 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1688 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1689 it, flags, reqp, cb_blocking,
1694 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1695 struct ptlrpc_request **request)
1699 EXP_CHECK_MD_OP(exp, link);
1700 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1701 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1705 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1706 const char *old, int oldlen, const char *new,
1707 int newlen, struct ptlrpc_request **request)
1711 EXP_CHECK_MD_OP(exp, rename);
1712 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1713 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1718 static inline int md_is_subdir(struct obd_export *exp,
1719 const struct lu_fid *pfid,
1720 const struct lu_fid *cfid,
1721 struct obd_capa *pc, struct obd_capa *cc,
1722 struct ptlrpc_request **request)
1726 EXP_CHECK_MD_OP(exp, is_subdir);
1727 MD_COUNTER_INCREMENT(exp->exp_obd, is_subdir);
1728 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, pc, cc, request);
1732 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1733 void *ea, int ealen, void *ea2, int ea2len,
1734 struct ptlrpc_request **request)
1738 EXP_CHECK_MD_OP(exp, setattr);
1739 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1740 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1741 ea2, ea2len, request);
1745 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1746 struct obd_capa *oc, struct ptlrpc_request **request)
1750 EXP_CHECK_MD_OP(exp, sync);
1751 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1752 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1756 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1757 struct obd_capa *oc, __u64 offset,
1759 struct ptlrpc_request **request)
1763 EXP_CHECK_MD_OP(exp, readpage);
1764 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1765 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1769 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1770 struct ptlrpc_request **request)
1774 EXP_CHECK_MD_OP(exp, unlink);
1775 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1776 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1780 static inline int md_get_lustre_md(struct obd_export *exp,
1781 struct ptlrpc_request *req,
1782 int offset, struct obd_export *dt_exp,
1783 struct obd_export *md_exp,
1784 struct lustre_md *md)
1787 EXP_CHECK_MD_OP(exp, get_lustre_md);
1788 MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1789 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1790 dt_exp, md_exp, md));
1793 static inline int md_free_lustre_md(struct obd_export *exp,
1794 struct lustre_md *md)
1797 EXP_CHECK_MD_OP(exp, free_lustre_md);
1798 MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1799 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1802 static inline int md_setxattr(struct obd_export *exp,
1803 const struct lu_fid *fid, struct obd_capa *oc,
1804 obd_valid valid, const char *name,
1805 const char *input, int input_size,
1806 int output_size, int flags,
1807 struct ptlrpc_request **request)
1810 EXP_CHECK_MD_OP(exp, setxattr);
1811 MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1812 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1813 input_size, output_size, flags,
1817 static inline int md_getxattr(struct obd_export *exp,
1818 const struct lu_fid *fid, struct obd_capa *oc,
1819 obd_valid valid, const char *name,
1820 const char *input, int input_size,
1821 int output_size, int flags,
1822 struct ptlrpc_request **request)
1825 EXP_CHECK_MD_OP(exp, getxattr);
1826 MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1827 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1828 input_size, output_size, flags,
1832 static inline int md_set_open_replay_data(struct obd_export *exp,
1833 struct obd_client_handle *och,
1834 struct ptlrpc_request *open_req)
1837 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1838 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1839 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1842 static inline int md_clear_open_replay_data(struct obd_export *exp,
1843 struct obd_client_handle *och)
1846 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1847 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1848 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1851 static inline int md_set_lock_data(struct obd_export *exp,
1852 __u64 *lockh, void *data)
1855 EXP_CHECK_MD_OP(exp, set_lock_data);
1856 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1857 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1860 static inline int md_cancel_unused(struct obd_export *exp,
1861 const struct lu_fid *fid,
1862 int flags, void *opaque)
1867 EXP_CHECK_MD_OP(exp, cancel_unused);
1868 MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1870 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1874 static inline int md_lock_match(struct obd_export *exp, int flags,
1875 const struct lu_fid *fid, ldlm_type_t type,
1876 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1877 struct lustre_handle *lockh)
1880 EXP_CHECK_MD_OP(exp, lock_match);
1881 MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1882 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1883 policy, mode, lockh));
1886 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1887 int def_asize, int cookiesize)
1890 EXP_CHECK_MD_OP(exp, init_ea_size);
1891 MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1892 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1896 static inline int md_get_remote_perm(struct obd_export *exp,
1897 const struct lu_fid *fid,
1898 struct obd_capa *oc,
1899 struct ptlrpc_request **request)
1902 EXP_CHECK_MD_OP(exp, get_remote_perm);
1903 MD_COUNTER_INCREMENT(exp->exp_obd, get_remote_perm);
1904 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, request));
1907 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1912 EXP_CHECK_MD_OP(exp, renew_capa);
1913 MD_COUNTER_INCREMENT(exp->exp_obd, renew_capa);
1914 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1918 /* OBD Metadata Support */
1919 extern int obd_init_caches(void);
1920 extern void obd_cleanup_caches(void);
1922 /* support routines */
1923 extern cfs_mem_cache_t *obdo_cachep;
1924 static inline struct obdo *obdo_alloc(void)
1927 OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1931 static inline void obdo_free(struct obdo *oa)
1933 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1936 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
1938 /* something here */
1941 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
1943 /* something here */
1946 /* I'm as embarrassed about this as you are.
1948 * <shaver> // XXX do not look into _superhack with remaining eye
1949 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1950 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1953 extern void obd_sysctl_init (void);
1954 extern void obd_sysctl_clean (void);
1957 typedef __u8 class_uuid_t[16];
1958 void class_generate_random_uuid(class_uuid_t uuid);
1959 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1962 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1963 int class_add_uuid(const char *uuid, __u64 nid);
1964 int class_del_uuid (const char *uuid);
1965 void class_init_uuidlist(void);
1966 void class_exit_uuidlist(void);
1969 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1970 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1972 #endif /* __LINUX_OBD_CLASS_H */