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 520
46 extern struct obd_device obd_dev[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(struct obd_type *type, 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,
78 int oig_init(struct obd_io_group **oig);
79 void oig_add_one(struct obd_io_group *oig,
80 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_attach(struct lustre_cfg *lcfg);
94 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
95 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
96 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
97 struct obd_device *class_incref(struct obd_device *obd);
98 void class_decref(struct obd_device *obd);
100 #define CFG_F_START 0x01 /* Set when we start updating from a log */
101 #define CFG_F_MARKER 0x02 /* We are within a maker */
102 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
103 #define CFG_F_COMPAT146 0x08 /* Translation to new obd names required */
104 #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 unsigned int cld_stopping:1;
130 struct lustre_profile {
131 struct list_head lp_list;
137 struct lustre_profile *class_get_profile(const char * prof);
138 void class_del_profile(const char *prof);
141 #define class_export_get(exp) \
143 struct obd_export *exp_ = exp; \
144 atomic_inc(&exp_->exp_refcount); \
145 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
146 atomic_read(&exp_->exp_refcount)); \
150 #define class_export_put(exp) \
152 LASSERT((exp) != NULL); \
153 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
154 atomic_read(&(exp)->exp_refcount) - 1); \
155 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
156 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
157 __class_export_put(exp); \
159 void __class_export_put(struct obd_export *);
160 struct obd_export *class_new_export(struct obd_device *obddev,
161 struct obd_uuid *cluuid);
162 void class_unlink_export(struct obd_export *exp);
164 struct obd_import *class_import_get(struct obd_import *);
165 void class_import_put(struct obd_import *);
166 struct obd_import *class_new_import(struct obd_device *obd);
167 void class_destroy_import(struct obd_import *exp);
169 struct obd_type *class_search_type(const char *name);
170 struct obd_type *class_get_type(const char *name);
171 void class_put_type(struct obd_type *type);
172 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
173 struct obd_uuid *cluuid);
174 int class_disconnect(struct obd_export *exp);
175 void class_fail_export(struct obd_export *exp);
176 void class_disconnect_exports(struct obd_device *obddev);
177 void class_disconnect_stale_exports(struct obd_device *obddev);
178 int class_manual_cleanup(struct obd_device *obd);
180 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
181 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
182 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
185 #define OBT(dev) (dev)->obd_type
186 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
187 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
188 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
190 /* Ensure obd_setup: used for cleanup which must be called
191 while obd is stopping */
192 #define OBD_CHECK_DEV(obd) \
195 CERROR("NULL device\n"); \
200 /* ensure obd_setup and !obd_stopping */
201 #define OBD_CHECK_DEV_ACTIVE(obd) \
203 OBD_CHECK_DEV(obd); \
204 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
205 CERROR("Device %d not setup\n", \
213 #define OBD_COUNTER_OFFSET(op) \
214 ((offsetof(struct obd_ops, o_ ## op) - \
215 offsetof(struct obd_ops, o_iocontrol)) \
216 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
218 #define OBD_COUNTER_INCREMENT(obd, op) \
219 if ((obd)->obd_stats != NULL) { \
220 unsigned int coffset; \
221 coffset = (unsigned int)(obd)->obd_cntr_base + \
222 OBD_COUNTER_OFFSET(op); \
223 LASSERT(coffset < obd->obd_stats->ls_num); \
224 lprocfs_counter_incr(obd->obd_stats, coffset); \
227 #define MD_COUNTER_OFFSET(op) \
228 ((offsetof(struct md_ops, m_ ## op) - \
229 offsetof(struct md_ops, m_getstatus)) \
230 / sizeof(((struct md_ops *)(0))->m_getstatus))
232 #define MD_COUNTER_INCREMENT(obd, op) \
233 if ((obd)->md_stats != NULL) { \
234 unsigned int coffset; \
235 coffset = (unsigned int)(obd)->md_cntr_base + \
236 MD_COUNTER_OFFSET(op); \
237 LASSERT(coffset < (obd)->md_stats->ls_num); \
238 lprocfs_counter_incr((obd)->md_stats, coffset); \
242 #define OBD_COUNTER_OFFSET(op)
243 #define OBD_COUNTER_INCREMENT(obd, op)
244 #define MD_COUNTER_INCREMENT(obd, op)
247 #define OBD_CHECK_MD_OP(obd, op, err) \
249 if (!OBT(obd) || !MDP((obd), op)) { \
251 CERROR("md_" #op ": dev %s/%d no operation\n", \
252 obd->obd_name, obd->obd_minor); \
257 #define EXP_CHECK_MD_OP(exp, op) \
259 if ((exp) == NULL) { \
260 CERROR("obd_" #op ": NULL export\n"); \
263 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
264 CERROR("obd_" #op ": cleaned up obd\n"); \
265 RETURN(-EOPNOTSUPP); \
267 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
268 CERROR("obd_" #op ": dev %s/%d no operation\n", \
269 (exp)->exp_obd->obd_name, \
270 (exp)->exp_obd->obd_minor); \
271 RETURN(-EOPNOTSUPP); \
276 #define OBD_CHECK_DT_OP(obd, op, err) \
278 if (!OBT(obd) || !OBP((obd), op)) { \
280 CERROR("obd_" #op ": dev %d no operation\n", \
286 #define EXP_CHECK_DT_OP(exp, op) \
288 if ((exp) == NULL) { \
289 CERROR("obd_" #op ": NULL export\n"); \
292 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
293 CERROR("obd_" #op ": cleaned up obd\n"); \
294 RETURN(-EOPNOTSUPP); \
296 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
297 CERROR("obd_" #op ": dev %d no operation\n", \
298 (exp)->exp_obd->obd_minor); \
299 RETURN(-EOPNOTSUPP); \
303 #define CTXT_CHECK_OP(ctxt, op, err) \
305 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
307 CERROR("lop_" #op ": dev %d no operation\n", \
308 ctxt->loc_obd->obd_minor); \
313 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
314 void *key, __u32 *vallen, void *val)
319 EXP_CHECK_DT_OP(exp, get_info);
320 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
322 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
326 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
327 void *key, obd_count vallen, void *val,
328 struct ptlrpc_request_set *set)
333 EXP_CHECK_DT_OP(exp, set_info_async);
334 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info_async);
336 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
342 #define DECLARE_LU_VARS(ldt, d) \
343 struct lu_device_type *ldt; \
346 #define DECLARE_LU_VARS(ldt, d) \
347 extern void __placeholder_to_put_a_semicolon(void)
349 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
352 DECLARE_LU_VARS(ldt, d);
356 ldt = obd->obd_type->typ_lu;
358 struct lu_context ctx;
360 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
362 lu_context_enter(&ctx);
363 d = ldt->ldt_ops->ldto_device_alloc(&ctx, ldt, cfg);
364 lu_context_exit(&ctx);
365 lu_context_fini(&ctx);
376 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
377 OBD_COUNTER_INCREMENT(obd, setup);
378 rc = OBP(obd, setup)(obd, cfg);
383 static inline int obd_precleanup(struct obd_device *obd,
384 enum obd_cleanup_stage cleanup_stage)
389 OBD_CHECK_DT_OP(obd, precleanup, 0);
390 OBD_COUNTER_INCREMENT(obd, precleanup);
392 rc = OBP(obd, precleanup)(obd, cleanup_stage);
396 static inline int obd_cleanup(struct obd_device *obd)
399 DECLARE_LU_VARS(ldt, d);
405 ldt = obd->obd_type->typ_lu;
407 if (ldt != NULL && d != NULL) {
408 struct lu_context ctx;
410 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
412 lu_context_enter(&ctx);
413 ldt->ldt_ops->ldto_device_free(&ctx, d);
414 lu_context_exit(&ctx);
415 lu_context_fini(&ctx);
416 obd->obd_lu_dev = NULL;
422 OBD_CHECK_DT_OP(obd, cleanup, 0);
423 rc = OBP(obd, cleanup)(obd);
425 OBD_COUNTER_INCREMENT(obd, cleanup);
430 obd_process_config(struct obd_device *obd, int datalen, void *data)
433 DECLARE_LU_VARS(ldt, d);
439 ldt = obd->obd_type->typ_lu;
441 if (ldt != NULL && d != NULL) {
442 struct lu_context ctx;
444 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
446 lu_context_enter(&ctx);
447 rc = d->ld_ops->ldo_process_config(&ctx, d, data);
448 lu_context_exit(&ctx);
449 lu_context_fini(&ctx);
454 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
455 rc = OBP(obd, process_config)(obd, datalen, data);
457 OBD_COUNTER_INCREMENT(obd, process_config);
462 /* Pack an in-memory MD struct for storage on disk.
463 * Returns +ve size of packed MD (0 for free), or -ve error.
465 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
466 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
467 * If @*disk_tgt == NULL, it will be allocated
469 static inline int obd_packmd(struct obd_export *exp,
470 struct lov_mds_md **disk_tgt,
471 struct lov_stripe_md *mem_src)
476 EXP_CHECK_DT_OP(exp, packmd);
477 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
479 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
483 static inline int obd_size_diskmd(struct obd_export *exp,
484 struct lov_stripe_md *mem_src)
486 return obd_packmd(exp, NULL, mem_src);
489 /* helper functions */
490 static inline int obd_alloc_diskmd(struct obd_export *exp,
491 struct lov_mds_md **disk_tgt)
494 LASSERT(*disk_tgt == NULL);
495 return obd_packmd(exp, disk_tgt, NULL);
498 static inline int obd_free_diskmd(struct obd_export *exp,
499 struct lov_mds_md **disk_tgt)
503 return obd_packmd(exp, disk_tgt, NULL);
506 /* Unpack an MD struct from disk to in-memory format.
507 * Returns +ve size of unpacked MD (0 for free), or -ve error.
509 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
510 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
511 * If @*mem_tgt == NULL, it will be allocated
513 static inline int obd_unpackmd(struct obd_export *exp,
514 struct lov_stripe_md **mem_tgt,
515 struct lov_mds_md *disk_src,
521 EXP_CHECK_DT_OP(exp, unpackmd);
522 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
524 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
528 /* helper functions */
529 static inline int obd_alloc_memmd(struct obd_export *exp,
530 struct lov_stripe_md **mem_tgt)
533 LASSERT(*mem_tgt == NULL);
534 return obd_unpackmd(exp, mem_tgt, NULL, 0);
537 static inline int obd_free_memmd(struct obd_export *exp,
538 struct lov_stripe_md **mem_tgt)
542 return obd_unpackmd(exp, mem_tgt, NULL, 0);
545 static inline int obd_checkmd(struct obd_export *exp,
546 struct obd_export *md_exp,
547 struct lov_stripe_md *mem_tgt)
552 EXP_CHECK_DT_OP(exp, checkmd);
553 OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
555 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
559 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
560 struct lov_stripe_md **ea,
561 struct obd_trans_info *oti)
566 EXP_CHECK_DT_OP(exp, create);
567 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
569 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
573 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
574 struct lov_stripe_md *ea,
575 struct obd_trans_info *oti,
576 struct obd_export *md_exp)
581 EXP_CHECK_DT_OP(exp, destroy);
582 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
584 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
588 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
589 struct lov_stripe_md *ea)
594 EXP_CHECK_DT_OP(exp, getattr);
595 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
597 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
601 static inline int obd_getattr_async(struct obd_export *exp,
602 struct obdo *obdo, struct lov_stripe_md *ea,
603 struct ptlrpc_request_set *set)
608 EXP_CHECK_DT_OP(exp, getattr);
609 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
611 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
615 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
616 struct lov_stripe_md *ea,
617 struct obd_trans_info *oti)
622 EXP_CHECK_DT_OP(exp, setattr);
623 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
625 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
629 static inline int obd_setattr_async(struct obd_export *exp,
631 struct lov_stripe_md *ea,
632 struct obd_trans_info *oti)
637 EXP_CHECK_DT_OP(exp, setattr_async);
638 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
640 rc = OBP(exp->exp_obd, setattr_async)(exp, obdo, ea, oti);
644 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
647 struct obd_device *obd = imp->imp_obd;
651 OBD_CHECK_DEV_ACTIVE(obd);
652 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
653 OBD_COUNTER_INCREMENT(obd, add_conn);
655 rc = OBP(obd, add_conn)(imp, uuid, priority);
659 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
661 struct obd_device *obd = imp->imp_obd;
665 OBD_CHECK_DEV_ACTIVE(obd);
666 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
667 OBD_COUNTER_INCREMENT(obd, del_conn);
669 rc = OBP(obd, del_conn)(imp, uuid);
673 static inline int obd_connect(const struct lu_context *ctx,
674 struct lustre_handle *conn,struct obd_device *obd,
675 struct obd_uuid *cluuid,
676 struct obd_connect_data *d)
679 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
682 OBD_CHECK_DEV_ACTIVE(obd);
683 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
684 OBD_COUNTER_INCREMENT(obd, connect);
686 rc = OBP(obd, connect)(ctx, conn, obd, cluuid, d);
687 /* check that only subset is granted */
688 LASSERT(ergo(d != NULL,
689 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
693 static inline int obd_reconnect(struct obd_export *exp,
694 struct obd_device *obd,
695 struct obd_uuid *cluuid,
696 struct obd_connect_data *d)
699 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
702 OBD_CHECK_DEV_ACTIVE(obd);
703 OBD_CHECK_DT_OP(obd, reconnect, 0);
704 OBD_COUNTER_INCREMENT(obd, reconnect);
706 rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
707 /* check that only subset is granted */
708 LASSERT(ergo(d != NULL,
709 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
713 static inline int obd_disconnect(struct obd_export *exp)
718 EXP_CHECK_DT_OP(exp, disconnect);
719 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
721 rc = OBP(exp->exp_obd, disconnect)(exp);
725 static inline int obd_fid_init(struct obd_export *exp)
730 if (OBP(exp->exp_obd, fid_init) == NULL)
733 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_init);
735 rc = OBP(exp->exp_obd, fid_init)(exp);
739 static inline int obd_fid_fini(struct obd_export *exp)
744 if (OBP(exp->exp_obd, fid_fini) == NULL)
747 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_fini);
749 rc = OBP(exp->exp_obd, fid_fini)(exp);
753 static inline int obd_fid_alloc(struct obd_export *exp,
755 struct lu_placement_hint *hint)
760 if (OBP(exp->exp_obd, fid_alloc) == NULL)
763 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
765 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
769 static inline int obd_fid_delete(struct obd_export *exp,
775 if (OBP(exp->exp_obd, fid_delete) == NULL)
778 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
779 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
783 static inline int obd_init_export(struct obd_export *exp)
788 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
789 OBP((exp)->exp_obd, init_export))
790 rc = OBP(exp->exp_obd, init_export)(exp);
794 static inline int obd_destroy_export(struct obd_export *exp)
797 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
798 OBP((exp)->exp_obd, destroy_export))
799 OBP(exp->exp_obd, destroy_export)(exp);
803 static inline struct dentry *
804 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
806 LASSERT(exp->exp_obd);
808 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
813 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
815 LASSERT(exp->exp_obd);
816 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
818 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
819 dentry, exp->exp_obd);
825 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
828 /* @max_age is the oldest time in jiffies that we accept using a cached data.
829 * If the cache is older than @max_age we will get a new value from the
830 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
831 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
832 unsigned long max_age)
840 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
841 OBD_COUNTER_INCREMENT(obd, statfs);
843 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
844 if (time_before(obd->obd_osfs_age, max_age)) {
845 rc = OBP(obd, statfs)(obd, osfs, max_age);
847 spin_lock(&obd->obd_osfs_lock);
848 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
849 obd->obd_osfs_age = jiffies;
850 spin_unlock(&obd->obd_osfs_lock);
853 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
854 spin_lock(&obd->obd_osfs_lock);
855 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
856 spin_unlock(&obd->obd_osfs_lock);
861 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
862 struct lov_stripe_md *ea, obd_size start,
868 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
869 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
871 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
875 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
876 struct lov_stripe_md *ea, obd_size start,
877 obd_size end, struct obd_trans_info *oti)
882 EXP_CHECK_DT_OP(exp, punch);
883 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
885 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
889 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
890 struct lov_stripe_md *ea, obd_count oa_bufs,
891 struct brw_page *pg, struct obd_trans_info *oti)
896 EXP_CHECK_DT_OP(exp, brw);
897 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
899 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
900 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
901 "or OBD_BRW_CHECK\n");
905 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
909 static inline int obd_brw_async(int cmd, struct obd_export *exp,
910 struct obdo *oa, struct lov_stripe_md *ea,
911 obd_count oa_bufs, struct brw_page *pg,
912 struct ptlrpc_request_set *set,
913 struct obd_trans_info *oti)
918 EXP_CHECK_DT_OP(exp, brw_async);
919 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
921 if (!(cmd & OBD_BRW_RWMASK)) {
922 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
926 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
931 static inline int obd_prep_async_page(struct obd_export *exp,
932 struct lov_stripe_md *lsm,
933 struct lov_oinfo *loi,
934 struct page *page, obd_off offset,
935 struct obd_async_page_ops *ops,
936 void *data, void **res)
941 OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
942 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
944 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
949 static inline int obd_queue_async_io(struct obd_export *exp,
950 struct lov_stripe_md *lsm,
951 struct lov_oinfo *loi, void *cookie,
952 int cmd, obd_off off, int count,
953 obd_flag brw_flags, obd_flag async_flags)
958 OBD_CHECK_DT_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
959 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
960 LASSERT(cmd & OBD_BRW_RWMASK);
962 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
963 count, brw_flags, async_flags);
967 static inline int obd_set_async_flags(struct obd_export *exp,
968 struct lov_stripe_md *lsm,
969 struct lov_oinfo *loi, void *cookie,
970 obd_flag async_flags)
975 OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
976 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
978 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
983 static inline int obd_queue_group_io(struct obd_export *exp,
984 struct lov_stripe_md *lsm,
985 struct lov_oinfo *loi,
986 struct obd_io_group *oig,
987 void *cookie, int cmd, obd_off off,
988 int count, obd_flag brw_flags,
989 obd_flag async_flags)
994 OBD_CHECK_DT_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
995 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
996 LASSERT(cmd & OBD_BRW_RWMASK);
998 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
999 cmd, off, count, brw_flags,
1004 static inline int obd_trigger_group_io(struct obd_export *exp,
1005 struct lov_stripe_md *lsm,
1006 struct lov_oinfo *loi,
1007 struct obd_io_group *oig)
1012 OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1013 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
1015 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1019 static inline int obd_teardown_async_page(struct obd_export *exp,
1020 struct lov_stripe_md *lsm,
1021 struct lov_oinfo *loi, void *cookie)
1026 OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1027 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
1029 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1033 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1034 int objcount, struct obd_ioobj *obj,
1035 int niocount, struct niobuf_remote *remote,
1036 struct niobuf_local *local,
1037 struct obd_trans_info *oti)
1042 OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1043 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1045 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1046 remote, local, oti);
1050 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1051 int objcount, struct obd_ioobj *obj,
1052 int niocount, struct niobuf_local *local,
1053 struct obd_trans_info *oti, int rc)
1057 OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1058 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1060 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1065 static inline int obd_merge_lvb(struct obd_export *exp,
1066 struct lov_stripe_md *lsm,
1067 struct ost_lvb *lvb, int kms_only)
1072 OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1073 OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1075 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1079 static inline int obd_adjust_kms(struct obd_export *exp,
1080 struct lov_stripe_md *lsm, obd_off size,
1086 OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1087 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1089 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1093 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1094 int len, void *karg, void *uarg)
1099 EXP_CHECK_DT_OP(exp, iocontrol);
1100 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1102 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1106 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
1107 __u32 type, ldlm_policy_data_t *policy,
1108 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
1109 void *gl_cb, void *data, __u32 lvb_len,
1110 void *lvb_swabber, struct lustre_handle *lockh)
1115 EXP_CHECK_DT_OP(exp, enqueue);
1116 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1118 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
1119 bl_cb, cp_cb, gl_cb, data, lvb_len,
1120 lvb_swabber, lockh);
1124 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1125 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1126 int *flags, void *data, struct lustre_handle *lockh)
1131 EXP_CHECK_DT_OP(exp, match);
1132 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1134 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1139 static inline int obd_change_cbdata(struct obd_export *exp,
1140 struct lov_stripe_md *lsm,
1141 ldlm_iterator_t it, void *data)
1146 EXP_CHECK_DT_OP(exp, change_cbdata);
1147 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1149 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1153 static inline int obd_cancel(struct obd_export *exp,
1154 struct lov_stripe_md *ea, __u32 mode,
1155 struct lustre_handle *lockh)
1160 EXP_CHECK_DT_OP(exp, cancel);
1161 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1163 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1167 static inline int obd_cancel_unused(struct obd_export *exp,
1168 struct lov_stripe_md *ea,
1169 int flags, void *opaque)
1174 EXP_CHECK_DT_OP(exp, cancel_unused);
1175 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1177 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1181 static inline int obd_join_lru(struct obd_export *exp,
1182 struct lov_stripe_md *ea, int join)
1187 EXP_CHECK_DT_OP(exp, join_lru);
1188 OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1190 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1194 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1196 int objcount, struct obd_ioobj *obj,
1197 int niocount, struct niobuf_remote *remote)
1201 EXP_CHECK_DT_OP(exp, preprw);
1202 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1204 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1206 class_export_put(exp);
1210 static inline int obd_pin(struct obd_export *exp, struct lu_fid *fid,
1211 struct obd_client_handle *handle, int flag)
1215 EXP_CHECK_DT_OP(exp, pin);
1216 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1218 rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1222 static inline int obd_unpin(struct obd_export *exp,
1223 struct obd_client_handle *handle, int flag)
1227 EXP_CHECK_DT_OP(exp, unpin);
1228 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1230 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1235 static inline void obd_import_event(struct obd_device *obd,
1236 struct obd_import *imp,
1237 enum obd_import_event event)
1240 CERROR("NULL device\n");
1244 if (obd->obd_set_up && OBP(obd, import_event)) {
1245 OBD_COUNTER_INCREMENT(obd, import_event);
1246 OBP(obd, import_event)(obd, imp, event);
1250 static inline int obd_notify(struct obd_device *obd,
1251 struct obd_device *watched,
1252 enum obd_notify_event ev,
1257 /* the check for async_recov is a complete hack - I'm hereby
1258 overloading the meaning to also mean "this was called from
1259 mds_postsetup". I know that my mds is able to handle notifies
1260 by this point, and it needs to get them to execute mds_postrecov. */
1261 if (!obd->obd_set_up && !obd->obd_async_recov) {
1262 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1266 if (!OBP(obd, notify)) {
1267 CERROR("obd %s has no notify handler\n", obd->obd_name);
1271 OBD_COUNTER_INCREMENT(obd, notify);
1272 return OBP(obd, notify)(obd, watched, ev, data);
1275 static inline int obd_notify_observer(struct obd_device *observer,
1276 struct obd_device *observed,
1277 enum obd_notify_event ev,
1283 struct obd_notify_upcall *onu;
1285 if (observer->obd_observer)
1286 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1290 * Also, call non-obd listener, if any
1292 onu = &observer->obd_upcall;
1293 if (onu->onu_upcall != NULL)
1294 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1298 return rc1 ? rc1 : rc2;
1301 static inline int obd_quotacheck(struct obd_export *exp,
1302 struct obd_quotactl *oqctl)
1307 EXP_CHECK_DT_OP(exp, quotacheck);
1308 OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1310 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1314 static inline int obd_quotactl(struct obd_export *exp,
1315 struct obd_quotactl *oqctl)
1320 EXP_CHECK_DT_OP(exp, quotactl);
1321 OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1323 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1327 static inline int obd_health_check(struct obd_device *obd)
1329 /* returns: 0 on healthy
1330 * >0 on unhealthy + reason code/flag
1331 * however the only suppored reason == 1 right now
1332 * We'll need to define some better reasons
1333 * or flags in the future.
1339 /* don't use EXP_CHECK_OP, because NULL method is normal here */
1340 if (obd == NULL || !OBT(obd)) {
1341 CERROR("cleaned up obd\n");
1342 RETURN(-EOPNOTSUPP);
1344 if (!obd->obd_set_up || obd->obd_stopping)
1346 if (!OBP(obd, health_check))
1349 rc = OBP(obd, health_check)(obd);
1353 static inline int obd_register_observer(struct obd_device *obd,
1354 struct obd_device *observer)
1358 if (obd->obd_observer && observer)
1360 obd->obd_observer = observer;
1364 /* metadata helpers */
1365 static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
1370 EXP_CHECK_MD_OP(exp, getstatus);
1371 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1372 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1376 static inline int md_getattr(struct obd_export *exp, struct lu_fid *fid,
1377 obd_valid valid, int ea_size,
1378 struct ptlrpc_request **request)
1382 EXP_CHECK_MD_OP(exp, getattr);
1383 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1384 rc = MDP(exp->exp_obd, getattr)(exp, fid, valid,
1389 static inline int md_change_cbdata(struct obd_export *exp, struct lu_fid *fid,
1390 ldlm_iterator_t it, void *data)
1394 EXP_CHECK_MD_OP(exp, change_cbdata);
1395 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1396 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1400 static inline int md_close(struct obd_export *exp,
1401 struct md_op_data *op_data,
1402 struct obd_client_handle *och,
1403 struct ptlrpc_request **request)
1407 EXP_CHECK_MD_OP(exp, close);
1408 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1409 rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1413 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1414 const void *data, int datalen, int mode,
1415 __u32 uid, __u32 gid, __u32 cap_effective, __u64 rdev,
1416 struct ptlrpc_request **request)
1420 EXP_CHECK_MD_OP(exp, create);
1421 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1422 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1423 uid, gid, cap_effective, rdev, request);
1427 static inline int md_done_writing(struct obd_export *exp,
1428 struct md_op_data *op_data)
1432 EXP_CHECK_MD_OP(exp, done_writing);
1433 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1434 rc = MDP(exp->exp_obd, done_writing)(exp, op_data);
1438 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1439 struct lookup_intent *it, int lock_mode,
1440 struct md_op_data *op_data,
1441 struct lustre_handle *lockh,
1442 void *lmm, int lmmsize,
1443 ldlm_completion_callback cb_completion,
1444 ldlm_blocking_callback cb_blocking,
1445 void *cb_data, int extra_lock_flags)
1449 EXP_CHECK_MD_OP(exp, enqueue);
1450 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1451 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1452 op_data, lockh, lmm, lmmsize,
1453 cb_completion, cb_blocking,
1454 cb_data, extra_lock_flags);
1458 static inline int md_getattr_name(struct obd_export *exp, struct lu_fid *fid,
1459 const char *filename, int namelen,
1460 obd_valid valid, int ea_size,
1461 struct ptlrpc_request **request)
1465 EXP_CHECK_MD_OP(exp, getattr_name);
1466 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1467 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1468 valid, ea_size, request);
1472 static inline int md_intent_lock(struct obd_export *exp,
1473 struct md_op_data *op_data,
1474 void *lmm, int lmmsize,
1475 struct lookup_intent *it,
1476 int flags, struct ptlrpc_request **reqp,
1477 ldlm_blocking_callback cb_blocking,
1478 int extra_lock_flags)
1482 EXP_CHECK_MD_OP(exp, intent_lock);
1483 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1484 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1485 it, flags, reqp, cb_blocking,
1490 static inline int md_link(struct obd_export *exp,
1491 struct md_op_data *op_data,
1492 struct ptlrpc_request **request)
1496 EXP_CHECK_MD_OP(exp, link);
1497 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1498 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1502 static inline int md_rename(struct obd_export *exp,
1503 struct md_op_data *op_data,
1504 const char *old, int oldlen,
1505 const char *new, int newlen,
1506 struct ptlrpc_request **request)
1510 EXP_CHECK_MD_OP(exp, rename);
1511 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1512 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1517 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1518 struct iattr *iattr, void *ea, int ealen,
1519 void *ea2, int ea2len, struct ptlrpc_request **request)
1523 EXP_CHECK_MD_OP(exp, setattr);
1524 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1525 rc = MDP(exp->exp_obd, setattr)(exp, op_data, iattr, ea, ealen,
1526 ea2, ea2len, request);
1530 static inline int md_sync(struct obd_export *exp, struct lu_fid *fid,
1531 struct ptlrpc_request **request)
1535 EXP_CHECK_MD_OP(exp, sync);
1536 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1537 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1541 static inline int md_readpage(struct obd_export *exp, struct lu_fid *fid,
1542 __u64 offset, struct page *page,
1543 struct ptlrpc_request **request)
1547 EXP_CHECK_MD_OP(exp, readpage);
1548 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1549 rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1553 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1554 struct ptlrpc_request **request)
1558 EXP_CHECK_MD_OP(exp, unlink);
1559 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1560 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1564 static inline int md_get_lustre_md(struct obd_export *exp,
1565 struct ptlrpc_request *req,
1566 int offset, struct obd_export *dt_exp,
1567 struct lustre_md *md)
1570 EXP_CHECK_MD_OP(exp, get_lustre_md);
1571 MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1572 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1576 static inline int md_free_lustre_md(struct obd_export *exp,
1577 struct lustre_md *md)
1580 EXP_CHECK_MD_OP(exp, free_lustre_md);
1581 MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1582 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1585 static inline int md_setxattr(struct obd_export *exp, struct lu_fid *fid,
1586 obd_valid valid, const char *name,
1587 const char *input, int input_size,
1588 int output_size, int flags,
1589 struct ptlrpc_request **request)
1592 EXP_CHECK_MD_OP(exp, setxattr);
1593 MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1594 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1595 input_size, output_size, flags,
1599 static inline int md_getxattr(struct obd_export *exp, struct lu_fid *fid,
1600 obd_valid valid, const char *name,
1601 const char *input, int input_size,
1602 int output_size, int flags,
1603 struct ptlrpc_request **request)
1606 EXP_CHECK_MD_OP(exp, getxattr);
1607 MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1608 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1609 input_size, output_size, flags,
1613 static inline int md_set_open_replay_data(struct obd_export *exp,
1614 struct obd_client_handle *och,
1615 struct ptlrpc_request *open_req)
1618 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1619 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1620 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1623 static inline int md_clear_open_replay_data(struct obd_export *exp,
1624 struct obd_client_handle *och)
1627 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1628 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1629 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1632 static inline int md_set_lock_data(struct obd_export *exp,
1633 __u64 *lockh, void *data)
1636 EXP_CHECK_MD_OP(exp, set_lock_data);
1637 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1638 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1641 static inline int md_cancel_unused(struct obd_export *exp,
1643 int flags, void *opaque)
1648 EXP_CHECK_MD_OP(exp, cancel_unused);
1649 MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1651 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1655 static inline int md_lock_match(struct obd_export *exp, int flags,
1656 struct lu_fid *fid, ldlm_type_t type,
1657 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1658 struct lustre_handle *lockh)
1661 EXP_CHECK_MD_OP(exp, lock_match);
1662 MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1663 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1664 policy, mode, lockh));
1667 static inline int md_init_ea_size(struct obd_export *exp,
1668 int easize, int def_asize,
1672 EXP_CHECK_MD_OP(exp, init_ea_size);
1673 MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1674 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize,
1679 /* OBD Metadata Support */
1680 extern int obd_init_caches(void);
1681 extern void obd_cleanup_caches(void);
1683 /* support routines */
1684 extern cfs_mem_cache_t *obdo_cachep;
1685 static inline struct obdo *obdo_alloc(void)
1688 OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1692 static inline void obdo_free(struct obdo *oa)
1694 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1697 static inline void obdo2fid(struct obdo *oa,
1700 /* something here */
1703 static inline void fid2obdo(struct lu_fid *fid,
1706 /* something here */
1709 /* I'm as embarrassed about this as you are.
1711 * <shaver> // XXX do not look into _superhack with remaining eye
1712 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1713 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1716 extern void obd_sysctl_init (void);
1717 extern void obd_sysctl_clean (void);
1720 typedef __u8 class_uuid_t[16];
1721 void class_generate_random_uuid(class_uuid_t uuid);
1722 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1725 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1726 int class_add_uuid(const char *uuid, __u64 nid);
1727 int class_del_uuid (const char *uuid);
1728 void class_init_uuidlist(void);
1729 void class_exit_uuidlist(void);
1732 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1733 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1735 #endif /* __LINUX_OBD_CLASS_H */