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