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