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)
387 DECLARE_LU_VARS(ldt, d);
392 ldt = obd->obd_type->typ_lu;
394 if (ldt != NULL && d != NULL) {
395 struct lu_context ctx;
397 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
399 lu_context_enter(&ctx);
400 ldt->ldt_ops->ldto_device_fini(&ctx, d);
401 lu_context_exit(&ctx);
402 lu_context_fini(&ctx);
403 obd->obd_lu_dev = NULL;
409 OBD_CHECK_DT_OP(obd, precleanup, 0);
410 rc = OBP(obd, precleanup)(obd, cleanup_stage);
413 OBD_COUNTER_INCREMENT(obd, precleanup);
417 static inline int obd_cleanup(struct obd_device *obd)
420 DECLARE_LU_VARS(ldt, d);
426 ldt = obd->obd_type->typ_lu;
428 if (ldt != NULL && d != NULL) {
429 struct lu_context ctx;
431 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
433 lu_context_enter(&ctx);
434 ldt->ldt_ops->ldto_device_free(&ctx, d);
435 lu_context_exit(&ctx);
436 lu_context_fini(&ctx);
437 obd->obd_lu_dev = NULL;
443 OBD_CHECK_DT_OP(obd, cleanup, 0);
444 rc = OBP(obd, cleanup)(obd);
446 OBD_COUNTER_INCREMENT(obd, cleanup);
451 obd_process_config(struct obd_device *obd, int datalen, void *data)
454 DECLARE_LU_VARS(ldt, d);
460 ldt = obd->obd_type->typ_lu;
462 if (ldt != NULL && d != NULL) {
463 struct lu_context ctx;
465 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
467 lu_context_enter(&ctx);
468 rc = d->ld_ops->ldo_process_config(&ctx, d, data);
469 lu_context_exit(&ctx);
470 lu_context_fini(&ctx);
475 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
476 rc = OBP(obd, process_config)(obd, datalen, data);
478 OBD_COUNTER_INCREMENT(obd, process_config);
483 /* Pack an in-memory MD struct for storage on disk.
484 * Returns +ve size of packed MD (0 for free), or -ve error.
486 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
487 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
488 * If @*disk_tgt == NULL, it will be allocated
490 static inline int obd_packmd(struct obd_export *exp,
491 struct lov_mds_md **disk_tgt,
492 struct lov_stripe_md *mem_src)
497 EXP_CHECK_DT_OP(exp, packmd);
498 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
500 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
504 static inline int obd_size_diskmd(struct obd_export *exp,
505 struct lov_stripe_md *mem_src)
507 return obd_packmd(exp, NULL, mem_src);
510 /* helper functions */
511 static inline int obd_alloc_diskmd(struct obd_export *exp,
512 struct lov_mds_md **disk_tgt)
515 LASSERT(*disk_tgt == NULL);
516 return obd_packmd(exp, disk_tgt, NULL);
519 static inline int obd_free_diskmd(struct obd_export *exp,
520 struct lov_mds_md **disk_tgt)
524 return obd_packmd(exp, disk_tgt, NULL);
527 /* Unpack an MD struct from disk to in-memory format.
528 * Returns +ve size of unpacked MD (0 for free), or -ve error.
530 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
531 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
532 * If @*mem_tgt == NULL, it will be allocated
534 static inline int obd_unpackmd(struct obd_export *exp,
535 struct lov_stripe_md **mem_tgt,
536 struct lov_mds_md *disk_src,
542 EXP_CHECK_DT_OP(exp, unpackmd);
543 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
545 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
549 /* helper functions */
550 static inline int obd_alloc_memmd(struct obd_export *exp,
551 struct lov_stripe_md **mem_tgt)
554 LASSERT(*mem_tgt == NULL);
555 return obd_unpackmd(exp, mem_tgt, NULL, 0);
558 static inline int obd_free_memmd(struct obd_export *exp,
559 struct lov_stripe_md **mem_tgt)
563 return obd_unpackmd(exp, mem_tgt, NULL, 0);
566 static inline int obd_checkmd(struct obd_export *exp,
567 struct obd_export *md_exp,
568 struct lov_stripe_md *mem_tgt)
573 EXP_CHECK_DT_OP(exp, checkmd);
574 OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
576 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
580 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
581 struct lov_stripe_md **ea,
582 struct obd_trans_info *oti)
587 EXP_CHECK_DT_OP(exp, create);
588 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
590 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
594 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
595 struct lov_stripe_md *ea,
596 struct obd_trans_info *oti,
597 struct obd_export *md_exp)
602 EXP_CHECK_DT_OP(exp, destroy);
603 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
605 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
609 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
610 struct lov_stripe_md *ea)
615 EXP_CHECK_DT_OP(exp, getattr);
616 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
618 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
622 static inline int obd_getattr_async(struct obd_export *exp,
623 struct obdo *obdo, struct lov_stripe_md *ea,
624 struct ptlrpc_request_set *set)
629 EXP_CHECK_DT_OP(exp, getattr);
630 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
632 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
636 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
637 struct lov_stripe_md *ea,
638 struct obd_trans_info *oti)
643 EXP_CHECK_DT_OP(exp, setattr);
644 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
646 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
650 static inline int obd_setattr_async(struct obd_export *exp,
652 struct lov_stripe_md *ea,
653 struct obd_trans_info *oti)
658 EXP_CHECK_DT_OP(exp, setattr_async);
659 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
661 rc = OBP(exp->exp_obd, setattr_async)(exp, obdo, ea, oti);
665 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
668 struct obd_device *obd = imp->imp_obd;
672 OBD_CHECK_DEV_ACTIVE(obd);
673 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
674 OBD_COUNTER_INCREMENT(obd, add_conn);
676 rc = OBP(obd, add_conn)(imp, uuid, priority);
680 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
682 struct obd_device *obd = imp->imp_obd;
686 OBD_CHECK_DEV_ACTIVE(obd);
687 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
688 OBD_COUNTER_INCREMENT(obd, del_conn);
690 rc = OBP(obd, del_conn)(imp, uuid);
694 static inline int obd_connect(const struct lu_context *ctx,
695 struct lustre_handle *conn,struct obd_device *obd,
696 struct obd_uuid *cluuid,
697 struct obd_connect_data *d)
700 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
703 OBD_CHECK_DEV_ACTIVE(obd);
704 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
705 OBD_COUNTER_INCREMENT(obd, connect);
707 rc = OBP(obd, connect)(ctx, conn, obd, cluuid, d);
708 /* check that only subset is granted */
709 LASSERT(ergo(d != NULL,
710 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
714 static inline int obd_reconnect(struct obd_export *exp,
715 struct obd_device *obd,
716 struct obd_uuid *cluuid,
717 struct obd_connect_data *d)
720 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
723 OBD_CHECK_DEV_ACTIVE(obd);
724 OBD_CHECK_DT_OP(obd, reconnect, 0);
725 OBD_COUNTER_INCREMENT(obd, reconnect);
727 rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
728 /* check that only subset is granted */
729 LASSERT(ergo(d != NULL,
730 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
734 static inline int obd_disconnect(struct obd_export *exp)
739 EXP_CHECK_DT_OP(exp, disconnect);
740 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
742 rc = OBP(exp->exp_obd, disconnect)(exp);
746 static inline int obd_fid_init(struct obd_export *exp)
751 if (OBP(exp->exp_obd, fid_init) == NULL)
754 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_init);
756 rc = OBP(exp->exp_obd, fid_init)(exp);
760 static inline int obd_fid_fini(struct obd_export *exp)
765 if (OBP(exp->exp_obd, fid_fini) == NULL)
768 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_fini);
770 rc = OBP(exp->exp_obd, fid_fini)(exp);
774 static inline int obd_fid_alloc(struct obd_export *exp,
776 struct lu_placement_hint *hint)
781 if (OBP(exp->exp_obd, fid_alloc) == NULL)
784 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
786 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
790 static inline int obd_fid_delete(struct obd_export *exp,
796 if (OBP(exp->exp_obd, fid_delete) == NULL)
799 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
800 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
804 static inline int obd_init_export(struct obd_export *exp)
809 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
810 OBP((exp)->exp_obd, init_export))
811 rc = OBP(exp->exp_obd, init_export)(exp);
815 static inline int obd_destroy_export(struct obd_export *exp)
818 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
819 OBP((exp)->exp_obd, destroy_export))
820 OBP(exp->exp_obd, destroy_export)(exp);
824 static inline struct dentry *
825 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
827 LASSERT(exp->exp_obd);
829 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
834 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
836 LASSERT(exp->exp_obd);
837 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
839 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
840 dentry, exp->exp_obd);
846 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
849 /* @max_age is the oldest time in jiffies that we accept using a cached data.
850 * If the cache is older than @max_age we will get a new value from the
851 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
852 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
853 unsigned long max_age)
861 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
862 OBD_COUNTER_INCREMENT(obd, statfs);
864 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
865 if (time_before(obd->obd_osfs_age, max_age)) {
866 rc = OBP(obd, statfs)(obd, osfs, max_age);
868 spin_lock(&obd->obd_osfs_lock);
869 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
870 obd->obd_osfs_age = jiffies;
871 spin_unlock(&obd->obd_osfs_lock);
874 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
875 spin_lock(&obd->obd_osfs_lock);
876 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
877 spin_unlock(&obd->obd_osfs_lock);
882 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
883 struct lov_stripe_md *ea, obd_size start,
889 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
890 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
892 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
896 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
897 struct lov_stripe_md *ea, obd_size start,
898 obd_size end, struct obd_trans_info *oti)
903 EXP_CHECK_DT_OP(exp, punch);
904 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
906 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
910 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
911 struct lov_stripe_md *ea, obd_count oa_bufs,
912 struct brw_page *pg, struct obd_trans_info *oti)
917 EXP_CHECK_DT_OP(exp, brw);
918 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
920 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
921 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
922 "or OBD_BRW_CHECK\n");
926 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
930 static inline int obd_brw_async(int cmd, struct obd_export *exp,
931 struct obdo *oa, struct lov_stripe_md *ea,
932 obd_count oa_bufs, struct brw_page *pg,
933 struct ptlrpc_request_set *set,
934 struct obd_trans_info *oti)
939 EXP_CHECK_DT_OP(exp, brw_async);
940 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
942 if (!(cmd & OBD_BRW_RWMASK)) {
943 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
947 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
952 static inline int obd_prep_async_page(struct obd_export *exp,
953 struct lov_stripe_md *lsm,
954 struct lov_oinfo *loi,
955 struct page *page, obd_off offset,
956 struct obd_async_page_ops *ops,
957 void *data, void **res)
962 OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
963 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
965 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
970 static inline int obd_queue_async_io(struct obd_export *exp,
971 struct lov_stripe_md *lsm,
972 struct lov_oinfo *loi, void *cookie,
973 int cmd, obd_off off, int count,
974 obd_flag brw_flags, obd_flag async_flags)
979 OBD_CHECK_DT_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
980 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
981 LASSERT(cmd & OBD_BRW_RWMASK);
983 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
984 count, brw_flags, async_flags);
988 static inline int obd_set_async_flags(struct obd_export *exp,
989 struct lov_stripe_md *lsm,
990 struct lov_oinfo *loi, void *cookie,
991 obd_flag async_flags)
996 OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
997 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
999 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1004 static inline int obd_queue_group_io(struct obd_export *exp,
1005 struct lov_stripe_md *lsm,
1006 struct lov_oinfo *loi,
1007 struct obd_io_group *oig,
1008 void *cookie, int cmd, obd_off off,
1009 int count, obd_flag brw_flags,
1010 obd_flag async_flags)
1015 OBD_CHECK_DT_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1016 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
1017 LASSERT(cmd & OBD_BRW_RWMASK);
1019 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1020 cmd, off, count, brw_flags,
1025 static inline int obd_trigger_group_io(struct obd_export *exp,
1026 struct lov_stripe_md *lsm,
1027 struct lov_oinfo *loi,
1028 struct obd_io_group *oig)
1033 OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1034 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
1036 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1040 static inline int obd_teardown_async_page(struct obd_export *exp,
1041 struct lov_stripe_md *lsm,
1042 struct lov_oinfo *loi, void *cookie)
1047 OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1048 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
1050 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1054 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1055 int objcount, struct obd_ioobj *obj,
1056 int niocount, struct niobuf_remote *remote,
1057 struct niobuf_local *local,
1058 struct obd_trans_info *oti)
1063 OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1064 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1066 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1067 remote, local, oti);
1071 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1072 int objcount, struct obd_ioobj *obj,
1073 int niocount, struct niobuf_local *local,
1074 struct obd_trans_info *oti, int rc)
1078 OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1079 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1081 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1086 static inline int obd_merge_lvb(struct obd_export *exp,
1087 struct lov_stripe_md *lsm,
1088 struct ost_lvb *lvb, int kms_only)
1093 OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1094 OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1096 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1100 static inline int obd_adjust_kms(struct obd_export *exp,
1101 struct lov_stripe_md *lsm, obd_off size,
1107 OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1108 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1110 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1114 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1115 int len, void *karg, void *uarg)
1120 EXP_CHECK_DT_OP(exp, iocontrol);
1121 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1123 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1127 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
1128 __u32 type, ldlm_policy_data_t *policy,
1129 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
1130 void *gl_cb, void *data, __u32 lvb_len,
1131 void *lvb_swabber, struct lustre_handle *lockh)
1136 EXP_CHECK_DT_OP(exp, enqueue);
1137 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1139 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
1140 bl_cb, cp_cb, gl_cb, data, lvb_len,
1141 lvb_swabber, lockh);
1145 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1146 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1147 int *flags, void *data, struct lustre_handle *lockh)
1152 EXP_CHECK_DT_OP(exp, match);
1153 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1155 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1160 static inline int obd_change_cbdata(struct obd_export *exp,
1161 struct lov_stripe_md *lsm,
1162 ldlm_iterator_t it, void *data)
1167 EXP_CHECK_DT_OP(exp, change_cbdata);
1168 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1170 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1174 static inline int obd_cancel(struct obd_export *exp,
1175 struct lov_stripe_md *ea, __u32 mode,
1176 struct lustre_handle *lockh)
1181 EXP_CHECK_DT_OP(exp, cancel);
1182 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1184 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1188 static inline int obd_cancel_unused(struct obd_export *exp,
1189 struct lov_stripe_md *ea,
1190 int flags, void *opaque)
1195 EXP_CHECK_DT_OP(exp, cancel_unused);
1196 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1198 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1202 static inline int obd_join_lru(struct obd_export *exp,
1203 struct lov_stripe_md *ea, int join)
1208 EXP_CHECK_DT_OP(exp, join_lru);
1209 OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1211 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1215 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1217 int objcount, struct obd_ioobj *obj,
1218 int niocount, struct niobuf_remote *remote)
1222 EXP_CHECK_DT_OP(exp, preprw);
1223 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1225 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1227 class_export_put(exp);
1231 static inline int obd_pin(struct obd_export *exp, struct lu_fid *fid,
1232 struct obd_client_handle *handle, int flag)
1236 EXP_CHECK_DT_OP(exp, pin);
1237 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1239 rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1243 static inline int obd_unpin(struct obd_export *exp,
1244 struct obd_client_handle *handle, int flag)
1248 EXP_CHECK_DT_OP(exp, unpin);
1249 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1251 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1256 static inline void obd_import_event(struct obd_device *obd,
1257 struct obd_import *imp,
1258 enum obd_import_event event)
1261 CERROR("NULL device\n");
1265 if (obd->obd_set_up && OBP(obd, import_event)) {
1266 OBD_COUNTER_INCREMENT(obd, import_event);
1267 OBP(obd, import_event)(obd, imp, event);
1271 static inline int obd_notify(struct obd_device *obd,
1272 struct obd_device *watched,
1273 enum obd_notify_event ev,
1278 /* the check for async_recov is a complete hack - I'm hereby
1279 overloading the meaning to also mean "this was called from
1280 mds_postsetup". I know that my mds is able to handle notifies
1281 by this point, and it needs to get them to execute mds_postrecov. */
1282 if (!obd->obd_set_up && !obd->obd_async_recov) {
1283 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1287 if (!OBP(obd, notify)) {
1288 CERROR("obd %s has no notify handler\n", obd->obd_name);
1292 OBD_COUNTER_INCREMENT(obd, notify);
1293 return OBP(obd, notify)(obd, watched, ev, data);
1296 static inline int obd_notify_observer(struct obd_device *observer,
1297 struct obd_device *observed,
1298 enum obd_notify_event ev,
1304 struct obd_notify_upcall *onu;
1306 if (observer->obd_observer)
1307 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1311 * Also, call non-obd listener, if any
1313 onu = &observer->obd_upcall;
1314 if (onu->onu_upcall != NULL)
1315 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1319 return rc1 ? rc1 : rc2;
1322 static inline int obd_quotacheck(struct obd_export *exp,
1323 struct obd_quotactl *oqctl)
1328 EXP_CHECK_DT_OP(exp, quotacheck);
1329 OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1331 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1335 static inline int obd_quotactl(struct obd_export *exp,
1336 struct obd_quotactl *oqctl)
1341 EXP_CHECK_DT_OP(exp, quotactl);
1342 OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1344 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1348 static inline int obd_health_check(struct obd_device *obd)
1350 /* returns: 0 on healthy
1351 * >0 on unhealthy + reason code/flag
1352 * however the only suppored reason == 1 right now
1353 * We'll need to define some better reasons
1354 * or flags in the future.
1360 /* don't use EXP_CHECK_OP, because NULL method is normal here */
1361 if (obd == NULL || !OBT(obd)) {
1362 CERROR("cleaned up obd\n");
1363 RETURN(-EOPNOTSUPP);
1365 if (!obd->obd_set_up || obd->obd_stopping)
1367 if (!OBP(obd, health_check))
1370 rc = OBP(obd, health_check)(obd);
1374 static inline int obd_register_observer(struct obd_device *obd,
1375 struct obd_device *observer)
1379 if (obd->obd_observer && observer)
1381 obd->obd_observer = observer;
1385 /* metadata helpers */
1386 static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
1391 EXP_CHECK_MD_OP(exp, getstatus);
1392 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1393 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1397 static inline int md_getattr(struct obd_export *exp, struct lu_fid *fid,
1398 obd_valid valid, int ea_size,
1399 struct ptlrpc_request **request)
1403 EXP_CHECK_MD_OP(exp, getattr);
1404 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1405 rc = MDP(exp->exp_obd, getattr)(exp, fid, valid,
1410 static inline int md_change_cbdata(struct obd_export *exp, struct lu_fid *fid,
1411 ldlm_iterator_t it, void *data)
1415 EXP_CHECK_MD_OP(exp, change_cbdata);
1416 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1417 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1421 static inline int md_close(struct obd_export *exp,
1422 struct md_op_data *op_data,
1423 struct obd_client_handle *och,
1424 struct ptlrpc_request **request)
1428 EXP_CHECK_MD_OP(exp, close);
1429 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1430 rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1434 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1435 const void *data, int datalen, int mode,
1436 __u32 uid, __u32 gid, __u32 cap_effective, __u64 rdev,
1437 struct ptlrpc_request **request)
1441 EXP_CHECK_MD_OP(exp, create);
1442 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1443 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1444 uid, gid, cap_effective, rdev, request);
1448 static inline int md_done_writing(struct obd_export *exp,
1449 struct md_op_data *op_data)
1453 EXP_CHECK_MD_OP(exp, done_writing);
1454 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1455 rc = MDP(exp->exp_obd, done_writing)(exp, op_data);
1459 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1460 struct lookup_intent *it, int lock_mode,
1461 struct md_op_data *op_data,
1462 struct lustre_handle *lockh,
1463 void *lmm, int lmmsize,
1464 ldlm_completion_callback cb_completion,
1465 ldlm_blocking_callback cb_blocking,
1466 void *cb_data, int extra_lock_flags)
1470 EXP_CHECK_MD_OP(exp, enqueue);
1471 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1472 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1473 op_data, lockh, lmm, lmmsize,
1474 cb_completion, cb_blocking,
1475 cb_data, extra_lock_flags);
1479 static inline int md_getattr_name(struct obd_export *exp, struct lu_fid *fid,
1480 const char *filename, int namelen,
1481 obd_valid valid, int ea_size,
1482 struct ptlrpc_request **request)
1486 EXP_CHECK_MD_OP(exp, getattr_name);
1487 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1488 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1489 valid, ea_size, request);
1493 static inline int md_intent_lock(struct obd_export *exp,
1494 struct md_op_data *op_data,
1495 void *lmm, int lmmsize,
1496 struct lookup_intent *it,
1497 int flags, struct ptlrpc_request **reqp,
1498 ldlm_blocking_callback cb_blocking,
1499 int extra_lock_flags)
1503 EXP_CHECK_MD_OP(exp, intent_lock);
1504 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1505 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1506 it, flags, reqp, cb_blocking,
1511 static inline int md_link(struct obd_export *exp,
1512 struct md_op_data *op_data,
1513 struct ptlrpc_request **request)
1517 EXP_CHECK_MD_OP(exp, link);
1518 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1519 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1523 static inline int md_rename(struct obd_export *exp,
1524 struct md_op_data *op_data,
1525 const char *old, int oldlen,
1526 const char *new, int newlen,
1527 struct ptlrpc_request **request)
1531 EXP_CHECK_MD_OP(exp, rename);
1532 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1533 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1538 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1539 struct iattr *iattr, void *ea, int ealen,
1540 void *ea2, int ea2len, struct ptlrpc_request **request)
1544 EXP_CHECK_MD_OP(exp, setattr);
1545 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1546 rc = MDP(exp->exp_obd, setattr)(exp, op_data, iattr, ea, ealen,
1547 ea2, ea2len, request);
1551 static inline int md_sync(struct obd_export *exp, struct lu_fid *fid,
1552 struct ptlrpc_request **request)
1556 EXP_CHECK_MD_OP(exp, sync);
1557 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1558 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1562 static inline int md_readpage(struct obd_export *exp, struct lu_fid *fid,
1563 __u64 offset, struct page *page,
1564 struct ptlrpc_request **request)
1568 EXP_CHECK_MD_OP(exp, readpage);
1569 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1570 rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1574 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1575 struct ptlrpc_request **request)
1579 EXP_CHECK_MD_OP(exp, unlink);
1580 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1581 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1585 static inline int md_get_lustre_md(struct obd_export *exp,
1586 struct ptlrpc_request *req,
1587 int offset, struct obd_export *dt_exp,
1588 struct lustre_md *md)
1591 EXP_CHECK_MD_OP(exp, get_lustre_md);
1592 MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1593 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1597 static inline int md_free_lustre_md(struct obd_export *exp,
1598 struct lustre_md *md)
1601 EXP_CHECK_MD_OP(exp, free_lustre_md);
1602 MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1603 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1606 static inline int md_setxattr(struct obd_export *exp, struct lu_fid *fid,
1607 obd_valid valid, const char *name,
1608 const char *input, int input_size,
1609 int output_size, int flags,
1610 struct ptlrpc_request **request)
1613 EXP_CHECK_MD_OP(exp, setxattr);
1614 MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1615 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1616 input_size, output_size, flags,
1620 static inline int md_getxattr(struct obd_export *exp, struct lu_fid *fid,
1621 obd_valid valid, const char *name,
1622 const char *input, int input_size,
1623 int output_size, int flags,
1624 struct ptlrpc_request **request)
1627 EXP_CHECK_MD_OP(exp, getxattr);
1628 MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1629 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1630 input_size, output_size, flags,
1634 static inline int md_set_open_replay_data(struct obd_export *exp,
1635 struct obd_client_handle *och,
1636 struct ptlrpc_request *open_req)
1639 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1640 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1641 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1644 static inline int md_clear_open_replay_data(struct obd_export *exp,
1645 struct obd_client_handle *och)
1648 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1649 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1650 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1653 static inline int md_set_lock_data(struct obd_export *exp,
1654 __u64 *lockh, void *data)
1657 EXP_CHECK_MD_OP(exp, set_lock_data);
1658 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1659 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1662 static inline int md_cancel_unused(struct obd_export *exp,
1664 int flags, void *opaque)
1669 EXP_CHECK_MD_OP(exp, cancel_unused);
1670 MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1672 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1676 static inline int md_lock_match(struct obd_export *exp, int flags,
1677 struct lu_fid *fid, ldlm_type_t type,
1678 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1679 struct lustre_handle *lockh)
1682 EXP_CHECK_MD_OP(exp, lock_match);
1683 MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1684 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1685 policy, mode, lockh));
1688 static inline int md_init_ea_size(struct obd_export *exp,
1689 int easize, int def_asize,
1693 EXP_CHECK_MD_OP(exp, init_ea_size);
1694 MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1695 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize,
1700 /* OBD Metadata Support */
1701 extern int obd_init_caches(void);
1702 extern void obd_cleanup_caches(void);
1704 /* support routines */
1705 extern cfs_mem_cache_t *obdo_cachep;
1706 static inline struct obdo *obdo_alloc(void)
1709 OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1713 static inline void obdo_free(struct obdo *oa)
1715 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1718 static inline void obdo2fid(struct obdo *oa,
1721 /* something here */
1724 static inline void fid2obdo(struct lu_fid *fid,
1727 /* something here */
1730 /* I'm as embarrassed about this as you are.
1732 * <shaver> // XXX do not look into _superhack with remaining eye
1733 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1734 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1737 extern void obd_sysctl_init (void);
1738 extern void obd_sysctl_clean (void);
1741 typedef __u8 class_uuid_t[16];
1742 void class_generate_random_uuid(class_uuid_t uuid);
1743 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1746 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1747 int class_add_uuid(const char *uuid, __u64 nid);
1748 int class_del_uuid (const char *uuid);
1749 void class_init_uuidlist(void);
1750 void class_exit_uuidlist(void);
1753 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1754 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1756 #endif /* __LINUX_OBD_CLASS_H */