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