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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
35 #include <linux/kobject.h>
36 #include <obd_support.h>
37 #include <lustre_import.h>
38 #include <lustre_net.h>
40 #include <lustre_lib.h>
41 #include <uapi/linux/lustre/lustre_idl.h>
42 #include <lprocfs_status.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 struct ldebugfs_vars *module_vars,
78 const char *nm, struct lu_device_type *ldt);
79 int class_unregister_type(const char *nm);
81 struct obd_device *class_newdev(const char *type_name, const char *name,
83 int class_register_device(struct obd_device *obd);
84 void class_unregister_device(struct obd_device *obd);
85 void class_free_dev(struct obd_device *obd);
87 struct obd_device *class_dev_by_str(const char *str);
88 int class_name2dev(const char *name);
89 struct obd_device *class_name2obd(const char *name);
90 int class_uuid2dev(struct obd_uuid *uuid);
91 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
92 void class_obd_list(void);
93 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
94 const char *type_name,
95 struct obd_uuid *grp_uuid);
96 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
98 struct obd_device *class_num2obd(int num);
99 int get_devices_count(void);
101 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
103 static inline char *obd_export_nid2str(struct obd_export *exp)
105 return exp->exp_connection == NULL ?
106 "<unknown>" : libcfs_nid2str(exp->exp_connection->c_peer.nid);
109 static inline char *obd_import_nid2str(struct obd_import *imp)
111 return imp->imp_connection == NULL ?
112 "<unknown>" : libcfs_nid2str(imp->imp_connection->c_peer.nid);
115 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
116 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
117 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
120 int obd_zombie_impexp_init(void);
121 void obd_zombie_impexp_stop(void);
122 void obd_zombie_impexp_cull(void);
123 void obd_zombie_barrier(void);
124 void obd_exports_barrier(struct obd_device *obd);
125 int kuc_len(int payload_len);
126 struct kuc_hdr * kuc_ptr(void *p);
127 void *kuc_alloc(int payload_len, int transport, int type);
128 void kuc_free(void *p, int payload_len);
129 int obd_get_request_slot(struct client_obd *cli);
130 void obd_put_request_slot(struct client_obd *cli);
131 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
132 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
133 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
134 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
135 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
137 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
138 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
142 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
143 struct llog_rec_hdr *, void *);
145 struct obd_export *obd_stale_export_get(void);
146 void obd_stale_export_put(struct obd_export *exp);
147 void obd_stale_export_adjust(struct obd_export *exp);
150 /* For interoperability */
151 struct cfg_interop_param {
156 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
157 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
158 const char *new_name);
159 void print_lustre_cfg(struct lustre_cfg *lcfg);
160 int class_process_config(struct lustre_cfg *lcfg);
161 ssize_t class_set_global(const char *param);
162 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
163 struct kobject *kobj);
164 int class_attach(struct lustre_cfg *lcfg);
165 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
166 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
167 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
169 int class_find_param(char *buf, char *key, char **valp);
170 struct cfg_interop_param *class_find_old_param(const char *param,
171 struct cfg_interop_param *ptr);
172 int class_get_next_param(char **params, char *copy);
173 int class_match_param(char *buf, const char *key, char **valp);
174 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
175 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
176 int class_parse_net(char *buf, u32 *net, char **endh);
177 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
178 int class_match_net(char *buf, char *key, u32 net);
180 struct obd_device *class_incref(struct obd_device *obd,
181 const char *scope, const void *source);
182 void class_decref(struct obd_device *obd,
183 const char *scope, const void *source);
184 void dump_exports(struct obd_device *obd, int locks, int debug_level);
185 int class_config_llog_handler(const struct lu_env *env,
186 struct llog_handle *handle,
187 struct llog_rec_hdr *rec, void *data);
188 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
190 #define CFG_F_START 0x01 /* Set when we start updating from a log */
191 #define CFG_F_MARKER 0x02 /* We are within a maker */
192 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
193 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
195 /* Passed as data param to class_config_parse_llog */
196 struct config_llog_instance {
197 unsigned long cfg_instance;
198 struct super_block *cfg_sb;
199 struct obd_uuid cfg_uuid;
200 llog_cb_t cfg_callback;
201 int cfg_last_idx; /* for partial llog processing */
206 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
207 char *name, struct config_llog_instance *cfg);
210 * Generate a unique configuration instance for this mount
212 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
213 * For now, use the same value as before - the superblock pointer value.
215 * Using the client UUID would be an option, but it needs more testing.
217 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
219 return (unsigned long)sb;
222 #define CONFIG_SUB_SPTLRPC 0x01
223 #define CONFIG_SUB_RECOVER 0x02
224 #define CONFIG_SUB_PARAMS 0x04
225 #define CONFIG_SUB_NODEMAP 0x08
226 #define CONFIG_SUB_BARRIER 0x10
228 /* Sub clds should be attached to the config_llog_data when processing
229 * config log for client or server target. */
230 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
232 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
235 #define PARAMS_FILENAME "params"
236 #define BARRIER_FILENAME "barrier"
237 #define LCTL_UPCALL "lctl"
239 static inline bool logname_is_barrier(const char *logname)
243 /* logname for barrier is "fsname-barrier" */
244 ptr = strstr(logname, BARRIER_FILENAME);
245 if (ptr && (ptr - logname) >= 2 &&
246 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
252 /* list of active configuration logs */
253 struct config_llog_data {
254 struct ldlm_res_id cld_resid;
255 struct lustre_handle cld_lockh;
256 struct config_llog_instance cld_cfg;
257 struct list_head cld_list_chain;/* on config_llog_list */
258 atomic_t cld_refcount;
259 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
260 struct config_llog_data *cld_params; /* common parameters log */
261 struct config_llog_data *cld_recover;/* imperative recover log */
262 struct config_llog_data *cld_nodemap;/* nodemap log */
263 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
264 struct obd_export *cld_mgcexp;
265 struct mutex cld_lock;
267 unsigned int cld_stopping:1, /* we were told to stop
269 cld_lostlock:1; /* lock not requeued */
273 struct lustre_profile {
274 struct list_head lp_list;
279 bool lp_list_deleted;
282 struct lustre_profile *class_get_profile(const char * prof);
283 void class_del_profile(const char *prof);
284 void class_put_profile(struct lustre_profile *lprof);
285 void class_del_profiles(void);
288 #if LUSTRE_TRACKS_LOCK_EXP_REFS
290 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
291 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
292 extern void (*class_export_dump_hook)(struct obd_export *);
296 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
297 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
301 #define class_export_rpc_inc(exp) \
303 atomic_inc(&(exp)->exp_rpc_count); \
304 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
305 (exp), atomic_read(&(exp)->exp_rpc_count)); \
308 #define class_export_rpc_dec(exp) \
310 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
311 atomic_dec(&(exp)->exp_rpc_count); \
312 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
313 (exp), atomic_read(&(exp)->exp_rpc_count)); \
316 #define class_export_lock_get(exp, lock) \
318 atomic_inc(&(exp)->exp_locks_count); \
319 __class_export_add_lock_ref(exp, lock); \
320 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
321 (exp), atomic_read(&(exp)->exp_locks_count)); \
322 class_export_get(exp); \
325 #define class_export_lock_put(exp, lock) \
327 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
328 atomic_dec(&(exp)->exp_locks_count); \
329 __class_export_del_lock_ref(exp, lock); \
330 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
331 (exp), atomic_read(&(exp)->exp_locks_count)); \
332 class_export_put(exp); \
335 #define class_export_cb_get(exp) \
337 atomic_inc(&(exp)->exp_cb_count); \
338 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
339 (exp), atomic_read(&(exp)->exp_cb_count)); \
340 class_export_get(exp); \
343 #define class_export_cb_put(exp) \
345 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
346 atomic_dec(&(exp)->exp_cb_count); \
347 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
348 (exp), atomic_read(&(exp)->exp_cb_count)); \
349 class_export_put(exp); \
353 struct obd_export *class_export_get(struct obd_export *exp);
354 void class_export_put(struct obd_export *exp);
355 struct obd_export *class_new_export(struct obd_device *obd,
356 struct obd_uuid *cluuid);
357 struct obd_export *class_new_export_self(struct obd_device *obd,
358 struct obd_uuid *uuid);
359 void class_unlink_export(struct obd_export *exp);
361 struct obd_import *class_import_get(struct obd_import *);
362 void class_import_put(struct obd_import *);
363 struct obd_import *class_new_import(struct obd_device *obd);
364 void class_destroy_import(struct obd_import *exp);
366 #ifdef HAVE_SERVER_SUPPORT
367 struct obd_type *class_search_type(const char *name);
368 struct obd_type *class_get_type(const char *name);
370 void class_put_type(struct obd_type *type);
371 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
372 struct obd_uuid *cluuid);
373 int class_disconnect(struct obd_export *exp);
374 void class_fail_export(struct obd_export *exp);
375 int class_connected_export(struct obd_export *exp);
376 void class_disconnect_exports(struct obd_device *obd);
377 int class_manual_cleanup(struct obd_device *obd);
378 void class_disconnect_stale_exports(struct obd_device *,
379 int (*test_export)(struct obd_export *));
381 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
383 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
384 (obd->obd_force ? OBD_OPT_FORCE : 0) |
385 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
389 #ifdef HAVE_SERVER_SUPPORT
390 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
392 LASSERT(exp->exp_obd);
393 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
395 return exp->exp_obd->u.obt.obt_lut;
398 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
400 LASSERT(obd->u.obt.obt_lut);
401 return &obd->u.obt.obt_lut->lut_lsd;
409 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
410 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
412 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
413 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
415 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
416 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
418 static inline int obd_check_dev(struct obd_device *obd)
421 CERROR("NULL device\n");
427 /* ensure obd_setup and !obd_stopping */
428 #define OBD_CHECK_DEV_ACTIVE(obd) \
430 rc = obd_check_dev(obd); \
434 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
435 CERROR("Device %d not setup\n", \
442 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
444 /* Always add in ldlm_stats */
445 tmp->nid_ldlm_stats =
446 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
447 LPROCFS_STATS_FLAG_NOPERCPU);
448 if (tmp->nid_ldlm_stats == NULL)
451 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
453 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
454 tmp->nid_ldlm_stats);
457 static inline int exp_check_ops(struct obd_export *exp)
462 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
468 static inline int class_devno_max(void)
470 return MAX_OBD_DEVICES;
473 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
474 __u32 keylen, void *key,
475 __u32 *vallen, void *val)
480 rc = exp_check_ops(exp);
484 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
485 CERROR("%s: no %s operation\n",
486 (exp)->exp_obd->obd_name, __func__);
490 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
494 static inline int obd_set_info_async(const struct lu_env *env,
495 struct obd_export *exp,
496 __u32 keylen, void *key,
497 __u32 vallen, void *val,
498 struct ptlrpc_request_set *set)
503 rc = exp_check_ops(exp);
507 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
508 CERROR("%s: no %s operation\n",
509 (exp)->exp_obd->obd_name, __func__);
513 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
519 * obd-lu integration.
521 * Functionality is being moved into new lu_device-based layering, but some
522 * pieces of configuration process are still based on obd devices.
524 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
525 * subsume ->o_setup() methods of obd devices they replace. The same for
526 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
527 * result, obd_setup() and obd_process_config() branch and call one XOR
530 * Yet neither lu_device_type_operations::ldto_device_fini() nor
531 * lu_device_type_operations::ldto_device_free() fully implement the
532 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
533 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
535 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
538 struct obd_type *type = obd->obd_type;
539 struct lu_device_type *ldt;
543 wait_var_event(&type->typ_lu,
544 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
547 struct lu_context session_ctx;
550 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
551 session_ctx.lc_thread = NULL;
552 lu_context_enter(&session_ctx);
554 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
556 struct lu_device *dev;
557 env.le_ses = &session_ctx;
558 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
561 obd->obd_lu_dev = dev;
567 lu_context_exit(&session_ctx);
568 lu_context_fini(&session_ctx);
570 if (!obd->obd_type->typ_dt_ops->o_setup) {
571 CERROR("%s: no %s operation\n", obd->obd_name,
575 rc = OBP(obd, setup)(obd, cfg);
580 static inline int obd_precleanup(struct obd_device *obd)
583 struct lu_device_type *ldt = obd->obd_type->typ_lu;
584 struct lu_device *d = obd->obd_lu_dev;
588 if (ldt != NULL && d != NULL) {
589 struct lu_env *env = lu_env_find();
594 rc = lu_env_init(env, ldt->ldt_ctx_tags);
598 ldt->ldt_ops->ldto_device_fini(env, d);
605 if (!obd->obd_type->typ_dt_ops->o_precleanup)
608 rc = OBP(obd, precleanup)(obd);
612 static inline int obd_cleanup(struct obd_device *obd)
615 struct lu_device_type *ldt = obd->obd_type->typ_lu;
616 struct lu_device *d = obd->obd_lu_dev;
619 if (ldt != NULL && d != NULL) {
622 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
624 ldt->ldt_ops->ldto_device_free(&env, d);
626 obd->obd_lu_dev = NULL;
629 if (!obd->obd_type->typ_dt_ops->o_cleanup)
632 rc = OBP(obd, cleanup)(obd);
636 static inline void obd_cleanup_client_import(struct obd_device *obd)
640 /* If we set up but never connected, the
641 client import will not have been cleaned. */
642 down_write(&obd->u.cli.cl_sem);
643 if (obd->u.cli.cl_import) {
644 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 = exp->exp_obd;
1053 if (unlikely(obd == NULL))
1056 OBD_CHECK_DEV_ACTIVE(obd);
1058 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1059 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1060 RETURN(-EOPNOTSUPP);
1063 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1064 obd->obd_name, obd->obd_osfs_age, max_age);
1065 /* ignore cache if aggregated isn't expected */
1066 if (obd->obd_osfs_age < max_age ||
1067 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1068 !(flags & OBD_STATFS_SUM))) {
1069 /* the RPC will block anyway, so avoid sending many at once */
1070 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1071 (flags & OBD_STATFS_NESTED)
1072 ? SINGLE_DEPTH_NESTING : 0);
1075 if (obd->obd_osfs_age < max_age ||
1076 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1077 !(flags & OBD_STATFS_SUM))) {
1078 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1080 mutex_unlock(&obd->obd_dev_mutex);
1081 GOTO(cached, rc = 0);
1085 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1086 obd->obd_name, &obd->obd_osfs,
1087 osfs->os_bavail, osfs->os_blocks,
1088 osfs->os_ffree, osfs->os_files);
1090 spin_lock(&obd->obd_osfs_lock);
1091 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1092 obd->obd_osfs_age = ktime_get_seconds();
1093 spin_unlock(&obd->obd_osfs_lock);
1095 mutex_unlock(&obd->obd_dev_mutex);
1099 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1100 obd->obd_name, &obd->obd_osfs,
1101 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1102 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1103 spin_lock(&obd->obd_osfs_lock);
1104 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1105 spin_unlock(&obd->obd_osfs_lock);
1110 static inline int obd_preprw(const struct lu_env *env, int cmd,
1111 struct obd_export *exp, struct obdo *oa,
1112 int objcount, struct obd_ioobj *obj,
1113 struct niobuf_remote *remote, int *pages,
1114 struct niobuf_local *local)
1120 rc = exp_check_ops(exp);
1124 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1125 CERROR("%s: no %s operation\n",
1126 (exp)->exp_obd->obd_name, __func__);
1130 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1136 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1137 struct obd_export *exp, struct obdo *oa,
1138 int objcount, struct obd_ioobj *obj,
1139 struct niobuf_remote *rnb, int pages,
1140 struct niobuf_local *local, const int orig_rc)
1145 rc = exp_check_ops(exp);
1149 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1150 CERROR("%s: no %s operation\n",
1151 (exp)->exp_obd->obd_name, __func__);
1155 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1156 rnb, pages, local, orig_rc);
1161 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1162 int len, void *karg, void __user *uarg)
1167 rc = exp_check_ops(exp);
1171 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1172 CERROR("%s: no %s operation\n",
1173 (exp)->exp_obd->obd_name, __func__);
1177 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1181 static inline void obd_import_event(struct obd_device *obd,
1182 struct obd_import *imp,
1183 enum obd_import_event event)
1187 CERROR("NULL device\n");
1192 if (obd->obd_set_up && OBP(obd, import_event))
1193 OBP(obd, import_event)(obd, imp, event);
1198 static inline int obd_notify(struct obd_device *obd,
1199 struct obd_device *watched,
1200 enum obd_notify_event ev)
1205 rc = obd_check_dev(obd);
1209 if (!obd->obd_set_up) {
1210 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1214 if (!OBP(obd, notify)) {
1215 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1219 rc = OBP(obd, notify)(obd, watched, ev);
1224 static inline int obd_notify_observer(struct obd_device *observer,
1225 struct obd_device *observed,
1226 enum obd_notify_event ev)
1230 struct obd_notify_upcall *onu;
1232 if (observer->obd_observer)
1233 rc = obd_notify(observer->obd_observer, observed, ev);
1236 * Also, call non-obd listener, if any
1238 onu = &observer->obd_upcall;
1239 if (onu->onu_upcall != NULL)
1240 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1242 return rc ? rc : rc2;
1245 static inline int obd_quotactl(struct obd_export *exp,
1246 struct obd_quotactl *oqctl)
1251 rc = exp_check_ops(exp);
1255 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1256 CERROR("%s: no %s operation\n",
1257 (exp)->exp_obd->obd_name, __func__);
1261 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1265 static inline int obd_health_check(const struct lu_env *env,
1266 struct obd_device *obd)
1268 /* returns: 0 on healthy
1269 * >0 on unhealthy + reason code/flag
1270 * however the only suppored reason == 1 right now
1271 * We'll need to define some better reasons
1272 * or flags in the future.
1279 /* NULL method is normal here */
1280 if (obd == NULL || !obd->obd_type) {
1281 CERROR("cleaned up obd\n");
1282 RETURN(-EOPNOTSUPP);
1284 if (!obd->obd_set_up || obd->obd_stopping)
1286 if (!OBP(obd, health_check))
1289 rc = OBP(obd, health_check)(env, obd);
1293 static inline int obd_register_observer(struct obd_device *obd,
1294 struct obd_device *observer)
1299 rc = obd_check_dev(obd);
1303 down_write(&obd->obd_observer_link_sem);
1304 if (obd->obd_observer && observer) {
1305 up_write(&obd->obd_observer_link_sem);
1308 obd->obd_observer = observer;
1309 up_write(&obd->obd_observer_link_sem);
1313 /* metadata helpers */
1319 LPROC_MD_INTENT_LOCK,
1328 LPROC_MD_INTENT_GETATTR_ASYNC,
1329 LPROC_MD_REVALIDATE_LOCK,
1333 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1338 rc = exp_check_ops(exp);
1342 return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1345 static inline int md_getattr(struct obd_export *exp,
1346 struct md_op_data *op_data,
1347 struct ptlrpc_request **request)
1351 rc = exp_check_ops(exp);
1355 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1358 return MDP(exp->exp_obd, getattr)(exp, op_data, request);
1361 static inline int md_null_inode(struct obd_export *exp,
1362 const struct lu_fid *fid)
1366 rc = exp_check_ops(exp);
1370 return MDP(exp->exp_obd, null_inode)(exp, fid);
1373 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1374 struct md_open_data *mod,
1375 struct ptlrpc_request **request)
1379 rc = exp_check_ops(exp);
1383 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1386 return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1389 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1390 const void *data, size_t datalen, umode_t mode,
1391 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1392 __u64 rdev, struct ptlrpc_request **request)
1396 rc = exp_check_ops(exp);
1400 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1403 return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1404 uid, gid, cap_effective, rdev,
1408 static inline int md_enqueue(struct obd_export *exp,
1409 struct ldlm_enqueue_info *einfo,
1410 const union ldlm_policy_data *policy,
1411 struct md_op_data *op_data,
1412 struct lustre_handle *lockh,
1413 __u64 extra_lock_flags)
1417 rc = exp_check_ops(exp);
1421 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1424 return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1428 static inline int md_getattr_name(struct obd_export *exp,
1429 struct md_op_data *op_data,
1430 struct ptlrpc_request **request)
1434 rc = exp_check_ops(exp);
1438 return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1441 static inline int md_intent_lock(struct obd_export *exp,
1442 struct md_op_data *op_data,
1443 struct lookup_intent *it,
1444 struct ptlrpc_request **reqp,
1445 ldlm_blocking_callback cb_blocking,
1446 __u64 extra_lock_flags)
1450 rc = exp_check_ops(exp);
1454 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1455 LPROC_MD_INTENT_LOCK);
1457 return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1458 cb_blocking, extra_lock_flags);
1461 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1462 struct ptlrpc_request **request)
1466 rc = exp_check_ops(exp);
1470 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1473 return MDP(exp->exp_obd, link)(exp, op_data, request);
1476 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1477 const char *old_name, size_t oldlen,
1478 const char *new_name, size_t newlen,
1479 struct ptlrpc_request **request)
1483 rc = exp_check_ops(exp);
1487 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1490 return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
1491 new_name, newlen, request);
1494 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1495 void *ea, size_t ealen,
1496 struct ptlrpc_request **request)
1500 rc = exp_check_ops(exp);
1504 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1507 return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1510 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1511 struct ptlrpc_request **request)
1515 rc = exp_check_ops(exp);
1519 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1522 return MDP(exp->exp_obd, fsync)(exp, fid, request);
1525 /* FLR: resync mirrored files. */
1526 static inline int md_file_resync(struct obd_export *exp,
1527 struct md_op_data *data)
1531 rc = exp_check_ops(exp);
1535 return MDP(exp->exp_obd, file_resync)(exp, data);
1538 static inline int md_read_page(struct obd_export *exp,
1539 struct md_op_data *op_data,
1540 struct md_callback *cb_op,
1542 struct page **ppage)
1546 rc = exp_check_ops(exp);
1550 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1551 LPROC_MD_READ_PAGE);
1553 return MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1557 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1558 struct ptlrpc_request **request)
1562 rc = exp_check_ops(exp);
1566 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1569 return MDP(exp->exp_obd, unlink)(exp, op_data, request);
1572 static inline int md_get_lustre_md(struct obd_export *exp,
1573 struct ptlrpc_request *req,
1574 struct obd_export *dt_exp,
1575 struct obd_export *md_exp,
1576 struct lustre_md *md)
1580 rc = exp_check_ops(exp);
1584 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1587 static inline int md_free_lustre_md(struct obd_export *exp,
1588 struct lustre_md *md)
1592 rc = exp_check_ops(exp);
1596 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1599 static inline int md_merge_attr(struct obd_export *exp,
1600 const struct lu_fid *fid,
1601 const struct lmv_stripe_md *lsm,
1602 struct cl_attr *attr,
1603 ldlm_blocking_callback cb)
1607 rc = exp_check_ops(exp);
1611 return MDP(exp->exp_obd, merge_attr)(exp, fid, lsm, attr, cb);
1614 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1615 u64 obd_md_valid, const char *name,
1616 const void *value, size_t value_size,
1617 unsigned int xattr_flags, u32 suppgid,
1618 struct ptlrpc_request **req)
1622 rc = exp_check_ops(exp);
1626 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1629 return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1630 value, value_size, xattr_flags,
1634 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1635 u64 obd_md_valid, const char *name,
1636 size_t buf_size, struct ptlrpc_request **req)
1640 rc = exp_check_ops(exp);
1644 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1647 return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1651 static inline int md_set_open_replay_data(struct obd_export *exp,
1652 struct obd_client_handle *och,
1653 struct lookup_intent *it)
1657 rc = exp_check_ops(exp);
1661 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1664 static inline int md_clear_open_replay_data(struct obd_export *exp,
1665 struct obd_client_handle *och)
1669 rc = exp_check_ops(exp);
1673 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1676 static inline int md_set_lock_data(struct obd_export *exp,
1677 const struct lustre_handle *lockh,
1678 void *data, __u64 *bits)
1682 rc = exp_check_ops(exp);
1686 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1690 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1691 union ldlm_policy_data *policy, enum ldlm_mode mode,
1692 enum ldlm_cancel_flags cancel_flags, void *opaque)
1696 rc = exp_check_ops(exp);
1700 return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1701 cancel_flags, opaque);
1704 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1705 const struct lu_fid *fid,
1706 enum ldlm_type type,
1707 union ldlm_policy_data *policy,
1708 enum ldlm_mode mode,
1709 struct lustre_handle *lockh)
1713 rc = exp_check_ops(exp);
1717 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1718 policy, mode, lockh);
1721 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1726 rc = exp_check_ops(exp);
1730 return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
1733 static inline int md_intent_getattr_async(struct obd_export *exp,
1734 struct md_enqueue_info *minfo)
1738 rc = exp_check_ops(exp);
1742 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1743 LPROC_MD_INTENT_GETATTR_ASYNC);
1745 return MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1748 static inline int md_revalidate_lock(struct obd_export *exp,
1749 struct lookup_intent *it,
1750 struct lu_fid *fid, __u64 *bits)
1754 rc = exp_check_ops(exp);
1758 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1759 LPROC_MD_REVALIDATE_LOCK);
1761 return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1764 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1765 const struct lmv_stripe_md *lsm,
1766 const char *name, int namelen,
1771 rc = exp_check_ops(exp);
1775 return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
1779 /* Unpack an MD struct from disk to in-memory format.
1780 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1782 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1783 * If *plsm == NULL then it will be allocated.
1785 static inline int md_unpackmd(struct obd_export *exp,
1786 struct lmv_stripe_md **plsm,
1787 const union lmv_mds_md *lmm, size_t lmm_size)
1791 rc = exp_check_ops(exp);
1795 return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1798 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1799 int *rcs, struct ptlrpc_request_set *set)
1803 rc = exp_check_ops(exp);
1807 return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
1810 /* OBD Metadata Support */
1812 extern int obd_init_caches(void);
1813 extern void obd_cleanup_caches(void);
1815 typedef int (*register_lwp_cb)(void *data);
1817 struct lwp_register_item {
1818 struct obd_export **lri_exp;
1819 register_lwp_cb lri_cb_func;
1821 struct list_head lri_list;
1823 char lri_name[MTI_NAME_MAXLEN];
1827 #ifdef HAVE_SERVER_SUPPORT
1828 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1829 register_lwp_cb cb_func, void *cb_data);
1830 void lustre_deregister_lwp_item(struct obd_export **exp);
1831 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1832 void lustre_notify_lwp_list(struct obd_export *exp);
1833 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1834 #endif /* HAVE_SERVER_SUPPORT */
1835 int lustre_register_fs(void);
1836 int lustre_unregister_fs(void);
1837 int lustre_check_exclusion(struct super_block *sb, char *svname);
1840 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1841 int class_add_uuid(const char *uuid, __u64 nid);
1842 int class_del_uuid (const char *uuid);
1843 int class_add_nids_to_uuid(struct obd_uuid *uuid, lnet_nid_t *nids,
1845 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1848 extern char obd_jobid_name[];
1852 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1853 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1855 /* root squash info */
1856 struct root_squash_info {
1859 struct list_head rsi_nosquash_nids;
1860 spinlock_t rsi_lock;
1863 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1865 /* linux-module.c */
1866 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1867 int class_procfs_init(void);
1868 int class_procfs_clean(void);
1870 extern void obd_heat_add(struct obd_heat_instance *instance,
1871 unsigned int time_second, __u64 count,
1872 unsigned int weight, unsigned int period_second);
1873 extern void obd_heat_decay(struct obd_heat_instance *instance,
1874 __u64 time_second, unsigned int weight,
1875 unsigned int period_second);
1876 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
1877 unsigned int time_second, unsigned int weight,
1878 unsigned int period_second);
1879 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
1880 #endif /* __LINUX_OBD_CLASS_H */