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);
150 int obd_pool_init(void);
151 void obd_pool_fini(void);
152 void obd_pool_add_user(void);
153 int obd_pool_get_desc_pages(struct ptlrpc_bulk_desc *desc);
154 int obd_pool_get_pages_array(struct page **pa, unsigned int count);
155 int obd_pool_get_pages(void **buf, unsigned int order);
156 void obd_pool_put_desc_pages(struct ptlrpc_bulk_desc *desc);
157 void obd_pool_put_pages_array(struct page **pa, unsigned int count);
158 void obd_pool_put_pages(void *buf, unsigned int order);
159 int obd_pool_get_free_pages(unsigned int order);
160 int pool_is_at_full_capacity(int order);
162 int encrypt_page_pools_seq_show(struct seq_file *m, void *v);
163 int page_pools_seq_show(struct seq_file *m, void *v);
165 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
166 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
170 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
171 struct llog_rec_hdr *, void *);
173 struct obd_export *obd_stale_export_get(void);
174 void obd_stale_export_put(struct obd_export *exp);
175 void obd_stale_export_adjust(struct obd_export *exp);
178 /* For interoperability */
179 struct cfg_interop_param {
184 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
185 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
186 const char *new_name);
187 void print_lustre_cfg(struct lustre_cfg *lcfg);
188 int class_process_config(struct lustre_cfg *lcfg);
189 ssize_t class_set_global(const char *param);
190 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
191 struct kobject *kobj);
192 int class_attach(struct lustre_cfg *lcfg);
193 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
194 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
195 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
197 int class_find_param(char *buf, char *key, char **valp);
198 struct cfg_interop_param *class_find_old_param(const char *param,
199 struct cfg_interop_param *ptr);
200 int class_get_next_param(char **params, char *copy);
201 int class_match_param(char *buf, const char *key, char **valp);
202 int class_parse_nid(char *buf, struct lnet_nid *nid, char **endh);
203 int class_parse_nid_quiet(char *buf, struct lnet_nid *nid, char **endh);
204 int class_parse_net(char *buf, u32 *net, char **endh);
205 int class_match_nid(char *buf, char *key, struct lnet_nid *nid);
206 int class_match_net(char *buf, char *key, u32 net);
208 struct obd_device *class_incref(struct obd_device *obd,
209 const char *scope, const void *source);
210 void class_decref(struct obd_device *obd,
211 const char *scope, const void *source);
212 void dump_exports(struct obd_device *obd, int locks, int debug_level);
213 int class_config_llog_handler(const struct lu_env *env,
214 struct llog_handle *handle,
215 struct llog_rec_hdr *rec, void *data);
216 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
218 #define CFG_F_START 0x01 /* Set when we start updating from a log */
219 #define CFG_F_MARKER 0x02 /* We are within a maker */
220 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
221 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
223 /* Passed as data param to class_config_parse_llog */
224 struct config_llog_instance {
225 unsigned long cfg_instance;
226 struct super_block *cfg_sb;
227 struct obd_uuid cfg_uuid;
228 llog_cb_t cfg_callback;
229 int cfg_last_idx; /* for partial llog processing */
234 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
235 char *name, struct config_llog_instance *cfg);
238 * Generate a unique configuration instance for this mount
240 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
241 * For now, use the same value as before - the superblock pointer value.
243 * Using the client UUID would be an option, but it needs more testing.
245 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
247 return (unsigned long)sb;
250 #define CONFIG_SUB_SPTLRPC 0x01
251 #define CONFIG_SUB_RECOVER 0x02
252 #define CONFIG_SUB_PARAMS 0x04
253 #define CONFIG_SUB_NODEMAP 0x08
254 #define CONFIG_SUB_BARRIER 0x10
256 /* Sub clds should be attached to the config_llog_data when processing
257 * config log for client or server target. */
258 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
260 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
263 #define PARAMS_FILENAME "params"
264 #define BARRIER_FILENAME "barrier"
265 #define LCTL_UPCALL "lctl"
267 static inline bool logname_is_barrier(const char *logname)
271 /* logname for barrier is "fsname-barrier" */
272 ptr = strstr(logname, BARRIER_FILENAME);
273 if (ptr && (ptr - logname) >= 2 &&
274 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
280 /* list of active configuration logs */
281 struct config_llog_data {
282 struct ldlm_res_id cld_resid;
283 struct lustre_handle cld_lockh;
284 struct config_llog_instance cld_cfg;
285 struct list_head cld_list_chain;/* on config_llog_list */
286 refcount_t cld_refcount;
287 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
288 struct config_llog_data *cld_params; /* common parameters log */
289 struct config_llog_data *cld_recover;/* imperative recover log */
290 struct config_llog_data *cld_nodemap;/* nodemap log */
291 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
292 struct obd_export *cld_mgcexp;
293 struct mutex cld_lock;
294 enum mgs_cfg_type cld_type;
295 unsigned int cld_stopping:1, /* we were told to stop
297 cld_lostlock:1, /* lock not requeued */
298 cld_processed:1; /* successfully fetched */
302 struct lustre_profile {
303 struct list_head lp_list;
308 bool lp_list_deleted;
311 struct lustre_profile *class_get_profile(const char * prof);
312 void class_del_profile(const char *prof);
313 void class_put_profile(struct lustre_profile *lprof);
314 void class_del_profiles(void);
317 #if LUSTRE_TRACKS_LOCK_EXP_REFS
319 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
320 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
321 extern void (*class_export_dump_hook)(struct obd_export *);
325 #define __class_export_add_lock_ref(exp, lock) do {} while (0)
326 #define __class_export_del_lock_ref(exp, lock) do {} while (0)
330 #define class_export_rpc_inc(exp) \
332 atomic_inc(&(exp)->exp_rpc_count); \
333 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
334 (exp), atomic_read(&(exp)->exp_rpc_count)); \
337 #define class_export_rpc_dec(exp) \
339 LASSERT(atomic_read(&(exp)->exp_rpc_count) > 0); \
340 atomic_dec(&(exp)->exp_rpc_count); \
341 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
342 (exp), atomic_read(&(exp)->exp_rpc_count)); \
345 #define class_export_lock_get(exp, lock) \
347 atomic_inc(&(exp)->exp_locks_count); \
348 __class_export_add_lock_ref(exp, lock); \
349 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
350 (exp), atomic_read(&(exp)->exp_locks_count)); \
351 class_export_get(exp); \
354 #define class_export_lock_put(exp, lock) \
356 LASSERT(atomic_read(&(exp)->exp_locks_count) > 0); \
357 atomic_dec(&(exp)->exp_locks_count); \
358 __class_export_del_lock_ref(exp, lock); \
359 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
360 (exp), atomic_read(&(exp)->exp_locks_count)); \
361 class_export_put(exp); \
364 #define class_export_cb_get(exp) \
366 atomic_inc(&(exp)->exp_cb_count); \
367 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
368 (exp), atomic_read(&(exp)->exp_cb_count)); \
369 class_export_get(exp); \
372 #define class_export_cb_put(exp) \
374 LASSERT(atomic_read(&(exp)->exp_cb_count) > 0); \
375 atomic_dec(&(exp)->exp_cb_count); \
376 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
377 (exp), atomic_read(&(exp)->exp_cb_count)); \
378 class_export_put(exp); \
382 struct obd_export *class_export_get(struct obd_export *exp);
383 void class_export_put(struct obd_export *exp);
384 struct obd_export *class_new_export(struct obd_device *obd,
385 struct obd_uuid *cluuid);
386 struct obd_export *class_new_export_self(struct obd_device *obd,
387 struct obd_uuid *uuid);
388 void class_unlink_export(struct obd_export *exp);
390 struct obd_import *class_import_get(struct obd_import *);
391 void class_import_put(struct obd_import *);
392 struct obd_import *class_new_import(struct obd_device *obd);
393 void class_destroy_import(struct obd_import *exp);
395 #ifdef HAVE_SERVER_SUPPORT
396 struct obd_type *class_search_type(const char *name);
397 struct obd_type *class_get_type(const char *name);
399 void class_put_type(struct obd_type *type);
400 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
401 struct obd_uuid *cluuid);
402 int class_disconnect(struct obd_export *exp);
403 void class_fail_export(struct obd_export *exp);
404 int class_connected_export(struct obd_export *exp);
405 void class_disconnect_exports(struct obd_device *obd);
406 int class_manual_cleanup(struct obd_device *obd);
407 void class_disconnect_stale_exports(struct obd_device *,
408 int (*test_export)(struct obd_export *));
410 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
412 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
413 (obd->obd_force ? OBD_OPT_FORCE : 0) |
414 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
418 #ifdef HAVE_SERVER_SUPPORT
419 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
421 struct obd_device_target *obt;
423 LASSERT(exp->exp_obd);
424 obt = (void *)&exp->exp_obd->u;
425 if (obt->obt_magic != OBT_MAGIC)
430 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
432 struct obd_device_target *obt = obd2obt(obd);
435 return &obt->obt_lut->lut_lsd;
443 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
444 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
446 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
447 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
449 static inline int obd_check_dev(struct obd_device *obd)
452 CERROR("NULL device\n");
458 /* ensure obd_setup and !obd_stopping */
459 #define OBD_CHECK_DEV_ACTIVE(obd) \
461 rc = obd_check_dev(obd); \
465 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
466 CERROR("Device %d not setup\n", \
473 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
475 /* Always add in ldlm_stats */
476 tmp->nid_ldlm_stats =
477 lprocfs_stats_alloc(LDLM_LAST_OPC - LDLM_FIRST_OPC,
478 LPROCFS_STATS_FLAG_NOPERCPU);
479 if (tmp->nid_ldlm_stats == NULL)
482 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
484 return lprocfs_stats_register(tmp->nid_proc, "ldlm_stats",
485 tmp->nid_ldlm_stats);
488 static inline int exp_check_ops(struct obd_export *exp)
493 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
499 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
500 __u32 keylen, void *key,
501 __u32 *vallen, void *val)
507 rc = exp_check_ops(exp);
511 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
512 CERROR("%s: no %s operation\n",
513 (exp)->exp_obd->obd_name, __func__);
517 rc = exp->exp_obd->obd_type->typ_dt_ops->o_get_info(env, exp, keylen,
522 static inline int obd_set_info_async(const struct lu_env *env,
523 struct obd_export *exp,
524 __u32 keylen, void *key,
525 __u32 vallen, void *val,
526 struct ptlrpc_request_set *set)
532 rc = exp_check_ops(exp);
536 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
537 CERROR("%s: no %s operation\n",
538 (exp)->exp_obd->obd_name, __func__);
542 rc = exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async(env, exp,
551 * obd-lu integration.
553 * Functionality is being moved into new lu_device-based layering, but some
554 * pieces of configuration process are still based on obd devices.
556 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
557 * subsume ->o_setup() methods of obd devices they replace. The same for
558 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
559 * result, obd_setup() and obd_process_config() branch and call one XOR
562 * Yet neither lu_device_type_operations::ldto_device_fini() nor
563 * lu_device_type_operations::ldto_device_free() fully implement the
564 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
565 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
567 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
570 struct obd_type *type = obd->obd_type;
571 struct lu_device_type *ldt;
575 wait_var_event(&type->typ_lu,
576 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
579 struct lu_context session_ctx;
582 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
583 session_ctx.lc_thread = NULL;
584 lu_context_enter(&session_ctx);
586 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
588 struct lu_device *dev;
589 env.le_ses = &session_ctx;
590 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
593 obd->obd_lu_dev = dev;
595 #ifdef HAVE_SERVER_SUPPORT
596 if (lu_device_is_dt(dev) &&
597 lu2dt_dev(dev)->dd_rdonly)
598 obd->obd_read_only = 1;
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)
620 struct lu_device_type *ldt = obd->obd_type->typ_lu;
621 struct lu_device *d = obd->obd_lu_dev;
625 if (ldt != NULL && d != NULL) {
626 struct lu_env *env = lu_env_find();
631 rc = lu_env_init(env, ldt->ldt_ctx_tags);
635 ldt->ldt_ops->ldto_device_fini(env, d);
642 if (!obd->obd_type->typ_dt_ops->o_precleanup)
645 rc = obd->obd_type->typ_dt_ops->o_precleanup(obd);
649 static inline int obd_cleanup(struct obd_device *obd)
652 struct lu_device_type *ldt = obd->obd_type->typ_lu;
653 struct lu_device *d = obd->obd_lu_dev;
656 if (ldt != NULL && d != NULL) {
659 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
661 ldt->ldt_ops->ldto_device_free(&env, d);
663 obd->obd_lu_dev = NULL;
666 if (!obd->obd_type->typ_dt_ops->o_cleanup)
669 rc = obd->obd_type->typ_dt_ops->o_cleanup(obd);
673 static inline void obd_cleanup_client_import(struct obd_device *obd)
677 /* If we set up but never connected, the client import will not
680 down_write(&obd->u.cli.cl_sem);
681 if (obd->u.cli.cl_import) {
682 struct obd_import *imp;
684 imp = obd->u.cli.cl_import;
685 CDEBUG(D_CONFIG, "%s: client import never connected\n",
687 ptlrpc_invalidate_import(imp);
688 client_destroy_import(imp);
689 obd->u.cli.cl_import = NULL;
691 up_write(&obd->u.cli.cl_sem);
696 static inline int obd_process_config(struct obd_device *obd, int datalen,
700 struct lu_device_type *ldt = obd->obd_type->typ_lu;
701 struct lu_device *d = obd->obd_lu_dev;
705 obd->obd_process_conf = 1;
706 if (ldt != NULL && d != NULL) {
709 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
711 rc = d->ld_ops->ldo_process_config(&env, d, data);
715 if (!obd->obd_type->typ_dt_ops->o_process_config) {
716 CERROR("%s: no %s operation\n",
717 obd->obd_name, __func__);
720 rc = obd->obd_type->typ_dt_ops->o_process_config(obd, datalen,
724 obd->obd_process_conf = 0;
729 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
736 rc = exp_check_ops(exp);
740 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
741 CERROR("%s: no %s operation\n",
742 (exp)->exp_obd->obd_name, __func__);
746 rc = exp->exp_obd->obd_type->typ_dt_ops->o_create(env, exp, obdo);
750 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
757 rc = exp_check_ops(exp);
761 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
762 CERROR("%s: no %s operation\n",
763 (exp)->exp_obd->obd_name, __func__);
767 rc = exp->exp_obd->obd_type->typ_dt_ops->o_destroy(env, exp, obdo);
771 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
777 rc = exp_check_ops(exp);
781 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
782 CERROR("%s: no %s operation\n",
783 (exp)->exp_obd->obd_name, __func__);
787 rc = exp->exp_obd->obd_type->typ_dt_ops->o_getattr(env, exp, oa);
792 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
798 rc = exp_check_ops(exp);
802 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
803 CERROR("%s: no %s operation\n",
804 (exp)->exp_obd->obd_name, __func__);
808 rc = exp->exp_obd->obd_type->typ_dt_ops->o_setattr(env, exp, oa);
813 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
816 struct obd_device *obd = imp->imp_obd;
821 OBD_CHECK_DEV_ACTIVE(obd);
822 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
823 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
827 rc = obd->obd_type->typ_dt_ops->o_add_conn(imp, uuid, priority);
831 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
833 struct obd_device *obd = imp->imp_obd;
838 OBD_CHECK_DEV_ACTIVE(obd);
839 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
840 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
844 rc = obd->obd_type->typ_dt_ops->o_del_conn(imp, uuid);
848 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
850 struct obd_uuid *uuid;
854 if (!exp->exp_obd->obd_type ||
855 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
858 uuid = exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid(exp);
862 /** Create a new /a exp on device /a obd for the uuid /a cluuid
863 * @param exp New export handle
864 * @param d Connect data, supported flags are set, flags also understood
865 * by obd are returned.
867 static inline int obd_connect(const struct lu_env *env,
868 struct obd_export **exp, struct obd_device *obd,
869 struct obd_uuid *cluuid,
870 struct obd_connect_data *data,
874 __u64 ocf = data ? data->ocd_connect_flags : 0;
878 OBD_CHECK_DEV_ACTIVE(obd);
879 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
880 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
884 rc = obd->obd_type->typ_dt_ops->o_connect(env, exp, obd, cluuid, data,
886 /* check that only subset is granted */
887 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
888 data->ocd_connect_flags));
892 static inline int obd_reconnect(const struct lu_env *env,
893 struct obd_export *exp,
894 struct obd_device *obd,
895 struct obd_uuid *cluuid,
896 struct obd_connect_data *d,
900 __u64 ocf = d ? d->ocd_connect_flags : 0;
904 OBD_CHECK_DEV_ACTIVE(obd);
905 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
908 rc = obd->obd_type->typ_dt_ops->o_reconnect(env, exp, obd, cluuid, d,
910 /* check that only subset is granted */
911 LASSERT(ergo(d != NULL,
912 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
916 static inline int obd_disconnect(struct obd_export *exp)
921 rc = exp_check_ops(exp);
925 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
926 CERROR("%s: no %s operation\n",
927 (exp)->exp_obd->obd_name, __func__);
931 rc = exp->exp_obd->obd_type->typ_dt_ops->o_disconnect(exp);
935 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
936 enum lu_cli_type type)
942 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
945 rc = obd->obd_type->typ_dt_ops->o_fid_init(obd, exp, type);
949 static inline int obd_fid_fini(struct obd_device *obd)
954 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
957 rc = obd->obd_type->typ_dt_ops->o_fid_fini(obd);
961 static inline int obd_fid_alloc(const struct lu_env *env,
962 struct obd_export *exp,
964 struct md_op_data *op_data)
969 rc = exp_check_ops(exp);
973 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
974 CERROR("%s: no %s operation\n",
975 (exp)->exp_obd->obd_name, __func__);
979 rc = exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc(env, exp, fid,
984 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
990 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
991 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
995 /* Check poolname validity */
996 if (!poolname || poolname[0] == '\0' || lov_pool_is_reserved(poolname))
999 rc = obd->obd_type->typ_dt_ops->o_pool_new(obd, poolname);
1003 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1008 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
1009 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1010 RETURN(-EOPNOTSUPP);
1013 rc = obd->obd_type->typ_dt_ops->o_pool_del(obd, poolname);
1017 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1024 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1025 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1026 RETURN(-EOPNOTSUPP);
1029 rc = obd->obd_type->typ_dt_ops->o_pool_add(obd, poolname, ostname);
1033 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1039 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1040 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1041 RETURN(-EOPNOTSUPP);
1044 rc = obd->obd_type->typ_dt_ops->o_pool_rem(obd, poolname, ostname);
1048 static inline int obd_init_export(struct obd_export *exp)
1053 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1054 exp->exp_obd->obd_type->typ_dt_ops->o_init_export)
1055 rc = exp->exp_obd->obd_type->typ_dt_ops->o_init_export(exp);
1059 static inline int obd_destroy_export(struct obd_export *exp)
1062 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1063 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export)
1064 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export(exp);
1068 /* @max_age is the oldest time in seconds that we accept using a cached data.
1069 * If the cache is older than @max_age we will get a new value from the
1070 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1072 static inline int obd_statfs_async(struct obd_export *exp,
1073 struct obd_info *oinfo,
1075 struct ptlrpc_request_set *rqset)
1077 struct obd_device *obd;
1082 if (exp == NULL || exp->exp_obd == NULL)
1086 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1088 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1092 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1093 obd->obd_name, obd->obd_osfs_age, max_age);
1094 rc = obd->obd_type->typ_dt_ops->o_statfs_async(exp, oinfo, max_age,
1100 /* @max_age is the oldest time in seconds that we accept using a cached data.
1101 * If the cache is older than @max_age we will get a new value from the
1102 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1104 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1105 struct obd_statfs *osfs, time64_t max_age,
1108 struct obd_device *obd;
1112 if (unlikely(exp == NULL || exp->exp_obd == NULL))
1116 OBD_CHECK_DEV_ACTIVE(obd);
1118 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1119 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1120 RETURN(-EOPNOTSUPP);
1123 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1124 obd->obd_name, obd->obd_osfs_age, max_age);
1125 /* ignore cache if aggregated isn't expected */
1126 if (obd->obd_osfs_age < max_age ||
1127 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1128 !(flags & OBD_STATFS_SUM))) {
1129 /* the RPC will block anyway, so avoid sending many at once */
1130 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1131 (flags & OBD_STATFS_NESTED)
1132 ? SINGLE_DEPTH_NESTING : 0);
1135 if (obd->obd_osfs_age < max_age ||
1136 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1137 !(flags & OBD_STATFS_SUM))) {
1138 rc = obd->obd_type->typ_dt_ops->o_statfs(env, exp, osfs,
1142 mutex_unlock(&obd->obd_dev_mutex);
1143 GOTO(cached, rc = 0);
1147 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1148 obd->obd_name, &obd->obd_osfs,
1149 osfs->os_bavail, osfs->os_blocks,
1150 osfs->os_ffree, osfs->os_files);
1152 spin_lock(&obd->obd_osfs_lock);
1153 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1154 obd->obd_osfs_age = ktime_get_seconds();
1155 spin_unlock(&obd->obd_osfs_lock);
1157 mutex_unlock(&obd->obd_dev_mutex);
1161 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1162 obd->obd_name, &obd->obd_osfs,
1163 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1164 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1165 spin_lock(&obd->obd_osfs_lock);
1166 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1167 spin_unlock(&obd->obd_osfs_lock);
1172 static inline int obd_preprw(const struct lu_env *env, int cmd,
1173 struct obd_export *exp, struct obdo *oa,
1174 int objcount, struct obd_ioobj *obj,
1175 struct niobuf_remote *remote, int *pages,
1176 struct niobuf_local *local)
1182 rc = exp_check_ops(exp);
1186 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1187 CERROR("%s: no %s operation\n",
1188 (exp)->exp_obd->obd_name, __func__);
1192 rc = exp->exp_obd->obd_type->typ_dt_ops->o_preprw(env, cmd, exp,
1194 remote, pages, local);
1199 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1200 struct obd_export *exp, struct obdo *oa,
1201 int objcount, struct obd_ioobj *obj,
1202 struct niobuf_remote *rnb, int pages,
1203 struct niobuf_local *local, const int orig_rc,
1204 int nob, ktime_t kstart)
1210 rc = exp_check_ops(exp);
1214 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1215 CERROR("%s: no %s operation\n",
1216 (exp)->exp_obd->obd_name, __func__);
1220 rc = exp->exp_obd->obd_type->typ_dt_ops->o_commitrw(env, cmd, exp, oa,
1229 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1230 int len, void *karg, void __user *uarg)
1236 rc = exp_check_ops(exp);
1240 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1241 CERROR("%s: no %s operation\n",
1242 (exp)->exp_obd->obd_name, __func__);
1246 rc = exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol(cmd, exp,
1252 static inline void obd_import_event(struct obd_device *obd,
1253 struct obd_import *imp,
1254 enum obd_import_event event)
1258 CERROR("NULL device\n");
1263 if (obd->obd_set_up && obd->obd_type->typ_dt_ops->o_import_event)
1264 obd->obd_type->typ_dt_ops->o_import_event(obd, imp, event);
1269 static inline int obd_notify(struct obd_device *obd,
1270 struct obd_device *watched,
1271 enum obd_notify_event ev)
1277 rc = obd_check_dev(obd);
1281 if (!obd->obd_set_up) {
1282 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1286 if (!obd->obd_type->typ_dt_ops->o_notify) {
1287 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1291 rc = obd->obd_type->typ_dt_ops->o_notify(obd, watched, ev);
1296 static inline int obd_notify_observer(struct obd_device *observer,
1297 struct obd_device *observed,
1298 enum obd_notify_event ev)
1302 struct obd_notify_upcall *onu;
1304 if (WARN_ON_ONCE(!observer))
1307 if (observer->obd_observer)
1308 rc = obd_notify(observer->obd_observer, observed, ev);
1311 * Also, call non-obd listener, if any
1313 onu = &observer->obd_upcall;
1314 if (onu->onu_upcall != NULL)
1315 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1317 return rc ? rc : rc2;
1320 static inline int obd_quotactl(struct obd_export *exp,
1321 struct obd_quotactl *oqctl)
1327 rc = exp_check_ops(exp);
1331 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1332 CERROR("%s: no %s operation\n",
1333 (exp)->exp_obd->obd_name, __func__);
1337 rc = exp->exp_obd->obd_type->typ_dt_ops->o_quotactl(exp->exp_obd,
1342 static inline int obd_quota_iter(struct obd_export *exp,
1343 struct obd_quotactl *oqctl,
1344 struct list_head *list)
1349 oqctl->qc_iter_list = (__u64)list;
1350 rc = obd_quotactl(exp, oqctl);
1354 } while (oqctl->qc_iter_md_offset || oqctl->qc_iter_dt_offset);
1359 static inline int obd_health_check(const struct lu_env *env,
1360 struct obd_device *obd)
1362 /* returns: 0 on healthy
1363 * >0 on unhealthy + reason code/flag
1364 * however the only suppored reason == 1 right now
1365 * We'll need to define some better reasons
1366 * or flags in the future.
1373 /* NULL method is normal here */
1374 if (obd == NULL || !obd->obd_type) {
1375 CERROR("cleaned up obd\n");
1376 RETURN(-EOPNOTSUPP);
1378 if (!obd->obd_set_up || obd->obd_stopping)
1380 if (!obd->obd_type->typ_dt_ops->o_health_check)
1383 rc = obd->obd_type->typ_dt_ops->o_health_check(env, obd);
1387 static inline int obd_register_observer(struct obd_device *obd,
1388 struct obd_device *observer)
1394 rc = obd_check_dev(obd);
1398 down_write(&obd->obd_observer_link_sem);
1399 if (obd->obd_observer && observer) {
1400 up_write(&obd->obd_observer_link_sem);
1403 obd->obd_observer = observer;
1404 up_write(&obd->obd_observer_link_sem);
1408 /* metadata helpers */
1414 LPROC_MD_INTENT_LOCK,
1423 LPROC_MD_INTENT_GETATTR_ASYNC,
1424 LPROC_MD_REVALIDATE_LOCK,
1428 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1433 rc = exp_check_ops(exp);
1437 return exp->exp_obd->obd_type->typ_md_ops->m_get_root(exp, fileset,
1441 static inline int md_getattr(struct obd_export *exp,
1442 struct md_op_data *op_data,
1443 struct ptlrpc_request **request)
1447 rc = exp_check_ops(exp);
1451 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1454 return exp->exp_obd->obd_type->typ_md_ops->m_getattr(exp, op_data,
1458 static inline int md_null_inode(struct obd_export *exp,
1459 const struct lu_fid *fid)
1463 rc = exp_check_ops(exp);
1467 return exp->exp_obd->obd_type->typ_md_ops->m_null_inode(exp, fid);
1470 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1471 struct md_open_data *mod,
1472 struct ptlrpc_request **request)
1476 rc = exp_check_ops(exp);
1480 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1483 return exp->exp_obd->obd_type->typ_md_ops->m_close(exp, op_data, mod,
1487 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1488 const void *data, size_t datalen, umode_t mode,
1489 uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1490 __u64 rdev, struct ptlrpc_request **request)
1494 rc = exp_check_ops(exp);
1498 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1501 return exp->exp_obd->obd_type->typ_md_ops->m_create(exp, op_data, data,
1507 static inline int md_enqueue(struct obd_export *exp,
1508 struct ldlm_enqueue_info *einfo,
1509 const union ldlm_policy_data *policy,
1510 struct md_op_data *op_data,
1511 struct lustre_handle *lockh,
1512 __u64 extra_lock_flags)
1516 rc = exp_check_ops(exp);
1520 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1523 return exp->exp_obd->obd_type->typ_md_ops->m_enqueue(exp, einfo, policy,
1528 static inline int md_getattr_name(struct obd_export *exp,
1529 struct md_op_data *op_data,
1530 struct ptlrpc_request **request)
1534 rc = exp_check_ops(exp);
1538 return exp->exp_obd->obd_type->typ_md_ops->m_getattr_name(exp, op_data,
1542 static inline int md_intent_lock(struct obd_export *exp,
1543 struct md_op_data *op_data,
1544 struct lookup_intent *it,
1545 struct ptlrpc_request **reqp,
1546 ldlm_blocking_callback cb_blocking,
1547 __u64 extra_lock_flags)
1551 rc = exp_check_ops(exp);
1555 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1556 LPROC_MD_INTENT_LOCK);
1558 return exp->exp_obd->obd_type->typ_md_ops->m_intent_lock(exp, op_data,
1564 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1565 struct ptlrpc_request **request)
1569 rc = exp_check_ops(exp);
1573 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1576 return exp->exp_obd->obd_type->typ_md_ops->m_link(exp, op_data,
1580 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1581 const char *old_name, size_t oldlen,
1582 const char *new_name, size_t newlen,
1583 struct ptlrpc_request **request)
1587 rc = exp_check_ops(exp);
1591 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1594 return exp->exp_obd->obd_type->typ_md_ops->m_rename(exp, op_data,
1600 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1601 void *ea, size_t ealen,
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_setattr(exp, op_data, ea,
1617 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1618 struct ptlrpc_request **request)
1622 rc = exp_check_ops(exp);
1626 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1629 return exp->exp_obd->obd_type->typ_md_ops->m_fsync(exp, fid, request);
1632 /* FLR: resync mirrored files. */
1633 static inline int md_file_resync(struct obd_export *exp,
1634 struct md_op_data *data)
1638 rc = exp_check_ops(exp);
1642 return exp->exp_obd->obd_type->typ_md_ops->m_file_resync(exp, data);
1645 static inline int md_read_page(struct obd_export *exp,
1646 struct md_op_data *op_data,
1647 struct md_readdir_info *mrinfo,
1648 __u64 hash_offset, struct page **ppage)
1652 rc = exp_check_ops(exp);
1656 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1657 LPROC_MD_READ_PAGE);
1659 return exp->exp_obd->obd_type->typ_md_ops->m_read_page(exp, op_data,
1665 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1666 struct ptlrpc_request **request)
1670 rc = exp_check_ops(exp);
1674 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1677 return exp->exp_obd->obd_type->typ_md_ops->m_unlink(exp, op_data,
1681 static inline int md_get_lustre_md(struct obd_export *exp,
1682 struct req_capsule *pill,
1683 struct obd_export *dt_exp,
1684 struct obd_export *md_exp,
1685 struct lustre_md *md)
1689 rc = exp_check_ops(exp);
1693 return exp->exp_obd->obd_type->typ_md_ops->m_get_lustre_md(exp, pill,
1698 static inline int md_put_lustre_md(struct obd_export *exp,
1699 struct lustre_md *md)
1703 rc = exp_check_ops(exp);
1707 return exp->exp_obd->obd_type->typ_md_ops->m_put_lustre_md(exp, md);
1710 static inline int md_merge_attr(struct obd_export *exp,
1711 const struct lmv_stripe_object *lso,
1712 struct cl_attr *attr,
1713 ldlm_blocking_callback cb)
1717 rc = exp_check_ops(exp);
1721 return exp->exp_obd->obd_type->typ_md_ops->m_merge_attr(exp, lso, attr,
1725 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1726 u64 obd_md_valid, const char *name,
1727 const void *value, size_t value_size,
1728 unsigned int xattr_flags, u32 suppgid,
1729 struct ptlrpc_request **req)
1733 rc = exp_check_ops(exp);
1737 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1740 return exp->exp_obd->obd_type->typ_md_ops->m_setxattr(exp, fid,
1749 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1750 u64 obd_md_valid, const char *name,
1751 size_t buf_size, struct ptlrpc_request **req)
1755 rc = exp_check_ops(exp);
1759 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1762 return exp->exp_obd->obd_type->typ_md_ops->m_getxattr(exp, fid,
1768 static inline int md_set_open_replay_data(struct obd_export *exp,
1769 struct obd_client_handle *och,
1770 struct lookup_intent *it)
1774 rc = exp_check_ops(exp);
1778 return exp->exp_obd->obd_type->typ_md_ops->m_set_open_replay_data(exp,
1783 static inline int md_clear_open_replay_data(struct obd_export *exp,
1784 struct obd_client_handle *och)
1788 rc = exp_check_ops(exp);
1792 return exp->exp_obd->obd_type->typ_md_ops->m_clear_open_replay_data(exp, och);
1795 static inline int md_set_lock_data(struct obd_export *exp,
1796 const struct lustre_handle *lockh,
1797 void *data, __u64 *bits)
1801 rc = exp_check_ops(exp);
1805 return exp->exp_obd->obd_type->typ_md_ops->m_set_lock_data(exp, lockh,
1811 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1812 union ldlm_policy_data *policy, enum ldlm_mode mode,
1813 enum ldlm_cancel_flags cancel_flags, void *opaque)
1817 rc = exp_check_ops(exp);
1821 return exp->exp_obd->obd_type->typ_md_ops->m_cancel_unused(exp,
1828 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1829 const struct lu_fid *fid,
1830 enum ldlm_type type,
1831 union ldlm_policy_data *policy,
1832 enum ldlm_mode mode,
1833 struct lustre_handle *lockh)
1837 rc = exp_check_ops(exp);
1841 return exp->exp_obd->obd_type->typ_md_ops->m_lock_match(exp, flags,
1847 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1852 rc = exp_check_ops(exp);
1856 return exp->exp_obd->obd_type->typ_md_ops->m_init_ea_size(exp, ea_size,
1860 static inline int md_intent_getattr_async(struct obd_export *exp,
1861 struct md_op_item *item)
1865 rc = exp_check_ops(exp);
1869 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1870 LPROC_MD_INTENT_GETATTR_ASYNC);
1872 return exp->exp_obd->obd_type->typ_md_ops->m_intent_getattr_async(exp,
1876 static inline int md_revalidate_lock(struct obd_export *exp,
1877 struct lookup_intent *it,
1878 struct lu_fid *fid, __u64 *bits)
1882 rc = exp_check_ops(exp);
1886 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1887 LPROC_MD_REVALIDATE_LOCK);
1889 return exp->exp_obd->obd_type->typ_md_ops->m_revalidate_lock(exp,
1894 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1895 const struct lmv_stripe_object *lso,
1896 const char *name, int namelen,
1901 rc = exp_check_ops(exp);
1905 return exp->exp_obd->obd_type->typ_md_ops->m_get_fid_from_lsm(exp,
1911 /* Unpack an MD struct from disk to in-memory format.
1912 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1914 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1915 * If *plsm == NULL then it will be allocated.
1917 static inline int md_stripe_object_create(struct obd_export *exp,
1918 struct lmv_stripe_object **lsop,
1919 const union lmv_mds_md *lmm,
1924 rc = exp_check_ops(exp);
1928 return exp->exp_obd->obd_type->typ_md_ops->m_stripe_object_create(exp,
1934 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1935 int *rcs, struct ptlrpc_request_set *set)
1939 rc = exp_check_ops(exp);
1943 return exp->exp_obd->obd_type->typ_md_ops->m_rmfid(exp, fa, rcs, set);
1946 static inline struct lu_batch *
1947 md_batch_create(struct obd_export *exp, enum lu_batch_flags flags,
1952 rc = exp_check_ops(exp);
1956 return exp->exp_obd->obd_type->typ_md_ops->m_batch_create(exp, flags,
1960 static inline int md_batch_stop(struct obd_export *exp, struct lu_batch *bh)
1964 rc = exp_check_ops(exp);
1968 return exp->exp_obd->obd_type->typ_md_ops->m_batch_stop(exp, bh);
1971 static inline int md_batch_flush(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_flush(exp, bh, wait);
1983 static inline int md_batch_add(struct obd_export *exp, struct lu_batch *bh,
1984 struct md_op_item *item)
1988 rc = exp_check_ops(exp);
1992 return exp->exp_obd->obd_type->typ_md_ops->m_batch_add(exp, bh, item);
1995 /* OBD Metadata Support */
1997 extern int obd_init_caches(void);
1998 extern void obd_cleanup_caches(void);
2000 typedef int (*register_lwp_cb)(void *data);
2002 struct lwp_register_item {
2003 struct obd_export **lri_exp;
2004 register_lwp_cb lri_cb_func;
2006 struct list_head lri_list;
2008 char lri_name[MTI_NAME_MAXLEN];
2012 #ifdef HAVE_SERVER_SUPPORT
2013 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
2014 register_lwp_cb cb_func, void *cb_data);
2015 void lustre_deregister_lwp_item(struct obd_export **exp);
2016 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
2017 void lustre_notify_lwp_list(struct obd_export *exp);
2018 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
2019 #endif /* HAVE_SERVER_SUPPORT */
2020 int lustre_check_exclusion(struct super_block *sb, char *svname);
2023 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
2025 int class_add_uuid(const char *uuid, struct lnet_nid *nid);
2026 int class_del_uuid (const char *uuid);
2027 int class_add_nids_to_uuid(struct obd_uuid *uuid, struct lnet_nid *nidlist,
2028 int nid_count, int nid_size);
2029 int class_check_uuid(struct obd_uuid *uuid, struct lnet_nid *nid);
2032 extern char obd_jobid_name[];
2034 extern unsigned int obd_lbug_on_eviction;
2035 extern unsigned int obd_dump_on_eviction;
2037 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
2039 if (obd_lbug_on_eviction &&
2040 strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
2041 strlen(LUSTRE_MGC_NAME))) {
2042 CERROR("LBUG upon eviction\n");
2046 return obd_dump_on_eviction;
2051 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
2052 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
2054 /* root squash info */
2055 struct root_squash_info {
2058 struct list_head rsi_nosquash_nids;
2059 spinlock_t rsi_lock;
2062 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
2064 /* linux-module.c */
2065 struct obd_ioctl_data;
2066 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
2067 int class_procfs_init(void);
2068 int class_procfs_clean(void);
2070 extern void obd_heat_add(struct obd_heat_instance *instance,
2071 unsigned int time_second, __u64 count,
2072 unsigned int weight, unsigned int period_second);
2073 extern void obd_heat_decay(struct obd_heat_instance *instance,
2074 __u64 time_second, unsigned int weight,
2075 unsigned int period_second);
2076 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
2077 unsigned int time_second, unsigned int weight,
2078 unsigned int period_second);
2079 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
2081 /* struct kobj_type */
2083 struct attribute *_get_attr_matches(const struct kobj_type *typ,
2084 const char *key, size_t keylen,
2085 int (*is_match)(const char *, const char *,
2090 #ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
2091 for (i = 0; typ->default_groups[i]; i++) {
2093 struct attribute **attrs;
2095 attrs = (struct attribute **)typ->default_groups[i]->attrs;
2096 for (k = 0; attrs[k]; k++) {
2097 if (is_match(attrs[k]->name, key, keylen))
2098 return (struct attribute *)attrs[k];
2102 for (i = 0; typ->default_attrs[i]; i++) {
2103 if (is_match(typ->default_attrs[i]->name, key, keylen))
2104 return typ->default_attrs[i];
2111 int _attr_name_exact(const char *attr_name, const char *key, size_t len)
2113 return !strcmp(attr_name, key);
2117 struct attribute *get_attr_by_name(const struct kobj_type *typ,
2120 return _get_attr_matches(typ, name, 0, _attr_name_exact);
2124 int _attr_name_starts_with(const char *attr_name, const char *name, size_t len)
2126 return !strncmp(attr_name, name, len);
2130 struct attribute *get_attr_starts_with(const struct kobj_type *typ,
2134 return _get_attr_matches(typ, name, len, _attr_name_starts_with);
2137 int obd_ioctl_msg(const char *file, const char *func, int line, int level,
2138 const char *name, unsigned int cmd, const char *msg, int rc);
2139 #define OBD_IOC_DEBUG(level, dev, cmd, msg, rc) \
2140 obd_ioctl_msg(__FILE__, __func__, __LINE__, level, dev, cmd, msg, rc)
2141 #define OBD_IOC_ERROR(dev, cmd, msg, rc) \
2142 obd_ioctl_msg(__FILE__, __func__, __LINE__, D_ERROR, dev, cmd, msg, rc)
2144 #endif /* __LINUX_OBD_CLASS_H */