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, 2015, 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, __u64 flags2,
107 int obd_zombie_impexp_init(void);
108 void obd_zombie_impexp_stop(void);
109 void obd_zombie_impexp_cull(void);
110 void obd_zombie_barrier(void);
111 void obd_exports_barrier(struct obd_device *obd);
112 int kuc_len(int payload_len);
113 struct kuc_hdr * kuc_ptr(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 extern atomic_t obd_stale_export_num;
135 extern struct list_head obd_stale_exports;
136 extern spinlock_t obd_stale_export_lock;
138 struct obd_export *obd_stale_export_get(void);
139 void obd_stale_export_put(struct obd_export *exp);
140 void obd_stale_export_adjust(struct obd_export *exp);
143 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
144 const char *new_name);
145 int class_process_config(struct lustre_cfg *lcfg);
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);
152 struct obd_device *class_incref(struct obd_device *obd,
153 const char *scope, const void *source);
154 void class_decref(struct obd_device *obd,
155 const char *scope, const void *source);
156 void dump_exports(struct obd_device *obd, int locks);
157 int class_config_llog_handler(const struct lu_env *env,
158 struct llog_handle *handle,
159 struct llog_rec_hdr *rec, void *data);
160 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
161 int class_add_uuid(const char *uuid, __u64 nid);
163 #define CFG_F_START 0x01 /* Set when we start updating from a log */
164 #define CFG_F_MARKER 0x02 /* We are within a maker */
165 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
166 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
167 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
169 /* Passed as data param to class_config_parse_llog */
170 struct config_llog_instance {
173 struct super_block *cfg_sb;
174 struct obd_uuid cfg_uuid;
175 llog_cb_t cfg_callback;
176 int cfg_last_idx; /* for partial llog processing */
180 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
181 char *name, struct config_llog_instance *cfg);
185 CONFIG_T_SPTLRPC = 1,
186 CONFIG_T_RECOVER = 2,
188 CONFIG_T_NODEMAP = 4,
192 #define PARAMS_FILENAME "params"
193 #define LCTL_UPCALL "lctl"
195 /* list of active configuration logs */
196 struct config_llog_data {
197 struct ldlm_res_id cld_resid;
198 struct config_llog_instance cld_cfg;
199 struct list_head cld_list_chain;
200 atomic_t cld_refcount;
201 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
202 struct config_llog_data *cld_params; /* common parameters log */
203 struct config_llog_data *cld_recover;/* imperative recover log */
204 struct config_llog_data *cld_nodemap;/* nodemap log */
205 struct obd_export *cld_mgcexp;
206 struct mutex cld_lock;
208 unsigned int cld_stopping:1, /* we were told to stop
210 cld_lostlock:1; /* lock not requeued */
214 struct lustre_profile {
215 struct list_head lp_list;
220 bool lp_list_deleted;
223 struct lustre_profile *class_get_profile(const char * prof);
224 void class_del_profile(const char *prof);
225 void class_put_profile(struct lustre_profile *lprof);
226 void class_del_profiles(void);
229 #if LUSTRE_TRACKS_LOCK_EXP_REFS
231 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
232 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
233 extern void (*class_export_dump_hook)(struct obd_export *);
237 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
238 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
242 #define class_export_rpc_inc(exp) \
244 atomic_inc(&(exp)->exp_rpc_count); \
245 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
246 (exp), atomic_read(&(exp)->exp_rpc_count)); \
249 #define class_export_rpc_dec(exp) \
251 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
252 atomic_dec(&(exp)->exp_rpc_count); \
253 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
254 (exp), atomic_read(&(exp)->exp_rpc_count)); \
257 #define class_export_lock_get(exp, lock) \
259 atomic_inc(&(exp)->exp_locks_count); \
260 __class_export_add_lock_ref(exp, lock); \
261 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
262 (exp), atomic_read(&(exp)->exp_locks_count)); \
263 class_export_get(exp); \
266 #define class_export_lock_put(exp, lock) \
268 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
269 atomic_dec(&(exp)->exp_locks_count); \
270 __class_export_del_lock_ref(exp, lock); \
271 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
272 (exp), atomic_read(&(exp)->exp_locks_count)); \
273 class_export_put(exp); \
276 #define class_export_cb_get(exp) \
278 atomic_inc(&(exp)->exp_cb_count); \
279 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
280 (exp), atomic_read(&(exp)->exp_cb_count)); \
281 class_export_get(exp); \
284 #define class_export_cb_put(exp) \
286 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
287 atomic_dec(&(exp)->exp_cb_count); \
288 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
289 (exp), atomic_read(&(exp)->exp_cb_count)); \
290 class_export_put(exp); \
294 struct obd_export *class_export_get(struct obd_export *exp);
295 void class_export_put(struct obd_export *exp);
296 struct obd_export *class_new_export(struct obd_device *obddev,
297 struct obd_uuid *cluuid);
298 void class_unlink_export(struct obd_export *exp);
300 struct obd_import *class_import_get(struct obd_import *);
301 void class_import_put(struct obd_import *);
302 struct obd_import *class_new_import(struct obd_device *obd);
303 void class_destroy_import(struct obd_import *exp);
305 struct obd_type *class_search_type(const char *name);
306 struct obd_type *class_get_type(const char *name);
307 void class_put_type(struct obd_type *type);
308 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
309 struct obd_uuid *cluuid);
310 int class_disconnect(struct obd_export *exp);
311 void class_fail_export(struct obd_export *exp);
312 int class_connected_export(struct obd_export *exp);
313 void class_disconnect_exports(struct obd_device *obddev);
314 int class_manual_cleanup(struct obd_device *obd);
315 void class_disconnect_stale_exports(struct obd_device *,
316 int (*test_export)(struct obd_export *));
317 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
319 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
320 (obd->obd_force ? OBD_OPT_FORCE : 0) |
321 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
325 #ifdef HAVE_SERVER_SUPPORT
326 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
328 LASSERT(exp->exp_obd);
329 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
331 return exp->exp_obd->u.obt.obt_lut;
334 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
336 LASSERT(obd->u.obt.obt_lut);
337 return &obd->u.obt.obt_lut->lut_lsd;
345 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
346 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
348 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
349 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
351 #define OBT(dev) (dev)->obd_type
352 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
353 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
354 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
356 /* Ensure obd_setup: used for cleanup which must be called
357 while obd is stopping */
358 #define OBD_CHECK_DEV(obd) \
361 CERROR("NULL device\n"); \
366 /* ensure obd_setup and !obd_stopping */
367 #define OBD_CHECK_DEV_ACTIVE(obd) \
369 OBD_CHECK_DEV(obd); \
370 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
371 CERROR("Device %d not setup\n", \
378 #ifdef CONFIG_PROC_FS
379 #define OBD_COUNTER_OFFSET(op) \
380 ((offsetof(struct obd_ops, o_ ## op) - \
381 offsetof(struct obd_ops, o_iocontrol)) \
382 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
384 /* The '- 1' below is for o_owner. */
385 #define NUM_OBD_STATS \
386 (sizeof(struct obd_ops) / \
387 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
389 #define OBD_COUNTER_INCREMENT(obd, op) \
390 lprocfs_counter_incr((obd)->obd_stats, \
391 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
393 #define EXP_COUNTER_INCREMENT(exp, op) \
396 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
397 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
398 if ((exp)->exp_obd->obd_uses_nid_stats && \
399 (exp)->exp_nid_stats != NULL) \
400 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
404 #define _MD_COUNTER_OFFSET(m_op) \
405 ((offsetof(struct md_ops, m_op) - \
406 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
407 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
409 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
411 #define NUM_MD_STATS \
412 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
413 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
415 /* Note that we only increment md counters for ops whose offset is less
416 * than NUM_MD_STATS. This is explained in a comment in the definition
417 * of struct md_ops. */
418 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
420 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
421 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
422 (exp)->exp_obd->obd_md_cntr_base + \
423 MD_COUNTER_OFFSET(op)); \
427 #define OBD_COUNTER_OFFSET(op)
428 #define OBD_COUNTER_INCREMENT(obd, op)
429 #define EXP_COUNTER_INCREMENT(exp, op)
430 #define EXP_MD_COUNTER_INCREMENT(exp, op)
433 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
435 /* Always add in ldlm_stats */
436 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
437 ,LPROCFS_STATS_FLAG_NOPERCPU);
438 if (tmp->nid_ldlm_stats == NULL)
441 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
443 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
444 tmp->nid_ldlm_stats);
447 #define EXP_CHECK_MD_OP(exp, op) \
449 if ((exp) == NULL) { \
450 CERROR("obd_" #op ": NULL export\n"); \
453 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
454 CERROR("obd_" #op ": cleaned up obd\n"); \
455 RETURN(-EOPNOTSUPP); \
457 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
458 CERROR("obd_" #op ": dev %s/%d no operation\n", \
459 (exp)->exp_obd->obd_name, \
460 (exp)->exp_obd->obd_minor); \
461 RETURN(-EOPNOTSUPP); \
466 #define OBD_CHECK_DT_OP(obd, op, err) \
468 if (!OBT(obd) || !OBP((obd), op)) { \
470 CERROR("obd_" #op ": dev %d no operation\n", \
476 #define EXP_CHECK_DT_OP(exp, op) \
478 if ((exp) == NULL) { \
479 CERROR("obd_" #op ": NULL export\n"); \
482 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
483 CERROR("obd_" #op ": cleaned up obd\n"); \
484 RETURN(-EOPNOTSUPP); \
486 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
487 CERROR("obd_" #op ": dev %d no operation\n", \
488 (exp)->exp_obd->obd_minor); \
489 RETURN(-EOPNOTSUPP); \
493 #define CTXT_CHECK_OP(ctxt, op, err) \
495 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
497 CERROR("lop_" #op ": dev %d no operation\n", \
498 ctxt->loc_obd->obd_minor); \
503 static inline int class_devno_max(void)
505 return MAX_OBD_DEVICES;
508 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
509 __u32 keylen, void *key,
510 __u32 *vallen, void *val)
515 EXP_CHECK_DT_OP(exp, get_info);
516 EXP_COUNTER_INCREMENT(exp, get_info);
518 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
522 static inline int obd_set_info_async(const struct lu_env *env,
523 struct obd_export *exp,
524 __u32 keylen, void *key,
525 __u32 vallen, void *val,
526 struct ptlrpc_request_set *set)
531 EXP_CHECK_DT_OP(exp, set_info_async);
532 EXP_COUNTER_INCREMENT(exp, set_info_async);
534 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
540 * obd-lu integration.
542 * Functionality is being moved into new lu_device-based layering, but some
543 * pieces of configuration process are still based on obd devices.
545 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
546 * subsume ->o_setup() methods of obd devices they replace. The same for
547 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
548 * result, obd_setup() and obd_process_config() branch and call one XOR
551 * Yet neither lu_device_type_operations::ldto_device_fini() nor
552 * lu_device_type_operations::ldto_device_free() fully implement the
553 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
554 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
557 #define DECLARE_LU_VARS(ldt, d) \
558 struct lu_device_type *ldt; \
561 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
564 DECLARE_LU_VARS(ldt, d);
567 ldt = obd->obd_type->typ_lu;
569 struct lu_context session_ctx;
571 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
572 session_ctx.lc_thread = NULL;
573 lu_context_enter(&session_ctx);
575 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
577 env.le_ses = &session_ctx;
578 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
587 lu_context_exit(&session_ctx);
588 lu_context_fini(&session_ctx);
591 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
592 OBD_COUNTER_INCREMENT(obd, setup);
593 rc = OBP(obd, setup)(obd, cfg);
598 static inline int obd_precleanup(struct obd_device *obd)
601 DECLARE_LU_VARS(ldt, d);
605 ldt = obd->obd_type->typ_lu;
607 if (ldt != NULL && d != NULL) {
610 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
612 ldt->ldt_ops->ldto_device_fini(&env, d);
616 OBD_CHECK_DT_OP(obd, precleanup, 0);
617 OBD_COUNTER_INCREMENT(obd, precleanup);
619 rc = OBP(obd, precleanup)(obd);
623 static inline int obd_cleanup(struct obd_device *obd)
626 DECLARE_LU_VARS(ldt, d);
631 ldt = obd->obd_type->typ_lu;
633 if (ldt != NULL && d != NULL) {
636 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
638 ldt->ldt_ops->ldto_device_free(&env, d);
640 obd->obd_lu_dev = NULL;
643 OBD_CHECK_DT_OP(obd, cleanup, 0);
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);
672 obd_process_config(struct obd_device *obd, int datalen, void *data)
675 DECLARE_LU_VARS(ldt, d);
680 obd->obd_process_conf = 1;
681 ldt = obd->obd_type->typ_lu;
683 if (ldt != NULL && d != NULL) {
686 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
688 rc = d->ld_ops->ldo_process_config(&env, d, data);
692 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
693 rc = OBP(obd, process_config)(obd, datalen, data);
695 OBD_COUNTER_INCREMENT(obd, process_config);
696 obd->obd_process_conf = 0;
701 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
707 EXP_CHECK_DT_OP(exp, create);
708 EXP_COUNTER_INCREMENT(exp, create);
710 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
714 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
720 EXP_CHECK_DT_OP(exp, destroy);
721 EXP_COUNTER_INCREMENT(exp, destroy);
723 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
727 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
733 EXP_CHECK_DT_OP(exp, getattr);
734 EXP_COUNTER_INCREMENT(exp, getattr);
735 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
740 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
746 EXP_CHECK_DT_OP(exp, setattr);
747 EXP_COUNTER_INCREMENT(exp, setattr);
748 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
753 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
756 struct obd_device *obd = imp->imp_obd;
760 OBD_CHECK_DEV_ACTIVE(obd);
761 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
762 OBD_COUNTER_INCREMENT(obd, add_conn);
764 rc = OBP(obd, add_conn)(imp, uuid, priority);
768 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
770 struct obd_device *obd = imp->imp_obd;
774 OBD_CHECK_DEV_ACTIVE(obd);
775 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
776 OBD_COUNTER_INCREMENT(obd, del_conn);
778 rc = OBP(obd, del_conn)(imp, uuid);
782 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
784 struct obd_uuid *uuid;
787 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
788 EXP_COUNTER_INCREMENT(exp, get_uuid);
790 uuid = OBP(exp->exp_obd, get_uuid)(exp);
794 /** Create a new /a exp on device /a obd for the uuid /a cluuid
795 * @param exp New export handle
796 * @param d Connect data, supported flags are set, flags also understood
797 * by obd are returned.
799 static inline int obd_connect(const struct lu_env *env,
800 struct obd_export **exp,struct obd_device *obd,
801 struct obd_uuid *cluuid,
802 struct obd_connect_data *data,
806 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
810 OBD_CHECK_DEV_ACTIVE(obd);
811 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
812 OBD_COUNTER_INCREMENT(obd, connect);
814 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
815 /* check that only subset is granted */
816 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
817 data->ocd_connect_flags));
821 static inline int obd_reconnect(const struct lu_env *env,
822 struct obd_export *exp,
823 struct obd_device *obd,
824 struct obd_uuid *cluuid,
825 struct obd_connect_data *d,
829 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
834 OBD_CHECK_DEV_ACTIVE(obd);
835 OBD_CHECK_DT_OP(obd, reconnect, 0);
836 OBD_COUNTER_INCREMENT(obd, reconnect);
838 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
839 /* check that only subset is granted */
840 LASSERT(ergo(d != NULL,
841 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
845 static inline int obd_disconnect(struct obd_export *exp)
850 EXP_CHECK_DT_OP(exp, disconnect);
851 EXP_COUNTER_INCREMENT(exp, disconnect);
853 rc = OBP(exp->exp_obd, disconnect)(exp);
857 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
858 enum lu_cli_type type)
863 OBD_CHECK_DT_OP(obd, fid_init, 0);
864 OBD_COUNTER_INCREMENT(obd, fid_init);
866 rc = OBP(obd, fid_init)(obd, exp, type);
870 static inline int obd_fid_fini(struct obd_device *obd)
875 OBD_CHECK_DT_OP(obd, fid_fini, 0);
876 OBD_COUNTER_INCREMENT(obd, fid_fini);
878 rc = OBP(obd, fid_fini)(obd);
882 static inline int obd_fid_alloc(const struct lu_env *env,
883 struct obd_export *exp,
885 struct md_op_data *op_data)
890 EXP_CHECK_DT_OP(exp, fid_alloc);
891 EXP_COUNTER_INCREMENT(exp, fid_alloc);
893 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
897 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
902 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
903 EXP_COUNTER_INCREMENT(exp, ping);
905 rc = OBP(exp->exp_obd, ping)(env, exp);
909 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
914 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
915 OBD_COUNTER_INCREMENT(obd, pool_new);
917 rc = OBP(obd, pool_new)(obd, poolname);
921 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
926 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
927 OBD_COUNTER_INCREMENT(obd, pool_del);
929 rc = OBP(obd, pool_del)(obd, poolname);
933 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
938 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
939 OBD_COUNTER_INCREMENT(obd, pool_add);
941 rc = OBP(obd, pool_add)(obd, poolname, ostname);
945 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
950 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
951 OBD_COUNTER_INCREMENT(obd, pool_rem);
953 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
957 static inline void obd_getref(struct obd_device *obd)
960 if (OBT(obd) && OBP(obd, getref)) {
961 OBD_COUNTER_INCREMENT(obd, getref);
962 OBP(obd, getref)(obd);
967 static inline void obd_putref(struct obd_device *obd)
970 if (OBT(obd) && OBP(obd, putref)) {
971 OBD_COUNTER_INCREMENT(obd, putref);
972 OBP(obd, putref)(obd);
977 static inline int obd_init_export(struct obd_export *exp)
982 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
983 OBP((exp)->exp_obd, init_export))
984 rc = OBP(exp->exp_obd, init_export)(exp);
988 static inline int obd_destroy_export(struct obd_export *exp)
991 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
992 OBP((exp)->exp_obd, destroy_export))
993 OBP(exp->exp_obd, destroy_export)(exp);
997 /* @max_age is the oldest time in jiffies that we accept using a cached data.
998 * If the cache is older than @max_age we will get a new value from the
999 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1000 static inline int obd_statfs_async(struct obd_export *exp,
1001 struct obd_info *oinfo,
1003 struct ptlrpc_request_set *rqset)
1006 struct obd_device *obd;
1009 if (exp == NULL || exp->exp_obd == NULL)
1013 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1014 OBD_COUNTER_INCREMENT(obd, statfs);
1016 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1017 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1018 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1019 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1021 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1022 " objects "LPU64"/"LPU64"\n",
1023 obd->obd_name, &obd->obd_osfs,
1024 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1025 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1026 spin_lock(&obd->obd_osfs_lock);
1027 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1028 spin_unlock(&obd->obd_osfs_lock);
1029 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1030 if (oinfo->oi_cb_up)
1031 oinfo->oi_cb_up(oinfo, 0);
1036 static inline int obd_statfs_rqset(struct obd_export *exp,
1037 struct obd_statfs *osfs, __u64 max_age,
1040 struct ptlrpc_request_set *set = NULL;
1041 struct obd_info oinfo = {
1049 set = ptlrpc_prep_set();
1053 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1055 rc = ptlrpc_set_wait(set);
1057 ptlrpc_set_destroy(set);
1062 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1063 * If the cache is older than @max_age we will get a new value from the
1064 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1065 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1066 struct obd_statfs *osfs, __u64 max_age,
1070 struct obd_device *obd = exp->exp_obd;
1076 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1077 OBD_COUNTER_INCREMENT(obd, statfs);
1079 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1080 obd->obd_osfs_age, max_age);
1081 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1082 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1084 spin_lock(&obd->obd_osfs_lock);
1085 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1086 obd->obd_osfs_age = cfs_time_current_64();
1087 spin_unlock(&obd->obd_osfs_lock);
1090 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1091 " objects "LPU64"/"LPU64"\n",
1092 obd->obd_name, &obd->obd_osfs,
1093 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1094 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1095 spin_lock(&obd->obd_osfs_lock);
1096 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1097 spin_unlock(&obd->obd_osfs_lock);
1102 static inline int obd_preprw(const struct lu_env *env, int cmd,
1103 struct obd_export *exp, struct obdo *oa,
1104 int objcount, struct obd_ioobj *obj,
1105 struct niobuf_remote *remote, int *pages,
1106 struct niobuf_local *local)
1111 EXP_CHECK_DT_OP(exp, preprw);
1112 EXP_COUNTER_INCREMENT(exp, preprw);
1113 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1119 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1120 struct obd_export *exp, struct obdo *oa,
1121 int objcount, struct obd_ioobj *obj,
1122 struct niobuf_remote *rnb, int pages,
1123 struct niobuf_local *local, int rc)
1127 EXP_CHECK_DT_OP(exp, commitrw);
1128 EXP_COUNTER_INCREMENT(exp, commitrw);
1129 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1130 rnb, pages, local, rc);
1135 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1136 int len, void *karg, void __user *uarg)
1141 EXP_CHECK_DT_OP(exp, iocontrol);
1142 EXP_COUNTER_INCREMENT(exp, iocontrol);
1144 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1148 static inline void obd_import_event(struct obd_device *obd,
1149 struct obd_import *imp,
1150 enum obd_import_event event)
1154 CERROR("NULL device\n");
1158 if (obd->obd_set_up && OBP(obd, import_event)) {
1159 OBD_COUNTER_INCREMENT(obd, import_event);
1160 OBP(obd, import_event)(obd, imp, event);
1165 static inline int obd_notify(struct obd_device *obd,
1166 struct obd_device *watched,
1167 enum obd_notify_event ev,
1174 if (!obd->obd_set_up) {
1175 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1179 if (!OBP(obd, notify)) {
1180 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1184 OBD_COUNTER_INCREMENT(obd, notify);
1185 rc = OBP(obd, notify)(obd, watched, ev, data);
1189 static inline int obd_notify_observer(struct obd_device *observer,
1190 struct obd_device *observed,
1191 enum obd_notify_event ev,
1197 struct obd_notify_upcall *onu;
1199 if (observer->obd_observer)
1200 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1204 * Also, call non-obd listener, if any
1206 onu = &observer->obd_upcall;
1207 if (onu->onu_upcall != NULL)
1208 rc2 = onu->onu_upcall(observer, observed, ev,
1209 onu->onu_owner, NULL);
1213 return rc1 ? rc1 : rc2;
1216 static inline int obd_quotactl(struct obd_export *exp,
1217 struct obd_quotactl *oqctl)
1222 EXP_CHECK_DT_OP(exp, quotactl);
1223 EXP_COUNTER_INCREMENT(exp, quotactl);
1225 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1229 static inline int obd_health_check(const struct lu_env *env,
1230 struct obd_device *obd)
1232 /* returns: 0 on healthy
1233 * >0 on unhealthy + reason code/flag
1234 * however the only suppored reason == 1 right now
1235 * We'll need to define some better reasons
1236 * or flags in the future.
1242 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1243 if (obd == NULL || !OBT(obd)) {
1244 CERROR("cleaned up obd\n");
1245 RETURN(-EOPNOTSUPP);
1247 if (!obd->obd_set_up || obd->obd_stopping)
1249 if (!OBP(obd, health_check))
1252 rc = OBP(obd, health_check)(env, obd);
1256 static inline int obd_register_observer(struct obd_device *obd,
1257 struct obd_device *observer)
1261 down_write(&obd->obd_observer_link_sem);
1262 if (obd->obd_observer && observer) {
1263 up_write(&obd->obd_observer_link_sem);
1266 obd->obd_observer = observer;
1267 up_write(&obd->obd_observer_link_sem);
1271 /* metadata helpers */
1272 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1278 EXP_CHECK_MD_OP(exp, get_root);
1279 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1280 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1285 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1286 struct ptlrpc_request **request)
1290 EXP_CHECK_MD_OP(exp, getattr);
1291 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1292 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1296 static inline int md_null_inode(struct obd_export *exp,
1297 const struct lu_fid *fid)
1301 EXP_CHECK_MD_OP(exp, null_inode);
1302 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1303 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1307 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1308 struct md_open_data *mod,
1309 struct ptlrpc_request **request)
1313 EXP_CHECK_MD_OP(exp, close);
1314 EXP_MD_COUNTER_INCREMENT(exp, close);
1315 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1319 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1320 const void *data, size_t datalen, umode_t mode,
1321 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1322 __u64 rdev, struct ptlrpc_request **request)
1326 EXP_CHECK_MD_OP(exp, create);
1327 EXP_MD_COUNTER_INCREMENT(exp, create);
1328 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1329 uid, gid, cap_effective, rdev, request);
1333 static inline int md_enqueue(struct obd_export *exp,
1334 struct ldlm_enqueue_info *einfo,
1335 const union ldlm_policy_data *policy,
1336 struct lookup_intent *it,
1337 struct md_op_data *op_data,
1338 struct lustre_handle *lockh,
1339 __u64 extra_lock_flags)
1343 EXP_CHECK_MD_OP(exp, enqueue);
1344 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1345 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1350 static inline int md_getattr_name(struct obd_export *exp,
1351 struct md_op_data *op_data,
1352 struct ptlrpc_request **request)
1356 EXP_CHECK_MD_OP(exp, getattr_name);
1357 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1358 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1362 static inline int md_intent_lock(struct obd_export *exp,
1363 struct md_op_data *op_data,
1364 struct lookup_intent *it,
1365 struct ptlrpc_request **reqp,
1366 ldlm_blocking_callback cb_blocking,
1367 __u64 extra_lock_flags)
1371 EXP_CHECK_MD_OP(exp, intent_lock);
1372 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1373 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1378 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1379 struct ptlrpc_request **request)
1383 EXP_CHECK_MD_OP(exp, link);
1384 EXP_MD_COUNTER_INCREMENT(exp, link);
1385 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1389 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1390 const char *old, size_t oldlen, const char *new,
1391 size_t newlen, struct ptlrpc_request **request)
1395 EXP_CHECK_MD_OP(exp, rename);
1396 EXP_MD_COUNTER_INCREMENT(exp, rename);
1397 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1402 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1403 void *ea, size_t ealen,
1404 struct ptlrpc_request **request)
1408 EXP_CHECK_MD_OP(exp, setattr);
1409 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1410 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1414 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1415 struct ptlrpc_request **request)
1420 EXP_CHECK_MD_OP(exp, fsync);
1421 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1422 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1427 static inline int md_read_page(struct obd_export *exp,
1428 struct md_op_data *op_data,
1429 struct md_callback *cb_op,
1431 struct page **ppage)
1435 EXP_CHECK_MD_OP(exp, read_page);
1436 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1437 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1442 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1443 struct ptlrpc_request **request)
1447 EXP_CHECK_MD_OP(exp, unlink);
1448 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1449 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1453 static inline int md_get_lustre_md(struct obd_export *exp,
1454 struct ptlrpc_request *req,
1455 struct obd_export *dt_exp,
1456 struct obd_export *md_exp,
1457 struct lustre_md *md)
1460 EXP_CHECK_MD_OP(exp, get_lustre_md);
1461 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1462 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1465 static inline int md_free_lustre_md(struct obd_export *exp,
1466 struct lustre_md *md)
1469 EXP_CHECK_MD_OP(exp, free_lustre_md);
1470 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1471 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1474 static inline int md_merge_attr(struct obd_export *exp,
1475 const struct lmv_stripe_md *lsm,
1476 struct cl_attr *attr,
1477 ldlm_blocking_callback cb)
1480 EXP_CHECK_MD_OP(exp, merge_attr);
1481 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1482 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1485 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1486 u64 valid, const char *name,
1487 const char *input, int input_size,
1488 int output_size, int flags, __u32 suppgid,
1489 struct ptlrpc_request **request)
1492 EXP_CHECK_MD_OP(exp, setxattr);
1493 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1494 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1495 input_size, output_size, flags,
1499 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1500 u64 valid, const char *name,
1501 const char *input, int input_size,
1502 int output_size, int flags,
1503 struct ptlrpc_request **request)
1506 EXP_CHECK_MD_OP(exp, getxattr);
1507 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1508 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1509 input_size, output_size, flags,
1513 static inline int md_set_open_replay_data(struct obd_export *exp,
1514 struct obd_client_handle *och,
1515 struct lookup_intent *it)
1518 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1519 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1520 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1523 static inline int md_clear_open_replay_data(struct obd_export *exp,
1524 struct obd_client_handle *och)
1527 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1528 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1529 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1532 static inline int md_set_lock_data(struct obd_export *exp,
1533 const struct lustre_handle *lockh,
1534 void *data, __u64 *bits)
1537 EXP_CHECK_MD_OP(exp, set_lock_data);
1538 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1539 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1543 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1544 union ldlm_policy_data *policy, enum ldlm_mode mode,
1545 enum ldlm_cancel_flags cancel_flags, void *opaque)
1550 EXP_CHECK_MD_OP(exp, cancel_unused);
1551 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1553 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1554 cancel_flags, opaque);
1558 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1559 const struct lu_fid *fid,
1560 enum ldlm_type type,
1561 union ldlm_policy_data *policy,
1562 enum ldlm_mode mode,
1563 struct lustre_handle *lockh)
1566 EXP_CHECK_MD_OP(exp, lock_match);
1567 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1568 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1569 policy, mode, lockh));
1572 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1576 EXP_CHECK_MD_OP(exp, init_ea_size);
1577 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1578 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1581 static inline int md_intent_getattr_async(struct obd_export *exp,
1582 struct md_enqueue_info *minfo)
1586 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1587 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1588 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1592 static inline int md_revalidate_lock(struct obd_export *exp,
1593 struct lookup_intent *it,
1594 struct lu_fid *fid, __u64 *bits)
1598 EXP_CHECK_MD_OP(exp, revalidate_lock);
1599 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1600 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1604 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1605 const struct lmv_stripe_md *lsm,
1606 const char *name, int namelen,
1611 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1612 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1613 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1618 /* Unpack an MD struct from disk to in-memory format.
1619 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1621 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1622 * If *plsm == NULL then it will be allocated.
1624 static inline int md_unpackmd(struct obd_export *exp,
1625 struct lmv_stripe_md **plsm,
1626 const union lmv_mds_md *lmm, size_t lmm_size)
1630 EXP_CHECK_MD_OP(exp, unpackmd);
1631 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1632 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1636 /* OBD Metadata Support */
1638 extern int obd_init_caches(void);
1639 extern void obd_cleanup_caches(void);
1641 /* support routines */
1642 extern struct kmem_cache *obdo_cachep;
1644 #define OBDO_ALLOC(ptr) \
1646 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1649 #define OBDO_FREE(ptr) \
1651 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1655 typedef int (*register_lwp_cb)(void *data);
1657 struct lwp_register_item {
1658 struct obd_export **lri_exp;
1659 register_lwp_cb lri_cb_func;
1661 struct list_head lri_list;
1663 char lri_name[MTI_NAME_MAXLEN];
1666 /* I'm as embarrassed about this as you are.
1668 * <shaver> // XXX do not look into _superhack with remaining eye
1669 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1670 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1673 #ifdef HAVE_SERVER_SUPPORT
1674 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1675 register_lwp_cb cb_func, void *cb_data);
1676 void lustre_deregister_lwp_item(struct obd_export **exp);
1677 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1678 void lustre_notify_lwp_list(struct obd_export *exp);
1679 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1680 #endif /* HAVE_SERVER_SUPPORT */
1681 int lustre_register_fs(void);
1682 int lustre_unregister_fs(void);
1683 int lustre_check_exclusion(struct super_block *sb, char *svname);
1686 extern void obd_sysctl_init (void);
1687 extern void obd_sysctl_clean (void);
1690 typedef __u8 class_uuid_t[16];
1691 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1694 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1695 int class_add_uuid(const char *uuid, __u64 nid);
1696 int class_del_uuid (const char *uuid);
1697 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1698 void class_init_uuidlist(void);
1699 void class_exit_uuidlist(void);
1702 extern char obd_jobid_node[];
1705 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1709 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1710 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1712 /* root squash info */
1713 struct rw_semaphore;
1714 struct root_squash_info {
1717 struct list_head rsi_nosquash_nids;
1718 struct rw_semaphore rsi_sem;
1721 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1723 /* linux-module.c */
1724 extern struct miscdevice obd_psdev;
1725 int class_procfs_init(void);
1726 int class_procfs_clean(void);
1728 #endif /* __LINUX_OBD_CLASS_H */