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 #define MAX_OBD_DEVICES 2048
46 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
47 extern spinlock_t obd_dev_lock;
49 /* OBD Operations Declarations */
50 extern struct obd_device *class_conn2obd(struct lustre_handle *);
51 extern struct obd_device *class_exp2obd(struct obd_export *);
53 struct lu_device_type;
56 struct obd_export *class_conn2export(struct lustre_handle *);
57 int class_register_type(struct obd_ops *, struct md_ops *,
58 struct lprocfs_vars *, const char *nm,
59 struct lu_device_type *ldt);
60 int class_unregister_type(const char *nm);
62 struct obd_device *class_newdev(const char *type_name, const char *name);
63 void class_release_dev(struct obd_device *obd);
65 int class_name2dev(const char *name);
66 struct obd_device *class_name2obd(const char *name);
67 int class_uuid2dev(struct obd_uuid *uuid);
68 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
69 void class_obd_list(void);
70 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
71 const char * typ_name,
72 struct obd_uuid *grp_uuid);
73 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
74 struct obd_uuid *grp_uuid);
75 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
77 struct obd_device * class_num2obd(int num);
79 int oig_init(struct obd_io_group **oig);
80 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
81 void oig_complete_one(struct obd_io_group *oig,
82 struct oig_callback_context *occ, int rc);
83 void oig_release(struct obd_io_group *oig);
84 int oig_wait(struct obd_io_group *oig);
86 char *obd_export_nid2str(struct obd_export *exp);
88 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
89 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
92 int class_process_config(struct lustre_cfg *lcfg);
93 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
94 struct lustre_cfg *lcfg, void *data);
95 int class_attach(struct lustre_cfg *lcfg);
96 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
97 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
98 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
99 struct obd_device *class_incref(struct obd_device *obd);
100 void class_decref(struct obd_device *obd);
102 #define CFG_F_START 0x01 /* Set when we start updating from a log */
103 #define CFG_F_MARKER 0x02 /* We are within a maker */
104 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
105 #define CFG_F_COMPAT146 0x08 /* Using old-style log */
106 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
108 /* Passed as data param to class_config_parse_llog */
109 struct config_llog_instance {
111 struct super_block *cfg_sb;
112 struct obd_uuid cfg_uuid;
113 int cfg_last_idx; /* for partial llog processing */
116 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
117 struct config_llog_instance *cfg);
118 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
119 struct config_llog_instance *cfg);
121 /* list of active configuration logs */
122 struct config_llog_data {
124 struct ldlm_res_id cld_resid;
125 struct config_llog_instance cld_cfg;
126 struct list_head cld_list_chain;
127 atomic_t cld_refcount;
128 struct obd_export *cld_mgcexp;
129 unsigned int cld_stopping:1;
132 struct lustre_profile {
133 struct list_head lp_list;
139 struct lustre_profile *class_get_profile(const char * prof);
140 void class_del_profile(const char *prof);
141 void class_del_profiles(void);
144 #define class_export_get(exp) \
146 struct obd_export *exp_ = exp; \
147 atomic_inc(&exp_->exp_refcount); \
148 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
149 atomic_read(&exp_->exp_refcount)); \
153 #define class_export_put(exp) \
155 LASSERT((exp) != NULL); \
156 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
157 atomic_read(&(exp)->exp_refcount) - 1); \
158 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
159 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
160 __class_export_put(exp); \
162 void __class_export_put(struct obd_export *);
163 struct obd_export *class_new_export(struct obd_device *obddev,
164 struct obd_uuid *cluuid);
165 void class_unlink_export(struct obd_export *exp);
167 struct obd_import *class_import_get(struct obd_import *);
168 void class_import_put(struct obd_import *);
169 struct obd_import *class_new_import(struct obd_device *obd);
170 void class_destroy_import(struct obd_import *exp);
172 struct obd_type *class_search_type(const char *name);
173 struct obd_type *class_get_type(const char *name);
174 void class_put_type(struct obd_type *type);
175 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
176 struct obd_uuid *cluuid);
177 int class_disconnect(struct obd_export *exp);
178 void class_fail_export(struct obd_export *exp);
179 void class_disconnect_exports(struct obd_device *obddev);
180 void class_disconnect_stale_exports(struct obd_device *obddev);
181 int class_manual_cleanup(struct obd_device *obd);
183 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
184 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
185 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
188 #define OBT(dev) (dev)->obd_type
189 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
190 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
191 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
193 /* Ensure obd_setup: used for cleanup which must be called
194 while obd is stopping */
195 #define OBD_CHECK_DEV(obd) \
198 CERROR("NULL device\n"); \
203 /* ensure obd_setup and !obd_stopping */
204 #define OBD_CHECK_DEV_ACTIVE(obd) \
206 OBD_CHECK_DEV(obd); \
207 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
208 CERROR("Device %d not setup\n", \
216 #define OBD_COUNTER_OFFSET(op) \
217 ((offsetof(struct obd_ops, o_ ## op) - \
218 offsetof(struct obd_ops, o_iocontrol)) \
219 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
221 #define OBD_COUNTER_INCREMENT(obd, op) \
222 if ((obd)->obd_stats != NULL) { \
223 unsigned int coffset; \
224 coffset = (unsigned int)(obd)->obd_cntr_base + \
225 OBD_COUNTER_OFFSET(op); \
226 LASSERT(coffset < obd->obd_stats->ls_num); \
227 lprocfs_counter_incr(obd->obd_stats, coffset); \
230 #define MD_COUNTER_OFFSET(op) \
231 ((offsetof(struct md_ops, m_ ## op) - \
232 offsetof(struct md_ops, m_getstatus)) \
233 / sizeof(((struct md_ops *)(0))->m_getstatus))
235 #define MD_COUNTER_INCREMENT(obd, op) \
236 if ((obd)->md_stats != NULL) { \
237 unsigned int coffset; \
238 coffset = (unsigned int)(obd)->md_cntr_base + \
239 MD_COUNTER_OFFSET(op); \
240 LASSERT(coffset < (obd)->md_stats->ls_num); \
241 lprocfs_counter_incr((obd)->md_stats, coffset); \
245 #define OBD_COUNTER_OFFSET(op)
246 #define OBD_COUNTER_INCREMENT(obd, op)
247 #define MD_COUNTER_INCREMENT(obd, op)
250 #define OBD_CHECK_MD_OP(obd, op, err) \
252 if (!OBT(obd) || !MDP((obd), op)) { \
254 CERROR("md_" #op ": dev %s/%d no operation\n", \
255 obd->obd_name, obd->obd_minor); \
260 #define EXP_CHECK_MD_OP(exp, op) \
262 if ((exp) == NULL) { \
263 CERROR("obd_" #op ": NULL export\n"); \
266 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
267 CERROR("obd_" #op ": cleaned up obd\n"); \
268 RETURN(-EOPNOTSUPP); \
270 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
271 CERROR("obd_" #op ": dev %s/%d no operation\n", \
272 (exp)->exp_obd->obd_name, \
273 (exp)->exp_obd->obd_minor); \
274 RETURN(-EOPNOTSUPP); \
279 #define OBD_CHECK_DT_OP(obd, op, err) \
281 if (!OBT(obd) || !OBP((obd), op)) { \
283 CERROR("obd_" #op ": dev %d no operation\n", \
289 #define EXP_CHECK_DT_OP(exp, op) \
291 if ((exp) == NULL) { \
292 CERROR("obd_" #op ": NULL export\n"); \
295 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
296 CERROR("obd_" #op ": cleaned up obd\n"); \
297 RETURN(-EOPNOTSUPP); \
299 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
300 CERROR("obd_" #op ": dev %d no operation\n", \
301 (exp)->exp_obd->obd_minor); \
302 RETURN(-EOPNOTSUPP); \
306 #define CTXT_CHECK_OP(ctxt, op, err) \
308 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
310 CERROR("lop_" #op ": dev %d no operation\n", \
311 ctxt->loc_obd->obd_minor); \
316 static inline int class_devno_max(void)
318 return MAX_OBD_DEVICES;
321 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
322 void *key, __u32 *vallen, void *val)
327 EXP_CHECK_DT_OP(exp, get_info);
328 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
330 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
334 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
335 void *key, obd_count vallen, void *val,
336 struct ptlrpc_request_set *set)
341 EXP_CHECK_DT_OP(exp, set_info_async);
342 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info_async);
344 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
350 #define DECLARE_LU_VARS(ldt, d) \
351 struct lu_device_type *ldt; \
354 #define DECLARE_LU_VARS(ldt, d) \
355 extern void __placeholder_to_put_a_semicolon(void)
357 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
360 DECLARE_LU_VARS(ldt, d);
364 ldt = obd->obd_type->typ_lu;
366 struct lu_context ctx;
368 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
370 lu_context_enter(&ctx);
371 d = ldt->ldt_ops->ldto_device_alloc(&ctx, ldt, cfg);
372 lu_context_exit(&ctx);
373 lu_context_fini(&ctx);
384 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
385 OBD_COUNTER_INCREMENT(obd, setup);
386 rc = OBP(obd, setup)(obd, cfg);
391 static inline int obd_precleanup(struct obd_device *obd,
392 enum obd_cleanup_stage cleanup_stage)
395 DECLARE_LU_VARS(ldt, d);
400 ldt = obd->obd_type->typ_lu;
402 if (ldt != NULL && d != NULL) {
403 struct lu_context ctx;
405 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
407 lu_context_enter(&ctx);
408 ldt->ldt_ops->ldto_device_fini(&ctx, d);
409 lu_context_exit(&ctx);
410 lu_context_fini(&ctx);
411 obd->obd_lu_dev = NULL;
417 OBD_CHECK_DT_OP(obd, precleanup, 0);
418 rc = OBP(obd, precleanup)(obd, cleanup_stage);
421 OBD_COUNTER_INCREMENT(obd, precleanup);
425 static inline int obd_cleanup(struct obd_device *obd)
428 DECLARE_LU_VARS(ldt, d);
434 ldt = obd->obd_type->typ_lu;
436 if (ldt != NULL && d != NULL) {
437 struct lu_context ctx;
439 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
441 lu_context_enter(&ctx);
442 ldt->ldt_ops->ldto_device_free(&ctx, d);
443 lu_context_exit(&ctx);
444 lu_context_fini(&ctx);
445 obd->obd_lu_dev = NULL;
451 OBD_CHECK_DT_OP(obd, cleanup, 0);
452 rc = OBP(obd, cleanup)(obd);
454 OBD_COUNTER_INCREMENT(obd, cleanup);
459 obd_process_config(struct obd_device *obd, int datalen, void *data)
462 DECLARE_LU_VARS(ldt, d);
468 ldt = obd->obd_type->typ_lu;
470 if (ldt != NULL && d != NULL) {
471 struct lu_context ctx;
473 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
475 lu_context_enter(&ctx);
476 rc = d->ld_ops->ldo_process_config(&ctx, d, data);
477 lu_context_exit(&ctx);
478 lu_context_fini(&ctx);
483 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
484 rc = OBP(obd, process_config)(obd, datalen, data);
486 OBD_COUNTER_INCREMENT(obd, process_config);
491 /* Pack an in-memory MD struct for storage on disk.
492 * Returns +ve size of packed MD (0 for free), or -ve error.
494 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
495 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
496 * If @*disk_tgt == NULL, it will be allocated
498 static inline int obd_packmd(struct obd_export *exp,
499 struct lov_mds_md **disk_tgt,
500 struct lov_stripe_md *mem_src)
505 EXP_CHECK_DT_OP(exp, packmd);
506 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
508 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
512 static inline int obd_size_diskmd(struct obd_export *exp,
513 struct lov_stripe_md *mem_src)
515 return obd_packmd(exp, NULL, mem_src);
518 /* helper functions */
519 static inline int obd_alloc_diskmd(struct obd_export *exp,
520 struct lov_mds_md **disk_tgt)
523 LASSERT(*disk_tgt == NULL);
524 return obd_packmd(exp, disk_tgt, NULL);
527 static inline int obd_free_diskmd(struct obd_export *exp,
528 struct lov_mds_md **disk_tgt)
532 return obd_packmd(exp, disk_tgt, NULL);
535 /* Unpack an MD struct from disk to in-memory format.
536 * Returns +ve size of unpacked MD (0 for free), or -ve error.
538 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
539 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
540 * If @*mem_tgt == NULL, it will be allocated
542 static inline int obd_unpackmd(struct obd_export *exp,
543 struct lov_stripe_md **mem_tgt,
544 struct lov_mds_md *disk_src,
550 EXP_CHECK_DT_OP(exp, unpackmd);
551 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
553 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
557 /* helper functions */
558 static inline int obd_alloc_memmd(struct obd_export *exp,
559 struct lov_stripe_md **mem_tgt)
562 LASSERT(*mem_tgt == NULL);
563 return obd_unpackmd(exp, mem_tgt, NULL, 0);
566 static inline int obd_free_memmd(struct obd_export *exp,
567 struct lov_stripe_md **mem_tgt)
571 return obd_unpackmd(exp, mem_tgt, NULL, 0);
574 static inline int obd_checkmd(struct obd_export *exp,
575 struct obd_export *md_exp,
576 struct lov_stripe_md *mem_tgt)
581 EXP_CHECK_DT_OP(exp, checkmd);
582 OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
584 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
588 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
589 struct lov_stripe_md **ea,
590 struct obd_trans_info *oti)
595 EXP_CHECK_DT_OP(exp, create);
596 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
598 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
602 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
603 struct lov_stripe_md *ea,
604 struct obd_trans_info *oti,
605 struct obd_export *md_exp)
610 EXP_CHECK_DT_OP(exp, destroy);
611 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
613 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
617 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
622 EXP_CHECK_DT_OP(exp, getattr);
623 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
625 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
629 static inline int obd_getattr_async(struct obd_export *exp,
630 struct obd_info *oinfo,
631 struct ptlrpc_request_set *set)
636 EXP_CHECK_DT_OP(exp, getattr_async);
637 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr_async);
639 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
643 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
644 struct obd_trans_info *oti)
649 EXP_CHECK_DT_OP(exp, setattr);
650 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
652 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
656 /* This performs all the requests set init/wait/destroy actions. */
657 static inline int obd_setattr_rqset(struct obd_export *exp,
658 struct obd_info *oinfo,
659 struct obd_trans_info *oti)
661 struct ptlrpc_request_set *set = NULL;
665 EXP_CHECK_DT_OP(exp, setattr_async);
666 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
668 set = ptlrpc_prep_set();
672 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
674 rc = ptlrpc_set_wait(set);
675 ptlrpc_set_destroy(set);
679 /* This adds all the requests into @set if @set != NULL, otherwise
680 all requests are sent asynchronously without waiting for response. */
681 static inline int obd_setattr_async(struct obd_export *exp,
682 struct obd_info *oinfo,
683 struct obd_trans_info *oti,
684 struct ptlrpc_request_set *set)
689 EXP_CHECK_DT_OP(exp, setattr_async);
690 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
692 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
696 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
699 struct obd_device *obd = imp->imp_obd;
703 OBD_CHECK_DEV_ACTIVE(obd);
704 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
705 OBD_COUNTER_INCREMENT(obd, add_conn);
707 rc = OBP(obd, add_conn)(imp, uuid, priority);
711 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
713 struct obd_device *obd = imp->imp_obd;
717 OBD_CHECK_DEV_ACTIVE(obd);
718 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
719 OBD_COUNTER_INCREMENT(obd, del_conn);
721 rc = OBP(obd, del_conn)(imp, uuid);
725 static inline int obd_connect(const struct lu_context *ctx,
726 struct lustre_handle *conn,struct obd_device *obd,
727 struct obd_uuid *cluuid,
728 struct obd_connect_data *d)
731 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
734 OBD_CHECK_DEV_ACTIVE(obd);
735 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
736 OBD_COUNTER_INCREMENT(obd, connect);
738 rc = OBP(obd, connect)(ctx, conn, obd, cluuid, d);
739 /* check that only subset is granted */
740 LASSERT(ergo(d != NULL,
741 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
745 static inline int obd_reconnect(struct obd_export *exp,
746 struct obd_device *obd,
747 struct obd_uuid *cluuid,
748 struct obd_connect_data *d)
751 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
754 OBD_CHECK_DEV_ACTIVE(obd);
755 OBD_CHECK_DT_OP(obd, reconnect, 0);
756 OBD_COUNTER_INCREMENT(obd, reconnect);
758 rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
759 /* check that only subset is granted */
760 LASSERT(ergo(d != NULL,
761 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
765 static inline int obd_disconnect(struct obd_export *exp)
770 EXP_CHECK_DT_OP(exp, disconnect);
771 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
773 rc = OBP(exp->exp_obd, disconnect)(exp);
777 static inline int obd_fid_init(struct obd_export *exp)
782 if (OBP(exp->exp_obd, fid_init) == NULL)
785 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_init);
787 rc = OBP(exp->exp_obd, fid_init)(exp);
791 static inline int obd_fid_fini(struct obd_export *exp)
796 if (OBP(exp->exp_obd, fid_fini) == NULL)
799 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_fini);
801 rc = OBP(exp->exp_obd, fid_fini)(exp);
805 static inline int obd_fid_alloc(struct obd_export *exp,
807 struct lu_placement_hint *hint)
812 if (OBP(exp->exp_obd, fid_alloc) == NULL)
815 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
817 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
821 static inline int obd_fid_delete(struct obd_export *exp,
827 if (OBP(exp->exp_obd, fid_delete) == NULL)
830 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
831 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
835 static inline int obd_ping(struct obd_export *exp)
840 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
841 OBD_COUNTER_INCREMENT(exp->exp_obd, ping);
843 rc = OBP(exp->exp_obd, ping)(exp);
847 static inline int obd_init_export(struct obd_export *exp)
852 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
853 OBP((exp)->exp_obd, init_export))
854 rc = OBP(exp->exp_obd, init_export)(exp);
858 static inline int obd_destroy_export(struct obd_export *exp)
861 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
862 OBP((exp)->exp_obd, destroy_export))
863 OBP(exp->exp_obd, destroy_export)(exp);
867 static inline int obd_extent_calc(struct obd_export *exp,
868 struct lov_stripe_md *md,
869 int cmd, obd_off *offset)
873 EXP_CHECK_DT_OP(exp, extent_calc);
874 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
878 static inline struct dentry *
879 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
881 LASSERT(exp->exp_obd);
883 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
888 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
890 LASSERT(exp->exp_obd);
891 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
893 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
894 dentry, exp->exp_obd);
900 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
903 /* @max_age is the oldest time in jiffies that we accept using a cached data.
904 * If the cache is older than @max_age we will get a new value from the
905 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
906 static inline int obd_statfs_async(struct obd_device *obd,
907 struct obd_info *oinfo,
909 struct ptlrpc_request_set *rqset)
917 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
918 OBD_COUNTER_INCREMENT(obd, statfs);
920 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
921 obd->obd_osfs_age, max_age);
922 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
923 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
925 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
926 spin_lock(&obd->obd_osfs_lock);
927 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
928 spin_unlock(&obd->obd_osfs_lock);
930 oinfo->oi_cb_up(oinfo, 0);
935 static inline int obd_statfs_rqset(struct obd_device *obd,
936 struct obd_statfs *osfs, __u64 max_age)
938 struct ptlrpc_request_set *set = NULL;
939 struct obd_info oinfo = { { { 0 } } };
943 set = ptlrpc_prep_set();
947 oinfo.oi_osfs = osfs;
948 rc = obd_statfs_async(obd, &oinfo, max_age, set);
950 rc = ptlrpc_set_wait(set);
951 ptlrpc_set_destroy(set);
955 /* @max_age is the oldest time in jiffies that we accept using a cached data.
956 * If the cache is older than @max_age we will get a new value from the
957 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
958 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
967 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
968 OBD_COUNTER_INCREMENT(obd, statfs);
970 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
971 obd->obd_osfs_age, max_age);
972 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
973 rc = OBP(obd, statfs)(obd, osfs, max_age);
975 spin_lock(&obd->obd_osfs_lock);
976 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
977 obd->obd_osfs_age = cfs_time_current_64();
978 spin_unlock(&obd->obd_osfs_lock);
981 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
982 spin_lock(&obd->obd_osfs_lock);
983 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
984 spin_unlock(&obd->obd_osfs_lock);
989 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
990 struct lov_stripe_md *ea, obd_size start,
996 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
997 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
999 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
1003 static inline int obd_punch_rqset(struct obd_export *exp,
1004 struct obd_info *oinfo,
1005 struct obd_trans_info *oti)
1007 struct ptlrpc_request_set *set = NULL;
1011 EXP_CHECK_DT_OP(exp, punch);
1012 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1014 set = ptlrpc_prep_set();
1018 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1020 rc = ptlrpc_set_wait(set);
1021 ptlrpc_set_destroy(set);
1025 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1026 struct obd_trans_info *oti,
1027 struct ptlrpc_request_set *rqset)
1032 EXP_CHECK_DT_OP(exp, punch);
1033 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1035 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1039 static inline int obd_brw(int cmd, struct obd_export *exp,
1040 struct obd_info *oinfo, obd_count oa_bufs,
1041 struct brw_page *pg, struct obd_trans_info *oti)
1046 EXP_CHECK_DT_OP(exp, brw);
1047 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
1049 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1050 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1051 "or OBD_BRW_CHECK\n");
1055 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1059 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1060 struct obd_info *oinfo, obd_count oa_bufs,
1061 struct brw_page *pg, struct obd_trans_info *oti,
1062 struct ptlrpc_request_set *set)
1067 EXP_CHECK_DT_OP(exp, brw_async);
1068 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
1070 if (!(cmd & OBD_BRW_RWMASK)) {
1071 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1075 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1079 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1080 struct obdo *oa, struct lov_stripe_md *lsm,
1081 obd_count oa_bufs, struct brw_page *pg,
1082 struct obd_trans_info *oti)
1084 struct ptlrpc_request_set *set = NULL;
1085 struct obd_info oinfo = { { { 0 } } };
1089 set = ptlrpc_prep_set();
1095 rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1097 rc = ptlrpc_set_wait(set);
1099 CERROR("error from callback: rc = %d\n", rc);
1101 CDEBUG(D_INODE, "error from obd_brw_async: rc = %d\n", rc);
1103 ptlrpc_set_destroy(set);
1107 static inline int obd_prep_async_page(struct obd_export *exp,
1108 struct lov_stripe_md *lsm,
1109 struct lov_oinfo *loi,
1110 struct page *page, obd_off offset,
1111 struct obd_async_page_ops *ops,
1112 void *data, void **res)
1117 OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
1118 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
1120 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1125 static inline int obd_queue_async_io(struct obd_export *exp,
1126 struct lov_stripe_md *lsm,
1127 struct lov_oinfo *loi, void *cookie,
1128 int cmd, obd_off off, int count,
1129 obd_flag brw_flags, obd_flag async_flags)
1134 OBD_CHECK_DT_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
1135 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
1136 LASSERT(cmd & OBD_BRW_RWMASK);
1138 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1139 count, brw_flags, async_flags);
1143 static inline int obd_set_async_flags(struct obd_export *exp,
1144 struct lov_stripe_md *lsm,
1145 struct lov_oinfo *loi, void *cookie,
1146 obd_flag async_flags)
1151 OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1152 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
1154 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1159 static inline int obd_queue_group_io(struct obd_export *exp,
1160 struct lov_stripe_md *lsm,
1161 struct lov_oinfo *loi,
1162 struct obd_io_group *oig,
1163 void *cookie, int cmd, obd_off off,
1164 int count, obd_flag brw_flags,
1165 obd_flag async_flags)
1170 OBD_CHECK_DT_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1171 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
1172 LASSERT(cmd & OBD_BRW_RWMASK);
1174 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1175 cmd, off, count, brw_flags,
1180 static inline int obd_trigger_group_io(struct obd_export *exp,
1181 struct lov_stripe_md *lsm,
1182 struct lov_oinfo *loi,
1183 struct obd_io_group *oig)
1188 OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1189 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
1191 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1195 static inline int obd_teardown_async_page(struct obd_export *exp,
1196 struct lov_stripe_md *lsm,
1197 struct lov_oinfo *loi, void *cookie)
1202 OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1203 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
1205 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1209 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1210 int objcount, struct obd_ioobj *obj,
1211 int niocount, struct niobuf_remote *remote,
1212 struct niobuf_local *local,
1213 struct obd_trans_info *oti)
1218 OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1219 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1221 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1222 remote, local, oti);
1226 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1227 int objcount, struct obd_ioobj *obj,
1228 int niocount, struct niobuf_local *local,
1229 struct obd_trans_info *oti, int rc)
1233 OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1234 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1236 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1241 static inline int obd_merge_lvb(struct obd_export *exp,
1242 struct lov_stripe_md *lsm,
1243 struct ost_lvb *lvb, int kms_only)
1248 OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1249 OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1251 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1255 static inline int obd_adjust_kms(struct obd_export *exp,
1256 struct lov_stripe_md *lsm, obd_off size,
1262 OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1263 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1265 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1269 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1270 int len, void *karg, void *uarg)
1275 EXP_CHECK_DT_OP(exp, iocontrol);
1276 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1278 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1282 static inline int obd_enqueue_rqset(struct obd_export *exp,
1283 struct obd_info *oinfo,
1284 struct obd_enqueue_info *einfo)
1289 EXP_CHECK_DT_OP(exp, enqueue);
1290 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1292 einfo->ei_rqset = ptlrpc_prep_set();
1293 if (einfo->ei_rqset == NULL)
1296 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1298 rc = ptlrpc_set_wait(einfo->ei_rqset);
1299 ptlrpc_set_destroy(einfo->ei_rqset);
1300 einfo->ei_rqset = NULL;
1305 static inline int obd_enqueue(struct obd_export *exp,
1306 struct obd_info *oinfo,
1307 struct obd_enqueue_info *einfo)
1312 EXP_CHECK_DT_OP(exp, enqueue);
1313 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1315 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1319 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1320 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1321 int *flags, void *data, struct lustre_handle *lockh)
1326 EXP_CHECK_DT_OP(exp, match);
1327 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1329 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1334 static inline int obd_change_cbdata(struct obd_export *exp,
1335 struct lov_stripe_md *lsm,
1336 ldlm_iterator_t it, void *data)
1341 EXP_CHECK_DT_OP(exp, change_cbdata);
1342 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1344 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1348 static inline int obd_cancel(struct obd_export *exp,
1349 struct lov_stripe_md *ea, __u32 mode,
1350 struct lustre_handle *lockh)
1355 EXP_CHECK_DT_OP(exp, cancel);
1356 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1358 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1362 static inline int obd_cancel_unused(struct obd_export *exp,
1363 struct lov_stripe_md *ea,
1364 int flags, void *opaque)
1369 EXP_CHECK_DT_OP(exp, cancel_unused);
1370 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1372 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1376 static inline int obd_join_lru(struct obd_export *exp,
1377 struct lov_stripe_md *ea, int join)
1382 EXP_CHECK_DT_OP(exp, join_lru);
1383 OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1385 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1389 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1391 int objcount, struct obd_ioobj *obj,
1392 int niocount, struct niobuf_remote *remote)
1396 EXP_CHECK_DT_OP(exp, preprw);
1397 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1399 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1401 class_export_put(exp);
1405 static inline int obd_pin(struct obd_export *exp, struct lu_fid *fid,
1406 struct obd_client_handle *handle, int flag)
1410 EXP_CHECK_DT_OP(exp, pin);
1411 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1413 rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1417 static inline int obd_unpin(struct obd_export *exp,
1418 struct obd_client_handle *handle, int flag)
1422 EXP_CHECK_DT_OP(exp, unpin);
1423 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1425 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1430 static inline void obd_import_event(struct obd_device *obd,
1431 struct obd_import *imp,
1432 enum obd_import_event event)
1435 CERROR("NULL device\n");
1439 if (obd->obd_set_up && OBP(obd, import_event)) {
1440 OBD_COUNTER_INCREMENT(obd, import_event);
1441 OBP(obd, import_event)(obd, imp, event);
1445 static inline int obd_notify(struct obd_device *obd,
1446 struct obd_device *watched,
1447 enum obd_notify_event ev,
1452 /* the check for async_recov is a complete hack - I'm hereby
1453 overloading the meaning to also mean "this was called from
1454 mds_postsetup". I know that my mds is able to handle notifies
1455 by this point, and it needs to get them to execute mds_postrecov. */
1456 if (!obd->obd_set_up && !obd->obd_async_recov) {
1457 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1461 if (!OBP(obd, notify)) {
1462 CERROR("obd %s has no notify handler\n", obd->obd_name);
1466 OBD_COUNTER_INCREMENT(obd, notify);
1467 return OBP(obd, notify)(obd, watched, ev, data);
1470 static inline int obd_notify_observer(struct obd_device *observer,
1471 struct obd_device *observed,
1472 enum obd_notify_event ev,
1478 struct obd_notify_upcall *onu;
1480 if (observer->obd_observer)
1481 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1485 * Also, call non-obd listener, if any
1487 onu = &observer->obd_upcall;
1488 if (onu->onu_upcall != NULL)
1489 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1493 return rc1 ? rc1 : rc2;
1496 static inline int obd_quotacheck(struct obd_export *exp,
1497 struct obd_quotactl *oqctl)
1502 EXP_CHECK_DT_OP(exp, quotacheck);
1503 OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1505 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1509 static inline int obd_quotactl(struct obd_export *exp,
1510 struct obd_quotactl *oqctl)
1515 EXP_CHECK_DT_OP(exp, quotactl);
1516 OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1518 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1522 static inline int obd_health_check(struct obd_device *obd)
1524 /* returns: 0 on healthy
1525 * >0 on unhealthy + reason code/flag
1526 * however the only suppored reason == 1 right now
1527 * We'll need to define some better reasons
1528 * or flags in the future.
1534 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1535 if (obd == NULL || !OBT(obd)) {
1536 CERROR("cleaned up obd\n");
1537 RETURN(-EOPNOTSUPP);
1539 if (!obd->obd_set_up || obd->obd_stopping)
1541 if (!OBP(obd, health_check))
1544 rc = OBP(obd, health_check)(obd);
1548 static inline int obd_register_observer(struct obd_device *obd,
1549 struct obd_device *observer)
1553 if (obd->obd_observer && observer)
1555 obd->obd_observer = observer;
1559 /* metadata helpers */
1560 static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
1565 EXP_CHECK_MD_OP(exp, getstatus);
1566 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1567 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1571 static inline int md_getattr(struct obd_export *exp, struct lu_fid *fid,
1572 obd_valid valid, int ea_size,
1573 struct ptlrpc_request **request)
1577 EXP_CHECK_MD_OP(exp, getattr);
1578 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1579 rc = MDP(exp->exp_obd, getattr)(exp, fid, valid,
1584 static inline int md_change_cbdata(struct obd_export *exp, struct lu_fid *fid,
1585 ldlm_iterator_t it, void *data)
1589 EXP_CHECK_MD_OP(exp, change_cbdata);
1590 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1591 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1595 static inline int md_close(struct obd_export *exp,
1596 struct md_op_data *op_data,
1597 struct obd_client_handle *och,
1598 struct ptlrpc_request **request)
1602 EXP_CHECK_MD_OP(exp, close);
1603 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1604 rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1608 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1609 const void *data, int datalen, int mode,
1610 __u32 uid, __u32 gid, __u32 cap_effective, __u64 rdev,
1611 struct ptlrpc_request **request)
1615 EXP_CHECK_MD_OP(exp, create);
1616 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1617 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1618 uid, gid, cap_effective, rdev, request);
1622 static inline int md_done_writing(struct obd_export *exp,
1623 struct md_op_data *op_data)
1627 EXP_CHECK_MD_OP(exp, done_writing);
1628 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1629 rc = MDP(exp->exp_obd, done_writing)(exp, op_data);
1633 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1634 struct lookup_intent *it, int lock_mode,
1635 struct md_op_data *op_data,
1636 struct lustre_handle *lockh,
1637 void *lmm, int lmmsize,
1638 ldlm_completion_callback cb_completion,
1639 ldlm_blocking_callback cb_blocking,
1640 void *cb_data, int extra_lock_flags)
1644 EXP_CHECK_MD_OP(exp, enqueue);
1645 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1646 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1647 op_data, lockh, lmm, lmmsize,
1648 cb_completion, cb_blocking,
1649 cb_data, extra_lock_flags);
1653 static inline int md_getattr_name(struct obd_export *exp, struct lu_fid *fid,
1654 const char *filename, int namelen,
1655 obd_valid valid, int ea_size,
1656 struct ptlrpc_request **request)
1660 EXP_CHECK_MD_OP(exp, getattr_name);
1661 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1662 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1663 valid, ea_size, request);
1667 static inline int md_intent_lock(struct obd_export *exp,
1668 struct md_op_data *op_data,
1669 void *lmm, int lmmsize,
1670 struct lookup_intent *it,
1671 int flags, struct ptlrpc_request **reqp,
1672 ldlm_blocking_callback cb_blocking,
1673 int extra_lock_flags)
1677 EXP_CHECK_MD_OP(exp, intent_lock);
1678 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1679 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1680 it, flags, reqp, cb_blocking,
1685 static inline int md_link(struct obd_export *exp,
1686 struct md_op_data *op_data,
1687 struct ptlrpc_request **request)
1691 EXP_CHECK_MD_OP(exp, link);
1692 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1693 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1697 static inline int md_rename(struct obd_export *exp,
1698 struct md_op_data *op_data,
1699 const char *old, int oldlen,
1700 const char *new, int newlen,
1701 struct ptlrpc_request **request)
1705 EXP_CHECK_MD_OP(exp, rename);
1706 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1707 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1712 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1713 struct iattr *iattr, void *ea, int ealen,
1714 void *ea2, int ea2len, struct ptlrpc_request **request)
1718 EXP_CHECK_MD_OP(exp, setattr);
1719 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1720 rc = MDP(exp->exp_obd, setattr)(exp, op_data, iattr, ea, ealen,
1721 ea2, ea2len, request);
1725 static inline int md_sync(struct obd_export *exp, struct lu_fid *fid,
1726 struct ptlrpc_request **request)
1730 EXP_CHECK_MD_OP(exp, sync);
1731 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1732 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1736 static inline int md_readpage(struct obd_export *exp, struct lu_fid *fid,
1737 __u64 offset, struct page *page,
1738 struct ptlrpc_request **request)
1742 EXP_CHECK_MD_OP(exp, readpage);
1743 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1744 rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1748 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1749 struct ptlrpc_request **request)
1753 EXP_CHECK_MD_OP(exp, unlink);
1754 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1755 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1759 static inline int md_get_lustre_md(struct obd_export *exp,
1760 struct ptlrpc_request *req,
1761 int offset, struct obd_export *dt_exp,
1762 struct lustre_md *md)
1765 EXP_CHECK_MD_OP(exp, get_lustre_md);
1766 MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1767 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1771 static inline int md_free_lustre_md(struct obd_export *exp,
1772 struct lustre_md *md)
1775 EXP_CHECK_MD_OP(exp, free_lustre_md);
1776 MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1777 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1780 static inline int md_setxattr(struct obd_export *exp, struct lu_fid *fid,
1781 obd_valid valid, const char *name,
1782 const char *input, int input_size,
1783 int output_size, int flags,
1784 struct ptlrpc_request **request)
1787 EXP_CHECK_MD_OP(exp, setxattr);
1788 MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1789 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1790 input_size, output_size, flags,
1794 static inline int md_getxattr(struct obd_export *exp, struct lu_fid *fid,
1795 obd_valid valid, const char *name,
1796 const char *input, int input_size,
1797 int output_size, int flags,
1798 struct ptlrpc_request **request)
1801 EXP_CHECK_MD_OP(exp, getxattr);
1802 MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1803 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1804 input_size, output_size, flags,
1808 static inline int md_set_open_replay_data(struct obd_export *exp,
1809 struct obd_client_handle *och,
1810 struct ptlrpc_request *open_req)
1813 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1814 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1815 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1818 static inline int md_clear_open_replay_data(struct obd_export *exp,
1819 struct obd_client_handle *och)
1822 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1823 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1824 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1827 static inline int md_set_lock_data(struct obd_export *exp,
1828 __u64 *lockh, void *data)
1831 EXP_CHECK_MD_OP(exp, set_lock_data);
1832 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1833 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1836 static inline int md_cancel_unused(struct obd_export *exp,
1838 int flags, void *opaque)
1843 EXP_CHECK_MD_OP(exp, cancel_unused);
1844 MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1846 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1850 static inline int md_lock_match(struct obd_export *exp, int flags,
1851 struct lu_fid *fid, ldlm_type_t type,
1852 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1853 struct lustre_handle *lockh)
1856 EXP_CHECK_MD_OP(exp, lock_match);
1857 MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1858 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1859 policy, mode, lockh));
1862 static inline int md_init_ea_size(struct obd_export *exp,
1863 int easize, int def_asize,
1867 EXP_CHECK_MD_OP(exp, init_ea_size);
1868 MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1869 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize,
1874 /* OBD Metadata Support */
1875 extern int obd_init_caches(void);
1876 extern void obd_cleanup_caches(void);
1878 /* support routines */
1879 extern cfs_mem_cache_t *obdo_cachep;
1880 static inline struct obdo *obdo_alloc(void)
1883 OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1887 static inline void obdo_free(struct obdo *oa)
1889 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1892 static inline void obdo2fid(struct obdo *oa,
1895 /* something here */
1898 static inline void fid2obdo(struct lu_fid *fid,
1901 /* something here */
1904 /* I'm as embarrassed about this as you are.
1906 * <shaver> // XXX do not look into _superhack with remaining eye
1907 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1908 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1911 extern void obd_sysctl_init (void);
1912 extern void obd_sysctl_clean (void);
1915 typedef __u8 class_uuid_t[16];
1916 void class_generate_random_uuid(class_uuid_t uuid);
1917 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1920 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1921 int class_add_uuid(const char *uuid, __u64 nid);
1922 int class_del_uuid (const char *uuid);
1923 void class_init_uuidlist(void);
1924 void class_exit_uuidlist(void);
1927 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1928 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1930 #endif /* __LINUX_OBD_CLASS_H */