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.
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. */
51 extern rwlock_t obd_dev_lock;
53 /* OBD Operations Declarations */
54 extern struct obd_device *class_conn2obd(struct lustre_handle *);
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);
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 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
67 struct lprocfs_vars *module_vars,
68 const char *nm, struct lu_device_type *ldt);
69 int class_unregister_type(const char *nm);
71 struct obd_device *class_newdev(const char *type_name, const char *name,
73 int class_register_device(struct obd_device *obd);
74 void class_unregister_device(struct obd_device *obd);
75 void class_free_dev(struct obd_device *obd);
77 struct obd_device *class_dev_by_str(const char *str);
78 int class_name2dev(const char *name);
79 struct obd_device *class_name2obd(const char *name);
80 int class_uuid2dev(struct obd_uuid *uuid);
81 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
82 void class_obd_list(void);
83 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
84 const char * typ_name,
85 struct obd_uuid *grp_uuid);
86 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
88 struct obd_device * class_num2obd(int num);
89 int get_devices_count(void);
91 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
93 char *obd_export_nid2str(struct obd_export *exp);
95 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
96 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
97 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
100 int obd_zombie_impexp_init(void);
101 void obd_zombie_impexp_stop(void);
102 void obd_zombie_impexp_cull(void);
103 void obd_zombie_barrier(void);
104 void obd_exports_barrier(struct obd_device *obd);
105 int kuc_len(int payload_len);
106 struct kuc_hdr * kuc_ptr(void *p);
107 void *kuc_alloc(int payload_len, int transport, int type);
108 void kuc_free(void *p, int payload_len);
109 int obd_get_request_slot(struct client_obd *cli);
110 void obd_put_request_slot(struct client_obd *cli);
111 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
112 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
113 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
114 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
115 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
117 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
118 struct lookup_intent *it);
119 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
120 struct lookup_intent *it, __u16 tag);
124 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
125 struct llog_rec_hdr *, void *);
127 struct obd_export *obd_stale_export_get(void);
128 void obd_stale_export_put(struct obd_export *exp);
129 void obd_stale_export_adjust(struct obd_export *exp);
132 /* For interoperability */
133 struct cfg_interop_param {
138 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
139 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
140 const char *new_name);
141 void print_lustre_cfg(struct lustre_cfg *lcfg);
142 int class_process_config(struct lustre_cfg *lcfg);
143 ssize_t class_set_global(const char *param);
144 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
145 struct kobject *kobj);
146 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
147 struct lustre_cfg *lcfg, void *data);
148 int class_attach(struct lustre_cfg *lcfg);
149 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
150 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
151 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
153 int class_find_param(char *buf, char *key, char **valp);
154 struct cfg_interop_param *class_find_old_param(const char *param,
155 struct cfg_interop_param *ptr);
156 int class_get_next_param(char **params, char *copy);
157 int class_match_param(char *buf, const char *key, char **valp);
158 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
159 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
160 int class_parse_net(char *buf, u32 *net, char **endh);
161 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
162 int class_match_net(char *buf, char *key, u32 net);
164 struct obd_device *class_incref(struct obd_device *obd,
165 const char *scope, const void *source);
166 void class_decref(struct obd_device *obd,
167 const char *scope, const void *source);
168 void dump_exports(struct obd_device *obd, int locks, int debug_level);
169 int class_config_llog_handler(const struct lu_env *env,
170 struct llog_handle *handle,
171 struct llog_rec_hdr *rec, void *data);
172 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
174 #define CFG_F_START 0x01 /* Set when we start updating from a log */
175 #define CFG_F_MARKER 0x02 /* We are within a maker */
176 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
177 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
178 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
180 /* Passed as data param to class_config_parse_llog */
181 struct config_llog_instance {
184 struct super_block *cfg_sb;
185 struct obd_uuid cfg_uuid;
186 llog_cb_t cfg_callback;
187 int cfg_last_idx; /* for partial llog processing */
192 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
193 char *name, struct config_llog_instance *cfg);
195 #define CONFIG_SUB_SPTLRPC 0x01
196 #define CONFIG_SUB_RECOVER 0x02
197 #define CONFIG_SUB_PARAMS 0x04
198 #define CONFIG_SUB_NODEMAP 0x08
199 #define CONFIG_SUB_BARRIER 0x10
201 /* Sub clds should be attached to the config_llog_data when processing
202 * config log for client or server target. */
203 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
205 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
208 #define PARAMS_FILENAME "params"
209 #define BARRIER_FILENAME "barrier"
210 #define LCTL_UPCALL "lctl"
212 static inline bool logname_is_barrier(const char *logname)
216 /* logname for barrier is "fsname-barrier" */
217 ptr = strstr(logname, BARRIER_FILENAME);
218 if (ptr && (ptr - logname) >= 2 &&
219 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
225 /* list of active configuration logs */
226 struct config_llog_data {
227 struct ldlm_res_id cld_resid;
228 struct config_llog_instance cld_cfg;
229 struct list_head cld_list_chain;/* on config_llog_list */
230 atomic_t cld_refcount;
231 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
232 struct config_llog_data *cld_params; /* common parameters log */
233 struct config_llog_data *cld_recover;/* imperative recover log */
234 struct config_llog_data *cld_nodemap;/* nodemap log */
235 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
236 struct obd_export *cld_mgcexp;
237 struct mutex cld_lock;
239 unsigned int cld_stopping:1, /* we were told to stop
241 cld_lostlock:1; /* lock not requeued */
245 struct lustre_profile {
246 struct list_head lp_list;
251 bool lp_list_deleted;
254 struct lustre_profile *class_get_profile(const char * prof);
255 void class_del_profile(const char *prof);
256 void class_put_profile(struct lustre_profile *lprof);
257 void class_del_profiles(void);
260 #if LUSTRE_TRACKS_LOCK_EXP_REFS
262 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
263 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
264 extern void (*class_export_dump_hook)(struct obd_export *);
268 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
269 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
273 #define class_export_rpc_inc(exp) \
275 atomic_inc(&(exp)->exp_rpc_count); \
276 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
277 (exp), atomic_read(&(exp)->exp_rpc_count)); \
280 #define class_export_rpc_dec(exp) \
282 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
283 atomic_dec(&(exp)->exp_rpc_count); \
284 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
285 (exp), atomic_read(&(exp)->exp_rpc_count)); \
288 #define class_export_lock_get(exp, lock) \
290 atomic_inc(&(exp)->exp_locks_count); \
291 __class_export_add_lock_ref(exp, lock); \
292 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
293 (exp), atomic_read(&(exp)->exp_locks_count)); \
294 class_export_get(exp); \
297 #define class_export_lock_put(exp, lock) \
299 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
300 atomic_dec(&(exp)->exp_locks_count); \
301 __class_export_del_lock_ref(exp, lock); \
302 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
303 (exp), atomic_read(&(exp)->exp_locks_count)); \
304 class_export_put(exp); \
307 #define class_export_cb_get(exp) \
309 atomic_inc(&(exp)->exp_cb_count); \
310 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
311 (exp), atomic_read(&(exp)->exp_cb_count)); \
312 class_export_get(exp); \
315 #define class_export_cb_put(exp) \
317 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
318 atomic_dec(&(exp)->exp_cb_count); \
319 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
320 (exp), atomic_read(&(exp)->exp_cb_count)); \
321 class_export_put(exp); \
325 struct obd_export *class_export_get(struct obd_export *exp);
326 void class_export_put(struct obd_export *exp);
327 struct obd_export *class_new_export(struct obd_device *obddev,
328 struct obd_uuid *cluuid);
329 struct obd_export *class_new_export_self(struct obd_device *obd,
330 struct obd_uuid *uuid);
331 void class_unlink_export(struct obd_export *exp);
333 struct obd_import *class_import_get(struct obd_import *);
334 void class_import_put(struct obd_import *);
335 struct obd_import *class_new_import(struct obd_device *obd);
336 void class_destroy_import(struct obd_import *exp);
338 struct obd_type *class_search_type(const char *name);
339 struct obd_type *class_get_type(const char *name);
340 void class_put_type(struct obd_type *type);
341 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
342 struct obd_uuid *cluuid);
343 int class_disconnect(struct obd_export *exp);
344 void class_fail_export(struct obd_export *exp);
345 int class_connected_export(struct obd_export *exp);
346 void class_disconnect_exports(struct obd_device *obddev);
347 int class_manual_cleanup(struct obd_device *obd);
348 void class_disconnect_stale_exports(struct obd_device *,
349 int (*test_export)(struct obd_export *));
350 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
352 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
353 (obd->obd_force ? OBD_OPT_FORCE : 0) |
354 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
358 #ifdef HAVE_SERVER_SUPPORT
359 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
361 LASSERT(exp->exp_obd);
362 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
364 return exp->exp_obd->u.obt.obt_lut;
367 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
369 LASSERT(obd->u.obt.obt_lut);
370 return &obd->u.obt.obt_lut->lut_lsd;
378 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
379 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
381 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
382 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
384 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
385 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
387 /* Ensure obd_setup: used for cleanup which must be called
388 while obd is stopping */
389 #define OBD_CHECK_DEV(obd) \
392 CERROR("NULL device\n"); \
397 /* ensure obd_setup and !obd_stopping */
398 #define OBD_CHECK_DEV_ACTIVE(obd) \
400 OBD_CHECK_DEV(obd); \
401 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
402 CERROR("Device %d not setup\n", \
409 #ifdef CONFIG_PROC_FS
410 #define OBD_COUNTER_OFFSET(op) \
411 ((offsetof(struct obd_ops, o_ ## op) - \
412 offsetof(struct obd_ops, o_iocontrol)) \
413 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
415 /* The '- 1' below is for o_owner. */
416 #define NUM_OBD_STATS \
417 (sizeof(struct obd_ops) / \
418 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
420 #define OBD_COUNTER_INCREMENT(obd, op) \
421 lprocfs_counter_incr((obd)->obd_stats, \
422 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
424 #define EXP_COUNTER_INCREMENT(exp, op) \
427 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
428 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
429 if ((exp)->exp_obd->obd_uses_nid_stats && \
430 (exp)->exp_nid_stats != NULL) \
431 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
435 #define _MD_COUNTER_OFFSET(m_op) \
436 ((offsetof(struct md_ops, m_op) - \
437 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
438 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
440 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
442 #define NUM_MD_STATS \
443 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
444 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
446 /* Note that we only increment md counters for ops whose offset is less
447 * than NUM_MD_STATS. This is explained in a comment in the definition
448 * of struct md_ops. */
449 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
451 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
452 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
453 (exp)->exp_obd->obd_md_cntr_base + \
454 MD_COUNTER_OFFSET(op)); \
458 #define OBD_COUNTER_OFFSET(op)
459 #define OBD_COUNTER_INCREMENT(obd, op)
460 #define EXP_COUNTER_INCREMENT(exp, op)
461 #define EXP_MD_COUNTER_INCREMENT(exp, op)
464 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
466 /* Always add in ldlm_stats */
467 tmp->nid_ldlm_stats =
468 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
469 LPROCFS_STATS_FLAG_NOPERCPU);
470 if (tmp->nid_ldlm_stats == NULL)
473 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
475 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
476 tmp->nid_ldlm_stats);
479 static inline int exp_check_ops(struct obd_export *exp)
484 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
490 static inline int class_devno_max(void)
492 return MAX_OBD_DEVICES;
495 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
496 __u32 keylen, void *key,
497 __u32 *vallen, void *val)
502 rc = exp_check_ops(exp);
506 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
507 CERROR("%s: no %s operation\n",
508 (exp)->exp_obd->obd_name, __func__);
511 EXP_COUNTER_INCREMENT(exp, get_info);
513 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
517 static inline int obd_set_info_async(const struct lu_env *env,
518 struct obd_export *exp,
519 __u32 keylen, void *key,
520 __u32 vallen, void *val,
521 struct ptlrpc_request_set *set)
526 rc = exp_check_ops(exp);
530 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
531 CERROR("%s: no %s operation\n",
532 (exp)->exp_obd->obd_name, __func__);
535 EXP_COUNTER_INCREMENT(exp, set_info_async);
537 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
543 * obd-lu integration.
545 * Functionality is being moved into new lu_device-based layering, but some
546 * pieces of configuration process are still based on obd devices.
548 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
549 * subsume ->o_setup() methods of obd devices they replace. The same for
550 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
551 * result, obd_setup() and obd_process_config() branch and call one XOR
554 * Yet neither lu_device_type_operations::ldto_device_fini() nor
555 * lu_device_type_operations::ldto_device_free() fully implement the
556 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
557 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
559 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
562 struct lu_device_type *ldt = obd->obd_type->typ_lu;
568 struct lu_context session_ctx;
570 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
571 session_ctx.lc_thread = NULL;
572 lu_context_enter(&session_ctx);
574 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
576 env.le_ses = &session_ctx;
577 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
586 lu_context_exit(&session_ctx);
587 lu_context_fini(&session_ctx);
590 if (!obd->obd_type->typ_dt_ops->o_setup) {
591 CERROR("%s: no %s operation\n", obd->obd_name,
595 OBD_COUNTER_INCREMENT(obd, setup);
596 rc = OBP(obd, setup)(obd, cfg);
601 static inline int obd_precleanup(struct obd_device *obd)
604 struct lu_device_type *ldt = obd->obd_type->typ_lu;
605 struct lu_device *d = obd->obd_lu_dev;
609 if (ldt != NULL && d != NULL) {
612 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
614 ldt->ldt_ops->ldto_device_fini(&env, d);
619 if (!obd->obd_type->typ_dt_ops->o_precleanup)
622 OBD_COUNTER_INCREMENT(obd, precleanup);
624 rc = OBP(obd, precleanup)(obd);
628 static inline int obd_cleanup(struct obd_device *obd)
631 struct lu_device_type *ldt = obd->obd_type->typ_lu;
632 struct lu_device *d = obd->obd_lu_dev;
635 if (ldt != NULL && d != NULL) {
638 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
640 ldt->ldt_ops->ldto_device_free(&env, d);
642 obd->obd_lu_dev = NULL;
645 if (!obd->obd_type->typ_dt_ops->o_cleanup)
648 OBD_COUNTER_INCREMENT(obd, cleanup);
650 rc = OBP(obd, cleanup)(obd);
654 static inline void obd_cleanup_client_import(struct obd_device *obd)
658 /* If we set up but never connected, the
659 client import will not have been cleaned. */
660 down_write(&obd->u.cli.cl_sem);
661 if (obd->u.cli.cl_import) {
662 struct obd_import *imp;
663 imp = obd->u.cli.cl_import;
664 CDEBUG(D_CONFIG, "%s: client import never connected\n",
666 ptlrpc_invalidate_import(imp);
667 client_destroy_import(imp);
668 obd->u.cli.cl_import = NULL;
670 up_write(&obd->u.cli.cl_sem);
675 static inline int obd_process_config(struct obd_device *obd, int datalen,
679 struct lu_device_type *ldt = obd->obd_type->typ_lu;
680 struct lu_device *d = obd->obd_lu_dev;
684 obd->obd_process_conf = 1;
685 if (ldt != NULL && d != NULL) {
688 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
690 rc = d->ld_ops->ldo_process_config(&env, d, data);
694 if (!obd->obd_type->typ_dt_ops->o_process_config) {
695 CERROR("%s: no %s operation\n",
696 obd->obd_name, __func__);
699 rc = OBP(obd, process_config)(obd, datalen, data);
701 OBD_COUNTER_INCREMENT(obd, process_config);
702 obd->obd_process_conf = 0;
707 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
713 rc = exp_check_ops(exp);
717 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
718 CERROR("%s: no %s operation\n",
719 (exp)->exp_obd->obd_name, __func__);
722 EXP_COUNTER_INCREMENT(exp, create);
724 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
728 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
734 rc = exp_check_ops(exp);
738 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
739 CERROR("%s: no %s operation\n",
740 (exp)->exp_obd->obd_name, __func__);
743 EXP_COUNTER_INCREMENT(exp, destroy);
745 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
749 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
755 rc = exp_check_ops(exp);
759 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
760 CERROR("%s: no %s operation\n",
761 (exp)->exp_obd->obd_name, __func__);
764 EXP_COUNTER_INCREMENT(exp, getattr);
765 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
770 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
776 rc = exp_check_ops(exp);
780 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
781 CERROR("%s: no %s operation\n",
782 (exp)->exp_obd->obd_name, __func__);
785 EXP_COUNTER_INCREMENT(exp, setattr);
786 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
791 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
794 struct obd_device *obd = imp->imp_obd;
798 OBD_CHECK_DEV_ACTIVE(obd);
799 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
800 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
803 OBD_COUNTER_INCREMENT(obd, add_conn);
805 rc = OBP(obd, add_conn)(imp, uuid, priority);
809 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
811 struct obd_device *obd = imp->imp_obd;
815 OBD_CHECK_DEV_ACTIVE(obd);
816 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
817 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
820 OBD_COUNTER_INCREMENT(obd, del_conn);
822 rc = OBP(obd, del_conn)(imp, uuid);
826 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
828 struct obd_uuid *uuid;
831 if (!exp->exp_obd->obd_type ||
832 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
835 EXP_COUNTER_INCREMENT(exp, get_uuid);
837 uuid = OBP(exp->exp_obd, get_uuid)(exp);
841 /** Create a new /a exp on device /a obd for the uuid /a cluuid
842 * @param exp New export handle
843 * @param d Connect data, supported flags are set, flags also understood
844 * by obd are returned.
846 static inline int obd_connect(const struct lu_env *env,
847 struct obd_export **exp,struct obd_device *obd,
848 struct obd_uuid *cluuid,
849 struct obd_connect_data *data,
853 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
857 OBD_CHECK_DEV_ACTIVE(obd);
858 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
859 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
862 OBD_COUNTER_INCREMENT(obd, connect);
864 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
865 /* check that only subset is granted */
866 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
867 data->ocd_connect_flags));
871 static inline int obd_reconnect(const struct lu_env *env,
872 struct obd_export *exp,
873 struct obd_device *obd,
874 struct obd_uuid *cluuid,
875 struct obd_connect_data *d,
879 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
884 OBD_CHECK_DEV_ACTIVE(obd);
885 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
888 OBD_COUNTER_INCREMENT(obd, reconnect);
890 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
891 /* check that only subset is granted */
892 LASSERT(ergo(d != NULL,
893 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
897 static inline int obd_disconnect(struct obd_export *exp)
901 rc = exp_check_ops(exp);
905 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
906 CERROR("%s: no %s operation\n",
907 (exp)->exp_obd->obd_name, __func__);
910 EXP_COUNTER_INCREMENT(exp, disconnect);
912 rc = OBP(exp->exp_obd, disconnect)(exp);
916 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
917 enum lu_cli_type type)
922 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
924 OBD_COUNTER_INCREMENT(obd, fid_init);
926 rc = OBP(obd, fid_init)(obd, exp, type);
930 static inline int obd_fid_fini(struct obd_device *obd)
934 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
936 OBD_COUNTER_INCREMENT(obd, fid_fini);
938 rc = OBP(obd, fid_fini)(obd);
942 static inline int obd_fid_alloc(const struct lu_env *env,
943 struct obd_export *exp,
945 struct md_op_data *op_data)
949 rc = exp_check_ops(exp);
953 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
954 CERROR("%s: no %s operation\n",
955 (exp)->exp_obd->obd_name, __func__);
958 EXP_COUNTER_INCREMENT(exp, fid_alloc);
960 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
964 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
969 if (!exp->exp_obd->obd_type ||
970 !exp->exp_obd->obd_type->typ_dt_ops->o_ping)
973 EXP_COUNTER_INCREMENT(exp, ping);
975 rc = OBP(exp->exp_obd, ping)(env, exp);
979 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
984 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
985 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
988 OBD_COUNTER_INCREMENT(obd, pool_new);
990 rc = OBP(obd, pool_new)(obd, poolname);
994 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
998 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
999 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1000 RETURN(-EOPNOTSUPP);
1002 OBD_COUNTER_INCREMENT(obd, pool_del);
1004 rc = OBP(obd, pool_del)(obd, poolname);
1008 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1014 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1015 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1016 RETURN(-EOPNOTSUPP);
1018 OBD_COUNTER_INCREMENT(obd, pool_add);
1020 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1024 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1030 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1031 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1032 RETURN(-EOPNOTSUPP);
1034 OBD_COUNTER_INCREMENT(obd, pool_rem);
1036 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1040 static inline void obd_getref(struct obd_device *obd)
1043 if (obd->obd_type && OBP(obd, getref)) {
1044 OBD_COUNTER_INCREMENT(obd, getref);
1045 OBP(obd, getref)(obd);
1050 static inline void obd_putref(struct obd_device *obd)
1053 if (obd->obd_type && OBP(obd, putref)) {
1054 OBD_COUNTER_INCREMENT(obd, putref);
1055 OBP(obd, putref)(obd);
1060 static inline int obd_init_export(struct obd_export *exp)
1065 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1066 OBP((exp)->exp_obd, init_export))
1067 rc = OBP(exp->exp_obd, init_export)(exp);
1071 static inline int obd_destroy_export(struct obd_export *exp)
1074 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1075 OBP(exp->exp_obd, destroy_export))
1076 OBP(exp->exp_obd, destroy_export)(exp);
1080 /* @max_age is the oldest time in seconds that we accept using a cached data.
1081 * If the cache is older than @max_age we will get a new value from the
1082 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1084 static inline int obd_statfs_async(struct obd_export *exp,
1085 struct obd_info *oinfo,
1087 struct ptlrpc_request_set *rqset)
1090 struct obd_device *obd;
1094 if (exp == NULL || exp->exp_obd == NULL)
1098 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1099 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1100 RETURN(-EOPNOTSUPP);
1102 OBD_COUNTER_INCREMENT(obd, statfs);
1104 CDEBUG(D_SUPER, "%s: osfs %p age %lld, max_age %lld\n",
1105 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1106 if (obd->obd_osfs_age < max_age) {
1107 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1110 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1111 obd->obd_name, &obd->obd_osfs,
1112 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1113 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1114 spin_lock(&obd->obd_osfs_lock);
1115 memcpy(oinfo->oi_osfs, &obd->obd_osfs,
1116 sizeof(*oinfo->oi_osfs));
1117 spin_unlock(&obd->obd_osfs_lock);
1118 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1119 if (oinfo->oi_cb_up)
1120 oinfo->oi_cb_up(oinfo, 0);
1125 /* @max_age is the oldest time in seconds that we accept using a cached data.
1126 * If the cache is older than @max_age we will get a new value from the
1127 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1129 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1130 struct obd_statfs *osfs, time64_t max_age,
1134 struct obd_device *obd = exp->exp_obd;
1140 OBD_CHECK_DEV_ACTIVE(obd);
1142 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1143 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1144 RETURN(-EOPNOTSUPP);
1146 OBD_COUNTER_INCREMENT(obd, statfs);
1148 CDEBUG(D_SUPER, "osfs %lld, max_age %lld\n",
1149 obd->obd_osfs_age, max_age);
1150 if (obd->obd_osfs_age < max_age) {
1151 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1153 spin_lock(&obd->obd_osfs_lock);
1154 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1155 obd->obd_osfs_age = ktime_get_seconds();
1156 spin_unlock(&obd->obd_osfs_lock);
1159 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1160 " objects %llu/%llu\n",
1161 obd->obd_name, &obd->obd_osfs,
1162 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1163 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1164 spin_lock(&obd->obd_osfs_lock);
1165 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1166 spin_unlock(&obd->obd_osfs_lock);
1171 static inline int obd_preprw(const struct lu_env *env, int cmd,
1172 struct obd_export *exp, struct obdo *oa,
1173 int objcount, struct obd_ioobj *obj,
1174 struct niobuf_remote *remote, int *pages,
1175 struct niobuf_local *local)
1181 rc = exp_check_ops(exp);
1185 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1186 CERROR("%s: no %s operation\n",
1187 (exp)->exp_obd->obd_name, __func__);
1190 EXP_COUNTER_INCREMENT(exp, preprw);
1191 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1197 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1198 struct obd_export *exp, struct obdo *oa,
1199 int objcount, struct obd_ioobj *obj,
1200 struct niobuf_remote *rnb, int pages,
1201 struct niobuf_local *local, int rc)
1205 rc = exp_check_ops(exp);
1209 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1210 CERROR("%s: no %s operation\n",
1211 (exp)->exp_obd->obd_name, __func__);
1214 EXP_COUNTER_INCREMENT(exp, commitrw);
1215 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1216 rnb, pages, local, rc);
1221 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1222 int len, void *karg, void __user *uarg)
1227 rc = exp_check_ops(exp);
1231 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1232 CERROR("%s: no %s operation\n",
1233 (exp)->exp_obd->obd_name, __func__);
1236 EXP_COUNTER_INCREMENT(exp, iocontrol);
1238 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1242 static inline void obd_import_event(struct obd_device *obd,
1243 struct obd_import *imp,
1244 enum obd_import_event event)
1248 CERROR("NULL device\n");
1252 if (obd->obd_set_up && OBP(obd, import_event)) {
1253 OBD_COUNTER_INCREMENT(obd, import_event);
1254 OBP(obd, import_event)(obd, imp, event);
1259 static inline int obd_notify(struct obd_device *obd,
1260 struct obd_device *watched,
1261 enum obd_notify_event ev)
1267 if (!obd->obd_set_up) {
1268 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1272 if (!OBP(obd, notify)) {
1273 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1277 OBD_COUNTER_INCREMENT(obd, notify);
1278 rc = OBP(obd, notify)(obd, watched, ev);
1283 static inline int obd_notify_observer(struct obd_device *observer,
1284 struct obd_device *observed,
1285 enum obd_notify_event ev)
1289 struct obd_notify_upcall *onu;
1291 if (observer->obd_observer)
1292 rc = obd_notify(observer->obd_observer, observed, ev);
1295 * Also, call non-obd listener, if any
1297 onu = &observer->obd_upcall;
1298 if (onu->onu_upcall != NULL)
1299 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1301 return rc ? rc : rc2;
1304 static inline int obd_quotactl(struct obd_export *exp,
1305 struct obd_quotactl *oqctl)
1310 rc = exp_check_ops(exp);
1314 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1315 CERROR("%s: no %s operation\n",
1316 (exp)->exp_obd->obd_name, __func__);
1319 EXP_COUNTER_INCREMENT(exp, quotactl);
1321 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1325 static inline int obd_health_check(const struct lu_env *env,
1326 struct obd_device *obd)
1328 /* returns: 0 on healthy
1329 * >0 on unhealthy + reason code/flag
1330 * however the only suppored reason == 1 right now
1331 * We'll need to define some better reasons
1332 * or flags in the future.
1339 /* NULL method is normal here */
1340 if (obd == NULL || !obd->obd_type) {
1341 CERROR("cleaned up obd\n");
1342 RETURN(-EOPNOTSUPP);
1344 if (!obd->obd_set_up || obd->obd_stopping)
1346 if (!OBP(obd, health_check))
1349 rc = OBP(obd, health_check)(env, obd);
1353 static inline int obd_register_observer(struct obd_device *obd,
1354 struct obd_device *observer)
1358 down_write(&obd->obd_observer_link_sem);
1359 if (obd->obd_observer && observer) {
1360 up_write(&obd->obd_observer_link_sem);
1363 obd->obd_observer = observer;
1364 up_write(&obd->obd_observer_link_sem);
1368 /* metadata helpers */
1369 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1375 rc = exp_check_ops(exp);
1378 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1379 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1384 static inline int md_getattr(struct obd_export *exp,
1385 struct md_op_data *op_data,
1386 struct ptlrpc_request **request)
1391 rc = exp_check_ops(exp);
1394 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1395 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1399 static inline int md_null_inode(struct obd_export *exp,
1400 const struct lu_fid *fid)
1404 rc = exp_check_ops(exp);
1407 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1408 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1412 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1413 struct md_open_data *mod,
1414 struct ptlrpc_request **request)
1418 rc = exp_check_ops(exp);
1421 EXP_MD_COUNTER_INCREMENT(exp, close);
1422 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1426 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1427 const void *data, size_t datalen, umode_t mode,
1428 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1429 __u64 rdev, struct ptlrpc_request **request)
1433 rc = exp_check_ops(exp);
1436 EXP_MD_COUNTER_INCREMENT(exp, create);
1437 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1438 uid, gid, cap_effective, rdev, request);
1442 static inline int md_enqueue(struct obd_export *exp,
1443 struct ldlm_enqueue_info *einfo,
1444 const union ldlm_policy_data *policy,
1445 struct md_op_data *op_data,
1446 struct lustre_handle *lockh,
1447 __u64 extra_lock_flags)
1451 rc = exp_check_ops(exp);
1454 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1455 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1460 static inline int md_getattr_name(struct obd_export *exp,
1461 struct md_op_data *op_data,
1462 struct ptlrpc_request **request)
1466 rc = exp_check_ops(exp);
1469 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1470 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1474 static inline int md_intent_lock(struct obd_export *exp,
1475 struct md_op_data *op_data,
1476 struct lookup_intent *it,
1477 struct ptlrpc_request **reqp,
1478 ldlm_blocking_callback cb_blocking,
1479 __u64 extra_lock_flags)
1483 rc = exp_check_ops(exp);
1486 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1487 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1492 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1493 struct ptlrpc_request **request)
1497 rc = exp_check_ops(exp);
1500 EXP_MD_COUNTER_INCREMENT(exp, link);
1501 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1505 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1506 const char *old, size_t oldlen, const char *new,
1507 size_t newlen, struct ptlrpc_request **request)
1511 rc = exp_check_ops(exp);
1515 EXP_MD_COUNTER_INCREMENT(exp, rename);
1516 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1521 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1522 void *ea, size_t ealen,
1523 struct ptlrpc_request **request)
1527 rc = exp_check_ops(exp);
1531 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1532 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1536 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1537 struct ptlrpc_request **request)
1542 rc = exp_check_ops(exp);
1546 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1547 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1552 /* FLR: resync mirrored files. */
1553 static inline int md_file_resync(struct obd_export *exp,
1554 struct md_op_data *data)
1559 rc = exp_check_ops(exp);
1563 EXP_MD_COUNTER_INCREMENT(exp, file_resync);
1564 rc = MDP(exp->exp_obd, file_resync)(exp, data);
1569 static inline int md_read_page(struct obd_export *exp,
1570 struct md_op_data *op_data,
1571 struct md_callback *cb_op,
1573 struct page **ppage)
1577 rc = exp_check_ops(exp);
1581 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1582 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1587 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1588 struct ptlrpc_request **request)
1592 rc = exp_check_ops(exp);
1596 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1597 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1601 static inline int md_get_lustre_md(struct obd_export *exp,
1602 struct ptlrpc_request *req,
1603 struct obd_export *dt_exp,
1604 struct obd_export *md_exp,
1605 struct lustre_md *md)
1609 rc = exp_check_ops(exp);
1613 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1614 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1617 static inline int md_free_lustre_md(struct obd_export *exp,
1618 struct lustre_md *md)
1622 rc = exp_check_ops(exp);
1625 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1626 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1629 static inline int md_merge_attr(struct obd_export *exp,
1630 const struct lmv_stripe_md *lsm,
1631 struct cl_attr *attr,
1632 ldlm_blocking_callback cb)
1636 rc = exp_check_ops(exp);
1639 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1640 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1643 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1644 u64 valid, const char *name,
1645 const char *input, int input_size,
1646 int output_size, int flags, __u32 suppgid,
1647 struct ptlrpc_request **request)
1652 rc = exp_check_ops(exp);
1655 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1656 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1657 input_size, output_size, flags,
1661 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1662 u64 valid, const char *name,
1663 const char *input, int input_size,
1664 int output_size, int flags,
1665 struct ptlrpc_request **request)
1669 rc = exp_check_ops(exp);
1672 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1673 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1674 input_size, output_size, flags,
1678 static inline int md_set_open_replay_data(struct obd_export *exp,
1679 struct obd_client_handle *och,
1680 struct lookup_intent *it)
1684 rc = exp_check_ops(exp);
1687 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1688 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1691 static inline int md_clear_open_replay_data(struct obd_export *exp,
1692 struct obd_client_handle *och)
1696 rc = exp_check_ops(exp);
1699 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1700 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1703 static inline int md_set_lock_data(struct obd_export *exp,
1704 const struct lustre_handle *lockh,
1705 void *data, __u64 *bits)
1709 rc = exp_check_ops(exp);
1712 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1713 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1717 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1718 union ldlm_policy_data *policy, enum ldlm_mode mode,
1719 enum ldlm_cancel_flags cancel_flags, void *opaque)
1724 rc = exp_check_ops(exp);
1727 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1729 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1730 cancel_flags, opaque);
1734 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1735 const struct lu_fid *fid,
1736 enum ldlm_type type,
1737 union ldlm_policy_data *policy,
1738 enum ldlm_mode mode,
1739 struct lustre_handle *lockh)
1743 rc = exp_check_ops(exp);
1746 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1747 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1748 policy, mode, lockh));
1751 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1756 rc = exp_check_ops(exp);
1759 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1760 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1763 static inline int md_intent_getattr_async(struct obd_export *exp,
1764 struct md_enqueue_info *minfo)
1768 rc = exp_check_ops(exp);
1771 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1772 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1776 static inline int md_revalidate_lock(struct obd_export *exp,
1777 struct lookup_intent *it,
1778 struct lu_fid *fid, __u64 *bits)
1782 rc = exp_check_ops(exp);
1785 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1786 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1790 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1791 const struct lmv_stripe_md *lsm,
1792 const char *name, int namelen,
1797 rc = exp_check_ops(exp);
1800 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1801 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1806 /* Unpack an MD struct from disk to in-memory format.
1807 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1809 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1810 * If *plsm == NULL then it will be allocated.
1812 static inline int md_unpackmd(struct obd_export *exp,
1813 struct lmv_stripe_md **plsm,
1814 const union lmv_mds_md *lmm, size_t lmm_size)
1818 rc = exp_check_ops(exp);
1821 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1822 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1826 /* OBD Metadata Support */
1828 extern int obd_init_caches(void);
1829 extern void obd_cleanup_caches(void);
1831 /* support routines */
1832 extern struct kmem_cache *obdo_cachep;
1834 #define OBDO_ALLOC(ptr) \
1836 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1839 #define OBDO_FREE(ptr) \
1841 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1845 typedef int (*register_lwp_cb)(void *data);
1847 struct lwp_register_item {
1848 struct obd_export **lri_exp;
1849 register_lwp_cb lri_cb_func;
1851 struct list_head lri_list;
1853 char lri_name[MTI_NAME_MAXLEN];
1856 /* I'm as embarrassed about this as you are.
1858 * <shaver> // XXX do not look into _superhack with remaining eye
1859 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1860 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1863 #ifdef HAVE_SERVER_SUPPORT
1864 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1865 register_lwp_cb cb_func, void *cb_data);
1866 void lustre_deregister_lwp_item(struct obd_export **exp);
1867 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1868 void lustre_notify_lwp_list(struct obd_export *exp);
1869 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1870 #endif /* HAVE_SERVER_SUPPORT */
1871 int lustre_register_fs(void);
1872 int lustre_unregister_fs(void);
1873 int lustre_check_exclusion(struct super_block *sb, char *svname);
1875 typedef __u8 class_uuid_t[16];
1876 static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
1878 snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-"
1879 "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1880 uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9],
1881 uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]);
1885 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1886 int class_add_uuid(const char *uuid, __u64 nid);
1887 int class_del_uuid (const char *uuid);
1888 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1891 extern char obd_jobid_node[];
1894 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1898 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1899 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1901 /* root squash info */
1902 struct rw_semaphore;
1903 struct root_squash_info {
1906 struct list_head rsi_nosquash_nids;
1907 struct rw_semaphore rsi_sem;
1910 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1912 /* linux-module.c */
1913 extern struct miscdevice obd_psdev;
1914 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1915 int class_procfs_init(void);
1916 int class_procfs_clean(void);
1918 #endif /* __LINUX_OBD_CLASS_H */