Whamcloud - gitweb
b=10718
[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_nid_stats != NULL &&                       \
251                     (export)->exp_nid_stats->nid_stats != NULL)              \
252                         lprocfs_counter_incr(                                \
253                                 (export)->exp_nid_stats->nid_stats, coffset);\
254         }
255
256 #else
257 #define OBD_COUNTER_OFFSET(op)
258 #define OBD_COUNTER_INCREMENT(obd, op)
259 #define EXP_COUNTER_INCREMENT(exp, op);
260 #endif
261
262 #define OBD_CHECK_OP(obd, op, err)                              \
263 do {                                                            \
264         if (!OBT(obd) || !OBP((obd), op)) {\
265                 if (err)                                        \
266                         CERROR("obd_" #op ": dev %d no operation\n",    \
267                                obd->obd_minor);                         \
268                 RETURN(err);                                    \
269         }                                                       \
270 } while (0)
271
272 #define EXP_CHECK_OP(exp, op)                                   \
273 do {                                                            \
274         if ((exp) == NULL) {                                    \
275                 CERROR("obd_" #op ": NULL export\n");           \
276                 RETURN(-ENODEV);                                \
277         }                                                       \
278         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
279                 CERROR("obd_" #op ": cleaned up obd\n");        \
280                 RETURN(-EOPNOTSUPP);                            \
281         }                                                       \
282         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
283                 CERROR("obd_" #op ": dev %d no operation\n",    \
284                        (exp)->exp_obd->obd_minor);              \
285                 RETURN(-EOPNOTSUPP);                            \
286         }                                                       \
287 } while (0)
288
289 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
290 do {                                                            \
291         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
292                 if (err)                                        \
293                         CERROR("lop_" #op ": dev %d no operation\n",    \
294                                ctxt->loc_obd->obd_minor);                         \
295                 RETURN(err);                                    \
296         }                                                       \
297 } while (0)
298
299 static inline int class_devno_max(void)
300 {
301         return MAX_OBD_DEVICES;
302 }
303
304 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
305                                void *key, __u32 *vallen, void *val)
306 {
307         int rc;
308         ENTRY;
309
310         EXP_CHECK_OP(exp, get_info);
311         EXP_COUNTER_INCREMENT(exp, get_info);
312
313         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
314         RETURN(rc);
315 }
316
317 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
318                                      void *key, obd_count vallen, void *val,
319                                      struct ptlrpc_request_set *set)
320 {
321         int rc;
322         ENTRY;
323
324         EXP_CHECK_OP(exp, set_info_async);
325         EXP_COUNTER_INCREMENT(exp, set_info_async);
326
327         rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val, 
328                                                set);
329         RETURN(rc);
330 }
331
332 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
333 {
334         int rc;
335         ENTRY;
336
337         OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
338         OBD_COUNTER_INCREMENT(obd, setup);
339
340         rc = OBP(obd, setup)(obd, datalen, data);
341         RETURN(rc);
342 }
343
344 static inline int obd_precleanup(struct obd_device *obd, 
345                                  enum obd_cleanup_stage cleanup_stage)
346 {
347         int rc;
348         ENTRY;
349
350         OBD_CHECK_OP(obd, precleanup, 0);
351         OBD_COUNTER_INCREMENT(obd, precleanup);
352
353         rc = OBP(obd, precleanup)(obd, cleanup_stage);
354         RETURN(rc);
355 }
356
357 static inline int obd_cleanup(struct obd_device *obd)
358 {
359         int rc;
360         ENTRY;
361
362         OBD_CHECK_DEV(obd);
363         OBD_CHECK_OP(obd, cleanup, 0);
364         OBD_COUNTER_INCREMENT(obd, cleanup);
365
366         rc = OBP(obd, cleanup)(obd);
367         RETURN(rc);
368 }
369
370 static inline int
371 obd_process_config(struct obd_device *obd, int datalen, void *data)
372 {
373         int rc;
374         ENTRY;
375
376         OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
377         OBD_COUNTER_INCREMENT(obd, process_config);
378
379         rc = OBP(obd, process_config)(obd, datalen, data);
380         RETURN(rc);
381 }
382
383 /* Pack an in-memory MD struct for storage on disk.
384  * Returns +ve size of packed MD (0 for free), or -ve error.
385  *
386  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
387  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
388  * If @*disk_tgt == NULL, it will be allocated
389  */
390 static inline int obd_packmd(struct obd_export *exp,
391                              struct lov_mds_md **disk_tgt,
392                              struct lov_stripe_md *mem_src)
393 {
394         int rc;
395         ENTRY;
396
397         EXP_CHECK_OP(exp, packmd);
398         EXP_COUNTER_INCREMENT(exp, packmd);
399
400         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
401         RETURN(rc);
402 }
403
404 static inline int obd_size_diskmd(struct obd_export *exp,
405                                   struct lov_stripe_md *mem_src)
406 {
407         return obd_packmd(exp, NULL, mem_src);
408 }
409
410 /* helper functions */
411 static inline int obd_alloc_diskmd(struct obd_export *exp,
412                                    struct lov_mds_md **disk_tgt)
413 {
414         LASSERT(disk_tgt);
415         LASSERT(*disk_tgt == NULL);
416         return obd_packmd(exp, disk_tgt, NULL);
417 }
418
419 static inline int obd_free_diskmd(struct obd_export *exp,
420                                   struct lov_mds_md **disk_tgt)
421 {
422         LASSERT(disk_tgt);
423         LASSERT(*disk_tgt);
424         return obd_packmd(exp, disk_tgt, NULL);
425 }
426
427 /* Unpack an MD struct from disk to in-memory format.
428  * Returns +ve size of unpacked MD (0 for free), or -ve error.
429  *
430  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
431  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
432  * If @*mem_tgt == NULL, it will be allocated
433  */
434 static inline int obd_unpackmd(struct obd_export *exp,
435                                struct lov_stripe_md **mem_tgt,
436                                struct lov_mds_md *disk_src,
437                                int disk_len)
438 {
439         int rc;
440         ENTRY;
441
442         EXP_CHECK_OP(exp, unpackmd);
443         EXP_COUNTER_INCREMENT(exp, unpackmd);
444
445         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
446         RETURN(rc);
447 }
448
449 /* helper functions */
450 static inline int obd_alloc_memmd(struct obd_export *exp,
451                                   struct lov_stripe_md **mem_tgt)
452 {
453         LASSERT(mem_tgt);
454         LASSERT(*mem_tgt == NULL);
455         return obd_unpackmd(exp, mem_tgt, NULL, 0);
456 }
457
458 static inline int obd_free_memmd(struct obd_export *exp,
459                                  struct lov_stripe_md **mem_tgt)
460 {
461         LASSERT(mem_tgt);
462         LASSERT(*mem_tgt);
463         return obd_unpackmd(exp, mem_tgt, NULL, 0);
464 }
465
466 static inline int obd_checkmd(struct obd_export *exp,
467                               struct obd_export *md_exp,
468                               struct lov_stripe_md *mem_tgt)
469 {
470         int rc;
471         ENTRY;
472
473         EXP_CHECK_OP(exp, checkmd);
474         EXP_COUNTER_INCREMENT(exp, checkmd);
475
476         rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
477         RETURN(rc);
478 }
479
480 static inline int obd_precreate(struct obd_export *exp, int need_create)
481 {
482         int rc;
483         ENTRY;
484
485         EXP_CHECK_OP(exp, precreate);
486         OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
487
488         rc = OBP(exp->exp_obd, precreate)(exp, need_create);
489         RETURN(rc);
490 }
491
492 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
493                              struct lov_stripe_md **ea,
494                              struct obd_trans_info *oti)
495 {
496         int rc;
497         ENTRY;
498
499         EXP_CHECK_OP(exp, create);
500         EXP_COUNTER_INCREMENT(exp, create);
501
502         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
503         RETURN(rc);
504 }
505
506 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
507                               struct lov_stripe_md *ea,
508                               struct obd_trans_info *oti,
509                               struct obd_export *md_exp)
510 {
511         int rc;
512         ENTRY;
513
514         EXP_CHECK_OP(exp, destroy);
515         EXP_COUNTER_INCREMENT(exp, destroy);
516
517         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
518         RETURN(rc);
519 }
520
521 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
522 {
523         int rc;
524         ENTRY;
525
526         EXP_CHECK_OP(exp, getattr);
527         EXP_COUNTER_INCREMENT(exp, getattr);
528
529         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
530         RETURN(rc);
531 }
532
533 static inline int obd_getattr_async(struct obd_export *exp,
534                                     struct obd_info *oinfo,
535                                     struct ptlrpc_request_set *set)
536 {
537         int rc;
538         ENTRY;
539
540         EXP_CHECK_OP(exp, getattr_async);
541         EXP_COUNTER_INCREMENT(exp, getattr_async);
542
543         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
544         RETURN(rc);
545 }
546
547 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
548                               struct obd_trans_info *oti)
549 {
550         int rc;
551         ENTRY;
552
553         EXP_CHECK_OP(exp, setattr);
554         EXP_COUNTER_INCREMENT(exp, setattr);
555
556         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
557         RETURN(rc);
558 }
559
560 /* This performs all the requests set init/wait/destroy actions. */
561 static inline int obd_setattr_rqset(struct obd_export *exp,
562                                     struct obd_info *oinfo,
563                                     struct obd_trans_info *oti)
564 {
565         struct ptlrpc_request_set *set = NULL;
566         int rc;
567         ENTRY;
568
569         EXP_CHECK_OP(exp, setattr_async);
570         EXP_COUNTER_INCREMENT(exp, setattr_async);
571
572         set =  ptlrpc_prep_set();
573         if (set == NULL)
574                 RETURN(-ENOMEM);
575
576         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
577         if (rc == 0)
578                 rc = ptlrpc_set_wait(set);
579         ptlrpc_set_destroy(set);
580         RETURN(rc);
581 }
582
583 /* This adds all the requests into @set if @set != NULL, otherwise
584    all requests are sent asynchronously without waiting for response. */
585 static inline int obd_setattr_async(struct obd_export *exp,
586                                     struct obd_info *oinfo,
587                                     struct obd_trans_info *oti,
588                                     struct ptlrpc_request_set *set)
589 {
590         int rc;
591         ENTRY;
592
593         EXP_CHECK_OP(exp, setattr_async);
594         EXP_COUNTER_INCREMENT(exp, setattr_async);
595
596         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
597         RETURN(rc);
598 }
599
600 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
601                                int priority)
602 {
603         struct obd_device *obd = imp->imp_obd;
604         int rc;
605         ENTRY;
606
607         OBD_CHECK_DEV_ACTIVE(obd);
608         OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
609         OBD_COUNTER_INCREMENT(obd, add_conn);
610
611         rc = OBP(obd, add_conn)(imp, uuid, priority);
612         RETURN(rc);
613 }
614
615 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
616 {
617         struct obd_device *obd = imp->imp_obd;
618         int rc;
619         ENTRY;
620
621         OBD_CHECK_DEV_ACTIVE(obd);
622         OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
623         OBD_COUNTER_INCREMENT(obd, del_conn);
624
625         rc = OBP(obd, del_conn)(imp, uuid);
626         RETURN(rc);
627 }
628
629 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
630                               struct obd_uuid *cluuid,
631                               struct obd_connect_data *d,
632                               void *localdata)
633 {
634         int rc;
635         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
636         ENTRY;
637
638         OBD_CHECK_DEV_ACTIVE(obd);
639         OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
640         OBD_COUNTER_INCREMENT(obd, connect);
641
642         rc = OBP(obd, connect)(conn, obd, cluuid, d, localdata);
643         /* check that only subset is granted */
644         LASSERT(ergo(d != NULL,
645                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
646         RETURN(rc);
647 }
648
649 static inline int obd_reconnect(struct obd_export *exp,
650                                 struct obd_device *obd,
651                                 struct obd_uuid *cluuid,
652                                 struct obd_connect_data *d)
653 {
654         int rc;
655         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
656         ENTRY;
657
658         OBD_CHECK_DEV_ACTIVE(obd);
659         OBD_CHECK_OP(obd, reconnect, 0);
660         OBD_COUNTER_INCREMENT(obd, reconnect);
661
662         rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
663         /* check that only subset is granted */
664         LASSERT(ergo(d != NULL,
665                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
666         RETURN(rc);
667 }
668
669 static inline int obd_disconnect(struct obd_export *exp)
670 {
671         int rc;
672         ENTRY;
673
674         EXP_CHECK_OP(exp, disconnect);
675         EXP_COUNTER_INCREMENT(exp, disconnect);
676
677         rc = OBP(exp->exp_obd, disconnect)(exp);
678         RETURN(rc);
679 }
680
681 static inline int obd_ping(struct obd_export *exp)
682 {
683         int rc;
684         ENTRY;
685
686         OBD_CHECK_OP(exp->exp_obd, ping, 0);
687         EXP_COUNTER_INCREMENT(exp, ping);
688
689         rc = OBP(exp->exp_obd, ping)(exp);
690         RETURN(rc);
691 }
692
693 static inline int obd_init_export(struct obd_export *exp)
694 {
695         int rc = 0;
696
697         ENTRY;
698         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
699             OBP((exp)->exp_obd, init_export))
700                 rc = OBP(exp->exp_obd, init_export)(exp);
701         RETURN(rc);
702 }
703
704 static inline int obd_destroy_export(struct obd_export *exp)
705 {
706         ENTRY;
707         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
708             OBP((exp)->exp_obd, destroy_export))
709                 OBP(exp->exp_obd, destroy_export)(exp);
710         RETURN(0);
711 }
712
713 static inline int obd_extent_calc(struct obd_export *exp,
714                                   struct lov_stripe_md *md,
715                                   int cmd, obd_off *offset)
716 {
717         int rc;
718         ENTRY;
719         EXP_CHECK_OP(exp, extent_calc);
720         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
721         RETURN(rc);
722 }
723
724 static inline struct dentry *
725 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
726 {
727         LASSERT(exp->exp_obd);
728
729         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
730                                exp->exp_obd);
731 }
732
733 #ifndef time_before
734 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
735 #endif
736
737 /* @max_age is the oldest time in jiffies that we accept using a cached data.
738  * If the cache is older than @max_age we will get a new value from the
739  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
740 static inline int obd_statfs_async(struct obd_device *obd,
741                                    struct obd_info *oinfo,
742                                    __u64 max_age,
743                                    struct ptlrpc_request_set *rqset)
744 {
745         int rc = 0;
746         ENTRY;
747
748         if (obd == NULL)
749                 RETURN(-EINVAL);
750
751         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
752         OBD_COUNTER_INCREMENT(obd, statfs);
753
754         CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
755                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
756         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
757                 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
758         } else {
759                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
760                        " objects "LPU64"/"LPU64"\n",
761                        obd->obd_name, &obd->obd_osfs,
762                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
763                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
764                 spin_lock(&obd->obd_osfs_lock);
765                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
766                 spin_unlock(&obd->obd_osfs_lock);
767                 if (oinfo->oi_cb_up)
768                         oinfo->oi_cb_up(oinfo, 0);
769         }
770         RETURN(rc);
771 }
772
773 static inline int obd_statfs_rqset(struct obd_device *obd,
774                                    struct obd_statfs *osfs, __u64 max_age)
775 {
776         struct ptlrpc_request_set *set = NULL;
777         struct obd_info oinfo = { { { 0 } } };
778         int rc = 0;
779         ENTRY;
780
781         set = ptlrpc_prep_set();
782         if (set == NULL)
783                 RETURN(-ENOMEM);
784
785         oinfo.oi_osfs = osfs;
786         rc = obd_statfs_async(obd, &oinfo, max_age, set);
787         if (rc == 0)
788                 rc = ptlrpc_set_wait(set);
789         ptlrpc_set_destroy(set);
790         RETURN(rc);
791 }
792
793 /* @max_age is the oldest time in jiffies that we accept using a cached data.
794  * If the cache is older than @max_age we will get a new value from the
795  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
796 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
797                              __u64 max_age)
798 {
799         int rc = 0;
800         ENTRY;
801
802         if (obd == NULL)
803                 RETURN(-EINVAL);
804
805         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
806         OBD_COUNTER_INCREMENT(obd, statfs);
807
808         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
809                obd->obd_osfs_age, max_age);
810         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
811                 rc = OBP(obd, statfs)(obd, osfs, max_age);
812                 if (rc == 0) {
813                         spin_lock(&obd->obd_osfs_lock);
814                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
815                         obd->obd_osfs_age = cfs_time_current_64();
816                         spin_unlock(&obd->obd_osfs_lock);
817                 }
818         } else {
819                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
820                        " objects "LPU64"/"LPU64"\n",
821                        obd->obd_name, &obd->obd_osfs,
822                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
823                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
824                 spin_lock(&obd->obd_osfs_lock);
825                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
826                 spin_unlock(&obd->obd_osfs_lock);
827         }
828         RETURN(rc);
829 }
830
831 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
832                            struct lov_stripe_md *ea, obd_size start,
833                            obd_size end)
834 {
835         int rc;
836         ENTRY;
837
838         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
839         EXP_COUNTER_INCREMENT(exp, sync);
840
841         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
842         RETURN(rc);
843 }
844
845 static inline int obd_punch_rqset(struct obd_export *exp,
846                                   struct obd_info *oinfo,
847                                   struct obd_trans_info *oti)
848 {
849         struct ptlrpc_request_set *set = NULL;
850         int rc;
851         ENTRY;
852
853         EXP_CHECK_OP(exp, punch);
854         EXP_COUNTER_INCREMENT(exp, punch);
855
856         set =  ptlrpc_prep_set();
857         if (set == NULL)
858                 RETURN(-ENOMEM);
859
860         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
861         if (rc == 0)
862                 rc = ptlrpc_set_wait(set);
863         ptlrpc_set_destroy(set);
864         RETURN(rc);
865 }
866
867 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
868                             struct obd_trans_info *oti,
869                             struct ptlrpc_request_set *rqset)
870 {
871         int rc;
872         ENTRY;
873
874         EXP_CHECK_OP(exp, punch);
875         EXP_COUNTER_INCREMENT(exp, punch);
876
877         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
878         RETURN(rc);
879 }
880
881 static inline int obd_brw(int cmd, struct obd_export *exp,
882                           struct obd_info *oinfo, obd_count oa_bufs,
883                           struct brw_page *pg, struct obd_trans_info *oti)
884 {
885         int rc;
886         ENTRY;
887
888         EXP_CHECK_OP(exp, brw);
889         EXP_COUNTER_INCREMENT(exp, brw);
890
891         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
892                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
893                        "or OBD_BRW_CHECK\n");
894                 LBUG();
895         }
896
897         rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
898         RETURN(rc);
899 }
900
901 static inline int obd_brw_async(int cmd, struct obd_export *exp,
902                                 struct obd_info *oinfo, obd_count oa_bufs,
903                                 struct brw_page *pg, struct obd_trans_info *oti,
904                                 struct ptlrpc_request_set *set)
905 {
906         int rc;
907         ENTRY;
908
909         EXP_CHECK_OP(exp, brw_async);
910         EXP_COUNTER_INCREMENT(exp, brw_async);
911
912         if (!(cmd & OBD_BRW_RWMASK)) {
913                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
914                 LBUG();
915         }
916
917         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
918         RETURN(rc);
919 }
920
921 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
922                                 struct obdo *oa, struct lov_stripe_md *lsm,
923                                 obd_count oa_bufs, struct brw_page *pg,
924                                 struct obd_trans_info *oti)
925 {
926         struct ptlrpc_request_set *set = NULL;
927         struct obd_info oinfo = { { { 0 } } };
928         int rc = 0;
929         ENTRY;
930
931         set =  ptlrpc_prep_set();
932         if (set == NULL)
933                 RETURN(-ENOMEM);
934
935         oinfo.oi_oa = oa;
936         oinfo.oi_md = lsm;
937         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
938         if (rc == 0) {
939                 rc = ptlrpc_set_wait(set);
940                 if (rc)
941                         CERROR("error from callback: rc = %d\n", rc);
942         } else {
943                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
944                        "error from obd_brw_async: rc = %d\n", rc);
945         }
946         ptlrpc_set_destroy(set);
947         RETURN(rc);
948 }
949
950 static inline  int obd_prep_async_page(struct obd_export *exp,
951                                        struct lov_stripe_md *lsm,
952                                        struct lov_oinfo *loi,
953                                        cfs_page_t *page, obd_off offset,
954                                        struct obd_async_page_ops *ops,
955                                        void *data, void **res, int nocache,
956                                        struct lustre_handle *lockh)
957 {
958         int ret;
959         ENTRY;
960
961         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
962         EXP_COUNTER_INCREMENT(exp, prep_async_page);
963
964         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
965                                                  ops, data, res, nocache,
966                                                  lockh);
967         RETURN(ret);
968 }
969
970 static inline int obd_queue_async_io(struct obd_export *exp,
971                                      struct lov_stripe_md *lsm,
972                                      struct lov_oinfo *loi, void *cookie,
973                                      int cmd, obd_off off, int count,
974                                      obd_flag brw_flags, obd_flag async_flags)
975 {
976         int rc;
977         ENTRY;
978
979         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
980         EXP_COUNTER_INCREMENT(exp, queue_async_io);
981         LASSERT(cmd & OBD_BRW_RWMASK);
982
983         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
984                                                count, brw_flags, async_flags);
985         RETURN(rc);
986 }
987
988 static inline int obd_set_async_flags(struct obd_export *exp,
989                                       struct lov_stripe_md *lsm,
990                                       struct lov_oinfo *loi, void *cookie,
991                                       obd_flag async_flags)
992 {
993         int rc;
994         ENTRY;
995
996         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
997         EXP_COUNTER_INCREMENT(exp, set_async_flags);
998
999         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1000                                                 async_flags);
1001         RETURN(rc);
1002 }
1003
1004 static inline int obd_queue_group_io(struct obd_export *exp,
1005                                      struct lov_stripe_md *lsm,
1006                                      struct lov_oinfo *loi,
1007                                      struct obd_io_group *oig,
1008                                      void *cookie, int cmd, obd_off off,
1009                                      int count, obd_flag brw_flags,
1010                                      obd_flag async_flags)
1011 {
1012         int rc;
1013         ENTRY;
1014
1015         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1016         EXP_COUNTER_INCREMENT(exp, queue_group_io);
1017         LASSERT(cmd & OBD_BRW_RWMASK);
1018
1019         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1020                                                cmd, off, count, brw_flags,
1021                                                async_flags);
1022         RETURN(rc);
1023 }
1024
1025 static inline int obd_trigger_group_io(struct obd_export *exp,
1026                                        struct lov_stripe_md *lsm,
1027                                        struct lov_oinfo *loi,
1028                                        struct obd_io_group *oig)
1029 {
1030         int rc;
1031         ENTRY;
1032
1033         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1034         EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1035
1036         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1037         RETURN(rc);
1038 }
1039
1040 static inline int obd_teardown_async_page(struct obd_export *exp,
1041                                           struct lov_stripe_md *lsm,
1042                                           struct lov_oinfo *loi, void *cookie)
1043 {
1044         int rc;
1045         ENTRY;
1046
1047         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1048         EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1049
1050         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1051         RETURN(rc);
1052 }
1053
1054 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1055                              int objcount, struct obd_ioobj *obj,
1056                              int niocount, struct niobuf_remote *remote,
1057                              struct niobuf_local *local,
1058                              struct obd_trans_info *oti)
1059 {
1060         int rc;
1061         ENTRY;
1062
1063         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1064         EXP_COUNTER_INCREMENT(exp, preprw);
1065
1066         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1067                                        remote, local, oti);
1068         RETURN(rc);
1069 }
1070
1071 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1072                                int objcount, struct obd_ioobj *obj,
1073                                int niocount, struct niobuf_local *local,
1074                                struct obd_trans_info *oti, int rc)
1075 {
1076         ENTRY;
1077
1078         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1079         EXP_COUNTER_INCREMENT(exp, commitrw);
1080
1081         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1082                                          local, oti, rc);
1083         RETURN(rc);
1084 }
1085
1086 static inline int obd_merge_lvb(struct obd_export *exp,
1087                                 struct lov_stripe_md *lsm,
1088                                 struct ost_lvb *lvb, int kms_only)
1089 {
1090         int rc;
1091         ENTRY;
1092
1093         OBD_CHECK_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1094         EXP_COUNTER_INCREMENT(exp, merge_lvb);
1095
1096         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1097         RETURN(rc);
1098 }
1099
1100 static inline int obd_adjust_kms(struct obd_export *exp,
1101                                  struct lov_stripe_md *lsm, obd_off size,
1102                                  int shrink)
1103 {
1104         int rc;
1105         ENTRY;
1106
1107         OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1108         EXP_COUNTER_INCREMENT(exp, adjust_kms);
1109
1110         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1111         RETURN(rc);
1112 }
1113
1114 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1115                                 int len, void *karg, void *uarg)
1116 {
1117         int rc;
1118         ENTRY;
1119
1120         EXP_CHECK_OP(exp, iocontrol);
1121         EXP_COUNTER_INCREMENT(exp, iocontrol);
1122
1123         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1124         RETURN(rc);
1125 }
1126
1127 static inline int obd_enqueue_rqset(struct obd_export *exp,
1128                                     struct obd_info *oinfo,
1129                                     struct ldlm_enqueue_info *einfo)
1130 {
1131         struct ptlrpc_request_set *set = NULL;
1132         int rc;
1133         ENTRY;
1134
1135         EXP_CHECK_OP(exp, enqueue);
1136         EXP_COUNTER_INCREMENT(exp, enqueue);
1137
1138         set =  ptlrpc_prep_set();
1139         if (set == NULL)
1140                 RETURN(-ENOMEM);
1141
1142         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1143         if (rc == 0)
1144                 rc = ptlrpc_set_wait(set);
1145         ptlrpc_set_destroy(set);
1146         RETURN(rc);
1147 }
1148
1149 static inline int obd_enqueue(struct obd_export *exp,
1150                               struct obd_info *oinfo,
1151                               struct ldlm_enqueue_info *einfo,
1152                               struct ptlrpc_request_set *set)
1153 {
1154         int rc;
1155         ENTRY;
1156
1157         EXP_CHECK_OP(exp, enqueue);
1158         EXP_COUNTER_INCREMENT(exp, enqueue);
1159
1160         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1161         RETURN(rc);
1162 }
1163
1164 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1165                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1166                             int *flags, void *data, struct lustre_handle *lockh)
1167 {
1168         int rc;
1169         ENTRY;
1170
1171         EXP_CHECK_OP(exp, match);
1172         EXP_COUNTER_INCREMENT(exp, match);
1173
1174         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1175                                       lockh);
1176         RETURN(rc);
1177 }
1178
1179 static inline int obd_change_cbdata(struct obd_export *exp,
1180                                     struct lov_stripe_md *lsm,
1181                                     ldlm_iterator_t it, void *data)
1182 {
1183         int rc;
1184         ENTRY;
1185
1186         EXP_CHECK_OP(exp, change_cbdata);
1187         EXP_COUNTER_INCREMENT(exp, change_cbdata);
1188
1189         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1190         RETURN(rc);
1191 }
1192
1193 static inline int obd_cancel(struct obd_export *exp,
1194                              struct lov_stripe_md *ea, __u32 mode,
1195                              struct lustre_handle *lockh)
1196 {
1197         int rc;
1198         ENTRY;
1199
1200         EXP_CHECK_OP(exp, cancel);
1201         EXP_COUNTER_INCREMENT(exp, cancel);
1202
1203         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1204         RETURN(rc);
1205 }
1206
1207 static inline int obd_cancel_unused(struct obd_export *exp,
1208                                     struct lov_stripe_md *ea, int flags,
1209                                     void *opaque)
1210 {
1211         int rc;
1212         ENTRY;
1213
1214         EXP_CHECK_OP(exp, cancel_unused);
1215         EXP_COUNTER_INCREMENT(exp, cancel_unused);
1216
1217         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1218         RETURN(rc);
1219 }
1220
1221 static inline int obd_join_lru(struct obd_export *exp,
1222                                struct lov_stripe_md *ea, int join)
1223 {
1224         int rc;
1225         ENTRY;
1226
1227         EXP_CHECK_OP(exp, join_lru);
1228         EXP_COUNTER_INCREMENT(exp, join_lru);
1229
1230         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1231         RETURN(rc);
1232 }
1233
1234 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1235                           int type, struct obd_client_handle *handle, int flag)
1236 {
1237         int rc;
1238         ENTRY;
1239
1240         EXP_CHECK_OP(exp, pin);
1241         EXP_COUNTER_INCREMENT(exp, pin);
1242
1243         rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1244         RETURN(rc);
1245 }
1246
1247 static inline int obd_unpin(struct obd_export *exp,
1248                             struct obd_client_handle *handle, int flag)
1249 {
1250         int rc;
1251         ENTRY;
1252
1253         EXP_CHECK_OP(exp, unpin);
1254         EXP_COUNTER_INCREMENT(exp, unpin);
1255
1256         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1257         RETURN(rc);
1258 }
1259
1260
1261 static inline void obd_import_event(struct obd_device *obd,
1262                                     struct obd_import *imp,
1263                                     enum obd_import_event event)
1264 {
1265         ENTRY;
1266         if (!obd) {
1267                 CERROR("NULL device\n");
1268                 EXIT;
1269                 return;
1270         }
1271         if (obd->obd_set_up && OBP(obd, import_event)) {
1272                 OBD_COUNTER_INCREMENT(obd, import_event);
1273                 OBP(obd, import_event)(obd, imp, event);
1274         }
1275         EXIT;
1276 }
1277
1278 static inline int obd_notify(struct obd_device *obd,
1279                              struct obd_device *watched,
1280                              enum obd_notify_event ev, void *data)
1281 {
1282         ENTRY;
1283         OBD_CHECK_DEV(obd);
1284
1285         /* the check for async_recov is a complete hack - I'm hereby
1286            overloading the meaning to also mean "this was called from
1287            mds_postsetup".  I know that my mds is able to handle notifies
1288            by this point, and it needs to get them to execute mds_postrecov. */                                                                                
1289         if (!obd->obd_set_up && !obd->obd_async_recov) {
1290                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1291                 RETURN(-EINVAL);
1292         }
1293
1294         if (!OBP(obd, notify)) 
1295                 RETURN(-ENOSYS);
1296
1297         OBD_COUNTER_INCREMENT(obd, notify);
1298         RETURN(OBP(obd, notify)(obd, watched, ev, data));
1299 }
1300
1301 static inline int obd_notify_observer(struct obd_device *observer,
1302                                       struct obd_device *observed,
1303                                       enum obd_notify_event ev, void *data)
1304 {
1305         int rc1;
1306         int rc2;
1307
1308         struct obd_notify_upcall *onu;
1309
1310         if (observer->obd_observer)
1311                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1312         else
1313                 rc1 = 0;
1314         /*
1315          * Also, call non-obd listener, if any
1316          */
1317         onu = &observer->obd_upcall;
1318         if (onu->onu_upcall != NULL)
1319                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1320         else
1321                 rc2 = 0;
1322
1323         return rc1 ?: rc2;
1324  }
1325
1326 static inline int obd_quotacheck(struct obd_export *exp,
1327                                  struct obd_quotactl *oqctl)
1328 {
1329         int rc;
1330         ENTRY;
1331
1332         EXP_CHECK_OP(exp, quotacheck);
1333         EXP_COUNTER_INCREMENT(exp, quotacheck);
1334
1335         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1336         RETURN(rc);
1337 }
1338
1339 static inline int obd_quotactl(struct obd_export *exp,
1340                                struct obd_quotactl *oqctl)
1341 {
1342         int rc;
1343         ENTRY;
1344
1345         EXP_CHECK_OP(exp, quotactl);
1346         EXP_COUNTER_INCREMENT(exp, quotactl);
1347
1348         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1349         RETURN(rc);
1350 }
1351
1352 static inline int obd_health_check(struct obd_device *obd)
1353 {
1354         /* returns: 0 on healthy
1355          *         >0 on unhealthy + reason code/flag
1356          *            however the only suppored reason == 1 right now
1357          *            We'll need to define some better reasons
1358          *            or flags in the future.
1359          *         <0 on error
1360          */
1361         int rc;
1362         ENTRY;
1363
1364         /* don't use EXP_CHECK_OP, because NULL method is normal here */
1365         if (obd == NULL || !OBT(obd)) {
1366                 CERROR("cleaned up obd\n");
1367                 RETURN(-EOPNOTSUPP);
1368         }
1369         if (!obd->obd_set_up || obd->obd_stopping)
1370                 RETURN(0);
1371         if (!OBP(obd, health_check))
1372                 RETURN(0);
1373
1374         rc = OBP(obd, health_check)(obd);
1375         RETURN(rc);
1376 }
1377
1378 static inline int obd_register_observer(struct obd_device *obd,
1379                                         struct obd_device *observer)
1380 {
1381         ENTRY;
1382         OBD_CHECK_DEV(obd);
1383         if (obd->obd_observer && observer)
1384                 RETURN(-EALREADY);
1385         obd->obd_observer = observer;
1386         RETURN(0);
1387 }
1388
1389 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1390                                                obd_page_removal_cb_t cb,
1391                                                obd_pin_extent_cb pin_cb)
1392 {
1393         int rc;
1394         ENTRY;
1395
1396         OBD_CHECK_OP(exp->exp_obd, register_page_removal_cb, 0);
1397         OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1398
1399         rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1400         RETURN(rc);
1401 }
1402
1403 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1404                                                  obd_page_removal_cb_t cb)
1405 {
1406         int rc;
1407         ENTRY;
1408
1409         OBD_CHECK_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1410         OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1411
1412         rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1413         RETURN(rc);
1414 }
1415
1416 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1417                                               obd_lock_cancel_cb cb)
1418 {
1419         int rc;
1420         ENTRY;
1421
1422         OBD_CHECK_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1423         OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1424
1425         rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1426         RETURN(rc);
1427 }
1428
1429 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1430                                                  obd_lock_cancel_cb cb)
1431 {
1432         int rc;
1433         ENTRY;
1434
1435         OBD_CHECK_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1436         OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1437
1438         rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1439         RETURN(rc);
1440 }
1441
1442 /* OBD Metadata Support */
1443
1444 extern int obd_init_caches(void);
1445 extern void obd_cleanup_caches(void);
1446
1447 /* support routines */
1448 extern cfs_mem_cache_t *obdo_cachep;
1449
1450 #define OBDO_ALLOC(ptr)                                                       \
1451 do {                                                                          \
1452         OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep);                               \
1453 } while(0)
1454
1455 #define OBDO_FREE(ptr)                                                        \
1456 do {                                                                          \
1457         OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
1458 } while(0)
1459
1460 /* I'm as embarrassed about this as you are.
1461  *
1462  * <shaver> // XXX do not look into _superhack with remaining eye
1463  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1464 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1465
1466 /* sysctl.c */
1467 extern void obd_sysctl_init (void);
1468 extern void obd_sysctl_clean (void);
1469
1470 /* uuid.c  */
1471 typedef __u8 class_uuid_t[16];
1472 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1473
1474 /* lustre_peer.c    */
1475 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index);
1476 int class_add_uuid(char *uuid, __u64 nid);
1477 int class_del_uuid (char *uuid);
1478 void class_init_uuidlist(void);
1479 void class_exit_uuidlist(void);
1480
1481 /* prng.c */
1482 void ll_generate_random_uuid(class_uuid_t uuid_out);
1483
1484 #endif /* __LINUX_OBD_CLASS_H */