Whamcloud - gitweb
Land b1_6_elc onto b1_6 (20070621_0218)
[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_create(struct obd_export *exp, struct obdo *obdo,
480                              struct lov_stripe_md **ea,
481                              struct obd_trans_info *oti)
482 {
483         int rc;
484         ENTRY;
485
486         EXP_CHECK_OP(exp, create);
487         EXP_COUNTER_INCREMENT(exp, create);
488
489         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
490         RETURN(rc);
491 }
492
493 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
494                               struct lov_stripe_md *ea,
495                               struct obd_trans_info *oti,
496                               struct obd_export *md_exp)
497 {
498         int rc;
499         ENTRY;
500
501         EXP_CHECK_OP(exp, destroy);
502         EXP_COUNTER_INCREMENT(exp, destroy);
503
504         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
505         RETURN(rc);
506 }
507
508 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
509 {
510         int rc;
511         ENTRY;
512
513         EXP_CHECK_OP(exp, getattr);
514         EXP_COUNTER_INCREMENT(exp, getattr);
515
516         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
517         RETURN(rc);
518 }
519
520 static inline int obd_getattr_async(struct obd_export *exp,
521                                     struct obd_info *oinfo,
522                                     struct ptlrpc_request_set *set)
523 {
524         int rc;
525         ENTRY;
526
527         EXP_CHECK_OP(exp, getattr_async);
528         EXP_COUNTER_INCREMENT(exp, getattr_async);
529
530         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
531         RETURN(rc);
532 }
533
534 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
535                               struct obd_trans_info *oti)
536 {
537         int rc;
538         ENTRY;
539
540         EXP_CHECK_OP(exp, setattr);
541         EXP_COUNTER_INCREMENT(exp, setattr);
542
543         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
544         RETURN(rc);
545 }
546
547 /* This performs all the requests set init/wait/destroy actions. */
548 static inline int obd_setattr_rqset(struct obd_export *exp,
549                                     struct obd_info *oinfo,
550                                     struct obd_trans_info *oti)
551 {
552         struct ptlrpc_request_set *set = NULL;
553         int rc;
554         ENTRY;
555
556         EXP_CHECK_OP(exp, setattr_async);
557         EXP_COUNTER_INCREMENT(exp, setattr_async);
558
559         set =  ptlrpc_prep_set();
560         if (set == NULL)
561                 RETURN(-ENOMEM);
562
563         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
564         if (rc == 0)
565                 rc = ptlrpc_set_wait(set);
566         ptlrpc_set_destroy(set);
567         RETURN(rc);
568 }
569
570 /* This adds all the requests into @set if @set != NULL, otherwise
571    all requests are sent asynchronously without waiting for response. */
572 static inline int obd_setattr_async(struct obd_export *exp,
573                                     struct obd_info *oinfo,
574                                     struct obd_trans_info *oti,
575                                     struct ptlrpc_request_set *set)
576 {
577         int rc;
578         ENTRY;
579
580         EXP_CHECK_OP(exp, setattr_async);
581         EXP_COUNTER_INCREMENT(exp, setattr_async);
582
583         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
584         RETURN(rc);
585 }
586
587 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
588                                int priority)
589 {
590         struct obd_device *obd = imp->imp_obd;
591         int rc;
592         ENTRY;
593
594         OBD_CHECK_DEV_ACTIVE(obd);
595         OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
596         OBD_COUNTER_INCREMENT(obd, add_conn);
597
598         rc = OBP(obd, add_conn)(imp, uuid, priority);
599         RETURN(rc);
600 }
601
602 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
603 {
604         struct obd_device *obd = imp->imp_obd;
605         int rc;
606         ENTRY;
607
608         OBD_CHECK_DEV_ACTIVE(obd);
609         OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
610         OBD_COUNTER_INCREMENT(obd, del_conn);
611
612         rc = OBP(obd, del_conn)(imp, uuid);
613         RETURN(rc);
614 }
615
616 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
617                               struct obd_uuid *cluuid,
618                               struct obd_connect_data *d)
619 {
620         int rc;
621         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
622         ENTRY;
623
624         OBD_CHECK_DEV_ACTIVE(obd);
625         OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
626         OBD_COUNTER_INCREMENT(obd, connect);
627
628         rc = OBP(obd, connect)(conn, obd, cluuid, d);
629         /* check that only subset is granted */
630         LASSERT(ergo(d != NULL,
631                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
632         RETURN(rc);
633 }
634
635 static inline int obd_reconnect(struct obd_export *exp,
636                                 struct obd_device *obd,
637                                 struct obd_uuid *cluuid,
638                                 struct obd_connect_data *d)
639 {
640         int rc;
641         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
642         ENTRY;
643
644         OBD_CHECK_DEV_ACTIVE(obd);
645         OBD_CHECK_OP(obd, reconnect, 0);
646         OBD_COUNTER_INCREMENT(obd, reconnect);
647
648         rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
649         /* check that only subset is granted */
650         LASSERT(ergo(d != NULL,
651                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
652         RETURN(rc);
653 }
654
655 static inline int obd_disconnect(struct obd_export *exp)
656 {
657         int rc;
658         ENTRY;
659
660         EXP_CHECK_OP(exp, disconnect);
661         EXP_COUNTER_INCREMENT(exp, disconnect);
662
663         rc = OBP(exp->exp_obd, disconnect)(exp);
664         RETURN(rc);
665 }
666
667 static inline int obd_ping(struct obd_export *exp)
668 {
669         int rc;
670         ENTRY;
671
672         OBD_CHECK_OP(exp->exp_obd, ping, 0);
673         EXP_COUNTER_INCREMENT(exp, ping);
674
675         rc = OBP(exp->exp_obd, ping)(exp);
676         RETURN(rc);
677 }
678
679 static inline int obd_init_export(struct obd_export *exp)
680 {
681         int rc = 0;
682
683         ENTRY;
684         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
685             OBP((exp)->exp_obd, init_export))
686                 rc = OBP(exp->exp_obd, init_export)(exp);
687         RETURN(rc);
688 }
689
690 static inline int obd_destroy_export(struct obd_export *exp)
691 {
692         ENTRY;
693         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
694             OBP((exp)->exp_obd, destroy_export))
695                 OBP(exp->exp_obd, destroy_export)(exp);
696         RETURN(0);
697 }
698
699 static inline int obd_extent_calc(struct obd_export *exp,
700                                   struct lov_stripe_md *md,
701                                   int cmd, obd_off *offset)
702 {
703         int rc;
704         ENTRY;
705         EXP_CHECK_OP(exp, extent_calc);
706         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
707         RETURN(rc);
708 }
709
710 static inline struct dentry *
711 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
712 {
713         LASSERT(exp->exp_obd);
714
715         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
716                                exp->exp_obd);
717 }
718
719 #ifndef time_before
720 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
721 #endif
722
723 /* @max_age is the oldest time in jiffies that we accept using a cached data.
724  * If the cache is older than @max_age we will get a new value from the
725  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
726 static inline int obd_statfs_async(struct obd_device *obd,
727                                    struct obd_info *oinfo,
728                                    __u64 max_age,
729                                    struct ptlrpc_request_set *rqset)
730 {
731         int rc = 0;
732         ENTRY;
733
734         if (obd == NULL)
735                 RETURN(-EINVAL);
736
737         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
738         OBD_COUNTER_INCREMENT(obd, statfs);
739
740         CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
741                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
742         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
743                 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
744         } else {
745                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
746                        " objects "LPU64"/"LPU64"\n",
747                        obd->obd_name, &obd->obd_osfs,
748                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
749                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
750                 spin_lock(&obd->obd_osfs_lock);
751                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
752                 spin_unlock(&obd->obd_osfs_lock);
753                 if (oinfo->oi_cb_up)
754                         oinfo->oi_cb_up(oinfo, 0);
755         }
756         RETURN(rc);
757 }
758
759 static inline int obd_statfs_rqset(struct obd_device *obd,
760                                    struct obd_statfs *osfs, __u64 max_age)
761 {
762         struct ptlrpc_request_set *set = NULL;
763         struct obd_info oinfo = { { { 0 } } };
764         int rc = 0;
765         ENTRY;
766
767         set = ptlrpc_prep_set();
768         if (set == NULL)
769                 RETURN(-ENOMEM);
770
771         oinfo.oi_osfs = osfs;
772         rc = obd_statfs_async(obd, &oinfo, max_age, set);
773         if (rc == 0)
774                 rc = ptlrpc_set_wait(set);
775         ptlrpc_set_destroy(set);
776         RETURN(rc);
777 }
778
779 /* @max_age is the oldest time in jiffies that we accept using a cached data.
780  * If the cache is older than @max_age we will get a new value from the
781  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
782 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
783                              __u64 max_age)
784 {
785         int rc = 0;
786         ENTRY;
787
788         if (obd == NULL)
789                 RETURN(-EINVAL);
790
791         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
792         OBD_COUNTER_INCREMENT(obd, statfs);
793
794         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
795                obd->obd_osfs_age, max_age);
796         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
797                 rc = OBP(obd, statfs)(obd, osfs, max_age);
798                 if (rc == 0) {
799                         spin_lock(&obd->obd_osfs_lock);
800                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
801                         obd->obd_osfs_age = cfs_time_current_64();
802                         spin_unlock(&obd->obd_osfs_lock);
803                 }
804         } else {
805                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
806                        " objects "LPU64"/"LPU64"\n",
807                        obd->obd_name, &obd->obd_osfs,
808                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
809                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
810                 spin_lock(&obd->obd_osfs_lock);
811                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
812                 spin_unlock(&obd->obd_osfs_lock);
813         }
814         RETURN(rc);
815 }
816
817 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
818                            struct lov_stripe_md *ea, obd_size start,
819                            obd_size end)
820 {
821         int rc;
822         ENTRY;
823
824         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
825         EXP_COUNTER_INCREMENT(exp, sync);
826
827         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
828         RETURN(rc);
829 }
830
831 static inline int obd_punch_rqset(struct obd_export *exp,
832                                   struct obd_info *oinfo,
833                                   struct obd_trans_info *oti)
834 {
835         struct ptlrpc_request_set *set = NULL;
836         int rc;
837         ENTRY;
838
839         EXP_CHECK_OP(exp, punch);
840         EXP_COUNTER_INCREMENT(exp, punch);
841
842         set =  ptlrpc_prep_set();
843         if (set == NULL)
844                 RETURN(-ENOMEM);
845
846         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
847         if (rc == 0)
848                 rc = ptlrpc_set_wait(set);
849         ptlrpc_set_destroy(set);
850         RETURN(rc);
851 }
852
853 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
854                             struct obd_trans_info *oti,
855                             struct ptlrpc_request_set *rqset)
856 {
857         int rc;
858         ENTRY;
859
860         EXP_CHECK_OP(exp, punch);
861         EXP_COUNTER_INCREMENT(exp, punch);
862
863         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
864         RETURN(rc);
865 }
866
867 static inline int obd_brw(int cmd, struct obd_export *exp,
868                           struct obd_info *oinfo, obd_count oa_bufs,
869                           struct brw_page *pg, struct obd_trans_info *oti)
870 {
871         int rc;
872         ENTRY;
873
874         EXP_CHECK_OP(exp, brw);
875         EXP_COUNTER_INCREMENT(exp, brw);
876
877         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
878                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
879                        "or OBD_BRW_CHECK\n");
880                 LBUG();
881         }
882
883         rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
884         RETURN(rc);
885 }
886
887 static inline int obd_brw_async(int cmd, struct obd_export *exp,
888                                 struct obd_info *oinfo, obd_count oa_bufs,
889                                 struct brw_page *pg, struct obd_trans_info *oti,
890                                 struct ptlrpc_request_set *set)
891 {
892         int rc;
893         ENTRY;
894
895         EXP_CHECK_OP(exp, brw_async);
896         EXP_COUNTER_INCREMENT(exp, brw_async);
897
898         if (!(cmd & OBD_BRW_RWMASK)) {
899                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
900                 LBUG();
901         }
902
903         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
904         RETURN(rc);
905 }
906
907 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
908                                 struct obdo *oa, struct lov_stripe_md *lsm,
909                                 obd_count oa_bufs, struct brw_page *pg,
910                                 struct obd_trans_info *oti)
911 {
912         struct ptlrpc_request_set *set = NULL;
913         struct obd_info oinfo = { { { 0 } } };
914         atomic_t nob;
915         int rc = 0;
916         ENTRY;
917
918         set =  ptlrpc_prep_set();
919         if (set == NULL)
920                 RETURN(-ENOMEM);
921         atomic_set(&nob, 0);
922         set->set_countp = &nob;
923
924         oinfo.oi_oa = oa;
925         oinfo.oi_md = lsm;
926         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
927         if (rc == 0) {
928                 rc = ptlrpc_set_wait(set);
929                 if (rc)
930                         CERROR("error from callback: rc = %d\n", rc);
931                 else
932                         rc = atomic_read(&nob);
933         } else {
934                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
935                        "error from obd_brw_async: rc = %d\n", rc);
936         }
937         ptlrpc_set_destroy(set);
938         RETURN(rc);
939 }
940
941 static inline  int obd_prep_async_page(struct obd_export *exp,
942                                        struct lov_stripe_md *lsm,
943                                        struct lov_oinfo *loi,
944                                        cfs_page_t *page, obd_off offset,
945                                        struct obd_async_page_ops *ops,
946                                        void *data, void **res)
947 {
948         int ret;
949         ENTRY;
950
951         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
952         EXP_COUNTER_INCREMENT(exp, prep_async_page);
953
954         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
955                                                  ops, data, res);
956         RETURN(ret);
957 }
958
959 static inline int obd_queue_async_io(struct obd_export *exp,
960                                      struct lov_stripe_md *lsm,
961                                      struct lov_oinfo *loi, void *cookie,
962                                      int cmd, obd_off off, int count,
963                                      obd_flag brw_flags, obd_flag async_flags)
964 {
965         int rc;
966         ENTRY;
967
968         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
969         EXP_COUNTER_INCREMENT(exp, queue_async_io);
970         LASSERT(cmd & OBD_BRW_RWMASK);
971
972         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
973                                                count, brw_flags, async_flags);
974         RETURN(rc);
975 }
976
977 static inline int obd_set_async_flags(struct obd_export *exp,
978                                       struct lov_stripe_md *lsm,
979                                       struct lov_oinfo *loi, void *cookie,
980                                       obd_flag async_flags)
981 {
982         int rc;
983         ENTRY;
984
985         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
986         EXP_COUNTER_INCREMENT(exp, set_async_flags);
987
988         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
989                                                 async_flags);
990         RETURN(rc);
991 }
992
993 static inline int obd_queue_group_io(struct obd_export *exp,
994                                      struct lov_stripe_md *lsm,
995                                      struct lov_oinfo *loi,
996                                      struct obd_io_group *oig,
997                                      void *cookie, int cmd, obd_off off,
998                                      int count, obd_flag brw_flags,
999                                      obd_flag async_flags)
1000 {
1001         int rc;
1002         ENTRY;
1003
1004         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1005         EXP_COUNTER_INCREMENT(exp, queue_group_io);
1006         LASSERT(cmd & OBD_BRW_RWMASK);
1007
1008         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1009                                                cmd, off, count, brw_flags,
1010                                                async_flags);
1011         RETURN(rc);
1012 }
1013
1014 static inline int obd_trigger_group_io(struct obd_export *exp,
1015                                        struct lov_stripe_md *lsm,
1016                                        struct lov_oinfo *loi,
1017                                        struct obd_io_group *oig)
1018 {
1019         int rc;
1020         ENTRY;
1021
1022         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1023         EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1024
1025         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1026         RETURN(rc);
1027 }
1028
1029 static inline int obd_teardown_async_page(struct obd_export *exp,
1030                                           struct lov_stripe_md *lsm,
1031                                           struct lov_oinfo *loi, void *cookie)
1032 {
1033         int rc;
1034         ENTRY;
1035
1036         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1037         EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1038
1039         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1040         RETURN(rc);
1041 }
1042
1043 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1044                              int objcount, struct obd_ioobj *obj,
1045                              int niocount, struct niobuf_remote *remote,
1046                              struct niobuf_local *local,
1047                              struct obd_trans_info *oti)
1048 {
1049         int rc;
1050         ENTRY;
1051
1052         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1053         EXP_COUNTER_INCREMENT(exp, preprw);
1054
1055         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1056                                        remote, local, oti);
1057         RETURN(rc);
1058 }
1059
1060 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1061                                int objcount, struct obd_ioobj *obj,
1062                                int niocount, struct niobuf_local *local,
1063                                struct obd_trans_info *oti, int rc)
1064 {
1065         ENTRY;
1066
1067         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1068         EXP_COUNTER_INCREMENT(exp, commitrw);
1069
1070         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1071                                          local, oti, rc);
1072         RETURN(rc);
1073 }
1074
1075 static inline int obd_merge_lvb(struct obd_export *exp,
1076                                 struct lov_stripe_md *lsm,
1077                                 struct ost_lvb *lvb, int kms_only)
1078 {
1079         int rc;
1080         ENTRY;
1081
1082         OBD_CHECK_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1083         EXP_COUNTER_INCREMENT(exp, merge_lvb);
1084
1085         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1086         RETURN(rc);
1087 }
1088
1089 static inline int obd_adjust_kms(struct obd_export *exp,
1090                                  struct lov_stripe_md *lsm, obd_off size,
1091                                  int shrink)
1092 {
1093         int rc;
1094         ENTRY;
1095
1096         OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1097         EXP_COUNTER_INCREMENT(exp, adjust_kms);
1098
1099         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1100         RETURN(rc);
1101 }
1102
1103 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1104                                 int len, void *karg, void *uarg)
1105 {
1106         int rc;
1107         ENTRY;
1108
1109         EXP_CHECK_OP(exp, iocontrol);
1110         EXP_COUNTER_INCREMENT(exp, iocontrol);
1111
1112         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1113         RETURN(rc);
1114 }
1115
1116 static inline int obd_enqueue_rqset(struct obd_export *exp,
1117                                     struct obd_info *oinfo,
1118                                     struct ldlm_enqueue_info *einfo)
1119 {
1120         struct ptlrpc_request_set *set = NULL;
1121         int rc;
1122         ENTRY;
1123
1124         EXP_CHECK_OP(exp, enqueue);
1125         EXP_COUNTER_INCREMENT(exp, enqueue);
1126
1127         set =  ptlrpc_prep_set();
1128         if (set == NULL)
1129                 RETURN(-ENOMEM);
1130
1131         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1132         if (rc == 0)
1133                 rc = ptlrpc_set_wait(set);
1134         ptlrpc_set_destroy(set);
1135         RETURN(rc);
1136 }
1137
1138 static inline int obd_enqueue(struct obd_export *exp,
1139                               struct obd_info *oinfo,
1140                               struct ldlm_enqueue_info *einfo,
1141                               struct ptlrpc_request_set *set)
1142 {
1143         int rc;
1144         ENTRY;
1145
1146         EXP_CHECK_OP(exp, enqueue);
1147         EXP_COUNTER_INCREMENT(exp, enqueue);
1148
1149         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1150         RETURN(rc);
1151 }
1152
1153 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1154                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1155                             int *flags, void *data, struct lustre_handle *lockh)
1156 {
1157         int rc;
1158         ENTRY;
1159
1160         EXP_CHECK_OP(exp, match);
1161         EXP_COUNTER_INCREMENT(exp, match);
1162
1163         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1164                                       lockh);
1165         RETURN(rc);
1166 }
1167
1168 static inline int obd_change_cbdata(struct obd_export *exp,
1169                                     struct lov_stripe_md *lsm,
1170                                     ldlm_iterator_t it, void *data)
1171 {
1172         int rc;
1173         ENTRY;
1174
1175         EXP_CHECK_OP(exp, change_cbdata);
1176         EXP_COUNTER_INCREMENT(exp, change_cbdata);
1177
1178         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1179         RETURN(rc);
1180 }
1181
1182 static inline int obd_cancel(struct obd_export *exp,
1183                              struct lov_stripe_md *ea, __u32 mode,
1184                              struct lustre_handle *lockh)
1185 {
1186         int rc;
1187         ENTRY;
1188
1189         EXP_CHECK_OP(exp, cancel);
1190         EXP_COUNTER_INCREMENT(exp, cancel);
1191
1192         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1193         RETURN(rc);
1194 }
1195
1196 static inline int obd_cancel_unused(struct obd_export *exp,
1197                                     struct lov_stripe_md *ea, int flags,
1198                                     void *opaque)
1199 {
1200         int rc;
1201         ENTRY;
1202
1203         EXP_CHECK_OP(exp, cancel_unused);
1204         EXP_COUNTER_INCREMENT(exp, cancel_unused);
1205
1206         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1207         RETURN(rc);
1208 }
1209
1210 static inline int obd_join_lru(struct obd_export *exp,
1211                                struct lov_stripe_md *ea, int join)
1212 {
1213         int rc;
1214         ENTRY;
1215
1216         EXP_CHECK_OP(exp, join_lru);
1217         EXP_COUNTER_INCREMENT(exp, join_lru);
1218
1219         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1220         RETURN(rc);
1221 }
1222
1223 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1224                           int type, struct obd_client_handle *handle, int flag)
1225 {
1226         int rc;
1227         ENTRY;
1228
1229         EXP_CHECK_OP(exp, pin);
1230         EXP_COUNTER_INCREMENT(exp, pin);
1231
1232         rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1233         RETURN(rc);
1234 }
1235
1236 static inline int obd_unpin(struct obd_export *exp,
1237                             struct obd_client_handle *handle, int flag)
1238 {
1239         int rc;
1240         ENTRY;
1241
1242         EXP_CHECK_OP(exp, unpin);
1243         EXP_COUNTER_INCREMENT(exp, unpin);
1244
1245         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1246         RETURN(rc);
1247 }
1248
1249
1250 static inline void obd_import_event(struct obd_device *obd,
1251                                     struct obd_import *imp,
1252                                     enum obd_import_event event)
1253 {
1254         ENTRY;
1255         if (!obd) {
1256                 CERROR("NULL device\n");
1257                 EXIT;
1258                 return;
1259         }
1260         if (obd->obd_set_up && OBP(obd, import_event)) {
1261                 OBD_COUNTER_INCREMENT(obd, import_event);
1262                 OBP(obd, import_event)(obd, imp, event);
1263         }
1264         EXIT;
1265 }
1266
1267 static inline int obd_notify(struct obd_device *obd,
1268                              struct obd_device *watched,
1269                              enum obd_notify_event ev, void *data)
1270 {
1271         ENTRY;
1272         OBD_CHECK_DEV(obd);
1273
1274         /* the check for async_recov is a complete hack - I'm hereby
1275            overloading the meaning to also mean "this was called from
1276            mds_postsetup".  I know that my mds is able to handle notifies
1277            by this point, and it needs to get them to execute mds_postrecov. */                                                                                
1278         if (!obd->obd_set_up && !obd->obd_async_recov) {
1279                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1280                 RETURN(-EINVAL);
1281         }
1282
1283         if (!OBP(obd, notify)) 
1284                 RETURN(-ENOSYS);
1285
1286         OBD_COUNTER_INCREMENT(obd, notify);
1287         RETURN(OBP(obd, notify)(obd, watched, ev, data));
1288 }
1289
1290 static inline int obd_notify_observer(struct obd_device *observer,
1291                                       struct obd_device *observed,
1292                                       enum obd_notify_event ev, void *data)
1293 {
1294         int rc1;
1295         int rc2;
1296
1297         struct obd_notify_upcall *onu;
1298
1299         if (observer->obd_observer)
1300                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1301         else
1302                 rc1 = 0;
1303         /*
1304          * Also, call non-obd listener, if any
1305          */
1306         onu = &observer->obd_upcall;
1307         if (onu->onu_upcall != NULL)
1308                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1309         else
1310                 rc2 = 0;
1311
1312         return rc1 ?: rc2;
1313  }
1314
1315 static inline int obd_quotacheck(struct obd_export *exp,
1316                                  struct obd_quotactl *oqctl)
1317 {
1318         int rc;
1319         ENTRY;
1320
1321         EXP_CHECK_OP(exp, quotacheck);
1322         EXP_COUNTER_INCREMENT(exp, quotacheck);
1323
1324         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1325         RETURN(rc);
1326 }
1327
1328 static inline int obd_quotactl(struct obd_export *exp,
1329                                struct obd_quotactl *oqctl)
1330 {
1331         int rc;
1332         ENTRY;
1333
1334         EXP_CHECK_OP(exp, quotactl);
1335         EXP_COUNTER_INCREMENT(exp, quotactl);
1336
1337         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1338         RETURN(rc);
1339 }
1340
1341 static inline int obd_health_check(struct obd_device *obd)
1342 {
1343         /* returns: 0 on healthy
1344          *         >0 on unhealthy + reason code/flag
1345          *            however the only suppored reason == 1 right now
1346          *            We'll need to define some better reasons
1347          *            or flags in the future.
1348          *         <0 on error
1349          */
1350         int rc;
1351         ENTRY;
1352
1353         /* don't use EXP_CHECK_OP, because NULL method is normal here */
1354         if (obd == NULL || !OBT(obd)) {
1355                 CERROR("cleaned up obd\n");
1356                 RETURN(-EOPNOTSUPP);
1357         }
1358         if (!obd->obd_set_up || obd->obd_stopping)
1359                 RETURN(0);
1360         if (!OBP(obd, health_check))
1361                 RETURN(0);
1362
1363         rc = OBP(obd, health_check)(obd);
1364         RETURN(rc);
1365 }
1366
1367 static inline int obd_register_observer(struct obd_device *obd,
1368                                         struct obd_device *observer)
1369 {
1370         ENTRY;
1371         OBD_CHECK_DEV(obd);
1372         if (obd->obd_observer && observer)
1373                 RETURN(-EALREADY);
1374         obd->obd_observer = observer;
1375         RETURN(0);
1376 }
1377
1378 /* OBD Metadata Support */
1379
1380 extern int obd_init_caches(void);
1381 extern void obd_cleanup_caches(void);
1382
1383 /* support routines */
1384 extern cfs_mem_cache_t *obdo_cachep;
1385 static inline struct obdo *obdo_alloc(void)
1386 {
1387         struct obdo *oa;
1388
1389         OBD_SLAB_ALLOC(oa, obdo_cachep, CFS_ALLOC_STD, sizeof(*oa));
1390
1391         return oa;
1392 }
1393
1394 static inline void obdo_free(struct obdo *oa)
1395 {
1396         OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1397 }
1398
1399 /* I'm as embarrassed about this as you are.
1400  *
1401  * <shaver> // XXX do not look into _superhack with remaining eye
1402  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1403 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1404
1405 /* sysctl.c */
1406 extern void obd_sysctl_init (void);
1407 extern void obd_sysctl_clean (void);
1408
1409 /* uuid.c  */
1410 typedef __u8 class_uuid_t[16];
1411 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1412
1413 /* lustre_peer.c    */
1414 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index);
1415 int class_add_uuid(char *uuid, __u64 nid);
1416 int class_del_uuid (char *uuid);
1417 void class_init_uuidlist(void);
1418 void class_exit_uuidlist(void);
1419
1420 /* prng.c */
1421 void ll_generate_random_uuid(class_uuid_t uuid_out);
1422
1423 #endif /* __LINUX_OBD_CLASS_H */