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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 #include <obd_support.h>
41 #include <lustre_import.h>
42 #include <lustre_net.h>
44 #include <lustre_lib.h>
45 #include <lustre/lustre_idl.h>
46 #include <lprocfs_status.h>
48 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
49 * and resends for avoid deadlocks */
50 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
52 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
53 * instead of a specific set. This
54 * means that we cannot rely on the set
55 * interpret routine to be called.
56 * lov_statfs_fini() must thus be called
57 * by the request interpret routine */
58 #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
59 * information from MDT0. */
61 /* OBD Device Declarations */
62 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
63 extern struct list_head obd_types;
64 extern spinlock_t obd_types_lock;
65 extern rwlock_t obd_dev_lock;
67 /* OBD Operations Declarations */
68 extern struct obd_device *class_conn2obd(struct lustre_handle *);
69 extern struct obd_device *class_exp2obd(struct obd_export *);
70 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
71 extern int lustre_get_jobid(char *jobid);
73 struct lu_device_type;
76 struct obd_export *class_conn2export(struct lustre_handle *);
77 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
78 struct lprocfs_vars *module_vars,
79 const char *nm, struct lu_device_type *ldt);
80 int class_unregister_type(const char *nm);
82 struct obd_device *class_newdev(const char *type_name, const char *name);
83 void class_release_dev(struct obd_device *obd);
85 int class_name2dev(const char *name);
86 struct obd_device *class_name2obd(const char *name);
87 int class_uuid2dev(struct obd_uuid *uuid);
88 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
89 void class_obd_list(void);
90 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
91 const char * typ_name,
92 struct obd_uuid *grp_uuid);
93 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
95 struct obd_device * class_num2obd(int num);
96 int get_devices_count(void);
98 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
100 char *obd_export_nid2str(struct obd_export *exp);
102 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
103 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
104 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
106 int obd_zombie_impexp_init(void);
107 void obd_zombie_impexp_stop(void);
108 void obd_zombie_impexp_cull(void);
109 void obd_zombie_barrier(void);
110 void obd_exports_barrier(struct obd_device *obd);
111 int kuc_len(int payload_len);
112 struct kuc_hdr * kuc_ptr(void *p);
113 int kuc_ispayload(void *p);
114 void *kuc_alloc(int payload_len, int transport, int type);
115 void kuc_free(void *p, int payload_len);
116 int obd_get_request_slot(struct client_obd *cli);
117 void obd_put_request_slot(struct client_obd *cli);
118 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
119 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
120 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
121 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
122 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
124 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
125 struct lookup_intent *it);
126 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
127 struct lookup_intent *it, __u16 tag);
131 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
132 struct llog_rec_hdr *, void *);
134 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
135 const char *new_name);
136 int class_process_config(struct lustre_cfg *lcfg);
137 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
138 struct lustre_cfg *lcfg, void *data);
139 int class_attach(struct lustre_cfg *lcfg);
140 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
141 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
142 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
143 struct obd_device *class_incref(struct obd_device *obd,
144 const char *scope, const void *source);
145 void class_decref(struct obd_device *obd,
146 const char *scope, const void *source);
147 void dump_exports(struct obd_device *obd, int locks);
148 int class_config_llog_handler(const struct lu_env *env,
149 struct llog_handle *handle,
150 struct llog_rec_hdr *rec, void *data);
151 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
152 int class_add_uuid(const char *uuid, __u64 nid);
154 #define CFG_F_START 0x01 /* Set when we start updating from a log */
155 #define CFG_F_MARKER 0x02 /* We are within a maker */
156 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
157 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
158 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
160 /* Passed as data param to class_config_parse_llog */
161 struct config_llog_instance {
164 struct super_block *cfg_sb;
165 struct obd_uuid cfg_uuid;
166 llog_cb_t cfg_callback;
167 int cfg_last_idx; /* for partial llog processing */
171 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
172 char *name, struct config_llog_instance *cfg);
173 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
174 char *name, struct config_llog_instance *cfg);
178 CONFIG_T_SPTLRPC = 1,
179 CONFIG_T_RECOVER = 2,
184 #define PARAMS_FILENAME "params"
185 #define LCTL_UPCALL "lctl"
187 /* list of active configuration logs */
188 struct config_llog_data {
189 struct ldlm_res_id cld_resid;
190 struct config_llog_instance cld_cfg;
191 struct list_head cld_list_chain;
192 atomic_t cld_refcount;
193 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
194 struct config_llog_data *cld_params; /* common parameters log */
195 struct config_llog_data *cld_recover;/* imperative recover log */
196 struct obd_export *cld_mgcexp;
197 struct mutex cld_lock;
199 unsigned int cld_stopping:1, /* we were told to stop
201 cld_lostlock:1; /* lock not requeued */
205 struct lustre_profile {
206 struct list_head lp_list;
212 struct lustre_profile *class_get_profile(const char * prof);
213 void class_del_profile(const char *prof);
214 void class_del_profiles(void);
216 #if LUSTRE_TRACKS_LOCK_EXP_REFS
218 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
219 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
220 extern void (*class_export_dump_hook)(struct obd_export *);
224 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
225 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
229 #define class_export_rpc_inc(exp) \
231 atomic_inc(&(exp)->exp_rpc_count); \
232 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
233 (exp), atomic_read(&(exp)->exp_rpc_count)); \
236 #define class_export_rpc_dec(exp) \
238 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
239 atomic_dec(&(exp)->exp_rpc_count); \
240 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
241 (exp), atomic_read(&(exp)->exp_rpc_count)); \
244 #define class_export_lock_get(exp, lock) \
246 atomic_inc(&(exp)->exp_locks_count); \
247 __class_export_add_lock_ref(exp, lock); \
248 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
249 (exp), atomic_read(&(exp)->exp_locks_count)); \
250 class_export_get(exp); \
253 #define class_export_lock_put(exp, lock) \
255 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
256 atomic_dec(&(exp)->exp_locks_count); \
257 __class_export_del_lock_ref(exp, lock); \
258 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
259 (exp), atomic_read(&(exp)->exp_locks_count)); \
260 class_export_put(exp); \
263 #define class_export_cb_get(exp) \
265 atomic_inc(&(exp)->exp_cb_count); \
266 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
267 (exp), atomic_read(&(exp)->exp_cb_count)); \
268 class_export_get(exp); \
271 #define class_export_cb_put(exp) \
273 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
274 atomic_dec(&(exp)->exp_cb_count); \
275 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
276 (exp), atomic_read(&(exp)->exp_cb_count)); \
277 class_export_put(exp); \
281 struct obd_export *class_export_get(struct obd_export *exp);
282 void class_export_put(struct obd_export *exp);
283 struct obd_export *class_new_export(struct obd_device *obddev,
284 struct obd_uuid *cluuid);
285 void class_unlink_export(struct obd_export *exp);
287 struct obd_import *class_import_get(struct obd_import *);
288 void class_import_put(struct obd_import *);
289 struct obd_import *class_new_import(struct obd_device *obd);
290 void class_destroy_import(struct obd_import *exp);
292 struct obd_type *class_search_type(const char *name);
293 struct obd_type *class_get_type(const char *name);
294 void class_put_type(struct obd_type *type);
295 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
296 struct obd_uuid *cluuid);
297 int class_disconnect(struct obd_export *exp);
298 void class_fail_export(struct obd_export *exp);
299 int class_connected_export(struct obd_export *exp);
300 void class_disconnect_exports(struct obd_device *obddev);
301 int class_manual_cleanup(struct obd_device *obd);
302 void class_disconnect_stale_exports(struct obd_device *,
303 int (*test_export)(struct obd_export *));
304 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
306 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
307 (obd->obd_force ? OBD_OPT_FORCE : 0) |
308 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
312 #ifdef HAVE_SERVER_SUPPORT
313 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
315 LASSERT(exp->exp_obd);
316 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
318 return exp->exp_obd->u.obt.obt_lut;
321 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
323 LASSERT(obd->u.obt.obt_lut);
324 return &obd->u.obt.obt_lut->lut_lsd;
332 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
333 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
335 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
336 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
338 #define OBT(dev) (dev)->obd_type
339 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
340 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
341 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
343 /* Ensure obd_setup: used for cleanup which must be called
344 while obd is stopping */
345 #define OBD_CHECK_DEV(obd) \
348 CERROR("NULL device\n"); \
353 /* ensure obd_setup and !obd_stopping */
354 #define OBD_CHECK_DEV_ACTIVE(obd) \
356 OBD_CHECK_DEV(obd); \
357 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
358 CERROR("Device %d not setup\n", \
365 #ifdef CONFIG_PROC_FS
366 #define OBD_COUNTER_OFFSET(op) \
367 ((offsetof(struct obd_ops, o_ ## op) - \
368 offsetof(struct obd_ops, o_iocontrol)) \
369 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
371 /* The '- 1' below is for o_owner. */
372 #define NUM_OBD_STATS \
373 (sizeof(struct obd_ops) / \
374 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
376 #define OBD_COUNTER_INCREMENT(obd, op) \
377 lprocfs_counter_incr((obd)->obd_stats, \
378 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
380 #define EXP_COUNTER_INCREMENT(exp, op) \
383 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
384 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
385 if ((exp)->exp_obd->obd_uses_nid_stats && \
386 (exp)->exp_nid_stats != NULL) \
387 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
391 #define _MD_COUNTER_OFFSET(m_op) \
392 ((offsetof(struct md_ops, m_op) - \
393 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
394 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
396 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
398 #define NUM_MD_STATS \
399 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
400 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
402 /* Note that we only increment md counters for ops whose offset is less
403 * than NUM_MD_STATS. This is explained in a comment in the definition
404 * of struct md_ops. */
405 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
407 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
408 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
409 (exp)->exp_obd->obd_md_cntr_base + \
410 MD_COUNTER_OFFSET(op)); \
414 #define OBD_COUNTER_OFFSET(op)
415 #define OBD_COUNTER_INCREMENT(obd, op)
416 #define EXP_COUNTER_INCREMENT(exp, op)
417 #define EXP_MD_COUNTER_INCREMENT(exp, op)
420 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
422 /* Always add in ldlm_stats */
423 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
424 ,LPROCFS_STATS_FLAG_NOPERCPU);
425 if (tmp->nid_ldlm_stats == NULL)
428 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
430 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
431 tmp->nid_ldlm_stats);
434 #define EXP_CHECK_MD_OP(exp, op) \
436 if ((exp) == NULL) { \
437 CERROR("obd_" #op ": NULL export\n"); \
440 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
441 CERROR("obd_" #op ": cleaned up obd\n"); \
442 RETURN(-EOPNOTSUPP); \
444 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
445 CERROR("obd_" #op ": dev %s/%d no operation\n", \
446 (exp)->exp_obd->obd_name, \
447 (exp)->exp_obd->obd_minor); \
448 RETURN(-EOPNOTSUPP); \
453 #define OBD_CHECK_DT_OP(obd, op, err) \
455 if (!OBT(obd) || !OBP((obd), op)) { \
457 CERROR("obd_" #op ": dev %d no operation\n", \
463 #define EXP_CHECK_DT_OP(exp, op) \
465 if ((exp) == NULL) { \
466 CERROR("obd_" #op ": NULL export\n"); \
469 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
470 CERROR("obd_" #op ": cleaned up obd\n"); \
471 RETURN(-EOPNOTSUPP); \
473 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
474 CERROR("obd_" #op ": dev %d no operation\n", \
475 (exp)->exp_obd->obd_minor); \
476 RETURN(-EOPNOTSUPP); \
480 #define CTXT_CHECK_OP(ctxt, op, err) \
482 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
484 CERROR("lop_" #op ": dev %d no operation\n", \
485 ctxt->loc_obd->obd_minor); \
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 EXP_CHECK_DT_OP(exp, get_info);
503 EXP_COUNTER_INCREMENT(exp, get_info);
505 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
509 static inline int obd_set_info_async(const struct lu_env *env,
510 struct obd_export *exp,
511 __u32 keylen, void *key,
512 __u32 vallen, void *val,
513 struct ptlrpc_request_set *set)
518 EXP_CHECK_DT_OP(exp, set_info_async);
519 EXP_COUNTER_INCREMENT(exp, set_info_async);
521 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
527 * obd-lu integration.
529 * Functionality is being moved into new lu_device-based layering, but some
530 * pieces of configuration process are still based on obd devices.
532 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
533 * subsume ->o_setup() methods of obd devices they replace. The same for
534 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
535 * result, obd_setup() and obd_process_config() branch and call one XOR
538 * Yet neither lu_device_type_operations::ldto_device_fini() nor
539 * lu_device_type_operations::ldto_device_free() fully implement the
540 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
541 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
544 #define DECLARE_LU_VARS(ldt, d) \
545 struct lu_device_type *ldt; \
548 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
551 DECLARE_LU_VARS(ldt, d);
554 ldt = obd->obd_type->typ_lu;
556 struct lu_context session_ctx;
558 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
559 session_ctx.lc_thread = NULL;
560 lu_context_enter(&session_ctx);
562 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
564 env.le_ses = &session_ctx;
565 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
574 lu_context_exit(&session_ctx);
575 lu_context_fini(&session_ctx);
578 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
579 OBD_COUNTER_INCREMENT(obd, setup);
580 rc = OBP(obd, setup)(obd, cfg);
585 static inline int obd_precleanup(struct obd_device *obd,
586 enum obd_cleanup_stage cleanup_stage)
589 DECLARE_LU_VARS(ldt, d);
593 ldt = obd->obd_type->typ_lu;
595 if (ldt != NULL && d != NULL) {
596 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
599 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
601 ldt->ldt_ops->ldto_device_fini(&env, d);
606 OBD_CHECK_DT_OP(obd, precleanup, 0);
607 OBD_COUNTER_INCREMENT(obd, precleanup);
609 rc = OBP(obd, precleanup)(obd, cleanup_stage);
613 static inline int obd_cleanup(struct obd_device *obd)
616 DECLARE_LU_VARS(ldt, d);
621 ldt = obd->obd_type->typ_lu;
623 if (ldt != NULL && d != NULL) {
626 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
628 ldt->ldt_ops->ldto_device_free(&env, d);
630 obd->obd_lu_dev = NULL;
633 OBD_CHECK_DT_OP(obd, cleanup, 0);
634 OBD_COUNTER_INCREMENT(obd, cleanup);
636 rc = OBP(obd, cleanup)(obd);
640 static inline void obd_cleanup_client_import(struct obd_device *obd)
644 /* If we set up but never connected, the
645 client import will not have been cleaned. */
646 down_write(&obd->u.cli.cl_sem);
647 if (obd->u.cli.cl_import) {
648 struct obd_import *imp;
649 imp = obd->u.cli.cl_import;
650 CDEBUG(D_CONFIG, "%s: client import never connected\n",
652 ptlrpc_invalidate_import(imp);
653 if (imp->imp_rq_pool) {
654 ptlrpc_free_rq_pool(imp->imp_rq_pool);
655 imp->imp_rq_pool = NULL;
657 client_destroy_import(imp);
658 obd->u.cli.cl_import = NULL;
660 up_write(&obd->u.cli.cl_sem);
666 obd_process_config(struct obd_device *obd, int datalen, void *data)
669 DECLARE_LU_VARS(ldt, d);
674 obd->obd_process_conf = 1;
675 ldt = obd->obd_type->typ_lu;
677 if (ldt != NULL && d != NULL) {
680 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
682 rc = d->ld_ops->ldo_process_config(&env, d, data);
686 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
687 rc = OBP(obd, process_config)(obd, datalen, data);
689 OBD_COUNTER_INCREMENT(obd, process_config);
690 obd->obd_process_conf = 0;
695 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
701 EXP_CHECK_DT_OP(exp, create);
702 EXP_COUNTER_INCREMENT(exp, create);
704 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
708 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
714 EXP_CHECK_DT_OP(exp, destroy);
715 EXP_COUNTER_INCREMENT(exp, destroy);
717 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
721 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
727 EXP_CHECK_DT_OP(exp, getattr);
728 EXP_COUNTER_INCREMENT(exp, getattr);
729 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
734 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
740 EXP_CHECK_DT_OP(exp, setattr);
741 EXP_COUNTER_INCREMENT(exp, setattr);
742 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
747 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
750 struct obd_device *obd = imp->imp_obd;
754 OBD_CHECK_DEV_ACTIVE(obd);
755 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
756 OBD_COUNTER_INCREMENT(obd, add_conn);
758 rc = OBP(obd, add_conn)(imp, uuid, priority);
762 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
764 struct obd_device *obd = imp->imp_obd;
768 OBD_CHECK_DEV_ACTIVE(obd);
769 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
770 OBD_COUNTER_INCREMENT(obd, del_conn);
772 rc = OBP(obd, del_conn)(imp, uuid);
776 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
778 struct obd_uuid *uuid;
781 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
782 EXP_COUNTER_INCREMENT(exp, get_uuid);
784 uuid = OBP(exp->exp_obd, get_uuid)(exp);
788 /** Create a new /a exp on device /a obd for the uuid /a cluuid
789 * @param exp New export handle
790 * @param d Connect data, supported flags are set, flags also understood
791 * by obd are returned.
793 static inline int obd_connect(const struct lu_env *env,
794 struct obd_export **exp,struct obd_device *obd,
795 struct obd_uuid *cluuid,
796 struct obd_connect_data *data,
800 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
804 OBD_CHECK_DEV_ACTIVE(obd);
805 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
806 OBD_COUNTER_INCREMENT(obd, connect);
808 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
809 /* check that only subset is granted */
810 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
811 data->ocd_connect_flags));
815 static inline int obd_reconnect(const struct lu_env *env,
816 struct obd_export *exp,
817 struct obd_device *obd,
818 struct obd_uuid *cluuid,
819 struct obd_connect_data *d,
823 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
828 OBD_CHECK_DEV_ACTIVE(obd);
829 OBD_CHECK_DT_OP(obd, reconnect, 0);
830 OBD_COUNTER_INCREMENT(obd, reconnect);
832 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
833 /* check that only subset is granted */
834 LASSERT(ergo(d != NULL,
835 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
839 static inline int obd_disconnect(struct obd_export *exp)
844 EXP_CHECK_DT_OP(exp, disconnect);
845 EXP_COUNTER_INCREMENT(exp, disconnect);
847 rc = OBP(exp->exp_obd, disconnect)(exp);
851 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
852 enum lu_cli_type type)
857 OBD_CHECK_DT_OP(obd, fid_init, 0);
858 OBD_COUNTER_INCREMENT(obd, fid_init);
860 rc = OBP(obd, fid_init)(obd, exp, type);
864 static inline int obd_fid_fini(struct obd_device *obd)
869 OBD_CHECK_DT_OP(obd, fid_fini, 0);
870 OBD_COUNTER_INCREMENT(obd, fid_fini);
872 rc = OBP(obd, fid_fini)(obd);
876 static inline int obd_fid_alloc(const struct lu_env *env,
877 struct obd_export *exp,
879 struct md_op_data *op_data)
884 EXP_CHECK_DT_OP(exp, fid_alloc);
885 EXP_COUNTER_INCREMENT(exp, fid_alloc);
887 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
891 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
896 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
897 EXP_COUNTER_INCREMENT(exp, ping);
899 rc = OBP(exp->exp_obd, ping)(env, exp);
903 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
908 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
909 OBD_COUNTER_INCREMENT(obd, pool_new);
911 rc = OBP(obd, pool_new)(obd, poolname);
915 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
920 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
921 OBD_COUNTER_INCREMENT(obd, pool_del);
923 rc = OBP(obd, pool_del)(obd, poolname);
927 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
932 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
933 OBD_COUNTER_INCREMENT(obd, pool_add);
935 rc = OBP(obd, pool_add)(obd, poolname, ostname);
939 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
944 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
945 OBD_COUNTER_INCREMENT(obd, pool_rem);
947 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
951 static inline void obd_getref(struct obd_device *obd)
954 if (OBT(obd) && OBP(obd, getref)) {
955 OBD_COUNTER_INCREMENT(obd, getref);
956 OBP(obd, getref)(obd);
961 static inline void obd_putref(struct obd_device *obd)
964 if (OBT(obd) && OBP(obd, putref)) {
965 OBD_COUNTER_INCREMENT(obd, putref);
966 OBP(obd, putref)(obd);
971 static inline int obd_init_export(struct obd_export *exp)
976 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
977 OBP((exp)->exp_obd, init_export))
978 rc = OBP(exp->exp_obd, init_export)(exp);
982 static inline int obd_destroy_export(struct obd_export *exp)
985 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
986 OBP((exp)->exp_obd, destroy_export))
987 OBP(exp->exp_obd, destroy_export)(exp);
991 /* @max_age is the oldest time in jiffies that we accept using a cached data.
992 * If the cache is older than @max_age we will get a new value from the
993 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
994 static inline int obd_statfs_async(struct obd_export *exp,
995 struct obd_info *oinfo,
997 struct ptlrpc_request_set *rqset)
1000 struct obd_device *obd;
1003 if (exp == NULL || exp->exp_obd == NULL)
1007 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1008 OBD_COUNTER_INCREMENT(obd, statfs);
1010 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1011 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1012 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1013 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1015 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1016 " objects "LPU64"/"LPU64"\n",
1017 obd->obd_name, &obd->obd_osfs,
1018 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1019 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1020 spin_lock(&obd->obd_osfs_lock);
1021 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1022 spin_unlock(&obd->obd_osfs_lock);
1023 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1024 if (oinfo->oi_cb_up)
1025 oinfo->oi_cb_up(oinfo, 0);
1030 static inline int obd_statfs_rqset(struct obd_export *exp,
1031 struct obd_statfs *osfs, __u64 max_age,
1034 struct ptlrpc_request_set *set = NULL;
1035 struct obd_info oinfo = {
1043 set = ptlrpc_prep_set();
1047 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1049 rc = ptlrpc_set_wait(set);
1051 ptlrpc_set_destroy(set);
1056 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1057 * If the cache is older than @max_age we will get a new value from the
1058 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1059 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1060 struct obd_statfs *osfs, __u64 max_age,
1064 struct obd_device *obd = exp->exp_obd;
1070 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1071 OBD_COUNTER_INCREMENT(obd, statfs);
1073 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1074 obd->obd_osfs_age, max_age);
1075 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1076 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1078 spin_lock(&obd->obd_osfs_lock);
1079 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1080 obd->obd_osfs_age = cfs_time_current_64();
1081 spin_unlock(&obd->obd_osfs_lock);
1084 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1085 " objects "LPU64"/"LPU64"\n",
1086 obd->obd_name, &obd->obd_osfs,
1087 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1088 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1089 spin_lock(&obd->obd_osfs_lock);
1090 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1091 spin_unlock(&obd->obd_osfs_lock);
1096 static inline int obd_preprw(const struct lu_env *env, int cmd,
1097 struct obd_export *exp, struct obdo *oa,
1098 int objcount, struct obd_ioobj *obj,
1099 struct niobuf_remote *remote, int *pages,
1100 struct niobuf_local *local)
1105 EXP_CHECK_DT_OP(exp, preprw);
1106 EXP_COUNTER_INCREMENT(exp, preprw);
1107 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1113 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1114 struct obd_export *exp, struct obdo *oa,
1115 int objcount, struct obd_ioobj *obj,
1116 struct niobuf_remote *rnb, int pages,
1117 struct niobuf_local *local, int rc)
1121 EXP_CHECK_DT_OP(exp, commitrw);
1122 EXP_COUNTER_INCREMENT(exp, commitrw);
1123 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1124 rnb, pages, local, rc);
1129 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1130 int len, void *karg, void __user *uarg)
1135 EXP_CHECK_DT_OP(exp, iocontrol);
1136 EXP_COUNTER_INCREMENT(exp, iocontrol);
1138 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1142 static inline void obd_import_event(struct obd_device *obd,
1143 struct obd_import *imp,
1144 enum obd_import_event event)
1148 CERROR("NULL device\n");
1152 if (obd->obd_set_up && OBP(obd, import_event)) {
1153 OBD_COUNTER_INCREMENT(obd, import_event);
1154 OBP(obd, import_event)(obd, imp, event);
1159 static inline int obd_notify(struct obd_device *obd,
1160 struct obd_device *watched,
1161 enum obd_notify_event ev,
1168 if (!obd->obd_set_up) {
1169 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1173 if (!OBP(obd, notify)) {
1174 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1178 OBD_COUNTER_INCREMENT(obd, notify);
1179 rc = OBP(obd, notify)(obd, watched, ev, data);
1183 static inline int obd_notify_observer(struct obd_device *observer,
1184 struct obd_device *observed,
1185 enum obd_notify_event ev,
1191 struct obd_notify_upcall *onu;
1193 if (observer->obd_observer)
1194 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1198 * Also, call non-obd listener, if any
1200 onu = &observer->obd_upcall;
1201 if (onu->onu_upcall != NULL)
1202 rc2 = onu->onu_upcall(observer, observed, ev,
1203 onu->onu_owner, NULL);
1207 return rc1 ? rc1 : rc2;
1210 static inline int obd_quotactl(struct obd_export *exp,
1211 struct obd_quotactl *oqctl)
1216 EXP_CHECK_DT_OP(exp, quotactl);
1217 EXP_COUNTER_INCREMENT(exp, quotactl);
1219 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1223 static inline int obd_health_check(const struct lu_env *env,
1224 struct obd_device *obd)
1226 /* returns: 0 on healthy
1227 * >0 on unhealthy + reason code/flag
1228 * however the only suppored reason == 1 right now
1229 * We'll need to define some better reasons
1230 * or flags in the future.
1236 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1237 if (obd == NULL || !OBT(obd)) {
1238 CERROR("cleaned up obd\n");
1239 RETURN(-EOPNOTSUPP);
1241 if (!obd->obd_set_up || obd->obd_stopping)
1243 if (!OBP(obd, health_check))
1246 rc = OBP(obd, health_check)(env, obd);
1250 static inline int obd_register_observer(struct obd_device *obd,
1251 struct obd_device *observer)
1255 down_write(&obd->obd_observer_link_sem);
1256 if (obd->obd_observer && observer) {
1257 up_write(&obd->obd_observer_link_sem);
1260 obd->obd_observer = observer;
1261 up_write(&obd->obd_observer_link_sem);
1265 /* metadata helpers */
1266 static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
1271 EXP_CHECK_MD_OP(exp, getstatus);
1272 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1273 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1278 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1279 struct ptlrpc_request **request)
1283 EXP_CHECK_MD_OP(exp, getattr);
1284 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1285 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1289 static inline int md_null_inode(struct obd_export *exp,
1290 const struct lu_fid *fid)
1294 EXP_CHECK_MD_OP(exp, null_inode);
1295 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1296 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1300 static inline int md_find_cbdata(struct obd_export *exp,
1301 const struct lu_fid *fid,
1302 ldlm_iterator_t it, void *data)
1306 EXP_CHECK_MD_OP(exp, find_cbdata);
1307 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1308 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1312 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1313 struct md_open_data *mod,
1314 struct ptlrpc_request **request)
1318 EXP_CHECK_MD_OP(exp, close);
1319 EXP_MD_COUNTER_INCREMENT(exp, close);
1320 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1324 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1325 const void *data, size_t datalen, umode_t mode,
1326 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1327 __u64 rdev, struct ptlrpc_request **request)
1331 EXP_CHECK_MD_OP(exp, create);
1332 EXP_MD_COUNTER_INCREMENT(exp, create);
1333 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1334 uid, gid, cap_effective, rdev, request);
1338 static inline int md_enqueue(struct obd_export *exp,
1339 struct ldlm_enqueue_info *einfo,
1340 const union ldlm_policy_data *policy,
1341 struct lookup_intent *it,
1342 struct md_op_data *op_data,
1343 struct lustre_handle *lockh,
1344 __u64 extra_lock_flags)
1348 EXP_CHECK_MD_OP(exp, enqueue);
1349 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1350 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1355 static inline int md_getattr_name(struct obd_export *exp,
1356 struct md_op_data *op_data,
1357 struct ptlrpc_request **request)
1361 EXP_CHECK_MD_OP(exp, getattr_name);
1362 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1363 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1367 static inline int md_intent_lock(struct obd_export *exp,
1368 struct md_op_data *op_data,
1369 struct lookup_intent *it,
1370 struct ptlrpc_request **reqp,
1371 ldlm_blocking_callback cb_blocking,
1372 __u64 extra_lock_flags)
1376 EXP_CHECK_MD_OP(exp, intent_lock);
1377 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1378 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1383 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1384 struct ptlrpc_request **request)
1388 EXP_CHECK_MD_OP(exp, link);
1389 EXP_MD_COUNTER_INCREMENT(exp, link);
1390 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1394 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1395 const char *old, size_t oldlen, const char *new,
1396 size_t newlen, struct ptlrpc_request **request)
1400 EXP_CHECK_MD_OP(exp, rename);
1401 EXP_MD_COUNTER_INCREMENT(exp, rename);
1402 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1407 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1408 void *ea, size_t ealen,
1409 struct ptlrpc_request **request)
1413 EXP_CHECK_MD_OP(exp, setattr);
1414 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1415 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1419 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1420 struct ptlrpc_request **request)
1425 EXP_CHECK_MD_OP(exp, fsync);
1426 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1427 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1432 static inline int md_read_page(struct obd_export *exp,
1433 struct md_op_data *op_data,
1434 struct md_callback *cb_op,
1436 struct page **ppage)
1440 EXP_CHECK_MD_OP(exp, read_page);
1441 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1442 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1447 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1448 struct ptlrpc_request **request)
1452 EXP_CHECK_MD_OP(exp, unlink);
1453 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1454 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1458 static inline int md_get_lustre_md(struct obd_export *exp,
1459 struct ptlrpc_request *req,
1460 struct obd_export *dt_exp,
1461 struct obd_export *md_exp,
1462 struct lustre_md *md)
1465 EXP_CHECK_MD_OP(exp, get_lustre_md);
1466 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1467 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1470 static inline int md_free_lustre_md(struct obd_export *exp,
1471 struct lustre_md *md)
1474 EXP_CHECK_MD_OP(exp, free_lustre_md);
1475 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1476 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1479 static inline int md_merge_attr(struct obd_export *exp,
1480 const struct lmv_stripe_md *lsm,
1481 struct cl_attr *attr,
1482 ldlm_blocking_callback cb)
1485 EXP_CHECK_MD_OP(exp, merge_attr);
1486 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1487 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1490 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1491 u64 valid, const char *name,
1492 const char *input, int input_size,
1493 int output_size, int flags, __u32 suppgid,
1494 struct ptlrpc_request **request)
1497 EXP_CHECK_MD_OP(exp, setxattr);
1498 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1499 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1500 input_size, output_size, flags,
1504 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1505 u64 valid, const char *name,
1506 const char *input, int input_size,
1507 int output_size, int flags,
1508 struct ptlrpc_request **request)
1511 EXP_CHECK_MD_OP(exp, getxattr);
1512 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1513 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1514 input_size, output_size, flags,
1518 static inline int md_set_open_replay_data(struct obd_export *exp,
1519 struct obd_client_handle *och,
1520 struct lookup_intent *it)
1523 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1524 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1525 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1528 static inline int md_clear_open_replay_data(struct obd_export *exp,
1529 struct obd_client_handle *och)
1532 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1533 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1534 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1537 static inline int md_set_lock_data(struct obd_export *exp,
1538 __u64 *lockh, void *data, __u64 *bits)
1541 EXP_CHECK_MD_OP(exp, set_lock_data);
1542 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1543 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1546 static inline int md_cancel_unused(struct obd_export *exp,
1547 const struct lu_fid *fid,
1548 ldlm_policy_data_t *policy,
1550 ldlm_cancel_flags_t flags,
1556 EXP_CHECK_MD_OP(exp, cancel_unused);
1557 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1559 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1564 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1565 const struct lu_fid *fid,
1567 ldlm_policy_data_t *policy,
1569 struct lustre_handle *lockh)
1572 EXP_CHECK_MD_OP(exp, lock_match);
1573 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1574 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1575 policy, mode, lockh));
1578 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1582 EXP_CHECK_MD_OP(exp, init_ea_size);
1583 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1584 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1587 static inline int md_get_remote_perm(struct obd_export *exp,
1588 const struct lu_fid *fid, u32 suppgid,
1589 struct ptlrpc_request **request)
1592 EXP_CHECK_MD_OP(exp, get_remote_perm);
1593 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1595 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, suppgid, request));
1598 static inline int md_intent_getattr_async(struct obd_export *exp,
1599 struct md_enqueue_info *minfo,
1600 struct ldlm_enqueue_info *einfo)
1604 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1605 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1606 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1610 static inline int md_revalidate_lock(struct obd_export *exp,
1611 struct lookup_intent *it,
1612 struct lu_fid *fid, __u64 *bits)
1616 EXP_CHECK_MD_OP(exp, revalidate_lock);
1617 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1618 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1622 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1623 const struct lmv_stripe_md *lsm,
1624 const char *name, int namelen,
1629 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1630 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1631 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1636 /* Unpack an MD struct from disk to in-memory format.
1637 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1639 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1640 * If *plsm == NULL then it will be allocated.
1642 static inline int md_unpackmd(struct obd_export *exp,
1643 struct lmv_stripe_md **plsm,
1644 const union lmv_mds_md *lmm, size_t lmm_size)
1648 EXP_CHECK_MD_OP(exp, unpackmd);
1649 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1650 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1654 /* OBD Metadata Support */
1656 extern int obd_init_caches(void);
1657 extern void obd_cleanup_caches(void);
1659 /* support routines */
1660 extern struct kmem_cache *obdo_cachep;
1662 #define OBDO_ALLOC(ptr) \
1664 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1667 #define OBDO_FREE(ptr) \
1669 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1673 typedef int (*register_lwp_cb)(void *data);
1675 struct lwp_register_item {
1676 struct obd_export **lri_exp;
1677 register_lwp_cb lri_cb_func;
1679 struct list_head lri_list;
1680 char lri_name[MTI_NAME_MAXLEN];
1683 /* I'm as embarrassed about this as you are.
1685 * <shaver> // XXX do not look into _superhack with remaining eye
1686 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1687 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1690 #ifdef HAVE_SERVER_SUPPORT
1691 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1692 register_lwp_cb cb_func, void *cb_data);
1693 void lustre_deregister_lwp_item(struct obd_export **exp);
1694 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1695 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1696 #endif /* HAVE_SERVER_SUPPORT */
1697 int lustre_register_fs(void);
1698 int lustre_unregister_fs(void);
1699 int lustre_check_exclusion(struct super_block *sb, char *svname);
1702 extern void obd_sysctl_init (void);
1703 extern void obd_sysctl_clean (void);
1706 typedef __u8 class_uuid_t[16];
1707 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1710 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1711 int class_add_uuid(const char *uuid, __u64 nid);
1712 int class_del_uuid (const char *uuid);
1713 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1714 void class_init_uuidlist(void);
1715 void class_exit_uuidlist(void);
1718 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1722 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1723 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1725 /* root squash info */
1726 struct rw_semaphore;
1727 struct root_squash_info {
1730 struct list_head rsi_nosquash_nids;
1731 struct rw_semaphore rsi_sem;
1734 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1736 /* linux-module.c */
1737 extern struct miscdevice obd_psdev;
1738 int class_procfs_init(void);
1739 int class_procfs_clean(void);
1741 #endif /* __LINUX_OBD_CLASS_H */