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