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