Whamcloud - gitweb
Move random uuid functions to prng.c
[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 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
46 extern spinlock_t obd_dev_lock;
47
48 /* OBD Operations Declarations */
49 extern struct obd_device *class_conn2obd(struct lustre_handle *);
50 extern struct obd_device *class_exp2obd(struct obd_export *);
51
52 /* genops.c */
53 struct obd_export *class_conn2export(struct lustre_handle *);
54 int class_register_type(struct obd_ops *ops, struct lprocfs_vars *,
55                         const char *nm);
56 int class_unregister_type(const char *nm);
57
58 struct obd_device *class_newdev(const char *type_name, const char *name);
59 void class_release_dev(struct obd_device *obd);
60
61 int class_name2dev(const char *name);
62 struct obd_device *class_name2obd(const char *name);
63 int class_uuid2dev(struct obd_uuid *uuid);
64 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
65 void class_obd_list(void);
66 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
67                                           const char * typ_name,
68                                           struct obd_uuid *grp_uuid);
69 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
70                                              struct obd_uuid *grp_uuid);
71 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
72                                            int *next);
73 struct obd_device * class_num2obd(int num);
74
75 int oig_init(struct obd_io_group **oig);
76 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
77 void oig_complete_one(struct obd_io_group *oig,
78                       struct oig_callback_context *occ, int rc);
79 void oig_release(struct obd_io_group *oig);
80 int oig_wait(struct obd_io_group *oig);
81
82 char *obd_export_nid2str(struct obd_export *exp);
83
84 int obd_export_evict_by_nid(struct obd_device *obd, char *nid);
85 int obd_export_evict_by_uuid(struct obd_device *obd, char *uuid);
86
87 /* obd_config.c */
88 int class_process_config(struct lustre_cfg *lcfg);
89 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, 
90                              struct lustre_cfg *lcfg, void *data);
91 int class_attach(struct lustre_cfg *lcfg);
92 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
93 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
94 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
95 struct obd_device *class_incref(struct obd_device *obd);
96 void class_decref(struct obd_device *obd);
97
98 #define CFG_F_START     0x01   /* Set when we start updating from a log */
99 #define CFG_F_MARKER    0x02   /* We are within a maker */
100 #define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
101 #define CFG_F_COMPAT146 0x08   /* Allow old-style logs */
102 #define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
103 #define CFG_F_SERVER146 0x20   /* Using old server */
104
105 /* Passed as data param to class_config_parse_llog */
106 struct config_llog_instance {
107         char *              cfg_instance;
108         struct super_block *cfg_sb;
109         struct obd_uuid     cfg_uuid;
110         int                 cfg_last_idx; /* for partial llog processing */
111         int                 cfg_flags; 
112 };
113 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
114                             struct config_llog_instance *cfg);
115 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
116                            struct config_llog_instance *cfg);
117
118 /* list of active configuration logs  */
119 struct config_llog_data {
120         char               *cld_logname;
121         struct ldlm_res_id  cld_resid;
122         struct config_llog_instance cld_cfg;
123         struct list_head    cld_list_chain;
124         atomic_t            cld_refcount;
125         struct obd_export  *cld_mgcexp;
126         unsigned int        cld_stopping:1; /* we were told to stop watching */
127         unsigned int        cld_lostlock:1; /* lock not requeued */
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(char * prof);
138 void class_del_profile(char *prof);
139 void class_del_profiles(void);
140
141 #define class_export_rpc_get(exp)                                       \
142 ({                                                                      \
143         atomic_inc(&(exp)->exp_rpc_count);                              \
144         CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",    \
145                (exp), atomic_read(&(exp)->exp_rpc_count));              \
146         class_export_get(exp);                                          \
147 })
148
149 #define class_export_rpc_put(exp)                                       \
150 ({                                                                      \
151         atomic_dec(&(exp)->exp_rpc_count);                              \
152         CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",    \
153                (exp), atomic_read(&(exp)->exp_rpc_count));              \
154         class_export_put(exp);                                          \
155 })
156
157 /* genops.c */
158 #define class_export_get(exp)                                                  \
159 ({                                                                             \
160         struct obd_export *exp_ = exp;                                         \
161         atomic_inc(&exp_->exp_refcount);                                       \
162         CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_,          \
163                atomic_read(&exp_->exp_refcount));                              \
164         exp_;                                                                  \
165 })
166
167 #define class_export_put(exp)                                                  \
168 do {                                                                           \
169         LASSERT((exp) != NULL);                                                \
170         CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp),         \
171                atomic_read(&(exp)->exp_refcount) - 1);                         \
172         LASSERT(atomic_read(&(exp)->exp_refcount) > 0);                        \
173         LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a);                 \
174         __class_export_put(exp);                                               \
175 } while (0)
176
177 void __class_export_put(struct obd_export *);
178 struct obd_export *class_new_export(struct obd_device *obddev,
179                                     struct obd_uuid *cluuid);
180 void class_unlink_export(struct obd_export *exp);
181
182 struct obd_import *class_import_get(struct obd_import *);
183 void class_import_put(struct obd_import *);
184 struct obd_import *class_new_import(struct obd_device *obd);
185 void class_destroy_import(struct obd_import *exp);
186
187 struct obd_type *class_search_type(const char *name);
188 struct obd_type *class_get_type(const char *name);
189 void class_put_type(struct obd_type *type);
190 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
191                   struct obd_uuid *cluuid);
192 int class_disconnect(struct obd_export *exp);
193 void class_fail_export(struct obd_export *exp);
194 void class_disconnect_exports(struct obd_device *obddev);
195 void class_disconnect_stale_exports(struct obd_device *obddev);
196 int class_manual_cleanup(struct obd_device *obd);
197
198 /* obdo.c */
199 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
200 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
201
202
203 #define OBT(dev)        (dev)->obd_type
204 #define OBP(dev, op)    (dev)->obd_type->typ_ops->o_ ## op
205 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
206
207 /* Ensure obd_setup: used for cleanup which must be called
208    while obd is stopping */
209 #define OBD_CHECK_DEV(obd)                                      \
210 do {                                                            \
211         if (!(obd)) {                                           \
212                 CERROR("NULL device\n");                        \
213                 RETURN(-ENODEV);                                \
214         }                                                       \
215 } while (0)
216
217 /* ensure obd_setup and !obd_stopping */
218 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
219 do {                                                            \
220         OBD_CHECK_DEV(obd);                                     \
221         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
222                 CERROR("Device %d not setup\n",                 \
223                        (obd)->obd_minor);                       \
224                 RETURN(-ENODEV);                                \
225         }                                                       \
226 } while (0)
227
228
229 #ifdef LPROCFS
230 #define OBD_COUNTER_OFFSET(op)                                  \
231         ((offsetof(struct obd_ops, o_ ## op) -                  \
232           offsetof(struct obd_ops, o_iocontrol))                \
233          / sizeof(((struct obd_ops *)(0))->o_iocontrol))
234
235 #define OBD_COUNTER_INCREMENT(obdx, op)                           \
236         if ((obdx)->obd_stats != NULL) {                          \
237                 unsigned int coffset;                             \
238                 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
239                         OBD_COUNTER_OFFSET(op);                   \
240                 LASSERT(coffset < (obdx)->obd_stats->ls_num);     \
241                 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
242         }
243
244 #define EXP_COUNTER_INCREMENT(export, op)                                    \
245         if ((export)->exp_obd->obd_stats != NULL) {                          \
246                 unsigned int coffset;                                        \
247                 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
248                         OBD_COUNTER_OFFSET(op);                              \
249                 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num);     \
250                 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
251                 if ((export)->exp_ops_stats != NULL)                         \
252                         lprocfs_counter_incr(                                \
253                                 (export)->exp_ops_stats, coffset);           \
254         }
255
256 #else
257 #define OBD_COUNTER_OFFSET(op)
258 #define OBD_COUNTER_INCREMENT(obd, op)
259 #define EXP_COUNTER_INCREMENT(exp, op);
260 #endif
261
262 #define OBD_CHECK_OP(obd, op, err)                              \
263 do {                                                            \
264         if (!OBT(obd) || !OBP((obd), op)) {\
265                 if (err)                                        \
266                         CERROR("obd_" #op ": dev %d no operation\n",    \
267                                obd->obd_minor);                         \
268                 RETURN(err);                                    \
269         }                                                       \
270 } while (0)
271
272 #define EXP_CHECK_OP(exp, op)                                   \
273 do {                                                            \
274         if ((exp) == NULL) {                                    \
275                 CERROR("obd_" #op ": NULL export\n");           \
276                 RETURN(-ENODEV);                                \
277         }                                                       \
278         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
279                 CERROR("obd_" #op ": cleaned up obd\n");        \
280                 RETURN(-EOPNOTSUPP);                            \
281         }                                                       \
282         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
283                 CERROR("obd_" #op ": dev %d no operation\n",    \
284                        (exp)->exp_obd->obd_minor);              \
285                 RETURN(-EOPNOTSUPP);                            \
286         }                                                       \
287 } while (0)
288
289 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
290 do {                                                            \
291         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
292                 if (err)                                        \
293                         CERROR("lop_" #op ": dev %d no operation\n",    \
294                                ctxt->loc_obd->obd_minor);                         \
295                 RETURN(err);                                    \
296         }                                                       \
297 } while (0)
298
299 static inline int class_devno_max(void)
300 {
301         return MAX_OBD_DEVICES;
302 }
303
304 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
305                                void *key, __u32 *vallen, void *val)
306 {
307         int rc;
308         ENTRY;
309
310         EXP_CHECK_OP(exp, get_info);
311         EXP_COUNTER_INCREMENT(exp, get_info);
312
313         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
314         RETURN(rc);
315 }
316
317 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
318                                      void *key, obd_count vallen, void *val,
319                                      struct ptlrpc_request_set *set)
320 {
321         int rc;
322         ENTRY;
323
324         EXP_CHECK_OP(exp, set_info_async);
325         EXP_COUNTER_INCREMENT(exp, set_info_async);
326
327         rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val, 
328                                                set);
329         RETURN(rc);
330 }
331
332 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
333 {
334         int rc;
335         ENTRY;
336
337         OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
338         OBD_COUNTER_INCREMENT(obd, setup);
339
340         rc = OBP(obd, setup)(obd, datalen, data);
341         RETURN(rc);
342 }
343
344 static inline int obd_precleanup(struct obd_device *obd, 
345                                  enum obd_cleanup_stage cleanup_stage)
346 {
347         int rc;
348         ENTRY;
349
350         OBD_CHECK_OP(obd, precleanup, 0);
351         OBD_COUNTER_INCREMENT(obd, precleanup);
352
353         rc = OBP(obd, precleanup)(obd, cleanup_stage);
354         RETURN(rc);
355 }
356
357 static inline int obd_cleanup(struct obd_device *obd)
358 {
359         int rc;
360         ENTRY;
361
362         OBD_CHECK_DEV(obd);
363         OBD_CHECK_OP(obd, cleanup, 0);
364         OBD_COUNTER_INCREMENT(obd, cleanup);
365
366         rc = OBP(obd, cleanup)(obd);
367         RETURN(rc);
368 }
369
370 static inline int
371 obd_process_config(struct obd_device *obd, int datalen, void *data)
372 {
373         int rc;
374         ENTRY;
375
376         OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
377         OBD_COUNTER_INCREMENT(obd, process_config);
378
379         rc = OBP(obd, process_config)(obd, datalen, data);
380         RETURN(rc);
381 }
382
383 /* Pack an in-memory MD struct for storage on disk.
384  * Returns +ve size of packed MD (0 for free), or -ve error.
385  *
386  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
387  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
388  * If @*disk_tgt == NULL, it will be allocated
389  */
390 static inline int obd_packmd(struct obd_export *exp,
391                              struct lov_mds_md **disk_tgt,
392                              struct lov_stripe_md *mem_src)
393 {
394         int rc;
395         ENTRY;
396
397         EXP_CHECK_OP(exp, packmd);
398         EXP_COUNTER_INCREMENT(exp, packmd);
399
400         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
401         RETURN(rc);
402 }
403
404 static inline int obd_size_diskmd(struct obd_export *exp,
405                                   struct lov_stripe_md *mem_src)
406 {
407         return obd_packmd(exp, NULL, mem_src);
408 }
409
410 /* helper functions */
411 static inline int obd_alloc_diskmd(struct obd_export *exp,
412                                    struct lov_mds_md **disk_tgt)
413 {
414         LASSERT(disk_tgt);
415         LASSERT(*disk_tgt == NULL);
416         return obd_packmd(exp, disk_tgt, NULL);
417 }
418
419 static inline int obd_free_diskmd(struct obd_export *exp,
420                                   struct lov_mds_md **disk_tgt)
421 {
422         LASSERT(disk_tgt);
423         LASSERT(*disk_tgt);
424         return obd_packmd(exp, disk_tgt, NULL);
425 }
426
427 /* Unpack an MD struct from disk to in-memory format.
428  * Returns +ve size of unpacked MD (0 for free), or -ve error.
429  *
430  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
431  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
432  * If @*mem_tgt == NULL, it will be allocated
433  */
434 static inline int obd_unpackmd(struct obd_export *exp,
435                                struct lov_stripe_md **mem_tgt,
436                                struct lov_mds_md *disk_src,
437                                int disk_len)
438 {
439         int rc;
440         ENTRY;
441
442         EXP_CHECK_OP(exp, unpackmd);
443         EXP_COUNTER_INCREMENT(exp, unpackmd);
444
445         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
446         RETURN(rc);
447 }
448
449 /* helper functions */
450 static inline int obd_alloc_memmd(struct obd_export *exp,
451                                   struct lov_stripe_md **mem_tgt)
452 {
453         LASSERT(mem_tgt);
454         LASSERT(*mem_tgt == NULL);
455         return obd_unpackmd(exp, mem_tgt, NULL, 0);
456 }
457
458 static inline int obd_free_memmd(struct obd_export *exp,
459                                  struct lov_stripe_md **mem_tgt)
460 {
461         LASSERT(mem_tgt);
462         LASSERT(*mem_tgt);
463         return obd_unpackmd(exp, mem_tgt, NULL, 0);
464 }
465
466 static inline int obd_checkmd(struct obd_export *exp,
467                               struct obd_export *md_exp,
468                               struct lov_stripe_md *mem_tgt)
469 {
470         int rc;
471         ENTRY;
472
473         EXP_CHECK_OP(exp, checkmd);
474         EXP_COUNTER_INCREMENT(exp, checkmd);
475
476         rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
477         RETURN(rc);
478 }
479
480 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
481                              struct lov_stripe_md **ea,
482                              struct obd_trans_info *oti)
483 {
484         int rc;
485         ENTRY;
486
487         EXP_CHECK_OP(exp, create);
488         EXP_COUNTER_INCREMENT(exp, create);
489
490         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
491         RETURN(rc);
492 }
493
494 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
495                               struct lov_stripe_md *ea,
496                               struct obd_trans_info *oti,
497                               struct obd_export *md_exp)
498 {
499         int rc;
500         ENTRY;
501
502         EXP_CHECK_OP(exp, destroy);
503         EXP_COUNTER_INCREMENT(exp, destroy);
504
505         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
506         RETURN(rc);
507 }
508
509 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
510 {
511         int rc;
512         ENTRY;
513
514         EXP_CHECK_OP(exp, getattr);
515         EXP_COUNTER_INCREMENT(exp, getattr);
516
517         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
518         RETURN(rc);
519 }
520
521 static inline int obd_getattr_async(struct obd_export *exp,
522                                     struct obd_info *oinfo,
523                                     struct ptlrpc_request_set *set)
524 {
525         int rc;
526         ENTRY;
527
528         EXP_CHECK_OP(exp, getattr_async);
529         EXP_COUNTER_INCREMENT(exp, getattr_async);
530
531         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
532         RETURN(rc);
533 }
534
535 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
536                               struct obd_trans_info *oti)
537 {
538         int rc;
539         ENTRY;
540
541         EXP_CHECK_OP(exp, setattr);
542         EXP_COUNTER_INCREMENT(exp, setattr);
543
544         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
545         RETURN(rc);
546 }
547
548 /* This performs all the requests set init/wait/destroy actions. */
549 static inline int obd_setattr_rqset(struct obd_export *exp,
550                                     struct obd_info *oinfo,
551                                     struct obd_trans_info *oti)
552 {
553         struct ptlrpc_request_set *set = NULL;
554         int rc;
555         ENTRY;
556
557         EXP_CHECK_OP(exp, setattr_async);
558         EXP_COUNTER_INCREMENT(exp, setattr_async);
559
560         set =  ptlrpc_prep_set();
561         if (set == NULL)
562                 RETURN(-ENOMEM);
563
564         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
565         if (rc == 0)
566                 rc = ptlrpc_set_wait(set);
567         ptlrpc_set_destroy(set);
568         RETURN(rc);
569 }
570
571 /* This adds all the requests into @set if @set != NULL, otherwise
572    all requests are sent asynchronously without waiting for response. */
573 static inline int obd_setattr_async(struct obd_export *exp,
574                                     struct obd_info *oinfo,
575                                     struct obd_trans_info *oti,
576                                     struct ptlrpc_request_set *set)
577 {
578         int rc;
579         ENTRY;
580
581         EXP_CHECK_OP(exp, setattr_async);
582         EXP_COUNTER_INCREMENT(exp, setattr_async);
583
584         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
585         RETURN(rc);
586 }
587
588 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
589                                int priority)
590 {
591         struct obd_device *obd = imp->imp_obd;
592         int rc;
593         ENTRY;
594
595         OBD_CHECK_DEV_ACTIVE(obd);
596         OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
597         OBD_COUNTER_INCREMENT(obd, add_conn);
598
599         rc = OBP(obd, add_conn)(imp, uuid, priority);
600         RETURN(rc);
601 }
602
603 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
604 {
605         struct obd_device *obd = imp->imp_obd;
606         int rc;
607         ENTRY;
608
609         OBD_CHECK_DEV_ACTIVE(obd);
610         OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
611         OBD_COUNTER_INCREMENT(obd, del_conn);
612
613         rc = OBP(obd, del_conn)(imp, uuid);
614         RETURN(rc);
615 }
616
617 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
618                               struct obd_uuid *cluuid,
619                               struct obd_connect_data *d)
620 {
621         int rc;
622         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
623         ENTRY;
624
625         OBD_CHECK_DEV_ACTIVE(obd);
626         OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
627         OBD_COUNTER_INCREMENT(obd, connect);
628
629         rc = OBP(obd, connect)(conn, obd, cluuid, d);
630         /* check that only subset is granted */
631         LASSERT(ergo(d != NULL,
632                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
633         RETURN(rc);
634 }
635
636 static inline int obd_reconnect(struct obd_export *exp,
637                                 struct obd_device *obd,
638                                 struct obd_uuid *cluuid,
639                                 struct obd_connect_data *d)
640 {
641         int rc;
642         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
643         ENTRY;
644
645         OBD_CHECK_DEV_ACTIVE(obd);
646         OBD_CHECK_OP(obd, reconnect, 0);
647         OBD_COUNTER_INCREMENT(obd, reconnect);
648
649         rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
650         /* check that only subset is granted */
651         LASSERT(ergo(d != NULL,
652                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
653         RETURN(rc);
654 }
655
656 static inline int obd_disconnect(struct obd_export *exp)
657 {
658         int rc;
659         ENTRY;
660
661         EXP_CHECK_OP(exp, disconnect);
662         EXP_COUNTER_INCREMENT(exp, disconnect);
663
664         rc = OBP(exp->exp_obd, disconnect)(exp);
665         RETURN(rc);
666 }
667
668 static inline int obd_ping(struct obd_export *exp)
669 {
670         int rc;
671         ENTRY;
672
673         OBD_CHECK_OP(exp->exp_obd, ping, 0);
674         EXP_COUNTER_INCREMENT(exp, ping);
675
676         rc = OBP(exp->exp_obd, ping)(exp);
677         RETURN(rc);
678 }
679
680 static inline int obd_init_export(struct obd_export *exp)
681 {
682         int rc = 0;
683
684         ENTRY;
685         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
686             OBP((exp)->exp_obd, init_export))
687                 rc = OBP(exp->exp_obd, init_export)(exp);
688         RETURN(rc);
689 }
690
691 static inline int obd_destroy_export(struct obd_export *exp)
692 {
693         ENTRY;
694         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
695             OBP((exp)->exp_obd, destroy_export))
696                 OBP(exp->exp_obd, destroy_export)(exp);
697         RETURN(0);
698 }
699
700 static inline int obd_extent_calc(struct obd_export *exp,
701                                   struct lov_stripe_md *md,
702                                   int cmd, obd_off *offset)
703 {
704         int rc;
705         ENTRY;
706         EXP_CHECK_OP(exp, extent_calc);
707         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
708         RETURN(rc);
709 }
710
711 static inline struct dentry *
712 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
713 {
714         LASSERT(exp->exp_obd);
715
716         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
717                                exp->exp_obd);
718 }
719
720 #ifndef time_before
721 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
722 #endif
723
724 /* @max_age is the oldest time in jiffies that we accept using a cached data.
725  * If the cache is older than @max_age we will get a new value from the
726  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
727 static inline int obd_statfs_async(struct obd_device *obd,
728                                    struct obd_info *oinfo,
729                                    __u64 max_age,
730                                    struct ptlrpc_request_set *rqset)
731 {
732         int rc = 0;
733         ENTRY;
734
735         if (obd == NULL)
736                 RETURN(-EINVAL);
737
738         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
739         OBD_COUNTER_INCREMENT(obd, statfs);
740
741         CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
742                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
743         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
744                 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
745         } else {
746                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
747                        " objects "LPU64"/"LPU64"\n",
748                        obd->obd_name, &obd->obd_osfs,
749                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
750                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
751                 spin_lock(&obd->obd_osfs_lock);
752                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
753                 spin_unlock(&obd->obd_osfs_lock);
754                 if (oinfo->oi_cb_up)
755                         oinfo->oi_cb_up(oinfo, 0);
756         }
757         RETURN(rc);
758 }
759
760 static inline int obd_statfs_rqset(struct obd_device *obd,
761                                    struct obd_statfs *osfs, __u64 max_age)
762 {
763         struct ptlrpc_request_set *set = NULL;
764         struct obd_info oinfo = { { { 0 } } };
765         int rc = 0;
766         ENTRY;
767
768         set = ptlrpc_prep_set();
769         if (set == NULL)
770                 RETURN(-ENOMEM);
771
772         oinfo.oi_osfs = osfs;
773         rc = obd_statfs_async(obd, &oinfo, max_age, set);
774         if (rc == 0)
775                 rc = ptlrpc_set_wait(set);
776         ptlrpc_set_destroy(set);
777         RETURN(rc);
778 }
779
780 /* @max_age is the oldest time in jiffies that we accept using a cached data.
781  * If the cache is older than @max_age we will get a new value from the
782  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
783 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
784                              __u64 max_age)
785 {
786         int rc = 0;
787         ENTRY;
788
789         if (obd == NULL)
790                 RETURN(-EINVAL);
791
792         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
793         OBD_COUNTER_INCREMENT(obd, statfs);
794
795         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
796                obd->obd_osfs_age, max_age);
797         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
798                 rc = OBP(obd, statfs)(obd, osfs, max_age);
799                 if (rc == 0) {
800                         spin_lock(&obd->obd_osfs_lock);
801                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
802                         obd->obd_osfs_age = cfs_time_current_64();
803                         spin_unlock(&obd->obd_osfs_lock);
804                 }
805         } else {
806                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
807                        " objects "LPU64"/"LPU64"\n",
808                        obd->obd_name, &obd->obd_osfs,
809                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
810                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
811                 spin_lock(&obd->obd_osfs_lock);
812                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
813                 spin_unlock(&obd->obd_osfs_lock);
814         }
815         RETURN(rc);
816 }
817
818 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
819                            struct lov_stripe_md *ea, obd_size start,
820                            obd_size end)
821 {
822         int rc;
823         ENTRY;
824
825         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
826         EXP_COUNTER_INCREMENT(exp, sync);
827
828         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
829         RETURN(rc);
830 }
831
832 static inline int obd_punch_rqset(struct obd_export *exp,
833                                   struct obd_info *oinfo,
834                                   struct obd_trans_info *oti)
835 {
836         struct ptlrpc_request_set *set = NULL;
837         int rc;
838         ENTRY;
839
840         EXP_CHECK_OP(exp, punch);
841         EXP_COUNTER_INCREMENT(exp, punch);
842
843         set =  ptlrpc_prep_set();
844         if (set == NULL)
845                 RETURN(-ENOMEM);
846
847         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
848         if (rc == 0)
849                 rc = ptlrpc_set_wait(set);
850         ptlrpc_set_destroy(set);
851         RETURN(rc);
852 }
853
854 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
855                             struct obd_trans_info *oti,
856                             struct ptlrpc_request_set *rqset)
857 {
858         int rc;
859         ENTRY;
860
861         EXP_CHECK_OP(exp, punch);
862         EXP_COUNTER_INCREMENT(exp, punch);
863
864         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
865         RETURN(rc);
866 }
867
868 static inline int obd_brw(int cmd, struct obd_export *exp,
869                           struct obd_info *oinfo, obd_count oa_bufs,
870                           struct brw_page *pg, struct obd_trans_info *oti)
871 {
872         int rc;
873         ENTRY;
874
875         EXP_CHECK_OP(exp, brw);
876         EXP_COUNTER_INCREMENT(exp, brw);
877
878         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
879                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
880                        "or OBD_BRW_CHECK\n");
881                 LBUG();
882         }
883
884         rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
885         RETURN(rc);
886 }
887
888 static inline int obd_brw_async(int cmd, struct obd_export *exp,
889                                 struct obd_info *oinfo, obd_count oa_bufs,
890                                 struct brw_page *pg, struct obd_trans_info *oti,
891                                 struct ptlrpc_request_set *set)
892 {
893         int rc;
894         ENTRY;
895
896         EXP_CHECK_OP(exp, brw_async);
897         EXP_COUNTER_INCREMENT(exp, brw_async);
898
899         if (!(cmd & OBD_BRW_RWMASK)) {
900                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
901                 LBUG();
902         }
903
904         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
905         RETURN(rc);
906 }
907
908 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
909                                 struct obdo *oa, struct lov_stripe_md *lsm,
910                                 obd_count oa_bufs, struct brw_page *pg,
911                                 struct obd_trans_info *oti)
912 {
913         struct ptlrpc_request_set *set = NULL;
914         struct obd_info oinfo = { { { 0 } } };
915         int rc = 0;
916         ENTRY;
917
918         set =  ptlrpc_prep_set();
919         if (set == NULL)
920                 RETURN(-ENOMEM);
921
922         oinfo.oi_oa = oa;
923         oinfo.oi_md = lsm;
924         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
925         if (rc == 0) {
926                 rc = ptlrpc_set_wait(set);
927                 if (rc)
928                         CERROR("error from callback: rc = %d\n", rc);
929         } else {
930                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
931                        "error from obd_brw_async: rc = %d\n", rc);
932         }
933         ptlrpc_set_destroy(set);
934         RETURN(rc);
935 }
936
937 static inline  int obd_prep_async_page(struct obd_export *exp,
938                                        struct lov_stripe_md *lsm,
939                                        struct lov_oinfo *loi,
940                                        cfs_page_t *page, obd_off offset,
941                                        struct obd_async_page_ops *ops,
942                                        void *data, void **res)
943 {
944         int ret;
945         ENTRY;
946
947         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
948         EXP_COUNTER_INCREMENT(exp, prep_async_page);
949
950         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
951                                                  ops, data, res);
952         RETURN(ret);
953 }
954
955 static inline int obd_queue_async_io(struct obd_export *exp,
956                                      struct lov_stripe_md *lsm,
957                                      struct lov_oinfo *loi, void *cookie,
958                                      int cmd, obd_off off, int count,
959                                      obd_flag brw_flags, obd_flag async_flags)
960 {
961         int rc;
962         ENTRY;
963
964         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
965         EXP_COUNTER_INCREMENT(exp, queue_async_io);
966         LASSERT(cmd & OBD_BRW_RWMASK);
967
968         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
969                                                count, brw_flags, async_flags);
970         RETURN(rc);
971 }
972
973 static inline int obd_set_async_flags(struct obd_export *exp,
974                                       struct lov_stripe_md *lsm,
975                                       struct lov_oinfo *loi, void *cookie,
976                                       obd_flag async_flags)
977 {
978         int rc;
979         ENTRY;
980
981         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
982         EXP_COUNTER_INCREMENT(exp, set_async_flags);
983
984         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
985                                                 async_flags);
986         RETURN(rc);
987 }
988
989 static inline int obd_queue_group_io(struct obd_export *exp,
990                                      struct lov_stripe_md *lsm,
991                                      struct lov_oinfo *loi,
992                                      struct obd_io_group *oig,
993                                      void *cookie, int cmd, obd_off off,
994                                      int count, obd_flag brw_flags,
995                                      obd_flag async_flags)
996 {
997         int rc;
998         ENTRY;
999
1000         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1001         EXP_COUNTER_INCREMENT(exp, queue_group_io);
1002         LASSERT(cmd & OBD_BRW_RWMASK);
1003
1004         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1005                                                cmd, off, count, brw_flags,
1006                                                async_flags);
1007         RETURN(rc);
1008 }
1009
1010 static inline int obd_trigger_group_io(struct obd_export *exp,
1011                                        struct lov_stripe_md *lsm,
1012                                        struct lov_oinfo *loi,
1013                                        struct obd_io_group *oig)
1014 {
1015         int rc;
1016         ENTRY;
1017
1018         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1019         EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1020
1021         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1022         RETURN(rc);
1023 }
1024
1025 static inline int obd_teardown_async_page(struct obd_export *exp,
1026                                           struct lov_stripe_md *lsm,
1027                                           struct lov_oinfo *loi, void *cookie)
1028 {
1029         int rc;
1030         ENTRY;
1031
1032         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1033         EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1034
1035         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1036         RETURN(rc);
1037 }
1038
1039 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1040                              int objcount, struct obd_ioobj *obj,
1041                              int niocount, struct niobuf_remote *remote,
1042                              struct niobuf_local *local,
1043                              struct obd_trans_info *oti)
1044 {
1045         int rc;
1046         ENTRY;
1047
1048         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1049         EXP_COUNTER_INCREMENT(exp, preprw);
1050
1051         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1052                                        remote, local, oti);
1053         RETURN(rc);
1054 }
1055
1056 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1057                                int objcount, struct obd_ioobj *obj,
1058                                int niocount, struct niobuf_local *local,
1059                                struct obd_trans_info *oti, int rc)
1060 {
1061         ENTRY;
1062
1063         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1064         EXP_COUNTER_INCREMENT(exp, commitrw);
1065
1066         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1067                                          local, oti, rc);
1068         RETURN(rc);
1069 }
1070
1071 static inline int obd_merge_lvb(struct obd_export *exp,
1072                                 struct lov_stripe_md *lsm,
1073                                 struct ost_lvb *lvb, int kms_only)
1074 {
1075         int rc;
1076         ENTRY;
1077
1078         OBD_CHECK_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1079         EXP_COUNTER_INCREMENT(exp, merge_lvb);
1080
1081         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1082         RETURN(rc);
1083 }
1084
1085 static inline int obd_adjust_kms(struct obd_export *exp,
1086                                  struct lov_stripe_md *lsm, obd_off size,
1087                                  int shrink)
1088 {
1089         int rc;
1090         ENTRY;
1091
1092         OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1093         EXP_COUNTER_INCREMENT(exp, adjust_kms);
1094
1095         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1096         RETURN(rc);
1097 }
1098
1099 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1100                                 int len, void *karg, void *uarg)
1101 {
1102         int rc;
1103         ENTRY;
1104
1105         EXP_CHECK_OP(exp, iocontrol);
1106         EXP_COUNTER_INCREMENT(exp, iocontrol);
1107
1108         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1109         RETURN(rc);
1110 }
1111
1112 static inline int obd_enqueue_rqset(struct obd_export *exp,
1113                                     struct obd_info *oinfo,
1114                                     struct obd_enqueue_info *einfo)
1115 {
1116         int rc;
1117         ENTRY;
1118
1119         EXP_CHECK_OP(exp, enqueue);
1120         EXP_COUNTER_INCREMENT(exp, enqueue);
1121
1122         einfo->ei_rqset =  ptlrpc_prep_set();
1123         if (einfo->ei_rqset == NULL)
1124                 RETURN(-ENOMEM);
1125
1126         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1127         if (rc == 0)
1128                 rc = ptlrpc_set_wait(einfo->ei_rqset);
1129         ptlrpc_set_destroy(einfo->ei_rqset);
1130         einfo->ei_rqset = NULL;
1131
1132         RETURN(rc);
1133 }
1134
1135 static inline int obd_enqueue(struct obd_export *exp,
1136                               struct obd_info *oinfo,
1137                               struct obd_enqueue_info *einfo)
1138 {
1139         int rc;
1140         ENTRY;
1141
1142         EXP_CHECK_OP(exp, enqueue);
1143         EXP_COUNTER_INCREMENT(exp, enqueue);
1144
1145         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo);
1146         RETURN(rc);
1147 }
1148
1149 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1150                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1151                             int *flags, void *data, struct lustre_handle *lockh)
1152 {
1153         int rc;
1154         ENTRY;
1155
1156         EXP_CHECK_OP(exp, match);
1157         EXP_COUNTER_INCREMENT(exp, match);
1158
1159         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1160                                       lockh);
1161         RETURN(rc);
1162 }
1163
1164 static inline int obd_change_cbdata(struct obd_export *exp,
1165                                     struct lov_stripe_md *lsm,
1166                                     ldlm_iterator_t it, void *data)
1167 {
1168         int rc;
1169         ENTRY;
1170
1171         EXP_CHECK_OP(exp, change_cbdata);
1172         EXP_COUNTER_INCREMENT(exp, change_cbdata);
1173
1174         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1175         RETURN(rc);
1176 }
1177
1178 static inline int obd_cancel(struct obd_export *exp,
1179                              struct lov_stripe_md *ea, __u32 mode,
1180                              struct lustre_handle *lockh)
1181 {
1182         int rc;
1183         ENTRY;
1184
1185         EXP_CHECK_OP(exp, cancel);
1186         EXP_COUNTER_INCREMENT(exp, cancel);
1187
1188         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1189         RETURN(rc);
1190 }
1191
1192 static inline int obd_cancel_unused(struct obd_export *exp,
1193                                     struct lov_stripe_md *ea, int flags,
1194                                     void *opaque)
1195 {
1196         int rc;
1197         ENTRY;
1198
1199         EXP_CHECK_OP(exp, cancel_unused);
1200         EXP_COUNTER_INCREMENT(exp, cancel_unused);
1201
1202         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1203         RETURN(rc);
1204 }
1205
1206 static inline int obd_join_lru(struct obd_export *exp,
1207                                struct lov_stripe_md *ea, int join)
1208 {
1209         int rc;
1210         ENTRY;
1211
1212         EXP_CHECK_OP(exp, join_lru);
1213         EXP_COUNTER_INCREMENT(exp, join_lru);
1214
1215         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1216         RETURN(rc);
1217 }
1218
1219 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1220                           int type, struct obd_client_handle *handle, int flag)
1221 {
1222         int rc;
1223         ENTRY;
1224
1225         EXP_CHECK_OP(exp, pin);
1226         EXP_COUNTER_INCREMENT(exp, pin);
1227
1228         rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1229         RETURN(rc);
1230 }
1231
1232 static inline int obd_unpin(struct obd_export *exp,
1233                             struct obd_client_handle *handle, int flag)
1234 {
1235         int rc;
1236         ENTRY;
1237
1238         EXP_CHECK_OP(exp, unpin);
1239         EXP_COUNTER_INCREMENT(exp, unpin);
1240
1241         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1242         RETURN(rc);
1243 }
1244
1245
1246 static inline void obd_import_event(struct obd_device *obd,
1247                                     struct obd_import *imp,
1248                                     enum obd_import_event event)
1249 {
1250         ENTRY;
1251         if (!obd) {
1252                 CERROR("NULL device\n");
1253                 EXIT;
1254                 return;
1255         }
1256         if (obd->obd_set_up && OBP(obd, import_event)) {
1257                 OBD_COUNTER_INCREMENT(obd, import_event);
1258                 OBP(obd, import_event)(obd, imp, event);
1259         }
1260         EXIT;
1261 }
1262
1263 static inline int obd_notify(struct obd_device *obd,
1264                              struct obd_device *watched,
1265                              enum obd_notify_event ev, void *data)
1266 {
1267         ENTRY;
1268         OBD_CHECK_DEV(obd);
1269
1270         /* the check for async_recov is a complete hack - I'm hereby
1271            overloading the meaning to also mean "this was called from
1272            mds_postsetup".  I know that my mds is able to handle notifies
1273            by this point, and it needs to get them to execute mds_postrecov. */                                                                                
1274         if (!obd->obd_set_up && !obd->obd_async_recov) {
1275                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1276                 RETURN(-EINVAL);
1277         }
1278
1279         if (!OBP(obd, notify)) 
1280                 RETURN(-ENOSYS);
1281
1282         OBD_COUNTER_INCREMENT(obd, notify);
1283         RETURN(OBP(obd, notify)(obd, watched, ev, data));
1284 }
1285
1286 static inline int obd_notify_observer(struct obd_device *observer,
1287                                       struct obd_device *observed,
1288                                       enum obd_notify_event ev, void *data)
1289 {
1290         int rc1;
1291         int rc2;
1292
1293         struct obd_notify_upcall *onu;
1294
1295         if (observer->obd_observer)
1296                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1297         else
1298                 rc1 = 0;
1299         /*
1300          * Also, call non-obd listener, if any
1301          */
1302         onu = &observer->obd_upcall;
1303         if (onu->onu_upcall != NULL)
1304                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1305         else
1306                 rc2 = 0;
1307
1308         return rc1 ?: rc2;
1309  }
1310
1311 static inline int obd_quotacheck(struct obd_export *exp,
1312                                  struct obd_quotactl *oqctl)
1313 {
1314         int rc;
1315         ENTRY;
1316
1317         EXP_CHECK_OP(exp, quotacheck);
1318         EXP_COUNTER_INCREMENT(exp, quotacheck);
1319
1320         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1321         RETURN(rc);
1322 }
1323
1324 static inline int obd_quotactl(struct obd_export *exp,
1325                                struct obd_quotactl *oqctl)
1326 {
1327         int rc;
1328         ENTRY;
1329
1330         EXP_CHECK_OP(exp, quotactl);
1331         EXP_COUNTER_INCREMENT(exp, quotactl);
1332
1333         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1334         RETURN(rc);
1335 }
1336
1337 static inline int obd_health_check(struct obd_device *obd)
1338 {
1339         /* returns: 0 on healthy
1340          *         >0 on unhealthy + reason code/flag
1341          *            however the only suppored reason == 1 right now
1342          *            We'll need to define some better reasons
1343          *            or flags in the future.
1344          *         <0 on error
1345          */
1346         int rc;
1347         ENTRY;
1348
1349         /* don't use EXP_CHECK_OP, because NULL method is normal here */
1350         if (obd == NULL || !OBT(obd)) {
1351                 CERROR("cleaned up obd\n");
1352                 RETURN(-EOPNOTSUPP);
1353         }
1354         if (!obd->obd_set_up || obd->obd_stopping)
1355                 RETURN(0);
1356         if (!OBP(obd, health_check))
1357                 RETURN(0);
1358
1359         rc = OBP(obd, health_check)(obd);
1360         RETURN(rc);
1361 }
1362
1363 static inline int obd_register_observer(struct obd_device *obd,
1364                                         struct obd_device *observer)
1365 {
1366         ENTRY;
1367         OBD_CHECK_DEV(obd);
1368         if (obd->obd_observer && observer)
1369                 RETURN(-EALREADY);
1370         obd->obd_observer = observer;
1371         RETURN(0);
1372 }
1373
1374 /* OBD Metadata Support */
1375
1376 extern int obd_init_caches(void);
1377 extern void obd_cleanup_caches(void);
1378
1379 /* support routines */
1380 extern cfs_mem_cache_t *obdo_cachep;
1381 static inline struct obdo *obdo_alloc(void)
1382 {
1383         struct obdo *oa;
1384
1385         OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1386
1387         return oa;
1388 }
1389
1390 static inline void obdo_free(struct obdo *oa)
1391 {
1392         OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1393 }
1394
1395 /* I'm as embarrassed about this as you are.
1396  *
1397  * <shaver> // XXX do not look into _superhack with remaining eye
1398  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1399 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1400
1401 /* sysctl.c */
1402 extern void obd_sysctl_init (void);
1403 extern void obd_sysctl_clean (void);
1404
1405 /* uuid.c  */
1406 typedef __u8 class_uuid_t[16];
1407 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1408
1409 /* lustre_peer.c    */
1410 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index);
1411 int class_add_uuid(char *uuid, __u64 nid);
1412 int class_del_uuid (char *uuid);
1413 void class_init_uuidlist(void);
1414 void class_exit_uuidlist(void);
1415
1416 #endif /* __LINUX_OBD_CLASS_H */