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>
43 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
44 * and resends for avoid deadlocks */
45 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
47 #define OBD_STATFS_FOR_MDT0 0x0004 /* The statfs is only for retrieving
48 * information from MDT0. */
49 #define OBD_STATFS_SUM 0x0008 /* get aggregated statfs from MDT */
50 #define OBD_STATFS_NESTED 0x0010 /* Call while already holding
51 * obd_dev_mutex of a difference
55 extern rwlock_t obd_dev_lock;
57 /* OBD Operations Declarations */
58 extern struct obd_device *class_exp2obd(struct obd_export *);
59 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
60 int lustre_get_jobid(char *jobid, size_t len);
61 void lustre_jobid_clear(const char *jobid);
62 void jobid_cache_fini(void);
63 int jobid_cache_init(void);
64 char *jobid_current(void);
65 int jobid_set_current(char *jobid);
67 struct lu_device_type;
70 struct obd_export *class_conn2export(struct lustre_handle *);
71 #ifdef HAVE_SERVER_SUPPORT
72 struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
74 int class_register_type(const struct obd_ops *dt_ops,
75 const struct md_ops *md_ops, bool enable_proc,
76 const char *nm, struct lu_device_type *ldt);
77 int class_unregister_type(const char *nm);
79 struct obd_device *class_newdev(const char *type_name, const char *name,
81 int class_register_device(struct obd_device *obd);
82 void class_unregister_device(struct obd_device *obd);
83 void class_free_dev(struct obd_device *obd);
85 struct obd_device *class_dev_by_str(const char *str);
86 int class_name2dev(const char *name);
87 struct obd_device *class_name2obd(const char *name);
88 int class_uuid2dev(struct obd_uuid *uuid);
89 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
90 void class_obd_list(void);
91 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
92 const char *type_name,
93 struct obd_uuid *grp_uuid);
94 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
96 struct obd_device *class_num2obd(int num);
97 int get_devices_count(void);
99 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
101 static inline char *obd_export_nid2str(struct obd_export *exp)
103 return exp->exp_connection == NULL ?
104 "<unknown>" : libcfs_nidstr(&exp->exp_connection->c_peer.nid);
107 static inline char *obd_import_nid2str(struct obd_import *imp)
109 return imp->imp_connection == NULL ?
110 "<unknown>" : libcfs_nidstr(&imp->imp_connection->c_peer.nid);
113 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
114 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
115 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
118 int obd_zombie_impexp_init(void);
119 void obd_zombie_impexp_stop(void);
120 void obd_zombie_impexp_cull(void);
121 void obd_zombie_barrier(void);
122 void obd_exports_barrier(struct obd_device *obd);
123 int kuc_len(int payload_len);
124 struct kuc_hdr * kuc_ptr(void *p);
125 void *kuc_alloc(int payload_len, int transport, int type);
126 void kuc_free(void *p, int payload_len);
127 int obd_get_request_slot(struct client_obd *cli);
128 void obd_put_request_slot(struct client_obd *cli);
129 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
130 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
131 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
132 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
133 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
135 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
136 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
140 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
141 struct llog_rec_hdr *, void *);
143 struct obd_export *obd_stale_export_get(void);
144 void obd_stale_export_put(struct obd_export *exp);
145 void obd_stale_export_adjust(struct obd_export *exp);
148 /* For interoperability */
149 struct cfg_interop_param {
154 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
155 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
156 const char *new_name);
157 void print_lustre_cfg(struct lustre_cfg *lcfg);
158 int class_process_config(struct lustre_cfg *lcfg);
159 ssize_t class_set_global(const char *param);
160 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
161 struct kobject *kobj);
162 int class_attach(struct lustre_cfg *lcfg);
163 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
164 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
165 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
167 int class_find_param(char *buf, char *key, char **valp);
168 struct cfg_interop_param *class_find_old_param(const char *param,
169 struct cfg_interop_param *ptr);
170 int class_get_next_param(char **params, char *copy);
171 int class_match_param(char *buf, const char *key, char **valp);
172 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
173 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
174 int class_parse_net(char *buf, u32 *net, char **endh);
175 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
176 int class_match_net(char *buf, char *key, u32 net);
178 struct obd_device *class_incref(struct obd_device *obd,
179 const char *scope, const void *source);
180 void class_decref(struct obd_device *obd,
181 const char *scope, const void *source);
182 void dump_exports(struct obd_device *obd, int locks, int debug_level);
183 int class_config_llog_handler(const struct lu_env *env,
184 struct llog_handle *handle,
185 struct llog_rec_hdr *rec, void *data);
186 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
188 #define CFG_F_START 0x01 /* Set when we start updating from a log */
189 #define CFG_F_MARKER 0x02 /* We are within a maker */
190 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
191 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
193 /* Passed as data param to class_config_parse_llog */
194 struct config_llog_instance {
195 unsigned long cfg_instance;
196 struct super_block *cfg_sb;
197 struct obd_uuid cfg_uuid;
198 llog_cb_t cfg_callback;
199 int cfg_last_idx; /* for partial llog processing */
204 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
205 char *name, struct config_llog_instance *cfg);
208 * Generate a unique configuration instance for this mount
210 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
211 * For now, use the same value as before - the superblock pointer value.
213 * Using the client UUID would be an option, but it needs more testing.
215 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
217 return (unsigned long)sb;
220 #define CONFIG_SUB_SPTLRPC 0x01
221 #define CONFIG_SUB_RECOVER 0x02
222 #define CONFIG_SUB_PARAMS 0x04
223 #define CONFIG_SUB_NODEMAP 0x08
224 #define CONFIG_SUB_BARRIER 0x10
226 /* Sub clds should be attached to the config_llog_data when processing
227 * config log for client or server target. */
228 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
230 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
233 #define PARAMS_FILENAME "params"
234 #define BARRIER_FILENAME "barrier"
235 #define LCTL_UPCALL "lctl"
237 static inline bool logname_is_barrier(const char *logname)
241 /* logname for barrier is "fsname-barrier" */
242 ptr = strstr(logname, BARRIER_FILENAME);
243 if (ptr && (ptr - logname) >= 2 &&
244 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
250 /* list of active configuration logs */
251 struct config_llog_data {
252 struct ldlm_res_id cld_resid;
253 struct lustre_handle cld_lockh;
254 struct config_llog_instance cld_cfg;
255 struct list_head cld_list_chain;/* on config_llog_list */
256 atomic_t cld_refcount;
257 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
258 struct config_llog_data *cld_params; /* common parameters log */
259 struct config_llog_data *cld_recover;/* imperative recover log */
260 struct config_llog_data *cld_nodemap;/* nodemap log */
261 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
262 struct obd_export *cld_mgcexp;
263 struct mutex cld_lock;
264 enum mgs_cfg_type cld_type;
265 unsigned int cld_stopping:1, /* we were told to stop
267 cld_lostlock:1; /* lock not requeued */
271 struct lustre_profile {
272 struct list_head lp_list;
277 bool lp_list_deleted;
280 struct lustre_profile *class_get_profile(const char * prof);
281 void class_del_profile(const char *prof);
282 void class_put_profile(struct lustre_profile *lprof);
283 void class_del_profiles(void);
286 #if LUSTRE_TRACKS_LOCK_EXP_REFS
288 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
289 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
290 extern void (*class_export_dump_hook)(struct obd_export *);
294 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
295 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
299 #define class_export_rpc_inc(exp) \
301 atomic_inc(&(exp)->exp_rpc_count); \
302 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
303 (exp), atomic_read(&(exp)->exp_rpc_count)); \
306 #define class_export_rpc_dec(exp) \
308 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
309 atomic_dec(&(exp)->exp_rpc_count); \
310 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
311 (exp), atomic_read(&(exp)->exp_rpc_count)); \
314 #define class_export_lock_get(exp, lock) \
316 atomic_inc(&(exp)->exp_locks_count); \
317 __class_export_add_lock_ref(exp, lock); \
318 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
319 (exp), atomic_read(&(exp)->exp_locks_count)); \
320 class_export_get(exp); \
323 #define class_export_lock_put(exp, lock) \
325 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
326 atomic_dec(&(exp)->exp_locks_count); \
327 __class_export_del_lock_ref(exp, lock); \
328 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
329 (exp), atomic_read(&(exp)->exp_locks_count)); \
330 class_export_put(exp); \
333 #define class_export_cb_get(exp) \
335 atomic_inc(&(exp)->exp_cb_count); \
336 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
337 (exp), atomic_read(&(exp)->exp_cb_count)); \
338 class_export_get(exp); \
341 #define class_export_cb_put(exp) \
343 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
344 atomic_dec(&(exp)->exp_cb_count); \
345 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
346 (exp), atomic_read(&(exp)->exp_cb_count)); \
347 class_export_put(exp); \
351 struct obd_export *class_export_get(struct obd_export *exp);
352 void class_export_put(struct obd_export *exp);
353 struct obd_export *class_new_export(struct obd_device *obd,
354 struct obd_uuid *cluuid);
355 struct obd_export *class_new_export_self(struct obd_device *obd,
356 struct obd_uuid *uuid);
357 void class_unlink_export(struct obd_export *exp);
359 struct obd_import *class_import_get(struct obd_import *);
360 void class_import_put(struct obd_import *);
361 struct obd_import *class_new_import(struct obd_device *obd);
362 void class_destroy_import(struct obd_import *exp);
364 #ifdef HAVE_SERVER_SUPPORT
365 struct obd_type *class_search_type(const char *name);
366 struct obd_type *class_get_type(const char *name);
368 void class_put_type(struct obd_type *type);
369 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
370 struct obd_uuid *cluuid);
371 int class_disconnect(struct obd_export *exp);
372 void class_fail_export(struct obd_export *exp);
373 int class_connected_export(struct obd_export *exp);
374 void class_disconnect_exports(struct obd_device *obd);
375 int class_manual_cleanup(struct obd_device *obd);
376 void class_disconnect_stale_exports(struct obd_device *,
377 int (*test_export)(struct obd_export *));
379 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
381 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
382 (obd->obd_force ? OBD_OPT_FORCE : 0) |
383 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
387 #ifdef HAVE_SERVER_SUPPORT
388 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
390 LASSERT(exp->exp_obd);
391 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
393 return exp->exp_obd->u.obt.obt_lut;
396 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
398 LASSERT(obd->u.obt.obt_lut);
399 return &obd->u.obt.obt_lut->lut_lsd;
407 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
408 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
410 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
411 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
413 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
414 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
416 static inline int obd_check_dev(struct obd_device *obd)
419 CERROR("NULL device\n");
425 /* ensure obd_setup and !obd_stopping */
426 #define OBD_CHECK_DEV_ACTIVE(obd) \
428 rc = obd_check_dev(obd); \
432 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
433 CERROR("Device %d not setup\n", \
440 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
442 /* Always add in ldlm_stats */
443 tmp->nid_ldlm_stats =
444 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
445 LPROCFS_STATS_FLAG_NOPERCPU);
446 if (tmp->nid_ldlm_stats == NULL)
449 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
451 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
452 tmp->nid_ldlm_stats);
455 static inline int exp_check_ops(struct obd_export *exp)
460 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
466 static inline int class_devno_max(void)
468 return MAX_OBD_DEVICES;
471 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
472 __u32 keylen, void *key,
473 __u32 *vallen, void *val)
478 rc = exp_check_ops(exp);
482 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
483 CERROR("%s: no %s operation\n",
484 (exp)->exp_obd->obd_name, __func__);
488 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
492 static inline int obd_set_info_async(const struct lu_env *env,
493 struct obd_export *exp,
494 __u32 keylen, void *key,
495 __u32 vallen, void *val,
496 struct ptlrpc_request_set *set)
501 rc = exp_check_ops(exp);
505 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
506 CERROR("%s: no %s operation\n",
507 (exp)->exp_obd->obd_name, __func__);
511 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
517 * obd-lu integration.
519 * Functionality is being moved into new lu_device-based layering, but some
520 * pieces of configuration process are still based on obd devices.
522 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
523 * subsume ->o_setup() methods of obd devices they replace. The same for
524 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
525 * result, obd_setup() and obd_process_config() branch and call one XOR
528 * Yet neither lu_device_type_operations::ldto_device_fini() nor
529 * lu_device_type_operations::ldto_device_free() fully implement the
530 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
531 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
533 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
536 struct obd_type *type = obd->obd_type;
537 struct lu_device_type *ldt;
541 wait_var_event(&type->typ_lu,
542 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
545 struct lu_context session_ctx;
548 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
549 session_ctx.lc_thread = NULL;
550 lu_context_enter(&session_ctx);
552 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
554 struct lu_device *dev;
555 env.le_ses = &session_ctx;
556 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
559 obd->obd_lu_dev = dev;
565 lu_context_exit(&session_ctx);
566 lu_context_fini(&session_ctx);
568 if (!obd->obd_type->typ_dt_ops->o_setup) {
569 CERROR("%s: no %s operation\n", obd->obd_name,
573 rc = OBP(obd, setup)(obd, cfg);
578 static inline int obd_precleanup(struct obd_device *obd)
581 struct lu_device_type *ldt = obd->obd_type->typ_lu;
582 struct lu_device *d = obd->obd_lu_dev;
586 if (ldt != NULL && d != NULL) {
587 struct lu_env *env = lu_env_find();
592 rc = lu_env_init(env, ldt->ldt_ctx_tags);
596 ldt->ldt_ops->ldto_device_fini(env, d);
603 if (!obd->obd_type->typ_dt_ops->o_precleanup)
606 rc = OBP(obd, precleanup)(obd);
610 static inline int obd_cleanup(struct obd_device *obd)
613 struct lu_device_type *ldt = obd->obd_type->typ_lu;
614 struct lu_device *d = obd->obd_lu_dev;
617 if (ldt != NULL && d != NULL) {
620 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
622 ldt->ldt_ops->ldto_device_free(&env, d);
624 obd->obd_lu_dev = NULL;
627 if (!obd->obd_type->typ_dt_ops->o_cleanup)
630 rc = OBP(obd, cleanup)(obd);
634 static inline void obd_cleanup_client_import(struct obd_device *obd)
638 /* If we set up but never connected, the client import will not
641 down_write(&obd->u.cli.cl_sem);
642 if (obd->u.cli.cl_import) {
643 struct obd_import *imp;
645 imp = obd->u.cli.cl_import;
646 CDEBUG(D_CONFIG, "%s: client import never connected\n",
648 ptlrpc_invalidate_import(imp);
649 client_destroy_import(imp);
650 obd->u.cli.cl_import = NULL;
652 up_write(&obd->u.cli.cl_sem);
657 static inline int obd_process_config(struct obd_device *obd, int datalen,
661 struct lu_device_type *ldt = obd->obd_type->typ_lu;
662 struct lu_device *d = obd->obd_lu_dev;
666 obd->obd_process_conf = 1;
667 if (ldt != NULL && d != NULL) {
670 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
672 rc = d->ld_ops->ldo_process_config(&env, d, data);
676 if (!obd->obd_type->typ_dt_ops->o_process_config) {
677 CERROR("%s: no %s operation\n",
678 obd->obd_name, __func__);
681 rc = OBP(obd, process_config)(obd, datalen, data);
684 obd->obd_process_conf = 0;
689 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
695 rc = exp_check_ops(exp);
699 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
700 CERROR("%s: no %s operation\n",
701 (exp)->exp_obd->obd_name, __func__);
705 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
709 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
715 rc = exp_check_ops(exp);
719 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
720 CERROR("%s: no %s operation\n",
721 (exp)->exp_obd->obd_name, __func__);
725 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
729 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
735 rc = exp_check_ops(exp);
739 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
740 CERROR("%s: no %s operation\n",
741 (exp)->exp_obd->obd_name, __func__);
745 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
750 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
756 rc = exp_check_ops(exp);
760 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
761 CERROR("%s: no %s operation\n",
762 (exp)->exp_obd->obd_name, __func__);
766 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
771 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
774 struct obd_device *obd = imp->imp_obd;
778 OBD_CHECK_DEV_ACTIVE(obd);
779 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
780 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
784 rc = OBP(obd, add_conn)(imp, uuid, priority);
788 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
790 struct obd_device *obd = imp->imp_obd;
794 OBD_CHECK_DEV_ACTIVE(obd);
795 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
796 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
800 rc = OBP(obd, del_conn)(imp, uuid);
804 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
806 struct obd_uuid *uuid;
809 if (!exp->exp_obd->obd_type ||
810 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
813 uuid = OBP(exp->exp_obd, get_uuid)(exp);
817 /** Create a new /a exp on device /a obd for the uuid /a cluuid
818 * @param exp New export handle
819 * @param d Connect data, supported flags are set, flags also understood
820 * by obd are returned.
822 static inline int obd_connect(const struct lu_env *env,
823 struct obd_export **exp,struct obd_device *obd,
824 struct obd_uuid *cluuid,
825 struct obd_connect_data *data,
829 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
833 OBD_CHECK_DEV_ACTIVE(obd);
834 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
835 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
839 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
840 /* check that only subset is granted */
841 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
842 data->ocd_connect_flags));
846 static inline int obd_reconnect(const struct lu_env *env,
847 struct obd_export *exp,
848 struct obd_device *obd,
849 struct obd_uuid *cluuid,
850 struct obd_connect_data *d,
854 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
859 OBD_CHECK_DEV_ACTIVE(obd);
860 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
863 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
864 /* check that only subset is granted */
865 LASSERT(ergo(d != NULL,
866 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
870 static inline int obd_disconnect(struct obd_export *exp)
874 rc = exp_check_ops(exp);
878 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
879 CERROR("%s: no %s operation\n",
880 (exp)->exp_obd->obd_name, __func__);
884 rc = OBP(exp->exp_obd, disconnect)(exp);
888 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
889 enum lu_cli_type type)
894 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
897 rc = OBP(obd, fid_init)(obd, exp, type);
901 static inline int obd_fid_fini(struct obd_device *obd)
905 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
908 rc = OBP(obd, fid_fini)(obd);
912 static inline int obd_fid_alloc(const struct lu_env *env,
913 struct obd_export *exp,
915 struct md_op_data *op_data)
919 rc = exp_check_ops(exp);
923 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
924 CERROR("%s: no %s operation\n",
925 (exp)->exp_obd->obd_name, __func__);
929 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
933 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
938 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
939 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
943 rc = OBP(obd, pool_new)(obd, poolname);
947 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
951 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
952 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
956 rc = OBP(obd, pool_del)(obd, poolname);
960 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
966 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
967 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
971 rc = OBP(obd, pool_add)(obd, poolname, ostname);
975 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
981 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
982 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
986 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
990 static inline int obd_init_export(struct obd_export *exp)
995 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
996 OBP((exp)->exp_obd, init_export))
997 rc = OBP(exp->exp_obd, init_export)(exp);
1001 static inline int obd_destroy_export(struct obd_export *exp)
1004 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1005 OBP(exp->exp_obd, destroy_export))
1006 OBP(exp->exp_obd, destroy_export)(exp);
1010 /* @max_age is the oldest time in seconds that we accept using a cached data.
1011 * If the cache is older than @max_age we will get a new value from the
1012 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1014 static inline int obd_statfs_async(struct obd_export *exp,
1015 struct obd_info *oinfo,
1017 struct ptlrpc_request_set *rqset)
1019 struct obd_device *obd;
1024 if (exp == NULL || exp->exp_obd == NULL)
1028 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1030 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1034 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1035 obd->obd_name, obd->obd_osfs_age, max_age);
1036 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1041 /* @max_age is the oldest time in seconds that we accept using a cached data.
1042 * If the cache is older than @max_age we will get a new value from the
1043 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1045 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1046 struct obd_statfs *osfs, time64_t max_age,
1049 struct obd_device *obd;
1053 if (unlikely(exp == NULL || exp->exp_obd == NULL))
1057 OBD_CHECK_DEV_ACTIVE(obd);
1059 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1060 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1061 RETURN(-EOPNOTSUPP);
1064 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1065 obd->obd_name, obd->obd_osfs_age, max_age);
1066 /* ignore cache if aggregated isn't expected */
1067 if (obd->obd_osfs_age < max_age ||
1068 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1069 !(flags & OBD_STATFS_SUM))) {
1070 /* the RPC will block anyway, so avoid sending many at once */
1071 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1072 (flags & OBD_STATFS_NESTED)
1073 ? SINGLE_DEPTH_NESTING : 0);
1076 if (obd->obd_osfs_age < max_age ||
1077 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1078 !(flags & OBD_STATFS_SUM))) {
1079 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1081 mutex_unlock(&obd->obd_dev_mutex);
1082 GOTO(cached, rc = 0);
1086 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1087 obd->obd_name, &obd->obd_osfs,
1088 osfs->os_bavail, osfs->os_blocks,
1089 osfs->os_ffree, osfs->os_files);
1091 spin_lock(&obd->obd_osfs_lock);
1092 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1093 obd->obd_osfs_age = ktime_get_seconds();
1094 spin_unlock(&obd->obd_osfs_lock);
1096 mutex_unlock(&obd->obd_dev_mutex);
1100 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1101 obd->obd_name, &obd->obd_osfs,
1102 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1103 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1104 spin_lock(&obd->obd_osfs_lock);
1105 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1106 spin_unlock(&obd->obd_osfs_lock);
1111 static inline int obd_preprw(const struct lu_env *env, int cmd,
1112 struct obd_export *exp, struct obdo *oa,
1113 int objcount, struct obd_ioobj *obj,
1114 struct niobuf_remote *remote, int *pages,
1115 struct niobuf_local *local)
1121 rc = exp_check_ops(exp);
1125 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1126 CERROR("%s: no %s operation\n",
1127 (exp)->exp_obd->obd_name, __func__);
1131 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1137 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1138 struct obd_export *exp, struct obdo *oa,
1139 int objcount, struct obd_ioobj *obj,
1140 struct niobuf_remote *rnb, int pages,
1141 struct niobuf_local *local, const int orig_rc,
1142 int nob, ktime_t kstart)
1147 rc = exp_check_ops(exp);
1151 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1152 CERROR("%s: no %s operation\n",
1153 (exp)->exp_obd->obd_name, __func__);
1157 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1158 rnb, pages, local, orig_rc, nob,
1164 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1165 int len, void *karg, void __user *uarg)
1170 rc = exp_check_ops(exp);
1174 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1175 CERROR("%s: no %s operation\n",
1176 (exp)->exp_obd->obd_name, __func__);
1180 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1184 static inline void obd_import_event(struct obd_device *obd,
1185 struct obd_import *imp,
1186 enum obd_import_event event)
1190 CERROR("NULL device\n");
1195 if (obd->obd_set_up && OBP(obd, import_event))
1196 OBP(obd, import_event)(obd, imp, event);
1201 static inline int obd_notify(struct obd_device *obd,
1202 struct obd_device *watched,
1203 enum obd_notify_event ev)
1208 rc = obd_check_dev(obd);
1212 if (!obd->obd_set_up) {
1213 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1217 if (!OBP(obd, notify)) {
1218 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1222 rc = OBP(obd, notify)(obd, watched, ev);
1227 static inline int obd_notify_observer(struct obd_device *observer,
1228 struct obd_device *observed,
1229 enum obd_notify_event ev)
1233 struct obd_notify_upcall *onu;
1235 if (observer->obd_observer)
1236 rc = obd_notify(observer->obd_observer, observed, ev);
1239 * Also, call non-obd listener, if any
1241 onu = &observer->obd_upcall;
1242 if (onu->onu_upcall != NULL)
1243 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1245 return rc ? rc : rc2;
1248 static inline int obd_quotactl(struct obd_export *exp,
1249 struct obd_quotactl *oqctl)
1254 rc = exp_check_ops(exp);
1258 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1259 CERROR("%s: no %s operation\n",
1260 (exp)->exp_obd->obd_name, __func__);
1264 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1268 static inline int obd_health_check(const struct lu_env *env,
1269 struct obd_device *obd)
1271 /* returns: 0 on healthy
1272 * >0 on unhealthy + reason code/flag
1273 * however the only suppored reason == 1 right now
1274 * We'll need to define some better reasons
1275 * or flags in the future.
1282 /* NULL method is normal here */
1283 if (obd == NULL || !obd->obd_type) {
1284 CERROR("cleaned up obd\n");
1285 RETURN(-EOPNOTSUPP);
1287 if (!obd->obd_set_up || obd->obd_stopping)
1289 if (!OBP(obd, health_check))
1292 rc = OBP(obd, health_check)(env, obd);
1296 static inline int obd_register_observer(struct obd_device *obd,
1297 struct obd_device *observer)
1302 rc = obd_check_dev(obd);
1306 down_write(&obd->obd_observer_link_sem);
1307 if (obd->obd_observer && observer) {
1308 up_write(&obd->obd_observer_link_sem);
1311 obd->obd_observer = observer;
1312 up_write(&obd->obd_observer_link_sem);
1316 /* metadata helpers */
1322 LPROC_MD_INTENT_LOCK,
1331 LPROC_MD_INTENT_GETATTR_ASYNC,
1332 LPROC_MD_REVALIDATE_LOCK,
1336 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1341 rc = exp_check_ops(exp);
1345 return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1348 static inline int md_getattr(struct obd_export *exp,
1349 struct md_op_data *op_data,
1350 struct ptlrpc_request **request)
1354 rc = exp_check_ops(exp);
1358 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1361 return MDP(exp->exp_obd, getattr)(exp, op_data, request);
1364 static inline int md_null_inode(struct obd_export *exp,
1365 const struct lu_fid *fid)
1369 rc = exp_check_ops(exp);
1373 return MDP(exp->exp_obd, null_inode)(exp, fid);
1376 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1377 struct md_open_data *mod,
1378 struct ptlrpc_request **request)
1382 rc = exp_check_ops(exp);
1386 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1389 return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1392 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1393 const void *data, size_t datalen, umode_t mode,
1394 uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1395 __u64 rdev, struct ptlrpc_request **request)
1399 rc = exp_check_ops(exp);
1403 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1406 return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1407 uid, gid, cap_effective, rdev,
1411 static inline int md_enqueue(struct obd_export *exp,
1412 struct ldlm_enqueue_info *einfo,
1413 const union ldlm_policy_data *policy,
1414 struct md_op_data *op_data,
1415 struct lustre_handle *lockh,
1416 __u64 extra_lock_flags)
1420 rc = exp_check_ops(exp);
1424 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1427 return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1431 static inline int md_getattr_name(struct obd_export *exp,
1432 struct md_op_data *op_data,
1433 struct ptlrpc_request **request)
1437 rc = exp_check_ops(exp);
1441 return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1444 static inline int md_intent_lock(struct obd_export *exp,
1445 struct md_op_data *op_data,
1446 struct lookup_intent *it,
1447 struct ptlrpc_request **reqp,
1448 ldlm_blocking_callback cb_blocking,
1449 __u64 extra_lock_flags)
1453 rc = exp_check_ops(exp);
1457 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1458 LPROC_MD_INTENT_LOCK);
1460 return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1461 cb_blocking, extra_lock_flags);
1464 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1465 struct ptlrpc_request **request)
1469 rc = exp_check_ops(exp);
1473 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1476 return MDP(exp->exp_obd, link)(exp, op_data, request);
1479 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1480 const char *old_name, size_t oldlen,
1481 const char *new_name, size_t newlen,
1482 struct ptlrpc_request **request)
1486 rc = exp_check_ops(exp);
1490 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1493 return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
1494 new_name, newlen, request);
1497 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1498 void *ea, size_t ealen,
1499 struct ptlrpc_request **request)
1503 rc = exp_check_ops(exp);
1507 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1510 return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1513 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1514 struct ptlrpc_request **request)
1518 rc = exp_check_ops(exp);
1522 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1525 return MDP(exp->exp_obd, fsync)(exp, fid, request);
1528 /* FLR: resync mirrored files. */
1529 static inline int md_file_resync(struct obd_export *exp,
1530 struct md_op_data *data)
1534 rc = exp_check_ops(exp);
1538 return MDP(exp->exp_obd, file_resync)(exp, data);
1541 static inline int md_read_page(struct obd_export *exp,
1542 struct md_op_data *op_data,
1543 struct md_readdir_info *mrinfo,
1544 __u64 hash_offset, struct page **ppage)
1548 rc = exp_check_ops(exp);
1552 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1553 LPROC_MD_READ_PAGE);
1555 return MDP(exp->exp_obd, read_page)(exp, op_data, mrinfo, hash_offset,
1559 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1560 struct ptlrpc_request **request)
1564 rc = exp_check_ops(exp);
1568 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1571 return MDP(exp->exp_obd, unlink)(exp, op_data, request);
1574 static inline int md_get_lustre_md(struct obd_export *exp,
1575 struct req_capsule *pill,
1576 struct obd_export *dt_exp,
1577 struct obd_export *md_exp,
1578 struct lustre_md *md)
1582 rc = exp_check_ops(exp);
1586 return MDP(exp->exp_obd, get_lustre_md)(exp, pill, dt_exp, md_exp, md);
1589 static inline int md_free_lustre_md(struct obd_export *exp,
1590 struct lustre_md *md)
1594 rc = exp_check_ops(exp);
1598 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1601 static inline int md_merge_attr(struct obd_export *exp,
1602 const struct lmv_stripe_md *lsm,
1603 struct cl_attr *attr,
1604 ldlm_blocking_callback cb)
1608 rc = exp_check_ops(exp);
1612 return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb);
1615 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1616 u64 obd_md_valid, const char *name,
1617 const void *value, size_t value_size,
1618 unsigned int xattr_flags, u32 suppgid,
1619 struct ptlrpc_request **req)
1623 rc = exp_check_ops(exp);
1627 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1630 return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1631 value, value_size, xattr_flags,
1635 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1636 u64 obd_md_valid, const char *name,
1637 size_t buf_size, struct ptlrpc_request **req)
1641 rc = exp_check_ops(exp);
1645 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1648 return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1652 static inline int md_set_open_replay_data(struct obd_export *exp,
1653 struct obd_client_handle *och,
1654 struct lookup_intent *it)
1658 rc = exp_check_ops(exp);
1662 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1665 static inline int md_clear_open_replay_data(struct obd_export *exp,
1666 struct obd_client_handle *och)
1670 rc = exp_check_ops(exp);
1674 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1677 static inline int md_set_lock_data(struct obd_export *exp,
1678 const struct lustre_handle *lockh,
1679 void *data, __u64 *bits)
1683 rc = exp_check_ops(exp);
1687 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1691 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1692 union ldlm_policy_data *policy, enum ldlm_mode mode,
1693 enum ldlm_cancel_flags cancel_flags, void *opaque)
1697 rc = exp_check_ops(exp);
1701 return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1702 cancel_flags, opaque);
1705 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1706 const struct lu_fid *fid,
1707 enum ldlm_type type,
1708 union ldlm_policy_data *policy,
1709 enum ldlm_mode mode,
1710 struct lustre_handle *lockh)
1714 rc = exp_check_ops(exp);
1718 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1719 policy, mode, lockh);
1722 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1727 rc = exp_check_ops(exp);
1731 return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
1734 static inline int md_intent_getattr_async(struct obd_export *exp,
1735 struct md_enqueue_info *minfo)
1739 rc = exp_check_ops(exp);
1743 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1744 LPROC_MD_INTENT_GETATTR_ASYNC);
1746 return MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1749 static inline int md_revalidate_lock(struct obd_export *exp,
1750 struct lookup_intent *it,
1751 struct lu_fid *fid, __u64 *bits)
1755 rc = exp_check_ops(exp);
1759 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1760 LPROC_MD_REVALIDATE_LOCK);
1762 return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1765 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1766 const struct lmv_stripe_md *lsm,
1767 const char *name, int namelen,
1772 rc = exp_check_ops(exp);
1776 return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
1780 /* Unpack an MD struct from disk to in-memory format.
1781 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1783 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1784 * If *plsm == NULL then it will be allocated.
1786 static inline int md_unpackmd(struct obd_export *exp,
1787 struct lmv_stripe_md **plsm,
1788 const union lmv_mds_md *lmm, size_t lmm_size)
1792 rc = exp_check_ops(exp);
1796 return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1799 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1800 int *rcs, struct ptlrpc_request_set *set)
1804 rc = exp_check_ops(exp);
1808 return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
1811 /* OBD Metadata Support */
1813 extern int obd_init_caches(void);
1814 extern void obd_cleanup_caches(void);
1816 typedef int (*register_lwp_cb)(void *data);
1818 struct lwp_register_item {
1819 struct obd_export **lri_exp;
1820 register_lwp_cb lri_cb_func;
1822 struct list_head lri_list;
1824 char lri_name[MTI_NAME_MAXLEN];
1828 #ifdef HAVE_SERVER_SUPPORT
1829 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1830 register_lwp_cb cb_func, void *cb_data);
1831 void lustre_deregister_lwp_item(struct obd_export **exp);
1832 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1833 void lustre_notify_lwp_list(struct obd_export *exp);
1834 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1835 int lustre_tgt_register_fs(void);
1836 void lustre_tgt_unregister_fs(void);
1837 #endif /* HAVE_SERVER_SUPPORT */
1838 int lustre_check_exclusion(struct super_block *sb, char *svname);
1841 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
1843 int class_add_uuid(const char *uuid, __u64 nid);
1844 int class_del_uuid (const char *uuid);
1845 int class_add_nids_to_uuid(struct obd_uuid *uuid, lnet_nid_t *nids,
1847 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1850 extern char obd_jobid_name[];
1852 extern unsigned int obd_lbug_on_eviction;
1853 extern unsigned int obd_dump_on_eviction;
1855 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
1857 if (obd_lbug_on_eviction &&
1858 strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
1859 strlen(LUSTRE_MGC_NAME))) {
1860 CERROR("LBUG upon eviction\n");
1864 return obd_dump_on_eviction;
1869 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1870 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1872 /* root squash info */
1873 struct root_squash_info {
1876 struct list_head rsi_nosquash_nids;
1877 spinlock_t rsi_lock;
1880 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1882 /* linux-module.c */
1883 struct obd_ioctl_data;
1884 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
1885 int class_procfs_init(void);
1886 int class_procfs_clean(void);
1888 extern void obd_heat_add(struct obd_heat_instance *instance,
1889 unsigned int time_second, __u64 count,
1890 unsigned int weight, unsigned int period_second);
1891 extern void obd_heat_decay(struct obd_heat_instance *instance,
1892 __u64 time_second, unsigned int weight,
1893 unsigned int period_second);
1894 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
1895 unsigned int time_second, unsigned int weight,
1896 unsigned int period_second);
1897 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
1898 #endif /* __LINUX_OBD_CLASS_H */