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