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