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