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