Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / include / obd_class.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #ifndef __CLASS_OBD_H
37 #define __CLASS_OBD_H
38
39 #ifndef __KERNEL__
40 # include <liblustre.h>
41 #endif
42
43 #include <obd_support.h>
44 #include <lustre_import.h>
45 #include <lustre_net.h>
46 #include <obd.h>
47 #include <lustre_lib.h>
48 #include <lustre/lustre_idl.h>
49 #include <lprocfs_status.h>
50
51 #if defined(__linux__)
52 #include <linux/obd_class.h>
53 #elif defined(__APPLE__)
54 #include <darwin/obd_class.h>
55 #elif defined(__WINNT__)
56 #include <winnt/obd_class.h>
57 #else
58 #error Unsupported operating system.
59 #endif
60
61 /* OBD Device Declarations */
62 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
63 extern spinlock_t obd_dev_lock;
64
65 /* OBD Operations Declarations */
66 extern struct obd_device *class_conn2obd(struct lustre_handle *);
67 extern struct obd_device *class_exp2obd(struct obd_export *);
68
69 struct lu_device_type;
70
71 /* genops.c */
72 struct obd_export *class_conn2export(struct lustre_handle *);
73 int class_register_type(struct obd_ops *, struct md_ops *,
74                         struct lprocfs_vars *, const char *nm,
75                         struct lu_device_type *ldt);
76 int class_unregister_type(const char *nm);
77
78 struct obd_device *class_newdev(const char *type_name, const char *name);
79 void class_release_dev(struct obd_device *obd);
80
81 int class_name2dev(const char *name);
82 struct obd_device *class_name2obd(const char *name);
83 int class_uuid2dev(struct obd_uuid *uuid);
84 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
85 void class_obd_list(void);
86 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
87                                           const char * typ_name,
88                                           struct obd_uuid *grp_uuid);
89 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
90                                            int *next);
91 struct obd_device * class_num2obd(int num);
92
93 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
94
95 char *obd_export_nid2str(struct obd_export *exp);
96
97 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
98 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
99
100 int obd_zombie_impexp_init(void);
101 void obd_zombie_impexp_stop(void);
102 void obd_zombie_impexp_cull(void);
103 void obd_zombie_barrier(void);
104 void obd_exports_barrier(struct obd_device *obd);
105
106 /* obd_config.c */
107 int class_process_config(struct lustre_cfg *lcfg);
108 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
109                              struct lustre_cfg *lcfg, void *data);
110 int class_attach(struct lustre_cfg *lcfg);
111 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
112 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
113 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
114 struct obd_device *class_incref(struct obd_device *obd,
115                                 const char *scope, const void *source);
116 void class_decref(struct obd_device *obd,
117                   const char *scope, const void *source);
118 void dump_exports(struct obd_device *obd);
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 #define class_export_rpc_get(exp)                                       \
176 ({                                                                      \
177         atomic_inc(&(exp)->exp_rpc_count);                              \
178         CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",    \
179                (exp), atomic_read(&(exp)->exp_rpc_count));              \
180         class_export_get(exp);                                          \
181 })
182
183 #define class_export_rpc_put(exp)                                       \
184 ({                                                                      \
185         LASSERT(atomic_read(&exp->exp_rpc_count) > 0);                  \
186         atomic_dec(&(exp)->exp_rpc_count);                              \
187         CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",    \
188                (exp), atomic_read(&(exp)->exp_rpc_count));              \
189         class_export_put(exp);                                          \
190 })
191
192 #define class_export_lock_get(exp)                                      \
193 ({                                                                      \
194         atomic_inc(&(exp)->exp_locks_count);                            \
195         CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
196                (exp), atomic_read(&(exp)->exp_locks_count));            \
197         class_export_get(exp);                                          \
198 })
199
200 #define class_export_lock_put(exp)                                      \
201 ({                                                                      \
202         LASSERT(atomic_read(&exp->exp_locks_count) > 0);                \
203         atomic_dec(&(exp)->exp_locks_count);                            \
204         CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
205                (exp), atomic_read(&(exp)->exp_locks_count));            \
206         class_export_put(exp);                                          \
207 })
208
209 #define class_export_cb_get(exp)                                        \
210 ({                                                                      \
211         atomic_inc(&(exp)->exp_cb_count);                               \
212         CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
213                (exp), atomic_read(&(exp)->exp_cb_count));               \
214         class_export_get(exp);                                          \
215 })
216
217 #define class_export_cb_put(exp)                                        \
218 ({                                                                      \
219         LASSERT(atomic_read(&exp->exp_cb_count) > 0);                   \
220         atomic_dec(&(exp)->exp_cb_count);                               \
221         CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
222                (exp), atomic_read(&(exp)->exp_cb_count));               \
223         class_export_put(exp);                                          \
224 })
225
226 /* genops.c */
227 struct obd_export *class_export_get(struct obd_export *exp);
228 void class_export_put(struct obd_export *exp);
229 struct obd_export *class_new_export(struct obd_device *obddev,
230                                     struct obd_uuid *cluuid);
231 void class_unlink_export(struct obd_export *exp);
232
233 struct obd_import *class_import_get(struct obd_import *);
234 void class_import_put(struct obd_import *);
235 struct obd_import *class_new_import(struct obd_device *obd);
236 void class_destroy_import(struct obd_import *exp);
237
238 struct obd_type *class_search_type(const char *name);
239 struct obd_type *class_get_type(const char *name);
240 void class_put_type(struct obd_type *type);
241 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
242                   struct obd_uuid *cluuid);
243 int class_disconnect(struct obd_export *exp);
244 void class_fail_export(struct obd_export *exp);
245 void class_disconnect_exports(struct obd_device *obddev);
246 int class_manual_cleanup(struct obd_device *obd);
247 void class_disconnect_stale_exports(struct obd_device *,
248                                     int (*test_export)(struct obd_export *));
249 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
250 {
251         return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
252                 (obd->obd_force ? OBD_OPT_FORCE : 0) |
253                 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
254                 0);
255 }
256
257 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
258 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
259 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
260                      unsigned int ia_valid);
261 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
262 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
263 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
264                   unsigned int valid);
265
266 #define OBT(dev)        (dev)->obd_type
267 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
268 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
269 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
270
271 /* Ensure obd_setup: used for cleanup which must be called
272    while obd is stopping */
273 #define OBD_CHECK_DEV(obd)                                      \
274 do {                                                            \
275         if (!(obd)) {                                           \
276                 CERROR("NULL device\n");                        \
277                 RETURN(-ENODEV);                                \
278         }                                                       \
279 } while (0)
280
281 /* ensure obd_setup and !obd_stopping */
282 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
283 do {                                                            \
284         OBD_CHECK_DEV(obd);                                     \
285         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
286                 CERROR("Device %d not setup\n",                 \
287                        (obd)->obd_minor);                       \
288                 RETURN(-ENODEV);                                \
289         }                                                       \
290 } while (0)
291
292
293 #ifdef LPROCFS
294 #define OBD_COUNTER_OFFSET(op)                                  \
295         ((offsetof(struct obd_ops, o_ ## op) -                  \
296           offsetof(struct obd_ops, o_iocontrol))                \
297          / sizeof(((struct obd_ops *)(0))->o_iocontrol))
298
299 #define OBD_COUNTER_INCREMENT(obdx, op)                           \
300         if ((obdx)->obd_stats != NULL) {                          \
301                 unsigned int coffset;                             \
302                 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
303                         OBD_COUNTER_OFFSET(op);                   \
304                 LASSERT(coffset < (obdx)->obd_stats->ls_num);     \
305                 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
306         }
307
308 #define EXP_COUNTER_INCREMENT(export, op)                                    \
309         if ((export)->exp_obd->obd_stats != NULL) {                          \
310                 unsigned int coffset;                                        \
311                 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
312                         OBD_COUNTER_OFFSET(op);                              \
313                 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num);     \
314                 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
315                 if ((export)->exp_nid_stats != NULL &&                       \
316                     (export)->exp_nid_stats->nid_stats != NULL)              \
317                         lprocfs_counter_incr(                                \
318                                 (export)->exp_nid_stats->nid_stats, coffset);\
319         }
320
321 #define MD_COUNTER_OFFSET(op)                                   \
322         ((offsetof(struct md_ops, m_ ## op) -                   \
323           offsetof(struct md_ops, m_getstatus))                 \
324          / sizeof(((struct md_ops *)(0))->m_getstatus))
325
326 #define MD_COUNTER_INCREMENT(obdx, op)                           \
327         if ((obd)->md_stats != NULL) {                           \
328                 unsigned int coffset;                            \
329                 coffset = (unsigned int)((obdx)->md_cntr_base) + \
330                         MD_COUNTER_OFFSET(op);                   \
331                 LASSERT(coffset < (obdx)->md_stats->ls_num);     \
332                 lprocfs_counter_incr((obdx)->md_stats, coffset); \
333         }
334
335 #define EXP_MD_COUNTER_INCREMENT(export, op)                                 \
336         if ((export)->exp_obd->obd_stats != NULL) {                          \
337                 unsigned int coffset;                                        \
338                 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) +  \
339                         MD_COUNTER_OFFSET(op);                               \
340                 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num);      \
341                 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset);  \
342                 if ((export)->exp_md_stats != NULL)                          \
343                         lprocfs_counter_incr(                                \
344                                 (export)->exp_md_stats, coffset);            \
345         }
346
347 #else
348 #define OBD_COUNTER_OFFSET(op)
349 #define OBD_COUNTER_INCREMENT(obd, op)
350 #define EXP_COUNTER_INCREMENT(exp, op)
351 #define MD_COUNTER_INCREMENT(obd, op)
352 #define EXP_MD_COUNTER_INCREMENT(exp, op)
353 #endif
354
355 #define OBD_CHECK_MD_OP(obd, op, err)                           \
356 do {                                                            \
357         if (!OBT(obd) || !MDP((obd), op)) {                     \
358                 if (err)                                        \
359                         CERROR("md_" #op ": dev %s/%d no operation\n", \
360                                obd->obd_name, obd->obd_minor);  \
361                 RETURN(err);                                    \
362         }                                                       \
363 } while (0)
364
365 #define EXP_CHECK_MD_OP(exp, op)                                \
366 do {                                                            \
367         if ((exp) == NULL) {                                    \
368                 CERROR("obd_" #op ": NULL export\n");           \
369                 RETURN(-ENODEV);                                \
370         }                                                       \
371         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
372                 CERROR("obd_" #op ": cleaned up obd\n");        \
373                 RETURN(-EOPNOTSUPP);                            \
374         }                                                       \
375         if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
376                 CERROR("obd_" #op ": dev %s/%d no operation\n", \
377                        (exp)->exp_obd->obd_name,                \
378                        (exp)->exp_obd->obd_minor);              \
379                 RETURN(-EOPNOTSUPP);                            \
380         }                                                       \
381 } while (0)
382
383
384 #define OBD_CHECK_DT_OP(obd, op, err)                           \
385 do {                                                            \
386         if (!OBT(obd) || !OBP((obd), op)) {                     \
387                 if (err)                                        \
388                         CERROR("obd_" #op ": dev %d no operation\n",    \
389                                obd->obd_minor);                 \
390                 RETURN(err);                                    \
391         }                                                       \
392 } while (0)
393
394 #define EXP_CHECK_DT_OP(exp, op)                                \
395 do {                                                            \
396         if ((exp) == NULL) {                                    \
397                 CERROR("obd_" #op ": NULL export\n");           \
398                 RETURN(-ENODEV);                                \
399         }                                                       \
400         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
401                 CERROR("obd_" #op ": cleaned up obd\n");        \
402                 RETURN(-EOPNOTSUPP);                            \
403         }                                                       \
404         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
405                 CERROR("obd_" #op ": dev %d no operation\n",    \
406                        (exp)->exp_obd->obd_minor);              \
407                 RETURN(-EOPNOTSUPP);                            \
408         }                                                       \
409 } while (0)
410
411 #define CTXT_CHECK_OP(ctxt, op, err)                                 \
412 do {                                                                 \
413         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {             \
414                 if (err)                                             \
415                         CERROR("lop_" #op ": dev %d no operation\n", \
416                                ctxt->loc_obd->obd_minor);            \
417                 RETURN(err);                                         \
418         }                                                            \
419 } while (0)
420
421 static inline int class_devno_max(void)
422 {
423         return MAX_OBD_DEVICES;
424 }
425
426 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
427                                void *key, __u32 *vallen, void *val,
428                                struct lov_stripe_md *lsm)
429 {
430         int rc;
431         ENTRY;
432
433         EXP_CHECK_DT_OP(exp, get_info);
434         EXP_COUNTER_INCREMENT(exp, get_info);
435
436         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
437         RETURN(rc);
438 }
439
440 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
441                                      void *key, obd_count vallen, void *val,
442                                      struct ptlrpc_request_set *set)
443 {
444         int rc;
445         ENTRY;
446
447         EXP_CHECK_DT_OP(exp, set_info_async);
448         EXP_COUNTER_INCREMENT(exp, set_info_async);
449
450         rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
451                                                set);
452         RETURN(rc);
453 }
454
455 /*
456  * obd-lu integration.
457  *
458  * Functionality is being moved into new lu_device-based layering, but some
459  * pieces of configuration process are still based on obd devices.
460  *
461  * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
462  * subsume ->o_setup() methods of obd devices they replace. The same for
463  * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
464  * result, obd_setup() and obd_process_config() branch and call one XOR
465  * another.
466  *
467  * Yet neither lu_device_type_operations::ldto_device_fini() nor
468  * lu_device_type_operations::ldto_device_free() fully implement the
469  * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
470  * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
471  */
472
473 #define DECLARE_LU_VARS(ldt, d)                 \
474         struct lu_device_type *ldt;       \
475         struct lu_device *d
476
477 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
478 {
479         int rc;
480         DECLARE_LU_VARS(ldt, d);
481         ENTRY;
482
483         ldt = obd->obd_type->typ_lu;
484         if (ldt != NULL) {
485                 struct lu_context  session_ctx;
486                 struct lu_env env;
487                 lu_context_init(&session_ctx, LCT_SESSION);
488                 session_ctx.lc_thread = NULL;
489                 lu_context_enter(&session_ctx);
490
491                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
492                 if (rc == 0) {
493                         env.le_ses = &session_ctx;
494                         d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
495                         lu_env_fini(&env);
496                         if (!IS_ERR(d)) {
497                                 obd->obd_lu_dev = d;
498                                 d->ld_obd = obd;
499                                 rc = 0;
500                         } else
501                                 rc = PTR_ERR(d);
502                 }
503                 lu_context_exit(&session_ctx);
504                 lu_context_fini(&session_ctx);
505
506         } else {
507                 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
508                 OBD_COUNTER_INCREMENT(obd, setup);
509                 rc = OBP(obd, setup)(obd, cfg);
510         }
511         RETURN(rc);
512 }
513
514 static inline int obd_precleanup(struct obd_device *obd,
515                                  enum obd_cleanup_stage cleanup_stage)
516 {
517         int rc;
518         DECLARE_LU_VARS(ldt, d);
519         ENTRY;
520
521         OBD_CHECK_DEV(obd);
522         ldt = obd->obd_type->typ_lu;
523         d = obd->obd_lu_dev;
524         if (ldt != NULL && d != NULL) {
525                 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
526                         struct lu_env env;
527
528                         rc = lu_env_init(&env, ldt->ldt_ctx_tags);
529                         if (rc == 0) {
530                                 ldt->ldt_ops->ldto_device_fini(&env, d);
531                                 lu_env_fini(&env);
532                         }
533                 }
534         }
535         OBD_CHECK_DT_OP(obd, precleanup, 0);
536         OBD_COUNTER_INCREMENT(obd, precleanup);
537
538         rc = OBP(obd, precleanup)(obd, cleanup_stage);
539         RETURN(rc);
540 }
541
542 static inline int obd_cleanup(struct obd_device *obd)
543 {
544         int rc;
545         DECLARE_LU_VARS(ldt, d);
546         ENTRY;
547
548         OBD_CHECK_DEV(obd);
549
550         ldt = obd->obd_type->typ_lu;
551         d = obd->obd_lu_dev;
552         if (ldt != NULL && d != NULL) {
553                 struct lu_env env;
554
555                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
556                 if (rc == 0) {
557                         ldt->ldt_ops->ldto_device_free(&env, d);
558                         lu_env_fini(&env);
559                         obd->obd_lu_dev = NULL;
560                 }
561         }
562         OBD_CHECK_DT_OP(obd, cleanup, 0);
563         OBD_COUNTER_INCREMENT(obd, cleanup);
564
565         rc = OBP(obd, cleanup)(obd);
566         RETURN(rc);
567 }
568
569 static inline int
570 obd_process_config(struct obd_device *obd, int datalen, void *data)
571 {
572         int rc;
573         DECLARE_LU_VARS(ldt, d);
574         ENTRY;
575
576         OBD_CHECK_DEV(obd);
577
578         obd->obd_process_conf = 1;
579         ldt = obd->obd_type->typ_lu;
580         d = obd->obd_lu_dev;
581         if (ldt != NULL && d != NULL) {
582                 struct lu_env env;
583
584                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
585                 if (rc == 0) {
586                         rc = d->ld_ops->ldo_process_config(&env, d, data);
587                         lu_env_fini(&env);
588                 }
589         } else {
590                 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
591                 rc = OBP(obd, process_config)(obd, datalen, data);
592         }
593         OBD_COUNTER_INCREMENT(obd, process_config);
594         obd->obd_process_conf = 0;
595
596         RETURN(rc);
597 }
598
599 /* Pack an in-memory MD struct for storage on disk.
600  * Returns +ve size of packed MD (0 for free), or -ve error.
601  *
602  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
603  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
604  * If @*disk_tgt == NULL, it will be allocated
605  */
606 static inline int obd_packmd(struct obd_export *exp,
607                              struct lov_mds_md **disk_tgt,
608                              struct lov_stripe_md *mem_src)
609 {
610         int rc;
611         ENTRY;
612
613         EXP_CHECK_DT_OP(exp, packmd);
614         EXP_COUNTER_INCREMENT(exp, packmd);
615
616         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
617         RETURN(rc);
618 }
619
620 static inline int obd_size_diskmd(struct obd_export *exp,
621                                   struct lov_stripe_md *mem_src)
622 {
623         return obd_packmd(exp, NULL, mem_src);
624 }
625
626 /* helper functions */
627 static inline int obd_alloc_diskmd(struct obd_export *exp,
628                                    struct lov_mds_md **disk_tgt)
629 {
630         LASSERT(disk_tgt);
631         LASSERT(*disk_tgt == NULL);
632         return obd_packmd(exp, disk_tgt, NULL);
633 }
634
635 static inline int obd_free_diskmd(struct obd_export *exp,
636                                   struct lov_mds_md **disk_tgt)
637 {
638         LASSERT(disk_tgt);
639         LASSERT(*disk_tgt);
640         return obd_packmd(exp, disk_tgt, NULL);
641 }
642
643 /* Unpack an MD struct from disk to in-memory format.
644  * Returns +ve size of unpacked MD (0 for free), or -ve error.
645  *
646  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
647  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
648  * If @*mem_tgt == NULL, it will be allocated
649  */
650 static inline int obd_unpackmd(struct obd_export *exp,
651                                struct lov_stripe_md **mem_tgt,
652                                struct lov_mds_md *disk_src,
653                                int disk_len)
654 {
655         int rc;
656         ENTRY;
657
658         EXP_CHECK_DT_OP(exp, unpackmd);
659         EXP_COUNTER_INCREMENT(exp, unpackmd);
660
661         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
662         RETURN(rc);
663 }
664
665 /* helper functions */
666 static inline int obd_alloc_memmd(struct obd_export *exp,
667                                   struct lov_stripe_md **mem_tgt)
668 {
669         LASSERT(mem_tgt);
670         LASSERT(*mem_tgt == NULL);
671         return obd_unpackmd(exp, mem_tgt, NULL, 0);
672 }
673
674 static inline int obd_free_memmd(struct obd_export *exp,
675                                  struct lov_stripe_md **mem_tgt)
676 {
677         int rc;
678
679         LASSERT(mem_tgt);
680         LASSERT(*mem_tgt);
681         rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
682         *mem_tgt = NULL;
683         return rc;
684 }
685
686 static inline int obd_checkmd(struct obd_export *exp,
687                               struct obd_export *md_exp,
688                               struct lov_stripe_md *mem_tgt)
689 {
690         int rc;
691         ENTRY;
692
693         EXP_CHECK_DT_OP(exp, checkmd);
694         EXP_COUNTER_INCREMENT(exp, checkmd);
695
696         rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
697         RETURN(rc);
698 }
699
700 static inline int obd_precreate(struct obd_export *exp)
701 {
702         int rc;
703         ENTRY;
704
705         EXP_CHECK_DT_OP(exp, precreate);
706         OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
707
708         rc = OBP(exp->exp_obd, precreate)(exp);
709         RETURN(rc);
710 }
711
712 static inline int obd_create_async(struct obd_export *exp,
713                                    struct obd_info *oinfo,
714                                    struct lov_stripe_md **ea,
715                                    struct obd_trans_info *oti)
716 {
717         int rc;
718         ENTRY;
719
720         EXP_CHECK_DT_OP(exp, create_async);
721         EXP_COUNTER_INCREMENT(exp, create_async);
722
723         rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
724         RETURN(rc);
725 }
726
727 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
728                              struct lov_stripe_md **ea,
729                              struct obd_trans_info *oti)
730 {
731         int rc;
732         ENTRY;
733
734         EXP_CHECK_DT_OP(exp, create);
735         EXP_COUNTER_INCREMENT(exp, create);
736
737         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
738         RETURN(rc);
739 }
740
741 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
742                               struct lov_stripe_md *ea,
743                               struct obd_trans_info *oti,
744                               struct obd_export *md_exp, void *capa)
745 {
746         int rc;
747         ENTRY;
748
749         EXP_CHECK_DT_OP(exp, destroy);
750         EXP_COUNTER_INCREMENT(exp, destroy);
751
752         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
753         RETURN(rc);
754 }
755
756 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
757 {
758         int rc;
759         ENTRY;
760
761         EXP_CHECK_DT_OP(exp, getattr);
762         EXP_COUNTER_INCREMENT(exp, getattr);
763
764         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
765         RETURN(rc);
766 }
767
768 static inline int obd_getattr_async(struct obd_export *exp,
769                                     struct obd_info *oinfo,
770                                     struct ptlrpc_request_set *set)
771 {
772         int rc;
773         ENTRY;
774
775         EXP_CHECK_DT_OP(exp, getattr_async);
776         EXP_COUNTER_INCREMENT(exp, getattr_async);
777
778         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
779         RETURN(rc);
780 }
781
782 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
783                               struct obd_trans_info *oti)
784 {
785         int rc;
786         ENTRY;
787
788         EXP_CHECK_DT_OP(exp, setattr);
789         EXP_COUNTER_INCREMENT(exp, setattr);
790
791         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
792         RETURN(rc);
793 }
794
795 /* This performs all the requests set init/wait/destroy actions. */
796 static inline int obd_setattr_rqset(struct obd_export *exp,
797                                     struct obd_info *oinfo,
798                                     struct obd_trans_info *oti)
799 {
800         struct ptlrpc_request_set *set = NULL;
801         int rc;
802         ENTRY;
803
804         EXP_CHECK_DT_OP(exp, setattr_async);
805         EXP_COUNTER_INCREMENT(exp, setattr_async);
806
807         set =  ptlrpc_prep_set();
808         if (set == NULL)
809                 RETURN(-ENOMEM);
810
811         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
812         if (rc == 0)
813                 rc = ptlrpc_set_wait(set);
814         ptlrpc_set_destroy(set);
815         RETURN(rc);
816 }
817
818 /* This adds all the requests into @set if @set != NULL, otherwise
819    all requests are sent asynchronously without waiting for response. */
820 static inline int obd_setattr_async(struct obd_export *exp,
821                                     struct obd_info *oinfo,
822                                     struct obd_trans_info *oti,
823                                     struct ptlrpc_request_set *set)
824 {
825         int rc;
826         ENTRY;
827
828         EXP_CHECK_DT_OP(exp, setattr_async);
829         EXP_COUNTER_INCREMENT(exp, setattr_async);
830
831         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
832         RETURN(rc);
833 }
834
835 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
836                                int priority)
837 {
838         struct obd_device *obd = imp->imp_obd;
839         int rc;
840         ENTRY;
841
842         OBD_CHECK_DEV_ACTIVE(obd);
843         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
844         OBD_COUNTER_INCREMENT(obd, add_conn);
845
846         rc = OBP(obd, add_conn)(imp, uuid, priority);
847         RETURN(rc);
848 }
849
850 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
851 {
852         struct obd_device *obd = imp->imp_obd;
853         int rc;
854         ENTRY;
855
856         OBD_CHECK_DEV_ACTIVE(obd);
857         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
858         OBD_COUNTER_INCREMENT(obd, del_conn);
859
860         rc = OBP(obd, del_conn)(imp, uuid);
861         RETURN(rc);
862 }
863
864 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
865 {
866         struct obd_uuid *uuid;
867         ENTRY;
868
869         OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
870         EXP_COUNTER_INCREMENT(exp, get_uuid);
871
872         uuid = OBP(exp->exp_obd, get_uuid)(exp);
873         RETURN(uuid);
874 }
875
876 static inline int obd_connect(const struct lu_env *env,
877                               struct obd_export **exp,struct obd_device *obd,
878                               struct obd_uuid *cluuid,
879                               struct obd_connect_data *d,
880                               void *localdata)
881 {
882         int rc;
883         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
884                                                    * check */
885         ENTRY;
886
887         OBD_CHECK_DEV_ACTIVE(obd);
888         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
889         OBD_COUNTER_INCREMENT(obd, connect);
890
891         rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
892         /* check that only subset is granted */
893         LASSERT(ergo(d != NULL,
894                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
895         RETURN(rc);
896 }
897
898 static inline int obd_reconnect(const struct lu_env *env,
899                                 struct obd_export *exp,
900                                 struct obd_device *obd,
901                                 struct obd_uuid *cluuid,
902                                 struct obd_connect_data *d,
903                                 void *localdata)
904 {
905         int rc;
906         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
907                                                    * check */
908
909         ENTRY;
910
911         OBD_CHECK_DEV_ACTIVE(obd);
912         OBD_CHECK_DT_OP(obd, reconnect, 0);
913         OBD_COUNTER_INCREMENT(obd, reconnect);
914
915         rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
916         /* check that only subset is granted */
917         LASSERT(ergo(d != NULL,
918                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
919         RETURN(rc);
920 }
921
922 static inline int obd_disconnect(struct obd_export *exp)
923 {
924         int rc;
925         ENTRY;
926
927         EXP_CHECK_DT_OP(exp, disconnect);
928         EXP_COUNTER_INCREMENT(exp, disconnect);
929
930         rc = OBP(exp->exp_obd, disconnect)(exp);
931         RETURN(rc);
932 }
933
934 static inline int obd_fid_init(struct obd_export *exp)
935 {
936         int rc;
937         ENTRY;
938
939         OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
940         EXP_COUNTER_INCREMENT(exp, fid_init);
941
942         rc = OBP(exp->exp_obd, fid_init)(exp);
943         RETURN(rc);
944 }
945
946 static inline int obd_fid_fini(struct obd_export *exp)
947 {
948         int rc;
949         ENTRY;
950
951         OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
952         EXP_COUNTER_INCREMENT(exp, fid_fini);
953
954         rc = OBP(exp->exp_obd, fid_fini)(exp);
955         RETURN(rc);
956 }
957
958 static inline int obd_fid_alloc(struct obd_export *exp,
959                                 struct lu_fid *fid,
960                                 struct md_op_data *op_data)
961 {
962         int rc;
963         ENTRY;
964
965         EXP_CHECK_DT_OP(exp, fid_alloc);
966         EXP_COUNTER_INCREMENT(exp, fid_alloc);
967
968         rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
969         RETURN(rc);
970 }
971
972 static inline int obd_fid_delete(struct obd_export *exp,
973                                  const struct lu_fid *fid)
974 {
975         int rc;
976         ENTRY;
977
978         EXP_CHECK_DT_OP(exp, fid_delete);
979         EXP_COUNTER_INCREMENT(exp, fid_delete);
980
981         rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
982         RETURN(rc);
983 }
984
985 static inline int obd_ping(struct obd_export *exp)
986 {
987         int rc;
988         ENTRY;
989
990         OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
991         EXP_COUNTER_INCREMENT(exp, ping);
992
993         rc = OBP(exp->exp_obd, ping)(exp);
994         RETURN(rc);
995 }
996
997 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
998 {
999         int rc;
1000         ENTRY;
1001
1002         OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1003         OBD_COUNTER_INCREMENT(obd, pool_new);
1004
1005         rc = OBP(obd, pool_new)(obd, poolname);
1006         RETURN(rc);
1007 }
1008
1009 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1010 {
1011         int rc;
1012         ENTRY;
1013
1014         OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1015         OBD_COUNTER_INCREMENT(obd, pool_del);
1016
1017         rc = OBP(obd, pool_del)(obd, poolname);
1018         RETURN(rc);
1019 }
1020
1021 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1022 {
1023         int rc;
1024         ENTRY;
1025
1026         OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1027         OBD_COUNTER_INCREMENT(obd, pool_add);
1028
1029         rc = OBP(obd, pool_add)(obd, poolname, ostname);
1030         RETURN(rc);
1031 }
1032
1033 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1034 {
1035         int rc;
1036         ENTRY;
1037
1038         OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1039         OBD_COUNTER_INCREMENT(obd, pool_rem);
1040
1041         rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1042         RETURN(rc);
1043 }
1044
1045 static inline void obd_getref(struct obd_device *obd)
1046 {
1047         ENTRY;
1048         if (OBT(obd) && OBP(obd, getref)) {
1049                 OBD_COUNTER_INCREMENT(obd, getref);
1050                 OBP(obd, getref)(obd);
1051         }
1052         EXIT;
1053 }
1054
1055 static inline void obd_putref(struct obd_device *obd)
1056 {
1057         ENTRY;
1058         if (OBT(obd) && OBP(obd, putref)) {
1059                 OBD_COUNTER_INCREMENT(obd, putref);
1060                 OBP(obd, putref)(obd);
1061         }
1062         EXIT;
1063 }
1064
1065 static inline int obd_init_export(struct obd_export *exp)
1066 {
1067         int rc = 0;
1068
1069         ENTRY;
1070         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1071             OBP((exp)->exp_obd, init_export))
1072                 rc = OBP(exp->exp_obd, init_export)(exp);
1073         RETURN(rc);
1074 }
1075
1076 static inline int obd_destroy_export(struct obd_export *exp)
1077 {
1078         ENTRY;
1079         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1080             OBP((exp)->exp_obd, destroy_export))
1081                 OBP(exp->exp_obd, destroy_export)(exp);
1082         RETURN(0);
1083 }
1084
1085 static inline int obd_extent_calc(struct obd_export *exp,
1086                                   struct lov_stripe_md *md,
1087                                   int cmd, obd_off *offset)
1088 {
1089         int rc;
1090         ENTRY;
1091         EXP_CHECK_DT_OP(exp, extent_calc);
1092         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1093         RETURN(rc);
1094 }
1095
1096 static inline struct dentry *
1097 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1098 {
1099         LASSERT(exp->exp_obd);
1100
1101         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1102                                exp->exp_obd);
1103 }
1104
1105 static inline int
1106 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1107 {
1108         LASSERT(exp->exp_obd);
1109         CERROR("FIXME what's the story here?  This needs to be an obd fn?\n");
1110 #if 0
1111         return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1112                               dentry, exp->exp_obd);
1113 #endif
1114         return 0;
1115 }
1116
1117 #ifndef time_before
1118 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
1119 #endif
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                 spin_lock(&obd->obd_osfs_lock);
1149                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1150                 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                         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                         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                 spin_lock(&obd->obd_osfs_lock);
1212                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1213                 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                 do_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                 do_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         if (obd->obd_observer && observer)
1646                 RETURN(-EALREADY);
1647         obd->obd_observer = observer;
1648         RETURN(0);
1649 }
1650
1651 #if 0
1652 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1653                                                obd_page_removal_cb_t cb,
1654                                                obd_pin_extent_cb pin_cb)
1655 {
1656         int rc;
1657         ENTRY;
1658
1659         OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1660         OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1661
1662         rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1663         RETURN(rc);
1664 }
1665
1666 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1667                                                  obd_page_removal_cb_t cb)
1668 {
1669         int rc;
1670         ENTRY;
1671
1672         OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1673         OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1674
1675         rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1676         RETURN(rc);
1677 }
1678
1679 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1680                                               obd_lock_cancel_cb cb)
1681 {
1682         int rc;
1683         ENTRY;
1684
1685         OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1686         OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1687
1688         rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1689         RETURN(rc);
1690 }
1691
1692 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1693                                                  obd_lock_cancel_cb cb)
1694 {
1695         int rc;
1696         ENTRY;
1697
1698         OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1699         OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1700
1701         rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1702         RETURN(rc);
1703 }
1704 #endif
1705
1706 /* metadata helpers */
1707 static inline int md_getstatus(struct obd_export *exp,
1708                                struct lu_fid *fid, struct obd_capa **pc)
1709 {
1710         int rc;
1711         ENTRY;
1712
1713         EXP_CHECK_MD_OP(exp, getstatus);
1714         EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1715         rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1716         RETURN(rc);
1717 }
1718
1719 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1720                              struct obd_capa *oc, obd_valid valid, int ea_size,
1721                              struct ptlrpc_request **request)
1722 {
1723         int rc;
1724         ENTRY;
1725         EXP_CHECK_MD_OP(exp, getattr);
1726         EXP_MD_COUNTER_INCREMENT(exp, getattr);
1727         rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1728                                         ea_size, request);
1729         RETURN(rc);
1730 }
1731
1732 static inline int md_change_cbdata(struct obd_export *exp,
1733                                    const struct lu_fid *fid,
1734                                    ldlm_iterator_t it, void *data)
1735 {
1736         int rc;
1737         ENTRY;
1738         EXP_CHECK_MD_OP(exp, change_cbdata);
1739         EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1740         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1741         RETURN(rc);
1742 }
1743
1744 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1745                            struct md_open_data *mod,
1746                            struct ptlrpc_request **request)
1747 {
1748         int rc;
1749         ENTRY;
1750         EXP_CHECK_MD_OP(exp, close);
1751         EXP_MD_COUNTER_INCREMENT(exp, close);
1752         rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1753         RETURN(rc);
1754 }
1755
1756 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1757                             const void *data, int datalen, int mode, __u32 uid,
1758                             __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1759                             struct ptlrpc_request **request)
1760 {
1761         int rc;
1762         ENTRY;
1763         EXP_CHECK_MD_OP(exp, create);
1764         EXP_MD_COUNTER_INCREMENT(exp, create);
1765         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1766                                        uid, gid, cap_effective, rdev, request);
1767         RETURN(rc);
1768 }
1769
1770 static inline int md_done_writing(struct obd_export *exp,
1771                                   struct md_op_data *op_data,
1772                                   struct md_open_data *mod)
1773 {
1774         int rc;
1775         ENTRY;
1776         EXP_CHECK_MD_OP(exp, done_writing);
1777         EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1778         rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1779         RETURN(rc);
1780 }
1781
1782 static inline int md_enqueue(struct obd_export *exp,
1783                              struct ldlm_enqueue_info *einfo,
1784                              struct lookup_intent *it,
1785                              struct md_op_data *op_data,
1786                              struct lustre_handle *lockh,
1787                              void *lmm, int lmmsize,
1788                              struct ptlrpc_request **req,
1789                              int extra_lock_flags)
1790 {
1791         int rc;
1792         ENTRY;
1793         EXP_CHECK_MD_OP(exp, enqueue);
1794         EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1795         rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1796                                         lmm, lmmsize, req, extra_lock_flags);
1797         RETURN(rc);
1798 }
1799
1800 static inline int md_getattr_name(struct obd_export *exp,
1801                                   const struct lu_fid *fid, struct obd_capa *oc,
1802                                   const char *name, int namelen,
1803                                   obd_valid valid, int ea_size, __u32 suppgid,
1804                                   struct ptlrpc_request **request)
1805 {
1806         int rc;
1807         ENTRY;
1808         EXP_CHECK_MD_OP(exp, getattr_name);
1809         EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1810         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1811                                              valid, ea_size, suppgid, request);
1812         RETURN(rc);
1813 }
1814
1815 static inline int md_intent_lock(struct obd_export *exp,
1816                                  struct md_op_data *op_data, void *lmm,
1817                                  int lmmsize, struct lookup_intent *it,
1818                                  int flags, struct ptlrpc_request **reqp,
1819                                  ldlm_blocking_callback cb_blocking,
1820                                  int extra_lock_flags)
1821 {
1822         int rc;
1823         ENTRY;
1824         EXP_CHECK_MD_OP(exp, intent_lock);
1825         EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1826         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1827                                             it, flags, reqp, cb_blocking,
1828                                             extra_lock_flags);
1829         RETURN(rc);
1830 }
1831
1832 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1833                           struct ptlrpc_request **request)
1834 {
1835         int rc;
1836         ENTRY;
1837         EXP_CHECK_MD_OP(exp, link);
1838         EXP_MD_COUNTER_INCREMENT(exp, link);
1839         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1840         RETURN(rc);
1841 }
1842
1843 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1844                             const char *old, int oldlen, const char *new,
1845                             int newlen, struct ptlrpc_request **request)
1846 {
1847         int rc;
1848         ENTRY;
1849         EXP_CHECK_MD_OP(exp, rename);
1850         EXP_MD_COUNTER_INCREMENT(exp, rename);
1851         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1852                                        newlen, request);
1853         RETURN(rc);
1854 }
1855
1856 static inline int md_is_subdir(struct obd_export *exp,
1857                                const struct lu_fid *pfid,
1858                                const struct lu_fid *cfid,
1859                                struct ptlrpc_request **request)
1860 {
1861         int rc;
1862         ENTRY;
1863         EXP_CHECK_MD_OP(exp, is_subdir);
1864         EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1865         rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1866         RETURN(rc);
1867 }
1868
1869 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1870                              void *ea, int ealen, void *ea2, int ea2len,
1871                              struct ptlrpc_request **request,
1872                              struct md_open_data **mod)
1873 {
1874         int rc;
1875         ENTRY;
1876         EXP_CHECK_MD_OP(exp, setattr);
1877         EXP_MD_COUNTER_INCREMENT(exp, setattr);
1878         rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1879                                         ea2, ea2len, request, mod);
1880         RETURN(rc);
1881 }
1882
1883 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1884                           struct obd_capa *oc, struct ptlrpc_request **request)
1885 {
1886         int rc;
1887         ENTRY;
1888         EXP_CHECK_MD_OP(exp, sync);
1889         EXP_MD_COUNTER_INCREMENT(exp, sync);
1890         rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1891         RETURN(rc);
1892 }
1893
1894 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1895                               struct obd_capa *oc, __u64 offset,
1896                               struct page *page,
1897                               struct ptlrpc_request **request)
1898 {
1899         int rc;
1900         ENTRY;
1901         EXP_CHECK_MD_OP(exp, readpage);
1902         EXP_MD_COUNTER_INCREMENT(exp, readpage);
1903         rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1904         RETURN(rc);
1905 }
1906
1907 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1908                             struct ptlrpc_request **request)
1909 {
1910         int rc;
1911         ENTRY;
1912         EXP_CHECK_MD_OP(exp, unlink);
1913         EXP_MD_COUNTER_INCREMENT(exp, unlink);
1914         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1915         RETURN(rc);
1916 }
1917
1918 static inline int md_get_lustre_md(struct obd_export *exp,
1919                                    struct ptlrpc_request *req,
1920                                    struct obd_export *dt_exp,
1921                                    struct obd_export *md_exp,
1922                                    struct lustre_md *md)
1923 {
1924         ENTRY;
1925         EXP_CHECK_MD_OP(exp, get_lustre_md);
1926         EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1927         RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1928 }
1929
1930 static inline int md_free_lustre_md(struct obd_export *exp,
1931                                     struct lustre_md *md)
1932 {
1933         ENTRY;
1934         EXP_CHECK_MD_OP(exp, free_lustre_md);
1935         EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1936         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1937 }
1938
1939 static inline int md_setxattr(struct obd_export *exp,
1940                               const struct lu_fid *fid, struct obd_capa *oc,
1941                               obd_valid valid, const char *name,
1942                               const char *input, int input_size,
1943                               int output_size, int flags, __u32 suppgid,
1944                               struct ptlrpc_request **request)
1945 {
1946         ENTRY;
1947         EXP_CHECK_MD_OP(exp, setxattr);
1948         EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1949         RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1950                                            input_size, output_size, flags,
1951                                            suppgid, request));
1952 }
1953
1954 static inline int md_getxattr(struct obd_export *exp,
1955                               const struct lu_fid *fid, struct obd_capa *oc,
1956                               obd_valid valid, const char *name,
1957                               const char *input, int input_size,
1958                               int output_size, int flags,
1959                               struct ptlrpc_request **request)
1960 {
1961         ENTRY;
1962         EXP_CHECK_MD_OP(exp, getxattr);
1963         EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1964         RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1965                                            input_size, output_size, flags,
1966                                            request));
1967 }
1968
1969 static inline int md_set_open_replay_data(struct obd_export *exp,
1970                                           struct obd_client_handle *och,
1971                                           struct ptlrpc_request *open_req)
1972 {
1973         ENTRY;
1974         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1975         EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1976         RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1977 }
1978
1979 static inline int md_clear_open_replay_data(struct obd_export *exp,
1980                                             struct obd_client_handle *och)
1981 {
1982         ENTRY;
1983         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1984         EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1985         RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1986 }
1987
1988 static inline int md_set_lock_data(struct obd_export *exp,
1989                                    __u64 *lockh, void *data, __u32 *bits)
1990 {
1991         ENTRY;
1992         EXP_CHECK_MD_OP(exp, set_lock_data);
1993         EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1994         RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1995 }
1996
1997 static inline int md_cancel_unused(struct obd_export *exp,
1998                                    const struct lu_fid *fid,
1999                                    ldlm_policy_data_t *policy,
2000                                    ldlm_mode_t mode, int flags, void *opaque)
2001 {
2002         int rc;
2003         ENTRY;
2004
2005         EXP_CHECK_MD_OP(exp, cancel_unused);
2006         EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2007
2008         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2009                                               flags, opaque);
2010         RETURN(rc);
2011 }
2012
2013 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2014                                         const struct lu_fid *fid,
2015                                         ldlm_type_t type,
2016                                         ldlm_policy_data_t *policy,
2017                                         ldlm_mode_t mode,
2018                                         struct lustre_handle *lockh)
2019 {
2020         ENTRY;
2021         EXP_CHECK_MD_OP(exp, lock_match);
2022         EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2023         RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2024                                              policy, mode, lockh));
2025 }
2026
2027 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2028                                   int def_asize, int cookiesize)
2029 {
2030         ENTRY;
2031         EXP_CHECK_MD_OP(exp, init_ea_size);
2032         EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2033         RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2034                                                cookiesize));
2035 }
2036
2037 static inline int md_get_remote_perm(struct obd_export *exp,
2038                                      const struct lu_fid *fid,
2039                                      struct obd_capa *oc, __u32 suppgid,
2040                                      struct ptlrpc_request **request)
2041 {
2042         ENTRY;
2043         EXP_CHECK_MD_OP(exp, get_remote_perm);
2044         EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2045         RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2046                                                   request));
2047 }
2048
2049 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2050                                 renew_capa_cb_t cb)
2051 {
2052         int rc;
2053         ENTRY;
2054         EXP_CHECK_MD_OP(exp, renew_capa);
2055         EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2056         rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2057         RETURN(rc);
2058 }
2059
2060 static inline int md_unpack_capa(struct obd_export *exp,
2061                                  struct ptlrpc_request *req,
2062                                  const struct req_msg_field *field,
2063                                  struct obd_capa **oc)
2064 {
2065         int rc;
2066         ENTRY;
2067         EXP_CHECK_MD_OP(exp, unpack_capa);
2068         EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2069         rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2070         RETURN(rc);
2071 }
2072
2073 static inline int md_intent_getattr_async(struct obd_export *exp,
2074                                           struct md_enqueue_info *minfo,
2075                                           struct ldlm_enqueue_info *einfo)
2076 {
2077         int rc;
2078         ENTRY;
2079         EXP_CHECK_MD_OP(exp, intent_getattr_async);
2080         EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2081         rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2082         RETURN(rc);
2083 }
2084
2085 static inline int md_revalidate_lock(struct obd_export *exp,
2086                                      struct lookup_intent *it,
2087                                      struct lu_fid *fid)
2088 {
2089         int rc;
2090         ENTRY;
2091         EXP_CHECK_MD_OP(exp, revalidate_lock);
2092         EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2093         rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2094         RETURN(rc);
2095 }
2096
2097
2098 /* OBD Metadata Support */
2099
2100 extern int obd_init_caches(void);
2101 extern void obd_cleanup_caches(void);
2102
2103 /* support routines */
2104 extern cfs_mem_cache_t *obdo_cachep;
2105
2106 #define OBDO_ALLOC(ptr)                                                       \
2107 do {                                                                          \
2108         OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep);                               \
2109 } while(0)
2110
2111 #define OBDO_FREE(ptr)                                                        \
2112 do {                                                                          \
2113         OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
2114 } while(0)
2115
2116
2117 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2118 {
2119         /* something here */
2120 }
2121
2122 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2123 {
2124         /* something here */
2125 }
2126
2127 /* I'm as embarrassed about this as you are.
2128  *
2129  * <shaver> // XXX do not look into _superhack with remaining eye
2130  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2131 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2132
2133 /* sysctl.c */
2134 extern void obd_sysctl_init (void);
2135 extern void obd_sysctl_clean (void);
2136
2137 /* uuid.c  */
2138 typedef __u8 class_uuid_t[16];
2139 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2140
2141 /* lustre_peer.c    */
2142 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2143 int class_add_uuid(const char *uuid, __u64 nid);
2144 int class_del_uuid (const char *uuid);
2145 void class_init_uuidlist(void);
2146 void class_exit_uuidlist(void);
2147
2148 /* mea.c */
2149 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2150 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2151
2152 /* prng.c */
2153 void ll_generate_random_uuid(class_uuid_t uuid_out);
2154
2155 #endif /* __LINUX_OBD_CLASS_H */