Whamcloud - gitweb
fcd7070b081afc6f59a73b171c30952709b382c8
[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 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp) {
310         int rc;
311
312         rc = lprocfs_register_stats(tmp->nid_proc, "stats",
313                                     tmp->nid_stats);
314         if (rc)
315                 return rc;
316
317         /* Always add in ldlm_stats */
318         tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
319                                                   ,LPROCFS_STATS_FLAG_NOPERCPU);
320         if (tmp->nid_ldlm_stats == NULL)
321                 return -ENOMEM;
322
323         lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
324
325         return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
326                                       tmp->nid_ldlm_stats);
327 }
328
329 #define OBD_CHECK_OP(obd, op, err)                              \
330 do {                                                            \
331         if (!OBT(obd) || !OBP((obd), op)) {\
332                 if (err)                                        \
333                         CERROR("obd_" #op ": dev %d no operation\n",    \
334                                obd->obd_minor);                         \
335                 RETURN(err);                                    \
336         }                                                       \
337 } while (0)
338
339 #define EXP_CHECK_OP(exp, op)                                   \
340 do {                                                            \
341         if ((exp) == NULL) {                                    \
342                 CERROR("obd_" #op ": NULL export\n");           \
343                 RETURN(-ENODEV);                                \
344         }                                                       \
345         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
346                 CERROR("obd_" #op ": cleaned up obd\n");        \
347                 RETURN(-EOPNOTSUPP);                            \
348         }                                                       \
349         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
350                 CERROR("obd_" #op ": dev %d no operation\n",    \
351                        (exp)->exp_obd->obd_minor);              \
352                 RETURN(-EOPNOTSUPP);                            \
353         }                                                       \
354 } while (0)
355
356 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
357 do {                                                            \
358         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
359                 if (err)                                        \
360                         CERROR("lop_" #op ": dev %d no operation\n",    \
361                                ctxt->loc_obd->obd_minor);                         \
362                 RETURN(err);                                    \
363         }                                                       \
364 } while (0)
365
366 static inline int class_devno_max(void)
367 {
368         return MAX_OBD_DEVICES;
369 }
370
371 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
372                                void *key, __u32 *vallen, void *val,
373                                struct lov_stripe_md *lsm)
374 {
375         int rc;
376         ENTRY;
377
378         EXP_CHECK_OP(exp, get_info);
379         EXP_COUNTER_INCREMENT(exp, get_info);
380
381         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
382         RETURN(rc);
383 }
384
385 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
386                                      void *key, obd_count vallen, void *val,
387                                      struct ptlrpc_request_set *set)
388 {
389         int rc;
390         ENTRY;
391
392         EXP_CHECK_OP(exp, set_info_async);
393         EXP_COUNTER_INCREMENT(exp, set_info_async);
394
395         rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
396                                                set);
397         RETURN(rc);
398 }
399
400 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
401 {
402         int rc;
403         ENTRY;
404
405         OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
406         OBD_COUNTER_INCREMENT(obd, setup);
407
408         rc = OBP(obd, setup)(obd, datalen, data);
409         RETURN(rc);
410 }
411
412 static inline int obd_precleanup(struct obd_device *obd,
413                                  enum obd_cleanup_stage cleanup_stage)
414 {
415         int rc;
416         ENTRY;
417
418         OBD_CHECK_OP(obd, precleanup, 0);
419         OBD_COUNTER_INCREMENT(obd, precleanup);
420
421         rc = OBP(obd, precleanup)(obd, cleanup_stage);
422         RETURN(rc);
423 }
424
425 static inline int obd_cleanup(struct obd_device *obd)
426 {
427         int rc;
428         ENTRY;
429
430         OBD_CHECK_DEV(obd);
431         OBD_CHECK_OP(obd, cleanup, 0);
432         OBD_COUNTER_INCREMENT(obd, cleanup);
433
434         rc = OBP(obd, cleanup)(obd);
435         RETURN(rc);
436 }
437
438 static inline int
439 obd_process_config(struct obd_device *obd, int datalen, void *data)
440 {
441         int rc;
442         ENTRY;
443
444         OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
445         OBD_COUNTER_INCREMENT(obd, process_config);
446
447         rc = OBP(obd, process_config)(obd, datalen, data);
448         RETURN(rc);
449 }
450
451 /* Pack an in-memory MD struct for storage on disk.
452  * Returns +ve size of packed MD (0 for free), or -ve error.
453  *
454  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
455  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
456  * If @*disk_tgt == NULL, it will be allocated
457  */
458 static inline int obd_packmd(struct obd_export *exp,
459                              struct lov_mds_md **disk_tgt,
460                              struct lov_stripe_md *mem_src)
461 {
462         int rc;
463         ENTRY;
464
465         EXP_CHECK_OP(exp, packmd);
466         EXP_COUNTER_INCREMENT(exp, packmd);
467
468         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
469         RETURN(rc);
470 }
471
472 static inline int obd_size_diskmd(struct obd_export *exp,
473                                   struct lov_stripe_md *mem_src)
474 {
475         return obd_packmd(exp, NULL, mem_src);
476 }
477
478 /* helper functions */
479 static inline int obd_alloc_diskmd(struct obd_export *exp,
480                                    struct lov_mds_md **disk_tgt)
481 {
482         LASSERT(disk_tgt);
483         LASSERT(*disk_tgt == NULL);
484         return obd_packmd(exp, disk_tgt, NULL);
485 }
486
487 static inline int obd_free_diskmd(struct obd_export *exp,
488                                   struct lov_mds_md **disk_tgt)
489 {
490         LASSERT(disk_tgt);
491         LASSERT(*disk_tgt);
492         return obd_packmd(exp, disk_tgt, NULL);
493 }
494
495 /* Unpack an MD struct from disk to in-memory format.
496  * Returns +ve size of unpacked MD (0 for free), or -ve error.
497  *
498  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
499  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
500  * If @*mem_tgt == NULL, it will be allocated
501  */
502 static inline int obd_unpackmd(struct obd_export *exp,
503                                struct lov_stripe_md **mem_tgt,
504                                struct lov_mds_md *disk_src,
505                                int disk_len)
506 {
507         int rc;
508         ENTRY;
509
510         EXP_CHECK_OP(exp, unpackmd);
511         EXP_COUNTER_INCREMENT(exp, unpackmd);
512
513         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
514         RETURN(rc);
515 }
516
517 /* helper functions */
518 static inline int obd_alloc_memmd(struct obd_export *exp,
519                                   struct lov_stripe_md **mem_tgt)
520 {
521         LASSERT(mem_tgt);
522         LASSERT(*mem_tgt == NULL);
523         return obd_unpackmd(exp, mem_tgt, NULL, 0);
524 }
525
526 static inline int obd_free_memmd(struct obd_export *exp,
527                                  struct lov_stripe_md **mem_tgt)
528 {
529         LASSERT(mem_tgt);
530         LASSERT(*mem_tgt);
531         return obd_unpackmd(exp, mem_tgt, NULL, 0);
532 }
533
534 static inline int obd_checkmd(struct obd_export *exp,
535                               struct obd_export *md_exp,
536                               struct lov_stripe_md *mem_tgt)
537 {
538         int rc;
539         ENTRY;
540
541         EXP_CHECK_OP(exp, checkmd);
542         EXP_COUNTER_INCREMENT(exp, checkmd);
543
544         rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
545         RETURN(rc);
546 }
547
548 static inline int obd_precreate(struct obd_export *exp)
549 {
550         int rc;
551         ENTRY;
552
553         EXP_CHECK_OP(exp, precreate);
554         OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
555
556         rc = OBP(exp->exp_obd, precreate)(exp);
557         RETURN(rc);
558 }
559
560 static inline int obd_create_async(struct obd_export *exp,
561                                    struct obd_info *oinfo,
562                                    struct lov_stripe_md **ea,
563                                    struct obd_trans_info *oti)
564 {
565         int rc;
566         ENTRY;
567
568         EXP_CHECK_OP(exp, create_async);
569         EXP_COUNTER_INCREMENT(exp, create_async);
570
571         rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
572         RETURN(rc);
573 }
574
575 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
576                              struct lov_stripe_md **ea,
577                              struct obd_trans_info *oti)
578 {
579         int rc;
580         ENTRY;
581
582         EXP_CHECK_OP(exp, create);
583         EXP_COUNTER_INCREMENT(exp, create);
584
585         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
586         RETURN(rc);
587 }
588
589 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
590                               struct lov_stripe_md *ea,
591                               struct obd_trans_info *oti,
592                               struct obd_export *md_exp)
593 {
594         int rc;
595         ENTRY;
596
597         EXP_CHECK_OP(exp, destroy);
598         EXP_COUNTER_INCREMENT(exp, destroy);
599
600         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
601         RETURN(rc);
602 }
603
604 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
605 {
606         int rc;
607         ENTRY;
608
609         EXP_CHECK_OP(exp, getattr);
610         EXP_COUNTER_INCREMENT(exp, getattr);
611
612         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
613         RETURN(rc);
614 }
615
616 static inline int obd_getattr_async(struct obd_export *exp,
617                                     struct obd_info *oinfo,
618                                     struct ptlrpc_request_set *set)
619 {
620         int rc;
621         ENTRY;
622
623         EXP_CHECK_OP(exp, getattr_async);
624         EXP_COUNTER_INCREMENT(exp, getattr_async);
625
626         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
627         RETURN(rc);
628 }
629
630 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
631                               struct obd_trans_info *oti)
632 {
633         int rc;
634         ENTRY;
635
636         EXP_CHECK_OP(exp, setattr);
637         EXP_COUNTER_INCREMENT(exp, setattr);
638
639         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
640         RETURN(rc);
641 }
642
643 /* This performs all the requests set init/wait/destroy actions. */
644 static inline int obd_setattr_rqset(struct obd_export *exp,
645                                     struct obd_info *oinfo,
646                                     struct obd_trans_info *oti)
647 {
648         struct ptlrpc_request_set *set = NULL;
649         int rc;
650         ENTRY;
651
652         EXP_CHECK_OP(exp, setattr_async);
653         EXP_COUNTER_INCREMENT(exp, setattr_async);
654
655         set =  ptlrpc_prep_set();
656         if (set == NULL)
657                 RETURN(-ENOMEM);
658
659         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
660         if (rc == 0)
661                 rc = ptlrpc_set_wait(set);
662         ptlrpc_set_destroy(set);
663         RETURN(rc);
664 }
665
666 /* This adds all the requests into @set if @set != NULL, otherwise
667    all requests are sent asynchronously without waiting for response. */
668 static inline int obd_setattr_async(struct obd_export *exp,
669                                     struct obd_info *oinfo,
670                                     struct obd_trans_info *oti,
671                                     struct ptlrpc_request_set *set)
672 {
673         int rc;
674         ENTRY;
675
676         EXP_CHECK_OP(exp, setattr_async);
677         EXP_COUNTER_INCREMENT(exp, setattr_async);
678
679         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
680         RETURN(rc);
681 }
682
683 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
684                                int priority)
685 {
686         struct obd_device *obd = imp->imp_obd;
687         int rc;
688         ENTRY;
689
690         OBD_CHECK_DEV_ACTIVE(obd);
691         OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
692         OBD_COUNTER_INCREMENT(obd, add_conn);
693
694         rc = OBP(obd, add_conn)(imp, uuid, priority);
695         RETURN(rc);
696 }
697
698 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
699 {
700         struct obd_device *obd = imp->imp_obd;
701         int rc;
702         ENTRY;
703
704         OBD_CHECK_DEV_ACTIVE(obd);
705         OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
706         OBD_COUNTER_INCREMENT(obd, del_conn);
707
708         rc = OBP(obd, del_conn)(imp, uuid);
709         RETURN(rc);
710 }
711
712 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
713                               struct obd_uuid *cluuid,
714                               struct obd_connect_data *d,
715                               void *localdata)
716 {
717         int rc;
718         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
719         ENTRY;
720
721         OBD_CHECK_DEV_ACTIVE(obd);
722         OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
723         OBD_COUNTER_INCREMENT(obd, connect);
724
725         rc = OBP(obd, connect)(conn, obd, cluuid, d, localdata);
726         /* check that only subset is granted */
727         LASSERT(ergo(d != NULL,
728                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
729         RETURN(rc);
730 }
731
732 static inline int obd_reconnect(struct obd_export *exp,
733                                 struct obd_device *obd,
734                                 struct obd_uuid *cluuid,
735                                 struct obd_connect_data *d,
736                                 void *localdata)
737 {
738         int rc;
739         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
740         ENTRY;
741
742         OBD_CHECK_DEV_ACTIVE(obd);
743         OBD_CHECK_OP(obd, reconnect, 0);
744         OBD_COUNTER_INCREMENT(obd, reconnect);
745
746         rc = OBP(obd, reconnect)(exp, obd, cluuid, d, localdata);
747         /* check that only subset is granted */
748         LASSERT(ergo(d != NULL,
749                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
750         RETURN(rc);
751 }
752
753 static inline int obd_disconnect(struct obd_export *exp)
754 {
755         int rc;
756         ENTRY;
757
758         EXP_CHECK_OP(exp, disconnect);
759         EXP_COUNTER_INCREMENT(exp, disconnect);
760
761         rc = OBP(exp->exp_obd, disconnect)(exp);
762         RETURN(rc);
763 }
764
765 static inline int obd_fid_init(struct obd_export *exp)
766 {
767         int rc;
768         ENTRY;
769
770         OBD_CHECK_OP(exp->exp_obd, fid_init, 0);
771         EXP_COUNTER_INCREMENT(exp, fid_init);
772
773         rc = OBP(exp->exp_obd, fid_init)(exp);
774         RETURN(rc);
775 }
776
777 static inline int obd_fid_fini(struct obd_export *exp)
778 {
779         int rc;
780         ENTRY;
781
782         OBD_CHECK_OP(exp->exp_obd, fid_fini, 0);
783         EXP_COUNTER_INCREMENT(exp, fid_fini);
784
785         rc = OBP(exp->exp_obd, fid_fini)(exp);
786         RETURN(rc);
787 }
788
789 static inline int obd_ping(struct obd_export *exp)
790 {
791         int rc;
792         ENTRY;
793
794         OBD_CHECK_OP(exp->exp_obd, ping, 0);
795         EXP_COUNTER_INCREMENT(exp, ping);
796
797         rc = OBP(exp->exp_obd, ping)(exp);
798         RETURN(rc);
799 }
800
801 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
802 {
803         int rc;
804         ENTRY;
805
806         OBD_CHECK_OP(obd, pool_new, -EOPNOTSUPP);
807         OBD_COUNTER_INCREMENT(obd, pool_new);
808
809         rc = OBP(obd, pool_new)(obd, poolname);
810         RETURN(rc);
811 }
812
813 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
814 {
815         int rc;
816         ENTRY;
817
818         OBD_CHECK_OP(obd, pool_del, -EOPNOTSUPP);
819         OBD_COUNTER_INCREMENT(obd, pool_del);
820
821         rc = OBP(obd, pool_del)(obd, poolname);
822         RETURN(rc);
823 }
824
825 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
826 {
827         int rc;
828         ENTRY;
829
830         OBD_CHECK_OP(obd, pool_add, -EOPNOTSUPP);
831         OBD_COUNTER_INCREMENT(obd, pool_add);
832
833         rc = OBP(obd, pool_add)(obd, poolname, ostname);
834         RETURN(rc);
835 }
836
837 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
838 {
839         int rc;
840         ENTRY;
841
842         OBD_CHECK_OP(obd, pool_rem, -EOPNOTSUPP);
843         OBD_COUNTER_INCREMENT(obd, pool_rem);
844
845         rc = OBP(obd, pool_rem)(obd, poolname, ostname);
846         RETURN(rc);
847 }
848
849 static inline void obd_getref(struct obd_device *obd)
850 {
851         ENTRY;
852         if (OBT(obd) && OBP(obd, getref)) {
853                 OBD_COUNTER_INCREMENT(obd, getref);
854                 OBP(obd, getref)(obd);
855         }
856         EXIT;
857 }
858
859 static inline void obd_putref(struct obd_device *obd)
860 {
861         ENTRY;
862         if (OBT(obd) && OBP(obd, putref)) {
863                 OBD_COUNTER_INCREMENT(obd, putref);
864                 OBP(obd, putref)(obd);
865         }
866         EXIT;
867 }
868
869 static inline int obd_init_export(struct obd_export *exp)
870 {
871         int rc = 0;
872
873         ENTRY;
874         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
875             OBP((exp)->exp_obd, init_export))
876                 rc = OBP(exp->exp_obd, init_export)(exp);
877         RETURN(rc);
878 }
879
880 static inline int obd_destroy_export(struct obd_export *exp)
881 {
882         ENTRY;
883         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
884             OBP((exp)->exp_obd, destroy_export))
885                 OBP(exp->exp_obd, destroy_export)(exp);
886         RETURN(0);
887 }
888
889 static inline int obd_extent_calc(struct obd_export *exp,
890                                   struct lov_stripe_md *md,
891                                   int cmd, obd_off *offset)
892 {
893         int rc;
894         ENTRY;
895         EXP_CHECK_OP(exp, extent_calc);
896         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
897         RETURN(rc);
898 }
899
900 static inline struct dentry *
901 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
902 {
903         LASSERT(exp->exp_obd);
904
905         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
906                                exp->exp_obd);
907 }
908
909 #ifndef time_before
910 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
911 #endif
912
913 /* @max_age is the oldest time in jiffies that we accept using a cached data.
914  * If the cache is older than @max_age we will get a new value from the
915  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
916 static inline int obd_statfs_async(struct obd_device *obd,
917                                    struct obd_info *oinfo,
918                                    __u64 max_age,
919                                    struct ptlrpc_request_set *rqset)
920 {
921         int rc = 0;
922         ENTRY;
923
924         if (obd == NULL)
925                 RETURN(-EINVAL);
926
927         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
928         OBD_COUNTER_INCREMENT(obd, statfs);
929
930         CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
931                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
932         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
933                 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
934         } else {
935                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
936                        " objects "LPU64"/"LPU64"\n",
937                        obd->obd_name, &obd->obd_osfs,
938                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
939                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
940                 spin_lock(&obd->obd_osfs_lock);
941                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
942                 spin_unlock(&obd->obd_osfs_lock);
943                 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
944                 if (oinfo->oi_cb_up)
945                         oinfo->oi_cb_up(oinfo, 0);
946         }
947         RETURN(rc);
948 }
949
950 static inline int obd_statfs_rqset(struct obd_device *obd,
951                                    struct obd_statfs *osfs, __u64 max_age,
952                                    __u32 flags)
953 {
954         struct ptlrpc_request_set *set = NULL;
955         struct obd_info oinfo = { { { 0 } } };
956         int rc = 0;
957         ENTRY;
958
959         set = ptlrpc_prep_set();
960         if (set == NULL)
961                 RETURN(-ENOMEM);
962
963         oinfo.oi_osfs = osfs;
964         oinfo.oi_flags = flags;
965         rc = obd_statfs_async(obd, &oinfo, max_age, set);
966         if (rc == 0)
967                 rc = ptlrpc_set_wait(set);
968         ptlrpc_set_destroy(set);
969         RETURN(rc);
970 }
971
972 /* @max_age is the oldest time in jiffies that we accept using a cached data.
973  * If the cache is older than @max_age we will get a new value from the
974  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
975 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
976                              __u64 max_age, __u32 flags)
977 {
978         int rc = 0;
979         ENTRY;
980
981         if (obd == NULL)
982                 RETURN(-EINVAL);
983
984         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
985         OBD_COUNTER_INCREMENT(obd, statfs);
986
987         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
988                obd->obd_osfs_age, max_age);
989         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
990                 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
991                 if (rc == 0) {
992                         spin_lock(&obd->obd_osfs_lock);
993                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
994                         obd->obd_osfs_age = cfs_time_current_64();
995                         spin_unlock(&obd->obd_osfs_lock);
996                 }
997         } else {
998                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
999                        " objects "LPU64"/"LPU64"\n",
1000                        obd->obd_name, &obd->obd_osfs,
1001                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1002                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1003                 spin_lock(&obd->obd_osfs_lock);
1004                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1005                 spin_unlock(&obd->obd_osfs_lock);
1006         }
1007         RETURN(rc);
1008 }
1009
1010 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1011                                  obd_size start, obd_size end)
1012 {
1013         struct ptlrpc_request_set *set = NULL;
1014         int rc;
1015         ENTRY;
1016
1017         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1018         EXP_COUNTER_INCREMENT(exp, sync);
1019
1020         set =  ptlrpc_prep_set();
1021         if (set == NULL)
1022                 RETURN(-ENOMEM);
1023
1024         rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1025         if (rc == 0)
1026                 rc = ptlrpc_set_wait(set);
1027         ptlrpc_set_destroy(set);
1028         RETURN(rc);
1029 }
1030
1031 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1032                            obd_size start, obd_size end,
1033                            struct ptlrpc_request_set *set)
1034 {
1035         int rc;
1036         ENTRY;
1037
1038         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1039         EXP_COUNTER_INCREMENT(exp, sync);
1040
1041         rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1042         RETURN(rc);
1043 }
1044
1045 static inline int obd_punch_rqset(struct obd_export *exp,
1046                                   struct obd_info *oinfo,
1047                                   struct obd_trans_info *oti)
1048 {
1049         struct ptlrpc_request_set *set = NULL;
1050         int rc;
1051         ENTRY;
1052
1053         EXP_CHECK_OP(exp, punch);
1054         EXP_COUNTER_INCREMENT(exp, punch);
1055
1056         set =  ptlrpc_prep_set();
1057         if (set == NULL)
1058                 RETURN(-ENOMEM);
1059
1060         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1061         if (rc == 0)
1062                 rc = ptlrpc_set_wait(set);
1063         ptlrpc_set_destroy(set);
1064         RETURN(rc);
1065 }
1066
1067 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1068                             struct obd_trans_info *oti,
1069                             struct ptlrpc_request_set *rqset)
1070 {
1071         int rc;
1072         ENTRY;
1073
1074         EXP_CHECK_OP(exp, punch);
1075         EXP_COUNTER_INCREMENT(exp, punch);
1076
1077         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1078         RETURN(rc);
1079 }
1080
1081 static inline int obd_brw(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 {
1085         int rc;
1086         ENTRY;
1087
1088         EXP_CHECK_OP(exp, brw);
1089         EXP_COUNTER_INCREMENT(exp, brw);
1090
1091         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1092                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1093                        "or OBD_BRW_CHECK\n");
1094                 LBUG();
1095         }
1096
1097         rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1098         RETURN(rc);
1099 }
1100
1101 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1102                                 struct obd_info *oinfo, obd_count oa_bufs,
1103                                 struct brw_page *pg, struct obd_trans_info *oti,
1104                                 struct ptlrpc_request_set *set, int pshift)
1105 {
1106         int rc;
1107         ENTRY;
1108
1109         EXP_CHECK_OP(exp, brw_async);
1110         EXP_COUNTER_INCREMENT(exp, brw_async);
1111
1112         if (!(cmd & OBD_BRW_RWMASK)) {
1113                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1114                 LBUG();
1115         }
1116
1117         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs,
1118                                           pg, oti,set, pshift);
1119         RETURN(rc);
1120 }
1121
1122 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1123                                 struct obdo *oa, struct lov_stripe_md *lsm,
1124                                 obd_count oa_bufs, struct brw_page *pg,
1125                                 struct obd_trans_info *oti)
1126 {
1127         struct ptlrpc_request_set *set = NULL;
1128         struct obd_info oinfo = { { { 0 } } };
1129         int rc = 0;
1130         ENTRY;
1131
1132         set =  ptlrpc_prep_set();
1133         if (set == NULL)
1134                 RETURN(-ENOMEM);
1135
1136         oinfo.oi_oa = oa;
1137         oinfo.oi_md = lsm;
1138         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set, 0);
1139         if (rc == 0) {
1140                 rc = ptlrpc_set_wait(set);
1141                 if (rc)
1142                         CERROR("error from callback: rc = %d\n", rc);
1143         } else {
1144                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
1145                        "error from obd_brw_async: rc = %d\n", rc);
1146         }
1147         ptlrpc_set_destroy(set);
1148         RETURN(rc);
1149 }
1150
1151 /* flags used by obd_prep_async_page */
1152 #define OBD_PAGE_NO_CACHE  0x00000001 /* don't add to cache */
1153 #define OBD_FAST_LOCK 0x00000002 /* lockh refers to a "fast lock" */
1154
1155 static inline  int obd_prep_async_page(struct obd_export *exp,
1156                                        struct lov_stripe_md *lsm,
1157                                        struct lov_oinfo *loi,
1158                                        cfs_page_t *page, obd_off offset,
1159                                        struct obd_async_page_ops *ops,
1160                                        void *data, void **res, int flags,
1161                                        struct lustre_handle *lockh)
1162 {
1163         int ret;
1164         ENTRY;
1165
1166         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
1167         EXP_COUNTER_INCREMENT(exp, prep_async_page);
1168
1169         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1170                                                  ops, data, res, flags,
1171                                                  lockh);
1172         RETURN(ret);
1173 }
1174
1175 static inline int obd_get_lock(struct obd_export *exp,
1176                                struct lov_stripe_md *lsm, void **res, int rw,
1177                                obd_off start, obd_off end,
1178                                struct lustre_handle *lockh, int flags)
1179 {
1180         ENTRY;
1181
1182         OBD_CHECK_OP(exp->exp_obd, get_lock, -EOPNOTSUPP);
1183         EXP_COUNTER_INCREMENT(exp, get_lock);
1184
1185         RETURN(OBP(exp->exp_obd, get_lock)(exp, lsm, res, rw, start, end,
1186                                            lockh, flags));
1187 }
1188
1189 static inline int obd_queue_async_io(struct obd_export *exp,
1190                                      struct lov_stripe_md *lsm,
1191                                      struct lov_oinfo *loi, void *cookie,
1192                                      int cmd, obd_off off, int count,
1193                                      obd_flag brw_flags, obd_flag async_flags)
1194 {
1195         int rc;
1196         ENTRY;
1197
1198         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
1199         EXP_COUNTER_INCREMENT(exp, queue_async_io);
1200         LASSERT(cmd & OBD_BRW_RWMASK);
1201
1202         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1203                                                count, brw_flags, async_flags);
1204         RETURN(rc);
1205 }
1206
1207 static inline int obd_set_async_flags(struct obd_export *exp,
1208                                       struct lov_stripe_md *lsm,
1209                                       struct lov_oinfo *loi, void *cookie,
1210                                       obd_flag async_flags)
1211 {
1212         int rc;
1213         ENTRY;
1214
1215         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1216         EXP_COUNTER_INCREMENT(exp, set_async_flags);
1217
1218         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1219                                                 async_flags);
1220         RETURN(rc);
1221 }
1222
1223 static inline int obd_queue_group_io(struct obd_export *exp,
1224                                      struct lov_stripe_md *lsm,
1225                                      struct lov_oinfo *loi,
1226                                      struct obd_io_group *oig,
1227                                      void *cookie, int cmd, obd_off off,
1228                                      int count, obd_flag brw_flags,
1229                                      obd_flag async_flags)
1230 {
1231         int rc;
1232         ENTRY;
1233
1234         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1235         EXP_COUNTER_INCREMENT(exp, queue_group_io);
1236         LASSERT(cmd & OBD_BRW_RWMASK);
1237
1238         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1239                                                cmd, off, count, brw_flags,
1240                                                async_flags);
1241         RETURN(rc);
1242 }
1243
1244 static inline int obd_trigger_group_io(struct obd_export *exp,
1245                                        struct lov_stripe_md *lsm,
1246                                        struct lov_oinfo *loi,
1247                                        struct obd_io_group *oig)
1248 {
1249         int rc;
1250         ENTRY;
1251
1252         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1253         EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1254
1255         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1256         RETURN(rc);
1257 }
1258
1259 static inline int obd_teardown_async_page(struct obd_export *exp,
1260                                           struct lov_stripe_md *lsm,
1261                                           struct lov_oinfo *loi, void *cookie)
1262 {
1263         int rc;
1264         ENTRY;
1265
1266         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1267         EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1268
1269         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1270         RETURN(rc);
1271 }
1272
1273 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1274                              int objcount, struct obd_ioobj *obj,
1275                              struct niobuf_remote *remote, int *pages,
1276                              struct niobuf_local *local,
1277                              struct obd_trans_info *oti)
1278 {
1279         int rc;
1280         ENTRY;
1281
1282         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1283         EXP_COUNTER_INCREMENT(exp, preprw);
1284
1285         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1286                                        pages, local, oti);
1287         RETURN(rc);
1288 }
1289
1290 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1291                                int objcount, struct obd_ioobj *obj,
1292                                struct niobuf_remote *rnb, int pages,
1293                                struct niobuf_local *local,
1294                                struct obd_trans_info *oti, int rc)
1295 {
1296         ENTRY;
1297
1298         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1299         EXP_COUNTER_INCREMENT(exp, commitrw);
1300
1301         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1302                                          rnb, pages, local, oti, rc);
1303         RETURN(rc);
1304 }
1305
1306 static inline int obd_merge_lvb(struct obd_export *exp,
1307                                 struct lov_stripe_md *lsm,
1308                                 struct ost_lvb *lvb, int kms_only)
1309 {
1310         int rc;
1311         ENTRY;
1312
1313         OBD_CHECK_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1314         EXP_COUNTER_INCREMENT(exp, merge_lvb);
1315
1316         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1317         RETURN(rc);
1318 }
1319
1320 static inline int obd_update_lvb(struct obd_export *exp,
1321                                  struct lov_stripe_md *lsm,
1322                                  struct ost_lvb *lvb, obd_flag valid)
1323 {
1324         int rc;
1325         ENTRY;
1326
1327         OBD_CHECK_OP(exp->exp_obd, update_lvb, -EOPNOTSUPP);
1328         EXP_COUNTER_INCREMENT(exp, update_lvb);
1329
1330         rc = OBP(exp->exp_obd, update_lvb)(exp, lsm, lvb, valid);
1331         RETURN(rc);
1332 }
1333
1334 static inline int obd_adjust_kms(struct obd_export *exp,
1335                                  struct lov_stripe_md *lsm, obd_off size,
1336                                  int shrink)
1337 {
1338         int rc;
1339         ENTRY;
1340
1341         OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1342         EXP_COUNTER_INCREMENT(exp, adjust_kms);
1343
1344         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1345         RETURN(rc);
1346 }
1347
1348 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1349                                 int len, void *karg, void *uarg)
1350 {
1351         int rc;
1352         ENTRY;
1353
1354         EXP_CHECK_OP(exp, iocontrol);
1355         EXP_COUNTER_INCREMENT(exp, iocontrol);
1356
1357         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1358         RETURN(rc);
1359 }
1360
1361 static inline int obd_enqueue_rqset(struct obd_export *exp,
1362                                     struct obd_info *oinfo,
1363                                     struct ldlm_enqueue_info *einfo)
1364 {
1365         struct ptlrpc_request_set *set = NULL;
1366         int rc;
1367         ENTRY;
1368
1369         EXP_CHECK_OP(exp, enqueue);
1370         EXP_COUNTER_INCREMENT(exp, enqueue);
1371
1372         set =  ptlrpc_prep_set();
1373         if (set == NULL)
1374                 RETURN(-ENOMEM);
1375
1376         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1377         if (rc == 0)
1378                 rc = ptlrpc_set_wait(set);
1379         ptlrpc_set_destroy(set);
1380         RETURN(rc);
1381 }
1382
1383 static inline int obd_enqueue(struct obd_export *exp,
1384                               struct obd_info *oinfo,
1385                               struct ldlm_enqueue_info *einfo,
1386                               struct ptlrpc_request_set *set)
1387 {
1388         int rc;
1389         ENTRY;
1390
1391         EXP_CHECK_OP(exp, enqueue);
1392         EXP_COUNTER_INCREMENT(exp, enqueue);
1393
1394         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1395         RETURN(rc);
1396 }
1397
1398 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1399                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1400                             int *flags, void *data, struct lustre_handle *lockh,
1401                             int *n_matches)
1402 {
1403         int rc;
1404         ENTRY;
1405
1406         EXP_CHECK_OP(exp, match);
1407         EXP_COUNTER_INCREMENT(exp, match);
1408
1409         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1410                                       lockh, n_matches);
1411         RETURN(rc);
1412 }
1413
1414 static inline int obd_change_cbdata(struct obd_export *exp,
1415                                     struct lov_stripe_md *lsm,
1416                                     ldlm_iterator_t it, void *data)
1417 {
1418         int rc;
1419         ENTRY;
1420
1421         EXP_CHECK_OP(exp, change_cbdata);
1422         EXP_COUNTER_INCREMENT(exp, change_cbdata);
1423
1424         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1425         RETURN(rc);
1426 }
1427
1428 static inline int obd_find_cbdata(struct obd_export *exp,
1429                                   struct lov_stripe_md *lsm,
1430                                   ldlm_iterator_t it, void *data)
1431 {
1432         int rc;
1433         ENTRY;
1434
1435         EXP_CHECK_OP(exp, find_cbdata);
1436         EXP_COUNTER_INCREMENT(exp, find_cbdata);
1437
1438         rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1439         RETURN(rc);
1440 }
1441
1442 static inline int obd_cancel(struct obd_export *exp, struct lov_stripe_md *ea,
1443                              __u32 mode, struct lustre_handle *lockh, int flags,
1444                              obd_off end)
1445 {
1446         int rc;
1447         ENTRY;
1448
1449         EXP_CHECK_OP(exp, cancel);
1450         EXP_COUNTER_INCREMENT(exp, cancel);
1451
1452         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh, flags, end);
1453         RETURN(rc);
1454 }
1455
1456 static inline int obd_cancel_unused(struct obd_export *exp,
1457                                     struct lov_stripe_md *ea, int flags,
1458                                     void *opaque)
1459 {
1460         int rc;
1461         ENTRY;
1462
1463         EXP_CHECK_OP(exp, cancel_unused);
1464         EXP_COUNTER_INCREMENT(exp, cancel_unused);
1465
1466         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1467         RETURN(rc);
1468 }
1469
1470 static inline int obd_join_lru(struct obd_export *exp,
1471                                struct lov_stripe_md *ea, int join)
1472 {
1473         int rc;
1474         ENTRY;
1475
1476         EXP_CHECK_OP(exp, join_lru);
1477         EXP_COUNTER_INCREMENT(exp, join_lru);
1478
1479         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1480         RETURN(rc);
1481 }
1482
1483 static inline int obd_pin(struct obd_export *exp, struct ll_fid *fid,
1484                           struct obd_client_handle *handle, int flag)
1485 {
1486         int rc;
1487         ENTRY;
1488
1489         EXP_CHECK_OP(exp, pin);
1490         EXP_COUNTER_INCREMENT(exp, pin);
1491
1492         rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1493         RETURN(rc);
1494 }
1495
1496 static inline int obd_unpin(struct obd_export *exp,
1497                             struct obd_client_handle *handle, int flag)
1498 {
1499         int rc;
1500         ENTRY;
1501
1502         EXP_CHECK_OP(exp, unpin);
1503         EXP_COUNTER_INCREMENT(exp, unpin);
1504
1505         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1506         RETURN(rc);
1507 }
1508
1509
1510 static inline void obd_import_event(struct obd_device *obd,
1511                                     struct obd_import *imp,
1512                                     enum obd_import_event event)
1513 {
1514         ENTRY;
1515         if (!obd) {
1516                 CERROR("NULL device\n");
1517                 EXIT;
1518                 return;
1519         }
1520         if (obd->obd_set_up && OBP(obd, import_event)) {
1521                 OBD_COUNTER_INCREMENT(obd, import_event);
1522                 OBP(obd, import_event)(obd, imp, event);
1523         }
1524         EXIT;
1525 }
1526
1527 static inline int obd_notify(struct obd_device *obd,
1528                              struct obd_device *watched,
1529                              enum obd_notify_event ev, void *data)
1530 {
1531         ENTRY;
1532         OBD_CHECK_DEV(obd);
1533
1534         /* the check for async_recov is a complete hack - I'm hereby
1535            overloading the meaning to also mean "this was called from
1536            mds_postsetup".  I know that my mds is able to handle notifies
1537            by this point, and it needs to get them to execute mds_postrecov. */
1538         if (!obd->obd_set_up && !obd->obd_async_recov) {
1539                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1540                 RETURN(-EINVAL);
1541         }
1542
1543         if (!OBP(obd, notify))
1544                 RETURN(-ENOSYS);
1545
1546         OBD_COUNTER_INCREMENT(obd, notify);
1547         RETURN(OBP(obd, notify)(obd, watched, ev, data));
1548 }
1549
1550 static inline int obd_notify_observer(struct obd_device *observer,
1551                                       struct obd_device *observed,
1552                                       enum obd_notify_event ev, void *data)
1553 {
1554         int rc1;
1555         int rc2;
1556
1557         struct obd_notify_upcall *onu;
1558
1559         if (observer->obd_observer)
1560                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1561         else
1562                 rc1 = 0;
1563         /*
1564          * Also, call non-obd listener, if any
1565          */
1566         onu = &observer->obd_upcall;
1567         if (onu->onu_upcall != NULL)
1568                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1569         else
1570                 rc2 = 0;
1571
1572         return rc1 ?: rc2;
1573  }
1574
1575 static inline int obd_quotacheck(struct obd_export *exp,
1576                                  struct obd_quotactl *oqctl)
1577 {
1578         int rc;
1579         ENTRY;
1580
1581         EXP_CHECK_OP(exp, quotacheck);
1582         EXP_COUNTER_INCREMENT(exp, quotacheck);
1583
1584         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1585         RETURN(rc);
1586 }
1587
1588 static inline int obd_quotactl(struct obd_export *exp,
1589                                struct obd_quotactl *oqctl)
1590 {
1591         int rc;
1592         ENTRY;
1593
1594         EXP_CHECK_OP(exp, quotactl);
1595         EXP_COUNTER_INCREMENT(exp, quotactl);
1596
1597         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1598         RETURN(rc);
1599 }
1600
1601 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1602                                          struct quota_adjust_qunit *oqaq,
1603                                          struct lustre_quota_ctxt *qctxt)
1604 {
1605 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1606         struct timeval work_start;
1607         struct timeval work_end;
1608         long timediff;
1609 #endif
1610         int rc;
1611         ENTRY;
1612
1613 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1614         if (qctxt)
1615                 do_gettimeofday(&work_start);
1616 #endif
1617         EXP_CHECK_OP(exp, quota_adjust_qunit);
1618         EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1619
1620         rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1621
1622 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1623         if (qctxt) {
1624                 do_gettimeofday(&work_end);
1625                 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1626                 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1627                                     timediff);
1628         }
1629 #endif
1630         RETURN(rc);
1631 }
1632
1633 static inline int obd_health_check(struct obd_device *obd)
1634 {
1635         /* returns: 0 on healthy
1636          *         >0 on unhealthy + reason code/flag
1637          *            however the only suppored reason == 1 right now
1638          *            We'll need to define some better reasons
1639          *            or flags in the future.
1640          *         <0 on error
1641          */
1642         int rc;
1643         ENTRY;
1644
1645         /* don't use EXP_CHECK_OP, because NULL method is normal here */
1646         if (obd == NULL || !OBT(obd)) {
1647                 CERROR("cleaned up obd\n");
1648                 RETURN(-EOPNOTSUPP);
1649         }
1650         if (!obd->obd_set_up || obd->obd_stopping)
1651                 RETURN(0);
1652         if (!OBP(obd, health_check))
1653                 RETURN(0);
1654
1655         rc = OBP(obd, health_check)(obd);
1656         RETURN(rc);
1657 }
1658
1659 static inline int obd_register_observer(struct obd_device *obd,
1660                                         struct obd_device *observer)
1661 {
1662         ENTRY;
1663         OBD_CHECK_DEV(obd);
1664         down_write(&obd->obd_observer_link_sem);
1665         if (obd->obd_observer && observer) {
1666                 up_write(&obd->obd_observer_link_sem);
1667                 RETURN(-EALREADY);
1668         }
1669         obd->obd_observer = observer;
1670         up_write(&obd->obd_observer_link_sem);
1671         RETURN(0);
1672 }
1673
1674 static inline int obd_pin_observer(struct obd_device *obd,
1675                                    struct obd_device **observer)
1676 {
1677         ENTRY;
1678         down_read(&obd->obd_observer_link_sem);
1679         if (!obd->obd_observer) {
1680                 *observer = NULL;
1681                 up_read(&obd->obd_observer_link_sem);
1682                 RETURN(-ENOENT);
1683         }
1684         *observer = obd->obd_observer;
1685         RETURN(0);
1686 }
1687
1688 static inline int obd_unpin_observer(struct obd_device *obd)
1689 {
1690         ENTRY;
1691         up_read(&obd->obd_observer_link_sem);
1692         RETURN(0);
1693 }
1694
1695 static inline int obd_register_page_removal_cb(struct obd_device *obd,
1696                                                obd_page_removal_cb_t cb,
1697                                                obd_pin_extent_cb pin_cb)
1698 {
1699         int rc;
1700         ENTRY;
1701
1702         OBD_CHECK_OP(obd, register_page_removal_cb, 0);
1703         OBD_COUNTER_INCREMENT(obd, register_page_removal_cb);
1704
1705         rc = OBP(obd, register_page_removal_cb)(obd, cb, pin_cb);
1706         RETURN(rc);
1707 }
1708
1709 static inline int obd_unregister_page_removal_cb(struct obd_device *obd,
1710                                                  obd_page_removal_cb_t cb)
1711 {
1712         int rc;
1713         ENTRY;
1714
1715         OBD_CHECK_OP(obd, unregister_page_removal_cb, 0);
1716         OBD_COUNTER_INCREMENT(obd, unregister_page_removal_cb);
1717
1718         rc = OBP(obd, unregister_page_removal_cb)(obd, cb);
1719         RETURN(rc);
1720 }
1721
1722 static inline int obd_register_lock_cancel_cb(struct obd_device *obd,
1723                                               obd_lock_cancel_cb cb)
1724 {
1725         int rc;
1726         ENTRY;
1727
1728         OBD_CHECK_OP(obd, register_lock_cancel_cb, 0);
1729         OBD_COUNTER_INCREMENT(obd, register_lock_cancel_cb);
1730
1731         rc = OBP(obd, register_lock_cancel_cb)(obd, cb);
1732         RETURN(rc);
1733 }
1734
1735 static inline int obd_unregister_lock_cancel_cb(struct obd_device *obd,
1736                                                  obd_lock_cancel_cb cb)
1737 {
1738         int rc;
1739         ENTRY;
1740
1741         OBD_CHECK_OP(obd, unregister_lock_cancel_cb, 0);
1742         OBD_COUNTER_INCREMENT(obd, unregister_lock_cancel_cb);
1743
1744         rc = OBP(obd, unregister_lock_cancel_cb)(obd, cb);
1745         RETURN(rc);
1746 }
1747
1748 /* OBD Metadata Support */
1749
1750 extern int obd_init_caches(void);
1751 extern void obd_cleanup_caches(void);
1752
1753 /* support routines */
1754 extern cfs_mem_cache_t *obdo_cachep;
1755
1756 #define OBDO_ALLOC(ptr)                                                       \
1757 do {                                                                          \
1758         OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep);                               \
1759 } while(0)
1760
1761 #define OBDO_FREE(ptr)                                                        \
1762 do {                                                                          \
1763         OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
1764 } while(0)
1765
1766 /* I'm as embarrassed about this as you are.
1767  *
1768  * <shaver> // XXX do not look into _superhack with remaining eye
1769  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1770 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1771
1772 /* sysctl.c */
1773 extern void obd_sysctl_init (void);
1774 extern void obd_sysctl_clean (void);
1775
1776 /* uuid.c  */
1777 typedef __u8 class_uuid_t[16];
1778 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1779
1780 /* lustre_peer.c    */
1781 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index);
1782 int class_add_uuid(char *uuid, __u64 nid);
1783 int class_del_uuid (char *uuid);
1784 void class_init_uuidlist(void);
1785 void class_exit_uuidlist(void);
1786
1787 /* prng.c */
1788 void ll_generate_random_uuid(class_uuid_t uuid_out);
1789
1790 #endif /* __LINUX_OBD_CLASS_H */