Whamcloud - gitweb
oss capability fully works now.
[fs/lustre-release.git] / lustre / include / obd_class.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  *
21  */
22
23 #ifndef __CLASS_OBD_H
24 #define __CLASS_OBD_H
25
26 #include <obd_support.h>
27 #include <lustre_import.h>
28 #include <lustre_net.h>
29 #include <obd.h>
30 #include <lustre_lib.h>
31 #include <lustre/lustre_idl.h>
32 #include <lprocfs_status.h>
33
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>
40 #else
41 #error Unsupported operating system.
42 #endif
43
44 /* OBD Device Declarations */
45 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
46 extern spinlock_t obd_dev_lock;
47
48 /* OBD Operations Declarations */
49 extern struct obd_device *class_conn2obd(struct lustre_handle *);
50 extern struct obd_device *class_exp2obd(struct obd_export *);
51
52 struct lu_device_type;
53
54 /* genops.c */
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);
60
61 struct obd_device *class_newdev(const char *type_name, const char *name);
62 void class_release_dev(struct obd_device *obd);
63
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,
75                                            int *next);
76 struct obd_device * class_num2obd(int num);
77
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);
84
85 char *obd_export_nid2str(struct obd_export *exp);
86
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);
89
90 /* obd_config.c */
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);
100
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 */
106
107 /* Passed as data param to class_config_parse_llog */
108 struct config_llog_instance {
109         char *              cfg_instance;
110         struct super_block *cfg_sb;
111         struct obd_uuid     cfg_uuid;
112         int                 cfg_last_idx; /* for partial llog processing */
113         int                 cfg_flags;
114 };
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);
119
120 /* list of active configuration logs  */
121 struct config_llog_data {
122         char               *cld_logname;
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;
129 };
130
131 struct lustre_profile {
132         struct list_head lp_list;
133         char            *lp_profile;
134         char            *lp_dt;
135         char            *lp_md;
136 };
137
138 struct lustre_profile *class_get_profile(const char * prof);
139 void class_del_profile(const char *prof);
140 void class_del_profiles(void);
141
142 /* genops.c */
143 #define class_export_get(exp)                                                  \
144 ({                                                                             \
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));                              \
149         exp_;                                                                  \
150 })
151
152 #define class_export_put(exp)                                                  \
153 do {                                                                           \
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);                                               \
160 } while (0)
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);
165
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);
170
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);
182
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,
191                   unsigned int valid);
192
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
197
198 /* Ensure obd_setup: used for cleanup which must be called
199    while obd is stopping */
200 #define OBD_CHECK_DEV(obd)                                      \
201 do {                                                            \
202         if (!(obd)) {                                           \
203                 CERROR("NULL device\n");                        \
204                 RETURN(-ENODEV);                                \
205         }                                                       \
206 } while (0)
207
208 /* ensure obd_setup and !obd_stopping */
209 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
210 do {                                                            \
211         OBD_CHECK_DEV(obd);                                     \
212         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
213                 CERROR("Device %d not setup\n",                 \
214                        (obd)->obd_minor);                       \
215                 RETURN(-ENODEV);                                \
216         }                                                       \
217 } while (0)
218
219
220 #ifdef LPROCFS
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))
225
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);  \
233         }
234
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))
239
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); \
247         }
248
249 #else
250 #define OBD_COUNTER_OFFSET(op)
251 #define OBD_COUNTER_INCREMENT(obd, op)
252 #define MD_COUNTER_INCREMENT(obd, op)
253 #endif
254
255 #define OBD_CHECK_MD_OP(obd, op, err)                           \
256 do {                                                            \
257         if (!OBT(obd) || !MDP((obd), op)) {                     \
258                 if (err)                                        \
259                         CERROR("md_" #op ": dev %s/%d no operation\n", \
260                                obd->obd_name, obd->obd_minor);  \
261                 RETURN(err);                                    \
262         }                                                       \
263 } while (0)
264
265 #define EXP_CHECK_MD_OP(exp, op)                                \
266 do {                                                            \
267         if ((exp) == NULL) {                                    \
268                 CERROR("obd_" #op ": NULL export\n");           \
269                 RETURN(-ENODEV);                                \
270         }                                                       \
271         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
272                 CERROR("obd_" #op ": cleaned up obd\n");        \
273                 RETURN(-EOPNOTSUPP);                            \
274         }                                                       \
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);                            \
280         }                                                       \
281 } while (0)
282
283
284 #define OBD_CHECK_DT_OP(obd, op, err)                           \
285 do {                                                            \
286         if (!OBT(obd) || !OBP((obd), op)) {                     \
287                 if (err)                                        \
288                         CERROR("obd_" #op ": dev %d no operation\n",    \
289                                obd->obd_minor);                 \
290                 RETURN(err);                                    \
291         }                                                       \
292 } while (0)
293
294 #define EXP_CHECK_DT_OP(exp, op)                                \
295 do {                                                            \
296         if ((exp) == NULL) {                                    \
297                 CERROR("obd_" #op ": NULL export\n");           \
298                 RETURN(-ENODEV);                                \
299         }                                                       \
300         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
301                 CERROR("obd_" #op ": cleaned up obd\n");        \
302                 RETURN(-EOPNOTSUPP);                            \
303         }                                                       \
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);                            \
308         }                                                       \
309 } while (0)
310
311 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
312 do {                                                            \
313         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
314                 if (err)                                        \
315                         CERROR("lop_" #op ": dev %d no operation\n",    \
316                                ctxt->loc_obd->obd_minor);                         \
317                 RETURN(err);                                    \
318         }                                                       \
319 } while (0)
320
321 static inline int class_devno_max(void)
322 {
323         return MAX_OBD_DEVICES;
324 }
325
326 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
327                                void *key, __u32 *vallen, void *val)
328 {
329         int rc;
330         ENTRY;
331
332         EXP_CHECK_DT_OP(exp, get_info);
333         OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
334
335         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
336         RETURN(rc);
337 }
338
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)
342 {
343         int rc;
344         ENTRY;
345
346         EXP_CHECK_DT_OP(exp, set_info_async);
347         OBD_COUNTER_INCREMENT(exp->exp_obd, set_info_async);
348
349         rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
350                                                set);
351         RETURN(rc);
352 }
353
354 #ifdef __KERNEL__
355 #define DECLARE_LU_VARS(ldt, d)                 \
356         struct lu_device_type *ldt;             \
357         struct lu_device *d
358 #else
359 #define DECLARE_LU_VARS(ldt, d)                                 \
360         extern void __placeholder_to_put_a_semicolon(void)
361 #endif
362 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
363 {
364         int rc;
365         DECLARE_LU_VARS(ldt, d);
366         ENTRY;
367
368 #ifdef __KERNEL__
369         ldt = obd->obd_type->typ_lu;
370         if (ldt != NULL) {
371                 struct lu_env env;
372
373                 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
374                 if (rc == 0) {
375                         d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
376                         lu_env_fini(&env);
377                         if (!IS_ERR(d)) {
378                                 obd->obd_lu_dev = d;
379                                 d->ld_obd = obd;
380                                 rc = 0;
381                         } else
382                                 rc = PTR_ERR(d);
383                 }
384         } else
385 #endif
386         {
387                 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
388                 OBD_COUNTER_INCREMENT(obd, setup);
389                 rc = OBP(obd, setup)(obd, cfg);
390         }
391         RETURN(rc);
392 }
393
394 static inline int obd_precleanup(struct obd_device *obd,
395                                  enum obd_cleanup_stage cleanup_stage)
396 {
397         int rc;
398         DECLARE_LU_VARS(ldt, d);
399         ENTRY;
400
401         OBD_CHECK_DEV(obd);
402 #ifdef __KERNEL__
403         ldt = obd->obd_type->typ_lu;
404         d = obd->obd_lu_dev;
405         if (ldt != NULL) {
406                 LASSERT(d != NULL);
407                 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
408                         struct lu_env env;
409
410                         rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
411                         if (rc == 0) {
412                                 ldt->ldt_ops->ldto_device_fini(&env, d);
413                                 lu_env_fini(&env);
414                         }
415                 } else {
416                         rc = 0;
417                 }
418         } else
419 #endif
420         {
421                 OBD_CHECK_DT_OP(obd, precleanup, 0);
422                 rc = OBP(obd, precleanup)(obd, cleanup_stage);
423         }
424
425         OBD_COUNTER_INCREMENT(obd, precleanup);
426         RETURN(rc);
427 }
428
429 static inline int obd_cleanup(struct obd_device *obd)
430 {
431         int rc;
432         DECLARE_LU_VARS(ldt, d);
433         ENTRY;
434
435         OBD_CHECK_DEV(obd);
436
437 #ifdef __KERNEL__
438         ldt = obd->obd_type->typ_lu;
439         d = obd->obd_lu_dev;
440         if (ldt != NULL) {
441                 struct lu_env env;
442                 LASSERT(d != NULL);
443
444                 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
445                 if (rc == 0) {
446                         ldt->ldt_ops->ldto_device_free(&env, d);
447                         lu_env_fini(&env);
448                         obd->obd_lu_dev = NULL;
449                 }
450         } else
451 #endif
452         {
453                 OBD_CHECK_DT_OP(obd, cleanup, 0);
454                 rc = OBP(obd, cleanup)(obd);
455         }
456         OBD_COUNTER_INCREMENT(obd, cleanup);
457         RETURN(rc);
458 }
459
460 static inline int
461 obd_process_config(struct obd_device *obd, int datalen, void *data)
462 {
463         int rc;
464         DECLARE_LU_VARS(ldt, d);
465         ENTRY;
466
467         OBD_CHECK_DEV(obd);
468
469 #ifdef __KERNEL__
470         ldt = obd->obd_type->typ_lu;
471         d = obd->obd_lu_dev;
472         if (ldt != NULL && d != NULL) {
473                 struct lu_env env;
474
475                 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
476                 if (rc == 0) {
477                         rc = d->ld_ops->ldo_process_config(&env, d, data);
478                         lu_env_fini(&env);
479                 }
480         } else
481 #endif
482         {
483                 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
484                 rc = OBP(obd, process_config)(obd, datalen, data);
485         }
486         OBD_COUNTER_INCREMENT(obd, process_config);
487
488         RETURN(rc);
489 }
490
491 /* Pack an in-memory MD struct for storage on disk.
492  * Returns +ve size of packed MD (0 for free), or -ve error.
493  *
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
497  */
498 static inline int obd_packmd(struct obd_export *exp,
499                              struct lov_mds_md **disk_tgt,
500                              struct lov_stripe_md *mem_src)
501 {
502         int rc;
503         ENTRY;
504
505         EXP_CHECK_DT_OP(exp, packmd);
506         OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
507
508         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
509         RETURN(rc);
510 }
511
512 static inline int obd_size_diskmd(struct obd_export *exp,
513                                   struct lov_stripe_md *mem_src)
514 {
515         return obd_packmd(exp, NULL, mem_src);
516 }
517
518 /* helper functions */
519 static inline int obd_alloc_diskmd(struct obd_export *exp,
520                                    struct lov_mds_md **disk_tgt)
521 {
522         LASSERT(disk_tgt);
523         LASSERT(*disk_tgt == NULL);
524         return obd_packmd(exp, disk_tgt, NULL);
525 }
526
527 static inline int obd_free_diskmd(struct obd_export *exp,
528                                   struct lov_mds_md **disk_tgt)
529 {
530         LASSERT(disk_tgt);
531         LASSERT(*disk_tgt);
532         return obd_packmd(exp, disk_tgt, NULL);
533 }
534
535 /* Unpack an MD struct from disk to in-memory format.
536  * Returns +ve size of unpacked MD (0 for free), or -ve error.
537  *
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
541  */
542 static inline int obd_unpackmd(struct obd_export *exp,
543                                struct lov_stripe_md **mem_tgt,
544                                struct lov_mds_md *disk_src,
545                                int disk_len)
546 {
547         int rc;
548         ENTRY;
549
550         EXP_CHECK_DT_OP(exp, unpackmd);
551         OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
552
553         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
554         RETURN(rc);
555 }
556
557 /* helper functions */
558 static inline int obd_alloc_memmd(struct obd_export *exp,
559                                   struct lov_stripe_md **mem_tgt)
560 {
561         LASSERT(mem_tgt);
562         LASSERT(*mem_tgt == NULL);
563         return obd_unpackmd(exp, mem_tgt, NULL, 0);
564 }
565
566 static inline int obd_free_memmd(struct obd_export *exp,
567                                  struct lov_stripe_md **mem_tgt)
568 {
569         LASSERT(mem_tgt);
570         LASSERT(*mem_tgt);
571         return obd_unpackmd(exp, mem_tgt, NULL, 0);
572 }
573
574 static inline int obd_checkmd(struct obd_export *exp,
575                               struct obd_export *md_exp,
576                               struct lov_stripe_md *mem_tgt)
577 {
578         int rc;
579         ENTRY;
580
581         EXP_CHECK_DT_OP(exp, checkmd);
582         OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
583
584         rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
585         RETURN(rc);
586 }
587
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)
591 {
592         int rc;
593         ENTRY;
594
595         EXP_CHECK_DT_OP(exp, create);
596         OBD_COUNTER_INCREMENT(exp->exp_obd, create);
597
598         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
599         RETURN(rc);
600 }
601
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)
606 {
607         int rc;
608         ENTRY;
609
610         EXP_CHECK_DT_OP(exp, destroy);
611         OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
612
613         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
614         RETURN(rc);
615 }
616
617 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
618 {
619         int rc;
620         ENTRY;
621
622         EXP_CHECK_DT_OP(exp, getattr);
623         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
624
625         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
626         RETURN(rc);
627 }
628
629 static inline int obd_getattr_async(struct obd_export *exp,
630                                     struct obd_info *oinfo,
631                                     struct ptlrpc_request_set *set)
632 {
633         int rc;
634         ENTRY;
635
636         EXP_CHECK_DT_OP(exp, getattr_async);
637         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr_async);
638
639         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
640         RETURN(rc);
641 }
642
643 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
644                               struct obd_trans_info *oti)
645 {
646         int rc;
647         ENTRY;
648
649         EXP_CHECK_DT_OP(exp, setattr);
650         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
651
652         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
653         RETURN(rc);
654 }
655
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)
660 {
661         struct ptlrpc_request_set *set = NULL;
662         int rc;
663         ENTRY;
664
665         EXP_CHECK_DT_OP(exp, setattr_async);
666         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
667
668         set =  ptlrpc_prep_set();
669         if (set == NULL)
670                 RETURN(-ENOMEM);
671
672         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
673         if (rc == 0)
674                 rc = ptlrpc_set_wait(set);
675         ptlrpc_set_destroy(set);
676         RETURN(rc);
677 }
678
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)
685 {
686         int rc;
687         ENTRY;
688
689         EXP_CHECK_DT_OP(exp, setattr_async);
690         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
691
692         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
693         RETURN(rc);
694 }
695
696 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
697                                int priority)
698 {
699         struct obd_device *obd = imp->imp_obd;
700         int rc;
701         ENTRY;
702
703         OBD_CHECK_DEV_ACTIVE(obd);
704         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
705         OBD_COUNTER_INCREMENT(obd, add_conn);
706
707         rc = OBP(obd, add_conn)(imp, uuid, priority);
708         RETURN(rc);
709 }
710
711 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
712 {
713         struct obd_device *obd = imp->imp_obd;
714         int rc;
715         ENTRY;
716
717         OBD_CHECK_DEV_ACTIVE(obd);
718         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
719         OBD_COUNTER_INCREMENT(obd, del_conn);
720
721         rc = OBP(obd, del_conn)(imp, uuid);
722         RETURN(rc);
723 }
724
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)
729 {
730         int rc;
731         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
732         ENTRY;
733
734         OBD_CHECK_DEV_ACTIVE(obd);
735         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
736         OBD_COUNTER_INCREMENT(obd, connect);
737
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));
742         RETURN(rc);
743 }
744
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)
749 {
750         int rc;
751         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
752         ENTRY;
753
754         OBD_CHECK_DEV_ACTIVE(obd);
755         OBD_CHECK_DT_OP(obd, reconnect, 0);
756         OBD_COUNTER_INCREMENT(obd, reconnect);
757
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));
762         RETURN(rc);
763 }
764
765 static inline int obd_disconnect(struct obd_export *exp)
766 {
767         int rc;
768         ENTRY;
769
770         EXP_CHECK_DT_OP(exp, disconnect);
771         OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
772
773         rc = OBP(exp->exp_obd, disconnect)(exp);
774         RETURN(rc);
775 }
776
777 static inline int obd_fid_init(struct obd_export *exp)
778 {
779         int rc;
780         ENTRY;
781
782         if (OBP(exp->exp_obd, fid_init) == NULL)
783                 RETURN(-ENOTSUPP);
784
785         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_init);
786
787         rc = OBP(exp->exp_obd, fid_init)(exp);
788         RETURN(rc);
789 }
790
791 static inline int obd_fid_fini(struct obd_export *exp)
792 {
793         int rc;
794         ENTRY;
795
796         if (OBP(exp->exp_obd, fid_fini) == NULL)
797                 RETURN(-ENOTSUPP);
798
799         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_fini);
800
801         rc = OBP(exp->exp_obd, fid_fini)(exp);
802         RETURN(rc);
803 }
804
805 static inline int obd_fid_alloc(struct obd_export *exp,
806                                 struct lu_fid *fid,
807                                 struct lu_placement_hint *hint)
808 {
809         int rc;
810         ENTRY;
811
812         if (OBP(exp->exp_obd, fid_alloc) == NULL)
813                 RETURN(-ENOTSUPP);
814
815         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
816
817         rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
818         RETURN(rc);
819 }
820
821 static inline int obd_fid_delete(struct obd_export *exp,
822                                  const struct lu_fid *fid)
823 {
824         int rc;
825         ENTRY;
826
827         if (OBP(exp->exp_obd, fid_delete) == NULL)
828                 RETURN(0);
829
830         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
831         rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
832         RETURN(rc);
833 }
834
835 static inline int obd_ping(struct obd_export *exp)
836 {
837         int rc;
838         ENTRY;
839
840         OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
841         OBD_COUNTER_INCREMENT(exp->exp_obd, ping);
842
843         rc = OBP(exp->exp_obd, ping)(exp);
844         RETURN(rc);
845 }
846
847 static inline int obd_init_export(struct obd_export *exp)
848 {
849         int rc = 0;
850
851         ENTRY;
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);
855         RETURN(rc);
856 }
857
858 static inline int obd_destroy_export(struct obd_export *exp)
859 {
860         ENTRY;
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);
864         RETURN(0);
865 }
866
867 static inline int obd_extent_calc(struct obd_export *exp,
868                                   struct lov_stripe_md *md,
869                                   int cmd, obd_off *offset)
870 {
871         int rc;
872         ENTRY;
873         EXP_CHECK_DT_OP(exp, extent_calc);
874         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
875         RETURN(rc);
876 }
877
878 static inline struct dentry *
879 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
880 {
881         LASSERT(exp->exp_obd);
882
883         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
884                                exp->exp_obd);
885 }
886
887 static inline int
888 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
889 {
890         LASSERT(exp->exp_obd);
891         CERROR("FIXME what's the story here?  This needs to be an obd fn?\n");
892 #if 0
893         return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
894                               dentry, exp->exp_obd);
895 #endif
896         return 0;
897 }
898
899 #ifndef time_before
900 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
901 #endif
902
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,
908                                    __u64 max_age,
909                                    struct ptlrpc_request_set *rqset)
910 {
911         int rc = 0;
912         ENTRY;
913
914         if (obd == NULL)
915                 RETURN(-EINVAL);
916
917         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
918         OBD_COUNTER_INCREMENT(obd, statfs);
919
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);
924         } else {
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);
929                 if (oinfo->oi_cb_up)
930                         oinfo->oi_cb_up(oinfo, 0);
931         }
932         RETURN(rc);
933 }
934
935 static inline int obd_statfs_rqset(struct obd_device *obd,
936                                    struct obd_statfs *osfs, __u64 max_age)
937 {
938         struct ptlrpc_request_set *set = NULL;
939         struct obd_info oinfo = { { { 0 } } };
940         int rc = 0;
941         ENTRY;
942
943         set =  ptlrpc_prep_set();
944         if (set == NULL)
945                 RETURN(-ENOMEM);
946
947         oinfo.oi_osfs = osfs;
948         rc = obd_statfs_async(obd, &oinfo, max_age, set);
949         if (rc == 0)
950                 rc = ptlrpc_set_wait(set);
951         ptlrpc_set_destroy(set);
952         RETURN(rc);
953 }
954
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,
959                              __u64 max_age)
960 {
961         int rc = 0;
962         ENTRY;
963
964         if (obd == NULL)
965                 RETURN(-EINVAL);
966
967         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
968         OBD_COUNTER_INCREMENT(obd, statfs);
969
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);
974                 if (rc == 0) {
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);
979                 }
980         } else {
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);
985         }
986         RETURN(rc);
987 }
988
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)
992 {
993         int rc;
994         ENTRY;
995
996         OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
997         OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
998
999         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1000         RETURN(rc);
1001 }
1002
1003 static inline int obd_punch_rqset(struct obd_export *exp,
1004                                   struct obd_info *oinfo,
1005                                   struct obd_trans_info *oti)
1006 {
1007         struct ptlrpc_request_set *set = NULL;
1008         int rc;
1009         ENTRY;
1010
1011         EXP_CHECK_DT_OP(exp, punch);
1012         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1013
1014         set =  ptlrpc_prep_set();
1015         if (set == NULL)
1016                 RETURN(-ENOMEM);
1017
1018         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1019         if (rc == 0)
1020                 rc = ptlrpc_set_wait(set);
1021         ptlrpc_set_destroy(set);
1022         RETURN(rc);
1023 }
1024
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)
1028 {
1029         int rc;
1030         ENTRY;
1031
1032         EXP_CHECK_DT_OP(exp, punch);
1033         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1034
1035         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1036         RETURN(rc);
1037 }
1038
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)
1042 {
1043         int rc;
1044         ENTRY;
1045
1046         EXP_CHECK_DT_OP(exp, brw);
1047         OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
1048
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");
1052                 LBUG();
1053         }
1054
1055         rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1056         RETURN(rc);
1057 }
1058
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)
1063 {
1064         int rc;
1065         ENTRY;
1066
1067         EXP_CHECK_DT_OP(exp, brw_async);
1068         OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
1069
1070         if (!(cmd & OBD_BRW_RWMASK)) {
1071                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1072                 LBUG();
1073         }
1074
1075         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1076         RETURN(rc);
1077 }
1078
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)
1084 {
1085         struct ptlrpc_request_set *set = NULL;
1086         struct obd_info oinfo = { { { 0 } } };
1087         int rc = 0;
1088         ENTRY;
1089
1090         set =  ptlrpc_prep_set();
1091         if (set == NULL)
1092                 RETURN(-ENOMEM);
1093
1094         oinfo.oi_oa = oa;
1095         oinfo.oi_md = lsm;
1096         oinfo.oi_capa = ocapa;
1097         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1098         if (rc == 0) {
1099                 rc = ptlrpc_set_wait(set);
1100                 if (rc)
1101                         CERROR("error from callback: rc = %d\n", rc);
1102         } else {
1103                 CDEBUG(D_INODE, "error from obd_brw_async: rc = %d\n", rc);
1104         }
1105         ptlrpc_set_destroy(set);
1106         RETURN(rc);
1107 }
1108
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)
1115 {
1116         int ret;
1117         ENTRY;
1118
1119         OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
1120         OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
1121
1122         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1123                                                  ops, data, res);
1124         RETURN(ret);
1125 }
1126
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)
1132 {
1133         int rc;
1134         ENTRY;
1135
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);
1139
1140         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1141                                                count, brw_flags, async_flags);
1142         RETURN(rc);
1143 }
1144
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)
1149 {
1150         int rc;
1151         ENTRY;
1152
1153         OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1154         OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
1155
1156         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1157                                                 async_flags);
1158         RETURN(rc);
1159 }
1160
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)
1168 {
1169         int rc;
1170         ENTRY;
1171
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);
1175
1176         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1177                                                cmd, off, count, brw_flags,
1178                                                async_flags);
1179         RETURN(rc);
1180 }
1181
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)
1186 {
1187         int rc;
1188         ENTRY;
1189
1190         OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1191         OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
1192
1193         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1194         RETURN(rc);
1195 }
1196
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)
1200 {
1201         int rc;
1202         ENTRY;
1203
1204         OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1205         OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
1206
1207         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1208         RETURN(rc);
1209 }
1210
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)
1217 {
1218         int rc;
1219         ENTRY;
1220
1221         OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1222         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1223
1224         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1225                                        remote, local, oti, capa);
1226         RETURN(rc);
1227 }
1228
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)
1233 {
1234         ENTRY;
1235
1236         OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1237         OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1238
1239         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1240                                          local, oti, rc);
1241         RETURN(rc);
1242 }
1243
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)
1247 {
1248         int rc;
1249         ENTRY;
1250
1251         OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1252         OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1253
1254         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1255         RETURN(rc);
1256 }
1257
1258 static inline int obd_adjust_kms(struct obd_export *exp,
1259                                  struct lov_stripe_md *lsm, obd_off size,
1260                                  int shrink)
1261 {
1262         int rc;
1263         ENTRY;
1264
1265         OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1266         OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1267
1268         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1269         RETURN(rc);
1270 }
1271
1272 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1273                                 int len, void *karg, void *uarg)
1274 {
1275         int rc;
1276         ENTRY;
1277
1278         EXP_CHECK_DT_OP(exp, iocontrol);
1279         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1280
1281         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1282         RETURN(rc);
1283 }
1284
1285 static inline int obd_enqueue_rqset(struct obd_export *exp,
1286                                     struct obd_info *oinfo,
1287                                     struct obd_enqueue_info *einfo)
1288 {
1289         int rc;
1290         ENTRY;
1291
1292         EXP_CHECK_DT_OP(exp, enqueue);
1293         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1294
1295         einfo->ei_rqset =  ptlrpc_prep_set();
1296         if (einfo->ei_rqset == NULL)
1297                 RETURN(-ENOMEM);
1298
1299         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1300         if (rc == 0)
1301                 rc = ptlrpc_set_wait(einfo->ei_rqset);
1302         ptlrpc_set_destroy(einfo->ei_rqset);
1303         einfo->ei_rqset = NULL;
1304
1305         RETURN(rc);
1306 }
1307
1308 static inline int obd_enqueue(struct obd_export *exp,
1309                               struct obd_info *oinfo,
1310                               struct obd_enqueue_info *einfo)
1311 {
1312         int rc;
1313         ENTRY;
1314
1315         EXP_CHECK_DT_OP(exp, enqueue);
1316         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1317
1318         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1319         RETURN(rc);
1320 }
1321
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)
1325 {
1326         int rc;
1327         ENTRY;
1328
1329         EXP_CHECK_DT_OP(exp, match);
1330         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1331
1332         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1333                                       lockh);
1334         RETURN(rc);
1335 }
1336
1337 static inline int obd_change_cbdata(struct obd_export *exp,
1338                                     struct lov_stripe_md *lsm,
1339                                     ldlm_iterator_t it, void *data)
1340 {
1341         int rc;
1342         ENTRY;
1343
1344         EXP_CHECK_DT_OP(exp, change_cbdata);
1345         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1346
1347         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1348         RETURN(rc);
1349 }
1350
1351 static inline int obd_cancel(struct obd_export *exp,
1352                              struct lov_stripe_md *ea, __u32 mode,
1353                              struct lustre_handle *lockh)
1354 {
1355         int rc;
1356         ENTRY;
1357
1358         EXP_CHECK_DT_OP(exp, cancel);
1359         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1360
1361         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1362         RETURN(rc);
1363 }
1364
1365 static inline int obd_cancel_unused(struct obd_export *exp,
1366                                     struct lov_stripe_md *ea,
1367                                     int flags, void *opaque)
1368 {
1369         int rc;
1370         ENTRY;
1371
1372         EXP_CHECK_DT_OP(exp, cancel_unused);
1373         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1374
1375         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1376         RETURN(rc);
1377 }
1378
1379 static inline int obd_join_lru(struct obd_export *exp,
1380                                struct lov_stripe_md *ea, int join)
1381 {
1382         int rc;
1383         ENTRY;
1384
1385         EXP_CHECK_DT_OP(exp, join_lru);
1386         OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1387
1388         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1389         RETURN(rc);
1390 }
1391
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,
1394                           int flag)
1395 {
1396         int rc;
1397
1398         EXP_CHECK_DT_OP(exp, pin);
1399         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1400
1401         rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1402         return(rc);
1403 }
1404
1405 static inline int obd_unpin(struct obd_export *exp,
1406                             struct obd_client_handle *handle, int flag)
1407 {
1408         int rc;
1409
1410         EXP_CHECK_DT_OP(exp, unpin);
1411         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1412
1413         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1414         return(rc);
1415 }
1416
1417
1418 static inline void obd_import_event(struct obd_device *obd,
1419                                     struct obd_import *imp,
1420                                     enum obd_import_event event)
1421 {
1422         if (!obd) {
1423                 CERROR("NULL device\n");
1424                 EXIT;
1425                 return;
1426         }
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);
1430         }
1431 }
1432
1433 static inline int obd_llog_connect(struct obd_export *exp,
1434                                    struct llogd_conn_body *body)
1435 {
1436         ENTRY;
1437
1438         OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1439         OBD_COUNTER_INCREMENT(exp->exp_obd, llog_connect);
1440
1441         return OBP(exp->exp_obd, llog_connect)(exp, body);
1442 }
1443
1444
1445 static inline int obd_notify(struct obd_device *obd,
1446                              struct obd_device *watched,
1447                              enum obd_notify_event ev,
1448                              void *data)
1449 {
1450         OBD_CHECK_DEV(obd);
1451
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);
1458                 return -EINVAL;
1459         }
1460
1461         if (!OBP(obd, notify)) {
1462                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1463                 return -ENOSYS;
1464         }
1465
1466         OBD_COUNTER_INCREMENT(obd, notify);
1467         return OBP(obd, notify)(obd, watched, ev, data);
1468 }
1469
1470 static inline int obd_notify_observer(struct obd_device *observer,
1471                                       struct obd_device *observed,
1472                                       enum obd_notify_event ev,
1473                                       void *data)
1474 {
1475         int rc1;
1476         int rc2;
1477
1478         struct obd_notify_upcall *onu;
1479
1480         if (observer->obd_observer)
1481                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1482         else
1483                 rc1 = 0;
1484         /*
1485          * Also, call non-obd listener, if any
1486          */
1487         onu = &observer->obd_upcall;
1488         if (onu->onu_upcall != NULL)
1489                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1490         else
1491                 rc2 = 0;
1492
1493         return rc1 ? rc1 : rc2;
1494 }
1495
1496 static inline int obd_quotacheck(struct obd_export *exp,
1497                                  struct obd_quotactl *oqctl)
1498 {
1499         int rc;
1500         ENTRY;
1501
1502         EXP_CHECK_DT_OP(exp, quotacheck);
1503         OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1504
1505         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1506         RETURN(rc);
1507 }
1508
1509 static inline int obd_quotactl(struct obd_export *exp,
1510                                struct obd_quotactl *oqctl)
1511 {
1512         int rc;
1513         ENTRY;
1514
1515         EXP_CHECK_DT_OP(exp, quotactl);
1516         OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1517
1518         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1519         RETURN(rc);
1520 }
1521
1522 static inline int obd_health_check(struct obd_device *obd)
1523 {
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.
1529          *         <0 on error
1530          */
1531         int rc;
1532         ENTRY;
1533
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);
1538         }
1539         if (!obd->obd_set_up || obd->obd_stopping)
1540                 RETURN(0);
1541         if (!OBP(obd, health_check))
1542                 RETURN(0);
1543
1544         rc = OBP(obd, health_check)(obd);
1545         RETURN(rc);
1546 }
1547
1548 static inline int obd_register_observer(struct obd_device *obd,
1549                                         struct obd_device *observer)
1550 {
1551         ENTRY;
1552         OBD_CHECK_DEV(obd);
1553         if (obd->obd_observer && observer)
1554                 RETURN(-EALREADY);
1555         obd->obd_observer = observer;
1556         RETURN(0);
1557 }
1558
1559 /* metadata helpers */
1560 static inline int md_getstatus(struct obd_export *exp,
1561                                struct lu_fid *fid, struct obd_capa **pc)
1562 {
1563         int rc;
1564         ENTRY;
1565
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);
1569         RETURN(rc);
1570 }
1571
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)
1575 {
1576         int rc;
1577         ENTRY;
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,
1581                                         ea_size, request);
1582         RETURN(rc);
1583 }
1584
1585 static inline int md_change_cbdata(struct obd_export *exp,
1586                                    const struct lu_fid *fid,
1587                                    ldlm_iterator_t it, void *data)
1588 {
1589         int rc;
1590         ENTRY;
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);
1594         RETURN(rc);
1595 }
1596
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)
1600 {
1601         int rc;
1602         ENTRY;
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);
1606         RETURN(rc);
1607 }
1608
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)
1613 {
1614         int rc;
1615         ENTRY;
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);
1620         RETURN(rc);
1621 }
1622
1623 static inline int md_done_writing(struct obd_export *exp,
1624                                   struct md_op_data *op_data,
1625                                   struct obd_client_handle *och)
1626 {
1627         int rc;
1628         ENTRY;
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);
1632         RETURN(rc);
1633 }
1634
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)
1643 {
1644         int rc;
1645         ENTRY;
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);
1652         RETURN(rc);
1653 }
1654
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)
1660 {
1661         int rc;
1662         ENTRY;
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);
1667         RETURN(rc);
1668 }
1669
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)
1676 {
1677         int rc;
1678         ENTRY;
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,
1683                                             extra_lock_flags);
1684         RETURN(rc);
1685 }
1686
1687 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1688                           struct ptlrpc_request **request)
1689 {
1690         int rc;
1691         ENTRY;
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);
1695         RETURN(rc);
1696 }
1697
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)
1701 {
1702         int rc;
1703         ENTRY;
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,
1707                                        newlen, request);
1708         RETURN(rc);
1709 }
1710
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)
1716 {
1717         int rc;
1718         ENTRY;
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);
1722         RETURN(rc);
1723 }
1724
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)
1728 {
1729         int rc;
1730         ENTRY;
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);
1735         RETURN(rc);
1736 }
1737
1738 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1739                           struct obd_capa *oc, struct ptlrpc_request **request)
1740 {
1741         int rc;
1742         ENTRY;
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);
1746         RETURN(rc);
1747 }
1748
1749 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1750                               struct obd_capa *oc, __u64 offset,
1751                               struct page *page,
1752                               struct ptlrpc_request **request)
1753 {
1754         int rc;
1755         ENTRY;
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);
1759         RETURN(rc);
1760 }
1761
1762 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1763                             struct ptlrpc_request **request)
1764 {
1765         int rc;
1766         ENTRY;
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);
1770         RETURN(rc);
1771 }
1772
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)
1778 {
1779         ENTRY;
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));
1784 }
1785
1786 static inline int md_free_lustre_md(struct obd_export *exp,
1787                                     struct lustre_md *md)
1788 {
1789         ENTRY;
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));
1793 }
1794
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)
1801 {
1802         ENTRY;
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,
1807                                            request));
1808 }
1809
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)
1816 {
1817         ENTRY;
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,
1822                                            request));
1823 }
1824
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)
1828 {
1829         ENTRY;
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));
1833 }
1834
1835 static inline int md_clear_open_replay_data(struct obd_export *exp,
1836                                             struct obd_client_handle *och)
1837 {
1838         ENTRY;
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));
1842 }
1843
1844 static inline int md_set_lock_data(struct obd_export *exp,
1845                                    __u64 *lockh, void *data)
1846 {
1847         ENTRY;
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));
1851 }
1852
1853 static inline int md_cancel_unused(struct obd_export *exp,
1854                                    const struct lu_fid *fid,
1855                                    int flags, void *opaque)
1856 {
1857         int rc;
1858         ENTRY;
1859
1860         EXP_CHECK_MD_OP(exp, cancel_unused);
1861         MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1862
1863         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1864         RETURN(rc);
1865 }
1866
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)
1871 {
1872         ENTRY;
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));
1877 }
1878
1879 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1880                                   int def_asize, int cookiesize)
1881 {
1882         ENTRY;
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,
1886                                                cookiesize));
1887 }
1888
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)
1893 {
1894         ENTRY;
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));
1898 }
1899
1900 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1901                                 renew_capa_cb_t cb)
1902 {
1903         int rc;
1904         ENTRY;
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);
1908         RETURN(rc);
1909 }
1910
1911 /* OBD Metadata Support */
1912 extern int obd_init_caches(void);
1913 extern void obd_cleanup_caches(void);
1914
1915 /* support routines */
1916 extern cfs_mem_cache_t *obdo_cachep;
1917 static inline struct obdo *obdo_alloc(void)
1918 {
1919         struct obdo *oa;
1920         OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1921         return oa;
1922 }
1923
1924 static inline void obdo_free(struct obdo *oa)
1925 {
1926         OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1927 }
1928
1929 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
1930 {
1931         /* something here */
1932 }
1933
1934 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
1935 {
1936         /* something here */
1937 }
1938
1939 /* I'm as embarrassed about this as you are.
1940  *
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);
1944
1945 /* sysctl.c */
1946 extern void obd_sysctl_init (void);
1947 extern void obd_sysctl_clean (void);
1948
1949 /* uuid.c  */
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);
1953
1954 /* lustre_peer.c    */
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);
1960
1961 /* mea.c */
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);
1964
1965 #endif /* __LINUX_OBD_CLASS_H */