Whamcloud - gitweb
b=13220
[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         atomic_t nob;
927         int rc = 0;
928         ENTRY;
929
930         set =  ptlrpc_prep_set();
931         if (set == NULL)
932                 RETURN(-ENOMEM);
933         atomic_set(&nob, 0);
934         set->set_countp = &nob;
935
936         oinfo.oi_oa = oa;
937         oinfo.oi_md = lsm;
938         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
939         if (rc == 0) {
940                 rc = ptlrpc_set_wait(set);
941                 if (rc)
942                         CERROR("error from callback: rc = %d\n", rc);
943                 else
944                         rc = atomic_read(&nob);
945         } else {
946                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
947                        "error from obd_brw_async: rc = %d\n", rc);
948         }
949         ptlrpc_set_destroy(set);
950         RETURN(rc);
951 }
952
953 static inline  int obd_prep_async_page(struct obd_export *exp,
954                                        struct lov_stripe_md *lsm,
955                                        struct lov_oinfo *loi,
956                                        cfs_page_t *page, obd_off offset,
957                                        struct obd_async_page_ops *ops,
958                                        void *data, void **res)
959 {
960         int ret;
961         ENTRY;
962
963         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
964         EXP_COUNTER_INCREMENT(exp, prep_async_page);
965
966         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
967                                                  ops, data, res);
968         RETURN(ret);
969 }
970
971 static inline int obd_queue_async_io(struct obd_export *exp,
972                                      struct lov_stripe_md *lsm,
973                                      struct lov_oinfo *loi, void *cookie,
974                                      int cmd, obd_off off, int count,
975                                      obd_flag brw_flags, obd_flag async_flags)
976 {
977         int rc;
978         ENTRY;
979
980         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
981         EXP_COUNTER_INCREMENT(exp, queue_async_io);
982         LASSERT(cmd & OBD_BRW_RWMASK);
983
984         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
985                                                count, brw_flags, async_flags);
986         RETURN(rc);
987 }
988
989 static inline int obd_set_async_flags(struct obd_export *exp,
990                                       struct lov_stripe_md *lsm,
991                                       struct lov_oinfo *loi, void *cookie,
992                                       obd_flag async_flags)
993 {
994         int rc;
995         ENTRY;
996
997         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
998         EXP_COUNTER_INCREMENT(exp, set_async_flags);
999
1000         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1001                                                 async_flags);
1002         RETURN(rc);
1003 }
1004
1005 static inline int obd_queue_group_io(struct obd_export *exp,
1006                                      struct lov_stripe_md *lsm,
1007                                      struct lov_oinfo *loi,
1008                                      struct obd_io_group *oig,
1009                                      void *cookie, int cmd, obd_off off,
1010                                      int count, obd_flag brw_flags,
1011                                      obd_flag async_flags)
1012 {
1013         int rc;
1014         ENTRY;
1015
1016         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1017         EXP_COUNTER_INCREMENT(exp, queue_group_io);
1018         LASSERT(cmd & OBD_BRW_RWMASK);
1019
1020         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1021                                                cmd, off, count, brw_flags,
1022                                                async_flags);
1023         RETURN(rc);
1024 }
1025
1026 static inline int obd_trigger_group_io(struct obd_export *exp,
1027                                        struct lov_stripe_md *lsm,
1028                                        struct lov_oinfo *loi,
1029                                        struct obd_io_group *oig)
1030 {
1031         int rc;
1032         ENTRY;
1033
1034         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1035         EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1036
1037         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1038         RETURN(rc);
1039 }
1040
1041 static inline int obd_teardown_async_page(struct obd_export *exp,
1042                                           struct lov_stripe_md *lsm,
1043                                           struct lov_oinfo *loi, void *cookie)
1044 {
1045         int rc;
1046         ENTRY;
1047
1048         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1049         EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1050
1051         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1052         RETURN(rc);
1053 }
1054
1055 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1056                              int objcount, struct obd_ioobj *obj,
1057                              int niocount, struct niobuf_remote *remote,
1058                              struct niobuf_local *local,
1059                              struct obd_trans_info *oti)
1060 {
1061         int rc;
1062         ENTRY;
1063
1064         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1065         EXP_COUNTER_INCREMENT(exp, preprw);
1066
1067         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1068                                        remote, local, oti);
1069         RETURN(rc);
1070 }
1071
1072 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1073                                int objcount, struct obd_ioobj *obj,
1074                                int niocount, struct niobuf_local *local,
1075                                struct obd_trans_info *oti, int rc)
1076 {
1077         ENTRY;
1078
1079         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1080         EXP_COUNTER_INCREMENT(exp, commitrw);
1081
1082         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1083                                          local, oti, rc);
1084         RETURN(rc);
1085 }
1086
1087 static inline int obd_merge_lvb(struct obd_export *exp,
1088                                 struct lov_stripe_md *lsm,
1089                                 struct ost_lvb *lvb, int kms_only)
1090 {
1091         int rc;
1092         ENTRY;
1093
1094         OBD_CHECK_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1095         EXP_COUNTER_INCREMENT(exp, merge_lvb);
1096
1097         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1098         RETURN(rc);
1099 }
1100
1101 static inline int obd_adjust_kms(struct obd_export *exp,
1102                                  struct lov_stripe_md *lsm, obd_off size,
1103                                  int shrink)
1104 {
1105         int rc;
1106         ENTRY;
1107
1108         OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1109         EXP_COUNTER_INCREMENT(exp, adjust_kms);
1110
1111         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1112         RETURN(rc);
1113 }
1114
1115 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1116                                 int len, void *karg, void *uarg)
1117 {
1118         int rc;
1119         ENTRY;
1120
1121         EXP_CHECK_OP(exp, iocontrol);
1122         EXP_COUNTER_INCREMENT(exp, iocontrol);
1123
1124         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1125         RETURN(rc);
1126 }
1127
1128 static inline int obd_enqueue_rqset(struct obd_export *exp,
1129                                     struct obd_info *oinfo,
1130                                     struct ldlm_enqueue_info *einfo)
1131 {
1132         struct ptlrpc_request_set *set = NULL;
1133         int rc;
1134         ENTRY;
1135
1136         EXP_CHECK_OP(exp, enqueue);
1137         EXP_COUNTER_INCREMENT(exp, enqueue);
1138
1139         set =  ptlrpc_prep_set();
1140         if (set == NULL)
1141                 RETURN(-ENOMEM);
1142
1143         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1144         if (rc == 0)
1145                 rc = ptlrpc_set_wait(set);
1146         ptlrpc_set_destroy(set);
1147         RETURN(rc);
1148 }
1149
1150 static inline int obd_enqueue(struct obd_export *exp,
1151                               struct obd_info *oinfo,
1152                               struct ldlm_enqueue_info *einfo,
1153                               struct ptlrpc_request_set *set)
1154 {
1155         int rc;
1156         ENTRY;
1157
1158         EXP_CHECK_OP(exp, enqueue);
1159         EXP_COUNTER_INCREMENT(exp, enqueue);
1160
1161         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1162         RETURN(rc);
1163 }
1164
1165 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1166                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1167                             int *flags, void *data, struct lustre_handle *lockh)
1168 {
1169         int rc;
1170         ENTRY;
1171
1172         EXP_CHECK_OP(exp, match);
1173         EXP_COUNTER_INCREMENT(exp, match);
1174
1175         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1176                                       lockh);
1177         RETURN(rc);
1178 }
1179
1180 static inline int obd_change_cbdata(struct obd_export *exp,
1181                                     struct lov_stripe_md *lsm,
1182                                     ldlm_iterator_t it, void *data)
1183 {
1184         int rc;
1185         ENTRY;
1186
1187         EXP_CHECK_OP(exp, change_cbdata);
1188         EXP_COUNTER_INCREMENT(exp, change_cbdata);
1189
1190         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1191         RETURN(rc);
1192 }
1193
1194 static inline int obd_cancel(struct obd_export *exp,
1195                              struct lov_stripe_md *ea, __u32 mode,
1196                              struct lustre_handle *lockh)
1197 {
1198         int rc;
1199         ENTRY;
1200
1201         EXP_CHECK_OP(exp, cancel);
1202         EXP_COUNTER_INCREMENT(exp, cancel);
1203
1204         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1205         RETURN(rc);
1206 }
1207
1208 static inline int obd_cancel_unused(struct obd_export *exp,
1209                                     struct lov_stripe_md *ea, int flags,
1210                                     void *opaque)
1211 {
1212         int rc;
1213         ENTRY;
1214
1215         EXP_CHECK_OP(exp, cancel_unused);
1216         EXP_COUNTER_INCREMENT(exp, cancel_unused);
1217
1218         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1219         RETURN(rc);
1220 }
1221
1222 static inline int obd_join_lru(struct obd_export *exp,
1223                                struct lov_stripe_md *ea, int join)
1224 {
1225         int rc;
1226         ENTRY;
1227
1228         EXP_CHECK_OP(exp, join_lru);
1229         EXP_COUNTER_INCREMENT(exp, join_lru);
1230
1231         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1232         RETURN(rc);
1233 }
1234
1235 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1236                           int type, struct obd_client_handle *handle, int flag)
1237 {
1238         int rc;
1239         ENTRY;
1240
1241         EXP_CHECK_OP(exp, pin);
1242         EXP_COUNTER_INCREMENT(exp, pin);
1243
1244         rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1245         RETURN(rc);
1246 }
1247
1248 static inline int obd_unpin(struct obd_export *exp,
1249                             struct obd_client_handle *handle, int flag)
1250 {
1251         int rc;
1252         ENTRY;
1253
1254         EXP_CHECK_OP(exp, unpin);
1255         EXP_COUNTER_INCREMENT(exp, unpin);
1256
1257         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1258         RETURN(rc);
1259 }
1260
1261
1262 static inline void obd_import_event(struct obd_device *obd,
1263                                     struct obd_import *imp,
1264                                     enum obd_import_event event)
1265 {
1266         ENTRY;
1267         if (!obd) {
1268                 CERROR("NULL device\n");
1269                 EXIT;
1270                 return;
1271         }
1272         if (obd->obd_set_up && OBP(obd, import_event)) {
1273                 OBD_COUNTER_INCREMENT(obd, import_event);
1274                 OBP(obd, import_event)(obd, imp, event);
1275         }
1276         EXIT;
1277 }
1278
1279 static inline int obd_notify(struct obd_device *obd,
1280                              struct obd_device *watched,
1281                              enum obd_notify_event ev, void *data)
1282 {
1283         ENTRY;
1284         OBD_CHECK_DEV(obd);
1285
1286         /* the check for async_recov is a complete hack - I'm hereby
1287            overloading the meaning to also mean "this was called from
1288            mds_postsetup".  I know that my mds is able to handle notifies
1289            by this point, and it needs to get them to execute mds_postrecov. */                                                                                
1290         if (!obd->obd_set_up && !obd->obd_async_recov) {
1291                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1292                 RETURN(-EINVAL);
1293         }
1294
1295         if (!OBP(obd, notify)) 
1296                 RETURN(-ENOSYS);
1297
1298         OBD_COUNTER_INCREMENT(obd, notify);
1299         RETURN(OBP(obd, notify)(obd, watched, ev, data));
1300 }
1301
1302 static inline int obd_notify_observer(struct obd_device *observer,
1303                                       struct obd_device *observed,
1304                                       enum obd_notify_event ev, void *data)
1305 {
1306         int rc1;
1307         int rc2;
1308
1309         struct obd_notify_upcall *onu;
1310
1311         if (observer->obd_observer)
1312                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1313         else
1314                 rc1 = 0;
1315         /*
1316          * Also, call non-obd listener, if any
1317          */
1318         onu = &observer->obd_upcall;
1319         if (onu->onu_upcall != NULL)
1320                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1321         else
1322                 rc2 = 0;
1323
1324         return rc1 ?: rc2;
1325  }
1326
1327 static inline int obd_quotacheck(struct obd_export *exp,
1328                                  struct obd_quotactl *oqctl)
1329 {
1330         int rc;
1331         ENTRY;
1332
1333         EXP_CHECK_OP(exp, quotacheck);
1334         EXP_COUNTER_INCREMENT(exp, quotacheck);
1335
1336         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1337         RETURN(rc);
1338 }
1339
1340 static inline int obd_quotactl(struct obd_export *exp,
1341                                struct obd_quotactl *oqctl)
1342 {
1343         int rc;
1344         ENTRY;
1345
1346         EXP_CHECK_OP(exp, quotactl);
1347         EXP_COUNTER_INCREMENT(exp, quotactl);
1348
1349         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1350         RETURN(rc);
1351 }
1352
1353 static inline int obd_health_check(struct obd_device *obd)
1354 {
1355         /* returns: 0 on healthy
1356          *         >0 on unhealthy + reason code/flag
1357          *            however the only suppored reason == 1 right now
1358          *            We'll need to define some better reasons
1359          *            or flags in the future.
1360          *         <0 on error
1361          */
1362         int rc;
1363         ENTRY;
1364
1365         /* don't use EXP_CHECK_OP, because NULL method is normal here */
1366         if (obd == NULL || !OBT(obd)) {
1367                 CERROR("cleaned up obd\n");
1368                 RETURN(-EOPNOTSUPP);
1369         }
1370         if (!obd->obd_set_up || obd->obd_stopping)
1371                 RETURN(0);
1372         if (!OBP(obd, health_check))
1373                 RETURN(0);
1374
1375         rc = OBP(obd, health_check)(obd);
1376         RETURN(rc);
1377 }
1378
1379 static inline int obd_register_observer(struct obd_device *obd,
1380                                         struct obd_device *observer)
1381 {
1382         ENTRY;
1383         OBD_CHECK_DEV(obd);
1384         if (obd->obd_observer && observer)
1385                 RETURN(-EALREADY);
1386         obd->obd_observer = observer;
1387         RETURN(0);
1388 }
1389
1390 /* OBD Metadata Support */
1391
1392 extern int obd_init_caches(void);
1393 extern void obd_cleanup_caches(void);
1394
1395 /* support routines */
1396 extern cfs_mem_cache_t *obdo_cachep;
1397
1398 #define OBDO_ALLOC(ptr)                                                       \
1399 do {                                                                          \
1400         OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep);                               \
1401 } while(0)
1402
1403 #define OBDO_FREE(ptr)                                                        \
1404 do {                                                                          \
1405         OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
1406 } while(0)
1407
1408 /* I'm as embarrassed about this as you are.
1409  *
1410  * <shaver> // XXX do not look into _superhack with remaining eye
1411  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1412 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1413
1414 /* sysctl.c */
1415 extern void obd_sysctl_init (void);
1416 extern void obd_sysctl_clean (void);
1417
1418 /* uuid.c  */
1419 typedef __u8 class_uuid_t[16];
1420 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1421
1422 /* lustre_peer.c    */
1423 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index);
1424 int class_add_uuid(char *uuid, __u64 nid);
1425 int class_del_uuid (char *uuid);
1426 void class_init_uuidlist(void);
1427 void class_exit_uuidlist(void);
1428
1429 /* prng.c */
1430 void ll_generate_random_uuid(class_uuid_t uuid_out);
1431
1432 #endif /* __LINUX_OBD_CLASS_H */