Whamcloud - gitweb
b=20433 decrease the usage of memory on clients.
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __CLASS_OBD_H
38 #define __CLASS_OBD_H
39
40 #include <obd_support.h>
41 #include <lustre_import.h>
42 #include <lustre_net.h>
43 #include <obd.h>
44 #include <lustre_lib.h>
45 #include <lustre/lustre_idl.h>
46 #include <lprocfs_status.h>
47
48 #if defined(__linux__)
49 #include <linux/obd_class.h>
50 #elif defined(__APPLE__)
51 #include <darwin/obd_class.h>
52 #elif defined(__WINNT__)
53 #include <winnt/obd_class.h>
54 #else
55 #error Unsupported operating system.
56 #endif
57
58 /* OBD Device Declarations */
59 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
60 extern spinlock_t obd_dev_lock;
61 extern cfs_mem_cache_t *obd_lvfs_ctxt_cache;
62
63 /* OBD Operations Declarations */
64 extern struct obd_device *class_conn2obd(struct lustre_handle *);
65 extern struct obd_device *class_exp2obd(struct obd_export *);
66 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
67
68 /* genops.c */
69 struct obd_export *class_conn2export(struct lustre_handle *);
70 int class_register_type(struct obd_ops *ops, struct lprocfs_vars *,
71                         const char *nm);
72 int class_unregister_type(const char *nm);
73
74 struct obd_device *class_newdev(const char *type_name, const char *name);
75 void class_release_dev(struct obd_device *obd);
76
77 int class_name2dev(const char *name);
78 struct obd_device *class_name2obd(const char *name);
79 int class_uuid2dev(struct obd_uuid *uuid);
80 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
81 void class_obd_list(void);
82 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
83                                           const char * typ_name,
84                                           struct obd_uuid *grp_uuid);
85 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
86                                              struct obd_uuid *grp_uuid);
87 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
88                                            int *next);
89 struct obd_device * class_num2obd(int num);
90
91 int oig_init(struct obd_io_group **oig);
92 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
93 void oig_complete_one(struct obd_io_group *oig,
94                       struct oig_callback_context *occ, int rc);
95 void oig_release(struct obd_io_group *oig);
96 int oig_wait(struct obd_io_group *oig);
97
98 char *obd_export_nid2str(struct obd_export *exp);
99
100 int obd_export_evict_by_nid(struct obd_device *obd, char *nid);
101 int obd_export_evict_by_uuid(struct obd_device *obd, char *uuid);
102
103 int obd_zombie_impexp_init(void);
104 void obd_zombie_impexp_stop(void);
105 void obd_zombie_impexp_cull(void);
106 void obd_zombie_barrier(void);
107
108 /* obd_config.c */
109 int class_process_config(struct lustre_cfg *lcfg);
110 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
111                              struct lustre_cfg *lcfg, void *data);
112 int class_attach(struct lustre_cfg *lcfg);
113 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
114 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
115 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
116 struct obd_device *class_incref(struct obd_device *obd);
117 void class_decref(struct obd_device *obd);
118
119 /*obdecho*/
120 #ifdef LPROCFS
121 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
122 #else
123 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
124 {
125         memset(lvars, 0, sizeof(*lvars));
126 }
127 #endif
128
129 #define CFG_F_START     0x01   /* Set when we start updating from a log */
130 #define CFG_F_MARKER    0x02   /* We are within a maker */
131 #define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
132 #define CFG_F_COMPAT146 0x08   /* Allow old-style logs */
133 #define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
134
135 /* Passed as data param to class_config_parse_llog */
136 struct config_llog_instance {
137         char *              cfg_instance;
138         struct super_block *cfg_sb;
139         struct obd_uuid     cfg_uuid;
140         int                 cfg_last_idx; /* for partial llog processing */
141         int                 cfg_flags;
142 };
143 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
144                             struct config_llog_instance *cfg);
145 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
146                            struct config_llog_instance *cfg);
147
148 /* list of active configuration logs  */
149 struct config_llog_data {
150         char               *cld_logname;
151         struct ldlm_res_id  cld_resid;
152         struct config_llog_instance cld_cfg;
153         struct list_head    cld_list_chain;
154         atomic_t            cld_refcount;
155         struct obd_export  *cld_mgcexp;
156         unsigned int        cld_stopping:1; /* we were told to stop watching */
157         unsigned int        cld_lostlock:1; /* lock not requeued */
158         struct semaphore    cld_sem; /* for exclusive processing of the log */
159 };
160
161 struct lustre_profile {
162         struct list_head lp_list;
163         char * lp_profile;
164         char * lp_osc;
165         char * lp_mdc;
166 };
167
168 struct lustre_profile *class_get_profile(char * prof);
169 void class_del_profile(char *prof);
170 void class_del_profiles(void);
171
172 #define class_export_rpc_get(exp)                                       \
173 ({                                                                      \
174         atomic_inc(&(exp)->exp_rpc_count);                              \
175         CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",    \
176                (exp), atomic_read(&(exp)->exp_rpc_count));              \
177         class_export_get(exp);                                          \
178 })
179
180 #define class_export_rpc_put(exp)                                       \
181 ({                                                                      \
182         atomic_dec(&(exp)->exp_rpc_count);                              \
183         CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",    \
184                (exp), atomic_read(&(exp)->exp_rpc_count));              \
185         class_export_put(exp);                                          \
186 })
187
188 /* genops.c */
189 #define class_export_get(exp)                                                  \
190 ({                                                                             \
191         struct obd_export *exp_ = exp;                                         \
192         atomic_inc(&exp_->exp_refcount);                                       \
193         CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_,          \
194                atomic_read(&exp_->exp_refcount));                              \
195         exp_;                                                                  \
196 })
197
198 /* class_export_put() is non-blocking */
199 #define class_export_put(exp)                                                  \
200 do {                                                                           \
201         LASSERT((exp) != NULL);                                                \
202         CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp),         \
203                atomic_read(&(exp)->exp_refcount) - 1);                         \
204         LASSERT(atomic_read(&(exp)->exp_refcount) > 0);                        \
205         LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a);                 \
206         __class_export_put(exp);                                               \
207 } while (0)
208
209 void __class_export_put(struct obd_export *);
210 struct obd_export *class_new_export(struct obd_device *obddev,
211                                     struct obd_uuid *cluuid);
212 void class_unlink_export(struct obd_export *exp);
213
214 struct obd_import *class_import_get(struct obd_import *);
215 void class_import_put(struct obd_import *);
216 struct obd_import *class_new_import(struct obd_device *obd);
217 void class_destroy_import(struct obd_import *exp);
218
219 struct obd_type *class_search_type(const char *name);
220 struct obd_type *class_get_type(const char *name);
221 void class_put_type(struct obd_type *type);
222 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
223                   struct obd_uuid *cluuid);
224 int class_disconnect(struct obd_export *exp);
225 void class_fail_export(struct obd_export *exp);
226 int class_connected_export(struct obd_export *exp);
227 void class_disconnect_exports(struct obd_device *obddev);
228 void class_set_export_delayed(struct obd_export *exp);
229 void class_handle_stale_exports(struct obd_device *obddev);
230 void class_disconnect_expired_exports(struct obd_device *obd);
231 void class_disconnect_stale_exports(struct obd_device *obddev,
232                                     enum obd_option flags);
233 int class_stale_export_list(struct obd_device *obd, struct obd_ioctl_data *data);
234 int class_manual_cleanup(struct obd_device *obd);
235
236 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
237 {
238         return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
239                 (obd->obd_force ? OBD_OPT_FORCE : 0) |
240                 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
241                 0);
242 }
243
244 /* obdo.c */
245 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
246 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
247
248
249 #define OBT(dev)        (dev)->obd_type
250 #define OBP(dev, op)    (dev)->obd_type->typ_ops->o_ ## op
251 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
252
253 /* Ensure obd_setup: used for cleanup which must be called
254    while obd is stopping */
255 #define OBD_CHECK_DEV(obd)                                      \
256 do {                                                            \
257         if (!(obd)) {                                           \
258                 CERROR("NULL device\n");                        \
259                 RETURN(-ENODEV);                                \
260         }                                                       \
261 } while (0)
262
263 /* ensure obd_setup and !obd_stopping */
264 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
265 do {                                                            \
266         OBD_CHECK_DEV(obd);                                     \
267         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
268                 CERROR("Device %d not setup\n",                 \
269                        (obd)->obd_minor);                       \
270                 RETURN(-ENODEV);                                \
271         }                                                       \
272 } while (0)
273
274
275 #ifdef LPROCFS
276 #define OBD_COUNTER_OFFSET(op)                                  \
277         ((offsetof(struct obd_ops, o_ ## op) -                  \
278           offsetof(struct obd_ops, o_iocontrol))                \
279          / sizeof(((struct obd_ops *)(0))->o_iocontrol))
280
281 #define OBD_COUNTER_INCREMENT(obdx, op)                           \
282         if ((obdx)->obd_stats != NULL) {                          \
283                 unsigned int coffset;                             \
284                 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
285                         OBD_COUNTER_OFFSET(op);                   \
286                 LASSERT(coffset < (obdx)->obd_stats->ls_num);     \
287                 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
288         }
289
290 #define EXP_COUNTER_INCREMENT(export, op)                                    \
291         if ((export)->exp_obd->obd_stats != NULL) {                          \
292                 unsigned int coffset;                                        \
293                 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
294                         OBD_COUNTER_OFFSET(op);                              \
295                 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num);     \
296                 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
297                 if ((export)->exp_nid_stats != NULL &&                       \
298                     (export)->exp_nid_stats->nid_stats != NULL)              \
299                         lprocfs_counter_incr(                                \
300                                 (export)->exp_nid_stats->nid_stats, coffset);\
301         }
302
303 #else
304 #define OBD_COUNTER_OFFSET(op)
305 #define OBD_COUNTER_INCREMENT(obd, op)
306 #define EXP_COUNTER_INCREMENT(exp, op);
307 #endif
308
309 #define OBD_CHECK_OP(obd, op, err)                              \
310 do {                                                            \
311         if (!OBT(obd) || !OBP((obd), op)) {\
312                 if (err)                                        \
313                         CERROR("obd_" #op ": dev %d no operation\n",    \
314                                obd->obd_minor);                         \
315                 RETURN(err);                                    \
316         }                                                       \
317 } while (0)
318
319 #define EXP_CHECK_OP(exp, op)                                   \
320 do {                                                            \
321         if ((exp) == NULL) {                                    \
322                 CERROR("obd_" #op ": NULL export\n");           \
323                 RETURN(-ENODEV);                                \
324         }                                                       \
325         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
326                 CERROR("obd_" #op ": cleaned up obd\n");        \
327                 RETURN(-EOPNOTSUPP);                            \
328         }                                                       \
329         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
330                 CERROR("obd_" #op ": dev %d no operation\n",    \
331                        (exp)->exp_obd->obd_minor);              \
332                 RETURN(-EOPNOTSUPP);                            \
333         }                                                       \
334 } while (0)
335
336 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
337 do {                                                            \
338         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
339                 if (err)                                        \
340                         CERROR("lop_" #op ": dev %d no operation\n",    \
341                                ctxt->loc_obd->obd_minor);                         \
342                 RETURN(err);                                    \
343         }                                                       \
344 } while (0)
345
346 static inline int class_devno_max(void)
347 {
348         return MAX_OBD_DEVICES;
349 }
350
351 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
352                                void *key, __u32 *vallen, void *val,
353                                struct lov_stripe_md *lsm)
354 {
355         int rc;
356         ENTRY;
357
358         EXP_CHECK_OP(exp, get_info);
359         EXP_COUNTER_INCREMENT(exp, get_info);
360
361         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
362         RETURN(rc);
363 }
364
365 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
366                                      void *key, obd_count vallen, void *val,
367                                      struct ptlrpc_request_set *set)
368 {
369         int rc;
370         ENTRY;
371
372         EXP_CHECK_OP(exp, set_info_async);
373         EXP_COUNTER_INCREMENT(exp, set_info_async);
374
375         rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
376                                                set);
377         RETURN(rc);
378 }
379
380 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
381 {
382         int rc;
383         ENTRY;
384
385         OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
386         OBD_COUNTER_INCREMENT(obd, setup);
387
388         rc = OBP(obd, setup)(obd, datalen, data);
389         RETURN(rc);
390 }
391
392 static inline int obd_precleanup(struct obd_device *obd,
393                                  enum obd_cleanup_stage cleanup_stage)
394 {
395         int rc;
396         ENTRY;
397
398         OBD_CHECK_OP(obd, precleanup, 0);
399         OBD_COUNTER_INCREMENT(obd, precleanup);
400
401         rc = OBP(obd, precleanup)(obd, cleanup_stage);
402         RETURN(rc);
403 }
404
405 static inline int obd_cleanup(struct obd_device *obd)
406 {
407         int rc;
408         ENTRY;
409
410         OBD_CHECK_DEV(obd);
411         OBD_CHECK_OP(obd, cleanup, 0);
412         OBD_COUNTER_INCREMENT(obd, cleanup);
413
414         rc = OBP(obd, cleanup)(obd);
415         RETURN(rc);
416 }
417
418 static inline int
419 obd_process_config(struct obd_device *obd, int datalen, void *data)
420 {
421         int rc;
422         ENTRY;
423
424         OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
425         OBD_COUNTER_INCREMENT(obd, process_config);
426
427         rc = OBP(obd, process_config)(obd, datalen, data);
428         RETURN(rc);
429 }
430
431 /* Pack an in-memory MD struct for storage on disk.
432  * Returns +ve size of packed MD (0 for free), or -ve error.
433  *
434  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
435  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
436  * If @*disk_tgt == NULL, it will be allocated
437  */
438 static inline int obd_packmd(struct obd_export *exp,
439                              struct lov_mds_md **disk_tgt,
440                              struct lov_stripe_md *mem_src)
441 {
442         int rc;
443         ENTRY;
444
445         EXP_CHECK_OP(exp, packmd);
446         EXP_COUNTER_INCREMENT(exp, packmd);
447
448         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
449         RETURN(rc);
450 }
451
452 static inline int obd_size_diskmd(struct obd_export *exp,
453                                   struct lov_stripe_md *mem_src)
454 {
455         return obd_packmd(exp, NULL, mem_src);
456 }
457
458 /* helper functions */
459 static inline int obd_alloc_diskmd(struct obd_export *exp,
460                                    struct lov_mds_md **disk_tgt)
461 {
462         LASSERT(disk_tgt);
463         LASSERT(*disk_tgt == NULL);
464         return obd_packmd(exp, disk_tgt, NULL);
465 }
466
467 static inline int obd_free_diskmd(struct obd_export *exp,
468                                   struct lov_mds_md **disk_tgt)
469 {
470         LASSERT(disk_tgt);
471         LASSERT(*disk_tgt);
472         return obd_packmd(exp, disk_tgt, NULL);
473 }
474
475 /* Unpack an MD struct from disk to in-memory format.
476  * Returns +ve size of unpacked MD (0 for free), or -ve error.
477  *
478  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
479  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
480  * If @*mem_tgt == NULL, it will be allocated
481  */
482 static inline int obd_unpackmd(struct obd_export *exp,
483                                struct lov_stripe_md **mem_tgt,
484                                struct lov_mds_md *disk_src,
485                                int disk_len)
486 {
487         int rc;
488         ENTRY;
489
490         EXP_CHECK_OP(exp, unpackmd);
491         EXP_COUNTER_INCREMENT(exp, unpackmd);
492
493         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
494         RETURN(rc);
495 }
496
497 /* helper functions */
498 static inline int obd_alloc_memmd(struct obd_export *exp,
499                                   struct lov_stripe_md **mem_tgt)
500 {
501         LASSERT(mem_tgt);
502         LASSERT(*mem_tgt == NULL);
503         return obd_unpackmd(exp, mem_tgt, NULL, 0);
504 }
505
506 static inline int obd_free_memmd(struct obd_export *exp,
507                                  struct lov_stripe_md **mem_tgt)
508 {
509         LASSERT(mem_tgt);
510         LASSERT(*mem_tgt);
511         return obd_unpackmd(exp, mem_tgt, NULL, 0);
512 }
513
514 static inline int obd_checkmd(struct obd_export *exp,
515                               struct obd_export *md_exp,
516                               struct lov_stripe_md *mem_tgt)
517 {
518         int rc;
519         ENTRY;
520
521         EXP_CHECK_OP(exp, checkmd);
522         EXP_COUNTER_INCREMENT(exp, checkmd);
523
524         rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
525         RETURN(rc);
526 }
527
528 static inline int obd_precreate(struct obd_export *exp)
529 {
530         int rc;
531         ENTRY;
532
533         EXP_CHECK_OP(exp, precreate);
534         OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
535
536         rc = OBP(exp->exp_obd, precreate)(exp);
537         RETURN(rc);
538 }
539
540 static inline int obd_create_async(struct obd_export *exp,
541                                    struct obd_info *oinfo,
542                                    struct lov_stripe_md **ea,
543                                    struct obd_trans_info *oti)
544 {
545         int rc;
546         ENTRY;
547
548         EXP_CHECK_OP(exp, create_async);
549         EXP_COUNTER_INCREMENT(exp, create_async);
550
551         rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
552         RETURN(rc);
553 }
554
555 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
556                              struct lov_stripe_md **ea,
557                              struct obd_trans_info *oti)
558 {
559         int rc;
560         ENTRY;
561
562         EXP_CHECK_OP(exp, create);
563         EXP_COUNTER_INCREMENT(exp, create);
564
565         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
566         RETURN(rc);
567 }
568
569 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
570                               struct lov_stripe_md *ea,
571                               struct obd_trans_info *oti,
572                               struct obd_export *md_exp)
573 {
574         int rc;
575         ENTRY;
576
577         EXP_CHECK_OP(exp, destroy);
578         EXP_COUNTER_INCREMENT(exp, destroy);
579
580         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
581         RETURN(rc);
582 }
583
584 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
585 {
586         int rc;
587         ENTRY;
588
589         EXP_CHECK_OP(exp, getattr);
590         EXP_COUNTER_INCREMENT(exp, getattr);
591
592         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
593         RETURN(rc);
594 }
595
596 static inline int obd_getattr_async(struct obd_export *exp,
597                                     struct obd_info *oinfo,
598                                     struct ptlrpc_request_set *set)
599 {
600         int rc;
601         ENTRY;
602
603         EXP_CHECK_OP(exp, getattr_async);
604         EXP_COUNTER_INCREMENT(exp, getattr_async);
605
606         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
607         RETURN(rc);
608 }
609
610 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
611                               struct obd_trans_info *oti)
612 {
613         int rc;
614         ENTRY;
615
616         EXP_CHECK_OP(exp, setattr);
617         EXP_COUNTER_INCREMENT(exp, setattr);
618
619         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
620         RETURN(rc);
621 }
622
623 /* This performs all the requests set init/wait/destroy actions. */
624 static inline int obd_setattr_rqset(struct obd_export *exp,
625                                     struct obd_info *oinfo,
626                                     struct obd_trans_info *oti)
627 {
628         struct ptlrpc_request_set *set = NULL;
629         int rc;
630         ENTRY;
631
632         EXP_CHECK_OP(exp, setattr_async);
633         EXP_COUNTER_INCREMENT(exp, setattr_async);
634
635         set =  ptlrpc_prep_set();
636         if (set == NULL)
637                 RETURN(-ENOMEM);
638
639         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
640         if (rc == 0)
641                 rc = ptlrpc_set_wait(set);
642         ptlrpc_set_destroy(set);
643         RETURN(rc);
644 }
645
646 /* This adds all the requests into @set if @set != NULL, otherwise
647    all requests are sent asynchronously without waiting for response. */
648 static inline int obd_setattr_async(struct obd_export *exp,
649                                     struct obd_info *oinfo,
650                                     struct obd_trans_info *oti,
651                                     struct ptlrpc_request_set *set)
652 {
653         int rc;
654         ENTRY;
655
656         EXP_CHECK_OP(exp, setattr_async);
657         EXP_COUNTER_INCREMENT(exp, setattr_async);
658
659         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
660         RETURN(rc);
661 }
662
663 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
664                                int priority)
665 {
666         struct obd_device *obd = imp->imp_obd;
667         int rc;
668         ENTRY;
669
670         OBD_CHECK_DEV_ACTIVE(obd);
671         OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
672         OBD_COUNTER_INCREMENT(obd, add_conn);
673
674         rc = OBP(obd, add_conn)(imp, uuid, priority);
675         RETURN(rc);
676 }
677
678 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
679 {
680         struct obd_device *obd = imp->imp_obd;
681         int rc;
682         ENTRY;
683
684         OBD_CHECK_DEV_ACTIVE(obd);
685         OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
686         OBD_COUNTER_INCREMENT(obd, del_conn);
687
688         rc = OBP(obd, del_conn)(imp, uuid);
689         RETURN(rc);
690 }
691
692 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
693                               struct obd_uuid *cluuid,
694                               struct obd_connect_data *d,
695                               void *localdata)
696 {
697         int rc;
698         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
699         ENTRY;
700
701         OBD_CHECK_DEV_ACTIVE(obd);
702         OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
703         OBD_COUNTER_INCREMENT(obd, connect);
704
705         rc = OBP(obd, connect)(conn, obd, cluuid, d, localdata);
706         /* check that only subset is granted */
707         LASSERT(ergo(d != NULL,
708                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
709         RETURN(rc);
710 }
711
712 static inline int obd_reconnect(struct obd_export *exp,
713                                 struct obd_device *obd,
714                                 struct obd_uuid *cluuid,
715                                 struct obd_connect_data *d,
716                                 void *localdata)
717 {
718         int rc;
719         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
720         ENTRY;
721
722         OBD_CHECK_DEV_ACTIVE(obd);
723         OBD_CHECK_OP(obd, reconnect, 0);
724         OBD_COUNTER_INCREMENT(obd, reconnect);
725
726         rc = OBP(obd, reconnect)(exp, obd, cluuid, d, localdata);
727         /* check that only subset is granted */
728         LASSERT(ergo(d != NULL,
729                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
730         RETURN(rc);
731 }
732
733 static inline int obd_disconnect(struct obd_export *exp)
734 {
735         int rc;
736         ENTRY;
737
738         EXP_CHECK_OP(exp, disconnect);
739         EXP_COUNTER_INCREMENT(exp, disconnect);
740
741         rc = OBP(exp->exp_obd, disconnect)(exp);
742         RETURN(rc);
743 }
744
745 static inline int obd_fid_init(struct obd_export *exp)
746 {
747         int rc;
748         ENTRY;
749
750         OBD_CHECK_OP(exp->exp_obd, fid_init, 0);
751         EXP_COUNTER_INCREMENT(exp, fid_init);
752
753         rc = OBP(exp->exp_obd, fid_init)(exp);
754         RETURN(rc);
755 }
756
757 static inline int obd_fid_fini(struct obd_export *exp)
758 {
759         int rc;
760         ENTRY;
761
762         OBD_CHECK_OP(exp->exp_obd, fid_fini, 0);
763         EXP_COUNTER_INCREMENT(exp, fid_fini);
764
765         rc = OBP(exp->exp_obd, fid_fini)(exp);
766         RETURN(rc);
767 }
768
769 static inline int obd_ping(struct obd_export *exp)
770 {
771         int rc;
772         ENTRY;
773
774         OBD_CHECK_OP(exp->exp_obd, ping, 0);
775         EXP_COUNTER_INCREMENT(exp, ping);
776
777         rc = OBP(exp->exp_obd, ping)(exp);
778         RETURN(rc);
779 }
780
781 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
782 {
783         int rc;
784         ENTRY;
785
786         OBD_CHECK_OP(obd, pool_new, -EOPNOTSUPP);
787         OBD_COUNTER_INCREMENT(obd, pool_new);
788
789         rc = OBP(obd, pool_new)(obd, poolname);
790         RETURN(rc);
791 }
792
793 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
794 {
795         int rc;
796         ENTRY;
797
798         OBD_CHECK_OP(obd, pool_del, -EOPNOTSUPP);
799         OBD_COUNTER_INCREMENT(obd, pool_del);
800
801         rc = OBP(obd, pool_del)(obd, poolname);
802         RETURN(rc);
803 }
804
805 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
806 {
807         int rc;
808         ENTRY;
809
810         OBD_CHECK_OP(obd, pool_add, -EOPNOTSUPP);
811         OBD_COUNTER_INCREMENT(obd, pool_add);
812
813         rc = OBP(obd, pool_add)(obd, poolname, ostname);
814         RETURN(rc);
815 }
816
817 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
818 {
819         int rc;
820         ENTRY;
821
822         OBD_CHECK_OP(obd, pool_rem, -EOPNOTSUPP);
823         OBD_COUNTER_INCREMENT(obd, pool_rem);
824
825         rc = OBP(obd, pool_rem)(obd, poolname, ostname);
826         RETURN(rc);
827 }
828
829 static inline void obd_getref(struct obd_device *obd)
830 {
831         ENTRY;
832         if (OBT(obd) && OBP(obd, getref)) {
833                 OBD_COUNTER_INCREMENT(obd, getref);
834                 OBP(obd, getref)(obd);
835         }
836         EXIT;
837 }
838
839 static inline void obd_putref(struct obd_device *obd)
840 {
841         ENTRY;
842         if (OBT(obd) && OBP(obd, putref)) {
843                 OBD_COUNTER_INCREMENT(obd, putref);
844                 OBP(obd, putref)(obd);
845         }
846         EXIT;
847 }
848
849 static inline int obd_init_export(struct obd_export *exp)
850 {
851         int rc = 0;
852
853         ENTRY;
854         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
855             OBP((exp)->exp_obd, init_export))
856                 rc = OBP(exp->exp_obd, init_export)(exp);
857         RETURN(rc);
858 }
859
860 static inline int obd_destroy_export(struct obd_export *exp)
861 {
862         ENTRY;
863         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
864             OBP((exp)->exp_obd, destroy_export))
865                 OBP(exp->exp_obd, destroy_export)(exp);
866         RETURN(0);
867 }
868
869 static inline int obd_extent_calc(struct obd_export *exp,
870                                   struct lov_stripe_md *md,
871                                   int cmd, obd_off *offset)
872 {
873         int rc;
874         ENTRY;
875         EXP_CHECK_OP(exp, extent_calc);
876         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
877         RETURN(rc);
878 }
879
880 static inline struct dentry *
881 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
882 {
883         LASSERT(exp->exp_obd);
884
885         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
886                                exp->exp_obd);
887 }
888
889 #ifndef time_before
890 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
891 #endif
892
893 /* @max_age is the oldest time in jiffies that we accept using a cached data.
894  * If the cache is older than @max_age we will get a new value from the
895  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
896 static inline int obd_statfs_async(struct obd_device *obd,
897                                    struct obd_info *oinfo,
898                                    __u64 max_age,
899                                    struct ptlrpc_request_set *rqset)
900 {
901         int rc = 0;
902         ENTRY;
903
904         if (obd == NULL)
905                 RETURN(-EINVAL);
906
907         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
908         OBD_COUNTER_INCREMENT(obd, statfs);
909
910         CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
911                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
912         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
913                 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
914         } else {
915                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
916                        " objects "LPU64"/"LPU64"\n",
917                        obd->obd_name, &obd->obd_osfs,
918                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
919                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
920                 spin_lock(&obd->obd_osfs_lock);
921                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
922                 spin_unlock(&obd->obd_osfs_lock);
923                 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
924                 if (oinfo->oi_cb_up)
925                         oinfo->oi_cb_up(oinfo, 0);
926         }
927         RETURN(rc);
928 }
929
930 static inline int obd_statfs_rqset(struct obd_device *obd,
931                                    struct obd_statfs *osfs, __u64 max_age,
932                                    __u32 flags)
933 {
934         struct ptlrpc_request_set *set = NULL;
935         struct obd_info oinfo = { { { 0 } } };
936         int rc = 0;
937         ENTRY;
938
939         set = ptlrpc_prep_set();
940         if (set == NULL)
941                 RETURN(-ENOMEM);
942
943         oinfo.oi_osfs = osfs;
944         oinfo.oi_flags = flags;
945         rc = obd_statfs_async(obd, &oinfo, max_age, set);
946         if (rc == 0)
947                 rc = ptlrpc_set_wait(set);
948         ptlrpc_set_destroy(set);
949         RETURN(rc);
950 }
951
952 /* @max_age is the oldest time in jiffies that we accept using a cached data.
953  * If the cache is older than @max_age we will get a new value from the
954  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
955 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
956                              __u64 max_age, __u32 flags)
957 {
958         int rc = 0;
959         ENTRY;
960
961         if (obd == NULL)
962                 RETURN(-EINVAL);
963
964         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
965         OBD_COUNTER_INCREMENT(obd, statfs);
966
967         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
968                obd->obd_osfs_age, max_age);
969         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
970                 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
971                 if (rc == 0) {
972                         spin_lock(&obd->obd_osfs_lock);
973                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
974                         obd->obd_osfs_age = cfs_time_current_64();
975                         spin_unlock(&obd->obd_osfs_lock);
976                 }
977         } else {
978                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
979                        " objects "LPU64"/"LPU64"\n",
980                        obd->obd_name, &obd->obd_osfs,
981                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
982                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
983                 spin_lock(&obd->obd_osfs_lock);
984                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
985                 spin_unlock(&obd->obd_osfs_lock);
986         }
987         RETURN(rc);
988 }
989
990 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
991                                  obd_size start, obd_size end)
992 {
993         struct ptlrpc_request_set *set = NULL;
994         int rc;
995         ENTRY;
996
997         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
998         EXP_COUNTER_INCREMENT(exp, sync);
999
1000         set =  ptlrpc_prep_set();
1001         if (set == NULL)
1002                 RETURN(-ENOMEM);
1003
1004         rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1005         if (rc == 0)
1006                 rc = ptlrpc_set_wait(set);
1007         ptlrpc_set_destroy(set);
1008         RETURN(rc);
1009 }
1010
1011 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1012                            obd_size start, obd_size end,
1013                            struct ptlrpc_request_set *set)
1014 {
1015         int rc;
1016         ENTRY;
1017
1018         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1019         EXP_COUNTER_INCREMENT(exp, sync);
1020
1021         rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1022         RETURN(rc);
1023 }
1024
1025 static inline int obd_punch_rqset(struct obd_export *exp,
1026                                   struct obd_info *oinfo,
1027                                   struct obd_trans_info *oti)
1028 {
1029         struct ptlrpc_request_set *set = NULL;
1030         int rc;
1031         ENTRY;
1032
1033         EXP_CHECK_OP(exp, punch);
1034         EXP_COUNTER_INCREMENT(exp, punch);
1035
1036         set =  ptlrpc_prep_set();
1037         if (set == NULL)
1038                 RETURN(-ENOMEM);
1039
1040         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1041         if (rc == 0)
1042                 rc = ptlrpc_set_wait(set);
1043         ptlrpc_set_destroy(set);
1044         RETURN(rc);
1045 }
1046
1047 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1048                             struct obd_trans_info *oti,
1049                             struct ptlrpc_request_set *rqset)
1050 {
1051         int rc;
1052         ENTRY;
1053
1054         EXP_CHECK_OP(exp, punch);
1055         EXP_COUNTER_INCREMENT(exp, punch);
1056
1057         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1058         RETURN(rc);
1059 }
1060
1061 static inline int obd_brw(int cmd, struct obd_export *exp,
1062                           struct obd_info *oinfo, obd_count oa_bufs,
1063                           struct brw_page *pg, struct obd_trans_info *oti)
1064 {
1065         int rc;
1066         ENTRY;
1067
1068         EXP_CHECK_OP(exp, brw);
1069         EXP_COUNTER_INCREMENT(exp, brw);
1070
1071         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1072                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1073                        "or OBD_BRW_CHECK\n");
1074                 LBUG();
1075         }
1076
1077         rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1078         RETURN(rc);
1079 }
1080
1081 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1082                                 struct obd_info *oinfo, obd_count oa_bufs,
1083                                 struct brw_page *pg, struct obd_trans_info *oti,
1084                                 struct ptlrpc_request_set *set, int pshift)
1085 {
1086         int rc;
1087         ENTRY;
1088
1089         EXP_CHECK_OP(exp, brw_async);
1090         EXP_COUNTER_INCREMENT(exp, brw_async);
1091
1092         if (!(cmd & OBD_BRW_RWMASK)) {
1093                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1094                 LBUG();
1095         }
1096
1097         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs,
1098                                           pg, oti,set, pshift);
1099         RETURN(rc);
1100 }
1101
1102 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1103                                 struct obdo *oa, struct lov_stripe_md *lsm,
1104                                 obd_count oa_bufs, struct brw_page *pg,
1105                                 struct obd_trans_info *oti)
1106 {
1107         struct ptlrpc_request_set *set = NULL;
1108         struct obd_info oinfo = { { { 0 } } };
1109         int rc = 0;
1110         ENTRY;
1111
1112         set =  ptlrpc_prep_set();
1113         if (set == NULL)
1114                 RETURN(-ENOMEM);
1115
1116         oinfo.oi_oa = oa;
1117         oinfo.oi_md = lsm;
1118         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set, 0);
1119         if (rc == 0) {
1120                 rc = ptlrpc_set_wait(set);
1121                 if (rc)
1122                         CERROR("error from callback: rc = %d\n", rc);
1123         } else {
1124                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
1125                        "error from obd_brw_async: rc = %d\n", rc);
1126         }
1127         ptlrpc_set_destroy(set);
1128         RETURN(rc);
1129 }
1130
1131 /* flags used by obd_prep_async_page */
1132 #define OBD_PAGE_NO_CACHE  0x00000001 /* don't add to cache */
1133 #define OBD_FAST_LOCK 0x00000002 /* lockh refers to a "fast lock" */
1134
1135 static inline  int obd_prep_async_page(struct obd_export *exp,
1136                                        struct lov_stripe_md *lsm,
1137                                        struct lov_oinfo *loi,
1138                                        cfs_page_t *page, obd_off offset,
1139                                        struct obd_async_page_ops *ops,
1140                                        void *data, void **res, int flags,
1141                                        struct lustre_handle *lockh)
1142 {
1143         int ret;
1144         ENTRY;
1145
1146         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
1147         EXP_COUNTER_INCREMENT(exp, prep_async_page);
1148
1149         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1150                                                  ops, data, res, flags,
1151                                                  lockh);
1152         RETURN(ret);
1153 }
1154
1155 static inline int obd_get_lock(struct obd_export *exp,
1156                                struct lov_stripe_md *lsm, void **res, int rw,
1157                                obd_off start, obd_off end,
1158                                struct lustre_handle *lockh, int flags)
1159 {
1160         ENTRY;
1161
1162         OBD_CHECK_OP(exp->exp_obd, get_lock, -EOPNOTSUPP);
1163         EXP_COUNTER_INCREMENT(exp, get_lock);
1164
1165         RETURN(OBP(exp->exp_obd, get_lock)(exp, lsm, res, rw, start, end,
1166                                            lockh, flags));
1167 }
1168
1169 static inline int obd_queue_async_io(struct obd_export *exp,
1170                                      struct lov_stripe_md *lsm,
1171                                      struct lov_oinfo *loi, void *cookie,
1172                                      int cmd, obd_off off, int count,
1173                                      obd_flag brw_flags, obd_flag async_flags)
1174 {
1175         int rc;
1176         ENTRY;
1177
1178         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
1179         EXP_COUNTER_INCREMENT(exp, queue_async_io);
1180         LASSERT(cmd & OBD_BRW_RWMASK);
1181
1182         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1183                                                count, brw_flags, async_flags);
1184         RETURN(rc);
1185 }
1186
1187 static inline int obd_set_async_flags(struct obd_export *exp,
1188                                       struct lov_stripe_md *lsm,
1189                                       struct lov_oinfo *loi, void *cookie,
1190                                       obd_flag async_flags)
1191 {
1192         int rc;
1193         ENTRY;
1194
1195         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1196         EXP_COUNTER_INCREMENT(exp, set_async_flags);
1197
1198         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1199                                                 async_flags);
1200         RETURN(rc);
1201 }
1202
1203 static inline int obd_queue_group_io(struct obd_export *exp,
1204                                      struct lov_stripe_md *lsm,
1205                                      struct lov_oinfo *loi,
1206                                      struct obd_io_group *oig,
1207                                      void *cookie, int cmd, obd_off off,
1208                                      int count, obd_flag brw_flags,
1209                                      obd_flag async_flags)
1210 {
1211         int rc;
1212         ENTRY;
1213
1214         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1215         EXP_COUNTER_INCREMENT(exp, queue_group_io);
1216         LASSERT(cmd & OBD_BRW_RWMASK);
1217
1218         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1219                                                cmd, off, count, brw_flags,
1220                                                async_flags);
1221         RETURN(rc);
1222 }
1223
1224 static inline int obd_trigger_group_io(struct obd_export *exp,
1225                                        struct lov_stripe_md *lsm,
1226                                        struct lov_oinfo *loi,
1227                                        struct obd_io_group *oig)
1228 {
1229         int rc;
1230         ENTRY;
1231
1232         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1233         EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1234
1235         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1236         RETURN(rc);
1237 }
1238
1239 static inline int obd_teardown_async_page(struct obd_export *exp,
1240                                           struct lov_stripe_md *lsm,
1241                                           struct lov_oinfo *loi, void *cookie)
1242 {
1243         int rc;
1244         ENTRY;
1245
1246         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1247         EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1248
1249         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1250         RETURN(rc);
1251 }
1252
1253 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1254                              int objcount, struct obd_ioobj *obj,
1255                              struct niobuf_remote *remote, int *pages,
1256                              struct niobuf_local *local,
1257                              struct obd_trans_info *oti)
1258 {
1259         int rc;
1260         ENTRY;
1261
1262         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1263         EXP_COUNTER_INCREMENT(exp, preprw);
1264
1265         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1266                                        pages, local, oti);
1267         RETURN(rc);
1268 }
1269
1270 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1271                                int objcount, struct obd_ioobj *obj,
1272                                struct niobuf_remote *rnb, int pages,
1273                                struct niobuf_local *local,
1274                                struct obd_trans_info *oti, int rc)
1275 {
1276         ENTRY;
1277
1278         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1279         EXP_COUNTER_INCREMENT(exp, commitrw);
1280
1281         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1282                                          rnb, pages, local, oti, rc);
1283         RETURN(rc);
1284 }
1285
1286 static inline int obd_merge_lvb(struct obd_export *exp,
1287                                 struct lov_stripe_md *lsm,
1288                                 struct ost_lvb *lvb, int kms_only)
1289 {
1290         int rc;
1291         ENTRY;
1292
1293         OBD_CHECK_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1294         EXP_COUNTER_INCREMENT(exp, merge_lvb);
1295
1296         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1297         RETURN(rc);
1298 }
1299
1300 static inline int obd_update_lvb(struct obd_export *exp,
1301                                  struct lov_stripe_md *lsm,
1302                                  struct ost_lvb *lvb, obd_flag valid)
1303 {
1304         int rc;
1305         ENTRY;
1306
1307         OBD_CHECK_OP(exp->exp_obd, update_lvb, -EOPNOTSUPP);
1308         EXP_COUNTER_INCREMENT(exp, update_lvb);
1309
1310         rc = OBP(exp->exp_obd, update_lvb)(exp, lsm, lvb, valid);
1311         RETURN(rc);
1312 }
1313
1314 static inline int obd_adjust_kms(struct obd_export *exp,
1315                                  struct lov_stripe_md *lsm, obd_off size,
1316                                  int shrink)
1317 {
1318         int rc;
1319         ENTRY;
1320
1321         OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1322         EXP_COUNTER_INCREMENT(exp, adjust_kms);
1323
1324         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1325         RETURN(rc);
1326 }
1327
1328 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1329                                 int len, void *karg, void *uarg)
1330 {
1331         int rc;
1332         ENTRY;
1333
1334         EXP_CHECK_OP(exp, iocontrol);
1335         EXP_COUNTER_INCREMENT(exp, iocontrol);
1336
1337         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1338         RETURN(rc);
1339 }
1340
1341 static inline int obd_enqueue_rqset(struct obd_export *exp,
1342                                     struct obd_info *oinfo,
1343                                     struct ldlm_enqueue_info *einfo)
1344 {
1345         struct ptlrpc_request_set *set = NULL;
1346         int rc;
1347         ENTRY;
1348
1349         EXP_CHECK_OP(exp, enqueue);
1350         EXP_COUNTER_INCREMENT(exp, enqueue);
1351
1352         set =  ptlrpc_prep_set();
1353         if (set == NULL)
1354                 RETURN(-ENOMEM);
1355
1356         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1357         if (rc == 0)
1358                 rc = ptlrpc_set_wait(set);
1359         ptlrpc_set_destroy(set);
1360         RETURN(rc);
1361 }
1362
1363 static inline int obd_enqueue(struct obd_export *exp,
1364                               struct obd_info *oinfo,
1365                               struct ldlm_enqueue_info *einfo,
1366                               struct ptlrpc_request_set *set)
1367 {
1368         int rc;
1369         ENTRY;
1370
1371         EXP_CHECK_OP(exp, enqueue);
1372         EXP_COUNTER_INCREMENT(exp, enqueue);
1373
1374         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1375         RETURN(rc);
1376 }
1377
1378 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1379                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1380                             int *flags, void *data, struct lustre_handle *lockh,
1381                             int *n_matches)
1382 {
1383         int rc;
1384         ENTRY;
1385
1386         EXP_CHECK_OP(exp, match);
1387         EXP_COUNTER_INCREMENT(exp, match);
1388
1389         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1390                                       lockh, n_matches);
1391         RETURN(rc);
1392 }
1393
1394 static inline int obd_change_cbdata(struct obd_export *exp,
1395                                     struct lov_stripe_md *lsm,
1396                                     ldlm_iterator_t it, void *data)
1397 {
1398         int rc;
1399         ENTRY;
1400
1401         EXP_CHECK_OP(exp, change_cbdata);
1402         EXP_COUNTER_INCREMENT(exp, change_cbdata);
1403
1404         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1405         RETURN(rc);
1406 }
1407
1408 static inline int obd_find_cbdata(struct obd_export *exp,
1409                                   struct lov_stripe_md *lsm,
1410                                   ldlm_iterator_t it, void *data)
1411 {
1412         int rc;
1413         ENTRY;
1414
1415         EXP_CHECK_OP(exp, find_cbdata);
1416         EXP_COUNTER_INCREMENT(exp, find_cbdata);
1417
1418         rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1419         RETURN(rc);
1420 }
1421
1422 static inline int obd_cancel(struct obd_export *exp, struct lov_stripe_md *ea,
1423                              __u32 mode, struct lustre_handle *lockh, int flags,
1424                              obd_off end)
1425 {
1426         int rc;
1427         ENTRY;
1428
1429         EXP_CHECK_OP(exp, cancel);
1430         EXP_COUNTER_INCREMENT(exp, cancel);
1431
1432         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh, flags, end);
1433         RETURN(rc);
1434 }
1435
1436 static inline int obd_cancel_unused(struct obd_export *exp,
1437                                     struct lov_stripe_md *ea, int flags,
1438                                     void *opaque)
1439 {
1440         int rc;
1441         ENTRY;
1442
1443         EXP_CHECK_OP(exp, cancel_unused);
1444         EXP_COUNTER_INCREMENT(exp, cancel_unused);
1445
1446         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1447         RETURN(rc);
1448 }
1449
1450 static inline int obd_join_lru(struct obd_export *exp,
1451                                struct lov_stripe_md *ea, int join)
1452 {
1453         int rc;
1454         ENTRY;
1455
1456         EXP_CHECK_OP(exp, join_lru);
1457         EXP_COUNTER_INCREMENT(exp, join_lru);
1458
1459         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1460         RETURN(rc);
1461 }
1462
1463 static inline int obd_pin(struct obd_export *exp, struct ll_fid *fid,
1464                           struct obd_client_handle *handle, int flag)
1465 {
1466         int rc;
1467         ENTRY;
1468
1469         EXP_CHECK_OP(exp, pin);
1470         EXP_COUNTER_INCREMENT(exp, pin);
1471
1472         rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1473         RETURN(rc);
1474 }
1475
1476 static inline int obd_unpin(struct obd_export *exp,
1477                             struct obd_client_handle *handle, int flag)
1478 {
1479         int rc;
1480         ENTRY;
1481
1482         EXP_CHECK_OP(exp, unpin);
1483         EXP_COUNTER_INCREMENT(exp, unpin);
1484
1485         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1486         RETURN(rc);
1487 }
1488
1489
1490 static inline void obd_import_event(struct obd_device *obd,
1491                                     struct obd_import *imp,
1492                                     enum obd_import_event event)
1493 {
1494         ENTRY;
1495         if (!obd) {
1496                 CERROR("NULL device\n");
1497                 EXIT;
1498                 return;
1499         }
1500         if (obd->obd_set_up && OBP(obd, import_event)) {
1501                 OBD_COUNTER_INCREMENT(obd, import_event);
1502                 OBP(obd, import_event)(obd, imp, event);
1503         }
1504         EXIT;
1505 }
1506
1507 static inline int obd_notify(struct obd_device *obd,
1508                              struct obd_device *watched,
1509                              enum obd_notify_event ev, void *data)
1510 {
1511         ENTRY;
1512         OBD_CHECK_DEV(obd);
1513
1514         /* the check for async_recov is a complete hack - I'm hereby
1515            overloading the meaning to also mean "this was called from
1516            mds_postsetup".  I know that my mds is able to handle notifies
1517            by this point, and it needs to get them to execute mds_postrecov. */
1518         if (!obd->obd_set_up && !obd->obd_async_recov) {
1519                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1520                 RETURN(-EINVAL);
1521         }
1522
1523         if (!OBP(obd, notify))
1524                 RETURN(-ENOSYS);
1525
1526         OBD_COUNTER_INCREMENT(obd, notify);
1527         RETURN(OBP(obd, notify)(obd, watched, ev, data));
1528 }
1529
1530 static inline int obd_notify_observer(struct obd_device *observer,
1531                                       struct obd_device *observed,
1532                                       enum obd_notify_event ev, void *data)
1533 {
1534         int rc1;
1535         int rc2;
1536
1537         struct obd_notify_upcall *onu;
1538
1539         if (observer->obd_observer)
1540                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1541         else
1542                 rc1 = 0;
1543         /*
1544          * Also, call non-obd listener, if any
1545          */
1546         onu = &observer->obd_upcall;
1547         if (onu->onu_upcall != NULL)
1548                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1549         else
1550                 rc2 = 0;
1551
1552         return rc1 ?: rc2;
1553  }
1554
1555 static inline int obd_quotacheck(struct obd_export *exp,
1556                                  struct obd_quotactl *oqctl)
1557 {
1558         int rc;
1559         ENTRY;
1560
1561         EXP_CHECK_OP(exp, quotacheck);
1562         EXP_COUNTER_INCREMENT(exp, quotacheck);
1563
1564         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1565         RETURN(rc);
1566 }
1567
1568 static inline int obd_quotactl(struct obd_export *exp,
1569                                struct obd_quotactl *oqctl)
1570 {
1571         int rc;
1572         ENTRY;
1573
1574         EXP_CHECK_OP(exp, quotactl);
1575         EXP_COUNTER_INCREMENT(exp, quotactl);
1576
1577         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1578         RETURN(rc);
1579 }
1580
1581 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1582                                          struct quota_adjust_qunit *oqaq,
1583                                          struct lustre_quota_ctxt *qctxt)
1584 {
1585 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1586         struct timeval work_start;
1587         struct timeval work_end;
1588         long timediff;
1589 #endif
1590         int rc;
1591         ENTRY;
1592
1593 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1594         if (qctxt)
1595                 do_gettimeofday(&work_start);
1596 #endif
1597         EXP_CHECK_OP(exp, quota_adjust_qunit);
1598         EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1599
1600         rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1601
1602 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1603         if (qctxt) {
1604                 do_gettimeofday(&work_end);
1605                 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1606                 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1607                                     timediff);
1608         }
1609 #endif
1610         RETURN(rc);
1611 }
1612
1613 static inline int obd_health_check(struct obd_device *obd)
1614 {
1615         /* returns: 0 on healthy
1616          *         >0 on unhealthy + reason code/flag
1617          *            however the only suppored reason == 1 right now
1618          *            We'll need to define some better reasons
1619          *            or flags in the future.
1620          *         <0 on error
1621          */
1622         int rc;
1623         ENTRY;
1624
1625         /* don't use EXP_CHECK_OP, because NULL method is normal here */
1626         if (obd == NULL || !OBT(obd)) {
1627                 CERROR("cleaned up obd\n");
1628                 RETURN(-EOPNOTSUPP);
1629         }
1630         if (!obd->obd_set_up || obd->obd_stopping)
1631                 RETURN(0);
1632         if (!OBP(obd, health_check))
1633                 RETURN(0);
1634
1635         rc = OBP(obd, health_check)(obd);
1636         RETURN(rc);
1637 }
1638
1639 static inline int obd_register_observer(struct obd_device *obd,
1640                                         struct obd_device *observer)
1641 {
1642         ENTRY;
1643         OBD_CHECK_DEV(obd);
1644         down_write(&obd->obd_observer_link_sem);
1645         if (obd->obd_observer && observer) {
1646                 up_write(&obd->obd_observer_link_sem);
1647                 RETURN(-EALREADY);
1648         }
1649         obd->obd_observer = observer;
1650         up_write(&obd->obd_observer_link_sem);
1651         RETURN(0);
1652 }
1653
1654 static inline int obd_pin_observer(struct obd_device *obd,
1655                                    struct obd_device **observer)
1656 {
1657         ENTRY;
1658         down_read(&obd->obd_observer_link_sem);
1659         if (!obd->obd_observer) {
1660                 *observer = NULL;
1661                 up_read(&obd->obd_observer_link_sem);
1662                 RETURN(-ENOENT);
1663         }
1664         *observer = obd->obd_observer;
1665         RETURN(0);
1666 }
1667
1668 static inline int obd_unpin_observer(struct obd_device *obd)
1669 {
1670         ENTRY;
1671         up_read(&obd->obd_observer_link_sem);
1672         RETURN(0);
1673 }
1674
1675 static inline int obd_register_page_removal_cb(struct obd_device *obd,
1676                                                obd_page_removal_cb_t cb,
1677                                                obd_pin_extent_cb pin_cb)
1678 {
1679         int rc;
1680         ENTRY;
1681
1682         OBD_CHECK_OP(obd, register_page_removal_cb, 0);
1683         OBD_COUNTER_INCREMENT(obd, register_page_removal_cb);
1684
1685         rc = OBP(obd, register_page_removal_cb)(obd, cb, pin_cb);
1686         RETURN(rc);
1687 }
1688
1689 static inline int obd_unregister_page_removal_cb(struct obd_device *obd,
1690                                                  obd_page_removal_cb_t cb)
1691 {
1692         int rc;
1693         ENTRY;
1694
1695         OBD_CHECK_OP(obd, unregister_page_removal_cb, 0);
1696         OBD_COUNTER_INCREMENT(obd, unregister_page_removal_cb);
1697
1698         rc = OBP(obd, unregister_page_removal_cb)(obd, cb);
1699         RETURN(rc);
1700 }
1701
1702 static inline int obd_register_lock_cancel_cb(struct obd_device *obd,
1703                                               obd_lock_cancel_cb cb)
1704 {
1705         int rc;
1706         ENTRY;
1707
1708         OBD_CHECK_OP(obd, register_lock_cancel_cb, 0);
1709         OBD_COUNTER_INCREMENT(obd, register_lock_cancel_cb);
1710
1711         rc = OBP(obd, register_lock_cancel_cb)(obd, cb);
1712         RETURN(rc);
1713 }
1714
1715 static inline int obd_unregister_lock_cancel_cb(struct obd_device *obd,
1716                                                  obd_lock_cancel_cb cb)
1717 {
1718         int rc;
1719         ENTRY;
1720
1721         OBD_CHECK_OP(obd, unregister_lock_cancel_cb, 0);
1722         OBD_COUNTER_INCREMENT(obd, unregister_lock_cancel_cb);
1723
1724         rc = OBP(obd, unregister_lock_cancel_cb)(obd, cb);
1725         RETURN(rc);
1726 }
1727
1728 /* OBD Metadata Support */
1729
1730 extern int obd_init_caches(void);
1731 extern void obd_cleanup_caches(void);
1732
1733 /* support routines */
1734 extern cfs_mem_cache_t *obdo_cachep;
1735
1736 #define OBDO_ALLOC(ptr)                                                       \
1737 do {                                                                          \
1738         OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep);                               \
1739 } while(0)
1740
1741 #define OBDO_FREE(ptr)                                                        \
1742 do {                                                                          \
1743         OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
1744 } while(0)
1745
1746 /* I'm as embarrassed about this as you are.
1747  *
1748  * <shaver> // XXX do not look into _superhack with remaining eye
1749  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1750 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1751
1752 /* sysctl.c */
1753 extern void obd_sysctl_init (void);
1754 extern void obd_sysctl_clean (void);
1755
1756 /* uuid.c  */
1757 typedef __u8 class_uuid_t[16];
1758 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1759
1760 /* lustre_peer.c    */
1761 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index);
1762 int class_add_uuid(char *uuid, __u64 nid);
1763 int class_del_uuid (char *uuid);
1764 void class_init_uuidlist(void);
1765 void class_exit_uuidlist(void);
1766
1767 /* prng.c */
1768 void ll_generate_random_uuid(class_uuid_t uuid_out);
1769
1770 #endif /* __LINUX_OBD_CLASS_H */