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