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