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