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