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