Whamcloud - gitweb
- merge with 1_5,some fixes.
[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 #define MAX_OBD_DEVICES 2048
46 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
47 extern spinlock_t obd_dev_lock;
48
49 /* OBD Operations Declarations */
50 extern struct obd_device *class_conn2obd(struct lustre_handle *);
51 extern struct obd_device *class_exp2obd(struct obd_export *);
52
53 struct lu_device_type;
54
55 /* genops.c */
56 struct obd_export *class_conn2export(struct lustre_handle *);
57 int class_register_type(struct obd_ops *, struct md_ops *,
58                         struct lprocfs_vars *, const char *nm,
59                         struct lu_device_type *ldt);
60 int class_unregister_type(const char *nm);
61
62 struct obd_device *class_newdev(const char *type_name, const char *name);
63 void class_release_dev(struct obd_device *obd);
64
65 int class_name2dev(const char *name);
66 struct obd_device *class_name2obd(const char *name);
67 int class_uuid2dev(struct obd_uuid *uuid);
68 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
69 void class_obd_list(void);
70 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
71                                           const char * typ_name,
72                                           struct obd_uuid *grp_uuid);
73 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
74                                              struct obd_uuid *grp_uuid);
75 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
76                                            int *next);
77 struct obd_device * class_num2obd(int num);
78
79 int oig_init(struct obd_io_group **oig);
80 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
81 void oig_complete_one(struct obd_io_group *oig,
82                       struct oig_callback_context *occ, int rc);
83 void oig_release(struct obd_io_group *oig);
84 int oig_wait(struct obd_io_group *oig);
85
86 char *obd_export_nid2str(struct obd_export *exp);
87
88 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
89 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
90
91 /* obd_config.c */
92 int class_process_config(struct lustre_cfg *lcfg);
93 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, 
94                              struct lustre_cfg *lcfg, void *data);
95 int class_attach(struct lustre_cfg *lcfg);
96 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
97 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
98 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
99 struct obd_device *class_incref(struct obd_device *obd);
100 void class_decref(struct obd_device *obd);
101
102 #define CFG_F_START     0x01   /* Set when we start updating from a log */
103 #define CFG_F_MARKER    0x02   /* We are within a maker */
104 #define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
105 #define CFG_F_COMPAT146 0x08   /* Using old-style log */
106 #define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
107
108 /* Passed as data param to class_config_parse_llog */
109 struct config_llog_instance {
110         char *              cfg_instance;
111         struct super_block *cfg_sb;
112         struct obd_uuid     cfg_uuid;
113         int                 cfg_last_idx; /* for partial llog processing */
114         int                 cfg_flags;
115 };
116 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
117                             struct config_llog_instance *cfg);
118 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
119                            struct config_llog_instance *cfg);
120
121 /* list of active configuration logs  */
122 struct config_llog_data {
123         char               *cld_logname;
124         struct ldlm_res_id  cld_resid;
125         struct config_llog_instance cld_cfg;
126         struct list_head    cld_list_chain;
127         atomic_t            cld_refcount;
128         struct obd_export  *cld_mgcexp;
129         unsigned int        cld_stopping:1;
130 };
131
132 struct lustre_profile {
133         struct list_head lp_list;
134         char            *lp_profile;
135         char            *lp_dt;
136         char            *lp_md;
137 };
138
139 struct lustre_profile *class_get_profile(const char * prof);
140 void class_del_profile(const char *prof);
141 void class_del_profiles(void);
142
143 /* genops.c */
144 #define class_export_get(exp)                                                  \
145 ({                                                                             \
146         struct obd_export *exp_ = exp;                                         \
147         atomic_inc(&exp_->exp_refcount);                                       \
148         CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_,          \
149                atomic_read(&exp_->exp_refcount));                              \
150         exp_;                                                                  \
151 })
152
153 #define class_export_put(exp)                                                  \
154 do {                                                                           \
155         LASSERT((exp) != NULL);                                                \
156         CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp),         \
157                atomic_read(&(exp)->exp_refcount) - 1);                         \
158         LASSERT(atomic_read(&(exp)->exp_refcount) > 0);                        \
159         LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a);                 \
160         __class_export_put(exp);                                               \
161 } while (0)
162 void __class_export_put(struct obd_export *);
163 struct obd_export *class_new_export(struct obd_device *obddev,
164                                     struct obd_uuid *cluuid);
165 void class_unlink_export(struct obd_export *exp);
166
167 struct obd_import *class_import_get(struct obd_import *);
168 void class_import_put(struct obd_import *);
169 struct obd_import *class_new_import(struct obd_device *obd);
170 void class_destroy_import(struct obd_import *exp);
171
172 struct obd_type *class_search_type(const char *name);
173 struct obd_type *class_get_type(const char *name);
174 void class_put_type(struct obd_type *type);
175 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
176                   struct obd_uuid *cluuid);
177 int class_disconnect(struct obd_export *exp);
178 void class_fail_export(struct obd_export *exp);
179 void class_disconnect_exports(struct obd_device *obddev);
180 void class_disconnect_stale_exports(struct obd_device *obddev);
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
187
188 #define OBT(dev)        (dev)->obd_type
189 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
190 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
191 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
192
193 /* Ensure obd_setup: used for cleanup which must be called
194    while obd is stopping */
195 #define OBD_CHECK_DEV(obd)                                      \
196 do {                                                            \
197         if (!(obd)) {                                           \
198                 CERROR("NULL device\n");                        \
199                 RETURN(-ENODEV);                                \
200         }                                                       \
201 } while (0)
202
203 /* ensure obd_setup and !obd_stopping */
204 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
205 do {                                                            \
206         OBD_CHECK_DEV(obd);                                     \
207         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
208                 CERROR("Device %d not setup\n",                 \
209                        (obd)->obd_minor);                       \
210                 RETURN(-ENODEV);                                \
211         }                                                       \
212 } while (0)
213
214
215 #ifdef LPROCFS
216 #define OBD_COUNTER_OFFSET(op)                                  \
217         ((offsetof(struct obd_ops, o_ ## op) -                  \
218           offsetof(struct obd_ops, o_iocontrol))                \
219          / sizeof(((struct obd_ops *)(0))->o_iocontrol))
220
221 #define OBD_COUNTER_INCREMENT(obd, op)                          \
222         if ((obd)->obd_stats != NULL) {                         \
223                 unsigned int coffset;                           \
224                 coffset = (unsigned int)(obd)->obd_cntr_base +  \
225                         OBD_COUNTER_OFFSET(op);                 \
226                 LASSERT(coffset < obd->obd_stats->ls_num);      \
227                 lprocfs_counter_incr(obd->obd_stats, coffset);  \
228         }
229
230 #define MD_COUNTER_OFFSET(op)                                  \
231         ((offsetof(struct md_ops, m_ ## op) -                  \
232           offsetof(struct md_ops, m_getstatus))                \
233          / sizeof(((struct md_ops *)(0))->m_getstatus))
234
235 #define MD_COUNTER_INCREMENT(obd, op)                           \
236         if ((obd)->md_stats != NULL) {                          \
237                 unsigned int coffset;                           \
238                 coffset = (unsigned int)(obd)->md_cntr_base +   \
239                         MD_COUNTER_OFFSET(op);                  \
240                 LASSERT(coffset < (obd)->md_stats->ls_num);     \
241                 lprocfs_counter_incr((obd)->md_stats, coffset); \
242         }
243
244 #else
245 #define OBD_COUNTER_OFFSET(op)
246 #define OBD_COUNTER_INCREMENT(obd, op)
247 #define MD_COUNTER_INCREMENT(obd, op)
248 #endif
249
250 #define OBD_CHECK_MD_OP(obd, op, err)                           \
251 do {                                                            \
252         if (!OBT(obd) || !MDP((obd), op)) {                     \
253                 if (err)                                        \
254                         CERROR("md_" #op ": dev %s/%d no operation\n", \
255                                obd->obd_name, obd->obd_minor);  \
256                 RETURN(err);                                    \
257         }                                                       \
258 } while (0)
259
260 #define EXP_CHECK_MD_OP(exp, op)                                \
261 do {                                                            \
262         if ((exp) == NULL) {                                    \
263                 CERROR("obd_" #op ": NULL export\n");           \
264                 RETURN(-ENODEV);                                \
265         }                                                       \
266         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
267                 CERROR("obd_" #op ": cleaned up obd\n");        \
268                 RETURN(-EOPNOTSUPP);                            \
269         }                                                       \
270         if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
271                 CERROR("obd_" #op ": dev %s/%d no operation\n", \
272                        (exp)->exp_obd->obd_name,                \
273                        (exp)->exp_obd->obd_minor);              \
274                 RETURN(-EOPNOTSUPP);                            \
275         }                                                       \
276 } while (0)
277
278
279 #define OBD_CHECK_DT_OP(obd, op, err)                           \
280 do {                                                            \
281         if (!OBT(obd) || !OBP((obd), op)) {                     \
282                 if (err)                                        \
283                         CERROR("obd_" #op ": dev %d no operation\n",    \
284                                obd->obd_minor);                 \
285                 RETURN(err);                                    \
286         }                                                       \
287 } while (0)
288
289 #define EXP_CHECK_DT_OP(exp, op)                                \
290 do {                                                            \
291         if ((exp) == NULL) {                                    \
292                 CERROR("obd_" #op ": NULL export\n");           \
293                 RETURN(-ENODEV);                                \
294         }                                                       \
295         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
296                 CERROR("obd_" #op ": cleaned up obd\n");        \
297                 RETURN(-EOPNOTSUPP);                            \
298         }                                                       \
299         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
300                 CERROR("obd_" #op ": dev %d no operation\n",    \
301                        (exp)->exp_obd->obd_minor);              \
302                 RETURN(-EOPNOTSUPP);                            \
303         }                                                       \
304 } while (0)
305
306 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
307 do {                                                            \
308         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
309                 if (err)                                        \
310                         CERROR("lop_" #op ": dev %d no operation\n",    \
311                                ctxt->loc_obd->obd_minor);                         \
312                 RETURN(err);                                    \
313         }                                                       \
314 } while (0)
315
316 static inline int class_devno_max(void)
317 {
318         return MAX_OBD_DEVICES;
319 }
320
321 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
322                                void *key, __u32 *vallen, void *val)
323 {
324         int rc;
325         ENTRY;
326
327         EXP_CHECK_DT_OP(exp, get_info);
328         OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
329
330         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
331         RETURN(rc);
332 }
333
334 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
335                                      void *key, obd_count vallen, void *val,
336                                      struct ptlrpc_request_set *set)
337 {
338         int rc;
339         ENTRY;
340
341         EXP_CHECK_DT_OP(exp, set_info_async);
342         OBD_COUNTER_INCREMENT(exp->exp_obd, set_info_async);
343
344         rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
345                                                set);
346         RETURN(rc);
347 }
348
349 #ifdef __KERNEL__
350 #define DECLARE_LU_VARS(ldt, d)                 \
351         struct lu_device_type *ldt;             \
352         struct lu_device *d
353 #else
354 #define DECLARE_LU_VARS(ldt, d)                                 \
355         extern void __placeholder_to_put_a_semicolon(void)
356 #endif
357 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
358 {
359         int rc;
360         DECLARE_LU_VARS(ldt, d);
361         ENTRY;
362
363 #ifdef __KERNEL__
364         ldt = obd->obd_type->typ_lu;
365         if (ldt != NULL) {
366                 struct lu_context ctx;
367
368                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
369                 if (rc == 0) {
370                         lu_context_enter(&ctx);
371                         d = ldt->ldt_ops->ldto_device_alloc(&ctx, ldt, cfg);
372                         lu_context_exit(&ctx);
373                         lu_context_fini(&ctx);
374                         if (!IS_ERR(d)) {
375                                 obd->obd_lu_dev = d;
376                                 d->ld_obd = obd;
377                                 rc = 0;
378                         } else
379                                 rc = PTR_ERR(d);
380                 }
381         } else
382 #endif
383         {
384                 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
385                 OBD_COUNTER_INCREMENT(obd, setup);
386                 rc = OBP(obd, setup)(obd, cfg);
387         }
388         RETURN(rc);
389 }
390
391 static inline int obd_precleanup(struct obd_device *obd,
392                                  enum obd_cleanup_stage cleanup_stage)
393 {
394         int rc;
395         DECLARE_LU_VARS(ldt, d);
396         ENTRY;
397
398         OBD_CHECK_DEV(obd);
399 #ifdef __KERNEL__
400         ldt = obd->obd_type->typ_lu;
401         d = obd->obd_lu_dev;
402         if (ldt != NULL && d != NULL) {
403                 struct lu_context ctx;
404
405                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
406                 if (rc == 0) {
407                         lu_context_enter(&ctx);
408                         ldt->ldt_ops->ldto_device_fini(&ctx, d);
409                         lu_context_exit(&ctx);
410                         lu_context_fini(&ctx);
411                         obd->obd_lu_dev = NULL;
412                         rc = 0;
413                 }
414         } else
415 #endif
416         {
417                 OBD_CHECK_DT_OP(obd, precleanup, 0);
418                 rc = OBP(obd, precleanup)(obd, cleanup_stage);
419         }
420         
421         OBD_COUNTER_INCREMENT(obd, precleanup);
422         RETURN(rc);
423 }
424
425 static inline int obd_cleanup(struct obd_device *obd)
426 {
427         int rc;
428         DECLARE_LU_VARS(ldt, d);
429         ENTRY;
430
431         OBD_CHECK_DEV(obd);
432
433 #ifdef __KERNEL__
434         ldt = obd->obd_type->typ_lu;
435         d = obd->obd_lu_dev;
436         if (ldt != NULL && d != NULL) {
437                 struct lu_context ctx;
438
439                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
440                 if (rc == 0) {
441                         lu_context_enter(&ctx);
442                         ldt->ldt_ops->ldto_device_free(&ctx, d);
443                         lu_context_exit(&ctx);
444                         lu_context_fini(&ctx);
445                         obd->obd_lu_dev = NULL;
446                         rc = 0;
447                 }
448         } else
449 #endif
450         {
451                 OBD_CHECK_DT_OP(obd, cleanup, 0);
452                 rc = OBP(obd, cleanup)(obd);
453         }
454         OBD_COUNTER_INCREMENT(obd, cleanup);
455         RETURN(rc);
456 }
457
458 static inline int
459 obd_process_config(struct obd_device *obd, int datalen, void *data)
460 {
461         int rc;
462         DECLARE_LU_VARS(ldt, d);
463         ENTRY;
464
465         OBD_CHECK_DEV(obd);
466
467 #ifdef __KERNEL__
468         ldt = obd->obd_type->typ_lu;
469         d = obd->obd_lu_dev;
470         if (ldt != NULL && d != NULL) {
471                 struct lu_context ctx;
472
473                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
474                 if (rc == 0) {
475                         lu_context_enter(&ctx);
476                         rc = d->ld_ops->ldo_process_config(&ctx, d, data);
477                         lu_context_exit(&ctx);
478                         lu_context_fini(&ctx);
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_context *ctx,
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)(ctx, 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                                  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)
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);
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 {
1084         struct ptlrpc_request_set *set = NULL;
1085         struct obd_info oinfo = { { { 0 } } };
1086         int rc = 0;
1087         ENTRY;
1088
1089         set =  ptlrpc_prep_set();
1090         if (set == NULL)
1091                 RETURN(-ENOMEM);
1092
1093         oinfo.oi_oa = oa;
1094         oinfo.oi_md = lsm;
1095         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1096         if (rc == 0) {
1097                 rc = ptlrpc_set_wait(set);
1098                 if (rc)
1099                         CERROR("error from callback: rc = %d\n", rc);
1100         } else {
1101                 CDEBUG(D_INODE, "error from obd_brw_async: rc = %d\n", rc);
1102         }
1103         ptlrpc_set_destroy(set);
1104         RETURN(rc);
1105 }
1106
1107 static inline  int obd_prep_async_page(struct obd_export *exp,
1108                                        struct lov_stripe_md *lsm,
1109                                        struct lov_oinfo *loi,
1110                                        struct page *page, obd_off offset,
1111                                        struct obd_async_page_ops *ops,
1112                                        void *data, void **res)
1113 {
1114         int ret;
1115         ENTRY;
1116
1117         OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
1118         OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
1119
1120         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1121                                                  ops, data, res);
1122         RETURN(ret);
1123 }
1124
1125 static inline int obd_queue_async_io(struct obd_export *exp,
1126                                      struct lov_stripe_md *lsm,
1127                                      struct lov_oinfo *loi, void *cookie,
1128                                      int cmd, obd_off off, int count,
1129                                      obd_flag brw_flags, obd_flag async_flags)
1130 {
1131         int rc;
1132         ENTRY;
1133
1134         OBD_CHECK_DT_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
1135         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
1136         LASSERT(cmd & OBD_BRW_RWMASK);
1137
1138         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1139                                                count, brw_flags, async_flags);
1140         RETURN(rc);
1141 }
1142
1143 static inline int obd_set_async_flags(struct obd_export *exp,
1144                                       struct lov_stripe_md *lsm,
1145                                       struct lov_oinfo *loi, void *cookie,
1146                                       obd_flag async_flags)
1147 {
1148         int rc;
1149         ENTRY;
1150
1151         OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1152         OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
1153
1154         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1155                                                 async_flags);
1156         RETURN(rc);
1157 }
1158
1159 static inline int obd_queue_group_io(struct obd_export *exp,
1160                                      struct lov_stripe_md *lsm,
1161                                      struct lov_oinfo *loi,
1162                                      struct obd_io_group *oig,
1163                                      void *cookie, int cmd, obd_off off,
1164                                      int count, obd_flag brw_flags,
1165                                      obd_flag async_flags)
1166 {
1167         int rc;
1168         ENTRY;
1169
1170         OBD_CHECK_DT_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1171         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
1172         LASSERT(cmd & OBD_BRW_RWMASK);
1173
1174         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1175                                                cmd, off, count, brw_flags,
1176                                                async_flags);
1177         RETURN(rc);
1178 }
1179
1180 static inline int obd_trigger_group_io(struct obd_export *exp,
1181                                        struct lov_stripe_md *lsm,
1182                                        struct lov_oinfo *loi,
1183                                        struct obd_io_group *oig)
1184 {
1185         int rc;
1186         ENTRY;
1187
1188         OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1189         OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
1190
1191         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1192         RETURN(rc);
1193 }
1194
1195 static inline int obd_teardown_async_page(struct obd_export *exp,
1196                                           struct lov_stripe_md *lsm,
1197                                           struct lov_oinfo *loi, void *cookie)
1198 {
1199         int rc;
1200         ENTRY;
1201
1202         OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1203         OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
1204
1205         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1206         RETURN(rc);
1207 }
1208
1209 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1210                              int objcount, struct obd_ioobj *obj,
1211                              int niocount, struct niobuf_remote *remote,
1212                              struct niobuf_local *local,
1213                              struct obd_trans_info *oti)
1214 {
1215         int rc;
1216         ENTRY;
1217
1218         OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1219         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1220
1221         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1222                                        remote, local, oti);
1223         RETURN(rc);
1224 }
1225
1226 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1227                                int objcount, struct obd_ioobj *obj,
1228                                int niocount, struct niobuf_local *local,
1229                                struct obd_trans_info *oti, int rc)
1230 {
1231         ENTRY;
1232
1233         OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1234         OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1235
1236         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1237                                          local, oti, rc);
1238         RETURN(rc);
1239 }
1240
1241 static inline int obd_merge_lvb(struct obd_export *exp,
1242                                 struct lov_stripe_md *lsm,
1243                                 struct ost_lvb *lvb, int kms_only)
1244 {
1245         int rc;
1246         ENTRY;
1247
1248         OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1249         OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1250
1251         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1252         RETURN(rc);
1253 }
1254
1255 static inline int obd_adjust_kms(struct obd_export *exp,
1256                                  struct lov_stripe_md *lsm, obd_off size,
1257                                  int shrink)
1258 {
1259         int rc;
1260         ENTRY;
1261
1262         OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1263         OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1264
1265         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1266         RETURN(rc);
1267 }
1268
1269 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1270                                 int len, void *karg, void *uarg)
1271 {
1272         int rc;
1273         ENTRY;
1274
1275         EXP_CHECK_DT_OP(exp, iocontrol);
1276         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1277
1278         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1279         RETURN(rc);
1280 }
1281
1282 static inline int obd_enqueue_rqset(struct obd_export *exp,
1283                                     struct obd_info *oinfo,
1284                                     struct obd_enqueue_info *einfo)
1285 {
1286         int rc;
1287         ENTRY;
1288
1289         EXP_CHECK_DT_OP(exp, enqueue);
1290         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1291
1292         einfo->ei_rqset =  ptlrpc_prep_set();
1293         if (einfo->ei_rqset == NULL)
1294                 RETURN(-ENOMEM);
1295
1296         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1297         if (rc == 0)
1298                 rc = ptlrpc_set_wait(einfo->ei_rqset);
1299         ptlrpc_set_destroy(einfo->ei_rqset);
1300         einfo->ei_rqset = NULL;
1301
1302         RETURN(rc);
1303 }
1304
1305 static inline int obd_enqueue(struct obd_export *exp,
1306                               struct obd_info *oinfo,
1307                               struct obd_enqueue_info *einfo)
1308 {
1309         int rc;
1310         ENTRY;
1311
1312         EXP_CHECK_DT_OP(exp, enqueue);
1313         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1314
1315         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1316         RETURN(rc);
1317 }
1318
1319 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1320                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1321                             int *flags, void *data, struct lustre_handle *lockh)
1322 {
1323         int rc;
1324         ENTRY;
1325
1326         EXP_CHECK_DT_OP(exp, match);
1327         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1328
1329         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1330                                       lockh);
1331         RETURN(rc);
1332 }
1333
1334 static inline int obd_change_cbdata(struct obd_export *exp,
1335                                     struct lov_stripe_md *lsm,
1336                                     ldlm_iterator_t it, void *data)
1337 {
1338         int rc;
1339         ENTRY;
1340
1341         EXP_CHECK_DT_OP(exp, change_cbdata);
1342         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1343
1344         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1345         RETURN(rc);
1346 }
1347
1348 static inline int obd_cancel(struct obd_export *exp,
1349                              struct lov_stripe_md *ea, __u32 mode,
1350                              struct lustre_handle *lockh)
1351 {
1352         int rc;
1353         ENTRY;
1354
1355         EXP_CHECK_DT_OP(exp, cancel);
1356         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1357
1358         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1359         RETURN(rc);
1360 }
1361
1362 static inline int obd_cancel_unused(struct obd_export *exp,
1363                                     struct lov_stripe_md *ea,
1364                                     int flags, void *opaque)
1365 {
1366         int rc;
1367         ENTRY;
1368
1369         EXP_CHECK_DT_OP(exp, cancel_unused);
1370         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1371
1372         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1373         RETURN(rc);
1374 }
1375
1376 static inline int obd_join_lru(struct obd_export *exp,
1377                                struct lov_stripe_md *ea, int join)
1378 {
1379         int rc;
1380         ENTRY;
1381
1382         EXP_CHECK_DT_OP(exp, join_lru);
1383         OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1384
1385         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1386         RETURN(rc);
1387 }
1388
1389 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1390                                  struct obdo *oa,
1391                                  int objcount, struct obd_ioobj *obj,
1392                                  int niocount, struct niobuf_remote *remote)
1393 {
1394         int rc;
1395
1396         EXP_CHECK_DT_OP(exp, preprw);
1397         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1398
1399         rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1400                                            niocount, remote);
1401         class_export_put(exp);
1402         return(rc);
1403 }
1404
1405 static inline int obd_pin(struct obd_export *exp, struct lu_fid *fid,
1406                           struct obd_client_handle *handle, int flag)
1407 {
1408         int rc;
1409
1410         EXP_CHECK_DT_OP(exp, pin);
1411         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1412
1413         rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1414         return(rc);
1415 }
1416
1417 static inline int obd_unpin(struct obd_export *exp,
1418                             struct obd_client_handle *handle, int flag)
1419 {
1420         int rc;
1421
1422         EXP_CHECK_DT_OP(exp, unpin);
1423         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1424
1425         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1426         return(rc);
1427 }
1428
1429
1430 static inline void obd_import_event(struct obd_device *obd,
1431                                     struct obd_import *imp,
1432                                     enum obd_import_event event)
1433 {
1434         if (!obd) {
1435                 CERROR("NULL device\n");
1436                 EXIT;
1437                 return;
1438         }
1439         if (obd->obd_set_up && OBP(obd, import_event)) {
1440                 OBD_COUNTER_INCREMENT(obd, import_event);
1441                 OBP(obd, import_event)(obd, imp, event);
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, struct lu_fid *fid)
1561 {
1562         int rc;
1563         ENTRY;
1564
1565         EXP_CHECK_MD_OP(exp, getstatus);
1566         MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1567         rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1568         RETURN(rc);
1569 }
1570
1571 static inline int md_getattr(struct obd_export *exp, struct lu_fid *fid,
1572                              obd_valid valid, int ea_size,
1573                              struct ptlrpc_request **request)
1574 {
1575         int rc;
1576         ENTRY;
1577         EXP_CHECK_MD_OP(exp, getattr);
1578         MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1579         rc = MDP(exp->exp_obd, getattr)(exp, fid, valid,
1580                                         ea_size, request);
1581         RETURN(rc);
1582 }
1583
1584 static inline int md_change_cbdata(struct obd_export *exp, struct lu_fid *fid,
1585                                    ldlm_iterator_t it, void *data)
1586 {
1587         int rc;
1588         ENTRY;
1589         EXP_CHECK_MD_OP(exp, change_cbdata);
1590         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1591         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1592         RETURN(rc);
1593 }
1594
1595 static inline int md_close(struct obd_export *exp,
1596                            struct md_op_data *op_data,
1597                            struct obd_client_handle *och,
1598                            struct ptlrpc_request **request)
1599 {
1600         int rc;
1601         ENTRY;
1602         EXP_CHECK_MD_OP(exp, close);
1603         MD_COUNTER_INCREMENT(exp->exp_obd, close);
1604         rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1605         RETURN(rc);
1606 }
1607
1608 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1609                             const void *data, int datalen, int mode,
1610                             __u32 uid, __u32 gid, __u32 cap_effective, __u64 rdev,
1611                             struct ptlrpc_request **request)
1612 {
1613         int rc;
1614         ENTRY;
1615         EXP_CHECK_MD_OP(exp, create);
1616         MD_COUNTER_INCREMENT(exp->exp_obd, create);
1617         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1618                                        uid, gid, cap_effective, rdev, request);
1619         RETURN(rc);
1620 }
1621
1622 static inline int md_done_writing(struct obd_export *exp,
1623                                   struct md_op_data *op_data)
1624 {
1625         int rc;
1626         ENTRY;
1627         EXP_CHECK_MD_OP(exp, done_writing);
1628         MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1629         rc = MDP(exp->exp_obd, done_writing)(exp, op_data);
1630         RETURN(rc);
1631 }
1632
1633 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1634                              struct lookup_intent *it, int lock_mode,
1635                              struct md_op_data *op_data,
1636                              struct lustre_handle *lockh,
1637                              void *lmm, int lmmsize,
1638                              ldlm_completion_callback cb_completion,
1639                              ldlm_blocking_callback cb_blocking,
1640                              void *cb_data, int extra_lock_flags)
1641 {
1642         int rc;
1643         ENTRY;
1644         EXP_CHECK_MD_OP(exp, enqueue);
1645         MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1646         rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1647                                         op_data, lockh, lmm, lmmsize,
1648                                         cb_completion, cb_blocking,
1649                                         cb_data, extra_lock_flags);
1650         RETURN(rc);
1651 }
1652
1653 static inline int md_getattr_name(struct obd_export *exp, struct lu_fid *fid,
1654                                   const char *filename, int namelen,
1655                                   obd_valid valid, int ea_size,
1656                                   struct ptlrpc_request **request)
1657 {
1658         int rc;
1659         ENTRY;
1660         EXP_CHECK_MD_OP(exp, getattr_name);
1661         MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1662         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1663                                              valid, ea_size, request);
1664         RETURN(rc);
1665 }
1666
1667 static inline int md_intent_lock(struct obd_export *exp,
1668                                  struct md_op_data *op_data,
1669                                  void *lmm, int lmmsize,
1670                                  struct lookup_intent *it,
1671                                  int flags, struct ptlrpc_request **reqp,
1672                                  ldlm_blocking_callback cb_blocking,
1673                                  int extra_lock_flags)
1674 {
1675         int rc;
1676         ENTRY;
1677         EXP_CHECK_MD_OP(exp, intent_lock);
1678         MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1679         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1680                                             it, flags, reqp, cb_blocking,
1681                                             extra_lock_flags);
1682         RETURN(rc);
1683 }
1684
1685 static inline int md_link(struct obd_export *exp,
1686                           struct md_op_data *op_data,
1687                           struct ptlrpc_request **request)
1688 {
1689         int rc;
1690         ENTRY;
1691         EXP_CHECK_MD_OP(exp, link);
1692         MD_COUNTER_INCREMENT(exp->exp_obd, link);
1693         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1694         RETURN(rc);
1695 }
1696
1697 static inline int md_rename(struct obd_export *exp,
1698                             struct md_op_data *op_data,
1699                             const char *old, int oldlen,
1700                             const char *new, int newlen,
1701                             struct ptlrpc_request **request)
1702 {
1703         int rc;
1704         ENTRY;
1705         EXP_CHECK_MD_OP(exp, rename);
1706         MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1707         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1708                                        newlen, request);
1709         RETURN(rc);
1710 }
1711
1712 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1713                              struct iattr *iattr, void *ea, int ealen,
1714                              void *ea2, int ea2len, struct ptlrpc_request **request)
1715 {
1716         int rc;
1717         ENTRY;
1718         EXP_CHECK_MD_OP(exp, setattr);
1719         MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1720         rc = MDP(exp->exp_obd, setattr)(exp, op_data, iattr, ea, ealen,
1721                                         ea2, ea2len, request);
1722         RETURN(rc);
1723 }
1724
1725 static inline int md_sync(struct obd_export *exp, struct lu_fid *fid,
1726                           struct ptlrpc_request **request)
1727 {
1728         int rc;
1729         ENTRY;
1730         EXP_CHECK_MD_OP(exp, sync);
1731         MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1732         rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1733         RETURN(rc);
1734 }
1735
1736 static inline int md_readpage(struct obd_export *exp, struct lu_fid *fid,
1737                               __u64 offset, struct page *page,
1738                               struct ptlrpc_request **request)
1739 {
1740         int rc;
1741         ENTRY;
1742         EXP_CHECK_MD_OP(exp, readpage);
1743         MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1744         rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1745         RETURN(rc);
1746 }
1747
1748 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1749                             struct ptlrpc_request **request)
1750 {
1751         int rc;
1752         ENTRY;
1753         EXP_CHECK_MD_OP(exp, unlink);
1754         MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1755         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1756         RETURN(rc);
1757 }
1758
1759 static inline int md_get_lustre_md(struct obd_export *exp,
1760                                    struct ptlrpc_request *req,
1761                                    int offset, struct obd_export *dt_exp,
1762                                    struct lustre_md *md)
1763 {
1764         ENTRY;
1765         EXP_CHECK_MD_OP(exp, get_lustre_md);
1766         MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1767         RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1768                                                 dt_exp, md));
1769 }
1770
1771 static inline int md_free_lustre_md(struct obd_export *exp,
1772                                     struct lustre_md *md)
1773 {
1774         ENTRY;
1775         EXP_CHECK_MD_OP(exp, free_lustre_md);
1776         MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1777         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1778 }
1779
1780 static inline int md_setxattr(struct obd_export *exp, struct lu_fid *fid,
1781                               obd_valid valid, const char *name,
1782                               const char *input, int input_size,
1783                               int output_size, int flags,
1784                               struct ptlrpc_request **request)
1785 {
1786         ENTRY;
1787         EXP_CHECK_MD_OP(exp, setxattr);
1788         MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1789         RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1790                                            input_size, output_size, flags,
1791                                            request));
1792 }
1793
1794 static inline int md_getxattr(struct obd_export *exp, struct lu_fid *fid,
1795                               obd_valid valid, const char *name,
1796                               const char *input, int input_size,
1797                               int output_size, int flags,
1798                               struct ptlrpc_request **request)
1799 {
1800         ENTRY;
1801         EXP_CHECK_MD_OP(exp, getxattr);
1802         MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1803         RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1804                                            input_size, output_size, flags,
1805                                            request));
1806 }
1807
1808 static inline int md_set_open_replay_data(struct obd_export *exp,
1809                                           struct obd_client_handle *och,
1810                                           struct ptlrpc_request *open_req)
1811 {
1812         ENTRY;
1813         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1814         MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1815         RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1816 }
1817
1818 static inline int md_clear_open_replay_data(struct obd_export *exp,
1819                                             struct obd_client_handle *och)
1820 {
1821         ENTRY;
1822         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1823         MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1824         RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1825 }
1826
1827 static inline int md_set_lock_data(struct obd_export *exp,
1828                                    __u64 *lockh, void *data)
1829 {
1830         ENTRY;
1831         EXP_CHECK_MD_OP(exp, set_lock_data);
1832         MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1833         RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1834 }
1835
1836 static inline int md_cancel_unused(struct obd_export *exp,
1837                                    struct lu_fid *fid,
1838                                    int flags, void *opaque)
1839 {
1840         int rc;
1841         ENTRY;
1842
1843         EXP_CHECK_MD_OP(exp, cancel_unused);
1844         MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1845
1846         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1847         RETURN(rc);
1848 }
1849
1850 static inline int md_lock_match(struct obd_export *exp, int flags,
1851                                 struct lu_fid *fid, ldlm_type_t type,
1852                                 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1853                                 struct lustre_handle *lockh)
1854 {
1855         ENTRY;
1856         EXP_CHECK_MD_OP(exp, lock_match);
1857         MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1858         RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1859                                              policy, mode, lockh));
1860 }
1861
1862 static inline int md_init_ea_size(struct obd_export *exp,
1863                                   int easize, int def_asize,
1864                                   int cookiesize)
1865 {
1866         ENTRY;
1867         EXP_CHECK_MD_OP(exp, init_ea_size);
1868         MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1869         RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize,
1870                                                def_asize,
1871                                                cookiesize));
1872 }
1873
1874 /* OBD Metadata Support */
1875 extern int obd_init_caches(void);
1876 extern void obd_cleanup_caches(void);
1877
1878 /* support routines */
1879 extern cfs_mem_cache_t *obdo_cachep;
1880 static inline struct obdo *obdo_alloc(void)
1881 {
1882         struct obdo *oa;
1883         OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1884         return oa;
1885 }
1886
1887 static inline void obdo_free(struct obdo *oa)
1888 {
1889         OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1890 }
1891
1892 static inline void obdo2fid(struct obdo *oa,
1893                             struct lu_fid *fid)
1894 {
1895         /* something here */
1896 }
1897
1898 static inline void fid2obdo(struct lu_fid *fid,
1899                             struct obdo *oa)
1900 {
1901         /* something here */
1902 }
1903
1904 /* I'm as embarrassed about this as you are.
1905  *
1906  * <shaver> // XXX do not look into _superhack with remaining eye
1907  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1908 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1909
1910 /* sysctl.c */
1911 extern void obd_sysctl_init (void);
1912 extern void obd_sysctl_clean (void);
1913
1914 /* uuid.c  */
1915 typedef __u8 class_uuid_t[16];
1916 void class_generate_random_uuid(class_uuid_t uuid);
1917 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1918
1919 /* lustre_peer.c    */
1920 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1921 int class_add_uuid(const char *uuid, __u64 nid);
1922 int class_del_uuid (const char *uuid);
1923 void class_init_uuidlist(void);
1924 void class_exit_uuidlist(void);
1925
1926 /* mea.c */
1927 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1928 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1929
1930 #endif /* __LINUX_OBD_CLASS_H */