4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
34 #include <linux/kobject.h>
35 #include <obd_support.h>
36 #include <lustre_import.h>
37 #include <lustre_net.h>
39 #include <lustre_lib.h>
40 #include <uapi/linux/lustre/lustre_idl.h>
41 #include <lprocfs_status.h>
42 #ifdef HAVE_SERVER_SUPPORT
43 #include <lu_target.h>
44 #include <obd_target.h>
45 #include <dt_object.h>
48 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
49 * and resends for avoid deadlocks */
50 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
52 #define OBD_STATFS_FOR_MDT0 0x0004 /* The statfs is only for retrieving
53 * information from MDT0. */
54 #define OBD_STATFS_SUM 0x0008 /* get aggregated statfs from MDT */
55 #define OBD_STATFS_NESTED 0x0010 /* Call while already holding
56 * obd_dev_mutex of a difference
60 extern rwlock_t obd_dev_lock;
62 /* OBD Operations Declarations */
63 extern struct obd_device *class_exp2obd(struct obd_export *);
64 extern int class_handle_ioctl(unsigned int cmd, void __user *uarg);
65 int lustre_get_jobid(char *jobid, size_t len);
66 void lustre_jobid_clear(const char *jobid);
67 void jobid_cache_fini(void);
68 int jobid_cache_init(void);
69 char *jobid_current(void);
70 int jobid_set_current(char *jobid);
72 struct lu_device_type;
75 struct obd_export *class_conn2export(struct lustre_handle *);
76 #ifdef HAVE_SERVER_SUPPORT
77 struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
79 int class_register_type(const struct obd_ops *dt_ops,
80 const struct md_ops *md_ops, bool enable_proc,
81 const char *nm, struct lu_device_type *ldt);
82 int class_unregister_type(const char *nm);
84 struct obd_device *class_newdev(const char *type_name, const char *name,
86 int class_register_device(struct obd_device *obd);
87 void class_unregister_device(struct obd_device *obd);
88 void class_free_dev(struct obd_device *obd);
90 struct obd_device *class_dev_by_str(const char *str);
91 int class_name2dev(const char *name);
92 struct obd_device *class_name2obd(const char *name);
93 int class_uuid2dev(struct obd_uuid *uuid);
94 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
95 void class_obd_list(void);
96 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
97 const char *type_name,
98 struct obd_uuid *grp_uuid);
99 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
101 struct obd_device *class_num2obd(int num);
102 int get_devices_count(void);
104 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
106 static inline char *obd_export_nid2str(struct obd_export *exp)
108 return exp->exp_connection == NULL ?
109 "<unknown>" : libcfs_nidstr(&exp->exp_connection->c_peer.nid);
112 static inline char *obd_import_nid2str(struct obd_import *imp)
114 return imp->imp_connection == NULL ?
115 "<unknown>" : libcfs_nidstr(&imp->imp_connection->c_peer.nid);
118 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
119 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
120 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
123 int obd_zombie_impexp_init(void);
124 void obd_zombie_impexp_stop(void);
125 void obd_zombie_impexp_cull(void);
126 void obd_zombie_barrier(void);
127 void obd_exports_barrier(struct obd_device *obd);
128 int kuc_len(int payload_len);
129 struct kuc_hdr * kuc_ptr(void *p);
130 void *kuc_alloc(int payload_len, int transport, int type);
131 void kuc_free(void *p, int payload_len);
132 int obd_get_request_slot(struct client_obd *cli);
133 void obd_put_request_slot(struct client_obd *cli);
134 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
135 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
136 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
137 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
138 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
140 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
141 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
145 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
146 struct llog_rec_hdr *, void *);
148 struct obd_export *obd_stale_export_get(void);
149 void obd_stale_export_put(struct obd_export *exp);
150 void obd_stale_export_adjust(struct obd_export *exp);
153 /* For interoperability */
154 struct cfg_interop_param {
159 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
160 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
161 const char *new_name);
162 void print_lustre_cfg(struct lustre_cfg *lcfg);
163 int class_process_config(struct lustre_cfg *lcfg);
164 ssize_t class_set_global(const char *param);
165 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
166 struct kobject *kobj);
167 int class_attach(struct lustre_cfg *lcfg);
168 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
169 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
170 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
172 int class_find_param(char *buf, char *key, char **valp);
173 struct cfg_interop_param *class_find_old_param(const char *param,
174 struct cfg_interop_param *ptr);
175 int class_get_next_param(char **params, char *copy);
176 int class_match_param(char *buf, const char *key, char **valp);
177 int class_parse_nid(char *buf, struct lnet_nid *nid, char **endh);
178 int class_parse_nid_quiet(char *buf, struct lnet_nid *nid, char **endh);
179 int class_parse_net(char *buf, u32 *net, char **endh);
180 int class_match_nid(char *buf, char *key, struct lnet_nid *nid);
181 int class_match_net(char *buf, char *key, u32 net);
183 struct obd_device *class_incref(struct obd_device *obd,
184 const char *scope, const void *source);
185 void class_decref(struct obd_device *obd,
186 const char *scope, const void *source);
187 void dump_exports(struct obd_device *obd, int locks, int debug_level);
188 int class_config_llog_handler(const struct lu_env *env,
189 struct llog_handle *handle,
190 struct llog_rec_hdr *rec, void *data);
191 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
193 #define CFG_F_START 0x01 /* Set when we start updating from a log */
194 #define CFG_F_MARKER 0x02 /* We are within a maker */
195 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
196 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
198 /* Passed as data param to class_config_parse_llog */
199 struct config_llog_instance {
200 unsigned long cfg_instance;
201 struct super_block *cfg_sb;
202 struct obd_uuid cfg_uuid;
203 llog_cb_t cfg_callback;
204 int cfg_last_idx; /* for partial llog processing */
209 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
210 char *name, struct config_llog_instance *cfg);
213 * Generate a unique configuration instance for this mount
215 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
216 * For now, use the same value as before - the superblock pointer value.
218 * Using the client UUID would be an option, but it needs more testing.
220 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
222 return (unsigned long)sb;
225 #define CONFIG_SUB_SPTLRPC 0x01
226 #define CONFIG_SUB_RECOVER 0x02
227 #define CONFIG_SUB_PARAMS 0x04
228 #define CONFIG_SUB_NODEMAP 0x08
229 #define CONFIG_SUB_BARRIER 0x10
231 /* Sub clds should be attached to the config_llog_data when processing
232 * config log for client or server target. */
233 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
235 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
238 #define PARAMS_FILENAME "params"
239 #define BARRIER_FILENAME "barrier"
240 #define LCTL_UPCALL "lctl"
242 static inline bool logname_is_barrier(const char *logname)
246 /* logname for barrier is "fsname-barrier" */
247 ptr = strstr(logname, BARRIER_FILENAME);
248 if (ptr && (ptr - logname) >= 2 &&
249 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
255 /* list of active configuration logs */
256 struct config_llog_data {
257 struct ldlm_res_id cld_resid;
258 struct lustre_handle cld_lockh;
259 struct config_llog_instance cld_cfg;
260 struct list_head cld_list_chain;/* on config_llog_list */
261 atomic_t cld_refcount;
262 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
263 struct config_llog_data *cld_params; /* common parameters log */
264 struct config_llog_data *cld_recover;/* imperative recover log */
265 struct config_llog_data *cld_nodemap;/* nodemap log */
266 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
267 struct obd_export *cld_mgcexp;
268 struct mutex cld_lock;
269 enum mgs_cfg_type cld_type;
270 unsigned int cld_stopping:1, /* we were told to stop
272 cld_lostlock:1; /* lock not requeued */
276 struct lustre_profile {
277 struct list_head lp_list;
282 bool lp_list_deleted;
285 struct lustre_profile *class_get_profile(const char * prof);
286 void class_del_profile(const char *prof);
287 void class_put_profile(struct lustre_profile *lprof);
288 void class_del_profiles(void);
291 #if LUSTRE_TRACKS_LOCK_EXP_REFS
293 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
294 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
295 extern void (*class_export_dump_hook)(struct obd_export *);
299 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
300 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
304 #define class_export_rpc_inc(exp) \
306 atomic_inc(&(exp)->exp_rpc_count); \
307 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
308 (exp), atomic_read(&(exp)->exp_rpc_count)); \
311 #define class_export_rpc_dec(exp) \
313 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
314 atomic_dec(&(exp)->exp_rpc_count); \
315 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
316 (exp), atomic_read(&(exp)->exp_rpc_count)); \
319 #define class_export_lock_get(exp, lock) \
321 atomic_inc(&(exp)->exp_locks_count); \
322 __class_export_add_lock_ref(exp, lock); \
323 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
324 (exp), atomic_read(&(exp)->exp_locks_count)); \
325 class_export_get(exp); \
328 #define class_export_lock_put(exp, lock) \
330 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
331 atomic_dec(&(exp)->exp_locks_count); \
332 __class_export_del_lock_ref(exp, lock); \
333 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
334 (exp), atomic_read(&(exp)->exp_locks_count)); \
335 class_export_put(exp); \
338 #define class_export_cb_get(exp) \
340 atomic_inc(&(exp)->exp_cb_count); \
341 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
342 (exp), atomic_read(&(exp)->exp_cb_count)); \
343 class_export_get(exp); \
346 #define class_export_cb_put(exp) \
348 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
349 atomic_dec(&(exp)->exp_cb_count); \
350 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
351 (exp), atomic_read(&(exp)->exp_cb_count)); \
352 class_export_put(exp); \
356 struct obd_export *class_export_get(struct obd_export *exp);
357 void class_export_put(struct obd_export *exp);
358 struct obd_export *class_new_export(struct obd_device *obd,
359 struct obd_uuid *cluuid);
360 struct obd_export *class_new_export_self(struct obd_device *obd,
361 struct obd_uuid *uuid);
362 void class_unlink_export(struct obd_export *exp);
364 struct obd_import *class_import_get(struct obd_import *);
365 void class_import_put(struct obd_import *);
366 struct obd_import *class_new_import(struct obd_device *obd);
367 void class_destroy_import(struct obd_import *exp);
369 #ifdef HAVE_SERVER_SUPPORT
370 struct obd_type *class_search_type(const char *name);
371 struct obd_type *class_get_type(const char *name);
373 void class_put_type(struct obd_type *type);
374 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
375 struct obd_uuid *cluuid);
376 int class_disconnect(struct obd_export *exp);
377 void class_fail_export(struct obd_export *exp);
378 int class_connected_export(struct obd_export *exp);
379 void class_disconnect_exports(struct obd_device *obd);
380 int class_manual_cleanup(struct obd_device *obd);
381 void class_disconnect_stale_exports(struct obd_device *,
382 int (*test_export)(struct obd_export *));
384 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
386 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
387 (obd->obd_force ? OBD_OPT_FORCE : 0) |
388 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
392 #ifdef HAVE_SERVER_SUPPORT
393 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
395 struct obd_device_target *obt;
397 LASSERT(exp->exp_obd);
398 obt = (void *)&exp->exp_obd->u;
399 if (obt->obt_magic != OBT_MAGIC)
404 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
406 struct obd_device_target *obt = obd2obt(obd);
409 return &obt->obt_lut->lut_lsd;
417 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
418 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
420 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
421 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
423 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
424 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
426 static inline int obd_check_dev(struct obd_device *obd)
429 CERROR("NULL device\n");
435 /* ensure obd_setup and !obd_stopping */
436 #define OBD_CHECK_DEV_ACTIVE(obd) \
438 rc = obd_check_dev(obd); \
442 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
443 CERROR("Device %d not setup\n", \
450 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
452 /* Always add in ldlm_stats */
453 tmp->nid_ldlm_stats =
454 lprocfs_stats_alloc(LDLM_LAST_OPC - LDLM_FIRST_OPC,
455 LPROCFS_STATS_FLAG_NOPERCPU);
456 if (tmp->nid_ldlm_stats == NULL)
459 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
461 return lprocfs_stats_register(tmp->nid_proc, "ldlm_stats",
462 tmp->nid_ldlm_stats);
465 static inline int exp_check_ops(struct obd_export *exp)
470 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
476 static inline int class_devno_max(void)
478 return MAX_OBD_DEVICES;
481 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
482 __u32 keylen, void *key,
483 __u32 *vallen, void *val)
488 rc = exp_check_ops(exp);
492 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
493 CERROR("%s: no %s operation\n",
494 (exp)->exp_obd->obd_name, __func__);
498 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
502 static inline int obd_set_info_async(const struct lu_env *env,
503 struct obd_export *exp,
504 __u32 keylen, void *key,
505 __u32 vallen, void *val,
506 struct ptlrpc_request_set *set)
511 rc = exp_check_ops(exp);
515 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
516 CERROR("%s: no %s operation\n",
517 (exp)->exp_obd->obd_name, __func__);
521 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
527 * obd-lu integration.
529 * Functionality is being moved into new lu_device-based layering, but some
530 * pieces of configuration process are still based on obd devices.
532 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
533 * subsume ->o_setup() methods of obd devices they replace. The same for
534 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
535 * result, obd_setup() and obd_process_config() branch and call one XOR
538 * Yet neither lu_device_type_operations::ldto_device_fini() nor
539 * lu_device_type_operations::ldto_device_free() fully implement the
540 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
541 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
543 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
546 struct obd_type *type = obd->obd_type;
547 struct lu_device_type *ldt;
551 wait_var_event(&type->typ_lu,
552 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
555 struct lu_context session_ctx;
558 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
559 session_ctx.lc_thread = NULL;
560 lu_context_enter(&session_ctx);
562 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
564 struct lu_device *dev;
565 env.le_ses = &session_ctx;
566 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
569 obd->obd_lu_dev = dev;
571 #ifdef HAVE_SERVER_SUPPORT
572 if (lu_device_is_dt(dev) &&
573 lu2dt_dev(dev)->dd_rdonly)
574 obd->obd_read_only = 1;
580 lu_context_exit(&session_ctx);
581 lu_context_fini(&session_ctx);
583 if (!obd->obd_type->typ_dt_ops->o_setup) {
584 CERROR("%s: no %s operation\n", obd->obd_name,
588 rc = OBP(obd, setup)(obd, cfg);
593 static inline int obd_precleanup(struct obd_device *obd)
596 struct lu_device_type *ldt = obd->obd_type->typ_lu;
597 struct lu_device *d = obd->obd_lu_dev;
601 if (ldt != NULL && d != NULL) {
602 struct lu_env *env = lu_env_find();
607 rc = lu_env_init(env, ldt->ldt_ctx_tags);
611 ldt->ldt_ops->ldto_device_fini(env, d);
618 if (!obd->obd_type->typ_dt_ops->o_precleanup)
621 rc = OBP(obd, precleanup)(obd);
625 static inline int obd_cleanup(struct obd_device *obd)
628 struct lu_device_type *ldt = obd->obd_type->typ_lu;
629 struct lu_device *d = obd->obd_lu_dev;
632 if (ldt != NULL && d != NULL) {
635 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
637 ldt->ldt_ops->ldto_device_free(&env, d);
639 obd->obd_lu_dev = NULL;
642 if (!obd->obd_type->typ_dt_ops->o_cleanup)
645 rc = OBP(obd, cleanup)(obd);
649 static inline void obd_cleanup_client_import(struct obd_device *obd)
653 /* If we set up but never connected, the client import will not
656 down_write(&obd->u.cli.cl_sem);
657 if (obd->u.cli.cl_import) {
658 struct obd_import *imp;
660 imp = obd->u.cli.cl_import;
661 CDEBUG(D_CONFIG, "%s: client import never connected\n",
663 ptlrpc_invalidate_import(imp);
664 client_destroy_import(imp);
665 obd->u.cli.cl_import = NULL;
667 up_write(&obd->u.cli.cl_sem);
672 static inline int obd_process_config(struct obd_device *obd, int datalen,
676 struct lu_device_type *ldt = obd->obd_type->typ_lu;
677 struct lu_device *d = obd->obd_lu_dev;
681 obd->obd_process_conf = 1;
682 if (ldt != NULL && d != NULL) {
685 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
687 rc = d->ld_ops->ldo_process_config(&env, d, data);
691 if (!obd->obd_type->typ_dt_ops->o_process_config) {
692 CERROR("%s: no %s operation\n",
693 obd->obd_name, __func__);
696 rc = OBP(obd, process_config)(obd, datalen, data);
699 obd->obd_process_conf = 0;
704 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
710 rc = exp_check_ops(exp);
714 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
715 CERROR("%s: no %s operation\n",
716 (exp)->exp_obd->obd_name, __func__);
720 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
724 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
730 rc = exp_check_ops(exp);
734 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
735 CERROR("%s: no %s operation\n",
736 (exp)->exp_obd->obd_name, __func__);
740 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
744 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
750 rc = exp_check_ops(exp);
754 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
755 CERROR("%s: no %s operation\n",
756 (exp)->exp_obd->obd_name, __func__);
760 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
765 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
771 rc = exp_check_ops(exp);
775 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
776 CERROR("%s: no %s operation\n",
777 (exp)->exp_obd->obd_name, __func__);
781 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
786 static inline int obd_add_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_add_conn) {
795 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
799 rc = OBP(obd, add_conn)(imp, uuid, priority);
803 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
805 struct obd_device *obd = imp->imp_obd;
809 OBD_CHECK_DEV_ACTIVE(obd);
810 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
811 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
815 rc = OBP(obd, del_conn)(imp, uuid);
819 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
821 struct obd_uuid *uuid;
824 if (!exp->exp_obd->obd_type ||
825 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
828 uuid = OBP(exp->exp_obd, get_uuid)(exp);
832 /** Create a new /a exp on device /a obd for the uuid /a cluuid
833 * @param exp New export handle
834 * @param d Connect data, supported flags are set, flags also understood
835 * by obd are returned.
837 static inline int obd_connect(const struct lu_env *env,
838 struct obd_export **exp,struct obd_device *obd,
839 struct obd_uuid *cluuid,
840 struct obd_connect_data *data,
844 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
848 OBD_CHECK_DEV_ACTIVE(obd);
849 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
850 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
854 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
855 /* check that only subset is granted */
856 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
857 data->ocd_connect_flags));
861 static inline int obd_reconnect(const struct lu_env *env,
862 struct obd_export *exp,
863 struct obd_device *obd,
864 struct obd_uuid *cluuid,
865 struct obd_connect_data *d,
869 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
874 OBD_CHECK_DEV_ACTIVE(obd);
875 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
878 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
879 /* check that only subset is granted */
880 LASSERT(ergo(d != NULL,
881 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
885 static inline int obd_disconnect(struct obd_export *exp)
889 rc = exp_check_ops(exp);
893 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
894 CERROR("%s: no %s operation\n",
895 (exp)->exp_obd->obd_name, __func__);
899 rc = OBP(exp->exp_obd, disconnect)(exp);
903 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
904 enum lu_cli_type type)
909 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
912 rc = OBP(obd, fid_init)(obd, exp, type);
916 static inline int obd_fid_fini(struct obd_device *obd)
920 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
923 rc = OBP(obd, fid_fini)(obd);
927 static inline int obd_fid_alloc(const struct lu_env *env,
928 struct obd_export *exp,
930 struct md_op_data *op_data)
934 rc = exp_check_ops(exp);
938 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
939 CERROR("%s: no %s operation\n",
940 (exp)->exp_obd->obd_name, __func__);
944 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
948 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
953 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
954 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
958 /* Check poolname validity */
959 if (!poolname || poolname[0] == '\0' || lov_pool_is_reserved(poolname))
962 rc = OBP(obd, pool_new)(obd, poolname);
966 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
970 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
971 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
975 rc = OBP(obd, pool_del)(obd, poolname);
979 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
985 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
986 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
990 rc = OBP(obd, pool_add)(obd, poolname, ostname);
994 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1000 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1001 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1002 RETURN(-EOPNOTSUPP);
1005 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1009 static inline int obd_init_export(struct obd_export *exp)
1014 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1015 OBP((exp)->exp_obd, init_export))
1016 rc = OBP(exp->exp_obd, init_export)(exp);
1020 static inline int obd_destroy_export(struct obd_export *exp)
1023 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1024 OBP(exp->exp_obd, destroy_export))
1025 OBP(exp->exp_obd, destroy_export)(exp);
1029 /* @max_age is the oldest time in seconds that we accept using a cached data.
1030 * If the cache is older than @max_age we will get a new value from the
1031 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1033 static inline int obd_statfs_async(struct obd_export *exp,
1034 struct obd_info *oinfo,
1036 struct ptlrpc_request_set *rqset)
1038 struct obd_device *obd;
1043 if (exp == NULL || exp->exp_obd == NULL)
1047 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1049 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1053 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1054 obd->obd_name, obd->obd_osfs_age, max_age);
1055 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1060 /* @max_age is the oldest time in seconds that we accept using a cached data.
1061 * If the cache is older than @max_age we will get a new value from the
1062 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1064 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1065 struct obd_statfs *osfs, time64_t max_age,
1068 struct obd_device *obd;
1072 if (unlikely(exp == NULL || exp->exp_obd == NULL))
1076 OBD_CHECK_DEV_ACTIVE(obd);
1078 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1079 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1080 RETURN(-EOPNOTSUPP);
1083 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1084 obd->obd_name, obd->obd_osfs_age, max_age);
1085 /* ignore cache if aggregated isn't expected */
1086 if (obd->obd_osfs_age < max_age ||
1087 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1088 !(flags & OBD_STATFS_SUM))) {
1089 /* the RPC will block anyway, so avoid sending many at once */
1090 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1091 (flags & OBD_STATFS_NESTED)
1092 ? SINGLE_DEPTH_NESTING : 0);
1095 if (obd->obd_osfs_age < max_age ||
1096 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1097 !(flags & OBD_STATFS_SUM))) {
1098 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1100 mutex_unlock(&obd->obd_dev_mutex);
1101 GOTO(cached, rc = 0);
1105 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1106 obd->obd_name, &obd->obd_osfs,
1107 osfs->os_bavail, osfs->os_blocks,
1108 osfs->os_ffree, osfs->os_files);
1110 spin_lock(&obd->obd_osfs_lock);
1111 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1112 obd->obd_osfs_age = ktime_get_seconds();
1113 spin_unlock(&obd->obd_osfs_lock);
1115 mutex_unlock(&obd->obd_dev_mutex);
1119 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1120 obd->obd_name, &obd->obd_osfs,
1121 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1122 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1123 spin_lock(&obd->obd_osfs_lock);
1124 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1125 spin_unlock(&obd->obd_osfs_lock);
1130 static inline int obd_preprw(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 *remote, int *pages,
1134 struct niobuf_local *local)
1140 rc = exp_check_ops(exp);
1144 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1145 CERROR("%s: no %s operation\n",
1146 (exp)->exp_obd->obd_name, __func__);
1150 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1156 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1157 struct obd_export *exp, struct obdo *oa,
1158 int objcount, struct obd_ioobj *obj,
1159 struct niobuf_remote *rnb, int pages,
1160 struct niobuf_local *local, const int orig_rc,
1161 int nob, ktime_t kstart)
1166 rc = exp_check_ops(exp);
1170 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1171 CERROR("%s: no %s operation\n",
1172 (exp)->exp_obd->obd_name, __func__);
1176 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1177 rnb, pages, local, orig_rc, nob,
1183 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1184 int len, void *karg, void __user *uarg)
1189 rc = exp_check_ops(exp);
1193 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1194 CERROR("%s: no %s operation\n",
1195 (exp)->exp_obd->obd_name, __func__);
1199 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1203 static inline void obd_import_event(struct obd_device *obd,
1204 struct obd_import *imp,
1205 enum obd_import_event event)
1209 CERROR("NULL device\n");
1214 if (obd->obd_set_up && OBP(obd, import_event))
1215 OBP(obd, import_event)(obd, imp, event);
1220 static inline int obd_notify(struct obd_device *obd,
1221 struct obd_device *watched,
1222 enum obd_notify_event ev)
1227 rc = obd_check_dev(obd);
1231 if (!obd->obd_set_up) {
1232 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1236 if (!OBP(obd, notify)) {
1237 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1241 rc = OBP(obd, notify)(obd, watched, ev);
1246 static inline int obd_notify_observer(struct obd_device *observer,
1247 struct obd_device *observed,
1248 enum obd_notify_event ev)
1252 struct obd_notify_upcall *onu;
1254 if (observer->obd_observer)
1255 rc = obd_notify(observer->obd_observer, observed, ev);
1258 * Also, call non-obd listener, if any
1260 onu = &observer->obd_upcall;
1261 if (onu->onu_upcall != NULL)
1262 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1264 return rc ? rc : rc2;
1267 static inline int obd_quotactl(struct obd_export *exp,
1268 struct obd_quotactl *oqctl)
1273 rc = exp_check_ops(exp);
1277 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1278 CERROR("%s: no %s operation\n",
1279 (exp)->exp_obd->obd_name, __func__);
1283 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1287 static inline int obd_health_check(const struct lu_env *env,
1288 struct obd_device *obd)
1290 /* returns: 0 on healthy
1291 * >0 on unhealthy + reason code/flag
1292 * however the only suppored reason == 1 right now
1293 * We'll need to define some better reasons
1294 * or flags in the future.
1301 /* NULL method is normal here */
1302 if (obd == NULL || !obd->obd_type) {
1303 CERROR("cleaned up obd\n");
1304 RETURN(-EOPNOTSUPP);
1306 if (!obd->obd_set_up || obd->obd_stopping)
1308 if (!OBP(obd, health_check))
1311 rc = OBP(obd, health_check)(env, obd);
1315 static inline int obd_register_observer(struct obd_device *obd,
1316 struct obd_device *observer)
1321 rc = obd_check_dev(obd);
1325 down_write(&obd->obd_observer_link_sem);
1326 if (obd->obd_observer && observer) {
1327 up_write(&obd->obd_observer_link_sem);
1330 obd->obd_observer = observer;
1331 up_write(&obd->obd_observer_link_sem);
1335 /* metadata helpers */
1341 LPROC_MD_INTENT_LOCK,
1350 LPROC_MD_INTENT_GETATTR_ASYNC,
1351 LPROC_MD_REVALIDATE_LOCK,
1355 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1360 rc = exp_check_ops(exp);
1364 return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1367 static inline int md_getattr(struct obd_export *exp,
1368 struct md_op_data *op_data,
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, getattr)(exp, op_data, request);
1383 static inline int md_null_inode(struct obd_export *exp,
1384 const struct lu_fid *fid)
1388 rc = exp_check_ops(exp);
1392 return MDP(exp->exp_obd, null_inode)(exp, fid);
1395 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1396 struct md_open_data *mod,
1397 struct ptlrpc_request **request)
1401 rc = exp_check_ops(exp);
1405 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1408 return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1411 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1412 const void *data, size_t datalen, umode_t mode,
1413 uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1414 __u64 rdev, struct ptlrpc_request **request)
1418 rc = exp_check_ops(exp);
1422 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1425 return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1426 uid, gid, cap_effective, rdev,
1430 static inline int md_enqueue(struct obd_export *exp,
1431 struct ldlm_enqueue_info *einfo,
1432 const union ldlm_policy_data *policy,
1433 struct md_op_data *op_data,
1434 struct lustre_handle *lockh,
1435 __u64 extra_lock_flags)
1439 rc = exp_check_ops(exp);
1443 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1446 return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1450 static inline int md_getattr_name(struct obd_export *exp,
1451 struct md_op_data *op_data,
1452 struct ptlrpc_request **request)
1456 rc = exp_check_ops(exp);
1460 return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1463 static inline int md_intent_lock(struct obd_export *exp,
1464 struct md_op_data *op_data,
1465 struct lookup_intent *it,
1466 struct ptlrpc_request **reqp,
1467 ldlm_blocking_callback cb_blocking,
1468 __u64 extra_lock_flags)
1472 rc = exp_check_ops(exp);
1476 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1477 LPROC_MD_INTENT_LOCK);
1479 return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1480 cb_blocking, extra_lock_flags);
1483 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1484 struct ptlrpc_request **request)
1488 rc = exp_check_ops(exp);
1492 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1495 return MDP(exp->exp_obd, link)(exp, op_data, request);
1498 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1499 const char *old_name, size_t oldlen,
1500 const char *new_name, size_t newlen,
1501 struct ptlrpc_request **request)
1505 rc = exp_check_ops(exp);
1509 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1512 return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
1513 new_name, newlen, request);
1516 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1517 void *ea, size_t ealen,
1518 struct ptlrpc_request **request)
1522 rc = exp_check_ops(exp);
1526 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1529 return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1532 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1533 struct ptlrpc_request **request)
1537 rc = exp_check_ops(exp);
1541 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1544 return MDP(exp->exp_obd, fsync)(exp, fid, request);
1547 /* FLR: resync mirrored files. */
1548 static inline int md_file_resync(struct obd_export *exp,
1549 struct md_op_data *data)
1553 rc = exp_check_ops(exp);
1557 return MDP(exp->exp_obd, file_resync)(exp, data);
1560 static inline int md_read_page(struct obd_export *exp,
1561 struct md_op_data *op_data,
1562 struct md_readdir_info *mrinfo,
1563 __u64 hash_offset, struct page **ppage)
1567 rc = exp_check_ops(exp);
1571 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1572 LPROC_MD_READ_PAGE);
1574 return MDP(exp->exp_obd, read_page)(exp, op_data, mrinfo, hash_offset,
1578 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1579 struct ptlrpc_request **request)
1583 rc = exp_check_ops(exp);
1587 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1590 return MDP(exp->exp_obd, unlink)(exp, op_data, request);
1593 static inline int md_get_lustre_md(struct obd_export *exp,
1594 struct req_capsule *pill,
1595 struct obd_export *dt_exp,
1596 struct obd_export *md_exp,
1597 struct lustre_md *md)
1601 rc = exp_check_ops(exp);
1605 return MDP(exp->exp_obd, get_lustre_md)(exp, pill, dt_exp, md_exp, md);
1608 static inline int md_free_lustre_md(struct obd_export *exp,
1609 struct lustre_md *md)
1613 rc = exp_check_ops(exp);
1617 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1620 static inline int md_merge_attr(struct obd_export *exp,
1621 const struct lmv_stripe_md *lsm,
1622 struct cl_attr *attr,
1623 ldlm_blocking_callback cb)
1627 rc = exp_check_ops(exp);
1631 return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb);
1634 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1635 u64 obd_md_valid, const char *name,
1636 const void *value, size_t value_size,
1637 unsigned int xattr_flags, u32 suppgid,
1638 struct ptlrpc_request **req)
1642 rc = exp_check_ops(exp);
1646 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1649 return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1650 value, value_size, xattr_flags,
1654 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1655 u64 obd_md_valid, const char *name,
1656 size_t buf_size, struct ptlrpc_request **req)
1660 rc = exp_check_ops(exp);
1664 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1667 return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1671 static inline int md_set_open_replay_data(struct obd_export *exp,
1672 struct obd_client_handle *och,
1673 struct lookup_intent *it)
1677 rc = exp_check_ops(exp);
1681 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1684 static inline int md_clear_open_replay_data(struct obd_export *exp,
1685 struct obd_client_handle *och)
1689 rc = exp_check_ops(exp);
1693 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1696 static inline int md_set_lock_data(struct obd_export *exp,
1697 const struct lustre_handle *lockh,
1698 void *data, __u64 *bits)
1702 rc = exp_check_ops(exp);
1706 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1710 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1711 union ldlm_policy_data *policy, enum ldlm_mode mode,
1712 enum ldlm_cancel_flags cancel_flags, void *opaque)
1716 rc = exp_check_ops(exp);
1720 return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1721 cancel_flags, opaque);
1724 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1725 const struct lu_fid *fid,
1726 enum ldlm_type type,
1727 union ldlm_policy_data *policy,
1728 enum ldlm_mode mode,
1729 struct lustre_handle *lockh)
1733 rc = exp_check_ops(exp);
1737 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1738 policy, mode, lockh);
1741 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1746 rc = exp_check_ops(exp);
1750 return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
1753 static inline int md_intent_getattr_async(struct obd_export *exp,
1754 struct md_op_item *item)
1758 rc = exp_check_ops(exp);
1762 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1763 LPROC_MD_INTENT_GETATTR_ASYNC);
1765 return MDP(exp->exp_obd, intent_getattr_async)(exp, item);
1768 static inline int md_revalidate_lock(struct obd_export *exp,
1769 struct lookup_intent *it,
1770 struct lu_fid *fid, __u64 *bits)
1774 rc = exp_check_ops(exp);
1778 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1779 LPROC_MD_REVALIDATE_LOCK);
1781 return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1784 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1785 const struct lmv_stripe_md *lsm,
1786 const char *name, int namelen,
1791 rc = exp_check_ops(exp);
1795 return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
1799 /* Unpack an MD struct from disk to in-memory format.
1800 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1802 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1803 * If *plsm == NULL then it will be allocated.
1805 static inline int md_unpackmd(struct obd_export *exp,
1806 struct lmv_stripe_md **plsm,
1807 const union lmv_mds_md *lmm, size_t lmm_size)
1811 rc = exp_check_ops(exp);
1815 return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1818 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1819 int *rcs, struct ptlrpc_request_set *set)
1823 rc = exp_check_ops(exp);
1827 return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
1830 static inline struct lu_batch *
1831 md_batch_create(struct obd_export *exp, enum lu_batch_flags flags,
1836 rc = exp_check_ops(exp);
1840 return MDP(exp->exp_obd, batch_create)(exp, flags, max_count);
1843 static inline int md_batch_stop(struct obd_export *exp, struct lu_batch *bh)
1847 rc = exp_check_ops(exp);
1851 return MDP(exp->exp_obd, batch_stop)(exp, bh);
1854 static inline int md_batch_flush(struct obd_export *exp, struct lu_batch *bh,
1859 rc = exp_check_ops(exp);
1863 return MDP(exp->exp_obd, batch_flush)(exp, bh, wait);
1866 static inline int md_batch_add(struct obd_export *exp, struct lu_batch *bh,
1867 struct md_op_item *item)
1871 rc = exp_check_ops(exp);
1875 return MDP(exp->exp_obd, batch_add)(exp, bh, item);
1878 /* OBD Metadata Support */
1880 extern int obd_init_caches(void);
1881 extern void obd_cleanup_caches(void);
1883 typedef int (*register_lwp_cb)(void *data);
1885 struct lwp_register_item {
1886 struct obd_export **lri_exp;
1887 register_lwp_cb lri_cb_func;
1889 struct list_head lri_list;
1891 char lri_name[MTI_NAME_MAXLEN];
1895 #ifdef HAVE_SERVER_SUPPORT
1896 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1897 register_lwp_cb cb_func, void *cb_data);
1898 void lustre_deregister_lwp_item(struct obd_export **exp);
1899 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1900 void lustre_notify_lwp_list(struct obd_export *exp);
1901 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1902 #endif /* HAVE_SERVER_SUPPORT */
1903 int lustre_check_exclusion(struct super_block *sb, char *svname);
1906 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
1908 int class_add_uuid(const char *uuid, struct lnet_nid *nid);
1909 int class_del_uuid (const char *uuid);
1910 int class_add_nids_to_uuid(struct obd_uuid *uuid, lnet_nid_t *nids,
1912 int class_check_uuid(struct obd_uuid *uuid, struct lnet_nid *nid);
1915 extern char obd_jobid_name[];
1917 extern unsigned int obd_lbug_on_eviction;
1918 extern unsigned int obd_dump_on_eviction;
1920 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
1922 if (obd_lbug_on_eviction &&
1923 strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
1924 strlen(LUSTRE_MGC_NAME))) {
1925 CERROR("LBUG upon eviction\n");
1929 return obd_dump_on_eviction;
1934 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1935 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1937 /* root squash info */
1938 struct root_squash_info {
1941 struct list_head rsi_nosquash_nids;
1942 spinlock_t rsi_lock;
1945 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1947 /* linux-module.c */
1948 struct obd_ioctl_data;
1949 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
1950 int class_procfs_init(void);
1951 int class_procfs_clean(void);
1953 extern void obd_heat_add(struct obd_heat_instance *instance,
1954 unsigned int time_second, __u64 count,
1955 unsigned int weight, unsigned int period_second);
1956 extern void obd_heat_decay(struct obd_heat_instance *instance,
1957 __u64 time_second, unsigned int weight,
1958 unsigned int period_second);
1959 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
1960 unsigned int time_second, unsigned int weight,
1961 unsigned int period_second);
1962 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
1964 /* struct kobj_type */
1966 struct attribute *_get_attr_matches(const struct kobj_type *typ,
1967 const char *key, size_t keylen,
1968 int (*is_match)(const char *, const char *,
1973 #ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
1974 for (i = 0; typ->default_groups[i]; i++) {
1976 struct attribute **attrs;
1978 attrs = (struct attribute **)typ->default_groups[i]->attrs;
1979 for (k = 0; attrs[k]; k++) {
1980 if (is_match(attrs[k]->name, key, keylen))
1981 return (struct attribute *)attrs[k];
1985 for (i = 0; typ->default_attrs[i]; i++) {
1986 if (is_match(typ->default_attrs[i]->name, key, keylen))
1987 return typ->default_attrs[i];
1994 int _attr_name_exact(const char *attr_name, const char *key, size_t len)
1996 return !strcmp(attr_name, key);
2000 struct attribute *get_attr_by_name(const struct kobj_type *typ,
2003 return _get_attr_matches(typ, name, 0, _attr_name_exact);
2007 int _attr_name_starts_with(const char *attr_name, const char *name, size_t len)
2009 return !strncmp(attr_name, name, len);
2013 struct attribute *get_attr_starts_with(const struct kobj_type *typ,
2017 return _get_attr_matches(typ, name, len, _attr_name_starts_with);
2020 int obd_ioctl_msg(const char *file, const char *func, int line, int level,
2021 const char *name, unsigned int cmd, const char *msg, int rc);
2022 #define OBD_IOC_DEBUG(level, dev, cmd, msg, rc) \
2023 obd_ioctl_msg(__FILE__, __func__, __LINE__, level, dev, cmd, msg, rc)
2024 #define OBD_IOC_ERROR(dev, cmd, msg, rc) \
2025 obd_ioctl_msg(__FILE__, __func__, __LINE__, D_ERROR, dev, cmd, msg, rc)
2027 #endif /* __LINUX_OBD_CLASS_H */