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