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