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