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