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_create(struct obd_export *exp, struct obdo *obdo,
636                              struct lov_stripe_md **ea,
637                              struct obd_trans_info *oti)
638 {
639         int rc;
640         ENTRY;
641
642         EXP_CHECK_DT_OP(exp, create);
643         EXP_COUNTER_INCREMENT(exp, create);
644
645         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
646         RETURN(rc);
647 }
648
649 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
650                               struct lov_stripe_md *ea,
651                               struct obd_trans_info *oti,
652                               struct obd_export *md_exp)
653 {
654         int rc;
655         ENTRY;
656
657         EXP_CHECK_DT_OP(exp, destroy);
658         EXP_COUNTER_INCREMENT(exp, destroy);
659
660         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
661         RETURN(rc);
662 }
663
664 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
665 {
666         int rc;
667         ENTRY;
668
669         EXP_CHECK_DT_OP(exp, getattr);
670         EXP_COUNTER_INCREMENT(exp, getattr);
671
672         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
673         RETURN(rc);
674 }
675
676 static inline int obd_getattr_async(struct obd_export *exp,
677                                     struct obd_info *oinfo,
678                                     struct ptlrpc_request_set *set)
679 {
680         int rc;
681         ENTRY;
682
683         EXP_CHECK_DT_OP(exp, getattr_async);
684         EXP_COUNTER_INCREMENT(exp, getattr_async);
685
686         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
687         RETURN(rc);
688 }
689
690 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
691                               struct obd_trans_info *oti)
692 {
693         int rc;
694         ENTRY;
695
696         EXP_CHECK_DT_OP(exp, setattr);
697         EXP_COUNTER_INCREMENT(exp, setattr);
698
699         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
700         RETURN(rc);
701 }
702
703 /* This performs all the requests set init/wait/destroy actions. */
704 static inline int obd_setattr_rqset(struct obd_export *exp,
705                                     struct obd_info *oinfo,
706                                     struct obd_trans_info *oti)
707 {
708         struct ptlrpc_request_set *set = NULL;
709         int rc;
710         ENTRY;
711
712         EXP_CHECK_DT_OP(exp, setattr_async);
713         EXP_COUNTER_INCREMENT(exp, setattr_async);
714
715         set =  ptlrpc_prep_set();
716         if (set == NULL)
717                 RETURN(-ENOMEM);
718
719         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
720         if (rc == 0)
721                 rc = ptlrpc_set_wait(set);
722         ptlrpc_set_destroy(set);
723         RETURN(rc);
724 }
725
726 /* This adds all the requests into @set if @set != NULL, otherwise
727    all requests are sent asynchronously without waiting for response. */
728 static inline int obd_setattr_async(struct obd_export *exp,
729                                     struct obd_info *oinfo,
730                                     struct obd_trans_info *oti,
731                                     struct ptlrpc_request_set *set)
732 {
733         int rc;
734         ENTRY;
735
736         EXP_CHECK_DT_OP(exp, setattr_async);
737         EXP_COUNTER_INCREMENT(exp, setattr_async);
738
739         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
740         RETURN(rc);
741 }
742
743 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
744                                int priority)
745 {
746         struct obd_device *obd = imp->imp_obd;
747         int rc;
748         ENTRY;
749
750         OBD_CHECK_DEV_ACTIVE(obd);
751         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
752         OBD_COUNTER_INCREMENT(obd, add_conn);
753
754         rc = OBP(obd, add_conn)(imp, uuid, priority);
755         RETURN(rc);
756 }
757
758 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
759 {
760         struct obd_device *obd = imp->imp_obd;
761         int rc;
762         ENTRY;
763
764         OBD_CHECK_DEV_ACTIVE(obd);
765         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
766         OBD_COUNTER_INCREMENT(obd, del_conn);
767
768         rc = OBP(obd, del_conn)(imp, uuid);
769         RETURN(rc);
770 }
771
772 static inline int obd_connect(const struct lu_env *env,
773                               struct lustre_handle *conn,struct obd_device *obd,
774                               struct obd_uuid *cluuid,
775                               struct obd_connect_data *d)
776 {
777         int rc;
778 #ifdef LIBCFS_DEBUG
779         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
780                                                    * check */
781 #endif
782         ENTRY;
783
784         OBD_CHECK_DEV_ACTIVE(obd);
785         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
786         OBD_COUNTER_INCREMENT(obd, connect);
787
788         rc = OBP(obd, connect)(env, conn, obd, cluuid, d);
789         /* check that only subset is granted */
790         LASSERT(ergo(d != NULL,
791                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
792         RETURN(rc);
793 }
794
795 static inline int obd_reconnect(struct obd_export *exp,
796                                 struct obd_device *obd,
797                                 struct obd_uuid *cluuid,
798                                 struct obd_connect_data *d)
799 {
800         int rc;
801 #ifdef LIBCFS_DEBUG
802         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
803                                                    * check */
804 #endif
805
806         ENTRY;
807
808         OBD_CHECK_DEV_ACTIVE(obd);
809         OBD_CHECK_DT_OP(obd, reconnect, 0);
810         OBD_COUNTER_INCREMENT(obd, reconnect);
811
812         rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
813         /* check that only subset is granted */
814         LASSERT(ergo(d != NULL,
815                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
816         RETURN(rc);
817 }
818
819 static inline int obd_disconnect(struct obd_export *exp)
820 {
821         int rc;
822         ENTRY;
823
824         EXP_CHECK_DT_OP(exp, disconnect);
825         EXP_COUNTER_INCREMENT(exp, disconnect);
826
827         rc = OBP(exp->exp_obd, disconnect)(exp);
828         RETURN(rc);
829 }
830
831 static inline int obd_fid_init(struct obd_export *exp)
832 {
833         int rc;
834         ENTRY;
835
836         OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
837         EXP_COUNTER_INCREMENT(exp, fid_init);
838
839         rc = OBP(exp->exp_obd, fid_init)(exp);
840         RETURN(rc);
841 }
842
843 static inline int obd_fid_fini(struct obd_export *exp)
844 {
845         int rc;
846         ENTRY;
847
848         OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
849         EXP_COUNTER_INCREMENT(exp, fid_fini);
850
851         rc = OBP(exp->exp_obd, fid_fini)(exp);
852         RETURN(rc);
853 }
854
855 static inline int obd_fid_alloc(struct obd_export *exp,
856                                 struct lu_fid *fid,
857                                 struct md_op_data *op_data)
858 {
859         int rc;
860         ENTRY;
861
862         EXP_CHECK_DT_OP(exp, fid_alloc);
863         EXP_COUNTER_INCREMENT(exp, fid_alloc);
864
865         rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
866         RETURN(rc);
867 }
868
869 static inline int obd_fid_delete(struct obd_export *exp,
870                                  const struct lu_fid *fid)
871 {
872         int rc;
873         ENTRY;
874
875         EXP_CHECK_DT_OP(exp, fid_delete);
876         EXP_COUNTER_INCREMENT(exp, fid_delete);
877
878         rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
879         RETURN(rc);
880 }
881
882 static inline int obd_ping(struct obd_export *exp)
883 {
884         int rc;
885         ENTRY;
886
887         OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
888         EXP_COUNTER_INCREMENT(exp, ping);
889
890         rc = OBP(exp->exp_obd, ping)(exp);
891         RETURN(rc);
892 }
893
894 static inline int obd_init_export(struct obd_export *exp)
895 {
896         int rc = 0;
897
898         ENTRY;
899         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
900             OBP((exp)->exp_obd, init_export))
901                 rc = OBP(exp->exp_obd, init_export)(exp);
902         RETURN(rc);
903 }
904
905 static inline int obd_destroy_export(struct obd_export *exp)
906 {
907         ENTRY;
908         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
909             OBP((exp)->exp_obd, destroy_export))
910                 OBP(exp->exp_obd, destroy_export)(exp);
911         RETURN(0);
912 }
913
914 static inline int obd_extent_calc(struct obd_export *exp,
915                                   struct lov_stripe_md *md,
916                                   int cmd, obd_off *offset)
917 {
918         int rc;
919         ENTRY;
920         EXP_CHECK_DT_OP(exp, extent_calc);
921         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
922         RETURN(rc);
923 }
924
925 static inline struct dentry *
926 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
927 {
928         LASSERT(exp->exp_obd);
929
930         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
931                                exp->exp_obd);
932 }
933
934 static inline int
935 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
936 {
937         LASSERT(exp->exp_obd);
938         CERROR("FIXME what's the story here?  This needs to be an obd fn?\n");
939 #if 0
940         return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
941                               dentry, exp->exp_obd);
942 #endif
943         return 0;
944 }
945
946 #ifndef time_before
947 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
948 #endif
949
950 /* @max_age is the oldest time in jiffies that we accept using a cached data.
951  * If the cache is older than @max_age we will get a new value from the
952  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
953 static inline int obd_statfs_async(struct obd_device *obd,
954                                    struct obd_info *oinfo,
955                                    __u64 max_age,
956                                    struct ptlrpc_request_set *rqset)
957 {
958         int rc = 0;
959         ENTRY;
960
961         if (obd == NULL)
962                 RETURN(-EINVAL);
963
964         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
965         OBD_COUNTER_INCREMENT(obd, statfs);
966
967         CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
968                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
969         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
970                 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
971         } else {
972                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
973                        " objects "LPU64"/"LPU64"\n",
974                        obd->obd_name, &obd->obd_osfs,
975                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
976                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
977                 spin_lock(&obd->obd_osfs_lock);
978                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
979                 spin_unlock(&obd->obd_osfs_lock);
980                 if (oinfo->oi_cb_up)
981                         oinfo->oi_cb_up(oinfo, 0);
982         }
983         RETURN(rc);
984 }
985
986 static inline int obd_statfs_rqset(struct obd_device *obd,
987                                    struct obd_statfs *osfs, __u64 max_age)
988 {
989         struct ptlrpc_request_set *set = NULL;
990         struct obd_info oinfo = { { { 0 } } };
991         int rc = 0;
992         ENTRY;
993
994         set =  ptlrpc_prep_set();
995         if (set == NULL)
996                 RETURN(-ENOMEM);
997
998         oinfo.oi_osfs = osfs;
999         rc = obd_statfs_async(obd, &oinfo, max_age, set);
1000         if (rc == 0)
1001                 rc = ptlrpc_set_wait(set);
1002         ptlrpc_set_destroy(set);
1003         RETURN(rc);
1004 }
1005
1006 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1007  * If the cache is older than @max_age we will get a new value from the
1008  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1009 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1010                              __u64 max_age)
1011 {
1012         int rc = 0;
1013         ENTRY;
1014
1015         if (obd == NULL)
1016                 RETURN(-EINVAL);
1017
1018         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1019         OBD_COUNTER_INCREMENT(obd, statfs);
1020
1021         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1022                obd->obd_osfs_age, max_age);
1023         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1024                 rc = OBP(obd, statfs)(obd, osfs, max_age);
1025                 if (rc == 0) {
1026                         spin_lock(&obd->obd_osfs_lock);
1027                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1028                         obd->obd_osfs_age = cfs_time_current_64();
1029                         spin_unlock(&obd->obd_osfs_lock);
1030                 }
1031         } else {
1032                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1033                        " objects "LPU64"/"LPU64"\n",
1034                        obd->obd_name, &obd->obd_osfs,
1035                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1036                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1037                 spin_lock(&obd->obd_osfs_lock);
1038                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1039                 spin_unlock(&obd->obd_osfs_lock);
1040         }
1041         RETURN(rc);
1042 }
1043
1044 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1045                            struct lov_stripe_md *ea, obd_size start,
1046                            obd_size end, void *capa)
1047 {
1048         int rc;
1049         ENTRY;
1050
1051         OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1052         EXP_COUNTER_INCREMENT(exp, sync);
1053
1054         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1055         RETURN(rc);
1056 }
1057
1058 static inline int obd_punch_rqset(struct obd_export *exp,
1059                                   struct obd_info *oinfo,
1060                                   struct obd_trans_info *oti)
1061 {
1062         struct ptlrpc_request_set *set = NULL;
1063         int rc;
1064         ENTRY;
1065
1066         EXP_CHECK_DT_OP(exp, punch);
1067         EXP_COUNTER_INCREMENT(exp, punch);
1068
1069         set =  ptlrpc_prep_set();
1070         if (set == NULL)
1071                 RETURN(-ENOMEM);
1072
1073         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1074         if (rc == 0)
1075                 rc = ptlrpc_set_wait(set);
1076         ptlrpc_set_destroy(set);
1077         RETURN(rc);
1078 }
1079
1080 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1081                             struct obd_trans_info *oti,
1082                             struct ptlrpc_request_set *rqset)
1083 {
1084         int rc;
1085         ENTRY;
1086
1087         EXP_CHECK_DT_OP(exp, punch);
1088         EXP_COUNTER_INCREMENT(exp, punch);
1089
1090         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1091         RETURN(rc);
1092 }
1093
1094 static inline int obd_brw(int cmd, struct obd_export *exp,
1095                           struct obd_info *oinfo, obd_count oa_bufs,
1096                           struct brw_page *pg, struct obd_trans_info *oti)
1097 {
1098         int rc;
1099         ENTRY;
1100
1101         EXP_CHECK_DT_OP(exp, brw);
1102         EXP_COUNTER_INCREMENT(exp, brw);
1103
1104         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1105                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1106                        "or OBD_BRW_CHECK\n");
1107                 LBUG();
1108         }
1109
1110         rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1111         RETURN(rc);
1112 }
1113
1114 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1115                                 struct obd_info *oinfo, obd_count oa_bufs,
1116                                 struct brw_page *pg, struct obd_trans_info *oti,
1117                                 struct ptlrpc_request_set *set)
1118 {
1119         int rc;
1120         ENTRY;
1121
1122         EXP_CHECK_DT_OP(exp, brw_async);
1123         EXP_COUNTER_INCREMENT(exp, brw_async);
1124
1125         if (!(cmd & OBD_BRW_RWMASK)) {
1126                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1127                 LBUG();
1128         }
1129
1130         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1131         RETURN(rc);
1132 }
1133
1134 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1135                                 struct obdo *oa, struct lov_stripe_md *lsm,
1136                                 obd_count oa_bufs, struct brw_page *pg,
1137                                 struct obd_trans_info *oti,
1138                                 struct obd_capa *ocapa)
1139 {
1140         struct ptlrpc_request_set *set = NULL;
1141         struct obd_info oinfo = { { { 0 } } };
1142         atomic_t nob;
1143         int rc = 0;
1144         ENTRY;
1145
1146         set =  ptlrpc_prep_set();
1147         if (set == NULL)
1148                 RETURN(-ENOMEM);
1149         atomic_set(&nob, 0);
1150         set->set_countp = &nob;
1151
1152         oinfo.oi_oa = oa;
1153         oinfo.oi_md = lsm;
1154         oinfo.oi_capa = ocapa;
1155         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1156         if (rc == 0) {
1157                 rc = ptlrpc_set_wait(set);
1158                 if (rc)
1159                         CERROR("error from callback: rc = %d\n", rc);
1160                 else
1161                         rc = atomic_read(&nob);
1162         } else {
1163                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
1164                        "error from obd_brw_async: rc = %d\n", rc);
1165         }
1166         ptlrpc_set_destroy(set);
1167         RETURN(rc);
1168 }
1169
1170 static inline  int obd_prep_async_page(struct obd_export *exp,
1171                                        struct lov_stripe_md *lsm,
1172                                        struct lov_oinfo *loi,
1173                                        cfs_page_t *page, obd_off offset,
1174                                        struct obd_async_page_ops *ops,
1175                                        void *data, void **res)
1176 {
1177         int ret;
1178         ENTRY;
1179
1180         EXP_CHECK_DT_OP(exp, prep_async_page);
1181         EXP_COUNTER_INCREMENT(exp, prep_async_page);
1182
1183         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1184                                                  ops, data, res);
1185         RETURN(ret);
1186 }
1187
1188 static inline int obd_queue_async_io(struct obd_export *exp,
1189                                      struct lov_stripe_md *lsm,
1190                                      struct lov_oinfo *loi, void *cookie,
1191                                      int cmd, obd_off off, int count,
1192                                      obd_flag brw_flags, obd_flag async_flags)
1193 {
1194         int rc;
1195         ENTRY;
1196
1197         EXP_CHECK_DT_OP(exp, queue_async_io);
1198         EXP_COUNTER_INCREMENT(exp, queue_async_io);
1199         LASSERT(cmd & OBD_BRW_RWMASK);
1200
1201         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1202                                                count, brw_flags, async_flags);
1203         RETURN(rc);
1204 }
1205
1206 static inline int obd_set_async_flags(struct obd_export *exp,
1207                                       struct lov_stripe_md *lsm,
1208                                       struct lov_oinfo *loi, void *cookie,
1209                                       obd_flag async_flags)
1210 {
1211         int rc;
1212         ENTRY;
1213
1214         EXP_CHECK_DT_OP(exp, set_async_flags);
1215         EXP_COUNTER_INCREMENT(exp, set_async_flags);
1216
1217         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1218                                                 async_flags);
1219         RETURN(rc);
1220 }
1221
1222 static inline int obd_queue_group_io(struct obd_export *exp,
1223                                      struct lov_stripe_md *lsm,
1224                                      struct lov_oinfo *loi,
1225                                      struct obd_io_group *oig,
1226                                      void *cookie, int cmd, obd_off off,
1227                                      int count, obd_flag brw_flags,
1228                                      obd_flag async_flags)
1229 {
1230         int rc;
1231         ENTRY;
1232
1233         EXP_CHECK_DT_OP(exp, queue_group_io);
1234         EXP_COUNTER_INCREMENT(exp, queue_group_io);
1235         LASSERT(cmd & OBD_BRW_RWMASK);
1236
1237         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1238                                                cmd, off, count, brw_flags,
1239                                                async_flags);
1240         RETURN(rc);
1241 }
1242
1243 static inline int obd_trigger_group_io(struct obd_export *exp,
1244                                        struct lov_stripe_md *lsm,
1245                                        struct lov_oinfo *loi,
1246                                        struct obd_io_group *oig)
1247 {
1248         int rc;
1249         ENTRY;
1250
1251         EXP_CHECK_DT_OP(exp, trigger_group_io);
1252         EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1253
1254         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1255         RETURN(rc);
1256 }
1257
1258 static inline int obd_teardown_async_page(struct obd_export *exp,
1259                                           struct lov_stripe_md *lsm,
1260                                           struct lov_oinfo *loi, void *cookie)
1261 {
1262         int rc;
1263         ENTRY;
1264
1265         EXP_CHECK_DT_OP(exp, teardown_async_page);
1266         EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1267
1268         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1269         RETURN(rc);
1270 }
1271
1272 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1273                              int objcount, struct obd_ioobj *obj,
1274                              int niocount, struct niobuf_remote *remote,
1275                              struct niobuf_local *local,
1276                              struct obd_trans_info *oti,
1277                              struct lustre_capa *capa)
1278 {
1279         int rc;
1280         ENTRY;
1281
1282         EXP_CHECK_DT_OP(exp, preprw);
1283         EXP_COUNTER_INCREMENT(exp, preprw);
1284
1285         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1286                                        remote, local, oti, capa);
1287         RETURN(rc);
1288 }
1289
1290 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1291                                int objcount, struct obd_ioobj *obj,
1292                                int niocount, struct niobuf_local *local,
1293                                struct obd_trans_info *oti, int rc)
1294 {
1295         ENTRY;
1296
1297         EXP_CHECK_DT_OP(exp, commitrw);
1298         EXP_COUNTER_INCREMENT(exp, commitrw);
1299
1300         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1301                                          local, oti, rc);
1302         RETURN(rc);
1303 }
1304
1305 static inline int obd_merge_lvb(struct obd_export *exp,
1306                                 struct lov_stripe_md *lsm,
1307                                 struct ost_lvb *lvb, int kms_only)
1308 {
1309         int rc;
1310         ENTRY;
1311
1312         EXP_CHECK_DT_OP(exp, merge_lvb);
1313         EXP_COUNTER_INCREMENT(exp, merge_lvb);
1314
1315         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1316         RETURN(rc);
1317 }
1318
1319 static inline int obd_adjust_kms(struct obd_export *exp,
1320                                  struct lov_stripe_md *lsm, obd_off size,
1321                                  int shrink)
1322 {
1323         int rc;
1324         ENTRY;
1325
1326         EXP_CHECK_DT_OP(exp, adjust_kms);
1327         EXP_COUNTER_INCREMENT(exp, adjust_kms);
1328
1329         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1330         RETURN(rc);
1331 }
1332
1333 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1334                                 int len, void *karg, void *uarg)
1335 {
1336         int rc;
1337         ENTRY;
1338
1339         EXP_CHECK_DT_OP(exp, iocontrol);
1340         EXP_COUNTER_INCREMENT(exp, iocontrol);
1341
1342         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1343         RETURN(rc);
1344 }
1345
1346 static inline int obd_enqueue_rqset(struct obd_export *exp,
1347                                     struct obd_info *oinfo,
1348                                     struct obd_enqueue_info *einfo)
1349 {
1350         int rc;
1351         ENTRY;
1352
1353         EXP_CHECK_DT_OP(exp, enqueue);
1354         EXP_COUNTER_INCREMENT(exp, enqueue);
1355
1356         einfo->ei_rqset =  ptlrpc_prep_set();
1357         if (einfo->ei_rqset == NULL)
1358                 RETURN(-ENOMEM);
1359
1360         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1361         if (rc == 0)
1362                 rc = ptlrpc_set_wait(einfo->ei_rqset);
1363         ptlrpc_set_destroy(einfo->ei_rqset);
1364         einfo->ei_rqset = NULL;
1365
1366         RETURN(rc);
1367 }
1368
1369 static inline int obd_enqueue(struct obd_export *exp,
1370                               struct obd_info *oinfo,
1371                               struct obd_enqueue_info *einfo)
1372 {
1373         int rc;
1374         ENTRY;
1375
1376         EXP_CHECK_DT_OP(exp, enqueue);
1377         EXP_COUNTER_INCREMENT(exp, enqueue);
1378
1379         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1380         RETURN(rc);
1381 }
1382
1383 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1384                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1385                             int *flags, void *data, struct lustre_handle *lockh)
1386 {
1387         int rc;
1388         ENTRY;
1389
1390         EXP_CHECK_DT_OP(exp, match);
1391         EXP_COUNTER_INCREMENT(exp, match);
1392
1393         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1394                                       lockh);
1395         RETURN(rc);
1396 }
1397
1398 static inline int obd_change_cbdata(struct obd_export *exp,
1399                                     struct lov_stripe_md *lsm,
1400                                     ldlm_iterator_t it, void *data)
1401 {
1402         int rc;
1403         ENTRY;
1404
1405         EXP_CHECK_DT_OP(exp, change_cbdata);
1406         EXP_COUNTER_INCREMENT(exp, change_cbdata);
1407
1408         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1409         RETURN(rc);
1410 }
1411
1412 static inline int obd_cancel(struct obd_export *exp,
1413                              struct lov_stripe_md *ea, __u32 mode,
1414                              struct lustre_handle *lockh)
1415 {
1416         int rc;
1417         ENTRY;
1418
1419         EXP_CHECK_DT_OP(exp, cancel);
1420         EXP_COUNTER_INCREMENT(exp, cancel);
1421
1422         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1423         RETURN(rc);
1424 }
1425
1426 static inline int obd_cancel_unused(struct obd_export *exp,
1427                                     struct lov_stripe_md *ea,
1428                                     int flags, void *opaque)
1429 {
1430         int rc;
1431         ENTRY;
1432
1433         EXP_CHECK_DT_OP(exp, cancel_unused);
1434         EXP_COUNTER_INCREMENT(exp, cancel_unused);
1435
1436         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1437         RETURN(rc);
1438 }
1439
1440 static inline int obd_join_lru(struct obd_export *exp,
1441                                struct lov_stripe_md *ea, int join)
1442 {
1443         int rc;
1444         ENTRY;
1445
1446         EXP_CHECK_DT_OP(exp, join_lru);
1447         EXP_COUNTER_INCREMENT(exp, join_lru);
1448
1449         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1450         RETURN(rc);
1451 }
1452
1453 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1454                           struct obd_capa *oc, struct obd_client_handle *handle,
1455                           int flag)
1456 {
1457         int rc;
1458         ENTRY;
1459
1460         EXP_CHECK_DT_OP(exp, pin);
1461         EXP_COUNTER_INCREMENT(exp, pin);
1462
1463         rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1464         RETURN(rc);
1465 }
1466
1467 static inline int obd_unpin(struct obd_export *exp,
1468                             struct obd_client_handle *handle, int flag)
1469 {
1470         int rc;
1471         ENTRY;
1472
1473         EXP_CHECK_DT_OP(exp, unpin);
1474         EXP_COUNTER_INCREMENT(exp, unpin);
1475
1476         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1477         RETURN(rc);
1478 }
1479
1480
1481 static inline void obd_import_event(struct obd_device *obd,
1482                                     struct obd_import *imp,
1483                                     enum obd_import_event event)
1484 {
1485         ENTRY;
1486         if (!obd) {
1487                 CERROR("NULL device\n");
1488                 EXIT;
1489                 return;
1490         }
1491         if (obd->obd_set_up && OBP(obd, import_event)) {
1492                 OBD_COUNTER_INCREMENT(obd, import_event);
1493                 OBP(obd, import_event)(obd, imp, event);
1494         }
1495         EXIT;
1496 }
1497
1498 static inline int obd_llog_connect(struct obd_export *exp,
1499                                    struct llogd_conn_body *body)
1500 {
1501         int rc;
1502         ENTRY;
1503
1504         OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1505         EXP_COUNTER_INCREMENT(exp, llog_connect);
1506
1507         rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1508         RETURN(rc);
1509 }
1510
1511
1512 static inline int obd_notify(struct obd_device *obd,
1513                              struct obd_device *watched,
1514                              enum obd_notify_event ev,
1515                              void *data)
1516 {
1517         int rc;
1518         ENTRY;
1519         OBD_CHECK_DEV(obd);
1520
1521         /* the check for async_recov is a complete hack - I'm hereby
1522            overloading the meaning to also mean "this was called from
1523            mds_postsetup".  I know that my mds is able to handle notifies
1524            by this point, and it needs to get them to execute mds_postrecov. */
1525         if (!obd->obd_set_up && !obd->obd_async_recov) {
1526                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1527                 RETURN(-EINVAL);
1528         }
1529
1530         if (!OBP(obd, notify)) {
1531                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1532                 RETURN(-ENOSYS);
1533         }
1534
1535         OBD_COUNTER_INCREMENT(obd, notify);
1536         rc = OBP(obd, notify)(obd, watched, ev, data);
1537         RETURN(rc);
1538 }
1539
1540 static inline int obd_notify_observer(struct obd_device *observer,
1541                                       struct obd_device *observed,
1542                                       enum obd_notify_event ev,
1543                                       void *data)
1544 {
1545         int rc1;
1546         int rc2;
1547
1548         struct obd_notify_upcall *onu;
1549
1550         if (observer->obd_observer)
1551                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1552         else
1553                 rc1 = 0;
1554         /*
1555          * Also, call non-obd listener, if any
1556          */
1557         onu = &observer->obd_upcall;
1558         if (onu->onu_upcall != NULL)
1559                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1560         else
1561                 rc2 = 0;
1562
1563         return rc1 ? rc1 : rc2;
1564 }
1565
1566 static inline int obd_quotacheck(struct obd_export *exp,
1567                                  struct obd_quotactl *oqctl)
1568 {
1569         int rc;
1570         ENTRY;
1571
1572         EXP_CHECK_DT_OP(exp, quotacheck);
1573         EXP_COUNTER_INCREMENT(exp, quotacheck);
1574
1575         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1576         RETURN(rc);
1577 }
1578
1579 static inline int obd_quotactl(struct obd_export *exp,
1580                                struct obd_quotactl *oqctl)
1581 {
1582         int rc;
1583         ENTRY;
1584
1585         EXP_CHECK_DT_OP(exp, quotactl);
1586         EXP_COUNTER_INCREMENT(exp, quotactl);
1587
1588         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1589         RETURN(rc);
1590 }
1591
1592 static inline int obd_health_check(struct obd_device *obd)
1593 {
1594         /* returns: 0 on healthy
1595          *         >0 on unhealthy + reason code/flag
1596          *            however the only suppored reason == 1 right now
1597          *            We'll need to define some better reasons
1598          *            or flags in the future.
1599          *         <0 on error
1600          */
1601         int rc;
1602         ENTRY;
1603
1604         /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1605         if (obd == NULL || !OBT(obd)) {
1606                 CERROR("cleaned up obd\n");
1607                 RETURN(-EOPNOTSUPP);
1608         }
1609         if (!obd->obd_set_up || obd->obd_stopping)
1610                 RETURN(0);
1611         if (!OBP(obd, health_check))
1612                 RETURN(0);
1613
1614         rc = OBP(obd, health_check)(obd);
1615         RETURN(rc);
1616 }
1617
1618 static inline int obd_register_observer(struct obd_device *obd,
1619                                         struct obd_device *observer)
1620 {
1621         ENTRY;
1622         OBD_CHECK_DEV(obd);
1623         if (obd->obd_observer && observer)
1624                 RETURN(-EALREADY);
1625         obd->obd_observer = observer;
1626         RETURN(0);
1627 }
1628
1629 /* metadata helpers */
1630 static inline int md_getstatus(struct obd_export *exp,
1631                                struct lu_fid *fid, struct obd_capa **pc)
1632 {
1633         int rc;
1634         ENTRY;
1635
1636         EXP_CHECK_MD_OP(exp, getstatus);
1637         EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1638         rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1639         RETURN(rc);
1640 }
1641
1642 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1643                              struct obd_capa *oc, obd_valid valid, int ea_size,
1644                              struct ptlrpc_request **request)
1645 {
1646         int rc;
1647         ENTRY;
1648         EXP_CHECK_MD_OP(exp, getattr);
1649         EXP_MD_COUNTER_INCREMENT(exp, getattr);
1650         rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1651                                         ea_size, request);
1652         RETURN(rc);
1653 }
1654
1655 static inline int md_change_cbdata(struct obd_export *exp,
1656                                    const struct lu_fid *fid,
1657                                    ldlm_iterator_t it, void *data)
1658 {
1659         int rc;
1660         ENTRY;
1661         EXP_CHECK_MD_OP(exp, change_cbdata);
1662         EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1663         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1664         RETURN(rc);
1665 }
1666
1667 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1668                            struct obd_client_handle *och,
1669                            struct ptlrpc_request **request)
1670 {
1671         int rc;
1672         ENTRY;
1673         EXP_CHECK_MD_OP(exp, close);
1674         EXP_MD_COUNTER_INCREMENT(exp, close);
1675         rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1676         RETURN(rc);
1677 }
1678
1679 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1680                             const void *data, int datalen, int mode, __u32 uid,
1681                             __u32 gid, __u32 cap_effective, __u64 rdev,
1682                             struct ptlrpc_request **request)
1683 {
1684         int rc;
1685         ENTRY;
1686         EXP_CHECK_MD_OP(exp, create);
1687         EXP_MD_COUNTER_INCREMENT(exp, create);
1688         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1689                                        uid, gid, cap_effective, rdev, request);
1690         RETURN(rc);
1691 }
1692
1693 static inline int md_done_writing(struct obd_export *exp,
1694                                   struct md_op_data *op_data,
1695                                   struct obd_client_handle *och)
1696 {
1697         int rc;
1698         ENTRY;
1699         EXP_CHECK_MD_OP(exp, done_writing);
1700         EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1701         rc = MDP(exp->exp_obd, done_writing)(exp, op_data, och);
1702         RETURN(rc);
1703 }
1704
1705 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1706                              struct lookup_intent *it, int lock_mode,
1707                              struct md_op_data *op_data,
1708                              struct lustre_handle *lockh,
1709                              void *lmm, int lmmsize,
1710                              ldlm_completion_callback cb_completion,
1711                              ldlm_blocking_callback cb_blocking,
1712                              void *cb_data, int extra_lock_flags)
1713 {
1714         int rc;
1715         ENTRY;
1716         EXP_CHECK_MD_OP(exp, enqueue);
1717         EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1718         rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1719                                         op_data, lockh, lmm, lmmsize,
1720                                         cb_completion, cb_blocking,
1721                                         cb_data, extra_lock_flags);
1722         RETURN(rc);
1723 }
1724
1725 static inline int md_getattr_name(struct obd_export *exp,
1726                                   const struct lu_fid *fid, struct obd_capa *oc,
1727                                   const char *name, int namelen,
1728                                   obd_valid valid, int ea_size,
1729                                   struct ptlrpc_request **request)
1730 {
1731         int rc;
1732         ENTRY;
1733         EXP_CHECK_MD_OP(exp, getattr_name);
1734         EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1735         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1736                                              valid, ea_size, request);
1737         RETURN(rc);
1738 }
1739
1740 static inline int md_intent_lock(struct obd_export *exp,
1741                                  struct md_op_data *op_data, void *lmm,
1742                                  int lmmsize, struct lookup_intent *it,
1743                                  int flags, struct ptlrpc_request **reqp,
1744                                  ldlm_blocking_callback cb_blocking,
1745                                  int extra_lock_flags)
1746 {
1747         int rc;
1748         ENTRY;
1749         EXP_CHECK_MD_OP(exp, intent_lock);
1750         EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1751         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1752                                             it, flags, reqp, cb_blocking,
1753                                             extra_lock_flags);
1754         RETURN(rc);
1755 }
1756
1757 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1758                           struct ptlrpc_request **request)
1759 {
1760         int rc;
1761         ENTRY;
1762         EXP_CHECK_MD_OP(exp, link);
1763         EXP_MD_COUNTER_INCREMENT(exp, link);
1764         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1765         RETURN(rc);
1766 }
1767
1768 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1769                             const char *old, int oldlen, const char *new,
1770                             int newlen, struct ptlrpc_request **request)
1771 {
1772         int rc;
1773         ENTRY;
1774         EXP_CHECK_MD_OP(exp, rename);
1775         EXP_MD_COUNTER_INCREMENT(exp, rename);
1776         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1777                                        newlen, request);
1778         RETURN(rc);
1779 }
1780
1781 static inline int md_is_subdir(struct obd_export *exp,
1782                                const struct lu_fid *pfid,
1783                                const struct lu_fid *cfid,
1784                                struct ptlrpc_request **request)
1785 {
1786         int rc;
1787         ENTRY;
1788         EXP_CHECK_MD_OP(exp, is_subdir);
1789         EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1790         rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1791         RETURN(rc);
1792 }
1793
1794 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1795                              void *ea, int ealen, void *ea2, int ea2len,
1796                              struct ptlrpc_request **request)
1797 {
1798         int rc;
1799         ENTRY;
1800         EXP_CHECK_MD_OP(exp, setattr);
1801         EXP_MD_COUNTER_INCREMENT(exp, setattr);
1802         rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1803                                         ea2, ea2len, request);
1804         RETURN(rc);
1805 }
1806
1807 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1808                           struct obd_capa *oc, struct ptlrpc_request **request)
1809 {
1810         int rc;
1811         ENTRY;
1812         EXP_CHECK_MD_OP(exp, sync);
1813         EXP_MD_COUNTER_INCREMENT(exp, sync);
1814         rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1815         RETURN(rc);
1816 }
1817
1818 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1819                               struct obd_capa *oc, __u64 offset,
1820                               struct page *page,
1821                               struct ptlrpc_request **request)
1822 {
1823         int rc;
1824         ENTRY;
1825         EXP_CHECK_MD_OP(exp, readpage);
1826         EXP_MD_COUNTER_INCREMENT(exp, readpage);
1827         rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1828         RETURN(rc);
1829 }
1830
1831 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1832                             struct ptlrpc_request **request)
1833 {
1834         int rc;
1835         ENTRY;
1836         EXP_CHECK_MD_OP(exp, unlink);
1837         EXP_MD_COUNTER_INCREMENT(exp, unlink);
1838         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1839         RETURN(rc);
1840 }
1841
1842 static inline int md_get_lustre_md(struct obd_export *exp,
1843                                    struct ptlrpc_request *req,
1844                                    int offset, struct obd_export *dt_exp,
1845                                    struct obd_export *md_exp,
1846                                    struct lustre_md *md)
1847 {
1848         ENTRY;
1849         EXP_CHECK_MD_OP(exp, get_lustre_md);
1850         EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1851         RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1852                                                 dt_exp, md_exp, md));
1853 }
1854
1855 static inline int md_free_lustre_md(struct obd_export *exp,
1856                                     struct lustre_md *md)
1857 {
1858         ENTRY;
1859         EXP_CHECK_MD_OP(exp, free_lustre_md);
1860         EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1861         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1862 }
1863
1864 static inline int md_setxattr(struct obd_export *exp,
1865                               const struct lu_fid *fid, struct obd_capa *oc,
1866                               obd_valid valid, const char *name,
1867                               const char *input, int input_size,
1868                               int output_size, int flags,
1869                               struct ptlrpc_request **request)
1870 {
1871         ENTRY;
1872         EXP_CHECK_MD_OP(exp, setxattr);
1873         EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1874         RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1875                                            input_size, output_size, flags,
1876                                            request));
1877 }
1878
1879 static inline int md_getxattr(struct obd_export *exp,
1880                               const struct lu_fid *fid, struct obd_capa *oc,
1881                               obd_valid valid, const char *name,
1882                               const char *input, int input_size,
1883                               int output_size, int flags,
1884                               struct ptlrpc_request **request)
1885 {
1886         ENTRY;
1887         EXP_CHECK_MD_OP(exp, getxattr);
1888         EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1889         RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1890                                            input_size, output_size, flags,
1891                                            request));
1892 }
1893
1894 static inline int md_set_open_replay_data(struct obd_export *exp,
1895                                           struct obd_client_handle *och,
1896                                           struct ptlrpc_request *open_req)
1897 {
1898         ENTRY;
1899         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1900         EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1901         RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1902 }
1903
1904 static inline int md_clear_open_replay_data(struct obd_export *exp,
1905                                             struct obd_client_handle *och)
1906 {
1907         ENTRY;
1908         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1909         EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1910         RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1911 }
1912
1913 static inline int md_set_lock_data(struct obd_export *exp,
1914                                    __u64 *lockh, void *data)
1915 {
1916         ENTRY;
1917         EXP_CHECK_MD_OP(exp, set_lock_data);
1918         EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1919         RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1920 }
1921
1922 static inline int md_cancel_unused(struct obd_export *exp,
1923                                    const struct lu_fid *fid,
1924                                    ldlm_policy_data_t *policy,
1925                                    ldlm_mode_t mode, int flags, void *opaque)
1926 {
1927         int rc;
1928         ENTRY;
1929
1930         EXP_CHECK_MD_OP(exp, cancel_unused);
1931         EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1932
1933         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1934                                               flags, opaque);
1935         RETURN(rc);
1936 }
1937
1938 static inline int md_lock_match(struct obd_export *exp, int flags,
1939                                 const struct lu_fid *fid, ldlm_type_t type,
1940                                 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1941                                 struct lustre_handle *lockh)
1942 {
1943         ENTRY;
1944         EXP_CHECK_MD_OP(exp, lock_match);
1945         EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1946         RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1947                                              policy, mode, lockh));
1948 }
1949
1950 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1951                                   int def_asize, int cookiesize)
1952 {
1953         ENTRY;
1954         EXP_CHECK_MD_OP(exp, init_ea_size);
1955         EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1956         RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1957                                                cookiesize));
1958 }
1959
1960 static inline int md_get_remote_perm(struct obd_export *exp,
1961                                      const struct lu_fid *fid,
1962                                      struct obd_capa *oc,
1963                                      struct ptlrpc_request **request)
1964 {
1965         ENTRY;
1966         EXP_CHECK_MD_OP(exp, get_remote_perm);
1967         EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1968         RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, request));
1969 }
1970
1971 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1972                                 renew_capa_cb_t cb)
1973 {
1974         int rc;
1975         ENTRY;
1976         EXP_CHECK_MD_OP(exp, renew_capa);
1977         EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1978         rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1979         RETURN(rc);
1980 }
1981
1982 /* OBD Metadata Support */
1983
1984 extern int obd_init_caches(void);
1985 extern void obd_cleanup_caches(void);
1986
1987 /* support routines */
1988 extern cfs_mem_cache_t *obdo_cachep;
1989
1990 #define OBDO_ALLOC(ptr)                                                       \
1991 do {                                                                          \
1992         OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep);                               \
1993 } while(0)
1994
1995 #define OBDO_FREE(ptr)                                                        \
1996 do {                                                                          \
1997         OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
1998 } while(0)
1999
2000
2001 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2002 {
2003         /* something here */
2004 }
2005
2006 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2007 {
2008         /* something here */
2009 }
2010
2011 /* I'm as embarrassed about this as you are.
2012  *
2013  * <shaver> // XXX do not look into _superhack with remaining eye
2014  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2015 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2016
2017 /* sysctl.c */
2018 extern void obd_sysctl_init (void);
2019 extern void obd_sysctl_clean (void);
2020
2021 /* uuid.c  */
2022 typedef __u8 class_uuid_t[16];
2023 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2024
2025 /* lustre_peer.c    */
2026 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2027 int class_add_uuid(const char *uuid, __u64 nid);
2028 int class_del_uuid (const char *uuid);
2029 void class_init_uuidlist(void);
2030 void class_exit_uuidlist(void);
2031
2032 /* mea.c */
2033 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2034 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2035
2036 /* prng.c */
2037 void ll_generate_random_uuid(class_uuid_t uuid_out);
2038
2039 #endif /* __LINUX_OBD_CLASS_H */