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