4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
34 #include <linux/kobject.h>
35 #include <obd_support.h>
36 #include <lustre_import.h>
37 #include <lustre_net.h>
39 #include <lustre_lib.h>
40 #include <uapi/linux/lustre/lustre_idl.h>
41 #include <lprocfs_status.h>
42 #include <dt_object.h>
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 extern rwlock_t obd_dev_lock;
58 /* OBD Operations Declarations */
59 extern struct obd_device *class_exp2obd(struct obd_export *);
60 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
61 int lustre_get_jobid(char *jobid, size_t len);
62 void lustre_jobid_clear(const char *jobid);
63 void jobid_cache_fini(void);
64 int jobid_cache_init(void);
65 char *jobid_current(void);
66 int jobid_set_current(char *jobid);
68 struct lu_device_type;
71 struct obd_export *class_conn2export(struct lustre_handle *);
72 #ifdef HAVE_SERVER_SUPPORT
73 struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
75 int class_register_type(const struct obd_ops *dt_ops,
76 const struct md_ops *md_ops, bool enable_proc,
77 const char *nm, struct lu_device_type *ldt);
78 int class_unregister_type(const char *nm);
80 struct obd_device *class_newdev(const char *type_name, const char *name,
82 int class_register_device(struct obd_device *obd);
83 void class_unregister_device(struct obd_device *obd);
84 void class_free_dev(struct obd_device *obd);
86 struct obd_device *class_dev_by_str(const char *str);
87 int class_name2dev(const char *name);
88 struct obd_device *class_name2obd(const char *name);
89 int class_uuid2dev(struct obd_uuid *uuid);
90 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
91 void class_obd_list(void);
92 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
93 const char *type_name,
94 struct obd_uuid *grp_uuid);
95 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
97 struct obd_device *class_num2obd(int num);
98 int get_devices_count(void);
100 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
102 static inline char *obd_export_nid2str(struct obd_export *exp)
104 return exp->exp_connection == NULL ?
105 "<unknown>" : libcfs_nidstr(&exp->exp_connection->c_peer.nid);
108 static inline char *obd_import_nid2str(struct obd_import *imp)
110 return imp->imp_connection == NULL ?
111 "<unknown>" : libcfs_nidstr(&imp->imp_connection->c_peer.nid);
114 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
115 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
116 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
119 int obd_zombie_impexp_init(void);
120 void obd_zombie_impexp_stop(void);
121 void obd_zombie_impexp_cull(void);
122 void obd_zombie_barrier(void);
123 void obd_exports_barrier(struct obd_device *obd);
124 int kuc_len(int payload_len);
125 struct kuc_hdr * kuc_ptr(void *p);
126 void *kuc_alloc(int payload_len, int transport, int type);
127 void kuc_free(void *p, int payload_len);
128 int obd_get_request_slot(struct client_obd *cli);
129 void obd_put_request_slot(struct client_obd *cli);
130 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
131 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
132 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
133 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
134 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
136 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
137 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
141 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
142 struct llog_rec_hdr *, void *);
144 struct obd_export *obd_stale_export_get(void);
145 void obd_stale_export_put(struct obd_export *exp);
146 void obd_stale_export_adjust(struct obd_export *exp);
149 /* For interoperability */
150 struct cfg_interop_param {
155 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
156 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
157 const char *new_name);
158 void print_lustre_cfg(struct lustre_cfg *lcfg);
159 int class_process_config(struct lustre_cfg *lcfg);
160 ssize_t class_set_global(const char *param);
161 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
162 struct kobject *kobj);
163 int class_attach(struct lustre_cfg *lcfg);
164 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
165 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
166 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
168 int class_find_param(char *buf, char *key, char **valp);
169 struct cfg_interop_param *class_find_old_param(const char *param,
170 struct cfg_interop_param *ptr);
171 int class_get_next_param(char **params, char *copy);
172 int class_match_param(char *buf, const char *key, char **valp);
173 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
174 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
175 int class_parse_net(char *buf, u32 *net, char **endh);
176 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
177 int class_match_net(char *buf, char *key, u32 net);
179 struct obd_device *class_incref(struct obd_device *obd,
180 const char *scope, const void *source);
181 void class_decref(struct obd_device *obd,
182 const char *scope, const void *source);
183 void dump_exports(struct obd_device *obd, int locks, int debug_level);
184 int class_config_llog_handler(const struct lu_env *env,
185 struct llog_handle *handle,
186 struct llog_rec_hdr *rec, void *data);
187 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
189 #define CFG_F_START 0x01 /* Set when we start updating from a log */
190 #define CFG_F_MARKER 0x02 /* We are within a maker */
191 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
192 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
194 /* Passed as data param to class_config_parse_llog */
195 struct config_llog_instance {
196 unsigned long cfg_instance;
197 struct super_block *cfg_sb;
198 struct obd_uuid cfg_uuid;
199 llog_cb_t cfg_callback;
200 int cfg_last_idx; /* for partial llog processing */
205 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
206 char *name, struct config_llog_instance *cfg);
209 * Generate a unique configuration instance for this mount
211 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
212 * For now, use the same value as before - the superblock pointer value.
214 * Using the client UUID would be an option, but it needs more testing.
216 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
218 return (unsigned long)sb;
221 #define CONFIG_SUB_SPTLRPC 0x01
222 #define CONFIG_SUB_RECOVER 0x02
223 #define CONFIG_SUB_PARAMS 0x04
224 #define CONFIG_SUB_NODEMAP 0x08
225 #define CONFIG_SUB_BARRIER 0x10
227 /* Sub clds should be attached to the config_llog_data when processing
228 * config log for client or server target. */
229 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
231 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
234 #define PARAMS_FILENAME "params"
235 #define BARRIER_FILENAME "barrier"
236 #define LCTL_UPCALL "lctl"
238 static inline bool logname_is_barrier(const char *logname)
242 /* logname for barrier is "fsname-barrier" */
243 ptr = strstr(logname, BARRIER_FILENAME);
244 if (ptr && (ptr - logname) >= 2 &&
245 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
251 /* list of active configuration logs */
252 struct config_llog_data {
253 struct ldlm_res_id cld_resid;
254 struct lustre_handle cld_lockh;
255 struct config_llog_instance cld_cfg;
256 struct list_head cld_list_chain;/* on config_llog_list */
257 atomic_t cld_refcount;
258 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
259 struct config_llog_data *cld_params; /* common parameters log */
260 struct config_llog_data *cld_recover;/* imperative recover log */
261 struct config_llog_data *cld_nodemap;/* nodemap log */
262 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
263 struct obd_export *cld_mgcexp;
264 struct mutex cld_lock;
265 enum mgs_cfg_type cld_type;
266 unsigned int cld_stopping:1, /* we were told to stop
268 cld_lostlock:1; /* lock not requeued */
272 struct lustre_profile {
273 struct list_head lp_list;
278 bool lp_list_deleted;
281 struct lustre_profile *class_get_profile(const char * prof);
282 void class_del_profile(const char *prof);
283 void class_put_profile(struct lustre_profile *lprof);
284 void class_del_profiles(void);
287 #if LUSTRE_TRACKS_LOCK_EXP_REFS
289 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
290 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
291 extern void (*class_export_dump_hook)(struct obd_export *);
295 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
296 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
300 #define class_export_rpc_inc(exp) \
302 atomic_inc(&(exp)->exp_rpc_count); \
303 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
304 (exp), atomic_read(&(exp)->exp_rpc_count)); \
307 #define class_export_rpc_dec(exp) \
309 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
310 atomic_dec(&(exp)->exp_rpc_count); \
311 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
312 (exp), atomic_read(&(exp)->exp_rpc_count)); \
315 #define class_export_lock_get(exp, lock) \
317 atomic_inc(&(exp)->exp_locks_count); \
318 __class_export_add_lock_ref(exp, lock); \
319 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
320 (exp), atomic_read(&(exp)->exp_locks_count)); \
321 class_export_get(exp); \
324 #define class_export_lock_put(exp, lock) \
326 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
327 atomic_dec(&(exp)->exp_locks_count); \
328 __class_export_del_lock_ref(exp, lock); \
329 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
330 (exp), atomic_read(&(exp)->exp_locks_count)); \
331 class_export_put(exp); \
334 #define class_export_cb_get(exp) \
336 atomic_inc(&(exp)->exp_cb_count); \
337 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
338 (exp), atomic_read(&(exp)->exp_cb_count)); \
339 class_export_get(exp); \
342 #define class_export_cb_put(exp) \
344 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
345 atomic_dec(&(exp)->exp_cb_count); \
346 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
347 (exp), atomic_read(&(exp)->exp_cb_count)); \
348 class_export_put(exp); \
352 struct obd_export *class_export_get(struct obd_export *exp);
353 void class_export_put(struct obd_export *exp);
354 struct obd_export *class_new_export(struct obd_device *obd,
355 struct obd_uuid *cluuid);
356 struct obd_export *class_new_export_self(struct obd_device *obd,
357 struct obd_uuid *uuid);
358 void class_unlink_export(struct obd_export *exp);
360 struct obd_import *class_import_get(struct obd_import *);
361 void class_import_put(struct obd_import *);
362 struct obd_import *class_new_import(struct obd_device *obd);
363 void class_destroy_import(struct obd_import *exp);
365 #ifdef HAVE_SERVER_SUPPORT
366 struct obd_type *class_search_type(const char *name);
367 struct obd_type *class_get_type(const char *name);
369 void class_put_type(struct obd_type *type);
370 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
371 struct obd_uuid *cluuid);
372 int class_disconnect(struct obd_export *exp);
373 void class_fail_export(struct obd_export *exp);
374 int class_connected_export(struct obd_export *exp);
375 void class_disconnect_exports(struct obd_device *obd);
376 int class_manual_cleanup(struct obd_device *obd);
377 void class_disconnect_stale_exports(struct obd_device *,
378 int (*test_export)(struct obd_export *));
380 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
382 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
383 (obd->obd_force ? OBD_OPT_FORCE : 0) |
384 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
388 #ifdef HAVE_SERVER_SUPPORT
389 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
391 LASSERT(exp->exp_obd);
392 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
394 return exp->exp_obd->u.obt.obt_lut;
397 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
399 LASSERT(obd->u.obt.obt_lut);
400 return &obd->u.obt.obt_lut->lut_lsd;
408 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
409 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
411 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
412 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
414 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
415 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
417 static inline int obd_check_dev(struct obd_device *obd)
420 CERROR("NULL device\n");
426 /* ensure obd_setup and !obd_stopping */
427 #define OBD_CHECK_DEV_ACTIVE(obd) \
429 rc = obd_check_dev(obd); \
433 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
434 CERROR("Device %d not setup\n", \
441 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
443 /* Always add in ldlm_stats */
444 tmp->nid_ldlm_stats =
445 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
446 LPROCFS_STATS_FLAG_NOPERCPU);
447 if (tmp->nid_ldlm_stats == NULL)
450 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
452 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
453 tmp->nid_ldlm_stats);
456 static inline int exp_check_ops(struct obd_export *exp)
461 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
467 static inline int class_devno_max(void)
469 return MAX_OBD_DEVICES;
472 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
473 __u32 keylen, void *key,
474 __u32 *vallen, void *val)
479 rc = exp_check_ops(exp);
483 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
484 CERROR("%s: no %s operation\n",
485 (exp)->exp_obd->obd_name, __func__);
489 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
493 static inline int obd_set_info_async(const struct lu_env *env,
494 struct obd_export *exp,
495 __u32 keylen, void *key,
496 __u32 vallen, void *val,
497 struct ptlrpc_request_set *set)
502 rc = exp_check_ops(exp);
506 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
507 CERROR("%s: no %s operation\n",
508 (exp)->exp_obd->obd_name, __func__);
512 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
518 * obd-lu integration.
520 * Functionality is being moved into new lu_device-based layering, but some
521 * pieces of configuration process are still based on obd devices.
523 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
524 * subsume ->o_setup() methods of obd devices they replace. The same for
525 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
526 * result, obd_setup() and obd_process_config() branch and call one XOR
529 * Yet neither lu_device_type_operations::ldto_device_fini() nor
530 * lu_device_type_operations::ldto_device_free() fully implement the
531 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
532 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
534 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
537 struct obd_type *type = obd->obd_type;
538 struct lu_device_type *ldt;
542 wait_var_event(&type->typ_lu,
543 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
546 struct lu_context session_ctx;
549 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
550 session_ctx.lc_thread = NULL;
551 lu_context_enter(&session_ctx);
553 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
555 struct lu_device *dev;
556 env.le_ses = &session_ctx;
557 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
560 obd->obd_lu_dev = dev;
562 if (lu_device_is_dt(dev) &&
563 lu2dt_dev(dev)->dd_rdonly)
564 obd->obd_read_only = 1;
569 lu_context_exit(&session_ctx);
570 lu_context_fini(&session_ctx);
572 if (!obd->obd_type->typ_dt_ops->o_setup) {
573 CERROR("%s: no %s operation\n", obd->obd_name,
577 rc = OBP(obd, setup)(obd, cfg);
582 static inline int obd_precleanup(struct obd_device *obd)
585 struct lu_device_type *ldt = obd->obd_type->typ_lu;
586 struct lu_device *d = obd->obd_lu_dev;
590 if (ldt != NULL && d != NULL) {
591 struct lu_env *env = lu_env_find();
596 rc = lu_env_init(env, ldt->ldt_ctx_tags);
600 ldt->ldt_ops->ldto_device_fini(env, d);
607 if (!obd->obd_type->typ_dt_ops->o_precleanup)
610 rc = OBP(obd, precleanup)(obd);
614 static inline int obd_cleanup(struct obd_device *obd)
617 struct lu_device_type *ldt = obd->obd_type->typ_lu;
618 struct lu_device *d = obd->obd_lu_dev;
621 if (ldt != NULL && d != NULL) {
624 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
626 ldt->ldt_ops->ldto_device_free(&env, d);
628 obd->obd_lu_dev = NULL;
631 if (!obd->obd_type->typ_dt_ops->o_cleanup)
634 rc = OBP(obd, cleanup)(obd);
638 static inline void obd_cleanup_client_import(struct obd_device *obd)
642 /* If we set up but never connected, the client import will not
645 down_write(&obd->u.cli.cl_sem);
646 if (obd->u.cli.cl_import) {
647 struct obd_import *imp;
649 imp = obd->u.cli.cl_import;
650 CDEBUG(D_CONFIG, "%s: client import never connected\n",
652 ptlrpc_invalidate_import(imp);
653 client_destroy_import(imp);
654 obd->u.cli.cl_import = NULL;
656 up_write(&obd->u.cli.cl_sem);
661 static inline int obd_process_config(struct obd_device *obd, int datalen,
665 struct lu_device_type *ldt = obd->obd_type->typ_lu;
666 struct lu_device *d = obd->obd_lu_dev;
670 obd->obd_process_conf = 1;
671 if (ldt != NULL && d != NULL) {
674 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
676 rc = d->ld_ops->ldo_process_config(&env, d, data);
680 if (!obd->obd_type->typ_dt_ops->o_process_config) {
681 CERROR("%s: no %s operation\n",
682 obd->obd_name, __func__);
685 rc = OBP(obd, process_config)(obd, datalen, data);
688 obd->obd_process_conf = 0;
693 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
699 rc = exp_check_ops(exp);
703 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
704 CERROR("%s: no %s operation\n",
705 (exp)->exp_obd->obd_name, __func__);
709 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
713 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
719 rc = exp_check_ops(exp);
723 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
724 CERROR("%s: no %s operation\n",
725 (exp)->exp_obd->obd_name, __func__);
729 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
733 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
739 rc = exp_check_ops(exp);
743 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
744 CERROR("%s: no %s operation\n",
745 (exp)->exp_obd->obd_name, __func__);
749 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
754 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
760 rc = exp_check_ops(exp);
764 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
765 CERROR("%s: no %s operation\n",
766 (exp)->exp_obd->obd_name, __func__);
770 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
775 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
778 struct obd_device *obd = imp->imp_obd;
782 OBD_CHECK_DEV_ACTIVE(obd);
783 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
784 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
788 rc = OBP(obd, add_conn)(imp, uuid, priority);
792 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
794 struct obd_device *obd = imp->imp_obd;
798 OBD_CHECK_DEV_ACTIVE(obd);
799 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
800 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
804 rc = OBP(obd, del_conn)(imp, uuid);
808 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
810 struct obd_uuid *uuid;
813 if (!exp->exp_obd->obd_type ||
814 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
817 uuid = OBP(exp->exp_obd, get_uuid)(exp);
821 /** Create a new /a exp on device /a obd for the uuid /a cluuid
822 * @param exp New export handle
823 * @param d Connect data, supported flags are set, flags also understood
824 * by obd are returned.
826 static inline int obd_connect(const struct lu_env *env,
827 struct obd_export **exp,struct obd_device *obd,
828 struct obd_uuid *cluuid,
829 struct obd_connect_data *data,
833 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
837 OBD_CHECK_DEV_ACTIVE(obd);
838 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
839 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
843 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
844 /* check that only subset is granted */
845 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
846 data->ocd_connect_flags));
850 static inline int obd_reconnect(const struct lu_env *env,
851 struct obd_export *exp,
852 struct obd_device *obd,
853 struct obd_uuid *cluuid,
854 struct obd_connect_data *d,
858 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
863 OBD_CHECK_DEV_ACTIVE(obd);
864 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
867 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
868 /* check that only subset is granted */
869 LASSERT(ergo(d != NULL,
870 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
874 static inline int obd_disconnect(struct obd_export *exp)
878 rc = exp_check_ops(exp);
882 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
883 CERROR("%s: no %s operation\n",
884 (exp)->exp_obd->obd_name, __func__);
888 rc = OBP(exp->exp_obd, disconnect)(exp);
892 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
893 enum lu_cli_type type)
898 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
901 rc = OBP(obd, fid_init)(obd, exp, type);
905 static inline int obd_fid_fini(struct obd_device *obd)
909 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
912 rc = OBP(obd, fid_fini)(obd);
916 static inline int obd_fid_alloc(const struct lu_env *env,
917 struct obd_export *exp,
919 struct md_op_data *op_data)
923 rc = exp_check_ops(exp);
927 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
928 CERROR("%s: no %s operation\n",
929 (exp)->exp_obd->obd_name, __func__);
933 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
937 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
942 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
943 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
947 rc = OBP(obd, pool_new)(obd, poolname);
951 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
955 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
956 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
960 rc = OBP(obd, pool_del)(obd, poolname);
964 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
970 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
971 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
975 rc = OBP(obd, pool_add)(obd, poolname, ostname);
979 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
985 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
986 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
990 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
994 static inline int obd_init_export(struct obd_export *exp)
999 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1000 OBP((exp)->exp_obd, init_export))
1001 rc = OBP(exp->exp_obd, init_export)(exp);
1005 static inline int obd_destroy_export(struct obd_export *exp)
1008 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1009 OBP(exp->exp_obd, destroy_export))
1010 OBP(exp->exp_obd, destroy_export)(exp);
1014 /* @max_age is the oldest time in seconds that we accept using a cached data.
1015 * If the cache is older than @max_age we will get a new value from the
1016 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1018 static inline int obd_statfs_async(struct obd_export *exp,
1019 struct obd_info *oinfo,
1021 struct ptlrpc_request_set *rqset)
1023 struct obd_device *obd;
1028 if (exp == NULL || exp->exp_obd == NULL)
1032 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1034 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1038 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1039 obd->obd_name, obd->obd_osfs_age, max_age);
1040 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1045 /* @max_age is the oldest time in seconds that we accept using a cached data.
1046 * If the cache is older than @max_age we will get a new value from the
1047 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1049 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1050 struct obd_statfs *osfs, time64_t max_age,
1053 struct obd_device *obd;
1057 if (unlikely(exp == NULL || exp->exp_obd == NULL))
1061 OBD_CHECK_DEV_ACTIVE(obd);
1063 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1064 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1065 RETURN(-EOPNOTSUPP);
1068 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1069 obd->obd_name, obd->obd_osfs_age, max_age);
1070 /* ignore cache if aggregated isn't expected */
1071 if (obd->obd_osfs_age < max_age ||
1072 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1073 !(flags & OBD_STATFS_SUM))) {
1074 /* the RPC will block anyway, so avoid sending many at once */
1075 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1076 (flags & OBD_STATFS_NESTED)
1077 ? SINGLE_DEPTH_NESTING : 0);
1080 if (obd->obd_osfs_age < max_age ||
1081 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1082 !(flags & OBD_STATFS_SUM))) {
1083 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1085 mutex_unlock(&obd->obd_dev_mutex);
1086 GOTO(cached, rc = 0);
1090 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1091 obd->obd_name, &obd->obd_osfs,
1092 osfs->os_bavail, osfs->os_blocks,
1093 osfs->os_ffree, osfs->os_files);
1095 spin_lock(&obd->obd_osfs_lock);
1096 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1097 obd->obd_osfs_age = ktime_get_seconds();
1098 spin_unlock(&obd->obd_osfs_lock);
1100 mutex_unlock(&obd->obd_dev_mutex);
1104 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1105 obd->obd_name, &obd->obd_osfs,
1106 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1107 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1108 spin_lock(&obd->obd_osfs_lock);
1109 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1110 spin_unlock(&obd->obd_osfs_lock);
1115 static inline int obd_preprw(const struct lu_env *env, int cmd,
1116 struct obd_export *exp, struct obdo *oa,
1117 int objcount, struct obd_ioobj *obj,
1118 struct niobuf_remote *remote, int *pages,
1119 struct niobuf_local *local)
1125 rc = exp_check_ops(exp);
1129 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1130 CERROR("%s: no %s operation\n",
1131 (exp)->exp_obd->obd_name, __func__);
1135 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1141 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1142 struct obd_export *exp, struct obdo *oa,
1143 int objcount, struct obd_ioobj *obj,
1144 struct niobuf_remote *rnb, int pages,
1145 struct niobuf_local *local, const int orig_rc,
1146 int nob, ktime_t kstart)
1151 rc = exp_check_ops(exp);
1155 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1156 CERROR("%s: no %s operation\n",
1157 (exp)->exp_obd->obd_name, __func__);
1161 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1162 rnb, pages, local, orig_rc, nob,
1168 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1169 int len, void *karg, void __user *uarg)
1174 rc = exp_check_ops(exp);
1178 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1179 CERROR("%s: no %s operation\n",
1180 (exp)->exp_obd->obd_name, __func__);
1184 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1188 static inline void obd_import_event(struct obd_device *obd,
1189 struct obd_import *imp,
1190 enum obd_import_event event)
1194 CERROR("NULL device\n");
1199 if (obd->obd_set_up && OBP(obd, import_event))
1200 OBP(obd, import_event)(obd, imp, event);
1205 static inline int obd_notify(struct obd_device *obd,
1206 struct obd_device *watched,
1207 enum obd_notify_event ev)
1212 rc = obd_check_dev(obd);
1216 if (!obd->obd_set_up) {
1217 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1221 if (!OBP(obd, notify)) {
1222 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1226 rc = OBP(obd, notify)(obd, watched, ev);
1231 static inline int obd_notify_observer(struct obd_device *observer,
1232 struct obd_device *observed,
1233 enum obd_notify_event ev)
1237 struct obd_notify_upcall *onu;
1239 if (observer->obd_observer)
1240 rc = obd_notify(observer->obd_observer, observed, ev);
1243 * Also, call non-obd listener, if any
1245 onu = &observer->obd_upcall;
1246 if (onu->onu_upcall != NULL)
1247 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1249 return rc ? rc : rc2;
1252 static inline int obd_quotactl(struct obd_export *exp,
1253 struct obd_quotactl *oqctl)
1258 rc = exp_check_ops(exp);
1262 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1263 CERROR("%s: no %s operation\n",
1264 (exp)->exp_obd->obd_name, __func__);
1268 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1272 static inline int obd_health_check(const struct lu_env *env,
1273 struct obd_device *obd)
1275 /* returns: 0 on healthy
1276 * >0 on unhealthy + reason code/flag
1277 * however the only suppored reason == 1 right now
1278 * We'll need to define some better reasons
1279 * or flags in the future.
1286 /* NULL method is normal here */
1287 if (obd == NULL || !obd->obd_type) {
1288 CERROR("cleaned up obd\n");
1289 RETURN(-EOPNOTSUPP);
1291 if (!obd->obd_set_up || obd->obd_stopping)
1293 if (!OBP(obd, health_check))
1296 rc = OBP(obd, health_check)(env, obd);
1300 static inline int obd_register_observer(struct obd_device *obd,
1301 struct obd_device *observer)
1306 rc = obd_check_dev(obd);
1310 down_write(&obd->obd_observer_link_sem);
1311 if (obd->obd_observer && observer) {
1312 up_write(&obd->obd_observer_link_sem);
1315 obd->obd_observer = observer;
1316 up_write(&obd->obd_observer_link_sem);
1320 /* metadata helpers */
1326 LPROC_MD_INTENT_LOCK,
1335 LPROC_MD_INTENT_GETATTR_ASYNC,
1336 LPROC_MD_REVALIDATE_LOCK,
1340 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1345 rc = exp_check_ops(exp);
1349 return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1352 static inline int md_getattr(struct obd_export *exp,
1353 struct md_op_data *op_data,
1354 struct ptlrpc_request **request)
1358 rc = exp_check_ops(exp);
1362 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1365 return MDP(exp->exp_obd, getattr)(exp, op_data, request);
1368 static inline int md_null_inode(struct obd_export *exp,
1369 const struct lu_fid *fid)
1373 rc = exp_check_ops(exp);
1377 return MDP(exp->exp_obd, null_inode)(exp, fid);
1380 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1381 struct md_open_data *mod,
1382 struct ptlrpc_request **request)
1386 rc = exp_check_ops(exp);
1390 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1393 return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1396 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1397 const void *data, size_t datalen, umode_t mode,
1398 uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1399 __u64 rdev, struct ptlrpc_request **request)
1403 rc = exp_check_ops(exp);
1407 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1410 return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1411 uid, gid, cap_effective, rdev,
1415 static inline int md_enqueue(struct obd_export *exp,
1416 struct ldlm_enqueue_info *einfo,
1417 const union ldlm_policy_data *policy,
1418 struct md_op_data *op_data,
1419 struct lustre_handle *lockh,
1420 __u64 extra_lock_flags)
1424 rc = exp_check_ops(exp);
1428 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1431 return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1435 static inline int md_getattr_name(struct obd_export *exp,
1436 struct md_op_data *op_data,
1437 struct ptlrpc_request **request)
1441 rc = exp_check_ops(exp);
1445 return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1448 static inline int md_intent_lock(struct obd_export *exp,
1449 struct md_op_data *op_data,
1450 struct lookup_intent *it,
1451 struct ptlrpc_request **reqp,
1452 ldlm_blocking_callback cb_blocking,
1453 __u64 extra_lock_flags)
1457 rc = exp_check_ops(exp);
1461 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1462 LPROC_MD_INTENT_LOCK);
1464 return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1465 cb_blocking, extra_lock_flags);
1468 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1469 struct ptlrpc_request **request)
1473 rc = exp_check_ops(exp);
1477 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1480 return MDP(exp->exp_obd, link)(exp, op_data, request);
1483 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1484 const char *old_name, size_t oldlen,
1485 const char *new_name, size_t newlen,
1486 struct ptlrpc_request **request)
1490 rc = exp_check_ops(exp);
1494 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1497 return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
1498 new_name, newlen, request);
1501 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1502 void *ea, size_t ealen,
1503 struct ptlrpc_request **request)
1507 rc = exp_check_ops(exp);
1511 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1514 return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1517 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1518 struct ptlrpc_request **request)
1522 rc = exp_check_ops(exp);
1526 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1529 return MDP(exp->exp_obd, fsync)(exp, fid, request);
1532 /* FLR: resync mirrored files. */
1533 static inline int md_file_resync(struct obd_export *exp,
1534 struct md_op_data *data)
1538 rc = exp_check_ops(exp);
1542 return MDP(exp->exp_obd, file_resync)(exp, data);
1545 static inline int md_read_page(struct obd_export *exp,
1546 struct md_op_data *op_data,
1547 struct md_readdir_info *mrinfo,
1548 __u64 hash_offset, struct page **ppage)
1552 rc = exp_check_ops(exp);
1556 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1557 LPROC_MD_READ_PAGE);
1559 return MDP(exp->exp_obd, read_page)(exp, op_data, mrinfo, hash_offset,
1563 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1564 struct ptlrpc_request **request)
1568 rc = exp_check_ops(exp);
1572 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1575 return MDP(exp->exp_obd, unlink)(exp, op_data, request);
1578 static inline int md_get_lustre_md(struct obd_export *exp,
1579 struct req_capsule *pill,
1580 struct obd_export *dt_exp,
1581 struct obd_export *md_exp,
1582 struct lustre_md *md)
1586 rc = exp_check_ops(exp);
1590 return MDP(exp->exp_obd, get_lustre_md)(exp, pill, dt_exp, md_exp, md);
1593 static inline int md_free_lustre_md(struct obd_export *exp,
1594 struct lustre_md *md)
1598 rc = exp_check_ops(exp);
1602 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1605 static inline int md_merge_attr(struct obd_export *exp,
1606 const struct lmv_stripe_md *lsm,
1607 struct cl_attr *attr,
1608 ldlm_blocking_callback cb)
1612 rc = exp_check_ops(exp);
1616 return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb);
1619 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1620 u64 obd_md_valid, const char *name,
1621 const void *value, size_t value_size,
1622 unsigned int xattr_flags, u32 suppgid,
1623 struct ptlrpc_request **req)
1627 rc = exp_check_ops(exp);
1631 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1634 return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1635 value, value_size, xattr_flags,
1639 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1640 u64 obd_md_valid, const char *name,
1641 size_t buf_size, struct ptlrpc_request **req)
1645 rc = exp_check_ops(exp);
1649 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1652 return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1656 static inline int md_set_open_replay_data(struct obd_export *exp,
1657 struct obd_client_handle *och,
1658 struct lookup_intent *it)
1662 rc = exp_check_ops(exp);
1666 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1669 static inline int md_clear_open_replay_data(struct obd_export *exp,
1670 struct obd_client_handle *och)
1674 rc = exp_check_ops(exp);
1678 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1681 static inline int md_set_lock_data(struct obd_export *exp,
1682 const struct lustre_handle *lockh,
1683 void *data, __u64 *bits)
1687 rc = exp_check_ops(exp);
1691 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1695 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1696 union ldlm_policy_data *policy, enum ldlm_mode mode,
1697 enum ldlm_cancel_flags cancel_flags, void *opaque)
1701 rc = exp_check_ops(exp);
1705 return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1706 cancel_flags, opaque);
1709 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1710 const struct lu_fid *fid,
1711 enum ldlm_type type,
1712 union ldlm_policy_data *policy,
1713 enum ldlm_mode mode,
1714 struct lustre_handle *lockh)
1718 rc = exp_check_ops(exp);
1722 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1723 policy, mode, lockh);
1726 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1731 rc = exp_check_ops(exp);
1735 return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
1738 static inline int md_intent_getattr_async(struct obd_export *exp,
1739 struct md_op_item *item)
1743 rc = exp_check_ops(exp);
1747 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1748 LPROC_MD_INTENT_GETATTR_ASYNC);
1750 return MDP(exp->exp_obd, intent_getattr_async)(exp, item);
1753 static inline int md_revalidate_lock(struct obd_export *exp,
1754 struct lookup_intent *it,
1755 struct lu_fid *fid, __u64 *bits)
1759 rc = exp_check_ops(exp);
1763 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1764 LPROC_MD_REVALIDATE_LOCK);
1766 return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1769 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1770 const struct lmv_stripe_md *lsm,
1771 const char *name, int namelen,
1776 rc = exp_check_ops(exp);
1780 return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
1784 /* Unpack an MD struct from disk to in-memory format.
1785 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1787 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1788 * If *plsm == NULL then it will be allocated.
1790 static inline int md_unpackmd(struct obd_export *exp,
1791 struct lmv_stripe_md **plsm,
1792 const union lmv_mds_md *lmm, size_t lmm_size)
1796 rc = exp_check_ops(exp);
1800 return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1803 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1804 int *rcs, struct ptlrpc_request_set *set)
1808 rc = exp_check_ops(exp);
1812 return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
1815 /* OBD Metadata Support */
1817 extern int obd_init_caches(void);
1818 extern void obd_cleanup_caches(void);
1820 typedef int (*register_lwp_cb)(void *data);
1822 struct lwp_register_item {
1823 struct obd_export **lri_exp;
1824 register_lwp_cb lri_cb_func;
1826 struct list_head lri_list;
1828 char lri_name[MTI_NAME_MAXLEN];
1832 #ifdef HAVE_SERVER_SUPPORT
1833 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1834 register_lwp_cb cb_func, void *cb_data);
1835 void lustre_deregister_lwp_item(struct obd_export **exp);
1836 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1837 void lustre_notify_lwp_list(struct obd_export *exp);
1838 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1839 #endif /* HAVE_SERVER_SUPPORT */
1840 int lustre_check_exclusion(struct super_block *sb, char *svname);
1843 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
1845 int class_add_uuid(const char *uuid, __u64 nid);
1846 int class_del_uuid (const char *uuid);
1847 int class_add_nids_to_uuid(struct obd_uuid *uuid, lnet_nid_t *nids,
1849 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1852 extern char obd_jobid_name[];
1854 extern unsigned int obd_lbug_on_eviction;
1855 extern unsigned int obd_dump_on_eviction;
1857 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
1859 if (obd_lbug_on_eviction &&
1860 strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
1861 strlen(LUSTRE_MGC_NAME))) {
1862 CERROR("LBUG upon eviction\n");
1866 return obd_dump_on_eviction;
1871 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1872 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1874 /* root squash info */
1875 struct root_squash_info {
1878 struct list_head rsi_nosquash_nids;
1879 spinlock_t rsi_lock;
1882 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1884 /* linux-module.c */
1885 struct obd_ioctl_data;
1886 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
1887 int class_procfs_init(void);
1888 int class_procfs_clean(void);
1890 extern void obd_heat_add(struct obd_heat_instance *instance,
1891 unsigned int time_second, __u64 count,
1892 unsigned int weight, unsigned int period_second);
1893 extern void obd_heat_decay(struct obd_heat_instance *instance,
1894 __u64 time_second, unsigned int weight,
1895 unsigned int period_second);
1896 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
1897 unsigned int time_second, unsigned int weight,
1898 unsigned int period_second);
1899 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
1900 #endif /* __LINUX_OBD_CLASS_H */