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 sptlrpc_pool_init(void);
151 void sptlrpc_pool_fini(void);
152 int encrypt_page_pools_seq_show(struct seq_file *m, void *v);
153 int page_pools_seq_show(struct seq_file *m, void *v);
155 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
156 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
160 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
161 struct llog_rec_hdr *, void *);
163 struct obd_export *obd_stale_export_get(void);
164 void obd_stale_export_put(struct obd_export *exp);
165 void obd_stale_export_adjust(struct obd_export *exp);
168 /* For interoperability */
169 struct cfg_interop_param {
174 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
175 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
176 const char *new_name);
177 void print_lustre_cfg(struct lustre_cfg *lcfg);
178 int class_process_config(struct lustre_cfg *lcfg);
179 ssize_t class_set_global(const char *param);
180 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
181 struct kobject *kobj);
182 int class_attach(struct lustre_cfg *lcfg);
183 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
184 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
185 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
187 int class_find_param(char *buf, char *key, char **valp);
188 struct cfg_interop_param *class_find_old_param(const char *param,
189 struct cfg_interop_param *ptr);
190 int class_get_next_param(char **params, char *copy);
191 int class_match_param(char *buf, const char *key, char **valp);
192 int class_parse_nid(char *buf, struct lnet_nid *nid, char **endh);
193 int class_parse_nid_quiet(char *buf, struct lnet_nid *nid, char **endh);
194 int class_parse_net(char *buf, u32 *net, char **endh);
195 int class_match_nid(char *buf, char *key, struct lnet_nid *nid);
196 int class_match_net(char *buf, char *key, u32 net);
198 struct obd_device *class_incref(struct obd_device *obd,
199 const char *scope, const void *source);
200 void class_decref(struct obd_device *obd,
201 const char *scope, const void *source);
202 void dump_exports(struct obd_device *obd, int locks, int debug_level);
203 int class_config_llog_handler(const struct lu_env *env,
204 struct llog_handle *handle,
205 struct llog_rec_hdr *rec, void *data);
206 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
208 #define CFG_F_START 0x01 /* Set when we start updating from a log */
209 #define CFG_F_MARKER 0x02 /* We are within a maker */
210 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
211 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
213 /* Passed as data param to class_config_parse_llog */
214 struct config_llog_instance {
215 unsigned long cfg_instance;
216 struct super_block *cfg_sb;
217 struct obd_uuid cfg_uuid;
218 llog_cb_t cfg_callback;
219 int cfg_last_idx; /* for partial llog processing */
224 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
225 char *name, struct config_llog_instance *cfg);
228 * Generate a unique configuration instance for this mount
230 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
231 * For now, use the same value as before - the superblock pointer value.
233 * Using the client UUID would be an option, but it needs more testing.
235 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
237 return (unsigned long)sb;
240 #define CONFIG_SUB_SPTLRPC 0x01
241 #define CONFIG_SUB_RECOVER 0x02
242 #define CONFIG_SUB_PARAMS 0x04
243 #define CONFIG_SUB_NODEMAP 0x08
244 #define CONFIG_SUB_BARRIER 0x10
246 /* Sub clds should be attached to the config_llog_data when processing
247 * config log for client or server target. */
248 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
250 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
253 #define PARAMS_FILENAME "params"
254 #define BARRIER_FILENAME "barrier"
255 #define LCTL_UPCALL "lctl"
257 static inline bool logname_is_barrier(const char *logname)
261 /* logname for barrier is "fsname-barrier" */
262 ptr = strstr(logname, BARRIER_FILENAME);
263 if (ptr && (ptr - logname) >= 2 &&
264 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
270 /* list of active configuration logs */
271 struct config_llog_data {
272 struct ldlm_res_id cld_resid;
273 struct lustre_handle cld_lockh;
274 struct config_llog_instance cld_cfg;
275 struct list_head cld_list_chain;/* on config_llog_list */
276 refcount_t cld_refcount;
277 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
278 struct config_llog_data *cld_params; /* common parameters log */
279 struct config_llog_data *cld_recover;/* imperative recover log */
280 struct config_llog_data *cld_nodemap;/* nodemap log */
281 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
282 struct obd_export *cld_mgcexp;
283 struct mutex cld_lock;
284 enum mgs_cfg_type cld_type;
285 unsigned int cld_stopping:1, /* we were told to stop
287 cld_lostlock:1, /* lock not requeued */
288 cld_processed:1; /* successfully fetched */
292 struct lustre_profile {
293 struct list_head lp_list;
298 bool lp_list_deleted;
301 struct lustre_profile *class_get_profile(const char * prof);
302 void class_del_profile(const char *prof);
303 void class_put_profile(struct lustre_profile *lprof);
304 void class_del_profiles(void);
307 #if LUSTRE_TRACKS_LOCK_EXP_REFS
309 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
310 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
311 extern void (*class_export_dump_hook)(struct obd_export *);
315 #define __class_export_add_lock_ref(exp, lock) do {} while (0)
316 #define __class_export_del_lock_ref(exp, lock) do {} while (0)
320 #define class_export_rpc_inc(exp) \
322 atomic_inc(&(exp)->exp_rpc_count); \
323 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
324 (exp), atomic_read(&(exp)->exp_rpc_count)); \
327 #define class_export_rpc_dec(exp) \
329 LASSERT(atomic_read(&(exp)->exp_rpc_count) > 0); \
330 atomic_dec(&(exp)->exp_rpc_count); \
331 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
332 (exp), atomic_read(&(exp)->exp_rpc_count)); \
335 #define class_export_lock_get(exp, lock) \
337 atomic_inc(&(exp)->exp_locks_count); \
338 __class_export_add_lock_ref(exp, lock); \
339 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
340 (exp), atomic_read(&(exp)->exp_locks_count)); \
341 class_export_get(exp); \
344 #define class_export_lock_put(exp, lock) \
346 LASSERT(atomic_read(&(exp)->exp_locks_count) > 0); \
347 atomic_dec(&(exp)->exp_locks_count); \
348 __class_export_del_lock_ref(exp, lock); \
349 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
350 (exp), atomic_read(&(exp)->exp_locks_count)); \
351 class_export_put(exp); \
354 #define class_export_cb_get(exp) \
356 atomic_inc(&(exp)->exp_cb_count); \
357 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
358 (exp), atomic_read(&(exp)->exp_cb_count)); \
359 class_export_get(exp); \
362 #define class_export_cb_put(exp) \
364 LASSERT(atomic_read(&(exp)->exp_cb_count) > 0); \
365 atomic_dec(&(exp)->exp_cb_count); \
366 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
367 (exp), atomic_read(&(exp)->exp_cb_count)); \
368 class_export_put(exp); \
372 struct obd_export *class_export_get(struct obd_export *exp);
373 void class_export_put(struct obd_export *exp);
374 struct obd_export *class_new_export(struct obd_device *obd,
375 struct obd_uuid *cluuid);
376 struct obd_export *class_new_export_self(struct obd_device *obd,
377 struct obd_uuid *uuid);
378 void class_unlink_export(struct obd_export *exp);
380 struct obd_import *class_import_get(struct obd_import *);
381 void class_import_put(struct obd_import *);
382 struct obd_import *class_new_import(struct obd_device *obd);
383 void class_destroy_import(struct obd_import *exp);
385 #ifdef HAVE_SERVER_SUPPORT
386 struct obd_type *class_search_type(const char *name);
387 struct obd_type *class_get_type(const char *name);
389 void class_put_type(struct obd_type *type);
390 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
391 struct obd_uuid *cluuid);
392 int class_disconnect(struct obd_export *exp);
393 void class_fail_export(struct obd_export *exp);
394 int class_connected_export(struct obd_export *exp);
395 void class_disconnect_exports(struct obd_device *obd);
396 int class_manual_cleanup(struct obd_device *obd);
397 void class_disconnect_stale_exports(struct obd_device *,
398 int (*test_export)(struct obd_export *));
400 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
402 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
403 (obd->obd_force ? OBD_OPT_FORCE : 0) |
404 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
408 #ifdef HAVE_SERVER_SUPPORT
409 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
411 struct obd_device_target *obt;
413 LASSERT(exp->exp_obd);
414 obt = (void *)&exp->exp_obd->u;
415 if (obt->obt_magic != OBT_MAGIC)
420 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
422 struct obd_device_target *obt = obd2obt(obd);
425 return &obt->obt_lut->lut_lsd;
433 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
434 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
436 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
437 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
439 static inline int obd_check_dev(struct obd_device *obd)
442 CERROR("NULL device\n");
448 /* ensure obd_setup and !obd_stopping */
449 #define OBD_CHECK_DEV_ACTIVE(obd) \
451 rc = obd_check_dev(obd); \
455 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
456 CERROR("Device %d not setup\n", \
463 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
465 /* Always add in ldlm_stats */
466 tmp->nid_ldlm_stats =
467 lprocfs_stats_alloc(LDLM_LAST_OPC - LDLM_FIRST_OPC,
468 LPROCFS_STATS_FLAG_NOPERCPU);
469 if (tmp->nid_ldlm_stats == NULL)
472 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
474 return lprocfs_stats_register(tmp->nid_proc, "ldlm_stats",
475 tmp->nid_ldlm_stats);
478 static inline int exp_check_ops(struct obd_export *exp)
483 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
489 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
490 __u32 keylen, void *key,
491 __u32 *vallen, void *val)
497 rc = exp_check_ops(exp);
501 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
502 CERROR("%s: no %s operation\n",
503 (exp)->exp_obd->obd_name, __func__);
507 rc = exp->exp_obd->obd_type->typ_dt_ops->o_get_info(env, exp, keylen,
512 static inline int obd_set_info_async(const struct lu_env *env,
513 struct obd_export *exp,
514 __u32 keylen, void *key,
515 __u32 vallen, void *val,
516 struct ptlrpc_request_set *set)
522 rc = exp_check_ops(exp);
526 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
527 CERROR("%s: no %s operation\n",
528 (exp)->exp_obd->obd_name, __func__);
532 rc = exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async(env, exp,
541 * obd-lu integration.
543 * Functionality is being moved into new lu_device-based layering, but some
544 * pieces of configuration process are still based on obd devices.
546 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
547 * subsume ->o_setup() methods of obd devices they replace. The same for
548 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
549 * result, obd_setup() and obd_process_config() branch and call one XOR
552 * Yet neither lu_device_type_operations::ldto_device_fini() nor
553 * lu_device_type_operations::ldto_device_free() fully implement the
554 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
555 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
557 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
560 struct obd_type *type = obd->obd_type;
561 struct lu_device_type *ldt;
565 wait_var_event(&type->typ_lu,
566 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
569 struct lu_context session_ctx;
572 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
573 session_ctx.lc_thread = NULL;
574 lu_context_enter(&session_ctx);
576 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
578 struct lu_device *dev;
579 env.le_ses = &session_ctx;
580 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
583 obd->obd_lu_dev = dev;
585 #ifdef HAVE_SERVER_SUPPORT
586 if (lu_device_is_dt(dev) &&
587 lu2dt_dev(dev)->dd_rdonly)
588 obd->obd_read_only = 1;
594 lu_context_exit(&session_ctx);
595 lu_context_fini(&session_ctx);
597 if (!obd->obd_type->typ_dt_ops->o_setup) {
598 CERROR("%s: no %s operation\n", obd->obd_name,
602 rc = obd->obd_type->typ_dt_ops->o_setup(obd, cfg);
607 static inline int obd_precleanup(struct obd_device *obd)
610 struct lu_device_type *ldt = obd->obd_type->typ_lu;
611 struct lu_device *d = obd->obd_lu_dev;
615 if (ldt != NULL && d != NULL) {
616 struct lu_env *env = lu_env_find();
621 rc = lu_env_init(env, ldt->ldt_ctx_tags);
625 ldt->ldt_ops->ldto_device_fini(env, d);
632 if (!obd->obd_type->typ_dt_ops->o_precleanup)
635 rc = obd->obd_type->typ_dt_ops->o_precleanup(obd);
639 static inline int obd_cleanup(struct obd_device *obd)
642 struct lu_device_type *ldt = obd->obd_type->typ_lu;
643 struct lu_device *d = obd->obd_lu_dev;
646 if (ldt != NULL && d != NULL) {
649 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
651 ldt->ldt_ops->ldto_device_free(&env, d);
653 obd->obd_lu_dev = NULL;
656 if (!obd->obd_type->typ_dt_ops->o_cleanup)
659 rc = obd->obd_type->typ_dt_ops->o_cleanup(obd);
663 static inline void obd_cleanup_client_import(struct obd_device *obd)
667 /* If we set up but never connected, the client import will not
670 down_write(&obd->u.cli.cl_sem);
671 if (obd->u.cli.cl_import) {
672 struct obd_import *imp;
674 imp = obd->u.cli.cl_import;
675 CDEBUG(D_CONFIG, "%s: client import never connected\n",
677 ptlrpc_invalidate_import(imp);
678 client_destroy_import(imp);
679 obd->u.cli.cl_import = NULL;
681 up_write(&obd->u.cli.cl_sem);
686 static inline int obd_process_config(struct obd_device *obd, int datalen,
690 struct lu_device_type *ldt = obd->obd_type->typ_lu;
691 struct lu_device *d = obd->obd_lu_dev;
695 obd->obd_process_conf = 1;
696 if (ldt != NULL && d != NULL) {
699 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
701 rc = d->ld_ops->ldo_process_config(&env, d, data);
705 if (!obd->obd_type->typ_dt_ops->o_process_config) {
706 CERROR("%s: no %s operation\n",
707 obd->obd_name, __func__);
710 rc = obd->obd_type->typ_dt_ops->o_process_config(obd, datalen,
714 obd->obd_process_conf = 0;
719 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
726 rc = exp_check_ops(exp);
730 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
731 CERROR("%s: no %s operation\n",
732 (exp)->exp_obd->obd_name, __func__);
736 rc = exp->exp_obd->obd_type->typ_dt_ops->o_create(env, exp, obdo);
740 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
747 rc = exp_check_ops(exp);
751 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
752 CERROR("%s: no %s operation\n",
753 (exp)->exp_obd->obd_name, __func__);
757 rc = exp->exp_obd->obd_type->typ_dt_ops->o_destroy(env, exp, obdo);
761 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
767 rc = exp_check_ops(exp);
771 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
772 CERROR("%s: no %s operation\n",
773 (exp)->exp_obd->obd_name, __func__);
777 rc = exp->exp_obd->obd_type->typ_dt_ops->o_getattr(env, exp, oa);
782 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
788 rc = exp_check_ops(exp);
792 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
793 CERROR("%s: no %s operation\n",
794 (exp)->exp_obd->obd_name, __func__);
798 rc = exp->exp_obd->obd_type->typ_dt_ops->o_setattr(env, exp, oa);
803 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
806 struct obd_device *obd = imp->imp_obd;
811 OBD_CHECK_DEV_ACTIVE(obd);
812 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
813 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
817 rc = obd->obd_type->typ_dt_ops->o_add_conn(imp, uuid, priority);
821 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
823 struct obd_device *obd = imp->imp_obd;
828 OBD_CHECK_DEV_ACTIVE(obd);
829 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
830 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
834 rc = obd->obd_type->typ_dt_ops->o_del_conn(imp, uuid);
838 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
840 struct obd_uuid *uuid;
844 if (!exp->exp_obd->obd_type ||
845 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
848 uuid = exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid(exp);
852 /** Create a new /a exp on device /a obd for the uuid /a cluuid
853 * @param exp New export handle
854 * @param d Connect data, supported flags are set, flags also understood
855 * by obd are returned.
857 static inline int obd_connect(const struct lu_env *env,
858 struct obd_export **exp, struct obd_device *obd,
859 struct obd_uuid *cluuid,
860 struct obd_connect_data *data,
864 __u64 ocf = data ? data->ocd_connect_flags : 0;
868 OBD_CHECK_DEV_ACTIVE(obd);
869 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
870 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
874 rc = obd->obd_type->typ_dt_ops->o_connect(env, exp, obd, cluuid, data,
876 /* check that only subset is granted */
877 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
878 data->ocd_connect_flags));
882 static inline int obd_reconnect(const struct lu_env *env,
883 struct obd_export *exp,
884 struct obd_device *obd,
885 struct obd_uuid *cluuid,
886 struct obd_connect_data *d,
890 __u64 ocf = d ? d->ocd_connect_flags : 0;
894 OBD_CHECK_DEV_ACTIVE(obd);
895 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
898 rc = obd->obd_type->typ_dt_ops->o_reconnect(env, exp, obd, cluuid, d,
900 /* check that only subset is granted */
901 LASSERT(ergo(d != NULL,
902 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
906 static inline int obd_disconnect(struct obd_export *exp)
911 rc = exp_check_ops(exp);
915 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
916 CERROR("%s: no %s operation\n",
917 (exp)->exp_obd->obd_name, __func__);
921 rc = exp->exp_obd->obd_type->typ_dt_ops->o_disconnect(exp);
925 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
926 enum lu_cli_type type)
932 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
935 rc = obd->obd_type->typ_dt_ops->o_fid_init(obd, exp, type);
939 static inline int obd_fid_fini(struct obd_device *obd)
944 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
947 rc = obd->obd_type->typ_dt_ops->o_fid_fini(obd);
951 static inline int obd_fid_alloc(const struct lu_env *env,
952 struct obd_export *exp,
954 struct md_op_data *op_data)
959 rc = exp_check_ops(exp);
963 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
964 CERROR("%s: no %s operation\n",
965 (exp)->exp_obd->obd_name, __func__);
969 rc = exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc(env, exp, fid,
974 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
980 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
981 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
985 /* Check poolname validity */
986 if (!poolname || poolname[0] == '\0' || lov_pool_is_reserved(poolname))
989 rc = obd->obd_type->typ_dt_ops->o_pool_new(obd, poolname);
993 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
998 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
999 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1000 RETURN(-EOPNOTSUPP);
1003 rc = obd->obd_type->typ_dt_ops->o_pool_del(obd, poolname);
1007 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1014 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1015 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1016 RETURN(-EOPNOTSUPP);
1019 rc = obd->obd_type->typ_dt_ops->o_pool_add(obd, poolname, ostname);
1023 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1029 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1030 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1031 RETURN(-EOPNOTSUPP);
1034 rc = obd->obd_type->typ_dt_ops->o_pool_rem(obd, poolname, ostname);
1038 static inline int obd_init_export(struct obd_export *exp)
1043 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1044 exp->exp_obd->obd_type->typ_dt_ops->o_init_export)
1045 rc = exp->exp_obd->obd_type->typ_dt_ops->o_init_export(exp);
1049 static inline int obd_destroy_export(struct obd_export *exp)
1052 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1053 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export)
1054 exp->exp_obd->obd_type->typ_dt_ops->o_destroy_export(exp);
1058 /* @max_age is the oldest time in seconds that we accept using a cached data.
1059 * If the cache is older than @max_age we will get a new value from the
1060 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1062 static inline int obd_statfs_async(struct obd_export *exp,
1063 struct obd_info *oinfo,
1065 struct ptlrpc_request_set *rqset)
1067 struct obd_device *obd;
1072 if (exp == NULL || exp->exp_obd == NULL)
1076 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1078 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1082 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1083 obd->obd_name, obd->obd_osfs_age, max_age);
1084 rc = obd->obd_type->typ_dt_ops->o_statfs_async(exp, oinfo, max_age,
1090 /* @max_age is the oldest time in seconds that we accept using a cached data.
1091 * If the cache is older than @max_age we will get a new value from the
1092 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1094 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1095 struct obd_statfs *osfs, time64_t max_age,
1098 struct obd_device *obd;
1102 if (unlikely(exp == NULL || exp->exp_obd == NULL))
1106 OBD_CHECK_DEV_ACTIVE(obd);
1108 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1109 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1110 RETURN(-EOPNOTSUPP);
1113 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1114 obd->obd_name, obd->obd_osfs_age, max_age);
1115 /* ignore cache if aggregated isn't expected */
1116 if (obd->obd_osfs_age < max_age ||
1117 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1118 !(flags & OBD_STATFS_SUM))) {
1119 /* the RPC will block anyway, so avoid sending many at once */
1120 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1121 (flags & OBD_STATFS_NESTED)
1122 ? SINGLE_DEPTH_NESTING : 0);
1125 if (obd->obd_osfs_age < max_age ||
1126 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1127 !(flags & OBD_STATFS_SUM))) {
1128 rc = obd->obd_type->typ_dt_ops->o_statfs(env, exp, osfs,
1132 mutex_unlock(&obd->obd_dev_mutex);
1133 GOTO(cached, rc = 0);
1137 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1138 obd->obd_name, &obd->obd_osfs,
1139 osfs->os_bavail, osfs->os_blocks,
1140 osfs->os_ffree, osfs->os_files);
1142 spin_lock(&obd->obd_osfs_lock);
1143 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1144 obd->obd_osfs_age = ktime_get_seconds();
1145 spin_unlock(&obd->obd_osfs_lock);
1147 mutex_unlock(&obd->obd_dev_mutex);
1151 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1152 obd->obd_name, &obd->obd_osfs,
1153 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1154 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1155 spin_lock(&obd->obd_osfs_lock);
1156 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1157 spin_unlock(&obd->obd_osfs_lock);
1162 static inline int obd_preprw(const struct lu_env *env, int cmd,
1163 struct obd_export *exp, struct obdo *oa,
1164 int objcount, struct obd_ioobj *obj,
1165 struct niobuf_remote *remote, int *pages,
1166 struct niobuf_local *local)
1172 rc = exp_check_ops(exp);
1176 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1177 CERROR("%s: no %s operation\n",
1178 (exp)->exp_obd->obd_name, __func__);
1182 rc = exp->exp_obd->obd_type->typ_dt_ops->o_preprw(env, cmd, exp,
1184 remote, pages, local);
1189 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1190 struct obd_export *exp, struct obdo *oa,
1191 int objcount, struct obd_ioobj *obj,
1192 struct niobuf_remote *rnb, int pages,
1193 struct niobuf_local *local, const int orig_rc,
1194 int nob, ktime_t kstart)
1200 rc = exp_check_ops(exp);
1204 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1205 CERROR("%s: no %s operation\n",
1206 (exp)->exp_obd->obd_name, __func__);
1210 rc = exp->exp_obd->obd_type->typ_dt_ops->o_commitrw(env, cmd, exp, oa,
1219 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1220 int len, void *karg, void __user *uarg)
1226 rc = exp_check_ops(exp);
1230 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1231 CERROR("%s: no %s operation\n",
1232 (exp)->exp_obd->obd_name, __func__);
1236 rc = exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol(cmd, exp,
1242 static inline void obd_import_event(struct obd_device *obd,
1243 struct obd_import *imp,
1244 enum obd_import_event event)
1248 CERROR("NULL device\n");
1253 if (obd->obd_set_up && obd->obd_type->typ_dt_ops->o_import_event)
1254 obd->obd_type->typ_dt_ops->o_import_event(obd, imp, event);
1259 static inline int obd_notify(struct obd_device *obd,
1260 struct obd_device *watched,
1261 enum obd_notify_event ev)
1267 rc = obd_check_dev(obd);
1271 if (!obd->obd_set_up) {
1272 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1276 if (!obd->obd_type->typ_dt_ops->o_notify) {
1277 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1281 rc = obd->obd_type->typ_dt_ops->o_notify(obd, watched, ev);
1286 static inline int obd_notify_observer(struct obd_device *observer,
1287 struct obd_device *observed,
1288 enum obd_notify_event ev)
1292 struct obd_notify_upcall *onu;
1294 if (WARN_ON_ONCE(!observer))
1297 if (observer->obd_observer)
1298 rc = obd_notify(observer->obd_observer, observed, ev);
1301 * Also, call non-obd listener, if any
1303 onu = &observer->obd_upcall;
1304 if (onu->onu_upcall != NULL)
1305 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1307 return rc ? rc : rc2;
1310 static inline int obd_quotactl(struct obd_export *exp,
1311 struct obd_quotactl *oqctl)
1317 rc = exp_check_ops(exp);
1321 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1322 CERROR("%s: no %s operation\n",
1323 (exp)->exp_obd->obd_name, __func__);
1327 rc = exp->exp_obd->obd_type->typ_dt_ops->o_quotactl(exp->exp_obd,
1332 static inline int obd_quota_iter(struct obd_export *exp,
1333 struct obd_quotactl *oqctl,
1334 struct list_head *list)
1339 oqctl->qc_iter_list = (__u64)list;
1340 rc = obd_quotactl(exp, oqctl);
1344 } while (oqctl->qc_iter_md_offset || oqctl->qc_iter_dt_offset);
1349 static inline int obd_health_check(const struct lu_env *env,
1350 struct obd_device *obd)
1352 /* returns: 0 on healthy
1353 * >0 on unhealthy + reason code/flag
1354 * however the only suppored reason == 1 right now
1355 * We'll need to define some better reasons
1356 * or flags in the future.
1363 /* NULL method is normal here */
1364 if (obd == NULL || !obd->obd_type) {
1365 CERROR("cleaned up obd\n");
1366 RETURN(-EOPNOTSUPP);
1368 if (!obd->obd_set_up || obd->obd_stopping)
1370 if (!obd->obd_type->typ_dt_ops->o_health_check)
1373 rc = obd->obd_type->typ_dt_ops->o_health_check(env, obd);
1377 static inline int obd_register_observer(struct obd_device *obd,
1378 struct obd_device *observer)
1384 rc = obd_check_dev(obd);
1388 down_write(&obd->obd_observer_link_sem);
1389 if (obd->obd_observer && observer) {
1390 up_write(&obd->obd_observer_link_sem);
1393 obd->obd_observer = observer;
1394 up_write(&obd->obd_observer_link_sem);
1398 /* metadata helpers */
1404 LPROC_MD_INTENT_LOCK,
1413 LPROC_MD_INTENT_GETATTR_ASYNC,
1414 LPROC_MD_REVALIDATE_LOCK,
1418 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1423 rc = exp_check_ops(exp);
1427 return exp->exp_obd->obd_type->typ_md_ops->m_get_root(exp, fileset,
1431 static inline int md_getattr(struct obd_export *exp,
1432 struct md_op_data *op_data,
1433 struct ptlrpc_request **request)
1437 rc = exp_check_ops(exp);
1441 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1444 return exp->exp_obd->obd_type->typ_md_ops->m_getattr(exp, op_data,
1448 static inline int md_null_inode(struct obd_export *exp,
1449 const struct lu_fid *fid)
1453 rc = exp_check_ops(exp);
1457 return exp->exp_obd->obd_type->typ_md_ops->m_null_inode(exp, fid);
1460 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1461 struct md_open_data *mod,
1462 struct ptlrpc_request **request)
1466 rc = exp_check_ops(exp);
1470 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1473 return exp->exp_obd->obd_type->typ_md_ops->m_close(exp, op_data, mod,
1477 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1478 const void *data, size_t datalen, umode_t mode,
1479 uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1480 __u64 rdev, struct ptlrpc_request **request)
1484 rc = exp_check_ops(exp);
1488 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1491 return exp->exp_obd->obd_type->typ_md_ops->m_create(exp, op_data, data,
1497 static inline int md_enqueue(struct obd_export *exp,
1498 struct ldlm_enqueue_info *einfo,
1499 const union ldlm_policy_data *policy,
1500 struct md_op_data *op_data,
1501 struct lustre_handle *lockh,
1502 __u64 extra_lock_flags)
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_enqueue(exp, einfo, policy,
1518 static inline int md_getattr_name(struct obd_export *exp,
1519 struct md_op_data *op_data,
1520 struct ptlrpc_request **request)
1524 rc = exp_check_ops(exp);
1528 return exp->exp_obd->obd_type->typ_md_ops->m_getattr_name(exp, op_data,
1532 static inline int md_intent_lock(struct obd_export *exp,
1533 struct md_op_data *op_data,
1534 struct lookup_intent *it,
1535 struct ptlrpc_request **reqp,
1536 ldlm_blocking_callback cb_blocking,
1537 __u64 extra_lock_flags)
1541 rc = exp_check_ops(exp);
1545 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1546 LPROC_MD_INTENT_LOCK);
1548 return exp->exp_obd->obd_type->typ_md_ops->m_intent_lock(exp, op_data,
1554 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1555 struct ptlrpc_request **request)
1559 rc = exp_check_ops(exp);
1563 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1566 return exp->exp_obd->obd_type->typ_md_ops->m_link(exp, op_data,
1570 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1571 const char *old_name, size_t oldlen,
1572 const char *new_name, size_t newlen,
1573 struct ptlrpc_request **request)
1577 rc = exp_check_ops(exp);
1581 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1584 return exp->exp_obd->obd_type->typ_md_ops->m_rename(exp, op_data,
1590 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1591 void *ea, size_t ealen,
1592 struct ptlrpc_request **request)
1596 rc = exp_check_ops(exp);
1600 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1603 return exp->exp_obd->obd_type->typ_md_ops->m_setattr(exp, op_data, ea,
1607 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1608 struct ptlrpc_request **request)
1612 rc = exp_check_ops(exp);
1616 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1619 return exp->exp_obd->obd_type->typ_md_ops->m_fsync(exp, fid, request);
1622 /* FLR: resync mirrored files. */
1623 static inline int md_file_resync(struct obd_export *exp,
1624 struct md_op_data *data)
1628 rc = exp_check_ops(exp);
1632 return exp->exp_obd->obd_type->typ_md_ops->m_file_resync(exp, data);
1635 static inline int md_read_page(struct obd_export *exp,
1636 struct md_op_data *op_data,
1637 struct md_readdir_info *mrinfo,
1638 __u64 hash_offset, struct page **ppage)
1642 rc = exp_check_ops(exp);
1646 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1647 LPROC_MD_READ_PAGE);
1649 return exp->exp_obd->obd_type->typ_md_ops->m_read_page(exp, op_data,
1655 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1656 struct ptlrpc_request **request)
1660 rc = exp_check_ops(exp);
1664 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1667 return exp->exp_obd->obd_type->typ_md_ops->m_unlink(exp, op_data,
1671 static inline int md_get_lustre_md(struct obd_export *exp,
1672 struct req_capsule *pill,
1673 struct obd_export *dt_exp,
1674 struct obd_export *md_exp,
1675 struct lustre_md *md)
1679 rc = exp_check_ops(exp);
1683 return exp->exp_obd->obd_type->typ_md_ops->m_get_lustre_md(exp, pill,
1688 static inline int md_put_lustre_md(struct obd_export *exp,
1689 struct lustre_md *md)
1693 rc = exp_check_ops(exp);
1697 return exp->exp_obd->obd_type->typ_md_ops->m_put_lustre_md(exp, md);
1700 static inline int md_merge_attr(struct obd_export *exp,
1701 const struct lmv_stripe_object *lso,
1702 struct cl_attr *attr,
1703 ldlm_blocking_callback cb)
1707 rc = exp_check_ops(exp);
1711 return exp->exp_obd->obd_type->typ_md_ops->m_merge_attr(exp, lso, attr,
1715 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1716 u64 obd_md_valid, const char *name,
1717 const void *value, size_t value_size,
1718 unsigned int xattr_flags, u32 suppgid,
1719 struct ptlrpc_request **req)
1723 rc = exp_check_ops(exp);
1727 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1730 return exp->exp_obd->obd_type->typ_md_ops->m_setxattr(exp, fid,
1739 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1740 u64 obd_md_valid, const char *name,
1741 size_t buf_size, 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_getxattr(exp, fid,
1758 static inline int md_set_open_replay_data(struct obd_export *exp,
1759 struct obd_client_handle *och,
1760 struct lookup_intent *it)
1764 rc = exp_check_ops(exp);
1768 return exp->exp_obd->obd_type->typ_md_ops->m_set_open_replay_data(exp,
1773 static inline int md_clear_open_replay_data(struct obd_export *exp,
1774 struct obd_client_handle *och)
1778 rc = exp_check_ops(exp);
1782 return exp->exp_obd->obd_type->typ_md_ops->m_clear_open_replay_data(exp, och);
1785 static inline int md_set_lock_data(struct obd_export *exp,
1786 const struct lustre_handle *lockh,
1787 void *data, __u64 *bits)
1791 rc = exp_check_ops(exp);
1795 return exp->exp_obd->obd_type->typ_md_ops->m_set_lock_data(exp, lockh,
1801 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1802 union ldlm_policy_data *policy, enum ldlm_mode mode,
1803 enum ldlm_cancel_flags cancel_flags, void *opaque)
1807 rc = exp_check_ops(exp);
1811 return exp->exp_obd->obd_type->typ_md_ops->m_cancel_unused(exp,
1818 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1819 const struct lu_fid *fid,
1820 enum ldlm_type type,
1821 union ldlm_policy_data *policy,
1822 enum ldlm_mode mode,
1823 struct lustre_handle *lockh)
1827 rc = exp_check_ops(exp);
1831 return exp->exp_obd->obd_type->typ_md_ops->m_lock_match(exp, flags,
1837 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1842 rc = exp_check_ops(exp);
1846 return exp->exp_obd->obd_type->typ_md_ops->m_init_ea_size(exp, ea_size,
1850 static inline int md_intent_getattr_async(struct obd_export *exp,
1851 struct md_op_item *item)
1855 rc = exp_check_ops(exp);
1859 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1860 LPROC_MD_INTENT_GETATTR_ASYNC);
1862 return exp->exp_obd->obd_type->typ_md_ops->m_intent_getattr_async(exp,
1866 static inline int md_revalidate_lock(struct obd_export *exp,
1867 struct lookup_intent *it,
1868 struct lu_fid *fid, __u64 *bits)
1872 rc = exp_check_ops(exp);
1876 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1877 LPROC_MD_REVALIDATE_LOCK);
1879 return exp->exp_obd->obd_type->typ_md_ops->m_revalidate_lock(exp,
1884 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1885 const struct lmv_stripe_object *lso,
1886 const char *name, int namelen,
1891 rc = exp_check_ops(exp);
1895 return exp->exp_obd->obd_type->typ_md_ops->m_get_fid_from_lsm(exp,
1901 /* Unpack an MD struct from disk to in-memory format.
1902 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1904 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1905 * If *plsm == NULL then it will be allocated.
1907 static inline int md_stripe_object_create(struct obd_export *exp,
1908 struct lmv_stripe_object **lsop,
1909 const union lmv_mds_md *lmm,
1914 rc = exp_check_ops(exp);
1918 return exp->exp_obd->obd_type->typ_md_ops->m_stripe_object_create(exp,
1924 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1925 int *rcs, struct ptlrpc_request_set *set)
1929 rc = exp_check_ops(exp);
1933 return exp->exp_obd->obd_type->typ_md_ops->m_rmfid(exp, fa, rcs, set);
1936 static inline struct lu_batch *
1937 md_batch_create(struct obd_export *exp, enum lu_batch_flags flags,
1942 rc = exp_check_ops(exp);
1946 return exp->exp_obd->obd_type->typ_md_ops->m_batch_create(exp, flags,
1950 static inline int md_batch_stop(struct obd_export *exp, struct lu_batch *bh)
1954 rc = exp_check_ops(exp);
1958 return exp->exp_obd->obd_type->typ_md_ops->m_batch_stop(exp, bh);
1961 static inline int md_batch_flush(struct obd_export *exp, struct lu_batch *bh,
1966 rc = exp_check_ops(exp);
1970 return exp->exp_obd->obd_type->typ_md_ops->m_batch_flush(exp, bh, wait);
1973 static inline int md_batch_add(struct obd_export *exp, struct lu_batch *bh,
1974 struct md_op_item *item)
1978 rc = exp_check_ops(exp);
1982 return exp->exp_obd->obd_type->typ_md_ops->m_batch_add(exp, bh, item);
1985 /* OBD Metadata Support */
1987 extern int obd_init_caches(void);
1988 extern void obd_cleanup_caches(void);
1990 typedef int (*register_lwp_cb)(void *data);
1992 struct lwp_register_item {
1993 struct obd_export **lri_exp;
1994 register_lwp_cb lri_cb_func;
1996 struct list_head lri_list;
1998 char lri_name[MTI_NAME_MAXLEN];
2002 #ifdef HAVE_SERVER_SUPPORT
2003 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
2004 register_lwp_cb cb_func, void *cb_data);
2005 void lustre_deregister_lwp_item(struct obd_export **exp);
2006 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
2007 void lustre_notify_lwp_list(struct obd_export *exp);
2008 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
2009 #endif /* HAVE_SERVER_SUPPORT */
2010 int lustre_check_exclusion(struct super_block *sb, char *svname);
2013 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
2015 int class_add_uuid(const char *uuid, struct lnet_nid *nid);
2016 int class_del_uuid (const char *uuid);
2017 int class_add_nids_to_uuid(struct obd_uuid *uuid, struct lnet_nid *nidlist,
2018 int nid_count, int nid_size);
2019 int class_check_uuid(struct obd_uuid *uuid, struct lnet_nid *nid);
2022 extern char obd_jobid_name[];
2024 extern unsigned int obd_lbug_on_eviction;
2025 extern unsigned int obd_dump_on_eviction;
2027 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
2029 if (obd_lbug_on_eviction &&
2030 strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
2031 strlen(LUSTRE_MGC_NAME))) {
2032 CERROR("LBUG upon eviction\n");
2036 return obd_dump_on_eviction;
2041 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
2042 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
2044 /* root squash info */
2045 struct root_squash_info {
2048 struct list_head rsi_nosquash_nids;
2049 spinlock_t rsi_lock;
2052 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
2054 /* linux-module.c */
2055 struct obd_ioctl_data;
2056 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
2057 int class_procfs_init(void);
2058 int class_procfs_clean(void);
2060 extern void obd_heat_add(struct obd_heat_instance *instance,
2061 unsigned int time_second, __u64 count,
2062 unsigned int weight, unsigned int period_second);
2063 extern void obd_heat_decay(struct obd_heat_instance *instance,
2064 __u64 time_second, unsigned int weight,
2065 unsigned int period_second);
2066 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
2067 unsigned int time_second, unsigned int weight,
2068 unsigned int period_second);
2069 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
2071 /* struct kobj_type */
2073 struct attribute *_get_attr_matches(const struct kobj_type *typ,
2074 const char *key, size_t keylen,
2075 int (*is_match)(const char *, const char *,
2080 #ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
2081 for (i = 0; typ->default_groups[i]; i++) {
2083 struct attribute **attrs;
2085 attrs = (struct attribute **)typ->default_groups[i]->attrs;
2086 for (k = 0; attrs[k]; k++) {
2087 if (is_match(attrs[k]->name, key, keylen))
2088 return (struct attribute *)attrs[k];
2092 for (i = 0; typ->default_attrs[i]; i++) {
2093 if (is_match(typ->default_attrs[i]->name, key, keylen))
2094 return typ->default_attrs[i];
2101 int _attr_name_exact(const char *attr_name, const char *key, size_t len)
2103 return !strcmp(attr_name, key);
2107 struct attribute *get_attr_by_name(const struct kobj_type *typ,
2110 return _get_attr_matches(typ, name, 0, _attr_name_exact);
2114 int _attr_name_starts_with(const char *attr_name, const char *name, size_t len)
2116 return !strncmp(attr_name, name, len);
2120 struct attribute *get_attr_starts_with(const struct kobj_type *typ,
2124 return _get_attr_matches(typ, name, len, _attr_name_starts_with);
2127 int obd_ioctl_msg(const char *file, const char *func, int line, int level,
2128 const char *name, unsigned int cmd, const char *msg, int rc);
2129 #define OBD_IOC_DEBUG(level, dev, cmd, msg, rc) \
2130 obd_ioctl_msg(__FILE__, __func__, __LINE__, level, dev, cmd, msg, rc)
2131 #define OBD_IOC_ERROR(dev, cmd, msg, rc) \
2132 obd_ioctl_msg(__FILE__, __func__, __LINE__, D_ERROR, dev, cmd, msg, rc)
2134 #endif /* __LINUX_OBD_CLASS_H */