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;
404 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
405 struct lu_context ctx;
407 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
409 lu_context_enter(&ctx);
410 ldt->ldt_ops->ldto_device_fini(&ctx, d);
411 lu_context_exit(&ctx);
412 lu_context_fini(&ctx);
419 OBD_CHECK_DT_OP(obd, precleanup, 0);
420 rc = OBP(obd, precleanup)(obd, cleanup_stage);
423 OBD_COUNTER_INCREMENT(obd, precleanup);
427 static inline int obd_cleanup(struct obd_device *obd)
430 DECLARE_LU_VARS(ldt, d);
436 ldt = obd->obd_type->typ_lu;
439 struct lu_context ctx;
442 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
444 lu_context_enter(&ctx);
445 ldt->ldt_ops->ldto_device_free(&ctx, d);
446 lu_context_exit(&ctx);
447 lu_context_fini(&ctx);
448 obd->obd_lu_dev = NULL;
453 OBD_CHECK_DT_OP(obd, cleanup, 0);
454 rc = OBP(obd, cleanup)(obd);
456 OBD_COUNTER_INCREMENT(obd, cleanup);
461 obd_process_config(struct obd_device *obd, int datalen, void *data)
464 DECLARE_LU_VARS(ldt, d);
470 ldt = obd->obd_type->typ_lu;
472 if (ldt != NULL && d != NULL) {
473 struct lu_context ctx;
475 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
477 lu_context_enter(&ctx);
478 rc = d->ld_ops->ldo_process_config(&ctx, d, data);
479 lu_context_exit(&ctx);
480 lu_context_fini(&ctx);
485 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
486 rc = OBP(obd, process_config)(obd, datalen, data);
488 OBD_COUNTER_INCREMENT(obd, process_config);
493 /* Pack an in-memory MD struct for storage on disk.
494 * Returns +ve size of packed MD (0 for free), or -ve error.
496 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
497 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
498 * If @*disk_tgt == NULL, it will be allocated
500 static inline int obd_packmd(struct obd_export *exp,
501 struct lov_mds_md **disk_tgt,
502 struct lov_stripe_md *mem_src)
507 EXP_CHECK_DT_OP(exp, packmd);
508 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
510 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
514 static inline int obd_size_diskmd(struct obd_export *exp,
515 struct lov_stripe_md *mem_src)
517 return obd_packmd(exp, NULL, mem_src);
520 /* helper functions */
521 static inline int obd_alloc_diskmd(struct obd_export *exp,
522 struct lov_mds_md **disk_tgt)
525 LASSERT(*disk_tgt == NULL);
526 return obd_packmd(exp, disk_tgt, NULL);
529 static inline int obd_free_diskmd(struct obd_export *exp,
530 struct lov_mds_md **disk_tgt)
534 return obd_packmd(exp, disk_tgt, NULL);
537 /* Unpack an MD struct from disk to in-memory format.
538 * Returns +ve size of unpacked MD (0 for free), or -ve error.
540 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
541 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
542 * If @*mem_tgt == NULL, it will be allocated
544 static inline int obd_unpackmd(struct obd_export *exp,
545 struct lov_stripe_md **mem_tgt,
546 struct lov_mds_md *disk_src,
552 EXP_CHECK_DT_OP(exp, unpackmd);
553 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
555 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
559 /* helper functions */
560 static inline int obd_alloc_memmd(struct obd_export *exp,
561 struct lov_stripe_md **mem_tgt)
564 LASSERT(*mem_tgt == NULL);
565 return obd_unpackmd(exp, mem_tgt, NULL, 0);
568 static inline int obd_free_memmd(struct obd_export *exp,
569 struct lov_stripe_md **mem_tgt)
573 return obd_unpackmd(exp, mem_tgt, NULL, 0);
576 static inline int obd_checkmd(struct obd_export *exp,
577 struct obd_export *md_exp,
578 struct lov_stripe_md *mem_tgt)
583 EXP_CHECK_DT_OP(exp, checkmd);
584 OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
586 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
590 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
591 struct lov_stripe_md **ea,
592 struct obd_trans_info *oti)
597 EXP_CHECK_DT_OP(exp, create);
598 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
600 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
604 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
605 struct lov_stripe_md *ea,
606 struct obd_trans_info *oti,
607 struct obd_export *md_exp)
612 EXP_CHECK_DT_OP(exp, destroy);
613 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
615 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
619 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
624 EXP_CHECK_DT_OP(exp, getattr);
625 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
627 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
631 static inline int obd_getattr_async(struct obd_export *exp,
632 struct obd_info *oinfo,
633 struct ptlrpc_request_set *set)
638 EXP_CHECK_DT_OP(exp, getattr_async);
639 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr_async);
641 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
645 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
646 struct obd_trans_info *oti)
651 EXP_CHECK_DT_OP(exp, setattr);
652 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
654 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
658 /* This performs all the requests set init/wait/destroy actions. */
659 static inline int obd_setattr_rqset(struct obd_export *exp,
660 struct obd_info *oinfo,
661 struct obd_trans_info *oti)
663 struct ptlrpc_request_set *set = NULL;
667 EXP_CHECK_DT_OP(exp, setattr_async);
668 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
670 set = ptlrpc_prep_set();
674 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
676 rc = ptlrpc_set_wait(set);
677 ptlrpc_set_destroy(set);
681 /* This adds all the requests into @set if @set != NULL, otherwise
682 all requests are sent asynchronously without waiting for response. */
683 static inline int obd_setattr_async(struct obd_export *exp,
684 struct obd_info *oinfo,
685 struct obd_trans_info *oti,
686 struct ptlrpc_request_set *set)
691 EXP_CHECK_DT_OP(exp, setattr_async);
692 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
694 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
698 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
701 struct obd_device *obd = imp->imp_obd;
705 OBD_CHECK_DEV_ACTIVE(obd);
706 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
707 OBD_COUNTER_INCREMENT(obd, add_conn);
709 rc = OBP(obd, add_conn)(imp, uuid, priority);
713 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
715 struct obd_device *obd = imp->imp_obd;
719 OBD_CHECK_DEV_ACTIVE(obd);
720 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
721 OBD_COUNTER_INCREMENT(obd, del_conn);
723 rc = OBP(obd, del_conn)(imp, uuid);
727 static inline int obd_connect(const struct lu_context *ctx,
728 struct lustre_handle *conn,struct obd_device *obd,
729 struct obd_uuid *cluuid,
730 struct obd_connect_data *d)
733 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
736 OBD_CHECK_DEV_ACTIVE(obd);
737 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
738 OBD_COUNTER_INCREMENT(obd, connect);
740 rc = OBP(obd, connect)(ctx, conn, obd, cluuid, d);
741 /* check that only subset is granted */
742 LASSERT(ergo(d != NULL,
743 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
747 static inline int obd_reconnect(struct obd_export *exp,
748 struct obd_device *obd,
749 struct obd_uuid *cluuid,
750 struct obd_connect_data *d)
753 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
756 OBD_CHECK_DEV_ACTIVE(obd);
757 OBD_CHECK_DT_OP(obd, reconnect, 0);
758 OBD_COUNTER_INCREMENT(obd, reconnect);
760 rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
761 /* check that only subset is granted */
762 LASSERT(ergo(d != NULL,
763 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
767 static inline int obd_disconnect(struct obd_export *exp)
772 EXP_CHECK_DT_OP(exp, disconnect);
773 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
775 rc = OBP(exp->exp_obd, disconnect)(exp);
779 static inline int obd_fid_init(struct obd_export *exp)
784 if (OBP(exp->exp_obd, fid_init) == NULL)
787 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_init);
789 rc = OBP(exp->exp_obd, fid_init)(exp);
793 static inline int obd_fid_fini(struct obd_export *exp)
798 if (OBP(exp->exp_obd, fid_fini) == NULL)
801 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_fini);
803 rc = OBP(exp->exp_obd, fid_fini)(exp);
807 static inline int obd_fid_alloc(struct obd_export *exp,
809 struct lu_placement_hint *hint)
814 if (OBP(exp->exp_obd, fid_alloc) == NULL)
817 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
819 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
823 static inline int obd_fid_delete(struct obd_export *exp,
824 const struct lu_fid *fid)
829 if (OBP(exp->exp_obd, fid_delete) == NULL)
832 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
833 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
837 static inline int obd_ping(struct obd_export *exp)
842 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
843 OBD_COUNTER_INCREMENT(exp->exp_obd, ping);
845 rc = OBP(exp->exp_obd, ping)(exp);
849 static inline int obd_init_export(struct obd_export *exp)
854 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
855 OBP((exp)->exp_obd, init_export))
856 rc = OBP(exp->exp_obd, init_export)(exp);
860 static inline int obd_destroy_export(struct obd_export *exp)
863 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
864 OBP((exp)->exp_obd, destroy_export))
865 OBP(exp->exp_obd, destroy_export)(exp);
869 static inline int obd_extent_calc(struct obd_export *exp,
870 struct lov_stripe_md *md,
871 int cmd, obd_off *offset)
875 EXP_CHECK_DT_OP(exp, extent_calc);
876 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
880 static inline struct dentry *
881 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
883 LASSERT(exp->exp_obd);
885 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
890 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
892 LASSERT(exp->exp_obd);
893 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
895 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
896 dentry, exp->exp_obd);
902 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
905 /* @max_age is the oldest time in jiffies that we accept using a cached data.
906 * If the cache is older than @max_age we will get a new value from the
907 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
908 static inline int obd_statfs_async(struct obd_device *obd,
909 struct obd_info *oinfo,
911 struct ptlrpc_request_set *rqset)
919 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
920 OBD_COUNTER_INCREMENT(obd, statfs);
922 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
923 obd->obd_osfs_age, max_age);
924 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
925 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
927 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
928 spin_lock(&obd->obd_osfs_lock);
929 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
930 spin_unlock(&obd->obd_osfs_lock);
932 oinfo->oi_cb_up(oinfo, 0);
937 static inline int obd_statfs_rqset(struct obd_device *obd,
938 struct obd_statfs *osfs, __u64 max_age)
940 struct ptlrpc_request_set *set = NULL;
941 struct obd_info oinfo = { { { 0 } } };
945 set = ptlrpc_prep_set();
949 oinfo.oi_osfs = osfs;
950 rc = obd_statfs_async(obd, &oinfo, max_age, set);
952 rc = ptlrpc_set_wait(set);
953 ptlrpc_set_destroy(set);
957 /* @max_age is the oldest time in jiffies that we accept using a cached data.
958 * If the cache is older than @max_age we will get a new value from the
959 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
960 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
969 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
970 OBD_COUNTER_INCREMENT(obd, statfs);
972 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
973 obd->obd_osfs_age, max_age);
974 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
975 rc = OBP(obd, statfs)(obd, osfs, max_age);
977 spin_lock(&obd->obd_osfs_lock);
978 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
979 obd->obd_osfs_age = cfs_time_current_64();
980 spin_unlock(&obd->obd_osfs_lock);
983 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
984 spin_lock(&obd->obd_osfs_lock);
985 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
986 spin_unlock(&obd->obd_osfs_lock);
991 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
992 struct lov_stripe_md *ea, obd_size start,
998 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
999 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
1001 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
1005 static inline int obd_punch_rqset(struct obd_export *exp,
1006 struct obd_info *oinfo,
1007 struct obd_trans_info *oti)
1009 struct ptlrpc_request_set *set = NULL;
1013 EXP_CHECK_DT_OP(exp, punch);
1014 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1016 set = ptlrpc_prep_set();
1020 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1022 rc = ptlrpc_set_wait(set);
1023 ptlrpc_set_destroy(set);
1027 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1028 struct obd_trans_info *oti,
1029 struct ptlrpc_request_set *rqset)
1034 EXP_CHECK_DT_OP(exp, punch);
1035 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1037 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1041 static inline int obd_brw(int cmd, struct obd_export *exp,
1042 struct obd_info *oinfo, obd_count oa_bufs,
1043 struct brw_page *pg, struct obd_trans_info *oti)
1048 EXP_CHECK_DT_OP(exp, brw);
1049 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
1051 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1052 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1053 "or OBD_BRW_CHECK\n");
1057 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1061 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1062 struct obd_info *oinfo, obd_count oa_bufs,
1063 struct brw_page *pg, struct obd_trans_info *oti,
1064 struct ptlrpc_request_set *set)
1069 EXP_CHECK_DT_OP(exp, brw_async);
1070 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
1072 if (!(cmd & OBD_BRW_RWMASK)) {
1073 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1077 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1081 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1082 struct obdo *oa, struct lov_stripe_md *lsm,
1083 obd_count oa_bufs, struct brw_page *pg,
1084 struct obd_trans_info *oti)
1086 struct ptlrpc_request_set *set = NULL;
1087 struct obd_info oinfo = { { { 0 } } };
1091 set = ptlrpc_prep_set();
1097 rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1099 rc = ptlrpc_set_wait(set);
1101 CERROR("error from callback: rc = %d\n", rc);
1103 CDEBUG(D_INODE, "error from obd_brw_async: rc = %d\n", rc);
1105 ptlrpc_set_destroy(set);
1109 static inline int obd_prep_async_page(struct obd_export *exp,
1110 struct lov_stripe_md *lsm,
1111 struct lov_oinfo *loi,
1112 struct page *page, obd_off offset,
1113 struct obd_async_page_ops *ops,
1114 void *data, void **res)
1119 OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
1120 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
1122 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1127 static inline int obd_queue_async_io(struct obd_export *exp,
1128 struct lov_stripe_md *lsm,
1129 struct lov_oinfo *loi, void *cookie,
1130 int cmd, obd_off off, int count,
1131 obd_flag brw_flags, obd_flag async_flags)
1136 OBD_CHECK_DT_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
1137 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
1138 LASSERT(cmd & OBD_BRW_RWMASK);
1140 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1141 count, brw_flags, async_flags);
1145 static inline int obd_set_async_flags(struct obd_export *exp,
1146 struct lov_stripe_md *lsm,
1147 struct lov_oinfo *loi, void *cookie,
1148 obd_flag async_flags)
1153 OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1154 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
1156 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1161 static inline int obd_queue_group_io(struct obd_export *exp,
1162 struct lov_stripe_md *lsm,
1163 struct lov_oinfo *loi,
1164 struct obd_io_group *oig,
1165 void *cookie, int cmd, obd_off off,
1166 int count, obd_flag brw_flags,
1167 obd_flag async_flags)
1172 OBD_CHECK_DT_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1173 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
1174 LASSERT(cmd & OBD_BRW_RWMASK);
1176 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1177 cmd, off, count, brw_flags,
1182 static inline int obd_trigger_group_io(struct obd_export *exp,
1183 struct lov_stripe_md *lsm,
1184 struct lov_oinfo *loi,
1185 struct obd_io_group *oig)
1190 OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1191 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
1193 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1197 static inline int obd_teardown_async_page(struct obd_export *exp,
1198 struct lov_stripe_md *lsm,
1199 struct lov_oinfo *loi, void *cookie)
1204 OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1205 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
1207 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1211 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1212 int objcount, struct obd_ioobj *obj,
1213 int niocount, struct niobuf_remote *remote,
1214 struct niobuf_local *local,
1215 struct obd_trans_info *oti)
1220 OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1221 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1223 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1224 remote, local, oti);
1228 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1229 int objcount, struct obd_ioobj *obj,
1230 int niocount, struct niobuf_local *local,
1231 struct obd_trans_info *oti, int rc)
1235 OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1236 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1238 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1243 static inline int obd_merge_lvb(struct obd_export *exp,
1244 struct lov_stripe_md *lsm,
1245 struct ost_lvb *lvb, int kms_only)
1250 OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1251 OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1253 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1257 static inline int obd_adjust_kms(struct obd_export *exp,
1258 struct lov_stripe_md *lsm, obd_off size,
1264 OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1265 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1267 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1271 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1272 int len, void *karg, void *uarg)
1277 EXP_CHECK_DT_OP(exp, iocontrol);
1278 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1280 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1284 static inline int obd_enqueue_rqset(struct obd_export *exp,
1285 struct obd_info *oinfo,
1286 struct obd_enqueue_info *einfo)
1291 EXP_CHECK_DT_OP(exp, enqueue);
1292 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1294 einfo->ei_rqset = ptlrpc_prep_set();
1295 if (einfo->ei_rqset == NULL)
1298 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1300 rc = ptlrpc_set_wait(einfo->ei_rqset);
1301 ptlrpc_set_destroy(einfo->ei_rqset);
1302 einfo->ei_rqset = NULL;
1307 static inline int obd_enqueue(struct obd_export *exp,
1308 struct obd_info *oinfo,
1309 struct obd_enqueue_info *einfo)
1314 EXP_CHECK_DT_OP(exp, enqueue);
1315 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1317 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1321 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1322 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1323 int *flags, void *data, struct lustre_handle *lockh)
1328 EXP_CHECK_DT_OP(exp, match);
1329 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1331 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1336 static inline int obd_change_cbdata(struct obd_export *exp,
1337 struct lov_stripe_md *lsm,
1338 ldlm_iterator_t it, void *data)
1343 EXP_CHECK_DT_OP(exp, change_cbdata);
1344 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1346 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1350 static inline int obd_cancel(struct obd_export *exp,
1351 struct lov_stripe_md *ea, __u32 mode,
1352 struct lustre_handle *lockh)
1357 EXP_CHECK_DT_OP(exp, cancel);
1358 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1360 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1364 static inline int obd_cancel_unused(struct obd_export *exp,
1365 struct lov_stripe_md *ea,
1366 int flags, void *opaque)
1371 EXP_CHECK_DT_OP(exp, cancel_unused);
1372 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1374 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1378 static inline int obd_join_lru(struct obd_export *exp,
1379 struct lov_stripe_md *ea, int join)
1384 EXP_CHECK_DT_OP(exp, join_lru);
1385 OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1387 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1391 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1393 int objcount, struct obd_ioobj *obj,
1394 int niocount, struct niobuf_remote *remote)
1398 EXP_CHECK_DT_OP(exp, preprw);
1399 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1401 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1403 class_export_put(exp);
1407 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1408 struct obd_client_handle *handle, int flag)
1412 EXP_CHECK_DT_OP(exp, pin);
1413 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1415 rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1419 static inline int obd_unpin(struct obd_export *exp,
1420 struct obd_client_handle *handle, int flag)
1424 EXP_CHECK_DT_OP(exp, unpin);
1425 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1427 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1432 static inline void obd_import_event(struct obd_device *obd,
1433 struct obd_import *imp,
1434 enum obd_import_event event)
1437 CERROR("NULL device\n");
1441 if (obd->obd_set_up && OBP(obd, import_event)) {
1442 OBD_COUNTER_INCREMENT(obd, import_event);
1443 OBP(obd, import_event)(obd, imp, event);
1447 static inline int obd_notify(struct obd_device *obd,
1448 struct obd_device *watched,
1449 enum obd_notify_event ev,
1454 /* the check for async_recov is a complete hack - I'm hereby
1455 overloading the meaning to also mean "this was called from
1456 mds_postsetup". I know that my mds is able to handle notifies
1457 by this point, and it needs to get them to execute mds_postrecov. */
1458 if (!obd->obd_set_up && !obd->obd_async_recov) {
1459 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1463 if (!OBP(obd, notify)) {
1464 CERROR("obd %s has no notify handler\n", obd->obd_name);
1468 OBD_COUNTER_INCREMENT(obd, notify);
1469 return OBP(obd, notify)(obd, watched, ev, data);
1472 static inline int obd_notify_observer(struct obd_device *observer,
1473 struct obd_device *observed,
1474 enum obd_notify_event ev,
1480 struct obd_notify_upcall *onu;
1482 if (observer->obd_observer)
1483 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1487 * Also, call non-obd listener, if any
1489 onu = &observer->obd_upcall;
1490 if (onu->onu_upcall != NULL)
1491 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1495 return rc1 ? rc1 : rc2;
1498 static inline int obd_quotacheck(struct obd_export *exp,
1499 struct obd_quotactl *oqctl)
1504 EXP_CHECK_DT_OP(exp, quotacheck);
1505 OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1507 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1511 static inline int obd_quotactl(struct obd_export *exp,
1512 struct obd_quotactl *oqctl)
1517 EXP_CHECK_DT_OP(exp, quotactl);
1518 OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1520 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1524 static inline int obd_health_check(struct obd_device *obd)
1526 /* returns: 0 on healthy
1527 * >0 on unhealthy + reason code/flag
1528 * however the only suppored reason == 1 right now
1529 * We'll need to define some better reasons
1530 * or flags in the future.
1536 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1537 if (obd == NULL || !OBT(obd)) {
1538 CERROR("cleaned up obd\n");
1539 RETURN(-EOPNOTSUPP);
1541 if (!obd->obd_set_up || obd->obd_stopping)
1543 if (!OBP(obd, health_check))
1546 rc = OBP(obd, health_check)(obd);
1550 static inline int obd_register_observer(struct obd_device *obd,
1551 struct obd_device *observer)
1555 if (obd->obd_observer && observer)
1557 obd->obd_observer = observer;
1561 /* metadata helpers */
1562 static inline int md_getstatus(struct obd_export *exp,
1568 EXP_CHECK_MD_OP(exp, getstatus);
1569 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1570 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1574 static inline int md_getattr(struct obd_export *exp,
1575 const struct lu_fid *fid,
1576 obd_valid valid, int ea_size,
1577 struct ptlrpc_request **request)
1581 EXP_CHECK_MD_OP(exp, getattr);
1582 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1583 rc = MDP(exp->exp_obd, getattr)(exp, fid, valid,
1588 static inline int md_change_cbdata(struct obd_export *exp,
1589 const struct lu_fid *fid,
1590 ldlm_iterator_t it, void *data)
1594 EXP_CHECK_MD_OP(exp, change_cbdata);
1595 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1596 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1600 static inline int md_close(struct obd_export *exp,
1601 struct md_op_data *op_data,
1602 struct obd_client_handle *och,
1603 struct ptlrpc_request **request)
1607 EXP_CHECK_MD_OP(exp, close);
1608 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1609 rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1613 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1614 const void *data, int datalen, int mode,
1615 __u32 uid, __u32 gid, __u32 cap_effective, __u64 rdev,
1616 struct ptlrpc_request **request)
1620 EXP_CHECK_MD_OP(exp, create);
1621 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1622 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1623 uid, gid, cap_effective, rdev, request);
1627 static inline int md_done_writing(struct obd_export *exp,
1628 struct md_op_data *op_data)
1632 EXP_CHECK_MD_OP(exp, done_writing);
1633 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1634 rc = MDP(exp->exp_obd, done_writing)(exp, op_data);
1638 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1639 struct lookup_intent *it, int lock_mode,
1640 struct md_op_data *op_data,
1641 struct lustre_handle *lockh,
1642 void *lmm, int lmmsize,
1643 ldlm_completion_callback cb_completion,
1644 ldlm_blocking_callback cb_blocking,
1645 void *cb_data, int extra_lock_flags)
1649 EXP_CHECK_MD_OP(exp, enqueue);
1650 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1651 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1652 op_data, lockh, lmm, lmmsize,
1653 cb_completion, cb_blocking,
1654 cb_data, extra_lock_flags);
1658 static inline int md_getattr_name(struct obd_export *exp,
1659 const struct lu_fid *fid,
1660 const char *filename, int namelen,
1661 obd_valid valid, int ea_size,
1662 struct ptlrpc_request **request)
1666 EXP_CHECK_MD_OP(exp, getattr_name);
1667 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1668 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1669 valid, ea_size, request);
1673 static inline int md_intent_lock(struct obd_export *exp,
1674 struct md_op_data *op_data,
1675 void *lmm, int lmmsize,
1676 struct lookup_intent *it,
1677 int flags, struct ptlrpc_request **reqp,
1678 ldlm_blocking_callback cb_blocking,
1679 int extra_lock_flags)
1683 EXP_CHECK_MD_OP(exp, intent_lock);
1684 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1685 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1686 it, flags, reqp, cb_blocking,
1691 static inline int md_link(struct obd_export *exp,
1692 struct md_op_data *op_data,
1693 struct ptlrpc_request **request)
1697 EXP_CHECK_MD_OP(exp, link);
1698 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1699 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1703 static inline int md_rename(struct obd_export *exp,
1704 struct md_op_data *op_data,
1705 const char *old, int oldlen,
1706 const char *new, int newlen,
1707 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_setattr(struct obd_export *exp, struct md_op_data *op_data,
1719 struct iattr *iattr, void *ea, int ealen,
1720 void *ea2, int ea2len, struct ptlrpc_request **request)
1724 EXP_CHECK_MD_OP(exp, setattr);
1725 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1726 rc = MDP(exp->exp_obd, setattr)(exp, op_data, iattr, ea, ealen,
1727 ea2, ea2len, request);
1731 static inline int md_sync(struct obd_export *exp,
1732 const struct lu_fid *fid,
1733 struct ptlrpc_request **request)
1737 EXP_CHECK_MD_OP(exp, sync);
1738 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1739 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1743 static inline int md_readpage(struct obd_export *exp,
1744 const struct lu_fid *fid,
1745 __u64 offset, struct page *page,
1746 struct ptlrpc_request **request)
1750 EXP_CHECK_MD_OP(exp, readpage);
1751 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1752 rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1756 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1757 struct ptlrpc_request **request)
1761 EXP_CHECK_MD_OP(exp, unlink);
1762 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1763 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1767 static inline int md_get_lustre_md(struct obd_export *exp,
1768 struct ptlrpc_request *req,
1769 int offset, struct obd_export *dt_exp,
1770 struct lustre_md *md)
1773 EXP_CHECK_MD_OP(exp, get_lustre_md);
1774 MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1775 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1779 static inline int md_free_lustre_md(struct obd_export *exp,
1780 struct lustre_md *md)
1783 EXP_CHECK_MD_OP(exp, free_lustre_md);
1784 MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1785 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1788 static inline int md_setxattr(struct obd_export *exp,
1789 const struct lu_fid *fid,
1790 obd_valid valid, const char *name,
1791 const char *input, int input_size,
1792 int output_size, int flags,
1793 struct ptlrpc_request **request)
1796 EXP_CHECK_MD_OP(exp, setxattr);
1797 MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1798 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1799 input_size, output_size, flags,
1803 static inline int md_getxattr(struct obd_export *exp,
1804 const struct lu_fid *fid,
1805 obd_valid valid, const char *name,
1806 const char *input, int input_size,
1807 int output_size, int flags,
1808 struct ptlrpc_request **request)
1811 EXP_CHECK_MD_OP(exp, getxattr);
1812 MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1813 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1814 input_size, output_size, flags,
1818 static inline int md_set_open_replay_data(struct obd_export *exp,
1819 struct obd_client_handle *och,
1820 struct ptlrpc_request *open_req)
1823 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1824 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1825 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1828 static inline int md_clear_open_replay_data(struct obd_export *exp,
1829 struct obd_client_handle *och)
1832 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1833 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1834 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1837 static inline int md_set_lock_data(struct obd_export *exp,
1838 __u64 *lockh, void *data)
1841 EXP_CHECK_MD_OP(exp, set_lock_data);
1842 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1843 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1846 static inline int md_cancel_unused(struct obd_export *exp,
1847 const struct lu_fid *fid,
1848 int flags, void *opaque)
1853 EXP_CHECK_MD_OP(exp, cancel_unused);
1854 MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1856 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1860 static inline int md_lock_match(struct obd_export *exp, int flags,
1861 const struct lu_fid *fid, ldlm_type_t type,
1862 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1863 struct lustre_handle *lockh)
1866 EXP_CHECK_MD_OP(exp, lock_match);
1867 MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1868 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1869 policy, mode, lockh));
1872 static inline int md_init_ea_size(struct obd_export *exp,
1873 int easize, int def_asize,
1877 EXP_CHECK_MD_OP(exp, init_ea_size);
1878 MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1879 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize,
1884 /* OBD Metadata Support */
1885 extern int obd_init_caches(void);
1886 extern void obd_cleanup_caches(void);
1888 /* support routines */
1889 extern cfs_mem_cache_t *obdo_cachep;
1890 static inline struct obdo *obdo_alloc(void)
1893 OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1897 static inline void obdo_free(struct obdo *oa)
1899 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1902 static inline void obdo2fid(struct obdo *oa,
1905 /* something here */
1908 static inline void fid2obdo(struct lu_fid *fid,
1911 /* something here */
1914 /* I'm as embarrassed about this as you are.
1916 * <shaver> // XXX do not look into _superhack with remaining eye
1917 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1918 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1921 extern void obd_sysctl_init (void);
1922 extern void obd_sysctl_clean (void);
1925 typedef __u8 class_uuid_t[16];
1926 void class_generate_random_uuid(class_uuid_t uuid);
1927 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1930 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1931 int class_add_uuid(const char *uuid, __u64 nid);
1932 int class_del_uuid (const char *uuid);
1933 void class_init_uuidlist(void);
1934 void class_exit_uuidlist(void);
1937 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1938 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1940 #endif /* __LINUX_OBD_CLASS_H */