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