4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
35 #include <linux/kobject.h>
36 #include <obd_support.h>
37 #include <lustre_import.h>
38 #include <lustre_net.h>
40 #include <lustre_lib.h>
41 #include <uapi/linux/lustre/lustre_idl.h>
42 #include <lprocfs_status.h>
44 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
45 * and resends for avoid deadlocks */
46 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
48 #define OBD_STATFS_FOR_MDT0 0x0004 /* The statfs is only for retrieving
49 * information from MDT0. */
50 #define OBD_STATFS_SUM 0x0008 /* get aggregated statfs from MDT */
52 extern rwlock_t obd_dev_lock;
54 /* OBD Operations Declarations */
55 extern struct obd_device *class_exp2obd(struct obd_export *);
56 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
57 int lustre_get_jobid(char *jobid, size_t len);
58 void lustre_jobid_clear(const char *jobid);
59 void jobid_cache_fini(void);
60 int jobid_cache_init(void);
62 struct lu_device_type;
65 struct obd_export *class_conn2export(struct lustre_handle *);
66 struct kobject *class_setup_tunables(const char *name);
67 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
68 struct lprocfs_vars *module_vars,
69 const char *nm, struct lu_device_type *ldt);
70 int class_unregister_type(const char *nm);
72 struct obd_device *class_newdev(const char *type_name, const char *name,
74 int class_register_device(struct obd_device *obd);
75 void class_unregister_device(struct obd_device *obd);
76 void class_free_dev(struct obd_device *obd);
78 struct obd_device *class_dev_by_str(const char *str);
79 int class_name2dev(const char *name);
80 struct obd_device *class_name2obd(const char *name);
81 int class_uuid2dev(struct obd_uuid *uuid);
82 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
83 void class_obd_list(void);
84 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
85 const char * typ_name,
86 struct obd_uuid *grp_uuid);
87 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
89 struct obd_device * class_num2obd(int num);
90 int get_devices_count(void);
92 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
94 static inline char *obd_export_nid2str(struct obd_export *exp)
96 return exp->exp_connection == NULL ?
97 "<unknown>" : libcfs_nid2str(exp->exp_connection->c_peer.nid);
100 static inline char *obd_import_nid2str(struct obd_import *imp)
102 return imp->imp_connection == NULL ?
103 "<unknown>" : libcfs_nid2str(imp->imp_connection->c_peer.nid);
106 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
107 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
108 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
111 int obd_zombie_impexp_init(void);
112 void obd_zombie_impexp_stop(void);
113 void obd_zombie_impexp_cull(void);
114 void obd_zombie_barrier(void);
115 void obd_exports_barrier(struct obd_device *obd);
116 int kuc_len(int payload_len);
117 struct kuc_hdr * kuc_ptr(void *p);
118 void *kuc_alloc(int payload_len, int transport, int type);
119 void kuc_free(void *p, int payload_len);
120 int obd_get_request_slot(struct client_obd *cli);
121 void obd_put_request_slot(struct client_obd *cli);
122 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
123 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
124 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
125 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
126 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
128 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
129 struct lookup_intent *it);
130 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
131 struct lookup_intent *it, __u16 tag);
135 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
136 struct llog_rec_hdr *, void *);
138 struct obd_export *obd_stale_export_get(void);
139 void obd_stale_export_put(struct obd_export *exp);
140 void obd_stale_export_adjust(struct obd_export *exp);
143 /* For interoperability */
144 struct cfg_interop_param {
149 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
150 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
151 const char *new_name);
152 void print_lustre_cfg(struct lustre_cfg *lcfg);
153 int class_process_config(struct lustre_cfg *lcfg);
154 ssize_t class_set_global(const char *param);
155 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
156 struct kobject *kobj);
157 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
158 struct lustre_cfg *lcfg, void *data);
159 int class_attach(struct lustre_cfg *lcfg);
160 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
161 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
162 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
164 int class_find_param(char *buf, char *key, char **valp);
165 struct cfg_interop_param *class_find_old_param(const char *param,
166 struct cfg_interop_param *ptr);
167 int class_get_next_param(char **params, char *copy);
168 int class_match_param(char *buf, const char *key, char **valp);
169 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
170 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
171 int class_parse_net(char *buf, u32 *net, char **endh);
172 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
173 int class_match_net(char *buf, char *key, u32 net);
175 struct obd_device *class_incref(struct obd_device *obd,
176 const char *scope, const void *source);
177 void class_decref(struct obd_device *obd,
178 const char *scope, const void *source);
179 void dump_exports(struct obd_device *obd, int locks, int debug_level);
180 int class_config_llog_handler(const struct lu_env *env,
181 struct llog_handle *handle,
182 struct llog_rec_hdr *rec, void *data);
183 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
185 #define CFG_F_START 0x01 /* Set when we start updating from a log */
186 #define CFG_F_MARKER 0x02 /* We are within a maker */
187 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
188 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
190 /* Passed as data param to class_config_parse_llog */
191 struct config_llog_instance {
192 unsigned long cfg_instance;
193 struct super_block *cfg_sb;
194 struct obd_uuid cfg_uuid;
195 llog_cb_t cfg_callback;
196 int cfg_last_idx; /* for partial llog processing */
201 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
202 char *name, struct config_llog_instance *cfg);
205 * Generate a unique configuration instance for this mount
207 * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
208 * For now, use the same value as before - the superblock pointer value.
210 * Using the client UUID would be an option, but it needs more testing.
212 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
214 return (unsigned long)sb;
217 #define CONFIG_SUB_SPTLRPC 0x01
218 #define CONFIG_SUB_RECOVER 0x02
219 #define CONFIG_SUB_PARAMS 0x04
220 #define CONFIG_SUB_NODEMAP 0x08
221 #define CONFIG_SUB_BARRIER 0x10
223 /* Sub clds should be attached to the config_llog_data when processing
224 * config log for client or server target. */
225 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
227 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
230 #define PARAMS_FILENAME "params"
231 #define BARRIER_FILENAME "barrier"
232 #define LCTL_UPCALL "lctl"
234 static inline bool logname_is_barrier(const char *logname)
238 /* logname for barrier is "fsname-barrier" */
239 ptr = strstr(logname, BARRIER_FILENAME);
240 if (ptr && (ptr - logname) >= 2 &&
241 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
247 /* list of active configuration logs */
248 struct config_llog_data {
249 struct ldlm_res_id cld_resid;
250 struct config_llog_instance cld_cfg;
251 struct list_head cld_list_chain;/* on config_llog_list */
252 atomic_t cld_refcount;
253 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
254 struct config_llog_data *cld_params; /* common parameters log */
255 struct config_llog_data *cld_recover;/* imperative recover log */
256 struct config_llog_data *cld_nodemap;/* nodemap log */
257 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
258 struct obd_export *cld_mgcexp;
259 struct mutex cld_lock;
261 unsigned int cld_stopping:1, /* we were told to stop
263 cld_lostlock:1; /* lock not requeued */
267 struct lustre_profile {
268 struct list_head lp_list;
273 bool lp_list_deleted;
276 struct lustre_profile *class_get_profile(const char * prof);
277 void class_del_profile(const char *prof);
278 void class_put_profile(struct lustre_profile *lprof);
279 void class_del_profiles(void);
282 #if LUSTRE_TRACKS_LOCK_EXP_REFS
284 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
285 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
286 extern void (*class_export_dump_hook)(struct obd_export *);
290 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
291 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
295 #define class_export_rpc_inc(exp) \
297 atomic_inc(&(exp)->exp_rpc_count); \
298 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
299 (exp), atomic_read(&(exp)->exp_rpc_count)); \
302 #define class_export_rpc_dec(exp) \
304 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
305 atomic_dec(&(exp)->exp_rpc_count); \
306 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
307 (exp), atomic_read(&(exp)->exp_rpc_count)); \
310 #define class_export_lock_get(exp, lock) \
312 atomic_inc(&(exp)->exp_locks_count); \
313 __class_export_add_lock_ref(exp, lock); \
314 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
315 (exp), atomic_read(&(exp)->exp_locks_count)); \
316 class_export_get(exp); \
319 #define class_export_lock_put(exp, lock) \
321 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
322 atomic_dec(&(exp)->exp_locks_count); \
323 __class_export_del_lock_ref(exp, lock); \
324 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
325 (exp), atomic_read(&(exp)->exp_locks_count)); \
326 class_export_put(exp); \
329 #define class_export_cb_get(exp) \
331 atomic_inc(&(exp)->exp_cb_count); \
332 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
333 (exp), atomic_read(&(exp)->exp_cb_count)); \
334 class_export_get(exp); \
337 #define class_export_cb_put(exp) \
339 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
340 atomic_dec(&(exp)->exp_cb_count); \
341 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
342 (exp), atomic_read(&(exp)->exp_cb_count)); \
343 class_export_put(exp); \
347 struct obd_export *class_export_get(struct obd_export *exp);
348 void class_export_put(struct obd_export *exp);
349 struct obd_export *class_new_export(struct obd_device *obddev,
350 struct obd_uuid *cluuid);
351 struct obd_export *class_new_export_self(struct obd_device *obd,
352 struct obd_uuid *uuid);
353 void class_unlink_export(struct obd_export *exp);
355 struct obd_import *class_import_get(struct obd_import *);
356 void class_import_put(struct obd_import *);
357 struct obd_import *class_new_import(struct obd_device *obd);
358 void class_destroy_import(struct obd_import *exp);
360 struct obd_type *class_search_type(const char *name);
361 struct obd_type *class_get_type(const char *name);
362 void class_put_type(struct obd_type *type);
363 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
364 struct obd_uuid *cluuid);
365 int class_disconnect(struct obd_export *exp);
366 void class_fail_export(struct obd_export *exp);
367 int class_connected_export(struct obd_export *exp);
368 void class_disconnect_exports(struct obd_device *obddev);
369 int class_manual_cleanup(struct obd_device *obd);
370 void class_disconnect_stale_exports(struct obd_device *,
371 int (*test_export)(struct obd_export *));
373 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
375 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
376 (obd->obd_force ? OBD_OPT_FORCE : 0) |
377 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
381 #ifdef HAVE_SERVER_SUPPORT
382 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
384 LASSERT(exp->exp_obd);
385 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
387 return exp->exp_obd->u.obt.obt_lut;
390 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
392 LASSERT(obd->u.obt.obt_lut);
393 return &obd->u.obt.obt_lut->lut_lsd;
401 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
402 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
404 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
405 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
407 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
408 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
410 static inline int obd_check_dev(struct obd_device *obd)
413 CERROR("NULL device\n");
419 /* ensure obd_setup and !obd_stopping */
420 #define OBD_CHECK_DEV_ACTIVE(obd) \
422 rc = obd_check_dev(obd); \
426 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
427 CERROR("Device %d not setup\n", \
434 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
436 /* Always add in ldlm_stats */
437 tmp->nid_ldlm_stats =
438 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
439 LPROCFS_STATS_FLAG_NOPERCPU);
440 if (tmp->nid_ldlm_stats == NULL)
443 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
445 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
446 tmp->nid_ldlm_stats);
449 static inline int exp_check_ops(struct obd_export *exp)
454 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
460 static inline int class_devno_max(void)
462 return MAX_OBD_DEVICES;
465 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
466 __u32 keylen, void *key,
467 __u32 *vallen, void *val)
472 rc = exp_check_ops(exp);
476 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
477 CERROR("%s: no %s operation\n",
478 (exp)->exp_obd->obd_name, __func__);
482 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
486 static inline int obd_set_info_async(const struct lu_env *env,
487 struct obd_export *exp,
488 __u32 keylen, void *key,
489 __u32 vallen, void *val,
490 struct ptlrpc_request_set *set)
495 rc = exp_check_ops(exp);
499 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
500 CERROR("%s: no %s operation\n",
501 (exp)->exp_obd->obd_name, __func__);
505 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
511 * obd-lu integration.
513 * Functionality is being moved into new lu_device-based layering, but some
514 * pieces of configuration process are still based on obd devices.
516 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
517 * subsume ->o_setup() methods of obd devices they replace. The same for
518 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
519 * result, obd_setup() and obd_process_config() branch and call one XOR
522 * Yet neither lu_device_type_operations::ldto_device_fini() nor
523 * lu_device_type_operations::ldto_device_free() fully implement the
524 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
525 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
527 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
530 struct lu_device_type *ldt = obd->obd_type->typ_lu;
536 struct lu_context session_ctx;
538 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
539 session_ctx.lc_thread = NULL;
540 lu_context_enter(&session_ctx);
542 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
544 env.le_ses = &session_ctx;
545 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
554 lu_context_exit(&session_ctx);
555 lu_context_fini(&session_ctx);
558 if (!obd->obd_type->typ_dt_ops->o_setup) {
559 CERROR("%s: no %s operation\n", obd->obd_name,
563 rc = OBP(obd, setup)(obd, cfg);
568 static inline int obd_precleanup(struct obd_device *obd)
571 struct lu_device_type *ldt = obd->obd_type->typ_lu;
572 struct lu_device *d = obd->obd_lu_dev;
576 if (ldt != NULL && d != NULL) {
577 struct lu_env *env = lu_env_find();
582 rc = lu_env_init(env, ldt->ldt_ctx_tags);
586 ldt->ldt_ops->ldto_device_fini(env, d);
593 if (!obd->obd_type->typ_dt_ops->o_precleanup)
596 rc = OBP(obd, precleanup)(obd);
600 static inline int obd_cleanup(struct obd_device *obd)
603 struct lu_device_type *ldt = obd->obd_type->typ_lu;
604 struct lu_device *d = obd->obd_lu_dev;
607 if (ldt != NULL && d != NULL) {
610 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
612 ldt->ldt_ops->ldto_device_free(&env, d);
614 obd->obd_lu_dev = NULL;
617 if (!obd->obd_type->typ_dt_ops->o_cleanup)
620 rc = OBP(obd, cleanup)(obd);
624 static inline void obd_cleanup_client_import(struct obd_device *obd)
628 /* If we set up but never connected, the
629 client import will not have been cleaned. */
630 down_write(&obd->u.cli.cl_sem);
631 if (obd->u.cli.cl_import) {
632 struct obd_import *imp;
633 imp = obd->u.cli.cl_import;
634 CDEBUG(D_CONFIG, "%s: client import never connected\n",
636 ptlrpc_invalidate_import(imp);
637 client_destroy_import(imp);
638 obd->u.cli.cl_import = NULL;
640 up_write(&obd->u.cli.cl_sem);
645 static inline int obd_process_config(struct obd_device *obd, int datalen,
649 struct lu_device_type *ldt = obd->obd_type->typ_lu;
650 struct lu_device *d = obd->obd_lu_dev;
654 obd->obd_process_conf = 1;
655 if (ldt != NULL && d != NULL) {
658 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
660 rc = d->ld_ops->ldo_process_config(&env, d, data);
664 if (!obd->obd_type->typ_dt_ops->o_process_config) {
665 CERROR("%s: no %s operation\n",
666 obd->obd_name, __func__);
669 rc = OBP(obd, process_config)(obd, datalen, data);
672 obd->obd_process_conf = 0;
677 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
683 rc = exp_check_ops(exp);
687 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
688 CERROR("%s: no %s operation\n",
689 (exp)->exp_obd->obd_name, __func__);
693 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
697 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
703 rc = exp_check_ops(exp);
707 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
708 CERROR("%s: no %s operation\n",
709 (exp)->exp_obd->obd_name, __func__);
713 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
717 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
723 rc = exp_check_ops(exp);
727 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
728 CERROR("%s: no %s operation\n",
729 (exp)->exp_obd->obd_name, __func__);
733 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
738 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
744 rc = exp_check_ops(exp);
748 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
749 CERROR("%s: no %s operation\n",
750 (exp)->exp_obd->obd_name, __func__);
754 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
759 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
762 struct obd_device *obd = imp->imp_obd;
766 OBD_CHECK_DEV_ACTIVE(obd);
767 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
768 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
772 rc = OBP(obd, add_conn)(imp, uuid, priority);
776 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
778 struct obd_device *obd = imp->imp_obd;
782 OBD_CHECK_DEV_ACTIVE(obd);
783 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
784 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
788 rc = OBP(obd, del_conn)(imp, uuid);
792 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
794 struct obd_uuid *uuid;
797 if (!exp->exp_obd->obd_type ||
798 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
801 uuid = OBP(exp->exp_obd, get_uuid)(exp);
805 /** Create a new /a exp on device /a obd for the uuid /a cluuid
806 * @param exp New export handle
807 * @param d Connect data, supported flags are set, flags also understood
808 * by obd are returned.
810 static inline int obd_connect(const struct lu_env *env,
811 struct obd_export **exp,struct obd_device *obd,
812 struct obd_uuid *cluuid,
813 struct obd_connect_data *data,
817 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
821 OBD_CHECK_DEV_ACTIVE(obd);
822 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
823 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
827 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
828 /* check that only subset is granted */
829 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
830 data->ocd_connect_flags));
834 static inline int obd_reconnect(const struct lu_env *env,
835 struct obd_export *exp,
836 struct obd_device *obd,
837 struct obd_uuid *cluuid,
838 struct obd_connect_data *d,
842 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
847 OBD_CHECK_DEV_ACTIVE(obd);
848 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
851 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
852 /* check that only subset is granted */
853 LASSERT(ergo(d != NULL,
854 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
858 static inline int obd_disconnect(struct obd_export *exp)
862 rc = exp_check_ops(exp);
866 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
867 CERROR("%s: no %s operation\n",
868 (exp)->exp_obd->obd_name, __func__);
872 rc = OBP(exp->exp_obd, disconnect)(exp);
876 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
877 enum lu_cli_type type)
882 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
885 rc = OBP(obd, fid_init)(obd, exp, type);
889 static inline int obd_fid_fini(struct obd_device *obd)
893 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
896 rc = OBP(obd, fid_fini)(obd);
900 static inline int obd_fid_alloc(const struct lu_env *env,
901 struct obd_export *exp,
903 struct md_op_data *op_data)
907 rc = exp_check_ops(exp);
911 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
912 CERROR("%s: no %s operation\n",
913 (exp)->exp_obd->obd_name, __func__);
917 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
921 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
926 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
927 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
931 rc = OBP(obd, pool_new)(obd, poolname);
935 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
939 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
940 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
944 rc = OBP(obd, pool_del)(obd, poolname);
948 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
954 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
955 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
959 rc = OBP(obd, pool_add)(obd, poolname, ostname);
963 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
969 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
970 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
974 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
978 static inline int obd_init_export(struct obd_export *exp)
983 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
984 OBP((exp)->exp_obd, init_export))
985 rc = OBP(exp->exp_obd, init_export)(exp);
989 static inline int obd_destroy_export(struct obd_export *exp)
992 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
993 OBP(exp->exp_obd, destroy_export))
994 OBP(exp->exp_obd, destroy_export)(exp);
998 /* @max_age is the oldest time in seconds that we accept using a cached data.
999 * If the cache is older than @max_age we will get a new value from the
1000 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1002 static inline int obd_statfs_async(struct obd_export *exp,
1003 struct obd_info *oinfo,
1005 struct ptlrpc_request_set *rqset)
1007 struct obd_device *obd;
1012 if (exp == NULL || exp->exp_obd == NULL)
1016 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1018 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1022 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1023 obd->obd_name, obd->obd_osfs_age, max_age);
1024 if (obd->obd_osfs_age < max_age) {
1025 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1028 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1029 obd->obd_name, &obd->obd_osfs,
1030 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1031 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1032 spin_lock(&obd->obd_osfs_lock);
1033 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1034 spin_unlock(&obd->obd_osfs_lock);
1035 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1036 if (oinfo->oi_cb_up)
1037 oinfo->oi_cb_up(oinfo, 0);
1042 /* @max_age is the oldest time in seconds that we accept using a cached data.
1043 * If the cache is older than @max_age we will get a new value from the
1044 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1046 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1047 struct obd_statfs *osfs, time64_t max_age,
1050 struct obd_device *obd = exp->exp_obd;
1054 if (unlikely(obd == NULL))
1057 OBD_CHECK_DEV_ACTIVE(obd);
1059 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1060 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1061 RETURN(-EOPNOTSUPP);
1064 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1065 obd->obd_name, obd->obd_osfs_age, max_age);
1066 /* ignore cache if aggregated isn't expected */
1067 if (obd->obd_osfs_age < max_age ||
1068 ((obd->obd_osfs.os_state & OS_STATE_SUM) &&
1069 !(flags & OBD_STATFS_SUM))) {
1070 /* the RPC will block anyway, so avoid sending many at once */
1071 rc = mutex_lock_interruptible(&obd->obd_dev_mutex);
1074 if (obd->obd_osfs_age < max_age ||
1075 ((obd->obd_osfs.os_state & OS_STATE_SUM) &&
1076 !(flags & OBD_STATFS_SUM))) {
1077 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1079 mutex_unlock(&obd->obd_dev_mutex);
1080 GOTO(cached, rc = 0);
1084 "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1085 obd->obd_name, &obd->obd_osfs,
1086 osfs->os_bavail, osfs->os_blocks,
1087 osfs->os_ffree, osfs->os_files);
1089 spin_lock(&obd->obd_osfs_lock);
1090 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1091 obd->obd_osfs_age = ktime_get_seconds();
1092 spin_unlock(&obd->obd_osfs_lock);
1094 mutex_unlock(&obd->obd_dev_mutex);
1098 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1099 obd->obd_name, &obd->obd_osfs,
1100 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1101 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1102 spin_lock(&obd->obd_osfs_lock);
1103 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1104 spin_unlock(&obd->obd_osfs_lock);
1109 static inline int obd_preprw(const struct lu_env *env, int cmd,
1110 struct obd_export *exp, struct obdo *oa,
1111 int objcount, struct obd_ioobj *obj,
1112 struct niobuf_remote *remote, int *pages,
1113 struct niobuf_local *local)
1119 rc = exp_check_ops(exp);
1123 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1124 CERROR("%s: no %s operation\n",
1125 (exp)->exp_obd->obd_name, __func__);
1129 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1135 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1136 struct obd_export *exp, struct obdo *oa,
1137 int objcount, struct obd_ioobj *obj,
1138 struct niobuf_remote *rnb, int pages,
1139 struct niobuf_local *local, const int orig_rc)
1144 rc = exp_check_ops(exp);
1148 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1149 CERROR("%s: no %s operation\n",
1150 (exp)->exp_obd->obd_name, __func__);
1154 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1155 rnb, pages, local, orig_rc);
1160 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1161 int len, void *karg, void __user *uarg)
1166 rc = exp_check_ops(exp);
1170 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1171 CERROR("%s: no %s operation\n",
1172 (exp)->exp_obd->obd_name, __func__);
1176 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1180 static inline void obd_import_event(struct obd_device *obd,
1181 struct obd_import *imp,
1182 enum obd_import_event event)
1186 CERROR("NULL device\n");
1191 if (obd->obd_set_up && OBP(obd, import_event))
1192 OBP(obd, import_event)(obd, imp, event);
1197 static inline int obd_notify(struct obd_device *obd,
1198 struct obd_device *watched,
1199 enum obd_notify_event ev)
1204 rc = obd_check_dev(obd);
1208 if (!obd->obd_set_up) {
1209 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1213 if (!OBP(obd, notify)) {
1214 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1218 rc = OBP(obd, notify)(obd, watched, ev);
1223 static inline int obd_notify_observer(struct obd_device *observer,
1224 struct obd_device *observed,
1225 enum obd_notify_event ev)
1229 struct obd_notify_upcall *onu;
1231 if (observer->obd_observer)
1232 rc = obd_notify(observer->obd_observer, observed, ev);
1235 * Also, call non-obd listener, if any
1237 onu = &observer->obd_upcall;
1238 if (onu->onu_upcall != NULL)
1239 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1241 return rc ? rc : rc2;
1244 static inline int obd_quotactl(struct obd_export *exp,
1245 struct obd_quotactl *oqctl)
1250 rc = exp_check_ops(exp);
1254 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1255 CERROR("%s: no %s operation\n",
1256 (exp)->exp_obd->obd_name, __func__);
1260 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1264 static inline int obd_health_check(const struct lu_env *env,
1265 struct obd_device *obd)
1267 /* returns: 0 on healthy
1268 * >0 on unhealthy + reason code/flag
1269 * however the only suppored reason == 1 right now
1270 * We'll need to define some better reasons
1271 * or flags in the future.
1278 /* NULL method is normal here */
1279 if (obd == NULL || !obd->obd_type) {
1280 CERROR("cleaned up obd\n");
1281 RETURN(-EOPNOTSUPP);
1283 if (!obd->obd_set_up || obd->obd_stopping)
1285 if (!OBP(obd, health_check))
1288 rc = OBP(obd, health_check)(env, obd);
1292 static inline int obd_register_observer(struct obd_device *obd,
1293 struct obd_device *observer)
1298 rc = obd_check_dev(obd);
1302 down_write(&obd->obd_observer_link_sem);
1303 if (obd->obd_observer && observer) {
1304 up_write(&obd->obd_observer_link_sem);
1307 obd->obd_observer = observer;
1308 up_write(&obd->obd_observer_link_sem);
1312 /* metadata helpers */
1318 LPROC_MD_INTENT_LOCK,
1327 LPROC_MD_INTENT_GETATTR_ASYNC,
1328 LPROC_MD_REVALIDATE_LOCK,
1332 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1337 rc = exp_check_ops(exp);
1341 return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1344 static inline int md_getattr(struct obd_export *exp,
1345 struct md_op_data *op_data,
1346 struct ptlrpc_request **request)
1350 rc = exp_check_ops(exp);
1354 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1357 return MDP(exp->exp_obd, getattr)(exp, op_data, request);
1360 static inline int md_null_inode(struct obd_export *exp,
1361 const struct lu_fid *fid)
1365 rc = exp_check_ops(exp);
1369 return MDP(exp->exp_obd, null_inode)(exp, fid);
1372 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1373 struct md_open_data *mod,
1374 struct ptlrpc_request **request)
1378 rc = exp_check_ops(exp);
1382 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1385 return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1388 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1389 const void *data, size_t datalen, umode_t mode,
1390 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1391 __u64 rdev, struct ptlrpc_request **request)
1395 rc = exp_check_ops(exp);
1399 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1402 return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1403 uid, gid, cap_effective, rdev,
1407 static inline int md_enqueue(struct obd_export *exp,
1408 struct ldlm_enqueue_info *einfo,
1409 const union ldlm_policy_data *policy,
1410 struct md_op_data *op_data,
1411 struct lustre_handle *lockh,
1412 __u64 extra_lock_flags)
1416 rc = exp_check_ops(exp);
1420 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1423 return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1427 static inline int md_getattr_name(struct obd_export *exp,
1428 struct md_op_data *op_data,
1429 struct ptlrpc_request **request)
1433 rc = exp_check_ops(exp);
1437 return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1440 static inline int md_intent_lock(struct obd_export *exp,
1441 struct md_op_data *op_data,
1442 struct lookup_intent *it,
1443 struct ptlrpc_request **reqp,
1444 ldlm_blocking_callback cb_blocking,
1445 __u64 extra_lock_flags)
1449 rc = exp_check_ops(exp);
1453 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1454 LPROC_MD_INTENT_LOCK);
1456 return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1457 cb_blocking, extra_lock_flags);
1460 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1461 struct ptlrpc_request **request)
1465 rc = exp_check_ops(exp);
1469 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1472 return MDP(exp->exp_obd, link)(exp, op_data, request);
1475 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1476 const char *old_name, size_t oldlen,
1477 const char *new_name, size_t newlen,
1478 struct ptlrpc_request **request)
1482 rc = exp_check_ops(exp);
1486 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1489 return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
1490 new_name, newlen, request);
1493 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1494 void *ea, size_t ealen,
1495 struct ptlrpc_request **request)
1499 rc = exp_check_ops(exp);
1503 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1506 return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1509 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1510 struct ptlrpc_request **request)
1514 rc = exp_check_ops(exp);
1518 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1521 return MDP(exp->exp_obd, fsync)(exp, fid, request);
1524 /* FLR: resync mirrored files. */
1525 static inline int md_file_resync(struct obd_export *exp,
1526 struct md_op_data *data)
1530 rc = exp_check_ops(exp);
1534 return MDP(exp->exp_obd, file_resync)(exp, data);
1537 static inline int md_read_page(struct obd_export *exp,
1538 struct md_op_data *op_data,
1539 struct md_callback *cb_op,
1541 struct page **ppage)
1545 rc = exp_check_ops(exp);
1549 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1550 LPROC_MD_READ_PAGE);
1552 return MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1556 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1557 struct ptlrpc_request **request)
1561 rc = exp_check_ops(exp);
1565 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1568 return MDP(exp->exp_obd, unlink)(exp, op_data, request);
1571 static inline int md_get_lustre_md(struct obd_export *exp,
1572 struct ptlrpc_request *req,
1573 struct obd_export *dt_exp,
1574 struct obd_export *md_exp,
1575 struct lustre_md *md)
1579 rc = exp_check_ops(exp);
1583 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1586 static inline int md_free_lustre_md(struct obd_export *exp,
1587 struct lustre_md *md)
1591 rc = exp_check_ops(exp);
1595 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1598 static inline int md_merge_attr(struct obd_export *exp,
1599 const struct lu_fid *fid,
1600 const struct lmv_stripe_md *lsm,
1601 struct cl_attr *attr,
1602 ldlm_blocking_callback cb)
1606 rc = exp_check_ops(exp);
1610 return MDP(exp->exp_obd, merge_attr)(exp, fid, lsm, attr, cb);
1613 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1614 u64 obd_md_valid, const char *name,
1615 const void *value, size_t value_size,
1616 unsigned int xattr_flags, u32 suppgid,
1617 struct ptlrpc_request **req)
1621 rc = exp_check_ops(exp);
1625 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1628 return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1629 value, value_size, xattr_flags,
1633 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1634 u64 obd_md_valid, const char *name,
1635 size_t buf_size, struct ptlrpc_request **req)
1639 rc = exp_check_ops(exp);
1643 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1646 return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1650 static inline int md_set_open_replay_data(struct obd_export *exp,
1651 struct obd_client_handle *och,
1652 struct lookup_intent *it)
1656 rc = exp_check_ops(exp);
1660 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1663 static inline int md_clear_open_replay_data(struct obd_export *exp,
1664 struct obd_client_handle *och)
1668 rc = exp_check_ops(exp);
1672 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1675 static inline int md_set_lock_data(struct obd_export *exp,
1676 const struct lustre_handle *lockh,
1677 void *data, __u64 *bits)
1681 rc = exp_check_ops(exp);
1685 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1689 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1690 union ldlm_policy_data *policy, enum ldlm_mode mode,
1691 enum ldlm_cancel_flags cancel_flags, void *opaque)
1695 rc = exp_check_ops(exp);
1699 return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1700 cancel_flags, opaque);
1703 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1704 const struct lu_fid *fid,
1705 enum ldlm_type type,
1706 union ldlm_policy_data *policy,
1707 enum ldlm_mode mode,
1708 struct lustre_handle *lockh)
1712 rc = exp_check_ops(exp);
1716 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1717 policy, mode, lockh);
1720 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1725 rc = exp_check_ops(exp);
1729 return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
1732 static inline int md_intent_getattr_async(struct obd_export *exp,
1733 struct md_enqueue_info *minfo)
1737 rc = exp_check_ops(exp);
1741 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1742 LPROC_MD_INTENT_GETATTR_ASYNC);
1744 return MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1747 static inline int md_revalidate_lock(struct obd_export *exp,
1748 struct lookup_intent *it,
1749 struct lu_fid *fid, __u64 *bits)
1753 rc = exp_check_ops(exp);
1757 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1758 LPROC_MD_REVALIDATE_LOCK);
1760 return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1763 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1764 const struct lmv_stripe_md *lsm,
1765 const char *name, int namelen,
1770 rc = exp_check_ops(exp);
1774 return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
1778 /* Unpack an MD struct from disk to in-memory format.
1779 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1781 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1782 * If *plsm == NULL then it will be allocated.
1784 static inline int md_unpackmd(struct obd_export *exp,
1785 struct lmv_stripe_md **plsm,
1786 const union lmv_mds_md *lmm, size_t lmm_size)
1790 rc = exp_check_ops(exp);
1794 return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1797 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1798 int *rcs, struct ptlrpc_request_set *set)
1802 rc = exp_check_ops(exp);
1806 return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
1809 /* OBD Metadata Support */
1811 extern int obd_init_caches(void);
1812 extern void obd_cleanup_caches(void);
1814 typedef int (*register_lwp_cb)(void *data);
1816 struct lwp_register_item {
1817 struct obd_export **lri_exp;
1818 register_lwp_cb lri_cb_func;
1820 struct list_head lri_list;
1822 char lri_name[MTI_NAME_MAXLEN];
1825 /* I'm as embarrassed about this as you are.
1827 * <shaver> // XXX do not look into _superhack with remaining eye
1828 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1829 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1832 #ifdef HAVE_SERVER_SUPPORT
1833 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1834 register_lwp_cb cb_func, void *cb_data);
1835 void lustre_deregister_lwp_item(struct obd_export **exp);
1836 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1837 void lustre_notify_lwp_list(struct obd_export *exp);
1838 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1839 #endif /* HAVE_SERVER_SUPPORT */
1840 int lustre_register_fs(void);
1841 int lustre_unregister_fs(void);
1842 int lustre_check_exclusion(struct super_block *sb, char *svname);
1844 typedef __u8 class_uuid_t[16];
1845 static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
1847 snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-"
1848 "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1849 uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9],
1850 uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]);
1854 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1855 int class_add_uuid(const char *uuid, __u64 nid);
1856 int class_del_uuid (const char *uuid);
1857 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1860 extern char obd_jobid_name[];
1863 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1867 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1868 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1870 /* root squash info */
1871 struct rw_semaphore;
1872 struct root_squash_info {
1875 struct list_head rsi_nosquash_nids;
1876 struct rw_semaphore rsi_sem;
1879 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1881 /* linux-module.c */
1882 extern struct miscdevice obd_psdev;
1883 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1884 int class_procfs_init(void);
1885 int class_procfs_clean(void);
1886 #endif /* __LINUX_OBD_CLASS_H */