Whamcloud - gitweb
- added md_delete_object() and lmv_delete_object(). This is needed to remove LMV...
[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_write_extents(struct obd_export *exp, struct obd_ioobj *obj,
906                                     int niocount, struct niobuf_local *local, int rc)
907 {
908         ENTRY;
909
910         /* there are cases when write_extents is not implemented. */
911         if (!OBP(exp->exp_obd, write_extents))
912                 RETURN(0);
913                 
914         OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
915
916         rc = OBP(exp->exp_obd, write_extents)(exp, obj, niocount, local, rc);
917         RETURN(rc);
918 }
919
920 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
921                                 int len, void *karg, void *uarg)
922 {
923         int rc;
924         ENTRY;
925
926         EXP_CHECK_OP(exp, iocontrol);
927         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
928
929         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
930         RETURN(rc);
931 }
932
933 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
934                               __u32 type, ldlm_policy_data_t *policy,
935                               __u32 mode, int *flags, void *bl_cb, void *cp_cb,
936                               void *gl_cb, void *data, __u32 lvb_len,
937                               void *lvb_swabber, struct lustre_handle *lockh)
938 {
939         int rc;
940         ENTRY;
941
942         EXP_CHECK_OP(exp, enqueue);
943         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
944
945         rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
946                                         bl_cb, cp_cb, gl_cb, data, lvb_len,
947                                         lvb_swabber, lockh);
948         RETURN(rc);
949 }
950
951 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
952                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
953                             int *flags, void *data, struct lustre_handle *lockh)
954 {
955         int rc;
956         ENTRY;
957
958         EXP_CHECK_OP(exp, match);
959         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
960
961         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
962                                       lockh);
963         RETURN(rc);
964 }
965
966 static inline int obd_change_cbdata(struct obd_export *exp,
967                                     struct lov_stripe_md *lsm,
968                                     ldlm_iterator_t it, void *data)
969 {
970         int rc;
971         ENTRY;
972
973         EXP_CHECK_OP(exp, change_cbdata);
974         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
975
976         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
977         RETURN(rc);
978 }
979
980 static inline int obd_cancel(struct obd_export *exp,
981                              struct lov_stripe_md *ea, __u32 mode,
982                              struct lustre_handle *lockh)
983 {
984         int rc;
985         ENTRY;
986
987         EXP_CHECK_OP(exp, cancel);
988         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
989
990         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
991         RETURN(rc);
992 }
993
994 static inline int obd_cancel_unused(struct obd_export *exp,
995                                     struct lov_stripe_md *ea, int flags,
996                                     void *opaque)
997 {
998         int rc;
999         ENTRY;
1000
1001         EXP_CHECK_OP(exp, cancel_unused);
1002         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1003
1004         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1005         RETURN(rc);
1006 }
1007
1008
1009 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1010                                  struct obdo *oa,
1011                                  int objcount, struct obd_ioobj *obj,
1012                                  int niocount, struct niobuf_remote *remote)
1013 {
1014         int rc;
1015
1016         EXP_CHECK_OP(exp, preprw);
1017         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1018
1019         rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1020                                            niocount, remote);
1021         class_export_put(exp);
1022         return(rc);
1023 }
1024
1025 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1026                           int type, struct obd_client_handle *handle, int flag)
1027 {
1028         int rc;
1029
1030         EXP_CHECK_OP(exp, pin);
1031         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1032
1033         rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1034         return(rc);
1035 }
1036
1037 static inline int obd_unpin(struct obd_export *exp,
1038                             struct obd_client_handle *handle, int flag)
1039 {
1040         int rc;
1041
1042         EXP_CHECK_OP(exp, unpin);
1043         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1044
1045         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1046         return(rc);
1047 }
1048
1049
1050 static inline void obd_import_event(struct obd_device *obd,
1051                                     struct obd_import *imp,
1052                                     enum obd_import_event event)
1053 {
1054         if (obd->obd_set_up && OBP(obd, import_event)) {
1055                 OBD_COUNTER_INCREMENT(obd, import_event);
1056                 OBP(obd, import_event)(obd, imp, event);
1057         }
1058 }
1059
1060 static inline int obd_llog_connect(struct obd_device *obd,
1061                                         struct llogd_conn_body *body)
1062 {
1063         ENTRY;
1064         if (!obd->obd_set_up) {
1065                 CERROR("obd %s not set up\n", obd->obd_name);
1066                 return -EINVAL;
1067         }
1068
1069         if (!OBP(obd, llog_connect)) {
1070                 CERROR("obd %s has no llog_connect handler\n", obd->obd_name);
1071                 return -ENOSYS;
1072         }
1073
1074         return OBP(obd, llog_connect)(obd, body);
1075 }
1076
1077 static inline int obd_notify(struct obd_device *obd,
1078                              struct obd_device *watched,
1079                              int active)
1080 {
1081         if (!obd->obd_set_up) {
1082                 CERROR("obd %s not set up\n", obd->obd_name);
1083                 return -EINVAL;
1084         }
1085
1086         if (!OBP(obd, notify)) {
1087                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1088                 return -ENOSYS;
1089         }
1090
1091         OBD_COUNTER_INCREMENT(obd, notify);
1092         return OBP(obd, notify)(obd, watched, active);
1093 }
1094
1095 static inline int obd_register_observer(struct obd_device *obd,
1096                                         struct obd_device *observer)
1097 {
1098         ENTRY;
1099         if (obd->obd_observer && observer)
1100                 RETURN(-EALREADY);
1101         obd->obd_observer = observer;
1102         RETURN(0);
1103 }
1104
1105 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1106 {
1107         int rc;
1108         ENTRY;
1109         LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1110         OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1111         rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1112         RETURN(rc);
1113 }
1114
1115 static inline int md_getstatus(struct obd_export *exp, struct ll_fid *fid)
1116 {
1117         int rc;
1118
1119         EXP_CHECK_MD_OP(exp, getstatus);
1120         MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1121         rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1122         RETURN(rc);
1123 }
1124
1125 /* this function notifies MDC, that inode described by @fid gets removed from
1126  * memory.*/
1127 static inline int md_delete_object(struct obd_export *exp,
1128                                    struct ll_fid *fid)
1129 {
1130         int rc;
1131         ENTRY;
1132
1133         /* as this method only notifies MDC that inode gets deleted, we can
1134          * return zero if method is not implemented, this means, that OBD does
1135          * not need such a notification. */
1136         if (MDP(exp->exp_obd, delete_object) == NULL)
1137                 RETURN(0);
1138         
1139         MD_COUNTER_INCREMENT(exp->exp_obd, delete_object);
1140         rc = MDP(exp->exp_obd, delete_object)(exp, fid);
1141         RETURN(rc);
1142 }
1143
1144 static inline int md_getattr(struct obd_export *exp, struct ll_fid *fid,
1145                              unsigned long valid, unsigned int ea_size,
1146                              struct ptlrpc_request **request)
1147 {
1148         int rc;
1149         ENTRY;
1150         EXP_CHECK_MD_OP(exp, getattr);
1151         MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1152         rc = MDP(exp->exp_obd, getattr)(exp, fid, valid, ea_size, request);
1153         RETURN(rc);
1154 }
1155
1156 static inline int md_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
1157                                    ldlm_iterator_t it, void *data)
1158 {
1159         int rc;
1160         ENTRY;
1161         EXP_CHECK_MD_OP(exp, change_cbdata);
1162         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1163         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1164         RETURN(rc);
1165 }
1166
1167 static inline int md_change_cbdata_name(struct obd_export *exp,
1168                                         struct ll_fid *fid, char *name,
1169                                         int namelen, struct ll_fid *fid2,
1170                                         ldlm_iterator_t it, void *data)
1171 {
1172         int rc;
1173         
1174         /* this seem to be needed only for lmv. */
1175         if (!MDP(exp->exp_obd, change_cbdata_name))
1176                 return 0;
1177         
1178         ENTRY;
1179                 
1180         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1181         rc = MDP(exp->exp_obd, change_cbdata_name)(exp, fid, name, namelen,
1182                                                    fid2, it, data);
1183         RETURN(rc);
1184 }
1185
1186 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1187                            struct obd_client_handle *och,
1188                            struct ptlrpc_request **request)
1189 {
1190         int rc;
1191         ENTRY;
1192         EXP_CHECK_MD_OP(exp, close);
1193         MD_COUNTER_INCREMENT(exp->exp_obd, close);
1194         rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1195         RETURN(rc);
1196 }
1197
1198 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1199                             const void *data, int datalen, int mode,
1200                             __u32 uid, __u32 gid, __u64 rdev,
1201                             struct ptlrpc_request **request)
1202 {
1203         int rc;
1204         ENTRY;
1205         EXP_CHECK_MD_OP(exp, create);
1206         MD_COUNTER_INCREMENT(exp->exp_obd, create);
1207         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1208                                        uid, gid, rdev, request);
1209         RETURN(rc);
1210 }
1211
1212 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1213 {
1214         int rc;
1215         ENTRY;
1216         EXP_CHECK_MD_OP(exp, done_writing);
1217         MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1218         rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1219         RETURN(rc);
1220 }
1221
1222 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1223                              struct lookup_intent *it, int lock_mode,
1224                              struct mdc_op_data *data,
1225                              struct lustre_handle *lockh,
1226                              void *lmm, int lmmsize,
1227                              ldlm_completion_callback cb_completion,
1228                              ldlm_blocking_callback cb_blocking,
1229                              void *cb_data)
1230 {
1231         int rc;
1232         ENTRY;
1233         EXP_CHECK_MD_OP(exp, enqueue);
1234         MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1235         rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1236                                         data, lockh, lmm, lmmsize,
1237                                         cb_completion, cb_blocking,
1238                                         cb_data);
1239         RETURN(rc);
1240 }
1241
1242 static inline int md_getattr_name(struct obd_export *exp, struct ll_fid *fid,
1243                                   char *filename, int namelen,
1244                                   unsigned long valid, unsigned int ea_size,
1245                                   struct ptlrpc_request **request)
1246 {
1247         int rc;
1248         ENTRY;
1249         EXP_CHECK_MD_OP(exp, getattr_name);
1250         MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1251         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1252                                              valid, ea_size, request);
1253         RETURN(rc);
1254 }
1255
1256 static inline int md_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
1257                                  struct ll_fid *pfid, const char *name,
1258                                  int len, void *lmm, int lmmsize,
1259                                  struct ll_fid *cfid, struct lookup_intent *it,
1260                                  int flags, struct ptlrpc_request **reqp,
1261                                  ldlm_blocking_callback cb_blocking)
1262 {
1263         int rc;
1264         ENTRY;
1265         EXP_CHECK_MD_OP(exp, intent_lock);
1266         MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1267         rc = MDP(exp->exp_obd, intent_lock)(exp, uctxt, pfid, name, len,
1268                                             lmm, lmmsize, cfid, it, flags,
1269                                             reqp, cb_blocking);
1270         RETURN(rc);
1271 }
1272
1273 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1274                           struct ptlrpc_request **request)
1275 {
1276         int rc;
1277         ENTRY;
1278         EXP_CHECK_MD_OP(exp, link);
1279         MD_COUNTER_INCREMENT(exp->exp_obd, link);
1280         rc = MDP(exp->exp_obd, link)(exp, data, request);
1281         RETURN(rc);
1282 }
1283
1284 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1285                             const char *old, int oldlen,
1286                             const char *new, int newlen,
1287                             struct ptlrpc_request **request)
1288 {
1289         int rc;
1290         ENTRY;
1291         EXP_CHECK_MD_OP(exp, rename);
1292         MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1293         rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1294                                        newlen, request);
1295         RETURN(rc);
1296 }
1297
1298 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1299                              struct iattr *iattr, void *ea, int ealen,
1300                              void *ea2, int ea2len,
1301                              struct ptlrpc_request **request)
1302 {
1303         int rc;
1304         ENTRY;
1305         EXP_CHECK_MD_OP(exp, setattr);
1306         MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1307         rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1308                                         ea2, ea2len, request);
1309         RETURN(rc);
1310 }
1311
1312 static inline int md_sync(struct obd_export *exp, struct ll_fid *fid,
1313                                struct ptlrpc_request **request)
1314 {
1315         int rc;
1316         ENTRY;
1317         EXP_CHECK_MD_OP(exp, sync);
1318         MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1319         rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1320         RETURN(rc);
1321 }
1322
1323 static inline int md_readpage(struct obd_export *exp, struct ll_fid *fid,
1324                               __u64 offset, struct page *page,
1325                               struct ptlrpc_request **request)
1326 {
1327         int rc;
1328         ENTRY;
1329         EXP_CHECK_MD_OP(exp, readpage);
1330         MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1331         rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1332         RETURN(rc);
1333 }
1334
1335 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1336                             struct ptlrpc_request **request)
1337 {
1338         int rc;
1339         ENTRY;
1340         EXP_CHECK_MD_OP(exp, unlink);
1341         MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1342         rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1343         RETURN(rc);
1344 }
1345
1346 static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
1347                                                  char *name, int len)
1348 {
1349         ENTRY;
1350         if (MDP(exp->exp_obd, get_real_obd) == NULL)
1351                 return exp->exp_obd;
1352         MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1353         return MDP(exp->exp_obd, get_real_obd)(exp, name, len);
1354 }
1355
1356 static inline int md_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
1357 {
1358         ENTRY;
1359         EXP_CHECK_MD_OP(exp, valid_attrs);
1360         MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1361         return MDP(exp->exp_obd, valid_attrs)(exp, fid);
1362 }
1363
1364 static inline int md_req2lustre_md(struct obd_export *exp,
1365                                    struct ptlrpc_request *req,
1366                                    unsigned int offset,
1367                                    struct obd_export *osc_exp,
1368                                    struct lustre_md *md)
1369 {
1370         ENTRY;
1371         EXP_CHECK_MD_OP(exp, req2lustre_md);
1372         MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1373         return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1374 }
1375
1376 static inline int md_set_open_replay_data(struct obd_export *exp,
1377                                           struct obd_client_handle *och,
1378                                           struct ptlrpc_request *open_req)
1379 {
1380         ENTRY;
1381         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1382         MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1383         return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1384 }
1385
1386 static inline int md_clear_open_replay_data(struct obd_export *exp,
1387                                             struct obd_client_handle *och)
1388 {
1389         ENTRY;
1390         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1391         MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1392         return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1393 }
1394
1395 static inline int md_store_inode_generation(struct obd_export *exp,
1396                                             struct ptlrpc_request *req,
1397                                             int reqoff, int repoff)
1398 {
1399         ENTRY;
1400         EXP_CHECK_MD_OP(exp, store_inode_generation);
1401         MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1402         return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1403                    reqoff, repoff);
1404 }
1405
1406 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1407 {
1408         ENTRY;
1409         EXP_CHECK_MD_OP(exp, set_lock_data);
1410         MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1411         return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1412 }
1413
1414 /* OBD Metadata Support */
1415
1416 extern int obd_init_caches(void);
1417 extern void obd_cleanup_caches(void);
1418
1419 /* support routines */
1420 extern kmem_cache_t *obdo_cachep;
1421 static inline struct obdo *obdo_alloc(void)
1422 {
1423         struct obdo *oa;
1424
1425         oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1426         if (oa == NULL)
1427                 LBUG();
1428         CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1429         memset(oa, 0, sizeof (*oa));
1430
1431         return oa;
1432 }
1433
1434 static inline void obdo_free(struct obdo *oa)
1435 {
1436         if (!oa)
1437                 return;
1438         CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1439         kmem_cache_free(obdo_cachep, oa);
1440 }
1441
1442 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1443 #define to_kdev_t(dev) dev
1444 #define kdev_t_to_nr(dev) dev
1445 #endif
1446
1447 /* I'm as embarrassed about this as you are.
1448  *
1449  * <shaver> // XXX do not look into _superhack with remaining eye
1450  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1451 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1452 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1453
1454 /* sysctl.c */
1455 extern void obd_sysctl_init (void);
1456 extern void obd_sysctl_clean (void);
1457
1458 /* uuid.c  */
1459 typedef __u8 class_uuid_t[16];
1460 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1461 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1462
1463 /* lustre_peer.c    */
1464 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1465 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1466 int class_del_uuid (char *uuid);
1467 void class_init_uuidlist(void);
1468 void class_exit_uuidlist(void);
1469
1470 /* mea.c */
1471 int mea_name2idx(struct mea *mea, char *name, int namelen);
1472 int raw_name2idx(int count, const char *name, int namelen);
1473
1474 #endif /* __LINUX_OBD_CLASS_H */