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