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