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 #ifdef HAVE_SERVER_SUPPORT
37 #define SERVER_ONLY_EXPORT_SYMBOL(symbol) EXPORT_SYMBOL(symbol)
40 #define SERVER_ONLY static
41 #define SERVER_ONLY_EXPORT_SYMBOL(symbol)
44 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
45 * and resends for avoid deadlocks */
46 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
48 #define OBD_STATFS_FOR_MDT0 0x0004 /* The statfs is only for retrieving
49 * information from MDT0. */
50 #define OBD_STATFS_SUM 0x0008 /* get aggregated statfs from MDT */
51 #define OBD_STATFS_NESTED 0x0010 /* Call while already holding
52 * obd_dev_mutex of a difference
56 #define OBD_MAX_INDEX xa_limit_31b.max
58 #define obd_device_find(devno) \
59 xa_find(&obd_devs, &devno, OBD_MAX_INDEX, XA_PRESENT)
61 #define obd_device_find_after(devno) \
62 xa_find_after(&obd_devs, &devno, OBD_MAX_INDEX, XA_PRESENT)
64 #define obd_device_for_each(devno, obd) \
65 xa_for_each(&obd_devs, devno, obd)
67 #define obd_device_for_each_start(devno, obd, start) \
68 xa_for_each_start(&obd_devs, devno, obd, start)
70 #define obd_device_for_each_cond(devno, obd, cond) \
71 obd_device_for_each(devno, obd) \
74 #define obd_device_for_each_uuid(devno, obd, uuid) \
75 obd_device_for_each_cond(devno, obd, \
76 obd_uuid_equals(uuid, &obd->obd_uuid))
78 #define obd_device_lock() xa_lock(&obd_devs)
79 #define obd_device_unlock() xa_unlock(&obd_devs)
81 /* OBD Operations Declarations */
82 extern struct obd_device *class_exp2obd(struct obd_export *);
83 extern int class_handle_ioctl(unsigned int cmd, void __user *uarg);
84 int lustre_get_jobid(char *jobid, size_t len);
85 void lustre_jobid_clear(const char *jobid);
86 void jobid_cache_fini(void);
87 int jobid_cache_init(void);
88 char *jobid_current(void);
89 int jobid_set_current(char *jobid);
91 struct lu_device_type;
94 extern struct xarray obd_devs;
95 struct obd_export *class_conn2export(struct lustre_handle *);
96 #ifdef HAVE_SERVER_SUPPORT
97 struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
99 int class_register_type(const struct obd_ops *dt_ops,
100 const struct md_ops *md_ops, bool enable_proc,
101 const char *nm, struct lu_device_type *ldt);
102 int class_unregister_type(const char *nm);
104 struct obd_device *class_newdev(const char *type_name, const char *name,
106 int class_register_device(struct obd_device *obd);
107 void class_unregister_device(struct obd_device *obd);
108 void class_free_dev(struct obd_device *obd);
110 struct obd_device *class_str2obd(const char *str);
111 int class_name2dev(const char *name);
112 struct obd_device *class_name2obd(const char *name);
113 int class_uuid2dev(struct obd_uuid *uuid);
114 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
115 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
116 const char *type_name,
117 struct obd_uuid *grp_uuid);
118 struct obd_device *class_num2obd(int num);
119 int class_obd_devs_count(void);
121 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
123 static inline char *obd_export_nid2str(struct obd_export *exp)
125 return exp->exp_connection == NULL ?
126 "<unknown>" : libcfs_nidstr(&exp->exp_connection->c_peer.nid);
129 static inline char *obd_import_nid2str(struct obd_import *imp)
131 return imp->imp_connection == NULL ?
132 "<unknown>" : libcfs_nidstr(&imp->imp_connection->c_peer.nid);
135 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
136 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
137 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
140 int obd_zombie_impexp_init(void);
141 void obd_zombie_impexp_stop(void);
142 void obd_zombie_impexp_cull(void);
143 void obd_zombie_barrier(void);
144 void obd_exports_barrier(struct obd_device *obd);
145 int kuc_len(int payload_len);
146 struct kuc_hdr * kuc_ptr(void *p);
147 void *kuc_alloc(int payload_len, int transport, int type);
148 void kuc_free(void *p, int payload_len);
149 int obd_get_request_slot(struct client_obd *cli);
150 void obd_put_request_slot(struct client_obd *cli);
151 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
152 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
153 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
154 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
155 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
158 int obd_pool_init(void);
159 void obd_pool_fini(void);
160 void obd_pool_add_user(void);
161 int obd_pool_get_desc_pages(struct ptlrpc_bulk_desc *desc);
162 int obd_pool_get_pages_array(struct page **pa, unsigned int count);
163 int obd_pool_get_pages(void **buf, unsigned int order);
164 void obd_pool_put_desc_pages(struct ptlrpc_bulk_desc *desc);
165 void obd_pool_put_pages_array(struct page **pa, unsigned int count);
166 void obd_pool_put_pages(void *buf, unsigned int order);
167 int obd_pool_get_free_pages(unsigned int order);
168 int pool_is_at_full_capacity(int order);
170 int encrypt_page_pools_seq_show(struct seq_file *m, void *v);
171 int page_pools_seq_show(struct seq_file *m, void *v);
173 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
174 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
178 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
179 struct llog_rec_hdr *, void *);
181 struct obd_export *obd_stale_export_get(void);
182 void obd_stale_export_put(struct obd_export *exp);
183 void obd_stale_export_adjust(struct obd_export *exp);
186 /* For interoperability */
187 struct cfg_interop_param {
192 #ifdef HAVE_SERVER_SUPPORT
193 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg));
196 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
197 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
198 const char *new_name);
199 void print_lustre_cfg(struct lustre_cfg *lcfg);
200 int class_process_config(struct lustre_cfg *lcfg);
201 ssize_t class_set_global(const char *param);
202 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
203 struct kobject *kobj);
204 int class_attach(struct lustre_cfg *lcfg);
205 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
206 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
207 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
209 int class_find_param(char *buf, char *key, char **valp);
210 struct cfg_interop_param *class_find_old_param(const char *param,
211 struct cfg_interop_param *ptr);
212 int class_get_next_param(char **params, char *copy);
213 int class_match_param(char *buf, const char *key, char **valp);
214 int class_parse_nid(char *buf, struct lnet_nid *nid, char **endh);
215 int class_parse_nid_quiet(char *buf, struct lnet_nid *nid, char **endh);
216 int class_parse_net(char *buf, u32 *net, char **endh);
217 int class_match_nid(char *buf, char *key, struct lnet_nid *nid);
218 int class_match_net(char *buf, char *key, u32 net);
220 struct obd_device *class_incref(struct obd_device *obd,
221 const char *scope, const void *source);
222 void class_decref(struct obd_device *obd,
223 const char *scope, const void *source);
224 void dump_exports(struct obd_device *obd, int locks, int debug_level);
225 int class_config_llog_handler(const struct lu_env *env,
226 struct llog_handle *handle,
227 struct llog_rec_hdr *rec, void *data);
228 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
230 #define CFG_F_START 0x01 /* Set when we start updating from a log */
231 #define CFG_F_MARKER 0x02 /* We are within a maker */
232 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
233 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
235 /* Passed as data param to class_config_parse_llog */
236 struct config_llog_instance {
237 unsigned long cfg_instance;
238 struct super_block *cfg_sb;
239 struct obd_uuid cfg_uuid;
240 llog_cb_t cfg_callback;
241 int cfg_last_idx; /* for partial llog processing */
246 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
247 char *name, struct config_llog_instance *cfg);
250 * Generate a unique configuration instance for this mount
252 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
253 * For now, use the same value as before - the superblock pointer value.
255 * Using the client UUID would be an option, but it needs more testing.
257 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
259 return (unsigned long)sb;
262 #define CONFIG_SUB_SPTLRPC 0x01
263 #define CONFIG_SUB_RECOVER 0x02
264 #define CONFIG_SUB_PARAMS 0x04
265 #define CONFIG_SUB_NODEMAP 0x08
266 #define CONFIG_SUB_BARRIER 0x10
268 /* Sub clds should be attached to the config_llog_data when processing
269 * config log for client or server target. */
270 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
272 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
275 #define PARAMS_FILENAME "params"
276 #define BARRIER_FILENAME "barrier"
277 #define LCTL_UPCALL "lctl"
279 static inline bool logname_is_barrier(const char *logname)
283 /* logname for barrier is "fsname-barrier" */
284 ptr = strstr(logname, BARRIER_FILENAME);
285 if (ptr && (ptr - logname) >= 2 &&
286 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
292 /* list of active configuration logs */
293 struct config_llog_data {
294 struct ldlm_res_id cld_resid;
295 struct lustre_handle cld_lockh;
296 struct config_llog_instance cld_cfg;
297 struct list_head cld_list_chain;/* on config_llog_list */
298 refcount_t cld_refcount;
299 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
300 struct config_llog_data *cld_params; /* common parameters log */
301 struct config_llog_data *cld_recover;/* imperative recover log */
302 struct config_llog_data *cld_nodemap;/* nodemap log */
303 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
304 struct obd_export *cld_mgcexp;
305 struct mutex cld_lock;
306 enum mgs_cfg_type cld_type;
307 unsigned int cld_stopping:1, /* we were told to stop
309 cld_lostlock:1, /* lock not requeued */
310 cld_processed:1; /* successfully fetched */
314 struct lustre_profile {
315 struct list_head lp_list;
320 bool lp_list_deleted;
323 struct lustre_profile *class_get_profile(const char * prof);
324 void class_del_profile(const char *prof);
325 void class_put_profile(struct lustre_profile *lprof);
326 void class_del_profiles(void);
329 #if LUSTRE_TRACKS_LOCK_EXP_REFS
331 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
332 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
333 extern void (*class_export_dump_hook)(struct obd_export *);
337 #define __class_export_add_lock_ref(exp, lock) do {} while (0)
338 #define __class_export_del_lock_ref(exp, lock) do {} while (0)
342 #define class_export_rpc_inc(exp) \
344 atomic_inc(&(exp)->exp_rpc_count); \
345 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
346 (exp), atomic_read(&(exp)->exp_rpc_count)); \
349 #define class_export_rpc_dec(exp) \
351 LASSERT(atomic_read(&(exp)->exp_rpc_count) > 0); \
352 atomic_dec(&(exp)->exp_rpc_count); \
353 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
354 (exp), atomic_read(&(exp)->exp_rpc_count)); \
357 #define class_export_lock_get(exp, lock) \
359 atomic_inc(&(exp)->exp_locks_count); \
360 __class_export_add_lock_ref(exp, lock); \
361 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
362 (exp), atomic_read(&(exp)->exp_locks_count)); \
363 class_export_get(exp); \
366 #define class_export_lock_put(exp, lock) \
368 LASSERT(atomic_read(&(exp)->exp_locks_count) > 0); \
369 atomic_dec(&(exp)->exp_locks_count); \
370 __class_export_del_lock_ref(exp, lock); \
371 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
372 (exp), atomic_read(&(exp)->exp_locks_count)); \
373 class_export_put(exp); \
376 #define class_export_cb_get(exp) \
378 atomic_inc(&(exp)->exp_cb_count); \
379 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
380 (exp), atomic_read(&(exp)->exp_cb_count)); \
381 class_export_get(exp); \
384 #define class_export_cb_put(exp) \
386 LASSERT(atomic_read(&(exp)->exp_cb_count) > 0); \
387 atomic_dec(&(exp)->exp_cb_count); \
388 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
389 (exp), atomic_read(&(exp)->exp_cb_count)); \
390 class_export_put(exp); \
394 struct obd_export *class_export_get(struct obd_export *exp);
395 void class_export_put(struct obd_export *exp);
396 struct obd_export *class_new_export(struct obd_device *obd,
397 struct obd_uuid *cluuid);
398 struct obd_export *class_new_export_self(struct obd_device *obd,
399 struct obd_uuid *uuid);
400 void class_unlink_export(struct obd_export *exp);
402 struct obd_import *class_import_get(struct obd_import *);
403 void class_import_put(struct obd_import *);
404 struct obd_import *class_new_import(struct obd_device *obd);
405 void class_destroy_import(struct obd_import *exp);
407 #ifdef HAVE_SERVER_SUPPORT
408 struct obd_type *class_search_type(const char *name);
409 struct obd_type *class_get_type(const char *name);
411 void class_put_type(struct obd_type *type);
412 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
413 struct obd_uuid *cluuid);
414 int class_disconnect(struct obd_export *exp);
415 void class_fail_export(struct obd_export *exp);
416 int class_connected_export(struct obd_export *exp);
417 void class_disconnect_exports(struct obd_device *obd);
418 int class_manual_cleanup(struct obd_device *obd);
419 void class_disconnect_stale_exports(struct obd_device *,
420 int (*test_export)(struct obd_export *));
422 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
424 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
425 (obd->obd_force ? OBD_OPT_FORCE : 0) |
426 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
430 #ifdef HAVE_SERVER_SUPPORT
431 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
433 struct obd_device_target *obt;
435 LASSERT(exp->exp_obd);
436 obt = (void *)&exp->exp_obd->u;
437 if (obt->obt_magic != OBT_MAGIC)
442 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
444 struct obd_device_target *obt = obd2obt(obd);
447 return &obt->obt_lut->lut_lsd;
455 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
456 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
458 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
459 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
461 static inline int obd_check_dev(struct obd_device *obd)
464 CERROR("NULL device\n");
470 /* ensure obd_setup and !obd_stopping */
471 #define OBD_CHECK_DEV_ACTIVE(obd) \
473 rc = obd_check_dev(obd); \
477 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
478 CERROR("Device %d not setup\n", \
485 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
487 /* Always add in ldlm_stats */
488 tmp->nid_ldlm_stats =
489 lprocfs_stats_alloc(LDLM_LAST_OPC - LDLM_FIRST_OPC,
490 LPROCFS_STATS_FLAG_NOPERCPU);
491 if (tmp->nid_ldlm_stats == NULL)
494 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
496 return lprocfs_stats_register(tmp->nid_proc, "ldlm_stats",
497 tmp->nid_ldlm_stats);
500 static inline int exp_check_ops(struct obd_export *exp)
505 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
511 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
512 __u32 keylen, void *key,
513 __u32 *vallen, void *val)
519 rc = exp_check_ops(exp);
523 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
524 CERROR("%s: no %s operation\n",
525 (exp)->exp_obd->obd_name, __func__);
529 rc = exp->exp_obd->obd_type->typ_dt_ops->o_get_info(env, exp, keylen,
534 static inline int obd_set_info_async(const struct lu_env *env,
535 struct obd_export *exp,
536 __u32 keylen, void *key,
537 __u32 vallen, void *val,
538 struct ptlrpc_request_set *set)
544 rc = exp_check_ops(exp);
548 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
549 CERROR("%s: no %s operation\n",
550 (exp)->exp_obd->obd_name, __func__);
554 rc = exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async(env, exp,
563 * obd-lu integration.
565 * Functionality is being moved into new lu_device-based layering, but some
566 * pieces of configuration process are still based on obd devices.
568 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
569 * subsume ->o_setup() methods of obd devices they replace. The same for
570 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
571 * result, obd_setup() and obd_process_config() branch and call one XOR
574 * Yet neither lu_device_type_operations::ldto_device_fini() nor
575 * lu_device_type_operations::ldto_device_free() fully implement the
576 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
577 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
579 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
582 struct obd_type *type = obd->obd_type;
583 struct lu_device_type *ldt;
587 wait_var_event(&type->typ_lu,
588 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
591 struct lu_context session_ctx;
594 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
595 session_ctx.lc_thread = NULL;
596 lu_context_enter(&session_ctx);
598 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
600 struct lu_device *dev;
601 env.le_ses = &session_ctx;
602 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
605 obd->obd_lu_dev = dev;
607 #ifdef HAVE_SERVER_SUPPORT
608 if (lu_device_is_dt(dev) &&
609 lu2dt_dev(dev)->dd_rdonly)
610 obd->obd_read_only = 1;
616 lu_context_exit(&session_ctx);
617 lu_context_fini(&session_ctx);
619 if (!obd->obd_type->typ_dt_ops->o_setup) {
620 CERROR("%s: no %s operation\n", obd->obd_name,
624 rc = obd->obd_type->typ_dt_ops->o_setup(obd, cfg);
629 static inline int obd_precleanup(struct obd_device *obd)
632 struct lu_device_type *ldt = obd->obd_type->typ_lu;
633 struct lu_device *d = obd->obd_lu_dev;
637 if (ldt != NULL && d != NULL) {
638 struct lu_env *env = lu_env_find();
643 rc = lu_env_init(env, ldt->ldt_ctx_tags);
647 ldt->ldt_ops->ldto_device_fini(env, d);
654 if (!obd->obd_type->typ_dt_ops->o_precleanup)
657 rc = obd->obd_type->typ_dt_ops->o_precleanup(obd);
661 static inline int obd_cleanup(struct obd_device *obd)
664 struct lu_device_type *ldt = obd->obd_type->typ_lu;
665 struct lu_device *d = obd->obd_lu_dev;
668 if (ldt != NULL && d != NULL) {
671 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
673 ldt->ldt_ops->ldto_device_free(&env, d);
675 obd->obd_lu_dev = NULL;
678 if (!obd->obd_type->typ_dt_ops->o_cleanup)
681 rc = obd->obd_type->typ_dt_ops->o_cleanup(obd);
685 static inline void obd_cleanup_client_import(struct obd_device *obd)
689 /* If we set up but never connected, the client import will not
692 down_write(&obd->u.cli.cl_sem);
693 if (obd->u.cli.cl_import) {
694 struct obd_import *imp;
696 imp = obd->u.cli.cl_import;
697 CDEBUG(D_CONFIG, "%s: client import never connected\n",
699 ptlrpc_invalidate_import(imp);
700 client_destroy_import(imp);
701 obd->u.cli.cl_import = NULL;
703 up_write(&obd->u.cli.cl_sem);
708 static inline int obd_process_config(struct obd_device *obd, int datalen,
712 struct lu_device_type *ldt = obd->obd_type->typ_lu;
713 struct lu_device *d = obd->obd_lu_dev;
717 obd->obd_process_conf = 1;
718 if (ldt != NULL && d != NULL) {
721 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
723 rc = d->ld_ops->ldo_process_config(&env, d, data);
727 if (!obd->obd_type->typ_dt_ops->o_process_config) {
728 CERROR("%s: no %s operation\n",
729 obd->obd_name, __func__);
732 rc = obd->obd_type->typ_dt_ops->o_process_config(obd, datalen,
736 obd->obd_process_conf = 0;
741 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
748 rc = exp_check_ops(exp);
752 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
753 CERROR("%s: no %s operation\n",
754 (exp)->exp_obd->obd_name, __func__);
758 rc = exp->exp_obd->obd_type->typ_dt_ops->o_create(env, exp, obdo);
762 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
769 rc = exp_check_ops(exp);
773 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
774 CERROR("%s: no %s operation\n",
775 (exp)->exp_obd->obd_name, __func__);
779 rc = exp->exp_obd->obd_type->typ_dt_ops->o_destroy(env, exp, obdo);
783 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
789 rc = exp_check_ops(exp);
793 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
794 CERROR("%s: no %s operation\n",
795 (exp)->exp_obd->obd_name, __func__);
799 rc = exp->exp_obd->obd_type->typ_dt_ops->o_getattr(env, exp, oa);
804 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
810 rc = exp_check_ops(exp);
814 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
815 CERROR("%s: no %s operation\n",
816 (exp)->exp_obd->obd_name, __func__);
820 rc = exp->exp_obd->obd_type->typ_dt_ops->o_setattr(env, exp, oa);
825 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
828 struct obd_device *obd = imp->imp_obd;
833 OBD_CHECK_DEV_ACTIVE(obd);
834 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
835 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
839 rc = obd->obd_type->typ_dt_ops->o_add_conn(imp, uuid, priority);
843 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
845 struct obd_device *obd = imp->imp_obd;
850 OBD_CHECK_DEV_ACTIVE(obd);
851 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
852 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
856 rc = obd->obd_type->typ_dt_ops->o_del_conn(imp, uuid);
860 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
862 struct obd_uuid *uuid;
866 if (!exp->exp_obd->obd_type ||
867 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
870 uuid = exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid(exp);
874 /** Create a new /a exp on device /a obd for the uuid /a cluuid
875 * @param exp New export handle
876 * @param d Connect data, supported flags are set, flags also understood
877 * by obd are returned.
879 static inline int obd_connect(const struct lu_env *env,
880 struct obd_export **exp, struct obd_device *obd,
881 struct obd_uuid *cluuid,
882 struct obd_connect_data *data,
886 __u64 ocf = data ? data->ocd_connect_flags : 0;
890 OBD_CHECK_DEV_ACTIVE(obd);
891 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
892 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
896 rc = obd->obd_type->typ_dt_ops->o_connect(env, exp, obd, cluuid, data,
898 /* check that only subset is granted */
899 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
900 data->ocd_connect_flags));
904 static inline int obd_reconnect(const struct lu_env *env,
905 struct obd_export *exp,
906 struct obd_device *obd,
907 struct obd_uuid *cluuid,
908 struct obd_connect_data *d,
912 __u64 ocf = d ? d->ocd_connect_flags : 0;
916 OBD_CHECK_DEV_ACTIVE(obd);
917 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
920 rc = obd->obd_type->typ_dt_ops->o_reconnect(env, exp, obd, cluuid, d,
922 /* check that only subset is granted */
923 LASSERT(ergo(d != NULL,
924 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
928 static inline int obd_disconnect(struct obd_export *exp)
933 rc = exp_check_ops(exp);
937 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
938 CERROR("%s: no %s operation\n",
939 (exp)->exp_obd->obd_name, __func__);
943 rc = exp->exp_obd->obd_type->typ_dt_ops->o_disconnect(exp);
947 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
948 enum lu_cli_type type)
954 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
957 rc = obd->obd_type->typ_dt_ops->o_fid_init(obd, exp, type);
961 static inline int obd_fid_fini(struct obd_device *obd)
966 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
969 rc = obd->obd_type->typ_dt_ops->o_fid_fini(obd);
973 static inline int obd_fid_alloc(const struct lu_env *env,
974 struct obd_export *exp,
976 struct md_op_data *op_data)
981 rc = exp_check_ops(exp);
985 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
986 CERROR("%s: no %s operation\n",
987 (exp)->exp_obd->obd_name, __func__);
991 rc = exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc(env, exp, fid,
996 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1002 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
1003 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1004 RETURN(-EOPNOTSUPP);
1007 /* Check poolname validity */
1008 if (!poolname || poolname[0] == '\0' || lov_pool_is_reserved(poolname))
1011 rc = obd->obd_type->typ_dt_ops->o_pool_new(obd, poolname);
1015 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1020 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
1021 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1022 RETURN(-EOPNOTSUPP);
1025 rc = obd->obd_type->typ_dt_ops->o_pool_del(obd, poolname);
1029 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1036 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1037 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1038 RETURN(-EOPNOTSUPP);
1041 rc = obd->obd_type->typ_dt_ops->o_pool_add(obd, poolname, ostname);
1045 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1051 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1052 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1053 RETURN(-EOPNOTSUPP);
1056 rc = obd->obd_type->typ_dt_ops->o_pool_rem(obd, poolname, ostname);
1060 static inline int obd_init_export(struct obd_export *exp)
1065 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1066 exp->exp_obd->obd_type->typ_dt_ops->o_init_export)
1067 rc = exp->exp_obd->obd_type->typ_dt_ops->o_init_export(exp);
1071 static inline int obd_destroy_export(struct obd_export *exp)
1074 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1075 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export)
1076 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export(exp);
1080 /* @max_age is the oldest time in seconds that we accept using a cached data.
1081 * If the cache is older than @max_age we will get a new value from the
1082 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1084 static inline int obd_statfs_async(struct obd_export *exp,
1085 struct obd_info *oinfo,
1087 struct ptlrpc_request_set *rqset)
1089 struct obd_device *obd;
1094 if (exp == NULL || exp->exp_obd == NULL)
1098 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1100 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1104 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1105 obd->obd_name, obd->obd_osfs_age, max_age);
1106 rc = obd->obd_type->typ_dt_ops->o_statfs_async(exp, oinfo, max_age,
1112 /* @max_age is the oldest time in seconds that we accept using a cached data.
1113 * If the cache is older than @max_age we will get a new value from the
1114 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1116 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1117 struct obd_statfs *osfs, time64_t max_age,
1120 struct obd_device *obd;
1124 if (unlikely(exp == NULL || exp->exp_obd == NULL))
1128 OBD_CHECK_DEV_ACTIVE(obd);
1130 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1131 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1132 RETURN(-EOPNOTSUPP);
1135 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1136 obd->obd_name, obd->obd_osfs_age, max_age);
1137 /* ignore cache if aggregated isn't expected */
1138 if (obd->obd_osfs_age < max_age ||
1139 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1140 !(flags & OBD_STATFS_SUM))) {
1141 /* the RPC will block anyway, so avoid sending many at once */
1142 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1143 (flags & OBD_STATFS_NESTED)
1144 ? SINGLE_DEPTH_NESTING : 0);
1147 if (obd->obd_osfs_age < max_age ||
1148 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1149 !(flags & OBD_STATFS_SUM))) {
1150 rc = obd->obd_type->typ_dt_ops->o_statfs(env, exp, osfs,
1154 mutex_unlock(&obd->obd_dev_mutex);
1155 GOTO(cached, rc = 0);
1159 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1160 obd->obd_name, &obd->obd_osfs,
1161 osfs->os_bavail, osfs->os_blocks,
1162 osfs->os_ffree, osfs->os_files);
1164 spin_lock(&obd->obd_osfs_lock);
1165 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1166 obd->obd_osfs_age = ktime_get_seconds();
1167 spin_unlock(&obd->obd_osfs_lock);
1169 mutex_unlock(&obd->obd_dev_mutex);
1173 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1174 obd->obd_name, &obd->obd_osfs,
1175 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1176 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1177 spin_lock(&obd->obd_osfs_lock);
1178 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1179 spin_unlock(&obd->obd_osfs_lock);
1184 static inline int obd_preprw(const struct lu_env *env, int cmd,
1185 struct obd_export *exp, struct obdo *oa,
1186 int objcount, struct obd_ioobj *obj,
1187 struct niobuf_remote *remote, int *pages,
1188 struct niobuf_local *local)
1194 rc = exp_check_ops(exp);
1198 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1199 CERROR("%s: no %s operation\n",
1200 (exp)->exp_obd->obd_name, __func__);
1204 rc = exp->exp_obd->obd_type->typ_dt_ops->o_preprw(env, cmd, exp,
1206 remote, pages, local);
1211 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1212 struct obd_export *exp, struct obdo *oa,
1213 int objcount, struct obd_ioobj *obj,
1214 struct niobuf_remote *rnb, int pages,
1215 struct niobuf_local *local, const int orig_rc,
1216 int nob, ktime_t kstart)
1222 rc = exp_check_ops(exp);
1226 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1227 CERROR("%s: no %s operation\n",
1228 (exp)->exp_obd->obd_name, __func__);
1232 rc = exp->exp_obd->obd_type->typ_dt_ops->o_commitrw(env, cmd, exp, oa,
1241 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1242 int len, void *karg, void __user *uarg)
1248 rc = exp_check_ops(exp);
1252 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1253 CERROR("%s: no %s operation\n",
1254 (exp)->exp_obd->obd_name, __func__);
1258 rc = exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol(cmd, exp,
1264 static inline void obd_import_event(struct obd_device *obd,
1265 struct obd_import *imp,
1266 enum obd_import_event event)
1270 CERROR("NULL device\n");
1275 if (obd->obd_set_up && obd->obd_type->typ_dt_ops->o_import_event)
1276 obd->obd_type->typ_dt_ops->o_import_event(obd, imp, event);
1281 static inline int obd_notify(struct obd_device *obd,
1282 struct obd_device *watched,
1283 enum obd_notify_event ev)
1289 rc = obd_check_dev(obd);
1293 if (!obd->obd_set_up) {
1294 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1298 if (!obd->obd_type->typ_dt_ops->o_notify) {
1299 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1303 rc = obd->obd_type->typ_dt_ops->o_notify(obd, watched, ev);
1308 static inline int obd_notify_observer(struct obd_device *observer,
1309 struct obd_device *observed,
1310 enum obd_notify_event ev)
1314 struct obd_notify_upcall *onu;
1316 if (WARN_ON_ONCE(!observer))
1319 if (observer->obd_observer)
1320 rc = obd_notify(observer->obd_observer, observed, ev);
1323 * Also, call non-obd listener, if any
1325 onu = &observer->obd_upcall;
1326 if (onu->onu_upcall != NULL)
1327 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1329 return rc ? rc : rc2;
1332 static inline int obd_quotactl(struct obd_export *exp,
1333 struct obd_quotactl *oqctl)
1339 rc = exp_check_ops(exp);
1343 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1344 CERROR("%s: no %s operation\n",
1345 (exp)->exp_obd->obd_name, __func__);
1349 rc = exp->exp_obd->obd_type->typ_dt_ops->o_quotactl(exp->exp_obd,
1354 static inline int obd_quota_iter(struct obd_export *exp,
1355 struct obd_quotactl *oqctl,
1356 struct list_head *list)
1361 oqctl->qc_iter_list = (__u64)list;
1362 rc = obd_quotactl(exp, oqctl);
1366 } while (oqctl->qc_iter_md_offset || oqctl->qc_iter_dt_offset);
1371 static inline int obd_health_check(const struct lu_env *env,
1372 struct obd_device *obd)
1374 /* returns: 0 on healthy
1375 * >0 on unhealthy + reason code/flag
1376 * however the only suppored reason == 1 right now
1377 * We'll need to define some better reasons
1378 * or flags in the future.
1385 /* NULL method is normal here */
1386 if (obd == NULL || !obd->obd_type) {
1387 CERROR("cleaned up obd\n");
1388 RETURN(-EOPNOTSUPP);
1390 if (!obd->obd_set_up || obd->obd_stopping)
1392 if (!obd->obd_type->typ_dt_ops->o_health_check)
1395 rc = obd->obd_type->typ_dt_ops->o_health_check(env, obd);
1399 static inline int obd_register_observer(struct obd_device *obd,
1400 struct obd_device *observer)
1406 rc = obd_check_dev(obd);
1410 down_write(&obd->obd_observer_link_sem);
1411 if (obd->obd_observer && observer) {
1412 up_write(&obd->obd_observer_link_sem);
1415 obd->obd_observer = observer;
1416 up_write(&obd->obd_observer_link_sem);
1420 /* metadata helpers */
1426 LPROC_MD_INTENT_LOCK,
1435 LPROC_MD_INTENT_GETATTR_ASYNC,
1436 LPROC_MD_REVALIDATE_LOCK,
1440 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1445 rc = exp_check_ops(exp);
1449 return exp->exp_obd->obd_type->typ_md_ops->m_get_root(exp, fileset,
1453 static inline int md_getattr(struct obd_export *exp,
1454 struct md_op_data *op_data,
1455 struct ptlrpc_request **request)
1459 rc = exp_check_ops(exp);
1463 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1466 return exp->exp_obd->obd_type->typ_md_ops->m_getattr(exp, op_data,
1470 static inline int md_null_inode(struct obd_export *exp,
1471 const struct lu_fid *fid)
1475 rc = exp_check_ops(exp);
1479 return exp->exp_obd->obd_type->typ_md_ops->m_null_inode(exp, fid);
1482 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1483 struct md_open_data *mod,
1484 struct ptlrpc_request **request)
1488 rc = exp_check_ops(exp);
1492 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1495 return exp->exp_obd->obd_type->typ_md_ops->m_close(exp, op_data, mod,
1499 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1500 const void *data, size_t datalen, umode_t mode,
1501 uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1502 __u64 rdev, struct ptlrpc_request **request)
1506 rc = exp_check_ops(exp);
1510 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1513 return exp->exp_obd->obd_type->typ_md_ops->m_create(exp, op_data, data,
1519 static inline int md_enqueue(struct obd_export *exp,
1520 struct ldlm_enqueue_info *einfo,
1521 const union ldlm_policy_data *policy,
1522 struct md_op_data *op_data,
1523 struct lustre_handle *lockh,
1524 __u64 extra_lock_flags)
1528 rc = exp_check_ops(exp);
1532 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1535 return exp->exp_obd->obd_type->typ_md_ops->m_enqueue(exp, einfo, policy,
1540 static inline int md_getattr_name(struct obd_export *exp,
1541 struct md_op_data *op_data,
1542 struct ptlrpc_request **request)
1546 rc = exp_check_ops(exp);
1550 return exp->exp_obd->obd_type->typ_md_ops->m_getattr_name(exp, op_data,
1554 static inline int md_intent_lock(struct obd_export *exp,
1555 struct md_op_data *op_data,
1556 struct lookup_intent *it,
1557 struct ptlrpc_request **reqp,
1558 ldlm_blocking_callback cb_blocking,
1559 __u64 extra_lock_flags)
1563 rc = exp_check_ops(exp);
1567 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1568 LPROC_MD_INTENT_LOCK);
1570 return exp->exp_obd->obd_type->typ_md_ops->m_intent_lock(exp, op_data,
1576 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1577 struct ptlrpc_request **request)
1581 rc = exp_check_ops(exp);
1585 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1588 return exp->exp_obd->obd_type->typ_md_ops->m_link(exp, op_data,
1592 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1593 const char *old_name, size_t oldlen,
1594 const char *new_name, size_t newlen,
1595 struct ptlrpc_request **request)
1599 rc = exp_check_ops(exp);
1603 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1606 return exp->exp_obd->obd_type->typ_md_ops->m_rename(exp, op_data,
1612 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1613 void *ea, size_t ealen,
1614 struct ptlrpc_request **request)
1618 rc = exp_check_ops(exp);
1622 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1625 return exp->exp_obd->obd_type->typ_md_ops->m_setattr(exp, op_data, ea,
1629 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1630 struct ptlrpc_request **request)
1634 rc = exp_check_ops(exp);
1638 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1641 return exp->exp_obd->obd_type->typ_md_ops->m_fsync(exp, fid, request);
1644 /* FLR: resync mirrored files. */
1645 static inline int md_file_resync(struct obd_export *exp,
1646 struct md_op_data *data)
1650 rc = exp_check_ops(exp);
1654 return exp->exp_obd->obd_type->typ_md_ops->m_file_resync(exp, data);
1657 static inline int md_read_page(struct obd_export *exp,
1658 struct md_op_data *op_data,
1659 struct md_readdir_info *mrinfo,
1660 __u64 hash_offset, struct page **ppage)
1664 rc = exp_check_ops(exp);
1668 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1669 LPROC_MD_READ_PAGE);
1671 return exp->exp_obd->obd_type->typ_md_ops->m_read_page(exp, op_data,
1677 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1678 struct ptlrpc_request **request)
1682 rc = exp_check_ops(exp);
1686 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1689 return exp->exp_obd->obd_type->typ_md_ops->m_unlink(exp, op_data,
1693 static inline int md_get_lustre_md(struct obd_export *exp,
1694 struct req_capsule *pill,
1695 struct obd_export *dt_exp,
1696 struct obd_export *md_exp,
1697 struct lustre_md *md)
1701 rc = exp_check_ops(exp);
1705 return exp->exp_obd->obd_type->typ_md_ops->m_get_lustre_md(exp, pill,
1710 static inline int md_put_lustre_md(struct obd_export *exp,
1711 struct lustre_md *md)
1715 rc = exp_check_ops(exp);
1719 return exp->exp_obd->obd_type->typ_md_ops->m_put_lustre_md(exp, md);
1722 static inline int md_merge_attr(struct obd_export *exp,
1723 const struct lmv_stripe_object *lso,
1724 struct cl_attr *attr,
1725 ldlm_blocking_callback cb)
1729 rc = exp_check_ops(exp);
1733 return exp->exp_obd->obd_type->typ_md_ops->m_merge_attr(exp, lso, attr,
1737 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1738 u64 obd_md_valid, const char *name,
1739 const void *value, size_t value_size,
1740 unsigned int xattr_flags, u32 suppgid,
1741 struct ptlrpc_request **req)
1745 rc = exp_check_ops(exp);
1749 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1752 return exp->exp_obd->obd_type->typ_md_ops->m_setxattr(exp, fid,
1761 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1762 u64 obd_md_valid, const char *name,
1763 size_t buf_size, struct ptlrpc_request **req)
1767 rc = exp_check_ops(exp);
1771 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1774 return exp->exp_obd->obd_type->typ_md_ops->m_getxattr(exp, fid,
1780 static inline int md_set_open_replay_data(struct obd_export *exp,
1781 struct obd_client_handle *och,
1782 struct lookup_intent *it)
1786 rc = exp_check_ops(exp);
1790 return exp->exp_obd->obd_type->typ_md_ops->m_set_open_replay_data(exp,
1795 static inline int md_clear_open_replay_data(struct obd_export *exp,
1796 struct obd_client_handle *och)
1800 rc = exp_check_ops(exp);
1804 return exp->exp_obd->obd_type->typ_md_ops->m_clear_open_replay_data(exp, och);
1807 static inline int md_set_lock_data(struct obd_export *exp,
1808 const struct lustre_handle *lockh,
1809 void *data, __u64 *bits)
1813 rc = exp_check_ops(exp);
1817 return exp->exp_obd->obd_type->typ_md_ops->m_set_lock_data(exp, lockh,
1823 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1824 union ldlm_policy_data *policy, enum ldlm_mode mode,
1825 enum ldlm_cancel_flags cancel_flags, void *opaque)
1829 rc = exp_check_ops(exp);
1833 return exp->exp_obd->obd_type->typ_md_ops->m_cancel_unused(exp,
1840 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1841 const struct lu_fid *fid,
1842 enum ldlm_type type,
1843 union ldlm_policy_data *policy,
1844 enum ldlm_mode mode,
1845 struct lustre_handle *lockh)
1849 rc = exp_check_ops(exp);
1853 return exp->exp_obd->obd_type->typ_md_ops->m_lock_match(exp, flags,
1859 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1864 rc = exp_check_ops(exp);
1868 return exp->exp_obd->obd_type->typ_md_ops->m_init_ea_size(exp, ea_size,
1872 static inline int md_intent_getattr_async(struct obd_export *exp,
1873 struct md_op_item *item)
1877 rc = exp_check_ops(exp);
1881 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1882 LPROC_MD_INTENT_GETATTR_ASYNC);
1884 return exp->exp_obd->obd_type->typ_md_ops->m_intent_getattr_async(exp,
1888 static inline int md_revalidate_lock(struct obd_export *exp,
1889 struct lookup_intent *it,
1890 struct lu_fid *fid, __u64 *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 */