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