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