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, 2016, 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 int class_process_config(struct lustre_cfg *lcfg);
142 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
143 struct lustre_cfg *lcfg, void *data);
144 int class_attach(struct lustre_cfg *lcfg);
145 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
146 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
147 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
149 int class_find_param(char *buf, char *key, char **valp);
150 struct cfg_interop_param *class_find_old_param(const char *param,
151 struct cfg_interop_param *ptr);
152 int class_get_next_param(char **params, char *copy);
153 int class_match_param(char *buf, const char *key, char **valp);
154 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
155 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
156 int class_parse_net(char *buf, u32 *net, char **endh);
157 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
158 int class_match_net(char *buf, char *key, u32 net);
160 struct obd_device *class_incref(struct obd_device *obd,
161 const char *scope, const void *source);
162 void class_decref(struct obd_device *obd,
163 const char *scope, const void *source);
164 void dump_exports(struct obd_device *obd, int locks, int debug_level);
165 int class_config_llog_handler(const struct lu_env *env,
166 struct llog_handle *handle,
167 struct llog_rec_hdr *rec, void *data);
168 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
170 #define CFG_F_START 0x01 /* Set when we start updating from a log */
171 #define CFG_F_MARKER 0x02 /* We are within a maker */
172 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
173 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
174 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
176 /* Passed as data param to class_config_parse_llog */
177 struct config_llog_instance {
180 struct super_block *cfg_sb;
181 struct obd_uuid cfg_uuid;
182 llog_cb_t cfg_callback;
183 int cfg_last_idx; /* for partial llog processing */
188 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
189 char *name, struct config_llog_instance *cfg);
191 #define CONFIG_SUB_SPTLRPC 0x01
192 #define CONFIG_SUB_RECOVER 0x02
193 #define CONFIG_SUB_PARAMS 0x04
194 #define CONFIG_SUB_NODEMAP 0x08
195 #define CONFIG_SUB_BARRIER 0x10
197 /* Sub clds should be attached to the config_llog_data when processing
198 * config log for client or server target. */
199 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
201 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
204 #define PARAMS_FILENAME "params"
205 #define BARRIER_FILENAME "barrier"
206 #define LCTL_UPCALL "lctl"
208 static inline bool logname_is_barrier(const char *logname)
212 /* logname for barrier is "fsname-barrier" */
213 ptr = strstr(logname, BARRIER_FILENAME);
214 if (ptr && (ptr - logname) >= 2 &&
215 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
221 /* list of active configuration logs */
222 struct config_llog_data {
223 struct ldlm_res_id cld_resid;
224 struct config_llog_instance cld_cfg;
225 struct list_head cld_list_chain;
226 atomic_t cld_refcount;
227 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
228 struct config_llog_data *cld_params; /* common parameters log */
229 struct config_llog_data *cld_recover;/* imperative recover log */
230 struct config_llog_data *cld_nodemap;/* nodemap log */
231 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
232 struct obd_export *cld_mgcexp;
233 struct mutex cld_lock;
235 unsigned int cld_stopping:1, /* we were told to stop
237 cld_lostlock:1; /* lock not requeued */
241 struct lustre_profile {
242 struct list_head lp_list;
247 bool lp_list_deleted;
250 struct lustre_profile *class_get_profile(const char * prof);
251 void class_del_profile(const char *prof);
252 void class_put_profile(struct lustre_profile *lprof);
253 void class_del_profiles(void);
256 #if LUSTRE_TRACKS_LOCK_EXP_REFS
258 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
259 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
260 extern void (*class_export_dump_hook)(struct obd_export *);
264 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
265 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
269 #define class_export_rpc_inc(exp) \
271 atomic_inc(&(exp)->exp_rpc_count); \
272 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
273 (exp), atomic_read(&(exp)->exp_rpc_count)); \
276 #define class_export_rpc_dec(exp) \
278 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
279 atomic_dec(&(exp)->exp_rpc_count); \
280 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
281 (exp), atomic_read(&(exp)->exp_rpc_count)); \
284 #define class_export_lock_get(exp, lock) \
286 atomic_inc(&(exp)->exp_locks_count); \
287 __class_export_add_lock_ref(exp, lock); \
288 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
289 (exp), atomic_read(&(exp)->exp_locks_count)); \
290 class_export_get(exp); \
293 #define class_export_lock_put(exp, lock) \
295 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
296 atomic_dec(&(exp)->exp_locks_count); \
297 __class_export_del_lock_ref(exp, lock); \
298 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
299 (exp), atomic_read(&(exp)->exp_locks_count)); \
300 class_export_put(exp); \
303 #define class_export_cb_get(exp) \
305 atomic_inc(&(exp)->exp_cb_count); \
306 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
307 (exp), atomic_read(&(exp)->exp_cb_count)); \
308 class_export_get(exp); \
311 #define class_export_cb_put(exp) \
313 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
314 atomic_dec(&(exp)->exp_cb_count); \
315 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
316 (exp), atomic_read(&(exp)->exp_cb_count)); \
317 class_export_put(exp); \
321 struct obd_export *class_export_get(struct obd_export *exp);
322 void class_export_put(struct obd_export *exp);
323 struct obd_export *class_new_export(struct obd_device *obddev,
324 struct obd_uuid *cluuid);
325 struct obd_export *class_new_export_self(struct obd_device *obd,
326 struct obd_uuid *uuid);
327 void class_unlink_export(struct obd_export *exp);
329 struct obd_import *class_import_get(struct obd_import *);
330 void class_import_put(struct obd_import *);
331 struct obd_import *class_new_import(struct obd_device *obd);
332 void class_destroy_import(struct obd_import *exp);
334 struct obd_type *class_search_type(const char *name);
335 struct obd_type *class_get_type(const char *name);
336 void class_put_type(struct obd_type *type);
337 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
338 struct obd_uuid *cluuid);
339 int class_disconnect(struct obd_export *exp);
340 void class_fail_export(struct obd_export *exp);
341 int class_connected_export(struct obd_export *exp);
342 void class_disconnect_exports(struct obd_device *obddev);
343 int class_manual_cleanup(struct obd_device *obd);
344 void class_disconnect_stale_exports(struct obd_device *,
345 int (*test_export)(struct obd_export *));
346 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
348 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
349 (obd->obd_force ? OBD_OPT_FORCE : 0) |
350 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
354 #ifdef HAVE_SERVER_SUPPORT
355 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
357 LASSERT(exp->exp_obd);
358 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
360 return exp->exp_obd->u.obt.obt_lut;
363 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
365 LASSERT(obd->u.obt.obt_lut);
366 return &obd->u.obt.obt_lut->lut_lsd;
374 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
375 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
377 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
378 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
380 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
381 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
383 /* Ensure obd_setup: used for cleanup which must be called
384 while obd is stopping */
385 #define OBD_CHECK_DEV(obd) \
388 CERROR("NULL device\n"); \
393 /* ensure obd_setup and !obd_stopping */
394 #define OBD_CHECK_DEV_ACTIVE(obd) \
396 OBD_CHECK_DEV(obd); \
397 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
398 CERROR("Device %d not setup\n", \
405 #ifdef CONFIG_PROC_FS
406 #define OBD_COUNTER_OFFSET(op) \
407 ((offsetof(struct obd_ops, o_ ## op) - \
408 offsetof(struct obd_ops, o_iocontrol)) \
409 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
411 /* The '- 1' below is for o_owner. */
412 #define NUM_OBD_STATS \
413 (sizeof(struct obd_ops) / \
414 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
416 #define OBD_COUNTER_INCREMENT(obd, op) \
417 lprocfs_counter_incr((obd)->obd_stats, \
418 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
420 #define EXP_COUNTER_INCREMENT(exp, op) \
423 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
424 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
425 if ((exp)->exp_obd->obd_uses_nid_stats && \
426 (exp)->exp_nid_stats != NULL) \
427 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
431 #define _MD_COUNTER_OFFSET(m_op) \
432 ((offsetof(struct md_ops, m_op) - \
433 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
434 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
436 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
438 #define NUM_MD_STATS \
439 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
440 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
442 /* Note that we only increment md counters for ops whose offset is less
443 * than NUM_MD_STATS. This is explained in a comment in the definition
444 * of struct md_ops. */
445 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
447 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
448 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
449 (exp)->exp_obd->obd_md_cntr_base + \
450 MD_COUNTER_OFFSET(op)); \
454 #define OBD_COUNTER_OFFSET(op)
455 #define OBD_COUNTER_INCREMENT(obd, op)
456 #define EXP_COUNTER_INCREMENT(exp, op)
457 #define EXP_MD_COUNTER_INCREMENT(exp, op)
460 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
462 /* Always add in ldlm_stats */
463 tmp->nid_ldlm_stats =
464 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
465 LPROCFS_STATS_FLAG_NOPERCPU);
466 if (tmp->nid_ldlm_stats == NULL)
469 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
471 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
472 tmp->nid_ldlm_stats);
475 static inline int exp_check_ops(struct obd_export *exp)
480 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
486 static inline int class_devno_max(void)
488 return MAX_OBD_DEVICES;
491 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
492 __u32 keylen, void *key,
493 __u32 *vallen, void *val)
498 rc = exp_check_ops(exp);
502 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
503 CERROR("%s: no %s operation\n",
504 (exp)->exp_obd->obd_name, __func__);
507 EXP_COUNTER_INCREMENT(exp, get_info);
509 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
513 static inline int obd_set_info_async(const struct lu_env *env,
514 struct obd_export *exp,
515 __u32 keylen, void *key,
516 __u32 vallen, void *val,
517 struct ptlrpc_request_set *set)
522 rc = exp_check_ops(exp);
526 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
527 CERROR("%s: no %s operation\n",
528 (exp)->exp_obd->obd_name, __func__);
531 EXP_COUNTER_INCREMENT(exp, set_info_async);
533 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
539 * obd-lu integration.
541 * Functionality is being moved into new lu_device-based layering, but some
542 * pieces of configuration process are still based on obd devices.
544 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
545 * subsume ->o_setup() methods of obd devices they replace. The same for
546 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
547 * result, obd_setup() and obd_process_config() branch and call one XOR
550 * Yet neither lu_device_type_operations::ldto_device_fini() nor
551 * lu_device_type_operations::ldto_device_free() fully implement the
552 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
553 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
555 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
558 struct lu_device_type *ldt = obd->obd_type->typ_lu;
564 struct lu_context session_ctx;
566 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
567 session_ctx.lc_thread = NULL;
568 lu_context_enter(&session_ctx);
570 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
572 env.le_ses = &session_ctx;
573 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
582 lu_context_exit(&session_ctx);
583 lu_context_fini(&session_ctx);
586 if (!obd->obd_type->typ_dt_ops->o_setup) {
587 CERROR("%s: no %s operation\n", obd->obd_name,
591 OBD_COUNTER_INCREMENT(obd, setup);
592 rc = OBP(obd, setup)(obd, cfg);
597 static inline int obd_precleanup(struct obd_device *obd)
600 struct lu_device_type *ldt = obd->obd_type->typ_lu;
601 struct lu_device *d = obd->obd_lu_dev;
605 if (ldt != NULL && d != NULL) {
608 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
610 ldt->ldt_ops->ldto_device_fini(&env, d);
615 if (!obd->obd_type->typ_dt_ops->o_precleanup)
618 OBD_COUNTER_INCREMENT(obd, precleanup);
620 rc = OBP(obd, precleanup)(obd);
624 static inline int obd_cleanup(struct obd_device *obd)
627 struct lu_device_type *ldt = obd->obd_type->typ_lu;
628 struct lu_device *d = obd->obd_lu_dev;
631 if (ldt != NULL && d != NULL) {
634 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
636 ldt->ldt_ops->ldto_device_free(&env, d);
638 obd->obd_lu_dev = NULL;
641 if (!obd->obd_type->typ_dt_ops->o_cleanup)
644 OBD_COUNTER_INCREMENT(obd, cleanup);
646 rc = OBP(obd, cleanup)(obd);
650 static inline void obd_cleanup_client_import(struct obd_device *obd)
654 /* If we set up but never connected, the
655 client import will not have been cleaned. */
656 down_write(&obd->u.cli.cl_sem);
657 if (obd->u.cli.cl_import) {
658 struct obd_import *imp;
659 imp = obd->u.cli.cl_import;
660 CDEBUG(D_CONFIG, "%s: client import never connected\n",
662 ptlrpc_invalidate_import(imp);
663 client_destroy_import(imp);
664 obd->u.cli.cl_import = NULL;
666 up_write(&obd->u.cli.cl_sem);
671 static inline int obd_process_config(struct obd_device *obd, int datalen,
675 struct lu_device_type *ldt = obd->obd_type->typ_lu;
676 struct lu_device *d = obd->obd_lu_dev;
680 obd->obd_process_conf = 1;
681 if (ldt != NULL && d != NULL) {
684 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
686 rc = d->ld_ops->ldo_process_config(&env, d, data);
690 if (!obd->obd_type->typ_dt_ops->o_process_config) {
691 CERROR("%s: no %s operation\n",
692 obd->obd_name, __func__);
695 rc = OBP(obd, process_config)(obd, datalen, data);
697 OBD_COUNTER_INCREMENT(obd, process_config);
698 obd->obd_process_conf = 0;
703 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
709 rc = exp_check_ops(exp);
713 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
714 CERROR("%s: no %s operation\n",
715 (exp)->exp_obd->obd_name, __func__);
718 EXP_COUNTER_INCREMENT(exp, create);
720 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
724 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
730 rc = exp_check_ops(exp);
734 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
735 CERROR("%s: no %s operation\n",
736 (exp)->exp_obd->obd_name, __func__);
739 EXP_COUNTER_INCREMENT(exp, destroy);
741 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
745 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
751 rc = exp_check_ops(exp);
755 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
756 CERROR("%s: no %s operation\n",
757 (exp)->exp_obd->obd_name, __func__);
760 EXP_COUNTER_INCREMENT(exp, getattr);
761 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
766 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
772 rc = exp_check_ops(exp);
776 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
777 CERROR("%s: no %s operation\n",
778 (exp)->exp_obd->obd_name, __func__);
781 EXP_COUNTER_INCREMENT(exp, setattr);
782 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
787 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
790 struct obd_device *obd = imp->imp_obd;
794 OBD_CHECK_DEV_ACTIVE(obd);
795 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
796 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
799 OBD_COUNTER_INCREMENT(obd, add_conn);
801 rc = OBP(obd, add_conn)(imp, uuid, priority);
805 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
807 struct obd_device *obd = imp->imp_obd;
811 OBD_CHECK_DEV_ACTIVE(obd);
812 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
813 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
816 OBD_COUNTER_INCREMENT(obd, del_conn);
818 rc = OBP(obd, del_conn)(imp, uuid);
822 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
824 struct obd_uuid *uuid;
827 if (!exp->exp_obd->obd_type ||
828 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
831 EXP_COUNTER_INCREMENT(exp, get_uuid);
833 uuid = OBP(exp->exp_obd, get_uuid)(exp);
837 /** Create a new /a exp on device /a obd for the uuid /a cluuid
838 * @param exp New export handle
839 * @param d Connect data, supported flags are set, flags also understood
840 * by obd are returned.
842 static inline int obd_connect(const struct lu_env *env,
843 struct obd_export **exp,struct obd_device *obd,
844 struct obd_uuid *cluuid,
845 struct obd_connect_data *data,
849 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
853 OBD_CHECK_DEV_ACTIVE(obd);
854 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
855 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
858 OBD_COUNTER_INCREMENT(obd, connect);
860 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
861 /* check that only subset is granted */
862 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
863 data->ocd_connect_flags));
867 static inline int obd_reconnect(const struct lu_env *env,
868 struct obd_export *exp,
869 struct obd_device *obd,
870 struct obd_uuid *cluuid,
871 struct obd_connect_data *d,
875 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
880 OBD_CHECK_DEV_ACTIVE(obd);
881 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
884 OBD_COUNTER_INCREMENT(obd, reconnect);
886 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
887 /* check that only subset is granted */
888 LASSERT(ergo(d != NULL,
889 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
893 static inline int obd_disconnect(struct obd_export *exp)
897 rc = exp_check_ops(exp);
901 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
902 CERROR("%s: no %s operation\n",
903 (exp)->exp_obd->obd_name, __func__);
906 EXP_COUNTER_INCREMENT(exp, disconnect);
908 rc = OBP(exp->exp_obd, disconnect)(exp);
912 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
913 enum lu_cli_type type)
918 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
920 OBD_COUNTER_INCREMENT(obd, fid_init);
922 rc = OBP(obd, fid_init)(obd, exp, type);
926 static inline int obd_fid_fini(struct obd_device *obd)
930 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
932 OBD_COUNTER_INCREMENT(obd, fid_fini);
934 rc = OBP(obd, fid_fini)(obd);
938 static inline int obd_fid_alloc(const struct lu_env *env,
939 struct obd_export *exp,
941 struct md_op_data *op_data)
945 rc = exp_check_ops(exp);
949 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
950 CERROR("%s: no %s operation\n",
951 (exp)->exp_obd->obd_name, __func__);
954 EXP_COUNTER_INCREMENT(exp, fid_alloc);
956 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
960 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
965 if (!exp->exp_obd->obd_type ||
966 !exp->exp_obd->obd_type->typ_dt_ops->o_ping)
969 EXP_COUNTER_INCREMENT(exp, ping);
971 rc = OBP(exp->exp_obd, ping)(env, exp);
975 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
980 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
981 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
984 OBD_COUNTER_INCREMENT(obd, pool_new);
986 rc = OBP(obd, pool_new)(obd, poolname);
990 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
994 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
995 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
998 OBD_COUNTER_INCREMENT(obd, pool_del);
1000 rc = OBP(obd, pool_del)(obd, poolname);
1004 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1010 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1011 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1012 RETURN(-EOPNOTSUPP);
1014 OBD_COUNTER_INCREMENT(obd, pool_add);
1016 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1020 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1026 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1027 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1028 RETURN(-EOPNOTSUPP);
1030 OBD_COUNTER_INCREMENT(obd, pool_rem);
1032 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1036 static inline void obd_getref(struct obd_device *obd)
1039 if (obd->obd_type && OBP(obd, getref)) {
1040 OBD_COUNTER_INCREMENT(obd, getref);
1041 OBP(obd, getref)(obd);
1046 static inline void obd_putref(struct obd_device *obd)
1049 if (obd->obd_type && OBP(obd, putref)) {
1050 OBD_COUNTER_INCREMENT(obd, putref);
1051 OBP(obd, putref)(obd);
1056 static inline int obd_init_export(struct obd_export *exp)
1061 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1062 OBP((exp)->exp_obd, init_export))
1063 rc = OBP(exp->exp_obd, init_export)(exp);
1067 static inline int obd_destroy_export(struct obd_export *exp)
1070 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1071 OBP(exp->exp_obd, destroy_export))
1072 OBP(exp->exp_obd, destroy_export)(exp);
1076 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1077 * If the cache is older than @max_age we will get a new value from the
1078 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1079 static inline int obd_statfs_async(struct obd_export *exp,
1080 struct obd_info *oinfo,
1082 struct ptlrpc_request_set *rqset)
1085 struct obd_device *obd;
1089 if (exp == NULL || exp->exp_obd == NULL)
1093 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1094 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1095 RETURN(-EOPNOTSUPP);
1097 OBD_COUNTER_INCREMENT(obd, statfs);
1099 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1100 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1101 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1102 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1105 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1106 obd->obd_name, &obd->obd_osfs,
1107 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1108 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1109 spin_lock(&obd->obd_osfs_lock);
1110 memcpy(oinfo->oi_osfs, &obd->obd_osfs,
1111 sizeof(*oinfo->oi_osfs));
1112 spin_unlock(&obd->obd_osfs_lock);
1113 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1114 if (oinfo->oi_cb_up)
1115 oinfo->oi_cb_up(oinfo, 0);
1120 static inline int obd_statfs_rqset(struct obd_export *exp,
1121 struct obd_statfs *osfs, __u64 max_age,
1124 struct ptlrpc_request_set *set = NULL;
1125 struct obd_info oinfo = {
1133 set = ptlrpc_prep_set();
1137 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1139 rc = ptlrpc_set_wait(set);
1141 ptlrpc_set_destroy(set);
1146 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1147 * If the cache is older than @max_age we will get a new value from the
1148 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1149 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1150 struct obd_statfs *osfs, __u64 max_age,
1154 struct obd_device *obd = exp->exp_obd;
1160 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1161 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1162 RETURN(-EOPNOTSUPP);
1164 OBD_COUNTER_INCREMENT(obd, statfs);
1166 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1167 obd->obd_osfs_age, max_age);
1168 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1169 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1171 spin_lock(&obd->obd_osfs_lock);
1172 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1173 obd->obd_osfs_age = cfs_time_current_64();
1174 spin_unlock(&obd->obd_osfs_lock);
1177 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1178 " objects %llu/%llu\n",
1179 obd->obd_name, &obd->obd_osfs,
1180 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1181 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1182 spin_lock(&obd->obd_osfs_lock);
1183 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1184 spin_unlock(&obd->obd_osfs_lock);
1189 static inline int obd_preprw(const struct lu_env *env, int cmd,
1190 struct obd_export *exp, struct obdo *oa,
1191 int objcount, struct obd_ioobj *obj,
1192 struct niobuf_remote *remote, int *pages,
1193 struct niobuf_local *local)
1199 rc = exp_check_ops(exp);
1203 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1204 CERROR("%s: no %s operation\n",
1205 (exp)->exp_obd->obd_name, __func__);
1208 EXP_COUNTER_INCREMENT(exp, preprw);
1209 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1215 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1216 struct obd_export *exp, struct obdo *oa,
1217 int objcount, struct obd_ioobj *obj,
1218 struct niobuf_remote *rnb, int pages,
1219 struct niobuf_local *local, int rc)
1223 rc = exp_check_ops(exp);
1227 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1228 CERROR("%s: no %s operation\n",
1229 (exp)->exp_obd->obd_name, __func__);
1232 EXP_COUNTER_INCREMENT(exp, commitrw);
1233 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1234 rnb, pages, local, rc);
1239 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1240 int len, void *karg, void __user *uarg)
1245 rc = exp_check_ops(exp);
1249 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1250 CERROR("%s: no %s operation\n",
1251 (exp)->exp_obd->obd_name, __func__);
1254 EXP_COUNTER_INCREMENT(exp, iocontrol);
1256 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1260 static inline void obd_import_event(struct obd_device *obd,
1261 struct obd_import *imp,
1262 enum obd_import_event event)
1266 CERROR("NULL device\n");
1270 if (obd->obd_set_up && OBP(obd, import_event)) {
1271 OBD_COUNTER_INCREMENT(obd, import_event);
1272 OBP(obd, import_event)(obd, imp, event);
1277 static inline int obd_notify(struct obd_device *obd,
1278 struct obd_device *watched,
1279 enum obd_notify_event ev)
1285 if (!obd->obd_set_up) {
1286 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1290 if (!OBP(obd, notify)) {
1291 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1295 OBD_COUNTER_INCREMENT(obd, notify);
1296 rc = OBP(obd, notify)(obd, watched, ev);
1301 static inline int obd_notify_observer(struct obd_device *observer,
1302 struct obd_device *observed,
1303 enum obd_notify_event ev)
1307 struct obd_notify_upcall *onu;
1309 if (observer->obd_observer)
1310 rc = obd_notify(observer->obd_observer, observed, ev);
1313 * Also, call non-obd listener, if any
1315 onu = &observer->obd_upcall;
1316 if (onu->onu_upcall != NULL)
1317 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1319 return rc ? rc : rc2;
1322 static inline int obd_quotactl(struct obd_export *exp,
1323 struct obd_quotactl *oqctl)
1328 rc = exp_check_ops(exp);
1332 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1333 CERROR("%s: no %s operation\n",
1334 (exp)->exp_obd->obd_name, __func__);
1337 EXP_COUNTER_INCREMENT(exp, quotactl);
1339 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1343 static inline int obd_health_check(const struct lu_env *env,
1344 struct obd_device *obd)
1346 /* returns: 0 on healthy
1347 * >0 on unhealthy + reason code/flag
1348 * however the only suppored reason == 1 right now
1349 * We'll need to define some better reasons
1350 * or flags in the future.
1357 /* NULL method is normal here */
1358 if (obd == NULL || !obd->obd_type) {
1359 CERROR("cleaned up obd\n");
1360 RETURN(-EOPNOTSUPP);
1362 if (!obd->obd_set_up || obd->obd_stopping)
1364 if (!OBP(obd, health_check))
1367 rc = OBP(obd, health_check)(env, obd);
1371 static inline int obd_register_observer(struct obd_device *obd,
1372 struct obd_device *observer)
1376 down_write(&obd->obd_observer_link_sem);
1377 if (obd->obd_observer && observer) {
1378 up_write(&obd->obd_observer_link_sem);
1381 obd->obd_observer = observer;
1382 up_write(&obd->obd_observer_link_sem);
1386 /* metadata helpers */
1387 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1393 rc = exp_check_ops(exp);
1396 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1397 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1402 static inline int md_getattr(struct obd_export *exp,
1403 struct md_op_data *op_data,
1404 struct ptlrpc_request **request)
1409 rc = exp_check_ops(exp);
1412 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1413 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1417 static inline int md_null_inode(struct obd_export *exp,
1418 const struct lu_fid *fid)
1422 rc = exp_check_ops(exp);
1425 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1426 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1430 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1431 struct md_open_data *mod,
1432 struct ptlrpc_request **request)
1436 rc = exp_check_ops(exp);
1439 EXP_MD_COUNTER_INCREMENT(exp, close);
1440 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1444 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1445 const void *data, size_t datalen, umode_t mode,
1446 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1447 __u64 rdev, struct ptlrpc_request **request)
1451 rc = exp_check_ops(exp);
1454 EXP_MD_COUNTER_INCREMENT(exp, create);
1455 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1456 uid, gid, cap_effective, rdev, request);
1460 static inline int md_enqueue(struct obd_export *exp,
1461 struct ldlm_enqueue_info *einfo,
1462 const union ldlm_policy_data *policy,
1463 struct md_op_data *op_data,
1464 struct lustre_handle *lockh,
1465 __u64 extra_lock_flags)
1469 rc = exp_check_ops(exp);
1472 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1473 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1478 static inline int md_getattr_name(struct obd_export *exp,
1479 struct md_op_data *op_data,
1480 struct ptlrpc_request **request)
1484 rc = exp_check_ops(exp);
1487 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1488 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1492 static inline int md_intent_lock(struct obd_export *exp,
1493 struct md_op_data *op_data,
1494 struct lookup_intent *it,
1495 struct ptlrpc_request **reqp,
1496 ldlm_blocking_callback cb_blocking,
1497 __u64 extra_lock_flags)
1501 rc = exp_check_ops(exp);
1504 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1505 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1510 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1511 struct ptlrpc_request **request)
1515 rc = exp_check_ops(exp);
1518 EXP_MD_COUNTER_INCREMENT(exp, link);
1519 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1523 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1524 const char *old, size_t oldlen, const char *new,
1525 size_t newlen, struct ptlrpc_request **request)
1529 rc = exp_check_ops(exp);
1533 EXP_MD_COUNTER_INCREMENT(exp, rename);
1534 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1539 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1540 void *ea, size_t ealen,
1541 struct ptlrpc_request **request)
1545 rc = exp_check_ops(exp);
1549 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1550 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1554 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1555 struct ptlrpc_request **request)
1560 rc = exp_check_ops(exp);
1564 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1565 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1570 static inline int md_read_page(struct obd_export *exp,
1571 struct md_op_data *op_data,
1572 struct md_callback *cb_op,
1574 struct page **ppage)
1578 rc = exp_check_ops(exp);
1582 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1583 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1588 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1589 struct ptlrpc_request **request)
1593 rc = exp_check_ops(exp);
1597 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1598 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1602 static inline int md_get_lustre_md(struct obd_export *exp,
1603 struct ptlrpc_request *req,
1604 struct obd_export *dt_exp,
1605 struct obd_export *md_exp,
1606 struct lustre_md *md)
1610 rc = exp_check_ops(exp);
1614 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1615 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1618 static inline int md_free_lustre_md(struct obd_export *exp,
1619 struct lustre_md *md)
1623 rc = exp_check_ops(exp);
1626 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1627 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1630 static inline int md_merge_attr(struct obd_export *exp,
1631 const struct lmv_stripe_md *lsm,
1632 struct cl_attr *attr,
1633 ldlm_blocking_callback cb)
1637 rc = exp_check_ops(exp);
1640 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1641 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1644 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1645 u64 valid, const char *name,
1646 const char *input, int input_size,
1647 int output_size, int flags, __u32 suppgid,
1648 struct ptlrpc_request **request)
1653 rc = exp_check_ops(exp);
1656 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1657 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1658 input_size, output_size, flags,
1662 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1663 u64 valid, const char *name,
1664 const char *input, int input_size,
1665 int output_size, int flags,
1666 struct ptlrpc_request **request)
1670 rc = exp_check_ops(exp);
1673 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1674 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1675 input_size, output_size, flags,
1679 static inline int md_set_open_replay_data(struct obd_export *exp,
1680 struct obd_client_handle *och,
1681 struct lookup_intent *it)
1685 rc = exp_check_ops(exp);
1688 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1689 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1692 static inline int md_clear_open_replay_data(struct obd_export *exp,
1693 struct obd_client_handle *och)
1697 rc = exp_check_ops(exp);
1700 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1701 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1704 static inline int md_set_lock_data(struct obd_export *exp,
1705 const struct lustre_handle *lockh,
1706 void *data, __u64 *bits)
1710 rc = exp_check_ops(exp);
1713 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1714 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1718 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1719 union ldlm_policy_data *policy, enum ldlm_mode mode,
1720 enum ldlm_cancel_flags cancel_flags, void *opaque)
1725 rc = exp_check_ops(exp);
1728 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1730 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1731 cancel_flags, opaque);
1735 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1736 const struct lu_fid *fid,
1737 enum ldlm_type type,
1738 union ldlm_policy_data *policy,
1739 enum ldlm_mode mode,
1740 struct lustre_handle *lockh)
1744 rc = exp_check_ops(exp);
1747 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1748 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1749 policy, mode, lockh));
1752 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1757 rc = exp_check_ops(exp);
1760 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1761 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1764 static inline int md_intent_getattr_async(struct obd_export *exp,
1765 struct md_enqueue_info *minfo)
1769 rc = exp_check_ops(exp);
1772 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1773 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1777 static inline int md_revalidate_lock(struct obd_export *exp,
1778 struct lookup_intent *it,
1779 struct lu_fid *fid, __u64 *bits)
1783 rc = exp_check_ops(exp);
1786 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1787 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1791 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1792 const struct lmv_stripe_md *lsm,
1793 const char *name, int namelen,
1798 rc = exp_check_ops(exp);
1801 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1802 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1807 /* Unpack an MD struct from disk to in-memory format.
1808 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1810 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1811 * If *plsm == NULL then it will be allocated.
1813 static inline int md_unpackmd(struct obd_export *exp,
1814 struct lmv_stripe_md **plsm,
1815 const union lmv_mds_md *lmm, size_t lmm_size)
1819 rc = exp_check_ops(exp);
1822 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1823 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1827 /* OBD Metadata Support */
1829 extern int obd_init_caches(void);
1830 extern void obd_cleanup_caches(void);
1832 /* support routines */
1833 extern struct kmem_cache *obdo_cachep;
1835 #define OBDO_ALLOC(ptr) \
1837 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1840 #define OBDO_FREE(ptr) \
1842 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1846 typedef int (*register_lwp_cb)(void *data);
1848 struct lwp_register_item {
1849 struct obd_export **lri_exp;
1850 register_lwp_cb lri_cb_func;
1852 struct list_head lri_list;
1854 char lri_name[MTI_NAME_MAXLEN];
1857 /* I'm as embarrassed about this as you are.
1859 * <shaver> // XXX do not look into _superhack with remaining eye
1860 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1861 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1864 #ifdef HAVE_SERVER_SUPPORT
1865 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1866 register_lwp_cb cb_func, void *cb_data);
1867 void lustre_deregister_lwp_item(struct obd_export **exp);
1868 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1869 void lustre_notify_lwp_list(struct obd_export *exp);
1870 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1871 #endif /* HAVE_SERVER_SUPPORT */
1872 int lustre_register_fs(void);
1873 int lustre_unregister_fs(void);
1874 int lustre_check_exclusion(struct super_block *sb, char *svname);
1877 extern int obd_sysctl_init(void);
1878 extern void obd_sysctl_clean(void);
1880 typedef __u8 class_uuid_t[16];
1881 static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
1883 snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-"
1884 "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1885 uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9],
1886 uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]);
1890 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1891 int class_add_uuid(const char *uuid, __u64 nid);
1892 int class_del_uuid (const char *uuid);
1893 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1896 extern char obd_jobid_node[];
1899 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1903 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1904 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1906 /* root squash info */
1907 struct rw_semaphore;
1908 struct root_squash_info {
1911 struct list_head rsi_nosquash_nids;
1912 struct rw_semaphore rsi_sem;
1915 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1917 /* linux-module.c */
1918 extern struct miscdevice obd_psdev;
1919 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1920 int class_procfs_init(void);
1921 int class_procfs_clean(void);
1923 #endif /* __LINUX_OBD_CLASS_H */