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