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