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