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 const char *nm, struct lu_device_type *ldt);
78 int class_unregister_type(const char *nm);
80 struct obd_device *class_newdev(const char *type_name, const char *name,
82 int class_register_device(struct obd_device *obd);
83 void class_unregister_device(struct obd_device *obd);
84 void class_free_dev(struct obd_device *obd);
86 struct obd_device *class_dev_by_str(const char *str);
87 int class_name2dev(const char *name);
88 struct obd_device *class_name2obd(const char *name);
89 int class_uuid2dev(struct obd_uuid *uuid);
90 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
91 void class_obd_list(void);
92 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
93 const char *type_name,
94 struct obd_uuid *grp_uuid);
95 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
97 struct obd_device *class_num2obd(int num);
98 int get_devices_count(void);
100 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
102 static inline char *obd_export_nid2str(struct obd_export *exp)
104 return exp->exp_connection == NULL ?
105 "<unknown>" : libcfs_nid2str(exp->exp_connection->c_peer.nid);
108 static inline char *obd_import_nid2str(struct obd_import *imp)
110 return imp->imp_connection == NULL ?
111 "<unknown>" : libcfs_nid2str(imp->imp_connection->c_peer.nid);
114 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
115 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
116 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
119 int obd_zombie_impexp_init(void);
120 void obd_zombie_impexp_stop(void);
121 void obd_zombie_impexp_cull(void);
122 void obd_zombie_barrier(void);
123 void obd_exports_barrier(struct obd_device *obd);
124 int kuc_len(int payload_len);
125 struct kuc_hdr * kuc_ptr(void *p);
126 void *kuc_alloc(int payload_len, int transport, int type);
127 void kuc_free(void *p, int payload_len);
128 int obd_get_request_slot(struct client_obd *cli);
129 void obd_put_request_slot(struct client_obd *cli);
130 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
131 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
132 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
133 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
134 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
136 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
137 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
141 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
142 struct llog_rec_hdr *, void *);
144 struct obd_export *obd_stale_export_get(void);
145 void obd_stale_export_put(struct obd_export *exp);
146 void obd_stale_export_adjust(struct obd_export *exp);
149 /* For interoperability */
150 struct cfg_interop_param {
155 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
156 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
157 const char *new_name);
158 void print_lustre_cfg(struct lustre_cfg *lcfg);
159 int class_process_config(struct lustre_cfg *lcfg);
160 ssize_t class_set_global(const char *param);
161 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
162 struct kobject *kobj);
163 int class_attach(struct lustre_cfg *lcfg);
164 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
165 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
166 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
168 int class_find_param(char *buf, char *key, char **valp);
169 struct cfg_interop_param *class_find_old_param(const char *param,
170 struct cfg_interop_param *ptr);
171 int class_get_next_param(char **params, char *copy);
172 int class_match_param(char *buf, const char *key, char **valp);
173 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
174 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
175 int class_parse_net(char *buf, u32 *net, char **endh);
176 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
177 int class_match_net(char *buf, char *key, u32 net);
179 struct obd_device *class_incref(struct obd_device *obd,
180 const char *scope, const void *source);
181 void class_decref(struct obd_device *obd,
182 const char *scope, const void *source);
183 void dump_exports(struct obd_device *obd, int locks, int debug_level);
184 int class_config_llog_handler(const struct lu_env *env,
185 struct llog_handle *handle,
186 struct llog_rec_hdr *rec, void *data);
187 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
189 #define CFG_F_START 0x01 /* Set when we start updating from a log */
190 #define CFG_F_MARKER 0x02 /* We are within a maker */
191 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
192 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
194 /* Passed as data param to class_config_parse_llog */
195 struct config_llog_instance {
196 unsigned long cfg_instance;
197 struct super_block *cfg_sb;
198 struct obd_uuid cfg_uuid;
199 llog_cb_t cfg_callback;
200 int cfg_last_idx; /* for partial llog processing */
205 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
206 char *name, struct config_llog_instance *cfg);
209 * Generate a unique configuration instance for this mount
211 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
212 * For now, use the same value as before - the superblock pointer value.
214 * Using the client UUID would be an option, but it needs more testing.
216 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
218 return (unsigned long)sb;
221 #define CONFIG_SUB_SPTLRPC 0x01
222 #define CONFIG_SUB_RECOVER 0x02
223 #define CONFIG_SUB_PARAMS 0x04
224 #define CONFIG_SUB_NODEMAP 0x08
225 #define CONFIG_SUB_BARRIER 0x10
227 /* Sub clds should be attached to the config_llog_data when processing
228 * config log for client or server target. */
229 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
231 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
234 #define PARAMS_FILENAME "params"
235 #define BARRIER_FILENAME "barrier"
236 #define LCTL_UPCALL "lctl"
238 static inline bool logname_is_barrier(const char *logname)
242 /* logname for barrier is "fsname-barrier" */
243 ptr = strstr(logname, BARRIER_FILENAME);
244 if (ptr && (ptr - logname) >= 2 &&
245 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
251 /* list of active configuration logs */
252 struct config_llog_data {
253 struct ldlm_res_id cld_resid;
254 struct lustre_handle cld_lockh;
255 struct config_llog_instance cld_cfg;
256 struct list_head cld_list_chain;/* on config_llog_list */
257 atomic_t cld_refcount;
258 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
259 struct config_llog_data *cld_params; /* common parameters log */
260 struct config_llog_data *cld_recover;/* imperative recover log */
261 struct config_llog_data *cld_nodemap;/* nodemap log */
262 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
263 struct obd_export *cld_mgcexp;
264 struct mutex cld_lock;
266 unsigned int cld_stopping:1, /* we were told to stop
268 cld_lostlock:1; /* lock not requeued */
272 struct lustre_profile {
273 struct list_head lp_list;
278 bool lp_list_deleted;
281 struct lustre_profile *class_get_profile(const char * prof);
282 void class_del_profile(const char *prof);
283 void class_put_profile(struct lustre_profile *lprof);
284 void class_del_profiles(void);
287 #if LUSTRE_TRACKS_LOCK_EXP_REFS
289 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
290 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
291 extern void (*class_export_dump_hook)(struct obd_export *);
295 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
296 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
300 #define class_export_rpc_inc(exp) \
302 atomic_inc(&(exp)->exp_rpc_count); \
303 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
304 (exp), atomic_read(&(exp)->exp_rpc_count)); \
307 #define class_export_rpc_dec(exp) \
309 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
310 atomic_dec(&(exp)->exp_rpc_count); \
311 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
312 (exp), atomic_read(&(exp)->exp_rpc_count)); \
315 #define class_export_lock_get(exp, lock) \
317 atomic_inc(&(exp)->exp_locks_count); \
318 __class_export_add_lock_ref(exp, lock); \
319 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
320 (exp), atomic_read(&(exp)->exp_locks_count)); \
321 class_export_get(exp); \
324 #define class_export_lock_put(exp, lock) \
326 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
327 atomic_dec(&(exp)->exp_locks_count); \
328 __class_export_del_lock_ref(exp, lock); \
329 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
330 (exp), atomic_read(&(exp)->exp_locks_count)); \
331 class_export_put(exp); \
334 #define class_export_cb_get(exp) \
336 atomic_inc(&(exp)->exp_cb_count); \
337 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
338 (exp), atomic_read(&(exp)->exp_cb_count)); \
339 class_export_get(exp); \
342 #define class_export_cb_put(exp) \
344 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
345 atomic_dec(&(exp)->exp_cb_count); \
346 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
347 (exp), atomic_read(&(exp)->exp_cb_count)); \
348 class_export_put(exp); \
352 struct obd_export *class_export_get(struct obd_export *exp);
353 void class_export_put(struct obd_export *exp);
354 struct obd_export *class_new_export(struct obd_device *obd,
355 struct obd_uuid *cluuid);
356 struct obd_export *class_new_export_self(struct obd_device *obd,
357 struct obd_uuid *uuid);
358 void class_unlink_export(struct obd_export *exp);
360 struct obd_import *class_import_get(struct obd_import *);
361 void class_import_put(struct obd_import *);
362 struct obd_import *class_new_import(struct obd_device *obd);
363 void class_destroy_import(struct obd_import *exp);
365 #ifdef HAVE_SERVER_SUPPORT
366 struct obd_type *class_search_type(const char *name);
367 struct obd_type *class_get_type(const char *name);
369 void class_put_type(struct obd_type *type);
370 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
371 struct obd_uuid *cluuid);
372 int class_disconnect(struct obd_export *exp);
373 void class_fail_export(struct obd_export *exp);
374 int class_connected_export(struct obd_export *exp);
375 void class_disconnect_exports(struct obd_device *obd);
376 int class_manual_cleanup(struct obd_device *obd);
377 void class_disconnect_stale_exports(struct obd_device *,
378 int (*test_export)(struct obd_export *));
380 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
382 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
383 (obd->obd_force ? OBD_OPT_FORCE : 0) |
384 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
388 #ifdef HAVE_SERVER_SUPPORT
389 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
391 LASSERT(exp->exp_obd);
392 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
394 return exp->exp_obd->u.obt.obt_lut;
397 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
399 LASSERT(obd->u.obt.obt_lut);
400 return &obd->u.obt.obt_lut->lut_lsd;
408 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
409 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
411 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
412 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
414 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
415 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
417 static inline int obd_check_dev(struct obd_device *obd)
420 CERROR("NULL device\n");
426 /* ensure obd_setup and !obd_stopping */
427 #define OBD_CHECK_DEV_ACTIVE(obd) \
429 rc = obd_check_dev(obd); \
433 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
434 CERROR("Device %d not setup\n", \
441 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
443 /* Always add in ldlm_stats */
444 tmp->nid_ldlm_stats =
445 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
446 LPROCFS_STATS_FLAG_NOPERCPU);
447 if (tmp->nid_ldlm_stats == NULL)
450 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
452 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
453 tmp->nid_ldlm_stats);
456 static inline int exp_check_ops(struct obd_export *exp)
461 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
467 static inline int class_devno_max(void)
469 return MAX_OBD_DEVICES;
472 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
473 __u32 keylen, void *key,
474 __u32 *vallen, void *val)
479 rc = exp_check_ops(exp);
483 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
484 CERROR("%s: no %s operation\n",
485 (exp)->exp_obd->obd_name, __func__);
489 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
493 static inline int obd_set_info_async(const struct lu_env *env,
494 struct obd_export *exp,
495 __u32 keylen, void *key,
496 __u32 vallen, void *val,
497 struct ptlrpc_request_set *set)
502 rc = exp_check_ops(exp);
506 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
507 CERROR("%s: no %s operation\n",
508 (exp)->exp_obd->obd_name, __func__);
512 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
518 * obd-lu integration.
520 * Functionality is being moved into new lu_device-based layering, but some
521 * pieces of configuration process are still based on obd devices.
523 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
524 * subsume ->o_setup() methods of obd devices they replace. The same for
525 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
526 * result, obd_setup() and obd_process_config() branch and call one XOR
529 * Yet neither lu_device_type_operations::ldto_device_fini() nor
530 * lu_device_type_operations::ldto_device_free() fully implement the
531 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
532 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
534 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
537 struct obd_type *type = obd->obd_type;
538 struct lu_device_type *ldt;
542 wait_var_event(&type->typ_lu,
543 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
546 struct lu_context session_ctx;
549 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
550 session_ctx.lc_thread = NULL;
551 lu_context_enter(&session_ctx);
553 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
555 struct lu_device *dev;
556 env.le_ses = &session_ctx;
557 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
560 obd->obd_lu_dev = dev;
566 lu_context_exit(&session_ctx);
567 lu_context_fini(&session_ctx);
569 if (!obd->obd_type->typ_dt_ops->o_setup) {
570 CERROR("%s: no %s operation\n", obd->obd_name,
574 rc = OBP(obd, setup)(obd, cfg);
579 static inline int obd_precleanup(struct obd_device *obd)
582 struct lu_device_type *ldt = obd->obd_type->typ_lu;
583 struct lu_device *d = obd->obd_lu_dev;
587 if (ldt != NULL && d != NULL) {
588 struct lu_env *env = lu_env_find();
593 rc = lu_env_init(env, ldt->ldt_ctx_tags);
597 ldt->ldt_ops->ldto_device_fini(env, d);
604 if (!obd->obd_type->typ_dt_ops->o_precleanup)
607 rc = OBP(obd, precleanup)(obd);
611 static inline int obd_cleanup(struct obd_device *obd)
614 struct lu_device_type *ldt = obd->obd_type->typ_lu;
615 struct lu_device *d = obd->obd_lu_dev;
618 if (ldt != NULL && d != NULL) {
621 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
623 ldt->ldt_ops->ldto_device_free(&env, d);
625 obd->obd_lu_dev = NULL;
628 if (!obd->obd_type->typ_dt_ops->o_cleanup)
631 rc = OBP(obd, cleanup)(obd);
635 static inline void obd_cleanup_client_import(struct obd_device *obd)
639 /* If we set up but never connected, the
640 client import will not have been cleaned. */
641 down_write(&obd->u.cli.cl_sem);
642 if (obd->u.cli.cl_import) {
643 struct obd_import *imp;
644 imp = obd->u.cli.cl_import;
645 CDEBUG(D_CONFIG, "%s: client import never connected\n",
647 ptlrpc_invalidate_import(imp);
648 client_destroy_import(imp);
649 obd->u.cli.cl_import = NULL;
651 up_write(&obd->u.cli.cl_sem);
656 static inline int obd_process_config(struct obd_device *obd, int datalen,
660 struct lu_device_type *ldt = obd->obd_type->typ_lu;
661 struct lu_device *d = obd->obd_lu_dev;
665 obd->obd_process_conf = 1;
666 if (ldt != NULL && d != NULL) {
669 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
671 rc = d->ld_ops->ldo_process_config(&env, d, data);
675 if (!obd->obd_type->typ_dt_ops->o_process_config) {
676 CERROR("%s: no %s operation\n",
677 obd->obd_name, __func__);
680 rc = OBP(obd, process_config)(obd, datalen, data);
683 obd->obd_process_conf = 0;
688 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
694 rc = exp_check_ops(exp);
698 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
699 CERROR("%s: no %s operation\n",
700 (exp)->exp_obd->obd_name, __func__);
704 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
708 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
714 rc = exp_check_ops(exp);
718 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
719 CERROR("%s: no %s operation\n",
720 (exp)->exp_obd->obd_name, __func__);
724 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
728 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
734 rc = exp_check_ops(exp);
738 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
739 CERROR("%s: no %s operation\n",
740 (exp)->exp_obd->obd_name, __func__);
744 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
749 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
755 rc = exp_check_ops(exp);
759 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
760 CERROR("%s: no %s operation\n",
761 (exp)->exp_obd->obd_name, __func__);
765 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
770 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
773 struct obd_device *obd = imp->imp_obd;
777 OBD_CHECK_DEV_ACTIVE(obd);
778 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
779 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
783 rc = OBP(obd, add_conn)(imp, uuid, priority);
787 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
789 struct obd_device *obd = imp->imp_obd;
793 OBD_CHECK_DEV_ACTIVE(obd);
794 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
795 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
799 rc = OBP(obd, del_conn)(imp, uuid);
803 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
805 struct obd_uuid *uuid;
808 if (!exp->exp_obd->obd_type ||
809 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
812 uuid = OBP(exp->exp_obd, get_uuid)(exp);
816 /** Create a new /a exp on device /a obd for the uuid /a cluuid
817 * @param exp New export handle
818 * @param d Connect data, supported flags are set, flags also understood
819 * by obd are returned.
821 static inline int obd_connect(const struct lu_env *env,
822 struct obd_export **exp,struct obd_device *obd,
823 struct obd_uuid *cluuid,
824 struct obd_connect_data *data,
828 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
832 OBD_CHECK_DEV_ACTIVE(obd);
833 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
834 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
838 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
839 /* check that only subset is granted */
840 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
841 data->ocd_connect_flags));
845 static inline int obd_reconnect(const struct lu_env *env,
846 struct obd_export *exp,
847 struct obd_device *obd,
848 struct obd_uuid *cluuid,
849 struct obd_connect_data *d,
853 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
858 OBD_CHECK_DEV_ACTIVE(obd);
859 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
862 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
863 /* check that only subset is granted */
864 LASSERT(ergo(d != NULL,
865 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
869 static inline int obd_disconnect(struct obd_export *exp)
873 rc = exp_check_ops(exp);
877 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
878 CERROR("%s: no %s operation\n",
879 (exp)->exp_obd->obd_name, __func__);
883 rc = OBP(exp->exp_obd, disconnect)(exp);
887 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
888 enum lu_cli_type type)
893 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
896 rc = OBP(obd, fid_init)(obd, exp, type);
900 static inline int obd_fid_fini(struct obd_device *obd)
904 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
907 rc = OBP(obd, fid_fini)(obd);
911 static inline int obd_fid_alloc(const struct lu_env *env,
912 struct obd_export *exp,
914 struct md_op_data *op_data)
918 rc = exp_check_ops(exp);
922 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
923 CERROR("%s: no %s operation\n",
924 (exp)->exp_obd->obd_name, __func__);
928 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
932 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
937 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
938 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
942 rc = OBP(obd, pool_new)(obd, poolname);
946 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
950 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
951 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
955 rc = OBP(obd, pool_del)(obd, poolname);
959 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
965 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
966 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
970 rc = OBP(obd, pool_add)(obd, poolname, ostname);
974 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
980 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
981 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
985 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
989 static inline int obd_init_export(struct obd_export *exp)
994 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
995 OBP((exp)->exp_obd, init_export))
996 rc = OBP(exp->exp_obd, init_export)(exp);
1000 static inline int obd_destroy_export(struct obd_export *exp)
1003 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1004 OBP(exp->exp_obd, destroy_export))
1005 OBP(exp->exp_obd, destroy_export)(exp);
1009 /* @max_age is the oldest time in seconds that we accept using a cached data.
1010 * If the cache is older than @max_age we will get a new value from the
1011 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1013 static inline int obd_statfs_async(struct obd_export *exp,
1014 struct obd_info *oinfo,
1016 struct ptlrpc_request_set *rqset)
1018 struct obd_device *obd;
1023 if (exp == NULL || exp->exp_obd == NULL)
1027 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1029 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1033 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1034 obd->obd_name, obd->obd_osfs_age, max_age);
1035 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1040 /* @max_age is the oldest time in seconds that we accept using a cached data.
1041 * If the cache is older than @max_age we will get a new value from the
1042 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1044 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1045 struct obd_statfs *osfs, time64_t max_age,
1048 struct obd_device *obd = exp->exp_obd;
1052 if (unlikely(obd == NULL))
1055 OBD_CHECK_DEV_ACTIVE(obd);
1057 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1058 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1059 RETURN(-EOPNOTSUPP);
1062 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1063 obd->obd_name, obd->obd_osfs_age, max_age);
1064 /* ignore cache if aggregated isn't expected */
1065 if (obd->obd_osfs_age < max_age ||
1066 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1067 !(flags & OBD_STATFS_SUM))) {
1068 /* the RPC will block anyway, so avoid sending many at once */
1069 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1070 (flags & OBD_STATFS_NESTED)
1071 ? SINGLE_DEPTH_NESTING : 0);
1074 if (obd->obd_osfs_age < max_age ||
1075 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1076 !(flags & OBD_STATFS_SUM))) {
1077 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1079 mutex_unlock(&obd->obd_dev_mutex);
1080 GOTO(cached, rc = 0);
1084 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1085 obd->obd_name, &obd->obd_osfs,
1086 osfs->os_bavail, osfs->os_blocks,
1087 osfs->os_ffree, osfs->os_files);
1089 spin_lock(&obd->obd_osfs_lock);
1090 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1091 obd->obd_osfs_age = ktime_get_seconds();
1092 spin_unlock(&obd->obd_osfs_lock);
1094 mutex_unlock(&obd->obd_dev_mutex);
1098 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1099 obd->obd_name, &obd->obd_osfs,
1100 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1101 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1102 spin_lock(&obd->obd_osfs_lock);
1103 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1104 spin_unlock(&obd->obd_osfs_lock);
1109 static inline int obd_preprw(const struct lu_env *env, int cmd,
1110 struct obd_export *exp, struct obdo *oa,
1111 int objcount, struct obd_ioobj *obj,
1112 struct niobuf_remote *remote, int *pages,
1113 struct niobuf_local *local)
1119 rc = exp_check_ops(exp);
1123 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1124 CERROR("%s: no %s operation\n",
1125 (exp)->exp_obd->obd_name, __func__);
1129 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1135 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1136 struct obd_export *exp, struct obdo *oa,
1137 int objcount, struct obd_ioobj *obj,
1138 struct niobuf_remote *rnb, int pages,
1139 struct niobuf_local *local, const int orig_rc)
1144 rc = exp_check_ops(exp);
1148 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1149 CERROR("%s: no %s operation\n",
1150 (exp)->exp_obd->obd_name, __func__);
1154 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1155 rnb, pages, local, orig_rc);
1160 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1161 int len, void *karg, void __user *uarg)
1166 rc = exp_check_ops(exp);
1170 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1171 CERROR("%s: no %s operation\n",
1172 (exp)->exp_obd->obd_name, __func__);
1176 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1180 static inline void obd_import_event(struct obd_device *obd,
1181 struct obd_import *imp,
1182 enum obd_import_event event)
1186 CERROR("NULL device\n");
1191 if (obd->obd_set_up && OBP(obd, import_event))
1192 OBP(obd, import_event)(obd, imp, event);
1197 static inline int obd_notify(struct obd_device *obd,
1198 struct obd_device *watched,
1199 enum obd_notify_event ev)
1204 rc = obd_check_dev(obd);
1208 if (!obd->obd_set_up) {
1209 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1213 if (!OBP(obd, notify)) {
1214 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1218 rc = OBP(obd, notify)(obd, watched, ev);
1223 static inline int obd_notify_observer(struct obd_device *observer,
1224 struct obd_device *observed,
1225 enum obd_notify_event ev)
1229 struct obd_notify_upcall *onu;
1231 if (observer->obd_observer)
1232 rc = obd_notify(observer->obd_observer, observed, ev);
1235 * Also, call non-obd listener, if any
1237 onu = &observer->obd_upcall;
1238 if (onu->onu_upcall != NULL)
1239 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1241 return rc ? rc : rc2;
1244 static inline int obd_quotactl(struct obd_export *exp,
1245 struct obd_quotactl *oqctl)
1250 rc = exp_check_ops(exp);
1254 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1255 CERROR("%s: no %s operation\n",
1256 (exp)->exp_obd->obd_name, __func__);
1260 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1264 static inline int obd_health_check(const struct lu_env *env,
1265 struct obd_device *obd)
1267 /* returns: 0 on healthy
1268 * >0 on unhealthy + reason code/flag
1269 * however the only suppored reason == 1 right now
1270 * We'll need to define some better reasons
1271 * or flags in the future.
1278 /* NULL method is normal here */
1279 if (obd == NULL || !obd->obd_type) {
1280 CERROR("cleaned up obd\n");
1281 RETURN(-EOPNOTSUPP);
1283 if (!obd->obd_set_up || obd->obd_stopping)
1285 if (!OBP(obd, health_check))
1288 rc = OBP(obd, health_check)(env, obd);
1292 static inline int obd_register_observer(struct obd_device *obd,
1293 struct obd_device *observer)
1298 rc = obd_check_dev(obd);
1302 down_write(&obd->obd_observer_link_sem);
1303 if (obd->obd_observer && observer) {
1304 up_write(&obd->obd_observer_link_sem);
1307 obd->obd_observer = observer;
1308 up_write(&obd->obd_observer_link_sem);
1312 /* metadata helpers */
1318 LPROC_MD_INTENT_LOCK,
1327 LPROC_MD_INTENT_GETATTR_ASYNC,
1328 LPROC_MD_REVALIDATE_LOCK,
1332 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1337 rc = exp_check_ops(exp);
1341 return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1344 static inline int md_getattr(struct obd_export *exp,
1345 struct md_op_data *op_data,
1346 struct ptlrpc_request **request)
1350 rc = exp_check_ops(exp);
1354 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1357 return MDP(exp->exp_obd, getattr)(exp, op_data, request);
1360 static inline int md_null_inode(struct obd_export *exp,
1361 const struct lu_fid *fid)
1365 rc = exp_check_ops(exp);
1369 return MDP(exp->exp_obd, null_inode)(exp, fid);
1372 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1373 struct md_open_data *mod,
1374 struct ptlrpc_request **request)
1378 rc = exp_check_ops(exp);
1382 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1385 return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1388 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1389 const void *data, size_t datalen, umode_t mode,
1390 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1391 __u64 rdev, struct ptlrpc_request **request)
1395 rc = exp_check_ops(exp);
1399 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1402 return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1403 uid, gid, cap_effective, rdev,
1407 static inline int md_enqueue(struct obd_export *exp,
1408 struct ldlm_enqueue_info *einfo,
1409 const union ldlm_policy_data *policy,
1410 struct md_op_data *op_data,
1411 struct lustre_handle *lockh,
1412 __u64 extra_lock_flags)
1416 rc = exp_check_ops(exp);
1420 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1423 return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1427 static inline int md_getattr_name(struct obd_export *exp,
1428 struct md_op_data *op_data,
1429 struct ptlrpc_request **request)
1433 rc = exp_check_ops(exp);
1437 return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1440 static inline int md_intent_lock(struct obd_export *exp,
1441 struct md_op_data *op_data,
1442 struct lookup_intent *it,
1443 struct ptlrpc_request **reqp,
1444 ldlm_blocking_callback cb_blocking,
1445 __u64 extra_lock_flags)
1449 rc = exp_check_ops(exp);
1453 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1454 LPROC_MD_INTENT_LOCK);
1456 return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1457 cb_blocking, extra_lock_flags);
1460 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1461 struct ptlrpc_request **request)
1465 rc = exp_check_ops(exp);
1469 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1472 return MDP(exp->exp_obd, link)(exp, op_data, request);
1475 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1476 const char *old_name, size_t oldlen,
1477 const char *new_name, size_t newlen,
1478 struct ptlrpc_request **request)
1482 rc = exp_check_ops(exp);
1486 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1489 return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
1490 new_name, newlen, request);
1493 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1494 void *ea, size_t ealen,
1495 struct ptlrpc_request **request)
1499 rc = exp_check_ops(exp);
1503 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1506 return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1509 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1510 struct ptlrpc_request **request)
1514 rc = exp_check_ops(exp);
1518 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1521 return MDP(exp->exp_obd, fsync)(exp, fid, request);
1524 /* FLR: resync mirrored files. */
1525 static inline int md_file_resync(struct obd_export *exp,
1526 struct md_op_data *data)
1530 rc = exp_check_ops(exp);
1534 return MDP(exp->exp_obd, file_resync)(exp, data);
1537 static inline int md_read_page(struct obd_export *exp,
1538 struct md_op_data *op_data,
1539 struct md_callback *cb_op,
1541 struct page **ppage)
1545 rc = exp_check_ops(exp);
1549 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1550 LPROC_MD_READ_PAGE);
1552 return MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1556 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1557 struct ptlrpc_request **request)
1561 rc = exp_check_ops(exp);
1565 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1568 return MDP(exp->exp_obd, unlink)(exp, op_data, request);
1571 static inline int md_get_lustre_md(struct obd_export *exp,
1572 struct ptlrpc_request *req,
1573 struct obd_export *dt_exp,
1574 struct obd_export *md_exp,
1575 struct lustre_md *md)
1579 rc = exp_check_ops(exp);
1583 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1586 static inline int md_free_lustre_md(struct obd_export *exp,
1587 struct lustre_md *md)
1591 rc = exp_check_ops(exp);
1595 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1598 static inline int md_merge_attr(struct obd_export *exp,
1599 const struct lmv_stripe_md *lsm,
1600 struct cl_attr *attr,
1601 ldlm_blocking_callback cb)
1605 rc = exp_check_ops(exp);
1609 return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb);
1612 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1613 u64 obd_md_valid, const char *name,
1614 const void *value, size_t value_size,
1615 unsigned int xattr_flags, u32 suppgid,
1616 struct ptlrpc_request **req)
1620 rc = exp_check_ops(exp);
1624 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1627 return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1628 value, value_size, xattr_flags,
1632 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1633 u64 obd_md_valid, const char *name,
1634 size_t buf_size, struct ptlrpc_request **req)
1638 rc = exp_check_ops(exp);
1642 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1645 return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1649 static inline int md_set_open_replay_data(struct obd_export *exp,
1650 struct obd_client_handle *och,
1651 struct lookup_intent *it)
1655 rc = exp_check_ops(exp);
1659 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1662 static inline int md_clear_open_replay_data(struct obd_export *exp,
1663 struct obd_client_handle *och)
1667 rc = exp_check_ops(exp);
1671 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1674 static inline int md_set_lock_data(struct obd_export *exp,
1675 const struct lustre_handle *lockh,
1676 void *data, __u64 *bits)
1680 rc = exp_check_ops(exp);
1684 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1688 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1689 union ldlm_policy_data *policy, enum ldlm_mode mode,
1690 enum ldlm_cancel_flags cancel_flags, void *opaque)
1694 rc = exp_check_ops(exp);
1698 return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1699 cancel_flags, opaque);
1702 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1703 const struct lu_fid *fid,
1704 enum ldlm_type type,
1705 union ldlm_policy_data *policy,
1706 enum ldlm_mode mode,
1707 struct lustre_handle *lockh)
1711 rc = exp_check_ops(exp);
1715 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1716 policy, mode, lockh);
1719 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1724 rc = exp_check_ops(exp);
1728 return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
1731 static inline int md_intent_getattr_async(struct obd_export *exp,
1732 struct md_enqueue_info *minfo)
1736 rc = exp_check_ops(exp);
1740 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1741 LPROC_MD_INTENT_GETATTR_ASYNC);
1743 return MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1746 static inline int md_revalidate_lock(struct obd_export *exp,
1747 struct lookup_intent *it,
1748 struct lu_fid *fid, __u64 *bits)
1752 rc = exp_check_ops(exp);
1756 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1757 LPROC_MD_REVALIDATE_LOCK);
1759 return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1762 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1763 const struct lmv_stripe_md *lsm,
1764 const char *name, int namelen,
1769 rc = exp_check_ops(exp);
1773 return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
1777 /* Unpack an MD struct from disk to in-memory format.
1778 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1780 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1781 * If *plsm == NULL then it will be allocated.
1783 static inline int md_unpackmd(struct obd_export *exp,
1784 struct lmv_stripe_md **plsm,
1785 const union lmv_mds_md *lmm, size_t lmm_size)
1789 rc = exp_check_ops(exp);
1793 return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1796 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1797 int *rcs, struct ptlrpc_request_set *set)
1801 rc = exp_check_ops(exp);
1805 return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
1808 /* OBD Metadata Support */
1810 extern int obd_init_caches(void);
1811 extern void obd_cleanup_caches(void);
1813 typedef int (*register_lwp_cb)(void *data);
1815 struct lwp_register_item {
1816 struct obd_export **lri_exp;
1817 register_lwp_cb lri_cb_func;
1819 struct list_head lri_list;
1821 char lri_name[MTI_NAME_MAXLEN];
1825 #ifdef HAVE_SERVER_SUPPORT
1826 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1827 register_lwp_cb cb_func, void *cb_data);
1828 void lustre_deregister_lwp_item(struct obd_export **exp);
1829 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1830 void lustre_notify_lwp_list(struct obd_export *exp);
1831 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1832 #endif /* HAVE_SERVER_SUPPORT */
1833 int lustre_register_fs(void);
1834 int lustre_unregister_fs(void);
1835 int lustre_check_exclusion(struct super_block *sb, char *svname);
1838 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1839 int class_add_uuid(const char *uuid, __u64 nid);
1840 int class_del_uuid (const char *uuid);
1841 int class_add_nids_to_uuid(struct obd_uuid *uuid, lnet_nid_t *nids,
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 struct obd_ioctl_data;
1865 int obd_ioctl_getdata(struct obd_ioctl_data **data, 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 */