Whamcloud - gitweb
landing b_cmobd_merge on HEAD
[fs/lustre-release.git] / lustre / include / linux / obd_class.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #ifndef __LINUX_CLASS_OBD_H
24 #define __LINUX_CLASS_OBD_H
25
26 #ifndef __KERNEL__
27 #include <sys/types.h>
28 #include <portals/list.h>
29 #else
30 #include <asm/segment.h>
31 #include <asm/uaccess.h>
32 #include <linux/types.h>
33 #include <linux/fs.h>
34 #include <linux/time.h>
35 #include <linux/timer.h>
36 #endif
37
38 #include <linux/obd_support.h>
39 #include <linux/lustre_import.h>
40 #include <linux/lustre_net.h>
41 #include <linux/obd.h>
42 #include <linux/lustre_lib.h>
43 #include <linux/lustre_idl.h>
44 #include <linux/lprocfs_status.h>
45 #include <linux/lustre_mds.h>
46
47 /* OBD Device Declarations */
48 #define MAX_OBD_DEVICES 256
49 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
50
51 /* OBD Operations Declarations */
52 extern struct obd_device *class_conn2obd(struct lustre_handle *);
53 extern struct obd_device *class_exp2obd(struct obd_export *);
54
55 /* genops.c */
56 struct obd_export *class_conn2export(struct lustre_handle *);
57 int class_register_type(struct obd_ops *ops, struct md_ops *md_ops,
58                         struct lprocfs_vars *, char *nm);
59 int class_unregister_type(char *nm);
60
61 struct obd_device *class_newdev(int *dev);
62
63 int class_name2dev(char *name);
64 struct obd_device *class_name2obd(char *name);
65 int class_uuid2dev(struct obd_uuid *uuid);
66 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
67 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
68                                           char * typ_name,
69                                           struct obd_uuid *grp_uuid);
70 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
71                                            int *next);
72
73 int oig_init(struct obd_io_group **oig);
74 void oig_add_one(struct obd_io_group *oig,
75                   struct oig_callback_context *occ);
76 void oig_complete_one(struct obd_io_group *oig,
77                        struct oig_callback_context *occ, int rc);
78 void oig_release(struct obd_io_group *oig);
79 int oig_wait(struct obd_io_group *oig);
80
81 /* config.c */
82 int class_process_config(struct lustre_cfg *lcfg);
83 int class_attach(struct lustre_cfg *lcfg);
84 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
85 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
86 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
87
88 /* Passed as data param to class_config_parse_llog */
89 struct config_llog_instance {
90         char * cfg_instance;
91         struct obd_uuid cfg_uuid;
92         ptl_nid_t  cfg_local_nid;
93 };
94 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
95                             struct config_llog_instance *cfg);
96 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
97                            struct config_llog_instance *cfg);
98
99 struct lustre_profile {
100         struct list_head lp_list;
101         char * lp_profile;
102         char * lp_osc;
103         char * lp_mdc;
104 };
105
106 struct lustre_profile *class_get_profile(char * prof);
107 void class_del_profile(char *prof);
108
109 #define class_export_get(exp)                                                  \
110 ({                                                                             \
111         struct obd_export *exp_ = exp;                                         \
112         atomic_inc(&exp_->exp_refcount);                                       \
113         CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_,          \
114                atomic_read(&exp_->exp_refcount));                              \
115         exp_;                                                                  \
116 })
117
118 #define class_export_put(exp)                                                  \
119 do {                                                                           \
120         LASSERT((exp) != NULL);                                                \
121         CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp),         \
122                atomic_read(&(exp)->exp_refcount) - 1);                         \
123         LASSERT(atomic_read(&(exp)->exp_refcount) > 0);                        \
124         LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a);                 \
125         __class_export_put(exp);                                               \
126 } while (0)
127 void __class_export_put(struct obd_export *);
128 struct obd_export *class_new_export(struct obd_device *obddev);
129 void class_unlink_export(struct obd_export *exp);
130
131 struct obd_import *class_import_get(struct obd_import *);
132 void class_import_put(struct obd_import *);
133 struct obd_import *class_new_import(void);
134 void class_destroy_import(struct obd_import *exp);
135
136 struct obd_type *class_get_type(char *name);
137 void class_put_type(struct obd_type *type);
138 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
139                   struct obd_uuid *cluuid);
140 int class_disconnect(struct obd_export *exp, int failover);
141 void class_disconnect_exports(struct obd_device *obddev, int failover);
142 /* generic operations shared by various OBD types */
143 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
144 int class_multi_cleanup(struct obd_device *obddev);
145
146 /* obdo.c */
147 #ifdef __KERNEL__
148 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
149 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
150 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
151 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
152 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
153 #endif
154 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
155 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
156 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
157
158 static inline int obd_check_conn(struct lustre_handle *conn)
159 {
160         struct obd_device *obd;
161         if (!conn) {
162                 CERROR("NULL conn\n");
163                 RETURN(-ENOTCONN);
164         }
165
166         obd = class_conn2obd(conn);
167         if (!obd) {
168                 CERROR("NULL obd\n");
169                 RETURN(-ENODEV);
170         }
171
172         if (!obd->obd_attached) {
173                 CERROR("obd %d not attached\n", obd->obd_minor);
174                 RETURN(-ENODEV);
175         }
176
177         if (!obd->obd_set_up) {
178                 CERROR("obd %d not setup\n", obd->obd_minor);
179                 RETURN(-ENODEV);
180         }
181
182         if (!obd->obd_type) {
183                 CERROR("obd %d not typed\n", obd->obd_minor);
184                 RETURN(-ENODEV);
185         }
186
187         if (!obd->obd_type->typ_ops) {
188                 CERROR("obd_check_conn: obd %d no operations\n",
189                        obd->obd_minor);
190                 RETURN(-EOPNOTSUPP);
191         }
192         return 0;
193 }
194
195
196 #define OBT(dev)        (dev)->obd_type
197 #define OBP(dev, op)    (dev)->obd_type->typ_ops->o_ ## op
198 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
199 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
200
201 /* Ensure obd_setup: used for disconnect which might be called while
202    an obd is stopping. */
203 #define OBD_CHECK_SETUP(conn, exp)                                      \
204 do {                                                                    \
205         if (!(conn)) {                                                  \
206                 CERROR("NULL connection\n");                            \
207                 RETURN(-EINVAL);                                        \
208         }                                                               \
209                                                                         \
210         exp = class_conn2export(conn);                                  \
211         if (!(exp)) {                                                   \
212                 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
213                 RETURN(-EINVAL);                                        \
214         }                                                               \
215                                                                         \
216         if (!(exp)->exp_obd->obd_set_up) {                              \
217                 CERROR("Device %d not setup\n",                         \
218                        (exp)->exp_obd->obd_minor);                      \
219                 class_export_put(exp);                                  \
220                 RETURN(-EINVAL);                                        \
221         }                                                               \
222 } while (0)
223
224 /* Ensure obd_setup and !obd_stopping. */
225 #define OBD_CHECK_ACTIVE(conn, exp)                                     \
226 do {                                                                    \
227         if (!(conn)) {                                                  \
228                 CERROR("NULL connection\n");                            \
229                 RETURN(-EINVAL);                                        \
230         }                                                               \
231                                                                         \
232         exp = class_conn2export(conn);                                  \
233         if (!(exp)) {                                                   \
234                 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
235                 RETURN(-EINVAL);                                        \
236         }                                                               \
237                                                                         \
238         if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
239                 CERROR("Device %d not setup\n",                         \
240                        (exp)->exp_obd->obd_minor);                      \
241                 class_export_put(exp);                                  \
242                 RETURN(-EINVAL);                                        \
243         }                                                               \
244 } while (0)
245
246 /* Ensure obd_setup: used for cleanup which must be called
247    while obd is stopping */
248 #define OBD_CHECK_DEV_STOPPING(obd)                             \
249 do {                                                            \
250         if (!(obd)) {                                           \
251                 CERROR("NULL device\n");                        \
252                 RETURN(-ENODEV);                                \
253         }                                                       \
254                                                                 \
255         if (!(obd)->obd_set_up) {                               \
256                 CERROR("Device %d not setup\n",                 \
257                        (obd)->obd_minor);                       \
258                 RETURN(-ENODEV);                                \
259         }                                                       \
260                                                                 \
261         if (!(obd)->obd_stopping) {                             \
262                 CERROR("Device %d not stopping\n",              \
263                        (obd)->obd_minor);                       \
264                 RETURN(-ENODEV);                                \
265         }                                                       \
266 } while (0)
267
268 /* ensure obd_setup and !obd_stopping */
269 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
270 do {                                                            \
271         if (!(obd)) {                                           \
272                 CERROR("NULL device\n");                        \
273                 RETURN(-ENODEV);                                \
274         }                                                       \
275                                                                 \
276         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
277                 CERROR("Device %d not setup\n",                 \
278                        (obd)->obd_minor);                       \
279                 RETURN(-ENODEV);                                \
280         }                                                       \
281 } while (0)
282
283
284 #ifdef LPROCFS
285 #define OBD_COUNTER_OFFSET(op)                                  \
286         ((offsetof(struct obd_ops, o_ ## op) -                  \
287           offsetof(struct obd_ops, o_iocontrol))                \
288          / sizeof(((struct obd_ops *)(0))->o_iocontrol))
289
290 #define OBD_COUNTER_INCREMENT(obd, op)                          \
291         if ((obd)->obd_stats != NULL) {                         \
292                 unsigned int coffset;                           \
293                 coffset = (unsigned int)(obd)->obd_cntr_base +  \
294                         OBD_COUNTER_OFFSET(op);                 \
295                 LASSERT(coffset < obd->obd_stats->ls_num);      \
296                 lprocfs_counter_incr(obd->obd_stats, coffset);  \
297         }
298 /* FIXME: real accounting here */
299 #define MD_COUNTER_INCREMENT(obd, op)
300 #else
301 #define OBD_COUNTER_OFFSET(op)
302 #define OBD_COUNTER_INCREMENT(obd, op)
303 #define MD_COUNTER_INCREMENT(obd, op)
304 #endif
305
306 #define OBD_CHECK_MD_OP(obd, op, err)                           \
307 do {                                                            \
308         if (!OBT(obd) || !MDP((obd), op)) {\
309                 if (err)                                        \
310                         CERROR("obd_md" #op ": dev %d no operation\n",    \
311                                obd->obd_minor);                 \
312                 RETURN(err);                                    \
313         }                                                       \
314 } while (0)
315
316 #define EXP_CHECK_MD_OP(exp, op)                                \
317 do {                                                            \
318         if ((exp) == NULL) {                                    \
319                 CERROR("obd_" #op ": NULL export\n");           \
320                 RETURN(-ENODEV);                                \
321         }                                                       \
322         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
323                 CERROR("obd_" #op ": cleaned up obd\n");        \
324                 RETURN(-EOPNOTSUPP);                            \
325         }                                                       \
326         if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
327                 CERROR("obd_" #op ": dev %d no operation\n",    \
328                        (exp)->exp_obd->obd_minor);              \
329                 RETURN(-EOPNOTSUPP);                            \
330         }                                                       \
331 } while (0)
332
333 #define OBD_CHECK_OP(obd, op, err)                              \
334 do {                                                            \
335         if (!OBT(obd) || !OBP((obd), op)) {\
336                 if (err)                                        \
337                         CERROR("obd_" #op ": dev %d no operation\n",    \
338                                obd->obd_minor);                         \
339                 RETURN(err);                                    \
340         }                                                       \
341 } while (0)
342
343 #define EXP_CHECK_OP(exp, op)                                   \
344 do {                                                            \
345         if ((exp) == NULL) {                                    \
346                 CERROR("obd_" #op ": NULL export\n");           \
347                 RETURN(-ENODEV);                                \
348         }                                                       \
349         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
350                 CERROR("obd_" #op ": cleaned up obd\n");        \
351                 RETURN(-EOPNOTSUPP);                            \
352         }                                                       \
353         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
354                 CERROR("obd_" #op ": dev %d no operation\n",    \
355                        (exp)->exp_obd->obd_minor);              \
356                 RETURN(-EOPNOTSUPP);                            \
357         }                                                       \
358 } while (0)
359
360 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
361 do {                                                            \
362         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
363                 if (err)                                        \
364                         CERROR("lop_" #op ": dev %d no operation\n",    \
365                                ctxt->loc_obd->obd_minor);                         \
366                 RETURN(err);                                    \
367         }                                                       \
368 } while (0)
369
370 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
371                                void *key, __u32 *vallen, void *val)
372 {
373         int rc;
374         ENTRY;
375
376         EXP_CHECK_OP(exp, get_info);
377         OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
378
379         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
380         RETURN(rc);
381 }
382
383 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
384                                void *key, obd_count vallen, void *val)
385 {
386         int rc;
387         ENTRY;
388
389         EXP_CHECK_OP(exp, set_info);
390         OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
391
392         rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
393         RETURN(rc);
394 }
395
396 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
397 {
398         int rc;
399         ENTRY;
400
401         OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
402         OBD_COUNTER_INCREMENT(obd, setup);
403
404         rc = OBP(obd, setup)(obd, datalen, data);
405         RETURN(rc);
406 }
407
408 static inline int obd_precleanup(struct obd_device *obd, int flags)
409 {
410         int rc;
411         ENTRY;
412
413         OBD_CHECK_OP(obd, precleanup, 0);
414         OBD_COUNTER_INCREMENT(obd, precleanup);
415
416         rc = OBP(obd, precleanup)(obd, flags);
417         RETURN(rc);
418 }
419
420 static inline int obd_cleanup(struct obd_device *obd, int flags)
421 {
422         int rc;
423         ENTRY;
424
425         OBD_CHECK_DEV_STOPPING(obd);
426         OBD_CHECK_OP(obd, cleanup, 0);
427         OBD_COUNTER_INCREMENT(obd, cleanup);
428
429         rc = OBP(obd, cleanup)(obd, flags);
430         RETURN(rc);
431 }
432
433 /* Pack an in-memory MD struct for storage on disk.
434  * Returns +ve size of packed MD (0 for free), or -ve error.
435  *
436  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
437  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
438  * If @*disk_tgt == NULL, it will be allocated
439  */
440 static inline int obd_packmd(struct obd_export *exp,
441                              struct lov_mds_md **disk_tgt,
442                              struct lov_stripe_md *mem_src)
443 {
444         int rc;
445         ENTRY;
446
447         EXP_CHECK_OP(exp, packmd);
448         OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
449
450         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
451         RETURN(rc);
452 }
453
454 static inline int obd_size_diskmd(struct obd_export *exp,
455                                   struct lov_stripe_md *mem_src)
456 {
457         return obd_packmd(exp, NULL, mem_src);
458 }
459
460 /* helper functions */
461 static inline int obd_alloc_diskmd(struct obd_export *exp,
462                                    struct lov_mds_md **disk_tgt)
463 {
464         LASSERT(disk_tgt);
465         LASSERT(*disk_tgt == NULL);
466         return obd_packmd(exp, disk_tgt, NULL);
467 }
468
469 static inline int obd_free_diskmd(struct obd_export *exp,
470                                   struct lov_mds_md **disk_tgt)
471 {
472         LASSERT(disk_tgt);
473         LASSERT(*disk_tgt);
474         return obd_packmd(exp, disk_tgt, NULL);
475 }
476
477 /* Unpack an MD struct from disk to in-memory format.
478  * Returns +ve size of unpacked MD (0 for free), or -ve error.
479  *
480  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
481  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
482  * If @*mem_tgt == NULL, it will be allocated
483  */
484 static inline int obd_unpackmd(struct obd_export *exp,
485                                struct lov_stripe_md **mem_tgt,
486                                struct lov_mds_md *disk_src,
487                                int disk_len)
488 {
489         int rc;
490         ENTRY;
491
492         EXP_CHECK_OP(exp, unpackmd);
493         OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
494
495         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
496         RETURN(rc);
497 }
498
499 /* helper functions */
500 static inline int obd_alloc_memmd(struct obd_export *exp,
501                                   struct lov_stripe_md **mem_tgt)
502 {
503         LASSERT(mem_tgt);
504         LASSERT(*mem_tgt == NULL);
505         return obd_unpackmd(exp, mem_tgt, NULL, 0);
506 }
507
508 static inline int obd_free_memmd(struct obd_export *exp,
509                                  struct lov_stripe_md **mem_tgt)
510 {
511         LASSERT(mem_tgt);
512         LASSERT(*mem_tgt);
513         return obd_unpackmd(exp, mem_tgt, NULL, 0);
514 }
515
516 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
517                              struct lov_stripe_md **ea,
518                              struct obd_trans_info *oti)
519 {
520         int rc;
521         ENTRY;
522
523         EXP_CHECK_OP(exp, create);
524         OBD_COUNTER_INCREMENT(exp->exp_obd, create);
525
526         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
527         RETURN(rc);
528 }
529
530 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
531                               struct lov_stripe_md *ea,
532                               struct obd_trans_info *oti)
533 {
534         int rc;
535         ENTRY;
536
537         EXP_CHECK_OP(exp, destroy);
538         OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
539
540         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
541         RETURN(rc);
542 }
543
544 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
545                               struct lov_stripe_md *ea)
546 {
547         int rc;
548         ENTRY;
549
550         EXP_CHECK_OP(exp, getattr);
551         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
552
553         rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
554         RETURN(rc);
555 }
556
557 static inline int obd_getattr_async(struct obd_export *exp,
558                                     struct obdo *obdo, struct lov_stripe_md *ea,
559                                     struct ptlrpc_request_set *set)
560 {
561         int rc;
562         ENTRY;
563
564         EXP_CHECK_OP(exp, getattr);
565         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
566
567         rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
568         RETURN(rc);
569 }
570
571 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
572                               struct lov_stripe_md *ea,
573                               struct obd_trans_info *oti)
574 {
575         int rc;
576         ENTRY;
577
578         EXP_CHECK_OP(exp, setattr);
579         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
580
581         rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
582         RETURN(rc);
583 }
584
585 static inline int obd_connect(struct lustre_handle *conn,
586                               struct obd_device *obd, struct obd_uuid *cluuid)
587 {
588         int rc;
589         ENTRY;
590
591         OBD_CHECK_DEV_ACTIVE(obd);
592         OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
593         OBD_COUNTER_INCREMENT(obd, connect);
594
595         rc = OBP(obd, connect)(conn, obd, cluuid);
596         RETURN(rc);
597 }
598
599 static inline int obd_disconnect(struct obd_export *exp, int flags)
600 {
601         int rc;
602         ENTRY;
603
604         EXP_CHECK_OP(exp, disconnect);
605         OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
606
607         rc = OBP(exp->exp_obd, disconnect)(exp, flags);
608         RETURN(rc);
609 }
610
611 static inline int obd_init_export(struct obd_export *exp)
612 {
613         int rc = 0;
614
615         ENTRY;
616         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
617             OBP((exp)->exp_obd, init_export))
618                 rc = OBP(exp->exp_obd, init_export)(exp);
619         RETURN(rc);
620 }
621
622 static inline int obd_destroy_export(struct obd_export *exp)
623 {
624         ENTRY;
625         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
626             OBP((exp)->exp_obd, destroy_export))
627                 OBP(exp->exp_obd, destroy_export)(exp);
628         RETURN(0);
629 }
630
631 static inline struct dentry *
632 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
633 {
634         LASSERT(exp->exp_obd);
635
636         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
637                                exp->exp_obd);
638 }
639
640 #ifndef time_before
641 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
642 #endif
643
644 /* @max_age is the oldest time in jiffies that we accept using a cached data.
645  * If the cache is older than @max_age we will get a new value from the
646  * target.  Use a value of "jiffies + HZ" to guarantee freshness. */
647 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
648                              unsigned long max_age)
649 {
650         int rc = 0;
651         ENTRY;
652
653         if (obd == NULL)
654                 RETURN(-EINVAL);
655
656         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
657         OBD_COUNTER_INCREMENT(obd, statfs);
658
659         CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
660         if (time_before(obd->obd_osfs_age, max_age)) {
661                 rc = OBP(obd, statfs)(obd, osfs, max_age);
662                 if (rc == 0) {
663                         spin_lock(&obd->obd_osfs_lock);
664                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
665                         obd->obd_osfs_age = jiffies;
666                         spin_unlock(&obd->obd_osfs_lock);
667                 }
668         } else {
669                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
670                 spin_lock(&obd->obd_osfs_lock);
671                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
672                 spin_unlock(&obd->obd_osfs_lock);
673         }
674         RETURN(rc);
675 }
676
677 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
678                            struct lov_stripe_md *ea, obd_size start,
679                            obd_size end)
680 {
681         int rc;
682         ENTRY;
683
684         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
685         OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
686
687         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
688         RETURN(rc);
689 }
690
691 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
692                             struct lov_stripe_md *ea, obd_size start,
693                             obd_size end, struct obd_trans_info *oti)
694 {
695         int rc;
696         ENTRY;
697
698         EXP_CHECK_OP(exp, punch);
699         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
700
701         rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
702         RETURN(rc);
703 }
704
705 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
706                           struct lov_stripe_md *ea, obd_count oa_bufs,
707                           struct brw_page *pg, struct obd_trans_info *oti)
708 {
709         int rc;
710         ENTRY;
711
712         EXP_CHECK_OP(exp, brw);
713         OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
714
715         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
716                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
717                        "or OBD_BRW_CHECK\n");
718                 LBUG();
719         }
720
721         rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
722         RETURN(rc);
723 }
724
725 static inline int obd_brw_async(int cmd, struct obd_export *exp,
726                                 struct obdo *oa, struct lov_stripe_md *ea,
727                                 obd_count oa_bufs, struct brw_page *pg,
728                                 struct ptlrpc_request_set *set,
729                                 struct obd_trans_info *oti)
730 {
731         int rc;
732         ENTRY;
733
734         EXP_CHECK_OP(exp, brw_async);
735         OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
736
737         if (!(cmd & OBD_BRW_RWMASK)) {
738                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
739                 LBUG();
740         }
741
742         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
743                                           oti);
744         RETURN(rc);
745 }
746
747 static inline  int obd_prep_async_page(struct obd_export *exp,
748                                        struct lov_stripe_md *lsm,
749                                        struct lov_oinfo *loi,
750                                        struct page *page, obd_off offset,
751                                        struct obd_async_page_ops *ops,
752                                        void *data, void **res)
753 {
754         int ret;
755         ENTRY;
756
757         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
758         OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
759
760         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
761                                                  ops, data, res);
762         RETURN(ret);
763 }
764
765 static inline int obd_queue_async_io(struct obd_export *exp,
766                                      struct lov_stripe_md *lsm,
767                                      struct lov_oinfo *loi, void *cookie,
768                                      int cmd, obd_off off, int count,
769                                      obd_flag brw_flags, obd_flag async_flags)
770 {
771         int rc;
772         ENTRY;
773
774         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
775         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
776         LASSERT(cmd & OBD_BRW_RWMASK);
777
778         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
779                                                count, brw_flags, async_flags);
780         RETURN(rc);
781 }
782
783 static inline int obd_set_async_flags(struct obd_export *exp,
784                                       struct lov_stripe_md *lsm,
785                                       struct lov_oinfo *loi, void *cookie,
786                                       obd_flag async_flags)
787 {
788         int rc;
789         ENTRY;
790
791         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
792         OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
793
794         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
795                                                 async_flags);
796         RETURN(rc);
797 }
798
799 static inline int obd_queue_group_io(struct obd_export *exp,
800                                      struct lov_stripe_md *lsm,
801                                      struct lov_oinfo *loi,
802                                      struct obd_io_group *oig,
803                                      void *cookie, int cmd, obd_off off,
804                                      int count, obd_flag brw_flags,
805                                      obd_flag async_flags)
806 {
807         int rc;
808         ENTRY;
809
810         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
811         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
812         LASSERT(cmd & OBD_BRW_RWMASK);
813
814         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
815                                                cmd, off, count, brw_flags,
816                                                async_flags);
817         RETURN(rc);
818 }
819
820 static inline int obd_trigger_group_io(struct obd_export *exp,
821                                        struct lov_stripe_md *lsm,
822                                        struct lov_oinfo *loi,
823                                        struct obd_io_group *oig)
824 {
825         int rc;
826         ENTRY;
827
828         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
829         OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
830
831         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
832         RETURN(rc);
833 }
834
835 static inline int obd_teardown_async_page(struct obd_export *exp,
836                                           struct lov_stripe_md *lsm,
837                                           struct lov_oinfo *loi, void *cookie)
838 {
839         int rc;
840         ENTRY;
841
842         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
843         OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
844
845         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
846         RETURN(rc);
847 }
848
849 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
850                              int objcount, struct obd_ioobj *obj,
851                              int niocount, struct niobuf_remote *remote,
852                              struct niobuf_local *local,
853                              struct obd_trans_info *oti)
854 {
855         int rc;
856         ENTRY;
857
858         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
859         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
860
861         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
862                                        remote, local, oti);
863         RETURN(rc);
864 }
865
866 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
867                                int objcount, struct obd_ioobj *obj,
868                                int niocount, struct niobuf_local *local,
869                                struct obd_trans_info *oti, int rc)
870 {
871         ENTRY;
872
873         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
874         OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
875
876         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
877                                          local, oti, rc);
878         RETURN(rc);
879 }
880
881 static inline int obd_write_extents(struct obd_export *exp, struct obd_ioobj *obj,
882                                     int niocount, struct niobuf_local *local, int rc)
883 {
884         ENTRY;
885
886         /* there are cases when write_extents is not implemented. */
887         if (!OBP(exp->exp_obd, write_extents))
888                 RETURN(0);
889                 
890         OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
891
892         rc = OBP(exp->exp_obd, write_extents)(exp, obj, niocount, local, rc);
893         RETURN(rc);
894 }
895
896 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
897                                 int len, void *karg, void *uarg)
898 {
899         int rc;
900         ENTRY;
901
902         EXP_CHECK_OP(exp, iocontrol);
903         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
904
905         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
906         RETURN(rc);
907 }
908
909 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
910                               __u32 type, ldlm_policy_data_t *policy,
911                               __u32 mode, int *flags, void *bl_cb, void *cp_cb,
912                               void *gl_cb, void *data, __u32 lvb_len,
913                               void *lvb_swabber, struct lustre_handle *lockh)
914 {
915         int rc;
916         ENTRY;
917
918         EXP_CHECK_OP(exp, enqueue);
919         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
920
921         rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
922                                         bl_cb, cp_cb, gl_cb, data, lvb_len,
923                                         lvb_swabber, lockh);
924         RETURN(rc);
925 }
926
927 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
928                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
929                             int *flags, void *data, struct lustre_handle *lockh)
930 {
931         int rc;
932         ENTRY;
933
934         EXP_CHECK_OP(exp, match);
935         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
936
937         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
938                                       lockh);
939         RETURN(rc);
940 }
941
942 static inline int obd_change_cbdata(struct obd_export *exp,
943                                     struct lov_stripe_md *lsm,
944                                     ldlm_iterator_t it, void *data)
945 {
946         int rc;
947         ENTRY;
948
949         EXP_CHECK_OP(exp, change_cbdata);
950         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
951
952         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
953         RETURN(rc);
954 }
955
956 static inline int obd_cancel(struct obd_export *exp,
957                              struct lov_stripe_md *ea, __u32 mode,
958                              struct lustre_handle *lockh)
959 {
960         int rc;
961         ENTRY;
962
963         EXP_CHECK_OP(exp, cancel);
964         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
965
966         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
967         RETURN(rc);
968 }
969
970 static inline int obd_cancel_unused(struct obd_export *exp,
971                                     struct lov_stripe_md *ea, int flags,
972                                     void *opaque)
973 {
974         int rc;
975         ENTRY;
976
977         EXP_CHECK_OP(exp, cancel_unused);
978         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
979
980         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
981         RETURN(rc);
982 }
983
984
985 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
986                                  struct obdo *oa,
987                                  int objcount, struct obd_ioobj *obj,
988                                  int niocount, struct niobuf_remote *remote)
989 {
990         int rc;
991
992         EXP_CHECK_OP(exp, preprw);
993         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
994
995         rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
996                                            niocount, remote);
997         class_export_put(exp);
998         return(rc);
999 }
1000
1001 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1002                           int type, struct obd_client_handle *handle, int flag)
1003 {
1004         int rc;
1005
1006         EXP_CHECK_OP(exp, pin);
1007         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1008
1009         rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1010         return(rc);
1011 }
1012
1013 static inline int obd_unpin(struct obd_export *exp,
1014                             struct obd_client_handle *handle, int flag)
1015 {
1016         int rc;
1017
1018         EXP_CHECK_OP(exp, unpin);
1019         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1020
1021         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1022         return(rc);
1023 }
1024
1025
1026 static inline void obd_import_event(struct obd_device *obd,
1027                                     struct obd_import *imp,
1028                                     enum obd_import_event event)
1029 {
1030         if (obd->obd_set_up && OBP(obd, import_event)) {
1031                 OBD_COUNTER_INCREMENT(obd, import_event);
1032                 OBP(obd, import_event)(obd, imp, event);
1033         }
1034 }
1035
1036 static inline int obd_llog_connect(struct obd_device *obd,
1037                                         struct llogd_conn_body *body)
1038 {
1039         ENTRY;
1040         if (!obd->obd_set_up) {
1041                 CERROR("obd %s not set up\n", obd->obd_name);
1042                 return -EINVAL;
1043         }
1044
1045         if (!OBP(obd, llog_connect)) {
1046                 CERROR("obd %s has no llog_connect handler\n", obd->obd_name);
1047                 return -ENOSYS;
1048         }
1049
1050         return OBP(obd, llog_connect)(obd, body);
1051 }
1052
1053 static inline int obd_notify(struct obd_device *obd,
1054                              struct obd_device *watched,
1055                              int active)
1056 {
1057         if (!obd->obd_set_up) {
1058                 CERROR("obd %s not set up\n", obd->obd_name);
1059                 return -EINVAL;
1060         }
1061
1062         if (!OBP(obd, notify)) {
1063                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1064                 return -ENOSYS;
1065         }
1066
1067         OBD_COUNTER_INCREMENT(obd, notify);
1068         return OBP(obd, notify)(obd, watched, active);
1069 }
1070
1071 static inline int obd_register_observer(struct obd_device *obd,
1072                                         struct obd_device *observer)
1073 {
1074         ENTRY;
1075         if (obd->obd_observer && observer)
1076                 RETURN(-EALREADY);
1077         obd->obd_observer = observer;
1078         RETURN(0);
1079 }
1080
1081 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1082 {
1083         int rc;
1084         ENTRY;
1085         LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1086         OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1087         rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1088         RETURN(rc);
1089 }
1090
1091 static inline int md_getstatus(struct obd_export *exp, struct ll_fid *fid)
1092 {
1093         int rc;
1094
1095         EXP_CHECK_MD_OP(exp, getstatus);
1096         MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1097         rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1098         RETURN(rc);
1099 }
1100
1101 static inline int md_getattr(struct obd_export *exp, struct ll_fid *fid,
1102                              unsigned long valid, unsigned int ea_size,
1103                              struct ptlrpc_request **request)
1104 {
1105         int rc;
1106         EXP_CHECK_MD_OP(exp, getattr);
1107         MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1108         rc = MDP(exp->exp_obd, getattr)(exp, fid, valid, ea_size, request);
1109         RETURN(rc);
1110 }
1111
1112 static inline int md_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
1113                                    ldlm_iterator_t it, void *data)
1114 {
1115         int rc;
1116         ENTRY;
1117         EXP_CHECK_MD_OP(exp, change_cbdata);
1118         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1119         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1120         RETURN(rc);
1121 }
1122
1123 static inline int md_change_cbdata_name(struct obd_export *exp,
1124                                         struct ll_fid *fid, char *name,
1125                                         int namelen, struct ll_fid *fid2,
1126                                         ldlm_iterator_t it, void *data)
1127 {
1128         int rc;
1129         
1130         /* this seem to be needed only for lmv. */
1131         if (!MDP(exp->exp_obd, change_cbdata_name))
1132                 return 0;
1133         
1134         ENTRY;
1135                 
1136         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1137         rc = MDP(exp->exp_obd, change_cbdata_name)(exp, fid, name, namelen,
1138                                                    fid2, it, data);
1139         RETURN(rc);
1140 }
1141
1142 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1143                            struct obd_client_handle *och,
1144                            struct ptlrpc_request **request)
1145 {
1146         int rc;
1147         ENTRY;
1148         EXP_CHECK_MD_OP(exp, close);
1149         MD_COUNTER_INCREMENT(exp->exp_obd, close);
1150         rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1151         RETURN(rc);
1152 }
1153
1154 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1155                             const void *data, int datalen, int mode,
1156                             __u32 uid, __u32 gid, __u64 rdev,
1157                             struct ptlrpc_request **request)
1158 {
1159         int rc;
1160         ENTRY;
1161         EXP_CHECK_MD_OP(exp, create);
1162         MD_COUNTER_INCREMENT(exp->exp_obd, create);
1163         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1164                                        uid, gid, rdev, request);
1165         RETURN(rc);
1166 }
1167
1168 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1169 {
1170         int rc;
1171         ENTRY;
1172         EXP_CHECK_MD_OP(exp, done_writing);
1173         MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1174         rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1175         RETURN(rc);
1176 }
1177
1178 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1179                              struct lookup_intent *it, int lock_mode,
1180                              struct mdc_op_data *data,
1181                              struct lustre_handle *lockh,
1182                              void *lmm, int lmmsize,
1183                              ldlm_completion_callback cb_completion,
1184                              ldlm_blocking_callback cb_blocking,
1185                              void *cb_data)
1186 {
1187         int rc;
1188         ENTRY;
1189         EXP_CHECK_MD_OP(exp, enqueue);
1190         MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1191         rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1192                                         data, lockh, lmm, lmmsize,
1193                                         cb_completion, cb_blocking,
1194                                         cb_data);
1195         RETURN(rc);
1196 }
1197
1198 static inline int md_getattr_name(struct obd_export *exp, struct ll_fid *fid,
1199                                   char *filename, int namelen,
1200                                   unsigned long valid, unsigned int ea_size,
1201                                   struct ptlrpc_request **request)
1202 {
1203         int rc;
1204         ENTRY;
1205         EXP_CHECK_MD_OP(exp, getattr_name);
1206         MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1207         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1208                                              valid, ea_size, request);
1209         RETURN(rc);
1210 }
1211
1212 static inline int md_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
1213                                  struct ll_fid *pfid, const char *name,
1214                                  int len, void *lmm, int lmmsize,
1215                                  struct ll_fid *cfid, struct lookup_intent *it,
1216                                  int flags, struct ptlrpc_request **reqp,
1217                                  ldlm_blocking_callback cb_blocking)
1218 {
1219         int rc;
1220         ENTRY;
1221         EXP_CHECK_MD_OP(exp, intent_lock);
1222         MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1223         rc = MDP(exp->exp_obd, intent_lock)(exp, uctxt, pfid, name, len,
1224                                             lmm, lmmsize, cfid, it, flags,
1225                                             reqp, cb_blocking);
1226         RETURN(rc);
1227 }
1228
1229 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1230                           struct ptlrpc_request **request)
1231 {
1232         int rc;
1233         ENTRY;
1234         EXP_CHECK_MD_OP(exp, link);
1235         MD_COUNTER_INCREMENT(exp->exp_obd, link);
1236         rc = MDP(exp->exp_obd, link)(exp, data, request);
1237         RETURN(rc);
1238 }
1239
1240 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1241                             const char *old, int oldlen,
1242                             const char *new, int newlen,
1243                             struct ptlrpc_request **request)
1244 {
1245         int rc;
1246         ENTRY;
1247         EXP_CHECK_MD_OP(exp, rename);
1248         MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1249         rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1250                                        newlen, request);
1251         RETURN(rc);
1252 }
1253
1254 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1255                              struct iattr *iattr, void *ea, int ealen,
1256                              void *ea2, int ea2len,
1257                              struct ptlrpc_request **request)
1258 {
1259         int rc;
1260         ENTRY;
1261         EXP_CHECK_MD_OP(exp, setattr);
1262         MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1263         rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1264                                         ea2, ea2len, request);
1265         RETURN(rc);
1266 }
1267
1268 static inline int md_sync(struct obd_export *exp, struct ll_fid *fid,
1269                                struct ptlrpc_request **request)
1270 {
1271         int rc;
1272         ENTRY;
1273         EXP_CHECK_MD_OP(exp, sync);
1274         MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1275         rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1276         RETURN(rc);
1277 }
1278
1279 static inline int md_readpage(struct obd_export *exp, struct ll_fid *fid,
1280                               __u64 offset, struct page *page,
1281                               struct ptlrpc_request **request)
1282 {
1283         int rc;
1284         ENTRY;
1285         EXP_CHECK_MD_OP(exp, readpage);
1286         MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1287         rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1288         RETURN(rc);
1289 }
1290
1291 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1292                             struct ptlrpc_request **request)
1293 {
1294         int rc;
1295         ENTRY;
1296         EXP_CHECK_MD_OP(exp, unlink);
1297         MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1298         rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1299         RETURN(rc);
1300 }
1301
1302 static inline struct obd_device * md_get_real_obd(struct obd_export *exp,
1303                                                   char *name, int len)
1304 {
1305         ENTRY;
1306         if (MDP(exp->exp_obd, get_real_obd) == NULL)
1307                 return exp->exp_obd;
1308         MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1309         return MDP(exp->exp_obd, get_real_obd)(exp, name, len);
1310 }
1311
1312 static inline int md_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
1313 {
1314         ENTRY;
1315         EXP_CHECK_MD_OP(exp, valid_attrs);
1316         MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1317         return MDP(exp->exp_obd, valid_attrs)(exp, fid);
1318 }
1319
1320 static inline int md_req2lustre_md(struct obd_export *exp,
1321                                    struct ptlrpc_request *req,
1322                                    unsigned int offset,
1323                                    struct obd_export *osc_exp,
1324                                    struct lustre_md *md)
1325 {
1326         ENTRY;
1327         EXP_CHECK_MD_OP(exp, req2lustre_md);
1328         MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1329         return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1330 }
1331
1332 static inline int md_set_open_replay_data(struct obd_export *exp,
1333                                           struct obd_client_handle *och,
1334                                           struct ptlrpc_request *open_req)
1335 {
1336         ENTRY;
1337         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1338         MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1339         return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1340 }
1341
1342 static inline int md_clear_open_replay_data(struct obd_export *exp,
1343                                             struct obd_client_handle *och)
1344 {
1345         ENTRY;
1346         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1347         MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1348         return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1349 }
1350
1351 static inline int md_store_inode_generation(struct obd_export *exp,
1352                                             struct ptlrpc_request *req,
1353                                             int reqoff, int repoff)
1354 {
1355         ENTRY;
1356         EXP_CHECK_MD_OP(exp, store_inode_generation);
1357         MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1358         return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1359                    reqoff, repoff);
1360 }
1361
1362 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1363 {
1364         ENTRY;
1365         EXP_CHECK_MD_OP(exp, set_lock_data);
1366         MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1367         return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1368 }
1369
1370 /* OBD Metadata Support */
1371
1372 extern int obd_init_caches(void);
1373 extern void obd_cleanup_caches(void);
1374
1375 /* support routines */
1376 extern kmem_cache_t *obdo_cachep;
1377 static inline struct obdo *obdo_alloc(void)
1378 {
1379         struct obdo *oa;
1380
1381         oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1382         if (oa == NULL)
1383                 LBUG();
1384         CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1385         memset(oa, 0, sizeof (*oa));
1386
1387         return oa;
1388 }
1389
1390 static inline void obdo_free(struct obdo *oa)
1391 {
1392         if (!oa)
1393                 return;
1394         CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1395         kmem_cache_free(obdo_cachep, oa);
1396 }
1397
1398 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1399 #define to_kdev_t(dev) dev
1400 #define kdev_t_to_nr(dev) dev
1401 #endif
1402
1403 /* I'm as embarrassed about this as you are.
1404  *
1405  * <shaver> // XXX do not look into _superhack with remaining eye
1406  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1407 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1408 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1409
1410 /* sysctl.c */
1411 extern void obd_sysctl_init (void);
1412 extern void obd_sysctl_clean (void);
1413
1414 /* uuid.c  */
1415 typedef __u8 class_uuid_t[16];
1416 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1417 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1418
1419 /* lustre_peer.c    */
1420 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1421 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1422 int class_del_uuid (char *uuid);
1423 void class_init_uuidlist(void);
1424 void class_exit_uuidlist(void);
1425
1426 /* mea.c */
1427 int mea_name2idx(struct mea *mea, char *name, int namelen);
1428 int raw_name2idx(int count, const char *name, int namelen);
1429
1430 #endif /* __LINUX_OBD_CLASS_H */