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 */
52 extern rwlock_t obd_dev_lock;
54 /* OBD Operations Declarations */
55 extern struct obd_device *class_exp2obd(struct obd_export *);
56 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
57 int lustre_get_jobid(char *jobid, size_t len);
58 void lustre_jobid_clear(const char *jobid);
59 void jobid_cache_fini(void);
60 int jobid_cache_init(void);
61 char *jobid_current(void);
62 int jobid_set_current(char *jobid);
64 struct lu_device_type;
67 struct obd_export *class_conn2export(struct lustre_handle *);
68 #ifdef HAVE_SERVER_SUPPORT
69 struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
71 int class_register_type(const struct obd_ops *dt_ops,
72 const struct md_ops *md_ops, bool enable_proc,
73 struct lprocfs_vars *module_vars,
74 const char *nm, struct lu_device_type *ldt);
75 int class_unregister_type(const char *nm);
77 struct obd_device *class_newdev(const char *type_name, const char *name,
79 int class_register_device(struct obd_device *obd);
80 void class_unregister_device(struct obd_device *obd);
81 void class_free_dev(struct obd_device *obd);
83 struct obd_device *class_dev_by_str(const char *str);
84 int class_name2dev(const char *name);
85 struct obd_device *class_name2obd(const char *name);
86 int class_uuid2dev(struct obd_uuid *uuid);
87 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
88 void class_obd_list(void);
89 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
90 const char *type_name,
91 struct obd_uuid *grp_uuid);
92 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
94 struct obd_device *class_num2obd(int num);
95 int get_devices_count(void);
97 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
99 static inline char *obd_export_nid2str(struct obd_export *exp)
101 return exp->exp_connection == NULL ?
102 "<unknown>" : libcfs_nid2str(exp->exp_connection->c_peer.nid);
105 static inline char *obd_import_nid2str(struct obd_import *imp)
107 return imp->imp_connection == NULL ?
108 "<unknown>" : libcfs_nid2str(imp->imp_connection->c_peer.nid);
111 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
112 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
113 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
116 int obd_zombie_impexp_init(void);
117 void obd_zombie_impexp_stop(void);
118 void obd_zombie_impexp_cull(void);
119 void obd_zombie_barrier(void);
120 void obd_exports_barrier(struct obd_device *obd);
121 int kuc_len(int payload_len);
122 struct kuc_hdr * kuc_ptr(void *p);
123 void *kuc_alloc(int payload_len, int transport, int type);
124 void kuc_free(void *p, int payload_len);
125 int obd_get_request_slot(struct client_obd *cli);
126 void obd_put_request_slot(struct client_obd *cli);
127 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
128 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
129 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
130 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
131 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
133 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
134 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
138 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
139 struct llog_rec_hdr *, void *);
141 struct obd_export *obd_stale_export_get(void);
142 void obd_stale_export_put(struct obd_export *exp);
143 void obd_stale_export_adjust(struct obd_export *exp);
146 /* For interoperability */
147 struct cfg_interop_param {
152 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
153 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
154 const char *new_name);
155 void print_lustre_cfg(struct lustre_cfg *lcfg);
156 int class_process_config(struct lustre_cfg *lcfg);
157 ssize_t class_set_global(const char *param);
158 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
159 struct kobject *kobj);
160 int class_attach(struct lustre_cfg *lcfg);
161 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
162 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
163 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
165 int class_find_param(char *buf, char *key, char **valp);
166 struct cfg_interop_param *class_find_old_param(const char *param,
167 struct cfg_interop_param *ptr);
168 int class_get_next_param(char **params, char *copy);
169 int class_match_param(char *buf, const char *key, char **valp);
170 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
171 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
172 int class_parse_net(char *buf, u32 *net, char **endh);
173 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
174 int class_match_net(char *buf, char *key, u32 net);
176 struct obd_device *class_incref(struct obd_device *obd,
177 const char *scope, const void *source);
178 void class_decref(struct obd_device *obd,
179 const char *scope, const void *source);
180 void dump_exports(struct obd_device *obd, int locks, int debug_level);
181 int class_config_llog_handler(const struct lu_env *env,
182 struct llog_handle *handle,
183 struct llog_rec_hdr *rec, void *data);
184 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
186 #define CFG_F_START 0x01 /* Set when we start updating from a log */
187 #define CFG_F_MARKER 0x02 /* We are within a maker */
188 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
189 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
191 /* Passed as data param to class_config_parse_llog */
192 struct config_llog_instance {
193 unsigned long cfg_instance;
194 struct super_block *cfg_sb;
195 struct obd_uuid cfg_uuid;
196 llog_cb_t cfg_callback;
197 int cfg_last_idx; /* for partial llog processing */
202 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
203 char *name, struct config_llog_instance *cfg);
206 * Generate a unique configuration instance for this mount
208 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
209 * For now, use the same value as before - the superblock pointer value.
211 * Using the client UUID would be an option, but it needs more testing.
213 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
215 return (unsigned long)sb;
218 #define CONFIG_SUB_SPTLRPC 0x01
219 #define CONFIG_SUB_RECOVER 0x02
220 #define CONFIG_SUB_PARAMS 0x04
221 #define CONFIG_SUB_NODEMAP 0x08
222 #define CONFIG_SUB_BARRIER 0x10
224 /* Sub clds should be attached to the config_llog_data when processing
225 * config log for client or server target. */
226 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
228 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
231 #define PARAMS_FILENAME "params"
232 #define BARRIER_FILENAME "barrier"
233 #define LCTL_UPCALL "lctl"
235 static inline bool logname_is_barrier(const char *logname)
239 /* logname for barrier is "fsname-barrier" */
240 ptr = strstr(logname, BARRIER_FILENAME);
241 if (ptr && (ptr - logname) >= 2 &&
242 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
248 /* list of active configuration logs */
249 struct config_llog_data {
250 struct ldlm_res_id cld_resid;
251 struct lustre_handle cld_lockh;
252 struct config_llog_instance cld_cfg;
253 struct list_head cld_list_chain;/* on config_llog_list */
254 atomic_t cld_refcount;
255 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
256 struct config_llog_data *cld_params; /* common parameters log */
257 struct config_llog_data *cld_recover;/* imperative recover log */
258 struct config_llog_data *cld_nodemap;/* nodemap log */
259 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
260 struct obd_export *cld_mgcexp;
261 struct mutex cld_lock;
263 unsigned int cld_stopping:1, /* we were told to stop
265 cld_lostlock:1; /* lock not requeued */
269 struct lustre_profile {
270 struct list_head lp_list;
275 bool lp_list_deleted;
278 struct lustre_profile *class_get_profile(const char * prof);
279 void class_del_profile(const char *prof);
280 void class_put_profile(struct lustre_profile *lprof);
281 void class_del_profiles(void);
284 #if LUSTRE_TRACKS_LOCK_EXP_REFS
286 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
287 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
288 extern void (*class_export_dump_hook)(struct obd_export *);
292 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
293 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
297 #define class_export_rpc_inc(exp) \
299 atomic_inc(&(exp)->exp_rpc_count); \
300 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
301 (exp), atomic_read(&(exp)->exp_rpc_count)); \
304 #define class_export_rpc_dec(exp) \
306 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
307 atomic_dec(&(exp)->exp_rpc_count); \
308 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
309 (exp), atomic_read(&(exp)->exp_rpc_count)); \
312 #define class_export_lock_get(exp, lock) \
314 atomic_inc(&(exp)->exp_locks_count); \
315 __class_export_add_lock_ref(exp, lock); \
316 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
317 (exp), atomic_read(&(exp)->exp_locks_count)); \
318 class_export_get(exp); \
321 #define class_export_lock_put(exp, lock) \
323 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
324 atomic_dec(&(exp)->exp_locks_count); \
325 __class_export_del_lock_ref(exp, lock); \
326 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
327 (exp), atomic_read(&(exp)->exp_locks_count)); \
328 class_export_put(exp); \
331 #define class_export_cb_get(exp) \
333 atomic_inc(&(exp)->exp_cb_count); \
334 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
335 (exp), atomic_read(&(exp)->exp_cb_count)); \
336 class_export_get(exp); \
339 #define class_export_cb_put(exp) \
341 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
342 atomic_dec(&(exp)->exp_cb_count); \
343 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
344 (exp), atomic_read(&(exp)->exp_cb_count)); \
345 class_export_put(exp); \
349 struct obd_export *class_export_get(struct obd_export *exp);
350 void class_export_put(struct obd_export *exp);
351 struct obd_export *class_new_export(struct obd_device *obd,
352 struct obd_uuid *cluuid);
353 struct obd_export *class_new_export_self(struct obd_device *obd,
354 struct obd_uuid *uuid);
355 void class_unlink_export(struct obd_export *exp);
357 struct obd_import *class_import_get(struct obd_import *);
358 void class_import_put(struct obd_import *);
359 struct obd_import *class_new_import(struct obd_device *obd);
360 void class_destroy_import(struct obd_import *exp);
362 #ifdef HAVE_SERVER_SUPPORT
363 struct obd_type *class_search_type(const char *name);
364 struct obd_type *class_get_type(const char *name);
366 void class_put_type(struct obd_type *type);
367 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
368 struct obd_uuid *cluuid);
369 int class_disconnect(struct obd_export *exp);
370 void class_fail_export(struct obd_export *exp);
371 int class_connected_export(struct obd_export *exp);
372 void class_disconnect_exports(struct obd_device *obd);
373 int class_manual_cleanup(struct obd_device *obd);
374 void class_disconnect_stale_exports(struct obd_device *,
375 int (*test_export)(struct obd_export *));
377 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
379 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
380 (obd->obd_force ? OBD_OPT_FORCE : 0) |
381 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
385 #ifdef HAVE_SERVER_SUPPORT
386 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
388 LASSERT(exp->exp_obd);
389 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
391 return exp->exp_obd->u.obt.obt_lut;
394 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
396 LASSERT(obd->u.obt.obt_lut);
397 return &obd->u.obt.obt_lut->lut_lsd;
405 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
406 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
408 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
409 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
411 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
412 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
414 static inline int obd_check_dev(struct obd_device *obd)
417 CERROR("NULL device\n");
423 /* ensure obd_setup and !obd_stopping */
424 #define OBD_CHECK_DEV_ACTIVE(obd) \
426 rc = obd_check_dev(obd); \
430 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
431 CERROR("Device %d not setup\n", \
438 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
440 /* Always add in ldlm_stats */
441 tmp->nid_ldlm_stats =
442 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
443 LPROCFS_STATS_FLAG_NOPERCPU);
444 if (tmp->nid_ldlm_stats == NULL)
447 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
449 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
450 tmp->nid_ldlm_stats);
453 static inline int exp_check_ops(struct obd_export *exp)
458 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
464 static inline int class_devno_max(void)
466 return MAX_OBD_DEVICES;
469 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
470 __u32 keylen, void *key,
471 __u32 *vallen, void *val)
476 rc = exp_check_ops(exp);
480 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
481 CERROR("%s: no %s operation\n",
482 (exp)->exp_obd->obd_name, __func__);
486 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
490 static inline int obd_set_info_async(const struct lu_env *env,
491 struct obd_export *exp,
492 __u32 keylen, void *key,
493 __u32 vallen, void *val,
494 struct ptlrpc_request_set *set)
499 rc = exp_check_ops(exp);
503 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
504 CERROR("%s: no %s operation\n",
505 (exp)->exp_obd->obd_name, __func__);
509 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
515 * obd-lu integration.
517 * Functionality is being moved into new lu_device-based layering, but some
518 * pieces of configuration process are still based on obd devices.
520 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
521 * subsume ->o_setup() methods of obd devices they replace. The same for
522 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
523 * result, obd_setup() and obd_process_config() branch and call one XOR
526 * Yet neither lu_device_type_operations::ldto_device_fini() nor
527 * lu_device_type_operations::ldto_device_free() fully implement the
528 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
529 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
531 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
534 struct obd_type *type = obd->obd_type;
535 struct lu_device_type *ldt;
539 wait_var_event(&type->typ_lu,
540 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
543 struct lu_context session_ctx;
546 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
547 session_ctx.lc_thread = NULL;
548 lu_context_enter(&session_ctx);
550 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
552 struct lu_device *dev;
553 env.le_ses = &session_ctx;
554 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
557 obd->obd_lu_dev = dev;
563 lu_context_exit(&session_ctx);
564 lu_context_fini(&session_ctx);
566 if (!obd->obd_type->typ_dt_ops->o_setup) {
567 CERROR("%s: no %s operation\n", obd->obd_name,
571 rc = OBP(obd, setup)(obd, cfg);
576 static inline int obd_precleanup(struct obd_device *obd)
579 struct lu_device_type *ldt = obd->obd_type->typ_lu;
580 struct lu_device *d = obd->obd_lu_dev;
584 if (ldt != NULL && d != NULL) {
585 struct lu_env *env = lu_env_find();
590 rc = lu_env_init(env, ldt->ldt_ctx_tags);
594 ldt->ldt_ops->ldto_device_fini(env, d);
601 if (!obd->obd_type->typ_dt_ops->o_precleanup)
604 rc = OBP(obd, precleanup)(obd);
608 static inline int obd_cleanup(struct obd_device *obd)
611 struct lu_device_type *ldt = obd->obd_type->typ_lu;
612 struct lu_device *d = obd->obd_lu_dev;
615 if (ldt != NULL && d != NULL) {
618 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
620 ldt->ldt_ops->ldto_device_free(&env, d);
622 obd->obd_lu_dev = NULL;
625 if (!obd->obd_type->typ_dt_ops->o_cleanup)
628 rc = OBP(obd, cleanup)(obd);
632 static inline void obd_cleanup_client_import(struct obd_device *obd)
636 /* If we set up but never connected, the
637 client import will not have been cleaned. */
638 down_write(&obd->u.cli.cl_sem);
639 if (obd->u.cli.cl_import) {
640 struct obd_import *imp;
641 imp = obd->u.cli.cl_import;
642 CDEBUG(D_CONFIG, "%s: client import never connected\n",
644 ptlrpc_invalidate_import(imp);
645 client_destroy_import(imp);
646 obd->u.cli.cl_import = NULL;
648 up_write(&obd->u.cli.cl_sem);
653 static inline int obd_process_config(struct obd_device *obd, int datalen,
657 struct lu_device_type *ldt = obd->obd_type->typ_lu;
658 struct lu_device *d = obd->obd_lu_dev;
662 obd->obd_process_conf = 1;
663 if (ldt != NULL && d != NULL) {
666 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
668 rc = d->ld_ops->ldo_process_config(&env, d, data);
672 if (!obd->obd_type->typ_dt_ops->o_process_config) {
673 CERROR("%s: no %s operation\n",
674 obd->obd_name, __func__);
677 rc = OBP(obd, process_config)(obd, datalen, data);
680 obd->obd_process_conf = 0;
685 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
691 rc = exp_check_ops(exp);
695 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
696 CERROR("%s: no %s operation\n",
697 (exp)->exp_obd->obd_name, __func__);
701 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
705 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
711 rc = exp_check_ops(exp);
715 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
716 CERROR("%s: no %s operation\n",
717 (exp)->exp_obd->obd_name, __func__);
721 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
725 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
731 rc = exp_check_ops(exp);
735 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
736 CERROR("%s: no %s operation\n",
737 (exp)->exp_obd->obd_name, __func__);
741 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
746 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
752 rc = exp_check_ops(exp);
756 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
757 CERROR("%s: no %s operation\n",
758 (exp)->exp_obd->obd_name, __func__);
762 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
767 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
770 struct obd_device *obd = imp->imp_obd;
774 OBD_CHECK_DEV_ACTIVE(obd);
775 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
776 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
780 rc = OBP(obd, add_conn)(imp, uuid, priority);
784 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
786 struct obd_device *obd = imp->imp_obd;
790 OBD_CHECK_DEV_ACTIVE(obd);
791 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
792 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
796 rc = OBP(obd, del_conn)(imp, uuid);
800 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
802 struct obd_uuid *uuid;
805 if (!exp->exp_obd->obd_type ||
806 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
809 uuid = OBP(exp->exp_obd, get_uuid)(exp);
813 /** Create a new /a exp on device /a obd for the uuid /a cluuid
814 * @param exp New export handle
815 * @param d Connect data, supported flags are set, flags also understood
816 * by obd are returned.
818 static inline int obd_connect(const struct lu_env *env,
819 struct obd_export **exp,struct obd_device *obd,
820 struct obd_uuid *cluuid,
821 struct obd_connect_data *data,
825 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
829 OBD_CHECK_DEV_ACTIVE(obd);
830 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
831 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
835 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
836 /* check that only subset is granted */
837 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
838 data->ocd_connect_flags));
842 static inline int obd_reconnect(const struct lu_env *env,
843 struct obd_export *exp,
844 struct obd_device *obd,
845 struct obd_uuid *cluuid,
846 struct obd_connect_data *d,
850 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
855 OBD_CHECK_DEV_ACTIVE(obd);
856 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
859 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
860 /* check that only subset is granted */
861 LASSERT(ergo(d != NULL,
862 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
866 static inline int obd_disconnect(struct obd_export *exp)
870 rc = exp_check_ops(exp);
874 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
875 CERROR("%s: no %s operation\n",
876 (exp)->exp_obd->obd_name, __func__);
880 rc = OBP(exp->exp_obd, disconnect)(exp);
884 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
885 enum lu_cli_type type)
890 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
893 rc = OBP(obd, fid_init)(obd, exp, type);
897 static inline int obd_fid_fini(struct obd_device *obd)
901 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
904 rc = OBP(obd, fid_fini)(obd);
908 static inline int obd_fid_alloc(const struct lu_env *env,
909 struct obd_export *exp,
911 struct md_op_data *op_data)
915 rc = exp_check_ops(exp);
919 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
920 CERROR("%s: no %s operation\n",
921 (exp)->exp_obd->obd_name, __func__);
925 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
929 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
934 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
935 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
939 rc = OBP(obd, pool_new)(obd, poolname);
943 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
947 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
948 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
952 rc = OBP(obd, pool_del)(obd, poolname);
956 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
962 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
963 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
967 rc = OBP(obd, pool_add)(obd, poolname, ostname);
971 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
977 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
978 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
982 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
986 static inline int obd_init_export(struct obd_export *exp)
991 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
992 OBP((exp)->exp_obd, init_export))
993 rc = OBP(exp->exp_obd, init_export)(exp);
997 static inline int obd_destroy_export(struct obd_export *exp)
1000 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1001 OBP(exp->exp_obd, destroy_export))
1002 OBP(exp->exp_obd, destroy_export)(exp);
1006 /* @max_age is the oldest time in seconds that we accept using a cached data.
1007 * If the cache is older than @max_age we will get a new value from the
1008 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1010 static inline int obd_statfs_async(struct obd_export *exp,
1011 struct obd_info *oinfo,
1013 struct ptlrpc_request_set *rqset)
1015 struct obd_device *obd;
1020 if (exp == NULL || exp->exp_obd == NULL)
1024 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1026 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1030 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1031 obd->obd_name, obd->obd_osfs_age, max_age);
1032 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1037 /* @max_age is the oldest time in seconds that we accept using a cached data.
1038 * If the cache is older than @max_age we will get a new value from the
1039 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1041 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1042 struct obd_statfs *osfs, time64_t max_age,
1045 struct obd_device *obd = exp->exp_obd;
1049 if (unlikely(obd == NULL))
1052 OBD_CHECK_DEV_ACTIVE(obd);
1054 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1055 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1056 RETURN(-EOPNOTSUPP);
1059 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1060 obd->obd_name, obd->obd_osfs_age, max_age);
1061 /* ignore cache if aggregated isn't expected */
1062 if (obd->obd_osfs_age < max_age ||
1063 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1064 !(flags & OBD_STATFS_SUM))) {
1065 /* the RPC will block anyway, so avoid sending many at once */
1066 rc = mutex_lock_interruptible(&obd->obd_dev_mutex);
1069 if (obd->obd_osfs_age < max_age ||
1070 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1071 !(flags & OBD_STATFS_SUM))) {
1072 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1074 mutex_unlock(&obd->obd_dev_mutex);
1075 GOTO(cached, rc = 0);
1079 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1080 obd->obd_name, &obd->obd_osfs,
1081 osfs->os_bavail, osfs->os_blocks,
1082 osfs->os_ffree, osfs->os_files);
1084 spin_lock(&obd->obd_osfs_lock);
1085 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1086 obd->obd_osfs_age = ktime_get_seconds();
1087 spin_unlock(&obd->obd_osfs_lock);
1089 mutex_unlock(&obd->obd_dev_mutex);
1093 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1094 obd->obd_name, &obd->obd_osfs,
1095 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1096 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1097 spin_lock(&obd->obd_osfs_lock);
1098 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1099 spin_unlock(&obd->obd_osfs_lock);
1104 static inline int obd_preprw(const struct lu_env *env, int cmd,
1105 struct obd_export *exp, struct obdo *oa,
1106 int objcount, struct obd_ioobj *obj,
1107 struct niobuf_remote *remote, int *pages,
1108 struct niobuf_local *local)
1114 rc = exp_check_ops(exp);
1118 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1119 CERROR("%s: no %s operation\n",
1120 (exp)->exp_obd->obd_name, __func__);
1124 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1130 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1131 struct obd_export *exp, struct obdo *oa,
1132 int objcount, struct obd_ioobj *obj,
1133 struct niobuf_remote *rnb, int pages,
1134 struct niobuf_local *local, const int orig_rc)
1139 rc = exp_check_ops(exp);
1143 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1144 CERROR("%s: no %s operation\n",
1145 (exp)->exp_obd->obd_name, __func__);
1149 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1150 rnb, pages, local, orig_rc);
1155 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1156 int len, void *karg, void __user *uarg)
1161 rc = exp_check_ops(exp);
1165 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1166 CERROR("%s: no %s operation\n",
1167 (exp)->exp_obd->obd_name, __func__);
1171 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1175 static inline void obd_import_event(struct obd_device *obd,
1176 struct obd_import *imp,
1177 enum obd_import_event event)
1181 CERROR("NULL device\n");
1186 if (obd->obd_set_up && OBP(obd, import_event))
1187 OBP(obd, import_event)(obd, imp, event);
1192 static inline int obd_notify(struct obd_device *obd,
1193 struct obd_device *watched,
1194 enum obd_notify_event ev)
1199 rc = obd_check_dev(obd);
1203 if (!obd->obd_set_up) {
1204 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1208 if (!OBP(obd, notify)) {
1209 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1213 rc = OBP(obd, notify)(obd, watched, ev);
1218 static inline int obd_notify_observer(struct obd_device *observer,
1219 struct obd_device *observed,
1220 enum obd_notify_event ev)
1224 struct obd_notify_upcall *onu;
1226 if (observer->obd_observer)
1227 rc = obd_notify(observer->obd_observer, observed, ev);
1230 * Also, call non-obd listener, if any
1232 onu = &observer->obd_upcall;
1233 if (onu->onu_upcall != NULL)
1234 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1236 return rc ? rc : rc2;
1239 static inline int obd_quotactl(struct obd_export *exp,
1240 struct obd_quotactl *oqctl)
1245 rc = exp_check_ops(exp);
1249 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1250 CERROR("%s: no %s operation\n",
1251 (exp)->exp_obd->obd_name, __func__);
1255 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1259 static inline int obd_health_check(const struct lu_env *env,
1260 struct obd_device *obd)
1262 /* returns: 0 on healthy
1263 * >0 on unhealthy + reason code/flag
1264 * however the only suppored reason == 1 right now
1265 * We'll need to define some better reasons
1266 * or flags in the future.
1273 /* NULL method is normal here */
1274 if (obd == NULL || !obd->obd_type) {
1275 CERROR("cleaned up obd\n");
1276 RETURN(-EOPNOTSUPP);
1278 if (!obd->obd_set_up || obd->obd_stopping)
1280 if (!OBP(obd, health_check))
1283 rc = OBP(obd, health_check)(env, obd);
1287 static inline int obd_register_observer(struct obd_device *obd,
1288 struct obd_device *observer)
1293 rc = obd_check_dev(obd);
1297 down_write(&obd->obd_observer_link_sem);
1298 if (obd->obd_observer && observer) {
1299 up_write(&obd->obd_observer_link_sem);
1302 obd->obd_observer = observer;
1303 up_write(&obd->obd_observer_link_sem);
1307 /* metadata helpers */
1313 LPROC_MD_INTENT_LOCK,
1322 LPROC_MD_INTENT_GETATTR_ASYNC,
1323 LPROC_MD_REVALIDATE_LOCK,
1327 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1332 rc = exp_check_ops(exp);
1336 return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1339 static inline int md_getattr(struct obd_export *exp,
1340 struct md_op_data *op_data,
1341 struct ptlrpc_request **request)
1345 rc = exp_check_ops(exp);
1349 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1352 return MDP(exp->exp_obd, getattr)(exp, op_data, request);
1355 static inline int md_null_inode(struct obd_export *exp,
1356 const struct lu_fid *fid)
1360 rc = exp_check_ops(exp);
1364 return MDP(exp->exp_obd, null_inode)(exp, fid);
1367 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1368 struct md_open_data *mod,
1369 struct ptlrpc_request **request)
1373 rc = exp_check_ops(exp);
1377 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1380 return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1383 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1384 const void *data, size_t datalen, umode_t mode,
1385 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1386 __u64 rdev, struct ptlrpc_request **request)
1390 rc = exp_check_ops(exp);
1394 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1397 return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1398 uid, gid, cap_effective, rdev,
1402 static inline int md_enqueue(struct obd_export *exp,
1403 struct ldlm_enqueue_info *einfo,
1404 const union ldlm_policy_data *policy,
1405 struct md_op_data *op_data,
1406 struct lustre_handle *lockh,
1407 __u64 extra_lock_flags)
1411 rc = exp_check_ops(exp);
1415 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1418 return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1422 static inline int md_getattr_name(struct obd_export *exp,
1423 struct md_op_data *op_data,
1424 struct ptlrpc_request **request)
1428 rc = exp_check_ops(exp);
1432 return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1435 static inline int md_intent_lock(struct obd_export *exp,
1436 struct md_op_data *op_data,
1437 struct lookup_intent *it,
1438 struct ptlrpc_request **reqp,
1439 ldlm_blocking_callback cb_blocking,
1440 __u64 extra_lock_flags)
1444 rc = exp_check_ops(exp);
1448 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1449 LPROC_MD_INTENT_LOCK);
1451 return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1452 cb_blocking, extra_lock_flags);
1455 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1456 struct ptlrpc_request **request)
1460 rc = exp_check_ops(exp);
1464 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1467 return MDP(exp->exp_obd, link)(exp, op_data, request);
1470 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1471 const char *old_name, size_t oldlen,
1472 const char *new_name, size_t newlen,
1473 struct ptlrpc_request **request)
1477 rc = exp_check_ops(exp);
1481 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1484 return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
1485 new_name, newlen, request);
1488 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1489 void *ea, size_t ealen,
1490 struct ptlrpc_request **request)
1494 rc = exp_check_ops(exp);
1498 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1501 return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1504 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1505 struct ptlrpc_request **request)
1509 rc = exp_check_ops(exp);
1513 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1516 return MDP(exp->exp_obd, fsync)(exp, fid, request);
1519 /* FLR: resync mirrored files. */
1520 static inline int md_file_resync(struct obd_export *exp,
1521 struct md_op_data *data)
1525 rc = exp_check_ops(exp);
1529 return MDP(exp->exp_obd, file_resync)(exp, data);
1532 static inline int md_read_page(struct obd_export *exp,
1533 struct md_op_data *op_data,
1534 struct md_callback *cb_op,
1536 struct page **ppage)
1540 rc = exp_check_ops(exp);
1544 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1545 LPROC_MD_READ_PAGE);
1547 return MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1551 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1552 struct ptlrpc_request **request)
1556 rc = exp_check_ops(exp);
1560 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1563 return MDP(exp->exp_obd, unlink)(exp, op_data, request);
1566 static inline int md_get_lustre_md(struct obd_export *exp,
1567 struct ptlrpc_request *req,
1568 struct obd_export *dt_exp,
1569 struct obd_export *md_exp,
1570 struct lustre_md *md)
1574 rc = exp_check_ops(exp);
1578 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1581 static inline int md_free_lustre_md(struct obd_export *exp,
1582 struct lustre_md *md)
1586 rc = exp_check_ops(exp);
1590 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1593 static inline int md_merge_attr(struct obd_export *exp,
1594 const struct lu_fid *fid,
1595 const struct lmv_stripe_md *lsm,
1596 struct cl_attr *attr,
1597 ldlm_blocking_callback cb)
1601 rc = exp_check_ops(exp);
1605 return MDP(exp->exp_obd, merge_attr)(exp, fid, lsm, attr, cb);
1608 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1609 u64 obd_md_valid, const char *name,
1610 const void *value, size_t value_size,
1611 unsigned int xattr_flags, u32 suppgid,
1612 struct ptlrpc_request **req)
1616 rc = exp_check_ops(exp);
1620 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1623 return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1624 value, value_size, xattr_flags,
1628 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1629 u64 obd_md_valid, const char *name,
1630 size_t buf_size, struct ptlrpc_request **req)
1634 rc = exp_check_ops(exp);
1638 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1641 return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1645 static inline int md_set_open_replay_data(struct obd_export *exp,
1646 struct obd_client_handle *och,
1647 struct lookup_intent *it)
1651 rc = exp_check_ops(exp);
1655 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1658 static inline int md_clear_open_replay_data(struct obd_export *exp,
1659 struct obd_client_handle *och)
1663 rc = exp_check_ops(exp);
1667 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1670 static inline int md_set_lock_data(struct obd_export *exp,
1671 const struct lustre_handle *lockh,
1672 void *data, __u64 *bits)
1676 rc = exp_check_ops(exp);
1680 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1684 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1685 union ldlm_policy_data *policy, enum ldlm_mode mode,
1686 enum ldlm_cancel_flags cancel_flags, void *opaque)
1690 rc = exp_check_ops(exp);
1694 return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1695 cancel_flags, opaque);
1698 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1699 const struct lu_fid *fid,
1700 enum ldlm_type type,
1701 union ldlm_policy_data *policy,
1702 enum ldlm_mode mode,
1703 struct lustre_handle *lockh)
1707 rc = exp_check_ops(exp);
1711 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1712 policy, mode, lockh);
1715 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1720 rc = exp_check_ops(exp);
1724 return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
1727 static inline int md_intent_getattr_async(struct obd_export *exp,
1728 struct md_enqueue_info *minfo)
1732 rc = exp_check_ops(exp);
1736 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1737 LPROC_MD_INTENT_GETATTR_ASYNC);
1739 return MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1742 static inline int md_revalidate_lock(struct obd_export *exp,
1743 struct lookup_intent *it,
1744 struct lu_fid *fid, __u64 *bits)
1748 rc = exp_check_ops(exp);
1752 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1753 LPROC_MD_REVALIDATE_LOCK);
1755 return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1758 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1759 const struct lmv_stripe_md *lsm,
1760 const char *name, int namelen,
1765 rc = exp_check_ops(exp);
1769 return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
1773 /* Unpack an MD struct from disk to in-memory format.
1774 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1776 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1777 * If *plsm == NULL then it will be allocated.
1779 static inline int md_unpackmd(struct obd_export *exp,
1780 struct lmv_stripe_md **plsm,
1781 const union lmv_mds_md *lmm, size_t lmm_size)
1785 rc = exp_check_ops(exp);
1789 return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1792 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1793 int *rcs, struct ptlrpc_request_set *set)
1797 rc = exp_check_ops(exp);
1801 return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
1804 /* OBD Metadata Support */
1806 extern int obd_init_caches(void);
1807 extern void obd_cleanup_caches(void);
1809 typedef int (*register_lwp_cb)(void *data);
1811 struct lwp_register_item {
1812 struct obd_export **lri_exp;
1813 register_lwp_cb lri_cb_func;
1815 struct list_head lri_list;
1817 char lri_name[MTI_NAME_MAXLEN];
1820 /* I'm as embarrassed about this as you are.
1822 * <shaver> // XXX do not look into _superhack with remaining eye
1823 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1824 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
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_check_uuid(struct obd_uuid *uuid, __u64 nid);
1846 extern char obd_jobid_name[];
1850 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1851 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1853 /* root squash info */
1854 struct root_squash_info {
1857 struct list_head rsi_nosquash_nids;
1858 spinlock_t rsi_lock;
1861 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1863 /* linux-module.c */
1864 extern struct miscdevice obd_psdev;
1865 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1866 int class_procfs_init(void);
1867 int class_procfs_clean(void);
1869 extern void obd_heat_add(struct obd_heat_instance *instance,
1870 unsigned int time_second, __u64 count,
1871 unsigned int weight, unsigned int period_second);
1872 extern void obd_heat_decay(struct obd_heat_instance *instance,
1873 __u64 time_second, unsigned int weight,
1874 unsigned int period_second);
1875 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
1876 unsigned int time_second, unsigned int weight,
1877 unsigned int period_second);
1878 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
1879 #endif /* __LINUX_OBD_CLASS_H */