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