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