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