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