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