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