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 refcount_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 */
282 cld_processed:1; /* successfully fetched */
286 struct lustre_profile {
287 struct list_head lp_list;
292 bool lp_list_deleted;
295 struct lustre_profile *class_get_profile(const char * prof);
296 void class_del_profile(const char *prof);
297 void class_put_profile(struct lustre_profile *lprof);
298 void class_del_profiles(void);
301 #if LUSTRE_TRACKS_LOCK_EXP_REFS
303 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
304 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
305 extern void (*class_export_dump_hook)(struct obd_export *);
309 #define __class_export_add_lock_ref(exp, lock) do {} while (0)
310 #define __class_export_del_lock_ref(exp, lock) do {} while (0)
314 #define class_export_rpc_inc(exp) \
316 atomic_inc(&(exp)->exp_rpc_count); \
317 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
318 (exp), atomic_read(&(exp)->exp_rpc_count)); \
321 #define class_export_rpc_dec(exp) \
323 LASSERT(atomic_read(&(exp)->exp_rpc_count) > 0); \
324 atomic_dec(&(exp)->exp_rpc_count); \
325 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
326 (exp), atomic_read(&(exp)->exp_rpc_count)); \
329 #define class_export_lock_get(exp, lock) \
331 atomic_inc(&(exp)->exp_locks_count); \
332 __class_export_add_lock_ref(exp, lock); \
333 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
334 (exp), atomic_read(&(exp)->exp_locks_count)); \
335 class_export_get(exp); \
338 #define class_export_lock_put(exp, lock) \
340 LASSERT(atomic_read(&(exp)->exp_locks_count) > 0); \
341 atomic_dec(&(exp)->exp_locks_count); \
342 __class_export_del_lock_ref(exp, lock); \
343 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
344 (exp), atomic_read(&(exp)->exp_locks_count)); \
345 class_export_put(exp); \
348 #define class_export_cb_get(exp) \
350 atomic_inc(&(exp)->exp_cb_count); \
351 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
352 (exp), atomic_read(&(exp)->exp_cb_count)); \
353 class_export_get(exp); \
356 #define class_export_cb_put(exp) \
358 LASSERT(atomic_read(&(exp)->exp_cb_count) > 0); \
359 atomic_dec(&(exp)->exp_cb_count); \
360 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
361 (exp), atomic_read(&(exp)->exp_cb_count)); \
362 class_export_put(exp); \
366 struct obd_export *class_export_get(struct obd_export *exp);
367 void class_export_put(struct obd_export *exp);
368 struct obd_export *class_new_export(struct obd_device *obd,
369 struct obd_uuid *cluuid);
370 struct obd_export *class_new_export_self(struct obd_device *obd,
371 struct obd_uuid *uuid);
372 void class_unlink_export(struct obd_export *exp);
374 struct obd_import *class_import_get(struct obd_import *);
375 void class_import_put(struct obd_import *);
376 struct obd_import *class_new_import(struct obd_device *obd);
377 void class_destroy_import(struct obd_import *exp);
379 #ifdef HAVE_SERVER_SUPPORT
380 struct obd_type *class_search_type(const char *name);
381 struct obd_type *class_get_type(const char *name);
383 void class_put_type(struct obd_type *type);
384 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
385 struct obd_uuid *cluuid);
386 int class_disconnect(struct obd_export *exp);
387 void class_fail_export(struct obd_export *exp);
388 int class_connected_export(struct obd_export *exp);
389 void class_disconnect_exports(struct obd_device *obd);
390 int class_manual_cleanup(struct obd_device *obd);
391 void class_disconnect_stale_exports(struct obd_device *,
392 int (*test_export)(struct obd_export *));
394 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
396 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
397 (obd->obd_force ? OBD_OPT_FORCE : 0) |
398 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
402 #ifdef HAVE_SERVER_SUPPORT
403 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
405 struct obd_device_target *obt;
407 LASSERT(exp->exp_obd);
408 obt = (void *)&exp->exp_obd->u;
409 if (obt->obt_magic != OBT_MAGIC)
414 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
416 struct obd_device_target *obt = obd2obt(obd);
419 return &obt->obt_lut->lut_lsd;
427 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
428 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
430 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
431 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
433 static inline int obd_check_dev(struct obd_device *obd)
436 CERROR("NULL device\n");
442 /* ensure obd_setup and !obd_stopping */
443 #define OBD_CHECK_DEV_ACTIVE(obd) \
445 rc = obd_check_dev(obd); \
449 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
450 CERROR("Device %d not setup\n", \
457 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
459 /* Always add in ldlm_stats */
460 tmp->nid_ldlm_stats =
461 lprocfs_stats_alloc(LDLM_LAST_OPC - LDLM_FIRST_OPC,
462 LPROCFS_STATS_FLAG_NOPERCPU);
463 if (tmp->nid_ldlm_stats == NULL)
466 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
468 return lprocfs_stats_register(tmp->nid_proc, "ldlm_stats",
469 tmp->nid_ldlm_stats);
472 static inline int exp_check_ops(struct obd_export *exp)
477 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
483 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
484 __u32 keylen, void *key,
485 __u32 *vallen, void *val)
491 rc = exp_check_ops(exp);
495 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
496 CERROR("%s: no %s operation\n",
497 (exp)->exp_obd->obd_name, __func__);
501 rc = exp->exp_obd->obd_type->typ_dt_ops->o_get_info(env, exp, keylen,
506 static inline int obd_set_info_async(const struct lu_env *env,
507 struct obd_export *exp,
508 __u32 keylen, void *key,
509 __u32 vallen, void *val,
510 struct ptlrpc_request_set *set)
516 rc = exp_check_ops(exp);
520 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
521 CERROR("%s: no %s operation\n",
522 (exp)->exp_obd->obd_name, __func__);
526 rc = exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async(env, exp,
535 * obd-lu integration.
537 * Functionality is being moved into new lu_device-based layering, but some
538 * pieces of configuration process are still based on obd devices.
540 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
541 * subsume ->o_setup() methods of obd devices they replace. The same for
542 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
543 * result, obd_setup() and obd_process_config() branch and call one XOR
546 * Yet neither lu_device_type_operations::ldto_device_fini() nor
547 * lu_device_type_operations::ldto_device_free() fully implement the
548 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
549 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
551 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
554 struct obd_type *type = obd->obd_type;
555 struct lu_device_type *ldt;
559 wait_var_event(&type->typ_lu,
560 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
563 struct lu_context session_ctx;
566 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
567 session_ctx.lc_thread = NULL;
568 lu_context_enter(&session_ctx);
570 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
572 struct lu_device *dev;
573 env.le_ses = &session_ctx;
574 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
577 obd->obd_lu_dev = dev;
579 #ifdef HAVE_SERVER_SUPPORT
580 if (lu_device_is_dt(dev) &&
581 lu2dt_dev(dev)->dd_rdonly)
582 obd->obd_read_only = 1;
588 lu_context_exit(&session_ctx);
589 lu_context_fini(&session_ctx);
591 if (!obd->obd_type->typ_dt_ops->o_setup) {
592 CERROR("%s: no %s operation\n", obd->obd_name,
596 rc = obd->obd_type->typ_dt_ops->o_setup(obd, cfg);
601 static inline int obd_precleanup(struct obd_device *obd)
604 struct lu_device_type *ldt = obd->obd_type->typ_lu;
605 struct lu_device *d = obd->obd_lu_dev;
609 if (ldt != NULL && d != NULL) {
610 struct lu_env *env = lu_env_find();
615 rc = lu_env_init(env, ldt->ldt_ctx_tags);
619 ldt->ldt_ops->ldto_device_fini(env, d);
626 if (!obd->obd_type->typ_dt_ops->o_precleanup)
629 rc = obd->obd_type->typ_dt_ops->o_precleanup(obd);
633 static inline int obd_cleanup(struct obd_device *obd)
636 struct lu_device_type *ldt = obd->obd_type->typ_lu;
637 struct lu_device *d = obd->obd_lu_dev;
640 if (ldt != NULL && d != NULL) {
643 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
645 ldt->ldt_ops->ldto_device_free(&env, d);
647 obd->obd_lu_dev = NULL;
650 if (!obd->obd_type->typ_dt_ops->o_cleanup)
653 rc = obd->obd_type->typ_dt_ops->o_cleanup(obd);
657 static inline void obd_cleanup_client_import(struct obd_device *obd)
661 /* If we set up but never connected, the client import will not
664 down_write(&obd->u.cli.cl_sem);
665 if (obd->u.cli.cl_import) {
666 struct obd_import *imp;
668 imp = obd->u.cli.cl_import;
669 CDEBUG(D_CONFIG, "%s: client import never connected\n",
671 ptlrpc_invalidate_import(imp);
672 client_destroy_import(imp);
673 obd->u.cli.cl_import = NULL;
675 up_write(&obd->u.cli.cl_sem);
680 static inline int obd_process_config(struct obd_device *obd, int datalen,
684 struct lu_device_type *ldt = obd->obd_type->typ_lu;
685 struct lu_device *d = obd->obd_lu_dev;
689 obd->obd_process_conf = 1;
690 if (ldt != NULL && d != NULL) {
693 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
695 rc = d->ld_ops->ldo_process_config(&env, d, data);
699 if (!obd->obd_type->typ_dt_ops->o_process_config) {
700 CERROR("%s: no %s operation\n",
701 obd->obd_name, __func__);
704 rc = obd->obd_type->typ_dt_ops->o_process_config(obd, datalen,
708 obd->obd_process_conf = 0;
713 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
720 rc = exp_check_ops(exp);
724 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
725 CERROR("%s: no %s operation\n",
726 (exp)->exp_obd->obd_name, __func__);
730 rc = exp->exp_obd->obd_type->typ_dt_ops->o_create(env, exp, obdo);
734 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
741 rc = exp_check_ops(exp);
745 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
746 CERROR("%s: no %s operation\n",
747 (exp)->exp_obd->obd_name, __func__);
751 rc = exp->exp_obd->obd_type->typ_dt_ops->o_destroy(env, exp, obdo);
755 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
761 rc = exp_check_ops(exp);
765 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
766 CERROR("%s: no %s operation\n",
767 (exp)->exp_obd->obd_name, __func__);
771 rc = exp->exp_obd->obd_type->typ_dt_ops->o_getattr(env, exp, oa);
776 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
782 rc = exp_check_ops(exp);
786 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
787 CERROR("%s: no %s operation\n",
788 (exp)->exp_obd->obd_name, __func__);
792 rc = exp->exp_obd->obd_type->typ_dt_ops->o_setattr(env, exp, oa);
797 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
800 struct obd_device *obd = imp->imp_obd;
805 OBD_CHECK_DEV_ACTIVE(obd);
806 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
807 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
811 rc = obd->obd_type->typ_dt_ops->o_add_conn(imp, uuid, priority);
815 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
817 struct obd_device *obd = imp->imp_obd;
822 OBD_CHECK_DEV_ACTIVE(obd);
823 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
824 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
828 rc = obd->obd_type->typ_dt_ops->o_del_conn(imp, uuid);
832 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
834 struct obd_uuid *uuid;
838 if (!exp->exp_obd->obd_type ||
839 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
842 uuid = exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid(exp);
846 /** Create a new /a exp on device /a obd for the uuid /a cluuid
847 * @param exp New export handle
848 * @param d Connect data, supported flags are set, flags also understood
849 * by obd are returned.
851 static inline int obd_connect(const struct lu_env *env,
852 struct obd_export **exp, struct obd_device *obd,
853 struct obd_uuid *cluuid,
854 struct obd_connect_data *data,
858 __u64 ocf = data ? data->ocd_connect_flags : 0;
862 OBD_CHECK_DEV_ACTIVE(obd);
863 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
864 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
868 rc = obd->obd_type->typ_dt_ops->o_connect(env, exp, obd, cluuid, data,
870 /* check that only subset is granted */
871 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
872 data->ocd_connect_flags));
876 static inline int obd_reconnect(const struct lu_env *env,
877 struct obd_export *exp,
878 struct obd_device *obd,
879 struct obd_uuid *cluuid,
880 struct obd_connect_data *d,
884 __u64 ocf = d ? d->ocd_connect_flags : 0;
888 OBD_CHECK_DEV_ACTIVE(obd);
889 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
892 rc = obd->obd_type->typ_dt_ops->o_reconnect(env, exp, obd, cluuid, d,
894 /* check that only subset is granted */
895 LASSERT(ergo(d != NULL,
896 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
900 static inline int obd_disconnect(struct obd_export *exp)
905 rc = exp_check_ops(exp);
909 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
910 CERROR("%s: no %s operation\n",
911 (exp)->exp_obd->obd_name, __func__);
915 rc = exp->exp_obd->obd_type->typ_dt_ops->o_disconnect(exp);
919 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
920 enum lu_cli_type type)
926 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
929 rc = obd->obd_type->typ_dt_ops->o_fid_init(obd, exp, type);
933 static inline int obd_fid_fini(struct obd_device *obd)
938 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
941 rc = obd->obd_type->typ_dt_ops->o_fid_fini(obd);
945 static inline int obd_fid_alloc(const struct lu_env *env,
946 struct obd_export *exp,
948 struct md_op_data *op_data)
953 rc = exp_check_ops(exp);
957 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
958 CERROR("%s: no %s operation\n",
959 (exp)->exp_obd->obd_name, __func__);
963 rc = exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc(env, exp, fid,
968 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
974 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
975 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
979 /* Check poolname validity */
980 if (!poolname || poolname[0] == '\0' || lov_pool_is_reserved(poolname))
983 rc = obd->obd_type->typ_dt_ops->o_pool_new(obd, poolname);
987 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
992 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
993 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
997 rc = obd->obd_type->typ_dt_ops->o_pool_del(obd, poolname);
1001 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1008 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1009 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1010 RETURN(-EOPNOTSUPP);
1013 rc = obd->obd_type->typ_dt_ops->o_pool_add(obd, poolname, ostname);
1017 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1023 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1024 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1025 RETURN(-EOPNOTSUPP);
1028 rc = obd->obd_type->typ_dt_ops->o_pool_rem(obd, poolname, ostname);
1032 static inline int obd_init_export(struct obd_export *exp)
1037 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1038 exp->exp_obd->obd_type->typ_dt_ops->o_init_export)
1039 rc = exp->exp_obd->obd_type->typ_dt_ops->o_init_export(exp);
1043 static inline int obd_destroy_export(struct obd_export *exp)
1046 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1047 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export)
1048 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export(exp);
1052 /* @max_age is the oldest time in seconds that we accept using a cached data.
1053 * If the cache is older than @max_age we will get a new value from the
1054 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1056 static inline int obd_statfs_async(struct obd_export *exp,
1057 struct obd_info *oinfo,
1059 struct ptlrpc_request_set *rqset)
1061 struct obd_device *obd;
1066 if (exp == NULL || exp->exp_obd == NULL)
1070 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1072 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1076 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1077 obd->obd_name, obd->obd_osfs_age, max_age);
1078 rc = obd->obd_type->typ_dt_ops->o_statfs_async(exp, oinfo, max_age,
1084 /* @max_age is the oldest time in seconds that we accept using a cached data.
1085 * If the cache is older than @max_age we will get a new value from the
1086 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1088 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1089 struct obd_statfs *osfs, time64_t max_age,
1092 struct obd_device *obd;
1096 if (unlikely(exp == NULL || exp->exp_obd == NULL))
1100 OBD_CHECK_DEV_ACTIVE(obd);
1102 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1103 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1104 RETURN(-EOPNOTSUPP);
1107 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1108 obd->obd_name, obd->obd_osfs_age, max_age);
1109 /* ignore cache if aggregated isn't expected */
1110 if (obd->obd_osfs_age < max_age ||
1111 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1112 !(flags & OBD_STATFS_SUM))) {
1113 /* the RPC will block anyway, so avoid sending many at once */
1114 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1115 (flags & OBD_STATFS_NESTED)
1116 ? SINGLE_DEPTH_NESTING : 0);
1119 if (obd->obd_osfs_age < max_age ||
1120 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1121 !(flags & OBD_STATFS_SUM))) {
1122 rc = obd->obd_type->typ_dt_ops->o_statfs(env, exp, osfs,
1126 mutex_unlock(&obd->obd_dev_mutex);
1127 GOTO(cached, rc = 0);
1131 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1132 obd->obd_name, &obd->obd_osfs,
1133 osfs->os_bavail, osfs->os_blocks,
1134 osfs->os_ffree, osfs->os_files);
1136 spin_lock(&obd->obd_osfs_lock);
1137 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1138 obd->obd_osfs_age = ktime_get_seconds();
1139 spin_unlock(&obd->obd_osfs_lock);
1141 mutex_unlock(&obd->obd_dev_mutex);
1145 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1146 obd->obd_name, &obd->obd_osfs,
1147 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1148 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1149 spin_lock(&obd->obd_osfs_lock);
1150 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1151 spin_unlock(&obd->obd_osfs_lock);
1156 static inline int obd_preprw(const struct lu_env *env, int cmd,
1157 struct obd_export *exp, struct obdo *oa,
1158 int objcount, struct obd_ioobj *obj,
1159 struct niobuf_remote *remote, int *pages,
1160 struct niobuf_local *local)
1166 rc = exp_check_ops(exp);
1170 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1171 CERROR("%s: no %s operation\n",
1172 (exp)->exp_obd->obd_name, __func__);
1176 rc = exp->exp_obd->obd_type->typ_dt_ops->o_preprw(env, cmd, exp,
1178 remote, pages, local);
1183 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1184 struct obd_export *exp, struct obdo *oa,
1185 int objcount, struct obd_ioobj *obj,
1186 struct niobuf_remote *rnb, int pages,
1187 struct niobuf_local *local, const int orig_rc,
1188 int nob, ktime_t kstart)
1194 rc = exp_check_ops(exp);
1198 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1199 CERROR("%s: no %s operation\n",
1200 (exp)->exp_obd->obd_name, __func__);
1204 rc = exp->exp_obd->obd_type->typ_dt_ops->o_commitrw(env, cmd, exp, oa,
1213 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1214 int len, void *karg, void __user *uarg)
1220 rc = exp_check_ops(exp);
1224 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1225 CERROR("%s: no %s operation\n",
1226 (exp)->exp_obd->obd_name, __func__);
1230 rc = exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol(cmd, exp,
1236 static inline void obd_import_event(struct obd_device *obd,
1237 struct obd_import *imp,
1238 enum obd_import_event event)
1242 CERROR("NULL device\n");
1247 if (obd->obd_set_up && obd->obd_type->typ_dt_ops->o_import_event)
1248 obd->obd_type->typ_dt_ops->o_import_event(obd, imp, event);
1253 static inline int obd_notify(struct obd_device *obd,
1254 struct obd_device *watched,
1255 enum obd_notify_event ev)
1261 rc = obd_check_dev(obd);
1265 if (!obd->obd_set_up) {
1266 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1270 if (!obd->obd_type->typ_dt_ops->o_notify) {
1271 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1275 rc = obd->obd_type->typ_dt_ops->o_notify(obd, watched, ev);
1280 static inline int obd_notify_observer(struct obd_device *observer,
1281 struct obd_device *observed,
1282 enum obd_notify_event ev)
1286 struct obd_notify_upcall *onu;
1288 if (WARN_ON_ONCE(!observer))
1291 if (observer->obd_observer)
1292 rc = obd_notify(observer->obd_observer, observed, ev);
1295 * Also, call non-obd listener, if any
1297 onu = &observer->obd_upcall;
1298 if (onu->onu_upcall != NULL)
1299 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1301 return rc ? rc : rc2;
1304 static inline int obd_quotactl(struct obd_export *exp,
1305 struct obd_quotactl *oqctl)
1311 rc = exp_check_ops(exp);
1315 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1316 CERROR("%s: no %s operation\n",
1317 (exp)->exp_obd->obd_name, __func__);
1321 rc = exp->exp_obd->obd_type->typ_dt_ops->o_quotactl(exp->exp_obd,
1326 static inline int obd_quota_iter(struct obd_export *exp,
1327 struct obd_quotactl *oqctl,
1328 struct list_head *list)
1333 oqctl->qc_iter_list = (__u64)list;
1334 rc = obd_quotactl(exp, oqctl);
1338 } while (oqctl->qc_iter_md_offset || oqctl->qc_iter_dt_offset);
1343 static inline int obd_health_check(const struct lu_env *env,
1344 struct obd_device *obd)
1346 /* returns: 0 on healthy
1347 * >0 on unhealthy + reason code/flag
1348 * however the only suppored reason == 1 right now
1349 * We'll need to define some better reasons
1350 * or flags in the future.
1357 /* NULL method is normal here */
1358 if (obd == NULL || !obd->obd_type) {
1359 CERROR("cleaned up obd\n");
1360 RETURN(-EOPNOTSUPP);
1362 if (!obd->obd_set_up || obd->obd_stopping)
1364 if (!obd->obd_type->typ_dt_ops->o_health_check)
1367 rc = obd->obd_type->typ_dt_ops->o_health_check(env, obd);
1371 static inline int obd_register_observer(struct obd_device *obd,
1372 struct obd_device *observer)
1378 rc = obd_check_dev(obd);
1382 down_write(&obd->obd_observer_link_sem);
1383 if (obd->obd_observer && observer) {
1384 up_write(&obd->obd_observer_link_sem);
1387 obd->obd_observer = observer;
1388 up_write(&obd->obd_observer_link_sem);
1392 /* metadata helpers */
1398 LPROC_MD_INTENT_LOCK,
1407 LPROC_MD_INTENT_GETATTR_ASYNC,
1408 LPROC_MD_REVALIDATE_LOCK,
1412 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1417 rc = exp_check_ops(exp);
1421 return exp->exp_obd->obd_type->typ_md_ops->m_get_root(exp, fileset,
1425 static inline int md_getattr(struct obd_export *exp,
1426 struct md_op_data *op_data,
1427 struct ptlrpc_request **request)
1431 rc = exp_check_ops(exp);
1435 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1438 return exp->exp_obd->obd_type->typ_md_ops->m_getattr(exp, op_data,
1442 static inline int md_null_inode(struct obd_export *exp,
1443 const struct lu_fid *fid)
1447 rc = exp_check_ops(exp);
1451 return exp->exp_obd->obd_type->typ_md_ops->m_null_inode(exp, fid);
1454 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1455 struct md_open_data *mod,
1456 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_close(exp, op_data, mod,
1471 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1472 const void *data, size_t datalen, umode_t mode,
1473 uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1474 __u64 rdev, struct ptlrpc_request **request)
1478 rc = exp_check_ops(exp);
1482 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1485 return exp->exp_obd->obd_type->typ_md_ops->m_create(exp, op_data, data,
1491 static inline int md_enqueue(struct obd_export *exp,
1492 struct ldlm_enqueue_info *einfo,
1493 const union ldlm_policy_data *policy,
1494 struct md_op_data *op_data,
1495 struct lustre_handle *lockh,
1496 __u64 extra_lock_flags)
1500 rc = exp_check_ops(exp);
1504 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1507 return exp->exp_obd->obd_type->typ_md_ops->m_enqueue(exp, einfo, policy,
1512 static inline int md_getattr_name(struct obd_export *exp,
1513 struct md_op_data *op_data,
1514 struct ptlrpc_request **request)
1518 rc = exp_check_ops(exp);
1522 return exp->exp_obd->obd_type->typ_md_ops->m_getattr_name(exp, op_data,
1526 static inline int md_intent_lock(struct obd_export *exp,
1527 struct md_op_data *op_data,
1528 struct lookup_intent *it,
1529 struct ptlrpc_request **reqp,
1530 ldlm_blocking_callback cb_blocking,
1531 __u64 extra_lock_flags)
1535 rc = exp_check_ops(exp);
1539 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1540 LPROC_MD_INTENT_LOCK);
1542 return exp->exp_obd->obd_type->typ_md_ops->m_intent_lock(exp, op_data,
1548 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
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_link(exp, op_data,
1564 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1565 const char *old_name, size_t oldlen,
1566 const char *new_name, size_t newlen,
1567 struct ptlrpc_request **request)
1571 rc = exp_check_ops(exp);
1575 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1578 return exp->exp_obd->obd_type->typ_md_ops->m_rename(exp, op_data,
1584 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1585 void *ea, size_t ealen,
1586 struct ptlrpc_request **request)
1590 rc = exp_check_ops(exp);
1594 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1597 return exp->exp_obd->obd_type->typ_md_ops->m_setattr(exp, op_data, ea,
1601 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1602 struct ptlrpc_request **request)
1606 rc = exp_check_ops(exp);
1610 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1613 return exp->exp_obd->obd_type->typ_md_ops->m_fsync(exp, fid, request);
1616 /* FLR: resync mirrored files. */
1617 static inline int md_file_resync(struct obd_export *exp,
1618 struct md_op_data *data)
1622 rc = exp_check_ops(exp);
1626 return exp->exp_obd->obd_type->typ_md_ops->m_file_resync(exp, data);
1629 static inline int md_read_page(struct obd_export *exp,
1630 struct md_op_data *op_data,
1631 struct md_readdir_info *mrinfo,
1632 __u64 hash_offset, struct page **ppage)
1636 rc = exp_check_ops(exp);
1640 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1641 LPROC_MD_READ_PAGE);
1643 return exp->exp_obd->obd_type->typ_md_ops->m_read_page(exp, op_data,
1649 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1650 struct ptlrpc_request **request)
1654 rc = exp_check_ops(exp);
1658 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1661 return exp->exp_obd->obd_type->typ_md_ops->m_unlink(exp, op_data,
1665 static inline int md_get_lustre_md(struct obd_export *exp,
1666 struct req_capsule *pill,
1667 struct obd_export *dt_exp,
1668 struct obd_export *md_exp,
1669 struct lustre_md *md)
1673 rc = exp_check_ops(exp);
1677 return exp->exp_obd->obd_type->typ_md_ops->m_get_lustre_md(exp, pill,
1682 static inline int md_put_lustre_md(struct obd_export *exp,
1683 struct lustre_md *md)
1687 rc = exp_check_ops(exp);
1691 return exp->exp_obd->obd_type->typ_md_ops->m_put_lustre_md(exp, md);
1694 static inline int md_merge_attr(struct obd_export *exp,
1695 const struct lmv_stripe_object *lso,
1696 struct cl_attr *attr,
1697 ldlm_blocking_callback cb)
1701 rc = exp_check_ops(exp);
1705 return exp->exp_obd->obd_type->typ_md_ops->m_merge_attr(exp, lso, attr,
1709 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1710 u64 obd_md_valid, const char *name,
1711 const void *value, size_t value_size,
1712 unsigned int xattr_flags, u32 suppgid,
1713 struct ptlrpc_request **req)
1717 rc = exp_check_ops(exp);
1721 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1724 return exp->exp_obd->obd_type->typ_md_ops->m_setxattr(exp, fid,
1733 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1734 u64 obd_md_valid, const char *name,
1735 size_t buf_size, struct ptlrpc_request **req)
1739 rc = exp_check_ops(exp);
1743 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1746 return exp->exp_obd->obd_type->typ_md_ops->m_getxattr(exp, fid,
1752 static inline int md_set_open_replay_data(struct obd_export *exp,
1753 struct obd_client_handle *och,
1754 struct lookup_intent *it)
1758 rc = exp_check_ops(exp);
1762 return exp->exp_obd->obd_type->typ_md_ops->m_set_open_replay_data(exp,
1767 static inline int md_clear_open_replay_data(struct obd_export *exp,
1768 struct obd_client_handle *och)
1772 rc = exp_check_ops(exp);
1776 return exp->exp_obd->obd_type->typ_md_ops->m_clear_open_replay_data(exp, och);
1779 static inline int md_set_lock_data(struct obd_export *exp,
1780 const struct lustre_handle *lockh,
1781 void *data, __u64 *bits)
1785 rc = exp_check_ops(exp);
1789 return exp->exp_obd->obd_type->typ_md_ops->m_set_lock_data(exp, lockh,
1795 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1796 union ldlm_policy_data *policy, enum ldlm_mode mode,
1797 enum ldlm_cancel_flags cancel_flags, void *opaque)
1801 rc = exp_check_ops(exp);
1805 return exp->exp_obd->obd_type->typ_md_ops->m_cancel_unused(exp,
1812 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1813 const struct lu_fid *fid,
1814 enum ldlm_type type,
1815 union ldlm_policy_data *policy,
1816 enum ldlm_mode mode,
1817 struct lustre_handle *lockh)
1821 rc = exp_check_ops(exp);
1825 return exp->exp_obd->obd_type->typ_md_ops->m_lock_match(exp, flags,
1831 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1836 rc = exp_check_ops(exp);
1840 return exp->exp_obd->obd_type->typ_md_ops->m_init_ea_size(exp, ea_size,
1844 static inline int md_intent_getattr_async(struct obd_export *exp,
1845 struct md_op_item *item)
1849 rc = exp_check_ops(exp);
1853 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1854 LPROC_MD_INTENT_GETATTR_ASYNC);
1856 return exp->exp_obd->obd_type->typ_md_ops->m_intent_getattr_async(exp,
1860 static inline int md_revalidate_lock(struct obd_export *exp,
1861 struct lookup_intent *it,
1862 struct lu_fid *fid, __u64 *bits)
1866 rc = exp_check_ops(exp);
1870 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1871 LPROC_MD_REVALIDATE_LOCK);
1873 return exp->exp_obd->obd_type->typ_md_ops->m_revalidate_lock(exp,
1878 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1879 const struct lmv_stripe_object *lso,
1880 const char *name, int namelen,
1885 rc = exp_check_ops(exp);
1889 return exp->exp_obd->obd_type->typ_md_ops->m_get_fid_from_lsm(exp,
1895 /* Unpack an MD struct from disk to in-memory format.
1896 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1898 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1899 * If *plsm == NULL then it will be allocated.
1901 static inline int md_stripe_object_create(struct obd_export *exp,
1902 struct lmv_stripe_object **lsop,
1903 const union lmv_mds_md *lmm,
1908 rc = exp_check_ops(exp);
1912 return exp->exp_obd->obd_type->typ_md_ops->m_stripe_object_create(exp,
1918 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1919 int *rcs, struct ptlrpc_request_set *set)
1923 rc = exp_check_ops(exp);
1927 return exp->exp_obd->obd_type->typ_md_ops->m_rmfid(exp, fa, rcs, set);
1930 static inline struct lu_batch *
1931 md_batch_create(struct obd_export *exp, enum lu_batch_flags flags,
1936 rc = exp_check_ops(exp);
1940 return exp->exp_obd->obd_type->typ_md_ops->m_batch_create(exp, flags,
1944 static inline int md_batch_stop(struct obd_export *exp, struct lu_batch *bh)
1948 rc = exp_check_ops(exp);
1952 return exp->exp_obd->obd_type->typ_md_ops->m_batch_stop(exp, bh);
1955 static inline int md_batch_flush(struct obd_export *exp, struct lu_batch *bh,
1960 rc = exp_check_ops(exp);
1964 return exp->exp_obd->obd_type->typ_md_ops->m_batch_flush(exp, bh, wait);
1967 static inline int md_batch_add(struct obd_export *exp, struct lu_batch *bh,
1968 struct md_op_item *item)
1972 rc = exp_check_ops(exp);
1976 return exp->exp_obd->obd_type->typ_md_ops->m_batch_add(exp, bh, item);
1979 /* OBD Metadata Support */
1981 extern int obd_init_caches(void);
1982 extern void obd_cleanup_caches(void);
1984 typedef int (*register_lwp_cb)(void *data);
1986 struct lwp_register_item {
1987 struct obd_export **lri_exp;
1988 register_lwp_cb lri_cb_func;
1990 struct list_head lri_list;
1992 char lri_name[MTI_NAME_MAXLEN];
1996 #ifdef HAVE_SERVER_SUPPORT
1997 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1998 register_lwp_cb cb_func, void *cb_data);
1999 void lustre_deregister_lwp_item(struct obd_export **exp);
2000 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
2001 void lustre_notify_lwp_list(struct obd_export *exp);
2002 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
2003 #endif /* HAVE_SERVER_SUPPORT */
2004 int lustre_check_exclusion(struct super_block *sb, char *svname);
2007 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
2009 int class_add_uuid(const char *uuid, struct lnet_nid *nid);
2010 int class_del_uuid (const char *uuid);
2011 int class_add_nids_to_uuid(struct obd_uuid *uuid, struct lnet_nid *nidlist,
2012 int nid_count, int nid_size);
2013 int class_check_uuid(struct obd_uuid *uuid, struct lnet_nid *nid);
2016 extern char obd_jobid_name[];
2018 extern unsigned int obd_lbug_on_eviction;
2019 extern unsigned int obd_dump_on_eviction;
2021 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
2023 if (obd_lbug_on_eviction &&
2024 strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
2025 strlen(LUSTRE_MGC_NAME))) {
2026 CERROR("LBUG upon eviction\n");
2030 return obd_dump_on_eviction;
2035 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
2036 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
2038 /* root squash info */
2039 struct root_squash_info {
2042 struct list_head rsi_nosquash_nids;
2043 spinlock_t rsi_lock;
2046 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
2048 /* linux-module.c */
2049 struct obd_ioctl_data;
2050 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
2051 int class_procfs_init(void);
2052 int class_procfs_clean(void);
2054 extern void obd_heat_add(struct obd_heat_instance *instance,
2055 unsigned int time_second, __u64 count,
2056 unsigned int weight, unsigned int period_second);
2057 extern void obd_heat_decay(struct obd_heat_instance *instance,
2058 __u64 time_second, unsigned int weight,
2059 unsigned int period_second);
2060 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
2061 unsigned int time_second, unsigned int weight,
2062 unsigned int period_second);
2063 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
2065 /* struct kobj_type */
2067 struct attribute *_get_attr_matches(const struct kobj_type *typ,
2068 const char *key, size_t keylen,
2069 int (*is_match)(const char *, const char *,
2074 #ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
2075 for (i = 0; typ->default_groups[i]; i++) {
2077 struct attribute **attrs;
2079 attrs = (struct attribute **)typ->default_groups[i]->attrs;
2080 for (k = 0; attrs[k]; k++) {
2081 if (is_match(attrs[k]->name, key, keylen))
2082 return (struct attribute *)attrs[k];
2086 for (i = 0; typ->default_attrs[i]; i++) {
2087 if (is_match(typ->default_attrs[i]->name, key, keylen))
2088 return typ->default_attrs[i];
2095 int _attr_name_exact(const char *attr_name, const char *key, size_t len)
2097 return !strcmp(attr_name, key);
2101 struct attribute *get_attr_by_name(const struct kobj_type *typ,
2104 return _get_attr_matches(typ, name, 0, _attr_name_exact);
2108 int _attr_name_starts_with(const char *attr_name, const char *name, size_t len)
2110 return !strncmp(attr_name, name, len);
2114 struct attribute *get_attr_starts_with(const struct kobj_type *typ,
2118 return _get_attr_matches(typ, name, len, _attr_name_starts_with);
2121 int obd_ioctl_msg(const char *file, const char *func, int line, int level,
2122 const char *name, unsigned int cmd, const char *msg, int rc);
2123 #define OBD_IOC_DEBUG(level, dev, cmd, msg, rc) \
2124 obd_ioctl_msg(__FILE__, __func__, __LINE__, level, dev, cmd, msg, rc)
2125 #define OBD_IOC_ERROR(dev, cmd, msg, rc) \
2126 obd_ioctl_msg(__FILE__, __func__, __LINE__, D_ERROR, dev, cmd, msg, rc)
2128 #endif /* __LINUX_OBD_CLASS_H */