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