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