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