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