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