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