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