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