Whamcloud - gitweb
Branch HEAD
[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 #ifndef __CLASS_OBD_H
23 #define __CLASS_OBD_H
24
25 #ifndef __KERNEL__
26 # include <liblustre.h>
27 #endif
28
29 #include <obd_support.h>
30 #include <lustre_import.h>
31 #include <lustre_net.h>
32 #include <obd.h>
33 #include <lustre_lib.h>
34 #include <lustre/lustre_idl.h>
35 #include <lprocfs_status.h>
36
37 #if defined(__linux__)
38 #include <linux/obd_class.h>
39 #elif defined(__APPLE__)
40 #include <darwin/obd_class.h>
41 #elif defined(__WINNT__)
42 #include <winnt/obd_class.h>
43 #else
44 #error Unsupported operating system.
45 #endif
46
47 /* OBD Device Declarations */
48 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
49 extern spinlock_t obd_dev_lock;
50
51 /* OBD Operations Declarations */
52 extern struct obd_device *class_conn2obd(struct lustre_handle *);
53 extern struct obd_device *class_exp2obd(struct obd_export *);
54
55 struct lu_device_type;
56
57 /* genops.c */
58 struct obd_export *class_conn2export(struct lustre_handle *);
59 int class_register_type(struct obd_ops *, struct md_ops *,
60                         struct lprocfs_vars *, const char *nm,
61                         struct lu_device_type *ldt);
62 int class_unregister_type(const char *nm);
63
64 struct obd_device *class_newdev(const char *type_name, const char *name);
65 void class_release_dev(struct obd_device *obd);
66
67 int class_name2dev(const char *name);
68 struct obd_device *class_name2obd(const char *name);
69 int class_uuid2dev(struct obd_uuid *uuid);
70 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
71 void class_obd_list(void);
72 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
73                                           const char * typ_name,
74                                           struct obd_uuid *grp_uuid);
75 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
76                                              struct obd_uuid *grp_uuid);
77 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
78                                            int *next);
79 struct obd_device * class_num2obd(int num);
80
81 int oig_init(struct obd_io_group **oig);
82 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
83 void oig_complete_one(struct obd_io_group *oig,
84                       struct oig_callback_context *occ, int rc);
85 void oig_release(struct obd_io_group *oig);
86 int oig_wait(struct obd_io_group *oig);
87
88 char *obd_export_nid2str(struct obd_export *exp);
89
90 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
91 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
92
93 int obd_zombie_impexp_init(void);
94 void obd_zombie_impexp_stop(void);
95 void obd_zombie_impexp_cull(void);
96
97 /* obd_config.c */
98 int class_process_config(struct lustre_cfg *lcfg);
99 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
100                              struct lustre_cfg *lcfg, void *data);
101 int class_attach(struct lustre_cfg *lcfg);
102 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
103 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
104 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
105 struct obd_device *class_incref(struct obd_device *obd);
106 void class_decref(struct obd_device *obd);
107
108 /*obdecho*/
109 #ifdef LPROCFS
110 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
111 #else
112 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
113 {
114         memset(lvars, 0, sizeof(*lvars));
115 }
116 #endif
117
118 #define CFG_F_START     0x01   /* Set when we start updating from a log */
119 #define CFG_F_MARKER    0x02   /* We are within a maker */
120 #define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
121 #define CFG_F_COMPAT146 0x08   /* Allow old-style logs */
122 #define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
123
124 /* Passed as data param to class_config_parse_llog */
125 struct config_llog_instance {
126         char *              cfg_instance;
127         struct super_block *cfg_sb;
128         struct obd_uuid     cfg_uuid;
129         int                 cfg_last_idx; /* for partial llog processing */
130         int                 cfg_flags;
131 };
132 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
133                             struct config_llog_instance *cfg);
134 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
135                            struct config_llog_instance *cfg);
136
137 /* list of active configuration logs  */
138 struct config_llog_data {
139         char               *cld_logname;
140         struct ldlm_res_id  cld_resid;
141         struct config_llog_instance cld_cfg;
142         struct list_head    cld_list_chain;
143         atomic_t            cld_refcount;
144         struct obd_export  *cld_mgcexp;
145         unsigned int        cld_stopping:1, /* we were told to stop watching */
146                             cld_lostlock:1; /* lock not requeued */
147 };
148
149 struct lustre_profile {
150         struct list_head lp_list;
151         char            *lp_profile;
152         char            *lp_dt;
153         char            *lp_md;
154 };
155
156 struct lustre_profile *class_get_profile(const char * prof);
157 void class_del_profile(const char *prof);
158 void class_del_profiles(void);
159
160 #define class_export_rpc_get(exp)                                       \
161 ({                                                                      \
162         atomic_inc(&(exp)->exp_rpc_count);                              \
163         CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",    \
164                (exp), atomic_read(&(exp)->exp_rpc_count));              \
165         class_export_get(exp);                                          \
166 })
167
168 #define class_export_rpc_put(exp)                                       \
169 ({                                                                      \
170         atomic_dec(&(exp)->exp_rpc_count);                              \
171         CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",    \
172                (exp), atomic_read(&(exp)->exp_rpc_count));              \
173         class_export_put(exp);                                          \
174 })
175
176 /* genops.c */
177 #define class_export_get(exp)                                                  \
178 ({                                                                             \
179         struct obd_export *exp_ = exp;                                         \
180         atomic_inc(&exp_->exp_refcount);                                       \
181         CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_,          \
182                atomic_read(&exp_->exp_refcount));                              \
183         exp_;                                                                  \
184 })
185
186 #define class_export_put(exp)                                                  \
187 do {                                                                           \
188         LASSERT((exp) != NULL);                                                \
189         CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp),         \
190                atomic_read(&(exp)->exp_refcount) - 1);                         \
191         LASSERT(atomic_read(&(exp)->exp_refcount) > 0);                        \
192         LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a);                 \
193         __class_export_put(exp);                                               \
194 } while (0)
195
196 void __class_export_put(struct obd_export *);
197 struct obd_export *class_new_export(struct obd_device *obddev,
198                                     struct obd_uuid *cluuid);
199 void class_unlink_export(struct obd_export *exp);
200
201 struct obd_import *class_import_get(struct obd_import *);
202 void class_import_put(struct obd_import *);
203 struct obd_import *class_new_import(struct obd_device *obd);
204 void class_destroy_import(struct obd_import *exp);
205
206 struct obd_type *class_search_type(const char *name);
207 struct obd_type *class_get_type(const char *name);
208 void class_put_type(struct obd_type *type);
209 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
210                   struct obd_uuid *cluuid);
211 int class_disconnect(struct obd_export *exp);
212 void class_fail_export(struct obd_export *exp);
213 void class_disconnect_exports(struct obd_device *obddev);
214 int class_disconnect_stale_exports(struct obd_device *,
215                                     int (*test_export)(struct obd_export *));
216 int class_manual_cleanup(struct obd_device *obd);
217
218 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
219 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
220 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
221                      unsigned int ia_valid);
222 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
223 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
224 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
225                   unsigned int valid);
226
227 #define OBT(dev)        (dev)->obd_type
228 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
229 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
230 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
231
232 /* Ensure obd_setup: used for cleanup which must be called
233    while obd is stopping */
234 #define OBD_CHECK_DEV(obd)                                      \
235 do {                                                            \
236         if (!(obd)) {                                           \
237                 CERROR("NULL device\n");                        \
238                 RETURN(-ENODEV);                                \
239         }                                                       \
240 } while (0)
241
242 /* ensure obd_setup and !obd_stopping */
243 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
244 do {                                                            \
245         OBD_CHECK_DEV(obd);                                     \
246         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
247                 CERROR("Device %d not setup\n",                 \
248                        (obd)->obd_minor);                       \
249                 RETURN(-ENODEV);                                \
250         }                                                       \
251 } while (0)
252
253
254 #ifdef LPROCFS
255 #define OBD_COUNTER_OFFSET(op)                                  \
256         ((offsetof(struct obd_ops, o_ ## op) -                  \
257           offsetof(struct obd_ops, o_iocontrol))                \
258          / sizeof(((struct obd_ops *)(0))->o_iocontrol))
259
260 #define OBD_COUNTER_INCREMENT(obdx, op)                           \
261         if ((obdx)->obd_stats != NULL) {                          \
262                 unsigned int coffset;                             \
263                 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
264                         OBD_COUNTER_OFFSET(op);                   \
265                 LASSERT(coffset < (obdx)->obd_stats->ls_num);     \
266                 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
267         }
268
269 #define EXP_COUNTER_INCREMENT(export, op)                                    \
270         if ((export)->exp_obd->obd_stats != NULL) {                          \
271                 unsigned int coffset;                                        \
272                 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
273                         OBD_COUNTER_OFFSET(op);                              \
274                 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num);     \
275                 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
276                 if ((export)->exp_nid_stats != NULL &&                       \
277                     (export)->exp_nid_stats->nid_stats != NULL)              \
278                         lprocfs_counter_incr(                                \
279                                 (export)->exp_nid_stats->nid_stats, coffset);\
280         }
281
282 #define MD_COUNTER_OFFSET(op)                                   \
283         ((offsetof(struct md_ops, m_ ## op) -                   \
284           offsetof(struct md_ops, m_getstatus))                 \
285          / sizeof(((struct md_ops *)(0))->m_getstatus))
286
287 #define MD_COUNTER_INCREMENT(obdx, op)                           \
288         if ((obd)->md_stats != NULL) {                           \
289                 unsigned int coffset;                            \
290                 coffset = (unsigned int)((obdx)->md_cntr_base) + \
291                         MD_COUNTER_OFFSET(op);                   \
292                 LASSERT(coffset < (obdx)->md_stats->ls_num);     \
293                 lprocfs_counter_incr((obdx)->md_stats, coffset); \
294         }
295
296 #define EXP_MD_COUNTER_INCREMENT(export, op)                                 \
297         if ((export)->exp_obd->obd_stats != NULL) {                          \
298                 unsigned int coffset;                                        \
299                 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) +  \
300                         MD_COUNTER_OFFSET(op);                               \
301                 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num);      \
302                 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset);  \
303                 if ((export)->exp_md_stats != NULL)                          \
304                         lprocfs_counter_incr(                                \
305                                 (export)->exp_md_stats, coffset);            \
306         }
307
308 #else
309 #define OBD_COUNTER_OFFSET(op)
310 #define OBD_COUNTER_INCREMENT(obd, op)
311 #define EXP_COUNTER_INCREMENT(exp, op)
312 #define MD_COUNTER_INCREMENT(obd, op)
313 #define EXP_MD_COUNTER_INCREMENT(exp, op)
314 #endif
315
316 #define OBD_CHECK_MD_OP(obd, op, err)                           \
317 do {                                                            \
318         if (!OBT(obd) || !MDP((obd), op)) {                     \
319                 if (err)                                        \
320                         CERROR("md_" #op ": dev %s/%d no operation\n", \
321                                obd->obd_name, obd->obd_minor);  \
322                 RETURN(err);                                    \
323         }                                                       \
324 } while (0)
325
326 #define EXP_CHECK_MD_OP(exp, op)                                \
327 do {                                                            \
328         if ((exp) == NULL) {                                    \
329                 CERROR("obd_" #op ": NULL export\n");           \
330                 RETURN(-ENODEV);                                \
331         }                                                       \
332         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
333                 CERROR("obd_" #op ": cleaned up obd\n");        \
334                 RETURN(-EOPNOTSUPP);                            \
335         }                                                       \
336         if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
337                 CERROR("obd_" #op ": dev %s/%d no operation\n", \
338                        (exp)->exp_obd->obd_name,                \
339                        (exp)->exp_obd->obd_minor);              \
340                 RETURN(-EOPNOTSUPP);                            \
341         }                                                       \
342 } while (0)
343
344
345 #define OBD_CHECK_DT_OP(obd, op, err)                           \
346 do {                                                            \
347         if (!OBT(obd) || !OBP((obd), op)) {                     \
348                 if (err)                                        \
349                         CERROR("obd_" #op ": dev %d no operation\n",    \
350                                obd->obd_minor);                 \
351                 RETURN(err);                                    \
352         }                                                       \
353 } while (0)
354
355 #define EXP_CHECK_DT_OP(exp, op)                                \
356 do {                                                            \
357         if ((exp) == NULL) {                                    \
358                 CERROR("obd_" #op ": NULL export\n");           \
359                 RETURN(-ENODEV);                                \
360         }                                                       \
361         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
362                 CERROR("obd_" #op ": cleaned up obd\n");        \
363                 RETURN(-EOPNOTSUPP);                            \
364         }                                                       \
365         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
366                 CERROR("obd_" #op ": dev %d no operation\n",    \
367                        (exp)->exp_obd->obd_minor);              \
368                 RETURN(-EOPNOTSUPP);                            \
369         }                                                       \
370 } while (0)
371
372 #define CTXT_CHECK_OP(ctxt, op, err)                                 \
373 do {                                                                 \
374         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {             \
375                 if (err)                                             \
376                         CERROR("lop_" #op ": dev %d no operation\n", \
377                                ctxt->loc_obd->obd_minor);            \
378                 RETURN(err);                                         \
379         }                                                            \
380 } while (0)
381
382 static inline int class_devno_max(void)
383 {
384         return MAX_OBD_DEVICES;
385 }
386
387 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
388                                void *key, __u32 *vallen, void *val)
389 {
390         int rc;
391         ENTRY;
392
393         EXP_CHECK_DT_OP(exp, get_info);
394         EXP_COUNTER_INCREMENT(exp, get_info);
395
396         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
397         RETURN(rc);
398 }
399
400 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
401                                      void *key, obd_count vallen, void *val,
402                                      struct ptlrpc_request_set *set)
403 {
404         int rc;
405         ENTRY;
406
407         EXP_CHECK_DT_OP(exp, set_info_async);
408         EXP_COUNTER_INCREMENT(exp, set_info_async);
409
410         rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
411                                                set);
412         RETURN(rc);
413 }
414
415 #ifdef __KERNEL__
416 #define DECLARE_LU_VARS(ldt, d)                 \
417         struct lu_device_type *ldt;             \
418         struct lu_device *d
419 #else
420 #define DECLARE_LU_VARS(ldt, d)                                 \
421         extern void __placeholder_to_put_a_semicolon(void)
422 #endif
423 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
424 {
425         int rc;
426         DECLARE_LU_VARS(ldt, d);
427         ENTRY;
428
429 #ifdef __KERNEL__
430         ldt = obd->obd_type->typ_lu;
431         if (ldt != NULL) {
432                 struct lu_env env;
433
434                 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
435                 if (rc == 0) {
436                         d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
437                         lu_env_fini(&env);
438                         if (!IS_ERR(d)) {
439                                 obd->obd_lu_dev = d;
440                                 d->ld_obd = obd;
441                                 rc = 0;
442                         } else
443                                 rc = PTR_ERR(d);
444                 }
445         } else
446 #endif
447         {
448                 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
449                 OBD_COUNTER_INCREMENT(obd, setup);
450                 rc = OBP(obd, setup)(obd, cfg);
451         }
452         RETURN(rc);
453 }
454
455 static inline int obd_precleanup(struct obd_device *obd,
456                                  enum obd_cleanup_stage cleanup_stage)
457 {
458         int rc;
459         DECLARE_LU_VARS(ldt, d);
460         ENTRY;
461
462         OBD_CHECK_DEV(obd);
463 #ifdef __KERNEL__
464         ldt = obd->obd_type->typ_lu;
465         d = obd->obd_lu_dev;
466         if (ldt != NULL) {
467                 LASSERT(d != NULL);
468                 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
469                         struct lu_env env;
470
471                         rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
472                         if (rc == 0) {
473                                 ldt->ldt_ops->ldto_device_fini(&env, d);
474                                 lu_env_fini(&env);
475                         }
476                 } else {
477                         rc = 0;
478                 }
479         } else
480 #endif
481         {
482                 OBD_CHECK_DT_OP(obd, precleanup, 0);
483                 rc = OBP(obd, precleanup)(obd, cleanup_stage);
484         }
485
486         OBD_COUNTER_INCREMENT(obd, precleanup);
487         RETURN(rc);
488 }
489
490 static inline int obd_cleanup(struct obd_device *obd)
491 {
492         int rc;
493         DECLARE_LU_VARS(ldt, d);
494         ENTRY;
495
496         OBD_CHECK_DEV(obd);
497
498 #ifdef __KERNEL__
499         ldt = obd->obd_type->typ_lu;
500         d = obd->obd_lu_dev;
501         if (ldt != NULL) {
502                 struct lu_env env;
503                 LASSERT(d != NULL);
504
505                 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
506                 if (rc == 0) {
507                         ldt->ldt_ops->ldto_device_free(&env, d);
508                         lu_env_fini(&env);
509                         obd->obd_lu_dev = NULL;
510                 }
511         } else
512 #endif
513         {
514                 OBD_CHECK_DT_OP(obd, cleanup, 0);
515                 rc = OBP(obd, cleanup)(obd);
516         }
517         OBD_COUNTER_INCREMENT(obd, cleanup);
518         RETURN(rc);
519 }
520
521 static inline int
522 obd_process_config(struct obd_device *obd, int datalen, void *data)
523 {
524         int rc;
525         DECLARE_LU_VARS(ldt, d);
526         ENTRY;
527
528         OBD_CHECK_DEV(obd);
529
530 #ifdef __KERNEL__
531         ldt = obd->obd_type->typ_lu;
532         d = obd->obd_lu_dev;
533         if (ldt != NULL && d != NULL) {
534                 struct lu_env env;
535
536                 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
537                 if (rc == 0) {
538                         rc = d->ld_ops->ldo_process_config(&env, d, data);
539                         lu_env_fini(&env);
540                 }
541         } else
542 #endif
543         {
544                 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
545                 rc = OBP(obd, process_config)(obd, datalen, data);
546         }
547         OBD_COUNTER_INCREMENT(obd, process_config);
548
549         RETURN(rc);
550 }
551
552 /* Pack an in-memory MD struct for storage on disk.
553  * Returns +ve size of packed MD (0 for free), or -ve error.
554  *
555  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
556  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
557  * If @*disk_tgt == NULL, it will be allocated
558  */
559 static inline int obd_packmd(struct obd_export *exp,
560                              struct lov_mds_md **disk_tgt,
561                              struct lov_stripe_md *mem_src)
562 {
563         int rc;
564         ENTRY;
565
566         EXP_CHECK_DT_OP(exp, packmd);
567         EXP_COUNTER_INCREMENT(exp, packmd);
568
569         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
570         RETURN(rc);
571 }
572
573 static inline int obd_size_diskmd(struct obd_export *exp,
574                                   struct lov_stripe_md *mem_src)
575 {
576         return obd_packmd(exp, NULL, mem_src);
577 }
578
579 /* helper functions */
580 static inline int obd_alloc_diskmd(struct obd_export *exp,
581                                    struct lov_mds_md **disk_tgt)
582 {
583         LASSERT(disk_tgt);
584         LASSERT(*disk_tgt == NULL);
585         return obd_packmd(exp, disk_tgt, NULL);
586 }
587
588 static inline int obd_free_diskmd(struct obd_export *exp,
589                                   struct lov_mds_md **disk_tgt)
590 {
591         LASSERT(disk_tgt);
592         LASSERT(*disk_tgt);
593         return obd_packmd(exp, disk_tgt, NULL);
594 }
595
596 /* Unpack an MD struct from disk to in-memory format.
597  * Returns +ve size of unpacked MD (0 for free), or -ve error.
598  *
599  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
600  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
601  * If @*mem_tgt == NULL, it will be allocated
602  */
603 static inline int obd_unpackmd(struct obd_export *exp,
604                                struct lov_stripe_md **mem_tgt,
605                                struct lov_mds_md *disk_src,
606                                int disk_len)
607 {
608         int rc;
609         ENTRY;
610
611         EXP_CHECK_DT_OP(exp, unpackmd);
612         EXP_COUNTER_INCREMENT(exp, unpackmd);
613
614         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
615         RETURN(rc);
616 }
617
618 /* helper functions */
619 static inline int obd_alloc_memmd(struct obd_export *exp,
620                                   struct lov_stripe_md **mem_tgt)
621 {
622         LASSERT(mem_tgt);
623         LASSERT(*mem_tgt == NULL);
624         return obd_unpackmd(exp, mem_tgt, NULL, 0);
625 }
626
627 static inline int obd_free_memmd(struct obd_export *exp,
628                                  struct lov_stripe_md **mem_tgt)
629 {
630         LASSERT(mem_tgt);
631         LASSERT(*mem_tgt);
632         return obd_unpackmd(exp, mem_tgt, NULL, 0);
633 }
634
635 static inline int obd_checkmd(struct obd_export *exp,
636                               struct obd_export *md_exp,
637                               struct lov_stripe_md *mem_tgt)
638 {
639         int rc;
640         ENTRY;
641
642         EXP_CHECK_DT_OP(exp, checkmd);
643         EXP_COUNTER_INCREMENT(exp, checkmd);
644
645         rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
646         RETURN(rc);
647 }
648
649 static inline int obd_precreate(struct obd_export *exp)
650 {
651         int rc;
652         ENTRY;
653
654         EXP_CHECK_DT_OP(exp, precreate);
655         OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
656
657         rc = OBP(exp->exp_obd, precreate)(exp);
658         RETURN(rc);
659 }
660
661 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
662                              struct lov_stripe_md **ea,
663                              struct obd_trans_info *oti)
664 {
665         int rc;
666         ENTRY;
667
668         EXP_CHECK_DT_OP(exp, create);
669         EXP_COUNTER_INCREMENT(exp, create);
670
671         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
672         RETURN(rc);
673 }
674
675 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
676                               struct lov_stripe_md *ea,
677                               struct obd_trans_info *oti,
678                               struct obd_export *md_exp)
679 {
680         int rc;
681         ENTRY;
682
683         EXP_CHECK_DT_OP(exp, destroy);
684         EXP_COUNTER_INCREMENT(exp, destroy);
685
686         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
687         RETURN(rc);
688 }
689
690 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
691 {
692         int rc;
693         ENTRY;
694
695         EXP_CHECK_DT_OP(exp, getattr);
696         EXP_COUNTER_INCREMENT(exp, getattr);
697
698         rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
699         RETURN(rc);
700 }
701
702 static inline int obd_getattr_async(struct obd_export *exp,
703                                     struct obd_info *oinfo,
704                                     struct ptlrpc_request_set *set)
705 {
706         int rc;
707         ENTRY;
708
709         EXP_CHECK_DT_OP(exp, getattr_async);
710         EXP_COUNTER_INCREMENT(exp, getattr_async);
711
712         rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
713         RETURN(rc);
714 }
715
716 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
717                               struct obd_trans_info *oti)
718 {
719         int rc;
720         ENTRY;
721
722         EXP_CHECK_DT_OP(exp, setattr);
723         EXP_COUNTER_INCREMENT(exp, setattr);
724
725         rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
726         RETURN(rc);
727 }
728
729 /* This performs all the requests set init/wait/destroy actions. */
730 static inline int obd_setattr_rqset(struct obd_export *exp,
731                                     struct obd_info *oinfo,
732                                     struct obd_trans_info *oti)
733 {
734         struct ptlrpc_request_set *set = NULL;
735         int rc;
736         ENTRY;
737
738         EXP_CHECK_DT_OP(exp, setattr_async);
739         EXP_COUNTER_INCREMENT(exp, setattr_async);
740
741         set =  ptlrpc_prep_set();
742         if (set == NULL)
743                 RETURN(-ENOMEM);
744
745         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
746         if (rc == 0)
747                 rc = ptlrpc_set_wait(set);
748         ptlrpc_set_destroy(set);
749         RETURN(rc);
750 }
751
752 /* This adds all the requests into @set if @set != NULL, otherwise
753    all requests are sent asynchronously without waiting for response. */
754 static inline int obd_setattr_async(struct obd_export *exp,
755                                     struct obd_info *oinfo,
756                                     struct obd_trans_info *oti,
757                                     struct ptlrpc_request_set *set)
758 {
759         int rc;
760         ENTRY;
761
762         EXP_CHECK_DT_OP(exp, setattr_async);
763         EXP_COUNTER_INCREMENT(exp, setattr_async);
764
765         rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
766         RETURN(rc);
767 }
768
769 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
770                                int priority)
771 {
772         struct obd_device *obd = imp->imp_obd;
773         int rc;
774         ENTRY;
775
776         OBD_CHECK_DEV_ACTIVE(obd);
777         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
778         OBD_COUNTER_INCREMENT(obd, add_conn);
779
780         rc = OBP(obd, add_conn)(imp, uuid, priority);
781         RETURN(rc);
782 }
783
784 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
785 {
786         struct obd_device *obd = imp->imp_obd;
787         int rc;
788         ENTRY;
789
790         OBD_CHECK_DEV_ACTIVE(obd);
791         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
792         OBD_COUNTER_INCREMENT(obd, del_conn);
793
794         rc = OBP(obd, del_conn)(imp, uuid);
795         RETURN(rc);
796 }
797
798 static inline int obd_connect(const struct lu_env *env,
799                               struct lustre_handle *conn,struct obd_device *obd,
800                               struct obd_uuid *cluuid,
801                               struct obd_connect_data *d,
802                               void *localdata)
803 {
804         int rc;
805 #ifdef LIBCFS_DEBUG
806         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
807                                                    * check */
808 #endif
809         ENTRY;
810
811         OBD_CHECK_DEV_ACTIVE(obd);
812         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
813         OBD_COUNTER_INCREMENT(obd, connect);
814
815         rc = OBP(obd, connect)(env, conn, obd, cluuid, d, localdata);
816         /* check that only subset is granted */
817         LASSERT(ergo(d != NULL,
818                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
819         RETURN(rc);
820 }
821
822 static inline int obd_reconnect(const struct lu_env *env,
823                                 struct obd_export *exp,
824                                 struct obd_device *obd,
825                                 struct obd_uuid *cluuid,
826                                 struct obd_connect_data *d)
827 {
828         int rc;
829 #ifdef LIBCFS_DEBUG
830         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
831                                                    * check */
832 #endif
833
834         ENTRY;
835
836         OBD_CHECK_DEV_ACTIVE(obd);
837         OBD_CHECK_DT_OP(obd, reconnect, 0);
838         OBD_COUNTER_INCREMENT(obd, reconnect);
839
840         rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d);
841         /* check that only subset is granted */
842         LASSERT(ergo(d != NULL,
843                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
844         RETURN(rc);
845 }
846
847 static inline int obd_disconnect(struct obd_export *exp)
848 {
849         int rc;
850         ENTRY;
851
852         EXP_CHECK_DT_OP(exp, disconnect);
853         EXP_COUNTER_INCREMENT(exp, disconnect);
854
855         rc = OBP(exp->exp_obd, disconnect)(exp);
856         RETURN(rc);
857 }
858
859 static inline int obd_fid_init(struct obd_export *exp)
860 {
861         int rc;
862         ENTRY;
863
864         OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
865         EXP_COUNTER_INCREMENT(exp, fid_init);
866
867         rc = OBP(exp->exp_obd, fid_init)(exp);
868         RETURN(rc);
869 }
870
871 static inline int obd_fid_fini(struct obd_export *exp)
872 {
873         int rc;
874         ENTRY;
875
876         OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
877         EXP_COUNTER_INCREMENT(exp, fid_fini);
878
879         rc = OBP(exp->exp_obd, fid_fini)(exp);
880         RETURN(rc);
881 }
882
883 static inline int obd_fid_alloc(struct obd_export *exp,
884                                 struct lu_fid *fid,
885                                 struct md_op_data *op_data)
886 {
887         int rc;
888         ENTRY;
889
890         EXP_CHECK_DT_OP(exp, fid_alloc);
891         EXP_COUNTER_INCREMENT(exp, fid_alloc);
892
893         rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
894         RETURN(rc);
895 }
896
897 static inline int obd_fid_delete(struct obd_export *exp,
898                                  const struct lu_fid *fid)
899 {
900         int rc;
901         ENTRY;
902
903         EXP_CHECK_DT_OP(exp, fid_delete);
904         EXP_COUNTER_INCREMENT(exp, fid_delete);
905
906         rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
907         RETURN(rc);
908 }
909
910 static inline int obd_ping(struct obd_export *exp)
911 {
912         int rc;
913         ENTRY;
914
915         OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
916         EXP_COUNTER_INCREMENT(exp, ping);
917
918         rc = OBP(exp->exp_obd, ping)(exp);
919         RETURN(rc);
920 }
921
922 static inline int obd_init_export(struct obd_export *exp)
923 {
924         int rc = 0;
925
926         ENTRY;
927         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
928             OBP((exp)->exp_obd, init_export))
929                 rc = OBP(exp->exp_obd, init_export)(exp);
930         RETURN(rc);
931 }
932
933 static inline int obd_destroy_export(struct obd_export *exp)
934 {
935         ENTRY;
936         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
937             OBP((exp)->exp_obd, destroy_export))
938                 OBP(exp->exp_obd, destroy_export)(exp);
939         RETURN(0);
940 }
941
942 static inline int obd_extent_calc(struct obd_export *exp,
943                                   struct lov_stripe_md *md,
944                                   int cmd, obd_off *offset)
945 {
946         int rc;
947         ENTRY;
948         EXP_CHECK_DT_OP(exp, extent_calc);
949         rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
950         RETURN(rc);
951 }
952
953 static inline struct dentry *
954 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
955 {
956         LASSERT(exp->exp_obd);
957
958         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
959                                exp->exp_obd);
960 }
961
962 static inline int
963 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
964 {
965         LASSERT(exp->exp_obd);
966         CERROR("FIXME what's the story here?  This needs to be an obd fn?\n");
967 #if 0
968         return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
969                               dentry, exp->exp_obd);
970 #endif
971         return 0;
972 }
973
974 #ifndef time_before
975 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
976 #endif
977
978 /* @max_age is the oldest time in jiffies that we accept using a cached data.
979  * If the cache is older than @max_age we will get a new value from the
980  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
981 static inline int obd_statfs_async(struct obd_device *obd,
982                                    struct obd_info *oinfo,
983                                    __u64 max_age,
984                                    struct ptlrpc_request_set *rqset)
985 {
986         int rc = 0;
987         ENTRY;
988
989         if (obd == NULL)
990                 RETURN(-EINVAL);
991
992         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
993         OBD_COUNTER_INCREMENT(obd, statfs);
994
995         CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
996                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
997         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
998                 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
999         } else {
1000                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1001                        " objects "LPU64"/"LPU64"\n",
1002                        obd->obd_name, &obd->obd_osfs,
1003                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1004                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1005                 spin_lock(&obd->obd_osfs_lock);
1006                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1007                 spin_unlock(&obd->obd_osfs_lock);
1008                 if (oinfo->oi_cb_up)
1009                         oinfo->oi_cb_up(oinfo, 0);
1010         }
1011         RETURN(rc);
1012 }
1013
1014 static inline int obd_statfs_rqset(struct obd_device *obd,
1015                                    struct obd_statfs *osfs, __u64 max_age,
1016                                    __u32 flags)
1017 {
1018         struct ptlrpc_request_set *set = NULL;
1019         struct obd_info oinfo = { { { 0 } } };
1020         int rc = 0;
1021         ENTRY;
1022
1023         set =  ptlrpc_prep_set();
1024         if (set == NULL)
1025                 RETURN(-ENOMEM);
1026
1027         oinfo.oi_osfs = osfs;
1028         oinfo.oi_flags = flags;
1029         rc = obd_statfs_async(obd, &oinfo, max_age, set);
1030         if (rc == 0)
1031                 rc = ptlrpc_set_wait(set);
1032         ptlrpc_set_destroy(set);
1033         RETURN(rc);
1034 }
1035
1036 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1037  * If the cache is older than @max_age we will get a new value from the
1038  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1039 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1040                              __u64 max_age, __u32 flags)
1041 {
1042         int rc = 0;
1043         ENTRY;
1044
1045         if (obd == NULL)
1046                 RETURN(-EINVAL);
1047
1048         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1049         OBD_COUNTER_INCREMENT(obd, statfs);
1050
1051         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1052                obd->obd_osfs_age, max_age);
1053         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1054                 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1055                 if (rc == 0) {
1056                         spin_lock(&obd->obd_osfs_lock);
1057                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1058                         obd->obd_osfs_age = cfs_time_current_64();
1059                         spin_unlock(&obd->obd_osfs_lock);
1060                 }
1061         } else {
1062                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1063                        " objects "LPU64"/"LPU64"\n",
1064                        obd->obd_name, &obd->obd_osfs,
1065                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1066                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1067                 spin_lock(&obd->obd_osfs_lock);
1068                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1069                 spin_unlock(&obd->obd_osfs_lock);
1070         }
1071         RETURN(rc);
1072 }
1073
1074 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1075                            struct lov_stripe_md *ea, obd_size start,
1076                            obd_size end, void *capa)
1077 {
1078         int rc;
1079         ENTRY;
1080
1081         OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1082         EXP_COUNTER_INCREMENT(exp, sync);
1083
1084         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1085         RETURN(rc);
1086 }
1087
1088 static inline int obd_punch_rqset(struct obd_export *exp,
1089                                   struct obd_info *oinfo,
1090                                   struct obd_trans_info *oti)
1091 {
1092         struct ptlrpc_request_set *set = NULL;
1093         int rc;
1094         ENTRY;
1095
1096         EXP_CHECK_DT_OP(exp, punch);
1097         EXP_COUNTER_INCREMENT(exp, punch);
1098
1099         set =  ptlrpc_prep_set();
1100         if (set == NULL)
1101                 RETURN(-ENOMEM);
1102
1103         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1104         if (rc == 0)
1105                 rc = ptlrpc_set_wait(set);
1106         ptlrpc_set_destroy(set);
1107         RETURN(rc);
1108 }
1109
1110 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1111                             struct obd_trans_info *oti,
1112                             struct ptlrpc_request_set *rqset)
1113 {
1114         int rc;
1115         ENTRY;
1116
1117         EXP_CHECK_DT_OP(exp, punch);
1118         EXP_COUNTER_INCREMENT(exp, punch);
1119
1120         rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1121         RETURN(rc);
1122 }
1123
1124 static inline int obd_brw(int cmd, struct obd_export *exp,
1125                           struct obd_info *oinfo, obd_count oa_bufs,
1126                           struct brw_page *pg, struct obd_trans_info *oti)
1127 {
1128         int rc;
1129         ENTRY;
1130
1131         EXP_CHECK_DT_OP(exp, brw);
1132         EXP_COUNTER_INCREMENT(exp, brw);
1133
1134         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1135                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1136                        "or OBD_BRW_CHECK\n");
1137                 LBUG();
1138         }
1139
1140         rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1141         RETURN(rc);
1142 }
1143
1144 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1145                                 struct obd_info *oinfo, obd_count oa_bufs,
1146                                 struct brw_page *pg, struct obd_trans_info *oti,
1147                                 struct ptlrpc_request_set *set)
1148 {
1149         int rc;
1150         ENTRY;
1151
1152         EXP_CHECK_DT_OP(exp, brw_async);
1153         EXP_COUNTER_INCREMENT(exp, brw_async);
1154
1155         if (!(cmd & OBD_BRW_RWMASK)) {
1156                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1157                 LBUG();
1158         }
1159
1160         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1161         RETURN(rc);
1162 }
1163
1164 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1165                                 struct obdo *oa, struct lov_stripe_md *lsm,
1166                                 obd_count oa_bufs, struct brw_page *pg,
1167                                 struct obd_trans_info *oti,
1168                                 struct obd_capa *ocapa)
1169 {
1170         struct ptlrpc_request_set *set = NULL;
1171         struct obd_info oinfo = { { { 0 } } };
1172         int rc = 0;
1173         ENTRY;
1174
1175         set =  ptlrpc_prep_set();
1176         if (set == NULL)
1177                 RETURN(-ENOMEM);
1178
1179         oinfo.oi_oa = oa;
1180         oinfo.oi_md = lsm;
1181         oinfo.oi_capa = ocapa;
1182         rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1183         if (rc == 0) {
1184                 rc = ptlrpc_set_wait(set);
1185                 if (rc)
1186                         CERROR("error from callback: rc = %d\n", rc);
1187         } else {
1188                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
1189                        "error from obd_brw_async: rc = %d\n", rc);
1190         }
1191         ptlrpc_set_destroy(set);
1192         RETURN(rc);
1193 }
1194
1195 static inline  int obd_prep_async_page(struct obd_export *exp,
1196                                        struct lov_stripe_md *lsm,
1197                                        struct lov_oinfo *loi,
1198                                        cfs_page_t *page, obd_off offset,
1199                                        struct obd_async_page_ops *ops,
1200                                        void *data, void **res, int nocache,
1201                                        struct lustre_handle *lockh)
1202 {
1203         int ret;
1204         ENTRY;
1205
1206         EXP_CHECK_DT_OP(exp, prep_async_page);
1207         EXP_COUNTER_INCREMENT(exp, prep_async_page);
1208
1209         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1210                                                  ops, data, res, nocache,
1211                                                  lockh);
1212         RETURN(ret);
1213 }
1214
1215 /**
1216  * Checks if requested extent lock is compatible with a lock under the page.
1217  *
1218  * Checks if the lock under \a page is compatible with a read or write lock
1219  * (specified by \a rw) for an extent [\a start , \a end].
1220  *
1221  * \param exp obd export (lov or osc)
1222  * \param lsm striping information for the file
1223  * \param res async_page placeholder
1224  * \param rw OBD_BRW_READ if requested for reading,
1225  *           OBD_BRW_WRITE if requested for writing
1226  * \param start start of the requested extent
1227  * \param end end of the requested extent
1228  * \param cookie transparent parameter for passing locking context
1229  *
1230  * \post result == 1, *cookie == context, appropriate lock is referenced or
1231  *
1232  * \retval 1 owned lock is reused for the request
1233  * \retval 0 no lock reused for the request
1234  * \retval -ENOTSUPP reget_short_lock is not exported at this layer
1235  *
1236  * \see obd_release_short_lock
1237  */
1238 static inline int obd_reget_short_lock(struct obd_export *exp,
1239                                        struct lov_stripe_md *lsm,
1240                                        void **res, int rw,
1241                                        obd_off start, obd_off end,
1242                                        void **cookie)
1243 {
1244         ENTRY;
1245
1246         EXP_CHECK_DT_OP(exp, reget_short_lock);
1247         EXP_COUNTER_INCREMENT(exp, reget_short_lock);
1248
1249         RETURN(OBP(exp->exp_obd, reget_short_lock)(exp, lsm, res, rw,
1250                                                    start, end, cookie));
1251 }
1252
1253
1254 /**
1255  * Releases a reference to a lock taken in a "fast" way.
1256  *
1257  * Releases a read or write (specified by \a rw) lock
1258  * referenced by \a cookie.
1259  *
1260  * \param exp obd export (lov or osc)
1261  * \param lsm striping information for the file
1262  * \param end end of the locked extent
1263  * \param rw OBD_BRW_READ if requested for reading,
1264  *           OBD_BRW_WRITE if requested for writing
1265  * \param cookie transparent parameter for passing locking context
1266  *
1267  * \post appropriate lock is dereferenced
1268  *
1269  * \see obd_reget_short_lock
1270  */
1271 static inline int obd_release_short_lock(struct obd_export *exp,
1272                                          struct lov_stripe_md *lsm, obd_off end,
1273                                          void *cookie, int rw)
1274 {
1275         ENTRY;
1276
1277         EXP_CHECK_DT_OP(exp, release_short_lock);
1278         EXP_COUNTER_INCREMENT(exp, release_short_lock);
1279
1280         RETURN(OBP(exp->exp_obd, release_short_lock)(exp, lsm, end,
1281                                                      cookie, rw));
1282 }
1283
1284 static inline int obd_queue_async_io(struct obd_export *exp,
1285                                      struct lov_stripe_md *lsm,
1286                                      struct lov_oinfo *loi, void *cookie,
1287                                      int cmd, obd_off off, int count,
1288                                      obd_flag brw_flags, obd_flag async_flags)
1289 {
1290         int rc;
1291         ENTRY;
1292
1293         EXP_CHECK_DT_OP(exp, queue_async_io);
1294         EXP_COUNTER_INCREMENT(exp, queue_async_io);
1295         LASSERT(cmd & OBD_BRW_RWMASK);
1296
1297         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1298                                                count, brw_flags, async_flags);
1299         RETURN(rc);
1300 }
1301
1302 static inline int obd_set_async_flags(struct obd_export *exp,
1303                                       struct lov_stripe_md *lsm,
1304                                       struct lov_oinfo *loi, void *cookie,
1305                                       obd_flag async_flags)
1306 {
1307         int rc;
1308         ENTRY;
1309
1310         EXP_CHECK_DT_OP(exp, set_async_flags);
1311         EXP_COUNTER_INCREMENT(exp, set_async_flags);
1312
1313         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1314                                                 async_flags);
1315         RETURN(rc);
1316 }
1317
1318 static inline int obd_queue_group_io(struct obd_export *exp,
1319                                      struct lov_stripe_md *lsm,
1320                                      struct lov_oinfo *loi,
1321                                      struct obd_io_group *oig,
1322                                      void *cookie, int cmd, obd_off off,
1323                                      int count, obd_flag brw_flags,
1324                                      obd_flag async_flags)
1325 {
1326         int rc;
1327         ENTRY;
1328
1329         EXP_CHECK_DT_OP(exp, queue_group_io);
1330         EXP_COUNTER_INCREMENT(exp, queue_group_io);
1331         LASSERT(cmd & OBD_BRW_RWMASK);
1332
1333         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1334                                                cmd, off, count, brw_flags,
1335                                                async_flags);
1336         RETURN(rc);
1337 }
1338
1339 static inline int obd_trigger_group_io(struct obd_export *exp,
1340                                        struct lov_stripe_md *lsm,
1341                                        struct lov_oinfo *loi,
1342                                        struct obd_io_group *oig)
1343 {
1344         int rc;
1345         ENTRY;
1346
1347         EXP_CHECK_DT_OP(exp, trigger_group_io);
1348         EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1349
1350         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1351         RETURN(rc);
1352 }
1353
1354 static inline int obd_teardown_async_page(struct obd_export *exp,
1355                                           struct lov_stripe_md *lsm,
1356                                           struct lov_oinfo *loi, void *cookie)
1357 {
1358         int rc;
1359         ENTRY;
1360
1361         EXP_CHECK_DT_OP(exp, teardown_async_page);
1362         EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1363
1364         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1365         RETURN(rc);
1366 }
1367
1368 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1369                              int objcount, struct obd_ioobj *obj,
1370                              int niocount, struct niobuf_remote *remote,
1371                              struct niobuf_local *local,
1372                              struct obd_trans_info *oti,
1373                              struct lustre_capa *capa)
1374 {
1375         int rc;
1376         ENTRY;
1377
1378         EXP_CHECK_DT_OP(exp, preprw);
1379         EXP_COUNTER_INCREMENT(exp, preprw);
1380
1381         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1382                                        remote, local, oti, capa);
1383         RETURN(rc);
1384 }
1385
1386 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1387                                int objcount, struct obd_ioobj *obj,
1388                                int niocount, struct niobuf_local *local,
1389                                struct obd_trans_info *oti, int rc)
1390 {
1391         ENTRY;
1392
1393         EXP_CHECK_DT_OP(exp, commitrw);
1394         EXP_COUNTER_INCREMENT(exp, commitrw);
1395
1396         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1397                                          local, oti, rc);
1398         RETURN(rc);
1399 }
1400
1401 static inline int obd_merge_lvb(struct obd_export *exp,
1402                                 struct lov_stripe_md *lsm,
1403                                 struct ost_lvb *lvb, int kms_only)
1404 {
1405         int rc;
1406         ENTRY;
1407
1408         EXP_CHECK_DT_OP(exp, merge_lvb);
1409         EXP_COUNTER_INCREMENT(exp, merge_lvb);
1410
1411         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1412         RETURN(rc);
1413 }
1414
1415 static inline int obd_adjust_kms(struct obd_export *exp,
1416                                  struct lov_stripe_md *lsm, obd_off size,
1417                                  int shrink)
1418 {
1419         int rc;
1420         ENTRY;
1421
1422         EXP_CHECK_DT_OP(exp, adjust_kms);
1423         EXP_COUNTER_INCREMENT(exp, adjust_kms);
1424
1425         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1426         RETURN(rc);
1427 }
1428
1429 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1430                                 int len, void *karg, void *uarg)
1431 {
1432         int rc;
1433         ENTRY;
1434
1435         EXP_CHECK_DT_OP(exp, iocontrol);
1436         EXP_COUNTER_INCREMENT(exp, iocontrol);
1437
1438         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1439         RETURN(rc);
1440 }
1441
1442 static inline int obd_enqueue_rqset(struct obd_export *exp,
1443                                     struct obd_info *oinfo,
1444                                     struct ldlm_enqueue_info *einfo)
1445 {
1446         struct ptlrpc_request_set *set = NULL;
1447         int rc;
1448         ENTRY;
1449
1450         EXP_CHECK_DT_OP(exp, enqueue);
1451         EXP_COUNTER_INCREMENT(exp, enqueue);
1452
1453         set =  ptlrpc_prep_set();
1454         if (set == NULL)
1455                 RETURN(-ENOMEM);
1456
1457         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1458         if (rc == 0)
1459                 rc = ptlrpc_set_wait(set);
1460         ptlrpc_set_destroy(set);
1461         RETURN(rc);
1462 }
1463
1464 static inline int obd_enqueue(struct obd_export *exp,
1465                               struct obd_info *oinfo,
1466                               struct ldlm_enqueue_info *einfo,
1467                               struct ptlrpc_request_set *set)
1468 {
1469         int rc;
1470         ENTRY;
1471
1472         EXP_CHECK_DT_OP(exp, enqueue);
1473         EXP_COUNTER_INCREMENT(exp, enqueue);
1474
1475         rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1476         RETURN(rc);
1477 }
1478
1479 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1480                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1481                             int *flags, void *data, struct lustre_handle *lockh)
1482 {
1483         int rc;
1484         ENTRY;
1485
1486         EXP_CHECK_DT_OP(exp, match);
1487         EXP_COUNTER_INCREMENT(exp, match);
1488
1489         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1490                                       lockh);
1491         RETURN(rc);
1492 }
1493
1494 static inline int obd_change_cbdata(struct obd_export *exp,
1495                                     struct lov_stripe_md *lsm,
1496                                     ldlm_iterator_t it, void *data)
1497 {
1498         int rc;
1499         ENTRY;
1500
1501         EXP_CHECK_DT_OP(exp, change_cbdata);
1502         EXP_COUNTER_INCREMENT(exp, change_cbdata);
1503
1504         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1505         RETURN(rc);
1506 }
1507
1508 static inline int obd_cancel(struct obd_export *exp,
1509                              struct lov_stripe_md *ea, __u32 mode,
1510                              struct lustre_handle *lockh)
1511 {
1512         int rc;
1513         ENTRY;
1514
1515         EXP_CHECK_DT_OP(exp, cancel);
1516         EXP_COUNTER_INCREMENT(exp, cancel);
1517
1518         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1519         RETURN(rc);
1520 }
1521
1522 static inline int obd_cancel_unused(struct obd_export *exp,
1523                                     struct lov_stripe_md *ea,
1524                                     int flags, void *opaque)
1525 {
1526         int rc;
1527         ENTRY;
1528
1529         EXP_CHECK_DT_OP(exp, cancel_unused);
1530         EXP_COUNTER_INCREMENT(exp, cancel_unused);
1531
1532         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1533         RETURN(rc);
1534 }
1535
1536 static inline int obd_join_lru(struct obd_export *exp,
1537                                struct lov_stripe_md *ea, int join)
1538 {
1539         int rc;
1540         ENTRY;
1541
1542         EXP_CHECK_DT_OP(exp, join_lru);
1543         EXP_COUNTER_INCREMENT(exp, join_lru);
1544
1545         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1546         RETURN(rc);
1547 }
1548
1549 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1550                           struct obd_capa *oc, struct obd_client_handle *handle,
1551                           int flag)
1552 {
1553         int rc;
1554         ENTRY;
1555
1556         EXP_CHECK_DT_OP(exp, pin);
1557         EXP_COUNTER_INCREMENT(exp, pin);
1558
1559         rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1560         RETURN(rc);
1561 }
1562
1563 static inline int obd_unpin(struct obd_export *exp,
1564                             struct obd_client_handle *handle, int flag)
1565 {
1566         int rc;
1567         ENTRY;
1568
1569         EXP_CHECK_DT_OP(exp, unpin);
1570         EXP_COUNTER_INCREMENT(exp, unpin);
1571
1572         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1573         RETURN(rc);
1574 }
1575
1576
1577 static inline void obd_import_event(struct obd_device *obd,
1578                                     struct obd_import *imp,
1579                                     enum obd_import_event event)
1580 {
1581         ENTRY;
1582         if (!obd) {
1583                 CERROR("NULL device\n");
1584                 EXIT;
1585                 return;
1586         }
1587         if (obd->obd_set_up && OBP(obd, import_event)) {
1588                 OBD_COUNTER_INCREMENT(obd, import_event);
1589                 OBP(obd, import_event)(obd, imp, event);
1590         }
1591         EXIT;
1592 }
1593
1594 static inline int obd_llog_connect(struct obd_export *exp,
1595                                    struct llogd_conn_body *body)
1596 {
1597         int rc;
1598         ENTRY;
1599
1600         OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1601         EXP_COUNTER_INCREMENT(exp, llog_connect);
1602
1603         rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1604         RETURN(rc);
1605 }
1606
1607
1608 static inline int obd_notify(struct obd_device *obd,
1609                              struct obd_device *watched,
1610                              enum obd_notify_event ev,
1611                              void *data)
1612 {
1613         int rc;
1614         ENTRY;
1615         OBD_CHECK_DEV(obd);
1616
1617         /* the check for async_recov is a complete hack - I'm hereby
1618            overloading the meaning to also mean "this was called from
1619            mds_postsetup".  I know that my mds is able to handle notifies
1620            by this point, and it needs to get them to execute mds_postrecov. */
1621         if (!obd->obd_set_up && !obd->obd_async_recov) {
1622                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1623                 RETURN(-EINVAL);
1624         }
1625
1626         if (!OBP(obd, notify)) {
1627                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1628                 RETURN(-ENOSYS);
1629         }
1630
1631         OBD_COUNTER_INCREMENT(obd, notify);
1632         rc = OBP(obd, notify)(obd, watched, ev, data);
1633         RETURN(rc);
1634 }
1635
1636 static inline int obd_notify_observer(struct obd_device *observer,
1637                                       struct obd_device *observed,
1638                                       enum obd_notify_event ev,
1639                                       void *data)
1640 {
1641         int rc1;
1642         int rc2;
1643
1644         struct obd_notify_upcall *onu;
1645
1646         if (observer->obd_observer)
1647                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1648         else
1649                 rc1 = 0;
1650         /*
1651          * Also, call non-obd listener, if any
1652          */
1653         onu = &observer->obd_upcall;
1654         if (onu->onu_upcall != NULL)
1655                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1656         else
1657                 rc2 = 0;
1658
1659         return rc1 ? rc1 : rc2;
1660 }
1661
1662 static inline int obd_quotacheck(struct obd_export *exp,
1663                                  struct obd_quotactl *oqctl)
1664 {
1665         int rc;
1666         ENTRY;
1667
1668         EXP_CHECK_DT_OP(exp, quotacheck);
1669         EXP_COUNTER_INCREMENT(exp, quotacheck);
1670
1671         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1672         RETURN(rc);
1673 }
1674
1675 static inline int obd_quotactl(struct obd_export *exp,
1676                                struct obd_quotactl *oqctl)
1677 {
1678         int rc;
1679         ENTRY;
1680
1681         EXP_CHECK_DT_OP(exp, quotactl);
1682         EXP_COUNTER_INCREMENT(exp, quotactl);
1683
1684         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1685         RETURN(rc);
1686 }
1687
1688 static inline int obd_health_check(struct obd_device *obd)
1689 {
1690         /* returns: 0 on healthy
1691          *         >0 on unhealthy + reason code/flag
1692          *            however the only suppored reason == 1 right now
1693          *            We'll need to define some better reasons
1694          *            or flags in the future.
1695          *         <0 on error
1696          */
1697         int rc;
1698         ENTRY;
1699
1700         /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1701         if (obd == NULL || !OBT(obd)) {
1702                 CERROR("cleaned up obd\n");
1703                 RETURN(-EOPNOTSUPP);
1704         }
1705         if (!obd->obd_set_up || obd->obd_stopping)
1706                 RETURN(0);
1707         if (!OBP(obd, health_check))
1708                 RETURN(0);
1709
1710         rc = OBP(obd, health_check)(obd);
1711         RETURN(rc);
1712 }
1713
1714 static inline int obd_register_observer(struct obd_device *obd,
1715                                         struct obd_device *observer)
1716 {
1717         ENTRY;
1718         OBD_CHECK_DEV(obd);
1719         if (obd->obd_observer && observer)
1720                 RETURN(-EALREADY);
1721         obd->obd_observer = observer;
1722         RETURN(0);
1723 }
1724
1725 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1726                                                obd_page_removal_cb_t cb,
1727                                                obd_pin_extent_cb pin_cb)
1728 {
1729         int rc;
1730         ENTRY;
1731
1732         OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1733         OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1734
1735         rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1736         RETURN(rc);
1737 }
1738
1739 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1740                                                  obd_page_removal_cb_t cb)
1741 {
1742         int rc;
1743         ENTRY;
1744
1745         OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1746         OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1747
1748         rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1749         RETURN(rc);
1750 }
1751
1752 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1753                                               obd_lock_cancel_cb cb)
1754 {
1755         int rc;
1756         ENTRY;
1757
1758         OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1759         OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1760
1761         rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1762         RETURN(rc);
1763 }
1764
1765 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1766                                                  obd_lock_cancel_cb cb)
1767 {
1768         int rc;
1769         ENTRY;
1770
1771         OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1772         OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1773
1774         rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1775         RETURN(rc);
1776 }
1777
1778 /* metadata helpers */
1779 static inline int md_getstatus(struct obd_export *exp,
1780                                struct lu_fid *fid, struct obd_capa **pc)
1781 {
1782         int rc;
1783         ENTRY;
1784
1785         EXP_CHECK_MD_OP(exp, getstatus);
1786         EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1787         rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1788         RETURN(rc);
1789 }
1790
1791 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1792                              struct obd_capa *oc, obd_valid valid, int ea_size,
1793                              struct ptlrpc_request **request)
1794 {
1795         int rc;
1796         ENTRY;
1797         EXP_CHECK_MD_OP(exp, getattr);
1798         EXP_MD_COUNTER_INCREMENT(exp, getattr);
1799         rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1800                                         ea_size, request);
1801         RETURN(rc);
1802 }
1803
1804 static inline int md_change_cbdata(struct obd_export *exp,
1805                                    const struct lu_fid *fid,
1806                                    ldlm_iterator_t it, void *data)
1807 {
1808         int rc;
1809         ENTRY;
1810         EXP_CHECK_MD_OP(exp, change_cbdata);
1811         EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1812         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1813         RETURN(rc);
1814 }
1815
1816 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1817                            struct md_open_data *mod,
1818                            struct ptlrpc_request **request)
1819 {
1820         int rc;
1821         ENTRY;
1822         EXP_CHECK_MD_OP(exp, close);
1823         EXP_MD_COUNTER_INCREMENT(exp, close);
1824         rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1825         RETURN(rc);
1826 }
1827
1828 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1829                             const void *data, int datalen, int mode, __u32 uid,
1830                             __u32 gid, __u32 cap_effective, __u64 rdev,
1831                             struct ptlrpc_request **request)
1832 {
1833         int rc;
1834         ENTRY;
1835         EXP_CHECK_MD_OP(exp, create);
1836         EXP_MD_COUNTER_INCREMENT(exp, create);
1837         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1838                                        uid, gid, cap_effective, rdev, request);
1839         RETURN(rc);
1840 }
1841
1842 static inline int md_done_writing(struct obd_export *exp,
1843                                   struct md_op_data *op_data,
1844                                   struct md_open_data *mod)
1845 {
1846         int rc;
1847         ENTRY;
1848         EXP_CHECK_MD_OP(exp, done_writing);
1849         EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1850         rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1851         RETURN(rc);
1852 }
1853
1854 static inline int md_enqueue(struct obd_export *exp,
1855                              struct ldlm_enqueue_info *einfo,
1856                              struct lookup_intent *it,
1857                              struct md_op_data *op_data,
1858                              struct lustre_handle *lockh,
1859                              void *lmm, int lmmsize,
1860                              int extra_lock_flags)
1861 {
1862         int rc;
1863         ENTRY;
1864         EXP_CHECK_MD_OP(exp, enqueue);
1865         EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1866         rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1867                                         lmm, lmmsize, extra_lock_flags);
1868         RETURN(rc);
1869 }
1870
1871 static inline int md_getattr_name(struct obd_export *exp,
1872                                   const struct lu_fid *fid, struct obd_capa *oc,
1873                                   const char *name, int namelen,
1874                                   obd_valid valid, int ea_size, __u32 suppgid,
1875                                   struct ptlrpc_request **request)
1876 {
1877         int rc;
1878         ENTRY;
1879         EXP_CHECK_MD_OP(exp, getattr_name);
1880         EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1881         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1882                                              valid, ea_size, suppgid, request);
1883         RETURN(rc);
1884 }
1885
1886 static inline int md_intent_lock(struct obd_export *exp,
1887                                  struct md_op_data *op_data, void *lmm,
1888                                  int lmmsize, struct lookup_intent *it,
1889                                  int flags, struct ptlrpc_request **reqp,
1890                                  ldlm_blocking_callback cb_blocking,
1891                                  int extra_lock_flags)
1892 {
1893         int rc;
1894         ENTRY;
1895         EXP_CHECK_MD_OP(exp, intent_lock);
1896         EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1897         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1898                                             it, flags, reqp, cb_blocking,
1899                                             extra_lock_flags);
1900         RETURN(rc);
1901 }
1902
1903 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1904                           struct ptlrpc_request **request)
1905 {
1906         int rc;
1907         ENTRY;
1908         EXP_CHECK_MD_OP(exp, link);
1909         EXP_MD_COUNTER_INCREMENT(exp, link);
1910         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1911         RETURN(rc);
1912 }
1913
1914 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1915                             const char *old, int oldlen, const char *new,
1916                             int newlen, struct ptlrpc_request **request)
1917 {
1918         int rc;
1919         ENTRY;
1920         EXP_CHECK_MD_OP(exp, rename);
1921         EXP_MD_COUNTER_INCREMENT(exp, rename);
1922         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1923                                        newlen, request);
1924         RETURN(rc);
1925 }
1926
1927 static inline int md_is_subdir(struct obd_export *exp,
1928                                const struct lu_fid *pfid,
1929                                const struct lu_fid *cfid,
1930                                struct ptlrpc_request **request)
1931 {
1932         int rc;
1933         ENTRY;
1934         EXP_CHECK_MD_OP(exp, is_subdir);
1935         EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1936         rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1937         RETURN(rc);
1938 }
1939
1940 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1941                              void *ea, int ealen, void *ea2, int ea2len,
1942                              struct ptlrpc_request **request,
1943                              struct md_open_data **mod)
1944 {
1945         int rc;
1946         ENTRY;
1947         EXP_CHECK_MD_OP(exp, setattr);
1948         EXP_MD_COUNTER_INCREMENT(exp, setattr);
1949         rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1950                                         ea2, ea2len, request, mod);
1951         RETURN(rc);
1952 }
1953
1954 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1955                           struct obd_capa *oc, struct ptlrpc_request **request)
1956 {
1957         int rc;
1958         ENTRY;
1959         EXP_CHECK_MD_OP(exp, sync);
1960         EXP_MD_COUNTER_INCREMENT(exp, sync);
1961         rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1962         RETURN(rc);
1963 }
1964
1965 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1966                               struct obd_capa *oc, __u64 offset,
1967                               struct page *page,
1968                               struct ptlrpc_request **request)
1969 {
1970         int rc;
1971         ENTRY;
1972         EXP_CHECK_MD_OP(exp, readpage);
1973         EXP_MD_COUNTER_INCREMENT(exp, readpage);
1974         rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1975         RETURN(rc);
1976 }
1977
1978 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1979                             struct ptlrpc_request **request)
1980 {
1981         int rc;
1982         ENTRY;
1983         EXP_CHECK_MD_OP(exp, unlink);
1984         EXP_MD_COUNTER_INCREMENT(exp, unlink);
1985         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1986         RETURN(rc);
1987 }
1988
1989 static inline int md_get_lustre_md(struct obd_export *exp,
1990                                    struct ptlrpc_request *req,
1991                                    struct obd_export *dt_exp,
1992                                    struct obd_export *md_exp,
1993                                    struct lustre_md *md)
1994 {
1995         ENTRY;
1996         EXP_CHECK_MD_OP(exp, get_lustre_md);
1997         EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1998         RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1999 }
2000
2001 static inline int md_free_lustre_md(struct obd_export *exp,
2002                                     struct lustre_md *md)
2003 {
2004         ENTRY;
2005         EXP_CHECK_MD_OP(exp, free_lustre_md);
2006         EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2007         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2008 }
2009
2010 static inline int md_setxattr(struct obd_export *exp,
2011                               const struct lu_fid *fid, struct obd_capa *oc,
2012                               obd_valid valid, const char *name,
2013                               const char *input, int input_size,
2014                               int output_size, int flags, __u32 suppgid,
2015                               struct ptlrpc_request **request)
2016 {
2017         ENTRY;
2018         EXP_CHECK_MD_OP(exp, setxattr);
2019         EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2020         RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2021                                            input_size, output_size, flags,
2022                                            suppgid, request));
2023 }
2024
2025 static inline int md_getxattr(struct obd_export *exp,
2026                               const struct lu_fid *fid, struct obd_capa *oc,
2027                               obd_valid valid, const char *name,
2028                               const char *input, int input_size,
2029                               int output_size, int flags,
2030                               struct ptlrpc_request **request)
2031 {
2032         ENTRY;
2033         EXP_CHECK_MD_OP(exp, getxattr);
2034         EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2035         RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2036                                            input_size, output_size, flags,
2037                                            request));
2038 }
2039
2040 static inline int md_set_open_replay_data(struct obd_export *exp,
2041                                           struct obd_client_handle *och,
2042                                           struct ptlrpc_request *open_req)
2043 {
2044         ENTRY;
2045         EXP_CHECK_MD_OP(exp, set_open_replay_data);
2046         EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2047         RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2048 }
2049
2050 static inline int md_clear_open_replay_data(struct obd_export *exp,
2051                                             struct obd_client_handle *och)
2052 {
2053         ENTRY;
2054         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2055         EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2056         RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2057 }
2058
2059 static inline int md_set_lock_data(struct obd_export *exp,
2060                                    __u64 *lockh, void *data)
2061 {
2062         ENTRY;
2063         EXP_CHECK_MD_OP(exp, set_lock_data);
2064         EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2065         RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
2066 }
2067
2068 static inline int md_cancel_unused(struct obd_export *exp,
2069                                    const struct lu_fid *fid,
2070                                    ldlm_policy_data_t *policy,
2071                                    ldlm_mode_t mode, int flags, void *opaque)
2072 {
2073         int rc;
2074         ENTRY;
2075
2076         EXP_CHECK_MD_OP(exp, cancel_unused);
2077         EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2078
2079         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2080                                               flags, opaque);
2081         RETURN(rc);
2082 }
2083
2084 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2085                                         const struct lu_fid *fid,
2086                                         ldlm_type_t type,
2087                                         ldlm_policy_data_t *policy,
2088                                         ldlm_mode_t mode,
2089                                         struct lustre_handle *lockh)
2090 {
2091         ENTRY;
2092         EXP_CHECK_MD_OP(exp, lock_match);
2093         EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2094         RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2095                                              policy, mode, lockh));
2096 }
2097
2098 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2099                                   int def_asize, int cookiesize)
2100 {
2101         ENTRY;
2102         EXP_CHECK_MD_OP(exp, init_ea_size);
2103         EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2104         RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2105                                                cookiesize));
2106 }
2107
2108 static inline int md_get_remote_perm(struct obd_export *exp,
2109                                      const struct lu_fid *fid,
2110                                      struct obd_capa *oc, __u32 suppgid,
2111                                      struct ptlrpc_request **request)
2112 {
2113         ENTRY;
2114         EXP_CHECK_MD_OP(exp, get_remote_perm);
2115         EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2116         RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2117                                                   request));
2118 }
2119
2120 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2121                                 renew_capa_cb_t cb)
2122 {
2123         int rc;
2124         ENTRY;
2125         EXP_CHECK_MD_OP(exp, renew_capa);
2126         EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2127         rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2128         RETURN(rc);
2129 }
2130
2131 static inline int md_intent_getattr_async(struct obd_export *exp,
2132                                           struct md_enqueue_info *minfo,
2133                                           struct ldlm_enqueue_info *einfo)
2134 {
2135         int rc;
2136         ENTRY;
2137         EXP_CHECK_MD_OP(exp, intent_getattr_async);
2138         EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2139         rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2140         RETURN(rc);
2141 }
2142
2143 static inline int md_revalidate_lock(struct obd_export *exp,
2144                                      struct lookup_intent *it,
2145                                      struct lu_fid *fid)
2146 {
2147         int rc;
2148         ENTRY;
2149         EXP_CHECK_MD_OP(exp, revalidate_lock);
2150         EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2151         rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2152         RETURN(rc);
2153 }
2154
2155
2156 /* OBD Metadata Support */
2157
2158 extern int obd_init_caches(void);
2159 extern void obd_cleanup_caches(void);
2160
2161 /* support routines */
2162 extern cfs_mem_cache_t *obdo_cachep;
2163
2164 #define OBDO_ALLOC(ptr)                                                       \
2165 do {                                                                          \
2166         OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep);                               \
2167 } while(0)
2168
2169 #define OBDO_FREE(ptr)                                                        \
2170 do {                                                                          \
2171         OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
2172 } while(0)
2173
2174
2175 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2176 {
2177         /* something here */
2178 }
2179
2180 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2181 {
2182         /* something here */
2183 }
2184
2185 /* I'm as embarrassed about this as you are.
2186  *
2187  * <shaver> // XXX do not look into _superhack with remaining eye
2188  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2189 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2190
2191 /* sysctl.c */
2192 extern void obd_sysctl_init (void);
2193 extern void obd_sysctl_clean (void);
2194
2195 /* uuid.c  */
2196 typedef __u8 class_uuid_t[16];
2197 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2198
2199 /* lustre_peer.c    */
2200 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2201 int class_add_uuid(const char *uuid, __u64 nid);
2202 int class_del_uuid (const char *uuid);
2203 void class_init_uuidlist(void);
2204 void class_exit_uuidlist(void);
2205
2206 /* mea.c */
2207 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2208 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2209
2210 /* prng.c */
2211 void ll_generate_random_uuid(class_uuid_t uuid_out);
2212
2213 #endif /* __LINUX_OBD_CLASS_H */