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