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