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