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