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