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