1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <obd_support.h>
27 #include <lustre_import.h>
28 #include <lustre_net.h>
30 #include <lustre_lib.h>
31 #include <lustre/lustre_idl.h>
32 #include <lprocfs_status.h>
34 #if defined(__linux__)
35 #include <linux/obd_class.h>
36 #elif defined(__APPLE__)
37 #include <darwin/obd_class.h>
38 #elif defined(__WINNT__)
39 #include <winnt/obd_class.h>
41 #error Unsupported operating system.
44 /* OBD Device Declarations */
45 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
46 extern spinlock_t obd_dev_lock;
48 /* OBD Operations Declarations */
49 extern struct obd_device *class_conn2obd(struct lustre_handle *);
50 extern struct obd_device *class_exp2obd(struct obd_export *);
52 struct lu_device_type;
55 struct obd_export *class_conn2export(struct lustre_handle *);
56 int class_register_type(struct obd_ops *, struct md_ops *,
57 struct lprocfs_vars *, const char *nm,
58 struct lu_device_type *ldt);
59 int class_unregister_type(const char *nm);
61 struct obd_device *class_newdev(const char *type_name, const char *name);
62 void class_release_dev(struct obd_device *obd);
64 int class_name2dev(const char *name);
65 struct obd_device *class_name2obd(const char *name);
66 int class_uuid2dev(struct obd_uuid *uuid);
67 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
68 void class_obd_list(void);
69 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
70 const char * typ_name,
71 struct obd_uuid *grp_uuid);
72 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
73 struct obd_uuid *grp_uuid);
74 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
76 struct obd_device * class_num2obd(int num);
78 int oig_init(struct obd_io_group **oig);
79 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
80 void oig_complete_one(struct obd_io_group *oig,
81 struct oig_callback_context *occ, int rc);
82 void oig_release(struct obd_io_group *oig);
83 int oig_wait(struct obd_io_group *oig);
85 char *obd_export_nid2str(struct obd_export *exp);
87 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
88 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
91 int class_process_config(struct lustre_cfg *lcfg);
92 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
93 struct lustre_cfg *lcfg, void *data);
94 int class_attach(struct lustre_cfg *lcfg);
95 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
96 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
97 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
98 struct obd_device *class_incref(struct obd_device *obd);
99 void class_decref(struct obd_device *obd);
101 #define CFG_F_START 0x01 /* Set when we start updating from a log */
102 #define CFG_F_MARKER 0x02 /* We are within a maker */
103 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
104 #define CFG_F_COMPAT146 0x08 /* Using old-style log */
105 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
107 /* Passed as data param to class_config_parse_llog */
108 struct config_llog_instance {
110 struct super_block *cfg_sb;
111 struct obd_uuid cfg_uuid;
112 int cfg_last_idx; /* for partial llog processing */
115 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
116 struct config_llog_instance *cfg);
117 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
118 struct config_llog_instance *cfg);
120 /* list of active configuration logs */
121 struct config_llog_data {
123 struct ldlm_res_id cld_resid;
124 struct config_llog_instance cld_cfg;
125 struct list_head cld_list_chain;
126 atomic_t cld_refcount;
127 struct obd_export *cld_mgcexp;
128 unsigned int cld_stopping:1;
131 struct lustre_profile {
132 struct list_head lp_list;
138 struct lustre_profile *class_get_profile(const char * prof);
139 void class_del_profile(const char *prof);
140 void class_del_profiles(void);
143 #define class_export_get(exp) \
145 struct obd_export *exp_ = exp; \
146 atomic_inc(&exp_->exp_refcount); \
147 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
148 atomic_read(&exp_->exp_refcount)); \
152 #define class_export_put(exp) \
154 LASSERT((exp) != NULL); \
155 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
156 atomic_read(&(exp)->exp_refcount) - 1); \
157 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
158 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
159 __class_export_put(exp); \
161 void __class_export_put(struct obd_export *);
162 struct obd_export *class_new_export(struct obd_device *obddev,
163 struct obd_uuid *cluuid);
164 void class_unlink_export(struct obd_export *exp);
166 struct obd_import *class_import_get(struct obd_import *);
167 void class_import_put(struct obd_import *);
168 struct obd_import *class_new_import(struct obd_device *obd);
169 void class_destroy_import(struct obd_import *exp);
171 struct obd_type *class_search_type(const char *name);
172 struct obd_type *class_get_type(const char *name);
173 void class_put_type(struct obd_type *type);
174 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
175 struct obd_uuid *cluuid);
176 int class_disconnect(struct obd_export *exp);
177 void class_fail_export(struct obd_export *exp);
178 void class_disconnect_exports(struct obd_device *obddev);
179 int class_disconnect_stale_exports(struct obd_device *,
180 int (*test_export)(struct obd_export *));
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);
186 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
187 unsigned int ia_valid);
188 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
189 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
190 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
193 #define OBT(dev) (dev)->obd_type
194 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
195 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
196 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
198 /* Ensure obd_setup: used for cleanup which must be called
199 while obd is stopping */
200 #define OBD_CHECK_DEV(obd) \
203 CERROR("NULL device\n"); \
208 /* ensure obd_setup and !obd_stopping */
209 #define OBD_CHECK_DEV_ACTIVE(obd) \
211 OBD_CHECK_DEV(obd); \
212 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
213 CERROR("Device %d not setup\n", \
221 #define OBD_COUNTER_OFFSET(op) \
222 ((offsetof(struct obd_ops, o_ ## op) - \
223 offsetof(struct obd_ops, o_iocontrol)) \
224 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
226 #define OBD_COUNTER_INCREMENT(obd, op) \
227 if ((obd)->obd_stats != NULL) { \
228 unsigned int coffset; \
229 coffset = (unsigned int)(obd)->obd_cntr_base + \
230 OBD_COUNTER_OFFSET(op); \
231 LASSERT(coffset < obd->obd_stats->ls_num); \
232 lprocfs_counter_incr(obd->obd_stats, coffset); \
235 #define MD_COUNTER_OFFSET(op) \
236 ((offsetof(struct md_ops, m_ ## op) - \
237 offsetof(struct md_ops, m_getstatus)) \
238 / sizeof(((struct md_ops *)(0))->m_getstatus))
240 #define MD_COUNTER_INCREMENT(obd, op) \
241 if ((obd)->md_stats != NULL) { \
242 unsigned int coffset; \
243 coffset = (unsigned int)(obd)->md_cntr_base + \
244 MD_COUNTER_OFFSET(op); \
245 LASSERT(coffset < (obd)->md_stats->ls_num); \
246 lprocfs_counter_incr((obd)->md_stats, coffset); \
250 #define OBD_COUNTER_OFFSET(op)
251 #define OBD_COUNTER_INCREMENT(obd, op)
252 #define MD_COUNTER_INCREMENT(obd, op)
255 #define OBD_CHECK_MD_OP(obd, op, err) \
257 if (!OBT(obd) || !MDP((obd), op)) { \
259 CERROR("md_" #op ": dev %s/%d no operation\n", \
260 obd->obd_name, obd->obd_minor); \
265 #define EXP_CHECK_MD_OP(exp, op) \
267 if ((exp) == NULL) { \
268 CERROR("obd_" #op ": NULL export\n"); \
271 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
272 CERROR("obd_" #op ": cleaned up obd\n"); \
273 RETURN(-EOPNOTSUPP); \
275 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
276 CERROR("obd_" #op ": dev %s/%d no operation\n", \
277 (exp)->exp_obd->obd_name, \
278 (exp)->exp_obd->obd_minor); \
279 RETURN(-EOPNOTSUPP); \
284 #define OBD_CHECK_DT_OP(obd, op, err) \
286 if (!OBT(obd) || !OBP((obd), op)) { \
288 CERROR("obd_" #op ": dev %d no operation\n", \
294 #define EXP_CHECK_DT_OP(exp, op) \
296 if ((exp) == NULL) { \
297 CERROR("obd_" #op ": NULL export\n"); \
300 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
301 CERROR("obd_" #op ": cleaned up obd\n"); \
302 RETURN(-EOPNOTSUPP); \
304 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
305 CERROR("obd_" #op ": dev %d no operation\n", \
306 (exp)->exp_obd->obd_minor); \
307 RETURN(-EOPNOTSUPP); \
311 #define CTXT_CHECK_OP(ctxt, op, err) \
313 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
315 CERROR("lop_" #op ": dev %d no operation\n", \
316 ctxt->loc_obd->obd_minor); \
321 static inline int class_devno_max(void)
323 return MAX_OBD_DEVICES;
326 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
327 void *key, __u32 *vallen, void *val)
332 EXP_CHECK_DT_OP(exp, get_info);
333 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
335 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
339 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
340 void *key, obd_count vallen, void *val,
341 struct ptlrpc_request_set *set)
346 EXP_CHECK_DT_OP(exp, set_info_async);
347 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info_async);
349 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
355 #define DECLARE_LU_VARS(ldt, d) \
356 struct lu_device_type *ldt; \
359 #define DECLARE_LU_VARS(ldt, d) \
360 extern void __placeholder_to_put_a_semicolon(void)
362 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
365 DECLARE_LU_VARS(ldt, d);
369 ldt = obd->obd_type->typ_lu;
373 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
375 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
387 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
388 OBD_COUNTER_INCREMENT(obd, setup);
389 rc = OBP(obd, setup)(obd, cfg);
394 static inline int obd_precleanup(struct obd_device *obd,
395 enum obd_cleanup_stage cleanup_stage)
398 DECLARE_LU_VARS(ldt, d);
403 ldt = obd->obd_type->typ_lu;
407 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
410 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
412 ldt->ldt_ops->ldto_device_fini(&env, d);
421 OBD_CHECK_DT_OP(obd, precleanup, 0);
422 rc = OBP(obd, precleanup)(obd, cleanup_stage);
425 OBD_COUNTER_INCREMENT(obd, precleanup);
429 static inline int obd_cleanup(struct obd_device *obd)
432 DECLARE_LU_VARS(ldt, d);
438 ldt = obd->obd_type->typ_lu;
444 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
446 ldt->ldt_ops->ldto_device_free(&env, d);
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) {
475 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
477 rc = d->ld_ops->ldo_process_config(&env, d, data);
483 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
484 rc = OBP(obd, process_config)(obd, datalen, data);
486 OBD_COUNTER_INCREMENT(obd, process_config);
491 /* Pack an in-memory MD struct for storage on disk.
492 * Returns +ve size of packed MD (0 for free), or -ve error.
494 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
495 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
496 * If @*disk_tgt == NULL, it will be allocated
498 static inline int obd_packmd(struct obd_export *exp,
499 struct lov_mds_md **disk_tgt,
500 struct lov_stripe_md *mem_src)
505 EXP_CHECK_DT_OP(exp, packmd);
506 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
508 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
512 static inline int obd_size_diskmd(struct obd_export *exp,
513 struct lov_stripe_md *mem_src)
515 return obd_packmd(exp, NULL, mem_src);
518 /* helper functions */
519 static inline int obd_alloc_diskmd(struct obd_export *exp,
520 struct lov_mds_md **disk_tgt)
523 LASSERT(*disk_tgt == NULL);
524 return obd_packmd(exp, disk_tgt, NULL);
527 static inline int obd_free_diskmd(struct obd_export *exp,
528 struct lov_mds_md **disk_tgt)
532 return obd_packmd(exp, disk_tgt, NULL);
535 /* Unpack an MD struct from disk to in-memory format.
536 * Returns +ve size of unpacked MD (0 for free), or -ve error.
538 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
539 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
540 * If @*mem_tgt == NULL, it will be allocated
542 static inline int obd_unpackmd(struct obd_export *exp,
543 struct lov_stripe_md **mem_tgt,
544 struct lov_mds_md *disk_src,
550 EXP_CHECK_DT_OP(exp, unpackmd);
551 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
553 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
557 /* helper functions */
558 static inline int obd_alloc_memmd(struct obd_export *exp,
559 struct lov_stripe_md **mem_tgt)
562 LASSERT(*mem_tgt == NULL);
563 return obd_unpackmd(exp, mem_tgt, NULL, 0);
566 static inline int obd_free_memmd(struct obd_export *exp,
567 struct lov_stripe_md **mem_tgt)
571 return obd_unpackmd(exp, mem_tgt, NULL, 0);
574 static inline int obd_checkmd(struct obd_export *exp,
575 struct obd_export *md_exp,
576 struct lov_stripe_md *mem_tgt)
581 EXP_CHECK_DT_OP(exp, checkmd);
582 OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
584 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
588 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
589 struct lov_stripe_md **ea,
590 struct obd_trans_info *oti)
595 EXP_CHECK_DT_OP(exp, create);
596 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
598 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
602 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
603 struct lov_stripe_md *ea,
604 struct obd_trans_info *oti,
605 struct obd_export *md_exp)
610 EXP_CHECK_DT_OP(exp, destroy);
611 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
613 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
617 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
622 EXP_CHECK_DT_OP(exp, getattr);
623 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
625 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
629 static inline int obd_getattr_async(struct obd_export *exp,
630 struct obd_info *oinfo,
631 struct ptlrpc_request_set *set)
636 EXP_CHECK_DT_OP(exp, getattr_async);
637 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr_async);
639 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
643 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
644 struct obd_trans_info *oti)
649 EXP_CHECK_DT_OP(exp, setattr);
650 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
652 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
656 /* This performs all the requests set init/wait/destroy actions. */
657 static inline int obd_setattr_rqset(struct obd_export *exp,
658 struct obd_info *oinfo,
659 struct obd_trans_info *oti)
661 struct ptlrpc_request_set *set = NULL;
665 EXP_CHECK_DT_OP(exp, setattr_async);
666 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
668 set = ptlrpc_prep_set();
672 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
674 rc = ptlrpc_set_wait(set);
675 ptlrpc_set_destroy(set);
679 /* This adds all the requests into @set if @set != NULL, otherwise
680 all requests are sent asynchronously without waiting for response. */
681 static inline int obd_setattr_async(struct obd_export *exp,
682 struct obd_info *oinfo,
683 struct obd_trans_info *oti,
684 struct ptlrpc_request_set *set)
689 EXP_CHECK_DT_OP(exp, setattr_async);
690 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
692 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
696 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
699 struct obd_device *obd = imp->imp_obd;
703 OBD_CHECK_DEV_ACTIVE(obd);
704 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
705 OBD_COUNTER_INCREMENT(obd, add_conn);
707 rc = OBP(obd, add_conn)(imp, uuid, priority);
711 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
713 struct obd_device *obd = imp->imp_obd;
717 OBD_CHECK_DEV_ACTIVE(obd);
718 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
719 OBD_COUNTER_INCREMENT(obd, del_conn);
721 rc = OBP(obd, del_conn)(imp, uuid);
725 static inline int obd_connect(const struct lu_env *env,
726 struct lustre_handle *conn,struct obd_device *obd,
727 struct obd_uuid *cluuid,
728 struct obd_connect_data *d)
731 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
734 OBD_CHECK_DEV_ACTIVE(obd);
735 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
736 OBD_COUNTER_INCREMENT(obd, connect);
738 rc = OBP(obd, connect)(env, conn, obd, cluuid, d);
739 /* check that only subset is granted */
740 LASSERT(ergo(d != NULL,
741 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
745 static inline int obd_reconnect(struct obd_export *exp,
746 struct obd_device *obd,
747 struct obd_uuid *cluuid,
748 struct obd_connect_data *d)
751 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
754 OBD_CHECK_DEV_ACTIVE(obd);
755 OBD_CHECK_DT_OP(obd, reconnect, 0);
756 OBD_COUNTER_INCREMENT(obd, reconnect);
758 rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
759 /* check that only subset is granted */
760 LASSERT(ergo(d != NULL,
761 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
765 static inline int obd_disconnect(struct obd_export *exp)
770 EXP_CHECK_DT_OP(exp, disconnect);
771 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
773 rc = OBP(exp->exp_obd, disconnect)(exp);
777 static inline int obd_fid_init(struct obd_export *exp)
782 if (OBP(exp->exp_obd, fid_init) == NULL)
785 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_init);
787 rc = OBP(exp->exp_obd, fid_init)(exp);
791 static inline int obd_fid_fini(struct obd_export *exp)
796 if (OBP(exp->exp_obd, fid_fini) == NULL)
799 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_fini);
801 rc = OBP(exp->exp_obd, fid_fini)(exp);
805 static inline int obd_fid_alloc(struct obd_export *exp,
807 struct lu_placement_hint *hint)
812 if (OBP(exp->exp_obd, fid_alloc) == NULL)
815 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
817 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
821 static inline int obd_fid_delete(struct obd_export *exp,
822 const struct lu_fid *fid)
827 if (OBP(exp->exp_obd, fid_delete) == NULL)
830 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
831 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
835 static inline int obd_ping(struct obd_export *exp)
840 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
841 OBD_COUNTER_INCREMENT(exp->exp_obd, ping);
843 rc = OBP(exp->exp_obd, ping)(exp);
847 static inline int obd_init_export(struct obd_export *exp)
852 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
853 OBP((exp)->exp_obd, init_export))
854 rc = OBP(exp->exp_obd, init_export)(exp);
858 static inline int obd_destroy_export(struct obd_export *exp)
861 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
862 OBP((exp)->exp_obd, destroy_export))
863 OBP(exp->exp_obd, destroy_export)(exp);
867 static inline int obd_extent_calc(struct obd_export *exp,
868 struct lov_stripe_md *md,
869 int cmd, obd_off *offset)
873 EXP_CHECK_DT_OP(exp, extent_calc);
874 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
878 static inline struct dentry *
879 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
881 LASSERT(exp->exp_obd);
883 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
888 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
890 LASSERT(exp->exp_obd);
891 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
893 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
894 dentry, exp->exp_obd);
900 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
903 /* @max_age is the oldest time in jiffies that we accept using a cached data.
904 * If the cache is older than @max_age we will get a new value from the
905 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
906 static inline int obd_statfs_async(struct obd_device *obd,
907 struct obd_info *oinfo,
909 struct ptlrpc_request_set *rqset)
917 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
918 OBD_COUNTER_INCREMENT(obd, statfs);
920 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
921 obd->obd_osfs_age, max_age);
922 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
923 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
925 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
926 spin_lock(&obd->obd_osfs_lock);
927 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
928 spin_unlock(&obd->obd_osfs_lock);
930 oinfo->oi_cb_up(oinfo, 0);
935 static inline int obd_statfs_rqset(struct obd_device *obd,
936 struct obd_statfs *osfs, __u64 max_age)
938 struct ptlrpc_request_set *set = NULL;
939 struct obd_info oinfo = { { { 0 } } };
943 set = ptlrpc_prep_set();
947 oinfo.oi_osfs = osfs;
948 rc = obd_statfs_async(obd, &oinfo, max_age, set);
950 rc = ptlrpc_set_wait(set);
951 ptlrpc_set_destroy(set);
955 /* @max_age is the oldest time in jiffies that we accept using a cached data.
956 * If the cache is older than @max_age we will get a new value from the
957 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
958 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
967 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
968 OBD_COUNTER_INCREMENT(obd, statfs);
970 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
971 obd->obd_osfs_age, max_age);
972 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
973 rc = OBP(obd, statfs)(obd, osfs, max_age);
975 spin_lock(&obd->obd_osfs_lock);
976 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
977 obd->obd_osfs_age = cfs_time_current_64();
978 spin_unlock(&obd->obd_osfs_lock);
981 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
982 spin_lock(&obd->obd_osfs_lock);
983 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
984 spin_unlock(&obd->obd_osfs_lock);
989 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
990 struct lov_stripe_md *ea, obd_size start,
991 obd_size end, void *capa)
996 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
997 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
999 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1003 static inline int obd_punch_rqset(struct obd_export *exp,
1004 struct obd_info *oinfo,
1005 struct obd_trans_info *oti)
1007 struct ptlrpc_request_set *set = NULL;
1011 EXP_CHECK_DT_OP(exp, punch);
1012 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1014 set = ptlrpc_prep_set();
1018 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1020 rc = ptlrpc_set_wait(set);
1021 ptlrpc_set_destroy(set);
1025 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1026 struct obd_trans_info *oti,
1027 struct ptlrpc_request_set *rqset)
1032 EXP_CHECK_DT_OP(exp, punch);
1033 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1035 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1039 static inline int obd_brw(int cmd, struct obd_export *exp,
1040 struct obd_info *oinfo, obd_count oa_bufs,
1041 struct brw_page *pg, struct obd_trans_info *oti)
1046 EXP_CHECK_DT_OP(exp, brw);
1047 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
1049 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1050 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1051 "or OBD_BRW_CHECK\n");
1055 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1059 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1060 struct obd_info *oinfo, obd_count oa_bufs,
1061 struct brw_page *pg, struct obd_trans_info *oti,
1062 struct ptlrpc_request_set *set)
1067 EXP_CHECK_DT_OP(exp, brw_async);
1068 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
1070 if (!(cmd & OBD_BRW_RWMASK)) {
1071 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1075 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1079 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1080 struct obdo *oa, struct lov_stripe_md *lsm,
1081 obd_count oa_bufs, struct brw_page *pg,
1082 struct obd_trans_info *oti,
1083 struct obd_capa *ocapa)
1085 struct ptlrpc_request_set *set = NULL;
1086 struct obd_info oinfo = { { { 0 } } };
1090 set = ptlrpc_prep_set();
1096 oinfo.oi_capa = ocapa;
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,
1216 struct lustre_capa *capa)
1221 OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1222 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1224 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1225 remote, local, oti, capa);
1229 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1230 int objcount, struct obd_ioobj *obj,
1231 int niocount, struct niobuf_local *local,
1232 struct obd_trans_info *oti, int rc)
1236 OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1237 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1239 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1244 static inline int obd_merge_lvb(struct obd_export *exp,
1245 struct lov_stripe_md *lsm,
1246 struct ost_lvb *lvb, int kms_only)
1251 OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1252 OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1254 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1258 static inline int obd_adjust_kms(struct obd_export *exp,
1259 struct lov_stripe_md *lsm, obd_off size,
1265 OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1266 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1268 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1272 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1273 int len, void *karg, void *uarg)
1278 EXP_CHECK_DT_OP(exp, iocontrol);
1279 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1281 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1285 static inline int obd_enqueue_rqset(struct obd_export *exp,
1286 struct obd_info *oinfo,
1287 struct obd_enqueue_info *einfo)
1292 EXP_CHECK_DT_OP(exp, enqueue);
1293 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1295 einfo->ei_rqset = ptlrpc_prep_set();
1296 if (einfo->ei_rqset == NULL)
1299 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1301 rc = ptlrpc_set_wait(einfo->ei_rqset);
1302 ptlrpc_set_destroy(einfo->ei_rqset);
1303 einfo->ei_rqset = NULL;
1308 static inline int obd_enqueue(struct obd_export *exp,
1309 struct obd_info *oinfo,
1310 struct obd_enqueue_info *einfo)
1315 EXP_CHECK_DT_OP(exp, enqueue);
1316 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1318 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1322 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1323 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1324 int *flags, void *data, struct lustre_handle *lockh)
1329 EXP_CHECK_DT_OP(exp, match);
1330 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1332 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1337 static inline int obd_change_cbdata(struct obd_export *exp,
1338 struct lov_stripe_md *lsm,
1339 ldlm_iterator_t it, void *data)
1344 EXP_CHECK_DT_OP(exp, change_cbdata);
1345 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1347 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1351 static inline int obd_cancel(struct obd_export *exp,
1352 struct lov_stripe_md *ea, __u32 mode,
1353 struct lustre_handle *lockh)
1358 EXP_CHECK_DT_OP(exp, cancel);
1359 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1361 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1365 static inline int obd_cancel_unused(struct obd_export *exp,
1366 struct lov_stripe_md *ea,
1367 int flags, void *opaque)
1372 EXP_CHECK_DT_OP(exp, cancel_unused);
1373 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1375 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1379 static inline int obd_join_lru(struct obd_export *exp,
1380 struct lov_stripe_md *ea, int join)
1385 EXP_CHECK_DT_OP(exp, join_lru);
1386 OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1388 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1392 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1393 struct obd_capa *oc, struct obd_client_handle *handle,
1398 EXP_CHECK_DT_OP(exp, pin);
1399 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1401 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1405 static inline int obd_unpin(struct obd_export *exp,
1406 struct obd_client_handle *handle, int flag)
1410 EXP_CHECK_DT_OP(exp, unpin);
1411 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1413 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1418 static inline void obd_import_event(struct obd_device *obd,
1419 struct obd_import *imp,
1420 enum obd_import_event event)
1423 CERROR("NULL device\n");
1427 if (obd->obd_set_up && OBP(obd, import_event)) {
1428 OBD_COUNTER_INCREMENT(obd, import_event);
1429 OBP(obd, import_event)(obd, imp, event);
1433 static inline int obd_llog_connect(struct obd_export *exp,
1434 struct llogd_conn_body *body)
1438 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1439 OBD_COUNTER_INCREMENT(exp->exp_obd, llog_connect);
1441 return OBP(exp->exp_obd, llog_connect)(exp, body);
1445 static inline int obd_notify(struct obd_device *obd,
1446 struct obd_device *watched,
1447 enum obd_notify_event ev,
1452 /* the check for async_recov is a complete hack - I'm hereby
1453 overloading the meaning to also mean "this was called from
1454 mds_postsetup". I know that my mds is able to handle notifies
1455 by this point, and it needs to get them to execute mds_postrecov. */
1456 if (!obd->obd_set_up && !obd->obd_async_recov) {
1457 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1461 if (!OBP(obd, notify)) {
1462 CERROR("obd %s has no notify handler\n", obd->obd_name);
1466 OBD_COUNTER_INCREMENT(obd, notify);
1467 return OBP(obd, notify)(obd, watched, ev, data);
1470 static inline int obd_notify_observer(struct obd_device *observer,
1471 struct obd_device *observed,
1472 enum obd_notify_event ev,
1478 struct obd_notify_upcall *onu;
1480 if (observer->obd_observer)
1481 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1485 * Also, call non-obd listener, if any
1487 onu = &observer->obd_upcall;
1488 if (onu->onu_upcall != NULL)
1489 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1493 return rc1 ? rc1 : rc2;
1496 static inline int obd_quotacheck(struct obd_export *exp,
1497 struct obd_quotactl *oqctl)
1502 EXP_CHECK_DT_OP(exp, quotacheck);
1503 OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1505 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1509 static inline int obd_quotactl(struct obd_export *exp,
1510 struct obd_quotactl *oqctl)
1515 EXP_CHECK_DT_OP(exp, quotactl);
1516 OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1518 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1522 static inline int obd_health_check(struct obd_device *obd)
1524 /* returns: 0 on healthy
1525 * >0 on unhealthy + reason code/flag
1526 * however the only suppored reason == 1 right now
1527 * We'll need to define some better reasons
1528 * or flags in the future.
1534 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1535 if (obd == NULL || !OBT(obd)) {
1536 CERROR("cleaned up obd\n");
1537 RETURN(-EOPNOTSUPP);
1539 if (!obd->obd_set_up || obd->obd_stopping)
1541 if (!OBP(obd, health_check))
1544 rc = OBP(obd, health_check)(obd);
1548 static inline int obd_register_observer(struct obd_device *obd,
1549 struct obd_device *observer)
1553 if (obd->obd_observer && observer)
1555 obd->obd_observer = observer;
1559 /* metadata helpers */
1560 static inline int md_getstatus(struct obd_export *exp,
1561 struct lu_fid *fid, struct obd_capa **pc)
1566 EXP_CHECK_MD_OP(exp, getstatus);
1567 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1568 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1572 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1573 struct obd_capa *oc, obd_valid valid, int ea_size,
1574 struct ptlrpc_request **request)
1578 EXP_CHECK_MD_OP(exp, getattr);
1579 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1580 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1585 static inline int md_change_cbdata(struct obd_export *exp,
1586 const struct lu_fid *fid,
1587 ldlm_iterator_t it, void *data)
1591 EXP_CHECK_MD_OP(exp, change_cbdata);
1592 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1593 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1597 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1598 struct obd_client_handle *och,
1599 struct ptlrpc_request **request)
1603 EXP_CHECK_MD_OP(exp, close);
1604 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1605 rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1609 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1610 const void *data, int datalen, int mode, __u32 uid,
1611 __u32 gid, __u32 cap_effective, __u64 rdev,
1612 struct ptlrpc_request **request)
1616 EXP_CHECK_MD_OP(exp, create);
1617 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1618 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1619 uid, gid, cap_effective, rdev, request);
1623 static inline int md_done_writing(struct obd_export *exp,
1624 struct md_op_data *op_data,
1625 struct obd_client_handle *och)
1629 EXP_CHECK_MD_OP(exp, done_writing);
1630 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1631 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, och);
1635 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1636 struct lookup_intent *it, int lock_mode,
1637 struct md_op_data *op_data,
1638 struct lustre_handle *lockh,
1639 void *lmm, int lmmsize,
1640 ldlm_completion_callback cb_completion,
1641 ldlm_blocking_callback cb_blocking,
1642 void *cb_data, int extra_lock_flags)
1646 EXP_CHECK_MD_OP(exp, enqueue);
1647 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1648 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1649 op_data, lockh, lmm, lmmsize,
1650 cb_completion, cb_blocking,
1651 cb_data, extra_lock_flags);
1655 static inline int md_getattr_name(struct obd_export *exp,
1656 const struct lu_fid *fid, struct obd_capa *oc,
1657 const char *name, int namelen,
1658 obd_valid valid, int ea_size,
1659 struct ptlrpc_request **request)
1663 EXP_CHECK_MD_OP(exp, getattr_name);
1664 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1665 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1666 valid, ea_size, request);
1670 static inline int md_intent_lock(struct obd_export *exp,
1671 struct md_op_data *op_data, void *lmm,
1672 int lmmsize, struct lookup_intent *it,
1673 int flags, struct ptlrpc_request **reqp,
1674 ldlm_blocking_callback cb_blocking,
1675 int extra_lock_flags)
1679 EXP_CHECK_MD_OP(exp, intent_lock);
1680 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1681 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1682 it, flags, reqp, cb_blocking,
1687 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1688 struct ptlrpc_request **request)
1692 EXP_CHECK_MD_OP(exp, link);
1693 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1694 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1698 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1699 const char *old, int oldlen, const char *new,
1700 int newlen, struct ptlrpc_request **request)
1704 EXP_CHECK_MD_OP(exp, rename);
1705 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1706 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1711 static inline int md_is_subdir(struct obd_export *exp,
1712 const struct lu_fid *pfid,
1713 const struct lu_fid *cfid,
1714 struct obd_capa *pc, struct obd_capa *cc,
1715 struct ptlrpc_request **request)
1719 EXP_CHECK_MD_OP(exp, is_subdir);
1720 MD_COUNTER_INCREMENT(exp->exp_obd, is_subdir);
1721 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, pc, cc, request);
1725 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1726 void *ea, int ealen, void *ea2, int ea2len,
1727 struct ptlrpc_request **request)
1731 EXP_CHECK_MD_OP(exp, setattr);
1732 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1733 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1734 ea2, ea2len, request);
1738 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1739 struct obd_capa *oc, struct ptlrpc_request **request)
1743 EXP_CHECK_MD_OP(exp, sync);
1744 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1745 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1749 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1750 struct obd_capa *oc, __u64 offset,
1752 struct ptlrpc_request **request)
1756 EXP_CHECK_MD_OP(exp, readpage);
1757 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1758 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1762 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1763 struct ptlrpc_request **request)
1767 EXP_CHECK_MD_OP(exp, unlink);
1768 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1769 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1773 static inline int md_get_lustre_md(struct obd_export *exp,
1774 struct ptlrpc_request *req,
1775 int offset, struct obd_export *dt_exp,
1776 struct obd_export *md_exp,
1777 struct lustre_md *md)
1780 EXP_CHECK_MD_OP(exp, get_lustre_md);
1781 MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1782 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1783 dt_exp, md_exp, md));
1786 static inline int md_free_lustre_md(struct obd_export *exp,
1787 struct lustre_md *md)
1790 EXP_CHECK_MD_OP(exp, free_lustre_md);
1791 MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1792 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1795 static inline int md_setxattr(struct obd_export *exp,
1796 const struct lu_fid *fid, struct obd_capa *oc,
1797 obd_valid valid, const char *name,
1798 const char *input, int input_size,
1799 int output_size, int flags,
1800 struct ptlrpc_request **request)
1803 EXP_CHECK_MD_OP(exp, setxattr);
1804 MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1805 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1806 input_size, output_size, flags,
1810 static inline int md_getxattr(struct obd_export *exp,
1811 const struct lu_fid *fid, struct obd_capa *oc,
1812 obd_valid valid, const char *name,
1813 const char *input, int input_size,
1814 int output_size, int flags,
1815 struct ptlrpc_request **request)
1818 EXP_CHECK_MD_OP(exp, getxattr);
1819 MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1820 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1821 input_size, output_size, flags,
1825 static inline int md_set_open_replay_data(struct obd_export *exp,
1826 struct obd_client_handle *och,
1827 struct ptlrpc_request *open_req)
1830 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1831 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1832 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1835 static inline int md_clear_open_replay_data(struct obd_export *exp,
1836 struct obd_client_handle *och)
1839 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1840 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1841 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1844 static inline int md_set_lock_data(struct obd_export *exp,
1845 __u64 *lockh, void *data)
1848 EXP_CHECK_MD_OP(exp, set_lock_data);
1849 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1850 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1853 static inline int md_cancel_unused(struct obd_export *exp,
1854 const struct lu_fid *fid,
1855 int flags, void *opaque)
1860 EXP_CHECK_MD_OP(exp, cancel_unused);
1861 MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1863 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1867 static inline int md_lock_match(struct obd_export *exp, int flags,
1868 const struct lu_fid *fid, ldlm_type_t type,
1869 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1870 struct lustre_handle *lockh)
1873 EXP_CHECK_MD_OP(exp, lock_match);
1874 MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1875 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1876 policy, mode, lockh));
1879 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1880 int def_asize, int cookiesize)
1883 EXP_CHECK_MD_OP(exp, init_ea_size);
1884 MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1885 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1889 static inline int md_get_remote_perm(struct obd_export *exp,
1890 const struct lu_fid *fid,
1891 struct obd_capa *oc,
1892 struct ptlrpc_request **request)
1895 EXP_CHECK_MD_OP(exp, get_remote_perm);
1896 MD_COUNTER_INCREMENT(exp->exp_obd, get_remote_perm);
1897 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, request));
1900 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1905 EXP_CHECK_MD_OP(exp, renew_capa);
1906 MD_COUNTER_INCREMENT(exp->exp_obd, renew_capa);
1907 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1911 /* OBD Metadata Support */
1912 extern int obd_init_caches(void);
1913 extern void obd_cleanup_caches(void);
1915 /* support routines */
1916 extern cfs_mem_cache_t *obdo_cachep;
1917 static inline struct obdo *obdo_alloc(void)
1920 OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1924 static inline void obdo_free(struct obdo *oa)
1926 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1929 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
1931 /* something here */
1934 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
1936 /* something here */
1939 /* I'm as embarrassed about this as you are.
1941 * <shaver> // XXX do not look into _superhack with remaining eye
1942 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1943 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1946 extern void obd_sysctl_init (void);
1947 extern void obd_sysctl_clean (void);
1950 typedef __u8 class_uuid_t[16];
1951 void class_generate_random_uuid(class_uuid_t uuid);
1952 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1955 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1956 int class_add_uuid(const char *uuid, __u64 nid);
1957 int class_del_uuid (const char *uuid);
1958 void class_init_uuidlist(void);
1959 void class_exit_uuidlist(void);
1962 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1963 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1965 #endif /* __LINUX_OBD_CLASS_H */