Whamcloud - gitweb
d5afcd12f537f024c9ea8af3bbd7c86769a68fa2
[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 void class_disconnect_stale_exports(struct obd_device *obddev);
180 int class_manual_cleanup(struct obd_device *obd);
181
182 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
183 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
184 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
185 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
186                      unsigned int ia_valid);
187 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
188 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
189 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
190                   unsigned int valid);
191
192 #define OBT(dev)        (dev)->obd_type
193 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
194 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
195 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
196
197 /* Ensure obd_setup: used for cleanup which must be called
198    while obd is stopping */
199 #define OBD_CHECK_DEV(obd)                                      \
200 do {                                                            \
201         if (!(obd)) {                                           \
202                 CERROR("NULL device\n");                        \
203                 RETURN(-ENODEV);                                \
204         }                                                       \
205 } while (0)
206
207 /* ensure obd_setup and !obd_stopping */
208 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
209 do {                                                            \
210         OBD_CHECK_DEV(obd);                                     \
211         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
212                 CERROR("Device %d not setup\n",                 \
213                        (obd)->obd_minor);                       \
214                 RETURN(-ENODEV);                                \
215         }                                                       \
216 } while (0)
217
218
219 #ifdef LPROCFS
220 #define OBD_COUNTER_OFFSET(op)                                  \
221         ((offsetof(struct obd_ops, o_ ## op) -                  \
222           offsetof(struct obd_ops, o_iocontrol))                \
223          / sizeof(((struct obd_ops *)(0))->o_iocontrol))
224
225 #define OBD_COUNTER_INCREMENT(obd, op)                          \
226         if ((obd)->obd_stats != NULL) {                         \
227                 unsigned int coffset;                           \
228                 coffset = (unsigned int)(obd)->obd_cntr_base +  \
229                         OBD_COUNTER_OFFSET(op);                 \
230                 LASSERT(coffset < obd->obd_stats->ls_num);      \
231                 lprocfs_counter_incr(obd->obd_stats, coffset);  \
232         }
233
234 #define MD_COUNTER_OFFSET(op)                                  \
235         ((offsetof(struct md_ops, m_ ## op) -                  \
236           offsetof(struct md_ops, m_getstatus))                \
237          / sizeof(((struct md_ops *)(0))->m_getstatus))
238
239 #define MD_COUNTER_INCREMENT(obd, op)                           \
240         if ((obd)->md_stats != NULL) {                          \
241                 unsigned int coffset;                           \
242                 coffset = (unsigned int)(obd)->md_cntr_base +   \
243                         MD_COUNTER_OFFSET(op);                  \
244                 LASSERT(coffset < (obd)->md_stats->ls_num);     \
245                 lprocfs_counter_incr((obd)->md_stats, coffset); \
246         }
247
248 #else
249 #define OBD_COUNTER_OFFSET(op)
250 #define OBD_COUNTER_INCREMENT(obd, op)
251 #define MD_COUNTER_INCREMENT(obd, op)
252 #endif
253
254 #define OBD_CHECK_MD_OP(obd, op, err)                           \
255 do {                                                            \
256         if (!OBT(obd) || !MDP((obd), op)) {                     \
257                 if (err)                                        \
258                         CERROR("md_" #op ": dev %s/%d no operation\n", \
259                                obd->obd_name, obd->obd_minor);  \
260                 RETURN(err);                                    \
261         }                                                       \
262 } while (0)
263
264 #define EXP_CHECK_MD_OP(exp, op)                                \
265 do {                                                            \
266         if ((exp) == NULL) {                                    \
267                 CERROR("obd_" #op ": NULL export\n");           \
268                 RETURN(-ENODEV);                                \
269         }                                                       \
270         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
271                 CERROR("obd_" #op ": cleaned up obd\n");        \
272                 RETURN(-EOPNOTSUPP);                            \
273         }                                                       \
274         if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
275                 CERROR("obd_" #op ": dev %s/%d no operation\n", \
276                        (exp)->exp_obd->obd_name,                \
277                        (exp)->exp_obd->obd_minor);              \
278                 RETURN(-EOPNOTSUPP);                            \
279         }                                                       \
280 } while (0)
281
282
283 #define OBD_CHECK_DT_OP(obd, op, err)                           \
284 do {                                                            \
285         if (!OBT(obd) || !OBP((obd), op)) {                     \
286                 if (err)                                        \
287                         CERROR("obd_" #op ": dev %d no operation\n",    \
288                                obd->obd_minor);                 \
289                 RETURN(err);                                    \
290         }                                                       \
291 } while (0)
292
293 #define EXP_CHECK_DT_OP(exp, op)                                \
294 do {                                                            \
295         if ((exp) == NULL) {                                    \
296                 CERROR("obd_" #op ": NULL export\n");           \
297                 RETURN(-ENODEV);                                \
298         }                                                       \
299         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
300                 CERROR("obd_" #op ": cleaned up obd\n");        \
301                 RETURN(-EOPNOTSUPP);                            \
302         }                                                       \
303         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
304                 CERROR("obd_" #op ": dev %d no operation\n",    \
305                        (exp)->exp_obd->obd_minor);              \
306                 RETURN(-EOPNOTSUPP);                            \
307         }                                                       \
308 } while (0)
309
310 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
311 do {                                                            \
312         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
313                 if (err)                                        \
314                         CERROR("lop_" #op ": dev %d no operation\n",    \
315                                ctxt->loc_obd->obd_minor);                         \
316                 RETURN(err);                                    \
317         }                                                       \
318 } while (0)
319
320 static inline int class_devno_max(void)
321 {
322         return MAX_OBD_DEVICES;
323 }
324
325 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
326                                void *key, __u32 *vallen, void *val)
327 {
328         int rc;
329         ENTRY;
330
331         EXP_CHECK_DT_OP(exp, get_info);
332         OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
333
334         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
335         RETURN(rc);
336 }
337
338 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
339                                      void *key, obd_count vallen, void *val,
340                                      struct ptlrpc_request_set *set)
341 {
342         int rc;
343         ENTRY;
344
345         EXP_CHECK_DT_OP(exp, set_info_async);
346         OBD_COUNTER_INCREMENT(exp->exp_obd, set_info_async);
347
348         rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
349                                                set);
350         RETURN(rc);
351 }
352
353 #ifdef __KERNEL__
354 #define DECLARE_LU_VARS(ldt, d)                 \
355         struct lu_device_type *ldt;             \
356         struct lu_device *d
357 #else
358 #define DECLARE_LU_VARS(ldt, d)                                 \
359         extern void __placeholder_to_put_a_semicolon(void)
360 #endif
361 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
362 {
363         int rc;
364         DECLARE_LU_VARS(ldt, d);
365         ENTRY;
366
367 #ifdef __KERNEL__
368         ldt = obd->obd_type->typ_lu;
369         if (ldt != NULL) {
370                 struct lu_context ctx;
371
372                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
373                 if (rc == 0) {
374                         lu_context_enter(&ctx);
375                         d = ldt->ldt_ops->ldto_device_alloc(&ctx, ldt, cfg);
376                         lu_context_exit(&ctx);
377                         lu_context_fini(&ctx);
378                         if (!IS_ERR(d)) {
379                                 obd->obd_lu_dev = d;
380                                 d->ld_obd = obd;
381                                 rc = 0;
382                         } else
383                                 rc = PTR_ERR(d);
384                 }
385         } else
386 #endif
387         {
388                 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
389                 OBD_COUNTER_INCREMENT(obd, setup);
390                 rc = OBP(obd, setup)(obd, cfg);
391         }
392         RETURN(rc);
393 }
394
395 static inline int obd_precleanup(struct obd_device *obd,
396                                  enum obd_cleanup_stage cleanup_stage)
397 {
398         int rc;
399         DECLARE_LU_VARS(ldt, d);
400         ENTRY;
401
402         OBD_CHECK_DEV(obd);
403 #ifdef __KERNEL__
404         ldt = obd->obd_type->typ_lu;
405         d = obd->obd_lu_dev;
406         if (ldt != NULL) {
407                 LASSERT(d != NULL);
408                 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
409                         struct lu_context ctx;
410                         
411                         rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
412                         if (rc == 0) {
413                                 lu_context_enter(&ctx);
414                                 ldt->ldt_ops->ldto_device_fini(&ctx, d);
415                                 lu_context_exit(&ctx);
416                                 lu_context_fini(&ctx);
417                         }
418                 } else {
419                         rc = 0;
420                 }
421         } else
422 #endif
423         {
424                 OBD_CHECK_DT_OP(obd, precleanup, 0);
425                 rc = OBP(obd, precleanup)(obd, cleanup_stage);
426         }
427         
428         OBD_COUNTER_INCREMENT(obd, precleanup);
429         RETURN(rc);
430 }
431
432 static inline int obd_cleanup(struct obd_device *obd)
433 {
434         int rc;
435         DECLARE_LU_VARS(ldt, d);
436         ENTRY;
437
438         OBD_CHECK_DEV(obd);
439
440 #ifdef __KERNEL__
441         ldt = obd->obd_type->typ_lu;
442         d = obd->obd_lu_dev;
443         if (ldt != NULL) {
444                 struct lu_context ctx;
445                 LASSERT(d != NULL);
446
447                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
448                 if (rc == 0) {
449                         lu_context_enter(&ctx);
450                         ldt->ldt_ops->ldto_device_free(&ctx, d);
451                         lu_context_exit(&ctx);
452                         lu_context_fini(&ctx);
453                         obd->obd_lu_dev = NULL;
454                 }
455         } else
456 #endif
457         {
458                 OBD_CHECK_DT_OP(obd, cleanup, 0);
459                 rc = OBP(obd, cleanup)(obd);
460         }
461         OBD_COUNTER_INCREMENT(obd, cleanup);
462         RETURN(rc);
463 }
464
465 static inline int
466 obd_process_config(struct obd_device *obd, int datalen, void *data)
467 {
468         int rc;
469         DECLARE_LU_VARS(ldt, d);
470         ENTRY;
471
472         OBD_CHECK_DEV(obd);
473
474 #ifdef __KERNEL__
475         ldt = obd->obd_type->typ_lu;
476         d = obd->obd_lu_dev;
477         if (ldt != NULL && d != NULL) {
478                 struct lu_context ctx;
479
480                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
481                 if (rc == 0) {
482                         lu_context_enter(&ctx);
483                         rc = d->ld_ops->ldo_process_config(&ctx, d, data);
484                         lu_context_exit(&ctx);
485                         lu_context_fini(&ctx);
486                 }
487         } else
488 #endif
489         {
490                 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
491                 rc = OBP(obd, process_config)(obd, datalen, data);
492         }
493         OBD_COUNTER_INCREMENT(obd, process_config);
494
495         RETURN(rc);
496 }
497
498 /* Pack an in-memory MD struct for storage on disk.
499  * Returns +ve size of packed MD (0 for free), or -ve error.
500  *
501  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
502  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
503  * If @*disk_tgt == NULL, it will be allocated
504  */
505 static inline int obd_packmd(struct obd_export *exp,
506                              struct lov_mds_md **disk_tgt,
507                              struct lov_stripe_md *mem_src)
508 {
509         int rc;
510         ENTRY;
511
512         EXP_CHECK_DT_OP(exp, packmd);
513         OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
514
515         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
516         RETURN(rc);
517 }
518
519 static inline int obd_size_diskmd(struct obd_export *exp,
520                                   struct lov_stripe_md *mem_src)
521 {
522         return obd_packmd(exp, NULL, mem_src);
523 }
524
525 /* helper functions */
526 static inline int obd_alloc_diskmd(struct obd_export *exp,
527                                    struct lov_mds_md **disk_tgt)
528 {
529         LASSERT(disk_tgt);
530         LASSERT(*disk_tgt == NULL);
531         return obd_packmd(exp, disk_tgt, NULL);
532 }
533
534 static inline int obd_free_diskmd(struct obd_export *exp,
535                                   struct lov_mds_md **disk_tgt)
536 {
537         LASSERT(disk_tgt);
538         LASSERT(*disk_tgt);
539         return obd_packmd(exp, disk_tgt, NULL);
540 }
541
542 /* Unpack an MD struct from disk to in-memory format.
543  * Returns +ve size of unpacked MD (0 for free), or -ve error.
544  *
545  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
546  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
547  * If @*mem_tgt == NULL, it will be allocated
548  */
549 static inline int obd_unpackmd(struct obd_export *exp,
550                                struct lov_stripe_md **mem_tgt,
551                                struct lov_mds_md *disk_src,
552                                int disk_len)
553 {
554         int rc;
555         ENTRY;
556
557         EXP_CHECK_DT_OP(exp, unpackmd);
558         OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
559
560         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
561         RETURN(rc);
562 }
563
564 /* helper functions */
565 static inline int obd_alloc_memmd(struct obd_export *exp,
566                                   struct lov_stripe_md **mem_tgt)
567 {
568         LASSERT(mem_tgt);
569         LASSERT(*mem_tgt == NULL);
570         return obd_unpackmd(exp, mem_tgt, NULL, 0);
571 }
572
573 static inline int obd_free_memmd(struct obd_export *exp,
574                                  struct lov_stripe_md **mem_tgt)
575 {
576         LASSERT(mem_tgt);
577         LASSERT(*mem_tgt);
578         return obd_unpackmd(exp, mem_tgt, NULL, 0);
579 }
580
581 static inline int obd_checkmd(struct obd_export *exp,
582                               struct obd_export *md_exp,
583                               struct lov_stripe_md *mem_tgt)
584 {
585         int rc;
586         ENTRY;
587
588         EXP_CHECK_DT_OP(exp, checkmd);
589         OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
590
591         rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
592         RETURN(rc);
593 }
594
595 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
596                              struct lov_stripe_md **ea,
597                              struct obd_trans_info *oti)
598 {
599         int rc;
600         ENTRY;
601
602         EXP_CHECK_DT_OP(exp, create);
603         OBD_COUNTER_INCREMENT(exp->exp_obd, create);
604
605         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
606         RETURN(rc);
607 }
608
609 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
610                               struct lov_stripe_md *ea,
611                               struct obd_trans_info *oti,
612                               struct obd_export *md_exp, void *capa)
613 {
614         int rc;
615         ENTRY;
616
617         EXP_CHECK_DT_OP(exp, destroy);
618         OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
619
620         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
621         RETURN(rc);
622 }
623
624 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
625 {
626         int rc;
627         ENTRY;
628
629         EXP_CHECK_DT_OP(exp, getattr);
630         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
631
632         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
633         RETURN(rc);
634 }
635
636 static inline int obd_getattr_async(struct obd_export *exp,
637                                     struct obd_info *oinfo,
638                                     struct ptlrpc_request_set *set)
639 {
640         int rc;
641         ENTRY;
642
643         EXP_CHECK_DT_OP(exp, getattr_async);
644         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr_async);
645
646         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
647         RETURN(rc);
648 }
649
650 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
651                               struct obd_trans_info *oti)
652 {
653         int rc;
654         ENTRY;
655
656         EXP_CHECK_DT_OP(exp, setattr);
657         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
658
659         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
660         RETURN(rc);
661 }
662
663 /* This performs all the requests set init/wait/destroy actions. */
664 static inline int obd_setattr_rqset(struct obd_export *exp,
665                                     struct obd_info *oinfo,
666                                     struct obd_trans_info *oti)
667 {
668         struct ptlrpc_request_set *set = NULL;
669         int rc;
670         ENTRY;
671
672         EXP_CHECK_DT_OP(exp, setattr_async);
673         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
674
675         set =  ptlrpc_prep_set();
676         if (set == NULL)
677                 RETURN(-ENOMEM);
678
679         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
680         if (rc == 0)
681                 rc = ptlrpc_set_wait(set);
682         ptlrpc_set_destroy(set);
683         RETURN(rc);
684 }
685
686 /* This adds all the requests into @set if @set != NULL, otherwise
687    all requests are sent asynchronously without waiting for response. */
688 static inline int obd_setattr_async(struct obd_export *exp,
689                                     struct obd_info *oinfo,
690                                     struct obd_trans_info *oti,
691                                     struct ptlrpc_request_set *set)
692 {
693         int rc;
694         ENTRY;
695
696         EXP_CHECK_DT_OP(exp, setattr_async);
697         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
698
699         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
700         RETURN(rc);
701 }
702
703 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
704                                int priority)
705 {
706         struct obd_device *obd = imp->imp_obd;
707         int rc;
708         ENTRY;
709
710         OBD_CHECK_DEV_ACTIVE(obd);
711         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
712         OBD_COUNTER_INCREMENT(obd, add_conn);
713
714         rc = OBP(obd, add_conn)(imp, uuid, priority);
715         RETURN(rc);
716 }
717
718 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
719 {
720         struct obd_device *obd = imp->imp_obd;
721         int rc;
722         ENTRY;
723
724         OBD_CHECK_DEV_ACTIVE(obd);
725         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
726         OBD_COUNTER_INCREMENT(obd, del_conn);
727
728         rc = OBP(obd, del_conn)(imp, uuid);
729         RETURN(rc);
730 }
731
732 static inline int obd_connect(const struct lu_context *ctx,
733                               struct lustre_handle *conn,struct obd_device *obd,
734                               struct obd_uuid *cluuid,
735                               struct obd_connect_data *d)
736 {
737         int rc;
738         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
739         ENTRY;
740
741         OBD_CHECK_DEV_ACTIVE(obd);
742         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
743         OBD_COUNTER_INCREMENT(obd, connect);
744
745         rc = OBP(obd, connect)(ctx, conn, obd, cluuid, d);
746         /* check that only subset is granted */
747         LASSERT(ergo(d != NULL,
748                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
749         RETURN(rc);
750 }
751
752 static inline int obd_reconnect(struct obd_export *exp,
753                                 struct obd_device *obd,
754                                 struct obd_uuid *cluuid,
755                                 struct obd_connect_data *d)
756 {
757         int rc;
758         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
759         ENTRY;
760
761         OBD_CHECK_DEV_ACTIVE(obd);
762         OBD_CHECK_DT_OP(obd, reconnect, 0);
763         OBD_COUNTER_INCREMENT(obd, reconnect);
764
765         rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
766         /* check that only subset is granted */
767         LASSERT(ergo(d != NULL,
768                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
769         RETURN(rc);
770 }
771
772 static inline int obd_disconnect(struct obd_export *exp)
773 {
774         int rc;
775         ENTRY;
776
777         EXP_CHECK_DT_OP(exp, disconnect);
778         OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
779
780         rc = OBP(exp->exp_obd, disconnect)(exp);
781         RETURN(rc);
782 }
783
784 static inline int obd_fid_init(struct obd_export *exp)
785 {
786         int rc;
787         ENTRY;
788
789         if (OBP(exp->exp_obd, fid_init) == NULL)
790                 RETURN(-ENOTSUPP);
791
792         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_init);
793
794         rc = OBP(exp->exp_obd, fid_init)(exp);
795         RETURN(rc);
796 }
797
798 static inline int obd_fid_fini(struct obd_export *exp)
799 {
800         int rc;
801         ENTRY;
802
803         if (OBP(exp->exp_obd, fid_fini) == NULL)
804                 RETURN(-ENOTSUPP);
805
806         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_fini);
807
808         rc = OBP(exp->exp_obd, fid_fini)(exp);
809         RETURN(rc);
810 }
811
812 static inline int obd_fid_alloc(struct obd_export *exp,
813                                 struct lu_fid *fid,
814                                 struct lu_placement_hint *hint)
815 {
816         int rc;
817         ENTRY;
818
819         if (OBP(exp->exp_obd, fid_alloc) == NULL)
820                 RETURN(-ENOTSUPP);
821
822         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
823
824         rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
825         RETURN(rc);
826 }
827
828 static inline int obd_fid_delete(struct obd_export *exp,
829                                  const struct lu_fid *fid)
830 {
831         int rc;
832         ENTRY;
833
834         if (OBP(exp->exp_obd, fid_delete) == NULL)
835                 RETURN(0);
836
837         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
838         rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
839         RETURN(rc);
840 }
841
842 static inline int obd_ping(struct obd_export *exp)
843 {
844         int rc;
845         ENTRY;
846
847         OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
848         OBD_COUNTER_INCREMENT(exp->exp_obd, ping);
849
850         rc = OBP(exp->exp_obd, ping)(exp);
851         RETURN(rc);
852 }
853
854 static inline int obd_init_export(struct obd_export *exp)
855 {
856         int rc = 0;
857
858         ENTRY;
859         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
860             OBP((exp)->exp_obd, init_export))
861                 rc = OBP(exp->exp_obd, init_export)(exp);
862         RETURN(rc);
863 }
864
865 static inline int obd_destroy_export(struct obd_export *exp)
866 {
867         ENTRY;
868         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
869             OBP((exp)->exp_obd, destroy_export))
870                 OBP(exp->exp_obd, destroy_export)(exp);
871         RETURN(0);
872 }
873
874 static inline int obd_extent_calc(struct obd_export *exp,
875                                   struct lov_stripe_md *md,
876                                   int cmd, obd_off *offset)
877 {
878         int rc;
879         ENTRY;
880         EXP_CHECK_DT_OP(exp, extent_calc);
881         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
882         RETURN(rc);
883 }
884
885 static inline struct dentry *
886 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
887 {
888         LASSERT(exp->exp_obd);
889
890         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
891                                exp->exp_obd);
892 }
893
894 static inline int
895 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
896 {
897         LASSERT(exp->exp_obd);
898         CERROR("FIXME what's the story here?  This needs to be an obd fn?\n");
899 #if 0
900         return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
901                               dentry, exp->exp_obd);
902 #endif
903         return 0;
904 }
905
906 #ifndef time_before
907 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
908 #endif
909
910 /* @max_age is the oldest time in jiffies that we accept using a cached data.
911  * If the cache is older than @max_age we will get a new value from the
912  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
913 static inline int obd_statfs_async(struct obd_device *obd,
914                                    struct obd_info *oinfo,
915                                    __u64 max_age,
916                                    struct ptlrpc_request_set *rqset)
917 {
918         int rc = 0;
919         ENTRY;
920
921         if (obd == NULL)
922                 RETURN(-EINVAL);
923
924         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
925         OBD_COUNTER_INCREMENT(obd, statfs);
926
927         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
928                obd->obd_osfs_age, max_age);
929         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
930                 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
931         } else {
932                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
933                 spin_lock(&obd->obd_osfs_lock);
934                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
935                 spin_unlock(&obd->obd_osfs_lock);
936                 if (oinfo->oi_cb_up)
937                         oinfo->oi_cb_up(oinfo, 0);
938         }
939         RETURN(rc);
940 }
941
942 static inline int obd_statfs_rqset(struct obd_device *obd,
943                                    struct obd_statfs *osfs, __u64 max_age)
944 {
945         struct ptlrpc_request_set *set = NULL;
946         struct obd_info oinfo = { { { 0 } } };
947         int rc = 0;
948         ENTRY;
949
950         set =  ptlrpc_prep_set();
951         if (set == NULL)
952                 RETURN(-ENOMEM);
953
954         oinfo.oi_osfs = osfs;
955         rc = obd_statfs_async(obd, &oinfo, max_age, set);
956         if (rc == 0)
957                 rc = ptlrpc_set_wait(set);
958         ptlrpc_set_destroy(set);
959         RETURN(rc);
960 }
961
962 /* @max_age is the oldest time in jiffies that we accept using a cached data.
963  * If the cache is older than @max_age we will get a new value from the
964  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
965 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
966                              __u64 max_age)
967 {
968         int rc = 0;
969         ENTRY;
970
971         if (obd == NULL)
972                 RETURN(-EINVAL);
973
974         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
975         OBD_COUNTER_INCREMENT(obd, statfs);
976
977         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
978                obd->obd_osfs_age, max_age);
979         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
980                 rc = OBP(obd, statfs)(obd, osfs, max_age);
981                 if (rc == 0) {
982                         spin_lock(&obd->obd_osfs_lock);
983                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
984                         obd->obd_osfs_age = cfs_time_current_64();
985                         spin_unlock(&obd->obd_osfs_lock);
986                 }
987         } else {
988                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
989                 spin_lock(&obd->obd_osfs_lock);
990                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
991                 spin_unlock(&obd->obd_osfs_lock);
992         }
993         RETURN(rc);
994 }
995
996 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
997                            struct lov_stripe_md *ea, obd_size start,
998                            obd_size end, void *capa)
999 {
1000         int rc;
1001         ENTRY;
1002
1003         OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1004         OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
1005
1006         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1007         RETURN(rc);
1008 }
1009
1010 static inline int obd_punch_rqset(struct obd_export *exp,
1011                                   struct obd_info *oinfo,
1012                                   struct obd_trans_info *oti)
1013 {
1014         struct ptlrpc_request_set *set = NULL;
1015         int rc;
1016         ENTRY;
1017
1018         EXP_CHECK_DT_OP(exp, punch);
1019         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1020
1021         set =  ptlrpc_prep_set();
1022         if (set == NULL)
1023                 RETURN(-ENOMEM);
1024
1025         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1026         if (rc == 0)
1027                 rc = ptlrpc_set_wait(set);
1028         ptlrpc_set_destroy(set);
1029         RETURN(rc);
1030 }
1031
1032 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1033                             struct obd_trans_info *oti,
1034                             struct ptlrpc_request_set *rqset)
1035 {
1036         int rc;
1037         ENTRY;
1038
1039         EXP_CHECK_DT_OP(exp, punch);
1040         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
1041
1042         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1043         RETURN(rc);
1044 }
1045
1046 static inline int obd_brw(int cmd, struct obd_export *exp,
1047                           struct obd_info *oinfo, obd_count oa_bufs,
1048                           struct brw_page *pg, struct obd_trans_info *oti)
1049 {
1050         int rc;
1051         ENTRY;
1052
1053         EXP_CHECK_DT_OP(exp, brw);
1054         OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
1055
1056         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1057                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1058                        "or OBD_BRW_CHECK\n");
1059                 LBUG();
1060         }
1061
1062         rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1063         RETURN(rc);
1064 }
1065
1066 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1067                                 struct obd_info *oinfo, obd_count oa_bufs,
1068                                 struct brw_page *pg, struct obd_trans_info *oti,
1069                                 struct ptlrpc_request_set *set)
1070 {
1071         int rc;
1072         ENTRY;
1073
1074         EXP_CHECK_DT_OP(exp, brw_async);
1075         OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
1076
1077         if (!(cmd & OBD_BRW_RWMASK)) {
1078                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1079                 LBUG();
1080         }
1081
1082         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1083         RETURN(rc);
1084 }
1085
1086 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1087                                 struct obdo *oa, struct lov_stripe_md *lsm,
1088                                 obd_count oa_bufs, struct brw_page *pg,
1089                                 struct obd_trans_info *oti,
1090                                 struct obd_capa *ocapa)
1091 {
1092         struct ptlrpc_request_set *set = NULL;
1093         struct obd_info oinfo = { { { 0 } } };
1094         int rc = 0;
1095         ENTRY;
1096
1097         set =  ptlrpc_prep_set();
1098         if (set == NULL)
1099                 RETURN(-ENOMEM);
1100
1101         oinfo.oi_oa = oa;
1102         oinfo.oi_md = lsm;
1103         oinfo.oi_capa = ocapa;
1104         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1105         if (rc == 0) {
1106                 rc = ptlrpc_set_wait(set);
1107                 if (rc)
1108                         CERROR("error from callback: rc = %d\n", rc);
1109         } else {
1110                 CDEBUG(D_INODE, "error from obd_brw_async: rc = %d\n", rc);
1111         }
1112         ptlrpc_set_destroy(set);
1113         RETURN(rc);
1114 }
1115
1116 static inline  int obd_prep_async_page(struct obd_export *exp,
1117                                        struct lov_stripe_md *lsm,
1118                                        struct lov_oinfo *loi,
1119                                        struct page *page, obd_off offset,
1120                                        struct obd_async_page_ops *ops,
1121                                        void *data, void **res)
1122 {
1123         int ret;
1124         ENTRY;
1125
1126         OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
1127         OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
1128
1129         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1130                                                  ops, data, res);
1131         RETURN(ret);
1132 }
1133
1134 static inline int obd_queue_async_io(struct obd_export *exp,
1135                                      struct lov_stripe_md *lsm,
1136                                      struct lov_oinfo *loi, void *cookie,
1137                                      int cmd, obd_off off, int count,
1138                                      obd_flag brw_flags, obd_flag async_flags)
1139 {
1140         int rc;
1141         ENTRY;
1142
1143         OBD_CHECK_DT_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
1144         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
1145         LASSERT(cmd & OBD_BRW_RWMASK);
1146
1147         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1148                                                count, brw_flags, async_flags);
1149         RETURN(rc);
1150 }
1151
1152 static inline int obd_set_async_flags(struct obd_export *exp,
1153                                       struct lov_stripe_md *lsm,
1154                                       struct lov_oinfo *loi, void *cookie,
1155                                       obd_flag async_flags)
1156 {
1157         int rc;
1158         ENTRY;
1159
1160         OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1161         OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
1162
1163         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1164                                                 async_flags);
1165         RETURN(rc);
1166 }
1167
1168 static inline int obd_queue_group_io(struct obd_export *exp,
1169                                      struct lov_stripe_md *lsm,
1170                                      struct lov_oinfo *loi,
1171                                      struct obd_io_group *oig,
1172                                      void *cookie, int cmd, obd_off off,
1173                                      int count, obd_flag brw_flags,
1174                                      obd_flag async_flags)
1175 {
1176         int rc;
1177         ENTRY;
1178
1179         OBD_CHECK_DT_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1180         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
1181         LASSERT(cmd & OBD_BRW_RWMASK);
1182
1183         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1184                                                cmd, off, count, brw_flags,
1185                                                async_flags);
1186         RETURN(rc);
1187 }
1188
1189 static inline int obd_trigger_group_io(struct obd_export *exp,
1190                                        struct lov_stripe_md *lsm,
1191                                        struct lov_oinfo *loi,
1192                                        struct obd_io_group *oig)
1193 {
1194         int rc;
1195         ENTRY;
1196
1197         OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1198         OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
1199
1200         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1201         RETURN(rc);
1202 }
1203
1204 static inline int obd_teardown_async_page(struct obd_export *exp,
1205                                           struct lov_stripe_md *lsm,
1206                                           struct lov_oinfo *loi, void *cookie)
1207 {
1208         int rc;
1209         ENTRY;
1210
1211         OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1212         OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
1213
1214         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1215         RETURN(rc);
1216 }
1217
1218 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1219                              int objcount, struct obd_ioobj *obj,
1220                              int niocount, struct niobuf_remote *remote,
1221                              struct niobuf_local *local,
1222                              struct obd_trans_info *oti,
1223                              struct lustre_capa *capa)
1224 {
1225         int rc;
1226         ENTRY;
1227
1228         OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1229         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1230
1231         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1232                                        remote, local, oti, capa);
1233         RETURN(rc);
1234 }
1235
1236 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1237                                int objcount, struct obd_ioobj *obj,
1238                                int niocount, struct niobuf_local *local,
1239                                struct obd_trans_info *oti, int rc)
1240 {
1241         ENTRY;
1242
1243         OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1244         OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1245
1246         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1247                                          local, oti, rc);
1248         RETURN(rc);
1249 }
1250
1251 static inline int obd_merge_lvb(struct obd_export *exp,
1252                                 struct lov_stripe_md *lsm,
1253                                 struct ost_lvb *lvb, int kms_only)
1254 {
1255         int rc;
1256         ENTRY;
1257
1258         OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1259         OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1260
1261         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1262         RETURN(rc);
1263 }
1264
1265 static inline int obd_adjust_kms(struct obd_export *exp,
1266                                  struct lov_stripe_md *lsm, obd_off size,
1267                                  int shrink)
1268 {
1269         int rc;
1270         ENTRY;
1271
1272         OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1273         OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1274
1275         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1276         RETURN(rc);
1277 }
1278
1279 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1280                                 int len, void *karg, void *uarg)
1281 {
1282         int rc;
1283         ENTRY;
1284
1285         EXP_CHECK_DT_OP(exp, iocontrol);
1286         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1287
1288         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1289         RETURN(rc);
1290 }
1291
1292 static inline int obd_enqueue_rqset(struct obd_export *exp,
1293                                     struct obd_info *oinfo,
1294                                     struct obd_enqueue_info *einfo)
1295 {
1296         int rc;
1297         ENTRY;
1298
1299         EXP_CHECK_DT_OP(exp, enqueue);
1300         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1301
1302         einfo->ei_rqset =  ptlrpc_prep_set();
1303         if (einfo->ei_rqset == NULL)
1304                 RETURN(-ENOMEM);
1305
1306         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1307         if (rc == 0)
1308                 rc = ptlrpc_set_wait(einfo->ei_rqset);
1309         ptlrpc_set_destroy(einfo->ei_rqset);
1310         einfo->ei_rqset = NULL;
1311
1312         RETURN(rc);
1313 }
1314
1315 static inline int obd_enqueue(struct obd_export *exp,
1316                               struct obd_info *oinfo,
1317                               struct obd_enqueue_info *einfo)
1318 {
1319         int rc;
1320         ENTRY;
1321
1322         EXP_CHECK_DT_OP(exp, enqueue);
1323         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1324
1325         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1326         RETURN(rc);
1327 }
1328
1329 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1330                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1331                             int *flags, void *data, struct lustre_handle *lockh)
1332 {
1333         int rc;
1334         ENTRY;
1335
1336         EXP_CHECK_DT_OP(exp, match);
1337         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1338
1339         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1340                                       lockh);
1341         RETURN(rc);
1342 }
1343
1344 static inline int obd_change_cbdata(struct obd_export *exp,
1345                                     struct lov_stripe_md *lsm,
1346                                     ldlm_iterator_t it, void *data)
1347 {
1348         int rc;
1349         ENTRY;
1350
1351         EXP_CHECK_DT_OP(exp, change_cbdata);
1352         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1353
1354         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1355         RETURN(rc);
1356 }
1357
1358 static inline int obd_cancel(struct obd_export *exp,
1359                              struct lov_stripe_md *ea, __u32 mode,
1360                              struct lustre_handle *lockh)
1361 {
1362         int rc;
1363         ENTRY;
1364
1365         EXP_CHECK_DT_OP(exp, cancel);
1366         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1367
1368         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1369         RETURN(rc);
1370 }
1371
1372 static inline int obd_cancel_unused(struct obd_export *exp,
1373                                     struct lov_stripe_md *ea,
1374                                     int flags, void *opaque)
1375 {
1376         int rc;
1377         ENTRY;
1378
1379         EXP_CHECK_DT_OP(exp, cancel_unused);
1380         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1381
1382         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1383         RETURN(rc);
1384 }
1385
1386 static inline int obd_join_lru(struct obd_export *exp,
1387                                struct lov_stripe_md *ea, int join)
1388 {
1389         int rc;
1390         ENTRY;
1391
1392         EXP_CHECK_DT_OP(exp, join_lru);
1393         OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1394
1395         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1396         RETURN(rc);
1397 }
1398
1399 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1400                           struct obd_capa *oc, struct obd_client_handle *handle,
1401                           int flag)
1402 {
1403         int rc;
1404
1405         EXP_CHECK_DT_OP(exp, pin);
1406         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1407
1408         rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1409         return(rc);
1410 }
1411
1412 static inline int obd_unpin(struct obd_export *exp,
1413                             struct obd_client_handle *handle, int flag)
1414 {
1415         int rc;
1416
1417         EXP_CHECK_DT_OP(exp, unpin);
1418         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1419
1420         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1421         return(rc);
1422 }
1423
1424
1425 static inline void obd_import_event(struct obd_device *obd,
1426                                     struct obd_import *imp,
1427                                     enum obd_import_event event)
1428 {
1429         if (!obd) {
1430                 CERROR("NULL device\n");
1431                 EXIT;
1432                 return;
1433         }
1434         if (obd->obd_set_up && OBP(obd, import_event)) {
1435                 OBD_COUNTER_INCREMENT(obd, import_event);
1436                 OBP(obd, import_event)(obd, imp, event);
1437         }
1438 }
1439
1440 static inline int obd_llog_connect(struct obd_export *exp,
1441                                    struct llogd_conn_body *body)
1442 {
1443         ENTRY;
1444         
1445         OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1446         OBD_COUNTER_INCREMENT(exp->exp_obd, llog_connect);
1447
1448         return OBP(exp->exp_obd, llog_connect)(exp, body);
1449 }
1450
1451
1452 static inline int obd_notify(struct obd_device *obd,
1453                              struct obd_device *watched,
1454                              enum obd_notify_event ev,
1455                              void *data)
1456 {
1457         OBD_CHECK_DEV(obd);
1458
1459         /* the check for async_recov is a complete hack - I'm hereby
1460            overloading the meaning to also mean "this was called from
1461            mds_postsetup".  I know that my mds is able to handle notifies
1462            by this point, and it needs to get them to execute mds_postrecov. */
1463         if (!obd->obd_set_up && !obd->obd_async_recov) {
1464                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1465                 return -EINVAL;
1466         }
1467
1468         if (!OBP(obd, notify)) {
1469                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1470                 return -ENOSYS;
1471         }
1472
1473         OBD_COUNTER_INCREMENT(obd, notify);
1474         return OBP(obd, notify)(obd, watched, ev, data);
1475 }
1476
1477 static inline int obd_notify_observer(struct obd_device *observer,
1478                                       struct obd_device *observed,
1479                                       enum obd_notify_event ev,
1480                                       void *data)
1481 {
1482         int rc1;
1483         int rc2;
1484
1485         struct obd_notify_upcall *onu;
1486
1487         if (observer->obd_observer)
1488                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1489         else
1490                 rc1 = 0;
1491         /*
1492          * Also, call non-obd listener, if any
1493          */
1494         onu = &observer->obd_upcall;
1495         if (onu->onu_upcall != NULL)
1496                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1497         else
1498                 rc2 = 0;
1499
1500         return rc1 ? rc1 : rc2;
1501 }
1502
1503 static inline int obd_quotacheck(struct obd_export *exp,
1504                                  struct obd_quotactl *oqctl)
1505 {
1506         int rc;
1507         ENTRY;
1508
1509         EXP_CHECK_DT_OP(exp, quotacheck);
1510         OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1511
1512         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1513         RETURN(rc);
1514 }
1515
1516 static inline int obd_quotactl(struct obd_export *exp,
1517                                struct obd_quotactl *oqctl)
1518 {
1519         int rc;
1520         ENTRY;
1521
1522         EXP_CHECK_DT_OP(exp, quotactl);
1523         OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1524
1525         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1526         RETURN(rc);
1527 }
1528
1529 static inline int obd_health_check(struct obd_device *obd)
1530 {
1531         /* returns: 0 on healthy
1532          *         >0 on unhealthy + reason code/flag
1533          *            however the only suppored reason == 1 right now
1534          *            We'll need to define some better reasons
1535          *            or flags in the future.
1536          *         <0 on error
1537          */
1538         int rc;
1539         ENTRY;
1540
1541         /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1542         if (obd == NULL || !OBT(obd)) {
1543                 CERROR("cleaned up obd\n");
1544                 RETURN(-EOPNOTSUPP);
1545         }
1546         if (!obd->obd_set_up || obd->obd_stopping)
1547                 RETURN(0);
1548         if (!OBP(obd, health_check))
1549                 RETURN(0);
1550
1551         rc = OBP(obd, health_check)(obd);
1552         RETURN(rc);
1553 }
1554
1555 static inline int obd_register_observer(struct obd_device *obd,
1556                                         struct obd_device *observer)
1557 {
1558         ENTRY;
1559         OBD_CHECK_DEV(obd);
1560         if (obd->obd_observer && observer)
1561                 RETURN(-EALREADY);
1562         obd->obd_observer = observer;
1563         RETURN(0);
1564 }
1565
1566 /* metadata helpers */
1567 static inline int md_getstatus(struct obd_export *exp,
1568                                struct lu_fid *fid, struct obd_capa **pc)
1569 {
1570         int rc;
1571         ENTRY;
1572
1573         EXP_CHECK_MD_OP(exp, getstatus);
1574         MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1575         rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1576         RETURN(rc);
1577 }
1578
1579 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1580                              struct obd_capa *oc, obd_valid valid, int ea_size,
1581                              struct ptlrpc_request **request)
1582 {
1583         int rc;
1584         ENTRY;
1585         EXP_CHECK_MD_OP(exp, getattr);
1586         MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1587         rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1588                                         ea_size, request);
1589         RETURN(rc);
1590 }
1591
1592 static inline int md_change_cbdata(struct obd_export *exp,
1593                                    const struct lu_fid *fid,
1594                                    ldlm_iterator_t it, void *data)
1595 {
1596         int rc;
1597         ENTRY;
1598         EXP_CHECK_MD_OP(exp, change_cbdata);
1599         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1600         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1601         RETURN(rc);
1602 }
1603
1604 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1605                            struct obd_client_handle *och,
1606                            struct ptlrpc_request **request)
1607 {
1608         int rc;
1609         ENTRY;
1610         EXP_CHECK_MD_OP(exp, close);
1611         MD_COUNTER_INCREMENT(exp->exp_obd, close);
1612         rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1613         RETURN(rc);
1614 }
1615
1616 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1617                             const void *data, int datalen, int mode, __u32 uid,
1618                             __u32 gid, __u32 cap_effective, __u64 rdev,
1619                             struct ptlrpc_request **request)
1620 {
1621         int rc;
1622         ENTRY;
1623         EXP_CHECK_MD_OP(exp, create);
1624         MD_COUNTER_INCREMENT(exp->exp_obd, create);
1625         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1626                                        uid, gid, cap_effective, rdev, request);
1627         RETURN(rc);
1628 }
1629
1630 static inline int md_done_writing(struct obd_export *exp,
1631                                   struct md_op_data *op_data,
1632                                   struct obd_client_handle *och)
1633 {
1634         int rc;
1635         ENTRY;
1636         EXP_CHECK_MD_OP(exp, done_writing);
1637         MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1638         rc = MDP(exp->exp_obd, done_writing)(exp, op_data, och);
1639         RETURN(rc);
1640 }
1641
1642 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1643                              struct lookup_intent *it, int lock_mode,
1644                              struct md_op_data *op_data,
1645                              struct lustre_handle *lockh,
1646                              void *lmm, int lmmsize,
1647                              ldlm_completion_callback cb_completion,
1648                              ldlm_blocking_callback cb_blocking,
1649                              void *cb_data, int extra_lock_flags)
1650 {
1651         int rc;
1652         ENTRY;
1653         EXP_CHECK_MD_OP(exp, enqueue);
1654         MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1655         rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1656                                         op_data, lockh, lmm, lmmsize,
1657                                         cb_completion, cb_blocking,
1658                                         cb_data, extra_lock_flags);
1659         RETURN(rc);
1660 }
1661
1662 static inline int md_getattr_name(struct obd_export *exp,
1663                                   const struct lu_fid *fid, struct obd_capa *oc,
1664                                   const char *name, int namelen,
1665                                   obd_valid valid, int ea_size,
1666                                   struct ptlrpc_request **request)
1667 {
1668         int rc;
1669         ENTRY;
1670         EXP_CHECK_MD_OP(exp, getattr_name);
1671         MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1672         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1673                                              valid, ea_size, request);
1674         RETURN(rc);
1675 }
1676
1677 static inline int md_intent_lock(struct obd_export *exp,
1678                                  struct md_op_data *op_data, void *lmm,
1679                                  int lmmsize, struct lookup_intent *it,
1680                                  int flags, struct ptlrpc_request **reqp,
1681                                  ldlm_blocking_callback cb_blocking,
1682                                  int extra_lock_flags)
1683 {
1684         int rc;
1685         ENTRY;
1686         EXP_CHECK_MD_OP(exp, intent_lock);
1687         MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1688         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1689                                             it, flags, reqp, cb_blocking,
1690                                             extra_lock_flags);
1691         RETURN(rc);
1692 }
1693
1694 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1695                           struct ptlrpc_request **request)
1696 {
1697         int rc;
1698         ENTRY;
1699         EXP_CHECK_MD_OP(exp, link);
1700         MD_COUNTER_INCREMENT(exp->exp_obd, link);
1701         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1702         RETURN(rc);
1703 }
1704
1705 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1706                             const char *old, int oldlen, const char *new,
1707                             int newlen, struct ptlrpc_request **request)
1708 {
1709         int rc;
1710         ENTRY;
1711         EXP_CHECK_MD_OP(exp, rename);
1712         MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1713         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1714                                        newlen, request);
1715         RETURN(rc);
1716 }
1717
1718 static inline int md_is_subdir(struct obd_export *exp,
1719                                const struct lu_fid *pfid,
1720                                const struct lu_fid *cfid,
1721                                struct obd_capa *pc, struct obd_capa *cc,
1722                                struct ptlrpc_request **request)
1723 {
1724         int rc;
1725         ENTRY;
1726         EXP_CHECK_MD_OP(exp, is_subdir);
1727         MD_COUNTER_INCREMENT(exp->exp_obd, is_subdir);
1728         rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, pc, cc, request);
1729         RETURN(rc);
1730 }
1731
1732 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1733                              void *ea, int ealen, void *ea2, int ea2len,
1734                              struct ptlrpc_request **request)
1735 {
1736         int rc;
1737         ENTRY;
1738         EXP_CHECK_MD_OP(exp, setattr);
1739         MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1740         rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1741                                         ea2, ea2len, request);
1742         RETURN(rc);
1743 }
1744
1745 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1746                           struct obd_capa *oc, struct ptlrpc_request **request)
1747 {
1748         int rc;
1749         ENTRY;
1750         EXP_CHECK_MD_OP(exp, sync);
1751         MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1752         rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1753         RETURN(rc);
1754 }
1755
1756 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1757                               struct obd_capa *oc, __u64 offset,
1758                               struct page *page,
1759                               struct ptlrpc_request **request)
1760 {
1761         int rc;
1762         ENTRY;
1763         EXP_CHECK_MD_OP(exp, readpage);
1764         MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1765         rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1766         RETURN(rc);
1767 }
1768
1769 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1770                             struct ptlrpc_request **request)
1771 {
1772         int rc;
1773         ENTRY;
1774         EXP_CHECK_MD_OP(exp, unlink);
1775         MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1776         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1777         RETURN(rc);
1778 }
1779
1780 static inline int md_get_lustre_md(struct obd_export *exp,
1781                                    struct ptlrpc_request *req,
1782                                    int offset, struct obd_export *dt_exp,
1783                                    struct obd_export *md_exp,
1784                                    struct lustre_md *md)
1785 {
1786         ENTRY;
1787         EXP_CHECK_MD_OP(exp, get_lustre_md);
1788         MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1789         RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1790                                                 dt_exp, md_exp, md));
1791 }
1792
1793 static inline int md_free_lustre_md(struct obd_export *exp,
1794                                     struct lustre_md *md)
1795 {
1796         ENTRY;
1797         EXP_CHECK_MD_OP(exp, free_lustre_md);
1798         MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1799         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1800 }
1801
1802 static inline int md_setxattr(struct obd_export *exp,
1803                               const struct lu_fid *fid, struct obd_capa *oc,
1804                               obd_valid valid, const char *name,
1805                               const char *input, int input_size,
1806                               int output_size, int flags,
1807                               struct ptlrpc_request **request)
1808 {
1809         ENTRY;
1810         EXP_CHECK_MD_OP(exp, setxattr);
1811         MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1812         RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1813                                            input_size, output_size, flags,
1814                                            request));
1815 }
1816
1817 static inline int md_getxattr(struct obd_export *exp,
1818                               const struct lu_fid *fid, struct obd_capa *oc,
1819                               obd_valid valid, const char *name,
1820                               const char *input, int input_size,
1821                               int output_size, int flags,
1822                               struct ptlrpc_request **request)
1823 {
1824         ENTRY;
1825         EXP_CHECK_MD_OP(exp, getxattr);
1826         MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1827         RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1828                                            input_size, output_size, flags,
1829                                            request));
1830 }
1831
1832 static inline int md_set_open_replay_data(struct obd_export *exp,
1833                                           struct obd_client_handle *och,
1834                                           struct ptlrpc_request *open_req)
1835 {
1836         ENTRY;
1837         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1838         MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1839         RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1840 }
1841
1842 static inline int md_clear_open_replay_data(struct obd_export *exp,
1843                                             struct obd_client_handle *och)
1844 {
1845         ENTRY;
1846         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1847         MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1848         RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1849 }
1850
1851 static inline int md_set_lock_data(struct obd_export *exp,
1852                                    __u64 *lockh, void *data)
1853 {
1854         ENTRY;
1855         EXP_CHECK_MD_OP(exp, set_lock_data);
1856         MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1857         RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1858 }
1859
1860 static inline int md_cancel_unused(struct obd_export *exp,
1861                                    const struct lu_fid *fid,
1862                                    int flags, void *opaque)
1863 {
1864         int rc;
1865         ENTRY;
1866
1867         EXP_CHECK_MD_OP(exp, cancel_unused);
1868         MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1869
1870         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1871         RETURN(rc);
1872 }
1873
1874 static inline int md_lock_match(struct obd_export *exp, int flags,
1875                                 const struct lu_fid *fid, ldlm_type_t type,
1876                                 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1877                                 struct lustre_handle *lockh)
1878 {
1879         ENTRY;
1880         EXP_CHECK_MD_OP(exp, lock_match);
1881         MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1882         RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1883                                              policy, mode, lockh));
1884 }
1885
1886 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1887                                   int def_asize, int cookiesize)
1888 {
1889         ENTRY;
1890         EXP_CHECK_MD_OP(exp, init_ea_size);
1891         MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1892         RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1893                                                cookiesize));
1894 }
1895
1896 static inline int md_get_remote_perm(struct obd_export *exp,
1897                                      const struct lu_fid *fid,
1898                                      struct obd_capa *oc,
1899                                      struct ptlrpc_request **request)
1900 {
1901         ENTRY;
1902         EXP_CHECK_MD_OP(exp, get_remote_perm);
1903         MD_COUNTER_INCREMENT(exp->exp_obd, get_remote_perm);
1904         RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, request));
1905 }
1906
1907 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1908                                 renew_capa_cb_t cb)
1909 {
1910         int rc;
1911         ENTRY;
1912         EXP_CHECK_MD_OP(exp, renew_capa);
1913         MD_COUNTER_INCREMENT(exp->exp_obd, renew_capa);
1914         rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1915         RETURN(rc);
1916 }
1917
1918 /* OBD Metadata Support */
1919 extern int obd_init_caches(void);
1920 extern void obd_cleanup_caches(void);
1921
1922 /* support routines */
1923 extern cfs_mem_cache_t *obdo_cachep;
1924 static inline struct obdo *obdo_alloc(void)
1925 {
1926         struct obdo *oa;
1927         OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1928         return oa;
1929 }
1930
1931 static inline void obdo_free(struct obdo *oa)
1932 {
1933         OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1934 }
1935
1936 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
1937 {
1938         /* something here */
1939 }
1940
1941 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
1942 {
1943         /* something here */
1944 }
1945
1946 /* I'm as embarrassed about this as you are.
1947  *
1948  * <shaver> // XXX do not look into _superhack with remaining eye
1949  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1950 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1951
1952 /* sysctl.c */
1953 extern void obd_sysctl_init (void);
1954 extern void obd_sysctl_clean (void);
1955
1956 /* uuid.c  */
1957 typedef __u8 class_uuid_t[16];
1958 void class_generate_random_uuid(class_uuid_t uuid);
1959 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1960
1961 /* lustre_peer.c    */
1962 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1963 int class_add_uuid(const char *uuid, __u64 nid);
1964 int class_del_uuid (const char *uuid);
1965 void class_init_uuidlist(void);
1966 void class_exit_uuidlist(void);
1967
1968 /* mea.c */
1969 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1970 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1971
1972 #endif /* __LINUX_OBD_CLASS_H */