Whamcloud - gitweb
Add async create into HEAD (port from 1.x)
[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_async(struct obd_export *exp,
680                                    struct obd_info *oinfo,
681                                    struct lov_stripe_md **ea,
682                                    struct obd_trans_info *oti)
683 {
684         int rc;
685         ENTRY;
686
687         EXP_CHECK_DT_OP(exp, create_async);
688         EXP_COUNTER_INCREMENT(exp, create_async);
689
690         rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
691         RETURN(rc);
692 }
693
694 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
695                              struct lov_stripe_md **ea,
696                              struct obd_trans_info *oti)
697 {
698         int rc;
699         ENTRY;
700
701         EXP_CHECK_DT_OP(exp, create);
702         EXP_COUNTER_INCREMENT(exp, create);
703
704         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
705         RETURN(rc);
706 }
707
708 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
709                               struct lov_stripe_md *ea,
710                               struct obd_trans_info *oti,
711                               struct obd_export *md_exp, void *capa)
712 {
713         int rc;
714         ENTRY;
715
716         EXP_CHECK_DT_OP(exp, destroy);
717         EXP_COUNTER_INCREMENT(exp, destroy);
718
719         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
720         RETURN(rc);
721 }
722
723 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
724 {
725         int rc;
726         ENTRY;
727
728         EXP_CHECK_DT_OP(exp, getattr);
729         EXP_COUNTER_INCREMENT(exp, getattr);
730
731         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
732         RETURN(rc);
733 }
734
735 static inline int obd_getattr_async(struct obd_export *exp,
736                                     struct obd_info *oinfo,
737                                     struct ptlrpc_request_set *set)
738 {
739         int rc;
740         ENTRY;
741
742         EXP_CHECK_DT_OP(exp, getattr_async);
743         EXP_COUNTER_INCREMENT(exp, getattr_async);
744
745         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
746         RETURN(rc);
747 }
748
749 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
750                               struct obd_trans_info *oti)
751 {
752         int rc;
753         ENTRY;
754
755         EXP_CHECK_DT_OP(exp, setattr);
756         EXP_COUNTER_INCREMENT(exp, setattr);
757
758         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
759         RETURN(rc);
760 }
761
762 /* This performs all the requests set init/wait/destroy actions. */
763 static inline int obd_setattr_rqset(struct obd_export *exp,
764                                     struct obd_info *oinfo,
765                                     struct obd_trans_info *oti)
766 {
767         struct ptlrpc_request_set *set = NULL;
768         int rc;
769         ENTRY;
770
771         EXP_CHECK_DT_OP(exp, setattr_async);
772         EXP_COUNTER_INCREMENT(exp, setattr_async);
773
774         set =  ptlrpc_prep_set();
775         if (set == NULL)
776                 RETURN(-ENOMEM);
777
778         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
779         if (rc == 0)
780                 rc = ptlrpc_set_wait(set);
781         ptlrpc_set_destroy(set);
782         RETURN(rc);
783 }
784
785 /* This adds all the requests into @set if @set != NULL, otherwise
786    all requests are sent asynchronously without waiting for response. */
787 static inline int obd_setattr_async(struct obd_export *exp,
788                                     struct obd_info *oinfo,
789                                     struct obd_trans_info *oti,
790                                     struct ptlrpc_request_set *set)
791 {
792         int rc;
793         ENTRY;
794
795         EXP_CHECK_DT_OP(exp, setattr_async);
796         EXP_COUNTER_INCREMENT(exp, setattr_async);
797
798         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
799         RETURN(rc);
800 }
801
802 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
803                                int priority)
804 {
805         struct obd_device *obd = imp->imp_obd;
806         int rc;
807         ENTRY;
808
809         OBD_CHECK_DEV_ACTIVE(obd);
810         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
811         OBD_COUNTER_INCREMENT(obd, add_conn);
812
813         rc = OBP(obd, add_conn)(imp, uuid, priority);
814         RETURN(rc);
815 }
816
817 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
818 {
819         struct obd_device *obd = imp->imp_obd;
820         int rc;
821         ENTRY;
822
823         OBD_CHECK_DEV_ACTIVE(obd);
824         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
825         OBD_COUNTER_INCREMENT(obd, del_conn);
826
827         rc = OBP(obd, del_conn)(imp, uuid);
828         RETURN(rc);
829 }
830
831 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
832 {
833         struct obd_uuid *uuid;
834         ENTRY;
835
836         OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
837         EXP_COUNTER_INCREMENT(exp, get_uuid);
838
839         uuid = OBP(exp->exp_obd, get_uuid)(exp);
840         RETURN(uuid);
841 }
842
843 static inline int obd_connect(const struct lu_env *env,
844                               struct obd_export **exp,struct obd_device *obd,
845                               struct obd_uuid *cluuid,
846                               struct obd_connect_data *d,
847                               void *localdata)
848 {
849         int rc;
850         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
851                                                    * check */
852         ENTRY;
853
854         OBD_CHECK_DEV_ACTIVE(obd);
855         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
856         OBD_COUNTER_INCREMENT(obd, connect);
857
858         rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
859         /* check that only subset is granted */
860         LASSERT(ergo(d != NULL,
861                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
862         RETURN(rc);
863 }
864
865 static inline int obd_reconnect(const struct lu_env *env,
866                                 struct obd_export *exp,
867                                 struct obd_device *obd,
868                                 struct obd_uuid *cluuid,
869                                 struct obd_connect_data *d,
870                                 void *localdata)
871 {
872         int rc;
873         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
874                                                    * check */
875
876         ENTRY;
877
878         OBD_CHECK_DEV_ACTIVE(obd);
879         OBD_CHECK_DT_OP(obd, reconnect, 0);
880         OBD_COUNTER_INCREMENT(obd, reconnect);
881
882         rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
883         /* check that only subset is granted */
884         LASSERT(ergo(d != NULL,
885                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
886         RETURN(rc);
887 }
888
889 static inline int obd_disconnect(struct obd_export *exp)
890 {
891         int rc;
892         ENTRY;
893
894         EXP_CHECK_DT_OP(exp, disconnect);
895         EXP_COUNTER_INCREMENT(exp, disconnect);
896
897         rc = OBP(exp->exp_obd, disconnect)(exp);
898         RETURN(rc);
899 }
900
901 static inline int obd_fid_init(struct obd_export *exp)
902 {
903         int rc;
904         ENTRY;
905
906         OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
907         EXP_COUNTER_INCREMENT(exp, fid_init);
908
909         rc = OBP(exp->exp_obd, fid_init)(exp);
910         RETURN(rc);
911 }
912
913 static inline int obd_fid_fini(struct obd_export *exp)
914 {
915         int rc;
916         ENTRY;
917
918         OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
919         EXP_COUNTER_INCREMENT(exp, fid_fini);
920
921         rc = OBP(exp->exp_obd, fid_fini)(exp);
922         RETURN(rc);
923 }
924
925 static inline int obd_fid_alloc(struct obd_export *exp,
926                                 struct lu_fid *fid,
927                                 struct md_op_data *op_data)
928 {
929         int rc;
930         ENTRY;
931
932         EXP_CHECK_DT_OP(exp, fid_alloc);
933         EXP_COUNTER_INCREMENT(exp, fid_alloc);
934
935         rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
936         RETURN(rc);
937 }
938
939 static inline int obd_fid_delete(struct obd_export *exp,
940                                  const struct lu_fid *fid)
941 {
942         int rc;
943         ENTRY;
944
945         EXP_CHECK_DT_OP(exp, fid_delete);
946         EXP_COUNTER_INCREMENT(exp, fid_delete);
947
948         rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
949         RETURN(rc);
950 }
951
952 static inline int obd_ping(struct obd_export *exp)
953 {
954         int rc;
955         ENTRY;
956
957         OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
958         EXP_COUNTER_INCREMENT(exp, ping);
959
960         rc = OBP(exp->exp_obd, ping)(exp);
961         RETURN(rc);
962 }
963
964 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
965 {
966         int rc;
967         ENTRY;
968
969         OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
970         OBD_COUNTER_INCREMENT(obd, pool_new);
971
972         rc = OBP(obd, pool_new)(obd, poolname);
973         RETURN(rc);
974 }
975
976 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
977 {
978         int rc;
979         ENTRY;
980
981         OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
982         OBD_COUNTER_INCREMENT(obd, pool_del);
983
984         rc = OBP(obd, pool_del)(obd, poolname);
985         RETURN(rc);
986 }
987
988 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
989 {
990         int rc;
991         ENTRY;
992
993         OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
994         OBD_COUNTER_INCREMENT(obd, pool_add);
995
996         rc = OBP(obd, pool_add)(obd, poolname, ostname);
997         RETURN(rc);
998 }
999
1000 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1001 {
1002         int rc;
1003         ENTRY;
1004
1005         OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1006         OBD_COUNTER_INCREMENT(obd, pool_rem);
1007
1008         rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1009         RETURN(rc);
1010 }
1011
1012 static inline void obd_getref(struct obd_device *obd)
1013 {
1014         ENTRY;
1015         if (OBT(obd) && OBP(obd, getref)) {
1016                 OBD_COUNTER_INCREMENT(obd, getref);
1017                 OBP(obd, getref)(obd);
1018         }
1019         EXIT;
1020 }
1021
1022 static inline void obd_putref(struct obd_device *obd)
1023 {
1024         ENTRY;
1025         if (OBT(obd) && OBP(obd, putref)) {
1026                 OBD_COUNTER_INCREMENT(obd, putref);
1027                 OBP(obd, putref)(obd);
1028         }
1029         EXIT;
1030 }
1031
1032 static inline int obd_init_export(struct obd_export *exp)
1033 {
1034         int rc = 0;
1035
1036         ENTRY;
1037         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1038             OBP((exp)->exp_obd, init_export))
1039                 rc = OBP(exp->exp_obd, init_export)(exp);
1040         RETURN(rc);
1041 }
1042
1043 static inline int obd_destroy_export(struct obd_export *exp)
1044 {
1045         ENTRY;
1046         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1047             OBP((exp)->exp_obd, destroy_export))
1048                 OBP(exp->exp_obd, destroy_export)(exp);
1049         RETURN(0);
1050 }
1051
1052 static inline int obd_extent_calc(struct obd_export *exp,
1053                                   struct lov_stripe_md *md,
1054                                   int cmd, obd_off *offset)
1055 {
1056         int rc;
1057         ENTRY;
1058         EXP_CHECK_DT_OP(exp, extent_calc);
1059         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1060         RETURN(rc);
1061 }
1062
1063 static inline struct dentry *
1064 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1065 {
1066         LASSERT(exp->exp_obd);
1067
1068         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1069                                exp->exp_obd);
1070 }
1071
1072 static inline int
1073 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1074 {
1075         LASSERT(exp->exp_obd);
1076         CERROR("FIXME what's the story here?  This needs to be an obd fn?\n");
1077 #if 0
1078         return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1079                               dentry, exp->exp_obd);
1080 #endif
1081         return 0;
1082 }
1083
1084 #ifndef time_before
1085 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
1086 #endif
1087
1088 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1089  * If the cache is older than @max_age we will get a new value from the
1090  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1091 static inline int obd_statfs_async(struct obd_device *obd,
1092                                    struct obd_info *oinfo,
1093                                    __u64 max_age,
1094                                    struct ptlrpc_request_set *rqset)
1095 {
1096         int rc = 0;
1097         ENTRY;
1098
1099         if (obd == NULL)
1100                 RETURN(-EINVAL);
1101
1102         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1103         OBD_COUNTER_INCREMENT(obd, statfs);
1104
1105         CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1106                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1107         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1108                 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1109         } else {
1110                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1111                        " objects "LPU64"/"LPU64"\n",
1112                        obd->obd_name, &obd->obd_osfs,
1113                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1114                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1115                 spin_lock(&obd->obd_osfs_lock);
1116                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1117                 spin_unlock(&obd->obd_osfs_lock);
1118                 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1119                 if (oinfo->oi_cb_up)
1120                         oinfo->oi_cb_up(oinfo, 0);
1121         }
1122         RETURN(rc);
1123 }
1124
1125 static inline int obd_statfs_rqset(struct obd_device *obd,
1126                                    struct obd_statfs *osfs, __u64 max_age,
1127                                    __u32 flags)
1128 {
1129         struct ptlrpc_request_set *set = NULL;
1130         struct obd_info oinfo = { { { 0 } } };
1131         int rc = 0;
1132         ENTRY;
1133
1134         set =  ptlrpc_prep_set();
1135         if (set == NULL)
1136                 RETURN(-ENOMEM);
1137
1138         oinfo.oi_osfs = osfs;
1139         oinfo.oi_flags = flags;
1140         rc = obd_statfs_async(obd, &oinfo, max_age, set);
1141         if (rc == 0)
1142                 rc = ptlrpc_set_wait(set);
1143         ptlrpc_set_destroy(set);
1144         RETURN(rc);
1145 }
1146
1147 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1148  * If the cache is older than @max_age we will get a new value from the
1149  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1150 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1151                              __u64 max_age, __u32 flags)
1152 {
1153         int rc = 0;
1154         ENTRY;
1155
1156         if (obd == NULL)
1157                 RETURN(-EINVAL);
1158
1159         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1160         OBD_COUNTER_INCREMENT(obd, statfs);
1161
1162         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1163                obd->obd_osfs_age, max_age);
1164         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1165                 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1166                 if (rc == 0) {
1167                         spin_lock(&obd->obd_osfs_lock);
1168                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1169                         obd->obd_osfs_age = cfs_time_current_64();
1170                         spin_unlock(&obd->obd_osfs_lock);
1171                 }
1172         } else {
1173                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1174                        " objects "LPU64"/"LPU64"\n",
1175                        obd->obd_name, &obd->obd_osfs,
1176                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1177                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1178                 spin_lock(&obd->obd_osfs_lock);
1179                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1180                 spin_unlock(&obd->obd_osfs_lock);
1181         }
1182         RETURN(rc);
1183 }
1184
1185 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1186                            struct lov_stripe_md *ea, obd_size start,
1187                            obd_size end, void *capa)
1188 {
1189         int rc;
1190         ENTRY;
1191
1192         OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1193         EXP_COUNTER_INCREMENT(exp, sync);
1194
1195         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1196         RETURN(rc);
1197 }
1198
1199 static inline int obd_punch_rqset(struct obd_export *exp,
1200                                   struct obd_info *oinfo,
1201                                   struct obd_trans_info *oti)
1202 {
1203         struct ptlrpc_request_set *set = NULL;
1204         int rc;
1205         ENTRY;
1206
1207         EXP_CHECK_DT_OP(exp, punch);
1208         EXP_COUNTER_INCREMENT(exp, punch);
1209
1210         set =  ptlrpc_prep_set();
1211         if (set == NULL)
1212                 RETURN(-ENOMEM);
1213
1214         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1215         if (rc == 0)
1216                 rc = ptlrpc_set_wait(set);
1217         ptlrpc_set_destroy(set);
1218         RETURN(rc);
1219 }
1220
1221 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1222                             struct obd_trans_info *oti,
1223                             struct ptlrpc_request_set *rqset)
1224 {
1225         int rc;
1226         ENTRY;
1227
1228         EXP_CHECK_DT_OP(exp, punch);
1229         EXP_COUNTER_INCREMENT(exp, punch);
1230
1231         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1232         RETURN(rc);
1233 }
1234
1235 static inline int obd_brw(int cmd, struct obd_export *exp,
1236                           struct obd_info *oinfo, obd_count oa_bufs,
1237                           struct brw_page *pg, struct obd_trans_info *oti)
1238 {
1239         int rc;
1240         ENTRY;
1241
1242         EXP_CHECK_DT_OP(exp, brw);
1243         EXP_COUNTER_INCREMENT(exp, brw);
1244
1245         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1246                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1247                        "or OBD_BRW_CHECK\n");
1248                 LBUG();
1249         }
1250
1251         rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1252         RETURN(rc);
1253 }
1254
1255 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1256                              int objcount, struct obd_ioobj *obj,
1257                              struct niobuf_remote *remote, int *pages,
1258                              struct niobuf_local *local,
1259                              struct obd_trans_info *oti,
1260                              struct lustre_capa *capa)
1261 {
1262         int rc;
1263         ENTRY;
1264
1265         EXP_CHECK_DT_OP(exp, preprw);
1266         EXP_COUNTER_INCREMENT(exp, preprw);
1267
1268         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1269                                        pages, local, oti, capa);
1270         RETURN(rc);
1271 }
1272
1273 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1274                                int objcount, struct obd_ioobj *obj,
1275                                struct niobuf_remote *rnb, int pages,
1276                                struct niobuf_local *local,
1277                                struct obd_trans_info *oti, int rc)
1278 {
1279         ENTRY;
1280
1281         EXP_CHECK_DT_OP(exp, commitrw);
1282         EXP_COUNTER_INCREMENT(exp, commitrw);
1283
1284         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1285                                          rnb, pages, local, oti, rc);
1286         RETURN(rc);
1287 }
1288
1289 static inline int obd_merge_lvb(struct obd_export *exp,
1290                                 struct lov_stripe_md *lsm,
1291                                 struct ost_lvb *lvb, int kms_only)
1292 {
1293         int rc;
1294         ENTRY;
1295
1296         EXP_CHECK_DT_OP(exp, merge_lvb);
1297         EXP_COUNTER_INCREMENT(exp, merge_lvb);
1298
1299         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1300         RETURN(rc);
1301 }
1302
1303 static inline int obd_adjust_kms(struct obd_export *exp,
1304                                  struct lov_stripe_md *lsm, obd_off size,
1305                                  int shrink)
1306 {
1307         int rc;
1308         ENTRY;
1309
1310         EXP_CHECK_DT_OP(exp, adjust_kms);
1311         EXP_COUNTER_INCREMENT(exp, adjust_kms);
1312
1313         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1314         RETURN(rc);
1315 }
1316
1317 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1318                                 int len, void *karg, void *uarg)
1319 {
1320         int rc;
1321         ENTRY;
1322
1323         EXP_CHECK_DT_OP(exp, iocontrol);
1324         EXP_COUNTER_INCREMENT(exp, iocontrol);
1325
1326         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1327         RETURN(rc);
1328 }
1329
1330 static inline int obd_enqueue_rqset(struct obd_export *exp,
1331                                     struct obd_info *oinfo,
1332                                     struct ldlm_enqueue_info *einfo)
1333 {
1334         struct ptlrpc_request_set *set = NULL;
1335         int rc;
1336         ENTRY;
1337
1338         EXP_CHECK_DT_OP(exp, enqueue);
1339         EXP_COUNTER_INCREMENT(exp, enqueue);
1340
1341         set =  ptlrpc_prep_set();
1342         if (set == NULL)
1343                 RETURN(-ENOMEM);
1344
1345         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1346         if (rc == 0)
1347                 rc = ptlrpc_set_wait(set);
1348         ptlrpc_set_destroy(set);
1349         RETURN(rc);
1350 }
1351
1352 static inline int obd_enqueue(struct obd_export *exp,
1353                               struct obd_info *oinfo,
1354                               struct ldlm_enqueue_info *einfo,
1355                               struct ptlrpc_request_set *set)
1356 {
1357         int rc;
1358         ENTRY;
1359
1360         EXP_CHECK_DT_OP(exp, enqueue);
1361         EXP_COUNTER_INCREMENT(exp, enqueue);
1362
1363         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1364         RETURN(rc);
1365 }
1366
1367 static inline int obd_change_cbdata(struct obd_export *exp,
1368                                     struct lov_stripe_md *lsm,
1369                                     ldlm_iterator_t it, void *data)
1370 {
1371         int rc;
1372         ENTRY;
1373
1374         EXP_CHECK_DT_OP(exp, change_cbdata);
1375         EXP_COUNTER_INCREMENT(exp, change_cbdata);
1376
1377         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1378         RETURN(rc);
1379 }
1380
1381 static inline int obd_cancel(struct obd_export *exp,
1382                              struct lov_stripe_md *ea, __u32 mode,
1383                              struct lustre_handle *lockh)
1384 {
1385         int rc;
1386         ENTRY;
1387
1388         EXP_CHECK_DT_OP(exp, cancel);
1389         EXP_COUNTER_INCREMENT(exp, cancel);
1390
1391         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1392         RETURN(rc);
1393 }
1394
1395 static inline int obd_cancel_unused(struct obd_export *exp,
1396                                     struct lov_stripe_md *ea,
1397                                     int flags, void *opaque)
1398 {
1399         int rc;
1400         ENTRY;
1401
1402         EXP_CHECK_DT_OP(exp, cancel_unused);
1403         EXP_COUNTER_INCREMENT(exp, cancel_unused);
1404
1405         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1406         RETURN(rc);
1407 }
1408
1409 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1410                           struct obd_capa *oc, struct obd_client_handle *handle,
1411                           int flag)
1412 {
1413         int rc;
1414         ENTRY;
1415
1416         EXP_CHECK_DT_OP(exp, pin);
1417         EXP_COUNTER_INCREMENT(exp, pin);
1418
1419         rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1420         RETURN(rc);
1421 }
1422
1423 static inline int obd_unpin(struct obd_export *exp,
1424                             struct obd_client_handle *handle, int flag)
1425 {
1426         int rc;
1427         ENTRY;
1428
1429         EXP_CHECK_DT_OP(exp, unpin);
1430         EXP_COUNTER_INCREMENT(exp, unpin);
1431
1432         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1433         RETURN(rc);
1434 }
1435
1436
1437 static inline void obd_import_event(struct obd_device *obd,
1438                                     struct obd_import *imp,
1439                                     enum obd_import_event event)
1440 {
1441         ENTRY;
1442         if (!obd) {
1443                 CERROR("NULL device\n");
1444                 EXIT;
1445                 return;
1446         }
1447         if (obd->obd_set_up && OBP(obd, import_event)) {
1448                 OBD_COUNTER_INCREMENT(obd, import_event);
1449                 OBP(obd, import_event)(obd, imp, event);
1450         }
1451         EXIT;
1452 }
1453
1454 static inline int obd_llog_connect(struct obd_export *exp,
1455                                    struct llogd_conn_body *body)
1456 {
1457         int rc;
1458         ENTRY;
1459
1460         OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1461         EXP_COUNTER_INCREMENT(exp, llog_connect);
1462
1463         rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1464         RETURN(rc);
1465 }
1466
1467
1468 static inline int obd_notify(struct obd_device *obd,
1469                              struct obd_device *watched,
1470                              enum obd_notify_event ev,
1471                              void *data)
1472 {
1473         int rc;
1474         ENTRY;
1475         OBD_CHECK_DEV(obd);
1476
1477         /* the check for async_recov is a complete hack - I'm hereby
1478            overloading the meaning to also mean "this was called from
1479            mds_postsetup".  I know that my mds is able to handle notifies
1480            by this point, and it needs to get them to execute mds_postrecov. */
1481         if (!obd->obd_set_up && !obd->obd_async_recov) {
1482                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1483                 RETURN(-EINVAL);
1484         }
1485
1486         if (!OBP(obd, notify)) {
1487                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1488                 RETURN(-ENOSYS);
1489         }
1490
1491         OBD_COUNTER_INCREMENT(obd, notify);
1492         rc = OBP(obd, notify)(obd, watched, ev, data);
1493         RETURN(rc);
1494 }
1495
1496 static inline int obd_notify_observer(struct obd_device *observer,
1497                                       struct obd_device *observed,
1498                                       enum obd_notify_event ev,
1499                                       void *data)
1500 {
1501         int rc1;
1502         int rc2;
1503
1504         struct obd_notify_upcall *onu;
1505
1506         if (observer->obd_observer)
1507                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1508         else
1509                 rc1 = 0;
1510         /*
1511          * Also, call non-obd listener, if any
1512          */
1513         onu = &observer->obd_upcall;
1514         if (onu->onu_upcall != NULL)
1515                 rc2 = onu->onu_upcall(observer, observed, ev,
1516                                       onu->onu_owner, NULL);
1517         else
1518                 rc2 = 0;
1519
1520         return rc1 ? rc1 : rc2;
1521 }
1522
1523 static inline int obd_quotacheck(struct obd_export *exp,
1524                                  struct obd_quotactl *oqctl)
1525 {
1526         int rc;
1527         ENTRY;
1528
1529         EXP_CHECK_DT_OP(exp, quotacheck);
1530         EXP_COUNTER_INCREMENT(exp, quotacheck);
1531
1532         rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1533         RETURN(rc);
1534 }
1535
1536 static inline int obd_quotactl(struct obd_export *exp,
1537                                struct obd_quotactl *oqctl)
1538 {
1539         int rc;
1540         ENTRY;
1541
1542         EXP_CHECK_DT_OP(exp, quotactl);
1543         EXP_COUNTER_INCREMENT(exp, quotactl);
1544
1545         rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1546         RETURN(rc);
1547 }
1548
1549 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1550                                          struct quota_adjust_qunit *oqaq,
1551                                          struct lustre_quota_ctxt *qctxt)
1552 {
1553 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1554         struct timeval work_start;
1555         struct timeval work_end;
1556         long timediff;
1557 #endif
1558         int rc;
1559         ENTRY;
1560
1561 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1562         if (qctxt)
1563                 do_gettimeofday(&work_start);
1564 #endif
1565         EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1566         EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1567
1568         rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1569
1570 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1571         if (qctxt) {
1572                 do_gettimeofday(&work_end);
1573                 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1574                 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1575                                     timediff);
1576         }
1577 #endif
1578         RETURN(rc);
1579 }
1580
1581 static inline int obd_health_check(struct obd_device *obd)
1582 {
1583         /* returns: 0 on healthy
1584          *         >0 on unhealthy + reason code/flag
1585          *            however the only suppored reason == 1 right now
1586          *            We'll need to define some better reasons
1587          *            or flags in the future.
1588          *         <0 on error
1589          */
1590         int rc;
1591         ENTRY;
1592
1593         /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1594         if (obd == NULL || !OBT(obd)) {
1595                 CERROR("cleaned up obd\n");
1596                 RETURN(-EOPNOTSUPP);
1597         }
1598         if (!obd->obd_set_up || obd->obd_stopping)
1599                 RETURN(0);
1600         if (!OBP(obd, health_check))
1601                 RETURN(0);
1602
1603         rc = OBP(obd, health_check)(obd);
1604         RETURN(rc);
1605 }
1606
1607 static inline int obd_register_observer(struct obd_device *obd,
1608                                         struct obd_device *observer)
1609 {
1610         ENTRY;
1611         OBD_CHECK_DEV(obd);
1612         if (obd->obd_observer && observer)
1613                 RETURN(-EALREADY);
1614         obd->obd_observer = observer;
1615         RETURN(0);
1616 }
1617
1618 #if 0
1619 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1620                                                obd_page_removal_cb_t cb,
1621                                                obd_pin_extent_cb pin_cb)
1622 {
1623         int rc;
1624         ENTRY;
1625
1626         OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1627         OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1628
1629         rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1630         RETURN(rc);
1631 }
1632
1633 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1634                                                  obd_page_removal_cb_t cb)
1635 {
1636         int rc;
1637         ENTRY;
1638
1639         OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1640         OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1641
1642         rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1643         RETURN(rc);
1644 }
1645
1646 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1647                                               obd_lock_cancel_cb cb)
1648 {
1649         int rc;
1650         ENTRY;
1651
1652         OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1653         OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1654
1655         rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1656         RETURN(rc);
1657 }
1658
1659 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1660                                                  obd_lock_cancel_cb cb)
1661 {
1662         int rc;
1663         ENTRY;
1664
1665         OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1666         OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1667
1668         rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1669         RETURN(rc);
1670 }
1671 #endif
1672
1673 /* metadata helpers */
1674 static inline int md_getstatus(struct obd_export *exp,
1675                                struct lu_fid *fid, struct obd_capa **pc)
1676 {
1677         int rc;
1678         ENTRY;
1679
1680         EXP_CHECK_MD_OP(exp, getstatus);
1681         EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1682         rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1683         RETURN(rc);
1684 }
1685
1686 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1687                              struct obd_capa *oc, obd_valid valid, int ea_size,
1688                              struct ptlrpc_request **request)
1689 {
1690         int rc;
1691         ENTRY;
1692         EXP_CHECK_MD_OP(exp, getattr);
1693         EXP_MD_COUNTER_INCREMENT(exp, getattr);
1694         rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1695                                         ea_size, request);
1696         RETURN(rc);
1697 }
1698
1699 static inline int md_change_cbdata(struct obd_export *exp,
1700                                    const struct lu_fid *fid,
1701                                    ldlm_iterator_t it, void *data)
1702 {
1703         int rc;
1704         ENTRY;
1705         EXP_CHECK_MD_OP(exp, change_cbdata);
1706         EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1707         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1708         RETURN(rc);
1709 }
1710
1711 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1712                            struct md_open_data *mod,
1713                            struct ptlrpc_request **request)
1714 {
1715         int rc;
1716         ENTRY;
1717         EXP_CHECK_MD_OP(exp, close);
1718         EXP_MD_COUNTER_INCREMENT(exp, close);
1719         rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1720         RETURN(rc);
1721 }
1722
1723 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1724                             const void *data, int datalen, int mode, __u32 uid,
1725                             __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1726                             struct ptlrpc_request **request)
1727 {
1728         int rc;
1729         ENTRY;
1730         EXP_CHECK_MD_OP(exp, create);
1731         EXP_MD_COUNTER_INCREMENT(exp, create);
1732         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1733                                        uid, gid, cap_effective, rdev, request);
1734         RETURN(rc);
1735 }
1736
1737 static inline int md_done_writing(struct obd_export *exp,
1738                                   struct md_op_data *op_data,
1739                                   struct md_open_data *mod)
1740 {
1741         int rc;
1742         ENTRY;
1743         EXP_CHECK_MD_OP(exp, done_writing);
1744         EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1745         rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1746         RETURN(rc);
1747 }
1748
1749 static inline int md_enqueue(struct obd_export *exp,
1750                              struct ldlm_enqueue_info *einfo,
1751                              struct lookup_intent *it,
1752                              struct md_op_data *op_data,
1753                              struct lustre_handle *lockh,
1754                              void *lmm, int lmmsize,
1755                              struct ptlrpc_request **req,
1756                              int extra_lock_flags)
1757 {
1758         int rc;
1759         ENTRY;
1760         EXP_CHECK_MD_OP(exp, enqueue);
1761         EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1762         rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1763                                         lmm, lmmsize, req, extra_lock_flags);
1764         RETURN(rc);
1765 }
1766
1767 static inline int md_getattr_name(struct obd_export *exp,
1768                                   const struct lu_fid *fid, struct obd_capa *oc,
1769                                   const char *name, int namelen,
1770                                   obd_valid valid, int ea_size, __u32 suppgid,
1771                                   struct ptlrpc_request **request)
1772 {
1773         int rc;
1774         ENTRY;
1775         EXP_CHECK_MD_OP(exp, getattr_name);
1776         EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1777         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1778                                              valid, ea_size, suppgid, request);
1779         RETURN(rc);
1780 }
1781
1782 static inline int md_intent_lock(struct obd_export *exp,
1783                                  struct md_op_data *op_data, void *lmm,
1784                                  int lmmsize, struct lookup_intent *it,
1785                                  int flags, struct ptlrpc_request **reqp,
1786                                  ldlm_blocking_callback cb_blocking,
1787                                  int extra_lock_flags)
1788 {
1789         int rc;
1790         ENTRY;
1791         EXP_CHECK_MD_OP(exp, intent_lock);
1792         EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1793         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1794                                             it, flags, reqp, cb_blocking,
1795                                             extra_lock_flags);
1796         RETURN(rc);
1797 }
1798
1799 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1800                           struct ptlrpc_request **request)
1801 {
1802         int rc;
1803         ENTRY;
1804         EXP_CHECK_MD_OP(exp, link);
1805         EXP_MD_COUNTER_INCREMENT(exp, link);
1806         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1807         RETURN(rc);
1808 }
1809
1810 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1811                             const char *old, int oldlen, const char *new,
1812                             int newlen, struct ptlrpc_request **request)
1813 {
1814         int rc;
1815         ENTRY;
1816         EXP_CHECK_MD_OP(exp, rename);
1817         EXP_MD_COUNTER_INCREMENT(exp, rename);
1818         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1819                                        newlen, request);
1820         RETURN(rc);
1821 }
1822
1823 static inline int md_is_subdir(struct obd_export *exp,
1824                                const struct lu_fid *pfid,
1825                                const struct lu_fid *cfid,
1826                                struct ptlrpc_request **request)
1827 {
1828         int rc;
1829         ENTRY;
1830         EXP_CHECK_MD_OP(exp, is_subdir);
1831         EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1832         rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1833         RETURN(rc);
1834 }
1835
1836 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1837                              void *ea, int ealen, void *ea2, int ea2len,
1838                              struct ptlrpc_request **request,
1839                              struct md_open_data **mod)
1840 {
1841         int rc;
1842         ENTRY;
1843         EXP_CHECK_MD_OP(exp, setattr);
1844         EXP_MD_COUNTER_INCREMENT(exp, setattr);
1845         rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1846                                         ea2, ea2len, request, mod);
1847         RETURN(rc);
1848 }
1849
1850 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1851                           struct obd_capa *oc, struct ptlrpc_request **request)
1852 {
1853         int rc;
1854         ENTRY;
1855         EXP_CHECK_MD_OP(exp, sync);
1856         EXP_MD_COUNTER_INCREMENT(exp, sync);
1857         rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1858         RETURN(rc);
1859 }
1860
1861 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1862                               struct obd_capa *oc, __u64 offset,
1863                               struct page *page,
1864                               struct ptlrpc_request **request)
1865 {
1866         int rc;
1867         ENTRY;
1868         EXP_CHECK_MD_OP(exp, readpage);
1869         EXP_MD_COUNTER_INCREMENT(exp, readpage);
1870         rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1871         RETURN(rc);
1872 }
1873
1874 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1875                             struct ptlrpc_request **request)
1876 {
1877         int rc;
1878         ENTRY;
1879         EXP_CHECK_MD_OP(exp, unlink);
1880         EXP_MD_COUNTER_INCREMENT(exp, unlink);
1881         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1882         RETURN(rc);
1883 }
1884
1885 static inline int md_get_lustre_md(struct obd_export *exp,
1886                                    struct ptlrpc_request *req,
1887                                    struct obd_export *dt_exp,
1888                                    struct obd_export *md_exp,
1889                                    struct lustre_md *md)
1890 {
1891         ENTRY;
1892         EXP_CHECK_MD_OP(exp, get_lustre_md);
1893         EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1894         RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1895 }
1896
1897 static inline int md_free_lustre_md(struct obd_export *exp,
1898                                     struct lustre_md *md)
1899 {
1900         ENTRY;
1901         EXP_CHECK_MD_OP(exp, free_lustre_md);
1902         EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1903         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1904 }
1905
1906 static inline int md_setxattr(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, __u32 suppgid,
1911                               struct ptlrpc_request **request)
1912 {
1913         ENTRY;
1914         EXP_CHECK_MD_OP(exp, setxattr);
1915         EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1916         RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1917                                            input_size, output_size, flags,
1918                                            suppgid, request));
1919 }
1920
1921 static inline int md_getxattr(struct obd_export *exp,
1922                               const struct lu_fid *fid, struct obd_capa *oc,
1923                               obd_valid valid, const char *name,
1924                               const char *input, int input_size,
1925                               int output_size, int flags,
1926                               struct ptlrpc_request **request)
1927 {
1928         ENTRY;
1929         EXP_CHECK_MD_OP(exp, getxattr);
1930         EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1931         RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1932                                            input_size, output_size, flags,
1933                                            request));
1934 }
1935
1936 static inline int md_set_open_replay_data(struct obd_export *exp,
1937                                           struct obd_client_handle *och,
1938                                           struct ptlrpc_request *open_req)
1939 {
1940         ENTRY;
1941         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1942         EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1943         RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1944 }
1945
1946 static inline int md_clear_open_replay_data(struct obd_export *exp,
1947                                             struct obd_client_handle *och)
1948 {
1949         ENTRY;
1950         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1951         EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1952         RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1953 }
1954
1955 static inline int md_set_lock_data(struct obd_export *exp,
1956                                    __u64 *lockh, void *data)
1957 {
1958         ENTRY;
1959         EXP_CHECK_MD_OP(exp, set_lock_data);
1960         EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1961         RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1962 }
1963
1964 static inline int md_cancel_unused(struct obd_export *exp,
1965                                    const struct lu_fid *fid,
1966                                    ldlm_policy_data_t *policy,
1967                                    ldlm_mode_t mode, int flags, void *opaque)
1968 {
1969         int rc;
1970         ENTRY;
1971
1972         EXP_CHECK_MD_OP(exp, cancel_unused);
1973         EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1974
1975         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1976                                               flags, opaque);
1977         RETURN(rc);
1978 }
1979
1980 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
1981                                         const struct lu_fid *fid,
1982                                         ldlm_type_t type,
1983                                         ldlm_policy_data_t *policy,
1984                                         ldlm_mode_t mode,
1985                                         struct lustre_handle *lockh)
1986 {
1987         ENTRY;
1988         EXP_CHECK_MD_OP(exp, lock_match);
1989         EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1990         RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1991                                              policy, mode, lockh));
1992 }
1993
1994 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1995                                   int def_asize, int cookiesize)
1996 {
1997         ENTRY;
1998         EXP_CHECK_MD_OP(exp, init_ea_size);
1999         EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2000         RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2001                                                cookiesize));
2002 }
2003
2004 static inline int md_get_remote_perm(struct obd_export *exp,
2005                                      const struct lu_fid *fid,
2006                                      struct obd_capa *oc, __u32 suppgid,
2007                                      struct ptlrpc_request **request)
2008 {
2009         ENTRY;
2010         EXP_CHECK_MD_OP(exp, get_remote_perm);
2011         EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2012         RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2013                                                   request));
2014 }
2015
2016 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2017                                 renew_capa_cb_t cb)
2018 {
2019         int rc;
2020         ENTRY;
2021         EXP_CHECK_MD_OP(exp, renew_capa);
2022         EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2023         rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2024         RETURN(rc);
2025 }
2026
2027 static inline int md_unpack_capa(struct obd_export *exp,
2028                                  struct ptlrpc_request *req,
2029                                  const struct req_msg_field *field,
2030                                  struct obd_capa **oc)
2031 {
2032         int rc;
2033         ENTRY;
2034         EXP_CHECK_MD_OP(exp, unpack_capa);
2035         EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2036         rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2037         RETURN(rc);
2038 }
2039
2040 static inline int md_intent_getattr_async(struct obd_export *exp,
2041                                           struct md_enqueue_info *minfo,
2042                                           struct ldlm_enqueue_info *einfo)
2043 {
2044         int rc;
2045         ENTRY;
2046         EXP_CHECK_MD_OP(exp, intent_getattr_async);
2047         EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2048         rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2049         RETURN(rc);
2050 }
2051
2052 static inline int md_revalidate_lock(struct obd_export *exp,
2053                                      struct lookup_intent *it,
2054                                      struct lu_fid *fid)
2055 {
2056         int rc;
2057         ENTRY;
2058         EXP_CHECK_MD_OP(exp, revalidate_lock);
2059         EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2060         rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2061         RETURN(rc);
2062 }
2063
2064
2065 /* OBD Metadata Support */
2066
2067 extern int obd_init_caches(void);
2068 extern void obd_cleanup_caches(void);
2069
2070 /* support routines */
2071 extern cfs_mem_cache_t *obdo_cachep;
2072
2073 #define OBDO_ALLOC(ptr)                                                       \
2074 do {                                                                          \
2075         OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep);                               \
2076 } while(0)
2077
2078 #define OBDO_FREE(ptr)                                                        \
2079 do {                                                                          \
2080         OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
2081 } while(0)
2082
2083
2084 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2085 {
2086         /* something here */
2087 }
2088
2089 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2090 {
2091         /* something here */
2092 }
2093
2094 /* I'm as embarrassed about this as you are.
2095  *
2096  * <shaver> // XXX do not look into _superhack with remaining eye
2097  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2098 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2099
2100 /* sysctl.c */
2101 extern void obd_sysctl_init (void);
2102 extern void obd_sysctl_clean (void);
2103
2104 /* uuid.c  */
2105 typedef __u8 class_uuid_t[16];
2106 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2107
2108 /* lustre_peer.c    */
2109 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2110 int class_add_uuid(const char *uuid, __u64 nid);
2111 int class_del_uuid (const char *uuid);
2112 void class_init_uuidlist(void);
2113 void class_exit_uuidlist(void);
2114
2115 /* mea.c */
2116 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2117 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2118
2119 /* prng.c */
2120 void ll_generate_random_uuid(class_uuid_t uuid_out);
2121
2122 #endif /* __LINUX_OBD_CLASS_H */