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 * Header defining common operations on OBD devices.
19 #include <linux/kobject.h>
20 #include <obd_support.h>
21 #include <lustre_import.h>
22 #include <lustre_net.h>
24 #include <lustre_lib.h>
25 #include <uapi/linux/lustre/lustre_idl.h>
26 #include <lprocfs_status.h>
27 #ifdef HAVE_SERVER_SUPPORT
28 #include <lu_target.h>
29 #include <obd_target.h>
30 #include <dt_object.h>
33 #ifdef HAVE_SERVER_SUPPORT
34 #define SERVER_ONLY_EXPORT_SYMBOL(symbol) EXPORT_SYMBOL(symbol)
37 #define SERVER_ONLY static
38 #define SERVER_ONLY_EXPORT_SYMBOL(symbol)
41 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
42 * and resends for avoid deadlocks */
43 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
45 #define OBD_STATFS_FOR_MDT0 0x0004 /* The statfs is only for retrieving
46 * information from MDT0. */
47 #define OBD_STATFS_SUM 0x0008 /* get aggregated statfs from MDT */
48 #define OBD_STATFS_NESTED 0x0010 /* Call while already holding
49 * obd_dev_mutex of a difference
53 #define OBD_MAX_INDEX xa_limit_31b.max
55 #define obd_device_find(devno) \
56 xa_find(&obd_devs, &devno, OBD_MAX_INDEX, XA_PRESENT)
58 #define obd_device_find_after(devno) \
59 xa_find_after(&obd_devs, &devno, OBD_MAX_INDEX, XA_PRESENT)
61 #define obd_device_for_each(devno, obd) \
62 xa_for_each(&obd_devs, devno, obd)
64 #define obd_device_for_each_start(devno, obd, start) \
65 xa_for_each_start(&obd_devs, devno, obd, start)
67 #define obd_device_for_each_cond(devno, obd, cond) \
68 obd_device_for_each(devno, obd) \
71 #define obd_device_for_each_uuid(devno, obd, uuid) \
72 obd_device_for_each_cond(devno, obd, \
73 obd_uuid_equals(uuid, &obd->obd_uuid))
75 #define obd_device_lock() xa_lock(&obd_devs)
76 #define obd_device_unlock() xa_unlock(&obd_devs)
78 /* OBD Operations Declarations */
79 extern struct obd_device *class_exp2obd(struct obd_export *);
80 extern int class_handle_ioctl(unsigned int cmd, void __user *uarg);
81 int lustre_get_jobid(char *jobid, size_t len);
82 void lustre_jobid_clear(const char *jobid);
83 void jobid_cache_fini(void);
84 int jobid_cache_init(void);
85 char *jobid_current(void);
86 int jobid_set_current(char *jobid);
88 struct lu_device_type;
91 extern struct xarray obd_devs;
92 struct obd_export *class_conn2export(struct lustre_handle *);
93 #ifdef HAVE_SERVER_SUPPORT
94 struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
96 int class_register_type(const struct obd_ops *dt_ops,
97 const struct md_ops *md_ops, bool enable_proc,
98 const char *nm, struct lu_device_type *ldt);
99 int class_unregister_type(const char *nm);
101 struct obd_device *class_newdev(const char *type_name, const char *name,
103 int class_register_device(struct obd_device *obd);
104 void class_unregister_device(struct obd_device *obd);
105 void class_free_dev(struct obd_device *obd);
107 struct obd_device *class_str2obd(const char *str);
108 int class_name2dev(const char *name);
109 struct obd_device *class_name2obd(const char *name);
110 int class_uuid2dev(struct obd_uuid *uuid);
111 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
112 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
113 const char *type_name,
114 struct obd_uuid *grp_uuid);
115 struct obd_device *class_num2obd(int num);
116 int class_obd_devs_count(void);
118 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
120 static inline char *obd_export_nid2str(struct obd_export *exp)
122 return exp->exp_connection == NULL ?
123 "<unknown>" : libcfs_nidstr(&exp->exp_connection->c_peer.nid);
126 static inline char *obd_import_nid2str(struct obd_import *imp)
128 return imp->imp_connection == NULL ?
129 "<unknown>" : libcfs_nidstr(&imp->imp_connection->c_peer.nid);
132 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
133 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
134 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
137 int obd_zombie_impexp_init(void);
138 void obd_zombie_impexp_stop(void);
139 void obd_zombie_impexp_cull(void);
140 void obd_zombie_barrier(void);
141 void obd_exports_barrier(struct obd_device *obd);
142 int kuc_len(int payload_len);
143 struct kuc_hdr * kuc_ptr(void *p);
144 void *kuc_alloc(int payload_len, int transport, int type);
145 void kuc_free(void *p, int payload_len);
146 int obd_get_request_slot(struct client_obd *cli);
147 void obd_put_request_slot(struct client_obd *cli);
148 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
149 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
150 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
151 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
152 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
155 int obd_pool_init(void);
156 void obd_pool_fini(void);
157 void obd_pool_add_user(void);
158 int obd_pool_get_desc_pages(struct ptlrpc_bulk_desc *desc);
159 int obd_pool_get_pages_array(struct page **pa, unsigned int count);
160 int obd_pool_get_objects(void **buf, unsigned int order);
161 void obd_pool_put_desc_pages(struct ptlrpc_bulk_desc *desc);
162 void obd_pool_put_pages_array(struct page **pa, unsigned int count);
163 void obd_pool_put_objects(void *buf, unsigned int order);
164 int obd_pool_get_free_objects(unsigned int order);
165 int pool_is_at_full_capacity(int order);
168 int cfs_hash_init(void);
169 void cfs_hash_fini(void);
171 int encrypt_page_pools_seq_show(struct seq_file *m, void *v);
172 int page_pools_seq_show(struct seq_file *m, void *v);
174 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
175 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
179 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
180 struct llog_rec_hdr *, void *);
182 struct obd_export *obd_stale_export_get(void);
183 void obd_stale_export_put(struct obd_export *exp);
184 void obd_stale_export_adjust(struct obd_export *exp);
187 /* For interoperability */
188 struct cfg_interop_param {
193 #ifdef HAVE_SERVER_SUPPORT
194 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg));
197 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
198 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
199 const char *new_name);
200 void print_lustre_cfg(struct lustre_cfg *lcfg);
201 int class_process_config(struct lustre_cfg *lcfg, struct kobject *kobj);
202 ssize_t class_set_global(const char *param);
203 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
204 struct kobject *kobj);
205 int class_attach(struct lustre_cfg *lcfg);
206 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
207 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
208 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
210 int class_find_param(char *buf, char *key, char **valp);
211 struct cfg_interop_param *class_find_old_param(const char *param,
212 struct cfg_interop_param *ptr);
213 int class_get_next_param(char **params, char *copy);
214 int class_match_param(char *buf, const char *key, char **valp);
215 int class_parse_nid(char *buf, struct lnet_nid *nid, char **endh);
216 int class_parse_nid_quiet(char *buf, struct lnet_nid *nid, char **endh);
217 int class_parse_net(char *buf, u32 *net, char **endh);
218 int class_match_nid(char *buf, char *key, struct lnet_nid *nid);
219 int class_match_net(char *buf, char *key, u32 net);
221 struct obd_device *class_incref(struct obd_device *obd,
222 const char *scope, const void *source);
223 void class_decref(struct obd_device *obd,
224 const char *scope, const void *source);
225 void dump_exports(struct obd_device *obd, int locks, int debug_level);
226 int class_config_llog_handler(const struct lu_env *env,
227 struct llog_handle *handle,
228 struct llog_rec_hdr *rec, void *data);
229 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
231 #define CFG_F_START 0x01 /* Set when we start updating from a log */
232 #define CFG_F_MARKER 0x02 /* We are within a maker */
233 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
234 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
236 /* Passed as data param to class_config_parse_llog */
237 struct config_llog_instance {
238 unsigned long cfg_instance;
239 struct kobject *cfg_kobj;
240 struct super_block *cfg_sb;
241 struct obd_uuid cfg_uuid;
242 llog_cb_t cfg_callback;
243 int cfg_last_idx; /* for partial llog processing */
248 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
249 char *name, struct config_llog_instance *cfg);
252 * Generate a unique configuration instance for this mount
254 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
255 * For now, use the same value as before - the superblock pointer value.
257 * Using the client UUID would be an option, but it needs more testing.
259 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
261 return (unsigned long)sb;
264 #define CONFIG_SUB_SPTLRPC 0x01
265 #define CONFIG_SUB_RECOVER 0x02
266 #define CONFIG_SUB_PARAMS 0x04
267 #define CONFIG_SUB_NODEMAP 0x08
268 #define CONFIG_SUB_BARRIER 0x10
270 /* Sub clds should be attached to the config_llog_data when processing
271 * config log for client or server target. */
272 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
274 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
277 #define PARAMS_FILENAME "params"
278 #define BARRIER_FILENAME "barrier"
279 #define LCTL_UPCALL "lctl"
281 static inline bool logname_is_barrier(const char *logname)
285 /* logname for barrier is "fsname-barrier" */
286 ptr = strstr(logname, BARRIER_FILENAME);
287 if (ptr && (ptr - logname) >= 2 &&
288 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
294 /* list of active configuration logs */
295 struct config_llog_data {
296 struct ldlm_res_id cld_resid;
297 struct lustre_handle cld_lockh;
298 struct config_llog_instance cld_cfg;
299 struct list_head cld_list_chain;/* on config_llog_list */
300 refcount_t cld_refcount;
301 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
302 struct config_llog_data *cld_params; /* common parameters log */
303 struct config_llog_data *cld_recover;/* imperative recover log */
304 struct config_llog_data *cld_nodemap;/* nodemap log */
305 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
306 struct obd_export *cld_mgcexp;
307 struct mutex cld_lock;
308 enum mgs_cfg_type cld_type;
309 unsigned int cld_stopping:1, /* we were told to stop
311 cld_lostlock:1, /* lock not requeued */
312 cld_processed:1; /* successfully fetched */
316 struct lustre_profile {
317 struct list_head lp_list;
322 bool lp_list_deleted;
325 struct lustre_profile *class_get_profile(const char * prof);
326 void class_del_profile(const char *prof);
327 void class_put_profile(struct lustre_profile *lprof);
328 void class_del_profiles(void);
331 #if LUSTRE_TRACKS_LOCK_EXP_REFS
333 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
334 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
335 extern void (*class_export_dump_hook)(struct obd_export *);
339 #define __class_export_add_lock_ref(exp, lock) do {} while (0)
340 #define __class_export_del_lock_ref(exp, lock) do {} while (0)
344 #define class_export_rpc_inc(exp) \
346 atomic_inc(&(exp)->exp_rpc_count); \
347 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
348 (exp), atomic_read(&(exp)->exp_rpc_count)); \
351 #define class_export_rpc_dec(exp) \
353 LASSERT(atomic_read(&(exp)->exp_rpc_count) > 0); \
354 atomic_dec(&(exp)->exp_rpc_count); \
355 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
356 (exp), atomic_read(&(exp)->exp_rpc_count)); \
359 #define class_export_lock_get(exp, lock) \
361 atomic_inc(&(exp)->exp_locks_count); \
362 __class_export_add_lock_ref(exp, lock); \
363 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
364 (exp), atomic_read(&(exp)->exp_locks_count)); \
365 class_export_get(exp); \
368 #define class_export_lock_put(exp, lock) \
370 LASSERT(atomic_read(&(exp)->exp_locks_count) > 0); \
371 atomic_dec(&(exp)->exp_locks_count); \
372 __class_export_del_lock_ref(exp, lock); \
373 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
374 (exp), atomic_read(&(exp)->exp_locks_count)); \
375 class_export_put(exp); \
378 #define class_export_cb_get(exp) \
380 atomic_inc(&(exp)->exp_cb_count); \
381 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
382 (exp), atomic_read(&(exp)->exp_cb_count)); \
383 class_export_get(exp); \
386 #define class_export_cb_put(exp) \
388 LASSERT(atomic_read(&(exp)->exp_cb_count) > 0); \
389 atomic_dec(&(exp)->exp_cb_count); \
390 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
391 (exp), atomic_read(&(exp)->exp_cb_count)); \
392 class_export_put(exp); \
396 struct obd_export *class_export_get(struct obd_export *exp);
397 void class_export_put(struct obd_export *exp);
398 struct obd_export *class_new_export(struct obd_device *obd,
399 struct obd_uuid *cluuid);
400 struct obd_export *class_new_export_self(struct obd_device *obd,
401 struct obd_uuid *uuid);
402 void class_unlink_export(struct obd_export *exp);
404 struct obd_import *class_import_get(struct obd_import *);
405 void class_import_put(struct obd_import *);
406 struct obd_import *class_new_import(struct obd_device *obd);
407 void class_destroy_import(struct obd_import *exp);
409 int obd_export_timed_init(struct obd_export *exp, void **data);
410 void obd_export_timed_fini(struct obd_export *exp, void **data);
411 void obd_export_timed_add(struct obd_export *exp, void **data);
412 void obd_export_timed_del(struct obd_export *exp);
413 struct obd_export *obd_export_timed_get(struct obd_device *obd, bool last);
415 #ifdef HAVE_SERVER_SUPPORT
416 struct obd_type *class_search_type(const char *name);
417 struct obd_type *class_get_type(const char *name);
419 void class_put_type(struct obd_type *type);
420 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
421 struct obd_uuid *cluuid);
422 int class_disconnect(struct obd_export *exp);
423 void class_fail_export(struct obd_export *exp);
424 int class_connected_export(struct obd_export *exp);
425 void class_disconnect_exports(struct obd_device *obd);
426 int class_manual_cleanup(struct obd_device *obd);
427 void class_disconnect_stale_exports(struct obd_device *,
428 int (*test_export)(struct obd_export *));
430 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
432 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
433 (obd->obd_force ? OBD_OPT_FORCE : 0) |
434 (test_bit(OBDF_ABORT_RECOVERY, obd->obd_flags) ? OBD_OPT_ABORT_RECOV : 0) |
438 #ifdef HAVE_SERVER_SUPPORT
439 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
441 struct obd_device_target *obt;
443 LASSERT(exp->exp_obd);
444 obt = (void *)&exp->exp_obd->u;
445 if (obt->obt_magic != OBT_MAGIC)
450 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
452 struct obd_device_target *obt = obd2obt(obd);
455 return &obt->obt_lut->lut_lsd;
463 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
464 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
466 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
467 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
469 static inline int obd_check_dev(struct obd_device *obd)
472 CERROR("NULL device\n");
476 if (!test_bit(OBDF_SET_UP, (obd)->obd_flags) ||
477 (obd)->obd_stopping) {
478 CERROR("Device %d not setup\n",
486 static inline int exp_check_ops(struct obd_export *exp)
491 if (!exp->exp_obd || !exp->exp_obd->obd_type)
497 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
498 __u32 keylen, void *key,
499 __u32 *vallen, void *val)
505 rc = exp_check_ops(exp);
509 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
510 CERROR("%s: no %s operation\n",
511 (exp)->exp_obd->obd_name, __func__);
515 rc = exp->exp_obd->obd_type->typ_dt_ops->o_get_info(env, exp, keylen,
520 static inline int obd_set_info_async(const struct lu_env *env,
521 struct obd_export *exp,
522 __u32 keylen, void *key,
523 __u32 vallen, void *val,
524 struct ptlrpc_request_set *set)
530 rc = exp_check_ops(exp);
534 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
535 CERROR("%s: no %s operation\n",
536 (exp)->exp_obd->obd_name, __func__);
540 rc = exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async(env, exp,
549 * obd-lu integration.
551 * Functionality is being moved into new lu_device-based layering, but some
552 * pieces of configuration process are still based on obd devices.
554 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
555 * subsume ->o_setup() methods of obd devices they replace. The same for
556 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
557 * result, obd_setup() and obd_process_config() branch and call one XOR
560 * Yet neither lu_device_type_operations::ldto_device_fini() nor
561 * lu_device_type_operations::ldto_device_free() fully implement the
562 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
563 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
565 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
568 struct obd_type *type = obd->obd_type;
569 struct lu_device_type *ldt;
573 wait_var_event(&type->typ_lu,
574 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
577 struct lu_context session_ctx;
578 struct lu_device *dev;
581 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
582 session_ctx.lc_thread = NULL;
583 lu_context_enter(&session_ctx);
585 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
587 env.le_ses = &session_ctx;
588 dev = ldto_device_alloc(&env, ldt, cfg);
590 obd->obd_lu_dev = dev;
593 #ifdef HAVE_SERVER_SUPPORT
594 if (lu_device_is_dt(dev) &&
595 lu2dt_dev(dev)->dd_rdonly)
596 obd->obd_read_only = 1;
598 rc = ldto_device_init(&env, dev, ldt->ldt_name, NULL);
604 lu_context_exit(&session_ctx);
605 lu_context_fini(&session_ctx);
607 if (!obd->obd_type->typ_dt_ops->o_setup) {
608 CERROR("%s: no %s operation\n", obd->obd_name,
612 rc = obd->obd_type->typ_dt_ops->o_setup(obd, cfg);
617 static inline int obd_precleanup(struct obd_device *obd)
619 struct lu_device_type *ldt = obd->obd_type->typ_lu;
620 struct lu_device *d = obd->obd_lu_dev;
625 if (ldt != NULL && d != NULL) {
626 struct lu_env *env = lu_env_find();
629 if (!env && lu_env_init(&_env, ldt->ldt_ctx_tags) == 0) {
631 rc = lu_env_add(env);
633 ldto_device_fini(env, d);
641 if (!obd->obd_type->typ_dt_ops->o_precleanup)
644 rc = obd->obd_type->typ_dt_ops->o_precleanup(obd);
648 static inline int obd_cleanup(struct obd_device *obd)
651 struct lu_device_type *ldt = obd->obd_type->typ_lu;
652 struct lu_device *d = obd->obd_lu_dev;
655 if (ldt != NULL && d != NULL) {
658 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
660 ldto_device_free(&env, d);
662 obd->obd_lu_dev = NULL;
665 if (!obd->obd_type->typ_dt_ops->o_cleanup)
668 rc = obd->obd_type->typ_dt_ops->o_cleanup(obd);
672 static inline void obd_cleanup_client_import(struct obd_device *obd)
676 /* If we set up but never connected, the client import will not
679 down_write(&obd->u.cli.cl_sem);
680 if (obd->u.cli.cl_import) {
681 struct obd_import *imp;
683 imp = obd->u.cli.cl_import;
684 CDEBUG(D_CONFIG, "%s: client import never connected\n",
686 ptlrpc_invalidate_import(imp);
687 client_destroy_import(imp);
688 obd->u.cli.cl_import = NULL;
690 up_write(&obd->u.cli.cl_sem);
695 static inline int obd_process_config(struct obd_device *obd, int datalen,
699 struct lu_device_type *ldt = obd->obd_type->typ_lu;
700 struct lu_device *d = obd->obd_lu_dev;
704 obd->obd_process_conf = 1;
705 if (ldt != NULL && d != NULL) {
708 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
710 rc = d->ld_ops->ldo_process_config(&env, d, data);
714 if (!obd->obd_type->typ_dt_ops->o_process_config) {
715 CERROR("%s: no %s operation\n",
716 obd->obd_name, __func__);
719 rc = obd->obd_type->typ_dt_ops->o_process_config(obd, datalen,
723 obd->obd_process_conf = 0;
728 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
735 rc = exp_check_ops(exp);
739 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
740 CERROR("%s: no %s operation\n",
741 (exp)->exp_obd->obd_name, __func__);
745 rc = exp->exp_obd->obd_type->typ_dt_ops->o_create(env, exp, obdo);
749 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
756 rc = exp_check_ops(exp);
760 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
761 CERROR("%s: no %s operation\n",
762 (exp)->exp_obd->obd_name, __func__);
766 rc = exp->exp_obd->obd_type->typ_dt_ops->o_destroy(env, exp, obdo);
770 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
776 rc = exp_check_ops(exp);
780 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
781 CERROR("%s: no %s operation\n",
782 (exp)->exp_obd->obd_name, __func__);
786 rc = exp->exp_obd->obd_type->typ_dt_ops->o_getattr(env, exp, oa);
791 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
797 rc = exp_check_ops(exp);
801 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
802 CERROR("%s: no %s operation\n",
803 (exp)->exp_obd->obd_name, __func__);
807 rc = exp->exp_obd->obd_type->typ_dt_ops->o_setattr(env, exp, oa);
812 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
815 struct obd_device *obd = imp->imp_obd;
820 rc = obd_check_dev(obd);
824 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
825 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
829 rc = obd->obd_type->typ_dt_ops->o_add_conn(imp, uuid, priority);
833 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
835 struct obd_device *obd = imp->imp_obd;
840 rc = obd_check_dev(obd);
844 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
845 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
849 rc = obd->obd_type->typ_dt_ops->o_del_conn(imp, uuid);
853 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
855 struct obd_uuid *uuid;
859 if (!exp->exp_obd->obd_type ||
860 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
863 uuid = exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid(exp);
867 /** Create a new /a exp on device /a obd for the uuid /a cluuid
868 * @param exp New export handle
869 * @param d Connect data, supported flags are set, flags also understood
870 * by obd are returned.
872 static inline int obd_connect(const struct lu_env *env,
873 struct obd_export **exp, struct obd_device *obd,
874 struct obd_uuid *cluuid,
875 struct obd_connect_data *data,
879 __u64 ocf = data ? data->ocd_connect_flags : 0;
883 rc = obd_check_dev(obd);
887 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
888 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
892 rc = obd->obd_type->typ_dt_ops->o_connect(env, exp, obd, cluuid, data,
894 /* check that only subset is granted */
895 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
896 data->ocd_connect_flags));
900 static inline int obd_reconnect(const struct lu_env *env,
901 struct obd_export *exp,
902 struct obd_device *obd,
903 struct obd_uuid *cluuid,
904 struct obd_connect_data *d,
908 __u64 ocf = d ? d->ocd_connect_flags : 0;
912 rc = obd_check_dev(obd);
916 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
919 rc = obd->obd_type->typ_dt_ops->o_reconnect(env, exp, obd, cluuid, d,
921 /* check that only subset is granted */
922 LASSERT(ergo(d != NULL,
923 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
927 static inline int obd_disconnect(struct obd_export *exp)
932 rc = exp_check_ops(exp);
936 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
937 CERROR("%s: no %s operation\n",
938 (exp)->exp_obd->obd_name, __func__);
942 rc = exp->exp_obd->obd_type->typ_dt_ops->o_disconnect(exp);
946 static inline int obd_fid_alloc(const struct lu_env *env,
947 struct obd_export *exp,
949 struct md_op_data *op_data)
954 rc = exp_check_ops(exp);
958 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
959 CERROR("%s: no %s operation\n",
960 (exp)->exp_obd->obd_name, __func__);
964 rc = exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc(env, exp, fid,
969 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
975 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
976 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
980 /* Check poolname validity */
981 if (!poolname || poolname[0] == '\0' || lov_pool_is_reserved(poolname))
984 rc = obd->obd_type->typ_dt_ops->o_pool_new(obd, poolname);
988 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
993 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
994 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
998 rc = obd->obd_type->typ_dt_ops->o_pool_del(obd, poolname);
1002 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1009 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1010 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1011 RETURN(-EOPNOTSUPP);
1014 rc = obd->obd_type->typ_dt_ops->o_pool_add(obd, poolname, ostname);
1018 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1024 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1025 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1026 RETURN(-EOPNOTSUPP);
1029 rc = obd->obd_type->typ_dt_ops->o_pool_rem(obd, poolname, ostname);
1033 static inline int obd_init_export(struct obd_export *exp)
1038 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1039 exp->exp_obd->obd_type->typ_dt_ops->o_init_export)
1040 rc = exp->exp_obd->obd_type->typ_dt_ops->o_init_export(exp);
1044 static inline int obd_destroy_export(struct obd_export *exp)
1047 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1048 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export)
1049 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export(exp);
1053 /* @max_age is the oldest time in seconds that we accept using a cached data.
1054 * If the cache is older than @max_age we will get a new value from the
1055 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1057 static inline int obd_statfs_async(struct obd_export *exp,
1058 struct obd_info *oinfo,
1060 struct ptlrpc_request_set *rqset)
1062 struct obd_device *obd;
1067 if (exp == NULL || exp->exp_obd == NULL)
1071 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1073 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1077 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1078 obd->obd_name, obd->obd_osfs_age, max_age);
1079 rc = obd->obd_type->typ_dt_ops->o_statfs_async(exp, oinfo, max_age,
1085 /* @max_age is the oldest time in seconds that we accept using a cached data.
1086 * If the cache is older than @max_age we will get a new value from the
1087 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1089 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1090 struct obd_statfs *osfs, time64_t max_age,
1093 struct obd_device *obd;
1097 if (unlikely(exp == NULL || exp->exp_obd == NULL))
1102 rc = obd_check_dev(obd);
1106 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1107 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1108 RETURN(-EOPNOTSUPP);
1111 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1112 obd->obd_name, obd->obd_osfs_age, max_age);
1113 /* ignore cache if aggregated isn't expected */
1114 if (obd->obd_osfs_age < max_age ||
1115 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1116 !(flags & OBD_STATFS_SUM))) {
1117 /* the RPC will block anyway, so avoid sending many at once */
1118 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1119 (flags & OBD_STATFS_NESTED)
1120 ? SINGLE_DEPTH_NESTING : 0);
1123 if (obd->obd_osfs_age < max_age ||
1124 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1125 !(flags & OBD_STATFS_SUM))) {
1126 rc = obd->obd_type->typ_dt_ops->o_statfs(env, exp, osfs,
1130 mutex_unlock(&obd->obd_dev_mutex);
1131 GOTO(cached, rc = 0);
1135 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1136 obd->obd_name, &obd->obd_osfs,
1137 osfs->os_bavail, osfs->os_blocks,
1138 osfs->os_ffree, osfs->os_files);
1140 spin_lock(&obd->obd_osfs_lock);
1141 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1142 obd->obd_osfs_age = ktime_get_seconds();
1143 spin_unlock(&obd->obd_osfs_lock);
1145 mutex_unlock(&obd->obd_dev_mutex);
1149 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1150 obd->obd_name, &obd->obd_osfs,
1151 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1152 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1153 spin_lock(&obd->obd_osfs_lock);
1154 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1155 spin_unlock(&obd->obd_osfs_lock);
1160 static inline int obd_preprw(const struct lu_env *env, int cmd,
1161 struct obd_export *exp, struct obdo *oa,
1162 int objcount, struct obd_ioobj *obj,
1163 struct niobuf_remote *remote, int *pages,
1164 struct niobuf_local *local)
1170 rc = exp_check_ops(exp);
1174 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1175 CERROR("%s: no %s operation\n",
1176 (exp)->exp_obd->obd_name, __func__);
1180 rc = exp->exp_obd->obd_type->typ_dt_ops->o_preprw(env, cmd, exp,
1182 remote, pages, local);
1187 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1188 struct obd_export *exp, struct obdo *oa,
1189 int objcount, struct obd_ioobj *obj,
1190 struct niobuf_remote *rnb, int pages,
1191 struct niobuf_local *local, const int orig_rc,
1192 int nob, ktime_t kstart)
1198 rc = exp_check_ops(exp);
1202 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1203 CERROR("%s: no %s operation\n",
1204 (exp)->exp_obd->obd_name, __func__);
1208 rc = exp->exp_obd->obd_type->typ_dt_ops->o_commitrw(env, cmd, exp, oa,
1217 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1218 int len, void *karg, void __user *uarg)
1224 rc = exp_check_ops(exp);
1228 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1229 CERROR("%s: no %s operation\n",
1230 (exp)->exp_obd->obd_name, __func__);
1234 rc = exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol(cmd, exp,
1240 static inline void obd_import_event(struct obd_device *obd,
1241 struct obd_import *imp,
1242 enum obd_import_event event)
1248 rc = obd_check_dev(obd);
1252 if (obd->obd_type->typ_dt_ops->o_import_event)
1253 obd->obd_type->typ_dt_ops->o_import_event(obd, imp, event);
1258 static inline int obd_notify(struct obd_device *obd,
1259 struct obd_device *watched,
1260 enum obd_notify_event ev)
1266 rc = obd_check_dev(obd);
1270 if (!obd->obd_type->typ_dt_ops->o_notify) {
1271 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1272 RETURN(-EOPNOTSUPP);
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 = (uintptr_t)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 (!test_bit(OBDF_SET_UP, obd->obd_flags) || 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 */
1397 LPROC_MD_ENQUEUE_ASYNC,
1399 LPROC_MD_INTENT_LOCK,
1408 LPROC_MD_INTENT_GETATTR_ASYNC,
1409 LPROC_MD_REVALIDATE_LOCK,
1413 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1418 rc = exp_check_ops(exp);
1422 return exp->exp_obd->obd_type->typ_md_ops->m_get_root(exp, fileset,
1426 static inline int md_getattr(struct obd_export *exp,
1427 struct md_op_data *op_data,
1428 struct ptlrpc_request **request)
1432 rc = exp_check_ops(exp);
1436 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1439 return exp->exp_obd->obd_type->typ_md_ops->m_getattr(exp, op_data,
1443 static inline int md_null_inode(struct obd_export *exp,
1444 const struct lu_fid *fid)
1448 rc = exp_check_ops(exp);
1452 return exp->exp_obd->obd_type->typ_md_ops->m_null_inode(exp, fid);
1455 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1456 struct md_open_data *mod,
1457 struct ptlrpc_request **request)
1461 rc = exp_check_ops(exp);
1465 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1468 return exp->exp_obd->obd_type->typ_md_ops->m_close(exp, op_data, mod,
1472 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1473 const void *data, size_t datalen, umode_t mode,
1474 uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1475 __u64 rdev, struct ptlrpc_request **request)
1479 rc = exp_check_ops(exp);
1483 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1486 return exp->exp_obd->obd_type->typ_md_ops->m_create(exp, op_data, data,
1492 static inline int md_enqueue(struct obd_export *exp,
1493 struct ldlm_enqueue_info *einfo,
1494 const union ldlm_policy_data *policy,
1495 struct md_op_data *op_data,
1496 struct lustre_handle *lockh,
1497 __u64 extra_lock_flags)
1501 rc = exp_check_ops(exp);
1505 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1508 return exp->exp_obd->obd_type->typ_md_ops->m_enqueue(exp, einfo, policy,
1513 static inline int md_enqueue_async(struct obd_export *exp,
1514 struct ldlm_enqueue_info *einfo,
1515 obd_enqueue_update_f upcall,
1516 struct md_op_data *op_data,
1517 const union ldlm_policy_data *policy,
1523 rc = exp_check_ops(exp);
1527 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1528 LPROC_MD_ENQUEUE_ASYNC);
1530 rc = exp->exp_obd->obd_type->typ_md_ops->m_enqueue_async(exp, einfo,
1532 policy, lock_flags);
1536 static inline int md_getattr_name(struct obd_export *exp,
1537 struct md_op_data *op_data,
1538 struct ptlrpc_request **request)
1542 rc = exp_check_ops(exp);
1546 return exp->exp_obd->obd_type->typ_md_ops->m_getattr_name(exp, op_data,
1550 static inline int md_intent_lock(struct obd_export *exp,
1551 struct md_op_data *op_data,
1552 struct lookup_intent *it,
1553 struct ptlrpc_request **reqp,
1554 ldlm_blocking_callback cb_blocking,
1555 __u64 extra_lock_flags)
1559 rc = exp_check_ops(exp);
1563 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1564 LPROC_MD_INTENT_LOCK);
1566 return exp->exp_obd->obd_type->typ_md_ops->m_intent_lock(exp, op_data,
1572 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1573 struct ptlrpc_request **request)
1577 rc = exp_check_ops(exp);
1581 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1584 return exp->exp_obd->obd_type->typ_md_ops->m_link(exp, op_data,
1588 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1589 const char *old_name, size_t oldlen,
1590 const char *new_name, size_t newlen,
1591 struct ptlrpc_request **request)
1595 rc = exp_check_ops(exp);
1599 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1602 return exp->exp_obd->obd_type->typ_md_ops->m_rename(exp, op_data,
1608 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1609 void *ea, size_t ealen,
1610 struct ptlrpc_request **request)
1614 rc = exp_check_ops(exp);
1618 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1621 return exp->exp_obd->obd_type->typ_md_ops->m_setattr(exp, op_data, ea,
1625 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1626 struct ptlrpc_request **request)
1630 rc = exp_check_ops(exp);
1634 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1637 return exp->exp_obd->obd_type->typ_md_ops->m_fsync(exp, fid, request);
1640 /* FLR: resync mirrored files. */
1641 static inline int md_file_resync(struct obd_export *exp,
1642 struct md_op_data *data)
1646 rc = exp_check_ops(exp);
1650 return exp->exp_obd->obd_type->typ_md_ops->m_file_resync(exp, data);
1653 static inline int md_read_page(struct obd_export *exp,
1654 struct md_op_data *op_data,
1655 struct md_readdir_info *mrinfo,
1656 __u64 hash_offset, struct page **ppage)
1660 rc = exp_check_ops(exp);
1664 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1665 LPROC_MD_READ_PAGE);
1667 return exp->exp_obd->obd_type->typ_md_ops->m_read_page(exp, op_data,
1673 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1674 struct ptlrpc_request **request)
1678 rc = exp_check_ops(exp);
1682 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1685 return exp->exp_obd->obd_type->typ_md_ops->m_unlink(exp, op_data,
1689 static inline int md_get_lustre_md(struct obd_export *exp,
1690 struct req_capsule *pill,
1691 struct obd_export *dt_exp,
1692 struct obd_export *md_exp,
1693 struct lustre_md *md)
1697 rc = exp_check_ops(exp);
1701 return exp->exp_obd->obd_type->typ_md_ops->m_get_lustre_md(exp, pill,
1706 static inline int md_put_lustre_md(struct obd_export *exp,
1707 struct lustre_md *md)
1711 rc = exp_check_ops(exp);
1715 return exp->exp_obd->obd_type->typ_md_ops->m_put_lustre_md(exp, md);
1718 static inline int md_merge_attr(struct obd_export *exp,
1719 const struct lmv_stripe_object *lso,
1720 struct cl_attr *attr,
1721 ldlm_blocking_callback cb)
1725 rc = exp_check_ops(exp);
1729 return exp->exp_obd->obd_type->typ_md_ops->m_merge_attr(exp, lso, attr,
1733 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1734 u64 obd_md_valid, const char *name,
1735 const void *value, size_t value_size,
1736 unsigned int xattr_flags, u32 suppgid, u32 projid,
1737 struct ptlrpc_request **req)
1741 rc = exp_check_ops(exp);
1745 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1748 return exp->exp_obd->obd_type->typ_md_ops->m_setxattr(exp, fid,
1757 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1758 u64 obd_md_valid, const char *name,
1759 size_t buf_size, u32 projid,
1760 struct ptlrpc_request **req)
1764 rc = exp_check_ops(exp);
1768 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1771 return exp->exp_obd->obd_type->typ_md_ops->m_getxattr(exp, fid,
1777 static inline int md_set_open_replay_data(struct obd_export *exp,
1778 struct obd_client_handle *och,
1779 struct lookup_intent *it)
1783 rc = exp_check_ops(exp);
1787 return exp->exp_obd->obd_type->typ_md_ops->m_set_open_replay_data(exp,
1792 static inline int md_clear_open_replay_data(struct obd_export *exp,
1793 struct obd_client_handle *och)
1797 rc = exp_check_ops(exp);
1801 return exp->exp_obd->obd_type->typ_md_ops->m_clear_open_replay_data(exp, och);
1804 static inline int md_set_lock_data(struct obd_export *exp,
1805 const struct lustre_handle *lockh,
1806 void *data, enum mds_ibits_locks *bits)
1810 rc = exp_check_ops(exp);
1814 return exp->exp_obd->obd_type->typ_md_ops->m_set_lock_data(exp, lockh,
1820 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1821 union ldlm_policy_data *policy, enum ldlm_mode mode,
1822 enum ldlm_cancel_flags cancel_flags, void *opaque)
1826 rc = exp_check_ops(exp);
1830 return exp->exp_obd->obd_type->typ_md_ops->m_cancel_unused(exp,
1837 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1838 const struct lu_fid *fid,
1839 enum ldlm_type type,
1840 union ldlm_policy_data *policy,
1841 enum ldlm_mode mode,
1842 enum ldlm_match_flags match_flags,
1843 struct lustre_handle *lockh)
1847 rc = exp_check_ops(exp);
1851 return exp->exp_obd->obd_type->typ_md_ops->m_lock_match(exp, flags,
1858 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1863 rc = exp_check_ops(exp);
1867 return exp->exp_obd->obd_type->typ_md_ops->m_init_ea_size(exp, ea_size,
1871 static inline int md_intent_getattr_async(struct obd_export *exp,
1872 struct md_op_item *item)
1876 rc = exp_check_ops(exp);
1880 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1881 LPROC_MD_INTENT_GETATTR_ASYNC);
1883 return exp->exp_obd->obd_type->typ_md_ops->m_intent_getattr_async(exp,
1887 static inline int md_revalidate_lock(struct obd_export *exp,
1888 struct lookup_intent *it,
1890 enum mds_ibits_locks *bits)
1894 rc = exp_check_ops(exp);
1898 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1899 LPROC_MD_REVALIDATE_LOCK);
1901 return exp->exp_obd->obd_type->typ_md_ops->m_revalidate_lock(exp,
1906 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1907 const struct lmv_stripe_object *lso,
1908 const char *name, int namelen,
1913 rc = exp_check_ops(exp);
1917 return exp->exp_obd->obd_type->typ_md_ops->m_get_fid_from_lsm(exp,
1923 /* Unpack an MD struct from disk to in-memory format.
1924 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1926 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1927 * If *plsm == NULL then it will be allocated.
1929 static inline int md_stripe_object_create(struct obd_export *exp,
1930 struct lmv_stripe_object **lsop,
1931 const union lmv_mds_md *lmm,
1936 rc = exp_check_ops(exp);
1940 return exp->exp_obd->obd_type->typ_md_ops->m_stripe_object_create(exp,
1946 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1947 int *rcs, struct ptlrpc_request_set *set)
1951 rc = exp_check_ops(exp);
1955 return exp->exp_obd->obd_type->typ_md_ops->m_rmfid(exp, fa, rcs, set);
1958 static inline struct lu_batch *
1959 md_batch_create(struct obd_export *exp, enum lu_batch_flags flags,
1964 rc = exp_check_ops(exp);
1968 return exp->exp_obd->obd_type->typ_md_ops->m_batch_create(exp, flags,
1972 static inline int md_batch_stop(struct obd_export *exp, struct lu_batch *bh)
1976 rc = exp_check_ops(exp);
1980 return exp->exp_obd->obd_type->typ_md_ops->m_batch_stop(exp, bh);
1983 static inline int md_batch_flush(struct obd_export *exp, struct lu_batch *bh,
1988 rc = exp_check_ops(exp);
1992 return exp->exp_obd->obd_type->typ_md_ops->m_batch_flush(exp, bh, wait);
1995 static inline int md_batch_add(struct obd_export *exp, struct lu_batch *bh,
1996 struct md_op_item *item)
2000 rc = exp_check_ops(exp);
2004 return exp->exp_obd->obd_type->typ_md_ops->m_batch_add(exp, bh, item);
2007 /* OBD Metadata Support */
2009 extern int obd_init_caches(void);
2010 extern void obd_cleanup_caches(void);
2012 typedef int (*register_lwp_cb)(void *data);
2014 struct lwp_register_item {
2015 struct obd_export **lri_exp;
2016 register_lwp_cb lri_cb_func;
2018 struct list_head lri_list;
2020 char lri_name[MTI_NAME_MAXLEN];
2024 #ifdef HAVE_SERVER_SUPPORT
2025 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
2026 register_lwp_cb cb_func, void *cb_data);
2027 void lustre_deregister_lwp_item(struct obd_export **exp);
2028 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
2029 void lustre_notify_lwp_list(struct obd_export *exp);
2030 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
2031 #endif /* HAVE_SERVER_SUPPORT */
2032 int lustre_check_exclusion(struct super_block *sb, char *svname);
2035 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
2037 int class_add_uuid(const char *uuid, struct lnet_nid *nid);
2038 int class_del_uuid (const char *uuid);
2039 int class_add_nids_to_uuid(struct obd_uuid *uuid, struct lnet_nid *nidlist,
2040 int nid_count, int nid_size);
2041 int class_check_uuid(struct obd_uuid *uuid, struct lnet_nid *nid);
2044 extern char obd_jobid_name[];
2046 extern unsigned int obd_lbug_on_eviction;
2047 extern unsigned int obd_dump_on_eviction;
2049 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
2051 if (obd_lbug_on_eviction &&
2052 strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
2053 strlen(LUSTRE_MGC_NAME))) {
2054 CERROR("LBUG upon eviction\n");
2058 return obd_dump_on_eviction;
2063 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
2064 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
2066 /* root squash info */
2067 struct root_squash_info {
2070 struct list_head rsi_nosquash_nids;
2071 spinlock_t rsi_lock;
2074 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
2076 /* linux-module.c */
2077 struct obd_ioctl_data;
2078 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
2079 int class_procfs_init(void);
2080 int class_procfs_clean(void);
2082 extern void obd_heat_add(struct obd_heat_instance *instance,
2083 unsigned int time_second, __u64 count,
2084 unsigned int weight, unsigned int period_second);
2085 extern void obd_heat_decay(struct obd_heat_instance *instance,
2086 __u64 time_second, unsigned int weight,
2087 unsigned int period_second);
2088 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
2089 unsigned int time_second, unsigned int weight,
2090 unsigned int period_second);
2091 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
2093 /* struct kobj_type */
2095 struct attribute *_get_attr_matches(const struct kobj_type *typ,
2096 const char *key, size_t keylen,
2097 int (*is_match)(const char *, const char *,
2102 #ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
2103 for (i = 0; typ->default_groups[i]; i++) {
2105 struct attribute **attrs;
2107 attrs = (struct attribute **)typ->default_groups[i]->attrs;
2108 for (k = 0; attrs[k]; k++) {
2109 if (is_match(attrs[k]->name, key, keylen))
2110 return (struct attribute *)attrs[k];
2114 for (i = 0; typ->default_attrs[i]; i++) {
2115 if (is_match(typ->default_attrs[i]->name, key, keylen))
2116 return typ->default_attrs[i];
2123 int _attr_name_exact(const char *attr_name, const char *key, size_t len)
2125 return !strcmp(attr_name, key);
2129 struct attribute *get_attr_by_name(const struct kobj_type *typ,
2132 return _get_attr_matches(typ, name, 0, _attr_name_exact);
2136 int _attr_name_starts_with(const char *attr_name, const char *name, size_t len)
2138 return !strncmp(attr_name, name, len);
2142 struct attribute *get_attr_starts_with(const struct kobj_type *typ,
2146 return _get_attr_matches(typ, name, len, _attr_name_starts_with);
2149 int obd_ioctl_msg(const char *file, const char *func, int line, int level,
2150 const char *name, unsigned int cmd, const char *msg, int rc);
2151 #define OBD_IOC_DEBUG(level, dev, cmd, msg, rc) \
2152 obd_ioctl_msg(__FILE__, __func__, __LINE__, level, dev, cmd, msg, rc)
2153 #define OBD_IOC_ERROR(dev, cmd, msg, rc) \
2154 obd_ioctl_msg(__FILE__, __func__, __LINE__, D_ERROR, dev, cmd, msg, rc)
2156 /* ldlm/ldlm_lib.c */
2157 void target_recovery_fini(struct obd_device *obd);
2158 void target_recovery_init(struct lu_target *lut, svc_handler_t handler);
2161 #endif /* __LINUX_OBD_CLASS_H */