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