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_nid4(char *buf, lnet_nid_t *nid4, char **endh);
178 int class_parse_nid4_quiet(char *buf, lnet_nid_t *nid4, char **endh);
179 int class_parse_nid(char *buf, struct lnet_nid *nid, char **endh);
180 int class_parse_nid_quiet(char *buf, struct lnet_nid *nid, char **endh);
181 int class_parse_net(char *buf, u32 *net, char **endh);
182 int class_match_nid(char *buf, char *key, struct lnet_nid *nid);
183 int class_match_net(char *buf, char *key, u32 net);
185 struct obd_device *class_incref(struct obd_device *obd,
186 const char *scope, const void *source);
187 void class_decref(struct obd_device *obd,
188 const char *scope, const void *source);
189 void dump_exports(struct obd_device *obd, int locks, int debug_level);
190 int class_config_llog_handler(const struct lu_env *env,
191 struct llog_handle *handle,
192 struct llog_rec_hdr *rec, void *data);
193 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
195 #define CFG_F_START 0x01 /* Set when we start updating from a log */
196 #define CFG_F_MARKER 0x02 /* We are within a maker */
197 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
198 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
200 /* Passed as data param to class_config_parse_llog */
201 struct config_llog_instance {
202 unsigned long cfg_instance;
203 struct super_block *cfg_sb;
204 struct obd_uuid cfg_uuid;
205 llog_cb_t cfg_callback;
206 int cfg_last_idx; /* for partial llog processing */
211 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
212 char *name, struct config_llog_instance *cfg);
215 * Generate a unique configuration instance for this mount
217 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
218 * For now, use the same value as before - the superblock pointer value.
220 * Using the client UUID would be an option, but it needs more testing.
222 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
224 return (unsigned long)sb;
227 #define CONFIG_SUB_SPTLRPC 0x01
228 #define CONFIG_SUB_RECOVER 0x02
229 #define CONFIG_SUB_PARAMS 0x04
230 #define CONFIG_SUB_NODEMAP 0x08
231 #define CONFIG_SUB_BARRIER 0x10
233 /* Sub clds should be attached to the config_llog_data when processing
234 * config log for client or server target. */
235 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
237 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
240 #define PARAMS_FILENAME "params"
241 #define BARRIER_FILENAME "barrier"
242 #define LCTL_UPCALL "lctl"
244 static inline bool logname_is_barrier(const char *logname)
248 /* logname for barrier is "fsname-barrier" */
249 ptr = strstr(logname, BARRIER_FILENAME);
250 if (ptr && (ptr - logname) >= 2 &&
251 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
257 /* list of active configuration logs */
258 struct config_llog_data {
259 struct ldlm_res_id cld_resid;
260 struct lustre_handle cld_lockh;
261 struct config_llog_instance cld_cfg;
262 struct list_head cld_list_chain;/* on config_llog_list */
263 atomic_t cld_refcount;
264 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
265 struct config_llog_data *cld_params; /* common parameters log */
266 struct config_llog_data *cld_recover;/* imperative recover log */
267 struct config_llog_data *cld_nodemap;/* nodemap log */
268 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
269 struct obd_export *cld_mgcexp;
270 struct mutex cld_lock;
271 enum mgs_cfg_type cld_type;
272 unsigned int cld_stopping:1, /* we were told to stop
274 cld_lostlock:1; /* lock not requeued */
278 struct lustre_profile {
279 struct list_head lp_list;
284 bool lp_list_deleted;
287 struct lustre_profile *class_get_profile(const char * prof);
288 void class_del_profile(const char *prof);
289 void class_put_profile(struct lustre_profile *lprof);
290 void class_del_profiles(void);
293 #if LUSTRE_TRACKS_LOCK_EXP_REFS
295 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
296 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
297 extern void (*class_export_dump_hook)(struct obd_export *);
301 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
302 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
306 #define class_export_rpc_inc(exp) \
308 atomic_inc(&(exp)->exp_rpc_count); \
309 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
310 (exp), atomic_read(&(exp)->exp_rpc_count)); \
313 #define class_export_rpc_dec(exp) \
315 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
316 atomic_dec(&(exp)->exp_rpc_count); \
317 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
318 (exp), atomic_read(&(exp)->exp_rpc_count)); \
321 #define class_export_lock_get(exp, lock) \
323 atomic_inc(&(exp)->exp_locks_count); \
324 __class_export_add_lock_ref(exp, lock); \
325 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
326 (exp), atomic_read(&(exp)->exp_locks_count)); \
327 class_export_get(exp); \
330 #define class_export_lock_put(exp, lock) \
332 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
333 atomic_dec(&(exp)->exp_locks_count); \
334 __class_export_del_lock_ref(exp, lock); \
335 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
336 (exp), atomic_read(&(exp)->exp_locks_count)); \
337 class_export_put(exp); \
340 #define class_export_cb_get(exp) \
342 atomic_inc(&(exp)->exp_cb_count); \
343 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
344 (exp), atomic_read(&(exp)->exp_cb_count)); \
345 class_export_get(exp); \
348 #define class_export_cb_put(exp) \
350 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
351 atomic_dec(&(exp)->exp_cb_count); \
352 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
353 (exp), atomic_read(&(exp)->exp_cb_count)); \
354 class_export_put(exp); \
358 struct obd_export *class_export_get(struct obd_export *exp);
359 void class_export_put(struct obd_export *exp);
360 struct obd_export *class_new_export(struct obd_device *obd,
361 struct obd_uuid *cluuid);
362 struct obd_export *class_new_export_self(struct obd_device *obd,
363 struct obd_uuid *uuid);
364 void class_unlink_export(struct obd_export *exp);
366 struct obd_import *class_import_get(struct obd_import *);
367 void class_import_put(struct obd_import *);
368 struct obd_import *class_new_import(struct obd_device *obd);
369 void class_destroy_import(struct obd_import *exp);
371 #ifdef HAVE_SERVER_SUPPORT
372 struct obd_type *class_search_type(const char *name);
373 struct obd_type *class_get_type(const char *name);
375 void class_put_type(struct obd_type *type);
376 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
377 struct obd_uuid *cluuid);
378 int class_disconnect(struct obd_export *exp);
379 void class_fail_export(struct obd_export *exp);
380 int class_connected_export(struct obd_export *exp);
381 void class_disconnect_exports(struct obd_device *obd);
382 int class_manual_cleanup(struct obd_device *obd);
383 void class_disconnect_stale_exports(struct obd_device *,
384 int (*test_export)(struct obd_export *));
386 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
388 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
389 (obd->obd_force ? OBD_OPT_FORCE : 0) |
390 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
394 #ifdef HAVE_SERVER_SUPPORT
395 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
397 struct obd_device_target *obt;
399 LASSERT(exp->exp_obd);
400 obt = (void *)&exp->exp_obd->u;
401 if (obt->obt_magic != OBT_MAGIC)
406 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
408 struct obd_device_target *obt = obd2obt(obd);
411 return &obt->obt_lut->lut_lsd;
419 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
420 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
422 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
423 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
425 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
426 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
428 static inline int obd_check_dev(struct obd_device *obd)
431 CERROR("NULL device\n");
437 /* ensure obd_setup and !obd_stopping */
438 #define OBD_CHECK_DEV_ACTIVE(obd) \
440 rc = obd_check_dev(obd); \
444 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
445 CERROR("Device %d not setup\n", \
452 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
454 /* Always add in ldlm_stats */
455 tmp->nid_ldlm_stats =
456 lprocfs_stats_alloc(LDLM_LAST_OPC - LDLM_FIRST_OPC,
457 LPROCFS_STATS_FLAG_NOPERCPU);
458 if (tmp->nid_ldlm_stats == NULL)
461 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
463 return lprocfs_stats_register(tmp->nid_proc, "ldlm_stats",
464 tmp->nid_ldlm_stats);
467 static inline int exp_check_ops(struct obd_export *exp)
472 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
478 static inline int class_devno_max(void)
480 return MAX_OBD_DEVICES;
483 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
484 __u32 keylen, void *key,
485 __u32 *vallen, void *val)
490 rc = exp_check_ops(exp);
494 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
495 CERROR("%s: no %s operation\n",
496 (exp)->exp_obd->obd_name, __func__);
500 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
504 static inline int obd_set_info_async(const struct lu_env *env,
505 struct obd_export *exp,
506 __u32 keylen, void *key,
507 __u32 vallen, void *val,
508 struct ptlrpc_request_set *set)
513 rc = exp_check_ops(exp);
517 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
518 CERROR("%s: no %s operation\n",
519 (exp)->exp_obd->obd_name, __func__);
523 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
529 * obd-lu integration.
531 * Functionality is being moved into new lu_device-based layering, but some
532 * pieces of configuration process are still based on obd devices.
534 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
535 * subsume ->o_setup() methods of obd devices they replace. The same for
536 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
537 * result, obd_setup() and obd_process_config() branch and call one XOR
540 * Yet neither lu_device_type_operations::ldto_device_fini() nor
541 * lu_device_type_operations::ldto_device_free() fully implement the
542 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
543 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
545 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
548 struct obd_type *type = obd->obd_type;
549 struct lu_device_type *ldt;
553 wait_var_event(&type->typ_lu,
554 smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
557 struct lu_context session_ctx;
560 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
561 session_ctx.lc_thread = NULL;
562 lu_context_enter(&session_ctx);
564 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
566 struct lu_device *dev;
567 env.le_ses = &session_ctx;
568 dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
571 obd->obd_lu_dev = dev;
573 #ifdef HAVE_SERVER_SUPPORT
574 if (lu_device_is_dt(dev) &&
575 lu2dt_dev(dev)->dd_rdonly)
576 obd->obd_read_only = 1;
582 lu_context_exit(&session_ctx);
583 lu_context_fini(&session_ctx);
585 if (!obd->obd_type->typ_dt_ops->o_setup) {
586 CERROR("%s: no %s operation\n", obd->obd_name,
590 rc = OBP(obd, setup)(obd, cfg);
595 static inline int obd_precleanup(struct obd_device *obd)
598 struct lu_device_type *ldt = obd->obd_type->typ_lu;
599 struct lu_device *d = obd->obd_lu_dev;
603 if (ldt != NULL && d != NULL) {
604 struct lu_env *env = lu_env_find();
609 rc = lu_env_init(env, ldt->ldt_ctx_tags);
613 ldt->ldt_ops->ldto_device_fini(env, d);
620 if (!obd->obd_type->typ_dt_ops->o_precleanup)
623 rc = OBP(obd, precleanup)(obd);
627 static inline int obd_cleanup(struct obd_device *obd)
630 struct lu_device_type *ldt = obd->obd_type->typ_lu;
631 struct lu_device *d = obd->obd_lu_dev;
634 if (ldt != NULL && d != NULL) {
637 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
639 ldt->ldt_ops->ldto_device_free(&env, d);
641 obd->obd_lu_dev = NULL;
644 if (!obd->obd_type->typ_dt_ops->o_cleanup)
647 rc = OBP(obd, cleanup)(obd);
651 static inline void obd_cleanup_client_import(struct obd_device *obd)
655 /* If we set up but never connected, the client import will not
658 down_write(&obd->u.cli.cl_sem);
659 if (obd->u.cli.cl_import) {
660 struct obd_import *imp;
662 imp = obd->u.cli.cl_import;
663 CDEBUG(D_CONFIG, "%s: client import never connected\n",
665 ptlrpc_invalidate_import(imp);
666 client_destroy_import(imp);
667 obd->u.cli.cl_import = NULL;
669 up_write(&obd->u.cli.cl_sem);
674 static inline int obd_process_config(struct obd_device *obd, int datalen,
678 struct lu_device_type *ldt = obd->obd_type->typ_lu;
679 struct lu_device *d = obd->obd_lu_dev;
683 obd->obd_process_conf = 1;
684 if (ldt != NULL && d != NULL) {
687 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
689 rc = d->ld_ops->ldo_process_config(&env, d, data);
693 if (!obd->obd_type->typ_dt_ops->o_process_config) {
694 CERROR("%s: no %s operation\n",
695 obd->obd_name, __func__);
698 rc = OBP(obd, process_config)(obd, datalen, data);
701 obd->obd_process_conf = 0;
706 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
712 rc = exp_check_ops(exp);
716 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
717 CERROR("%s: no %s operation\n",
718 (exp)->exp_obd->obd_name, __func__);
722 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
726 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
732 rc = exp_check_ops(exp);
736 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
737 CERROR("%s: no %s operation\n",
738 (exp)->exp_obd->obd_name, __func__);
742 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
746 static inline int obd_getattr(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_getattr) {
757 CERROR("%s: no %s operation\n",
758 (exp)->exp_obd->obd_name, __func__);
762 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
767 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
773 rc = exp_check_ops(exp);
777 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
778 CERROR("%s: no %s operation\n",
779 (exp)->exp_obd->obd_name, __func__);
783 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
788 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
791 struct obd_device *obd = imp->imp_obd;
795 OBD_CHECK_DEV_ACTIVE(obd);
796 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
797 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
801 rc = OBP(obd, add_conn)(imp, uuid, priority);
805 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
807 struct obd_device *obd = imp->imp_obd;
811 OBD_CHECK_DEV_ACTIVE(obd);
812 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
813 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
817 rc = OBP(obd, del_conn)(imp, uuid);
821 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
823 struct obd_uuid *uuid;
826 if (!exp->exp_obd->obd_type ||
827 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
830 uuid = OBP(exp->exp_obd, get_uuid)(exp);
834 /** Create a new /a exp on device /a obd for the uuid /a cluuid
835 * @param exp New export handle
836 * @param d Connect data, supported flags are set, flags also understood
837 * by obd are returned.
839 static inline int obd_connect(const struct lu_env *env,
840 struct obd_export **exp,struct obd_device *obd,
841 struct obd_uuid *cluuid,
842 struct obd_connect_data *data,
846 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
850 OBD_CHECK_DEV_ACTIVE(obd);
851 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
852 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
856 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
857 /* check that only subset is granted */
858 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
859 data->ocd_connect_flags));
863 static inline int obd_reconnect(const struct lu_env *env,
864 struct obd_export *exp,
865 struct obd_device *obd,
866 struct obd_uuid *cluuid,
867 struct obd_connect_data *d,
871 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
876 OBD_CHECK_DEV_ACTIVE(obd);
877 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
880 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
881 /* check that only subset is granted */
882 LASSERT(ergo(d != NULL,
883 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
887 static inline int obd_disconnect(struct obd_export *exp)
891 rc = exp_check_ops(exp);
895 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
896 CERROR("%s: no %s operation\n",
897 (exp)->exp_obd->obd_name, __func__);
901 rc = OBP(exp->exp_obd, disconnect)(exp);
905 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
906 enum lu_cli_type type)
911 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
914 rc = OBP(obd, fid_init)(obd, exp, type);
918 static inline int obd_fid_fini(struct obd_device *obd)
922 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
925 rc = OBP(obd, fid_fini)(obd);
929 static inline int obd_fid_alloc(const struct lu_env *env,
930 struct obd_export *exp,
932 struct md_op_data *op_data)
936 rc = exp_check_ops(exp);
940 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
941 CERROR("%s: no %s operation\n",
942 (exp)->exp_obd->obd_name, __func__);
946 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
950 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
955 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
956 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
960 /* Check poolname validity */
961 if (!poolname || poolname[0] == '\0' || lov_pool_is_reserved(poolname))
964 rc = OBP(obd, pool_new)(obd, poolname);
968 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
972 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
973 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
977 rc = OBP(obd, pool_del)(obd, poolname);
981 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
987 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
988 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
992 rc = OBP(obd, pool_add)(obd, poolname, ostname);
996 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1002 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1003 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1004 RETURN(-EOPNOTSUPP);
1007 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1011 static inline int obd_init_export(struct obd_export *exp)
1016 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1017 OBP((exp)->exp_obd, init_export))
1018 rc = OBP(exp->exp_obd, init_export)(exp);
1022 static inline int obd_destroy_export(struct obd_export *exp)
1025 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1026 OBP(exp->exp_obd, destroy_export))
1027 OBP(exp->exp_obd, destroy_export)(exp);
1031 /* @max_age is the oldest time in seconds that we accept using a cached data.
1032 * If the cache is older than @max_age we will get a new value from the
1033 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1035 static inline int obd_statfs_async(struct obd_export *exp,
1036 struct obd_info *oinfo,
1038 struct ptlrpc_request_set *rqset)
1040 struct obd_device *obd;
1045 if (exp == NULL || exp->exp_obd == NULL)
1049 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1051 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1055 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1056 obd->obd_name, obd->obd_osfs_age, max_age);
1057 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1062 /* @max_age is the oldest time in seconds that we accept using a cached data.
1063 * If the cache is older than @max_age we will get a new value from the
1064 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1066 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1067 struct obd_statfs *osfs, time64_t max_age,
1070 struct obd_device *obd;
1074 if (unlikely(exp == NULL || exp->exp_obd == NULL))
1078 OBD_CHECK_DEV_ACTIVE(obd);
1080 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1081 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1082 RETURN(-EOPNOTSUPP);
1085 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1086 obd->obd_name, obd->obd_osfs_age, max_age);
1087 /* ignore cache if aggregated isn't expected */
1088 if (obd->obd_osfs_age < max_age ||
1089 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1090 !(flags & OBD_STATFS_SUM))) {
1091 /* the RPC will block anyway, so avoid sending many at once */
1092 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1093 (flags & OBD_STATFS_NESTED)
1094 ? SINGLE_DEPTH_NESTING : 0);
1097 if (obd->obd_osfs_age < max_age ||
1098 ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1099 !(flags & OBD_STATFS_SUM))) {
1100 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1102 mutex_unlock(&obd->obd_dev_mutex);
1103 GOTO(cached, rc = 0);
1107 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1108 obd->obd_name, &obd->obd_osfs,
1109 osfs->os_bavail, osfs->os_blocks,
1110 osfs->os_ffree, osfs->os_files);
1112 spin_lock(&obd->obd_osfs_lock);
1113 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1114 obd->obd_osfs_age = ktime_get_seconds();
1115 spin_unlock(&obd->obd_osfs_lock);
1117 mutex_unlock(&obd->obd_dev_mutex);
1121 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1122 obd->obd_name, &obd->obd_osfs,
1123 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1124 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1125 spin_lock(&obd->obd_osfs_lock);
1126 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1127 spin_unlock(&obd->obd_osfs_lock);
1132 static inline int obd_preprw(const struct lu_env *env, int cmd,
1133 struct obd_export *exp, struct obdo *oa,
1134 int objcount, struct obd_ioobj *obj,
1135 struct niobuf_remote *remote, int *pages,
1136 struct niobuf_local *local)
1142 rc = exp_check_ops(exp);
1146 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1147 CERROR("%s: no %s operation\n",
1148 (exp)->exp_obd->obd_name, __func__);
1152 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1158 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1159 struct obd_export *exp, struct obdo *oa,
1160 int objcount, struct obd_ioobj *obj,
1161 struct niobuf_remote *rnb, int pages,
1162 struct niobuf_local *local, const int orig_rc,
1163 int nob, ktime_t kstart)
1168 rc = exp_check_ops(exp);
1172 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1173 CERROR("%s: no %s operation\n",
1174 (exp)->exp_obd->obd_name, __func__);
1178 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1179 rnb, pages, local, orig_rc, nob,
1185 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1186 int len, void *karg, void __user *uarg)
1191 rc = exp_check_ops(exp);
1195 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1196 CERROR("%s: no %s operation\n",
1197 (exp)->exp_obd->obd_name, __func__);
1201 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1205 static inline void obd_import_event(struct obd_device *obd,
1206 struct obd_import *imp,
1207 enum obd_import_event event)
1211 CERROR("NULL device\n");
1216 if (obd->obd_set_up && OBP(obd, import_event))
1217 OBP(obd, import_event)(obd, imp, event);
1222 static inline int obd_notify(struct obd_device *obd,
1223 struct obd_device *watched,
1224 enum obd_notify_event ev)
1229 rc = obd_check_dev(obd);
1233 if (!obd->obd_set_up) {
1234 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1238 if (!OBP(obd, notify)) {
1239 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1243 rc = OBP(obd, notify)(obd, watched, ev);
1248 static inline int obd_notify_observer(struct obd_device *observer,
1249 struct obd_device *observed,
1250 enum obd_notify_event ev)
1254 struct obd_notify_upcall *onu;
1256 if (observer->obd_observer)
1257 rc = obd_notify(observer->obd_observer, observed, ev);
1260 * Also, call non-obd listener, if any
1262 onu = &observer->obd_upcall;
1263 if (onu->onu_upcall != NULL)
1264 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1266 return rc ? rc : rc2;
1269 static inline int obd_quotactl(struct obd_export *exp,
1270 struct obd_quotactl *oqctl)
1275 rc = exp_check_ops(exp);
1279 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1280 CERROR("%s: no %s operation\n",
1281 (exp)->exp_obd->obd_name, __func__);
1285 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1289 static inline int obd_health_check(const struct lu_env *env,
1290 struct obd_device *obd)
1292 /* returns: 0 on healthy
1293 * >0 on unhealthy + reason code/flag
1294 * however the only suppored reason == 1 right now
1295 * We'll need to define some better reasons
1296 * or flags in the future.
1303 /* NULL method is normal here */
1304 if (obd == NULL || !obd->obd_type) {
1305 CERROR("cleaned up obd\n");
1306 RETURN(-EOPNOTSUPP);
1308 if (!obd->obd_set_up || obd->obd_stopping)
1310 if (!OBP(obd, health_check))
1313 rc = OBP(obd, health_check)(env, obd);
1317 static inline int obd_register_observer(struct obd_device *obd,
1318 struct obd_device *observer)
1323 rc = obd_check_dev(obd);
1327 down_write(&obd->obd_observer_link_sem);
1328 if (obd->obd_observer && observer) {
1329 up_write(&obd->obd_observer_link_sem);
1332 obd->obd_observer = observer;
1333 up_write(&obd->obd_observer_link_sem);
1337 /* metadata helpers */
1343 LPROC_MD_INTENT_LOCK,
1352 LPROC_MD_INTENT_GETATTR_ASYNC,
1353 LPROC_MD_REVALIDATE_LOCK,
1357 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1362 rc = exp_check_ops(exp);
1366 return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1369 static inline int md_getattr(struct obd_export *exp,
1370 struct md_op_data *op_data,
1371 struct ptlrpc_request **request)
1375 rc = exp_check_ops(exp);
1379 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1382 return MDP(exp->exp_obd, getattr)(exp, op_data, request);
1385 static inline int md_null_inode(struct obd_export *exp,
1386 const struct lu_fid *fid)
1390 rc = exp_check_ops(exp);
1394 return MDP(exp->exp_obd, null_inode)(exp, fid);
1397 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1398 struct md_open_data *mod,
1399 struct ptlrpc_request **request)
1403 rc = exp_check_ops(exp);
1407 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1410 return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1413 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1414 const void *data, size_t datalen, umode_t mode,
1415 uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1416 __u64 rdev, struct ptlrpc_request **request)
1420 rc = exp_check_ops(exp);
1424 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1427 return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1428 uid, gid, cap_effective, rdev,
1432 static inline int md_enqueue(struct obd_export *exp,
1433 struct ldlm_enqueue_info *einfo,
1434 const union ldlm_policy_data *policy,
1435 struct md_op_data *op_data,
1436 struct lustre_handle *lockh,
1437 __u64 extra_lock_flags)
1441 rc = exp_check_ops(exp);
1445 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1448 return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1452 static inline int md_getattr_name(struct obd_export *exp,
1453 struct md_op_data *op_data,
1454 struct ptlrpc_request **request)
1458 rc = exp_check_ops(exp);
1462 return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1465 static inline int md_intent_lock(struct obd_export *exp,
1466 struct md_op_data *op_data,
1467 struct lookup_intent *it,
1468 struct ptlrpc_request **reqp,
1469 ldlm_blocking_callback cb_blocking,
1470 __u64 extra_lock_flags)
1474 rc = exp_check_ops(exp);
1478 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1479 LPROC_MD_INTENT_LOCK);
1481 return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1482 cb_blocking, extra_lock_flags);
1485 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1486 struct ptlrpc_request **request)
1490 rc = exp_check_ops(exp);
1494 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1497 return MDP(exp->exp_obd, link)(exp, op_data, request);
1500 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1501 const char *old_name, size_t oldlen,
1502 const char *new_name, size_t newlen,
1503 struct ptlrpc_request **request)
1507 rc = exp_check_ops(exp);
1511 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1514 return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
1515 new_name, newlen, request);
1518 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1519 void *ea, size_t ealen,
1520 struct ptlrpc_request **request)
1524 rc = exp_check_ops(exp);
1528 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1531 return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1534 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1535 struct ptlrpc_request **request)
1539 rc = exp_check_ops(exp);
1543 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1546 return MDP(exp->exp_obd, fsync)(exp, fid, request);
1549 /* FLR: resync mirrored files. */
1550 static inline int md_file_resync(struct obd_export *exp,
1551 struct md_op_data *data)
1555 rc = exp_check_ops(exp);
1559 return MDP(exp->exp_obd, file_resync)(exp, data);
1562 static inline int md_read_page(struct obd_export *exp,
1563 struct md_op_data *op_data,
1564 struct md_readdir_info *mrinfo,
1565 __u64 hash_offset, struct page **ppage)
1569 rc = exp_check_ops(exp);
1573 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1574 LPROC_MD_READ_PAGE);
1576 return MDP(exp->exp_obd, read_page)(exp, op_data, mrinfo, hash_offset,
1580 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1581 struct ptlrpc_request **request)
1585 rc = exp_check_ops(exp);
1589 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1592 return MDP(exp->exp_obd, unlink)(exp, op_data, request);
1595 static inline int md_get_lustre_md(struct obd_export *exp,
1596 struct req_capsule *pill,
1597 struct obd_export *dt_exp,
1598 struct obd_export *md_exp,
1599 struct lustre_md *md)
1603 rc = exp_check_ops(exp);
1607 return MDP(exp->exp_obd, get_lustre_md)(exp, pill, dt_exp, md_exp, md);
1610 static inline int md_free_lustre_md(struct obd_export *exp,
1611 struct lustre_md *md)
1615 rc = exp_check_ops(exp);
1619 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1622 static inline int md_merge_attr(struct obd_export *exp,
1623 const struct lmv_stripe_md *lsm,
1624 struct cl_attr *attr,
1625 ldlm_blocking_callback cb)
1629 rc = exp_check_ops(exp);
1633 return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb);
1636 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1637 u64 obd_md_valid, const char *name,
1638 const void *value, size_t value_size,
1639 unsigned int xattr_flags, u32 suppgid,
1640 struct ptlrpc_request **req)
1644 rc = exp_check_ops(exp);
1648 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1651 return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1652 value, value_size, xattr_flags,
1656 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1657 u64 obd_md_valid, const char *name,
1658 size_t buf_size, struct ptlrpc_request **req)
1662 rc = exp_check_ops(exp);
1666 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1669 return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1673 static inline int md_set_open_replay_data(struct obd_export *exp,
1674 struct obd_client_handle *och,
1675 struct lookup_intent *it)
1679 rc = exp_check_ops(exp);
1683 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1686 static inline int md_clear_open_replay_data(struct obd_export *exp,
1687 struct obd_client_handle *och)
1691 rc = exp_check_ops(exp);
1695 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1698 static inline int md_set_lock_data(struct obd_export *exp,
1699 const struct lustre_handle *lockh,
1700 void *data, __u64 *bits)
1704 rc = exp_check_ops(exp);
1708 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1712 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1713 union ldlm_policy_data *policy, enum ldlm_mode mode,
1714 enum ldlm_cancel_flags cancel_flags, void *opaque)
1718 rc = exp_check_ops(exp);
1722 return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1723 cancel_flags, opaque);
1726 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1727 const struct lu_fid *fid,
1728 enum ldlm_type type,
1729 union ldlm_policy_data *policy,
1730 enum ldlm_mode mode,
1731 struct lustre_handle *lockh)
1735 rc = exp_check_ops(exp);
1739 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1740 policy, mode, lockh);
1743 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1748 rc = exp_check_ops(exp);
1752 return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
1755 static inline int md_intent_getattr_async(struct obd_export *exp,
1756 struct md_op_item *item)
1760 rc = exp_check_ops(exp);
1764 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1765 LPROC_MD_INTENT_GETATTR_ASYNC);
1767 return MDP(exp->exp_obd, intent_getattr_async)(exp, item);
1770 static inline int md_revalidate_lock(struct obd_export *exp,
1771 struct lookup_intent *it,
1772 struct lu_fid *fid, __u64 *bits)
1776 rc = exp_check_ops(exp);
1780 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1781 LPROC_MD_REVALIDATE_LOCK);
1783 return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1786 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1787 const struct lmv_stripe_md *lsm,
1788 const char *name, int namelen,
1793 rc = exp_check_ops(exp);
1797 return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
1801 /* Unpack an MD struct from disk to in-memory format.
1802 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1804 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1805 * If *plsm == NULL then it will be allocated.
1807 static inline int md_unpackmd(struct obd_export *exp,
1808 struct lmv_stripe_md **plsm,
1809 const union lmv_mds_md *lmm, size_t lmm_size)
1813 rc = exp_check_ops(exp);
1817 return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1820 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1821 int *rcs, struct ptlrpc_request_set *set)
1825 rc = exp_check_ops(exp);
1829 return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
1832 static inline struct lu_batch *
1833 md_batch_create(struct obd_export *exp, enum lu_batch_flags flags,
1838 rc = exp_check_ops(exp);
1842 return MDP(exp->exp_obd, batch_create)(exp, flags, max_count);
1845 static inline int md_batch_stop(struct obd_export *exp, struct lu_batch *bh)
1849 rc = exp_check_ops(exp);
1853 return MDP(exp->exp_obd, batch_stop)(exp, bh);
1856 static inline int md_batch_flush(struct obd_export *exp, struct lu_batch *bh,
1861 rc = exp_check_ops(exp);
1865 return MDP(exp->exp_obd, batch_flush)(exp, bh, wait);
1868 static inline int md_batch_add(struct obd_export *exp, struct lu_batch *bh,
1869 struct md_op_item *item)
1873 rc = exp_check_ops(exp);
1877 return MDP(exp->exp_obd, batch_add)(exp, bh, item);
1880 /* OBD Metadata Support */
1882 extern int obd_init_caches(void);
1883 extern void obd_cleanup_caches(void);
1885 typedef int (*register_lwp_cb)(void *data);
1887 struct lwp_register_item {
1888 struct obd_export **lri_exp;
1889 register_lwp_cb lri_cb_func;
1891 struct list_head lri_list;
1893 char lri_name[MTI_NAME_MAXLEN];
1897 #ifdef HAVE_SERVER_SUPPORT
1898 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1899 register_lwp_cb cb_func, void *cb_data);
1900 void lustre_deregister_lwp_item(struct obd_export **exp);
1901 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1902 void lustre_notify_lwp_list(struct obd_export *exp);
1903 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1904 #endif /* HAVE_SERVER_SUPPORT */
1905 int lustre_check_exclusion(struct super_block *sb, char *svname);
1908 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
1910 int class_add_uuid(const char *uuid, struct lnet_nid *nid);
1911 int class_del_uuid (const char *uuid);
1912 int class_add_nids_to_uuid(struct obd_uuid *uuid, lnet_nid_t *nids,
1914 int class_check_uuid(struct obd_uuid *uuid, struct lnet_nid *nid);
1917 extern char obd_jobid_name[];
1919 extern unsigned int obd_lbug_on_eviction;
1920 extern unsigned int obd_dump_on_eviction;
1922 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
1924 if (obd_lbug_on_eviction &&
1925 strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
1926 strlen(LUSTRE_MGC_NAME))) {
1927 CERROR("LBUG upon eviction\n");
1931 return obd_dump_on_eviction;
1936 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1937 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1939 /* root squash info */
1940 struct root_squash_info {
1943 struct list_head rsi_nosquash_nids;
1944 spinlock_t rsi_lock;
1947 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1949 /* linux-module.c */
1950 struct obd_ioctl_data;
1951 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
1952 int class_procfs_init(void);
1953 int class_procfs_clean(void);
1955 extern void obd_heat_add(struct obd_heat_instance *instance,
1956 unsigned int time_second, __u64 count,
1957 unsigned int weight, unsigned int period_second);
1958 extern void obd_heat_decay(struct obd_heat_instance *instance,
1959 __u64 time_second, unsigned int weight,
1960 unsigned int period_second);
1961 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
1962 unsigned int time_second, unsigned int weight,
1963 unsigned int period_second);
1964 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
1966 /* struct kobj_type */
1968 struct attribute *_get_attr_matches(const struct kobj_type *typ,
1969 const char *key, size_t keylen,
1970 int (*is_match)(const char *, const char *,
1975 #ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
1976 for (i = 0; typ->default_groups[i]; i++) {
1978 struct attribute **attrs;
1980 attrs = (struct attribute **)typ->default_groups[i]->attrs;
1981 for (k = 0; attrs[k]; k++) {
1982 if (is_match(attrs[k]->name, key, keylen))
1983 return (struct attribute *)attrs[k];
1987 for (i = 0; typ->default_attrs[i]; i++) {
1988 if (is_match(typ->default_attrs[i]->name, key, keylen))
1989 return typ->default_attrs[i];
1996 int _attr_name_exact(const char *attr_name, const char *key, size_t len)
1998 return !strcmp(attr_name, key);
2002 struct attribute *get_attr_by_name(const struct kobj_type *typ,
2005 return _get_attr_matches(typ, name, 0, _attr_name_exact);
2009 int _attr_name_starts_with(const char *attr_name, const char *name, size_t len)
2011 return !strncmp(attr_name, name, len);
2015 struct attribute *get_attr_starts_with(const struct kobj_type *typ,
2019 return _get_attr_matches(typ, name, len, _attr_name_starts_with);
2022 int obd_ioctl_msg(const char *file, const char *func, int line, int level,
2023 const char *name, unsigned int cmd, const char *msg, int rc);
2024 #define OBD_IOC_DEBUG(level, dev, cmd, msg, rc) \
2025 obd_ioctl_msg(__FILE__, __func__, __LINE__, level, dev, cmd, msg, rc)
2026 #define OBD_IOC_ERROR(dev, cmd, msg, rc) \
2027 obd_ioctl_msg(__FILE__, __func__, __LINE__, D_ERROR, dev, cmd, msg, rc)
2029 #endif /* __LINUX_OBD_CLASS_H */