Whamcloud - gitweb
- call ldto_device_fini() in obd_precleanup()
[fs/lustre-release.git] / lustre / include / 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 __CLASS_OBD_H
24 #define __CLASS_OBD_H
25
26 #include <obd_support.h>
27 #include <lustre_import.h>
28 #include <lustre_net.h>
29 #include <obd.h>
30 #include <lustre_lib.h>
31 #include <lustre/lustre_idl.h>
32 #include <lprocfs_status.h>
33
34 #if defined(__linux__)
35 #include <linux/obd_class.h>
36 #elif defined(__APPLE__)
37 #include <darwin/obd_class.h>
38 #elif defined(__WINNT__)
39 #include <winnt/obd_class.h>
40 #else
41 #error Unsupported operating system.
42 #endif
43
44 /* OBD Device Declarations */
45 #define MAX_OBD_DEVICES 520
46 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
47 extern spinlock_t obd_dev_lock;
48
49 /* OBD Operations Declarations */
50 extern struct obd_device *class_conn2obd(struct lustre_handle *);
51 extern struct obd_device *class_exp2obd(struct obd_export *);
52
53 struct lu_device_type;
54
55 /* genops.c */
56 struct obd_export *class_conn2export(struct lustre_handle *);
57 int class_register_type(struct obd_ops *, struct md_ops *,
58                         struct lprocfs_vars *, const char *nm,
59                         struct lu_device_type *ldt);
60 int class_unregister_type(const char *nm);
61
62 struct obd_device *class_newdev(struct obd_type *type, char *name);
63 void class_release_dev(struct obd_device *obd);
64
65 int class_name2dev(const char *name);
66 struct obd_device *class_name2obd(const char *name);
67 int class_uuid2dev(struct obd_uuid *uuid);
68 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
69 void class_obd_list(void);
70 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
71                                           const char * typ_name,
72                                           struct obd_uuid *grp_uuid);
73 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
74                                              struct obd_uuid *grp_uuid);
75 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
76                                            int *next);
77
78 int oig_init(struct obd_io_group **oig);
79 void oig_add_one(struct obd_io_group *oig,
80                   struct oig_callback_context *occ);
81 void oig_complete_one(struct obd_io_group *oig,
82                       struct oig_callback_context *occ, int rc);
83 void oig_release(struct obd_io_group *oig);
84 int oig_wait(struct obd_io_group *oig);
85
86 char *obd_export_nid2str(struct obd_export *exp);
87
88 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
89 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
90
91 /* obd_config.c */
92 int class_process_config(struct lustre_cfg *lcfg);
93 int class_attach(struct lustre_cfg *lcfg);
94 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
95 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
96 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
97 struct obd_device *class_incref(struct obd_device *obd);
98 void class_decref(struct obd_device *obd);
99
100 #define CFG_F_START     0x01   /* Set when we start updating from a log */
101 #define CFG_F_MARKER    0x02   /* We are within a maker */
102 #define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
103 #define CFG_F_COMPAT146 0x08   /* Translation to new obd names required */
104 #define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
105
106
107 /* Passed as data param to class_config_parse_llog */
108 struct config_llog_instance {
109         char *              cfg_instance;
110         struct super_block *cfg_sb;
111         struct obd_uuid     cfg_uuid;
112         int                 cfg_last_idx; /* for partial llog processing */
113         int                 cfg_flags;
114 };
115 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
116                             struct config_llog_instance *cfg);
117 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
118                            struct config_llog_instance *cfg);
119
120 /* list of active configuration logs  */
121 struct config_llog_data {
122         char               *cld_logname;
123         struct ldlm_res_id  cld_resid;
124         struct config_llog_instance cld_cfg;
125         struct list_head    cld_list_chain;
126         atomic_t            cld_refcount;
127         unsigned int        cld_stopping:1;
128 };
129
130 struct lustre_profile {
131         struct list_head lp_list;
132         char * lp_profile;
133         char * lp_osc;
134         char * lp_mdc;
135 };
136
137 struct lustre_profile *class_get_profile(const char * prof);
138 void class_del_profile(const char *prof);
139
140 /* genops.c */
141 #define class_export_get(exp)                                                  \
142 ({                                                                             \
143         struct obd_export *exp_ = exp;                                         \
144         atomic_inc(&exp_->exp_refcount);                                       \
145         CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_,          \
146                atomic_read(&exp_->exp_refcount));                              \
147         exp_;                                                                  \
148 })
149
150 #define class_export_put(exp)                                                  \
151 do {                                                                           \
152         LASSERT((exp) != NULL);                                                \
153         CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp),         \
154                atomic_read(&(exp)->exp_refcount) - 1);                         \
155         LASSERT(atomic_read(&(exp)->exp_refcount) > 0);                        \
156         LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a);                 \
157         __class_export_put(exp);                                               \
158 } while (0)
159 void __class_export_put(struct obd_export *);
160 struct obd_export *class_new_export(struct obd_device *obddev,
161                                     struct obd_uuid *cluuid);
162 void class_unlink_export(struct obd_export *exp);
163
164 struct obd_import *class_import_get(struct obd_import *);
165 void class_import_put(struct obd_import *);
166 struct obd_import *class_new_import(struct obd_device *obd);
167 void class_destroy_import(struct obd_import *exp);
168
169 struct obd_type *class_search_type(const char *name);
170 struct obd_type *class_get_type(const char *name);
171 void class_put_type(struct obd_type *type);
172 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
173                   struct obd_uuid *cluuid);
174 int class_disconnect(struct obd_export *exp);
175 void class_fail_export(struct obd_export *exp);
176 void class_disconnect_exports(struct obd_device *obddev);
177 void class_disconnect_stale_exports(struct obd_device *obddev);
178 int class_manual_cleanup(struct obd_device *obd);
179
180 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
181 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
182 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
183
184
185 #define OBT(dev)        (dev)->obd_type
186 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
187 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
188 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
189
190 /* Ensure obd_setup: used for cleanup which must be called
191    while obd is stopping */
192 #define OBD_CHECK_DEV(obd)                                      \
193 do {                                                            \
194         if (!(obd)) {                                           \
195                 CERROR("NULL device\n");                        \
196                 RETURN(-ENODEV);                                \
197         }                                                       \
198 } while (0)
199
200 /* ensure obd_setup and !obd_stopping */
201 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
202 do {                                                            \
203         OBD_CHECK_DEV(obd);                                     \
204         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
205                 CERROR("Device %d not setup\n",                 \
206                        (obd)->obd_minor);                       \
207                 RETURN(-ENODEV);                                \
208         }                                                       \
209 } while (0)
210
211
212 #ifdef LPROCFS
213 #define OBD_COUNTER_OFFSET(op)                                  \
214         ((offsetof(struct obd_ops, o_ ## op) -                  \
215           offsetof(struct obd_ops, o_iocontrol))                \
216          / sizeof(((struct obd_ops *)(0))->o_iocontrol))
217
218 #define OBD_COUNTER_INCREMENT(obd, op)                          \
219         if ((obd)->obd_stats != NULL) {                         \
220                 unsigned int coffset;                           \
221                 coffset = (unsigned int)(obd)->obd_cntr_base +  \
222                         OBD_COUNTER_OFFSET(op);                 \
223                 LASSERT(coffset < obd->obd_stats->ls_num);      \
224                 lprocfs_counter_incr(obd->obd_stats, coffset);  \
225         }
226
227 #define MD_COUNTER_OFFSET(op)                                  \
228         ((offsetof(struct md_ops, m_ ## op) -                  \
229           offsetof(struct md_ops, m_getstatus))                \
230          / sizeof(((struct md_ops *)(0))->m_getstatus))
231
232 #define MD_COUNTER_INCREMENT(obd, op)                           \
233         if ((obd)->md_stats != NULL) {                          \
234                 unsigned int coffset;                           \
235                 coffset = (unsigned int)(obd)->md_cntr_base +   \
236                         MD_COUNTER_OFFSET(op);                  \
237                 LASSERT(coffset < (obd)->md_stats->ls_num);     \
238                 lprocfs_counter_incr((obd)->md_stats, coffset); \
239         }
240
241 #else
242 #define OBD_COUNTER_OFFSET(op)
243 #define OBD_COUNTER_INCREMENT(obd, op)
244 #define MD_COUNTER_INCREMENT(obd, op)
245 #endif
246
247 #define OBD_CHECK_MD_OP(obd, op, err)                           \
248 do {                                                            \
249         if (!OBT(obd) || !MDP((obd), op)) {                     \
250                 if (err)                                        \
251                         CERROR("md_" #op ": dev %s/%d no operation\n", \
252                                obd->obd_name, obd->obd_minor);  \
253                 RETURN(err);                                    \
254         }                                                       \
255 } while (0)
256
257 #define EXP_CHECK_MD_OP(exp, op)                                \
258 do {                                                            \
259         if ((exp) == NULL) {                                    \
260                 CERROR("obd_" #op ": NULL export\n");           \
261                 RETURN(-ENODEV);                                \
262         }                                                       \
263         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
264                 CERROR("obd_" #op ": cleaned up obd\n");        \
265                 RETURN(-EOPNOTSUPP);                            \
266         }                                                       \
267         if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
268                 CERROR("obd_" #op ": dev %s/%d no operation\n", \
269                        (exp)->exp_obd->obd_name,                \
270                        (exp)->exp_obd->obd_minor);              \
271                 RETURN(-EOPNOTSUPP);                            \
272         }                                                       \
273 } while (0)
274
275
276 #define OBD_CHECK_DT_OP(obd, op, err)                           \
277 do {                                                            \
278         if (!OBT(obd) || !OBP((obd), op)) {                     \
279                 if (err)                                        \
280                         CERROR("obd_" #op ": dev %d no operation\n",    \
281                                obd->obd_minor);                 \
282                 RETURN(err);                                    \
283         }                                                       \
284 } while (0)
285
286 #define EXP_CHECK_DT_OP(exp, op)                                \
287 do {                                                            \
288         if ((exp) == NULL) {                                    \
289                 CERROR("obd_" #op ": NULL export\n");           \
290                 RETURN(-ENODEV);                                \
291         }                                                       \
292         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
293                 CERROR("obd_" #op ": cleaned up obd\n");        \
294                 RETURN(-EOPNOTSUPP);                            \
295         }                                                       \
296         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
297                 CERROR("obd_" #op ": dev %d no operation\n",    \
298                        (exp)->exp_obd->obd_minor);              \
299                 RETURN(-EOPNOTSUPP);                            \
300         }                                                       \
301 } while (0)
302
303 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
304 do {                                                            \
305         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
306                 if (err)                                        \
307                         CERROR("lop_" #op ": dev %d no operation\n",    \
308                                ctxt->loc_obd->obd_minor);                         \
309                 RETURN(err);                                    \
310         }                                                       \
311 } while (0)
312
313 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
314                                void *key, __u32 *vallen, void *val)
315 {
316         int rc;
317         ENTRY;
318
319         EXP_CHECK_DT_OP(exp, get_info);
320         OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
321
322         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
323         RETURN(rc);
324 }
325
326 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
327                                      void *key, obd_count vallen, void *val,
328                                      struct ptlrpc_request_set *set)
329 {
330         int rc;
331         ENTRY;
332
333         EXP_CHECK_DT_OP(exp, set_info_async);
334         OBD_COUNTER_INCREMENT(exp->exp_obd, set_info_async);
335
336         rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
337                                                set);
338         RETURN(rc);
339 }
340
341 #ifdef __KERNEL__
342 #define DECLARE_LU_VARS(ldt, d)                 \
343         struct lu_device_type *ldt;             \
344         struct lu_device *d
345 #else
346 #define DECLARE_LU_VARS(ldt, d)                                 \
347         extern void __placeholder_to_put_a_semicolon(void)
348 #endif
349 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
350 {
351         int rc;
352         DECLARE_LU_VARS(ldt, d);
353         ENTRY;
354
355 #ifdef __KERNEL__
356         ldt = obd->obd_type->typ_lu;
357         if (ldt != NULL) {
358                 struct lu_context ctx;
359
360                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
361                 if (rc == 0) {
362                         lu_context_enter(&ctx);
363                         d = ldt->ldt_ops->ldto_device_alloc(&ctx, ldt, cfg);
364                         lu_context_exit(&ctx);
365                         lu_context_fini(&ctx);
366                         if (!IS_ERR(d)) {
367                                 obd->obd_lu_dev = d;
368                                 d->ld_obd = obd;
369                                 rc = 0;
370                         } else
371                                 rc = PTR_ERR(d);
372                 }
373         } else
374 #endif
375         {
376                 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
377                 OBD_COUNTER_INCREMENT(obd, setup);
378                 rc = OBP(obd, setup)(obd, cfg);
379         }
380         RETURN(rc);
381 }
382
383 static inline int obd_precleanup(struct obd_device *obd,
384                                  enum obd_cleanup_stage cleanup_stage)
385 {
386         int rc;
387         DECLARE_LU_VARS(ldt, d);
388         ENTRY;
389
390         OBD_CHECK_DEV(obd);
391 #ifdef __KERNEL__
392         ldt = obd->obd_type->typ_lu;
393         d = obd->obd_lu_dev;
394         if (ldt != NULL && d != NULL) {
395                 struct lu_context ctx;
396
397                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
398                 if (rc == 0) {
399                         lu_context_enter(&ctx);
400                         ldt->ldt_ops->ldto_device_fini(&ctx, d);
401                         lu_context_exit(&ctx);
402                         lu_context_fini(&ctx);
403                         obd->obd_lu_dev = NULL;
404                         rc = 0;
405                 }
406         } else
407 #endif
408         {
409                 OBD_CHECK_DT_OP(obd, precleanup, 0);
410                 rc = OBP(obd, precleanup)(obd, cleanup_stage);
411         }
412         
413         OBD_COUNTER_INCREMENT(obd, precleanup);
414         RETURN(rc);
415 }
416
417 static inline int obd_cleanup(struct obd_device *obd)
418 {
419         int rc;
420         DECLARE_LU_VARS(ldt, d);
421         ENTRY;
422
423         OBD_CHECK_DEV(obd);
424
425 #ifdef __KERNEL__
426         ldt = obd->obd_type->typ_lu;
427         d = obd->obd_lu_dev;
428         if (ldt != NULL && d != NULL) {
429                 struct lu_context ctx;
430
431                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
432                 if (rc == 0) {
433                         lu_context_enter(&ctx);
434                         ldt->ldt_ops->ldto_device_free(&ctx, d);
435                         lu_context_exit(&ctx);
436                         lu_context_fini(&ctx);
437                         obd->obd_lu_dev = NULL;
438                         rc = 0;
439                 }
440         } else
441 #endif
442         {
443                 OBD_CHECK_DT_OP(obd, cleanup, 0);
444                 rc = OBP(obd, cleanup)(obd);
445         }
446         OBD_COUNTER_INCREMENT(obd, cleanup);
447         RETURN(rc);
448 }
449
450 static inline int
451 obd_process_config(struct obd_device *obd, int datalen, void *data)
452 {
453         int rc;
454         DECLARE_LU_VARS(ldt, d);
455         ENTRY;
456
457         OBD_CHECK_DEV(obd);
458
459 #ifdef __KERNEL__
460         ldt = obd->obd_type->typ_lu;
461         d = obd->obd_lu_dev;
462         if (ldt != NULL && d != NULL) {
463                 struct lu_context ctx;
464
465                 rc = lu_context_init(&ctx, ldt->ldt_ctx_tags);
466                 if (rc == 0) {
467                         lu_context_enter(&ctx);
468                         rc = d->ld_ops->ldo_process_config(&ctx, d, data);
469                         lu_context_exit(&ctx);
470                         lu_context_fini(&ctx);
471                 }
472         } else
473 #endif
474         {
475                 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
476                 rc = OBP(obd, process_config)(obd, datalen, data);
477         }
478         OBD_COUNTER_INCREMENT(obd, process_config);
479
480         RETURN(rc);
481 }
482
483 /* Pack an in-memory MD struct for storage on disk.
484  * Returns +ve size of packed MD (0 for free), or -ve error.
485  *
486  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
487  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
488  * If @*disk_tgt == NULL, it will be allocated
489  */
490 static inline int obd_packmd(struct obd_export *exp,
491                              struct lov_mds_md **disk_tgt,
492                              struct lov_stripe_md *mem_src)
493 {
494         int rc;
495         ENTRY;
496
497         EXP_CHECK_DT_OP(exp, packmd);
498         OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
499
500         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
501         RETURN(rc);
502 }
503
504 static inline int obd_size_diskmd(struct obd_export *exp,
505                                   struct lov_stripe_md *mem_src)
506 {
507         return obd_packmd(exp, NULL, mem_src);
508 }
509
510 /* helper functions */
511 static inline int obd_alloc_diskmd(struct obd_export *exp,
512                                    struct lov_mds_md **disk_tgt)
513 {
514         LASSERT(disk_tgt);
515         LASSERT(*disk_tgt == NULL);
516         return obd_packmd(exp, disk_tgt, NULL);
517 }
518
519 static inline int obd_free_diskmd(struct obd_export *exp,
520                                   struct lov_mds_md **disk_tgt)
521 {
522         LASSERT(disk_tgt);
523         LASSERT(*disk_tgt);
524         return obd_packmd(exp, disk_tgt, NULL);
525 }
526
527 /* Unpack an MD struct from disk to in-memory format.
528  * Returns +ve size of unpacked MD (0 for free), or -ve error.
529  *
530  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
531  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
532  * If @*mem_tgt == NULL, it will be allocated
533  */
534 static inline int obd_unpackmd(struct obd_export *exp,
535                                struct lov_stripe_md **mem_tgt,
536                                struct lov_mds_md *disk_src,
537                                int disk_len)
538 {
539         int rc;
540         ENTRY;
541
542         EXP_CHECK_DT_OP(exp, unpackmd);
543         OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
544
545         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
546         RETURN(rc);
547 }
548
549 /* helper functions */
550 static inline int obd_alloc_memmd(struct obd_export *exp,
551                                   struct lov_stripe_md **mem_tgt)
552 {
553         LASSERT(mem_tgt);
554         LASSERT(*mem_tgt == NULL);
555         return obd_unpackmd(exp, mem_tgt, NULL, 0);
556 }
557
558 static inline int obd_free_memmd(struct obd_export *exp,
559                                  struct lov_stripe_md **mem_tgt)
560 {
561         LASSERT(mem_tgt);
562         LASSERT(*mem_tgt);
563         return obd_unpackmd(exp, mem_tgt, NULL, 0);
564 }
565
566 static inline int obd_checkmd(struct obd_export *exp,
567                               struct obd_export *md_exp,
568                               struct lov_stripe_md *mem_tgt)
569 {
570         int rc;
571         ENTRY;
572
573         EXP_CHECK_DT_OP(exp, checkmd);
574         OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
575
576         rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
577         RETURN(rc);
578 }
579
580 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
581                              struct lov_stripe_md **ea,
582                              struct obd_trans_info *oti)
583 {
584         int rc;
585         ENTRY;
586
587         EXP_CHECK_DT_OP(exp, create);
588         OBD_COUNTER_INCREMENT(exp->exp_obd, create);
589
590         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
591         RETURN(rc);
592 }
593
594 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
595                               struct lov_stripe_md *ea,
596                               struct obd_trans_info *oti,
597                               struct obd_export *md_exp)
598 {
599         int rc;
600         ENTRY;
601
602         EXP_CHECK_DT_OP(exp, destroy);
603         OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
604
605         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
606         RETURN(rc);
607 }
608
609 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
610                               struct lov_stripe_md *ea)
611 {
612         int rc;
613         ENTRY;
614
615         EXP_CHECK_DT_OP(exp, getattr);
616         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
617
618         rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
619         RETURN(rc);
620 }
621
622 static inline int obd_getattr_async(struct obd_export *exp,
623                                     struct obdo *obdo, struct lov_stripe_md *ea,
624                                     struct ptlrpc_request_set *set)
625 {
626         int rc;
627         ENTRY;
628
629         EXP_CHECK_DT_OP(exp, getattr);
630         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
631
632         rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
633         RETURN(rc);
634 }
635
636 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
637                               struct lov_stripe_md *ea,
638                               struct obd_trans_info *oti)
639 {
640         int rc;
641         ENTRY;
642
643         EXP_CHECK_DT_OP(exp, setattr);
644         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
645
646         rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
647         RETURN(rc);
648 }
649
650 static inline int obd_setattr_async(struct obd_export *exp,
651                                     struct obdo *obdo,
652                                     struct lov_stripe_md *ea,
653                                     struct obd_trans_info *oti)
654 {
655         int rc;
656         ENTRY;
657
658         EXP_CHECK_DT_OP(exp, setattr_async);
659         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
660
661         rc = OBP(exp->exp_obd, setattr_async)(exp, obdo, ea, oti);
662         RETURN(rc);
663 }
664
665 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
666                                int priority)
667 {
668         struct obd_device *obd = imp->imp_obd;
669         int rc;
670         ENTRY;
671
672         OBD_CHECK_DEV_ACTIVE(obd);
673         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
674         OBD_COUNTER_INCREMENT(obd, add_conn);
675
676         rc = OBP(obd, add_conn)(imp, uuid, priority);
677         RETURN(rc);
678 }
679
680 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
681 {
682         struct obd_device *obd = imp->imp_obd;
683         int rc;
684         ENTRY;
685
686         OBD_CHECK_DEV_ACTIVE(obd);
687         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
688         OBD_COUNTER_INCREMENT(obd, del_conn);
689
690         rc = OBP(obd, del_conn)(imp, uuid);
691         RETURN(rc);
692 }
693
694 static inline int obd_connect(const struct lu_context *ctx,
695                               struct lustre_handle *conn,struct obd_device *obd,
696                               struct obd_uuid *cluuid,
697                               struct obd_connect_data *d)
698 {
699         int rc;
700         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
701         ENTRY;
702
703         OBD_CHECK_DEV_ACTIVE(obd);
704         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
705         OBD_COUNTER_INCREMENT(obd, connect);
706
707         rc = OBP(obd, connect)(ctx, conn, obd, cluuid, d);
708         /* check that only subset is granted */
709         LASSERT(ergo(d != NULL,
710                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
711         RETURN(rc);
712 }
713
714 static inline int obd_reconnect(struct obd_export *exp,
715                                 struct obd_device *obd,
716                                 struct obd_uuid *cluuid,
717                                 struct obd_connect_data *d)
718 {
719         int rc;
720         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
721         ENTRY;
722
723         OBD_CHECK_DEV_ACTIVE(obd);
724         OBD_CHECK_DT_OP(obd, reconnect, 0);
725         OBD_COUNTER_INCREMENT(obd, reconnect);
726
727         rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
728         /* check that only subset is granted */
729         LASSERT(ergo(d != NULL,
730                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
731         RETURN(rc);
732 }
733
734 static inline int obd_disconnect(struct obd_export *exp)
735 {
736         int rc;
737         ENTRY;
738
739         EXP_CHECK_DT_OP(exp, disconnect);
740         OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
741
742         rc = OBP(exp->exp_obd, disconnect)(exp);
743         RETURN(rc);
744 }
745
746 static inline int obd_fid_init(struct obd_export *exp)
747 {
748         int rc;
749         ENTRY;
750
751         if (OBP(exp->exp_obd, fid_init) == NULL)
752                 RETURN(-ENOTSUPP);
753
754         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_init);
755
756         rc = OBP(exp->exp_obd, fid_init)(exp);
757         RETURN(rc);
758 }
759
760 static inline int obd_fid_fini(struct obd_export *exp)
761 {
762         int rc;
763         ENTRY;
764
765         if (OBP(exp->exp_obd, fid_fini) == NULL)
766                 RETURN(-ENOTSUPP);
767
768         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_fini);
769
770         rc = OBP(exp->exp_obd, fid_fini)(exp);
771         RETURN(rc);
772 }
773
774 static inline int obd_fid_alloc(struct obd_export *exp,
775                                 struct lu_fid *fid,
776                                 struct lu_placement_hint *hint)
777 {
778         int rc;
779         ENTRY;
780
781         if (OBP(exp->exp_obd, fid_alloc) == NULL)
782                 RETURN(-ENOTSUPP);
783
784         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
785
786         rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
787         RETURN(rc);
788 }
789
790 static inline int obd_fid_delete(struct obd_export *exp,
791                                  struct lu_fid *fid)
792 {
793         int rc;
794         ENTRY;
795
796         if (OBP(exp->exp_obd, fid_delete) == NULL)
797                 RETURN(0);
798
799         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
800         rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
801         RETURN(rc);
802 }
803
804 static inline int obd_init_export(struct obd_export *exp)
805 {
806         int rc = 0;
807
808         ENTRY;
809         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
810             OBP((exp)->exp_obd, init_export))
811                 rc = OBP(exp->exp_obd, init_export)(exp);
812         RETURN(rc);
813 }
814
815 static inline int obd_destroy_export(struct obd_export *exp)
816 {
817         ENTRY;
818         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
819             OBP((exp)->exp_obd, destroy_export))
820                 OBP(exp->exp_obd, destroy_export)(exp);
821         RETURN(0);
822 }
823
824 static inline struct dentry *
825 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
826 {
827         LASSERT(exp->exp_obd);
828
829         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
830                                exp->exp_obd);
831 }
832
833 static inline int
834 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
835 {
836         LASSERT(exp->exp_obd);
837         CERROR("FIXME what's the story here?  This needs to be an obd fn?\n");
838 #if 0
839         return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
840                               dentry, exp->exp_obd);
841 #endif
842         return 0;
843 }
844
845 #ifndef time_before
846 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
847 #endif
848
849 /* @max_age is the oldest time in jiffies that we accept using a cached data.
850  * If the cache is older than @max_age we will get a new value from the
851  * target.  Use a value of "jiffies + HZ" to guarantee freshness. */
852 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
853                              unsigned long max_age)
854 {
855         int rc = 0;
856         ENTRY;
857
858         if (obd == NULL)
859                 RETURN(-EINVAL);
860
861         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
862         OBD_COUNTER_INCREMENT(obd, statfs);
863
864         CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
865         if (time_before(obd->obd_osfs_age, max_age)) {
866                 rc = OBP(obd, statfs)(obd, osfs, max_age);
867                 if (rc == 0) {
868                         spin_lock(&obd->obd_osfs_lock);
869                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
870                         obd->obd_osfs_age = jiffies;
871                         spin_unlock(&obd->obd_osfs_lock);
872                 }
873         } else {
874                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
875                 spin_lock(&obd->obd_osfs_lock);
876                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
877                 spin_unlock(&obd->obd_osfs_lock);
878         }
879         RETURN(rc);
880 }
881
882 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
883                            struct lov_stripe_md *ea, obd_size start,
884                            obd_size end)
885 {
886         int rc;
887         ENTRY;
888
889         OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
890         OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
891
892         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
893         RETURN(rc);
894 }
895
896 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
897                             struct lov_stripe_md *ea, obd_size start,
898                             obd_size end, struct obd_trans_info *oti)
899 {
900         int rc;
901         ENTRY;
902
903         EXP_CHECK_DT_OP(exp, punch);
904         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
905
906         rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
907         RETURN(rc);
908 }
909
910 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
911                           struct lov_stripe_md *ea, obd_count oa_bufs,
912                           struct brw_page *pg, struct obd_trans_info *oti)
913 {
914         int rc;
915         ENTRY;
916
917         EXP_CHECK_DT_OP(exp, brw);
918         OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
919
920         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
921                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
922                        "or OBD_BRW_CHECK\n");
923                 LBUG();
924         }
925
926         rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
927         RETURN(rc);
928 }
929
930 static inline int obd_brw_async(int cmd, struct obd_export *exp,
931                                 struct obdo *oa, struct lov_stripe_md *ea,
932                                 obd_count oa_bufs, struct brw_page *pg,
933                                 struct ptlrpc_request_set *set,
934                                 struct obd_trans_info *oti)
935 {
936         int rc;
937         ENTRY;
938
939         EXP_CHECK_DT_OP(exp, brw_async);
940         OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
941
942         if (!(cmd & OBD_BRW_RWMASK)) {
943                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
944                 LBUG();
945         }
946
947         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
948                                           oti);
949         RETURN(rc);
950 }
951
952 static inline  int obd_prep_async_page(struct obd_export *exp,
953                                        struct lov_stripe_md *lsm,
954                                        struct lov_oinfo *loi,
955                                        struct page *page, obd_off offset,
956                                        struct obd_async_page_ops *ops,
957                                        void *data, void **res)
958 {
959         int ret;
960         ENTRY;
961
962         OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
963         OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
964
965         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
966                                                  ops, data, res);
967         RETURN(ret);
968 }
969
970 static inline int obd_queue_async_io(struct obd_export *exp,
971                                      struct lov_stripe_md *lsm,
972                                      struct lov_oinfo *loi, void *cookie,
973                                      int cmd, obd_off off, int count,
974                                      obd_flag brw_flags, obd_flag async_flags)
975 {
976         int rc;
977         ENTRY;
978
979         OBD_CHECK_DT_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
980         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
981         LASSERT(cmd & OBD_BRW_RWMASK);
982
983         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
984                                                count, brw_flags, async_flags);
985         RETURN(rc);
986 }
987
988 static inline int obd_set_async_flags(struct obd_export *exp,
989                                       struct lov_stripe_md *lsm,
990                                       struct lov_oinfo *loi, void *cookie,
991                                       obd_flag async_flags)
992 {
993         int rc;
994         ENTRY;
995
996         OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
997         OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
998
999         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1000                                                 async_flags);
1001         RETURN(rc);
1002 }
1003
1004 static inline int obd_queue_group_io(struct obd_export *exp,
1005                                      struct lov_stripe_md *lsm,
1006                                      struct lov_oinfo *loi,
1007                                      struct obd_io_group *oig,
1008                                      void *cookie, int cmd, obd_off off,
1009                                      int count, obd_flag brw_flags,
1010                                      obd_flag async_flags)
1011 {
1012         int rc;
1013         ENTRY;
1014
1015         OBD_CHECK_DT_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1016         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
1017         LASSERT(cmd & OBD_BRW_RWMASK);
1018
1019         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1020                                                cmd, off, count, brw_flags,
1021                                                async_flags);
1022         RETURN(rc);
1023 }
1024
1025 static inline int obd_trigger_group_io(struct obd_export *exp,
1026                                        struct lov_stripe_md *lsm,
1027                                        struct lov_oinfo *loi,
1028                                        struct obd_io_group *oig)
1029 {
1030         int rc;
1031         ENTRY;
1032
1033         OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1034         OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
1035
1036         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1037         RETURN(rc);
1038 }
1039
1040 static inline int obd_teardown_async_page(struct obd_export *exp,
1041                                           struct lov_stripe_md *lsm,
1042                                           struct lov_oinfo *loi, void *cookie)
1043 {
1044         int rc;
1045         ENTRY;
1046
1047         OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1048         OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
1049
1050         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1051         RETURN(rc);
1052 }
1053
1054 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1055                              int objcount, struct obd_ioobj *obj,
1056                              int niocount, struct niobuf_remote *remote,
1057                              struct niobuf_local *local,
1058                              struct obd_trans_info *oti)
1059 {
1060         int rc;
1061         ENTRY;
1062
1063         OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1064         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1065
1066         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1067                                        remote, local, oti);
1068         RETURN(rc);
1069 }
1070
1071 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1072                                int objcount, struct obd_ioobj *obj,
1073                                int niocount, struct niobuf_local *local,
1074                                struct obd_trans_info *oti, int rc)
1075 {
1076         ENTRY;
1077
1078         OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1079         OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1080
1081         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1082                                          local, oti, rc);
1083         RETURN(rc);
1084 }
1085
1086 static inline int obd_merge_lvb(struct obd_export *exp,
1087                                 struct lov_stripe_md *lsm,
1088                                 struct ost_lvb *lvb, int kms_only)
1089 {
1090         int rc;
1091         ENTRY;
1092
1093         OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1094         OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1095
1096         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1097         RETURN(rc);
1098 }
1099
1100 static inline int obd_adjust_kms(struct obd_export *exp,
1101                                  struct lov_stripe_md *lsm, obd_off size,
1102                                  int shrink)
1103 {
1104         int rc;
1105         ENTRY;
1106
1107         OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1108         OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1109
1110         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1111         RETURN(rc);
1112 }
1113
1114 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1115                                 int len, void *karg, void *uarg)
1116 {
1117         int rc;
1118         ENTRY;
1119
1120         EXP_CHECK_DT_OP(exp, iocontrol);
1121         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1122
1123         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1124         RETURN(rc);
1125 }
1126
1127 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
1128                               __u32 type, ldlm_policy_data_t *policy,
1129                               __u32 mode, int *flags, void *bl_cb, void *cp_cb,
1130                               void *gl_cb, void *data, __u32 lvb_len,
1131                               void *lvb_swabber, struct lustre_handle *lockh)
1132 {
1133         int rc;
1134         ENTRY;
1135
1136         EXP_CHECK_DT_OP(exp, enqueue);
1137         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1138
1139         rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
1140                                         bl_cb, cp_cb, gl_cb, data, lvb_len,
1141                                         lvb_swabber, lockh);
1142         RETURN(rc);
1143 }
1144
1145 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1146                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1147                             int *flags, void *data, struct lustre_handle *lockh)
1148 {
1149         int rc;
1150         ENTRY;
1151
1152         EXP_CHECK_DT_OP(exp, match);
1153         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1154
1155         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1156                                       lockh);
1157         RETURN(rc);
1158 }
1159
1160 static inline int obd_change_cbdata(struct obd_export *exp,
1161                                     struct lov_stripe_md *lsm,
1162                                     ldlm_iterator_t it, void *data)
1163 {
1164         int rc;
1165         ENTRY;
1166
1167         EXP_CHECK_DT_OP(exp, change_cbdata);
1168         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1169
1170         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1171         RETURN(rc);
1172 }
1173
1174 static inline int obd_cancel(struct obd_export *exp,
1175                              struct lov_stripe_md *ea, __u32 mode,
1176                              struct lustre_handle *lockh)
1177 {
1178         int rc;
1179         ENTRY;
1180
1181         EXP_CHECK_DT_OP(exp, cancel);
1182         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1183
1184         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1185         RETURN(rc);
1186 }
1187
1188 static inline int obd_cancel_unused(struct obd_export *exp,
1189                                     struct lov_stripe_md *ea,
1190                                     int flags, void *opaque)
1191 {
1192         int rc;
1193         ENTRY;
1194
1195         EXP_CHECK_DT_OP(exp, cancel_unused);
1196         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1197
1198         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1199         RETURN(rc);
1200 }
1201
1202 static inline int obd_join_lru(struct obd_export *exp,
1203                                struct lov_stripe_md *ea, int join)
1204 {
1205         int rc;
1206         ENTRY;
1207
1208         EXP_CHECK_DT_OP(exp, join_lru);
1209         OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1210
1211         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1212         RETURN(rc);
1213 }
1214
1215 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1216                                  struct obdo *oa,
1217                                  int objcount, struct obd_ioobj *obj,
1218                                  int niocount, struct niobuf_remote *remote)
1219 {
1220         int rc;
1221
1222         EXP_CHECK_DT_OP(exp, preprw);
1223         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1224
1225         rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1226                                            niocount, remote);
1227         class_export_put(exp);
1228         return(rc);
1229 }
1230
1231 static inline int obd_pin(struct obd_export *exp, struct lu_fid *fid,
1232                           struct obd_client_handle *handle, int flag)
1233 {
1234         int rc;
1235
1236         EXP_CHECK_DT_OP(exp, pin);
1237         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1238
1239         rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1240         return(rc);
1241 }
1242
1243 static inline int obd_unpin(struct obd_export *exp,
1244                             struct obd_client_handle *handle, int flag)
1245 {
1246         int rc;
1247
1248         EXP_CHECK_DT_OP(exp, unpin);
1249         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1250
1251         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1252         return(rc);
1253 }
1254
1255
1256 static inline void obd_import_event(struct obd_device *obd,
1257                                     struct obd_import *imp,
1258                                     enum obd_import_event event)
1259 {
1260         if (!obd) {
1261                 CERROR("NULL device\n");
1262                 EXIT;
1263                 return;
1264         }
1265         if (obd->obd_set_up && OBP(obd, import_event)) {
1266                 OBD_COUNTER_INCREMENT(obd, import_event);
1267                 OBP(obd, import_event)(obd, imp, event);
1268         }
1269 }
1270
1271 static inline int obd_notify(struct obd_device *obd,
1272                              struct obd_device *watched,
1273                              enum obd_notify_event ev,
1274                              void *data)
1275 {
1276         OBD_CHECK_DEV(obd);
1277
1278         /* the check for async_recov is a complete hack - I'm hereby
1279            overloading the meaning to also mean "this was called from
1280            mds_postsetup".  I know that my mds is able to handle notifies
1281            by this point, and it needs to get them to execute mds_postrecov. */
1282         if (!obd->obd_set_up && !obd->obd_async_recov) {
1283                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1284                 return -EINVAL;
1285         }
1286
1287         if (!OBP(obd, notify)) {
1288                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1289                 return -ENOSYS;
1290         }
1291
1292         OBD_COUNTER_INCREMENT(obd, notify);
1293         return OBP(obd, notify)(obd, watched, ev, data);
1294 }
1295
1296 static inline int obd_notify_observer(struct obd_device *observer,
1297                                       struct obd_device *observed,
1298                                       enum obd_notify_event ev,
1299                                       void *data)
1300 {
1301         int rc1;
1302         int rc2;
1303
1304         struct obd_notify_upcall *onu;
1305
1306         if (observer->obd_observer)
1307                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1308         else
1309                 rc1 = 0;
1310         /*
1311          * Also, call non-obd listener, if any
1312          */
1313         onu = &observer->obd_upcall;
1314         if (onu->onu_upcall != NULL)
1315                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1316         else
1317                 rc2 = 0;
1318
1319         return rc1 ? rc1 : rc2;
1320 }
1321
1322 static inline int obd_quotacheck(struct obd_export *exp,
1323                                  struct obd_quotactl *oqctl)
1324 {
1325         int rc;
1326         ENTRY;
1327
1328         EXP_CHECK_DT_OP(exp, quotacheck);
1329         OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1330
1331         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1332         RETURN(rc);
1333 }
1334
1335 static inline int obd_quotactl(struct obd_export *exp,
1336                                struct obd_quotactl *oqctl)
1337 {
1338         int rc;
1339         ENTRY;
1340
1341         EXP_CHECK_DT_OP(exp, quotactl);
1342         OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1343
1344         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1345         RETURN(rc);
1346 }
1347
1348 static inline int obd_health_check(struct obd_device *obd)
1349 {
1350         /* returns: 0 on healthy
1351          *         >0 on unhealthy + reason code/flag
1352          *            however the only suppored reason == 1 right now
1353          *            We'll need to define some better reasons
1354          *            or flags in the future.
1355          *         <0 on error
1356          */
1357         int rc;
1358         ENTRY;
1359
1360         /* don't use EXP_CHECK_OP, because NULL method is normal here */
1361         if (obd == NULL || !OBT(obd)) {
1362                 CERROR("cleaned up obd\n");
1363                 RETURN(-EOPNOTSUPP);
1364         }
1365         if (!obd->obd_set_up || obd->obd_stopping)
1366                 RETURN(0);
1367         if (!OBP(obd, health_check))
1368                 RETURN(0);
1369
1370         rc = OBP(obd, health_check)(obd);
1371         RETURN(rc);
1372 }
1373
1374 static inline int obd_register_observer(struct obd_device *obd,
1375                                         struct obd_device *observer)
1376 {
1377         ENTRY;
1378         OBD_CHECK_DEV(obd);
1379         if (obd->obd_observer && observer)
1380                 RETURN(-EALREADY);
1381         obd->obd_observer = observer;
1382         RETURN(0);
1383 }
1384
1385 /* metadata helpers */
1386 static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
1387 {
1388         int rc;
1389         ENTRY;
1390
1391         EXP_CHECK_MD_OP(exp, getstatus);
1392         MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1393         rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1394         RETURN(rc);
1395 }
1396
1397 static inline int md_getattr(struct obd_export *exp, struct lu_fid *fid,
1398                              obd_valid valid, int ea_size,
1399                              struct ptlrpc_request **request)
1400 {
1401         int rc;
1402         ENTRY;
1403         EXP_CHECK_MD_OP(exp, getattr);
1404         MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1405         rc = MDP(exp->exp_obd, getattr)(exp, fid, valid,
1406                                         ea_size, request);
1407         RETURN(rc);
1408 }
1409
1410 static inline int md_change_cbdata(struct obd_export *exp, struct lu_fid *fid,
1411                                    ldlm_iterator_t it, void *data)
1412 {
1413         int rc;
1414         ENTRY;
1415         EXP_CHECK_MD_OP(exp, change_cbdata);
1416         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1417         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1418         RETURN(rc);
1419 }
1420
1421 static inline int md_close(struct obd_export *exp,
1422                            struct md_op_data *op_data,
1423                            struct obd_client_handle *och,
1424                            struct ptlrpc_request **request)
1425 {
1426         int rc;
1427         ENTRY;
1428         EXP_CHECK_MD_OP(exp, close);
1429         MD_COUNTER_INCREMENT(exp->exp_obd, close);
1430         rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1431         RETURN(rc);
1432 }
1433
1434 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1435                             const void *data, int datalen, int mode,
1436                             __u32 uid, __u32 gid, __u32 cap_effective, __u64 rdev,
1437                             struct ptlrpc_request **request)
1438 {
1439         int rc;
1440         ENTRY;
1441         EXP_CHECK_MD_OP(exp, create);
1442         MD_COUNTER_INCREMENT(exp->exp_obd, create);
1443         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1444                                        uid, gid, cap_effective, rdev, request);
1445         RETURN(rc);
1446 }
1447
1448 static inline int md_done_writing(struct obd_export *exp,
1449                                   struct md_op_data *op_data)
1450 {
1451         int rc;
1452         ENTRY;
1453         EXP_CHECK_MD_OP(exp, done_writing);
1454         MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1455         rc = MDP(exp->exp_obd, done_writing)(exp, op_data);
1456         RETURN(rc);
1457 }
1458
1459 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1460                              struct lookup_intent *it, int lock_mode,
1461                              struct md_op_data *op_data,
1462                              struct lustre_handle *lockh,
1463                              void *lmm, int lmmsize,
1464                              ldlm_completion_callback cb_completion,
1465                              ldlm_blocking_callback cb_blocking,
1466                              void *cb_data, int extra_lock_flags)
1467 {
1468         int rc;
1469         ENTRY;
1470         EXP_CHECK_MD_OP(exp, enqueue);
1471         MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1472         rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1473                                         op_data, lockh, lmm, lmmsize,
1474                                         cb_completion, cb_blocking,
1475                                         cb_data, extra_lock_flags);
1476         RETURN(rc);
1477 }
1478
1479 static inline int md_getattr_name(struct obd_export *exp, struct lu_fid *fid,
1480                                   const char *filename, int namelen,
1481                                   obd_valid valid, int ea_size,
1482                                   struct ptlrpc_request **request)
1483 {
1484         int rc;
1485         ENTRY;
1486         EXP_CHECK_MD_OP(exp, getattr_name);
1487         MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1488         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1489                                              valid, ea_size, request);
1490         RETURN(rc);
1491 }
1492
1493 static inline int md_intent_lock(struct obd_export *exp,
1494                                  struct md_op_data *op_data,
1495                                  void *lmm, int lmmsize,
1496                                  struct lookup_intent *it,
1497                                  int flags, struct ptlrpc_request **reqp,
1498                                  ldlm_blocking_callback cb_blocking,
1499                                  int extra_lock_flags)
1500 {
1501         int rc;
1502         ENTRY;
1503         EXP_CHECK_MD_OP(exp, intent_lock);
1504         MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1505         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1506                                             it, flags, reqp, cb_blocking,
1507                                             extra_lock_flags);
1508         RETURN(rc);
1509 }
1510
1511 static inline int md_link(struct obd_export *exp,
1512                           struct md_op_data *op_data,
1513                           struct ptlrpc_request **request)
1514 {
1515         int rc;
1516         ENTRY;
1517         EXP_CHECK_MD_OP(exp, link);
1518         MD_COUNTER_INCREMENT(exp->exp_obd, link);
1519         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1520         RETURN(rc);
1521 }
1522
1523 static inline int md_rename(struct obd_export *exp,
1524                             struct md_op_data *op_data,
1525                             const char *old, int oldlen,
1526                             const char *new, int newlen,
1527                             struct ptlrpc_request **request)
1528 {
1529         int rc;
1530         ENTRY;
1531         EXP_CHECK_MD_OP(exp, rename);
1532         MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1533         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1534                                        newlen, request);
1535         RETURN(rc);
1536 }
1537
1538 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1539                              struct iattr *iattr, void *ea, int ealen,
1540                              void *ea2, int ea2len, struct ptlrpc_request **request)
1541 {
1542         int rc;
1543         ENTRY;
1544         EXP_CHECK_MD_OP(exp, setattr);
1545         MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1546         rc = MDP(exp->exp_obd, setattr)(exp, op_data, iattr, ea, ealen,
1547                                         ea2, ea2len, request);
1548         RETURN(rc);
1549 }
1550
1551 static inline int md_sync(struct obd_export *exp, struct lu_fid *fid,
1552                           struct ptlrpc_request **request)
1553 {
1554         int rc;
1555         ENTRY;
1556         EXP_CHECK_MD_OP(exp, sync);
1557         MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1558         rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1559         RETURN(rc);
1560 }
1561
1562 static inline int md_readpage(struct obd_export *exp, struct lu_fid *fid,
1563                               __u64 offset, struct page *page,
1564                               struct ptlrpc_request **request)
1565 {
1566         int rc;
1567         ENTRY;
1568         EXP_CHECK_MD_OP(exp, readpage);
1569         MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1570         rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1571         RETURN(rc);
1572 }
1573
1574 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1575                             struct ptlrpc_request **request)
1576 {
1577         int rc;
1578         ENTRY;
1579         EXP_CHECK_MD_OP(exp, unlink);
1580         MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1581         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1582         RETURN(rc);
1583 }
1584
1585 static inline int md_get_lustre_md(struct obd_export *exp,
1586                                    struct ptlrpc_request *req,
1587                                    int offset, struct obd_export *dt_exp,
1588                                    struct lustre_md *md)
1589 {
1590         ENTRY;
1591         EXP_CHECK_MD_OP(exp, get_lustre_md);
1592         MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1593         RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1594                                                 dt_exp, md));
1595 }
1596
1597 static inline int md_free_lustre_md(struct obd_export *exp,
1598                                     struct lustre_md *md)
1599 {
1600         ENTRY;
1601         EXP_CHECK_MD_OP(exp, free_lustre_md);
1602         MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1603         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1604 }
1605
1606 static inline int md_setxattr(struct obd_export *exp, struct lu_fid *fid,
1607                               obd_valid valid, const char *name,
1608                               const char *input, int input_size,
1609                               int output_size, int flags,
1610                               struct ptlrpc_request **request)
1611 {
1612         ENTRY;
1613         EXP_CHECK_MD_OP(exp, setxattr);
1614         MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1615         RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1616                                            input_size, output_size, flags,
1617                                            request));
1618 }
1619
1620 static inline int md_getxattr(struct obd_export *exp, struct lu_fid *fid,
1621                               obd_valid valid, const char *name,
1622                               const char *input, int input_size,
1623                               int output_size, int flags,
1624                               struct ptlrpc_request **request)
1625 {
1626         ENTRY;
1627         EXP_CHECK_MD_OP(exp, getxattr);
1628         MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1629         RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1630                                            input_size, output_size, flags,
1631                                            request));
1632 }
1633
1634 static inline int md_set_open_replay_data(struct obd_export *exp,
1635                                           struct obd_client_handle *och,
1636                                           struct ptlrpc_request *open_req)
1637 {
1638         ENTRY;
1639         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1640         MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1641         RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1642 }
1643
1644 static inline int md_clear_open_replay_data(struct obd_export *exp,
1645                                             struct obd_client_handle *och)
1646 {
1647         ENTRY;
1648         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1649         MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1650         RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1651 }
1652
1653 static inline int md_set_lock_data(struct obd_export *exp,
1654                                    __u64 *lockh, void *data)
1655 {
1656         ENTRY;
1657         EXP_CHECK_MD_OP(exp, set_lock_data);
1658         MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1659         RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1660 }
1661
1662 static inline int md_cancel_unused(struct obd_export *exp,
1663                                    struct lu_fid *fid,
1664                                    int flags, void *opaque)
1665 {
1666         int rc;
1667         ENTRY;
1668
1669         EXP_CHECK_MD_OP(exp, cancel_unused);
1670         MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1671
1672         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1673         RETURN(rc);
1674 }
1675
1676 static inline int md_lock_match(struct obd_export *exp, int flags,
1677                                 struct lu_fid *fid, ldlm_type_t type,
1678                                 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1679                                 struct lustre_handle *lockh)
1680 {
1681         ENTRY;
1682         EXP_CHECK_MD_OP(exp, lock_match);
1683         MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1684         RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1685                                              policy, mode, lockh));
1686 }
1687
1688 static inline int md_init_ea_size(struct obd_export *exp,
1689                                   int easize, int def_asize,
1690                                   int cookiesize)
1691 {
1692         ENTRY;
1693         EXP_CHECK_MD_OP(exp, init_ea_size);
1694         MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1695         RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize,
1696                                                def_asize,
1697                                                cookiesize));
1698 }
1699
1700 /* OBD Metadata Support */
1701 extern int obd_init_caches(void);
1702 extern void obd_cleanup_caches(void);
1703
1704 /* support routines */
1705 extern cfs_mem_cache_t *obdo_cachep;
1706 static inline struct obdo *obdo_alloc(void)
1707 {
1708         struct obdo *oa;
1709         OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1710         return oa;
1711 }
1712
1713 static inline void obdo_free(struct obdo *oa)
1714 {
1715         OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1716 }
1717
1718 static inline void obdo2fid(struct obdo *oa,
1719                             struct lu_fid *fid)
1720 {
1721         /* something here */
1722 }
1723
1724 static inline void fid2obdo(struct lu_fid *fid,
1725                             struct obdo *oa)
1726 {
1727         /* something here */
1728 }
1729
1730 /* I'm as embarrassed about this as you are.
1731  *
1732  * <shaver> // XXX do not look into _superhack with remaining eye
1733  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1734 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1735
1736 /* sysctl.c */
1737 extern void obd_sysctl_init (void);
1738 extern void obd_sysctl_clean (void);
1739
1740 /* uuid.c  */
1741 typedef __u8 class_uuid_t[16];
1742 void class_generate_random_uuid(class_uuid_t uuid);
1743 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1744
1745 /* lustre_peer.c    */
1746 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1747 int class_add_uuid(const char *uuid, __u64 nid);
1748 int class_del_uuid (const char *uuid);
1749 void class_init_uuidlist(void);
1750 void class_exit_uuidlist(void);
1751
1752 /* mea.c */
1753 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1754 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1755
1756 #endif /* __LINUX_OBD_CLASS_H */