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