1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5 * Use is subject to license terms.
7 * Copyright (c) 2011, 2017, Intel Corporation.
11 * This file is part of Lustre, http://www.lustre.org/
13 * lustre/include/obd_class.h
15 * Header defining common operations on OBD devices.
22 #include <linux/kobject.h>
23 #include <obd_support.h>
24 #include <lustre_import.h>
25 #include <lustre_net.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>
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
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
48 #define OBD_MAX_INDEX xa_limit_31b.max
50 #define obd_device_find(devno) \
51 xa_find(&obd_devs, &devno, OBD_MAX_INDEX, XA_PRESENT)
53 #define obd_device_find_after(devno) \
54 xa_find_after(&obd_devs, &devno, OBD_MAX_INDEX, XA_PRESENT)
56 #define obd_device_for_each(devno, obd) \
57 xa_for_each(&obd_devs, devno, obd)
59 #define obd_device_for_each_start(devno, obd, start) \
60 xa_for_each_start(&obd_devs, devno, obd, start)
62 #define obd_device_for_each_cond(devno, obd, cond) \
63 obd_device_for_each(devno, obd) \
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))
70 #define obd_device_lock() xa_lock(&obd_devs)
71 #define obd_device_unlock() xa_unlock(&obd_devs)
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);
83 struct lu_device_type;
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);
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);
96 struct obd_device *class_newdev(const char *type_name, const char *name,
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);
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);
113 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
115 static inline char *obd_export_nid2str(struct obd_export *exp)
117 return exp->exp_connection == NULL ?
118 "<unknown>" : libcfs_nidstr(&exp->exp_connection->c_peer.nid);
121 static inline char *obd_import_nid2str(struct obd_import *imp)
123 return imp->imp_connection == NULL ?
124 "<unknown>" : libcfs_nidstr(&imp->imp_connection->c_peer.nid);
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,
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);
149 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
150 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
154 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
155 struct llog_rec_hdr *, void *);
157 struct obd_export *obd_stale_export_get(void);
158 void obd_stale_export_put(struct obd_export *exp);
159 void obd_stale_export_adjust(struct obd_export *exp);
162 /* For interoperability */
163 struct cfg_interop_param {
168 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
169 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
170 const char *new_name);
171 void print_lustre_cfg(struct lustre_cfg *lcfg);
172 int class_process_config(struct lustre_cfg *lcfg);
173 ssize_t class_set_global(const char *param);
174 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
175 struct kobject *kobj);
176 int class_attach(struct lustre_cfg *lcfg);
177 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
178 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
179 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
181 int class_find_param(char *buf, char *key, char **valp);
182 struct cfg_interop_param *class_find_old_param(const char *param,
183 struct cfg_interop_param *ptr);
184 int class_get_next_param(char **params, char *copy);
185 int class_match_param(char *buf, const char *key, char **valp);
186 int class_parse_nid(char *buf, struct lnet_nid *nid, char **endh);
187 int class_parse_nid_quiet(char *buf, struct lnet_nid *nid, char **endh);
188 int class_parse_net(char *buf, u32 *net, char **endh);
189 int class_match_nid(char *buf, char *key, struct lnet_nid *nid);
190 int class_match_net(char *buf, char *key, u32 net);
192 struct obd_device *class_incref(struct obd_device *obd,
193 const char *scope, const void *source);
194 void class_decref(struct obd_device *obd,
195 const char *scope, const void *source);
196 void dump_exports(struct obd_device *obd, int locks, int debug_level);
197 int class_config_llog_handler(const struct lu_env *env,
198 struct llog_handle *handle,
199 struct llog_rec_hdr *rec, void *data);
200 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
202 #define CFG_F_START 0x01 /* Set when we start updating from a log */
203 #define CFG_F_MARKER 0x02 /* We are within a maker */
204 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
205 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
207 /* Passed as data param to class_config_parse_llog */
208 struct config_llog_instance {
209 unsigned long cfg_instance;
210 struct super_block *cfg_sb;
211 struct obd_uuid cfg_uuid;
212 llog_cb_t cfg_callback;
213 int cfg_last_idx; /* for partial llog processing */
218 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
219 char *name, struct config_llog_instance *cfg);
222 * Generate a unique configuration instance for this mount
224 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
225 * For now, use the same value as before - the superblock pointer value.
227 * Using the client UUID would be an option, but it needs more testing.
229 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
231 return (unsigned long)sb;
234 #define CONFIG_SUB_SPTLRPC 0x01
235 #define CONFIG_SUB_RECOVER 0x02
236 #define CONFIG_SUB_PARAMS 0x04
237 #define CONFIG_SUB_NODEMAP 0x08
238 #define CONFIG_SUB_BARRIER 0x10
240 /* Sub clds should be attached to the config_llog_data when processing
241 * config log for client or server target. */
242 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
244 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
247 #define PARAMS_FILENAME "params"
248 #define BARRIER_FILENAME "barrier"
249 #define LCTL_UPCALL "lctl"
251 static inline bool logname_is_barrier(const char *logname)
255 /* logname for barrier is "fsname-barrier" */
256 ptr = strstr(logname, BARRIER_FILENAME);
257 if (ptr && (ptr - logname) >= 2 &&
258 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
264 /* list of active configuration logs */
265 struct config_llog_data {
266 struct ldlm_res_id cld_resid;
267 struct lustre_handle cld_lockh;
268 struct config_llog_instance cld_cfg;
269 struct list_head cld_list_chain;/* on config_llog_list */
270 atomic_t cld_refcount;
271 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
272 struct config_llog_data *cld_params; /* common parameters log */
273 struct config_llog_data *cld_recover;/* imperative recover log */
274 struct config_llog_data *cld_nodemap;/* nodemap log */
275 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
276 struct obd_export *cld_mgcexp;
277 struct mutex cld_lock;
278 enum mgs_cfg_type cld_type;
279 unsigned int cld_stopping:1, /* we were told to stop
281 cld_lostlock:1; /* lock not requeued */
285 struct lustre_profile {
286 struct list_head lp_list;
291 bool lp_list_deleted;
294 struct lustre_profile *class_get_profile(const char * prof);
295 void class_del_profile(const char *prof);
296 void class_put_profile(struct lustre_profile *lprof);
297 void class_del_profiles(void);
300 #if LUSTRE_TRACKS_LOCK_EXP_REFS
302 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
303 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
304 extern void (*class_export_dump_hook)(struct obd_export *);
308 #define __class_export_add_lock_ref(exp, lock) do {} while (0)
309 #define __class_export_del_lock_ref(exp, lock) do {} while (0)
313 #define class_export_rpc_inc(exp) \
315 atomic_inc(&(exp)->exp_rpc_count); \
316 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
317 (exp), atomic_read(&(exp)->exp_rpc_count)); \
320 #define class_export_rpc_dec(exp) \
322 LASSERT(atomic_read(&(exp)->exp_rpc_count) > 0); \
323 atomic_dec(&(exp)->exp_rpc_count); \
324 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
325 (exp), atomic_read(&(exp)->exp_rpc_count)); \
328 #define class_export_lock_get(exp, lock) \
330 atomic_inc(&(exp)->exp_locks_count); \
331 __class_export_add_lock_ref(exp, lock); \
332 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
333 (exp), atomic_read(&(exp)->exp_locks_count)); \
334 class_export_get(exp); \
337 #define class_export_lock_put(exp, lock) \
339 LASSERT(atomic_read(&(exp)->exp_locks_count) > 0); \
340 atomic_dec(&(exp)->exp_locks_count); \
341 __class_export_del_lock_ref(exp, lock); \
342 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
343 (exp), atomic_read(&(exp)->exp_locks_count)); \
344 class_export_put(exp); \
347 #define class_export_cb_get(exp) \
349 atomic_inc(&(exp)->exp_cb_count); \
350 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
351 (exp), atomic_read(&(exp)->exp_cb_count)); \
352 class_export_get(exp); \
355 #define class_export_cb_put(exp) \
357 LASSERT(atomic_read(&(exp)->exp_cb_count) > 0); \
358 atomic_dec(&(exp)->exp_cb_count); \
359 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
360 (exp), atomic_read(&(exp)->exp_cb_count)); \
361 class_export_put(exp); \
365 struct obd_export *class_export_get(struct obd_export *exp);
366 void class_export_put(struct obd_export *exp);
367 struct obd_export *class_new_export(struct obd_device *obd,
368 struct obd_uuid *cluuid);
369 struct obd_export *class_new_export_self(struct obd_device *obd,
370 struct obd_uuid *uuid);
371 void class_unlink_export(struct obd_export *exp);
373 struct obd_import *class_import_get(struct obd_import *);
374 void class_import_put(struct obd_import *);
375 struct obd_import *class_new_import(struct obd_device *obd);
376 void class_destroy_import(struct obd_import *exp);
378 #ifdef HAVE_SERVER_SUPPORT
379 struct obd_type *class_search_type(const char *name);
380 struct obd_type *class_get_type(const char *name);
382 void class_put_type(struct obd_type *type);
383 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
384 struct obd_uuid *cluuid);
385 int class_disconnect(struct obd_export *exp);
386 void class_fail_export(struct obd_export *exp);
387 int class_connected_export(struct obd_export *exp);
388 void class_disconnect_exports(struct obd_device *obd);
389 int class_manual_cleanup(struct obd_device *obd);
390 void class_disconnect_stale_exports(struct obd_device *,
391 int (*test_export)(struct obd_export *));
393 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
395 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
396 (obd->obd_force ? OBD_OPT_FORCE : 0) |
397 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
401 #ifdef HAVE_SERVER_SUPPORT
402 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
404 struct obd_device_target *obt;
406 LASSERT(exp->exp_obd);
407 obt = (void *)&exp->exp_obd->u;
408 if (obt->obt_magic != OBT_MAGIC)
413 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
415 struct obd_device_target *obt = obd2obt(obd);
418 return &obt->obt_lut->lut_lsd;
426 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
427 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
429 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
430 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
432 static inline int obd_check_dev(struct obd_device *obd)
435 CERROR("NULL device\n");
441 /* ensure obd_setup and !obd_stopping */
442 #define OBD_CHECK_DEV_ACTIVE(obd) \
444 rc = obd_check_dev(obd); \
448 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
449 CERROR("Device %d not setup\n", \
456 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
458 /* Always add in ldlm_stats */
459 tmp->nid_ldlm_stats =
460 lprocfs_stats_alloc(LDLM_LAST_OPC - LDLM_FIRST_OPC,
461 LPROCFS_STATS_FLAG_NOPERCPU);
462 if (tmp->nid_ldlm_stats == NULL)
465 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
467 return lprocfs_stats_register(tmp->nid_proc, "ldlm_stats",
468 tmp->nid_ldlm_stats);
471 static inline int exp_check_ops(struct obd_export *exp)
476 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
482 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
483 __u32 keylen, void *key,
484 __u32 *vallen, void *val)
490 rc = exp_check_ops(exp);
494 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
495 CERROR("%s: no %s operation\n",
496 (exp)->exp_obd->obd_name, __func__);
500 rc = exp->exp_obd->obd_type->typ_dt_ops->o_get_info(env, exp, keylen,
505 static inline int obd_set_info_async(const struct lu_env *env,
506 struct obd_export *exp,
507 __u32 keylen, void *key,
508 __u32 vallen, void *val,
509 struct ptlrpc_request_set *set)
515 rc = exp_check_ops(exp);
519 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
520 CERROR("%s: no %s operation\n",
521 (exp)->exp_obd->obd_name, __func__);
525 rc = exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async(env, exp,
534 * obd-lu integration.
536 * Functionality is being moved into new lu_device-based layering, but some
537 * pieces of configuration process are still based on obd devices.
539 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
540 * subsume ->o_setup() methods of obd devices they replace. The same for
541 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
542 * result, obd_setup() and obd_process_config() branch and call one XOR
545 * Yet neither lu_device_type_operations::ldto_device_fini() nor
546 * lu_device_type_operations::ldto_device_free() fully implement the
547 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
548 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
550 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
553 struct obd_type *type = obd->obd_type;
554 struct lu_device_type *ldt;
558 wait_var_event(&type->typ_lu,
559 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
562 struct lu_context session_ctx;
565 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
566 session_ctx.lc_thread = NULL;
567 lu_context_enter(&session_ctx);
569 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
571 struct lu_device *dev;
572 env.le_ses = &session_ctx;
573 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
576 obd->obd_lu_dev = dev;
578 #ifdef HAVE_SERVER_SUPPORT
579 if (lu_device_is_dt(dev) &&
580 lu2dt_dev(dev)->dd_rdonly)
581 obd->obd_read_only = 1;
587 lu_context_exit(&session_ctx);
588 lu_context_fini(&session_ctx);
590 if (!obd->obd_type->typ_dt_ops->o_setup) {
591 CERROR("%s: no %s operation\n", obd->obd_name,
595 rc = obd->obd_type->typ_dt_ops->o_setup(obd, cfg);
600 static inline int obd_precleanup(struct obd_device *obd)
603 struct lu_device_type *ldt = obd->obd_type->typ_lu;
604 struct lu_device *d = obd->obd_lu_dev;
608 if (ldt != NULL && d != NULL) {
609 struct lu_env *env = lu_env_find();
614 rc = lu_env_init(env, ldt->ldt_ctx_tags);
618 ldt->ldt_ops->ldto_device_fini(env, d);
625 if (!obd->obd_type->typ_dt_ops->o_precleanup)
628 rc = obd->obd_type->typ_dt_ops->o_precleanup(obd);
632 static inline int obd_cleanup(struct obd_device *obd)
635 struct lu_device_type *ldt = obd->obd_type->typ_lu;
636 struct lu_device *d = obd->obd_lu_dev;
639 if (ldt != NULL && d != NULL) {
642 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
644 ldt->ldt_ops->ldto_device_free(&env, d);
646 obd->obd_lu_dev = NULL;
649 if (!obd->obd_type->typ_dt_ops->o_cleanup)
652 rc = obd->obd_type->typ_dt_ops->o_cleanup(obd);
656 static inline void obd_cleanup_client_import(struct obd_device *obd)
660 /* If we set up but never connected, the client import will not
663 down_write(&obd->u.cli.cl_sem);
664 if (obd->u.cli.cl_import) {
665 struct obd_import *imp;
667 imp = obd->u.cli.cl_import;
668 CDEBUG(D_CONFIG, "%s: client import never connected\n",
670 ptlrpc_invalidate_import(imp);
671 client_destroy_import(imp);
672 obd->u.cli.cl_import = NULL;
674 up_write(&obd->u.cli.cl_sem);
679 static inline int obd_process_config(struct obd_device *obd, int datalen,
683 struct lu_device_type *ldt = obd->obd_type->typ_lu;
684 struct lu_device *d = obd->obd_lu_dev;
688 obd->obd_process_conf = 1;
689 if (ldt != NULL && d != NULL) {
692 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
694 rc = d->ld_ops->ldo_process_config(&env, d, data);
698 if (!obd->obd_type->typ_dt_ops->o_process_config) {
699 CERROR("%s: no %s operation\n",
700 obd->obd_name, __func__);
703 rc = obd->obd_type->typ_dt_ops->o_process_config(obd, datalen,
707 obd->obd_process_conf = 0;
712 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
719 rc = exp_check_ops(exp);
723 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
724 CERROR("%s: no %s operation\n",
725 (exp)->exp_obd->obd_name, __func__);
729 rc = exp->exp_obd->obd_type->typ_dt_ops->o_create(env, exp, obdo);
733 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
740 rc = exp_check_ops(exp);
744 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
745 CERROR("%s: no %s operation\n",
746 (exp)->exp_obd->obd_name, __func__);
750 rc = exp->exp_obd->obd_type->typ_dt_ops->o_destroy(env, exp, obdo);
754 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
760 rc = exp_check_ops(exp);
764 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
765 CERROR("%s: no %s operation\n",
766 (exp)->exp_obd->obd_name, __func__);
770 rc = exp->exp_obd->obd_type->typ_dt_ops->o_getattr(env, exp, oa);
775 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
781 rc = exp_check_ops(exp);
785 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
786 CERROR("%s: no %s operation\n",
787 (exp)->exp_obd->obd_name, __func__);
791 rc = exp->exp_obd->obd_type->typ_dt_ops->o_setattr(env, exp, oa);
796 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
799 struct obd_device *obd = imp->imp_obd;
804 OBD_CHECK_DEV_ACTIVE(obd);
805 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
806 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
810 rc = obd->obd_type->typ_dt_ops->o_add_conn(imp, uuid, priority);
814 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
816 struct obd_device *obd = imp->imp_obd;
821 OBD_CHECK_DEV_ACTIVE(obd);
822 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
823 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
827 rc = obd->obd_type->typ_dt_ops->o_del_conn(imp, uuid);
831 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
833 struct obd_uuid *uuid;
837 if (!exp->exp_obd->obd_type ||
838 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
841 uuid = exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid(exp);
845 /** Create a new /a exp on device /a obd for the uuid /a cluuid
846 * @param exp New export handle
847 * @param d Connect data, supported flags are set, flags also understood
848 * by obd are returned.
850 static inline int obd_connect(const struct lu_env *env,
851 struct obd_export **exp, struct obd_device *obd,
852 struct obd_uuid *cluuid,
853 struct obd_connect_data *data,
857 __u64 ocf = data ? data->ocd_connect_flags : 0;
861 OBD_CHECK_DEV_ACTIVE(obd);
862 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
863 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
867 rc = obd->obd_type->typ_dt_ops->o_connect(env, exp, obd, cluuid, data,
869 /* check that only subset is granted */
870 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
871 data->ocd_connect_flags));
875 static inline int obd_reconnect(const struct lu_env *env,
876 struct obd_export *exp,
877 struct obd_device *obd,
878 struct obd_uuid *cluuid,
879 struct obd_connect_data *d,
883 __u64 ocf = d ? d->ocd_connect_flags : 0;
887 OBD_CHECK_DEV_ACTIVE(obd);
888 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
891 rc = obd->obd_type->typ_dt_ops->o_reconnect(env, exp, obd, cluuid, d,
893 /* check that only subset is granted */
894 LASSERT(ergo(d != NULL,
895 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
899 static inline int obd_disconnect(struct obd_export *exp)
904 rc = exp_check_ops(exp);
908 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
909 CERROR("%s: no %s operation\n",
910 (exp)->exp_obd->obd_name, __func__);
914 rc = exp->exp_obd->obd_type->typ_dt_ops->o_disconnect(exp);
918 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
919 enum lu_cli_type type)
925 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
928 rc = obd->obd_type->typ_dt_ops->o_fid_init(obd, exp, type);
932 static inline int obd_fid_fini(struct obd_device *obd)
937 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
940 rc = obd->obd_type->typ_dt_ops->o_fid_fini(obd);
944 static inline int obd_fid_alloc(const struct lu_env *env,
945 struct obd_export *exp,
947 struct md_op_data *op_data)
952 rc = exp_check_ops(exp);
956 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
957 CERROR("%s: no %s operation\n",
958 (exp)->exp_obd->obd_name, __func__);
962 rc = exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc(env, exp, fid,
967 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
973 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
974 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
978 /* Check poolname validity */
979 if (!poolname || poolname[0] == '\0' || lov_pool_is_reserved(poolname))
982 rc = obd->obd_type->typ_dt_ops->o_pool_new(obd, poolname);
986 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
991 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
992 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
996 rc = obd->obd_type->typ_dt_ops->o_pool_del(obd, poolname);
1000 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1007 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1008 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1009 RETURN(-EOPNOTSUPP);
1012 rc = obd->obd_type->typ_dt_ops->o_pool_add(obd, poolname, ostname);
1016 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1022 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1023 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1024 RETURN(-EOPNOTSUPP);
1027 rc = obd->obd_type->typ_dt_ops->o_pool_rem(obd, poolname, ostname);
1031 static inline int obd_init_export(struct obd_export *exp)
1036 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1037 exp->exp_obd->obd_type->typ_dt_ops->o_init_export)
1038 rc = exp->exp_obd->obd_type->typ_dt_ops->o_init_export(exp);
1042 static inline int obd_destroy_export(struct obd_export *exp)
1045 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1046 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export)
1047 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export(exp);
1051 /* @max_age is the oldest time in seconds that we accept using a cached data.
1052 * If the cache is older than @max_age we will get a new value from the
1053 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1055 static inline int obd_statfs_async(struct obd_export *exp,
1056 struct obd_info *oinfo,
1058 struct ptlrpc_request_set *rqset)
1060 struct obd_device *obd;
1065 if (exp == NULL || exp->exp_obd == NULL)
1069 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1071 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1075 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1076 obd->obd_name, obd->obd_osfs_age, max_age);
1077 rc = obd->obd_type->typ_dt_ops->o_statfs_async(exp, oinfo, max_age,
1083 /* @max_age is the oldest time in seconds that we accept using a cached data.
1084 * If the cache is older than @max_age we will get a new value from the
1085 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1087 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1088 struct obd_statfs *osfs, time64_t max_age,
1091 struct obd_device *obd;
1095 if (unlikely(exp == NULL || exp->exp_obd == NULL))
1099 OBD_CHECK_DEV_ACTIVE(obd);
1101 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1102 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1103 RETURN(-EOPNOTSUPP);
1106 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1107 obd->obd_name, obd->obd_osfs_age, max_age);
1108 /* ignore cache if aggregated isn't expected */
1109 if (obd->obd_osfs_age < max_age ||
1110 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1111 !(flags & OBD_STATFS_SUM))) {
1112 /* the RPC will block anyway, so avoid sending many at once */
1113 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1114 (flags & OBD_STATFS_NESTED)
1115 ? SINGLE_DEPTH_NESTING : 0);
1118 if (obd->obd_osfs_age < max_age ||
1119 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1120 !(flags & OBD_STATFS_SUM))) {
1121 rc = obd->obd_type->typ_dt_ops->o_statfs(env, exp, osfs,
1125 mutex_unlock(&obd->obd_dev_mutex);
1126 GOTO(cached, rc = 0);
1130 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1131 obd->obd_name, &obd->obd_osfs,
1132 osfs->os_bavail, osfs->os_blocks,
1133 osfs->os_ffree, osfs->os_files);
1135 spin_lock(&obd->obd_osfs_lock);
1136 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1137 obd->obd_osfs_age = ktime_get_seconds();
1138 spin_unlock(&obd->obd_osfs_lock);
1140 mutex_unlock(&obd->obd_dev_mutex);
1144 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1145 obd->obd_name, &obd->obd_osfs,
1146 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1147 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1148 spin_lock(&obd->obd_osfs_lock);
1149 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1150 spin_unlock(&obd->obd_osfs_lock);
1155 static inline int obd_preprw(const struct lu_env *env, int cmd,
1156 struct obd_export *exp, struct obdo *oa,
1157 int objcount, struct obd_ioobj *obj,
1158 struct niobuf_remote *remote, int *pages,
1159 struct niobuf_local *local)
1165 rc = exp_check_ops(exp);
1169 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1170 CERROR("%s: no %s operation\n",
1171 (exp)->exp_obd->obd_name, __func__);
1175 rc = exp->exp_obd->obd_type->typ_dt_ops->o_preprw(env, cmd, exp,
1177 remote, pages, local);
1182 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1183 struct obd_export *exp, struct obdo *oa,
1184 int objcount, struct obd_ioobj *obj,
1185 struct niobuf_remote *rnb, int pages,
1186 struct niobuf_local *local, const int orig_rc,
1187 int nob, ktime_t kstart)
1193 rc = exp_check_ops(exp);
1197 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1198 CERROR("%s: no %s operation\n",
1199 (exp)->exp_obd->obd_name, __func__);
1203 rc = exp->exp_obd->obd_type->typ_dt_ops->o_commitrw(env, cmd, exp, oa,
1212 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1213 int len, void *karg, void __user *uarg)
1219 rc = exp_check_ops(exp);
1223 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1224 CERROR("%s: no %s operation\n",
1225 (exp)->exp_obd->obd_name, __func__);
1229 rc = exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol(cmd, exp,
1235 static inline void obd_import_event(struct obd_device *obd,
1236 struct obd_import *imp,
1237 enum obd_import_event event)
1241 CERROR("NULL device\n");
1246 if (obd->obd_set_up && obd->obd_type->typ_dt_ops->o_import_event)
1247 obd->obd_type->typ_dt_ops->o_import_event(obd, imp, event);
1252 static inline int obd_notify(struct obd_device *obd,
1253 struct obd_device *watched,
1254 enum obd_notify_event ev)
1260 rc = obd_check_dev(obd);
1264 if (!obd->obd_set_up) {
1265 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1269 if (!obd->obd_type->typ_dt_ops->o_notify) {
1270 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1274 rc = obd->obd_type->typ_dt_ops->o_notify(obd, watched, ev);
1279 static inline int obd_notify_observer(struct obd_device *observer,
1280 struct obd_device *observed,
1281 enum obd_notify_event ev)
1285 struct obd_notify_upcall *onu;
1287 if (WARN_ON_ONCE(!observer))
1290 if (observer->obd_observer)
1291 rc = obd_notify(observer->obd_observer, observed, ev);
1294 * Also, call non-obd listener, if any
1296 onu = &observer->obd_upcall;
1297 if (onu->onu_upcall != NULL)
1298 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1300 return rc ? rc : rc2;
1303 static inline int obd_quotactl(struct obd_export *exp,
1304 struct obd_quotactl *oqctl)
1310 rc = exp_check_ops(exp);
1314 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1315 CERROR("%s: no %s operation\n",
1316 (exp)->exp_obd->obd_name, __func__);
1320 rc = exp->exp_obd->obd_type->typ_dt_ops->o_quotactl(exp->exp_obd,
1325 static inline int obd_health_check(const struct lu_env *env,
1326 struct obd_device *obd)
1328 /* returns: 0 on healthy
1329 * >0 on unhealthy + reason code/flag
1330 * however the only suppored reason == 1 right now
1331 * We'll need to define some better reasons
1332 * or flags in the future.
1339 /* NULL method is normal here */
1340 if (obd == NULL || !obd->obd_type) {
1341 CERROR("cleaned up obd\n");
1342 RETURN(-EOPNOTSUPP);
1344 if (!obd->obd_set_up || obd->obd_stopping)
1346 if (!obd->obd_type->typ_dt_ops->o_health_check)
1349 rc = obd->obd_type->typ_dt_ops->o_health_check(env, obd);
1353 static inline int obd_register_observer(struct obd_device *obd,
1354 struct obd_device *observer)
1360 rc = obd_check_dev(obd);
1364 down_write(&obd->obd_observer_link_sem);
1365 if (obd->obd_observer && observer) {
1366 up_write(&obd->obd_observer_link_sem);
1369 obd->obd_observer = observer;
1370 up_write(&obd->obd_observer_link_sem);
1374 /* metadata helpers */
1380 LPROC_MD_INTENT_LOCK,
1389 LPROC_MD_INTENT_GETATTR_ASYNC,
1390 LPROC_MD_REVALIDATE_LOCK,
1394 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1399 rc = exp_check_ops(exp);
1403 return exp->exp_obd->obd_type->typ_md_ops->m_get_root(exp, fileset,
1407 static inline int md_getattr(struct obd_export *exp,
1408 struct md_op_data *op_data,
1409 struct ptlrpc_request **request)
1413 rc = exp_check_ops(exp);
1417 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1420 return exp->exp_obd->obd_type->typ_md_ops->m_getattr(exp, op_data,
1424 static inline int md_null_inode(struct obd_export *exp,
1425 const struct lu_fid *fid)
1429 rc = exp_check_ops(exp);
1433 return exp->exp_obd->obd_type->typ_md_ops->m_null_inode(exp, fid);
1436 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1437 struct md_open_data *mod,
1438 struct ptlrpc_request **request)
1442 rc = exp_check_ops(exp);
1446 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1449 return exp->exp_obd->obd_type->typ_md_ops->m_close(exp, op_data, mod,
1453 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1454 const void *data, size_t datalen, umode_t mode,
1455 uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1456 __u64 rdev, struct ptlrpc_request **request)
1460 rc = exp_check_ops(exp);
1464 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1467 return exp->exp_obd->obd_type->typ_md_ops->m_create(exp, op_data, data,
1473 static inline int md_enqueue(struct obd_export *exp,
1474 struct ldlm_enqueue_info *einfo,
1475 const union ldlm_policy_data *policy,
1476 struct md_op_data *op_data,
1477 struct lustre_handle *lockh,
1478 __u64 extra_lock_flags)
1482 rc = exp_check_ops(exp);
1486 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1489 return exp->exp_obd->obd_type->typ_md_ops->m_enqueue(exp, einfo, policy,
1494 static inline int md_getattr_name(struct obd_export *exp,
1495 struct md_op_data *op_data,
1496 struct ptlrpc_request **request)
1500 rc = exp_check_ops(exp);
1504 return exp->exp_obd->obd_type->typ_md_ops->m_getattr_name(exp, op_data,
1508 static inline int md_intent_lock(struct obd_export *exp,
1509 struct md_op_data *op_data,
1510 struct lookup_intent *it,
1511 struct ptlrpc_request **reqp,
1512 ldlm_blocking_callback cb_blocking,
1513 __u64 extra_lock_flags)
1517 rc = exp_check_ops(exp);
1521 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1522 LPROC_MD_INTENT_LOCK);
1524 return exp->exp_obd->obd_type->typ_md_ops->m_intent_lock(exp, op_data,
1530 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1531 struct ptlrpc_request **request)
1535 rc = exp_check_ops(exp);
1539 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1542 return exp->exp_obd->obd_type->typ_md_ops->m_link(exp, op_data,
1546 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1547 const char *old_name, size_t oldlen,
1548 const char *new_name, size_t newlen,
1549 struct ptlrpc_request **request)
1553 rc = exp_check_ops(exp);
1557 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1560 return exp->exp_obd->obd_type->typ_md_ops->m_rename(exp, op_data,
1566 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1567 void *ea, size_t ealen,
1568 struct ptlrpc_request **request)
1572 rc = exp_check_ops(exp);
1576 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1579 return exp->exp_obd->obd_type->typ_md_ops->m_setattr(exp, op_data, ea,
1583 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1584 struct ptlrpc_request **request)
1588 rc = exp_check_ops(exp);
1592 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1595 return exp->exp_obd->obd_type->typ_md_ops->m_fsync(exp, fid, request);
1598 /* FLR: resync mirrored files. */
1599 static inline int md_file_resync(struct obd_export *exp,
1600 struct md_op_data *data)
1604 rc = exp_check_ops(exp);
1608 return exp->exp_obd->obd_type->typ_md_ops->m_file_resync(exp, data);
1611 static inline int md_read_page(struct obd_export *exp,
1612 struct md_op_data *op_data,
1613 struct md_readdir_info *mrinfo,
1614 __u64 hash_offset, struct page **ppage)
1618 rc = exp_check_ops(exp);
1622 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1623 LPROC_MD_READ_PAGE);
1625 return exp->exp_obd->obd_type->typ_md_ops->m_read_page(exp, op_data,
1631 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1632 struct ptlrpc_request **request)
1636 rc = exp_check_ops(exp);
1640 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1643 return exp->exp_obd->obd_type->typ_md_ops->m_unlink(exp, op_data,
1647 static inline int md_get_lustre_md(struct obd_export *exp,
1648 struct req_capsule *pill,
1649 struct obd_export *dt_exp,
1650 struct obd_export *md_exp,
1651 struct lustre_md *md)
1655 rc = exp_check_ops(exp);
1659 return exp->exp_obd->obd_type->typ_md_ops->m_get_lustre_md(exp, pill,
1664 static inline int md_put_lustre_md(struct obd_export *exp,
1665 struct lustre_md *md)
1669 rc = exp_check_ops(exp);
1673 return exp->exp_obd->obd_type->typ_md_ops->m_put_lustre_md(exp, md);
1676 static inline int md_merge_attr(struct obd_export *exp,
1677 const struct lmv_stripe_object *lso,
1678 struct cl_attr *attr,
1679 ldlm_blocking_callback cb)
1683 rc = exp_check_ops(exp);
1687 return exp->exp_obd->obd_type->typ_md_ops->m_merge_attr(exp, lso, attr,
1691 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1692 u64 obd_md_valid, const char *name,
1693 const void *value, size_t value_size,
1694 unsigned int xattr_flags, u32 suppgid,
1695 struct ptlrpc_request **req)
1699 rc = exp_check_ops(exp);
1703 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1706 return exp->exp_obd->obd_type->typ_md_ops->m_setxattr(exp, fid,
1715 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1716 u64 obd_md_valid, const char *name,
1717 size_t buf_size, struct ptlrpc_request **req)
1721 rc = exp_check_ops(exp);
1725 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1728 return exp->exp_obd->obd_type->typ_md_ops->m_getxattr(exp, fid,
1734 static inline int md_set_open_replay_data(struct obd_export *exp,
1735 struct obd_client_handle *och,
1736 struct lookup_intent *it)
1740 rc = exp_check_ops(exp);
1744 return exp->exp_obd->obd_type->typ_md_ops->m_set_open_replay_data(exp,
1749 static inline int md_clear_open_replay_data(struct obd_export *exp,
1750 struct obd_client_handle *och)
1754 rc = exp_check_ops(exp);
1758 return exp->exp_obd->obd_type->typ_md_ops->m_clear_open_replay_data(exp, och);
1761 static inline int md_set_lock_data(struct obd_export *exp,
1762 const struct lustre_handle *lockh,
1763 void *data, __u64 *bits)
1767 rc = exp_check_ops(exp);
1771 return exp->exp_obd->obd_type->typ_md_ops->m_set_lock_data(exp, lockh,
1777 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1778 union ldlm_policy_data *policy, enum ldlm_mode mode,
1779 enum ldlm_cancel_flags cancel_flags, void *opaque)
1783 rc = exp_check_ops(exp);
1787 return exp->exp_obd->obd_type->typ_md_ops->m_cancel_unused(exp,
1794 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1795 const struct lu_fid *fid,
1796 enum ldlm_type type,
1797 union ldlm_policy_data *policy,
1798 enum ldlm_mode mode,
1799 struct lustre_handle *lockh)
1803 rc = exp_check_ops(exp);
1807 return exp->exp_obd->obd_type->typ_md_ops->m_lock_match(exp, flags,
1813 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1818 rc = exp_check_ops(exp);
1822 return exp->exp_obd->obd_type->typ_md_ops->m_init_ea_size(exp, ea_size,
1826 static inline int md_intent_getattr_async(struct obd_export *exp,
1827 struct md_op_item *item)
1831 rc = exp_check_ops(exp);
1835 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1836 LPROC_MD_INTENT_GETATTR_ASYNC);
1838 return exp->exp_obd->obd_type->typ_md_ops->m_intent_getattr_async(exp,
1842 static inline int md_revalidate_lock(struct obd_export *exp,
1843 struct lookup_intent *it,
1844 struct lu_fid *fid, __u64 *bits)
1848 rc = exp_check_ops(exp);
1852 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1853 LPROC_MD_REVALIDATE_LOCK);
1855 return exp->exp_obd->obd_type->typ_md_ops->m_revalidate_lock(exp,
1860 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1861 const struct lmv_stripe_object *lso,
1862 const char *name, int namelen,
1867 rc = exp_check_ops(exp);
1871 return exp->exp_obd->obd_type->typ_md_ops->m_get_fid_from_lsm(exp,
1877 /* Unpack an MD struct from disk to in-memory format.
1878 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1880 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1881 * If *plsm == NULL then it will be allocated.
1883 static inline int md_stripe_object_create(struct obd_export *exp,
1884 struct lmv_stripe_object **lsop,
1885 const union lmv_mds_md *lmm,
1890 rc = exp_check_ops(exp);
1894 return exp->exp_obd->obd_type->typ_md_ops->m_stripe_object_create(exp,
1900 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1901 int *rcs, struct ptlrpc_request_set *set)
1905 rc = exp_check_ops(exp);
1909 return exp->exp_obd->obd_type->typ_md_ops->m_rmfid(exp, fa, rcs, set);
1912 static inline struct lu_batch *
1913 md_batch_create(struct obd_export *exp, enum lu_batch_flags flags,
1918 rc = exp_check_ops(exp);
1922 return exp->exp_obd->obd_type->typ_md_ops->m_batch_create(exp, flags,
1926 static inline int md_batch_stop(struct obd_export *exp, struct lu_batch *bh)
1930 rc = exp_check_ops(exp);
1934 return exp->exp_obd->obd_type->typ_md_ops->m_batch_stop(exp, bh);
1937 static inline int md_batch_flush(struct obd_export *exp, struct lu_batch *bh,
1942 rc = exp_check_ops(exp);
1946 return exp->exp_obd->obd_type->typ_md_ops->m_batch_flush(exp, bh, wait);
1949 static inline int md_batch_add(struct obd_export *exp, struct lu_batch *bh,
1950 struct md_op_item *item)
1954 rc = exp_check_ops(exp);
1958 return exp->exp_obd->obd_type->typ_md_ops->m_batch_add(exp, bh, item);
1961 /* OBD Metadata Support */
1963 extern int obd_init_caches(void);
1964 extern void obd_cleanup_caches(void);
1966 typedef int (*register_lwp_cb)(void *data);
1968 struct lwp_register_item {
1969 struct obd_export **lri_exp;
1970 register_lwp_cb lri_cb_func;
1972 struct list_head lri_list;
1974 char lri_name[MTI_NAME_MAXLEN];
1978 #ifdef HAVE_SERVER_SUPPORT
1979 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1980 register_lwp_cb cb_func, void *cb_data);
1981 void lustre_deregister_lwp_item(struct obd_export **exp);
1982 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1983 void lustre_notify_lwp_list(struct obd_export *exp);
1984 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1985 #endif /* HAVE_SERVER_SUPPORT */
1986 int lustre_check_exclusion(struct super_block *sb, char *svname);
1989 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
1991 int class_add_uuid(const char *uuid, struct lnet_nid *nid);
1992 int class_del_uuid (const char *uuid);
1993 int class_add_nids_to_uuid(struct obd_uuid *uuid, struct lnet_nid *nidlist,
1994 int nid_count, int nid_size);
1995 int class_check_uuid(struct obd_uuid *uuid, struct lnet_nid *nid);
1998 extern char obd_jobid_name[];
2000 extern unsigned int obd_lbug_on_eviction;
2001 extern unsigned int obd_dump_on_eviction;
2003 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
2005 if (obd_lbug_on_eviction &&
2006 strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
2007 strlen(LUSTRE_MGC_NAME))) {
2008 CERROR("LBUG upon eviction\n");
2012 return obd_dump_on_eviction;
2017 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
2018 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
2020 /* root squash info */
2021 struct root_squash_info {
2024 struct list_head rsi_nosquash_nids;
2025 spinlock_t rsi_lock;
2028 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
2030 /* linux-module.c */
2031 struct obd_ioctl_data;
2032 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
2033 int class_procfs_init(void);
2034 int class_procfs_clean(void);
2036 extern void obd_heat_add(struct obd_heat_instance *instance,
2037 unsigned int time_second, __u64 count,
2038 unsigned int weight, unsigned int period_second);
2039 extern void obd_heat_decay(struct obd_heat_instance *instance,
2040 __u64 time_second, unsigned int weight,
2041 unsigned int period_second);
2042 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
2043 unsigned int time_second, unsigned int weight,
2044 unsigned int period_second);
2045 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
2047 /* struct kobj_type */
2049 struct attribute *_get_attr_matches(const struct kobj_type *typ,
2050 const char *key, size_t keylen,
2051 int (*is_match)(const char *, const char *,
2056 #ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
2057 for (i = 0; typ->default_groups[i]; i++) {
2059 struct attribute **attrs;
2061 attrs = (struct attribute **)typ->default_groups[i]->attrs;
2062 for (k = 0; attrs[k]; k++) {
2063 if (is_match(attrs[k]->name, key, keylen))
2064 return (struct attribute *)attrs[k];
2068 for (i = 0; typ->default_attrs[i]; i++) {
2069 if (is_match(typ->default_attrs[i]->name, key, keylen))
2070 return typ->default_attrs[i];
2077 int _attr_name_exact(const char *attr_name, const char *key, size_t len)
2079 return !strcmp(attr_name, key);
2083 struct attribute *get_attr_by_name(const struct kobj_type *typ,
2086 return _get_attr_matches(typ, name, 0, _attr_name_exact);
2090 int _attr_name_starts_with(const char *attr_name, const char *name, size_t len)
2092 return !strncmp(attr_name, name, len);
2096 struct attribute *get_attr_starts_with(const struct kobj_type *typ,
2100 return _get_attr_matches(typ, name, len, _attr_name_starts_with);
2103 int obd_ioctl_msg(const char *file, const char *func, int line, int level,
2104 const char *name, unsigned int cmd, const char *msg, int rc);
2105 #define OBD_IOC_DEBUG(level, dev, cmd, msg, rc) \
2106 obd_ioctl_msg(__FILE__, __func__, __LINE__, level, dev, cmd, msg, rc)
2107 #define OBD_IOC_ERROR(dev, cmd, msg, rc) \
2108 obd_ioctl_msg(__FILE__, __func__, __LINE__, D_ERROR, dev, cmd, msg, rc)
2110 #endif /* __LINUX_OBD_CLASS_H */