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