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) {
579 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
581 ldt->ldt_ops->ldto_device_fini(&env, d);
586 if (!obd->obd_type->typ_dt_ops->o_precleanup)
589 rc = OBP(obd, precleanup)(obd);
593 static inline int obd_cleanup(struct obd_device *obd)
596 struct lu_device_type *ldt = obd->obd_type->typ_lu;
597 struct lu_device *d = obd->obd_lu_dev;
600 if (ldt != NULL && d != NULL) {
603 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
605 ldt->ldt_ops->ldto_device_free(&env, d);
607 obd->obd_lu_dev = NULL;
610 if (!obd->obd_type->typ_dt_ops->o_cleanup)
613 rc = OBP(obd, cleanup)(obd);
617 static inline void obd_cleanup_client_import(struct obd_device *obd)
621 /* If we set up but never connected, the
622 client import will not have been cleaned. */
623 down_write(&obd->u.cli.cl_sem);
624 if (obd->u.cli.cl_import) {
625 struct obd_import *imp;
626 imp = obd->u.cli.cl_import;
627 CDEBUG(D_CONFIG, "%s: client import never connected\n",
629 ptlrpc_invalidate_import(imp);
630 client_destroy_import(imp);
631 obd->u.cli.cl_import = NULL;
633 up_write(&obd->u.cli.cl_sem);
638 static inline int obd_process_config(struct obd_device *obd, int datalen,
642 struct lu_device_type *ldt = obd->obd_type->typ_lu;
643 struct lu_device *d = obd->obd_lu_dev;
647 obd->obd_process_conf = 1;
648 if (ldt != NULL && d != NULL) {
651 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
653 rc = d->ld_ops->ldo_process_config(&env, d, data);
657 if (!obd->obd_type->typ_dt_ops->o_process_config) {
658 CERROR("%s: no %s operation\n",
659 obd->obd_name, __func__);
662 rc = OBP(obd, process_config)(obd, datalen, data);
665 obd->obd_process_conf = 0;
670 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
676 rc = exp_check_ops(exp);
680 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
681 CERROR("%s: no %s operation\n",
682 (exp)->exp_obd->obd_name, __func__);
686 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
690 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
696 rc = exp_check_ops(exp);
700 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
701 CERROR("%s: no %s operation\n",
702 (exp)->exp_obd->obd_name, __func__);
706 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
710 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
716 rc = exp_check_ops(exp);
720 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
721 CERROR("%s: no %s operation\n",
722 (exp)->exp_obd->obd_name, __func__);
726 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
731 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
737 rc = exp_check_ops(exp);
741 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
742 CERROR("%s: no %s operation\n",
743 (exp)->exp_obd->obd_name, __func__);
747 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
752 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
755 struct obd_device *obd = imp->imp_obd;
759 OBD_CHECK_DEV_ACTIVE(obd);
760 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
761 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
765 rc = OBP(obd, add_conn)(imp, uuid, priority);
769 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
771 struct obd_device *obd = imp->imp_obd;
775 OBD_CHECK_DEV_ACTIVE(obd);
776 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
777 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
781 rc = OBP(obd, del_conn)(imp, uuid);
785 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
787 struct obd_uuid *uuid;
790 if (!exp->exp_obd->obd_type ||
791 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
794 uuid = OBP(exp->exp_obd, get_uuid)(exp);
798 /** Create a new /a exp on device /a obd for the uuid /a cluuid
799 * @param exp New export handle
800 * @param d Connect data, supported flags are set, flags also understood
801 * by obd are returned.
803 static inline int obd_connect(const struct lu_env *env,
804 struct obd_export **exp,struct obd_device *obd,
805 struct obd_uuid *cluuid,
806 struct obd_connect_data *data,
810 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
814 OBD_CHECK_DEV_ACTIVE(obd);
815 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
816 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
820 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
821 /* check that only subset is granted */
822 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
823 data->ocd_connect_flags));
827 static inline int obd_reconnect(const struct lu_env *env,
828 struct obd_export *exp,
829 struct obd_device *obd,
830 struct obd_uuid *cluuid,
831 struct obd_connect_data *d,
835 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
840 OBD_CHECK_DEV_ACTIVE(obd);
841 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
844 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
845 /* check that only subset is granted */
846 LASSERT(ergo(d != NULL,
847 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
851 static inline int obd_disconnect(struct obd_export *exp)
855 rc = exp_check_ops(exp);
859 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
860 CERROR("%s: no %s operation\n",
861 (exp)->exp_obd->obd_name, __func__);
865 rc = OBP(exp->exp_obd, disconnect)(exp);
869 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
870 enum lu_cli_type type)
875 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
878 rc = OBP(obd, fid_init)(obd, exp, type);
882 static inline int obd_fid_fini(struct obd_device *obd)
886 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
889 rc = OBP(obd, fid_fini)(obd);
893 static inline int obd_fid_alloc(const struct lu_env *env,
894 struct obd_export *exp,
896 struct md_op_data *op_data)
900 rc = exp_check_ops(exp);
904 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
905 CERROR("%s: no %s operation\n",
906 (exp)->exp_obd->obd_name, __func__);
910 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
914 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
919 if (!exp->exp_obd->obd_type ||
920 !exp->exp_obd->obd_type->typ_dt_ops->o_ping)
923 rc = OBP(exp->exp_obd, ping)(env, exp);
927 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
932 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
933 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
937 rc = OBP(obd, pool_new)(obd, poolname);
941 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
945 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
946 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
950 rc = OBP(obd, pool_del)(obd, poolname);
954 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
960 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
961 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
965 rc = OBP(obd, pool_add)(obd, poolname, ostname);
969 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
975 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
976 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
980 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
984 static inline int obd_init_export(struct obd_export *exp)
989 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
990 OBP((exp)->exp_obd, init_export))
991 rc = OBP(exp->exp_obd, init_export)(exp);
995 static inline int obd_destroy_export(struct obd_export *exp)
998 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
999 OBP(exp->exp_obd, destroy_export))
1000 OBP(exp->exp_obd, destroy_export)(exp);
1004 /* @max_age is the oldest time in seconds that we accept using a cached data.
1005 * If the cache is older than @max_age we will get a new value from the
1006 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1008 static inline int obd_statfs_async(struct obd_export *exp,
1009 struct obd_info *oinfo,
1011 struct ptlrpc_request_set *rqset)
1013 struct obd_device *obd;
1018 if (exp == NULL || exp->exp_obd == NULL)
1022 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1024 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1028 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1029 obd->obd_name, obd->obd_osfs_age, max_age);
1030 if (obd->obd_osfs_age < max_age) {
1031 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1034 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1035 obd->obd_name, &obd->obd_osfs,
1036 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1037 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1038 spin_lock(&obd->obd_osfs_lock);
1039 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1040 spin_unlock(&obd->obd_osfs_lock);
1041 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1042 if (oinfo->oi_cb_up)
1043 oinfo->oi_cb_up(oinfo, 0);
1048 /* @max_age is the oldest time in seconds that we accept using a cached data.
1049 * If the cache is older than @max_age we will get a new value from the
1050 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1052 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1053 struct obd_statfs *osfs, time64_t max_age,
1056 struct obd_device *obd = exp->exp_obd;
1060 if (unlikely(obd == NULL))
1063 OBD_CHECK_DEV_ACTIVE(obd);
1065 if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1066 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1067 RETURN(-EOPNOTSUPP);
1070 CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1071 obd->obd_name, obd->obd_osfs_age, max_age);
1072 /* ignore cache if aggregated isn't expected */
1073 if (obd->obd_osfs_age < max_age ||
1074 ((obd->obd_osfs.os_state & OS_STATE_SUM) &&
1075 !(flags & OBD_STATFS_SUM))) {
1076 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1078 spin_lock(&obd->obd_osfs_lock);
1079 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1080 obd->obd_osfs_age = ktime_get_seconds();
1081 spin_unlock(&obd->obd_osfs_lock);
1085 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1086 obd->obd_name, &obd->obd_osfs,
1087 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1088 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1089 spin_lock(&obd->obd_osfs_lock);
1090 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1091 spin_unlock(&obd->obd_osfs_lock);
1096 static inline int obd_preprw(const struct lu_env *env, int cmd,
1097 struct obd_export *exp, struct obdo *oa,
1098 int objcount, struct obd_ioobj *obj,
1099 struct niobuf_remote *remote, int *pages,
1100 struct niobuf_local *local)
1106 rc = exp_check_ops(exp);
1110 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1111 CERROR("%s: no %s operation\n",
1112 (exp)->exp_obd->obd_name, __func__);
1116 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1122 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1123 struct obd_export *exp, struct obdo *oa,
1124 int objcount, struct obd_ioobj *obj,
1125 struct niobuf_remote *rnb, int pages,
1126 struct niobuf_local *local, const int orig_rc)
1131 rc = exp_check_ops(exp);
1135 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1136 CERROR("%s: no %s operation\n",
1137 (exp)->exp_obd->obd_name, __func__);
1141 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1142 rnb, pages, local, orig_rc);
1147 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1148 int len, void *karg, void __user *uarg)
1153 rc = exp_check_ops(exp);
1157 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1158 CERROR("%s: no %s operation\n",
1159 (exp)->exp_obd->obd_name, __func__);
1163 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1167 static inline void obd_import_event(struct obd_device *obd,
1168 struct obd_import *imp,
1169 enum obd_import_event event)
1173 CERROR("NULL device\n");
1178 if (obd->obd_set_up && OBP(obd, import_event))
1179 OBP(obd, import_event)(obd, imp, event);
1184 static inline int obd_notify(struct obd_device *obd,
1185 struct obd_device *watched,
1186 enum obd_notify_event ev)
1191 rc = obd_check_dev(obd);
1195 if (!obd->obd_set_up) {
1196 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1200 if (!OBP(obd, notify)) {
1201 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1205 rc = OBP(obd, notify)(obd, watched, ev);
1210 static inline int obd_notify_observer(struct obd_device *observer,
1211 struct obd_device *observed,
1212 enum obd_notify_event ev)
1216 struct obd_notify_upcall *onu;
1218 if (observer->obd_observer)
1219 rc = obd_notify(observer->obd_observer, observed, ev);
1222 * Also, call non-obd listener, if any
1224 onu = &observer->obd_upcall;
1225 if (onu->onu_upcall != NULL)
1226 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1228 return rc ? rc : rc2;
1231 static inline int obd_quotactl(struct obd_export *exp,
1232 struct obd_quotactl *oqctl)
1237 rc = exp_check_ops(exp);
1241 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1242 CERROR("%s: no %s operation\n",
1243 (exp)->exp_obd->obd_name, __func__);
1247 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1251 static inline int obd_health_check(const struct lu_env *env,
1252 struct obd_device *obd)
1254 /* returns: 0 on healthy
1255 * >0 on unhealthy + reason code/flag
1256 * however the only suppored reason == 1 right now
1257 * We'll need to define some better reasons
1258 * or flags in the future.
1265 /* NULL method is normal here */
1266 if (obd == NULL || !obd->obd_type) {
1267 CERROR("cleaned up obd\n");
1268 RETURN(-EOPNOTSUPP);
1270 if (!obd->obd_set_up || obd->obd_stopping)
1272 if (!OBP(obd, health_check))
1275 rc = OBP(obd, health_check)(env, obd);
1279 static inline int obd_register_observer(struct obd_device *obd,
1280 struct obd_device *observer)
1285 rc = obd_check_dev(obd);
1289 down_write(&obd->obd_observer_link_sem);
1290 if (obd->obd_observer && observer) {
1291 up_write(&obd->obd_observer_link_sem);
1294 obd->obd_observer = observer;
1295 up_write(&obd->obd_observer_link_sem);
1299 /* metadata helpers */
1305 LPROC_MD_INTENT_LOCK,
1314 LPROC_MD_INTENT_GETATTR_ASYNC,
1315 LPROC_MD_REVALIDATE_LOCK,
1319 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1324 rc = exp_check_ops(exp);
1328 return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1331 static inline int md_getattr(struct obd_export *exp,
1332 struct md_op_data *op_data,
1333 struct ptlrpc_request **request)
1337 rc = exp_check_ops(exp);
1341 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1344 return MDP(exp->exp_obd, getattr)(exp, op_data, request);
1347 static inline int md_null_inode(struct obd_export *exp,
1348 const struct lu_fid *fid)
1352 rc = exp_check_ops(exp);
1356 return MDP(exp->exp_obd, null_inode)(exp, fid);
1359 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1360 struct md_open_data *mod,
1361 struct ptlrpc_request **request)
1365 rc = exp_check_ops(exp);
1369 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1372 return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1375 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1376 const void *data, size_t datalen, umode_t mode,
1377 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1378 __u64 rdev, struct ptlrpc_request **request)
1382 rc = exp_check_ops(exp);
1386 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1389 return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1390 uid, gid, cap_effective, rdev,
1394 static inline int md_enqueue(struct obd_export *exp,
1395 struct ldlm_enqueue_info *einfo,
1396 const union ldlm_policy_data *policy,
1397 struct md_op_data *op_data,
1398 struct lustre_handle *lockh,
1399 __u64 extra_lock_flags)
1403 rc = exp_check_ops(exp);
1407 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1410 return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1414 static inline int md_getattr_name(struct obd_export *exp,
1415 struct md_op_data *op_data,
1416 struct ptlrpc_request **request)
1420 rc = exp_check_ops(exp);
1424 return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1427 static inline int md_intent_lock(struct obd_export *exp,
1428 struct md_op_data *op_data,
1429 struct lookup_intent *it,
1430 struct ptlrpc_request **reqp,
1431 ldlm_blocking_callback cb_blocking,
1432 __u64 extra_lock_flags)
1436 rc = exp_check_ops(exp);
1440 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1441 LPROC_MD_INTENT_LOCK);
1443 return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1444 cb_blocking, extra_lock_flags);
1447 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1448 struct ptlrpc_request **request)
1452 rc = exp_check_ops(exp);
1456 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1459 return MDP(exp->exp_obd, link)(exp, op_data, request);
1462 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1463 const char *old_name, size_t oldlen,
1464 const char *new_name, size_t newlen,
1465 struct ptlrpc_request **request)
1469 rc = exp_check_ops(exp);
1473 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1476 return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
1477 new_name, newlen, request);
1480 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1481 void *ea, size_t ealen,
1482 struct ptlrpc_request **request)
1486 rc = exp_check_ops(exp);
1490 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1493 return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1496 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1497 struct ptlrpc_request **request)
1501 rc = exp_check_ops(exp);
1505 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1508 return MDP(exp->exp_obd, fsync)(exp, fid, request);
1511 /* FLR: resync mirrored files. */
1512 static inline int md_file_resync(struct obd_export *exp,
1513 struct md_op_data *data)
1517 rc = exp_check_ops(exp);
1521 return MDP(exp->exp_obd, file_resync)(exp, data);
1524 static inline int md_read_page(struct obd_export *exp,
1525 struct md_op_data *op_data,
1526 struct md_callback *cb_op,
1528 struct page **ppage)
1532 rc = exp_check_ops(exp);
1536 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1537 LPROC_MD_READ_PAGE);
1539 return MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1543 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1544 struct ptlrpc_request **request)
1548 rc = exp_check_ops(exp);
1552 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1555 return MDP(exp->exp_obd, unlink)(exp, op_data, request);
1558 static inline int md_get_lustre_md(struct obd_export *exp,
1559 struct ptlrpc_request *req,
1560 struct obd_export *dt_exp,
1561 struct obd_export *md_exp,
1562 struct lustre_md *md)
1566 rc = exp_check_ops(exp);
1570 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1573 static inline int md_free_lustre_md(struct obd_export *exp,
1574 struct lustre_md *md)
1578 rc = exp_check_ops(exp);
1582 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1585 static inline int md_merge_attr(struct obd_export *exp,
1586 const struct lmv_stripe_md *lsm,
1587 struct cl_attr *attr,
1588 ldlm_blocking_callback cb)
1592 rc = exp_check_ops(exp);
1596 return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb);
1599 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1600 u64 obd_md_valid, const char *name,
1601 const void *value, size_t value_size,
1602 unsigned int xattr_flags, u32 suppgid,
1603 struct ptlrpc_request **req)
1607 rc = exp_check_ops(exp);
1611 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1614 return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1615 value, value_size, xattr_flags,
1619 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1620 u64 obd_md_valid, const char *name,
1621 size_t buf_size, struct ptlrpc_request **req)
1625 rc = exp_check_ops(exp);
1629 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1632 return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1636 static inline int md_set_open_replay_data(struct obd_export *exp,
1637 struct obd_client_handle *och,
1638 struct lookup_intent *it)
1642 rc = exp_check_ops(exp);
1646 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1649 static inline int md_clear_open_replay_data(struct obd_export *exp,
1650 struct obd_client_handle *och)
1654 rc = exp_check_ops(exp);
1658 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1661 static inline int md_set_lock_data(struct obd_export *exp,
1662 const struct lustre_handle *lockh,
1663 void *data, __u64 *bits)
1667 rc = exp_check_ops(exp);
1671 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1675 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1676 union ldlm_policy_data *policy, enum ldlm_mode mode,
1677 enum ldlm_cancel_flags cancel_flags, void *opaque)
1681 rc = exp_check_ops(exp);
1685 return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1686 cancel_flags, opaque);
1689 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1690 const struct lu_fid *fid,
1691 enum ldlm_type type,
1692 union ldlm_policy_data *policy,
1693 enum ldlm_mode mode,
1694 struct lustre_handle *lockh)
1698 rc = exp_check_ops(exp);
1702 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1703 policy, mode, lockh);
1706 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1711 rc = exp_check_ops(exp);
1715 return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
1718 static inline int md_intent_getattr_async(struct obd_export *exp,
1719 struct md_enqueue_info *minfo)
1723 rc = exp_check_ops(exp);
1727 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1728 LPROC_MD_INTENT_GETATTR_ASYNC);
1730 return MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1733 static inline int md_revalidate_lock(struct obd_export *exp,
1734 struct lookup_intent *it,
1735 struct lu_fid *fid, __u64 *bits)
1739 rc = exp_check_ops(exp);
1743 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1744 LPROC_MD_REVALIDATE_LOCK);
1746 return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1749 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1750 const struct lmv_stripe_md *lsm,
1751 const char *name, int namelen,
1756 rc = exp_check_ops(exp);
1760 return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
1764 /* Unpack an MD struct from disk to in-memory format.
1765 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1767 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1768 * If *plsm == NULL then it will be allocated.
1770 static inline int md_unpackmd(struct obd_export *exp,
1771 struct lmv_stripe_md **plsm,
1772 const union lmv_mds_md *lmm, size_t lmm_size)
1776 rc = exp_check_ops(exp);
1780 return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1783 /* OBD Metadata Support */
1785 extern int obd_init_caches(void);
1786 extern void obd_cleanup_caches(void);
1788 typedef int (*register_lwp_cb)(void *data);
1790 struct lwp_register_item {
1791 struct obd_export **lri_exp;
1792 register_lwp_cb lri_cb_func;
1794 struct list_head lri_list;
1796 char lri_name[MTI_NAME_MAXLEN];
1799 /* I'm as embarrassed about this as you are.
1801 * <shaver> // XXX do not look into _superhack with remaining eye
1802 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1803 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1806 #ifdef HAVE_SERVER_SUPPORT
1807 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1808 register_lwp_cb cb_func, void *cb_data);
1809 void lustre_deregister_lwp_item(struct obd_export **exp);
1810 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1811 void lustre_notify_lwp_list(struct obd_export *exp);
1812 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1813 #endif /* HAVE_SERVER_SUPPORT */
1814 int lustre_register_fs(void);
1815 int lustre_unregister_fs(void);
1816 int lustre_check_exclusion(struct super_block *sb, char *svname);
1818 typedef __u8 class_uuid_t[16];
1819 static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
1821 snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-"
1822 "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1823 uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9],
1824 uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]);
1828 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1829 int class_add_uuid(const char *uuid, __u64 nid);
1830 int class_del_uuid (const char *uuid);
1831 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1834 extern char obd_jobid_name[];
1837 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1841 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1842 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1844 /* root squash info */
1845 struct rw_semaphore;
1846 struct root_squash_info {
1849 struct list_head rsi_nosquash_nids;
1850 struct rw_semaphore rsi_sem;
1853 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1855 /* linux-module.c */
1856 extern struct miscdevice obd_psdev;
1857 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1858 int class_procfs_init(void);
1859 int class_procfs_clean(void);
1860 #endif /* __LINUX_OBD_CLASS_H */