Whamcloud - gitweb
d488e6d34a15befbcb107886da4e20f68940c444
[fs/lustre-release.git] / lustre / include / obd_class.h
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Copyright (c) 2011, 2017, Intel Corporation.
8  */
9
10 /*
11  * This file is part of Lustre, http://www.lustre.org/
12  *
13  * lustre/include/obd_class.h
14  *
15  * Header defining common operations on OBD devices.
16  *
17  */
18
19 #ifndef __CLASS_OBD_H
20 #define __CLASS_OBD_H
21
22 #include <linux/kobject.h>
23 #include <obd_support.h>
24 #include <lustre_import.h>
25 #include <lustre_net.h>
26 #include <obd.h>
27 #include <lustre_lib.h>
28 #include <uapi/linux/lustre/lustre_idl.h>
29 #include <lprocfs_status.h>
30 #ifdef HAVE_SERVER_SUPPORT
31 #include <lu_target.h>
32 #include <obd_target.h>
33 #include <dt_object.h>
34 #endif
35
36 #define OBD_STATFS_NODELAY      0x0001  /* requests should be send without delay
37                                          * and resends for avoid deadlocks */
38 #define OBD_STATFS_FROM_CACHE   0x0002  /* the statfs callback should not update
39                                          * obd_osfs_age */
40 #define OBD_STATFS_FOR_MDT0     0x0004  /* The statfs is only for retrieving
41                                          * information from MDT0. */
42 #define OBD_STATFS_SUM          0x0008  /* get aggregated statfs from MDT */
43 #define OBD_STATFS_NESTED       0x0010  /* Call while already holding
44                                          * obd_dev_mutex of a difference
45                                          * device.
46                                          */
47
48 #define OBD_MAX_INDEX xa_limit_31b.max
49
50 #define obd_device_find(devno)                                          \
51         xa_find(&obd_devs, &devno, OBD_MAX_INDEX, XA_PRESENT)
52
53 #define obd_device_find_after(devno)                                    \
54         xa_find_after(&obd_devs, &devno, OBD_MAX_INDEX, XA_PRESENT)
55
56 #define obd_device_for_each(devno, obd)                 \
57         xa_for_each(&obd_devs, devno, obd)
58
59 #define obd_device_for_each_start(devno, obd, start)    \
60         xa_for_each_start(&obd_devs, devno, obd, start)
61
62 #define obd_device_for_each_cond(devno, obd, cond)       \
63         obd_device_for_each(devno, obd)                  \
64         if (cond)
65
66 #define obd_device_for_each_uuid(devno, obd, uuid)       \
67         obd_device_for_each_cond(devno, obd,             \
68                                  obd_uuid_equals(uuid, &obd->obd_uuid))
69
70 #define obd_device_lock() xa_lock(&obd_devs)
71 #define obd_device_unlock() xa_unlock(&obd_devs)
72
73 /* OBD Operations Declarations */
74 extern struct obd_device *class_exp2obd(struct obd_export *);
75 extern int class_handle_ioctl(unsigned int cmd, void __user *uarg);
76 int lustre_get_jobid(char *jobid, size_t len);
77 void lustre_jobid_clear(const char *jobid);
78 void jobid_cache_fini(void);
79 int jobid_cache_init(void);
80 char *jobid_current(void);
81 int jobid_set_current(char *jobid);
82
83 struct lu_device_type;
84
85 /* genops.c */
86 extern struct xarray obd_devs;
87 struct obd_export *class_conn2export(struct lustre_handle *);
88 #ifdef HAVE_SERVER_SUPPORT
89 struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
90 #endif
91 int class_register_type(const struct obd_ops *dt_ops,
92                         const struct md_ops *md_ops, bool enable_proc,
93                         const char *nm, struct lu_device_type *ldt);
94 int class_unregister_type(const char *nm);
95
96 struct obd_device *class_newdev(const char *type_name, const char *name,
97                                 const char *uuid);
98 int class_register_device(struct obd_device *obd);
99 void class_unregister_device(struct obd_device *obd);
100 void class_free_dev(struct obd_device *obd);
101
102 struct obd_device *class_str2obd(const char *str);
103 int class_name2dev(const char *name);
104 struct obd_device *class_name2obd(const char *name);
105 int class_uuid2dev(struct obd_uuid *uuid);
106 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
107 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
108                                          const char *type_name,
109                                          struct obd_uuid *grp_uuid);
110 struct obd_device *class_num2obd(int num);
111 int class_obd_devs_count(void);
112
113 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
114
115 static inline char *obd_export_nid2str(struct obd_export *exp)
116 {
117         return exp->exp_connection == NULL ?
118                "<unknown>" : libcfs_nidstr(&exp->exp_connection->c_peer.nid);
119 }
120
121 static inline char *obd_import_nid2str(struct obd_import *imp)
122 {
123         return imp->imp_connection == NULL ?
124                "<unknown>" : libcfs_nidstr(&imp->imp_connection->c_peer.nid);
125 }
126
127 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
128 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
129 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
130                           const char *sep);
131
132 int obd_zombie_impexp_init(void);
133 void obd_zombie_impexp_stop(void);
134 void obd_zombie_impexp_cull(void);
135 void obd_zombie_barrier(void);
136 void obd_exports_barrier(struct obd_device *obd);
137 int kuc_len(int payload_len);
138 struct kuc_hdr * kuc_ptr(void *p);
139 void *kuc_alloc(int payload_len, int transport, int type);
140 void kuc_free(void *p, int payload_len);
141 int obd_get_request_slot(struct client_obd *cli);
142 void obd_put_request_slot(struct client_obd *cli);
143 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
144 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
145 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
146 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
147 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
148
149 /* page_pools.c */
150 int  sptlrpc_pool_init(void);
151 void sptlrpc_pool_fini(void);
152 int encrypt_page_pools_seq_show(struct seq_file *m, void *v);
153 int page_pools_seq_show(struct seq_file *m, void *v);
154
155 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
156 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
157
158 struct llog_handle;
159 struct llog_rec_hdr;
160 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
161                          struct llog_rec_hdr *, void *);
162
163 struct obd_export *obd_stale_export_get(void);
164 void obd_stale_export_put(struct obd_export *exp);
165 void obd_stale_export_adjust(struct obd_export *exp);
166
167 /* obd_config.c */
168 /* For interoperability */
169 struct cfg_interop_param {
170         char *old_param;
171         char *new_param;
172 };
173
174 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
175 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
176                                      const char *new_name);
177 void print_lustre_cfg(struct lustre_cfg *lcfg);
178 int class_process_config(struct lustre_cfg *lcfg);
179 ssize_t class_set_global(const char *param);
180 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
181                             struct kobject *kobj);
182 int class_attach(struct lustre_cfg *lcfg);
183 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
184 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
185 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
186
187 int class_find_param(char *buf, char *key, char **valp);
188 struct cfg_interop_param *class_find_old_param(const char *param,
189                                                struct cfg_interop_param *ptr);
190 int class_get_next_param(char **params, char *copy);
191 int class_match_param(char *buf, const char *key, char **valp);
192 int class_parse_nid(char *buf, struct lnet_nid *nid, char **endh);
193 int class_parse_nid_quiet(char *buf, struct lnet_nid *nid, char **endh);
194 int class_parse_net(char *buf, u32 *net, char **endh);
195 int class_match_nid(char *buf, char *key, struct lnet_nid *nid);
196 int class_match_net(char *buf, char *key, u32 net);
197
198 struct obd_device *class_incref(struct obd_device *obd,
199                                 const char *scope, const void *source);
200 void class_decref(struct obd_device *obd,
201                   const char *scope, const void *source);
202 void dump_exports(struct obd_device *obd, int locks, int debug_level);
203 int class_config_llog_handler(const struct lu_env *env,
204                               struct llog_handle *handle,
205                               struct llog_rec_hdr *rec, void *data);
206 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
207
208 #define CFG_F_START     0x01   /* Set when we start updating from a log */
209 #define CFG_F_MARKER    0x02   /* We are within a maker */
210 #define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
211 #define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
212
213 /* Passed as data param to class_config_parse_llog */
214 struct config_llog_instance {
215         unsigned long            cfg_instance;
216         struct super_block      *cfg_sb;
217         struct obd_uuid          cfg_uuid;
218         llog_cb_t                cfg_callback;
219         int                      cfg_last_idx; /* for partial llog processing */
220         int                      cfg_flags;
221         __u32                    cfg_lwp_idx;
222         __u32                    cfg_sub_clds;
223 };
224 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
225                             char *name, struct config_llog_instance *cfg);
226
227 /**
228  * Generate a unique configuration instance for this mount
229  *
230  * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
231  * For now, use the same value as before - the superblock pointer value.
232  *
233  * Using the client UUID would be an option, but it needs more testing.
234  */
235 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
236 {
237         return (unsigned long)sb;
238 }
239
240 #define CONFIG_SUB_SPTLRPC      0x01
241 #define CONFIG_SUB_RECOVER      0x02
242 #define CONFIG_SUB_PARAMS       0x04
243 #define CONFIG_SUB_NODEMAP      0x08
244 #define CONFIG_SUB_BARRIER      0x10
245
246 /* Sub clds should be attached to the config_llog_data when processing
247  * config log for client or server target. */
248 #define CONFIG_SUB_CLIENT       (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
249                                  CONFIG_SUB_PARAMS)
250 #define CONFIG_SUB_SERVER       (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
251                                  CONFIG_SUB_BARRIER)
252
253 #define PARAMS_FILENAME         "params"
254 #define BARRIER_FILENAME        "barrier"
255 #define LCTL_UPCALL             "lctl"
256
257 static inline bool logname_is_barrier(const char *logname)
258 {
259         char *ptr;
260
261         /* logname for barrier is "fsname-barrier" */
262         ptr = strstr(logname, BARRIER_FILENAME);
263         if (ptr && (ptr - logname) >= 2 &&
264             *(ptr - 1) == '-' && *(ptr + 7) == '\0')
265                 return true;
266
267         return false;
268 }
269
270 /* list of active configuration logs  */
271 struct config_llog_data {
272         struct ldlm_res_id          cld_resid;
273         struct lustre_handle        cld_lockh;
274         struct config_llog_instance cld_cfg;
275         struct list_head            cld_list_chain;/* on config_llog_list */
276         refcount_t                  cld_refcount;
277         struct config_llog_data    *cld_sptlrpc;/* depended sptlrpc log */
278         struct config_llog_data    *cld_params; /* common parameters log */
279         struct config_llog_data    *cld_recover;/* imperative recover log */
280         struct config_llog_data    *cld_nodemap;/* nodemap log */
281         struct config_llog_data    *cld_barrier;/* barrier log (for MDT only) */
282         struct obd_export          *cld_mgcexp;
283         struct mutex                cld_lock;
284         enum mgs_cfg_type           cld_type;
285         unsigned int                cld_stopping:1, /* we were told to stop
286                                                      * watching */
287                                     cld_lostlock:1, /* lock not requeued */
288                                     cld_processed:1;  /* successfully fetched */
289         char                        cld_logname[0];
290 };
291
292 struct lustre_profile {
293         struct list_head         lp_list;
294         char                    *lp_profile;
295         char                    *lp_dt;
296         char                    *lp_md;
297         int                      lp_refs;
298         bool                     lp_list_deleted;
299 };
300
301 struct lustre_profile *class_get_profile(const char * prof);
302 void class_del_profile(const char *prof);
303 void class_put_profile(struct lustre_profile *lprof);
304 void class_del_profiles(void);
305
306
307 #if LUSTRE_TRACKS_LOCK_EXP_REFS
308
309 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
310 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
311 extern void (*class_export_dump_hook)(struct obd_export *);
312
313 #else
314
315 #define __class_export_add_lock_ref(exp, lock)             do {} while (0)
316 #define __class_export_del_lock_ref(exp, lock)             do {} while (0)
317
318 #endif
319
320 #define class_export_rpc_inc(exp)                                       \
321 ({                                                                      \
322         atomic_inc(&(exp)->exp_rpc_count);                              \
323         CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",    \
324                (exp), atomic_read(&(exp)->exp_rpc_count));              \
325 })
326
327 #define class_export_rpc_dec(exp)                                       \
328 ({                                                                      \
329         LASSERT(atomic_read(&(exp)->exp_rpc_count) > 0);                \
330         atomic_dec(&(exp)->exp_rpc_count);                              \
331         CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",    \
332                (exp), atomic_read(&(exp)->exp_rpc_count));              \
333 })
334
335 #define class_export_lock_get(exp, lock)                                \
336 ({                                                                      \
337         atomic_inc(&(exp)->exp_locks_count);                            \
338         __class_export_add_lock_ref(exp, lock);                         \
339         CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
340                (exp), atomic_read(&(exp)->exp_locks_count));            \
341         class_export_get(exp);                                          \
342 })
343
344 #define class_export_lock_put(exp, lock)                                \
345 ({                                                                      \
346         LASSERT(atomic_read(&(exp)->exp_locks_count) > 0);              \
347         atomic_dec(&(exp)->exp_locks_count);                            \
348         __class_export_del_lock_ref(exp, lock);                         \
349         CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
350                (exp), atomic_read(&(exp)->exp_locks_count));            \
351         class_export_put(exp);                                          \
352 })
353
354 #define class_export_cb_get(exp)                                        \
355 ({                                                                      \
356         atomic_inc(&(exp)->exp_cb_count);                               \
357         CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
358                (exp), atomic_read(&(exp)->exp_cb_count));               \
359         class_export_get(exp);                                          \
360 })
361
362 #define class_export_cb_put(exp)                                        \
363 ({                                                                      \
364         LASSERT(atomic_read(&(exp)->exp_cb_count) > 0);                 \
365         atomic_dec(&(exp)->exp_cb_count);                               \
366         CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
367                (exp), atomic_read(&(exp)->exp_cb_count));               \
368         class_export_put(exp);                                          \
369 })
370
371 /* genops.c */
372 struct obd_export *class_export_get(struct obd_export *exp);
373 void class_export_put(struct obd_export *exp);
374 struct obd_export *class_new_export(struct obd_device *obd,
375                                     struct obd_uuid *cluuid);
376 struct obd_export *class_new_export_self(struct obd_device *obd,
377                                          struct obd_uuid *uuid);
378 void class_unlink_export(struct obd_export *exp);
379
380 struct obd_import *class_import_get(struct obd_import *);
381 void class_import_put(struct obd_import *);
382 struct obd_import *class_new_import(struct obd_device *obd);
383 void class_destroy_import(struct obd_import *exp);
384
385 #ifdef HAVE_SERVER_SUPPORT
386 struct obd_type *class_search_type(const char *name);
387 struct obd_type *class_get_type(const char *name);
388 #endif
389 void class_put_type(struct obd_type *type);
390 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
391                   struct obd_uuid *cluuid);
392 int class_disconnect(struct obd_export *exp);
393 void class_fail_export(struct obd_export *exp);
394 int class_connected_export(struct obd_export *exp);
395 void class_disconnect_exports(struct obd_device *obd);
396 int class_manual_cleanup(struct obd_device *obd);
397 void class_disconnect_stale_exports(struct obd_device *,
398                                     int (*test_export)(struct obd_export *));
399
400 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
401 {
402         return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
403                 (obd->obd_force ? OBD_OPT_FORCE : 0) |
404                 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
405                 0);
406 }
407
408 #ifdef HAVE_SERVER_SUPPORT
409 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
410 {
411         struct obd_device_target *obt;
412
413         LASSERT(exp->exp_obd);
414         obt = (void *)&exp->exp_obd->u;
415         if (obt->obt_magic != OBT_MAGIC)
416                 return NULL;
417         return obt->obt_lut;
418 }
419
420 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
421 {
422         struct obd_device_target *obt = obd2obt(obd);
423
424         LASSERT(obt);
425         return &obt->obt_lut->lut_lsd;
426 }
427 #endif
428
429 /* obdo.c */
430 struct lu_attr;
431 struct inode;
432
433 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
434 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
435
436 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
437 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
438
439 static inline int obd_check_dev(struct obd_device *obd)
440 {
441         if (!obd) {
442                 CERROR("NULL device\n");
443                 return -ENODEV;
444         }
445         return 0;
446 }
447
448 /* ensure obd_setup and !obd_stopping */
449 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
450 do {                                                            \
451         rc = obd_check_dev(obd);                                \
452         if (rc)                                                 \
453                 return rc;                                      \
454                                                                 \
455         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
456                 CERROR("Device %d not setup\n",                 \
457                        (obd)->obd_minor);                       \
458                 RETURN(-ENODEV);                                \
459         }                                                       \
460 } while (0)
461
462
463 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
464 {
465         /* Always add in ldlm_stats */
466         tmp->nid_ldlm_stats =
467                 lprocfs_stats_alloc(LDLM_LAST_OPC - LDLM_FIRST_OPC,
468                                     LPROCFS_STATS_FLAG_NOPERCPU);
469         if (tmp->nid_ldlm_stats == NULL)
470                 return -ENOMEM;
471
472         lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
473
474         return lprocfs_stats_register(tmp->nid_proc, "ldlm_stats",
475                                       tmp->nid_ldlm_stats);
476 }
477
478 static inline int exp_check_ops(struct obd_export *exp)
479 {
480         if (exp == NULL) {
481                 RETURN(-ENODEV);
482         }
483         if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
484                 RETURN(-EOPNOTSUPP);
485         }
486         RETURN(0);
487 }
488
489 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
490                                __u32 keylen, void *key,
491                                __u32 *vallen, void *val)
492 {
493         int rc;
494
495         ENTRY;
496
497         rc = exp_check_ops(exp);
498         if (rc)
499                 RETURN(rc);
500
501         if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
502                 CERROR("%s: no %s operation\n",
503                        (exp)->exp_obd->obd_name, __func__);
504                 RETURN(-ENOTSUPP);
505         }
506
507         rc = exp->exp_obd->obd_type->typ_dt_ops->o_get_info(env, exp, keylen,
508                                                             key, vallen, val);
509         RETURN(rc);
510 }
511
512 static inline int obd_set_info_async(const struct lu_env *env,
513                                      struct obd_export *exp,
514                                      __u32 keylen, void *key,
515                                      __u32 vallen, void *val,
516                                      struct ptlrpc_request_set *set)
517 {
518         int rc;
519
520         ENTRY;
521
522         rc = exp_check_ops(exp);
523         if (rc)
524                 RETURN(rc);
525
526         if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
527                 CERROR("%s: no %s operation\n",
528                        (exp)->exp_obd->obd_name, __func__);
529                 RETURN(-ENOTSUPP);
530         }
531
532         rc = exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async(env, exp,
533                                                                   keylen,
534                                                                   key,
535                                                                   vallen,
536                                                                   val, set);
537         RETURN(rc);
538 }
539
540 /*
541  * obd-lu integration.
542  *
543  * Functionality is being moved into new lu_device-based layering, but some
544  * pieces of configuration process are still based on obd devices.
545  *
546  * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
547  * subsume ->o_setup() methods of obd devices they replace. The same for
548  * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
549  * result, obd_setup() and obd_process_config() branch and call one XOR
550  * another.
551  *
552  * Yet neither lu_device_type_operations::ldto_device_fini() nor
553  * lu_device_type_operations::ldto_device_free() fully implement the
554  * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
555  * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
556  */
557 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
558 {
559         int rc;
560         struct obd_type *type = obd->obd_type;
561         struct lu_device_type *ldt;
562
563         ENTRY;
564
565         wait_var_event(&type->typ_lu,
566                        smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
567         ldt = type->typ_lu;
568         if (ldt != NULL) {
569                 struct lu_context session_ctx;
570                 struct lu_env env;
571
572                 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
573                 session_ctx.lc_thread = NULL;
574                 lu_context_enter(&session_ctx);
575
576                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
577                 if (rc == 0) {
578                         struct lu_device *dev;
579                         env.le_ses = &session_ctx;
580                         dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
581                         lu_env_fini(&env);
582                         if (!IS_ERR(dev)) {
583                                 obd->obd_lu_dev = dev;
584                                 dev->ld_obd = obd;
585 #ifdef HAVE_SERVER_SUPPORT
586                                 if (lu_device_is_dt(dev) &&
587                                     lu2dt_dev(dev)->dd_rdonly)
588                                         obd->obd_read_only = 1;
589 #endif
590                                 rc = 0;
591                         } else
592                                 rc = PTR_ERR(dev);
593                 }
594                 lu_context_exit(&session_ctx);
595                 lu_context_fini(&session_ctx);
596         } else {
597                 if (!obd->obd_type->typ_dt_ops->o_setup) {
598                         CERROR("%s: no %s operation\n", obd->obd_name,
599                                __func__);
600                         RETURN(-EOPNOTSUPP);
601                 }
602                 rc = obd->obd_type->typ_dt_ops->o_setup(obd, cfg);
603         }
604         RETURN(rc);
605 }
606
607 static inline int obd_precleanup(struct obd_device *obd)
608 {
609         int rc;
610         struct lu_device_type *ldt = obd->obd_type->typ_lu;
611         struct lu_device *d = obd->obd_lu_dev;
612
613         ENTRY;
614
615         if (ldt != NULL && d != NULL) {
616                 struct lu_env *env = lu_env_find();
617                 struct lu_env _env;
618
619                 if (!env) {
620                         env = &_env;
621                         rc = lu_env_init(env, ldt->ldt_ctx_tags);
622                         LASSERT(rc == 0);
623                         lu_env_add(env);
624                 }
625                 ldt->ldt_ops->ldto_device_fini(env, d);
626                 if (env == &_env) {
627                         lu_env_remove(env);
628                         lu_env_fini(env);
629                 }
630         }
631
632         if (!obd->obd_type->typ_dt_ops->o_precleanup)
633                 RETURN(0);
634
635         rc = obd->obd_type->typ_dt_ops->o_precleanup(obd);
636         RETURN(rc);
637 }
638
639 static inline int obd_cleanup(struct obd_device *obd)
640 {
641         int rc;
642         struct lu_device_type *ldt = obd->obd_type->typ_lu;
643         struct lu_device *d = obd->obd_lu_dev;
644
645         ENTRY;
646         if (ldt != NULL && d != NULL) {
647                 struct lu_env env;
648
649                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
650                 if (rc == 0) {
651                         ldt->ldt_ops->ldto_device_free(&env, d);
652                         lu_env_fini(&env);
653                         obd->obd_lu_dev = NULL;
654                 }
655         }
656         if (!obd->obd_type->typ_dt_ops->o_cleanup)
657                 RETURN(0);
658
659         rc = obd->obd_type->typ_dt_ops->o_cleanup(obd);
660         RETURN(rc);
661 }
662
663 static inline void obd_cleanup_client_import(struct obd_device *obd)
664 {
665         ENTRY;
666
667         /* If we set up but never connected, the client import will not
668          * have been cleaned.
669          */
670         down_write(&obd->u.cli.cl_sem);
671         if (obd->u.cli.cl_import) {
672                 struct obd_import *imp;
673
674                 imp = obd->u.cli.cl_import;
675                 CDEBUG(D_CONFIG, "%s: client import never connected\n",
676                        obd->obd_name);
677                 ptlrpc_invalidate_import(imp);
678                 client_destroy_import(imp);
679                 obd->u.cli.cl_import = NULL;
680         }
681         up_write(&obd->u.cli.cl_sem);
682
683         EXIT;
684 }
685
686 static inline int obd_process_config(struct obd_device *obd, int datalen,
687                                      void *data)
688 {
689         int rc;
690         struct lu_device_type *ldt = obd->obd_type->typ_lu;
691         struct lu_device *d = obd->obd_lu_dev;
692
693         ENTRY;
694
695         obd->obd_process_conf = 1;
696         if (ldt != NULL && d != NULL) {
697                 struct lu_env env;
698
699                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
700                 if (rc == 0) {
701                         rc = d->ld_ops->ldo_process_config(&env, d, data);
702                         lu_env_fini(&env);
703                 }
704         } else {
705                 if (!obd->obd_type->typ_dt_ops->o_process_config) {
706                         CERROR("%s: no %s operation\n",
707                                obd->obd_name, __func__);
708                         RETURN(-EOPNOTSUPP);
709                 }
710                 rc = obd->obd_type->typ_dt_ops->o_process_config(obd, datalen,
711                                                                  data);
712         }
713
714         obd->obd_process_conf = 0;
715
716         RETURN(rc);
717 }
718
719 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
720                              struct obdo *obdo)
721 {
722         int rc;
723
724         ENTRY;
725
726         rc = exp_check_ops(exp);
727         if (rc)
728                 RETURN(rc);
729
730         if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
731                 CERROR("%s: no %s operation\n",
732                        (exp)->exp_obd->obd_name, __func__);
733                 RETURN(-ENOTSUPP);
734         }
735
736         rc = exp->exp_obd->obd_type->typ_dt_ops->o_create(env, exp, obdo);
737         RETURN(rc);
738 }
739
740 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
741                               struct obdo *obdo)
742 {
743         int rc;
744
745         ENTRY;
746
747         rc = exp_check_ops(exp);
748         if (rc)
749                 RETURN(rc);
750
751         if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
752                 CERROR("%s: no %s operation\n",
753                        (exp)->exp_obd->obd_name, __func__);
754                 RETURN(-ENOTSUPP);
755         }
756
757         rc = exp->exp_obd->obd_type->typ_dt_ops->o_destroy(env, exp, obdo);
758         RETURN(rc);
759 }
760
761 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
762                               struct obdo *oa)
763 {
764         int rc;
765
766         ENTRY;
767         rc = exp_check_ops(exp);
768         if (rc)
769                 RETURN(rc);
770
771         if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
772                 CERROR("%s: no %s operation\n",
773                        (exp)->exp_obd->obd_name, __func__);
774                 RETURN(-ENOTSUPP);
775         }
776
777         rc = exp->exp_obd->obd_type->typ_dt_ops->o_getattr(env, exp, oa);
778
779         RETURN(rc);
780 }
781
782 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
783                               struct obdo *oa)
784 {
785         int rc;
786
787         ENTRY;
788         rc = exp_check_ops(exp);
789         if (rc)
790                 RETURN(rc);
791
792         if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
793                 CERROR("%s: no %s operation\n",
794                        (exp)->exp_obd->obd_name, __func__);
795                 RETURN(-ENOTSUPP);
796         }
797
798         rc = exp->exp_obd->obd_type->typ_dt_ops->o_setattr(env, exp, oa);
799
800         RETURN(rc);
801 }
802
803 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
804                                int priority)
805 {
806         struct obd_device *obd = imp->imp_obd;
807         int rc;
808
809         ENTRY;
810
811         OBD_CHECK_DEV_ACTIVE(obd);
812         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
813                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
814                 RETURN(-EOPNOTSUPP);
815         }
816
817         rc = obd->obd_type->typ_dt_ops->o_add_conn(imp, uuid, priority);
818         RETURN(rc);
819 }
820
821 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
822 {
823         struct obd_device *obd = imp->imp_obd;
824         int rc;
825
826         ENTRY;
827
828         OBD_CHECK_DEV_ACTIVE(obd);
829         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
830                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
831                 RETURN(-EOPNOTSUPP);
832         }
833
834         rc = obd->obd_type->typ_dt_ops->o_del_conn(imp, uuid);
835         RETURN(rc);
836 }
837
838 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
839 {
840         struct obd_uuid *uuid;
841
842         ENTRY;
843
844         if (!exp->exp_obd->obd_type ||
845             !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
846                 RETURN(NULL);
847
848         uuid = exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid(exp);
849         RETURN(uuid);
850 }
851
852 /** Create a new /a exp on device /a obd for the uuid /a cluuid
853  * @param exp New export handle
854  * @param d Connect data, supported flags are set, flags also understood
855  *    by obd are returned.
856  */
857 static inline int obd_connect(const struct lu_env *env,
858                               struct obd_export **exp, struct obd_device *obd,
859                               struct obd_uuid *cluuid,
860                               struct obd_connect_data *data,
861                               void *localdata)
862 {
863         int rc;
864         __u64 ocf = data ? data->ocd_connect_flags : 0;
865
866         ENTRY;
867
868         OBD_CHECK_DEV_ACTIVE(obd);
869         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
870                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
871                 RETURN(-EOPNOTSUPP);
872         }
873
874         rc = obd->obd_type->typ_dt_ops->o_connect(env, exp, obd, cluuid, data,
875                                                   localdata);
876         /* check that only subset is granted */
877         LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
878                                     data->ocd_connect_flags));
879         RETURN(rc);
880 }
881
882 static inline int obd_reconnect(const struct lu_env *env,
883                                 struct obd_export *exp,
884                                 struct obd_device *obd,
885                                 struct obd_uuid *cluuid,
886                                 struct obd_connect_data *d,
887                                 void *localdata)
888 {
889         int rc;
890         __u64 ocf = d ? d->ocd_connect_flags : 0;
891
892         ENTRY;
893
894         OBD_CHECK_DEV_ACTIVE(obd);
895         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
896                 RETURN(0);
897
898         rc = obd->obd_type->typ_dt_ops->o_reconnect(env, exp, obd, cluuid, d,
899                                                     localdata);
900         /* check that only subset is granted */
901         LASSERT(ergo(d != NULL,
902                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
903         RETURN(rc);
904 }
905
906 static inline int obd_disconnect(struct obd_export *exp)
907 {
908         int rc;
909
910         ENTRY;
911         rc = exp_check_ops(exp);
912         if (rc)
913                 RETURN(rc);
914
915         if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
916                 CERROR("%s: no %s operation\n",
917                        (exp)->exp_obd->obd_name, __func__);
918                 RETURN(-ENOTSUPP);
919         }
920
921         rc = exp->exp_obd->obd_type->typ_dt_ops->o_disconnect(exp);
922         RETURN(rc);
923 }
924
925 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
926                                enum lu_cli_type type)
927 {
928         int rc;
929
930         ENTRY;
931
932         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
933                 RETURN(0);
934
935         rc = obd->obd_type->typ_dt_ops->o_fid_init(obd, exp, type);
936         RETURN(rc);
937 }
938
939 static inline int obd_fid_fini(struct obd_device *obd)
940 {
941         int rc;
942
943         ENTRY;
944         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
945                 RETURN(0);
946
947         rc = obd->obd_type->typ_dt_ops->o_fid_fini(obd);
948         RETURN(rc);
949 }
950
951 static inline int obd_fid_alloc(const struct lu_env *env,
952                                 struct obd_export *exp,
953                                 struct lu_fid *fid,
954                                 struct md_op_data *op_data)
955 {
956         int rc;
957
958         ENTRY;
959         rc = exp_check_ops(exp);
960         if (rc)
961                 RETURN(rc);
962
963         if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
964                 CERROR("%s: no %s operation\n",
965                        (exp)->exp_obd->obd_name, __func__);
966                 RETURN(-ENOTSUPP);
967         }
968
969         rc = exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc(env, exp, fid,
970                                                              op_data);
971         RETURN(rc);
972 }
973
974 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
975 {
976         int rc;
977
978         ENTRY;
979
980         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
981                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
982                 RETURN(-EOPNOTSUPP);
983         }
984
985         /* Check poolname validity */
986         if (!poolname || poolname[0] == '\0' || lov_pool_is_reserved(poolname))
987                 RETURN(-EINVAL);
988
989         rc = obd->obd_type->typ_dt_ops->o_pool_new(obd, poolname);
990         RETURN(rc);
991 }
992
993 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
994 {
995         int rc;
996
997         ENTRY;
998         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
999                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1000                 RETURN(-EOPNOTSUPP);
1001         }
1002
1003         rc = obd->obd_type->typ_dt_ops->o_pool_del(obd, poolname);
1004         RETURN(rc);
1005 }
1006
1007 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1008                                char *ostname)
1009 {
1010         int rc;
1011
1012         ENTRY;
1013
1014         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1015                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1016                 RETURN(-EOPNOTSUPP);
1017         }
1018
1019         rc = obd->obd_type->typ_dt_ops->o_pool_add(obd, poolname, ostname);
1020         RETURN(rc);
1021 }
1022
1023 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1024                                char *ostname)
1025 {
1026         int rc;
1027
1028         ENTRY;
1029         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1030                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1031                 RETURN(-EOPNOTSUPP);
1032         }
1033
1034         rc = obd->obd_type->typ_dt_ops->o_pool_rem(obd, poolname, ostname);
1035         RETURN(rc);
1036 }
1037
1038 static inline int obd_init_export(struct obd_export *exp)
1039 {
1040         int rc = 0;
1041
1042         ENTRY;
1043         if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1044             exp->exp_obd->obd_type->typ_dt_ops->o_init_export)
1045                 rc = exp->exp_obd->obd_type->typ_dt_ops->o_init_export(exp);
1046         RETURN(rc);
1047 }
1048
1049 static inline int obd_destroy_export(struct obd_export *exp)
1050 {
1051         ENTRY;
1052         if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1053             exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export)
1054                 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export(exp);
1055         RETURN(0);
1056 }
1057
1058 /* @max_age is the oldest time in seconds that we accept using a cached data.
1059  * If the cache is older than @max_age we will get a new value from the
1060  * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1061  */
1062 static inline int obd_statfs_async(struct obd_export *exp,
1063                                    struct obd_info *oinfo,
1064                                    time64_t max_age,
1065                                    struct ptlrpc_request_set *rqset)
1066 {
1067         struct obd_device *obd;
1068         int rc = 0;
1069
1070         ENTRY;
1071
1072         if (exp == NULL || exp->exp_obd == NULL)
1073                 RETURN(-EINVAL);
1074
1075         obd = exp->exp_obd;
1076         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1077                 rc = -EOPNOTSUPP;
1078                 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1079                 RETURN(rc);
1080         }
1081
1082         CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1083                obd->obd_name, obd->obd_osfs_age, max_age);
1084         rc = obd->obd_type->typ_dt_ops->o_statfs_async(exp, oinfo, max_age,
1085                                                        rqset);
1086
1087         RETURN(rc);
1088 }
1089
1090 /* @max_age is the oldest time in seconds that we accept using a cached data.
1091  * If the cache is older than @max_age we will get a new value from the
1092  * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1093  */
1094 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1095                              struct obd_statfs *osfs, time64_t max_age,
1096                              __u32 flags)
1097 {
1098         struct obd_device *obd;
1099         int rc = 0;
1100
1101         ENTRY;
1102         if (unlikely(exp == NULL || exp->exp_obd == NULL))
1103                 RETURN(-EINVAL);
1104
1105         obd = exp->exp_obd;
1106         OBD_CHECK_DEV_ACTIVE(obd);
1107
1108         if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1109                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1110                 RETURN(-EOPNOTSUPP);
1111         }
1112
1113         CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1114                obd->obd_name, obd->obd_osfs_age, max_age);
1115         /* ignore cache if aggregated isn't expected */
1116         if (obd->obd_osfs_age < max_age ||
1117             ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1118              !(flags & OBD_STATFS_SUM))) {
1119                 /* the RPC will block anyway, so avoid sending many at once */
1120                 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1121                                                      (flags & OBD_STATFS_NESTED)
1122                                                      ? SINGLE_DEPTH_NESTING : 0);
1123                 if (rc)
1124                         RETURN(rc);
1125                 if (obd->obd_osfs_age < max_age ||
1126                     ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1127                      !(flags & OBD_STATFS_SUM))) {
1128                         rc = obd->obd_type->typ_dt_ops->o_statfs(env, exp, osfs,
1129                                                                  max_age,
1130                                                                  flags);
1131                 } else {
1132                         mutex_unlock(&obd->obd_dev_mutex);
1133                         GOTO(cached, rc = 0);
1134                 }
1135                 if (rc == 0) {
1136                         CDEBUG(D_SUPER,
1137                                "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1138                                obd->obd_name, &obd->obd_osfs,
1139                                osfs->os_bavail, osfs->os_blocks,
1140                                osfs->os_ffree, osfs->os_files);
1141
1142                         spin_lock(&obd->obd_osfs_lock);
1143                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1144                         obd->obd_osfs_age = ktime_get_seconds();
1145                         spin_unlock(&obd->obd_osfs_lock);
1146                 }
1147                 mutex_unlock(&obd->obd_dev_mutex);
1148         } else {
1149 cached:
1150                 CDEBUG(D_SUPER,
1151                        "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1152                        obd->obd_name, &obd->obd_osfs,
1153                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1154                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1155                 spin_lock(&obd->obd_osfs_lock);
1156                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1157                 spin_unlock(&obd->obd_osfs_lock);
1158         }
1159         RETURN(rc);
1160 }
1161
1162 static inline int obd_preprw(const struct lu_env *env, int cmd,
1163                              struct obd_export *exp, struct obdo *oa,
1164                              int objcount, struct obd_ioobj *obj,
1165                              struct niobuf_remote *remote, int *pages,
1166                              struct niobuf_local *local)
1167 {
1168         int rc;
1169
1170         ENTRY;
1171
1172         rc = exp_check_ops(exp);
1173         if (rc)
1174                 RETURN(rc);
1175
1176         if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1177                 CERROR("%s: no %s operation\n",
1178                        (exp)->exp_obd->obd_name, __func__);
1179                 RETURN(-ENOTSUPP);
1180         }
1181
1182         rc = exp->exp_obd->obd_type->typ_dt_ops->o_preprw(env, cmd, exp,
1183                                                           oa, objcount, obj,
1184                                                           remote, pages, local);
1185
1186         RETURN(rc);
1187 }
1188
1189 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1190                                struct obd_export *exp, struct obdo *oa,
1191                                int objcount, struct obd_ioobj *obj,
1192                                struct niobuf_remote *rnb, int pages,
1193                                struct niobuf_local *local, const int orig_rc,
1194                                int nob, ktime_t kstart)
1195 {
1196         int rc;
1197
1198         ENTRY;
1199
1200         rc = exp_check_ops(exp);
1201         if (rc)
1202                 RETURN(rc);
1203
1204         if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1205                 CERROR("%s: no %s operation\n",
1206                        (exp)->exp_obd->obd_name, __func__);
1207                 RETURN(-ENOTSUPP);
1208         }
1209
1210         rc = exp->exp_obd->obd_type->typ_dt_ops->o_commitrw(env, cmd, exp, oa,
1211                                                             objcount, obj,
1212                                                             rnb, pages, local,
1213                                                             orig_rc, nob,
1214                                                             kstart);
1215
1216         RETURN(rc);
1217 }
1218
1219 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1220                                 int len, void *karg, void __user *uarg)
1221 {
1222         int rc;
1223
1224         ENTRY;
1225
1226         rc = exp_check_ops(exp);
1227         if (rc)
1228                 RETURN(rc);
1229
1230         if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1231                 CERROR("%s: no %s operation\n",
1232                        (exp)->exp_obd->obd_name, __func__);
1233                 RETURN(-ENOTSUPP);
1234         }
1235
1236         rc = exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol(cmd, exp,
1237                                                              len, karg,
1238                                                              uarg);
1239         RETURN(rc);
1240 }
1241
1242 static inline void obd_import_event(struct obd_device *obd,
1243                                     struct obd_import *imp,
1244                                     enum obd_import_event event)
1245 {
1246         ENTRY;
1247         if (!obd) {
1248                 CERROR("NULL device\n");
1249                 EXIT;
1250                 return;
1251         }
1252
1253         if (obd->obd_set_up && obd->obd_type->typ_dt_ops->o_import_event)
1254                 obd->obd_type->typ_dt_ops->o_import_event(obd, imp, event);
1255
1256         EXIT;
1257 }
1258
1259 static inline int obd_notify(struct obd_device *obd,
1260                              struct obd_device *watched,
1261                              enum obd_notify_event ev)
1262 {
1263         int rc;
1264
1265         ENTRY;
1266
1267         rc = obd_check_dev(obd);
1268         if (rc)
1269                 return rc;
1270
1271         if (!obd->obd_set_up) {
1272                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1273                 RETURN(-EINVAL);
1274         }
1275
1276         if (!obd->obd_type->typ_dt_ops->o_notify) {
1277                 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1278                 RETURN(-ENOSYS);
1279         }
1280
1281         rc = obd->obd_type->typ_dt_ops->o_notify(obd, watched, ev);
1282
1283         RETURN(rc);
1284 }
1285
1286 static inline int obd_notify_observer(struct obd_device *observer,
1287                                       struct obd_device *observed,
1288                                       enum obd_notify_event ev)
1289 {
1290         int rc = 0;
1291         int rc2 = 0;
1292         struct obd_notify_upcall *onu;
1293
1294         if (WARN_ON_ONCE(!observer))
1295                 return -ENODEV;
1296
1297         if (observer->obd_observer)
1298                 rc = obd_notify(observer->obd_observer, observed, ev);
1299
1300         /*
1301          * Also, call non-obd listener, if any
1302          */
1303         onu = &observer->obd_upcall;
1304         if (onu->onu_upcall != NULL)
1305                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1306
1307         return rc ? rc : rc2;
1308 }
1309
1310 static inline int obd_quotactl(struct obd_export *exp,
1311                                struct obd_quotactl *oqctl)
1312 {
1313         int rc;
1314
1315         ENTRY;
1316
1317         rc = exp_check_ops(exp);
1318         if (rc)
1319                 RETURN(rc);
1320
1321         if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1322                 CERROR("%s: no %s operation\n",
1323                        (exp)->exp_obd->obd_name, __func__);
1324                 RETURN(-ENOTSUPP);
1325         }
1326
1327         rc = exp->exp_obd->obd_type->typ_dt_ops->o_quotactl(exp->exp_obd,
1328                                                             exp, oqctl);
1329         RETURN(rc);
1330 }
1331
1332 static inline int obd_quota_iter(struct obd_export *exp,
1333                                  struct obd_quotactl *oqctl,
1334                                  struct list_head *list)
1335 {
1336         int rc = 0;
1337
1338         do {
1339                 oqctl->qc_iter_list = (__u64)list;
1340                 rc = obd_quotactl(exp, oqctl);
1341                 if (rc)
1342                         break;
1343
1344         } while (oqctl->qc_iter_md_offset || oqctl->qc_iter_dt_offset);
1345
1346         return rc;
1347 }
1348
1349 static inline int obd_health_check(const struct lu_env *env,
1350                                    struct obd_device *obd)
1351 {
1352         /* returns: 0 on healthy
1353          *         >0 on unhealthy + reason code/flag
1354          *            however the only suppored reason == 1 right now
1355          *            We'll need to define some better reasons
1356          *            or flags in the future.
1357          *         <0 on error
1358          */
1359         int rc;
1360
1361         ENTRY;
1362
1363         /* NULL method is normal here */
1364         if (obd == NULL || !obd->obd_type) {
1365                 CERROR("cleaned up obd\n");
1366                 RETURN(-EOPNOTSUPP);
1367         }
1368         if (!obd->obd_set_up || obd->obd_stopping)
1369                 RETURN(0);
1370         if (!obd->obd_type->typ_dt_ops->o_health_check)
1371                 RETURN(0);
1372
1373         rc = obd->obd_type->typ_dt_ops->o_health_check(env, obd);
1374         RETURN(rc);
1375 }
1376
1377 static inline int obd_register_observer(struct obd_device *obd,
1378                                         struct obd_device *observer)
1379 {
1380         int rc;
1381
1382         ENTRY;
1383
1384         rc = obd_check_dev(obd);
1385         if (rc)
1386                 return rc;
1387
1388         down_write(&obd->obd_observer_link_sem);
1389         if (obd->obd_observer && observer) {
1390                 up_write(&obd->obd_observer_link_sem);
1391                 RETURN(-EALREADY);
1392         }
1393         obd->obd_observer = observer;
1394         up_write(&obd->obd_observer_link_sem);
1395         RETURN(0);
1396 }
1397
1398 /* metadata helpers */
1399 enum mps_stat_idx {
1400         LPROC_MD_CLOSE,
1401         LPROC_MD_CREATE,
1402         LPROC_MD_ENQUEUE,
1403         LPROC_MD_GETATTR,
1404         LPROC_MD_INTENT_LOCK,
1405         LPROC_MD_LINK,
1406         LPROC_MD_RENAME,
1407         LPROC_MD_SETATTR,
1408         LPROC_MD_FSYNC,
1409         LPROC_MD_READ_PAGE,
1410         LPROC_MD_UNLINK,
1411         LPROC_MD_SETXATTR,
1412         LPROC_MD_GETXATTR,
1413         LPROC_MD_INTENT_GETATTR_ASYNC,
1414         LPROC_MD_REVALIDATE_LOCK,
1415         LPROC_MD_LAST_OPC,
1416 };
1417
1418 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1419                               struct lu_fid *fid)
1420 {
1421         int rc;
1422
1423         rc = exp_check_ops(exp);
1424         if (rc)
1425                 return rc;
1426
1427         return exp->exp_obd->obd_type->typ_md_ops->m_get_root(exp, fileset,
1428                                                               fid);
1429 }
1430
1431 static inline int md_getattr(struct obd_export *exp,
1432                              struct md_op_data *op_data,
1433                              struct ptlrpc_request **request)
1434 {
1435         int rc;
1436
1437         rc = exp_check_ops(exp);
1438         if (rc)
1439                 return rc;
1440
1441         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1442                              LPROC_MD_GETATTR);
1443
1444         return exp->exp_obd->obd_type->typ_md_ops->m_getattr(exp, op_data,
1445                                                              request);
1446 }
1447
1448 static inline int md_null_inode(struct obd_export *exp,
1449                                    const struct lu_fid *fid)
1450 {
1451         int rc;
1452
1453         rc = exp_check_ops(exp);
1454         if (rc)
1455                 return rc;
1456
1457         return exp->exp_obd->obd_type->typ_md_ops->m_null_inode(exp, fid);
1458 }
1459
1460 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1461                            struct md_open_data *mod,
1462                            struct ptlrpc_request **request)
1463 {
1464         int rc;
1465
1466         rc = exp_check_ops(exp);
1467         if (rc)
1468                 return rc;
1469
1470         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1471                              LPROC_MD_CLOSE);
1472
1473         return exp->exp_obd->obd_type->typ_md_ops->m_close(exp, op_data, mod,
1474                                                            request);
1475 }
1476
1477 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1478                             const void *data, size_t datalen, umode_t mode,
1479                             uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1480                             __u64 rdev, struct ptlrpc_request **request)
1481 {
1482         int rc;
1483
1484         rc = exp_check_ops(exp);
1485         if (rc)
1486                 return rc;
1487
1488         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1489                              LPROC_MD_CREATE);
1490
1491         return exp->exp_obd->obd_type->typ_md_ops->m_create(exp, op_data, data,
1492                                                             datalen, mode, uid,
1493                                                             gid, cap_effective,
1494                                                             rdev, request);
1495 }
1496
1497 static inline int md_enqueue(struct obd_export *exp,
1498                              struct ldlm_enqueue_info *einfo,
1499                              const union ldlm_policy_data *policy,
1500                              struct md_op_data *op_data,
1501                              struct lustre_handle *lockh,
1502                              __u64 extra_lock_flags)
1503 {
1504         int rc;
1505
1506         rc = exp_check_ops(exp);
1507         if (rc)
1508                 return rc;
1509
1510         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1511                              LPROC_MD_ENQUEUE);
1512
1513         return exp->exp_obd->obd_type->typ_md_ops->m_enqueue(exp, einfo, policy,
1514                                                              op_data, lockh,
1515                                                              extra_lock_flags);
1516 }
1517
1518 static inline int md_getattr_name(struct obd_export *exp,
1519                                   struct md_op_data *op_data,
1520                                   struct ptlrpc_request **request)
1521 {
1522         int rc;
1523
1524         rc = exp_check_ops(exp);
1525         if (rc)
1526                 return rc;
1527
1528         return exp->exp_obd->obd_type->typ_md_ops->m_getattr_name(exp, op_data,
1529                                                                   request);
1530 }
1531
1532 static inline int md_intent_lock(struct obd_export *exp,
1533                                  struct md_op_data *op_data,
1534                                  struct lookup_intent *it,
1535                                  struct ptlrpc_request **reqp,
1536                                  ldlm_blocking_callback cb_blocking,
1537                                  __u64 extra_lock_flags)
1538 {
1539         int rc;
1540
1541         rc = exp_check_ops(exp);
1542         if (rc)
1543                 return rc;
1544
1545         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1546                              LPROC_MD_INTENT_LOCK);
1547
1548         return exp->exp_obd->obd_type->typ_md_ops->m_intent_lock(exp, op_data,
1549                                                                  it, reqp,
1550                                                                  cb_blocking,
1551                                                                  extra_lock_flags);
1552 }
1553
1554 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1555                           struct ptlrpc_request **request)
1556 {
1557         int rc;
1558
1559         rc = exp_check_ops(exp);
1560         if (rc)
1561                 return rc;
1562
1563         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1564                              LPROC_MD_LINK);
1565
1566         return exp->exp_obd->obd_type->typ_md_ops->m_link(exp, op_data,
1567                                                           request);
1568 }
1569
1570 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1571                             const char *old_name, size_t oldlen,
1572                             const char *new_name, size_t newlen,
1573                             struct ptlrpc_request **request)
1574 {
1575         int rc;
1576
1577         rc = exp_check_ops(exp);
1578         if (rc)
1579                 return rc;
1580
1581         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1582                              LPROC_MD_RENAME);
1583
1584         return exp->exp_obd->obd_type->typ_md_ops->m_rename(exp, op_data,
1585                                                             old_name,
1586                                                             oldlen, new_name,
1587                                                             newlen, request);
1588 }
1589
1590 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1591                              void *ea, size_t ealen,
1592                              struct ptlrpc_request **request)
1593 {
1594         int rc;
1595
1596         rc = exp_check_ops(exp);
1597         if (rc)
1598                 return rc;
1599
1600         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1601                              LPROC_MD_SETATTR);
1602
1603         return exp->exp_obd->obd_type->typ_md_ops->m_setattr(exp, op_data, ea,
1604                                                              ealen, request);
1605 }
1606
1607 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1608                            struct ptlrpc_request **request)
1609 {
1610         int rc;
1611
1612         rc = exp_check_ops(exp);
1613         if (rc)
1614                 return rc;
1615
1616         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1617                              LPROC_MD_FSYNC);
1618
1619         return exp->exp_obd->obd_type->typ_md_ops->m_fsync(exp, fid, request);
1620 }
1621
1622 /* FLR: resync mirrored files. */
1623 static inline int md_file_resync(struct obd_export *exp,
1624                                  struct md_op_data *data)
1625 {
1626         int rc;
1627
1628         rc = exp_check_ops(exp);
1629         if (rc)
1630                 return rc;
1631
1632         return exp->exp_obd->obd_type->typ_md_ops->m_file_resync(exp, data);
1633 }
1634
1635 static inline int md_read_page(struct obd_export *exp,
1636                                struct md_op_data *op_data,
1637                                struct md_readdir_info *mrinfo,
1638                                __u64  hash_offset, struct page **ppage)
1639 {
1640         int rc;
1641
1642         rc = exp_check_ops(exp);
1643         if (rc)
1644                 return rc;
1645
1646         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1647                              LPROC_MD_READ_PAGE);
1648
1649         return exp->exp_obd->obd_type->typ_md_ops->m_read_page(exp, op_data,
1650                                                                mrinfo,
1651                                                                hash_offset,
1652                                                                ppage);
1653 }
1654
1655 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1656                             struct ptlrpc_request **request)
1657 {
1658         int rc;
1659
1660         rc = exp_check_ops(exp);
1661         if (rc)
1662                 return rc;
1663
1664         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1665                              LPROC_MD_UNLINK);
1666
1667         return exp->exp_obd->obd_type->typ_md_ops->m_unlink(exp, op_data,
1668                                                             request);
1669 }
1670
1671 static inline int md_get_lustre_md(struct obd_export *exp,
1672                                    struct req_capsule *pill,
1673                                    struct obd_export *dt_exp,
1674                                    struct obd_export *md_exp,
1675                                    struct lustre_md *md)
1676 {
1677         int rc;
1678
1679         rc = exp_check_ops(exp);
1680         if (rc)
1681                 return rc;
1682
1683         return exp->exp_obd->obd_type->typ_md_ops->m_get_lustre_md(exp, pill,
1684                                                                    dt_exp,
1685                                                                    md_exp, md);
1686 }
1687
1688 static inline int md_put_lustre_md(struct obd_export *exp,
1689                                     struct lustre_md *md)
1690 {
1691         int rc;
1692
1693         rc = exp_check_ops(exp);
1694         if (rc)
1695                 return rc;
1696
1697         return exp->exp_obd->obd_type->typ_md_ops->m_put_lustre_md(exp, md);
1698 }
1699
1700 static inline int md_merge_attr(struct obd_export *exp,
1701                                 const struct lmv_stripe_object *lso,
1702                                 struct cl_attr *attr,
1703                                 ldlm_blocking_callback cb)
1704 {
1705         int rc;
1706
1707         rc = exp_check_ops(exp);
1708         if (rc)
1709                 return rc;
1710
1711         return exp->exp_obd->obd_type->typ_md_ops->m_merge_attr(exp, lso, attr,
1712                                                                 cb);
1713 }
1714
1715 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1716                               u64 obd_md_valid, const char *name,
1717                               const void *value, size_t value_size,
1718                               unsigned int xattr_flags, u32 suppgid,
1719                               struct ptlrpc_request **req)
1720 {
1721         int rc;
1722
1723         rc = exp_check_ops(exp);
1724         if (rc)
1725                 return rc;
1726
1727         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1728                              LPROC_MD_SETXATTR);
1729
1730         return exp->exp_obd->obd_type->typ_md_ops->m_setxattr(exp, fid,
1731                                                               obd_md_valid,
1732                                                               name, value,
1733                                                               value_size,
1734                                                               xattr_flags,
1735                                                               suppgid,
1736                                                               req);
1737 }
1738
1739 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1740                               u64 obd_md_valid, const char *name,
1741                               size_t buf_size, struct ptlrpc_request **req)
1742 {
1743         int rc;
1744
1745         rc = exp_check_ops(exp);
1746         if (rc)
1747                 return rc;
1748
1749         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1750                              LPROC_MD_GETXATTR);
1751
1752         return exp->exp_obd->obd_type->typ_md_ops->m_getxattr(exp, fid,
1753                                                               obd_md_valid,
1754                                                               name, buf_size,
1755                                                               req);
1756 }
1757
1758 static inline int md_set_open_replay_data(struct obd_export *exp,
1759                                           struct obd_client_handle *och,
1760                                           struct lookup_intent *it)
1761 {
1762         int rc;
1763
1764         rc = exp_check_ops(exp);
1765         if (rc)
1766                 return rc;
1767
1768         return exp->exp_obd->obd_type->typ_md_ops->m_set_open_replay_data(exp,
1769                                                                           och,
1770                                                                           it);
1771 }
1772
1773 static inline int md_clear_open_replay_data(struct obd_export *exp,
1774                                             struct obd_client_handle *och)
1775 {
1776         int rc;
1777
1778         rc = exp_check_ops(exp);
1779         if (rc)
1780                 return rc;
1781
1782         return exp->exp_obd->obd_type->typ_md_ops->m_clear_open_replay_data(exp, och);
1783 }
1784
1785 static inline int md_set_lock_data(struct obd_export *exp,
1786                                    const struct lustre_handle *lockh,
1787                                    void *data, __u64 *bits)
1788 {
1789         int rc;
1790
1791         rc = exp_check_ops(exp);
1792         if (rc)
1793                 return rc;
1794
1795         return exp->exp_obd->obd_type->typ_md_ops->m_set_lock_data(exp, lockh,
1796                                                                    data,
1797                                                                    bits);
1798 }
1799
1800 static inline
1801 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1802                      union ldlm_policy_data *policy, enum ldlm_mode mode,
1803                      enum ldlm_cancel_flags cancel_flags, void *opaque)
1804 {
1805         int rc;
1806
1807         rc = exp_check_ops(exp);
1808         if (rc)
1809                 return rc;
1810
1811         return exp->exp_obd->obd_type->typ_md_ops->m_cancel_unused(exp,
1812                                                                    fid, policy,
1813                                                                    mode,
1814                                                                    cancel_flags,
1815                                                                    opaque);
1816 }
1817
1818 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1819                                            const struct lu_fid *fid,
1820                                            enum ldlm_type type,
1821                                            union ldlm_policy_data *policy,
1822                                            enum ldlm_mode mode,
1823                                            struct lustre_handle *lockh)
1824 {
1825         int rc;
1826
1827         rc = exp_check_ops(exp);
1828         if (rc)
1829                 return rc;
1830
1831         return exp->exp_obd->obd_type->typ_md_ops->m_lock_match(exp, flags,
1832                                                                 fid, type,
1833                                                                 policy, mode,
1834                                                                 lockh);
1835 }
1836
1837 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1838                                   __u32 def_ea_size)
1839 {
1840         int rc;
1841
1842         rc = exp_check_ops(exp);
1843         if (rc)
1844                 return rc;
1845
1846         return exp->exp_obd->obd_type->typ_md_ops->m_init_ea_size(exp, ea_size,
1847                                                                   def_ea_size);
1848 }
1849
1850 static inline int md_intent_getattr_async(struct obd_export *exp,
1851                                           struct md_op_item *item)
1852 {
1853         int rc;
1854
1855         rc = exp_check_ops(exp);
1856         if (rc)
1857                 return rc;
1858
1859         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1860                              LPROC_MD_INTENT_GETATTR_ASYNC);
1861
1862         return exp->exp_obd->obd_type->typ_md_ops->m_intent_getattr_async(exp,
1863                                                                           item);
1864 }
1865
1866 static inline int md_revalidate_lock(struct obd_export *exp,
1867                                      struct lookup_intent *it,
1868                                      struct lu_fid *fid, __u64 *bits)
1869 {
1870         int rc;
1871
1872         rc = exp_check_ops(exp);
1873         if (rc)
1874                 return rc;
1875
1876         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1877                              LPROC_MD_REVALIDATE_LOCK);
1878
1879         return exp->exp_obd->obd_type->typ_md_ops->m_revalidate_lock(exp,
1880                                                                      it, fid,
1881                                                                      bits);
1882 }
1883
1884 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1885                                       const struct lmv_stripe_object *lso,
1886                                       const char *name, int namelen,
1887                                       struct lu_fid *fid)
1888 {
1889         int rc;
1890
1891         rc = exp_check_ops(exp);
1892         if (rc)
1893                 return rc;
1894
1895         return exp->exp_obd->obd_type->typ_md_ops->m_get_fid_from_lsm(exp,
1896                                                                       lso, name,
1897                                                                       namelen,
1898                                                                       fid);
1899 }
1900
1901 /* Unpack an MD struct from disk to in-memory format.
1902  * Returns +ve size of unpacked MD (0 for free), or -ve error.
1903  *
1904  * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1905  * If *plsm == NULL then it will be allocated.
1906  */
1907 static inline int md_stripe_object_create(struct obd_export *exp,
1908                                           struct lmv_stripe_object **lsop,
1909                                           const union lmv_mds_md *lmm,
1910                                           size_t lmm_size)
1911 {
1912         int rc;
1913
1914         rc = exp_check_ops(exp);
1915         if (rc)
1916                 return rc;
1917
1918         return exp->exp_obd->obd_type->typ_md_ops->m_stripe_object_create(exp,
1919                                                                           lsop,
1920                                                                           lmm,
1921                                                                           lmm_size);
1922 }
1923
1924 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1925                            int *rcs, struct ptlrpc_request_set *set)
1926 {
1927         int rc;
1928
1929         rc = exp_check_ops(exp);
1930         if (rc)
1931                 return rc;
1932
1933         return exp->exp_obd->obd_type->typ_md_ops->m_rmfid(exp, fa, rcs, set);
1934 }
1935
1936 static inline struct lu_batch *
1937 md_batch_create(struct obd_export *exp, enum lu_batch_flags flags,
1938                 __u32 max_count)
1939 {
1940         int rc;
1941
1942         rc = exp_check_ops(exp);
1943         if (rc)
1944                 return ERR_PTR(rc);
1945
1946         return exp->exp_obd->obd_type->typ_md_ops->m_batch_create(exp, flags,
1947                                                                   max_count);
1948 }
1949
1950 static inline int md_batch_stop(struct obd_export *exp, struct lu_batch *bh)
1951 {
1952         int rc;
1953
1954         rc = exp_check_ops(exp);
1955         if (rc)
1956                 return rc;
1957
1958         return exp->exp_obd->obd_type->typ_md_ops->m_batch_stop(exp, bh);
1959 }
1960
1961 static inline int md_batch_flush(struct obd_export *exp, struct lu_batch *bh,
1962                                  bool wait)
1963 {
1964         int rc;
1965
1966         rc = exp_check_ops(exp);
1967         if (rc)
1968                 return rc;
1969
1970         return exp->exp_obd->obd_type->typ_md_ops->m_batch_flush(exp, bh, wait);
1971 }
1972
1973 static inline int md_batch_add(struct obd_export *exp, struct lu_batch *bh,
1974                                struct md_op_item *item)
1975 {
1976         int rc;
1977
1978         rc = exp_check_ops(exp);
1979         if (rc)
1980                 return rc;
1981
1982         return exp->exp_obd->obd_type->typ_md_ops->m_batch_add(exp, bh, item);
1983 }
1984
1985 /* OBD Metadata Support */
1986
1987 extern int obd_init_caches(void);
1988 extern void obd_cleanup_caches(void);
1989
1990 typedef int (*register_lwp_cb)(void *data);
1991
1992 struct lwp_register_item {
1993         struct obd_export **lri_exp;
1994         register_lwp_cb     lri_cb_func;
1995         void               *lri_cb_data;
1996         struct list_head    lri_list;
1997         atomic_t            lri_ref;
1998         char                lri_name[MTI_NAME_MAXLEN];
1999 };
2000
2001 /* obd_mount.c */
2002 #ifdef HAVE_SERVER_SUPPORT
2003 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
2004                              register_lwp_cb cb_func, void *cb_data);
2005 void lustre_deregister_lwp_item(struct obd_export **exp);
2006 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
2007 void lustre_notify_lwp_list(struct obd_export *exp);
2008 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
2009 #endif /* HAVE_SERVER_SUPPORT */
2010 int lustre_check_exclusion(struct super_block *sb, char *svname);
2011
2012 /* lustre_peer.c    */
2013 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
2014                         int index);
2015 int class_add_uuid(const char *uuid, struct lnet_nid *nid);
2016 int class_del_uuid (const char *uuid);
2017 int class_add_nids_to_uuid(struct obd_uuid *uuid, struct lnet_nid *nidlist,
2018                            int nid_count, int nid_size);
2019 int class_check_uuid(struct obd_uuid *uuid, struct lnet_nid *nid);
2020
2021 /* class_obd.c */
2022 extern char obd_jobid_name[];
2023
2024 extern unsigned int obd_lbug_on_eviction;
2025 extern unsigned int obd_dump_on_eviction;
2026
2027 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
2028 {
2029         if (obd_lbug_on_eviction &&
2030             strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
2031                     strlen(LUSTRE_MGC_NAME))) {
2032                 CERROR("LBUG upon eviction\n");
2033                 LBUG();
2034         }
2035
2036         return obd_dump_on_eviction;
2037 }
2038
2039 /* statfs_pack.c */
2040 struct kstatfs;
2041 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
2042 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
2043
2044 /* root squash info */
2045 struct root_squash_info {
2046         uid_t                   rsi_uid;
2047         gid_t                   rsi_gid;
2048         struct list_head        rsi_nosquash_nids;
2049         spinlock_t              rsi_lock;
2050 };
2051
2052 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
2053
2054 /* linux-module.c */
2055 struct obd_ioctl_data;
2056 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
2057 int class_procfs_init(void);
2058 int class_procfs_clean(void);
2059
2060 extern void obd_heat_add(struct obd_heat_instance *instance,
2061                          unsigned int time_second, __u64 count,
2062                          unsigned int weight, unsigned int period_second);
2063 extern void obd_heat_decay(struct obd_heat_instance *instance,
2064                            __u64 time_second, unsigned int weight,
2065                            unsigned int period_second);
2066 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
2067                           unsigned int time_second, unsigned int weight,
2068                           unsigned int period_second);
2069 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
2070
2071 /* struct kobj_type */
2072 static inline
2073 struct attribute *_get_attr_matches(const struct kobj_type *typ,
2074                                     const char *key, size_t keylen,
2075                                     int (*is_match)(const char *, const char *,
2076                                                     size_t))
2077 {
2078         int i;
2079
2080 #ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
2081         for (i = 0; typ->default_groups[i]; i++) {
2082                 int k;
2083                 struct attribute **attrs;
2084
2085                 attrs = (struct attribute **)typ->default_groups[i]->attrs;
2086                 for (k = 0; attrs[k]; k++) {
2087                         if (is_match(attrs[k]->name, key, keylen))
2088                                 return (struct attribute *)attrs[k];
2089                 }
2090         }
2091 #else
2092         for (i = 0; typ->default_attrs[i]; i++) {
2093                 if (is_match(typ->default_attrs[i]->name, key, keylen))
2094                         return typ->default_attrs[i];
2095         }
2096 #endif
2097         return NULL;
2098 }
2099
2100 static inline
2101 int _attr_name_exact(const char *attr_name, const char *key, size_t len)
2102 {
2103         return !strcmp(attr_name, key);
2104 }
2105
2106 static inline
2107 struct attribute *get_attr_by_name(const struct kobj_type *typ,
2108                                    const char *name)
2109 {
2110         return _get_attr_matches(typ, name, 0, _attr_name_exact);
2111 }
2112
2113 static inline
2114 int _attr_name_starts_with(const char *attr_name, const char *name, size_t len)
2115 {
2116         return !strncmp(attr_name, name, len);
2117 }
2118
2119 static inline
2120 struct attribute *get_attr_starts_with(const struct kobj_type *typ,
2121                                        const char *name,
2122                                        size_t len)
2123 {
2124         return _get_attr_matches(typ, name, len, _attr_name_starts_with);
2125 }
2126
2127 int obd_ioctl_msg(const char *file, const char *func, int line, int level,
2128                   const char *name, unsigned int cmd, const char *msg, int rc);
2129 #define OBD_IOC_DEBUG(level, dev, cmd, msg, rc) \
2130         obd_ioctl_msg(__FILE__, __func__, __LINE__, level, dev, cmd, msg, rc)
2131 #define OBD_IOC_ERROR(dev, cmd, msg, rc)        \
2132         obd_ioctl_msg(__FILE__, __func__, __LINE__, D_ERROR, dev, cmd, msg, rc)
2133
2134 #endif /* __LINUX_OBD_CLASS_H */