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