Whamcloud - gitweb
b=1451
[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 {
628         int rc;
629         ENTRY;
630
631         OBD_CHECK_DEV_ACTIVE(obd);
632         OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
633         OBD_COUNTER_INCREMENT(obd, connect);
634
635         rc = OBP(obd, connect)(conn, obd, cluuid);
636         RETURN(rc);
637 }
638
639 static inline int obd_disconnect(struct obd_export *exp, int flags)
640 {
641         int rc;
642         ENTRY;
643
644         EXP_CHECK_OP(exp, disconnect);
645         OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
646
647         rc = OBP(exp->exp_obd, disconnect)(exp, flags);
648         RETURN(rc);
649 }
650
651 static inline int obd_init_export(struct obd_export *exp)
652 {
653         int rc = 0;
654
655         ENTRY;
656         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
657             OBP((exp)->exp_obd, init_export))
658                 rc = OBP(exp->exp_obd, init_export)(exp);
659         RETURN(rc);
660 }
661
662 static inline int obd_destroy_export(struct obd_export *exp)
663 {
664         ENTRY;
665         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
666             OBP((exp)->exp_obd, destroy_export))
667                 OBP(exp->exp_obd, destroy_export)(exp);
668         RETURN(0);
669 }
670
671 static inline struct dentry *
672 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
673 {
674         LASSERT(exp->exp_obd);
675
676         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
677                                exp->exp_obd);
678 }
679
680 #ifndef time_before
681 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
682 #endif
683
684 /* @max_age is the oldest time in jiffies that we accept using a cached data.
685  * If the cache is older than @max_age we will get a new value from the
686  * target.  Use a value of "jiffies + HZ" to guarantee freshness. */
687 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
688                              unsigned long max_age)
689 {
690         int rc = 0;
691         ENTRY;
692
693         if (obd == NULL)
694                 RETURN(-EINVAL);
695
696         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
697         OBD_COUNTER_INCREMENT(obd, statfs);
698
699         CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
700         if (time_before(obd->obd_osfs_age, max_age)) {
701                 rc = OBP(obd, statfs)(obd, osfs, max_age);
702                 if (rc == 0) {
703                         spin_lock(&obd->obd_osfs_lock);
704                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
705                         obd->obd_osfs_age = jiffies;
706                         spin_unlock(&obd->obd_osfs_lock);
707                 }
708         } else {
709                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
710                 spin_lock(&obd->obd_osfs_lock);
711                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
712                 spin_unlock(&obd->obd_osfs_lock);
713         }
714         RETURN(rc);
715 }
716
717 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
718                            struct lov_stripe_md *ea, obd_size start,
719                            obd_size end)
720 {
721         int rc;
722         ENTRY;
723
724         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
725         OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
726
727         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
728         RETURN(rc);
729 }
730
731 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
732                             struct lov_stripe_md *ea, obd_size start,
733                             obd_size end, struct obd_trans_info *oti)
734 {
735         int rc;
736         ENTRY;
737
738         EXP_CHECK_OP(exp, punch);
739         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
740
741         rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
742         RETURN(rc);
743 }
744
745 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
746                           struct lov_stripe_md *ea, obd_count oa_bufs,
747                           struct brw_page *pg, struct obd_trans_info *oti)
748 {
749         int rc;
750         ENTRY;
751
752         EXP_CHECK_OP(exp, brw);
753         OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
754
755         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
756                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
757                        "or OBD_BRW_CHECK\n");
758                 LBUG();
759         }
760
761         rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
762         RETURN(rc);
763 }
764
765 static inline int obd_brw_async(int cmd, struct obd_export *exp,
766                                 struct obdo *oa, struct lov_stripe_md *ea,
767                                 obd_count oa_bufs, struct brw_page *pg,
768                                 struct ptlrpc_request_set *set,
769                                 struct obd_trans_info *oti)
770 {
771         int rc;
772         ENTRY;
773
774         EXP_CHECK_OP(exp, brw_async);
775         OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
776
777         if (!(cmd & OBD_BRW_RWMASK)) {
778                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
779                 LBUG();
780         }
781
782         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
783                                           oti);
784         RETURN(rc);
785 }
786
787 static inline  int obd_prep_async_page(struct obd_export *exp,
788                                        struct lov_stripe_md *lsm,
789                                        struct lov_oinfo *loi,
790                                        struct page *page, obd_off offset,
791                                        struct obd_async_page_ops *ops,
792                                        void *data, void **res)
793 {
794         int ret;
795         ENTRY;
796
797         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
798         OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
799
800         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
801                                                  ops, data, res);
802         RETURN(ret);
803 }
804
805 static inline int obd_queue_async_io(struct obd_export *exp,
806                                      struct lov_stripe_md *lsm,
807                                      struct lov_oinfo *loi, void *cookie,
808                                      int cmd, obd_off off, int count,
809                                      obd_flag brw_flags, obd_flag async_flags)
810 {
811         int rc;
812         ENTRY;
813
814         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
815         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
816         LASSERT(cmd & OBD_BRW_RWMASK);
817
818         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
819                                                count, brw_flags, async_flags);
820         RETURN(rc);
821 }
822
823 static inline int obd_set_async_flags(struct obd_export *exp,
824                                       struct lov_stripe_md *lsm,
825                                       struct lov_oinfo *loi, void *cookie,
826                                       obd_flag async_flags)
827 {
828         int rc;
829         ENTRY;
830
831         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
832         OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
833
834         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
835                                                 async_flags);
836         RETURN(rc);
837 }
838
839 static inline int obd_queue_group_io(struct obd_export *exp,
840                                      struct lov_stripe_md *lsm,
841                                      struct lov_oinfo *loi,
842                                      struct obd_io_group *oig,
843                                      void *cookie, int cmd, obd_off off,
844                                      int count, obd_flag brw_flags,
845                                      obd_flag async_flags)
846 {
847         int rc;
848         ENTRY;
849
850         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
851         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
852         LASSERT(cmd & OBD_BRW_RWMASK);
853
854         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
855                                                cmd, off, count, brw_flags,
856                                                async_flags);
857         RETURN(rc);
858 }
859
860 static inline int obd_trigger_group_io(struct obd_export *exp,
861                                        struct lov_stripe_md *lsm,
862                                        struct lov_oinfo *loi,
863                                        struct obd_io_group *oig)
864 {
865         int rc;
866         ENTRY;
867
868         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
869         OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
870
871         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
872         RETURN(rc);
873 }
874
875 static inline int obd_teardown_async_page(struct obd_export *exp,
876                                           struct lov_stripe_md *lsm,
877                                           struct lov_oinfo *loi, void *cookie)
878 {
879         int rc;
880         ENTRY;
881
882         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
883         OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
884
885         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
886         RETURN(rc);
887 }
888
889 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
890                              int objcount, struct obd_ioobj *obj,
891                              int niocount, struct niobuf_remote *remote,
892                              struct niobuf_local *local,
893                              struct obd_trans_info *oti)
894 {
895         int rc;
896         ENTRY;
897
898         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
899         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
900
901         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
902                                        remote, local, oti);
903         RETURN(rc);
904 }
905
906 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
907                                int objcount, struct obd_ioobj *obj,
908                                int niocount, struct niobuf_local *local,
909                                struct obd_trans_info *oti, int rc)
910 {
911         ENTRY;
912
913         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
914         OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
915
916         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
917                                          local, oti, rc);
918         RETURN(rc);
919 }
920
921 static inline int obd_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
922                             int objcount,struct niobuf_remote *rnb)
923 {
924         int rc;
925         ENTRY;
926
927         /* there are cases when write_extents is not implemented. */
928         if (!OBP(exp->exp_obd, do_cow))
929                 RETURN(0);
930                 
931         OBD_COUNTER_INCREMENT(exp->exp_obd, do_cow);
932
933         rc = OBP(exp->exp_obd, do_cow)(exp, obj, objcount, rnb);
934
935         RETURN(rc);
936 }
937
938 static inline int obd_write_extents(struct obd_export *exp, 
939                                     struct obd_ioobj *obj,
940                                     int objcount, int niocount,  
941                                     struct niobuf_local *local, 
942                                     int rc)
943 {
944         ENTRY;
945
946         /* there are cases when write_extents is not implemented. */
947         if (!OBP(exp->exp_obd, write_extents))
948                 RETURN(0);
949                 
950         OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
951
952         rc = OBP(exp->exp_obd, write_extents)(exp, obj, objcount, niocount, 
953                                               local, rc);
954         RETURN(rc);
955 }
956
957 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
958                                 int len, void *karg, void *uarg)
959 {
960         int rc;
961         ENTRY;
962
963         EXP_CHECK_OP(exp, iocontrol);
964         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
965
966         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
967         RETURN(rc);
968 }
969
970 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
971                               __u32 type, ldlm_policy_data_t *policy,
972                               __u32 mode, int *flags, void *bl_cb, void *cp_cb,
973                               void *gl_cb, void *data, __u32 lvb_len,
974                               void *lvb_swabber, struct lustre_handle *lockh)
975 {
976         int rc;
977         ENTRY;
978
979         EXP_CHECK_OP(exp, enqueue);
980         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
981
982         rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
983                                         bl_cb, cp_cb, gl_cb, data, lvb_len,
984                                         lvb_swabber, lockh);
985         RETURN(rc);
986 }
987
988 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
989                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
990                             int *flags, void *data, struct lustre_handle *lockh)
991 {
992         int rc;
993         ENTRY;
994
995         EXP_CHECK_OP(exp, match);
996         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
997
998         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
999                                       lockh);
1000         RETURN(rc);
1001 }
1002
1003 static inline int obd_change_cbdata(struct obd_export *exp,
1004                                     struct lov_stripe_md *lsm,
1005                                     ldlm_iterator_t it, void *data)
1006 {
1007         int rc;
1008         ENTRY;
1009
1010         EXP_CHECK_OP(exp, change_cbdata);
1011         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1012
1013         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1014         RETURN(rc);
1015 }
1016
1017 static inline int obd_cancel(struct obd_export *exp,
1018                              struct lov_stripe_md *ea, __u32 mode,
1019                              struct lustre_handle *lockh)
1020 {
1021         int rc;
1022         ENTRY;
1023
1024         EXP_CHECK_OP(exp, cancel);
1025         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1026
1027         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1028         RETURN(rc);
1029 }
1030
1031 static inline int obd_cancel_unused(struct obd_export *exp,
1032                                     struct lov_stripe_md *ea, int flags,
1033                                     void *opaque)
1034 {
1035         int rc;
1036         ENTRY;
1037
1038         EXP_CHECK_OP(exp, cancel_unused);
1039         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1040
1041         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1042         RETURN(rc);
1043 }
1044
1045
1046 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1047                                  struct obdo *oa,
1048                                  int objcount, struct obd_ioobj *obj,
1049                                  int niocount, struct niobuf_remote *remote)
1050 {
1051         int rc;
1052
1053         EXP_CHECK_OP(exp, preprw);
1054         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1055
1056         rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1057                                            niocount, remote);
1058         class_export_put(exp);
1059         return(rc);
1060 }
1061
1062 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1063                           int type, struct obd_client_handle *handle, int flag)
1064 {
1065         int rc;
1066
1067         EXP_CHECK_OP(exp, pin);
1068         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1069
1070         rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1071         return(rc);
1072 }
1073
1074 static inline int obd_unpin(struct obd_export *exp,
1075                             struct obd_client_handle *handle, int flag)
1076 {
1077         int rc;
1078
1079         EXP_CHECK_OP(exp, unpin);
1080         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1081
1082         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1083         return(rc);
1084 }
1085
1086
1087 static inline void obd_import_event(struct obd_device *obd,
1088                                     struct obd_import *imp,
1089                                     enum obd_import_event event)
1090 {
1091         if (obd->obd_set_up && OBP(obd, import_event)) {
1092                 OBD_COUNTER_INCREMENT(obd, import_event);
1093                 OBP(obd, import_event)(obd, imp, event);
1094         }
1095 }
1096
1097 static inline int obd_llog_connect(struct obd_device *obd,
1098                                         struct llogd_conn_body *body)
1099 {
1100         ENTRY;
1101         if (!obd->obd_set_up) {
1102                 CERROR("obd %s not set up\n", obd->obd_name);
1103                 return -EINVAL;
1104         }
1105
1106         if (!OBP(obd, llog_connect)) {
1107                 CERROR("obd %s has no llog_connect handler\n", obd->obd_name);
1108                 return -ENOSYS;
1109         }
1110
1111         return OBP(obd, llog_connect)(obd, body);
1112 }
1113
1114 static inline int obd_notify(struct obd_device *obd,
1115                              struct obd_device *watched,
1116                              int active)
1117 {
1118         if (!obd->obd_set_up) {
1119                 CERROR("obd %s not set up\n", obd->obd_name);
1120                 return -EINVAL;
1121         }
1122
1123         if (!OBP(obd, notify)) {
1124                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1125                 return -ENOSYS;
1126         }
1127
1128         OBD_COUNTER_INCREMENT(obd, notify);
1129         return OBP(obd, notify)(obd, watched, active);
1130 }
1131
1132 static inline int obd_register_observer(struct obd_device *obd,
1133                                         struct obd_device *observer)
1134 {
1135         ENTRY;
1136         if (obd->obd_observer && observer)
1137                 RETURN(-EALREADY);
1138         obd->obd_observer = observer;
1139         RETURN(0);
1140 }
1141
1142 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1143 {
1144         int rc;
1145         ENTRY;
1146         LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1147         OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1148         rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1149         RETURN(rc);
1150 }
1151
1152 static inline int md_getstatus(struct obd_export *exp, struct ll_fid *fid)
1153 {
1154         int rc;
1155
1156         EXP_CHECK_MD_OP(exp, getstatus);
1157         MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1158         rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1159         RETURN(rc);
1160 }
1161
1162 /* this function notifies MDC, that inode described by @fid gets removed from
1163  * memory.*/
1164 static inline int md_delete_object(struct obd_export *exp,
1165                                    struct ll_fid *fid)
1166 {
1167         int rc;
1168         ENTRY;
1169
1170         /* as this method only notifies MDC that inode gets deleted, we can
1171          * return zero if method is not implemented, this means, that OBD does
1172          * not need such a notification. */
1173         if (MDP(exp->exp_obd, delete_object) == NULL)
1174                 RETURN(0);
1175         
1176         MD_COUNTER_INCREMENT(exp->exp_obd, delete_object);
1177         rc = MDP(exp->exp_obd, delete_object)(exp, fid);
1178         RETURN(rc);
1179 }
1180
1181 static inline int md_getattr(struct obd_export *exp, struct ll_fid *fid,
1182                              unsigned long valid, unsigned int ea_size,
1183                              struct ptlrpc_request **request)
1184 {
1185         int rc;
1186         ENTRY;
1187         EXP_CHECK_MD_OP(exp, getattr);
1188         MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1189         rc = MDP(exp->exp_obd, getattr)(exp, fid, valid, ea_size, request);
1190         RETURN(rc);
1191 }
1192
1193 static inline int md_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
1194                                    ldlm_iterator_t it, void *data)
1195 {
1196         int rc;
1197         ENTRY;
1198         EXP_CHECK_MD_OP(exp, change_cbdata);
1199         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1200         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1201         RETURN(rc);
1202 }
1203
1204 static inline int md_change_cbdata_name(struct obd_export *exp,
1205                                         struct ll_fid *fid, char *name,
1206                                         int namelen, struct ll_fid *fid2,
1207                                         ldlm_iterator_t it, void *data)
1208 {
1209         int rc;
1210         
1211         /* this seem to be needed only for lmv. */
1212         if (!MDP(exp->exp_obd, change_cbdata_name))
1213                 return 0;
1214         
1215         ENTRY;
1216                 
1217         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1218         rc = MDP(exp->exp_obd, change_cbdata_name)(exp, fid, name, namelen,
1219                                                    fid2, it, data);
1220         RETURN(rc);
1221 }
1222
1223 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1224                            struct obd_client_handle *och,
1225                            struct ptlrpc_request **request)
1226 {
1227         int rc;
1228         ENTRY;
1229         EXP_CHECK_MD_OP(exp, close);
1230         MD_COUNTER_INCREMENT(exp->exp_obd, close);
1231         rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1232         RETURN(rc);
1233 }
1234
1235 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1236                             const void *data, int datalen, int mode,
1237                             __u32 uid, __u32 gid, __u64 rdev,
1238                             struct ptlrpc_request **request)
1239 {
1240         int rc;
1241         ENTRY;
1242         EXP_CHECK_MD_OP(exp, create);
1243         MD_COUNTER_INCREMENT(exp->exp_obd, create);
1244         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1245                                        uid, gid, rdev, request);
1246         RETURN(rc);
1247 }
1248
1249 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1250 {
1251         int rc;
1252         ENTRY;
1253         EXP_CHECK_MD_OP(exp, done_writing);
1254         MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1255         rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1256         RETURN(rc);
1257 }
1258
1259 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1260                              struct lookup_intent *it, int lock_mode,
1261                              struct mdc_op_data *data,
1262                              struct lustre_handle *lockh,
1263                              void *lmm, int lmmsize,
1264                              ldlm_completion_callback cb_completion,
1265                              ldlm_blocking_callback cb_blocking,
1266                              void *cb_data)
1267 {
1268         int rc;
1269         ENTRY;
1270         EXP_CHECK_MD_OP(exp, enqueue);
1271         MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1272         rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1273                                         data, lockh, lmm, lmmsize,
1274                                         cb_completion, cb_blocking,
1275                                         cb_data);
1276         RETURN(rc);
1277 }
1278
1279 static inline int md_getattr_name(struct obd_export *exp, struct ll_fid *fid,
1280                                   char *filename, int namelen,
1281                                   unsigned long valid, unsigned int ea_size,
1282                                   struct ptlrpc_request **request)
1283 {
1284         int rc;
1285         ENTRY;
1286         EXP_CHECK_MD_OP(exp, getattr_name);
1287         MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1288         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1289                                              valid, ea_size, request);
1290         RETURN(rc);
1291 }
1292
1293 static inline int md_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
1294                                  struct ll_fid *pfid, const char *name,
1295                                  int len, void *lmm, int lmmsize,
1296                                  struct ll_fid *cfid, struct lookup_intent *it,
1297                                  int flags, struct ptlrpc_request **reqp,
1298                                  ldlm_blocking_callback cb_blocking)
1299 {
1300         int rc;
1301         ENTRY;
1302         EXP_CHECK_MD_OP(exp, intent_lock);
1303         MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1304         rc = MDP(exp->exp_obd, intent_lock)(exp, uctxt, pfid, name, len,
1305                                             lmm, lmmsize, cfid, it, flags,
1306                                             reqp, cb_blocking);
1307         RETURN(rc);
1308 }
1309
1310 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1311                           struct ptlrpc_request **request)
1312 {
1313         int rc;
1314         ENTRY;
1315         EXP_CHECK_MD_OP(exp, link);
1316         MD_COUNTER_INCREMENT(exp->exp_obd, link);
1317         rc = MDP(exp->exp_obd, link)(exp, data, request);
1318         RETURN(rc);
1319 }
1320
1321 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1322                             const char *old, int oldlen,
1323                             const char *new, int newlen,
1324                             struct ptlrpc_request **request)
1325 {
1326         int rc;
1327         ENTRY;
1328         EXP_CHECK_MD_OP(exp, rename);
1329         MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1330         rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1331                                        newlen, request);
1332         RETURN(rc);
1333 }
1334
1335 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1336                              struct iattr *iattr, void *ea, int ealen,
1337                              void *ea2, int ea2len,
1338                              struct ptlrpc_request **request)
1339 {
1340         int rc;
1341         ENTRY;
1342         EXP_CHECK_MD_OP(exp, setattr);
1343         MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1344         rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1345                                         ea2, ea2len, request);
1346         RETURN(rc);
1347 }
1348
1349 static inline int md_sync(struct obd_export *exp, struct ll_fid *fid,
1350                                struct ptlrpc_request **request)
1351 {
1352         int rc;
1353         ENTRY;
1354         EXP_CHECK_MD_OP(exp, sync);
1355         MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1356         rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1357         RETURN(rc);
1358 }
1359
1360 static inline int md_readpage(struct obd_export *exp, struct ll_fid *fid,
1361                               __u64 offset, struct page *page,
1362                               struct ptlrpc_request **request)
1363 {
1364         int rc;
1365         ENTRY;
1366         EXP_CHECK_MD_OP(exp, readpage);
1367         MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1368         rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1369         RETURN(rc);
1370 }
1371
1372 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1373                             struct ptlrpc_request **request)
1374 {
1375         int rc;
1376         ENTRY;
1377         EXP_CHECK_MD_OP(exp, unlink);
1378         MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1379         rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1380         RETURN(rc);
1381 }
1382
1383 static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
1384                                                  char *name, int len)
1385 {
1386         ENTRY;
1387         if (MDP(exp->exp_obd, get_real_obd) == NULL)
1388                 return exp->exp_obd;
1389         MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1390         return MDP(exp->exp_obd, get_real_obd)(exp, name, len);
1391 }
1392
1393 static inline int md_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
1394 {
1395         ENTRY;
1396         EXP_CHECK_MD_OP(exp, valid_attrs);
1397         MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1398         return MDP(exp->exp_obd, valid_attrs)(exp, fid);
1399 }
1400
1401 static inline int md_req2lustre_md(struct obd_export *exp,
1402                                    struct ptlrpc_request *req,
1403                                    unsigned int offset,
1404                                    struct obd_export *osc_exp,
1405                                    struct lustre_md *md)
1406 {
1407         ENTRY;
1408         EXP_CHECK_MD_OP(exp, req2lustre_md);
1409         MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1410         return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1411 }
1412
1413 static inline int md_set_open_replay_data(struct obd_export *exp,
1414                                           struct obd_client_handle *och,
1415                                           struct ptlrpc_request *open_req)
1416 {
1417         ENTRY;
1418         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1419         MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1420         return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1421 }
1422
1423 static inline int md_clear_open_replay_data(struct obd_export *exp,
1424                                             struct obd_client_handle *och)
1425 {
1426         ENTRY;
1427         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1428         MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1429         return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1430 }
1431
1432 static inline int md_store_inode_generation(struct obd_export *exp,
1433                                             struct ptlrpc_request *req,
1434                                             int reqoff, int repoff)
1435 {
1436         ENTRY;
1437         EXP_CHECK_MD_OP(exp, store_inode_generation);
1438         MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1439         return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1440                    reqoff, repoff);
1441 }
1442
1443 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1444 {
1445         ENTRY;
1446         EXP_CHECK_MD_OP(exp, set_lock_data);
1447         MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1448         return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1449 }
1450
1451 /* OBD Metadata Support */
1452
1453 extern int obd_init_caches(void);
1454 extern void obd_cleanup_caches(void);
1455
1456 /* support routines */
1457 extern kmem_cache_t *obdo_cachep;
1458 static inline struct obdo *obdo_alloc(void)
1459 {
1460         struct obdo *oa;
1461
1462         oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1463         if (oa == NULL)
1464                 LBUG();
1465         CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1466         memset(oa, 0, sizeof (*oa));
1467
1468         return oa;
1469 }
1470
1471 static inline void obdo_free(struct obdo *oa)
1472 {
1473         if (!oa)
1474                 return;
1475         CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1476         kmem_cache_free(obdo_cachep, 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 count, const char *name, int namelen);
1510
1511 #endif /* __LINUX_OBD_CLASS_H */