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