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