Whamcloud - gitweb
ffa37277f674029f1472f9c55e9da1c61cc130eb
[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                               struct lustre_capa *capa)
558 {
559         int rc;
560         ENTRY;
561
562         EXP_CHECK_OP(exp, setattr);
563         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
564
565         rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti, capa);
566         RETURN(rc);
567 }
568 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
569                                int priority)
570 {
571         struct obd_device *obd = imp->imp_obd;
572         int rc;
573         ENTRY;
574
575         OBD_CHECK_DEV_ACTIVE(obd);
576         OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
577         OBD_COUNTER_INCREMENT(obd, add_conn);
578
579         rc = OBP(obd, add_conn)(imp, uuid, priority);
580         RETURN(rc);
581 }
582
583 static inline int obd_del_conn(struct obd_import *imp,
584                                struct obd_uuid *uuid)
585 {
586         struct obd_device *obd = imp->imp_obd;
587         int rc;
588         ENTRY;
589
590         OBD_CHECK_DEV_ACTIVE(obd);
591         OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
592         OBD_COUNTER_INCREMENT(obd, del_conn);
593
594         rc = OBP(obd, del_conn)(imp, uuid);
595         RETURN(rc);
596 }
597
598
599 static inline int obd_connect(struct lustre_handle *conn,
600                               struct obd_device *obd,
601                               struct obd_uuid *cluuid,
602                               struct obd_connect_data *data,
603                               unsigned long flags)
604 {
605         int rc;
606         ENTRY;
607
608         OBD_CHECK_DEV_ACTIVE(obd);
609         OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
610         OBD_COUNTER_INCREMENT(obd, connect);
611
612         rc = OBP(obd, connect)(conn, obd, cluuid, data, flags);
613         RETURN(rc);
614 }
615
616 static inline int obd_connect_post(struct obd_export *exp,
617                                    unsigned initial,
618                                    unsigned long flags)
619 {
620         int rc;
621         ENTRY;
622
623         OBD_CHECK_DEV_ACTIVE(exp->exp_obd);
624         if (!OBT(exp->exp_obd) || !OBP((exp->exp_obd), connect_post))
625                 RETURN(0);
626         OBD_COUNTER_INCREMENT(exp->exp_obd, connect_post);
627         rc = OBP(exp->exp_obd, connect_post)(exp, initial, flags);
628         RETURN(rc);
629 }
630
631 static inline int obd_disconnect(struct obd_export *exp,
632                                  unsigned long flags)
633 {
634         int rc;
635         ENTRY;
636
637         EXP_CHECK_OP(exp, disconnect);
638         OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
639
640         rc = OBP(exp->exp_obd, disconnect)(exp, flags);
641         RETURN(rc);
642 }
643
644 static inline int obd_init_export(struct obd_export *exp)
645 {
646         int rc = 0;
647
648         ENTRY;
649         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
650             OBP((exp)->exp_obd, init_export))
651                 rc = OBP(exp->exp_obd, init_export)(exp);
652         RETURN(rc);
653 }
654
655 static inline int obd_destroy_export(struct obd_export *exp)
656 {
657         ENTRY;
658         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
659             OBP((exp)->exp_obd, destroy_export))
660                 OBP(exp->exp_obd, destroy_export)(exp);
661         RETURN(0);
662 }
663
664 static inline struct dentry *
665 obd_lvfs_id2dentry(struct obd_export *exp, __u64 ino, 
666                    __u32 gen, __u64 gr)
667 {
668         LASSERT(exp->exp_obd);
669
670         return lvfs_id2dentry(&exp->exp_obd->obd_lvfs_ctxt, 
671                               ino, gen, gr, exp->exp_obd);
672 }
673
674 #ifndef time_before
675 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
676 #endif
677
678 /* @max_age is the oldest time in jiffies that we accept using a cached data.
679  * If the cache is older than @max_age we will get a new value from the
680  * target.  Use a value of "jiffies + HZ" to guarantee freshness. */
681 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
682                              unsigned long max_age)
683 {
684         int rc = 0;
685         ENTRY;
686
687         if (obd == NULL)
688                 RETURN(-EINVAL);
689
690         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
691         OBD_COUNTER_INCREMENT(obd, statfs);
692
693         CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
694         if (time_before(obd->obd_osfs_age, max_age)) {
695                 rc = OBP(obd, statfs)(obd, osfs, max_age);
696                 if (rc == 0) {
697                         spin_lock(&obd->obd_osfs_lock);
698                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
699                         obd->obd_osfs_age = jiffies;
700                         spin_unlock(&obd->obd_osfs_lock);
701                 }
702         } else {
703                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
704                 spin_lock(&obd->obd_osfs_lock);
705                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
706                 spin_unlock(&obd->obd_osfs_lock);
707         }
708         RETURN(rc);
709 }
710
711 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
712                            struct lov_stripe_md *ea, obd_size start,
713                            obd_size end)
714 {
715         int rc;
716         ENTRY;
717
718         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
719         OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
720
721         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
722         RETURN(rc);
723 }
724
725 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
726                             struct lov_stripe_md *ea, obd_size start,
727                             obd_size end, struct obd_trans_info *oti,
728                             struct lustre_capa *capa)
729 {
730         int rc;
731         ENTRY;
732
733         EXP_CHECK_OP(exp, punch);
734         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
735
736         rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti, capa);
737         RETURN(rc);
738 }
739
740 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
741                           struct lov_stripe_md *ea, obd_count oa_bufs,
742                           struct brw_page *pg, struct obd_trans_info *oti)
743 {
744         int rc;
745         ENTRY;
746
747         EXP_CHECK_OP(exp, brw);
748         OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
749
750         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
751                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
752                        "or OBD_BRW_CHECK\n");
753                 LBUG();
754         }
755
756         rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
757         RETURN(rc);
758 }
759
760 static inline int obd_brw_async(int cmd, struct obd_export *exp,
761                                 struct obdo *oa, struct lov_stripe_md *ea,
762                                 obd_count oa_bufs, struct brw_page *pg,
763                                 struct ptlrpc_request_set *set,
764                                 struct obd_trans_info *oti)
765 {
766         int rc;
767         ENTRY;
768
769         EXP_CHECK_OP(exp, brw_async);
770         OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
771
772         if (!(cmd & OBD_BRW_RWMASK)) {
773                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
774                 LBUG();
775         }
776
777         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
778                                           oti);
779         RETURN(rc);
780 }
781
782 static inline int obd_prep_async_page(struct obd_export *exp,
783                                       struct lov_stripe_md *lsm,
784                                       struct lov_oinfo *loi,
785                                       struct page *page, obd_off offset,
786                                       struct obd_async_page_ops *ops,
787                                       void *data, void **res)
788 {
789         int ret;
790         ENTRY;
791
792         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
793         OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
794
795         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
796                                                  ops, data, res);
797         RETURN(ret);
798 }
799
800 static inline int obd_queue_async_io(struct obd_export *exp,
801                                      struct lov_stripe_md *lsm,
802                                      struct lov_oinfo *loi, void *cookie,
803                                      int cmd, obd_off off, int count,
804                                      obd_flags brw_flags, obd_flags async_flags)
805 {
806         int rc;
807         ENTRY;
808
809         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
810         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
811         LASSERT(cmd & OBD_BRW_RWMASK);
812
813         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
814                                                count, brw_flags, async_flags);
815         RETURN(rc);
816 }
817
818 static inline int obd_set_async_flags(struct obd_export *exp,
819                                       struct lov_stripe_md *lsm,
820                                       struct lov_oinfo *loi, void *cookie,
821                                       obd_flags async_flags)
822 {
823         int rc;
824         ENTRY;
825
826         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
827         OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
828
829         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
830                                                 async_flags);
831         RETURN(rc);
832 }
833
834 static inline int obd_queue_group_io(struct obd_export *exp,
835                                      struct lov_stripe_md *lsm,
836                                      struct lov_oinfo *loi,
837                                      struct obd_io_group *oig,
838                                      void *cookie, int cmd, obd_off off,
839                                      int count, obd_flags brw_flags,
840                                      obd_flags async_flags)
841 {
842         int rc;
843         ENTRY;
844
845         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
846         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
847         LASSERT(cmd & OBD_BRW_RWMASK);
848
849         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
850                                                cmd, off, count, brw_flags,
851                                                async_flags);
852         RETURN(rc);
853 }
854
855 static inline int obd_trigger_group_io(struct obd_export *exp,
856                                        struct lov_stripe_md *lsm,
857                                        struct lov_oinfo *loi,
858                                        struct obd_io_group *oig)
859 {
860         int rc;
861         ENTRY;
862
863         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
864         OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
865
866         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
867         RETURN(rc);
868 }
869
870 static inline int obd_teardown_async_page(struct obd_export *exp,
871                                           struct lov_stripe_md *lsm,
872                                           struct lov_oinfo *loi, void *cookie)
873 {
874         int rc;
875         ENTRY;
876
877         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
878         OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
879
880         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
881         RETURN(rc);
882 }
883
884 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
885                              int objcount, struct obd_ioobj *obj,
886                              int niocount, struct niobuf_remote *remote,
887                              struct niobuf_local *local,
888                              struct obd_trans_info *oti,
889                              struct lustre_capa *capa)
890 {
891         int rc;
892         ENTRY;
893
894         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
895         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
896
897         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
898                                        remote, local, oti, capa);
899         RETURN(rc);
900 }
901
902 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
903                                int objcount, struct obd_ioobj *obj,
904                                int niocount, struct niobuf_local *local,
905                                struct obd_trans_info *oti, int rc)
906 {
907         ENTRY;
908
909         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
910         OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
911
912         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
913                                          local, oti, rc);
914         RETURN(rc);
915 }
916
917 static inline int obd_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
918                             int objcount,struct niobuf_remote *rnb)
919 {
920         int rc;
921         ENTRY;
922
923         /* there are cases when write_extents is not implemented. */
924         if (!OBP(exp->exp_obd, do_cow))
925                 RETURN(0);
926                 
927         OBD_COUNTER_INCREMENT(exp->exp_obd, do_cow);
928
929         rc = OBP(exp->exp_obd, do_cow)(exp, obj, objcount, rnb);
930
931         RETURN(rc);
932 }
933
934 static inline int obd_write_extents(struct obd_export *exp, 
935                                     struct obd_ioobj *obj,
936                                     int objcount, int niocount,  
937                                     struct niobuf_local *local, 
938                                     int rc)
939 {
940         ENTRY;
941
942         /* there are cases when write_extents is not implemented. */
943         if (!OBP(exp->exp_obd, write_extents))
944                 RETURN(0);
945                 
946         OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
947
948         rc = OBP(exp->exp_obd, write_extents)(exp, obj, objcount, niocount, 
949                                               local, rc);
950         RETURN(rc);
951 }
952
953 static inline int obd_adjust_kms(struct obd_export *exp,
954                                  struct lov_stripe_md *lsm,
955                                  obd_off size, int shrink)
956 {
957         int rc;
958         ENTRY;
959
960         OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
961         OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
962
963         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
964         RETURN(rc);
965 }
966
967 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
968                                 int len, void *karg, void *uarg)
969 {
970         int rc;
971         ENTRY;
972
973         EXP_CHECK_OP(exp, iocontrol);
974         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
975
976         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
977         RETURN(rc);
978 }
979
980 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
981                               __u32 type, ldlm_policy_data_t *policy,
982                               __u32 mode, int *flags, void *bl_cb, void *cp_cb,
983                               void *gl_cb, void *data, __u32 lvb_len,
984                               void *lvb_swabber, struct lustre_handle *lockh)
985 {
986         int rc;
987         ENTRY;
988
989         EXP_CHECK_OP(exp, enqueue);
990         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
991
992         rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
993                                         bl_cb, cp_cb, gl_cb, data, lvb_len,
994                                         lvb_swabber, lockh);
995         RETURN(rc);
996 }
997
998 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
999                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1000                             int *flags, void *data, struct lustre_handle *lockh)
1001 {
1002         int rc;
1003         ENTRY;
1004
1005         EXP_CHECK_OP(exp, match);
1006         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1007
1008         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1009                                       lockh);
1010         RETURN(rc);
1011 }
1012
1013 static inline int obd_change_cbdata(struct obd_export *exp,
1014                                     struct lov_stripe_md *lsm,
1015                                     ldlm_iterator_t it, void *data)
1016 {
1017         int rc;
1018         ENTRY;
1019
1020         EXP_CHECK_OP(exp, change_cbdata);
1021         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1022
1023         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1024         RETURN(rc);
1025 }
1026
1027 static inline int obd_cancel(struct obd_export *exp,
1028                              struct lov_stripe_md *ea, __u32 mode,
1029                              struct lustre_handle *lockh)
1030 {
1031         int rc;
1032         ENTRY;
1033
1034         EXP_CHECK_OP(exp, cancel);
1035         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1036
1037         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1038         RETURN(rc);
1039 }
1040
1041 static inline int obd_cancel_unused(struct obd_export *exp,
1042                                     struct lov_stripe_md *ea, int flags,
1043                                     void *opaque)
1044 {
1045         int rc;
1046         ENTRY;
1047
1048         EXP_CHECK_OP(exp, cancel_unused);
1049         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1050
1051         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1052         RETURN(rc);
1053 }
1054
1055
1056 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1057                                  struct obdo *oa,
1058                                  int objcount, struct obd_ioobj *obj,
1059                                  int niocount, struct niobuf_remote *remote)
1060 {
1061         int rc;
1062
1063         EXP_CHECK_OP(exp, preprw);
1064         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1065
1066         rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1067                                            niocount, remote);
1068         class_export_put(exp);
1069         return(rc);
1070 }
1071
1072 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1073                           int type, struct obd_client_handle *handle, int flag)
1074 {
1075         int rc;
1076
1077         EXP_CHECK_OP(exp, pin);
1078         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1079
1080         rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1081         return(rc);
1082 }
1083
1084 static inline int obd_unpin(struct obd_export *exp,
1085                             struct obd_client_handle *handle, int flag)
1086 {
1087         int rc;
1088
1089         EXP_CHECK_OP(exp, unpin);
1090         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1091
1092         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1093         return(rc);
1094 }
1095
1096
1097 static inline void obd_import_event(struct obd_device *obd,
1098                                     struct obd_import *imp,
1099                                     enum obd_import_event event)
1100 {
1101         if (!obd) {
1102                 CERROR("NULL device\n");
1103                 EXIT;
1104                 return;
1105         }
1106         if (obd->obd_set_up && OBP(obd, import_event)) {
1107                 OBD_COUNTER_INCREMENT(obd, import_event);
1108                 OBP(obd, import_event)(obd, imp, event);
1109         }
1110 }
1111
1112 static inline int obd_llog_connect(struct obd_export *exp,
1113                                         struct llogd_conn_body *body)
1114 {
1115         ENTRY;
1116         EXP_CHECK_OP(exp, llog_connect);
1117         return OBP(exp->exp_obd, llog_connect)(exp, body);
1118 }
1119
1120 static inline int obd_notify(struct obd_device *obd, struct obd_device *watched,
1121                              int active, void *data)
1122 {
1123         OBD_CHECK_DEV(obd);
1124         if (!obd->obd_set_up) {
1125                 CERROR("obd %s not set up\n", obd->obd_name);
1126                 return -EINVAL;
1127         }
1128
1129         if (!OBP(obd, notify)) {
1130                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1131                 return -ENOSYS;
1132         }
1133
1134         OBD_COUNTER_INCREMENT(obd, notify);
1135         return OBP(obd, notify)(obd, watched, active, data);
1136 }
1137
1138 static inline int obd_register_observer(struct obd_device *obd,
1139                                         struct obd_device *observer)
1140 {
1141         ENTRY;
1142         OBD_CHECK_DEV(obd);
1143         if (obd->obd_observer && observer)
1144                 RETURN(-EALREADY);
1145         obd->obd_observer = observer;
1146         RETURN(0);
1147 }
1148
1149 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1150 {
1151         int rc;
1152         ENTRY;
1153         LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1154         OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1155         rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1156         RETURN(rc);
1157 }
1158
1159 static inline int md_getstatus(struct obd_export *exp, struct lustre_id *id)
1160 {
1161         int rc;
1162
1163         EXP_CHECK_MD_OP(exp, getstatus);
1164         MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1165         rc = MDP(exp->exp_obd, getstatus)(exp, id);
1166         RETURN(rc);
1167 }
1168
1169 static inline int md_delete_inode(struct obd_export *exp,
1170                                   struct lustre_id *id)
1171 {
1172         int rc;
1173         ENTRY;
1174
1175         if (MDP(exp->exp_obd, delete_inode) == NULL)
1176                 RETURN(0);
1177         
1178         MD_COUNTER_INCREMENT(exp->exp_obd, delete_inode);
1179         rc = MDP(exp->exp_obd, delete_inode)(exp, id);
1180         RETURN(rc);
1181 }
1182
1183 static inline int md_getattr(struct obd_export *exp, struct lustre_id *id,
1184                              __u64 valid, const char *xattr_name,
1185                              const void *xattr_data, unsigned int xattr_datalen,
1186                              unsigned int ea_size, struct obd_capa *ocapa,
1187                              struct ptlrpc_request **request)
1188 {
1189         int rc;
1190         ENTRY;
1191         EXP_CHECK_MD_OP(exp, getattr);
1192         MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1193         rc = MDP(exp->exp_obd, getattr)(exp, id, valid, xattr_name,
1194                                         xattr_data, xattr_datalen,
1195                                         ea_size, ocapa, request);
1196         RETURN(rc);
1197 }
1198
1199 static inline int md_access_check(struct obd_export *exp, struct lustre_id *id,
1200                                   struct ptlrpc_request **request)
1201 {
1202         int rc;
1203         ENTRY;
1204         EXP_CHECK_MD_OP(exp, access_check);
1205         MD_COUNTER_INCREMENT(exp->exp_obd, access_check);
1206         rc = MDP(exp->exp_obd, access_check)(exp, id, request);
1207         RETURN(rc);
1208 }
1209
1210 static inline int md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
1211                                    ldlm_iterator_t it, void *data)
1212 {
1213         int rc;
1214         ENTRY;
1215         EXP_CHECK_MD_OP(exp, change_cbdata);
1216         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1217         rc = MDP(exp->exp_obd, change_cbdata)(exp, id, it, data);
1218         RETURN(rc);
1219 }
1220
1221 static inline int md_change_cbdata_name(struct obd_export *exp,
1222                                         struct lustre_id *id, char *name,
1223                                         int namelen, struct lustre_id *id2,
1224                                         ldlm_iterator_t it, void *data)
1225 {
1226         int rc;
1227         
1228         /* this seem to be needed only for lmv. */
1229         if (!MDP(exp->exp_obd, change_cbdata_name))
1230                 return 0;
1231         
1232         ENTRY;
1233                 
1234         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1235         rc = MDP(exp->exp_obd, change_cbdata_name)(exp, id, name, namelen,
1236                                                    id2, it, data);
1237         RETURN(rc);
1238 }
1239
1240 static inline int md_close(struct obd_export *exp,
1241                            struct mdc_op_data *op_data,
1242                            struct obd_client_handle *och,
1243                            struct ptlrpc_request **request)
1244 {
1245         int rc;
1246         ENTRY;
1247         EXP_CHECK_MD_OP(exp, close);
1248         MD_COUNTER_INCREMENT(exp->exp_obd, close);
1249         rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1250         RETURN(rc);
1251 }
1252
1253 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1254                             const void *data, int datalen, int mode,
1255                             __u32 uid, __u32 gid, __u64 rdev,
1256                             struct ptlrpc_request **request)
1257 {
1258         int rc;
1259         ENTRY;
1260         EXP_CHECK_MD_OP(exp, create);
1261         MD_COUNTER_INCREMENT(exp->exp_obd, create);
1262         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1263                                        uid, gid, rdev, request);
1264         RETURN(rc);
1265 }
1266
1267 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1268 {
1269         int rc;
1270         ENTRY;
1271         EXP_CHECK_MD_OP(exp, done_writing);
1272         MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1273         rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1274         RETURN(rc);
1275 }
1276
1277 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1278                              struct lookup_intent *it, int lock_mode,
1279                              struct mdc_op_data *data,
1280                              struct lustre_handle *lockh,
1281                              void *lmm, int lmmsize,
1282                              ldlm_completion_callback cb_completion,
1283                              ldlm_blocking_callback cb_blocking,
1284                              void *cb_data)
1285 {
1286         int rc;
1287         ENTRY;
1288         EXP_CHECK_MD_OP(exp, enqueue);
1289         MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1290         rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1291                                         data, lockh, lmm, lmmsize,
1292                                         cb_completion, cb_blocking,
1293                                         cb_data);
1294         RETURN(rc);
1295 }
1296
1297 static inline int md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
1298                                   char *filename, int namelen,
1299                                   __u64 valid, unsigned int ea_size,
1300                                   struct ptlrpc_request **request)
1301 {
1302         int rc;
1303         ENTRY;
1304         EXP_CHECK_MD_OP(exp, getattr_lock);
1305         MD_COUNTER_INCREMENT(exp->exp_obd, getattr_lock);
1306         rc = MDP(exp->exp_obd, getattr_lock)(exp, id, filename, namelen,
1307                                              valid, ea_size, request);
1308         RETURN(rc);
1309 }
1310
1311 static inline int md_intent_lock(struct obd_export *exp,
1312                                  struct lustre_id *pid, const char *name,
1313                                  int len, void *lmm, int lmmsize,
1314                                  struct lustre_id *cid,
1315                                  struct lookup_intent *it,
1316                                  int flags, struct ptlrpc_request **reqp,
1317                                  ldlm_blocking_callback cb_blocking)
1318 {
1319         int rc;
1320         ENTRY;
1321         EXP_CHECK_MD_OP(exp, intent_lock);
1322         MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1323         rc = MDP(exp->exp_obd, intent_lock)(exp, pid, name, len, lmm,
1324                                             lmmsize, cid, it, flags,
1325                                             reqp, cb_blocking);
1326         RETURN(rc);
1327 }
1328
1329 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1330                           struct ptlrpc_request **request)
1331 {
1332         int rc;
1333         ENTRY;
1334         EXP_CHECK_MD_OP(exp, link);
1335         MD_COUNTER_INCREMENT(exp->exp_obd, link);
1336         rc = MDP(exp->exp_obd, link)(exp, data, request);
1337         RETURN(rc);
1338 }
1339
1340 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1341                             const char *old, int oldlen,
1342                             const char *new, int newlen,
1343                             struct ptlrpc_request **request)
1344 {
1345         int rc;
1346         ENTRY;
1347         EXP_CHECK_MD_OP(exp, rename);
1348         MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1349         rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1350                                        newlen, request);
1351         RETURN(rc);
1352 }
1353
1354 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1355                              struct iattr *iattr, void *ea, int ealen,
1356                              void *ea2, int ea2len, void *ea3, int ea3len,
1357                              struct ptlrpc_request **request)
1358 {
1359         int rc;
1360         ENTRY;
1361         EXP_CHECK_MD_OP(exp, setattr);
1362         MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1363         rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1364                                         ea2, ea2len, ea3, ea3len, request);
1365         RETURN(rc);
1366 }
1367
1368 static inline int md_sync(struct obd_export *exp, struct lustre_id *id,
1369                                struct ptlrpc_request **request)
1370 {
1371         int rc;
1372         ENTRY;
1373         EXP_CHECK_MD_OP(exp, sync);
1374         MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1375         rc = MDP(exp->exp_obd, sync)(exp, id, request);
1376         RETURN(rc);
1377 }
1378
1379 static inline int md_readpage(struct obd_export *exp, struct lustre_id *id,
1380                               __u64 offset, struct page *page,
1381                               struct ptlrpc_request **request)
1382 {
1383         int rc;
1384         ENTRY;
1385         EXP_CHECK_MD_OP(exp, readpage);
1386         MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1387         rc = MDP(exp->exp_obd, readpage)(exp, id, offset, page, request);
1388         RETURN(rc);
1389 }
1390
1391 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1392                             struct ptlrpc_request **request)
1393 {
1394         int rc;
1395         ENTRY;
1396         EXP_CHECK_MD_OP(exp, unlink);
1397         MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1398         rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1399         RETURN(rc);
1400 }
1401
1402 static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
1403                                                  struct lustre_id *fid)
1404 {
1405         ENTRY;
1406         if (MDP(exp->exp_obd, get_real_obd) == NULL)
1407                 return exp->exp_obd;
1408         MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1409         return MDP(exp->exp_obd, get_real_obd)(exp, fid);
1410 }
1411
1412 static inline int md_valid_attrs(struct obd_export *exp,
1413                                  struct lustre_id *id)
1414 {
1415         ENTRY;
1416         EXP_CHECK_MD_OP(exp, valid_attrs);
1417         MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1418         return MDP(exp->exp_obd, valid_attrs)(exp, id);
1419 }
1420
1421 static inline int md_req2lustre_md(struct obd_export *exp,
1422                                    struct ptlrpc_request *req,
1423                                    unsigned int offset,
1424                                    struct obd_export *osc_exp,
1425                                    struct lustre_md *md)
1426 {
1427         ENTRY;
1428         EXP_CHECK_MD_OP(exp, req2lustre_md);
1429         MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1430         return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1431 }
1432
1433 static inline int md_set_open_replay_data(struct obd_export *exp,
1434                                           struct obd_client_handle *och,
1435                                           struct ptlrpc_request *open_req)
1436 {
1437         ENTRY;
1438         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1439         MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1440         return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1441 }
1442
1443 static inline int md_clear_open_replay_data(struct obd_export *exp,
1444                                             struct obd_client_handle *och)
1445 {
1446         ENTRY;
1447         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1448         MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1449         return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1450 }
1451
1452 static inline int md_store_inode_generation(struct obd_export *exp,
1453                                             struct ptlrpc_request *req,
1454                                             int reqoff, int repoff)
1455 {
1456         ENTRY;
1457         EXP_CHECK_MD_OP(exp, store_inode_generation);
1458         MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1459         return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1460                    reqoff, repoff);
1461 }
1462
1463 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l,
1464                                    void *data)
1465 {
1466         ENTRY;
1467         EXP_CHECK_MD_OP(exp, set_lock_data);
1468         MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1469         return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1470 }
1471
1472 /* OBD Metadata Support */
1473
1474 extern int obd_init_caches(void);
1475 extern void obd_cleanup_caches(void);
1476
1477 /* support routines */
1478 extern kmem_cache_t *obdo_cachep;
1479 static inline struct obdo *obdo_alloc(void)
1480 {
1481         struct obdo *oa;
1482
1483         OBD_SLAB_ALLOC(oa, obdo_cachep, GFP_KERNEL,
1484                        sizeof(*oa));
1485         return oa;
1486 }
1487
1488 static inline void obdo_free(struct obdo *oa)
1489 {
1490         OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1491 }
1492
1493 static inline void obdo2id(struct lustre_id *id,
1494                            struct obdo *oa)
1495 {
1496         LASSERT(oa && id);
1497         id_ino(id) = oa->o_id;
1498         id_fid(id) = oa->o_fid;
1499         id_group(id) = oa->o_mds;
1500         id_gen(id) = oa->o_generation;
1501 }
1502
1503 static inline void id2obdo(struct obdo *oa,
1504                            struct lustre_id *id)
1505 {
1506         LASSERT(oa && id);
1507         oa->o_id = id_ino(id);
1508         oa->o_fid = id_fid(id);
1509         oa->o_mds = id_group(id);
1510         oa->o_generation = id_gen(id);
1511 }
1512
1513 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1514 #define to_kdev_t(dev) dev
1515 #define kdev_t_to_nr(dev) dev
1516 #endif
1517
1518 /* I'm as embarrassed about this as you are.
1519  *
1520  * <shaver> // XXX do not look into _superhack with remaining eye
1521  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1522 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1523 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1524
1525 /* sysctl.c */
1526 extern void obd_sysctl_init (void);
1527 extern void obd_sysctl_clean (void);
1528
1529 /* uuid.c  */
1530 typedef __u8 class_uuid_t[16];
1531 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1532 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1533
1534 /* lustre_peer.c    */
1535 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1536 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1537 int class_del_uuid (char *uuid);
1538 void class_init_uuidlist(void);
1539 void class_exit_uuidlist(void);
1540
1541 /* mea.c */
1542 int mea_name2idx(struct mea *mea, char *name, int namelen);
1543 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1544
1545 #endif /* __LINUX_OBD_CLASS_H */