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